@blackbelt-technology/pi-agent-dashboard 0.10.0 → 0.11.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 (255) hide show
  1. package/AGENTS.md +2 -2
  2. package/README.md +47 -6
  3. package/docs/architecture.md +1369 -63
  4. package/package.json +14 -9
  5. package/packages/extension/package.json +5 -3
  6. package/packages/extension/src/bridge-handlers/dispatch.ts +57 -3
  7. package/packages/extension/src/bridge-handlers/instance.ts +10 -1
  8. package/packages/extension/src/bridge-handlers/lifecycle.ts +65 -26
  9. package/packages/extension/src/bridge-ticket-client.ts +61 -7
  10. package/packages/extension/src/bridge-tls-checks.ts +79 -0
  11. package/packages/extension/src/bridge.ts +41 -28
  12. package/packages/extension/src/canvas-tool.ts +2 -0
  13. package/packages/extension/src/command-handler.ts +80 -6
  14. package/packages/extension/src/connect-target.ts +23 -0
  15. package/packages/extension/src/connection.ts +30 -7
  16. package/packages/extension/src/dashboard-http-origin.ts +88 -0
  17. package/packages/extension/src/dev-build.ts +11 -1
  18. package/packages/extension/src/git-link-builder.ts +11 -2
  19. package/packages/extension/src/inbound-limits.ts +138 -0
  20. package/packages/extension/src/local-token-header.ts +77 -6
  21. package/packages/extension/src/model-refresh.ts +69 -0
  22. package/packages/extension/src/pinned-endpoint.ts +44 -0
  23. package/packages/extension/src/project-trust-live.ts +143 -0
  24. package/packages/extension/src/project-trust.ts +159 -20
  25. package/packages/extension/src/provider-register.ts +59 -18
  26. package/packages/extension/src/remote-registration-gate.ts +21 -21
  27. package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
  28. package/packages/extension/src/role-model-tools.ts +47 -6
  29. package/packages/extension/src/server-auto-start.ts +1 -1
  30. package/packages/extension/src/server-proof-probe.ts +117 -0
  31. package/packages/extension/src/session-sync.ts +42 -12
  32. package/packages/extension/src/vault-delivery.ts +11 -1
  33. package/packages/server/package.json +8 -8
  34. package/packages/server/src/access/access-grants.ts +61 -8
  35. package/packages/server/src/access/access-health.ts +10 -0
  36. package/packages/server/src/access/access-plane.ts +5 -1
  37. package/packages/server/src/access/containment-gate.ts +55 -17
  38. package/packages/server/src/access/cwd-verdict.ts +3 -3
  39. package/packages/server/src/access/pi-trust-live.ts +244 -0
  40. package/packages/server/src/access/pi-trust-mirror-service.ts +44 -11
  41. package/packages/server/src/access/planes.ts +106 -1
  42. package/packages/server/src/access/preview-egress-store.ts +153 -0
  43. package/packages/server/src/access/prompt-channel.ts +5 -0
  44. package/packages/server/src/access/provisioning-wiring.ts +113 -0
  45. package/packages/server/src/access/provisioning.ts +763 -0
  46. package/packages/server/src/access/yolo-session.ts +54 -2
  47. package/packages/server/src/acp-bridge/acp-session-adapter.ts +8 -3
  48. package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
  49. package/packages/server/src/auth/audit-log.ts +80 -0
  50. package/packages/server/src/auth/auth-plugin.ts +44 -25
  51. package/packages/server/src/auth/auth.ts +24 -4
  52. package/packages/server/src/auth/bearer-auth.ts +52 -12
  53. package/packages/server/src/auth/cors-origin.ts +76 -29
  54. package/packages/server/src/auth/csp-report-paths.ts +31 -0
  55. package/packages/server/src/auth/csp-report-sink.ts +302 -0
  56. package/packages/server/src/auth/csp-report-store.ts +406 -0
  57. package/packages/server/src/auth/csp.ts +105 -9
  58. package/packages/server/src/auth/dashboard-credential-store.ts +4 -0
  59. package/packages/server/src/auth/dashboard-state-caller.ts +29 -0
  60. package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
  61. package/packages/server/src/auth/local-proof.ts +69 -18
  62. package/packages/server/src/auth/localhost-guard.ts +48 -10
  63. package/packages/server/src/auth/nav-intent.ts +72 -0
  64. package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
  65. package/packages/server/src/auth/passkey/passkey-pages.ts +17 -81
  66. package/packages/server/src/auth/passkey/passkey-routes.ts +8 -0
  67. package/packages/server/src/auth/pi-legacy-credentials.ts +3 -0
  68. package/packages/server/src/auth/plugin-server-trust.ts +29 -0
  69. package/packages/server/src/auth/plugin-trust-store.ts +103 -0
  70. package/packages/server/src/auth/proven-tls.ts +45 -0
  71. package/packages/server/src/auth/provider-auth-storage.ts +6 -1
  72. package/packages/server/src/auth/radius-mcp.ts +1 -1
  73. package/packages/server/src/auth/request-principal.ts +32 -0
  74. package/packages/server/src/auth/secret-rotation.ts +246 -0
  75. package/packages/server/src/auth/secure-origin.ts +56 -0
  76. package/packages/server/src/auth/serve-app-host.ts +111 -11
  77. package/packages/server/src/auth/ws-ticket.ts +39 -1
  78. package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
  79. package/packages/server/src/browser-handlers/directory-handler.ts +23 -0
  80. package/packages/server/src/browser-handlers/folder-gate.ts +55 -0
  81. package/packages/server/src/browser-handlers/handler-context.ts +25 -2
  82. package/packages/server/src/browser-handlers/session-action-handler.ts +9 -1
  83. package/packages/server/src/browser-handlers/subscription-handler.ts +100 -2
  84. package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
  85. package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
  86. package/packages/server/src/cli.ts +210 -39
  87. package/packages/server/src/config-api.ts +23 -1
  88. package/packages/server/src/config-snapshot.ts +48 -1
  89. package/packages/server/src/directory-service.ts +160 -54
  90. package/packages/server/src/event-wiring.ts +143 -108
  91. package/packages/server/src/git-worktree/git-operations.ts +44 -10
  92. package/packages/server/src/git-worktree/redact-git-text.ts +124 -0
  93. package/packages/server/src/git-worktree/ref-arg.ts +39 -0
  94. package/packages/server/src/git-worktree/worktree-init-trust.ts +43 -1
  95. package/packages/server/src/identity/http-road-classification.ts +13 -1
  96. package/packages/server/src/identity/ws-message-scope.ts +1 -0
  97. package/packages/server/src/identity/ws-road-classification.ts +1 -0
  98. package/packages/server/src/known-server-moves.ts +36 -15
  99. package/packages/server/src/lib/browse-roots.ts +118 -17
  100. package/packages/server/src/lib/client-dist.ts +36 -21
  101. package/packages/server/src/lib/dashboard-state-guard.ts +230 -0
  102. package/packages/server/src/lib/diagram-render.ts +4 -6
  103. package/packages/server/src/lib/eml.ts +3 -8
  104. package/packages/server/src/lib/file-cwd-admission.ts +145 -0
  105. package/packages/server/src/lib/grep-worker.ts +23 -0
  106. package/packages/server/src/lib/grep.ts +93 -7
  107. package/packages/server/src/lib/index-html.ts +81 -0
  108. package/packages/server/src/lib/office-preview.ts +2 -3
  109. package/packages/server/src/lib/path-containment.ts +7 -0
  110. package/packages/server/src/lib/resolve-file-mention.ts +11 -9
  111. package/packages/server/src/lib/route-admission.ts +80 -0
  112. package/packages/server/src/lib/writable-md-target.ts +4 -0
  113. package/packages/server/src/lifecycle/recovery-server.ts +65 -18
  114. package/packages/server/src/live-server/capability-redact.ts +15 -0
  115. package/packages/server/src/live-server/live-browser-gate.ts +22 -0
  116. package/packages/server/src/live-server/live-capability.ts +224 -17
  117. package/packages/server/src/live-server/live-csp-report.ts +63 -0
  118. package/packages/server/src/live-server/live-csp.ts +93 -0
  119. package/packages/server/src/live-server/live-egress.ts +435 -0
  120. package/packages/server/src/live-server/live-exposure.ts +149 -0
  121. package/packages/server/src/live-server/live-log.ts +21 -0
  122. package/packages/server/src/live-server/live-origin-scan.ts +298 -0
  123. package/packages/server/src/live-server/live-server-manager.ts +209 -33
  124. package/packages/server/src/live-server/live-server-proxy.ts +162 -17
  125. package/packages/server/src/live-server/live-static.ts +228 -0
  126. package/packages/server/src/openspec/dependencies-file.ts +122 -0
  127. package/packages/server/src/openspec/openspec-change-watcher.ts +3 -1
  128. package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
  129. package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +72 -26
  130. package/packages/server/src/openspec/openspec-poll-worker-pool.ts +48 -12
  131. package/packages/server/src/openspec/openspec-poll-worker.ts +95 -9
  132. package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
  133. package/packages/server/src/openspec/workflow-schema.ts +141 -267
  134. package/packages/server/src/package/npm-search-proxy.ts +5 -2
  135. package/packages/server/src/package/provider-probe.ts +8 -2
  136. package/packages/server/src/pairing/browser-gateway.ts +188 -12
  137. package/packages/server/src/pairing/device-token-services.ts +26 -0
  138. package/packages/server/src/pairing/paired-devices.ts +335 -22
  139. package/packages/server/src/pairing/pairing.ts +34 -4
  140. package/packages/server/src/pairing/socket-locality.ts +26 -0
  141. package/packages/server/src/persistence/preferences-store.ts +9 -0
  142. package/packages/server/src/pi/bridge-channel.ts +33 -0
  143. package/packages/server/src/pi/bridge-upgrade-auth.ts +18 -3
  144. package/packages/server/src/pi/gateway-listeners.ts +9 -3
  145. package/packages/server/src/pi/host-project-trust.ts +14 -6
  146. package/packages/server/src/pi/pi-gateway.ts +191 -21
  147. package/packages/server/src/pi/resource-toggle-trust.ts +1 -1
  148. package/packages/server/src/plugin-discovery-wiring.ts +142 -0
  149. package/packages/server/src/plugin-event-seam.ts +116 -4
  150. package/packages/server/src/plugin-runtime-clients.ts +89 -0
  151. package/packages/server/src/routes/access-routes.ts +159 -9
  152. package/packages/server/src/routes/agent-event-stream-routes.ts +137 -0
  153. package/packages/server/src/routes/canvas-types-routes.ts +20 -6
  154. package/packages/server/src/routes/csp-violations-routes.ts +162 -0
  155. package/packages/server/src/routes/file-routes.ts +329 -209
  156. package/packages/server/src/routes/file-write-binary-routes.ts +77 -20
  157. package/packages/server/src/routes/folder-project-routes.ts +18 -12
  158. package/packages/server/src/routes/git-routes.ts +319 -203
  159. package/packages/server/src/routes/grep-routes.ts +38 -14
  160. package/packages/server/src/routes/known-servers-routes.ts +189 -91
  161. package/packages/server/src/routes/live-server-routes.ts +378 -15
  162. package/packages/server/src/routes/local-proof-routes.ts +14 -0
  163. package/packages/server/src/routes/nav-intent-routes.ts +46 -0
  164. package/packages/server/src/routes/openspec-group-routes.ts +53 -44
  165. package/packages/server/src/routes/openspec-routes.ts +379 -28
  166. package/packages/server/src/routes/package-routes.ts +58 -10
  167. package/packages/server/src/routes/pairing-routes.ts +146 -10
  168. package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
  169. package/packages/server/src/routes/plugin-activation-routes.ts +59 -0
  170. package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
  171. package/packages/server/src/routes/provider-auth-routes.ts +15 -2
  172. package/packages/server/src/routes/resource-activation-routes.ts +18 -4
  173. package/packages/server/src/routes/session-routes.ts +51 -4
  174. package/packages/server/src/routes/system-routes.ts +84 -15
  175. package/packages/server/src/routes/ui-link-base.ts +88 -0
  176. package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
  177. package/packages/server/src/server.ts +648 -137
  178. package/packages/server/src/session/hydration-state.ts +148 -0
  179. package/packages/server/src/session/memory-session-manager.ts +7 -0
  180. package/packages/server/src/session/replay-exit-controller.ts +221 -0
  181. package/packages/server/src/session/retained-transcript.ts +9 -2
  182. package/packages/server/src/session/session-load-worker.ts +11 -2
  183. package/packages/server/src/spawn-process/headless-pid-registry.ts +14 -9
  184. package/packages/server/src/terminal/terminal-manager.ts +54 -46
  185. package/packages/server/src/tls/tls-bridge-route.ts +61 -0
  186. package/packages/server/src/tls/tls-config-validation.ts +2 -0
  187. package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
  188. package/packages/server/src/vault/vault-delivery-hub.ts +155 -25
  189. package/packages/server/src/watch-files-handler.ts +66 -0
  190. package/packages/shared/package.json +1 -1
  191. package/packages/shared/src/browser-protocol.ts +148 -2
  192. package/packages/shared/src/canvas-declare.ts +27 -0
  193. package/packages/shared/src/config.ts +372 -53
  194. package/packages/shared/src/containment-guard.ts +35 -0
  195. package/packages/shared/src/dashboard-plugin/anthropic-peer-names.ts +9 -0
  196. package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
  197. package/packages/shared/src/dashboard-plugin/file-handler.ts +2 -0
  198. package/packages/shared/src/dashboard-plugin/host-api.ts +61 -0
  199. package/packages/shared/src/dashboard-plugin/host-fx-classes.ts +23 -0
  200. package/packages/shared/src/dashboard-plugin/host-import-map.ts +38 -0
  201. package/packages/shared/src/dashboard-plugin/index.ts +2 -0
  202. package/packages/shared/src/dashboard-plugin/manifest-types.ts +54 -1
  203. package/packages/shared/src/dashboard-plugin/plugin-status.ts +54 -0
  204. package/packages/shared/src/dashboard-plugin/slot-props.ts +45 -3
  205. package/packages/shared/src/dashboard-plugin/slot-types.ts +8 -0
  206. package/packages/shared/src/dashboard-plugin/subagent-types.ts +219 -0
  207. package/packages/shared/src/dashboard-plugin/ui-primitives.ts +28 -0
  208. package/packages/shared/src/display-prefs.ts +13 -0
  209. package/packages/shared/src/doctor-core.ts +94 -27
  210. package/packages/shared/src/live-server.ts +141 -0
  211. package/packages/shared/src/local-proof-signal.ts +16 -0
  212. package/packages/shared/src/loopback-host.ts +26 -0
  213. package/packages/shared/src/mcp/verb-tiers.generated.ts +178 -0
  214. package/packages/shared/src/mdns-discovery.ts +25 -6
  215. package/packages/shared/src/nav-intent.ts +29 -0
  216. package/packages/shared/src/openspec-dependencies.ts +760 -0
  217. package/packages/shared/src/openspec-poller.ts +3 -2
  218. package/packages/shared/src/pairing-knock-client.ts +44 -4
  219. package/packages/shared/src/pi-trust-live-query.ts +93 -0
  220. package/packages/shared/src/pi-trust-mirror-snapshot.ts +5 -7
  221. package/packages/shared/src/pi-trust-mirror-types.ts +36 -3
  222. package/packages/shared/src/pi-trust-mirror.ts +29 -3
  223. package/packages/shared/src/pi-trust-resource-digest.ts +255 -0
  224. package/packages/shared/src/platform/ensure-bundled-git.ts +57 -34
  225. package/packages/shared/src/platform/git-source.ts +88 -26
  226. package/packages/shared/src/platform/git.ts +14 -8
  227. package/packages/shared/src/platform/process.ts +48 -4
  228. package/packages/shared/src/platform/resolve-pi-shell.ts +76 -0
  229. package/packages/shared/src/platform/select-git-source.ts +7 -0
  230. package/packages/shared/src/plugin-route-cwd.ts +95 -0
  231. package/packages/shared/src/preview-egress.ts +138 -0
  232. package/packages/shared/src/project-root.ts +16 -0
  233. package/packages/shared/src/protocol.ts +40 -1
  234. package/packages/shared/src/recommended-extensions.ts +18 -0
  235. package/packages/shared/src/recovery-timing.ts +27 -0
  236. package/packages/shared/src/remote-credentials.ts +63 -0
  237. package/packages/shared/src/rest-api.ts +55 -8
  238. package/packages/shared/src/route-tiers.ts +55 -1
  239. package/packages/shared/src/runtime-overlay/archive-safety.d.mts +2 -0
  240. package/packages/shared/src/runtime-overlay/archive-safety.mjs +33 -0
  241. package/packages/shared/src/runtime-overlay/manifest.d.mts +7 -0
  242. package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
  243. package/packages/shared/src/safe-local-path.ts +24 -0
  244. package/packages/shared/src/sanitize-profiles.ts +98 -0
  245. package/packages/shared/src/server-launcher.ts +9 -1
  246. package/packages/shared/src/server-pinning.ts +55 -2
  247. package/packages/shared/src/server-routes.ts +462 -0
  248. package/packages/shared/src/session-ui-path.ts +11 -0
  249. package/packages/shared/src/tls-only-token.ts +16 -0
  250. package/packages/shared/src/tool-registry/definitions.ts +5 -5
  251. package/packages/shared/src/tool-registry/strategies.ts +12 -11
  252. package/packages/shared/src/types.ts +66 -0
  253. package/packages/shared/src/url-policy.ts +96 -0
  254. package/packages/shared/src/vault-delivery.ts +15 -0
  255. package/packages/shared/src/ws-message-tiers.ts +1 -0
