pi-odd-worktree 3.15.1 → 3.16.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 (127) hide show
  1. package/README.md +48 -25
  2. package/extensions/odd-worktree-tools.ts +70 -212
  3. package/lib/shell-api/api.ts +523 -0
  4. package/lib/shell-api/arm.ts +83 -0
  5. package/lib/shell-api/bus.ts +1389 -0
  6. package/lib/shell-api/capture.ts +1340 -0
  7. package/lib/shell-api/card-style-line.ts +112 -0
  8. package/lib/shell-api/card-style-rows.ts +390 -0
  9. package/lib/shell-api/card-style-transform.ts +862 -0
  10. package/lib/shell-api/card-style-wiring.ts +477 -0
  11. package/lib/shell-api/card-styles.ts +153 -0
  12. package/lib/shell-api/config.ts +71 -0
  13. package/lib/shell-api/extension.ts +247 -0
  14. package/lib/shell-api/hook.ts +322 -0
  15. package/lib/shell-api/index.ts +88 -0
  16. package/lib/shell-api/message-design-adoption.ts +549 -0
  17. package/lib/shell-api/message-design-rows.ts +313 -0
  18. package/lib/shell-api/message-design-wiring.ts +369 -0
  19. package/lib/shell-api/message-designs.ts +746 -0
  20. package/lib/shell-api/notices.ts +137 -0
  21. package/lib/shell-api/plugin-lines.ts +877 -0
  22. package/lib/shell-api/presence.ts +258 -0
  23. package/lib/shell-api/repaint.ts +351 -0
  24. package/lib/shell-api/row-labels.ts +146 -0
  25. package/lib/shell-api/row-names.ts +273 -0
  26. package/lib/shell-api/row-origin.ts +144 -0
  27. package/lib/shell-api/rows.ts +591 -0
  28. package/lib/shell-api/section-panel.ts +378 -0
  29. package/lib/shell-api/section-pointer.ts +164 -0
  30. package/lib/shell-api/sections-preview.ts +275 -0
  31. package/lib/shell-api/sections-rows.ts +133 -0
  32. package/lib/shell-api/sidebar-render.ts +705 -0
  33. package/lib/shell-api/sidebar.ts +1126 -0
  34. package/lib/shell-api/store.ts +279 -0
  35. package/lib/shell-api/tool-design-adoption.ts +263 -0
  36. package/lib/shell-api/tool-design-rows.ts +307 -0
  37. package/lib/shell-api/tool-design-wiring.ts +481 -0
  38. package/lib/shell-api/tool-designs.ts +1411 -0
  39. package/lib/shell-api/transform-pipeline.ts +351 -0
  40. package/lib/shell-api/types.ts +803 -0
  41. package/lib/shell-api/visibility.ts +154 -0
  42. package/package.json +3 -2
  43. package/tools/files-bridge.test.js +81 -66
  44. package/tools/fixtures/load-extension.js +40 -18
  45. package/tools/issues-command.test.js +4 -7
  46. package/tools/issues-section.test.js +71 -81
  47. package/tools/odd-rail-wiring.test.js +16 -10
  48. package/tools/package-surface.test.js +42 -13
  49. package/tools/prs-command.test.js +11 -6
  50. package/tools/session-auto-name-wiring.test.js +39 -0
  51. package/tools/shell-api/api.test.ts +484 -0
  52. package/tools/shell-api/apply-on-move.test.ts +529 -0
  53. package/tools/shell-api/arm.test.ts +220 -0
  54. package/tools/shell-api/bridge-ready.test.ts +309 -0
  55. package/tools/shell-api/bus.test.ts +194 -0
  56. package/tools/shell-api/button-rows.test.ts +435 -0
  57. package/tools/shell-api/capture.test.ts +583 -0
  58. package/tools/shell-api/card-style-rows.test.ts +493 -0
  59. package/tools/shell-api/card-style-transform.test.ts +379 -0
  60. package/tools/shell-api/card-style-wiring.test.ts +258 -0
  61. package/tools/shell-api/card-styles-e2e.test.ts +502 -0
  62. package/tools/shell-api/card-styles.test.ts +324 -0
  63. package/tools/shell-api/card-transcript-path.test.ts +178 -0
  64. package/tools/shell-api/compatibility-regression.test.mjs +64 -0
  65. package/tools/shell-api/config.test.ts +93 -0
  66. package/tools/shell-api/docs-coverage.test.ts +82 -0
  67. package/tools/shell-api/e2e.test.ts +562 -0
  68. package/tools/shell-api/example-bash-identity.test.ts +372 -0
  69. package/tools/shell-api/example-bash-matrix.test.ts +856 -0
  70. package/tools/shell-api/example-designs.test.ts +737 -0
  71. package/tools/shell-api/example-neon-transform.test.ts +283 -0
  72. package/tools/shell-api/example-plain-style.test.ts +1225 -0
  73. package/tools/shell-api/extension.test.ts +157 -0
  74. package/tools/shell-api/fake-events.ts +58 -0
  75. package/tools/shell-api/fake-host.ts +211 -0
  76. package/tools/shell-api/fake-sidebar.ts +516 -0
  77. package/tools/shell-api/fake-transcript.ts +486 -0
  78. package/tools/shell-api/frame-telemetry.test.ts +317 -0
  79. package/tools/shell-api/hook.test.ts +196 -0
  80. package/tools/shell-api/manifest.test.ts +47 -0
  81. package/tools/shell-api/message-design-adoption.test.ts +611 -0
  82. package/tools/shell-api/message-design-follows.test.ts +361 -0
  83. package/tools/shell-api/message-design-pi-release.test.mjs +157 -0
  84. package/tools/shell-api/message-design-regressions.test.mjs +162 -0
  85. package/tools/shell-api/message-design-rows.test.ts +266 -0
  86. package/tools/shell-api/message-design-wiring.test.ts +362 -0
  87. package/tools/shell-api/message-designs.test.ts +339 -0
  88. package/tools/shell-api/new-category.test.ts +1101 -0
  89. package/tools/shell-api/notices.test.ts +292 -0
  90. package/tools/shell-api/plugin-integration-lines.test.ts +827 -0
  91. package/tools/shell-api/presence.test.ts +396 -0
  92. package/tools/shell-api/rail-part-hits.test.ts +281 -0
  93. package/tools/shell-api/rail-surfaces.test.ts +402 -0
  94. package/tools/shell-api/rail-width.test.ts +406 -0
  95. package/tools/shell-api/regression.test.ts +434 -0
  96. package/tools/shell-api/repaint-api.test.ts +200 -0
  97. package/tools/shell-api/reserved-categories.test.ts +250 -0
  98. package/tools/shell-api/row-labels.test.ts +261 -0
  99. package/tools/shell-api/row-names.test.ts +407 -0
  100. package/tools/shell-api/row-origin.test.ts +395 -0
  101. package/tools/shell-api/row-placement-regression.test.ts +797 -0
  102. package/tools/shell-api/row-placement.test.ts +410 -0
  103. package/tools/shell-api/section-interaction.test.ts +364 -0
  104. package/tools/shell-api/section-panel.test.ts +430 -0
  105. package/tools/shell-api/section-placement-rail.test.ts +390 -0
  106. package/tools/shell-api/section-placement.test.ts +386 -0
  107. package/tools/shell-api/sections-preview.test.ts +312 -0
  108. package/tools/shell-api/sections-rows.test.ts +293 -0
  109. package/tools/shell-api/sidebar-backend.test.ts +477 -0
  110. package/tools/shell-api/sidebar-e2e.test.ts +317 -0
  111. package/tools/shell-api/sidebar-hover.test.ts +276 -0
  112. package/tools/shell-api/sidebar-independent.test.ts +291 -0
  113. package/tools/shell-api/sidebar-render.test.ts +281 -0
  114. package/tools/shell-api/sidebar-sections.test.ts +247 -0
  115. package/tools/shell-api/store.test.ts +192 -0
  116. package/tools/shell-api/surface-repaint-cost.test.ts +520 -0
  117. package/tools/shell-api/tool-design-card-style.test.ts +308 -0
  118. package/tools/shell-api/tool-design-chain.test.ts +471 -0
  119. package/tools/shell-api/tool-design-cost.test.ts +591 -0
  120. package/tools/shell-api/tool-design-rows.test.ts +627 -0
  121. package/tools/shell-api/tool-design-scopes-audit.test.ts +212 -0
  122. package/tools/shell-api/tool-designs.test.ts +2412 -0
  123. package/tools/shell-api/transform-pipeline.test.ts +376 -0
  124. package/tools/shell-api/transforms-bus.test.ts +233 -0
  125. package/tools/shell-api/verifier-width-regressions.test.ts +147 -0
  126. package/tools/shell-api-rpc.test.js +189 -0
  127. package/tools/user-prompt-card.test.js +8 -9
