@blackbelt-technology/pi-dashboard-extension 0.7.0 → 0.8.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 (216) hide show
  1. package/.pi/skills/browser/SKILL.md +28 -14
  2. package/.pi/skills/browser/UPSTREAM.md +10 -1
  3. package/.pi/skills/browser/references/electron.agent.md +57 -0
  4. package/.pi/skills/browser/references/own-browser.md +299 -0
  5. package/.pi/skills/browser/references/web.agent.md +323 -0
  6. package/.pi/skills/browser/scripts/check-panerelay.sh +157 -0
  7. package/.pi/skills/doctor/SKILL.md +3 -9
  8. package/.pi/skills/doctor/_lib/checks.ts +14 -68
  9. package/.pi/skills/doctor/_lib/derive-tokens.ts +1 -0
  10. package/.pi/skills/doctor/modules/apple-tools.knowledge.hash +1 -0
  11. package/.pi/skills/doctor/modules/apple-tools.md +51 -0
  12. package/.pi/skills/doctor/modules/oauth-redirect-base.knowledge.hash +1 -0
  13. package/.pi/skills/doctor/modules/oauth-redirect-base.md +71 -0
  14. package/.pi/skills/doctor/modules/pi-resolution.knowledge.hash +1 -1
  15. package/.pi/skills/doctor/modules/pi-resolution.md +21 -1
  16. package/.pi/skills/pi-dashboard/references/api-reference.agent.md +69 -0
  17. package/.pi/skills/project-init/SKILL.md +1 -7
  18. package/.pi/skills/project-init/dox-doctrine.md +42 -0
  19. package/.pi/skills/project-init/profiles/docs/profile.json +1 -1
  20. package/README.md +19 -0
  21. package/agents/DoxTriage.md +80 -0
  22. package/package.json +22 -11
  23. package/src/agent-settled.ts +27 -9
  24. package/src/auto-session-namer.ts +486 -70
  25. package/src/autostart-guard.ts +99 -0
  26. package/src/autostart-lock.ts +258 -0
  27. package/src/bridge-context.ts +86 -5
  28. package/src/bridge-ticket-client.ts +105 -0
  29. package/src/bridge.ts +917 -213
  30. package/src/command-handler.ts +332 -57
  31. package/src/connect-target.ts +130 -0
  32. package/src/connection.ts +371 -7
  33. package/src/endpoint-resolution.ts +221 -0
  34. package/src/flow-event-wiring.ts +125 -3
  35. package/src/followup-buffer.ts +217 -0
  36. package/src/instance-verification.ts +125 -0
  37. package/src/local-token-header.ts +44 -0
  38. package/src/model-refresh.ts +95 -0
  39. package/src/notify-proxy.ts +33 -0
  40. package/src/pi-env.d.ts +4 -0
  41. package/src/pi-retry-settings.ts +91 -0
  42. package/src/provider-register.ts +86 -21
  43. package/src/remote-registration-gate.ts +102 -0
  44. package/src/retry-tracker.ts +265 -86
  45. package/src/role-manager.ts +20 -0
  46. package/src/role-model-tools.ts +38 -3
  47. package/src/server-auto-start.ts +144 -2
  48. package/src/server-pin-store.ts +92 -0
  49. package/src/session-move.ts +275 -0
  50. package/src/session-sync.ts +24 -5
  51. package/src/subagent-forward-sites.ts +69 -0
  52. package/src/subagent-frame-buffer.ts +24 -3
  53. package/src/subagent-frame-strip.ts +109 -0
  54. package/src/subagent-tick-throttle.ts +250 -0
  55. package/src/transcript-backfill.ts +151 -0
  56. package/src/transcript-request-guard.ts +76 -0
  57. package/src/transport-diagnostics.ts +76 -0
  58. package/src/turn-actionability.ts +20 -0
  59. package/src/ui-stale-guard.ts +58 -0
  60. package/.pi/skills/doctor/AGENTS.md +0 -27
  61. package/src/AGENTS.md +0 -57
  62. package/src/__tests__/abort-latch.test.ts +0 -97
  63. package/src/__tests__/agent-settled.test.ts +0 -82
  64. package/src/__tests__/artifact-roots.test.ts +0 -83
  65. package/src/__tests__/ask-user-attachments.test.ts +0 -106
  66. package/src/__tests__/ask-user-schema-discriminator.test.ts +0 -141
  67. package/src/__tests__/ask-user-tool.test.ts +0 -571
  68. package/src/__tests__/auto-session-namer.test.ts +0 -339
  69. package/src/__tests__/bridge-default-model-apply.test.ts +0 -242
  70. package/src/__tests__/bridge-default-model-gate.test.ts +0 -50
  71. package/src/__tests__/bridge-entry-id-pi-070.test.ts +0 -174
  72. package/src/__tests__/bridge-followup-chat-order.test.ts +0 -215
  73. package/src/__tests__/bridge-followup-multi-entry.test.ts +0 -202
  74. package/src/__tests__/bridge-followup-mutation.test.ts +0 -217
  75. package/src/__tests__/bridge-followup-queue-drain.test.ts +0 -266
  76. package/src/__tests__/bridge-hasui-flip.test.ts +0 -109
  77. package/src/__tests__/bridge-no-queue-mutation.test.ts +0 -112
  78. package/src/__tests__/bridge-plugin-emit-event.test.ts +0 -44
  79. package/src/__tests__/bridge-queue-update-forward.test.ts +0 -77
  80. package/src/__tests__/bridge-resume-disconnect.test.ts +0 -333
  81. package/src/__tests__/bridge-shadow-queue-gate.test.ts +0 -299
  82. package/src/__tests__/bridge-shutdown-reset.test.ts +0 -159
  83. package/src/__tests__/bridge-slash-command-routing.test.ts +0 -458
  84. package/src/__tests__/bridge-stop-after-turn.test.ts +0 -72
  85. package/src/__tests__/bridge-system-followup.test.ts +0 -163
  86. package/src/__tests__/bridge-thinking-level-select.test.ts +0 -68
  87. package/src/__tests__/browser-skill-registered.test.ts +0 -84
  88. package/src/__tests__/build-provider-catalogue.test.ts +0 -210
  89. package/src/__tests__/command-handler.test.ts +0 -1180
  90. package/src/__tests__/commit-draft.test.ts +0 -100
  91. package/src/__tests__/connection-dropped-frames.test.ts +0 -78
  92. package/src/__tests__/connection-suppress-auto-start.test.ts +0 -97
  93. package/src/__tests__/connection.test.ts +0 -344
  94. package/src/__tests__/credentials-updated.test.ts +0 -26
  95. package/src/__tests__/custom-provider-apikey-roundtrip.test.ts +0 -128
  96. package/src/__tests__/cwd-missing-probe.test.ts +0 -82
  97. package/src/__tests__/dashboard-commands-shipped.test.ts +0 -53
  98. package/src/__tests__/dashboard-context-injector.test.ts +0 -190
  99. package/src/__tests__/dashboard-default-adapter.test.ts +0 -77
  100. package/src/__tests__/dev-build.test.ts +0 -79
  101. package/src/__tests__/doctor/checks.test.ts +0 -121
  102. package/src/__tests__/doctor/modules.test.ts +0 -64
  103. package/src/__tests__/doctor/provenance-hash.test.ts +0 -94
  104. package/src/__tests__/doctor/router.test.ts +0 -143
  105. package/src/__tests__/empty-actionable-guard-config.test.ts +0 -32
  106. package/src/__tests__/empty-actionable-guard.test.ts +0 -73
  107. package/src/__tests__/enrich-model-metadata.test.ts +0 -222
  108. package/src/__tests__/event-forwarder.test.ts +0 -119
  109. package/src/__tests__/extension-slash-command-detection.test.ts +0 -143
  110. package/src/__tests__/filter-enabled-models.test.ts +0 -151
  111. package/src/__tests__/fixtures/turn-actionability-fixtures.ts +0 -69
  112. package/src/__tests__/fork-entryid-timing.test.ts +0 -88
  113. package/src/__tests__/git-info-status.test.ts +0 -73
  114. package/src/__tests__/git-link-builder.test.ts +0 -102
  115. package/src/__tests__/git-poll.test.ts +0 -69
  116. package/src/__tests__/markdown-image-inliner.test.ts +0 -392
  117. package/src/__tests__/model-resolve.test.ts +0 -379
  118. package/src/__tests__/multiselect-dashboard-routing.test.ts +0 -203
  119. package/src/__tests__/multiselect-list.test.ts +0 -137
  120. package/src/__tests__/multiselect-polyfill.test.ts +0 -92
  121. package/src/__tests__/no-session-replacement-calls.test.ts +0 -99
  122. package/src/__tests__/no-tui-multiselect-arm-regression.test.ts +0 -81
  123. package/src/__tests__/openspec-activity-detector.test.ts +0 -337
  124. package/src/__tests__/openspec-cli-shim.test.ts +0 -145
  125. package/src/__tests__/openspec-poller.test.ts +0 -124
  126. package/src/__tests__/pi-version-tracker.test.ts +0 -109
  127. package/src/__tests__/process-metrics.test.ts +0 -47
  128. package/src/__tests__/process-scanner-kill.test.ts +0 -61
  129. package/src/__tests__/process-scanner.test.ts +0 -292
  130. package/src/__tests__/project-init-detect-stack.test.ts +0 -61
  131. package/src/__tests__/project-init-dox-kb-config.test.ts +0 -53
  132. package/src/__tests__/project-init-profiles.test.ts +0 -84
  133. package/src/__tests__/project-init-scaffold.test.ts +0 -139
  134. package/src/__tests__/project-init-seed-doctrine.test.ts +0 -100
  135. package/src/__tests__/project-trust.test.ts +0 -92
  136. package/src/__tests__/prompt-bus-wiring.test.ts +0 -791
  137. package/src/__tests__/prompt-bus.test.ts +0 -513
  138. package/src/__tests__/prompt-expander.test.ts +0 -398
  139. package/src/__tests__/provider-register-native-models.test.ts +0 -182
  140. package/src/__tests__/provider-register-reload.test.ts +0 -498
  141. package/src/__tests__/provider-register-thinking-levels.test.ts +0 -104
  142. package/src/__tests__/retry-tracker.test.ts +0 -152
  143. package/src/__tests__/role-manager.test.ts +0 -585
  144. package/src/__tests__/role-model-tools-registry-readiness.test.ts +0 -114
  145. package/src/__tests__/role-model-tools.test.ts +0 -229
  146. package/src/__tests__/search-files-completeness.test.ts +0 -111
  147. package/src/__tests__/search-files-ranking.test.ts +0 -168
  148. package/src/__tests__/server-auto-start.test.ts +0 -375
  149. package/src/__tests__/server-launcher-launch.test.ts +0 -96
  150. package/src/__tests__/server-launcher.test.ts +0 -101
  151. package/src/__tests__/server-probe.test.ts +0 -25
  152. package/src/__tests__/session-switch.test.ts +0 -139
  153. package/src/__tests__/session-sync.test.ts +0 -243
  154. package/src/__tests__/single-derivation-guard.test.ts +0 -39
  155. package/src/__tests__/source-detector.test.ts +0 -88
  156. package/src/__tests__/stats-extractor.test.ts +0 -92
  157. package/src/__tests__/subagent-frame-buffer.test.ts +0 -239
  158. package/src/__tests__/tool-result-image-inliner.test.ts +0 -206
  159. package/src/__tests__/tui-prompt-adapter.test.ts +0 -213
  160. package/src/__tests__/turn-actionability.test.ts +0 -86
  161. package/src/__tests__/ui-decorators.test.ts +0 -309
  162. package/src/__tests__/ui-modules.test.ts +0 -293
  163. package/src/__tests__/vcs-info.test.ts +0 -265
  164. package/src/__tests__/visibility-intent.test.ts +0 -43
  165. package/src/__tests__/watchdog.test.ts +0 -161
  166. package/src/abort-latch.ts.AGENTS.md +0 -3
  167. package/src/agent-settled.ts.AGENTS.md +0 -3
  168. package/src/artifact-roots.ts.AGENTS.md +0 -3
  169. package/src/ask-user-attachments.ts.AGENTS.md +0 -3
  170. package/src/ask-user-tool.ts.AGENTS.md +0 -3
  171. package/src/auto-session-namer.ts.AGENTS.md +0 -3
  172. package/src/bridge-context.ts.AGENTS.md +0 -3
  173. package/src/bridge-default-model-gate.ts.AGENTS.md +0 -3
  174. package/src/bridge.ts.AGENTS.md +0 -3
  175. package/src/command-handler.ts.AGENTS.md +0 -3
  176. package/src/commit-draft-agent.ts.AGENTS.md +0 -3
  177. package/src/commit-draft.ts.AGENTS.md +0 -3
  178. package/src/connection.ts.AGENTS.md +0 -3
  179. package/src/dashboard-context-injector.ts.AGENTS.md +0 -3
  180. package/src/dashboard-default-adapter.ts.AGENTS.md +0 -3
  181. package/src/dev-build.ts.AGENTS.md +0 -3
  182. package/src/empty-actionable-guard-config.ts.AGENTS.md +0 -3
  183. package/src/empty-actionable-guard.ts.AGENTS.md +0 -3
  184. package/src/event-forwarder.ts.AGENTS.md +0 -3
  185. package/src/flow-event-wiring.ts.AGENTS.md +0 -3
  186. package/src/git-link-builder.ts.AGENTS.md +0 -3
  187. package/src/git-poll.ts.AGENTS.md +0 -3
  188. package/src/hasui-flip.ts.AGENTS.md +0 -3
  189. package/src/markdown-image-inliner.ts.AGENTS.md +0 -3
  190. package/src/model-tracker.ts.AGENTS.md +0 -3
  191. package/src/multiselect-decode.ts.AGENTS.md +0 -3
  192. package/src/multiselect-list.ts.AGENTS.md +0 -3
  193. package/src/multiselect-polyfill.ts.AGENTS.md +0 -3
  194. package/src/openspec-cli-shim.ts.AGENTS.md +0 -7
  195. package/src/process-metrics.ts.AGENTS.md +0 -3
  196. package/src/process-scanner.ts.AGENTS.md +0 -3
  197. package/src/project-init/AGENTS.md +0 -12
  198. package/src/project-trust.ts.AGENTS.md +0 -3
  199. package/src/prompt-bus.ts.AGENTS.md +0 -3
  200. package/src/prompt-expander.ts.AGENTS.md +0 -3
  201. package/src/provider-register.ts.AGENTS.md +0 -3
  202. package/src/retry-tracker.ts.AGENTS.md +0 -3
  203. package/src/role-manager.ts.AGENTS.md +0 -3
  204. package/src/role-model-tools.ts.AGENTS.md +0 -3
  205. package/src/server-auto-start.ts.AGENTS.md +0 -3
  206. package/src/server-launcher.ts.AGENTS.md +0 -3
  207. package/src/session-sync.ts.AGENTS.md +0 -3
  208. package/src/slash-dispatch.ts.AGENTS.md +0 -3
  209. package/src/source-detector.ts.AGENTS.md +0 -3
  210. package/src/subagent-frame-buffer.ts.AGENTS.md +0 -3
  211. package/src/tool-result-image-inliner.ts.AGENTS.md +0 -3
  212. package/src/tui-prompt-adapter.ts.AGENTS.md +0 -3
  213. package/src/turn-actionability.ts.AGENTS.md +0 -3
  214. package/src/ui-modules.ts.AGENTS.md +0 -3
  215. package/src/vcs-info.ts.AGENTS.md +0 -3
  216. package/src/visibility-intent.ts.AGENTS.md +0 -3
