@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,20 +2,29 @@
|
|
|
2
2
|
* File and directory browse REST API routes (localhost-only).
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { randomBytes } from "node:crypto";
|
|
6
|
-
import { createReadStream } from "node:fs";
|
|
5
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
6
|
+
import { createReadStream, constants as fsConstants } from "node:fs";
|
|
7
7
|
import fs from "node:fs/promises";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
9
|
import os from "node:os";
|
|
10
10
|
import path from "node:path";
|
|
11
|
+
import type { CwdHoldDecision } from "@blackbelt-technology/dashboard-plugin-runtime/server";
|
|
11
12
|
import { loadConfig } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
12
|
-
import {
|
|
13
|
+
import { containmentAllows } from "@blackbelt-technology/pi-dashboard-shared/containment-guard.js";
|
|
14
|
+
import {
|
|
15
|
+
admissionAllows,
|
|
16
|
+
issueHeldAdmission,
|
|
17
|
+
releaseAdmission,
|
|
18
|
+
} from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
|
|
19
|
+
import { DIGEST_CEILING_BYTES, fileKind } from "@blackbelt-technology/pi-dashboard-shared/file-kind.js";
|
|
20
|
+
import { repairAsciiDoc } from "@blackbelt-technology/pi-dashboard-shared/markup-repair/asciidoc.js";
|
|
21
|
+
import { realpathAsync } from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
|
|
22
|
+
import { ASCIIDOC_PROFILE, keepColWidthStyleOnly } from "@blackbelt-technology/pi-dashboard-shared/sanitize-profiles.js";
|
|
13
23
|
import type { ApiResponse } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
14
24
|
import type { FastifyInstance } from "fastify";
|
|
15
|
-
import { type DenialRemedy, evaluateContainment } from "../access/containment-gate.js";
|
|
25
|
+
import { type DenialRemedy, decidePassive, evaluateContainment } from "../access/containment-gate.js";
|
|
26
|
+
import { resolveCwdVerdict } from "../access/cwd-verdict.js";
|
|
16
27
|
import { type HoldTarget, holdDenial } from "../access/denial-hold.js";
|
|
17
|
-
import { isUngrantableSubject } from "../access/forbidden-subjects.js";
|
|
18
|
-
import { canDiscloseAccessPosture } from "../auth/localhost-guard.js";
|
|
19
28
|
import {
|
|
20
29
|
assertRegularFile,
|
|
21
30
|
openVerifiedRegularFile,
|
|
@@ -23,11 +32,32 @@ import {
|
|
|
23
32
|
readFileVerifiedUtf8,
|
|
24
33
|
VerifiedReadRefused,
|
|
25
34
|
} from "../access/verified-read.js";
|
|
26
|
-
import {
|
|
35
|
+
import type { LocalTrustContext } from "../auth/local-proof.js";
|
|
36
|
+
import { canDiscloseAccessPosture, isLocallyTrusted } from "../auth/localhost-guard.js";
|
|
37
|
+
import {
|
|
38
|
+
CreateProjectError,
|
|
39
|
+
type CreateProjectReason,
|
|
40
|
+
classifyPaths,
|
|
41
|
+
createDirectory,
|
|
42
|
+
createProjectDirectory,
|
|
43
|
+
listDirectories,
|
|
44
|
+
parseFlagsQuery,
|
|
45
|
+
} from "../browse.js";
|
|
27
46
|
import { isImageUnderArtifactRoot } from "../lib/artifact-roots.js";
|
|
47
|
+
import {
|
|
48
|
+
BROWSE_OUTSIDE_ROOTS_ERROR,
|
|
49
|
+
type BrowseRootSources,
|
|
50
|
+
type BrowseRoots,
|
|
51
|
+
buildBrowseRootSources,
|
|
52
|
+
isWithinBrowseRoots,
|
|
53
|
+
resolveBrowseRoots,
|
|
54
|
+
} from "../lib/browse-roots.js";
|
|
55
|
+
import { DashboardStateRefused, openStateChecked, readFileStateChecked } from "../lib/dashboard-state-guard.js";
|
|
28
56
|
import { decodeFileUri } from "../lib/decode-file-uri.js";
|
|
29
57
|
import { renderDiagram } from "../lib/diagram-render.js";
|
|
58
|
+
import { createDigestGate, type DigestGate, type DigestLane } from "../lib/digest-gate.js";
|
|
30
59
|
import { EML_SIZE_CAP, loadParsedEml, toParseResult } from "../lib/eml.js";
|
|
60
|
+
import { admitFileCwd, CWD_UNAVAILABLE_FAILURE, cwdAnchors, type GateWire, releaseOnClose } from "../lib/file-cwd-admission.js";
|
|
31
61
|
import { enumerateMdCandidates } from "../lib/md-candidates.js";
|
|
32
62
|
import { extToContentType } from "../lib/mime-types.js";
|
|
33
63
|
import {
|
|
@@ -42,23 +72,31 @@ import {
|
|
|
42
72
|
renderPptx,
|
|
43
73
|
resolveRowLimit,
|
|
44
74
|
} from "../lib/office-preview.js";
|
|
45
|
-
import {
|
|
75
|
+
import { safeRealpath } from "../lib/path-containment.js";
|
|
76
|
+
import { loadPurify } from "../lib/purify.js";
|
|
77
|
+
import { admitRouteCwd, listKnownFolderCwds, type RouteAdmissionDeps } from "../lib/route-admission.js";
|
|
46
78
|
|
|
47
79
|
/**
|
|
48
80
|
* A gate failure. `error` is byte-identical to what the site returned before
|
|
49
81
|
* this change; `reason`/`hint`/`subject`/`denialId` are ADDITIVE (design D7) so
|
|
50
82
|
* the denial can name its remedy and bind a later grant to this refusal (D15).
|
|
51
83
|
* `{ code, error }` stays INTERNAL — callers convert via `denialBody`.
|
|
84
|
+
* `code` is the HTTP status; the wire `code` string lives in `wire`.
|
|
52
85
|
*/
|
|
53
|
-
type GateFailure = { code: number; error: string } & Partial<DenialRemedy>;
|
|
86
|
+
export type GateFailure = { code: number; error: string; wire?: GateWire } & Partial<DenialRemedy>;
|
|
54
87
|
|
|
55
88
|
/**
|
|
56
89
|
* The single conversion from a gate failure to the wire body. Every containment
|
|
57
90
|
* caller uses this so the additive fields cannot drift between sites, and so
|
|
58
91
|
* pre-existing fields stay byte-identical (task 3.2).
|
|
59
92
|
*/
|
|
60
|
-
function denialBody(gate: GateFailure): ApiResponse {
|
|
93
|
+
export function denialBody(gate: GateFailure): ApiResponse {
|
|
61
94
|
const body: Record<string, unknown> = { success: false, error: gate.error };
|
|
95
|
+
if (gate.wire !== undefined) {
|
|
96
|
+
body.code = gate.wire.code;
|
|
97
|
+
if (gate.wire.message !== undefined) body.message = gate.wire.message;
|
|
98
|
+
if (gate.wire.retryAfterMs !== undefined) body.retryAfterMs = gate.wire.retryAfterMs;
|
|
99
|
+
}
|
|
62
100
|
if (gate.reason !== undefined) body.reason = gate.reason;
|
|
63
101
|
if (gate.hint !== undefined) body.hint = gate.hint;
|
|
64
102
|
if (gate.subject !== undefined) body.subject = gate.subject;
|
|
@@ -69,6 +107,18 @@ function denialBody(gate: GateFailure): ApiResponse {
|
|
|
69
107
|
return body as unknown as ApiResponse;
|
|
70
108
|
}
|
|
71
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Reply with a gate failure: the status, `Retry-After: 1` on a 503 (an undecidable
|
|
112
|
+
* cwd admission), and the `denialBody`. Every caller of the file gate helpers uses
|
|
113
|
+
* this so the 503 contract cannot drift between sites. See change: core-file-cwd-admission (D3).
|
|
114
|
+
*/
|
|
115
|
+
export function sendGateFailure(reply: import("fastify").FastifyReply, gate: GateFailure): ApiResponse {
|
|
116
|
+
reply.code(gate.code);
|
|
117
|
+
if (gate.code === 503) reply.header("Retry-After", "1");
|
|
118
|
+
return denialBody(gate);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
import { serializeWrite } from "../lib/file-write-lock.js";
|
|
72
122
|
import { resolveFileMention } from "../lib/resolve-file-mention.js";
|
|
73
123
|
import { isWritableMdTarget } from "../lib/writable-md-target.js";
|
|
74
124
|
import type { PreferencesStore } from "../persistence/preferences-store.js";
|
|
@@ -80,8 +130,26 @@ import {
|
|
|
80
130
|
runOpener,
|
|
81
131
|
systemOpenCapability,
|
|
82
132
|
} from "../system-open-capability.js";
|
|
133
|
+
import { type FileHandlerDeps, registerFileWriteBinaryRoute } from "./file-write-binary-routes.js";
|
|
83
134
|
import type { NetworkGuard } from "./route-deps.js";
|
|
84
135
|
|
|
136
|
+
/** Per-response sandbox for scriptable raw responses. See change: harden-raw-svg-responses. */
|
|
137
|
+
export const RAW_SANDBOX_CSP =
|
|
138
|
+
"sandbox; default-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src data:; frame-ancestors 'self'";
|
|
139
|
+
|
|
140
|
+
const SCRIPTABLE_MEDIA_TYPES = new Set([
|
|
141
|
+
"text/html",
|
|
142
|
+
"image/svg+xml",
|
|
143
|
+
"application/xhtml+xml",
|
|
144
|
+
"application/xml",
|
|
145
|
+
"text/xml",
|
|
146
|
+
]);
|
|
147
|
+
|
|
148
|
+
/** True when a browser would execute script from this `Content-Type` (params/case ignored). */
|
|
149
|
+
export function isScriptableMediaType(contentType: string): boolean {
|
|
150
|
+
return SCRIPTABLE_MEDIA_TYPES.has(contentType.split(";")[0].trim().toLowerCase());
|
|
151
|
+
}
|
|
152
|
+
|
|
85
153
|
// Per-target write serialization. The optimistic mtime check + atomic rename
|
|
86
154
|
// must run as one critical section per file, else two concurrent writes can
|
|
87
155
|
// both read the same mtime, both pass, and the later rename clobbers the earlier
|
|
@@ -97,63 +165,84 @@ function homePiAnchor(): string {
|
|
|
97
165
|
return path.join(os.homedir(), ".pi");
|
|
98
166
|
}
|
|
99
167
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
168
|
+
/**
|
|
169
|
+
* SHA-1 of an open handle, streamed in 1 MiB chunks (abortable between chunks).
|
|
170
|
+
* Returns `null` when the file grew past the digest ceiling while being read, so
|
|
171
|
+
* a hash of an unbounded stream is never reported. SHA-1 is a change detector
|
|
172
|
+
* here, not a security primitive. See change: gate-changed-on-disk-by-content.
|
|
173
|
+
*/
|
|
174
|
+
async function hashHandle(fh: import("node:fs/promises").FileHandle, signal: AbortSignal): Promise<string | null> {
|
|
175
|
+
const hash = createHash("sha1");
|
|
176
|
+
const buf = Buffer.allocUnsafe(1024 * 1024);
|
|
177
|
+
let total = 0;
|
|
178
|
+
for (;;) {
|
|
179
|
+
if (signal.aborted) {
|
|
180
|
+
const e = new Error("aborted");
|
|
181
|
+
e.name = "AbortError";
|
|
182
|
+
throw e;
|
|
183
|
+
}
|
|
184
|
+
const { bytesRead } = await fh.read(buf, 0, buf.length, total);
|
|
185
|
+
if (bytesRead === 0) break;
|
|
186
|
+
total += bytesRead;
|
|
187
|
+
if (total > DIGEST_CEILING_BYTES) return null;
|
|
188
|
+
hash.update(buf.subarray(0, bytesRead));
|
|
189
|
+
}
|
|
190
|
+
return hash.digest("hex");
|
|
112
191
|
}
|
|
113
192
|
|
|
114
193
|
// Resolve + scope-validate a markdown target shared by the write + md-read
|
|
115
|
-
// endpoints. Directory scope (cwd present) requires
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
|
|
194
|
+
// endpoints. Directory scope (cwd present) requires an admitted cwd (shared
|
|
195
|
+
// guard: session, pinned, workspace folder or a worktree / main checkout of a
|
|
196
|
+
// known repository); global scope (cwd absent: undefined, null or "") requires
|
|
197
|
+
// an absolute path. Any other cwd value that is not an absolute string is
|
|
198
|
+
// REFUSED — it never selects the global scope. Returns the resolved abs path
|
|
199
|
+
// plus the guarded `cwd` (undefined in global scope: the no-cwd branch hands the
|
|
200
|
+
// sinks a constant, never the request value), or a GateFailure. Authorization
|
|
201
|
+
// (`isWritableMdTarget`) is applied by callers.
|
|
202
|
+
// See change: directory-settings-page-and-scoped-md-editing, core-file-cwd-admission.
|
|
203
|
+
async function resolveScopedMdPath(
|
|
204
|
+
rawCwd: unknown,
|
|
121
205
|
rawPath: string,
|
|
122
|
-
|
|
123
|
-
): { resolved: string
|
|
124
|
-
if (cwd && !sessionManager.listAll().some((s) => s.cwd === cwd)) {
|
|
125
|
-
return { code: 403, error: "unknown session path" };
|
|
126
|
-
}
|
|
206
|
+
routeAdmission: RouteAdmissionDeps,
|
|
207
|
+
): Promise<{ resolved: string; cwd: string | undefined } | GateFailure> {
|
|
127
208
|
const decoded = decodeFileUri(rawPath);
|
|
128
|
-
if (
|
|
129
|
-
return { code: 400, error: "global scope requires an absolute path" };
|
|
209
|
+
if (rawCwd === undefined || rawCwd === null || rawCwd === "") {
|
|
210
|
+
if (!path.isAbsolute(decoded)) return { code: 400, error: "global scope requires an absolute path" };
|
|
211
|
+
return { resolved: path.resolve(decoded), cwd: undefined };
|
|
212
|
+
}
|
|
213
|
+
const admitted = await admitFileCwd(rawCwd, routeAdmission);
|
|
214
|
+
if (!admitted.ok) return admitted.failure;
|
|
215
|
+
try {
|
|
216
|
+
return { resolved: path.resolve(admitted.cwd, decoded), cwd: admitted.cwd };
|
|
217
|
+
} finally {
|
|
218
|
+
admitted.release();
|
|
130
219
|
}
|
|
131
|
-
return { resolved: cwd ? path.resolve(cwd, decoded) : path.resolve(decoded) };
|
|
132
220
|
}
|
|
133
221
|
|
|
134
222
|
/** Discriminated outcome of an atomic markdown write. */
|
|
135
|
-
type MdWriteOutcome =
|
|
223
|
+
type MdWriteOutcome =
|
|
224
|
+
| { code: 200; mtime: number; size: number; sha1?: string }
|
|
225
|
+
| { code: 404 | 409 | 413 | 500; error: string };
|
|
136
226
|
|
|
137
227
|
/** Parsed + authorized write request, or a {code,error} reply mapping. */
|
|
138
|
-
type MdWritePrep = { resolved: string; content: string; mtime: number } |
|
|
228
|
+
type MdWritePrep = { resolved: string; content: string; mtime: number } | GateFailure;
|
|
139
229
|
|
|
140
230
|
// Parse, scope-validate, and authorize a `POST /api/file/write` body. Keeps the
|
|
141
231
|
// route handler trivial. Authorization is the `isWritableMdTarget` security
|
|
142
232
|
// boundary. See change: directory-settings-page-and-scoped-md-editing.
|
|
143
233
|
async function prepareMdWrite(
|
|
144
234
|
body: { cwd?: unknown; path?: unknown; content?: unknown; mtime?: unknown },
|
|
145
|
-
|
|
235
|
+
routeAdmission: RouteAdmissionDeps,
|
|
146
236
|
): Promise<MdWritePrep> {
|
|
147
|
-
const cwd = typeof body.cwd === "string" && body.cwd ? body.cwd : undefined;
|
|
148
237
|
const rawPath = typeof body.path === "string" ? body.path : "";
|
|
149
238
|
const content = typeof body.content === "string" ? body.content : undefined;
|
|
150
239
|
const mtime = typeof body.mtime === "number" ? body.mtime : undefined;
|
|
151
240
|
if (!rawPath || content === undefined || mtime === undefined) {
|
|
152
241
|
return { code: 400, error: "path, content and mtime are required" };
|
|
153
242
|
}
|
|
154
|
-
const target = resolveScopedMdPath(cwd, rawPath,
|
|
243
|
+
const target = await resolveScopedMdPath(body.cwd, rawPath, routeAdmission);
|
|
155
244
|
if ("code" in target) return target;
|
|
156
|
-
if (!(await isWritableMdTarget(target.resolved, { cwd }))) {
|
|
245
|
+
if (!(await isWritableMdTarget(target.resolved, { cwd: target.cwd }))) {
|
|
157
246
|
return { code: 403, error: "target is not a writable markdown file in scope" };
|
|
158
247
|
}
|
|
159
248
|
return { resolved: target.resolved, content, mtime };
|
|
@@ -190,8 +279,14 @@ async function performAtomicMdWrite(
|
|
|
190
279
|
path.dirname(real),
|
|
191
280
|
`.${path.basename(real)}.${randomBytes(8).toString("hex")}.tmp`,
|
|
192
281
|
);
|
|
282
|
+
// Encode ONCE: the bytes written and the bytes hashed are the same buffer, so
|
|
283
|
+
// the returned `sha1` is exactly what a later `/api/file/digest` reports (the
|
|
284
|
+
// editor pane rebaselines from it so its own Save never raises the
|
|
285
|
+
// changed-on-disk banner). See change: gate-changed-on-disk-by-content (D3).
|
|
286
|
+
const bytes = Buffer.from(content, "utf8");
|
|
287
|
+
if (bytes.length > DIGEST_CEILING_BYTES) return { code: 413, error: "content too large" };
|
|
193
288
|
try {
|
|
194
|
-
await fs.writeFile(tmpPath,
|
|
289
|
+
await fs.writeFile(tmpPath, bytes, { flag: "wx" });
|
|
195
290
|
// Preserve the original file mode so a private (e.g. 0600) instruction file
|
|
196
291
|
// is not widened to the umask default on replace.
|
|
197
292
|
await fs.chmod(tmpPath, current.mode & 0o777);
|
|
@@ -201,7 +296,12 @@ async function performAtomicMdWrite(
|
|
|
201
296
|
return { code: 500, error: err instanceof Error ? err.message : "write failed" };
|
|
202
297
|
}
|
|
203
298
|
const after = await fs.stat(real);
|
|
204
|
-
return {
|
|
299
|
+
return {
|
|
300
|
+
code: 200,
|
|
301
|
+
mtime: after.mtimeMs,
|
|
302
|
+
size: bytes.length,
|
|
303
|
+
sha1: createHash("sha1").update(bytes).digest("hex"),
|
|
304
|
+
};
|
|
205
305
|
}
|
|
206
306
|
|
|
207
307
|
// Lazy asciidoctor singleton. First call cost ~Opal init; the server is
|
|
@@ -219,28 +319,88 @@ function getAsciidoctor(): any {
|
|
|
219
319
|
return asciidoctorInstance;
|
|
220
320
|
}
|
|
221
321
|
|
|
322
|
+
interface AdocWarning {
|
|
323
|
+
text: string;
|
|
324
|
+
line: number | null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* One synchronous convert with asciidoctor's global logger swapped for an in-memory
|
|
329
|
+
* one, restored in `finally`. Synchronous ⇒ no cross-request interleaving.
|
|
330
|
+
* See change: add-md-adoc-markup-repair (design D3).
|
|
331
|
+
*/
|
|
332
|
+
function convertAdocCapturingWarnings(source: string): { html: string; warnings: AdocWarning[] } {
|
|
333
|
+
const adoc = getAsciidoctor();
|
|
334
|
+
const { LoggerManager, MemoryLogger } = adoc;
|
|
335
|
+
const prev = LoggerManager.getLogger();
|
|
336
|
+
const memory = MemoryLogger.create();
|
|
337
|
+
LoggerManager.setLogger(memory);
|
|
338
|
+
try {
|
|
339
|
+
// `showtitle`: embedded output otherwise drops the `= Title` doctitle.
|
|
340
|
+
const html = adoc.convert(source, { safe: "secure", standalone: false, attributes: { showtitle: "" } });
|
|
341
|
+
const warnings: AdocWarning[] = memory.getMessages().map((m: any) => {
|
|
342
|
+
const loc = m.getSourceLocation?.();
|
|
343
|
+
const line = loc?.getLineNumber?.();
|
|
344
|
+
return { text: String(m.getText?.() ?? ""), line: typeof line === "number" ? line : null };
|
|
345
|
+
});
|
|
346
|
+
return { html: String(html), warnings };
|
|
347
|
+
} finally {
|
|
348
|
+
LoggerManager.setLogger(prev);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// asciidoctor `safe:"secure"` still passes raw HTML through (`+++…+++`,
|
|
353
|
+
// `pass:[…]`), so the converted HTML is sanitized with DOMPurify before it is
|
|
354
|
+
// returned. `style` survives only as asciidoctor's own `<col style="width: N%;">`
|
|
355
|
+
// column widths (`keepColWidthStyleOnly`, shared with the client policy in
|
|
356
|
+
// sanitize-profiles.ts). See change: sanitize-untrusted-rendered-content.
|
|
357
|
+
|
|
358
|
+
async function sanitizeAdocHtml(html: string): Promise<string> {
|
|
359
|
+
const purify = await loadPurify();
|
|
360
|
+
// Defense in depth: `loadPurify` already refuses a DOM-less instance, but a
|
|
361
|
+
// pass-through DOMPurify must never be able to return raw HTML here.
|
|
362
|
+
if (purify.isSupported !== true) throw new Error("DOMPurify unavailable: cannot sanitize AsciiDoc");
|
|
363
|
+
// Hooks are global to the shared instance; add → sanitize → remove contains
|
|
364
|
+
// no `await`, so it cannot interleave with another sanitize call.
|
|
365
|
+
purify.addHook("uponSanitizeAttribute", keepColWidthStyleOnly);
|
|
366
|
+
try {
|
|
367
|
+
return purify.sanitize(html, ASCIIDOC_PROFILE);
|
|
368
|
+
} finally {
|
|
369
|
+
purify.removeHook("uponSanitizeAttribute", keepColWidthStyleOnly);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
222
373
|
// Shared anti-traversal gate for the EML routes — the SAME check as
|
|
223
374
|
// `/api/file/raw` (known session + `isAllowed` against the cwd anchor), factored
|
|
224
375
|
// so both new routes CALL it rather than re-implementing the containment logic
|
|
225
376
|
// (design D5). Returns the resolved abs path or a {code,error} reply mapping.
|
|
226
|
-
async function gateFilePath(
|
|
377
|
+
export async function gateFilePath(
|
|
227
378
|
cwd: string | undefined,
|
|
228
379
|
relPath: string | undefined,
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
|
|
380
|
+
routeAdmission: RouteAdmissionDeps,
|
|
381
|
+
/**
|
|
382
|
+
* `disclosure`: the caller may see `promptOutcome` (`canDiscloseAccessPosture`).
|
|
383
|
+
* `quiet`: record no denial and raise no prompt (a per-request re-check on a static preview).
|
|
384
|
+
*/
|
|
385
|
+
opts: { allowGrant?: boolean; disclosure?: boolean; quiet?: boolean } = {},
|
|
232
386
|
): Promise<{ resolved: string; viaGrant: boolean } | GateFailure> {
|
|
233
387
|
if (!cwd || !relPath) return { code: 400, error: "cwd and path parameters required" };
|
|
234
|
-
|
|
235
|
-
|
|
388
|
+
const admitted = await admitFileCwd(cwd, routeAdmission);
|
|
389
|
+
if (!admitted.ok) return admitted.failure;
|
|
390
|
+
let resolved: string;
|
|
391
|
+
let decision: Awaited<ReturnType<typeof evaluateContainment>>;
|
|
392
|
+
try {
|
|
393
|
+
resolved = path.resolve(admitted.cwd, relPath);
|
|
394
|
+
decision = await evaluateContainment(resolved, cwdAnchors(admitted), {
|
|
395
|
+
site: "file-routes:gateFilePath",
|
|
396
|
+
allowGrant: opts.allowGrant,
|
|
397
|
+
disclosure: opts.disclosure,
|
|
398
|
+
...(opts.quiet ? { quiet: true } : {}),
|
|
399
|
+
});
|
|
400
|
+
} finally {
|
|
401
|
+
admitted.release();
|
|
236
402
|
}
|
|
237
|
-
|
|
238
|
-
const decision = await evaluateContainment(resolved, [cwd], {
|
|
239
|
-
site: "file-routes:gateFilePath",
|
|
240
|
-
allowGrant: opts.allowGrant,
|
|
241
|
-
disclosure: opts.disclosure,
|
|
242
|
-
});
|
|
243
|
-
if (!decision.allowed) {
|
|
403
|
+
if (!containmentAllows(decision, resolved)) {
|
|
244
404
|
return { code: 403, error: "path outside working directory", ...decision.remedy };
|
|
245
405
|
}
|
|
246
406
|
// `viaGrant` MUST be propagated: `assertRegularFile` and the handle-verified
|
|
@@ -251,6 +411,64 @@ async function gateFilePath(
|
|
|
251
411
|
return { resolved, viaGrant: decision.viaGrant };
|
|
252
412
|
}
|
|
253
413
|
|
|
414
|
+
/**
|
|
415
|
+
* The `GET /api/file` read gate, factored so `GET /api/file/digest` calls the
|
|
416
|
+
* SAME code rather than a copy (spec: file-read-containment). decode → known
|
|
417
|
+
* session → containment against `[cwd, ~/.pi]` (with the live request so an
|
|
418
|
+
* eligible miss may be held for the operator) → `{ resolved, viaGrant }` or a
|
|
419
|
+
* `GateFailure` whose `code`/`error`/remedy are exactly what `/api/file` has
|
|
420
|
+
* always answered. `quiet` is the digest's background mode (no denial recorded,
|
|
421
|
+
* never held). See change: gate-changed-on-disk-by-content (D4).
|
|
422
|
+
*/
|
|
423
|
+
async function gateReadPath(
|
|
424
|
+
cwd: string | undefined,
|
|
425
|
+
rawPath: string | undefined,
|
|
426
|
+
req: {
|
|
427
|
+
routeAdmission: RouteAdmissionDeps;
|
|
428
|
+
request: import("fastify").FastifyRequest;
|
|
429
|
+
reply: import("fastify").FastifyReply;
|
|
430
|
+
quiet?: boolean;
|
|
431
|
+
},
|
|
432
|
+
): Promise<{ resolved: string; viaGrant: boolean; relPath: string } | GateFailure> {
|
|
433
|
+
const relPath = rawPath ? decodeFileUri(rawPath) : rawPath;
|
|
434
|
+
if (!cwd || !relPath) return { code: 400, error: "cwd and path parameters required" };
|
|
435
|
+
const admitted = await admitFileCwd(cwd, req.routeAdmission);
|
|
436
|
+
if (!admitted.ok) return admitted.failure;
|
|
437
|
+
let resolved: string;
|
|
438
|
+
let readDecision: Awaited<ReturnType<typeof evaluateContainment>>;
|
|
439
|
+
try {
|
|
440
|
+
resolved = path.resolve(admitted.cwd, relPath);
|
|
441
|
+
// Anchors include the fixed `~/.pi` allowlist so a resolved `~/.pi/…`
|
|
442
|
+
// mention (from `/api/file/resolve-mention`) previews without a 403 (D7).
|
|
443
|
+
readDecision = await evaluateContainment(resolved, [...cwdAnchors(admitted), homePiAnchor()], {
|
|
444
|
+
site: "file-routes:read",
|
|
445
|
+
...(req.quiet ? { quiet: true } : { hold: { request: req.request, reply: req.reply } }),
|
|
446
|
+
disclosure: canDiscloseAccessPosture(req.request),
|
|
447
|
+
session: admitted.cwd,
|
|
448
|
+
// Polymorphic: this route serves files AND directories, so the remedy
|
|
449
|
+
// must name whichever the target is (task 4.5 round 2, B1).
|
|
450
|
+
subjectKind: "auto",
|
|
451
|
+
});
|
|
452
|
+
} finally {
|
|
453
|
+
admitted.release();
|
|
454
|
+
}
|
|
455
|
+
if (!containmentAllows(readDecision, resolved)) {
|
|
456
|
+
return { code: 403, error: "path outside working directory", ...readDecision.remedy };
|
|
457
|
+
}
|
|
458
|
+
return { resolved, viaGrant: readDecision.viaGrant, relPath };
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const CREATE_PROJECT_STATUS: Record<CreateProjectReason, number> = {
|
|
462
|
+
invalid_name: 400,
|
|
463
|
+
reserved_name: 400,
|
|
464
|
+
too_long: 400,
|
|
465
|
+
outside_root: 400,
|
|
466
|
+
not_a_directory: 409,
|
|
467
|
+
root_not_a_directory: 409,
|
|
468
|
+
home_missing: 500,
|
|
469
|
+
fs_error: 500,
|
|
470
|
+
};
|
|
471
|
+
|
|
254
472
|
export function registerFileRoutes(
|
|
255
473
|
fastify: FastifyInstance,
|
|
256
474
|
deps: {
|
|
@@ -269,15 +487,42 @@ export function registerFileRoutes(
|
|
|
269
487
|
run?: (cmd: string, args: string[]) => void;
|
|
270
488
|
platform?: NodeJS.Platform;
|
|
271
489
|
};
|
|
490
|
+
// Hash-concurrency gate for `GET /api/file/digest` (change:
|
|
491
|
+
// gate-changed-on-disk-by-content, D4). Injectable so tests observe slots.
|
|
492
|
+
digestGate?: DigestGate;
|
|
493
|
+
// Plugin file-handler registry/validator seams for `POST /api/file/write-binary`
|
|
494
|
+
// (change: add-editor-pane-file-handlers). Absent → every handler save is refused (403).
|
|
495
|
+
fileHandlers?: FileHandlerDeps;
|
|
496
|
+
// Browse confinement (change: harden-server-capability-bounds, D1/D2).
|
|
497
|
+
// `localTrust`: strict-mode context for `isLocallyTrusted`. `browseRootSources`:
|
|
498
|
+
// the two root sources only server.ts can read (worktree-init trust roots and
|
|
499
|
+
// project-scope access grants); pinned dirs, session cwds and workspace
|
|
500
|
+
// folders come from `preferencesStore` / `sessionManager`.
|
|
501
|
+
localTrust?: LocalTrustContext;
|
|
502
|
+
browseRootSources?: Pick<BrowseRootSources, "worktreeRoots" | "projectGrants">;
|
|
503
|
+
/** `browse.confineRemote` (default true). `false` = a remote caller browses like a local one. */
|
|
504
|
+
browseConfineRemote?: boolean;
|
|
505
|
+
/**
|
|
506
|
+
* Shared cwd admission (change: core-file-cwd-admission, D1): `knownCwds` is the live known-folder
|
|
507
|
+
* set (sessions ∪ pins ∪ workspace folders), `admitOptions` the host logger + test seams. Absent →
|
|
508
|
+
* the known set of this registrar's own `sessionManager` + `preferencesStore`.
|
|
509
|
+
*/
|
|
510
|
+
routeAdmission?: RouteAdmissionDeps;
|
|
272
511
|
},
|
|
273
512
|
) {
|
|
274
513
|
const { sessionManager, preferencesStore, networkGuard } = deps;
|
|
514
|
+
const routeAdmission: RouteAdmissionDeps = {
|
|
515
|
+
...deps.routeAdmission,
|
|
516
|
+
knownCwds: deps.routeAdmission?.knownCwds ?? (() => listKnownFolderCwds({ sessionManager, preferencesStore })),
|
|
517
|
+
};
|
|
518
|
+
registerFileWriteBinaryRoute(fastify, { sessionManager, networkGuard, fileHandlers: deps.fileHandlers, routeAdmission });
|
|
275
519
|
const systemOpenCapable = deps.systemOpen?.capable ?? systemOpenCapability;
|
|
276
520
|
const systemOpenRun = deps.systemOpen?.run ?? runOpener;
|
|
277
521
|
const systemOpenPlatform = deps.systemOpen?.platform ?? process.platform;
|
|
278
522
|
const officeCaps = deps.officeCaps ?? OFFICE_CAPS;
|
|
279
523
|
const docxRenderMode = deps.docxRenderMode ?? "auto";
|
|
280
524
|
const docxPdfEngine = deps.docxPdfEngine ?? createDefaultDocxPdfEngine();
|
|
525
|
+
const digestGate = deps.digestGate ?? createDigestGate(2);
|
|
281
526
|
|
|
282
527
|
// Shared office-file gate (change: render-office-previews). Reuses the
|
|
283
528
|
// `/api/file/raw` anti-traversal posture (known cwd + containment) and adds
|
|
@@ -297,12 +542,20 @@ export function registerFileRoutes(
|
|
|
297
542
|
if (!cwd || !relPath) return { code: 400, error: "cwd and path parameters required" };
|
|
298
543
|
const ext = path.extname(relPath).toLowerCase();
|
|
299
544
|
if (!allowedExts.includes(ext)) return { code: 400, error: "renderer not supported for extension" };
|
|
300
|
-
|
|
301
|
-
|
|
545
|
+
const admitted = await admitFileCwd(cwd, routeAdmission);
|
|
546
|
+
if (!admitted.ok) return admitted.failure;
|
|
547
|
+
let resolved: string;
|
|
548
|
+
let decision: Awaited<ReturnType<typeof evaluateContainment>>;
|
|
549
|
+
try {
|
|
550
|
+
resolved = path.resolve(admitted.cwd, relPath);
|
|
551
|
+
decision = await evaluateContainment(resolved, cwdAnchors(admitted), {
|
|
552
|
+
site: "file-routes:gateOfficeFile",
|
|
553
|
+
disclosure,
|
|
554
|
+
});
|
|
555
|
+
} finally {
|
|
556
|
+
admitted.release();
|
|
302
557
|
}
|
|
303
|
-
|
|
304
|
-
const decision = await evaluateContainment(resolved, [cwd], { site: "file-routes:gateOfficeFile", disclosure });
|
|
305
|
-
if (!decision.allowed) {
|
|
558
|
+
if (!containmentAllows(decision, resolved)) {
|
|
306
559
|
return { code: 403, error: "path outside working directory", ...decision.remedy };
|
|
307
560
|
}
|
|
308
561
|
let stat: import("node:fs").Stats;
|
|
@@ -330,6 +583,29 @@ export function registerFileRoutes(
|
|
|
330
583
|
return { resolved, ext, stat, viaGrant: decision.viaGrant };
|
|
331
584
|
}
|
|
332
585
|
|
|
586
|
+
// Browse confinement applies ONLY to requests that are not genuinely local
|
|
587
|
+
// (tunnel, LAN, relayed loopback). Returns the shared-root set to enforce, or
|
|
588
|
+
// `null` for a local request (unrestricted picker). Roots are recomputed per
|
|
589
|
+
// request so a pin / unpin / grant applies immediately.
|
|
590
|
+
// See change: harden-server-capability-bounds (D1, D2).
|
|
591
|
+
const browseRootSources = buildBrowseRootSources({
|
|
592
|
+
preferencesStore,
|
|
593
|
+
sessionManager,
|
|
594
|
+
worktreeRoots: deps.browseRootSources?.worktreeRoots,
|
|
595
|
+
projectGrants: deps.browseRootSources?.projectGrants,
|
|
596
|
+
});
|
|
597
|
+
async function confinedRoots(request: { ip: string; headers: Record<string, unknown> }): Promise<BrowseRoots | null> {
|
|
598
|
+
if (deps.browseConfineRemote === false) return null;
|
|
599
|
+
if (isLocallyTrusted({ ip: request.ip, headers: request.headers }, deps.localTrust)) return null;
|
|
600
|
+
return resolveBrowseRoots(browseRootSources);
|
|
601
|
+
}
|
|
602
|
+
const refuseOutsideRoots = (reply: { code(n: number): unknown }, route: string, requested: string) => {
|
|
603
|
+
// JSON.stringify: the path is caller-controlled, so a newline must not forge a log line.
|
|
604
|
+
console.warn(`[browse] refused ${route}: ${JSON.stringify(requested)} is outside the shared roots`);
|
|
605
|
+
reply.code(403);
|
|
606
|
+
return { success: false, error: BROWSE_OUTSIDE_ROOTS_ERROR } satisfies ApiResponse;
|
|
607
|
+
};
|
|
608
|
+
|
|
333
609
|
// Directory browse endpoint.
|
|
334
610
|
// `detect=1` opts into eager `.git` / `.pi` classification on every entry
|
|
335
611
|
// (anything other than the literal string `"1"` is treated as falsy).
|
|
@@ -339,13 +615,23 @@ export function registerFileRoutes(
|
|
|
339
615
|
fastify.get<{ Querystring: { path?: string; q?: string; detect?: string } }>(
|
|
340
616
|
"/api/browse",
|
|
341
617
|
{ preHandler: networkGuard },
|
|
342
|
-
async (request) => {
|
|
618
|
+
async (request, reply) => {
|
|
619
|
+
const roots = await confinedRoots(request);
|
|
620
|
+
const requested = request.query.path || undefined;
|
|
621
|
+
if (roots && requested && !(await isWithinBrowseRoots(requested, roots))) {
|
|
622
|
+
return refuseOutsideRoots(reply, "GET /api/browse", requested);
|
|
623
|
+
}
|
|
343
624
|
try {
|
|
344
625
|
const result = await listDirectories(
|
|
345
|
-
|
|
626
|
+
requested,
|
|
346
627
|
request.query.q || undefined,
|
|
347
628
|
{ detect: request.query.detect === "1" },
|
|
348
629
|
);
|
|
630
|
+
if (roots) {
|
|
631
|
+
result.confined = true;
|
|
632
|
+
// Never offer a `..` row that leads to a refused directory.
|
|
633
|
+
if (result.parent && !(await isWithinBrowseRoots(result.parent, roots))) result.parent = null;
|
|
634
|
+
}
|
|
349
635
|
return { success: true, data: result } satisfies ApiResponse;
|
|
350
636
|
} catch {
|
|
351
637
|
return { success: false, error: "directory not found" } satisfies ApiResponse;
|
|
@@ -368,6 +654,12 @@ export function registerFileRoutes(
|
|
|
368
654
|
reply.code(400);
|
|
369
655
|
return { success: false, error: parsed.error } satisfies ApiResponse;
|
|
370
656
|
}
|
|
657
|
+
const roots = await confinedRoots(request);
|
|
658
|
+
if (roots) {
|
|
659
|
+
for (const p of parsed.paths) {
|
|
660
|
+
if (!(await isWithinBrowseRoots(p, roots))) return refuseOutsideRoots(reply, "GET /api/browse/flags", p);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
371
663
|
const flags = await classifyPaths(parsed.paths);
|
|
372
664
|
return { success: true, data: { flags } } satisfies ApiResponse;
|
|
373
665
|
},
|
|
@@ -381,6 +673,11 @@ export function registerFileRoutes(
|
|
|
381
673
|
const body = request.body ?? {};
|
|
382
674
|
const parent = typeof body.parent === "string" ? body.parent : "";
|
|
383
675
|
const name = typeof body.name === "string" ? body.name : "";
|
|
676
|
+
// A remote caller may create only inside the shared roots; checked before any fs write.
|
|
677
|
+
const roots = await confinedRoots(request);
|
|
678
|
+
if (roots && parent && !(await isWithinBrowseRoots(parent, roots))) {
|
|
679
|
+
return refuseOutsideRoots(reply, "POST /api/browse/mkdir", parent);
|
|
680
|
+
}
|
|
384
681
|
try {
|
|
385
682
|
const newPath = await createDirectory(parent, name);
|
|
386
683
|
return { success: true, data: { path: newPath } } satisfies ApiResponse;
|
|
@@ -397,40 +694,43 @@ export function registerFileRoutes(
|
|
|
397
694
|
},
|
|
398
695
|
);
|
|
399
696
|
|
|
697
|
+
// First-run project create: `<home>/Projects/<name>`, create-or-reuse, realpath-contained.
|
|
698
|
+
// Server-side validation only; `reason` is a stable machine code for the client.
|
|
699
|
+
// See change: streamline-first-run (design D4).
|
|
700
|
+
fastify.post<{ Body: { name?: unknown } }>(
|
|
701
|
+
"/api/browse/create-project",
|
|
702
|
+
{ preHandler: networkGuard },
|
|
703
|
+
async (request, reply) => {
|
|
704
|
+
const name = (request.body ?? {}).name;
|
|
705
|
+
const nameForLog =
|
|
706
|
+
typeof name === "string" ? JSON.stringify(name.slice(0, 64)) : "<non-string>";
|
|
707
|
+
const bytes = typeof name === "string" ? Buffer.byteLength(name, "utf8") : 0;
|
|
708
|
+
try {
|
|
709
|
+
const result = await createProjectDirectory(name);
|
|
710
|
+
console.log(
|
|
711
|
+
`[create-project] ${result.existed ? "reused" : "created"} name=${nameForLog} bytes=${bytes}`,
|
|
712
|
+
);
|
|
713
|
+
return { success: true, data: result } satisfies ApiResponse;
|
|
714
|
+
} catch (err) {
|
|
715
|
+
const reason: CreateProjectReason = err instanceof CreateProjectError ? err.reason : "fs_error";
|
|
716
|
+
const error = err instanceof Error ? err.message : "create-project failed";
|
|
717
|
+
console.log(`[create-project] rejected:${reason} name=${nameForLog} bytes=${bytes}`);
|
|
718
|
+
reply.code(CREATE_PROJECT_STATUS[reason]);
|
|
719
|
+
return { success: false, error, reason };
|
|
720
|
+
}
|
|
721
|
+
},
|
|
722
|
+
);
|
|
723
|
+
|
|
400
724
|
// File read endpoint — read file content or list directory
|
|
401
725
|
fastify.get<{ Querystring: { cwd?: string; path?: string } }>(
|
|
402
726
|
"/api/file",
|
|
403
727
|
{ preHandler: networkGuard },
|
|
404
728
|
async (request, reply) => {
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
reply.code(400);
|
|
409
|
-
return { success: false, error: "cwd and path parameters required" } satisfies ApiResponse;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
const allSessions = sessionManager.listAll();
|
|
413
|
-
if (!allSessions.some((s) => s.cwd === cwd)) {
|
|
414
|
-
reply.code(403);
|
|
415
|
-
return { success: false, error: "unknown session path" } satisfies ApiResponse;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
const resolved = path.resolve(cwd, relPath);
|
|
419
|
-
// Anchors include the fixed `~/.pi` allowlist so a resolved `~/.pi/…`
|
|
420
|
-
// mention (from `/api/file/resolve-mention`) previews without a 403 (D7).
|
|
421
|
-
const readDecision = await evaluateContainment(resolved, [cwd, homePiAnchor()], {
|
|
422
|
-
site: "file-routes:read",
|
|
423
|
-
hold: { request, reply },
|
|
424
|
-
disclosure: canDiscloseAccessPosture(request),
|
|
425
|
-
session: cwd,
|
|
426
|
-
// Polymorphic: this route serves files AND directories, so the remedy
|
|
427
|
-
// must name whichever the target is (task 4.5 round 2, B1).
|
|
428
|
-
subjectKind: "auto",
|
|
429
|
-
});
|
|
430
|
-
if (!readDecision.allowed) {
|
|
431
|
-
reply.code(403);
|
|
432
|
-
return { success: false, error: "path outside working directory", ...readDecision.remedy } as unknown as ApiResponse;
|
|
729
|
+
const gate = await gateReadPath(request.query.cwd, request.query.path, { routeAdmission, request, reply });
|
|
730
|
+
if ("code" in gate) {
|
|
731
|
+
return sendGateFailure(reply, gate);
|
|
433
732
|
}
|
|
733
|
+
const { resolved } = gate;
|
|
434
734
|
|
|
435
735
|
try {
|
|
436
736
|
const stat = await fs.stat(resolved);
|
|
@@ -452,9 +752,9 @@ export function registerFileRoutes(
|
|
|
452
752
|
// re-resolved path (design D14, task 2.8): containment and this open are
|
|
453
753
|
// two syscalls, so without it the path could be swapped for a symlink or
|
|
454
754
|
// a FIFO in the gap. Layer ①/② reads keep the pre-existing open.
|
|
455
|
-
const fh =
|
|
755
|
+
const fh = gate.viaGrant
|
|
456
756
|
? await openVerifiedRegularFile(resolved)
|
|
457
|
-
: await
|
|
757
|
+
: await openStateChecked(resolved, "r");
|
|
458
758
|
let kindResult;
|
|
459
759
|
let content: string | undefined;
|
|
460
760
|
try {
|
|
@@ -489,9 +789,10 @@ export function registerFileRoutes(
|
|
|
489
789
|
},
|
|
490
790
|
} satisfies ApiResponse;
|
|
491
791
|
} catch (err) {
|
|
492
|
-
if (err instanceof VerifiedReadRefused) {
|
|
792
|
+
if (err instanceof VerifiedReadRefused || err instanceof DashboardStateRefused) {
|
|
493
793
|
// A granted path whose file is not a regular file, or was swapped
|
|
494
|
-
// between the check and the open
|
|
794
|
+
// between the check and the open (or a swap onto a dashboard secret).
|
|
795
|
+
// Refused in the site's existing
|
|
495
796
|
// containment shape — deliberately no new user-facing string.
|
|
496
797
|
reply.code(403);
|
|
497
798
|
return { success: false, error: "path outside working directory" } satisfies ApiResponse;
|
|
@@ -502,6 +803,74 @@ export function registerFileRoutes(
|
|
|
502
803
|
},
|
|
503
804
|
);
|
|
504
805
|
|
|
806
|
+
// Content digest for the editor pane's changed-on-disk verification. Same
|
|
807
|
+
// read gate as `/api/file` (`gateReadPath`) and the same open rule (verified
|
|
808
|
+
// open only when grant-admitted, else a non-blocking open + `fstat`), but it
|
|
809
|
+
// never returns content: `{ size, mtime, sha1 }`. Above the fixed 256 MiB
|
|
810
|
+
// ceiling it returns `{ size, mtime }` without a hash. Hashing is bounded by
|
|
811
|
+
// a 2-wide two-lane gate (baseline before verify) whose slot is released on
|
|
812
|
+
// client abort. No cache (equal size+mtime across two writes would hide a
|
|
813
|
+
// real change). See change: gate-changed-on-disk-by-content (D4).
|
|
814
|
+
fastify.get<{ Querystring: { cwd?: string; path?: string; purpose?: string } }>(
|
|
815
|
+
"/api/file/digest",
|
|
816
|
+
{ preHandler: networkGuard },
|
|
817
|
+
async (request, reply) => {
|
|
818
|
+
const gate = await gateReadPath(request.query.cwd, request.query.path, {
|
|
819
|
+
routeAdmission,
|
|
820
|
+
request,
|
|
821
|
+
reply,
|
|
822
|
+
quiet: true,
|
|
823
|
+
});
|
|
824
|
+
reply.header("Cache-Control", "no-store");
|
|
825
|
+
if ("code" in gate) {
|
|
826
|
+
return sendGateFailure(reply, gate);
|
|
827
|
+
}
|
|
828
|
+
const lane: DigestLane = request.query.purpose === "baseline" ? "baseline" : "verify";
|
|
829
|
+
const ac = new AbortController();
|
|
830
|
+
const onClose = (): void => {
|
|
831
|
+
if (!reply.raw.writableFinished) ac.abort();
|
|
832
|
+
};
|
|
833
|
+
reply.raw.once("close", onClose);
|
|
834
|
+
let release: (() => void) | undefined;
|
|
835
|
+
try {
|
|
836
|
+
release = await digestGate.acquire(lane, ac.signal);
|
|
837
|
+
const fh = gate.viaGrant
|
|
838
|
+
? await openVerifiedRegularFile(gate.resolved)
|
|
839
|
+
: await fs.open(gate.resolved, fsConstants.O_RDONLY | (fsConstants.O_NONBLOCK ?? 0));
|
|
840
|
+
try {
|
|
841
|
+
const stat = await fh.stat();
|
|
842
|
+
if (!stat.isFile()) {
|
|
843
|
+
reply.code(404);
|
|
844
|
+
return { success: false, error: "not found" } satisfies ApiResponse;
|
|
845
|
+
}
|
|
846
|
+
const data: { size: number; mtime: number; sha1?: string } = { size: stat.size, mtime: stat.mtimeMs };
|
|
847
|
+
if (stat.size <= DIGEST_CEILING_BYTES) {
|
|
848
|
+
const sha1 = await hashHandle(fh, ac.signal);
|
|
849
|
+
if (sha1 !== null) data.sha1 = sha1;
|
|
850
|
+
}
|
|
851
|
+
return { success: true, data } satisfies ApiResponse;
|
|
852
|
+
} finally {
|
|
853
|
+
await fh.close();
|
|
854
|
+
}
|
|
855
|
+
} catch (err) {
|
|
856
|
+
if (err instanceof VerifiedReadRefused) {
|
|
857
|
+
reply.code(403);
|
|
858
|
+
return { success: false, error: "path outside working directory" } satisfies ApiResponse;
|
|
859
|
+
}
|
|
860
|
+
if ((err as Error)?.name === "AbortError") {
|
|
861
|
+
// Client went away — nobody is reading the reply.
|
|
862
|
+
reply.code(499);
|
|
863
|
+
return { success: false, error: "aborted" } satisfies ApiResponse;
|
|
864
|
+
}
|
|
865
|
+
reply.code(404);
|
|
866
|
+
return { success: false, error: "not found" } satisfies ApiResponse;
|
|
867
|
+
} finally {
|
|
868
|
+
release?.();
|
|
869
|
+
reply.raw.off("close", onClose);
|
|
870
|
+
}
|
|
871
|
+
},
|
|
872
|
+
);
|
|
873
|
+
|
|
505
874
|
// System-open endpoints (change: open-view-command-in-editor-pane, D9/D10).
|
|
506
875
|
// Spawn the OS opener on the SERVER host for the active tab's file. All of:
|
|
507
876
|
// - refuse when `capabilities.systemOpen` is false (headless/container),
|
|
@@ -540,14 +909,13 @@ export function registerFileRoutes(
|
|
|
540
909
|
// `allowGrant: false` — a read grant must NOT authorize launching a local
|
|
541
910
|
// application or revealing in the file manager. Those are a different
|
|
542
911
|
// capability from reading, so the two spawn routes keep the pre-change
|
|
543
|
-
//
|
|
544
|
-
const gate = await gateFilePath(cwd, rawPath,
|
|
912
|
+
// layers ①/② only decision (task 4.5 review gate, blocking #2).
|
|
913
|
+
const gate = await gateFilePath(cwd, rawPath, routeAdmission, {
|
|
545
914
|
allowGrant: false,
|
|
546
915
|
disclosure: canDiscloseAccessPosture(request),
|
|
547
916
|
});
|
|
548
917
|
if ("code" in gate) {
|
|
549
|
-
reply
|
|
550
|
-
return denialBody(gate);
|
|
918
|
+
return sendGateFailure(reply, gate);
|
|
551
919
|
}
|
|
552
920
|
const { cmd, args } = build(systemOpenPlatform, gate.resolved);
|
|
553
921
|
systemOpenRun(cmd, args);
|
|
@@ -584,22 +952,20 @@ export function registerFileRoutes(
|
|
|
584
952
|
return { success: false, error: "cwd and path parameters required" } satisfies ApiResponse;
|
|
585
953
|
}
|
|
586
954
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
return { success: false, error: "unknown session path" } satisfies ApiResponse;
|
|
590
|
-
}
|
|
955
|
+
const admitted = await admitFileCwd(cwd, routeAdmission, { reply });
|
|
956
|
+
if (!admitted.ok) return sendGateFailure(reply, admitted.failure);
|
|
591
957
|
|
|
592
|
-
const resolved = path.resolve(cwd, relPath);
|
|
593
|
-
const treeDecision = await evaluateContainment(resolved,
|
|
958
|
+
const resolved = path.resolve(admitted.cwd, relPath);
|
|
959
|
+
const treeDecision = await evaluateContainment(resolved, cwdAnchors(admitted), {
|
|
594
960
|
site: "file-routes:tree",
|
|
595
961
|
hold: { request, reply },
|
|
596
962
|
disclosure: canDiscloseAccessPosture(request),
|
|
597
|
-
session: cwd,
|
|
963
|
+
session: admitted.cwd,
|
|
598
964
|
// Directory-only site: the remedy must name THIS directory, not its
|
|
599
965
|
// parent (task 4.5 review).
|
|
600
966
|
subjectKind: "directory",
|
|
601
967
|
});
|
|
602
|
-
if (!treeDecision
|
|
968
|
+
if (!containmentAllows(treeDecision, resolved)) {
|
|
603
969
|
reply.code(403);
|
|
604
970
|
return { success: false, error: "path outside working directory", ...treeDecision.remedy } as unknown as ApiResponse;
|
|
605
971
|
}
|
|
@@ -649,23 +1015,31 @@ export function registerFileRoutes(
|
|
|
649
1015
|
// See change: directory-settings-page-and-scoped-md-editing.
|
|
650
1016
|
fastify.post<{ Body: { cwd?: unknown; path?: unknown; content?: unknown; mtime?: unknown } }>(
|
|
651
1017
|
"/api/file/write",
|
|
652
|
-
|
|
1018
|
+
// 256 MiB of content plus JSON escaping headroom. Fastify's default 1 MiB
|
|
1019
|
+
// limit made any markdown save over ~1 MiB fail with 413 (pre-existing bug);
|
|
1020
|
+
// the handler still refuses content above the 256 MiB ceiling.
|
|
1021
|
+
{ preHandler: networkGuard, bodyLimit: 600 * 1024 * 1024 },
|
|
653
1022
|
async (request, reply) => {
|
|
654
|
-
const prep = await prepareMdWrite(request.body ?? {},
|
|
1023
|
+
const prep = await prepareMdWrite(request.body ?? {}, routeAdmission);
|
|
655
1024
|
if ("code" in prep) {
|
|
656
|
-
reply
|
|
657
|
-
return { success: false, error: prep.error } satisfies ApiResponse;
|
|
1025
|
+
return sendGateFailure(reply, prep);
|
|
658
1026
|
}
|
|
659
1027
|
// Critical section: stat → mtime check → write → rename runs serialized per
|
|
660
1028
|
// target so the optimistic check is atomic w.r.t. a concurrent write.
|
|
661
|
-
|
|
1029
|
+
// Keyed by REALPATH (shared with `/api/file/write-binary`) so a symlink alias
|
|
1030
|
+
// cannot run two writes to one file at once. See change: add-editor-pane-file-handlers (D4).
|
|
1031
|
+
const lockKey = await safeRealpath(prep.resolved);
|
|
1032
|
+
const outcome = await serializeWrite(lockKey, () =>
|
|
662
1033
|
performAtomicMdWrite(prep.resolved, prep.content, prep.mtime),
|
|
663
1034
|
);
|
|
664
1035
|
if (outcome.code !== 200) {
|
|
665
1036
|
reply.code(outcome.code);
|
|
666
1037
|
return { success: false, error: outcome.error } satisfies ApiResponse;
|
|
667
1038
|
}
|
|
668
|
-
return {
|
|
1039
|
+
return {
|
|
1040
|
+
success: true,
|
|
1041
|
+
data: { mtime: outcome.mtime, size: outcome.size, sha1: outcome.sha1 },
|
|
1042
|
+
} satisfies ApiResponse;
|
|
669
1043
|
},
|
|
670
1044
|
);
|
|
671
1045
|
|
|
@@ -679,15 +1053,16 @@ export function registerFileRoutes(
|
|
|
679
1053
|
"/api/file/md-candidates",
|
|
680
1054
|
{ preHandler: networkGuard },
|
|
681
1055
|
async (request, reply) => {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
}
|
|
1056
|
+
// Absent (undefined / "") → global scope with a constant `{}`; any other value must be an
|
|
1057
|
+
// admitted absolute cwd. See change: core-file-cwd-admission (D1).
|
|
1058
|
+
const rawCwd: unknown = request.query.cwd;
|
|
1059
|
+
if (rawCwd === undefined || rawCwd === "") {
|
|
1060
|
+
const globalCandidates = await enumerateMdCandidates({});
|
|
1061
|
+
return { success: true, data: { candidates: globalCandidates } } satisfies ApiResponse;
|
|
689
1062
|
}
|
|
690
|
-
const
|
|
1063
|
+
const admitted = await admitFileCwd(rawCwd, routeAdmission, { reply });
|
|
1064
|
+
if (!admitted.ok) return sendGateFailure(reply, admitted.failure);
|
|
1065
|
+
const candidates = await enumerateMdCandidates({ cwd: admitted.cwd });
|
|
691
1066
|
return { success: true, data: { candidates } } satisfies ApiResponse;
|
|
692
1067
|
},
|
|
693
1068
|
);
|
|
@@ -703,19 +1078,17 @@ export function registerFileRoutes(
|
|
|
703
1078
|
"/api/file/md-read",
|
|
704
1079
|
{ preHandler: networkGuard },
|
|
705
1080
|
async (request, reply) => {
|
|
706
|
-
const cwd = request.query.cwd || undefined;
|
|
707
1081
|
const rawPath = request.query.path;
|
|
708
1082
|
if (!rawPath) {
|
|
709
1083
|
reply.code(400);
|
|
710
1084
|
return { success: false, error: "path parameter required" } satisfies ApiResponse;
|
|
711
1085
|
}
|
|
712
|
-
const target = resolveScopedMdPath(cwd, rawPath,
|
|
1086
|
+
const target = await resolveScopedMdPath(request.query.cwd, rawPath, routeAdmission);
|
|
713
1087
|
if ("code" in target) {
|
|
714
|
-
reply
|
|
715
|
-
return { success: false, error: target.error } satisfies ApiResponse;
|
|
1088
|
+
return sendGateFailure(reply, target);
|
|
716
1089
|
}
|
|
717
1090
|
const resolved = target.resolved;
|
|
718
|
-
if (!(await isWritableMdTarget(resolved, { cwd }))) {
|
|
1091
|
+
if (!(await isWritableMdTarget(resolved, { cwd: target.cwd }))) {
|
|
719
1092
|
reply.code(403);
|
|
720
1093
|
return { success: false, error: "target is not a readable markdown file in scope" } satisfies ApiResponse;
|
|
721
1094
|
}
|
|
@@ -751,17 +1124,12 @@ export function registerFileRoutes(
|
|
|
751
1124
|
reply.code(400);
|
|
752
1125
|
return { success: false, error: "cwd and path parameters required" } satisfies ApiResponse;
|
|
753
1126
|
}
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
//
|
|
758
|
-
//
|
|
759
|
-
|
|
760
|
-
// now contain it; `allow-once` admits exactly the named directory, for this
|
|
761
|
-
// request only. Every other outcome returns the unchanged denial below.
|
|
762
|
-
const cwdAdmitted =
|
|
763
|
-
knownCwds.has(cwd) || (await unknownCwdVerdictAdmits(cwd, { request, reply }, preferencesStore));
|
|
764
|
-
if (!cwdAdmitted) {
|
|
1127
|
+
// Admission (change: core-file-cwd-admission, D5). An absolute cwd is admitted through the
|
|
1128
|
+
// shared guard; a refusal may ask the operator (add-access-grant-dialog, task 6.2). An allow
|
|
1129
|
+
// verdict authorises a RE-RUN of the guard, never a skip: `allow-always` pinned the
|
|
1130
|
+
// directory so the live known set now contains it; `allow-once` admits exactly the named
|
|
1131
|
+
// directory, for this request only. An undecidable admission answers 503 and never prompts.
|
|
1132
|
+
const existsRefusal = (): ApiResponse => {
|
|
765
1133
|
reply.code(403);
|
|
766
1134
|
// Additive remedy fields beside the unchanged `"unknown cwd"` string
|
|
767
1135
|
// (design D7/D18); the known-cwd set already includes pinned
|
|
@@ -771,10 +1139,24 @@ export function registerFileRoutes(
|
|
|
771
1139
|
// add-access-grants-and-review.
|
|
772
1140
|
return {
|
|
773
1141
|
success: false,
|
|
1142
|
+
code: "cwd_unknown",
|
|
774
1143
|
error: "unknown cwd",
|
|
775
1144
|
reason: "cwd is not a known session or pinned directory.",
|
|
776
1145
|
hint: "Pin this directory to allow it, or open a session rooted in it.",
|
|
777
1146
|
} as unknown as ApiResponse;
|
|
1147
|
+
};
|
|
1148
|
+
if (typeof cwd !== "string" || !path.isAbsolute(cwd)) return existsRefusal();
|
|
1149
|
+
let admitted = await admitFileCwd(cwd, routeAdmission, { error: "unknown cwd", reply });
|
|
1150
|
+
if (!admitted.ok && admitted.failure.code === 503) return sendGateFailure(reply, admitted.failure);
|
|
1151
|
+
if (!admitted.ok) {
|
|
1152
|
+
const decision = await unknownCwdVerdict(cwd, { request, reply }, routeAdmission);
|
|
1153
|
+
if (decision.kind === "indeterminate") return sendGateFailure(reply, CWD_UNAVAILABLE_FAILURE);
|
|
1154
|
+
const held = issueHeldAdmission(decision, cwd);
|
|
1155
|
+
if (held.kind !== "admit" || !admissionAllows(held, cwd)) return existsRefusal();
|
|
1156
|
+
const token = held.token;
|
|
1157
|
+
const release = (): void => releaseAdmission(token);
|
|
1158
|
+
releaseOnClose(reply, release);
|
|
1159
|
+
admitted = { ok: true, cwd, canonCwd: token.canonCwd, release };
|
|
778
1160
|
}
|
|
779
1161
|
// Anti-traversal: probePath MUST be inside cwd (or a pinned dir / repo
|
|
780
1162
|
// git root). Pinned-dir anchor is exists-only; not folded onto read/raw/render.
|
|
@@ -787,16 +1169,16 @@ export function registerFileRoutes(
|
|
|
787
1169
|
return { success: false, error: "path outside cwd" } satisfies ApiResponse;
|
|
788
1170
|
}
|
|
789
1171
|
const resolved = path.resolve(probePath);
|
|
790
|
-
const anchors = [
|
|
1172
|
+
const anchors = [...cwdAnchors(admitted), ...preferencesStore.getPinnedDirectories()];
|
|
791
1173
|
const existsDecision = await evaluateContainment(resolved, anchors, {
|
|
792
1174
|
site: "file-routes:exists",
|
|
793
1175
|
hold: { request, reply },
|
|
794
1176
|
disclosure: canDiscloseAccessPosture(request),
|
|
795
|
-
session: cwd,
|
|
1177
|
+
session: admitted.cwd,
|
|
796
1178
|
// `fs.access` accepts files AND directories — polymorphic, see above.
|
|
797
1179
|
subjectKind: "auto",
|
|
798
1180
|
});
|
|
799
|
-
if (!existsDecision
|
|
1181
|
+
if (!containmentAllows(existsDecision, resolved)) {
|
|
800
1182
|
reply.code(403);
|
|
801
1183
|
return { success: false, error: "path outside cwd", ...existsDecision.remedy } as unknown as ApiResponse;
|
|
802
1184
|
}
|
|
@@ -830,11 +1212,9 @@ export function registerFileRoutes(
|
|
|
830
1212
|
reply.code(400);
|
|
831
1213
|
return { success: false, error: "cwd and mention are required" } satisfies ApiResponse;
|
|
832
1214
|
}
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
}
|
|
837
|
-
const result = await resolveFileMention(mention, { cwd });
|
|
1215
|
+
const admitted = await admitFileCwd(cwd, routeAdmission, { reply });
|
|
1216
|
+
if (!admitted.ok) return sendGateFailure(reply, admitted.failure);
|
|
1217
|
+
const result = await resolveFileMention(mention, { cwd: admitted.cwd, canonCwd: admitted.canonCwd });
|
|
838
1218
|
return {
|
|
839
1219
|
success: true,
|
|
840
1220
|
data: result ? { resolved: result.resolved, kind: result.kind } : { resolved: null },
|
|
@@ -869,13 +1249,11 @@ export function registerFileRoutes(
|
|
|
869
1249
|
return { success: false, error: "cwd and path parameters required" } satisfies ApiResponse;
|
|
870
1250
|
}
|
|
871
1251
|
|
|
872
|
-
const
|
|
873
|
-
if (!
|
|
874
|
-
|
|
875
|
-
return { success: false, error: "unknown session path" } satisfies ApiResponse;
|
|
876
|
-
}
|
|
1252
|
+
const admitted = await admitFileCwd(cwd, routeAdmission, { reply });
|
|
1253
|
+
if (!admitted.ok) return sendGateFailure(reply, admitted.failure);
|
|
1254
|
+
const rawAnchors = [...cwdAnchors(admitted), homePiAnchor()];
|
|
877
1255
|
|
|
878
|
-
const resolved = path.resolve(cwd, relPath);
|
|
1256
|
+
const resolved = path.resolve(admitted.cwd, relPath);
|
|
879
1257
|
// Layers ①/② (cwd + git common root) serve any type. Layer ③ — artifact
|
|
880
1258
|
// roots — is image-only and real-path contained; it covers agent
|
|
881
1259
|
// screenshots that live outside every cwd and git root.
|
|
@@ -886,15 +1264,15 @@ export function registerFileRoutes(
|
|
|
886
1264
|
// True only when the GRANT layer admitted this read — layers ①/② and the
|
|
887
1265
|
// artifact root do NOT get handle verification (task 2.8 scope).
|
|
888
1266
|
let viaGrant = false;
|
|
889
|
-
if (!(await
|
|
1267
|
+
if (!containmentAllows(await decidePassive(resolved, rawAnchors, { allowGrant: false }), resolved)) {
|
|
890
1268
|
if (!(await isImageUnderArtifactRoot(resolved))) {
|
|
891
|
-
const rawDecision = await evaluateContainment(resolved,
|
|
1269
|
+
const rawDecision = await evaluateContainment(resolved, rawAnchors, {
|
|
892
1270
|
site: "file-routes:raw",
|
|
893
1271
|
hold: { request, reply },
|
|
894
1272
|
disclosure: canDiscloseAccessPosture(request),
|
|
895
|
-
session: cwd,
|
|
1273
|
+
session: admitted.cwd,
|
|
896
1274
|
});
|
|
897
|
-
if (!rawDecision
|
|
1275
|
+
if (!containmentAllows(rawDecision, resolved)) {
|
|
898
1276
|
reply.code(403);
|
|
899
1277
|
return { success: false, error: "path outside working directory", ...rawDecision.remedy } as unknown as ApiResponse;
|
|
900
1278
|
}
|
|
@@ -922,6 +1300,15 @@ export function registerFileRoutes(
|
|
|
922
1300
|
|
|
923
1301
|
reply.header("Content-Type", contentType);
|
|
924
1302
|
reply.header("Content-Disposition", "inline");
|
|
1303
|
+
// Scriptable media types (SVG/HTML/XML) opened directly would run with the
|
|
1304
|
+
// dashboard origin. Enforce an opaque-origin sandbox in EVERY dashboard CSP
|
|
1305
|
+
// mode, on 200/206/416 and every admission path. The baseline CSP hook
|
|
1306
|
+
// only adds a header that is absent, so this is never overwritten.
|
|
1307
|
+
// See change: harden-raw-svg-responses.
|
|
1308
|
+
if (isScriptableMediaType(contentType)) {
|
|
1309
|
+
reply.header("Content-Security-Policy", RAW_SANDBOX_CSP);
|
|
1310
|
+
reply.header("X-Content-Type-Options", "nosniff");
|
|
1311
|
+
}
|
|
925
1312
|
reply.header("Cache-Control", "private, max-age=60");
|
|
926
1313
|
reply.header("Accept-Ranges", "bytes");
|
|
927
1314
|
|
|
@@ -989,19 +1376,31 @@ export function registerFileRoutes(
|
|
|
989
1376
|
}
|
|
990
1377
|
}
|
|
991
1378
|
|
|
1379
|
+
// Non-grant reads open here so the handle can be checked against the always-refused dashboard
|
|
1380
|
+
// files before a single byte is streamed (the path check and the open are two syscalls).
|
|
1381
|
+
let rawHandle: Awaited<ReturnType<typeof openStateChecked>> | undefined;
|
|
1382
|
+
if (!grantedHandle) {
|
|
1383
|
+
try {
|
|
1384
|
+
rawHandle = await openStateChecked(resolved, "r");
|
|
1385
|
+
} catch (err) {
|
|
1386
|
+
reply.code(err instanceof DashboardStateRefused ? 403 : 404);
|
|
1387
|
+
return {
|
|
1388
|
+
success: false,
|
|
1389
|
+
error: err instanceof DashboardStateRefused ? "path outside working directory" : "not found",
|
|
1390
|
+
} satisfies ApiResponse;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
const servedHandle = grantedHandle ?? rawHandle!;
|
|
1394
|
+
|
|
992
1395
|
if (range) {
|
|
993
1396
|
reply.code(206);
|
|
994
1397
|
reply.header("Content-Range", `bytes ${range.start}-${range.end}/${size}`);
|
|
995
1398
|
reply.header("Content-Length", String(range.end - range.start + 1));
|
|
996
|
-
return reply.send(
|
|
997
|
-
grantedHandle
|
|
998
|
-
? grantedHandle.createReadStream({ start: range.start, end: range.end })
|
|
999
|
-
: createReadStream(resolved, { start: range.start, end: range.end }),
|
|
1000
|
-
);
|
|
1399
|
+
return reply.send(servedHandle.createReadStream({ start: range.start, end: range.end }));
|
|
1001
1400
|
}
|
|
1002
1401
|
|
|
1003
1402
|
reply.header("Content-Length", String(size));
|
|
1004
|
-
return reply.send(
|
|
1403
|
+
return reply.send(servedHandle.createReadStream());
|
|
1005
1404
|
},
|
|
1006
1405
|
);
|
|
1007
1406
|
|
|
@@ -1014,7 +1413,7 @@ export function registerFileRoutes(
|
|
|
1014
1413
|
// engine-only PDF render (`{mode:"pdf"}`; no in-process fallback — engine
|
|
1015
1414
|
// absent → {success:false}; change: render-pptx-preview). Non-supported
|
|
1016
1415
|
// extensions → 400. Same anti-traversal gate as `/api/file/raw`.
|
|
1017
|
-
fastify.get<{ Querystring: { cwd?: string; path?: string } }>(
|
|
1416
|
+
fastify.get<{ Querystring: { cwd?: string; path?: string; repair?: string } }>(
|
|
1018
1417
|
"/api/file/render",
|
|
1019
1418
|
{ preHandler: networkGuard },
|
|
1020
1419
|
async (request, reply) => {
|
|
@@ -1046,8 +1445,7 @@ export function registerFileRoutes(
|
|
|
1046
1445
|
canDiscloseAccessPosture(request),
|
|
1047
1446
|
);
|
|
1048
1447
|
if ("code" in gate) {
|
|
1049
|
-
reply
|
|
1050
|
-
return denialBody(gate);
|
|
1448
|
+
return sendGateFailure(reply, gate);
|
|
1051
1449
|
}
|
|
1052
1450
|
const result = await renderPptx(
|
|
1053
1451
|
gate.resolved,
|
|
@@ -1071,8 +1469,7 @@ export function registerFileRoutes(
|
|
|
1071
1469
|
canDiscloseAccessPosture(request),
|
|
1072
1470
|
);
|
|
1073
1471
|
if ("code" in gate) {
|
|
1074
|
-
reply
|
|
1075
|
-
return denialBody(gate);
|
|
1472
|
+
return sendGateFailure(reply, gate);
|
|
1076
1473
|
}
|
|
1077
1474
|
const result = await renderDocx(
|
|
1078
1475
|
gate.resolved,
|
|
@@ -1088,24 +1485,31 @@ export function registerFileRoutes(
|
|
|
1088
1485
|
return { success: true, data } satisfies ApiResponse;
|
|
1089
1486
|
}
|
|
1090
1487
|
|
|
1091
|
-
const
|
|
1092
|
-
if (!
|
|
1093
|
-
reply.code(403);
|
|
1094
|
-
return { success: false, error: "unknown session path" } satisfies ApiResponse;
|
|
1095
|
-
}
|
|
1488
|
+
const admitted = await admitFileCwd(cwd, routeAdmission, { reply });
|
|
1489
|
+
if (!admitted.ok) return sendGateFailure(reply, admitted.failure);
|
|
1096
1490
|
|
|
1097
|
-
const resolved = path.resolve(cwd, relPath);
|
|
1098
|
-
const renderDecision = await evaluateContainment(resolved, [
|
|
1491
|
+
const resolved = path.resolve(admitted.cwd, relPath);
|
|
1492
|
+
const renderDecision = await evaluateContainment(resolved, [...cwdAnchors(admitted), homePiAnchor()], {
|
|
1099
1493
|
site: "file-routes:render",
|
|
1100
1494
|
hold: { request, reply },
|
|
1101
1495
|
disclosure: canDiscloseAccessPosture(request),
|
|
1102
|
-
session: cwd,
|
|
1496
|
+
session: admitted.cwd,
|
|
1103
1497
|
});
|
|
1104
|
-
if (!renderDecision
|
|
1498
|
+
if (!containmentAllows(renderDecision, resolved)) {
|
|
1105
1499
|
reply.code(403);
|
|
1106
1500
|
return { success: false, error: "path outside working directory", ...renderDecision.remedy } as unknown as ApiResponse;
|
|
1107
1501
|
}
|
|
1108
1502
|
|
|
1503
|
+
// Modification token, taken BEFORE the read: a concurrent write can only make it
|
|
1504
|
+
// older than the content, so the apply-side verify fails safe ("file changed").
|
|
1505
|
+
let mtime = 0;
|
|
1506
|
+
try {
|
|
1507
|
+
mtime = (await fs.stat(resolved)).mtimeMs;
|
|
1508
|
+
} catch {
|
|
1509
|
+
reply.code(404);
|
|
1510
|
+
return { success: false, error: "not found" } satisfies ApiResponse;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1109
1513
|
let source: string;
|
|
1110
1514
|
if (renderDecision.viaGrant) {
|
|
1111
1515
|
// Verified against the open handle (design D14, task 2.8) — a granted
|
|
@@ -1122,7 +1526,7 @@ export function registerFileRoutes(
|
|
|
1122
1526
|
}
|
|
1123
1527
|
} else {
|
|
1124
1528
|
try {
|
|
1125
|
-
source = await
|
|
1529
|
+
source = await readFileStateChecked(resolved, "utf-8");
|
|
1126
1530
|
} catch {
|
|
1127
1531
|
reply.code(404);
|
|
1128
1532
|
return { success: false, error: "not found" } satisfies ApiResponse;
|
|
@@ -1130,10 +1534,14 @@ export function registerFileRoutes(
|
|
|
1130
1534
|
}
|
|
1131
1535
|
|
|
1132
1536
|
try {
|
|
1133
|
-
|
|
1134
|
-
// `
|
|
1135
|
-
const
|
|
1136
|
-
|
|
1537
|
+
// Markup repair is a pure source scan (shared with the client's apply path);
|
|
1538
|
+
// `repair=0` serves the "view original rendering" toggle.
|
|
1539
|
+
const repaired = request.query.repair === "0" ? { source, repairs: [] } : repairAsciiDoc(source);
|
|
1540
|
+
const { html, warnings } = convertAdocCapturingWarnings(repaired.source);
|
|
1541
|
+
return {
|
|
1542
|
+
success: true,
|
|
1543
|
+
data: { html: await sanitizeAdocHtml(html), repairs: repaired.repairs, warnings, mtime },
|
|
1544
|
+
} satisfies ApiResponse;
|
|
1137
1545
|
} catch (err) {
|
|
1138
1546
|
const msg = err instanceof Error ? err.message : "render failed";
|
|
1139
1547
|
reply.code(500);
|
|
@@ -1163,8 +1571,7 @@ export function registerFileRoutes(
|
|
|
1163
1571
|
canDiscloseAccessPosture(request),
|
|
1164
1572
|
);
|
|
1165
1573
|
if ("code" in gate) {
|
|
1166
|
-
reply
|
|
1167
|
-
return denialBody(gate);
|
|
1574
|
+
return sendGateFailure(reply, gate);
|
|
1168
1575
|
}
|
|
1169
1576
|
const out = pdfCachePath(gate.resolved, gate.stat.mtimeMs, gate.stat.size);
|
|
1170
1577
|
try {
|
|
@@ -1205,8 +1612,7 @@ export function registerFileRoutes(
|
|
|
1205
1612
|
canDiscloseAccessPosture(request),
|
|
1206
1613
|
);
|
|
1207
1614
|
if ("code" in gate) {
|
|
1208
|
-
reply
|
|
1209
|
-
return denialBody(gate);
|
|
1615
|
+
return sendGateFailure(reply, gate);
|
|
1210
1616
|
}
|
|
1211
1617
|
let buffer: Buffer;
|
|
1212
1618
|
if (gate.viaGrant) {
|
|
@@ -1224,7 +1630,7 @@ export function registerFileRoutes(
|
|
|
1224
1630
|
}
|
|
1225
1631
|
} else {
|
|
1226
1632
|
try {
|
|
1227
|
-
buffer = await
|
|
1633
|
+
buffer = await readFileStateChecked(gate.resolved);
|
|
1228
1634
|
} catch {
|
|
1229
1635
|
reply.code(404);
|
|
1230
1636
|
return { success: false, error: "not found" } satisfies ApiResponse;
|
|
@@ -1252,12 +1658,11 @@ export function registerFileRoutes(
|
|
|
1252
1658
|
"/api/file/eml",
|
|
1253
1659
|
{ preHandler: networkGuard },
|
|
1254
1660
|
async (request, reply) => {
|
|
1255
|
-
const gate = await gateFilePath(request.query.cwd, request.query.path,
|
|
1661
|
+
const gate = await gateFilePath(request.query.cwd, request.query.path, routeAdmission, {
|
|
1256
1662
|
disclosure: canDiscloseAccessPosture(request),
|
|
1257
1663
|
});
|
|
1258
1664
|
if ("code" in gate) {
|
|
1259
|
-
reply
|
|
1260
|
-
return denialBody(gate);
|
|
1665
|
+
return sendGateFailure(reply, gate);
|
|
1261
1666
|
}
|
|
1262
1667
|
const ext = path.extname(request.query.path ?? "").toLowerCase();
|
|
1263
1668
|
if (ext !== ".eml") {
|
|
@@ -1311,12 +1716,11 @@ export function registerFileRoutes(
|
|
|
1311
1716
|
"/api/file/eml-attachment",
|
|
1312
1717
|
{ preHandler: networkGuard },
|
|
1313
1718
|
async (request, reply) => {
|
|
1314
|
-
const gate = await gateFilePath(request.query.cwd, request.query.path,
|
|
1719
|
+
const gate = await gateFilePath(request.query.cwd, request.query.path, routeAdmission, {
|
|
1315
1720
|
disclosure: canDiscloseAccessPosture(request),
|
|
1316
1721
|
});
|
|
1317
1722
|
if ("code" in gate) {
|
|
1318
|
-
reply
|
|
1319
|
-
return denialBody(gate);
|
|
1723
|
+
return sendGateFailure(reply, gate);
|
|
1320
1724
|
}
|
|
1321
1725
|
if (path.extname(request.query.path ?? "").toLowerCase() !== ".eml") {
|
|
1322
1726
|
reply.code(400);
|
|
@@ -1409,24 +1813,31 @@ export function registerFileRoutes(
|
|
|
1409
1813
|
}
|
|
1410
1814
|
|
|
1411
1815
|
/**
|
|
1412
|
-
* Ask about an unknown-cwd denial and re-run the
|
|
1413
|
-
*
|
|
1414
|
-
*
|
|
1816
|
+
* Ask about an unknown-cwd denial and re-run the shared guard on an allow verdict
|
|
1817
|
+
* (add-access-grant-dialog, task 6.2). Returns the post-verdict decision: `admit` only for an
|
|
1818
|
+
* explicit allow that the re-run confirms, `indeterminate` when the re-run cannot decide, else
|
|
1819
|
+
* `refuse`. The re-run is the shared `resolveCwdVerdict` (canonical compare against the known
|
|
1820
|
+
* set, allow-once real-path re-resolution, `rerunAlways` through `admitRouteCwd`) — the same
|
|
1821
|
+
* rules plugin holds use. See change: harden-plugin-cwd-admission, core-file-cwd-admission (D5).
|
|
1415
1822
|
*/
|
|
1416
|
-
async function
|
|
1823
|
+
async function unknownCwdVerdict(
|
|
1417
1824
|
cwd: string,
|
|
1418
1825
|
target: HoldTarget,
|
|
1419
|
-
|
|
1420
|
-
): Promise<
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1826
|
+
routeAdmission: RouteAdmissionDeps,
|
|
1827
|
+
): Promise<CwdHoldDecision> {
|
|
1828
|
+
// The subject is the REAL path, so an allow-once can later be compared strictly against
|
|
1829
|
+
// what the path means at release time. A cwd that does not resolve is never asked about:
|
|
1830
|
+
// the post-verdict re-run refuses it whatever the operator answers (and a pin for a
|
|
1831
|
+
// directory that is not there is meaningless) — the same rule the plugin seam applies.
|
|
1832
|
+
const real = await realpathAsync(path.resolve(cwd));
|
|
1833
|
+
if (real.kind !== "ok") return { kind: "refuse" };
|
|
1834
|
+
const resolution = await holdDenial({ plane: "cwd", rawSubject: real.path, origin: "file-routes:exists" }, target);
|
|
1835
|
+
return resolveCwdVerdict(cwd, resolution, {
|
|
1836
|
+
known: routeAdmission.knownCwds ?? (() => []),
|
|
1837
|
+
rerunAlways: async (canon) => {
|
|
1838
|
+
const admission = await admitRouteCwd(canon, routeAdmission);
|
|
1839
|
+
if (admission.kind === "admit") releaseAdmission(admission.token);
|
|
1840
|
+
return admission.kind;
|
|
1841
|
+
},
|
|
1842
|
+
});
|
|
1432
1843
|
}
|