pi-odd-worktree 2.0.0 → 3.0.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.
Files changed (160) hide show
  1. package/README.md +54 -311
  2. package/extensions/odd-worktree-tools.ts +4149 -2447
  3. package/lib/bash-activity.js +1164 -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 +1416 -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 +308 -14
  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 -711
  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 +1419 -0
  75. package/tools/bash-design.test.js +1091 -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 +610 -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 +1871 -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 +391 -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 +1512 -66
  121. package/tools/issues-open-guard.test.js +1096 -0
  122. package/tools/issues-section.test.js +4195 -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 +2569 -308
  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 +477 -93
  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,575 @@
1
+ 'use strict';
2
+ // T19 (S36, S41), T2 (S5) and T14 (S18) together: the picker's and the issues
3
+ // panel's keys are bound directly on the host, and the package itself loads only
4
+ // when gentle-shell-bridge is published.
5
+ //
6
+ // What this file proves, all of it through the loaded extension:
7
+ // - `alt+p` is bound with `pi.registerShortcut` at load — FIRST and complete —
8
+ // `alt+i` is bound beside it (S5), and `/files` and `/issues` are registered
9
+ // under their own names (S36/S41);
10
+ // - `GENTLE_PI_FILES_KEY` / `GENTLE_PI_ISSUES_KEY` override those keys, and an
11
+ // empty (or blank) override falls back to `alt+p` / `alt+i`;
12
+ // - without the `gh` CLI `/issues` never registers, and its key is never bound;
13
+ // - each bound handler is the SAME path its command opens, with the session
14
+ // context the host hands a shortcut;
15
+ // - a complete bridge is handed NO keymap and NO palette row for `files`, and is
16
+ // never asked to resolve a key, while the shortcut is still bound (S36);
17
+ // - a late bridge announcement and a `session_start` never add those rows and
18
+ // never bind a second key;
19
+ // - a host without `registerShortcut`, a host that throws from it, and a missing
20
+ // command handler never break the extension and say nothing;
21
+ // - with NO bridge the package registers NOTHING — no command, no tool, no
22
+ // renderer, no hook, no key — and only ONE notice names the install line (S18,
23
+ // T14); a malformed bridge is the same silence, and the ONE ready announcement
24
+ // is what brings the whole surface to life, exactly once.
25
+ //
26
+ // Where the two contracts meet (this is the merge of main's T15 with this
27
+ // branch's S18): the key is bound at load, but it is bound inside the package's
28
+ // single registration episode, so a host with no bridge gets no key because it
29
+ // gets no surface at all.
30
+ //
31
+ // The bridge slot is process-wide, so it is restored after every test, and the
32
+ // environment this file touches is snapshotted and restored in `after`.
33
+
34
+ const { test, after, afterEach } = require('node:test');
35
+ const assert = require('node:assert/strict');
36
+ const fs = require('node:fs');
37
+ const os = require('node:os');
38
+ const path = require('node:path');
39
+
40
+ const { loadExtension, withGhPath } = require('./fixtures/load-extension.js');
41
+
42
+ const BRIDGE_SLOT = Symbol.for('gentle-shell-bridge/api/v1');
43
+ const READY_EVENT = 'gentle-shell-bridge:ready';
44
+ // The one line `/files` answers a host with no overlay: the proof that the bound
45
+ // key reached the command's own path.
46
+ const NO_UI_LINE = 'files: the file picker needs an interactive session with overlay support';
47
+ // The shared statement a directory outside any repository gets, at info. The
48
+ // issues key and the `/issues` command must answer with this same line.
49
+ const noRepositoryLine = (cwd) => `not a git repository: ${cwd}; run 'git init' first`;
50
+
51
+ const savedEnv = { ...process.env };
52
+ const scratch = [];
53
+ after(() => {
54
+ delete globalThis[BRIDGE_SLOT];
55
+ for (const key of Object.keys(process.env)) {
56
+ if (!(key in savedEnv)) delete process.env[key];
57
+ }
58
+ for (const [key, value] of Object.entries(savedEnv)) process.env[key] = value;
59
+ for (const dir of scratch) {
60
+ try { fs.rmSync(dir, { recursive: true, force: true }); } catch { /* best effort */ }
61
+ }
62
+ });
63
+
64
+ afterEach(() => {
65
+ delete globalThis[BRIDGE_SLOT];
66
+ delete process.env.GENTLE_PI_FILES_KEY;
67
+ delete process.env.GENTLE_PI_ISSUES_KEY;
68
+ });
69
+
70
+ // A fake bridge on the real slot, complete enough for every surface this package
71
+ // could possibly contribute to: it records each registration and each
72
+ // resolution, so a `files` row — or even a question about one — is visible.
73
+ //
74
+ // S18 (T14): the gate this package loads behind validates the WHOLE published
75
+ // object (`schema`, `version`, `registerSection`, `registerRows`, `createStore`),
76
+ // so a fake that only carried the picker's two old members would be "no bridge"
77
+ // and this suite would test an extension that never loaded. The members no
78
+ // assertion here measures are therefore present but inert; `members` overrides
79
+ // any of them to model a throwing or partial bridge.
80
+ function installBridge({ members = {} } = {}) {
81
+ const keymaps = [];
82
+ const commands = [];
83
+ const resolved = [];
84
+ const api = {
85
+ schema: 'gentle-shell-bridge/api',
86
+ version: 1,
87
+ registerSection: () => () => {},
88
+ registerRows: () => () => {},
89
+ registerToolDesign: () => () => {},
90
+ createStore: () => ({}),
91
+ requestRepaint: () => {},
92
+ registerKeymap: (registration) => {
93
+ keymaps.push(registration);
94
+ return () => {};
95
+ },
96
+ registerCommands: (registration) => {
97
+ commands.push(registration);
98
+ return () => {};
99
+ },
100
+ resolveKeymap: (id) => {
101
+ resolved.push(id);
102
+ return { key: 'alt+p' };
103
+ },
104
+ ...members,
105
+ };
106
+ globalThis[BRIDGE_SLOT] = api;
107
+ return { api, keymaps, commands, resolved };
108
+ }
109
+
110
+ // A fake host whose ONE added seam is the shortcut registration the package makes
111
+ // itself. `loadExtension` merges it over its own double, so every other
112
+ // registration is the loader's real one.
113
+ function installHost() {
114
+ const shortcuts = [];
115
+ const pi = {
116
+ registerShortcut: (key, options) => {
117
+ shortcuts.push({ key, options });
118
+ },
119
+ };
120
+ return { pi, shortcuts };
121
+ }
122
+
123
+ function sessionStartHandlers(hooks) {
124
+ return hooks.filter(([event]) => event === 'session_start').map(([, handler]) => handler);
125
+ }
126
+
127
+ async function fireSessionStart(hooks, ctx) {
128
+ for (const handler of sessionStartHandlers(hooks)) {
129
+ const out = handler({}, ctx);
130
+ if (out && typeof out.then === 'function') await out;
131
+ }
132
+ }
133
+
134
+ // A bound key is fire-and-forget for the host — it never awaits the command's own
135
+ // async path — so a test that compares its effect with the command's waits for
136
+ // both sinks to answer instead of assuming the keypress returned settled.
137
+ async function settled(sinks) {
138
+ for (let attempt = 0; attempt < 200; attempt += 1) {
139
+ if (sinks.every((sink) => sink.length > 0)) return;
140
+ await new Promise((resolve) => setTimeout(resolve, 5));
141
+ }
142
+ }
143
+
144
+ // `session_start` also runs the `/issues` gate, so no test may reach a real `gh`:
145
+ // the fake runner fails fast and the gate closes without a child process.
146
+ async function stubGh() {
147
+ const { LIB_DIR } = require('./fixtures/load-extension.js');
148
+ const ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
149
+ ghIssues.setGhRunner(async () => ({ status: 1, stdout: '', stderr: 'no gh here', error: null }));
150
+ ghIssues.setGitRunner(async () => ({ status: 1, stdout: '', stderr: 'no git here', error: null }));
151
+ }
152
+
153
+ function notifyHost() {
154
+ const notifications = [];
155
+ return {
156
+ notifications,
157
+ ctx: {
158
+ cwd: practiceCheckout(),
159
+ ui: { notify: (text, level) => notifications.push([level, text]) },
160
+ },
161
+ };
162
+ }
163
+
164
+ // A plain directory with no repository in it: the picker answers early and the
165
+ // key's only observable effect is the line it reaches.
166
+ function practiceCheckout() {
167
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'odd-files-bridge-'));
168
+ scratch.push(dir);
169
+ return fs.realpathSync(dir);
170
+ }
171
+
172
+ // The `files` rows a fake bridge was handed, if any: the whole claim S36 removes.
173
+ function filesRows(rows) {
174
+ return rows.filter((row) => row && row.id === 'files');
175
+ }
176
+
177
+ // ---------------------------------------------------------------------------
178
+ // S36/S41: the key is bound directly, no bridge row involved.
179
+ // ---------------------------------------------------------------------------
180
+
181
+ test('S41/S5: the shortcuts bind alt+p first and alt+i beside it, and both commands still register', async () => {
182
+ const bridge = installBridge();
183
+ const host = installHost();
184
+ const loaded = await loadExtension(host.pi);
185
+
186
+ assert.equal(host.shortcuts.length, 2, 'the picker key and the issues key are bound, and nothing else');
187
+ assert.equal(host.shortcuts[0].key, 'alt+p', 'the picker key is still bound FIRST, at its default (S41)');
188
+ assert.equal(typeof host.shortcuts[0].options.handler, 'function');
189
+ assert.equal(typeof host.shortcuts[0].options.description, 'string');
190
+ assert.equal(host.shortcuts[1].key, 'alt+i', 'the issues panel follows it at its default (S5)');
191
+ assert.equal(typeof host.shortcuts[1].options.handler, 'function');
192
+ assert.equal(typeof host.shortcuts[1].options.description, 'string');
193
+ assert.notEqual(host.shortcuts[1].options.description, host.shortcuts[0].options.description,
194
+ 'each key describes its own surface');
195
+ assert.equal(loaded.commands.has('files'), true, '/files is still registered under its own name');
196
+ assert.equal(loaded.commands.has('issues'), true, 'and /issues is the command behind the second key');
197
+ assert.deepEqual(bridge.keymaps, [], 'this package contributes no keymap action at all');
198
+ assert.deepEqual(bridge.commands, [], 'nor any palette row');
199
+ assert.deepEqual(bridge.resolved, [], 'and the shell is never asked to resolve a key');
200
+ assert.notEqual(globalThis[BRIDGE_SLOT], undefined, 'the bridge is the host\'s own published object');
201
+ });
202
+
203
+ test('S41: GENTLE_PI_FILES_KEY overrides the bound key', async () => {
204
+ installBridge();
205
+ process.env.GENTLE_PI_FILES_KEY = 'ctrl+shift+f';
206
+ const host = installHost();
207
+ await loadExtension(host.pi);
208
+
209
+ assert.equal(host.shortcuts.length, 2);
210
+ assert.equal(host.shortcuts[0].key, 'ctrl+shift+f', 'the environment variable wins over the default');
211
+ assert.equal(host.shortcuts[1].key, 'alt+i', 'and the picker\'s override moves no other key');
212
+ });
213
+
214
+ test('S41: an empty or blank override falls back to alt+p', async () => {
215
+ installBridge();
216
+ for (const value of ['', ' ']) {
217
+ process.env.GENTLE_PI_FILES_KEY = value;
218
+ const host = installHost();
219
+ await loadExtension(host.pi);
220
+ assert.equal(host.shortcuts.length, 2, `the two keys are bound for the override ${JSON.stringify(value)}`);
221
+ assert.equal(host.shortcuts[0].key, 'alt+p', `an empty override is not a key: ${JSON.stringify(value)}`);
222
+ assert.equal(host.shortcuts[1].key, 'alt+i', `and it moves no other key: ${JSON.stringify(value)}`);
223
+ }
224
+ });
225
+
226
+ test('S36: the bound key runs the SAME path /files opens, with the session context', async () => {
227
+ installBridge();
228
+ const host = installHost();
229
+ const loaded = await loadExtension(host.pi);
230
+
231
+ const sink = notifyHost();
232
+ await host.shortcuts[0].options.handler(sink.ctx);
233
+ assert.deepEqual(sink.notifications, [['info', NO_UI_LINE]],
234
+ 'the bound key reaches the command handler with the context the host handed it');
235
+
236
+ const direct = notifyHost();
237
+ await loaded.commands.get('files').handler('', direct.ctx);
238
+ assert.deepEqual(direct.notifications, [['info', NO_UI_LINE]], 'and the command answers the same way');
239
+ });
240
+
241
+ // ---------------------------------------------------------------------------
242
+ // S5 (issues-linked-prs-and-alt-i T2): the second host shortcut, `alt+i`.
243
+ // ---------------------------------------------------------------------------
244
+
245
+ test('S5: alt+i binds at load and its handler opens what /issues opens', async () => {
246
+ installBridge();
247
+ const host = installHost();
248
+ const loaded = await loadExtension(host.pi);
249
+
250
+ assert.equal(host.shortcuts.length, 2, 'the issues key is bound beside the picker key');
251
+ assert.equal(host.shortcuts[1].key, 'alt+i', 'the default key is alt+i (S5)');
252
+
253
+ // One directory outside any repository: the key and the command must refuse in
254
+ // exactly the same words, which is the observable that they are one path.
255
+ const cwd = practiceCheckout();
256
+ const keyed = [];
257
+ const direct = [];
258
+ const ctxTo = (sink) => ({ cwd, ui: { notify: (text, level) => sink.push([level, text]) } });
259
+
260
+ // The `gh` probe answers at CALL time, so it is held present here: the gate this
261
+ // test compares is the repository one, and neither path may reach a real `gh`.
262
+ await withGhPath('present', async () => {
263
+ await host.shortcuts[1].options.handler(ctxTo(keyed));
264
+ await loaded.commands.get('issues').handler('', ctxTo(direct));
265
+ await settled([keyed, direct]);
266
+ });
267
+
268
+ assert.equal(keyed.length, 1, 'the key answers exactly once, like the command');
269
+ assert.deepEqual(keyed, direct, 'the key runs the command\'s OWN path, never a copy of it');
270
+ assert.deepEqual(keyed, [['info', noRepositoryLine(cwd)]],
271
+ 'and outside a repository the shared statement is the info line');
272
+ });
273
+
274
+ test('S5: GENTLE_PI_ISSUES_KEY overrides the issues key and moves no other key', async () => {
275
+ installBridge();
276
+ process.env.GENTLE_PI_ISSUES_KEY = 'ctrl+shift+i';
277
+ const host = installHost();
278
+ await loadExtension(host.pi);
279
+
280
+ assert.equal(host.shortcuts.length, 2);
281
+ assert.equal(host.shortcuts[0].key, 'alt+p', 'the picker key is untouched');
282
+ assert.equal(host.shortcuts[1].key, 'ctrl+shift+i', 'the environment variable wins over the default');
283
+ });
284
+
285
+ test('S5: an empty or blank issues override falls back to alt+i', async () => {
286
+ installBridge();
287
+ for (const value of ['', ' ']) {
288
+ process.env.GENTLE_PI_ISSUES_KEY = value;
289
+ const host = installHost();
290
+ await loadExtension(host.pi);
291
+ assert.equal(host.shortcuts.length, 2, `the two keys are bound for the override ${JSON.stringify(value)}`);
292
+ assert.equal(host.shortcuts[1].key, 'alt+i', `an empty override is not a key: ${JSON.stringify(value)}`);
293
+ delete process.env.GENTLE_PI_ISSUES_KEY;
294
+ }
295
+ });
296
+
297
+ test('S5: without the gh CLI no issues key is bound, and the picker key still is', async () => {
298
+ installBridge();
299
+ const host = installHost();
300
+ const loaded = await loadExtension(host.pi, { gh: false });
301
+
302
+ assert.equal(loaded.commands.has('issues'), false, 'the gate leaves /issues unregistered');
303
+ assert.deepEqual(host.shortcuts.map((entry) => entry.key), ['alt+p'],
304
+ 'so no dead issues key is bound, and the picker key is unaffected');
305
+ });
306
+
307
+ // ---------------------------------------------------------------------------
308
+ // S36: a bridge present and complete still gets NO files row, and no resolve.
309
+ // ---------------------------------------------------------------------------
310
+
311
+ test('S36: a complete bridge receives no keymap row and no palette row for files', async () => {
312
+ const bridge = installBridge();
313
+ const host = installHost();
314
+ const loaded = await loadExtension(host.pi);
315
+
316
+ assert.deepEqual(filesRows(bridge.keymaps), [], 'no registerKeymap call carries the id files');
317
+ assert.deepEqual(filesRows(bridge.commands), [], 'no registerCommands call carries the id files');
318
+ assert.deepEqual(bridge.keymaps, [], 'and this package contributes no keymap action at all');
319
+ assert.deepEqual(bridge.commands, [], 'nor any palette row');
320
+ assert.deepEqual(bridge.resolved, [], 'the shell is never asked to resolve a key');
321
+ assert.deepEqual(host.shortcuts.map((entry) => entry.key), ['alt+p', 'alt+i'], 'the shortcuts are still bound');
322
+ assert.equal(loaded.commands.has('files'), true);
323
+ assert.equal(loaded.commands.has('issues'), true);
324
+ });
325
+
326
+ // ---------------------------------------------------------------------------
327
+ // S18 (T14): no bridge, no package. The policy the human chose, verbatim:
328
+ // "Desactivar todo el plugin" — when gentle-shell-bridge is not published, this
329
+ // extension registers NOTHING: no command, no tool, no renderer, no card, no rail,
330
+ // no hook, no prompt append, and no key. The only thing that happens is ONE
331
+ // notice naming the install line, in a primary session.
332
+ // ---------------------------------------------------------------------------
333
+
334
+ // The harness may itself run inside an agent child (`GENTLE_PI_AGENTS_CHILD=1`),
335
+ // which is exactly the signal the notice's primary-session rule respects, so this
336
+ // test owns it: cleared here, restored after.
337
+ test('S18/S19 (T14): with no bridge NOTHING registers, and ONE notice names the install line', async () => {
338
+ delete globalThis[BRIDGE_SLOT];
339
+ const savedChild = process.env.GENTLE_PI_AGENTS_CHILD;
340
+ delete process.env.GENTLE_PI_AGENTS_CHILD;
341
+ try {
342
+ const host = installHost();
343
+ const loaded = await loadExtension(host.pi, { bridge: false });
344
+
345
+ assert.equal(host.shortcuts.length, 0, 'nothing is bound');
346
+ assert.deepEqual([...loaded.commands.keys()], [], 'no command');
347
+ assert.deepEqual([...loaded.tools.keys()], [], 'no tool');
348
+ assert.deepEqual([...loaded.messageRenderers.keys()], [], 'no message renderer');
349
+ assert.deepEqual([...loaded.entryRenderers.keys()], [], 'no entry renderer');
350
+ assert.deepEqual(loaded.hooks.map(([event]) => event), ['session_start'],
351
+ 'the ONE observer the missing-plugin notice needs (notify lives on the session), and nothing else');
352
+ assert.equal(globalThis[BRIDGE_SLOT], undefined, 'nothing is published by this package');
353
+
354
+ // The notice: the existing missing-plugin window, in a primary session.
355
+ const sink = notifyHost();
356
+ await fireSessionStart(loaded.hooks, sink.ctx);
357
+ assert.deepEqual(sink.notifications, [[
358
+ 'warning',
359
+ 'the issues rail needs the gentle-shell-bridge plugin: install it with pi install npm:gentle-shell-bridge',
360
+ ]], 'exactly one notice, naming npm:gentle-shell-bridge and its install line');
361
+
362
+ // And the session did not load a surface either.
363
+ assert.deepEqual([...loaded.commands.keys()], [], 'a session start without a bridge still registers no command');
364
+ assert.deepEqual([...loaded.tools.keys()], [], 'and no tool');
365
+ assert.equal(host.shortcuts.length, 0, 'and binds nothing');
366
+ } finally {
367
+ if (savedChild === undefined) delete process.env.GENTLE_PI_AGENTS_CHILD;
368
+ else process.env.GENTLE_PI_AGENTS_CHILD = savedChild;
369
+ }
370
+ });
371
+
372
+ test('S18/S19: a malformed bridge is no bridge, and a bridge without the picker\'s old rows is still complete', async () => {
373
+ const wrongSchema = installBridge();
374
+ wrongSchema.api.schema = 'gentle-shell-bridge/api/v2';
375
+ const schemaHost = installHost();
376
+ await loadExtension(schemaHost.pi);
377
+ assert.deepEqual(wrongSchema.keymaps, [], 'a foreign schema registers nothing');
378
+ assert.deepEqual(wrongSchema.commands, []);
379
+ assert.equal(schemaHost.shortcuts.length, 0, 'and binds no key');
380
+
381
+ delete globalThis[BRIDGE_SLOT];
382
+ const wrongVersion = installBridge();
383
+ wrongVersion.api.version = 2;
384
+ const versionHost = installHost();
385
+ await loadExtension(versionHost.pi);
386
+ assert.deepEqual(wrongVersion.keymaps, []);
387
+ assert.equal(versionHost.shortcuts.length, 0);
388
+
389
+ delete globalThis[BRIDGE_SLOT];
390
+ // The picker's two OLD members (`registerKeymap`, `registerCommands`) are no
391
+ // longer used by any surface, so a bridge without them is still a bridge this
392
+ // package loads behind: the surface registers and the key is bound.
393
+ const partial = installBridge({ members: { registerKeymap: undefined, registerCommands: undefined } });
394
+ const partialHost = installHost();
395
+ const loaded = await loadExtension(partialHost.pi);
396
+ assert.deepEqual(partialHost.shortcuts.map((entry) => entry.key), ['alt+p', 'alt+i'],
397
+ 'the keys come from the host, not from those members');
398
+ assert.deepEqual(partial.keymaps, [], 'nothing is contributed to a member that is absent');
399
+ assert.equal(loaded.commands.has('files'), true, 'the surface still registers');
400
+ });
401
+
402
+ // ---------------------------------------------------------------------------
403
+ // A bridge that publishes later, from the ONE ready announcement.
404
+ // ---------------------------------------------------------------------------
405
+
406
+ // RE-SCOPED (was "a bridge that publishes later lands both registrations from the
407
+ // ready event", which assumed the whole package had already registered eagerly at
408
+ // load and only the bridge surfaces waited). The announcement is now what brings
409
+ // the ENTIRE surface to life, and it may bring it exactly once.
410
+ test('S18/S19 (T14): the ready announcement registers the whole surface, exactly once', async () => {
411
+ delete globalThis[BRIDGE_SLOT];
412
+ const subscriptions = [];
413
+ const host = installHost();
414
+ const loaded = await loadExtension({
415
+ ...host.pi,
416
+ events: {
417
+ on: (event, handler) => {
418
+ subscriptions.push({ event, handler });
419
+ return () => {};
420
+ },
421
+ },
422
+ }, { bridge: false });
423
+
424
+ // Nothing at all while the bridge is absent, and ONE subscription listening for it.
425
+ assert.deepEqual([...loaded.commands.keys()], [], 'no command before the announcement');
426
+ assert.deepEqual([...loaded.tools.keys()], [], 'no tool either');
427
+ assert.equal(host.shortcuts.length, 0, 'and no key: there is no surface for it to open');
428
+ const ready = subscriptions.filter((entry) => entry.event === READY_EVENT);
429
+ assert.equal(ready.length, 1, 'ONE shared announcement subscription carries the whole gate');
430
+ assert.equal(subscriptions.every((entry) => entry.event === READY_EVENT), true, 'and nothing else is listened to');
431
+
432
+ // The bridge publishes and announces.
433
+ const bridge = installBridge();
434
+ for (const entry of ready) entry.handler();
435
+
436
+ assert.deepEqual([...loaded.commands.keys()].sort(), ['files', 'issues', 'odd', 'warp'],
437
+ 'the four commands arrive with the bridge');
438
+ assert.deepEqual([...loaded.tools.keys()].sort(), ['worktree_create', 'worktree_list'], 'the two tools');
439
+ assert.deepEqual([...loaded.messageRenderers.keys()], ['worktree-warp'], 'the message renderer');
440
+ assert.deepEqual([...loaded.entryRenderers.keys()].sort(), ['odd-worktree-issues-refusal', 'odd-worktree-warp-queue'],
441
+ 'both entry renderers');
442
+ const hookNames = new Set(loaded.hooks.map(([event]) => event));
443
+ for (const name of ['session_start', 'session_shutdown', 'tool_call', 'tool_result', 'turn_end', 'before_agent_start']) {
444
+ assert.equal(hookNames.has(name), true, `the ${name} hooks arrive too`);
445
+ }
446
+
447
+ // The picker's contribution to the BRIDGE is now none at all: the key is bound
448
+ // on the host, once, as part of that same registration episode.
449
+ assert.deepEqual(filesRows(bridge.keymaps), [], 'the late bridge is handed no keymap row');
450
+ assert.deepEqual(filesRows(bridge.commands), [], 'nor a palette row');
451
+ assert.deepEqual(bridge.resolved, [], 'and is never asked for a key');
452
+ assert.deepEqual(host.shortcuts.map((entry) => entry.key), ['alt+p', 'alt+i'],
453
+ 'the episode binds the picker key and the issues key, once each');
454
+
455
+ const sink = notifyHost();
456
+ await host.shortcuts[0].options.handler(sink.ctx);
457
+ assert.deepEqual(sink.notifications, [['info', NO_UI_LINE]], 'the late key reaches the picker path');
458
+
459
+ // A second announcement is a no-op: nothing registers twice, and no second key.
460
+ const commandCount = loaded.commands.size;
461
+ const toolCount = loaded.tools.size;
462
+ const hookCount = loaded.hooks.length;
463
+ for (const entry of ready) entry.handler();
464
+ assert.equal(loaded.commands.size, commandCount, 'a second announcement registers no second command');
465
+ assert.equal(loaded.tools.size, toolCount, 'no second tool');
466
+ assert.equal(loaded.hooks.length, hookCount, 'and no second hook');
467
+ assert.deepEqual(bridge.keymaps, [], 'and no second keymap action');
468
+ assert.deepEqual(bridge.commands, [], 'and no second palette row');
469
+ assert.equal(host.shortcuts.length, 2, 'the same two keys are still bound exactly once');
470
+ });
471
+
472
+ // ---------------------------------------------------------------------------
473
+ // Idempotent: a session start never stacks a second contribution or key.
474
+ // ---------------------------------------------------------------------------
475
+
476
+ test('S36: two session starts add no files row and no second key', async () => {
477
+ await stubGh();
478
+ const bridge = installBridge();
479
+ const host = installHost();
480
+ const loaded = await loadExtension(host.pi);
481
+
482
+ assert.equal(host.shortcuts.length, 2);
483
+
484
+ const ctx = notifyHost().ctx;
485
+ await fireSessionStart(loaded.hooks, ctx);
486
+ await fireSessionStart(loaded.hooks, ctx);
487
+ assert.deepEqual(filesRows(bridge.keymaps), [], 'a session start contributes nothing');
488
+ assert.deepEqual(filesRows(bridge.commands), []);
489
+ assert.equal(host.shortcuts.length, 2, 'and never stacks a second shortcut');
490
+
491
+ const sink = notifyHost();
492
+ await host.shortcuts[0].options.handler(sink.ctx);
493
+ assert.deepEqual(sink.notifications, [['info', NO_UI_LINE]], 'the one key still reaches the picker path');
494
+ });
495
+
496
+ // ---------------------------------------------------------------------------
497
+ // A broken bridge never breaks the extension.
498
+ // ---------------------------------------------------------------------------
499
+
500
+ test('S18/S19: a bridge whose members throw never breaks the extension', async () => {
501
+ const boom = () => { throw new Error('bridge member exploded'); };
502
+ // The members that ARE used: the rail's section, the `Cards` rows, the design
503
+ // and the store. The key no longer depends on the bridge at all.
504
+ const bridge = installBridge({
505
+ members: {
506
+ registerSection: boom,
507
+ registerRows: boom,
508
+ registerToolDesign: boom,
509
+ createStore: boom,
510
+ },
511
+ });
512
+ const host = installHost();
513
+ const loaded = await loadExtension(host.pi);
514
+
515
+ assert.equal(loaded.commands.has('files'), true, 'the command still registers');
516
+ assert.equal(loaded.tools.has('worktree_list'), true, 'the other surfaces still register');
517
+ assert.equal(host.shortcuts.length, 2, 'and the host bound both keys anyway');
518
+ assert.deepEqual(bridge.keymaps, [], 'a throwing bridge contributed no row');
519
+ assert.deepEqual(bridge.commands, []);
520
+
521
+ await stubGh();
522
+ await fireSessionStart(loaded.hooks, notifyHost().ctx);
523
+ assert.equal(host.shortcuts.length, 2, 'a session start changes nothing');
524
+ });
525
+
526
+ // ---------------------------------------------------------------------------
527
+ // A host that cannot take the key never breaks the extension.
528
+ // ---------------------------------------------------------------------------
529
+
530
+ test('S36/S5: a host with no registerShortcut at all still gets /files and /issues and never throws', async () => {
531
+ const loaded = await loadExtension({});
532
+ assert.equal(loaded.commands.has('files'), true, 'the command is the whole surface without a key');
533
+ assert.equal(loaded.commands.has('issues'), true, 'and so is /issues: the keys are the convenience, never the surface');
534
+ assert.equal(loaded.tools.has('worktree_list'), true, 'no other surface changes');
535
+
536
+ const sink = notifyHost();
537
+ await loaded.commands.get('files').handler('', sink.ctx);
538
+ assert.deepEqual(sink.notifications, [['info', NO_UI_LINE]]);
539
+ });
540
+
541
+ test('S36/S5: a host that refuses the shortcut says nothing and keeps both commands', async () => {
542
+ installBridge();
543
+ const attempted = [];
544
+ const loaded = await loadExtension({
545
+ registerShortcut: (key) => {
546
+ attempted.push(key);
547
+ throw new Error('the host refuses the key');
548
+ },
549
+ });
550
+ assert.deepEqual(attempted, ['alt+p', 'alt+i'],
551
+ 'both keys are offered to the host, in the order they are bound');
552
+ assert.equal(loaded.commands.has('files'), true, 'the picker command is unaffected');
553
+ assert.equal(loaded.commands.has('issues'), true, 'and so is the issues command');
554
+ const sink = notifyHost();
555
+ await loaded.commands.get('files').handler('', sink.ctx);
556
+ assert.deepEqual(sink.notifications, [['info', NO_UI_LINE]]);
557
+ });
558
+
559
+ test('S36: a missing command handler makes the bound key inert, never a throw', async () => {
560
+ installBridge();
561
+ const host = installHost();
562
+ await loadExtension({
563
+ ...host.pi,
564
+ registerCommand: undefined,
565
+ });
566
+
567
+ assert.deepEqual(host.shortcuts.map((entry) => entry.key), ['alt+p'],
568
+ 'only the picker binds: a host that took no command registered no issues command either');
569
+ // A host that took no command has no handler for the key to reach; the call
570
+ // must simply do nothing.
571
+ for (const entry of host.shortcuts) {
572
+ await entry.options.handler(notifyHost().ctx);
573
+ assert.equal(typeof entry.options.handler, 'function');
574
+ }
575
+ });