@aibyzero/cm-workflow 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +27 -0
- package/CHANGELOG.md +230 -1
- package/CONTRIBUTING.md +47 -0
- package/README.md +21 -3
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/VERSION +1 -1
- package/compat/claude-commands/cm-challenge.md +3 -0
- package/docs/architecture.md +40 -13
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +153 -16
- package/docs/live-evidence-drivers.md +28 -4
- package/docs/out-of-scope/README.md +25 -0
- package/docs/out-of-scope/background-supervisor.md +32 -0
- package/docs/reviewed-integration.md +48 -0
- package/docs/user-guide.md +50 -21
- package/install-codex.sh +331 -18
- package/install.ps1 +28 -2
- package/install.sh +321 -17
- package/package.json +2 -1
- package/runtime/js/cm-ai/batch-location.mjs +55 -0
- package/runtime/js/cm-ai/batch-plan.mjs +242 -0
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +94 -21
- package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-admission.mjs +18 -12
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
- package/runtime/js/cm-ai/codex-config.mjs +6 -2
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
- package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
- package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
- package/runtime/js/cm-ai/control-policy.mjs +24 -6
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +236 -34
- package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
- package/runtime/js/cm-ai/effect-contract.mjs +11 -2
- package/runtime/js/cm-ai/execution-policy.mjs +3 -1
- package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
- package/runtime/js/cm-ai/execution-store.mjs +60 -17
- package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
- package/runtime/js/cm-ai/host-check.mjs +14 -6
- package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
- package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
- package/runtime/js/cm-ai/host-replay.mjs +148 -0
- package/runtime/js/cm-ai/host-session.mjs +42 -9
- package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +22 -9
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
- package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
- package/runtime/js/cm-ai/live-evidence.mjs +28 -6
- package/runtime/js/cm-ai/operator-guidance.mjs +63 -30
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
- package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
- package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
- package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
- package/runtime/js/cm-ai/review-package.mjs +79 -7
- package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
- package/runtime/js/cm-ai/review-presentation.mjs +177 -8
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
- package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
- package/runtime/js/cm-ai/scope-revision.mjs +38 -0
- package/runtime/js/cm-ai/specification-material.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +247 -41
- package/runtime/js/cm-ai/verification-auto.mjs +38 -0
- package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
- package/runtime/js/cm-ai/worker-claude.mjs +35 -13
- package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
- package/runtime/js/cm-ai/worker-codex.mjs +41 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
- package/runtime/js/cm-fix/cause-package.mjs +46 -1
- package/runtime/js/cm-fix/command-correction.mjs +37 -0
- package/runtime/js/cm-fix/cooperative.mjs +12 -0
- package/runtime/js/cm-fix/dossier.mjs +8 -2
- package/runtime/js/cm-fix/execution.mjs +578 -100
- package/runtime/js/cm-fix/final-review.mjs +39 -8
- package/runtime/js/cm-fix/finish.mjs +15 -11
- package/runtime/js/cm-fix/host-review.mjs +65 -10
- package/runtime/js/cm-fix/host.mjs +35 -12
- package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
- package/runtime/js/cm-fix/metrics.mjs +18 -5
- package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
- package/runtime/js/cm-fix/regression.mjs +16 -7
- package/runtime/js/cm-fix/repair.mjs +29 -8
- package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
- package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
- package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
- package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
- package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
- package/runtime/js/cm-fix/review-verification.mjs +214 -0
- package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
- package/runtime/js/cm-fix/start.mjs +6 -3
- package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
- package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
- package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
- package/runtime/js/cm-prd/accepted-design.mjs +8 -0
- package/runtime/js/cm-prd/analysis.mjs +13 -9
- package/runtime/js/cm-prd/change.mjs +37 -16
- package/runtime/js/cm-prd/draft-save.mjs +13 -6
- package/runtime/js/cm-prd/draft.mjs +31 -3
- package/runtime/js/cm-prd/failed-correction.mjs +19 -3
- package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
- package/runtime/js/cm-prd/review-correction.mjs +6 -4
- package/runtime/js/cm-prd/review-disposition.mjs +7 -1
- package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
- package/runtime/js/cm-prd/self-check.mjs +125 -6
- package/runtime/js/cm-prd/session.mjs +30 -1
- package/runtime/js/cm-prd/summary.mjs +38 -17
- package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
- package/runtime/js/cm-prd/tree-digest.mjs +34 -0
- package/runtime/js/cm-prd/validation-reason.mjs +8 -4
- package/runtime/js/cm-security/scan.mjs +1 -1
- package/runtime/js/commander/decision.mjs +44 -0
- package/runtime/js/commander/dispatch-registry.mjs +110 -0
- package/runtime/js/commander/ledger.mjs +265 -0
- package/runtime/js/commander/preflight.mjs +107 -0
- package/runtime/js/notify-later.mjs +13 -0
- package/runtime/js/notify-send.mjs +6 -2
- package/runtime/js/notify.mjs +570 -63
- package/runtime/js/review-findings.mjs +38 -0
- package/runtime/js/session-boundary.mjs +56 -0
- package/runtime/js/session-handoff.mjs +68 -0
- package/runtime/js/spec-task-line.mjs +27 -13
- package/runtime/js/specs-status.mjs +1 -1
- package/runtime/js/task-scope.mjs +197 -0
- package/runtime/logging.md +6 -1
- package/runtime/model-efficiency.md +69 -10
- package/runtime/orchestration.md +3 -1
- package/runtime/project-learning.md +2 -0
- package/runtime/review.md +12 -2
- package/runtime/test-contract.md +1 -0
- package/scripts/ci-test-weights.json +3 -0
- package/scripts/cm-ai-admission.mjs +11 -5
- package/scripts/cm-ai-admission.test.mjs +23 -2
- package/scripts/cm-ai-batch-drive.mjs +79 -18
- package/scripts/cm-ai-batch-drive.test.mjs +169 -3
- package/scripts/cm-ai-batch-host.mjs +38 -9
- package/scripts/cm-ai-batch-host.test.mjs +27 -14
- package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
- package/scripts/cm-ai-batch-location.test.mjs +57 -0
- package/scripts/cm-ai-batch-plan.mjs +52 -0
- package/scripts/cm-ai-batch-plan.test.mjs +397 -0
- package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
- package/scripts/cm-ai-batch-run.mjs +483 -63
- package/scripts/cm-ai-batch-run.test.mjs +23 -4
- package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
- package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
- package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
- package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
- package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
- package/scripts/cm-ai-control-launch.test.mjs +21 -0
- package/scripts/cm-ai-control-policy.test.mjs +82 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
- package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
- package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
- package/scripts/cm-ai-development-rework.test.mjs +423 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +3 -2
- package/scripts/cm-ai-drive.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +37 -5
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host-fixture.mjs +9 -6
- package/scripts/cm-ai-host-protected.test.mjs +1 -1
- package/scripts/cm-ai-host.mjs +60 -19
- package/scripts/cm-ai-host.test.mjs +15 -0
- package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
- package/scripts/cm-ai-integration-independence.test.mjs +23 -0
- package/scripts/cm-ai-integration-launch.test.mjs +240 -0
- package/scripts/cm-ai-integration-preview.mjs +41 -0
- package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
- package/scripts/cm-ai-nested-execution.test.mjs +29 -1
- package/scripts/cm-ai-operator-guidance.test.mjs +71 -0
- package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
- package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
- package/scripts/cm-ai-review-failure.test.mjs +150 -5
- package/scripts/cm-ai-review-timeout.test.mjs +20 -0
- package/scripts/cm-ai-run.mjs +88 -21
- package/scripts/cm-ai-scope-revision.test.mjs +341 -0
- package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
- package/scripts/cm-ai-supersede.test.mjs +28 -0
- package/scripts/cm-ai-verification-auto.test.mjs +99 -0
- package/scripts/cm-announce-hook.mjs +35 -8
- package/scripts/cm-announce-hook.test.mjs +25 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +58 -1
- package/scripts/cm-claude-developer-worker.test.mjs +56 -7
- package/scripts/cm-claude-install-layout.test.mjs +1 -1
- package/scripts/cm-claude-probe.test.mjs +26 -0
- package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +49 -0
- package/scripts/cm-claude-worker.test.mjs +16 -0
- package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
- package/scripts/cm-codex-developer-worker.test.mjs +120 -0
- package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
- package/scripts/cm-codex-prompt-input.test.mjs +153 -0
- package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
- package/scripts/cm-commander-ledger.test.mjs +260 -0
- package/scripts/cm-commander-p2.test.mjs +295 -0
- package/scripts/cm-commander-preflight.mjs +84 -0
- package/scripts/cm-commander.mjs +116 -0
- package/scripts/cm-config-lock.mjs +35 -0
- package/scripts/cm-controlled-correction.test.mjs +10 -1
- package/scripts/cm-developer-failure-code.test.mjs +62 -0
- package/scripts/cm-display-task-id.test.mjs +41 -0
- package/scripts/cm-drive-liveness.test.mjs +83 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
- package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
- package/scripts/cm-external-batch-host.test.mjs +12 -9
- package/scripts/cm-external-process-cleanup.test.mjs +128 -0
- package/scripts/cm-external-qa-fix.test.mjs +89 -7
- package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
- package/scripts/cm-failover.mjs +48 -10
- package/scripts/cm-failover.test.mjs +46 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
- package/scripts/cm-fix-command-correction.mjs +17 -0
- package/scripts/cm-fix-command-correction.test.mjs +211 -0
- package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
- package/scripts/cm-fix-drive.mjs +33 -5
- package/scripts/cm-fix-drive.test.mjs +49 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
- package/scripts/cm-fix-host-review.test.mjs +21 -9
- package/scripts/cm-fix-host.mjs +26 -8
- package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
- package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
- package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
- package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
- package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
- package/scripts/cm-fix-review-preflight.mjs +24 -0
- package/scripts/cm-fix-review-storage.test.mjs +233 -0
- package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
- package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
- package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
- package/scripts/cm-fix-review-verification.test.mjs +146 -0
- package/scripts/cm-fix-revision-transport.test.mjs +81 -0
- package/scripts/cm-fix-source-correction.test.mjs +296 -0
- package/scripts/cm-fix-test-type-correction.mjs +18 -0
- package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
- package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
- package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
- package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
- package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
- package/scripts/cm-fix-verification-recovery.mjs +33 -0
- package/scripts/cm-host-diagnostic.test.mjs +33 -0
- package/scripts/cm-host-liveness.test.mjs +150 -0
- package/scripts/cm-host-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -0
- package/scripts/cm-host-stage-observer.test.mjs +41 -0
- package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
- package/scripts/cm-install-manifest.sh +351 -0
- package/scripts/cm-live-evidence.test.mjs +59 -1
- package/scripts/cm-log-event.mjs +61 -10
- package/scripts/cm-log-event.test.mjs +121 -1
- package/scripts/cm-matt-skills.mjs +576 -0
- package/scripts/cm-matt-skills.test.mjs +550 -0
- package/scripts/cm-notify-command.test.mjs +42 -10
- package/scripts/cm-notify.mjs +14 -10
- package/scripts/cm-notify.test.mjs +625 -75
- package/scripts/cm-patrol.mjs +4 -1
- package/scripts/cm-patrol.test.mjs +23 -5
- package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
- package/scripts/cm-prd-completion.test.mjs +56 -13
- package/scripts/cm-prd-design-phase.test.mjs +78 -8
- package/scripts/cm-prd-draft-save.test.mjs +12 -0
- package/scripts/cm-prd-draft.test.mjs +1 -1
- package/scripts/cm-prd-drive.mjs +13 -6
- package/scripts/cm-prd-drive.test.mjs +46 -2
- package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
- package/scripts/cm-prd-host.mjs +10 -5
- package/scripts/cm-prd-host.test.mjs +4 -2
- package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
- package/scripts/cm-prd-review-disposition.test.mjs +124 -8
- package/scripts/cm-prd-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +16 -1
- package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
- package/scripts/cm-prd-self-check.test.mjs +105 -5
- package/scripts/cm-prd-session-recovery.test.mjs +5 -3
- package/scripts/cm-prd-summary.test.mjs +55 -3
- package/scripts/cm-prd-task-grouping.test.mjs +6 -6
- package/scripts/cm-prd-tree-digest.test.mjs +74 -0
- package/scripts/cm-refactor-drive.mjs +2 -1
- package/scripts/cm-refactor-drive.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +3 -15
- package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
- package/scripts/cm-skill-hints-exam.mjs +149 -0
- package/scripts/cm-skill-hints-install.test.mjs +168 -0
- package/scripts/cm-skill-hints.exam.json +706 -0
- package/scripts/cm-skill-hints.json +119 -0
- package/scripts/cm-skill-hints.mjs +669 -0
- package/scripts/cm-skill-hints.test.mjs +831 -0
- package/scripts/cm-skill-judge.mjs +181 -0
- package/scripts/cm-skill-judge.test.mjs +255 -0
- package/scripts/cm-specs-status.test.mjs +4 -2
- package/scripts/cm-start-check.mjs +208 -0
- package/scripts/cm-start-check.test.mjs +321 -0
- package/scripts/cm-task-gate.mjs +150 -29
- package/scripts/cm-task-gate.test.mjs +73 -1
- package/scripts/cm-task-id-grammar.test.mjs +66 -0
- package/scripts/cm-task-scope.test.mjs +308 -0
- package/scripts/cm-test-suite.mjs +109 -0
- package/scripts/cm-test-suite.test.mjs +162 -0
- package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
- package/scripts/cm-upgrade-compat.test.mjs +239 -0
- package/scripts/cm-workflow-config.mjs +12 -2
- package/scripts/fixtures/fix-verification-claude.mjs +44 -0
- package/scripts/fixtures/host-diagnostic.mjs +33 -0
- package/scripts/fixtures/reviewed-integration.mjs +202 -0
- package/scripts/scan-public-safety.py +1 -0
- package/scripts/session-boundary.test.mjs +170 -0
- package/scripts/test-npm-install.py +14 -3
- package/scripts/test-shell-compat.sh +2 -0
- package/scripts/validate-public-repo.py +1 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N4-review.md +2 -1
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/N8-finish.md +22 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
- package/skills/cm-ai/references/js-host-recovery.md +79 -3
- package/skills/cm-ai/references/js-host.md +89 -17
- package/skills/cm-challenge/SKILL.md +65 -0
- package/skills/cm-challenge/evals/README.md +18 -0
- package/skills/cm-challenge/evals/trigger-cases.json +20 -0
- package/skills/cm-challenge/evals/trigger-config.json +28 -0
- package/skills/cm-challenge/references/examples.md +15 -0
- package/skills/cm-check/SKILL.md +5 -0
- package/skills/cm-check/references/js-host.md +2 -0
- package/skills/cm-fix/SKILL.md +12 -3
- package/skills/cm-fix/references/command-correction.md +67 -0
- package/skills/cm-fix/references/isolated-review.md +54 -0
- package/skills/cm-fix/references/js-host.md +62 -2
- package/skills/cm-fix/references/test-type-correction.md +72 -0
- package/skills/cm-fix/references/verification-recovery.md +114 -0
- package/skills/cm-idea/SKILL.md +2 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-notify/SKILL.md +2 -0
- package/skills/cm-prd/SKILL.md +12 -8
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +6 -0
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-host.md +4 -2
- package/skills/cm-prd/references/spec-self-check.md +5 -1
- package/skills/cm-refactor/SKILL.md +8 -0
- package/skills/cm-refactor/references/js-host.md +2 -0
- package/skills/cm-test/SKILL.md +4 -0
- package/templates/dashboard/dashboard.html +2 -2
- package/templates/pixel/cm-pixel.html +1 -1
- package/templates/pixel/cm-pixel.sh +1 -1
- package/templates/pixel/dev/template.html +1 -1
- package/templates/statusline/cm-statusline.sh +1 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// The verification gate answered by the host (control policy verification:"auto").
|
|
2
|
+
// It accepts the developer's per-requirement report only when every item is
|
|
3
|
+
// satisfied and no tagged item contradicts what the host itself ran
|
|
4
|
+
// (host-replay.mjs). It can only stop: a satisfied verdict still leaves the full
|
|
5
|
+
// independent review, which also reads the host's own replay record.
|
|
6
|
+
//
|
|
7
|
+
// Run claims are matched by their structured tag, never by reading free text:
|
|
8
|
+
// run "red" needs the test-files-only run to have run and failed; run "baseline"
|
|
9
|
+
// needs the baseline to have run (a run that could not start proves nothing) and,
|
|
10
|
+
// with a result, to have that result. An untagged item is not a run claim here.
|
|
11
|
+
// The same limit as the session-answered gate: coverage of every written
|
|
12
|
+
// requirement, and the tagging of every run claim, are not proven.
|
|
13
|
+
const ran=run=>run&&['passed','failed'].includes(run.outcome);
|
|
14
|
+
const redFact=facts=>facts.status!=='replayed'?`未实跑(${facts.reason})`
|
|
15
|
+
:facts.red.skipped?'tasks.md 未写测试文件,没有只放入测试文件的实跑'
|
|
16
|
+
:`只放入测试文件时检查 ${facts.red.outcome}`;
|
|
17
|
+
|
|
18
|
+
// report: the developer's items, null (absent) or 'invalid'. facts: replayDelivery's result.
|
|
19
|
+
export function autoVerificationVerdict({report,facts}){
|
|
20
|
+
if(report===null)return {satisfied:false,unsatisfied:['开发结果没有逐条要求与证据(requirements)']};
|
|
21
|
+
if(report==='invalid')return {satisfied:false,unsatisfied:['开发结果的逐条要求与证据(requirements)格式不合法']};
|
|
22
|
+
const unsatisfied=[],replayed=facts.status==='replayed';
|
|
23
|
+
for(const item of report){
|
|
24
|
+
if(item.satisfied!==true){unsatisfied.push(item.requirement);continue;}
|
|
25
|
+
if(item.run==='red'&&!(replayed&&!facts.red.skipped&&facts.red.outcome==='failed'))
|
|
26
|
+
unsatisfied.push(`${item.requirement}(标记为先失败,宿主实跑与此不符:${redFact(facts)})`);
|
|
27
|
+
if(item.run==='baseline'){
|
|
28
|
+
if(!replayed)unsatisfied.push(`${item.requirement}(标记为基线,宿主没有实跑基线:${facts.reason})`);
|
|
29
|
+
else if(!ran(facts.baseline))unsatisfied.push(`${item.requirement}(标记为基线,宿主基线没有跑起来:${facts.baseline.outcome})`);
|
|
30
|
+
else if(item.result&&item.result!==facts.baseline.outcome)
|
|
31
|
+
unsatisfied.push(`${item.requirement}(标记基线 ${item.result},宿主实跑基线 ${facts.baseline.outcome})`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// The runner stops at develop_checks_not_passed before this gate when the
|
|
35
|
+
// task's own checks fail; kept so the gate never passes a failed delivery.
|
|
36
|
+
if(facts.green.outcome!=='passed')unsatisfied.push(`宿主实跑:全部放入后检查 ${facts.green.outcome}`);
|
|
37
|
+
return unsatisfied.length?{satisfied:false,unsatisfied}:{satisfied:true,items:report};
|
|
38
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {createProviderUsageCapture} from './provider-usage.mjs';
|
|
2
2
|
// Read-only Claude process: edits are text proposals consumed by the protected host.
|
|
3
|
+
import {signalOwnedGroup} from './process-group-exit.mjs';
|
|
3
4
|
import {spawn} from 'node:child_process';
|
|
4
5
|
import {readFileSync} from 'node:fs';
|
|
5
6
|
import {claudeBaseArgs,claudeEnvironment} from './worker-claude.mjs';
|
|
@@ -23,8 +24,10 @@ export function validateClaudeProposal(raw){
|
|
|
23
24
|
shape(result,['status','value','edits']);
|
|
24
25
|
const value=result.value,nullable=v=>v===null||typeof v==='string';
|
|
25
26
|
need(value&&typeof value==='object','invalid_result');
|
|
26
|
-
shape(value,['outcome',...['application','retrospective','reason'].filter(key=>Object.hasOwn(value,key))]);
|
|
27
|
+
shape(value,['outcome',...['application','retrospective','reason','requirements'].filter(key=>Object.hasOwn(value,key))]);
|
|
27
28
|
need(['implemented','blocked'].includes(value.outcome),'invalid_result');
|
|
29
|
+
// The per-requirement report is validated where the host splits it off (requirement-evidence.mjs).
|
|
30
|
+
if(Object.hasOwn(value,'requirements'))need(value.requirements===null||Array.isArray(value.requirements)&&value.requirements.length<=64,'invalid_result');
|
|
28
31
|
if(Object.hasOwn(value,'reason'))need(nullable(value.reason),'invalid_result');
|
|
29
32
|
if(Object.hasOwn(value,'application')){
|
|
30
33
|
shape(value.application,['status','note']);
|
|
@@ -54,6 +57,18 @@ export function validateClaudeProposal(raw){
|
|
|
54
57
|
return result;
|
|
55
58
|
}
|
|
56
59
|
|
|
60
|
+
// Error classes of Claude CLI 2.1.x API failures (as the reviewer stream maps them,
|
|
61
|
+
// claude-review-stream.mjs). A provider developer that hits one ends with the class
|
|
62
|
+
// as its code; the provider text is never kept. The terminal status is unchanged.
|
|
63
|
+
const DEVELOPER_API_ERROR_CLASSES=Object.freeze({authentication_failed:'developer_auth_failed',
|
|
64
|
+
billing_error:'developer_billing_error',rate_limit:'developer_rate_limited',
|
|
65
|
+
server_error:'developer_server_error',model_not_found:'developer_model_not_found'});
|
|
66
|
+
const STARTUP_NOTICES=new Set(['dev_intent','ui_invalidate']);
|
|
67
|
+
function startupNotice(subtype,onNotice){
|
|
68
|
+
if(subtype==='dev_intent')return reportClaudeDevIntentNotice(onNotice);
|
|
69
|
+
if(typeof onNotice!=='function')return;
|
|
70
|
+
try{onNotice({kind:'claude_system_notice',subtype});}catch{}
|
|
71
|
+
}
|
|
57
72
|
function createClaudeDeveloperStream(onNotice=null,onUsageTerminal=null){
|
|
58
73
|
let session=null,initialized=false,done=false,value,assistant=false,noticeCount=0,thinkingCount=0;
|
|
59
74
|
const tools=new Set();
|
|
@@ -63,9 +78,11 @@ function createClaudeDeveloperStream(onNotice=null,onUsageTerminal=null){
|
|
|
63
78
|
need(typeof event.session_id==='string'&&event.session_id.trim()&&event.session_id.length<=128,'invalid_session');
|
|
64
79
|
if(session!==null)need(event.session_id===session,'session_mismatch');
|
|
65
80
|
if(!initialized){
|
|
66
|
-
|
|
81
|
+
// CLI 2.1.289 emits ui_invalidate before init, as the review stream
|
|
82
|
+
// already accepts. A notice never initializes the turn.
|
|
83
|
+
if(event.type==='system'&&STARTUP_NOTICES.has(event.subtype)){
|
|
67
84
|
need(noticeCount<32,'unexpected_event');noticeCount++;
|
|
68
|
-
session=event.session_id;
|
|
85
|
+
session=event.session_id;startupNotice(event.subtype,onNotice);return;
|
|
69
86
|
}
|
|
70
87
|
need(event.type==='system'&&event.subtype==='init','missing_init');
|
|
71
88
|
session=event.session_id;initialized=true;return;
|
|
@@ -75,13 +92,19 @@ function createClaudeDeveloperStream(onNotice=null,onUsageTerminal=null){
|
|
|
75
92
|
reportClaudeRateLimitNotice(event.rate_limit_info,onNotice);return;
|
|
76
93
|
}
|
|
77
94
|
if(event.type==='system'){
|
|
78
|
-
if(event.subtype
|
|
95
|
+
if(STARTUP_NOTICES.has(event.subtype)){
|
|
79
96
|
need(noticeCount<32,'unexpected_event');noticeCount++;
|
|
80
|
-
|
|
97
|
+
startupNotice(event.subtype,onNotice);return;
|
|
81
98
|
}
|
|
82
|
-
|
|
99
|
+
// Long developer turns emit one usage heartbeat per thinking step; same cap as the
|
|
100
|
+
// reviewer stream (claude-review-stream.mjs), with the 4 MB output limit behind it.
|
|
101
|
+
need(event.subtype==='thinking_tokens'&&thinkingCount<4096,'unexpected_event');thinkingCount++;return;
|
|
83
102
|
}
|
|
84
103
|
if(event.type==='assistant'){
|
|
104
|
+
// CLI 2.1.x reports an API failure as a synthetic assistant message carrying the
|
|
105
|
+
// error class, before any tool call; the is_error result follows.
|
|
106
|
+
if(typeof event.error==='string'&&event.parent_tool_use_id===null&&event.message?.role==='assistant'&&tools.size===0)
|
|
107
|
+
need(false,Object.hasOwn(DEVELOPER_API_ERROR_CLASSES,event.error)?DEVELOPER_API_ERROR_CLASSES[event.error]:'developer_api_error');
|
|
85
108
|
need(event.parent_tool_use_id===null&&event.error==null&&event.message?.role==='assistant','unexpected_assistant');
|
|
86
109
|
need(Array.isArray(event.message.content)&&event.message.content.length>0,'invalid_event');
|
|
87
110
|
let substantive=false;
|
|
@@ -146,18 +169,19 @@ export function claudeDeveloperWorker({cwd,model,effort,cli='claude',timeoutMs=1
|
|
|
146
169
|
let buffer='',bytes=0;
|
|
147
170
|
const stream=createClaudeDeveloperStream(onNotice,value=>usage.terminal(value));
|
|
148
171
|
let failure=null,closed=false,timer,cleanup;
|
|
149
|
-
|
|
172
|
+
// signalOwnedGroup (process-group-exit.mjs): an exited, not yet reaped leader
|
|
173
|
+
// (EPERM on macOS) is a stop only once its exit is observed and a re-probe
|
|
174
|
+
// answers ESRCH; anything unproven is a cleanup failure, as before.
|
|
175
|
+
const signalGroup=async signalName=>{
|
|
150
176
|
if(!Number.isInteger(child.pid)||child.pid<=0)return false;
|
|
151
|
-
try{
|
|
152
|
-
catch
|
|
177
|
+
try{return await signalOwnedGroup(child,signalName)==='sent';}
|
|
178
|
+
catch{failure??='process_cleanup_failed';return false;}
|
|
153
179
|
};
|
|
154
|
-
const cleanGroup=()=>{
|
|
155
|
-
if(
|
|
156
|
-
if(!signalGroup('SIGTERM'))return cleanup=Promise.resolve();
|
|
180
|
+
const cleanGroup=()=>cleanup??=(async()=>{
|
|
181
|
+
if(!await signalGroup('SIGTERM'))return;
|
|
157
182
|
// Keep escalation alive even when the leader closes its own pipes first.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
};
|
|
183
|
+
await new Promise(done=>setTimeout(done,1000));await signalGroup('SIGKILL');
|
|
184
|
+
})();
|
|
161
185
|
const stop=code=>{
|
|
162
186
|
failure??=code;
|
|
163
187
|
if(closed)return;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {createProviderUsageCapture} from './provider-usage.mjs';
|
|
2
|
+
import {VERIFICATION_TOOLS,readReviewVerification} from '../cm-fix/review-verification-contract.mjs';
|
|
2
3
|
import {externalEffort} from './external-models.mjs';
|
|
3
4
|
import {spawn} from 'node:child_process';
|
|
4
5
|
import {createHash} from 'node:crypto';
|
|
@@ -15,21 +16,33 @@ export function claudeBaseArgs(model,effort=null) {
|
|
|
15
16
|
'--permission-mode','dontAsk','--no-chrome','--no-session-persistence',
|
|
16
17
|
'--prompt-suggestions','false'];
|
|
17
18
|
}
|
|
18
|
-
export function claudeReviewArgs(model,effort=null) {
|
|
19
|
+
export function claudeReviewArgs(model,effort=null,verification=null,transport=null) {
|
|
19
20
|
const args=claudeBaseArgs(model,effort);
|
|
21
|
+
if(verification){
|
|
22
|
+
readReviewVerification(verification);
|
|
23
|
+
// safe-mode suppresses even explicitly configured MCP servers. Restricted
|
|
24
|
+
// mode keeps native tools disabled while allowing this fixed stdio server.
|
|
25
|
+
args[args.indexOf('--safe-mode')]='--restricted';
|
|
26
|
+
args.push('--settings',JSON.stringify({disableAllHooks:true,enabledPlugins:{},autoMemoryEnabled:false}));
|
|
27
|
+
args[args.indexOf('--mcp-config')+1]=transport?.mcpConfig??'CM_ISOLATED_REVIEW_TOOLS';
|
|
28
|
+
args.push('--allowedTools',...VERIFICATION_TOOLS);
|
|
29
|
+
}
|
|
20
30
|
const schema=JSON.parse(readFileSync(new URL('./review-result.schema.json',import.meta.url),'utf8'));
|
|
21
31
|
// Claude's schema engine does not accept the draft-2020-12 metadata.
|
|
22
32
|
delete schema.$schema;delete schema.$id;
|
|
23
33
|
return [...args,'--json-schema',JSON.stringify(schema)];
|
|
24
34
|
}
|
|
25
|
-
export function claudeReviewFingerprint({cwd,model,cli='claude',effort=null}) {
|
|
26
|
-
return createHash('sha256').update(JSON.stringify({cwd,cli,args:claudeReviewArgs(model,effort),
|
|
35
|
+
export function claudeReviewFingerprint({cwd,model,cli='claude',effort=null,verification=null}) {
|
|
36
|
+
return createHash('sha256').update(JSON.stringify({cwd,cli,args:claudeReviewArgs(model,effort,verification),...(verification?{verification:readReviewVerification(verification)}:{}),
|
|
27
37
|
environmentPolicy:1,promptTransport:'stdin'})).digest('hex');
|
|
28
38
|
}
|
|
29
39
|
export function claudeEnvironment() {
|
|
30
|
-
|
|
40
|
+
// CM_NOTIFY_OFF kept for the same reason as in cleanEnvironment (codex-config.mjs).
|
|
41
|
+
const allowed=['PATH','HOME','USER','LOGNAME','TMPDIR','LANG','LC_ALL','ANTHROPIC_API_KEY','CM_NOTIFY_OFF'];
|
|
31
42
|
return {...Object.fromEntries(Object.entries(process.env).filter(([key])=>allowed.includes(key))),
|
|
32
|
-
CLAUDE_CODE_MAX_RETRIES:'0',CLAUDE_CODE_RETRY_WATCHDOG:'0'
|
|
43
|
+
CLAUDE_CODE_MAX_RETRIES:'0',CLAUDE_CODE_RETRY_WATCHDOG:'0',
|
|
44
|
+
// CM's own sessions are not a person typing: the skill-hints hook stays out of them.
|
|
45
|
+
CM_SKILL_HINTS:'off'};
|
|
33
46
|
}
|
|
34
47
|
export function claudePreflightMatches(receipt,options) {
|
|
35
48
|
return receipt?.passed===true && receipt.provider==='claude'
|
|
@@ -39,16 +52,17 @@ export function claudePreflightMatches(receipt,options) {
|
|
|
39
52
|
// Diagnostic receipt is NOT authorization. Only the original V3 owner may dispatch this worker.
|
|
40
53
|
// A matching diagnostic receipt remains required separately from the V3 grant.
|
|
41
54
|
export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,spawnProcess=spawn,effort=null,
|
|
42
|
-
killProcess=(pid,signal)=>process.kill(pid,signal),onNotice=null,onUsage=null,onUsageClaim=null}) {
|
|
43
|
-
const args=claudeReviewArgs(model,effort);
|
|
55
|
+
killProcess=(pid,signal)=>process.kill(pid,signal),onNotice=null,onDiagnostic=null,onUsage=null,onUsageClaim=null,verification=null,verificationTransport=null}) {
|
|
56
|
+
const args=claudeReviewArgs(model,effort,verification,verificationTransport);
|
|
44
57
|
if (!Number.isSafeInteger(timeoutMs)||timeoutMs<1) throw new Error('invalid_timeout');
|
|
45
58
|
let used=false;
|
|
46
59
|
return async (request,{signal,onEvent,onTerminal})=>{
|
|
47
60
|
if (process.platform==='win32') return {status:'blocked',code:'unsupported_process_cleanup'};
|
|
48
61
|
if (used) return {status:'blocked',code:'worker_dispatch_limit'};
|
|
49
|
-
if (!claudePreflightMatches(preflight,{cwd,model,cli,effort})) {
|
|
62
|
+
if (!claudePreflightMatches(preflight,{cwd,model,cli,effort,verification})) {
|
|
50
63
|
return {status:'blocked',code:'tool_preflight_missing'};
|
|
51
64
|
}
|
|
65
|
+
if (verification&&!verificationTransport?.mcpConfig) return {status:'blocked',code:'review_verification_transport_missing'};
|
|
52
66
|
if (signal.aborted) return {status:'cancelled',code:'cancelled_before_dispatch'};
|
|
53
67
|
if (typeof request?.prompt!=='string') return {status:'failed',code:'invalid_prompt'};
|
|
54
68
|
used=true;
|
|
@@ -56,10 +70,17 @@ export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,s
|
|
|
56
70
|
try{onUsageClaim?.();}catch{}
|
|
57
71
|
return new Promise(resolve=>{
|
|
58
72
|
let child;
|
|
59
|
-
try { child=spawnProcess(cli,args,{cwd,env:claudeEnvironment(),stdio:['pipe','pipe','pipe'],detached:true}); }
|
|
73
|
+
try { child=spawnProcess(cli,args,{cwd:verificationTransport?.cwd??cwd,env:claudeEnvironment(),stdio:['pipe','pipe','pipe'],detached:true}); }
|
|
60
74
|
catch { usage.complete();resolve({status:'failed',code:'spawn_failed'});return; }
|
|
61
75
|
let buffer='', bytes=0, failure=null, settled=false, timedOut=false, killTimer, pendingClose;
|
|
62
|
-
let providerThread=null,providerTerminal=false,failedTerminal=false,receiptInvalid=false,failureDetail=null;
|
|
76
|
+
let providerThread=null,providerTerminal=false,failedTerminal=false,receiptInvalid=false,failureDetail=null,diagnosticReported=false;
|
|
77
|
+
// Optional, body-free diagnostics are separate from the strict observation
|
|
78
|
+
// receipt. Neither a callback nor its failure can change provider outcome.
|
|
79
|
+
const reportDiagnostic=error=>{
|
|
80
|
+
if(diagnosticReported||failure!==null||!error?.failureDetail)return;
|
|
81
|
+
diagnosticReported=true;
|
|
82
|
+
try{if(typeof onDiagnostic==='function')onDiagnostic({code:error.code,failureDetail:error.failureDetail});}catch{}
|
|
83
|
+
};
|
|
63
84
|
// The boundary code carries the stream's body-free summary so the record
|
|
64
85
|
// shows what was rejected; stop() and callers keep matching the base code.
|
|
65
86
|
const withDetail=code=>code==='unexpected_tool_or_content'&&failureDetail!==null
|
|
@@ -73,7 +94,7 @@ export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,s
|
|
|
73
94
|
if(event.event==='thread.started')providerThread=event.provider_thread;
|
|
74
95
|
if(event.event==='turn.completed')providerTerminal=true;
|
|
75
96
|
onEvent(event);
|
|
76
|
-
},onNotice);
|
|
97
|
+
},onNotice,verification?VERIFICATION_TOOLS:[]);
|
|
77
98
|
const stop=code=>{
|
|
78
99
|
if(!['cancelled','timeout','provider_failed','reviewer_auth_failed','reviewer_billing_error',
|
|
79
100
|
'reviewer_rate_limited','reviewer_server_error','reviewer_model_not_found','reviewer_api_error'].includes(code))receiptInvalid=true;
|
|
@@ -115,6 +136,7 @@ export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,s
|
|
|
115
136
|
stream.accept(message);
|
|
116
137
|
}
|
|
117
138
|
catch (error) {
|
|
139
|
+
reportDiagnostic(error);
|
|
118
140
|
if(failure===null&&error?.code==='unexpected_tool_or_content'&&error.detail)failureDetail=error.detail;
|
|
119
141
|
stop(error instanceof SyntaxError?'invalid_event':error.code??'invalid_event');
|
|
120
142
|
}
|
|
@@ -139,7 +161,7 @@ export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,s
|
|
|
139
161
|
if (buffer.trim()) accept(buffer);
|
|
140
162
|
pendingClose=async()=>{
|
|
141
163
|
settled=true;clean();
|
|
142
|
-
if(typeof onTerminal==='function')try{await cleanupGroup();}catch{failure='process_cleanup_unknown';}
|
|
164
|
+
if(verification||typeof onTerminal==='function')try{await cleanupGroup();}catch{failure='process_cleanup_unknown';}
|
|
143
165
|
usage.complete();
|
|
144
166
|
onEvent({event:'process_closed',exit_code:code,signal:exitSignal,timed_out:timedOut});
|
|
145
167
|
if(failure==='process_cleanup_unknown'){resolve({status:'failed',code:failure});return;}
|
|
@@ -152,7 +174,7 @@ export function claudeWorker({cwd,model,preflight,cli='claude',timeoutMs=60000,s
|
|
|
152
174
|
resolve({status:'failed',code:withDetail(failure??'incomplete_result')});return;
|
|
153
175
|
}
|
|
154
176
|
try {resolve(stream.finish());}
|
|
155
|
-
catch(error){resolve({status:'failed',code:error.code??'incomplete_result'});}
|
|
177
|
+
catch(error){reportDiagnostic(error);resolve({status:'failed',code:error.code??'incomplete_result'});}
|
|
156
178
|
};
|
|
157
179
|
// Leader close does not prove group cleanup: redirected descendant pipes may close early.
|
|
158
180
|
if (!killTimer) pendingClose();
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import {createProviderUsageCapture} from './provider-usage.mjs';
|
|
2
2
|
// Coding subprocess only. The host must authorize the task and select an isolated
|
|
3
3
|
// code workspace; workspace-write is not a per-file scope enforcement mechanism.
|
|
4
|
+
import {signalOwnedGroup} from './process-group-exit.mjs';
|
|
4
5
|
import {spawn} from 'node:child_process';
|
|
5
6
|
import {fileURLToPath} from 'node:url';
|
|
6
7
|
import {commonArgs,cleanEnvironment,specsPermissionArgs} from './codex-config.mjs';
|
|
7
8
|
import {need,text,validCallTimeout,json} from './effect-contract.mjs';
|
|
9
|
+
import {CODEX_RECONNECT_NOTICE_LIMIT,isCodexReconnectNotice} from './codex-reconnect-notice.mjs';
|
|
10
|
+
import {codexRateLimited,CODEX_FAILURE_GRACE_MS} from './worker-codex.mjs';
|
|
11
|
+
// A provider terminal (failed turn) still lets the usage of a later turn.failed through.
|
|
12
|
+
const PROVIDER_ENDED=new Set(['provider_failed']);
|
|
8
13
|
|
|
9
14
|
export function developerArgs({cwd,model,effort,schemaPath,disabledSkills=[],specsRoot=null}) {
|
|
10
15
|
text(cwd);text(schemaPath);
|
|
@@ -49,19 +54,20 @@ export function codexDeveloperWorker({cwd,model,effort,learning=true,specsRoot=n
|
|
|
49
54
|
try{child=spawnProcess(cli,args,{cwd,env:cleanEnvironment(),stdio:['pipe','pipe','pipe'],shell:false,detached:true});}
|
|
50
55
|
catch{usage.complete();resolve({status:'unavailable',code:'spawn_failed'});return;}
|
|
51
56
|
let buffer='',bytes=0,thread=null,turnStarted=false,completed=false,lastMessage=null;
|
|
52
|
-
let failure=null,closed=false,timer,cleanup,noticeCount=0;
|
|
53
|
-
|
|
57
|
+
let failure=null,providerFailed=false,closed=false,timer,failureGrace,cleanup,noticeCount=0,reconnectNoticeCount=0,rateLimited=false;
|
|
58
|
+
// signalOwnedGroup (process-group-exit.mjs): an exited, not yet reaped leader
|
|
59
|
+
// (EPERM on macOS) is a stop only once its exit is observed and a re-probe
|
|
60
|
+
// answers ESRCH; anything unproven is a cleanup failure, as before.
|
|
61
|
+
const signalGroup=async signalName=>{
|
|
54
62
|
if(!Number.isInteger(child.pid)||child.pid<=0)return false;
|
|
55
|
-
try{
|
|
56
|
-
catch
|
|
63
|
+
try{return await signalOwnedGroup(child,signalName)==='sent';}
|
|
64
|
+
catch{failure??='process_cleanup_failed';return false;}
|
|
57
65
|
};
|
|
58
|
-
const cleanGroup=()=>{
|
|
59
|
-
if(
|
|
60
|
-
if(!signalGroup('SIGTERM'))return cleanup=Promise.resolve();
|
|
66
|
+
const cleanGroup=()=>cleanup??=(async()=>{
|
|
67
|
+
if(!await signalGroup('SIGTERM'))return;
|
|
61
68
|
// Keep escalation alive even when the leader closes its own pipes first.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
69
|
+
await new Promise(done=>setTimeout(done,1000));await signalGroup('SIGKILL');
|
|
70
|
+
})();
|
|
65
71
|
const stop=code=>{
|
|
66
72
|
failure??=code;
|
|
67
73
|
if(closed)return;
|
|
@@ -72,12 +78,29 @@ export function codexDeveloperWorker({cwd,model,effort,learning=true,specsRoot=n
|
|
|
72
78
|
timer=setTimeout(()=>stop('timeout'),timeoutMs);
|
|
73
79
|
if(signal.aborted)abort();
|
|
74
80
|
const accept=line=>{
|
|
75
|
-
if(!line.trim()||failure
|
|
81
|
+
if(!line.trim()||failure&&!PROVIDER_ENDED.has(failure))return;
|
|
76
82
|
let event;try{event=JSON.parse(line);}catch{stop('invalid_event');return;}
|
|
77
83
|
if(!event||Array.isArray(event)||typeof event.type!=='string'){stop('invalid_event');return;}
|
|
78
84
|
if(event.type==='turn.failed'&&thread&&turnStarted&&!completed)usage.terminal(event.usage);
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
// Like the Codex reviewer (worker-codex.mjs): every failure event of the turn,
|
|
86
|
+
// the first or a later one, may name the rate limit; only the class is kept.
|
|
87
|
+
if((event.type==='error'&&!isCodexReconnectNotice(event)||event.type==='turn.failed')&&codexRateLimited(event))rateLimited=true;
|
|
88
|
+
// After a provider failure only further failure lines count: they stop at once.
|
|
89
|
+
if(providerFailed||PROVIDER_ENDED.has(failure)){
|
|
90
|
+
if(event.type==='turn.failed'||event.type==='error'&&!isCodexReconnectNotice(event))stop('provider_failed');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// Reconnects may precede thread initialization, but never bypass a
|
|
94
|
+
// completed turn. Keep their budget separate from item notices.
|
|
95
|
+
if(!completed&&isCodexReconnectNotice(event)&&reconnectNoticeCount<CODEX_RECONNECT_NOTICE_LIMIT){
|
|
96
|
+
reconnectNoticeCount++;
|
|
97
|
+
try{if(typeof onNotice==='function')onNotice(event.message.slice(0,200));}catch{}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// A lone error waits a short grace for the turn.failed that may name the class.
|
|
101
|
+
if(event.type==='turn.failed'){stop('provider_failed');return;}
|
|
102
|
+
// The fact is kept apart from failure, so a cancel or timeout in the grace keeps its code.
|
|
103
|
+
if(event.type==='error'){providerFailed=true;if(!closed)failureGrace=setTimeout(()=>stop('provider_failed'),CODEX_FAILURE_GRACE_MS);return;}
|
|
81
104
|
if(completed){
|
|
82
105
|
stop(event.type==='item.completed'&&event.item?.type==='error'?'invalid_event':'event_after_terminal');return;
|
|
83
106
|
}
|
|
@@ -113,7 +136,7 @@ export function codexDeveloperWorker({cwd,model,effort,learning=true,specsRoot=n
|
|
|
113
136
|
child.stderr.resume();
|
|
114
137
|
child.stdout.setEncoding('utf8');
|
|
115
138
|
child.stdout.on('data',chunk=>{
|
|
116
|
-
if(failure
|
|
139
|
+
if(failure&&!PROVIDER_ENDED.has(failure)||closed)return;
|
|
117
140
|
bytes+=Buffer.byteLength(chunk);if(bytes>4*1024*1024){stop('output_limit');return;}
|
|
118
141
|
buffer+=chunk;let index;
|
|
119
142
|
while((index=buffer.indexOf('\n'))!==-1){accept(buffer.slice(0,index));buffer=buffer.slice(index+1);}
|
|
@@ -125,12 +148,15 @@ export function codexDeveloperWorker({cwd,model,effort,learning=true,specsRoot=n
|
|
|
125
148
|
// Background commands must not outlive a normally exiting coding leader.
|
|
126
149
|
child.once('exit',()=>{cleanGroup();});
|
|
127
150
|
child.once('close',async(code,exitSignal)=>{
|
|
128
|
-
closed=true;clearTimeout(timer);signal.removeEventListener('abort',abort);
|
|
151
|
+
closed=true;clearTimeout(timer);clearTimeout(failureGrace);signal.removeEventListener('abort',abort);
|
|
129
152
|
await cleanGroup();
|
|
130
153
|
if(buffer.trim())accept(buffer);
|
|
131
154
|
usage.complete();
|
|
132
|
-
|
|
133
|
-
|
|
155
|
+
const ended=failure??(providerFailed?'provider_failed':null);
|
|
156
|
+
if(ended||code!==0||exitSignal||!completed||lastMessage===null){
|
|
157
|
+
// provider_failed stays the internal terminal; the published code names a rate limit.
|
|
158
|
+
resolve({status:ended==='spawn_failed'?'unavailable':'unknown',
|
|
159
|
+
code:ended==='provider_failed'&&rateLimited?'developer_rate_limited':ended??'incomplete_result'});return;
|
|
134
160
|
}
|
|
135
161
|
try{resolve({status:'succeeded',value:json(JSON.parse(lastMessage)),providerThread:thread});}
|
|
136
162
|
catch{resolve({status:'unknown',code:'invalid_output_json'});}
|
|
@@ -2,6 +2,7 @@ import {createProviderUsageCapture} from './provider-usage.mjs';
|
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { commonArgs, cleanEnvironment, configFingerprint } from './codex-config.mjs';
|
|
4
4
|
import {ownedProcessCleanup} from './owned-process-cleanup.mjs';
|
|
5
|
+
import {CODEX_RECONNECT_NOTICE_LIMIT,isCodexReconnectNotice} from './codex-reconnect-notice.mjs';
|
|
5
6
|
|
|
6
7
|
// A preflight receipt is diagnostic evidence, not a human approval token.
|
|
7
8
|
export function preflightMatches(receipt, options) {
|
|
@@ -28,6 +29,18 @@ function validEventShape(message) {
|
|
|
28
29
|
return true;
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
// A failed turn whose provider text names HTTP 429 / Too Many Requests / a rate
|
|
33
|
+
// limit is the same class the Claude reviewer reports (reviewer_rate_limited).
|
|
34
|
+
// Only the class leaves this file; the provider text is never kept or published.
|
|
35
|
+
const RATE_LIMITED=/(?<![0-9])429(?![0-9])|too many requests|rate[ _-]?limit/i;
|
|
36
|
+
const failureText=message=>message.type==='error'?message.message:message.error?.message;
|
|
37
|
+
export const codexRateLimited=message=>{const text=failureText(message);
|
|
38
|
+
return typeof text==='string'&&RATE_LIMITED.test(text.slice(0,2000));};
|
|
39
|
+
|
|
40
|
+
// Codex can write the generic error line before the turn.failed naming the class
|
|
41
|
+
// (e.g. a 429). A lone error waits this long for it before the group is stopped.
|
|
42
|
+
export const CODEX_FAILURE_GRACE_MS=2000;
|
|
43
|
+
|
|
31
44
|
export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
|
|
32
45
|
disabledSkills = [], cli = 'codex', timeoutMs = 60000,
|
|
33
46
|
promptTransport = 'argument', spawnProcess = spawn, onNotice = null,onUsage=null,onUsageClaim=null }) {
|
|
@@ -47,8 +60,10 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
|
|
|
47
60
|
});
|
|
48
61
|
const cleanupGroup=ownedProcessCleanup(child);
|
|
49
62
|
let buffer = '', outputBytes = 0, value, completion = false, failure, settled = false;
|
|
50
|
-
let failureTerminal = false, noticeCount = 0, receiptInvalid=false;
|
|
51
|
-
|
|
63
|
+
let failureTerminal = false, noticeCount = 0, reconnectNoticeCount = 0, receiptInvalid=false, rateLimited=false;
|
|
64
|
+
// provider_failed stays the internal code; the published one names the class.
|
|
65
|
+
const published=code=>code==='provider_failed'&&rateLimited?'reviewer_rate_limited':code;
|
|
66
|
+
let failureGrace, providerFailed = false, providerThread, turnStarted = false, usageContextInvalid=false, timedOut = false, closeTimer, closing=false, terminationRequested=false;
|
|
52
67
|
const cleanup=()=>process.platform==='win32'&&!terminationRequested?Promise.resolve():
|
|
53
68
|
cleanupGroup().catch(()=>{failure='process_cleanup_unknown';});
|
|
54
69
|
const stop = code => {
|
|
@@ -73,6 +88,15 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
|
|
|
73
88
|
let message;
|
|
74
89
|
try { message = JSON.parse(line); } catch { stop('invalid_event'); return; }
|
|
75
90
|
if (!validEventShape(message)) { stop('invalid_event'); return; }
|
|
91
|
+
// While a lone error waits for its turn.failed, only further failure lines count.
|
|
92
|
+
if (failureGrace !== undefined && message.type !== 'turn.failed' && message.type !== 'error') return;
|
|
93
|
+
// Codex emits reconnect notices as errors but may subsequently recover.
|
|
94
|
+
// Keep a separate bounded notice budget; overflow follows fatal handling.
|
|
95
|
+
if (isCodexReconnectNotice(message) && reconnectNoticeCount < CODEX_RECONNECT_NOTICE_LIMIT) {
|
|
96
|
+
reconnectNoticeCount++;
|
|
97
|
+
try { if (typeof onNotice === 'function') onNotice(message.message.slice(0, 200)); } catch {}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
76
100
|
// Notices stay outside the observer protocol and result contract.
|
|
77
101
|
if (message.type === 'item.completed' && message.item.type === 'error') {
|
|
78
102
|
if (typeof message.item.message !== 'string' || !providerThread
|
|
@@ -93,6 +117,7 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
|
|
|
93
117
|
}
|
|
94
118
|
if (message.type === 'turn.started') {if(!providerThread)usageContextInvalid=true;turnStarted = true;}
|
|
95
119
|
const isFailureTerminal = message.type === 'turn.failed' || message.type === 'error';
|
|
120
|
+
if (isFailureTerminal && codexRateLimited(message)) rateLimited = true;
|
|
96
121
|
// The generic error notice can precede the official turn.failed event.
|
|
97
122
|
// Preserve one normalized failure, while accounting only native terminals.
|
|
98
123
|
if(message.type==='turn.failed'&&providerThread&&turnStarted&&!completion&&!usageContextInvalid)usage.terminal(message.usage);
|
|
@@ -113,7 +138,16 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
|
|
|
113
138
|
try { value = JSON.parse(message.item.text); } catch { stop('invalid_output_json'); }
|
|
114
139
|
}
|
|
115
140
|
if (message.type === 'turn.completed') {completion = true;if(providerThread&&turnStarted&&!failureTerminal&&!usageContextInvalid)usage.terminal(message.usage);}
|
|
116
|
-
|
|
141
|
+
// A turn.failed (or a second failure line, above) stops at once; a lone error
|
|
142
|
+
// stops after the grace, so a turn.failed written right after it is still read.
|
|
143
|
+
if (isFailureTerminal) {
|
|
144
|
+
if (message.type === 'turn.failed') stop('provider_failed');
|
|
145
|
+
else {
|
|
146
|
+
// Kept apart from failure, so a cancel or timeout in the grace keeps its code.
|
|
147
|
+
providerFailed = true;
|
|
148
|
+
if (!closing) failureGrace ??= setTimeout(() => stop('provider_failed'), CODEX_FAILURE_GRACE_MS);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
117
151
|
}
|
|
118
152
|
child.stdout.on('data', chunk => {
|
|
119
153
|
if (settled) return;
|
|
@@ -126,7 +160,7 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
|
|
|
126
160
|
}
|
|
127
161
|
});
|
|
128
162
|
const clean = () => {
|
|
129
|
-
clearTimeout(timer); clearTimeout(closeTimer); signal.removeEventListener('abort', onAbort);
|
|
163
|
+
clearTimeout(timer); clearTimeout(closeTimer); clearTimeout(failureGrace); signal.removeEventListener('abort', onAbort);
|
|
130
164
|
};
|
|
131
165
|
child.once('error', async () => {
|
|
132
166
|
if(settled)return;settled=true;closing=true;clean();await cleanup();
|
|
@@ -145,12 +179,12 @@ export function codexWorker({ cwd, model, schemaPath, preflight, effort='high',
|
|
|
145
179
|
// Windows/direct-child exit and uncertain cleanup cannot issue this receipt.
|
|
146
180
|
if(process.platform!=='win32'&&failure!=='process_cleanup_unknown'&&!receiptInvalid&&typeof onTerminal==='function'){
|
|
147
181
|
if(completion&&providerThread&&value!==undefined)onTerminal({status:'succeeded',value});
|
|
148
|
-
else if(failureTerminal&&providerThread)onTerminal({status:'failed',code:'provider_failed'});
|
|
182
|
+
else if(failureTerminal&&providerThread)onTerminal({status:'failed',code:published('provider_failed')});
|
|
149
183
|
}
|
|
150
184
|
if(failure==='process_cleanup_unknown')resolve({status:'failed',code:failure});
|
|
151
185
|
else if (signal.aborted) resolve({ status: 'cancelled', code: 'cancelled' });
|
|
152
|
-
else if (failure || code !== 0 || !completion || !providerThread || value === undefined) {
|
|
153
|
-
resolve({ status: 'failed', code: failure ?? 'incomplete_result' });
|
|
186
|
+
else if (failure || providerFailed || code !== 0 || !completion || !providerThread || value === undefined) {
|
|
187
|
+
resolve({ status: 'failed', code: published(failure ?? (providerFailed ? 'provider_failed' : 'incomplete_result')) });
|
|
154
188
|
} else resolve({ status: 'succeeded', value });
|
|
155
189
|
});
|
|
156
190
|
if(promptTransport==='stdin'){
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {inspectVerificationDiagnostic} from './review-verification-diagnostic.mjs';
|
|
2
|
+
import {readReviewVerification,inspectReviewVerificationEvidence} from './review-verification-contract.mjs';
|
|
1
3
|
import {inspectFixReconciledResult} from './review-reconciliation.mjs';
|
|
2
4
|
// Shared V3 grant and normalized observation contracts; no completion receipt issuer.
|
|
3
5
|
import {validateReviewDispatchGrant} from '../cm-ai/durable-runner-state.mjs';
|
|
@@ -50,11 +52,23 @@ export function inspectCauseRegistration(raw,configuration){
|
|
|
50
52
|
return value;
|
|
51
53
|
}
|
|
52
54
|
export function inspectCauseResult(raw,registration,configuration,started){
|
|
53
|
-
const value=json(raw,1024*1024);shape(value,['dispatchAt','observation',...(Object.hasOwn(value,'reconciliationReceipt')?['reconciliationReceipt']:[])]);
|
|
55
|
+
const value=json(raw,1024*1024);shape(value,['dispatchAt','observation',...(Object.hasOwn(value,'reconciliationReceipt')?['reconciliationReceipt']:[]),...(Object.hasOwn(value,'verification')?['verification']:[]),...(Object.hasOwn(value,'verificationDiagnostic')?['verificationDiagnostic']:[])]);
|
|
54
56
|
need(Number.isSafeInteger(value.dispatchAt)&&value.dispatchAt>=registration.registeredAt
|
|
55
57
|
&&value.dispatchAt<registration.grant.expiresAt,'cause_registration_mismatch');
|
|
56
58
|
need(!value.reconciliationReceipt||(configuration.externalModels||configuration.executionPolicy),'review_reconciliation_unavailable');
|
|
57
59
|
const expected=causeExpectation(registration.request,configuration);
|
|
58
60
|
const result=value.reconciliationReceipt?inspectFixReconciledResult(value,expected,true):inspectProviderCauseReview(JSON.stringify(value.observation),JSON.stringify(expected));
|
|
59
|
-
need(result.providerThreadId===started,'cause_registration_mismatch');
|
|
61
|
+
need(result.providerThreadId===started,'cause_registration_mismatch');
|
|
62
|
+
if(configuration.reviewVerification){
|
|
63
|
+
readReviewVerification(configuration.reviewVerification);
|
|
64
|
+
need(!value.reconciliationReceipt,'review_verification_invalid');
|
|
65
|
+
if(result.observationStatus==='completed'||Object.hasOwn(value,'verification'))
|
|
66
|
+
inspectReviewVerificationEvidence(value.verification,{request:registration.request,configuration:configuration.reviewVerification,providerThreadId:started});
|
|
67
|
+
}else need(!Object.hasOwn(value,'verification'),'review_verification_invalid');
|
|
68
|
+
if(Object.hasOwn(value,'verificationDiagnostic')){
|
|
69
|
+
need(configuration.reviewVerification&&result.observationStatus!=='completed','review_verification_invalid');
|
|
70
|
+
const diagnostic=inspectVerificationDiagnostic(value.verificationDiagnostic,{request:registration.request,configuration:configuration.reviewVerification,providerThreadId:started});
|
|
71
|
+
return {...result,verificationDiagnostic:diagnostic};
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
60
74
|
}
|
|
@@ -7,6 +7,42 @@ import {inspectFixReproductionAttempts} from './reproduce.mjs';
|
|
|
7
7
|
import {inspectFixTestAuthor} from './test-author.mjs';
|
|
8
8
|
import {inventory} from './test-extension.mjs';
|
|
9
9
|
import {inspectVisualCarrier} from './visual.mjs';
|
|
10
|
+
import {inspectFixDiagnosis} from './diagnosis.mjs';
|
|
11
|
+
|
|
12
|
+
// A module-only correction is separate evidence, never a rewritten diagnosis or
|
|
13
|
+
// permission to change the code scope. The owner binds the target to history;
|
|
14
|
+
// every cause package carries both the original answer and that exact binding.
|
|
15
|
+
export function readDiagnosisModuleCorrection(raw,{identity,diagnosis}={}){
|
|
16
|
+
const value=json(raw,128*1024);
|
|
17
|
+
shape(value,['originalDiagnosis','target','reason','previousInvocationStopped','correctionDigest']);
|
|
18
|
+
const original=inspectFixDiagnosis(value.originalDiagnosis),t=value.target;
|
|
19
|
+
shape(t,['identity','configurationDigest','historyDigest','diagnosisRecordDigest','diagnosisDigest',
|
|
20
|
+
'reproductionDigest','walkthroughDigest','originalModules','modules','files','snapshotDigest']);
|
|
21
|
+
validIdentity(t.identity);
|
|
22
|
+
need(original.status==='diagnosed'&&value.previousInvocationStopped===true
|
|
23
|
+
&&typeof value.reason==='string'&&value.reason.trim().length>0&&Buffer.byteLength(value.reason)<=1000
|
|
24
|
+
&&!/[\r\n\0\u0085\u2028\u2029]/.test(value.reason),'fix_diagnosis_module_correction_binding');
|
|
25
|
+
need(['configurationDigest','historyDigest','diagnosisRecordDigest','diagnosisDigest','reproductionDigest','walkthroughDigest','snapshotDigest']
|
|
26
|
+
.every(key=>typeof t[key]==='string'&&/^[a-f0-9]{64}$/.test(t[key])),'fix_diagnosis_module_correction_binding');
|
|
27
|
+
const corrected=inspectFixDiagnosis({...original,affectedModules:t.modules});
|
|
28
|
+
need(digest(t.modules)===digest([...new Set(t.modules)].sort())
|
|
29
|
+
&&digest(t.originalModules)===digest(original.affectedModules)
|
|
30
|
+
&&t.originalModules.length<t.modules.length&&t.originalModules.every(module=>t.modules.includes(module))
|
|
31
|
+
&&t.diagnosisDigest===digest(original),'fix_diagnosis_module_correction_binding');
|
|
32
|
+
need(Array.isArray(t.files)&&t.files.length>0&&t.files.length<=32
|
|
33
|
+
&&digest(t.files.map(file=>file.path))===digest([...original.affectedPaths].sort()),'fix_diagnosis_module_correction_binding');
|
|
34
|
+
for(const file of t.files){
|
|
35
|
+
shape(file,['path','type','mode','size','sha256']);
|
|
36
|
+
need(file.type==='file'&&Number.isInteger(file.mode)&&file.mode>=0&&file.mode<=511
|
|
37
|
+
&&Number.isSafeInteger(file.size)&&file.size>=0&&file.size<=1024*1024
|
|
38
|
+
&&typeof file.sha256==='string'&&/^[a-f0-9]{64}$/.test(file.sha256),'fix_diagnosis_module_correction_binding');
|
|
39
|
+
}
|
|
40
|
+
need(t.snapshotDigest===digest(t.files)&&value.correctionDigest===digest({target:t,reason:value.reason,
|
|
41
|
+
previousInvocationStopped:value.previousInvocationStopped}),'fix_diagnosis_module_correction_binding');
|
|
42
|
+
if(identity!==undefined)need(digest(t.identity)===digest(identity),'fix_diagnosis_module_correction_binding');
|
|
43
|
+
if(diagnosis!==undefined)need(digest(corrected)===digest(diagnosis),'fix_diagnosis_module_correction_binding');
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
10
46
|
|
|
11
47
|
export const rediagnosisPackage=value=>({historyDigest:value.historyDigest,priorPackageDigest:value.priorPackageDigest,
|
|
12
48
|
priorObservationDigest:value.priorObservationDigest,reason:value.reason,reviewFeedback:value.reviewFeedback});
|
|
@@ -32,8 +68,10 @@ export function createFixCausePackage({codeProject,defect,status,context=true}){
|
|
|
32
68
|
const contextFiles=context&&status.rediagnosis?readContextFiles(codeProject,status.rediagnosis.reviewFeedback,status.diagnosis.affectedPaths):[];
|
|
33
69
|
const value=json({version:1,kind:'cm-fix-cause-review-package',identity:status.identity,defect,
|
|
34
70
|
reproduction:status.reproduction,diagnosis:status.diagnosis,learning:status.learning,
|
|
71
|
+
...(status.diagnosisModuleCorrection?{diagnosisModuleCorrection:readDiagnosisModuleCorrection(status.diagnosisModuleCorrection,{identity:status.identity,...(!status.rediagnosis?{diagnosis:status.diagnosis}:{})})}:{}),
|
|
35
72
|
...(status.rediagnosis?{rediagnosis:rediagnosisPackage(status.rediagnosis)}:{}),
|
|
36
73
|
...(status.causeReviewCorrection?{correction:status.causeReviewCorrection}:{}),
|
|
74
|
+
...(status.sourceRevision?{sourceRevision:status.sourceRevision}:{}),
|
|
37
75
|
files:readReviewSourceFiles(codeProject,status.diagnosis.affectedPaths),...(contextFiles.length?{contextFiles}:{})},4*1024*1024);
|
|
38
76
|
return json({...value,packageDigest:digest(value)},4*1024*1024);
|
|
39
77
|
}
|
|
@@ -42,7 +80,14 @@ export function readFixCausePackage(raw){
|
|
|
42
80
|
const value=json(raw,4*1024*1024);
|
|
43
81
|
shape(value,['version','kind','identity','defect','reproduction','diagnosis','learning','files','packageDigest',
|
|
44
82
|
...(Object.hasOwn(value,'correction')?['correction']:[]),...(Object.hasOwn(value,'rediagnosis')?['rediagnosis']:[]),
|
|
45
|
-
...(Object.hasOwn(value,'contextFiles')?['contextFiles']:[])])
|
|
83
|
+
...(Object.hasOwn(value,'contextFiles')?['contextFiles']:[]),...(Object.hasOwn(value,'sourceRevision')?['sourceRevision']:[]),
|
|
84
|
+
...(Object.hasOwn(value,'diagnosisModuleCorrection')?['diagnosisModuleCorrection']:[])]);
|
|
85
|
+
if(Object.hasOwn(value,'diagnosisModuleCorrection'))readDiagnosisModuleCorrection(value.diagnosisModuleCorrection,{identity:value.identity,...(!value.rediagnosis?{diagnosis:value.diagnosis}:{})});
|
|
86
|
+
if(value.sourceRevision){
|
|
87
|
+
shape(value.sourceRevision,['previousPackageDigest','correctionDigest','path','beforeSha256','afterSha256']);
|
|
88
|
+
const r=value.sourceRevision;need([r.previousPackageDigest,r.correctionDigest,r.beforeSha256,r.afterSha256].every(v=>typeof v==='string'&&/^[a-f0-9]{64}$/.test(v))
|
|
89
|
+
&&r.beforeSha256!==r.afterSha256&&value.files.some(f=>f.path===r.path&&f.sha256===r.afterSha256),'invalid_package');
|
|
90
|
+
}
|
|
46
91
|
if(value.rediagnosis){
|
|
47
92
|
shape(value.rediagnosis,['historyDigest','priorPackageDigest','priorObservationDigest','reason','reviewFeedback']);
|
|
48
93
|
need([value.rediagnosis.historyDigest,value.rediagnosis.priorPackageDigest,value.rediagnosis.priorObservationDigest].every(v=>typeof v==='string'&&/^[a-f0-9]{64}$/.test(v)), 'invalid_package');
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Read-only qualification and immutable record validation for one startup correction.
|
|
2
|
+
import {digest,json,need,shape} from '../cm-ai/effect-contract.mjs';
|
|
3
|
+
import {verifyFixRedEvidence} from './red-test.mjs';
|
|
4
|
+
import {COMMAND_CORRECTION,correctionRow,deriveJestCorrection,readCorrectionConfig,correctionFiles} from './jest-command-correction.mjs';
|
|
5
|
+
export {COMMAND_CORRECTION,correctionRow};
|
|
6
|
+
export function inspectCommandCorrection(payload,{configuration,records,red}){
|
|
7
|
+
const p=json(payload,256*1024);shape(p,['target','reason','previousInvocationStopped']);
|
|
8
|
+
const t=p.target;shape(t,['configurationDigest','historyDigest','redResultDigest','outputSha256','declaration','configFile','commands','files','snapshotDigest']);
|
|
9
|
+
need(p.previousInvocationStopped===true&&typeof p.reason==='string'&&p.reason.trim()&&Buffer.byteLength(p.reason)<=1000&&!/[\r\n\0]/.test(p.reason),'fix_command_correction_confirmation');
|
|
10
|
+
need(!correctionRow(records)&&t.configurationDigest===digest(configuration)&&t.historyDigest===digest(records)
|
|
11
|
+
&&red?.status==='not_red'&&t.redResultDigest===digest(records.at(-1))&&records.at(-1).id==='fix-red-test-result'
|
|
12
|
+
&&t.outputSha256===red.output.sha256,'fix_command_correction_binding');
|
|
13
|
+
need(digest(t.commands)===digest(deriveJestCorrection(configuration,t.declaration,t.configFile))
|
|
14
|
+
&&t.commands.some(c=>c.id==='red-test'),'fix_command_correction_binding');
|
|
15
|
+
need(Array.isArray(t.files)&&t.snapshotDigest===digest(t.files),'fix_command_correction_binding');
|
|
16
|
+
const file=t.files.find(f=>f.path===t.configFile.path);need(file&&file.sha256===t.configFile.sha256&&file.mode===t.configFile.mode,'fix_command_correction_binding');
|
|
17
|
+
return p;
|
|
18
|
+
}
|
|
19
|
+
export function inspectCommandCorrectionTarget({configuration,records,status,specsRoot,declaration}){
|
|
20
|
+
need(!correctionRow(records),'fix_command_correction_used');
|
|
21
|
+
need(status.stage==='red_test_not_confirmed'&&status.redTest?.status==='not_red'
|
|
22
|
+
&&!configuration.qaSource&&!configuration.externalModels&&!configuration.executionPolicy,'fix_command_correction_unavailable');
|
|
23
|
+
const raw=verifyFixRedEvidence(status.redTest,configuration.redTest,specsRoot);
|
|
24
|
+
const stderr=Buffer.from(raw.stderrBase64,'base64').toString('utf8');
|
|
25
|
+
const stdout=Buffer.from(raw.stdoutBase64,'base64').toString('utf8');
|
|
26
|
+
need(status.redTest.output.complete===true&&status.redTest.observation.outcome==='failed'
|
|
27
|
+
&&!/(?:^|[\r\n])\s*(?:Test Suites|Tests):/m.test(stdout+'\n'+stderr)
|
|
28
|
+
&&status.redTest.observation.exitCode===1&&status.redTest.observation.signatureMatched===false
|
|
29
|
+
&&stderr.startsWith('Error: Could not find a config file based on provided values:')
|
|
30
|
+
&&stderr.includes(`cwd: "${configuration.redTest.cwd}"`),'fix_command_correction_unavailable');
|
|
31
|
+
const mutable=[...(configuration.repair?.scope??[]),...(configuration.redTest?.testFiles??[]),...(configuration.baseline?.testFiles??[])];
|
|
32
|
+
need(!mutable.includes(declaration.path),'fix_command_correction_config');
|
|
33
|
+
const configFile=readCorrectionConfig(configuration,declaration),commands=deriveJestCorrection(configuration,declaration,configFile),files=correctionFiles(configuration,declaration);
|
|
34
|
+
need(commands.every(c=>!c.before.includes('--')&&!c.before.includes('-c')),'fix_command_correction_config');
|
|
35
|
+
return {configurationDigest:digest(configuration),historyDigest:digest(records),redResultDigest:digest(records.at(-1)),outputSha256:status.redTest.output.sha256,
|
|
36
|
+
declaration:json(declaration),configFile,commands,files,snapshotDigest:digest(files)};
|
|
37
|
+
}
|