@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,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
- });