@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,86 @@
|
|
|
1
|
+
// Offline data inspection only: never authenticates, dispatches or grants completion.
|
|
2
|
+
import {digest,need,shape,id,text,hex,json,validIdentity} from './effect-contract.mjs';
|
|
3
|
+
import {readReviewPackage} from './review-package.mjs';
|
|
4
|
+
import {reviewResult,reviewResultForPaths} from './review-runner.mjs';
|
|
5
|
+
import {MAX_REVIEW_EXCLUSIONS} from './effect-contract.mjs';
|
|
6
|
+
import {readFixCausePackage,causeReviewPaths} from '../cm-fix/cause-package.mjs';
|
|
7
|
+
|
|
8
|
+
function decode(raw,limit) {
|
|
9
|
+
need(typeof raw==='string');need(Buffer.byteLength(raw,'utf8')<=limit,'limit_exceeded');
|
|
10
|
+
return json(JSON.parse(raw),limit);
|
|
11
|
+
}
|
|
12
|
+
function expectation(v,cause=false) {
|
|
13
|
+
shape(v,['request','developerThreadId','excludedThreadIds']);
|
|
14
|
+
id(v.developerThreadId);need(Array.isArray(v.excludedThreadIds)&&v.excludedThreadIds.length<=MAX_REVIEW_EXCLUSIONS);
|
|
15
|
+
v.excludedThreadIds.forEach(id);
|
|
16
|
+
const r=v.request;
|
|
17
|
+
shape(r,['version','invocationId','identity','role','provider','requestedModel','contextId','payload','requestDigest']);
|
|
18
|
+
need(r.version===1&&r.role==='reviewer'&&['codex','claude'].includes(r.provider));
|
|
19
|
+
id(r.invocationId);id(r.contextId);validIdentity(r.identity);text(r.requestedModel);hex(r.requestDigest);
|
|
20
|
+
const {requestDigest,...body}=r;need(digest(body)===requestDigest,'observation_binding');
|
|
21
|
+
shape(r.payload,['reviewPackage','priorReview']);
|
|
22
|
+
const pkg=(cause?readFixCausePackage:readReviewPackage)(r.payload.reviewPackage);
|
|
23
|
+
if(cause)need(r.payload.priorReview===null,'observation_binding');
|
|
24
|
+
need(digest(pkg.identity)===digest(r.identity),'observation_binding');
|
|
25
|
+
return {request:r,pkg,excluded:new Set([v.developerThreadId,...v.excludedThreadIds])};
|
|
26
|
+
}
|
|
27
|
+
function eventStream(events,excluded) {
|
|
28
|
+
need(Array.isArray(events)&&events.length<=64);
|
|
29
|
+
let stage=0,thread=null,terminal=null,close=null;
|
|
30
|
+
for(const e of events) {
|
|
31
|
+
need(close===null);
|
|
32
|
+
if(e?.event==='process_closed') {
|
|
33
|
+
shape(e,['event','exit_code','signal','timed_out']);
|
|
34
|
+
need(e.exit_code===null||Number.isInteger(e.exit_code)&&e.exit_code>=-255&&e.exit_code<=255);
|
|
35
|
+
need(e.signal===null||typeof e.signal==='string'&&e.signal.trim().length>0&&e.signal.length<=64);
|
|
36
|
+
need(typeof e.timed_out==='boolean');close=e;continue;
|
|
37
|
+
}
|
|
38
|
+
need(terminal===null);
|
|
39
|
+
if(e?.event==='thread.started') {
|
|
40
|
+
shape(e,['event','provider_thread']);need(stage===0);id(e.provider_thread);
|
|
41
|
+
need(!excluded.has(e.provider_thread),'observation_context');thread=e.provider_thread;stage=1;
|
|
42
|
+
}else {
|
|
43
|
+
shape(e,['event','item_type']);
|
|
44
|
+
if(e.event==='turn.started'){need(stage===1&&e.item_type===null);stage=2;}
|
|
45
|
+
else if(e.event==='item.completed'){need(stage===2&&e.item_type==='agent_message');stage=3;}
|
|
46
|
+
else if(e.event==='turn.completed'){need(stage===3&&e.item_type===null);terminal=e.event;}
|
|
47
|
+
else {need(['error','turn.failed'].includes(e.event)&&e.item_type===null);terminal=e.event;}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {thread,terminal,close};
|
|
51
|
+
}
|
|
52
|
+
export function inspectProviderReview(observationText,expectationText) {
|
|
53
|
+
need(arguments.length===2);
|
|
54
|
+
return inspect(observationText,expectationText,false);
|
|
55
|
+
}
|
|
56
|
+
export function inspectProviderCauseReview(observationText,expectationText){
|
|
57
|
+
need(arguments.length===2);
|
|
58
|
+
return inspect(observationText,expectationText,true);
|
|
59
|
+
}
|
|
60
|
+
function inspect(observationText,expectationText,cause) {
|
|
61
|
+
try {
|
|
62
|
+
const observation=decode(observationText,1024*1024),expected=expectation(decode(expectationText,10*1024*1024),cause);
|
|
63
|
+
shape(observation,['version','kind','requestDigest','events','result']);
|
|
64
|
+
need(observation.version===1&&observation.kind==='cm-provider-review-observation');
|
|
65
|
+
hex(observation.requestDigest);need(observation.requestDigest===expected.request.requestDigest,'observation_binding');
|
|
66
|
+
const {thread,terminal,close}=eventStream(observation.events,expected.excluded),r=observation.result;
|
|
67
|
+
if(r?.status==='succeeded')shape(r,['status','value']);
|
|
68
|
+
else {shape(r,['status','code']);need(['failed','cancelled'].includes(r.status));text(r.code);need(r.code.length<=256);}
|
|
69
|
+
let observationStatus='unknown',code='transport_incomplete',review=null;
|
|
70
|
+
if(close?.timed_out===true||r.code==='timeout')code='transport_timeout';
|
|
71
|
+
else if(r.status==='cancelled'||r.code==='cancelled'){observationStatus='cancelled';code='transport_cancelled';}
|
|
72
|
+
else if(close?.exit_code===0&&close.signal===null&&terminal==='turn.completed'&&r.status==='succeeded'){
|
|
73
|
+
review=cause?reviewResultForPaths(r.value,expected.pkg,causeReviewPaths(expected.pkg)):reviewResult(r.value,expected.pkg);
|
|
74
|
+
observationStatus='completed';code=null;
|
|
75
|
+
}
|
|
76
|
+
return json({version:1,kind:cause?'cm-provider-cause-review-inspection':'cm-provider-review-inspection',requestDigest:expected.request.requestDigest,
|
|
77
|
+
observationDigest:digest(observation),identity:expected.request.identity,logicalContextId:expected.request.contextId,
|
|
78
|
+
provider:expected.request.provider,requestedModel:expected.request.requestedModel,effectiveModel:null,providerThreadId:thread,
|
|
79
|
+
observationStatus,code,review,completionEligible:false});
|
|
80
|
+
}catch(error){
|
|
81
|
+
const allowed=['limit_exceeded','observation_binding','observation_context','invalid_package',
|
|
82
|
+
'review_package_mismatch','missing_material','contradictory_verdict'];
|
|
83
|
+
const code=allowed.includes(error?.code)?error.code:'observation_invalid';
|
|
84
|
+
throw Object.assign(new Error(code),{code});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Bind a trusted host configuration to current log evidence. Reports never
|
|
2
|
+
// supply executable configuration, scope or authority.
|
|
3
|
+
import {readHostQaFixHandoff} from './host-qa-fix.mjs';
|
|
4
|
+
import {qaFixIdentity,inspectFixQaSource} from '../cm-fix/qa-source.mjs';
|
|
5
|
+
import {digest,json,need,shape,validIdentity} from './effect-contract.mjs';
|
|
6
|
+
|
|
7
|
+
export function bindQaFixDefinition({template,identity,packageDigest,testRunId}){
|
|
8
|
+
const fixed=json(template,64*1024);
|
|
9
|
+
shape(fixed,['specsRoot','feature','identity','configuration']);validIdentity(fixed.identity);
|
|
10
|
+
validIdentity(identity);
|
|
11
|
+
need(digest({...identity,attempt:fixed.identity.attempt})===digest(fixed.identity)
|
|
12
|
+
&&identity.attempt>=fixed.identity.attempt&&identity.attempt<=2,'qa_fix_source_mismatch');
|
|
13
|
+
need(!Object.hasOwn(fixed.configuration,'qaSource'),'invalid_fix_template');
|
|
14
|
+
const handoff=readHostQaFixHandoff({specsDir:fixed.specsRoot,codeProject:fixed.configuration.reproduction.cwd,
|
|
15
|
+
feature:fixed.feature,identity,packageDigest,testRunId});
|
|
16
|
+
need(handoff.status!=='blocked','fix_qa_source_blocked');
|
|
17
|
+
const qaSource={feature:fixed.feature,identity,packageDigest,testRunId,handoffDigest:handoff.handoffDigest};
|
|
18
|
+
const definition={specsRoot:fixed.specsRoot,identity:qaFixIdentity(qaSource),configuration:{...fixed.configuration,qaSource}};
|
|
19
|
+
inspectFixQaSource(definition);
|
|
20
|
+
return json(definition,64*1024);
|
|
21
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Immutable file projection shared by review publishers, not an approval issuer.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {randomUUID} from 'node:crypto';
|
|
5
|
+
import {need} from './effect-contract.mjs';
|
|
6
|
+
|
|
7
|
+
export function writeReviewEvidence({reviewsDir,name,bytes,validate=()=>{},inspectOnly=false,exclusive=false}){
|
|
8
|
+
need(typeof name==='string'&&/^[A-Za-z0-9._-]+\.md$/.test(name),'unsupported_path');
|
|
9
|
+
return writeImmutableWorkflowFile({reviewsDir,name,bytes,validate,inspectOnly,exclusive});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Shared no-overwrite publication for fixed workflow Markdown/JSON artifacts.
|
|
13
|
+
export function writeImmutableWorkflowFile({reviewsDir,name,bytes,validate=()=>{},inspectOnly=false,exclusive=false}){
|
|
14
|
+
need(path.isAbsolute(reviewsDir)&&fs.realpathSync(reviewsDir)===reviewsDir
|
|
15
|
+
&&fs.lstatSync(reviewsDir).isDirectory(),'unsupported_path');
|
|
16
|
+
need(typeof name==='string'&&/^[A-Za-z0-9._-]+\.(md|json)$/.test(name)&&Buffer.isBuffer(bytes),'unsupported_path');
|
|
17
|
+
need(bytes.length<=256*1024,'limit_exceeded');
|
|
18
|
+
const target=path.join(reviewsDir,name);
|
|
19
|
+
const verify=()=>{
|
|
20
|
+
const stat=fs.lstatSync(target);
|
|
21
|
+
need(stat.isFile()&&!stat.isSymbolicLink()&&stat.nlink===1&&stat.size===bytes.length,'review_file_conflict');
|
|
22
|
+
need(fs.readFileSync(target).equals(bytes),'review_file_conflict');validate(target);
|
|
23
|
+
};
|
|
24
|
+
if(inspectOnly){verify();return {outcome:'published',path:target};}
|
|
25
|
+
const temp=path.join(reviewsDir,`.cm-review-${randomUUID()}`);let fd;
|
|
26
|
+
try{
|
|
27
|
+
fd=fs.openSync(temp,fs.constants.O_WRONLY|fs.constants.O_CREAT|fs.constants.O_EXCL,0o600);
|
|
28
|
+
fs.writeFileSync(fd,bytes);fs.fsyncSync(fd);fs.closeSync(fd);fd=undefined;validate(temp);
|
|
29
|
+
try{fs.linkSync(temp,target);}catch(error){if(error.code!=='EEXIST')throw error;need(!exclusive,'review_file_conflict');verify();}
|
|
30
|
+
fs.unlinkSync(temp);
|
|
31
|
+
const dir=fs.openSync(reviewsDir,fs.constants.O_RDONLY);
|
|
32
|
+
try{fs.fsyncSync(dir);}finally{fs.closeSync(dir);}
|
|
33
|
+
return {outcome:'published',path:target};
|
|
34
|
+
}finally{
|
|
35
|
+
if(fd!==undefined)fs.closeSync(fd);
|
|
36
|
+
try{fs.unlinkSync(temp);}catch(error){if(error.code!=='ENOENT')throw error;}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
// S2a offline content binding only. No reviewer authentication or task writes.
|
|
2
|
+
// Trusted fixture hosts only: callers own authorization and a quiescent root.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
|
+
import { digest } from './contracts.mjs';
|
|
7
|
+
import {resolveCodeProjects,validateCodeProjectPaths,
|
|
8
|
+
codeProjectInstructionPaths,assertCodeProjectSelections} from './code-projects.mjs';
|
|
9
|
+
|
|
10
|
+
const FILE_LIMIT=1024*1024, SNAPSHOT_LIMIT=2*1024*1024, FILE_COUNT=256;
|
|
11
|
+
// Inventory budgets bound scanning, independently of the much smaller review body.
|
|
12
|
+
const INVENTORY_COUNT=10000, INVENTORY_LIMIT=1024*1024*1024;
|
|
13
|
+
const materialPath=(p,selected)=>selected.has(p)||p.split('/').at(-1)==='AGENTS.md';
|
|
14
|
+
// Fixed dependency/cache directories, not caller-controlled business exclusions.
|
|
15
|
+
// Keep this narrower than the discovery scanner: dist/build may be authored files.
|
|
16
|
+
const dependencyDirectories=new Set(['.venv','node_modules','__pycache__','.pytest_cache','.ruff_cache']);
|
|
17
|
+
const inDependencyDirectory=p=>p.split('/').slice(0,-1).some(part=>dependencyDirectories.has(part.toLowerCase()));
|
|
18
|
+
const sha = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
19
|
+
const fail = code => { const error=new Error(code); error.code=code; throw error; };
|
|
20
|
+
const need = (condition,code='invalid_input') => { if(!condition) fail(code); };
|
|
21
|
+
const record = v => v!==null && typeof v==='object' && !Array.isArray(v);
|
|
22
|
+
const keys = (v,expected) => need(record(v) && Object.keys(v).sort().join('|')===[...expected].sort().join('|'));
|
|
23
|
+
const id = v => need(typeof v==='string' && /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(v));
|
|
24
|
+
|
|
25
|
+
// Inspect descriptors before reading values; never execute input accessors.
|
|
26
|
+
function plain(value, ancestors=new Set(), depth=0) {
|
|
27
|
+
need(depth<=40);
|
|
28
|
+
if(value===null || ['string','boolean'].includes(typeof value)) return value;
|
|
29
|
+
if(typeof value==='number') { need(Number.isFinite(value)); return value; }
|
|
30
|
+
need(typeof value==='object' && !ancestors.has(value));
|
|
31
|
+
need((Array.isArray(value) ? [Array.prototype] : [Object.prototype,null]).includes(Object.getPrototypeOf(value)));
|
|
32
|
+
need(Object.getOwnPropertySymbols(value).length===0);
|
|
33
|
+
const descriptors=Object.getOwnPropertyDescriptors(value), array=Array.isArray(value);
|
|
34
|
+
const names=Object.keys(descriptors).filter(k=>!array || k!=='length');
|
|
35
|
+
if(array) need(names.length===value.length && names.every((k,i)=>k===String(i)));
|
|
36
|
+
ancestors.add(value);
|
|
37
|
+
const pairs=names.map(k=>{
|
|
38
|
+
const d=descriptors[k]; need(Object.hasOwn(d,'value') && d.enumerable);
|
|
39
|
+
return [k,plain(d.value,ancestors,depth+1)];
|
|
40
|
+
});
|
|
41
|
+
ancestors.delete(value);
|
|
42
|
+
return array ? pairs.map(([,v])=>v) : Object.fromEntries(pairs);
|
|
43
|
+
}
|
|
44
|
+
function freeze(value) {
|
|
45
|
+
if(value && typeof value==='object') { Object.values(value).forEach(freeze); Object.freeze(value); }
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
function identityCheck(v) {
|
|
49
|
+
keys(v,['repositoryId','runId','taskId','attempt']);
|
|
50
|
+
[v.repositoryId,v.runId,v.taskId].forEach(id); need([1,2].includes(v.attempt));
|
|
51
|
+
}
|
|
52
|
+
function filePath(p) {
|
|
53
|
+
need(typeof p==='string' && p.length>0 && !/[\\:\x00-\x1f\x7f-\x9f]/.test(p)
|
|
54
|
+
&& p.normalize('NFC')===p,'unsupported_path');
|
|
55
|
+
const parts=p.split('/');
|
|
56
|
+
need(parts.every(s=>s && s!=='.' && s!=='..'),'unsupported_path');
|
|
57
|
+
need(parts.every(s=>!['.git','.ssh','.aws','.gnupg'].includes(s.toLowerCase())
|
|
58
|
+
&& !/^\.env(?:\.|$)/i.test(s)),'unsupported_path');
|
|
59
|
+
return p;
|
|
60
|
+
}
|
|
61
|
+
function paths(input) {
|
|
62
|
+
need(Array.isArray(input) && input.length>0 && input.length<=FILE_COUNT);
|
|
63
|
+
const result=input.map(filePath).sort();
|
|
64
|
+
need(new Set(result.map(p=>p.toLowerCase())).size===result.length,'unsupported_path');
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
function rootPath(root) {
|
|
68
|
+
need(typeof root==='string' && path.isAbsolute(root),'unsupported_path');
|
|
69
|
+
try { const real=fs.realpathSync(root); need(fs.statSync(real).isDirectory(),'unsupported_file'); return real; }
|
|
70
|
+
catch(error) { if(error.code==='unsupported_file')throw error; fail('read_failed'); }
|
|
71
|
+
}
|
|
72
|
+
const statKey = s => [s.dev,s.ino,s.mode,s.nlink,s.size,s.mtimeNs,s.ctimeNs].join(':');
|
|
73
|
+
function readFile(root,p,includeContent=true,limit=FILE_LIMIT) {
|
|
74
|
+
let fd;
|
|
75
|
+
try {
|
|
76
|
+
const abs=path.join(root,p),before=fs.lstatSync(abs,{bigint:true});
|
|
77
|
+
need(before.isFile() && before.nlink===1n,'unsupported_file');
|
|
78
|
+
need(before.size<=BigInt(limit),'limit_exceeded');
|
|
79
|
+
fd=fs.openSync(abs,fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW??0));
|
|
80
|
+
const opened=fs.fstatSync(fd,{bigint:true});
|
|
81
|
+
need(statKey(before)===statKey(opened),'snapshot_changed');
|
|
82
|
+
const buf=Buffer.alloc(Math.min(Number(before.size)+1,64*1024)),hash=createHash('sha256'),chunks=[];
|
|
83
|
+
let offset=0;
|
|
84
|
+
while(offset<=Number(before.size)) {
|
|
85
|
+
const count=fs.readSync(fd,buf,0,Math.min(buf.length,Number(before.size)+1-offset),null);
|
|
86
|
+
if(!count)break;
|
|
87
|
+
hash.update(buf.subarray(0,count));
|
|
88
|
+
if(includeContent)chunks.push(Buffer.from(buf.subarray(0,count)));
|
|
89
|
+
offset+=count;
|
|
90
|
+
}
|
|
91
|
+
const after=fs.fstatSync(fd,{bigint:true}),last=fs.lstatSync(abs,{bigint:true});
|
|
92
|
+
need(statKey(before)===statKey(after) && statKey(before)===statKey(last)
|
|
93
|
+
&& offset===Number(before.size),'snapshot_changed');
|
|
94
|
+
return {path:p,type:'file',mode:Number(before.mode & 0o7777n),size:offset,
|
|
95
|
+
sha256:hash.digest('hex'),...(includeContent?{contentBase64:Buffer.concat(chunks).toString('base64')}:{})};
|
|
96
|
+
} catch(error) {
|
|
97
|
+
if(['unsupported_file','limit_exceeded','snapshot_changed'].includes(error.code))throw error;
|
|
98
|
+
fail('read_failed');
|
|
99
|
+
} finally { if(fd!==undefined) fs.closeSync(fd); }
|
|
100
|
+
}
|
|
101
|
+
// The only excluded business subtree is the host-owned specs root, not an
|
|
102
|
+
// arbitrary ignore list. Pure path mapping is shared with journal validation.
|
|
103
|
+
export function reviewSpecsPath(root,specsRoot) {
|
|
104
|
+
for(const p of [root,specsRoot])need(typeof p==='string'&&path.isAbsolute(p)&&path.resolve(p)===p&&!p.includes('\0'),'unsupported_path');
|
|
105
|
+
need(root!==specsRoot&&!root.startsWith(specsRoot+path.sep),'overlapping_roots');
|
|
106
|
+
return specsRoot.startsWith(root+path.sep)?filePath(path.relative(root,specsRoot).split(path.sep).join('/')):null;
|
|
107
|
+
}
|
|
108
|
+
function snapshot(root,specsPath=null,projectPaths=null,retainedPaths=[],selected=null) {
|
|
109
|
+
if(specsPath!==null){
|
|
110
|
+
const target=path.join(root,specsPath);
|
|
111
|
+
need(fs.realpathSync(target)===target&&fs.lstatSync(target).isDirectory(),'unsupported_path');
|
|
112
|
+
}
|
|
113
|
+
const files=[],seen=new Set(); let total=0,materialBytes=0,materialCount=0;
|
|
114
|
+
function add(p,s){
|
|
115
|
+
need(s.isFile()&&!s.isSymbolicLink()&&s.nlink===1,'unsupported_file');
|
|
116
|
+
const includeContent=selected===null||materialPath(p,selected);
|
|
117
|
+
const countLimit=selected===null?FILE_COUNT:INVENTORY_COUNT;
|
|
118
|
+
const byteLimit=selected===null?SNAPSHOT_LIMIT:INVENTORY_LIMIT;
|
|
119
|
+
need(files.length<countLimit&&total+s.size<=byteLimit,'limit_exceeded');
|
|
120
|
+
if(includeContent)need(materialCount<FILE_COUNT&&materialBytes+s.size<=SNAPSHOT_LIMIT,'limit_exceeded');
|
|
121
|
+
const f=readFile(root,p,includeContent,includeContent?Math.min(FILE_LIMIT,SNAPSHOT_LIMIT-materialBytes):byteLimit-total);
|
|
122
|
+
total+=f.size;
|
|
123
|
+
if(includeContent){materialBytes+=f.size;materialCount++;}
|
|
124
|
+
files.push(f);
|
|
125
|
+
}
|
|
126
|
+
function walk(rel='',depth=0,codeRoot='') {
|
|
127
|
+
need(depth<=32,'limit_exceeded');
|
|
128
|
+
let names;
|
|
129
|
+
try { names=fs.readdirSync(path.join(root,rel)).sort(); } catch { fail('read_failed'); }
|
|
130
|
+
for(const name of names) {
|
|
131
|
+
const p=rel ? rel+'/'+name : name;
|
|
132
|
+
let s; try { s=fs.lstatSync(path.join(root,p)); } catch { fail('read_failed'); }
|
|
133
|
+
// Linked worktrees use a regular .git pointer file instead of a directory.
|
|
134
|
+
// Treat both as Git metadata, never read/follow the pointer or traverse it.
|
|
135
|
+
// Scope and requirement paths still cannot select any .git entry.
|
|
136
|
+
if(p===(codeRoot?codeRoot+'/.git':'.git') && !s.isSymbolicLink()
|
|
137
|
+
&& (s.isDirectory() || (s.isFile() && s.nlink===1))) continue;
|
|
138
|
+
filePath(p);
|
|
139
|
+
const alias=p.toLowerCase(); need(!seen.has(alias),'unsupported_path'); seen.add(alias);
|
|
140
|
+
if(p===specsPath){need(s.isDirectory()&&!s.isSymbolicLink(),'unsupported_path');continue;}
|
|
141
|
+
// Never follow a dependency-root symlink. Old baselines that captured
|
|
142
|
+
// these files still verify their original material instead of dropping it.
|
|
143
|
+
if(s.isDirectory()&&dependencyDirectories.has(name)
|
|
144
|
+
&&!retainedPaths.some(file=>file.startsWith(p+'/')))continue;
|
|
145
|
+
if(s.isDirectory()) walk(p,depth+1,codeRoot);
|
|
146
|
+
else add(p,s);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if(projectPaths===null)walk();
|
|
150
|
+
else{
|
|
151
|
+
const roots=projectPaths.map(prefix=>path.join(root,prefix));
|
|
152
|
+
resolveCodeProjects(root,roots);
|
|
153
|
+
for(const prefix of projectPaths)walk(prefix,0,prefix);
|
|
154
|
+
for(const p of codeProjectInstructionPaths(projectPaths)){
|
|
155
|
+
if(projectPaths.some(prefix=>p.startsWith(prefix+'/')))continue;
|
|
156
|
+
let stat;try{stat=fs.lstatSync(path.join(root,p));}catch(error){if(error.code==='ENOENT')continue;throw error;}
|
|
157
|
+
need(!seen.has(p.toLowerCase()),'unsupported_path');seen.add(p.toLowerCase());add(p,stat);
|
|
158
|
+
}
|
|
159
|
+
resolveCodeProjects(root,roots);
|
|
160
|
+
}
|
|
161
|
+
return files.sort((a,b)=>a.path<b.path?-1:a.path>b.path?1:0);
|
|
162
|
+
}
|
|
163
|
+
const sealed = (data,key) => {
|
|
164
|
+
const result={...data,[key]:digest(data)};
|
|
165
|
+
need(Buffer.byteLength(JSON.stringify(result))<=8*1024*1024,'limit_exceeded');
|
|
166
|
+
return freeze(result);
|
|
167
|
+
};
|
|
168
|
+
export function captureReviewBaseline(options) {
|
|
169
|
+
const v=plain(options); keys(v,['root','identity','scope','requirements',
|
|
170
|
+
...['specsRoot','codeProjectPaths','bootstrapRequirements','version'].filter(key=>Object.hasOwn(v,key))]); identityCheck(v.identity);
|
|
171
|
+
const version=v.version??2;need([1,2].includes(version));
|
|
172
|
+
const bootstrap=Object.hasOwn(v,'bootstrapRequirements')?v.bootstrapRequirements:null;
|
|
173
|
+
if(bootstrap!==null){
|
|
174
|
+
validBootstrapRequirements(bootstrap);
|
|
175
|
+
need(Object.hasOwn(v,'specsRoot')&&bootstrap.specsRoot===v.specsRoot,'bootstrap_requirements_mismatch');
|
|
176
|
+
currentBootstrapRequirements(bootstrap);
|
|
177
|
+
}
|
|
178
|
+
const scope=paths(v.scope), requirements=requirementPaths(v.requirements,bootstrap!==null),root=rootPath(v.root);
|
|
179
|
+
need(![...scope,...requirements].some(inDependencyDirectory),'excluded_snapshot_path');
|
|
180
|
+
const projectPaths=Object.hasOwn(v,'codeProjectPaths')?validateCodeProjectPaths(v.codeProjectPaths):null;
|
|
181
|
+
if(projectPaths!==null)resolveCodeProjects(v.root,projectPaths.map(prefix=>path.join(root,prefix)));
|
|
182
|
+
const specsPath=Object.hasOwn(v,'specsRoot')?reviewSpecsPath(root,v.specsRoot):null;
|
|
183
|
+
if(specsPath!==null)validateSpecsSelection(specsPath,[...scope,...requirements]);
|
|
184
|
+
if(projectPaths!==null){
|
|
185
|
+
if(specsPath!==null)validateProjectSpecs(specsPath,projectPaths);
|
|
186
|
+
assertCodeProjectSelections(projectPaths,[...scope,...requirements],{allowInstructions:true});
|
|
187
|
+
}
|
|
188
|
+
const files=snapshot(root,specsPath,projectPaths,[],version===1?null:new Set([...scope,...requirements]));
|
|
189
|
+
need(requirements.every(p=>files.some(f=>f.path===p)),'read_failed');
|
|
190
|
+
for(const p of scope) {
|
|
191
|
+
const absolute=path.join(root,p);
|
|
192
|
+
if(fs.existsSync(absolute)) need(fs.lstatSync(absolute).isFile(),'unsupported_file');
|
|
193
|
+
}
|
|
194
|
+
return sealed({version,kind:'cm-review-baseline',identity:v.identity,rootDigest:sha(root),
|
|
195
|
+
scope,requirements,files,...(specsPath===null?{}:{specsPath}),
|
|
196
|
+
...(projectPaths===null?{}:{codeProjectPaths:projectPaths}),
|
|
197
|
+
...(bootstrap===null?{}:{bootstrapRequirements:bootstrap})},'baselineDigest');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Bounded selected-file material for pre-implementation reviews; no whole-tree scan.
|
|
201
|
+
export function readReviewSourceFiles(root,selected){
|
|
202
|
+
let total=0;
|
|
203
|
+
const real=rootPath(root),files=paths(selected).map(p=>{
|
|
204
|
+
const parts=p.split('/');let parent=real;
|
|
205
|
+
for(const part of parts.slice(0,-1)){
|
|
206
|
+
parent=path.join(parent,part);
|
|
207
|
+
const stat=fs.lstatSync(parent);
|
|
208
|
+
need(stat.isDirectory()&&!stat.isSymbolicLink()&&fs.realpathSync(parent)===parent,'unsupported_path');
|
|
209
|
+
}
|
|
210
|
+
const file=readFile(real,p);total+=file.size;need(total<=SNAPSHOT_LIMIT,'limit_exceeded');return file;
|
|
211
|
+
});
|
|
212
|
+
return freeze(files);
|
|
213
|
+
}
|
|
214
|
+
function validateSpecsSelection(specsPath,selections) {
|
|
215
|
+
filePath(specsPath);
|
|
216
|
+
const boundary=specsPath.toLowerCase();
|
|
217
|
+
need(selections.every(p=>{const name=p.toLowerCase();return name!==boundary
|
|
218
|
+
&&!name.startsWith(boundary+'/')&&!boundary.startsWith(name+'/');}),'protected_specs');
|
|
219
|
+
}
|
|
220
|
+
function validateProjectSpecs(specsPath,projectPaths){
|
|
221
|
+
const boundary=specsPath.toLowerCase();
|
|
222
|
+
need(projectPaths.every(prefix=>prefix.toLowerCase()!==boundary
|
|
223
|
+
&&!prefix.toLowerCase().startsWith(boundary+'/')),'protected_specs');
|
|
224
|
+
}
|
|
225
|
+
function requirementPaths(value,bootstrap){
|
|
226
|
+
return bootstrap&&Array.isArray(value)&&value.length===0?[]:paths(value);
|
|
227
|
+
}
|
|
228
|
+
const hex = v => need(typeof v==='string' && /^[a-f0-9]{64}$/.test(v));
|
|
229
|
+
function fileRecord(f) {
|
|
230
|
+
keys(f,['path','type','mode','size','sha256','contentBase64']); filePath(f.path);
|
|
231
|
+
need(f.type==='file' && Number.isInteger(f.mode) && f.mode>=0 && f.mode<=0o7777);
|
|
232
|
+
need(Number.isInteger(f.size) && f.size>=0 && f.size<=FILE_LIMIT);
|
|
233
|
+
hex(f.sha256); need(typeof f.contentBase64==='string' && f.contentBase64.length<=Math.ceil(FILE_LIMIT/3)*4);
|
|
234
|
+
const bytes=Buffer.from(f.contentBase64,'base64');
|
|
235
|
+
need(bytes.toString('base64')===f.contentBase64 && bytes.length===f.size && sha(bytes)===f.sha256);
|
|
236
|
+
}
|
|
237
|
+
function fileList(files) {
|
|
238
|
+
need(Array.isArray(files) && files.length>0 && files.length<=FILE_COUNT);
|
|
239
|
+
files.forEach(fileRecord);
|
|
240
|
+
const names=files.map(f=>f.path); need(digest(names)===digest(paths(names)));
|
|
241
|
+
need(files.reduce((sum,f)=>sum+f.size,0)<=SNAPSHOT_LIMIT,'limit_exceeded');
|
|
242
|
+
}
|
|
243
|
+
// V2 keeps exact records for review material and digest-only records elsewhere.
|
|
244
|
+
// V1 validation stays unchanged for existing journals and their fixed digests.
|
|
245
|
+
function inventoryList(b) {
|
|
246
|
+
const files=b.files,selected=new Set([...b.scope,...b.requirements]);
|
|
247
|
+
need(Array.isArray(files)&&files.length<=INVENTORY_COUNT);
|
|
248
|
+
const material=[];let total=0,previous=null;const aliases=new Set();
|
|
249
|
+
for(const f of files){
|
|
250
|
+
if(materialPath(f.path,selected)){fileRecord(f);material.push(f);}
|
|
251
|
+
else{
|
|
252
|
+
keys(f,['path','type','mode','size','sha256']);filePath(f.path);
|
|
253
|
+
need(f.type==='file'&&Number.isInteger(f.mode)&&f.mode>=0&&f.mode<=0o7777);
|
|
254
|
+
need(Number.isSafeInteger(f.size)&&f.size>=0&&f.size<=INVENTORY_LIMIT);hex(f.sha256);
|
|
255
|
+
}
|
|
256
|
+
need(previous===null||previous<f.path);previous=f.path;
|
|
257
|
+
need(!aliases.has(f.path.toLowerCase()));aliases.add(f.path.toLowerCase());
|
|
258
|
+
total+=f.size;need(total<=INVENTORY_LIMIT);
|
|
259
|
+
}
|
|
260
|
+
if(material.length)fileList(material);
|
|
261
|
+
need(Buffer.byteLength(JSON.stringify(b))<=8*1024*1024,'limit_exceeded');
|
|
262
|
+
}
|
|
263
|
+
const bootstrapPaths=['0.bootstrap/design.md','0.bootstrap/requirements.md'];
|
|
264
|
+
function validBootstrapRequirements(value,published=false){
|
|
265
|
+
keys(value,['feature','files',published?'rootDigest':'specsRoot']);
|
|
266
|
+
need(value.feature==='0.bootstrap','bootstrap_requirements_invalid');
|
|
267
|
+
if(published)hex(value.rootDigest);
|
|
268
|
+
else need(typeof value.specsRoot==='string'&&path.isAbsolute(value.specsRoot)
|
|
269
|
+
&&path.resolve(value.specsRoot)===value.specsRoot&&!value.specsRoot.includes('\0'),'unsupported_path');
|
|
270
|
+
fileList(value.files);
|
|
271
|
+
need(digest(value.files.map(file=>file.path))===digest(bootstrapPaths)
|
|
272
|
+
&&value.files.every(file=>file.size>0),'bootstrap_requirements_invalid');
|
|
273
|
+
}
|
|
274
|
+
function currentBootstrapRequirements(value){
|
|
275
|
+
need(fs.realpathSync(value.specsRoot)===value.specsRoot,'unsupported_path');
|
|
276
|
+
const files=readReviewSourceFiles(value.specsRoot,bootstrapPaths);
|
|
277
|
+
need(digest(files)===digest(value.files),'bootstrap_requirements_changed');
|
|
278
|
+
return {feature:value.feature,files:value.files,rootDigest:sha(value.specsRoot)};
|
|
279
|
+
}
|
|
280
|
+
export function readReviewSourceRecords(raw){
|
|
281
|
+
const files=plain(raw);fileList(files);return freeze(files);
|
|
282
|
+
}
|
|
283
|
+
function validBaseline(b) {
|
|
284
|
+
try {
|
|
285
|
+
keys(b,['version','kind','identity','rootDigest','scope','requirements','files','baselineDigest',
|
|
286
|
+
...['specsPath','codeProjectPaths','bootstrapRequirements'].filter(key=>Object.hasOwn(b,key))]);
|
|
287
|
+
need([1,2].includes(b.version) && b.kind==='cm-review-baseline'); identityCheck(b.identity); hex(b.rootDigest);
|
|
288
|
+
const bootstrap=Object.hasOwn(b,'bootstrapRequirements');if(bootstrap)validBootstrapRequirements(b.bootstrapRequirements);
|
|
289
|
+
need(digest(b.scope)===digest(paths(b.scope)) && digest(b.requirements)===digest(requirementPaths(b.requirements,bootstrap)));
|
|
290
|
+
if(b.version===2)inventoryList(b);
|
|
291
|
+
else if(!bootstrap||b.files.length)fileList(b.files);else need(Array.isArray(b.files));
|
|
292
|
+
need(b.requirements.every(p=>b.files.some(f=>f.path===p)));
|
|
293
|
+
if(Object.hasOwn(b,'specsPath'))validateSpecsSelection(b.specsPath,[...b.scope,...b.requirements,...b.files.map(f=>f.path)]);
|
|
294
|
+
if(Object.hasOwn(b,'codeProjectPaths')){
|
|
295
|
+
need(digest(b.codeProjectPaths)===digest(validateCodeProjectPaths(b.codeProjectPaths)));
|
|
296
|
+
assertCodeProjectSelections(b.codeProjectPaths,[...b.scope,...b.requirements,...b.files.map(f=>f.path)],{allowInstructions:true});
|
|
297
|
+
if(Object.hasOwn(b,'specsPath'))validateProjectSpecs(b.specsPath,b.codeProjectPaths);
|
|
298
|
+
}
|
|
299
|
+
const {baselineDigest,...data}=b; hex(baselineDigest); need(digest(data)===baselineDigest);
|
|
300
|
+
} catch { fail('invalid_baseline'); }
|
|
301
|
+
}
|
|
302
|
+
function validChecks(checks) {
|
|
303
|
+
need(Array.isArray(checks) && checks.length>0);
|
|
304
|
+
need(Buffer.byteLength(JSON.stringify(checks))<=64*1024,'limit_exceeded');
|
|
305
|
+
const ids=new Set();
|
|
306
|
+
for(const c of checks) {
|
|
307
|
+
if(c.kind==='visual'){
|
|
308
|
+
keys(c,['id','kind','outcome','evidence','before','after']);id(c.id);need(!ids.has(c.id));ids.add(c.id);
|
|
309
|
+
need(['passed','failed','unavailable'].includes(c.outcome));
|
|
310
|
+
need(typeof c.evidence==='string'&&c.evidence.trim().length>0);
|
|
311
|
+
const carrier=value=>{
|
|
312
|
+
keys(value,['path','sha256','kind','description']);hex(value.sha256);
|
|
313
|
+
need(typeof value.path==='string'&&path.isAbsolute(value.path)&&path.resolve(value.path)===value.path
|
|
314
|
+
&&!/[\x00-\x1f\x7f-\x9f]/.test(value.path));
|
|
315
|
+
need(['screenshot','video'].includes(value.kind));
|
|
316
|
+
need(typeof value.description==='string'&&value.description.trim().length>0);
|
|
317
|
+
};
|
|
318
|
+
carrier(c.before);need((c.after===null)===(c.outcome==='unavailable'));
|
|
319
|
+
if(c.after!==null)carrier(c.after);
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
keys(c,['id','command','outcome','exitCode','evidence']); id(c.id); need(!ids.has(c.id)); ids.add(c.id);
|
|
323
|
+
need(Array.isArray(c.command) && c.command.length>0 && c.command.every(a=>typeof a==='string' && a.length>0));
|
|
324
|
+
need(typeof c.evidence==='string' && c.evidence.trim().length>0);
|
|
325
|
+
need(c.outcome==='passed' && c.exitCode===0
|
|
326
|
+
|| c.outcome==='failed' && Number.isSafeInteger(c.exitCode) && c.exitCode!==0
|
|
327
|
+
|| c.outcome==='unavailable' && c.exitCode===null);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
export function createReviewPackage(options) {
|
|
331
|
+
const v=plain(options); keys(v,['root','baseline','checks',...(Object.hasOwn(v,'handoffPath')?['handoffPath']:[])]); const b=v.baseline;
|
|
332
|
+
validBaseline(b); validChecks(v.checks);
|
|
333
|
+
const root=rootPath(v.root); need(sha(root)===b.rootDigest,'invalid_baseline');
|
|
334
|
+
const bootstrap=Object.hasOwn(b,'bootstrapRequirements')?currentBootstrapRequirements(b.bootstrapRequirements):null;
|
|
335
|
+
if(bootstrap!==null)need(reviewSpecsPath(root,b.bootstrapRequirements.specsRoot)===(b.specsPath??null),'bootstrap_requirements_mismatch');
|
|
336
|
+
const files=snapshot(root,b.specsPath??null,b.codeProjectPaths??null,b.files.map(f=>f.path),b.version===1?null:new Set([...b.scope,...b.requirements])),before=new Map(b.files.map(f=>[f.path,f])),after=new Map(files.map(f=>[f.path,f]));
|
|
337
|
+
const changes=[];
|
|
338
|
+
for(const p of [...new Set([...before.keys(),...after.keys()])].sort()) {
|
|
339
|
+
const old=before.get(p)??null,current=after.get(p)??null;
|
|
340
|
+
if(digest(old)===digest(current))continue;
|
|
341
|
+
need(b.scope.includes(p),'out_of_scope'); changes.push({path:p,before:old,after:current});
|
|
342
|
+
}
|
|
343
|
+
need(changes.length>0,'empty_changes');
|
|
344
|
+
const requirements=b.requirements.map(p=>{ need(after.has(p),'read_failed'); return after.get(p); });
|
|
345
|
+
const pkg=sealed({version:1,kind:'cm-review-package',identity:b.identity,rootDigest:b.rootDigest,
|
|
346
|
+
baseIdentity:b.baselineDigest,scope:b.scope,changes,requirements,checks:v.checks,
|
|
347
|
+
...(Object.hasOwn(b,'codeProjectPaths')?{codeProjectPaths:b.codeProjectPaths,
|
|
348
|
+
instructions:files.filter(file=>file.path.split('/').at(-1)==='AGENTS.md')}:{}),
|
|
349
|
+
...(bootstrap===null?{}:{bootstrapRequirements:bootstrap}),
|
|
350
|
+
...(Object.hasOwn(v,'handoffPath')?{handoff:readHandoffSnapshot(v.handoffPath)}:{}),
|
|
351
|
+
artifactDigest:digest(changes),requirementsDigest:digest(requirements),checksDigest:digest(v.checks)},'packageDigest');
|
|
352
|
+
need(Buffer.byteLength(JSON.stringify(pkg))<=8*1024*1024,'limit_exceeded');
|
|
353
|
+
return pkg;
|
|
354
|
+
}
|
|
355
|
+
function validPackage(p) {
|
|
356
|
+
try {
|
|
357
|
+
keys(p,['version','kind','identity','rootDigest','baseIdentity','scope','changes','requirements',
|
|
358
|
+
'checks','artifactDigest','requirementsDigest','checksDigest','packageDigest',
|
|
359
|
+
...(Object.hasOwn(p,'handoff')?['handoff']:[]),
|
|
360
|
+
...(Object.hasOwn(p,'codeProjectPaths')?['codeProjectPaths','instructions']:[]),
|
|
361
|
+
...(Object.hasOwn(p,'bootstrapRequirements')?['bootstrapRequirements']:[])]);
|
|
362
|
+
if(Object.hasOwn(p,'handoff')) {
|
|
363
|
+
fileRecord(p.handoff);need(!p.handoff.path.includes('/')&&p.handoff.size<=256*1024);
|
|
364
|
+
}
|
|
365
|
+
need(p.version===1 && p.kind==='cm-review-package'); identityCheck(p.identity);
|
|
366
|
+
[p.rootDigest,p.baseIdentity,p.artifactDigest,p.requirementsDigest,p.checksDigest,p.packageDigest].forEach(hex);
|
|
367
|
+
need(digest(p.scope)===digest(paths(p.scope)));
|
|
368
|
+
need(Array.isArray(p.changes) && p.changes.length>0 && p.changes.length<=FILE_COUNT);
|
|
369
|
+
const names=[];
|
|
370
|
+
for(const change of p.changes) {
|
|
371
|
+
keys(change,['path','before','after']); filePath(change.path); need(p.scope.includes(change.path));
|
|
372
|
+
names.push(change.path); need(change.before!==null || change.after!==null);
|
|
373
|
+
for(const f of [change.before,change.after]) if(f!==null) { fileRecord(f); need(f.path===change.path); }
|
|
374
|
+
need(digest(change.before)!==digest(change.after));
|
|
375
|
+
}
|
|
376
|
+
need(digest(names)===digest(paths(names)));
|
|
377
|
+
if(Object.hasOwn(p,'bootstrapRequirements')){
|
|
378
|
+
validBootstrapRequirements(p.bootstrapRequirements,true);
|
|
379
|
+
if(p.requirements.length)fileList(p.requirements);else need(Array.isArray(p.requirements));
|
|
380
|
+
}else fileList(p.requirements);
|
|
381
|
+
validChecks(p.checks);
|
|
382
|
+
if(Object.hasOwn(p,'codeProjectPaths')){
|
|
383
|
+
need(digest(p.codeProjectPaths)===digest(validateCodeProjectPaths(p.codeProjectPaths)));
|
|
384
|
+
need(Array.isArray(p.instructions));if(p.instructions.length)fileList(p.instructions);
|
|
385
|
+
need(p.instructions.every(file=>file.path.split('/').at(-1)==='AGENTS.md'));
|
|
386
|
+
assertCodeProjectSelections(p.codeProjectPaths,[...p.scope,...p.requirements.map(f=>f.path),...p.instructions.map(f=>f.path)],{allowInstructions:true});
|
|
387
|
+
for(const file of p.instructions){
|
|
388
|
+
const change=p.changes.find(item=>item.path===file.path),requirement=p.requirements.find(item=>item.path===file.path);
|
|
389
|
+
if(change)need(digest(file)===digest(change.after));
|
|
390
|
+
if(requirement)need(digest(file)===digest(requirement));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
need(digest(p.changes)===p.artifactDigest && digest(p.requirements)===p.requirementsDigest
|
|
394
|
+
&& digest(p.checks)===p.checksDigest);
|
|
395
|
+
const {packageDigest,...data}=p; need(digest(data)===packageDigest);
|
|
396
|
+
need(Buffer.byteLength(JSON.stringify(p))<=8*1024*1024);
|
|
397
|
+
} catch { fail('invalid_package'); }
|
|
398
|
+
}
|
|
399
|
+
export function verifyReviewPackage(options) {
|
|
400
|
+
const v=plain(options); keys(v,['root','baseline','checks','reviewPackage','expectedDigest',
|
|
401
|
+
...(Object.hasOwn(v,'handoffPath')?['handoffPath']:[])]);
|
|
402
|
+
hex(v.expectedDigest); validBaseline(v.baseline); validPackage(v.reviewPackage);
|
|
403
|
+
need(v.reviewPackage.packageDigest===v.expectedDigest,'package_mismatch');
|
|
404
|
+
need(Object.hasOwn(v.reviewPackage,'handoff')===Object.hasOwn(v,'handoffPath'),'package_mismatch');
|
|
405
|
+
const current=createReviewPackage({root:v.root,baseline:v.baseline,checks:v.checks,
|
|
406
|
+
...(Object.hasOwn(v,'handoffPath')?{handoffPath:v.handoffPath}:{})});
|
|
407
|
+
need(current.packageDigest===v.expectedDigest,'package_mismatch');
|
|
408
|
+
return freeze({outcome:'matched',packageDigest:current.packageDigest});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// The host supplies this separate specs-root file; workers never select it.
|
|
412
|
+
// Reuse the bounded no-follow snapshot reader and store bytes, not a live path.
|
|
413
|
+
function readHandoffSnapshot(p) {
|
|
414
|
+
need(typeof p==='string'&&path.isAbsolute(p)&&path.resolve(p)===p,'unsupported_path');
|
|
415
|
+
const parent=path.dirname(p),name=filePath(path.basename(p));
|
|
416
|
+
need(fs.realpathSync(parent)===parent,'unsupported_path');
|
|
417
|
+
const file=readFile(parent,name);need(file.size<=256*1024,'limit_exceeded');return file;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Offline readers deliberately do not sample the current (possibly modified) tree.
|
|
421
|
+
export function readReviewBaseline(raw) {
|
|
422
|
+
const value=plain(raw);validBaseline(value);return freeze(value);
|
|
423
|
+
}
|
|
424
|
+
export function readReviewPackage(raw) {
|
|
425
|
+
const value=plain(raw);validPackage(value);return freeze(value);
|
|
426
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://cm-workflow.local/schemas/codex-review-result-v1.json",
|
|
4
|
+
"title": "CM Codex reviewer result",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": ["verdict", "packageDigest", "examinedPaths", "findings", "summary"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"verdict": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"enum": ["approved", "changes_requested", "blocked"]
|
|
12
|
+
},
|
|
13
|
+
"packageDigest": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"pattern": "^[a-f0-9]{64}$"
|
|
16
|
+
},
|
|
17
|
+
"examinedPaths": {
|
|
18
|
+
"type": "array",
|
|
19
|
+
"uniqueItems": true,
|
|
20
|
+
"items": { "type": "string", "minLength": 1 }
|
|
21
|
+
},
|
|
22
|
+
"findings": {
|
|
23
|
+
"type": "array",
|
|
24
|
+
"maxItems": 100,
|
|
25
|
+
"items": {
|
|
26
|
+
"type": "object",
|
|
27
|
+
"additionalProperties": false,
|
|
28
|
+
"required": ["id", "severity", "path", "message", "evidence"],
|
|
29
|
+
"properties": {
|
|
30
|
+
"id": { "type": "string", "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$" },
|
|
31
|
+
"severity": { "type": "string", "enum": ["P0", "P1", "P2", "P3"] },
|
|
32
|
+
"path": { "type": "string", "minLength": 1 },
|
|
33
|
+
"message": { "type": "string", "minLength": 1 },
|
|
34
|
+
"evidence": { "type": "string", "minLength": 1 }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"summary": { "type": "string", "minLength": 1 }
|
|
39
|
+
}
|
|
40
|
+
}
|