@@ -4,12 +4,12 @@
4
4
  * Generation (scratch root + empty XDG_DATA_HOME, `schema which/fork/validate`,
5
5
  * anchor-checked YAML patch, stamp, staged swap), component-wise stamp
6
6
  * comparison, the six writing actions (enable / disable / update / adopt / pin /
7
- * remove) behind one write guard, and the poll-side status. The filesystem
8
- * parts (`inspectSchema`, `computeWorkflowSchemaStatus`, `fingerprintDir`,
9
- * `enumerateActiveChanges`) never spawn the CLI so they can run in a worker
10
- * thread; every CLI call goes through the injectable `CliRunner`.
7
+ * remove) behind one write guard. The filesystem-only status (stamp, config,
8
+ * change enumeration, `inspectSchema`, `fingerprintDir`) lives in the
9
+ * worker-safe `workflow-schema-status.ts` and is re-exported here; every CLI
10
+ * call goes through the injectable `CliRunner`.
11
11
  *
12
- * See change: add-pi-spec-driven-schema.
12
+ * See changes: add-pi-spec-driven-schema, move-workflow-schema-status-to-poll-worker.
13
13
  */
14
14
  import crypto from "node:crypto";
15
15
  import fsp from "node:fs/promises";
@@ -31,15 +31,46 @@ import type {
31
31
  } from "@blackbelt-technology/pi-dashboard-shared/types.js";