@@ -25,9 +25,9 @@
25
25
  // `<n> issues · stale` (T10), while a failed first read is still one error row —
26
26
  // except a session cwd that is not a repository (S12/T11), whose one line is
27
27
  // exactly `not a git repository` in the `dim` tone, never `error`;
28
- // - a host with no bridge gets ONE warning per process naming
29
- // `pi install npm:gentle-shell-bridge` (T11), primary sessions only, after
30
- // the announcement window and never once the bridge announced;
28
+ // - a host with an ABSENT or INCOMPATIBLE slot gets no install hint, no warning and no
29
+ // notice at all: the shell API is native (this package's `lib/shell-api/`) since T2, so there is
30
+ // nothing to install and nobody to warn;
31
31
  // - `lines()`/`meta()` are synchronous frames over an in-process snapshot: a
32
32
  // never-settled read still answers, two stale frames schedule ONE refresh,
33
33
  // and `onRefreshed` fires once per landed refresh;
@@ -53,10 +53,10 @@
53
53
  // four arguments it always had; DEFAULT_ROW_LABEL is `github` (S4),
54
54
  // - the three states are rows (`loading…`, `no open issues`, ONE error row),
55
55
  // never a throw;
56
- // - the extension reaches the rail ONLY through gentle-shell-bridge's
57
- // published object (read from its Symbol slot, never imported): present it
58
- // registers one section, absent it subscribes to the ready announcement
59
- // once and registers nothing;
56
+ // - the extension reaches the rail ONLY through the bridge API's published object
57
+ // (read from its Symbol slot; the runtime itself is this package's own
58
+ // `lib/shell-api/`): a compatible object registers one section, an absent or
59
+ // incompatible one registers nothing and says nothing;
60
60
  // - the drawn section reads the checkout's own repository ONCE:
