@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,458 +0,0 @@
1
- /**
2
- * Regression test pinning the slash-command routing contract.
3
- * Drives `command-handler.handle({type:"send_prompt"...})` against a stub pi
4
- * and asserts the call counts + emitted command_feedback events from
5
- * `design.md` Decision 5 table.
6
- *
7
- * regression: see openspec/changes/fix-extension-slash-commands-in-dashboard/
8
- */
9
- import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
10
- import { createCommandHandler } from "../command-handler.js";
11
- import { hasDispatchCommand } from "../bridge-context.js";
12
- import { tryDispatchExtensionCommand, type DispatchConnection } from "../slash-dispatch.js";
13
- import type { ExtensionToServerMessage } from "@blackbelt-technology/pi-dashboard-shared/protocol.js";
14
-
15
- interface StubOpts {
16
- withDispatch?: boolean;
17
- dispatchRejects?: Error;
18
- getCommandsThrows?: boolean;
19
- commands?: Array<{ name: string; source: string }>;
20
- }
21
-
22
- function makeStubPi(opts: StubOpts = {}) {
23
- const dispatchCommand = opts.withDispatch
24
- ? vi.fn(async (_text: string, _options?: any) => {
25
- if (opts.dispatchRejects) throw opts.dispatchRejects;
26
- })
27
- : undefined;
28
- const sendUserMessage = vi.fn();
29
- const setSessionName = vi.fn();
30
- const events = { emit: vi.fn() };
31
- const getCommands = vi.fn(() => {
32
- if (opts.getCommandsThrows) throw new Error("stale ctx");
33
- return opts.commands ?? [
34
- { name: "ctx-stats", source: "extension" },
35
- { name: "skill:foo", source: "skill" },
36
- { name: "review", source: "prompt" },
37
- { name: "__dashboard_reload", source: "extension" },
38
- ];
39
- });
40
- const pi: any = {
41
- sendUserMessage,
42
- getCommands,
43
- setSessionName,
44
- events,
45
- };
46
- if (dispatchCommand) pi.dispatchCommand = dispatchCommand;
47
- return { pi, sendUserMessage, dispatchCommand, getCommands, events };
48
- }
49
-
50
- function feedbackEvents(sink: ReturnType<typeof vi.fn>, command: string) {
51
- return sink.mock.calls
52
- .map((c) => c[0] as ExtensionToServerMessage)
53
- .filter(
54
- (m) =>
55
- m.type === "event_forward" &&
56
- (m as any).event?.eventType === "command_feedback" &&
57
- ((m as any).event?.data?.command === command),
58
- )
59
- .map((m) => (m as any).event.data);
60
- }
61
-
62
- async function drive(text: string, stub: ReturnType<typeof makeStubPi>, delivery?: "steer" | "followUp") {
63
- const sink = vi.fn();
64
- const handler = createCommandHandler(stub.pi as any, "s1", { eventSink: sink });
65
- await handler.handle({ type: "send_prompt", sessionId: "s1", text, delivery } as any);
66
- return sink;
67
- }
68
-
69
- describe("bridge slash command routing (regression contract)", () => {
70
- it("extension cmd with dispatchCommand → dispatch called, no sendUserMessage, started+completed", async () => {
71
- // regression: see openspec/changes/fix-extension-slash-commands-in-dashboard/
72
- const stub = makeStubPi({ withDispatch: true });
73
- const sink = await drive("/ctx-stats", stub);
74
-
75
- expect(stub.dispatchCommand).toHaveBeenCalledTimes(1);
76
- expect(stub.dispatchCommand).toHaveBeenCalledWith("/ctx-stats", { streamingBehavior: "followUp" });
77
- expect(stub.sendUserMessage).not.toHaveBeenCalled();
78
-
79
- const evs = feedbackEvents(sink, "/ctx-stats");
80
- expect(evs.map((e) => e.status)).toEqual(["started", "completed"]);
81
- });
82
-
83
- it("extension cmd with delivery: steer → dispatchCommand called with streamingBehavior: steer", async () => {
84
- const stub = makeStubPi({ withDispatch: true });
85
- const sink = await drive("/ctx-stats", stub, "steer");
86
-
87
- expect(stub.dispatchCommand).toHaveBeenCalledTimes(1);
88
- expect(stub.dispatchCommand).toHaveBeenCalledWith("/ctx-stats", { streamingBehavior: "steer" });
89
- expect(stub.sendUserMessage).not.toHaveBeenCalled();
90
-
91
- const evs = feedbackEvents(sink, "/ctx-stats");
92
- expect(evs.map((e) => e.status)).toEqual(["started", "completed"]);
93
- });
94
-
95
- it("extension cmd, NO dispatchCommand, not headless → error feedback with session-shape hint, no sendUserMessage", async () => {
96
- // Path D: extension commands cannot be dispatched for non-headless sessions.
97
- // Emits error with hint explaining tmux / wt own pi's stdin.
98
- // See change: fix-slash-dispatch-delivery, enable-rpc-keeper-by-default.
99
- const stub = makeStubPi({ withDispatch: false });
100
- const sink = await drive("/ctx-stats", stub);
101
-
102
- // sendUserMessage is NOT called — the command is handled (with error).
103
- expect(stub.sendUserMessage).not.toHaveBeenCalled();
104
-
105
- // Error feedback emitted with session-shape hint.
106
- const evs = feedbackEvents(sink, "/ctx-stats");
107
- expect(evs.map((e) => e.status)).toEqual(["error"]);
108
- expect(evs[0].message).toContain("session shape");
109
- });
110
-
111
- it("extension cmd dispatch rejects → started+error with err.message, no sendUserMessage", async () => {
112
- const stub = makeStubPi({ withDispatch: true, dispatchRejects: new Error("boom") });
113
- const sink = await drive("/ctx-stats", stub);
114
-
115
- expect(stub.dispatchCommand).toHaveBeenCalledTimes(1);
116
- expect(stub.sendUserMessage).not.toHaveBeenCalled();
117
-
118
- const evs = feedbackEvents(sink, "/ctx-stats");
119
- expect(evs.map((e) => e.status)).toEqual(["started", "error"]);
120
- expect(evs[1].message).toBe("boom");
121
- });
122
-
123
- it("skill command → no dispatch, sendUserMessage called once, no command_feedback", async () => {
124
- const stub = makeStubPi({ withDispatch: true });
125
- const sink = await drive("/skill:foo", stub);
126
-
127
- expect(stub.dispatchCommand).not.toHaveBeenCalled();
128
- expect(stub.sendUserMessage).toHaveBeenCalledTimes(1);
129
-
130
- expect(feedbackEvents(sink, "/skill:foo")).toEqual([]);
131
- });
132
-
133
- it("prompt template → no dispatch, sendUserMessage called once, no command_feedback", async () => {
134
- const stub = makeStubPi({ withDispatch: true });
135
- const sink = await drive("/review", stub);
136
-
137
- expect(stub.dispatchCommand).not.toHaveBeenCalled();
138
- expect(stub.sendUserMessage).toHaveBeenCalledTimes(1);
139
- expect(feedbackEvents(sink, "/review")).toEqual([]);
140
- });
141
-
142
- it("passthrough text → no dispatch, sendUserMessage called once, no command_feedback", async () => {
143
- const stub = makeStubPi({ withDispatch: true });
144
- const sink = await drive("hello world", stub);
145
-
146
- expect(stub.dispatchCommand).not.toHaveBeenCalled();
147
- expect(stub.sendUserMessage).toHaveBeenCalledTimes(1);
148
- });
149
-
150
- it("unrecognized slash → no dispatch, sendUserMessage called once, no command_feedback", async () => {
151
- const stub = makeStubPi({ withDispatch: true });
152
- const sink = await drive("/totally-unknown-command", stub);
153
-
154
- expect(stub.dispatchCommand).not.toHaveBeenCalled();
155
- expect(stub.sendUserMessage).toHaveBeenCalledTimes(1);
156
- expect(feedbackEvents(sink, "/totally-unknown-command")).toEqual([]);
157
- });
158
-
159
- it("bridge-native /__dashboard_reload → no dispatch, no error feedback, sendUserMessage fallback", async () => {
160
- const stub = makeStubPi({ withDispatch: true });
161
- const sink = await drive("/__dashboard_reload", stub);
162
-
163
- expect(stub.dispatchCommand).not.toHaveBeenCalled();
164
- // It IS in the command list with source: extension, but DASHBOARD_NATIVE_COMMANDS
165
- // / __-prefix exclusion suppresses it. The slash branch falls through to sendUserMessage.
166
- expect(stub.sendUserMessage).toHaveBeenCalledTimes(1);
167
- expect(feedbackEvents(sink, "/__dashboard_reload")).toEqual([]);
168
- });
169
-
170
- it("getCommands throws → no crash, no command_feedback, sendUserMessage fallback fires", async () => {
171
- const stub = makeStubPi({ withDispatch: true, getCommandsThrows: true });
172
- const sink = await drive("/ctx-stats", stub);
173
-
174
- expect(stub.dispatchCommand).not.toHaveBeenCalled();
175
- // helper returns false on throw → caller falls through to sendUserMessage path
176
- expect(stub.sendUserMessage).toHaveBeenCalledTimes(1);
177
- expect(feedbackEvents(sink, "/ctx-stats")).toEqual([]);
178
- });
179
-
180
- it("never duplicates command_feedback on dispatch path (success)", async () => {
181
- const stub = makeStubPi({ withDispatch: true });
182
- const sink = await drive("/ctx-stats", stub);
183
- const evs = feedbackEvents(sink, "/ctx-stats");
184
- expect(evs.filter((e) => e.status === "started")).toHaveLength(1);
185
- expect(evs.filter((e) => e.status === "completed" || e.status === "error")).toHaveLength(1);
186
- });
187
-
188
- it("error feedback on fallthrough path (dispatchCommand absent, non-headless)", async () => {
189
- // Path D returns true with error feedback (including rpc-keeper hint).
190
- // See change: fix-slash-dispatch-delivery.
191
- const stub = makeStubPi({ withDispatch: false });
192
- const sink = await drive("/ctx-stats", stub);
193
- const evs = feedbackEvents(sink, "/ctx-stats");
194
- expect(evs).toHaveLength(1);
195
- expect(evs[0].status).toBe("error");
196
- expect(evs[0].message).toContain("session shape");
197
- });
198
-
199
- it("anti-regression: /ctx-stats does NOT reach sendUserMessage when dispatchCommand absent", async () => {
200
- // Path D now emits error feedback instead of falling through silently.
201
- // Extension commands can only be dispatched for headless sessions with
202
- // the RPC keeper enabled. See change: fix-slash-dispatch-delivery.
203
- const stub = makeStubPi({ withDispatch: false });
204
- const sink = await drive("/ctx-stats", stub);
205
- // sendUserMessage is NOT called — command handled with error feedback.
206
- expect(stub.sendUserMessage).not.toHaveBeenCalled();
207
- const evs = feedbackEvents(sink, "/ctx-stats");
208
- expect(evs).toHaveLength(1);
209
- expect(evs[0].status).toBe("error");
210
- });
211
- });
212
-
213
- // See change: add-rpc-stdin-dispatch-with-keeper-sidecar (task 7.7 + 9.1).
214
- // Direct-driver tests for tryDispatchExtensionCommand covering the
215
- // three-way decision (Paths B / C / D) and asserting mutual exclusion:
216
- // for any single dispatch, EXACTLY ONE of (pi.dispatchCommand call,
217
- // connection.send dispatch_extension_command, sink error feedback) fires.
218
- describe("tryDispatchExtensionCommand: Path B/C/D mutual exclusion", () => {
219
- const ORIGINAL_ENV_FLAG = process.env.PI_DASHBOARD_SPAWNED;
220
- const ORIGINAL_ARGV = process.argv;
221
-
222
- function setHeadless(headless: boolean) {
223
- if (headless) {
224
- process.env.PI_DASHBOARD_SPAWNED = "1";
225
- process.argv = ["node", "pi", "--mode", "rpc"];
226
- } else {
227
- delete process.env.PI_DASHBOARD_SPAWNED;
228
- process.argv = ["node", "pi"];
229
- }
230
- }
231
-
232
- beforeEach(() => { setHeadless(false); });
233
- afterEach(() => {
234
- if (ORIGINAL_ENV_FLAG === undefined) delete process.env.PI_DASHBOARD_SPAWNED;
235
- else process.env.PI_DASHBOARD_SPAWNED = ORIGINAL_ENV_FLAG;
236
- process.argv = ORIGINAL_ARGV;
237
- });
238
-
239
- function makePi(opts: { withDispatch?: boolean } = {}) {
240
- const dispatchCommand = opts.withDispatch ? vi.fn(async () => undefined) : undefined;
241
- const getCommands = vi.fn(() => [{ name: "ctx-stats", source: "extension" }]);
242
- const pi: any = { getCommands };
243
- if (dispatchCommand) pi.dispatchCommand = dispatchCommand;
244
- return { pi, dispatchCommand };
245
- }
246
-
247
- function makeConn(): { conn: DispatchConnection; sent: ExtensionToServerMessage[] } {
248
- const sent: ExtensionToServerMessage[] = [];
249
- return { conn: { send: (m) => sent.push(m) }, sent };
250
- }
251
-
252
- it("Path B: pi.dispatchCommand present → dispatch called; no connection.send; sink gets started+completed", async () => {
253
- const { pi, dispatchCommand } = makePi({ withDispatch: true });
254
- const sink = vi.fn();
255
- const { conn, sent } = makeConn();
256
- setHeadless(true); // headless detection irrelevant when dispatchCommand exists
257
-
258
- const handled = await tryDispatchExtensionCommand(pi, "/ctx-stats", "sid", sink, conn);
259
- expect(handled).toBe(true);
260
- expect(dispatchCommand).toHaveBeenCalledTimes(1);
261
- expect(sent.filter((m) => m.type === "dispatch_extension_command")).toEqual([]);
262
- const evs = sink.mock.calls
263
- .map((c: any[]) => c[0])
264
- .filter((m: any) => m?.event?.eventType === "command_feedback")
265
- .map((m: any) => m.event.data.status);
266
- expect(evs).toEqual(["started", "completed"]);
267
- });
268
-
269
- it("Path C: no dispatchCommand + headless + connection → dispatch_extension_command emitted; no terminal feedback from bridge", async () => {
270
- const { pi, dispatchCommand } = makePi({ withDispatch: false });
271
- expect(dispatchCommand).toBeUndefined();
272
- const sink = vi.fn();
273
- const { conn, sent } = makeConn();
274
- setHeadless(true);
275
-
276
- const handled = await tryDispatchExtensionCommand(pi, "/ctx-stats", "sid-abc", sink, conn);
277
- expect(handled).toBe(true);
278
-
279
- // Exactly one dispatch_extension_command emission with the right shape.
280
- const dispatches = sent.filter((m): m is Extract<ExtensionToServerMessage, { type: "dispatch_extension_command" }> =>
281
- m.type === "dispatch_extension_command");
282
- expect(dispatches).toHaveLength(1);
283
- expect(dispatches[0].sessionId).toBe("sid-abc");
284
- expect(dispatches[0].command).toBe("/ctx-stats");
285
- expect(typeof dispatches[0].requestId).toBe("string");
286
- expect(dispatches[0].requestId.length).toBeGreaterThan(0);
287
-
288
- // Bridge emitted started ONLY — server is responsible for the terminal event.
289
- const evs = sink.mock.calls
290
- .map((c: any[]) => c[0])
291
- .filter((m: any) => m?.event?.eventType === "command_feedback")
292
- .map((m: any) => m.event.data.status);
293
- expect(evs).toEqual(["started"]);
294
- });
295
-
296
- it("Path D: no dispatchCommand + non-headless → returns true with error feedback including rpc-keeper hint", async () => {
297
- const { pi } = makePi({ withDispatch: false });
298
- const sink = vi.fn();
299
- const { conn, sent } = makeConn();
300
- setHeadless(false);
301
-
302
- const handled = await tryDispatchExtensionCommand(pi, "/ctx-stats", "sid", sink, conn);
303
- expect(handled).toBe(true); // handled with error feedback
304
- expect(sent.filter((m) => m.type === "dispatch_extension_command")).toEqual([]);
305
- // Error feedback emitted with rpc-keeper hint.
306
- const evs = sink.mock.calls
307
- .map((c: any[]) => c[0])
308
- .filter((m: any) => m?.event?.eventType === "command_feedback");
309
- expect(evs).toHaveLength(1);
310
- expect((evs[0] as any).event.data.status).toBe("error");
311
- expect((evs[0] as any).event.data.message).toContain("session shape");
312
- });
313
-
314
- it("Path D: no dispatchCommand + no connection → returns true with error feedback", async () => {
315
- const { pi } = makePi({ withDispatch: false });
316
- const sink = vi.fn();
317
- setHeadless(false);
318
-
319
- const handled = await tryDispatchExtensionCommand(pi, "/ctx-stats", "sid", sink, undefined);
320
- expect(handled).toBe(true); // handled with error feedback
321
- // Error feedback emitted with rpc-keeper hint.
322
- const evs = sink.mock.calls
323
- .map((c: any[]) => c[0])
324
- .filter((m: any) => m?.event?.eventType === "command_feedback");
325
- expect(evs).toHaveLength(1);
326
- expect((evs[0] as any).event.data.status).toBe("error");
327
- });
328
-
329
- it("non-extension /skill:foo → returns false; no path fires; no events", async () => {
330
- const pi: any = {
331
- getCommands: () => [{ name: "skill:foo", source: "skill" }],
332
- dispatchCommand: vi.fn(),
333
- };
334
- const sink = vi.fn();
335
- const { conn, sent } = makeConn();
336
- setHeadless(true);
337
-
338
- const handled = await tryDispatchExtensionCommand(pi, "/skill:foo", "sid", sink, conn);
339
- expect(handled).toBe(false);
340
- expect(pi.dispatchCommand).not.toHaveBeenCalled();
341
- expect(sent).toEqual([]);
342
- expect(sink).not.toHaveBeenCalled();
343
- });
344
-
345
- it("mutual exclusion: across all single-dispatch invocations, exactly one of (B, C, D) fires", async () => {
346
- type Scenario = { withDispatch: boolean; headless: boolean; expect: "B" | "C" | "D" };
347
- const scenarios: Scenario[] = [
348
- { withDispatch: true, headless: true, expect: "B" },
349
- { withDispatch: true, headless: false, expect: "B" },
350
- { withDispatch: false, headless: true, expect: "C" },
351
- { withDispatch: false, headless: false, expect: "D" },
352
- ];
353
- for (const s of scenarios) {
354
- const { pi, dispatchCommand } = makePi({ withDispatch: s.withDispatch });
355
- const sink = vi.fn();
356
- const { conn, sent } = makeConn();
357
- setHeadless(s.headless);
358
-
359
- const handled = await tryDispatchExtensionCommand(pi, "/ctx-stats", "sid", sink, conn);
360
-
361
- const dispatchedB = !!dispatchCommand && dispatchCommand.mock.calls.length > 0;
362
- const dispatchedC = sent.some((m) => m.type === "dispatch_extension_command");
363
- const dispatchedD = sink.mock.calls
364
- .map((c: any[]) => c[0])
365
- .some((m: any) => m?.event?.eventType === "command_feedback" && m?.event?.data?.status === "error");
366
-
367
- expect(handled, JSON.stringify(s)).toBe(true); // all paths now handle the command
368
-
369
- const fired = [dispatchedB && "B", dispatchedC && "C", dispatchedD && "D"].filter(Boolean);
370
- expect(fired, JSON.stringify(s)).toEqual([s.expect]);
371
- }
372
- });
373
- });
374
-
375
- // See change: add-steering-message (task 4.4).
376
- // Verify the slash-routing fallback paths that call sendUserMessage honor the
377
- // delivery field — `"steer"` → deliverAs:"steer"; absent/"followUp" → deliverAs:"followUp".
378
- describe("bridge slash routing: delivery field → sendUserMessage deliverAs", () => {
379
- function lastDeliverAs(sendUserMessage: ReturnType<typeof vi.fn>): string | undefined {
380
- const lastCall = sendUserMessage.mock.calls.at(-1);
381
- if (!lastCall) return undefined;
382
- const opts = lastCall[1];
383
- return opts?.deliverAs;
384
- }
385
-
386
- it("skill command + delivery:'steer' → sendUserMessage called with deliverAs:'steer'", async () => {
387
- const stub = makeStubPi({ withDispatch: true });
388
- await drive("/skill:foo", stub, "steer");
389
- expect(stub.sendUserMessage).toHaveBeenCalledTimes(1);
390
- expect(lastDeliverAs(stub.sendUserMessage)).toBe("steer");
391
- });
392
-
393
- it("skill command + delivery:'followUp' → sendUserMessage called with deliverAs:'followUp'", async () => {
394
- const stub = makeStubPi({ withDispatch: true });
395
- await drive("/skill:foo", stub, "followUp");
396
- expect(stub.sendUserMessage).toHaveBeenCalledTimes(1);
397
- expect(lastDeliverAs(stub.sendUserMessage)).toBe("followUp");
398
- });
399
-
400
- it("skill command + delivery omitted → sendUserMessage defaults to deliverAs:'followUp'", async () => {
401
- const stub = makeStubPi({ withDispatch: true });
402
- await drive("/skill:foo", stub);
403
- expect(stub.sendUserMessage).toHaveBeenCalledTimes(1);
404
- expect(lastDeliverAs(stub.sendUserMessage)).toBe("followUp");
405
- });
406
-
407
- it("prompt template + delivery:'steer' → deliverAs:'steer'", async () => {
408
- const stub = makeStubPi({ withDispatch: true });
409
- await drive("/review", stub, "steer");
410
- expect(lastDeliverAs(stub.sendUserMessage)).toBe("steer");
411
- });
412
-
413
- it("passthrough text + delivery:'steer' → deliverAs:'steer'", async () => {
414
- const stub = makeStubPi({ withDispatch: true });
415
- await drive("hello world", stub, "steer");
416
- expect(lastDeliverAs(stub.sendUserMessage)).toBe("steer");
417
- });
418
-
419
- it("passthrough text + delivery omitted → deliverAs:'followUp'", async () => {
420
- const stub = makeStubPi({ withDispatch: true });
421
- await drive("hello world", stub);
422
- expect(lastDeliverAs(stub.sendUserMessage)).toBe("followUp");
423
- });
424
-
425
- it("unrecognized slash + delivery:'steer' → deliverAs:'steer'", async () => {
426
- const stub = makeStubPi({ withDispatch: true });
427
- await drive("/totally-unknown-command", stub, "steer");
428
- expect(lastDeliverAs(stub.sendUserMessage)).toBe("steer");
429
- });
430
-
431
- it("bridge-native /__dashboard_reload fallback + delivery:'steer' → deliverAs:'steer'", async () => {
432
- const stub = makeStubPi({ withDispatch: true });
433
- await drive("/__dashboard_reload", stub, "steer");
434
- expect(lastDeliverAs(stub.sendUserMessage)).toBe("steer");
435
- });
436
-
437
- it("getCommands throws fallback + delivery:'steer' → deliverAs:'steer'", async () => {
438
- const stub = makeStubPi({ withDispatch: true, getCommandsThrows: true });
439
- await drive("/ctx-stats", stub, "steer");
440
- expect(lastDeliverAs(stub.sendUserMessage)).toBe("steer");
441
- });
442
- });
443
-
444
- describe("hasDispatchCommand", () => {
445
- it("returns true when field is a function", () => {
446
- expect(hasDispatchCommand({ dispatchCommand: () => {} })).toBe(true);
447
- });
448
- it("returns false when field is absent", () => {
449
- expect(hasDispatchCommand({})).toBe(false);
450
- });
451
- it("returns false when field is not a function", () => {
452
- expect(hasDispatchCommand({ dispatchCommand: "yes" })).toBe(false);
453
- });
454
- it("returns false on null/undefined", () => {
455
- expect(hasDispatchCommand(null)).toBe(false);
456
- expect(hasDispatchCommand(undefined)).toBe(false);
457
- });
458
- });
@@ -1,72 +0,0 @@
1
- /**
2
- * Bridge graceful stop-after-turn (shape contract).
3
- *
4
- * Models the bridge's two touch points:
5
- * - onMessage stop_after_turn → set state.shouldStopAfterTurn = true
6
- * - turn_end with flag set → cachedCtx.shutdown() once + clear flag
7
- *
8
- * See change: adopt-pi-071-072-073-features (B.2).
9
- */
10
- import { describe, it, expect, vi } from "vitest";
11
-
12
- interface FakeState {
13
- shouldStopAfterTurn?: boolean;
14
- }
15
-
16
- // Mirrors the bridge onMessage stop_after_turn branch.
17
- function onStopAfterTurn(state: FakeState): void {
18
- state.shouldStopAfterTurn = true;
19
- }
20
-
21
- // Mirrors the bridge turn_end branch.
22
- function onTurnEnd(state: FakeState, ctx: { shutdown?: () => void; abort?: () => void }): void {
23
- if (!state.shouldStopAfterTurn) return;
24
- state.shouldStopAfterTurn = false;
25
- try {
26
- if (typeof ctx?.shutdown === "function") ctx.shutdown();
27
- else ctx?.abort?.();
28
- } catch {
29
- /* non-fatal */
30
- }
31
- }
32
-
33
- describe("bridge stop-after-turn latch", () => {
34
- it("stop_after_turn sets the flag; turn_end shuts down once and clears it", () => {
35
- const state: FakeState = {};
36
- const shutdown = vi.fn();
37
- const ctx = { shutdown };
38
-
39
- onStopAfterTurn(state);
40
- expect(state.shouldStopAfterTurn).toBe(true);
41
-
42
- onTurnEnd(state, ctx);
43
- expect(shutdown).toHaveBeenCalledTimes(1);
44
- expect(state.shouldStopAfterTurn).toBe(false);
45
-
46
- // A second turn_end after the flag clears does NOT shut down again.
47
- onTurnEnd(state, ctx);
48
- expect(shutdown).toHaveBeenCalledTimes(1);
49
- });
50
-
51
- it("falls back to abort when shutdown is unavailable", () => {
52
- const state: FakeState = {};
53
- const abort = vi.fn();
54
- const ctx = { abort };
55
-
56
- onStopAfterTurn(state);
57
- onTurnEnd(state, ctx);
58
- expect(abort).toHaveBeenCalledTimes(1);
59
- expect(state.shouldStopAfterTurn).toBe(false);
60
- });
61
-
62
- it("is idempotent: repeated stop_after_turn keeps a single pending latch", () => {
63
- const state: FakeState = {};
64
- onStopAfterTurn(state);
65
- onStopAfterTurn(state);
66
- expect(state.shouldStopAfterTurn).toBe(true);
67
-
68
- const shutdown = vi.fn();
69
- onTurnEnd(state, { shutdown });
70
- expect(shutdown).toHaveBeenCalledTimes(1);
71
- });
72
- });