32
32
  import semver from "semver";
33
33
  import YAML from "yaml";
34
+ import {
35
+ type ConfigFile,
36
+ CURRENT_PATCH,
37
+ changesDirOf,
38
+ compareStamp,
39
+ computeSchemaStatus,
40
+ enumerateActiveChanges,
41
+ errCode,
42
+ fingerprintDir,
43
+ inspectSchema,
44
+ isKebabCaseName,
45
+ lstatOrNull,
46
+ parseStamp,
47
+ readChangeSchema,
48
+ readConfigFile,
49
+ type SchemaInspection,
50
+ type SchemaStatusOptions,
51
+ type StampComparison,
52
+ schemaDirOf,
53
+ schemasDirOf,
54
+ STAMP_KEY,
55
+ WORKFLOW_SCHEMA_NAME,
56
+ type WorkflowSchemaStamp,
57
+ } from "./workflow-schema-status.js";
58
+
59
+ export {
60
+ CURRENT_PATCH,
61
+ compareStamp,
62
+ fingerprintDir,
63
+ inspectSchema,
64
+ parseStamp,
65
+ type SchemaInspection,
66
+ type StampComparison,
67
+ type WorkflowSchemaStamp,
68
+ };
34
69
 
35
- export const CURRENT_PATCH = 1;
36
- const WORKFLOW_SCHEMA_NAME = "pi-spec-driven";
37
70
  const BASE_SCHEMA = "spec-driven";
