@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
|
@@ -6,6 +6,7 @@ import {createHash} from 'node:crypto';
|
|
|
6
6
|
import {spawnSync} from 'node:child_process';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
8
|
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
9
|
+
import {openExecutionStore} from './execution-store.mjs';
|
|
9
10
|
import {readRunnerHistory} from './durable-runner-state.mjs';
|
|
10
11
|
import {supersedeWorkflowFile} from './review-evidence-file.mjs';
|
|
11
12
|
import {need,digest} from './effect-contract.mjs';
|
|
@@ -18,6 +19,7 @@ import {compareReviewInventoryToBaseline,readReviewBaseline} from './review-pack
|
|
|
18
19
|
const writer=fileURLToPath(new URL('../../../scripts/cm-log-event.py',import.meta.url));
|
|
19
20
|
const unavailable=reason=>{const error=new Error('supersede_unavailable');error.code='supersede_unavailable';error.reason=reason;throw error;};
|
|
20
21
|
const hash=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
22
|
+
const targetChanged=reason=>{const error=new Error('snapshot_changed');error.code='snapshot_changed';error.reason=reason;throw error;};
|
|
21
23
|
const codeDrift=reason=>{const error=new Error('supersede_code_drift');error.code='supersede_code_drift';error.reason=reason;throw error;};
|
|
22
24
|
const driftInstruction='这些文件与直接前驱运行开工前的基线不一致。手动还原这些文件后重建运行;或确认保留这些改动时加 --accept-superseded-code-drift 重建(这些文件会被当成已有代码,不进新运行的审查改动)。';
|
|
23
25
|
|
|
@@ -72,6 +74,12 @@ function evidenceNames(reviewsDir,feature,taskId){
|
|
|
72
74
|
.map(entry=>entry.name).sort();
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
// Writer files of predecessors this process locked itself for an in-flight v2 restart.
|
|
78
|
+
// Only an exact registered lock held by this very process is exempt from the
|
|
79
|
+
// open-descriptor check; any other process holding the file still counts.
|
|
80
|
+
const ownedWriters=new Set();
|
|
81
|
+
const onlyThisProcess=pids=>pids.length>0&&pids.every(pid=>Number(pid)===process.pid);
|
|
82
|
+
|
|
75
83
|
export function oldWriterOpen(execution,runId,{lsofPath}={}){
|
|
76
84
|
// Inspect descriptor ownership without opening the old SQLite store.
|
|
77
85
|
const writerFile=path.join(execution,runId,'writer.sqlite');
|
|
@@ -83,6 +91,8 @@ export function oldWriterOpen(execution,runId,{lsofPath}={}){
|
|
|
83
91
|
if(result.error||result.signal||![0,1].includes(result.status)||diagnostics.length)
|
|
84
92
|
unavailable(`无法核对旧运行 ${runId} 的 writer 状态`);
|
|
85
93
|
if(result.status===0&&!/^p\d+$/m.test(result.stdout))unavailable(`无法核对旧运行 ${runId} 的 writer 状态`);
|
|
94
|
+
if(result.status===0&&ownedWriters.has(writerFile)
|
|
95
|
+
&&onlyThisProcess([...result.stdout.matchAll(/^p(\d+)$/gm)].map(match=>match[1])))return false;
|
|
86
96
|
return result.status===0;
|
|
87
97
|
}
|
|
88
98
|
const fuser='/usr/bin/fuser';
|
|
@@ -91,18 +101,30 @@ export function oldWriterOpen(execution,runId,{lsofPath}={}){
|
|
|
91
101
|
if(result.error||result.signal||![0,1].includes(result.status))
|
|
92
102
|
unavailable(`无法核对旧运行 ${runId} 的 writer 状态`);
|
|
93
103
|
if(result.status===0&&!/\b\d+\b/.test(result.stdout))unavailable(`无法核对旧运行 ${runId} 的 writer 状态`);
|
|
104
|
+
if(result.status===0&&ownedWriters.has(writerFile)&&onlyThisProcess(result.stdout.match(/\b\d+\b/g)??[]))return false;
|
|
94
105
|
return result.status===0;
|
|
95
106
|
}
|
|
96
107
|
unavailable(`缺少核对旧运行 ${runId} writer 占用的本地工具`);
|
|
97
108
|
}
|
|
98
109
|
|
|
99
|
-
export function prepareReviewedEvidenceSupersession({specsDir,codeProject,feature,identity,reason,tasksPath,acceptSupersededCodeDrift=false
|
|
110
|
+
export function prepareReviewedEvidenceSupersession({specsDir,codeProject,feature,identity,reason,tasksPath,acceptSupersededCodeDrift=false,
|
|
111
|
+
expectedPredecessor=null,predecessorTarget=null,holds=null,afterDiscovery=null}){
|
|
112
|
+
if((expectedPredecessor===null)!==(predecessorTarget===null))unavailable('重开目标与核对函数必须同时提供');
|
|
100
113
|
if(typeof reason!=='string'||!reason.trim()||Buffer.byteLength(reason,'utf8')>500||/[\r\n\0]/.test(reason))
|
|
101
114
|
unavailable('必须提供单行且不超过 500 字节的 --supersede-reason');
|
|
102
115
|
if(taskChecked(tasksPath,identity.taskId))unavailable('tasks.md 已将任务标为完成;若 QA BLOCKED 后确需重跑,先将该任务改回 - [ ],再以 --supersede-reviewed-evidence 和 --supersede-reason 创建新运行');
|
|
103
116
|
const reviewsDir=path.join(specsDir,'.reviews');
|
|
104
117
|
if(!fs.existsSync(reviewsDir))unavailable('没有同 feature、task 的旧运行');
|
|
105
118
|
const execution=path.join(reviewsDir,'.execution');
|
|
119
|
+
// Discovery runs once up front and, for a v2 restart, again under the predecessor lock.
|
|
120
|
+
// Every run directory that exists right now (except this call's own new run), including
|
|
121
|
+
// ones the scan below cannot attribute to a task yet, such as a fresh run whose journal
|
|
122
|
+
// is still empty. A directory that appears between the two discoveries is a new run.
|
|
123
|
+
const listRunDirectories=()=>fs.existsSync(execution)
|
|
124
|
+
?fs.readdirSync(execution,{withFileTypes:true}).filter(entry=>entry.isDirectory()&&entry.name!==identity.runId)
|
|
125
|
+
.map(entry=>entry.name).sort():[];
|
|
126
|
+
const scan=()=>{
|
|
127
|
+
const runDirectories=listRunDirectories();
|
|
106
128
|
const previousRunIds=[],priorRuns=[],alreadySuperseded=new Set();
|
|
107
129
|
if(fs.existsSync(execution))for(const entry of fs.readdirSync(execution,{withFileTypes:true})){
|
|
108
130
|
if(!entry.isDirectory()||entry.name===identity.runId)continue;
|
|
@@ -135,12 +157,58 @@ export function prepareReviewedEvidenceSupersession({specsDir,codeProject,featur
|
|
|
135
157
|
:['PASS','PASSED'].includes(qa)?`旧运行 ${entry.name} 的 QA 已通过`
|
|
136
158
|
:['FAIL','FAILED'].includes(qa)?`旧运行 ${entry.name} 的最新 QA 结果为 FAIL(未通过),失败要修复而不是重开发:在原运行上用 QA 修复(fix_advance / fix_run)处理;修复子运行的审查卡在结果未知时,确认旧进程已退出后用 abandon_review 放弃一次再重审`
|
|
137
159
|
:`旧运行 ${entry.name} 的最新 QA 结果为 ${qa},不是 BLOCKED,不能用重开发替换;请在原运行上按该结果的恢复入口处理`);
|
|
138
|
-
priorRuns.push({runId:entry.name,baseline:first.baseline,
|
|
160
|
+
priorRuns.push({runId:entry.name,baseline:first.baseline,snapshot,
|
|
139
161
|
carriedReview:carriedReviewFrom(entry.name,history.state,history.supersession)});
|
|
140
162
|
for(const runId of history.supersession?.previousRunIds??[])alreadySuperseded.add(runId);
|
|
141
163
|
previousRunIds.push(entry.name);
|
|
142
164
|
}
|
|
165
|
+
return {previousRunIds,priorRuns,alreadySuperseded,runDirectories};
|
|
166
|
+
};
|
|
167
|
+
let {previousRunIds,priorRuns,alreadySuperseded,runDirectories}=scan();
|
|
143
168
|
if(!previousRunIds.length)unavailable('没有同 feature、task 的旧运行');
|
|
169
|
+
if(typeof afterDiscovery==='function')afterDiscovery();
|
|
170
|
+
if(expectedPredecessor){
|
|
171
|
+
// V2 approval names one predecessor state. More than one live predecessor is
|
|
172
|
+
// ambiguous, and any movement after the preview stops before archiving.
|
|
173
|
+
const direct=priorRuns.filter(run=>!alreadySuperseded.has(run.runId));
|
|
174
|
+
if(direct.length!==1)unavailable(`新版重开只接受一条未被取代的直接前驱运行,当前有 ${direct.length} 条`);
|
|
175
|
+
const [run]=direct;
|
|
176
|
+
if(expectedPredecessor.identity.repositoryId!==identity.repositoryId||expectedPredecessor.identity.runId!==run.runId
|
|
177
|
+
||expectedPredecessor.identity.taskId!==identity.taskId)
|
|
178
|
+
targetChanged(`重开目标指向的旧运行与实际直接前驱 ${run.runId} 不一致;先只读 inspect-history 核对,不自动替换目标。`);
|
|
179
|
+
// Take the predecessor's writer lock BEFORE the final comparison and keep it
|
|
180
|
+
// (the caller releases it) through journaling and archiving. A concurrent
|
|
181
|
+
// resume of the old run, or a second restart naming a different new run, then
|
|
182
|
+
// fails as unavailable instead of racing this approval.
|
|
183
|
+
need(Array.isArray(holds),'supersede_unavailable');
|
|
184
|
+
let held;
|
|
185
|
+
try{held=openExecutionStore({specsRoot:specsDir,identity:{repositoryId:identity.repositoryId,runId:run.runId},
|
|
186
|
+
fingerprints:run.snapshot.fingerprints,create:false});}
|
|
187
|
+
catch(error){unavailable(`旧运行 ${run.runId} 的 writer 无法锁定(${error.code??'open_failed'});可能正被恢复或另一次重开占用`);}
|
|
188
|
+
const writerFile=path.join(execution,run.runId,'writer.sqlite'),release=held.close;
|
|
189
|
+
ownedWriters.add(writerFile);
|
|
190
|
+
held={snapshot:held.snapshot,close(){try{release();}finally{ownedWriters.delete(writerFile);}}};
|
|
191
|
+
holds.push(held);
|
|
192
|
+
let current;
|
|
193
|
+
try{current=held.snapshot();}catch(error){targetChanged(`旧运行 ${run.runId} 的状态无法再次验证(${error.code??'read_failed'});先只读 inspect-history 核对。`);}
|
|
194
|
+
if(digest(predecessorTarget(current))!==digest(expectedPredecessor))
|
|
195
|
+
targetChanged(`旧运行 ${run.runId} 的状态在预览后已经变化;先只读 inspect-history 核对当前 supersedeTarget,不自动替换目标。`);
|
|
196
|
+
// Discovery above ran before this lock. Another restart naming a different new
|
|
197
|
+
// run may have completed in between and become the live predecessor, so look
|
|
198
|
+
// again under the lock and require the very same single direct predecessor.
|
|
199
|
+
const again=scan();
|
|
200
|
+
const directNow=again.priorRuns.filter(prior=>!again.alreadySuperseded.has(prior.runId));
|
|
201
|
+
if(directNow.length!==1||directNow[0].runId!==run.runId
|
|
202
|
+
||[...again.previousRunIds].sort().join('\n')!==[...previousRunIds].sort().join('\n'))
|
|
203
|
+
targetChanged('持锁后重新发现的同任务运行与批准时不同(另一次重开或新运行已出现);先只读 inspect-history 核对,不自动替换目标。');
|
|
204
|
+
// A run directory with no readable task identity yet (for example the leftover of a
|
|
205
|
+
// restart that failed before its first journal record, still resumable) is invisible
|
|
206
|
+
// to the comparison above, so any directory that is new since the first discovery
|
|
207
|
+
// also stops this restart and keeps the scene.
|
|
208
|
+
if(again.runDirectories.join('\n')!==runDirectories.join('\n'))
|
|
209
|
+
targetChanged('持锁后 .execution 下出现了批准时没有的运行目录(可能是另一次重开的残留或新运行);先只读核对该目录,不自动替换目标。');
|
|
210
|
+
({previousRunIds,priorRuns,alreadySuperseded,runDirectories}=again);
|
|
211
|
+
}
|
|
144
212
|
const drift=priorRuns.filter(run=>!alreadySuperseded.has(run.runId))
|
|
145
213
|
.flatMap(run=>verifyOldCodeBaseline(codeProject,run.baseline)
|
|
146
214
|
.map(file=>({predecessorRunId:run.runId,...file})))
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// Explicit, one-run integration evidence. Ordinary delivery discovery remains
|
|
2
|
+
// strict. This module never opens a writer, edits a product, or dispatches work.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {createHash} from 'node:crypto';
|
|
8
|
+
import {digest,hex,id,json,need,shape,validIdentity} from './effect-contract.mjs';
|
|
9
|
+
import {readReviewBaseline,readReviewPackage} from './review-package.mjs';
|
|
10
|
+
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
11
|
+
import {readRunnerHistory} from './durable-runner-state.mjs';
|
|
12
|
+
import {approvedReviewAt,completedReviewedDeliveries} from './reviewed-deliveries.mjs';
|
|
13
|
+
import {explainIntegratedDelivery,firstReviewAt} from './fix-code-association.mjs';
|
|
14
|
+
import {inspectFixFinalRegistration,inspectFixFinalResult} from '../cm-fix/final-review.mjs';
|
|
15
|
+
import {readIntegrationSnapshots,assertSnapshotBoundaries,verifySnapshotReview} from './integration-snapshots.mjs';
|
|
16
|
+
|
|
17
|
+
const sha=bytes=>createHash('sha256').update(bytes).digest('hex');
|
|
18
|
+
const absolute=value=>need(typeof value==='string'&&path.isAbsolute(value)&&path.normalize(value)===value
|
|
19
|
+
&&!/[\x00-\x1f]/.test(value),'integration_path_invalid');
|
|
20
|
+
const equal=(a,b,code='integration_binding_mismatch')=>need(digest(a)===digest(b),code);
|
|
21
|
+
const canonical=value=>Buffer.from(JSON.stringify(value)+'\n');
|
|
22
|
+
const meta=({contentBase64,...value})=>value;
|
|
23
|
+
const learningPaths=records=>records.flatMap(row=>row.payload.type==='effect-intent'
|
|
24
|
+
?(row.payload.effect.learningInput?.learningFiles??[]).filter(file=>file.scope==='project').map(file=>file.path):[]);
|
|
25
|
+
const documentPath=value=>typeof value==='string'&&/^docs\/(?:[A-Za-z0-9_.-]+\/)*[A-Za-z0-9_.-]+\.md$/.test(value)
|
|
26
|
+
&&!value.split('/').some(part=>part==='.'||part==='..'||/^(?:AGENTS|CLAUDE|SKILL)\.md$/i.test(part));
|
|
27
|
+
|
|
28
|
+
export function readIntegrationPlan(raw){
|
|
29
|
+
const plan=json(raw,128*1024);shape(plan,['version','kind','author','target','sources','documents',
|
|
30
|
+
...(Object.hasOwn(plan,'snapshots')?['snapshots']:[])]);
|
|
31
|
+
if(Object.hasOwn(plan,'snapshots'))readIntegrationSnapshots(plan.snapshots);
|
|
32
|
+
need(plan.version===1&&plan.kind==='cm-reviewed-integration-v1','integration_plan_invalid');
|
|
33
|
+
shape(plan.author,['provider','contextId']);need(plan.author.provider==='codex','integration_author_invalid');id(plan.author.contextId);
|
|
34
|
+
const target=plan.target;shape(target,['identity','rootDigest','baselineDigest','packageDigest','recordCount','lastDigest']);
|
|
35
|
+
validIdentity(target.identity);
|
|
36
|
+
for(const key of ['rootDigest','baselineDigest','packageDigest','lastDigest'])hex(target[key]);
|
|
37
|
+
need(Number.isSafeInteger(target.recordCount)&&target.recordCount>0&&target.recordCount<1024,'integration_plan_invalid');
|
|
38
|
+
need(Array.isArray(plan.sources)&&plan.sources.length<=64&&Array.isArray(plan.documents)
|
|
39
|
+
&&plan.documents.length<=16&&(plan.sources.length+plan.documents.length+(plan.snapshots?.files.length??0))>0,'integration_plan_invalid');
|
|
40
|
+
const ids=new Set();
|
|
41
|
+
for(const source of plan.sources){
|
|
42
|
+
shape(source,['identity','root','revision','packageDigest']);validIdentity(source.identity);absolute(source.root);
|
|
43
|
+
hex(source.revision);hex(source.packageDigest);
|
|
44
|
+
need(source.identity.runId!==target.identity.runId&&!ids.has(source.identity.runId),'integration_source_invalid');
|
|
45
|
+
ids.add(source.identity.runId);
|
|
46
|
+
}
|
|
47
|
+
const paths=new Set();
|
|
48
|
+
for(const doc of plan.documents){
|
|
49
|
+
shape(doc,['path','before','after']);need(documentPath(doc.path)&&!paths.has(doc.path),'integration_document_invalid');
|
|
50
|
+
paths.add(doc.path);
|
|
51
|
+
for(const file of [doc.before,doc.after]){
|
|
52
|
+
shape(file,['path','type','mode','size','sha256']);
|
|
53
|
+
need(file.path===doc.path&&file.type==='file'&&file.mode===0o644&&Number.isSafeInteger(file.size)
|
|
54
|
+
&&file.size>=0&&file.size<=256*1024,'integration_document_invalid');hex(file.sha256);
|
|
55
|
+
}
|
|
56
|
+
need(doc.before.sha256!==doc.after.sha256,'integration_document_invalid');
|
|
57
|
+
}
|
|
58
|
+
return plan;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function bindTarget(plan,baseline,parentPackage,records){
|
|
62
|
+
const base=readReviewBaseline(baseline),pkg=readReviewPackage(parentPackage),target=plan.target;
|
|
63
|
+
need(base.version===2&&pkg.baseIdentity===base.baselineDigest&&pkg.rootDigest===base.rootDigest,'integration_binding_mismatch');
|
|
64
|
+
equal(pkg.identity,base.identity);equal(target.identity,pkg.identity);
|
|
65
|
+
need(target.rootDigest===base.rootDigest&&target.baselineDigest===base.baselineDigest
|
|
66
|
+
&&target.packageDigest===pkg.packageDigest&&target.recordCount===records.length
|
|
67
|
+
&&target.lastDigest===records.at(-1)?.digest,'integration_binding_mismatch');
|
|
68
|
+
for(const doc of plan.documents)need(pkg.scope.includes(doc.path),'integration_document_invalid');
|
|
69
|
+
assertSnapshotBoundaries(plan.snapshots,base,[pkg],learningPaths(records));
|
|
70
|
+
return {base,pkg};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Pure replay validates the exact prefix and keeps historical completion intact.
|
|
74
|
+
// Live use also reopens the pinned review and source stores; absence never clears
|
|
75
|
+
// a gate merely because this record could be parsed.
|
|
76
|
+
export function validateIntegrationRecord({record,baseline,parentPackage,records}){
|
|
77
|
+
const value=json(record,256*1024);shape(value,['version','plan','reviewFile','reason','planDigest']);
|
|
78
|
+
need(value.version===1&&value.reason==='Explicit reviewed integration','integration_record_invalid');
|
|
79
|
+
const plan=readIntegrationPlan(value.plan);equal(value.planDigest,digest(plan));
|
|
80
|
+
shape(value.reviewFile,['path','sha256']);absolute(value.reviewFile.path);hex(value.reviewFile.sha256);
|
|
81
|
+
bindTarget(plan,baseline,parentPackage,records);return value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function readPinnedJson(file){
|
|
85
|
+
absolute(file);need(fs.realpathSync(file)===file,'integration_path_invalid');
|
|
86
|
+
const stat=fs.lstatSync(file);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.nlink===1&&stat.size<=12*1024*1024,'integration_evidence_invalid');
|
|
87
|
+
const fd=fs.openSync(file,fs.constants.O_RDONLY|(fs.constants.O_NOFOLLOW??0));
|
|
88
|
+
try{
|
|
89
|
+
const opened=fs.fstatSync(fd);need(opened.dev===stat.dev&&opened.ino===stat.ino,'integration_evidence_changed');
|
|
90
|
+
const bytes=fs.readFileSync(fd),end=fs.fstatSync(fd),named=fs.lstatSync(file);
|
|
91
|
+
need(end.dev===stat.dev&&end.ino===stat.ino&&end.size===stat.size&&end.mtimeMs===stat.mtimeMs
|
|
92
|
+
&&end.ctimeMs===stat.ctimeMs&&named.ino===stat.ino&&named.dev===stat.dev&&named.nlink===1,'integration_evidence_changed');
|
|
93
|
+
const value=JSON.parse(bytes.toString('utf8'));
|
|
94
|
+
need(bytes.equals(canonical(value)),'integration_evidence_invalid');
|
|
95
|
+
return {value,reference:{path:file,sha256:sha(bytes)}};
|
|
96
|
+
}finally{fs.closeSync(fd);}
|
|
97
|
+
}
|
|
98
|
+
export function readIntegrationEvidenceFile(file){
|
|
99
|
+
const {value,reference}=readPinnedJson(file);shape(value,['plan','review']);
|
|
100
|
+
return {evidence:{plan:readIntegrationPlan(value.plan),review:value.review},reference};
|
|
101
|
+
}
|
|
102
|
+
export const readIntegrationEvidence=file=>readIntegrationEvidenceFile(file).evidence;
|
|
103
|
+
|
|
104
|
+
// rev-parse only, with a project-external executable and no inherited Git
|
|
105
|
+
// environment. No hooks, target programs, filters or working-tree writes.
|
|
106
|
+
function gitCommonDir(root,excludedRoots){
|
|
107
|
+
need(fs.realpathSync(root)===root,'integration_source_invalid');
|
|
108
|
+
const inside=(dir,file)=>file===dir||file.startsWith(dir+path.sep);
|
|
109
|
+
const untrusted=file=>excludedRoots.some(dir=>inside(dir,file));
|
|
110
|
+
let bin=null;const safe=[];
|
|
111
|
+
for(const directory of (process.env.PATH??'').split(path.delimiter)){
|
|
112
|
+
if(!directory||!path.isAbsolute(directory))continue;
|
|
113
|
+
try{
|
|
114
|
+
const dir=fs.realpathSync(directory);if(untrusted(dir))continue;safe.push(dir);
|
|
115
|
+
const candidate=fs.realpathSync(path.join(dir,process.platform==='win32'?'git.exe':'git'));
|
|
116
|
+
if(!bin&&!untrusted(candidate)&&fs.statSync(candidate).isFile()){fs.accessSync(candidate,fs.constants.X_OK);bin=candidate;}
|
|
117
|
+
}catch{}
|
|
118
|
+
}
|
|
119
|
+
need(bin,'integration_git_unavailable');
|
|
120
|
+
const run=args=>spawnSync(bin,['--no-optional-locks','-c','core.fsmonitor=false','-C',root,...args],{
|
|
121
|
+
env:{PATH:safe.join(path.delimiter),HOME:os.tmpdir(),USERPROFILE:os.tmpdir(),LANG:'C',LC_ALL:'C',
|
|
122
|
+
GIT_CONFIG_NOSYSTEM:'1',GIT_CONFIG_GLOBAL:os.devNull,GIT_NO_REPLACE_OBJECTS:'1',GIT_NO_LAZY_FETCH:'1',GIT_TERMINAL_PROMPT:'0',
|
|
123
|
+
...(process.env.SystemRoot?{SystemRoot:process.env.SystemRoot}:{})},
|
|
124
|
+
timeout:5000,maxBuffer:65536});
|
|
125
|
+
const result=run(['rev-parse','--path-format=absolute','--show-toplevel','--git-common-dir']);
|
|
126
|
+
need(!result.error&&result.status===0,'integration_git_unavailable');
|
|
127
|
+
const lines=result.stdout.toString('utf8').trim().split('\n');
|
|
128
|
+
need(lines.length===2&&fs.realpathSync(lines[0])===root,'integration_source_invalid');
|
|
129
|
+
const listing=run(['worktree','list','--porcelain','-z']);
|
|
130
|
+
need(!listing.error&&listing.status===0&&listing.stdout.toString('utf8').split('\0')
|
|
131
|
+
.filter(line=>line==='worktree '+root).length===1,'integration_worktree_mismatch');
|
|
132
|
+
return fs.realpathSync(lines[1]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function hasRename(deliveries,from,to,before){
|
|
136
|
+
const matches=deliveries.flatMap(row=>row.packages).filter(({pkg,reviewedAt})=>{
|
|
137
|
+
if(pkg.identity.repositoryId!==from||!Number.isSafeInteger(reviewedAt)||reviewedAt>=before)return false;
|
|
138
|
+
const change=pkg.changes.find(row=>row.path==='package.json');
|
|
139
|
+
if(!change?.before?.contentBase64||!change?.after?.contentBase64)return false;
|
|
140
|
+
try{return JSON.parse(Buffer.from(change.before.contentBase64,'base64')).name===from
|
|
141
|
+
&&JSON.parse(Buffer.from(change.after.contentBase64,'base64')).name===to;}catch{return false;}
|
|
142
|
+
});
|
|
143
|
+
need(matches.length===1,'integration_repository_transition_unverified');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function resolveSources(plan,{root,specsRoot,deliveries,after}){
|
|
147
|
+
let common=null;const roots=new Map(),result=[];
|
|
148
|
+
const excludedRoots=[root,specsRoot,...plan.sources.map(item=>item.root)];
|
|
149
|
+
for(const source of plan.sources){
|
|
150
|
+
const snapshot=readExecutionSnapshot({specsRoot,identity:{repositoryId:source.identity.repositoryId,runId:source.identity.runId}});
|
|
151
|
+
need(snapshot.revision===source.revision,'integration_source_changed');
|
|
152
|
+
const init=snapshot.records[0]?.payload;
|
|
153
|
+
need(init?.protocol==='cm-task-runner'&&init.version===3&&init.type==='init','integration_source_invalid');
|
|
154
|
+
const history=readRunnerHistory(snapshot.records,init.config,3),state=history.state;
|
|
155
|
+
need(history.pending===null&&state.state==='fixture_completed'&&state.taskCommit?.outcome==='fixture_committed'
|
|
156
|
+
&&history.acceptedFixes.length===0&&!history.acceptedIntegration,'integration_source_not_completed');
|
|
157
|
+
const pkg=readReviewPackage(state.reviewPackage),reviewedAt=approvedReviewAt(state);
|
|
158
|
+
equal(pkg.identity,source.identity);
|
|
159
|
+
need(pkg.packageDigest===source.packageDigest&&init.config.root===source.root
|
|
160
|
+
&&pkg.rootDigest===sha(source.root)&&Number.isSafeInteger(reviewedAt)&&reviewedAt>after,'integration_source_invalid');
|
|
161
|
+
need(source.root!==root||source.identity.repositoryId!==plan.target.identity.repositoryId,'integration_mapping_unnecessary');
|
|
162
|
+
need(fs.realpathSync(source.root)===source.root,'integration_source_invalid');
|
|
163
|
+
if(source.root!==root){
|
|
164
|
+
common??=gitCommonDir(root,excludedRoots);
|
|
165
|
+
if(!roots.has(source.root))roots.set(source.root,gitCommonDir(source.root,excludedRoots));
|
|
166
|
+
need(roots.get(source.root)===common,'integration_worktree_mismatch');
|
|
167
|
+
}
|
|
168
|
+
if(source.identity.repositoryId!==plan.target.identity.repositoryId){
|
|
169
|
+
need(source.root===root,'integration_repository_transition_unverified');
|
|
170
|
+
hasRename(deliveries,plan.target.identity.repositoryId,source.identity.repositoryId,reviewedAt);
|
|
171
|
+
}
|
|
172
|
+
result.push({runId:source.identity.runId,root:source.root,taskId:source.identity.taskId,
|
|
173
|
+
learningPaths:learningPaths(snapshot.records),packages:[{pkg,reviewedAt}]});
|
|
174
|
+
}
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function integrationReviewIndependent({reviewRunId,targetRunId,hostContextId,authorContextId,
|
|
179
|
+
reviewerProvider,authorProvider,reviewerThreadId,previousThreads,developerThreadId}){
|
|
180
|
+
return reviewRunId!==targetRunId
|
|
181
|
+
&&hostContextId===authorContextId
|
|
182
|
+
&&reviewerProvider!==authorProvider
|
|
183
|
+
&&!previousThreads.includes(reviewerThreadId)
|
|
184
|
+
&&reviewerThreadId!==developerThreadId;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function verifyReview(review,plan,records){
|
|
188
|
+
need(review!==null,'integration_review_required');
|
|
189
|
+
shape(review,['configuration','registration','started','result']);
|
|
190
|
+
need(review.configuration?.reviewVerification,'integration_verification_required');
|
|
191
|
+
const registration=inspectFixFinalRegistration(review.registration,review.configuration);
|
|
192
|
+
const checked=inspectFixFinalResult(review.result,registration,review.configuration,review.started);
|
|
193
|
+
need(checked.observationStatus==='completed'&&checked.review.verdict==='approved','integration_review_not_approved');
|
|
194
|
+
const pkg=readReviewPackage(registration.request.payload.reviewPackage);
|
|
195
|
+
const config=records[0].payload.config;
|
|
196
|
+
const previousThreads=readRunnerHistory(records,config,3).reviewerThreads;
|
|
197
|
+
need(integrationReviewIndependent({reviewRunId:pkg.identity.runId,targetRunId:plan.target.identity.runId,
|
|
198
|
+
hostContextId:review.configuration.hostContextId,authorContextId:plan.author.contextId,
|
|
199
|
+
reviewerProvider:registration.request.provider,authorProvider:plan.author.provider,
|
|
200
|
+
reviewerThreadId:checked.providerThreadId,previousThreads,developerThreadId:config.reviewInvocation.developerThreadId}),
|
|
201
|
+
'integration_review_not_independent');
|
|
202
|
+
const file=pkg.requirements.find(item=>item.path==='integration/plan.json')
|
|
203
|
+
??pkg.changes.find(item=>item.path==='integration/plan.json')?.after;
|
|
204
|
+
need(file?.contentBase64===canonical(plan).toString('base64'),'integration_review_binding_mismatch');
|
|
205
|
+
for(const doc of plan.documents){
|
|
206
|
+
const change=pkg.changes.find(item=>item.path==='integration/documents/'+doc.path);
|
|
207
|
+
for(const side of ['before','after']){
|
|
208
|
+
const file=change?.[side];need(file,'integration_document_not_reviewed');
|
|
209
|
+
equal({...meta(file),path:doc.path},doc[side],'integration_document_not_reviewed');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
verifySnapshotReview(pkg,plan.snapshots);
|
|
213
|
+
return checked;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function verifyReviewedIntegration({root,specsRoot,baseline,parentPackage,records,plan:raw,review=null,requireReview=true}){
|
|
217
|
+
const plan=readIntegrationPlan(raw),{base,pkg}=bindTarget(plan,baseline,parentPackage,records);
|
|
218
|
+
need(fs.realpathSync(root)===root&&sha(root)===base.rootDigest,'integration_binding_mismatch');
|
|
219
|
+
const init=records[0]?.payload,history=readRunnerHistory(records,init.config,init.version);
|
|
220
|
+
need(init.version===3&&history.pending===null&&history.state.state==='fixture_completed'
|
|
221
|
+
&&history.state.taskCommit?.outcome==='fixture_committed'&&history.acceptedFixes.length===0
|
|
222
|
+
&&!history.acceptedIntegration,'integration_parent_not_completed');
|
|
223
|
+
equal(history.state.reviewPackage,pkg);
|
|
224
|
+
const after=approvedReviewAt(history.state),since=firstReviewAt(records,pkg.identity);
|
|
225
|
+
need(Number.isSafeInteger(after)&&Number.isSafeInteger(since),'integration_order_unverified');
|
|
226
|
+
const deliveries=completedReviewedDeliveries({specsRoot,root,identity:pkg.identity});
|
|
227
|
+
const sources=resolveSources(plan,{root,specsRoot,deliveries,after});
|
|
228
|
+
if(plan.snapshots){
|
|
229
|
+
const instructions=[...learningPaths(records),...sources.flatMap(row=>row.learningPaths)];
|
|
230
|
+
// Ordinary discovery intentionally keeps its old return contract. Reopen
|
|
231
|
+
// these already-validated journals only for the new snapshot boundary.
|
|
232
|
+
for(const delivery of deliveries){
|
|
233
|
+
const identity=delivery.packages[0].pkg.identity;
|
|
234
|
+
const saved=readExecutionSnapshot({specsRoot,identity:{repositoryId:identity.repositoryId,runId:identity.runId}});
|
|
235
|
+
if(saved.records[0].payload.protocol==='cm-task-runner'){
|
|
236
|
+
const initial=saved.records[0].payload;
|
|
237
|
+
const current=readRunnerHistory(saved.records,initial.config,initial.version);
|
|
238
|
+
need(current.pending===null&¤t.state.state==='fixture_completed'
|
|
239
|
+
&¤t.state.taskCommit?.outcome==='fixture_committed'
|
|
240
|
+
&¤t.state.reviewPackage?.packageDigest===delivery.packages[0].pkg.packageDigest,'integration_source_changed');
|
|
241
|
+
instructions.push(...learningPaths(saved.records));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
assertSnapshotBoundaries(plan.snapshots,base,[pkg,...[...deliveries,...sources].flatMap(row=>row.packages.map(item=>item.pkg))],instructions);
|
|
245
|
+
}
|
|
246
|
+
if(requireReview)verifyReview(review,plan,records);
|
|
247
|
+
explainIntegratedDelivery({root,baseline:base,parentPackage:pkg,deliveries,after,since,sources,documents:plan.documents,snapshots:plan.snapshots});
|
|
248
|
+
// Source snapshots may change while Git and tree comparisons run. Refuse
|
|
249
|
+
// before adoption; this does not authorize rereading a newer revision.
|
|
250
|
+
for(const source of plan.sources)need(readExecutionSnapshot({specsRoot,identity:{repositoryId:source.identity.repositoryId,
|
|
251
|
+
runId:source.identity.runId}}).revision===source.revision,'integration_source_changed');
|
|
252
|
+
return {version:1,planDigest:digest(plan),eligibleForAdoption:requireReview,code:requireReview?null:'integration_review_required',
|
|
253
|
+
paths:[],sourceCount:sources.length};
|
|
254
|
+
}
|
|
255
|
+
export function previewReviewedIntegration(input){
|
|
256
|
+
try{return verifyReviewedIntegration({...input,requireReview:input.review!=null});}
|
|
257
|
+
catch(error){return {version:1,planDigest:digest(input.plan),eligibleForAdoption:false,
|
|
258
|
+
code:typeof error.code==='string'?error.code:'integration_evidence_invalid',
|
|
259
|
+
paths:Array.isArray(error.paths)?error.paths:[],sourceCount:input.plan?.sources?.length??0};}
|
|
260
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Append-only scope evidence for one unreviewed conversation-owned delivery.
|
|
2
|
+
// A reason records the decision; it is not an authentication or grant mechanism.
|
|
3
|
+
import {digest,need} from './effect-contract.mjs';
|
|
4
|
+
import {validateDeveloperScope} from './developer-adapter.mjs';
|
|
5
|
+
import {readReviewScope,extendReviewBaseline} from './review-package.mjs';
|
|
6
|
+
|
|
7
|
+
export function revisedScope(value,current){
|
|
8
|
+
validateDeveloperScope(value);
|
|
9
|
+
const scope=readReviewScope(value);
|
|
10
|
+
need(current.every(file=>scope.includes(file)),'scope_revision_shrink');
|
|
11
|
+
need(scope.length>current.length,'scope_revision_no_additions');
|
|
12
|
+
return scope;
|
|
13
|
+
}
|
|
14
|
+
export function scopeRevisionBinding(s,config,count=0){
|
|
15
|
+
const entry=s.cache.at(-1);
|
|
16
|
+
need(config.controlPolicy?.version===2&&config.controlPolicy.development==='conversation'
|
|
17
|
+
&&config.controlPolicy.bootstrap==='disabled'
|
|
18
|
+
&&config.controlPolicy.qaFix==='disabled'&&config.bootstrap==null
|
|
19
|
+
&&s.state==='blocked'&&s.code==='develop_checks_not_passed'&&s.attempt===1
|
|
20
|
+
&&s.reviewPackage===null&&s.receipt===null&&s.receipts.length===0&&s.priorReview===null
|
|
21
|
+
&&s.reviewInvocation===null&&s.taskCommit==null&&!s.cancellationRequested
|
|
22
|
+
&&!s.cancelAfterCommit&&!s.workflowError&&count===0
|
|
23
|
+
&&entry?.effect.kind==='develop'&&entry.effect.identity.attempt===s.attempt
|
|
24
|
+
&&entry.result.state==='blocked'&&entry.result.code===s.code,'scope_revision_unavailable');
|
|
25
|
+
return {effectId:entry.effect.id,failedCheckpointDigest:digest(entry),previousScopeDigest:digest(config.scope)};
|
|
26
|
+
}
|
|
27
|
+
export function applyScopeRevision(state,config,baseline,record,count=0){
|
|
28
|
+
const expected=scopeRevisionBinding(state,config,count);
|
|
29
|
+
for(const key of Object.keys(expected))need(record[key]===expected[key],'scope_revision_source_changed');
|
|
30
|
+
need(record.baselineDigest===baseline.baselineDigest,'scope_revision_source_changed');
|
|
31
|
+
const scope=revisedScope(record.scope,config.scope);
|
|
32
|
+
need(digest(scope)===digest(record.scope),'invalid_input');
|
|
33
|
+
need(typeof record.reason==='string'&&record.reason.trim().length>0
|
|
34
|
+
&&Buffer.byteLength(record.reason,'utf8')<=500&&!/[\r\n\0]/.test(record.reason),'scope_revision_reason_required');
|
|
35
|
+
need(typeof record.at==='string'&&Number.isFinite(Date.parse(record.at))
|
|
36
|
+
&&new Date(record.at).toISOString()===record.at,'invalid_input');
|
|
37
|
+
return {scope,baseline:extendReviewBaseline(baseline,scope,record.files)};
|
|
38
|
+
}
|
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import {createHash} from 'node:crypto';
|
|
5
5
|
import {verifyApprovedManifest,normalizeRuntimeMarks,normalizeRuntimeMarkBytes} from '../../../scripts/cm-spec-manifest.mjs';
|
|
6
6
|
import {parseFeatureTaskText,declaredAcceptanceIds,DEPENDENCY} from './cm-ai-admission.mjs';
|
|
7
|
-
import {taskLines,TASK_GRAMMAR,
|
|
7
|
+
import {taskLines,TASK_GRAMMAR,recordedTaskGrammar} from '../spec-task-line.mjs';
|
|
8
8
|
import {readReviewSourceFiles,readReviewSourceExcerpt} from './review-package.mjs';
|
|
9
9
|
import {json,need,shape,hex,id,freeze,digest} from './effect-contract.mjs';
|
|
10
10
|
import {readExecutionSnapshot} from './execution-snapshot.mjs';
|
|
@@ -119,7 +119,7 @@ export function captureSpecificationMaterial({specsRoot,feature,taskId}){
|
|
|
119
119
|
need(readReviewSourceFiles(specsRoot,['.cm-specs-status'])[0].sha256===statusRecord.sha256);
|
|
120
120
|
verifyApprovedManifest(specsRoot,statusPath);
|
|
121
121
|
// The approval binds the grammar its bytes were approved with (spec-task-line.mjs).
|
|
122
|
-
const grammar=status.taskGrammar
|
|
122
|
+
const grammar=recordedTaskGrammar(status.taskGrammar);
|
|
123
123
|
const parsed=parseFeatureTaskText(texts['tasks.md'],{allowDependencyPunctuation:true,grammar});
|
|
124
124
|
need(!parsed.error);
|
|
125
125
|
const selected=parsed.tasks.find(task=>task.id===taskId&&!task.dropped);need(selected);
|