@blackbelt-technology/pi-agent-dashboard 0.10.0 → 0.12.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.
- package/AGENTS.md +4 -2
- package/README.md +64 -18
- package/docs/architecture.md +2325 -270
- package/package.json +36 -20
- package/packages/extension/package.json +18 -9
- package/packages/extension/src/bridge-context.ts +6 -0
- package/packages/extension/src/bridge-handlers/dispatch.ts +109 -70
- package/packages/extension/src/bridge-handlers/forwarders.ts +19 -42
- package/packages/extension/src/bridge-handlers/instance.ts +31 -13
- package/packages/extension/src/bridge-handlers/lifecycle.ts +149 -66
- package/packages/extension/src/bridge-shutdown.ts +44 -0
- package/packages/extension/src/bridge-ticket-client.ts +61 -7
- package/packages/extension/src/bridge-tls-checks.ts +79 -0
- package/packages/extension/src/bridge.ts +309 -284
- package/packages/extension/src/canvas-tool.ts +2 -0
- package/packages/extension/src/command-handler.ts +106 -37
- package/packages/extension/src/connect-target.ts +23 -0
- package/packages/extension/src/connection.ts +153 -38
- package/packages/extension/src/credential-guard.ts +300 -0
- package/packages/extension/src/custom-entry-forward.ts +27 -18
- package/packages/extension/src/dashboard-http-origin.ts +88 -0
- package/packages/extension/src/default-model-apply.ts +83 -0
- package/packages/extension/src/dev-build.ts +11 -1
- package/packages/extension/src/flow-event-wiring.ts +19 -95
- package/packages/extension/src/followup-drain.ts +19 -5
- package/packages/extension/src/git-link-builder.ts +11 -2
- package/packages/extension/src/inbound-limits.ts +138 -0
- package/packages/extension/src/local-token-header.ts +77 -6
- package/packages/extension/src/model-refresh.ts +69 -0
- package/packages/extension/src/path-gate/decide.ts +68 -5
- package/packages/extension/src/path-gate/handler.ts +16 -8
- package/packages/extension/src/path-gate/index.ts +2 -2
- package/packages/extension/src/path-gate/roots.ts +15 -3
- package/packages/extension/src/path-gate/suppression.ts +3 -0
- package/packages/extension/src/pi-env.d.ts +8 -1
- package/packages/extension/src/pi-retry-settings.ts +11 -2
- package/packages/extension/src/pinned-endpoint.ts +44 -0
- package/packages/extension/src/plugin-event-forward-registry.ts +90 -14
- package/packages/extension/src/preview-path-link.ts +151 -0
- package/packages/extension/src/project-init/scaffold.ts +98 -35
- package/packages/extension/src/project-trust-live.ts +143 -0
- package/packages/extension/src/project-trust.ts +178 -30
- package/packages/extension/src/provider-model-cache.ts +118 -0
- package/packages/extension/src/provider-register.ts +487 -46
- package/packages/extension/src/remote-registration-gate.ts +21 -21
- package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
- package/packages/extension/src/retry-tracker.ts +90 -7
- package/packages/extension/src/role-manager.ts +4 -2
- package/packages/extension/src/role-model-tools.ts +68 -10
- package/packages/extension/src/server-auto-start.ts +69 -3
- package/packages/extension/src/server-launcher.ts +26 -8
- package/packages/extension/src/server-proof-probe.ts +117 -0
- package/packages/extension/src/session-sync.ts +53 -24
- package/packages/extension/src/spawn-new-session.ts +22 -0
- package/packages/extension/src/steer-buffer.ts +164 -0
- package/packages/extension/src/stream-forward-buffer.ts +64 -15
- package/packages/extension/src/sudo-askpass/config-reader.ts +32 -0
- package/packages/extension/src/sudo-askpass/controller.ts +405 -0
- package/packages/extension/src/sudo-askpass/helper-script.ts +69 -0
- package/packages/extension/src/sudo-askpass/in-flight.ts +79 -0
- package/packages/extension/src/sudo-askpass/index.ts +11 -0
- package/packages/extension/src/sudo-askpass/install.ts +143 -0
- package/packages/extension/src/sudo-askpass/password-cache.ts +118 -0
- package/packages/extension/src/sudo-askpass/prompt-text.ts +55 -0
- package/packages/extension/src/sudo-askpass/protocol.ts +18 -0
- package/packages/extension/src/sudo-askpass/sudo-mask-registry.ts +52 -0
- package/packages/extension/src/terminal-reload.ts +19 -5
- package/packages/extension/src/tool-update-filter-registry.ts +210 -0
- package/packages/extension/src/vault-delivery.ts +11 -1
- package/packages/extension/src/vault-redaction.ts +4 -3
- package/packages/server/package.json +17 -14
- package/packages/server/src/access/access-denials.ts +8 -0
- package/packages/server/src/access/access-grants.ts +303 -64
- package/packages/server/src/access/access-health.ts +10 -0
- package/packages/server/src/access/access-plane.ts +12 -1
- package/packages/server/src/access/containment-gate.ts +113 -30
- package/packages/server/src/access/cwd-verdict.ts +3 -3
- package/packages/server/src/access/denial-hold.ts +3 -0
- package/packages/server/src/access/grant-coordinator.ts +17 -1
- package/packages/server/src/access/named-grant.ts +3 -0
- package/packages/server/src/access/pending-grant-registry.ts +32 -5
- package/packages/server/src/access/pi-trust-live.ts +244 -0
- package/packages/server/src/access/pi-trust-mirror-service.ts +50 -11
- package/packages/server/src/access/planes.ts +107 -1
- package/packages/server/src/access/preview-egress-store.ts +153 -0
- package/packages/server/src/access/prompt-channel.ts +5 -0
- package/packages/server/src/access/provisioning-wiring.ts +113 -0
- package/packages/server/src/access/provisioning.ts +763 -0
- package/packages/server/src/access/verified-read.ts +24 -7
- package/packages/server/src/access/yolo-session.ts +54 -2
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +18 -5
- package/packages/server/src/acp-bridge/server-requests.ts +10 -4
- package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
- package/packages/server/src/auth/audit-log.ts +108 -0
- package/packages/server/src/auth/auth-plugin.ts +230 -38
- package/packages/server/src/auth/auth.ts +104 -4
- package/packages/server/src/auth/bearer-auth.ts +52 -12
- package/packages/server/src/auth/bridge-ticket-eligibility.ts +53 -10
- package/packages/server/src/auth/cors-origin.ts +90 -30
- package/packages/server/src/auth/credential-envelope.ts +233 -0
- package/packages/server/src/auth/credential-key-worker.d.mts +16 -0
- package/packages/server/src/auth/credential-key-worker.mjs +108 -0
- package/packages/server/src/auth/credential-key.ts +479 -0
- package/packages/server/src/auth/credential-migration.ts +162 -0
- package/packages/server/src/auth/csp-report-paths.ts +26 -0
- package/packages/server/src/auth/csp-report-sink.ts +302 -0
- package/packages/server/src/auth/csp-report-store.ts +406 -0
- package/packages/server/src/auth/csp.ts +145 -11
- package/packages/server/src/auth/dashboard-credential-store.ts +4 -0
- package/packages/server/src/auth/dashboard-state-caller.ts +29 -0
- package/packages/server/src/auth/device-proof.ts +202 -0
- package/packages/server/src/auth/duplicate-cookie-gate.ts +271 -0
- package/packages/server/src/auth/host-admission.ts +7 -0
- package/packages/server/src/auth/host-gate.ts +13 -2
- package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
- package/packages/server/src/auth/local-proof.ts +69 -18
- package/packages/server/src/auth/localhost-guard.ts +98 -33
- package/packages/server/src/auth/locked-json-file.ts +68 -6
- package/packages/server/src/auth/models-json-store.ts +269 -0
- package/packages/server/src/auth/mutation-origin-gate.ts +5 -2
- package/packages/server/src/auth/nav-intent.ts +72 -0
- package/packages/server/src/auth/node-guard.ts +36 -49
- package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +17 -81
- package/packages/server/src/auth/passkey/passkey-routes.ts +8 -0
- package/packages/server/src/auth/pi-legacy-credentials.ts +3 -0
- package/packages/server/src/auth/plugin-credential-store.ts +81 -10
- package/packages/server/src/auth/plugin-server-trust.ts +29 -0
- package/packages/server/src/auth/plugin-trust-store.ts +103 -0
- package/packages/server/src/auth/proven-tls.ts +45 -0
- package/packages/server/src/auth/provider-auth-storage.ts +214 -12
- package/packages/server/src/auth/provider-block-checks.ts +321 -0
- package/packages/server/src/auth/provider-host-detect.ts +151 -0
- package/packages/server/src/auth/provider-key-file.ts +71 -0
- package/packages/server/src/auth/provider-readiness.ts +91 -0
- package/packages/server/src/auth/radius-mcp.ts +1 -1
- package/packages/server/src/auth/request-principal.ts +32 -0
- package/packages/server/src/auth/route-tier-gate.ts +3 -2
- package/packages/server/src/auth/secret-rotation.ts +246 -0
- package/packages/server/src/auth/secure-origin.ts +56 -0
- package/packages/server/src/auth/serve-app-host.ts +111 -11
- package/packages/server/src/auth/vertex-key-check.ts +140 -0
- package/packages/server/src/auth/ws-ticket.ts +40 -2
- package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
- package/packages/server/src/browse.ts +73 -20
- package/packages/server/src/browser-handlers/acp-guard.ts +1 -4
- package/packages/server/src/browser-handlers/directory-handler.ts +34 -24
- package/packages/server/src/browser-handlers/folder-gate.ts +55 -0
- package/packages/server/src/browser-handlers/handler-context.ts +25 -2
- package/packages/server/src/browser-handlers/session-action-handler.ts +167 -63
- package/packages/server/src/browser-handlers/spawn-choice.ts +138 -1
- package/packages/server/src/browser-handlers/subscription-handler.ts +146 -3
- package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
- package/packages/server/src/build-plugin-send-prompt.ts +18 -0
- package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
- package/packages/server/src/cli/credentials-command.ts +555 -0
- package/packages/server/src/cli.ts +229 -53
- package/packages/server/src/config-api.ts +53 -35
- package/packages/server/src/config-snapshot.ts +197 -1
- package/packages/server/src/directory-service.ts +193 -68
- package/packages/server/src/embed-lifecycle/idle-reaper.ts +13 -3
- package/packages/server/src/event-wiring.ts +322 -207
- package/packages/server/src/git-worktree/ensure-worktree.ts +185 -0
- package/packages/server/src/git-worktree/git-operations.ts +45 -11
- package/packages/server/src/git-worktree/redact-git-text.ts +124 -0
- package/packages/server/src/git-worktree/ref-arg.ts +39 -0
- package/packages/server/src/git-worktree/repo-lock.ts +42 -0
- package/packages/server/src/git-worktree/start-worktree-init.ts +151 -0
- package/packages/server/src/git-worktree/worktree-init-trust.ts +43 -1
- package/packages/server/src/git-worktree/worktree-init.ts +5 -1
- package/packages/server/src/identity/http-road-classification.ts +18 -2
- package/packages/server/src/identity/identity-floor.ts +5 -2
- package/packages/server/src/identity/ws-message-scope.ts +11 -3
- package/packages/server/src/identity/ws-road-classification.ts +3 -1
- package/packages/server/src/known-server-moves.ts +36 -15
- package/packages/server/src/lib/browse-roots.ts +129 -17
- package/packages/server/src/lib/client-dist.ts +36 -21
- package/packages/server/src/lib/content-disposition.ts +20 -0
- package/packages/server/src/lib/dashboard-state-guard.ts +513 -0
- package/packages/server/src/lib/diagram-render.ts +4 -6
- package/packages/server/src/lib/eml.ts +5 -10
- package/packages/server/src/lib/file-cwd-admission.ts +145 -0
- package/packages/server/src/lib/frame-policy-probe.ts +308 -0
- package/packages/server/src/lib/frame-policy-test-seam.ts +99 -0
- package/packages/server/src/lib/frame-policy-verdict.ts +125 -0
- package/packages/server/src/lib/grep-worker.ts +23 -0
- package/packages/server/src/lib/grep.ts +96 -7
- package/packages/server/src/lib/index-html.ts +81 -0
- package/packages/server/src/lib/mention-fuzzy-index.ts +263 -0
- package/packages/server/src/lib/office-preview.ts +49 -13
- package/packages/server/src/lib/path-containment.ts +50 -10
- package/packages/server/src/lib/resolve-file-mention.ts +234 -40
- package/packages/server/src/lib/resolve-mentions-batch.ts +143 -0
- package/packages/server/src/lib/route-admission.ts +80 -0
- package/packages/server/src/lib/writable-handler-target.ts +4 -0
- package/packages/server/src/lib/writable-md-target.ts +26 -0
- package/packages/server/src/lifecycle/boot-parent-liveness.ts +10 -25
- package/packages/server/src/lifecycle/credential-exit-barrier.ts +207 -0
- package/packages/server/src/lifecycle/exit-signal.ts +43 -0
- package/packages/server/src/lifecycle/recovery-server.ts +65 -18
- package/packages/server/src/live-server/capability-redact.ts +31 -0
- package/packages/server/src/live-server/live-browser-gate.ts +22 -0
- package/packages/server/src/live-server/live-capability.ts +615 -44
- package/packages/server/src/live-server/live-csp-report.ts +63 -0
- package/packages/server/src/live-server/live-csp.ts +141 -0
- package/packages/server/src/live-server/live-egress.ts +435 -0
- package/packages/server/src/live-server/live-exposure.ts +149 -0
- package/packages/server/src/live-server/live-log.ts +25 -0
- package/packages/server/src/live-server/live-origin-scan.ts +298 -0
- package/packages/server/src/live-server/live-server-manager.ts +220 -33
- package/packages/server/src/live-server/live-server-proxy.ts +411 -50
- package/packages/server/src/live-server/live-static.ts +231 -0
- package/packages/server/src/live-server/preview-dispatch.ts +286 -0
- package/packages/server/src/live-server/preview-observe.ts +53 -0
- package/packages/server/src/live-server/preview-origin.ts +182 -0
- package/packages/server/src/live-server/preview-path-bridge.ts +70 -0
- package/packages/server/src/live-server/preview-path-store.ts +420 -0
- package/packages/server/src/live-server/preview-path.ts +40 -0
- package/packages/server/src/live-server/preview-pool.ts +385 -0
- package/packages/server/src/live-server/preview-preflight.ts +41 -0
- package/packages/server/src/live-server/preview-reserve.ts +44 -0
- package/packages/server/src/live-server/preview-tier.ts +217 -0
- package/packages/server/src/live-server/preview-viewers.ts +54 -0
- package/packages/server/src/live-server/preview-ws-registry.ts +43 -0
- package/packages/server/src/model-proxy/custom-provider-discovery.ts +4 -2
- package/packages/server/src/model-proxy/internal-auth-storage.ts +5 -1
- package/packages/server/src/model-proxy/internal-registry.ts +283 -21
- package/packages/server/src/model-proxy/models-block-apply.ts +291 -0
- package/packages/server/src/model-proxy/pi-models-validator.ts +164 -0
- package/packages/server/src/model-proxy/registry-singleton.ts +44 -9
- package/packages/server/src/model-proxy/server-model-runtime.ts +17 -0
- package/packages/server/src/openspec/dependencies-file.ts +122 -0
- package/packages/server/src/openspec/openspec-change-watcher.ts +3 -1
- package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +72 -26
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +48 -12
- package/packages/server/src/openspec/openspec-poll-worker.ts +95 -9
- package/packages/server/src/openspec/readiness.ts +1 -1
- package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
- package/packages/server/src/openspec/workflow-schema.ts +141 -267
- package/packages/server/src/package/npm-search-proxy.ts +5 -2
- package/packages/server/src/package/provider-probe.ts +202 -7
- package/packages/server/src/pairing/browser-gateway.ts +325 -51
- package/packages/server/src/pairing/device-key-intake.ts +120 -0
- package/packages/server/src/pairing/device-token-services.ts +26 -0
- package/packages/server/src/pairing/paired-devices.ts +702 -27
- package/packages/server/src/pairing/pairing.ts +103 -11
- package/packages/server/src/pairing/{subagent-resync-routing.ts → resync-requester-registry.ts} +6 -10
- package/packages/server/src/pairing/socket-locality.ts +26 -0
- package/packages/server/src/pairing/ws-tier-gate.ts +74 -0
- package/packages/server/src/pending/pending-attach-registry.ts +15 -0
- package/packages/server/src/pending/pending-initial-prompt-registry.ts +15 -0
- package/packages/server/src/persistence/memory-event-store.ts +251 -296
- package/packages/server/src/persistence/preferences-store.ts +61 -2
- package/packages/server/src/pi/bridge-channel.ts +33 -0
- package/packages/server/src/pi/bridge-contention.ts +84 -2
- package/packages/server/src/pi/bridge-upgrade-auth.ts +18 -3
- package/packages/server/src/pi/gateway-listeners.ts +9 -3
- package/packages/server/src/pi/host-project-trust.ts +29 -15
- package/packages/server/src/pi/pi-gateway.ts +398 -41
- package/packages/server/src/pi/provisional-registration.ts +4 -1
- package/packages/server/src/pi/resource-toggle-trust.ts +18 -7
- package/packages/server/src/pi-agent-settings.ts +95 -301
- package/packages/server/src/pi-default-remirror.ts +89 -0
- package/packages/server/src/plugin-append-event.ts +35 -0
- package/packages/server/src/plugin-discovery-wiring.ts +142 -0
- package/packages/server/src/plugin-entry-stats.ts +61 -0
- package/packages/server/src/plugin-event-seam.ts +116 -4
- package/packages/server/src/plugin-local-request.ts +207 -0
- package/packages/server/src/plugin-ownership.ts +111 -0
- package/packages/server/src/plugin-policy-registry.ts +297 -0
- package/packages/server/src/plugin-request-lane.ts +92 -16
- package/packages/server/src/plugin-runtime-clients.ts +89 -0
- package/packages/server/src/preferences-relay.ts +20 -0
- package/packages/server/src/project-seed.ts +347 -0
- package/packages/server/src/push/push-transports/webhook-url.ts +8 -5
- package/packages/server/src/questions/question-store.ts +3 -2
- package/packages/server/src/routes/access-routes.ts +182 -15
- package/packages/server/src/routes/acme-routes.ts +14 -4
- package/packages/server/src/routes/agent-event-stream-routes.ts +137 -0
- package/packages/server/src/routes/canvas-types-routes.ts +20 -6
- package/packages/server/src/routes/csp-violations-routes.ts +162 -0
- package/packages/server/src/routes/file-routes.ts +640 -279
- package/packages/server/src/routes/file-write-binary-routes.ts +97 -24
- package/packages/server/src/routes/folder-project-routes.ts +18 -12
- package/packages/server/src/routes/frame-policy-routes.ts +215 -0
- package/packages/server/src/routes/git-routes.ts +340 -273
- package/packages/server/src/routes/grep-routes.ts +64 -14
- package/packages/server/src/routes/known-servers-routes.ts +189 -91
- package/packages/server/src/routes/live-server-routes.ts +572 -15
- package/packages/server/src/routes/local-proof-routes.ts +14 -0
- package/packages/server/src/routes/models-introspection-routes.ts +1 -1
- package/packages/server/src/routes/nav-intent-routes.ts +46 -0
- package/packages/server/src/routes/openspec-group-routes.ts +53 -44
- package/packages/server/src/routes/openspec-routes.ts +396 -31
- package/packages/server/src/routes/package-routes.ts +58 -10
- package/packages/server/src/routes/pairing-routes.ts +342 -17
- package/packages/server/src/routes/pi-settings-routes.ts +2 -0
- package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
- package/packages/server/src/routes/plugin-activation-routes.ts +59 -0
- package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
- package/packages/server/src/routes/preferences-auto-name-routes.ts +5 -2
- package/packages/server/src/routes/preferences-claude-compat-routes.ts +49 -0
- package/packages/server/src/routes/provider-auth-routes.ts +181 -10
- package/packages/server/src/routes/provider-override-routes.ts +158 -0
- package/packages/server/src/routes/provider-routes.ts +348 -86
- package/packages/server/src/routes/resource-activation-routes.ts +18 -4
- package/packages/server/src/routes/session-routes.ts +75 -25
- package/packages/server/src/routes/system-routes.ts +169 -52
- package/packages/server/src/routes/ui-link-base.ts +88 -0
- package/packages/server/src/rpc-keeper/keeper-manager.ts +196 -25
- package/packages/server/src/rpc-keeper/keeper.cjs +37 -23
- package/packages/server/src/runtime-overlay/extension-reload.ts +16 -10
- package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
- package/packages/server/src/runtime-overlay/runtime-stager.ts +4 -2
- package/packages/server/src/server.ts +1139 -291
- package/packages/server/src/services/cli-service.ts +59 -10
- package/packages/server/src/services/secrets-resolver.ts +46 -30
- package/packages/server/src/session/custom-event-group-annotation.ts +3 -3
- package/packages/server/src/session/custom-event-group-resolver.ts +10 -5
- package/packages/server/src/session/death-reason.ts +11 -7
- package/packages/server/src/session/event-status-extraction.ts +5 -1
- package/packages/server/src/session/hydration-state.ts +148 -0
- package/packages/server/src/session/memory-session-manager.ts +31 -2
- package/packages/server/src/session/open-tool-calls.ts +81 -47
- package/packages/server/src/session/pid-target.ts +127 -0
- package/packages/server/src/session/replay-compaction.ts +18 -5
- package/packages/server/src/session/replay-exit-controller.ts +221 -0
- package/packages/server/src/session/retained-transcript.ts +9 -2
- package/packages/server/src/session/seed-discovered-history.ts +85 -0
- package/packages/server/src/session/server-pid-context.ts +14 -0
- package/packages/server/src/session/session-api.ts +78 -29
- package/packages/server/src/session/session-archive.ts +7 -0
- package/packages/server/src/session/session-bootstrap.ts +9 -54
- package/packages/server/src/session/session-load-worker-pool.ts +11 -1
- package/packages/server/src/session/session-load-worker.ts +32 -4
- package/packages/server/src/spawn-process/abort-spawned-run.ts +28 -9
- package/packages/server/src/spawn-process/acp-spawn.ts +8 -2
- package/packages/server/src/spawn-process/headless-pid-registry.ts +393 -77
- package/packages/server/src/spawn-process/link-register.ts +42 -0
- package/packages/server/src/spawn-process/plugin-spawn-choice.ts +48 -0
- package/packages/server/src/spawn-process/plugin-spawn-worktree.ts +290 -0
- package/packages/server/src/spawn-process/process-classifier.ts +8 -3
- package/packages/server/src/spawn-process/process-manager.ts +61 -6
- package/packages/server/src/spawn-process/restored-identity.ts +112 -0
- package/packages/server/src/spawn-process/session-terminator.ts +179 -18
- package/packages/server/src/spawn-process/spawn-env-contributors.ts +2 -1
- package/packages/server/src/spawn-process/spawn-failure-log.ts +9 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +44 -19
- package/packages/server/src/sudo-credential/relay.ts +337 -0
- package/packages/server/src/terminal/terminal-gateway.ts +10 -0
- package/packages/server/src/terminal/terminal-manager.ts +54 -46
- package/packages/server/src/tls/sources/acme/credentials.ts +3 -2
- package/packages/server/src/tls/sources/acme/runtime.ts +2 -1
- package/packages/server/src/tls/tls-bridge-route.ts +61 -0
- package/packages/server/src/tls/tls-config-validation.ts +2 -0
- package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +172 -26
- package/packages/server/src/vault/vault-routes.ts +9 -2
- package/packages/server/src/vault/vault-store.ts +87 -24
- package/packages/server/src/watch-files-handler.ts +66 -0
- package/packages/server/vendor/xlsx/LICENSE +201 -0
- package/packages/server/vendor/xlsx/PROVENANCE.json +13 -0
- package/packages/server/vendor/xlsx/xlsx.d.mts +1065 -0
- package/packages/server/vendor/xlsx/xlsx.mjs +28228 -0
- package/packages/shared/package.json +4 -2
- package/packages/shared/src/agent-credential-files.ts +32 -0
- package/packages/shared/src/browser-protocol.ts +285 -59
- package/packages/shared/src/canvas-declare.ts +27 -0
- package/packages/shared/src/canvas-detect.ts +1 -1
- package/packages/shared/src/canvas-types.ts +2 -2
- package/packages/shared/src/config.ts +443 -187
- package/packages/shared/src/containment-guard.ts +45 -0
- package/packages/shared/src/credential-encryption.ts +87 -0
- package/packages/shared/src/custom-event-groups.ts +2 -0
- package/packages/shared/src/dashboard-plugin/claude-compat.ts +159 -0
- package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +2 -0
- package/packages/shared/src/dashboard-plugin/host-api.ts +61 -0
- package/packages/shared/src/dashboard-plugin/host-fx-classes.ts +23 -0
- package/packages/shared/src/dashboard-plugin/host-import-map.ts +38 -0
- package/packages/shared/src/dashboard-plugin/index.ts +2 -0
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +100 -1
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +58 -3
- package/packages/shared/src/dashboard-plugin/replay-entry-types.ts +46 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +47 -3
- package/packages/shared/src/dashboard-plugin/slot-types.ts +9 -1
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +39 -3
- package/packages/shared/src/device-key-proof.ts +309 -0
- package/packages/shared/src/display-prefs.ts +13 -0
- package/packages/shared/src/doctor-core.ts +94 -27
- package/packages/shared/src/event-forward-declaration.ts +85 -12
- package/packages/shared/src/forbidden-subjects.ts +126 -14
- package/packages/shared/src/heap-limits.ts +0 -30
- package/packages/shared/src/host-admission.ts +2 -1
- package/packages/shared/src/index.ts +7 -6
- package/packages/shared/src/live-server.ts +161 -0
- package/packages/shared/src/local-proof-signal.ts +16 -0
- package/packages/shared/src/loopback-host.ts +26 -0
- package/packages/shared/src/mcp/verb-tiers.generated.ts +176 -0
- package/packages/shared/src/mdns-discovery.ts +25 -6
- package/packages/shared/src/models-json-reader.ts +41 -0
- package/packages/shared/src/nav-intent.ts +29 -0
- package/packages/shared/src/network-denial-signal.ts +15 -0
- package/packages/shared/src/node-version.ts +63 -60
- package/packages/shared/src/openspec-dependencies.ts +760 -0
- package/packages/shared/src/openspec-poller.ts +3 -2
- package/packages/shared/src/pairing-knock-client.ts +135 -11
- package/packages/shared/src/pi-agent-settings-lock.ts +311 -0
- package/packages/shared/src/pi-path-compare.ts +31 -0
- package/packages/shared/src/pi-settings-schema.ts +52 -9
- package/packages/shared/src/pi-trust-live-query.ts +93 -0
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +21 -11
- package/packages/shared/src/pi-trust-mirror-types.ts +38 -3
- package/packages/shared/src/pi-trust-mirror.ts +47 -11
- package/packages/shared/src/pi-trust-resource-digest.ts +261 -0
- package/packages/shared/src/pid-namespace.ts +86 -0
- package/packages/shared/src/platform/ensure-bundled-git.ts +57 -34
- package/packages/shared/src/platform/git-source.ts +88 -26
- package/packages/shared/src/platform/git.ts +14 -8
- package/packages/shared/src/platform/native-ts-register.mjs +1 -1
- package/packages/shared/src/platform/process.ts +452 -5
- package/packages/shared/src/platform/resolve-pi-shell.ts +105 -0
- package/packages/shared/src/platform/select-git-source.ts +7 -0
- package/packages/shared/src/platform/spawn-runtime.ts +193 -7
- package/packages/shared/src/plugin-route-cwd.ts +95 -0
- package/packages/shared/src/preview-egress.ts +192 -0
- package/packages/shared/src/preview-origins.ts +398 -0
- package/packages/shared/src/project-root.ts +16 -0
- package/packages/shared/src/prompt-answer.ts +9 -5
- package/packages/shared/src/protocol.ts +187 -86
- package/packages/shared/src/provider-env-catalog.ts +413 -0
- package/packages/shared/src/provider-overrides.ts +112 -0
- package/packages/shared/src/question-types.ts +6 -0
- package/packages/shared/src/recommended-extensions.ts +97 -26
- package/packages/shared/src/recovery-timing.ts +27 -0
- package/packages/shared/src/remote-credentials.ts +63 -0
- package/packages/shared/src/renderer-by-ext.ts +5 -2
- package/packages/shared/src/rest-api.ts +148 -11
- package/packages/shared/src/role-schema.ts +24 -0
- package/packages/shared/src/route-tiers.ts +149 -4
- package/packages/shared/src/runtime-overlay/archive-safety.d.mts +2 -0
- package/packages/shared/src/runtime-overlay/archive-safety.mjs +33 -0
- package/packages/shared/src/runtime-overlay/compat.ts +70 -6
- package/packages/shared/src/runtime-overlay/manifest.d.mts +7 -0
- package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
- package/packages/shared/src/safe-local-path.ts +24 -0
- package/packages/shared/src/sanitize-profiles.ts +98 -0
- package/packages/shared/src/secret-patterns.ts +49 -0
- package/packages/shared/src/server-launcher.ts +9 -1
- package/packages/shared/src/server-pinning.ts +55 -2
- package/packages/shared/src/server-routes.ts +462 -0
- package/packages/shared/src/session-ui-path.ts +11 -0
- package/packages/shared/src/source-matching.ts +2 -2
- package/packages/shared/src/state-replay.ts +40 -24
- package/packages/shared/src/sudo-credential.ts +71 -0
- package/packages/shared/src/tls-only-token.ts +16 -0
- package/packages/shared/src/tool-path-resolve.ts +16 -1
- package/packages/shared/src/tool-registry/definitions.ts +5 -5
- package/packages/shared/src/tool-registry/strategies.ts +13 -12
- package/packages/shared/src/tool-workdir.ts +56 -0
- package/packages/shared/src/trusted-types-mode.ts +72 -0
- package/packages/shared/src/types.ts +134 -109
- package/packages/shared/src/url-policy.ts +96 -0
- package/packages/shared/src/vault-delivery.ts +15 -0
- package/packages/shared/src/vertex-regions.ts +81 -0
- package/packages/shared/src/ws-message-tiers.ts +11 -3
- package/packages/extension/src/subagent-fanout-admission.ts +0 -234
- package/packages/extension/src/subagent-forward-sites.ts +0 -69
- package/packages/extension/src/subagent-frame-buffer.ts +0 -245
- package/packages/extension/src/subagent-frame-strip.ts +0 -109
- package/packages/extension/src/subagent-saturation.ts +0 -196
- package/packages/extension/src/subagent-tick-throttle.ts +0 -252
- package/packages/shared/src/anthropic-messages-source.ts +0 -8
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filesystem half of `GET` / `PUT /api/openspec/dependencies`: a fresh read of
|
|
3
|
+
* one change's `dependencies.yaml` and the contained, preconditioned, atomic
|
|
4
|
+
* write. Route gates, the workflow-schema write guard and the per-cwd lock live
|
|
5
|
+
* in the route; this module owns containment, symlink refusal and the write.
|
|
6
|
+
*
|
|
7
|
+
* See change: add-openspec-change-dependencies.
|
|
8
|
+
*/
|
|
9
|
+
import { randomBytes } from "node:crypto";
|
|
10
|
+
import fsp from "node:fs/promises";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import {
|
|
13
|
+
DEPENDENCIES_FILE,
|
|
14
|
+
type DeclaredDependencies,
|
|
15
|
+
type FileStat,
|
|
16
|
+
readDependenciesFile,
|
|
17
|
+
} from "@blackbelt-technology/pi-dashboard-shared/openspec-dependencies.js";
|
|
18
|
+
|
|
19
|
+
export interface DeclaredRead {
|
|
20
|
+
declared: DeclaredDependencies | null;
|
|
21
|
+
declaredError: string | null;
|
|
22
|
+
file: FileStat | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function lstatOrNull(p: string): Promise<import("node:fs").Stats | null> {
|
|
26
|
+
try {
|
|
27
|
+
return await fsp.lstat(p);
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** `<root>/openspec/changes/<change>` for a canonical project root. */
|
|
34
|
+
const changeDirOf = (root: string, change: string): string => path.join(root, "openspec", "changes", change);
|
|
35
|
+
|
|
36
|
+
/** Read the file fresh under the read rules; a symlinked change directory is never read through. */
|
|
37
|
+
export async function readDeclared(root: string, change: string): Promise<DeclaredRead> {
|
|
38
|
+
const dir = changeDirOf(root, change);
|
|
39
|
+
const st = await lstatOrNull(dir);
|
|
40
|
+
if (!st?.isDirectory()) {
|
|
41
|
+
return { declared: null, declaredError: st ? "change directory is a symlink or not a directory" : null, file: null };
|
|
42
|
+
}
|
|
43
|
+
const r = await readDependenciesFile(path.join(dir, DEPENDENCIES_FILE));
|
|
44
|
+
if (r.kind === "absent") return { declared: null, declaredError: null, file: null };
|
|
45
|
+
if (r.kind === "invalid") return { declared: null, declaredError: r.error, file: r.stat ?? null };
|
|
46
|
+
return { declared: r.value, declaredError: null, file: r.stat };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type WriteOutcome =
|
|
50
|
+
| { ok: true; file: FileStat }
|
|
51
|
+
| { ok: false; status: 403 | 409 | 500; reason: "write-refused" | "modified" | "write-failed"; error: string };
|
|
52
|
+
|
|
53
|
+
const refused = (error: string): WriteOutcome => ({ ok: false, status: 403, reason: "write-refused", error });
|
|
54
|
+
const modified = (error: string): WriteOutcome => ({ ok: false, status: 409, reason: "modified", error });
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Write `content` as the change's `dependencies.yaml`.
|
|
58
|
+
*
|
|
59
|
+
* Containment first: the change directory and an existing file must be real
|
|
60
|
+
* (non-symlink) and the directory's realpath must sit under the canonical
|
|
61
|
+
* `<root>/openspec/changes/`. Then the precondition `expected` (the `file` value
|
|
62
|
+
* GET returned): `null` = the file must not exist; otherwise mtime and size must
|
|
63
|
+
* both match. The content goes to a temp file in the same directory and is moved
|
|
64
|
+
* into place — `rename` when replacing, `link` (no replace) when creating.
|
|
65
|
+
*/
|
|
66
|
+
export async function writeDependenciesFile(args: {
|
|
67
|
+
root: string;
|
|
68
|
+
change: string;
|
|
69
|
+
content: string;
|
|
70
|
+
expected: FileStat | null;
|
|
71
|
+
}): Promise<WriteOutcome> {
|
|
72
|
+
const { root, change, content, expected } = args;
|
|
73
|
+
const dir = changeDirOf(root, change);
|
|
74
|
+
const dirStat = await lstatOrNull(dir);
|
|
75
|
+
if (!dirStat || dirStat.isSymbolicLink() || !dirStat.isDirectory()) {
|
|
76
|
+
return refused("the change directory is missing, a symlink, or not a directory");
|
|
77
|
+
}
|
|
78
|
+
let changesReal: string;
|
|
79
|
+
let dirReal: string;
|
|
80
|
+
try {
|
|
81
|
+
changesReal = await fsp.realpath(path.join(root, "openspec", "changes"));
|
|
82
|
+
dirReal = await fsp.realpath(dir);
|
|
83
|
+
} catch {
|
|
84
|
+
return refused("cannot resolve the change directory");
|
|
85
|
+
}
|
|
86
|
+
// Strictly below `changes/` (the directory itself, e.g. change "." or "", is not a change directory).
|
|
87
|
+
if (dirReal === changesReal || !(dirReal + path.sep).startsWith(changesReal + path.sep)) {
|
|
88
|
+
return refused("the change directory resolves outside openspec/changes/");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const target = path.join(dirReal, DEPENDENCIES_FILE);
|
|
92
|
+
const existing = await lstatOrNull(target);
|
|
93
|
+
if (existing && (existing.isSymbolicLink() || !existing.isFile())) {
|
|
94
|
+
return refused("dependencies.yaml is a symlink or not a regular file");
|
|
95
|
+
}
|
|
96
|
+
if (expected === null) {
|
|
97
|
+
if (existing) return modified("dependencies.yaml was created after it was read");
|
|
98
|
+
} else if (!existing || existing.mtimeMs !== expected.mtimeMs || existing.size !== expected.size) {
|
|
99
|
+
return modified("dependencies.yaml changed since it was read");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const tmp = path.join(dirReal, `.dependencies.yaml.${process.pid}-${randomBytes(6).toString("hex")}.tmp`);
|
|
103
|
+
try {
|
|
104
|
+
await fsp.writeFile(tmp, content, { flag: "wx", mode: 0o644 });
|
|
105
|
+
if (expected === null) {
|
|
106
|
+
try {
|
|
107
|
+
await fsp.link(tmp, target); // exclusive: never replaces
|
|
108
|
+
} catch (err) {
|
|
109
|
+
if ((err as NodeJS.ErrnoException).code === "EEXIST") return modified("dependencies.yaml was created after it was read");
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
await fsp.rename(tmp, target);
|
|
114
|
+
}
|
|
115
|
+
const st = await fsp.stat(target);
|
|
116
|
+
return { ok: true, file: { mtimeMs: st.mtimeMs, size: st.size } };
|
|
117
|
+
} catch (err) {
|
|
118
|
+
return { ok: false, status: 500, reason: "write-failed", error: `could not write dependencies.yaml: ${(err as Error).message}` };
|
|
119
|
+
} finally {
|
|
120
|
+
await fsp.rm(tmp, { force: true }).catch(() => undefined);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -25,6 +25,8 @@ import { matchesOutputPattern } from "@blackbelt-technology/pi-dashboard-shared/
|
|
|
25
25
|
* - `tasks.md`, `proposal.md`, `design.md` at the change root
|
|
26
26
|
* - any `*.md` under any `specs/` subtree
|
|
27
27
|
* - `.openspec.yaml` (change metadata — affects schema / error state)
|
|
28
|
+
* - `dependencies.yaml` (declared change dependencies; spec-driven changes do
|
|
29
|
+
* not declare it as an artifact). See change: add-openspec-change-dependencies.
|
|
28
30
|
*
|
|
29
31
|
* The watcher event filename is the relative path from the watch root
|
|
30
32
|
* (`openspec/changes/`), so a typical match is
|
|
@@ -34,7 +36,7 @@ import { matchesOutputPattern } from "@blackbelt-technology/pi-dashboard-shared/
|
|
|
34
36
|
* (`my-change\\tasks.md`) match too.
|
|
35
37
|
*/
|
|
36
38
|
const FILTER_RE =
|
|
37
|
-
/^[^/]+\/(?:tasks\.md|proposal\.md|design\.md|\.openspec\.yaml|specs(?:\/.*)?\.md)$/;
|
|
39
|
+
/^[^/]+\/(?:tasks\.md|proposal\.md|design\.md|\.openspec\.yaml|dependencies\.yaml|specs(?:\/.*)?\.md)$/;
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
42
|
* Relevant events under `openspec/changes/` (path relative to that dir):
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the files the dependency graph is computed from — per-change
|
|
3
|
+
* `dependencies.yaml`, `proposal.md`, delta `spec.md` headers — plus the archive
|
|
4
|
+
* listing and main-spec existence, behind a per-file parse cache keyed by
|
|
5
|
+
* path + mtime + size. Runs wherever the poll build runs (worker thread or
|
|
6
|
+
* in-process), so the cache is per thread. All I/O is async and bounded.
|
|
7
|
+
*
|
|
8
|
+
* See change: add-openspec-change-dependencies.
|
|
9
|
+
*/
|
|
10
|
+
import { constants as fsConstants } from "node:fs";
|
|
11
|
+
import fsp from "node:fs/promises";
|
|
12
|
+
import * as path from "node:path";
|
|
13
|
+
import {
|
|
14
|
+
archivedChangeName,
|
|
15
|
+
type ChangeInputs,
|
|
16
|
+
computeDependencyGraph,
|
|
17
|
+
DEPENDENCIES_FILE,
|
|
18
|
+
type DeclaredState,
|
|
19
|
+
type DeltaScan,
|
|
20
|
+
type GraphInputs,
|
|
21
|
+
type ProposalScan,
|
|
22
|
+
readDependenciesFile,
|
|
23
|
+
scanDelta,
|
|
24
|
+
scanProposal,
|
|
25
|
+
} from "@blackbelt-technology/pi-dashboard-shared/openspec-dependencies.js";
|
|
26
|
+
import { mapLimit } from "@blackbelt-technology/pi-dashboard-shared/openspec-status-all.js";
|
|
27
|
+
import type { ChangeDependencies } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
28
|
+
import { MAX_SPEC_DEPTH } from "./openspec-poll-fs-helpers.js";
|
|
29
|
+
|
|
30
|
+
/** Markdown inputs larger than this are ignored (never read). */
|
|
31
|
+
const MAX_MARKDOWN_BYTES = 1024 * 1024;
|
|
32
|
+
const CHANGE_CONCURRENCY = 16;
|
|
33
|
+
|
|
34
|
+
interface CacheEntry<T> {
|
|
35
|
+
mtimeMs: number;
|
|
36
|
+
size: number;
|
|
37
|
+
value: T;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Per-thread per-file parse cache. Keys are absolute paths. */
|
|
41
|
+
const fileCache = new Map<string, CacheEntry<unknown>>();
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Per-change assembly cache keyed by the gate probe's effective mtime (the max
|
|
45
|
+
* over the change's tracked paths, which include every input read here). An
|
|
46
|
+
* unchanged mtime means no input moved, so the change costs no syscalls at all.
|
|
47
|
+
* The key is taken BEFORE the files are read, so a write in between only makes
|
|
48
|
+
* the next build re-read (never serves stale content). Sits on top of the
|
|
49
|
+
* per-file cache; entries remember the files they cover so pruning keeps them.
|
|
50
|
+
*/
|
|
51
|
+
interface ChangeCacheEntry {
|
|
52
|
+
mtime: number;
|
|
53
|
+
files: string[];
|
|
54
|
+
inputs: Omit<ChangeInputs, "name">;
|
|
55
|
+
}
|
|
56
|
+
const changeCache = new Map<string, ChangeCacheEntry>();
|
|
57
|
+
|
|
58
|
+
/** Test seam: drop every cached parse. */
|
|
59
|
+
export function clearDependencyInputCache(): void {
|
|
60
|
+
fileCache.clear();
|
|
61
|
+
changeCache.clear();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function cachedParse<T>(
|
|
65
|
+
file: string,
|
|
66
|
+
seen: Set<string>,
|
|
67
|
+
parse: (text: string) => T,
|
|
68
|
+
): Promise<T | null> {
|
|
69
|
+
let st: Awaited<ReturnType<typeof fsp.lstat>>;
|
|
70
|
+
try {
|
|
71
|
+
st = await fsp.lstat(file);
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
// Regular files only: never read through a symlink or a device.
|
|
76
|
+
if (!st.isFile() || st.size > MAX_MARKDOWN_BYTES) return null;
|
|
77
|
+
seen.add(file);
|
|
78
|
+
const hit = fileCache.get(file) as CacheEntry<T> | undefined;
|
|
79
|
+
if (hit && hit.mtimeMs === st.mtimeMs && hit.size === st.size) return hit.value;
|
|
80
|
+
const text = await readMarkdown(file);
|
|
81
|
+
if (text === null) return null;
|
|
82
|
+
const value = parse(text);
|
|
83
|
+
fileCache.set(file, { mtimeMs: st.mtimeMs, size: st.size, value });
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Bounded read of a regular file that is re-checked on the OPEN handle: never through a symlink
|
|
89
|
+
* (`O_NOFOLLOW`), never blocking on a FIFO swapped in after the caller's lstat (`O_NONBLOCK`), never more
|
|
90
|
+
* than `MAX_MARKDOWN_BYTES`. `null` = unreadable or not a regular file.
|
|
91
|
+
*/
|
|
92
|
+
async function readMarkdown(file: string): Promise<string | null> {
|
|
93
|
+
const noFollow = typeof fsConstants.O_NOFOLLOW === "number" ? fsConstants.O_NOFOLLOW : 0;
|
|
94
|
+
const nonBlock = typeof fsConstants.O_NONBLOCK === "number" ? fsConstants.O_NONBLOCK : 0;
|
|
95
|
+
let handle: Awaited<ReturnType<typeof fsp.open>> | undefined;
|
|
96
|
+
try {
|
|
97
|
+
handle = await fsp.open(file, fsConstants.O_RDONLY | noFollow | nonBlock);
|
|
98
|
+
const hs = await handle.stat();
|
|
99
|
+
if (!hs.isFile() || hs.size > MAX_MARKDOWN_BYTES) return null;
|
|
100
|
+
const buf = Buffer.alloc(hs.size + 1);
|
|
101
|
+
const { bytesRead } = await handle.read(buf, 0, buf.length, 0);
|
|
102
|
+
return bytesRead > hs.size ? null : buf.toString("utf8", 0, bytesRead); // grew while reading: skip
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
} finally {
|
|
106
|
+
await handle?.close().catch(() => undefined);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function readDeclared(file: string, seen: Set<string>): Promise<DeclaredState> {
|
|
111
|
+
let st: Awaited<ReturnType<typeof fsp.lstat>>;
|
|
112
|
+
try {
|
|
113
|
+
st = await fsp.lstat(file);
|
|
114
|
+
} catch {
|
|
115
|
+
return { state: "absent" };
|
|
116
|
+
}
|
|
117
|
+
seen.add(file);
|
|
118
|
+
const hit = fileCache.get(file) as CacheEntry<DeclaredState> | undefined;
|
|
119
|
+
if (hit && hit.mtimeMs === st.mtimeMs && hit.size === st.size) return hit.value;
|
|
120
|
+
const r = await readDependenciesFile(file);
|
|
121
|
+
const value: DeclaredState =
|
|
122
|
+
r.kind === "absent"
|
|
123
|
+
? { state: "absent" }
|
|
124
|
+
: r.kind === "invalid"
|
|
125
|
+
? { state: "invalid", error: r.error }
|
|
126
|
+
: { state: "ok", value: r.value };
|
|
127
|
+
// A symlink / FIFO / oversize file is re-checked each build (cheap lstat), not cached.
|
|
128
|
+
if (r.kind === "ok" || (r.kind === "invalid" && st.isFile() && st.size <= 64 * 1024)) {
|
|
129
|
+
fileCache.set(file, { mtimeMs: st.mtimeMs, size: st.size, value });
|
|
130
|
+
}
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Capability id → delta `spec.md` path, walking `specs/` (nested ids included). */
|
|
135
|
+
async function listDeltaFiles(specsDir: string): Promise<Array<{ cap: string; file: string }>> {
|
|
136
|
+
const out: Array<{ cap: string; file: string }> = [];
|
|
137
|
+
const walk = async (dir: string, rel: string, depth: number): Promise<void> => {
|
|
138
|
+
let entries: import("node:fs").Dirent[];
|
|
139
|
+
try {
|
|
140
|
+
entries = await fsp.readdir(dir, { withFileTypes: true });
|
|
141
|
+
} catch {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
for (const e of entries) {
|
|
145
|
+
if (e.isDirectory()) {
|
|
146
|
+
if (depth < MAX_SPEC_DEPTH) await walk(path.join(dir, e.name), rel ? `${rel}/${e.name}` : e.name, depth + 1);
|
|
147
|
+
} else if (e.isFile() && e.name === "spec.md" && rel) {
|
|
148
|
+
out.push({ cap: rel, file: path.join(dir, e.name) });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
await walk(specsDir, "", 0);
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function archivedNames(archiveDir: string): Promise<string[]> {
|
|
157
|
+
try {
|
|
158
|
+
const entries = await fsp.readdir(archiveDir, { withFileTypes: true });
|
|
159
|
+
const names: string[] = [];
|
|
160
|
+
for (const e of entries) {
|
|
161
|
+
if (!e.isDirectory()) continue;
|
|
162
|
+
const n = archivedChangeName(e.name);
|
|
163
|
+
if (n) names.push(n);
|
|
164
|
+
}
|
|
165
|
+
return names;
|
|
166
|
+
} catch {
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function mainSpecExists(openspecDir: string, cap: string): Promise<boolean> {
|
|
172
|
+
try {
|
|
173
|
+
return (await fsp.stat(path.join(openspecDir, "specs", ...cap.split("/"), "spec.md"))).isFile();
|
|
174
|
+
} catch {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
interface CollectedInputs {
|
|
180
|
+
inputs: GraphInputs;
|
|
181
|
+
/** Every capability id touched by an active delta (sorted) — stored with the gate stamp. */
|
|
182
|
+
capabilityIds: string[];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Read the graph inputs for `names` (the active changes of this build).
|
|
187
|
+
* `mtimes` = the probe's per-change effective mtime (optional): equal to the
|
|
188
|
+
* previous build's value → the assembled inputs are reused without any I/O.
|
|
189
|
+
*/
|
|
190
|
+
const isSingleSegment = (name: string): boolean => name !== "" && name !== "." && name !== ".." && !/[\\/\0]/.test(name);
|
|
191
|
+
|
|
192
|
+
async function collectDependencyInputs(
|
|
193
|
+
openspecDir: string,
|
|
194
|
+
names: string[],
|
|
195
|
+
mtimes?: Record<string, number | undefined>,
|
|
196
|
+
): Promise<CollectedInputs> {
|
|
197
|
+
const changesDir = path.join(openspecDir, "changes");
|
|
198
|
+
const seen = new Set<string>();
|
|
199
|
+
const seenChanges = new Set<string>();
|
|
200
|
+
const changes = await mapLimit(names, CHANGE_CONCURRENCY, async (name): Promise<ChangeInputs> => {
|
|
201
|
+
// Names come from the CLI's listing; defence in depth: only a single path segment is ever joined onto
|
|
202
|
+
// `changes/` (never `..`, a separator or NUL), so a hostile entry cannot reach files outside it.
|
|
203
|
+
if (!isSingleSegment(name)) return { name, declared: { state: "absent" }, proposal: null, deltas: {} };
|
|
204
|
+
const dir = path.join(changesDir, name);
|
|
205
|
+
const mtime = mtimes?.[name];
|
|
206
|
+
const hit = changeCache.get(dir);
|
|
207
|
+
if (hit && mtime !== undefined && hit.mtime === mtime) {
|
|
208
|
+
seenChanges.add(dir);
|
|
209
|
+
for (const f of hit.files) seen.add(f);
|
|
210
|
+
return { name, ...hit.inputs };
|
|
211
|
+
}
|
|
212
|
+
const before = new Set(seen);
|
|
213
|
+
const [declared, proposal, deltaFiles] = await Promise.all([
|
|
214
|
+
readDeclared(path.join(dir, DEPENDENCIES_FILE), seen),
|
|
215
|
+
cachedParse<ProposalScan>(path.join(dir, "proposal.md"), seen, scanProposal),
|
|
216
|
+
listDeltaFiles(path.join(dir, "specs")),
|
|
217
|
+
]);
|
|
218
|
+
const deltas: Record<string, DeltaScan> = {};
|
|
219
|
+
await Promise.all(
|
|
220
|
+
deltaFiles.map(async ({ cap, file }) => {
|
|
221
|
+
const scan = await cachedParse<DeltaScan>(file, seen, scanDelta);
|
|
222
|
+
if (scan) deltas[cap] = scan;
|
|
223
|
+
}),
|
|
224
|
+
);
|
|
225
|
+
if (mtime !== undefined) {
|
|
226
|
+
// The files this change contributed (set difference is exact: paths are per change).
|
|
227
|
+
const files = [...seen].filter((f) => !before.has(f) && f.startsWith(dir + path.sep));
|
|
228
|
+
changeCache.set(dir, { mtime, files, inputs: { declared, proposal, deltas } });
|
|
229
|
+
seenChanges.add(dir);
|
|
230
|
+
}
|
|
231
|
+
return { name, declared, proposal, deltas };
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
const capabilityIds = [...new Set(changes.flatMap((c) => Object.keys(c.deltas)))].sort();
|
|
235
|
+
const [archived, mainFlags] = await Promise.all([
|
|
236
|
+
archivedNames(path.join(changesDir, "archive")),
|
|
237
|
+
mapLimit(capabilityIds, 32, (cap) => mainSpecExists(openspecDir, cap)),
|
|
238
|
+
]);
|
|
239
|
+
const mainSpecs = capabilityIds.filter((_, i) => mainFlags[i]);
|
|
240
|
+
|
|
241
|
+
// Prune entries of this tree that were not read this build (deleted files).
|
|
242
|
+
const prefix = openspecDir + path.sep;
|
|
243
|
+
for (const key of fileCache.keys()) if (key.startsWith(prefix) && !seen.has(key)) fileCache.delete(key);
|
|
244
|
+
for (const key of changeCache.keys()) if (key.startsWith(prefix) && !seenChanges.has(key)) changeCache.delete(key);
|
|
245
|
+
|
|
246
|
+
return { inputs: { changes, archived, mainSpecs }, capabilityIds };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export interface DependencyComputation {
|
|
250
|
+
graph: Record<string, ChangeDependencies>;
|
|
251
|
+
capabilityIds: string[];
|
|
252
|
+
/** Compute time (reads + graph), ms. */
|
|
253
|
+
ms: number;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Read inputs and compute the graph for the active `names`. */
|
|
257
|
+
export async function computeDependencies(
|
|
258
|
+
openspecDir: string,
|
|
259
|
+
names: string[],
|
|
260
|
+
mtimes?: Record<string, number | undefined>,
|
|
261
|
+
): Promise<DependencyComputation> {
|
|
262
|
+
const t0 = performance.now();
|
|
263
|
+
const { inputs, capabilityIds } = await collectDependencyInputs(openspecDir, names, mtimes);
|
|
264
|
+
const graph = computeDependencyGraph(inputs);
|
|
265
|
+
return { graph, capabilityIds, ms: performance.now() - t0 };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** One-line summary of a computed graph: edge counts by source, issue counts by severity, ms. */
|
|
269
|
+
export function summarizeDependencyGraph(graph: Record<string, ChangeDependencies>, ms: number): string {
|
|
270
|
+
const edges = { declared: 0, "inferred-text": 0, "inferred-capability": 0 };
|
|
271
|
+
const issues = { error: 0, warning: 0 };
|
|
272
|
+
for (const d of Object.values(graph)) {
|
|
273
|
+
for (const e of d.blockedBy) edges[e.source]++;
|
|
274
|
+
for (const i of d.issues) issues[i.severity]++;
|
|
275
|
+
}
|
|
276
|
+
return (
|
|
277
|
+
`[openspec-deps] changes=${Object.keys(graph).length} edges declared=${edges.declared} ` +
|
|
278
|
+
`inferred-text=${edges["inferred-text"]} inferred-capability=${edges["inferred-capability"]} ` +
|
|
279
|
+
`issues error=${issues.error} warning=${issues.warning} ms=${ms.toFixed(1)}`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
@@ -37,6 +37,44 @@ export function effectiveMtimeOr(paths: string[]): number | undefined {
|
|
|
37
37
|
return max;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/** Deepest nesting of capability ids under `specs/` that is probed (matches the dependency scanner's walk). */
|
|
41
|
+
export const MAX_SPEC_DEPTH = 6;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Every directory under `specsDir` plus its `spec.md`, nested capability ids included, so an in-place edit of
|
|
45
|
+
* `specs/area/feature/spec.md` moves the probed mtime (a parent directory's mtime does not advance for it).
|
|
46
|
+
* Errors (missing dir, permissions) leave the fan-out shorter, never throw.
|
|
47
|
+
*/
|
|
48
|
+
function specProbePathsSync(specsDir: string, depth: number): string[] {
|
|
49
|
+
const out: string[] = [];
|
|
50
|
+
try {
|
|
51
|
+
for (const e of fs.readdirSync(specsDir, { withFileTypes: true })) {
|
|
52
|
+
if (!e.isDirectory()) continue;
|
|
53
|
+
const capDir = path.join(specsDir, e.name);
|
|
54
|
+
out.push(capDir, path.join(capDir, "spec.md"));
|
|
55
|
+
if (depth + 1 < MAX_SPEC_DEPTH) out.push(...specProbePathsSync(capDir, depth + 1));
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
// ENOENT, permission denied, etc.
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function specProbePaths(specsDir: string, depth: number): Promise<string[]> {
|
|
64
|
+
const out: string[] = [];
|
|
65
|
+
try {
|
|
66
|
+
for (const e of await fs.promises.readdir(specsDir, { withFileTypes: true })) {
|
|
67
|
+
if (!e.isDirectory()) continue;
|
|
68
|
+
const capDir = path.join(specsDir, e.name);
|
|
69
|
+
out.push(capDir, path.join(capDir, "spec.md"));
|
|
70
|
+
if (depth + 1 < MAX_SPEC_DEPTH) out.push(...(await specProbePaths(capDir, depth + 1)));
|
|
71
|
+
}
|
|
72
|
+
} catch {
|
|
73
|
+
// no specs/ yet — fan-out stays empty
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
40
78
|
/**
|
|
41
79
|
* File set tracked by the per-change effective-mtime computation.
|
|
42
80
|
*
|
|
@@ -60,20 +98,7 @@ export function perChangeArtifactPaths(changesRoot: string, name: string): strin
|
|
|
60
98
|
path.join(dir, "design.md"),
|
|
61
99
|
];
|
|
62
100
|
const specsDir = path.join(dir, "specs");
|
|
63
|
-
const specsExtras: string[] = [specsDir];
|
|
64
|
-
try {
|
|
65
|
-
const entries = fs.readdirSync(specsDir, { withFileTypes: true });
|
|
66
|
-
for (const e of entries) {
|
|
67
|
-
if (e.isDirectory()) {
|
|
68
|
-
const capDir = path.join(specsDir, e.name);
|
|
69
|
-
specsExtras.push(capDir);
|
|
70
|
-
specsExtras.push(path.join(capDir, "spec.md"));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
} catch {
|
|
74
|
-
// ENOENT, permission denied, etc. — leave specsExtras with just specsDir
|
|
75
|
-
// (its own statMtimeOr will return undefined and be excluded from max).
|
|
76
|
-
}
|
|
101
|
+
const specsExtras: string[] = [specsDir, ...specProbePathsSync(specsDir, 0)];
|
|
77
102
|
return [...base, ...specsExtras];
|
|
78
103
|
}
|
|
79
104
|
|
|
@@ -84,10 +109,20 @@ export interface ProbeRequest {
|
|
|
84
109
|
openspecDir: string;
|
|
85
110
|
/** Per-change extras from the last successful `--all` result; `null` before the first one (legacy set only). */
|
|
86
111
|
extras: Record<string, TrackedExtras> | null;
|
|
112
|
+
/**
|
|
113
|
+
* Capability ids touched by an active delta in the previous build; the probe
|
|
114
|
+
* stats `specs/<cap>/` and `specs/<cap>/spec.md` for each (L2 reads main-spec
|
|
115
|
+
* existence). `null`/absent before the first build: the cwd-level stamp is
|
|
116
|
+
* then incomplete and the gate does not skip. See change: add-openspec-change-dependencies.
|
|
117
|
+
*/
|
|
118
|
+
capabilityIds?: readonly string[] | null;
|
|
87
119
|
}
|
|
88
120
|
|
|
89
121
|
export interface ProbeResponse {
|
|
90
|
-
/**
|
|
122
|
+
/**
|
|
123
|
+
* Max mtime over the cwd-level set (`openspec/`, `changes/`, `changes/archive/`, `config.yaml`,
|
|
124
|
+
* `specs/`, the main-spec paths of `capabilityIds`, everything under `schemas/`).
|
|
125
|
+
*/
|
|
91
126
|
cwdMtime: number | undefined;
|
|
92
127
|
/** Enumerated change directories (excludes `archive/` and dot-dirs), sorted by name. */
|
|
93
128
|
names: string[];
|
|
@@ -157,21 +192,27 @@ async function legacyChangePaths(changeDir: string): Promise<string[]> {
|
|
|
157
192
|
const base = [
|
|
158
193
|
changeDir,
|
|
159
194
|
path.join(changeDir, ".openspec.yaml"),
|
|
195
|
+
path.join(changeDir, "dependencies.yaml"),
|
|
160
196
|
path.join(changeDir, "tasks.md"),
|
|
161
197
|
path.join(changeDir, "proposal.md"),
|
|
162
198
|
path.join(changeDir, "design.md"),
|
|
163
199
|
];
|
|
164
200
|
const specsDir = path.join(changeDir, "specs");
|
|
165
|
-
const out = [...base, specsDir];
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
201
|
+
const out = [...base, specsDir, ...(await specProbePaths(specsDir, 0))];
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Cwd-level dependency inputs beyond the legacy set: `changes/archive/` (an
|
|
207
|
+
* archive satisfies edges), `openspec/specs/` and, for each capability id,
|
|
208
|
+
* every directory prefix plus `spec.md` (directory mtimes catch deletions).
|
|
209
|
+
*/
|
|
210
|
+
function dependencyCwdPaths(openspecDir: string, capabilityIds: readonly string[] | null | undefined): string[] {
|
|
211
|
+
const out = [path.join(openspecDir, "changes", "archive"), path.join(openspecDir, "specs")];
|
|
212
|
+
for (const cap of capabilityIds ?? []) {
|
|
213
|
+
const parts = cap.split("/");
|
|
214
|
+
for (let i = 1; i <= parts.length; i++) out.push(path.join(openspecDir, "specs", ...parts.slice(0, i)));
|
|
215
|
+
out.push(path.join(openspecDir, "specs", ...parts, "spec.md"));
|
|
175
216
|
}
|
|
176
217
|
return out;
|
|
177
218
|
}
|
|
@@ -189,7 +230,12 @@ export async function probeTrackedPaths(req: ProbeRequest): Promise<ProbeRespons
|
|
|
189
230
|
|
|
190
231
|
const cwdPaths = [openspecDir, changesDir, path.join(openspecDir, "config.yaml")];
|
|
191
232
|
const schemaTree = await walk(path.join(openspecDir, "schemas"), true);
|
|
192
|
-
const cwdMtime = await maxMtime([
|
|
233
|
+
const cwdMtime = await maxMtime([
|
|
234
|
+
...cwdPaths,
|
|
235
|
+
...dependencyCwdPaths(openspecDir, req.capabilityIds),
|
|
236
|
+
path.join(openspecDir, "schemas"),
|
|
237
|
+
...schemaTree,
|
|
238
|
+
]);
|
|
193
239
|
|
|
194
240
|
const mtimes = await mapLimit(names, 16, async (name) => {
|
|
195
241
|
const changeDir = path.join(changesDir, name);
|