@blackbelt-technology/pi-agent-dashboard 0.9.0 → 0.10.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/README.md +38 -5
- package/docs/architecture.md +1673 -75
- package/package.json +23 -15
- package/packages/extension/package.json +8 -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 +450 -0
- package/packages/extension/src/bridge-handlers/forwarders.ts +616 -0
- package/packages/extension/src/bridge-handlers/instance.ts +220 -0
- package/packages/extension/src/bridge-handlers/lifecycle.ts +1030 -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.ts +480 -2510
- package/packages/extension/src/command-handler.ts +180 -11
- package/packages/extension/src/connection.ts +265 -18
- package/packages/extension/src/dashboard-context-injector.ts +26 -47
- 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/local-token-header.ts +161 -17
- package/packages/extension/src/message-update-coalescer.ts +3 -1
- package/packages/extension/src/model-refresh.ts +19 -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/plugin-event-forward-registry.ts +200 -0
- package/packages/extension/src/project-trust.ts +119 -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 +87 -20
- package/packages/extension/src/role-manager.ts +5 -4
- package/packages/extension/src/server-auto-start.ts +12 -5
- package/packages/extension/src/server-launcher.ts +11 -13
- package/packages/extension/src/session-move.ts +19 -0
- package/packages/extension/src/session-sync.ts +31 -38
- 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 +394 -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 +18 -0
- 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 +28 -1
- 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-mirror-service.ts +374 -0
- package/packages/server/src/access/planes.ts +10 -1
- package/packages/server/src/access/refusal-ledger.ts +6 -6
- package/packages/server/src/access/yolo-session.ts +73 -12
- 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 +544 -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/attachments/fit-worker-pool.ts +12 -17
- package/packages/server/src/auth/approval-refusal.ts +87 -0
- package/packages/server/src/auth/auth-plugin.ts +292 -79
- package/packages/server/src/auth/auth.ts +78 -7
- package/packages/server/src/auth/bearer-auth.ts +23 -1
- package/packages/server/src/auth/cors-origin.ts +10 -0
- package/packages/server/src/auth/csp.ts +6 -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.ts +7 -4
- package/packages/server/src/auth/local-token.ts +16 -0
- package/packages/server/src/auth/localhost-guard.ts +251 -8
- 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-log.ts +34 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +173 -0
- package/packages/server/src/auth/passkey/passkey-routes.ts +224 -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 +321 -0
- package/packages/server/src/auth/provider-auth-registry.ts +35 -1
- package/packages/server/src/auth/provider-auth-storage.ts +55 -8
- package/packages/server/src/auth/radius-override.ts +13 -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/serve-app-host.ts +97 -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/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 +128 -6
- package/packages/server/src/browser-handlers/session-action-handler.ts +129 -62
- 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/cli.ts +883 -97
- package/packages/server/src/config-api.ts +143 -1
- package/packages/server/src/config-snapshot.ts +5 -0
- package/packages/server/src/directory-service.ts +435 -32
- 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 +208 -35
- package/packages/server/src/file-watch-manager.ts +187 -39
- package/packages/server/src/git-worktree/git-operations.ts +16 -5
- package/packages/server/src/git-worktree/worktree-init-trust.ts +48 -5
- 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 +18 -0
- 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 +9 -0
- package/packages/server/src/identity/ws-road-classification.ts +9 -0
- package/packages/server/src/known-server-moves.ts +175 -0
- package/packages/server/src/lib/browse-roots.ts +36 -0
- package/packages/server/src/lib/digest-gate.ts +82 -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/purify.ts +13 -5
- package/packages/server/src/lib/writable-handler-target.ts +66 -0
- package/packages/server/src/lib/writable-md-target.ts +12 -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 +77 -1
- package/packages/server/src/lifecycle/stop-ownership.ts +97 -11
- package/packages/server/src/live-server/live-capability.ts +254 -0
- package/packages/server/src/live-server/live-server-proxy.ts +173 -26
- 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/openspec-change-watcher.ts +109 -16
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +132 -0
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +90 -35
- package/packages/server/src/openspec/openspec-poll-worker.ts +200 -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.ts +1128 -0
- package/packages/server/src/package/installed-package-enricher.ts +38 -3
- 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 +5 -3
- package/packages/server/src/pairing/browser-gateway.ts +108 -8
- package/packages/server/src/pairing/knock-admission.ts +277 -0
- package/packages/server/src/pairing/pairing.ts +154 -27
- 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 +116 -7
- package/packages/server/src/pi/bridge-upgrade-auth.ts +32 -21
- package/packages/server/src/pi/folder-commands.ts +141 -0
- 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 +158 -33
- package/packages/server/src/pi/pi-gateway.ts +93 -9
- 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/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 +123 -5
- 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/file-routes.ts +366 -75
- package/packages/server/src/routes/file-write-binary-routes.ts +473 -0
- package/packages/server/src/routes/folder-project-routes.ts +99 -0
- package/packages/server/src/routes/git-routes.ts +17 -2
- package/packages/server/src/routes/known-servers-routes.ts +333 -53
- package/packages/server/src/routes/live-server-routes.ts +72 -4
- package/packages/server/src/routes/local-proof-routes.ts +12 -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/openspec-routes.ts +270 -40
- package/packages/server/src/routes/package-health-routes.ts +140 -0
- package/packages/server/src/routes/package-routes.ts +28 -1
- package/packages/server/src/routes/pairing-routes.ts +158 -24
- 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/plugin-activation-routes.ts +87 -27
- package/packages/server/src/routes/provider-auth-routes.ts +22 -5
- package/packages/server/src/routes/provider-routes.ts +29 -0
- package/packages/server/src/routes/resource-activation-routes.ts +16 -32
- package/packages/server/src/routes/session-routes.ts +49 -5
- package/packages/server/src/routes/system-routes.ts +207 -23
- package/packages/server/src/routes/tls-routes.ts +55 -0
- package/packages/server/src/routes/user-routes.ts +192 -0
- 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 +919 -139
- 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/in-flight-tool-calls.ts +74 -0
- package/packages/server/src/session/memory-session-manager.ts +53 -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/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-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/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 +67 -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-config-validation.ts +92 -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/vault-bindings.ts +101 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +294 -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/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 +385 -71
- package/packages/shared/src/canonical-subject.ts +27 -2
- package/packages/shared/src/card-sections.ts +185 -1
- package/packages/shared/src/chrome-profiles.ts +188 -0
- package/packages/shared/src/config.ts +473 -26
- 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/editor-pane-tab.ts +26 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +71 -0
- package/packages/shared/src/dashboard-plugin/index.ts +7 -3
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +106 -2
- 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 +95 -0
- package/packages/shared/src/dashboard-plugin/slot-types.ts +64 -4
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +22 -3
- package/packages/shared/src/dashboard-starter.ts +30 -0
- package/packages/shared/src/display-name.ts +42 -0
- package/packages/shared/src/doctor-core.ts +25 -107
- 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/local-credential-proof.ts +219 -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/md-table-cell.ts +11 -0
- package/packages/shared/src/mdns-discovery.ts +392 -42
- package/packages/shared/src/models-json-reader.ts +6 -0
- package/packages/shared/src/openspec-design-evidence.ts +25 -1
- package/packages/shared/src/openspec-poller.ts +210 -9
- 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 +261 -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-mirror-snapshot.ts +200 -0
- package/packages/shared/src/pi-trust-mirror-types.ts +57 -0
- package/packages/shared/src/pi-trust-mirror.ts +328 -0
- package/packages/shared/src/platform/binary-lookup.ts +2 -194
- package/packages/shared/src/platform/git.ts +204 -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 +51 -0
- package/packages/shared/src/platform/runner.ts +46 -2
- 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/project-name.ts +42 -0
- package/packages/shared/src/prompt-answer.ts +183 -0
- package/packages/shared/src/protocol.ts +133 -8
- package/packages/shared/src/question-types.ts +73 -0
- package/packages/shared/src/recommended-extensions.ts +80 -23
- package/packages/shared/src/recovery-timing.ts +12 -0
- package/packages/shared/src/redaction.ts +50 -0
- package/packages/shared/src/rest-api.ts +484 -1
- 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 +127 -0
- 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/server-identity.ts +51 -15
- package/packages/shared/src/server-launcher.ts +12 -33
- package/packages/shared/src/server-pinning.ts +81 -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/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-status.ts +69 -0
- package/packages/shared/src/tool-path-resolve.ts +243 -0
- package/packages/shared/src/tool-registry/definitions.ts +26 -4
- 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/tunnel-provider.ts +3 -2
- package/packages/shared/src/types.ts +104 -9
- package/packages/shared/src/vault-delivery.ts +73 -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 +135 -0
- package/tsconfig.base.json +1 -0
|
@@ -20,21 +20,36 @@
|
|
|
20
20
|
*
|
|
21
21
|
* See change: consolidate-tool-resolution.
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
import
|
|
23
|
+
|
|
24
|
+
import { existsSync, promises as fsp, readFileSync } from "node:fs";
|
|
25
|
+
import path from "node:path";
|
|
26
|
+
import { parse as parseYaml } from "yaml";
|
|
26
27
|
import {
|
|
27
|
-
evaluateLocalDesignSatisfaction,
|
|
28
28
|
createFsDesignEvidenceProbe,
|
|
29
29
|
type DesignEvidenceProbe,
|
|
30
|
+
evaluateLocalDesignSatisfaction,
|
|
30
31
|
} from "./openspec-design-evidence.js";
|
|
31
32
|
import {
|
|
32
|
-
evaluateLocalSpecsSatisfaction,
|
|
33
33
|
createFsSpecsEvidenceProbe,
|
|
34
|
+
evaluateLocalSpecsSatisfaction,
|
|
34
35
|
type SpecsEvidenceProbe,
|
|
35
36
|
} from "./openspec-specs-evidence.js";
|
|
36
|
-
import {
|
|
37
|
-
|
|
37
|
+
import {
|
|
38
|
+
canonicalArtifactOrder,
|
|
39
|
+
computeTrackedExtras,
|
|
40
|
+
countTasksFromContent,
|
|
41
|
+
entryError,
|
|
42
|
+
mapCliPath,
|
|
43
|
+
mapLimit,
|
|
44
|
+
type StatusAllEntry,
|
|
45
|
+
type StatusAllRaw,
|
|
46
|
+
selectTrackedArtifact,
|
|
47
|
+
type TrackedExtras,
|
|
48
|
+
taskListStatus,
|
|
49
|
+
} from "./openspec-status-all.js";
|
|
50
|
+
import { listOr, OPENSPEC_LIST, OPENSPEC_STATUS, OPENSPEC_STATUS_ALL, statusOr, userSchemasDir } from "./platform/openspec.js";
|
|
51
|
+
import { type Result, runAsync, unwrap } from "./platform/runner.js";
|
|
52
|
+
import type { OpenSpecArtifact, OpenSpecChange, OpenSpecData } from "./types.js";
|
|
38
53
|
|
|
39
54
|
const EMPTY_DATA: OpenSpecData = { initialized: false, changes: [] };
|
|
40
55
|
|
|
@@ -62,7 +77,7 @@ export type SpecsProbeFactory = (changeName: string) => SpecsEvidenceProbe;
|
|
|
62
77
|
|
|
63
78
|
export function buildOpenSpecData(
|
|
64
79
|
listResult: { changes?: Array<{ name: string; status: string; completedTasks: number; totalTasks: number }> } | null,
|
|
65
|
-
statusResults: Map<string, { artifacts?: Array<{ id: string; status: string }>; isComplete?: boolean } | null>,
|
|
80
|
+
statusResults: Map<string, { artifacts?: Array<{ id: string; status: string }>; isComplete?: boolean; schemaName?: string } | null>,
|
|
66
81
|
probeFactory?: DesignProbeFactory,
|
|
67
82
|
specsProbeFactory?: SpecsProbeFactory,
|
|
68
83
|
): OpenSpecData {
|
|
@@ -86,7 +101,11 @@ export function buildOpenSpecData(
|
|
|
86
101
|
const designIdx = artifacts.findIndex((a) => a.id === "design");
|
|
87
102
|
if (designIdx !== -1 && artifacts[designIdx].status === "ready") {
|
|
88
103
|
const probe = probeFactory(c.name);
|
|
89
|
-
|
|
104
|
+
// pi-spec-driven skips evidence: per-change `schemaName` (status --all /
|
|
105
|
+
// status --change), else resolved locally from `.openspec.yaml` on the
|
|
106
|
+
// fallback `list` path. See change: add-pi-spec-driven-schema.
|
|
107
|
+
const schemaName = statusResult?.schemaName ?? probe.localSchemaName?.("");
|
|
108
|
+
if (evaluateLocalDesignSatisfaction("", probe, schemaName)) {
|
|
90
109
|
artifacts[designIdx] = { ...artifacts[designIdx], status: "done" };
|
|
91
110
|
}
|
|
92
111
|
}
|
|
@@ -219,6 +238,7 @@ export function createFsProbeFactory(cwd: string): DesignProbeFactory {
|
|
|
219
238
|
hasDesignFile: () => probe.hasDesignFile(changeDir),
|
|
220
239
|
hasDesignDirWithMd: () => probe.hasDesignDirWithMd(changeDir),
|
|
221
240
|
tasksHasCheckboxes: () => probe.tasksHasCheckboxes(changeDir),
|
|
241
|
+
localSchemaName: () => probe.localSchemaName?.(changeDir),
|
|
222
242
|
};
|
|
223
243
|
};
|
|
224
244
|
}
|
|
@@ -310,3 +330,184 @@ export async function pollOpenSpecAsync(cwd: string): Promise<OpenSpecData> {
|
|
|
310
330
|
createFsSpecsProbeFactory(cwd),
|
|
311
331
|
);
|
|
312
332
|
}
|
|
333
|
+
|
|
334
|
+
// ── `openspec status --all` path ────────────────────────────────────────────
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Run `openspec status --all --json` for one cwd and return the RAW outcome
|
|
338
|
+
* regardless of exit code (a single broken change exits 1 with complete JSON).
|
|
339
|
+
* Never throws; spawn-level failures set `failure`. Classification and
|
|
340
|
+
* parsing happen later, off the main thread. See change: use-openspec-status-all.
|
|
341
|
+
*/
|
|
342
|
+
export async function runOpenSpecStatusAll(cwd: string): Promise<StatusAllRaw> {
|
|
343
|
+
return statusAllRawFromResult(await runAsync(OPENSPEC_STATUS_ALL, { cwd }, { cwd }));
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Runner `Result` → raw outcome: stdout + stderr whatever the exit code; spawn-level failures set `failure`. */
|
|
347
|
+
export function statusAllRawFromResult(result: Result<string>): StatusAllRaw {
|
|
348
|
+
if (result.ok) return { stdout: result.value, stderr: "", exitCode: 0 };
|
|
349
|
+
const err = result.error;
|
|
350
|
+
if (err.kind === "exit") {
|
|
351
|
+
return { stdout: err.stdout ?? "", stderr: err.stderr ?? "", exitCode: err.code ?? null };
|
|
352
|
+
}
|
|
353
|
+
return { stdout: "", stderr: "", exitCode: null, failure: err.kind };
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/** schema.yaml path → `{ mtimeMs, applyTracks }`, memoized by mtime. */
|
|
357
|
+
const schemaTracksMemo = new Map<string, { mtimeMs: number; tracks: string | undefined }>();
|
|
358
|
+
|
|
359
|
+
async function readApplyTracks(schemaFile: string): Promise<{ exists: boolean; tracks: string | undefined }> {
|
|
360
|
+
let mtimeMs: number;
|
|
361
|
+
try {
|
|
362
|
+
mtimeMs = (await fsp.stat(schemaFile)).mtimeMs;
|
|
363
|
+
} catch {
|
|
364
|
+
return { exists: false, tracks: undefined };
|
|
365
|
+
}
|
|
366
|
+
const memo = schemaTracksMemo.get(schemaFile);
|
|
367
|
+
if (memo && memo.mtimeMs === mtimeMs) return { exists: true, tracks: memo.tracks };
|
|
368
|
+
let tracks: string | undefined;
|
|
369
|
+
try {
|
|
370
|
+
const doc = parseYaml(await fsp.readFile(schemaFile, "utf8")) as { apply?: { tracks?: unknown } } | null;
|
|
371
|
+
const t = doc?.apply?.tracks;
|
|
372
|
+
tracks = typeof t === "string" ? t : undefined;
|
|
373
|
+
} catch {
|
|
374
|
+
tracks = undefined; // unreadable / unparsable ⇒ `apply.tracks` absent
|
|
375
|
+
}
|
|
376
|
+
schemaTracksMemo.set(schemaFile, { mtimeMs, tracks });
|
|
377
|
+
return { exists: true, tracks };
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* `apply.tracks` for a schema by OpenSpec's resolution order: project-local
|
|
382
|
+
* `<openspec>/schemas/<name>/schema.yaml`, then the user schema dir; the first
|
|
383
|
+
* existing file wins (even when it declares no `apply.tracks`). The built-in
|
|
384
|
+
* package schemas are not read — `spec-driven` tracks `tasks.md`, which the
|
|
385
|
+
* "artifact with id `tasks`" default yields identically.
|
|
386
|
+
*/
|
|
387
|
+
export async function resolveApplyTracks(
|
|
388
|
+
schemaName: string | undefined,
|
|
389
|
+
openspecDir: string,
|
|
390
|
+
userDir: string = userSchemasDir(),
|
|
391
|
+
): Promise<string | undefined> {
|
|
392
|
+
if (!schemaName || /[\\/]/.test(schemaName) || schemaName === "." || schemaName === ".." || /^[A-Za-z]:/.test(schemaName)) {
|
|
393
|
+
return undefined;
|
|
394
|
+
}
|
|
395
|
+
for (const dir of [path.join(openspecDir, "schemas"), userDir]) {
|
|
396
|
+
const r = await readApplyTracks(path.join(dir, schemaName, "schema.yaml"));
|
|
397
|
+
if (r.exists) return r.tracks;
|
|
398
|
+
}
|
|
399
|
+
return undefined;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
async function countFile(file: string): Promise<{ total: number; completed: number }> {
|
|
403
|
+
try {
|
|
404
|
+
return countTasksFromContent(await fsp.readFile(file, "utf8"));
|
|
405
|
+
} catch {
|
|
406
|
+
return { total: 0, completed: 0 };
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export interface StatusAllBuildInput {
|
|
411
|
+
cwd: string;
|
|
412
|
+
/** Server-canonical `<cwd>/openspec` directory (realpath). */
|
|
413
|
+
openspecDir: string;
|
|
414
|
+
/** `root.path` exactly as the CLI emitted it. */
|
|
415
|
+
rootPath: string;
|
|
416
|
+
entries: StatusAllEntry[];
|
|
417
|
+
/** Probe effective mtime per change — the sort key (newest first, ties by name). */
|
|
418
|
+
orderMtimes: Record<string, number | undefined>;
|
|
419
|
+
/** Test seam: user schema directory. */
|
|
420
|
+
userSchemasDir?: string;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export interface StatusAllBuildResult {
|
|
424
|
+
data: OpenSpecData;
|
|
425
|
+
/** Tracked extras per change, mapped onto `openspecDir`, for the gate and watcher. */
|
|
426
|
+
extras: Record<string, TrackedExtras>;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** Local task counts for one entry (OpenSpec's file selection; top-level `tasks.md` fallback). */
|
|
430
|
+
async function countEntryTasks(
|
|
431
|
+
entry: StatusAllEntry,
|
|
432
|
+
err: ReturnType<typeof entryError>,
|
|
433
|
+
input: StatusAllBuildInput,
|
|
434
|
+
): Promise<{ total: number; completed: number }> {
|
|
435
|
+
const { openspecDir, rootPath } = input;
|
|
436
|
+
const tracks = err ? undefined : await resolveApplyTracks(entry.schemaName, openspecDir, input.userSchemasDir);
|
|
437
|
+
const tracked = err ? undefined : selectTrackedArtifact(entry.artifacts, tracks);
|
|
438
|
+
const files: string[] = [];
|
|
439
|
+
for (const p of tracked ? (entry.artifactPaths?.[tracked.id]?.existingOutputPaths ?? []) : []) {
|
|
440
|
+
const mapped = mapCliPath(p, rootPath, openspecDir);
|
|
441
|
+
if (mapped) files.push(mapped);
|
|
442
|
+
}
|
|
443
|
+
if (files.length === 0) files.push(path.join(openspecDir, "changes", entry.changeName, "tasks.md"));
|
|
444
|
+
let total = 0;
|
|
445
|
+
let completed = 0;
|
|
446
|
+
for (const f of files) {
|
|
447
|
+
const c = await countFile(f);
|
|
448
|
+
total += c.total;
|
|
449
|
+
completed += c.completed;
|
|
450
|
+
}
|
|
451
|
+
return { total, completed };
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/** Newest-first by probe mtime, ties by name. */
|
|
455
|
+
function byNewestThenName(orderMtimes: Record<string, number | undefined>) {
|
|
456
|
+
return (a: OpenSpecChange, b: OpenSpecChange): number => {
|
|
457
|
+
const ma = orderMtimes[a.name] ?? 0;
|
|
458
|
+
const mb = orderMtimes[b.name] ?? 0;
|
|
459
|
+
if (ma !== mb) return mb - ma;
|
|
460
|
+
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Build `OpenSpecData` from a classified `status --all` envelope: local task
|
|
466
|
+
* counting (OpenSpec's task-line rule and file selection), canonical artifact
|
|
467
|
+
* order, per-change `error`, the promote-only design/specs overrides, and the
|
|
468
|
+
* newest-first change order. All file I/O is async and bounded.
|
|
469
|
+
* See change: use-openspec-status-all.
|
|
470
|
+
*/
|
|
471
|
+
export async function buildOpenSpecDataFromStatusAll(input: StatusAllBuildInput): Promise<StatusAllBuildResult> {
|
|
472
|
+
const { cwd, openspecDir, rootPath, entries, orderMtimes } = input;
|
|
473
|
+
|
|
474
|
+
const counted = await mapLimit(entries, 16, async (entry) => {
|
|
475
|
+
const err = entryError(entry);
|
|
476
|
+
return { entry, err, ...(await countEntryTasks(entry, err, input)) };
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
const listEntries = counted.map((c) => ({
|
|
480
|
+
name: c.entry.changeName,
|
|
481
|
+
status: taskListStatus(c.total, c.completed),
|
|
482
|
+
completedTasks: c.completed,
|
|
483
|
+
totalTasks: c.total,
|
|
484
|
+
}));
|
|
485
|
+
const statusResults = new Map<string, { artifacts?: Array<{ id: string; status: string }>; isComplete?: boolean; schemaName?: string } | null>();
|
|
486
|
+
const extras: Record<string, TrackedExtras> = {};
|
|
487
|
+
for (const c of counted) {
|
|
488
|
+
const { entry } = c;
|
|
489
|
+
extras[entry.changeName] = computeTrackedExtras(entry, rootPath, openspecDir, path.join(openspecDir, "changes", entry.changeName));
|
|
490
|
+
statusResults.set(
|
|
491
|
+
entry.changeName,
|
|
492
|
+
c.err
|
|
493
|
+
? null
|
|
494
|
+
: {
|
|
495
|
+
...(entry.schemaName ? { schemaName: entry.schemaName } : {}),
|
|
496
|
+
artifacts: canonicalArtifactOrder(entry.artifacts ?? []).map((a) => ({ id: a.id, status: a.status })),
|
|
497
|
+
...(typeof entry.isComplete === "boolean" ? { isComplete: entry.isComplete } : {}),
|
|
498
|
+
},
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const built = buildOpenSpecData(
|
|
503
|
+
{ changes: listEntries },
|
|
504
|
+
statusResults,
|
|
505
|
+
createFsProbeFactory(cwd),
|
|
506
|
+
createFsSpecsProbeFactory(cwd),
|
|
507
|
+
);
|
|
508
|
+
const errorByName = new Map(counted.filter((c) => c.err).map((c) => [c.entry.changeName, c.err!]));
|
|
509
|
+
const changes = built.changes
|
|
510
|
+
.map((c) => (errorByName.has(c.name) ? { ...c, error: errorByName.get(c.name)! } : c))
|
|
511
|
+
.sort(byNewestThenName(orderMtimes));
|
|
512
|
+
return { data: { initialized: true, changes }, extras };
|
|
513
|
+
}
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the `openspec status --all --json` poll path.
|
|
3
|
+
*
|
|
4
|
+
* No filesystem and no process spawning here — the module is safe to import
|
|
5
|
+
* from the poll worker and from browser-adjacent code. It owns:
|
|
6
|
+
* - envelope classification (unsupported CLI / whole-call failure / success),
|
|
7
|
+
* - sanitization of per-change error text before it is broadcast,
|
|
8
|
+
* - OpenSpec's task-line counting rule,
|
|
9
|
+
* - the per-CLI-installation "`--all` unsupported" cache,
|
|
10
|
+
* - CLI-path → server-path mapping and tracked-path extras for the gate.
|
|
11
|
+
*
|
|
12
|
+
* See change: use-openspec-status-all.
|
|
13
|
+
*/
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
|
|
16
|
+
// ── Raw CLI result ──────────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
/** Raw result of one `openspec status --all --json` call, whatever the exit code. */
|
|
19
|
+
export interface StatusAllRaw {
|
|
20
|
+
stdout: string;
|
|
21
|
+
stderr: string;
|
|
22
|
+
exitCode: number | null;
|
|
23
|
+
/**
|
|
24
|
+
* Spawn-level failure (not-found / timeout / spawn-failure / aborted /
|
|
25
|
+
* output-too-large): there is no trustworthy stdout. The value is a short
|
|
26
|
+
* machine-readable cause, never forwarded to clients.
|
|
27
|
+
*/
|
|
28
|
+
failure?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface StatusAllArtifact {
|
|
32
|
+
id: string;
|
|
33
|
+
outputPath?: string;
|
|
34
|
+
status: string;
|
|
35
|
+
requires?: string[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface StatusAllArtifactPaths {
|
|
39
|
+
outputPath?: string;
|
|
40
|
+
resolvedOutputPath?: string;
|
|
41
|
+
existingOutputPaths?: string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface StatusAllEntry {
|
|
45
|
+
changeName: string;
|
|
46
|
+
schemaName?: string;
|
|
47
|
+
changeRoot?: string;
|
|
48
|
+
artifactPaths?: Record<string, StatusAllArtifactPaths>;
|
|
49
|
+
isComplete?: boolean;
|
|
50
|
+
artifacts?: StatusAllArtifact[];
|
|
51
|
+
status?: Array<{ severity?: string; code?: string; message?: string }>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type StatusAllClassification =
|
|
55
|
+
| { kind: "unsupported" }
|
|
56
|
+
| { kind: "failed"; reason: string }
|
|
57
|
+
| { kind: "ok"; root: { path: string; source?: string }; entries: StatusAllEntry[] };
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Parse JSON from stdout; returns null on parse failure.
|
|
61
|
+
*
|
|
62
|
+
* Tolerates a non-JSON PREAMBLE. `openspec` prints a one-off telemetry notice
|
|
63
|
+
* on its first run under a given HOME, ahead of the JSON body — strict parsing
|
|
64
|
+
* turned that into "no changes", so a fresh HOME (new container, new user, CI)
|
|
65
|
+
* silently produced an empty OpenSpec panel on the first poll.
|
|
66
|
+
* See test: platform/__tests__/openspec-json-preamble.test.ts.
|
|
67
|
+
* (Lives here, not in `platform/openspec.ts`, so this module stays free of runner/fs imports.)
|
|
68
|
+
*/
|
|
69
|
+
export function parseJsonOrNull(out: string): unknown | null {
|
|
70
|
+
const trimmed = out.trim();
|
|
71
|
+
if (!trimmed) return null;
|
|
72
|
+
try {
|
|
73
|
+
return JSON.parse(trimmed);
|
|
74
|
+
} catch {
|
|
75
|
+
// Retry from the first JSON opener. Only a leading preamble is recovered;
|
|
76
|
+
// trailing junk still fails, and output with no opener stays null.
|
|
77
|
+
const start = trimmed.search(/[[{]/);
|
|
78
|
+
if (start <= 0) return null;
|
|
79
|
+
try {
|
|
80
|
+
return JSON.parse(trimmed.slice(start));
|
|
81
|
+
} catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ── Classification ──────────────────────────────────────────────────────────
|
|
88
|
+
|
|
89
|
+
/** Commander's wording for an unknown option on an older CLI. */
|
|
90
|
+
const UNSUPPORTED_RE = /unknown option ['"]?--all/i;
|
|
91
|
+
|
|
92
|
+
function isObject(v: unknown): v is Record<string, unknown> {
|
|
93
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Classify one raw `status --all` result. Order matters: the unsupported-CLI
|
|
98
|
+
* test runs first (it only fires when there is NO JSON body), then the
|
|
99
|
+
* whole-call failure checks, otherwise success.
|
|
100
|
+
*/
|
|
101
|
+
export function classifyStatusAll(raw: StatusAllRaw): StatusAllClassification {
|
|
102
|
+
if (raw.failure) return { kind: "failed", reason: raw.failure };
|
|
103
|
+
|
|
104
|
+
const parsed = parseJsonOrNull(raw.stdout);
|
|
105
|
+
const hasJson = isObject(parsed);
|
|
106
|
+
|
|
107
|
+
if (!hasJson) {
|
|
108
|
+
if (UNSUPPORTED_RE.test(raw.stderr) || UNSUPPORTED_RE.test(raw.stdout)) {
|
|
109
|
+
return { kind: "unsupported" };
|
|
110
|
+
}
|
|
111
|
+
return { kind: "failed", reason: "no-json" };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const top = parsed;
|
|
115
|
+
if (Array.isArray(top.status) && top.status.some((s) => isObject(s) && s.severity === "error")) {
|
|
116
|
+
return { kind: "failed", reason: "top-level-error" };
|
|
117
|
+
}
|
|
118
|
+
const root = top.root;
|
|
119
|
+
if (root === null) return { kind: "failed", reason: "root-null" };
|
|
120
|
+
if (!isObject(root) || typeof root.path !== "string") return { kind: "failed", reason: "root-missing" };
|
|
121
|
+
if (root.source === "implicit") return { kind: "failed", reason: "root-implicit" };
|
|
122
|
+
if (!Array.isArray(top.changes)) return { kind: "failed", reason: "changes-missing" };
|
|
123
|
+
|
|
124
|
+
const entries = top.changes.filter(
|
|
125
|
+
(e): e is StatusAllEntry => isObject(e) && typeof e.changeName === "string",
|
|
126
|
+
);
|
|
127
|
+
return {
|
|
128
|
+
kind: "ok",
|
|
129
|
+
root: { path: root.path, ...(typeof root.source === "string" ? { source: root.source } : {}) },
|
|
130
|
+
entries,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ── Sanitization ────────────────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
export const ERROR_MESSAGE_MAX = 500;
|
|
137
|
+
export const ERROR_CODE_MAX = 64;
|
|
138
|
+
|
|
139
|
+
function truncate(s: string, max: number): string {
|
|
140
|
+
if (s.length <= max) return s;
|
|
141
|
+
let out = s.slice(0, max);
|
|
142
|
+
// Never end on a lone high surrogate (would break JSON/UTF-8 round-trips).
|
|
143
|
+
const last = out.charCodeAt(out.length - 1);
|
|
144
|
+
if (last >= 0xd800 && last <= 0xdbff) out = out.slice(0, -1);
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Sanitize a CLI-provided error before caching/broadcasting: control
|
|
150
|
+
* characters stripped, `message` collapsed onto one line of ≤ 500 chars,
|
|
151
|
+
* `code` ≤ 64 chars. Line breaks become a single space so words do not fuse.
|
|
152
|
+
*/
|
|
153
|
+
export function sanitizeChangeError(code: unknown, message: unknown): { code: string; message: string } {
|
|
154
|
+
const c = String(code ?? "").replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029]/g, "");
|
|
155
|
+
const m = String(message ?? "")
|
|
156
|
+
.replace(/[\r\n\u2028\u2029]+/g, " ")
|
|
157
|
+
.replace(/[\u0000-\u001f\u007f-\u009f]/g, "");
|
|
158
|
+
return { code: truncate(c, ERROR_CODE_MAX), message: truncate(m, ERROR_MESSAGE_MAX) };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The per-change error for an entry carrying no `artifacts`, or `null` when
|
|
163
|
+
* the entry is a healthy one. An entry with neither `artifacts` nor `status`
|
|
164
|
+
* maps to `unknown-entry`.
|
|
165
|
+
*/
|
|
166
|
+
export function entryError(entry: StatusAllEntry): { code: string; message: string } | null {
|
|
167
|
+
const list = Array.isArray(entry.status) ? entry.status : [];
|
|
168
|
+
const errorStatus = list.find((s) => s && s.severity === "error");
|
|
169
|
+
// `artifacts` present and non-empty ⇒ healthy; an empty list alongside an
|
|
170
|
+
// error status is still a broken change.
|
|
171
|
+
if (Array.isArray(entry.artifacts) && (entry.artifacts.length > 0 || !errorStatus)) return null;
|
|
172
|
+
const first = errorStatus ?? list[0];
|
|
173
|
+
if (!first) return sanitizeChangeError("unknown-entry", "Unrecognised entry in openspec status output");
|
|
174
|
+
return sanitizeChangeError(first.code ?? "change_error", first.message ?? "");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ── Task counting (OpenSpec's rule) ─────────────────────────────────────────
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Verbatim copy of OpenSpec's `TASK_LINE_PATTERN` (utils/task-progress.js) at
|
|
181
|
+
* 1.14.3: any CommonMark list marker (`-`, `*`, `+`, `1.`, `1)`) and a one-token
|
|
182
|
+
* checkbox (`[~]`, `[]`, `[ x ]` count as not-done), link bullets excluded.
|
|
183
|
+
* Re-copy it on every CLI bump; the `status --all` parity suite
|
|
184
|
+
* (`openspec-status-all-parity.shard*.test.ts`) is the oracle.
|
|
185
|
+
* See change: refresh-electron-bundled-components.
|
|
186
|
+
*/
|
|
187
|
+
const TASK_LINE_PATTERN = /^\s*(?:[-*+]|\d{1,9}[.)])\s*\[(?:\s*([^\]\s]?)\s*\](?![([])|\s+\])\s*(.*)/;
|
|
188
|
+
|
|
189
|
+
/** Mirrors OpenSpec's `countTasksFromContent`: every matching line counts. */
|
|
190
|
+
export function countTasksFromContent(content: string): { total: number; completed: number } {
|
|
191
|
+
let total = 0;
|
|
192
|
+
let completed = 0;
|
|
193
|
+
for (const line of content.split("\n")) {
|
|
194
|
+
const m = TASK_LINE_PATTERN.exec(line);
|
|
195
|
+
if (!m) continue;
|
|
196
|
+
total++;
|
|
197
|
+
if ((m[1] ?? "").toLowerCase() === "x") completed++;
|
|
198
|
+
}
|
|
199
|
+
return { total, completed };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function taskListStatus(total: number, completed: number): "no-tasks" | "in-progress" | "complete" {
|
|
203
|
+
if (total === 0) return "no-tasks";
|
|
204
|
+
return completed === total ? "complete" : "in-progress";
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Pick the tracked-tasks artifact the way OpenSpec's `findTrackedTasksArtifact`
|
|
209
|
+
* does: by `apply.tracks` (artifact whose `outputPath` equals it; none
|
|
210
|
+
* matching ⇒ none), else the artifact with id `tasks`.
|
|
211
|
+
*/
|
|
212
|
+
export function selectTrackedArtifact(
|
|
213
|
+
artifacts: StatusAllArtifact[] | undefined,
|
|
214
|
+
applyTracks: string | undefined,
|
|
215
|
+
): StatusAllArtifact | undefined {
|
|
216
|
+
const list = artifacts ?? [];
|
|
217
|
+
if (applyTracks != null) return list.find((a) => a.outputPath === applyTracks);
|
|
218
|
+
return list.find((a) => a.id === "tasks");
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// ── Canonical artifact order ────────────────────────────────────────────────
|
|
222
|
+
|
|
223
|
+
const CANONICAL_ARTIFACT_ORDER = ["proposal", "design", "specs", "tasks"] as const;
|
|
224
|
+
|
|
225
|
+
/** `proposal, design, specs, tasks` (those present), then the rest in CLI order. */
|
|
226
|
+
export function canonicalArtifactOrder<T extends { id: string }>(artifacts: T[]): T[] {
|
|
227
|
+
const rank = (id: string) => {
|
|
228
|
+
const i = (CANONICAL_ARTIFACT_ORDER as readonly string[]).indexOf(id);
|
|
229
|
+
return i === -1 ? CANONICAL_ARTIFACT_ORDER.length : i;
|
|
230
|
+
};
|
|
231
|
+
// Array.prototype.sort is stable: equal ranks keep CLI order.
|
|
232
|
+
return [...artifacts].sort((a, b) => rank(a.id) - rank(b.id));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ── Unsupported-CLI cache ───────────────────────────────────────────────────
|
|
236
|
+
|
|
237
|
+
export interface StatusAllSupportCache {
|
|
238
|
+
/**
|
|
239
|
+
* True when `--all` is known not to work for the CLI installation currently
|
|
240
|
+
* resolved to `version` (null = unresolvable package.json). With a null
|
|
241
|
+
* version the verdict is cached for the process but re-evaluated on every
|
|
242
|
+
* force refresh. A changed version clears the verdict (upgrade picked up).
|
|
243
|
+
*/
|
|
244
|
+
isKnownUnsupported(version: string | null, force: boolean): boolean;
|
|
245
|
+
markUnsupported(version: string | null): void;
|
|
246
|
+
/** A successful `--all` call clears any verdict (a re-evaluating force refresh can flip it back). */
|
|
247
|
+
markSupported(): void;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function createStatusAllSupportCache(): StatusAllSupportCache {
|
|
251
|
+
let marked = false;
|
|
252
|
+
let markedVersion: string | null = null;
|
|
253
|
+
return {
|
|
254
|
+
isKnownUnsupported(version, force) {
|
|
255
|
+
if (!marked) return false;
|
|
256
|
+
if (version === null) {
|
|
257
|
+
if (markedVersion !== null) {
|
|
258
|
+
marked = false; // was resolvable, no longer is — re-evaluate
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
return !force;
|
|
262
|
+
}
|
|
263
|
+
if (version !== markedVersion) {
|
|
264
|
+
marked = false; // upgraded/downgraded — try `--all` again
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
return true;
|
|
268
|
+
},
|
|
269
|
+
markUnsupported(version) {
|
|
270
|
+
marked = true;
|
|
271
|
+
markedVersion = version;
|
|
272
|
+
},
|
|
273
|
+
markSupported() {
|
|
274
|
+
marked = false;
|
|
275
|
+
markedVersion = null;
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ── CLI-path → server-path mapping & tracked extras ─────────────────────────
|
|
281
|
+
|
|
282
|
+
/** Extra tracked paths for one change, already mapped onto the server's `openspec/` dir. */
|
|
283
|
+
export interface TrackedExtras {
|
|
284
|
+
/** Files and directories to stat. */
|
|
285
|
+
files: string[];
|
|
286
|
+
/** Directory prefixes of glob outputs; the probe also tracks every directory beneath them. */
|
|
287
|
+
globPrefixes: string[];
|
|
288
|
+
/** Glob/literal outputs as paths relative to the change dir (forward slashes), for the watcher filter. */
|
|
289
|
+
outputs: string[];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Map a CLI-emitted absolute path onto the server's canonical `openspec/` dir.
|
|
294
|
+
* The CLI path is relativized against `root.path` exactly as emitted; a path
|
|
295
|
+
* that escapes the root, or does not live under `openspec/`, yields `null`.
|
|
296
|
+
*/
|
|
297
|
+
export function mapCliPath(
|
|
298
|
+
cliPath: string,
|
|
299
|
+
rootPath: string,
|
|
300
|
+
canonicalOpenspecDir: string,
|
|
301
|
+
): string | null {
|
|
302
|
+
if (typeof cliPath !== "string" || cliPath.length === 0) return null;
|
|
303
|
+
const rel = path.relative(rootPath, cliPath);
|
|
304
|
+
if (!rel || path.isAbsolute(rel)) return null;
|
|
305
|
+
const segments = rel.split(/[\\/]+/).filter(Boolean);
|
|
306
|
+
if (segments.length < 2 || segments[0] !== "openspec" || segments.includes("..")) return null;
|
|
307
|
+
return path.join(canonicalOpenspecDir, ...segments.slice(1));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const GLOB_CHARS = /[*?{]/;
|
|
311
|
+
|
|
312
|
+
/** Output pattern relative to the change dir (forward slashes), or null when unusable. */
|
|
313
|
+
function relativeOutputPattern(ap: StatusAllArtifactPaths, changeRoot: string | undefined): string | null {
|
|
314
|
+
let rel = ap.outputPath;
|
|
315
|
+
if (!rel && ap.resolvedOutputPath && changeRoot) {
|
|
316
|
+
rel = path.relative(changeRoot, ap.resolvedOutputPath);
|
|
317
|
+
}
|
|
318
|
+
if (!rel || path.isAbsolute(rel)) return null;
|
|
319
|
+
const norm = rel.split(/[\\/]+/).filter(Boolean);
|
|
320
|
+
if (norm.length === 0 || norm.includes("..")) return null;
|
|
321
|
+
return norm.join("/");
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Tracked extras of one change entry (see "Cwd-level change-detection gate"). */
|
|
325
|
+
export function computeTrackedExtras(
|
|
326
|
+
entry: StatusAllEntry,
|
|
327
|
+
rootPath: string,
|
|
328
|
+
canonicalOpenspecDir: string,
|
|
329
|
+
changeDir: string,
|
|
330
|
+
): TrackedExtras {
|
|
331
|
+
const files = new Set<string>();
|
|
332
|
+
const globPrefixes = new Set<string>();
|
|
333
|
+
const outputs = new Set<string>();
|
|
334
|
+
const addWithParent = (p: string) => {
|
|
335
|
+
files.add(p);
|
|
336
|
+
files.add(path.dirname(p));
|
|
337
|
+
};
|
|
338
|
+
for (const ap of Object.values(entry.artifactPaths ?? {})) {
|
|
339
|
+
for (const existing of ap.existingOutputPaths ?? []) {
|
|
340
|
+
const mapped = mapCliPath(existing, rootPath, canonicalOpenspecDir);
|
|
341
|
+
if (mapped) addWithParent(mapped);
|
|
342
|
+
}
|
|
343
|
+
const pattern = relativeOutputPattern(ap, entry.changeRoot);
|
|
344
|
+
if (!pattern) continue;
|
|
345
|
+
outputs.add(pattern);
|
|
346
|
+
const segments = pattern.split("/");
|
|
347
|
+
const globIdx = segments.findIndex((s) => GLOB_CHARS.test(s));
|
|
348
|
+
if (globIdx === -1) {
|
|
349
|
+
addWithParent(path.join(changeDir, ...segments));
|
|
350
|
+
} else {
|
|
351
|
+
const prefix = path.join(changeDir, ...segments.slice(0, globIdx));
|
|
352
|
+
globPrefixes.add(prefix);
|
|
353
|
+
files.add(prefix);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return { files: [...files], globPrefixes: [...globPrefixes], outputs: [...outputs] };
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** Does a change-relative path (forward slashes) match a recorded output pattern? */
|
|
360
|
+
export function matchesOutputPattern(relPath: string, pattern: string): boolean {
|
|
361
|
+
const norm = relPath.replace(/\\/g, "/");
|
|
362
|
+
if (!GLOB_CHARS.test(pattern)) return norm === pattern;
|
|
363
|
+
// Minimal glob: `**` spans segments, `*` stays inside one segment.
|
|
364
|
+
// Only `*`, `**` and `?` are globs here; every other regex metacharacter
|
|
365
|
+
// (incl. `{}` / `[]`, brace expansion is not implemented) matches literally.
|
|
366
|
+
const re = pattern
|
|
367
|
+
.split("/")
|
|
368
|
+
.map((seg) => (seg === "**" ? ".*" : seg.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]")))
|
|
369
|
+
.join("/")
|
|
370
|
+
.replace(/\/\.\*\//g, "/(?:.*/)?");
|
|
371
|
+
try {
|
|
372
|
+
return new RegExp(`^${re}$`).test(norm);
|
|
373
|
+
} catch {
|
|
374
|
+
return false; // a malformed pattern never throws into an fs.watch callback
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ── Bounded concurrency ─────────────────────────────────────────────────────
|
|
379
|
+
|
|
380
|
+
/** `Promise.all(items.map(fn))` with at most `limit` calls in flight; order preserved. */
|
|
381
|
+
export async function mapLimit<T, R>(items: readonly T[], limit: number, fn: (item: T, index: number) => Promise<R>): Promise<R[]> {
|
|
382
|
+
const out = new Array<R>(items.length);
|
|
383
|
+
let next = 0;
|
|
384
|
+
const worker = async () => {
|
|
385
|
+
while (true) {
|
|
386
|
+
const i = next++;
|
|
387
|
+
if (i >= items.length) return;
|
|
388
|
+
out[i] = await fn(items[i], i);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
await Promise.all(Array.from({ length: Math.max(1, Math.min(limit, items.length)) }, worker));
|
|
392
|
+
return out;
|
|
393
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire shape of the `operate_required` refusal (403) that `operate`-gated routes
|
|
3
|
+
* (`/api/vault*`, `/api/services*` mutations) send. Pure types + constants: the
|
|
4
|
+
* server builds the body, the client reads `remedies`.
|
|
5
|
+
*
|
|
6
|
+
* Disclosure rule: the body has exactly these five keys and nothing about hosts,
|
|
7
|
+
* networks, devices or vault posture. `sign-in` is the only configuration fact it
|
|
8
|
+
* reveals (a usable login method exists). `request-access` reveals only what the
|
|
9
|
+
* public knock route already tells the same caller (Host admitted? on-link?).
|
|
10
|
+
* See change: surface-operate-required-remedy, add-request-access-remedy.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** What the refused caller can do about it. A later change MAY add values. */
|
|
14
|
+
export type OperateRemedy = "use-host" | "re-pair" | "request-access" | "sign-in";
|
|
15
|
+
|
|
16
|
+
/** Canonical relative order of the remedies defined here. */
|
|
17
|
+
export const OPERATE_REMEDY_ORDER: readonly OperateRemedy[] = ["use-host", "re-pair", "request-access", "sign-in"];
|
|
18
|
+
|
|
19
|
+
/** Why the caller was refused. */
|
|
20
|
+
export type OperateRequiredReason = "no-credential" | "tier-too-low";
|
|
21
|
+
|
|
22
|
+
/** Body of an `operate_required` 403. Exactly these keys. */
|
|
23
|
+
export interface OperateRequiredBody {
|
|
24
|
+
success: false;
|
|
25
|
+
error: "operate_required";
|
|
26
|
+
message: string;
|
|
27
|
+
reason: OperateRequiredReason;
|
|
28
|
+
remedies: OperateRemedy[];
|
|
29
|
+
}
|