@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,398 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from "vitest";
2
- import { mkdirSync, writeFileSync, rmSync } from "node:fs";
3
- import { dirname, join } from "node:path";
4
- import { expandPromptTemplateFromDisk, loadPromptTemplate } from "../prompt-expander.js";
5
- import { parseSkillBlock } from "@blackbelt-technology/pi-dashboard-shared/skill-block-parser.js";
6
-
7
- const tmpDir = join(import.meta.dirname ?? __dirname, "__tmp_prompt_test__");
8
- const promptsDir = join(tmpDir, ".pi", "prompts");
9
- const skillsDir = join(tmpDir, ".pi", "skills");
10
-
11
- beforeEach(() => {
12
- mkdirSync(promptsDir, { recursive: true });
13
- writeFileSync(join(promptsDir, "opsx-continue.md"), "---\ndescription: continue\n---\nContinue the change");
14
- writeFileSync(join(promptsDir, "opsx-apply.md"), "Apply the change");
15
- writeFileSync(join(promptsDir, "hello.md"), "Hello world");
16
- // Skill fixture
17
- mkdirSync(join(skillsDir, "my-skill"), { recursive: true });
18
- writeFileSync(
19
- join(skillsDir, "my-skill", "SKILL.md"),
20
- "---\nname: my-skill\ndescription: A demo skill\n---\nFirst body line\nSecond body line",
21
- );
22
- });
23
-
24
- afterEach(() => {
25
- rmSync(tmpDir, { recursive: true, force: true });
26
- });
27
-
28
- describe("expandPromptTemplateFromDisk", () => {
29
- it("expands hyphen form /opsx-continue", () => {
30
- const result = expandPromptTemplateFromDisk("/opsx-continue my-change", tmpDir);
31
- expect(result).toContain("Continue the change");
32
- expect(result).toContain("my-change");
33
- });
34
-
35
- it("expands colon form /opsx:continue as alias for /opsx-continue", () => {
36
- const result = expandPromptTemplateFromDisk("/opsx:continue my-change", tmpDir);
37
- expect(result).toContain("Continue the change");
38
- expect(result).toContain("my-change");
39
- });
40
-
41
- it("expands colon form /opsx:apply without args", () => {
42
- const result = expandPromptTemplateFromDisk("/opsx:apply", tmpDir);
43
- expect(result).toBe("Apply the change");
44
- });
45
-
46
- it("does not affect non-opsx colon commands", () => {
47
- // /hello has no colon, should work as before
48
- const result = expandPromptTemplateFromDisk("/hello", tmpDir);
49
- expect(result).toBe("Hello world");
50
- });
51
-
52
- it("returns original text when no template found", () => {
53
- const result = expandPromptTemplateFromDisk("/nonexistent", tmpDir);
54
- expect(result).toBe("/nonexistent");
55
- });
56
-
57
- it("strips YAML frontmatter from colon form too", () => {
58
- const result = expandPromptTemplateFromDisk("/opsx:continue", tmpDir);
59
- expect(result).toBe("Continue the change");
60
- expect(result).not.toContain("---");
61
- });
62
-
63
- // See change: render-skill-invocations-collapsibly.
64
-
65
- it("wraps /skill:my-skill output in a <skill> envelope (with args)", () => {
66
- const result = expandPromptTemplateFromDisk("/skill:my-skill do the thing", tmpDir);
67
- expect(result.startsWith('<skill name="my-skill" location="')).toBe(true);
68
- expect(result).toContain("References are relative to ");
69
- expect(result).toContain("First body line\nSecond body line");
70
- expect(result.endsWith("\n\ndo the thing")).toBe(true);
71
- // round-trips through parseSkillBlock
72
- const parsed = parseSkillBlock(result);
73
- expect(parsed).not.toBeNull();
74
- expect(parsed!.name).toBe("my-skill");
75
- expect(parsed!.args).toBe("do the thing");
76
- expect(parsed!.condensed).toBe("/skill:my-skill do the thing");
77
- });
78
-
79
- it("wraps /skill:my-skill output in a <skill> envelope (without args)", () => {
80
- const result = expandPromptTemplateFromDisk("/skill:my-skill", tmpDir);
81
- expect(result.startsWith('<skill name="my-skill" location="')).toBe(true);
82
- expect(result.endsWith("</skill>")).toBe(true);
83
- expect(result).not.toContain("</skill>\n\n");
84
- const parsed = parseSkillBlock(result);
85
- expect(parsed!.args).toBeUndefined();
86
- expect(parsed!.condensed).toBe("/skill:my-skill");
87
- });
88
-
89
- it("prompt template /opsx-continue stays unwrapped (no <skill> tag)", () => {
90
- const result = expandPromptTemplateFromDisk("/opsx-continue my-change", tmpDir);
91
- expect(result).not.toContain("<skill name=");
92
- expect(result).not.toContain("</skill>");
93
- });
94
-
95
- it("colon-alias prompt template /opsx:continue stays unwrapped", () => {
96
- const result = expandPromptTemplateFromDisk("/opsx:continue x", tmpDir);
97
- expect(result).not.toContain("<skill name=");
98
- });
99
-
100
- // Change: unify-opsx-colon-hyphen-aliases — symmetric : ↔ - resolution.
101
-
102
- function makeSkillFile(relPath: string, body = "skill body"): string {
103
- const abs = join(tmpDir, relPath);
104
- mkdirSync(dirname(abs), { recursive: true });
105
- writeFileSync(abs, `---\nname: ignored\n---\n${body}`);
106
- return abs;
107
- }
108
-
109
- it("expands hyphen-typed slash command resolving a colon-registered pi.getCommands skill", () => {
110
- const skillPath = makeSkillFile("registry/colon/SKILL.md");
111
- const pi = {
112
- getCommands: () => [{ name: "opsx:archive", source: "skill", path: skillPath }],
113
- };
114
- const result = expandPromptTemplateFromDisk("/opsx-archive my-change", tmpDir, pi);
115
- expect(result.startsWith('<skill name="opsx:archive" location="')).toBe(true);
116
- expect(result.endsWith("\n\nmy-change")).toBe(true);
117
- const parsed = parseSkillBlock(result);
118
- expect(parsed!.name).toBe("opsx:archive");
119
- expect(parsed!.args).toBe("my-change");
120
- });
121
-
122
- it("expands colon-typed slash command resolving a hyphen-registered pi.getCommands skill", () => {
123
- const skillPath = makeSkillFile("registry/hyphen/SKILL.md");
124
- const pi = {
125
- getCommands: () => [{ name: "opsx-archive", source: "skill", path: skillPath }],
126
- };
127
- const result = expandPromptTemplateFromDisk("/opsx:archive my-change", tmpDir, pi);
128
- expect(result.startsWith('<skill name="opsx-archive" location="')).toBe(true);
129
- expect(result.endsWith("\n\nmy-change")).toBe(true);
130
- const parsed = parseSkillBlock(result);
131
- expect(parsed!.name).toBe("opsx-archive");
132
- });
133
-
134
- it("expands colon-typed slash command resolving a hyphen-named local SKILL.md directory", () => {
135
- mkdirSync(join(skillsDir, "opsx-archive"), { recursive: true });
136
- writeFileSync(join(skillsDir, "opsx-archive", "SKILL.md"), "---\nname: x\n---\nbody");
137
- const result = expandPromptTemplateFromDisk("/opsx:archive arg", tmpDir);
138
- expect(result.startsWith('<skill name="opsx-archive" location="')).toBe(true);
139
- const parsed = parseSkillBlock(result);
140
- expect(parsed!.name).toBe("opsx-archive");
141
- expect(parsed!.args).toBe("arg");
142
- });
143
-
144
- it("expands hyphen-typed slash command resolving a colon-named local SKILL.md directory", () => {
145
- mkdirSync(join(skillsDir, "opsx:archive"), { recursive: true });
146
- writeFileSync(join(skillsDir, "opsx:archive", "SKILL.md"), "---\nname: x\n---\nbody");
147
- const result = expandPromptTemplateFromDisk("/opsx-archive arg", tmpDir);
148
- expect(result.startsWith('<skill name="opsx:archive" location="')).toBe(true);
149
- const parsed = parseSkillBlock(result);
150
- expect(parsed!.name).toBe("opsx:archive");
151
- });
152
-
153
- it("original-form precedence: colon-typed prefers colon-registered skill over hyphen-form prompt template", () => {
154
- // Local prompt opsx-foo.md exists; registry has skill opsx:foo.
155
- writeFileSync(join(promptsDir, "opsx-foo.md"), "prompt body");
156
- const skillPath = makeSkillFile("registry/precedence/SKILL.md", "skill body");
157
- const pi = {
158
- getCommands: () => [{ name: "opsx:foo", source: "skill", path: skillPath }],
159
- };
160
- // /opsx:foo → must wrap as skill (registry hit on original form).
161
- const colon = expandPromptTemplateFromDisk("/opsx:foo", tmpDir, pi);
162
- expect(colon.startsWith('<skill name="opsx:foo" location="')).toBe(true);
163
- // /opsx-foo → must NOT wrap (local prompt hit on original form).
164
- const hyphen = expandPromptTemplateFromDisk("/opsx-foo", tmpDir, pi);
165
- expect(hyphen).not.toContain("<skill name=");
166
- expect(hyphen).toContain("prompt body");
167
- });
168
-
169
- it("original-form-first across distinct pi.getCommands entries", () => {
170
- const aPath = makeSkillFile("registry/A/SKILL.md", "A body");
171
- const bPath = makeSkillFile("registry/B/SKILL.md", "B body");
172
- const pi = {
173
- getCommands: () => [
174
- { name: "opsx:foo", source: "skill", path: aPath },
175
- { name: "opsx-foo", source: "skill", path: bPath },
176
- ],
177
- };
178
- const colon = expandPromptTemplateFromDisk("/opsx:foo arg", tmpDir, pi);
179
- expect(colon).toContain(`location="${aPath}"`);
180
- expect(colon).toContain('name="opsx:foo"');
181
- expect(colon).not.toContain(`location="${bPath}"`);
182
- const hyphen = expandPromptTemplateFromDisk("/opsx-foo arg", tmpDir, pi);
183
- expect(hyphen).toContain(`location="${bPath}"`);
184
- expect(hyphen).toContain('name="opsx-foo"');
185
- expect(hyphen).not.toContain(`location="${aPath}"`);
186
- });
187
-
188
- it("original form in pi-registry beats remapped form in local-scan", () => {
189
- // Local prompt opsx-foo.md exists; registry has skill opsx:foo.
190
- writeFileSync(join(promptsDir, "opsx-foo.md"), "prompt body");
191
- const skillPath = makeSkillFile("registry/outer/SKILL.md", "skill body");
192
- const pi = {
193
- getCommands: () => [{ name: "opsx:foo", source: "skill", path: skillPath }],
194
- };
195
- // /opsx:foo: outer-loop probes original form across ALL stores first.
196
- // Step 3 hit on registry — must NOT fall through to remapped opsx-foo local prompt.
197
- const result = expandPromptTemplateFromDisk("/opsx:foo", tmpDir, pi);
198
- expect(result.startsWith('<skill name="opsx:foo" location="')).toBe(true);
199
- expect(result).not.toContain("prompt body");
200
- });
201
-
202
- // Change: resolve-global-prompt-templates-from-dashboard — source:"prompt" via pi.getCommands().
203
-
204
- it("expands a global prompt template resolved via pi.getCommands source:prompt (sourceInfo.path — real pi shape)", () => {
205
- const promptPath = join(tmpDir, "registry", "session-summary.md");
206
- mkdirSync(dirname(promptPath), { recursive: true });
207
- writeFileSync(promptPath, "---\ndescription: Summarize\n---\nSummarize this session");
208
- // Real pi getCommands() returns the path under sourceInfo, NOT top-level path.
209
- const pi = {
210
- getCommands: () => [
211
- { name: "session-summary", source: "prompt", sourceInfo: { path: promptPath, source: "local", scope: "user" } },
212
- ],
213
- };
214
- const result = expandPromptTemplateFromDisk("/session-summary extra args", tmpDir, pi);
215
- // Prompt templates are NOT wrapped in a <skill> envelope.
216
- expect(result).not.toContain("<skill name=");
217
- expect(result.startsWith("Summarize this session")).toBe(true);
218
- expect(result.endsWith("\n\nextra args")).toBe(true);
219
- });
220
-
221
- it("expands a global prompt template via top-level path (legacy / stub shape)", () => {
222
- const promptPath = join(tmpDir, "registry", "legacy-summary.md");
223
- mkdirSync(dirname(promptPath), { recursive: true });
224
- writeFileSync(promptPath, "Legacy body");
225
- const pi = {
226
- getCommands: () => [
227
- { name: "legacy-summary", source: "prompt", path: promptPath },
228
- ],
229
- };
230
- expect(expandPromptTemplateFromDisk("/legacy-summary", tmpDir, pi)).toBe("Legacy body");
231
- });
232
-
233
- it("ignores a malformed getCommands entry (non-string path) without throwing", () => {
234
- const pi = {
235
- getCommands: () => [
236
- { name: "session-summary", source: "prompt", sourceInfo: { path: 12345 } },
237
- { name: "session-summary", source: "prompt", path: null },
238
- ],
239
- };
240
- // Malformed paths => no resolution, raw text returned (no throw).
241
- expect(expandPromptTemplateFromDisk("/session-summary", tmpDir, pi)).toBe("/session-summary");
242
- });
243
-
244
- it("tolerates a non-array getCommands() return", () => {
245
- const pi = { getCommands: () => null };
246
- expect(expandPromptTemplateFromDisk("/session-summary", tmpDir, pi)).toBe("/session-summary");
247
- });
248
-
249
- it("expands a colon-aliased prompt template registered with hyphen via pi.getCommands", () => {
250
- const promptPath = join(tmpDir, "registry", "session-summary.md");
251
- mkdirSync(dirname(promptPath), { recursive: true });
252
- writeFileSync(promptPath, "Summarize this session");
253
- const pi = {
254
- getCommands: () => [
255
- { name: "session-summary", source: "prompt", sourceInfo: { path: promptPath } },
256
- ],
257
- };
258
- const result = expandPromptTemplateFromDisk("/session:summary", tmpDir, pi);
259
- expect(result).toBe("Summarize this session");
260
- });
261
-
262
- it("misspelled name with wrong separator returns input unchanged", () => {
263
- rmSync(tmpDir, { recursive: true, force: true });
264
- mkdirSync(tmpDir, { recursive: true });
265
- const result = expandPromptTemplateFromDisk("/opsx:nonexistent foo", tmpDir);
266
- expect(result).toBe("/opsx:nonexistent foo");
267
- });
268
- });
269
-
270
- describe("loadPromptTemplate (executable-mode frontmatter)", () => {
271
- it("resolves executable: bash to kind exec", () => {
272
- writeFileSync(
273
- join(promptsDir, "exec-cmd.md"),
274
- "---\nexecutable: bash\n---\necho hi",
275
- );
276
- const loaded = loadPromptTemplate("/exec-cmd", tmpDir);
277
- expect(loaded).toEqual({ kind: "exec", body: "echo hi", excludeFromContext: true, argsString: "" });
278
- });
279
-
280
- it("defaults excludeFromContext to true for executable: bash", () => {
281
- writeFileSync(join(promptsDir, "exec-default.md"), "---\nexecutable: bash\n---\necho hi");
282
- const loaded = loadPromptTemplate("/exec-default", tmpDir);
283
- expect(loaded?.kind).toBe("exec");
284
- if (loaded?.kind === "exec") expect(loaded.excludeFromContext).toBe(true);
285
- });
286
-
287
- it("honours excludeFromContext: false override", () => {
288
- writeFileSync(
289
- join(promptsDir, "exec-capture.md"),
290
- "---\nexecutable: bash\nexcludeFromContext: false\n---\necho hi",
291
- );
292
- const loaded = loadPromptTemplate("/exec-capture", tmpDir);
293
- expect(loaded?.kind).toBe("exec");
294
- if (loaded?.kind === "exec") expect(loaded.excludeFromContext).toBe(false);
295
- });
296
-
297
- it("carries args string through to exec result", () => {
298
- writeFileSync(join(promptsDir, "exec-args.md"), "---\nexecutable: bash\n---\necho \"$1\"");
299
- const loaded = loadPromptTemplate("/exec-args abc 123", tmpDir);
300
- expect(loaded?.kind).toBe("exec");
301
- if (loaded?.kind === "exec") expect(loaded.argsString).toBe("abc 123");
302
- });
303
-
304
- it("unsupported executable value falls back to kind llm (graceful degrade)", () => {
305
- writeFileSync(join(promptsDir, "exec-node.md"), "---\nexecutable: node\n---\nbody text");
306
- const loaded = loadPromptTemplate("/exec-node", tmpDir);
307
- expect(loaded).toEqual({ kind: "llm", text: "body text" });
308
- });
309
-
310
- it("ignores unknown frontmatter keys (forward compat) while still exec", () => {
311
- writeFileSync(
312
- join(promptsDir, "exec-future.md"),
313
- "---\nexecutable: bash\nfutureField: 42\n---\necho hi",
314
- );
315
- const loaded = loadPromptTemplate("/exec-future", tmpDir);
316
- expect(loaded?.kind).toBe("exec");
317
- });
318
-
319
- it("malformed (unclosed) frontmatter falls back to llm, never throws", () => {
320
- // No trailing `---`: the whole file (including the leading ---) is body.
321
- writeFileSync(join(promptsDir, "exec-bad.md"), "---\nexecutable: bash\necho hi");
322
- const loaded = loadPromptTemplate("/exec-bad", tmpDir);
323
- expect(loaded?.kind).toBe("llm");
324
- });
325
-
326
- it("frontmatter line without colon is ignored, executable still parses", () => {
327
- writeFileSync(
328
- join(promptsDir, "exec-nocolon.md"),
329
- "---\nexecutable: bash\nstraylinewithoutcolon\n---\necho hi",
330
- );
331
- const loaded = loadPromptTemplate("/exec-nocolon", tmpDir);
332
- expect(loaded?.kind).toBe("exec");
333
- });
334
-
335
- it("value containing a colon parses (split on first colon)", () => {
336
- writeFileSync(
337
- join(promptsDir, "exec-colonval.md"),
338
- "---\nexecutable: bash\ndescription: foo: bar\n---\necho hi",
339
- );
340
- const loaded = loadPromptTemplate("/exec-colonval", tmpDir);
341
- expect(loaded?.kind).toBe("exec");
342
- });
343
-
344
- it("regular template without executable resolves to kind llm with args appended", () => {
345
- const loaded = loadPromptTemplate("/opsx-continue my-change", tmpDir);
346
- expect(loaded?.kind).toBe("llm");
347
- if (loaded?.kind === "llm") {
348
- expect(loaded.text).toContain("Continue the change");
349
- expect(loaded.text).toContain("my-change");
350
- }
351
- });
352
-
353
- it("returns null when no template matched", () => {
354
- expect(loadPromptTemplate("/nonexistent", tmpDir)).toBeNull();
355
- });
356
-
357
- it("resolves a bundled command via pi.getCommands() when cwd lacks the skill (real/Docker session)", () => {
358
- // Skill installed OUTSIDE cwd (mimics extension install dir). cwd = tmpDir
359
- // has no .pi/skills/pi-dashboard. Registry surfaces the skill's SKILL.md.
360
- const installDir = join(tmpDir, "installed", "pi-dashboard");
361
- const cmdDir = join(installDir, "commands");
362
- mkdirSync(cmdDir, { recursive: true });
363
- const skillMd = join(installDir, "SKILL.md");
364
- writeFileSync(skillMd, "---\nname: pi-dashboard\n---\nskill body");
365
- writeFileSync(join(cmdDir, "dashboard-server-health.md"), "---\nexecutable: bash\n---\necho ok");
366
- // Session cwd: a sibling dir with NO skill on disk.
367
- const sessionCwd = join(tmpDir, "some-user-project");
368
- mkdirSync(sessionCwd, { recursive: true });
369
- const pi = {
370
- getCommands: () => [
371
- { name: "pi-dashboard", source: "skill", sourceInfo: { path: skillMd } },
372
- ],
373
- };
374
- const loaded = loadPromptTemplate("/dashboard:server-health", sessionCwd, pi);
375
- expect(loaded?.kind).toBe("exec");
376
- if (loaded?.kind === "exec") expect(loaded.body).toBe("echo ok");
377
- });
378
-
379
- it("resolves a skill-bundled command from <skill>/commands/*.md (colon alias)", () => {
380
- const cmdDir = join(skillsDir, "pi-dashboard", "commands");
381
- mkdirSync(cmdDir, { recursive: true });
382
- writeFileSync(join(skillsDir, "pi-dashboard", "SKILL.md"), "---\nname: pi-dashboard\n---\nskill body");
383
- writeFileSync(
384
- join(cmdDir, "dashboard-server-health.md"),
385
- '---\nexecutable: bash\n---\ncurl -s "$PI_DASHBOARD_BASE/api/health"',
386
- );
387
- const loaded = loadPromptTemplate("/dashboard:server-health", tmpDir);
388
- expect(loaded?.kind).toBe("exec");
389
- if (loaded?.kind === "exec") expect(loaded.body).toContain("/api/health");
390
- });
391
-
392
- it("expandPromptTemplateFromDisk returns ORIGINAL text for an exec template (never leaks bash body to LLM)", () => {
393
- writeFileSync(join(promptsDir, "exec-legacy.md"), "---\nexecutable: bash\n---\necho hi");
394
- // Multi-line passthrough path calls this then sendUserMessage; must NOT
395
- // return the raw bash body. See change: add-dashboard-slash-commands.
396
- expect(expandPromptTemplateFromDisk("/exec-legacy", tmpDir)).toBe("/exec-legacy");
397
- });
398
- });
@@ -1,182 +0,0 @@
1
- /**
2
- * registerEntry honors the native user-authored `~/.pi/agent/models.json`:
3
- * registers the UNION of discovered + native ids, resolves native capability
4
- * metadata (contextWindow/maxTokens/reasoning/thinkingLevelMap/compat/input/cost)
5
- * ahead of the enrichment fallback, and stays defensive (malformed file /
6
- * discovery outage → fallback, no throw).
7
- *
8
- * Driven through reloadProviders() so registerEntry runs end-to-end.
9
- *
10
- * See change: honor-native-models-json-metadata (test-plan E9/E10/X2/X3, §3).
11
- */
12
- import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
13
- import { tmpdir } from "node:os";
14
- import { join } from "node:path";
15
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
16
-
17
- async function importFresh() {
18
- vi.resetModules();
19
- return (await import("../provider-register.js")) as typeof import("../provider-register.js");
20
- }
21
-
22
- function makeMockPi() {
23
- const registerProvider = vi.fn();
24
- const pi = {
25
- registerProvider,
26
- unregisterProvider: vi.fn(),
27
- events: { on: vi.fn(), emit: vi.fn() },
28
- on: vi.fn(),
29
- } as any;
30
- return { pi, registerProvider };
31
- }
32
-
33
- function writeProvidersJson(home: string, providers: Record<string, any>) {
34
- const dir = join(home, ".pi", "agent");
35
- mkdirSync(dir, { recursive: true });
36
- writeFileSync(join(dir, "providers.json"), JSON.stringify({ providers }, null, 2), "utf-8");
37
- }
38
-
39
- function writeModelsJson(home: string, text: string) {
40
- const dir = join(home, ".pi", "agent");
41
- mkdirSync(dir, { recursive: true });
42
- writeFileSync(join(dir, "models.json"), text, "utf-8");
43
- }
44
-
45
- /** The single models config passed to registerProvider for `name`. */
46
- function lastConfig(registerProvider: any, name: string): any {
47
- const calls = registerProvider.mock.calls.filter((c: any[]) => c[0] === name && c[1]?.models);
48
- return calls[calls.length - 1]?.[1];
49
- }
50
- function modelById(config: any, id: string): any {
51
- return config?.models?.find((m: any) => m.id === id);
52
- }
53
-
54
- describe("registerEntry — native models.json honored", () => {
55
- let tmpHome: string;
56
- const originalHome = process.env.HOME;
57
- const originalFetch = globalThis.fetch;
58
-
59
- beforeEach(() => {
60
- tmpHome = mkdtempSync(join(tmpdir(), "provider-native-"));
61
- process.env.HOME = tmpHome;
62
- });
63
- afterEach(() => {
64
- globalThis.fetch = originalFetch;
65
- process.env.HOME = originalHome;
66
- rmSync(tmpHome, { recursive: true, force: true });
67
- });
68
-
69
- it("registers the UNION of discovered ids and native models.json ids (E9)", async () => {
70
- globalThis.fetch = vi.fn(async () =>
71
- new Response(JSON.stringify({ data: [{ id: "a" }] }), { status: 200 }),
72
- ) as any;
73
- writeProvidersJson(tmpHome, { newapi: { baseUrl: "https://x/v1", apiKey: "k", api: "openai-completions" } });
74
- writeModelsJson(tmpHome, JSON.stringify({ providers: { newapi: { models: [{ id: "a" }, { id: "b" }] } } }));
75
-
76
- const mod = await importFresh();
77
- const { pi, registerProvider } = makeMockPi();
78
- await mod.reloadProviders(pi);
79
-
80
- const config = lastConfig(registerProvider, "newapi");
81
- expect(config.models.map((m: any) => m.id).sort()).toEqual(["a", "b"]);
82
- // `b` is authored-only (absent from /v1/models) but still registered.
83
- expect(modelById(config, "b")).toBeDefined();
84
- });
85
-
86
- it("native metadata wins over the enrichment fallback, carrying map + compat (E10)", async () => {
87
- globalThis.fetch = vi.fn(async () =>
88
- new Response(JSON.stringify({ data: [{ id: "glm-5.2" }] }), { status: 200 }),
89
- ) as any;
90
- writeProvidersJson(tmpHome, { newapi: { baseUrl: "https://x/v1", apiKey: "k", api: "openai-completions" } });
91
- const map = { minimal: null, xhigh: "xhigh", max: "max" };
92
- const compat = { thinkingFormat: "deepseek", supportsReasoningEffort: true };
93
- writeModelsJson(
94
- tmpHome,
95
- JSON.stringify({
96
- providers: {
97
- newapi: {
98
- models: [
99
- {
100
- id: "glm-5.2",
101
- contextWindow: 200000,
102
- maxTokens: 65536,
103
- reasoning: true,
104
- thinkingLevelMap: map,
105
- compat,
106
- input: ["text", "image"],
107
- cost: { input: 3, output: 15 },
108
- },
109
- ],
110
- },
111
- },
112
- }),
113
- );
114
-
115
- const mod = await importFresh();
116
- const { pi, registerProvider } = makeMockPi();
117
- await mod.reloadProviders(pi);
118
-
119
- const m = modelById(lastConfig(registerProvider, "newapi"), "glm-5.2");
120
- expect(m.contextWindow).toBe(200000);
121
- expect(m.maxTokens).toBe(65536);
122
- expect(m.reasoning).toBe(true);
123
- expect(m.thinkingLevelMap).toEqual(map);
124
- expect(m.compat).toEqual(compat);
125
- expect(m.input).toEqual(["text", "image"]);
126
- expect(m.cost).toMatchObject({ input: 3, output: 15 });
127
- // NOT the openai-completions fallback floors
128
- expect(m.contextWindow).not.toBe(128000);
129
- });
130
-
131
- it("falls back to enrichment defaults when no native entry exists (E10 negative / §3.3)", async () => {
132
- globalThis.fetch = vi.fn(async () =>
133
- new Response(JSON.stringify({ data: [{ id: "plain" }] }), { status: 200 }),
134
- ) as any;
135
- writeProvidersJson(tmpHome, { newapi: { baseUrl: "https://x/v1", apiKey: "k", api: "openai-completions" } });
136
- // no models.json
137
-
138
- const mod = await importFresh();
139
- const { pi, registerProvider } = makeMockPi();
140
- await mod.reloadProviders(pi);
141
-
142
- const m = modelById(lastConfig(registerProvider, "newapi"), "plain");
143
- expect(m).toBeDefined();
144
- expect(m.contextWindow).toBe(128000); // openai-completions fallback floor
145
- expect(m.thinkingLevelMap).toBeUndefined();
146
- });
147
-
148
- it("malformed models.json → falls back to enrichment without throwing (X2)", async () => {
149
- vi.spyOn(console, "warn").mockImplementation(() => {});
150
- globalThis.fetch = vi.fn(async () =>
151
- new Response(JSON.stringify({ data: [{ id: "plain" }] }), { status: 200 }),
152
- ) as any;
153
- writeProvidersJson(tmpHome, { newapi: { baseUrl: "https://x/v1", apiKey: "k", api: "openai-completions" } });
154
- writeModelsJson(tmpHome, "{ not valid json");
155
-
156
- const mod = await importFresh();
157
- const { pi, registerProvider } = makeMockPi();
158
- await expect(mod.reloadProviders(pi)).resolves.toBeDefined();
159
-
160
- const m = modelById(lastConfig(registerProvider, "newapi"), "plain");
161
- expect(m).toBeDefined();
162
- expect(m.contextWindow).toBe(128000); // fallback still applies
163
- });
164
-
165
- it("discovery outage → native-declared model still registered (X3 / AC5)", async () => {
166
- // /v1/models unreachable
167
- globalThis.fetch = vi.fn(async () => new Response("nope", { status: 500 })) as any;
168
- writeProvidersJson(tmpHome, { newapi: { baseUrl: "https://x/v1", apiKey: "k", api: "openai-completions" } });
169
- writeModelsJson(
170
- tmpHome,
171
- JSON.stringify({ providers: { newapi: { models: [{ id: "glm-5.2", contextWindow: 200000, reasoning: true }] } } }),
172
- );
173
-
174
- const mod = await importFresh();
175
- const { pi, registerProvider } = makeMockPi();
176
- await mod.reloadProviders(pi);
177
-
178
- const m = modelById(lastConfig(registerProvider, "newapi"), "glm-5.2");
179
- expect(m).toBeDefined();
180
- expect(m.contextWindow).toBe(200000);
181
- });
182
- });