@aibyzero/cm-workflow 0.17.1 → 0.19.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 +242 -0
- package/README.md +20 -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/autonomy.mjs +152 -0
- 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 +56 -17
- 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 +115 -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 +581 -65
- 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 +5 -4
- 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 +21 -7
- package/scripts/cm-ai-admission.test.mjs +171 -3
- 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-autonomy.mjs +94 -0
- package/scripts/cm-autonomy.test.mjs +162 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +60 -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 +581 -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 +323 -0
- package/scripts/cm-start-check.test.mjs +406 -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 +4 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N3-execute-task.md +1 -1
- 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 +82 -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 +14 -9
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +8 -1
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-change-recovery.md +14 -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
|
@@ -3,12 +3,14 @@ import assert from 'node:assert/strict';
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import {spawnSync} from 'node:child_process';
|
|
6
|
+
import {spawn,spawnSync} from 'node:child_process';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
8
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
9
|
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
10
10
|
import {claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
11
|
-
import {batchDevelopAttempts} from './cm-ai-batch-drive.mjs';
|
|
11
|
+
import {batchDevelopAttempts,batchSessionMembers,batchLiveDevelopError,liveDevelopWaitMs,liveAnswerRoute,LIVE_DEVELOP_MARGIN_MS} from './cm-ai-batch-drive.mjs';
|
|
12
|
+
import {createLiveEvidence} from '../runtime/js/cm-ai/live-evidence.mjs';
|
|
13
|
+
import {HOST_ANSWER_TIMEOUT_DEFAULT_MS} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
12
14
|
import {runLiveDriver} from './fixtures/live-evidence-driver.mjs';
|
|
13
15
|
|
|
14
16
|
const DRIVER=fileURLToPath(new URL('./cm-ai-batch-drive.mjs',import.meta.url));
|
|
@@ -24,8 +26,9 @@ function fixture(t,count=1){
|
|
|
24
26
|
const specsDir=path.join(root,'specs5'),codeProject=path.join(root,'app'),bin=path.join(root,'bin');
|
|
25
27
|
fs.mkdirSync(path.join(specsDir,'1.work'),{recursive:true});fs.mkdirSync(codeProject);fs.mkdirSync(bin);
|
|
26
28
|
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,'1.work',name),'# Fixture\n');
|
|
29
|
+
// Each task declares the same file the batch config gives it.
|
|
27
30
|
fs.writeFileSync(path.join(specsDir,'1.work','tasks.md'),Array.from({length:count},(_,n)=>
|
|
28
|
-
`- [ ] T-00${n+1}: implement target ${n+1}\n`).join(''));
|
|
31
|
+
`- [ ] T-00${n+1}: implement target ${n+1}\n - 范围: \`${n===0?'target.mjs':`target${n+1}.mjs`}\`\n`).join(''));
|
|
29
32
|
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(specsDir)}));
|
|
30
33
|
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
31
34
|
for(const args of [['init','-b','main'],['config','user.name','Fixture'],['config','user.email','fixture@example.invalid'],['add','-A'],['commit','-m','baseline']]){
|
|
@@ -127,6 +130,22 @@ test('real batch host advances with authored edit and actual check, then resumes
|
|
|
127
130
|
const again=f.drive(f.plan({mode:'resume',originalHostContext:'batch-host-a'}),'advance');
|
|
128
131
|
assert.equal(again.status,0,again.stderr);
|
|
129
132
|
});
|
|
133
|
+
// The project log is shared by every run in the specs root. Rows of other runs,
|
|
134
|
+
// including another batch, must not make a new batch look already started.
|
|
135
|
+
test('a new batch starts in a specs root whose shared project log has only other runs',t=>{
|
|
136
|
+
const f=fixture(t);prepared(f);
|
|
137
|
+
const foreign=[{schema_version:1,workflow:'cm-prd',event:'run_done',run_id:'prd-earlier'},
|
|
138
|
+
{schema_version:1,workflow:'cm-ai',event:'decision',phase:'batch_start',run_id:'some-other-batch',from_key:'1.work/T-001'},
|
|
139
|
+
{schema_version:1,workflow:'cm-ai',event:'progress',run_id:'batch-drive-run',detail:'not a batch decision row'}];
|
|
140
|
+
fs.writeFileSync(path.join(f.specsDir,'运行日志.jsonl'),foreign.map(row=>JSON.stringify(row)).join('\n')+'\n');
|
|
141
|
+
const first=f.drive(f.plan(),'advance');
|
|
142
|
+
assert.equal(first.status,0,first.stderr);
|
|
143
|
+
assert.doesNotMatch(first.stderr,/批次已有存档/);
|
|
144
|
+
assert.match(first.stderr,/应答 develop/);
|
|
145
|
+
// Once this batch has written its own decision rows, create is refused again.
|
|
146
|
+
const again=f.drive(f.plan(),'advance');
|
|
147
|
+
assert.equal(again.status,2);assert.match(again.stderr,/批次已有存档,请用 resume/);
|
|
148
|
+
});
|
|
130
149
|
test('real batch reaches completion with automatic configured fixture review',t=>{
|
|
131
150
|
const f=fixture(t);prepared(f);
|
|
132
151
|
f.write('develop-a2.json',develop);
|
|
@@ -230,6 +249,9 @@ test('batch driver refuses an oversized answer of a later task before launching
|
|
|
230
249
|
function laterTask(f,scope,files){
|
|
231
250
|
const config=path.join(f.root,'batch.json'),bundle=JSON.parse(fs.readFileSync(config,'utf8'));
|
|
232
251
|
bundle.batch.tasks[1].scope=scope;fs.writeFileSync(config,JSON.stringify(bundle));
|
|
252
|
+
// tasks.md is the authority for T-002's files: keep it equal to the batch config.
|
|
253
|
+
const tasks=path.join(bundle.batch.specsDir,'1.work','tasks.md');
|
|
254
|
+
fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace(' - 范围: `target2.mjs`',` - 范围: ${scope.map(file=>`\`${file}\``).join(', ')}`));
|
|
233
255
|
const later=path.join(f.root,'answers','1.work','T-002');fs.mkdirSync(later,{recursive:true});
|
|
234
256
|
for(const name of ['qa-assess.json','documentation-inspect.json'])
|
|
235
257
|
fs.copyFileSync(path.join(f.answers,name),path.join(later,name));
|
|
@@ -471,3 +493,147 @@ test('batch configured review reaches both rounds and completes without a review
|
|
|
471
493
|
assert.match(fs.readFileSync(path.join(f.specsDir,'.reviews','work-T-001-r1.md'),'utf8'),/verdict: changes_requested/);
|
|
472
494
|
assert.match(fs.readFileSync(path.join(f.specsDir,'.reviews','work-T-001-r2.md'),'utf8'),/verdict: approved/);
|
|
473
495
|
});
|
|
496
|
+
|
|
497
|
+
// Batch review rate limit (2026-10-26 follow-up): the batch driver waits, then sends
|
|
498
|
+
// retry_review with the frozen batch and member stop. The batch host redispatches
|
|
499
|
+
// exactly that review, or answers staleRetry without dispatching anything.
|
|
500
|
+
function rateLimitedReviewer(f,failures){
|
|
501
|
+
const cli=path.join(f.root,'bin','codex'),counter=path.join(f.root,'review-calls.txt');
|
|
502
|
+
fs.writeFileSync(cli,`#!/usr/bin/env node
|
|
503
|
+
import fs from 'node:fs';import {randomUUID} from 'node:crypto';
|
|
504
|
+
const counter=${JSON.stringify(counter)};const calls=(fs.existsSync(counter)?Number(fs.readFileSync(counter,'utf8')):0)+1;
|
|
505
|
+
fs.writeFileSync(counter,String(calls));
|
|
506
|
+
if(calls<=${failures}){
|
|
507
|
+
let prompt='';for await(const part of process.stdin)prompt+=part;
|
|
508
|
+
const message='exceeded retry limit, last status: 429 Too Many Requests';
|
|
509
|
+
for(const value of [{type:'thread.started',thread_id:randomUUID()},{type:'turn.started'},{type:'error',message},{type:'turn.failed',error:{message}}])
|
|
510
|
+
process.stdout.write(JSON.stringify(value)+'\\n');
|
|
511
|
+
// Like the real CLI, still alive when the worker stops it (an instant exit races the
|
|
512
|
+
// worker's group signal; macOS answers EPERM for a group that is only a zombie).
|
|
513
|
+
setTimeout(()=>process.exit(1),5000);await new Promise(()=>{});
|
|
514
|
+
}
|
|
515
|
+
await import(${JSON.stringify(reviewer)});
|
|
516
|
+
`);
|
|
517
|
+
fs.chmodSync(cli,0o700);
|
|
518
|
+
return ()=>fs.existsSync(counter)?Number(fs.readFileSync(counter,'utf8')):0;
|
|
519
|
+
}
|
|
520
|
+
const batchLog=f=>{const file=path.join(f.specsDir,'运行日志.jsonl');return fs.existsSync(file)?fs.readFileSync(file,'utf8')
|
|
521
|
+
.split('\n').filter(Boolean).map(JSON.parse).filter(row=>typeof row.phase==='string'&&row.phase.startsWith('batch_')):[];};
|
|
522
|
+
const until=async(check,ms=20000)=>{const end=Date.now()+ms;while(!check()&&Date.now()<end)await new Promise(r=>setTimeout(r,50));return check();};
|
|
523
|
+
function driveAsync(f,file,operation,env){
|
|
524
|
+
const child=spawn(process.execPath,[DRIVER,'--plan',file,operation],{env:{...process.env,PATH:path.join(f.root,'bin')+path.delimiter+process.env.PATH,
|
|
525
|
+
CM_WORKFLOW_HOME:path.join(f.root,'home'),CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs'),...env}});
|
|
526
|
+
let stdout='',stderr='';child.stdout.on('data',c=>stdout+=c);child.stderr.on('data',c=>stderr+=c);
|
|
527
|
+
return {stderr:()=>stderr,done:new Promise(resolve=>child.on('close',status=>resolve({status,stdout,stderr})))};
|
|
528
|
+
}
|
|
529
|
+
test('batch driver waits out a member review rate limit and redispatches only that review with retry_review',async t=>{
|
|
530
|
+
const f=fixture(t);prepared(f);f.write('develop-a2.json',develop);
|
|
531
|
+
const reviews=rateLimitedReviewer(f,1),permissions=['--allow-qa','--review-config','review.json'];
|
|
532
|
+
const tasks=path.join(f.specsDir,'1.work','tasks.md'),before=fs.readFileSync(tasks,'utf8');
|
|
533
|
+
const run=await driveAsync(f,f.plan({permissions}),'advance',{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'300,300,300'}).done;
|
|
534
|
+
assert.equal(run.status,0,run.stderr);
|
|
535
|
+
assert.match(run.stderr,/审查被限流(reviewer_rate_limited),1 秒后在原运行自动重派审查(第 1\/3 次)/);
|
|
536
|
+
const result=JSON.parse(run.stdout).result;
|
|
537
|
+
// Only that review: the member is approved, nothing completed, merged or handed off.
|
|
538
|
+
assert.equal(result.state,'approved',run.stdout);assert.equal(result.taskKey,key);assert.equal(result.operation,'decision');
|
|
539
|
+
// The batch's next step, not the member's complete: send advance from the batch entry.
|
|
540
|
+
assert.equal(result.pendingAction,'advance');assert.match(result.guidance.nextStep,/从批次入口发送 advance/);
|
|
541
|
+
assert.equal(reviews(),2);assert.equal(fs.readFileSync(tasks,'utf8'),before);
|
|
542
|
+
assert.deepEqual(batchLog(f).map(row=>row.phase),['batch_start']);
|
|
543
|
+
// The next advance continues the batch as usual.
|
|
544
|
+
const next=f.drive(f.plan({mode:'resume',originalHostContext:'batch-host-a',permissions}),'advance');
|
|
545
|
+
assert.equal(next.status,0,next.stderr);assert.notEqual(JSON.parse(next.stdout).result.state,'approved');
|
|
546
|
+
});
|
|
547
|
+
test('batch rate-limit retry is stale once another driver moved the batch on: nothing dispatched or written',async t=>{
|
|
548
|
+
const f=fixture(t);prepared(f);f.write('develop-a2.json',develop);
|
|
549
|
+
const reviews=rateLimitedReviewer(f,1),permissions=['--allow-qa','--review-config','review.json'];
|
|
550
|
+
const waiting=driveAsync(f,f.plan({permissions}),'advance',{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'15000'});
|
|
551
|
+
assert(await until(()=>/秒后在原运行自动重派审查/.test(waiting.stderr())),'the first driver is waiting');
|
|
552
|
+
// Meanwhile the session advances the batch itself.
|
|
553
|
+
const other=f.drive(f.plan({mode:'resume',originalHostContext:'batch-host-a',permissions}),'advance');
|
|
554
|
+
assert.equal(other.status,0,other.stderr);assert.equal(reviews(),2);
|
|
555
|
+
const tasks=path.join(f.specsDir,'1.work','tasks.md'),afterOther={tasks:fs.readFileSync(tasks,'utf8'),log:batchLog(f)};
|
|
556
|
+
const first=await waiting.done,result=JSON.parse(first.stdout).result;
|
|
557
|
+
assert.equal(result.staleRetry,true,first.stdout);assert.equal(result.outcome,'rejected');
|
|
558
|
+
assert.match(first.stderr,/状态已变,未自动重试/);
|
|
559
|
+
assert.equal(reviews(),2,'no third review');
|
|
560
|
+
assert.deepEqual({tasks:fs.readFileSync(tasks,'utf8'),log:batchLog(f)},afterOther,'tasks.md and the batch log unchanged');
|
|
561
|
+
});
|
|
562
|
+
test('batch rate-limit retry stops at the round\'s second failure and does not retry again',async t=>{
|
|
563
|
+
const f=fixture(t);prepared(f);f.write('develop-a2.json',develop);
|
|
564
|
+
const reviews=rateLimitedReviewer(f,2),permissions=['--allow-qa','--review-config','review.json'];
|
|
565
|
+
const run=await driveAsync(f,f.plan({permissions}),'advance',{CM_DRIVE_RATE_LIMIT_DELAYS_MS:'300,300,300'}).done;
|
|
566
|
+
const result=JSON.parse(run.stdout).result;
|
|
567
|
+
assert.equal(result.state,'blocked',run.stdout);assert.equal(result.pendingAction,'abandon_review');
|
|
568
|
+
assert.equal(reviews(),2);assert.equal((run.stderr.match(/自动重派审查(第 /g)??[]).length,1);
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
// Design 3.4: session members of a v2 provider batch (batch.memberDevelopment).
|
|
572
|
+
const sessionBatch={tasks:[{feature:'1.work',taskId:'T-001'},{feature:'1.work',taskId:'T-002'}],memberDevelopment:{'1.work/T-002':'session'}};
|
|
573
|
+
const providerPolicy={version:2,development:'provider',bootstrap:'disabled',qa:'disabled',qaFix:'disabled'};
|
|
574
|
+
test('session members come only from memberDevelopment of a v2 provider batch',()=>{
|
|
575
|
+
assert.deepEqual([...batchSessionMembers(sessionBatch,providerPolicy)],['1.work/T-002']);
|
|
576
|
+
const {memberDevelopment,...legacy}=sessionBatch;
|
|
577
|
+
// No field (old batch), a conversation policy or the legacy entry: nobody changes.
|
|
578
|
+
assert.equal(batchSessionMembers(legacy,providerPolicy).size,0);
|
|
579
|
+
assert.equal(batchSessionMembers(sessionBatch,{...providerPolicy,development:'conversation'}).size,0);
|
|
580
|
+
assert.equal(batchSessionMembers(sessionBatch,undefined).size,0);
|
|
581
|
+
});
|
|
582
|
+
test('develop declaration must match the session members',()=>{
|
|
583
|
+
const members=new Set(['1.work/T-002']);
|
|
584
|
+
assert.equal(batchLiveDevelopError(members,true,'advance'),null);
|
|
585
|
+
assert.match(batchLiveDevelopError(members,false,'advance'),/1\.work\/T-002.*liveEvidence\.kinds 需要声明 develop/);
|
|
586
|
+
assert.equal(batchLiveDevelopError(members,false,'status'),null);
|
|
587
|
+
for(const operation of ['advance','status'])assert.match(batchLiveDevelopError(new Set(),true,operation),/没有开发方为会话的成员/);
|
|
588
|
+
assert.equal(batchLiveDevelopError(new Set(),false,'advance'),null);
|
|
589
|
+
});
|
|
590
|
+
test('develop live wait never ends before the host develop deadline',()=>{
|
|
591
|
+
assert.equal(LIVE_DEVELOP_MARGIN_MS>0,true);
|
|
592
|
+
assert.equal(liveDevelopWaitMs({}),HOST_ANSWER_TIMEOUT_DEFAULT_MS+LIVE_DEVELOP_MARGIN_MS);
|
|
593
|
+
assert.equal(liveDevelopWaitMs({CM_HOST_ANSWER_TIMEOUT_MINUTES:'45'}),45*60000+LIVE_DEVELOP_MARGIN_MS);
|
|
594
|
+
// The session develop call is still cut at 30 minutes by the runner: a smaller or invalid value cannot shorten the wait.
|
|
595
|
+
for(const value of ['10','0','abc'])assert.equal(liveDevelopWaitMs({CM_HOST_ANSWER_TIMEOUT_MINUTES:value}),HOST_ANSWER_TIMEOUT_DEFAULT_MS+LIVE_DEVELOP_MARGIN_MS);
|
|
596
|
+
});
|
|
597
|
+
test('live develop reaches only session members and returns the protected proposal unchanged',async t=>{
|
|
598
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-live-develop-')));
|
|
599
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
600
|
+
const reply={status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
601
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null},requirements:[]},edits:[{path:'docs/qa.md',beforeSha256:null,content:'# QA\n'}]};
|
|
602
|
+
let written;
|
|
603
|
+
const live=createLiveEvidence({directory:'exchange',kinds:['develop','qa_logic'],timeoutMs:1000},{base:root,
|
|
604
|
+
allowedKinds:['qa_logic','qa_browser','verification_precheck','develop'],minimumTimeouts:{develop:liveDevelopWaitMs({})},notify:file=>{
|
|
605
|
+
written=JSON.parse(fs.readFileSync(file,'utf8'));
|
|
606
|
+
fs.writeFileSync(file.replace('.request.json','.result.json'),JSON.stringify({type:'host_result',sessionId:written.sessionId,
|
|
607
|
+
callId:written.callId,requestDigest:written.requestDigest,result:reply}));}});
|
|
608
|
+
assert.equal(live.timeoutFor('develop'),HOST_ANSWER_TIMEOUT_DEFAULT_MS+LIVE_DEVELOP_MARGIN_MS);assert.equal(live.timeoutFor('qa_logic'),1000);
|
|
609
|
+
const runs=new Map([['run-1',{key:'1.work/T-001',generation:1}],['run-2',{key:'1.work/T-002',generation:1}]]);
|
|
610
|
+
const state={live,runs,sessionMembers:new Set(['1.work/T-002'])};
|
|
611
|
+
const developRow=runId=>({type:'host_request',sessionId:'s',callId:`c-${runId}`,requestDigest:'b'.repeat(64),kind:'develop',
|
|
612
|
+
payload:{request:{identity:{repositoryId:'r',runId,taskId:'T-002',attempt:1},payload:{scope:['docs/qa.md']}},prompt:'p',
|
|
613
|
+
codeProject:'/fixture/app',route:{role:'developer'},editMode:'protected-text-v1',expected:{'docs/qa.md':null}}});
|
|
614
|
+
assert.equal(liveAnswerRoute(developRow('run-1'),state),false,'a provider member never answers develop live');
|
|
615
|
+
assert.equal(liveAnswerRoute({...developRow('run-2'),kind:'qa_logic'},state),true);
|
|
616
|
+
assert.equal(liveAnswerRoute({...developRow('run-2'),kind:'qa_browser'},state),false);
|
|
617
|
+
const row=developRow('run-2');assert.equal(liveAnswerRoute(row,state),true);
|
|
618
|
+
assert.deepEqual(await live.answer(row),reply);assert.deepEqual(written,row);
|
|
619
|
+
});
|
|
620
|
+
test('legacy batch refuses a develop live declaration before launch',t=>{
|
|
621
|
+
const f=fixture(t);prepared(f);
|
|
622
|
+
const r=f.drive(f.plan({liveEvidence:{directory:'exchange',kinds:['develop']}}),'advance');
|
|
623
|
+
assert.equal(r.status,2,r.stderr);assert.match(r.stderr,/没有开发方为会话的成员/);noStore(f);
|
|
624
|
+
});
|
|
625
|
+
// AI潮: workflow qa without timeoutMs gives each case 60 s while the live responder waits
|
|
626
|
+
// 15 minutes by default, so every minutes-long iOS walkthrough came back BLOCKED.
|
|
627
|
+
test('a new batch whose QA answer window is shorter than the live wait stops before starting',async t=>{
|
|
628
|
+
const f=fixture(t);prepared(f);
|
|
629
|
+
const cases=['logic','browser'].map((kind,index)=>({id:`TC-00${index+1}`,origin:'user',kind,blocking:true,
|
|
630
|
+
acIds:[],taskIds:['T-001'],title:'Fixture observation',preconditions:[],steps:['Observe fixture'],expected:['value is 42'],cleanup:[]}));
|
|
631
|
+
fs.writeFileSync(path.join(f.specsDir,'1.work/test-cases.json'),JSON.stringify({schemaVersion:'1.0',feature:'work',cases}));
|
|
632
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(f.specsDir)}));
|
|
633
|
+
const plan=f.plan({permissions:['--allow-qa','--browser-qa','available'],
|
|
634
|
+
liveEvidence:{directory:'exchange',kinds:['qa_logic','qa_browser'],timeoutMs:900000}});
|
|
635
|
+
const r=f.drive(plan,'advance');
|
|
636
|
+
assert.equal(r.status,2,r.stderr);
|
|
637
|
+
assert.match(r.stderr,/1\.work\/T-001: workflow 的 qa\.timeoutMs 未填(默认 60000) 毫秒,短于 PLAN\.liveEvidence 对 qa_logic、qa_browser 的等待 900000 毫秒/);
|
|
638
|
+
noStore(f);
|
|
639
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {readBatchExecutionPolicy,freezeBatchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
3
|
+
import {batchSegments,batchMemberWorktree} from '../runtime/js/cm-ai/batch-location.mjs';
|
|
3
4
|
import {readBatchExternalModels,freezeBatchExternalModels,batchModelsFile} from '../runtime/js/cm-ai/external-group-models.mjs';
|
|
4
5
|
// Current-conversation transport for the existing batch driver, not a new loop.
|
|
5
6
|
import fs from 'node:fs';
|
|
@@ -89,7 +90,7 @@ export function migrateLegacyPreflightCache(batch,review,runtime){
|
|
|
89
90
|
try{const a=fs.lstatSync(file),b=fs.lstatSync(destination);interrupted=a.dev===b.dev&&a.ino===b.ino;}catch(error){if(error.code!=='ENOENT')throw error;}
|
|
90
91
|
const source=pinned(file,interrupted?2:1);
|
|
91
92
|
if(source===null)refuse(`${entry.name} 在核对时消失`);
|
|
92
|
-
const cwd=
|
|
93
|
+
const cwd=batchMemberWorktree({codeProject:batch.codeProject,taskId,segments:batchSegments({specsDir:batch.specsDir,batchId:batch.batchId})});
|
|
93
94
|
const options={cwd,model:review.model,disabledSkills:review.disabledSkills,promptTransport:'stdin'};
|
|
94
95
|
let cached;try{cached=readConversationReviewConfigurationValue(JSON.parse(source.bytes.toString('utf8')),null);}
|
|
95
96
|
catch{refuse(`${entry.name} 不是预检缓存格式`);}
|
|
@@ -179,6 +180,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
179
180
|
const {batch,workflows,bootstraps=null}=bundle;need(Array.isArray(batch.tasks),'invalid_batch_config');
|
|
180
181
|
need(workflows!==null&&typeof workflows==='object'&&!Array.isArray(workflows),'invalid_batch_config');
|
|
181
182
|
const keys=batch.tasks.map(task=>`${task.feature}/${task.taskId}`);
|
|
183
|
+
// Grammar 3 execution table (batch-plan.mjs; validated again by createCmAiBatch): the
|
|
184
|
+
// members the current session develops even when a provider develops the rest.
|
|
185
|
+
const sessionMembers=new Set(batch.memberDevelopment!==null&&typeof batch.memberDevelopment==='object'?Object.keys(batch.memberDevelopment):[]);
|
|
182
186
|
if(bootstraps!==null){
|
|
183
187
|
need(typeof bootstraps==='object'&&!Array.isArray(bootstraps),'invalid_bootstrap_config');
|
|
184
188
|
for(const [key,config] of Object.entries(bootstraps)){
|
|
@@ -245,12 +249,14 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
245
249
|
}
|
|
246
250
|
else need(false,'invalid_arguments');
|
|
247
251
|
}
|
|
252
|
+
if([...developments.keys()].some(key=>sessionMembers.has(key)))throw Object.assign(new Error('invalid_arguments'),
|
|
253
|
+
{code:'invalid_arguments',reason:'--allow-provider-development 不能授权批次执行表里由会话开发的成员'});
|
|
248
254
|
if(controlPolicy){
|
|
249
255
|
allowQa=controlPolicy.qa==='run';allowBootstrap=controlPolicy.bootstrap==='write';
|
|
250
256
|
need((controlPolicy.development==='provider')===Boolean(providerConfig),'invalid_arguments');
|
|
251
257
|
need(controlPolicy.bootstrap!=='write'||bootstraps!==null,'invalid_arguments');
|
|
252
258
|
need(bootstraps===null||controlPolicy.bootstrap==='write','invalid_arguments');
|
|
253
|
-
if(providerConfig)for(const key of keys)developments.set(key,1);
|
|
259
|
+
if(providerConfig)for(const key of keys)if(!sessionMembers.has(key))developments.set(key,1);
|
|
254
260
|
need(!rerunUnknownQa&&!rerunBlockedQa,'supersede_unavailable');
|
|
255
261
|
}
|
|
256
262
|
const started=keys.some(key=>fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',batchTaskRunId(batch.batchId,key),'state.json')));
|
|
@@ -268,6 +274,15 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
268
274
|
need(!Object.hasOwn(providerConfig,'effort')||providerConfig.effort===pair.effort,'external_model_configuration_conflict');
|
|
269
275
|
providerConfig={...providerConfig,...pair};
|
|
270
276
|
}
|
|
277
|
+
need(!sessionMembers.size||!externalModels&&!executionPolicy,'session_member_unsupported_config');
|
|
278
|
+
// A v2 provider batch: a session member's coder is this host, so it must be the
|
|
279
|
+
// declared coder; it is reviewed by the declared reviewer like the provider members
|
|
280
|
+
// (reviewRuntime), never by the host itself.
|
|
281
|
+
const sessionReviewRuntime=controlPolicy?.development==='provider'&&sessionMembers.size?routes.reviewerRuntime:null;
|
|
282
|
+
if(sessionReviewRuntime!==null&&routes.coderRuntime!==(runtime??'codex'))
|
|
283
|
+
throw Object.assign(new Error('session_coder_runtime_mismatch'),{code:'session_coder_runtime_mismatch',
|
|
284
|
+
reason:`成员 ${[...sessionMembers].join(', ')} 由当前会话开发,宿主运行时必须是项目声明的写代码方 ${routes.coderRuntime};`
|
|
285
|
+
+`现在是 ${runtime??'codex(未传 --runtime 时的缺省值)'}。在 PLAN.permissions 加 --runtime ${routes.coderRuntime}`});
|
|
271
286
|
review=review===null?null:readConversationReviewConfiguration(review,externalModels?.providers[routes.reviewerRuntime]??null);
|
|
272
287
|
need(!developments.size||providerConfig!==null,'protected_configuration_required');
|
|
273
288
|
// Same launch-time assertion as the single-task host, evaluated across every
|
|
@@ -302,14 +317,23 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
302
317
|
let reconciling=false;
|
|
303
318
|
const driver=createCmAiBatch({configuration:{...batch,...(controlPolicy?{controlPolicy}:{}),...(externalModels?{externalModels}:{}),...(executionPolicy?{executionPolicy}:{})},logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
|
|
304
319
|
runtime:runtime??'codex',checkCommands:(providerConfig??protection)?.checkCommands??null,checkTimeoutMs:(providerConfig??protection)?.timeoutMs??60000,
|
|
305
|
-
rerunUnknownQa,rerunBlockedQa,qaEnvironmentFailure,memberActions,holdRevisions:[...holds],bootstrapKeys:Object.keys(bootstraps??{}),
|
|
306
|
-
executionFor:async(definition,{parallelMember=false}={})=>{
|
|
320
|
+
rerunUnknownQa,rerunBlockedQa,qaEnvironmentFailure,memberActions,holdRevisions:[...holds],bootstrapKeys:Object.keys(bootstraps??{}),workflows,
|
|
321
|
+
executionFor:async(definition,{parallelMember=false,soloMember=false}={})=>{
|
|
307
322
|
await freezeBatchExecutionPolicy(batch,executionPolicy);
|
|
308
323
|
freezeBatchExternalModels(batch,externalModels);
|
|
309
324
|
const key=`${definition.feature}/${definition.identity.taskId}`;
|
|
310
|
-
|
|
325
|
+
// A parallel member's review loopback runs on the reviewer the factory will bind: the
|
|
326
|
+
// declared one for a provider-developed member (the host runtime may be the coder
|
|
327
|
+
// there), else the one this member always had (host runtime, or the external route).
|
|
328
|
+
const memberReviewer=developments.has(key)?resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),runtime??'codex').reviewerRuntime
|
|
329
|
+
:externalModels?routes.reviewerRuntime:runtime??'codex';
|
|
330
|
+
const memberReview=parallelMember?await memberReviewConfiguration(batch,definition,review,memberReviewer,externalModels?.providers[routes.reviewerRuntime]??null,!reconciling,Boolean(executionPolicy)):review;
|
|
311
331
|
const execution=createConversationExecution(definition,hostContextId,parallelMember?memberBridge:bridge,memberReview,null,workflows[key],allowQa,runtime??'codex',
|
|
312
|
-
{parallelMember,...(controlPolicy?{controlPolicy}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels,...(providerConfig?{reviewerRuntime:routes.reviewerRuntime}:{})}:{}),...(verificationPrecheck?{verificationPrecheck:true}:{}),
|
|
332
|
+
{parallelMember,...(soloMember?{soloMember}:{}),...(controlPolicy?{controlPolicy}:{}),...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels,...(providerConfig?{reviewerRuntime:routes.reviewerRuntime}:{})}:{}),...(verificationPrecheck?{verificationPrecheck:true}:{}),
|
|
333
|
+
// A batch without an execution table keeps its exact projection.
|
|
334
|
+
batchWorkflowsDigest:digest(executionPolicy?{workflows,bootstraps,externalModels,executionPolicy}:externalModels?{workflows,bootstraps,externalModels}
|
|
335
|
+
:Object.hasOwn(batch,'memberDevelopment')?{workflows,bootstraps,memberDevelopment:batch.memberDevelopment}:bootstraps?{workflows,bootstraps}:workflows),qaLogHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
|
|
336
|
+
...(sessionMembers.has(key)?{memberDevelopment:'session',...(sessionReviewRuntime!==null?{reviewRuntime:sessionReviewRuntime}:{})}:{}),
|
|
313
337
|
// A protected CLI config also protects unauthorized tasks: they stay on the
|
|
314
338
|
// current-session transport but with the same sandbox checks (protected-text edits).
|
|
315
339
|
...(protection?{protection}:providerConfig?{protection:{checkCommands:providerConfig.checkCommands,timeoutMs:providerConfig.timeoutMs}}:{}),
|
|
@@ -324,8 +348,13 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
324
348
|
const host={async handle(request){
|
|
325
349
|
try{
|
|
326
350
|
reconciling=request.operation==='reconcile_review';const result=await driver.handle(request);
|
|
327
|
-
if(controlPolicy&&request.operation==='status'&&result.state!=='running')
|
|
328
|
-
|
|
351
|
+
if(controlPolicy&&request.operation==='status'&&result.state!=='running'){
|
|
352
|
+
// A merge conflict stays reported when its member cannot be targeted (e.g.
|
|
353
|
+
// its worktree is gone); the target is marked unavailable, not invented.
|
|
354
|
+
if(result.code!=='merge_conflict')return {...result,controlTarget:await driver.controlTarget()};
|
|
355
|
+
try{return {...result,controlTarget:await driver.controlTarget()};}
|
|
356
|
+
catch(cause){return {...result,controlTargetUnavailable:{code:safeCode(cause)}};}
|
|
357
|
+
}
|
|
329
358
|
return result;
|
|
330
359
|
}
|
|
331
360
|
catch(cause){const reason=boundedReason(cause);return {outcome:'blocked',code:safeCode(cause),...(reason?{reason}:{})};}
|
|
@@ -334,7 +363,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
334
363
|
try{await serveHostTransport({host,input,output,toolBridge:bridge},inputLimitRaw);}
|
|
335
364
|
finally{if(rawMode)input.setRawMode(false);}
|
|
336
365
|
return 0;
|
|
337
|
-
}catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required','protected_scope',...Object.keys(UNSUPPORTED_REASON)].includes(code)
|
|
366
|
+
}catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required','protected_scope','session_coder_runtime_mismatch',...Object.keys(UNSUPPORTED_REASON)].includes(code)
|
|
338
367
|
&&typeof cause.reason==='string'?{reason:cause.reason}:{}),...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:{})}})+'\n');return 1;}
|
|
339
368
|
finally{bridge?.close();}
|
|
340
369
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {hostDiagnostic} from './fixtures/host-diagnostic.mjs';
|
|
2
2
|
import test from 'node:test';
|
|
3
|
+
import {batchSegment} from '../runtime/js/cm-ai/batch-location.mjs';
|
|
3
4
|
import assert from 'node:assert/strict';
|
|
4
5
|
import fs from 'node:fs';
|
|
5
6
|
import os from 'node:os';
|
|
@@ -108,7 +109,7 @@ function execute(f,{cancel=false,args=[],operations=[{operation:'advance',reques
|
|
|
108
109
|
if(row.type==='host_request'){
|
|
109
110
|
const payload=row.payload,identity=payload.identity??payload.request.identity;
|
|
110
111
|
const cwd=f.parallel&&identity.taskId!=='T-003'
|
|
111
|
-
?path.join(f.root,'.cm-worktrees',f.batch.batchId
|
|
112
|
+
?path.join(f.root,'.cm-worktrees',batchSegment(f.batch.batchId),identity.taskId):f.codeProject;
|
|
112
113
|
calls.push(`${identity.taskId}:${row.kind}`);
|
|
113
114
|
if(cancel){pendingControls.add('status');pendingControls.add('cancel');send({operation:'status',requestId:'status'});send({operation:'cancel',requestId:'cancel'});continue;}
|
|
114
115
|
if(row.kind==='develop'){
|
|
@@ -239,7 +240,7 @@ test('parallel member loopback preflights bind worktree cwd, stop before start a
|
|
|
239
240
|
try{
|
|
240
241
|
f.batch.tasks=[1,2,3].map(n=>({feature:'1.work',taskId:`T-00${n}`,scope:[`task${n}.mjs`],requirements:['requirements.md']}));
|
|
241
242
|
f.batch.parallel=[['1.work/T-001','1.work/T-002']];
|
|
242
|
-
fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: first\n- [ ] T-002: second\n- [ ] T-003: final\n\n- T-003 依赖 T-001, T-002\n');
|
|
243
|
+
fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: first\n - 范围: `task1.mjs`\n- [ ] T-002: second\n - 范围: `task2.mjs`\n- [ ] T-003: final\n - 范围: `task3.mjs`\n\n- T-003 依赖 T-001, T-002\n');
|
|
243
244
|
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(f.specsDir)}));
|
|
244
245
|
const original=JSON.parse(fs.readFileSync(f.config,'utf8')).workflows['1.work/T-001'];
|
|
245
246
|
fs.writeFileSync(f.config,JSON.stringify({batch:f.batch,workflows:Object.fromEntries(f.batch.tasks.map(task=>[`1.work/${task.taskId}`,original]))}));
|
|
@@ -272,7 +273,7 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
272
273
|
const directory=path.join(f.specsDir,'.reviews','.execution',f.batch.batchId);
|
|
273
274
|
const receipts=[1,2].map(n=>fs.readFileSync(path.join(directory,`preflight-T-00${n}.json`),'utf8'));
|
|
274
275
|
for(const [index,bytes] of receipts.entries()){
|
|
275
|
-
const config=JSON.parse(bytes),cwd=path.join(f.root,'.cm-worktrees',f.batch.batchId
|
|
276
|
+
const config=JSON.parse(bytes),cwd=path.join(f.root,'.cm-worktrees',batchSegment(f.batch.batchId),`T-00${index+1}`);
|
|
276
277
|
assert(preflightMatches(config.preflight,{cwd,model:'fixture',disabledSkills:[],promptTransport:'stdin'}));
|
|
277
278
|
assert(!preflightMatches(config.preflight,{cwd:f.codeProject,model:'fixture',disabledSkills:[],promptTransport:'stdin'}));
|
|
278
279
|
assert.equal(config.preflight.real_model_requests,0);assert.equal(config.preflight.listener_closed,true);
|
|
@@ -298,13 +299,13 @@ function legacyParallelFixture(){
|
|
|
298
299
|
const f=fixture();f.parallel=true;
|
|
299
300
|
f.batch.tasks=[1,2,3].map(n=>({feature:'1.work',taskId:`T-00${n}`,scope:[`task${n}.mjs`],requirements:['requirements.md']}));
|
|
300
301
|
f.batch.parallel=[['1.work/T-001','1.work/T-002']];
|
|
301
|
-
fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: first\n- [ ] T-002: second\n- [ ] T-003: final\n\n- T-003 依赖 T-001, T-002\n');
|
|
302
|
+
fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: first\n - 范围: `task1.mjs`\n- [ ] T-002: second\n - 范围: `task2.mjs`\n- [ ] T-003: final\n - 范围: `task3.mjs`\n\n- T-003 依赖 T-001, T-002\n');
|
|
302
303
|
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(f.specsDir)}));
|
|
303
304
|
const original=JSON.parse(fs.readFileSync(f.config,'utf8')).workflows['1.work/T-001'];
|
|
304
305
|
fs.writeFileSync(f.config,JSON.stringify({batch:f.batch,workflows:Object.fromEntries(f.batch.tasks.map(task=>[`1.work/${task.taskId}`,original]))}));
|
|
305
306
|
f.legacy=path.join(f.specsDir,'.reviews','.execution',f.batch.batchId);
|
|
306
307
|
f.current=path.join(f.specsDir,'.reviews','external-preflight',f.batch.batchId);
|
|
307
|
-
f.worktree=taskId=>path.join(f.root,'.cm-worktrees',f.batch.batchId
|
|
308
|
+
f.worktree=taskId=>path.join(f.root,'.cm-worktrees',batchSegment(f.batch.batchId),taskId);
|
|
308
309
|
return f;
|
|
309
310
|
}
|
|
310
311
|
const legacyReceipt=(f,taskId,extra={})=>JSON.stringify({model:'fixture',disabledSkills:[],preflight:{passed:true,cli_model:'fixture',
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {mergeLessons} from '../runtime/js/cm-ai/cm-ai-learning-writer.mjs';
|
|
8
|
+
|
|
9
|
+
// Two parallel members each write their lesson into AGENTS.md in their own
|
|
10
|
+
// worktree; the batch merges with AGENTS.md merge=union (cm-ai-batch-run.mjs
|
|
11
|
+
// unionAttributes). When the base has no "## 项目教训" section, both members
|
|
12
|
+
// create it. Git refines the identical added lines as common, so the merged
|
|
13
|
+
// file has one heading and both lessons, not a conflict or a doubled heading.
|
|
14
|
+
const git=(cwd,args)=>{const run=spawnSync('git',['-C',cwd,'-c','user.email=t@example.invalid','-c','user.name=t',...args],{encoding:'utf8'});
|
|
15
|
+
assert.equal(run.status,0,run.stderr);return run.stdout.trim();};
|
|
16
|
+
const lesson=(taskId,trigger)=>({feature:'1.work',identity:{repositoryId:'r',runId:'u',taskId,attempt:1},
|
|
17
|
+
candidates:[{classification:'memory_only',trigger,action:`${trigger} 的做法`,evidence:['src/a.js']}]});
|
|
18
|
+
|
|
19
|
+
for(const base of ['# 项目\n\n规则\n','# 项目\n\n## 项目教训\n\n- 旧教训\n\n## 其他\n\n内容\n'])
|
|
20
|
+
test(`two members' lessons merge into one section (${base.includes('项目教训')?'section exists':'no section yet'})`,t=>{
|
|
21
|
+
const repo=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-learning-union-')));
|
|
22
|
+
t.after(()=>fs.rmSync(repo,{recursive:true,force:true}));
|
|
23
|
+
git(repo,['init','-q','-b','base']);fs.writeFileSync(path.join(repo,'AGENTS.md'),base);git(repo,['add','.']);git(repo,['commit','-qm','base']);
|
|
24
|
+
for(const [branch,taskId,trigger] of [['a','T-002','左边的教训'],['b','T-003','右边的教训']]){
|
|
25
|
+
git(repo,['checkout','-q','-b',branch,'base']);
|
|
26
|
+
fs.writeFileSync(path.join(repo,'AGENTS.md'),mergeLessons(fs.readFileSync(path.join(repo,'AGENTS.md'),'utf8'),lesson(taskId,trigger)));
|
|
27
|
+
git(repo,['commit','-qam',branch]);
|
|
28
|
+
}
|
|
29
|
+
git(repo,['checkout','-q','a']);
|
|
30
|
+
fs.writeFileSync(path.join(repo,'.git','info','attributes'),'AGENTS.md merge=union\n');
|
|
31
|
+
git(repo,['merge','-q','--no-ff','--no-edit','b']);
|
|
32
|
+
const merged=fs.readFileSync(path.join(repo,'AGENTS.md'),'utf8');
|
|
33
|
+
assert.equal(merged.match(/^## 项目教训$/gm).length,1,merged);
|
|
34
|
+
assert.match(merged,/左边的教训/);assert.match(merged,/右边的教训/);
|
|
35
|
+
if(base.includes('## 其他'))assert.ok(merged.indexOf('右边的教训')<merged.indexOf('## 其他'),'lessons stay inside their section');
|
|
36
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// A batch's member worktrees and branches. New batches derive their segment from
|
|
2
|
+
// the full batchId and record it in batch_start; a batch that started without it
|
|
3
|
+
// keeps the old 8-character prefix so a resume finds what it created.
|
|
4
|
+
import test from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import {BATCH_SEGMENT_FIELD,batchSegment,batchSegments,batchMemberWorktree,batchMemberBranch} from '../runtime/js/cm-ai/batch-location.mjs';
|
|
10
|
+
|
|
11
|
+
function specs(t,rows=[]){
|
|
12
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-location-')));
|
|
13
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
14
|
+
const specsDir=path.join(root,'specs');fs.mkdirSync(specsDir);
|
|
15
|
+
if(rows.length)fs.writeFileSync(path.join(specsDir,'运行日志.jsonl'),rows.map(row=>JSON.stringify(row)).join('\n')+'\n');
|
|
16
|
+
return {root,specsDir,codeProject:path.join(root,'app')};
|
|
17
|
+
}
|
|
18
|
+
const start=(batchId,extra={})=>({schema_version:1,workflow:'cm-ai',event:'decision',phase:'batch_start',run_id:batchId,...extra});
|
|
19
|
+
|
|
20
|
+
test('two batches sharing an 8-character prefix get different worktrees and branches',t=>{
|
|
21
|
+
const f=specs(t);
|
|
22
|
+
const a=batchSegments({specsDir:f.specsDir,batchId:'batch-20261022-A'}),b=batchSegments({specsDir:f.specsDir,batchId:'batch-20261022-B'});
|
|
23
|
+
assert.notEqual(a.dir,b.dir);assert.notEqual(a.ref,b.ref);
|
|
24
|
+
const where=segments=>[batchMemberWorktree({codeProject:f.codeProject,segments,taskId:'T-001'}),
|
|
25
|
+
batchMemberBranch({segments,feature:'1.work',taskId:'T-001'})];
|
|
26
|
+
assert.notDeepEqual(where(a),where(b));
|
|
27
|
+
assert.equal(where(a)[0],path.join(f.root,'.cm-worktrees',batchSegment('batch-20261022-A'),'T-001'));
|
|
28
|
+
assert.equal(where(a)[1],`cm/${batchSegment('batch-20261022-A')}/work/T-001`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('a batch that already started without a recorded segment keeps the old prefix',t=>{
|
|
32
|
+
const f=specs(t,[start('v1.2.3-batch')]);
|
|
33
|
+
const segments=batchSegments({specsDir:f.specsDir,batchId:'v1.2.3-batch'});
|
|
34
|
+
assert.equal(segments.legacy,true);
|
|
35
|
+
assert.equal(batchMemberWorktree({codeProject:f.codeProject,segments,taskId:'T-002'}),path.join(f.root,'.cm-worktrees','v1.2.3-b','T-002'));
|
|
36
|
+
assert.equal(batchMemberBranch({segments,feature:'2.search',taskId:'T-002'}),'cm/v1-2-3-b/search/T-002');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('a recorded segment is used only when it is the one the full id derives',t=>{
|
|
40
|
+
const good=specs(t,[start('batch-ok',{[BATCH_SEGMENT_FIELD]:batchSegment('batch-ok')})]);
|
|
41
|
+
assert.deepEqual(batchSegments({specsDir:good.specsDir,batchId:'batch-ok'}),{dir:batchSegment('batch-ok'),ref:batchSegment('batch-ok'),legacy:false});
|
|
42
|
+
for(const forged of ['../../etc','batch-ok',batchSegment('other-batch'),null]){
|
|
43
|
+
const f=specs(t,[start('batch-ok',{[BATCH_SEGMENT_FIELD]:forged})]);
|
|
44
|
+
assert.throws(()=>batchSegments({specsDir:f.specsDir,batchId:'batch-ok'}),{code:'batch_history_invalid'},String(forged));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('rows of other batches and other workflows do not decide the segment',t=>{
|
|
49
|
+
const f=specs(t,[start('another-batch'),{schema_version:1,workflow:'cm-prd',event:'run_done',run_id:'mine-1234'},
|
|
50
|
+
{schema_version:1,workflow:'cm-ai',event:'progress',run_id:'mine-1234'}]);
|
|
51
|
+
assert.equal(batchSegments({specsDir:f.specsDir,batchId:'mine-1234'}).dir,batchSegment('mine-1234'));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('the segment is a safe single path component and ref component',()=>{
|
|
55
|
+
for(const id of ['a','a.b.c.d.e.f.g.h','....----','batch_2026.10.23-x'])
|
|
56
|
+
assert.match(batchSegment(id),/^[A-Za-z0-9_-]{1,8}-[a-f0-9]{12}$/,id);
|
|
57
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Prints the batch configuration /cm-ai runs for the feature admission selects,
|
|
3
|
+
// grouped from the approved tasks.md (runtime/js/cm-ai/batch-plan.mjs). The
|
|
4
|
+
// session no longer writes groups by hand; the batch host validates them again.
|
|
5
|
+
//
|
|
6
|
+
// stdout: {mode:"batch",feature,groups,config} — pass config to cm-ai-batch-host
|
|
7
|
+
// as the batch configuration file;
|
|
8
|
+
// {mode:"serial",feature,reason} — run the feature's tasks one at a time
|
|
9
|
+
// with cm-ai-admission --print-run-definition, as before;
|
|
10
|
+
// {mode:"complete"} — no task is left.
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import {fileURLToPath} from 'node:url';
|
|
14
|
+
import {loadConfig} from './cm-workflow-config.mjs';
|
|
15
|
+
import {planCmAiBatch,parallelSettings} from '../runtime/js/cm-ai/batch-plan.mjs';
|
|
16
|
+
import {validateHostWorkflowConfiguration} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
|
|
17
|
+
|
|
18
|
+
const usage='usage: cm-ai-batch-plan.mjs --specs-dir PATH --code-project PATH --repository-id ID --batch-id ID [--workflow-config PATH]';
|
|
19
|
+
function parse(argv){
|
|
20
|
+
const flags=new Map([['--specs-dir','specsDir'],['--code-project','codeProject'],['--repository-id','repositoryId'],
|
|
21
|
+
['--batch-id','batchId'],['--workflow-config','workflowConfig']]);
|
|
22
|
+
const input={};
|
|
23
|
+
for(let index=0;index<argv.length;index+=2){
|
|
24
|
+
const key=flags.get(argv[index]);
|
|
25
|
+
if(!key||index+1>=argv.length||Object.hasOwn(input,key))return null;
|
|
26
|
+
input[key]=argv[index+1];
|
|
27
|
+
}
|
|
28
|
+
return ['specsDir','codeProject','repositoryId','batchId'].every(key=>typeof input[key]==='string')?input:null;
|
|
29
|
+
}
|
|
30
|
+
export function main(argv=process.argv.slice(2)){
|
|
31
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0])){process.stdout.write(usage+'\n');return 0;}
|
|
32
|
+
const input=parse(argv);
|
|
33
|
+
if(!input){process.stderr.write(usage+'\n');return 2;}
|
|
34
|
+
try{
|
|
35
|
+
const specsDir=fs.realpathSync(path.resolve(input.specsDir)),codeProject=fs.realpathSync(path.resolve(input.codeProject));
|
|
36
|
+
const settings=parallelSettings(loadConfig({projectRoot:codeProject}));
|
|
37
|
+
// The single-task workflow configuration the batch host gets for these tasks: its
|
|
38
|
+
// QA critical paths keep tasks that would hit them out of one-member groups.
|
|
39
|
+
const workflow=input.workflowConfig===undefined?null
|
|
40
|
+
:validateHostWorkflowConfiguration(JSON.parse(fs.readFileSync(path.resolve(input.workflowConfig),'utf8')));
|
|
41
|
+
const plan=planCmAiBatch({specsDir,codeProject,repositoryId:input.repositoryId,batchId:input.batchId,settings,workflow});
|
|
42
|
+
process.stdout.write(JSON.stringify(plan)+'\n');return 0;
|
|
43
|
+
}catch(error){
|
|
44
|
+
process.stderr.write(JSON.stringify({error:{code:error.code??'batch_plan_failed',
|
|
45
|
+
...(typeof error.reason==='string'?{reason:error.reason}:{})}})+'\n');return 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function isMain(entry){
|
|
49
|
+
if(!entry)return false;
|
|
50
|
+
try{return fs.realpathSync(entry)===fileURLToPath(import.meta.url);}catch{return path.resolve(entry)===fileURLToPath(import.meta.url);}
|
|
51
|
+
}
|
|
52
|
+
if(isMain(process.argv[1]))process.exitCode=main();
|