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
@@ -0,0 +1,293 @@
1
+ /**
2
+ * The automatic `Sections` toggle rows (S5, S6), against the fake host and the fake sidebar.
3
+ *
4
+ * A plugin never writes a `setting`, a `value`, a `current()`, an `action()` or a `preview()`: the
5
+ * bridge derives all of it from the section registration. These tests pin that surface, the
6
+ * persistence file, and the one property that makes the toggle useful — hiding takes effect on the
7
+ * sidebar's NEXT FRAME, not only on the next menu open.
8
+ */
9
+
10
+ import assert from "node:assert/strict";
11
+ import { mkdtempSync, readFileSync, 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 { armBridge } from "../../lib/shell-api/arm.ts";
17
+ import { registerSection, resetBusForTests, resetSectionsForTests, snapshotProviders } from "../../lib/shell-api/bus.ts";
18
+ import { disableCaptureBackend, resetCaptureStateForTests } from "../../lib/shell-api/capture.ts";
19
+ import { resetHookStateForTests } from "../../lib/shell-api/hook.ts";
20
+ import { resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
21
+ import {
22
+ SECTION_ROWS_PROVIDER_ID,
23
+ installSectionRows,
24
+ } from "../../lib/shell-api/sections-rows.ts";
25
+ import {
26
+ disableSidebarBackend,
27
+ installSidebarBackend,
28
+ resetSidebarStateForTests,
29
+ } from "../../lib/shell-api/sidebar.ts";
30
+ import { installSectionRail, resetSectionFailuresForTests } from "../../lib/shell-api/sidebar-render.ts";
31
+ import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
32
+ import type { CustomizeRow, RowContext, SidebarSection } from "../../lib/shell-api/types.ts";
33
+ import { createFakeHost, type FakeHost } from "./fake-host.ts";
34
+ import { cardTitles, fakeTui, registerNativeFooter, resetSidebar } from "./fake-sidebar.ts";
35
+
36
+ const HOOK_KEY = Symbol.for("gentle-pi.customize-row-providers");
37
+ const hookSlot = (): Record<symbol, unknown> => globalThis as unknown as Record<symbol, unknown>;
38
+
39
+ let configHome: string;
40
+ let previousConfigHome: string | undefined;
41
+
42
+ test.before(() => {
43
+ configHome = mkdtempSync(join(tmpdir(), "gsb-rows-"));
44
+ previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
45
+ process.env.GENTLE_PI_CONFIG_HOME = configHome;
46
+ });
47
+
48
+ test.after(() => {
49
+ if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
50
+ else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
51
+ rmSync(configHome, { recursive: true, force: true });
52
+ });
53
+
54
+ test.beforeEach(() => {
55
+ // The visibility store is a real file: each test starts from nothing on disk.
56
+ rmSync(join(configHome, "gentle-shell-bridge"), { recursive: true, force: true });
57
+ resetBusForTests();
58
+ resetSectionsForTests();
59
+ resetSidebar();
60
+ resetSidebarStateForTests();
61
+ resetSectionFailuresForTests();
62
+ resetStoreStateForTests();
63
+ resetCaptureStateForTests();
64
+ resetHookStateForTests();
65
+ resetRowBuildStateForTests();
66
+ delete hookSlot()[HOOK_KEY];
67
+ });
68
+
69
+ test.afterEach(() => {
70
+ disableCaptureBackend();
71
+ disableSidebarBackend();
72
+ delete hookSlot()[HOOK_KEY];
73
+ });
74
+
75
+ const section = (id: string, extra: Partial<SidebarSection> = {}): SidebarSection => ({
76
+ id,
77
+ title: id.toUpperCase(),
78
+ lines: () => [`body ${id}`],
79
+ ...extra,
80
+ });
81
+
82
+ const ctx = (): RowContext => ({ theme: undefined, configHome });
83
+
84
+ /** The one internal provider, read straight from the bus so a build needs no menu. */
85
+ const rowsNow = (): CustomizeRow[] => {
86
+ const provider = snapshotProviders().find((entry) => entry.id === SECTION_ROWS_PROVIDER_ID);
87
+ assert.ok(provider !== undefined, "the bridge registers its own Sections provider");
88
+ return provider.rows(ctx());
89
+ };
90
+
91
+ const settingsOf = (rows: CustomizeRow[]): string[] =>
92
+ rows.map((row) => row.choice?.setting ?? "");
93
+
94
+ /** Native host + interception + renderer + the internal rows provider, then a menu host. */
95
+ function arm(): FakeHost {
96
+ registerNativeFooter();
97
+ installSidebarBackend(() => fakeTui());
98
+ installSectionRail();
99
+ installSectionRows();
100
+ const host = createFakeHost();
101
+ armBridge(host.ui);
102
+ return host;
103
+ }
104
+
105
+ const storePath = (): string => join(configHome, "gentle-shell-bridge", "bridge-sections.json");
106
+
107
+ test("a section becomes two consecutive Sections rows carrying its title as a label, and both values", () => {
108
+ registerSection(section("loon.music", { title: "MUSIC" }));
109
+ const host = arm();
110
+
111
+ host.buildMenu();
112
+
113
+ const injected = host.liveRows().filter((row) => row.category === "Sections");
114
+ assert.equal(injected.length, 2, "exactly one toggle: two values, two rows");
115
+ assert.equal(
116
+ injected[0].choice?.setting,
117
+ "music",
118
+ "the line's name is the row label, never the section id",
119
+ );
120
+ assert.equal(injected[0].choice?.setting, injected[1].choice?.setting, "one setting, two values");
121
+ assert.deepEqual(
122
+ injected.map((row) => row.choice?.value),
123
+ ["shown", "hidden"],
124
+ "consecutive rows, so the host draws one line",
125
+ );
126
+ assert.deepEqual(
127
+ injected.map((row) => (typeof row.label === "function" ? row.label() : row.label)),
128
+ ["music", "music"],
129
+ "the label is the title as a human reads it, in the row label and in the setting",
130
+ );
131
+
132
+ const lines = host.toggleLines();
133
+ assert.equal(lines.length, 1, "one rendered line per section");
134
+ assert.ok(lines[0].startsWith("music "), "the rendered line reads as a label");
135
+ assert.equal(lines[0].includes("Section:"), false, "no prefix is added to the label");
136
+ assert.equal(lines[0].includes("loon.music"), false, "and the id never appears in the row");
137
+ assert.ok(lines[0].includes("● shown"), "defaultVisible defaults to shown");
138
+ assert.ok(lines[0].includes("○ hidden"));
139
+ assert.ok(host.rendered().includes("music"), "the label is what the row reads as");
140
+ });
141
+
142
+ test("toggling persists to the bridge store first, then the host repaints", async () => {
143
+ registerSection(section("loon.music", { title: "MUSIC" }));
144
+ const host = arm();
145
+ host.buildMenu();
146
+ const invalidationsBefore = host.invalidateCount();
147
+
148
+ await host.pressRow(
149
+ (row) => row.choice?.setting === "music" && row.choice.value === "hidden",
150
+ );
151
+
152
+ assert.deepEqual(JSON.parse(readFileSync(storePath(), "utf8")), {
153
+ schemaVersion: 1,
154
+ values: { sections: { "loon.music": false } },
155
+ });
156
+ assert.equal(host.invalidateCount(), invalidationsBefore + 1, "the host repaints after the action");
157
+
158
+ assert.ok(host.toggleLines()[0].includes("○ shown"), "the bullet left shown");
159
+ assert.ok(host.toggleLines()[0].includes("● hidden"), "and landed on hidden");
160
+ });
161
+
162
+ test("both values draw the host's shared Sections preview, never a picture of the card", () => {
163
+ registerSection(section("loon.music", { title: "MUSIC" }));
164
+ // The provider is read directly, so no host rows array was ever captured: the base list is the
165
+ // host's own empty case and only the bridge's section can be listed.
166
+ arm();
167
+
168
+ const rows = rowsNow();
169
+ const shown = rows.find((row) => row.choice?.value === "shown");
170
+ const hidden = rows.find((row) => row.choice?.value === "hidden");
171
+ assert.ok(shown?.preview !== undefined && hidden?.preview !== undefined);
172
+
173
+ assert.deepEqual(shown.preview(), {
174
+ title: "Sections · music shown",
175
+ sample: "[music]",
176
+ });
177
+ assert.deepEqual(hidden.preview(), {
178
+ title: "Sections · music hidden",
179
+ sample: "[no optional sections]",
180
+ });
181
+ });
182
+
183
+ test("hiding takes effect on the sidebar's next frame, without building the section again", async () => {
184
+ let linesCalls = 0;
185
+ registerSection(
186
+ section("loon.music", {
187
+ title: "MUSIC",
188
+ lines: () => {
189
+ linesCalls += 1;
190
+ return ["track one"];
191
+ },
192
+ }),
193
+ );
194
+ const host = arm();
195
+ host.buildMenu();
196
+
197
+ assert.deepEqual(cardTitles(), ["FOOTER", "MUSIC"]);
198
+ assert.equal(linesCalls, 1);
199
+
200
+ await host.pressRow(
201
+ (row) => row.choice?.setting === "music" && row.choice.value === "hidden",
202
+ );
203
+ linesCalls = 0;
204
+
205
+ assert.deepEqual(cardTitles(), ["FOOTER"], "the next frame drops the card");
206
+ assert.equal(linesCalls, 0, "and does not build the hidden section's content");
207
+ });
208
+
209
+ test("a section registered later gains rows without re-registering the provider", () => {
210
+ registerSection(section("first", { title: "FIRST" }));
211
+ installSectionRows();
212
+
213
+ assert.equal(rowsNow().length, 2);
214
+
215
+ registerSection(section("second", { title: "SECOND" }));
216
+
217
+ assert.deepEqual(
218
+ settingsOf(rowsNow()),
219
+ ["first", "first", "second", "second"],
220
+ "rows are built per menu build from the live registry, each named by its label",
221
+ );
222
+ });
223
+
224
+ test("a disposed section loses its rows and its card", async () => {
225
+ const dispose = registerSection(section("gone", { title: "GONE" }));
226
+ registerSection(section("stays", { title: "STAYS" }));
227
+ const host = arm();
228
+ host.buildMenu();
229
+ assert.equal(host.toggleLines().length, 2);
230
+ assert.deepEqual(cardTitles(), ["FOOTER", "GONE", "STAYS"]);
231
+
232
+ dispose();
233
+
234
+ assert.deepEqual(settingsOf(rowsNow()), ["stays", "stays"]);
235
+ assert.deepEqual(cardTitles(), ["FOOTER", "STAYS"]);
236
+ });
237
+
238
+ test("two sections with the same id replace each other instead of duplicating", () => {
239
+ registerSection(section("dup", { title: "FIRST TITLE" }));
240
+ registerSection(section("dup", { title: "SECOND TITLE" }));
241
+ registerSection(section("other", { title: "OTHER" }));
242
+ const host = arm();
243
+ host.buildMenu();
244
+
245
+ const dupRows = rowsNow().filter((row) => row.choice?.setting === "second title");
246
+ assert.equal(dupRows.length, 2, "still one toggle for that id");
247
+ assert.equal(
248
+ host.toggleLines().filter((line) => line.startsWith("second title")).length,
249
+ 1,
250
+ "and one line, named by the live title's label",
251
+ );
252
+
253
+ assert.deepEqual(cardTitles(), ["FOOTER", "SECOND TITLE", "OTHER"], "one card, the live section");
254
+
255
+ // One rendered label per toggle value, so the same label appears twice by design; what matters is
256
+ // that the replaced label is gone.
257
+ const rendered = [...new Set(host.rendered().filter((label) => label.includes("title")))];
258
+ assert.deepEqual(rendered, ["second title"], "the replaced title is not left in the menu");
259
+ });
260
+
261
+ test("each section's line is independent: one toggle never writes another's key", () => {
262
+ registerSection(section("a", { title: "AAA" }));
263
+ registerSection(section("b", { title: "BBB" }));
264
+ arm();
265
+
266
+ const hideB = rowsNow().find(
267
+ (row) => row.choice?.setting === "bbb" && row.choice.value === "hidden",
268
+ );
269
+ assert.ok(hideB?.action !== undefined);
270
+ hideB.action({ input: async () => undefined, confirm: async () => true, capture: async () => undefined });
271
+
272
+ assert.deepEqual(JSON.parse(readFileSync(storePath(), "utf8")), {
273
+ schemaVersion: 1,
274
+ values: { sections: { b: false } },
275
+ });
276
+ const rows = rowsNow();
277
+ const currentFor = (setting: string, value: string): boolean | undefined =>
278
+ rows.find((row) => row.choice?.setting === setting && row.choice.value === value)?.choice?.current();
279
+ assert.equal(currentFor("aaa", "shown"), true, "the untouched section stays shown");
280
+ assert.equal(currentFor("bbb", "shown"), false);
281
+ assert.equal(currentFor("bbb", "hidden"), true);
282
+ });
283
+
284
+ test("defaultVisible false starts hidden, and the rows say so", () => {
285
+ registerSection(section("quiet", { title: "QUIET", defaultVisible: false }));
286
+ const host = arm();
287
+ host.buildMenu();
288
+
289
+ assert.deepEqual(cardTitles(), ["FOOTER"]);
290
+ const line = host.toggleLines()[0];
291
+ assert.ok(line.includes("○ shown"));
292
+ assert.ok(line.includes("● hidden"));
293
+ });