From 6c81048150259b133a01c8a9ffe7deb9d9a68830 Mon Sep 17 00:00:00 2001 From: CC Evans Date: Sun, 8 Nov 2026 15:20:55 -0500 Subject: [PATCH 1/3] BOB-191: conductor reap --worktrees keeps a worktree with untracked, non-ignored files Co-Authored-By: Claude Sonnet 5.5 --- lib/conductor/worktree-reaper.js | 33 ++++++++++---- test/lib/conductor/read-only.test.js | 2 +- test/lib/conductor/worktree-reaper.test.js | 52 ++++++++++++++++++++-- 3 files changed, 74 insertions(+), 13 deletions(-) diff --git a/lib/conductor/worktree-reaper.js b/lib/conductor/worktree-reaper.js index 0671bdd..5b175c6 100644 --- a/lib/conductor/worktree-reaper.js +++ b/lib/conductor/worktree-reaper.js @@ -13,9 +13,11 @@ // candidates and a locked or prunable one (folder already gone) is kept. // - the ticket ID in its folder name is on a studio board and EVERY ticket named is done. // No ticket in the name, or one that is not on a board, keeps it. -// - `git status --porcelain -uno` is empty: no modified or staged tracked file. Untracked -// and ignored files (node_modules, .next, logs) do not block it and go with the folder; -// committed work is on the branch, which stays. +// - `git status --porcelain --untracked-files=normal` is empty: no modified or staged tracked +// file and no untracked, non-ignored file (a review.md or test-evidence/ nobody committed +// is work that would go with the folder, BOB-191). Only IGNORED files (node_modules, .next, +// logs) go with the folder; committed work is on the branch, which stays. The untracked +// mode is passed explicitly so a user's status.showUntrackedFiles=no cannot hide them. // - a detached HEAD must already be on some local or remote branch: a detached worktree has // no branch of its own to keep, so removing it would orphan commits made on it. // - no live session's cwd is inside it. Live means any session `claude agents` lists that @@ -48,6 +50,12 @@ export function liveCwds(sessions) { return sessions.filter(s => !ended.has(s) && s.cwd).map(s => ({ cwd: real(s.cwd), name: s.name })); } +/** "review.md, test-evidence/ (+3)": the first two entries git status lists, then how many more. */ +function untrackedSummary(entries) { + const shown = entries.slice(0, 2).join(', '); + return entries.length > 2 ? `${shown} (+${entries.length - 2})` : shown; +} + function describe(w) { return { repo: w.repo, path: w.path, branch: w.branch, ticket: w.ticket_ids.join(', ') || null, stage: w.stage }; } @@ -55,7 +63,8 @@ function describe(w) { /** * Sort classified worktrees (worktrees.js classifyWorktrees) into candidates and kept * ones, each kept one with its reason. `dirty(path)` returns the porcelain text of - * `git status -uno` for a path; it is only called for a worktree that passed every other rule. + * `git status --untracked-files=normal` for a path (ignored files are not listed); it is only + * called for a worktree that passed every other rule. * `onBranch(path)` says whether a detached HEAD is already on a branch; only asked for detached ones. */ export function evaluateWorktrees(worktrees, { live, cwd, dirty, onBranch }) { @@ -80,9 +89,15 @@ export function evaluateWorktrees(worktrees, { live, cwd, dirty, onBranch }) { kept.push({ ...describe(w), why: 'git status failed', error: e.message, notable: true }); continue; } - if (changes.trim()) { - const n = changes.trim().split('\n').length; - keep(`${n} tracked file(s) modified or staged`, { notable: true, group: 'tracked files modified or staged' }); + const lines = changes.split('\n').filter(l => l.trim()); + const untracked = lines.filter(l => l.startsWith('??')).map(l => l.slice(3)); + const tracked = lines.length - untracked.length; + if (tracked > 0) { + keep(`${tracked} tracked file(s) modified or staged`, { notable: true, group: 'tracked files modified or staged' }); + continue; + } + if (untracked.length > 0) { + keep(`untracked: ${untrackedSummary(untracked)}`, { notable: true, group: 'untracked files that are not ignored' }); continue; } if (w.detached) { @@ -95,13 +110,13 @@ export function evaluateWorktrees(worktrees, { live, cwd, dirty, onBranch }) { } if (!safe) { keep('detached HEAD is on no branch: removing it would orphan its commits', { notable: true }); continue; } } - candidates.push({ ...describe(w), repo_path: w.repo_path, reason: `${w.ticket_ids.join(', ')} done, tracked files clean, no live session inside` }); + candidates.push({ ...describe(w), repo_path: w.repo_path, reason: `${w.ticket_ids.join(', ')} done, no uncommitted or untracked files, no live session inside` }); } return { candidates, kept }; } function readDirty(run) { - return (p) => run('git', ['-C', p, 'status', '--porcelain', '-uno']); + return (p) => run('git', ['-C', p, 'status', '--porcelain', '--untracked-files=normal']); } /** True when a detached HEAD is contained in at least one local or remote branch. */ diff --git a/test/lib/conductor/read-only.test.js b/test/lib/conductor/read-only.test.js index aea09cb..bc24c26 100644 --- a/test/lib/conductor/read-only.test.js +++ b/test/lib/conductor/read-only.test.js @@ -84,7 +84,7 @@ describe('the worktree reaper does exactly one removal', () => { test('`git -C worktree remove --force ` is the only exec that changes anything', () => { const runs = [...code.matchAll(/\brun\(([^)]*)\)/g)].map(m => m[1].replace(/\s+/g, ' ')); expect(runs).toEqual([ - "'git', ['-C', p, 'status', '--porcelain', '-uno']", + "'git', ['-C', p, 'status', '--porcelain', '--untracked-files=normal']", "'git', ['-C', p, 'for-each-ref', '--contains', 'HEAD', 'refs/heads', 'refs/remotes']", "'git', ['-C', still.repo_path, 'worktree', 'remove', '--force', still.path]", ]); diff --git a/test/lib/conductor/worktree-reaper.test.js b/test/lib/conductor/worktree-reaper.test.js index 10ce569..8105759 100644 --- a/test/lib/conductor/worktree-reaper.test.js +++ b/test/lib/conductor/worktree-reaper.test.js @@ -49,7 +49,8 @@ describe('conductor worktree reaper', () => { beforeEach(() => { ({ root, hookDir } = makeStudio()); fs.writeFileSync(path.join(root, 'tracked.txt'), 'a\n'); - git(root, 'add', 'tracked.txt'); + fs.writeFileSync(path.join(root, '.gitignore'), '*.log\nbuild-cache/\n'); + git(root, 'add', 'tracked.txt', '.gitignore'); git(root, 'commit', '-q', '-m', 'init'); app = fs.mkdtempSync(path.join(os.tmpdir(), 'bobby-wt-app-')); execFileSync('git', ['init', '-q', app]); @@ -109,15 +110,60 @@ describe('conductor worktree reaper', () => { expect(report.failed).toBe(0); }); - test('untracked and ignored files do not block removal (only tracked changes do)', () => { + test('ignored files do not block removal (they are rebuildable)', () => { finish(1); const p = wt(root, 'AL-1-ui'); fs.writeFileSync(path.join(p, 'scratch.log'), 'x'); + fs.mkdirSync(path.join(p, 'build-cache')); + fs.writeFileSync(path.join(p, 'build-cache', 'a'), 'x'); const report = go(mockRun(), { apply: true }); expect(report.results[0].outcome).toBe('removed'); expect(exists(p)).toBe(false); }); + test('untracked, non-ignored files and folders keep the worktree and the dry run says which (BOB-191)', () => { + finish(1); finish(2); finish(3); + const one = wt(root, 'AL-1-ui'); + const many = wt(root, 'AL-2-ui'); + const clean = wt(root, 'AL-3-ui'); + fs.writeFileSync(path.join(one, 'review.md'), 'x'); + fs.mkdirSync(path.join(one, 'test-evidence')); + fs.writeFileSync(path.join(one, 'test-evidence', 'shot.png'), 'x'); + for (const f of ['a.txt', 'b.txt', 'c.txt', 'd.txt']) fs.writeFileSync(path.join(many, f), 'x'); + const m = mockRun(); + const report = go(m, { apply: true }); + expect(report.candidates.map(c => c.path)).toEqual([clean]); + const why = Object.fromEntries(report.kept.map(k => [path.basename(k.path), k.why])); + expect(why['AL-1-ui']).toBe('untracked: review.md, test-evidence/'); + expect(why['AL-2-ui']).toBe('untracked: a.txt, b.txt (+2)'); + expect(m.removals()).toEqual([['git', '-C', root, 'worktree', 'remove', '--force', clean]]); + expect(exists(path.join(one, 'review.md'))).toBe(true); + expect(exists(path.join(many, 'd.txt'))).toBe(true); + const text = renderWorktreeReap(report, { apply: false }); + expect(text).toMatch(/2 {2}untracked files that are not ignored/); + expect(text).toMatch(/kept .*AL-1-ui.*untracked: review\.md, test-evidence\//); + }); + + test('a user setting status.showUntrackedFiles=no cannot hide untracked files from the check', () => { + finish(1); + const p = wt(root, 'AL-1-ui'); + fs.writeFileSync(path.join(p, 'review.md'), 'x'); + git(root, 'config', 'status.showUntrackedFiles', 'no'); + const report = go(mockRun(), { apply: true }); + expect(report.candidates).toEqual([]); + expect(report.kept[0].why).toBe('untracked: review.md'); + expect(exists(path.join(p, 'review.md'))).toBe(true); + }); + + test('tracked changes are reported ahead of untracked ones', () => { + finish(1); + const p = wt(root, 'AL-1-ui'); + fs.appendFileSync(path.join(p, 'tracked.txt'), 'edit\n'); + fs.writeFileSync(path.join(p, 'review.md'), 'x'); + const report = go(mockRun()); + expect(report.kept[0].why).toBe('1 tracked file(s) modified or staged'); + }); + test('a session that has ended (done, no pid) does not keep a worktree; interactive and blocked ones do', () => { finish(1); finish(3); finish(4); const ended = wt(root, 'AL-1-ui'); @@ -247,7 +293,7 @@ describe('conductor worktree reaper', () => { test('--sizes measures the candidates with du and caches them; without it no du runs', () => { finish(1); const p = wt(root, 'AL-1-ui'); - fs.writeFileSync(path.join(p, 'big.bin'), Buffer.alloc(2 * 1024 * 1024)); + fs.writeFileSync(path.join(p, 'big.log'), Buffer.alloc(2 * 1024 * 1024)); const plain = mockRun(); expect(go(plain).sizes).toBeNull(); expect(plain.calls.filter(c => c[0] === 'du')).toEqual([]); From 948cde089f120af8ed9c8ea08eb5c0edfb1ce61b Mon Sep 17 00:00:00 2001 From: CC Evans Date: Sun, 8 Nov 2026 15:21:39 -0500 Subject: [PATCH 2/3] BOB-191: review fixes (CHANGELOG still said -uno) Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b23853d..0c07690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,9 @@ All notable changes to Bobby are documented here. The format is based on studio repo, from `git worktree list --porcelain`); sizes (`du`, slow) show only from the cache or after `status --sizes`. `conductor reap --worktrees` (dry run unless `--apply`, M4 only) removes a worktree with `git worktree remove --force` (branch kept) only when every ticket named - in its folder name is done, `git status --porcelain -uno` is empty, no live session's cwd is + in its folder name is done, `git status --porcelain --untracked-files=normal` is empty (no modified + or staged file and no untracked, non-ignored file such as a review.md or test-evidence/ — the dry run + names them, BOB-191; ignored files like node_modules do not block it), no live session's cwd is inside it and a detached HEAD is already on a branch; folders that are not git worktrees are listed, never touched. `--sizes` measures the candidates. A failing git or claude is an error. - **`bobby conductor` (BOB-174): read-only studio status board.** `bobby conductor init` From 1bb24ceace55d97326e69e4d41138d5a637c3341 Mon Sep 17 00:00:00 2001 From: CC Evans Date: Sun, 8 Nov 2026 15:22:19 -0500 Subject: [PATCH 3/3] BOB-191: test the apply re-check keeps a worktree that gained an untracked file Co-Authored-By: Claude Sonnet 5.5 --- test/lib/conductor/worktree-reaper.test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/lib/conductor/worktree-reaper.test.js b/test/lib/conductor/worktree-reaper.test.js index 8105759..eb97b2d 100644 --- a/test/lib/conductor/worktree-reaper.test.js +++ b/test/lib/conductor/worktree-reaper.test.js @@ -191,6 +191,18 @@ describe('conductor worktree reaper', () => { expect(exists(p)).toBe(true); }); + test('a review.md written between the plan and the removal keeps the worktree', () => { + finish(1); + const p = wt(root, 'AL-1-ui'); + // claude agents is read once per snapshot; write the file at the second read, before the re-check's git status + const m = mockRun({ agents: (reads) => { if (reads === 2) fs.writeFileSync(path.join(p, 'review.md'), 'x'); return []; } }); + const report = go(m, { apply: true }); + expect(report.candidates).toHaveLength(1); + expect(report.results[0]).toMatchObject({ outcome: 'skipped', detail: 'untracked: review.md' }); + expect(m.removals()).toEqual([]); + expect(exists(path.join(p, 'review.md'))).toBe(true); + }); + test('the folder this command runs from is never removed', () => { finish(1); const p = wt(root, 'AL-1-ui');