@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,379 +0,0 @@
1
- /**
2
- * Tests for the `model:resolve` event listener registered by provider-register.ts.
3
- *
4
- * Spec: openspec/changes/adopt-model-resolve-handler-and-roles-ownership/
5
- * specs/dashboard-model-resolution/spec.md
6
- *
7
- * Approach: stand up a fake ExtensionAPI that captures `pi.on(...)` and
8
- * `pi.events.on(...)` handlers. Call activate() with no providers.json
9
- * (so provider registration is a no-op), then drive a synthesized
10
- * `session_start` event to inject a stubbed `modelRegistry`. Finally
11
- * emit `model:resolve` probes and assert the listener's behaviour.
12
- *
13
- * Mirrors the structure of pi-dashboard-subagents' `model-resolve.test.ts`.
14
- */
15
-
16
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
17
- import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
18
- import { homedir } from "node:os";
19
- import { join } from "node:path";
20
-
21
- // Note: provider-register.ts keeps module-level state (`modelRegistryRef`)
22
- // that is set lazily by session_start and gated by a `!modelRegistryRef`
23
- // check. Tests reset modules in beforeEach so each test gets a fresh import
24
- // and can inject its own registry.
25
-
26
- const CONFIG = () => join(homedir(), ".pi", "agent", "providers.json");
27
-
28
- type AnyModel = { id: string; provider?: string };
29
-
30
- interface FakePi {
31
- pi: any;
32
- events: Map<string, Array<(data: any) => any>>;
33
- lifecycle: Map<string, Array<(event: any, ctx: any) => any>>;
34
- emit: (name: string, data: any) => Promise<void>;
35
- fireLifecycle: (name: string, event: any, ctx: any) => Promise<void>;
36
- }
37
-
38
- function mkPi(): FakePi {
39
- const events = new Map<string, Array<(data: any) => any>>();
40
- const lifecycle = new Map<string, Array<(event: any, ctx: any) => any>>();
41
- const pi: any = {
42
- events: {
43
- on: (name: string, fn: (data: any) => any) => {
44
- const list = events.get(name) ?? [];
45
- list.push(fn);
46
- events.set(name, list);
47
- },
48
- emit: async (name: string, data: any) => {
49
- for (const fn of events.get(name) ?? []) await fn(data);
50
- },
51
- },
52
- on: (name: string, fn: (event: any, ctx: any) => any) => {
53
- const list = lifecycle.get(name) ?? [];
54
- list.push(fn);
55
- lifecycle.set(name, list);
56
- },
57
- registerProvider: () => {},
58
- unregisterProvider: () => {},
59
- setModel: async () => {},
60
- };
61
- return {
62
- pi,
63
- events,
64
- lifecycle,
65
- emit: async (name, data) => {
66
- for (const fn of events.get(name) ?? []) await fn(data);
67
- },
68
- fireLifecycle: async (name, event, ctx) => {
69
- for (const fn of lifecycle.get(name) ?? []) await fn(event, ctx);
70
- },
71
- };
72
- }
73
-
74
- function makeRegistry(opts: {
75
- models?: AnyModel[];
76
- authOk?: boolean;
77
- authError?: string;
78
- }) {
79
- const models = opts.models ?? [];
80
- return {
81
- find: (provider: string, id: string) =>
82
- models.find((m) => m.provider === provider && m.id === id),
83
- getAll: () => models,
84
- getApiKeyAndHeaders: async (_m: AnyModel) =>
85
- opts.authOk === false
86
- ? { ok: false, error: opts.authError ?? "missing" }
87
- : { ok: true, apiKey: "sk-test", headers: {} },
88
- };
89
- }
90
-
91
- async function bootstrap(registry: any) {
92
- const fake = mkPi();
93
- const { activate } = await import("../provider-register.js");
94
- activate(fake.pi);
95
- // Inject modelRegistry via the session_start lifecycle hook (the same path
96
- // production code uses to capture it).
97
- await fake.fireLifecycle("session_start", {}, { modelRegistry: registry, model: null, ui: { notify: () => {} } });
98
- return fake;
99
- }
100
-
101
- function resetConfig() {
102
- mkdirSync(join(homedir(), ".pi", "agent"), { recursive: true });
103
- if (existsSync(CONFIG())) rmSync(CONFIG());
104
- }
105
-
106
- beforeEach(() => {
107
- resetConfig();
108
- vi.resetModules();
109
- });
110
-
111
- afterEach(() => {
112
- resetConfig();
113
- });
114
-
115
- describe("model:resolve — @role resolution", () => {
116
- it("resolves @fast from providers.json#roles to a Model + auth", async () => {
117
- writeFileSync(CONFIG(), JSON.stringify({
118
- roles: { fast: "anthropic/claude-haiku-4-5" },
119
- }));
120
- const registry = makeRegistry({
121
- models: [{ id: "claude-haiku-4-5", provider: "anthropic" }],
122
- });
123
- const fake = await bootstrap(registry);
124
-
125
- const probe: any = { ref: "@fast" };
126
- await fake.emit("model:resolve", probe);
127
-
128
- expect(probe.error).toBeUndefined();
129
- expect(probe.model).toEqual({ id: "claude-haiku-4-5", provider: "anthropic" });
130
- expect(probe.resolved).toBe("anthropic/claude-haiku-4-5");
131
- expect(probe.auth).toEqual({ ok: true, apiKey: "sk-test", headers: {} });
132
- });
133
-
134
- it("unknown @role sets probe.error and probe.available.roles hint", async () => {
135
- writeFileSync(CONFIG(), JSON.stringify({
136
- roles: { fast: "anthropic/haiku", research: "anthropic/opus" },
137
- }));
138
- const fake = await bootstrap(makeRegistry({ models: [] }));
139
-
140
- const probe: any = { ref: "@unknownrole" };
141
- await fake.emit("model:resolve", probe);
142
-
143
- expect(probe.model).toBeUndefined();
144
- expect(probe.error).toMatch(/Role "@unknownrole"/);
145
- expect(probe.available?.roles).toEqual({ fast: "anthropic/haiku", research: "anthropic/opus" });
146
- });
147
-
148
- it("empty @role name surfaces an error", async () => {
149
- const fake = await bootstrap(makeRegistry({ models: [] }));
150
- const probe: any = { ref: "@" };
151
- await fake.emit("model:resolve", probe);
152
- expect(probe.model).toBeUndefined();
153
- expect(probe.error).toMatch(/Invalid role alias/);
154
- });
155
- });
156
-
157
- describe("model:resolve — provider/model resolution", () => {
158
- it("resolves a literal provider/model via registry.find", async () => {
159
- const m = { id: "claude-opus-4", provider: "anthropic" };
160
- const fake = await bootstrap(makeRegistry({ models: [m] }));
161
-
162
- const probe: any = { ref: "anthropic/claude-opus-4" };
163
- await fake.emit("model:resolve", probe);
164
-
165
- expect(probe.model).toBe(m);
166
- expect(probe.resolved).toBe("anthropic/claude-opus-4");
167
- });
168
-
169
- it("unknown provider/model surfaces error with available models hint", async () => {
170
- const fake = await bootstrap(makeRegistry({
171
- models: [
172
- { id: "a", provider: "p" },
173
- { id: "b", provider: "p" },
174
- ],
175
- }));
176
- const probe: any = { ref: "anthropic/made-up" };
177
- await fake.emit("model:resolve", probe);
178
- expect(probe.model).toBeUndefined();
179
- expect(probe.error).toMatch(/No model matched "anthropic\/made-up"/);
180
- expect(probe.available?.models).toEqual(["a", "b"]);
181
- });
182
- });
183
-
184
- describe("model:resolve — bare id resolution", () => {
185
- it("resolves a bare id via registry.getAll first-match", async () => {
186
- const m = { id: "claude-haiku-4-5", provider: "anthropic" };
187
- const fake = await bootstrap(makeRegistry({ models: [m] }));
188
-
189
- const probe: any = { ref: "claude-haiku-4-5" };
190
- await fake.emit("model:resolve", probe);
191
-
192
- expect(probe.model).toBe(m);
193
- expect(probe.resolved).toBe("anthropic/claude-haiku-4-5");
194
- });
195
-
196
- it("unknown bare id surfaces error with available models hint", async () => {
197
- const fake = await bootstrap(makeRegistry({
198
- models: [
199
- { id: "a", provider: "p" },
200
- { id: "b", provider: "p" },
201
- { id: "c", provider: "p" },
202
- ],
203
- }));
204
- const probe: any = { ref: "made-up-model" };
205
- await fake.emit("model:resolve", probe);
206
- expect(probe.model).toBeUndefined();
207
- expect(probe.error).toMatch(/No model matched "made-up-model"/);
208
- expect(probe.available?.models).toEqual(["a", "b", "c"]);
209
- });
210
- });
211
-
212
- describe("model:resolve — thinking suffix", () => {
213
- it("parses :high off provider/model before registry lookup", async () => {
214
- const m = { id: "claude-opus-4", provider: "anthropic" };
215
- let findArgs: [string, string] | undefined;
216
- const registry = {
217
- find: (p: string, id: string) => {
218
- findArgs = [p, id];
219
- return p === "anthropic" && id === "claude-opus-4" ? m : undefined;
220
- },
221
- getAll: () => [m],
222
- getApiKeyAndHeaders: async () => ({ ok: true }),
223
- };
224
- const fake = await bootstrap(registry);
225
- const probe: any = { ref: "anthropic/claude-opus-4:high" };
226
- await fake.emit("model:resolve", probe);
227
-
228
- expect(probe.thinkingLevel).toBe("high");
229
- expect(findArgs).toEqual(["anthropic", "claude-opus-4"]);
230
- expect(probe.resolved).toBe("anthropic/claude-opus-4");
231
- expect(probe.model).toBe(m);
232
- });
233
-
234
- it("parses :medium off bare id before registry lookup", async () => {
235
- const m = { id: "claude-haiku-4-5", provider: "anthropic" };
236
- const fake = await bootstrap(makeRegistry({ models: [m] }));
237
- const probe: any = { ref: "claude-haiku-4-5:medium" };
238
- await fake.emit("model:resolve", probe);
239
- expect(probe.thinkingLevel).toBe("medium");
240
- expect(probe.model).toBe(m);
241
- });
242
-
243
- it("parses :low off @role-resolved literal", async () => {
244
- writeFileSync(CONFIG(), JSON.stringify({
245
- roles: { fast: "anthropic/claude-haiku-4-5:low" },
246
- }));
247
- const m = { id: "claude-haiku-4-5", provider: "anthropic" };
248
- const fake = await bootstrap(makeRegistry({ models: [m] }));
249
- const probe: any = { ref: "@fast" };
250
- await fake.emit("model:resolve", probe);
251
- expect(probe.thinkingLevel).toBe("low");
252
- expect(probe.model).toBe(m);
253
- });
254
- });
255
-
256
- describe("model:resolve — cooperative early-return", () => {
257
- it("returns immediately when probe.model is already set", async () => {
258
- let findCalled = false;
259
- const registry = {
260
- find: () => { findCalled = true; return undefined; },
261
- getAll: () => { findCalled = true; return []; },
262
- getApiKeyAndHeaders: async () => ({ ok: true }),
263
- };
264
- const fake = await bootstrap(registry);
265
-
266
- const preset = { id: "preset", provider: "p" };
267
- const probe: any = { ref: "anything", model: preset };
268
- await fake.emit("model:resolve", probe);
269
-
270
- expect(probe.model).toBe(preset);
271
- expect(findCalled).toBe(false);
272
- expect(probe.error).toBeUndefined();
273
- expect(probe.resolved).toBeUndefined();
274
- });
275
-
276
- it("ignores empty / non-string ref", async () => {
277
- const fake = await bootstrap(makeRegistry({ models: [] }));
278
- const probe: any = { ref: "" };
279
- await fake.emit("model:resolve", probe);
280
- expect(probe.model).toBeUndefined();
281
- expect(probe.error).toBeUndefined();
282
-
283
- const probe2: any = { ref: 42 };
284
- await fake.emit("model:resolve", probe2);
285
- expect(probe2.model).toBeUndefined();
286
- expect(probe2.error).toBeUndefined();
287
- });
288
- });
289
-
290
- describe("model:resolve — malformed providers.json tolerated", () => {
291
- it("malformed JSON during @role lookup returns empty available.roles", async () => {
292
- writeFileSync(CONFIG(), "{ not json");
293
- const fake = await bootstrap(makeRegistry({ models: [] }));
294
- const probe: any = { ref: "@fast" };
295
- await fake.emit("model:resolve", probe);
296
- expect(probe.model).toBeUndefined();
297
- expect(probe.error).toMatch(/Role "@fast"/);
298
- expect(probe.available?.roles).toEqual({});
299
- });
300
- });
301
-
302
- // ── Dead pi.modelRegistry fallback removed ────────────────────────────
303
- //
304
- // See change: add-agent-role-model-tools. The former getModelRegistry()
305
- // fallback read `(piRef as any).modelRegistry` — a property that does NOT
306
- // exist on ExtensionAPI in pi 0.80 (it lives on ExtensionContext). These
307
- // tests pin the corrected behaviour: the ONLY registry source is the
308
- // `ctx.modelRegistry`-captured `modelRegistryRef`, and when it is unpopulated
309
- // the handler sets probe.error (never throws, never resolves via pi.*).
310
-
311
- async function bootstrapCold(piModelRegistry: any) {
312
- const fake = mkPi();
313
- if (piModelRegistry !== undefined) {
314
- fake.pi.modelRegistry = piModelRegistry;
315
- }
316
- const { activate } = await import("../provider-register.js");
317
- activate(fake.pi);
318
- // Intentionally NO `session_start` / `model_select` fired.
319
- return fake;
320
- }
321
-
322
- describe("model:resolve — dead pi.modelRegistry fallback is gone", () => {
323
- it("does NOT resolve via pi.modelRegistry when modelRegistryRef is null (known model)", async () => {
324
- // Repro (task 1.1): pi.modelRegistry is set but modelRegistryRef is not.
325
- // The dead fallback would have resolved; the corrected handler must NOT —
326
- // probe.model stays unset and probe.error fires for a known model.
327
- const m = { id: "claude-haiku-4-5", provider: "anthropic" };
328
- const piRegistry = makeRegistry({ models: [m] });
329
- const fake = await bootstrapCold(piRegistry);
330
-
331
- const probe: any = { ref: "anthropic/claude-haiku-4-5" };
332
- await fake.emit("model:resolve", probe);
333
-
334
- expect(probe.model).toBeUndefined();
335
- expect(probe.error).toBe('Model registry unavailable — cannot resolve "anthropic/claude-haiku-4-5".');
336
- });
337
-
338
- it("fills probe.model from the ctx.modelRegistry-captured warm ref", async () => {
339
- const warmModel = { id: "warm-only", provider: "anthropic" };
340
- const warmRegistry = makeRegistry({ models: [warmModel] });
341
-
342
- const fake = mkPi();
343
- // Even with a bogus pi.modelRegistry present, the warm ref is the source.
344
- fake.pi.modelRegistry = makeRegistry({ models: [] });
345
- const { activate } = await import("../provider-register.js");
346
- activate(fake.pi);
347
- await fake.fireLifecycle("session_start", {}, { modelRegistry: warmRegistry, model: null, ui: { notify: () => {} } });
348
-
349
- const probe: any = { ref: "anthropic/warm-only" };
350
- await fake.emit("model:resolve", probe);
351
-
352
- expect(probe.error).toBeUndefined();
353
- expect(probe.model).toBe(warmModel);
354
- });
355
-
356
- it("no registry handle yields the unavailable error, not a throw", async () => {
357
- const fake = await bootstrapCold(undefined);
358
- const probe: any = { ref: "anthropic/claude-haiku-4-5" };
359
- await expect(fake.emit("model:resolve", probe)).resolves.toBeUndefined();
360
- expect(probe.model).toBeUndefined();
361
- expect(probe.error).toBe('Model registry unavailable — cannot resolve "anthropic/claude-haiku-4-5".');
362
- });
363
-
364
- it("@role with a captured warm ref fills probe.model", async () => {
365
- writeFileSync(CONFIG(), JSON.stringify({
366
- roles: { fast: "anthropic/claude-haiku-4-5" },
367
- }));
368
- const m = { id: "claude-haiku-4-5", provider: "anthropic" };
369
- const fake = await bootstrap(makeRegistry({ models: [m] }));
370
-
371
- const probe: any = { ref: "@fast" };
372
- await fake.emit("model:resolve", probe);
373
-
374
- expect(probe.error).toBeUndefined();
375
- expect(probe.model).toBe(m);
376
- expect(probe.resolved).toBe("anthropic/claude-haiku-4-5");
377
- expect(probe.auth).toEqual({ ok: true, apiKey: "sk-test", headers: {} });
378
- });
379
- });
@@ -1,203 +0,0 @@
1
- /**
2
- * Tests for the bridge's `ctx.ui.multiselect` PromptBus patch and the TUI
3
- * adapter's multiselect handling. The patch lives in `bridge.ts` but is
4
- * exercised here through a small reproduction harness so we don't pull in
5
- * the full session lifecycle.
6
- *
7
- * See change: fix-multiselect-auto-cancel-on-dashboard.
8
- */
9
- import { describe, it, expect, vi, beforeEach } from "vitest";
10
- import { decodeMultiselectAnswer } from "../multiselect-decode.js";
11
-
12
- // ──────────────────────────────────────────────────────────────────────
13
- // `decodeMultiselectAnswer` — pure helper used by both the runtime patch
14
- // and the TUI adapter's response encoding round-trip.
15
- // ──────────────────────────────────────────────────────────────────────
16
-
17
- describe("decodeMultiselectAnswer", () => {
18
- it("resolves cancellation as undefined", () => {
19
- expect(decodeMultiselectAnswer({ cancelled: true })).toBeUndefined();
20
- expect(decodeMultiselectAnswer({ cancelled: true, answer: '["x"]' })).toBeUndefined();
21
- });
22
-
23
- it("resolves successful selection from JSON-encoded array", () => {
24
- expect(decodeMultiselectAnswer({ cancelled: false, answer: '["a","c"]' })).toEqual(["a", "c"]);
25
- });
26
-
27
- it("resolves empty selection as []", () => {
28
- expect(decodeMultiselectAnswer({ cancelled: false, answer: "[]" })).toEqual([]);
29
- });
30
-
31
- it("resolves null / undefined / empty answer as [] (not undefined)", () => {
32
- expect(decodeMultiselectAnswer({ cancelled: false, answer: undefined })).toEqual([]);
33
- expect(decodeMultiselectAnswer({ cancelled: false, answer: "" })).toEqual([]);
34
- });
35
-
36
- it("resolves unparseable JSON as [] without throwing", () => {
37
- expect(decodeMultiselectAnswer({ cancelled: false, answer: "not-json" })).toEqual([]);
38
- expect(decodeMultiselectAnswer({ cancelled: false, answer: "{not:array}" })).toEqual([]);
39
- });
40
-
41
- it("resolves valid JSON that is not an array as []", () => {
42
- expect(decodeMultiselectAnswer({ cancelled: false, answer: '"just-a-string"' })).toEqual([]);
43
- expect(decodeMultiselectAnswer({ cancelled: false, answer: '{"k":"v"}' })).toEqual([]);
44
- });
45
- });
46
-
47
- // ──────────────────────────────────────────────────────────────────────
48
- // Bridge patch reproduction — emulate the assignment block in
49
- // `bridge.ts:935-948` plus the new multiselect arm and assert behavior.
50
- // We cannot import `bridge.ts` directly (it has heavy session-lifecycle
51
- // imports), so we reproduce the assignment closure here. The closure
52
- // shape MUST match `bridge.ts` exactly; if `bridge.ts` drifts, the
53
- // regression guard test (see "ctx.ui.multiselect is assigned by the
54
- // bridge patch block" below) re-loads the bridge source and asserts
55
- // the assignment exists.
56
- // ──────────────────────────────────────────────────────────────────────
57
-
58
- interface BusRequestArgs {
59
- pipeline: string;
60
- type: string;
61
- question: string;
62
- options?: string[];
63
- metadata?: Record<string, unknown>;
64
- }
65
-
66
- interface FakeBus {
67
- request: (args: BusRequestArgs) => Promise<{ cancelled?: boolean; answer?: string }>;
68
- }
69
-
70
- function applyMultiselectPatch(
71
- ctx: { ui: Record<string, any> },
72
- bus: FakeBus,
73
- ): void {
74
- const existing = (ctx.ui as any).multiselect;
75
- if (typeof existing === "function") {
76
- // eslint-disable-next-line no-console
77
- console.warn("[bridge] ctx.ui.multiselect already exists — overriding for PromptBus routing");
78
- }
79
- (ctx.ui as any).multiselect = (title: string, options: string[], opts?: { message?: string }) =>
80
- bus.request({
81
- pipeline: "command",
82
- type: "multiselect",
83
- question: title,
84
- options,
85
- metadata: opts?.message ? { message: opts.message } : undefined,
86
- }).then((r) => decodeMultiselectAnswer(r));
87
- }
88
-
89
- describe("bridge ctx.ui.multiselect patch", () => {
90
- let ctx: { ui: Record<string, any> };
91
- let bus: FakeBus;
92
- let requestSpy: ReturnType<typeof vi.fn>;
93
-
94
- beforeEach(() => {
95
- requestSpy = vi.fn();
96
- bus = { request: requestSpy as any };
97
- ctx = { ui: {} };
98
- });
99
-
100
- it("assigns ctx.ui.multiselect as a function after the patch runs", () => {
101
- expect(typeof ctx.ui.multiselect).toBe("undefined");
102
- applyMultiselectPatch(ctx, bus);
103
- expect(typeof ctx.ui.multiselect).toBe("function");
104
- });
105
-
106
- it("dispatches bus.request with the right shape on call", async () => {
107
- applyMultiselectPatch(ctx, bus);
108
- requestSpy.mockResolvedValue({ cancelled: false, answer: '["a","c"]' });
109
-
110
- const result = await ctx.ui.multiselect("Pick", ["a", "b", "c"], { message: "ctx" });
111
-
112
- expect(requestSpy).toHaveBeenCalledTimes(1);
113
- expect(requestSpy).toHaveBeenCalledWith({
114
- pipeline: "command",
115
- type: "multiselect",
116
- question: "Pick",
117
- options: ["a", "b", "c"],
118
- metadata: { message: "ctx" },
119
- });
120
- expect(result).toEqual(["a", "c"]);
121
- });
122
-
123
- it("omits metadata when no message is provided", async () => {
124
- applyMultiselectPatch(ctx, bus);
125
- requestSpy.mockResolvedValue({ cancelled: false, answer: "[]" });
126
-
127
- await ctx.ui.multiselect("Pick", ["a", "b"]);
128
-
129
- expect(requestSpy).toHaveBeenCalledWith(
130
- expect.objectContaining({ metadata: undefined }),
131
- );
132
- });
133
-
134
- it("resolves successful selection through the decoder", async () => {
135
- applyMultiselectPatch(ctx, bus);
136
- requestSpy.mockResolvedValue({ cancelled: false, answer: '["a","c"]' });
137
- await expect(ctx.ui.multiselect("t", ["a", "b", "c"])).resolves.toEqual(["a", "c"]);
138
- });
139
-
140
- it("resolves empty selection as []", async () => {
141
- applyMultiselectPatch(ctx, bus);
142
- requestSpy.mockResolvedValue({ cancelled: false, answer: "[]" });
143
- await expect(ctx.ui.multiselect("t", ["a"])).resolves.toEqual([]);
144
- });
145
-
146
- it("resolves cancellation as undefined", async () => {
147
- applyMultiselectPatch(ctx, bus);
148
- requestSpy.mockResolvedValue({ cancelled: true });
149
- await expect(ctx.ui.multiselect("t", ["a"])).resolves.toBeUndefined();
150
- });
151
-
152
- it("resolves unparseable answer as [] without throwing", async () => {
153
- applyMultiselectPatch(ctx, bus);
154
- requestSpy.mockResolvedValue({ cancelled: false, answer: "not-json" });
155
- await expect(ctx.ui.multiselect("t", ["a"])).resolves.toEqual([]);
156
- });
157
-
158
- it("warns when ctx.ui.multiselect was already a function before the patch", () => {
159
- const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
160
- ctx.ui.multiselect = () => Promise.resolve(["pre-existing"]);
161
-
162
- applyMultiselectPatch(ctx, bus);
163
-
164
- expect(warnSpy).toHaveBeenCalledWith(
165
- expect.stringContaining("already exists"),
166
- );
167
- // The patch still wins — subsequent calls go through bus.request.
168
- requestSpy.mockResolvedValue({ cancelled: false, answer: '["winner"]' });
169
- return ctx.ui.multiselect("t", ["a"]).then((r: any) => {
170
- expect(r).toEqual(["winner"]);
171
- expect(requestSpy).toHaveBeenCalled();
172
- warnSpy.mockRestore();
173
- });
174
- });
175
- });
176
-
177
- // ──────────────────────────────────────────────────────────────────────
178
- // Source regression guard — re-load bridge.ts as text and assert the
179
- // multiselect patch line exists. Mirrors `no-direct-process-kill.test.ts`
180
- // pattern: textual scan over a single file, fail with file:line if the
181
- // expected snippet is missing or moved.
182
- // ──────────────────────────────────────────────────────────────────────
183
-
184
- describe("bridge.ts source regression guard", () => {
185
- it("contains the ctx.ui.multiselect PromptBus assignment", async () => {
186
- const fs = await import("node:fs");
187
- const path = await import("node:path");
188
- const url = await import("node:url");
189
- const here = path.dirname(url.fileURLToPath(import.meta.url));
190
- const bridgePath = path.resolve(here, "../bridge.ts");
191
- const src = fs.readFileSync(bridgePath, "utf8");
192
-
193
- // The assignment must mention `multiselect` as a key on ctx.ui AND
194
- // dispatch through bus.request with type:"multiselect".
195
- expect(src).toMatch(/\(ctx\.ui as any\)\.multiselect\s*=/);
196
- expect(src).toMatch(/type:\s*"multiselect"/);
197
- });
198
-
199
- // Note: the previous-change assertions about `custom: ctx.ui.custom?.bind(...)`
200
- // capture and the TUI `prompt.type === "multiselect"` arm were removed by
201
- // change `fix-multiselect-tui-arm-self-cancel`. The inverse-guard for that
202
- // removal lives in `no-tui-multiselect-arm-regression.test.ts`.
203
- });