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,292 @@
1
+ /**
2
+ * The in-TUI diagnostics channel.
3
+ *
4
+ * Pi renders every diagnostic inside its own report; text written to stdout/stderr at load time
5
+ * appears in the terminal around Pi's startup, outside the TUI that owns the screen. So the bridge
6
+ * never writes to the console: a message produced before a context exists is buffered here and
7
+ * flushed ONCE through `ctx.ui.notify`, and the diagnostics record keeps reporting it afterwards.
8
+ *
9
+ * These tests pin the whole contract: the bounded buffer, the dedupe, the flush-once rule, the
10
+ * no-UI case, the status block, and — the reason the module exists — that loading the entry, the
11
+ * example and an armed session produce ZERO console writes.
12
+ */
13
+
14
+ import assert from "node:assert/strict";
15
+ import test from "node:test";
16
+
17
+ import { BRIDGE_API_KEY, resetBridgeApiForTests } from "../../lib/shell-api/api.ts";
18
+ import { resetBusForTests } from "../../lib/shell-api/bus.ts";
19
+ import { resetCaptureStateForTests } from "../../lib/shell-api/capture.ts";
20
+ import gentleShellBridge, {
21
+ type BridgeExtensionApi,
22
+ type BridgeSessionHandler,
23
+ } from "../../lib/shell-api/extension.ts";
24
+ import { resetHookStateForTests } from "../../lib/shell-api/hook.ts";
25
+ import {
26
+ MAX_NOTICES,
27
+ flushNotices,
28
+ recordNotice,
29
+ resetNoticesForTests,
30
+ snapshotNotices,
31
+ } from "../../lib/shell-api/notices.ts";
32
+ import { resetRowBuildStateForTests } from "../../lib/shell-api/rows.ts";
33
+ import { disableSidebarBackend, resetSidebarStateForTests } from "../../lib/shell-api/sidebar.ts";
34
+ import { resetSectionFailuresForTests } from "../../lib/shell-api/sidebar-render.ts";
35
+ import { resetStoreStateForTests } from "../../lib/shell-api/store.ts";
36
+ import { createFakeHost } from "./fake-host.ts";
37
+ import { resetSidebar } from "./fake-sidebar.ts";
38
+
39
+ const hostSlot = (): Record<symbol, unknown> => globalThis as unknown as Record<symbol, unknown>;
40
+
41
+ interface ConsoleCapture {
42
+ writes: string[];
43
+ restore: () => void;
44
+ }
45
+
46
+ /** Record every terminal write the process would show. */
47
+ const captureConsole = (): ConsoleCapture => {
48
+ const writes: string[] = [];
49
+ const sink = (globalThis as unknown as { console: { log: unknown; warn: unknown; error: unknown } })
50
+ .console;
51
+ const original = { log: sink.log, warn: sink.warn, error: sink.error };
52
+ const record =
53
+ (method: string) =>
54
+ (...args: unknown[]): void => {
55
+ writes.push(`${method}: ${args.map((arg) => String(arg)).join(" ")}`);
56
+ };
57
+ sink.log = record("log");
58
+ sink.warn = record("warn");
59
+ sink.error = record("error");
60
+ return {
61
+ writes,
62
+ restore: () => {
63
+ sink.log = original.log;
64
+ sink.warn = original.warn;
65
+ sink.error = original.error;
66
+ },
67
+ };
68
+ };
69
+
70
+ interface RecordingUi {
71
+ notify: (message: string, level?: "info" | "warning" | "error") => void;
72
+ }
73
+
74
+ const recordingUi = (): { ui: RecordingUi; calls: Array<[string, string | undefined]> } => {
75
+ const calls: Array<[string, string | undefined]> = [];
76
+ return {
77
+ ui: { notify: (message, level) => calls.push([message, level]) },
78
+ calls,
79
+ };
80
+ };
81
+
82
+ const entryHandlers = (): BridgeSessionHandler[] => {
83
+ const handlers: BridgeSessionHandler[] = [];
84
+ const pi: BridgeExtensionApi = {
85
+ // `gentle-pi` is loaded, so the runtime gate is open and the buffered notice is flushed.
86
+ getCommands: () => [{ name: "gentle:customize" }],
87
+ on(_event, handler) {
88
+ handlers.push(handler);
89
+ },
90
+ registerCommand() {},
91
+ };
92
+ gentleShellBridge(pi);
93
+ return handlers;
94
+ };
95
+
96
+ test.beforeEach(() => {
97
+ resetBridgeApiForTests();
98
+ resetNoticesForTests();
99
+ resetBusForTests();
100
+ resetSidebar();
101
+ resetSidebarStateForTests();
102
+ resetSectionFailuresForTests();
103
+ resetStoreStateForTests();
104
+ resetCaptureStateForTests();
105
+ resetHookStateForTests();
106
+ resetRowBuildStateForTests();
107
+ disableSidebarBackend();
108
+ });
109
+
110
+ // ---------------------------------------------------------------------------------------------
111
+ // The bounded buffer
112
+ // ---------------------------------------------------------------------------------------------
113
+
114
+ test("a notice is buffered as pending, with its level", () => {
115
+ recordNotice("the slot holds a foreign object", "warning");
116
+
117
+ assert.deepEqual(snapshotNotices(), {
118
+ entries: [{ message: "the slot holds a foreign object", level: "warning", emitted: false }],
119
+ dropped: 0,
120
+ });
121
+ });
122
+
123
+ test("the default level is warning: every notice here is a problem report", () => {
124
+ recordNotice("no registerToolRenderer");
125
+
126
+ assert.equal(snapshotNotices().entries[0].level, "warning");
127
+ });
128
+
129
+ test("an identical message is recorded once, not once per load", () => {
130
+ recordNotice("same fact", "warning");
131
+ recordNotice("same fact", "warning");
132
+ recordNotice("same fact", "error");
133
+
134
+ assert.deepEqual(
135
+ snapshotNotices().entries.map((entry) => [entry.message, entry.level]),
136
+ [
137
+ ["same fact", "warning"],
138
+ ["same fact", "error"],
139
+ ],
140
+ );
141
+ });
142
+
143
+ test("the buffer is bounded and counts what it had to drop", () => {
144
+ for (let index = 0; index < MAX_NOTICES + 3; index += 1) recordNotice(`notice ${index}`);
145
+
146
+ const snapshot = snapshotNotices();
147
+ assert.equal(snapshot.entries.length, MAX_NOTICES, "never unbounded");
148
+ assert.equal(snapshot.dropped, 3, "and the loss is reported, not silent");
149
+ assert.equal(snapshot.entries[0].message, "notice 3", "the newest messages survive");
150
+ assert.equal(snapshot.entries.at(-1)?.message, `notice ${MAX_NOTICES + 2}`);
151
+ });
152
+
153
+ test("delivered entries are evicted before a pending one, and nothing is dropped", () => {
154
+ for (let index = 0; index < MAX_NOTICES; index += 1) recordNotice(`delivered ${index}`);
155
+ flushNotices(recordingUi().ui);
156
+ recordNotice("still pending");
157
+ recordNotice("later 1");
158
+ recordNotice("later 2");
159
+
160
+ const snapshot = snapshotNotices();
161
+ assert.equal(snapshot.entries.length, MAX_NOTICES);
162
+ assert.equal(snapshot.dropped, 0, "only already-delivered entries made room");
163
+ assert.equal(
164
+ snapshot.entries.some((entry) => entry.message === "still pending"),
165
+ true,
166
+ "a message the user never saw is never the first to go",
167
+ );
168
+ assert.equal(
169
+ snapshot.entries.some((entry) => entry.message === "delivered 0"),
170
+ false,
171
+ "the oldest delivered notice made the room",
172
+ );
173
+ });
174
+
175
+ // ---------------------------------------------------------------------------------------------
176
+ // The flush: once, through the UI, and only when a UI exists
177
+ // ---------------------------------------------------------------------------------------------
178
+
179
+ test("the first UI session delivers every pending notice exactly once", () => {
180
+ const { ui, calls } = recordingUi();
181
+ recordNotice("first", "warning");
182
+ recordNotice("second", "error");
183
+
184
+ assert.equal(flushNotices(ui), 2);
185
+ assert.equal(flushNotices(ui), 0, "a second session_start never repeats a delivered message");
186
+ assert.deepEqual(calls, [
187
+ ["first", "warning"],
188
+ ["second", "error"],
189
+ ]);
190
+ assert.deepEqual(
191
+ snapshotNotices().entries.map((entry) => entry.emitted),
192
+ [true, true],
193
+ "and they stay reported for the diagnostics record",
194
+ );
195
+ });
196
+
197
+ test("a session without a UI flushes nothing and keeps the message pending", () => {
198
+ recordNotice("waiting for a UI");
199
+
200
+ assert.equal(flushNotices(undefined), 0);
201
+ assert.equal(flushNotices({}), 0, "a context without notify cannot deliver anything");
202
+ assert.deepEqual(
203
+ snapshotNotices().entries.map((entry) => entry.emitted),
204
+ [false],
205
+ "nothing was marked delivered",
206
+ );
207
+ });
208
+
209
+ test("a notify that throws leaves the message pending instead of losing it", () => {
210
+ recordNotice("retry me");
211
+
212
+ assert.doesNotThrow(() =>
213
+ flushNotices({
214
+ notify: () => {
215
+ throw new Error("ui bug");
216
+ },
217
+ }),
218
+ );
219
+ assert.equal(snapshotNotices().entries[0].emitted, false);
220
+
221
+ const { ui, calls } = recordingUi();
222
+ assert.equal(flushNotices(ui), 1, "the next session delivers it");
223
+ assert.deepEqual(calls, [["retry me", "warning"]]);
224
+ });
225
+
226
+ // ---------------------------------------------------------------------------------------------
227
+ // the diagnostics record keeps the information
228
+ // ---------------------------------------------------------------------------------------------
229
+
230
+ // ---------------------------------------------------------------------------------------------
231
+ // No console writes, ever
232
+ // ---------------------------------------------------------------------------------------------
233
+
234
+ test("loading a copy of the handshake with an incompatible slot writes nothing to the console", async () => {
235
+ resetBridgeApiForTests();
236
+ resetNoticesForTests();
237
+ hostSlot()[BRIDGE_API_KEY] = { schema: "someone-else/api", version: 9 };
238
+
239
+ const captured = captureConsole();
240
+ try {
241
+ await import(new URL("../../lib/shell-api/api.ts?console-free-skew", import.meta.url).href);
242
+ } finally {
243
+ captured.restore();
244
+ }
245
+
246
+ assert.deepEqual(captured.writes, [], "the message must not land in the terminal");
247
+ const entries = snapshotNotices().entries;
248
+ assert.equal(entries.length, 1, "it is buffered instead");
249
+ assert.equal(entries[0].level, "warning");
250
+ assert.match(entries[0].message, /incompatible|not the|version/u);
251
+ });
252
+
253
+ test("loading the extension entry writes nothing to the console", async () => {
254
+ const captured = captureConsole();
255
+ try {
256
+ await import(new URL("../../lib/shell-api/extension.ts?console-free-load", import.meta.url).href);
257
+ } finally {
258
+ captured.restore();
259
+ }
260
+
261
+ assert.deepEqual(captured.writes, []);
262
+ });
263
+
264
+ test("an armed session flushes once through notify and writes nothing to the console", () => {
265
+ const host = createFakeHost();
266
+ const { ui, calls } = recordingUi();
267
+ const handlers = entryHandlers();
268
+ recordNotice("buffered before the UI existed", "warning");
269
+
270
+ const captured = captureConsole();
271
+ try {
272
+ handlers[0]({}, { hasUI: true, ui: { ...host.ui, ...ui } });
273
+ handlers[0]({}, { hasUI: true, ui: { ...host.ui, ...ui } });
274
+ } finally {
275
+ captured.restore();
276
+ }
277
+
278
+ assert.deepEqual(captured.writes, []);
279
+ assert.deepEqual(calls, [["buffered before the UI existed", "warning"]]);
280
+ });
281
+
282
+ test("a no-UI session does not flush, and the same message arrives on the next UI session", () => {
283
+ const { ui, calls } = recordingUi();
284
+ const handlers = entryHandlers();
285
+ recordNotice("waiting for a UI", "warning");
286
+
287
+ handlers[0]({}, { hasUI: false });
288
+ assert.deepEqual(calls, [], "nothing can be shown without a UI");
289
+
290
+ handlers[0]({}, { hasUI: true, ui });
291
+ assert.deepEqual(calls, [["waiting for a UI", "warning"]], "flushed exactly once, later");
292
+ });