Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ These are captures of real Electron interactions with a temporary Git workspace

The new-session view shows the selected root's branch and changed-file counts before you send a task. A partially staged file counts once overall and appears in both staged and unstaged totals. Use **Review workspace changes** to open Changes and keep your task draft. Counts follow the existing refresh on focus, navigation and every 15 seconds; unavailable folders and failed inspections never appear clean.

Unresolved Git conflicts appear beside the change count before starting or resuming Pi. Workspace status previews the first three conflicted paths within the selected root; open **Review workspace changes** to see all changed files. Saved history keeps the conflict count visible while status is collapsed. Continuation stays available so Pi can help resolve the files. Staging resolved files clears the warning on the next inspection.

Expanded tool cards show output first. Open Input or close Output independently, and copy either section while it is closed. These choices stay with each card while scrolling through the transcript; reopening the transcript resets them.

Each section reports when copying is in progress, succeeds or fails. A failed copy keeps a retry message beside its Copy button, including when the section is closed. Copy again to retry. New streamed text clears the previous copy feedback so Copied always refers to the current text.
Expand Down
16 changes: 13 additions & 3 deletions src/main/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type WorkspaceDetails = {
upstream?: GitUpstream;
headCommit?: { hash: string; subject: string; committedAt: string };
changes: GitChange[];
conflicts?: string[];
files: string[];
gitError?: string;
filesTruncated?: boolean;
Expand Down Expand Up @@ -196,7 +197,7 @@ async function inspectUpstream(cwd: string, branch: string): Promise<GitUpstream
export async function inspectWorkspace(cwd: string): Promise<WorkspaceDetails> {
const { files, filesTruncated } = await listFiles(cwd);
try {
const [branch, working, staged, untracked, commit] = await Promise.all([
const [branch, working, staged, untracked, commit, conflicts] = await Promise.all([
git(cwd, ['branch', '--show-current']),
git(cwd, [
'diff',
Expand Down Expand Up @@ -226,8 +227,16 @@ export async function inspectWorkspace(cwd: string): Promise<WorkspaceDetails> {
// An unborn or unreadable HEAD must not hide otherwise valid changes.
git(cwd, ['log', '-1', '--no-show-signature', '--format=%H%x00%cI%x00%s', 'HEAD', '--'])
.catch(() => ''),
git(cwd, [
'diff', '--no-ext-diff', '--no-textconv', '--name-only',
'--diff-filter=U', '-z', '--relative', '--', '.',
]),
]);
const [hash, committedAt, subject] = commit.split('\0');
const conflictPaths = new Set(conflicts.split('\0').filter(Boolean));
// Unmerged files can have both an unmerged marker and a patch in numstat.
// They belong in the working copy once, not among staged resolutions.
const workingChanges = new Map(parseNumstat(working, false).map((change) => [change.path, change]));
return {
branch: branch.trim(),
upstream: await inspectUpstream(cwd, branch.trim()),
Expand All @@ -238,9 +247,10 @@ export async function inspectWorkspace(cwd: string): Promise<WorkspaceDetails> {
} : undefined,
files,
filesTruncated,
conflicts: [...conflictPaths],
changes: [
...parseNumstat(working, false),
...parseNumstat(staged, true),
...workingChanges.values(),
...parseNumstat(staged, true).filter((change) => !conflictPaths.has(change.path)),
...untracked
.split('\0')
.filter(Boolean)
Expand Down
22 changes: 20 additions & 2 deletions src/renderer/components/WorkspaceStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function WorkspaceStatus({
const staged = changes.filter((change) => change.staged).length;
const unstaged = changes.filter((change) => !change.staged && !change.untracked).length;
const untracked = changes.filter((change) => change.untracked).length;
const message = unavailable
const conflicts = details.conflicts ?? [];
const changeMessage = unavailable
? 'Restore this folder to inspect Git changes.'
: !ready
? 'Checking Git changes…'
Expand All @@ -30,6 +31,10 @@ export function WorkspaceStatus({
? `${count} changed ${count === 1 ? 'file' : 'files'}`
: 'No changes in this root';
const inspected = !unavailable && ready && !details.gitError;
const conflictMessage = `${conflicts.length} unresolved ${conflicts.length === 1 ? 'conflict' : 'conflicts'}`;
const message = inspected && conflicts.length
? `${changeMessage} · ${conflictMessage}`
: changeMessage;
const commit = inspected ? details.headCommit : undefined;

const content = (
Expand All @@ -44,6 +49,19 @@ export function WorkspaceStatus({
<p role="status">{message}</p>
{inspected && (
<>
{conflicts.length > 0 && (
<div className="wb-workspace-conflicts" aria-label="Unresolved Git conflicts">
<p>Review these files before continuing. Pi can help resolve them.</p>
<ul>
{conflicts.slice(0, 3).map((file) => (
<li key={file} title={file}>{file}</li>
))}
</ul>
{conflicts.length > 3 && (
<p className="wb-meta">{conflicts.length - 3} more in workspace changes.</p>
)}
</div>
)}
<p className="wb-meta">
{details.branch || 'Detached HEAD'} · {staged} staged · {unstaged} unstaged · {untracked} untracked
</p>
Expand Down Expand Up @@ -88,7 +106,7 @@ export function WorkspaceStatus({
Current workspace changes
<span className="wb-meta" title={inspected ? `${details.branch || 'Detached HEAD'} · ${message}` : message}>
{inspected && <span className="wb-history-status-branch">{details.branch || 'Detached HEAD'}</span>}
<span>{inspected && ' · '}{message}</span>
<span>{inspected && ' · '}{inspected && conflicts.length ? conflictMessage : message}</span>
</span>
</summary>
<div className="wb-workspace-status">{content}</div>
Expand Down
15 changes: 15 additions & 0 deletions src/renderer/workbench.css
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,21 @@ html[data-reduced-motion='true'] .wb-shell *::after {
.wb-workspace-upstream {
overflow-wrap: anywhere;
}
.wb-workspace-conflicts {
border-left: 2px solid var(--warning);
padding-left: 10px;
margin: 8px 0;
font-size: 12px;
}
.wb-workspace-conflicts ul {
margin: 4px 0;
padding-left: 16px;
}
.wb-workspace-conflicts li {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.wb-workspace-upstream-note {
display: block;
}
Expand Down
80 changes: 80 additions & 0 deletions tests/e2e/workspace-status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,86 @@ describe('workspace status in Electron', () => {
expect(errors).toEqual([]);
});

it('warns before new and saved continuation, keeps drafts and clears conflicts after resolution', async () => {
git(clean, 'config', 'user.name', 'Test');
git(clean, 'config', 'user.email', 'test@example.test');
git(clean, 'config', 'commit.gpgsign', 'false');
const longFile = 'src/a long package name/another long folder/café-parser-with-a-long-name.ts';
await fs.mkdir(path.dirname(path.join(clean, longFile)), { recursive: true });
await fs.writeFile(path.join(clean, longFile), 'base\n');
git(clean, 'add', '.');
const commit = (subject: string) => git(clean, '-c', 'user.name=Test', '-c', 'user.email=test@example.test',
'-c', 'commit.gpgsign=false', 'commit', '-am', subject);
commit('Add parser');
git(clean, 'switch', '-c', 'other');
for (const file of ['app.ts', longFile]) await fs.writeFile(path.join(clean, file), 'other\n');
commit('Other changes');
git(clean, 'switch', 'main');
for (const file of ['app.ts', longFile]) await fs.writeFile(path.join(clean, file), 'main\n');
commit('Main changes');
expect(() => git(clean, 'merge', 'other')).toThrow();
const archive = path.join(fixture, 'sessions/workspace/conflict.jsonl');
await fs.writeFile(archive, [
{ type: 'session', version: 3, id: 'conflict', cwd: clean, timestamp: new Date().toISOString() },
{ type: 'message', id: 'request', parentId: null, message: { role: 'user', content: [{ type: 'text', text: 'Continue parser work' }] } },
].map((record) => JSON.stringify(record)).join('\n') + '\n');
await page.getByLabel('Workspace group').selectOption({ label: 'clean' });
await page.getByRole('button', { name: 'New session', exact: true }).click();
await page.evaluate(() => window.dispatchEvent(new Event('focus')));
await expect.poll(() => status().textContent()).toContain('2 unresolved conflicts');
expect(await status().textContent()).toContain('main · 0 staged · 2 unstaged · 0 untracked');
expect(await status().getByText(longFile, { exact: true }).isVisible()).toBe(true);
await page.getByLabel('Message pi').fill('Resolve these files with care.');
expect(await page.getByRole('button', { name: 'Send', exact: true }).isEnabled()).toBe(true);
await page.evaluate(() => document.fonts.ready);
await status().scrollIntoViewIfNeeded();
await capture('workspace-conflicts.png');
await resizeWindow(900, 600);
await status().getByLabel('Unresolved Git conflicts').scrollIntoViewIfNeeded();
expect(await page.evaluate(() => document.body.scrollWidth <= innerWidth)).toBe(true);
await capture('workspace-conflicts-narrow.png');
await resizeWindow(1280, 900);
await status().getByRole('button', { name: 'Review workspace changes' }).click();
await page.getByRole('heading', { name: 'Changes review', exact: true }).waitFor();
expect(await page.getByLabel('Message pi').inputValue()).toBe('Resolve these files with care.');
await page.getByRole('button', { name: /^Sessions/ }).click();
await page.getByRole('tree', { name: 'Session archives', exact: true })
.getByRole('treeitem', { name: /Continue parser work/ }).click();
await expect.poll(() => status().locator('summary').textContent()).toContain('2 unresolved conflicts');
await page.getByLabel('Message pi').fill('Help resolve the conflicts before continuing.');
expect(await page.getByRole('button', { name: 'Resume', exact: true }).isEnabled()).toBe(true);
await capture('history-conflicts.png');
await resizeWindow(900, 600);
const summaryStatus = status().locator('summary .wb-meta > span').last();
expect(await summaryStatus.evaluate((el) => el.scrollWidth <= el.clientWidth)).toBe(true);
await capture('history-conflicts-narrow.png');
await status().locator('summary').click();
await status().getByLabel('Unresolved Git conflicts').waitFor();
await status().getByLabel('Unresolved Git conflicts').scrollIntoViewIfNeeded();
expect(await page.locator('.wb-transcript').evaluate((el) => el.clientHeight)).toBeGreaterThan(40);
expect(await page.evaluate(() => document.body.scrollWidth <= innerWidth)).toBe(true);
expect(await page.locator('.wb-composer').evaluate((el) => el.getBoundingClientRect().bottom))
.toBeLessThanOrEqual(await page.locator('.wb-statusbar').evaluate((el) => el.getBoundingClientRect().top));
await capture('history-conflicts-expanded-narrow.png');
for (const file of ['app.ts', longFile]) await fs.writeFile(path.join(clean, file), 'resolved\n');
git(clean, 'add', '.');
await page.evaluate(() => window.dispatchEvent(new Event('focus')));
await expect.poll(() => status().getByLabel('Unresolved Git conflicts').count()).toBe(0);
expect(await status().textContent()).toContain('main · 2 staged · 0 unstaged · 0 untracked');
expect(await status().locator('summary').textContent()).not.toContain('unresolved conflict');
expect(await page.getByLabel('Message pi').inputValue()).toBe('Help resolve the conflicts before continuing.');
await resizeWindow(1280, 900);
await page.getByLabel('Workspace group').selectOption({ label: 'project' });
expect(await status().getByLabel('Unresolved Git conflicts').count()).toBe(0);
await page.getByLabel('Workspace group').selectOption({ label: 'clean' });
await page.getByRole('button', { name: 'New session', exact: true }).click();
expect(await page.getByLabel('Message pi').inputValue()).toBe('Resolve these files with care.');
const commands = (await fs.readFile(rpcLog, 'utf8').catch(() => ''))
.split('\n').filter(Boolean).map((line) => JSON.parse(line));
expect(commands.every((command) => command.type === 'get_available_models')).toBe(true);
expect(errors).toEqual([]);
});

it('does not describe non-Git folders or missing roots as clean', async () => {
await select('plain');
await expect.poll(() => status().textContent()).toContain('Git changes are unavailable for this folder.');
Expand Down
37 changes: 36 additions & 1 deletion tests/integration/WorkspaceStatus.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,39 @@ const change: GitChange = {
afterEach(cleanup);

describe('workspace Git status', () => {
it('warns about unresolved conflicts, bounds the path preview and keeps review available', () => {
const onReview = vi.fn();
const conflicts = ['src/café <parser>.ts', 'deleted.ts', 'src/long/path.ts', 'fourth.ts'];
const { container, rerender } = render(<WorkspaceStatus workspace={workspace} details={{
...details, changes: [change], conflicts,
}} ready onReview={onReview} />);
expect(screen.getByRole('status')).toHaveTextContent('1 changed file · 4 unresolved conflicts');
expect(screen.getByLabelText('Unresolved Git conflicts')).toBeVisible();
expect(screen.getAllByRole('listitem')).toHaveLength(3);
expect(screen.getByTitle(conflicts[0])).toHaveTextContent(conflicts[0]);
expect(container.querySelector('parser')).toBeNull();
expect(screen.getByText('1 more in workspace changes.')).toBeVisible();
fireEvent.click(screen.getByRole('button', { name: 'Review workspace changes' }));
expect(onReview).toHaveBeenCalledOnce();
rerender(<WorkspaceStatus workspace={workspace} details={{ ...details, conflicts: [conflicts[0]] }} ready onReview={onReview} />);
expect(screen.getByRole('status')).toHaveTextContent('1 unresolved conflict');
rerender(<WorkspaceStatus workspace={workspace} details={{ ...details, conflicts: [] }} ready onReview={onReview} />);
expect(screen.queryByLabelText('Unresolved Git conflicts')).not.toBeInTheDocument();
expect(screen.getByRole('status')).toHaveTextContent('No changes in this root');
});

it('keeps conflict counts visible in collapsed history and reveals paths on expansion', () => {
const { container } = render(<WorkspaceStatus context="history" workspace={workspace} details={{
...details, changes: [change], conflicts: ['app.ts'],
}} ready onReview={vi.fn()} />);
expect(container.querySelector('summary')).toHaveTextContent('1 unresolved conflict');
expect(container.querySelector('summary')).not.toHaveTextContent('1 changed file');
expect(screen.getByText('app.ts')).not.toBeVisible();
fireEvent.click(screen.getByText('Current workspace changes'));
expect(screen.getByText('app.ts')).toBeVisible();
expect(screen.getByText('Review these files before continuing. Pi can help resolve them.')).toBeVisible();
});

it('shows local upstream counts and refreshes them without claiming to fetch', () => {
const { rerender } = render(<WorkspaceStatus workspace={workspace} details={{ ...details,
upstream: { state: 'tracked', name: 'origin/feature/status', ahead: 2, behind: 3 },
Expand Down Expand Up @@ -118,12 +151,14 @@ describe('workspace Git status', () => {
{ ready: true, availability: 'unavailable' as const, gitError: undefined, message: 'Restore this folder to inspect Git changes.' },
{ ready: true, availability: 'available' as const, gitError: 'Git changes are unavailable for this folder.', message: 'Git changes are unavailable for this folder.' },
])('does not claim a clean root when $message', ({ ready, availability, gitError, message }) => {
render(<WorkspaceStatus workspace={{ ...workspace, availability }} details={{ ...details, gitError, headCommit, upstream: { state: 'tracked', name: 'origin/main', ahead: 1, behind: 2 } }} ready={ready} onReview={vi.fn()} />);
render(<WorkspaceStatus workspace={{ ...workspace, availability }} details={{ ...details, gitError, headCommit, conflicts: ['stale.ts'], upstream: { state: 'tracked', name: 'origin/main', ahead: 1, behind: 2 } }} ready={ready} onReview={vi.fn()} />);
expect(screen.getByRole('status')).toHaveTextContent(message);
expect(screen.getByRole('button')).toBeDisabled();
expect(screen.queryByText('No changes in this root')).not.toBeInTheDocument();
expect(screen.queryByText(/old-branch|feature\/status/)).not.toBeInTheDocument();
expect(screen.queryByLabelText('Current repository commit')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Upstream comparison')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Unresolved Git conflicts')).not.toBeInTheDocument();
expect(screen.queryByText(/unresolved conflict/)).not.toBeInTheDocument();
});
});
40 changes: 40 additions & 0 deletions tests/unit/workbench.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,46 @@ afterEach(async () => {
});

describe('workspace inspection and preview', () => {
it('finds unresolved merge conflicts with literal root-relative paths and clears them after staging resolutions', async () => {
const root = await fixture();
const nested = path.join(root, 'package');
await fs.mkdir(nested);
await git(root, ['init', '-b', 'main']);
await git(root, ['config', 'user.name', 'Test']);
await git(root, ['config', 'user.email', 'test@example.test']);
await git(root, ['config', 'commit.gpgsign', 'false']);
const paths = ['package/café\nparser.ts', 'sibling.ts'];
const write = (text: string) => Promise.all(paths.map((file) => fs.writeFile(path.join(root, file), text)));
await write('base\n');
await git(root, ['add', '.']);
await git(root, ['commit', '-m', 'Shared base']);
await git(root, ['switch', '-c', 'other']);
await write('other\n');
await git(root, ['commit', '-am', 'Other changes']);
await git(root, ['switch', 'main']);
await write('main\n');
await git(root, ['commit', '-am', 'Main changes']);
await expect(git(root, ['merge', 'other'])).rejects.toThrow();

const whole = await inspectWorkspace(root);
expect(whole.conflicts).toEqual(paths);
expect(whole.changes.map((change) => change.path)).toEqual(paths);
expect(whole.changes.every((change) => !change.staged)).toBe(true);
const result = await inspectWorkspace(nested);
expect(result.gitError).toBeUndefined();
expect(result.conflicts).toEqual(['café\nparser.ts']);
expect(result.changes.some((change) => change.path === 'café\nparser.ts')).toBe(true);
await fs.writeFile(path.join(nested, 'café\nparser.ts'), 'resolved\n');
await git(nested, ['add', '.']);
const resolved = await inspectWorkspace(nested);
expect(resolved.conflicts).toEqual([]);
expect(resolved.changes).toHaveLength(1);
expect(resolved.changes[0].staged).toBe(true);
expect((await inspectWorkspace(root)).conflicts).toEqual(['sibling.ts']);
await git(root, ['merge', '--abort']);
expect((await inspectWorkspace(root)).conflicts).toEqual([]);
}, 15_000);

it('compares local upstream refs from nested roots and refreshes ahead, behind and diverged counts without fetching', async () => {
const root = await fixture();
const nested = path.join(root, 'package');
Expand Down
Loading