@aibyzero/cm-workflow 0.10.5
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/.codex-plugin/plugin.json +30 -0
- package/AGENTS.md +74 -0
- package/CONTRIBUTING.md +62 -0
- package/LICENSE +21 -0
- package/README.md +263 -0
- package/SECURITY.md +49 -0
- package/THIRD_PARTY_NOTICES.md +29 -0
- package/VERSION +1 -0
- package/agents/cm-backend-agent.md +34 -0
- package/agents/cm-contract-agent.md +34 -0
- package/agents/cm-database-agent.md +34 -0
- package/agents/cm-frontend-agent.md +33 -0
- package/agents/cm-miniprogram-agent.md +33 -0
- package/agents/cm-ui-agent.md +34 -0
- package/assets/docs/command-picker-mobile.svg +56 -0
- package/assets/docs/command-picker.svg +56 -0
- package/assets/docs/user-guide-hero-mobile.svg +35 -0
- package/assets/docs/user-guide-hero.svg +36 -0
- package/assets/readme/delivery-flow.svg +86 -0
- package/assets/readme/hero.svg +77 -0
- package/assets/readme/recovery-record.svg +73 -0
- package/assets/readme/test-evidence.svg +64 -0
- package/compat/claude-commands/cm-ai.md +3 -0
- package/compat/claude-commands/cm-check.md +3 -0
- package/compat/claude-commands/cm-fix.md +3 -0
- package/compat/claude-commands/cm-idea.md +3 -0
- package/compat/claude-commands/cm-init.md +3 -0
- package/compat/claude-commands/cm-prd.md +3 -0
- package/compat/claude-commands/cm-refactor.md +3 -0
- package/compat/claude-commands/cm-test.md +3 -0
- package/docs/architecture.md +155 -0
- package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-a1-handoff.json +57 -0
- package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-a2-handoff.json +58 -0
- package/docs/fixes/.reviews/fix-cancel-throw-T-FIX-cancel-throw-r1.md +121 -0
- package/docs/fixes/.reviews/fix-cancel-throw-v2-T-FIX-cancel-throw-v2-a1-handoff.json +56 -0
- package/docs/fixes/.reviews/fix-cancel-throw-v2-T-FIX-cancel-throw-v2-r1.md +100 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-a1-handoff.json +61 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-a2-handoff.json +63 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-r1.md +58 -0
- package/docs/fixes/.reviews/fix-cm-js-n1n2-admission-successor-T-FIX-cm-js-n1n2-admission-successor-r2.md +55 -0
- package/docs/fixes/.reviews/fix-f01-dual-failure-terminal-T-FIX-f01-dual-failure-terminal-a1-handoff.json +65 -0
- package/docs/fixes/.reviews/fix-f01-dual-failure-terminal-T-FIX-f01-dual-failure-terminal-r1.md +88 -0
- package/docs/fixes/.reviews/fix-manifest-runtime-checkbox-drift-r1.md +33 -0
- package/docs/fixes/.reviews/fix-manifest-runtime-checkbox-drift-r2.md +31 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-a1-handoff.json +56 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-a2-handoff.json +85 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-r1.md +53 -0
- package/docs/fixes/.reviews/fix-model-call-boundary-identity-T-FIX-model-call-boundary-identity-r2.md +80 -0
- package/docs/fixes/.reviews/fix-review-evidence-scope-honesty-T-FIX-review-evidence-scope-honesty-a1-handoff.json +35 -0
- package/docs/fixes/.reviews/fix-review-evidence-scope-honesty-T-FIX-review-evidence-scope-honesty-r1.md +33 -0
- package/docs/fixes/.reviews/fix-windows-cp1252-log-output-r1.md +30 -0
- package/docs/fixes/.reviews/fix-windows-cp1252-log-output-r2.md +16 -0
- package/docs/fixes/.reviews/openai-compatible-depth-fixture-T-FIX-openai-compatible-depth-fixture-a1-handoff.json +40 -0
- package/docs/fixes/.reviews/openai-compatible-depth-fixture-T-FIX-openai-compatible-depth-fixture-r1.md +30 -0
- package/docs/fixes/20260729-windows-cp1252-log-output.md +65 -0
- package/docs/fixes/20260804-manifest-runtime-checkbox-drift.md +67 -0
- package/docs/fixes/20260806-model-call-boundary-identity.md +80 -0
- package/docs/fixes/20260807-prelanding-integrity.md +58 -0
- package/docs/fixes/20260826-openai-compatible-depth-fixture.md +39 -0
- package/docs/fixes/20260903-cm-js-n1n2-admission-r1.md +64 -0
- package/docs/fixes/20260903-cm-js-n1n2-admission-successor.md +83 -0
- package/docs/fixes/20260903-s4c1b-v3-cancel-throw.md +89 -0
- package/docs/fixes/20260904-f01-codex-dual-failure-terminal.md +89 -0
- package/docs/fixes/20260907-wip-triage-log.md +44 -0
- package/docs/installation.md +202 -0
- package/docs/js-workflow-control.md +1010 -0
- package/docs/sample-prd/prd-funding-rate-alert.md +42 -0
- package/docs/sample-specs/docs//351/234/200/346/261/202/347/244/272/344/276/213.md +24 -0
- package/docs/user-guide.md +526 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/README.md +19 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.excalidraw +3650 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.mp4 +0 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.png +0 -0
- package/docs//351/207/215/346/236/204/346/265/201/347/250/213/350/256/276/350/256/241/refactor-flow.spec.json +223 -0
- package/install-codex.sh +184 -0
- package/install.ps1 +206 -0
- package/install.sh +244 -0
- package/package.json +58 -0
- package/runtime/external-expert.md +302 -0
- package/runtime/js/cm-ai/accepted-fix.mjs +28 -0
- package/runtime/js/cm-ai/claude-developer-adapter.mjs +6 -0
- package/runtime/js/cm-ai/claude-review-adapter.mjs +16 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +53 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +107 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +353 -0
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +217 -0
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +538 -0
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +119 -0
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +172 -0
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +320 -0
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +107 -0
- package/runtime/js/cm-ai/code-projects.mjs +85 -0
- package/runtime/js/cm-ai/codex-config.mjs +48 -0
- package/runtime/js/cm-ai/codex-developer-adapter.mjs +5 -0
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +6 -0
- package/runtime/js/cm-ai/codex-developer-output.schema.json +37 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +73 -0
- package/runtime/js/cm-ai/contracts.mjs +156 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +93 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +504 -0
- package/runtime/js/cm-ai/effect-contract.mjs +102 -0
- package/runtime/js/cm-ai/execution-platform.mjs +7 -0
- package/runtime/js/cm-ai/execution-store.mjs +211 -0
- package/runtime/js/cm-ai/fix-code-association.mjs +40 -0
- package/runtime/js/cm-ai/gate-bridge.mjs +25 -0
- package/runtime/js/cm-ai/host-bootstrap.mjs +170 -0
- package/runtime/js/cm-ai/host-check.mjs +89 -0
- package/runtime/js/cm-ai/host-conversation-execution.mjs +125 -0
- package/runtime/js/cm-ai/host-documentation.mjs +40 -0
- package/runtime/js/cm-ai/host-handoff.mjs +71 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +58 -0
- package/runtime/js/cm-ai/host-qa-executor.mjs +238 -0
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +131 -0
- package/runtime/js/cm-ai/host-qa-fix.mjs +30 -0
- package/runtime/js/cm-ai/host-qa-policy.mjs +70 -0
- package/runtime/js/cm-ai/host-review-authority.mjs +36 -0
- package/runtime/js/cm-ai/host-review-file.mjs +56 -0
- package/runtime/js/cm-ai/host-role-routing.mjs +41 -0
- package/runtime/js/cm-ai/host-session.mjs +96 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +53 -0
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +45 -0
- package/runtime/js/cm-ai/host.mjs +20 -0
- package/runtime/js/cm-ai/index.mjs +7 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +86 -0
- package/runtime/js/cm-ai/qa-fix-definition.mjs +21 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +38 -0
- package/runtime/js/cm-ai/review-package.mjs +426 -0
- package/runtime/js/cm-ai/review-result.schema.json +40 -0
- package/runtime/js/cm-ai/review-runner.mjs +35 -0
- package/runtime/js/cm-ai/task-commit-codec.mjs +54 -0
- package/runtime/js/cm-ai/task-commit.mjs +201 -0
- package/runtime/js/cm-ai/task-owner.mjs +97 -0
- package/runtime/js/cm-ai/task-runner.mjs +766 -0
- package/runtime/js/cm-ai/tool-preview.mjs +205 -0
- package/runtime/js/cm-ai/worker-claude.mjs +104 -0
- package/runtime/js/cm-ai/worker-codex-developer.mjs +124 -0
- package/runtime/js/cm-ai/worker-codex.mjs +143 -0
- package/runtime/js/cm-check/host.mjs +101 -0
- package/runtime/js/cm-fix/baseline.mjs +70 -0
- package/runtime/js/cm-fix/cause-evidence.mjs +24 -0
- package/runtime/js/cm-fix/cause-invocation.mjs +40 -0
- package/runtime/js/cm-fix/cause-package.mjs +68 -0
- package/runtime/js/cm-fix/dossier.mjs +140 -0
- package/runtime/js/cm-fix/execution.mjs +1549 -0
- package/runtime/js/cm-fix/final-review-evidence.mjs +20 -0
- package/runtime/js/cm-fix/final-review.mjs +156 -0
- package/runtime/js/cm-fix/finish.mjs +124 -0
- package/runtime/js/cm-fix/handoff.mjs +64 -0
- package/runtime/js/cm-fix/host-review.mjs +38 -0
- package/runtime/js/cm-fix/host.mjs +96 -0
- package/runtime/js/cm-fix/investigation.mjs +25 -0
- package/runtime/js/cm-fix/layout.mjs +17 -0
- package/runtime/js/cm-fix/learning-writeback.mjs +86 -0
- package/runtime/js/cm-fix/learning.mjs +31 -0
- package/runtime/js/cm-fix/metrics.mjs +75 -0
- package/runtime/js/cm-fix/progress.mjs +64 -0
- package/runtime/js/cm-fix/protected-edits.mjs +95 -0
- package/runtime/js/cm-fix/qa-source.mjs +58 -0
- package/runtime/js/cm-fix/red-test.mjs +92 -0
- package/runtime/js/cm-fix/regression-evidence.mjs +64 -0
- package/runtime/js/cm-fix/regression.mjs +41 -0
- package/runtime/js/cm-fix/repair.mjs +95 -0
- package/runtime/js/cm-fix/reproduce.mjs +54 -0
- package/runtime/js/cm-fix/retrospective.mjs +41 -0
- package/runtime/js/cm-fix/review-baseline.mjs +47 -0
- package/runtime/js/cm-fix/start.mjs +49 -0
- package/runtime/js/cm-fix/test-author.mjs +63 -0
- package/runtime/js/cm-fix/visual.mjs +72 -0
- package/runtime/js/cm-fix/walkthrough.mjs +126 -0
- package/runtime/js/cm-idea/session.mjs +79 -0
- package/runtime/js/cm-init/draft-generation.mjs +66 -0
- package/runtime/js/cm-init/draft-inspection.mjs +70 -0
- package/runtime/js/cm-init/project-analysis.mjs +60 -0
- package/runtime/js/cm-init/project-scan.mjs +55 -0
- package/runtime/js/cm-init/review-evidence.mjs +80 -0
- package/runtime/js/cm-prd/accepted-design.mjs +46 -0
- package/runtime/js/cm-prd/analysis.mjs +260 -0
- package/runtime/js/cm-prd/change.mjs +268 -0
- package/runtime/js/cm-prd/correction-check.mjs +49 -0
- package/runtime/js/cm-prd/design-risk.mjs +30 -0
- package/runtime/js/cm-prd/disposition-plan.mjs +33 -0
- package/runtime/js/cm-prd/draft-save.mjs +122 -0
- package/runtime/js/cm-prd/draft.mjs +70 -0
- package/runtime/js/cm-prd/materials.mjs +48 -0
- package/runtime/js/cm-prd/review-correction.mjs +158 -0
- package/runtime/js/cm-prd/review-disposition.mjs +96 -0
- package/runtime/js/cm-prd/review-findings.mjs +36 -0
- package/runtime/js/cm-prd/review-host.mjs +48 -0
- package/runtime/js/cm-prd/review-preparation.mjs +49 -0
- package/runtime/js/cm-prd/review-publication.mjs +56 -0
- package/runtime/js/cm-prd/self-check.mjs +75 -0
- package/runtime/js/cm-prd/session.mjs +74 -0
- package/runtime/js/cm-prd/summary.mjs +133 -0
- package/runtime/js/cm-refactor/host.mjs +2 -0
- package/runtime/js/cm-refactor/records.mjs +86 -0
- package/runtime/js/cm-refactor/workflow.mjs +478 -0
- package/runtime/js/cm-test/declared-command.mjs +32 -0
- package/runtime/js/cm-test/host.mjs +319 -0
- package/runtime/js/cm-test/logic-results.mjs +39 -0
- package/runtime/js/cm-test/recovery.mjs +58 -0
- package/runtime/js/cm-test/session.mjs +56 -0
- package/runtime/js/cm-test/source-snapshot.mjs +136 -0
- package/runtime/logging.md +207 -0
- package/runtime/model-efficiency.md +201 -0
- package/runtime/orchestration.md +113 -0
- package/runtime/project-context.md +43 -0
- package/runtime/project-learning.md +49 -0
- package/runtime/review.md +140 -0
- package/runtime/steelman-review.md +111 -0
- package/runtime/task-gates.md +283 -0
- package/runtime/task-handoff.schema.json +103 -0
- package/runtime/test-contract.md +212 -0
- package/runtime/workflow-config.md +118 -0
- package/runtime/workflow-routing.md +82 -0
- package/scripts/cm-ai-admission.mjs +50 -0
- package/scripts/cm-ai-admission.test.mjs +38 -0
- package/scripts/cm-ai-batch-host.mjs +77 -0
- package/scripts/cm-ai-batch-host.test.mjs +155 -0
- package/scripts/cm-ai-batch-run.mjs +136 -0
- package/scripts/cm-ai-batch-run.test.mjs +128 -0
- package/scripts/cm-ai-bootstrap.test.mjs +228 -0
- package/scripts/cm-ai-fix-integration.test.mjs +233 -0
- package/scripts/cm-ai-host.mjs +175 -0
- package/scripts/cm-ai-host.test.mjs +368 -0
- package/scripts/cm-ai-multi-root.test.mjs +289 -0
- package/scripts/cm-ai-nested-execution.test.mjs +313 -0
- package/scripts/cm-ai-run.mjs +293 -0
- package/scripts/cm-ai-run.test.mjs +336 -0
- package/scripts/cm-check-entry.mjs +120 -0
- package/scripts/cm-check-host.mjs +29 -0
- package/scripts/cm-check-host.test.mjs +71 -0
- package/scripts/cm-check-runtime.ps1 +69 -0
- package/scripts/cm-check-runtime.sh +910 -0
- package/scripts/cm-claude-probe.test.mjs +54 -0
- package/scripts/cm-claude-review-stream.test.mjs +45 -0
- package/scripts/cm-claude-worker.test.mjs +92 -0
- package/scripts/cm-codex-developer-adapter.test.mjs +85 -0
- package/scripts/cm-codex-developer-worker.test.mjs +128 -0
- package/scripts/cm-codex-review-progress.test.mjs +96 -0
- package/scripts/cm-execution-platform.test.mjs +47 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +72 -0
- package/scripts/cm-fix-cause-package.test.mjs +68 -0
- package/scripts/cm-fix-code-association.test.mjs +55 -0
- package/scripts/cm-fix-entry.mjs +132 -0
- package/scripts/cm-fix-execution.test.mjs +63 -0
- package/scripts/cm-fix-final-review.test.mjs +124 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +34 -0
- package/scripts/cm-fix-host-review.test.mjs +261 -0
- package/scripts/cm-fix-host-sequence.test.mjs +26 -0
- package/scripts/cm-fix-host.mjs +89 -0
- package/scripts/cm-fix-host.test.mjs +105 -0
- package/scripts/cm-fix-learning-writeback.test.mjs +73 -0
- package/scripts/cm-fix-learning.test.mjs +66 -0
- package/scripts/cm-fix-metrics.test.mjs +58 -0
- package/scripts/cm-fix-no-existing-tests.test.mjs +92 -0
- package/scripts/cm-fix-observation-dossier.test.mjs +452 -0
- package/scripts/cm-fix-progress.test.mjs +45 -0
- package/scripts/cm-fix-protected-edits.test.mjs +54 -0
- package/scripts/cm-fix-qa-source.test.mjs +206 -0
- package/scripts/cm-fix-red-owner.test.mjs +143 -0
- package/scripts/cm-fix-red-test.test.mjs +38 -0
- package/scripts/cm-fix-regression.test.mjs +57 -0
- package/scripts/cm-fix-repair-owner.test.mjs +370 -0
- package/scripts/cm-fix-repair.test.mjs +68 -0
- package/scripts/cm-fix-reproduce.test.mjs +31 -0
- package/scripts/cm-fix-retrospective.test.mjs +46 -0
- package/scripts/cm-fix-review-baseline.test.mjs +54 -0
- package/scripts/cm-fix-review-recovery.test.mjs +197 -0
- package/scripts/cm-fix-test-author.test.mjs +105 -0
- package/scripts/cm-fix-visual-bare.test.mjs +171 -0
- package/scripts/cm-fix-walkthrough.test.mjs +45 -0
- package/scripts/cm-host-check.test.mjs +113 -0
- package/scripts/cm-host-documentation.test.mjs +45 -0
- package/scripts/cm-host-handoff.test.mjs +58 -0
- package/scripts/cm-host-qa-executor.test.mjs +156 -0
- package/scripts/cm-host-qa-policy.test.mjs +59 -0
- package/scripts/cm-host-review-authority.test.mjs +60 -0
- package/scripts/cm-host-role-routing.test.mjs +33 -0
- package/scripts/cm-idea-entry.mjs +104 -0
- package/scripts/cm-idea-host.mjs +144 -0
- package/scripts/cm-idea-host.test.mjs +75 -0
- package/scripts/cm-idea-recovery.test.mjs +90 -0
- package/scripts/cm-init-analysis-host.test.mjs +50 -0
- package/scripts/cm-init-draft-generation.test.mjs +52 -0
- package/scripts/cm-init-draft-inspection.test.mjs +41 -0
- package/scripts/cm-init-entry.mjs +170 -0
- package/scripts/cm-init-host.mjs +284 -0
- package/scripts/cm-init-host.test.mjs +231 -0
- package/scripts/cm-init-project-analysis.test.mjs +47 -0
- package/scripts/cm-init-project-scan.test.mjs +41 -0
- package/scripts/cm-init-revision-host.test.mjs +61 -0
- package/scripts/cm-init-session.test.mjs +122 -0
- package/scripts/cm-log-event.mjs +538 -0
- package/scripts/cm-log-event.py +133 -0
- package/scripts/cm-log-event.test.mjs +70 -0
- package/scripts/cm-openai-compatible-call.py +661 -0
- package/scripts/cm-prd-analysis.test.mjs +67 -0
- package/scripts/cm-prd-completion.test.mjs +190 -0
- package/scripts/cm-prd-design-phase.test.mjs +296 -0
- package/scripts/cm-prd-draft-save.test.mjs +63 -0
- package/scripts/cm-prd-draft.test.mjs +39 -0
- package/scripts/cm-prd-entry.mjs +245 -0
- package/scripts/cm-prd-host.mjs +273 -0
- package/scripts/cm-prd-host.test.mjs +169 -0
- package/scripts/cm-prd-materials.test.mjs +41 -0
- package/scripts/cm-prd-review-claim.test.mjs +42 -0
- package/scripts/cm-prd-review-disposition.test.mjs +196 -0
- package/scripts/cm-prd-review-gate.mjs +194 -0
- package/scripts/cm-prd-review-gate.py +26 -0
- package/scripts/cm-prd-review-host.test.mjs +30 -0
- package/scripts/cm-prd-review-preparation.test.mjs +69 -0
- package/scripts/cm-prd-review-publication.test.mjs +95 -0
- package/scripts/cm-prd-revision.test.mjs +32 -0
- package/scripts/cm-prd-self-check.test.mjs +23 -0
- package/scripts/cm-prd-sources.test.mjs +76 -0
- package/scripts/cm-prd-timing.py +272 -0
- package/scripts/cm-refactor-entry.mjs +145 -0
- package/scripts/cm-refactor-host.mjs +26 -0
- package/scripts/cm-refactor-host.test.mjs +201 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +67 -0
- package/scripts/cm-review-inventory.test.mjs +109 -0
- package/scripts/cm-spec-manifest.mjs +104 -0
- package/scripts/cm-spec-manifest.py +26 -0
- package/scripts/cm-task-gate.mjs +879 -0
- package/scripts/cm-task-gate.py +312 -0
- package/scripts/cm-task-gate.test.mjs +202 -0
- package/scripts/cm-test-declared-command.test.mjs +18 -0
- package/scripts/cm-test-entry.mjs +231 -0
- package/scripts/cm-test-host.mjs +40 -0
- package/scripts/cm-test-host.test.mjs +169 -0
- package/scripts/cm-test-logic-results.test.mjs +26 -0
- package/scripts/cm-test-session.test.mjs +138 -0
- package/scripts/cm-usage-report.py +516 -0
- package/scripts/cm-workflow-config.mjs +463 -0
- package/scripts/cm-workflow-config.test.mjs +181 -0
- package/scripts/cm-workflow.mjs +36 -0
- package/scripts/cm-workflow.test.mjs +51 -0
- package/scripts/cm_workflow_config.py +52 -0
- package/scripts/fixtures/claude-review-process.mjs +35 -0
- package/scripts/fixtures/codex-review-process.mjs +22 -0
- package/scripts/fixtures/prd-review-gate-python-oracle.py +320 -0
- package/scripts/fixtures/spec-manifest-python-oracle.py +172 -0
- package/scripts/scan-public-safety.py +117 -0
- package/scripts/test-cm-log-event.py +1213 -0
- package/scripts/test-cm-openai-compatible-call.py +1185 -0
- package/scripts/test-cm-prd-review-gate.py +272 -0
- package/scripts/test-cm-prd-timing.py +168 -0
- package/scripts/test-cm-usage-report.py +584 -0
- package/scripts/test-npm-install.py +171 -0
- package/scripts/test-scan-public-safety.py +76 -0
- package/scripts/test-shell-compat.sh +365 -0
- package/scripts/test-spec-manifest.py +263 -0
- package/scripts/test-task-gate.py +46 -0
- package/scripts/test-workflow-config.py +30 -0
- package/scripts/validate-public-repo.py +245 -0
- package/scripts/validate-test-cases.mjs +71 -0
- package/scripts/validate-test-cases.py +27 -0
- package/scripts/validate-test-cases.test.mjs +36 -0
- package/skills/cm-ai/SKILL.md +137 -0
- package/skills/cm-ai/references/N1-init.md +108 -0
- package/skills/cm-ai/references/N2-enter-feature.md +38 -0
- package/skills/cm-ai/references/N3-execute-task.md +123 -0
- package/skills/cm-ai/references/N4-review.md +103 -0
- package/skills/cm-ai/references/N5-mark-done.md +117 -0
- package/skills/cm-ai/references/N6-qa-eval.md +102 -0
- package/skills/cm-ai/references/N7-context.md +23 -0
- package/skills/cm-ai/references/N8-finish.md +103 -0
- package/skills/cm-ai/references/js-host.md +126 -0
- package/skills/cm-backend-engineer/SKILL.md +100 -0
- package/skills/cm-check/SKILL.md +52 -0
- package/skills/cm-check/references/js-host.md +44 -0
- package/skills/cm-contract-engineer/SKILL.md +136 -0
- package/skills/cm-database-engineer/SKILL.md +89 -0
- package/skills/cm-devops-engineer/SKILL.md +137 -0
- package/skills/cm-doc-syncer/SKILL.md +150 -0
- package/skills/cm-finance-expert/SKILL.md +85 -0
- package/skills/cm-fix/SKILL.md +199 -0
- package/skills/cm-fix/references/cross-boundary-debugging.md +44 -0
- package/skills/cm-fix/references/js-host.md +135 -0
- package/skills/cm-frontend-engineer/SKILL.md +127 -0
- package/skills/cm-idea/SKILL.md +55 -0
- package/skills/cm-idea/references/domains/trading.md +97 -0
- package/skills/cm-idea/references/example-prd.md +92 -0
- package/skills/cm-idea/references/idea-to-prd.md +282 -0
- package/skills/cm-idea/references/js-host.md +63 -0
- package/skills/cm-init/SKILL.md +191 -0
- package/skills/cm-init/references/js-host.md +123 -0
- package/skills/cm-miniprogram-engineer/SKILL.md +141 -0
- package/skills/cm-miniprogram-engineer/references/platform-readiness.md +58 -0
- package/skills/cm-miniprogram-engineer/references/release-checklist.md +59 -0
- package/skills/cm-prd/SKILL.md +548 -0
- package/skills/cm-prd/references/brownfield.md +13 -0
- package/skills/cm-prd/references/change-mode.md +145 -0
- package/skills/cm-prd/references/context-scope.md +62 -0
- package/skills/cm-prd/references/greenfield.md +80 -0
- package/skills/cm-prd/references/js-change-recovery.md +57 -0
- package/skills/cm-prd/references/js-host.md +98 -0
- package/skills/cm-prd/references/phase-timing.md +68 -0
- package/skills/cm-prd/references/spec-self-check.md +22 -0
- package/skills/cm-product-manager/SKILL.md +83 -0
- package/skills/cm-qa-engineer/SKILL.md +142 -0
- package/skills/cm-refactor/SKILL.md +236 -0
- package/skills/cm-refactor/references/js-batch.md +75 -0
- package/skills/cm-refactor/references/js-host.md +78 -0
- package/skills/cm-test/SKILL.md +288 -0
- package/skills/cm-test/references/js-host.md +118 -0
- package/skills/cm-ui-engineer/SKILL.md +105 -0
- package/skills/codebase-context/SKILL.md +489 -0
- package/skills/darwin-skill/NOTICE.md +26 -0
- package/skills/darwin-skill/README.md +272 -0
- package/skills/darwin-skill/SKILL.md +492 -0
- package/skills/darwin-skill/references/runtime-neutrality.md +68 -0
- package/skills/darwin-skill/references/skilllens-evidence.md +142 -0
- package/skills/darwin-skill/scripts/screenshot.mjs +71 -0
- package/skills/darwin-skill/templates/result-card-dark.html +698 -0
- package/skills/darwin-skill/templates/result-card-white.html +444 -0
- package/skills/darwin-skill/templates/result-card.html +616 -0
- package/skills/external-expert/SKILL.md +250 -0
- package/templates/arch-reference.md +68 -0
- package/templates/auto-update/cm-announce.sh +19 -0
- package/templates/auto-update/cm-update.sh +274 -0
- package/templates/cm-workflow.yml +52 -0
- package/templates/dashboard/dashboard.html +153 -0
- package/templates/dashboard/serve.sh +10 -0
- package/templates/hooks/pre-commit-cm-task-check +67 -0
- package/templates/pixel/cm-pixel.html +388 -0
- package/templates/pixel/cm-pixel.sh +212 -0
- package/templates/pixel/dev/README.md +20 -0
- package/templates/pixel/dev/atlas-preview.png +0 -0
- package/templates/pixel/dev/build.py +55 -0
- package/templates/pixel/dev/sheets/roguelikeChar_transparent.png +0 -0
- package/templates/pixel/dev/sheets/roguelikeCity_tilemap.png +0 -0
- package/templates/pixel/dev/sheets/roguelikeIndoor_transparent.png +0 -0
- package/templates/pixel/dev/template.html +388 -0
- package/templates/pixel/serve.sh +12 -0
- package/templates/refactor/cm-refactor-denies.json +14 -0
- package/templates/rules/backend-api.md +36 -0
- package/templates/rules/coding-style.md +44 -0
- package/templates/rules/database.md +27 -0
- package/templates/rules/finance.md +32 -0
- package/templates/rules/frontend.md +32 -0
- package/templates/rules/git-workflow.md +25 -0
- package/templates/rules/miniprogram.md +31 -0
- package/templates/rules/security.md +31 -0
- package/templates/rules/smart-contract.md +28 -0
- package/templates/rules/testing.md +36 -0
- package/templates/statusline/cm-statusline.sh +73 -0
- package/templates/ui-lens/cm-ui-lens-extract.mjs +55 -0
|
@@ -0,0 +1,879 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// JavaScript authority for CM handoff, review, and read-only completion-plan gates.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
7
|
+
import childProcess from 'node:child_process';
|
|
8
|
+
import {fileURLToPath} from 'node:url';
|
|
9
|
+
import {inspectFixWalkthrough,readFixWalkthrough,fixWalkthroughBinding} from '../runtime/js/cm-fix/walkthrough.mjs';
|
|
10
|
+
import {inspectFixRegressionFailure} from '../runtime/js/cm-fix/regression-evidence.mjs';
|
|
11
|
+
|
|
12
|
+
const TASK_RE=/^T-[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
13
|
+
const REVIEWERS=new Set(['codex-subagent','codex-cli','claude-cli','self-degraded']);
|
|
14
|
+
const VERDICTS=new Set(['approved','changes_requested','blocked']);
|
|
15
|
+
const PREPARATION_FILE_LIMIT=256*1024;
|
|
16
|
+
let preparationReadLimit=null;
|
|
17
|
+
|
|
18
|
+
export class GateError extends Error {
|
|
19
|
+
constructor(message){super(message);this.name='GateError';}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function define(target,key,value){
|
|
23
|
+
Object.defineProperty(target,key,{value,writable:true,enumerable:true,configurable:true});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function parseJsonStrict(text){
|
|
27
|
+
let index=0;
|
|
28
|
+
const whitespace=()=>{while(index<text.length&&/[ \t\r\n]/.test(text[index]))index++;};
|
|
29
|
+
function value(depth=0){
|
|
30
|
+
if(depth>256)throw new GateError('JSON nesting is too deep');
|
|
31
|
+
whitespace();
|
|
32
|
+
const start=index,character=text[index];
|
|
33
|
+
if(character==='"'){
|
|
34
|
+
index++;
|
|
35
|
+
for(let escaped=false;index<text.length;index++){
|
|
36
|
+
const current=text[index];
|
|
37
|
+
if(escaped){escaped=false;continue;}
|
|
38
|
+
if(current==='\\'){escaped=true;continue;}
|
|
39
|
+
if(current==='"'){
|
|
40
|
+
index++;
|
|
41
|
+
try{return JSON.parse(text.slice(start,index));}
|
|
42
|
+
catch(error){throw new GateError(`invalid JSON: ${error.message}`);}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new GateError('invalid JSON: unterminated string');
|
|
46
|
+
}
|
|
47
|
+
if(character==='{'){
|
|
48
|
+
index++;whitespace();
|
|
49
|
+
const result={},keys=new Set();
|
|
50
|
+
if(text[index]==='}'){index++;return result;}
|
|
51
|
+
while(true){
|
|
52
|
+
whitespace();
|
|
53
|
+
if(text[index]!=='"')throw new GateError('invalid JSON: object key must be a string');
|
|
54
|
+
const key=value(depth+1);
|
|
55
|
+
if(keys.has(key))throw new GateError(`JSON contains duplicate key: ${key}`);
|
|
56
|
+
keys.add(key);whitespace();
|
|
57
|
+
if(text[index++]!==':')throw new GateError("invalid JSON: expected ':'");
|
|
58
|
+
define(result,key,value(depth+1));whitespace();
|
|
59
|
+
if(text[index]==='}'){index++;return result;}
|
|
60
|
+
if(text[index++]!==',')throw new GateError("invalid JSON: expected ',' or '}'");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if(character==='['){
|
|
64
|
+
index++;whitespace();
|
|
65
|
+
const result=[];
|
|
66
|
+
if(text[index]===']'){index++;return result;}
|
|
67
|
+
while(true){
|
|
68
|
+
result.push(value(depth+1));whitespace();
|
|
69
|
+
if(text[index]===']'){index++;return result;}
|
|
70
|
+
if(text[index++]!==',')throw new GateError("invalid JSON: expected ',' or ']'");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for(const [literal,parsed] of [['true',true],['false',false],['null',null]]){
|
|
74
|
+
if(text.startsWith(literal,index)){index+=literal.length;return parsed;}
|
|
75
|
+
}
|
|
76
|
+
const number=text.slice(index).match(/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/);
|
|
77
|
+
if(number){
|
|
78
|
+
index+=number[0].length;
|
|
79
|
+
return /^-?(?:0|[1-9]\d*)$/.test(number[0])?BigInt(number[0]):Number(number[0]);
|
|
80
|
+
}
|
|
81
|
+
throw new GateError(`invalid JSON near byte ${index}`);
|
|
82
|
+
}
|
|
83
|
+
const parsed=value();whitespace();
|
|
84
|
+
if(index!==text.length)throw new GateError(`invalid JSON near byte ${index}`);
|
|
85
|
+
return parsed;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function readText(file,label){
|
|
89
|
+
if(preparationReadLimit!==null){
|
|
90
|
+
try{return new TextDecoder('utf-8',{fatal:true}).decode(fileRevision(file,preparationReadLimit).bytes);}
|
|
91
|
+
catch(error){if(error instanceof GateError)throw error;throw new GateError(`cannot read ${label} ${file}: ${error.message}`);}
|
|
92
|
+
}
|
|
93
|
+
let info;
|
|
94
|
+
try{info=fs.lstatSync(file);}catch(error){
|
|
95
|
+
if(error?.code==='ENOENT')throw new GateError(`${label} not found: ${file}`);
|
|
96
|
+
throw new GateError(`cannot read ${label} ${file}: ${error.message}`);
|
|
97
|
+
}
|
|
98
|
+
if(info.isSymbolicLink())throw new GateError(`${label} must not be a symlink: ${file}`);
|
|
99
|
+
if(!info.isFile())throw new GateError(`${label} must be a regular file: ${file}`);
|
|
100
|
+
try{return new TextDecoder('utf-8',{fatal:true}).decode(fs.readFileSync(file));}
|
|
101
|
+
catch(error){throw new GateError(`cannot read ${label} ${file}: ${error.message}`);}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function loadSchemaContract(){
|
|
105
|
+
const schemaPath=fileURLToPath(new URL('../runtime/task-handoff.schema.json',import.meta.url));
|
|
106
|
+
try{
|
|
107
|
+
const schema=JSON.parse(fs.readFileSync(schemaPath,'utf8'));
|
|
108
|
+
const properties=schema.properties;
|
|
109
|
+
const verification=properties.verification.items.properties;
|
|
110
|
+
const requiredFields=new Set(schema.required),allowedFields=new Set(Object.keys(properties));
|
|
111
|
+
if([...requiredFields].some(key=>!allowedFields.has(key)))throw new Error('required field has no property');
|
|
112
|
+
return {
|
|
113
|
+
requiredHandoffFields:requiredFields,
|
|
114
|
+
allowedHandoffFields:allowedFields,
|
|
115
|
+
verificationFields:new Set(Object.keys(verification)),
|
|
116
|
+
verificationStatuses:new Set(verification.status.enum),
|
|
117
|
+
handoffStatuses:new Set(properties.status.enum),
|
|
118
|
+
};
|
|
119
|
+
}catch(error){throw new Error(`invalid task handoff schema: ${schemaPath}: ${error.message}`);}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const SCHEMA=loadSchemaContract();
|
|
123
|
+
|
|
124
|
+
function requireTaskId(value,field='task_id'){
|
|
125
|
+
if(typeof value!=='string'||!TASK_RE.test(value))throw new GateError(`${field} must match T-<id>`);
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function requireString(value,field){
|
|
130
|
+
if(typeof value!=='string'||!value.trim())throw new GateError(`${field} must be a non-empty string`);
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function requireStringList(value,field,minimum=0){
|
|
135
|
+
if(!Array.isArray(value)||value.length<minimum)
|
|
136
|
+
throw new GateError(`${field} must be a list with at least ${minimum} item(s)`);
|
|
137
|
+
const items=value.map((item,index)=>requireString(item,`${field}[${index}]`));
|
|
138
|
+
if(new Set(items).size!==items.length)throw new GateError(`${field} must not contain duplicates`);
|
|
139
|
+
return items;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function requireFeature(value){
|
|
143
|
+
if(!value||value==='.'||value==='..'||[' ','.'].includes(value.at(-1)))
|
|
144
|
+
throw new GateError('feature must be a safe filename slug');
|
|
145
|
+
if([...value].some(character=>character.codePointAt(0)<32||'<>:"/\\|?*'.includes(character)))
|
|
146
|
+
throw new GateError('feature must be a safe cross-platform filename slug');
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function requireRelativeFiles(value){
|
|
151
|
+
const files=requireStringList(value,'changed_files');
|
|
152
|
+
for(const item of files){
|
|
153
|
+
if(item.startsWith('/')||item.startsWith('\\')||/^[A-Za-z]:[\\/]/.test(item)||item.includes('\\')
|
|
154
|
+
||item.split('/').includes('..')||item==='.'||item==='..')
|
|
155
|
+
throw new GateError(`changed_files entry must be a safe relative path: ${item}`);
|
|
156
|
+
}
|
|
157
|
+
return files;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function resolveStrictFalse(target){
|
|
161
|
+
let current=path.resolve(target);const missing=[];
|
|
162
|
+
while(true){
|
|
163
|
+
try{return path.join(fs.realpathSync(current),...missing.reverse());}
|
|
164
|
+
catch(error){
|
|
165
|
+
if(error?.code!=='ENOENT')throw error;
|
|
166
|
+
const parent=path.dirname(current);
|
|
167
|
+
if(parent===current)throw error;
|
|
168
|
+
missing.push(path.basename(current));current=parent;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function implementationSha256(projectRoot,changedFiles){
|
|
174
|
+
requireString(projectRoot,'project root');
|
|
175
|
+
const expanded=projectRoot==='~'?os.homedir()
|
|
176
|
+
:projectRoot.startsWith(`~${path.sep}`)?path.join(os.homedir(),projectRoot.slice(2)):projectRoot;
|
|
177
|
+
let root;
|
|
178
|
+
try{
|
|
179
|
+
root=fs.realpathSync(path.resolve(expanded));
|
|
180
|
+
if(!fs.statSync(root).isDirectory())throw new GateError(`project root is not an existing directory: ${root}`);
|
|
181
|
+
}catch(error){
|
|
182
|
+
if(error instanceof GateError)throw error;
|
|
183
|
+
throw new GateError(`project root is not an existing directory: ${path.resolve(expanded)}`);
|
|
184
|
+
}
|
|
185
|
+
const digest=createHash('sha256');digest.update('cm-implementation-v1\0');
|
|
186
|
+
const files=[...requireRelativeFiles(changedFiles)].sort((left,right)=>Buffer.compare(Buffer.from(left),Buffer.from(right)));
|
|
187
|
+
for(const relative of files){
|
|
188
|
+
const unresolved=path.join(root,...relative.split('/'));
|
|
189
|
+
try{if(fs.lstatSync(unresolved).isSymbolicLink())throw new GateError(`changed file must not be a symlink: ${relative}`);}
|
|
190
|
+
catch(error){if(error?.code!=='ENOENT')throw error;}
|
|
191
|
+
let candidate;
|
|
192
|
+
try{candidate=resolveStrictFalse(unresolved);}
|
|
193
|
+
catch(error){throw new GateError(`cannot resolve changed file ${relative}: ${error.message}`);}
|
|
194
|
+
const fromRoot=path.relative(root,candidate);
|
|
195
|
+
if(fromRoot===''||fromRoot==='..'||fromRoot.startsWith(`..${path.sep}`)||path.isAbsolute(fromRoot))
|
|
196
|
+
throw new GateError(`changed file resolves outside project root: ${relative}`);
|
|
197
|
+
digest.update(relative);digest.update('\0');
|
|
198
|
+
let info;
|
|
199
|
+
try{info=fs.statSync(candidate);}catch(error){
|
|
200
|
+
if(error?.code==='ENOENT'){digest.update('missing\0');continue;}
|
|
201
|
+
throw new GateError(`cannot read changed file ${relative}: ${error.message}`);
|
|
202
|
+
}
|
|
203
|
+
if(!info.isFile())throw new GateError(`changed file must be a regular file or deletion: ${relative}`);
|
|
204
|
+
let content;
|
|
205
|
+
try{content=fs.readFileSync(candidate);}catch(error){throw new GateError(`cannot read changed file ${relative}: ${error.message}`);}
|
|
206
|
+
digest.update('file\0');digest.update(String(content.length));digest.update('\0');digest.update(content);digest.update('\0');
|
|
207
|
+
}
|
|
208
|
+
return digest.digest('hex');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function verifyImplementationBinding(payload,{projectRoot=null,allowLegacyUnbound=false}={}){
|
|
212
|
+
const expected=payload.implementation_sha256;
|
|
213
|
+
if(expected===undefined){
|
|
214
|
+
if(allowLegacyUnbound)return false;
|
|
215
|
+
throw new GateError('handoff is not content-bound; legacy recovery requires --allow-legacy-unbound');
|
|
216
|
+
}
|
|
217
|
+
if(projectRoot===null||projectRoot===undefined)throw new GateError('content-bound handoff requires --project-root');
|
|
218
|
+
if(implementationSha256(projectRoot,payload.changed_files)!==expected)
|
|
219
|
+
throw new GateError('implementation content changed after handoff');
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function sameSet(actual,expected){
|
|
224
|
+
return actual.size===expected.size&&[...actual].every(item=>expected.has(item));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function loadHandoff(handoff,{task=null,attempt=null}={}){
|
|
228
|
+
let payload;
|
|
229
|
+
try{payload=parseJsonStrict(readText(handoff,'handoff'));}
|
|
230
|
+
catch(error){
|
|
231
|
+
if(error instanceof GateError)throw error;
|
|
232
|
+
throw new GateError(`cannot read handoff ${handoff}: ${error.message}`);
|
|
233
|
+
}
|
|
234
|
+
if(payload===null||typeof payload!=='object'||Array.isArray(payload))
|
|
235
|
+
throw new GateError('handoff root must be an object');
|
|
236
|
+
const fields=new Set(Object.keys(payload));
|
|
237
|
+
const missing=[...SCHEMA.requiredHandoffFields].filter(field=>!fields.has(field)).sort();
|
|
238
|
+
const unknown=[...fields].filter(field=>!SCHEMA.allowedHandoffFields.has(field)).sort();
|
|
239
|
+
if(missing.length)throw new GateError(`handoff missing fields: ${missing.join(', ')}`);
|
|
240
|
+
if(unknown.length)throw new GateError(`handoff has unknown fields: ${unknown.join(', ')}`);
|
|
241
|
+
if(payload.schema_version!==1n)
|
|
242
|
+
throw new GateError('schema_version must be 1');
|
|
243
|
+
const taskId=requireTaskId(payload.task_id);
|
|
244
|
+
if(typeof payload.attempt!=='bigint'||![1n,2n].includes(payload.attempt))
|
|
245
|
+
throw new GateError('attempt must be 1 or 2');
|
|
246
|
+
payload.schema_version=1;
|
|
247
|
+
payload.attempt=Number(payload.attempt);
|
|
248
|
+
if(!SCHEMA.handoffStatuses.has(payload.status))
|
|
249
|
+
throw new GateError('status must be ready_for_review or blocked');
|
|
250
|
+
requireRelativeFiles(payload.changed_files);
|
|
251
|
+
if(payload.implementation_sha256!==undefined&&
|
|
252
|
+
(typeof payload.implementation_sha256!=='string'||!/^[0-9a-f]{64}$/.test(payload.implementation_sha256)))
|
|
253
|
+
throw new GateError('implementation_sha256 must be a lowercase SHA-256 digest');
|
|
254
|
+
requireStringList(payload.evidence,'evidence',1);
|
|
255
|
+
const blockers=requireStringList(payload.blockers,'blockers');
|
|
256
|
+
const scopeDeviation=requireStringList(payload.scope_deviation,'scope_deviation');
|
|
257
|
+
if(!Array.isArray(payload.verification)||payload.verification.length===0)
|
|
258
|
+
throw new GateError('verification must contain at least one result');
|
|
259
|
+
const statuses=[];
|
|
260
|
+
payload.verification.forEach((item,index)=>{
|
|
261
|
+
if(item===null||typeof item!=='object'||Array.isArray(item))
|
|
262
|
+
throw new GateError(`verification[${index}] must be an object`);
|
|
263
|
+
if(!sameSet(new Set(Object.keys(item)),SCHEMA.verificationFields))
|
|
264
|
+
throw new GateError(`verification[${index}] must contain command, status, and evidence only`);
|
|
265
|
+
requireString(item.command,`verification[${index}].command`);
|
|
266
|
+
requireString(item.evidence,`verification[${index}].evidence`);
|
|
267
|
+
if(!SCHEMA.verificationStatuses.has(item.status))
|
|
268
|
+
throw new GateError(`verification[${index}].status is invalid`);
|
|
269
|
+
statuses.push(item.status);
|
|
270
|
+
});
|
|
271
|
+
if(payload.status==='ready_for_review'){
|
|
272
|
+
if(blockers.length)throw new GateError('ready_for_review handoff must not contain blockers');
|
|
273
|
+
if(scopeDeviation.length)throw new GateError('ready_for_review handoff must not contain scope_deviation');
|
|
274
|
+
if(statuses.some(status=>status!=='passed'))
|
|
275
|
+
throw new GateError('ready_for_review handoff requires every verification result to pass');
|
|
276
|
+
}else if(blockers.length===0&&scopeDeviation.length===0){
|
|
277
|
+
throw new GateError('blocked handoff must explain a blocker or scope deviation');
|
|
278
|
+
}
|
|
279
|
+
if(task!==null&&taskId!==task)throw new GateError(`handoff task ${taskId} does not match requested task ${task}`);
|
|
280
|
+
if(attempt!==null&&payload.attempt!==attempt)
|
|
281
|
+
throw new GateError(`handoff attempt ${payload.attempt} does not match requested attempt ${attempt}`);
|
|
282
|
+
return payload;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function parseReview(review){
|
|
286
|
+
const lines=readText(review,'review evidence').split(/\r\n|[\n\r\v\f\x1c-\x1e\x85\u2028\u2029]/);
|
|
287
|
+
if(lines.length===0||lines[0].trim()!=='---')
|
|
288
|
+
throw new GateError(`review evidence has no YAML header: ${review}`);
|
|
289
|
+
const end=lines.findIndex((line,index)=>index>0&&line.trim()==='---');
|
|
290
|
+
if(end<0)throw new GateError(`review evidence header is not closed: ${review}`);
|
|
291
|
+
const scalars={},seen=new Set(),scope=[];
|
|
292
|
+
let inScope=false,scopeSeen=false;
|
|
293
|
+
for(const line of lines.slice(1,end)){
|
|
294
|
+
if(line.trim()==='scope:'){
|
|
295
|
+
if(scopeSeen||seen.has('scope'))throw new GateError('review header contains duplicate field: scope');
|
|
296
|
+
scopeSeen=true;inScope=true;continue;
|
|
297
|
+
}
|
|
298
|
+
if(inScope&&/^[ \t]/.test(line)){
|
|
299
|
+
const stripped=line.trim();
|
|
300
|
+
if(stripped.startsWith('- ')&&stripped.slice(2).trim())scope.push(stripped.slice(2).trim());
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
inScope=false;
|
|
304
|
+
if(/^[ \t]/.test(line)||!line.includes(':'))continue;
|
|
305
|
+
const colon=line.indexOf(':'),key=line.slice(0,colon).trim();
|
|
306
|
+
if(seen.has(key)||(key==='scope'&&scopeSeen))throw new GateError(`review header contains duplicate field: ${key}`);
|
|
307
|
+
seen.add(key);
|
|
308
|
+
const raw=line.slice(colon+1).trim();
|
|
309
|
+
if(raw)define(scalars,key,raw.replace(/^["']+|["']+$/g,''));
|
|
310
|
+
}
|
|
311
|
+
if(scope.length===0)throw new GateError(`review evidence scope must contain at least one entry: ${review}`);
|
|
312
|
+
if(new Set(scope).size!==scope.length)throw new GateError(`review evidence scope must not contain duplicates: ${review}`);
|
|
313
|
+
const body=lines.slice(end+1).join('\n').trim();
|
|
314
|
+
if(!body)throw new GateError(`review evidence body must not be empty: ${review}`);
|
|
315
|
+
return {header:scalars,scope,body};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function sha256(file){
|
|
319
|
+
try{
|
|
320
|
+
const bytes=preparationReadLimit===null?fs.readFileSync(file):fileRevision(file,preparationReadLimit).bytes;
|
|
321
|
+
return createHash('sha256').update(bytes).digest('hex');
|
|
322
|
+
}
|
|
323
|
+
catch(error){throw new GateError(`cannot hash evidence ${file}: ${error.message}`);}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function integerHeader(value,label){
|
|
327
|
+
if(typeof value!=='string'||!/^[+-]?\d+$/.test(value))throw new GateError(`${label} must be an integer`);
|
|
328
|
+
return BigInt(value);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function validateReview(review,{task,attempt,handoff,changedFiles}){
|
|
332
|
+
const {header,scope,body}=parseReview(review);
|
|
333
|
+
const required=['at','reviewer','independent','task','attempt','round','verdict','handoff','handoff_sha256','blocking_findings'];
|
|
334
|
+
const missing=required.filter(field=>!Object.hasOwn(header,field)).sort();
|
|
335
|
+
if(missing.length)throw new GateError(`review header missing fields: ${missing.join(', ')}`);
|
|
336
|
+
if(header.task!==task)throw new GateError(`review task ${header.task} does not match ${task}`);
|
|
337
|
+
if(!/(?:Z|[+-]\d{2}:\d{2})$/.test(header.at)||Number.isNaN(Date.parse(header.at)))
|
|
338
|
+
throw new GateError('review at must include a valid ISO-8601 timezone');
|
|
339
|
+
const reviewAttempt=integerHeader(header.attempt,'review attempt and round');
|
|
340
|
+
const reviewRound=integerHeader(header.round,'review attempt and round');
|
|
341
|
+
if(reviewAttempt!==BigInt(attempt)||reviewRound!==BigInt(attempt))
|
|
342
|
+
throw new GateError('review attempt and round must match the handoff attempt');
|
|
343
|
+
if(!REVIEWERS.has(header.reviewer))throw new GateError(`unsupported reviewer channel: ${header.reviewer}`);
|
|
344
|
+
const independent=header.independent.toLowerCase();
|
|
345
|
+
if(!['true','false'].includes(independent))throw new GateError('review independent must be true or false');
|
|
346
|
+
if(header.reviewer==='self-degraded'&&independent!=='false')
|
|
347
|
+
throw new GateError('self-degraded review must declare independent: false');
|
|
348
|
+
if(header.reviewer!=='self-degraded'&&independent!=='true')
|
|
349
|
+
throw new GateError('independent review channel must declare independent: true');
|
|
350
|
+
if(!VERDICTS.has(header.verdict))throw new GateError(`unsupported review verdict: ${header.verdict}`);
|
|
351
|
+
const blocking=integerHeader(header.blocking_findings,'review blocking_findings');
|
|
352
|
+
if(blocking<0n)throw new GateError('review blocking_findings must not be negative');
|
|
353
|
+
if(header.verdict==='approved'&&blocking!==0n)
|
|
354
|
+
throw new GateError('approved review must declare blocking_findings: 0');
|
|
355
|
+
if(header.verdict!=='approved'&&blocking===0n)
|
|
356
|
+
throw new GateError('non-approved review must declare at least one blocking finding');
|
|
357
|
+
if(header.reviewer==='self-degraded'&&!header.degraded_reason?.trim())
|
|
358
|
+
throw new GateError('self-degraded review must include degraded_reason');
|
|
359
|
+
if(header.verdict==='approved'&&!/(零发现|无阻塞发现|未发现阻塞|zero findings|no findings|no blocking findings)/i.test(body))
|
|
360
|
+
throw new GateError('approved review body must explicitly state zero blocking findings');
|
|
361
|
+
if(attempt===2&&header.verdict==='changes_requested')
|
|
362
|
+
throw new GateError('round 2 blocking findings must use verdict: blocked');
|
|
363
|
+
if(header.handoff!==path.basename(handoff))
|
|
364
|
+
throw new GateError('review handoff does not match the current implementation evidence');
|
|
365
|
+
if(!/^[0-9a-f]{64}$/.test(header.handoff_sha256))
|
|
366
|
+
throw new GateError('review handoff_sha256 must be a lowercase SHA-256 digest');
|
|
367
|
+
if(header.handoff_sha256!==sha256(handoff))
|
|
368
|
+
throw new GateError('review handoff digest does not match the current implementation evidence');
|
|
369
|
+
const missingScope=[...new Set(changedFiles)].filter(file=>!scope.includes(file)).sort();
|
|
370
|
+
if(missingScope.length)throw new GateError(`review scope does not cover changed files: ${missingScope.join(', ')}`);
|
|
371
|
+
return header;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function expectedHandoff(reviewsDir,feature,task,attempt){
|
|
375
|
+
requireFeature(feature);
|
|
376
|
+
return path.join(reviewsDir,`${feature}-${task}-a${attempt}-handoff.json`);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function requireExpectedHandoff(handoff,{reviewsDir,feature,task,attempt}){
|
|
380
|
+
const expected=expectedHandoff(reviewsDir,feature,task,attempt);
|
|
381
|
+
let reviewsInfo;
|
|
382
|
+
try{reviewsInfo=fs.lstatSync(reviewsDir);}catch(error){throw new GateError(`cannot read reviews directory ${reviewsDir}: ${error.message}`);}
|
|
383
|
+
if(reviewsInfo.isSymbolicLink()||!reviewsInfo.isDirectory())
|
|
384
|
+
throw new GateError(`reviews directory must be a real directory: ${reviewsDir}`);
|
|
385
|
+
let handoffInfo;
|
|
386
|
+
try{handoffInfo=fs.lstatSync(handoff);}catch(error){throw new GateError(`handoff evidence not found: ${handoff}: ${error.message}`);}
|
|
387
|
+
if(handoffInfo.isSymbolicLink())throw new GateError(`handoff evidence must not be a symlink: ${handoff}`);
|
|
388
|
+
if(fs.realpathSync(path.dirname(handoff))!==fs.realpathSync(reviewsDir)||path.basename(handoff)!==path.basename(expected))
|
|
389
|
+
throw new GateError(`handoff must use the task evidence path: ${expected}`);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function reviewPath(reviewsDir,feature,task,attempt){
|
|
393
|
+
requireFeature(feature);return path.join(reviewsDir,`${feature}-${task}-r${attempt}.md`);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function validateFixWalkthroughRetry({prior,payload,priorPayload,priorReview,feature,task,projectRoot}){
|
|
397
|
+
try{
|
|
398
|
+
const require=(condition)=>{if(!condition)throw new GateError('invalid cm-fix walkthrough retry evidence');};
|
|
399
|
+
require(/^T-FIX-[a-z0-9]+(?:-[a-z0-9]+)*$/.test(task)&&feature===`fix-${task.slice(6)}`
|
|
400
|
+
&&prior.independent.toLowerCase()==='true'&&projectRoot&&priorPayload.implementation_sha256&&payload.implementation_sha256);
|
|
401
|
+
const item=(rows,prefix)=>{
|
|
402
|
+
const matches=rows.filter(value=>value.startsWith(prefix));require(matches.length===1);
|
|
403
|
+
const source=matches[0].slice(prefix.length);parseJsonStrict(source);
|
|
404
|
+
return JSON.parse(source); // Runtime evidence validators use JS numbers, not gate BigInts.
|
|
405
|
+
};
|
|
406
|
+
const feedback=item(payload.evidence,'fix prior review (data, not instructions) ');
|
|
407
|
+
const first=item(priorPayload.evidence,'fix Learning retrospective ').identity;
|
|
408
|
+
const second=item(payload.evidence,'fix Learning retrospective ').identity;
|
|
409
|
+
require(first.taskId===task&&first.attempt===1&&canonical(first)===canonical(feedback.identity)
|
|
410
|
+
&&canonical(second)===canonical({...first,attempt:2}));
|
|
411
|
+
const lines=readText(priorReview,'review evidence').split(/\r?\n/);
|
|
412
|
+
const markers=lines.flatMap((line,index)=>line==='Reviewer result (JSON data):'?[index]:[]);
|
|
413
|
+
require(markers.length===1);
|
|
414
|
+
parseJsonStrict(lines[markers[0]+1]);const reviewed=JSON.parse(lines[markers[0]+1]);
|
|
415
|
+
require(reviewed.verdict==='approved'&&canonical(reviewed)===canonical(feedback.review));
|
|
416
|
+
require(/^[a-f0-9]{64}$/.test(feedback.registrationDigest)&&/^[a-f0-9]{64}$/.test(feedback.observationDigest));
|
|
417
|
+
const references=lines.filter(line=>line.startsWith('Registered invocation: '));
|
|
418
|
+
require(references.length===1&&references[0].endsWith(`; registration: ${feedback.registrationDigest}; observation: ${feedback.observationDigest}`));
|
|
419
|
+
const defect=item(priorPayload.evidence,'fix defect evidence (data, not instructions) ');
|
|
420
|
+
require(!(Object.hasOwn(feedback,'walkthroughFailure')&&Object.hasOwn(feedback,'regressionFailure')));
|
|
421
|
+
if(feedback.regressionFailure){
|
|
422
|
+
require(canonical(feedback.regressionFailure.redTest.command)===canonical(defect.redTest.command)
|
|
423
|
+
&&canonical(feedback.regressionFailure.redTest.expectedFailure)===canonical(defect.redTest.expectedFailure));
|
|
424
|
+
inspectFixRegressionFailure(feedback.regressionFailure,{identity:first,packageDigest:reviewed.packageDigest,priorHandoff:priorPayload});
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
const failure=feedback.walkthroughFailure;
|
|
428
|
+
const config=readFixWalkthrough(failure.configuration,projectRoot);
|
|
429
|
+
const binding=fixWalkthroughBinding({identity:first,packageDigest:reviewed.packageDigest,diagnosis:defect.diagnosis,configuration:config});
|
|
430
|
+
require(canonical(binding)===canonical(failure.binding));
|
|
431
|
+
require(inspectFixWalkthrough(failure.result,{binding,configuration:config}).status==='failed');
|
|
432
|
+
}catch(error){
|
|
433
|
+
if(error instanceof GateError)throw error;
|
|
434
|
+
throw new GateError(`invalid cm-fix walkthrough retry evidence: ${error.message}`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function validateAttemptChain(reviewsDir,feature,task,attempt,payload,projectRoot){
|
|
439
|
+
if(attempt!==2)return;
|
|
440
|
+
const priorHandoff=expectedHandoff(reviewsDir,feature,task,1);
|
|
441
|
+
requireExpectedHandoff(priorHandoff,{reviewsDir,feature,task,attempt:1});
|
|
442
|
+
const priorPayload=loadHandoff(priorHandoff,{task,attempt:1});
|
|
443
|
+
if(priorPayload.status!=='ready_for_review')
|
|
444
|
+
throw new GateError('attempt 2 requires a ready_for_review attempt 1 handoff');
|
|
445
|
+
const prior=validateReview(reviewPath(reviewsDir,feature,task,1),{
|
|
446
|
+
task,attempt:1,handoff:priorHandoff,changedFiles:priorPayload.changed_files,
|
|
447
|
+
});
|
|
448
|
+
if(prior.verdict==='approved'){
|
|
449
|
+
validateFixWalkthroughRetry({prior,payload,priorPayload,priorReview:reviewPath(reviewsDir,feature,task,1),feature,task,projectRoot});
|
|
450
|
+
}else if(prior.verdict!=='changes_requested')
|
|
451
|
+
throw new GateError('attempt 2 requires round 1 verdict: changes_requested');
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function verifyLearningRecord(payload,projectRoot){
|
|
455
|
+
const applications=payload.evidence.filter(item=>item.startsWith('learning: applied ')||item==='learning: no_relevant_lesson');
|
|
456
|
+
const outcomes=payload.evidence.filter(item=>item.startsWith('learning: retrospective '));
|
|
457
|
+
if(applications.length!==1||outcomes.length!==1)
|
|
458
|
+
throw new GateError('Learning requires exactly one application and one retrospective record');
|
|
459
|
+
if(applications[0].startsWith('learning: applied ')&&!applications[0].slice(18).trim())
|
|
460
|
+
throw new GateError('Learning applied record requires a concrete lesson and action');
|
|
461
|
+
if(!['learning: retrospective no_new_lesson','learning: retrospective written AGENTS.md'].includes(outcomes[0]))
|
|
462
|
+
throw new GateError('Learning retrospective must be complete; pending writeback cannot pass');
|
|
463
|
+
if(outcomes[0]==='learning: retrospective written AGENTS.md'){
|
|
464
|
+
if(!projectRoot||!payload.changed_files.includes('AGENTS.md'))
|
|
465
|
+
throw new GateError('Learning writeback requires AGENTS.md in the reviewed implementation');
|
|
466
|
+
const target=path.join(projectRoot,'AGENTS.md');
|
|
467
|
+
const info=fs.lstatSync(target);
|
|
468
|
+
if(!info.isFile()||info.isSymbolicLink())throw new GateError('Learning AGENTS.md must be a regular file');
|
|
469
|
+
}
|
|
470
|
+
if(!payload.implementation_sha256||!projectRoot)
|
|
471
|
+
throw new GateError('Learning requires a content-bound handoff');
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export function checkN4({handoff,reviewsDir,feature,task,projectRoot=null,allowLegacyUnbound=false,requireLearning=false}){
|
|
475
|
+
requireTaskId(task,'task');
|
|
476
|
+
const payload=loadHandoff(handoff,{task});
|
|
477
|
+
if(payload.status!=='ready_for_review')throw new GateError('N4 requires a ready_for_review handoff');
|
|
478
|
+
if(requireLearning)verifyLearningRecord(payload,projectRoot);
|
|
479
|
+
const attempt=payload.attempt;
|
|
480
|
+
requireExpectedHandoff(handoff,{reviewsDir,feature,task,attempt});
|
|
481
|
+
validateAttemptChain(reviewsDir,feature,task,attempt,payload,projectRoot);
|
|
482
|
+
const contentBound=verifyImplementationBinding(payload,{projectRoot,allowLegacyUnbound});
|
|
483
|
+
return {gate:'n4',task,attempt,outcome:'ready_for_review',handoff_sha256:sha256(handoff),content_bound:contentBound};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export function checkN5({handoff,reviewsDir,feature,task,projectRoot=null,allowLegacyUnbound=false,requireLearning=false}){
|
|
487
|
+
requireTaskId(task,'task');
|
|
488
|
+
const payload=loadHandoff(handoff,{task});
|
|
489
|
+
if(payload.status!=='ready_for_review')throw new GateError('N5 requires a ready_for_review handoff');
|
|
490
|
+
if(requireLearning)verifyLearningRecord(payload,projectRoot);
|
|
491
|
+
const attempt=payload.attempt;
|
|
492
|
+
requireExpectedHandoff(handoff,{reviewsDir,feature,task,attempt});
|
|
493
|
+
validateAttemptChain(reviewsDir,feature,task,attempt,payload,projectRoot);
|
|
494
|
+
const contentBound=verifyImplementationBinding(payload,{projectRoot,allowLegacyUnbound});
|
|
495
|
+
const review=reviewPath(reviewsDir,feature,task,attempt);
|
|
496
|
+
const result=validateReview(review,{task,attempt,handoff,changedFiles:payload.changed_files});
|
|
497
|
+
if(result.verdict!=='approved')throw new GateError(`N5 requires verdict: approved, got ${result.verdict}`);
|
|
498
|
+
if(result.independent.toLowerCase()!=='true')
|
|
499
|
+
throw new GateError('N5 requires independent: true; self-degraded evidence is diagnostic only');
|
|
500
|
+
return {gate:'n5',task,attempt,outcome:'approved',review:fs.realpathSync(review),content_bound:contentBound};
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function statIdentity(info){
|
|
504
|
+
return [info.dev,info.ino,info.mode,info.nlink,info.size,info.mtimeNs,info.ctimeNs].map(String);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function sameRevision(left,right){
|
|
508
|
+
return left.path===right.path&&left.stat.every((value,index)=>value===right.stat[index])&&left.bytes.equals(right.bytes);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function fileRevision(file,limit=null){
|
|
512
|
+
let descriptor;
|
|
513
|
+
try{
|
|
514
|
+
const before=fs.lstatSync(file,{bigint:true});
|
|
515
|
+
if(!before.isFile()||before.isSymbolicLink())
|
|
516
|
+
throw new GateError(`revision source must be a regular non-symlink file: ${file}`);
|
|
517
|
+
if(limit!==null&&(before.size>BigInt(limit)||before.nlink!==1n))
|
|
518
|
+
throw new GateError('preparation file exceeds bound or is hardlinked');
|
|
519
|
+
descriptor=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
|
|
520
|
+
const opened=fs.fstatSync(descriptor,{bigint:true});
|
|
521
|
+
const capacity=Number(before.size)+(limit===null?0:1),buffer=Buffer.alloc(capacity);
|
|
522
|
+
let size=0;
|
|
523
|
+
while(size<buffer.length){
|
|
524
|
+
const count=fs.readSync(descriptor,buffer,size,buffer.length-size,size);
|
|
525
|
+
if(count===0)break;
|
|
526
|
+
size+=count;
|
|
527
|
+
}
|
|
528
|
+
const after=fs.fstatSync(descriptor,{bigint:true}),current=fs.lstatSync(file,{bigint:true});
|
|
529
|
+
const identity=statIdentity(before);
|
|
530
|
+
if(size!==Number(before.size)||![opened,after,current].every(info=>statIdentity(info).every((value,index)=>value===identity[index])))
|
|
531
|
+
throw new GateError(`revision changed while reading: ${file}`);
|
|
532
|
+
return {path:fs.realpathSync(file),stat:identity,bytes:buffer.subarray(0,size)};
|
|
533
|
+
}catch(error){
|
|
534
|
+
if(error instanceof GateError)throw error;
|
|
535
|
+
throw new GateError(`cannot pin revision for ${file}: ${error.message}`);
|
|
536
|
+
}finally{if(descriptor!==undefined)fs.closeSync(descriptor);}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function requireRevisions(revisions){
|
|
540
|
+
for(const revision of revisions)if(!sameRevision(fileRevision(revision.path,preparationReadLimit),revision))
|
|
541
|
+
throw new GateError(`revision changed; refusing stale task replacement: ${revision.path}`);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function pinApproval(selectors){
|
|
545
|
+
const {handoff,reviewsDir,feature,task}=selectors;
|
|
546
|
+
requireFeature(feature);requireTaskId(task,'task');
|
|
547
|
+
const revisions=[fileRevision(handoff,preparationReadLimit)];
|
|
548
|
+
const payload=loadHandoff(handoff,{task});
|
|
549
|
+
requireRevisions(revisions);
|
|
550
|
+
for(let attempt=1;attempt<=payload.attempt;attempt++){
|
|
551
|
+
for(const file of [expectedHandoff(reviewsDir,feature,task,attempt),reviewPath(reviewsDir,feature,task,attempt)]){
|
|
552
|
+
const pinned=fileRevision(file,preparationReadLimit);
|
|
553
|
+
if(!revisions.some(revision=>revision.path===pinned.path))revisions.push(pinned);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const approval={...checkN5(selectors)};
|
|
557
|
+
requireRevisions(revisions);
|
|
558
|
+
return {approval,revisions};
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function selectedTasksPath({tasksPath,reviewsDir,feature,task}){
|
|
562
|
+
requireFeature(feature);requireTaskId(task,'task');
|
|
563
|
+
let reviewsParent,tasksReal;
|
|
564
|
+
try{
|
|
565
|
+
reviewsParent=path.dirname(fs.realpathSync(reviewsDir));
|
|
566
|
+
tasksReal=fs.realpathSync(tasksPath);
|
|
567
|
+
}catch(error){throw new GateError(`cannot resolve task authority: ${error.message}`);}
|
|
568
|
+
const allowed=new Set();
|
|
569
|
+
for(const candidate of [path.join(reviewsParent,'tasks.md'),path.join(reviewsParent,feature,'tasks.md')]){
|
|
570
|
+
try{allowed.add(fs.realpathSync(candidate));}catch(error){if(error?.code!=='ENOENT')throw new GateError(`cannot resolve task authority: ${error.message}`);}
|
|
571
|
+
}
|
|
572
|
+
let entries;
|
|
573
|
+
try{entries=fs.readdirSync(reviewsParent,{withFileTypes:true});}
|
|
574
|
+
catch(error){throw new GateError(`cannot read specs root ${reviewsParent}: ${error.message}`);}
|
|
575
|
+
const suffix=`.${feature}`;
|
|
576
|
+
for(const entry of entries){
|
|
577
|
+
if(!entry.name.endsWith(suffix)||!/^[0-9]+$/.test(entry.name.slice(0,-suffix.length)))continue;
|
|
578
|
+
const directory=path.join(reviewsParent,entry.name);
|
|
579
|
+
try{
|
|
580
|
+
if(!fs.statSync(directory).isDirectory())continue;
|
|
581
|
+
allowed.add(fs.realpathSync(path.join(directory,'tasks.md')));
|
|
582
|
+
}catch(error){if(error?.code!=='ENOENT')throw new GateError(`cannot resolve task authority: ${error.message}`);}
|
|
583
|
+
}
|
|
584
|
+
if(!allowed.has(tasksReal))
|
|
585
|
+
throw new GateError(`tasks file must be the specs-local authority: ${[...allowed].sort().join(' or ')}`);
|
|
586
|
+
if(fs.lstatSync(tasksPath).isSymbolicLink())throw new GateError(`tasks file must not be a symlink: ${tasksPath}`);
|
|
587
|
+
return tasksReal;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function splitLinesKeepEnds(text){
|
|
591
|
+
const lines=[];let start=0;
|
|
592
|
+
for(let index=0;index<text.length;index++){
|
|
593
|
+
const character=text[index];
|
|
594
|
+
if(character==='\r'){
|
|
595
|
+
if(text[index+1]==='\n')index++;
|
|
596
|
+
lines.push({start,text:text.slice(start,index+1)});start=index+1;
|
|
597
|
+
}else if(/[\n\v\f\x1c-\x1e\x85\u2028\u2029]/.test(character)){
|
|
598
|
+
lines.push({start,text:text.slice(start,index+1)});start=index+1;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if(start<text.length)lines.push({start,text:text.slice(start)});
|
|
602
|
+
return lines;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function withoutLineEnding(line){return line.replace(/(?:\r\n|[\n\r\v\f\x1c-\x1e\x85\u2028\u2029])$/,'');}
|
|
606
|
+
function escapeRegExp(value){return value.replace(/[.*+?^${}()|[\]\\]/g,'\\$&');}
|
|
607
|
+
|
|
608
|
+
function parseTaskTarget(task,tasksPath,revision){
|
|
609
|
+
let text;
|
|
610
|
+
try{text=new TextDecoder('utf-8',{fatal:true}).decode(revision.bytes);}
|
|
611
|
+
catch(error){throw new GateError(`cannot read tasks file ${tasksPath}: ${error.message}`);}
|
|
612
|
+
const pattern=new RegExp(`^(\\s*-\\s*)\\[([ xX])\\](\\s+${escapeRegExp(task)}(?=[:\\s]|$).*)$`);
|
|
613
|
+
const matches=[];
|
|
614
|
+
for(const line of splitLinesKeepEnds(text)){
|
|
615
|
+
const match=pattern.exec(withoutLineEnding(line.text));
|
|
616
|
+
if(match)matches.push({line,match});
|
|
617
|
+
}
|
|
618
|
+
if(matches.length!==1)throw new GateError(`tasks file must contain exactly one checkbox for ${task}`);
|
|
619
|
+
return {text,...matches[0]};
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
function taskAfterBytes(target,original){
|
|
623
|
+
if(target.match[2].toLowerCase()==='x')return original;
|
|
624
|
+
const characterOffset=target.line.start+target.match[1].length+1;
|
|
625
|
+
const byteOffset=Buffer.byteLength(target.text.slice(0,characterOffset));
|
|
626
|
+
if(original[byteOffset]!==32)throw new GateError('task checkbox byte offset mismatch');
|
|
627
|
+
return Buffer.concat([original.subarray(0,byteOffset),Buffer.from('x'),original.subarray(byteOffset+1)]);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function canonical(value){
|
|
631
|
+
if(value===null||typeof value==='string'||typeof value==='boolean'||typeof value==='number')return JSON.stringify(value);
|
|
632
|
+
if(Array.isArray(value))return `[${value.map(canonical).join(',')}]`;
|
|
633
|
+
return `{${Object.keys(value).sort().map(key=>`${JSON.stringify(key)}:${canonical(value[key])}`).join(',')}}`;
|
|
634
|
+
}
|
|
635
|
+
function canonicalDigest(value){return createHash('sha256').update(canonical(value)).digest('hex');}
|
|
636
|
+
function opaqueRevision(revision){
|
|
637
|
+
return canonicalDigest({path:revision.path,stat:revision.stat,sha256:createHash('sha256').update(revision.bytes).digest('hex')});
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
export function prepareMarkDone(selectors){
|
|
641
|
+
if(preparationReadLimit!==null)throw new GateError('nested completion preparation is unsupported');
|
|
642
|
+
preparationReadLimit=PREPARATION_FILE_LIMIT;
|
|
643
|
+
try{
|
|
644
|
+
const tasks=selectedTasksPath(selectors),revision=fileRevision(tasks,preparationReadLimit);
|
|
645
|
+
const {approval,revisions}=pinApproval(selectors);
|
|
646
|
+
requireRevisions([revision]);
|
|
647
|
+
const target=parseTaskTarget(selectors.task,tasks,revision),after=taskAfterBytes(target,revision.bytes);
|
|
648
|
+
const physical=new Map();
|
|
649
|
+
for(const pinned of revisions){
|
|
650
|
+
const existing=physical.get(pinned.path);
|
|
651
|
+
if(existing&&!sameRevision(existing,pinned))throw new GateError('conflicting revisions for physical preparation evidence');
|
|
652
|
+
physical.set(pinned.path,pinned);
|
|
653
|
+
}
|
|
654
|
+
if(physical.size>4)throw new GateError('preparation evidence count exceeds bound');
|
|
655
|
+
const plan={
|
|
656
|
+
version:1,protocol:'cm-mark-done-plan',feature:selectors.feature,taskId:selectors.task,
|
|
657
|
+
attempt:approval.attempt,tasksPath:revision.path,mode:Number(BigInt(revision.stat[2])&0o7777n),
|
|
658
|
+
beforeBase64:revision.bytes.toString('base64'),afterBase64:after.toString('base64'),
|
|
659
|
+
beforeDigest:createHash('sha256').update(revision.bytes).digest('hex'),
|
|
660
|
+
afterDigest:createHash('sha256').update(after).digest('hex'),taskRevision:opaqueRevision(revision),
|
|
661
|
+
evidence:[...physical.values()].map(item=>({path:item.path,revision:opaqueRevision(item)})).sort((a,b)=>Buffer.compare(Buffer.from(a.path),Buffer.from(b.path))),
|
|
662
|
+
};
|
|
663
|
+
plan.planDigest=canonicalDigest(plan);
|
|
664
|
+
if(Buffer.byteLength(JSON.stringify(plan))>1024*1024)throw new GateError('preparation plan exceeds bound');
|
|
665
|
+
requireRevisions(revisions);requireRevisions([revision]);
|
|
666
|
+
return plan;
|
|
667
|
+
}finally{preparationReadLimit=null;}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export function verifyMarkDonePlan(selectors,expectedPlanDigest){
|
|
671
|
+
if(typeof expectedPlanDigest!=='string'||!/^[0-9a-f]{64}$/.test(expectedPlanDigest))
|
|
672
|
+
throw new GateError('expected plan digest must be lowercase SHA256');
|
|
673
|
+
const plan=prepareMarkDone(selectors);
|
|
674
|
+
if(plan.planDigest!==expectedPlanDigest)throw new GateError('preparation plan changed; refusing stale proposal');
|
|
675
|
+
return {outcome:'matched',planDigest:plan.planDigest};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function requireTaskLockAdapter(selectors,environment){
|
|
679
|
+
const expected=process.platform==='win32'
|
|
680
|
+
?path.join(fs.realpathSync(selectors.reviewsDir),'.cm-task-write.lock')
|
|
681
|
+
:path.join(fs.realpathSync(selectors.reviewsDir),'.execution','writer.sqlite');
|
|
682
|
+
let supplied='';
|
|
683
|
+
try{supplied=pathKey(fs.realpathSync.native(environment.CM_TASK_GATE_WRITER_LOCK));}catch{}
|
|
684
|
+
if(environment.CM_TASK_GATE_LOCK_ADAPTER!=='1'||Number(environment.CM_TASK_GATE_LOCK_PARENT_PID)!==process.ppid
|
|
685
|
+
||supplied!==pathKey(fs.realpathSync.native(expected)))
|
|
686
|
+
throw new GateError('mark-done requires the existing task ownership lock adapter');
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
export function markDoneLocked(selectors,expectedPlanDigest,environment=process.env){
|
|
690
|
+
requireTaskLockAdapter(selectors,environment);
|
|
691
|
+
const plan=prepareMarkDone(selectors);
|
|
692
|
+
if(plan.planDigest!==expectedPlanDigest)throw new GateError('preparation plan changed; refusing stale proposal');
|
|
693
|
+
const before=Buffer.from(plan.beforeBase64,'base64'),after=Buffer.from(plan.afterBase64,'base64');
|
|
694
|
+
const approval=checkN5(selectors);
|
|
695
|
+
if(before.equals(after)){
|
|
696
|
+
verifyMarkDonePlan(selectors,plan.planDigest);
|
|
697
|
+
return {...approval,outcome:'already_done',tasks:plan.tasksPath};
|
|
698
|
+
}
|
|
699
|
+
const parent=path.dirname(plan.tasksPath),temporary=path.join(parent,`.${path.basename(plan.tasksPath)}.${process.pid}.${randomUUID()}.tmp`);
|
|
700
|
+
let descriptor,renamed=false;
|
|
701
|
+
try{
|
|
702
|
+
descriptor=fs.openSync(temporary,fs.constants.O_WRONLY|fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_NOFOLLOW,0o600);
|
|
703
|
+
fs.writeFileSync(descriptor,after);fs.fsyncSync(descriptor);fs.fchmodSync(descriptor,plan.mode);
|
|
704
|
+
const temporaryBytes=fs.readFileSync(temporary);
|
|
705
|
+
if(!temporaryBytes.equals(after)||sha256(temporary)!==plan.afterDigest)throw new GateError('temporary task bytes changed');
|
|
706
|
+
fs.closeSync(descriptor);descriptor=undefined;
|
|
707
|
+
verifyMarkDonePlan(selectors,plan.planDigest);
|
|
708
|
+
fs.renameSync(temporary,plan.tasksPath);renamed=true;
|
|
709
|
+
if(process.platform!=='win32'){
|
|
710
|
+
const directory=fs.openSync(parent,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
|
|
711
|
+
try{fs.fsyncSync(directory);}finally{fs.closeSync(directory);}
|
|
712
|
+
}
|
|
713
|
+
return {...approval,outcome:'marked_done',tasks:plan.tasksPath};
|
|
714
|
+
}catch(error){
|
|
715
|
+
if(error instanceof GateError)throw error;
|
|
716
|
+
throw new GateError(`cannot atomically update tasks file ${plan.tasksPath}: ${error.message}`);
|
|
717
|
+
}finally{
|
|
718
|
+
if(descriptor!==undefined)try{fs.closeSync(descriptor);}catch{}
|
|
719
|
+
if(!renamed)try{fs.unlinkSync(temporary);}catch(error){if(error.code!=='ENOENT')throw error;}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function runGit(directory,...arguments_){
|
|
724
|
+
const result=childProcess.spawnSync('git',['-C',directory,...arguments_],{encoding:'utf8'});
|
|
725
|
+
if(result.error||result.status!==0){
|
|
726
|
+
const detail=result.stderr?.trim()||result.stdout?.trim()||result.error?.message||'git command failed';
|
|
727
|
+
throw new GateError(`git -C ${directory} ${arguments_.join(' ')}: ${detail}`);
|
|
728
|
+
}
|
|
729
|
+
return result.stdout.trim();
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function pathKey(value){
|
|
733
|
+
const normalized=path.normalize(value);
|
|
734
|
+
return process.platform==='win32'?normalized.toLowerCase():normalized;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function commonGitDir(directory){
|
|
738
|
+
const raw=runGit(directory,'rev-parse','--git-common-dir');
|
|
739
|
+
return pathKey(fs.realpathSync.native(path.resolve(directory,raw)));
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
function registeredWorktrees(repo){
|
|
743
|
+
const entries=new Map(),lines=[...runGit(repo,'worktree','list','--porcelain').split(/\r?\n/),''];
|
|
744
|
+
let current=null,branch='',detached=false;
|
|
745
|
+
for(const line of lines){
|
|
746
|
+
if(line.startsWith('worktree ')){
|
|
747
|
+
if(current!==null)entries.set(current,{branch,detached});
|
|
748
|
+
current=pathKey(fs.realpathSync.native(line.slice('worktree '.length)));branch='';detached=false;
|
|
749
|
+
}else if(line.startsWith('branch ')){
|
|
750
|
+
branch=line.startsWith('branch refs/heads/')?line.slice('branch refs/heads/'.length):line.slice('branch '.length);
|
|
751
|
+
}else if(line==='detached')detached=true;
|
|
752
|
+
else if(line===''&¤t!==null){entries.set(current,{branch,detached});current=null;}
|
|
753
|
+
}
|
|
754
|
+
return entries;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
function parseAssignment(raw){
|
|
758
|
+
const separator=raw.indexOf('=');
|
|
759
|
+
if(separator<0)throw new GateError('assignment must use T-xxx=/absolute/worktree/path');
|
|
760
|
+
const task=raw.slice(0,separator),rawPath=raw.slice(separator+1);
|
|
761
|
+
requireTaskId(task,'assignment task');requireString(rawPath,'assignment path');
|
|
762
|
+
if(!path.isAbsolute(rawPath))throw new GateError('assignment path must be absolute');
|
|
763
|
+
try{return {task,worktree:fs.realpathSync.native(rawPath)};}
|
|
764
|
+
catch(error){throw new GateError(`cannot resolve assignment path ${rawPath}: ${error.message}`);}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
export function checkParallelWrite({repo,assignment}){
|
|
768
|
+
let repository;
|
|
769
|
+
try{repository=fs.realpathSync.native(repo);}
|
|
770
|
+
catch(error){throw new GateError(`cannot resolve repository ${repo}: ${error.message}`);}
|
|
771
|
+
if(!Array.isArray(assignment)||assignment.length<2)
|
|
772
|
+
throw new GateError('parallel write guard requires at least two assignments');
|
|
773
|
+
const baseCommon=commonGitDir(repository),registered=registeredWorktrees(repository);
|
|
774
|
+
const assignments=assignment.map(parseAssignment);
|
|
775
|
+
if(new Set(assignments.map(item=>item.task)).size!==assignments.length)
|
|
776
|
+
throw new GateError('parallel write assignments must use unique task ids');
|
|
777
|
+
if(new Set(assignments.map(item=>pathKey(item.worktree))).size!==assignments.length)
|
|
778
|
+
throw new GateError('parallel write assignments must use distinct worktree paths');
|
|
779
|
+
const result=[];
|
|
780
|
+
for(const item of assignments){
|
|
781
|
+
const metadata=registered.get(pathKey(item.worktree));
|
|
782
|
+
if(!metadata)throw new GateError(`${item.task} path is not a registered worktree: ${item.worktree}`);
|
|
783
|
+
if(commonGitDir(item.worktree)!==baseCommon)
|
|
784
|
+
throw new GateError(`${item.task} worktree belongs to a different repository`);
|
|
785
|
+
const observed=runGit(item.worktree,'branch','--show-current');
|
|
786
|
+
if(metadata.detached||!metadata.branch||!observed)
|
|
787
|
+
throw new GateError(`${item.task} worktree must use a non-detached branch`);
|
|
788
|
+
if(metadata.branch!==observed)throw new GateError(`${item.task} branch metadata does not match the worktree`);
|
|
789
|
+
result.push({...item,branch:metadata.branch});
|
|
790
|
+
}
|
|
791
|
+
if(new Set(result.map(item=>item.branch)).size!==result.length)
|
|
792
|
+
throw new GateError('parallel write assignments must use distinct branches');
|
|
793
|
+
return {gate:'parallel-write',outcome:'isolated',assignments:result};
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function usage(){return 'usage: cm-task-gate.mjs {validate-handoff|hash-implementation|check-n4|check-n5|prepare-mark-done|verify-mark-done-plan|check-parallel-write} [options]';}
|
|
797
|
+
|
|
798
|
+
function parseCli(argv){
|
|
799
|
+
if(argv.length===0||argv.includes('--help')||argv.includes('-h'))return {help:true};
|
|
800
|
+
const command=argv[0];
|
|
801
|
+
if(!['validate-handoff','hash-implementation','check-n4','check-n5','prepare-mark-done','verify-mark-done-plan','mark-done-locked','check-parallel-write'].includes(command))
|
|
802
|
+
throw new GateError('unsupported command');
|
|
803
|
+
const allowed=command==='validate-handoff'?new Set(['--handoff','--task','--attempt'])
|
|
804
|
+
:command==='hash-implementation'?new Set(['--project-root','--file'])
|
|
805
|
+
:command==='check-parallel-write'?new Set(['--repo','--assignment'])
|
|
806
|
+
:new Set(['--handoff','--reviews-dir','--feature','--task','--project-root','--allow-legacy-unbound','--require-learning',
|
|
807
|
+
...(['prepare-mark-done','verify-mark-done-plan','mark-done-locked'].includes(command)?['--tasks']:[]),
|
|
808
|
+
...(['verify-mark-done-plan','mark-done-locked'].includes(command)?['--expected-plan-digest']:[])]);
|
|
809
|
+
const required=command==='validate-handoff'?new Set(['--handoff','--task','--attempt'])
|
|
810
|
+
:command==='hash-implementation'?new Set(['--project-root','--file'])
|
|
811
|
+
:command==='check-parallel-write'?new Set(['--repo','--assignment'])
|
|
812
|
+
:new Set(['--handoff','--reviews-dir','--feature','--task',
|
|
813
|
+
...(['prepare-mark-done','verify-mark-done-plan','mark-done-locked'].includes(command)?['--tasks']:[]),
|
|
814
|
+
...(['verify-mark-done-plan','mark-done-locked'].includes(command)?['--expected-plan-digest']:[])]);
|
|
815
|
+
const values={command};
|
|
816
|
+
for(let index=1;index<argv.length;){
|
|
817
|
+
const flag=argv[index];
|
|
818
|
+
if(!allowed.has(flag))throw new GateError('invalid arguments');
|
|
819
|
+
if(flag==='--allow-legacy-unbound'||flag==='--require-learning'){
|
|
820
|
+
const key=flag==='--require-learning'?'requireLearning':'allowLegacyUnbound';
|
|
821
|
+
if(Object.hasOwn(values,key))throw new GateError(`duplicate argument: ${flag}`);
|
|
822
|
+
values[key]=true;index++;continue;
|
|
823
|
+
}
|
|
824
|
+
const value=argv[index+1];if(value===undefined)throw new GateError('invalid arguments');
|
|
825
|
+
const key={'--handoff':'handoff','--reviews-dir':'reviewsDir','--feature':'feature','--task':'task','--attempt':'attempt',
|
|
826
|
+
'--tasks':'tasksPath','--expected-plan-digest':'expectedPlanDigest','--repo':'repo','--assignment':'assignment',
|
|
827
|
+
'--project-root':'projectRoot','--file':'file'}[flag];
|
|
828
|
+
if(['assignment','file'].includes(key)){
|
|
829
|
+
if(!Object.hasOwn(values,key))values[key]=[];
|
|
830
|
+
values[key].push(value);
|
|
831
|
+
}else{
|
|
832
|
+
if(Object.hasOwn(values,key))throw new GateError(`duplicate argument: ${flag}`);
|
|
833
|
+
values[key]=value;
|
|
834
|
+
}
|
|
835
|
+
index+=2;
|
|
836
|
+
}
|
|
837
|
+
for(const flag of required){
|
|
838
|
+
const key={'--handoff':'handoff','--reviews-dir':'reviewsDir','--feature':'feature','--task':'task','--attempt':'attempt',
|
|
839
|
+
'--tasks':'tasksPath','--expected-plan-digest':'expectedPlanDigest','--repo':'repo','--assignment':'assignment',
|
|
840
|
+
'--project-root':'projectRoot','--file':'file'}[flag];
|
|
841
|
+
if(!Object.hasOwn(values,key))throw new GateError(`missing argument: ${flag}`);
|
|
842
|
+
}
|
|
843
|
+
if(Object.hasOwn(values,'attempt')){
|
|
844
|
+
if(!/^[+-]?\d+$/.test(values.attempt))throw new GateError('attempt must be an integer');
|
|
845
|
+
values.attempt=Number(values.attempt);
|
|
846
|
+
}
|
|
847
|
+
return values;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
export function main(argv=process.argv.slice(2),environment=process.env){
|
|
851
|
+
let args,result;
|
|
852
|
+
try{
|
|
853
|
+
args=parseCli(argv);
|
|
854
|
+
if(args.help){process.stdout.write(`${usage()}\n`);return 0;}
|
|
855
|
+
if(args.command==='validate-handoff'){
|
|
856
|
+
requireTaskId(args.task,'task');
|
|
857
|
+
const payload=loadHandoff(args.handoff,{task:args.task,attempt:args.attempt});
|
|
858
|
+
result={gate:'handoff',task:payload.task_id,attempt:payload.attempt,outcome:payload.status};
|
|
859
|
+
}else if(args.command==='hash-implementation')result={gate:'implementation-hash',
|
|
860
|
+
implementation_sha256:implementationSha256(args.projectRoot,args.file),changed_files:[...args.file].sort((left,right)=>Buffer.compare(Buffer.from(left),Buffer.from(right)))};
|
|
861
|
+
else if(args.command==='check-n4')result=checkN4(args);
|
|
862
|
+
else if(args.command==='check-n5')result=checkN5(args);
|
|
863
|
+
else if(args.command==='prepare-mark-done')result=prepareMarkDone(args);
|
|
864
|
+
else if(args.command==='verify-mark-done-plan')result=verifyMarkDonePlan(args,args.expectedPlanDigest);
|
|
865
|
+
else if(args.command==='mark-done-locked')result=markDoneLocked(args,args.expectedPlanDigest,environment);
|
|
866
|
+
else result=checkParallelWrite(args);
|
|
867
|
+
}catch(error){
|
|
868
|
+
process.stderr.write(`ERROR: ${error.message}\n`);return error instanceof GateError?1:2;
|
|
869
|
+
}
|
|
870
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);return 0;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function isMain(entry){
|
|
874
|
+
if(!entry)return false;
|
|
875
|
+
try{return fs.realpathSync(entry)===fileURLToPath(import.meta.url);}
|
|
876
|
+
catch{return path.resolve(entry)===fileURLToPath(import.meta.url);}
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
if(isMain(process.argv[1]))process.exitCode=main();
|