@@ -1,513 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
- import { PromptBus, type PromptAdapter, type PromptRequest, type PromptResponse } from "../prompt-bus.js";
3
-
4
- function createMockAdapter(name: string, claim: any = {}) {
5
- return {
6
- name,
7
- onRequest: vi.fn().mockReturnValue(claim) as any,
8
- onResponse: vi.fn() as any,
9
- onCancel: vi.fn() as any,
10
- } satisfies PromptAdapter;
11
- }
12
-
13
- describe("PromptBus", () => {
14
- let bus: PromptBus;
15
- let onDashboardRequest: any;
16
- let onDashboardDismiss: any;
17
- let onDashboardCancel: any;
18
-
19
- beforeEach(() => {
20
- vi.useFakeTimers();
21
- onDashboardRequest = vi.fn() as any;
22
- onDashboardDismiss = vi.fn() as any;
23
- onDashboardCancel = vi.fn() as any;
24
- bus = new PromptBus({
25
- timeoutMs: 5000,
26
- onDashboardRequest,
27
- onDashboardDismiss,
28
- onDashboardCancel,
29
- });
30
- });
31
-
32
- afterEach(() => {
33
- vi.useRealTimers();
34
- });
35
-
36
- describe("adapter registration", () => {
37
- it("should register an adapter", () => {
38
- const adapter = createMockAdapter("test");
39
- bus.registerAdapter(adapter);
40
- expect(bus.adapterNames).toEqual(["test"]);
41
- });
42
-
43
- it("should replace adapter with same name on re-registration", () => {
44
- const adapter1 = createMockAdapter("test");
45
- const adapter2 = createMockAdapter("test");
46
- bus.registerAdapter(adapter1);
47
- bus.registerAdapter(adapter2);
48
- expect(bus.adapterNames).toEqual(["test"]);
49
-
50
- // Verify new adapter is used
51
- bus.request({ pipeline: "command", type: "select", question: "Pick:", options: ["A"] });
52
- expect(adapter2.onRequest).toHaveBeenCalled();
53
- expect(adapter1.onRequest).not.toHaveBeenCalled();
54
- });
55
-
56
- it("should unregister adapter via returned function", () => {
57
- const adapter = createMockAdapter("test");
58
- const unsub = bus.registerAdapter(adapter);
59
- expect(bus.adapterNames).toEqual(["test"]);
60
- unsub();
61
- expect(bus.adapterNames).toEqual([]);
62
- });
63
-
64
- it("should support multiple adapters", () => {
65
- bus.registerAdapter(createMockAdapter("a"));
66
- bus.registerAdapter(createMockAdapter("b"));
67
- expect(bus.adapterNames).toEqual(["a", "b"]);
68
- });
69
- });
70
-
71
- describe("request distribution", () => {
72
- it("should call onRequest on all registered adapters", () => {
73
- const a = createMockAdapter("a");
74
- const b = createMockAdapter("b");
75
- bus.registerAdapter(a);
76
- bus.registerAdapter(b);
77
-
78
- bus.request({ pipeline: "command", type: "select", question: "Pick:", options: ["A", "B"] });
79
-
80
- expect(a.onRequest).toHaveBeenCalledWith(expect.objectContaining({
81
- pipeline: "command",
82
- type: "select",
83
- question: "Pick:",
84
- options: ["A", "B"],
85
- }));
86
- expect(b.onRequest).toHaveBeenCalledWith(expect.objectContaining({
87
- pipeline: "command",
88
- }));
89
- });
90
-
91
- it("should generate a unique id for each request", () => {
92
- const adapter = createMockAdapter("a");
93
- bus.registerAdapter(adapter);
94
-
95
- bus.request({ pipeline: "command", type: "select", question: "Q1", options: ["A"] });
96
- bus.request({ pipeline: "command", type: "select", question: "Q2", options: ["B"] });
97
-
98
- const id1 = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
99
- const id2 = (adapter.onRequest.mock.calls[1][0] as PromptRequest).id;
100
- expect(id1).not.toBe(id2);
101
- });
102
-
103
- it("should send prompt_request to dashboard with custom component if claimed", () => {
104
- const adapter = createMockAdapter("arch", {
105
- component: { type: "architect-prompt", props: { foo: 1 } },
106
- placement: "widget-bar",
107
- });
108
- bus.registerAdapter(adapter);
109
-
110
- bus.request({ pipeline: "architect-new", type: "select", question: "Save?", options: ["Save", "Cancel"] });
111
-
112
- expect(onDashboardRequest).toHaveBeenCalledWith(
113
- expect.objectContaining({ question: "Save?" }),
114
- { type: "architect-prompt", props: { foo: 1 } },
115
- "widget-bar",
116
- );
117
- });
118
-
119
- it("should fall back to generic-dialog when no adapter claims with component", () => {
120
- const adapter = createMockAdapter("tui", {}); // no component
121
- bus.registerAdapter(adapter);
122
-
123
- bus.request({ pipeline: "command", type: "select", question: "Pick:", options: ["A"] });
124
-
125
- expect(onDashboardRequest).toHaveBeenCalledWith(
126
- expect.objectContaining({ question: "Pick:" }),
127
- expect.objectContaining({ type: "generic-dialog" }),
128
- "inline",
129
- );
130
- });
131
-
132
- it("should use first adapter's component when multiple claim", () => {
133
- const a = createMockAdapter("a", {
134
- component: { type: "custom-a", props: {} },
135
- placement: "widget-bar",
136
- });
137
- const b = createMockAdapter("b", {
138
- component: { type: "custom-b", props: {} },
139
- placement: "inline",
140
- });
141
- bus.registerAdapter(a);
142
- bus.registerAdapter(b);
143
-
144
- bus.request({ pipeline: "test", type: "select", question: "Q", options: [] });
145
-
146
- expect(onDashboardRequest).toHaveBeenCalledWith(
147
- expect.anything(),
148
- expect.objectContaining({ type: "custom-a" }),
149
- "widget-bar",
150
- );
151
- });
152
-
153
- it("should skip adapters that return null", () => {
154
- const a = createMockAdapter("a");
155
- a.onRequest.mockReturnValue(null);
156
- const b = createMockAdapter("b", {});
157
- bus.registerAdapter(a);
158
- bus.registerAdapter(b);
159
-
160
- bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
161
-
162
- // Should still send to dashboard (generic fallback since b has no component)
163
- expect(onDashboardRequest).toHaveBeenCalled();
164
- });
165
-
166
- it("should handle adapter onRequest throwing without breaking", () => {
167
- const bad = createMockAdapter("bad");
168
- bad.onRequest.mockImplementation(() => { throw new Error("boom"); });
169
- const good = createMockAdapter("good", {});
170
- bus.registerAdapter(bad);
171
- bus.registerAdapter(good);
172
-
173
- bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
174
-
175
- expect(good.onRequest).toHaveBeenCalled();
176
- });
177
- });
178
-
179
- describe("first-response-wins", () => {
180
- it("should resolve with first response", async () => {
181
- const adapter = createMockAdapter("a");
182
- bus.registerAdapter(adapter);
183
-
184
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: ["A"] });
185
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
186
-
187
- bus.respond({ id, answer: "A", source: "a" });
188
-
189
- const result = await promise;
190
- expect(result).toEqual({ id, answer: "A", source: "a" });
191
- });
192
-
193
- it("should ignore second response for same prompt", async () => {
194
- const adapter = createMockAdapter("a");
195
- bus.registerAdapter(adapter);
196
-
197
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: ["A", "B"] });
198
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
199
-
200
- bus.respond({ id, answer: "A", source: "tui" });
201
- bus.respond({ id, answer: "B", source: "dashboard" }); // late, ignored
202
-
203
- const result = await promise;
204
- expect(result.answer).toBe("A");
205
- expect(result.source).toBe("tui");
206
- });
207
-
208
- it("should remove from pending after response", async () => {
209
- const adapter = createMockAdapter("a");
210
- bus.registerAdapter(adapter);
211
-
212
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
213
- expect(bus.pendingCount).toBe(1);
214
-
215
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
216
- bus.respond({ id, answer: "A", source: "a" });
217
- await promise;
218
-
219
- expect(bus.pendingCount).toBe(0);
220
- });
221
- });
222
-
223
- describe("cross-adapter dismissal", () => {
224
- it("should call onResponse on all adapters when one responds", async () => {
225
- const a = createMockAdapter("a");
226
- const b = createMockAdapter("b");
227
- bus.registerAdapter(a);
228
- bus.registerAdapter(b);
229
-
230
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
231
- const id = (a.onRequest.mock.calls[0][0] as PromptRequest).id;
232
-
233
- bus.respond({ id, answer: "X", source: "a" });
234
- await promise;
235
-
236
- expect(a.onResponse).toHaveBeenCalledWith({ id, answer: "X", source: "a" });
237
- expect(b.onResponse).toHaveBeenCalledWith({ id, answer: "X", source: "a" });
238
- });
239
-
240
- it("should send dashboard dismiss on response", async () => {
241
- const adapter = createMockAdapter("a");
242
- bus.registerAdapter(adapter);
243
-
244
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
245
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
246
-
247
- bus.respond({ id, answer: "A", source: "tui" });
248
- await promise;
249
-
250
- expect(onDashboardDismiss).toHaveBeenCalledWith(id);
251
- });
252
- });
253
-
254
- describe("cancellation", () => {
255
- it("should resolve with cancelled when cancel is called", async () => {
256
- const adapter = createMockAdapter("a");
257
- bus.registerAdapter(adapter);
258
-
259
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
260
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
261
-
262
- bus.cancel(id);
263
-
264
- const result = await promise;
265
- expect(result.cancelled).toBe(true);
266
- });
267
-
268
- it("should call onCancel on all adapters", async () => {
269
- const a = createMockAdapter("a");
270
- const b = createMockAdapter("b");
271
- bus.registerAdapter(a);
272
- bus.registerAdapter(b);
273
-
274
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
275
- const id = (a.onRequest.mock.calls[0][0] as PromptRequest).id;
276
-
277
- bus.cancel(id);
278
- await promise;
279
-
280
- expect(a.onCancel).toHaveBeenCalledWith(id);
281
- expect(b.onCancel).toHaveBeenCalledWith(id);
282
- });
283
-
284
- it("should send dashboard cancel on cancel", async () => {
285
- const adapter = createMockAdapter("a");
286
- bus.registerAdapter(adapter);
287
-
288
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
289
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
290
-
291
- bus.cancel(id);
292
- await promise;
293
-
294
- expect(onDashboardCancel).toHaveBeenCalledWith(id);
295
- });
296
-
297
- it("should be a no-op when cancelling already-resolved prompt", () => {
298
- const adapter = createMockAdapter("a");
299
- bus.registerAdapter(adapter);
300
-
301
- bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
302
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
303
-
304
- bus.respond({ id, answer: "A", source: "a" });
305
- bus.cancel(id); // no-op, no error
306
-
307
- expect(adapter.onCancel).not.toHaveBeenCalled();
308
- });
309
- });
310
-
311
- describe("timeout", () => {
312
- it("should cancel prompt after timeout", async () => {
313
- const adapter = createMockAdapter("a");
314
- bus.registerAdapter(adapter);
315
-
316
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
317
-
318
- vi.advanceTimersByTime(5000);
319
-
320
- const result = await promise;
321
- expect(result.cancelled).toBe(true);
322
- expect(adapter.onCancel).toHaveBeenCalled();
323
- });
324
-
325
- it("should not timeout if answered before deadline", async () => {
326
- const adapter = createMockAdapter("a");
327
- bus.registerAdapter(adapter);
328
-
329
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
330
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
331
-
332
- vi.advanceTimersByTime(2000);
333
- bus.respond({ id, answer: "A", source: "a" });
334
-
335
- const result = await promise;
336
- expect(result.answer).toBe("A");
337
- expect(result.cancelled).toBeUndefined();
338
-
339
- // Advance past timeout — should be no-op
340
- vi.advanceTimersByTime(5000);
341
- expect(adapter.onCancel).not.toHaveBeenCalled();
342
- });
343
-
344
- it("should never timeout when timeoutMs is -1 (infinite)", async () => {
345
- const infiniteBus = new PromptBus({
346
- timeoutMs: -1,
347
- onDashboardRequest,
348
- onDashboardDismiss,
349
- onDashboardCancel,
350
- });
351
- const adapter = createMockAdapter("a");
352
- infiniteBus.registerAdapter(adapter);
353
-
354
- const promise = infiniteBus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
355
-
356
- // Advance way past the default 5-minute timeout
357
- vi.advanceTimersByTime(10 * 60 * 1000);
358
-
359
- // Still pending — no cancellation fired
360
- expect(adapter.onCancel).not.toHaveBeenCalled();
361
- expect(infiniteBus.pendingCount).toBe(1);
362
-
363
- // Can still be answered normally
364
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
365
- infiniteBus.respond({ id, answer: "late", source: "a" });
366
- const result = await promise;
367
- expect(result.answer).toBe("late");
368
- expect(result.cancelled).toBeUndefined();
369
- });
370
-
371
- it("should never timeout when timeoutMs is 0 (also treated as infinite)", async () => {
372
- const infiniteBus = new PromptBus({
373
- timeoutMs: 0,
374
- onDashboardRequest,
375
- onDashboardDismiss,
376
- onDashboardCancel,
377
- });
378
- const adapter = createMockAdapter("a");
379
- infiniteBus.registerAdapter(adapter);
380
-
381
- infiniteBus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
382
-
383
- vi.advanceTimersByTime(10 * 60 * 1000);
384
- expect(adapter.onCancel).not.toHaveBeenCalled();
385
- expect(infiniteBus.pendingCount).toBe(1);
386
- });
387
- });
388
-
389
- describe("concurrent prompts", () => {
390
- it("should handle multiple pending prompts independently", async () => {
391
- const adapter = createMockAdapter("a");
392
- bus.registerAdapter(adapter);
393
-
394
- const promise1 = bus.request({ pipeline: "command", type: "select", question: "Q1", options: ["A"] });
395
- const promise2 = bus.request({ pipeline: "architect-new", type: "input", question: "Q2" });
396
-
397
- expect(bus.pendingCount).toBe(2);
398
-
399
- const id1 = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
400
- const id2 = (adapter.onRequest.mock.calls[1][0] as PromptRequest).id;
401
-
402
- bus.respond({ id: id1, answer: "A", source: "tui" });
403
-
404
- const result1 = await promise1;
405
- expect(result1.answer).toBe("A");
406
- expect(bus.pendingCount).toBe(1);
407
-
408
- bus.respond({ id: id2, answer: "guidance", source: "dashboard" });
409
-
410
- const result2 = await promise2;
411
- expect(result2.answer).toBe("guidance");
412
- expect(bus.pendingCount).toBe(0);
413
- });
414
-
415
- it("should not dismiss other prompts when one is answered", async () => {
416
- const adapter = createMockAdapter("a");
417
- bus.registerAdapter(adapter);
418
-
419
- bus.request({ pipeline: "command", type: "select", question: "Q1", options: [] });
420
- bus.request({ pipeline: "command", type: "select", question: "Q2", options: [] });
421
-
422
- const id1 = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
423
-
424
- bus.respond({ id: id1, answer: "A", source: "tui" });
425
-
426
- // Second prompt should still be pending
427
- expect(bus.pendingCount).toBe(1);
428
- });
429
- });
430
-
431
- describe("respond with unknown id", () => {
432
- it("should silently ignore response for unknown prompt id", () => {
433
- bus.respond({ id: "nonexistent", answer: "A", source: "tui" });
434
- // No error
435
- });
436
- });
437
-
438
- describe("getPendingRequests", () => {
439
- it("should return empty array when no prompts are pending", () => {
440
- expect(bus.getPendingRequests()).toEqual([]);
441
- });
442
-
443
- it("should return pending prompt with resolved component", () => {
444
- const adapter = createMockAdapter("a", {
445
- component: { type: "custom-ui", props: { x: 1 } },
446
- placement: "widget-bar",
447
- });
448
- bus.registerAdapter(adapter);
449
-
450
- bus.request({ pipeline: "command", type: "select", question: "Pick:", options: ["A"] });
451
-
452
- const pending = bus.getPendingRequests();
453
- expect(pending).toHaveLength(1);
454
- expect(pending[0].request).toEqual(expect.objectContaining({
455
- pipeline: "command",
456
- type: "select",
457
- question: "Pick:",
458
- }));
459
- expect(pending[0].component).toEqual({ type: "custom-ui", props: { x: 1 } });
460
- expect(pending[0].placement).toBe("widget-bar");
461
- });
462
-
463
- it("should return generic-dialog component when no adapter claims with component", () => {
464
- const adapter = createMockAdapter("tui", {}); // no component
465
- bus.registerAdapter(adapter);
466
-
467
- bus.request({ pipeline: "command", type: "select", question: "Pick:", options: ["A"] });
468
-
469
- const pending = bus.getPendingRequests();
470
- expect(pending).toHaveLength(1);
471
- expect(pending[0].component.type).toBe("generic-dialog");
472
- expect(pending[0].placement).toBe("inline");
473
- });
474
-
475
- it("should omit resolved prompts", async () => {
476
- const adapter = createMockAdapter("a");
477
- bus.registerAdapter(adapter);
478
-
479
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
480
- expect(bus.getPendingRequests()).toHaveLength(1);
481
-
482
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
483
- bus.respond({ id, answer: "A", source: "a" });
484
- await promise;
485
-
486
- expect(bus.getPendingRequests()).toEqual([]);
487
- });
488
-
489
- it("should omit cancelled prompts", async () => {
490
- const adapter = createMockAdapter("a");
491
- bus.registerAdapter(adapter);
492
-
493
- const promise = bus.request({ pipeline: "command", type: "select", question: "Q", options: [] });
494
- expect(bus.getPendingRequests()).toHaveLength(1);
495
-
496
- const id = (adapter.onRequest.mock.calls[0][0] as PromptRequest).id;
497
- bus.cancel(id);
498
- await promise;
499
-
500
- expect(bus.getPendingRequests()).toEqual([]);
501
- });
502
-
503
- it("should return multiple pending prompts", () => {
504
- const adapter = createMockAdapter("a");
505
- bus.registerAdapter(adapter);
506
-
507
- bus.request({ pipeline: "command", type: "select", question: "Q1", options: ["A"] });
508
- bus.request({ pipeline: "command", type: "input", question: "Q2" });
509
-
510
- expect(bus.getPendingRequests()).toHaveLength(2);
511
- });
512
- });
513
- });