38
- const STAMP_KEY = "x-pi-dashboard";
39
71
  const DESIGN_ANCHOR = "When to include design.md (create only if any apply):";
40
72
  const DESIGN_REPLACEMENT =
41
73
  'When a full design.md is warranted (otherwise still create design.md containing one line "Not needed: <reason>"):';
42
- const KEBAB = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
43
74
  const RETRYABLE_CODES = new Set(["EPERM", "EBUSY", "EACCES"]);
44
75
  /** Windows rename retry: initial attempt + 5 retries, delays sum to 1.55 s (< 2 s window). */
45
76
  const RETRY_DELAYS_MS: readonly number[] = [50, 100, 200, 400, 800];
@@ -174,10 +205,6 @@ const passThroughSemaphore: Semaphore = {
174
205
 
175
206
  // ── Small helpers ───────────────────────────────────────────────────────────
176
207
 
177
- function errCode(err: unknown): string | undefined {
178
- return (err as NodeJS.ErrnoException | null)?.code;
179
- }
180
-
181
208
  function errMsg(err: unknown): string {
182
209
  return err instanceof Error ? err.message : String(err);
183
210
  }
@@ -194,23 +221,8 @@ function parseJsonObject(stdout: string): Record<string, unknown> | null {
194
221
  }
195
222
  }
196
223
 
197
- async function lstatOrNull(p: string): Promise<import("node:fs").Stats | null> {
198
- try {
199
- return await fsp.lstat(p);
200
- } catch {
201
- return null;
202
- }
203
- }
204
-
205
- const schemasDirOf = (root: string): string => path.join(root, "openspec", "schemas");
206
- const schemaDirOf = (root: string): string => path.join(schemasDirOf(root), WORKFLOW_SCHEMA_NAME);
207
- const changesDirOf = (root: string): string => path.join(root, "openspec", "changes");
208
224
  const rel = (root: string, p: string): string => path.relative(root, p).split(path.sep).join("/");
209
225
 
210
- function isKebabCaseName(name: unknown): name is string {
211
- return typeof name === "string" && KEBAB.test(name);
212
- }
213
-
214
226
  /** Retry a rename on Windows `EPERM`/`EBUSY`/`EACCES`: 5 retries, 1.55 s of backoff in total. */
