clinkx 1.2.0 → 1.4.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/CHANGELOG.md +60 -0
- package/README.md +17 -8
- package/clinkx-workflows/dist/architecture-arena/admission.d.ts +16 -0
- package/clinkx-workflows/dist/architecture-arena/admission.js +107 -0
- package/clinkx-workflows/dist/architecture-arena/admission.js.map +1 -0
- package/clinkx-workflows/dist/architecture-arena/contract.d.ts +1368 -0
- package/clinkx-workflows/dist/architecture-arena/contract.js +254 -0
- package/clinkx-workflows/dist/architecture-arena/contract.js.map +1 -0
- package/clinkx-workflows/dist/architecture-arena/runtime.d.ts +53 -0
- package/clinkx-workflows/dist/architecture-arena/runtime.js +511 -0
- package/clinkx-workflows/dist/architecture-arena/runtime.js.map +1 -0
- package/clinkx-workflows/dist/architecture-comparison/admission.d.ts +17 -1
- package/clinkx-workflows/dist/architecture-comparison/admission.js +27 -4
- package/clinkx-workflows/dist/architecture-comparison/admission.js.map +1 -1
- package/clinkx-workflows/dist/architecture-comparison/contract.d.ts +59 -62
- package/clinkx-workflows/dist/architecture-comparison/contract.js +4 -21
- package/clinkx-workflows/dist/architecture-comparison/contract.js.map +1 -1
- package/clinkx-workflows/dist/architecture-comparison/runtime.d.ts +4 -3
- package/clinkx-workflows/dist/architecture-comparison/runtime.js +22 -67
- package/clinkx-workflows/dist/architecture-comparison/runtime.js.map +1 -1
- package/clinkx-workflows/dist/artifacts.d.ts +19 -4
- package/clinkx-workflows/dist/artifacts.js +16 -7
- package/clinkx-workflows/dist/artifacts.js.map +1 -1
- package/clinkx-workflows/dist/backend.d.ts +30 -0
- package/clinkx-workflows/dist/child-env.d.ts +3 -0
- package/clinkx-workflows/dist/child-env.js +11 -0
- package/clinkx-workflows/dist/child-env.js.map +1 -1
- package/clinkx-workflows/dist/clink-client.d.ts +8 -2
- package/clinkx-workflows/dist/clink-client.js +4 -2
- package/clinkx-workflows/dist/clink-client.js.map +1 -1
- package/clinkx-workflows/dist/context-preflight.d.ts +6 -0
- package/clinkx-workflows/dist/context-preflight.js.map +1 -1
- package/clinkx-workflows/dist/council-execution-policy.d.ts +3 -1
- package/clinkx-workflows/dist/council-execution-policy.js +4 -0
- package/clinkx-workflows/dist/council-execution-policy.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/api-routes.d.ts +21 -0
- package/clinkx-workflows/dist/dashboard/api-routes.js +27 -0
- package/clinkx-workflows/dist/dashboard/api-routes.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.d.ts +13 -0
- package/clinkx-workflows/dist/dashboard/auth/challenge-store.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/controller.d.ts +27 -0
- package/clinkx-workflows/dist/dashboard/auth/controller.js +262 -23
- package/clinkx-workflows/dist/dashboard/auth/controller.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.d.ts +62 -0
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js +70 -0
- package/clinkx-workflows/dist/dashboard/auth/settings-step-up.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/contracts.d.ts +586 -586
- package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +28 -28
- package/clinkx-workflows/dist/dashboard/request-admission.d.ts +6 -0
- package/clinkx-workflows/dist/dashboard/request-admission.js +9 -0
- package/clinkx-workflows/dist/dashboard/request-admission.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/server-factory.js +15 -1
- package/clinkx-workflows/dist/dashboard/server-factory.js.map +1 -1
- package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +32 -32
- package/clinkx-workflows/dist/dashboard/settings-contract.d.ts +1806 -0
- package/clinkx-workflows/dist/dashboard/settings-contract.js +630 -0
- package/clinkx-workflows/dist/dashboard/settings-contract.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.d.ts +48 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.js +195 -0
- package/clinkx-workflows/dist/dashboard/settings-process-reader.js.map +1 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.d.ts +87 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.js +690 -0
- package/clinkx-workflows/dist/dashboard/settings-routes.js.map +1 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/index-DSOtuS0p.js +122 -0
- package/clinkx-workflows/dist/dashboard-ui/assets/style-C5guUjwN.css +1 -0
- package/clinkx-workflows/dist/dashboard-ui/index.html +2 -2
- package/clinkx-workflows/dist/delegate-signature.d.ts +4 -3
- package/clinkx-workflows/dist/delegate-signature.js +4 -3
- package/clinkx-workflows/dist/delegate-signature.js.map +1 -1
- package/clinkx-workflows/dist/durable-file-core.d.ts +76 -0
- package/clinkx-workflows/dist/durable-file-core.js +146 -0
- package/clinkx-workflows/dist/durable-file-core.js.map +1 -0
- package/clinkx-workflows/dist/durable-file.d.ts +13 -0
- package/clinkx-workflows/dist/durable-file.js +22 -0
- package/clinkx-workflows/dist/durable-file.js.map +1 -0
- package/clinkx-workflows/dist/engine.d.ts +42 -7
- package/clinkx-workflows/dist/engine.js +196 -24
- package/clinkx-workflows/dist/engine.js.map +1 -1
- package/clinkx-workflows/dist/index.js +68 -2
- package/clinkx-workflows/dist/index.js.map +1 -1
- package/clinkx-workflows/dist/ping-pong/admission.d.ts +127 -0
- package/clinkx-workflows/dist/ping-pong/admission.js +522 -0
- package/clinkx-workflows/dist/ping-pong/admission.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/contract.d.ts +2539 -0
- package/clinkx-workflows/dist/ping-pong/contract.js +819 -0
- package/clinkx-workflows/dist/ping-pong/contract.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/control.d.ts +67 -0
- package/clinkx-workflows/dist/ping-pong/control.js +12 -0
- package/clinkx-workflows/dist/ping-pong/control.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/runtime-handle.d.ts +24 -0
- package/clinkx-workflows/dist/ping-pong/runtime-handle.js +55 -0
- package/clinkx-workflows/dist/ping-pong/runtime-handle.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/runtime.d.ts +235 -0
- package/clinkx-workflows/dist/ping-pong/runtime.js +1183 -0
- package/clinkx-workflows/dist/ping-pong/runtime.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/settle.d.ts +57 -0
- package/clinkx-workflows/dist/ping-pong/settle.js +58 -0
- package/clinkx-workflows/dist/ping-pong/settle.js.map +1 -0
- package/clinkx-workflows/dist/ping-pong/sidecar.d.ts +65 -0
- package/clinkx-workflows/dist/ping-pong/sidecar.js +138 -0
- package/clinkx-workflows/dist/ping-pong/sidecar.js.map +1 -0
- package/clinkx-workflows/dist/plan-review/publication.d.ts +2 -1
- package/clinkx-workflows/dist/plan-review/publication.js +5 -6
- package/clinkx-workflows/dist/plan-review/publication.js.map +1 -1
- package/clinkx-workflows/dist/plan-review/snapshot.d.ts +3 -2
- package/clinkx-workflows/dist/plan-review/snapshot.js +8 -8
- package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -1
- package/clinkx-workflows/dist/recipe-host.d.ts +315 -0
- package/clinkx-workflows/dist/recipe-host.js +183 -0
- package/clinkx-workflows/dist/recipe-host.js.map +1 -0
- package/clinkx-workflows/dist/recipe-seats.d.ts +96 -0
- package/clinkx-workflows/dist/recipe-seats.js +163 -0
- package/clinkx-workflows/dist/recipe-seats.js.map +1 -0
- package/clinkx-workflows/dist/recipe-shared/evidence.d.ts +67 -0
- package/clinkx-workflows/dist/recipe-shared/evidence.js +111 -0
- package/clinkx-workflows/dist/recipe-shared/evidence.js.map +1 -0
- package/clinkx-workflows/dist/reducers/index.d.ts +9 -1
- package/clinkx-workflows/dist/reducers/index.js +30 -0
- package/clinkx-workflows/dist/reducers/index.js.map +1 -1
- package/clinkx-workflows/dist/run-lock-reclaim.d.ts +44 -0
- package/clinkx-workflows/dist/run-lock-reclaim.js +86 -0
- package/clinkx-workflows/dist/run-lock-reclaim.js.map +1 -0
- package/clinkx-workflows/dist/settings/audit.d.ts +101 -0
- package/clinkx-workflows/dist/settings/audit.js +318 -0
- package/clinkx-workflows/dist/settings/audit.js.map +1 -0
- package/clinkx-workflows/dist/settings/bootstrap.d.ts +35 -0
- package/clinkx-workflows/dist/settings/bootstrap.js +52 -0
- package/clinkx-workflows/dist/settings/bootstrap.js.map +1 -0
- package/clinkx-workflows/dist/settings/codec.d.ts +51 -0
- package/clinkx-workflows/dist/settings/codec.js +410 -0
- package/clinkx-workflows/dist/settings/codec.js.map +1 -0
- package/clinkx-workflows/dist/settings/durable-write.d.ts +48 -0
- package/clinkx-workflows/dist/settings/durable-write.js +31 -0
- package/clinkx-workflows/dist/settings/durable-write.js.map +1 -0
- package/clinkx-workflows/dist/settings/index.d.ts +20 -0
- package/clinkx-workflows/dist/settings/index.js +23 -0
- package/clinkx-workflows/dist/settings/index.js.map +1 -0
- package/clinkx-workflows/dist/settings/loader.d.ts +80 -0
- package/clinkx-workflows/dist/settings/loader.js +577 -0
- package/clinkx-workflows/dist/settings/loader.js.map +1 -0
- package/clinkx-workflows/dist/settings/lock.d.ts +108 -0
- package/clinkx-workflows/dist/settings/lock.js +344 -0
- package/clinkx-workflows/dist/settings/lock.js.map +1 -0
- package/clinkx-workflows/dist/settings/paths.d.ts +65 -0
- package/clinkx-workflows/dist/settings/paths.js +173 -0
- package/clinkx-workflows/dist/settings/paths.js.map +1 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.d.ts +47 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.js +305 -0
- package/clinkx-workflows/dist/settings/process-heartbeat.js.map +1 -0
- package/clinkx-workflows/dist/settings/registry.d.ts +178 -0
- package/clinkx-workflows/dist/settings/registry.js +1285 -0
- package/clinkx-workflows/dist/settings/registry.js.map +1 -0
- package/clinkx-workflows/dist/settings/schema.d.ts +404 -0
- package/clinkx-workflows/dist/settings/schema.js +415 -0
- package/clinkx-workflows/dist/settings/schema.js.map +1 -0
- package/clinkx-workflows/dist/settings/store.d.ts +157 -0
- package/clinkx-workflows/dist/settings/store.js +842 -0
- package/clinkx-workflows/dist/settings/store.js.map +1 -0
- package/clinkx-workflows/dist/state-schema.d.ts +11 -0
- package/clinkx-workflows/dist/state-schema.js +4 -1
- package/clinkx-workflows/dist/state-schema.js.map +1 -1
- package/clinkx-workflows/dist/state.d.ts +178 -3
- package/clinkx-workflows/dist/state.js +618 -83
- package/clinkx-workflows/dist/state.js.map +1 -1
- package/clinkx-workflows/dist/stdio-entry.d.ts +2 -0
- package/clinkx-workflows/dist/stdio-entry.js +52 -0
- package/clinkx-workflows/dist/stdio-entry.js.map +1 -0
- package/clinkx-workflows/dist/transport.d.ts +2 -1
- package/clinkx-workflows/dist/transport.js +5 -0
- package/clinkx-workflows/dist/transport.js.map +1 -1
- package/clinkx-workflows/dist/validators/architecture-arena.d.ts +6 -0
- package/clinkx-workflows/dist/validators/architecture-arena.js +16 -0
- package/clinkx-workflows/dist/validators/architecture-arena.js.map +1 -0
- package/clinkx-workflows/dist/validators/index.js +4 -0
- package/clinkx-workflows/dist/validators/index.js.map +1 -1
- package/clinkx-workflows/dist/validators/ping-pong.d.ts +6 -0
- package/clinkx-workflows/dist/validators/ping-pong.js +10 -0
- package/clinkx-workflows/dist/validators/ping-pong.js.map +1 -0
- package/clinkx-workflows/dist/workflow-tools.d.ts +51 -5
- package/clinkx-workflows/dist/workflow-tools.js +785 -34
- package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
- package/clinkx-workflows/dist/workflow-verification-contract.d.ts +4 -4
- package/clinkx-workflows/templates/architecture-arena/candidate.txt +39 -0
- package/clinkx-workflows/templates/architecture-arena/judge.txt +34 -0
- package/clinkx-workflows/templates/ping-pong/implement.txt +14 -0
- package/clinkx-workflows/templates/ping-pong/remediate.txt +14 -0
- package/clinkx-workflows/templates/ping-pong/review.txt +27 -0
- package/clinkx-workflows/workflows/architecture-arena.yaml +127 -0
- package/clinkx-workflows/workflows/ping-pong.yaml +158 -0
- package/dist/context-builder/bundle.js +4 -3
- package/dist/context-builder/bundle.js.map +1 -1
- package/dist/context-builder/delegate-packet.d.ts +1 -0
- package/dist/context-builder/delegate-packet.js +66 -7
- package/dist/context-builder/delegate-packet.js.map +1 -1
- package/dist/context-builder/delegate-validation.d.ts +12 -3
- package/dist/context-builder/delegate-validation.js +23 -13
- package/dist/context-builder/delegate-validation.js.map +1 -1
- package/dist/context-builder/external-gaps.d.ts +14 -3
- package/dist/context-builder/external-gaps.js +124 -18
- package/dist/context-builder/external-gaps.js.map +1 -1
- package/dist/context-builder/handler.js +108 -191
- package/dist/context-builder/handler.js.map +1 -1
- package/dist/context-builder/review-coverage.js +27 -1
- package/dist/context-builder/review-coverage.js.map +1 -1
- package/dist/context-builder/secrets.js +1 -1
- package/dist/context-builder/secrets.js.map +1 -1
- package/dist/context-builder/versions.d.ts +10 -4
- package/dist/context-builder/versions.js +10 -4
- package/dist/context-builder/versions.js.map +1 -1
- package/dist/context-builder/workflow-runner.js +33 -24
- package/dist/context-builder/workflow-runner.js.map +1 -1
- package/dist/dashboard-cli.d.ts +2 -0
- package/dist/dashboard-cli.js +197 -58
- package/dist/dashboard-cli.js.map +1 -1
- package/dist/dashboard-companion/client.d.ts +10 -0
- package/dist/dashboard-companion/client.js +43 -1
- package/dist/dashboard-companion/client.js.map +1 -1
- package/dist/dashboard-companion/config.d.ts +19 -1
- package/dist/dashboard-companion/config.js +104 -3
- package/dist/dashboard-companion/config.js.map +1 -1
- package/dist/dashboard-companion/protocol.d.ts +16 -0
- package/dist/dashboard-companion/protocol.js +55 -1
- package/dist/dashboard-companion/protocol.js.map +1 -1
- package/dist/dashboard-companion/workstation-binding.d.ts +69 -0
- package/dist/dashboard-companion/workstation-binding.js +192 -0
- package/dist/dashboard-companion/workstation-binding.js.map +1 -0
- package/dist/dashboard-gateway/admin-cli.d.ts +10 -0
- package/dist/dashboard-gateway/admin-cli.js +266 -0
- package/dist/dashboard-gateway/admin-cli.js.map +1 -0
- package/dist/dashboard-gateway/config.d.ts +50 -0
- package/dist/dashboard-gateway/config.js +235 -1
- package/dist/dashboard-gateway/config.js.map +1 -1
- package/dist/dashboard-gateway/connection-registry.d.ts +100 -0
- package/dist/dashboard-gateway/connection-registry.js +228 -0
- package/dist/dashboard-gateway/connection-registry.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/account-auth.d.ts +78 -0
- package/dist/dashboard-gateway/control-plane/account-auth.js +198 -0
- package/dist/dashboard-gateway/control-plane/account-auth.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/billing.d.ts +264 -0
- package/dist/dashboard-gateway/control-plane/billing.js +787 -0
- package/dist/dashboard-gateway/control-plane/billing.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/contracts.d.ts +1293 -0
- package/dist/dashboard-gateway/control-plane/contracts.js +280 -0
- package/dist/dashboard-gateway/control-plane/contracts.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/cookies.d.ts +13 -0
- package/dist/dashboard-gateway/control-plane/cookies.js +46 -0
- package/dist/dashboard-gateway/control-plane/cookies.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/credentials.d.ts +63 -0
- package/dist/dashboard-gateway/control-plane/credentials.js +66 -0
- package/dist/dashboard-gateway/control-plane/credentials.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/entitlements.d.ts +118 -0
- package/dist/dashboard-gateway/control-plane/entitlements.js +329 -0
- package/dist/dashboard-gateway/control-plane/entitlements.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/errors.d.ts +17 -0
- package/dist/dashboard-gateway/control-plane/errors.js +23 -0
- package/dist/dashboard-gateway/control-plane/errors.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/hosts.d.ts +6 -0
- package/dist/dashboard-gateway/control-plane/hosts.js +16 -0
- package/dist/dashboard-gateway/control-plane/hosts.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/http.d.ts +34 -0
- package/dist/dashboard-gateway/control-plane/http.js +331 -0
- package/dist/dashboard-gateway/control-plane/http.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/schema.d.ts +9 -0
- package/dist/dashboard-gateway/control-plane/schema.js +247 -0
- package/dist/dashboard-gateway/control-plane/schema.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/secrets.d.ts +20 -0
- package/dist/dashboard-gateway/control-plane/secrets.js +39 -0
- package/dist/dashboard-gateway/control-plane/secrets.js.map +1 -0
- package/dist/dashboard-gateway/control-plane/store.d.ts +579 -0
- package/dist/dashboard-gateway/control-plane/store.js +1115 -0
- package/dist/dashboard-gateway/control-plane/store.js.map +1 -0
- package/dist/dashboard-gateway/cookie-boundary.d.ts +60 -0
- package/dist/dashboard-gateway/cookie-boundary.js +205 -0
- package/dist/dashboard-gateway/cookie-boundary.js.map +1 -0
- package/dist/dashboard-gateway/index.js +271 -494
- package/dist/dashboard-gateway/index.js.map +1 -1
- package/dist/dashboard-gateway/main.js +7 -2
- package/dist/dashboard-gateway/main.js.map +1 -1
- package/dist/dashboard-gateway/routing.d.ts +43 -0
- package/dist/dashboard-gateway/routing.js +65 -0
- package/dist/dashboard-gateway/routing.js.map +1 -0
- package/dist/dashboard-gateway/tenant-gateway.d.ts +56 -0
- package/dist/dashboard-gateway/tenant-gateway.js +989 -0
- package/dist/dashboard-gateway/tenant-gateway.js.map +1 -0
- package/dist/dashboard-gateway/tenant-main.d.ts +41 -0
- package/dist/dashboard-gateway/tenant-main.js +303 -0
- package/dist/dashboard-gateway/tenant-main.js.map +1 -0
- package/dist/dashboard-gateway/tunnel-errors.d.ts +16 -0
- package/dist/dashboard-gateway/tunnel-errors.js +22 -0
- package/dist/dashboard-gateway/tunnel-errors.js.map +1 -0
- package/dist/dashboard-gateway/tunnel-http.d.ts +21 -0
- package/dist/dashboard-gateway/tunnel-http.js +195 -0
- package/dist/dashboard-gateway/tunnel-http.js.map +1 -0
- package/dist/elaris/config.d.ts +10 -0
- package/dist/elaris/config.js +27 -1
- package/dist/elaris/config.js.map +1 -1
- package/dist/elaris/tools.js +4 -1
- package/dist/elaris/tools.js.map +1 -1
- package/dist/handler.d.ts +6 -0
- package/dist/handler.js +17 -1
- package/dist/handler.js.map +1 -1
- package/dist/index.d.ts +0 -31
- package/dist/index.js +41 -404
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +17 -0
- package/dist/lib.js +17 -0
- package/dist/lib.js.map +1 -0
- package/dist/local-clink-backend.d.ts +2 -1
- package/dist/local-clink-backend.js +28 -4
- package/dist/local-clink-backend.js.map +1 -1
- package/dist/parsers/extract.d.ts +19 -1
- package/dist/parsers/extract.js +68 -3
- package/dist/parsers/extract.js.map +1 -1
- package/dist/pipeline.d.ts +17 -1
- package/dist/pipeline.js +34 -6
- package/dist/pipeline.js.map +1 -1
- package/dist/process-group.d.ts +65 -0
- package/dist/process-group.js +153 -0
- package/dist/process-group.js.map +1 -0
- package/dist/progress-report/lock.d.ts +17 -59
- package/dist/progress-report/lock.js +25 -329
- package/dist/progress-report/lock.js.map +1 -1
- package/dist/progress-report/schema.d.ts +23 -23
- package/dist/project-verification/files.js +1 -1
- package/dist/project-verification/files.js.map +1 -1
- package/dist/project-verification/process.js +23 -44
- package/dist/project-verification/process.js.map +1 -1
- package/dist/project-verification/service.js +9 -1
- package/dist/project-verification/service.js.map +1 -1
- package/dist/prompt.d.ts +7 -0
- package/dist/prompt.js +18 -1
- package/dist/prompt.js.map +1 -1
- package/dist/recipe-host/git-trust.d.ts +43 -0
- package/dist/recipe-host/git-trust.js +360 -0
- package/dist/recipe-host/git-trust.js.map +1 -0
- package/dist/recipe-host/git.d.ts +42 -0
- package/dist/recipe-host/git.js +207 -0
- package/dist/recipe-host/git.js.map +1 -0
- package/dist/recipe-host/native-recipe-host.d.ts +127 -0
- package/dist/recipe-host/native-recipe-host.js +880 -0
- package/dist/recipe-host/native-recipe-host.js.map +1 -0
- package/dist/recipe-host/seat-cwd.d.ts +16 -0
- package/dist/recipe-host/seat-cwd.js +170 -0
- package/dist/recipe-host/seat-cwd.js.map +1 -0
- package/dist/runner.d.ts +43 -1
- package/dist/runner.js +234 -35
- package/dist/runner.js.map +1 -1
- package/dist/server.js +84 -5
- package/dist/server.js.map +1 -1
- package/dist/settings-cli/clients.d.ts +137 -0
- package/dist/settings-cli/clients.js +1124 -0
- package/dist/settings-cli/clients.js.map +1 -0
- package/dist/settings-cli/commands.d.ts +67 -0
- package/dist/settings-cli/commands.js +726 -0
- package/dist/settings-cli/commands.js.map +1 -0
- package/dist/settings-cli/format.d.ts +34 -0
- package/dist/settings-cli/format.js +40 -0
- package/dist/settings-cli/format.js.map +1 -0
- package/dist/settings-cli/main.d.ts +18 -0
- package/dist/settings-cli/main.js +256 -0
- package/dist/settings-cli/main.js.map +1 -0
- package/dist/stdio-main.d.ts +73 -0
- package/dist/stdio-main.js +455 -0
- package/dist/stdio-main.js.map +1 -0
- package/docs/configuration.md +362 -40
- package/docs/engineering-recipes.md +291 -0
- package/docs/security.md +234 -6
- package/docs/verification/project-checks.md +24 -2
- package/package.json +6 -2
- package/clinkx-workflows/dist/dashboard-ui/assets/index-BdpmbPps.js +0 -115
- package/clinkx-workflows/dist/dashboard-ui/assets/style-Im5i1iAs.css +0 -1
|
@@ -0,0 +1,880 @@
|
|
|
1
|
+
import { lstat, mkdir, mkdtemp, readdir, readFile, realpath, rm, rmdir } from "node:fs/promises";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
|
+
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { readRecipePruneSummary, RecipeHostError, RecipeVerificationBusyError, } from "../../clinkx-workflows/dist/recipe-host.js";
|
|
7
|
+
import { getClinkxHome, getStateDir } from "../../clinkx-workflows/dist/config.js";
|
|
8
|
+
import { isArtifactOnlyAllowedRootEntry, isPathWithinAllowedRoots, isSamePathOrDescendant, parseAllowedRootsEnv, stripArtifactOnlyMarker, } from "../allowed-roots.js";
|
|
9
|
+
import { logger } from "../logger.js";
|
|
10
|
+
import { ExpectedSchema, ResultSchema } from "../project-verification/contract.js";
|
|
11
|
+
import { readBounded } from "../project-verification/files.js";
|
|
12
|
+
import { DEFAULT_GIT_TIMEOUT_MS, GitExitError, runGit } from "./git.js";
|
|
13
|
+
import { assertGitMetadataDirs, assertGitMetadataUnchanged, computeCandidateWitness, snapshotGitMetadata, WITNESS_LISTING_MAX_BYTES, } from "./git-trust.js";
|
|
14
|
+
/** Run ids and seat names become path segments: no `/`, no `.`/`..`, no leading `-`. */
|
|
15
|
+
const ID_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_-]{0,63}$/;
|
|
16
|
+
const COMMIT_PATTERN = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
17
|
+
export const DEFAULT_MAX_PATCH_BYTES = 16 * 1024 * 1024;
|
|
18
|
+
const MAX_STAT_BYTES = 1024 * 1024;
|
|
19
|
+
export function isValidRecipePathId(value) {
|
|
20
|
+
return ID_PATTERN.test(value);
|
|
21
|
+
}
|
|
22
|
+
function invalidParams(message) {
|
|
23
|
+
return new McpError(ErrorCode.InvalidParams, message);
|
|
24
|
+
}
|
|
25
|
+
function assertId(value, label) {
|
|
26
|
+
if (!isValidRecipePathId(value)) {
|
|
27
|
+
throw invalidParams(`Invalid recipe ${label} ${JSON.stringify(value)}: must match ${ID_PATTERN.source}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function assertCommitId(value) {
|
|
31
|
+
if (!COMMIT_PATTERN.test(value)) {
|
|
32
|
+
throw invalidParams(`Recipe baseline must be a full lowercase commit id, not a ref or working-tree state; got ${JSON.stringify(value)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function errnoCode(error) {
|
|
36
|
+
const code = error?.code;
|
|
37
|
+
return typeof code === "string" ? code : undefined;
|
|
38
|
+
}
|
|
39
|
+
/** Canonicalize the deepest existing ancestor; the missing tail is appended lexically. */
|
|
40
|
+
export function canonicalizeBestEffort(path) {
|
|
41
|
+
const lexical = resolve(path);
|
|
42
|
+
const tail = [];
|
|
43
|
+
let current = lexical;
|
|
44
|
+
for (;;) {
|
|
45
|
+
try {
|
|
46
|
+
return join(realpathSync(current), ...tail.reverse());
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
const parent = dirname(current);
|
|
50
|
+
if (parent === current)
|
|
51
|
+
return lexical;
|
|
52
|
+
tail.push(basename(current));
|
|
53
|
+
current = parent;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const VERIFICATION_SUMMARY_CHARS = 2000;
|
|
58
|
+
/**
|
|
59
|
+
* Report (never delete) an owned seat's registration that survived
|
|
60
|
+
* `git worktree remove`. The path is only lstat-ed: a previously verified
|
|
61
|
+
* admin path can be substituted afterwards (for example a `worktrees`
|
|
62
|
+
* symlink), so any deletion here could reach foreign content. Neither this
|
|
63
|
+
* nor any other cleanup runs `git worktree prune`.
|
|
64
|
+
*/
|
|
65
|
+
async function leftoverRegistration(gitDir, seatPath) {
|
|
66
|
+
try {
|
|
67
|
+
await lstat(gitDir);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (errnoCode(error) === "ENOENT")
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
logger.warn({ git_dir: gitDir, seat: seatPath }, "recipe worktree registration survived git worktree remove; left in place");
|
|
74
|
+
return gitDir;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* True when every check result the runner recorded confirms cleanup
|
|
78
|
+
* (`cleanup_ok`). A check that never started (the runner stops at abort) has
|
|
79
|
+
* no result and confirms nothing more; an unreadable or invalid recorded
|
|
80
|
+
* result counts as unconfirmed.
|
|
81
|
+
*/
|
|
82
|
+
function checksCleanedUp(evidence) {
|
|
83
|
+
let expected;
|
|
84
|
+
try {
|
|
85
|
+
expected = ExpectedSchema.parse(JSON.parse(readBounded(evidence, "expected.json", 2 * 1024 * 1024).toString("utf8")));
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
for (const check of expected.expectations.checks) {
|
|
91
|
+
let bytes;
|
|
92
|
+
try {
|
|
93
|
+
bytes = readBounded(evidence, check.artifact_path, 16 * 1024);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error.code === "ENOENT")
|
|
97
|
+
continue;
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
if (ResultSchema.parse(JSON.parse(bytes.toString("utf8"))).cleanup_ok !== true)
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Identity and delta must see every recorded bit regardless of repo config:
|
|
112
|
+
* with core.filemode=false an exec-bit flip would not change the tree id.
|
|
113
|
+
*/
|
|
114
|
+
const IDENTITY_CONFIG = ["-c", "core.filemode=true", "-c", "core.symlinks=true"];
|
|
115
|
+
function workspaceChanged(path, detail) {
|
|
116
|
+
return new RecipeHostError(`Recipe workspace path ${path} ${detail}; refusing to operate on it (remove it manually if it is stale)`, "workspace_identity");
|
|
117
|
+
}
|
|
118
|
+
/** lstat without following the final component: must be a real directory. */
|
|
119
|
+
async function lstatDirectory(path) {
|
|
120
|
+
const stats = await lstat(path);
|
|
121
|
+
if (stats.isSymbolicLink() || !stats.isDirectory())
|
|
122
|
+
throw workspaceChanged(path, "is not a plain directory");
|
|
123
|
+
return { path, dev: stats.dev, ino: stats.ino };
|
|
124
|
+
}
|
|
125
|
+
/** Re-bind every directory of a chain, top-down, to its recorded identity. */
|
|
126
|
+
async function assertChain(chain) {
|
|
127
|
+
for (const expected of chain) {
|
|
128
|
+
let current;
|
|
129
|
+
try {
|
|
130
|
+
current = await lstatDirectory(expected.path);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (error instanceof RecipeHostError)
|
|
134
|
+
throw error;
|
|
135
|
+
throw workspaceChanged(expected.path, `disappeared (${errnoCode(error) ?? String(error)})`);
|
|
136
|
+
}
|
|
137
|
+
if (current.dev !== expected.dev || current.ino !== expected.ino) {
|
|
138
|
+
throw workspaceChanged(expected.path, "was replaced");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/*
|
|
143
|
+
* Residual race (the only one): Node has no openat/unlinkat-style anchored,
|
|
144
|
+
* no-follow API, so git still receives a path. Every git call that touches a
|
|
145
|
+
* workspace goes through `gitIn`, which re-binds the full home→root→run→seat
|
|
146
|
+
* chain immediately before the spawn and again immediately after it (a
|
|
147
|
+
* post-call mismatch throws and discards the result); rmdir is re-bound
|
|
148
|
+
* immediately before. What remains is the window between the final pre-call
|
|
149
|
+
* recheck and git's own path resolution: a same-user process that substitutes
|
|
150
|
+
* a chain directory inside that window can redirect that one git call (for
|
|
151
|
+
* `worktree remove`, onto another registered worktree of the same repository).
|
|
152
|
+
* A substitution at any earlier point is refused.
|
|
153
|
+
*/
|
|
154
|
+
export class NativeRecipeHost {
|
|
155
|
+
options;
|
|
156
|
+
/** Run dir identities recorded by reserveRunWorkspaces in this process. */
|
|
157
|
+
reserved = new Map();
|
|
158
|
+
/** Seats this instance's createWorkspace started (pending) or completed, per reserved run dir path. */
|
|
159
|
+
created = new Map();
|
|
160
|
+
/** Changed config bytes already shown to keep their non-allowlisted entries, per snapshot and file. */
|
|
161
|
+
acceptedMetadata = new Map();
|
|
162
|
+
constructor(options = {}) {
|
|
163
|
+
this.options = options;
|
|
164
|
+
}
|
|
165
|
+
get env() {
|
|
166
|
+
return this.options.env ?? process.env;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Repository-only git call (never addresses a recipe workspace path). With
|
|
170
|
+
* `gitMetadata`, the D4c drift recheck runs immediately before the spawn,
|
|
171
|
+
* so a planted filter or attribute stops the call before git can run it.
|
|
172
|
+
*/
|
|
173
|
+
async git(args, options = {}) {
|
|
174
|
+
const { gitMetadata, ...runOptions } = options;
|
|
175
|
+
await this.options.beforeGitSpawn?.(args);
|
|
176
|
+
if (gitMetadata !== undefined) {
|
|
177
|
+
await assertGitMetadataUnchanged(gitMetadata, this.listGitConfig, this.acceptedMetadata, runOptions.signal);
|
|
178
|
+
}
|
|
179
|
+
const result = await runGit(args, { timeoutMs: this.options.gitTimeoutMs, gitBinary: this.options.gitBinary, ...runOptions });
|
|
180
|
+
await this.options.afterGitSpawn?.(args);
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
/** Metadata listing for the snapshot and its recheck; spawned directly, outside the hooks and the recheck. */
|
|
184
|
+
listGitConfig = async (path, signal) => (await runGit(["config", "--file", path, "--no-includes", "--list", "-z"], {
|
|
185
|
+
cwd: dirname(path),
|
|
186
|
+
timeoutMs: this.options.gitTimeoutMs,
|
|
187
|
+
gitBinary: this.options.gitBinary,
|
|
188
|
+
maxStdoutBytes: 8 * 1024 * 1024,
|
|
189
|
+
signal,
|
|
190
|
+
operation: "git config --list (metadata)",
|
|
191
|
+
})).stdout;
|
|
192
|
+
async gitOut(args, options = {}) {
|
|
193
|
+
return (await this.git(args, options)).stdout.toString("utf8").trim();
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* The checked spawn wrapper for every workspace git call: re-bind `chain`
|
|
197
|
+
* immediately before and `after` (default `chain`) immediately after.
|
|
198
|
+
*/
|
|
199
|
+
async gitIn(chain, args, options = {}, after = chain) {
|
|
200
|
+
await this.options.beforeGitRecheck?.(args);
|
|
201
|
+
await assertChain(chain);
|
|
202
|
+
const result = await this.git(args, options);
|
|
203
|
+
await assertChain(after);
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
async gitInOut(chain, args, options = {}) {
|
|
207
|
+
return (await this.gitIn(chain, args, options)).stdout.toString("utf8").trim();
|
|
208
|
+
}
|
|
209
|
+
/** Lexical `${CLINKX_HOME}/workspaces`. */
|
|
210
|
+
workspacesRoot() {
|
|
211
|
+
try {
|
|
212
|
+
return join(getClinkxHome(this.env), "workspaces");
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
throw invalidParams(error instanceof Error ? error.message : String(error));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/** Chain [canonical $CLINKX_HOME, workspaces root]; neither may be a symlink at its canonical path. */
|
|
219
|
+
async rootChain() {
|
|
220
|
+
const home = await realpath(dirname(this.workspacesRoot()));
|
|
221
|
+
return [await lstatDirectory(home), await lstatDirectory(join(home, "workspaces"))];
|
|
222
|
+
}
|
|
223
|
+
async assertWorkspaceGrant() {
|
|
224
|
+
const workspacesRoot = canonicalizeBestEffort(this.workspacesRoot());
|
|
225
|
+
let stateDir;
|
|
226
|
+
let unmarked;
|
|
227
|
+
try {
|
|
228
|
+
stateDir = canonicalizeBestEffort(getStateDir(this.env));
|
|
229
|
+
// Missing entries stay lexical in the parser; canonicalize like the target.
|
|
230
|
+
unmarked = parseAllowedRootsEnv({ env: this.env, includeArtifactOnly: false }).map(canonicalizeBestEffort);
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
throw invalidParams(error instanceof Error ? error.message : String(error));
|
|
234
|
+
}
|
|
235
|
+
const covering = unmarked.filter((root) => isPathWithinAllowedRoots(workspacesRoot, [root]));
|
|
236
|
+
const qualifying = covering.find((root) => !isSamePathOrDescendant(stateDir, root));
|
|
237
|
+
if (qualifying !== undefined)
|
|
238
|
+
return { workspacesRoot, grantEntry: qualifying };
|
|
239
|
+
const fix = `Add an unmarked CLINKX_ALLOWED_ROOTS entry for ${workspacesRoot}`;
|
|
240
|
+
if (covering.length > 0) {
|
|
241
|
+
throw invalidParams(`Every unmarked CLINKX_ALLOWED_ROOTS entry covering ${workspacesRoot} is the workflow state dir or its ancestor ` +
|
|
242
|
+
`(${covering.join(", ")}); that would expose state as a context source. ${fix} that is not an ancestor of ${stateDir}.`);
|
|
243
|
+
}
|
|
244
|
+
const markedCovering = (this.env["CLINKX_ALLOWED_ROOTS"] ?? "")
|
|
245
|
+
.split(",")
|
|
246
|
+
.map((entry) => entry.trim())
|
|
247
|
+
.filter((entry) => entry.length > 0 && isArtifactOnlyAllowedRootEntry(entry))
|
|
248
|
+
.some((entry) => isSamePathOrDescendant(workspacesRoot, canonicalizeBestEffort(stripArtifactOnlyMarker(entry))));
|
|
249
|
+
throw invalidParams(markedCovering
|
|
250
|
+
? `Only artifact-only (/.) CLINKX_ALLOWED_ROOTS entries cover ${workspacesRoot}; worktree recipes need an unmarked grant. ${fix}.`
|
|
251
|
+
: `No CLINKX_ALLOWED_ROOTS entry covers ${workspacesRoot}; worktree recipes need it. ${fix}.`);
|
|
252
|
+
}
|
|
253
|
+
async assertRunWorkspacesAbsent(runId) {
|
|
254
|
+
assertId(runId, "run_id");
|
|
255
|
+
try {
|
|
256
|
+
await lstat(join(this.workspacesRoot(), runId));
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
if (errnoCode(error) === "ENOENT")
|
|
260
|
+
return;
|
|
261
|
+
throw new RecipeHostError(`Cannot inspect recipe workspaces for run ${runId}: ${String(error)}`, "workspace_check");
|
|
262
|
+
}
|
|
263
|
+
throw invalidParams(`Recipe workspaces for run_id ${runId} already exist; run_id reuse is not allowed for recipes`);
|
|
264
|
+
}
|
|
265
|
+
async reserveRunWorkspaces(runId) {
|
|
266
|
+
assertId(runId, "run_id");
|
|
267
|
+
await this.assertWorkspaceGrant();
|
|
268
|
+
await mkdir(this.workspacesRoot(), { recursive: true, mode: 0o700 });
|
|
269
|
+
const chain = await this.rootChain();
|
|
270
|
+
const runDir = join(chain[1].path, runId);
|
|
271
|
+
await assertChain(chain);
|
|
272
|
+
try {
|
|
273
|
+
await mkdir(runDir, { mode: 0o700 });
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
if (errnoCode(error) === "EEXIST") {
|
|
277
|
+
throw invalidParams(`Recipe workspaces for run_id ${runId} already exist; run_id reuse is not allowed for recipes`);
|
|
278
|
+
}
|
|
279
|
+
throw new RecipeHostError(`Cannot reserve recipe workspaces for run ${runId}: ${String(error)}`, "workspace_reserve");
|
|
280
|
+
}
|
|
281
|
+
const identity = await lstatDirectory(runDir);
|
|
282
|
+
await assertChain(chain);
|
|
283
|
+
this.reserved.set(runDir, identity);
|
|
284
|
+
return runDir;
|
|
285
|
+
}
|
|
286
|
+
async resolveBaseline(repoRoot, rev, signal) {
|
|
287
|
+
if (rev.length === 0 || rev.length > 256 || rev.includes("\0")) {
|
|
288
|
+
throw invalidParams("Recipe baseline revision must be 1..256 characters with no NUL");
|
|
289
|
+
}
|
|
290
|
+
const top = await this.repoToplevel(repoRoot, signal);
|
|
291
|
+
let commit;
|
|
292
|
+
try {
|
|
293
|
+
commit = await this.gitOut(["-C", top, "rev-parse", "--verify", "--quiet", "--end-of-options", `${rev}^{commit}`], { signal, operation: "git rev-parse baseline" });
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
if (error instanceof GitExitError)
|
|
297
|
+
throw invalidParams(`Recipe baseline ${JSON.stringify(rev)} is not a commit of ${top}`);
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
assertCommitId(commit);
|
|
301
|
+
return commit;
|
|
302
|
+
}
|
|
303
|
+
async createWorkspace(options) {
|
|
304
|
+
const { runId, seat, baseline, signal } = options;
|
|
305
|
+
assertId(runId, "run_id");
|
|
306
|
+
assertId(seat, "seat");
|
|
307
|
+
assertCommitId(baseline);
|
|
308
|
+
const { workspacesRoot } = await this.assertWorkspaceGrant();
|
|
309
|
+
const top = await this.repoToplevel(options.repoRoot, signal);
|
|
310
|
+
if (isSamePathOrDescendant(workspacesRoot, top) || isSamePathOrDescendant(top, workspacesRoot)) {
|
|
311
|
+
throw invalidParams(`Recipe workspaces ${workspacesRoot} must be outside the source repository ${top}`);
|
|
312
|
+
}
|
|
313
|
+
if (await this.resolveBaseline(top, baseline, signal) !== baseline) {
|
|
314
|
+
throw invalidParams(`Recipe baseline ${baseline} is not a commit of ${top}`);
|
|
315
|
+
}
|
|
316
|
+
let rootChain;
|
|
317
|
+
try {
|
|
318
|
+
rootChain = await this.rootChain();
|
|
319
|
+
await lstat(join(rootChain[1].path, runId));
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
if (errnoCode(error) === "ENOENT") {
|
|
323
|
+
throw invalidParams(`Recipe workspaces for run ${runId} are not reserved; call reserveRunWorkspaces first`);
|
|
324
|
+
}
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
const runDir = await lstatDirectory(join(rootChain[1].path, runId));
|
|
328
|
+
const reserved = this.reserved.get(runDir.path);
|
|
329
|
+
if (reserved !== undefined && (reserved.dev !== runDir.dev || reserved.ino !== runDir.ino)) {
|
|
330
|
+
throw workspaceChanged(runDir.path, "was replaced after reservation");
|
|
331
|
+
}
|
|
332
|
+
const runChain = [...rootChain, runDir];
|
|
333
|
+
const expectedCommon = canonicalizeBestEffort(await this.gitOut(["-C", top, "rev-parse", "--path-format=absolute", "--git-common-dir"], { signal, operation: "git rev-parse common dir" }));
|
|
334
|
+
const seatPath = join(runDir.path, seat);
|
|
335
|
+
try {
|
|
336
|
+
await lstat(seatPath);
|
|
337
|
+
throw invalidParams(`Recipe workspace ${seatPath} already exists`);
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
if (errnoCode(error) !== "ENOENT")
|
|
341
|
+
throw error;
|
|
342
|
+
}
|
|
343
|
+
// Ownership record for releaseUnadmittedRun, only for a reserved run dir.
|
|
344
|
+
// Provisional before `worktree add`: a cancel or failure after git
|
|
345
|
+
// registered the seat must still leave it removable by this execution.
|
|
346
|
+
const owned = reserved === undefined ? undefined : this.created.get(runDir.path) ?? new Map();
|
|
347
|
+
if (owned !== undefined) {
|
|
348
|
+
owned.set(seatPath, { commonDir: expectedCommon });
|
|
349
|
+
this.created.set(runDir.path, owned);
|
|
350
|
+
}
|
|
351
|
+
// Absolute gitlinks regardless of user config (git >= 2.48 can write
|
|
352
|
+
// relative ones); validateRecipeSeatCwd accepts only absolute links.
|
|
353
|
+
await this.gitIn(runChain, ["-c", "worktree.useRelativePaths=false", "-C", top, "worktree", "add", "--detach", seatPath, baseline], { signal, operation: "git worktree add" });
|
|
354
|
+
const seatChain = [...runChain, await lstatDirectory(seatPath)];
|
|
355
|
+
const admin = await this.verifyWorktreeAdmin(seatChain, expectedCommon, signal);
|
|
356
|
+
// D4c: the shared metadata as the user left it; every later call of this
|
|
357
|
+
// run rechecks against this snapshot, and so does this call from here on.
|
|
358
|
+
const gitMetadata = await snapshotGitMetadata(admin.commonDir, admin.gitDir, this.listGitConfig, signal);
|
|
359
|
+
const headAtCreate = await this.head(seatChain, signal, gitMetadata);
|
|
360
|
+
if (headAtCreate !== baseline) {
|
|
361
|
+
throw new RecipeHostError(`Recipe workspace ${seatPath} HEAD ${headAtCreate} does not match baseline ${baseline}`, "workspace_create");
|
|
362
|
+
}
|
|
363
|
+
owned?.set(seatPath, { identity: seatChain[3], commonDir: expectedCommon });
|
|
364
|
+
return { path: seatPath, baseline, headAtCreate, gitMetadata };
|
|
365
|
+
}
|
|
366
|
+
/*
|
|
367
|
+
* Identity limits (CONTRACTS 0-3): embedded repositories and submodules are
|
|
368
|
+
* recorded as gitlinks (the nested repo's HEAD commit only), so uncommitted
|
|
369
|
+
* edits inside them change neither the identity, the byte witness nor the
|
|
370
|
+
* captureDelta patch.
|
|
371
|
+
* Capture writes blobs and trees for the snapshot into the source
|
|
372
|
+
* repository's object database as unreachable objects (later reclaimed by
|
|
373
|
+
* git gc); no index, ref or HEAD is modified.
|
|
374
|
+
*/
|
|
375
|
+
async captureIdentity(path, baseline, signal, gitMetadata) {
|
|
376
|
+
return (await this.captureCandidate(path, baseline, signal, gitMetadata)).identity;
|
|
377
|
+
}
|
|
378
|
+
async captureCandidate(path, baseline, signal, gitMetadata) {
|
|
379
|
+
assertCommitId(baseline);
|
|
380
|
+
const seat = await this.locateSeat(path, signal, gitMetadata);
|
|
381
|
+
return this.identityAt(seat, baseline, signal, gitMetadata);
|
|
382
|
+
}
|
|
383
|
+
async assertHeadUnmoved(path, expectedHead, signal, gitMetadata) {
|
|
384
|
+
assertCommitId(expectedHead);
|
|
385
|
+
const seat = await this.locateSeat(path, signal, gitMetadata);
|
|
386
|
+
const head = await this.head(seat.chain, signal, gitMetadata);
|
|
387
|
+
const branch = await this.gitIn(seat.chain, ["-C", seat.real, "symbolic-ref", "-q", "HEAD"], { env: { GIT_CEILING_DIRECTORIES: seat.runDirReal }, allowExitCodes: [1], signal, gitMetadata, operation: "git symbolic-ref" });
|
|
388
|
+
if (head !== expectedHead || branch.exitCode === 0) {
|
|
389
|
+
const where = branch.exitCode === 0 ? `branch ${branch.stdout.toString("utf8").trim()}` : "detached";
|
|
390
|
+
throw new RecipeHostError(`Recipe workspace ${seat.real} HEAD moved: expected detached ${expectedHead}, found ${head} (${where}); writers must not run git`, "head_moved");
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
async captureDelta(path, baseline, options = {}) {
|
|
394
|
+
assertCommitId(baseline);
|
|
395
|
+
const seat = await this.locateSeat(path, options.signal, options.gitMetadata);
|
|
396
|
+
const { identity, witness } = await this.identityAt(seat, baseline, options.signal, options.gitMetadata);
|
|
397
|
+
const maxPatchBytes = options.maxPatchBytes ?? DEFAULT_MAX_PATCH_BYTES;
|
|
398
|
+
const common = { env: { GIT_CEILING_DIRECTORIES: seat.runDirReal }, signal: options.signal, gitMetadata: options.gitMetadata };
|
|
399
|
+
const diffArgs = ["--no-color", "--no-ext-diff", "--no-textconv", "--src-prefix=a/", "--dst-prefix=b/"];
|
|
400
|
+
const patch = (await this.gitIn(seat.chain, [...IDENTITY_CONFIG, "-C", seat.real, "diff", "--binary", ...diffArgs, baseline, identity, "--"], { ...common, maxStdoutBytes: maxPatchBytes, operation: "git diff delta" })).stdout;
|
|
401
|
+
const stat = (await this.gitIn(seat.chain, [...IDENTITY_CONFIG, "-C", seat.real, "diff", "--stat", ...diffArgs, baseline, identity, "--"], { ...common, maxStdoutBytes: MAX_STAT_BYTES, operation: "git diff --stat" })).stdout.toString("utf8");
|
|
402
|
+
return { identity, witness, patch, patchBytes: patch.length, stat };
|
|
403
|
+
}
|
|
404
|
+
async assertBaselineFiles(repoRoot, baseline, paths, signal) {
|
|
405
|
+
assertCommitId(baseline);
|
|
406
|
+
const top = await this.repoToplevel(repoRoot, signal);
|
|
407
|
+
for (const path of paths) {
|
|
408
|
+
if (path.length === 0 || path.length > 512 || path.includes("\0") || path.startsWith("/") ||
|
|
409
|
+
path.split("/").some((part) => part === "" || part === "." || part === "..")) {
|
|
410
|
+
throw invalidParams(`Recipe acceptance path ${JSON.stringify(path)} must be repository-relative without traversal`);
|
|
411
|
+
}
|
|
412
|
+
// argv only; the baseline is a validated full commit id and the path is
|
|
413
|
+
// a literal pathspec after `--`.
|
|
414
|
+
const listing = (await this.git(["-C", top, "ls-tree", "-z", "--full-tree", baseline, "--", path], { env: { GIT_LITERAL_PATHSPECS: "1" }, signal, operation: "git ls-tree acceptance input" })).stdout.toString("utf8");
|
|
415
|
+
const entries = listing.split("\0").filter((entry) => entry !== "");
|
|
416
|
+
const match = entries.length === 1 ? /^(\d{6}) (\w+) [0-9a-f]+\t(.*)$/s.exec(entries[0]) : null;
|
|
417
|
+
if (match === null || match[3] !== path) {
|
|
418
|
+
throw invalidParams(`Recipe acceptance input ${path} is not in baseline commit ${baseline}`);
|
|
419
|
+
}
|
|
420
|
+
if (match[2] !== "blob" || (match[1] !== "100644" && match[1] !== "100755")) {
|
|
421
|
+
throw invalidParams(`Recipe acceptance input ${path} is not a regular file in baseline commit ${baseline} (mode ${match[1]})`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async repositoryToplevel(repoRoot, signal) {
|
|
426
|
+
return this.repoToplevel(repoRoot, signal);
|
|
427
|
+
}
|
|
428
|
+
async describeBaselinePaths(repoRoot, baseline, paths, signal) {
|
|
429
|
+
assertCommitId(baseline);
|
|
430
|
+
const top = await this.repoToplevel(repoRoot, signal);
|
|
431
|
+
const entries = [];
|
|
432
|
+
for (const path of paths) {
|
|
433
|
+
if (path.length === 0 || path.length > 4096 || path.includes("\0") || path.startsWith("/") ||
|
|
434
|
+
path.split("/").some((part) => part === "" || part === "." || part === "..")) {
|
|
435
|
+
throw invalidParams(`Recipe context path ${JSON.stringify(path)} must be repository-relative without traversal`);
|
|
436
|
+
}
|
|
437
|
+
const type = await this.baselineEntryType(top, baseline, path, signal);
|
|
438
|
+
if (type !== "missing") {
|
|
439
|
+
entries.push({ path, type });
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
// Misses only: name the first non-tree ancestor (git does not descend
|
|
443
|
+
// through a symlinked directory, so the path itself is never listed).
|
|
444
|
+
let blockedBy;
|
|
445
|
+
const parts = path.split("/");
|
|
446
|
+
for (let depth = 1; depth < parts.length; depth += 1) {
|
|
447
|
+
const ancestor = parts.slice(0, depth).join("/");
|
|
448
|
+
const ancestorType = await this.baselineEntryType(top, baseline, ancestor, signal);
|
|
449
|
+
if (ancestorType === "tree")
|
|
450
|
+
continue;
|
|
451
|
+
if (ancestorType !== "missing")
|
|
452
|
+
blockedBy = { path: ancestor, type: ancestorType };
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
entries.push({ path, type, ...(blockedBy !== undefined ? { blockedBy } : {}) });
|
|
456
|
+
}
|
|
457
|
+
return entries;
|
|
458
|
+
}
|
|
459
|
+
/** One `git ls-tree` lookup of a literal repository-relative path at `baseline`. */
|
|
460
|
+
async baselineEntryType(top, baseline, path, signal) {
|
|
461
|
+
// argv only; the baseline is a validated full commit id and the path is
|
|
462
|
+
// a literal pathspec after `--`.
|
|
463
|
+
const listing = (await this.git(["-C", top, "ls-tree", "-z", "--full-tree", baseline, "--", path], { env: { GIT_LITERAL_PATHSPECS: "1" }, signal, operation: "git ls-tree context path" })).stdout.toString("utf8");
|
|
464
|
+
const entries = listing.split("\0").filter((entry) => entry !== "");
|
|
465
|
+
const match = entries.length === 1 ? /^(\d{6}) (\w+) [0-9a-f]+\t(.*)$/s.exec(entries[0]) : null;
|
|
466
|
+
if (match === null || match[3] !== path)
|
|
467
|
+
return "missing";
|
|
468
|
+
if (match[1] === "040000" && match[2] === "tree")
|
|
469
|
+
return "tree";
|
|
470
|
+
if (match[1] === "120000")
|
|
471
|
+
return "symlink";
|
|
472
|
+
if (match[1] === "160000")
|
|
473
|
+
return "gitlink";
|
|
474
|
+
return "file";
|
|
475
|
+
}
|
|
476
|
+
async hasUncommittedChanges(repoRoot, signal) {
|
|
477
|
+
const top = await this.repoToplevel(repoRoot, signal);
|
|
478
|
+
// GIT_OPTIONAL_LOCKS=0: status must not refresh (rewrite) the user's index.
|
|
479
|
+
const status = await this.gitOut(["-C", top, "status", "--porcelain", "--untracked-files=normal"], { env: { GIT_OPTIONAL_LOCKS: "0" }, signal, operation: "git status" });
|
|
480
|
+
return status.length > 0;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* 3-7: run the copy-preparation manifest (when declared) and the acceptance
|
|
484
|
+
* manifest against an owned worktree through the shared verification slot.
|
|
485
|
+
* The slot is fail-fast; a busy slot is a typed RecipeVerificationBusyError
|
|
486
|
+
* and nothing ran. Evidence lives outside the worktree; preparation and
|
|
487
|
+
* checks run writer-authored code on the host (not sandboxed).
|
|
488
|
+
*/
|
|
489
|
+
async verifyWorkspace(request) {
|
|
490
|
+
const service = this.options.verification;
|
|
491
|
+
if (service === undefined)
|
|
492
|
+
throw new RecipeHostError("Recipe host has no native verification service", "verification");
|
|
493
|
+
const seat = await this.locateSeat(request.worktree, request.signal, request.gitMetadata);
|
|
494
|
+
if (basename(dirname(seat.real)) !== request.runId) {
|
|
495
|
+
throw invalidParams(`Recipe verification worktree ${seat.real} does not belong to run ${request.runId}`);
|
|
496
|
+
}
|
|
497
|
+
if (!isAbsolute(request.evidenceDir)) {
|
|
498
|
+
throw invalidParams(`Recipe verification evidence dir must be absolute; got ${JSON.stringify(request.evidenceDir)}`);
|
|
499
|
+
}
|
|
500
|
+
// Canonical both ways, before anything is created: evidence inside the
|
|
501
|
+
// worktree would become candidate content, and a worktree inside the
|
|
502
|
+
// evidence dir would be written by the evidence writer.
|
|
503
|
+
const evidenceReal = canonicalizeBestEffort(request.evidenceDir);
|
|
504
|
+
if (isSamePathOrDescendant(evidenceReal, seat.real) || isSamePathOrDescendant(seat.real, evidenceReal)) {
|
|
505
|
+
throw invalidParams("Recipe verification evidence must be outside the worktree and must not contain it");
|
|
506
|
+
}
|
|
507
|
+
let entered = false;
|
|
508
|
+
try {
|
|
509
|
+
return await service.operation(async (native) => {
|
|
510
|
+
entered = true;
|
|
511
|
+
await mkdir(request.evidenceDir, { recursive: false, mode: 0o700 });
|
|
512
|
+
const parts = [];
|
|
513
|
+
let status = "passed";
|
|
514
|
+
let cleanupConfirmed = true;
|
|
515
|
+
const step = async (label, manifest) => {
|
|
516
|
+
const evidence = join(request.evidenceDir, label);
|
|
517
|
+
const result = await native.run({ project: seat.real, manifest, evidence });
|
|
518
|
+
// Exit/cleanup evidence per check: a failed assertion is an ordinary
|
|
519
|
+
// result; an unconfirmed process-group cleanup is not a result at all.
|
|
520
|
+
if (!checksCleanedUp(evidence)) {
|
|
521
|
+
cleanupConfirmed = false;
|
|
522
|
+
// Never `passed`: a check process may still be changing the worktree.
|
|
523
|
+
status = "failed";
|
|
524
|
+
parts.push(`${label}: check cleanup unconfirmed`);
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
const reasons = result.reasons.slice(0, 8).map((reason) => reason.check_id === "" ? reason.code : `${reason.check_id}:${reason.code}`);
|
|
528
|
+
parts.push(`${label}: ${result.status}${reasons.length > 0 ? ` (${reasons.join(", ")})` : ""}`);
|
|
529
|
+
if (result.status === "complete")
|
|
530
|
+
return true;
|
|
531
|
+
status = result.status === "failed" ? "failed" : status === "failed" ? "failed" : "incomplete";
|
|
532
|
+
return false;
|
|
533
|
+
};
|
|
534
|
+
if (request.copyPreparationManifest === undefined || await step("copy-preparation", request.copyPreparationManifest)) {
|
|
535
|
+
await step("acceptance", request.manifest);
|
|
536
|
+
}
|
|
537
|
+
if (status === "incomplete")
|
|
538
|
+
status = "failed";
|
|
539
|
+
return { status, summary: parts.join("; ").slice(0, VERIFICATION_SUMMARY_CHARS), cleanupConfirmed };
|
|
540
|
+
}, request.signal);
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
// Busy only when slot acquisition itself failed, before the callback ran.
|
|
544
|
+
if (!entered && error?.verificationSlotBusy === true) {
|
|
545
|
+
throw new RecipeVerificationBusyError();
|
|
546
|
+
}
|
|
547
|
+
throw error;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* The caller's signal is deliberately not used: rollback usually runs
|
|
552
|
+
* because that signal was aborted, and `runGit` refuses an aborted signal
|
|
553
|
+
* before spawning, so inheriting it would leak the seat. Each git call is
|
|
554
|
+
* instead bounded by a fresh timeout.
|
|
555
|
+
*/
|
|
556
|
+
async releaseUnadmittedRun(runId, _signal) {
|
|
557
|
+
assertId(runId, "run_id");
|
|
558
|
+
const fresh = () => AbortSignal.timeout(this.options.gitTimeoutMs ?? DEFAULT_GIT_TIMEOUT_MS);
|
|
559
|
+
const refuse = (reason) => {
|
|
560
|
+
logger.warn({ run_id: runId, reason }, "refusing recipe workspace cleanup; leaving the run directory in place");
|
|
561
|
+
return { released: false, removed: [], reason };
|
|
562
|
+
};
|
|
563
|
+
let rootChain;
|
|
564
|
+
let runDir;
|
|
565
|
+
try {
|
|
566
|
+
rootChain = await this.rootChain();
|
|
567
|
+
runDir = await lstatDirectory(join(rootChain[1].path, runId));
|
|
568
|
+
}
|
|
569
|
+
catch (error) {
|
|
570
|
+
return refuse(`run directory is not a plain directory (${errnoCode(error) ?? String(error)})`);
|
|
571
|
+
}
|
|
572
|
+
const reservation = this.reserved.get(runDir.path);
|
|
573
|
+
if (reservation === undefined)
|
|
574
|
+
return refuse("no reservation recorded by this host instance");
|
|
575
|
+
if (reservation.dev !== runDir.dev || reservation.ino !== runDir.ino)
|
|
576
|
+
return refuse("run directory was replaced after reservation");
|
|
577
|
+
const runChain = [...rootChain, runDir];
|
|
578
|
+
const owned = this.created.get(runDir.path) ?? new Map();
|
|
579
|
+
const entries = await readdir(runDir.path, { withFileTypes: true });
|
|
580
|
+
await assertChain(runChain);
|
|
581
|
+
// Verify every entry against this instance's records before removing any.
|
|
582
|
+
const seats = [];
|
|
583
|
+
for (const entry of entries) {
|
|
584
|
+
const seatPath = join(runDir.path, entry.name);
|
|
585
|
+
const record = owned.get(seatPath);
|
|
586
|
+
if (record === undefined)
|
|
587
|
+
return refuse(`entry ${entry.name} was not created by this execution`);
|
|
588
|
+
let identity;
|
|
589
|
+
try {
|
|
590
|
+
identity = await lstatDirectory(seatPath);
|
|
591
|
+
}
|
|
592
|
+
catch (error) {
|
|
593
|
+
return refuse(`seat ${entry.name} is not a plain directory (${errnoCode(error) ?? String(error)})`);
|
|
594
|
+
}
|
|
595
|
+
// A pending record has no identity yet; worktree verification below
|
|
596
|
+
// (expected common dir plus back-pointer) is what binds it.
|
|
597
|
+
if (record.identity !== undefined && (identity.dev !== record.identity.dev || identity.ino !== record.identity.ino)) {
|
|
598
|
+
return refuse(`seat ${entry.name} was replaced`);
|
|
599
|
+
}
|
|
600
|
+
const chain = [...runChain, identity];
|
|
601
|
+
let admin;
|
|
602
|
+
try {
|
|
603
|
+
admin = await this.verifyWorktreeAdmin(chain, record.commonDir, fresh());
|
|
604
|
+
}
|
|
605
|
+
catch (error) {
|
|
606
|
+
return refuse(`seat ${entry.name} failed worktree verification: ${error instanceof Error ? error.message : String(error)}`);
|
|
607
|
+
}
|
|
608
|
+
seats.push({ chain, ...admin });
|
|
609
|
+
}
|
|
610
|
+
const removed = [];
|
|
611
|
+
const leftoverRegistrations = [];
|
|
612
|
+
for (const { chain, commonDir, gitDir } of seats) {
|
|
613
|
+
const seatPath = chain[3].path;
|
|
614
|
+
// Own, verified seat with nothing dispatched: --force only covers host
|
|
615
|
+
// side effects (e.g. a partially read checkout), never foreign content.
|
|
616
|
+
await this.gitIn(chain, [`--git-dir=${commonDir}`, "worktree", "remove", "--force", seatPath], { signal: fresh(), operation: "git worktree remove" }, runChain);
|
|
617
|
+
const leftover = await leftoverRegistration(gitDir, seatPath);
|
|
618
|
+
if (leftover !== undefined)
|
|
619
|
+
leftoverRegistrations.push(leftover);
|
|
620
|
+
removed.push(seatPath);
|
|
621
|
+
}
|
|
622
|
+
await assertChain(runChain);
|
|
623
|
+
await rmdir(runDir.path);
|
|
624
|
+
this.reserved.delete(runDir.path);
|
|
625
|
+
this.created.delete(runDir.path);
|
|
626
|
+
return { released: true, removed, ...(leftoverRegistrations.length > 0 ? { leftoverRegistrations } : {}) };
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Cleanup policy B (D6): only seats the sidecar inventory lists, and only
|
|
630
|
+
* when the worktree verifies against the sidecar's repository, are removed.
|
|
631
|
+
* Every other entry (an unlisted directory, a worktree of another
|
|
632
|
+
* repository, a stray file) is left alone and reported in `remaining`, and
|
|
633
|
+
* the run dir stays.
|
|
634
|
+
*/
|
|
635
|
+
async removeWorkspaces(runId, inventory, signal) {
|
|
636
|
+
assertId(runId, "run_id");
|
|
637
|
+
let runChain;
|
|
638
|
+
try {
|
|
639
|
+
const rootChain = await this.rootChain();
|
|
640
|
+
runChain = [...rootChain, await lstatDirectory(join(rootChain[1].path, runId))];
|
|
641
|
+
}
|
|
642
|
+
catch (error) {
|
|
643
|
+
if (errnoCode(error) === "ENOENT")
|
|
644
|
+
return { removed: [] };
|
|
645
|
+
throw error;
|
|
646
|
+
}
|
|
647
|
+
const runDir = runChain[2];
|
|
648
|
+
const inventoried = new Set();
|
|
649
|
+
for (const path of inventory.worktreePaths) {
|
|
650
|
+
const name = basename(path);
|
|
651
|
+
if (!isAbsolute(path) || !isValidRecipePathId(name) || resolve(path) !== join(runDir.path, name)) {
|
|
652
|
+
throw new RecipeHostError(`Recipe sidecar worktree ${path} is not a seat of ${runDir.path}`, "workspace_remove");
|
|
653
|
+
}
|
|
654
|
+
inventoried.add(name);
|
|
655
|
+
}
|
|
656
|
+
const entries = await readdir(runDir.path, { withFileTypes: true });
|
|
657
|
+
await assertChain(runChain);
|
|
658
|
+
const candidates = entries.filter((entry) => inventoried.has(entry.name));
|
|
659
|
+
const expectedCommon = candidates.length === 0 ? undefined : await this.inventoryCommonDir(runId, inventory.repoRoot, signal);
|
|
660
|
+
// Verify every candidate before removing any.
|
|
661
|
+
const seats = [];
|
|
662
|
+
for (const entry of expectedCommon === undefined ? [] : candidates) {
|
|
663
|
+
try {
|
|
664
|
+
const chain = [...runChain, await lstatDirectory(join(runDir.path, entry.name))];
|
|
665
|
+
seats.push({ chain, ...await this.verifyWorktreeAdmin(chain, expectedCommon, signal) });
|
|
666
|
+
}
|
|
667
|
+
catch (error) {
|
|
668
|
+
if (!(error instanceof GitExitError) && !(error instanceof RecipeHostError && error.operation === "workspace_identity"))
|
|
669
|
+
throw error;
|
|
670
|
+
// A substituted run chain is not a per-seat problem: stop everything.
|
|
671
|
+
await assertChain(runChain);
|
|
672
|
+
logger.warn({ run_id: runId, seat: entry.name, err: error.message }, "recipe worktree does not verify against the sidecar repository; left in place");
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
const removed = [];
|
|
676
|
+
const leftoverRegistrations = [];
|
|
677
|
+
for (const { chain, commonDir, gitDir } of seats) {
|
|
678
|
+
const seatPath = chain[3].path;
|
|
679
|
+
// --git-dir (not -C <seat>) so git matches the path against its own worktree registry.
|
|
680
|
+
// The seat is gone afterwards, so only the run chain is re-bound after the call.
|
|
681
|
+
// `worktree remove` drops this seat's registration; a repository-wide
|
|
682
|
+
// `worktree prune` is never run (it would expire unrelated registrations).
|
|
683
|
+
await this.gitIn(chain, [`--git-dir=${commonDir}`, "worktree", "remove", "--force", seatPath], { signal, operation: "git worktree remove" }, runChain);
|
|
684
|
+
const leftover = await leftoverRegistration(gitDir, seatPath);
|
|
685
|
+
if (leftover !== undefined)
|
|
686
|
+
leftoverRegistrations.push(leftover);
|
|
687
|
+
removed.push(seatPath);
|
|
688
|
+
this.created.get(runDir.path)?.delete(seatPath);
|
|
689
|
+
}
|
|
690
|
+
const leftovers = leftoverRegistrations.length > 0 ? { leftoverRegistrations } : {};
|
|
691
|
+
await assertChain(runChain);
|
|
692
|
+
const remaining = (await readdir(runDir.path)).sort();
|
|
693
|
+
if (remaining.length > 0) {
|
|
694
|
+
logger.warn({ run_id: runId, remaining }, "recipe run dir keeps entries outside its verified sidecar inventory; left in place");
|
|
695
|
+
return { removed, remaining, ...leftovers };
|
|
696
|
+
}
|
|
697
|
+
await assertChain(runChain);
|
|
698
|
+
await rmdir(runDir.path);
|
|
699
|
+
// Confirmed gone: a later directory at this path (possibly reusing the
|
|
700
|
+
// inode) must never inherit this reservation or its seat records.
|
|
701
|
+
this.reserved.delete(runDir.path);
|
|
702
|
+
this.created.delete(runDir.path);
|
|
703
|
+
return { removed, ...leftovers };
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* The sidecar repository's common dir, looked up fresh (never from this
|
|
707
|
+
* instance's records, which a restart loses). Undefined when the sidecar
|
|
708
|
+
* names no usable repository: nothing can then be verified, so nothing is
|
|
709
|
+
* removed.
|
|
710
|
+
*/
|
|
711
|
+
async inventoryCommonDir(runId, repoRoot, signal) {
|
|
712
|
+
if (repoRoot === undefined || !isAbsolute(repoRoot) || repoRoot.includes("\0")) {
|
|
713
|
+
logger.warn({ run_id: runId }, "recipe sidecar names no absolute baseline.repo_root; leaving its worktrees");
|
|
714
|
+
return undefined;
|
|
715
|
+
}
|
|
716
|
+
try {
|
|
717
|
+
return canonicalizeBestEffort(await this.gitOut(["-C", repoRoot, "rev-parse", "--path-format=absolute", "--git-common-dir"], { signal, operation: "git rev-parse sidecar common dir" }));
|
|
718
|
+
}
|
|
719
|
+
catch (error) {
|
|
720
|
+
if (!(error instanceof GitExitError))
|
|
721
|
+
throw error;
|
|
722
|
+
logger.warn({ run_id: runId, err: error.message }, "recipe sidecar repository is not a git repository; leaving its worktrees");
|
|
723
|
+
return undefined;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* A seat must be a linked worktree rooted exactly at the chain's seat:
|
|
728
|
+
* toplevel realpath equals the seat, its gitdir is `<common>/worktrees/<name>`,
|
|
729
|
+
* and that gitdir's back-pointer names `<seat>/.git`. Returns the common dir.
|
|
730
|
+
* With `gitMetadata`, both resolved dirs must also be the ones the D4c
|
|
731
|
+
* snapshot was taken for.
|
|
732
|
+
*/
|
|
733
|
+
async verifyWorktree(chain, expectedCommon, signal, gitMetadata) {
|
|
734
|
+
return (await this.verifyWorktreeAdmin(chain, expectedCommon, signal, gitMetadata)).commonDir;
|
|
735
|
+
}
|
|
736
|
+
/** verifyWorktree, also returning the seat's own admin dir (`<common>/worktrees/<name>`). */
|
|
737
|
+
async verifyWorktreeAdmin(chain, expectedCommon, signal, gitMetadata) {
|
|
738
|
+
const seatPath = chain[3].path;
|
|
739
|
+
const lines = (await this.gitInOut(chain, ["-C", seatPath, "rev-parse", "--path-format=absolute", "--show-toplevel", "--git-dir", "--git-common-dir"], { env: { GIT_CEILING_DIRECTORIES: chain[2].path }, signal, gitMetadata, operation: "git rev-parse worktree" })).split("\n");
|
|
740
|
+
if (lines.length !== 3)
|
|
741
|
+
throw workspaceChanged(seatPath, "is not a linked git worktree");
|
|
742
|
+
const [toplevel, gitDir, commonDir] = lines.map((line) => canonicalizeBestEffort(line));
|
|
743
|
+
if (gitMetadata !== undefined)
|
|
744
|
+
assertGitMetadataDirs(gitMetadata, { commonDir, gitDir });
|
|
745
|
+
if (toplevel !== seatPath)
|
|
746
|
+
throw workspaceChanged(seatPath, `is not a worktree root (toplevel ${toplevel})`);
|
|
747
|
+
if (expectedCommon !== undefined && commonDir !== expectedCommon) {
|
|
748
|
+
throw workspaceChanged(seatPath, `belongs to ${commonDir}, not ${expectedCommon}`);
|
|
749
|
+
}
|
|
750
|
+
if (dirname(gitDir) !== join(commonDir, "worktrees")) {
|
|
751
|
+
throw workspaceChanged(seatPath, `has gitdir ${gitDir} outside ${join(commonDir, "worktrees")}`);
|
|
752
|
+
}
|
|
753
|
+
let backPointer;
|
|
754
|
+
try {
|
|
755
|
+
const bytes = await readFile(join(gitDir, "gitdir"));
|
|
756
|
+
if (bytes.length > 4096)
|
|
757
|
+
throw new Error("oversized");
|
|
758
|
+
backPointer = canonicalizeBestEffort(bytes.toString("utf8").trim());
|
|
759
|
+
}
|
|
760
|
+
catch {
|
|
761
|
+
throw workspaceChanged(seatPath, "has no readable worktree back-pointer");
|
|
762
|
+
}
|
|
763
|
+
if (backPointer !== join(seatPath, ".git")) {
|
|
764
|
+
throw workspaceChanged(seatPath, `is registered as ${backPointer}`);
|
|
765
|
+
}
|
|
766
|
+
await assertChain(chain);
|
|
767
|
+
return { commonDir, gitDir };
|
|
768
|
+
}
|
|
769
|
+
async repoToplevel(repoRoot, signal) {
|
|
770
|
+
if (!isAbsolute(repoRoot) || repoRoot.includes("\0")) {
|
|
771
|
+
throw invalidParams(`Recipe repo root must be an absolute path with no NUL; got ${JSON.stringify(repoRoot)}`);
|
|
772
|
+
}
|
|
773
|
+
try {
|
|
774
|
+
return canonicalizeBestEffort(await this.gitOut(["-C", repoRoot, "rev-parse", "--show-toplevel"], { signal, operation: "git rev-parse toplevel" }));
|
|
775
|
+
}
|
|
776
|
+
catch (error) {
|
|
777
|
+
if (error instanceof GitExitError)
|
|
778
|
+
throw invalidParams(`Recipe repo root ${repoRoot} is not inside a git work tree`);
|
|
779
|
+
throw error;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
/** Accept only `<workspaces>/<runId>/<seat>` plain directories that are verified worktrees. */
|
|
783
|
+
async locateSeat(path, signal, gitMetadata) {
|
|
784
|
+
if (!isAbsolute(path))
|
|
785
|
+
throw invalidParams(`Recipe workspace path must be absolute; got ${JSON.stringify(path)}`);
|
|
786
|
+
let rootChain;
|
|
787
|
+
let real;
|
|
788
|
+
try {
|
|
789
|
+
rootChain = await this.rootChain();
|
|
790
|
+
real = await realpath(path);
|
|
791
|
+
}
|
|
792
|
+
catch (error) {
|
|
793
|
+
if (error instanceof RecipeHostError)
|
|
794
|
+
throw error;
|
|
795
|
+
throw invalidParams(`Recipe workspace ${path} does not exist`);
|
|
796
|
+
}
|
|
797
|
+
const root = rootChain[1].path;
|
|
798
|
+
const parts = relative(root, real).split(sep);
|
|
799
|
+
if (parts.length !== 2 || !parts.every(isValidRecipePathId)) {
|
|
800
|
+
throw invalidParams(`Recipe workspace ${path} is not a seat directory under ${root}`);
|
|
801
|
+
}
|
|
802
|
+
const runDirReal = join(root, parts[0]);
|
|
803
|
+
const chain = [...rootChain, await lstatDirectory(runDirReal), await lstatDirectory(join(runDirReal, parts[1]))];
|
|
804
|
+
await this.verifyWorktree(chain, undefined, signal, gitMetadata);
|
|
805
|
+
return { real: chain[3].path, runDirReal, chain };
|
|
806
|
+
}
|
|
807
|
+
async head(chain, signal, gitMetadata) {
|
|
808
|
+
return this.gitInOut(chain, ["-C", chain[3].path, "rev-parse", "--verify", "HEAD"], { env: { GIT_CEILING_DIRECTORIES: chain[2].path }, signal, gitMetadata, operation: "git rev-parse HEAD" });
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* CONTRACTS 0-3: throwaway index in a private temp dir, passed in the child
|
|
812
|
+
* env only. The witness is computed over that index's path list, so tree
|
|
813
|
+
* id and witness describe the same snapshot.
|
|
814
|
+
*/
|
|
815
|
+
async identityAt(seat, baseline, signal, gitMetadata) {
|
|
816
|
+
const indexDir = await mkdtemp(join(tmpdir(), "clinkx-recipe-index-"));
|
|
817
|
+
try {
|
|
818
|
+
const opts = {
|
|
819
|
+
env: { GIT_INDEX_FILE: join(indexDir, "index"), GIT_CEILING_DIRECTORIES: seat.runDirReal },
|
|
820
|
+
signal,
|
|
821
|
+
gitMetadata,
|
|
822
|
+
};
|
|
823
|
+
await this.gitIn(seat.chain, [...IDENTITY_CONFIG, "-C", seat.real, "read-tree", baseline], { ...opts, operation: "git read-tree" });
|
|
824
|
+
await this.gitIn(seat.chain, [...IDENTITY_CONFIG, "-C", seat.real, "add", "-A"], { ...opts, operation: "git add -A" });
|
|
825
|
+
const tree = await this.gitInOut(seat.chain, [...IDENTITY_CONFIG, "-C", seat.real, "write-tree"], { ...opts, operation: "git write-tree" });
|
|
826
|
+
if (!COMMIT_PATTERN.test(tree))
|
|
827
|
+
throw new RecipeHostError(`git write-tree returned an invalid id ${JSON.stringify(tree)}`, "identity");
|
|
828
|
+
const listing = (await this.gitIn(seat.chain, [...IDENTITY_CONFIG, "-C", seat.real, "ls-files", "--stage", "-z"], { ...opts, maxStdoutBytes: WITNESS_LISTING_MAX_BYTES, operation: "git ls-files witness" })).stdout;
|
|
829
|
+
const witness = await computeCandidateWitness(seat.real, listing);
|
|
830
|
+
await assertChain(seat.chain);
|
|
831
|
+
return { identity: tree, witness };
|
|
832
|
+
}
|
|
833
|
+
finally {
|
|
834
|
+
await rm(indexDir, { recursive: true, force: true });
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* CONTRACTS C5 pre-prune observer: remove a recipe run's worktrees only when
|
|
840
|
+
* its sidecar proves zero unresolved operations; otherwise keep the run.
|
|
841
|
+
*/
|
|
842
|
+
export function createRecipePrePruneObserver(host) {
|
|
843
|
+
return async ({ runId, runDir }) => {
|
|
844
|
+
const summary = await readRecipePruneSummary(runDir);
|
|
845
|
+
if (summary.kind !== "read") {
|
|
846
|
+
logger.warn({ run_id: runId, reason: summary.reason }, "recipe sidecar unreadable; keeping run and worktrees");
|
|
847
|
+
return "veto";
|
|
848
|
+
}
|
|
849
|
+
if (summary.unresolvedOperations !== 0 || summary.worktreePaths === undefined) {
|
|
850
|
+
logger.warn({ run_id: runId, unresolved_operations: summary.unresolvedOperations ?? "unknown" }, "recipe run has unresolved operations or unknown worktrees; keeping run and worktrees");
|
|
851
|
+
return "veto";
|
|
852
|
+
}
|
|
853
|
+
if (!isValidRecipePathId(runId)) {
|
|
854
|
+
// No worktree can exist for an id outside the path grammar.
|
|
855
|
+
return summary.worktreePaths.length === 0 ? "allow" : "veto";
|
|
856
|
+
}
|
|
857
|
+
// Lexical comparison against the canonical root: following a symlinked run
|
|
858
|
+
// dir here would let a swapped directory make outside paths look owned.
|
|
859
|
+
const runWorkspaces = join(canonicalizeBestEffort(host.workspacesRoot()), runId);
|
|
860
|
+
const foreign = summary.worktreePaths.filter((path) => !isAbsolute(path) || !isSamePathOrDescendant(resolve(path), runWorkspaces));
|
|
861
|
+
if (foreign.length > 0) {
|
|
862
|
+
logger.warn({ run_id: runId, foreign }, "recipe sidecar names worktrees outside the run's workspaces; keeping run");
|
|
863
|
+
return "veto";
|
|
864
|
+
}
|
|
865
|
+
try {
|
|
866
|
+
const { removed, remaining } = await host.removeWorkspaces(runId, { repoRoot: summary.repoRoot, worktreePaths: summary.worktreePaths });
|
|
867
|
+
logger.info({ run_id: runId, removed: removed.length }, "removed recipe worktrees before pruning run");
|
|
868
|
+
if (remaining !== undefined && remaining.length > 0) {
|
|
869
|
+
logger.warn({ run_id: runId, remaining }, "recipe workspaces still hold unverified entries; keeping run");
|
|
870
|
+
return "veto";
|
|
871
|
+
}
|
|
872
|
+
return "allow";
|
|
873
|
+
}
|
|
874
|
+
catch (error) {
|
|
875
|
+
logger.warn({ run_id: runId, err: error instanceof Error ? error.message : String(error) }, "recipe worktree removal failed; keeping run");
|
|
876
|
+
return "veto";
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
//# sourceMappingURL=native-recipe-host.js.map
|