61
61
  // `checkoutRepoScope({cwd})` then ONE combined `gh api graphql` read of the
62
62
  // three scoped buckets, and a failed resolution is the error row with NO `gh`
@@ -86,8 +86,8 @@ const { pathToFileURL } = require('node:url');
86
86
  const { createIssuesSection } = require('../lib/issues-section.js');
87
87
 
88
88
  const BRIDGE_SLOT = Symbol.for('gentle-shell-bridge/api/v1');
89
- // T11's "one warning per process" lives on a process-wide slot, so a test that
90
- // expects the warning must not inherit another test's.
89
+ // The old "one warning per process" slot. Nothing sets it any more (T2 removed the hint),
90
+ // and the tests assert it stays untouched — a stale delete here would hide a regression.
91
91
  const WARNED_SLOT = Symbol.for('odd-worktree/issues-sidebar/install-warned');
92
92
  const IDENTITY = 'github.com/myfork/project';
93
93
 
@@ -1733,24 +1733,25 @@ test('S2: a published bridge receives exactly one section with the decided ident
1733
1733
  // RE-SCOPED (was "with no bridge and no events, nothing registers and nothing
1734
1734
  // throws", which asserted that `/issues` and both worktree tools still registered
1735
1735
  // without a bridge — the old policy, where only the bridge surfaces waited).
1736
- // S18 (T14, the human's "Desactivar todo el plugin"): with no bridge NOTHING of
1737
- // this package loads, not one command, tool, renderer, card or rail.
1738
- test('S18 (T14): with no bridge and no events, NOTHING registers and nothing throws', async () => {
1736
+ // S18 (T2): the shell API is NATIVE (this package's `lib/shell-api/`), so the only case that
1737
+ // still ships nothing is an ABSENT or INCOMPATIBLE slot — and that case says nothing
1738
+ // either: no observer, no install hint, no warn slot.
1739
+ test('S18 (T2): with no bridge and no events, NOTHING registers, nothing is said and nothing throws', async () => {
1739
1740
  delete globalThis[BRIDGE_SLOT];
1740
1741
  const loaded = await loadExtension({}, { bridge: false });
1741
1742
  assert.deepEqual([...loaded.commands.keys()], [], 'no command at all');
1742
1743
  assert.deepEqual([...loaded.tools.keys()], [], 'no tool at all');
1743
1744
  assert.deepEqual([...loaded.messageRenderers.keys()], [], 'no message renderer');
1744
1745
  assert.deepEqual([...loaded.entryRenderers.keys()], [], 'no entry renderer');
1745
- assert.deepEqual(loaded.hooks.map(([event]) => event), ['session_start'],
1746
- 'only the observer the missing-plugin notice needs');
1746
+ assert.deepEqual(loaded.hooks, [],
1747
+ 'and no hook at all: the missing-plugin observer the gate needed is gone');
1747
1748
  });
1748
1749
 
1749
1750
  // RE-SCOPED (was "with no bridge but events, the ready announcement is subscribed
1750
- // once", which also asserted `/issues` was registered). The subscription is still
1751
- // exactly one — it now carries the whole gate — and an announcement with no bridge
1752
- // on the slot still registers nothing.
1753
- test('S2/S18 (T14): with no bridge but events, the ready announcement is subscribed once and registers nothing yet', async () => {
1751
+ // once and registers nothing yet"). The hold is gone: the shell API publishes its
1752
+ // object at module load, the factory reads the slot ONCE, and a publication that lands
1753
+ // afterwards is not a wake-up path any more — the next load is.
1754
+ test('S2/S18 (T2): with no bridge but events, nothing is subscribed and nothing registers', async () => {
1754
1755
  delete globalThis[BRIDGE_SLOT];
1755
1756
  const subscriptions = [];
1756
1757
  const loaded = await loadExtension({
@@ -1761,21 +1762,13 @@ test('S2/S18 (T14): with no bridge but events, the ready announcement is subscri
1761
1762
  },
1762
1763
  },
1763
1764
  }, { bridge: false });
1764
- assert.equal(subscriptions.length, 1);
1765
- assert.equal(subscriptions[0].event, 'gentle-shell-bridge:ready');
1766
- assert.deepEqual([...loaded.commands.keys()], [], 'still nothing registered');
1767
- subscriptions[0].handler();
1768
- assert.equal(subscriptions.length, 1, 'a ready announcement is never a second subscription');
1769
- assert.deepEqual([...loaded.commands.keys()], [], 'an announcement with no published bridge registers nothing');
1770
-
1771
- // The bridge publishes and the SAME subscription registers the surface, once.
1765
+ assert.deepEqual(subscriptions, [], 'no ready announcement is listened to any more');
1766
+ assert.deepEqual([...loaded.commands.keys()], [], 'nothing registered');
1767
+
1768
+ // The bridge publishes afterwards: this load already read the slot and is done.
1772
1769
  installBridge();
1773
- subscriptions[0].handler();
1774
- assert.equal(loaded.commands.has('issues'), true, 'the published bridge brings the command');
1775
- assert.equal(loaded.tools.has('worktree_list'), true, 'and the tools');
1776
- const counted = loaded.hooks.length;
1777
- subscriptions[0].handler();
1778
- assert.equal(loaded.hooks.length, counted, 'a second announcement registers nothing twice');
1770
+ assert.deepEqual([...loaded.commands.keys()], [], 'a late publication registers nothing here');
1771
+ assert.deepEqual(subscriptions, [], 'and still nothing listens');
1779
1772
  });
1780
1773
 
1781
1774
  // S7 (T8): ONE combined read, and the rail draws the UNION of the two buckets the
@@ -2253,21 +2246,22 @@ test('S4 (T9): a row without a cross-referenced pull request carries no marker a
2253
2246
  });
2254
2247
 
2255
2248
  // ---------------------------------------------------------------------------
2256
- // T11 (S2 amended, L10): a host without the bridge gets ONE warning per process,
2257
- // primary sessions only, naming the install command. An empty slot at
2258
- // `session_start` is "not yet" — the check waits the announcement window — while
2259
- // a host with no bus can never announce and is warned at once.
2249
+ // T2 (S18): the install hint is GONE. The shell API is NATIVE (this package's
2250
+ // `lib/shell-api/`, imported by the entry), so there is nothing to install and nobody to warn: no
2251
+ // announcement window, no per-process warn slot and no `session_start` observer. What
2252
+ // this block proves instead is the SILENCE — an absent slot says nothing, a published
2253
+ // bridge registers and says nothing, and a child session says nothing.
2260
2254
  // ---------------------------------------------------------------------------
2261
2255
 
2262
2256
  function warningTexts(notices) {
2263
2257
  return notices.filter((notice) => notice.level === 'warning').map((notice) => notice.text);
2264
2258
  }
2265
2259
 
2266
- // The gate and the section's own read still have to answer: a T11 test fires a
2267
- // real `session_start`, so no child may ever reach the real `gh`.
2260
+ // The section's own read still has to answer: these tests fire a real `session_start`,
2261
+ // so no child may ever reach the real `gh`.
2268
2262
  async function bridgeWarnHarness({ events } = {}) {
2269
2263
  const checkout = makeCheckout();
2270
- // S18 (T14): the shared fixture publishes a default bridge, and this harness is
2264
+ // S18 (T14/T2): the shared fixture publishes a default bridge, and this harness is
2271
2265
  // about the ABSENT one, so it opts out: the slot is exactly what the test left.
2272
2266
  const loaded = await loadExtension(events ? { events } : {}, { bridge: false });
2273
2267
  ghIssues = require(path.join(LIB_DIR, 'gh-issues.js'));
@@ -2280,62 +2274,58 @@ async function bridgeWarnHarness({ events } = {}) {
2280
2274
  return { loaded, checkout, notices, ctx };
2281
2275
  }
2282
2276
 
2283
- test('S2 (T11): with no bridge and no bus, ONE warning names the install command', async () => {
2277
+ // RE-SCOPED (was "with no bridge and no bus, ONE warning names the install command").
2278
+ // The hint, its announce window, its process-wide warn slot and the observer that used
2279
+ // to deliver it are removed; an absent slot is simply silent.
2280
+ test('S2 (S18/T2): an absent slot says nothing, and the install hint, its window and its warn slot are gone', async () => {
2284
2281
  delete globalThis[BRIDGE_SLOT];
2285
2282
  const { loaded, notices, ctx } = await bridgeWarnHarness();
2286
2283
 
2287
2284
  await fireSessionStart(loaded.hooks, ctx);
2288
- assert.deepEqual(warningTexts(notices), [
2289
- 'the issues rail needs the gentle-shell-bridge plugin: install it with pi install npm:gentle-shell-bridge',
2290
- ], 'a host that can never announce is told at once, with the command');
2291
-
2292
- // One warning for the whole process: a second session start says nothing.
2293
- await fireSessionStart(loaded.hooks, ctx);
2294
- assert.equal(warningTexts(notices).length, 1, 'a second session_start never repeats the warning');
2285
+ assert.deepEqual(loaded.hooks, [], 'no observer is registered to warn from');
2286
+ assert.deepEqual(warningTexts(notices), [], 'and no warning names an install command');
2287
+ assert.equal(globalThis[WARNED_SLOT], undefined, 'the process-wide warn slot is never touched');
2295
2288
 
2296
- // And neither does a `/reload`, which builds a new instance of the extension:
2297
- // the human was already told, once, for this process.
2289
+ // A reloaded extension (a NEW module instance, exactly like `/reload`) says nothing
2290
+ // either, and nothing was deferred: no timer is left to fire later.
2298
2291
  const reloaded = await bridgeWarnHarness();
2299
2292
  await fireSessionStart(reloaded.loaded.hooks, reloaded.ctx);
2300
- assert.deepEqual(warningTexts(reloaded.notices), [], 'a reloaded extension stays silent');
2301
- await new Promise((resolve) => setTimeout(resolve, 100));
2302
- assert.equal(warningTexts(notices).length, 1);
2293
+ await new Promise((resolve) => setTimeout(resolve, 250));
2294
+ assert.deepEqual(warningTexts(reloaded.notices), [], 'a reload is silent too');
2295
+
2296
+ // And the entry no longer contains any of it: no hint text, no window, no slot.
2297
+ const source = stubbedSource();
2298
+ for (const gone of [
2299
+ 'ISSUES_SIDEBAR_INSTALL_HINT',
2300
+ 'ISSUES_SIDEBAR_INSTALL_WINDOW_MS',
2301
+ 'ISSUES_SIDEBAR_WARN_SLOT',
2302
+ 'install-warned',
2303
+ 'checkIssuesSidebarInstall',
2304
+ ]) {
2305
+ assert.equal(source.includes(gone), false, `${gone} is gone from the entry`);
2306
+ }
2307
+ assert.equal(source.includes('pi install npm:gentle-shell-bridge'), false,
2308
+ 'no install command is ever printed');
2303
2309
  });
2304
2310
 
2305
- test('S2 (T11): with a bus, a silent window warns once, and a late bridge cancels it', async () => {
2306
- // A host whose bus stays silent: the warning only lands after the window.
2307
- delete globalThis[BRIDGE_SLOT];
2308
- const silent = await bridgeWarnHarness({ events: { on: () => () => {} } });
2309
- const startedAt = Date.now();
2310
- await fireSessionStart(silent.loaded.hooks, silent.ctx);
2311
- assert.deepEqual(warningTexts(silent.notices), [],
2312
- 'an empty slot at session_start is "not yet", never "not installed"');
2313
- await waitFor(
2314
- () => warningTexts(silent.notices).length === 1,
2315
- 'the deferred check never warned',
2316
- );
2317
- assert.ok(Date.now() - startedAt >= 1000, 'the warning waits for the announcement window');
2318
- assert.match(warningTexts(silent.notices)[0], /pi install npm:gentle-shell-bridge/,
2319
- 'the warning names the install command verbatim');
2320
-
2321
- // A bridge that announces inside the window cancels the warning entirely.
2311
+ // RE-SCOPED (was "with a bus, a silent window warns once, and a late bridge cancels
2312
+ // it"). There is no window to wait for and no ready-announcement hold: an absent slot
2313
+ // subscribes to nothing and warns nothing.
2314
+ test('S2 (S18/T2): with a bus, an absent slot subscribes to nothing and warns nothing', async () => {
2322
2315
  delete globalThis[BRIDGE_SLOT];
2323
2316
  const subscriptions = [];
2324
- const latched = await bridgeWarnHarness({
2317
+ const silent = await bridgeWarnHarness({
2325
2318
  events: { on: (event, handler) => { subscriptions.push({ event, handler }); return () => {}; } },
2326
2319
  });
2327
- await fireSessionStart(latched.loaded.hooks, latched.ctx);
2328
- assert.deepEqual(warningTexts(latched.notices), [], 'nothing is said before the window closes');
2329
- assert.equal(subscriptions.length, 1, 'the section is subscribed to the ready announcement');
2330
- subscriptions[0].handler();
2331
- await new Promise((resolve) => setTimeout(resolve, 2300));
2332
- assert.deepEqual(warningTexts(latched.notices), [],
2333
- 'a late announcement cancels the warning the window would have produced');
2320
+ await fireSessionStart(silent.loaded.hooks, silent.ctx);
2321
+ assert.deepEqual(subscriptions, [], 'the ready-announcement wait is gone');
2322
+ await new Promise((resolve) => setTimeout(resolve, 250));
2323
+ assert.deepEqual(warningTexts(silent.notices), [], 'and no deferred warning lands either');
2324
+ assert.equal(globalThis[WARNED_SLOT], undefined, 'no warn slot is set');
2334
2325
  });
2335
2326
 
2336
- test('S2 (T11): a published bridge and a child session are never warned about', async () => {
2337
- // The bridge is installed: nothing is missing, so nothing is said, now or
2338
- // after the window.
2327
+ test('S2 (T11/T2): a published bridge and a child session are never warned about', async () => {
2328
+ // The bridge is on the slot: nothing is missing, so nothing is said.
2339
2329
  const published = installBridge();
2340
2330
  const withBridge = await bridgeWarnHarness();
2341
2331
  await fireSessionStart(withBridge.loaded.hooks, withBridge.ctx);
@@ -2345,7 +2335,7 @@ test('S2 (T11): a published bridge and a child session are never warned about',
2345
2335
  assert.deepEqual(warningTexts(withBridge.notices), []);
2346
2336
 
2347
2337
  // A child session never speaks for the human: the prompt block's own child
2348
- // signal is the test, and the warning stays silent.
2338
+ // signal is the test, and nothing here says anything at all.
2349
2339
  delete globalThis[BRIDGE_SLOT];
2350
2340
  const child = await bridgeWarnHarness();
2351
2341
  const saved = process.env.GENTLE_PI_AGENTS_CHILD;
@@ -129,8 +129,9 @@ async function load(options = {}) {
129
129
  return disposer;
130
130
  };
131
131
  globalThis[BRIDGE_SLOT] = bridge.api;
132
- // A host with no bridge registers nothing, so the case below removes the object
133
- // and then publishes one late, exactly like the plugin's own `ready` event.
132
+ // A host that publishes no bridge registers nothing (native-bridge T2): the slot is read ONCE,
133
+ // in the factory, so a case below removes the object to model it and a later publication is
134
+ // NOT a wake-up path — `noBridge` is therefore never combined with an expectation of a surface.
134
135
  if (opts.noBridge === true) delete globalThis[BRIDGE_SLOT];
135
136
  return withGhPath('present', async () => {
136
137
  process.env.GENTLE_WORKTREE_LIB_DIR = LIB_DIR;
@@ -321,19 +322,24 @@ describe('registration (S1, corrected S7)', () => {
321
322
  assert.ok(loaded.commands.has('odd'), 'and `/odd` is still the command a click dispatches');
322
323
  });
323
324
 
324
- test('with no bridge nothing is registered, and a late publication registers it', async () => {
325
+ test('with no bridge nothing is registered, and a publication after the load is picked up by the next load', async () => {
325
326
  const loaded = await load({ noBridge: true });
326
327
  assert.equal(globalThis[BRIDGE_SLOT], undefined, 'the slot really is empty');
327
328
  assert.deepEqual(loaded.sections, [], 'nothing is contributed without a bridge');
329
+ assert.deepEqual(loaded.hooks, [], 'no hook either: the gate observer is gone');
330
+ assert.deepEqual(loaded.ready, [], 'and no ready announcement is listened to');
328
331
 
329
- // The plugin publishes afterwards and announces it: the ONE subscription the
330
- // extension made answers with the section.
332
+ // The plugin publishes afterwards and announces it: this load already read the slot, so
333
+ // NEITHER the section nor a subscription answers.
331
334
  globalThis[BRIDGE_SLOT] = loaded.bridge.api;
332
- const ready = loaded.ready.filter((entry) => entry.event === 'gentle-shell-bridge:ready');
333
- assert.equal(ready.length, 1, 'one subscription for the announcement');
334
- for (const entry of ready) entry.handler();
335
- assert.equal(loaded.sections.filter((section) => section.id === RAIL_ID).length, 1,
336
- 'the late publication registers the rail once');
335
+ assert.deepEqual(loaded.sections, [], 'a late publication contributes no section to this load');
336
+ assert.deepEqual(loaded.ready, [], 'and nothing subscribes to the announcement');
337
+
338
+ // The NEXT load is the one that sees the bridge, with the rail it always had.
339
+ const next = await load();
340
+ const rail = next.sections.find((section) => section.id === RAIL_ID);
341
+ assert.ok(rail, 'the published bridge brings the rail');
342
+ assert.equal(rail.title, 'ODD');
337
343
  });
338
344
  });
339
345
 
@@ -12,10 +12,10 @@
12
12
  // are shipped; `/issues` is the T3 command that mounts them, without any
13
13
  // worktree↔issue association.
14
14
  //
15
- // The bash activity is not a preference here: it is a design on gentle-shell-bridge's
16
- // own `Card activity` line, so the shipped surface is exactly six commands, two tools, TWO
17
- // sidebar sections, one tools design and the one `Cards` row group the two file-card
18
- // switches carry. `/identity` is the name the person stores for their own prompt card and
15
+ // The bash activity is not a preference here: it is a design on this package's own shell
16
+ // API `Card activity` line, so the shipped surface is exactly six commands, two tools,
17
+ // TWO sidebar sections and the two designs (`activity`, `color`). `/identity` is the
18
+ // name the person stores for their own prompt card and
19
19
  // the orchestrator prompt: transversal like `/files`, so no module switch gates it.
20
20
  //
21
21
  // Everything here reads the observable surface: the registered command and
@@ -24,7 +24,7 @@ const { test, describe, after } = require('node:test');
24
24
  const assert = require('node:assert/strict');
25
25
  const fs = require('node:fs');
26
26
  const path = require('node:path');
27
- const { BRIDGE_SLOT, LIB_DIR, defaultBridge, loadExtension, stubbedSource } = require('./fixtures/load-extension.js');
27
+ const { BRIDGE_IMPORT, BRIDGE_SLOT, BRIDGE_STUB, LIB_DIR, defaultBridge, loadExtension, stubbedSource } = require('./fixtures/load-extension.js');
28
28
 
29
29
  const ROOT = path.resolve(__dirname, '..');
30
30
  const PKG = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
@@ -38,17 +38,34 @@ after(() => {
38
38
  });
39
39
 
40
40
  describe('manifest', () => {
41
- test('declares one Pi extension entry point and ships only that surface', () => {
41
+ test('declares one Pi extension entry point and ships only that surface (invariant 8)', () => {
42
42
  assert.equal(PKG.name, 'pi-odd-worktree');
43
43
  assert.ok(PKG.keywords.includes('pi-package'), 'keywords name the pi-package kind');
44
44
  assert.deepEqual(PKG.pi.extensions, ['./extensions/odd-worktree-tools.ts']);
45
- for (const entry of ['extensions', 'lib', 'tools', 'README.md']) {
46
- assert.ok(PKG.files.includes(entry), `files ships ${entry}`);
47
- }
45
+ // native-bridge T5 (invariant 8): the shell API is this package's own code under `lib/`, so
46
+ // there is no nested package and no negation: the list is the plain four entries again.
47
+ assert.deepEqual(PKG.files, ['extensions', 'lib', 'tools', 'README.md'],
48
+ 'files ships extensions, lib, tools and README.md');
48
49
  assert.equal(PKG.peerDependencies['@earendil-works/pi-coding-agent'], '*');
49
50
  assert.equal(PKG.peerDependencies['@earendil-works/pi-tui'], '*');
50
51
  assert.ok(!('dependencies' in PKG), 'no runtime dependencies are installed');
51
52
  assert.equal(/herdr/i.test(JSON.stringify(PKG)), false, 'the manifest claims no integration the package does not have');
53
+ // native-bridge T5: `test` is the plain-JS gate it always was, and the shell API's TypeScript
54
+ // suite is its own script — the same two globs CI runs.
55
+ assert.equal(PKG.scripts.test, 'node --test tools/*.test.js', 'the plain-JS gate is unchanged');
56
+ assert.equal(PKG.scripts['test:shell-api'], 'node --test tools/shell-api/*.test.ts tools/shell-api/*.test.mjs',
57
+ 'the shell API suite has its own script');
58
+ });
59
+
60
+ // native-bridge T5 (invariant 1): there is ONE package manifest. The shell API is code inside
61
+ // this package — no `package.json` of its own — so its sources, its suite and its docs are
62
+ // shipped only through the root `files` list.
63
+ test('the shell API is code in this package, never a nested package (invariant 1)', () => {
64
+ assert.equal(fs.existsSync(path.join(ROOT, 'lib/shell-api/package.json')), false,
65
+ 'no nested manifest exists');
66
+ assert.ok(!('name' in (PKG.lib ?? {})), 'and none is declared on the root manifest');
67
+ assert.ok(fs.existsSync(path.join(ROOT, 'lib/shell-api/extension.ts')), 'the entry can import the shell API factory');
68
+ assert.ok(fs.existsSync(path.join(ROOT, 'docs/shell-api/contract.md')), 'the contract ships for plugin authors');
52
69
  });
53
70
 
54
71
  test('ships no module for the removed commands', () => {
@@ -86,11 +103,17 @@ describe('manifest', () => {
86
103
  });
87
104
 
88
105
  describe('registration', () => {
106
+ // S2/S4 (native-bridge T5): the shipped surface is SIX commands — `/bridge-status` is gone with
107
+ // `lib/shell-api/status.ts`, and the shell API registers no command of its own. This plain-JS
108
+ // suite cannot import a `.ts` file, so the fixture stubs the shell API import (a no-op factory)
109
+ // and what it observes here is the six this package registers itself; the `bridgeExtension(pi)`
110
+ // call is pinned on the stubbed source below.
89
111
  test('registers /warp, /odd, /files, /issues, /prs, /identity and the two worktree tools', async () => {
90
112
  delete process.env.GENTLE_WORKTREE_THREAD;
91
113
  const { commands, tools, messageRenderers } = await loadExtension({});
92
114
  const registered = [...commands.keys()].sort();
93
- assert.deepEqual(registered, ['files', 'identity', 'issues', 'odd', 'prs', 'warp'], 'the command list is exactly the six panels');
115
+ assert.deepEqual(registered, ['files', 'identity', 'issues', 'odd', 'prs', 'warp'], 'exactly six commands');
116
+ assert.equal(stubbedSource().includes('bridgeExtension(pi)'), true, 'and the entry calls that factory plainly');
94
117
  assert.deepEqual([...tools.keys()].sort(), ['worktree_create', 'worktree_list'], 'exactly two agent tools');
95
118
  assert.deepEqual([...messageRenderers.keys()], ['worktree-warp']);
96
119
  });
@@ -122,10 +145,16 @@ describe('registration', () => {
122
145
  }
123
146
  });
124
147
 
125
- test('the bridge is never imported, and the surface reaches it through its published object', async () => {
148
+ // native-bridge T2/T5 (S2/S4): the shell API is NATIVE — this package's own `lib/shell-api/`,
149
+ // imported by the entry itself — and it is reached ONLY that way: never by the package's name,
150
+ // so no host has to install anything for this extension to have the API.
151
+ test('the shell API is imported from this package only, and the surface still reaches it through its published object', async () => {
126
152
  const source = stubbedSource();
127
- assert.equal(/from\s+["']gentle-shell-bridge/.test(source), false, 'no import of the bridge package anywhere');
128
- assert.equal(/require\(\s*["']gentle-shell-bridge/.test(source), false, 'no require of the bridge package anywhere');
153
+ const raw = fs.readFileSync(path.join(ROOT, 'extensions/odd-worktree-tools.ts'), 'utf8');
154
+ assert.ok(raw.includes(BRIDGE_IMPORT), 'the entry imports this package\'s own shell API');
155
+ assert.equal(source.includes(BRIDGE_STUB), true, 'and the plain-JS copy stubs that one import');
156
+ assert.equal(/from\s+["']gentle-shell-bridge/.test(raw), false, 'no import of the bridge package anywhere');
157
+ assert.equal(/require\(\s*["']gentle-shell-bridge/.test(raw), false, 'no require of the bridge package anywhere');
129
158
  assert.equal(source.split('api.registerSection(').length - 1, 2, 'exactly two sidebar sections are contributed');
130
159
  // T5 (S1): the count alone would drift silently, so the ids are asserted through
131
160
  // the bridge that received them: one `GITHUB` and one `ODD`, and nothing else.
@@ -653,14 +653,15 @@ describe('/prs overlay and reads (S1, S3)', () => {
653
653
  });
654
654
 
655
655
  test('S8/T22: the rail cache seeds the first frame, so /prs opens as fast as /issues', async () => {
656
- const b = await boot({ railMine: [{ number: 69, title: 'mine sixty-nine' }], railReview: [{ number: 70, title: 'review seventy' }] });
656
+ // T2 (native-bridge): the slot is read ONCE, in the factory, so the bridge a test measures is
657
+ // published BEFORE the load — a publication after it is not a wake-up path any more.
657
658
  const { registered } = installBridge();
659
+ const b = await boot({ railMine: [{ number: 69, title: 'mine sixty-nine' }], railReview: [{ number: 70, title: 'review seventy' }] });
658
660
  await warmGate(b.loaded);
659
661
  const root = makeCheckout();
660
662
  const ctx = sessionCtx(root);
661
- // The first start publishes the surface; the second is the session whose rail
662
- // reads, which is the in-memory entry `/prs` seeds from. Nothing is opened in
663
- // between, so this is exactly the state a click on the rail finds.
663
+ // The rail's own read belongs to the session it serves: one start binds the session the section
664
+ // reads with, and nothing is opened in between, so this is exactly the state a click finds.
664
665
  await fireSessionStart(b.loaded.hooks, sessionCtx(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-prs-seed-')))));
665
666
  await fireSessionStart(b.loaded.hooks, ctx);
666
667
  await drawSection(registered[0], ctx);
@@ -1039,11 +1040,15 @@ describe('S5: the session-start preload is dispatched, never awaited', () => {
1039
1040
  }
1040
1041
 
1041
1042
  async function gatedBoot() {
1043
+ // T2 (native-bridge): the bridge is published BEFORE the load, because the slot is read once,
1044
+ // in the factory — a surface that arrives later does not exist.
1045
+ installBridge();
1042
1046
  const b = await boot();
1047
+ // A REPUBLISHED bridge is a NEW binding: the section the spy can see is the one the first
1048
+ // `session_start` mounts on it, exactly as a shutdown-and-remount does.
1043
1049
  const { registered } = installBridge();
1044
1050
  const spy = spySectionFactory(b.loaded.mod);
1045
- // The first start publishes the surface (the bridge arrived after the load);
1046
- // the section exists from here on.
1051
+ // The first start binds the republished section; it exists from here on.
1047
1052
  await fireSessionStart(b.loaded.hooks, sessionCtx(track(fs.mkdtempSync(path.join(os.tmpdir(), 'odd-prs-gate-')))));
1048
1053
  const root = makeCheckout();
1049
1054
  const ctx = sessionCtx(root);
@@ -39,6 +39,15 @@ function git(cwd, args) {
39
39
  return execFileSync('git', args, { cwd, encoding: 'utf8' }).trim();
40
40
  }
41
41
 
42
+ // A checkout this package owns — `<repo-parent>/<repo-name>-worktrees/<odd>`, the
43
+ // one path rule the registry has — with its own `odd/tasks/`.
44
+ function makeWorktree(repo, odd) {
45
+ const dir = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, odd);
46
+ git(repo, ['worktree', 'add', '-q', dir, '-b', `feat/${odd}`]);
47
+ fs.mkdirSync(path.join(dir, 'odd', 'tasks'), { recursive: true });
48
+ return dir;
49
+ }
50
+
42
51
  // A repository whose principal checkout IS the ODD's home: one commit, `odd/tasks/`
43
52
  // present, nothing registered.
44
53
  function makeRepo() {
@@ -157,3 +166,33 @@ describe('naming from the principal checkout', () => {
157
166
  assert.equal(host.state.name, 'Mi sesión de investigación');
158
167
  });
159
168
  });
169
+
170
+ describe('naming follows the document, not the checkout the call started in', () => {
171
+ test('a write into a registered worktree renames from the principal checkout', async () => {
172
+ const repo = makeRepo();
173
+ const worktree = makeWorktree(repo, 'older-session');
174
+ const host = makeHost();
175
+ const extension = await loadExtension(host);
176
+ // The harness keeps its session in the principal checkout and the agent writes
177
+ // the ODD document where the work actually lives: the worktree.
178
+ fireToolCall(
179
+ extension,
180
+ { toolName: 'write', arguments: { path: path.join(worktree, 'odd/tasks/prompt-card-fix.md') } },
181
+ contextFor(host, repo),
182
+ );
183
+ assert.equal(host.state.name, 'Prompt card fix');
184
+ });
185
+
186
+ test('a write from inside that same worktree still renames', async () => {
187
+ const repo = makeRepo();
188
+ const worktree = makeWorktree(repo, 'older-session');
189
+ const host = makeHost();
190
+ const extension = await loadExtension(host);
191
+ fireToolCall(
192
+ extension,
193
+ { toolName: 'edit', arguments: { path: 'odd/tasks/warp-odd-picker.md' } },
194
+ contextFor(host, worktree),
195
+ );
196
+ assert.equal(host.state.name, 'Warp odd picker');
197
+ });
198
+ });