@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,289 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import {execFileSync} from 'node:child_process';
|
|
7
|
+
import {digest} from '../runtime/js/cm-ai/contracts.mjs';
|
|
8
|
+
import {captureReviewBaseline,createReviewPackage,verifyReviewPackage,readReviewBaseline,
|
|
9
|
+
readReviewPackage,readReviewSourceFiles} from '../runtime/js/cm-ai/review-package.mjs';
|
|
10
|
+
import {codeProjectPaths,resolveCodeProjects,groupCodeProjectPaths,codeProjectInstructionPaths}
|
|
11
|
+
from '../runtime/js/cm-ai/code-projects.mjs';
|
|
12
|
+
import {applyProtectedEdits,captureProtectedEdits,commitProtectedEdits} from '../runtime/js/cm-fix/protected-edits.mjs';
|
|
13
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
14
|
+
import {reviewResult,reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
15
|
+
|
|
16
|
+
const identity={repositoryId:'multi-root-fixture',runId:'r3-fixture',taskId:'T-001',attempt:1};
|
|
17
|
+
const checks=[{id:'aggregate',command:['node','check.mjs'],outcome:'passed',exitCode:0,evidence:'Synthetic aggregate check'}];
|
|
18
|
+
const moduleURL=new URL('../runtime/js/cm-ai/review-package.mjs',import.meta.url).href;
|
|
19
|
+
function write(root,file,content){
|
|
20
|
+
const target=path.join(root,file);fs.mkdirSync(path.dirname(target),{recursive:true});fs.writeFileSync(target,content);
|
|
21
|
+
}
|
|
22
|
+
function fixture(t){
|
|
23
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-multi-root-')));
|
|
24
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
25
|
+
for(const prefix of ['apps/api','apps/web']){
|
|
26
|
+
write(root,`${prefix}/AGENTS.md`,`# ${prefix} instructions\n`);
|
|
27
|
+
write(root,`${prefix}/source.mjs`,'export const value = 1;\n');
|
|
28
|
+
write(root,`${prefix}/requirement.md`,`Requirement for ${prefix}\n`);
|
|
29
|
+
write(root,`${prefix}/.git`,'gitdir: deliberately unread pointer\n');
|
|
30
|
+
}
|
|
31
|
+
write(root,'AGENTS.md','# Workspace instructions\n');write(root,'apps/AGENTS.md','# Shared app instructions\n');
|
|
32
|
+
write(root,'unrelated/.env','synthetic unrelated data');
|
|
33
|
+
write(root,'specs/1.feature/tasks.md','- [ ] T-001: One task across both roots\n');
|
|
34
|
+
const codeProjects=['apps/web','apps/api'].map(prefix=>path.join(root,prefix));
|
|
35
|
+
const options={root,codeProjectPaths:['apps/web','apps/api'],specsRoot:path.join(root,'specs'),identity,
|
|
36
|
+
scope:['apps/api/source.mjs','apps/web/source.mjs'],requirements:['apps/api/requirement.md','apps/web/requirement.md']};
|
|
37
|
+
return {root,codeProjects,options};
|
|
38
|
+
}
|
|
39
|
+
function editBoth(root,codeProjects,scope){
|
|
40
|
+
for(const group of groupCodeProjectPaths(root,codeProjects,scope)){
|
|
41
|
+
const expected=captureProtectedEdits(group.codeProject,group.paths);
|
|
42
|
+
applyProtectedEdits({cwd:group.codeProject,scope:group.paths,edits:group.paths.map(file=>({
|
|
43
|
+
path:file,beforeSha256:expected[file],content:'export const value = 2;\n'}))});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const resign=(value,key)=>{const {[key]:old,...body}=value;return {...body,[key]:digest(body)};};
|
|
47
|
+
|
|
48
|
+
test('visual check shape binds carriers without changing original command checks',t=>{
|
|
49
|
+
const {root,codeProjects,options}=fixture(t),baseline=captureReviewBaseline(options);
|
|
50
|
+
editBoth(root,codeProjects,options.scope);
|
|
51
|
+
const before={path:path.join(root,'specs/before.png'),sha256:'a'.repeat(64),kind:'screenshot',description:'Synthetic before descriptor'};
|
|
52
|
+
const after={...before,path:path.join(root,'specs/after.png'),sha256:'b'.repeat(64)};
|
|
53
|
+
const visual={id:'visual',kind:'visual',outcome:'passed',evidence:'Synthetic shape validation only',before,after};
|
|
54
|
+
for(const outcome of ['passed','failed','unavailable']){
|
|
55
|
+
const result={...visual,outcome,after:outcome==='unavailable'?null:after};
|
|
56
|
+
const pkg=createReviewPackage({root,baseline,checks:[...checks,result]});
|
|
57
|
+
assert.deepEqual(readReviewPackage(pkg).checks,[...checks,result]);
|
|
58
|
+
}
|
|
59
|
+
for(const invalid of [{...visual,after:null},{...visual,outcome:'unavailable'},
|
|
60
|
+
{...visual,command:['fake']},{...visual,before:{...before,path:'relative.png'}},
|
|
61
|
+
{...visual,after:{...after,sha256:'bad'}},{...visual,after:{...after,description:' '}}])
|
|
62
|
+
assert.throws(()=>createReviewPackage({root,baseline,checks:[invalid]}));
|
|
63
|
+
assert.throws(()=>createReviewPackage({root,baseline,checks:[visual,visual]}));
|
|
64
|
+
const pkg=createReviewPackage({root,baseline,checks:[visual]});
|
|
65
|
+
assert.throws(()=>readReviewPackage({...pkg,checks:[{...visual,after:{...after,sha256:'c'.repeat(64)}}]}));
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('one aggregate baseline/package binds both roots and actual instructions, excluding unrelated siblings',t=>{
|
|
69
|
+
const {root,codeProjects,options}=fixture(t),baseline=captureReviewBaseline(options);
|
|
70
|
+
assert.deepEqual(baseline.codeProjectPaths,['apps/api','apps/web']);
|
|
71
|
+
assert(!baseline.files.some(file=>file.path.startsWith('unrelated/')||file.path.startsWith('specs/')||file.path.endsWith('/.git')));
|
|
72
|
+
const instructionPaths=['AGENTS.md','apps/AGENTS.md','apps/api/AGENTS.md','apps/web/AGENTS.md'];
|
|
73
|
+
assert.deepEqual(codeProjectInstructionPaths(baseline.codeProjectPaths),instructionPaths);
|
|
74
|
+
editBoth(root,codeProjects,options.scope);
|
|
75
|
+
const pkg=createReviewPackage({root,baseline,checks});
|
|
76
|
+
assert.deepEqual(pkg.identity,identity);assert.deepEqual(pkg.changes.map(change=>change.path),options.scope);
|
|
77
|
+
assert.deepEqual(pkg.instructions.map(file=>file.path),instructionPaths);
|
|
78
|
+
assert.deepEqual(readReviewBaseline(baseline),baseline);assert.deepEqual(readReviewPackage(pkg),pkg);
|
|
79
|
+
const result={verdict:'approved',packageDigest:pkg.packageDigest,examinedPaths:reviewPaths(pkg),findings:[],summary:'Synthetic one-package review'};
|
|
80
|
+
assert.equal(reviewResult(result,pkg).verdict,'approved');
|
|
81
|
+
assert.throws(()=>reviewResult({...result,examinedPaths:result.examinedPaths.filter(file=>!file.startsWith('apps/web/'))},pkg),{code:'missing_material'});
|
|
82
|
+
write(root,'unrelated/new.txt','outside declared roots');
|
|
83
|
+
assert.equal(verifyReviewPackage({root,baseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
|
|
84
|
+
write(root,'apps/web/AGENTS.md','# Changed web instructions\n');
|
|
85
|
+
assert.throws(()=>verifyReviewPackage({root,baseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}),{code:'out_of_scope'});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('missing, overlapping, aliased roots and scope outside selected roots fail before any edits',t=>{
|
|
89
|
+
const {root,codeProjects,options}=fixture(t);
|
|
90
|
+
for(const selected of [['missing'],['.'],['apps','apps/web'],['apps/web','apps/web'],['apps/web','apps/WEB']])
|
|
91
|
+
assert.throws(()=>captureReviewBaseline({...options,codeProjectPaths:selected}));
|
|
92
|
+
fs.symlinkSync('web',path.join(root,'apps/linked'));
|
|
93
|
+
assert.throws(()=>resolveCodeProjects(root,[path.join(root,'apps/linked')]),{code:'unsupported_path'});
|
|
94
|
+
for(const scope of [['unrelated/new.txt'],['apps/web'],['AGENTS.md']])
|
|
95
|
+
assert.throws(()=>groupCodeProjectPaths(root,codeProjects,scope),{code:'out_of_scope'});
|
|
96
|
+
assert.throws(()=>captureReviewBaseline({...options,scope:['unrelated/new.txt']}),{code:'out_of_scope'});
|
|
97
|
+
assert.throws(()=>captureReviewBaseline({...options,requirements:['unrelated/new.txt']}),{code:'out_of_scope'});
|
|
98
|
+
const baseline=captureReviewBaseline(options);editBoth(root,codeProjects,options.scope);
|
|
99
|
+
write(root,'apps/web/extra.mjs','outside the task scope');
|
|
100
|
+
assert.throws(()=>createReviewPackage({root,baseline,checks}),{code:'out_of_scope'});
|
|
101
|
+
assert.equal(fs.readFileSync(path.join(root,'AGENTS.md'),'utf8'),'# Workspace instructions\n');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('persisted aggregate resumes in a new process and missing roots cannot become deletion-only success',t=>{
|
|
105
|
+
const {root,codeProjects,options}=fixture(t),baseline=captureReviewBaseline(options);
|
|
106
|
+
editBoth(root,codeProjects,options.scope);const pkg=createReviewPackage({root,baseline,checks});
|
|
107
|
+
const saved=path.join(root,'specs/recovery.json');
|
|
108
|
+
fs.writeFileSync(saved,JSON.stringify({root,baseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}));
|
|
109
|
+
const source=`import fs from 'node:fs';import {verifyReviewPackage,readReviewBaseline} from ${JSON.stringify(moduleURL)};
|
|
110
|
+
const saved=JSON.parse(fs.readFileSync(process.argv[1]));readReviewBaseline(saved.baseline);
|
|
111
|
+
process.stdout.write(JSON.stringify(verifyReviewPackage(saved)));`;
|
|
112
|
+
assert.equal(JSON.parse(execFileSync(process.execPath,['--input-type=module','-e',source,saved],{encoding:'utf8'})).outcome,'matched');
|
|
113
|
+
fs.renameSync(path.join(root,'apps/web'),path.join(root,'unrelated/saved-web'));
|
|
114
|
+
assert.deepEqual(readReviewBaseline(baseline),baseline); // offline history remains readable
|
|
115
|
+
assert.throws(()=>createReviewPackage({root,baseline,checks}));
|
|
116
|
+
assert.throws(()=>execFileSync(process.execPath,['--input-type=module','-e',source,saved],{stdio:'pipe'}));
|
|
117
|
+
fs.symlinkSync('../unrelated/saved-web',path.join(root,'apps/web'));
|
|
118
|
+
assert.throws(()=>createReviewPackage({root,baseline,checks}));
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('root metadata is sealed and workspace Learning remains separate from each root instructions',t=>{
|
|
122
|
+
const {root,codeProjects,options}=fixture(t);
|
|
123
|
+
const baseline=captureReviewBaseline({...options,scope:[...options.scope,'AGENTS.md']});
|
|
124
|
+
editBoth(root,codeProjects,options.scope);write(root,'AGENTS.md','# Workspace instructions\nHost Learning entry\n');
|
|
125
|
+
const pkg=createReviewPackage({root,baseline,checks});
|
|
126
|
+
assert(pkg.changes.some(change=>change.path==='AGENTS.md'));
|
|
127
|
+
const tampered=structuredClone(baseline);tampered.codeProjectPaths=['apps/api'];
|
|
128
|
+
assert.throws(()=>readReviewBaseline(tampered),{code:'invalid_baseline'});
|
|
129
|
+
assert.throws(()=>readReviewBaseline(resign(tampered,'baselineDigest')),{code:'invalid_baseline'});
|
|
130
|
+
const changed=structuredClone(pkg);changed.instructions[0].contentBase64=Buffer.from('other').toString('base64');
|
|
131
|
+
assert.throws(()=>readReviewPackage(resign(changed,'packageDigest')),{code:'invalid_package'});
|
|
132
|
+
assert.deepEqual(codeProjectPaths(root,codeProjects),baseline.codeProjectPaths);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('a selected root may contain protected specs but specs cannot be a selected code root',t=>{
|
|
136
|
+
const {root,options}=fixture(t);write(root,'apps/api/specs/task.md','original host state');
|
|
137
|
+
const specsRoot=path.join(root,'apps/api/specs');
|
|
138
|
+
const baseline=captureReviewBaseline({...options,specsRoot});
|
|
139
|
+
assert(!baseline.files.some(file=>file.path.startsWith('apps/api/specs/')));
|
|
140
|
+
assert.throws(()=>captureReviewBaseline({...options,specsRoot,scope:['apps/api/specs/task.md']}),{code:'protected_specs'});
|
|
141
|
+
assert.throws(()=>captureReviewBaseline({...options,specsRoot,codeProjectPaths:['apps/api/specs']}),{code:'protected_specs'});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('original single-root baseline and package keep their exact default fields and digest shape',t=>{
|
|
145
|
+
const {root}=fixture(t),single=path.join(root,'apps/api');
|
|
146
|
+
const baseline=captureReviewBaseline({root:single,identity,scope:['source.mjs'],requirements:['requirement.md']});
|
|
147
|
+
assert.deepEqual(Object.keys(baseline).sort(),['version','kind','identity','rootDigest','scope','requirements','files','baselineDigest'].sort());
|
|
148
|
+
assert.deepEqual(baseline,resign(baseline,'baselineDigest'));
|
|
149
|
+
write(single,'source.mjs','changed\n');const pkg=createReviewPackage({root:single,baseline,checks});
|
|
150
|
+
assert.deepEqual(Object.keys(pkg).sort(),['version','kind','identity','rootDigest','baseIdentity','scope','changes','requirements','checks',
|
|
151
|
+
'artifactDigest','requirementsDigest','checksDigest','packageDigest'].sort());
|
|
152
|
+
assert.equal(verifyReviewPackage({root:single,baseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test('bootstrap evidence permits empty code requirements, binds original req/design and ignores task checkbox changes',t=>{
|
|
156
|
+
const {root,options}=fixture(t),specsRoot=options.specsRoot;
|
|
157
|
+
write(specsRoot,'0.bootstrap/requirements.md','# Approved bootstrap requirements\n');
|
|
158
|
+
write(specsRoot,'0.bootstrap/design.md','# Approved bootstrap design\n');
|
|
159
|
+
write(specsRoot,'0.bootstrap/tasks.md','- [ ] T-001: Bootstrap both roots\n');
|
|
160
|
+
const files=readReviewSourceFiles(specsRoot,['0.bootstrap/requirements.md','0.bootstrap/design.md']);
|
|
161
|
+
const bootstrapRequirements={specsRoot,feature:'0.bootstrap',files};
|
|
162
|
+
assert.throws(()=>captureReviewBaseline({...options,requirements:[]}));
|
|
163
|
+
const baseline=captureReviewBaseline({...options,requirements:[],bootstrapRequirements});
|
|
164
|
+
assert.deepEqual(baseline.requirements,[]);assert.deepEqual(readReviewBaseline(baseline),baseline);
|
|
165
|
+
editBoth(root,options.codeProjectPaths.map(prefix=>path.join(root,prefix)),options.scope);const pkg=createReviewPackage({root,baseline,checks});
|
|
166
|
+
assert.deepEqual(pkg.bootstrapRequirements.files,files);assert.deepEqual(readReviewPackage(pkg),pkg);
|
|
167
|
+
write(specsRoot,'0.bootstrap/tasks.md','- [x] T-001: Bootstrap both roots\n');
|
|
168
|
+
assert.equal(verifyReviewPackage({root,baseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
|
|
169
|
+
const withTasks={...bootstrapRequirements,files:readReviewSourceFiles(specsRoot,['0.bootstrap/requirements.md','0.bootstrap/design.md','0.bootstrap/tasks.md'])};
|
|
170
|
+
assert.throws(()=>captureReviewBaseline({...options,requirements:[],bootstrapRequirements:withTasks}));
|
|
171
|
+
assert.throws(()=>captureReviewBaseline({...options,requirements:[],bootstrapRequirements:{...bootstrapRequirements,specsRoot:root}}),{code:'bootstrap_requirements_mismatch'});
|
|
172
|
+
const empty=path.join(root,'empty');fs.mkdirSync(empty);
|
|
173
|
+
const initial=captureReviewBaseline({root:empty,specsRoot,identity,scope:['AGENTS.md'],requirements:[],bootstrapRequirements});
|
|
174
|
+
assert.deepEqual(readReviewBaseline(initial).files,[]);
|
|
175
|
+
write(empty,'AGENTS.md','# Bootstrap-produced instructions\n');
|
|
176
|
+
assert.deepEqual(readReviewPackage(createReviewPackage({root:empty,baseline:initial,checks})).bootstrapRequirements.files,files);
|
|
177
|
+
write(specsRoot,'0.bootstrap/design.md','# Changed after approval\n');
|
|
178
|
+
assert.deepEqual(readReviewBaseline(baseline),baseline);
|
|
179
|
+
assert.throws(()=>createReviewPackage({root,baseline,checks}),{code:'bootstrap_requirements_changed'});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('native protected edits and real checks run per declared cwd and bind into one package',
|
|
183
|
+
{skip:process.platform!=='darwin',timeout:30000},async t=>{
|
|
184
|
+
const {root,codeProjects,options}=fixture(t),baseline=captureReviewBaseline(options),observed=[];
|
|
185
|
+
const signal=new AbortController().signal;
|
|
186
|
+
for(const [index,group] of groupCodeProjectPaths(root,codeProjects,options.scope).entries()){
|
|
187
|
+
const expected=captureProtectedEdits(group.codeProject,group.paths);
|
|
188
|
+
await commitProtectedEdits({cwd:group.codeProject,specsRoot:options.specsRoot,scope:group.paths,expected,identity,signal,timeoutMs:5000,
|
|
189
|
+
edits:group.paths.map(file=>({path:file,beforeSha256:expected[file],content:'export const value = 2;\n'}))});
|
|
190
|
+
const source=`const fs=require('node:fs'),assert=require('node:assert/strict');
|
|
191
|
+
assert.equal(process.cwd(),${JSON.stringify(group.codeProject)});
|
|
192
|
+
assert.match(fs.readFileSync('source.mjs','utf8'),/value = 2/);
|
|
193
|
+
assert.throws(()=>fs.appendFileSync(${JSON.stringify(path.join(options.specsRoot,'1.feature/tasks.md'))},'forbidden'));
|
|
194
|
+
assert.throws(()=>fs.appendFileSync('AGENTS.md','forbidden'));`;
|
|
195
|
+
const run=createHostCheck({cwd:group.codeProject,specsRoot:options.specsRoot,timeoutMs:5000,
|
|
196
|
+
commands:[{id:`root-${index}`,command:[process.execPath,'-e',source]}]});
|
|
197
|
+
const results=await run({identity},{signal});assert(results.every(check=>check.outcome==='passed'),JSON.stringify(results));
|
|
198
|
+
observed.push(...results.map(check=>({...check,evidence:`cwd=${group.codeProject}; ${check.evidence}`})));
|
|
199
|
+
}
|
|
200
|
+
const pkg=createReviewPackage({root,baseline,checks:observed});assert.equal(pkg.changes.length,2);assert.equal(pkg.checks.length,2);
|
|
201
|
+
assert.equal(verifyReviewPackage({root,baseline,checks:observed,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
|
|
202
|
+
assert.equal(fs.readFileSync(path.join(options.specsRoot,'1.feature/tasks.md'),'utf8'),'- [ ] T-001: One task across both roots\n');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('integrated original multi-root conversation completes one task and resumes without redispatch',
|
|
206
|
+
{skip:process.platform!=='darwin'||Number(process.versions.node.split('.')[0])<24,timeout:45000},t=>{
|
|
207
|
+
const {root,codeProjects,options}=fixture(t),specsDir=options.specsRoot;
|
|
208
|
+
for(const name of ['requirements.md','design.md'])write(specsDir,`1.feature/${name}`,'# Approved synthetic two-root task\n');
|
|
209
|
+
write(specsDir,'.cm-specs-status',JSON.stringify({status:'approved',features:['1.feature']}));
|
|
210
|
+
write(root,'.cm-workflow.json',JSON.stringify({version:1,policies:{delivery:'diff'}}));
|
|
211
|
+
const selected=resolveCodeProjects(root,codeProjects),definition={version:1,specsDir,codeProject:root,
|
|
212
|
+
codeProjects:selected,feature:'1.feature',identity,scope:options.scope,requirements:options.requirements};
|
|
213
|
+
const commands=selected.map((codeProject,index)=>({id:`root-${index}`,codeProject,
|
|
214
|
+
command:[process.execPath,'-e',`const a=require('node:assert/strict');a.equal(process.cwd(),${JSON.stringify(codeProject)});import('./source.mjs').then(m=>a.equal(m.value,2));`]}));
|
|
215
|
+
const protection={checkCommands:commands,timeoutMs:10000},workflow={documentationPaths:[],applicableAgentFiles:[],
|
|
216
|
+
qa:{commands:commands.map(command=>({...command,caseIds:[]})),
|
|
217
|
+
environment:{kind:'web',carrier:'browser',target:'http://127.0.0.1',scope:'local'}}};
|
|
218
|
+
const configFile=path.join(specsDir,'integration.json'),bin=path.join(specsDir,'bin');
|
|
219
|
+
write(specsDir,'integration.json',JSON.stringify({definition,protection,workflow}));fs.mkdirSync(bin);
|
|
220
|
+
const fake=path.join(bin,'claude');
|
|
221
|
+
fs.copyFileSync(new URL('./fixtures/claude-review-process.mjs',import.meta.url),fake);fs.chmodSync(fake,0o700);
|
|
222
|
+
// Shadow only the synthetic reviewer process. Codex sandbox stays the actual installed binary.
|
|
223
|
+
const env={...process.env,PATH:bin+path.delimiter+process.env.PATH};delete env.ANTHROPIC_API_KEY;
|
|
224
|
+
const source=`import fs from 'node:fs';import path from 'node:path';import assert from 'node:assert/strict';
|
|
225
|
+
import {openControlRun,validateRunDefinition} from ${JSON.stringify(new URL('./cm-ai-run.mjs',import.meta.url).href)};
|
|
226
|
+
import {createConversationExecution} from ${JSON.stringify(new URL('./cm-ai-host.mjs',import.meta.url).href)};
|
|
227
|
+
import {claudeReviewFingerprint} from ${JSON.stringify(new URL('../runtime/js/cm-ai/worker-claude.mjs',import.meta.url).href)};
|
|
228
|
+
const {definition:raw,protection,workflow}=JSON.parse(fs.readFileSync(process.argv[1]));
|
|
229
|
+
const definition=validateRunDefinition(raw),mode=process.argv[2],calls=[];
|
|
230
|
+
const bridge={async call(kind,payload){calls.push(kind);
|
|
231
|
+
if(kind==='develop'){
|
|
232
|
+
assert.equal(mode,'create');assert.deepEqual(payload.request.identity,definition.identity);
|
|
233
|
+
assert.equal(payload.codeProject,definition.codeProject);assert.deepEqual(payload.codeProjects,definition.codeProjects);
|
|
234
|
+
assert.deepEqual(payload.request.payload.scope,definition.scope);assert.equal(payload.editMode,'protected-text-v1');
|
|
235
|
+
assert.deepEqual(payload.projectInstructions.map(row=>row.codeProject),definition.codeProjects);
|
|
236
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
237
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},edits:definition.scope.map(file=>({
|
|
238
|
+
path:file,beforeSha256:payload.expected[file],content:'export const value = 2;\\n'}))};
|
|
239
|
+
}
|
|
240
|
+
if(kind==='qa_assess')return {scores:{scope:1,risk:1,accumulation:1,boundary:1},
|
|
241
|
+
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}};
|
|
242
|
+
assert.equal(kind,'documentation_inspect');
|
|
243
|
+
for(const file of definition.scope)assert.equal(fs.readFileSync(path.join(definition.codeProject,file),'utf8'),'export const value = 2;\\n');
|
|
244
|
+
const {syncId,identity,packageDigest,contextDigest}=payload;
|
|
245
|
+
return {syncId,identity,packageDigest,contextDigest,status:'completed',reason:'Actual fixture roots read back',
|
|
246
|
+
at:new Date().toISOString().replace(/\\.\\d{3}Z$/,'Z')};
|
|
247
|
+
}};
|
|
248
|
+
const review={model:'fixture',disabledSkills:[],preflight:{passed:true,provider:'claude',cli_model:'fixture',prompt_transport:'stdin',
|
|
249
|
+
config_fingerprint:claudeReviewFingerprint({cwd:definition.codeProject,model:'fixture'})}};
|
|
250
|
+
const execution=createConversationExecution(definition,'multi-root-host',bridge,review,mode==='create'?null:1,
|
|
251
|
+
workflow,true,'claude',{protection});
|
|
252
|
+
const run=await openControlRun(definition,mode,execution);
|
|
253
|
+
assert(run.host,JSON.stringify(run));
|
|
254
|
+
try{const result=await run.host.handle({version:1,operation:'advance',requestId:'advance',identity:definition.identity});
|
|
255
|
+
process.stdout.write(JSON.stringify({result,calls,checkpoint:run.checkpoint()}));}finally{run.close();}`;
|
|
256
|
+
const invoke=mode=>JSON.parse(execFileSync(process.execPath,['--input-type=module','-e',source,configFile,mode],
|
|
257
|
+
{env,encoding:'utf8',timeout:18000,maxBuffer:2*1024*1024}));
|
|
258
|
+
const first=invoke('create');assert.equal(first.result.state,'awaiting_review',JSON.stringify(first));
|
|
259
|
+
assert.deepEqual(first.calls,['develop']);
|
|
260
|
+
const stateFile=path.join(specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
261
|
+
const state=()=>JSON.parse(fs.readFileSync(stateFile));
|
|
262
|
+
const packages=value=>{
|
|
263
|
+
if(!value||typeof value!=='object')return [];
|
|
264
|
+
if(value.kind==='cm-review-package')return [value];
|
|
265
|
+
return Object.values(value).flatMap(packages);
|
|
266
|
+
};
|
|
267
|
+
const initialPackages=packages(state());assert(initialPackages.length>0);
|
|
268
|
+
const pkg=initialPackages.at(-1);
|
|
269
|
+
assert.deepEqual(pkg.identity,identity);assert.deepEqual(pkg.codeProjectPaths,['apps/api','apps/web']);
|
|
270
|
+
assert.deepEqual(pkg.changes.map(row=>row.path),options.scope);assert.equal(pkg.checks.length,2);
|
|
271
|
+
for(const [index,codeProject] of selected.entries())assert(pkg.checks[index].evidence.includes(`cwd=${codeProject};`));
|
|
272
|
+
assert.deepEqual(pkg.instructions.map(row=>row.path),['AGENTS.md','apps/AGENTS.md','apps/api/AGENTS.md','apps/web/AGENTS.md']);
|
|
273
|
+
assert.match(fs.readFileSync(path.join(specsDir,'1.feature/tasks.md'),'utf8'),/\[ \]/);
|
|
274
|
+
const completed=invoke('resume');assert.equal(completed.result.code,'run_done',JSON.stringify(completed));
|
|
275
|
+
assert.deepEqual(completed.calls,['qa_assess','documentation_inspect']);
|
|
276
|
+
const reopened=invoke('resume');assert.equal(reopened.result.code,'run_done',JSON.stringify(reopened));
|
|
277
|
+
assert.deepEqual(reopened.calls,['documentation_inspect']);
|
|
278
|
+
assert.equal(new Set(packages(state()).map(value=>value.packageDigest)).size,1);
|
|
279
|
+
assert.equal(packages(state()).at(-1).packageDigest,pkg.packageDigest);
|
|
280
|
+
assert.equal(state().records.filter(row=>row.payload.type==='review-invocation-registered').length,1);
|
|
281
|
+
const tasks=fs.readFileSync(path.join(specsDir,'1.feature/tasks.md'),'utf8');
|
|
282
|
+
assert.equal((tasks.match(/\[x\]/g)??[]).length,1);assert.equal((tasks.match(/T-001/g)??[]).length,1);
|
|
283
|
+
const handoff=JSON.parse(fs.readFileSync(path.join(specsDir,'.reviews','feature-T-001-a1-handoff.json')));
|
|
284
|
+
assert.deepEqual(handoff.changed_files,options.scope);
|
|
285
|
+
const logs=fs.readFileSync(path.join(specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
286
|
+
assert.equal(logs.filter(row=>row.event==='run_done').length,1);
|
|
287
|
+
assert.equal(logs.filter(row=>row.event==='test_run'&&row.phase==='start').length,1);
|
|
288
|
+
assert.equal(logs.find(row=>row.event==='test_run'&&row.phase==='complete').result,'PASS');
|
|
289
|
+
});
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawn,spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {createCodexExecution,openControlRun} from './cm-ai-run.mjs';
|
|
9
|
+
import {createConversationExecution,conversationProtection} from './cm-ai-host.mjs';
|
|
10
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
11
|
+
|
|
12
|
+
const supported=process.platform==='darwin'&&Number(process.versions.node.split('.')[0])>=24;
|
|
13
|
+
const identity={repositoryId:'fixture',runId:'nested-run',taskId:'T-001',attempt:1};
|
|
14
|
+
const request=operation=>({version:1,operation,requestId:operation,identity});
|
|
15
|
+
|
|
16
|
+
function workflowCli(args,codeProject,documentationStatus='completed'){
|
|
17
|
+
return new Promise((resolve,reject)=>{
|
|
18
|
+
const child=spawn(process.execPath,[fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url)),...args]);
|
|
19
|
+
let buffer='',stderr='',result;const calls=[];
|
|
20
|
+
const timer=setTimeout(()=>{child.kill('SIGTERM');reject(new Error('workflow timeout'));},15000);
|
|
21
|
+
const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
22
|
+
child.stderr.on('data',chunk=>stderr+=chunk);child.once('error',reject);
|
|
23
|
+
child.stdout.on('data',chunk=>{
|
|
24
|
+
buffer+=chunk;let end;
|
|
25
|
+
while((end=buffer.indexOf('\n'))!==-1){
|
|
26
|
+
const line=buffer.slice(0,end);buffer=buffer.slice(end+1);if(!line)continue;
|
|
27
|
+
try{
|
|
28
|
+
const row=JSON.parse(line);
|
|
29
|
+
if(row.type==='host_request'){
|
|
30
|
+
calls.push(row.kind);let value;
|
|
31
|
+
if(row.kind==='qa_assess')value={scores:{scope:1,risk:1,accumulation:1,boundary:1},
|
|
32
|
+
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}};
|
|
33
|
+
else{
|
|
34
|
+
assert.equal(row.kind,'documentation_inspect','no unprotected write/check request');
|
|
35
|
+
assert.equal(fs.readFileSync(path.join(codeProject,'README.md'),'utf8'),'# Updated\n');
|
|
36
|
+
const {syncId,identity,packageDigest,contextDigest}=row.payload;
|
|
37
|
+
value={syncId,identity,packageDigest,contextDigest,status:documentationStatus,reason:'Fixture document read back',
|
|
38
|
+
at:new Date().toISOString().replace(/\.\d{3}Z$/,'Z')};
|
|
39
|
+
}
|
|
40
|
+
send({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result:value});
|
|
41
|
+
}
|
|
42
|
+
if(row.requestId==='advance'&&row.result){result=row.result;child.stdin.end();}
|
|
43
|
+
}catch(error){clearTimeout(timer);child.kill('SIGTERM');reject(error);}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
child.once('close',code=>{clearTimeout(timer);if(code!==0)reject(new Error(stderr));else resolve({result,calls});});
|
|
47
|
+
send(request('advance'));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function fixture(fn){
|
|
52
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-nested-factory-')));
|
|
53
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(codeProject,'specs'),feature='1.demo';
|
|
54
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
55
|
+
fs.writeFileSync(path.join(codeProject,'a.js'),'old\n');
|
|
56
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'Synthetic requirement\n');
|
|
57
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'# Requirements\n');
|
|
58
|
+
fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Design\n');
|
|
59
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: implement\n');
|
|
60
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature]}));
|
|
61
|
+
const definition={version:1,codeProject,specsDir,feature,identity,scope:['a.js'],requirements:['requirements.md']};
|
|
62
|
+
const config={codeProject,specsRoot:specsDir,developerModel:'synthetic',reviewerModel:'synthetic',hostContextId:'host',
|
|
63
|
+
developerContextId:'author',timeoutMs:5000,
|
|
64
|
+
checkCommands:[{id:'value',command:[process.execPath,'-e',
|
|
65
|
+
"require('node:assert/strict').equal(require('node:fs').readFileSync('a.js','utf8'),'new\\n')"]}],
|
|
66
|
+
reviewerPreflight:{passed:true,cli_model:'synthetic',prompt_transport:'stdin',
|
|
67
|
+
config_fingerprint:configFingerprint({cwd:codeProject,model:'synthetic'})}};
|
|
68
|
+
const authority={authorizeDevelopment:()=>({status:'approved'}),
|
|
69
|
+
authorizeReview:()=>assert.fail('No real review authorization'),hostDecision:{status:'denied',code:'permission_denied'}};
|
|
70
|
+
try{await fn({root,definition,config,authority});}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for(const runtime of ['codex','claude'])test(`protected ${runtime} conversation retains host identity, scope protection and no redispatch on resume`,
|
|
74
|
+
{skip:!supported},()=>fixture(async({definition,config})=>{
|
|
75
|
+
let calls=0;
|
|
76
|
+
const bridge={async call(kind,payload){
|
|
77
|
+
assert.equal(kind,'develop');assert.equal(payload.request.provider,runtime);calls++;
|
|
78
|
+
assert.equal(payload.editMode,'protected-text-v1');
|
|
79
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
80
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},
|
|
81
|
+
edits:[{path:'a.js',beforeSha256:payload.expected['a.js'],content:'new\n'}]};
|
|
82
|
+
}};
|
|
83
|
+
const options={protection:{checkCommands:config.checkCommands,timeoutMs:config.timeoutMs}};
|
|
84
|
+
const make=()=>createConversationExecution(definition,'host',bridge,null,null,null,false,runtime,options);
|
|
85
|
+
const execution=make();assert(Object.isFrozen(execution));
|
|
86
|
+
const provenance=conversationProtection(execution);assert(Object.isFrozen(provenance));
|
|
87
|
+
assert.throws(()=>{provenance.definitionDigest='0'.repeat(64);},TypeError);
|
|
88
|
+
assert.equal(conversationProtection(execution),provenance);
|
|
89
|
+
await assert.rejects(openControlRun(definition,'create',{...execution}),{code:'nested_specs_protection_required'});
|
|
90
|
+
const wrong={...definition,scope:['b.js']};
|
|
91
|
+
await assert.rejects(openControlRun(wrong,'create',execution),{code:'execution_definition_mismatch'});
|
|
92
|
+
let run=await openControlRun(definition,'create',execution);
|
|
93
|
+
try{const result=await run.host.handle(request('advance'));assert.equal(result.code,'decision_required',JSON.stringify(result));}
|
|
94
|
+
finally{run.close();}
|
|
95
|
+
assert.equal(fs.readFileSync(path.join(definition.codeProject,'a.js'),'utf8'),'new\n');
|
|
96
|
+
assert.equal(calls,1);
|
|
97
|
+
run=await openControlRun(definition,'resume',make());
|
|
98
|
+
try{const result=await run.host.handle(request('advance'));assert.equal(result.code,'decision_required');assert.equal(calls,1);}
|
|
99
|
+
finally{run.close();}
|
|
100
|
+
assert.match(fs.readFileSync(path.join(definition.specsDir,definition.feature,'tasks.md'),'utf8'),/\[ \]/);
|
|
101
|
+
}));
|
|
102
|
+
|
|
103
|
+
test('protected factory binds exact roots and rejects copied/mutable claims before creating a store',
|
|
104
|
+
{skip:!supported},()=>fixture(async({root,definition,config,authority})=>{
|
|
105
|
+
const execution=await createCodexExecution(config,authority);
|
|
106
|
+
assert(Object.isFrozen(execution));assert(Object.isFrozen(execution.developer));
|
|
107
|
+
assert.throws(()=>{execution.check=()=>[];},TypeError);
|
|
108
|
+
assert.throws(()=>{execution.developer.run=()=>{};},TypeError);
|
|
109
|
+
assert.throws(()=>{execution.qaExecutor={run:()=>{}};},TypeError);
|
|
110
|
+
await assert.rejects(openControlRun(definition,'create',{...execution}),{code:'nested_specs_protection_required'});
|
|
111
|
+
const other=path.join(root,'other-specs');fs.mkdirSync(other);
|
|
112
|
+
await assert.rejects(openControlRun({...definition,specsDir:other},'create',execution),{code:'execution_specs_mismatch'});
|
|
113
|
+
const {specsRoot,...legacy}=config;
|
|
114
|
+
const unprotected=await createCodexExecution(legacy,authority);
|
|
115
|
+
await assert.rejects(openControlRun(definition,'create',unprotected),{code:'nested_specs_protection_required'});
|
|
116
|
+
const workflow=await createCodexExecution({...config,workflow:{definition,
|
|
117
|
+
configuration:{qa:null,documentationPaths:[],applicableAgentFiles:[]}}},
|
|
118
|
+
{...authority,workflow:{bridge:{call:()=>assert.fail('Construction never requests tools')},allowQa:false}});
|
|
119
|
+
assert(Object.isFrozen(workflow.documentationProvider));
|
|
120
|
+
await assert.rejects(openControlRun({...definition,scope:['different.js']},'create',workflow),{code:'execution_definition_mismatch'});
|
|
121
|
+
assert(!fs.existsSync(path.join(specsRoot,'.reviews')));
|
|
122
|
+
fs.renameSync(specsRoot,specsRoot+'-original');fs.symlinkSync(specsRoot+'-original',specsRoot);
|
|
123
|
+
await assert.rejects(openControlRun(definition,'create',execution),{code:'unsupported_path'});
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
for(const launch of ['factory','host','revision','workflow'])test(`${launch}: synthetic coding CLI receives native protection; real sandbox checks feed original runner and recovery`,
|
|
127
|
+
{skip:!supported},()=>fixture(async({root,definition,config,authority})=>{
|
|
128
|
+
if(launch==='workflow'){
|
|
129
|
+
definition.scope.push('README.md');fs.writeFileSync(path.join(definition.codeProject,'README.md'),'# Old\n');
|
|
130
|
+
fs.writeFileSync(path.join(definition.codeProject,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'}}));
|
|
131
|
+
}
|
|
132
|
+
// Never execute real `codex exec`: the shim emits synthetic provider events.
|
|
133
|
+
// It forwards only sandbox commands to the installed native sandbox.
|
|
134
|
+
const located=spawnSync('/usr/bin/which',['codex'],{encoding:'utf8'});
|
|
135
|
+
assert.equal(located.status,0);const realCodex=located.stdout.trim();assert(path.isAbsolute(realCodex));
|
|
136
|
+
const bin=path.join(root,'bin'),calls=path.join(root,'calls');fs.mkdirSync(bin);
|
|
137
|
+
const code="const fs=require('node:fs'),a=require('node:assert/strict');"
|
|
138
|
+
+"const denied=fn=>a.throws(fn,e=>['EPERM','EACCES'].includes(e.code));"
|
|
139
|
+
+"a.match(fs.readFileSync('specs/1.demo/tasks.md','utf8'),/\\[ \\]/);"
|
|
140
|
+
+"denied(()=>fs.writeFileSync('specs/1.demo/tasks.md','forged'));"
|
|
141
|
+
+"denied(()=>fs.writeFileSync('specs/.reviews/forged','bad'));"
|
|
142
|
+
+"denied(()=>fs.renameSync('specs','moved-specs'));"
|
|
143
|
+
+"denied(()=>fs.writeFileSync('AGENTS.md','bad'));"
|
|
144
|
+
+"const child=require('node:child_process').spawnSync(process.execPath,['-e',"
|
|
145
|
+
+"\"require('node:fs').writeFileSync('specs/1.demo/tasks.md','bad')\"]);a.notEqual(child.status,0);"
|
|
146
|
+
+(launch==='revision'?"fs.writeFileSync('a.js',fs.readFileSync('a.js','utf8')==='old\\n'?'new\\n':'new\\n// reviewed fix\\n');"
|
|
147
|
+
:"fs.writeFileSync('a.js','new\\n');")
|
|
148
|
+
+(launch==='workflow'?"fs.writeFileSync('README.md','# Updated\\n');":"");
|
|
149
|
+
fs.writeFileSync(path.join(bin,'codex'),String.raw`#!${process.execPath}
|
|
150
|
+
const fs=require('node:fs'),cp=require('node:child_process'),a=require('node:assert/strict');
|
|
151
|
+
const args=process.argv.slice(2),real=${JSON.stringify(realCodex)};
|
|
152
|
+
if(args[0]==='sandbox'){
|
|
153
|
+
const result=cp.spawnSync(real,args,{stdio:'inherit'});process.exit(result.status??1);
|
|
154
|
+
}
|
|
155
|
+
a.equal(args[0],'exec');a.equal(args.at(-1),'-');
|
|
156
|
+
const review=args.includes('--sandbox');
|
|
157
|
+
if(review)a.equal(args[args.indexOf('--sandbox')+1],'read-only');
|
|
158
|
+
const profile=[];
|
|
159
|
+
for(let i=0;i<args.length;i++)if(args[i]==='-c'&&(/^(default_permissions=|permissions.cm-specs=)/).test(args[i+1]))profile.push(args[i],args[i+1]);
|
|
160
|
+
if(!review){a.equal(profile.length,4);a(profile.join(' ').includes(${JSON.stringify(config.specsRoot)}));}
|
|
161
|
+
let input='';process.stdin.on('data',chunk=>input+=chunk);process.stdin.on('end',()=>{
|
|
162
|
+
const emit=value=>process.stdout.write(JSON.stringify(value)+'\n');
|
|
163
|
+
if(review){
|
|
164
|
+
const data=JSON.parse(input.split('<cm-review-data-json>\n')[1]);
|
|
165
|
+
if(${launch==='workflow'}){a(data.examinedPaths.includes('README.md'));a.equal(fs.readFileSync('README.md','utf8'),'# Updated\n');}
|
|
166
|
+
const changes=${launch==='revision'}&&data.reviewPackage.identity.attempt===1;
|
|
167
|
+
fs.appendFileSync(${JSON.stringify(calls)},'review\n');
|
|
168
|
+
emit({type:'thread.started',thread_id:'synthetic-independent-review-'+data.reviewPackage.identity.attempt});emit({type:'turn.started'});
|
|
169
|
+
emit({type:'item.completed',item:{type:'agent_message',text:JSON.stringify({verdict:changes?'changes_requested':'approved',
|
|
170
|
+
packageDigest:data.reviewPackage.packageDigest,examinedPaths:data.examinedPaths,
|
|
171
|
+
findings:changes?[{id:'F1',severity:'P2',path:'a.js',message:'Add reviewed comment',evidence:'Synthetic first-round finding'}]:[],summary:'Synthetic review only'})}});
|
|
172
|
+
emit({type:'turn.completed'});return;
|
|
173
|
+
}
|
|
174
|
+
a(input.includes('<cm-developer-data-json>'));fs.appendFileSync(${JSON.stringify(calls)},'developer\n');
|
|
175
|
+
if(${launch==='workflow'}){a(input.includes('synchronize these already-approved ordinary documentation paths'));a(input.includes('["README.md"]'));}
|
|
176
|
+
const run=cp.spawnSync(real,['sandbox','-P','cm-specs','--include-managed-config','-C',process.cwd(),...profile,'--',${JSON.stringify(process.execPath)},'-e',${JSON.stringify(code)}],{encoding:'utf8'});
|
|
177
|
+
if(run.status!==0){process.stderr.write(run.stderr??'');process.exit(1);}
|
|
178
|
+
emit({type:'thread.started',thread_id:'synthetic-protected-author'});emit({type:'turn.started'});
|
|
179
|
+
emit({type:'item.completed',item:{type:'agent_message',text:JSON.stringify({outcome:'implemented',
|
|
180
|
+
application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}})}});
|
|
181
|
+
emit({type:'turn.completed'});
|
|
182
|
+
});
|
|
183
|
+
`,{mode:0o700});
|
|
184
|
+
const previousPath=process.env.PATH;let run;
|
|
185
|
+
process.env.PATH=bin+path.delimiter+previousPath;
|
|
186
|
+
try{
|
|
187
|
+
if(launch!=='factory'){
|
|
188
|
+
const runFile=path.join(root,'run.json'),protectedFile=path.join(root,'protected.json'),reviewFile=path.join(root,'review.json');
|
|
189
|
+
fs.writeFileSync(runFile,JSON.stringify(definition));
|
|
190
|
+
const checkCommands=launch==='revision'?[{id:'value',command:[process.execPath,'-e',
|
|
191
|
+
"require('node:assert/strict')(require('node:fs').readFileSync('a.js','utf8').startsWith('new\\n'))"]}]:config.checkCommands;
|
|
192
|
+
fs.writeFileSync(protectedFile,JSON.stringify({model:config.developerModel,checkCommands,timeoutMs:config.timeoutMs}));
|
|
193
|
+
const disabledSkills=[path.join(root,'disabled-skill')];
|
|
194
|
+
fs.writeFileSync(reviewFile,JSON.stringify({model:config.reviewerModel,disabledSkills,
|
|
195
|
+
preflight:{...config.reviewerPreflight,config_fingerprint:configFingerprint({cwd:config.codeProject,model:config.reviewerModel,disabledSkills})}}));
|
|
196
|
+
if(launch==='workflow'){
|
|
197
|
+
const workflowFile=path.join(root,'workflow.json');
|
|
198
|
+
const qaCommand="const fs=require('node:fs'),a=require('node:assert/strict');"
|
|
199
|
+
+"a.equal(fs.readFileSync('README.md','utf8'),'# Updated\\n');"
|
|
200
|
+
+"a.match(fs.readFileSync('specs/1.demo/tasks.md','utf8'),/\\[x\\]/);"
|
|
201
|
+
+"a.throws(()=>fs.writeFileSync('specs/1.demo/tasks.md','forged'),e=>['EPERM','EACCES'].includes(e.code));"
|
|
202
|
+
+"a.throws(()=>fs.writeFileSync('AGENTS.md','forged'),e=>['EPERM','EACCES'].includes(e.code));";
|
|
203
|
+
const workflow={qa:{commands:[{id:'protected-qa',command:[process.execPath,'-e',qaCommand],caseIds:[]}],
|
|
204
|
+
environment:{kind:'web',carrier:'browser',target:'http://127.0.0.1:3000',scope:'local'}},
|
|
205
|
+
documentationPaths:['README.md'],applicableAgentFiles:[]};
|
|
206
|
+
fs.writeFileSync(workflowFile,JSON.stringify(workflow));
|
|
207
|
+
const args=['serve','--config',runFile,'--mode','create','--host-context','host','--allow-development',
|
|
208
|
+
'--protected-config',protectedFile,'--allow-provider-development-attempt','1','--review-config',reviewFile,
|
|
209
|
+
'--allow-review-attempt','1','--workflow-config',workflowFile,'--allow-qa'];
|
|
210
|
+
const denied=spawnSync(process.execPath,[fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url)),...args.slice(0,-1)],{encoding:'utf8',timeout:5000});
|
|
211
|
+
assert.equal(denied.status,1);assert(denied.stderr.includes('qa_authorization_required'));
|
|
212
|
+
assert(!fs.existsSync(path.join(config.specsRoot,'.reviews')));
|
|
213
|
+
fs.writeFileSync(workflowFile,JSON.stringify({...workflow,documentationPaths:['requirements.md']}));
|
|
214
|
+
const invalid=spawnSync(process.execPath,[fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url)),...args],{encoding:'utf8',timeout:5000});
|
|
215
|
+
assert.equal(invalid.status,1);assert(invalid.stderr.includes('documentation_scope_required'));
|
|
216
|
+
assert(!fs.existsSync(path.join(config.specsRoot,'.reviews')));
|
|
217
|
+
fs.writeFileSync(workflowFile,JSON.stringify(workflow));
|
|
218
|
+
const blocked=await workflowCli(args,definition.codeProject,'blocked');
|
|
219
|
+
assert.equal(blocked.result.code,'documentation_sync_blocked');
|
|
220
|
+
assert.deepEqual(blocked.calls,['qa_assess','documentation_inspect']);
|
|
221
|
+
assert(!fs.readFileSync(path.join(config.specsRoot,'运行日志.jsonl'),'utf8').includes('"event":"run_done"'));
|
|
222
|
+
args[4]='resume';
|
|
223
|
+
const first=await workflowCli(args,definition.codeProject);
|
|
224
|
+
assert.equal(first.result.code,'run_done',JSON.stringify(first));
|
|
225
|
+
assert.deepEqual(first.calls,['documentation_inspect']);
|
|
226
|
+
const handoff=JSON.parse(fs.readFileSync(path.join(config.specsRoot,'.reviews','demo-T-001-a1-handoff.json')));
|
|
227
|
+
assert(handoff.changed_files.includes('README.md'));
|
|
228
|
+
args[4]='resume';const resumed=await workflowCli(args,definition.codeProject);
|
|
229
|
+
assert.equal(resumed.result.code,'run_done');assert.deepEqual(resumed.calls,['documentation_inspect']);
|
|
230
|
+
assert.equal(fs.readFileSync(calls,'utf8'),'developer\nreview\n');
|
|
231
|
+
const logs=fs.readFileSync(path.join(config.specsRoot,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
232
|
+
assert.equal(logs.filter(row=>row.event==='test_run'&&row.phase==='start').length,1);
|
|
233
|
+
assert.equal(logs.filter(row=>row.event==='run_done').length,1);
|
|
234
|
+
assert.equal(logs.find(row=>row.event==='test_run'&&row.phase==='complete').result,'PASS');
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const invoke=(mode,flags=[],attempt='1')=>{
|
|
238
|
+
const child=spawnSync(process.execPath,[fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url)),
|
|
239
|
+
'serve','--config',runFile,'--mode',mode,'--host-context','host','--allow-development',
|
|
240
|
+
'--protected-config',protectedFile,'--allow-provider-development-attempt',attempt,'--review-config',reviewFile,...flags],
|
|
241
|
+
{encoding:'utf8',input:JSON.stringify(request('advance'))+'\n',timeout:12000});
|
|
242
|
+
assert.equal(child.status,0,child.stderr);
|
|
243
|
+
const rows=child.stdout.trim().split('\n').map(JSON.parse);
|
|
244
|
+
assert(!rows.some(row=>row.type==='host_request'),'protected mode never asks current host to perform unprotected writes');
|
|
245
|
+
return rows.find(row=>row.requestId==='advance').result;
|
|
246
|
+
};
|
|
247
|
+
assert.equal(invoke('create').state,'awaiting_review');
|
|
248
|
+
assert.equal(fs.readFileSync(calls,'utf8'),'developer\n');
|
|
249
|
+
assert.equal(invoke('resume').state,'awaiting_review');
|
|
250
|
+
assert.equal(fs.readFileSync(calls,'utf8'),'developer\n');
|
|
251
|
+
let result=invoke('resume',['--allow-review-attempt','1']);
|
|
252
|
+
if(launch==='revision'){
|
|
253
|
+
assert.equal(result.state,'changes_requested');assert.equal(result.identity.attempt,2);
|
|
254
|
+
assert.equal(result.code,'provider_development_authorization_required');
|
|
255
|
+
assert.equal(fs.readFileSync(calls,'utf8'),'developer\nreview\n');
|
|
256
|
+
const journal=path.join(config.specsRoot,'.reviews','.execution',identity.runId,'state.json');
|
|
257
|
+
const before=fs.readFileSync(journal);assert(!before.includes('"id":"develop-2"'));
|
|
258
|
+
assert.equal(invoke('resume').code,'provider_development_authorization_required');
|
|
259
|
+
assert.deepEqual(fs.readFileSync(journal),before,'waiting for permission does not mutate the journal');
|
|
260
|
+
result=invoke('resume',[],'2');assert.equal(result.state,'awaiting_review');
|
|
261
|
+
assert.equal(fs.readFileSync(calls,'utf8'),'developer\nreview\ndeveloper\n');
|
|
262
|
+
result=invoke('resume',['--allow-review-attempt','2'],'2');
|
|
263
|
+
}
|
|
264
|
+
assert.equal(result.state,'fixture_completed',JSON.stringify(result));
|
|
265
|
+
assert.equal(result.code,'qa_decision_required');
|
|
266
|
+
const expectedCalls=launch==='revision'?'developer\nreview\ndeveloper\nreview\n':'developer\nreview\n';
|
|
267
|
+
assert.equal(fs.readFileSync(calls,'utf8'),expectedCalls);
|
|
268
|
+
assert(fs.readFileSync(path.join(config.specsRoot,definition.feature,'tasks.md'),'utf8').includes('[x]'));
|
|
269
|
+
assert.equal(invoke('resume').state,'fixture_completed');
|
|
270
|
+
assert.equal(fs.readFileSync(calls,'utf8'),expectedCalls);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const execution=await createCodexExecution(config,authority);
|
|
274
|
+
run=await openControlRun(definition,'create',execution);
|
|
275
|
+
const result=await run.host.handle(request('advance'));
|
|
276
|
+
assert.equal(result.state,'awaiting_review',JSON.stringify(result));assert.equal(result.outcome,'denied');
|
|
277
|
+
assert.equal(fs.readFileSync(calls,'utf8'),'developer\n');
|
|
278
|
+
assert.equal(fs.readFileSync(path.join(definition.codeProject,'a.js'),'utf8'),'new\n');
|
|
279
|
+
const task=path.join(definition.specsDir,definition.feature,'tasks.md');
|
|
280
|
+
assert.equal(fs.readFileSync(task,'utf8'),'- [ ] T-001: implement\n');
|
|
281
|
+
assert(!fs.existsSync(path.join(definition.specsDir,'.reviews','forged')));
|
|
282
|
+
const handoff=JSON.parse(fs.readFileSync(path.join(definition.specsDir,'.reviews','demo-T-001-a1-handoff.json'),'utf8'));
|
|
283
|
+
assert(handoff.verification.every(row=>row.status==='passed'));
|
|
284
|
+
assert(!handoff.changed_files.some(file=>file.startsWith('specs/')));
|
|
285
|
+
run.close();run=null;
|
|
286
|
+
run=await openControlRun(definition,'resume',await createCodexExecution(config,authority));
|
|
287
|
+
assert.equal((await run.host.handle(request('advance'))).state,'awaiting_review');
|
|
288
|
+
assert.equal(fs.readFileSync(calls,'utf8'),'developer\n');
|
|
289
|
+
assert.equal(fs.readFileSync(task,'utf8'),'- [ ] T-001: implement\n');
|
|
290
|
+
}finally{run?.close();process.env.PATH=previousPath;}
|
|
291
|
+
}));
|
|
292
|
+
|
|
293
|
+
test('ordinary protected entry rejects missing authority and unsupported combinations before state creation',
|
|
294
|
+
{skip:!supported},()=>fixture(async({root,definition,config})=>{
|
|
295
|
+
const runFile=path.join(root,'run.json'),protectedFile=path.join(root,'protected.json'),reviewFile=path.join(root,'review.json');
|
|
296
|
+
fs.writeFileSync(runFile,JSON.stringify(definition));
|
|
297
|
+
fs.writeFileSync(protectedFile,JSON.stringify({model:config.developerModel,checkCommands:config.checkCommands,timeoutMs:config.timeoutMs}));
|
|
298
|
+
fs.writeFileSync(reviewFile,JSON.stringify({model:config.reviewerModel,preflight:config.reviewerPreflight}));
|
|
299
|
+
const protectedArgs=['--protected-config',protectedFile],authorization=['--allow-provider-development-attempt','1'];
|
|
300
|
+
const unsafeFix=path.join(root,'unsafe-fix.json');fs.writeFileSync(unsafeFix,JSON.stringify({configuration:{}}));
|
|
301
|
+
for(const [flags,code] of [[protectedArgs,'provider_development_authorization_required'],
|
|
302
|
+
[authorization,'protected_configuration_required'],
|
|
303
|
+
[[...protectedArgs,...authorization,'--runtime','claude'],'protected_runtime_unsupported'],
|
|
304
|
+
[[...protectedArgs,'--allow-provider-development-attempt','2'],'invalid_development_attempt'],
|
|
305
|
+
[[...protectedArgs,...authorization,'--qa-fix-owner-config',unsafeFix],'protected_fix_required'],
|
|
306
|
+
[[], 'nested_specs_protection_required']]){
|
|
307
|
+
const child=spawnSync(process.execPath,[fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url)),
|
|
308
|
+
'serve','--config',runFile,'--mode','create','--host-context','host','--allow-development','--review-config',reviewFile,...flags],
|
|
309
|
+
{encoding:'utf8',input:'',timeout:5000});
|
|
310
|
+
assert.equal(child.status,1);assert.equal(JSON.parse(child.stderr.trim().split('\n').at(-1)).error.code,code);
|
|
311
|
+
assert(!fs.existsSync(path.join(config.specsRoot,'.reviews')));
|
|
312
|
+
}
|
|
313
|
+
}));
|