pi-odd-worktree 2.1.0 → 3.0.1

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.
Files changed (160) hide show
  1. package/README.md +54 -319
  2. package/extensions/odd-worktree-tools.ts +4182 -2539
  3. package/lib/bash-activity.js +1166 -0
  4. package/lib/bash-design.js +684 -0
  5. package/lib/bash-destructive.js +559 -0
  6. package/lib/bash-frame.js +205 -0
  7. package/lib/card-content.js +23 -0
  8. package/lib/card-style.js +175 -0
  9. package/lib/checkout-facts.js +30 -70
  10. package/lib/codegraph-card-preview.js +628 -0
  11. package/lib/codegraph-card.js +515 -0
  12. package/lib/codegraph-compaction.js +76 -0
  13. package/lib/codegraph-daemon.js +246 -0
  14. package/lib/codegraph-edit-sync.js +182 -0
  15. package/lib/codegraph-guard-target.js +337 -0
  16. package/lib/codegraph-guard.js +211 -0
  17. package/lib/codegraph-index.js +1020 -0
  18. package/lib/codegraph-lock.js +607 -0
  19. package/lib/codegraph-mcp-config.js +134 -0
  20. package/lib/codegraph-mcp.js +123 -0
  21. package/lib/codegraph-paths.js +69 -0
  22. package/lib/codegraph-prompt/explore.md +11 -0
  23. package/lib/codegraph-prompt/fix.md +6 -0
  24. package/lib/codegraph-prompt/generic.md +8 -0
  25. package/lib/codegraph-prompt/judge.md +9 -0
  26. package/lib/codegraph-prompt/orchestrator.md +17 -0
  27. package/lib/codegraph-prompt/verify.md +10 -0
  28. package/lib/codegraph-prompt/worker.md +7 -0
  29. package/lib/codegraph-role.js +55 -0
  30. package/lib/codegraph-rules.js +146 -0
  31. package/lib/codegraph-session.js +303 -383
  32. package/lib/codegraph-warmup.js +139 -0
  33. package/lib/file-card-markdown.js +141 -0
  34. package/lib/file-card-resolver.js +245 -0
  35. package/lib/file-card.js +659 -0
  36. package/lib/files-index.js +387 -0
  37. package/lib/files-insert.js +81 -0
  38. package/lib/files-orders.js +326 -0
  39. package/lib/files-picker-view.js +1421 -0
  40. package/lib/files-preview.js +338 -0
  41. package/lib/files-scope-detail.js +171 -0
  42. package/lib/files-scope-view.js +507 -0
  43. package/lib/gh-issues.js +323 -15
  44. package/lib/issue-preview.js +26 -7
  45. package/lib/issues-bash-mutation.js +206 -0
  46. package/lib/issues-cache-store.js +261 -0
  47. package/lib/issues-section.js +710 -0
  48. package/lib/issues-view.js +649 -52
  49. package/lib/odd-prompt/odd-worktrees.md +21 -0
  50. package/lib/odd-worktrees-prompt.js +10 -28
  51. package/lib/related-issues-cache.js +210 -0
  52. package/lib/shell-card.js +825 -0
  53. package/lib/skill-odd-card.js +183 -0
  54. package/lib/tui-paint.js +4 -5
  55. package/lib/warp-create-panel.js +538 -250
  56. package/lib/warp-create-picker.js +56 -9
  57. package/lib/warp-delete-confirm.js +19 -28
  58. package/lib/warp-selector-view.js +160 -82
  59. package/lib/which-command.js +90 -0
  60. package/lib/worktree-card.js +267 -897
  61. package/lib/worktree-cards.js +383 -0
  62. package/lib/worktree-create.js +287 -0
  63. package/lib/worktree-git.js +3 -3
  64. package/lib/worktree-guard.js +548 -0
  65. package/lib/worktree-hooks.js +421 -712
  66. package/lib/worktree-list.js +120 -0
  67. package/lib/worktree-registry.js +162 -879
  68. package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
  69. package/lib/worktree-setup-runner.js +376 -0
  70. package/lib/worktree-setup.js +140 -0
  71. package/lib/worktree-warp-busy.js +462 -85
  72. package/lib/worktree-warp-sessions.js +1 -2
  73. package/package.json +2 -2
  74. package/tools/bash-activity.test.js +1420 -0
  75. package/tools/bash-design.test.js +1093 -0
  76. package/tools/bash-destructive.test.js +139 -0
  77. package/tools/card-content.test.js +44 -0
  78. package/tools/card-style.test.js +298 -0
  79. package/tools/codegraph-card-preview.test.js +254 -0
  80. package/tools/codegraph-card.test.js +1080 -0
  81. package/tools/codegraph-compaction.test.js +378 -0
  82. package/tools/codegraph-daemon.test.js +248 -0
  83. package/tools/codegraph-edit-sync.test.js +295 -0
  84. package/tools/codegraph-guard-target.test.js +174 -0
  85. package/tools/codegraph-guard.test.js +238 -0
  86. package/tools/codegraph-index.test.js +1948 -0
  87. package/tools/codegraph-lock.test.js +932 -0
  88. package/tools/codegraph-mcp-config.test.js +181 -0
  89. package/tools/codegraph-mcp.test.js +194 -0
  90. package/tools/codegraph-paths.test.js +44 -0
  91. package/tools/codegraph-role.test.js +30 -0
  92. package/tools/codegraph-rules.test.js +250 -0
  93. package/tools/codegraph-session.test.js +660 -391
  94. package/tools/codegraph-warmup.test.js +316 -0
  95. package/tools/commands.test.js +510 -31
  96. package/tools/file-card-markdown.test.js +188 -0
  97. package/tools/file-card.test.js +1289 -0
  98. package/tools/files-bridge.test.js +575 -0
  99. package/tools/files-command.test.js +613 -0
  100. package/tools/files-index.test.js +473 -0
  101. package/tools/files-insert.test.js +139 -0
  102. package/tools/files-orders.test.js +597 -0
  103. package/tools/files-picker-view.test.js +1889 -0
  104. package/tools/files-preview.test.js +452 -0
  105. package/tools/files-scope-detail.test.js +264 -0
  106. package/tools/files-scope-view.test.js +614 -0
  107. package/tools/fixtures/card-codegraph-outputs.js +110 -0
  108. package/tools/fixtures/codegraph-cli-stub.js +16 -0
  109. package/tools/fixtures/codegraph-init-process.js +28 -0
  110. package/tools/fixtures/codegraph-lock-worker.js +117 -0
  111. package/tools/fixtures/daemon-fake.js +98 -0
  112. package/tools/fixtures/daemon-mcp-server.js +39 -0
  113. package/tools/fixtures/daemon-warmup-worker.js +12 -0
  114. package/tools/fixtures/load-extension.js +136 -3
  115. package/tools/gh-issues-feedback.test.js +31 -7
  116. package/tools/gh-issues.test.js +417 -1
  117. package/tools/issue-preview.test.js +44 -7
  118. package/tools/issues-bash-mutation.test.js +101 -0
  119. package/tools/issues-cache-store.test.js +222 -0
  120. package/tools/issues-command.test.js +1517 -67
  121. package/tools/issues-open-guard.test.js +1096 -0
  122. package/tools/issues-section.test.js +4235 -0
  123. package/tools/issues-seed-query-regression.test.js +67 -0
  124. package/tools/issues-view.test.js +1489 -60
  125. package/tools/odd-worktrees-prompt.test.js +98 -65
  126. package/tools/package-surface.test.js +431 -36
  127. package/tools/related-issues-cache.test.js +324 -0
  128. package/tools/shell-card.test.js +834 -0
  129. package/tools/skill-odd-card.test.js +200 -0
  130. package/tools/t5-session-identity.test.js +44 -22
  131. package/tools/warp-busy-guard.test.js +2565 -309
  132. package/tools/warp-create-panel.test.js +499 -74
  133. package/tools/warp-create-picker.test.js +101 -5
  134. package/tools/warp-delete-confirm.test.js +49 -15
  135. package/tools/warp-empty-session.test.js +0 -1
  136. package/tools/warp-fallback-regression.test.js +533 -0
  137. package/tools/warp-selector-view.test.js +460 -196
  138. package/tools/which-command.test.js +126 -0
  139. package/tools/worktree-card.test.js +551 -0
  140. package/tools/worktree-cards.test.js +845 -0
  141. package/tools/worktree-changes.test.js +4 -5
  142. package/tools/worktree-create.test.js +489 -0
  143. package/tools/worktree-guard.test.js +823 -0
  144. package/tools/worktree-hooks.test.js +905 -0
  145. package/tools/worktree-list.test.js +170 -0
  146. package/tools/worktree-registry.test.js +89 -230
  147. package/tools/worktree-remove-async.test.js +318 -0
  148. package/tools/worktree-setup-runner.test.js +276 -0
  149. package/tools/worktree-setup.test.js +140 -0
  150. package/tools/worktree-tools.test.js +419 -199
  151. package/lib/codegraph-commands.js +0 -165
  152. package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
  153. package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
  154. package/lib/worktree-model-result.js +0 -291
  155. package/tools/codegraph-commands.test.js +0 -371
  156. package/tools/herdr-free-create.test.js +0 -161
  157. package/tools/worktree-close-herdr-async.test.js +0 -204
  158. package/tools/worktree-odd-migration.test.js +0 -224
  159. package/tools/worktree-registry-cache.test.js +0 -163
  160. package/tools/worktree-registry-odd.test.js +0 -231
