@aibyzero/cm-workflow 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +27 -0
- package/CHANGELOG.md +230 -1
- package/CONTRIBUTING.md +47 -0
- package/README.md +21 -3
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/VERSION +1 -1
- package/compat/claude-commands/cm-challenge.md +3 -0
- package/docs/architecture.md +40 -13
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +153 -16
- package/docs/live-evidence-drivers.md +28 -4
- package/docs/out-of-scope/README.md +25 -0
- package/docs/out-of-scope/background-supervisor.md +32 -0
- package/docs/reviewed-integration.md +48 -0
- package/docs/user-guide.md +50 -21
- package/install-codex.sh +331 -18
- package/install.ps1 +28 -2
- package/install.sh +321 -17
- package/package.json +2 -1
- package/runtime/js/cm-ai/batch-location.mjs +55 -0
- package/runtime/js/cm-ai/batch-plan.mjs +242 -0
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +94 -21
- package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
- package/runtime/js/cm-ai/codex-config.mjs +6 -2
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
- package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
- package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
- package/runtime/js/cm-ai/control-policy.mjs +24 -6
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +236 -34
- package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
- package/runtime/js/cm-ai/effect-contract.mjs +11 -2
- package/runtime/js/cm-ai/execution-policy.mjs +3 -1
- package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
- package/runtime/js/cm-ai/execution-store.mjs +60 -17
- package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
- package/runtime/js/cm-ai/host-check.mjs +14 -6
- package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
- package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
- package/runtime/js/cm-ai/host-replay.mjs +148 -0
- package/runtime/js/cm-ai/host-session.mjs +42 -9
- package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +22 -9
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
- package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
- package/runtime/js/cm-ai/live-evidence.mjs +28 -6
- package/runtime/js/cm-ai/operator-guidance.mjs +63 -30
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
- package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
- package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
- package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
- package/runtime/js/cm-ai/review-package.mjs +79 -7
- package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
- package/runtime/js/cm-ai/review-presentation.mjs +177 -8
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
- package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
- package/runtime/js/cm-ai/scope-revision.mjs +38 -0
- package/runtime/js/cm-ai/specification-material.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +247 -41
- package/runtime/js/cm-ai/verification-auto.mjs +38 -0
- package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
- package/runtime/js/cm-ai/worker-claude.mjs +35 -13
- package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
- package/runtime/js/cm-ai/worker-codex.mjs +41 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
- package/runtime/js/cm-fix/cause-package.mjs +46 -1
- package/runtime/js/cm-fix/command-correction.mjs +37 -0
- package/runtime/js/cm-fix/cooperative.mjs +12 -0
- package/runtime/js/cm-fix/dossier.mjs +8 -2
- package/runtime/js/cm-fix/execution.mjs +578 -100
- package/runtime/js/cm-fix/final-review.mjs +39 -8
- package/runtime/js/cm-fix/finish.mjs +15 -11
- package/runtime/js/cm-fix/host-review.mjs +65 -10
- package/runtime/js/cm-fix/host.mjs +35 -12
- package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
- package/runtime/js/cm-fix/metrics.mjs +18 -5
- package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
- package/runtime/js/cm-fix/regression.mjs +16 -7
- package/runtime/js/cm-fix/repair.mjs +29 -8
- package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
- package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
- package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
- package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
- package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
- package/runtime/js/cm-fix/review-verification.mjs +214 -0
- package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
- package/runtime/js/cm-fix/start.mjs +6 -3
- package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
- package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
- package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
- package/runtime/js/cm-prd/accepted-design.mjs +8 -0
- package/runtime/js/cm-prd/analysis.mjs +13 -9
- package/runtime/js/cm-prd/change.mjs +37 -16
- package/runtime/js/cm-prd/draft-save.mjs +13 -6
- package/runtime/js/cm-prd/draft.mjs +31 -3
- package/runtime/js/cm-prd/failed-correction.mjs +19 -3
- package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
- package/runtime/js/cm-prd/review-correction.mjs +6 -4
- package/runtime/js/cm-prd/review-disposition.mjs +7 -1
- package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
- package/runtime/js/cm-prd/self-check.mjs +125 -6
- package/runtime/js/cm-prd/session.mjs +30 -1
- package/runtime/js/cm-prd/summary.mjs +38 -17
- package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
- package/runtime/js/cm-prd/tree-digest.mjs +34 -0
- package/runtime/js/cm-prd/validation-reason.mjs +8 -4
- package/runtime/js/cm-security/scan.mjs +1 -1
- package/runtime/js/commander/decision.mjs +44 -0
- package/runtime/js/commander/dispatch-registry.mjs +110 -0
- package/runtime/js/commander/ledger.mjs +265 -0
- package/runtime/js/commander/preflight.mjs +107 -0
- package/runtime/js/notify-later.mjs +13 -0
- package/runtime/js/notify-send.mjs +6 -2
- package/runtime/js/notify.mjs +570 -63
- package/runtime/js/review-findings.mjs +38 -0
- package/runtime/js/session-boundary.mjs +56 -0
- package/runtime/js/session-handoff.mjs +68 -0
- package/runtime/js/spec-task-line.mjs +27 -13
- package/runtime/js/specs-status.mjs +1 -1
- package/runtime/js/task-scope.mjs +197 -0
- package/runtime/logging.md +6 -1
- package/runtime/model-efficiency.md +69 -10
- package/runtime/orchestration.md +3 -1
- package/runtime/project-learning.md +2 -0
- package/runtime/review.md +12 -2
- package/runtime/test-contract.md +1 -0
- package/scripts/ci-test-weights.json +3 -0
- package/scripts/cm-ai-admission.mjs +11 -5
- package/scripts/cm-ai-admission.test.mjs +23 -2
- package/scripts/cm-ai-batch-drive.mjs +79 -18
- package/scripts/cm-ai-batch-drive.test.mjs +169 -3
- package/scripts/cm-ai-batch-host.mjs +38 -9
- package/scripts/cm-ai-batch-host.test.mjs +27 -14
- package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
- package/scripts/cm-ai-batch-location.test.mjs +57 -0
- package/scripts/cm-ai-batch-plan.mjs +52 -0
- package/scripts/cm-ai-batch-plan.test.mjs +397 -0
- package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
- package/scripts/cm-ai-batch-run.mjs +483 -63
- package/scripts/cm-ai-batch-run.test.mjs +23 -4
- package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
- package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
- package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
- package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
- package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
- package/scripts/cm-ai-control-launch.test.mjs +21 -0
- package/scripts/cm-ai-control-policy.test.mjs +82 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
- package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
- package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
- package/scripts/cm-ai-development-rework.test.mjs +423 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +3 -2
- package/scripts/cm-ai-drive.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +37 -5
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host-fixture.mjs +9 -6
- package/scripts/cm-ai-host-protected.test.mjs +1 -1
- package/scripts/cm-ai-host.mjs +60 -19
- package/scripts/cm-ai-host.test.mjs +15 -0
- package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
- package/scripts/cm-ai-integration-independence.test.mjs +23 -0
- package/scripts/cm-ai-integration-launch.test.mjs +240 -0
- package/scripts/cm-ai-integration-preview.mjs +41 -0
- package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
- package/scripts/cm-ai-nested-execution.test.mjs +29 -1
- package/scripts/cm-ai-operator-guidance.test.mjs +71 -0
- package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
- package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
- package/scripts/cm-ai-review-failure.test.mjs +150 -5
- package/scripts/cm-ai-review-timeout.test.mjs +20 -0
- package/scripts/cm-ai-run.mjs +88 -21
- package/scripts/cm-ai-scope-revision.test.mjs +341 -0
- package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
- package/scripts/cm-ai-supersede.test.mjs +28 -0
- package/scripts/cm-ai-verification-auto.test.mjs +99 -0
- package/scripts/cm-announce-hook.mjs +35 -8
- package/scripts/cm-announce-hook.test.mjs +25 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +58 -1
- package/scripts/cm-claude-developer-worker.test.mjs +56 -7
- package/scripts/cm-claude-install-layout.test.mjs +1 -1
- package/scripts/cm-claude-probe.test.mjs +26 -0
- package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +49 -0
- package/scripts/cm-claude-worker.test.mjs +16 -0
- package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
- package/scripts/cm-codex-developer-worker.test.mjs +120 -0
- package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
- package/scripts/cm-codex-prompt-input.test.mjs +153 -0
- package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
- package/scripts/cm-commander-ledger.test.mjs +260 -0
- package/scripts/cm-commander-p2.test.mjs +295 -0
- package/scripts/cm-commander-preflight.mjs +84 -0
- package/scripts/cm-commander.mjs +116 -0
- package/scripts/cm-config-lock.mjs +35 -0
- package/scripts/cm-controlled-correction.test.mjs +10 -1
- package/scripts/cm-developer-failure-code.test.mjs +62 -0
- package/scripts/cm-display-task-id.test.mjs +41 -0
- package/scripts/cm-drive-liveness.test.mjs +83 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
- package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
- package/scripts/cm-external-batch-host.test.mjs +12 -9
- package/scripts/cm-external-process-cleanup.test.mjs +128 -0
- package/scripts/cm-external-qa-fix.test.mjs +89 -7
- package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
- package/scripts/cm-failover.mjs +48 -10
- package/scripts/cm-failover.test.mjs +46 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
- package/scripts/cm-fix-command-correction.mjs +17 -0
- package/scripts/cm-fix-command-correction.test.mjs +211 -0
- package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
- package/scripts/cm-fix-drive.mjs +33 -5
- package/scripts/cm-fix-drive.test.mjs +49 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
- package/scripts/cm-fix-host-review.test.mjs +21 -9
- package/scripts/cm-fix-host.mjs +26 -8
- package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
- package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
- package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
- package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
- package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
- package/scripts/cm-fix-review-preflight.mjs +24 -0
- package/scripts/cm-fix-review-storage.test.mjs +233 -0
- package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
- package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
- package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
- package/scripts/cm-fix-review-verification.test.mjs +146 -0
- package/scripts/cm-fix-revision-transport.test.mjs +81 -0
- package/scripts/cm-fix-source-correction.test.mjs +296 -0
- package/scripts/cm-fix-test-type-correction.mjs +18 -0
- package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
- package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
- package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
- package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
- package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
- package/scripts/cm-fix-verification-recovery.mjs +33 -0
- package/scripts/cm-host-diagnostic.test.mjs +33 -0
- package/scripts/cm-host-liveness.test.mjs +150 -0
- package/scripts/cm-host-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -0
- package/scripts/cm-host-stage-observer.test.mjs +41 -0
- package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
- package/scripts/cm-install-manifest.sh +351 -0
- package/scripts/cm-live-evidence.test.mjs +59 -1
- package/scripts/cm-log-event.mjs +61 -10
- package/scripts/cm-log-event.test.mjs +121 -1
- package/scripts/cm-matt-skills.mjs +576 -0
- package/scripts/cm-matt-skills.test.mjs +550 -0
- package/scripts/cm-notify-command.test.mjs +42 -10
- package/scripts/cm-notify.mjs +14 -10
- package/scripts/cm-notify.test.mjs +625 -75
- package/scripts/cm-patrol.mjs +4 -1
- package/scripts/cm-patrol.test.mjs +23 -5
- package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
- package/scripts/cm-prd-completion.test.mjs +56 -13
- package/scripts/cm-prd-design-phase.test.mjs +78 -8
- package/scripts/cm-prd-draft-save.test.mjs +12 -0
- package/scripts/cm-prd-draft.test.mjs +1 -1
- package/scripts/cm-prd-drive.mjs +13 -6
- package/scripts/cm-prd-drive.test.mjs +46 -2
- package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
- package/scripts/cm-prd-host.mjs +10 -5
- package/scripts/cm-prd-host.test.mjs +4 -2
- package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
- package/scripts/cm-prd-review-disposition.test.mjs +124 -8
- package/scripts/cm-prd-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +16 -1
- package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
- package/scripts/cm-prd-self-check.test.mjs +105 -5
- package/scripts/cm-prd-session-recovery.test.mjs +5 -3
- package/scripts/cm-prd-summary.test.mjs +55 -3
- package/scripts/cm-prd-task-grouping.test.mjs +6 -6
- package/scripts/cm-prd-tree-digest.test.mjs +74 -0
- package/scripts/cm-refactor-drive.mjs +2 -1
- package/scripts/cm-refactor-drive.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +3 -15
- package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
- package/scripts/cm-skill-hints-exam.mjs +149 -0
- package/scripts/cm-skill-hints-install.test.mjs +168 -0
- package/scripts/cm-skill-hints.exam.json +706 -0
- package/scripts/cm-skill-hints.json +119 -0
- package/scripts/cm-skill-hints.mjs +669 -0
- package/scripts/cm-skill-hints.test.mjs +831 -0
- package/scripts/cm-skill-judge.mjs +181 -0
- package/scripts/cm-skill-judge.test.mjs +255 -0
- package/scripts/cm-specs-status.test.mjs +4 -2
- package/scripts/cm-start-check.mjs +208 -0
- package/scripts/cm-start-check.test.mjs +321 -0
- package/scripts/cm-task-gate.mjs +150 -29
- package/scripts/cm-task-gate.test.mjs +73 -1
- package/scripts/cm-task-id-grammar.test.mjs +66 -0
- package/scripts/cm-task-scope.test.mjs +308 -0
- package/scripts/cm-test-suite.mjs +109 -0
- package/scripts/cm-test-suite.test.mjs +162 -0
- package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
- package/scripts/cm-upgrade-compat.test.mjs +239 -0
- package/scripts/cm-workflow-config.mjs +12 -2
- package/scripts/fixtures/fix-verification-claude.mjs +44 -0
- package/scripts/fixtures/host-diagnostic.mjs +33 -0
- package/scripts/fixtures/reviewed-integration.mjs +202 -0
- package/scripts/scan-public-safety.py +1 -0
- package/scripts/session-boundary.test.mjs +170 -0
- package/scripts/test-npm-install.py +14 -3
- package/scripts/test-shell-compat.sh +2 -0
- package/scripts/validate-public-repo.py +1 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N4-review.md +2 -1
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/N8-finish.md +22 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
- package/skills/cm-ai/references/js-host-recovery.md +79 -3
- package/skills/cm-ai/references/js-host.md +89 -17
- package/skills/cm-challenge/SKILL.md +65 -0
- package/skills/cm-challenge/evals/README.md +18 -0
- package/skills/cm-challenge/evals/trigger-cases.json +20 -0
- package/skills/cm-challenge/evals/trigger-config.json +28 -0
- package/skills/cm-challenge/references/examples.md +15 -0
- package/skills/cm-check/SKILL.md +5 -0
- package/skills/cm-check/references/js-host.md +2 -0
- package/skills/cm-fix/SKILL.md +12 -3
- package/skills/cm-fix/references/command-correction.md +67 -0
- package/skills/cm-fix/references/isolated-review.md +54 -0
- package/skills/cm-fix/references/js-host.md +62 -2
- package/skills/cm-fix/references/test-type-correction.md +72 -0
- package/skills/cm-fix/references/verification-recovery.md +114 -0
- package/skills/cm-idea/SKILL.md +2 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-notify/SKILL.md +2 -0
- package/skills/cm-prd/SKILL.md +12 -8
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +6 -0
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-host.md +4 -2
- package/skills/cm-prd/references/spec-self-check.md +5 -1
- package/skills/cm-refactor/SKILL.md +8 -0
- package/skills/cm-refactor/references/js-host.md +2 -0
- package/skills/cm-test/SKILL.md +4 -0
- package/templates/dashboard/dashboard.html +2 -2
- package/templates/pixel/cm-pixel.html +1 -1
- package/templates/pixel/cm-pixel.sh +1 -1
- package/templates/pixel/dev/template.html +1 -1
- package/templates/statusline/cm-statusline.sh +1 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// Upgrade compatibility (review R2-02, part 2): a batch started before the batch
|
|
2
|
+
// execution table (batch.memberDevelopment, design 3.7) resumes on the new code with its
|
|
3
|
+
// original plan digest, member fingerprints and path, and runs to completion.
|
|
4
|
+
//
|
|
5
|
+
// Archive format pinned from f73402d (the last commit before the upgrade):
|
|
6
|
+
// - scripts/cm-ai-batch-run.mjs: planDigest=digest(config) (line 160), and the first
|
|
7
|
+
// advance writes record('batch_start',{from_key,[BATCH_SEGMENT_FIELD]:batchSegment(batchId)})
|
|
8
|
+
// (line 530) through cm-log-event.py before any member run exists;
|
|
9
|
+
// - scripts/cm-ai-batch-host.mjs: config={...batch,controlPolicy} for a v2 batch;
|
|
10
|
+
// - runtime/js/cm-ai/batch-location.mjs: batchSegment = first 8 chars of batchId ('.'->'-')
|
|
11
|
+
// + '-' + sha256(batchId)[0..12], field worktree_segment.
|
|
12
|
+
// A real f73402d run of this fixture wrote exactly these batch_start keys (checked by the
|
|
13
|
+
// last test whenever f73402d is in the local history; CI shallow clones skip it).
|
|
14
|
+
import test from 'node:test';
|
|
15
|
+
import assert from 'node:assert/strict';
|
|
16
|
+
import fs from 'node:fs';
|
|
17
|
+
import os from 'node:os';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import {createHash,randomUUID} from 'node:crypto';
|
|
20
|
+
import {spawnSync} from 'node:child_process';
|
|
21
|
+
import {fileURLToPath} from 'node:url';
|
|
22
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
23
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
24
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
25
|
+
|
|
26
|
+
const repo=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
27
|
+
const LEGACY_COMMIT='f73402d';
|
|
28
|
+
const batchId='legacy-batch-run',repositoryId='legacy-batch-fixture';
|
|
29
|
+
const policy={version:2,development:'conversation',bootstrap:'disabled',qa:'run',qaFix:'disabled'};
|
|
30
|
+
const develop={status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
31
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
32
|
+
// The batch_start keys f73402d wrote (cm-log-event.py envelope + record() data).
|
|
33
|
+
const LEGACY_START_KEYS=['schema_version','run_id','at','workflow','event','runtime','project','detail','phase',
|
|
34
|
+
'project_path','specs_path','repository_id','plan_digest','from_key','worktree_segment','event_id'].sort();
|
|
35
|
+
|
|
36
|
+
// Two serial members (T-002 waits for T-001), task grammar 2 approval, v2 conversation
|
|
37
|
+
// development with QA, no execution table: the shape every pre-upgrade batch had.
|
|
38
|
+
function fixture(t){
|
|
39
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-upgrade-batch-')));
|
|
40
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
41
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'app'),bin=path.join(root,'bin'),reject=path.join(root,'reject-T-002');
|
|
42
|
+
fs.mkdirSync(path.join(specsDir,'1.work'),{recursive:true});fs.mkdirSync(codeProject);fs.mkdirSync(bin);
|
|
43
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,'1.work',name),'# Fixture\n');
|
|
44
|
+
fs.writeFileSync(path.join(specsDir,'1.work/tasks.md'),
|
|
45
|
+
'- [ ] T-001: first\n - 范围: `target.mjs`\n- [ ] T-002: second\n - 范围: `other.mjs`\n\n## 依赖关系\n\n- T-002 依赖 T-001\n');
|
|
46
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],
|
|
47
|
+
specFiles:buildManifest(specsDir),taskGrammar:2}));
|
|
48
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
49
|
+
for(const args of [['init','-b','main'],['config','user.name','Fixture'],['config','user.email','fixture@example.invalid'],['add','-A'],['commit','-m','baseline']]){
|
|
50
|
+
const r=spawnSync('git',['-C',codeProject,...args],{encoding:'utf8'});assert.equal(r.status,0,r.stderr);
|
|
51
|
+
}
|
|
52
|
+
const workflow={qa:{commands:[{id:'value',caseIds:[],command:[process.execPath,'-e',"import('./target.mjs').then(m=>{if(m.value!==42)process.exit(1)})"]}],
|
|
53
|
+
environment:{kind:'web',carrier:'browser',target:'fixture-target',scope:'local'}},documentationPaths:[],applicableAgentFiles:[]};
|
|
54
|
+
const bundle={batch:{version:1,repositoryId,batchId,specsDir,codeProject,tasks:[
|
|
55
|
+
{feature:'1.work',taskId:'T-001',scope:['target.mjs'],requirements:['requirements.md']},
|
|
56
|
+
{feature:'1.work',taskId:'T-002',scope:['other.mjs'],requirements:['requirements.md']}]},
|
|
57
|
+
workflows:{'1.work/T-001':workflow,'1.work/T-002':workflow}};
|
|
58
|
+
fs.writeFileSync(path.join(root,'run.json'),JSON.stringify(bundle));
|
|
59
|
+
fs.writeFileSync(path.join(root,'control.json'),JSON.stringify(policy));
|
|
60
|
+
fs.writeFileSync(path.join(root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,cli_model:'fixture',
|
|
61
|
+
prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}}));
|
|
62
|
+
// Fixture Codex reviewer: approves, except T-002 while the reject marker exists.
|
|
63
|
+
fs.writeFileSync(path.join(bin,'codex'),`#!${process.execPath}
|
|
64
|
+
const fs=require('node:fs');let prompt='';process.stdin.on('data',part=>prompt+=part);process.stdin.on('end',()=>{
|
|
65
|
+
const marker='<cm-review-data-json>\\n',data=JSON.parse(prompt.slice(prompt.indexOf(marker)+marker.length));
|
|
66
|
+
const reject=data.reviewPackage.identity.taskId==='T-002'&&fs.existsSync(${JSON.stringify(reject)});
|
|
67
|
+
const value={verdict:reject?'changes_requested':'approved',packageDigest:data.reviewPackage.packageDigest,examinedPaths:data.examinedPaths,
|
|
68
|
+
findings:reject?[{id:'F1',severity:'P2',path:'other.mjs',message:'Use 2',evidence:'Fixture finding'}]:[],summary:'Synthetic review'};
|
|
69
|
+
for(const event of [{type:'thread.started',thread_id:'fixture-'+Date.now()},{type:'turn.started'},
|
|
70
|
+
{type:'item.completed',item:{type:'agent_message',text:JSON.stringify(value)}},{type:'turn.completed'}])process.stdout.write(JSON.stringify(event)+'\\n');
|
|
71
|
+
});
|
|
72
|
+
`,{mode:0o700});
|
|
73
|
+
for(const [task,file,source] of [['T-001','target.mjs','export const value = 42;\n'],['T-002','other.mjs','export const other = 1;\n']]){
|
|
74
|
+
const dir=path.join(root,'answers/1.work',task);fs.mkdirSync(dir,{recursive:true});
|
|
75
|
+
fs.writeFileSync(path.join(dir,'develop.json'),JSON.stringify({...develop,edits:{[file]:`${task}.txt`}}));
|
|
76
|
+
fs.writeFileSync(path.join(dir,`${task}.txt`),source);
|
|
77
|
+
fs.writeFileSync(path.join(dir,'documentation-inspect.json'),JSON.stringify({status:'completed',reason:'Fixture inspected'}));
|
|
78
|
+
fs.writeFileSync(path.join(dir,'qa-assess.json'),JSON.stringify({confirmed:true}));
|
|
79
|
+
}
|
|
80
|
+
const plan=path.join(root,'plan.json');
|
|
81
|
+
const writePlan=mode=>fs.writeFileSync(plan,JSON.stringify({config:'run.json',mode,hostContext:'legacy-host',
|
|
82
|
+
...(mode==='resume'?{originalHostContext:'legacy-host'}:{}),controlConfig:'control.json',
|
|
83
|
+
permissions:['--review-config','review.json'],answers:'answers',
|
|
84
|
+
checks:{'1.work/T-001':[{id:'syntax',command:[process.execPath,'--check','target.mjs']}],
|
|
85
|
+
'1.work/T-002':[{id:'syntax',command:[process.execPath,'--check','other.mjs']}]}}));
|
|
86
|
+
writePlan('create');
|
|
87
|
+
const drive=(workflowRoot=repo)=>spawnSync(process.execPath,[path.join(workflowRoot,'scripts/cm-ai-batch-drive.mjs'),'--plan',plan,'advance'],
|
|
88
|
+
{encoding:'utf8',timeout:120000,env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,
|
|
89
|
+
CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}});
|
|
90
|
+
return {root,specsDir,codeProject,bundle,reject,writePlan,drive,log:path.join(specsDir,'运行日志.jsonl')};
|
|
91
|
+
}
|
|
92
|
+
// The plan digest and worktree segment exactly as f73402d computed them.
|
|
93
|
+
const legacyPlanDigest=bundle=>digest({...bundle.batch,controlPolicy:policy});
|
|
94
|
+
const legacySegment=id=>`${id.slice(0,8).replace(/\./g,'-')}-${createHash('sha256').update(id).digest('hex').slice(0,12)}`;
|
|
95
|
+
const batchRows=f=>fs.readFileSync(f.log,'utf8').trim().split('\n').map(line=>JSON.parse(line))
|
|
96
|
+
.filter(row=>row.run_id===batchId&&row.event==='decision'&&row.phase.startsWith('batch_'));
|
|
97
|
+
const memberStates=f=>{
|
|
98
|
+
const dir=path.join(f.specsDir,'.reviews/.execution');
|
|
99
|
+
return Object.fromEntries(fs.readdirSync(dir).filter(name=>fs.existsSync(path.join(dir,name,'state.json')))
|
|
100
|
+
.map(name=>[name,JSON.parse(fs.readFileSync(path.join(dir,name,'state.json'),'utf8'))]));
|
|
101
|
+
};
|
|
102
|
+
const lastResult=r=>JSON.parse(r.stdout.slice(r.stdout.indexOf('{'),r.stdout.lastIndexOf('}')+1)).result;
|
|
103
|
+
// Resume with the current code until the batch stops on its own.
|
|
104
|
+
function resumeToDone(f){
|
|
105
|
+
f.writePlan('resume');let result=null;
|
|
106
|
+
for(let round=0;round<6;round++){
|
|
107
|
+
const r=f.drive();assert.equal(r.status,0,r.stderr);result=lastResult(r);
|
|
108
|
+
if(['run_done','blocked'].includes(result.state)||result.outcome==='rejected')break;
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
function assertLegacyCompletion(f,expectedPlanDigest){
|
|
113
|
+
const rows=batchRows(f);
|
|
114
|
+
assert.deepEqual(rows.map(row=>row.phase),['batch_start','batch_task_committed','batch_handoff','batch_task_committed']);
|
|
115
|
+
assert.deepEqual([...new Set(rows.map(row=>row.plan_digest))],[expectedPlanDigest],'every row keeps the pre-upgrade plan digest');
|
|
116
|
+
const text=fs.readFileSync(f.log,'utf8');
|
|
117
|
+
assert.doesNotMatch(text,/memberDevelopment|member_development/,'no execution table enters the log');
|
|
118
|
+
assert.equal(Object.hasOwn(JSON.parse(fs.readFileSync(path.join(f.root,'run.json'),'utf8')).batch,'memberDevelopment'),false);
|
|
119
|
+
for(const [runId,state] of Object.entries(memberStates(f)))
|
|
120
|
+
assert.doesNotMatch(JSON.stringify(state),/memberDevelopment/,`${runId} carries no execution table`);
|
|
121
|
+
const log=spawnSync('git',['-C',f.codeProject,'log','--format=%s'],{encoding:'utf8'}).stdout;
|
|
122
|
+
assert.deepEqual(log.trim().split('\n'),['T-002: second','T-001: first','baseline'],'both members committed on the original serial path');
|
|
123
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,'1.work/tasks.md'),'utf8'),/\[x\] T-001[\s\S]*\[x\] T-002/);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
test('a batch whose pre-upgrade host wrote batch_start and stopped before its first member resumes on the old plan digest to run_done',t=>{
|
|
127
|
+
const f=fixture(t),planDigest=legacyPlanDigest(f.bundle);
|
|
128
|
+
// Hand-written archive: the one row f73402d wrote at the first advance, before any member run.
|
|
129
|
+
const row={schema_version:1,run_id:batchId,at:'2026-10-20T08:00:00+00:00',workflow:'cm-ai',event:'decision',runtime:'codex',
|
|
130
|
+
project:'app',detail:'Approved task batch started',phase:'batch_start',project_path:f.codeProject,specs_path:f.specsDir,
|
|
131
|
+
repository_id:repositoryId,plan_digest:planDigest,from_key:'1.work/T-001',worktree_segment:legacySegment(batchId),event_id:randomUUID()};
|
|
132
|
+
assert.deepEqual(Object.keys(row).sort(),LEGACY_START_KEYS);
|
|
133
|
+
fs.writeFileSync(f.log,JSON.stringify(row)+'\n');
|
|
134
|
+
const result=resumeToDone(f);
|
|
135
|
+
assert.equal(result.state,'run_done',JSON.stringify(result).slice(0,800));
|
|
136
|
+
assertLegacyCompletion(f,planDigest);
|
|
137
|
+
assert.equal(batchRows(f)[0].event_id,row.event_id,'the original batch_start row is kept, not rewritten');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const legacyAvailable=spawnSync('git',['-C',repo,'cat-file','-e',`${LEGACY_COMMIT}^{commit}`]).status===0;
|
|
141
|
+
test('a batch the f73402d code really ran to mid-member resumes on the new code with unchanged fingerprints to run_done',
|
|
142
|
+
{skip:legacyAvailable?false:`${LEGACY_COMMIT} 不在本地历史(浅克隆),跳过真实旧代码运行`,timeout:300000},t=>{
|
|
143
|
+
const old=fs.mkdtempSync(path.join(os.tmpdir(),'cm-upgrade-old-'));t.after(()=>fs.rmSync(old,{recursive:true,force:true}));
|
|
144
|
+
const archive=spawnSync('sh',['-c',`git -C "$1" archive ${LEGACY_COMMIT} | tar -x -C "$2"`,'archive',repo,old],{encoding:'utf8'});
|
|
145
|
+
assert.equal(archive.status,0,archive.stderr);
|
|
146
|
+
const f=fixture(t);fs.writeFileSync(f.reject,'');
|
|
147
|
+
// Pre-upgrade run: T-001 done and handed off, T-002 stopped after a changes_requested review.
|
|
148
|
+
const first=f.drive(old);assert.equal(first.status,0,first.stderr);
|
|
149
|
+
const stopped=lastResult(first);
|
|
150
|
+
assert.deepEqual([stopped.state,stopped.code,stopped.identity.taskId],['changes_requested','revision_answer_required','T-002']);
|
|
151
|
+
const before=batchRows(f),states=memberStates(f);
|
|
152
|
+
assert.deepEqual(before.map(row=>row.phase),['batch_start','batch_task_committed','batch_handoff']);
|
|
153
|
+
// The hand-written archive above matches the real one: same row keys, same digest formula.
|
|
154
|
+
assert.deepEqual(Object.keys(before[0]).sort(),LEGACY_START_KEYS);
|
|
155
|
+
assert.equal(before[0].plan_digest,legacyPlanDigest(f.bundle));
|
|
156
|
+
assert.equal(before[0].worktree_segment,legacySegment(batchId));
|
|
157
|
+
assert.equal(Object.keys(states).length,2);
|
|
158
|
+
for(const state of Object.values(states))assert.deepEqual(Object.keys(state.fingerprints).sort(),['config','inputs','workflow']);
|
|
159
|
+
// Upgrade: the T-002 author answers the review; the reviewer now approves.
|
|
160
|
+
fs.rmSync(f.reject);
|
|
161
|
+
const answers=path.join(f.root,'answers/1.work/T-002');
|
|
162
|
+
fs.writeFileSync(path.join(answers,'develop-a2.json'),JSON.stringify({...develop,edits:{'other.mjs':'second.txt'}}));
|
|
163
|
+
fs.writeFileSync(path.join(answers,'second.txt'),'export const other = 2;\n');
|
|
164
|
+
const result=resumeToDone(f);
|
|
165
|
+
assert.equal(result.state,'run_done',JSON.stringify(result).slice(0,800));
|
|
166
|
+
assertLegacyCompletion(f,before[0].plan_digest);
|
|
167
|
+
assert.deepEqual(batchRows(f).slice(0,3),before,'the pre-upgrade rows are kept byte for byte');
|
|
168
|
+
const after=memberStates(f);
|
|
169
|
+
for(const [runId,state] of Object.entries(states))
|
|
170
|
+
assert.deepEqual(after[runId].fingerprints,state.fingerprints,`${runId} keeps its pre-upgrade fingerprints`);
|
|
171
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'other.mjs'),'utf8'),'export const other = 2;\n');
|
|
172
|
+
});
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// 升级兼容的完整生命周期(审查 R2-02):升级前(f73402d)创建、带在途操作的 PRD 会话,
|
|
2
|
+
// 用新代码恢复 → 开始新操作 → 发布 → 批准,全程穿过真实宿主与准入 CLI。
|
|
3
|
+
//
|
|
4
|
+
// 夹具格式依据:f73402d 的 runtime/js/cm-prd/session.mjs openPrdSession/begin/call
|
|
5
|
+
// (state.json 只有 version/identity/checkpoint/active/segments;active 为
|
|
6
|
+
// {request,before,calls,selfCheckRules?},规则字段在更早的宿主里不存在;未收到结果的
|
|
7
|
+
// 调用只有 {callId,requestDigest,kind,payload}),f73402d 的 cm-ai-admission.mjs
|
|
8
|
+
// approveCmAiSpecs(批准状态字段与顺序,taskGrammar:2;更早的批准没有该字段),
|
|
9
|
+
// task-scope-record.mjs recordPrdTaskScopes({version,enforced,exempt})。
|
|
10
|
+
// 外壳逐字段手写;检查点与生成请求负载由 analysis.mjs 产生,它在 f73402d 与本分支之间
|
|
11
|
+
// 逐字节未变。最后一条测试在 f73402d 可用时真实运行旧宿主,核对手写夹具与真实存档逐字节一致。
|
|
12
|
+
import test from 'node:test';
|
|
13
|
+
import assert from 'node:assert/strict';
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import os from 'node:os';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
import {spawn,spawnSync} from 'node:child_process';
|
|
18
|
+
import {once} from 'node:events';
|
|
19
|
+
import {createInterface} from 'node:readline';
|
|
20
|
+
import {fileURLToPath} from 'node:url';
|
|
21
|
+
import {createCmPrdAnalysis} from '../runtime/js/cm-prd/analysis.mjs';
|
|
22
|
+
import {checkPrdDraftMechanics,matchesPrdDraftMechanics} from '../runtime/js/cm-prd/self-check.mjs';
|
|
23
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
24
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
25
|
+
|
|
26
|
+
const TIMEOUT=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??120000);
|
|
27
|
+
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
28
|
+
const UPGRADE_BASE='f73402d';
|
|
29
|
+
const ANALYZED={status:'analyzed',summary:'Developer need',sourcePaths:['docs/input.md'],openQuestions:[]};
|
|
30
|
+
const PLAN={requestId:'plan',operation:'advance',text:'Generate specification draft'};
|
|
31
|
+
// 升级前宿主在第一次生成请求发出后被杀时留下的分段计数(真实旧宿主运行观察)。
|
|
32
|
+
const SEGMENTS={context_load:1,requirements_analysis:2,task_split:1,design_generation:1};
|
|
33
|
+
|
|
34
|
+
// 在途操作登记的回答:规则 1 跳过 T-002/a,规则 2 起拒绝它;规则 3 起要求每个任务写范围;
|
|
35
|
+
// 规则 4(语法 3)还会发现会话任务 T-001 不是最后一个。四条规则得到四份不同的报告。
|
|
36
|
+
const TASKS_V1=['- [ ] T-001: Update guide',' - 范围: `README.md`',' - 开发: 会话',
|
|
37
|
+
'- [ ] T-002: Walk guide',' - 范围: `docs/qa.md`','- [ ] T-003: Polish guide','- [ ] T-002/a: Hidden task',''].join('\n');
|
|
38
|
+
// 修正后的回答:规则 1-3 全部通过(`开发: 会话` 只是说明文字),规则 4 下仍报 session_task_not_final。
|
|
39
|
+
const TASKS_V2=['- [ ] T-001: Update guide',' - 范围: `README.md`',' - 开发: 会话',
|
|
40
|
+
'- [ ] T-002: Walk guide',' - 范围: `docs/qa.md`',''].join('\n');
|
|
41
|
+
const reply=tasks=>({status:'draft',summary:'Synthetic documentation draft',features:[{name:'guide',testCasesReason:'no_observable_behavior',
|
|
42
|
+
documents:[{path:'requirements.md',content:'## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Document setup.'},
|
|
43
|
+
{path:'design.md',content:'## 方案摘要\nUnreviewed synthetic design'},{path:'tasks.md',content:tasks}]}]});
|
|
44
|
+
const EXPECTED_V1={1:[],2:['tasks_invalid'],3:['tasks_invalid','task_scope_missing'],
|
|
45
|
+
4:['tasks_invalid','task_scope_missing','session_task_not_final']};
|
|
46
|
+
|
|
47
|
+
function project(t,{prior}){
|
|
48
|
+
const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-upgrade-prd-')));
|
|
49
|
+
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
50
|
+
for(const name of ['docs','mirror'])fs.mkdirSync(path.join(dir,name));
|
|
51
|
+
fs.writeFileSync(path.join(dir,'docs/input.md'),'Synthetic requirement');
|
|
52
|
+
if(prior!=='none'){
|
|
53
|
+
// 升级前已批准并做完的一个 feature;状态按 f73402d approveCmAiSpecs 的字段顺序手写,
|
|
54
|
+
// 无字段版本是语法 2 出现前的批准。
|
|
55
|
+
fs.mkdirSync(path.join(dir,'1.history'));
|
|
56
|
+
for(const [file,content] of Object.entries({'requirements.md':'## 功能需求\n1. [F-001] History\n- [x] [AC-001] Kept.',
|
|
57
|
+
'design.md':'## 方案摘要\nHistory','tasks.md':'- [x] T-001: Old work\n'}))
|
|
58
|
+
fs.writeFileSync(path.join(dir,'1.history',file),content,{mode:0o600});
|
|
59
|
+
const at='2026-10-01T00:00:00.000Z',specFiles=buildManifest(dir);
|
|
60
|
+
fs.writeFileSync(path.join(dir,'.cm-specs-status'),JSON.stringify({status:'approved',summaryDigest:'a'.repeat(64),at,
|
|
61
|
+
features:['1.history'],specFiles,testCases:[],approval:{response:'开始',at},...(prior==='grammar2'?{taskGrammar:2}:{})})+'\n');
|
|
62
|
+
}
|
|
63
|
+
return dir;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 升级前会话存档:会话没有 taskGrammar/selfCheckRules,在途的 plan 操作已发出生成请求、
|
|
67
|
+
// 宿主随后中断(调用没有 result)。rules=null 是规则字段出现前的宿主写的。
|
|
68
|
+
async function legacySession(dir,{sessionId,rules,skillDir=path.join(root,'skills/cm-prd'),callId='0d2c7f5e-2b1a-4c3d-9e8f-7a6b5c4d3e2f'}){
|
|
69
|
+
const entry={skillDir,project:dir,specs:dir};let routeTurn=0,payload=null;
|
|
70
|
+
const analysis=createCmPrdAnalysis({input:entry,runtime:'codex',record:async({event})=>{if(event==='decision')routeTurn++;},
|
|
71
|
+
analyze:async()=>structuredClone(ANALYZED),
|
|
72
|
+
generate:async value=>{payload=JSON.parse(JSON.stringify(value));throw Object.assign(new Error('host stopped'),{code:'host_stopped'});}});
|
|
73
|
+
await analysis.advance('Analyze');
|
|
74
|
+
const checkpoint={analysis:analysis.checkpoint(),change:null,started:true,routeTurn,reviewState:null,summaryState:null,publishedSummary:false};
|
|
75
|
+
await assert.rejects(analysis.plan(PLAN.text),{code:'host_stopped'});
|
|
76
|
+
const call={callId,requestDigest:digest({kind:'prd_generate',payload}),kind:'prd_generate',payload};
|
|
77
|
+
const state={version:1,identity:{entry,runtime:'codex'},checkpoint,
|
|
78
|
+
active:{request:PLAN,before:checkpoint,calls:[call],...(rules===null?{}:{selfCheckRules:rules})},segments:SEGMENTS};
|
|
79
|
+
if(sessionId!==undefined){
|
|
80
|
+
for(const relative of ['.reviews','.reviews/prd-sessions',`.reviews/prd-sessions/${sessionId}`])
|
|
81
|
+
fs.mkdirSync(path.join(dir,relative),{mode:0o700,recursive:true});
|
|
82
|
+
fs.writeFileSync(path.join(dir,'.reviews/prd-sessions',sessionId,'state.json'),JSON.stringify(state),{mode:0o600});
|
|
83
|
+
}
|
|
84
|
+
return {state,call};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function host(dir,sessionId,onRequest){
|
|
88
|
+
const child=spawn(process.execPath,[path.join(root,'scripts/cm-prd-host.mjs'),'serve','--skill-dir',path.join(root,'skills/cm-prd'),
|
|
89
|
+
'--project',dir,'--specs',dir,'--runtime','codex','--allow-log-write','--allow-review-write','--allow-disposition-write',
|
|
90
|
+
'--allow-spec-write','--host-context','author-context','--session',sessionId],
|
|
91
|
+
{env:{...process.env,CM_WORKFLOW_LOG_HOME:path.join(dir,'mirror')},stdio:['pipe','pipe','pipe']});
|
|
92
|
+
let stderr='',bridge=null,readyResolve;const waiting=new Map(),ready=new Promise(resolve=>{readyResolve=resolve;});
|
|
93
|
+
child.stderr.on('data',chunk=>{stderr+=chunk;});
|
|
94
|
+
const closed=once(child,'close'),lines=createInterface({input:child.stdout});
|
|
95
|
+
const write=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
96
|
+
const loop=(async()=>{for await(const line of lines){
|
|
97
|
+
const message=JSON.parse(line);
|
|
98
|
+
if(message.type==='host_ready'){bridge=message.sessionId;readyResolve();}
|
|
99
|
+
else if(message.type==='host_request')write({type:'host_result',sessionId:bridge,callId:message.callId,
|
|
100
|
+
requestDigest:message.requestDigest,result:await onRequest(message)});
|
|
101
|
+
else if(Object.hasOwn(message,'requestId')){const resolve=waiting.get(message.requestId);waiting.delete(message.requestId);resolve(message);}
|
|
102
|
+
}})();
|
|
103
|
+
return {
|
|
104
|
+
async send(request){await ready;const answer=new Promise(resolve=>waiting.set(request.requestId,resolve));write(request);
|
|
105
|
+
const message=await answer;assert.equal(message.error,undefined,`${request.requestId}: ${JSON.stringify(message.error)} ${stderr}`);return message.result;},
|
|
106
|
+
async close(){await ready;write({type:'host_close',sessionId:bridge});const [code]=await closed;await loop;assert.equal(code,0,stderr);},
|
|
107
|
+
kill(){child.kill();},
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const sessionFile=(dir,sessionId)=>path.join(dir,'.reviews/prd-sessions',sessionId,'state.json');
|
|
112
|
+
const readState=(dir,sessionId)=>JSON.parse(fs.readFileSync(sessionFile(dir,sessionId),'utf8'));
|
|
113
|
+
const noBinding=state=>!Object.hasOwn(state,'taskGrammar')&&!Object.hasOwn(state,'selfCheckRules');
|
|
114
|
+
const codes=report=>report.findings.map(item=>item.code);
|
|
115
|
+
|
|
116
|
+
// rules:在途操作登记的规则(null=无字段,按规则 1);prior:发布前 .cm-specs-status 的样子。
|
|
117
|
+
for(const [rules,prior] of [[null,'none'],[1,'grammar2'],[2,'legacy'],[3,'none']])
|
|
118
|
+
test(`升级前会话(在途操作规则 ${rules??'无字段'},已有状态 ${prior})恢复→新操作→发布→批准`,{timeout:TIMEOUT},async t=>{
|
|
119
|
+
const dir=project(t,{prior}),sessionId=`prd-legacy-${rules??'none'}`,applied=rules??1;
|
|
120
|
+
const {call}=await legacySession(dir,{sessionId,rules});
|
|
121
|
+
const feature=prior==='none'?'1.guide':'2.guide';
|
|
122
|
+
// 新操作期间(请求已发出、结果未回)读存档:规则来自会话的旧字面量 3,会话本身不被改写。
|
|
123
|
+
const observed=[];
|
|
124
|
+
const watch=()=>{const state=readState(dir,sessionId);observed.push(state.active?.selfCheckRules);
|
|
125
|
+
assert.ok(noBinding(state),'升级前的会话不补写版本字段');};
|
|
126
|
+
let checks=0,v1Digest=null;
|
|
127
|
+
const session=host(dir,sessionId,async message=>{
|
|
128
|
+
const {kind,payload}=message;
|
|
129
|
+
if(kind==='prd_generate'){watch();return reply(TASKS_V2);}
|
|
130
|
+
if(kind==='prd_self_check'){watch();checks++;const draft=payload.draft;
|
|
131
|
+
// 第一次只为规则 1 的旧回答(它机械自检通过)报一个上下文失败,促成一次新的生成操作。
|
|
132
|
+
return {draftDigest:draft.draftDigest,features:draft.features.map(item=>({directory:item.directory,
|
|
133
|
+
checks:draft.mechanicalSelfCheck.pending.map((id,index)=>({id,status:draft.draftDigest===v1Digest&&index===0?'failed':'passed',
|
|
134
|
+
evidence:['Synthetic context check']}))}))};}
|
|
135
|
+
if(kind==='prd_review')return {reviewer:'codex-subagent',contextId:'reviewer-context',independent:true,at:'2026-10-27T00:00:00.000Z',
|
|
136
|
+
result:{verdict:'changes_requested',packageDigest:payload.package.packageDigest,examinedPaths:payload.examinedPaths,
|
|
137
|
+
findings:[{id:'R1',severity:'P2',path:`${feature}/design.md`,message:'Clarify design',evidence:'Synthetic finding'}],summary:'Synthetic review'}};
|
|
138
|
+
if(kind==='prd_correct')return {documents:payload.documents.map(item=>({path:item.path,
|
|
139
|
+
content:item.path===`${feature}/design.md`?'## 方案摘要\nCorrected synthetic design':item.content})),
|
|
140
|
+
decisions:[{id:'R1',status:'applied',evidence:['Synthetic clarification'],changedPaths:[`${feature}/design.md`]}]};
|
|
141
|
+
if(kind==='prd_summary')return {evidenceDigest:payload.evidenceDigest,deliveryForm:'Documentation',estimatedTime:'Human review required',
|
|
142
|
+
openQuestions:'None',risks:'Synthetic responses',contextScope:'Targeted',platformReadiness:'Not applicable',uiBaseline:'None',
|
|
143
|
+
designRisk:[{feature,signals:{greenfieldAdr:false,architectureOrDataFlow:false,newRuntimeDependencyOrToolchain:false,
|
|
144
|
+
publicContractDataOrSecurity:false,fiveOrMoreFunctions:false},evidence:['Synthetic documentation-only fixture']}]};
|
|
145
|
+
throw new Error(`unexpected host request ${kind}`);
|
|
146
|
+
});
|
|
147
|
+
try{
|
|
148
|
+
// 1. 恢复在途操作:消费原生成请求的结果,按它自己登记的规则重放。
|
|
149
|
+
let status=await session.send({requestId:'resume',operation:'resume',resolution:{callId:call.callId,requestDigest:call.requestDigest,
|
|
150
|
+
result:reply(TASKS_V1),evidence:'Planner reply delivered before the host stopped'}});
|
|
151
|
+
let state=readState(dir,sessionId);
|
|
152
|
+
assert.ok(noBinding(state));assert.equal(state.active,null);
|
|
153
|
+
const draft=state.checkpoint.analysis.draft,report=draft.mechanicalSelfCheck;
|
|
154
|
+
assert.deepEqual(codes(report),EXPECTED_V1[applied],`在途操作沿用规则 ${applied}`);
|
|
155
|
+
assert.deepEqual(report,checkPrdDraftMechanics(draft,{rules:applied}));
|
|
156
|
+
assert.ok(matchesPrdDraftMechanics(draft,report),'历史报告摘要仍匹配');
|
|
157
|
+
assert.equal(status.stage,applied===1?'draft_ready':'draft_self_check_failed');
|
|
158
|
+
v1Digest=draft.draftDigest;
|
|
159
|
+
// 2. 之后每个新操作都按会话固定的规则 3;修正稿在规则 4 下会失败,在这里通过。
|
|
160
|
+
for(let guard=0;status.stage!=='self_check_reported_passed';guard++){
|
|
161
|
+
assert.ok(guard<4,status.stage);
|
|
162
|
+
status=await session.send(status.stage==='draft_ready'?{requestId:`verify-${guard}`,operation:'advance',text:'Self-check'}
|
|
163
|
+
:{requestId:`fix-${guard}`,operation:'advance',text:'Fix reported findings'});
|
|
164
|
+
}
|
|
165
|
+
state=readState(dir,sessionId);
|
|
166
|
+
const fixed=state.checkpoint.analysis.draft;
|
|
167
|
+
assert.deepEqual(codes(fixed.mechanicalSelfCheck),[]);
|
|
168
|
+
assert.deepEqual(codes(checkPrdDraftMechanics(fixed,{rules:4})),['session_task_not_final'],'规则 4 会拒绝修正稿');
|
|
169
|
+
assert.ok(observed.length>=2&&observed.every(value=>value===3),`新操作登记规则 3:${observed}`);
|
|
170
|
+
// 3. 保存:规则 3 的保存写旧格式的范围记录,后续重查不按语法 3 读。
|
|
171
|
+
const saved=await session.send({requestId:'save',operation:'save_draft'});
|
|
172
|
+
assert.equal(saved.status,'draft_saved');
|
|
173
|
+
const slug=feature.replace(/^\d+\./,'');
|
|
174
|
+
assert.equal(fs.readFileSync(path.join(dir,`.reviews/prd-${slug}-task-scope.json`),'utf8'),
|
|
175
|
+
JSON.stringify({version:1,enforced:true,exempt:[]})+'\n');
|
|
176
|
+
assert.equal(fs.readFileSync(path.join(dir,feature,'tasks.md'),'utf8'),TASKS_V2);
|
|
177
|
+
// 4. 拆分审查、修正、处置、汇总(各处重查都在会话规则下通过)。
|
|
178
|
+
await session.send({requestId:'package',operation:'final_review_package',stage:'split',feature});
|
|
179
|
+
const reviewed=await session.send({requestId:'review',operation:'final_review',stage:'split',feature,mode:'independent'});
|
|
180
|
+
assert.equal(reviewed.reviewState.status,'review_recorded');
|
|
181
|
+
await session.send({requestId:'findings',operation:'review_findings',stage:'split',feature});
|
|
182
|
+
assert.equal((await session.send({requestId:'correct',operation:'correct_findings',stage:'split',feature})).status,'correction_saved');
|
|
183
|
+
const corrected=await session.send({requestId:'resume-correction',operation:'resume_correction',stage:'split',feature});
|
|
184
|
+
const disposed=await session.send({requestId:'disposition',operation:'review_disposition',stage:'split',feature,
|
|
185
|
+
packageDigest:corrected.packageDigest,decisions:corrected.decisions,artifacts:corrected.artifacts});
|
|
186
|
+
assert.equal(disposed.status,'disposition_recorded');
|
|
187
|
+
const summary=await session.send({requestId:'summary',operation:'prepare_summary'});
|
|
188
|
+
assert.equal(summary.readyForAwaitingReview,true,JSON.stringify(summary.blockers));
|
|
189
|
+
// 5. 发布:首次发布写会话绑定的语法 2;已有状态沿用它的语法(旧版无字段的保持无字段)。
|
|
190
|
+
const published=await session.send({requestId:'publish',operation:'publish_summary',summaryDigest:summary.summaryDigest});
|
|
191
|
+
assert.equal(published.status,'awaiting_review');
|
|
192
|
+
const awaiting=JSON.parse(fs.readFileSync(path.join(dir,'.cm-specs-status'),'utf8'));
|
|
193
|
+
assert.equal(awaiting.status,'awaiting_review');
|
|
194
|
+
if(prior==='legacy')assert.equal(Object.hasOwn(awaiting,'taskGrammar'),false,'无字段的旧状态保持无字段');
|
|
195
|
+
else assert.equal(awaiting.taskGrammar,2);
|
|
196
|
+
assert.ok(noBinding(readState(dir,sessionId)));
|
|
197
|
+
}finally{await session.close().catch(()=>session.kill());}
|
|
198
|
+
// 6. 批准:沿用待审状态携带的语法,没有携带的写 2,从不升成 3。
|
|
199
|
+
const approve=spawnSync(process.execPath,[path.join(root,'scripts/cm-ai-admission.mjs'),'--specs-dir',dir,'--code-project',dir,
|
|
200
|
+
'--approve','--approval-response','开始'],{encoding:'utf8',env:process.env});
|
|
201
|
+
const approved=JSON.parse(fs.readFileSync(path.join(dir,'.cm-specs-status'),'utf8'));
|
|
202
|
+
assert.equal(approved.status,'approved',approve.stdout+approve.stderr);
|
|
203
|
+
assert.equal(approved.taskGrammar,2);
|
|
204
|
+
assert.deepEqual(approved.features,prior==='none'?['1.guide']:['1.history','2.guide']);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// 手写夹具与升级前宿主真实写出的存档逐字节一致(只在本地有 f73402d 时可核对)。
|
|
208
|
+
const oldAvailable=spawnSync('git',['-C',root,'cat-file','-e',`${UPGRADE_BASE}^{commit}`]).status===0;
|
|
209
|
+
test('手写的升级前会话存档与 f73402d 宿主真实写出的逐字节一致',{timeout:TIMEOUT,
|
|
210
|
+
skip:oldAvailable?false:`本地没有 ${UPGRADE_BASE}(浅克隆),跳过真实旧宿主比对`},async t=>{
|
|
211
|
+
const old=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-upgrade-old-')));
|
|
212
|
+
t.after(()=>fs.rmSync(old,{recursive:true,force:true}));
|
|
213
|
+
const archive=spawnSync('git',['-C',root,'archive','--format=tar',UPGRADE_BASE],{maxBuffer:256*1024*1024});
|
|
214
|
+
assert.equal(archive.status,0,String(archive.stderr));
|
|
215
|
+
assert.equal(spawnSync('tar',['-x','-C',old],{input:archive.stdout}).status,0);
|
|
216
|
+
const dir=project(t,{prior:'none'}),skillDir=path.join(old,'skills/cm-prd');
|
|
217
|
+
const child=spawn(process.execPath,[path.join(old,'scripts/cm-prd-host.mjs'),'serve','--skill-dir',skillDir,'--project',dir,'--specs',dir,
|
|
218
|
+
'--runtime','codex','--allow-log-write'],{env:{...process.env,CM_WORKFLOW_LOG_HOME:path.join(dir,'mirror')},stdio:['pipe','pipe','pipe']});
|
|
219
|
+
const closed=once(child,'close'),lines=createInterface({input:child.stdout});let stderr='',bridge;
|
|
220
|
+
child.stderr.on('data',chunk=>{stderr+=chunk;});
|
|
221
|
+
const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
222
|
+
for await(const line of lines){
|
|
223
|
+
const message=JSON.parse(line);
|
|
224
|
+
if(message.type==='host_ready'){bridge=message.sessionId;send({requestId:'turn',operation:'start',text:'Analyze'});}
|
|
225
|
+
else if(message.type==='host_request'&&message.kind==='prd_analyze')send({type:'host_result',sessionId:bridge,callId:message.callId,
|
|
226
|
+
requestDigest:message.requestDigest,result:ANALYZED});
|
|
227
|
+
else if(message.requestId==='turn'){assert.equal(message.result?.stage,'analysis_ready',stderr);send(PLAN);}
|
|
228
|
+
// 生成请求发出后宿主中断:升级前在途操作的真实样子。
|
|
229
|
+
else if(message.type==='host_request'&&message.kind==='prd_generate'){child.kill('SIGKILL');break;}
|
|
230
|
+
}
|
|
231
|
+
lines.close();await closed;
|
|
232
|
+
const [sessionId]=fs.readdirSync(path.join(dir,'.reviews/prd-sessions'));
|
|
233
|
+
const real=fs.readFileSync(sessionFile(dir,sessionId),'utf8');
|
|
234
|
+
const recorded=JSON.parse(real);
|
|
235
|
+
assert.equal(recorded.active.selfCheckRules,3,'f73402d 的宿主登记规则 3');
|
|
236
|
+
// 调用编号是会话自己随机生成的,只有它取自真实存档。
|
|
237
|
+
const {state}=await legacySession(dir,{rules:3,skillDir,callId:recorded.active.calls[0].callId});
|
|
238
|
+
assert.equal(JSON.stringify(state),real);
|
|
239
|
+
});
|
|
@@ -284,7 +284,7 @@ function requireString(value,location,choices=null){
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
function validateRaw(value){
|
|
287
|
-
const root=requireMapping(value,'config');rejectUnknown(root,new Set(['version','project','runtimes','roles','policies']),'config');
|
|
287
|
+
const root=requireMapping(value,'config');rejectUnknown(root,new Set(['version','project','runtimes','roles','policies','parallel']),'config');
|
|
288
288
|
if(typeof root.version!=='bigint'||root.version!==1n)throw new ConfigError('config.version must equal integer 1');
|
|
289
289
|
if(Object.hasOwn(root,'project')){
|
|
290
290
|
const project=requireMapping(root.project,'config.project');rejectUnknown(project,new Set(['type','workflow']),'config.project');
|
|
@@ -322,6 +322,15 @@ function validateRaw(value){
|
|
|
322
322
|
if(Object.hasOwn(policies,'auto_fix'))requireString(policies.auto_fix,'config.policies.auto_fix',AUTO_FIX_POLICIES);
|
|
323
323
|
if(Object.hasOwn(policies,'delivery'))requireString(policies.delivery,'config.policies.delivery',DELIVERY_MODES);
|
|
324
324
|
}
|
|
325
|
+
// /cm-ai worktree parallelism (runtime/js/cm-ai/batch-plan.mjs). Not in the
|
|
326
|
+
// defaults: a project that does not set it keeps its effective config unchanged.
|
|
327
|
+
if(Object.hasOwn(root,'parallel')){
|
|
328
|
+
const parallel=requireMapping(root.parallel,'config.parallel');rejectUnknown(parallel,new Set(['enabled','max','worktree_all']),'config.parallel');
|
|
329
|
+
if(Object.hasOwn(parallel,'enabled')&&typeof parallel.enabled!=='boolean')throw new ConfigError('config.parallel.enabled must be boolean');
|
|
330
|
+
if(Object.hasOwn(parallel,'worktree_all')&&typeof parallel.worktree_all!=='boolean')throw new ConfigError('config.parallel.worktree_all must be boolean');
|
|
331
|
+
if(Object.hasOwn(parallel,'max')&&!((typeof parallel.max==='bigint'&¶llel.max>=1n&¶llel.max<=4n)
|
|
332
|
+
||(Number.isInteger(parallel.max)&¶llel.max>=1&¶llel.max<=4)))throw new ConfigError('config.parallel.max must be an integer from 1 to 4');
|
|
333
|
+
}
|
|
325
334
|
}
|
|
326
335
|
|
|
327
336
|
function validateEffective(config){
|
|
@@ -493,7 +502,8 @@ function loadConfigUsing(input,userDefaults){
|
|
|
493
502
|
if(SECRET_VALUE.test(text))throw new ConfigError('configuration contains a secret-like value');
|
|
494
503
|
try{
|
|
495
504
|
const raw=parseDocument(configPath,text);walkForSecrets(raw);validateRaw(raw);
|
|
496
|
-
const normalizedRaw={...raw,version:Number(raw.version)
|
|
505
|
+
const normalizedRaw={...raw,version:Number(raw.version),
|
|
506
|
+
...(raw.parallel&&Object.hasOwn(raw.parallel,'max')?{parallel:{...raw.parallel,max:Number(raw.parallel.max)}}:{})};
|
|
497
507
|
const projectDeclared=raw.runtimes?.available!==undefined;
|
|
498
508
|
const user=projectDeclared?null:userDefaults();
|
|
499
509
|
const defaults=user?deepMerge(DEFAULT_CONFIG,runtimePreset(user.preset)):DEFAULT_CONFIG;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Synthetic CLI protocol fixture. Exercises the real MCP server, never a model.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import {spawn} from 'node:child_process';
|
|
4
|
+
import {createInterface} from 'node:readline';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
const args=process.argv.slice(2),pick=key=>args[args.indexOf(key)+1];
|
|
7
|
+
assert(args.includes('--restricted'));assert(!args.includes('--safe-mode'));assert.equal(pick('--tools'),'');
|
|
8
|
+
const config=JSON.parse(pick('--mcp-config')).mcpServers.cm_review;
|
|
9
|
+
let prompt='';for await(const chunk of process.stdin)prompt+=chunk;
|
|
10
|
+
assert(!prompt.includes('Use no tools and do not execute code.'));
|
|
11
|
+
const probe=process.env.ANTHROPIC_API_KEY==='cm-synthetic-local-probe';
|
|
12
|
+
const data=probe?null:JSON.parse(prompt.split('<cm-review-data-json>\n')[1].split('\n')[0]);
|
|
13
|
+
const server=spawn(config.command,config.args,{stdio:['pipe','pipe','pipe']});server.stderr.resume();
|
|
14
|
+
const pending=new Map();let seq=0;
|
|
15
|
+
createInterface({input:server.stdout}).on('line',line=>{const value=JSON.parse(line);pending.get(value.id)?.(value.result);pending.delete(value.id);});
|
|
16
|
+
const rpc=(method,params={})=>new Promise(resolve=>{const id=++seq;pending.set(id,resolve);server.stdin.write(JSON.stringify({jsonrpc:'2.0',id,method,params})+'\n');});
|
|
17
|
+
const session_id='synthetic-isolated-review',emit=value=>process.stdout.write(JSON.stringify({...value,session_id})+'\n');
|
|
18
|
+
try{
|
|
19
|
+
await rpc('initialize',{protocolVersion:'2024-11-05',capabilities:{},clientInfo:{name:'fixture',version:'1'}});
|
|
20
|
+
const catalog=await rpc('tools/list');assert.deepEqual(catalog.tools.map(t=>t.name),['read_file','run_check','mutate_check']);
|
|
21
|
+
assert.deepEqual(catalog.tools[1].inputSchema.properties.id.enum,['unit']);
|
|
22
|
+
assert.deepEqual(catalog.tools[2].inputSchema.properties.checkId.enum,['unit']);
|
|
23
|
+
emit({type:'system',subtype:'init'});
|
|
24
|
+
if(probe){
|
|
25
|
+
const http=await import('node:http');
|
|
26
|
+
await new Promise((resolve,reject)=>{
|
|
27
|
+
const req=http.request(new URL('/v1/messages',process.env.ANTHROPIC_BASE_URL),{method:'POST',headers:{'x-api-key':'cm-synthetic-local-probe','content-type':'application/json'}},res=>{res.resume();res.on('end',resolve);});req.on('error',reject);
|
|
28
|
+
req.end(JSON.stringify({model:pick('--model'),messages:[{role:'user',content:'Synthetic local probe'}],tools:[{name:'StructuredOutput'},...catalog.tools.map(t=>({name:'mcp__cm_review__'+t.name}))]}));
|
|
29
|
+
});
|
|
30
|
+
}else{
|
|
31
|
+
|
|
32
|
+
const call=async(name,input)=>{
|
|
33
|
+
const id='tool-'+seq;emit({type:'assistant',parent_tool_use_id:null,message:{role:'assistant',content:[{type:'tool_use',id,name:'mcp__cm_review__'+name,input}]}});
|
|
34
|
+
const result=await rpc('tools/call',{name,arguments:input});
|
|
35
|
+
emit({type:'user',message:{role:'user',content:[{type:'tool_result',tool_use_id:id,is_error:result.isError===true,content:JSON.stringify(result.content)}]}});
|
|
36
|
+
assert(!result.isError,JSON.stringify(result));return JSON.parse(result.content[0].text);
|
|
37
|
+
};
|
|
38
|
+
const file=await call('read_file',{path:'value.mjs'});assert(file.content.includes('value=1'));
|
|
39
|
+
const mode=process.env.CM_VERIFICATION_FIXTURE_MODE??'valid';
|
|
40
|
+
assert.equal((await call('run_check',{id:'unit'})).exitCode,mode==='failed-check'?1:0);
|
|
41
|
+
if(mode==='valid')assert.equal((await call('mutate_check',{path:'value.mjs',find:'value=1',replace:'value=2',checkId:'unit'})).killed,true);
|
|
42
|
+
emit({type:'result',subtype:'success',is_error:false,num_turns:4,structured_output:{verdict:'approved',packageDigest:data.reviewPackage.packageDigest,examinedPaths:data.examinedPaths,findings:[],summary:'Synthetic CLI transport and actual isolated commands; not a model review.'}});
|
|
43
|
+
}
|
|
44
|
+
}finally{server.stdin.end();await new Promise(resolve=>server.once('close',resolve));}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Fixture-only metadata, following live-evidence-driver's bounded diagnostics.
|
|
2
|
+
// Never retain request IDs, paths, payloads, command lines or stderr contents.
|
|
3
|
+
const operations=new Set(['advance','start','status','fix_status','cancel','resume','host_close','host_result','eof']);
|
|
4
|
+
const kinds=new Set(['develop','check','review','complete','qa_assess','qa_browser','documentation_sync','documentation_inspect']);
|
|
5
|
+
const states=new Set(['idle','developing','pending_review','reviewing','fixture_completed','blocked','unknown','cancelled',
|
|
6
|
+
'requirements_analysis','awaiting_user','status_only']);
|
|
7
|
+
const codes=new Set(['develop_answer_missing','host_busy','execution_error','host_launch_failed','invalid_arguments']);
|
|
8
|
+
const signals=new Set(['SIGTERM','SIGKILL','SIGINT','SIGABRT','SIGSEGV','SIGHUP','SIGPIPE']);
|
|
9
|
+
const allowed=(set,value)=>set.has(value)?value:value==null?null:'other';
|
|
10
|
+
|
|
11
|
+
export function hostDiagnostic(child,{timeoutMs=null,now=()=>performance.now()}={}){
|
|
12
|
+
const started=now(),events=[];
|
|
13
|
+
let stdoutBytes=0,stderrBytes=0,exitCode=null,signal=null,closed=false;
|
|
14
|
+
let lastOperation=null,lastKind=null,lastState=null,lastCode=null,eventCount=0;
|
|
15
|
+
const elapsed=()=>Math.max(0,Math.round(now()-started));
|
|
16
|
+
const mark=(direction,row={})=>{
|
|
17
|
+
const operation=allowed(operations,row.operation??row.type);
|
|
18
|
+
const kind=allowed(kinds,row.kind),state=allowed(states,row.result?.state??row.result?.stage);
|
|
19
|
+
const code=allowed(codes,row.result?.code??row.error?.code);
|
|
20
|
+
if(direction==='send'&&operation)lastOperation=operation;
|
|
21
|
+
if(kind)lastKind=kind;if(state)lastState=state;if(code)lastCode=code;
|
|
22
|
+
events.push({n:++eventCount,elapsedMs:elapsed(),direction,operation,kind,state,code});
|
|
23
|
+
if(events.length>32)events.shift();
|
|
24
|
+
};
|
|
25
|
+
child.stdout?.on('data',chunk=>{stdoutBytes+=Buffer.byteLength(chunk);});
|
|
26
|
+
child.stderr?.on('data',chunk=>{stderrBytes+=Buffer.byteLength(chunk);});
|
|
27
|
+
child.once('close',(code,value)=>{closed=true;exitCode=Number.isInteger(code)?code:null;signal=allowed(signals,value);});
|
|
28
|
+
const snapshot=()=>({pid:Number.isInteger(child.pid)?child.pid:null,timeoutMs,elapsedMs:elapsed(),
|
|
29
|
+
closed,exitCode,signal,stdoutBytes,stderrBytes,eventCount,lastOperation,lastKind,lastState,lastCode,
|
|
30
|
+
events:events.map(event=>({...event}))});
|
|
31
|
+
return {send:row=>mark('send',row),receive:row=>mark('receive',row),snapshot,
|
|
32
|
+
attach:error=>Object.assign(error,{diagnostic:snapshot()})};
|
|
33
|
+
}
|