@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
|
@@ -4,9 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
import fs from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
|
+
import {
|
|
8
|
+
ADMISSION_DEADLINE_MS,
|
|
9
|
+
type AdmissionToken,
|
|
10
|
+
type AdmitCwdOptions,
|
|
11
|
+
admissionAllows,
|
|
12
|
+
releaseAdmission,
|
|
13
|
+
} from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
|
|
14
|
+
import { checkoutRoots } from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
|
|
7
15
|
import { getDefaultRegistry } from "@blackbelt-technology/pi-dashboard-shared/tool-registry/index.js";
|
|
8
16
|
import type { ApiResponse } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
9
|
-
import type { FastifyInstance } from "fastify";
|
|
17
|
+
import type { FastifyInstance, FastifyReply } from "fastify";
|
|
18
|
+
import { getPiTrustMirror } from "../access/pi-trust-mirror-service.js";
|
|
10
19
|
import {
|
|
11
20
|
addWorktree,
|
|
12
21
|
addWorktreeFromPr,
|
|
@@ -34,11 +43,13 @@ import {
|
|
|
34
43
|
type WorktreeRemovalVerdict,
|
|
35
44
|
worktreeDiffStat,
|
|
36
45
|
} from "../git-worktree/git-operations.js";
|
|
37
|
-
import { checkoutRoots } from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
|
|
38
46
|
import { evaluateGate, type GateResult, hookDefHash, type InitProgress, readInitHook, runInitHook, type WorktreeInitHook } from "../git-worktree/worktree-init.js";
|
|
47
|
+
import { gitErrorText, redactGitText } from "../git-worktree/redact-git-text.js";
|
|
48
|
+
import { INVALID_REF_CODE, InvalidRefError, isMissingArg, isValidRefArg } from "../git-worktree/ref-arg.js";
|
|
39
49
|
import { mapInitStderrToHint } from "../git-worktree/worktree-init-errors.js";
|
|
40
50
|
import type { WorktreeInitRegistry } from "../git-worktree/worktree-init-registry.js";
|
|
41
51
|
import { isTrusted, recordTrust } from "../git-worktree/worktree-init-trust.js";
|
|
52
|
+
import { admitRouteCwd, sendAdmissionUnavailable } from "../lib/route-admission.js";
|
|
42
53
|
import type { BrowserGateway } from "../pairing/browser-gateway.js";
|
|
43
54
|
import { safeRealpathSync } from "../resolve-path.js";
|
|
44
55
|
import { activeSessionsUnder, activeSessionsUnderResolved, sessionsUnder } from "../session/active-sessions-in-cwd.js";
|
|
@@ -71,7 +82,46 @@ export interface GitRoutesDeps {
|
|
|
71
82
|
* the final result either way). See change: generalize-worktree-init-hook.
|
|
72
83
|
*/
|
|
73
84
|
worktreeInitRegistry?: WorktreeInitRegistry;
|
|
85
|
+
/**
|
|
86
|
+
* Live known-folder set (session cwds ∪ pinned directories) every `cwd` is admitted
|
|
87
|
+
* against. Absent → nothing is known (fail closed). See change: core-cwd-admission.
|
|
88
|
+
*/
|
|
89
|
+
knownCwds?: () => string[];
|
|
90
|
+
/** `admitCwd` options: the host's throttled `onIndeterminate` logger + test seams. */
|
|
91
|
+
admitOptions?: AdmitCwdOptions;
|
|
92
|
+
/** Test seam: whole-`remove-batch` admission budget in ms (default 10 000). */
|
|
93
|
+
removeBatchAdmissionBudgetMs?: number;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Admission result of one git-route `cwd`: the canonical cwd to operate on, or the reply body. */
|
|
97
|
+
type GitCwdCheck =
|
|
98
|
+
| { ok: true; cwd: string; token: AdmissionToken }
|
|
99
|
+
| { ok: false; body: ApiResponse; code: string };
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* B20: redact git-derived text against the root the operation ran in. `root` is captured by the
|
|
103
|
+
* caller at operation time (a `const`), never read at broadcast time.
|
|
104
|
+
* See change: harden-git-terminal-plugin-boundaries.
|
|
105
|
+
*/
|
|
106
|
+
const redact = (text: unknown, root?: string): string => redactGitText(text, { root });
|
|
107
|
+
/** Redacted `err.message` (or a thrown string), falling back to `fallback`. */
|
|
108
|
+
const redactErr = (err: unknown, fallback: string, root?: string): string => redact(gitErrorText(err) || fallback, root);
|
|
109
|
+
|
|
110
|
+
/** B1r: the 400 `invalid_ref` envelope (no git process has started). */
|
|
111
|
+
function invalidRef(reply: FastifyReply, what: string): ApiResponse {
|
|
112
|
+
reply.code(400);
|
|
113
|
+
return { success: false, code: INVALID_REF_CODE, error: `invalid ${what}` };
|
|
74
114
|
}
|
|
115
|
+
/** A PRESENT optional ref/path field (absent/null/"" = not supplied) that fails validation. */
|
|
116
|
+
const presentInvalid = (v: unknown): boolean => !isMissingArg(v) && !isValidRefArg(v);
|
|
117
|
+
|
|
118
|
+
/** Whole-batch admission budget for `remove-batch` (design D1). */
|
|
119
|
+
const REMOVE_BATCH_ADMISSION_BUDGET_MS = 10_000;
|
|
120
|
+
/** A runner that never completes a probe: only a direct known-folder match can be admitted with it. */
|
|
121
|
+
const NO_DERIVATION_RUNNER: NonNullable<AdmitCwdOptions["runner"]> = async () => ({
|
|
122
|
+
ok: false,
|
|
123
|
+
error: { kind: "spawn-failure", message: "admission budget exhausted" },
|
|
124
|
+
});
|
|
75
125
|
|
|
76
126
|
/**
|
|
77
127
|
* Per-resolved-checkout cache of the gate result, with a short TTL.
|
|
@@ -157,6 +207,70 @@ function resolveBatchCap(v: unknown): number {
|
|
|
157
207
|
export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps) {
|
|
158
208
|
const { networkGuard, sessionManager, browserGateway, worktreeInitRegistry, sendToSession, commitDraftRelay, removeBatchCap: configuredRemoveBatchCap } = deps;
|
|
159
209
|
const removeBatchCap = resolveBatchCap(configuredRemoveBatchCap);
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Admit a request `cwd` (design D1): `admitRouteCwd`, then branch on
|
|
213
|
+
* `admissionAllows(admission, cwd)` HERE, on the unmodified request value, so static
|
|
214
|
+
* analysis keeps its modelled barrier. Returns the CANONICAL cwd — git runs on the
|
|
215
|
+
* realpath, so a later swap of the raw path cannot redirect the operation. The token is
|
|
216
|
+
* released when the response closes (success, error, throw or disconnect).
|
|
217
|
+
* No filesystem call touches the raw value outside the guard.
|
|
218
|
+
* See change: core-cwd-admission.
|
|
219
|
+
*/
|
|
220
|
+
async function admitGitCwd(
|
|
221
|
+
raw: string,
|
|
222
|
+
reply: FastifyReply,
|
|
223
|
+
admitOptions: AdmitCwdOptions | undefined = deps.admitOptions,
|
|
224
|
+
): Promise<GitCwdCheck> {
|
|
225
|
+
const admission = await admitRouteCwd(raw, { knownCwds: deps.knownCwds, admitOptions });
|
|
226
|
+
if (admission.kind === "indeterminate") {
|
|
227
|
+
return { ok: false, body: sendAdmissionUnavailable(reply), code: "cwd-admission-unavailable" };
|
|
228
|
+
}
|
|
229
|
+
if (admission.kind !== "admit" || !admissionAllows(admission, raw)) {
|
|
230
|
+
reply.code(400);
|
|
231
|
+
return {
|
|
232
|
+
ok: false,
|
|
233
|
+
code: "cwd_unknown",
|
|
234
|
+
body: {
|
|
235
|
+
success: false,
|
|
236
|
+
code: "cwd_unknown",
|
|
237
|
+
error: "cwd is not a known folder; pin the repository to allow git operations",
|
|
238
|
+
} satisfies ApiResponse,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const token = admission.token;
|
|
242
|
+
reply.raw.once("close", () => releaseAdmission(token));
|
|
243
|
+
// The client may have gone while admission ran (`close` already fired): release at once.
|
|
244
|
+
if (reply.raw.destroyed) releaseAdmission(token);
|
|
245
|
+
return { ok: true, cwd: token.canonCwd, token };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* `admitGitCwd` plus the presence and directory checks of the worktree endpoints
|
|
250
|
+
* (`cwd_invalid`: `cwd required` / `cwd does not exist` / `cwd is not a directory`),
|
|
251
|
+
* the latter two only for an ADMITTED cwd. See change: add-worktree-spawn-dialog,
|
|
252
|
+
* core-cwd-admission.
|
|
253
|
+
*/
|
|
254
|
+
async function validateCwd(raw: string | undefined, reply: FastifyReply): Promise<GitCwdCheck> {
|
|
255
|
+
if (!raw || typeof raw !== "string") {
|
|
256
|
+
reply.code(400);
|
|
257
|
+
return { ok: false, code: "cwd_invalid", body: { success: false, code: "cwd_invalid", error: "cwd required" } satisfies ApiResponse };
|
|
258
|
+
}
|
|
259
|
+
const admitted = await admitGitCwd(raw, reply);
|
|
260
|
+
if (!admitted.ok) return admitted;
|
|
261
|
+
const invalid = (error: string): GitCwdCheck => {
|
|
262
|
+
releaseAdmission(admitted.token);
|
|
263
|
+
reply.code(400);
|
|
264
|
+
return { ok: false, code: "cwd_invalid", body: { success: false, code: "cwd_invalid", error } satisfies ApiResponse };
|
|
265
|
+
};
|
|
266
|
+
try {
|
|
267
|
+
const stat = await fs.promises.stat(admitted.cwd);
|
|
268
|
+
if (!stat.isDirectory()) return invalid("cwd is not a directory");
|
|
269
|
+
} catch {
|
|
270
|
+
return invalid("cwd does not exist");
|
|
271
|
+
}
|
|
272
|
+
return admitted;
|
|
273
|
+
}
|
|
160
274
|
/**
|
|
161
275
|
* After a successful worktree Push / Open PR, force a PR-status probe on
|
|
162
276
|
* every bridge whose session cwd is the worktree or inside it (realpath-
|
|
@@ -178,36 +292,44 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
178
292
|
reply.code(400);
|
|
179
293
|
return { success: false, code: "cwd_required", error: "cwd parameter required" } satisfies ApiResponse;
|
|
180
294
|
}
|
|
181
|
-
|
|
295
|
+
const admitted = await admitGitCwd(cwd, reply);
|
|
296
|
+
if (!admitted.ok) return admitted.body;
|
|
297
|
+
if (!isGitRepo(admitted.cwd)) {
|
|
182
298
|
return { success: false, code: "not_a_repo", error: "not a git repository" } satisfies ApiResponse;
|
|
183
299
|
}
|
|
184
300
|
try {
|
|
185
|
-
const data = listBranches(cwd);
|
|
301
|
+
const data = listBranches(admitted.cwd);
|
|
186
302
|
return { success: true, data } satisfies ApiResponse;
|
|
187
303
|
} catch (err: any) {
|
|
188
|
-
return { success: false, code: "list_branches_failed", error: err
|
|
304
|
+
return { success: false, code: "list_branches_failed", error: redactErr(err, "failed to list branches", admitted.cwd) } satisfies ApiResponse;
|
|
189
305
|
}
|
|
190
306
|
},
|
|
191
307
|
);
|
|
192
308
|
|
|
193
|
-
fastify.post<{ Body: { cwd?: string; branch?:
|
|
309
|
+
fastify.post<{ Body: { cwd?: string; branch?: unknown; stash?: boolean } }>(
|
|
194
310
|
"/api/git/checkout",
|
|
195
311
|
{ preHandler: networkGuard },
|
|
196
312
|
async (request, reply) => {
|
|
197
313
|
const { cwd, branch, stash } = request.body ?? {};
|
|
198
|
-
|
|
314
|
+
// Missing (absent / null / "") keeps the existing code; a PRESENT invalid ref is `invalid_ref`
|
|
315
|
+
// (B1r) — checked before admission so nothing (not even a probe) runs for it.
|
|
316
|
+
if (!cwd || isMissingArg(branch)) {
|
|
199
317
|
reply.code(400);
|
|
200
318
|
return { success: false, code: "cwd_and_branch_required", error: "cwd and branch required" } satisfies ApiResponse;
|
|
201
319
|
}
|
|
320
|
+
if (!isValidRefArg(branch)) return invalidRef(reply, "branch");
|
|
321
|
+
const admitted = await admitGitCwd(cwd, reply);
|
|
322
|
+
if (!admitted.ok) return admitted.body;
|
|
202
323
|
try {
|
|
203
|
-
const result = checkoutBranch(cwd, branch, stash ?? false);
|
|
324
|
+
const result = checkoutBranch(admitted.cwd, branch, stash ?? false);
|
|
204
325
|
if (!result.success) {
|
|
205
326
|
reply.code(409);
|
|
206
327
|
return result;
|
|
207
328
|
}
|
|
208
329
|
return { success: true, data: { stashed: result.stashed } } satisfies ApiResponse;
|
|
209
330
|
} catch (err: any) {
|
|
210
|
-
|
|
331
|
+
if (err instanceof InvalidRefError) return invalidRef(reply, "branch");
|
|
332
|
+
return { success: false, code: "checkout_failed", error: redactErr(err, "checkout failed", admitted.cwd) } satisfies ApiResponse;
|
|
211
333
|
}
|
|
212
334
|
},
|
|
213
335
|
);
|
|
@@ -221,11 +343,13 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
221
343
|
reply.code(400);
|
|
222
344
|
return { success: false, code: "cwd_required", error: "cwd required" } satisfies ApiResponse;
|
|
223
345
|
}
|
|
346
|
+
const admitted = await admitGitCwd(cwd, reply);
|
|
347
|
+
if (!admitted.ok) return admitted.body;
|
|
224
348
|
try {
|
|
225
|
-
gitInit(cwd);
|
|
349
|
+
gitInit(admitted.cwd);
|
|
226
350
|
return { success: true } satisfies ApiResponse;
|
|
227
351
|
} catch (err: any) {
|
|
228
|
-
return { success: false, code: "git_init_failed", error: err
|
|
352
|
+
return { success: false, code: "git_init_failed", error: redactErr(err, "init failed", admitted.cwd) } satisfies ApiResponse;
|
|
229
353
|
}
|
|
230
354
|
},
|
|
231
355
|
);
|
|
@@ -238,11 +362,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
238
362
|
"/api/git/status",
|
|
239
363
|
{ preHandler: networkGuard },
|
|
240
364
|
async (request, reply) => {
|
|
241
|
-
const validated = validateCwd(request.query.cwd);
|
|
242
|
-
if (!validated.ok)
|
|
243
|
-
reply.code(400);
|
|
244
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
245
|
-
}
|
|
365
|
+
const validated = await validateCwd(request.query.cwd, reply);
|
|
366
|
+
if (!validated.ok) return validated.body;
|
|
246
367
|
if (!isGitRepo(validated.cwd)) {
|
|
247
368
|
return { success: false, code: "not_a_repo", error: "not a git repository" } satisfies ApiResponse;
|
|
248
369
|
}
|
|
@@ -259,11 +380,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
259
380
|
"/api/git/changed-files",
|
|
260
381
|
{ preHandler: networkGuard },
|
|
261
382
|
async (request, reply) => {
|
|
262
|
-
const validated = validateCwd(request.query.cwd);
|
|
263
|
-
if (!validated.ok)
|
|
264
|
-
reply.code(400);
|
|
265
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
266
|
-
}
|
|
383
|
+
const validated = await validateCwd(request.query.cwd, reply);
|
|
384
|
+
if (!validated.ok) return validated.body;
|
|
267
385
|
if (!isGitRepo(validated.cwd)) {
|
|
268
386
|
return { success: false, code: "not_a_repo", error: "not a git repository" } satisfies ApiResponse;
|
|
269
387
|
}
|
|
@@ -271,7 +389,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
271
389
|
const files = await getChangedFiles(validated.cwd);
|
|
272
390
|
return { success: true, data: files } satisfies ApiResponse;
|
|
273
391
|
} catch (err: any) {
|
|
274
|
-
return { success: false, code: "git_failed", error: err
|
|
392
|
+
return { success: false, code: "git_failed", error: redactErr(err, "failed to list changed files", validated.cwd) } satisfies ApiResponse;
|
|
275
393
|
}
|
|
276
394
|
},
|
|
277
395
|
);
|
|
@@ -284,11 +402,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
284
402
|
{ preHandler: networkGuard },
|
|
285
403
|
async (request, reply) => {
|
|
286
404
|
const { cwd, message, files } = request.body ?? {};
|
|
287
|
-
const validated = validateCwd(cwd);
|
|
288
|
-
if (!validated.ok)
|
|
289
|
-
reply.code(400);
|
|
290
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
291
|
-
}
|
|
405
|
+
const validated = await validateCwd(cwd, reply);
|
|
406
|
+
if (!validated.ok) return validated.body;
|
|
292
407
|
if (typeof message !== "string" || !Array.isArray(files)) {
|
|
293
408
|
reply.code(400);
|
|
294
409
|
return { success: false, code: "bad_request", error: "message and files[] required" } satisfies ApiResponse;
|
|
@@ -311,9 +426,9 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
311
426
|
} catch (err: any) {
|
|
312
427
|
if (err instanceof GitCommitError) {
|
|
313
428
|
reply.code(err.code === "path-escape" || err.code === "no-files" || err.code === "empty-message" ? 400 : 409);
|
|
314
|
-
return { success: false, code: err.code, error: err.message } satisfies ApiResponse;
|
|
429
|
+
return { success: false, code: err.code, error: redact(err.message, validated.cwd) } satisfies ApiResponse;
|
|
315
430
|
}
|
|
316
|
-
return { success: false, code: "commit-failed", error: err
|
|
431
|
+
return { success: false, code: "commit-failed", error: redactErr(err, "commit failed", validated.cwd) } satisfies ApiResponse;
|
|
317
432
|
}
|
|
318
433
|
},
|
|
319
434
|
);
|
|
@@ -325,11 +440,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
325
440
|
{ preHandler: networkGuard },
|
|
326
441
|
async (request, reply) => {
|
|
327
442
|
const { cwd, files, sessionId } = request.body ?? {};
|
|
328
|
-
const validated = validateCwd(cwd);
|
|
329
|
-
if (!validated.ok)
|
|
330
|
-
reply.code(400);
|
|
331
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
332
|
-
}
|
|
443
|
+
const validated = await validateCwd(cwd, reply);
|
|
444
|
+
if (!validated.ok) return validated.body;
|
|
333
445
|
// Every file must be a non-empty string (the diff is built per path).
|
|
334
446
|
if (
|
|
335
447
|
!Array.isArray(files) ||
|
|
@@ -371,11 +483,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
371
483
|
"/api/git/head",
|
|
372
484
|
{ preHandler: networkGuard },
|
|
373
485
|
async (request, reply) => {
|
|
374
|
-
const validated = validateCwd(request.query.cwd);
|
|
375
|
-
if (!validated.ok)
|
|
376
|
-
reply.code(400);
|
|
377
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
378
|
-
}
|
|
486
|
+
const validated = await validateCwd(request.query.cwd, reply);
|
|
487
|
+
if (!validated.ok) return validated.body;
|
|
379
488
|
if (!isGitRepo(validated.cwd)) {
|
|
380
489
|
return { success: false, code: "not_a_repo", error: "not a git repository" } satisfies ApiResponse;
|
|
381
490
|
}
|
|
@@ -383,7 +492,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
383
492
|
const head = readHead(validated.cwd);
|
|
384
493
|
return { success: true, data: head } satisfies ApiResponse;
|
|
385
494
|
} catch (err: any) {
|
|
386
|
-
return { success: false, code: "git_failed", error: err
|
|
495
|
+
return { success: false, code: "git_failed", error: redactErr(err, "failed to read HEAD", validated.cwd) } satisfies ApiResponse;
|
|
387
496
|
}
|
|
388
497
|
},
|
|
389
498
|
);
|
|
@@ -392,11 +501,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
392
501
|
"/api/git/worktrees",
|
|
393
502
|
{ preHandler: networkGuard },
|
|
394
503
|
async (request, reply) => {
|
|
395
|
-
const validated = validateCwd(request.query.cwd);
|
|
396
|
-
if (!validated.ok)
|
|
397
|
-
reply.code(400);
|
|
398
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
399
|
-
}
|
|
504
|
+
const validated = await validateCwd(request.query.cwd, reply);
|
|
505
|
+
if (!validated.ok) return validated.body;
|
|
400
506
|
if (!isGitRepo(validated.cwd)) {
|
|
401
507
|
return { success: false, code: "not_a_repo", error: "not a git repository" } satisfies ApiResponse;
|
|
402
508
|
}
|
|
@@ -404,7 +510,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
404
510
|
const worktrees = listWorktrees(validated.cwd);
|
|
405
511
|
return { success: true, data: { worktrees } } satisfies ApiResponse;
|
|
406
512
|
} catch (err: any) {
|
|
407
|
-
return { success: false, code: "git_failed", error: err
|
|
513
|
+
return { success: false, code: "git_failed", error: redactErr(err, "failed to list worktrees", validated.cwd) } satisfies ApiResponse;
|
|
408
514
|
}
|
|
409
515
|
},
|
|
410
516
|
);
|
|
@@ -417,11 +523,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
417
523
|
"/api/git/worktree/init-status",
|
|
418
524
|
{ preHandler: networkGuard },
|
|
419
525
|
async (request, reply) => {
|
|
420
|
-
const validated = validateCwd(request.query.cwd);
|
|
421
|
-
if (!validated.ok)
|
|
422
|
-
reply.code(400);
|
|
423
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
424
|
-
}
|
|
526
|
+
const validated = await validateCwd(request.query.cwd, reply);
|
|
527
|
+
if (!validated.ok) return validated.body;
|
|
425
528
|
// Config root without a git assumption: a non-git dir with
|
|
426
529
|
// `.pi/settings.json` resolves to itself so its declared hook is read.
|
|
427
530
|
// See change: support-non-git-init-hook.
|
|
@@ -474,7 +577,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
474
577
|
//
|
|
475
578
|
// Runs the declared hook for a checkout. TOFU-gated: an untrusted hook
|
|
476
579
|
// returns `init_untrusted` carrying the def for the client to confirm.
|
|
477
|
-
fastify.post<{ Body: { cwd?: string; requestId?: string; confirmHash?: string; scope?: unknown } }>(
|
|
580
|
+
fastify.post<{ Body: { cwd?: string; requestId?: string; confirmHash?: string; scope?: unknown; piTrust?: boolean } }>(
|
|
478
581
|
"/api/git/worktree/init",
|
|
479
582
|
{ preHandler: networkGuard },
|
|
480
583
|
async (request, reply) => {
|
|
@@ -491,11 +594,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
491
594
|
});
|
|
492
595
|
}
|
|
493
596
|
const body = request.body ?? {};
|
|
494
|
-
const validated = validateCwd(body.cwd);
|
|
495
|
-
if (!validated.ok)
|
|
496
|
-
reply.code(400);
|
|
497
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
498
|
-
}
|
|
597
|
+
const validated = await validateCwd(body.cwd, reply);
|
|
598
|
+
if (!validated.ok) return validated.body;
|
|
499
599
|
// Config root without a git assumption; a `null` root means an
|
|
500
600
|
// unconfigured non-git dir — reuse the existing no-hook envelope, not
|
|
501
601
|
// `not_a_repo`. See change: support-non-git-init-hook.
|
|
@@ -519,7 +619,26 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
519
619
|
return { success: false, code: "bad_request", error: "invalid scope" } satisfies ApiResponse;
|
|
520
620
|
}
|
|
521
621
|
const scope = rawScope === "session" ? "session" : "project";
|
|
522
|
-
|
|
622
|
+
const mirror = scope === "project" ? getPiTrustMirror() : undefined;
|
|
623
|
+
if (mirror) {
|
|
624
|
+
// Choice → trust store (strict) → snapshot; a failure of the first two
|
|
625
|
+
// fails the grant. See change: mirror-dashboard-trust-to-pi.
|
|
626
|
+
try {
|
|
627
|
+
mirror.grant("worktreeInit", configRoot, typeof body.piTrust === "boolean" ? body.piTrust : undefined, () =>
|
|
628
|
+
recordTrust(configRoot, hash, "project", { strict: true }),
|
|
629
|
+
);
|
|
630
|
+
} catch (err) {
|
|
631
|
+
reply.code(500);
|
|
632
|
+
return { success: false, code: "trust_not_recorded", error: `trust not recorded: ${redactErr(err, String(err), configRoot)}` } satisfies ApiResponse;
|
|
633
|
+
}
|
|
634
|
+
} else {
|
|
635
|
+
// "Until the dashboard restarts": the "also trust in pi" choice is held in
|
|
636
|
+
// memory with the entry and never written. See change: mirror-dashboard-trust-live-remote.
|
|
637
|
+
if (scope === "session" && typeof body.piTrust === "boolean") {
|
|
638
|
+
getPiTrustMirror()?.live?.setChoice("worktreeInit", configRoot, body.piTrust);
|
|
639
|
+
}
|
|
640
|
+
recordTrust(configRoot, hash, scope);
|
|
641
|
+
}
|
|
523
642
|
}
|
|
524
643
|
if (!isTrusted(configRoot, hash)) {
|
|
525
644
|
// Echo the hash so the client confirms with `confirmHash` without
|
|
@@ -558,8 +677,11 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
558
677
|
sendIf({ type: "worktree_init_done", requestId: requestId ?? "", cwd, durationMs: runResult.durationMs });
|
|
559
678
|
return { success: true, data: { ran: true, durationMs: runResult.durationMs } } satisfies ApiResponse;
|
|
560
679
|
}
|
|
561
|
-
|
|
562
|
-
|
|
680
|
+
// B20: the mapper sees the RAW stderr (so it can match paths); BOTH the mapped hint and the
|
|
681
|
+
// stderr are redacted AFTER mapping, against the checkout the hook ran in (`cwd`, captured above).
|
|
682
|
+
const rawStderr = runResult.stderr ?? "";
|
|
683
|
+
const hint = redact(mapInitStderrToHint(rawStderr) ?? `init failed (${runResult.code ?? "unknown"})`, cwd);
|
|
684
|
+
const stderr = redact(rawStderr, cwd);
|
|
563
685
|
worktreeInitRegistry?.finishRun(cwd, "failed", runResult.code ?? "init_failed");
|
|
564
686
|
sendIf({ type: "worktree_init_failed", requestId: requestId ?? "", cwd, code: runResult.code ?? "init_failed", message: hint, stderr });
|
|
565
687
|
reply.code(500);
|
|
@@ -568,7 +690,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
568
690
|
);
|
|
569
691
|
|
|
570
692
|
fastify.post<{
|
|
571
|
-
Body: { cwd?: string; base?:
|
|
693
|
+
Body: { cwd?: string; base?: unknown; newBranch?: unknown; path?: unknown; force?: boolean };
|
|
572
694
|
}>(
|
|
573
695
|
"/api/git/worktree",
|
|
574
696
|
{ preHandler: networkGuard },
|
|
@@ -578,42 +700,41 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
578
700
|
// worktree-init hook (GET /init-status + POST /init). See change:
|
|
579
701
|
// generalize-worktree-init-hook.
|
|
580
702
|
const body = request.body ?? {};
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
if (
|
|
703
|
+
// B1r: every PRESENT ref / branch / path is validated before admission or git. `base` absent /
|
|
704
|
+
// null / "" keeps the existing `cwd_invalid` envelope below; `newBranch` absent = checkout mode
|
|
705
|
+
// (a present `null` / "" / non-string is invalid); `path` absent / null / "" = default path.
|
|
706
|
+
// See change: harden-git-terminal-plugin-boundaries.
|
|
707
|
+
if (presentInvalid(body.base)) return invalidRef(reply, "base");
|
|
708
|
+
if (body.newBranch !== undefined && !isValidRefArg(body.newBranch)) return invalidRef(reply, "newBranch");
|
|
709
|
+
if (presentInvalid(body.path)) return invalidRef(reply, "path");
|
|
710
|
+
const validated = await validateCwd(body.cwd, reply);
|
|
711
|
+
if (!validated.ok) return validated.body;
|
|
712
|
+
if (!isValidRefArg(body.base)) {
|
|
587
713
|
reply.code(400);
|
|
588
714
|
return { success: false, code: "cwd_invalid", error: "base required" } satisfies ApiResponse;
|
|
589
715
|
}
|
|
590
|
-
// `newBranch` is optional
|
|
591
|
-
//
|
|
592
|
-
// (checkout mode). See change: worktree-checkout-existing-branch.
|
|
593
|
-
if (body.newBranch !== undefined && typeof body.newBranch !== "string") {
|
|
594
|
-
reply.code(400);
|
|
595
|
-
return { success: false, code: "cwd_invalid", error: "newBranch must be a string" } satisfies ApiResponse;
|
|
596
|
-
}
|
|
716
|
+
// `newBranch` is optional: present → fork mode; absent → the server checks out the existing
|
|
717
|
+
// `base` ref (checkout mode). See change: worktree-checkout-existing-branch.
|
|
597
718
|
const result = addWorktree({
|
|
598
719
|
cwd: validated.cwd,
|
|
599
720
|
base: body.base,
|
|
600
|
-
...(body.newBranch !== undefined ? { newBranch: body.newBranch } : {}),
|
|
601
|
-
path: body.path,
|
|
721
|
+
...(body.newBranch !== undefined ? { newBranch: body.newBranch as string } : {}),
|
|
722
|
+
path: typeof body.path === "string" && body.path.length > 0 ? body.path : undefined,
|
|
602
723
|
force: body.force === true,
|
|
603
724
|
});
|
|
604
725
|
if (!result.ok) {
|
|
605
726
|
const httpStatus =
|
|
606
727
|
result.error === "branch_in_use" || result.error === "branch_exists" || result.error === "path_exists"
|
|
607
728
|
? 409
|
|
608
|
-
: result.error === "not_a_repo" || result.error === "base_not_found"
|
|
729
|
+
: result.error === "not_a_repo" || result.error === "base_not_found" || result.error === "invalid_ref"
|
|
609
730
|
? 400
|
|
610
731
|
: 500;
|
|
611
732
|
reply.code(httpStatus);
|
|
612
733
|
return {
|
|
613
734
|
success: false,
|
|
614
735
|
code: result.error,
|
|
615
|
-
error: result.message,
|
|
616
|
-
...(result.stderr ? { stderr: result.stderr } : {}),
|
|
736
|
+
error: redact(result.message, validated.cwd),
|
|
737
|
+
...(result.stderr ? { stderr: redact(result.stderr, validated.cwd) } : {}),
|
|
617
738
|
...(typeof result.orphanLikely === "boolean" ? { orphanLikely: result.orphanLikely } : {}),
|
|
618
739
|
} satisfies ApiResponse;
|
|
619
740
|
}
|
|
@@ -630,17 +751,16 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
630
751
|
// Unblocks the worktree-spawn dialog when a previous failed attempt
|
|
631
752
|
// left an orphan directory at the target path. Conservative refuse
|
|
632
753
|
// rules — see `orphanCleanup` in `git-operations.ts`.
|
|
633
|
-
fastify.post<{ Body: { cwd?: string; path?:
|
|
754
|
+
fastify.post<{ Body: { cwd?: string; path?: unknown } }>(
|
|
634
755
|
"/api/git/worktree/orphan-cleanup",
|
|
635
756
|
{ preHandler: networkGuard },
|
|
636
757
|
async (request, reply) => {
|
|
637
758
|
const body = request.body ?? {};
|
|
638
|
-
|
|
639
|
-
if (
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
if (!body.path || typeof body.path !== "string") {
|
|
759
|
+
// B1r: a present option-like / control-character path is refused before admission or any fs/git work.
|
|
760
|
+
if (presentInvalid(body.path)) return invalidRef(reply, "path");
|
|
761
|
+
const validated = await validateCwd(body.cwd, reply);
|
|
762
|
+
if (!validated.ok) return validated.body;
|
|
763
|
+
if (!isValidRefArg(body.path)) {
|
|
644
764
|
reply.code(400);
|
|
645
765
|
return { success: false, code: "cwd_invalid", error: "path required" } satisfies ApiResponse;
|
|
646
766
|
}
|
|
@@ -656,14 +776,14 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
656
776
|
result.error === "too_many_files" ||
|
|
657
777
|
result.error === "file_too_large"
|
|
658
778
|
? 409
|
|
659
|
-
: result.error === "outside_repo" || result.error === "not_a_directory"
|
|
779
|
+
: result.error === "outside_repo" || result.error === "not_a_directory" || result.error === "invalid_ref"
|
|
660
780
|
? 400
|
|
661
781
|
: 500;
|
|
662
782
|
reply.code(httpStatus);
|
|
663
783
|
return {
|
|
664
784
|
success: false,
|
|
665
785
|
code: result.error,
|
|
666
|
-
error: result.message,
|
|
786
|
+
error: redact(result.message, validated.cwd),
|
|
667
787
|
} satisfies ApiResponse;
|
|
668
788
|
}
|
|
669
789
|
return { success: true } satisfies ApiResponse;
|
|
@@ -706,11 +826,11 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
706
826
|
{ preHandler: networkGuard },
|
|
707
827
|
async (request, reply) => {
|
|
708
828
|
const body = request.body ?? {};
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
829
|
+
// B1r: the worktree path being removed (`cwd`) is a caller-supplied git argument — an
|
|
830
|
+
// option-like / control-character value is refused before admission or git.
|
|
831
|
+
if (typeof body.cwd === "string" && presentInvalid(body.cwd)) return invalidRef(reply, "path");
|
|
832
|
+
const validated = await validateCwd(body.cwd, reply);
|
|
833
|
+
if (!validated.ok) return validated.body;
|
|
714
834
|
// Removing the main worktree — or one whose main checkout cannot be
|
|
715
835
|
// resolved — is a clean rejection, not a 500 from git (D3).
|
|
716
836
|
const { verdict, mainPath } = classifyRemoval(validated.cwd);
|
|
@@ -756,7 +876,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
756
876
|
success: false,
|
|
757
877
|
code: result.code,
|
|
758
878
|
error: result.code,
|
|
759
|
-
...(result.stderr ? { stderr: result.stderr } : {}),
|
|
879
|
+
...(result.stderr ? { stderr: redact(result.stderr, validated.cwd) } : {}),
|
|
760
880
|
} satisfies ApiResponse;
|
|
761
881
|
}
|
|
762
882
|
stampCwdMissing(validated.cwd);
|
|
@@ -786,45 +906,101 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
786
906
|
}
|
|
787
907
|
// Per-item containment + removal; never abort on first failure (design D4).
|
|
788
908
|
// Classification is PER ITEM (D7): each item is an independent delete
|
|
789
|
-
// decision against live git state — but AT MOST ONCE PER DISTINCT
|
|
790
|
-
// per request:
|
|
791
|
-
// spec forbids resolving the same cwd twice within one request).
|
|
909
|
+
// decision against live git state — but AT MOST ONCE PER DISTINCT checkout
|
|
910
|
+
// per request: items whose canonical cwd is equal reuse the memoized
|
|
911
|
+
// classification (the spec forbids resolving the same cwd twice within one request).
|
|
912
|
+
//
|
|
913
|
+
// Admission (change: core-cwd-admission, D1): sequential, memoized per distinct RAW cwd
|
|
914
|
+
// (the token is bound to the exact string), under a whole-batch budget. Each admission
|
|
915
|
+
// gets `deadlineMs = min(cap, remaining)`; once the budget is spent only a direct
|
|
916
|
+
// known-folder match (no git derivation) can still be decided. Tokens are released in
|
|
917
|
+
// one `finally`; the envelope stays 200 with per-item codes.
|
|
792
918
|
const classificationMemo = new Map<string, { verdict: WorktreeRemovalVerdict; mainPath?: string }>();
|
|
793
|
-
const
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
919
|
+
const admissionMemo = new Map<string, Promise<GitCwdCheck>>();
|
|
920
|
+
const tokens: AdmissionToken[] = [];
|
|
921
|
+
const budgetMs = deps.removeBatchAdmissionBudgetMs ?? REMOVE_BATCH_ADMISSION_BUDGET_MS;
|
|
922
|
+
const capMs = deps.admitOptions?.deadlineMs ?? ADMISSION_DEADLINE_MS;
|
|
923
|
+
const startedAt = Date.now();
|
|
924
|
+
// A scratch reply: a refused/unavailable item must not set the batch's HTTP status.
|
|
925
|
+
const itemReply = { code: () => itemReply, header: () => itemReply, raw: { once: () => undefined } } as unknown as FastifyReply;
|
|
926
|
+
const admitItem = (raw: string): Promise<GitCwdCheck> => {
|
|
927
|
+
let pending = admissionMemo.get(raw);
|
|
928
|
+
if (!pending) {
|
|
929
|
+
const remaining = budgetMs - (Date.now() - startedAt);
|
|
930
|
+
const opts: AdmitCwdOptions =
|
|
931
|
+
remaining > 0
|
|
932
|
+
? { ...deps.admitOptions, deadlineMs: Math.min(capMs, remaining) }
|
|
933
|
+
: { ...deps.admitOptions, runner: NO_DERIVATION_RUNNER };
|
|
934
|
+
pending = (async (): Promise<GitCwdCheck> => {
|
|
935
|
+
const checked = await admitGitCwd(raw, itemReply, opts);
|
|
936
|
+
if (!checked.ok) return checked;
|
|
937
|
+
tokens.push(checked.token);
|
|
938
|
+
const invalid = (error: string): GitCwdCheck => ({ ok: false, code: "cwd_invalid", body: { success: false, code: "cwd_invalid", error } });
|
|
939
|
+
try {
|
|
940
|
+
if (!(await fs.promises.stat(checked.cwd)).isDirectory()) return invalid("cwd is not a directory");
|
|
941
|
+
} catch {
|
|
942
|
+
return invalid("cwd does not exist");
|
|
943
|
+
}
|
|
944
|
+
return checked;
|
|
945
|
+
})();
|
|
946
|
+
admissionMemo.set(raw, pending);
|
|
800
947
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
948
|
+
return pending;
|
|
949
|
+
};
|
|
950
|
+
const results: Array<Record<string, unknown>> = [];
|
|
951
|
+
try {
|
|
952
|
+
for (const item of items) {
|
|
953
|
+
const rawCwd = item?.cwd;
|
|
954
|
+
if (typeof rawCwd === "string" && presentInvalid(rawCwd)) {
|
|
955
|
+
results.push({ cwd: "", ok: false, code: INVALID_REF_CODE });
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
const validated: GitCwdCheck =
|
|
959
|
+
!rawCwd || typeof rawCwd !== "string"
|
|
960
|
+
? { ok: false, code: "cwd_invalid", body: { success: false, code: "cwd_invalid", error: "cwd required" } }
|
|
961
|
+
: await admitItem(rawCwd);
|
|
962
|
+
if (!validated.ok) {
|
|
963
|
+
results.push({ cwd: rawCwd ?? "", ok: false, code: validated.code });
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
let classification = classificationMemo.get(validated.cwd);
|
|
967
|
+
if (!classification) {
|
|
968
|
+
classification = classifyRemoval(validated.cwd);
|
|
969
|
+
classificationMemo.set(validated.cwd, classification);
|
|
970
|
+
}
|
|
971
|
+
const { verdict, mainPath } = classification;
|
|
972
|
+
if (verdict !== "removable") {
|
|
973
|
+
results.push({
|
|
974
|
+
cwd: validated.cwd,
|
|
975
|
+
ok: false,
|
|
976
|
+
code: verdict === "main" ? "is_main_worktree" : "main_checkout_unresolved",
|
|
977
|
+
});
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
const force = item.force === true;
|
|
981
|
+
if (sessionManager) {
|
|
982
|
+
const activeIds = activeSessionsUnder(validated.cwd, sessionManager.listAll());
|
|
983
|
+
if (activeIds.length > 0 && !force) {
|
|
984
|
+
results.push({ cwd: validated.cwd, ok: false, code: "active_sessions", sessionIds: activeIds });
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
const result = removeWorktree({
|
|
804
989
|
cwd: validated.cwd,
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
if (activeIds.length > 0 && !force) {
|
|
813
|
-
return { cwd: validated.cwd, ok: false, code: "active_sessions", sessionIds: activeIds };
|
|
990
|
+
force,
|
|
991
|
+
deleteBranch: item.deleteBranch === true,
|
|
992
|
+
mainPath,
|
|
993
|
+
});
|
|
994
|
+
if (!result.ok) {
|
|
995
|
+
results.push({ cwd: validated.cwd, ok: false, code: result.code, ...(result.stderr ? { stderr: redact(result.stderr, validated.cwd) } : {}) });
|
|
996
|
+
continue;
|
|
814
997
|
}
|
|
998
|
+
stampCwdMissing(validated.cwd);
|
|
999
|
+
results.push({ cwd: validated.cwd, ok: true, code: "ok", ...result.data });
|
|
815
1000
|
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
deleteBranch: item.deleteBranch === true,
|
|
820
|
-
mainPath,
|
|
821
|
-
});
|
|
822
|
-
if (!result.ok) {
|
|
823
|
-
return { cwd: validated.cwd, ok: false, code: result.code, ...(result.stderr ? { stderr: result.stderr } : {}) };
|
|
824
|
-
}
|
|
825
|
-
stampCwdMissing(validated.cwd);
|
|
826
|
-
return { cwd: validated.cwd, ok: true, code: "ok", ...result.data };
|
|
827
|
-
});
|
|
1001
|
+
} finally {
|
|
1002
|
+
for (const t of tokens) releaseAdmission(t);
|
|
1003
|
+
}
|
|
828
1004
|
return { success: true, data: { results } } satisfies ApiResponse;
|
|
829
1005
|
},
|
|
830
1006
|
);
|
|
@@ -833,11 +1009,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
833
1009
|
"/api/git/worktree/prune",
|
|
834
1010
|
{ preHandler: networkGuard },
|
|
835
1011
|
async (request, reply) => {
|
|
836
|
-
const validated = validateCwd((request.body ?? {}).cwd);
|
|
837
|
-
if (!validated.ok)
|
|
838
|
-
reply.code(400);
|
|
839
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
840
|
-
}
|
|
1012
|
+
const validated = await validateCwd((request.body ?? {}).cwd, reply);
|
|
1013
|
+
if (!validated.ok) return validated.body;
|
|
841
1014
|
const result = pruneWorktrees(validated.cwd);
|
|
842
1015
|
if (!result.ok) {
|
|
843
1016
|
reply.code(result.code === "not_a_worktree" ? 400 : 500);
|
|
@@ -852,11 +1025,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
852
1025
|
{ preHandler: networkGuard },
|
|
853
1026
|
async (request, reply) => {
|
|
854
1027
|
const body = request.body ?? {};
|
|
855
|
-
const validated = validateCwd(body.cwd);
|
|
856
|
-
if (!validated.ok)
|
|
857
|
-
reply.code(400);
|
|
858
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
859
|
-
}
|
|
1028
|
+
const validated = await validateCwd(body.cwd, reply);
|
|
1029
|
+
if (!validated.ok) return validated.body;
|
|
860
1030
|
const baseHint = sessionManager
|
|
861
1031
|
? sessionManager.listAll().find((s) => s.cwd === validated.cwd)?.gitWorktreeBase
|
|
862
1032
|
: undefined;
|
|
@@ -876,7 +1046,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
876
1046
|
success: false,
|
|
877
1047
|
code: result.code,
|
|
878
1048
|
error: result.code,
|
|
879
|
-
...(result.stderr ? { stderr: result.stderr } : {}),
|
|
1049
|
+
...(result.stderr ? { stderr: redact(result.stderr, validated.cwd) } : {}),
|
|
880
1050
|
} satisfies ApiResponse;
|
|
881
1051
|
}
|
|
882
1052
|
return { success: true, data: result.data } satisfies ApiResponse;
|
|
@@ -888,11 +1058,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
888
1058
|
{ preHandler: networkGuard },
|
|
889
1059
|
async (request, reply) => {
|
|
890
1060
|
const body = request.body ?? {};
|
|
891
|
-
const validated = validateCwd(body.cwd);
|
|
892
|
-
if (!validated.ok)
|
|
893
|
-
reply.code(400);
|
|
894
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
895
|
-
}
|
|
1061
|
+
const validated = await validateCwd(body.cwd, reply);
|
|
1062
|
+
if (!validated.ok) return validated.body;
|
|
896
1063
|
const result = pushBranch({
|
|
897
1064
|
cwd: validated.cwd,
|
|
898
1065
|
setUpstream: body.setUpstream !== false,
|
|
@@ -907,7 +1074,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
907
1074
|
success: false,
|
|
908
1075
|
code: result.code,
|
|
909
1076
|
error: result.code,
|
|
910
|
-
...(result.stderr ? { stderr: result.stderr } : {}),
|
|
1077
|
+
...(result.stderr ? { stderr: redact(result.stderr, validated.cwd) } : {}),
|
|
911
1078
|
} satisfies ApiResponse;
|
|
912
1079
|
}
|
|
913
1080
|
requestPrRefresh(validated.cwd, "push");
|
|
@@ -920,11 +1087,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
920
1087
|
{ preHandler: networkGuard },
|
|
921
1088
|
async (request, reply) => {
|
|
922
1089
|
const body = request.body ?? {};
|
|
923
|
-
const validated = validateCwd(body.cwd);
|
|
924
|
-
if (!validated.ok)
|
|
925
|
-
reply.code(400);
|
|
926
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
927
|
-
}
|
|
1090
|
+
const validated = await validateCwd(body.cwd, reply);
|
|
1091
|
+
if (!validated.ok) return validated.body;
|
|
928
1092
|
const ghResolved = getDefaultRegistry().resolve("gh");
|
|
929
1093
|
if (!ghResolved.ok || !ghResolved.path) {
|
|
930
1094
|
reply.code(400);
|
|
@@ -955,7 +1119,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
955
1119
|
success: false,
|
|
956
1120
|
code: result.code,
|
|
957
1121
|
error: result.code,
|
|
958
|
-
...(result.stderr ? { stderr: result.stderr } : {}),
|
|
1122
|
+
...(result.stderr ? { stderr: redact(result.stderr, validated.cwd) } : {}),
|
|
959
1123
|
} satisfies ApiResponse;
|
|
960
1124
|
}
|
|
961
1125
|
requestPrRefresh(validated.cwd, "pr");
|
|
@@ -968,11 +1132,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
968
1132
|
"/api/git/pull-requests",
|
|
969
1133
|
{ preHandler: networkGuard },
|
|
970
1134
|
async (request, reply) => {
|
|
971
|
-
const validated = validateCwd(request.query.cwd);
|
|
972
|
-
if (!validated.ok)
|
|
973
|
-
reply.code(400);
|
|
974
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
975
|
-
}
|
|
1135
|
+
const validated = await validateCwd(request.query.cwd, reply);
|
|
1136
|
+
if (!validated.ok) return validated.body;
|
|
976
1137
|
const ghResolved = getDefaultRegistry().resolve("gh");
|
|
977
1138
|
if (!ghResolved.ok || !ghResolved.path) {
|
|
978
1139
|
reply.code(400);
|
|
@@ -989,7 +1150,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
989
1150
|
success: false,
|
|
990
1151
|
code: result.code,
|
|
991
1152
|
error: result.code,
|
|
992
|
-
...(result.stderr ? { stderr: result.stderr } : {}),
|
|
1153
|
+
...(result.stderr ? { stderr: redact(result.stderr, validated.cwd) } : {}),
|
|
993
1154
|
} satisfies ApiResponse;
|
|
994
1155
|
}
|
|
995
1156
|
return { success: true, data: result.data } satisfies ApiResponse;
|
|
@@ -997,21 +1158,20 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
997
1158
|
);
|
|
998
1159
|
|
|
999
1160
|
// ── Create worktree from PR (change: add-worktree-from-pull-request) ────
|
|
1000
|
-
fastify.post<{ Body: { cwd?: string; prNumber?: number; path?:
|
|
1161
|
+
fastify.post<{ Body: { cwd?: string; prNumber?: number; path?: unknown } }>(
|
|
1001
1162
|
"/api/git/worktree/from-pr",
|
|
1002
1163
|
{ preHandler: networkGuard },
|
|
1003
1164
|
async (request, reply) => {
|
|
1004
1165
|
const body = request.body ?? {};
|
|
1005
|
-
|
|
1006
|
-
if (
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
}
|
|
1166
|
+
// B1r: a present option-like / control-character path is refused before admission or git.
|
|
1167
|
+
if (presentInvalid(body.path)) return invalidRef(reply, "path");
|
|
1168
|
+
const validated = await validateCwd(body.cwd, reply);
|
|
1169
|
+
if (!validated.ok) return validated.body;
|
|
1010
1170
|
if (typeof body.prNumber !== "number" || !Number.isInteger(body.prNumber) || body.prNumber <= 0) {
|
|
1011
1171
|
reply.code(400);
|
|
1012
1172
|
return { success: false, code: "cwd_invalid", error: "prNumber required (positive integer)" } satisfies ApiResponse;
|
|
1013
1173
|
}
|
|
1014
|
-
const pathArg =
|
|
1174
|
+
const pathArg = isValidRefArg(body.path) ? body.path : undefined;
|
|
1015
1175
|
const result = addWorktreeFromPr({
|
|
1016
1176
|
cwd: validated.cwd,
|
|
1017
1177
|
prNumber: body.prNumber,
|
|
@@ -1022,14 +1182,14 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
1022
1182
|
result.error === "pr_not_found" ? 404
|
|
1023
1183
|
: result.error === "gh_not_authed" ? 401
|
|
1024
1184
|
: result.error === "branch_in_use" || result.error === "branch_exists" || result.error === "path_exists" ? 409
|
|
1025
|
-
: result.error === "not_a_repo" || result.error === "base_not_found" ? 400
|
|
1185
|
+
: result.error === "not_a_repo" || result.error === "base_not_found" || result.error === "invalid_ref" ? 400
|
|
1026
1186
|
: 500;
|
|
1027
1187
|
reply.code(httpStatus);
|
|
1028
1188
|
return {
|
|
1029
1189
|
success: false,
|
|
1030
1190
|
code: result.error,
|
|
1031
|
-
error: result.message,
|
|
1032
|
-
...(result.stderr ? { stderr: result.stderr } : {}),
|
|
1191
|
+
error: redact(result.message, validated.cwd),
|
|
1192
|
+
...(result.stderr ? { stderr: redact(result.stderr, validated.cwd) } : {}),
|
|
1033
1193
|
...(typeof result.orphanLikely === "boolean" ? { orphanLikely: result.orphanLikely } : {}),
|
|
1034
1194
|
} satisfies ApiResponse;
|
|
1035
1195
|
}
|
|
@@ -1044,11 +1204,8 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
1044
1204
|
"/api/git/worktree/diff-stat",
|
|
1045
1205
|
{ preHandler: networkGuard },
|
|
1046
1206
|
async (request, reply) => {
|
|
1047
|
-
const validated = validateCwd(request.query.cwd);
|
|
1048
|
-
if (!validated.ok)
|
|
1049
|
-
reply.code(400);
|
|
1050
|
-
return { success: false, code: validated.code, error: validated.message } satisfies ApiResponse;
|
|
1051
|
-
}
|
|
1207
|
+
const validated = await validateCwd(request.query.cwd, reply);
|
|
1208
|
+
if (!validated.ok) return validated.body;
|
|
1052
1209
|
const baseHint = sessionManager
|
|
1053
1210
|
? sessionManager.listAll().find((s) => s.cwd === validated.cwd)?.gitWorktreeBase
|
|
1054
1211
|
: undefined;
|
|
@@ -1060,7 +1217,7 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
1060
1217
|
success: false,
|
|
1061
1218
|
code: result.code,
|
|
1062
1219
|
error: result.code,
|
|
1063
|
-
...(result.stderr ? { stderr: result.stderr } : {}),
|
|
1220
|
+
...(result.stderr ? { stderr: redact(result.stderr, validated.cwd) } : {}),
|
|
1064
1221
|
} satisfies ApiResponse;
|
|
1065
1222
|
}
|
|
1066
1223
|
return { success: true, data: result.data } satisfies ApiResponse;
|
|
@@ -1076,40 +1233,14 @@ export function registerGitRoutes(fastify: FastifyInstance, deps: GitRoutesDeps)
|
|
|
1076
1233
|
reply.code(400);
|
|
1077
1234
|
return { success: false, code: "cwd_required", error: "cwd required" } satisfies ApiResponse;
|
|
1078
1235
|
}
|
|
1236
|
+
const admitted = await admitGitCwd(cwd, reply);
|
|
1237
|
+
if (!admitted.ok) return admitted.body;
|
|
1079
1238
|
try {
|
|
1080
|
-
const result = stashPop(cwd);
|
|
1239
|
+
const result = stashPop(admitted.cwd);
|
|
1081
1240
|
return { success: true, data: result } satisfies ApiResponse;
|
|
1082
1241
|
} catch (err: any) {
|
|
1083
|
-
return { success: false, code: "stash_pop_failed", error: err
|
|
1242
|
+
return { success: false, code: "stash_pop_failed", error: redactErr(err, "stash pop failed", admitted.cwd) } satisfies ApiResponse;
|
|
1084
1243
|
}
|
|
1085
1244
|
},
|
|
1086
1245
|
);
|
|
1087
1246
|
}
|
|
1088
|
-
|
|
1089
|
-
/**
|
|
1090
|
-
* Validate and realpath a cwd query / body parameter for the worktree
|
|
1091
|
-
* endpoints. Returns either `{ ok: true, cwd }` (realpath-resolved) or
|
|
1092
|
-
* `{ ok: false, code, message }` with a stable error code.
|
|
1093
|
-
*
|
|
1094
|
-
* See change: add-worktree-spawn-dialog.
|
|
1095
|
-
*/
|
|
1096
|
-
function validateCwd(raw: string | undefined):
|
|
1097
|
-
| { ok: true; cwd: string }
|
|
1098
|
-
| { ok: false; code: "cwd_invalid"; message: string } {
|
|
1099
|
-
// (Field names: `code` is the stable classifier consumed by clients;
|
|
1100
|
-
// `message` is the human-readable string surfaced on the wire as
|
|
1101
|
-
// ApiResponse.error.)
|
|
1102
|
-
if (!raw || typeof raw !== "string") {
|
|
1103
|
-
return { ok: false, code: "cwd_invalid", message: "cwd required" };
|
|
1104
|
-
}
|
|
1105
|
-
const resolved = safeRealpathSync(raw);
|
|
1106
|
-
try {
|
|
1107
|
-
const stat = fs.statSync(resolved);
|
|
1108
|
-
if (!stat.isDirectory()) {
|
|
1109
|
-
return { ok: false, code: "cwd_invalid", message: "cwd is not a directory" };
|
|
1110
|
-
}
|
|
1111
|
-
} catch {
|
|
1112
|
-
return { ok: false, code: "cwd_invalid", message: "cwd does not exist" };
|
|
1113
|
-
}
|
|
1114
|
-
return { ok: true, cwd: resolved };
|
|
1115
|
-
}
|