pi-odd-worktree 3.15.0 → 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.
Files changed (127) hide show
  1. package/README.md +48 -25
  2. package/extensions/odd-worktree-tools.ts +64 -211
  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/lib/user-prompt-card.js +48 -2
  43. package/package.json +3 -2
  44. package/tools/files-bridge.test.js +81 -66
  45. package/tools/fixtures/load-extension.js +40 -18
  46. package/tools/issues-command.test.js +4 -7
  47. package/tools/issues-section.test.js +71 -81
  48. package/tools/odd-rail-wiring.test.js +16 -10
  49. package/tools/package-surface.test.js +42 -13
  50. package/tools/prs-command.test.js +11 -6
  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 +80 -10
@@ -0,0 +1,308 @@
1
+ /**
2
+ * S22/T43 — a design can read the ACTIVE card style.
3
+ *
4
+ * `bash` is drawn by gentle-shell's own host renderers, so `float`/`neon` reaches it there
5
+ * (`lib/card-style-policy.ts` → `cardStyle()`). A tool registered by another extension —
6
+ * `bash_background`, `monitor`, `job_stop`, `job_list` — has no host card at all, so it never follows
7
+ * the style: the only way to decorate it from here is a tool DESIGN, and a design that wants to
8
+ * honour the user's selection has to be able to SEE it.
9
+ *
10
+ * `ctx` therefore carries the resolved selection, under the same three answers the bridge itself
11
+ * degrades from: `native` (nobody chose a style), `style` (the live registration), `missing` (a style
12
+ * that was disposed while it was selected — a `/reload`, an unloaded plugin). The field is additive
13
+ * and resolved ON ACCESS, at most once per pass: a design that never reads it draws exactly the rows
14
+ * it drew before the field existed, and pays nothing for it.
15
+ */
16
+
17
+ import assert from "node:assert/strict";
18
+ import { mkdtempSync, rmSync } from "node:fs";
19
+ import { tmpdir } from "node:os";
20
+ import { join } from "node:path";
21
+ import test from "node:test";
22
+
23
+ import { registerCardStyle, resetBusForTests, resetCardStylesForTests } from "../../lib/shell-api/bus.ts";
24
+ import { setCardStyleSelection } from "../../lib/shell-api/card-styles.ts";
25
+ import { disableCaptureBackend, resetCaptureStateForTests } from "../../lib/shell-api/capture.ts";
26
+ import { resetCardStyleTransformForTests } from "../../lib/shell-api/card-style-transform.ts";
27
+ import {
28
+ disableCardStyleTransform,
29
+ resetCardStyleWiringForTests,
30
+ } from "../../lib/shell-api/card-style-wiring.ts";
31
+ import { resetHookStateForTests } from "../../lib/shell-api/hook.ts";
32
+ import { resolveCardStyleSelection, type CardStyleSelection } from "../../lib/shell-api/index.ts";
33
+ import { resetNoticesForTests } from "../../lib/shell-api/notices.ts";
34
+ import { resetPluginLinesForTests } from "../../lib/shell-api/plugin-lines.ts";
35
+ import { resetRepaintForTests } from "../../lib/shell-api/repaint.ts";
36
+ import { isRecord, resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
37
+ import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
38
+ import {
39
+ adoptToolCards,
40
+ resetToolDesignAdoptionForTests,
41
+ } from "../../lib/shell-api/tool-design-adoption.ts";
42
+ import {
43
+ registerToolDesign,
44
+ resetToolDesignsForTests,
45
+ setToolDesignSelection,
46
+ } from "../../lib/shell-api/tool-designs.ts";
47
+ import { resetToolDesignWiringForTests } from "../../lib/shell-api/tool-design-wiring.ts";
48
+ import type { CardStyleRegistration, ToolDesignContext } from "../../lib/shell-api/types.ts";
49
+
50
+ let configHome: string;
51
+ let previousConfigHome: string | undefined;
52
+
53
+ test.before(() => {
54
+ configHome = mkdtempSync(join(tmpdir(), "gsb-tool-design-card-style-"));
55
+ previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
56
+ process.env.GENTLE_PI_CONFIG_HOME = configHome;
57
+ });
58
+
59
+ test.after(() => {
60
+ if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
61
+ else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
62
+ rmSync(configHome, { recursive: true, force: true });
63
+ });
64
+
65
+ test.beforeEach(() => {
66
+ // The selection is a real file: every test starts from nothing on disk.
67
+ rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
68
+ resetBusForTests();
69
+ resetCardStylesForTests();
70
+ resetToolDesignsForTests();
71
+ resetToolDesignWiringForTests();
72
+ resetToolDesignAdoptionForTests();
73
+ resetRepaintForTests();
74
+ resetStoreStateForTests();
75
+ resetNoticesForTests();
76
+ resetPluginLinesForTests();
77
+ resetRowBuildStateForTests();
78
+ resetCaptureStateForTests();
79
+ resetHookStateForTests();
80
+ resetCardStyleTransformForTests();
81
+ resetCardStyleWiringForTests();
82
+ disableCardStyleTransform();
83
+ disableCaptureBackend();
84
+ });
85
+
86
+ test.afterEach(disableCaptureBackend);
87
+
88
+ const THEME = { name: "fake-theme" };
89
+
90
+ /** The four rows the host's quiet bash card draws, ANSI and padding included. */
91
+ const BASH_CARD = [
92
+ "╭─ ✿ bash card ───────────── ctrl+o ╮",
93
+ "│ \u001b[36m$ ls -la\u001b[0m ",
94
+ "│ total 4 ",
95
+ "╰───────────────────────────────────╯",
96
+ ];
97
+
98
+ const DESIGN_ID = "loon.card-style-probe";
99
+
100
+ const frame = () => ({
101
+ top: (ctx: { width: number }) => "─".repeat(ctx.width),
102
+ line: (ctx: { text: string }) => ctx.text,
103
+ bottom: (ctx: { width: number }) => "─".repeat(ctx.width),
104
+ });
105
+
106
+ const style = (id: string): CardStyleRegistration => ({ id, label: id, frame: frame() });
107
+
108
+ /** The renderers the host builds for bash: a toolDefinition-shaped object, one component each. */
109
+ function bashRenderers(): { renderShell: string; renderCall: unknown; renderResult: unknown } {
110
+ return {
111
+ renderShell: "default",
112
+ renderCall: () => ({ render: (_width: number) => [...BASH_CARD] }),
113
+ renderResult: () => ({ render: (_width: number) => ["╭─ ✿ bash ─╮", "│ done", "╰──────────╯"] }),
114
+ };
115
+ }
116
+
117
+ interface FakeCard {
118
+ toolName?: unknown;
119
+ toolDefinition?: unknown;
120
+ component?: { render(width: number): string[] };
121
+ updateDisplay(): void;
122
+ invalidate(): void;
123
+ render(width: number): string[];
124
+ }
125
+
126
+ /** A `ToolExecutionComponent`-shaped card: `render()` draws what `renderCall` last built. */
127
+ function mountCard(toolDefinition: unknown): FakeCard {
128
+ const card: FakeCard = {
129
+ toolName: "bash",
130
+ toolDefinition,
131
+ updateDisplay(): void {
132
+ const renderCall = isRecord(card.toolDefinition) ? card.toolDefinition.renderCall : undefined;
133
+ // SAFETY: the host's `renderCall` is `(args, theme, ctx) => Component`; the test needs the
134
+ // component it answers.
135
+ card.component =
136
+ typeof renderCall === "function"
137
+ ? (renderCall as (...args: unknown[]) => { render(width: number): string[] })(
138
+ { command: "ls -la" },
139
+ THEME,
140
+ { args: {} },
141
+ )
142
+ : undefined;
143
+ },
144
+ invalidate(): void {
145
+ card.updateDisplay();
146
+ },
147
+ render(width: number): string[] {
148
+ return card.component === undefined ? [] : card.component.render(width);
149
+ },
150
+ };
151
+ card.updateDisplay();
152
+ return card;
153
+ }
154
+
155
+ /** Register a design that records the `cardStyle` of every pass, and select it for `bash`. */
156
+ const adoptWithProbe = (): { card: FakeCard; seen: Array<CardStyleSelection | undefined> } => {
157
+ const seen: Array<CardStyleSelection | undefined> = [];
158
+ registerToolDesign({
159
+ tool: "bash",
160
+ id: DESIGN_ID,
161
+ label: "card style probe",
162
+ apply(lines: readonly string[], ctx: ToolDesignContext): string[] {
163
+ seen.push(ctx.cardStyle);
164
+ return [...lines];
165
+ },
166
+ });
167
+ setToolDesignSelection("bash", DESIGN_ID);
168
+ const card = mountCard(bashRenderers());
169
+ assert.equal(adoptToolCards({ children: [card] }).adopted, 1, "the host's card is wrapped");
170
+ return { card, seen };
171
+ };
172
+
173
+ // ---------------------------------------------------------------------------------------------
174
+ // The three answers
175
+ // ---------------------------------------------------------------------------------------------
176
+
177
+ test("S22/T43: the design context carries the ACTIVE card style", () => {
178
+ registerCardStyle(style("loon.neon-ish"));
179
+ setCardStyleSelection("loon.neon-ish");
180
+ const { card, seen } = adoptWithProbe();
181
+
182
+ card.render(80);
183
+
184
+ assert.equal(seen.length, 1, "the design ran once, on one pass");
185
+ const answer = seen[0];
186
+ assert.ok(answer !== undefined, "the context carries `cardStyle` at all");
187
+ assert.equal(answer.kind, "style");
188
+ if (answer.kind !== "style") return;
189
+ assert.equal(answer.style.id, "loon.neon-ish", "the style the user selected");
190
+ });
191
+
192
+ test("S22/T43: with nothing selected the answer is `native`", () => {
193
+ const { card, seen } = adoptWithProbe();
194
+
195
+ card.render(80);
196
+
197
+ assert.deepEqual(seen[0], { kind: "native" }, "no style chosen is a first-class answer");
198
+ });
199
+
200
+ test("S22/T43: a style disposed while it was selected answers `missing`", () => {
201
+ const dispose = registerCardStyle(style("loon.doomed"));
202
+ setCardStyleSelection("loon.doomed");
203
+ dispose();
204
+ const { card, seen } = adoptWithProbe();
205
+
206
+ card.render(80);
207
+
208
+ assert.deepEqual(
209
+ seen[0],
210
+ { kind: "missing", id: "loon.doomed" },
211
+ "the bridge degrades to native and SAYS which id went missing, instead of throwing",
212
+ );
213
+ });
214
+
215
+ // ---------------------------------------------------------------------------------------------
216
+ // Additive: the rows cannot change for a design that ignores the field
217
+ // ---------------------------------------------------------------------------------------------
218
+
219
+ test("S22/T43: a design that never reads `cardStyle` draws the same bytes with a style selected", () => {
220
+ registerCardStyle(style("loon.neon-ish"));
221
+ setCardStyleSelection("loon.neon-ish");
222
+ registerToolDesign({
223
+ tool: "bash",
224
+ id: "loon.bash-heading",
225
+ label: "bash heading",
226
+ // The design of §14, unchanged: it rewrites the heading mark and nothing else.
227
+ apply: (lines: readonly string[]): string[] =>
228
+ lines.map((line) => (line.includes("$ ") ? line.replace("$ ", "bash ") : line)),
229
+ });
230
+ setToolDesignSelection("bash", "loon.bash-heading");
231
+
232
+ const card = mountCard(bashRenderers());
233
+ adoptToolCards({ children: [card] });
234
+
235
+ assert.deepEqual(
236
+ card.render(80),
237
+ [
238
+ BASH_CARD[0],
239
+ BASH_CARD[1].replace("$ ", "bash "),
240
+ BASH_CARD[2],
241
+ BASH_CARD[3],
242
+ ],
243
+ "byte for byte what the design drew before the field existed",
244
+ );
245
+ });
246
+
247
+ // ---------------------------------------------------------------------------------------------
248
+ // Live, and ONE answer per pass
249
+ // ---------------------------------------------------------------------------------------------
250
+
251
+ test("S22/T43: the style is read on every pass, so a switch reaches a card already on screen", () => {
252
+ registerCardStyle(style("loon.first"));
253
+ registerCardStyle(style("loon.second"));
254
+ setCardStyleSelection("loon.first");
255
+ const { card, seen } = adoptWithProbe();
256
+
257
+ card.render(80);
258
+ setCardStyleSelection("loon.second");
259
+ card.render(80);
260
+
261
+ const ids = seen.map((answer) => (answer?.kind === "style" ? answer.style.id : answer?.kind));
262
+ assert.deepEqual(ids, ["loon.first", "loon.second"], "no capture at resolution: the pass reads live");
263
+ });
264
+
265
+ test("S22/T43: one pass answers ONE style, even if the selection changes mid-pass", () => {
266
+ registerCardStyle(style("loon.first"));
267
+ registerCardStyle(style("loon.second"));
268
+ setCardStyleSelection("loon.first");
269
+ const answers: Array<CardStyleSelection | undefined> = [];
270
+ registerToolDesign({
271
+ tool: "bash",
272
+ id: DESIGN_ID,
273
+ label: "card style probe",
274
+ apply(lines: readonly string[], ctx: ToolDesignContext): string[] {
275
+ const first = ctx.cardStyle;
276
+ // A switch landing BETWEEN two reads of the same pass (a row action, a keypress) must not
277
+ // produce a card that is half of each: the bridge resolves the pass's answer once.
278
+ setCardStyleSelection("loon.second");
279
+ answers.push(first, ctx.cardStyle);
280
+ return [...lines];
281
+ },
282
+ });
283
+ setToolDesignSelection("bash", DESIGN_ID);
284
+ const card = mountCard(bashRenderers());
285
+ adoptToolCards({ children: [card] });
286
+
287
+ card.render(80);
288
+
289
+ const ids = answers.map((answer) => (answer?.kind === "style" ? answer.style.id : answer?.kind));
290
+ assert.deepEqual(ids, ["loon.first", "loon.first"], "both reads answered from one resolution");
291
+ });
292
+
293
+ // ---------------------------------------------------------------------------------------------
294
+ // The public surface
295
+ // ---------------------------------------------------------------------------------------------
296
+
297
+ test("S22/T43: a plugin reads the same answer outside the context, from the package entry", () => {
298
+ registerCardStyle(style("loon.neon-ish"));
299
+ setCardStyleSelection("loon.neon-ish");
300
+
301
+ const answer = resolveCardStyleSelection();
302
+
303
+ assert.equal(typeof resolveCardStyleSelection, "function", "the entry exports the resolver");
304
+ assert.equal(answer.kind, "style");
305
+ if (answer.kind !== "style") return;
306
+ assert.equal(answer.style.id, "loon.neon-ish");
307
+ assert.deepEqual(answer, resolveCardStyleSelection(), "and it is the same answer, read twice");
308
+ });