@blackbelt-technology/pi-dashboard-extension 0.7.0 → 0.9.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 (265) hide show
  1. package/.pi/skills/browser/SKILL.md +84 -29
  2. package/.pi/skills/browser/UPSTREAM.md +13 -1
  3. package/.pi/skills/browser/references/challenge.md +183 -0
  4. package/.pi/skills/browser/references/dashboard-relay.md +150 -0
  5. package/.pi/skills/browser/references/electron.agent.md +57 -0
  6. package/.pi/skills/browser/references/own-browser.md +305 -0
  7. package/.pi/skills/browser/references/web.agent.md +323 -0
  8. package/.pi/skills/browser/scripts/check-panerelay.sh +157 -0
  9. package/.pi/skills/doctor/SKILL.md +4 -9
  10. package/.pi/skills/doctor/_lib/checks.ts +133 -54
  11. package/.pi/skills/doctor/_lib/derive-tokens.ts +5 -0
  12. package/.pi/skills/doctor/modules/apple-tools.knowledge.hash +1 -0
  13. package/.pi/skills/doctor/modules/apple-tools.md +52 -0
  14. package/.pi/skills/doctor/modules/mcp-builtin.knowledge.hash +1 -0
  15. package/.pi/skills/doctor/modules/mcp-builtin.md +61 -0
  16. package/.pi/skills/doctor/modules/oauth-redirect-base.knowledge.hash +1 -0
  17. package/.pi/skills/doctor/modules/oauth-redirect-base.md +71 -0
  18. package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -1
  19. package/.pi/skills/doctor/modules/pi-resolution.md +21 -1
  20. package/.pi/skills/doctor/modules/plugins-bridges.md +14 -1
  21. package/.pi/skills/pi-dashboard/SKILL.md +10 -3
  22. package/.pi/skills/pi-dashboard/references/api-reference.agent.md +69 -0
  23. package/.pi/skills/pi-dashboard/scripts/dashboard-bus.ts +4 -4
  24. package/.pi/skills/project-init/SKILL.md +41 -34
  25. package/.pi/skills/project-init/profiles/coding/AGENTS.md.tmpl +0 -23
  26. package/.pi/skills/project-init/profiles/docs/profile.json +1 -1
  27. package/README.md +19 -0
  28. package/agents/DoxTriage.md +80 -0
  29. package/package.json +30 -16
  30. package/src/ask-user-tool.ts +4 -0
  31. package/src/auto-session-namer.ts +486 -70
  32. package/src/autostart-guard.ts +99 -0
  33. package/src/autostart-lock.ts +258 -0
  34. package/src/bridge-activation.ts +26 -0
  35. package/src/bridge-context.ts +106 -23
  36. package/src/bridge-default-model-gate.ts +38 -0
  37. package/src/bridge-polling.ts +148 -0
  38. package/src/bridge-ticket-client.ts +105 -0
  39. package/src/bridge.ts +1760 -350
  40. package/src/canvas-tool.ts +5 -0
  41. package/src/command-handler.ts +392 -71
  42. package/src/connect-target.ts +130 -0
  43. package/src/connection.ts +846 -17
  44. package/src/custom-entry-forward.ts +92 -0
  45. package/src/endpoint-resolution.ts +253 -0
  46. package/src/event-forwarder.ts +42 -0
  47. package/src/extension-identity.ts +59 -0
  48. package/src/flow-event-wiring.ts +125 -3
  49. package/src/followup-buffer.ts +217 -0
  50. package/src/git-dir-watcher.ts +79 -0
  51. package/src/git-poll.ts +45 -12
  52. package/src/git-probe-scheduler.ts +119 -0
  53. package/src/git-tracker.ts +284 -0
  54. package/src/instance-verification.ts +156 -0
  55. package/src/local-token-header.ts +44 -0
  56. package/src/mcp-token-delivery.ts +147 -0
  57. package/src/message-update-coalescer.ts +340 -0
  58. package/src/model-refresh.ts +95 -0
  59. package/src/model-tracker.ts +118 -35
  60. package/src/notify-proxy.ts +36 -0
  61. package/src/path-gate/decide.ts +149 -0
  62. package/src/path-gate/grant-cache.ts +71 -0
  63. package/src/path-gate/grant-link.ts +108 -0
  64. package/src/path-gate/handler.ts +307 -0
  65. package/src/path-gate/index.ts +155 -0
  66. package/src/path-gate/resolve.ts +126 -0
  67. package/src/path-gate/roots.ts +137 -0
  68. package/src/path-gate/suppression.ts +27 -0
  69. package/src/pending-prompt-emitter.ts +59 -0
  70. package/src/pi-env.d.ts +6 -10
  71. package/src/pi-retry-settings.ts +91 -0
  72. package/src/plugin-request-client.ts +114 -0
  73. package/src/poll-cost.ts +40 -0
  74. package/src/pr-status.ts +338 -0
  75. package/src/process-metrics.ts +77 -1
  76. package/src/process-scan-scheduler.ts +137 -0
  77. package/src/process-scanner.ts +226 -247
  78. package/src/project-init/dox-kb-config.ts +3 -0
  79. package/src/project-init/scaffold.ts +1 -4
  80. package/src/project-init/seed-doctrine.ts +23 -60
  81. package/src/prompt-bus.ts +13 -0
  82. package/src/provider-register.ts +92 -21
  83. package/src/remote-registration-gate.ts +102 -0
  84. package/src/retry-tracker.ts +258 -86
  85. package/src/role-manager.ts +38 -91
  86. package/src/role-model-tools.ts +44 -3
  87. package/src/server-auto-start.ts +331 -20
  88. package/src/server-launcher.ts +70 -34
  89. package/src/server-pin-store.ts +92 -0
  90. package/src/session-move.ts +275 -0
  91. package/src/session-sync.ts +75 -20
  92. package/src/slash-dispatch.ts +66 -81
  93. package/src/subagent-fanout-admission.ts +234 -0
  94. package/src/subagent-forward-sites.ts +69 -0
  95. package/src/subagent-frame-buffer.ts +24 -3
  96. package/src/subagent-frame-strip.ts +109 -0
  97. package/src/subagent-saturation.ts +196 -0
  98. package/src/subagent-tick-throttle.ts +250 -0
  99. package/src/terminal-reload.ts +298 -0
  100. package/src/transcript-backfill.ts +151 -0
  101. package/src/transport-diagnostics.ts +76 -0
  102. package/src/tui-prompt-adapter.ts +13 -1
  103. package/src/turn-actionability.ts +20 -0
  104. package/src/ui-stale-guard.ts +58 -0
  105. package/src/usage-drain.ts +167 -0
  106. package/src/vcs-info.ts +261 -63
  107. package/.pi/skills/doctor/AGENTS.md +0 -27
  108. package/.pi/skills/project-init/dox-doctrine.md +0 -104
  109. package/src/AGENTS.md +0 -57
  110. package/src/__tests__/abort-latch.test.ts +0 -97
  111. package/src/__tests__/agent-settled.test.ts +0 -82
  112. package/src/__tests__/artifact-roots.test.ts +0 -83
  113. package/src/__tests__/ask-user-attachments.test.ts +0 -106
  114. package/src/__tests__/ask-user-schema-discriminator.test.ts +0 -141
  115. package/src/__tests__/ask-user-tool.test.ts +0 -571
  116. package/src/__tests__/auto-session-namer.test.ts +0 -339
  117. package/src/__tests__/bridge-default-model-apply.test.ts +0 -242
  118. package/src/__tests__/bridge-default-model-gate.test.ts +0 -50
  119. package/src/__tests__/bridge-entry-id-pi-070.test.ts +0 -174
  120. package/src/__tests__/bridge-followup-chat-order.test.ts +0 -215
  121. package/src/__tests__/bridge-followup-multi-entry.test.ts +0 -202
  122. package/src/__tests__/bridge-followup-mutation.test.ts +0 -217
  123. package/src/__tests__/bridge-followup-queue-drain.test.ts +0 -266
  124. package/src/__tests__/bridge-hasui-flip.test.ts +0 -109
  125. package/src/__tests__/bridge-no-queue-mutation.test.ts +0 -112
  126. package/src/__tests__/bridge-plugin-emit-event.test.ts +0 -44
  127. package/src/__tests__/bridge-queue-update-forward.test.ts +0 -77
  128. package/src/__tests__/bridge-resume-disconnect.test.ts +0 -333
  129. package/src/__tests__/bridge-shadow-queue-gate.test.ts +0 -299
  130. package/src/__tests__/bridge-shutdown-reset.test.ts +0 -159
  131. package/src/__tests__/bridge-slash-command-routing.test.ts +0 -458
  132. package/src/__tests__/bridge-stop-after-turn.test.ts +0 -72
  133. package/src/__tests__/bridge-system-followup.test.ts +0 -163
  134. package/src/__tests__/bridge-thinking-level-select.test.ts +0 -68
  135. package/src/__tests__/browser-skill-registered.test.ts +0 -84
  136. package/src/__tests__/build-provider-catalogue.test.ts +0 -210
  137. package/src/__tests__/command-handler.test.ts +0 -1180
  138. package/src/__tests__/commit-draft.test.ts +0 -100
  139. package/src/__tests__/connection-dropped-frames.test.ts +0 -78
  140. package/src/__tests__/connection-suppress-auto-start.test.ts +0 -97
  141. package/src/__tests__/connection.test.ts +0 -344
  142. package/src/__tests__/credentials-updated.test.ts +0 -26
  143. package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +0 -128
  144. package/src/__tests__/cwd-missing-probe.test.ts +0 -82
  145. package/src/__tests__/dashboard-commands-shipped.test.ts +0 -53
  146. package/src/__tests__/dashboard-context-injector.test.ts +0 -190
  147. package/src/__tests__/dashboard-default-adapter.test.ts +0 -77
  148. package/src/__tests__/dev-build.test.ts +0 -79
  149. package/src/__tests__/doctor/checks.test.ts +0 -121
  150. package/src/__tests__/doctor/modules.test.ts +0 -64
  151. package/src/__tests__/doctor/provenance-hash.test.ts +0 -94
  152. package/src/__tests__/doctor/router.test.ts +0 -143
  153. package/src/__tests__/empty-actionable-guard-config.test.ts +0 -32
  154. package/src/__tests__/empty-actionable-guard.test.ts +0 -73
  155. package/src/__tests__/enrich-model-metadata.test.ts +0 -222
  156. package/src/__tests__/event-forwarder.test.ts +0 -119
  157. package/src/__tests__/extension-slash-command-detection.test.ts +0 -143
  158. package/src/__tests__/filter-enabled-models.test.ts +0 -151
  159. package/src/__tests__/fixtures/turn-actionability-fixtures.ts +0 -69
  160. package/src/__tests__/fork-entryid-timing.test.ts +0 -88
  161. package/src/__tests__/git-info-status.test.ts +0 -73
  162. package/src/__tests__/git-link-builder.test.ts +0 -102
  163. package/src/__tests__/git-poll.test.ts +0 -69
  164. package/src/__tests__/markdown-image-inliner.test.ts +0 -392
  165. package/src/__tests__/model-resolve.test.ts +0 -379
  166. package/src/__tests__/multiselect-dashboard-routing.test.ts +0 -203
  167. package/src/__tests__/multiselect-list.test.ts +0 -137
  168. package/src/__tests__/multiselect-polyfill.test.ts +0 -92
  169. package/src/__tests__/no-session-replacement-calls.test.ts +0 -99
  170. package/src/__tests__/no-tui-multiselect-arm-regression.test.ts +0 -81
  171. package/src/__tests__/openspec-activity-detector.test.ts +0 -337
  172. package/src/__tests__/openspec-cli-shim.test.ts +0 -145
  173. package/src/__tests__/openspec-poller.test.ts +0 -124
  174. package/src/__tests__/pi-version-tracker.test.ts +0 -109
  175. package/src/__tests__/process-metrics.test.ts +0 -47
  176. package/src/__tests__/process-scanner-kill.test.ts +0 -61
  177. package/src/__tests__/process-scanner.test.ts +0 -292
  178. package/src/__tests__/project-init-detect-stack.test.ts +0 -61
  179. package/src/__tests__/project-init-dox-kb-config.test.ts +0 -53
  180. package/src/__tests__/project-init-profiles.test.ts +0 -84
  181. package/src/__tests__/project-init-scaffold.test.ts +0 -139
  182. package/src/__tests__/project-init-seed-doctrine.test.ts +0 -100
  183. package/src/__tests__/project-trust.test.ts +0 -92
  184. package/src/__tests__/prompt-bus-wiring.test.ts +0 -791
  185. package/src/__tests__/prompt-bus.test.ts +0 -513
  186. package/src/__tests__/prompt-expander.test.ts +0 -398
  187. package/src/__tests__/provider-register-native-models.test.ts +0 -182
  188. package/src/__tests__/provider-register-reload.test.ts +0 -498
  189. package/src/__tests__/provider-register-thinking-levels.test.ts +0 -104
  190. package/src/__tests__/retry-tracker.test.ts +0 -152
  191. package/src/__tests__/role-manager.test.ts +0 -585
  192. package/src/__tests__/role-model-tools-registry-readiness.test.ts +0 -114
  193. package/src/__tests__/role-model-tools.test.ts +0 -229
  194. package/src/__tests__/search-files-completeness.test.ts +0 -111
  195. package/src/__tests__/search-files-ranking.test.ts +0 -168
  196. package/src/__tests__/server-auto-start.test.ts +0 -375
  197. package/src/__tests__/server-launcher-launch.test.ts +0 -96
  198. package/src/__tests__/server-launcher.test.ts +0 -101
  199. package/src/__tests__/server-probe.test.ts +0 -25
  200. package/src/__tests__/session-switch.test.ts +0 -139
  201. package/src/__tests__/session-sync.test.ts +0 -243
  202. package/src/__tests__/single-derivation-guard.test.ts +0 -39
  203. package/src/__tests__/source-detector.test.ts +0 -88
  204. package/src/__tests__/stats-extractor.test.ts +0 -92
  205. package/src/__tests__/subagent-frame-buffer.test.ts +0 -239
  206. package/src/__tests__/tool-result-image-inliner.test.ts +0 -206
  207. package/src/__tests__/tui-prompt-adapter.test.ts +0 -213
  208. package/src/__tests__/turn-actionability.test.ts +0 -86
  209. package/src/__tests__/ui-decorators.test.ts +0 -309
  210. package/src/__tests__/ui-modules.test.ts +0 -293
  211. package/src/__tests__/vcs-info.test.ts +0 -265
  212. package/src/__tests__/visibility-intent.test.ts +0 -43
  213. package/src/__tests__/watchdog.test.ts +0 -161
  214. package/src/abort-latch.ts.AGENTS.md +0 -3
  215. package/src/agent-settled.ts +0 -72
  216. package/src/agent-settled.ts.AGENTS.md +0 -3
  217. package/src/artifact-roots.ts.AGENTS.md +0 -3
  218. package/src/ask-user-attachments.ts.AGENTS.md +0 -3
  219. package/src/ask-user-tool.ts.AGENTS.md +0 -3
  220. package/src/auto-session-namer.ts.AGENTS.md +0 -3
  221. package/src/bridge-context.ts.AGENTS.md +0 -3
  222. package/src/bridge-default-model-gate.ts.AGENTS.md +0 -3
  223. package/src/bridge.ts.AGENTS.md +0 -3
  224. package/src/command-handler.ts.AGENTS.md +0 -3
  225. package/src/commit-draft-agent.ts.AGENTS.md +0 -3
  226. package/src/commit-draft.ts.AGENTS.md +0 -3
  227. package/src/connection.ts.AGENTS.md +0 -3
  228. package/src/dashboard-context-injector.ts.AGENTS.md +0 -3
  229. package/src/dashboard-default-adapter.ts.AGENTS.md +0 -3
  230. package/src/dev-build.ts.AGENTS.md +0 -3
  231. package/src/empty-actionable-guard-config.ts.AGENTS.md +0 -3
  232. package/src/empty-actionable-guard.ts.AGENTS.md +0 -3
  233. package/src/event-forwarder.ts.AGENTS.md +0 -3
  234. package/src/flow-event-wiring.ts.AGENTS.md +0 -3
  235. package/src/git-link-builder.ts.AGENTS.md +0 -3
  236. package/src/git-poll.ts.AGENTS.md +0 -3
  237. package/src/hasui-flip.ts.AGENTS.md +0 -3
  238. package/src/markdown-image-inliner.ts.AGENTS.md +0 -3
  239. package/src/model-tracker.ts.AGENTS.md +0 -3
  240. package/src/multiselect-decode.ts.AGENTS.md +0 -3
  241. package/src/multiselect-list.ts.AGENTS.md +0 -3
  242. package/src/multiselect-polyfill.ts.AGENTS.md +0 -3
  243. package/src/openspec-cli-shim.ts.AGENTS.md +0 -7
  244. package/src/process-metrics.ts.AGENTS.md +0 -3
  245. package/src/process-scanner.ts.AGENTS.md +0 -3
  246. package/src/project-init/AGENTS.md +0 -12
  247. package/src/project-trust.ts.AGENTS.md +0 -3
  248. package/src/prompt-bus.ts.AGENTS.md +0 -3
  249. package/src/prompt-expander.ts.AGENTS.md +0 -3
  250. package/src/provider-register.ts.AGENTS.md +0 -3
  251. package/src/retry-tracker.ts.AGENTS.md +0 -3
  252. package/src/role-manager.ts.AGENTS.md +0 -3
  253. package/src/role-model-tools.ts.AGENTS.md +0 -3
  254. package/src/server-auto-start.ts.AGENTS.md +0 -3
  255. package/src/server-launcher.ts.AGENTS.md +0 -3
  256. package/src/session-sync.ts.AGENTS.md +0 -3
  257. package/src/slash-dispatch.ts.AGENTS.md +0 -3
  258. package/src/source-detector.ts.AGENTS.md +0 -3
  259. package/src/subagent-frame-buffer.ts.AGENTS.md +0 -3
  260. package/src/tool-result-image-inliner.ts.AGENTS.md +0 -3
  261. package/src/tui-prompt-adapter.ts.AGENTS.md +0 -3
  262. package/src/turn-actionability.ts.AGENTS.md +0 -3
  263. package/src/ui-modules.ts.AGENTS.md +0 -3
  264. package/src/vcs-info.ts.AGENTS.md +0 -3
  265. package/src/visibility-intent.ts.AGENTS.md +0 -3