@@ -0,0 +1,1080 @@
1
+ 'use strict';
2
+ // S10: the CodeGraph card, drawn on this package's own card substrate
3
+ // (lib/shell-card.js) through the host's `registerToolRenderer` resolver.
4
+ //
5
+ // Every case goes through the module's public surface: the pure row builders
6
+ // (`codegraphCallRows`, `codegraphResultRows`, `codegraphShape`) and the resolver
7
+ // `createCodegraphCardResolver` hands back, read as the lines a component draws
8
+ // for a width. Nothing reads module-internal state, a repository, an index or a
9
+ // terminal, and no case spawns anything.
10
+ //
11
+ // The text seam and the themes are the fakes tools/worktree-cards.test.js uses:
12
+ // this package has no node_modules, so width measurement, truncation and
13
+ // wrapping are injected, and colour only ever arrives as `theme.fg(role, text)`.
14
+ const assert = require('node:assert/strict');
15
+ const { mkdtempSync, readFileSync, rmSync, writeFileSync } = require('node:fs');
16
+ const { tmpdir } = require('node:os');
17
+ const { join } = require('node:path');
18
+ const { after, before, test } = require('node:test');
19
+ const { pathToFileURL } = require('node:url');
20
+
21
+ const { LIB_DIR, stubbedSource, installDefaultBridge } = require('./fixtures/load-extension.js');
22
+
23
+ const {
24
+ CARD_CONTENT,
25
+ CODEGRAPH_MARK,
26
+ CODEGRAPH_MCP_TOOL,
27
+ CODEGRAPH_TITLE_ROLE,
28
+ CODEGRAPH_TOOL,
29
+ cardContentLevel,
30
+ codegraphCallRows,
31
+ codegraphResultRows,
32
+ codegraphShape,
33
+ createCodegraphCardResolver,
34
+ isCodeGraphCardTool,
35
+ } = require('../lib/codegraph-card.js');
36
+ const { CARD_STYLE } = require('../lib/card-style.js');
37
+ const {
38
+ EXPLORE,
39
+ INIT_EXISTING,
40
+ INIT_FAILED,
41
+ INIT_FRESH,
42
+ QUERY,
43
+ SYNC_CHANGED,
44
+ } = require('./fixtures/card-codegraph-outputs.js');
45
+
46
+ const MCP_PREFIXED_TOOL = 'mcp__codegraph__codegraph_explore';
47
+
48
+ // ---- the injected text seam (fakes: plain ASCII, each character one column) ----
49
+
50
+ const ANSI = /\x1b\[[0-9;]*m/g;
51
+ const stripAnsi = (value) => value.replace(ANSI, '');
52
+ const chars = (value) => [...stripAnsi(value)];
53
+
54
+ const metrics = {
55
+ visibleWidth(value) {
56
+ return chars(value).length;
57
+ },
58
+ truncateToWidth(value, width, ellipsis = '') {
59
+ if (width <= 0) return '';
60
+ if (this.visibleWidth(value) <= width) return value;
61
+ const tail = ellipsis ?? '';
62
+ const keep = Math.max(0, width - [...tail].length);
63
+ return chars(value).slice(0, keep).join('') + tail;
64
+ },
65
+ wrapTextWithAnsi(value, width) {
66
+ const text = stripAnsi(value);
67
+ if (width <= 0) return [text];
68
+ return text.split('\n').flatMap((line) => {
69
+ const lines = [];
70
+ let current = '';
71
+ for (const word of line.split(' ')) {
72
+ const candidate = current === '' ? word : `${current} ${word}`;
73
+ if ([...candidate].length <= width) {
74
+ current = candidate;
75
+ continue;
76
+ }
77
+ if (current !== '') {
78
+ lines.push(current);
79
+ current = '';
80
+ }
81
+ if ([...word].length <= width) {
82
+ current = word;
83
+ continue;
84
+ }
85
+ const rest = [...word];
86
+ while (rest.length > width) lines.push(rest.splice(0, width).join(''));
87
+ current = rest.join('');
88
+ }
89
+ lines.push(current);
90
+ return lines;
91
+ });
92
+ },
93
+ };
94
+
95
+ // ---- themes: a theme is an injected fg(role, text) ----
96
+
97
+ const plainTheme = {
98
+ fg(_role, value) {
99
+ return value;
100
+ },
101
+ };
102
+
103
+ /** A theme that can also paint the float background, so the text stays readable. */
104
+ function paintTheme() {
105
+ const roles = { fg: [], bg: [] };
106
+ return {
107
+ roles,
108
+ fg(role, value) {
109
+ roles.fg.push(role);
110
+ return value;
111
+ },
112
+ bg(role, value) {
113
+ roles.bg.push(role);
114
+ return `\x1b[48;5;240m${value}\x1b[49m`;
115
+ },
116
+ };
117
+ }
118
+
119
+ const taggedTheme = {
120
+ fg(role, value) {
121
+ return `<${role}>${value}</${role}>`;
122
+ },
123
+ };
124
+
125
+ function recordingTheme() {
126
+ const roles = [];
127
+ return {
128
+ roles,
129
+ fg(role, value) {
130
+ roles.push(role);
131
+ return value;
132
+ },
133
+ };
134
+ }
135
+
136
+ /** A theme that names every role it paints and can paint the float background, so a cell's role is readable. */
137
+ function railTheme() {
138
+ const roles = { fg: [], bg: [] };
139
+ return {
140
+ roles,
141
+ fg(role, value) {
142
+ roles.fg.push(role);
143
+ return `<${role}>${value}</${role}>`;
144
+ },
145
+ bg(role, value) {
146
+ roles.bg.push(role);
147
+ return `\x1b[48;5;240m${value}\x1b[49m`;
148
+ },
149
+ };
150
+ }
151
+
152
+ // S10: the style seam — the process-wide slot Gentle Shell publishes — and a
153
+ // scratch preference home, so no case reads or writes the real user's document.
154
+ const CARD_STYLE_SLOT = Symbol.for('gentle-pi.card-style');
155
+ const CARD_CONTENT_SLOT = Symbol.for('gentle-pi.card-content');
156
+
157
+ const savedHome = process.env.GENTLE_PI_CONFIG_HOME;
158
+ let configHome;
159
+
160
+ before(() => {
161
+ configHome = mkdtempSync(join(tmpdir(), 'odd-worktree-codegraph-card-'));
162
+ process.env.GENTLE_PI_CONFIG_HOME = configHome;
163
+ globalThis[CARD_STYLE_SLOT] = CARD_STYLE.NEON;
164
+ });
165
+
166
+ after(() => {
167
+ delete globalThis[CARD_STYLE_SLOT];
168
+ delete globalThis[CARD_CONTENT_SLOT];
169
+ if (savedHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
170
+ else process.env.GENTLE_PI_CONFIG_HOME = savedHome;
171
+ rmSync(configHome, { recursive: true, force: true });
172
+ });
173
+
174
+ function withContent(content, run) {
175
+ if (content === undefined) delete globalThis[CARD_CONTENT_SLOT];
176
+ else globalThis[CARD_CONTENT_SLOT] = content;
177
+ try {
178
+ return run();
179
+ } finally {
180
+ delete globalThis[CARD_CONTENT_SLOT];
181
+ }
182
+ }
183
+
184
+ // ---- the resolver under test ----
185
+
186
+ /** No hook at all would be the host's own: every case here registers through the probe. */
187
+ function cardFor(options) {
188
+ const registered = [];
189
+ const cards = createCodegraphCardResolver({
190
+ metrics,
191
+ theme: plainTheme,
192
+ registerToolRenderer: (resolver) => registered.push(resolver),
193
+ ...options,
194
+ });
195
+ assert.equal(cards.registered, true, 'the probe accepted the resolver');
196
+ assert.equal(registered.length, 1, 'exactly one resolver reached the host hook');
197
+ return registered[0];
198
+ }
199
+
200
+ /** A host that draws bash itself: its renderers draw nothing here, which is all a forwarded row needs to be. */
201
+ const HOST_BASH = {
202
+ renderShell: 'self',
203
+ renderCall: () => ({ render: () => [], invalidate() {} }),
204
+ renderResult: () => ({ render: () => [], invalidate() {} }),
205
+ };
206
+
207
+ /** One tool row as the host drives it: the resolver, then the slot it returned. */
208
+ function renderersFor(resolver, toolName, inherited) {
209
+ return resolver(toolName, () => (inherited === undefined && toolName === 'bash' ? HOST_BASH : inherited));
210
+ }
211
+
212
+ function callRows(resolver, toolName, args, theme, context, width) {
213
+ const slot = renderersFor(resolver, toolName);
214
+ assert.equal(typeof slot.renderCall, 'function', `${toolName} renders its call`);
215
+ return slot.renderCall(args, theme, context ?? {}).render(width);
216
+ }
217
+
218
+ function resultRows(resolver, toolName, result, options, theme, context, width) {
219
+ const slot = renderersFor(resolver, toolName);
220
+ assert.equal(typeof slot.renderResult, 'function', `${toolName} renders its result`);
221
+ return slot.renderResult(result, options, theme, context ?? {}).render(width);
222
+ }
223
+
224
+ function textResult(text, isError) {
225
+ return { content: [{ type: 'text', text }], details: {}, ...(isError ? { isError: true } : {}) };
226
+ }
227
+
228
+ /** The text a cell draws, with both the ANSI a real theme paints and the tags the fake theme wraps it in removed. */
229
+ const unpaint = (value) => stripAnsi(value).replace(/<\/?[a-zA-Z][a-zA-Z0-9]*>/g, '');
230
+
231
+ /** The visible content of a body row, without the neon frame. */
232
+ const bodyText = (row) => unpaint(row).replace(/^│ /, '').replace(/ +│$/, '');
233
+
234
+ /** Every row the card draws must be exactly the width the host asked for. */
235
+ function assertFramed(rows, width) {
236
+ for (const row of rows) assert.equal(metrics.visibleWidth(unpaint(row)), width, `"${unpaint(row)}" is not ${width} wide`);
237
+ }
238
+
239
+
240
+ // ---- the identity ----
241
+
242
+ test('the native tool, the MCP explore tool and a bash call are one card', () => {
243
+ assert.equal(CODEGRAPH_TOOL, 'codegraph');
244
+ assert.equal(CODEGRAPH_MCP_TOOL, 'codegraph_explore');
245
+ assert.equal(CODEGRAPH_MARK, '\u{F01BC}');
246
+ assert.equal(CODEGRAPH_TITLE_ROLE, 'mdCode');
247
+
248
+ assert.deepEqual(codegraphShape(CODEGRAPH_TOOL, { operation: 'explore', query: 'auth login' }), {
249
+ surface: 'tool',
250
+ operation: 'explore',
251
+ query: 'auth login',
252
+ });
253
+ // The MCP tool arrives under its bare name or the prefixed form the host reports.
254
+ for (const name of [CODEGRAPH_MCP_TOOL, MCP_PREFIXED_TOOL]) {
255
+ assert.deepEqual(codegraphShape(name, { query: 'auth login', maxFiles: 5 }), {
256
+ surface: 'mcp',
257
+ operation: 'explore',
258
+ query: 'auth login',
259
+ });
260
+ }
261
+ assert.deepEqual(codegraphShape('bash', { command: 'codegraph explore --path /tmp/ws -- auth login' }), {
262
+ surface: 'bash',
263
+ command: 'codegraph explore --path /tmp/ws -- auth login',
264
+ operation: 'explore',
265
+ query: 'auth login',
266
+ });
267
+
268
+ // The same call heads the same way whatever surface it came from: one program, one
269
+ // card. The two tools name the operation; the bash card names the command it ran.
270
+ const native = codegraphShape(CODEGRAPH_TOOL, { operation: 'explore', query: 'auth login' });
271
+ const mcp = codegraphShape(MCP_PREFIXED_TOOL, { query: 'auth login' });
272
+ const shell = codegraphShape('bash', { command: 'cd /tmp/ws && codegraph explore -- auth login' });
273
+ assert.deepEqual(codegraphCallRows(native), codegraphCallRows(mcp));
274
+ assert.equal(codegraphCallRows(shell)[0].text, codegraphCallRows(native)[0].text, 'one mark and one name');
275
+ assert.deepEqual(codegraphCallRows(native), [
276
+ { text: '\u{F01BC} codegraph', role: 'mdCode' },
277
+ { text: 'explore auth login', role: 'muted' },
278
+ ]);
279
+ assert.deepEqual(codegraphCallRows(shell)[1], { text: 'cd /tmp/ws && codegraph explore -- auth login', role: 'muted' }, 'a bash call names the command it ran');
280
+ // No row carries a colour or an escape of its own: the shell paints the roles above.
281
+ for (const row of codegraphCallRows(native)) {
282
+ assert.equal(row.text.includes(String.fromCharCode(27)), false, row.text);
283
+ assert.doesNotMatch(row.text, /#[0-9a-fA-F]{6}\b/, row.text);
284
+ }
285
+ });
286
+
287
+ test('S6: the MCP heading names the explored checkout briefly, and never its full path', () => {
288
+ const resolver = cardFor({ cwd: '/work/repo' });
289
+ const EXPLORED = '/home/jona/.pi/agent/git/github.com/Gentleman-Programming/gentle-shell';
290
+ const heading = (args, width = 120) => stripAnsi(callRows(resolver, MCP_PREFIXED_TOOL, args, plainTheme, { isPartial: false }, width)[0]);
291
+
292
+ const elsewhere = heading({ query: 'auth login', projectPath: EXPLORED });
293
+ assert.ok(elsewhere.includes(`${CODEGRAPH_MARK} codegraph · explore auth login · gentle-shell`), 'the last segment continues the heading');
294
+ assert.doesNotMatch(elsewhere, /Gentleman-Programming|\/home\/jona/, 'the full path never appears');
295
+
296
+ for (const projectPath of [undefined, '', '/work/repo', '/work/repo/']) {
297
+ const rows = heading({ query: 'auth login', ...(projectPath === undefined ? {} : { projectPath }) });
298
+ assert.match(rows, /codegraph · explore auth login/);
299
+ assert.doesNotMatch(rows, / · gentle-shell| · repo/, `${String(projectPath)} names no other checkout`);
300
+ }
301
+ assert.match(heading({ query: 'auth login', projectPath: 'gentle-shell' }), / · gentle-shell/, 'a bare name other than this checkout is named');
302
+ assert.doesNotMatch(
303
+ stripAnsi(callRows(cardFor({ cwd: '/work/repo/gentle-shell' }), MCP_PREFIXED_TOOL, { query: 'auth login', projectPath: 'gentle-shell' }, plainTheme, { isPartial: false }, 120)[0]),
304
+ / · gentle-shell/,
305
+ 'a bare name equal to the cwd name names no other checkout',
306
+ );
307
+
308
+ // The shape carries the segment for the MCP tool only, and reads the seam per paint.
309
+ assert.deepEqual(codegraphShape(MCP_PREFIXED_TOOL, { query: 'auth', projectPath: EXPLORED }, '/work/repo'), {
310
+ surface: 'mcp',
311
+ operation: 'explore',
312
+ query: 'auth',
313
+ project: 'gentle-shell',
314
+ });
315
+ assert.deepEqual(codegraphShape(MCP_PREFIXED_TOOL, { query: 'auth', projectPath: '/work/repo' }, '/work/repo'), { surface: 'mcp', operation: 'explore', query: 'auth' });
316
+ assert.deepEqual(codegraphShape(MCP_PREFIXED_TOOL, { query: 'auth', projectPath: EXPLORED }), { surface: 'mcp', operation: 'explore', query: 'auth', project: 'gentle-shell' }, 'an unanswerable seam shows the explicit argument');
317
+
318
+ // A seam that moves with the session re-decides on the next paint.
319
+ let cwd = '/work/repo';
320
+ const live = cardFor({ cwd: () => cwd });
321
+ const liveHeading = () => stripAnsi(callRows(live, MCP_PREFIXED_TOOL, { query: 'auth', projectPath: '/work/repo' }, plainTheme, { isPartial: false }, 120)[0]);
322
+ assert.doesNotMatch(liveHeading(), / · repo/);
323
+ cwd = '/work/other';
324
+ assert.match(liveHeading(), / · repo/, 'the same renderer follows the session it now belongs to');
325
+ });
326
+
327
+ test('a call whose operation is not known yet says so instead of guessing one', () => {
328
+ assert.deepEqual(codegraphShape(CODEGRAPH_TOOL, {}), { surface: 'tool', operation: '...' });
329
+ // The MCP tool's own name is the operation it runs.
330
+ assert.deepEqual(codegraphShape(CODEGRAPH_MCP_TOOL, {}), { surface: 'mcp', operation: 'explore' });
331
+ // Only a call that named exactly one payload word has a query; options are never read as one.
332
+ assert.deepEqual(codegraphShape('bash', { command: 'codegraph query "a b"' }), { surface: 'bash', command: 'codegraph query "a b"', operation: 'query', query: 'a b' });
333
+ assert.deepEqual(codegraphShape('bash', { command: 'codegraph query --path /tmp/ws alpha' }), { surface: 'bash', command: 'codegraph query --path /tmp/ws alpha', operation: 'query' });
334
+ // An invocation with no readable operation is still the card: it names the command.
335
+ assert.deepEqual(codegraphShape('bash', { command: 'codegraph --help' }), { surface: 'bash', command: 'codegraph --help' });
336
+ });
337
+
338
+ test('the two tool names are the card\'s, and nothing else is', () => {
339
+ for (const toolName of [CODEGRAPH_TOOL, CODEGRAPH_MCP_TOOL, MCP_PREFIXED_TOOL]) {
340
+ assert.equal(isCodeGraphCardTool(toolName), true, toolName);
341
+ }
342
+ for (const toolName of ['read', 'grep', 'edit', 'write', 'bash', 'powershell', 'codegraph_status', undefined, 42]) {
343
+ assert.equal(isCodeGraphCardTool(toolName), false, String(toolName));
344
+ }
345
+ });
346
+
347
+ // ---- the card, on the shell's own substrate ----
348
+
349
+ test('a call draws one heading with the CodeGraph mark and the operation as its detail', () => {
350
+ const resolver = cardFor();
351
+ const rows = callRows(resolver, CODEGRAPH_TOOL, { operation: 'init' }, taggedTheme, { isPartial: false }, 60);
352
+ assert.equal(rows.length, 1, 'a settled call draws its heading and lets the result close the frame');
353
+ assert.match(rows[0], /^<mdCode>╭<\/mdCode><mdCode>─ <\/mdCode>/, 'the frame carries the CodeGraph role, not the plain border');
354
+ assert.match(rows[0], /<mdCode>󰆼 codegraph<\/mdCode>/, 'the label carries the CodeGraph title role');
355
+ assert.match(rows[0], /<muted>·<\/muted> <muted>init<\/muted>/, 'the operation is the heading detail');
356
+ assertFramed(rows, 60);
357
+
358
+ // The same heading for the MCP tool, because it is the same program; a bash call
359
+ // is the same card too but names the command it ran instead of an operation.
360
+ const mcp = callRows(resolver, MCP_PREFIXED_TOOL, { query: 'auth' }, plainTheme, { isPartial: false }, 60);
361
+ const bash = callRows(resolver, 'bash', { command: 'codegraph explore auth' }, plainTheme, { isPartial: false }, 60);
362
+ assert.match(stripAnsi(mcp[0]), /󰆼 codegraph · explore auth/, 'the query is part of the detail');
363
+ assert.match(stripAnsi(bash[0]), /󰆼 codegraph · explore auth/, 'a bash call names the input it ran, without repeating the program');
364
+
365
+ // A call still streaming its arguments says so rather than guessing an operation.
366
+ const streaming = callRows(resolver, CODEGRAPH_TOOL, {}, plainTheme, { isPartial: false }, 60);
367
+ assert.match(stripAnsi(streaming[0]), /· \.\.\./, 'no operation yet is shown as "..."');
368
+ });
369
+
370
+ test('a settled card paints its whole box in the CodeGraph role, a running or failed one keeps its tone', () => {
371
+ const resolver = cardFor();
372
+ // Neon: the frame, not only the label, wears the CodeGraph role.
373
+ const call = callRows(resolver, CODEGRAPH_TOOL, { operation: 'init' }, taggedTheme, { isPartial: false }, 60);
374
+ assert.match(call[0], /^<mdCode>╭<\/mdCode><mdCode>─ <\/mdCode><mdCode>󰆼 codegraph<\/mdCode> <muted>·<\/muted> <muted>init<\/muted><mdCode> /, 'corners, lead and rule are the CodeGraph role');
375
+ assert.equal(call[0].includes('<border>'), false, 'no cell of the box keeps the plain border role');
376
+ const result = resultRows(resolver, CODEGRAPH_TOOL, textResult(INIT_FRESH), { isPartial: false }, taggedTheme, { args: { operation: 'init' } }, 60);
377
+ assert.match(result[0], /^<mdCode>│<\/mdCode> /, 'the result continues the same box');
378
+ assert.match(result.at(-1), /^<mdCode>╰/);
379
+ // The bash surface is the same card, so it paints the same box.
380
+ const bash = callRows(resolver, 'bash', { command: 'codegraph status' }, taggedTheme, { isPartial: false }, 60);
381
+ assert.match(bash[0], /^<mdCode>╭<\/mdCode>/);
382
+
383
+ // A running call keeps its warning tone and a failed one its error tone: an active
384
+ // state speaks for the call, so no identity role overrides it.
385
+ const running = callRows(resolver, CODEGRAPH_TOOL, { operation: 'init' }, taggedTheme, { isPartial: true }, 40);
386
+ assert.match(running[0], /^<warning>╭<\/warning>/);
387
+ assert.match(running[1], /^<warning>│<\/warning> /);
388
+ assert.match(running[2], /^<warning>╰<\/warning>/);
389
+ const failed = resultRows(resolver, CODEGRAPH_TOOL, textResult(INIT_FAILED, true), { isPartial: false }, taggedTheme, { args: { operation: 'init' } }, 60);
390
+ assert.match(failed[0], /^<error>│<\/error> /);
391
+ assert.match(failed.at(-1), /^<error>╰/);
392
+ });
393
+
394
+ test('the float card paints its rail in the CodeGraph role and keeps the tone band', () => {
395
+ const resolver = cardFor();
396
+ const theme = railTheme();
397
+ globalThis[CARD_STYLE_SLOT] = CARD_STYLE.FLOAT;
398
+ try {
399
+ const rows = callRows(resolver, CODEGRAPH_TOOL, { operation: 'init' }, theme, { isPartial: false }, 40);
400
+ assert.ok(rows.length > 0, 'the float card draws');
401
+ for (const row of rows) assert.ok(row.includes('<mdCode>▎</mdCode>'), `"${row}" does not paint its rail in the CodeGraph role`);
402
+ assert.equal(rows.join('\n').includes('<border>'), false, 'the left rail is the CodeGraph role and nothing of the band is plain border');
403
+ assert.deepEqual(theme.roles.bg, ['toolSuccessBg'], 'the tone still decides the band the rail rides on');
404
+
405
+ // A running card keeps its tone, band and rail alike.
406
+ const running = railTheme();
407
+ const pending = callRows(resolver, CODEGRAPH_TOOL, { operation: 'init' }, running, { isPartial: true }, 40);
408
+ assert.ok(pending.join('\n').includes('<warning>▎</warning>'));
409
+ assert.equal(pending.join('\n').includes('<mdCode>▎</mdCode>'), false);
410
+ assert.deepEqual(running.roles.bg, ['toolPendingBg']);
411
+ } finally {
412
+ globalThis[CARD_STYLE_SLOT] = CARD_STYLE.NEON;
413
+ }
414
+ });
415
+
416
+ test('a running call is the warning tone and closes its own frame', () => {
417
+ const resolver = cardFor();
418
+ const rows = callRows(resolver, CODEGRAPH_TOOL, { operation: 'init' }, taggedTheme, { isPartial: true }, 40);
419
+ assert.equal(rows.length, 3, 'a heading, the running row and the closed frame');
420
+ assert.match(rows[0], /^<warning>╭<\/warning>/, 'pending is the warning tone');
421
+ assert.match(rows[1], /^<warning>│<\/warning> <muted>running…<\/muted>/);
422
+ assert.match(rows[2], /^<warning>╰/);
423
+ assertFramed(rows, 40);
424
+
425
+ const failed = callRows(resolver, CODEGRAPH_TOOL, { operation: 'init' }, taggedTheme, { isPartial: false, isError: true }, 40);
426
+ assert.match(failed[0], /^<error>╭<\/error>/, 'a failed call is the error tone');
427
+ });
428
+
429
+ test('a collapsed result is the one factual row the output supports, in the muted role', () => {
430
+ const resolver = cardFor();
431
+ for (const [operation, text, expected] of [
432
+ ['init', INIT_FRESH, '→ initialized'],
433
+ ['init', INIT_EXISTING, '→ already initialized'],
434
+ ['sync', SYNC_CHANGED, '→ synced 3 changed files'],
435
+ ['query', QUERY, '→ 2 results'],
436
+ ]) {
437
+ const args = operation === 'query' ? { command: 'codegraph query alpha' } : { command: `codegraph ${operation}` };
438
+ const rows = resultRows(resolver, 'bash', textResult(text), { isPartial: false }, taggedTheme, { args }, 60);
439
+ assert.equal(rows.length, 2, `${operation}: one body row and the closing rule`);
440
+ assert.equal(bodyText(rows[0]), expected, `${operation} collapses to its own fact`);
441
+ assert.match(rows[0], /<muted>/, `${operation}: the preview is the muted role`);
442
+ assert.match(rows[1], /^<mdCode>╰/, `${operation}: the result closes the frame in the CodeGraph role`);
443
+ assertFramed(rows, 60);
444
+ }
445
+
446
+ // The MCP explore tool's own header sentence is the row the card states.
447
+ const explore = resultRows(resolver, MCP_PREFIXED_TOOL, textResult(EXPLORE), { isPartial: false }, plainTheme, {}, 60);
448
+ assert.equal(bodyText(explore[0]), '→ 2 symbols in 1 file');
449
+ });
450
+
451
+ test('S4: an expanded init draws its outcome row and the index facts, never the CLI advisory', () => {
452
+ const resolver = cardFor();
453
+ const expanded = resultRows(resolver, CODEGRAPH_TOOL, textResult(INIT_EXISTING), { expanded: true, isPartial: false }, plainTheme, { args: { operation: 'init' } }, 80);
454
+ assert.deepEqual(expanded.slice(0, -1).map(bodyText), ['→ already initialized'], 'the same one-row outcome the collapsed card states');
455
+ assert.doesNotMatch(expanded.slice(0, -1).map(bodyText).join('\n'), /Use "codegraph index"/, 'the CLI advisory line never reaches the card');
456
+
457
+ const fresh = resultRows(resolver, CODEGRAPH_TOOL, textResult(INIT_FRESH), { expanded: true, isPartial: false }, plainTheme, { args: { operation: 'init' } }, 80);
458
+ assert.deepEqual(
459
+ fresh.slice(0, -1).map(bodyText),
460
+ ['→ initialized', 'Indexed 1 files', '3 nodes, 2 edges in 208ms'],
461
+ 'the outcome row plus the index facts, and nothing else',
462
+ );
463
+ assert.doesNotMatch(fresh.slice(0, -1).map(bodyText).join('\n'), /Initializing CodeGraph|└ Done|Scanning files/, 'the progress chrome is not an index fact');
464
+ assertFramed(fresh, 80);
465
+
466
+ // Expanding is the reader's own ask, so the rows arrive at any content level.
467
+ withContent(CARD_CONTENT.MINIMAL, () => {
468
+ const atMinimal = resultRows(resolver, CODEGRAPH_TOOL, textResult(INIT_FRESH), { expanded: true, isPartial: false }, plainTheme, { args: { operation: 'init' } }, 80);
469
+ assert.deepEqual(atMinimal, fresh, 'the reader asked for everything and gets the facts');
470
+ });
471
+
472
+ // The same card for a bash `codegraph init`.
473
+ const bash = resultRows(resolver, 'bash', textResult(INIT_EXISTING), { expanded: true, isPartial: false }, plainTheme, { args: { command: 'codegraph init -y /tmp/ws' } }, 80);
474
+ assert.deepEqual(bash.slice(0, -1).map(bodyText), ['→ already initialized']);
475
+ assert.doesNotMatch(bash.slice(0, -1).map(bodyText).join('\n'), /Use "codegraph index"/);
476
+ });
477
+
478
+ test('S4: the collapsed init outcome row is drawn at both content levels', () => {
479
+ const resolver = cardFor();
480
+ for (const [text, expected] of [[INIT_FRESH, '→ initialized'], [INIT_EXISTING, '→ already initialized']]) {
481
+ withContent(CARD_CONTENT.MINIMAL, () => {
482
+ const rows = resultRows(resolver, CODEGRAPH_TOOL, textResult(text), { isPartial: false }, plainTheme, { args: { operation: 'init' } }, 80);
483
+ assert.deepEqual(rows.slice(0, -1).map(bodyText), [expected], 'a card of this package never loses its outcome row to minimal');
484
+ assertFramed(rows, 80);
485
+ });
486
+ const atDefault = resultRows(resolver, CODEGRAPH_TOOL, textResult(text), { isPartial: false }, plainTheme, { args: { operation: 'init' } }, 80);
487
+ assert.deepEqual(atDefault.slice(0, -1).map(bodyText), [expected], 'the default level draws the same row');
488
+ }
489
+
490
+ withContent(CARD_CONTENT.MINIMAL, () => {
491
+ const rows = resultRows(resolver, CODEGRAPH_TOOL, textResult(INIT_FRESH), { isPartial: false }, plainTheme, { args: { operation: 'init' } }, 80);
492
+ assert.equal(rows.slice(0, -1).map(bodyText).join('\n').includes('Indexed 1 files'), false,
493
+ 'minimal keeps the outcome alone; the index facts wait for the expansion');
494
+
495
+ // Preserved: minimal hides every other operation's body...
496
+ const sync = resultRows(resolver, 'bash', textResult(SYNC_CHANGED), { isPartial: false }, plainTheme, { args: { command: 'codegraph sync' } }, 80);
497
+ assert.deepEqual(sync.slice(0, -1).map(bodyText), [], 'a minimized sync still draws the call alone');
498
+ // ...and a failure still says why, at either level.
499
+ const failed = resultRows(resolver, CODEGRAPH_TOOL, textResult(INIT_FAILED, true), { isPartial: false }, plainTheme, { args: { operation: 'init' } }, 80);
500
+ assert.match(failed.slice(0, -1).map(bodyText).join('\n'), /Failed: EACCES/, 'a minimized failure still says why');
501
+ });
502
+ });
503
+
504
+ test('a card body row is painted in the output role, the preview in muted, a failure in error', () => {
505
+ const resolver = cardFor();
506
+ assert.match(
507
+ resultRows(resolver, CODEGRAPH_MCP_TOOL, textResult(EXPLORE), { expanded: true, isPartial: false }, taggedTheme, {}, 80)[0],
508
+ /<toolOutput>/,
509
+ 'the expanded output is the theme toolOutput role',
510
+ );
511
+ const failure = resultRows(resolver, 'bash', textResult(INIT_FAILED, true), { isPartial: false }, taggedTheme, { args: { command: 'codegraph init' } }, 80);
512
+ assert.match(failure[0], /<error>/, 'a failure paints its reason in the error role');
513
+ assert.match(bodyText(failure[0]), /Failed: EACCES/);
514
+ assert.match(failure.slice(0, -1).map(bodyText).join('\n'), /run "codegraph init" again/, 'the instruction the program printed stays with the reason');
515
+
516
+ // No colour is written down: every cell asks the theme for one of its own roles.
517
+ const recorder = recordingTheme();
518
+ callRows(resolver, MCP_PREFIXED_TOOL, { query: 'auth' }, recorder, { isPartial: false }, 80);
519
+ resultRows(resolver, MCP_PREFIXED_TOOL, textResult(EXPLORE), { isPartial: false }, recorder, {}, 80);
520
+ assert.deepEqual([...new Set(recorder.roles)].sort(), ['mdCode', 'muted'], 'the CodeGraph role paints the box and the label, the preview the muted role');
521
+ const expandedRecorder = recordingTheme();
522
+ resultRows(resolver, MCP_PREFIXED_TOOL, textResult(EXPLORE), { expanded: true, isPartial: false }, expandedRecorder, {}, 80);
523
+ assert.deepEqual([...new Set(expandedRecorder.roles)].sort(), ['mdCode', 'toolOutput'], 'an expanded body is the shell\'s tool-output role');
524
+ });
525
+
526
+ // ---- a bash call that runs codegraph is the CodeGraph card ----
527
+
528
+ /**
529
+ * The content of a heading and of any detail it wrapped onto body rows, with the
530
+ * chrome, the mark and the title removed: what the reader reads there.
531
+ */
532
+ function headingText(rows) {
533
+ return rows
534
+ .map((row, index) => {
535
+ const text = unpaint(row);
536
+ if (index > 0) return text.replace(/^│ /, '').replace(/ +│$/, '').replace(/^· /, '');
537
+ return text.replace(/^╭─ /, '').replace(/ ─*╮$/, '').replace(/^󰆼 codegraph(?: · )?/, '');
538
+ })
539
+ .join(' ')
540
+ .replace(/\s+/g, ' ')
541
+ .trim();
542
+ }
543
+
544
+ // The two compositions the session really ran. Both are one CodeGraph card.
545
+ const HELP_AND_STATUS = 'codegraph --help 2>&1 | head -60; echo "--- STATUS ---"; codegraph status 2>&1 | head -40';
546
+ const THREE_QUERIES = [
547
+ 'echo "=== codegraph query cardBodyRows ==="; codegraph query cardBodyRows 2>&1 | head -20; echo;',
548
+ 'echo "=== codegraph callers worktreeListView ==="; codegraph callers worktreeListView 2>&1 | head -20; echo;',
549
+ 'echo "=== codegraph node warpPendingGate ==="; codegraph node warpPendingGate 2>&1 | head -40',
550
+ ].join(' ');
551
+
552
+ test('a bash call that runs codegraph is the CodeGraph card, and names the command it ran', () => {
553
+ const resolver = cardFor();
554
+ const collapsed = callRows(resolver, 'bash', { command: HELP_AND_STATUS }, taggedTheme, { isPartial: false }, 40);
555
+ assert.equal(collapsed.length, 1, 'a collapsed call is one line: no operation label and no second heading');
556
+ assert.match(collapsed[0], /<mdCode>󰆼 codegraph<\/mdCode>/, 'the CodeGraph mark and name');
557
+ assert.match(collapsed[0], /<muted>·<\/muted> <muted>--help/, 'the input after the program is the heading detail');
558
+ assert.match(collapsed[0], /--help .*…/, 'a command too wide for the rule ends in an ellipsis instead of a second row');
559
+ assert.doesNotMatch(collapsed[0], /STATUS/, 'only what fits stays visible collapsed');
560
+ assertFramed(collapsed, 40);
561
+
562
+ // Expanded, the whole command is drawn: every line of it, wrapped, and nothing lost.
563
+ const expanded = callRows(resolver, 'bash', { command: HELP_AND_STATUS }, taggedTheme, { isPartial: false, expanded: true }, 80);
564
+ assert.ok(expanded.length > 1, 'the command continues on the rows below the rule');
565
+ assert.equal(headingText(expanded), HELP_AND_STATUS.slice('codegraph '.length), 'the complete input after the program is the heading detail');
566
+ assertFramed(expanded, 80);
567
+
568
+ // A multi-line command keeps every line too, once the reader expands it.
569
+ const script = 'codegraph status\necho done';
570
+ assert.equal(headingText(callRows(resolver, 'bash', { command: 'codegraph status; echo done' }, plainTheme, { isPartial: false, expanded: true }, 80)), 'status; echo done');
571
+ assert.equal(headingText(callRows(resolver, 'bash', { command: script }, plainTheme, { isPartial: false, expanded: true }, 80)), 'status echo done', 'a multi-line command keeps both of its lines');
572
+ });
573
+
574
+ test('any codegraph subcommand counts, and several of them in one command are one card', () => {
575
+ const resolver = cardFor();
576
+ for (const command of [
577
+ 'codegraph --help',
578
+ 'codegraph status',
579
+ 'codegraph callers worktreeListView',
580
+ 'codegraph node warpPendingGate',
581
+ 'codegraph status 2>&1 | head -40',
582
+ 'npx codegraph status',
583
+ 'pnpm exec codegraph status',
584
+ HELP_AND_STATUS,
585
+ THREE_QUERIES,
586
+ ]) {
587
+ const rows = callRows(resolver, 'bash', { command }, plainTheme, { isPartial: false }, 60);
588
+ assert.equal(rows.length, 1, command);
589
+ assert.match(stripAnsi(rows[0]), /󰆼 codegraph · /, command);
590
+ const detail = headingText(rows);
591
+ assert.ok(command.includes(detail.endsWith('…') ? detail.slice(0, -1) : detail), `${command} is the detail the card names`);
592
+ }
593
+ });
594
+
595
+ test('S5: a bash codegraph call names the input after the program, its arguments included', () => {
596
+ const resolver = cardFor();
597
+ const detail = (command) => headingText(callRows(resolver, 'bash', { command }, plainTheme, { isPartial: false, expanded: true }, 120));
598
+ assert.equal(detail('codegraph status .'), 'status .', 'the argument after the subcommand is part of the detail');
599
+ assert.equal(detail('codegraph init /tmp/ws'), 'init /tmp/ws');
600
+ assert.equal(detail('codegraph'), '', 'a bare call has no input to name');
601
+
602
+ for (const command of [
603
+ '/usr/local/bin/codegraph status .',
604
+ 'npx codegraph status .',
605
+ 'pnpm exec codegraph status .',
606
+ 'yarn codegraph status .',
607
+ 'bunx codegraph status .',
608
+ 'cd /tmp/ws && codegraph status .',
609
+ 'codegraph status .; echo done',
610
+ 'codegraph status . | head',
611
+ 'codegraph status . || true',
612
+ ]) {
613
+ const rows = callRows(resolver, 'bash', { command }, plainTheme, { isPartial: false }, 120);
614
+ assert.match(stripAnsi(rows[0]), /󰆼 codegraph/, `${command} is the CodeGraph card`);
615
+ assert.doesNotMatch(stripAnsi(rows[0]), /\$ bash/, `${command} never falls back to the generic heading`);
616
+ }
617
+ });
618
+
619
+ test('a bash command that only mentions codegraph stays the host\'s own row', () => {
620
+ const resolver = cardFor();
621
+ const seen = [];
622
+ const host = {
623
+ renderShell: 'self',
624
+ renderCall(...args) {
625
+ seen.push(args);
626
+ return { render: () => ['host bash call'], invalidate() {} };
627
+ },
628
+ renderResult: () => ({ render: () => ['host bash result'], invalidate() {} }),
629
+ };
630
+ const slot = resolver('bash', () => host);
631
+ for (const command of ['echo codegraph init', 'cat codegraph.json', 'grep -r codegraph src', 'pnpm test && ls']) {
632
+ assert.equal(codegraphShape('bash', { command }), undefined, command);
633
+ assert.deepEqual(slot.renderCall({ command }, plainTheme, { isPartial: false }).render(60), ['host bash call'], command);
634
+ }
635
+ assert.equal(seen.length, 4, 'every mention-only command reached the host renderer');
636
+ });
637
+
638
+ test('a bash CodeGraph card keeps the three content levels: the command, a three-row preview, everything', () => {
639
+ const resolver = cardFor();
640
+ const output = Array.from({ length: 8 }, (_, index) => `row ${index + 1}`).join('\n');
641
+ const args = { command: 'codegraph status' };
642
+ assert.match(stripAnsi(callRows(resolver, 'bash', args, plainTheme, { isPartial: false }, 60)[0]), /󰆼 codegraph · status/, 'the collapsed default shows the input it ran');
643
+
644
+ const preview = resultRows(resolver, 'bash', textResult(output), { isPartial: false }, plainTheme, { args }, 60);
645
+ assert.equal(preview.length, 4, 'at most three rows of output preview and the closing rule');
646
+ assert.equal(preview.slice(0, -1).map(bodyText).join('\n'), 'row 6\nrow 7\nrow 8');
647
+
648
+ withContent(CARD_CONTENT.MINIMAL, () => {
649
+ const minimal = resultRows(resolver, 'bash', textResult(output), { isPartial: false }, plainTheme, { args }, 60);
650
+ assert.equal(minimal.length, 1, 'the minimal level draws the command line alone');
651
+ assert.match(minimal[0], /^╰/, 'the result only closes the frame the call above opened');
652
+ });
653
+
654
+ const expanded = resultRows(resolver, 'bash', textResult(output), { expanded: true, isPartial: false }, plainTheme, { args }, 60);
655
+ assert.equal(expanded.slice(0, -1).map(bodyText).join('\n'), output, 'expanded shows every row it printed');
656
+ });
657
+
658
+ test('a minimized card draws no result at all, and a failure still says why', () => {
659
+ const resolver = cardFor();
660
+ const args = { command: 'codegraph query alpha' };
661
+ withContent(CARD_CONTENT.MINIMAL, () => {
662
+ const minimal = resultRows(resolver, 'bash', textResult(QUERY), { isPartial: false }, plainTheme, { args }, 60);
663
+ assert.equal(minimal.length, 1, 'the call alone is the card');
664
+ assert.match(minimal[0], /^╰/, 'the result only closes the frame the call above opened');
665
+ assert.equal(minimal.some((row) => stripAnsi(row).includes('→ 2 results')), false);
666
+
667
+ const failure = resultRows(resolver, 'bash', textResult(INIT_FAILED, true), { isPartial: false }, plainTheme, { args: { command: 'codegraph init' } }, 80);
668
+ assert.match(bodyText(failure[0]), /Failed: EACCES/, 'a failure always says why, at either level');
669
+ });
670
+ // Back at the default level the same inputs draw the preview again.
671
+ const restored = resultRows(resolver, 'bash', textResult(QUERY), { isPartial: false }, plainTheme, { args }, 60);
672
+ assert.equal(bodyText(restored[0]), '→ 2 results');
673
+ });
674
+
675
+ test('a partial result shows the rows it already has, and leaves the closing rule to the final one', () => {
676
+ const resolver = cardFor();
677
+ const args = { command: 'codegraph init' };
678
+ const rows = resultRows(resolver, 'bash', textResult('┌ Initializing CodeGraph\n│'), { isPartial: true }, plainTheme, { args }, 60);
679
+ assert.match(bodyText(rows[0]), /Initializing CodeGraph/, 'the rows the tool printed are the card');
680
+ assert.equal(rows.some((row) => row.startsWith('╰')), false, 'a streamed result does not close the frame yet');
681
+ });
682
+
683
+ test('the elapsed time rides the closing rule, and a very narrow card still draws', () => {
684
+ const resolver = cardFor();
685
+ const rows = resultRows(resolver, MCP_PREFIXED_TOOL, textResult(EXPLORE), { isPartial: false }, plainTheme, { durationMs: 1200 }, 60);
686
+ assert.match(rows.at(-1), / 1\.2s ╯$/);
687
+ for (const width of [0, 1, 2, 3, 5, 9, 12]) {
688
+ for (const drawn of [
689
+ callRows(resolver, CODEGRAPH_TOOL, { operation: 'init' }, plainTheme, { isPartial: true }, width),
690
+ resultRows(resolver, MCP_PREFIXED_TOOL, textResult(EXPLORE), { isPartial: false }, plainTheme, {}, width),
691
+ resultRows(resolver, MCP_PREFIXED_TOOL, textResult(EXPLORE), { expanded: true, isPartial: false }, plainTheme, {}, width),
692
+ ]) {
693
+ for (const row of drawn) assert.ok(metrics.visibleWidth(row) <= width, `"${stripAnsi(row)}" overflows ${width}`);
694
+ }
695
+ }
696
+ });
697
+
698
+ test('the content level is read on every paint, so a card on screen repaints when it changes', () => {
699
+ const resolver = cardFor();
700
+ const slot = renderersFor(resolver, MCP_PREFIXED_TOOL);
701
+ const component = slot.renderResult(textResult(EXPLORE), { isPartial: false }, plainTheme, {});
702
+ // The reader of the process-wide slot: no injected reader, so the shell's own level answers.
703
+ const before = component.render(60);
704
+ assert.match(bodyText(before[0]), /→ 2 symbols in 1 file/, 'the default level draws the preview');
705
+
706
+ globalThis[CARD_CONTENT_SLOT] = CARD_CONTENT.MINIMAL;
707
+ try {
708
+ const minimized = component.render(60);
709
+ assert.notDeepEqual(minimized, before, 'the same component repaints at the level now in force');
710
+ assert.equal(minimized.some((row) => stripAnsi(row).includes('2 symbols')), false, 'and the preview is gone');
711
+ // No rebuild, no new resolver: the very component already on screen is the one that changed.
712
+ globalThis[CARD_CONTENT_SLOT] = CARD_CONTENT.DEFAULT;
713
+ assert.deepEqual(component.render(60), before, 'and back again');
714
+ } finally {
715
+ delete globalThis[CARD_CONTENT_SLOT];
716
+ }
717
+
718
+ // A reader injected by the caller answers instead, also read on every paint.
719
+ let level = CARD_CONTENT.DEFAULT;
720
+ const injected = cardFor({ cardContent: () => level });
721
+ const injectedSlot = renderersFor(injected, MCP_PREFIXED_TOOL);
722
+ const injectedComponent = injectedSlot.renderResult(textResult(EXPLORE), { isPartial: false }, plainTheme, {});
723
+ assert.match(bodyText(injectedComponent.render(60)[0]), /→ 2 symbols/);
724
+ level = CARD_CONTENT.MINIMAL;
725
+ assert.equal(injectedComponent.render(60).some((row) => stripAnsi(row).includes('2 symbols')), false);
726
+ });
727
+
728
+ test('cardContentLevel reads the process-wide slot and only the two known levels', () => {
729
+ assert.equal(cardContentLevel({}), CARD_CONTENT.DEFAULT, 'an unset slot is the default preview level');
730
+ assert.equal(cardContentLevel({ [CARD_CONTENT_SLOT]: 'minimal' }), CARD_CONTENT.MINIMAL);
731
+ for (const junk of ['everything', 42, null, {}, []]) {
732
+ assert.equal(cardContentLevel({ [CARD_CONTENT_SLOT]: junk }), CARD_CONTENT.DEFAULT, 'a value this package cannot read is the safe level');
733
+ }
734
+ });
735
+
736
+ // ---- the resolver: what it owns, and what it must hand back untouched ----
737
+
738
+ test('every tool the card does not own is handed back exactly as the chain resolved it', () => {
739
+ const resolver = cardFor();
740
+ const hostRenderers = { renderCall: () => 'host call', renderResult: () => 'host result' };
741
+ for (const toolName of ['read', 'grep', 'edit', 'write', 'powershell', 'worktree_create', 'codegraph_status', undefined, 42]) {
742
+ assert.equal(resolver(toolName, () => hostRenderers), hostRenderers, `${String(toolName)} is the host's own row`);
743
+ }
744
+ // A chain that resolves nothing stays nothing: this package adds no renderer to an unrelated tool.
745
+ assert.equal(resolver('read', () => undefined), undefined);
746
+
747
+ // A bash call that is not CodeGraph forwards to the host's own drawing, with its own arguments.
748
+ const calls = [];
749
+ const host = {
750
+ renderShell: 'self',
751
+ renderCall(...args) {
752
+ calls.push(['call', ...args]);
753
+ return { render: () => ['host bash call'], invalidate() {} };
754
+ },
755
+ renderResult(...args) {
756
+ calls.push(['result', ...args]);
757
+ return { render: () => ['host bash result'], invalidate() {} };
758
+ },
759
+ };
760
+ const bash = resolver('bash', () => host);
761
+ assert.equal(typeof bash.renderCall, 'function', 'bash is decided per call, so its slot is always ours to decide');
762
+ const args = { command: 'pnpm test' };
763
+ const context = { isPartial: false };
764
+ assert.deepEqual(bash.renderCall(args, plainTheme, context).render(40), ['host bash call']);
765
+ assert.equal(calls[0][1], args, 'the host renderer receives the very arguments the host handed us');
766
+ assert.equal(calls[0][2], plainTheme);
767
+ assert.equal(calls[0][3], context);
768
+ assert.deepEqual(bash.renderResult(textResult('ok'), { isPartial: false }, plainTheme, { args }).render(40), ['host bash result']);
769
+ assert.equal(calls[1][1].content[0].text, 'ok');
770
+
771
+ // A bash call whose command DOES run CodeGraph is the card's.
772
+ const codegraph = bash.renderCall({ command: 'codegraph init' }, plainTheme, { isPartial: false }).render(60);
773
+ assert.match(stripAnsi(codegraph[0]), /󰆼 codegraph · init/);
774
+ });
775
+
776
+ test('the resolver takes its host seams as options and degrades to drawing nothing without the hook', () => {
777
+ // No registerToolRenderer at all: an older host, or one whose renderer chain refuses the probe.
778
+ const none = createCodegraphCardResolver({ metrics, theme: plainTheme });
779
+ assert.equal(none.registered, false, 'without the hook nothing is registered, so nothing of ours is drawn');
780
+ assert.doesNotThrow(() => none.resolver('codegraph', () => undefined));
781
+
782
+ let seen;
783
+ const cards = createCodegraphCardResolver({
784
+ metrics,
785
+ theme: plainTheme,
786
+ cardContent: () => CARD_CONTENT.DEFAULT,
787
+ registerToolRenderer: (resolver) => {
788
+ seen = resolver;
789
+ },
790
+ });
791
+ assert.equal(cards.registered, true);
792
+ assert.equal(seen, cards.resolver, 'the host hook receives this factory\'s resolver');
793
+
794
+ // A hook that throws while registering is the same as no hook: the host keeps drawing.
795
+ const hostile = createCodegraphCardResolver({
796
+ metrics,
797
+ theme: plainTheme,
798
+ registerToolRenderer: () => {
799
+ throw new Error('no such hook');
800
+ },
801
+ });
802
+ assert.equal(hostile.registered, false);
803
+
804
+ // The measurement seam is required, and the factory says which one is missing.
805
+ assert.throws(() => createCodegraphCardResolver(), /metrics/);
806
+ assert.throws(() => createCodegraphCardResolver({ registerToolRenderer: () => {} }), /metrics/);
807
+ const broken = { ...metrics, wrapTextWithAnsi: undefined };
808
+ assert.throws(() => createCodegraphCardResolver({ metrics: broken }), /wrapTextWithAnsi/);
809
+ // A metrics seam resolved late (the host's TUI package is loaded inside the hook) is read per paint.
810
+ const late = createCodegraphCardResolver({
811
+ metrics: () => metrics,
812
+ theme: plainTheme,
813
+ registerToolRenderer: () => {},
814
+ });
815
+ assert.equal(late.registered, true);
816
+ assert.match(stripAnsi(late.resolver('codegraph', () => undefined).renderCall({ operation: 'init' }, plainTheme, { isPartial: false }).render(60)[0]), /codegraph/);
817
+ });
818
+
819
+ test('a renderer that throws draws nothing and never breaks the transcript', () => {
820
+ const resolver = cardFor();
821
+ // The theme itself throws on every role it is asked for.
822
+ const hostileTheme = {
823
+ fg() {
824
+ throw new Error('Unknown theme color');
825
+ },
826
+ };
827
+ const call = resolver('codegraph', () => undefined).renderCall({ operation: 'init' }, hostileTheme, { isPartial: false });
828
+ assert.deepEqual(call.render(60), [], 'a card that cannot be painted draws no rows');
829
+ const result = resolver(MCP_PREFIXED_TOOL, () => undefined).renderResult(textResult(EXPLORE), { isPartial: false }, hostileTheme, {});
830
+ assert.deepEqual(result.render(60), []);
831
+
832
+ // The host's own renderer throws while drawing a bash row that is not CodeGraph's.
833
+ const throwing = resolver('bash', () => ({
834
+ renderShell: 'self',
835
+ renderCall() {
836
+ throw new Error('host renderer exploded');
837
+ },
838
+ renderResult() {
839
+ throw new Error('host renderer exploded');
840
+ },
841
+ }));
842
+ assert.doesNotThrow(() => throwing.renderCall({ command: 'ls' }, plainTheme, { isPartial: false }).render(40));
843
+ assert.doesNotThrow(() => throwing.renderResult(textResult('ok'), { isPartial: false }, plainTheme, { args: { command: 'ls' } }).render(40));
844
+ assert.deepEqual(throwing.renderCall({ command: 'ls' }, plainTheme, { isPartial: false }).render(40), [], 'and draws nothing of its own');
845
+
846
+ // A chain whose next() throws is the host's own drawing, and no CodeGraph card is lost.
847
+ const broken = resolver('read', () => {
848
+ throw new Error('chain exploded');
849
+ });
850
+ assert.equal(broken, undefined, 'a foreign tool with no usable chain stays the host\'s');
851
+ assert.doesNotThrow(() => resolver('codegraph', () => {
852
+ throw new Error('chain exploded');
853
+ }).renderCall({ operation: 'init' }, plainTheme, { isPartial: false }).render(60));
854
+ });
855
+
856
+ // ---- the host's shell: this card frames itself, so the host must not frame it too ----
857
+
858
+ test('the native and MCP CodeGraph tools declare a self shell, or the host draws its own filled box under the card', () => {
859
+ const resolver = cardFor();
860
+ assert.equal(resolver(CODEGRAPH_TOOL, () => undefined).renderShell, 'self');
861
+ assert.equal(resolver(MCP_PREFIXED_TOOL, () => undefined).renderShell, 'self');
862
+ assert.equal(resolver(CODEGRAPH_MCP_TOOL, () => undefined).renderShell, 'self');
863
+ });
864
+
865
+ test('a bash row is drawn by this card only on a host whose bash row already frames itself', () => {
866
+ const resolver = cardFor();
867
+ const self = { renderShell: 'self', renderCall: () => 'host-call', renderResult: () => 'host-result' };
868
+ const drawn = resolver('bash', () => self);
869
+ assert.equal(drawn.renderShell, 'self', 'the card keeps the shell the host row already had');
870
+ assert.notEqual(drawn.renderCall, self.renderCall, 'and draws a CodeGraph command itself');
871
+ // A host row inside the default filled box: this card would be drawn on top of the box, which is two designs at once.
872
+ const boxed = { renderCall: () => 'host-call', renderResult: () => 'host-result' };
873
+ assert.equal(resolver('bash', () => boxed), boxed, 'the host row is returned untouched');
874
+ });
875
+
876
+ test('a host with no bash renderer of its own keeps drawing every bash row itself', () => {
877
+ const resolver = cardFor();
878
+ assert.equal(resolver('bash', () => undefined), undefined, 'no command loses its drawing on such a host');
879
+ assert.equal(resolver('bash', () => {
880
+ throw new Error('chain exploded');
881
+ }), undefined);
882
+ });
883
+
884
+ // ---- S5's two styles, one card ----
885
+
886
+ /** The card's text with every chrome cell removed: what the reader actually reads. */
887
+ function contentOf(rows) {
888
+ return rows
889
+ .map((row) => unpaint(row).replace(/[╭╮╰╯─│▎]/g, ' ').replace(/\s+/g, ' ').trim())
890
+ .filter((text) => text.length > 0)
891
+ .join(' | ');
892
+ }
893
+
894
+ test('the same CodeGraph card is the same text in float and in neon, and only the chrome differs', () => {
895
+ const resolver = cardFor();
896
+ const theme = paintTheme();
897
+ const draw = (style, run) => {
898
+ globalThis[CARD_STYLE_SLOT] = style;
899
+ try {
900
+ return run();
901
+ } finally {
902
+ globalThis[CARD_STYLE_SLOT] = CARD_STYLE.NEON;
903
+ }
904
+ };
905
+ const call = (style) => draw(style, () => callRows(resolver, CODEGRAPH_TOOL, { operation: 'query', query: 'alpha' }, theme, { isPartial: false }, 60));
906
+ const result = (style) => draw(style, () => resultRows(resolver, CODEGRAPH_TOOL, textResult(QUERY), { isPartial: false }, theme, { args: { operation: 'query' }, durationMs: 1200 }, 60));
907
+
908
+ assert.equal(contentOf(call(CARD_STYLE.FLOAT)), contentOf(call(CARD_STYLE.NEON)), 'one heading, two chromes');
909
+ assert.equal(contentOf(result(CARD_STYLE.FLOAT)), contentOf(result(CARD_STYLE.NEON)), 'one preview row and one elapsed time');
910
+ assert.match(contentOf(result(CARD_STYLE.FLOAT)), /1\.2s$/);
911
+ assert.equal(call(CARD_STYLE.NEON).some((row) => row.includes('▎')), false, 'neon draws no rail');
912
+ assert.equal(result(CARD_STYLE.FLOAT).some((row) => /[╭╮╰╯─│]/.test(row)), false, 'float draws no box');
913
+ assert.ok(result(CARD_STYLE.FLOAT).every((row) => row.includes('\x1b[48;5;240m')), 'the float card paints the tone background');
914
+ for (const row of result(CARD_STYLE.FLOAT)) assert.equal(metrics.visibleWidth(unpaint(row)), 60, 'a float row is the width it was given');
915
+ });
916
+
917
+ test('an unreadable call or output draws nothing instead of throwing', () => {
918
+ const resolver = cardFor();
919
+ for (const value of [undefined, null, 42, {}, [], { content: 'nope' }, { content: [{ type: 'text', text: 42 }] }]) {
920
+ assert.doesNotThrow(() => codegraphShape(value, value));
921
+ assert.doesNotThrow(() => codegraphShape('bash', value));
922
+ assert.deepEqual(codegraphResultRows({ shape: { operation: 'init' }, text: value, expanded: false, isPartial: false, failed: false, content: CARD_CONTENT.DEFAULT }), []);
923
+ assert.doesNotThrow(() => resolver('bash', () => HOST_BASH).renderCall(value, plainTheme, { isPartial: false }).render(40));
924
+ }
925
+ // The native tool's own arguments are the only place its operation comes from.
926
+ assert.deepEqual(codegraphShape('bash', { command: 'ls' }), undefined);
927
+ assert.deepEqual(codegraphShape('read', { command: 'codegraph init' }), undefined);
928
+ });
929
+
930
+ // ---- purity ----
931
+
932
+ test('the modules carry no colour, no escape and no host package', () => {
933
+ for (const file of ['codegraph-card.js', 'codegraph-card-preview.js']) {
934
+ const source = readFileSync(join(__dirname, '..', 'lib', file), 'utf8');
935
+ assert.doesNotMatch(source, /@earendil-works/, `${file} requires no host package`);
936
+ assert.doesNotMatch(source, /\\u001b|\\x1b|String\.fromCharCode\(27\)/, `${file} writes no escape sequence down`);
937
+ assert.doesNotMatch(source, /#[0-9a-fA-F]{6}\b/, `${file} writes no hexadecimal colour`);
938
+ assert.doesNotMatch(source, /require\(['"](?!\.\/|node:)/, `${file} imports only its own modules and Node builtins`);
939
+ // S1: no model-facing tool is registered, executed or shadowed — the card only draws.
940
+ assert.doesNotMatch(source, /registerTool\(|\.execute\b|registerCommand\(|registerToolRenderer\(/, `${file} registers and runs nothing`);
941
+ }
942
+ });
943
+
944
+ // ---- S5: the composition, not the isolated resolver ----
945
+ //
946
+ // Every case above drives ONE resolver. The row the user reported wrong was decided
947
+ // by the chain the host builds from ALL of them: `resolveToolRenderers` calls the
948
+ // extension's resolvers in load order, each `next` resolving the following one, and
949
+ // the tool's own renderers last. That order is a fact of the extension file, so this
950
+ // block loads the extension itself against the fake host, collects the resolvers it
951
+ // registers, and renders a bash call through the chain the host would run.
952
+ //
953
+ // Both cards wear the classifier's `codegraph` mark for such a command, so the
954
+ // heading alone cannot say which one drew the row. What tells them apart is the body
955
+ // the CodeGraph card composes from the CLI's own output, and whether the bash card's
956
+ // slots were ever asked: they are captured here and stated to be untouched.
957
+
958
+ /** The `codegraph` CLI, faked for the one probe the extension makes. */
959
+ async function withCodegraphCli(run) {
960
+ // `cliAvailable` asks whether the binary is on PATH (`existsSync`, no spawn), and a
961
+ // host without it registers no CodeGraph card at all (invariant 19). The directory
962
+ // is scratch and PATH is restored before anything else runs.
963
+ const dir = mkdtempSync(join(tmpdir(), 'odd-worktree-codegraph-cli-'));
964
+ writeFileSync(join(dir, 'codegraph'), '');
965
+ const saved = process.env.PATH;
966
+ process.env.PATH = dir;
967
+ try {
968
+ return await run();
969
+ } finally {
970
+ process.env.PATH = saved;
971
+ rmSync(dir, { recursive: true, force: true });
972
+ }
973
+ }
974
+
975
+ /** The extension loaded as the host loads it, and the resolvers it registered, in order. */
976
+ async function loadComposedExtension() {
977
+ const savedLibDir = process.env.GENTLE_WORKTREE_LIB_DIR;
978
+ const dir = mkdtempSync(join(tmpdir(), 'odd-worktree-composed-'));
979
+ const copy = join(dir, 'odd-worktree-tools.mjs');
980
+ writeFileSync(copy, stubbedSource());
981
+ process.env.GENTLE_WORKTREE_LIB_DIR = LIB_DIR;
982
+ try {
983
+ const mod = await import(pathToFileURL(copy).href);
984
+ const resolvers = [];
985
+ const host = {
986
+ registerCommand: () => {},
987
+ registerTool: () => {},
988
+ registerMessageRenderer: () => {},
989
+ registerEntryRenderer: () => {},
990
+ appendEntry: () => {},
991
+ on: () => {},
992
+ registerToolRenderer: (resolver) => resolvers.push(resolver),
993
+ };
994
+ await withCodegraphCli(() => {
995
+ // S18 (T14): the extension registers nothing without gentle-shell-bridge, so
996
+ // this file's own host publishes the shared fixture's bridge before the factory
997
+ // runs.
998
+ installDefaultBridge();
999
+ mod.default(host);
1000
+ });
1001
+ // The cards measure text through the extension's own injected seam, so the test
1002
+ // supplies it after the load — the way the other card suites inject theirs.
1003
+ mod.setWorktreeToolCardMetrics(metrics);
1004
+ return { mod, resolvers };
1005
+ } finally {
1006
+ if (savedLibDir === undefined) delete process.env.GENTLE_WORKTREE_LIB_DIR;
1007
+ else process.env.GENTLE_WORKTREE_LIB_DIR = savedLibDir;
1008
+ rmSync(dir, { recursive: true, force: true });
1009
+ }
1010
+ }
1011
+
1012
+ /** The host's chain for one tool: the registered resolvers in order, then what comes after them. */
1013
+ function hostChain(resolvers, toolName, base = HOST_BASH) {
1014
+ const resolve = (index) => (index < resolvers.length ? resolvers[index](toolName, () => resolve(index + 1)) : base);
1015
+ return resolve(0);
1016
+ }
1017
+
1018
+ /** A resolver wrapped so a case can state whether its slots were ever asked for a row. */
1019
+ function countedResolver(resolver, asked = []) {
1020
+ const wrapped = (toolName, next) => {
1021
+ const renderers = resolver(toolName, next);
1022
+ if (renderers === undefined || renderers === null) return renderers;
1023
+ const observe = (name) => (...args) => {
1024
+ asked.push(name);
1025
+ return renderers[name](...args);
1026
+ };
1027
+ return { ...renderers, renderCall: observe('renderCall'), renderResult: observe('renderResult') };
1028
+ };
1029
+ return { asked, resolver: wrapped };
1030
+ }
1031
+
1032
+ /** One bash row down a chain, as the host drives it: its call and its result, as drawn lines. */
1033
+ function drawThrough(resolvers, command, output) {
1034
+ const slot = hostChain(resolvers, 'bash');
1035
+ assert.equal(slot?.renderShell, 'self', `${command} is drawn as a self-framed card`);
1036
+ const call = slot.renderCall({ command }, plainTheme, { isPartial: false }).render(64).map(unpaint);
1037
+ const result = slot.renderResult(textResult(output), { isPartial: false }, plainTheme, { args: { command } }).render(64).map(unpaint);
1038
+ return { call, result };
1039
+ }
1040
+
1041
+ let composed;
1042
+ let codegraphAt;
1043
+
1044
+ before(async () => {
1045
+ composed = await loadComposedExtension();
1046
+ // Only the CodeGraph card claims the native `codegraph` tool.
1047
+ codegraphAt = composed.resolvers.findIndex((resolver) => resolver(CODEGRAPH_TOOL, () => HOST_BASH) !== HOST_BASH);
1048
+ });
1049
+
1050
+ after(() => {
1051
+ composed = undefined;
1052
+ });
1053
+
1054
+ test('the extension registers the CodeGraph card through the host hook', () => {
1055
+ assert.notEqual(codegraphAt, -1, 'the CodeGraph card is registered through the host hook');
1056
+ });
1057
+
1058
+ test('a bash call that runs no CodeGraph is drawn exactly as the host draws it', () => {
1059
+ // The activity heading is applied by the bridge's design (lib/bash-design.js), never by a
1060
+ // resolver of this package: the chain hands this row to the host's own renderers.
1061
+ const drawn = drawThrough(composed.resolvers, 'pnpm test', 'Tests 12 passed');
1062
+ const host = drawThrough([], 'pnpm test', 'Tests 12 passed');
1063
+ assert.deepEqual(drawn, host);
1064
+ });
1065
+
1066
+ test('a `codegraph status .` bash call is drawn by the CodeGraph card', () => {
1067
+ const output = ['┌ CodeGraph status', '│', '◆ Workspace: /tmp/ws', '● 42 nodes, 66 edges', '│', '└ Done'].join('\n');
1068
+ const drawn = drawThrough(composed.resolvers, 'codegraph status .', output);
1069
+ const heading = drawn.call.join('\n');
1070
+ assert.ok(heading.includes(`${CODEGRAPH_MARK} ${CODEGRAPH_TOOL}`), `the heading carries the CodeGraph mark and name in "${heading}"`);
1071
+ assert.match(heading, /codegraph · status \./, 'the subcommand and its argument are the heading detail');
1072
+ assert.ok(drawn.result.some((row) => row.includes('◆ Workspace: /tmp/ws')), 'the body is the CLI output the CodeGraph card composes');
1073
+ });
1074
+
1075
+ test('a `codegraph init` bash call is drawn by the CodeGraph card', () => {
1076
+ const drawn = drawThrough(composed.resolvers, 'codegraph init', INIT_FRESH);
1077
+ const heading = drawn.call.join('\n');
1078
+ assert.ok(heading.includes(`${CODEGRAPH_MARK} ${CODEGRAPH_TOOL}`), `the heading carries the CodeGraph mark and name in "${heading}"`);
1079
+ assert.match(heading, /codegraph · init/, 'the operation is the heading detail');
1080
+ });