215
227
  async function renameWithRetry(deps: WorkflowSchemaDeps, from: string, to: string): Promise<void> {
216
228
  for (let attempt = 0; ; attempt++) {
@@ -225,112 +237,7 @@ async function renameWithRetry(deps: WorkflowSchemaDeps, from: string, to: strin
225
237
  }
226
238
  }
227
239
 
228
- // ── Fingerprint, stamp, comparison ──────────────────────────────────────────
229
-
230
- /** sha256 over every file's relative path + content hash (symlinks by target). `null` when `dir` is absent. */
231
- export async function fingerprintDir(dir: string): Promise<string | null> {
232
- if (!(await lstatOrNull(dir))) return null;
233
- const lines: string[] = [];
234
- const walk = async (d: string): Promise<void> => {
235
- const entries = (await fsp.readdir(d, { withFileTypes: true })).sort((a, b) => (a.name < b.name ? -1 : 1));
236
- for (const e of entries) {
237
- const full = path.join(d, e.name);
238
- const r = path.relative(dir, full).split(path.sep).join("/");
239
- if (e.isDirectory()) {
240
- lines.push(`${r}/`);
241
- await walk(full);
242
- } else if (e.isSymbolicLink()) {
243
- lines.push(`${r}\0L:${await fsp.readlink(full)}`);
244
- } else {
245
- lines.push(`${r}\0${crypto.createHash("sha256").update(await fsp.readFile(full)).digest("hex")}`);
246
- }
247
- }
248
- };
249
- await walk(dir);
250
- return crypto.createHash("sha256").update(lines.join("\n")).digest("hex");
251
- }
252
-
253
- export interface WorkflowSchemaStamp {
254
- /** Version of the CLI that generated the schema (`spec-driven@<base>`). */
255
- base: string;
256
- patch: number;
257
- /** Syntactically valid previous default, else `null` (treated as absent). */
258
- previousDefault: string | null;
259
- }
260
-
261
- export function parseStamp(yamlText: string): WorkflowSchemaStamp | null {
262
- let parsed: unknown;
263
- try {
264
- parsed = YAML.parse(yamlText);
265
- } catch {
266
- return null;
267
- }
268
- const raw = (parsed as Record<string, unknown> | null)?.[STAMP_KEY];
269
- if (!raw || typeof raw !== "object") return null;
270
- const s = raw as Record<string, unknown>;
271
- const m = typeof s.derivedFrom === "string" ? /^spec-driven@(.+)$/.exec(s.derivedFrom) : null;
272
- if (!m || !semver.valid(m[1])) return null;
273
- if (typeof s.patch !== "number" || !Number.isInteger(s.patch) || s.patch < 0) return null;
274
- const prev = isKebabCaseName(s.previousDefault) && s.previousDefault !== WORKFLOW_SCHEMA_NAME ? s.previousDefault : null;
275
- return { base: m[1], patch: s.patch, previousDefault: prev };
276
- }
277
-
278
- export type StampComparison = "current" | "outdated" | "newer" | "conflict";
279
-
280
- /** Component-wise: base by semver, patch numerically. Never lexicographic. */
281
- export function compareStamp(
282
- stamp: { base: string; patch: number },
283
- local: { base: string; patch: number },
284
- ): StampComparison {
285
- const base = semver.compare(stamp.base, local.base);
286
- const patch = Math.sign(stamp.patch - local.patch);
287
- const newer = base > 0 || patch > 0;
288
- const older = base < 0 || patch < 0;
289
- if (newer && older) return "conflict";
290
- if (newer) return "newer";
291
- if (older) return "outdated";
292
- return "current";
293
- }
294
-
295
- export interface SchemaInspection {
296
- generated: WorkflowSchemaGenerated;
297
- stamp: WorkflowSchemaStamp | null;
298
- /** Whole-directory fingerprint; `null` when the dir is absent or a symlink. */
299
- fingerprint: string | null;
300
- symlink: boolean;
301
- }
302
-
303
- export interface InspectOptions {
304
- /** Version of the resolved CLI. */
305
- localVersion: string;
306
- /** CLI part for `newer`/`conflict`: does `schema validate` pass locally? Default: assumed valid. */
307
- validateLocal?: (fingerprint: string) => Promise<boolean>;
308
- }
309
-
310
- /** Filesystem-only status of `<root>/openspec/schemas/pi-spec-driven` (no CLI spawn except via `validateLocal`). */
311
- export async function inspectSchema(root: string, opts: InspectOptions): Promise<SchemaInspection> {
312
- const dir = schemaDirOf(root);
313
- const st = await lstatOrNull(dir);
314
- if (!st) return { generated: "none", stamp: null, fingerprint: null, symlink: false };
315
- if (st.isSymbolicLink()) return { generated: "unmanaged", stamp: null, fingerprint: null, symlink: true };
316
- let stamp: WorkflowSchemaStamp | null = null;
317
- if (st.isDirectory()) {
318
- try {
319
- stamp = parseStamp(await fsp.readFile(path.join(dir, "schema.yaml"), "utf8"));
320
- } catch {
321
- stamp = null;
322
- }
323
- }
324
- const fingerprint = st.isDirectory() ? await fingerprintDir(dir).catch(() => null) : null;
325
- if (!stamp || !fingerprint) return { generated: "unmanaged", stamp: null, fingerprint, symlink: false };
326
- const localBase = semver.valid(opts.localVersion);
327
- if (!localBase) return { generated: "incompatible", stamp, fingerprint, symlink: false };
328
- let generated: WorkflowSchemaGenerated = compareStamp(stamp, { base: localBase, patch: CURRENT_PATCH });
329
- if ((generated === "newer" || generated === "conflict") && opts.validateLocal) {
330
- if (!(await opts.validateLocal(fingerprint))) generated = "incompatible";
331
- }
332
- return { generated, stamp, fingerprint, symlink: false };
333
- }
240
+ // ── Status with the `newer`/`conflict` validate ─────────────────────────────
334
241
 
335
242
  async function runValidate(deps: WorkflowSchemaDeps, cwd: string, name: string, xdg?: string): Promise<boolean> {
336
243
  const r = await deps.cli({ op: "validate", name }, { cwd, ...(xdg ? { xdgDataHome: xdg } : {}) });
@@ -372,156 +279,90 @@ export function makeValidateLocal(
372
279
  };
373
280
  }
374
281
 
375
- function inspectWithValidate(root: string, localVersion: string, deps: WorkflowSchemaDeps): Promise<SchemaInspection> {
376
- return inspectSchema(root, { localVersion, validateLocal: makeValidateLocal(root, localVersion, deps) });
377
- }
378
-
379
- // ── Config + change enumeration (filesystem only) ───────────────────────────
380
-
381
- interface ConfigFile {
382
- path: string;
383
- doc: YAML.Document;
384
- /** `schema:` value; `null` when the key is absent. */
385
- configured: string | null;
386
- }
387
-
388
- /** `config.yaml` wins over `config.yml`, as the CLI reads. `null` when neither exists; throws on unparseable YAML / non-string `schema`. */
389
- async function readConfigFile(root: string): Promise<ConfigFile | null> {
390
- for (const name of ["config.yaml", "config.yml"]) {
391
- const p = path.join(root, "openspec", name);
392
- let text: string;
393
- try {
394
- text = await fsp.readFile(p, "utf8");
395
- } catch (err) {
396
- if (errCode(err) === "ENOENT") continue;
397
- throw err;
398
- }
399
- const doc = YAML.parseDocument(text);
400
- if (doc.errors.length > 0) throw new Error(`${name} is not valid YAML: ${doc.errors[0].message}`);
401
- const v: unknown = doc.get("schema");
402
- if (v != null && typeof v !== "string") throw new Error(`${name} has a non-string \`schema:\``);
403
- return { path: p, doc, configured: typeof v === "string" ? v : null };
404
- }
405
- return null;
406
- }
407
-
408
- /** Active changes as OpenSpec enumerates them: real directories only, no `archive/`, no dot-dirs, no symlinks. Sorted. */
409
- async function enumerateActiveChanges(root: string): Promise<string[]> {
410
- let entries: import("node:fs").Dirent[];
411
- try {
412
- entries = await fsp.readdir(changesDirOf(root), { withFileTypes: true });
413
- } catch {
414
- return [];
415
- }
416
- return entries
417
- .filter((e) => e.isDirectory() && !e.isSymbolicLink() && e.name !== "archive" && !e.name.startsWith("."))
418
- .map((e) => e.name)
419
- .sort();
420
- }
421
-
422
- /** `schema:` of `<dir>/.openspec.yaml`: `undefined` = no file, `null` = file without a usable `schema:`. */
423
- async function readChangeSchema(dir: string): Promise<string | null | undefined> {
424
- let text: string;
425
- try {
426
- text = await fsp.readFile(path.join(dir, ".openspec.yaml"), "utf8");
427
- } catch {
428
- return undefined;
429
- }
430
- try {
431
- const v = (YAML.parse(text) as Record<string, unknown> | null)?.schema;
432
- return typeof v === "string" ? v : null;
433
- } catch {
434
- return null;
282
+ async function inspectWithValidate(
283
+ root: string,
284
+ localVersion: string,
285
+ deps: WorkflowSchemaDeps,
286
+ ): Promise<SchemaInspection> {
287
+ const info = await inspectSchema(root, { localVersion, fingerprint: "full" });
288
+ if ((info.generated === "newer" || info.generated === "conflict") && info.fingerprint) {
289
+ if (!(await makeValidateLocal(root, localVersion, deps)(info.fingerprint))) return { ...info, generated: "incompatible" };
435
290
  }
291
+ return info;
436
292
  }
437
293
 
438
- export interface ComputeStatusOptions extends InspectOptions {
439
- /** `<openspec package>/schemas`; `null` = unknown (the schema is then never reported missing). A function is resolved lazily, only when the config names a schema. */
440
- packageSchemasDir: string | null | (() => Promise<string | null>);
294
+ export interface ComputeStatusOptions extends Omit<SchemaStatusOptions, "userSchemasDirPath"> {
441
295
  /** Default: `userSchemasDir()`. */
442
296
  userSchemasDirPath?: string;
297
+ /** CLI part for `newer`/`conflict`: does `schema validate` pass locally? Default: assumed valid. */
298
+ validateLocal?: (fingerprint: string) => Promise<boolean>;
443
299
  }
444
300
 
445
301
  /**
446
- * Project-authored schema names under `<cwd>/openspec/schemas/`: real
447
- * directories only (no symlinks), excluding dot-prefixed staging dirs,
448
- * `*.fork-*` backups and the managed `pi-spec-driven`; sorted.
449
- */
450
- async function listProjectSchemas(cwd: string): Promise<string[]> {
451
- const dir = schemasDirOf(cwd);
452
- let names: string[];
453
- try {
454
- names = await fsp.readdir(dir);
455
- } catch {
456
- return [];
457
- }
458
- const kept = await Promise.all(
459
- names.map(async (name) => {
460
- if (name.startsWith(".") || name.includes(".fork-") || name === WORKFLOW_SCHEMA_NAME) return null;
461
- const st = await lstatOrNull(path.join(dir, name));
462
- return st?.isDirectory() ? name : null;
463
- }),
464
- );
465
- return kept.filter((n): n is string => n !== null).sort();
466
- }
467
-
468
- /**
469
- * `OpenSpecData.workflowSchema` from files + the stamp (poll-worker safe: no
470
- * CLI spawn except through `opts.validateLocal`). See "Workflow schema status
471
- * is reported separately from readiness". Runs on the poll hot path, so the
472
- * independent filesystem reads are issued concurrently (one `.openspec.yaml`
473
- * read per change, all in flight at once).
302
+ * `OpenSpecData.workflowSchema` with the `newer`/`conflict` verdict applied
303
+ * through `validateLocal`. The poll no longer uses this (the worker computes
304
+ * the fs part, the main thread validates); kept as the single-call form for
305
+ * callers and tests that want the finished status.
474
306
  */
475
307
  export async function computeWorkflowSchemaStatus(
476
308
  cwd: string,
477
309
  opts: ComputeStatusOptions,
478
310
  ): Promise<OpenSpecWorkflowSchemaStatus> {
479
- const configuredP = readConfigFile(cwd).then(
480
- (c) => c?.configured ?? null,
481
- () => null,
482
- );
483
- const inspectP = inspectSchema(cwd, opts);
484
- const missingP = configuredP.then(async (configured) => {
485
- if (configured === null) return false;
486
- const pkgDir = typeof opts.packageSchemasDir === "function" ? await opts.packageSchemasDir() : opts.packageSchemasDir;
487
- if (pkgDir === null) return false;
488
- const dirs = [schemasDirOf(cwd), opts.userSchemasDirPath ?? userSchemasDir(), pkgDir];
489
- const found = await Promise.all(dirs.map(async (d) => !!(await lstatOrNull(path.join(d, configured, "schema.yaml")))));
490
- return !found.some(Boolean);
311
+ const { validateLocal, userSchemasDirPath, ...rest } = opts;
312
+ const { status, validateFingerprint } = await computeSchemaStatus(cwd, {
313
+ fingerprint: "when-needed",
314
+ ...rest,
315
+ userSchemasDirPath: userSchemasDirPath ?? userSchemasDir(),
491
316
  });
492
- const pinsP = enumerateActiveChanges(cwd).then((names) =>
493
- Promise.all(names.map(async (name) => ({ name, pinned: await readChangeSchema(path.join(changesDirOf(cwd), name)) }))),
494
- );
495
- const [configured, { generated }, missing, pins, projectSchemas] = await Promise.all([
496
- configuredP,
497
- inspectP,
498
- missingP,
499
- pinsP,
500
- listProjectSchemas(cwd),
501
- ]);
502
-
503
- const unpinnedChanges: string[] = [];
504
- const affectedChanges: string[] = [];
505
- for (const { name, pinned } of pins) {
506
- if (pinned === undefined) {
507
- if (configured === WORKFLOW_SCHEMA_NAME) {
508
- unpinnedChanges.push(name);
509
- affectedChanges.push(name);
510
- }
511
- } else if (pinned === WORKFLOW_SCHEMA_NAME) {
512
- affectedChanges.push(name);
513
- }
317
+ if (validateFingerprint && validateLocal && !(await validateLocal(validateFingerprint))) {
318
+ return { ...status, generated: "incompatible" };
514
319
  }
515
- return { configured, generated, missing, unpinnedChanges, affectedChanges, projectSchemas };
320
+ return status;
516
321
  }
517
322
 
518
- // ── Patch v1 + stamp ────────────────────────────────────────────────────────
323
+ // ── Patch set (v1 + v2) + stamp ─────────────────────────────────────────────
519
324
 
520
- type PatchResult = { ok: true; text: string } | { ok: false; error: string };
325
+ /** `ok` carries the patched `schema.yaml` text and the template files the patch set adds. */
326
+ type PatchResult =
327
+ | { ok: true; text: string; templates: Record<string, string> }
328
+ | { ok: false; error: string };
329
+
330
+ /** `templates/dependencies.yaml` written by patch v2 (three empty lists, one comment each). */
331
+ const DEPENDENCIES_TEMPLATE = `# Changes that must ship before this one. Each entry: \`- change: <name>\` with an optional \`reason: <why>\`.
332
+ blocked_by: []
333
+ # Changes the dashboard may infer a dependency on that are NOT one (suppresses the inferred edge).
334
+ not_blocked_by: []
335
+ # Changes that are related but impose no order.
336
+ related: []
337
+ `;
338
+
339
+ const DEPENDENCIES_INSTRUCTION = `Declare how this change relates to the OTHER active changes by writing
340
+ dependencies.yaml in the change directory (see the template for the format).
341
+
342
+ Before writing it, inspect the other active changes (\`openspec list\`, then skim the
343
+ proposals and delta specs of those that touch the same capabilities, files or APIs):
344
+ - blocked_by: changes that must be implemented and shipped before this one. One entry
345
+ per blocker (\`- change: <name>\`), with a short \`reason\` when it is not obvious.
346
+ Use the exact change directory name; do not list this change itself.
347
+ - not_blocked_by: a change the dashboard might infer as a blocker (for example because
348
+ it shares a capability) that is NOT one.
349
+ - related: changes that are connected but impose no order.
350
+
351
+ The file is required even when there is nothing to declare: write empty lists
352
+ (\`blocked_by: []\`) to state explicitly that no dependencies exist.
353
+ `;
354
+
355
+ /** True when \`node\` is a YAML sequence of exactly the scalar strings \`values\`. */
356
+ function isSeqOf(node: unknown, values: string[]): node is YAML.YAMLSeq {
357
+ if (!YAML.isSeq(node) || node.items.length !== values.length) return false;
358
+ return node.items.every((item, i) => YAML.isScalar(item) && item.value === values[i]);
359
+ }
521
360
 
522
361
  /**
523
- * Comment-preserving patch v1 + stamp. Aborts when the design-instruction
524
- * anchor line is not found exactly once (a stamp never claims an unapplied patch).
362
+ * Comment-preserving patch set + stamp. Patch v1 rewrites the design-instruction
363
+ * anchor line; patch v2 inserts the \`dependencies\` artifact before \`tasks\` and
364
+ * makes \`tasks\` require it. Aborts when an anchor is not found exactly as expected
365
+ * (a stamp never claims an unapplied patch).
525
366
  */
526
367
  function patchAndStampSchemaYaml(
527
368
  yamlText: string,
@@ -542,9 +383,36 @@ function patchAndStampSchemaYaml(
542
383
  if (hits !== 1) {
543
384
  return { ok: false, error: `patch anchor not found exactly once (${hits}): "${DESIGN_ANCHOR}"` };
544
385
  }
386
+
387
+ // Patch v2 anchors: exactly one \`tasks\` artifact whose \`requires\` is [specs, design].
388
+ const items = YAML.isSeq(artifacts) ? artifacts.items : [];
389
+ const taskIdx = items.map((a, i) => (YAML.isMap(a) && a.get("id") === "tasks" ? i : -1)).filter((i) => i >= 0);
390
+ if (!YAML.isSeq(artifacts) || taskIdx.length !== 1) {
391
+ return { ok: false, error: "patch anchor not found: expected exactly one `tasks` artifact" };
392
+ }
393
+ const tasks = items[taskIdx[0]] as YAML.YAMLMap;
394
+ const requires = tasks.get("requires", true);
395
+ if (!isSeqOf(requires, ["specs", "design"])) {
396
+ return { ok: false, error: "patch anchor not found: `tasks.requires` is not exactly [specs, design]" };
397
+ }
398
+
545
399
  node.value = lines
546
400
  .map((l) => (l.trim() === DESIGN_ANCHOR ? l.slice(0, l.indexOf(DESIGN_ANCHOR)) + DESIGN_REPLACEMENT : l))
547
401
  .join("\n");
402
+
403
+ const instruction = new YAML.Scalar(DEPENDENCIES_INSTRUCTION);
404
+ instruction.type = "BLOCK_LITERAL";
405
+ const dependencies = doc.createNode({
406
+ id: "dependencies",
407
+ generates: "dependencies.yaml",
408
+ description: "Declared dependencies on other active changes",
409
+ template: "dependencies.yaml",
410
+ instruction,
411
+ requires: ["proposal", "specs"],
412
+ });
413
+ artifacts.items.splice(taskIdx[0], 0, dependencies);
414
+ requires.add(doc.createNode("dependencies"));
415
+
548
416
  doc.set(
549
417
  STAMP_KEY,
550
418
  doc.createNode({
@@ -553,7 +421,7 @@ function patchAndStampSchemaYaml(
553
421
  previousDefault: stamp.previousDefault,
554
422
  }),
555
423
  );
556
- return { ok: true, text: doc.toString({ lineWidth: 0 }) };
424
+ return { ok: true, text: doc.toString({ lineWidth: 0 }), templates: { "dependencies.yaml": DEPENDENCIES_TEMPLATE } };
557
425
  }
558
426
 
559
427
  // ── Generation + staged swap ────────────────────────────────────────────────
@@ -608,6 +476,9 @@ export async function generateWorkflowSchema(
608
476
  const patched = patchAndStampSchemaYaml(await fsp.readFile(yamlPath, "utf8"), { cliVersion, previousDefault });
609
477
  if (!patched.ok) return { ok: false, error: patched.error };
610
478
  await fsp.writeFile(yamlPath, patched.text);
479
+ for (const [file, content] of Object.entries(patched.templates)) {
480
+ await fsp.writeFile(path.join(scratchSchema, "templates", file), content);
481
+ }
611
482
 
612
483
  if (!(await runValidate(deps, scratchRoot, WORKFLOW_SCHEMA_NAME, xdg))) {
613
484
  return { ok: false, error: "generated schema failed `openspec schema validate`" };
@@ -771,8 +642,11 @@ interface Outcome {
771
642
 
772
643
  const refused = (error: string, extra: Partial<Outcome> = {}): Outcome => ({ ok: false, written: [], error, ...extra });
773
644
 
774
- /** Fresh `status --all` root checks + symlink refusals. Returns the canonical root or an error. */
775
- async function writeGuard(cwd: string, deps: WorkflowSchemaDeps): Promise<{ root: string } | { error: string }> {
645
+ /**
646
+ * Fresh `status --all` root checks + symlink refusals. Returns the canonical root or an error.
647
+ * Exported for the dependencies PUT, which applies the same "verify the root first" guard.
648
+ */
649
+ export async function writeGuard(cwd: string, deps: WorkflowSchemaDeps): Promise<{ root: string } | { error: string }> {
776
650
  let real: string;
777
651
  try {
778
652
  real = await fsp.realpath(cwd);
@@ -25,6 +25,8 @@ const TYPE_KEYWORDS: Record<string, string[]> = {
25
25
  skill: ["skill", "pi-skill", "skills"],
26
26
  theme: ["theme", "pi-theme", "themes"],
27
27
  prompt: ["prompt", "pi-prompt", "prompts"],
28
+ // Dashboard plugins: findable by the manifest-package keyword. See change: decouple-plugins-from-core (5.12).
29
+ "dashboard-plugin": ["pi-dashboard-plugin"],
28
30
  };
29
31
 
30
32
  function extractTypes(keywords: string[]): string[] {
@@ -65,8 +67,9 @@ export async function searchPackages(options: NpmSearchOptions = {}): Promise<Np
65
67
  const cached = searchCache.get(cacheKey);
66
68
  if (isFresh(cached)) return cached.data;
67
69
 
68
- // Build search text
69
- let text = "keywords:pi-package";
70
+ // Build search text. `type=dashboard-plugin` searches the dashboard-plugin keyword instead of
71
+ // `pi-package`; every other type keeps the default.
72
+ let text = type === "dashboard-plugin" ? "keywords:pi-dashboard-plugin" : "keywords:pi-package";
70
73
  if (query.trim()) text += ` ${query.trim()}`;
71
74
 
72
75
  const url = `${NPM_SEARCH_URL}?text=${encodeURIComponent(text)}&size=${SEARCH_SIZE}`;
@@ -248,7 +248,9 @@ async function fetchProviderModelBody(input: ProbeInput): Promise<unknown | null
248
248
  // a provider that stalls the response BODY (not just the headers) is still
249
249
  // aborted rather than hanging until the socket dies.
250
250
  try {
251
- const response = await fetch(req.url, { method: "GET", headers: req.headers, signal: controller.signal });
251
+ // redirect: "error" — the credential header must never follow a redirect to another origin.
252
+ // See change: triage-codeql-alert-debt (design D3 #19).
253
+ const response = await fetch(req.url, { method: "GET", headers: req.headers, signal: controller.signal, redirect: "error" });
252
254
  if (!response.ok) return null;
253
255
  try {
254
256
  return await response.json();
@@ -302,6 +304,7 @@ export async function probeProvider(input: ProbeInput): Promise<ProbeResult> {
302
304
  method: "GET",
303
305
  headers: req.headers,
304
306
  signal: controller.signal,
307
+ redirect: "error", // never forward the credential to a redirect target (D3 #19)
305
308
  });
306
309
  clearTimeout(timer);
307
310
 
@@ -334,7 +337,10 @@ export async function probeProvider(input: ProbeInput): Promise<ProbeResult> {
334
337
  };
335
338
  } catch (err: any) {
336
339
  clearTimeout(timer);
337
- const message = err?.message ?? String(err);
340
+ // undici reports a refused redirect as `TypeError: fetch failed` with the reason in `cause`.
341
+ const message = /redirect/i.test(String(err?.cause?.message ?? ""))
342
+ ? "Provider answered with a redirect; probes do not follow redirects. Use the final URL as the base URL."
343
+ : (err?.message ?? String(err));
338
344
  return { ok: false, error: redactErrorText(message, input.apiKey) };
339
345
  }
340
346
  }