@blackbelt-technology/pi-agent-dashboard 0.9.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.
- package/AGENTS.md +2 -2
- package/README.md +85 -11
- package/docs/architecture.md +3020 -116
- package/package.json +31 -18
- package/packages/extension/package.json +10 -8
- package/packages/extension/src/ask-user-tool.ts +65 -3
- package/packages/extension/src/auto-session-namer.ts +190 -50
- package/packages/extension/src/bridge-handlers/dispatch.ts +504 -0
- package/packages/extension/src/bridge-handlers/forwarders.ts +616 -0
- package/packages/extension/src/bridge-handlers/instance.ts +229 -0
- package/packages/extension/src/bridge-handlers/lifecycle.ts +1069 -0
- package/packages/extension/src/bridge-handlers/ui-prompt-patch.ts +198 -0
- package/packages/extension/src/bridge-identity-log.ts +45 -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 +517 -2534
- package/packages/extension/src/canvas-tool.ts +2 -0
- package/packages/extension/src/command-handler.ts +259 -16
- package/packages/extension/src/connect-target.ts +23 -0
- package/packages/extension/src/connection.ts +294 -24
- package/packages/extension/src/dashboard-context-injector.ts +26 -47
- package/packages/extension/src/dashboard-http-origin.ts +88 -0
- package/packages/extension/src/dev-build.ts +11 -1
- package/packages/extension/src/empty-actionable-guard.ts +8 -3
- package/packages/extension/src/flow-event-wiring.ts +1 -1
- package/packages/extension/src/followup-buffer.ts +1 -1
- package/packages/extension/src/followup-drain.ts +79 -0
- 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 +232 -17
- package/packages/extension/src/message-update-coalescer.ts +3 -1
- package/packages/extension/src/model-refresh.ts +88 -0
- package/packages/extension/src/multiselect-list.ts +6 -2
- package/packages/extension/src/multiselect-polyfill.ts +2 -2
- package/packages/extension/src/openspec-cli-shim.ts +1 -1
- package/packages/extension/src/path-gate/decide.ts +15 -41
- package/packages/extension/src/path-gate/grant-cache.ts +3 -1
- package/packages/extension/src/path-gate/handler.ts +51 -2
- package/packages/extension/src/path-gate/index.ts +12 -1
- package/packages/extension/src/path-gate/resolve.ts +6 -124
- package/packages/extension/src/path-gate/roots.ts +4 -1
- package/packages/extension/src/path-gate/suppression.ts +4 -1
- package/packages/extension/src/path-gate/yolo-link.ts +104 -0
- package/packages/extension/src/pinned-endpoint.ts +44 -0
- package/packages/extension/src/plugin-event-forward-registry.ts +200 -0
- package/packages/extension/src/project-trust-live.ts +143 -0
- package/packages/extension/src/project-trust.ts +258 -25
- package/packages/extension/src/prompt-expander.ts +5 -1
- package/packages/extension/src/prompt-meta.ts +64 -0
- package/packages/extension/src/provider-register.ts +146 -38
- package/packages/extension/src/remote-registration-gate.ts +21 -21
- package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
- package/packages/extension/src/role-manager.ts +5 -4
- package/packages/extension/src/role-model-tools.ts +47 -6
- package/packages/extension/src/server-auto-start.ts +13 -6
- package/packages/extension/src/server-launcher.ts +11 -13
- package/packages/extension/src/server-proof-probe.ts +117 -0
- package/packages/extension/src/session-move.ts +19 -0
- package/packages/extension/src/session-sync.ts +73 -50
- package/packages/extension/src/spawn-token.ts +46 -0
- package/packages/extension/src/stream-forward-buffer.ts +161 -0
- package/packages/extension/src/subagent-frame-buffer.ts +6 -2
- package/packages/extension/src/subagent-tick-throttle.ts +3 -1
- package/packages/extension/src/vault-delivery.ts +404 -0
- package/packages/extension/src/vault-forwarder.ts +128 -0
- package/packages/extension/src/vault-masker.ts +165 -0
- package/packages/extension/src/vault-redaction.ts +181 -0
- package/packages/extension/src/vcs-info.ts +5 -2
- package/packages/server/bin/pi-dashboard.mjs +26 -89
- package/packages/server/package.json +29 -15
- package/packages/server/src/access/access-grants.ts +79 -8
- package/packages/server/src/access/access-health.ts +10 -0
- package/packages/server/src/access/access-plane.ts +5 -1
- package/packages/server/src/access/agent-confirm-registry.ts +31 -13
- package/packages/server/src/access/agent-grant.ts +1 -1
- package/packages/server/src/access/agent-yolo.ts +91 -0
- package/packages/server/src/access/containment-gate.ts +82 -17
- package/packages/server/src/access/cwd-admission-log.ts +46 -0
- package/packages/server/src/access/cwd-verdict.ts +144 -0
- package/packages/server/src/access/grant-coordinator.ts +3 -1
- package/packages/server/src/access/pi-trust-live.ts +244 -0
- package/packages/server/src/access/pi-trust-mirror-service.ts +407 -0
- package/packages/server/src/access/planes.ts +116 -2
- 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/refusal-ledger.ts +6 -6
- package/packages/server/src/access/yolo-session.ts +127 -14
- package/packages/server/src/acp-bridge/acp-connection.ts +225 -0
- package/packages/server/src/acp-bridge/acp-restore.ts +41 -0
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +549 -0
- package/packages/server/src/acp-bridge/child-env.ts +73 -0
- package/packages/server/src/acp-bridge/event-log.ts +194 -0
- package/packages/server/src/acp-bridge/gateway-client.ts +136 -0
- package/packages/server/src/acp-bridge/local-bridge-socket.ts +67 -0
- package/packages/server/src/acp-bridge/local-host.ts +132 -0
- package/packages/server/src/acp-bridge/main.ts +118 -0
- package/packages/server/src/acp-bridge/models.ts +33 -0
- package/packages/server/src/acp-bridge/permission-bridge.ts +106 -0
- package/packages/server/src/acp-bridge/server-requests.ts +136 -0
- package/packages/server/src/acp-bridge/session-state.ts +127 -0
- package/packages/server/src/addons/addon-toggle-restore.ts +110 -0
- package/packages/server/src/addons/addons-catalog.ts +408 -0
- package/packages/server/src/addons/addons-folder-service.ts +347 -0
- package/packages/server/src/addons/addons-folder.ts +310 -0
- package/packages/server/src/addons/addons-service.ts +470 -0
- package/packages/server/src/addons/package-contents.ts +99 -0
- package/packages/server/src/addons/settings-entries.ts +120 -0
- package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
- package/packages/server/src/attachments/fit-worker-pool.ts +12 -17
- package/packages/server/src/auth/approval-refusal.ts +87 -0
- package/packages/server/src/auth/audit-log.ts +80 -0
- package/packages/server/src/auth/auth-plugin.ts +329 -97
- package/packages/server/src/auth/auth.ts +102 -11
- package/packages/server/src/auth/bearer-auth.ts +74 -12
- package/packages/server/src/auth/cors-origin.ts +86 -29
- package/packages/server/src/auth/csp-report-paths.ts +31 -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 +111 -9
- 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/host-admission.ts +26 -0
- package/packages/server/src/auth/host-gate.ts +6 -1
- package/packages/server/src/auth/local-credential.ts +258 -0
- package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
- package/packages/server/src/auth/local-proof.ts +76 -22
- package/packages/server/src/auth/local-token.ts +16 -0
- package/packages/server/src/auth/localhost-guard.ts +298 -17
- package/packages/server/src/auth/nav-intent.ts +72 -0
- package/packages/server/src/auth/network-trust-telemetry.ts +126 -0
- package/packages/server/src/auth/node-guard.ts +43 -0
- package/packages/server/src/auth/operate-required.ts +126 -0
- package/packages/server/src/auth/passkey/challenge-store.ts +90 -0
- package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
- package/packages/server/src/auth/passkey/passkey-log.ts +34 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +109 -0
- package/packages/server/src/auth/passkey/passkey-routes.ts +232 -0
- package/packages/server/src/auth/passkey/passkey-service.ts +247 -0
- package/packages/server/src/auth/passkey/phone-signin.ts +211 -0
- package/packages/server/src/auth/passkey/requester.ts +83 -0
- package/packages/server/src/auth/passkey/rp-context.ts +98 -0
- package/packages/server/src/auth/passkey/user-directory.ts +348 -0
- package/packages/server/src/auth/pi-legacy-credentials.ts +324 -0
- 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-registry.ts +35 -1
- package/packages/server/src/auth/provider-auth-storage.ts +61 -9
- package/packages/server/src/auth/radius-mcp.ts +1 -1
- package/packages/server/src/auth/radius-override.ts +13 -0
- package/packages/server/src/auth/request-principal.ts +32 -0
- package/packages/server/src/auth/route-tier-gate.ts +27 -11
- package/packages/server/src/auth/runtime-provider-catalogue.ts +107 -0
- package/packages/server/src/auth/scan-legacy-provider-ids.ts +80 -0
- 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 +197 -0
- package/packages/server/src/auth/trust-mode-boot.ts +93 -0
- package/packages/server/src/auth/trust-mode.ts +83 -0
- package/packages/server/src/auth/ws-ticket.ts +39 -1
- package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
- package/packages/server/src/auto-name-outcome-store.ts +4 -1
- package/packages/server/src/browse.ts +114 -2
- package/packages/server/src/browser-handlers/acp-guard.ts +79 -0
- package/packages/server/src/browser-handlers/directory-handler.ts +151 -6
- 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 +138 -63
- package/packages/server/src/browser-handlers/session-meta-handler.ts +16 -6
- package/packages/server/src/browser-handlers/spawn-choice.ts +99 -0
- package/packages/server/src/browser-handlers/subscription-handler.ts +100 -2
- package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
- package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
- package/packages/server/src/cli.ts +1063 -106
- package/packages/server/src/config-api.ts +166 -2
- package/packages/server/src/config-snapshot.ts +53 -1
- package/packages/server/src/directory-service.ts +545 -36
- package/packages/server/src/embed-lifecycle/caps.ts +35 -4
- package/packages/server/src/embed-lifecycle/embed-lifecycle-controller.ts +45 -4
- package/packages/server/src/embed-lifecycle/idle-reaper.ts +195 -20
- package/packages/server/src/embed-lifecycle/lifecycle-metrics.ts +38 -0
- package/packages/server/src/embed-lifecycle/plugin-session-close.ts +123 -0
- package/packages/server/src/embed-lifecycle/quiescence.ts +29 -3
- package/packages/server/src/embed-lifecycle/reclaim-give-up.ts +54 -0
- package/packages/server/src/event-wiring.ts +349 -141
- package/packages/server/src/file-watch-manager.ts +187 -39
- package/packages/server/src/git-worktree/git-operations.ts +60 -15
- 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/worktree-init-trust.ts +91 -6
- package/packages/server/src/git-worktree/worktree-init.ts +7 -56
- package/packages/server/src/identity/host-resources.ts +3 -0
- package/packages/server/src/identity/http-road-classification.ts +31 -1
- package/packages/server/src/identity/identity-registration-tracker.ts +4 -1
- package/packages/server/src/identity/plugin-identity.ts +19 -0
- package/packages/server/src/identity/policy-registry.ts +4 -1
- package/packages/server/src/identity/resolver-registry.ts +12 -3
- package/packages/server/src/identity/ws-message-scope.ts +10 -0
- package/packages/server/src/identity/ws-road-classification.ts +10 -0
- package/packages/server/src/known-server-moves.ts +196 -0
- package/packages/server/src/lib/browse-roots.ts +137 -0
- package/packages/server/src/lib/client-dist.ts +36 -21
- package/packages/server/src/lib/dashboard-state-guard.ts +230 -0
- package/packages/server/src/lib/diagram-render.ts +4 -6
- package/packages/server/src/lib/digest-gate.ts +82 -0
- package/packages/server/src/lib/eml.ts +3 -8
- package/packages/server/src/lib/file-cwd-admission.ts +145 -0
- package/packages/server/src/lib/file-write-lock.ts +24 -0
- package/packages/server/src/lib/folder-project.ts +439 -0
- package/packages/server/src/lib/grep-worker.ts +23 -0
- package/packages/server/src/lib/grep.ts +93 -7
- package/packages/server/src/lib/index-html.ts +81 -0
- package/packages/server/src/lib/office-preview.ts +2 -3
- package/packages/server/src/lib/path-containment.ts +7 -0
- package/packages/server/src/lib/purify.ts +13 -5
- package/packages/server/src/lib/resolve-file-mention.ts +11 -9
- package/packages/server/src/lib/route-admission.ts +80 -0
- package/packages/server/src/lib/writable-handler-target.ts +66 -0
- package/packages/server/src/lib/writable-md-target.ts +16 -1
- package/packages/server/src/lifecycle/classify-dashboard-port.ts +134 -0
- package/packages/server/src/lifecycle/home-lock.ts +344 -130
- package/packages/server/src/lifecycle/home-rendezvous.ts +41 -11
- package/packages/server/src/lifecycle/recovery-server.ts +129 -6
- package/packages/server/src/lifecycle/stop-ownership.ts +97 -11
- package/packages/server/src/live-server/capability-redact.ts +15 -0
- package/packages/server/src/live-server/live-browser-gate.ts +22 -0
- package/packages/server/src/live-server/live-capability.ts +461 -0
- package/packages/server/src/live-server/live-csp-report.ts +63 -0
- package/packages/server/src/live-server/live-csp.ts +93 -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 +21 -0
- package/packages/server/src/live-server/live-origin-scan.ts +298 -0
- package/packages/server/src/live-server/live-server-manager.ts +209 -33
- package/packages/server/src/live-server/live-server-proxy.ts +326 -34
- package/packages/server/src/live-server/live-static.ts +228 -0
- package/packages/server/src/metrics/eventloop-spike-metrics.ts +2 -2
- package/packages/server/src/model-proxy/internal-auth-storage.ts +27 -26
- package/packages/server/src/model-proxy/internal-registry.ts +6 -0
- package/packages/server/src/model-proxy/server-model-runtime.ts +6 -0
- package/packages/server/src/openspec/dependencies-file.ts +122 -0
- package/packages/server/src/openspec/openspec-change-watcher.ts +111 -16
- package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +189 -11
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +126 -35
- package/packages/server/src/openspec/openspec-poll-worker.ts +286 -44
- package/packages/server/src/openspec/proposal-attach-naming.ts +5 -3
- package/packages/server/src/openspec/readiness.ts +9 -0
- package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
- package/packages/server/src/openspec/workflow-schema.ts +1002 -0
- package/packages/server/src/package/installed-package-enricher.ts +38 -3
- package/packages/server/src/package/npm-search-proxy.ts +5 -2
- package/packages/server/src/package/package-health-scanner.ts +133 -0
- package/packages/server/src/package/package-manager-wrapper.ts +18 -2
- package/packages/server/src/package/provider-catalogue-cache.ts +17 -3
- package/packages/server/src/package/provider-probe.ts +13 -5
- package/packages/server/src/pairing/browser-gateway.ts +292 -16
- package/packages/server/src/pairing/device-token-services.ts +26 -0
- package/packages/server/src/pairing/knock-admission.ts +277 -0
- package/packages/server/src/pairing/paired-devices.ts +335 -22
- package/packages/server/src/pairing/pairing.ts +188 -31
- package/packages/server/src/pairing/socket-locality.ts +26 -0
- package/packages/server/src/pairing/subagent-resync-routing.ts +4 -1
- package/packages/server/src/pairing/ws-tier-gate.ts +34 -0
- package/packages/server/src/peer-servers.ts +77 -0
- package/packages/server/src/pending/pending-plugin-ref-registry.ts +57 -2
- package/packages/server/src/persistence/boot-state.ts +48 -1
- package/packages/server/src/persistence/memory-event-store.ts +216 -237
- package/packages/server/src/persistence/meta-persistence.ts +12 -1
- package/packages/server/src/persistence/preferences-store.ts +125 -7
- package/packages/server/src/pi/bridge-channel.ts +33 -0
- package/packages/server/src/pi/bridge-upgrade-auth.ts +48 -22
- package/packages/server/src/pi/folder-commands.ts +141 -0
- package/packages/server/src/pi/gateway-listeners.ts +9 -3
- package/packages/server/src/pi/gateway-socket-bind.ts +9 -3
- package/packages/server/src/pi/gateway-transport-policy.ts +13 -0
- package/packages/server/src/pi/host-project-trust.ts +166 -33
- package/packages/server/src/pi/pi-gateway.ts +283 -29
- package/packages/server/src/pi/pi-resource-scanner.ts +15 -0
- package/packages/server/src/pi/resource-activation-toggle.ts +6 -0
- package/packages/server/src/pi/resource-toggle-trust.ts +34 -2
- package/packages/server/src/pi/session-skill-registry.ts +13 -3
- package/packages/server/src/pi/settings-write-lock.ts +32 -0
- package/packages/server/src/pi/trust-challenges.ts +38 -0
- package/packages/server/src/pi-agent-settings.ts +701 -100
- package/packages/server/src/pi-settings-themes.ts +104 -0
- package/packages/server/src/plugin-discovery-wiring.ts +142 -0
- package/packages/server/src/plugin-event-seam.ts +116 -4
- package/packages/server/src/plugin-runtime-clients.ts +89 -0
- package/packages/server/src/questions/brief-generator.ts +138 -0
- package/packages/server/src/questions/brief-model.ts +55 -0
- package/packages/server/src/questions/brief-policy.ts +36 -0
- package/packages/server/src/questions/brief-prompt.ts +92 -0
- package/packages/server/src/questions/brief-runtime.ts +50 -0
- package/packages/server/src/questions/question-answer.ts +55 -0
- package/packages/server/src/questions/question-broadcast.ts +106 -0
- package/packages/server/src/questions/question-files.ts +128 -0
- package/packages/server/src/questions/question-routes.ts +126 -0
- package/packages/server/src/questions/question-snapshot.ts +150 -0
- package/packages/server/src/questions/question-stack.ts +57 -0
- package/packages/server/src/questions/question-store.ts +477 -0
- package/packages/server/src/routes/access-prompt-routes.ts +5 -3
- package/packages/server/src/routes/access-routes.ts +274 -6
- package/packages/server/src/routes/acme-routes.ts +190 -0
- package/packages/server/src/routes/acp-routes.ts +16 -0
- package/packages/server/src/routes/addons-routes.ts +221 -0
- 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 +620 -209
- package/packages/server/src/routes/file-write-binary-routes.ts +530 -0
- package/packages/server/src/routes/folder-project-routes.ts +105 -0
- package/packages/server/src/routes/git-routes.ts +334 -203
- package/packages/server/src/routes/grep-routes.ts +38 -14
- package/packages/server/src/routes/known-servers-routes.ts +433 -55
- package/packages/server/src/routes/live-server-routes.ts +438 -7
- package/packages/server/src/routes/local-proof-routes.ts +26 -7
- package/packages/server/src/routes/mermaid-repair-routes.ts +254 -0
- package/packages/server/src/routes/model-proxy-routes.ts +4 -2
- 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 +636 -55
- package/packages/server/src/routes/package-health-routes.ts +140 -0
- package/packages/server/src/routes/package-routes.ts +86 -11
- package/packages/server/src/routes/pairing-routes.ts +303 -33
- package/packages/server/src/routes/pi-retry-routes.ts +18 -2
- package/packages/server/src/routes/pi-settings-routes.ts +264 -0
- package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
- package/packages/server/src/routes/plugin-activation-routes.ts +146 -27
- package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
- package/packages/server/src/routes/provider-auth-routes.ts +37 -7
- package/packages/server/src/routes/provider-routes.ts +29 -0
- package/packages/server/src/routes/resource-activation-routes.ts +33 -35
- package/packages/server/src/routes/session-routes.ts +100 -9
- package/packages/server/src/routes/system-routes.ts +286 -33
- package/packages/server/src/routes/tls-routes.ts +55 -0
- package/packages/server/src/routes/ui-link-base.ts +88 -0
- package/packages/server/src/routes/user-routes.ts +192 -0
- package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
- package/packages/server/src/runtime-overlay/runtime-stager.ts +15 -2
- package/packages/server/src/runtime-overlay/runtime-update-checker.ts +11 -2
- package/packages/server/src/server.ts +1537 -246
- package/packages/server/src/services/attached-driver.ts +175 -0
- package/packages/server/src/services/change-notifier.ts +55 -0
- package/packages/server/src/services/cli-service.ts +450 -0
- package/packages/server/src/services/command-runner.ts +92 -0
- package/packages/server/src/services/definitions-store.ts +121 -0
- package/packages/server/src/services/driver.ts +112 -0
- package/packages/server/src/services/health.ts +94 -0
- package/packages/server/src/services/leases.ts +117 -0
- package/packages/server/src/services/log-text.ts +97 -0
- package/packages/server/src/services/native-driver.ts +283 -0
- package/packages/server/src/services/oci-driver.ts +590 -0
- package/packages/server/src/services/output-capture.ts +183 -0
- package/packages/server/src/services/paths.ts +82 -0
- package/packages/server/src/services/ports.ts +26 -0
- package/packages/server/src/services/routes.ts +140 -0
- package/packages/server/src/services/runtime-detect.ts +108 -0
- package/packages/server/src/services/secret-delivery.ts +61 -0
- package/packages/server/src/services/secrets-resolver.ts +145 -0
- package/packages/server/src/services/secrets-store.ts +137 -0
- package/packages/server/src/services/service-manager.ts +1565 -0
- package/packages/server/src/services/start-record.ts +66 -0
- package/packages/server/src/services/state-machine.ts +241 -0
- package/packages/server/src/session/archive-sweeper.ts +92 -3
- package/packages/server/src/session/custom-event-group-matcher.ts +4 -3
- package/packages/server/src/session/hydration-state.ts +148 -0
- package/packages/server/src/session/in-flight-tool-calls.ts +74 -0
- package/packages/server/src/session/memory-session-manager.ts +60 -0
- package/packages/server/src/session/name-provenance.ts +102 -0
- package/packages/server/src/session/open-tool-calls.ts +15 -6
- 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/session-api.ts +47 -12
- package/packages/server/src/session/session-archive.ts +56 -4
- package/packages/server/src/session/session-diff-cache.ts +11 -4
- package/packages/server/src/session/session-load-worker-pool.ts +4 -3
- package/packages/server/src/session/session-load-worker.ts +11 -2
- package/packages/server/src/session/session-scanner.ts +73 -3
- package/packages/server/src/session/session-to-meta.ts +15 -0
- package/packages/server/src/spawn-process/abort-spawned-run.ts +55 -0
- package/packages/server/src/spawn-process/acp-spawn.ts +131 -0
- package/packages/server/src/spawn-process/headless-pid-registry.ts +14 -9
- package/packages/server/src/spawn-process/process-manager.ts +164 -30
- package/packages/server/src/spawn-process/restart-helper.ts +9 -8
- package/packages/server/src/spawn-process/server-pid.ts +16 -7
- package/packages/server/src/spawn-process/session-terminator.ts +218 -0
- package/packages/server/src/spawn-process/spawn-env-contributors.ts +159 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +10 -1
- package/packages/server/src/terminal/terminal-manager.ts +75 -1
- package/packages/server/src/tls/cert-files.ts +228 -0
- package/packages/server/src/tls/cert-manager.ts +703 -0
- package/packages/server/src/tls/cert-store.ts +69 -0
- package/packages/server/src/tls/source-registry.ts +71 -0
- package/packages/server/src/tls/sources/acme/accounts.ts +76 -0
- package/packages/server/src/tls/sources/acme/acme-source.ts +508 -0
- package/packages/server/src/tls/sources/acme/config-projection.ts +34 -0
- package/packages/server/src/tls/sources/acme/credentials.ts +185 -0
- package/packages/server/src/tls/sources/acme/dns.ts +303 -0
- package/packages/server/src/tls/sources/acme/e2e-overrides.ts +49 -0
- package/packages/server/src/tls/sources/acme/entry.ts +180 -0
- package/packages/server/src/tls/sources/acme/gc.ts +78 -0
- package/packages/server/src/tls/sources/acme/runtime.ts +51 -0
- package/packages/server/src/tls/sources/acme/solvers/acme-dns.ts +154 -0
- package/packages/server/src/tls/sources/acme/solvers/cloudflare.ts +147 -0
- package/packages/server/src/tls/sources/acme/types.ts +72 -0
- package/packages/server/src/tls/sources/tailscale-cert.ts +172 -0
- package/packages/server/src/tls/tls-bridge-route.ts +61 -0
- package/packages/server/src/tls/tls-config-validation.ts +94 -0
- package/packages/server/src/tls/tls-listener.ts +351 -0
- package/packages/server/src/tls/types.ts +80 -0
- package/packages/server/src/tunnel/tunnel-block-events.ts +4 -1
- package/packages/server/src/tunnel/tunnel-core.ts +4 -1
- package/packages/server/src/tunnel/tunnel-endpoints.ts +4 -0
- package/packages/server/src/tunnel-providers/tailscale.ts +27 -6
- package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
- package/packages/server/src/vault/vault-bindings.ts +101 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +424 -0
- package/packages/server/src/vault/vault-grants.ts +260 -0
- package/packages/server/src/vault/vault-import.ts +161 -0
- package/packages/server/src/vault/vault-permissions.ts +39 -0
- package/packages/server/src/vault/vault-plugin-read.ts +64 -0
- package/packages/server/src/vault/vault-projects.ts +156 -0
- package/packages/server/src/vault/vault-routes.ts +277 -0
- package/packages/server/src/vault/vault-store.ts +371 -0
- package/packages/server/src/watch-files-handler.ts +66 -0
- package/packages/shared/package.json +5 -2
- package/packages/shared/src/acp/acp-config.ts +123 -0
- package/packages/shared/src/acp/normalize-v1.ts +92 -0
- package/packages/shared/src/acp/paths.ts +36 -0
- package/packages/shared/src/acp/to-dashboard-events.ts +533 -0
- package/packages/shared/src/acp/update-model.ts +574 -0
- package/packages/shared/src/anthropic-messages-source.ts +8 -0
- package/packages/shared/src/bind-reachability.ts +21 -2
- package/packages/shared/src/boot-state.ts +6 -0
- package/packages/shared/src/browser-host-identity.ts +49 -0
- package/packages/shared/src/browser-host-ipc.ts +107 -0
- package/packages/shared/src/browser-protocol.ts +533 -73
- package/packages/shared/src/canonical-subject.ts +27 -2
- package/packages/shared/src/canvas-declare.ts +27 -0
- package/packages/shared/src/card-sections.ts +185 -1
- package/packages/shared/src/chrome-profiles.ts +188 -0
- package/packages/shared/src/config.ts +817 -51
- package/packages/shared/src/containment-guard.ts +35 -0
- package/packages/shared/src/custom-event-groups.ts +5 -2
- package/packages/shared/src/cwd-guard.ts +381 -1
- package/packages/shared/src/dashboard-paths.ts +12 -0
- package/packages/shared/src/dashboard-plugin/anthropic-peer-names.ts +9 -0
- package/packages/shared/src/dashboard-plugin/editor-pane-tab.ts +26 -0
- package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +73 -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 +9 -3
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +160 -3
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +54 -0
- package/packages/shared/src/dashboard-plugin/project-identity.ts +42 -0
- package/packages/shared/src/dashboard-plugin/project-markers.ts +60 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +139 -2
- package/packages/shared/src/dashboard-plugin/slot-types.ts +72 -4
- package/packages/shared/src/dashboard-plugin/subagent-types.ts +219 -0
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +50 -3
- package/packages/shared/src/dashboard-starter.ts +30 -0
- package/packages/shared/src/display-name.ts +42 -0
- package/packages/shared/src/display-prefs.ts +13 -0
- package/packages/shared/src/doctor-core.ts +119 -134
- package/packages/shared/src/enabled-models-match.ts +47 -0
- package/packages/shared/src/event-forward-declaration.ts +187 -0
- package/packages/shared/src/file-kind.ts +54 -2
- package/packages/shared/src/git-worktree-helpers.ts +8 -4
- package/packages/shared/src/grammar-types.ts +3 -1
- package/packages/shared/src/host-admission.ts +2 -1
- package/packages/shared/src/host-port.ts +34 -0
- package/packages/shared/src/launcher-origin.ts +26 -0
- package/packages/shared/src/live-server.ts +141 -0
- package/packages/shared/src/local-credential-proof.ts +219 -0
- package/packages/shared/src/local-proof-signal.ts +16 -0
- package/packages/shared/src/loopback-host.ts +26 -0
- package/packages/shared/src/markup-repair/asciidoc.ts +130 -0
- package/packages/shared/src/markup-repair/types.ts +13 -0
- package/packages/shared/src/mcp/verb-tiers.generated.ts +178 -0
- package/packages/shared/src/md-table-cell.ts +11 -0
- package/packages/shared/src/mdns-discovery.ts +414 -45
- package/packages/shared/src/models-json-reader.ts +6 -0
- package/packages/shared/src/nav-intent.ts +29 -0
- package/packages/shared/src/openspec-dependencies.ts +760 -0
- package/packages/shared/src/openspec-design-evidence.ts +25 -1
- package/packages/shared/src/openspec-poller.ts +213 -11
- package/packages/shared/src/openspec-status-all.ts +393 -0
- package/packages/shared/src/operate-required.ts +29 -0
- package/packages/shared/src/pairing-knock-client.ts +301 -0
- package/packages/shared/src/pairing-knock.ts +71 -0
- package/packages/shared/src/pairing-refusal.ts +32 -0
- package/packages/shared/src/path-containment-guard-name.ts +8 -0
- package/packages/shared/src/pi-settings-keys.ts +9 -0
- package/packages/shared/src/pi-settings-schema.ts +285 -0
- package/packages/shared/src/pi-trust-live-query.ts +93 -0
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +198 -0
- package/packages/shared/src/pi-trust-mirror-types.ts +90 -0
- package/packages/shared/src/pi-trust-mirror.ts +354 -0
- package/packages/shared/src/pi-trust-resource-digest.ts +255 -0
- package/packages/shared/src/platform/binary-lookup.ts +2 -194
- 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 +210 -4
- package/packages/shared/src/platform/native-ts-hooks.mjs +93 -40
- package/packages/shared/src/platform/native-ts-register.mjs +22 -10
- package/packages/shared/src/platform/native-ts-tier.d.mts +1 -0
- package/packages/shared/src/platform/native-ts-tier.mjs +17 -0
- package/packages/shared/src/platform/node-spawn.ts +1 -2
- package/packages/shared/src/platform/openspec.ts +129 -31
- package/packages/shared/src/platform/process-scan.ts +199 -1
- package/packages/shared/src/platform/process.ts +99 -4
- package/packages/shared/src/platform/resolve-pi-shell.ts +76 -0
- package/packages/shared/src/platform/runner.ts +46 -2
- package/packages/shared/src/platform/select-git-source.ts +7 -0
- package/packages/shared/src/platform/spawn-mechanism.ts +14 -2
- package/packages/shared/src/platform/ts-loader-select.d.mts +1 -7
- package/packages/shared/src/platform/ts-loader-select.mjs +14 -43
- package/packages/shared/src/plugin-bridge-register.ts +24 -1
- package/packages/shared/src/plugin-route-cwd.ts +95 -0
- package/packages/shared/src/preview-egress.ts +138 -0
- package/packages/shared/src/project-name.ts +42 -0
- package/packages/shared/src/project-root.ts +16 -0
- package/packages/shared/src/prompt-answer.ts +183 -0
- package/packages/shared/src/protocol.ts +172 -8
- package/packages/shared/src/question-types.ts +73 -0
- package/packages/shared/src/recommended-extensions.ts +98 -23
- package/packages/shared/src/recovery-timing.ts +39 -0
- package/packages/shared/src/redaction.ts +50 -0
- package/packages/shared/src/remote-credentials.ts +63 -0
- package/packages/shared/src/rest-api.ts +533 -3
- package/packages/shared/src/role-config-disk.ts +23 -0
- package/packages/shared/src/role-schema.ts +79 -0
- package/packages/shared/src/route-tiers.ts +181 -0
- 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/manifest.d.mts +7 -0
- package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
- package/packages/shared/src/runtime-overlay/materialize-plugins.d.mts +17 -0
- package/packages/shared/src/runtime-overlay/materialize-plugins.mjs +119 -8
- package/packages/shared/src/safe-local-path.ts +24 -0
- package/packages/shared/src/sanitize-profiles.ts +98 -0
- package/packages/shared/src/server-identity.ts +51 -15
- package/packages/shared/src/server-launcher.ts +21 -34
- package/packages/shared/src/server-pinning.ts +136 -2
- package/packages/shared/src/server-routes.ts +462 -0
- package/packages/shared/src/services/offers.ts +114 -0
- package/packages/shared/src/services/schema.ts +628 -0
- package/packages/shared/src/services/status.ts +169 -0
- package/packages/shared/src/session-meta.ts +59 -2
- package/packages/shared/src/session-name.ts +8 -0
- package/packages/shared/src/session-ui-path.ts +11 -0
- package/packages/shared/src/skill-block-parser.ts +14 -0
- package/packages/shared/src/source-matching.ts +5 -1
- package/packages/shared/src/state-replay.ts +19 -0
- package/packages/shared/src/terminal-safe.ts +24 -0
- package/packages/shared/src/tls-only-token.ts +16 -0
- package/packages/shared/src/tls-status.ts +69 -0
- package/packages/shared/src/tool-path-resolve.ts +243 -0
- package/packages/shared/src/tool-registry/definitions.ts +31 -9
- package/packages/shared/src/tool-registry/index.ts +2 -2
- package/packages/shared/src/tool-registry/pi-tools.ts +32 -3
- package/packages/shared/src/tool-registry/strategies.ts +12 -11
- package/packages/shared/src/tunnel-provider.ts +3 -2
- package/packages/shared/src/types.ts +170 -9
- package/packages/shared/src/url-policy.ts +96 -0
- package/packages/shared/src/vault-delivery.ts +88 -0
- package/packages/shared/src/vault-origin.ts +51 -0
- package/packages/shared/src/vault-project-key.ts +53 -0
- package/packages/shared/src/worktree-init-hook.ts +69 -0
- package/packages/shared/src/ws-message-tiers.ts +136 -0
- package/tsconfig.base.json +1 -0
|
@@ -2,8 +2,23 @@
|
|
|
2
2
|
* OpenSpec and Pi Resources REST API routes (localhost-only).
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { realpathSync } from "node:fs";
|
|
5
6
|
import fs from "node:fs/promises";
|
|
6
7
|
import path from "node:path";
|
|
8
|
+
import { DEFAULT_OPENSPEC_POLL, type OpenSpecPollConfig } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
9
|
+
import {
|
|
10
|
+
type AdmitCwdOptions,
|
|
11
|
+
admissionAllows,
|
|
12
|
+
releaseAdmission,
|
|
13
|
+
} from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
|
|
14
|
+
import {
|
|
15
|
+
type DeclaredDependencies,
|
|
16
|
+
type FileStat,
|
|
17
|
+
KEBAB_ID_REGEX,
|
|
18
|
+
MAX_DEPENDENCIES_BYTES,
|
|
19
|
+
MAX_REASON_CHARS,
|
|
20
|
+
serializeDependencies,
|
|
21
|
+
} from "@blackbelt-technology/pi-dashboard-shared/openspec-dependencies.js";
|
|
7
22
|
import {
|
|
8
23
|
configListAsync,
|
|
9
24
|
configListOrAsync,
|
|
@@ -16,10 +31,20 @@ import {
|
|
|
16
31
|
workflowSetSignature,
|
|
17
32
|
writeOpenSpecConfigFile,
|
|
18
33
|
} from "@blackbelt-technology/pi-dashboard-shared/platform/openspec.js";
|
|
34
|
+
import { isPortableProjectName } from "@blackbelt-technology/pi-dashboard-shared/project-name.js";
|
|
35
|
+
import type { Semaphore } from "@blackbelt-technology/pi-dashboard-shared/semaphore.js";
|
|
36
|
+
import { inferPlatform, pathKey } from "@blackbelt-technology/pi-dashboard-shared/session-group-path.js";
|
|
19
37
|
import { getDefaultRegistry } from "@blackbelt-technology/pi-dashboard-shared/tool-registry/index.js";
|
|
20
38
|
import type { ApiResponse, OpenSpecConfig } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
21
|
-
import type { FastifyInstance } from "fastify";
|
|
39
|
+
import type { FastifyInstance, FastifyReply } from "fastify";
|
|
22
40
|
import { type DirectoryService, hasOpenSpecRoot } from "../directory-service.js";
|
|
41
|
+
import {
|
|
42
|
+
admitRouteCwd,
|
|
43
|
+
listKnownFolderCwds,
|
|
44
|
+
type RouteAdmissionDeps,
|
|
45
|
+
sendAdmissionUnavailable,
|
|
46
|
+
} from "../lib/route-admission.js";
|
|
47
|
+
import { readDeclared, writeDependenciesFile } from "../openspec/dependencies-file.js";
|
|
23
48
|
import { currentGlobalWorkflowSignature } from "../openspec/global-signature.js";
|
|
24
49
|
import { scanOpenSpecArchive } from "../openspec/openspec-archive.js";
|
|
25
50
|
import {
|
|
@@ -29,14 +54,164 @@ import {
|
|
|
29
54
|
readTasks,
|
|
30
55
|
toggleTask,
|
|
31
56
|
} from "../openspec/openspec-tasks.js";
|
|
57
|
+
import {
|
|
58
|
+
inspectSchema,
|
|
59
|
+
resolveDeps,
|
|
60
|
+
runWorkflowSchemaAction,
|
|
61
|
+
type WorkflowSchemaAction,
|
|
62
|
+
type WorkflowSchemaDeps,
|
|
63
|
+
type WorkflowSchemaRequest,
|
|
64
|
+
type WorkflowSchemaResult,
|
|
65
|
+
type WorkflowSchemaStamp,
|
|
66
|
+
writeGuard,
|
|
67
|
+
} from "../openspec/workflow-schema.js";
|
|
32
68
|
import type { PreferencesStore } from "../persistence/preferences-store.js";
|
|
69
|
+
import { type FolderCommandsResult, resolveFolderCommands } from "../pi/folder-commands.js";
|
|
33
70
|
import { isWithinFolder, joinSkillProvenance, type SkillReporter, sessionCommandRegistry } from "../pi/session-skill-registry.js";
|
|
71
|
+
import { safeRealpathSync } from "../resolve-path.js";
|
|
34
72
|
import type { SessionManager } from "../session/memory-session-manager.js";
|
|
35
73
|
import type { NetworkGuard } from "./route-deps.js";
|
|
36
74
|
|
|
37
75
|
/** Callback to broadcast an openspec_update after a successful toggle. */
|
|
38
76
|
export type OpenSpecBroadcaster = (cwd: string) => void;
|
|
39
77
|
|
|
78
|
+
/** The slice of `openspec.*` config the workflow-schema gates read (live, per request). */
|
|
79
|
+
export type OpenSpecGateConfig = Pick<OpenSpecPollConfig, "enabled" | "optOutDirectories" | "workflowSchema">;
|
|
80
|
+
|
|
81
|
+
const WORKFLOW_SCHEMA_ACTIONS: ReadonlySet<string> = new Set<WorkflowSchemaAction>([
|
|
82
|
+
"enable",
|
|
83
|
+
"disable",
|
|
84
|
+
"update",
|
|
85
|
+
"adopt",
|
|
86
|
+
"pin",
|
|
87
|
+
"remove",
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
// ── Legacy-artifact detection for the overwrite-confirm gate ──
|
|
91
|
+
// Coarse mirror of the pinned CLI's `legacy-cleanup.js`: `--tools` alone
|
|
92
|
+
// authorizes cleanup, and cleanup REMOVES marker blocks from root config
|
|
93
|
+
// files and DELETES legacy slash-command dirs/files without further
|
|
94
|
+
// prompting — so `<cwd>/openspec/` presence alone misses legacy projects
|
|
95
|
+
// (AGENTS.md markers + .claude/commands/openspec/, no openspec/ dir) that
|
|
96
|
+
// would be destructively edited on a plain Initialize. Markers + path list
|
|
97
|
+
// mirror @fission-ai/openspec@1.14.3 dist/core/legacy-cleanup.js; version
|
|
98
|
+
// drift degrades to fewer confirmations, never to a wrong refusal. See
|
|
99
|
+
// change: add-openspec-init-affordances (review round 1).
|
|
100
|
+
export const LEGACY_CONFIG_FILES = [
|
|
101
|
+
"CLAUDE.md", "CLINE.md", "CODEBUDDY.md", "COSTRICT.md",
|
|
102
|
+
"QODER.md", "IFLOW.md", "AGENTS.md", "QWEN.md",
|
|
103
|
+
];
|
|
104
|
+
const OPENSPEC_MARKER_START = "<!-- OPENSPEC:START -->";
|
|
105
|
+
const OPENSPEC_MARKER_END = "<!-- OPENSPEC:END -->";
|
|
106
|
+
export const LEGACY_COMMAND_DIRS = [
|
|
107
|
+
".claude/commands/openspec", ".codebuddy/commands/openspec",
|
|
108
|
+
".qoder/commands/openspec", ".lingma/commands/openspec",
|
|
109
|
+
".crush/commands/openspec", ".gemini/commands/openspec",
|
|
110
|
+
];
|
|
111
|
+
/**
|
|
112
|
+
* Filename prefixes that mark a file in a file-dir as legacy. Default is both; CoStrict's
|
|
113
|
+
* adapter writes LIVE `opsx-*.md` into its directory, and 1.14.3 only cleans `openspec-*.md`
|
|
114
|
+
* there, so an `opsx-` file alone must not force an overwrite confirmation.
|
|
115
|
+
*/
|
|
116
|
+
const LEGACY_FILE_PREFIXES: Record<string, string[]> = {
|
|
117
|
+
".cospec/openspec/commands": ["openspec-"],
|
|
118
|
+
};
|
|
119
|
+
export const LEGACY_COMMAND_FILE_DIRS = [
|
|
120
|
+
".cursor/commands", ".windsurf/workflows", ".kilocode/workflows",
|
|
121
|
+
".kiro/prompts", ".github/prompts", ".amazonq/prompts",
|
|
122
|
+
".clinerules/workflows", ".roo/commands", ".augment/commands",
|
|
123
|
+
".factory/commands", ".continue/prompts", ".agent/workflows",
|
|
124
|
+
".iflow/commands", ".qwen/commands", ".codex/prompts",
|
|
125
|
+
// opencode + junie are the only `opsx-*` producers — without these two
|
|
126
|
+
// entries the opsx- prefix check below is dead code (review round 2).
|
|
127
|
+
".opencode/command", ".junie/commands",
|
|
128
|
+
// 1.14.3 scopes CoStrict cleanup to `openspec-*.md` files (a directory entry
|
|
129
|
+
// would delete the live `opsx-*.md` commands), so it is a file dir here too.
|
|
130
|
+
".cospec/openspec/commands",
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
/** `realpathSync.native(cwd)`, or `cwd` itself when it does not resolve (lock key only). */
|
|
134
|
+
function canonicalPath(cwd: string): string {
|
|
135
|
+
try {
|
|
136
|
+
return realpathSync.native(cwd);
|
|
137
|
+
} catch {
|
|
138
|
+
return cwd;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Opt-out by exact `pathKey`, on the request spelling AND the canonical cwd (a symlink spelling cannot slip past). */
|
|
143
|
+
function isOptedOut(cwd: string, canonCwd: string, optOutDirectories: readonly string[]): boolean {
|
|
144
|
+
if (optOutDirectories.length === 0) return false;
|
|
145
|
+
const platform = inferPlatform([cwd, canonCwd, ...optOutDirectories]);
|
|
146
|
+
const keys = new Set(optOutDirectories.flatMap((d) => [pathKey(d, platform), pathKey(safeRealpathSync(d), platform)]));
|
|
147
|
+
return keys.has(pathKey(cwd, platform)) || keys.has(pathKey(canonCwd, platform));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
type OpenSpecAdmission =
|
|
151
|
+
| { kind: "ok"; cwd: string; canonCwd: string }
|
|
152
|
+
| { kind: "refused" }
|
|
153
|
+
| { kind: "unavailable"; body: unknown };
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Core cwd admission for the openspec routes (change: core-cwd-admission, D1/D4):
|
|
157
|
+
* `admitRouteCwd`, then the branch on `admissionAllows(admission, cwd)` right here, on the
|
|
158
|
+
* UNMODIFIED request value, so static analysis keeps its modelled barrier. The helpers hand back
|
|
159
|
+
* that guarded raw `cwd` (openspec signatures, broadcasts and opt-out keys stay raw) and the
|
|
160
|
+
* canonical cwd for the symlink-proof comparisons. The token is released when the response
|
|
161
|
+
* closes (success, error, throw or disconnect).
|
|
162
|
+
*/
|
|
163
|
+
export function createOpenSpecAdmission(routeAdmission: RouteAdmissionDeps, globalOpenSpecDir: string) {
|
|
164
|
+
/** Whether `cwd` (raw or canonical) is the directory whose `openspec/` is the global OpenSpec config dir. */
|
|
165
|
+
function isGlobalOpenSpecParent(cwd: string, canonCwd: string): boolean {
|
|
166
|
+
const canonGlobal = path.join(safeRealpathSync(path.dirname(globalOpenSpecDir)), path.basename(globalOpenSpecDir));
|
|
167
|
+
return (
|
|
168
|
+
path.join(cwd, "openspec") === globalOpenSpecDir ||
|
|
169
|
+
path.join(canonCwd, "openspec") === globalOpenSpecDir ||
|
|
170
|
+
path.join(canonCwd, "openspec") === canonGlobal
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Admit `raw`. `refused` leaves the reply untouched (the caller answers); `unavailable` has set the 503. */
|
|
175
|
+
async function admitOpenSpecCwd(raw: string, reply: FastifyReply): Promise<OpenSpecAdmission> {
|
|
176
|
+
const admission = await admitRouteCwd(raw, routeAdmission);
|
|
177
|
+
if (admission.kind === "indeterminate") return { kind: "unavailable", body: sendAdmissionUnavailable(reply) };
|
|
178
|
+
if (admission.kind !== "admit" || !admissionAllows(admission, raw)) return { kind: "refused" };
|
|
179
|
+
const token = admission.token;
|
|
180
|
+
reply.raw.once("close", () => releaseAdmission(token));
|
|
181
|
+
// The client may have gone while admission ran (`close` already fired): release at once.
|
|
182
|
+
if (reply.raw.destroyed) releaseAdmission(token);
|
|
183
|
+
return { kind: "ok", cwd: raw, canonCwd: token.canonCwd };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Admission for a site that did NOT refuse unknown cwds before this change: not admitted, or the
|
|
188
|
+
* global OpenSpec config dir → 403 `cwd_unknown` (design D4).
|
|
189
|
+
*/
|
|
190
|
+
async function admitUngatedCwd(
|
|
191
|
+
raw: string,
|
|
192
|
+
reply: FastifyReply,
|
|
193
|
+
): Promise<{ ok: true; cwd: string } | { ok: false; body: unknown }> {
|
|
194
|
+
const adm = await admitOpenSpecCwd(raw, reply);
|
|
195
|
+
if (adm.kind === "unavailable") return { ok: false, body: adm.body };
|
|
196
|
+
if (adm.kind === "refused" || isGlobalOpenSpecParent(raw, adm.canonCwd)) {
|
|
197
|
+
reply.code(403);
|
|
198
|
+
return {
|
|
199
|
+
ok: false,
|
|
200
|
+
body: {
|
|
201
|
+
success: false,
|
|
202
|
+
code: "cwd_unknown",
|
|
203
|
+
error: "cwd not allowed",
|
|
204
|
+
reason: "cwd is not a known session or pinned directory.",
|
|
205
|
+
hint: "Pin this directory to allow it, or open a session rooted in it.",
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return { ok: true, cwd: adm.cwd };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return { admitOpenSpecCwd, admitUngatedCwd, isGlobalOpenSpecParent };
|
|
213
|
+
}
|
|
214
|
+
|
|
40
215
|
export function registerOpenSpecRoutes(
|
|
41
216
|
fastify: FastifyInstance,
|
|
42
217
|
deps: {
|
|
@@ -44,11 +219,32 @@ export function registerOpenSpecRoutes(
|
|
|
44
219
|
preferencesStore: PreferencesStore;
|
|
45
220
|
directoryService: DirectoryService;
|
|
46
221
|
networkGuard: NetworkGuard;
|
|
222
|
+
/**
|
|
223
|
+
* Bridge-connection probe for `GET /api/pi-resources/commands`. A session's
|
|
224
|
+
* registry entry or status alone is not "live": a crashed pi never
|
|
225
|
+
* unregisters. Absent → no session counts as live (scan only).
|
|
226
|
+
*/
|
|
227
|
+
piGateway?: { isSessionConnected(sessionId: string): boolean };
|
|
47
228
|
/** Optional — called after a successful toggle to trigger openspec_update. */
|
|
48
229
|
onOpenSpecChanged?: OpenSpecBroadcaster;
|
|
230
|
+
/** Live `openspec.*` config (gates + `workflowSchema.defaultForNewProjects`). Absent → defaults (enabled, no opt-outs, default off). */
|
|
231
|
+
getOpenSpecConfig?: () => OpenSpecGateConfig;
|
|
232
|
+
/** Spawn semaphore for the workflow-schema `newer`/`conflict` validate. Absent → pass-through. */
|
|
233
|
+
spawnSemaphore?: Semaphore;
|
|
234
|
+
/** Test seam: overrides for the workflow-schema module's collaborators (CLI, fs, clock…). */
|
|
235
|
+
workflowSchemaDeps?: Partial<WorkflowSchemaDeps>;
|
|
236
|
+
/**
|
|
237
|
+
* Live known-folder set (session cwds ∪ pinned directories, unfiltered) every caller-supplied
|
|
238
|
+
* `cwd` is admitted against. Absent → the same set from `sessionManager` + `preferencesStore`.
|
|
239
|
+
* See change: core-cwd-admission.
|
|
240
|
+
*/
|
|
241
|
+
knownFolderCwds?: () => string[];
|
|
242
|
+
/** `admitCwd` options: the host's throttled `onIndeterminate` logger + test seams. */
|
|
243
|
+
admitOptions?: AdmitCwdOptions;
|
|
49
244
|
},
|
|
50
245
|
) {
|
|
51
|
-
const { sessionManager, preferencesStore, directoryService, networkGuard, onOpenSpecChanged } = deps;
|
|
246
|
+
const { sessionManager, preferencesStore, directoryService, networkGuard, onOpenSpecChanged, piGateway } = deps;
|
|
247
|
+
const gateConfig = (): OpenSpecGateConfig => deps.getOpenSpecConfig?.() ?? DEFAULT_OPENSPEC_POLL;
|
|
52
248
|
|
|
53
249
|
// OpenSpec workflow config endpoint — returns the user's enabled
|
|
54
250
|
// workflow commands so the client can render only the buttons /
|
|
@@ -65,7 +261,9 @@ export function registerOpenSpecRoutes(
|
|
|
65
261
|
// omitted, run `openspec config list` in any known project (or process
|
|
66
262
|
// cwd) so the Settings section can read the global config without a cwd.
|
|
67
263
|
// See change: add-openspec-profile-settings.
|
|
68
|
-
const
|
|
264
|
+
const resolved = await resolveConfigCwd(request.query.cwd, reply);
|
|
265
|
+
if (!resolved.ok) return resolved.body;
|
|
266
|
+
const cwd = resolved.cwd;
|
|
69
267
|
const now = Date.now();
|
|
70
268
|
const cached = configCache.get(cwd);
|
|
71
269
|
if (cached && now - cached.ts < CONFIG_TTL_MS) {
|
|
@@ -116,6 +314,33 @@ export function registerOpenSpecRoutes(
|
|
|
116
314
|
// See change: add-openspec-profile-settings.
|
|
117
315
|
const GLOBAL_OPENSPEC_DIR = path.dirname(openSpecConfigFilePath()); // ~/.config/openspec
|
|
118
316
|
|
|
317
|
+
// Core cwd admission (change: core-cwd-admission, D1/D4): see `createOpenSpecAdmission`.
|
|
318
|
+
const { admitOpenSpecCwd, admitUngatedCwd, isGlobalOpenSpecParent } = createOpenSpecAdmission(
|
|
319
|
+
{
|
|
320
|
+
knownCwds: deps.knownFolderCwds ?? (() => listKnownFolderCwds({ sessionManager, preferencesStore })),
|
|
321
|
+
admitOptions: deps.admitOptions,
|
|
322
|
+
},
|
|
323
|
+
GLOBAL_OPENSPEC_DIR,
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* The cwd of the global-config routes: a caller-supplied cwd is admitted; with none, the
|
|
328
|
+
* server-chosen fallback (`knownCwds()[0] ?? process.cwd()`) is kept and not re-admitted.
|
|
329
|
+
*/
|
|
330
|
+
async function resolveConfigCwd(
|
|
331
|
+
requested: unknown,
|
|
332
|
+
reply: FastifyReply,
|
|
333
|
+
): Promise<{ ok: true; cwd: string } | { ok: false; body: unknown }> {
|
|
334
|
+
if (typeof requested === "string" && requested.length > 0) return admitUngatedCwd(requested, reply);
|
|
335
|
+
return { ok: true, cwd: knownCwds()[0] ?? process.cwd() };
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** A request path segment (a change name) joined under the cwd by a lib: a single portable segment only. */
|
|
339
|
+
const invalidName = (reply: FastifyReply) => {
|
|
340
|
+
reply.code(400);
|
|
341
|
+
return { success: false, code: "invalid_name", error: "invalid change name" };
|
|
342
|
+
};
|
|
343
|
+
|
|
119
344
|
// True when `workflows` is exactly the EXPANDED_WORKFLOWS set (order-agnostic).
|
|
120
345
|
// Used to re-surface a custom-persisted expanded profile as the "expanded"
|
|
121
346
|
// alias on read. See change: fix-openspec-expanded-profile-update.
|
|
@@ -185,7 +410,9 @@ export function registerOpenSpecRoutes(
|
|
|
185
410
|
return { success: false, error: "invalid profile" } satisfies ApiResponse;
|
|
186
411
|
}
|
|
187
412
|
// cwd is only needed for the `core` preset invocation (CLI runs in a dir).
|
|
188
|
-
const
|
|
413
|
+
const resolved = await resolveConfigCwd(body.cwd, reply);
|
|
414
|
+
if (!resolved.ok) return resolved.body;
|
|
415
|
+
const cwd = resolved.cwd;
|
|
189
416
|
|
|
190
417
|
if (profile === "core") {
|
|
191
418
|
const res = configProfile({ cwd, preset: "core" });
|
|
@@ -224,7 +451,16 @@ export function registerOpenSpecRoutes(
|
|
|
224
451
|
{ preHandler: networkGuard },
|
|
225
452
|
async (request, reply) => {
|
|
226
453
|
const body = request.body ?? {};
|
|
227
|
-
|
|
454
|
+
let targets: string[];
|
|
455
|
+
if (body.all) {
|
|
456
|
+
targets = knownCwds(); // server-chosen list: not re-admitted
|
|
457
|
+
} else if (typeof body.cwd === "string" && body.cwd.length > 0) {
|
|
458
|
+
const admitted = await admitUngatedCwd(body.cwd, reply);
|
|
459
|
+
if (!admitted.ok) return admitted.body;
|
|
460
|
+
targets = [admitted.cwd];
|
|
461
|
+
} else {
|
|
462
|
+
targets = [];
|
|
463
|
+
}
|
|
228
464
|
if (targets.length === 0) {
|
|
229
465
|
reply.code(400);
|
|
230
466
|
return { success: false, error: "cwd or all required" } satisfies ApiResponse;
|
|
@@ -268,39 +504,6 @@ export function registerOpenSpecRoutes(
|
|
|
268
504
|
// (review round 1). See change: add-openspec-init-affordances.
|
|
269
505
|
let initSupportProbe: Promise<boolean> | undefined;
|
|
270
506
|
|
|
271
|
-
// ── Legacy-artifact detection for the overwrite-confirm gate ──
|
|
272
|
-
// Coarse mirror of the pinned CLI's `legacy-cleanup.js`: `--tools` alone
|
|
273
|
-
// authorizes cleanup, and cleanup REMOVES marker blocks from root config
|
|
274
|
-
// files and DELETES legacy slash-command dirs/files without further
|
|
275
|
-
// prompting — so `<cwd>/openspec/` presence alone misses legacy projects
|
|
276
|
-
// (AGENTS.md markers + .claude/commands/openspec/, no openspec/ dir) that
|
|
277
|
-
// would be destructively edited on a plain Initialize. Markers + path list
|
|
278
|
-
// mirror @fission-ai/openspec@1.6.0 dist/core/legacy-cleanup.js; version
|
|
279
|
-
// drift degrades to fewer confirmations, never to a wrong refusal. See
|
|
280
|
-
// change: add-openspec-init-affordances (review round 1).
|
|
281
|
-
const LEGACY_CONFIG_FILES = [
|
|
282
|
-
"CLAUDE.md", "CLINE.md", "CODEBUDDY.md", "COSTRICT.md",
|
|
283
|
-
"QODER.md", "IFLOW.md", "AGENTS.md", "QWEN.md",
|
|
284
|
-
];
|
|
285
|
-
const OPENSPEC_MARKER_START = "<!-- OPENSPEC:START -->";
|
|
286
|
-
const OPENSPEC_MARKER_END = "<!-- OPENSPEC:END -->";
|
|
287
|
-
const LEGACY_COMMAND_DIRS = [
|
|
288
|
-
".claude/commands/openspec", ".codebuddy/commands/openspec",
|
|
289
|
-
".qoder/commands/openspec", ".lingma/commands/openspec",
|
|
290
|
-
".crush/commands/openspec", ".gemini/commands/openspec",
|
|
291
|
-
".cospec/openspec/commands",
|
|
292
|
-
];
|
|
293
|
-
const LEGACY_COMMAND_FILE_DIRS = [
|
|
294
|
-
".cursor/commands", ".windsurf/workflows", ".kilocode/workflows",
|
|
295
|
-
".kiro/prompts", ".github/prompts", ".amazonq/prompts",
|
|
296
|
-
".clinerules/workflows", ".roo/commands", ".augment/commands",
|
|
297
|
-
".factory/commands", ".continue/prompts", ".agent/workflows",
|
|
298
|
-
".iflow/commands", ".qwen/commands", ".codex/prompts",
|
|
299
|
-
// opencode + junie are the only `opsx-*` producers — without these two
|
|
300
|
-
// entries the opsx- prefix check below is dead code (review round 2).
|
|
301
|
-
".opencode/command", ".junie/commands",
|
|
302
|
-
];
|
|
303
|
-
|
|
304
507
|
async function hasLegacyOpenSpecArtifacts(cwd: string): Promise<boolean> {
|
|
305
508
|
for (const f of LEGACY_CONFIG_FILES) {
|
|
306
509
|
try {
|
|
@@ -317,7 +520,8 @@ export function registerOpenSpecRoutes(
|
|
|
317
520
|
for (const dir of LEGACY_COMMAND_FILE_DIRS) {
|
|
318
521
|
try {
|
|
319
522
|
const entries = await fs.readdir(path.join(cwd, dir));
|
|
320
|
-
|
|
523
|
+
const prefixes = LEGACY_FILE_PREFIXES[dir] ?? ["openspec-", "opsx-"];
|
|
524
|
+
if (entries.some((e) => prefixes.some((p) => e.startsWith(p)))) return true;
|
|
321
525
|
} catch { /* absent */ }
|
|
322
526
|
}
|
|
323
527
|
return false;
|
|
@@ -326,21 +530,325 @@ export function registerOpenSpecRoutes(
|
|
|
326
530
|
// Per-cwd serialization (X4): while an invocation is in flight for a cwd,
|
|
327
531
|
// a second request is rejected 409 without spawning. The lock is released
|
|
328
532
|
// on every exit path, including the 60s timeout (X3).
|
|
533
|
+
// Keyed by `realpathSync.native(cwd)`; shared with POST /api/openspec/workflow-schema.
|
|
329
534
|
const inFlightInits = new Set<string>();
|
|
330
535
|
|
|
536
|
+
/** Stamp of the managed schema dir, or null (no/unreadable/unmanaged). */
|
|
537
|
+
async function readSchemaStamp(root: string): Promise<WorkflowSchemaStamp | null> {
|
|
538
|
+
try {
|
|
539
|
+
return (await inspectSchema(root, { localVersion: "" })).stamp;
|
|
540
|
+
} catch {
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* One workflow-schema action with the real spawn semaphore, the forced
|
|
547
|
+
* refresh (skipped when the caller refreshes right after), and the
|
|
548
|
+
* structured log line. The caller holds the per-cwd lock.
|
|
549
|
+
*/
|
|
550
|
+
async function runLoggedWorkflowAction(
|
|
551
|
+
log: { info(obj: object, msg: string): void },
|
|
552
|
+
cwd: string,
|
|
553
|
+
root: string,
|
|
554
|
+
req: WorkflowSchemaRequest,
|
|
555
|
+
refresh: boolean,
|
|
556
|
+
): Promise<WorkflowSchemaResult> {
|
|
557
|
+
const stampBefore = await readSchemaStamp(root);
|
|
558
|
+
const result = await runWorkflowSchemaAction(req, {
|
|
559
|
+
...(deps.spawnSemaphore ? { semaphore: deps.spawnSemaphore } : {}),
|
|
560
|
+
refresh: refresh
|
|
561
|
+
? async (c) => {
|
|
562
|
+
await directoryService.refreshOpenSpec(c);
|
|
563
|
+
onOpenSpecChanged?.(c);
|
|
564
|
+
}
|
|
565
|
+
: async () => undefined,
|
|
566
|
+
...deps.workflowSchemaDeps,
|
|
567
|
+
});
|
|
568
|
+
const stampAfter = await readSchemaStamp(root);
|
|
569
|
+
log.info(
|
|
570
|
+
{ event: "openspec.workflow-schema", cwd, action: req.action, ok: result.ok, written: result.written, stampBefore, stampAfter },
|
|
571
|
+
"openspec workflow-schema action",
|
|
572
|
+
);
|
|
573
|
+
return result;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// POST /api/openspec/workflow-schema — enable|disable|update|adopt|pin|remove
|
|
577
|
+
// the dashboard-managed `pi-spec-driven` schema for one project.
|
|
578
|
+
// Gate order: shape → tracked-or-pinned (membership, NO fs) → OpenSpec
|
|
579
|
+
// enabled → not opted out → fs (realpath + `<cwd>/openspec/`) → per-cwd lock.
|
|
580
|
+
// The allowed-state table + all name/containment checks live in
|
|
581
|
+
// `runWorkflowSchemaAction`. See change: add-pi-spec-driven-schema.
|
|
582
|
+
fastify.post<{ Body: Partial<Record<keyof WorkflowSchemaRequest, unknown>> }>(
|
|
583
|
+
"/api/openspec/workflow-schema",
|
|
584
|
+
{ preHandler: networkGuard },
|
|
585
|
+
async (request, reply) => {
|
|
586
|
+
const b = request.body ?? {};
|
|
587
|
+
const fail = (code: number, error: string, errCode?: string) => {
|
|
588
|
+
reply.code(code);
|
|
589
|
+
return { success: false, error, ...(errCode ? { code: errCode } : {}) } satisfies ApiResponse & { code?: string };
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
if (typeof b.cwd !== "string" || !b.cwd) return fail(400, "cwd required");
|
|
593
|
+
if (typeof b.action !== "string" || !WORKFLOW_SCHEMA_ACTIONS.has(b.action)) {
|
|
594
|
+
return fail(400, "action must be one of enable, disable, update, adopt, pin, remove");
|
|
595
|
+
}
|
|
596
|
+
if (b.confirm !== undefined && typeof b.confirm !== "boolean") return fail(400, "confirm must be a boolean");
|
|
597
|
+
if (b.pinTo !== undefined && typeof b.pinTo !== "string") return fail(400, "pinTo must be a string");
|
|
598
|
+
if (b.previousDefault !== undefined && typeof b.previousDefault !== "string") {
|
|
599
|
+
return fail(400, "previousDefault must be a string");
|
|
600
|
+
}
|
|
601
|
+
if (b.changes !== undefined && !(Array.isArray(b.changes) && b.changes.every((c) => typeof c === "string"))) {
|
|
602
|
+
return fail(400, "changes must be an array of strings");
|
|
603
|
+
}
|
|
604
|
+
// Admission first (the modelled guard; indeterminate → 503), then the EXISTING exact
|
|
605
|
+
// membership / opt-out / global-dir gates with their existing refusals — no widening.
|
|
606
|
+
const adm = await admitOpenSpecCwd(b.cwd, reply);
|
|
607
|
+
if (adm.kind === "unavailable") return adm.body;
|
|
608
|
+
if (adm.kind === "refused" || !knownInitTargets().includes(adm.cwd) || isGlobalOpenSpecParent(adm.cwd, adm.canonCwd)) {
|
|
609
|
+
return fail(400, "cwd is not a known session or pinned directory", "untracked");
|
|
610
|
+
}
|
|
611
|
+
const cwd = adm.cwd;
|
|
612
|
+
const cfg = gateConfig();
|
|
613
|
+
if (cfg.enabled === false) return fail(400, "OpenSpec is disabled", "openspec_disabled");
|
|
614
|
+
if (isOptedOut(cwd, adm.canonCwd, cfg.optOutDirectories)) {
|
|
615
|
+
return fail(400, "OpenSpec is opted out for this directory", "opted_out");
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// Only now touch the filesystem.
|
|
619
|
+
let real: string;
|
|
620
|
+
try {
|
|
621
|
+
real = realpathSync.native(cwd);
|
|
622
|
+
} catch {
|
|
623
|
+
return fail(400, "cwd does not exist", "no_openspec");
|
|
624
|
+
}
|
|
625
|
+
const hasOpenspec = await fs
|
|
626
|
+
.stat(path.join(real, "openspec"))
|
|
627
|
+
.then((st) => st.isDirectory())
|
|
628
|
+
.catch(() => false);
|
|
629
|
+
if (!hasOpenspec) return fail(400, "no openspec/ directory in cwd", "no_openspec");
|
|
630
|
+
|
|
631
|
+
if (inFlightInits.has(real)) return fail(409, "an OpenSpec init or workflow-schema action is already in flight for this directory");
|
|
632
|
+
inFlightInits.add(real);
|
|
633
|
+
try {
|
|
634
|
+
const req: WorkflowSchemaRequest = {
|
|
635
|
+
cwd,
|
|
636
|
+
action: b.action as WorkflowSchemaAction,
|
|
637
|
+
...(b.confirm !== undefined ? { confirm: b.confirm as boolean } : {}),
|
|
638
|
+
...(b.pinTo !== undefined ? { pinTo: b.pinTo as string } : {}),
|
|
639
|
+
...(b.changes !== undefined ? { changes: b.changes as string[] } : {}),
|
|
640
|
+
...(b.previousDefault !== undefined ? { previousDefault: b.previousDefault as string } : {}),
|
|
641
|
+
};
|
|
642
|
+
const result = await runLoggedWorkflowAction(request.log, cwd, real, req, true);
|
|
643
|
+
if (result.ok) return { success: true, data: result } satisfies ApiResponse;
|
|
644
|
+
// Refusals (state table, validation, guard) carry the current status in `data`.
|
|
645
|
+
reply.code(result.partial ? 500 : 422);
|
|
646
|
+
return { success: false, error: result.error ?? "workflow-schema action failed", data: result } satisfies ApiResponse;
|
|
647
|
+
} finally {
|
|
648
|
+
inFlightInits.delete(real);
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
// ── Change dependencies (add-openspec-change-dependencies) ───────────
|
|
654
|
+
//
|
|
655
|
+
// GET/PUT /api/openspec/dependencies?cwd=&change= — one change's
|
|
656
|
+
// `dependencies.yaml`. Gate order (answers carry `reason`): request shape →
|
|
657
|
+
// tracked → enabled → not opted out → `openspec/` exists → not on the
|
|
658
|
+
// fallback path → a cached `status --all` result → change in that result.
|
|
659
|
+
// PUT then: write guard + containment → per-cwd lock → `expected` precondition
|
|
660
|
+
// → atomic write.
|
|
661
|
+
type DepGate = { ok: true; cwd: string; real: string; change: string } | { ok: false };
|
|
662
|
+
|
|
663
|
+
const depFail = (reply: import("fastify").FastifyReply, code: number, reason: string, error: string) => {
|
|
664
|
+
reply.code(code);
|
|
665
|
+
return { success: false, error, reason } satisfies ApiResponse & { reason: string };
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
/** Gates 2–8 of the dependencies endpoints (gate 1, request validity, runs before). */
|
|
669
|
+
async function depGates(requestCwd: string, change: string, reply: import("fastify").FastifyReply): Promise<DepGate | { ok: false; body: unknown }> {
|
|
670
|
+
const respond = (code: number, reason: string, error: string) => ({ ok: false as const, body: depFail(reply, code, reason, error) });
|
|
671
|
+
// Admission is the modelled guard (indeterminate → 503); the exact membership / opt-out
|
|
672
|
+
// gates and their refusals are unchanged. The gate hands back the guarded raw cwd.
|
|
673
|
+
const adm = await admitOpenSpecCwd(requestCwd, reply);
|
|
674
|
+
if (adm.kind === "unavailable") return { ok: false, body: adm.body };
|
|
675
|
+
if (adm.kind === "refused" || !knownInitTargets().includes(adm.cwd) || isGlobalOpenSpecParent(adm.cwd, adm.canonCwd)) {
|
|
676
|
+
return respond(403, "cwd-not-tracked", "cwd is not a known session or pinned directory");
|
|
677
|
+
}
|
|
678
|
+
const cwd = adm.cwd;
|
|
679
|
+
const cfg = gateConfig();
|
|
680
|
+
if (cfg.enabled === false) return respond(403, "openspec-disabled", "OpenSpec is disabled");
|
|
681
|
+
if (isOptedOut(cwd, adm.canonCwd, cfg.optOutDirectories)) {
|
|
682
|
+
return respond(403, "opted-out", "OpenSpec is opted out for this directory");
|
|
683
|
+
}
|
|
684
|
+
let real: string;
|
|
685
|
+
try {
|
|
686
|
+
real = realpathSync.native(cwd);
|
|
687
|
+
} catch {
|
|
688
|
+
return respond(404, "no-openspec-dir", "cwd does not exist");
|
|
689
|
+
}
|
|
690
|
+
const hasOpenspec = await fs
|
|
691
|
+
.stat(path.join(real, "openspec"))
|
|
692
|
+
.then((st) => st.isDirectory())
|
|
693
|
+
.catch(() => false);
|
|
694
|
+
if (!hasOpenspec) return respond(404, "no-openspec-dir", "no openspec/ directory in cwd");
|
|
695
|
+
if (directoryService.getOpenSpecPollMode(cwd) === "fallback") {
|
|
696
|
+
return respond(409, "status-all-unsupported", "this OpenSpec CLI has no `status --all`; dependencies are not computed");
|
|
697
|
+
}
|
|
698
|
+
const data = directoryService.getOpenSpecData(cwd);
|
|
699
|
+
if (!data || !data.initialized || directoryService.getOpenSpecPollMode(cwd) !== "all") {
|
|
700
|
+
return respond(503, "pending", "no OpenSpec status result is cached for this directory yet");
|
|
701
|
+
}
|
|
702
|
+
if (!data.changes.some((c) => c.name === change)) return respond(404, "unknown-change", `no active change named ${change}`);
|
|
703
|
+
return { ok: true, cwd, real, change };
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
fastify.get<{ Querystring: { cwd?: string; change?: string } }>(
|
|
707
|
+
"/api/openspec/dependencies",
|
|
708
|
+
{ preHandler: networkGuard },
|
|
709
|
+
async (request, reply) => {
|
|
710
|
+
const { cwd, change } = request.query ?? {};
|
|
711
|
+
if (typeof cwd !== "string" || !cwd || typeof change !== "string" || !KEBAB_ID_REGEX.test(change) || !isPortableProjectName(change)) {
|
|
712
|
+
return depFail(reply, 400, "invalid-request", "cwd and a valid change name are required");
|
|
713
|
+
}
|
|
714
|
+
const gate = await depGates(cwd, change, reply);
|
|
715
|
+
if (!gate.ok) return "body" in gate ? gate.body : undefined;
|
|
716
|
+
const entry = directoryService.getOpenSpecData(gate.cwd)?.changes.find((c) => c.name === change);
|
|
717
|
+
const read = await readDeclared(gate.real, change);
|
|
718
|
+
return {
|
|
719
|
+
success: true,
|
|
720
|
+
data: {
|
|
721
|
+
dependencies: entry?.dependencies ?? null,
|
|
722
|
+
declared: read.declared,
|
|
723
|
+
declaredError: read.declaredError,
|
|
724
|
+
file: read.file,
|
|
725
|
+
},
|
|
726
|
+
} satisfies ApiResponse;
|
|
727
|
+
},
|
|
728
|
+
);
|
|
729
|
+
|
|
730
|
+
/** Whole-body validation of the PUT (gate 1). Returns the parsed declaration or an error message. */
|
|
731
|
+
function parseDependenciesPut(
|
|
732
|
+
body: unknown,
|
|
733
|
+
): { ok: true; cwd: string; change: string; declared: DeclaredDependencies; expected: FileStat | null } | { ok: false; error: string } {
|
|
734
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return { ok: false, error: "JSON object body required" };
|
|
735
|
+
if (Buffer.byteLength(JSON.stringify(body), "utf8") > MAX_DEPENDENCIES_BYTES) return { ok: false, error: "body exceeds 64 KiB" };
|
|
736
|
+
const b = body as Record<string, unknown>;
|
|
737
|
+
if (typeof b.cwd !== "string" || !b.cwd) return { ok: false, error: "cwd required" };
|
|
738
|
+
if (typeof b.change !== "string" || !KEBAB_ID_REGEX.test(b.change) || !isPortableProjectName(b.change)) return { ok: false, error: "change must be a valid change name" };
|
|
739
|
+
const change = b.change;
|
|
740
|
+
const names = (v: unknown, key: string): string[] | string => {
|
|
741
|
+
if (!Array.isArray(v)) return `${key} must be a list`;
|
|
742
|
+
const out: string[] = [];
|
|
743
|
+
for (const n of v) {
|
|
744
|
+
if (typeof n !== "string" || !KEBAB_ID_REGEX.test(n)) return `${key} has an invalid change name`;
|
|
745
|
+
if (n === change) return `${key} must not name the change itself`;
|
|
746
|
+
if (!out.includes(n)) out.push(n);
|
|
747
|
+
}
|
|
748
|
+
return out;
|
|
749
|
+
};
|
|
750
|
+
if (!Array.isArray(b.blockedBy)) return { ok: false, error: "blockedBy must be a list" };
|
|
751
|
+
const blockedBy: DeclaredDependencies["blockedBy"] = [];
|
|
752
|
+
for (const item of b.blockedBy) {
|
|
753
|
+
const rec = typeof item === "string" ? { change: item } : (item as { change?: unknown; reason?: unknown } | null);
|
|
754
|
+
if (!rec || typeof rec !== "object" || typeof rec.change !== "string" || !KEBAB_ID_REGEX.test(rec.change)) {
|
|
755
|
+
return { ok: false, error: "blockedBy has an invalid change name" };
|
|
756
|
+
}
|
|
757
|
+
if (rec.change === change) return { ok: false, error: "blockedBy must not name the change itself" };
|
|
758
|
+
const reason = (rec as { reason?: unknown }).reason;
|
|
759
|
+
if (reason !== undefined && reason !== null && (typeof reason !== "string" || reason.length > MAX_REASON_CHARS)) {
|
|
760
|
+
return { ok: false, error: `reason must be a string of at most ${MAX_REASON_CHARS} characters` };
|
|
761
|
+
}
|
|
762
|
+
if (blockedBy.some((x) => x.change === rec.change)) continue;
|
|
763
|
+
blockedBy.push(typeof reason === "string" && reason !== "" ? { change: rec.change, reason } : { change: rec.change });
|
|
764
|
+
}
|
|
765
|
+
const notBlockedBy = names(b.notBlockedBy, "notBlockedBy");
|
|
766
|
+
if (typeof notBlockedBy === "string") return { ok: false, error: notBlockedBy };
|
|
767
|
+
const related = names(b.related, "related");
|
|
768
|
+
if (typeof related === "string") return { ok: false, error: related };
|
|
769
|
+
if (!("expected" in b)) return { ok: false, error: "expected is required (null or { mtimeMs, size })" };
|
|
770
|
+
let expected: FileStat | null = null;
|
|
771
|
+
if (b.expected !== null) {
|
|
772
|
+
const e = b.expected as { mtimeMs?: unknown; size?: unknown };
|
|
773
|
+
if (!e || typeof e !== "object" || typeof e.mtimeMs !== "number" || typeof e.size !== "number") {
|
|
774
|
+
return { ok: false, error: "expected must be null or { mtimeMs, size }" };
|
|
775
|
+
}
|
|
776
|
+
expected = { mtimeMs: e.mtimeMs, size: e.size };
|
|
777
|
+
}
|
|
778
|
+
return { ok: true, cwd: b.cwd, change, declared: { blockedBy, notBlockedBy, related }, expected };
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
fastify.put<{ Body: unknown }>(
|
|
782
|
+
"/api/openspec/dependencies",
|
|
783
|
+
{ preHandler: networkGuard },
|
|
784
|
+
async (request, reply) => {
|
|
785
|
+
const parsed = parseDependenciesPut(request.body);
|
|
786
|
+
if (!parsed.ok) return depFail(reply, 400, "invalid-request", parsed.error);
|
|
787
|
+
const { change, declared, expected } = parsed;
|
|
788
|
+
const gate = await depGates(parsed.cwd, change, reply);
|
|
789
|
+
if (!gate.ok) return "body" in gate ? gate.body : undefined;
|
|
790
|
+
const cwd = gate.cwd; // the admission-bound request value
|
|
791
|
+
|
|
792
|
+
// Same root verification as every workflow-schema write.
|
|
793
|
+
// The guard spawns `status --all`; bound it by the shared spawn semaphore like every other CLI spawn.
|
|
794
|
+
const guard = () => writeGuard(cwd, resolveDeps(deps.workflowSchemaDeps));
|
|
795
|
+
const guarded = await (deps.spawnSemaphore ? deps.spawnSemaphore.run(guard) : guard());
|
|
796
|
+
if ("error" in guarded) return depFail(reply, 403, "write-refused", guarded.error);
|
|
797
|
+
|
|
798
|
+
// Shared per-cwd lock (keyed by the canonical cwd, so symlinked spellings collide).
|
|
799
|
+
const lockKey = gate.real; // canonical cwd from the gates; never re-resolved after they answered
|
|
800
|
+
if (inFlightInits.has(lockKey)) {
|
|
801
|
+
return depFail(reply, 409, "locked", "an OpenSpec init or workflow-schema action is already in flight for this directory");
|
|
802
|
+
}
|
|
803
|
+
inFlightInits.add(lockKey);
|
|
804
|
+
try {
|
|
805
|
+
const out = await writeDependenciesFile({
|
|
806
|
+
root: guarded.root,
|
|
807
|
+
change,
|
|
808
|
+
content: serializeDependencies(declared),
|
|
809
|
+
expected,
|
|
810
|
+
});
|
|
811
|
+
if (!out.ok) return depFail(reply, out.status, out.reason, out.error);
|
|
812
|
+
request.log.info(
|
|
813
|
+
{
|
|
814
|
+
event: "openspec.dependencies",
|
|
815
|
+
cwd,
|
|
816
|
+
change,
|
|
817
|
+
blockedBy: declared.blockedBy.length,
|
|
818
|
+
notBlockedBy: declared.notBlockedBy.length,
|
|
819
|
+
related: declared.related.length,
|
|
820
|
+
},
|
|
821
|
+
"openspec dependencies written",
|
|
822
|
+
);
|
|
823
|
+
// The watcher would pick the write up; refresh now so the board updates promptly.
|
|
824
|
+
void directoryService
|
|
825
|
+
.refreshOpenSpec(cwd)
|
|
826
|
+
.then(() => onOpenSpecChanged?.(cwd))
|
|
827
|
+
.catch(() => undefined);
|
|
828
|
+
return { success: true, data: { file: out.file } } satisfies ApiResponse;
|
|
829
|
+
} finally {
|
|
830
|
+
inFlightInits.delete(lockKey);
|
|
831
|
+
}
|
|
832
|
+
},
|
|
833
|
+
);
|
|
834
|
+
|
|
331
835
|
fastify.post<{ Body: { cwd?: string; confirm?: boolean } }>(
|
|
332
836
|
"/api/openspec/init",
|
|
333
837
|
{ preHandler: networkGuard },
|
|
334
838
|
async (request, reply) => {
|
|
335
|
-
const
|
|
336
|
-
if (!
|
|
839
|
+
const requestCwd = request.body?.cwd;
|
|
840
|
+
if (!requestCwd) {
|
|
337
841
|
reply.code(400);
|
|
338
842
|
return { success: false, error: "cwd required" } satisfies ApiResponse;
|
|
339
843
|
}
|
|
340
|
-
|
|
844
|
+
// Admission (modelled guard; indeterminate → 503), then the existing exact membership.
|
|
845
|
+
const adm = await admitOpenSpecCwd(requestCwd, reply);
|
|
846
|
+
if (adm.kind === "unavailable") return adm.body;
|
|
847
|
+
if (adm.kind === "refused" || !knownInitTargets().includes(adm.cwd) || isGlobalOpenSpecParent(adm.cwd, adm.canonCwd)) {
|
|
341
848
|
reply.code(400);
|
|
342
849
|
return { success: false, error: "cwd is not a known session or pinned directory" } satisfies ApiResponse;
|
|
343
850
|
}
|
|
851
|
+
const cwd = adm.cwd;
|
|
344
852
|
|
|
345
853
|
// Overwrite confirmation. Two coarse triggers, both deliberate:
|
|
346
854
|
// 1. <cwd>/openspec/ presence — the spec's minimum contract.
|
|
@@ -388,11 +896,15 @@ export function registerOpenSpecRoutes(
|
|
|
388
896
|
} satisfies ApiResponse;
|
|
389
897
|
}
|
|
390
898
|
|
|
391
|
-
|
|
899
|
+
// The tracked check has passed: key the lock by the canonical path so
|
|
900
|
+
// two spellings of one directory (symlink) share it, and so does the
|
|
901
|
+
// workflow-schema endpoint. See change: add-pi-spec-driven-schema (D7).
|
|
902
|
+
const lockKey = canonicalPath(cwd);
|
|
903
|
+
if (inFlightInits.has(lockKey)) {
|
|
392
904
|
reply.code(409);
|
|
393
905
|
return { success: false, error: "an init is already in flight for this directory" } satisfies ApiResponse;
|
|
394
906
|
}
|
|
395
|
-
inFlightInits.add(
|
|
907
|
+
inFlightInits.add(lockKey);
|
|
396
908
|
|
|
397
909
|
try {
|
|
398
910
|
// Heal a stale literal "expanded" profile BEFORE the spawn — init
|
|
@@ -437,17 +949,34 @@ export function registerOpenSpecRoutes(
|
|
|
437
949
|
preferencesStore.setOpenSpecUpdateSignature(cwd, sig);
|
|
438
950
|
}
|
|
439
951
|
directoryService.invalidateOpenSpecSignatureCache();
|
|
952
|
+
|
|
953
|
+
// Chain `enable` for a project that had no `openspec/` before this init,
|
|
954
|
+
// when the global default is on. Runs inside THIS lock (no re-acquire);
|
|
955
|
+
// a failure never fails init and is reported in the response. The
|
|
956
|
+
// refresh below covers enable's forced refresh. See change:
|
|
957
|
+
// add-pi-spec-driven-schema (D7).
|
|
958
|
+
const chained: { workflowSchema?: WorkflowSchemaResult; workflowSchemaError?: string } = {};
|
|
959
|
+
if (!hasOpenspecRootAlready && gateConfig().workflowSchema.defaultForNewProjects) {
|
|
960
|
+
try {
|
|
961
|
+
const r = await runLoggedWorkflowAction(request.log, cwd, lockKey, { cwd, action: "enable" }, false);
|
|
962
|
+
if (r.ok) chained.workflowSchema = r;
|
|
963
|
+
else chained.workflowSchemaError = r.error ?? "enable failed";
|
|
964
|
+
} catch (err) {
|
|
965
|
+
chained.workflowSchemaError = err instanceof Error ? err.message : String(err);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
440
969
|
try {
|
|
441
970
|
const data = await directoryService.refreshOpenSpec(cwd);
|
|
442
971
|
onOpenSpecChanged?.(cwd);
|
|
443
|
-
return { success: true, data: { cwd, stdout: res.value, readiness: data.readiness } } satisfies ApiResponse;
|
|
972
|
+
return { success: true, data: { cwd, stdout: res.value, readiness: data.readiness, ...chained } } satisfies ApiResponse;
|
|
444
973
|
} catch {
|
|
445
974
|
// Refresh is best-effort; init itself succeeded.
|
|
446
975
|
onOpenSpecChanged?.(cwd);
|
|
447
|
-
return { success: true, data: { cwd, stdout: res.value } } satisfies ApiResponse;
|
|
976
|
+
return { success: true, data: { cwd, stdout: res.value, ...chained } } satisfies ApiResponse;
|
|
448
977
|
}
|
|
449
978
|
} finally {
|
|
450
|
-
inFlightInits.delete(
|
|
979
|
+
inFlightInits.delete(lockKey);
|
|
451
980
|
}
|
|
452
981
|
},
|
|
453
982
|
);
|
|
@@ -475,12 +1004,14 @@ export function registerOpenSpecRoutes(
|
|
|
475
1004
|
"/api/openspec-archive",
|
|
476
1005
|
{ preHandler: networkGuard },
|
|
477
1006
|
async (request, reply) => {
|
|
478
|
-
const
|
|
479
|
-
if (!
|
|
1007
|
+
const requestCwd = request.query.cwd;
|
|
1008
|
+
if (!requestCwd) {
|
|
480
1009
|
reply.code(400);
|
|
481
1010
|
return { success: false, error: "Missing cwd" } satisfies ApiResponse;
|
|
482
1011
|
}
|
|
483
|
-
const
|
|
1012
|
+
const admitted = await admitUngatedCwd(requestCwd, reply);
|
|
1013
|
+
if (!admitted.ok) return admitted.body;
|
|
1014
|
+
const data = await scanOpenSpecArchive(admitted.cwd);
|
|
484
1015
|
return { success: true, data } satisfies ApiResponse;
|
|
485
1016
|
},
|
|
486
1017
|
);
|
|
@@ -493,7 +1024,14 @@ export function registerOpenSpecRoutes(
|
|
|
493
1024
|
// cwd optional: the global Settings resource pages read only the
|
|
494
1025
|
// global scope (cwd-independent), so they omit it and the server scans
|
|
495
1026
|
// relative to its own cwd. See change: resources-card-tabs.
|
|
496
|
-
|
|
1027
|
+
let cwd: string;
|
|
1028
|
+
if (typeof request.query.cwd === "string" && request.query.cwd.length > 0) {
|
|
1029
|
+
const admitted = await admitUngatedCwd(request.query.cwd, reply);
|
|
1030
|
+
if (!admitted.ok) return admitted.body;
|
|
1031
|
+
cwd = admitted.cwd;
|
|
1032
|
+
} else {
|
|
1033
|
+
cwd = process.cwd();
|
|
1034
|
+
}
|
|
497
1035
|
// Bootstrap gate removed under change: eliminate-electron-runtime-install
|
|
498
1036
|
// (task 3.5). pi/openspec/tsx ship as regular npm deps; pi-resources
|
|
499
1037
|
// endpoint is unconditionally available.
|
|
@@ -526,6 +1064,41 @@ export function registerOpenSpecRoutes(
|
|
|
526
1064
|
},
|
|
527
1065
|
);
|
|
528
1066
|
|
|
1067
|
+
// Folder command list WITHOUT a live session: the latest list of a connected
|
|
1068
|
+
// session in exactly this cwd, else the enabled skills/prompts from the scan.
|
|
1069
|
+
// See change: redesign-directory-home-split (D3).
|
|
1070
|
+
fastify.get<{ Querystring: { cwd?: string } }>(
|
|
1071
|
+
"/api/pi-resources/commands",
|
|
1072
|
+
{ preHandler: networkGuard },
|
|
1073
|
+
async (request, reply) => {
|
|
1074
|
+
const requestCwd = request.query.cwd;
|
|
1075
|
+
// Shape check BEFORE admission: a relative cwd is never resolved against the server's cwd.
|
|
1076
|
+
if (typeof requestCwd !== "string" || requestCwd.length === 0 || !path.isAbsolute(requestCwd)) {
|
|
1077
|
+
reply.code(400);
|
|
1078
|
+
return { success: false, error: "cwd must be an absolute path" } satisfies ApiResponse;
|
|
1079
|
+
}
|
|
1080
|
+
const admitted = await admitUngatedCwd(requestCwd, reply);
|
|
1081
|
+
if (!admitted.ok) return admitted.body;
|
|
1082
|
+
const cwd = admitted.cwd;
|
|
1083
|
+
let scan: Awaited<ReturnType<typeof directoryService.refreshPiResources>> | undefined;
|
|
1084
|
+
try {
|
|
1085
|
+
const cached = directoryService.getPiResources(cwd);
|
|
1086
|
+
if (cached?.stale) void directoryService.refreshPiResources(cwd).catch(() => { /* next request retries */ });
|
|
1087
|
+
scan = cached?.data ?? (await directoryService.refreshPiResources(cwd));
|
|
1088
|
+
} catch {
|
|
1089
|
+
scan = undefined; // unreadable folder → live list or `none`, never a 500
|
|
1090
|
+
}
|
|
1091
|
+
const data: FolderCommandsResult = resolveFolderCommands({
|
|
1092
|
+
cwd,
|
|
1093
|
+
scan,
|
|
1094
|
+
sessions: sessionManager.listAll(),
|
|
1095
|
+
registry: sessionCommandRegistry,
|
|
1096
|
+
isSessionConnected: (id) => piGateway?.isSessionConnected(id) ?? false,
|
|
1097
|
+
});
|
|
1098
|
+
return { success: true, data } satisfies ApiResponse;
|
|
1099
|
+
},
|
|
1100
|
+
);
|
|
1101
|
+
|
|
529
1102
|
// Pi Resource file endpoint — reads files from allowed pi resource locations
|
|
530
1103
|
fastify.get<{ Querystring: { path?: string } }>(
|
|
531
1104
|
"/api/pi-resource-file",
|
|
@@ -573,11 +1146,15 @@ export function registerOpenSpecRoutes(
|
|
|
573
1146
|
"/api/openspec/tasks",
|
|
574
1147
|
{ preHandler: networkGuard },
|
|
575
1148
|
async (request, reply) => {
|
|
576
|
-
const { cwd, change } = request.query;
|
|
577
|
-
if (!
|
|
1149
|
+
const { cwd: requestCwd, change } = request.query;
|
|
1150
|
+
if (!requestCwd || typeof change !== "string") {
|
|
578
1151
|
reply.code(400);
|
|
579
1152
|
return { success: false, error: "cwd and change query params required" } satisfies ApiResponse;
|
|
580
1153
|
}
|
|
1154
|
+
const admitted = await admitUngatedCwd(requestCwd, reply);
|
|
1155
|
+
if (!admitted.ok) return admitted.body;
|
|
1156
|
+
const cwd = admitted.cwd;
|
|
1157
|
+
if (!isPortableProjectName(change)) return invalidName(reply);
|
|
581
1158
|
try {
|
|
582
1159
|
const tasks = await readTasks(cwd, change);
|
|
583
1160
|
const groups = Array.from(new Set(tasks.map((t) => t.group).filter((g) => g.length > 0)));
|
|
@@ -600,9 +1177,9 @@ export function registerOpenSpecRoutes(
|
|
|
600
1177
|
{ preHandler: networkGuard },
|
|
601
1178
|
async (request, reply) => {
|
|
602
1179
|
const body = request.body ?? {};
|
|
603
|
-
const { cwd, change, id, done, line } = body;
|
|
1180
|
+
const { cwd: requestCwd, change, id, done, line } = body;
|
|
604
1181
|
if (
|
|
605
|
-
typeof
|
|
1182
|
+
typeof requestCwd !== "string" ||
|
|
606
1183
|
typeof change !== "string" ||
|
|
607
1184
|
typeof id !== "string" ||
|
|
608
1185
|
typeof done !== "boolean" ||
|
|
@@ -611,6 +1188,10 @@ export function registerOpenSpecRoutes(
|
|
|
611
1188
|
reply.code(400);
|
|
612
1189
|
return { success: false, error: "invalid body" } satisfies ApiResponse;
|
|
613
1190
|
}
|
|
1191
|
+
const admitted = await admitUngatedCwd(requestCwd, reply);
|
|
1192
|
+
if (!admitted.ok) return admitted.body;
|
|
1193
|
+
const cwd = admitted.cwd;
|
|
1194
|
+
if (!isPortableProjectName(change)) return invalidName(reply);
|
|
614
1195
|
try {
|
|
615
1196
|
const task = await toggleTask(cwd, change, id, done, line);
|
|
616
1197
|
// Fire-and-forget: refresh cache + broadcast openspec_update.
|