@aibyzero/cm-workflow 0.17.1 → 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 +23 -0
- package/CHANGELOG.md +224 -0
- package/README.md +14 -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 +11 -0
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +150 -15
- 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 +83 -14
- 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 +21 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +114 -11
- 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 +11 -5
- 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 +1 -1
- 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 +9 -2
- 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 +242 -39
- 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 +11 -5
- 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 +3 -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 +6 -5
- 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 +471 -57
- 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 +14 -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.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +34 -2
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host.mjs +60 -19
- 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 +16 -1
- 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-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 +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-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +13 -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-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 +4 -3
- 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-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -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 +575 -59
- 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 +45 -1
- 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 +1 -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-summary.test.mjs +24 -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 +1 -1
- 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-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/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 +56 -16
- 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
|
@@ -10,17 +10,21 @@ import {fileURLToPath} from 'node:url';
|
|
|
10
10
|
import {openControlRun,validateRunDefinition,assertCreatableScope} from './cm-ai-run.mjs';
|
|
11
11
|
import {developmentRetryable,completionRetryable,reviewRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
12
12
|
import {batchOperatorGuidance} from '../runtime/js/cm-ai/operator-guidance.mjs';
|
|
13
|
-
import {digest,json,shape,need,id,hex} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
13
|
+
import {digest,json,shape,need,id,hex,validIdentity} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
14
14
|
import {scanRows,findCmAiQaDecision,latestCmAiQaRun} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
15
|
-
import {checkParallelWrite} from './cm-task-gate.mjs';
|
|
15
|
+
import {checkParallelWrite,checkSoloWrite} from './cm-task-gate.mjs';
|
|
16
|
+
import {loadConfig} from './cm-workflow-config.mjs';
|
|
16
17
|
import {parseFeatureTaskText} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
17
|
-
import {approvedTaskGrammar} from '../runtime/js/spec-task-line.mjs';
|
|
18
|
+
import {approvedTaskGrammar,TASK_GRAMMAR} from '../runtime/js/spec-task-line.mjs';
|
|
18
19
|
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
19
20
|
import {inspectRunClosure as inspectClosure} from './cm-log-event.mjs';
|
|
20
21
|
import {releaseVerifiedQaResources} from '../runtime/js/cm-ai/qa-resource-release.mjs';
|
|
21
22
|
import {readRunnerHistory,projectedRunnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
22
23
|
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
23
24
|
import {readControlPolicy,controlTarget,readControlTarget} from '../runtime/js/cm-ai/control-policy.mjs';
|
|
25
|
+
import {BATCH_SEGMENT_FIELD,batchSegment,batchSegments,batchStarted,batchMemberWorktree,batchMemberBranch} from '../runtime/js/cm-ai/batch-location.mjs';
|
|
26
|
+
import {declaredTaskScope,assertDeclaredScope,parseTaskScopes,sessionTaskProblem,sessionTaskReason,taskDependents} from '../runtime/js/task-scope.mjs';
|
|
27
|
+
import {soloWorktreeBlocker,soloQaCounter,soloQaBase,workflowDecidesQa} from '../runtime/js/cm-ai/batch-plan.mjs';
|
|
24
28
|
import {strictPriorAttemptResolved,sameTaskPriorAttemptResolved} from '../runtime/js/cm-ai/external-run-guard.mjs';
|
|
25
29
|
|
|
26
30
|
const writer=fileURLToPath(new URL('./cm-log-event.py',import.meta.url));
|
|
@@ -90,9 +94,9 @@ export function memberSupersedeAdmitted(specsDir,runId,history){
|
|
|
90
94
|
return strictPriorAttemptResolved(runConfig,history,records)&&sameTaskPriorAttemptResolved(history);
|
|
91
95
|
}
|
|
92
96
|
export function createCmAiBatch({configuration,executionFor,logHome,runtime='codex',checkCommands=null,checkTimeoutMs=60000,
|
|
93
|
-
rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,holdRevisions=[],bootstrapKeys=[],memberActions={}}){
|
|
97
|
+
rerunUnknownQa=false,rerunBlockedQa=false,qaEnvironmentFailure=null,holdRevisions=[],bootstrapKeys=[],memberActions={},workflows=null}){
|
|
94
98
|
const config=json(configuration);
|
|
95
|
-
shape(config,['version','repositoryId','batchId','specsDir','codeProject','tasks',...['externalModels','executionPolicy','codeProjects','parallel','controlPolicy'].filter(name=>Object.hasOwn(config,name))]);
|
|
99
|
+
shape(config,['version','repositoryId','batchId','specsDir','codeProject','tasks',...['externalModels','executionPolicy','codeProjects','parallel','controlPolicy','memberDevelopment'].filter(name=>Object.hasOwn(config,name))]);
|
|
96
100
|
const controlPolicy=config.controlPolicy?readControlPolicy(config.controlPolicy):null;
|
|
97
101
|
need(config.version===1);id(config.repositoryId);id(config.batchId);need(config.batchId.length>=8);
|
|
98
102
|
need(typeof executionFor==='function'&&typeof logHome==='string'&&path.isAbsolute(logHome));
|
|
@@ -125,7 +129,11 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
125
129
|
// A member that will be created is refused before the batch locks, logs or
|
|
126
130
|
// prepares a worktree; an existing member keeps its own recovery path.
|
|
127
131
|
if(!bootstrapKeys.includes(key(task))&&!fs.existsSync(path.join(config.specsDir,'.reviews','.execution',definition.identity.runId,'state.json')))
|
|
128
|
-
try{
|
|
132
|
+
try{
|
|
133
|
+
assertCreatableScope(definition.scope);
|
|
134
|
+
// tasks.md is the authority for a task's files once it declares them.
|
|
135
|
+
assertDeclaredScope(definition);
|
|
136
|
+
}catch(error){error.reason=`${key(task)}: ${error.reason}`;throw error;}
|
|
129
137
|
plans.set(key(task),definition);
|
|
130
138
|
}
|
|
131
139
|
// Tasks whose second-round answer is not written yet stop after a changes_requested review.
|
|
@@ -136,8 +144,21 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
136
144
|
&&Array.isArray(memberActions[name])&&memberActions[name].every(item=>plans.has(item))),'invalid_input');
|
|
137
145
|
// One-shot per launch and member, like the single-task flags.
|
|
138
146
|
const actionGrants=new Map(Object.keys(BATCH_MEMBER_ACTIONS).map(name=>[name,new Set(memberActions[name]??[])]));
|
|
139
|
-
|
|
147
|
+
need(workflows===null||typeof workflows==='object'&&!Array.isArray(workflows),'invalid_input');
|
|
148
|
+
const declared=!batchStarted({specsDir:config.specsDir,batchId:config.batchId});
|
|
149
|
+
const groups=validateGroups(config,plans,{declared,workflows}),membership=new Map(groups.flatMap(group=>group.map(key=>[key,group])));
|
|
150
|
+
validateMemberDevelopment(config,plans,groups,{declared});
|
|
140
151
|
const originalMembership=new Map(membership),originalPlans=new Map(plans);
|
|
152
|
+
// A one-member group (batch-plan.mjs worktree_all) is a task developed alone in its
|
|
153
|
+
// own worktree. Unlike members developed alongside others it keeps the fixed N6
|
|
154
|
+
// checkpoints: its QA may run in the worktree and must pass before it is merged.
|
|
155
|
+
const soloMember=key=>originalMembership.get(key)?.length===1;
|
|
156
|
+
// A member is ready to merge once its QA is deferred (skipped) or, for a one-member
|
|
157
|
+
// group, skipped by the ordinary decision or triggered and passed.
|
|
158
|
+
const memberQaSettled=(key,binding)=>{
|
|
159
|
+
const qa=findCmAiQaDecision(binding);
|
|
160
|
+
return qa?.status==='skipped'||soloMember(key)&&qa?.status==='triggered'&&latestCmAiQaRun(binding)?.status==='passed';
|
|
161
|
+
};
|
|
141
162
|
const first=plans.keys().next().value,planDigest=digest(config),log=path.join(config.specsDir,'运行日志.jsonl');
|
|
142
163
|
const batchControlTarget=async(taskKey,state=progress())=>{
|
|
143
164
|
const definition=plans.get(taskKey);need(definition,'batch_member_action_unavailable');
|
|
@@ -170,7 +191,8 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
170
191
|
let releaseLock=null,completeTail=Promise.resolve();
|
|
171
192
|
async function executionForKey(taskKey){
|
|
172
193
|
if(!executions.has(taskKey)){
|
|
173
|
-
const execution=await executionFor(json(plans.get(taskKey)),{parallelMember:membership.has(taskKey)
|
|
194
|
+
const execution=await executionFor(json(plans.get(taskKey)),{parallelMember:membership.has(taskKey),
|
|
195
|
+
...(membership.has(taskKey)&&soloMember(taskKey)?{soloMember:true}:{})});
|
|
174
196
|
need(execution!==null&&typeof execution==='object','execution_adapter_required');
|
|
175
197
|
// Preserve fixed protected-factory provenance; never clone protected callbacks.
|
|
176
198
|
if(Object.isFrozen(execution)){
|
|
@@ -183,7 +205,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
183
205
|
const rows=[];
|
|
184
206
|
if(fs.existsSync(log))scanRows(log,row=>{
|
|
185
207
|
if(row?.workflow==='cm-ai'&&row.event==='decision'&&row.run_id===config.batchId
|
|
186
|
-
&&['batch_start','batch_task_committed','batch_handoff','batch_cancel','batch_member_ready','batch_member_blocked','batch_merge_conflict','batch_merge_started','batch_merge_blocked'].includes(row.phase))rows.push(row);
|
|
208
|
+
&&['batch_start','batch_task_committed','batch_handoff','batch_cancel','batch_member_ready','batch_member_blocked','batch_merge_conflict','batch_merge_started','batch_merge_blocked','batch_member_qa_failed'].includes(row.phase))rows.push(row);
|
|
187
209
|
});
|
|
188
210
|
if(groups.length)return parallelProgress(rows);
|
|
189
211
|
let current=first,stopped=false;const seen=new Set();
|
|
@@ -241,6 +263,12 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
241
263
|
}
|
|
242
264
|
if(row.phase==='batch_cancel'){stopped=true;code='cancelled';continue;}
|
|
243
265
|
if(['batch_merge_conflict','batch_merge_blocked'].includes(row.phase)){stopped=true;code=row.code;continue;}
|
|
266
|
+
if(row.phase==='batch_member_qa_failed'){
|
|
267
|
+
need(soloMember(row.from_key)&&!done.has(row.from_key)&&!ready.has(row.from_key)&&row.code==='batch_solo_qa_failed','batch_history_invalid');
|
|
268
|
+
const expected=location(row.from_key);
|
|
269
|
+
need(row.worktree===expected.worktree&&row.branch===expected.branch,'batch_history_invalid');
|
|
270
|
+
stopped=true;code=row.code;continue;
|
|
271
|
+
}
|
|
244
272
|
if(row.phase==='batch_member_blocked'){
|
|
245
273
|
need(originalMembership.has(row.from_key)&&!done.has(row.from_key)&&!ready.has(row.from_key)
|
|
246
274
|
&&!blocked.has(row.from_key)&&row.generation===2,'batch_history_invalid');
|
|
@@ -277,41 +305,91 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
277
305
|
// refs/heads/cm/work/T-001/<batch> cannot coexist, so a suffix would still collide
|
|
278
306
|
// with branches left by earlier versions. Git rejects ".." and a trailing dot in a
|
|
279
307
|
// ref component while batchId allows dots, so the segment normalises them.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
308
|
+
// batch-location.mjs: a new batch records a segment from its full id in
|
|
309
|
+
// batch_start; one that started without it keeps the old 8-character prefix.
|
|
310
|
+
let segments=null;
|
|
311
|
+
const memberSegments=()=>segments??=batchSegments({specsDir:config.specsDir,batchId:config.batchId});
|
|
312
|
+
const location=key=>{const definition=plans.get(key),current=memberSegments();return {
|
|
313
|
+
worktree:batchMemberWorktree({codeProject:config.codeProject,segments:current,taskId:definition.identity.taskId}),
|
|
314
|
+
branch:batchMemberBranch({segments:current,feature:definition.feature,taskId:definition.identity.taskId})};};
|
|
284
315
|
function verifyMerged(row){
|
|
285
316
|
const definition=plans.get(row.from_key),state=JSON.parse(fs.readFileSync(path.join(config.specsDir,'.reviews','.execution',definition.identity.runId,'state.json'),'utf8'));
|
|
286
317
|
const {revision,...body}=state;
|
|
287
318
|
need(revision===row.checkpoint&&digest(body)===revision,'batch_checkpoint_mismatch');
|
|
288
319
|
const binding={specsDir:config.specsDir,feature:definition.feature,identity:row.identity,packageDigest:row.package_digest};
|
|
289
|
-
need(
|
|
320
|
+
need(memberQaSettled(row.from_key,binding)&&inspectRunClosure(log,definition.identity.runId).closed,'batch_qa_not_ready');
|
|
290
321
|
batchGit(config.codeProject,['merge-base','--is-ancestor',row.merge_commit,'HEAD'],'batch_merge_history_changed');
|
|
291
322
|
}
|
|
292
323
|
function prepareGroup(group){
|
|
293
324
|
const state=progress(),remaining=group.filter(key=>membership.has(key)&&!state.done.has(key));
|
|
294
|
-
//
|
|
295
|
-
//
|
|
296
|
-
//
|
|
297
|
-
|
|
298
|
-
|
|
325
|
+
// Members may edit existing files. The group validator already requires
|
|
326
|
+
// pairwise-disjoint scopes and no dependency path, so members never write the
|
|
327
|
+
// same path; merges stay serial and a git conflict still stops as
|
|
328
|
+
// merge_conflict. The earlier create-only rule (#59, #187) existed because a
|
|
329
|
+
// task's scope was then guessed by the session; it now comes from the batch
|
|
330
|
+
// definition the scheduler validates.
|
|
299
331
|
for(const key of remaining){
|
|
300
332
|
const {worktree,branch}=location(key);
|
|
301
333
|
if(!fs.existsSync(worktree)){
|
|
302
334
|
need(!state.ready.has(key),'batch_worktree_missing');
|
|
335
|
+
// A branch left without its worktree (a cleanup stopped between removing the
|
|
336
|
+
// worktree and deleting the branch) is deleted only when it holds nothing beyond
|
|
337
|
+
// the main checkout's HEAD (`branch -d`, never -D); one with its own commits is
|
|
338
|
+
// somebody's work and stops the batch.
|
|
339
|
+
if(branchExists(branch)){
|
|
340
|
+
if(batchGit(config.codeProject,['rev-list',`HEAD..refs/heads/${branch}`])!=='')return memberBranchExists(key,branch);
|
|
341
|
+
batchGit(config.codeProject,['branch','-d',branch],'batch_worktree_failed');
|
|
342
|
+
}
|
|
303
343
|
fs.mkdirSync(path.dirname(worktree),{recursive:true});
|
|
304
344
|
batchGit(config.codeProject,['worktree','add','-b',branch,worktree,'HEAD'],'batch_worktree_failed');
|
|
305
345
|
}
|
|
306
346
|
need(batchGit(worktree,['branch','--show-current'])===branch,'batch_worktree_mismatch');
|
|
307
|
-
|
|
308
|
-
plans.set(key,validateRunDefinition({...definition,codeProject:worktree,
|
|
309
|
-
...(definition.codeProjects?{codeProjects:definition.codeProjects.map(root=>path.join(worktree,path.relative(config.codeProject,root)))}:{})}));
|
|
347
|
+
plans.set(key,worktreeDefinition(key));
|
|
310
348
|
}
|
|
311
|
-
//
|
|
349
|
+
// One remaining member (a one-member group, or the rest after a partial merge) is the
|
|
350
|
+
// only writer: the main checkout just waits to merge it and may be detached.
|
|
312
351
|
const assignments=remaining.map(key=>`${plans.get(key).identity.taskId}=${location(key).worktree}`);
|
|
313
|
-
if(assignments.length===1)
|
|
314
|
-
if(assignments.length)checkParallelWrite({repo:config.codeProject,assignment:assignments});
|
|
352
|
+
if(assignments.length===1)checkSoloWrite({repo:config.codeProject,assignment:assignments[0]});
|
|
353
|
+
else if(assignments.length)checkParallelWrite({repo:config.codeProject,assignment:assignments});
|
|
354
|
+
// A one-member group decides and runs its own QA in its worktree, which reloads the
|
|
355
|
+
// project configuration there. The planner's blob check is only a pre-filter (a
|
|
356
|
+
// checkout filter or a second config file hidden in the main checkout pass it), so
|
|
357
|
+
// the effective configurations both checkouts actually load are compared here,
|
|
358
|
+
// after the worktree exists and before any develop dispatch.
|
|
359
|
+
for(const key of remaining.filter(key=>soloMember(key)&&!state.ready.has(key))){
|
|
360
|
+
const diverged=memberConfigDivergence(key);if(!diverged)continue;
|
|
361
|
+
// Review r6: the batch never deletes the worktree or its branch here. Index flags
|
|
362
|
+
// (assume-unchanged, skip-worktree) can hide work from `git status`, so no check
|
|
363
|
+
// proves the directory holds nothing to keep; the operator cleans up by hand. While
|
|
364
|
+
// the worktree stays, every advance reuses it and compares again.
|
|
365
|
+
const {worktree,branch}=location(key);
|
|
366
|
+
const cleanup=`确认 worktree ${worktree} 里没有要保留的内容后手动清理:${manualCleanupCommands({repo:config.codeProject,worktree,branch}).join(';')}(不要加 --force 或 -D,Git 拒绝时说明还有改动或独有提交,先处理)`;
|
|
367
|
+
const nextStep=`${cleanup};然后让主目录与 worktree 加载出同一份项目配置(取消改写配置的 Git 检出过滤器、删掉多余的配置文件并提交、去掉藏起本地改动的 skip-worktree/assume-unchanged),再对本批次 advance;`
|
|
368
|
+
+`或在项目配置里设 parallel.worktree_all: false,剩余任务用 cm-ai-batch-plan.mjs 以新的批次 ID 重新生成批次`;
|
|
369
|
+
return Object.freeze({outcome:'blocked',state:'blocked',code:'batch_member_config_diverged',batchId:config.batchId,currentTask:key,
|
|
370
|
+
reason:`任务 ${key} 单独在 worktree 里开发,但 ${diverged};QA 会按另一套配置执行,所以不开发。批次不删除该 worktree 与分支 ${branch}。出口:${nextStep}。`,
|
|
371
|
+
guidance:stopGuidance(`任务 ${key} 的 worktree 与主目录加载出的项目配置不一致,未开发;worktree 与分支保留。`,`${nextStep}。`,
|
|
372
|
+
['以 worktree 建好后两边实际加载的配置为准','主目录与已完成的任务不受影响','批次不会代为删除 worktree 或分支;worktree 还在时,下次 advance 会复用它并重新比对配置'])});
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
function branchExists(branch){
|
|
377
|
+
return spawnSync('git',['-C',config.codeProject,'rev-parse','--verify','--quiet',`refs/heads/${branch}`],gitOptions()).status===0;
|
|
378
|
+
}
|
|
379
|
+
function memberBranchExists(key,branch){
|
|
380
|
+
const nextStep=`核对分支 ${branch} 上的提交:要保留就合并或另存,不要就在确认后自行删除;然后对本批次 advance`;
|
|
381
|
+
return Object.freeze({outcome:'blocked',state:'blocked',code:'batch_member_branch_exists',batchId:config.batchId,currentTask:key,
|
|
382
|
+
reason:`任务 ${key} 的成员分支 ${branch} 已存在且有主目录 HEAD 以外的提交,但对应的 worktree 不在;批次不删除它,也不在它上面开发。出口:${nextStep}。`,
|
|
383
|
+
guidance:stopGuidance(`任务 ${key} 的成员分支已存在且有独有提交,批次停下。`,`${nextStep}。`,['批次不会代为删除有独有提交的分支'])});
|
|
384
|
+
}
|
|
385
|
+
// Both checkouts' effective configurations, loaded the way QA and the browser check
|
|
386
|
+
// load them (loadConfig). A reason, or null when they are the same.
|
|
387
|
+
function memberConfigDivergence(key){
|
|
388
|
+
const load=root=>{try{return {value:digest(json(loadConfig({projectRoot:root})))};}catch(error){return {error:error.message??String(error)};}};
|
|
389
|
+
const main=load(config.codeProject),member=load(location(key).worktree);
|
|
390
|
+
if(main.error)return `主目录的项目配置无法加载(${main.error})`;
|
|
391
|
+
if(member.error)return `worktree 里的项目配置无法加载(${member.error})`;
|
|
392
|
+
return main.value===member.value?null:'worktree 与主目录加载出的有效配置不同';
|
|
315
393
|
}
|
|
316
394
|
function preserveBlockedMember(row){
|
|
317
395
|
const {worktree,branch}=location(row.from_key);
|
|
@@ -334,7 +412,12 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
334
412
|
...(['decision','complete','qa','context_refresh'].includes(operation)?{packageDigest:status.packageDigest}:{}),...extra});
|
|
335
413
|
return status;
|
|
336
414
|
};
|
|
337
|
-
|
|
415
|
+
// A one-member group runs the whole task lifecycle like a serial task, in its
|
|
416
|
+
// worktree: N6 decides with the fixed checkpoints and a triggered QA runs (and
|
|
417
|
+
// must pass) here, before the member is sealed and merged. A failed or blocked
|
|
418
|
+
// QA leaves the member unready, so the batch stops without merging it.
|
|
419
|
+
if(soloMember(key))status=await call('advance');
|
|
420
|
+
else for(let round=status.identity.attempt;round<=2;round++){
|
|
338
421
|
if(status.code===null&&['ready','changes_requested'].includes(status.state)
|
|
339
422
|
||developmentRetryable(status))await call('start');
|
|
340
423
|
if(['reported','advanced'].includes(status.outcome)&&(status.code===null&&status.state==='awaiting_review'
|
|
@@ -347,7 +430,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
347
430
|
}
|
|
348
431
|
break;
|
|
349
432
|
}
|
|
350
|
-
if(status.state==='fixture_completed'&&status.code===null){
|
|
433
|
+
if(!soloMember(key)&&status.state==='fixture_completed'&&status.code===null){
|
|
351
434
|
await call('qa');
|
|
352
435
|
if(status.code==='qa_skipped')await call('context_refresh',{testRunId:null});
|
|
353
436
|
}
|
|
@@ -358,22 +441,47 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
358
441
|
return null;
|
|
359
442
|
}finally{members.delete(key);run.close();}
|
|
360
443
|
}
|
|
361
|
-
|
|
444
|
+
// Verify a ready member's completed, QA-deferred delivery and commit it on its
|
|
445
|
+
// branch. Idempotent: an already committed worktree gets no new commit.
|
|
446
|
+
async function sealMember(row,commit=true){
|
|
362
447
|
const key=row.from_key,{worktree,branch}=location(key);
|
|
363
448
|
need(row.worktree===worktree&&row.branch===branch,'batch_worktree_mismatch');
|
|
449
|
+
// A stopped batch replays without preparing its group: bind the member root here.
|
|
450
|
+
if(plans.get(key).codeProject!==worktree)bindWorktree(key);
|
|
364
451
|
// Reopen the unchanged member root to verify its actual completion and QA.
|
|
365
452
|
const run=await open(key);
|
|
366
453
|
try{
|
|
367
454
|
need(!run.blocked&&run.checkpoint()===row.checkpoint,'batch_checkpoint_mismatch');
|
|
368
455
|
const status=await run.host.handle({version:1,operation:'status',requestId:'batch-merge-status',identity:row.identity});
|
|
369
456
|
need(status.state==='fixture_completed'&&status.code===null&&status.packageDigest===row.package_digest,'batch_checkpoint_mismatch');
|
|
370
|
-
need(
|
|
371
|
-
identity:row.identity,packageDigest:row.package_digest})
|
|
457
|
+
need(memberQaSettled(key,{specsDir:config.specsDir,feature:plans.get(key).feature,
|
|
458
|
+
identity:row.identity,packageDigest:row.package_digest}),'batch_qa_not_ready');
|
|
372
459
|
}finally{run.close();}
|
|
460
|
+
if(!commit)return;
|
|
461
|
+
batchGit(worktree,['add','-A']);
|
|
462
|
+
if(batchGit(worktree,['status','--porcelain']))batchGit(worktree,['commit',...taskCommitArgs(plans.get(key).identity.taskId,taskDescription(config,plans.get(key)))]);
|
|
463
|
+
}
|
|
464
|
+
// Every member that finished and is not merged yet, in task order.
|
|
465
|
+
const readyUnmerged=()=>{const state=progress();return [...plans.keys()].filter(key=>state.ready.has(key)&&!state.done.has(key));};
|
|
466
|
+
// Seal each such member for the conflict guidance. A member that fails its check
|
|
467
|
+
// stays unsealed and is named; the conflict itself is still returned.
|
|
468
|
+
async function sealForGuidance(){
|
|
469
|
+
const unsealed=[];
|
|
470
|
+
for(const key of readyUnmerged()){
|
|
471
|
+
try{await sealMember(progress().ready.get(key));}catch(cause){unsealed.push({taskKey:key,code:cause?.code??'batch_seal_failed'});}
|
|
472
|
+
}
|
|
473
|
+
return unsealed;
|
|
474
|
+
}
|
|
475
|
+
// status checks nothing and runs nothing: an empty Git status does not prove a
|
|
476
|
+
// reviewed delivery is on its branch, and Git may run configured programs. Every
|
|
477
|
+
// unmerged member is reported unverified; advance seals them and answers again.
|
|
478
|
+
const unsealedReadOnly=()=>readyUnmerged().map(key=>({taskKey:key,code:'batch_seal_unverified'}));
|
|
479
|
+
async function mergeMember(row){
|
|
480
|
+
const key=row.from_key,{worktree,branch}=location(key);
|
|
373
481
|
let intent=progress().merging.get(key);
|
|
482
|
+
// A logged merge intent already names the member commit.
|
|
483
|
+
await sealMember(row,!intent);
|
|
374
484
|
if(!intent){
|
|
375
|
-
batchGit(worktree,['add','-A']);
|
|
376
|
-
if(batchGit(worktree,['status','--porcelain']))batchGit(worktree,['commit',...taskCommitArgs(plans.get(key).identity.taskId,taskDescription(config,plans.get(key)))]);
|
|
377
485
|
need(batchGit(config.codeProject,['status','--porcelain'])==='','batch_main_dirty');
|
|
378
486
|
intent={from_key:key,expected_old:batchGit(config.codeProject,['rev-parse','HEAD']),member_commit:batchGit(worktree,['rev-parse','HEAD'])};
|
|
379
487
|
record('batch_merge_started',intent);
|
|
@@ -389,7 +497,10 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
389
497
|
batchGit(config.codeProject,['merge','--abort'],'batch_merge_abort_failed');
|
|
390
498
|
need(batchGit(config.codeProject,['rev-parse','HEAD'])===intent.expected_old,'batch_merge_history_changed');
|
|
391
499
|
record('batch_merge_conflict',{from_key:key,code:'merge_conflict',files,expected_old:intent.expected_old});
|
|
392
|
-
|
|
500
|
+
// The guidance has the operator merge every unmerged member's branch: commit
|
|
501
|
+
// each reviewed delivery there first, or its branch would merge as up to date.
|
|
502
|
+
const unsealed=await sealForGuidance();
|
|
503
|
+
return {outcome:'blocked',code:'merge_conflict',batchId:config.batchId,files,...(unsealed.length?{unsealed}:{}),guidance:mergeConflictGuidance(key,files,unsealed)};
|
|
393
504
|
}
|
|
394
505
|
}else{
|
|
395
506
|
// A crash may happen after Git commits but before the handoff log append.
|
|
@@ -418,9 +529,9 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
418
529
|
const initial=progress();
|
|
419
530
|
if(request.operation==='status')return {outcome:'reported',state:'parallel',batchId:config.batchId,
|
|
420
531
|
ready:group.filter(key=>initial.ready.has(key)),merged:group.filter(key=>initial.done.has(key))};
|
|
421
|
-
if(!initial.rows.length)record('batch_start',{from_key:liveKey});
|
|
532
|
+
if(!initial.rows.length)record('batch_start',{from_key:liveKey,[BATCH_SEGMENT_FIELD]:batchSegment(config.batchId)});
|
|
422
533
|
if(request.operation==='cancel'){record('batch_cancel',{from_key:liveKey});return {outcome:'cancelled',code:'cancelled',batchId:config.batchId};}
|
|
423
|
-
prepareGroup(group);
|
|
534
|
+
const prepared=prepareGroup(group);if(prepared)return prepared;
|
|
424
535
|
// Resolve every member's actual worktree preflight before any start dispatch.
|
|
425
536
|
for(const key of group.filter(key=>membership.has(key)&&!initial.done.has(key))){
|
|
426
537
|
try{await executionForKey(key);}catch(cause){
|
|
@@ -433,31 +544,55 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
433
544
|
const pending=group.filter(key=>membership.has(key)&&!initial.ready.has(key)&&!initial.done.has(key));
|
|
434
545
|
const results=await Promise.allSettled(pending.map(key=>driveMember(key,request)));
|
|
435
546
|
if(cancelled)return {outcome:'cancelled',code:'cancelled',batchId:config.batchId};
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
for(const [index,result] of results.entries()){
|
|
442
|
-
if(result.status==='rejected'){rejected??=result.reason;continue;}
|
|
443
|
-
const status=result.value;if(!status)continue;
|
|
547
|
+
// Classify every member result before merging: a member rescheduled to a serial
|
|
548
|
+
// second generation is the only one a later member may merge ahead of.
|
|
549
|
+
const decisions=results.map((result,index)=>{
|
|
550
|
+
if(result.status==='rejected')return {kind:'rejected',reason:result.reason};
|
|
551
|
+
const status=result.value;if(!status)return {kind:'none'};
|
|
444
552
|
// Retryable validation, review transport and completed-task QA stay on
|
|
445
553
|
// their existing recovery path; a new run must not bypass those gates.
|
|
446
554
|
const terminal=['blocked','failed','unknown'].includes(status.state)
|
|
447
555
|
&&!developmentRetryable(status)&&!completionRetryable(status)
|
|
448
556
|
||status.state==='pending_review'&&status.code!==null&&!reviewRetryable(status);
|
|
449
|
-
if(!terminal){waiting??=status;continue;}
|
|
450
557
|
const key=pending[index];
|
|
558
|
+
// The safety net (batch-plan.mjs keeps tasks that could trigger QA out of one-member
|
|
559
|
+
// groups): a one-member group whose own QA really failed has no QA repair path in a
|
|
560
|
+
// batch. It is not merged; the batch stops with its delivery committed on its branch.
|
|
561
|
+
if(soloMember(key)&&status.state==='fixture_completed'&&status.code==='qa_failed')return {kind:'qa_failed',key,status};
|
|
562
|
+
if(!terminal)return {kind:'waiting',status};
|
|
451
563
|
// Q25: a member that can still be resolved in its own run (original-invocation
|
|
452
564
|
// receipts, interrupted effect, a redo awaiting stop confirmation) keeps its
|
|
453
565
|
// worktree and stops with the batch operation named; an unconfirmed one stays
|
|
454
566
|
// in its run with an explicit stop; only a raw checkpointed blocked terminal is
|
|
455
567
|
// rescheduled serially. Ordinary batches follow the same rules (they used to
|
|
456
568
|
// reschedule every terminal, unknown included, and develop gen 2 at once).
|
|
457
|
-
if(IN_RUN_ACTIONS.has(status.pendingAction)){recoverable
|
|
569
|
+
if(IN_RUN_ACTIONS.has(status.pendingAction))return {kind:'recoverable',key,status};
|
|
458
570
|
const history=memberRunHistory(config.specsDir,plans.get(key).identity.runId);
|
|
459
|
-
if(!memberRescheduleAllowed(status,history)){
|
|
571
|
+
if(!memberRescheduleAllowed(status,history))return {kind:'unresolved',key,status,history};
|
|
572
|
+
return {kind:'reschedule',key,status};
|
|
573
|
+
});
|
|
574
|
+
const skipped=new Set([...progress().blocked.keys(),...decisions.filter(item=>item.kind==='reschedule').map(item=>item.key)]);
|
|
575
|
+
// A merge an earlier process started (its intent is logged, its handoff is
|
|
576
|
+
// not) is finished first: it may already be in Git. The rest merge in task
|
|
577
|
+
// order, not completion order: a later member waits while an earlier one is
|
|
578
|
+
// still unfinished (retrying, recovering, stopped), except one rescheduled to a
|
|
579
|
+
// serial second generation, which is redone on top of the merged result.
|
|
580
|
+
const unfinished=[...progress().merging.keys()].filter(key=>group.includes(key)&&!progress().done.has(key));
|
|
581
|
+
for(const key of [...unfinished,...[...plans.keys()].filter(key=>group.includes(key)&&!unfinished.includes(key))]){
|
|
582
|
+
if(progress().done.has(key))continue;
|
|
583
|
+
const row=progress().ready.get(key);
|
|
584
|
+
if(!row){if(skipped.has(key))continue;break;}
|
|
585
|
+
const result=await mergeMember(row);if(result)return result;
|
|
586
|
+
}
|
|
587
|
+
let waiting=null,rejected=null,recoverable=null,unresolved=null;const rescheduled=[];
|
|
588
|
+
for(const decision of decisions){
|
|
589
|
+
if(decision.kind==='rejected'){rejected??=decision.reason;continue;}
|
|
590
|
+
if(decision.kind==='waiting'){waiting??=decision.status;continue;}
|
|
591
|
+
if(decision.kind==='recoverable'){recoverable??={key:decision.key,status:decision.status};continue;}
|
|
592
|
+
if(decision.kind==='unresolved'){const {key,status,history}=decision;
|
|
460
593
|
unresolved??={key,status,history,raw:history?.state?`${history.state.state}/${history.state.code??history.state.state}`:'unreadable'};continue;}
|
|
594
|
+
if(decision.kind!=='reschedule')continue;
|
|
595
|
+
const {key,status}=decision;
|
|
461
596
|
rescheduled.push(key);
|
|
462
597
|
record('batch_member_blocked',{from_key:key,code:status.code??status.state,
|
|
463
598
|
reason:status.blockedReason??status.reason??status.code??status.state,...location(key),generation:2});
|
|
@@ -465,6 +600,15 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
465
600
|
// Log before Git mutation so a crash during WIP commit/removal is resumable.
|
|
466
601
|
for(const row of progress().blocked.values())preserveBlockedMember(row);
|
|
467
602
|
if(rejected)throw rejected;
|
|
603
|
+
const qaFailed=decisions.find(decision=>decision.kind==='qa_failed');
|
|
604
|
+
if(qaFailed){
|
|
605
|
+
// Committed before the stop is logged: a crash in between re-drives the member to
|
|
606
|
+
// the same recorded failure and commits nothing new.
|
|
607
|
+
commitSoloDelivery(qaFailed.key,qaFailed.status);
|
|
608
|
+
const row={from_key:qaFailed.key,code:'batch_solo_qa_failed',...location(qaFailed.key)};
|
|
609
|
+
record('batch_member_qa_failed',row);
|
|
610
|
+
return soloQaFailedStop(row);
|
|
611
|
+
}
|
|
468
612
|
if(recoverable)return parallelRecoveryRequired(recoverable.key,recoverable.status);
|
|
469
613
|
if(unresolved)return parallelMemberUnresolved(unresolved.key,unresolved.status,unresolved.raw,unresolved.history);
|
|
470
614
|
// The second generation is a new run: stop here so the next advance (and its
|
|
@@ -473,8 +617,62 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
473
617
|
if(waiting)return {...waiting,batchId:config.batchId};
|
|
474
618
|
return null;
|
|
475
619
|
}
|
|
620
|
+
// The member's reviewed, completed delivery, committed on its branch so the operator
|
|
621
|
+
// can merge it; only the recorded QA failure kept it from the ordinary seal.
|
|
622
|
+
function commitSoloDelivery(key,status){
|
|
623
|
+
const {worktree,branch}=location(key),definition=plans.get(key);
|
|
624
|
+
need(definition.codeProject===worktree&&fs.existsSync(worktree)&&batchGit(worktree,['branch','--show-current'])===branch,'batch_worktree_mismatch');
|
|
625
|
+
const qa=findCmAiQaDecision({specsDir:config.specsDir,feature:definition.feature,identity:status.identity,packageDigest:status.packageDigest});
|
|
626
|
+
need(qa?.status==='triggered'&&latestCmAiQaRun({specsDir:config.specsDir,feature:definition.feature,identity:status.identity,
|
|
627
|
+
packageDigest:status.packageDigest})?.status==='failed','batch_qa_not_ready');
|
|
628
|
+
batchGit(worktree,['add','-A']);
|
|
629
|
+
if(batchGit(worktree,['status','--porcelain']))batchGit(worktree,['commit',...taskCommitArgs(definition.identity.taskId,taskDescription(config,definition))]);
|
|
630
|
+
}
|
|
631
|
+
function soloQaFailedStop(row){
|
|
632
|
+
const {from_key:key,worktree,branch}=row;
|
|
633
|
+
const nextStep=`在主目录 git merge --no-ff ${branch}(工作树 ${worktree},分支上已提交该任务的已审交付);`
|
|
634
|
+
+`再用 /cm-fix 按该任务最新一轮 QA 报告(specs 的 .reviews/ 下)复现并修复,修复照常经过独立审查与回归;`
|
|
635
|
+
+`然后删除该工作树与分支;剩余任务用 cm-ai-batch-plan.mjs 以新的批次 ID 重新生成批次继续,功能最后一个任务会重跑整个功能的 QA。`;
|
|
636
|
+
return Object.freeze({outcome:'blocked',state:'blocked',code:'batch_solo_qa_failed',batchId:config.batchId,currentTask:key,
|
|
637
|
+
reason:`单独在 worktree 里开发的任务 ${key} 自己的 QA 未通过;批次没有 QA 修复出口,不合并它,批次停止,主目录未改动。出口:${nextStep}`,
|
|
638
|
+
guidance:stopGuidance(`任务 ${key} 在自己的 worktree 里 QA 未通过;批次不合并它并已停止,主目录未改动。`,nextStep,
|
|
639
|
+
['该任务已审查通过并在 tasks.md 记为完成,新批次会跳过它;不合并就会缺代码','合并进来的代码有已知 QA 失败,修复并通过 QA 前不要发布',
|
|
640
|
+
'原批次不会再推进;之后每次 advance 只重复本指引'])});
|
|
641
|
+
}
|
|
476
642
|
const stopGuidance=(summary,nextStep,prerequisites)=>Object.freeze({summary,nextStep,recoveryOperation:null,
|
|
477
643
|
prerequisites:Object.freeze(prerequisites),authorizationGranted:false});
|
|
644
|
+
// Review 2026-10-27 round 1 (P3): a batch that ends on a detached main checkout leaves its
|
|
645
|
+
// merges only on that commit (member branches are deleted). The finished result names the
|
|
646
|
+
// commit and how to keep it; the batch never creates or switches a branch itself.
|
|
647
|
+
function withDetachedSave(value){
|
|
648
|
+
if(batchGit(config.codeProject,['branch','--show-current'])!=='')return value;
|
|
649
|
+
const head=batchGit(config.codeProject,['rev-parse','HEAD']);
|
|
650
|
+
const note=`主目录停在 detached HEAD(提交 ${head.slice(0,12)}),本批次的结果只在这个提交上:要保留就在主目录运行 git switch -c <新分支名>`;
|
|
651
|
+
const guidance=value.guidance?Object.freeze({...value.guidance,prerequisites:Object.freeze([...(value.guidance.prerequisites??[]).slice(0,7),note])})
|
|
652
|
+
:stopGuidance('本批次已全部完成。',note,[]);
|
|
653
|
+
return {...value,detachedHead:head,guidance};
|
|
654
|
+
}
|
|
655
|
+
// A member whose reviewed, completed delivery does not merge (members never share a
|
|
656
|
+
// scope file, so this is a file outside every scope). The batch stays stopped; the
|
|
657
|
+
// operator merges by hand and plans the rest as a new batch. Redoing the task
|
|
658
|
+
// serially would mean reopening a completed, reviewed task, which is not automatic.
|
|
659
|
+
// Every member that finished and is not merged yet is listed, the conflicted one
|
|
660
|
+
// included, in task order: each is marked complete in tasks.md, so a new plan
|
|
661
|
+
// would skip it, and its code exists only on its branch (committed there before
|
|
662
|
+
// the guidance is given).
|
|
663
|
+
const mergeConflictGuidance=(key,files,unsealed=[])=>{
|
|
664
|
+
const listed=Array.isArray(files)&&files.length?files.join('、'):'(Git 未列出)';
|
|
665
|
+
const pending=readyUnmerged();
|
|
666
|
+
if(!pending.includes(key))pending.push(key);
|
|
667
|
+
const steps=pending.map(item=>{const {worktree,branch}=location(item);return `${item}:git merge --no-ff ${branch}(工作树 ${worktree})`;});
|
|
668
|
+
return stopGuidance(`并行成员 ${key} 的已审交付与已合并的结果在 ${listed} 上冲突;合并已撤销,主目录未改动,批次停止。`,
|
|
669
|
+
`在主目录按任务顺序手动合并这些已完成未合并的成员分支:${steps.join(';')};解决冲突后跑项目检查再提交;`
|
|
670
|
+
+`然后删除这些成员工作树与分支;剩余任务用 cm-ai-batch-plan.mjs 以新的批次 ID 重新生成批次继续。`,
|
|
671
|
+
[...(unsealed.length?[`以下成员的交付尚未确认提交到分支,分支里可能没有代码:${unsealed.map(item=>`${item.taskKey}(${item.code})`).join('、')}。`
|
|
672
|
+
+'先恢复缺失的工作树,再对本批次 advance 一次:它只核对并提交这些交付、重新给出本指引;这里不再列出后才能合并和清理']:[]),
|
|
673
|
+
'这些任务已审查通过并在 tasks.md 记为完成,合入的是它们的已审代码;新批次会跳过它们,漏合就会缺代码',
|
|
674
|
+
'合并后的组合没有经过审查,提交前必须跑项目检查','原批次不会再推进;advance 只会补提交并重复本指引']);
|
|
675
|
+
};
|
|
478
676
|
// reconcile_review exists only for external-model or execution-policy runs.
|
|
479
677
|
const batchKind=strict=>strict?'外部模型或执行策略批次':'批次';
|
|
480
678
|
// Name only exits whose entry conditions accept this member. Recoverable pendingActions
|
|
@@ -482,6 +680,11 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
482
680
|
// (parallelRecoveryRequired); original-call reconciliation that is not available now
|
|
483
681
|
// cannot become available later, so it is not offered. Supersede is offered only when
|
|
484
682
|
// memberSupersedeAdmitted says the supersede check and the external run guard pass.
|
|
683
|
+
// The member's own bounded diagnostic classes, kept when the batch rebuilds a stop
|
|
684
|
+
// around a member result (drivers and notices act on them, never on reason text).
|
|
685
|
+
const memberDiagnostics=status=>Object.freeze({
|
|
686
|
+
...(typeof status?.reviewFailure==='string'&&/^reviewer_[a-z_]{1,48}$/.test(status.reviewFailure)?{reviewFailure:status.reviewFailure}:{}),
|
|
687
|
+
...(typeof status?.developFailure==='string'&&/^developer_[a-z_]{1,48}$/.test(status.developFailure)?{developFailure:status.developFailure}:{})});
|
|
485
688
|
function parallelMemberUnresolved(key,status,raw,history){
|
|
486
689
|
const strict=Boolean(config.externalModels||config.executionPolicy),runId=plans.get(key).identity.runId;
|
|
487
690
|
const supersedable=memberSupersedeAdmitted(config.specsDir,runId,history);
|
|
@@ -496,6 +699,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
496
699
|
:`批次与单任务宿主目前都没有能处理它的操作:${why}${original}。保留批次、原运行和 worktree,不要取消批次或手改存档,把 rawState 与本 reason 交给维护者处理`);
|
|
497
700
|
return Object.freeze({outcome:'blocked',state:'blocked',code:'batch_parallel_member_unresolved',batchId:config.batchId,
|
|
498
701
|
currentTask:key,identity:status.identity,memberState:status.state,memberCode:status.code??null,pendingAction:status.pendingAction??null,
|
|
702
|
+
...memberDiagnostics(status),
|
|
499
703
|
rawState:raw,
|
|
500
704
|
reason:`${batchKind(strict)}的并行成员 ${key} 停在 ${status.state}/${status.code??status.state}(原始存档状态 ${raw}),结果尚未确认、写入方未证明已停或审查尚未终结,不改排串行(改排会换 runId、从 attempt 1 重派,绕过原调用对账与写入方停止证明)。出口:${exit}。`,
|
|
501
705
|
guidance:stopGuidance('并行成员结果未确认,批次不会自动改排或重派。',`${exit}。`,
|
|
@@ -519,6 +723,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
519
723
|
:`关闭批次宿主,带 ${grant.flag} ${key} 用同一批次配置重新启动,发送批次操作 ${action}(taskKey ${key}、单行 reason)`;
|
|
520
724
|
return Object.freeze({outcome:'blocked',state:'blocked',code:'batch_parallel_member_recovery_required',batchId:config.batchId,
|
|
521
725
|
currentTask:key,identity:status.identity,memberState:status.state,memberCode:status.code??null,pendingAction:action,
|
|
726
|
+
...memberDiagnostics(status),
|
|
522
727
|
reason:`${batchKind(Boolean(config.externalModels||config.executionPolicy))}的并行成员 ${key} 停在 ${status.state}/${status.code??status.state},可在它自己的运行里恢复,所以不改排串行(改排会丢掉原调用回执或中断记录)。出口:${exit};之后 advance 继续本批次。`,
|
|
523
728
|
guidance:Object.freeze({summary:'并行成员停在可在原运行内恢复的状态,批次不会自动改排。',nextStep:`${exit};之后 advance 继续本批次。`,
|
|
524
729
|
recoveryOperation:action,prerequisites:Object.freeze(['先确认旧宿主与该成员的会话或子进程已停止写入','恢复只转给该成员运行,不跨成员']),authorizationGranted:false})});
|
|
@@ -528,9 +733,87 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
528
733
|
const {worktree,branch}=location(taskKey);
|
|
529
734
|
need(fs.existsSync(worktree),'batch_member_action_unavailable');
|
|
530
735
|
need(batchGit(worktree,['branch','--show-current'])===branch,'batch_worktree_mismatch');
|
|
736
|
+
plans.set(taskKey,worktreeDefinition(taskKey));
|
|
737
|
+
}
|
|
738
|
+
// A member's definition rooted in its worktree, always mapped from the original
|
|
739
|
+
// plan so binding twice (a stopped replay, then controlTarget) maps once.
|
|
740
|
+
function worktreeDefinition(key){
|
|
741
|
+
const {worktree}=location(key),definition=originalPlans.get(key);
|
|
742
|
+
return validateRunDefinition({...definition,codeProject:worktree,
|
|
743
|
+
...(definition.codeProjects?{codeProjects:definition.codeProjects.map(root=>path.join(worktree,path.relative(config.codeProject,root)))}:{})});
|
|
744
|
+
}
|
|
745
|
+
// The batch-level part of a rate-limit retry target: which member, and the batch
|
|
746
|
+
// log as it was when the member stopped (digest of the plan and every batch row).
|
|
747
|
+
const batchLogDigest=state=>digest({planDigest,rows:state.rows});
|
|
748
|
+
const rateLimitedStop=result=>result?.state==='pending_review'&&result.code==='review_provider_failed'
|
|
749
|
+
&&result.reviewFailure==='reviewer_rate_limited'&&result.pendingAction==='resume'
|
|
750
|
+
&&typeof result.reviewInvocationId==='string'&&typeof result.identity?.runId==='string';
|
|
751
|
+
function withReviewRetryTarget(result){
|
|
752
|
+
if(!rateLimitedStop(result))return result;
|
|
753
|
+
const taskKey=[...plans].find(([,definition])=>definition.identity.runId===result.identity.runId)?.[0];
|
|
754
|
+
if(!taskKey)return result;
|
|
755
|
+
return Object.freeze({...result,taskKey:result.taskKey??taskKey,
|
|
756
|
+
reviewRetryTarget:Object.freeze({taskKey,batchDigest:batchLogDigest(progress())})});
|
|
757
|
+
}
|
|
758
|
+
// retry_review: redispatch exactly the one rate-limited review a driver waited for.
|
|
759
|
+
// batch.lock is held by the caller; the member's own decision check (expectedReviewStop,
|
|
760
|
+
// cm-ai-conversation-entry.mjs) runs in the member run this process opens and whose
|
|
761
|
+
// writer lock it holds. Any difference: staleRetry, nothing dispatched or written.
|
|
762
|
+
async function retryReview(request,state){
|
|
763
|
+
const taskKey=request.taskKey;
|
|
764
|
+
const stale=why=>Object.freeze({outcome:'rejected',code:'review_retry_target_changed',staleRetry:true,
|
|
765
|
+
batchId:config.batchId,taskKey,operation:'retry_review',reason:`状态已变,未自动重试:${why};本次没有派发任何操作`});
|
|
766
|
+
need(typeof taskKey==='string'&&taskKey.length>0,'invalid_input');validIdentity(request.identity);hex(request.packageDigest);hex(request.batchDigest);
|
|
767
|
+
shape(request.expectedReviewStop,['invocationId']);id(request.expectedReviewStop.invocationId);
|
|
768
|
+
if(!plans.has(taskKey))return stale(`${taskKey} 不是本批次的任务`);
|
|
769
|
+
if(state.stopped)return stale('批次已经停止');
|
|
770
|
+
if(request.batchDigest!==batchLogDigest(state))return stale('批次日志在等待期间有了新记录');
|
|
771
|
+
const stopped=membership.has(state.current)
|
|
772
|
+
?membership.get(state.current).filter(key=>membership.has(key)&&!state.ready?.has(key)&&!state.done?.has(key)):[state.current];
|
|
773
|
+
if(!stopped.includes(taskKey))return stale(`批次当前停在 ${stopped.join('、')},不是 ${taskKey}`);
|
|
774
|
+
if(membership.has(taskKey)){
|
|
775
|
+
const {worktree,branch}=location(taskKey);
|
|
776
|
+
if(!fs.existsSync(worktree)||batchGit(worktree,['branch','--show-current'])!==branch)return stale(`${taskKey} 的 worktree 已不在或换了分支`);
|
|
777
|
+
bindWorktree(taskKey);
|
|
778
|
+
}
|
|
531
779
|
const definition=plans.get(taskKey);
|
|
532
|
-
|
|
533
|
-
|
|
780
|
+
if(request.identity.repositoryId!==definition.identity.repositoryId||request.identity.runId!==definition.identity.runId
|
|
781
|
+
||request.identity.taskId!==definition.identity.taskId)return stale(`${taskKey} 的运行已不是等待时那一个`);
|
|
782
|
+
if(!fs.existsSync(path.join(config.specsDir,'.reviews','.execution',definition.identity.runId,'state.json')))
|
|
783
|
+
return stale(`${taskKey} 没有运行存档`);
|
|
784
|
+
const run=await open(taskKey);
|
|
785
|
+
if(run.blocked)return {outcome:'blocked',code:run.blocked.reason,batchId:config.batchId};
|
|
786
|
+
// Registered like a driven member, so a cancel on this host reaches it (it is
|
|
787
|
+
// forwarded to the member run and logged as batch_cancel while the review runs).
|
|
788
|
+
members.set(taskKey,run);
|
|
789
|
+
try{
|
|
790
|
+
// A cancel that arrived while the run was opening: dispatch nothing, record the
|
|
791
|
+
// cancel exactly as the serial path does after its open.
|
|
792
|
+
if(cancelled){
|
|
793
|
+
record('batch_cancel',{from_key:taskKey});
|
|
794
|
+
await run.host.handle({version:1,operation:'cancel',requestId:request.requestId,identity:plans.get(taskKey).identity});
|
|
795
|
+
return Object.freeze({outcome:'cancelled',code:'cancelled',batchId:config.batchId,taskKey});
|
|
796
|
+
}
|
|
797
|
+
const wire={operation:'decision',requestId:request.requestId,identity:request.identity,packageDigest:request.packageDigest,
|
|
798
|
+
expectedReviewStop:{invocationId:request.expectedReviewStop.invocationId}};
|
|
799
|
+
const result=controlPolicy?await run.controlHost.handle({version:2,...wire}):await run.host.handle({version:1,...wire});
|
|
800
|
+
if(cancelled)return Object.freeze({outcome:'cancelled',code:'cancelled',batchId:config.batchId,taskKey});
|
|
801
|
+
return retriedMemberResult(result,taskKey);
|
|
802
|
+
}finally{members.delete(taskKey);run.close();}
|
|
803
|
+
}
|
|
804
|
+
// Only this review: the member keeps its own state, code and identity (approved,
|
|
805
|
+
// changes_requested, a second failure). A next step the batch entry does not take
|
|
806
|
+
// (complete, resume, decision) becomes the batch's advance, with guidance saying so.
|
|
807
|
+
const BATCH_NEXT=new Set(['none','advance',...IN_RUN_ACTIONS]);
|
|
808
|
+
function retriedMemberResult(result,taskKey){
|
|
809
|
+
const base={...result,batchId:config.batchId,taskKey};
|
|
810
|
+
if(result.outcome==='rejected'||result.staleRetry===true||BATCH_NEXT.has(result.pendingAction))return Object.freeze(base);
|
|
811
|
+
const approved=result.state==='approved'&&result.code===null;
|
|
812
|
+
return Object.freeze({...base,pendingAction:'advance',guidance:stopGuidance(
|
|
813
|
+
approved?`审查限流已自动重试,${taskKey} 的审查已通过;批次停在这一步,没有顺带完成、合并或推进其他任务。`
|
|
814
|
+
:`审查限流已自动重试,${taskKey} 的这次审查已有结果(${result.state}${result.code?`/${result.code}`:''});批次没有顺带推进。`,
|
|
815
|
+
'从批次入口发送 advance 继续本批次(成员不能单独发 complete 或 decision)。',
|
|
816
|
+
['自动重试只重派了这一次审查','完成、QA、合并和后续任务由下一次批次 advance 照原流程进行'])});
|
|
534
817
|
}
|
|
535
818
|
async function memberAction(request,state){
|
|
536
819
|
const {option,flag}=BATCH_MEMBER_ACTIONS[request.operation],taskKey=request.taskKey;
|
|
@@ -559,17 +842,18 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
559
842
|
}
|
|
560
843
|
return Object.freeze({controlTarget:()=>batchControlTarget(progress().current),async handle(raw){
|
|
561
844
|
const request=json(raw);shape(request,['operation','requestId',...(request.operation==='reconcile_review'?['taskKey','invocationId']:[]),
|
|
845
|
+
...(request.operation==='retry_review'?['taskKey','identity','packageDigest','expectedReviewStop','batchDigest']:[]),
|
|
562
846
|
...(Object.hasOwn(BATCH_MEMBER_ACTIONS,request.operation??'')?['taskKey','reason']:[]),
|
|
563
847
|
...(controlPolicy?['version',...((IN_RUN_ACTIONS.has(request.operation??''))?['expectedControl']:[])]:[])]);id(request.requestId);
|
|
564
848
|
if(controlPolicy)need(request.version===2,'fingerprint_mismatch');
|
|
565
|
-
need(['advance','status','cancel','reconcile_review',...Object.keys(BATCH_MEMBER_ACTIONS)].includes(request.operation));
|
|
849
|
+
need(['advance','status','cancel','reconcile_review','retry_review',...Object.keys(BATCH_MEMBER_ACTIONS)].includes(request.operation));
|
|
566
850
|
if(request.operation==='cancel'&&busy){
|
|
567
851
|
cancelled=true;
|
|
568
852
|
if(members.size){record('batch_cancel',{from_key:liveKey});
|
|
569
853
|
await Promise.all([...members].map(([key,run])=>run.host.handle({version:1,operation:'cancel',requestId:request.requestId,identity:plans.get(key).identity})));
|
|
570
854
|
return {outcome:'cancelled',code:'cancelled',batchId:config.batchId};}
|
|
571
855
|
if(active){
|
|
572
|
-
if(progress().rows.length===0)record('batch_start',{from_key:liveKey});
|
|
856
|
+
if(progress().rows.length===0)record('batch_start',{from_key:liveKey,[BATCH_SEGMENT_FIELD]:batchSegment(config.batchId)});
|
|
573
857
|
record('batch_cancel',{from_key:liveKey});
|
|
574
858
|
return active.host.handle({version:1,operation:'cancel',requestId:request.requestId,identity:plans.get(liveKey).identity});
|
|
575
859
|
}
|
|
@@ -578,8 +862,16 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
578
862
|
if(request.operation==='status'&&busy)return {outcome:'reported',batchId:config.batchId,currentTask:liveKey,state:'running'};
|
|
579
863
|
need(!busy,'batch_busy');busy=true;
|
|
580
864
|
try{
|
|
581
|
-
|
|
865
|
+
// Another driver holding batch.lock is moving the batch: a timed retry is stale.
|
|
866
|
+
try{releaseLock=acquireBatchLock(config);}
|
|
867
|
+
catch(error){if(request.operation==='retry_review'&&error?.code==='batch_locked')return Object.freeze({outcome:'rejected',
|
|
868
|
+
code:'review_retry_target_changed',staleRetry:true,batchId:config.batchId,taskKey:request.taskKey,operation:'retry_review',
|
|
869
|
+
reason:'状态已变,未自动重试:另一个驾驶员正在推进本批次;本次没有派发任何操作'});throw error;}
|
|
870
|
+
const result=await (async()=>{
|
|
582
871
|
const initial=progress();liveKey=initial.current;
|
|
872
|
+
// A driver's timed rate-limit retry: checked against the frozen batch and member
|
|
873
|
+
// stop while batch.lock is held, before anything else runs or is written.
|
|
874
|
+
if(request.operation==='retry_review')return await retryReview(request,initial);
|
|
583
875
|
if(controlPolicy&&IN_RUN_ACTIONS.has(request.operation)){
|
|
584
876
|
const expected=json(request.expectedControl);shape(expected,['version','batchId','taskKey','member','batchDigest']);
|
|
585
877
|
readControlTarget(expected.member);hex(expected.batchDigest);
|
|
@@ -604,7 +896,15 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
604
896
|
:await run.host.handle({version:1,operation:'reconcile_review',requestId:request.requestId,identity:definition.identity,invocationId:request.invocationId});}
|
|
605
897
|
finally{run.close();}
|
|
606
898
|
}
|
|
607
|
-
if(initial.stopped)
|
|
899
|
+
if(initial.stopped){
|
|
900
|
+
const conflict=initial.code==='merge_conflict'?initial.rows.findLast(row=>row.phase==='batch_merge_conflict'):null;
|
|
901
|
+
// A stop logged before its members were sealed (a crash, or an older version):
|
|
902
|
+
// advance seals them; status stays read-only and reports the stop as logged.
|
|
903
|
+
if(initial.code==='batch_solo_qa_failed')return soloQaFailedStop(initial.rows.findLast(row=>row.phase==='batch_member_qa_failed'));
|
|
904
|
+
const unsealed=!conflict?[]:request.operation==='advance'?await sealForGuidance():unsealedReadOnly();
|
|
905
|
+
return {outcome:'blocked',code:initial.code??'cancelled',batchId:config.batchId,
|
|
906
|
+
...(conflict?{files:conflict.files,...(unsealed.length?{unsealed}:{}),guidance:mergeConflictGuidance(conflict.from_key,conflict.files,unsealed)}:{})};
|
|
907
|
+
}
|
|
608
908
|
if(Object.hasOwn(BATCH_MEMBER_ACTIONS,request.operation))return await memberAction(request,initial);
|
|
609
909
|
if(request.operation==='advance'&&!initial.rows.length){
|
|
610
910
|
const dirty=batchGit(config.codeProject,['status','--porcelain']);
|
|
@@ -639,7 +939,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
639
939
|
if(active.blocked)return {outcome:'blocked',code:active.blocked.reason,batchId:config.batchId};
|
|
640
940
|
// batch.lock serializes selection across processes; child locks remain run-local.
|
|
641
941
|
need(progress().current===liveKey&&!progress().stopped,'batch_history_changed');
|
|
642
|
-
if(progress().rows.length===0&&request.operation!=='status')record('batch_start',{from_key:liveKey});
|
|
942
|
+
if(progress().rows.length===0&&request.operation!=='status')record('batch_start',{from_key:liveKey,[BATCH_SEGMENT_FIELD]:batchSegment(config.batchId)});
|
|
643
943
|
if(cancelled||request.operation==='cancel'){
|
|
644
944
|
record('batch_cancel',{from_key:liveKey});cancelled=true;
|
|
645
945
|
return active.host.handle({version:1,operation:'cancel',requestId:request.requestId,identity:plans.get(liveKey).identity});
|
|
@@ -652,19 +952,37 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
652
952
|
const handoff=result.outcome==='refreshed'&&result.pendingAction==='start_next_task';
|
|
653
953
|
if(request.operation!=='advance'||(!finished&&!handoff))return {...result,batchId:config.batchId};
|
|
654
954
|
const next=handoff?`${result.nextTask.feature}/${result.nextTask.id}`:null;
|
|
655
|
-
|
|
955
|
+
// A batch plans one feature (cm-ai-batch-plan.mjs). When its last task hands
|
|
956
|
+
// off to the next feature, this batch is done: the next feature is planned as
|
|
957
|
+
// a new batch. Anything else outside the plan is still refused.
|
|
958
|
+
const featureDone=handoff&&!plans.has(next)&&[...plans.keys()].at(-1)===liveKey
|
|
959
|
+
&&result.nextTask.feature!==plans.get(liveKey).feature;
|
|
960
|
+
if(handoff&&!featureDone)need(plans.has(next),'batch_task_scope_required');
|
|
656
961
|
let task_commit=commitChanges(config.codeProject,taskCommitArgs(plans.get(liveKey).identity.taskId,taskDescription(config,plans.get(liveKey))));
|
|
657
962
|
if(task_commit)record('batch_task_committed',{from_key:liveKey,task_commit});
|
|
658
963
|
else task_commit=progress().rows.filter(row=>row.phase==='batch_task_committed'&&row.from_key===liveKey).at(-1)?.task_commit??null;
|
|
659
|
-
if(finished)return {...result,batchId:config.batchId,task_commit};
|
|
964
|
+
if(finished)return withDetachedSave({...result,batchId:config.batchId,task_commit});
|
|
965
|
+
if(featureDone)return withDetachedSave({...result,batchId:config.batchId,task_commit,batchComplete:true,nextFeature:result.nextTask.feature,
|
|
966
|
+
guidance:stopGuidance(`本批次的功能 ${plans.get(liveKey).feature} 已全部完成。`,
|
|
967
|
+
`下一个功能是 ${result.nextTask.feature}:用 cm-ai-batch-plan.mjs 以新的批次 ID 生成它的批次再继续。`,[])});
|
|
660
968
|
record('batch_handoff',{from_key:liveKey,to_key:next,checkpoint:active.checkpoint(),package_digest:result.packageDigest,task_commit});
|
|
661
969
|
active.close();active=null;liveKey=next;
|
|
662
970
|
}
|
|
663
971
|
need(false,'batch_limit');
|
|
972
|
+
})();
|
|
973
|
+
// Still under batch.lock: a rate-limited member stop names the frozen target a
|
|
974
|
+
// timed retry_review must find unchanged (the batch log digest and the member).
|
|
975
|
+
return request.operation==='advance'?withReviewRetryTarget(result):result;
|
|
664
976
|
}finally{active?.close();active=null;releaseLock?.();releaseLock=null;busy=false;}
|
|
665
977
|
}});
|
|
666
978
|
}
|
|
667
979
|
|
|
980
|
+
// Review r7: the manual cleanup commands are copied into a shell, so every path and the
|
|
981
|
+
// branch are quoted; they run against the main checkout from any directory.
|
|
982
|
+
const shellWord=word=>/^[\w@%+=:,./-]+$/.test(word)?word:`'${word.replace(/'/g,`'\\''`)}'`;
|
|
983
|
+
export function manualCleanupCommands({repo,worktree,branch}){
|
|
984
|
+
return [`git -C ${shellWord(repo)} worktree remove ${shellWord(worktree)}`,`git -C ${shellWord(repo)} branch -d ${shellWord(branch)}`];
|
|
985
|
+
}
|
|
668
986
|
function gitOptions(){return {encoding:'utf8',timeout:60000,maxBuffer:4*1024*1024,env:{...process.env,GIT_TERMINAL_PROMPT:'0'}};}
|
|
669
987
|
function git(cwd,args,code='batch_git_failed'){
|
|
670
988
|
const result=spawnSync('git',['-C',cwd,...args],gitOptions());
|
|
@@ -699,10 +1017,16 @@ function taskDescription(config,definition){
|
|
|
699
1017
|
{allowDependencyPunctuation:true,grammar:approvedTaskGrammar(config.specsDir)});
|
|
700
1018
|
need(!parsed.error,'parallel_task_invalid');return parsed.tasks.find(task=>task.id===definition.identity.taskId)?.description??definition.identity.taskId;
|
|
701
1019
|
}
|
|
702
|
-
|
|
1020
|
+
// declared: a batch that has not started yet takes parallel members only from
|
|
1021
|
+
// tasks.md scope (written at split time) and never a device task. A batch that
|
|
1022
|
+
// started before that rule keeps resuming under the rules it began with.
|
|
1023
|
+
// A one-member group is a task developed alone in its own worktree (batch-plan.mjs
|
|
1024
|
+
// worktree_all) under the same member rules. Batches written before it existed never
|
|
1025
|
+
// contain one (they were refused), so their resume is unchanged.
|
|
1026
|
+
function validateGroups(config,plans,{declared=false,workflows=null}={}){
|
|
703
1027
|
const groups=config.parallel??[];need(Array.isArray(groups),'invalid_parallel_groups');const used=new Set();
|
|
704
1028
|
for(const group of groups){
|
|
705
|
-
need(Array.isArray(group)&&group.length>=
|
|
1029
|
+
need(Array.isArray(group)&&group.length>=1&&group.length<=4,'invalid_parallel_group');
|
|
706
1030
|
need(group.every(key=>plans.has(key)&&!used.has(key))&&new Set(group).size===group.length,'invalid_parallel_group');
|
|
707
1031
|
const feature=plans.get(group[0]).feature;
|
|
708
1032
|
need(group.every(key=>plans.get(key).feature===feature),'parallel_feature_mismatch');
|
|
@@ -721,14 +1045,104 @@ function validateGroups(config,plans){
|
|
|
721
1045
|
need([...ids].every(id=>[...ids].every(other=>other===id||!reaches(id,other))),'parallel_dependency_conflict');
|
|
722
1046
|
const ordered=parsed.tasks.filter(task=>!task.dropped),last=ordered.at(-1);
|
|
723
1047
|
need(last&&!ids.has(last.id)&&plans.has(`${feature}/${last.id}`),'parallel_final_task_excluded');
|
|
1048
|
+
// The batch runs in plan order: the feature's last planned task collects the
|
|
1049
|
+
// members' deferred QA, so it cannot be a member either (new batches).
|
|
1050
|
+
if(declared)need(!ids.has(plans.get([...plans.keys()].filter(key=>plans.get(key).feature===feature).at(-1)).identity.taskId),
|
|
1051
|
+
'parallel_final_task_excluded');
|
|
724
1052
|
const paths=new Set();
|
|
725
1053
|
for(const key of group)for(const file of plans.get(key).scope){
|
|
726
1054
|
need(!paths.has(file),'parallel_scope_overlap');paths.add(file);
|
|
727
1055
|
}
|
|
1056
|
+
if(declared)for(const key of group){
|
|
1057
|
+
const scope=declaredTaskScope(config.specsDir,plans.get(key).feature,plans.get(key).identity.taskId);
|
|
1058
|
+
need(scope!==null,'parallel_scope_undeclared');need(!scope.device,'parallel_device_task');
|
|
1059
|
+
}
|
|
1060
|
+
// A new batch takes a one-member group only where the planner would propose it
|
|
1061
|
+
// (batch-plan.mjs): same project configuration in the worktree, no interactive QA,
|
|
1062
|
+
// and no fixed N6 checkpoint its QA could hit there (checked below).
|
|
1063
|
+
if(declared&&group.length===1){
|
|
1064
|
+
const blocked=soloWorktreeBlocker({specsDir:config.specsDir,codeProject:config.codeProject,feature});
|
|
1065
|
+
if(blocked)throw Object.assign(new Error(blocked.code),{code:blocked.code,reason:`${group[0]}: ${blocked.reason}`});
|
|
1066
|
+
}
|
|
728
1067
|
for(const key of group)used.add(key);
|
|
729
1068
|
}
|
|
1069
|
+
if(declared)checkSoloQaCheckpoints(config,plans,groups,workflows);
|
|
730
1070
|
return groups;
|
|
731
1071
|
}
|
|
1072
|
+
// Grammar 3 execution table (batch-plan.mjs): batch.memberDevelopment names the members
|
|
1073
|
+
// the session develops, {"feature/T-xxx":"session"}. It is part of the configuration (so
|
|
1074
|
+
// of planDigest) and absent from batches without such members, which keep their exact
|
|
1075
|
+
// plan digest. Present, it must match tasks.md (the 开发: 会话 marks of the approved
|
|
1076
|
+
// grammar 3) and the narrow rule: one session task per feature, its last task (last in
|
|
1077
|
+
// this configuration too, and no task waits for it), never a parallel member. A new batch on grammar 3 without the table is refused the same way;
|
|
1078
|
+
// a started one without it resumes as it began.
|
|
1079
|
+
function validateMemberDevelopment(config,plans,groups,{declared}){
|
|
1080
|
+
const table=config.memberDevelopment,grammar=approvedTaskGrammar(config.specsDir);
|
|
1081
|
+
if(table!==undefined)need(table!==null&&typeof table==='object'&&!Array.isArray(table)&&Object.keys(table).length>0
|
|
1082
|
+
&&Object.entries(table).every(([taskKey,value])=>plans.has(taskKey)&&value==='session'),'invalid_member_development');
|
|
1083
|
+
// External models and execution policy rewrite the reviewer identity and the abandon
|
|
1084
|
+
// rules; a session member is not supported with either in this round.
|
|
1085
|
+
if(table!==undefined)need(!config.externalModels&&!config.executionPolicy,'session_member_unsupported_config');
|
|
1086
|
+
if(table===undefined&&(!declared||grammar!==TASK_GRAMMAR))return;
|
|
1087
|
+
const grouped=new Set(groups.flat());
|
|
1088
|
+
for(const feature of new Set([...plans.values()].map(plan=>plan.feature))){
|
|
1089
|
+
const text=fs.readFileSync(path.join(config.specsDir,feature,'tasks.md'),'utf8');
|
|
1090
|
+
const parsed=parseFeatureTaskText(text,{allowDependencyPunctuation:true,grammar});need(!parsed.error,'parallel_task_invalid');
|
|
1091
|
+
const sessions=grammar===TASK_GRAMMAR?parseTaskScopes(text,{grammar}).sessions:new Set();
|
|
1092
|
+
const problem=sessionTaskProblem(parsed.tasks,sessions,parsed.dependencies);
|
|
1093
|
+
if(problem)throw Object.assign(new Error(problem.code),{code:problem.code,reason:`${feature}/tasks.md:${sessionTaskReason(problem)}`});
|
|
1094
|
+
// The same rule on this configuration's own order (a hand-written one too, whatever
|
|
1095
|
+
// planned it): the session member runs last among the feature's members, and no task
|
|
1096
|
+
// of the feature waits for it.
|
|
1097
|
+
const members=[...plans.keys()].filter(taskKey=>plans.get(taskKey).feature===feature);
|
|
1098
|
+
for(const taskKey of members.filter(item=>sessions.has(plans.get(item).identity.taskId))){
|
|
1099
|
+
const taskId=plans.get(taskKey).identity.taskId,dependents=taskDependents(parsed.tasks,parsed.dependencies,taskId);
|
|
1100
|
+
if(dependents.length){
|
|
1101
|
+
const late={code:'session_task_depended_on',tasks:[taskId],dependents};
|
|
1102
|
+
throw Object.assign(new Error(late.code),{code:late.code,reason:`${feature}/tasks.md:${sessionTaskReason(late)}`});
|
|
1103
|
+
}
|
|
1104
|
+
if(taskKey!==members.at(-1))throw Object.assign(new Error('session_task_not_final'),{code:'session_task_not_final',
|
|
1105
|
+
reason:`${taskKey}:会话任务在批次配置里排在 ${members.slice(members.indexOf(taskKey)+1).join(', ')} 前面;它只能是该功能最后执行的成员,用 cm-ai-batch-plan.mjs 重新生成批次配置`});
|
|
1106
|
+
}
|
|
1107
|
+
for(const [taskKey,plan] of plans){
|
|
1108
|
+
if(plan.feature!==feature)continue;
|
|
1109
|
+
const session=sessions.has(plan.identity.taskId);
|
|
1110
|
+
if(session&&grouped.has(taskKey))throw Object.assign(new Error('session_task_parallel'),{code:'session_task_parallel',reason:`${taskKey}:会话任务不能进并行组`});
|
|
1111
|
+
if(session!==Object.hasOwn(table??{},taskKey))throw Object.assign(new Error('member_development_mismatch'),{code:'member_development_mismatch',
|
|
1112
|
+
reason:`${taskKey}:批次执行表与 tasks.md 的「开发: 会话」标记不一致;用 cm-ai-batch-plan.mjs 重新生成批次配置`});
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
// The planner's walk along the batch order (soloQaCounter), with the launched workflows
|
|
1117
|
+
// and control policy. The count spans features (and a feature that closes drops its tasks
|
|
1118
|
+
// from floor), so a one-member group needs a one-feature batch. Its groups must be
|
|
1119
|
+
// contiguous in that order: a blocked member reruns when it is the first unfinished task,
|
|
1120
|
+
// so a member placed after outside tasks would rerun (and maybe reset the count) after them.
|
|
1121
|
+
function checkSoloQaCheckpoints(config,plans,groups,workflows){
|
|
1122
|
+
const solos=groups.filter(group=>group.length===1);
|
|
1123
|
+
if(!solos.length)return;
|
|
1124
|
+
const features=new Set([...plans.values()].map(plan=>plan.feature));
|
|
1125
|
+
if(features.size>1)throw Object.assign(new Error('parallel_solo_multi_feature'),{code:'parallel_solo_multi_feature',
|
|
1126
|
+
reason:`${solos[0][0]}: 批次含多个功能时不能单独开 worktree(QA 计数跨功能累计,推算不准);按功能分别生成批次(cm-ai-batch-plan.mjs)`});
|
|
1127
|
+
const order=[...plans.keys()];
|
|
1128
|
+
for(const group of groups){
|
|
1129
|
+
const at=group.map(key=>order.indexOf(key));
|
|
1130
|
+
if(Math.max(...at)-Math.min(...at)!==group.length-1)throw Object.assign(new Error('parallel_solo_split_group'),{code:'parallel_solo_split_group',
|
|
1131
|
+
reason:`${group.join(',')}: 有单独开 worktree 的任务时,同组成员必须在任务顺序里相邻(被阻断的成员改回主目录重做的时点才可推算);按顺序重排或用 cm-ai-batch-plan.mjs 重新生成`});
|
|
1132
|
+
}
|
|
1133
|
+
const [feature]=features,groupOf=new Map(groups.flatMap(group=>group.map(key=>[key,group]))),placed=new Set();
|
|
1134
|
+
const counter=soloQaCounter(soloQaBase({specsDir:config.specsDir,codeProject:config.codeProject,feature,repositoryId:config.repositoryId}));
|
|
1135
|
+
for(const key of plans.keys()){
|
|
1136
|
+
if(placed.has(key))continue;
|
|
1137
|
+
const group=groupOf.get(key)??[key];group.forEach(member=>placed.add(member));
|
|
1138
|
+
if(group.length>1){counter.placeGroup(group.length);continue;}
|
|
1139
|
+
const scope=plans.get(key).scope,workflow=workflows?.[key]??null;
|
|
1140
|
+
const rule=groupOf.has(key)?counter.check(scope,workflow):null;
|
|
1141
|
+
if(rule)throw Object.assign(new Error('parallel_solo_qa_checkpoint'),{code:'parallel_solo_qa_checkpoint',
|
|
1142
|
+
reason:`${key}: 单独在 worktree 里开发时 QA 可能按固定检查点触发(${rule}),批次没有 QA 修复出口;让它在主目录串行(用 cm-ai-batch-plan.mjs 带 --workflow-config 重新生成)`});
|
|
1143
|
+
counter.place(groupOf.has(key)?'solo':'main',scope,{workflow,hostDecides:workflowDecidesQa(workflow)||Boolean(config.controlPolicy)});
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
732
1146
|
function acquireBatchLock(config){
|
|
733
1147
|
const directory=path.join(config.specsDir,'.reviews','.execution');fs.mkdirSync(directory,{recursive:true,mode:0o700});
|
|
734
1148
|
need(fs.realpathSync(directory)===directory,'batch_lock_invalid');
|