diff --git a/README.md b/README.md index 053ba30..f2e0781 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/main/workbench.ts b/src/main/workbench.ts index 4786e9e..e0e144d 100644 --- a/src/main/workbench.ts +++ b/src/main/workbench.ts @@ -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; @@ -196,7 +197,7 @@ async function inspectUpstream(cwd: string, branch: string): Promise { 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', @@ -226,8 +227,16 @@ export async function inspectWorkspace(cwd: string): Promise { // 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()), @@ -238,9 +247,10 @@ export async function inspectWorkspace(cwd: string): Promise { } : 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) diff --git a/src/renderer/components/WorkspaceStatus.tsx b/src/renderer/components/WorkspaceStatus.tsx index 2ae6138..59a063f 100644 --- a/src/renderer/components/WorkspaceStatus.tsx +++ b/src/renderer/components/WorkspaceStatus.tsx @@ -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…' @@ -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 = ( @@ -44,6 +49,19 @@ export function WorkspaceStatus({

{message}

{inspected && ( <> + {conflicts.length > 0 && ( +
+

Review these files before continuing. Pi can help resolve them.

+
    + {conflicts.slice(0, 3).map((file) => ( +
  • {file}
  • + ))} +
+ {conflicts.length > 3 && ( +

{conflicts.length - 3} more in workspace changes.

+ )} +
+ )}

{details.branch || 'Detached HEAD'} · {staged} staged · {unstaged} unstaged · {untracked} untracked

@@ -88,7 +106,7 @@ export function WorkspaceStatus({ Current workspace changes {inspected && {details.branch || 'Detached HEAD'}} - {inspected && ' · '}{message} + {inspected && ' · '}{inspected && conflicts.length ? conflictMessage : message}
{content}
diff --git a/src/renderer/workbench.css b/src/renderer/workbench.css index 78aab20..fa9400a 100644 --- a/src/renderer/workbench.css +++ b/src/renderer/workbench.css @@ -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; } diff --git a/tests/e2e/workspace-status.test.ts b/tests/e2e/workspace-status.test.ts index 95e2dcd..9a2b59e 100644 --- a/tests/e2e/workspace-status.test.ts +++ b/tests/e2e/workspace-status.test.ts @@ -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.'); diff --git a/tests/integration/WorkspaceStatus.test.tsx b/tests/integration/WorkspaceStatus.test.tsx index 1f89267..2915fb8 100644 --- a/tests/integration/WorkspaceStatus.test.tsx +++ b/tests/integration/WorkspaceStatus.test.tsx @@ -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é .ts', 'deleted.ts', 'src/long/path.ts', 'fourth.ts']; + const { container, rerender } = render(); + 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(); + expect(screen.getByRole('status')).toHaveTextContent('1 unresolved conflict'); + rerender(); + 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(); + 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( { { 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(); + render(); 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(); }); }); diff --git a/tests/unit/workbench.test.ts b/tests/unit/workbench.test.ts index cac690c..a6a8faa 100644 --- a/tests/unit/workbench.test.ts +++ b/tests/unit/workbench.test.ts @@ -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');