pi-odd-worktree 3.15.1 → 3.16.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.
- package/README.md +48 -25
- package/extensions/odd-worktree-tools.ts +64 -211
- package/lib/shell-api/api.ts +523 -0
- package/lib/shell-api/arm.ts +83 -0
- package/lib/shell-api/bus.ts +1389 -0
- package/lib/shell-api/capture.ts +1340 -0
- package/lib/shell-api/card-style-line.ts +112 -0
- package/lib/shell-api/card-style-rows.ts +390 -0
- package/lib/shell-api/card-style-transform.ts +862 -0
- package/lib/shell-api/card-style-wiring.ts +477 -0
- package/lib/shell-api/card-styles.ts +153 -0
- package/lib/shell-api/config.ts +71 -0
- package/lib/shell-api/extension.ts +247 -0
- package/lib/shell-api/hook.ts +322 -0
- package/lib/shell-api/index.ts +88 -0
- package/lib/shell-api/message-design-adoption.ts +549 -0
- package/lib/shell-api/message-design-rows.ts +313 -0
- package/lib/shell-api/message-design-wiring.ts +369 -0
- package/lib/shell-api/message-designs.ts +746 -0
- package/lib/shell-api/notices.ts +137 -0
- package/lib/shell-api/plugin-lines.ts +877 -0
- package/lib/shell-api/presence.ts +258 -0
- package/lib/shell-api/repaint.ts +351 -0
- package/lib/shell-api/row-labels.ts +146 -0
- package/lib/shell-api/row-names.ts +273 -0
- package/lib/shell-api/row-origin.ts +144 -0
- package/lib/shell-api/rows.ts +591 -0
- package/lib/shell-api/section-panel.ts +378 -0
- package/lib/shell-api/section-pointer.ts +164 -0
- package/lib/shell-api/sections-preview.ts +275 -0
- package/lib/shell-api/sections-rows.ts +133 -0
- package/lib/shell-api/sidebar-render.ts +705 -0
- package/lib/shell-api/sidebar.ts +1126 -0
- package/lib/shell-api/store.ts +279 -0
- package/lib/shell-api/tool-design-adoption.ts +263 -0
- package/lib/shell-api/tool-design-rows.ts +307 -0
- package/lib/shell-api/tool-design-wiring.ts +481 -0
- package/lib/shell-api/tool-designs.ts +1411 -0
- package/lib/shell-api/transform-pipeline.ts +351 -0
- package/lib/shell-api/types.ts +803 -0
- package/lib/shell-api/visibility.ts +154 -0
- package/package.json +3 -2
- package/tools/files-bridge.test.js +81 -66
- package/tools/fixtures/load-extension.js +40 -18
- package/tools/issues-command.test.js +4 -7
- package/tools/issues-section.test.js +71 -81
- package/tools/odd-rail-wiring.test.js +16 -10
- package/tools/package-surface.test.js +42 -13
- package/tools/prs-command.test.js +11 -6
- package/tools/shell-api/api.test.ts +484 -0
- package/tools/shell-api/apply-on-move.test.ts +529 -0
- package/tools/shell-api/arm.test.ts +220 -0
- package/tools/shell-api/bridge-ready.test.ts +309 -0
- package/tools/shell-api/bus.test.ts +194 -0
- package/tools/shell-api/button-rows.test.ts +435 -0
- package/tools/shell-api/capture.test.ts +583 -0
- package/tools/shell-api/card-style-rows.test.ts +493 -0
- package/tools/shell-api/card-style-transform.test.ts +379 -0
- package/tools/shell-api/card-style-wiring.test.ts +258 -0
- package/tools/shell-api/card-styles-e2e.test.ts +502 -0
- package/tools/shell-api/card-styles.test.ts +324 -0
- package/tools/shell-api/card-transcript-path.test.ts +178 -0
- package/tools/shell-api/compatibility-regression.test.mjs +64 -0
- package/tools/shell-api/config.test.ts +93 -0
- package/tools/shell-api/docs-coverage.test.ts +82 -0
- package/tools/shell-api/e2e.test.ts +562 -0
- package/tools/shell-api/example-bash-identity.test.ts +372 -0
- package/tools/shell-api/example-bash-matrix.test.ts +856 -0
- package/tools/shell-api/example-designs.test.ts +737 -0
- package/tools/shell-api/example-neon-transform.test.ts +283 -0
- package/tools/shell-api/example-plain-style.test.ts +1225 -0
- package/tools/shell-api/extension.test.ts +157 -0
- package/tools/shell-api/fake-events.ts +58 -0
- package/tools/shell-api/fake-host.ts +211 -0
- package/tools/shell-api/fake-sidebar.ts +516 -0
- package/tools/shell-api/fake-transcript.ts +486 -0
- package/tools/shell-api/frame-telemetry.test.ts +317 -0
- package/tools/shell-api/hook.test.ts +196 -0
- package/tools/shell-api/manifest.test.ts +47 -0
- package/tools/shell-api/message-design-adoption.test.ts +611 -0
- package/tools/shell-api/message-design-follows.test.ts +361 -0
- package/tools/shell-api/message-design-pi-release.test.mjs +157 -0
- package/tools/shell-api/message-design-regressions.test.mjs +162 -0
- package/tools/shell-api/message-design-rows.test.ts +266 -0
- package/tools/shell-api/message-design-wiring.test.ts +362 -0
- package/tools/shell-api/message-designs.test.ts +339 -0
- package/tools/shell-api/new-category.test.ts +1101 -0
- package/tools/shell-api/notices.test.ts +292 -0
- package/tools/shell-api/plugin-integration-lines.test.ts +827 -0
- package/tools/shell-api/presence.test.ts +396 -0
- package/tools/shell-api/rail-part-hits.test.ts +281 -0
- package/tools/shell-api/rail-surfaces.test.ts +402 -0
- package/tools/shell-api/rail-width.test.ts +406 -0
- package/tools/shell-api/regression.test.ts +434 -0
- package/tools/shell-api/repaint-api.test.ts +200 -0
- package/tools/shell-api/reserved-categories.test.ts +250 -0
- package/tools/shell-api/row-labels.test.ts +261 -0
- package/tools/shell-api/row-names.test.ts +407 -0
- package/tools/shell-api/row-origin.test.ts +395 -0
- package/tools/shell-api/row-placement-regression.test.ts +797 -0
- package/tools/shell-api/row-placement.test.ts +410 -0
- package/tools/shell-api/section-interaction.test.ts +364 -0
- package/tools/shell-api/section-panel.test.ts +430 -0
- package/tools/shell-api/section-placement-rail.test.ts +390 -0
- package/tools/shell-api/section-placement.test.ts +386 -0
- package/tools/shell-api/sections-preview.test.ts +312 -0
- package/tools/shell-api/sections-rows.test.ts +293 -0
- package/tools/shell-api/sidebar-backend.test.ts +477 -0
- package/tools/shell-api/sidebar-e2e.test.ts +317 -0
- package/tools/shell-api/sidebar-hover.test.ts +276 -0
- package/tools/shell-api/sidebar-independent.test.ts +291 -0
- package/tools/shell-api/sidebar-render.test.ts +281 -0
- package/tools/shell-api/sidebar-sections.test.ts +247 -0
- package/tools/shell-api/store.test.ts +192 -0
- package/tools/shell-api/surface-repaint-cost.test.ts +520 -0
- package/tools/shell-api/tool-design-card-style.test.ts +308 -0
- package/tools/shell-api/tool-design-chain.test.ts +471 -0
- package/tools/shell-api/tool-design-cost.test.ts +591 -0
- package/tools/shell-api/tool-design-rows.test.ts +627 -0
- package/tools/shell-api/tool-design-scopes-audit.test.ts +212 -0
- package/tools/shell-api/tool-designs.test.ts +2412 -0
- package/tools/shell-api/transform-pipeline.test.ts +376 -0
- package/tools/shell-api/transforms-bus.test.ts +233 -0
- package/tools/shell-api/verifier-width-regressions.test.ts +147 -0
- package/tools/shell-api-rpc.test.js +189 -0
- package/tools/user-prompt-card.test.js +8 -9
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge-owned section visibility (S5, S6).
|
|
3
|
+
*
|
|
4
|
+
* Whether a section is shown is the BRIDGE's state, not the plugin's: the plugin asked for a
|
|
5
|
+
* section, the bridge added the toggle that hides it. Keeping it in the bridge's own store is what
|
|
6
|
+
* makes S1's "one call, zero extra steps" true — a plugin never needs a store, a setting name, a
|
|
7
|
+
* file or a `current()` of its own, and a user's choice survives `/reload` like any native setting.
|
|
8
|
+
*
|
|
9
|
+
* Why not the host's `visual-customization.json`: the host validates that file against a closed
|
|
10
|
+
* `VISUAL_SECTION_KEYS` list (`lib/visual-customization-policy.ts:82`, `keysMatch` ~:112-130) and
|
|
11
|
+
* rejects unknown keys, so a third-party section key cannot live there (S6). The user experience is
|
|
12
|
+
* the native one; the file deliberately is not.
|
|
13
|
+
*
|
|
14
|
+
* One file, one key. `createStore("bridge-sections")` writes
|
|
15
|
+
* `<gentle config home>/gentle-shell-bridge/bridge-sections.json`:
|
|
16
|
+
*
|
|
17
|
+
* ```json
|
|
18
|
+
* {
|
|
19
|
+
* "schemaVersion": 1,
|
|
20
|
+
* "values": {
|
|
21
|
+
* "sections": { "loon.music": false }
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* `sections` maps a section id to `true` (shown) / `false` (hidden); a missing id falls back to the
|
|
27
|
+
* section's `defaultVisible` (absent means shown). Values that are not booleans are ignored rather
|
|
28
|
+
* than coerced, so a hand-edited file cannot make a "hidden" section render.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { isRecord } from "./rows.ts";
|
|
32
|
+
import { createStore } from "./store.ts";
|
|
33
|
+
import type { SidebarSection } from "./types.ts";
|
|
34
|
+
|
|
35
|
+
/** The bridge's own plugin id for section visibility: one namespaced file for every section. */
|
|
36
|
+
export const SECTIONS_STORE_ID = "bridge-sections";
|
|
37
|
+
|
|
38
|
+
/** The key that holds section visibility. */
|
|
39
|
+
export const SECTIONS_STORE_KEY = "sections";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The key that holds section collapse state (N13). One file, two keys: both are bridge-owned state
|
|
43
|
+
* about the same sections, so a user's choices survive `/reload` together, and a single store write
|
|
44
|
+
* can never erase the other map.
|
|
45
|
+
*
|
|
46
|
+
* ```json
|
|
47
|
+
* { "schemaVersion": 1, "values": { "sections": { "loon.music": false }, "collapsed": { "loon.music": true } } }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export const SECTIONS_COLLAPSED_KEY = "collapsed";
|
|
51
|
+
|
|
52
|
+
/** Section id → visible. Only booleans from disk survive the read. */
|
|
53
|
+
export type SectionVisibility = Record<string, boolean>;
|
|
54
|
+
|
|
55
|
+
/** Section id → collapsed. Same rules as `SectionVisibility`. */
|
|
56
|
+
export type SectionCollapsed = Record<string, boolean>;
|
|
57
|
+
|
|
58
|
+
function toFlagMap(value: unknown): SectionVisibility {
|
|
59
|
+
// A NULL-prototype map on purpose: a persisted key such as `__proto__` must be an ordinary entry.
|
|
60
|
+
// On a plain `{}` that write hits the inherited setter, is silently dropped, and the next toggle
|
|
61
|
+
// erases it (B2).
|
|
62
|
+
const map = Object.create(null) as SectionVisibility;
|
|
63
|
+
if (!isRecord(value)) return map;
|
|
64
|
+
for (const [id, entry] of Object.entries(value)) {
|
|
65
|
+
if (typeof entry === "boolean") map[id] = entry;
|
|
66
|
+
}
|
|
67
|
+
return map;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Read one flag map once. One read per frame (the renderer) and one per menu build (the rows), so a
|
|
72
|
+
* frame never costs a file read per section.
|
|
73
|
+
*/
|
|
74
|
+
function readFlags(key: string): SectionVisibility {
|
|
75
|
+
return toFlagMap(createStore(SECTIONS_STORE_ID).get<unknown>(key, {}));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Whether one section's flag is on right now: the persisted value when there is one, otherwise the
|
|
80
|
+
* caller's fallback.
|
|
81
|
+
*/
|
|
82
|
+
function isFlagOn(
|
|
83
|
+
map: SectionVisibility,
|
|
84
|
+
id: string,
|
|
85
|
+
fallback: boolean,
|
|
86
|
+
): boolean {
|
|
87
|
+
// Own property only: the map has no prototype, but a caller may hand us an ordinary object, and
|
|
88
|
+
// `map["constructor"]` must never resolve to `Object`'s.
|
|
89
|
+
const stored = Object.hasOwn(map, id) ? map[id] : undefined;
|
|
90
|
+
return typeof stored === "boolean" ? stored : fallback;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Persist one flag, FIRST and synchronously, so the host's repaint that follows reads the new value.
|
|
95
|
+
* Reads the current map in the same call, so two sections' writes never overwrite each other, and
|
|
96
|
+
* writes through the same null-prototype shape the read produced.
|
|
97
|
+
*/
|
|
98
|
+
function writeFlag(key: string, id: string, value: boolean): void {
|
|
99
|
+
const store = createStore(SECTIONS_STORE_ID);
|
|
100
|
+
const current = toFlagMap(store.get<unknown>(key, {}));
|
|
101
|
+
const next = Object.create(null) as SectionVisibility;
|
|
102
|
+
for (const [entry, flag] of Object.entries(current)) next[entry] = flag;
|
|
103
|
+
next[id] = value;
|
|
104
|
+
store.set(key, next);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Read the whole visibility map once. One read per frame (the renderer) and one per menu build (the
|
|
109
|
+
* rows), so a frame never costs a file read per section.
|
|
110
|
+
*/
|
|
111
|
+
export function getSectionVisibility(): SectionVisibility {
|
|
112
|
+
return readFlags(SECTIONS_STORE_KEY);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Whether one section is visible right now: the persisted value when there is one, otherwise the
|
|
117
|
+
* section's `defaultVisible` (absent means visible).
|
|
118
|
+
*/
|
|
119
|
+
export function isSectionVisible(
|
|
120
|
+
visibility: SectionVisibility,
|
|
121
|
+
section: Pick<SidebarSection, "id" | "defaultVisible">,
|
|
122
|
+
): boolean {
|
|
123
|
+
return isFlagOn(visibility, section.id, section.defaultVisible !== false);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Persist one section's visibility, FIRST and synchronously, so the host's repaint that follows
|
|
128
|
+
* reads the new value.
|
|
129
|
+
*/
|
|
130
|
+
export function setSectionVisible(id: string, visible: boolean): void {
|
|
131
|
+
writeFlag(SECTIONS_STORE_KEY, id, visible);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The whole collapse map (N13). Collapsed is bridge-owned state for the same reason visibility is:
|
|
136
|
+
* the bridge added the header that folds the card, so the plugin needs no flag, no setting and no
|
|
137
|
+
* store of its own.
|
|
138
|
+
*/
|
|
139
|
+
export function getSectionCollapsed(): SectionCollapsed {
|
|
140
|
+
return readFlags(SECTIONS_COLLAPSED_KEY);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Whether one section is collapsed right now. A section with no stored value is EXPANDED: a card a
|
|
145
|
+
* user has never folded is open, which is the state the host's own sections start in.
|
|
146
|
+
*/
|
|
147
|
+
export function isSectionCollapsed(collapsed: SectionCollapsed, section: Pick<SidebarSection, "id">): boolean {
|
|
148
|
+
return isFlagOn(collapsed, section.id, false);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Persist one section's collapse state, FIRST and synchronously, for the repaint that follows. */
|
|
152
|
+
export function setSectionCollapsed(id: string, collapsed: boolean): void {
|
|
153
|
+
writeFlag(SECTIONS_COLLAPSED_KEY, id, collapsed);
|
|
154
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.0",
|
|
4
4
|
"description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
]
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"test": "node --test tools/*.test.js"
|
|
36
|
+
"test": "node --test tools/*.test.js",
|
|
37
|
+
"test:shell-api": "node --test tools/shell-api/*.test.ts tools/shell-api/*.test.mjs"
|
|
37
38
|
}
|
|
38
39
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
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
|
-
//
|
|
3
|
+
// panel's keys are bound directly on the host, and the package itself loads only when a
|
|
4
|
+
// compatible bridge object is on the published slot (native since native-bridge T2).
|
|
5
5
|
//
|
|
6
6
|
// What this file proves, all of it through the loaded extension:
|
|
7
7
|
// - `alt+p` is bound with `pi.registerShortcut` at load — FIRST and complete —
|
|
@@ -14,14 +14,13 @@
|
|
|
14
14
|
// context the host hands a shortcut;
|
|
15
15
|
// - a complete bridge is handed NO keymap and NO palette row for `files`, and is
|
|
16
16
|
// never asked to resolve a key, while the shortcut is still bound (S36);
|
|
17
|
-
// - a
|
|
18
|
-
// never bind a second key;
|
|
17
|
+
// - a `session_start` never adds those rows and never binds a second key;
|
|
19
18
|
// - a host without `registerShortcut`, a host that throws from it, and a missing
|
|
20
19
|
// command handler never break the extension and say nothing;
|
|
21
|
-
// - with
|
|
22
|
-
// renderer, no hook, no key — and
|
|
23
|
-
//
|
|
24
|
-
// is
|
|
20
|
+
// - with an ABSENT or INCOMPATIBLE slot the package registers NOTHING — no command, no
|
|
21
|
+
// tool, no renderer, no hook, no key — and says nothing either: the install hint, its
|
|
22
|
+
// warn slot and the ready-event hold are gone (S18, T2). The slot is read ONCE per load,
|
|
23
|
+
// so a publication that lands afterwards is picked up by the next load, not by this one.
|
|
25
24
|
//
|
|
26
25
|
// Where the two contracts meet (this is the merge of main's T15 with this
|
|
27
26
|
// branch's S18): the key is bound at load, but it is bound inside the package's
|
|
@@ -40,7 +39,6 @@ const path = require('node:path');
|
|
|
40
39
|
const { loadExtension, withGhPath } = require('./fixtures/load-extension.js');
|
|
41
40
|
|
|
42
41
|
const BRIDGE_SLOT = Symbol.for('gentle-shell-bridge/api/v1');
|
|
43
|
-
const READY_EVENT = 'gentle-shell-bridge:ready';
|
|
44
42
|
// The one line `/files` answers a host with no overlay: the proof that the bound
|
|
45
43
|
// key reached the command's own path.
|
|
46
44
|
const NO_UI_LINE = 'files: the file picker needs an interactive session with overlay support';
|
|
@@ -324,43 +322,47 @@ test('S36: a complete bridge receives no keymap row and no palette row for files
|
|
|
324
322
|
});
|
|
325
323
|
|
|
326
324
|
// ---------------------------------------------------------------------------
|
|
327
|
-
// S18 (T14)
|
|
328
|
-
//
|
|
329
|
-
//
|
|
330
|
-
// no
|
|
331
|
-
//
|
|
325
|
+
// S18 (T14) as amended by native-bridge T2/T5: the shell API is NATIVE (this package's
|
|
326
|
+
// own `lib/shell-api/`), so an ABSENT or INCOMPATIBLE slot is the only case left where this
|
|
327
|
+
// package ships nothing. The policy the human chose for that case, "Desactivar todo el
|
|
328
|
+
// plugin", still holds — no command, no tool, no renderer, no card, no rail, no hook, no
|
|
329
|
+
// prompt append and no key — and nothing is SAID either: there is no install hint, no
|
|
330
|
+
// notice and no observer left to say it with.
|
|
332
331
|
// ---------------------------------------------------------------------------
|
|
333
332
|
|
|
334
|
-
|
|
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 () => {
|
|
333
|
+
test('S18/S19 (T2): with no bridge NOTHING registers and NOTHING is said', async () => {
|
|
338
334
|
delete globalThis[BRIDGE_SLOT];
|
|
339
335
|
const savedChild = process.env.GENTLE_PI_AGENTS_CHILD;
|
|
340
336
|
delete process.env.GENTLE_PI_AGENTS_CHILD;
|
|
341
337
|
try {
|
|
338
|
+
const subscriptions = [];
|
|
342
339
|
const host = installHost();
|
|
343
|
-
const loaded = await loadExtension(
|
|
340
|
+
const loaded = await loadExtension({
|
|
341
|
+
...host.pi,
|
|
342
|
+
events: {
|
|
343
|
+
on: (event, handler) => {
|
|
344
|
+
subscriptions.push({ event, handler });
|
|
345
|
+
return () => {};
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
}, { bridge: false });
|
|
344
349
|
|
|
345
350
|
assert.equal(host.shortcuts.length, 0, 'nothing is bound');
|
|
346
351
|
assert.deepEqual([...loaded.commands.keys()], [], 'no command');
|
|
347
352
|
assert.deepEqual([...loaded.tools.keys()], [], 'no tool');
|
|
348
353
|
assert.deepEqual([...loaded.messageRenderers.keys()], [], 'no message renderer');
|
|
349
354
|
assert.deepEqual([...loaded.entryRenderers.keys()], [], 'no entry renderer');
|
|
350
|
-
assert.deepEqual(loaded.hooks
|
|
351
|
-
'
|
|
355
|
+
assert.deepEqual(loaded.hooks, [],
|
|
356
|
+
'and no hook at all: the missing-plugin observer the gate needed is gone');
|
|
352
357
|
assert.equal(globalThis[BRIDGE_SLOT], undefined, 'nothing is published by this package');
|
|
358
|
+
assert.deepEqual(subscriptions, [], 'and no ready announcement is listened to either');
|
|
353
359
|
|
|
354
|
-
//
|
|
360
|
+
// Nothing is ever said: a session start is impossible (no hook was registered) and a
|
|
361
|
+
// publication on the bus reaches no listener of this package.
|
|
355
362
|
const sink = notifyHost();
|
|
356
363
|
await fireSessionStart(loaded.hooks, sink.ctx);
|
|
357
|
-
assert.deepEqual(sink.notifications, [
|
|
358
|
-
|
|
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(sink.notifications, [], 'no install hint, no warning, no notice');
|
|
365
|
+
assert.deepEqual([...loaded.commands.keys()], [], 'a session start without a bridge registers no command');
|
|
364
366
|
assert.deepEqual([...loaded.tools.keys()], [], 'and no tool');
|
|
365
367
|
assert.equal(host.shortcuts.length, 0, 'and binds nothing');
|
|
366
368
|
} finally {
|
|
@@ -400,14 +402,16 @@ test('S18/S19: a malformed bridge is no bridge, and a bridge without the picker\
|
|
|
400
402
|
});
|
|
401
403
|
|
|
402
404
|
// ---------------------------------------------------------------------------
|
|
403
|
-
// A
|
|
405
|
+
// A publication that arrives AFTER the factory is not a wake-up path any more.
|
|
404
406
|
// ---------------------------------------------------------------------------
|
|
405
407
|
|
|
406
|
-
// RE-SCOPED (was "
|
|
407
|
-
//
|
|
408
|
-
//
|
|
409
|
-
//
|
|
410
|
-
|
|
408
|
+
// RE-SCOPED (was "the ready announcement registers the whole surface, exactly once",
|
|
409
|
+
// which was the deferred gate). The bridge is native and the entry imports it, so its
|
|
410
|
+
// object is on the slot BEFORE the factory runs and the slot is read ONCE, in the factory:
|
|
411
|
+
// there is no hold, no observer and no announcement subscription left to bring a surface
|
|
412
|
+
// to life. A slot that is empty at factory time therefore stays empty for that load, and
|
|
413
|
+
// the NEXT load (a `/reload` builds a new module instance) is what picks the bridge up.
|
|
414
|
+
test('S18/S19 (T2): a bridge that publishes after the factory is not picked up by that load', async () => {
|
|
411
415
|
delete globalThis[BRIDGE_SLOT];
|
|
412
416
|
const subscriptions = [];
|
|
413
417
|
const host = installHost();
|
|
@@ -421,52 +425,63 @@ test('S18/S19 (T14): the ready announcement registers the whole surface, exactly
|
|
|
421
425
|
},
|
|
422
426
|
}, { bridge: false });
|
|
423
427
|
|
|
424
|
-
// Nothing at all while the
|
|
425
|
-
assert.deepEqual([...loaded.commands.keys()], [], 'no command before the
|
|
428
|
+
// Nothing at all while the slot is empty, and nothing listening for a later arrival.
|
|
429
|
+
assert.deepEqual([...loaded.commands.keys()], [], 'no command before the bridge exists');
|
|
426
430
|
assert.deepEqual([...loaded.tools.keys()], [], 'no tool either');
|
|
427
|
-
assert.
|
|
428
|
-
|
|
429
|
-
assert.
|
|
430
|
-
assert.equal(subscriptions.every((entry) => entry.event === READY_EVENT), true, 'and nothing else is listened to');
|
|
431
|
+
assert.deepEqual(loaded.hooks, [], 'no hook');
|
|
432
|
+
assert.equal(host.shortcuts.length, 0, 'and no key');
|
|
433
|
+
assert.deepEqual(subscriptions, [], 'and no announcement subscription: the wait is gone');
|
|
431
434
|
|
|
432
|
-
// The bridge publishes and
|
|
435
|
+
// The bridge publishes afterwards: this load has already read the slot and is done.
|
|
433
436
|
const bridge = installBridge();
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
assert.deepEqual(
|
|
437
|
-
|
|
438
|
-
assert.deepEqual(
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const
|
|
437
|
+
assert.deepEqual([...loaded.commands.keys()], [], 'a late publication adds no command');
|
|
438
|
+
assert.deepEqual([...loaded.tools.keys()], [], 'no tool');
|
|
439
|
+
assert.deepEqual(loaded.hooks, [], 'no hook');
|
|
440
|
+
assert.equal(host.shortcuts.length, 0, 'and no key');
|
|
441
|
+
assert.deepEqual(subscriptions, [], 'still nothing listens');
|
|
442
|
+
|
|
443
|
+
// The next load is the one that sees it, with the whole surface it always had.
|
|
444
|
+
const nextSubscriptions = [];
|
|
445
|
+
const nextHost = installHost();
|
|
446
|
+
const reloaded = await loadExtension({
|
|
447
|
+
...nextHost.pi,
|
|
448
|
+
events: {
|
|
449
|
+
on: (event, handler) => {
|
|
450
|
+
nextSubscriptions.push({ event, handler });
|
|
451
|
+
return () => {};
|
|
452
|
+
},
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
assert.deepEqual([...reloaded.commands.keys()].sort(), ['files', 'identity', 'issues', 'odd', 'prs', 'warp'],
|
|
456
|
+
'the six commands arrive with the published bridge');
|
|
457
|
+
assert.deepEqual([...reloaded.tools.keys()].sort(), ['worktree_create', 'worktree_list'], 'the two tools');
|
|
458
|
+
assert.deepEqual([...reloaded.messageRenderers.keys()], ['worktree-warp'], 'the message renderer');
|
|
459
|
+
assert.deepEqual([...reloaded.entryRenderers.keys()].sort(),
|
|
460
|
+
['odd-worktree-issues-refusal', 'odd-worktree-warp-queue'], 'both entry renderers');
|
|
461
|
+
const hookNames = new Set(reloaded.hooks.map(([event]) => event));
|
|
443
462
|
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
|
|
463
|
+
assert.equal(hookNames.has(name), true, `the ${name} hooks are registered`);
|
|
445
464
|
}
|
|
446
465
|
|
|
447
|
-
// The picker's contribution to the BRIDGE is
|
|
448
|
-
//
|
|
449
|
-
assert.deepEqual(filesRows(bridge.keymaps), [], 'the
|
|
466
|
+
// The picker's contribution to the BRIDGE is none at all: the key is bound on the host,
|
|
467
|
+
// once, as part of that same registration episode.
|
|
468
|
+
assert.deepEqual(filesRows(bridge.keymaps), [], 'the bridge is handed no keymap row');
|
|
450
469
|
assert.deepEqual(filesRows(bridge.commands), [], 'nor a palette row');
|
|
451
470
|
assert.deepEqual(bridge.resolved, [], 'and is never asked for a key');
|
|
452
|
-
assert.deepEqual(
|
|
471
|
+
assert.deepEqual(nextHost.shortcuts.map((entry) => entry.key), ['alt+p', 'alt+i'],
|
|
453
472
|
'the episode binds the picker key and the issues key, once each');
|
|
454
473
|
|
|
455
474
|
const sink = notifyHost();
|
|
456
|
-
await
|
|
457
|
-
assert.deepEqual(sink.notifications, [['info', NO_UI_LINE]], 'the
|
|
475
|
+
await nextHost.shortcuts[0].options.handler(sink.ctx);
|
|
476
|
+
assert.deepEqual(sink.notifications, [['info', NO_UI_LINE]], 'the key reaches the picker path');
|
|
458
477
|
|
|
459
478
|
// A second announcement is a no-op: nothing registers twice, and no second key.
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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');
|
|
479
|
+
for (const entry of nextSubscriptions) entry.handler();
|
|
480
|
+
assert.deepEqual([...reloaded.commands.keys()].sort(), ['files', 'identity', 'issues', 'odd', 'prs', 'warp'],
|
|
481
|
+
'a repeated announcement registers no second command');
|
|
482
|
+
assert.equal(nextHost.shortcuts.length, 2, 'and binds no second key');
|
|
467
483
|
assert.deepEqual(bridge.keymaps, [], 'and no second keymap action');
|
|
468
484
|
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
485
|
});
|
|
471
486
|
|
|
472
487
|
// ---------------------------------------------------------------------------
|
|
@@ -27,31 +27,50 @@ const TYPE_STUB = [
|
|
|
27
27
|
|
|
28
28
|
// The stubbed source is read once per process; a test that asserts on the
|
|
29
29
|
// source itself can read SRC directly.
|
|
30
|
+
//
|
|
31
|
+
// S2/S3 (native-bridge T5): the entry statically imports the shell API from
|
|
32
|
+
// `../lib/shell-api/extension.ts` — odd-worktree's own code, which publishes the API slot at
|
|
33
|
+
// module load and arms the shell surfaces. A plain-JS suite may import neither a `.ts` file nor
|
|
34
|
+
// its TypeScript graph, so that import is stubbed here exactly like the two Pi package imports:
|
|
35
|
+
// the scratch `.mjs` gets a no-op factory and the slot is whatever the fixture publishes (see
|
|
36
|
+
// `installDefaultBridge`).
|
|
37
|
+
const BRIDGE_IMPORT = 'import bridgeExtension from "../lib/shell-api/extension.ts";';
|
|
38
|
+
const BRIDGE_STUB = 'const bridgeExtension = () => {};';
|
|
39
|
+
|
|
40
|
+
function stubOnce(source, needle, replacement) {
|
|
41
|
+
if (source.includes(needle) === false) return null;
|
|
42
|
+
return source.split(needle).join(replacement);
|
|
43
|
+
}
|
|
44
|
+
|
|
30
45
|
let cached = null;
|
|
31
46
|
function stubbedSource() {
|
|
32
47
|
if (cached !== null) return cached;
|
|
33
48
|
const srcText = fs.readFileSync(SRC, 'utf8');
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
const stubbedType = stubOnce(srcText, 'import { Type } from "@earendil-works/pi-ai";', TYPE_STUB);
|
|
50
|
+
const stubbedTool = stubOnce(stubbedType === null ? srcText : stubbedType,
|
|
51
|
+
'import { defineTool } from "@earendil-works/pi-coding-agent";',
|
|
52
|
+
'const defineTool = (def) => def;');
|
|
53
|
+
const stubbed = stubOnce(stubbedTool === null ? srcText : stubbedTool, BRIDGE_IMPORT, BRIDGE_STUB);
|
|
54
|
+
if (stubbedType === null || stubbedTool === null || stubbed === null || stubbed === srcText) {
|
|
55
|
+
throw new Error('expected all imports stubbed: the two Pi package imports and the vendored bridge import');
|
|
56
|
+
}
|
|
38
57
|
cached = stubbed;
|
|
39
58
|
return cached;
|
|
40
59
|
}
|
|
41
60
|
|
|
42
|
-
// S18 (issues-startup-performance T14):
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
// contributes actually use — the rail's
|
|
48
|
-
// `
|
|
49
|
-
// palette row, and the store. Nothing here weakens
|
|
50
|
-
// the object is a real enough bridge, not a thin one.
|
|
61
|
+
// S18 (issues-startup-performance T14) as amended by native-bridge T2/T5: the shell API is
|
|
62
|
+
// NATIVE (`lib/shell-api/`, stubbed out of this plain-JS copy), so a host double
|
|
63
|
+
// that publishes nothing on the slot gets an extension that registers NOTHING — every suite
|
|
64
|
+
// here would then be asserting nothing. The fake host therefore HAS the bridge:
|
|
65
|
+
// `defaultBridge()` is the published object with the schema and version the code validates
|
|
66
|
+
// and the members the surfaces this package contributes actually use — the rail's
|
|
67
|
+
// `registerSection`, the `Cards` rows' `registerRows`, the design's `registerToolDesign`, the
|
|
68
|
+
// picker's keymap action and palette row, and the store. Nothing here weakens
|
|
69
|
+
// `issuesSidebarBridge()`'s slot check: the object is a real enough bridge, not a thin one.
|
|
51
70
|
//
|
|
52
71
|
// `loadExtension(pi, { bridge: false })` is the opt-out for a suite that must
|
|
53
|
-
// prove the absent case: it publishes nothing and touches no slot, so the
|
|
54
|
-
// itself decides what is on it.
|
|
72
|
+
// prove the absent-or-incompatible case: it publishes nothing and touches no slot, so the
|
|
73
|
+
// test itself decides what is on it.
|
|
55
74
|
function defaultBridge() {
|
|
56
75
|
const sections = [];
|
|
57
76
|
const rows = [];
|
|
@@ -145,9 +164,10 @@ async function withGhPath(mode, run) {
|
|
|
145
164
|
// Load the extension with the injected `pi` double. Returns the registered
|
|
146
165
|
// commands and tools keyed by name, exactly as the host received them.
|
|
147
166
|
//
|
|
148
|
-
// S18 (T14): the
|
|
149
|
-
//
|
|
150
|
-
//
|
|
167
|
+
// S18 (T14): the slot is checked ONCE, in the factory, and the vendored bridge's own factory
|
|
168
|
+
// is stubbed here (no `.ts` may be imported by a plain-JS suite), so the fixture publishes the
|
|
169
|
+
// bridge BEFORE the factory runs. With no bridge the extension registers nothing at all, so a
|
|
170
|
+
// suite that wants that passes `{ bridge: false }`.
|
|
151
171
|
//
|
|
152
172
|
// S13 (T11): `gh` is present on PATH unless the suite passes `{ gh: false }`, for the
|
|
153
173
|
// same reason — the issues surfaces do not exist without it.
|
|
@@ -190,6 +210,8 @@ module.exports = {
|
|
|
190
210
|
LIB_DIR,
|
|
191
211
|
SRC,
|
|
192
212
|
BRIDGE_SLOT,
|
|
213
|
+
BRIDGE_IMPORT,
|
|
214
|
+
BRIDGE_STUB,
|
|
193
215
|
loadExtension,
|
|
194
216
|
stubbedSource,
|
|
195
217
|
defaultBridge,
|
|
@@ -171,14 +171,11 @@ async function fireSessionStart(hooks, ctx) {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
// This file is about the `gh` gate and the panel.
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
// earlier one had already consumed the hint. The fixtures leave it out, so every count below means
|
|
178
|
-
// the same thing alone or in the full run.
|
|
179
|
-
const BRIDGE_HINT = /gentle-shell-bridge/;
|
|
174
|
+
// This file is about the `gh` gate and the panel. T2 (native-bridge) removed the missing-bridge
|
|
175
|
+
// hint entirely — there is no install line and no per-process warn slot — so every count below is
|
|
176
|
+
// the whole list the host received, and it means the same thing alone or in the full run.
|
|
180
177
|
const recordNote = (notes) => (message, level) => {
|
|
181
|
-
|
|
178
|
+
notes.push([message, level]);
|
|
182
179
|
};
|
|
183
180
|
|
|
184
181
|
function gateCtx(cwd, notes) {
|