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,339 @@
1
+ /**
2
+ * S1/S4 — the message-design registry and its selection, with no host in sight.
3
+ *
4
+ * A message design paints a Pi CUSTOM MESSAGE (`pi.registerMessageRenderer`'s `customType`), the way a
5
+ * tool design paints a tool's card. This file pins the half that is pure registry — what a registration
6
+ * accepts and refuses, what a selection resolves to, and that a resolve is ONE store read — so the
7
+ * wiring that touches Pi's own renderer API can be tested separately against a fake host.
8
+ */
9
+
10
+ import assert from "node:assert/strict";
11
+ import { mkdtempSync, rmSync } from "node:fs";
12
+ import { tmpdir } from "node:os";
13
+ import { join } from "node:path";
14
+ import test from "node:test";
15
+
16
+ import {
17
+ MESSAGE_DESIGN_DEFAULT_LABEL,
18
+ MESSAGE_DESIGN_LINE_STORE_KEY,
19
+ MESSAGE_DESIGN_NATIVE,
20
+ MESSAGE_DESIGN_STORE_ID,
21
+ MESSAGE_DESIGN_STORE_KEY,
22
+ getMessageDesignConflicts,
23
+ getMessageDesignFailures,
24
+ getMessageDesignLineSelection,
25
+ getMessageDesignSelection,
26
+ getMessageDesignSelectionReads,
27
+ messageDesignLines,
28
+ registerMessageDesign,
29
+ resetMessageDesignSelectionReads,
30
+ resetMessageDesignsForTests,
31
+ resolveMessageDesignSelection,
32
+ setMessageDesignLineSelection,
33
+ setMessageDesignSelection,
34
+ } from "../../lib/shell-api/message-designs.ts";
35
+ import { resetNoticesForTests } from "../../lib/shell-api/notices.ts";
36
+ import { resetPluginLinesForTests } from "../../lib/shell-api/plugin-lines.ts";
37
+ import { resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
38
+ import { createStore, resetStoreStateForTests } from "../../lib/shell-api/store.ts";
39
+ import type { MessageDesignContext, MessageDesignRegistration } from "../../lib/shell-api/types.ts";
40
+
41
+ let configHome: string;
42
+ let previousConfigHome: string | undefined;
43
+
44
+ test.before(() => {
45
+ configHome = mkdtempSync(join(tmpdir(), "gsb-message-designs-"));
46
+ previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
47
+ process.env.GENTLE_PI_CONFIG_HOME = configHome;
48
+ });
49
+
50
+ test.after(() => {
51
+ if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
52
+ else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
53
+ rmSync(configHome, { recursive: true, force: true });
54
+ });
55
+
56
+ const resetAll = (): void => {
57
+ resetMessageDesignsForTests();
58
+ resetStoreStateForTests();
59
+ resetNoticesForTests();
60
+ resetPluginLinesForTests();
61
+ resetRowBuildStateForTests();
62
+ // The selections are a real file: every test starts from nothing on disk.
63
+ rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
64
+ };
65
+
66
+ test.beforeEach(resetAll);
67
+
68
+ const BUDGET_TYPE = "gentle-pi.exploration-budget";
69
+ const REMINDER_TYPE = "gentle-pi.verifier-settle-reminder";
70
+
71
+ const design = (extra: Partial<MessageDesignRegistration> = {}): MessageDesignRegistration => ({
72
+ customType: BUDGET_TYPE,
73
+ id: "loon.budget",
74
+ label: "budget",
75
+ apply: (lines: readonly string[]) => [...lines],
76
+ ...extra,
77
+ });
78
+
79
+ /** The stored document, read back the way the bridge itself writes it. */
80
+ const storedDocument = (): Record<string, unknown> =>
81
+ createStore(MESSAGE_DESIGN_STORE_ID).get<Record<string, unknown>>(MESSAGE_DESIGN_STORE_KEY, {});
82
+
83
+ // ---------------------------------------------------------------------------------------------
84
+ // What a registration accepts and refuses
85
+ // ---------------------------------------------------------------------------------------------
86
+
87
+ test("S1: an ungrouped design names ONE customType and appears on the type's own line", () => {
88
+ registerMessageDesign(design());
89
+
90
+ assert.deepEqual(
91
+ messageDesignLines().map((line) => ({ scope: line.scope, line: line.line, types: line.types })),
92
+ [{ scope: "type", line: BUDGET_TYPE, types: [BUDGET_TYPE] }],
93
+ "one implicit line, named after the type",
94
+ );
95
+ });
96
+
97
+ test("S1: a grouped design names a line and its types, and several join ONE line", () => {
98
+ registerMessageDesign({
99
+ line: "reminders",
100
+ types: [BUDGET_TYPE, REMINDER_TYPE],
101
+ id: "loon.reminders",
102
+ label: "reminders",
103
+ apply: (lines: readonly string[]) => [...lines],
104
+ });
105
+ registerMessageDesign({
106
+ line: "reminders",
107
+ types: [REMINDER_TYPE],
108
+ id: "loon.reminders-loud",
109
+ label: "loud",
110
+ apply: (lines: readonly string[]) => [...lines],
111
+ });
112
+
113
+ const lines = messageDesignLines();
114
+ assert.equal(lines.length, 1, "one line, not one per registration");
115
+ assert.equal(lines[0].scope, "line");
116
+ assert.equal(lines[0].line, "reminders");
117
+ assert.deepEqual([...lines[0].types].sort(), [BUDGET_TYPE, REMINDER_TYPE]);
118
+ assert.deepEqual(
119
+ lines[0].designs.map((entry: MessageDesignRegistration) => entry.id),
120
+ ["loon.reminders", "loon.reminders-loud"],
121
+ "values in registration order",
122
+ );
123
+ });
124
+
125
+ test("S1: mixing the two shapes, or naming neither, is refused before anything is stored", () => {
126
+ assert.throws(
127
+ () => registerMessageDesign(design({ line: "reminders", types: [REMINDER_TYPE] })),
128
+ /invalid message design/u,
129
+ "customType with line+types",
130
+ );
131
+ assert.throws(
132
+ () => registerMessageDesign({ id: "loon.empty", label: "empty", apply: (lines) => [...lines] }),
133
+ /invalid message design/u,
134
+ "neither shape",
135
+ );
136
+ assert.throws(
137
+ () =>
138
+ registerMessageDesign({
139
+ line: "reminders",
140
+ types: [],
141
+ id: "loon.empty",
142
+ label: "empty",
143
+ apply: (lines: readonly string[]) => [...lines],
144
+ }),
145
+ /invalid message design/u,
146
+ "an empty types list claims nothing",
147
+ );
148
+ assert.deepEqual(messageDesignLines(), [], "and a refusal stores nothing");
149
+ });
150
+
151
+ test("S1: an id, a label and an apply are validated the way every other surface validates them", () => {
152
+ assert.throws(() => registerMessageDesign(design({ id: "" })), /invalid message design id/u);
153
+ assert.throws(() => registerMessageDesign(design({ label: "" })), /invalid message design/u);
154
+ assert.throws(
155
+ () => registerMessageDesign(design({ label: MESSAGE_DESIGN_DEFAULT_LABEL })),
156
+ /reserved/u,
157
+ "`default` is the bridge's own value",
158
+ );
159
+ assert.throws(
160
+ () => registerMessageDesign(design({ label: MESSAGE_DESIGN_NATIVE })),
161
+ /reserved/u,
162
+ "and so is `native`",
163
+ );
164
+ assert.throws(
165
+ () =>
166
+ registerMessageDesign({
167
+ customType: BUDGET_TYPE,
168
+ id: "loon.no-apply",
169
+ label: "no apply",
170
+ } as unknown as MessageDesignRegistration),
171
+ /apply/u,
172
+ "a design with nothing to run is a plugin bug",
173
+ );
174
+ });
175
+
176
+ test("S1: the same id on one line replaces in place and is reported, keeping its position", () => {
177
+ registerMessageDesign(design({ label: "first" }));
178
+ registerMessageDesign(design({ label: "second" }));
179
+
180
+ const lines = messageDesignLines();
181
+ assert.equal(lines[0].designs.length, 1, "one value, not two");
182
+ assert.equal(lines[0].designs[0].label, "second");
183
+ assert.equal(getMessageDesignConflicts().length, 1, "the replacement is reported");
184
+ assert.equal(getMessageDesignConflicts()[0].kind, "replaced");
185
+ });
186
+
187
+ test("S1: an array registration is all-or-nothing", () => {
188
+ assert.throws(
189
+ () =>
190
+ registerMessageDesign([
191
+ design({ id: "loon.kept" }),
192
+ design({ id: "" }),
193
+ ]),
194
+ /invalid message design id/u,
195
+ );
196
+
197
+ assert.deepEqual(messageDesignLines(), [], "the accepted entry of the batch is withdrawn too");
198
+ });
199
+
200
+ test("S1: a disposer withdraws its own value and nothing else", () => {
201
+ const dispose = registerMessageDesign(design({ id: "loon.gone" }));
202
+ registerMessageDesign(design({ id: "loon.kept", label: "kept" }));
203
+
204
+ dispose();
205
+
206
+ assert.deepEqual(
207
+ messageDesignLines()[0].designs.map((entry: MessageDesignRegistration) => entry.id),
208
+ ["loon.kept"],
209
+ );
210
+ dispose();
211
+ assert.equal(messageDesignLines()[0].designs.length, 1, "disposal is idempotent");
212
+ });
213
+
214
+ // ---------------------------------------------------------------------------------------------
215
+ // Selection and resolution
216
+ // ---------------------------------------------------------------------------------------------
217
+
218
+ test("S4: no selection answers `native`, and a stored design answers `design`", () => {
219
+ registerMessageDesign(design());
220
+
221
+ assert.deepEqual(
222
+ resolveMessageDesignSelection(BUDGET_TYPE),
223
+ { kind: "native" },
224
+ "nothing chosen: the host's own output, untouched",
225
+ );
226
+
227
+ setMessageDesignSelection(BUDGET_TYPE, "loon.budget");
228
+ const selection = resolveMessageDesignSelection(BUDGET_TYPE);
229
+ assert.equal(selection.kind, "design");
230
+ if (selection.kind !== "design") return;
231
+ assert.equal(selection.design.id, "loon.budget");
232
+ });
233
+
234
+ test("S4: a selection whose design was disposed answers `missing`, never `native`", () => {
235
+ const dispose = registerMessageDesign(design());
236
+ setMessageDesignSelection(BUDGET_TYPE, "loon.budget");
237
+ dispose();
238
+
239
+ assert.deepEqual(resolveMessageDesignSelection(BUDGET_TYPE), {
240
+ kind: "missing",
241
+ id: "loon.budget",
242
+ });
243
+ });
244
+
245
+ test("S1: a grouped line's value covers only the types its own design lists", () => {
246
+ registerMessageDesign({
247
+ line: "reminders",
248
+ types: [BUDGET_TYPE],
249
+ id: "loon.budget-only",
250
+ label: "budget only",
251
+ apply: (lines: readonly string[]) => [...lines],
252
+ });
253
+ // A second VALUE of the SAME line, covering both types: the line claims both, the selected value
254
+ // does not, and that difference is exactly what `not-covered` reports (S1).
255
+ registerMessageDesign({
256
+ line: "reminders",
257
+ types: [BUDGET_TYPE, REMINDER_TYPE],
258
+ id: "loon.both",
259
+ label: "both",
260
+ apply: (lines: readonly string[]) => [...lines],
261
+ });
262
+ setMessageDesignLineSelection("line", "reminders", "loon.budget-only");
263
+
264
+ const covered = resolveMessageDesignSelection(BUDGET_TYPE);
265
+ assert.equal(covered.kind, "design", "the type the selected value lists is covered");
266
+
267
+ assert.deepEqual(
268
+ resolveMessageDesignSelection(REMINDER_TYPE),
269
+ { kind: "not-covered", id: "loon.budget-only" },
270
+ "a type the selected value does not list is not painted by it",
271
+ );
272
+ });
273
+
274
+ test("S1: the selection persists in the bridge's own file, and an unused line map is never written", () => {
275
+ setMessageDesignSelection(BUDGET_TYPE, "loon.budget");
276
+ assert.deepEqual(storedDocument(), { [BUDGET_TYPE]: "loon.budget" });
277
+
278
+ setMessageDesignLineSelection("line", "reminders", "loon.loud");
279
+ assert.deepEqual(storedDocument(), {
280
+ [BUDGET_TYPE]: "loon.budget",
281
+ [MESSAGE_DESIGN_LINE_STORE_KEY]: { reminders: "loon.loud" },
282
+ });
283
+ assert.equal(getMessageDesignLineSelection("type", BUDGET_TYPE), "loon.budget");
284
+ assert.equal(getMessageDesignLineSelection("line", "reminders"), "loon.loud");
285
+ assert.equal(
286
+ getMessageDesignLineSelection("line", "never-set"),
287
+ MESSAGE_DESIGN_NATIVE,
288
+ "an unset line reads as the host's own output",
289
+ );
290
+ });
291
+
292
+ test("S4: one resolve is ONE store read, and it never throws", () => {
293
+ registerMessageDesign(design());
294
+ setMessageDesignSelection(BUDGET_TYPE, "loon.budget");
295
+
296
+ resetMessageDesignSelectionReads();
297
+ resolveMessageDesignSelection(BUDGET_TYPE);
298
+ assert.equal(getMessageDesignSelectionReads(), 1, "one logical read, not one per candidate");
299
+
300
+ // A stored value that is not a string is a hand edit, never a crash.
301
+ createStore(MESSAGE_DESIGN_STORE_ID).set(MESSAGE_DESIGN_STORE_KEY, { [BUDGET_TYPE]: 42 });
302
+ assert.deepEqual(resolveMessageDesignSelection(BUDGET_TYPE), { kind: "native" });
303
+ assert.deepEqual(resolveMessageDesignSelection("never-seen"), { kind: "native" });
304
+ });
305
+
306
+ test("S4: a throwing design is isolated and reported, and the resolve still answers", () => {
307
+ registerMessageDesign(
308
+ design({
309
+ apply: () => {
310
+ throw new Error("kaboom");
311
+ },
312
+ }),
313
+ );
314
+ setMessageDesignSelection(BUDGET_TYPE, "loon.budget");
315
+
316
+ const selection = resolveMessageDesignSelection(BUDGET_TYPE);
317
+ assert.equal(selection.kind, "design", "resolving never runs the design");
318
+
319
+ // Nothing above should have recorded a failure: `apply` runs per pass, in the wiring, not here.
320
+ assert.deepEqual(getMessageDesignFailures(), []);
321
+ });
322
+
323
+ // ---------------------------------------------------------------------------------------------
324
+ // The types are the contract a design is written against
325
+ // ---------------------------------------------------------------------------------------------
326
+
327
+ test("S1: MessageDesignContext is the shape a design receives, and message is the host's own object", () => {
328
+ const message = { customType: BUDGET_TYPE, content: [] };
329
+ const ctx: MessageDesignContext = {
330
+ width: 72,
331
+ customType: BUDGET_TYPE,
332
+ theme: { name: "fake" },
333
+ cardStyle: { kind: "native" },
334
+ render: { expanded: false, outputPad: 0, message },
335
+ };
336
+
337
+ assert.equal(ctx.render.message, message, "forwarded by reference, never cloned");
338
+ assert.equal(ctx.width, 72);
339
+ });