pi-odd-worktree 3.7.2 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+ // S1/S2 (modular-tools): what the extension registers for each setting of the two module
3
+ // switches. The switches are read ONCE, when the extension registers, from the bridge's
4
+ // store, and a missing document keeps everything on — so every other suite in this package
5
+ // loads the whole thing.
6
+ const { test, describe, afterEach } = require('node:test');
7
+ const assert = require('node:assert/strict');
8
+ const os = require('node:os');
9
+
10
+ const { BRIDGE_SLOT, defaultBridge, loadExtension } = require('./fixtures/load-extension.js');
11
+
12
+ const saved = globalThis[BRIDGE_SLOT];
13
+ afterEach(() => {
14
+ if (saved === undefined) delete globalThis[BRIDGE_SLOT];
15
+ else globalThis[BRIDGE_SLOT] = saved;
16
+ });
17
+
18
+ // A bridge whose own-store `modules` document is the one handed in; everything else the
19
+ // default bridge does stays as it is.
20
+ async function load(modules, { selection, host } = {}) {
21
+ const bridge = defaultBridge();
22
+ const document = modules === undefined ? undefined : { ...modules };
23
+ bridge.api.createStore = () => ({
24
+ get: (key, fallback) => (key === 'modules' && document !== undefined ? document : fallback),
25
+ set: () => {},
26
+ delete: () => {},
27
+ });
28
+ // S11: the `Card activity` reader the CodeGraph card follows, when a case needs one.
29
+ if (typeof selection === 'function') bridge.api.resolveToolDesignSelection = selection;
30
+ globalThis[BRIDGE_SLOT] = bridge.api;
31
+ const loaded = await loadExtension(host || {});
32
+ return { ...loaded, bridge };
33
+ }
34
+
35
+ /** The activity design, as the bridge answers it while `Card activity` is on `activity`. */
36
+ const ACTIVITY = () => ({ kind: 'design', design: { id: 'odd-worktree.bash-activity' } });
37
+
38
+ const toolCallHandlers = (loaded) => loaded.hooks.filter(([name]) => name === 'tool_call').length;
39
+
40
+ async function promptOf(loaded, selectedTools) {
41
+ const options = { selectedTools };
42
+ for (const [name, handler] of loaded.hooks) {
43
+ if (name === 'before_agent_start') await handler({ systemPromptOptions: options }, { cwd: os.tmpdir() });
44
+ }
45
+ return options.appendSystemPrompt ?? '';
46
+ }
47
+
48
+ describe('the Tools page', () => {
49
+ test('the extension registers one provider on the `Tools` page, whatever the switches say', async () => {
50
+ for (const modules of [undefined, { codegraph: false }, { worktrees: false }, { codegraph: false, worktrees: false }]) {
51
+ const { bridge } = await load(modules);
52
+ const tools = bridge.rows.filter((provider) => provider.category === 'Tools');
53
+ assert.equal(tools.length, 1, JSON.stringify(modules));
54
+ assert.deepEqual(
55
+ tools[0].rows({}).map((row) => `${row.choice.setting} ${row.choice.value}`),
56
+ ['Codegraph+ Off', 'Codegraph+ On', 'Worktrees+ Off', 'Worktrees+ On'],
57
+ );
58
+ }
59
+ });
60
+ });
61
+
62
+ describe('Worktrees+', () => {
63
+ test('on (the default): the two tools, /warp, its card and every worktree guard and text', async () => {
64
+ const loaded = await load(undefined);
65
+ assert.deepEqual([...loaded.tools.keys()].filter((name) => name.startsWith('worktree_')).sort(), ['worktree_create', 'worktree_list']);
66
+ assert.ok(loaded.commands.has('warp'));
67
+ assert.ok(loaded.messageRenderers.has('worktree-warp'));
68
+ assert.match(await promptOf(loaded, []), /## ODD worktrees/);
69
+ });
70
+
71
+ test('off: no tools, no /warp, no warp card, no worktree text and fewer guards, while everything else stays', async () => {
72
+ const on = await load(undefined);
73
+ const off = await load({ worktrees: false });
74
+ assert.equal([...off.tools.keys()].some((name) => name.startsWith('worktree_')), false);
75
+ assert.equal(off.commands.has('warp'), false);
76
+ assert.equal(off.messageRenderers.has('worktree-warp'), false);
77
+ assert.doesNotMatch(await promptOf(off, []), /## ODD worktrees/);
78
+ // the naming handler, the bash guard and the write guard go; the skill-read guard stays
79
+ assert.equal(toolCallHandlers(on) - toolCallHandlers(off), 3);
80
+ assert.ok(toolCallHandlers(off) >= 1, 'the skill-read guard is transversal');
81
+ for (const name of ['odd', 'files']) assert.ok(off.commands.has(name), `${name} stays`);
82
+ assert.equal(off.hooks.some(([hook]) => hook === 'agent_settled'), false, 'the warp settle tick goes');
83
+ });
84
+
85
+ test('off keeps the CodeGraph text and the issues surface', async () => {
86
+ const off = await load({ worktrees: false });
87
+ assert.match(await promptOf(off, ['codegraph']), /## CodeGraph/);
88
+ assert.ok(off.commands.has('issues'));
89
+ });
90
+ });
91
+
92
+ describe('Codegraph+', () => {
93
+ test('on (the default): the role text rides the prompt of a session holding a CodeGraph tool', async () => {
94
+ assert.match(await promptOf(await load(undefined), ['codegraph']), /## CodeGraph/);
95
+ });
96
+
97
+ test('off: no CodeGraph text, and the worktrees half is untouched', async () => {
98
+ const off = await load({ codegraph: false });
99
+ const prompt = await promptOf(off, ['codegraph']);
100
+ assert.doesNotMatch(prompt, /## CodeGraph/);
101
+ assert.match(prompt, /## ODD worktrees/);
102
+ assert.ok(off.tools.has('worktree_create'));
103
+ assert.ok(off.commands.has('warp'));
104
+ });
105
+ });
106
+
107
+ describe('the CodeGraph card', () => {
108
+ const cardResolvers = async (modules, selection) => {
109
+ const resolvers = [];
110
+ await load(modules, { selection, host: { registerToolRenderer: (resolver) => resolvers.push(resolver) } });
111
+ return resolvers.filter((resolver) => resolver('codegraph', () => undefined) !== undefined).length;
112
+ };
113
+
114
+ test('is a design of the `Card activity` line: activity on paints it, and Codegraph+ off keeps it', async () => {
115
+ assert.equal(await cardResolvers(undefined, ACTIVITY), 1, 'activity on, both modules on');
116
+ assert.equal(await cardResolvers({ codegraph: false }, ACTIVITY), 1, 'Codegraph+ off does not take the card away');
117
+ });
118
+
119
+ test('is not a module surface: native leaves every row to the chain', async () => {
120
+ assert.equal(await cardResolvers(undefined, () => ({ kind: 'native' })), 0);
121
+ assert.equal(await cardResolvers({ codegraph: false }, () => ({ kind: 'native' })), 0);
122
+ assert.equal(await cardResolvers(undefined, undefined), 0, 'no reader, no switch, no card');
123
+ });
124
+ });
125
+
126
+ describe('both off', () => {
127
+ test('the package keeps its transversal surface and adds neither half', async () => {
128
+ const off = await load({ codegraph: false, worktrees: false });
129
+ assert.equal(await promptOf(off, ['codegraph']), '');
130
+ assert.equal(off.tools.size, 0);
131
+ for (const name of ['odd', 'files', 'issues']) assert.ok(off.commands.has(name), `${name} stays`);
132
+ });
133
+ });
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+ // S1/S3 (modular-tools): the two module switches, `Codegraph+` and `Worktrees+`. The
3
+ // module reads and writes one persisted document through the bridge's store, builds the
4
+ // `Tools` page's rows and says one short thing after a change. It is pure over the
5
+ // injected bridge, so nothing here loads the extension.
6
+ const { test, describe } = require('node:test');
7
+ const assert = require('node:assert/strict');
8
+
9
+ const modules = require('../lib/modules.js');
10
+
11
+ // A bridge whose `createStore` keeps one in-memory file per plugin id, like the real one.
12
+ function fakeBridge(initial = {}) {
13
+ const files = new Map(Object.entries(initial));
14
+ const writes = [];
15
+ const createStore = (id) => ({
16
+ get: (key, fallback) => (files.get(id)?.[key] !== undefined ? files.get(id)[key] : fallback),
17
+ set: (key, value) => {
18
+ files.set(id, { ...(files.get(id) ?? {}), [key]: value });
19
+ writes.push([id, key, value]);
20
+ },
21
+ });
22
+ return { api: { createStore }, files, writes };
23
+ }
24
+
25
+ describe('reading the switches', () => {
26
+ test('both modules are on when nothing is stored, and for every malformed document', () => {
27
+ assert.deepEqual(modules.readModules(fakeBridge().api), { codegraph: true, worktrees: true });
28
+ for (const bad of [null, 42, 'off', [], { codegraph: 'no' }, { worktrees: null }]) {
29
+ const { api } = fakeBridge({ 'odd-worktree': { modules: bad } });
30
+ const read = modules.readModules(api);
31
+ assert.equal(read.codegraph, true, JSON.stringify(bad));
32
+ assert.equal(read.worktrees, true, JSON.stringify(bad));
33
+ }
34
+ });
35
+
36
+ test('a stored false switches exactly that module off', () => {
37
+ const { api } = fakeBridge({ 'odd-worktree': { modules: { codegraph: false } } });
38
+ assert.deepEqual(modules.readModules(api), { codegraph: false, worktrees: true });
39
+ });
40
+
41
+ test('no bridge, no createStore and a throwing store all read as on and never throw', () => {
42
+ for (const api of [null, undefined, {}, { createStore: () => { throw new Error('disk'); } }]) {
43
+ assert.deepEqual(modules.readModules(api), { codegraph: true, worktrees: true });
44
+ }
45
+ });
46
+ });
47
+
48
+ describe('writing a switch', () => {
49
+ test('writes one key and keeps the other module and every other key of the document', () => {
50
+ const bridge = fakeBridge({ 'odd-worktree': { modules: { worktrees: false }, other: 1 } });
51
+ assert.equal(modules.writeModule(bridge.api, 'codegraph', false), true);
52
+ assert.deepEqual(bridge.files.get('odd-worktree'), { modules: { worktrees: false, codegraph: false }, other: 1 });
53
+ });
54
+
55
+ test('a failing store or an unknown module writes nothing and reports false', () => {
56
+ assert.equal(modules.writeModule({ createStore: () => { throw new Error('disk'); } }, 'codegraph', false), false);
57
+ const bridge = fakeBridge();
58
+ assert.equal(modules.writeModule(bridge.api, 'nope', false), false);
59
+ assert.deepEqual(bridge.writes, []);
60
+ });
61
+ });
62
+
63
+ describe('the Tools page rows', () => {
64
+ const rowsOf = (bridge, notices = []) => modules.moduleRowsProvider({ api: bridge.api, notify: (text) => notices.push(text) }).rows({});
65
+
66
+ test('one provider on the `Tools` page, two Off/On toggles named exactly like the switches', () => {
67
+ const provider = modules.moduleRowsProvider({ api: fakeBridge().api, notify: () => {} });
68
+ assert.equal(provider.category, 'Tools');
69
+ assert.equal(typeof provider.id, 'string');
70
+ const rows = provider.rows({});
71
+ assert.deepEqual(rows.map((row) => [row.choice.setting, row.choice.value]), [
72
+ ['Codegraph+', 'Off'], ['Codegraph+', 'On'], ['Worktrees+', 'Off'], ['Worktrees+', 'On'],
73
+ ]);
74
+ for (const row of rows) {
75
+ assert.equal(row.category, 'Tools');
76
+ assert.match(row.choice.setting, /^[A-Za-z]+\+?$/, 'a row name the bridge accepts');
77
+ assert.equal(typeof row.action, 'function');
78
+ }
79
+ });
80
+
81
+ test('current() follows the stored value, On by default', () => {
82
+ const bridge = fakeBridge({ 'odd-worktree': { modules: { worktrees: false } } });
83
+ const rows = rowsOf(bridge);
84
+ assert.deepEqual(rows.map((row) => row.choice.current()), [false, true, true, false]);
85
+ });
86
+
87
+ test('Enter persists first, then says one short thing about the restart', async () => {
88
+ const bridge = fakeBridge();
89
+ const notices = [];
90
+ const rows = rowsOf(bridge, notices);
91
+ await rows[0].action();
92
+ assert.deepEqual(bridge.files.get('odd-worktree').modules, { codegraph: false });
93
+ assert.equal(notices.length, 1);
94
+ assert.match(notices[0], /^Codegraph\+ Off/);
95
+ assert.match(notices[0], /\/reload/);
96
+ assert.match(notices[0], /new session/);
97
+ assert.ok(notices[0].length < 100, `short: ${notices[0]}`);
98
+ assert.equal(rows[0].choice.current(), true, 'the same page reads the new value');
99
+ });
100
+
101
+ test('choosing the value it already has changes nothing and says nothing', async () => {
102
+ const bridge = fakeBridge();
103
+ const notices = [];
104
+ const rows = rowsOf(bridge, notices);
105
+ await rows[3].action();
106
+ assert.deepEqual(bridge.writes, []);
107
+ assert.deepEqual(notices, []);
108
+ });
109
+
110
+ test('a store that cannot write says nothing and never throws', async () => {
111
+ const api = { createStore: () => ({ get: (_k, fallback) => fallback, set: () => { throw new Error('disk'); } }) };
112
+ const notices = [];
113
+ const rows = modules.moduleRowsProvider({ api, notify: (text) => notices.push(text) }).rows({});
114
+ await assert.doesNotReject(async () => rows[0].action());
115
+ assert.deepEqual(notices, []);
116
+ });
117
+
118
+ test('a throwing notify never fails the action', async () => {
119
+ const bridge = fakeBridge();
120
+ const rows = modules.moduleRowsProvider({ api: bridge.api, notify: () => { throw new Error('ui gone'); } }).rows({});
121
+ await assert.doesNotReject(async () => rows[0].action());
122
+ assert.deepEqual(bridge.files.get('odd-worktree').modules, { codegraph: false });
123
+ });
124
+ });
@@ -1,8 +1,7 @@
1
1
  'use strict';
2
- // S7 and (T3) S5: the `## ODD worktrees` section and its append-only injection. The
3
- // text is the contract, so it is asserted verbatim. There is exactly ONE primary
4
- // section, plus the one short block a child that WRITES gets (S5): the same heading,
5
- // its own file, and only for the three kinds of writing child.
2
+ // S7: the `## ODD worktrees` section and its append-only injection. The text is the
3
+ // contract, so it is asserted verbatim. There is exactly ONE section, for the primary
4
+ // session only: a child gets none of it.
6
5
  const { test, describe, after } = require('node:test');
7
6
  const assert = require('node:assert/strict');
8
7
  const os = require('node:os');
@@ -16,17 +15,7 @@ const PROMPT_DIR = path.resolve(__dirname, '..', 'lib', 'odd-prompt');
16
15
  const SECTION_FILE = path.join(PROMPT_DIR, 'odd-worktrees.md');
17
16
  const SECTION = fs.readFileSync(SECTION_FILE, 'utf8').trim();
18
17
 
19
- // S5: the one-line block a CHILD that writes gets. It lives in its own file, so it is
20
- // read here the way it is read on disk; a file that is gone fails the cases below.
21
- const CHILD_FILE = path.join(PROMPT_DIR, 'odd-worktrees-child.md');
22
- const childSection = () => fs.readFileSync(CHILD_FILE, 'utf8').trim();
23
-
24
- // The argv a subagent child really runs with: one directory named after the agent.
25
- function childArgv(agent) {
26
- if (typeof agent !== 'string') return ['node', path.join(os.tmpdir(), 'plain-agent', 'instructions.md')];
27
- return ['node', path.join(os.tmpdir(), `gentle-pi-subagent-${agent}-ab12cd`, 'instructions.md')];
28
- }
29
-
18
+ // The argv-free child switch: a subagent child runs with this environment.
30
19
  const CHILD_ENV = { GENTLE_PI_AGENTS_CHILD: '1' };
31
20
 
32
21
  const savedEnv = { ...process.env };
@@ -104,13 +93,17 @@ describe('session gating', () => {
104
93
  }
105
94
  });
106
95
 
107
- test('a GENTLE_PI_AGENTS_CHILD session gets the child block, never the primary one', () => {
96
+ test('a GENTLE_PI_AGENTS_CHILD session gets nothing, whatever agent it is', () => {
108
97
  clearEnv();
109
98
  process.env.GENTLE_PI_AGENTS_CHILD = '1';
99
+ for (const argv of [undefined, ['node', '/tmp/gentle-pi-subagent-gentle-ai-worker-ab12cd/instructions.md']]) {
100
+ const options = {};
101
+ run(primaryEvent(options), { env: process.env, argv });
102
+ assert.equal(options.appendSystemPrompt, undefined);
103
+ }
110
104
  const options = {};
111
- run(primaryEvent(options), { env: process.env });
112
- assert.equal(options.appendSystemPrompt, childSection(), 'a child whose name cannot be read is the generic child');
113
- assert.notEqual(options.appendSystemPrompt, SECTION);
105
+ run(primaryEvent(options), { env: CHILD_ENV });
106
+ assert.equal(options.appendSystemPrompt, undefined);
114
107
  });
115
108
 
116
109
  test('ODD_WORKTREE_PROMPT=0 suppresses the block entirely', () => {
@@ -142,77 +135,6 @@ describe('extension wiring (T3)', () => {
142
135
  });
143
136
  });
144
137
 
145
- // ---------------------------------------------------------------------------
146
- // S5: the child block — one short line, and only for a child that writes.
147
- // ---------------------------------------------------------------------------
148
- describe('S5: a child that writes gets one short block', () => {
149
- test('the block lives in its own file, opens with the idempotency heading and states the rule in two sentences at most', () => {
150
- const text = childSection();
151
- assert.ok(text.startsWith('## ODD worktrees'), text.split('\n')[0]);
152
- assert.match(text.replace(/\s+/g, ' '), /work only under the worktree of your workspace root/i);
153
- assert.match(text.replace(/\s+/g, ' '), /primary checkout on the default branch/i);
154
- assert.match(text.replace(/\s+/g, ' '), /stop and report/i);
155
- assert.match(text.replace(/\s+/g, ' '), /instead of writing/i);
156
- const sentences = (text.replace(/\s+/g, ' ').match(/[.!?](\s|$)/g) || []).length;
157
- assert.ok(sentences <= 2, `two sentences at most, got ${sentences}`);
158
- assert.notEqual(text, SECTION, 'the child block is not the primary block');
159
- });
160
-
161
- test('gentle-ai-worker, jd-fix-agent and a child whose agent name cannot be read get it', () => {
162
- for (const agent of ['gentle-ai-worker', 'jd-fix-agent', undefined]) {
163
- const options = {};
164
- run(primaryEvent(options), { env: CHILD_ENV, argv: childArgv(agent) });
165
- assert.equal(options.appendSystemPrompt, childSection(), String(agent));
166
- }
167
- });
168
-
169
- test('a child whose name is outside the table is the generic child, and gets it too', () => {
170
- const options = {};
171
- run(primaryEvent(options), { env: CHILD_ENV, argv: childArgv('some-unknown-agent') });
172
- assert.equal(options.appendSystemPrompt, childSection());
173
- });
174
-
175
- test('explore, verify, the two judges and every review-* child get nothing', () => {
176
- for (const agent of ['gentle-ai-explore', 'gentle-ai-verify', 'jd-judge-a', 'jd-judge-b', 'review-a', 'review-verify']) {
177
- const options = {};
178
- run(primaryEvent(options), { env: CHILD_ENV, argv: childArgv(agent) });
179
- assert.equal(options.appendSystemPrompt, undefined, agent);
180
- }
181
- });
182
-
183
- test('a child block is appended after the harness text and is idempotent', () => {
184
- const harness = 'You are Pi.\n\nUse the tools.';
185
- const options = { appendSystemPrompt: harness };
186
- run(primaryEvent(options), { env: CHILD_ENV, argv: childArgv('gentle-ai-worker') });
187
- assert.ok(options.appendSystemPrompt.startsWith(harness), 'existing text is the prefix');
188
- assert.equal(options.appendSystemPrompt, `${harness}\n\n${childSection()}`);
189
- const once = options.appendSystemPrompt;
190
- run(primaryEvent(options), { env: CHILD_ENV, argv: childArgv('gentle-ai-worker') });
191
- assert.equal(options.appendSystemPrompt, once, 'a second call adds nothing');
192
- });
193
-
194
- test('ODD_WORKTREE_PROMPT=0 suppresses the child block too', () => {
195
- const options = {};
196
- run(primaryEvent(options), { env: { ...CHILD_ENV, ODD_WORKTREE_PROMPT: '0' }, argv: childArgv('gentle-ai-worker') });
197
- assert.equal(options.appendSystemPrompt, undefined);
198
- });
199
-
200
- test('the primary session keeps its own block, unchanged', () => {
201
- const options = {};
202
- run(primaryEvent(options), { env: {}, argv: childArgv('gentle-ai-worker') });
203
- assert.equal(options.appendSystemPrompt, SECTION, 'a primary session gets the primary block');
204
- assert.notEqual(SECTION, childSection());
205
- });
206
-
207
- test('a missing child file falls back to the heading alone, never a crash', () => {
208
- const missing = path.join(os.tmpdir(), `odd-prompt-missing-${process.pid}`, 'odd-worktrees-child.md');
209
- assert.equal(prompt.readPromptFile(missing), null);
210
- assert.equal(prompt.sectionFromFile(missing, prompt.CHILD_FALLBACK), prompt.CHILD_FALLBACK);
211
- assert.equal(prompt.CHILD_FALLBACK.trim(), '## ODD worktrees');
212
- assert.equal(prompt.CHILD_SECTION, childSection());
213
- });
214
- });
215
-
216
138
  describe('the section is prose on disk', () => {
217
139
  test('the section lives in its own Markdown file and is what gets injected', () => {
218
140
  assert.ok(fs.existsSync(SECTION_FILE), 'the section file exists');
@@ -13,7 +13,7 @@
13
13
  // worktree↔issue association.
14
14
  //
15
15
  // The bash activity is not a preference here: it is a design on gentle-shell-bridge's
16
- // own `Card tags` line, so the shipped surface is exactly four commands, two tools, one
16
+ // own `Card activity` line, so the shipped surface is exactly four commands, two tools, one
17
17
  // sidebar section, one tools design and the one `Cards` row group the two file-card
18
18
  // switches carry.
19
19
  //
@@ -72,7 +72,7 @@ describe('manifest', () => {
72
72
  // classifier and the one design registered on the bridge. The file cards add
73
73
  // their own four modules — a classifier, the card, its resolver and the document
74
74
  // body Pi's Markdown draws — and own no preference at all (S1): they are gated by
75
- // the bridge's `Card tags` line, which is the bridge's, not ours.
75
+ // the bridge's `Card activity` line, which is the bridge's, not ours.
76
76
  for (const kept of ['gh-issues.js', 'issue-preview.js', 'issues-view.js', 'warp-selector-view.js', 'odd-view.js', 'worktree-git.js', 'worktree-registry.js', 'worktree-session-guard.js', 'skill-read-guard.js', 'bash-activity.js', 'bash-inline-script.js', 'bash-design.js', 'bash-frame.js', 'diff-design.js', 'skill-odd-card.js', 'file-card.js', 'file-card-resolver.js', 'file-card-markdown.js']) {
77
77
  assert.ok(shipped.includes(kept), `lib/${kept} is shipped`);
78
78
  }
@@ -106,7 +106,7 @@ describe('registration', () => {
106
106
  }
107
107
 
108
108
  // S1: the two file-card switches and their document are gone, and the extension
109
- // names neither. The file card is gated by the bridge's own `Card tags` line.
109
+ // names neither. The file card is gated by the bridge's own `Card activity` line.
110
110
  assert.equal(source.includes('registerCardsCustomize'), false, 'no row provider is registered for a switch');
111
111
  assert.equal(source.includes('card-files'), false, 'the extension never names their document');
112
112
  const modules = fs.readdirSync(lib).filter((entry) => entry.endsWith('.js'));
@@ -163,7 +163,7 @@ describe('registration', () => {
163
163
  await loadExtension({});
164
164
  assert.deepEqual(
165
165
  bridge.designs.map((design) => [design.line, design.id, design.label]),
166
- [['tags', 'odd-worktree.bash-activity', 'activity'], ['diff', 'odd-worktree.diff', 'color']],
166
+ [['activity', 'odd-worktree.bash-activity', 'activity'], ['diff', 'odd-worktree.diff', 'color']],
167
167
  'one design per line, once each',
168
168
  );
169
169
  } finally {
@@ -229,12 +229,18 @@ describe('removed surface', () => {
229
229
 
230
230
  test('CodeGraph is wired through one registration and adds no command or tool (S2)', async () => {
231
231
  const source = stubbedSource();
232
- // The extension mentions CodeGraph only to require the prompt section and the one registration.
233
- const mentions = source.split('\n').filter((line) => /codegraph/i.test(line.replace(/\/\/.*$/, '')));
232
+ // The extension mentions CodeGraph to require the prompt section, the one registration and the
233
+ // CARD — which is a design of the `Card activity` line, registered outside the module switch; the
234
+ // `Codegraph+` switch's own lines (`oddModules`) are the gate in front of the first two.
235
+ const mentions = source.split('\n').filter((line) => !/oddModules/.test(line) && /codegraph/i.test(line.replace(/\/\/.*$/, '')));
234
236
  assert.deepEqual(
235
237
  mentions.map((line) => line.trim()),
236
- ['libRequire("codegraph-rules.js").appendCodegraphSection(event);', 'libRequire("codegraph-session.js").registerCodegraph(pi, { metrics: () => resolveWorktreeToolCardMetrics() });'],
237
- 'the only CodeGraph references in the extension are the prompt section and the one registration',
238
+ [
239
+ 'libRequire("codegraph-rules.js").appendCodegraphSection(event);',
240
+ 'libRequire("codegraph-session.js").registerCodegraph(pi, { metrics: () => resolveWorktreeToolCardMetrics() });',
241
+ 'libRequire("codegraph-card.js").registerCodegraphCard(pi, {',
242
+ ],
243
+ 'the CodeGraph references in the extension are the prompt section, the one registration and the card',
238
244
  );
239
245
  const { commands, tools } = await loadExtension({});
240
246
  for (const gone of ['codegraph-hook', 'codegraph-init', 'codegraph-sync', 'codegraph']) {
@@ -342,7 +342,7 @@ test("a result body is the tool's own text, wrapped, padded and closed by one ru
342
342
  assert.equal(listBody[0], 'project: gentle-shell');
343
343
  assert.equal(listBody[1], 'path: /clone');
344
344
  assert.equal(listBody[2], 'base: main@1a2b3c4', 'the main row names its base and carries no stored state suffix');
345
- assert.equal(listBody[3], '1 cards-v2 · feat/cards-v2', 'the row carries the checkout name and its branch');
345
+ assert.equal(listBody.slice(3).join(' ').replace(/\s+/g, ' ').trim(), '1 /clone-worktrees/cards-v2 · feat/cards-v2', 'the row carries the checkout path and its branch, wrapped');
346
346
  });
347
347
 
348
348
  test('a collapsed result shows at most three body rows and marks what it hides', () => {
@@ -28,12 +28,11 @@ const { spawnSync } = require('node:child_process');
28
28
  const { decideBashGuard } = require('../lib/worktree-guard.js');
29
29
  const { loadExtension } = require('./fixtures/load-extension.js');
30
30
 
31
- // The three refusals of S10, written out: a reworded sentence fails here.
31
+ // The two refusals of S10, written out: a reworded sentence fails here.
32
32
  const WORKTREE_ADD_REFUSAL = '`git worktree add` did not run: create the ODD\'s checkout with `worktree_create`.';
33
- const WORKTREE_LIST_REFUSAL = '`git worktree list` did not run: use `worktree_list` (`all: true` also shows checkouts outside `<repo-name>-worktrees`).';
34
33
  const BRANCH_SWITCH_REFUSAL = 'The branch switch did not run: the principal checkout stays on its default branch. Create the ODD\'s checkout with `worktree_create`.';
35
34
 
36
- const REFUSALS = [WORKTREE_ADD_REFUSAL, WORKTREE_LIST_REFUSAL, BRANCH_SWITCH_REFUSAL];
35
+ const REFUSALS = [WORKTREE_ADD_REFUSAL, BRANCH_SWITCH_REFUSAL];
37
36
 
38
37
  // The two checkouts one repository has: the principal (its root IS the common dir's
39
38
  // parent) and a linked worktree (it shares the principal's common dir).
@@ -95,7 +94,6 @@ describe('the refusals are one reminder each (S10)', () => {
95
94
  test('each one says its command did not run and names the tool that replaces it', () => {
96
95
  for (const [sentence, tool] of [
97
96
  [WORKTREE_ADD_REFUSAL, '`worktree_create`'],
98
- [WORKTREE_LIST_REFUSAL, '`worktree_list`'],
99
97
  [BRANCH_SWITCH_REFUSAL, '`worktree_create`'],
100
98
  ]) {
101
99
  assert.equal(sentence.includes('!'), false, `no exclamation: ${sentence}`);
@@ -112,15 +110,9 @@ describe('the refusals are one reminder each (S10)', () => {
112
110
  assert.equal(named.length, 1, `exactly one tool is named: ${sentence}`);
113
111
  }
114
112
  });
115
-
116
- test('the listing refusal names all: true for the worktrees outside the directory', () => {
117
- assert.match(WORKTREE_LIST_REFUSAL, /`worktree_list`/);
118
- assert.match(WORKTREE_LIST_REFUSAL, /`all: true`/);
119
- assert.match(WORKTREE_LIST_REFUSAL, /outside `<repo-name>-worktrees`/);
120
- });
121
113
  });
122
114
 
123
- // ---- S1 and S9: any cwd, text only ----
115
+ // ---- S1: any cwd, text only ----
124
116
 
125
117
  const WORKTREE_ADD_COMMANDS = [
126
118
  'git worktree add ../odd-a',
@@ -151,7 +143,7 @@ const WORKTREE_LIST_COMMANDS = [
151
143
  'echo $(git worktree list --porcelain)',
152
144
  ];
153
145
 
154
- describe('S1 and S9: worktree commands are refused in every cwd', () => {
146
+ describe('S1: the create command is refused in every cwd', () => {
155
147
  test('the add sequence is refused with the create refusal', () => {
156
148
  for (const command of WORKTREE_ADD_COMMANDS) {
157
149
  for (const [label, options] of [
@@ -165,12 +157,11 @@ describe('S1 and S9: worktree commands are refused in every cwd', () => {
165
157
  }
166
158
  });
167
159
 
168
- test('the list sequence is refused with the listing refusal', () => {
160
+ test('listing worktrees with Git is never refused, in any cwd', () => {
169
161
  for (const command of WORKTREE_LIST_COMMANDS) {
170
162
  for (const options of [{ identity: PRINCIPAL }, { identity: LINKED }, { identity: new Error('not a git repository') }]) {
171
- const { run, reads } = harness(options);
172
- assert.deepEqual(run(command), { block: true, reason: WORKTREE_LIST_REFUSAL }, command);
173
- assert.deepEqual(reads, { identity: 0, defaultBranch: 0, currentBranch: 0 }, `${command} reads no repository state`);
163
+ const { run } = harness(options);
164
+ assert.deepEqual(run(command), { block: false }, command);
174
165
  }
175
166
  }
176
167
  });
@@ -433,10 +424,10 @@ describe('S11: a cd moves the checkout the switch is judged in', () => {
433
424
  }
434
425
  });
435
426
 
436
- test('S1 and S9 stay any-cwd: a cd never shelters a worktree command', () => {
427
+ test('S1 stays any-cwd: a cd never shelters a worktree command', () => {
437
428
  const { run } = harness({ identity: identityByCwd });
438
429
  assert.deepEqual(run(`cd ${LINKED.root} && git worktree add ../odd-b`), { block: true, reason: WORKTREE_ADD_REFUSAL });
439
- assert.deepEqual(run('cd $HOME && git worktree list'), { block: true, reason: WORKTREE_LIST_REFUSAL });
430
+ assert.deepEqual(run('cd $HOME && git worktree list'), { block: false });
440
431
  });
441
432
  });
442
433
 
@@ -474,10 +465,10 @@ describe('S4: a slash-named ref is a branch, not a path', () => {
474
465
  });
475
466
  });
476
467
 
477
- describe('S1 and S9: the sequence is found wherever the text puts it', () => {
468
+ describe('S1: the sequence is found wherever the text puts it', () => {
478
469
  test('a subshell, a quoted shell command and a line continuation still refuse', () => {
479
- for (const verb of ['add ../odd-probe', 'list']) {
480
- const reason = verb.startsWith('add') ? WORKTREE_ADD_REFUSAL : WORKTREE_LIST_REFUSAL;
470
+ for (const verb of ['add ../odd-probe']) {
471
+ const reason = WORKTREE_ADD_REFUSAL;
481
472
  for (const command of [
482
473
  `(git worktree ${verb})`,
483
474
  `bash -c 'git worktree ${verb}'`,
@@ -582,13 +573,13 @@ describe('S6: everything else passes', () => {
582
573
  // ---- S8: honest failure, never a false block ----
583
574
 
584
575
  describe('S8: an unreadable repository fails open, and nothing throws', () => {
585
- test('without an identity only S1 and S9 apply', () => {
576
+ test('without an identity only S1 applies', () => {
586
577
  for (const identity of [new Error('not a git repository'), undefined, null, {}, { root: '/repo' }]) {
587
578
  const { run } = harness({ identity });
588
579
  assert.deepEqual(run('git checkout -b feat/odd-a'), { block: false }, String(identity));
589
580
  assert.deepEqual(run('git checkout develop'), { block: false }, String(identity));
590
581
  assert.deepEqual(run('git worktree add ../odd-a'), { block: true, reason: WORKTREE_ADD_REFUSAL }, String(identity));
591
- assert.deepEqual(run('git worktree list'), { block: true, reason: WORKTREE_LIST_REFUSAL }, String(identity));
582
+ assert.deepEqual(run('git worktree list'), { block: false }, String(identity));
592
583
  }
593
584
  });
594
585
 
@@ -686,7 +677,7 @@ describe('the tool_call handler the extension registers', () => {
686
677
  }
687
678
  });
688
679
 
689
- test('refuses worktree creation and listing in any cwd', async () => {
680
+ test('refuses worktree creation in any cwd and lets listing through', async () => {
690
681
  for (const cwd of [principal, linked, outside]) {
691
682
  assert.deepEqual(
692
683
  await callTool(loaded.hooks, bash('git worktree add ../odd-b'), cwd),
@@ -695,7 +686,7 @@ describe('the tool_call handler the extension registers', () => {
695
686
  );
696
687
  assert.deepEqual(
697
688
  await callTool(loaded.hooks, bash('git worktree list --porcelain'), cwd),
698
- { block: true, reason: WORKTREE_LIST_REFUSAL },
689
+ undefined,
699
690
  `list in ${cwd}`,
700
691
  );
701
692
  assert.deepEqual(
@@ -6,7 +6,7 @@
6
6
  //
7
7
  // S2: the default view is the checkouts this package created plus the main one.
8
8
  // S2/S3: `all` adds the worktrees Git knows outside `<repo-name>-worktrees`.
9
- // S3: a row is its directory's basename (the ODD) and its branch — no `odd:` field, no
9
+ // S3: a row is the checkout's absolute path (whose last segment is the ODD) and its branch — no `odd:` field, no
10
10
  // date, no setup or hooks line, no stored state. A directory that exists is a worktree
11
11
  // and one that does not is simply not listed.
12
12
 
@@ -59,13 +59,13 @@ test('prints project, path, the unnumbered main checkout and the created worktre
59
59
  'project: demo',
60
60
  'path: /work/demo',
61
61
  'base: main@1a2b3c4',
62
- '1 alpha · feat/alpha',
63
- '2 zeta · feat/zeta',
62
+ '1 /work/demo-worktrees/alpha · feat/alpha',
63
+ '2 /work/demo-worktrees/zeta · feat/zeta',
64
64
  ].join('\n'));
65
65
  assertPlainLines(view.text);
66
66
  });
67
67
 
68
- test('each row is the directory basename — the ODD — and the branch, and nothing else', () => {
68
+ test('each row is the absolute path, whose last segment is the ODD, and the branch, and nothing else', () => {
69
69
  const view = viewOf({ entries: [MAIN, entry(`${WORKTREES}/worktree-surface`, 'feat/surface')] });
70
70
  const row = view.details.worktrees[1];
71
71
  assert.equal(row.name, 'worktree-surface', 'the ODD is the directory basename');
@@ -109,9 +109,9 @@ test('all adds the worktrees outside the canonical directory, after ours and by
109
109
  'project: demo',
110
110
  'path: /work/demo',
111
111
  'base: main@1a2b3c4',
112
- '1 alpha · feat/alpha',
113
- '2 beta · feat/beta',
114
- '3 gamma · -',
112
+ '1 /work/demo-worktrees/alpha · feat/alpha',
113
+ '2 /elsewhere/beta · feat/beta',
114
+ '3 /elsewhere/gamma · -',
115
115
  ].join('|'));
116
116
  assert.deepEqual(worktreeListFooters(view.details), [], 'nothing is hidden when everything is listed');
117
117
  assert.equal('foreign' in view.details, false, 'no state field decides what a row is');
@@ -120,7 +120,7 @@ test('all adds the worktrees outside the canonical directory, after ours and by
120
120
  test('a detached checkout prints a dash instead of inventing a branch', () => {
121
121
  const view = viewOf({ entries: [MAIN, entry(`${WORKTREES}/alpha`, null)] });
122
122
  assert.equal(view.details.worktrees[1].branch, '-');
123
- assert.equal(view.text.split('\n').at(-1), '1 alpha · -');
123
+ assert.equal(view.text.split('\n').at(-1), '1 /work/demo-worktrees/alpha · -');
124
124
  });
125
125
 
126
126
  test('the main row prints first and unnumbered, as Git lists it', () => {
@@ -292,7 +292,7 @@ describe('worktree_create', () => {
292
292
  `project: ${path.basename(repo)}`,
293
293
  `path: ${fs.realpathSync(repo)}`,
294
294
  `base: main@${shortHead(repo)}`,
295
- '1 odd-x · feat/x',
295
+ `1 ${target} · feat/x`,
296
296
  ]);
297
297
  assert.equal(listed.details.worktrees[1].name, 'odd-x', 'the ODD is the directory basename');
298
298
  assert.equal('odd' in listed.details.worktrees[1], false, 'the output carries no odd field');
@@ -440,7 +440,7 @@ describe('the tool_call handler the extension registers (S4)', () => {
440
440
  assert.equal(await callTool({ toolName: 'read', input: { path: target } }, PRINCIPAL), undefined);
441
441
  assert.equal(await callTool({ toolName: 'grep', input: { pattern: 'x', path: PRINCIPAL } }, PRINCIPAL), undefined);
442
442
  assert.deepEqual(await callTool(bash('git worktree add ../odd-b'), PRINCIPAL), { block: true, reason: WORKTREE_ADD_REFUSAL });
443
- assert.deepEqual(await callTool(bash('git worktree list --porcelain'), PRINCIPAL), { block: true, reason: '`git worktree list` did not run: use `worktree_list` (`all: true` also shows checkouts outside `<repo-name>-worktrees`).' });
443
+ assert.equal(await callTool(bash('git worktree list --porcelain'), PRINCIPAL), undefined);
444
444
  assert.deepEqual(await callTool(bash('git switch develop'), PRINCIPAL), { block: true, reason: BRANCH_SWITCH_REFUSAL });
445
445
  assert.equal(await callTool(bash('git switch develop'), linked), undefined);
446
446
  assert.equal(await callTool(bash('git status'), PRINCIPAL), undefined);