@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
package/scripts/cm-patrol.mjs
CHANGED
|
@@ -30,7 +30,8 @@ function readEntry(file){
|
|
|
30
30
|
if(!Number.isSafeInteger(value.pid)||value.pid<=0)return null;
|
|
31
31
|
const at=Date.parse(value.at);if(!Number.isFinite(at))return null;
|
|
32
32
|
return {file,pid:value.pid,at,sessionKey:text(value.sessionKey),workflow:text(value.workflow)??'cm',project:text(value.project),
|
|
33
|
-
runId:text(value.runId),task:text(value.task),stage:text(value.stage),operation:text(value.operation)
|
|
33
|
+
runId:text(value.runId),task:text(value.task),stage:text(value.stage),operation:text(value.operation),
|
|
34
|
+
sessionTitle:text(value.sessionTitle)};
|
|
34
35
|
}catch{return null;}
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -70,6 +71,8 @@ export function patrol({env=process.env,now=Date.now(),report=false}={}){
|
|
|
70
71
|
const sent=notify({key:`dead|${dead.map(entry=>entry.sessionKey??entry.file).sort().join(',')}`,event:'dead',
|
|
71
72
|
workflow:workflows.size===1?[...workflows][0]:'cm',project:projects.size===1?[...projects][0]:null,
|
|
72
73
|
runId:dead.length===1?dead[0].runId:null,task:dead.length===1?dead[0].task:null,
|
|
74
|
+
// The dead hosts' own sessions, never the session that runs this patrol.
|
|
75
|
+
sessionTitle:[...new Set(dead.map(entry=>entry.sessionTitle).filter(Boolean))].join('、')||null,
|
|
73
76
|
stage:`${dead.length} 个宿主进程已不在`,code:'host_process_gone',
|
|
74
77
|
nextAction:`${listed.join(';')}。请回到会话用 status 核对运行状态,需要时按恢复说明接手`},{env,now});
|
|
75
78
|
if(sent.sent||sent.reason==='duplicate')for(const entry of dead){try{fs.unlinkSync(entry.file);}catch{}}
|
|
@@ -24,7 +24,8 @@ function home(t,{withConfig=true}={}){
|
|
|
24
24
|
process.stdin.on('end',()=>{fs.appendFileSync(${JSON.stringify(sent)},JSON.stringify({title:process.env.CM_NOTIFY_TITLE,
|
|
25
25
|
body:process.env.CM_NOTIFY_BODY,stdin:JSON.parse(input)})+'\\n');});`);
|
|
26
26
|
if(withConfig)fs.writeFileSync(path.join(dir,'notify.json'),JSON.stringify({version:1,command:[process.execPath,script]}));
|
|
27
|
-
|
|
27
|
+
// Never read the real Claude Code session of whoever runs the tests.
|
|
28
|
+
const env={...process.env,CM_WORKFLOW_HOME:dir};delete env.CLAUDE_CODE_SESSION_ID;delete env.CM_NOTIFY_CLAUDE_PROJECTS;
|
|
28
29
|
const rows=()=>fs.existsSync(sent)?fs.readFileSync(sent,'utf8').trim().split('\n').map(line=>JSON.parse(line)):[];
|
|
29
30
|
const until=async(check,ms=8000)=>{const end=Date.now()+ms;while(!check()&&Date.now()<end)await new Promise(r=>setTimeout(r,25));return check();};
|
|
30
31
|
const registry=()=>fs.existsSync(hostRegistryDir(env))?fs.readdirSync(hostRegistryDir(env)).filter(name=>name.endsWith('.json')).sort():[];
|
|
@@ -98,7 +99,7 @@ test('patrol: dead hosts are merged into one notice and their entries removed; l
|
|
|
98
99
|
assert.equal(first.notice,'sent');assert.equal(first.dead,2);
|
|
99
100
|
assert(await h.until(()=>h.rows().length===1));
|
|
100
101
|
const [row]=h.rows();
|
|
101
|
-
assert.equal(row.title,'CM
|
|
102
|
+
assert.equal(row.title,'CM 宿主已退出未收尾 · work/demo-app');assert.equal(row.stdin.subtitle,'cm');
|
|
102
103
|
assert.equal(row.stdin.code,'host_process_gone');assert.equal(row.stdin.stage,'2 个宿主进程已不在');
|
|
103
104
|
assert.match(row.body,/cm-ai run-1 T-003 awaiting_review 最后动静 07:45Z;cm-fix fix-2 repair_required 最后动静 07:55Z/);
|
|
104
105
|
assert.doesNotMatch(row.body+JSON.stringify(row.stdin),/srv|demo-app\//,'no paths in body or payload');
|
|
@@ -113,17 +114,34 @@ test('patrol: a single dead host names its run and workflow; rate-limited or off
|
|
|
113
114
|
h.write(KEYS[1],{pid:gone,workflow:'cm-prd',runId:'prd-7',task:null,stage:'awaiting_user'});
|
|
114
115
|
const state={version:1,keys:{},sends:Array.from({length:4},()=>NOW-1000)};
|
|
115
116
|
fs.writeFileSync(path.join(h.dir,'notify-state.json'),JSON.stringify(state));
|
|
116
|
-
assert.equal(patrol({env:h.env,now:NOW}).notice,'
|
|
117
|
+
assert.equal(patrol({env:h.env,now:NOW}).notice,'rate_window');
|
|
117
118
|
assert.deepEqual(h.registry(),[`${KEYS[1]}.json`],'kept for the next pass');
|
|
118
|
-
assert.equal(patrol({env:h.env,now:NOW+
|
|
119
|
+
assert.equal(patrol({env:h.env,now:NOW+10*60000}).notice,'sent');
|
|
119
120
|
assert(await h.until(()=>h.rows().length===1));
|
|
120
|
-
assert.equal(h.rows()[0].title,'CM
|
|
121
|
+
assert.equal(h.rows()[0].title,'CM 宿主已退出未收尾 · work/demo-app');
|
|
121
122
|
assert.equal(h.rows()[0].stdin.runId,'prd-7');assert.equal(h.rows()[0].stdin.stage,'1 个宿主进程已不在');
|
|
122
123
|
assert.deepEqual(h.registry(),[]);
|
|
123
124
|
const off=home(t,{withConfig:false});off.write(KEYS[1],{pid:gone});
|
|
124
125
|
assert.equal(patrol({env:off.env,now:NOW}).notice,'off');assert.deepEqual(off.registry(),[`${KEYS[1]}.json`]);
|
|
125
126
|
});
|
|
126
127
|
|
|
128
|
+
test('patrol names the dead hosts own sessions, never the session that runs the patrol',async t=>{
|
|
129
|
+
const h=home(t),gone=gonePid(),projects=path.join(h.dir,'projects'),id='2e015f08-c743-427a-95fa-0e471a851593';
|
|
130
|
+
// The patrolling session has a title of its own; it must not appear.
|
|
131
|
+
fs.mkdirSync(path.join(projects,'p'),{recursive:true});
|
|
132
|
+
fs.writeFileSync(path.join(projects,'p',`${id}.jsonl`),JSON.stringify({type:'custom-title',customTitle:'正在巡检的会话'})+'\n');
|
|
133
|
+
const env={...h.env,CLAUDE_CODE_SESSION_ID:id,CM_NOTIFY_CLAUDE_PROJECTS:projects};
|
|
134
|
+
h.write(KEYS[1],{pid:gone,sessionTitle:'分析 skills 库'});
|
|
135
|
+
assert.equal(patrol({env,now:NOW}).notice,'sent');
|
|
136
|
+
assert(await h.until(()=>h.rows().length===1));
|
|
137
|
+
assert.equal(h.rows()[0].stdin.sessionTitle,'分析 skills 库');
|
|
138
|
+
// Without a recorded title nothing is guessed from the patrol's own session.
|
|
139
|
+
const other=home(t);other.write(KEYS[2],{pid:gone});
|
|
140
|
+
assert.equal(patrol({env:{...other.env,CLAUDE_CODE_SESSION_ID:id,CM_NOTIFY_CLAUDE_PROJECTS:projects},now:NOW}).notice,'sent');
|
|
141
|
+
assert(await other.until(()=>other.rows().length===1));
|
|
142
|
+
assert.equal(other.rows()[0].stdin.sessionTitle,undefined);
|
|
143
|
+
});
|
|
144
|
+
|
|
127
145
|
test('--report prints the summary and neither notifies nor removes anything',t=>{
|
|
128
146
|
const h=home(t),gone=gonePid(),now=Date.now();
|
|
129
147
|
// The CLI uses the real clock; this fixture must remain inside the unchanged TTL.
|
|
@@ -26,9 +26,9 @@ const version='\n| 日期 | 版本 | 说明 |\n| --- | --- | --- |\n| 2026-09-08
|
|
|
26
26
|
const docs=()=>[
|
|
27
27
|
{path:'requirements.md',content:'## 需求版本'+version+'\n## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Read guide\n'},
|
|
28
28
|
{path:'design.md',content:'## 设计版本'+version+'\n## 方案摘要\nExisting guide\n'},
|
|
29
|
-
{path:'tasks.md',content:'## 任务版本'+version+'\n- [x] T-001: Existing guide\n- [ ] T-002: Draft appendix\n'}];
|
|
29
|
+
{path:'tasks.md',content:'## 任务版本'+version+'\n- [x] T-001: Existing guide\n - 范围: `README.md`\n- [ ] T-002: Draft appendix\n - 范围: `README.md`\n'}];
|
|
30
30
|
const revised=()=>docs().map(doc=>({path:doc.path,content:doc.content.replace('| 2026-09-08 | v1 | original |','| 2026-09-08 | v1 | original |\n| 2026-09-08 | v2 | change |')
|
|
31
|
-
+(doc.path==='tasks.md'?'\n- [ ] T-003: [NEW] Add example\n':'\nUpdated example\n')}));
|
|
31
|
+
+(doc.path==='tasks.md'?'\n- [ ] T-003: [NEW] Add example\n - 范围: `README.md`\n':'\nUpdated example\n')}));
|
|
32
32
|
function fixture(t){const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-gaps-')));
|
|
33
33
|
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));fs.mkdirSync(path.join(dir,'docs'));fs.mkdirSync(path.join(dir,'mirror'));
|
|
34
34
|
fs.writeFileSync(path.join(dir,'docs/input.md'),'Synthetic guide');fs.mkdirSync(path.join(dir,'1.guide'));
|
|
@@ -7,9 +7,11 @@ import {spawn,spawnSync} from 'node:child_process';
|
|
|
7
7
|
import {once} from 'node:events';
|
|
8
8
|
import {createInterface} from 'node:readline';
|
|
9
9
|
import {fileURLToPath} from 'node:url';
|
|
10
|
+
import {semanticDigest} from './cm-spec-manifest.mjs';
|
|
10
11
|
import {inspectPrdChangeSnapshot,inspectPrdChangeProposal,applyPrdChange,assertPrdReviewsSettled} from '../runtime/js/cm-prd/change.mjs';
|
|
11
12
|
import {loadConfig} from './cm-workflow-config.mjs';
|
|
12
13
|
import {recordPrdReview} from './cm-prd-review-gate.mjs';
|
|
14
|
+
import {parseFeatureTaskText} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
13
15
|
|
|
14
16
|
// Keep runtime declarations and log mirrors independent of the invoking user's home.
|
|
15
17
|
const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-completion-home-'));
|
|
@@ -21,9 +23,9 @@ const version='\n| 日期 | 版本 | 说明 |\n| --- | --- | --- |\n| 2026-09-08
|
|
|
21
23
|
const docs=()=>[
|
|
22
24
|
{path:'requirements.md',content:'## 需求版本'+version+'\n## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Read guide\n'},
|
|
23
25
|
{path:'design.md',content:'## 设计版本'+version+'\n## 方案摘要\nExisting guide\n'},
|
|
24
|
-
{path:'tasks.md',content:'## 任务版本'+version+'\n- [x] T-001: Existing guide\n- [ ] T-002: Draft appendix\n'}];
|
|
26
|
+
{path:'tasks.md',content:'## 任务版本'+version+'\n- [x] T-001: Existing guide\n - 范围: `README.md`\n- [ ] T-002: Draft appendix\n - 范围: `README.md`\n'}];
|
|
25
27
|
const revised=()=>docs().map(doc=>({path:doc.path,content:doc.content.replace('| 2026-09-08 | v1 | original |','| 2026-09-08 | v1 | original |\n| 2026-09-08 | v2 | change |')
|
|
26
|
-
.replace('Existing guide\n','Existing guide\n')+(doc.path==='tasks.md'?'\n- [ ] T-003: [NEW] Add example\n':'\nUpdated example\n')}));
|
|
28
|
+
.replace('Existing guide\n','Existing guide\n')+(doc.path==='tasks.md'?'\n- [ ] T-003: [NEW] Add example\n - 范围: `README.md`\n':'\nUpdated example\n')}));
|
|
27
29
|
function fixture(t){const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-complete-')));
|
|
28
30
|
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));fs.mkdirSync(path.join(dir,'docs'));fs.mkdirSync(path.join(dir,'mirror'));
|
|
29
31
|
fs.writeFileSync(path.join(dir,'docs/input.md'),'Synthetic guide');fs.mkdirSync(path.join(dir,'1.guide'));
|
|
@@ -103,7 +105,7 @@ test('approved change retains revision history for the next real cm-prd change',
|
|
|
103
105
|
assert.doesNotThrow(()=>assertPrdReviewsSettled(dir,['1.guide'],{requireSplit:true}));
|
|
104
106
|
const nextDocs=revised().map(doc=>({path:doc.path,content:doc.content.replace('| 2026-09-08 | v2 | change |',
|
|
105
107
|
'| 2026-09-08 | v2 | change |\n| 2026-09-08 | v3 | another change |')+
|
|
106
|
-
(doc.path==='tasks.md'?'\n- [ ] T-004: [NEW] More examples\n':'\nMore detail\n')}));
|
|
108
|
+
(doc.path==='tasks.md'?'\n- [ ] T-004: [NEW] More examples\n - 范围: `README.md`\n':'\nMore detail\n')}));
|
|
107
109
|
const nextBefore=inspectPrdChangeSnapshot(dir);
|
|
108
110
|
const nextProposal=inspectPrdChangeProposal(nextBefore,{status:'draft',summary:'Another guide change',removed:[],features:[
|
|
109
111
|
{directory:'1.guide',documents:nextDocs,testCasesReason:'no_observable_behavior'}]},selected,config);
|
|
@@ -134,11 +136,18 @@ test('controlled inventory revision retains old review and archives removed feat
|
|
|
134
136
|
fs.writeFileSync(evidence,'---\nat: 2026-09-08T00:00:00Z\nreviewer: codex-subagent\nindependent: true\nscope:\n - 1.guide/tasks.md\n---\nSynthetic original review',{mode:0o600});
|
|
135
137
|
recordPrdReview({stage:'split',feature:'guide',evidence,receipt,disposition:'no_findings',finding_count:0,unresolved_count:0,
|
|
136
138
|
artifact:docs().map(doc=>path.join(dir,'1.guide',doc.path))});
|
|
139
|
+
// The approval covers 1.guide's tasks, so they may stay without scope in the change.
|
|
140
|
+
fs.writeFileSync(path.join(dir,'.cm-specs-status'),JSON.stringify({status:'approved',taskGrammar:2,features:['1.guide','2.obsolete'],
|
|
141
|
+
specFiles:[{path:'1.guide/tasks.md',sha256:semanticDigest(path.join(dir,'1.guide/tasks.md'))}]}),{mode:0o600});
|
|
137
142
|
const originalReview=fs.readFileSync(evidence),before=inspectPrdChangeSnapshot(dir),raw={status:'draft',summary:'Explicit inventory revision',removed:['2.obsolete'],features:[
|
|
138
143
|
{directory:'1.guide',documents:revised(),testCasesReason:'no_observable_behavior'},
|
|
139
144
|
{directory:'3.examples',documents:docs().map(doc=>({...doc,content:doc.content.replace('[x]','[ ]')})),testCasesReason:'no_observable_behavior'}]};
|
|
140
145
|
const selected=['1.guide','2.obsolete'],proposal=inspectPrdChangeProposal(before,raw,selected,loadConfig({projectRoot:dir}));
|
|
141
146
|
const result=applyPrdChange({specs:dir,before,proposal,selected});assert.deepEqual(result.features,['1.guide','3.examples']);
|
|
147
|
+
// Later re-checks of these files keep the scope rule; approved tasks stay exempt.
|
|
148
|
+
const record=name=>JSON.parse(fs.readFileSync(path.join(dir,`.reviews/prd-${name}-task-scope.json`),'utf8'));
|
|
149
|
+
assert.deepEqual(record('guide').exempt,parseFeatureTaskText(before.files['1.guide/tasks.md']).tasks.map(task=>task.id).sort());
|
|
150
|
+
assert.deepEqual(record('examples').exempt,[]);
|
|
142
151
|
assert.ok(fs.readFileSync(evidence).equals(originalReview));assert.equal(fs.existsSync(path.join(dir,'2.obsolete')),false);
|
|
143
152
|
assert.equal(fs.readFileSync(path.join(dir,`.reviews/prd-change-${proposal.proposalDigest}-removed/2.obsolete/asset.txt`),'utf8'),'original retained asset');
|
|
144
153
|
assert.equal(applyPrdChange({specs:dir,before,proposal,selected}).status,'awaiting_review');
|
|
@@ -146,11 +155,42 @@ test('controlled inventory revision retains old review and archives removed feat
|
|
|
146
155
|
assert.throws(()=>applyPrdChange({specs:dir,before,proposal,selected}),/conflict/);
|
|
147
156
|
assert.equal(fs.readFileSync(path.join(dir,'1.guide/design.md'),'utf8'),'User third version');
|
|
148
157
|
});
|
|
158
|
+
// A session's snapshot keeps its own version: one taken before scope records were
|
|
159
|
+
// bound still matches; a version-2 snapshot notices a changed record.
|
|
160
|
+
test('change snapshot binds scope records only from version 2; earlier snapshots still resume',t=>{
|
|
161
|
+
const dir=fixture(t),config=loadConfig({projectRoot:dir}),selected=['1.guide'];
|
|
162
|
+
fs.mkdirSync(path.join(dir,'.reviews'));const record=path.join(dir,'.reviews/prd-guide-task-scope.json');
|
|
163
|
+
fs.writeFileSync(record,JSON.stringify({version:1,enforced:true,exempt:[]})+'\n',{mode:0o600});
|
|
164
|
+
const current=inspectPrdChangeSnapshot(dir);assert.equal(current.snapshotVersion,2);assert.ok(current.scopeRecords['1.guide']);
|
|
165
|
+
const {snapshotVersion,scopeRecords,...legacy}=current;
|
|
166
|
+
const raw={status:'draft',summary:'Change',removed:[],features:[{directory:'1.guide',documents:revised(),testCasesReason:'no_observable_behavior'}]};
|
|
167
|
+
const fresh=inspectPrdChangeProposal(current,raw,selected,config);
|
|
168
|
+
fs.writeFileSync(record,JSON.stringify({version:1,enforced:true,exempt:['T-001']})+'\n',{mode:0o600});
|
|
169
|
+
assert.throws(()=>applyPrdChange({specs:dir,before:current,proposal:fresh,selected}),/prd_change_inputs_changed/);
|
|
170
|
+
// Unversioned with scopeRecords (bound only when a record existed): unchanged resumes, drift is refused.
|
|
171
|
+
const unversioned={...legacy,scopeRecords:{'1.guide':JSON.stringify({version:1,enforced:true,exempt:['T-001']})+'\n'}};
|
|
172
|
+
const middle=inspectPrdChangeProposal(unversioned,raw,selected,config);
|
|
173
|
+
fs.writeFileSync(record,JSON.stringify({version:1,enforced:true,exempt:[]})+'\n',{mode:0o600});
|
|
174
|
+
assert.throws(()=>applyPrdChange({specs:dir,before:unversioned,proposal:middle,selected}),/prd_change_inputs_changed/);
|
|
175
|
+
fs.writeFileSync(record,JSON.stringify({version:1,enforced:true,exempt:['T-001']})+'\n',{mode:0o600});
|
|
176
|
+
// Neither field: the oldest shape binds no record.
|
|
177
|
+
const old=inspectPrdChangeProposal(legacy,raw,selected,config);
|
|
178
|
+
assert.equal(applyPrdChange({specs:dir,before:legacy,proposal:old,selected}).status,'awaiting_review');
|
|
179
|
+
});
|
|
180
|
+
test('an unversioned snapshot with scopeRecords resumes while its records are unchanged',t=>{
|
|
181
|
+
const dir=fixture(t),config=loadConfig({projectRoot:dir}),selected=['1.guide'];
|
|
182
|
+
fs.mkdirSync(path.join(dir,'.reviews'));
|
|
183
|
+
fs.writeFileSync(path.join(dir,'.reviews/prd-guide-task-scope.json'),JSON.stringify({version:1,enforced:true,exempt:[]})+'\n',{mode:0o600});
|
|
184
|
+
const {snapshotVersion,...unversioned}=inspectPrdChangeSnapshot(dir);
|
|
185
|
+
const raw={status:'draft',summary:'Change',removed:[],features:[{directory:'1.guide',documents:revised(),testCasesReason:'no_observable_behavior'}]};
|
|
186
|
+
const proposal=inspectPrdChangeProposal(unversioned,raw,selected,config);
|
|
187
|
+
assert.equal(applyPrdChange({specs:dir,before:unversioned,proposal,selected}).status,'awaiting_review');
|
|
188
|
+
});
|
|
149
189
|
test('change cannot invent completion or erase completed lines; user case changes are surfaced',t=>{
|
|
150
190
|
const dir=fixture(t),before=inspectPrdChangeSnapshot(dir),config=loadConfig({projectRoot:dir});
|
|
151
191
|
const raw={status:'draft',summary:'Change',removed:[],features:[{directory:'1.guide',documents:revised(),testCasesReason:'no_observable_behavior'}]};
|
|
152
192
|
for(const mode of ['erase','invent']){const bad=structuredClone(raw);const task=bad.features[0].documents.find(doc=>doc.path==='tasks.md');
|
|
153
|
-
task.content=mode==='erase'?task.content.replace('[x]','[ ]'):task.content.replace('- [ ] T-002: Draft appendix','- [x] T-002: Draft appendix [CHANGED]');
|
|
193
|
+
task.content=mode==='erase'?task.content.replace('[x]','[ ]'):task.content.replace('- [ ] T-002: Draft appendix\n - 范围: `README.md`','- [x] T-002: Draft appendix [CHANGED]');
|
|
154
194
|
assert.throws(()=>inspectPrdChangeProposal(before,bad,['1.guide'],config),/prd_completed_task/);}
|
|
155
195
|
const synthetic={...before,files:{...before.files,'1.guide/test-cases.json':JSON.stringify({cases:[{id:'TC-001',origin:'user',expected:'Original user intent'}]})}};
|
|
156
196
|
const proposal=inspectPrdChangeProposal(synthetic,raw,['1.guide'],config);assert.equal(proposal.changedUserCases.length,1);
|
|
@@ -173,12 +213,13 @@ test('change guards completed tasks written without a colon or with a full-width
|
|
|
173
213
|
// approval an unfenced full-width example is prose, not the completed task.
|
|
174
214
|
test('change guard reads the approved original with the legacy grammar',t=>{
|
|
175
215
|
const dir=fixture(t),config=loadConfig({projectRoot:dir}),example='- [ ] T-001:旧写法示例';
|
|
176
|
-
|
|
177
|
-
|
|
216
|
+
// The example sits after T-001's own sub-item, so it never splits a task from its scope.
|
|
217
|
+
const owned='- [x] T-001: Existing guide\n - 范围: `README.md`\n';
|
|
218
|
+
fs.writeFileSync(path.join(dir,'1.guide/tasks.md'),docs()[2].content.replace(owned,`${owned}${example}\n`),{mode:0o600});
|
|
178
219
|
const before=inspectPrdChangeSnapshot(dir),task=revised().find(doc=>doc.path==='tasks.md');
|
|
179
220
|
const fenced={status:'draft',summary:'Fence the old example',removed:[],features:[{directory:'1.guide',
|
|
180
|
-
documents:revised().map(doc=>doc.path==='tasks.md'?{...doc,content:task.content.replace(
|
|
181
|
-
|
|
221
|
+
documents:revised().map(doc=>doc.path==='tasks.md'?{...doc,content:task.content.replace(owned,
|
|
222
|
+
`${owned}\`\`\`md\n${example}\n\`\`\`\n`)}:doc),testCasesReason:'no_observable_behavior'}]};
|
|
182
223
|
const proposal=inspectPrdChangeProposal(before,fenced,['1.guide'],config);
|
|
183
224
|
assert.equal(proposal.proposalDigest.length,64);
|
|
184
225
|
});
|
|
@@ -186,11 +227,13 @@ test('change guard reads the approved original with the legacy grammar',t=>{
|
|
|
186
227
|
// last approval bound, carried through the awaiting_review status of the first.
|
|
187
228
|
function sharedGrammarFixture(t){
|
|
188
229
|
const dir=fixture(t),tasks=path.join(dir,'1.guide/tasks.md');
|
|
189
|
-
fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace('- [ ] T-002: Draft appendix','- [ ] T-002:Draft appendix'),{mode:0o600});
|
|
190
|
-
|
|
230
|
+
fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace('- [ ] T-002: Draft appendix\n - 范围: `README.md`','- [ ] T-002:Draft appendix'),{mode:0o600});
|
|
231
|
+
// A real approval lists the approved bytes; its tasks may stay without scope in a change.
|
|
232
|
+
fs.writeFileSync(path.join(dir,'.cm-specs-status'),JSON.stringify({status:'approved',taskGrammar:2,features:['1.guide'],
|
|
233
|
+
specFiles:[{path:'1.guide/tasks.md',sha256:semanticDigest(tasks)}]}),{mode:0o600});
|
|
191
234
|
return dir;
|
|
192
235
|
}
|
|
193
|
-
const fullWidth=docs=>docs.map(doc=>doc.path==='tasks.md'?{...doc,content:doc.content.replace('- [ ] T-002: Draft appendix','- [ ] T-002:Draft appendix')}:doc);
|
|
236
|
+
const fullWidth=docs=>docs.map(doc=>doc.path==='tasks.md'?{...doc,content:doc.content.replace('- [ ] T-002: Draft appendix\n - 范围: `README.md`','- [ ] T-002:Draft appendix')}:doc);
|
|
194
237
|
const status=dir=>JSON.parse(fs.readFileSync(path.join(dir,'.cm-specs-status'),'utf8'));
|
|
195
238
|
test('a second change of the same feature before re-approval keeps the approved grammar',t=>{
|
|
196
239
|
const dir=sharedGrammarFixture(t),config=loadConfig({projectRoot:dir}),selected=['1.guide'];
|
|
@@ -201,7 +244,7 @@ test('a second change of the same feature before re-approval keeps the approved
|
|
|
201
244
|
applyPrdChange({specs:dir,before,proposal,selected});
|
|
202
245
|
assert.equal(status(dir).status,'awaiting_review');assert.equal(status(dir).taskGrammar,2);
|
|
203
246
|
const second=first.map(doc=>({...doc,content:doc.content+'\n| 2026-09-08 | v3 | again |\n'
|
|
204
|
-
+(doc.path==='tasks.md'?'- [ ] T-004: [NEW] Another example\n':'Again\n')}));
|
|
247
|
+
+(doc.path==='tasks.md'?'- [ ] T-004: [NEW] Another example\n - 范围: `README.md`\n':'Again\n')}));
|
|
205
248
|
before=inspectPrdChangeSnapshot(dir);
|
|
206
249
|
proposal=inspectPrdChangeProposal(before,{status:'draft',summary:'Second',removed:[],features:[{directory:'1.guide',
|
|
207
250
|
documents:second,testCasesReason:'no_observable_behavior'}]},selected,config);
|
|
@@ -222,7 +265,7 @@ test('a second change of another feature before re-approval still carries the ap
|
|
|
222
265
|
});
|
|
223
266
|
test('an unapproved legacy status never switches the change guard to the shared grammar',t=>{
|
|
224
267
|
const dir=fixture(t),config=loadConfig({projectRoot:dir}),tasks=path.join(dir,'1.guide/tasks.md');
|
|
225
|
-
fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace('- [ ] T-002: Draft appendix','- [ ] T-002:Draft appendix'),{mode:0o600});
|
|
268
|
+
fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace('- [ ] T-002: Draft appendix\n - 范围: `README.md`','- [ ] T-002:Draft appendix'),{mode:0o600});
|
|
226
269
|
fs.writeFileSync(path.join(dir,'.cm-specs-status'),JSON.stringify({status:'awaiting_review'}),{mode:0o600});
|
|
227
270
|
const before=inspectPrdChangeSnapshot(dir);
|
|
228
271
|
// Under the old grammar the full-width line is prose, so rewriting it as a
|
|
@@ -12,12 +12,12 @@ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
|
12
12
|
import {inspectPrdDesignDraft} from '../runtime/js/cm-prd/draft.mjs';
|
|
13
13
|
import {createCmPrdAnalysis} from '../runtime/js/cm-prd/analysis.mjs';
|
|
14
14
|
import {savePrdDesign,savePrdDraft,savePrdPromotedDraft} from '../runtime/js/cm-prd/draft-save.mjs';
|
|
15
|
-
import {inspectPrdDraft} from '../runtime/js/cm-prd/draft.mjs';
|
|
15
|
+
import {inspectPrdDraft,inspectPrdDraftReply} from '../runtime/js/cm-prd/draft.mjs';
|
|
16
16
|
import {runPrdHostReview} from '../runtime/js/cm-prd/review-host.mjs';
|
|
17
17
|
import {inspectPrdFindings} from '../runtime/js/cm-prd/review-findings.mjs';
|
|
18
18
|
import {inspectPrdSplitDesign} from '../runtime/js/cm-prd/split-design.mjs';
|
|
19
19
|
import {preparePrdReview} from '../runtime/js/cm-prd/review-preparation.mjs';
|
|
20
|
-
import {inspectAcceptedPrdDesign} from '../runtime/js/cm-prd/accepted-design.mjs';
|
|
20
|
+
import {inspectAcceptedPrdDesign,acceptedPrdDesignForPlanning} from '../runtime/js/cm-prd/accepted-design.mjs';
|
|
21
21
|
import {createPrdSummaryOwner,inspectPrdSummaryEvidence,publishPrdAwaitingReview} from '../runtime/js/cm-prd/summary.mjs';
|
|
22
22
|
import {assertPrdReviewsSettled} from '../runtime/js/cm-prd/change.mjs';
|
|
23
23
|
import {recordPrdHostDisposition,createPrdDispositionOwner} from '../runtime/js/cm-prd/review-disposition.mjs';
|
|
@@ -82,7 +82,7 @@ test('saved promotion archives both versions, resumes identically and preserves
|
|
|
82
82
|
const make=task=>inspectPrdDraft({status:'draft',summary:'Fixture',features:[{...design().features[0],
|
|
83
83
|
testCasesReason:'no_observable_behavior',documents:[...design().features[0].documents,{path:'tasks.md',content:task}]}]},
|
|
84
84
|
{nextIndex:1,generateCases:true,userCasesProvided:false});
|
|
85
|
-
const original=make('- [ ] T-001: Original'),draft=make('- [ ] T-001: Revised');
|
|
85
|
+
const original=make('- [ ] T-001: Original\n - 范围: `README.md`'),draft=make('- [ ] T-001: Revised\n - 范围: `README.md`');
|
|
86
86
|
savePrdDraft({specs:dir,writeEnabled:true,getDraft:()=>original});
|
|
87
87
|
const input={specs:dir,writeEnabled:true,getDraft:()=>draft,getOriginal:()=>original};
|
|
88
88
|
assert.throws(()=>savePrdPromotedDraft({...input,writeEnabled:false}));
|
|
@@ -152,14 +152,14 @@ for(const mode of ['self-check-revision','saved','rewrite','drift','late-risk','
|
|
|
152
152
|
assert.ok(message.payload.riskDiscovery);result=design();
|
|
153
153
|
if(promotes)result={status:'draft',summary:'Original full draft',features:[{...design().features[0],
|
|
154
154
|
testCasesReason:'no_observable_behavior',documents:[...design().features[0].documents,
|
|
155
|
-
{path:'tasks.md',content:'- [ ] T-001: Original task before risk discovery'}]}]};
|
|
155
|
+
{path:'tasks.md',content:'- [ ] T-001: Original task before risk discovery\n - 范围: `README.md`'}]}]};
|
|
156
156
|
}
|
|
157
157
|
else{
|
|
158
158
|
assert.equal(message.payload.phase,'tasks_after_design');
|
|
159
159
|
assert.equal(message.payload.acceptedDesign.features[0].directory,'1.guide');
|
|
160
160
|
assert.ok(message.payload.acceptedDesign.features[0].documents[1].content.includes('Corrected architecture'));
|
|
161
161
|
result={status:'draft',summary:'Tasks from disposed design',features:message.payload.acceptedDesign.features.map(feature=>({
|
|
162
|
-
name:feature.name,testCasesReason:'no_observable_behavior',documents:[...feature.documents,{path:'tasks.md',content:'- [ ] T-001: Update guide'}]}))};
|
|
162
|
+
name:feature.name,testCasesReason:'no_observable_behavior',documents:[...feature.documents,{path:'tasks.md',content:'- [ ] T-001: Update guide\n - 范围: `README.md`'}]}))};
|
|
163
163
|
if(mode==='self-check-revision'&&message.payload.selfCheckRevision){
|
|
164
164
|
result.selfCheckRevisionReason='AC setup needs a concrete observable result';
|
|
165
165
|
result.features[0].documents[0].content+='\nAC setup: run the documented command and verify output.';
|
|
@@ -298,7 +298,7 @@ for(const mode of ['self-check-revision','saved','rewrite','drift','late-risk','
|
|
|
298
298
|
assert.equal(fs.existsSync(path.join(dir,'.cm-specs-status')),succeeds);
|
|
299
299
|
if(succeeds){
|
|
300
300
|
assert.equal(JSON.parse(fs.readFileSync(path.join(dir,'.cm-specs-status'),'utf8')).status,'awaiting_review');
|
|
301
|
-
assert.equal(fs.readFileSync(path.join(dir,'1.guide/tasks.md'),'utf8'),'- [ ] T-001: Update guide');
|
|
301
|
+
assert.equal(fs.readFileSync(path.join(dir,'1.guide/tasks.md'),'utf8'),'- [ ] T-001: Update guide\n - 范围: `README.md`');
|
|
302
302
|
if(mode==='saved-promote'){
|
|
303
303
|
const archived=fs.readFileSync(path.join(dir,`.reviews/prd-task-revision-${originalDigest}.md`),'utf8');
|
|
304
304
|
assert.ok(archived.includes('Original task before risk discovery'));assert.ok(archived.includes('Update guide'));
|
|
@@ -315,7 +315,7 @@ test('mixed-risk features keep one batch and dispatch design only for high risk'
|
|
|
315
315
|
if(generation===1){const raw=design();raw.features.push({...design().features[0],name:'copy'});return raw;}
|
|
316
316
|
assert.equal(payload.acceptedDesign.features.length,2);
|
|
317
317
|
return {status:'draft',summary:'Mixed tasks',features:payload.acceptedDesign.features.map(feature=>({name:feature.name,
|
|
318
|
-
testCasesReason:'no_observable_behavior',documents:[...feature.documents,{path:'tasks.md',content:'- [ ] T-001: Update guide'}]}))};
|
|
318
|
+
testCasesReason:'no_observable_behavior',documents:[...feature.documents,{path:'tasks.md',content:'- [ ] T-001: Update guide\n - 范围: `README.md`'}]}))};
|
|
319
319
|
}});
|
|
320
320
|
await host.advance('Analyze');await host.plan('Design',{designOnly:true});
|
|
321
321
|
const value={draftDigest:host.status().designDraft.draftDigest,risks:[
|
|
@@ -340,6 +340,76 @@ test('mixed-risk features keep one batch and dispatch design only for high risk'
|
|
|
340
340
|
assert.equal(fs.existsSync(path.join(dir,'.reviews/prd-copy-design-r1.md')),false);
|
|
341
341
|
});
|
|
342
342
|
|
|
343
|
+
// Accepted requirements/design near 64 KiB used to leave no room for tasks: the
|
|
344
|
+
// tasks_after_design reply had to repeat them inside the same 64 KiB submission.
|
|
345
|
+
async function largeAcceptedDesign(t,documents){
|
|
346
|
+
const dir=fixture(t);let generation=0;const seen={};
|
|
347
|
+
const host=createCmPrdAnalysis({input:{skillDir:path.join(root,'skills/cm-prd'),project:dir,specs:dir},runtime:'codex',
|
|
348
|
+
record:async()=>{},analyze:async()=>({status:'analyzed',summary:'Large design',sourcePaths:['docs/input.md'],openQuestions:[]}),
|
|
349
|
+
generate:async payload=>{
|
|
350
|
+
generation++;
|
|
351
|
+
if(generation===1){
|
|
352
|
+
const raw=design();raw.features.push({...design().features[0],name:'copy'});
|
|
353
|
+
const pad=Math.floor((65400-Buffer.byteLength(JSON.stringify(raw)))/2);
|
|
354
|
+
for(const feature of raw.features)feature.documents[1].content+='\n'+'x'.repeat(pad);
|
|
355
|
+
return raw;
|
|
356
|
+
}
|
|
357
|
+
seen.payload=payload;
|
|
358
|
+
return {status:'draft',summary:'Tasks only',features:payload.acceptedDesign.features.map(feature=>({name:feature.name,
|
|
359
|
+
testCasesReason:'no_observable_behavior',documents:documents(feature)}))};
|
|
360
|
+
}});
|
|
361
|
+
await host.advance('Analyze');await host.plan('Design',{designOnly:true});
|
|
362
|
+
host.selectDesignReviews({draftDigest:host.status().designDraft.draftDigest,risks:[
|
|
363
|
+
{feature:'1.guide',signals:riskSignals(true),evidence:['New architecture']},
|
|
364
|
+
{feature:'2.copy',signals:riskSignals(false),evidence:['Existing text-only module']}]});
|
|
365
|
+
savePrdDesign({specs:dir,writeEnabled:true,getDraft:()=>host.currentDesignForSave()});
|
|
366
|
+
const prepare=()=>host.prepareReview('design','1.guide');
|
|
367
|
+
await runPrdHostReview({specs:dir,prepared:prepare(),authorContextId:'author',writeEnabled:true,mode:'independent',
|
|
368
|
+
revalidate:prepare,signal:new AbortController().signal,review:async payload=>({reviewer:'codex-subagent',contextId:'reviewer',
|
|
369
|
+
independent:true,at:'2026-09-08T00:00:00.000Z',result:{verdict:'approved',packageDigest:payload.package.packageDigest,
|
|
370
|
+
examinedPaths:payload.examinedPaths,findings:[],summary:'Synthetic'}})});
|
|
371
|
+
const review=inspectPrdFindings({specs:dir,stage:'design',feature:'1.guide'});
|
|
372
|
+
recordPrdHostDisposition({specs:dir,stage:'design',feature:'1.guide',packageDigest:review.packageDigest,
|
|
373
|
+
decisions:[],artifacts:review.reviewedArtifacts,writeEnabled:true});
|
|
374
|
+
return {dir,host,seen};
|
|
375
|
+
}
|
|
376
|
+
const tasksOnly={path:'tasks.md',content:'- [ ] T-001: Update guide\n - 范围: `README.md`'};
|
|
377
|
+
test('tasks after design may leave out accepted requirements and design; only the new documents count toward 64 KiB',async t=>{
|
|
378
|
+
const {dir,host,seen}=await largeAcceptedDesign(t,()=>[tasksOnly]);
|
|
379
|
+
const accepted=acceptedPrdDesignForPlanning(dir,host.checkpoint());
|
|
380
|
+
const result=await host.plan('Tasks now');
|
|
381
|
+
assert.ok(['draft_ready','draft_self_check_failed'].includes(result.stage),result.stage);
|
|
382
|
+
// A driver preflights with the same accepted design the host sends, and in the
|
|
383
|
+
// host's order: a reply that still repeats the accepted documents and exceeds
|
|
384
|
+
// 64 KiB is refused before the host is started, not after it records the answer.
|
|
385
|
+
assert.deepEqual(accepted,seen.payload.acceptedDesign);
|
|
386
|
+
const options={nextIndex:1,generateCases:true,userCasesProvided:false};
|
|
387
|
+
const reply=documents=>({status:'draft',summary:'Tasks only',features:accepted.features.map(feature=>({name:feature.name,
|
|
388
|
+
testCasesReason:'no_observable_behavior',documents:documents(feature)}))});
|
|
389
|
+
assert.equal(inspectPrdDraftReply(reply(()=>[tasksOnly]),accepted,options).features.length,2);
|
|
390
|
+
assert.throws(()=>inspectPrdDraftReply(reply(feature=>[...feature.documents,tasksOnly]),accepted,options),
|
|
391
|
+
error=>(error.code??error.message)==='limit_exceeded');
|
|
392
|
+
assert.match(seen.payload.instructions,/leaving out requirements\.md\/design\.md/);
|
|
393
|
+
const draft=host.status().draft;
|
|
394
|
+
assert.ok(Buffer.byteLength(JSON.stringify(draft.features))>65536);
|
|
395
|
+
for(const [index,feature] of draft.features.entries()){
|
|
396
|
+
const original=accepted.features[index].documents;
|
|
397
|
+
assert.deepEqual(feature.documents.map(doc=>doc.path),['requirements.md','design.md','tasks.md']);
|
|
398
|
+
for(const doc of original)assert.equal(feature.documents.find(item=>item.path===doc.path).content,doc.content);
|
|
399
|
+
}
|
|
400
|
+
// The planning history keeps the reply as sent, without the restored documents.
|
|
401
|
+
assert.deepEqual(result.planningReply.features.map(feature=>feature.documents.map(doc=>doc.path)),[['tasks.md'],['tasks.md']]);
|
|
402
|
+
});
|
|
403
|
+
test('tasks after design keeps the 64 KiB reply limit and refuses rewritten or repeated documents',async t=>{
|
|
404
|
+
const refused=async(documents,pattern)=>{const {host}=await largeAcceptedDesign(t,documents);
|
|
405
|
+
await assert.rejects(host.plan('Tasks now'),error=>pattern.test(error.code??error.message));assert.equal(host.status().draft,null);};
|
|
406
|
+
await refused(feature=>[...feature.documents,tasksOnly],/limit_exceeded/);
|
|
407
|
+
await refused(feature=>[{path:'requirements.md',content:feature.documents[0].content+'\nChanged'},tasksOnly],/prd_accepted_design_rewritten/);
|
|
408
|
+
await refused(()=>[tasksOnly,tasksOnly],/prd_draft_document_invalid/);
|
|
409
|
+
// A repeated accepted document is refused, never merged into one by the restore.
|
|
410
|
+
await refused(feature=>[feature.documents[0],feature.documents[0],tasksOnly],/prd_draft_document_invalid/);
|
|
411
|
+
});
|
|
412
|
+
|
|
343
413
|
// Real design receipt -> full draft -> split finding, unlike split-only fixtures.
|
|
344
414
|
const sha=content=>createHash('sha256').update(content).digest('hex');
|
|
345
415
|
const checked=({draft})=>({draftDigest:draft.draftDigest,features:draft.features.map(feature=>({directory:feature.directory,
|
|
@@ -350,7 +420,7 @@ async function splitDesignFixture(t,{split=true,featureName='guide',document='de
|
|
|
350
420
|
analyze:async()=>({status:'analyzed',summary:'Fixture',sourcePaths:['docs/input.md'],openQuestions:[]}),
|
|
351
421
|
generate:async payload=>payload.phase==='design'?{...design(),features:[{...design().features[0],name:featureName},...(batch?[{...design().features[0],name:'second'}]:[])]}:
|
|
352
422
|
{status:'draft',summary:'Accepted tasks',features:payload.acceptedDesign.features.map(f=>({name:f.name,
|
|
353
|
-
testCasesReason:'no_observable_behavior',documents:[...f.documents,{path:'tasks.md',content:'- [ ] T-001: Update guide'}]}))}};
|
|
423
|
+
testCasesReason:'no_observable_behavior',documents:[...f.documents,{path:'tasks.md',content:'- [ ] T-001: Update guide\n - 范围: `README.md`'}]}))}};
|
|
354
424
|
let host=createCmPrdAnalysis(options);const feature=`1.${featureName}`;
|
|
355
425
|
const review=async(stage,target=feature)=>{
|
|
356
426
|
const prepare=()=>host.prepareReview(stage,target);
|
|
@@ -25,6 +25,18 @@ test('save exact Markdown and JSON, explicit identical resume, no approval',t=>{
|
|
|
25
25
|
assert.equal(fs.existsSync(path.join(specs,'.cm-specs-status')),false);
|
|
26
26
|
assert.equal(result.completionAuthorized,false);
|
|
27
27
|
});
|
|
28
|
+
test('save records whether the saved tasks carry scopes, before the spec files',t=>{
|
|
29
|
+
const {specs,draft,args}=fixture(t);
|
|
30
|
+
const record=()=>JSON.parse(fs.readFileSync(path.join(specs,'.reviews/prd-guide-task-scope.json'),'utf8'));
|
|
31
|
+
assert.equal(savePrdDraft(args).status,'draft_saved');
|
|
32
|
+
assert.deepEqual(record(),{version:1,enforced:false,exempt:[]});
|
|
33
|
+
const scoped=fixture(t);scoped.draft.features[0].documents[2].content='- [ ] T-001: Document\n - 范围: `README.md`';
|
|
34
|
+
scoped.draft.draftDigest=digest({summary:scoped.draft.summary,features:scoped.draft.features});
|
|
35
|
+
assert.equal(savePrdDraft(scoped.args).status,'draft_saved');
|
|
36
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(scoped.specs,'.reviews/prd-guide-task-scope.json'),'utf8')),
|
|
37
|
+
{version:1,enforced:true,exempt:[]});
|
|
38
|
+
assert.equal(draft.features.length,1);
|
|
39
|
+
});
|
|
28
40
|
test('disabled and conflict preflight produce zero new spec writes',t=>{
|
|
29
41
|
const {specs,args}=fixture(t);assert.throws(()=>savePrdDraft({...args,writeEnabled:false}),/not_enabled/);
|
|
30
42
|
assert.deepEqual(fs.readdirSync(specs),[]);fs.mkdirSync(path.join(specs,'1.guide'));
|
|
@@ -9,7 +9,7 @@ import {inspectPrdDraft} from '../runtime/js/cm-prd/draft.mjs';
|
|
|
9
9
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
10
10
|
const draft=()=>({status:'draft',summary:'Documentation draft',features:[{name:'guide',
|
|
11
11
|
documents:['requirements.md','design.md','tasks.md'].map(file=>({path:file,
|
|
12
|
-
content:file==='requirements.md'?'- [ ] [AC-001] The guide describes setup.':file==='tasks.md'?'- [ ] T-001: Update guide':'# Synthetic design'})),
|
|
12
|
+
content:file==='requirements.md'?'- [ ] [AC-001] The guide describes setup.':file==='tasks.md'?'- [ ] T-001: Update guide\n - 范围: `README.md`':'# Synthetic design'})),
|
|
13
13
|
testCasesReason:'no_observable_behavior'}]});
|
|
14
14
|
test('draft structure refuses missing triad, unsafe path and dropped user cases',()=>{
|
|
15
15
|
const options={nextIndex:3,generateCases:true,userCasesProvided:false};
|
package/scripts/cm-prd-drive.mjs
CHANGED
|
@@ -32,9 +32,12 @@ import {createHash} from 'node:crypto';
|
|
|
32
32
|
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
33
33
|
import {inspectCmPrdAdmission,inspectCmPrdSources} from './cm-prd-entry.mjs';
|
|
34
34
|
import {loadConfig} from './cm-workflow-config.mjs';
|
|
35
|
-
import {
|
|
35
|
+
import {inspectPrdDraftReply,inspectPrdDesignDraft,nextPrdFeatureIndex,prdFeatureInventory} from '../runtime/js/cm-prd/draft.mjs';
|
|
36
|
+
import {acceptedPrdDesignForPlanning} from '../runtime/js/cm-prd/accepted-design.mjs';
|
|
36
37
|
import {inspectPrdChangeSnapshot,inspectPrdChangeProposal} from '../runtime/js/cm-prd/change.mjs';
|
|
37
38
|
import {checkPrdDraftMechanics} from '../runtime/js/cm-prd/self-check.mjs';
|
|
39
|
+
import {prdSessionVersions} from '../runtime/js/cm-prd/session.mjs';
|
|
40
|
+
import {prdTaskScopeOptions} from '../runtime/js/cm-prd/task-scope-record.mjs';
|
|
38
41
|
import {inspectPrdFindings} from '../runtime/js/cm-prd/review-findings.mjs';
|
|
39
42
|
import {inspectPrdDispositionPlan} from '../runtime/js/cm-prd/disposition-plan.mjs';
|
|
40
43
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
@@ -200,7 +203,7 @@ function load(){
|
|
|
200
203
|
const answers=preflightAnswers([...new Set(asks.filter(k=>FILES[k]))],kind=>{
|
|
201
204
|
const file=path.join(answersRoot??base,FILES[kind]);const value=readJson(file,kind);
|
|
202
205
|
if(value===undefined)stop(2,`步骤 ${operation} 会反问 ${kind},但答案文件不存在: ${file}`);
|
|
203
|
-
validate(kind,value,{stage,change,sources,config,specs,state,request,admission,hostContext:plan.hostContext});return value;
|
|
206
|
+
validate(kind,value,{stage,change,sources,config,specs,state,request,operation,admission,hostContext:plan.hostContext});return value;
|
|
204
207
|
});
|
|
205
208
|
if(asks.includes('prd_self_check')){
|
|
206
209
|
if(!Array.isArray(plan.contextChecks)||plan.contextChecks.length===0)
|
|
@@ -216,7 +219,7 @@ function load(){
|
|
|
216
219
|
if(documents.some(doc=>!nonempty(doc.content)))stop(2,'review_disposition 缺少已保存的 artifact 内容');
|
|
217
220
|
draft={draftDigest:digest(request.artifacts),features:[{directory:request.feature,
|
|
218
221
|
name:request.feature.replace(/^\d+\./,''),documents}]};
|
|
219
|
-
draft.mechanicalSelfCheck=checkPrdDraftMechanics(draft);
|
|
222
|
+
draft.mechanicalSelfCheck=checkPrdDraftMechanics(draft,prdTaskScopeOptions(specs,request.feature));
|
|
220
223
|
}
|
|
221
224
|
if(!draft)stop(2,'prd_self_check 缺少当前草稿');
|
|
222
225
|
for(const feature of draft.features)for(const id of draft.mechanicalSelfCheck.pending){
|
|
@@ -246,7 +249,10 @@ function validate(kind,value,ctx){
|
|
|
246
249
|
else if(ctx.change){
|
|
247
250
|
exact(value,['status','summary','features','removed'],'generate.json');
|
|
248
251
|
if(ctx.stage==='change_tasks'||ctx.stage==='change_check_failed'){
|
|
249
|
-
|
|
252
|
+
// Same rule the host applies: a resumed operation keeps the rule it began
|
|
253
|
+
// under (none recorded = rule 1); a new operation uses the one its session bound.
|
|
254
|
+
const rules=ctx.operation==='resume'?ctx.state.active?.selfCheckRules??1:prdSessionVersions(ctx.state,ctx.specs).selfCheckRules;
|
|
255
|
+
try{inspectPrdChangeProposal(inspectPrdChangeSnapshot(ctx.specs),value,ctx.state.checkpoint.change.selected,ctx.config,{rules});}
|
|
250
256
|
catch(e){fail('generate.json 不符合变更草稿或 scope',e.code??e.message);}
|
|
251
257
|
}else{
|
|
252
258
|
check(value.status==='documents'&&nonempty(value.summary)&&Array.isArray(value.features)&&Array.isArray(value.removed),'generate.json');
|
|
@@ -260,8 +266,9 @@ function validate(kind,value,ctx){
|
|
|
260
266
|
??ctx.state?.checkpoint?.analysis?.draft?.features?.[0]?.directory?.split('.')[0]
|
|
261
267
|
??nextPrdFeatureIndex(prdFeatureInventory(ctx.specs)));
|
|
262
268
|
try{if(value.status==='design')inspectPrdDesignDraft(value,{nextIndex});
|
|
263
|
-
|
|
264
|
-
|
|
269
|
+
// Same order as the host; requirements/design left out are restored from the accepted design.
|
|
270
|
+
else inspectPrdDraftReply(value,acceptedPrdDesignForPlanning(ctx.specs,ctx.state?.checkpoint?.analysis),
|
|
271
|
+
{nextIndex,generateCases:ctx.config.policies.generate_cases,userCasesProvided:ctx.sources.sourceInspection.userCases!==null});}
|
|
265
272
|
catch(e){fail('generate.json 不符合草稿 schema',e.code??e.message);}
|
|
266
273
|
}
|
|
267
274
|
}else if(kind==='prd_review'){
|
|
@@ -48,7 +48,7 @@ for(const format of ['pdf','html'])test(`${format} live material request is hash
|
|
|
48
48
|
const draft={status:'draft',summary:'Synthetic documentation draft',features:[{name:'guide',testCasesReason:'no_observable_behavior',
|
|
49
49
|
documents:[{path:'requirements.md',content:'## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Document setup.'},
|
|
50
50
|
{path:'design.md',content:'## 方案摘要\nSynthetic design'},
|
|
51
|
-
{path:'tasks.md',content:'- [ ] T-001: Update guide'}]}]};
|
|
51
|
+
{path:'tasks.md',content:'- [ ] T-001: Update guide\n - 范围: `README.md`'}]}]};
|
|
52
52
|
test('contextChecks with stdout and stderr record a passed command',async t=>{
|
|
53
53
|
const f=fixture(t);
|
|
54
54
|
const checks=await runPrdContextChecks(f.project,[{id:'output',command:[process.execPath,'-e',
|
|
@@ -128,6 +128,18 @@ test('static self-check evidence is refused before the host changes its session'
|
|
|
128
128
|
const run=f.drive('advance');assert.equal(run.status,2);assert.match(run.stderr,/self-check.json.*执行证据/);
|
|
129
129
|
assert.equal(fs.readFileSync(f.store(f.plan.session)).toString(),before.toString());
|
|
130
130
|
});
|
|
131
|
+
test('self-check revision with selfCheckRevisionReason passes driver preflight and reaches the host',t=>{
|
|
132
|
+
const f=draftReady(t);
|
|
133
|
+
f.plan.contextChecks=[{id:'read-source',command:[process.execPath,'-e',"require('fs').readFileSync('docs/input.md','utf8')"]}];
|
|
134
|
+
f.plan.contextJudgements={'1.guide':Object.fromEntries(pending.map((id,i)=>[id,i===0?'failed':'passed']))};
|
|
135
|
+
const checked=f.drive('advance');assert.equal(checked.status,0,checked.stderr);
|
|
136
|
+
assert.equal(checked.json.result.stage,'self_check_failed');
|
|
137
|
+
const revised=structuredClone(draft);revised.selfCheckRevisionReason='Task boundary named in the failed check';
|
|
138
|
+
revised.features[0].documents[0].content+='\n- [ ] [AC-002] Guide names its verification command.';
|
|
139
|
+
f.write('generate.json',revised);f.plan.request={text:'Revise after failed self-check'};
|
|
140
|
+
const run=f.drive('advance');assert.equal(run.status,0,run.stderr);
|
|
141
|
+
assert.equal(run.json.result.stage,'draft_ready');
|
|
142
|
+
});
|
|
131
143
|
test('self-check preflight requires real contextChecks before host launch',t=>{
|
|
132
144
|
const f=draftReady(t);
|
|
133
145
|
f.plan.contextJudgements={'1.guide':Object.fromEntries(pending.map(id=>[id,'passed']))};
|
|
@@ -166,7 +178,7 @@ test('real host unknown call resumes with its original callId and requestDigest'
|
|
|
166
178
|
if(row.type==='host_ready'){
|
|
167
179
|
hostSession=row.sessionId;host.stdin.write(JSON.stringify({requestId:'one',operation:'start',text:'Analyze'})+'\n');
|
|
168
180
|
}else if(row.type==='host_request'){
|
|
169
|
-
pending=row;host.stdin.write(JSON.stringify({type:'host_close',sessionId:hostSession})+'\n');break;
|
|
181
|
+
pending=row;host.stdin.write(JSON.stringify({type:'host_close',sessionId:hostSession,force:true})+'\n');break;
|
|
170
182
|
}
|
|
171
183
|
}
|
|
172
184
|
assert.ok(pending,diagnostics);host.stdin.end();await closed;
|
|
@@ -192,3 +204,35 @@ test('resume with a static result for pending self-check evidence points to aban
|
|
|
192
204
|
const missing=f.drive('resume',{session:runId,request:{resolution:null}});
|
|
193
205
|
assert.equal(missing.status,2);assert.match(missing.stderr,/abandon:true 放弃后重发原操作/);
|
|
194
206
|
});
|
|
207
|
+
|
|
208
|
+
// A change_tasks operation begun before self-check rules were recorded is
|
|
209
|
+
// re-answered (discard) under rule 1, exactly as the host will judge it; one
|
|
210
|
+
// begun under rule 2 is refused by the same preflight.
|
|
211
|
+
for(const recorded of [null,2])test(`change_tasks re-answer preflight follows the operation rule: ${recorded??'legacy'}`,t=>{
|
|
212
|
+
const f=fixture(t);fs.mkdirSync(path.join(f.project,'1.guide'));
|
|
213
|
+
const docs=Object.fromEntries(draft.features[0].documents.map(doc=>[doc.path,doc.content]));
|
|
214
|
+
for(const [name,content] of Object.entries(docs))fs.writeFileSync(path.join(f.project,'1.guide',name),content);
|
|
215
|
+
f.plan.change='1.guide';f.write('analyze.json',{status:'analyzed',summary:'Change need',openQuestions:[]});
|
|
216
|
+
assert.equal(f.drive('start').status,0);
|
|
217
|
+
f.plan.session=fs.readdirSync(path.join(f.project,'.reviews/prd-sessions'))[0];
|
|
218
|
+
const parts=paths=>({status:'documents',summary:'Unchanged parts',removed:[],
|
|
219
|
+
features:[{directory:'1.guide',documents:paths.map(p=>({path:p,content:docs[p]}))}]});
|
|
220
|
+
f.plan.request={text:'Requirements'};f.write('generate.json',parts(['requirements.md']));assert.equal(f.drive('advance').status,0);
|
|
221
|
+
f.plan.request={text:'Design'};f.write('generate.json',parts(['requirements.md','design.md']));
|
|
222
|
+
const designed=f.drive('advance');assert.equal(designed.status,0,designed.stderr);assert.equal(designed.json.result.stage,'change_tasks');
|
|
223
|
+
// The state a crashed change_tasks operation leaves: its refused answer is recorded.
|
|
224
|
+
const store=f.store(f.plan.session),state=JSON.parse(fs.readFileSync(store,'utf8'));
|
|
225
|
+
state.active={request:{requestId:'drive',operation:'advance',text:'Tasks'},before:state.checkpoint,
|
|
226
|
+
calls:[{kind:'prd_generate',callId:'call-1',requestDigest:'0'.repeat(64),payload:{},result:{status:'blocked',reason:'refused'}}],
|
|
227
|
+
...(recorded===null?{}:{selfCheckRules:recorded})};
|
|
228
|
+
fs.writeFileSync(store,JSON.stringify(state),{mode:0o600});
|
|
229
|
+
// Rule 1 skips the new T-002/a line; rule 2 rejects it.
|
|
230
|
+
f.write('generate.json',{status:'draft',summary:'Tasks',removed:[],features:[{directory:'1.guide',testCasesReason:'no_observable_behavior',
|
|
231
|
+
documents:[...['requirements.md','design.md'].map(p=>({path:p,content:docs[p]})),
|
|
232
|
+
{path:'tasks.md',content:`${docs['tasks.md']}\n- [ ] T-002/a: Hidden task\n\n| v2 | Synthetic change |`}]}]});
|
|
233
|
+
const before=fs.readFileSync(store);
|
|
234
|
+
const run=f.drive('resume',{request:{resolution:{callId:'call-1',requestDigest:'0'.repeat(64),discard:true,evidence:'Re-answer the refused draft'}}});
|
|
235
|
+
if(recorded===null){assert.equal(run.status,0,run.stderr);assert.equal(run.json.result.stage,'change_check');}
|
|
236
|
+
else{assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/不符合变更草稿.*prd_change_mechanics_failed/s);
|
|
237
|
+
assert.deepEqual(fs.readFileSync(store),before);}
|
|
238
|
+
});
|
|
@@ -23,9 +23,9 @@ const version='\n| 日期 | 版本 | 说明 |\n| --- | --- | --- |\n| 2026-09-08
|
|
|
23
23
|
const docs=()=>[
|
|
24
24
|
{path:'requirements.md',content:'## 需求版本'+version+'\n## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Read guide\n'},
|
|
25
25
|
{path:'design.md',content:'## 设计版本'+version+'\n## 方案摘要\nExisting guide\n'},
|
|
26
|
-
{path:'tasks.md',content:'## 任务版本'+version+'\n- [x] T-001: Existing guide\n- [ ] T-002: Draft appendix\n'}];
|
|
26
|
+
{path:'tasks.md',content:'## 任务版本'+version+'\n- [x] T-001: Existing guide\n - 范围: `README.md`\n- [ ] T-002: Draft appendix\n - 范围: `README.md`\n'}];
|
|
27
27
|
const revised=()=>docs().map(doc=>({path:doc.path,content:doc.content.replace('| 2026-09-08 | v1 | original |',
|
|
28
|
-
'| 2026-09-08 | v1 | original |\n| 2026-09-08 | v2 | change |')+(doc.path==='tasks.md'?'\n- [ ] T-003: [NEW] Add example\n':'\nUpdated example\n')}));
|
|
28
|
+
'| 2026-09-08 | v1 | original |\n| 2026-09-08 | v2 | change |')+(doc.path==='tasks.md'?'\n- [ ] T-003: [NEW] Add example\n - 范围: `README.md`\n':'\nUpdated example\n')}));
|
|
29
29
|
|
|
30
30
|
function fixture(t){
|
|
31
31
|
const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-gate-diagnostic-')));
|