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: 1 addition & 1 deletion docs/pidex-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Workspace inspection reads the file tree, Git branch/status and repository HEAD

Per-root views, new-session/history drafts, unsaved settings drafts, open tabs, transcript selection, and expanded rows are in-memory UI state. Restoring an interrupted history load retries the saved archive/entry, while completed error states require explicit retry. Settings cache only dirty drafts; clean views follow saved defaults. Changes views remount per root and late mutation results are checked against their original navigation generation. Scroll position and expansion are not persisted when a transcript is reopened.

New-session and saved-history status show in-progress Git merges and rebases from the selected worktree's own Git directory, including when all conflicts in the selected root have been resolved. These operations affect the whole worktree even for nested roots. The notice is informational; Pi can still start or resume to help finish the operation. Git operations are never continued or aborted by workspace inspection.
New-session and saved-history status show in-progress Git merges, rebases, cherry-picks and reverts from the selected worktree's own Git directory, including when all conflicts in the selected root have been resolved. Cherry-pick and revert sequences remain visible after a manual resolution commit clears the current operation marker. These operations affect the whole worktree even for nested roots. The notice is informational; Pi can still start or resume to help finish the operation. Git operations are never continued or aborted by workspace inspection.

## Transcript rendering

Expand Down
22 changes: 19 additions & 3 deletions src/main/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type GitUpstream =
| { state: 'tracked'; name: string; ahead: number; behind: number };
export type WorkspaceDetails = {
branch: string;
gitOperation?: 'merge' | 'rebase' | 'unavailable';
gitOperation?: 'merge' | 'rebase' | 'cherry-pick' | 'revert' | 'unavailable';
upstream?: GitUpstream;
headCommit?: { hash: string; subject: string; committedAt: string };
changes: GitChange[];
Expand Down Expand Up @@ -206,13 +206,29 @@ async function inspectGitOperation(cwd: string): Promise<WorkspaceDetails['gitOp
throw error;
},
);
const [rebaseMerge, rebaseApply, merge] = await Promise.all([
const [rebaseMerge, rebaseApply, merge, cherryPick, revert] = await Promise.all([
exists('rebase-merge'),
// git am also uses rebase-apply, but does not create this marker.
exists('rebase-apply/rebasing'),
exists('MERGE_HEAD'),
exists('CHERRY_PICK_HEAD'),
exists('REVERT_HEAD'),
]);
return rebaseMerge || rebaseApply ? 'rebase' : merge ? 'merge' : undefined;
if (rebaseMerge || rebaseApply) return 'rebase';
if (merge) return 'merge';
if (cherryPick) return 'cherry-pick';
if (revert) return 'revert';
// A manual commit can clear the current HEAD marker while a sequence
// still has commits to apply. The worktree's todo retains that state.
const todo = await fs.readFile(path.join(directory, 'sequencer/todo'), 'utf8').catch(
(error: NodeJS.ErrnoException) => {
if (error.code === 'ENOENT') return '';
throw error;
},
);
const command = todo.split('\n').map((line) => line.trim())
.find((line) => line && !line.startsWith('#'))?.split(/\s+/)[0];
return command === 'pick' ? 'cherry-pick' : command === 'revert' ? 'revert' : undefined;
} catch {
return 'unavailable';
}
Expand Down
10 changes: 7 additions & 3 deletions src/renderer/components/WorkspaceStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ export function WorkspaceStatus({
? 'Merge in progress'
: operation === 'rebase'
? 'Rebase in progress'
: operation === 'unavailable'
? 'Git operation status unavailable'
: '';
: operation === 'cherry-pick'
? 'Cherry-pick in progress'
: operation === 'revert'
? 'Revert in progress'
: operation === 'unavailable'
? 'Git operation status unavailable'
: '';

const content = (
<>
Expand Down
7 changes: 6 additions & 1 deletion tests/e2e/long-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ describe('long session in Electron', () => {
const start = performance.now();
await page.locator('.wb-sidebar .wb-session-item').first().click();
await page.getByRole('button', { name: 'Fork from here', exact: true }).click();
// The same transcript is already visible in the preview. Wait for the
// live session before navigating away, or the pending fork can be hidden.
const openSession = page.locator('.wb-sidebar .wb-session-item').filter({ hasText: 'this window' }).first();
await openSession.waitFor();
await page.getByRole('button', { name: 'Send', exact: true }).waitFor();
await page
.locator('.wb-transcript')
.getByText('Iteration 1499', { exact: true })
Expand All @@ -86,7 +91,7 @@ describe('long session in Electron', () => {
.getByRole('button', { name: 'New session', exact: true })
.click();
const switchStart = performance.now();
await page.locator('.wb-sidebar .wb-session-item').first().click();
await openSession.click();
await page
.locator('.wb-transcript')
.getByText('Iteration 1499', { exact: true })
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/session-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ describe('session branches in Electron', () => {
expect(ancestor).toContain('select entry `old-answer`, and choose Resume in new fork.');
await fs.mkdir(path.join(ROOT, '.tmp/proof'), { recursive: true });
const exportedFile = path.join(ROOT, '.tmp/proof/selected-history.md');
await fs.rm(exportedFile, { force: true });
await app.evaluate(({ BrowserWindow }, output) => {
BrowserWindow.getAllWindows()[0].webContents.session.once('will-download', (_event, item) => {
item.setSavePath(output);
Expand Down
63 changes: 63 additions & 0 deletions tests/e2e/workspace-status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,69 @@ describe('workspace status in Electron', () => {
expect(errors).toEqual([]);
});

it('shows cherry-picks and reverts before new and saved continuation until abort', async () => {
const archive = path.join(fixture, 'sessions/workspace/conflict.jsonl');
const original = await fs.readFile(archive, 'utf8');
for (const operation of ['cherry-pick', 'revert'] as const) {
await select('clean');
let target = 'other';
if (operation === 'revert') {
target = git(clean, 'rev-parse', 'HEAD').toString().trim();
for (const file of ['app.ts', longFile]) await fs.writeFile(path.join(clean, file), 'subsequent change\n');
git(clean, 'commit', '-am', 'Changes after the commit to revert');
}
expect(() => git(clean, operation, '--no-edit', target)).toThrow();
const message = operation === 'cherry-pick' ? 'Cherry-pick in progress' : 'Revert in progress';
await page.evaluate(() => window.dispatchEvent(new Event('focus')));
await expect.poll(() => status().getByLabel('Git operation').textContent()).toContain(message);
await page.getByLabel('Message pi').fill(`Help finish this ${operation}.`);
expect(await page.getByRole('button', { name: 'Send', exact: true }).isEnabled()).toBe(true);
// Staging all conflicts must not make an unfinished operation look complete.
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().getByLabel('Git operation').textContent()).toContain(message);
await page.evaluate(() => document.fonts.ready);
await status().getByLabel('Git operation').scrollIntoViewIfNeeded();
await capture(`workspace-${operation}-in-progress.png`);
await resizeWindow(900, 600);
await status().getByLabel('Git operation').scrollIntoViewIfNeeded();
expect(await page.evaluate(() => document.body.scrollWidth <= innerWidth)).toBe(true);
await capture(`workspace-${operation}-in-progress-narrow.png`);
await resizeWindow(1280, 900);
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(message);
await page.getByLabel('Message pi').fill(`Review the ${operation} before continuing saved work.`);
expect(await page.getByRole('button', { name: 'Resume', exact: true }).isEnabled()).toBe(true);
await capture(`history-${operation}-in-progress.png`);
await resizeWindow(900, 600);
await capture(`history-${operation}-in-progress-narrow.png`);
await status().locator('summary').click();
await status().getByLabel('Git operation').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-${operation}-in-progress-expanded-narrow.png`);
git(clean, operation, '--abort');
await page.evaluate(() => window.dispatchEvent(new Event('focus')));
await expect.poll(() => status().getByLabel('Git operation').count()).toBe(0);
expect(await status().locator('summary').textContent()).not.toContain(message);
expect(await page.getByLabel('Message pi').inputValue()).toBe(`Review the ${operation} before continuing saved work.`);
await resizeWindow(1280, 900);
await page.getByRole('button', { name: 'New session', exact: true }).click();
expect(await page.getByLabel('Message pi').inputValue()).toBe(`Help finish this ${operation}.`);
}
expect(await fs.readFile(archive, 'utf8')).toBe(original);
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
2 changes: 2 additions & 0 deletions tests/integration/WorkspaceStatus.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ describe('workspace Git status', () => {
it.each([
{ gitOperation: 'merge' as const, message: 'Merge in progress' },
{ gitOperation: 'rebase' as const, message: 'Rebase in progress' },
{ gitOperation: 'cherry-pick' as const, message: 'Cherry-pick in progress' },
{ gitOperation: 'revert' as const, message: 'Revert in progress' },
])('shows $message even after all root conflicts have been resolved', ({ gitOperation, message }) => {
const onReview = vi.fn();
const { container, rerender } = render(<WorkspaceStatus context="history" workspace={workspace} details={{
Expand Down
79 changes: 79 additions & 0 deletions tests/unit/workbench.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,85 @@ describe('workspace inspection and preview', () => {
expect((await inspectWorkspace(root)).headCommit?.subject).toBe('Main change');
}, 30_000);

it.each([
{ operation: 'cherry-pick', sequence: false },
{ operation: 'cherry-pick', sequence: true },
{ operation: 'revert', sequence: false },
{ operation: 'revert', sequence: true },
])('detects $operation with sequence=$sequence in a linked worktree through resolution and cleanup', async ({ operation, sequence }) => {
const root = await fixture();
const linked = path.join(await fixture(), 'linked worktree');
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']);
await fs.mkdir(path.join(root, 'package'));
await fs.writeFile(path.join(root, 'package/app.ts'), 'base\n');
await git(root, ['add', '.']);
await git(root, ['commit', '-m', 'Shared base']);
const base = (await git(root, ['rev-parse', 'HEAD'])).trim();
await fs.writeFile(path.join(root, 'package/app.ts'), 'source\n');
await git(root, ['commit', '-am', 'Source change']);
const first = (await git(root, ['rev-parse', 'HEAD'])).trim();
await fs.writeFile(path.join(root, 'package/extra.ts'), 'extra\n');
await git(root, ['add', '.']);
await git(root, ['commit', '-m', 'Another source change']);
const second = (await git(root, ['rev-parse', 'HEAD'])).trim();
await git(root, ['worktree', 'add', '-b', 'target', linked, operation === 'revert' ? second : base]);
const nested = path.join(linked, 'package');
await fs.writeFile(path.join(nested, 'app.ts'), 'target\n');
await git(linked, ['commit', '-am', 'Conflicting target change']);
await expect(git(linked, [operation, '--no-edit', first, ...(sequence ? [second] : [])])).rejects.toThrow();
const stopped = await inspectWorkspace(nested);
expect(stopped.gitOperation).toBe(operation);
expect(stopped.conflicts).toEqual(['app.ts']);
expect((await inspectWorkspace(root)).gitOperation).toBeUndefined();
await fs.writeFile(path.join(nested, 'app.ts'), 'resolved\n');
await git(linked, ['add', '.']);
const resolved = await inspectWorkspace(nested);
expect(resolved.conflicts).toEqual([]);
expect(resolved.gitOperation).toBe(operation);
if (sequence) {
// Real manual resolution clears *_HEAD, but leaves the sequence active.
await git(linked, ['commit', '-m', 'Resolve current operation']);
const directory = (await git(linked, ['rev-parse', '--absolute-git-dir'])).trim();
const marker = operation === 'revert' ? 'REVERT_HEAD' : 'CHERRY_PICK_HEAD';
await expect(fs.stat(path.join(directory, marker))).rejects.toMatchObject({ code: 'ENOENT' });
expect((await inspectWorkspace(nested)).gitOperation).toBe(operation);
execFileSync('git', [operation, '--continue'], {
cwd: linked, env: { ...process.env, GIT_EDITOR: 'true' }, stdio: 'pipe', timeout: 15_000,
});
expect(await fs.readFile(path.join(nested, 'app.ts'), 'utf8')).toBe('resolved\n');
if (operation === 'cherry-pick') expect(await fs.readFile(path.join(nested, 'extra.ts'), 'utf8')).toBe('extra\n');
else await expect(fs.stat(path.join(nested, 'extra.ts'))).rejects.toMatchObject({ code: 'ENOENT' });
} else {
await git(linked, [operation, '--abort']);
expect(await fs.readFile(path.join(nested, 'app.ts'), 'utf8')).toBe('target\n');
}
expect((await inspectWorkspace(nested)).gitOperation).toBeUndefined();
expect((await inspectWorkspace(root)).gitOperation).toBeUndefined();
}, 30_000);

it('keeps rebase precedence when it stops while applying a commit', async () => {
const root = await fixture();
await git(root, ['init', '-b', 'main']);
await fs.mkdir(path.join(root, '.git/rebase-merge'));
await fs.writeFile(path.join(root, '.git/CHERRY_PICK_HEAD'), 'stopped commit\n');
expect((await inspectWorkspace(root)).gitOperation).toBe('rebase');
});

it('keeps changes readable when sequencer state cannot be read', async () => {
const root = await fixture();
await git(root, ['init', '-b', 'main']);
await fs.writeFile(path.join(root, 'new.ts'), 'pending\n');
await fs.mkdir(path.join(root, '.git/sequencer'));
await fs.symlink('todo', path.join(root, '.git/sequencer/todo'));
const result = await inspectWorkspace(root);
expect(result.gitOperation).toBe('unavailable');
expect(result.gitError).toBeUndefined();
expect(result.changes[0]?.path).toBe('new.ts');
});

it('does not call a stopped git am a rebase', async () => {
const root = await fixture();
await git(root, ['init', '-b', 'main']);
Expand Down
Loading