@@ -1,137 +0,0 @@
1
- import { describe, it, expect, vi } from "vitest";
2
- import { MultiSelectList } from "../multiselect-list.js";
3
-
4
- function make(options: string[] = ["A", "B", "C"], title = "Pick", message?: string) {
5
- const list = new MultiSelectList(title, options, message);
6
- const onConfirm = vi.fn();
7
- const onCancel = vi.fn();
8
- list.onConfirm = onConfirm;
9
- list.onCancel = onCancel;
10
- return { list, onConfirm, onCancel };
11
- }
12
-
13
- describe("MultiSelectList", () => {
14
- describe("keybindings", () => {
15
- it("space toggles the checked state of the current item and nothing else", () => {
16
- const { list, onConfirm } = make();
17
- list.handleInput(" "); // toggle index 0 → A checked
18
- list.handleInput("\r");
19
- expect(onConfirm).toHaveBeenCalledWith(["A"]);
20
- });
21
-
22
- it("arrow down moves cursor and space toggles the new current item", () => {
23
- const { list, onConfirm } = make();
24
- list.handleInput("\u001b[B"); // cursor → 1 (B)
25
- list.handleInput(" "); // B checked
26
- list.handleInput("\r");
27
- expect(onConfirm).toHaveBeenCalledWith(["B"]);
28
- });
29
-
30
- it("j / k navigation works like arrows", () => {
31
- const { list, onConfirm } = make();
32
- list.handleInput("j"); // cursor → 1
33
- list.handleInput("j"); // cursor → 2
34
- list.handleInput(" "); // C checked
35
- list.handleInput("k"); // cursor → 1
36
- list.handleInput(" "); // B checked
37
- list.handleInput("\r");
38
- // selected values returned in ORIGINAL order
39
- expect(onConfirm).toHaveBeenCalledWith(["B", "C"]);
40
- });
41
-
42
- it("enter with nothing checked confirms with []", () => {
43
- const { list, onConfirm } = make();
44
- list.handleInput("\r");
45
- expect(onConfirm).toHaveBeenCalledWith([]);
46
- });
47
-
48
- it("escape cancels; no confirm is fired", () => {
49
- const { list, onConfirm, onCancel } = make();
50
- list.handleInput(" "); // check A
51
- list.handleInput("\u001b");
52
- expect(onCancel).toHaveBeenCalledTimes(1);
53
- expect(onConfirm).not.toHaveBeenCalled();
54
- });
55
-
56
- it("pressing 'a' does NOT bulk-toggle (no select-all in TUI)", () => {
57
- const { list, onConfirm } = make();
58
- list.handleInput("a");
59
- list.handleInput("\r");
60
- expect(onConfirm).toHaveBeenCalledWith([]);
61
- });
62
-
63
- it("cursor does not go below 0", () => {
64
- const { list } = make();
65
- list.handleInput("k");
66
- list.handleInput("k");
67
- expect(list.getCursor()).toBe(0);
68
- });
69
-
70
- it("cursor does not go past last item", () => {
71
- const { list } = make(["A", "B"]);
72
- list.handleInput("j");
73
- list.handleInput("j");
74
- list.handleInput("j");
75
- expect(list.getCursor()).toBe(1);
76
- });
77
-
78
- it("toggling twice returns item to unchecked", () => {
79
- const { list, onConfirm } = make();
80
- list.handleInput(" ");
81
- list.handleInput(" ");
82
- list.handleInput("\r");
83
- expect(onConfirm).toHaveBeenCalledWith([]);
84
- });
85
-
86
- it("selected order follows original option order, not toggle order", () => {
87
- const { list, onConfirm } = make(["A", "B", "C", "D"]);
88
- // toggle D first, then A, then C
89
- list.handleInput("j");
90
- list.handleInput("j");
91
- list.handleInput("j");
92
- list.handleInput(" "); // D
93
- list.handleInput("k");
94
- list.handleInput("k");
95
- list.handleInput("k");
96
- list.handleInput(" "); // A
97
- list.handleInput("j");
98
- list.handleInput("j");
99
- list.handleInput(" "); // C
100
- list.handleInput("\r");
101
- expect(onConfirm).toHaveBeenCalledWith(["A", "C", "D"]);
102
- });
103
- });
104
-
105
- describe("render", () => {
106
- it("includes footer hint", () => {
107
- const { list } = make();
108
- const lines = list.render(80);
109
- expect(lines.some((l) => l.includes("space toggle"))).toBe(true);
110
- expect(lines.some((l) => l.includes("enter confirm"))).toBe(true);
111
- expect(lines.some((l) => l.includes("esc cancel"))).toBe(true);
112
- });
113
-
114
- it("renders [ ] for unchecked and [x] for checked items", () => {
115
- const { list } = make();
116
- list.handleInput(" "); // check A
117
- const lines = list.render(80);
118
- expect(lines.some((l) => l.includes("[x] A"))).toBe(true);
119
- expect(lines.some((l) => l.includes("[ ] B"))).toBe(true);
120
- });
121
-
122
- it("renders cursor marker on current item", () => {
123
- const { list } = make();
124
- list.handleInput("j"); // cursor → 1
125
- const lines = list.render(80);
126
- // Cursor line should start with "▸ " somewhere
127
- expect(lines.some((l) => l.startsWith("▸ ") && l.includes("B"))).toBe(true);
128
- });
129
-
130
- it("includes title and message when provided", () => {
131
- const { list } = make(["A", "B"], "Pick one or more", "Some context");
132
- const lines = list.render(80);
133
- expect(lines.some((l) => l.includes("Pick one or more"))).toBe(true);
134
- expect(lines.some((l) => l.includes("Some context"))).toBe(true);
135
- });
136
- });
137
- });
@@ -1,92 +0,0 @@
1
- /**
2
- * Tests for `polyfillMultiselect`'s fallback chain. After the
3
- * fix-multiselect-auto-cancel-on-dashboard change, the polyfill prefers a
4
- * bridge-patched `ctx.ui.multiselect` (the PromptBus path that surfaces in
5
- * the dashboard browser) and falls back to the legacy `ctx.ui.custom` +
6
- * `MultiSelectList` overlay only when the patch is absent (older pi
7
- * versions or non-bridge embeddings).
8
- *
9
- * See change: fix-multiselect-auto-cancel-on-dashboard.
10
- */
11
- import { describe, it, expect, vi } from "vitest";
12
- import { polyfillMultiselect } from "../multiselect-polyfill.js";
13
-
14
- describe("polyfillMultiselect — fallback chain", () => {
15
- it("delegates to ctx.ui.multiselect when present (primary, bus-routed path)", async () => {
16
- const multiselectFn = vi.fn().mockResolvedValue(["a"]);
17
- const customFn = vi.fn();
18
- const ctx = {
19
- ui: {
20
- multiselect: multiselectFn,
21
- custom: customFn,
22
- },
23
- };
24
-
25
- const result = await polyfillMultiselect(ctx as any, "Pick", ["a", "b"]);
26
-
27
- expect(result).toEqual(["a"]);
28
- expect(multiselectFn).toHaveBeenCalledTimes(1);
29
- expect(multiselectFn).toHaveBeenCalledWith("Pick", ["a", "b"], undefined);
30
- expect(customFn).not.toHaveBeenCalled();
31
- });
32
-
33
- it("forwards opts.message to ctx.ui.multiselect when present", async () => {
34
- const multiselectFn = vi.fn().mockResolvedValue([]);
35
- const ctx = { ui: { multiselect: multiselectFn, custom: vi.fn() } };
36
-
37
- await polyfillMultiselect(ctx as any, "Pick", ["a"], { message: "ctx" });
38
-
39
- expect(multiselectFn).toHaveBeenCalledWith("Pick", ["a"], { message: "ctx" });
40
- });
41
-
42
- it("propagates undefined (cancellation) through the primary path", async () => {
43
- const multiselectFn = vi.fn().mockResolvedValue(undefined);
44
- const ctx = { ui: { multiselect: multiselectFn, custom: vi.fn() } };
45
-
46
- await expect(polyfillMultiselect(ctx as any, "t", ["a"])).resolves.toBeUndefined();
47
- });
48
-
49
- it("falls back to ctx.ui.custom when ctx.ui.multiselect is absent (TUI path)", async () => {
50
- let capturedDone: ((r: string[] | undefined) => void) | undefined;
51
- const customFn = vi.fn().mockImplementation((factory: any) => {
52
- return new Promise<string[] | undefined>((resolve) => {
53
- const done = (r: string[] | undefined) => resolve(r);
54
- capturedDone = done;
55
- const component = factory({}, {}, {}, done);
56
- // Simulate user confirming after the factory wires the component.
57
- component?.onConfirm?.(["b"]);
58
- });
59
- });
60
- const ctx = { ui: { custom: customFn } };
61
-
62
- const result = await polyfillMultiselect(ctx as any, "Pick", ["a", "b"]);
63
-
64
- expect(result).toEqual(["b"]);
65
- expect(customFn).toHaveBeenCalledTimes(1);
66
- expect(capturedDone).toBeTypeOf("function");
67
- });
68
-
69
- it("falls back to ctx.ui.custom and resolves undefined on cancel", async () => {
70
- const customFn = vi.fn().mockImplementation((factory: any) => {
71
- return new Promise<string[] | undefined>((resolve) => {
72
- const component = factory({}, {}, {}, (r: any) => resolve(r));
73
- component?.onCancel?.();
74
- });
75
- });
76
- const ctx = { ui: { custom: customFn } };
77
-
78
- await expect(polyfillMultiselect(ctx as any, "Pick", ["a"])).resolves.toBeUndefined();
79
- });
80
-
81
- it("does NOT fall back to ctx.ui.custom when ctx.ui.multiselect resolves to []", async () => {
82
- // Empty selection is a valid answer — must NOT trigger the legacy fallback.
83
- const multiselectFn = vi.fn().mockResolvedValue([]);
84
- const customFn = vi.fn();
85
- const ctx = { ui: { multiselect: multiselectFn, custom: customFn } };
86
-
87
- const result = await polyfillMultiselect(ctx as any, "t", ["a"]);
88
-
89
- expect(result).toEqual([]);
90
- expect(customFn).not.toHaveBeenCalled();
91
- });
92
- });
@@ -1,99 +0,0 @@
1
- /**
2
- * Repo-level invariant: the bridge MUST NOT call pi's session-replacement
3
- * APIs (`pi.newSession(...)`, `ctx.fork(...)`, `ctx.switchSession(...)`)
4
- * from any code under `packages/extension/src/`.
5
- *
6
- * Rationale: pi 0.69.0+ invalidates captured pre-replacement `pi`/`ctx`/
7
- * session-bound objects on next access after these calls. The bridge
8
- * holds long-lived caches (`cachedCtx`, `cachedModelRegistry`,
9
- * `cachedHasUI` in `bridge.ts`; `modelRegistry` in `provider-register.ts`)
10
- * that depend on pi being the ONLY originator of session replacement, so
11
- * we can re-capture inside the resulting `session_start` handler keyed on
12
- * `event.reason ∈ {"new","fork","resume"}`.
13
- *
14
- * If this test fails: do NOT add the call. Either drive the user-facing
15
- * action through the dashboard server (which prompts the user, who
16
- * triggers replacement via pi's UI), or wrap your post-switch work in
17
- * the `withSession` callback that pi 0.69+ exposes on each replacement
18
- * API and capture the freshly-emitted ReplacedSessionContext there.
19
- *
20
- * See change: pi-zero-seventy-compat.
21
- */
22
- import { describe, it, expect } from "vitest";
23
- import fs from "node:fs/promises";
24
- import path from "node:path";
25
- import url from "node:url";
26
-
27
- /**
28
- * Each pattern matches `<receiver>.<method>(` allowing for whitespace and
29
- * tolerating common variations like `await pi.newSession(...)`. Prefixed
30
- * with a non-word boundary so we don't flag method names embedded in
31
- * longer identifiers.
32
- */
33
- const PATTERNS: ReadonlyArray<{ name: string; re: RegExp }> = [
34
- { name: "pi.newSession", re: /(?:^|[^.\w])pi\.newSession\s*\(/ },
35
- { name: "ctx.fork", re: /(?:^|[^.\w])ctx\.fork\s*\(/ },
36
- { name: "ctx.switchSession", re: /(?:^|[^.\w])ctx\.switchSession\s*\(/ },
37
- ];
38
-
39
- /**
40
- * Per-line opt-out marker. Use only for documented exceptions (e.g. a
41
- * future migration cell that intentionally drives a replacement and
42
- * fully re-binds via `withSession`):
43
- * await pi.newSession({ withSession: ... }); // ban:session-replacement-ok
44
- */
45
- const OPT_OUT_MARKER = "ban:session-replacement-ok";
46
-
47
- async function* walk(dir: string): AsyncGenerator<string> {
48
- const entries = await fs.readdir(dir, { withFileTypes: true });
49
- for (const entry of entries) {
50
- const full = path.join(dir, entry.name);
51
- if (entry.isDirectory()) {
52
- if (entry.name === "node_modules" || entry.name === "dist" || entry.name === "__tests__") continue;
53
- yield* walk(full);
54
- } else if (entry.isFile() && /\.(ts|tsx|mts|cts)$/.test(entry.name)) {
55
- yield full;
56
- }
57
- }
58
- }
59
-
60
- describe("no session-replacement API calls in packages/extension/src/", () => {
61
- it("bridge code never invokes pi.newSession / ctx.fork / ctx.switchSession", async () => {
62
- const here = path.dirname(url.fileURLToPath(import.meta.url));
63
- const srcDir = path.resolve(here, "..");
64
- const repoRoot = path.resolve(here, "..", "..", "..", "..");
65
-
66
- const violations: Array<{ file: string; line: number; pattern: string; text: string }> = [];
67
-
68
- for await (const file of walk(srcDir)) {
69
- const content = await fs.readFile(file, "utf-8");
70
- const lines = content.split(/\r?\n/);
71
- lines.forEach((line, idx) => {
72
- if (line.includes(OPT_OUT_MARKER)) return;
73
- for (const { name, re } of PATTERNS) {
74
- if (re.test(line)) {
75
- violations.push({
76
- file: path.relative(repoRoot, file),
77
- line: idx + 1,
78
- pattern: name,
79
- text: line.trim(),
80
- });
81
- }
82
- }
83
- });
84
- }
85
-
86
- if (violations.length > 0) {
87
- const msg =
88
- `Bridge code MUST NOT call pi session-replacement APIs.\n` +
89
- `pi 0.69.0+ invalidates captured pre-replacement pi/ctx after these calls;\n` +
90
- `the bridge relies on pi being the sole originator of replacement so it can\n` +
91
- `re-capture state inside the resulting session_start handler.\n\n` +
92
- `Offenders (${violations.length}):\n` +
93
- violations
94
- .map((v) => ` ${v.file}:${v.line} [${v.pattern}] ${v.text}`)
95
- .join("\n");
96
- expect(violations, msg).toEqual([]);
97
- }
98
- });
99
- });
@@ -1,81 +0,0 @@
1
- /**
2
- * Repo-level invariant: `packages/extension/src/bridge.ts` MUST NOT
3
- * contain the co-occurrence of two substrings:
4
- *
5
- * 1. `originals.custom`
6
- * 2. `prompt.type === "multiselect"`
7
- *
8
- * If both appear in the same file, a contributor has (re)introduced the
9
- * TUI PromptBus-adapter multiselect arm that was removed by change
10
- * `fix-multiselect-tui-arm-self-cancel`. The arm is forbidden because
11
- * pi 0.70's RPC mode (the only mode dashboard headless sessions run
12
- * under) defines `ExtensionUIContext.custom` as an unconditional no-op
13
- * (`async custom() { return undefined; }`, see
14
- * `~/.nvm/.../@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.js`
15
- * lines 150-153). Awaiting that primitive resolves to `undefined`
16
- * synchronously, and the TUI arm's `bus.respond({ cancelled: true,
17
- * source: "tui" })` triggers the PromptBus's first-response-wins
18
- * dismissal — which auto-cancels the dashboard's already-rendered
19
- * `MultiselectRenderer` within ~1 event-loop tick.
20
- *
21
- * The bus-routed `(ctx.ui as any).multiselect = (...) => bus.request(...)`
22
- * patch site uses the substring `type: "multiselect"` (object-literal
23
- * shape), not `prompt.type === "multiselect"` (equality-check shape),
24
- * so it is unaffected by this lint.
25
- *
26
- * To remove a legitimate `originals.custom` reference (e.g. for a
27
- * future use that does not include multiselect prompt routing), keep
28
- * one substring and ensure the other does not co-occur.
29
- *
30
- * See change: fix-multiselect-tui-arm-self-cancel.
31
- */
32
- import { describe, it, expect } from "vitest";
33
- import fs from "node:fs/promises";
34
- import path from "node:path";
35
- import url from "node:url";
36
-
37
- const FORBIDDEN_A = "originals.custom";
38
- const FORBIDDEN_B = 'prompt.type === "multiselect"';
39
-
40
- function findLineNumbers(src: string, needle: string): number[] {
41
- const lines = src.split(/\r?\n/);
42
- const hits: number[] = [];
43
- lines.forEach((line, idx) => {
44
- if (line.includes(needle)) hits.push(idx + 1);
45
- });
46
- return hits;
47
- }
48
-
49
- describe("no TUI multiselect arm regression in bridge.ts", () => {
50
- it("bridge.ts MUST NOT contain both `originals.custom` and `prompt.type === \"multiselect\"`", async () => {
51
- const here = path.dirname(url.fileURLToPath(import.meta.url));
52
- const bridgePath = path.resolve(here, "..", "bridge.ts");
53
- const src = await fs.readFile(bridgePath, "utf-8");
54
-
55
- const hasA = src.includes(FORBIDDEN_A);
56
- const hasB = src.includes(FORBIDDEN_B);
57
-
58
- if (hasA && hasB) {
59
- const linesA = findLineNumbers(src, FORBIDDEN_A);
60
- const linesB = findLineNumbers(src, FORBIDDEN_B);
61
- const msg =
62
- `Forbidden co-occurrence in ${path.relative(process.cwd(), bridgePath)}:\n` +
63
- ` - "${FORBIDDEN_A}" found on line(s): ${linesA.join(", ")}\n` +
64
- ` - "${FORBIDDEN_B}" found on line(s): ${linesB.join(", ")}\n` +
65
- `\n` +
66
- `This pattern was removed by change "fix-multiselect-tui-arm-self-cancel".\n` +
67
- `pi 0.70 RPC mode's ctx.ui.custom is a no-op, so a TUI multiselect\n` +
68
- `arm that awaits originals.custom auto-cancels the dashboard-rendered\n` +
69
- `dialog within ~1 event-loop tick. The bus-routed ctx.ui.multiselect\n` +
70
- `patch + DashboardDefaultAdapter handle multiselect end-to-end without\n` +
71
- `any TUI arm participation. See:\n` +
72
- ` openspec/changes/archive/<date>-fix-multiselect-tui-arm-self-cancel/\n` +
73
- `(or openspec/changes/fix-multiselect-tui-arm-self-cancel/ if not yet archived).`;
74
- expect.fail(msg);
75
- }
76
-
77
- // Guardrail: at least one of the two substrings absent (we already
78
- // assert above that both-present is illegal). Either-alone is fine.
79
- expect(hasA && hasB).toBe(false);
80
- });
81
- });