@aibyzero/cm-workflow 0.16.4 → 0.16.6
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 +22 -0
- package/CHANGELOG.md +57 -0
- package/README.md +22 -4
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/VERSION +1 -1
- package/docs/architecture.md +43 -0
- package/docs/execution-optimizations.md +33 -0
- package/docs/external-models.md +114 -0
- package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
- package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
- package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
- package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
- package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
- package/docs/human-correction.md +31 -0
- package/docs/installation.md +48 -7
- package/docs/js-workflow-control.md +293 -33
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- package/docs/runtime-failover.md +1 -1
- package/docs/untested-branches.md +27 -4
- package/docs/user-guide.md +23 -8
- package/install-codex.sh +28 -11
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- package/runtime/js/cm-ai/cm-ai-admission.mjs +115 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +208 -34
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +181 -57
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +15 -58
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +56 -17
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +315 -0
- package/runtime/js/cm-ai/drive-core.mjs +47 -9
- package/runtime/js/cm-ai/durable-runner-state.mjs +413 -56
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-policy.mjs +58 -0
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/external-group-models.mjs +53 -0
- package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
- package/runtime/js/cm-ai/external-models.mjs +52 -0
- package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +126 -29
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +66 -20
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-progress.mjs +80 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
- package/runtime/js/cm-ai/host-qa-executor.mjs +23 -9
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +23 -6
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +12 -4
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +16 -5
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
- package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
- package/runtime/js/cm-ai/live-evidence.mjs +96 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
- package/runtime/js/cm-ai/model_configuration_write.py +214 -0
- package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +86 -0
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +68 -9
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +438 -31
- package/runtime/js/cm-ai/review-presentation.mjs +45 -0
- package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +658 -75
- package/runtime/js/cm-ai/tool-preview.mjs +8 -4
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-ai/worker-claude.mjs +63 -19
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
- package/runtime/js/cm-ai/worker-codex.mjs +45 -19
- package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
- package/runtime/js/cm-fix/cause-package.mjs +10 -1
- package/runtime/js/cm-fix/execution.mjs +279 -52
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/host-review.mjs +32 -9
- package/runtime/js/cm-fix/host.mjs +6 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/progress.mjs +5 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +27 -15
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-prd/summary.mjs +3 -1
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +10 -3
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +18 -11
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +135 -34
- package/scripts/cm-ai-batch-drive.test.mjs +209 -3
- package/scripts/cm-ai-batch-host.mjs +63 -24
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- package/scripts/cm-ai-batch-run.mjs +101 -34
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +159 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +162 -0
- package/scripts/cm-ai-bootstrap.test.mjs +174 -89
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +97 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +924 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +526 -60
- package/scripts/cm-ai-drive.test.mjs +336 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +142 -43
- package/scripts/cm-ai-host.test.mjs +232 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +187 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +977 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +206 -62
- package/scripts/cm-ai-run.test.mjs +6 -4
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.test.mjs +2 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +12 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +10 -2
- package/scripts/cm-claude-review-stream.test.mjs +25 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-codex-plugin-metadata.py +83 -0
- package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
- package/scripts/cm-efficiency-checks.test.mjs +37 -0
- package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
- package/scripts/cm-efficiency-offline.mjs +35 -0
- package/scripts/cm-efficiency-policy.test.mjs +48 -0
- package/scripts/cm-efficiency-presentation.test.mjs +35 -0
- package/scripts/cm-efficiency-response.test.mjs +117 -0
- package/scripts/cm-efficiency-usage.test.mjs +148 -0
- package/scripts/cm-external-batch-host.test.mjs +157 -0
- package/scripts/cm-external-fix-host.test.mjs +281 -0
- package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
- package/scripts/cm-external-group-models.test.mjs +60 -0
- package/scripts/cm-external-model-host.test.mjs +180 -0
- package/scripts/cm-external-model-recovery.test.mjs +108 -0
- package/scripts/cm-external-models.test.mjs +89 -0
- package/scripts/cm-external-process-cleanup.test.mjs +71 -0
- package/scripts/cm-external-qa-fix.test.mjs +170 -0
- package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +70 -23
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +24 -14
- package/scripts/cm-fix-protected-edits.test.mjs +12 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
- package/scripts/cm-fix-review-budget.test.mjs +147 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +213 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +25 -2
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-completion.test.mjs +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-host.mjs +13 -4
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +5 -1
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-runtime-i18n.mjs +15 -4
- package/scripts/cm-runtime-install.mjs +8 -4
- package/scripts/cm-runtime.mjs +116 -23
- package/scripts/cm-runtime.test.mjs +121 -12
- package/scripts/cm-security.test.mjs +32 -0
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +12 -1
- package/scripts/cm-task-gate-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +164 -20
- package/scripts/cm-task-gate.py +2 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/cm-test-drive.mjs +10 -4
- package/scripts/cm-test-drive.test.mjs +14 -1
- package/scripts/cm-tool-preview-context.test.mjs +12 -0
- package/scripts/cm-usage-report.py +22 -3
- package/scripts/cm-workflow-config.mjs +10 -1
- package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +101 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +11 -2
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/SKILL.md +2 -2
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +270 -43
- package/skills/cm-ai/references/knowledge-closeout.md +90 -0
- package/skills/cm-fix/SKILL.md +1 -1
- package/skills/cm-fix/references/js-host.md +52 -3
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
- package/skills/cm-runtime/SKILL.md +29 -6
- package/skills/cm-security/SKILL.md +4 -2
- package/skills/cm-security/references/scan-contract.md +1 -0
- package/templates/cm-workflow.yml +1 -1
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {readBatchExecutionPolicy,freezeBatchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
3
|
+
import {readBatchExternalModels,freezeBatchExternalModels,batchModelsFile} from '../runtime/js/cm-ai/external-group-models.mjs';
|
|
2
4
|
// Current-conversation transport for the existing batch driver, not a new loop.
|
|
3
5
|
import fs from 'node:fs';
|
|
4
6
|
import path from 'node:path';
|
|
5
7
|
import {fileURLToPath} from 'node:url';
|
|
6
|
-
import {createCmAiBatch} from './cm-ai-batch-run.mjs';
|
|
8
|
+
import {createCmAiBatch,batchTaskRunId} from './cm-ai-batch-run.mjs';
|
|
7
9
|
import {createConversationExecution,readConversationReviewConfiguration,readConversationProtection,runReviewPreflight} from './cm-ai-host.mjs';
|
|
8
10
|
import {loadConfig,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
|
|
9
11
|
import {preflightMatches} from '../runtime/js/cm-ai/worker-codex.mjs';
|
|
10
12
|
import {claudePreflightMatches} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
11
13
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
12
|
-
import {serveCmAiHost,parseHostInputLimit} from '../runtime/js/cm-ai/host-session.mjs';
|
|
14
|
+
import {serveCmAiHost,parseHostInputLimit,inputLimitReason} from '../runtime/js/cm-ai/host-session.mjs';
|
|
13
15
|
import {validateHostWorkflowConfiguration,featureHasBrowserCases,readBrowserCapability} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
|
|
14
16
|
import {digest,json,need,shape} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
17
|
+
import {identifyApprovedBootstrapFeature} from '../runtime/js/cm-ai/bootstrap-feature.mjs';
|
|
15
18
|
|
|
16
|
-
const usage='cm-ai-batch-host.mjs serve --config PATH --host-context ID --allow-development [--runtime codex|claude] [--input-limit BYTES] [--
|
|
19
|
+
const usage='cm-ai-batch-host.mjs serve --config PATH --host-context ID --allow-development --review-config PATH (required for a new batch; later launches pass the same file) [--execution-optimizations] [--external-models [--external-models-config PATH]] [--runtime codex|claude] [--input-limit BYTES] [--allow-review FEATURE/TASK:1|2]... [--allow-qa] [--rerun-unknown-qa | --rerun-blocked-qa] [--verification-precheck] [--browser-qa available|unavailable] [--protected-conversation-config PATH | --protected-config PATH] [--allow-provider-development FEATURE/TASK:1|2]... [--hold-revision FEATURE/TASK]...';
|
|
17
20
|
const safeCode=error=>typeof error?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(error.code)?error.code:'batch_host_failed';
|
|
18
21
|
|
|
19
22
|
export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHost){
|
|
20
23
|
return serve({...options,inputLimit:parseHostInputLimit(rawInputLimit)});
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
async function memberReviewConfiguration(batch,definition,review,runtime){
|
|
26
|
+
async function memberReviewConfiguration(batch,definition,review,runtime,pair=null,allowPreflight=true){
|
|
24
27
|
try{
|
|
25
28
|
need(review!==null,'review_configuration_required');
|
|
26
|
-
const options={cwd:definition.codeProject,model:review.model,disabledSkills:review.disabledSkills,promptTransport:'stdin'};
|
|
29
|
+
const options={cwd:definition.codeProject,model:review.model,...(pair?{effort:pair.effort}:{}),disabledSkills:review.disabledSkills,promptTransport:'stdin'};
|
|
27
30
|
const matches=config=>config.model===review.model&&digest(config.disabledSkills)===digest(review.disabledSkills)
|
|
28
31
|
&&(runtime==='claude'?claudePreflightMatches:preflightMatches)(config.preflight,options);
|
|
29
|
-
const directory=path.join(batch.specsDir,'.reviews'
|
|
32
|
+
const directory=path.join(batch.specsDir,'.reviews',...(pair?['external-preflight']:['.execution']),batch.batchId);
|
|
30
33
|
fs.mkdirSync(directory,{recursive:true,mode:0o700});
|
|
31
34
|
need(fs.realpathSync(directory)===directory,'invalid_preflight_cache');
|
|
32
35
|
const file=path.join(directory,`preflight-${definition.identity.taskId}.json`);
|
|
@@ -35,10 +38,11 @@ async function memberReviewConfiguration(batch,definition,review,runtime){
|
|
|
35
38
|
const withTimeout=config=>review.timeoutMs==null?config:{...config,timeoutMs:review.timeoutMs};
|
|
36
39
|
if(fs.existsSync(file)){
|
|
37
40
|
const info=fs.lstatSync(file);need(info.isFile()&&!info.isSymbolicLink(),'invalid_preflight_cache');
|
|
38
|
-
try{const cached=readConversationReviewConfiguration(file);if(matches(cached))return withTimeout(cached);}
|
|
41
|
+
try{const cached=readConversationReviewConfiguration(file,pair);if(matches(cached))return withTimeout(cached);}
|
|
39
42
|
catch{/* Invalid or obsolete diagnostics require a fresh loopback, never a rewritten fingerprint. */}
|
|
40
43
|
}
|
|
41
|
-
|
|
44
|
+
need(allowPreflight,'review_preflight_missing');
|
|
45
|
+
const config=await runReviewPreflight(definition,{model:review.model,...(pair?{effort:pair.effort}:{}),runtime,disabledSkills:review.disabledSkills});
|
|
42
46
|
need(matches(config),'review_preflight_failed');
|
|
43
47
|
const temporary=`${file}.${process.pid}.tmp`;
|
|
44
48
|
fs.writeFileSync(temporary,JSON.stringify(config)+'\n',{flag:'wx',mode:0o600});
|
|
@@ -48,7 +52,8 @@ async function memberReviewConfiguration(batch,definition,review,runtime){
|
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
51
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0]))
|
|
55
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Optional --execution-optimizations freezes policy v1 for new runs only; recovery retains the original policy and legacy runs reject retrofit. See docs/execution-optimizations.md.\n');
|
|
56
|
+
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\nOptional --input-limit BYTES sets the host input transport limit to an integer from 65536 to 4194304 (default 65536); it may change on resume.\nOptional --protected-conversation-config PATH uses the shared current-host scoped text proposals and native sandbox checks; {checkCommands,timeoutMs}. No extra model call, same Codex/Claude runtime and per-task Review permissions. Optional --protected-config PATH {model,checkCommands,timeoutMs} enables CLI development only for per-task --allow-provider-development FEATURE/TASK:1|2 grants; mutually exclusive with --protected-conversation-config. Optional bundle.bootstraps maps approved bootstrap task keys to {selection}; --allow-bootstrap-write grants only those fixed instruction/scaffold steps. Optional batch.codeProjects uses prefixed paths and checks with codeProject per command; one task remains one completion gate.\n--review-config PATH is required when no member run of the batch exists yet (like single-task create): it is bound into every member fingerprint and cannot be added on resume. It is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 900000). It is independent of --protected-conversation-config/--protected-config and wins over their timeoutMs for the reviewer. It is not part of the authorized configuration digest, so a resumed run may raise it after review_transport_timeout.\n--browser-qa available|unavailable declares interactive QA capability for applicable feature carriers including browser and ios-simulator; the flag name is retained for compatibility.\nOptional --rerun-unknown-qa / --rerun-blocked-qa carry the same single-task QA recovery into a batch and require --allow-qa; they are mutually exclusive. A batch has no --mode, so each task applies the flag only when it resumes an existing run and has a QA executor; a created run or a task without QA ignores it rather than failing the whole batch. Semantics, limits and the qaRound cap are the single-task ones, unchanged.\nOptional --verification-precheck sends the written verification of the task and the collected checks back as a verification_precheck request before any handoff or review package is built. It may only block: a requirement reported unsatisfied stops the task at blocked / verification_precheck_failed with pendingAction resume and spends no review round. Passing it is not an approval, writes no receipt and does not replace the independent review. A task with no written verification is unaffected.\nOptional --hold-revision FEATURE/TASK (repeatable, launch-only, never persisted) stops that task after a changes_requested review with code revision_answer_required, before any second-round develop intent; the next launch without it resumes the revision. It only narrows what this launch does.\nBatch entry requires a clean Git main checkout (including untracked files); batch_main_dirty lists dirty files before any task or worktree starts. Serial tasks are committed automatically before batch_handoff, with task_commit recording the SHA (null if unchanged). Terminal parallel members preserve WIP on their retained branches and fall back once to serial generation 2 after ready members merge.\n');return 0;}
|
|
52
57
|
let bridge;
|
|
53
58
|
try{
|
|
54
59
|
need(argv.length>=6&&argv[0]==='serve'&&argv[1]==='--config'&&argv[3]==='--host-context'
|
|
@@ -61,16 +66,18 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
61
66
|
if(bootstraps!==null){
|
|
62
67
|
need(typeof bootstraps==='object'&&!Array.isArray(bootstraps),'invalid_bootstrap_config');
|
|
63
68
|
for(const [key,config] of Object.entries(bootstraps)){
|
|
64
|
-
need(keys.includes(key)&&key.startsWith('
|
|
69
|
+
need(keys.includes(key)&&key.startsWith(identifyApprovedBootstrapFeature(batch.specsDir)+'/'),'bootstrap_task_required');shape(config,['selection']);
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
need(keys.length===Object.keys(workflows).length&&keys.every(key=>Object.hasOwn(workflows,key)),'workflow_task_mismatch');
|
|
68
73
|
for(const key of keys)if(workflows[key]!==null)validateHostWorkflowConfiguration(workflows[key]);
|
|
69
74
|
let review=null,allowQa=false,allowBootstrap=false,runtime=null,protection=null,providerConfig=null,browserQaFlag,inputLimitRaw;
|
|
70
|
-
let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false;const approvals=new Set(),developments=new Map();
|
|
75
|
+
let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false;const approvals=new Set(),developments=new Map(),holds=new Set();
|
|
76
|
+
let externalEnabled=false,externalFile,executionPolicyEnabled=false;
|
|
71
77
|
for(let index=6;index<argv.length;index++){
|
|
72
78
|
const name=argv[index];
|
|
73
|
-
if(name==='--
|
|
79
|
+
if(name==='--execution-optimizations'){need(!executionPolicyEnabled,'invalid_arguments');executionPolicyEnabled=true;}
|
|
80
|
+
else if(name==='--allow-qa'){need(!allowQa,'invalid_arguments');allowQa=true;}
|
|
74
81
|
else if(name==='--rerun-unknown-qa'){need(!rerunUnknownQa,'invalid_arguments');rerunUnknownQa=true;}
|
|
75
82
|
else if(name==='--rerun-blocked-qa'){need(!rerunBlockedQa,'invalid_arguments');rerunBlockedQa=true;}
|
|
76
83
|
else if(name==='--verification-precheck'){need(!verificationPrecheck,'invalid_arguments');verificationPrecheck=true;}
|
|
@@ -85,7 +92,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
85
92
|
need(protection===null&&providerConfig===null&&typeof argv[index+1]==='string','invalid_arguments');
|
|
86
93
|
const file=argv[++index],info=fs.lstatSync(file);
|
|
87
94
|
need(info.isFile()&&!info.isSymbolicLink()&&info.size<=64*1024,'invalid_protected_config');
|
|
88
|
-
providerConfig=json(JSON.parse(fs.readFileSync(file,'utf8')));shape(providerConfig,['
|
|
95
|
+
providerConfig=json(JSON.parse(fs.readFileSync(file,'utf8')));shape(providerConfig,['checkCommands','timeoutMs',...['model','effort'].filter(key=>Object.hasOwn(providerConfig,key))]);
|
|
89
96
|
}
|
|
90
97
|
else if(name==='--allow-provider-development'){
|
|
91
98
|
const approval=argv[++index];need(typeof approval==='string','invalid_arguments');
|
|
@@ -93,6 +100,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
93
100
|
need(keys.includes(key)&&['1','2'].includes(attempt),'invalid_arguments');
|
|
94
101
|
need(!developments.has(key),'invalid_arguments');developments.set(key,Number(attempt));
|
|
95
102
|
}
|
|
103
|
+
else if(name==='--external-models'){need(!externalEnabled,'invalid_arguments');externalEnabled=true;}
|
|
104
|
+
else if(name==='--external-models-config'){need(externalFile===undefined&&typeof argv[index+1]==='string','invalid_arguments');externalFile=argv[++index];}
|
|
96
105
|
else if(name==='--runtime'){
|
|
97
106
|
need(runtime===null&&['codex','claude'].includes(argv[index+1]),'invalid_runtime');runtime=argv[++index];
|
|
98
107
|
}
|
|
@@ -100,25 +109,51 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
100
109
|
need(inputLimitRaw===undefined&&typeof argv[index+1]==='string','invalid_arguments');
|
|
101
110
|
inputLimitRaw=argv[++index];parseHostInputLimit(inputLimitRaw);
|
|
102
111
|
}
|
|
103
|
-
else if(name==='--review-config'){need(review===null&&typeof argv[index+1]==='string','invalid_arguments');review=
|
|
112
|
+
else if(name==='--review-config'){need(review===null&&typeof argv[index+1]==='string','invalid_arguments');review=argv[++index];}
|
|
113
|
+
else if(name==='--hold-revision'){
|
|
114
|
+
const held=argv[++index];need(typeof held==='string'&&keys.includes(held)&&!holds.has(held),'invalid_arguments');holds.add(held);
|
|
115
|
+
}
|
|
104
116
|
else if(name==='--allow-review'){
|
|
105
117
|
const approval=argv[++index];need(typeof approval==='string'&&!approvals.has(approval),'invalid_arguments');
|
|
106
118
|
const split=approval.lastIndexOf(':'),key=approval.slice(0,split),attempt=approval.slice(split+1);
|
|
107
119
|
need(keys.includes(key)&&['1','2'].includes(attempt),'review_task_mismatch');approvals.add(approval);
|
|
108
120
|
}else need(false,'invalid_arguments');
|
|
109
121
|
}
|
|
122
|
+
const started=keys.some(key=>fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',batchTaskRunId(batch.batchId,key),'state.json')));
|
|
123
|
+
const executionPolicy=readBatchExecutionPolicy({batch,started,enabled:executionPolicyEnabled});
|
|
124
|
+
const routes=providerConfig?resolveProtectedRuntimes(loadConfig({projectRoot:batch.codeProject}),runtime??'codex'):{reviewerRuntime:runtime??'codex'};
|
|
125
|
+
const externalModels=readBatchExternalModels({batch,started,enabled:externalEnabled,inputFile:externalFile,providers:[routes.coderRuntime,routes.reviewerRuntime].filter(Boolean)});
|
|
126
|
+
if(providerConfig&&!externalModels)shape(providerConfig,['model','checkCommands','timeoutMs']);
|
|
127
|
+
if(providerConfig&&externalModels){
|
|
128
|
+
const pair=externalModels.providers[routes.coderRuntime];
|
|
129
|
+
need(!Object.hasOwn(providerConfig,'model')||providerConfig.model===pair.model,'external_model_configuration_conflict');
|
|
130
|
+
need(!Object.hasOwn(providerConfig,'effort')||providerConfig.effort===pair.effort,'external_model_configuration_conflict');
|
|
131
|
+
providerConfig={...providerConfig,...pair};
|
|
132
|
+
}
|
|
133
|
+
review=review===null?null:readConversationReviewConfiguration(review,externalModels?.providers[routes.reviewerRuntime]??null);
|
|
110
134
|
need(!developments.size||providerConfig!==null,'protected_configuration_required');
|
|
111
135
|
// Same launch-time assertion as the single-task host, evaluated across every
|
|
112
136
|
// task whose approved contract can select a browser case.
|
|
113
|
-
readBrowserCapability(browserQaFlag,keys.
|
|
114
|
-
&&featureHasBrowserCases(batch.specsDir,key.slice(0,key.lastIndexOf('/')),batch.codeProject)
|
|
137
|
+
readBrowserCapability(browserQaFlag,keys.flatMap(key=>workflows[key]?.qa!=null
|
|
138
|
+
&&featureHasBrowserCases(batch.specsDir,key.slice(0,key.lastIndexOf('/')),batch.codeProject)
|
|
139
|
+
?[workflows[key].qa.environment?.carrier??'browser']:[]));
|
|
115
140
|
need(!approvals.size||review!==null,'review_configuration_required');
|
|
116
141
|
// Same two guards as the single-task host. A batch has no --mode, so the
|
|
117
142
|
// per-task resume check lives in createCmAiBatch rather than here.
|
|
118
143
|
need(!(rerunUnknownQa&&rerunBlockedQa),'qa_recovery_authorization_required');
|
|
119
144
|
need(!(rerunUnknownQa||rerunBlockedQa)||allowQa,'qa_recovery_authorization_required');
|
|
120
145
|
need(allowQa||!Object.values(workflows).some(item=>item?.qa!=null),'qa_authorization_required');
|
|
121
|
-
|
|
146
|
+
// Same rule as single-task create: the reviewer binding is part of every
|
|
147
|
+
// member's durable fingerprint and cannot be added on resume. A batch none
|
|
148
|
+
// of whose member runs exist yet is being created. Batches that already
|
|
149
|
+
// started keep their original launch (older ones may have no review config).
|
|
150
|
+
const created=keys.some(key=>fs.existsSync(path.join(path.resolve(batch.specsDir),'.reviews','.execution',
|
|
151
|
+
batchTaskRunId(batch.batchId,key),'state.json')));
|
|
152
|
+
if(!created&&review===null)throw Object.assign(new Error('review_configuration_required'),{code:'review_configuration_required',
|
|
153
|
+
reason:'新批次必须带 --review-config:审查配置写进每个任务运行的指纹,恢复时不能再补。先用 cm-ai-host.mjs preflight 生成 review.json;'
|
|
154
|
+
+'是否真正派发审查仍由 --allow-review 单独授权'});
|
|
155
|
+
// Tool replies travel on the same input lines, so they share the one limit.
|
|
156
|
+
bridge=createHostToolBridge({responseLimit:parseHostInputLimit(inputLimitRaw)});
|
|
122
157
|
// The current conversation transport accepts one outstanding host call.
|
|
123
158
|
// Queue those calls only; member runners and independent Review stay concurrent.
|
|
124
159
|
let hostCallTail=Promise.resolve();
|
|
@@ -126,20 +161,23 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
126
161
|
const pending=hostCallTail.then(()=>bridge.call(...args));
|
|
127
162
|
hostCallTail=pending.then(()=>{},()=>{});return pending;
|
|
128
163
|
}};
|
|
129
|
-
|
|
164
|
+
let reconciling=false;
|
|
165
|
+
const driver=createCmAiBatch({configuration:{...batch,...(externalModels?{externalModels}:{}),...(executionPolicy?{executionPolicy}:{})},logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
|
|
130
166
|
runtime:runtime??'codex',checkCommands:(providerConfig??protection)?.checkCommands??null,checkTimeoutMs:(providerConfig??protection)?.timeoutMs??60000,
|
|
131
|
-
rerunUnknownQa,rerunBlockedQa,
|
|
167
|
+
rerunUnknownQa,rerunBlockedQa,holdRevisions:[...holds],
|
|
132
168
|
executionFor:async(definition,{parallelMember=false}={})=>{
|
|
169
|
+
await freezeBatchExecutionPolicy(batch,executionPolicy);
|
|
170
|
+
freezeBatchExternalModels(batch,externalModels);
|
|
133
171
|
const key=`${definition.feature}/${definition.identity.taskId}`;
|
|
134
172
|
const attempts=[1,2].filter(attempt=>approvals.has(`${key}:${attempt}`));
|
|
135
|
-
const memberReview=parallelMember?await memberReviewConfiguration(batch,definition,review,runtime??'codex'):review;
|
|
173
|
+
const memberReview=parallelMember?await memberReviewConfiguration(batch,definition,review,externalModels?routes.reviewerRuntime:runtime??'codex',externalModels?.providers[routes.reviewerRuntime]??null,!reconciling):review;
|
|
136
174
|
const execution=createConversationExecution(definition,argv[4],parallelMember?memberBridge:bridge,memberReview,attempts,workflows[key],allowQa,runtime??'codex',
|
|
137
|
-
{parallelMember,...(verificationPrecheck?{verificationPrecheck:true}:{}),batchWorkflowsDigest:digest(bootstraps?{workflows,bootstraps}:workflows),qaLogHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
|
|
175
|
+
{parallelMember,...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels,...(providerConfig?{reviewerRuntime:routes.reviewerRuntime}:{})}:{}),...(verificationPrecheck?{verificationPrecheck:true}:{}),batchWorkflowsDigest:digest(executionPolicy?{workflows,bootstraps,externalModels,executionPolicy}:externalModels?{workflows,bootstraps,externalModels}:bootstraps?{workflows,bootstraps}:workflows),qaLogHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
|
|
138
176
|
// A protected CLI config also protects unauthorized tasks: they stay on the
|
|
139
177
|
// current-session transport but with the same sandbox checks (protected-text edits).
|
|
140
178
|
...(protection?{protection}:providerConfig?{protection:{checkCommands:providerConfig.checkCommands,timeoutMs:providerConfig.timeoutMs}}:{}),
|
|
141
179
|
...(developments.has(key)?{
|
|
142
|
-
providerDevelopment:{model:providerConfig.model,attempt:developments.get(key),
|
|
180
|
+
providerDevelopment:{...(providerConfig.model?{model:providerConfig.model}:{}),...(Object.hasOwn(providerConfig,'effort')?{effort:providerConfig.effort}:{}),attempt:developments.get(key),
|
|
143
181
|
...resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),runtime??'codex')},
|
|
144
182
|
}:{}),...(bootstraps?.[key]?{bootstrap:{...bootstraps[key],allowWrite:allowBootstrap}}:{})});
|
|
145
183
|
// Bind the entire approved capability map before the first task starts,
|
|
@@ -147,13 +185,14 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
147
185
|
return execution;
|
|
148
186
|
}});
|
|
149
187
|
const host={async handle(request){
|
|
150
|
-
try{return await driver.handle(request);}catch(cause){return {outcome:'blocked',code:safeCode(cause)};}
|
|
188
|
+
try{reconciling=request.operation==='reconcile_review';return await driver.handle(request);}catch(cause){return {outcome:'blocked',code:safeCode(cause)};}
|
|
151
189
|
}};
|
|
152
190
|
const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
|
|
153
191
|
try{await serveHostTransport({host,input,output,toolBridge:bridge},inputLimitRaw);}
|
|
154
192
|
finally{if(rawMode)input.setRawMode(false);}
|
|
155
193
|
return 0;
|
|
156
|
-
}catch(cause){error.write(JSON.stringify({error:{code
|
|
194
|
+
}catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required'].includes(code)
|
|
195
|
+
&&typeof cause.reason==='string'?{reason:cause.reason}:{}),...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:{})}})+'\n');return 1;}
|
|
157
196
|
finally{bridge?.close();}
|
|
158
197
|
}
|
|
159
198
|
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
|
@@ -261,8 +261,9 @@ test('provider development grants select worktree runtimes and keep the serial t
|
|
|
261
261
|
fs.writeFileSync(stub,`
|
|
262
262
|
import {configFingerprint} from ${JSON.stringify(workerModule)};
|
|
263
263
|
export {readConversationReviewConfiguration,readConversationProtection} from ${JSON.stringify(hostModule)};
|
|
264
|
-
export {parseHostInputLimit} from ${JSON.stringify(sessionModule)};
|
|
264
|
+
export {parseHostInputLimit,inputLimitReason} from ${JSON.stringify(sessionModule)};
|
|
265
265
|
export const calls=[];export let scheduler;
|
|
266
|
+
export {batchTaskRunId} from ${JSON.stringify(new URL('./cm-ai-batch-run.mjs',import.meta.url).href)};
|
|
266
267
|
export function createConversationExecution(...args){calls.push(args);return {};}
|
|
267
268
|
export async function runReviewPreflight(definition,{model}){return {model,disabledSkills:[],preflight:{passed:true,
|
|
268
269
|
cli_model:model,prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:definition.codeProject,model})}};}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {readExecutionPolicy,readBatchExecutionPolicy,freezeBatchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
2
|
+
import {readModelJsonRecord} from '../runtime/js/cm-ai/model-configuration-file.mjs';
|
|
3
|
+
import {readExternalModels} from '../runtime/js/cm-ai/external-models.mjs';
|
|
1
4
|
// Trusted in-process batch driver. Task lifecycle and completion remain owned
|
|
2
5
|
// by the existing runner; only transitions between task runs are logged here.
|
|
3
6
|
import fs from 'node:fs';
|
|
@@ -5,34 +8,73 @@ import path from 'node:path';
|
|
|
5
8
|
import {spawnSync} from 'node:child_process';
|
|
6
9
|
import {fileURLToPath} from 'node:url';
|
|
7
10
|
import {openControlRun,validateRunDefinition} from './cm-ai-run.mjs';
|
|
8
|
-
import {developmentRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
11
|
+
import {developmentRetryable,completionRetryable,reviewRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
12
|
+
import {batchOperatorGuidance} from '../runtime/js/cm-ai/operator-guidance.mjs';
|
|
9
13
|
import {digest,json,shape,need,id,hex} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
10
14
|
import {scanRows,findCmAiQaDecision,latestCmAiQaRun} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
11
15
|
import {checkParallelWrite} from './cm-task-gate.mjs';
|
|
12
16
|
import {parseFeatureTaskText} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
17
|
+
import {approvedTaskGrammar} from '../runtime/js/spec-task-line.mjs';
|
|
13
18
|
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
14
19
|
import {inspectRunClosure} from './cm-log-event.mjs';
|
|
15
20
|
|
|
16
21
|
const writer=fileURLToPath(new URL('./cm-log-event.py',import.meta.url));
|
|
17
22
|
const key=task=>`${task.feature}/${task.taskId}`;
|
|
23
|
+
// Generation-1 member run id; the batch host uses it to tell a new batch from a resumed one.
|
|
24
|
+
export const batchTaskRunId=(batchId,taskKey)=>`task-${digest({batchId,task:taskKey}).slice(0,48)}`;
|
|
25
|
+
// A spec rebind is a single-task resume flag; batch members cannot take it, so
|
|
26
|
+
// never advertise it for them. Name the exits that do exist instead. An idle
|
|
27
|
+
// cancel of a parallel group does not end its member runs, so a parallel
|
|
28
|
+
// member cannot be superseded afterwards and only the spec revert applies.
|
|
29
|
+
export function batchMemberResult(result,{parallel=false}={}){
|
|
30
|
+
const decorate=value=>{
|
|
31
|
+
const guidance=batchOperatorGuidance(value);
|
|
32
|
+
return guidance?Object.freeze({...value,guidance}):value;
|
|
33
|
+
};
|
|
34
|
+
if(result?.pendingAction!=='spec_rebind')return decorate(result);
|
|
35
|
+
const files=/变更文件:([^;]+)/.exec(result.reason??'')?.[1]??'规格文件';
|
|
36
|
+
const revert=`规格已重新批准(变更:${files},只动了其他任务),但批次成员不能换绑。出口:还原这些规格改动并重新批准后继续本批次`;
|
|
37
|
+
return decorate(Object.freeze({...result,pendingAction:'none',
|
|
38
|
+
reason:parallel?`${revert}。并行组成员没有单独重做的出口。`
|
|
39
|
+
:`${revert};或取消本批次,还原该任务已改动的代码后,用单任务宿主 cm-ai-host.mjs 以 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做该任务。`}));
|
|
40
|
+
}
|
|
18
41
|
export function createCmAiBatch({configuration,executionFor,logHome,runtime='codex',checkCommands=null,checkTimeoutMs=60000,
|
|
19
|
-
rerunUnknownQa=false,rerunBlockedQa=false}){
|
|
42
|
+
rerunUnknownQa=false,rerunBlockedQa=false,holdRevisions=[]}){
|
|
20
43
|
const config=json(configuration);
|
|
21
|
-
shape(config,['version','repositoryId','batchId','specsDir','codeProject','tasks',...['codeProjects','parallel'].filter(name=>Object.hasOwn(config,name))]);
|
|
44
|
+
shape(config,['version','repositoryId','batchId','specsDir','codeProject','tasks',...['externalModels','executionPolicy','codeProjects','parallel'].filter(name=>Object.hasOwn(config,name))]);
|
|
22
45
|
need(config.version===1);id(config.repositoryId);id(config.batchId);need(config.batchId.length>=8);
|
|
23
46
|
need(typeof executionFor==='function'&&typeof logHome==='string'&&path.isAbsolute(logHome));
|
|
24
47
|
need(Array.isArray(config.tasks)&&config.tasks.length>0&&config.tasks.length<=256);
|
|
25
48
|
need(['codex','claude'].includes(runtime),'invalid_runtime');
|
|
49
|
+
if(config.externalModels)readExternalModels(config.externalModels);
|
|
50
|
+
if(config.executionPolicy)readExecutionPolicy(config.executionPolicy);
|
|
51
|
+
const batchGit=(cwd,args,code)=>{
|
|
52
|
+
if((config.externalModels||config.executionPolicy)&&args[0]==='add'&&args[1]==='-A')args=['add','-A','--','.',':!.cm-external-models-v1.json',':!.cm-model-config.lock'];
|
|
53
|
+
if((config.externalModels||config.executionPolicy)&&args[0]==='worktree'&&args[1]==='remove'){
|
|
54
|
+
const file=path.join(args[2],'.cm-external-models-v1.json');
|
|
55
|
+
if(fs.existsSync(file)){
|
|
56
|
+
need(digest(readModelJsonRecord(file).value)===digest({version:1,kind:'cm-external-code-binding',specsDir:config.specsDir}),'external_code_specs_conflict');
|
|
57
|
+
const lock=path.join(args[2],'.cm-model-config.lock');
|
|
58
|
+
if(fs.existsSync(lock)){const stat=fs.lstatSync(lock);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.nlink===1&&stat.size===0&&(stat.mode&0o077)===0,'invalid_model_configuration_lock');fs.unlinkSync(lock);}
|
|
59
|
+
fs.unlinkSync(file);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const output=git(cwd,args,code);
|
|
63
|
+
return (config.externalModels||config.executionPolicy)&&args[0]==='status'?output.split('\n').filter(line=>!['?? .cm-external-models-v1.json','?? .cm-model-config.lock'].includes(line)).join('\n'):output;
|
|
64
|
+
};
|
|
26
65
|
const plans=new Map();
|
|
27
66
|
for(const task of config.tasks){
|
|
28
67
|
shape(task,['feature','taskId','scope','requirements']);
|
|
29
68
|
need(!plans.has(key(task)));const definition=validateRunDefinition({version:1,
|
|
30
69
|
specsDir:config.specsDir,codeProject:config.codeProject,...(config.codeProjects?{codeProjects:config.codeProjects}:{}),feature:task.feature,
|
|
31
|
-
identity:{repositoryId:config.repositoryId,runId
|
|
70
|
+
identity:{repositoryId:config.repositoryId,runId:batchTaskRunId(config.batchId,key(task)),
|
|
32
71
|
taskId:task.taskId,attempt:1},scope:task.scope,requirements:task.requirements});
|
|
33
72
|
need(definition.specsDir===config.specsDir&&definition.codeProject===config.codeProject,'invalid_path');
|
|
34
73
|
plans.set(key(task),definition);
|
|
35
74
|
}
|
|
75
|
+
// Tasks whose second-round answer is not written yet stop after a changes_requested review.
|
|
76
|
+
need(Array.isArray(holdRevisions)&&holdRevisions.every(item=>plans.has(item)),'invalid_input');
|
|
77
|
+
const held=new Set(holdRevisions);
|
|
36
78
|
const groups=validateGroups(config,plans),membership=new Map(groups.flatMap(group=>group.map(key=>[key,group])));
|
|
37
79
|
const originalMembership=new Map(membership),originalPlans=new Map(plans);
|
|
38
80
|
const first=plans.keys().next().value,planDigest=digest(config),log=path.join(config.specsDir,'运行日志.jsonl');
|
|
@@ -91,8 +133,10 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
91
133
|
// only the tasks the flag can legally apply to receive it.
|
|
92
134
|
const recovery=mode==='resume'&&execution?.qaExecutor&&(rerunUnknownQa||rerunBlockedQa)
|
|
93
135
|
? {rerunUnknownQa,rerunBlockedQa} : {};
|
|
94
|
-
|
|
136
|
+
const run=await openControlRun(definition,mode,execution,{...recovery,...(held.has(taskKey)?{holdRevision:true}:{}),
|
|
95
137
|
...(membership.has(taskKey)?{parallelSelection:{version:1,group:membership.get(taskKey).map(key=>plans.get(key).identity.taskId)}}:{})});
|
|
138
|
+
if(!run.host)return run;
|
|
139
|
+
return {...run,host:{...run.host,handle:async request=>batchMemberResult(await run.host.handle(request),{parallel:membership.has(taskKey)})}};
|
|
96
140
|
}
|
|
97
141
|
function parallelProgress(rows){
|
|
98
142
|
const done=new Set(),ready=new Map(),merging=new Map(),blocked=new Map();let stopped=false,code=null;
|
|
@@ -152,7 +196,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
152
196
|
need(revision===row.checkpoint&&digest(body)===revision,'batch_checkpoint_mismatch');
|
|
153
197
|
const binding={specsDir:config.specsDir,feature:definition.feature,identity:row.identity,packageDigest:row.package_digest};
|
|
154
198
|
need(findCmAiQaDecision(binding)?.status==='skipped'&&inspectRunClosure(log,definition.identity.runId).closed,'batch_qa_not_ready');
|
|
155
|
-
|
|
199
|
+
batchGit(config.codeProject,['merge-base','--is-ancestor',row.merge_commit,'HEAD'],'batch_merge_history_changed');
|
|
156
200
|
}
|
|
157
201
|
function prepareGroup(group){
|
|
158
202
|
const state=progress(),remaining=group.filter(key=>membership.has(key)&&!state.done.has(key));
|
|
@@ -161,9 +205,9 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
161
205
|
if(!fs.existsSync(worktree)){
|
|
162
206
|
need(!state.ready.has(key),'batch_worktree_missing');
|
|
163
207
|
fs.mkdirSync(path.dirname(worktree),{recursive:true});
|
|
164
|
-
|
|
208
|
+
batchGit(config.codeProject,['worktree','add','-b',branch,worktree,'HEAD'],'batch_worktree_failed');
|
|
165
209
|
}
|
|
166
|
-
need(
|
|
210
|
+
need(batchGit(worktree,['branch','--show-current'])===branch,'batch_worktree_mismatch');
|
|
167
211
|
const definition=plans.get(key);
|
|
168
212
|
plans.set(key,validateRunDefinition({...definition,codeProject:worktree,
|
|
169
213
|
...(definition.codeProjects?{codeProjects:definition.codeProjects.map(root=>path.join(worktree,path.relative(config.codeProject,root)))}:{})}));
|
|
@@ -176,11 +220,11 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
176
220
|
function preserveBlockedMember(row){
|
|
177
221
|
const {worktree,branch}=location(row.from_key);
|
|
178
222
|
need(row.worktree===worktree&&row.branch===branch,'batch_worktree_mismatch');
|
|
179
|
-
|
|
223
|
+
batchGit(config.codeProject,['rev-parse','--verify',`refs/heads/${branch}`],'batch_worktree_missing');
|
|
180
224
|
if(!fs.existsSync(worktree))return;
|
|
181
|
-
need(
|
|
225
|
+
need(batchGit(worktree,['branch','--show-current'])===branch,'batch_worktree_mismatch');
|
|
182
226
|
commitChanges(worktree,taskCommitArgs(plans.get(row.from_key).identity.taskId,taskDescription(config,plans.get(row.from_key)),row.code,row.reason));
|
|
183
|
-
|
|
227
|
+
batchGit(config.codeProject,['worktree','remove',worktree]);
|
|
184
228
|
// Keep the branch: its WIP is evidence, not approved code to merge.
|
|
185
229
|
}
|
|
186
230
|
async function driveMember(key,request){
|
|
@@ -198,9 +242,10 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
198
242
|
if(status.code===null&&['ready','changes_requested'].includes(status.state)
|
|
199
243
|
||developmentRetryable(status))await call('start');
|
|
200
244
|
if(['reported','advanced'].includes(status.outcome)&&(status.code===null&&status.state==='awaiting_review'
|
|
201
|
-
||status
|
|
245
|
+
||reviewRetryable(status)))await call('decision');
|
|
202
246
|
if(status.outcome==='advanced'&&status.code===null&&status.state==='changes_requested'&&status.identity.attempt===round+1)continue;
|
|
203
|
-
if(['reported','advanced'].includes(status.outcome)
|
|
247
|
+
if(['reported','advanced'].includes(status.outcome)
|
|
248
|
+
&&(status.code===null&&status.state==='approved'||completionRetryable(status))){
|
|
204
249
|
const completion=completeTail.then(()=>call('complete'));
|
|
205
250
|
completeTail=completion.then(()=>{},()=>{});await completion;
|
|
206
251
|
}
|
|
@@ -231,31 +276,31 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
231
276
|
}finally{run.close();}
|
|
232
277
|
let intent=progress().merging.get(key);
|
|
233
278
|
if(!intent){
|
|
234
|
-
|
|
235
|
-
if(
|
|
236
|
-
need(
|
|
237
|
-
intent={from_key:key,expected_old:
|
|
279
|
+
batchGit(worktree,['add','-A']);
|
|
280
|
+
if(batchGit(worktree,['status','--porcelain']))batchGit(worktree,['commit',...taskCommitArgs(plans.get(key).identity.taskId,taskDescription(config,plans.get(key)))]);
|
|
281
|
+
need(batchGit(config.codeProject,['status','--porcelain'])==='','batch_main_dirty');
|
|
282
|
+
intent={from_key:key,expected_old:batchGit(config.codeProject,['rev-parse','HEAD']),member_commit:batchGit(worktree,['rev-parse','HEAD'])};
|
|
238
283
|
record('batch_merge_started',intent);
|
|
239
284
|
}
|
|
240
|
-
const current=
|
|
285
|
+
const current=batchGit(config.codeProject,['rev-parse','HEAD']);
|
|
241
286
|
if(current===intent.expected_old){
|
|
242
287
|
const restore=unionAttributes(config.codeProject);
|
|
243
288
|
let result;
|
|
244
289
|
try{result=spawnSync('git',['-C',config.codeProject,'merge','--no-ff','--no-edit',intent.member_commit],gitOptions());}
|
|
245
290
|
finally{restore();}
|
|
246
291
|
if(result.error||result.status!==0){
|
|
247
|
-
const files=
|
|
248
|
-
|
|
249
|
-
need(
|
|
292
|
+
const files=batchGit(config.codeProject,['diff','--name-only','--diff-filter=U']).split('\n').filter(Boolean);
|
|
293
|
+
batchGit(config.codeProject,['merge','--abort'],'batch_merge_abort_failed');
|
|
294
|
+
need(batchGit(config.codeProject,['rev-parse','HEAD'])===intent.expected_old,'batch_merge_history_changed');
|
|
250
295
|
record('batch_merge_conflict',{from_key:key,code:'merge_conflict',files,expected_old:intent.expected_old});
|
|
251
296
|
return {outcome:'blocked',code:'merge_conflict',batchId:config.batchId,files};
|
|
252
297
|
}
|
|
253
298
|
}else{
|
|
254
299
|
// A crash may happen after Git commits but before the handoff log append.
|
|
255
|
-
const parents=
|
|
300
|
+
const parents=batchGit(config.codeProject,['show','-s','--format=%P','HEAD']).split(' ');
|
|
256
301
|
need(parents.length===2&&parents[0]===intent.expected_old&&parents[1]===intent.member_commit,'batch_merge_history_changed');
|
|
257
302
|
}
|
|
258
|
-
const merge_commit=
|
|
303
|
+
const merge_commit=batchGit(config.codeProject,['rev-parse','HEAD']);
|
|
259
304
|
let post_merge_check='skipped';
|
|
260
305
|
if(checkCommands?.length){
|
|
261
306
|
const check=createHostCheck({cwd:config.codeProject,commands:checkCommands,timeoutMs:checkTimeoutMs});
|
|
@@ -270,7 +315,7 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
270
315
|
const next=[...plans.keys()].find(key=>!done.has(key));need(next,'parallel_final_task_excluded');
|
|
271
316
|
record('batch_handoff',{from_key:key,to_key:next,checkpoint:row.checkpoint,package_digest:row.package_digest,
|
|
272
317
|
identity:row.identity,merge_commit,post_merge_check});
|
|
273
|
-
|
|
318
|
+
batchGit(config.codeProject,['worktree','remove',worktree]);batchGit(config.codeProject,['branch','-d',branch]);
|
|
274
319
|
return null;
|
|
275
320
|
}
|
|
276
321
|
async function parallelGroup(group,request){
|
|
@@ -303,9 +348,9 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
303
348
|
// Retryable validation, review transport and completed-task QA stay on
|
|
304
349
|
// their existing recovery path; a new run must not bypass those gates.
|
|
305
350
|
const terminal=['blocked','failed','unknown'].includes(status.state)
|
|
306
|
-
|
|
307
|
-
||status.state==='pending_review'&&status.code!==null
|
|
308
|
-
if(!terminal){waiting??=status;continue;}
|
|
351
|
+
&&!developmentRetryable(status)&&!completionRetryable(status)
|
|
352
|
+
||status.state==='pending_review'&&status.code!==null&&!reviewRetryable(status);
|
|
353
|
+
if(!terminal||config.externalModels||config.executionPolicy){waiting??=status;continue;}
|
|
309
354
|
const key=pending[index];
|
|
310
355
|
record('batch_member_blocked',{from_key:key,code:status.code??status.state,
|
|
311
356
|
reason:status.blockedReason??status.reason??status.code??status.state,...location(key),generation:2});
|
|
@@ -317,8 +362,8 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
317
362
|
return null;
|
|
318
363
|
}
|
|
319
364
|
return Object.freeze({async handle(raw){
|
|
320
|
-
const request=json(raw);shape(request,['operation','requestId']);id(request.requestId);
|
|
321
|
-
need(['advance','status','cancel'].includes(request.operation));
|
|
365
|
+
const request=json(raw);shape(request,['operation','requestId',...(request.operation==='reconcile_review'?['taskKey','invocationId']:[])]);id(request.requestId);
|
|
366
|
+
need(['advance','status','cancel','reconcile_review'].includes(request.operation));
|
|
322
367
|
if(request.operation==='cancel'&&busy){
|
|
323
368
|
cancelled=true;
|
|
324
369
|
if(members.size){record('batch_cancel',{from_key:liveKey});
|
|
@@ -336,9 +381,29 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
336
381
|
try{
|
|
337
382
|
releaseLock=acquireBatchLock(config);
|
|
338
383
|
const initial=progress();liveKey=initial.current;
|
|
384
|
+
const {externalModels:ignoredModels,executionPolicy:ignoredPolicy,...policyBatch}=config;
|
|
385
|
+
const policy=readBatchExecutionPolicy({batch:policyBatch,started:initial.rows.length>0,enabled:!!config.executionPolicy});
|
|
386
|
+
need(digest(policy)===digest(config.executionPolicy??null),'execution_policy_batch_binding');
|
|
387
|
+
if(request.operation!=='status')await freezeBatchExecutionPolicy(policyBatch,policy);
|
|
388
|
+
if(request.operation==='reconcile_review'){
|
|
389
|
+
need((config.externalModels||config.executionPolicy)&&plans.has(request.taskKey),'review_reconciliation_unavailable');id(request.invocationId);
|
|
390
|
+
if(membership.has(request.taskKey)){
|
|
391
|
+
const {worktree,branch}=location(request.taskKey);
|
|
392
|
+
need(fs.existsSync(worktree),'review_reconciliation_unavailable');
|
|
393
|
+
need(batchGit(worktree,['branch','--show-current'])===branch,'batch_worktree_mismatch');
|
|
394
|
+
const definition=plans.get(request.taskKey);
|
|
395
|
+
plans.set(request.taskKey,validateRunDefinition({...definition,codeProject:worktree,
|
|
396
|
+
...(definition.codeProjects?{codeProjects:definition.codeProjects.map(root=>path.join(worktree,path.relative(config.codeProject,root)))}:{})}));
|
|
397
|
+
}
|
|
398
|
+
const definition=plans.get(request.taskKey);
|
|
399
|
+
need(fs.existsSync(path.join(config.specsDir,'.reviews','.execution',definition.identity.runId,'state.json')),'review_reconciliation_unavailable');
|
|
400
|
+
const run=await open(request.taskKey);
|
|
401
|
+
try{return await run.host.handle({version:1,operation:'reconcile_review',requestId:request.requestId,identity:definition.identity,invocationId:request.invocationId});}
|
|
402
|
+
finally{run.close();}
|
|
403
|
+
}
|
|
339
404
|
if(initial.stopped)return {outcome:'blocked',code:initial.code??'cancelled',batchId:config.batchId};
|
|
340
405
|
if(request.operation==='advance'&&!initial.rows.length){
|
|
341
|
-
const dirty=
|
|
406
|
+
const dirty=batchGit(config.codeProject,['status','--porcelain']);
|
|
342
407
|
if(dirty)return {outcome:'blocked',code:'batch_main_dirty',batchId:config.batchId,
|
|
343
408
|
reason:`batch_main_dirty\n${dirty}`,files:dirty.split('\n')};
|
|
344
409
|
}
|
|
@@ -403,8 +468,8 @@ function git(cwd,args,code='batch_git_failed'){
|
|
|
403
468
|
need(!result.error&&result.status===0&&result.signal===null,code);return result.stdout.trim();
|
|
404
469
|
}
|
|
405
470
|
function commitChanges(cwd,messageArgs){
|
|
406
|
-
if(!git(cwd,['status','--porcelain']))return null;
|
|
407
|
-
git(cwd,['add','-A']);git(cwd,['commit',...messageArgs]);
|
|
471
|
+
if(!git(cwd,['status','--porcelain']).split('\n').filter(line=>!['?? .cm-external-models-v1.json','?? .cm-model-config.lock'].includes(line)).join('\n'))return null;
|
|
472
|
+
git(cwd,['add','-A','--','.',':!.cm-external-models-v1.json',':!.cm-model-config.lock']);git(cwd,['commit',...messageArgs]);
|
|
408
473
|
return git(cwd,['rev-parse','HEAD']);
|
|
409
474
|
}
|
|
410
475
|
// Keep the original description in the body; only the subject is summarized.
|
|
@@ -427,7 +492,8 @@ export function taskCommitArgs(taskId,description,blockedCode=null,blockedReason
|
|
|
427
492
|
return ['-m',subject,'-m',description+(blockedCode!==null&&blockedReason!==null?`\n\n${blockedReason}`:'')];
|
|
428
493
|
}
|
|
429
494
|
function taskDescription(config,definition){
|
|
430
|
-
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(config.specsDir,definition.feature,'tasks.md'),'utf8'),
|
|
495
|
+
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(config.specsDir,definition.feature,'tasks.md'),'utf8'),
|
|
496
|
+
{allowDependencyPunctuation:true,grammar:approvedTaskGrammar(config.specsDir)});
|
|
431
497
|
need(!parsed.error,'parallel_task_invalid');return parsed.tasks.find(task=>task.id===definition.identity.taskId)?.description??definition.identity.taskId;
|
|
432
498
|
}
|
|
433
499
|
function validateGroups(config,plans){
|
|
@@ -437,7 +503,8 @@ function validateGroups(config,plans){
|
|
|
437
503
|
need(group.every(key=>plans.has(key)&&!used.has(key))&&new Set(group).size===group.length,'invalid_parallel_group');
|
|
438
504
|
const feature=plans.get(group[0]).feature;
|
|
439
505
|
need(group.every(key=>plans.get(key).feature===feature),'parallel_feature_mismatch');
|
|
440
|
-
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(config.specsDir,feature,'tasks.md'),'utf8'),
|
|
506
|
+
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(config.specsDir,feature,'tasks.md'),'utf8'),
|
|
507
|
+
{allowDependencyPunctuation:true,grammar:approvedTaskGrammar(config.specsDir)});
|
|
441
508
|
need(!parsed.error,'parallel_task_invalid');
|
|
442
509
|
const ids=new Set(group.map(key=>plans.get(key).identity.taskId));
|
|
443
510
|
need([...ids].every(id=>parsed.tasks.some(task=>task.id===id&&!task.dropped)),'parallel_task_invalid');
|