@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,53 @@
|
|
|
1
|
+
// Conservative print/stream-json decoder. No dispatch, grant or completion authority.
|
|
2
|
+
// Process ownership must append process_closed and reject unsuccessful exits.
|
|
3
|
+
export function createClaudeReviewStream(onEvent) {
|
|
4
|
+
let session = null, stage = 'init', value;
|
|
5
|
+
const reject = code => { stage = 'failed'; throw Object.assign(new Error(code), {code}); };
|
|
6
|
+
return Object.freeze({
|
|
7
|
+
accept(message) {
|
|
8
|
+
if (!message || typeof message !== 'object' || Array.isArray(message)) reject('invalid_event');
|
|
9
|
+
if (stage === 'done' || stage === 'failed') reject('unexpected_event');
|
|
10
|
+
if (typeof message.session_id !== 'string' || !message.session_id.trim()
|
|
11
|
+
|| message.session_id.length > 256) reject('invalid_session');
|
|
12
|
+
if (session !== null && session !== message.session_id) reject('session_mismatch');
|
|
13
|
+
if (stage === 'init') {
|
|
14
|
+
if (message.type !== 'system' || message.subtype !== 'init') reject('missing_init');
|
|
15
|
+
session = message.session_id;
|
|
16
|
+
stage = 'assistant';
|
|
17
|
+
onEvent({event:'thread.started', provider_thread:session});
|
|
18
|
+
onEvent({event:'turn.started', item_type:null});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (message.type === 'assistant' && stage === 'assistant') {
|
|
22
|
+
if (message.parent_tool_use_id !== null || message.error != null
|
|
23
|
+
|| message.message?.role !== 'assistant') reject('unexpected_assistant');
|
|
24
|
+
const content = message.message.content;
|
|
25
|
+
if (!Array.isArray(content) || content.length === 0
|
|
26
|
+
|| content.some(block => block?.type !== 'text' || typeof block.text !== 'string')) {
|
|
27
|
+
reject('unexpected_tool_or_content');
|
|
28
|
+
}
|
|
29
|
+
// Result is authoritative for structured output; assistant prose is never a verdict.
|
|
30
|
+
stage = 'result';
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (message.type === 'result') {
|
|
34
|
+
if (message.subtype !== 'success' || message.is_error !== false) reject('provider_failed');
|
|
35
|
+
if (stage !== 'result' || message.num_turns !== 1) reject('unexpected_result');
|
|
36
|
+
if (message.structured_output !== undefined) value = message.structured_output;
|
|
37
|
+
else {
|
|
38
|
+
try { value = JSON.parse(message.result); } catch { reject('invalid_output_json'); }
|
|
39
|
+
}
|
|
40
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) reject('invalid_output_json');
|
|
41
|
+
stage = 'done';
|
|
42
|
+
onEvent({event:'item.completed', item_type:'agent_message'});
|
|
43
|
+
onEvent({event:'turn.completed', item_type:null});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
reject('unexpected_event');
|
|
47
|
+
},
|
|
48
|
+
finish() {
|
|
49
|
+
if (stage !== 'done') reject('incomplete_result');
|
|
50
|
+
return {status:'succeeded', value};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Synthetic request capture only. No forwarding, review package, grant or task mutation.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import http from 'node:http';
|
|
6
|
+
import {spawn} from 'node:child_process';
|
|
7
|
+
import {gunzipSync,zstdDecompressSync} from 'node:zlib';
|
|
8
|
+
import {claudeWorker,claudeReviewFingerprint} from './worker-claude.mjs';
|
|
9
|
+
|
|
10
|
+
export function claudeProbeSandbox(temp,port) {
|
|
11
|
+
if(!path.isAbsolute(temp)||!Number.isInteger(port)||port<1||port>65535)throw Error('invalid_probe');
|
|
12
|
+
return `(version 1)(allow default)(deny network*)
|
|
13
|
+
(allow network-outbound (remote ip "localhost:${port}"))
|
|
14
|
+
(deny file-write*)(allow file-write* (subpath ${JSON.stringify(temp)}) (literal "/dev/null"))`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function previewClaudeTools({cwd,model,cli='claude',spawnProcess=spawn}) {
|
|
18
|
+
if(process.platform!=='darwin'||!fs.existsSync('/usr/bin/sandbox-exec')) {
|
|
19
|
+
throw Object.assign(Error('unsupported_probe_isolation'),{code:'unsupported_probe_isolation'});
|
|
20
|
+
}
|
|
21
|
+
cwd=fs.realpathSync(cwd);
|
|
22
|
+
if(!fs.statSync(cwd).isDirectory())throw Error('invalid_code_project');
|
|
23
|
+
const fingerprint=claudeReviewFingerprint({cwd,model,cli});
|
|
24
|
+
const temp=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-claude-probe-')));
|
|
25
|
+
const observations=[];
|
|
26
|
+
const controller=new AbortController();let stoppedByProbe=false;
|
|
27
|
+
const server=http.createServer((request,response)=>{
|
|
28
|
+
const index=observations.length;
|
|
29
|
+
if(index<8)observations.push({valid:false});else observations[0]={valid:false};
|
|
30
|
+
let chunks=[],size=0;
|
|
31
|
+
request.on('error',()=>{});
|
|
32
|
+
request.on('data',chunk=>{
|
|
33
|
+
size+=chunk.length;
|
|
34
|
+
if(size>1_000_000){chunks=[];request.destroy();return;}
|
|
35
|
+
chunks.push(chunk);
|
|
36
|
+
});
|
|
37
|
+
request.on('end',()=>{
|
|
38
|
+
const encoding=request.headers['content-encoding']??'identity';
|
|
39
|
+
let endpoint;
|
|
40
|
+
try{endpoint=new URL(request.url,'http://127.0.0.1').pathname;}
|
|
41
|
+
catch{
|
|
42
|
+
response.writeHead(400,{'Content-Type':'application/json'});response.end('{}');return;
|
|
43
|
+
}
|
|
44
|
+
// Installed CLI probes this endpoint before sending its messages request.
|
|
45
|
+
// A single empty GET/HEAD may receive a fixed health response, never a model answer.
|
|
46
|
+
if(['GET','HEAD'].includes(request.method)&&endpoint==='/api/hello'&&size===0
|
|
47
|
+
&&!observations.some(item=>item.startup===true)){
|
|
48
|
+
if(index<8)observations[index]={valid:false,startup:true};
|
|
49
|
+
response.writeHead(200,{'Content-Type':'application/json'});response.end('{}');return;
|
|
50
|
+
}
|
|
51
|
+
let safe={valid:false,checks:{json:false,encoding_supported:['identity','gzip','zstd'].includes(encoding),
|
|
52
|
+
post:request.method==='POST',messages_endpoint:endpoint==='/v1/messages',
|
|
53
|
+
models_endpoint:endpoint==='/v1/models',hello_endpoint:endpoint==='/api/hello',root_endpoint:endpoint==='/',
|
|
54
|
+
body_present:size>0}};
|
|
55
|
+
try {
|
|
56
|
+
let body=Buffer.concat(chunks);
|
|
57
|
+
if(encoding==='gzip')body=gunzipSync(body,{maxOutputLength:1_000_000});
|
|
58
|
+
else if(encoding==='zstd')body=zstdDecompressSync(body,{maxOutputLength:1_000_000});
|
|
59
|
+
else if(encoding!=='identity')throw Error('unsupported_encoding');
|
|
60
|
+
const data=JSON.parse(body.toString('utf8'));
|
|
61
|
+
const tools=data.tools??[];
|
|
62
|
+
const checks={json:true,post:request.method==='POST',
|
|
63
|
+
messages_endpoint:new URL(request.url,'http://127.0.0.1').pathname==='/v1/messages',
|
|
64
|
+
model_matches:data.model===model,messages_array:Array.isArray(data.messages),
|
|
65
|
+
tools_empty:Array.isArray(tools)&&tools.length===0,
|
|
66
|
+
synthetic_auth:request.headers['x-api-key']==='cm-synthetic-local-probe'};
|
|
67
|
+
safe={valid:Object.values(checks).every(Boolean),checks};
|
|
68
|
+
}catch{}
|
|
69
|
+
// Never retain raw request bodies, auth headers, local context or diagnostics.
|
|
70
|
+
if(index<8)observations[index]=safe;
|
|
71
|
+
response.writeHead(400,{'Content-Type':'application/json'});
|
|
72
|
+
response.end(JSON.stringify({type:'error',error:{type:'invalid_request_error',message:'CM_LOCAL_PROBE_STOP'}}));
|
|
73
|
+
// Inspection is finished; do not let CLI-internal repair/retry issue another model request.
|
|
74
|
+
if(safe.valid){stoppedByProbe=true;controller.abort();}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
server.requestTimeout=5000;server.headersTimeout=5000;
|
|
78
|
+
let result,closeEvidence=null,closed=false;
|
|
79
|
+
try {
|
|
80
|
+
await new Promise((resolve,reject)=>{server.once('error',reject);server.listen(0,'127.0.0.1',resolve);});
|
|
81
|
+
const port=server.address().port;
|
|
82
|
+
const preflight={passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:fingerprint};
|
|
83
|
+
// Internal diagnostic bootstrap: same worker lifecycle, forced sink and synthetic prompt only.
|
|
84
|
+
// This object is never returned as a passing receipt without examining the captured request.
|
|
85
|
+
const worker=claudeWorker({cwd,model,cli,preflight,timeoutMs:15000,
|
|
86
|
+
spawnProcess:(command,args,options)=>spawnProcess('/usr/bin/sandbox-exec',
|
|
87
|
+
['-p',claudeProbeSandbox(temp,port),command,...args],{...options,env:{...options.env,
|
|
88
|
+
ANTHROPIC_API_KEY:'cm-synthetic-local-probe',ANTHROPIC_BASE_URL:`http://127.0.0.1:${port}`,
|
|
89
|
+
CLAUDE_CONFIG_DIR:temp,CLAUDE_CODE_TMPDIR:temp,
|
|
90
|
+
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC:'1',TMPDIR:temp}})});
|
|
91
|
+
result=await worker({prompt:'Return JSON for synthetic diagnostic task CM-PROBE-001.'},
|
|
92
|
+
{signal:controller.signal,onEvent:event=>{
|
|
93
|
+
if(event.event==='process_closed')closeEvidence=event;
|
|
94
|
+
}});
|
|
95
|
+
} finally {
|
|
96
|
+
server.closeAllConnections();
|
|
97
|
+
await new Promise(resolve=>server.close(()=>resolve()));closed=true;
|
|
98
|
+
fs.rmSync(temp,{recursive:true,force:true});
|
|
99
|
+
}
|
|
100
|
+
const messages=observations.filter(item=>item.startup!==true);
|
|
101
|
+
return {model,disabledSkills:[],preflight:{provider:'claude',prompt_transport:'stdin',
|
|
102
|
+
config_fingerprint:fingerprint,passed:messages.length===1&&messages[0].valid
|
|
103
|
+
&&stoppedByProbe&&result?.status==='cancelled'&&closeEvidence!==null&&!closeEvidence.timed_out,
|
|
104
|
+
local_requests:observations.length,message_requests:messages.length,listener_closed:closed,isolation:'macos-loopback-sandbox',
|
|
105
|
+
process_code:result?.code??'unknown',stopped_by_probe:stoppedByProbe,exit_code:closeEvidence?.exit_code??null,
|
|
106
|
+
request_checks:observations.map(item=>item.startup?{startup:true}:item.checks??{complete:false})}};
|
|
107
|
+
}
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
// Read-only N1/N2 admission for the fixed cm-ai workflow. It never writes project state.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const TASK=/^\s*-\s*\[([ xX])\]\s+(?:~~)?(T-[A-Za-z0-9][A-Za-z0-9._-]*)(?=[:\s])[:\s]*(.*)$/;
|
|
9
|
+
const DEPENDENCY=/^\s*-\s*(T-[A-Za-z0-9][A-Za-z0-9._-]*)\s+依赖\s+(.+)$/;
|
|
10
|
+
const TASK_ID=/^T-[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
11
|
+
const ACCEPTANCE=/^\s*[-*]\s+(?:\[[ xX]\]\s+)?(?:\[(AC-\d{3,})\]|(AC-\d{3,}))(?=[:\s])/;
|
|
12
|
+
const FEATURE=/^(\d+)\.(.+)$/;
|
|
13
|
+
const TEST_CASE_VALIDATOR=fileURLToPath(new URL('../../../scripts/validate-test-cases.mjs',import.meta.url));
|
|
14
|
+
|
|
15
|
+
// Greenfield's T-001 scaffolds; its subsequent instruction task (normally
|
|
16
|
+
// T-002) owns init-equivalent rules. Use the existing parser and approval gate.
|
|
17
|
+
export function inspectCmAiBootstrapTask({specsDir,codeProject,taskId},inProgress=false) {
|
|
18
|
+
const admission=admissionFor({specsDir,codeProject},inProgress?taskId:null);
|
|
19
|
+
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
20
|
+
if(!['ready','complete'].includes(admission.state))fail(admission.reason);
|
|
21
|
+
const parsed=readFeature(admission.specsDir,'0.bootstrap');if(parsed.error)fail(parsed.error);
|
|
22
|
+
const task=parsed.tasks.find(item=>item.id===taskId&&!item.dropped);
|
|
23
|
+
const mode=task?.id==='T-001'&&/(?:脚手架|骨架|scaffold)/i.test(task.description)?'scaffold':'instructions';
|
|
24
|
+
if(!task||mode==='instructions'&&(!/(?:cm-init|\.claude\/|AGENTS\.md)/i.test(task.description)
|
|
25
|
+
||!/(?:生成|规范|规则|instruction|rules|generate)/i.test(task.description)))fail('bootstrap_task_required');
|
|
26
|
+
return frozen({task,mode,admission});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Read N6 task counts with the original task parser, including later features.
|
|
30
|
+
export function inspectCmAiQaTaskContext({specsDir,codeProject,feature,taskId}) {
|
|
31
|
+
const admission=inspectCmAiAdmission({specsDir,codeProject});
|
|
32
|
+
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
33
|
+
if(!['ready','complete'].includes(admission.state))fail(admission.reason);
|
|
34
|
+
const discovered=discoverFeatures(admission.specsDir);if(discovered.error)fail(discovered.error);
|
|
35
|
+
const completed=[];let selected=null;
|
|
36
|
+
for(const name of discovered.names){
|
|
37
|
+
const parsed=readFeature(admission.specsDir,name);if(parsed.error)fail(parsed.error);
|
|
38
|
+
if(name===feature)selected=parsed.tasks;
|
|
39
|
+
for(const task of parsed.tasks)if(task.completed&&!task.dropped)completed.push({feature:name,id:task.id});
|
|
40
|
+
}
|
|
41
|
+
if(!selected?.some(task=>task.id===taskId&&task.completed&&!task.dropped))fail('qa_not_ready');
|
|
42
|
+
const pending=selected.filter(task=>!task.completed&&!task.dropped).length;
|
|
43
|
+
return frozen({completed,pending,mergeEligible:pending===1&&admission.nextTask?.feature===feature});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Admission's public feature summary stops at the selected feature. Count all
|
|
47
|
+
// approved features with the same parser before treating a task as the last one.
|
|
48
|
+
export function isFinalCmAiTask({specsDir,codeProject,feature,taskId}) {
|
|
49
|
+
const admission=inspectCmAiAdmission({specsDir,codeProject});
|
|
50
|
+
if(admission.state!=='ready'||admission.nextTask.feature!==feature||admission.nextTask.id!==taskId)
|
|
51
|
+
throw Object.assign(new Error('documentation_admission_required'),{code:'documentation_admission_required'});
|
|
52
|
+
const discovered=discoverFeatures(admission.specsDir);
|
|
53
|
+
if(discovered.error)throw Object.assign(new Error(discovered.error),{code:discovered.error});
|
|
54
|
+
let pending=0;
|
|
55
|
+
for(const name of discovered.names){
|
|
56
|
+
const parsed=readFeature(admission.specsDir,name);
|
|
57
|
+
if(parsed.error)throw Object.assign(new Error(parsed.error),{code:parsed.error});
|
|
58
|
+
pending+=parsed.tasks.filter(task=>!task.completed&&!task.dropped).length;
|
|
59
|
+
}
|
|
60
|
+
return pending===1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function frozen(value){
|
|
64
|
+
if(value && typeof value==='object'){for(const item of Object.values(value))frozen(item);Object.freeze(value);}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function result(base,state,reason,extra={}){
|
|
69
|
+
return frozen({...base,state,reason,features:[],nextTask:null,warnings:[],...extra});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function directory(value){
|
|
73
|
+
if(typeof value!=='string'||!value.trim())return null;
|
|
74
|
+
const resolved=path.resolve(value);
|
|
75
|
+
try{return fs.statSync(resolved).isDirectory()?resolved:null;}catch{return null;}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function approvalIntent(response,assumeYes){
|
|
79
|
+
if(assumeYes===true)return 'explicit';
|
|
80
|
+
if(response===undefined||response===null||response==='')return 'none';
|
|
81
|
+
return typeof response==='string'&&response.trim()==='开始'?'explicit':'not_approval';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function readStatus(specsDir){
|
|
85
|
+
const target=path.join(specsDir,'.cm-specs-status');
|
|
86
|
+
if(!fs.existsSync(target))return {kind:'missing'};
|
|
87
|
+
try{
|
|
88
|
+
const specsRoot=fs.realpathSync(specsDir),realTarget=fs.realpathSync(target);
|
|
89
|
+
if(!contained(specsRoot,realTarget))return {kind:'invalid'};
|
|
90
|
+
const value=JSON.parse(fs.readFileSync(realTarget,'utf8'));
|
|
91
|
+
if(value===null||typeof value!=='object'||Array.isArray(value)||!['approved','awaiting_review'].includes(value.status))
|
|
92
|
+
return {kind:'invalid'};
|
|
93
|
+
return {kind:'valid',value};
|
|
94
|
+
}catch{return {kind:'invalid'};}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function contained(root,target){
|
|
98
|
+
const relative=path.relative(root,target);
|
|
99
|
+
return relative===''||(!relative.startsWith(`..${path.sep}`)&&relative!=='..'&&!path.isAbsolute(relative));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function discoverFeatures(specsDir){
|
|
103
|
+
const specsRoot=fs.realpathSync(specsDir);
|
|
104
|
+
const names=fs.readdirSync(specsDir,{withFileTypes:true})
|
|
105
|
+
.filter(entry=>entry.isDirectory()&&FEATURE.test(entry.name))
|
|
106
|
+
.map(entry=>entry.name)
|
|
107
|
+
.sort((a,b)=>{
|
|
108
|
+
if(a==='0.bootstrap')return b==='0.bootstrap'?0:-1;
|
|
109
|
+
if(b==='0.bootstrap')return 1;
|
|
110
|
+
const an=Number(a.match(FEATURE)[1]),bn=Number(b.match(FEATURE)[1]);
|
|
111
|
+
return an-bn||(a<b?-1:a>b?1:0);
|
|
112
|
+
});
|
|
113
|
+
if(!names.length)return {error:'features_missing'};
|
|
114
|
+
const reviewKeys=names.flatMap(name=>[name,name.replace(/^\d+\./,'')]);
|
|
115
|
+
if(new Set(reviewKeys).size!==reviewKeys.length)return {error:'feature_contract_invalid'};
|
|
116
|
+
for(const name of names){
|
|
117
|
+
const root=path.join(specsDir,name);
|
|
118
|
+
let featureRoot;
|
|
119
|
+
try{featureRoot=fs.realpathSync(root);}catch{return {error:'feature_contract_missing'};}
|
|
120
|
+
if(!contained(specsRoot,featureRoot))return {error:'feature_contract_invalid'};
|
|
121
|
+
for(const file of ['requirements.md','design.md','tasks.md']){
|
|
122
|
+
try{
|
|
123
|
+
const target=path.join(root,file);
|
|
124
|
+
if(!fs.statSync(target).isFile())return {error:'feature_contract_missing'};
|
|
125
|
+
if(!contained(featureRoot,fs.realpathSync(target)))return {error:'feature_contract_invalid'};
|
|
126
|
+
}
|
|
127
|
+
catch{return {error:'feature_contract_missing'};}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return {names};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function approvedFeaturesProblem(status,names){
|
|
134
|
+
if(!Array.isArray(status.features)||status.features.some(name=>typeof name!=='string'||!FEATURE.test(name)))
|
|
135
|
+
return 'spec_status_invalid';
|
|
136
|
+
const approved=new Set(status.features);
|
|
137
|
+
if(approved.size!==status.features.length)return 'spec_status_invalid';
|
|
138
|
+
if(approved.size!==names.length||names.some(name=>!approved.has(name)))return 'spec_features_changed';
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function validJson(bytes){
|
|
143
|
+
try{JSON.parse(bytes.toString('utf8'));return true;}catch{return false;}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function validTestContract(target,featureName){
|
|
147
|
+
const checked=spawnSync(process.execPath,[TEST_CASE_VALIDATOR,target],{stdio:'ignore'});
|
|
148
|
+
if(checked.error||checked.status!==0)return false;
|
|
149
|
+
let data;
|
|
150
|
+
try{data=JSON.parse(fs.readFileSync(target,'utf8'));}catch{return false;}
|
|
151
|
+
if(data.feature!==featureName)return false;
|
|
152
|
+
const featureRoot=path.dirname(target);
|
|
153
|
+
let sources;
|
|
154
|
+
try{sources=['requirements.md','design.md','tasks.md'].map(file=>fs.readFileSync(path.join(featureRoot,file),'utf8'));}
|
|
155
|
+
catch{return false;}
|
|
156
|
+
const acIds=new Set(sources.flatMap(source=>source.split(/\r?\n/).map(line=>line.match(ACCEPTANCE)).filter(Boolean).map(match=>match[1]||match[2])));
|
|
157
|
+
const taskIds=new Set(sources[2].split(/\r?\n/).map(line=>line.match(TASK)).filter(Boolean).map(match=>match[2]));
|
|
158
|
+
return data.cases.every(item=>item.acIds.every(id=>acIds.has(id))&&item.taskIds.every(id=>taskIds.has(id)));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function validateTestCases(specsDir,status,names){
|
|
162
|
+
if(Object.hasOwn(status,'testCases')){
|
|
163
|
+
if(!Array.isArray(status.testCases))return 'spec_status_invalid';
|
|
164
|
+
const expected=new Set(names.map(name=>path.resolve(specsDir,name,'test-cases.json')).filter(target=>fs.existsSync(target)));
|
|
165
|
+
const recorded=new Set();
|
|
166
|
+
for(const item of status.testCases){
|
|
167
|
+
if(item===null||typeof item!=='object'||Array.isArray(item)||typeof item.path!=='string'||!item.path||
|
|
168
|
+
path.isAbsolute(item.path)||typeof item.sha256!=='string'||!/^[a-fA-F0-9]{64}$/.test(item.sha256))return 'spec_status_invalid';
|
|
169
|
+
const target=path.resolve(specsDir,item.path);
|
|
170
|
+
if(!target.startsWith(`${path.resolve(specsDir)}${path.sep}`)||recorded.has(target))return 'spec_status_invalid';
|
|
171
|
+
recorded.add(target);
|
|
172
|
+
if(!expected.has(target))return 'test_cases_changed';
|
|
173
|
+
let bytes;
|
|
174
|
+
try{
|
|
175
|
+
const featureRoot=fs.realpathSync(path.dirname(target)),realTarget=fs.realpathSync(target);
|
|
176
|
+
if(!contained(featureRoot,realTarget))return 'spec_status_invalid';
|
|
177
|
+
bytes=fs.readFileSync(realTarget);
|
|
178
|
+
}catch{return 'test_cases_changed';}
|
|
179
|
+
const actual=createHash('sha256').update(bytes).digest('hex');
|
|
180
|
+
if(actual!==item.sha256.toLowerCase())return 'test_cases_changed';
|
|
181
|
+
if(!validJson(bytes))return 'test_cases_invalid';
|
|
182
|
+
const featureName=path.basename(path.dirname(target)).replace(/^\d+\./,'');
|
|
183
|
+
if(!validTestContract(target,featureName))return 'test_cases_invalid';
|
|
184
|
+
}
|
|
185
|
+
if(expected.size!==recorded.size||[...expected].some(target=>!recorded.has(target)))return 'test_cases_changed';
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
for(const name of names){
|
|
189
|
+
const target=path.join(specsDir,name,'test-cases.json');
|
|
190
|
+
try{
|
|
191
|
+
if(fs.existsSync(target)){
|
|
192
|
+
const featureRoot=fs.realpathSync(path.join(specsDir,name)),realTarget=fs.realpathSync(target);
|
|
193
|
+
if(!contained(featureRoot,realTarget)||!validJson(fs.readFileSync(realTarget))||
|
|
194
|
+
!validTestContract(target,name.replace(/^\d+\./,'')))return 'test_cases_invalid';
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
catch{return 'test_cases_invalid';}
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function readFeature(specsDir,name){
|
|
203
|
+
return parseFeatureTaskText(fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8'));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export function declaredAcceptanceIds(source){
|
|
207
|
+
return new Set(source.split(/\r?\n/).map(line=>line.match(ACCEPTANCE)).filter(Boolean).map(match=>match[1]||match[2]));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function parseFeatureTaskText(source){
|
|
211
|
+
const lines=source.split(/\r?\n/);
|
|
212
|
+
const tasks=[];
|
|
213
|
+
const taskIds=new Set();
|
|
214
|
+
const dependencies=new Map();
|
|
215
|
+
for(const line of lines){
|
|
216
|
+
const task=line.match(TASK);
|
|
217
|
+
if(task){
|
|
218
|
+
if(taskIds.has(task[2]))return {error:'tasks_invalid'};
|
|
219
|
+
taskIds.add(task[2]);
|
|
220
|
+
const dropped=/\[DROPPED(?:\s[^\]]*)?\]/.test(task[3]);
|
|
221
|
+
tasks.push({
|
|
222
|
+
id:task[2],
|
|
223
|
+
description:task[3].replace(/~~\s*\[DROPPED(?:\s[^\]]*)?\].*$/,'').trim(),
|
|
224
|
+
completed:task[1].toLowerCase()==='x',
|
|
225
|
+
dropped,
|
|
226
|
+
});
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const dependency=line.match(DEPENDENCY);
|
|
230
|
+
if(dependency){
|
|
231
|
+
if(dependencies.has(dependency[1]))return {error:'dependencies_invalid'};
|
|
232
|
+
const required=dependency[2].split(/[,,]/).map(value=>value.trim()).filter(Boolean);
|
|
233
|
+
if(!required.length||required.some(id=>!TASK_ID.test(id)))return {error:'dependencies_invalid'};
|
|
234
|
+
dependencies.set(dependency[1],required);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if(!tasks.length)return {error:'tasks_invalid'};
|
|
238
|
+
return {tasks,dependencies};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function validDependencies(tasks,dependencies){
|
|
242
|
+
const ids=new Set(tasks.map(task=>task.id));
|
|
243
|
+
for(const [taskId,required] of dependencies){
|
|
244
|
+
if(!ids.has(taskId)||required.some(id=>id===taskId||!ids.has(id)))return false;
|
|
245
|
+
}
|
|
246
|
+
const visiting=new Set(),visited=new Set();
|
|
247
|
+
const visit=id=>{
|
|
248
|
+
if(visiting.has(id))return false;
|
|
249
|
+
if(visited.has(id))return true;
|
|
250
|
+
visiting.add(id);
|
|
251
|
+
for(const dependency of dependencies.get(id)||[])if(!visit(dependency))return false;
|
|
252
|
+
visiting.delete(id);visited.add(id);return true;
|
|
253
|
+
};
|
|
254
|
+
return tasks.every(task=>visit(task.id));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function validateBootstrap(codeProject,specsDir,names){
|
|
258
|
+
const empty=fs.readdirSync(codeProject).length===0;
|
|
259
|
+
const hasBootstrap=names.includes('0.bootstrap');
|
|
260
|
+
if(empty&&!hasBootstrap)return 'bootstrap_required';
|
|
261
|
+
if(!empty&&hasBootstrap){
|
|
262
|
+
const parsed=readFeature(specsDir,'0.bootstrap');
|
|
263
|
+
if(parsed.error)return parsed.error;
|
|
264
|
+
const bootstrapTask=parsed.tasks.find(task=>task.id==='T-001');
|
|
265
|
+
if(bootstrapTask&&!bootstrapTask.completed&&!bootstrapTask.dropped)return 'bootstrap_conflict';
|
|
266
|
+
}
|
|
267
|
+
return null;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function reviewEvidenceNames(specsDir){
|
|
271
|
+
const reviews=path.join(specsDir,'.reviews');
|
|
272
|
+
try{
|
|
273
|
+
const info=fs.lstatSync(reviews);
|
|
274
|
+
if(info.isSymbolicLink()||!info.isDirectory())return {error:'review_evidence_invalid',names:[]};
|
|
275
|
+
return {names:fs.readdirSync(reviews,{withFileTypes:true}).filter(entry=>entry.isFile()).map(entry=>entry.name)};
|
|
276
|
+
}
|
|
277
|
+
catch(error){return error&&error.code==='ENOENT'?{names:[]}:{error:'review_evidence_invalid',names:[]};}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function regexEscape(value){return value.replace(/[.*+?^${}()|[\]\\]/g,'\\$&');}
|
|
281
|
+
|
|
282
|
+
function missingReviewIds(featureName,tasks,evidenceNames){
|
|
283
|
+
const featureKeys=[...new Set([featureName,featureName.replace(/^\d+\./,'')])].map(regexEscape);
|
|
284
|
+
return tasks.filter(task=>task.completed&&!task.dropped).map(task=>task.id).filter(taskId=>{
|
|
285
|
+
const escaped=regexEscape(taskId);
|
|
286
|
+
return !evidenceNames.some(name=>featureKeys.some(feature=>new RegExp(`^${feature}-${escaped}-r\\d+\\.md$`).test(name)));
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function selectTask(specsDir,names){
|
|
291
|
+
const features=[];
|
|
292
|
+
const warnings=[];
|
|
293
|
+
const evidence=reviewEvidenceNames(specsDir);
|
|
294
|
+
if(evidence.error)return {error:evidence.error,features,warnings};
|
|
295
|
+
const evidenceNames=evidence.names;
|
|
296
|
+
for(const name of names){
|
|
297
|
+
const parsed=readFeature(specsDir,name);
|
|
298
|
+
if(parsed.error)return {error:parsed.error,features,warnings};
|
|
299
|
+
if(!validDependencies(parsed.tasks,parsed.dependencies))return {error:'dependencies_invalid',features,warnings};
|
|
300
|
+
const byId=new Map(parsed.tasks.map(task=>[task.id,task]));
|
|
301
|
+
const pending=parsed.tasks.filter(task=>!task.completed&&!task.dropped);
|
|
302
|
+
const missing=missingReviewIds(name,parsed.tasks,evidenceNames);
|
|
303
|
+
if(missing.length)warnings.push(`⚠ 凭证缺失: ${missing.join(',')}(存量欠账,如实留档,恢复起严格执行)`);
|
|
304
|
+
features.push({
|
|
305
|
+
name,
|
|
306
|
+
total:parsed.tasks.length,
|
|
307
|
+
completed:parsed.tasks.filter(task=>task.completed).length,
|
|
308
|
+
dropped:parsed.tasks.filter(task=>task.dropped).length,
|
|
309
|
+
pending:pending.length,
|
|
310
|
+
});
|
|
311
|
+
if(!pending.length)continue;
|
|
312
|
+
const eligible=pending.find(task=>(parsed.dependencies.get(task.id)||[]).every(id=>{
|
|
313
|
+
const dependency=byId.get(id);
|
|
314
|
+
return dependency&&(dependency.completed||dependency.dropped);
|
|
315
|
+
}));
|
|
316
|
+
if(!eligible)return {error:'dependencies_not_ready',features,warnings};
|
|
317
|
+
return {features,warnings,nextTask:{feature:name,id:eligible.id,description:eligible.description}};
|
|
318
|
+
}
|
|
319
|
+
return {features,warnings,nextTask:null};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function inspectCmAiAdmission(options){
|
|
323
|
+
return admissionFor(options);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function admissionFor(options,inProgressBootstrap=null){
|
|
327
|
+
const input=options&&typeof options==='object'&&!Array.isArray(options)?options:{};
|
|
328
|
+
const specsDir=directory(input.specsDir),codeProject=directory(input.codeProject);
|
|
329
|
+
const base={version:1,workflow:'cm-ai',phase:'admission',approvalIntent:approvalIntent(input.approvalResponse,input.assumeYes),specsDir,codeProject};
|
|
330
|
+
if(!specsDir)return result(base,'blocked','specs_missing');
|
|
331
|
+
if(!codeProject)return result(base,'blocked','code_project_missing');
|
|
332
|
+
const discovered=discoverFeatures(specsDir);
|
|
333
|
+
if(discovered.error)return result(base,'blocked',discovered.error);
|
|
334
|
+
const status=readStatus(specsDir);
|
|
335
|
+
if(status.kind==='invalid')return result(base,'blocked','spec_status_invalid');
|
|
336
|
+
if(status.kind==='missing'||status.value.status==='awaiting_review'){
|
|
337
|
+
const reason=base.approvalIntent==='explicit'?'approval_write_required':'spec_approval_required';
|
|
338
|
+
return result(base,'awaiting_spec_approval',reason);
|
|
339
|
+
}
|
|
340
|
+
const featuresProblem=approvedFeaturesProblem(status.value,discovered.names);
|
|
341
|
+
if(featuresProblem==='spec_features_changed')return result(base,'awaiting_spec_approval',featuresProblem);
|
|
342
|
+
if(featuresProblem)return result(base,'blocked',featuresProblem);
|
|
343
|
+
const testCasesProblem=validateTestCases(specsDir,status.value,discovered.names);
|
|
344
|
+
if(testCasesProblem==='test_cases_changed')return result(base,'awaiting_spec_approval',testCasesProblem);
|
|
345
|
+
if(testCasesProblem)return result(base,'blocked',testCasesProblem);
|
|
346
|
+
const bootstrapProblem=validateBootstrap(codeProject,specsDir,discovered.names);
|
|
347
|
+
if(bootstrapProblem&&!(bootstrapProblem==='bootstrap_conflict'&&inProgressBootstrap==='T-001'))
|
|
348
|
+
return result(base,'blocked',bootstrapProblem);
|
|
349
|
+
const selection=selectTask(specsDir,discovered.names);
|
|
350
|
+
if(selection.error)return result(base,'blocked',selection.error,{features:selection.features,warnings:selection.warnings});
|
|
351
|
+
if(!selection.nextTask)return result(base,'complete','all_tasks_terminal',{features:selection.features,warnings:selection.warnings});
|
|
352
|
+
return result(base,'ready','task_selected',{features:selection.features,nextTask:selection.nextTask,warnings:selection.warnings});
|
|
353
|
+
}
|