@aibyzero/cm-workflow 0.16.3 → 0.16.5
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 +8 -0
- package/CHANGELOG.md +59 -0
- package/README.md +55 -3
- package/VERSION +1 -1
- package/docs/installation.md +21 -1
- package/docs/js-workflow-control.md +245 -33
- package/docs/next-steps.md +14 -24
- package/docs/runtime-failover.md +1 -1
- 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-stream.mjs +30 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +116 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +137 -22
- 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 +180 -53
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
- 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 +305 -0
- package/runtime/js/cm-ai/drive-core.mjs +39 -7
- package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
- 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-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
- package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +20 -5
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +13 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
- 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 +427 -31
- 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/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +502 -65
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-fix/execution.mjs +109 -25
- package/runtime/js/cm-fix/host-review.mjs +7 -3
- package/runtime/js/cm-fix/host.mjs +3 -1
- package/runtime/js/cm-fix/progress.mjs +1 -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-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/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/summary.mjs +6 -2
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +14 -3
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +19 -10
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +93 -21
- package/scripts/cm-ai-batch-drive.test.mjs +171 -3
- package/scripts/cm-ai-batch-host.mjs +37 -13
- package/scripts/cm-ai-batch-host.test.mjs +26 -0
- package/scripts/cm-ai-batch-run.mjs +33 -10
- 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 +158 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap.test.mjs +99 -7
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -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 +480 -47
- package/scripts/cm-ai-drive.test.mjs +247 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +89 -25
- package/scripts/cm-ai-host.test.mjs +274 -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-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +166 -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 +917 -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 +160 -60
- package/scripts/cm-ai-run.test.mjs +4 -3
- 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-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.mjs +4 -3
- package/scripts/cm-check-drive.test.mjs +17 -1
- package/scripts/cm-check-entry.mjs +13 -2
- package/scripts/cm-check-host.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +57 -1
- package/scripts/cm-check-runtime.sh +16 -7
- package/scripts/cm-claude-developer-worker.test.mjs +43 -2
- package/scripts/cm-claude-probe.test.mjs +9 -1
- package/scripts/cm-claude-review-stream.test.mjs +68 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- 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 +45 -13
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-host.mjs +9 -6
- package/scripts/cm-fix-review-budget.test.mjs +141 -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 +192 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-log-event.mjs +17 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-prd-completion.test.mjs +105 -2
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +13 -7
- package/scripts/cm-prd-drive.test.mjs +10 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- 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 +40 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- 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 +31 -1
- package/scripts/cm-task-gate.mjs +18 -10
- package/scripts/cm-task-gate.py +1 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/process-cleanup.mjs +99 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-npm-install.py +1 -1
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-shell-compat.sh +67 -0
- 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/references/N1-init.md +1 -1
- package/skills/cm-ai/references/js-host.md +264 -40
- package/skills/cm-check/SKILL.md +6 -1
- package/skills/cm-check/references/js-host.md +3 -3
- package/skills/cm-fix/references/js-host.md +22 -1
- package/skills/cm-prd/references/js-change-recovery.md +30 -0
- package/skills/cm-prd/references/js-host.md +6 -0
|
@@ -3,19 +3,24 @@
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import {fileURLToPath} from 'node:url';
|
|
6
|
-
import {createCmAiBatch} from './cm-ai-batch-run.mjs';
|
|
6
|
+
import {createCmAiBatch,batchTaskRunId} from './cm-ai-batch-run.mjs';
|
|
7
7
|
import {createConversationExecution,readConversationReviewConfiguration,readConversationProtection,runReviewPreflight} from './cm-ai-host.mjs';
|
|
8
8
|
import {loadConfig,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
|
|
9
9
|
import {preflightMatches} from '../runtime/js/cm-ai/worker-codex.mjs';
|
|
10
10
|
import {claudePreflightMatches} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
11
11
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
12
|
-
import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
12
|
+
import {serveCmAiHost,parseHostInputLimit,inputLimitReason} from '../runtime/js/cm-ai/host-session.mjs';
|
|
13
13
|
import {validateHostWorkflowConfiguration,featureHasBrowserCases,readBrowserCapability} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
|
|
14
14
|
import {digest,json,need,shape} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
15
|
+
import {identifyApprovedBootstrapFeature} from '../runtime/js/cm-ai/bootstrap-feature.mjs';
|
|
15
16
|
|
|
16
|
-
const usage='cm-ai-batch-host.mjs serve --config PATH --host-context ID --allow-development [--runtime codex|claude] [--
|
|
17
|
+
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) [--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
18
|
const safeCode=error=>typeof error?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(error.code)?error.code:'batch_host_failed';
|
|
18
19
|
|
|
20
|
+
export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHost){
|
|
21
|
+
return serve({...options,inputLimit:parseHostInputLimit(rawInputLimit)});
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
async function memberReviewConfiguration(batch,definition,review,runtime){
|
|
20
25
|
try{
|
|
21
26
|
need(review!==null,'review_configuration_required');
|
|
@@ -44,7 +49,7 @@ async function memberReviewConfiguration(batch,definition,review,runtime){
|
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
47
|
-
if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\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.\
|
|
52
|
+
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;}
|
|
48
53
|
let bridge;
|
|
49
54
|
try{
|
|
50
55
|
need(argv.length>=6&&argv[0]==='serve'&&argv[1]==='--config'&&argv[3]==='--host-context'
|
|
@@ -57,13 +62,13 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
57
62
|
if(bootstraps!==null){
|
|
58
63
|
need(typeof bootstraps==='object'&&!Array.isArray(bootstraps),'invalid_bootstrap_config');
|
|
59
64
|
for(const [key,config] of Object.entries(bootstraps)){
|
|
60
|
-
need(keys.includes(key)&&key.startsWith('
|
|
65
|
+
need(keys.includes(key)&&key.startsWith(identifyApprovedBootstrapFeature(batch.specsDir)+'/'),'bootstrap_task_required');shape(config,['selection']);
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
need(keys.length===Object.keys(workflows).length&&keys.every(key=>Object.hasOwn(workflows,key)),'workflow_task_mismatch');
|
|
64
69
|
for(const key of keys)if(workflows[key]!==null)validateHostWorkflowConfiguration(workflows[key]);
|
|
65
|
-
let review=null,allowQa=false,allowBootstrap=false,runtime=null,protection=null,providerConfig=null,browserQaFlag;
|
|
66
|
-
let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false;const approvals=new Set(),developments=new Map();
|
|
70
|
+
let review=null,allowQa=false,allowBootstrap=false,runtime=null,protection=null,providerConfig=null,browserQaFlag,inputLimitRaw;
|
|
71
|
+
let rerunUnknownQa=false,rerunBlockedQa=false,verificationPrecheck=false;const approvals=new Set(),developments=new Map(),holds=new Set();
|
|
67
72
|
for(let index=6;index<argv.length;index++){
|
|
68
73
|
const name=argv[index];
|
|
69
74
|
if(name==='--allow-qa'){need(!allowQa,'invalid_arguments');allowQa=true;}
|
|
@@ -92,7 +97,14 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
92
97
|
else if(name==='--runtime'){
|
|
93
98
|
need(runtime===null&&['codex','claude'].includes(argv[index+1]),'invalid_runtime');runtime=argv[++index];
|
|
94
99
|
}
|
|
100
|
+
else if(name==='--input-limit'){
|
|
101
|
+
need(inputLimitRaw===undefined&&typeof argv[index+1]==='string','invalid_arguments');
|
|
102
|
+
inputLimitRaw=argv[++index];parseHostInputLimit(inputLimitRaw);
|
|
103
|
+
}
|
|
95
104
|
else if(name==='--review-config'){need(review===null&&typeof argv[index+1]==='string','invalid_arguments');review=readConversationReviewConfiguration(argv[++index]);}
|
|
105
|
+
else if(name==='--hold-revision'){
|
|
106
|
+
const held=argv[++index];need(typeof held==='string'&&keys.includes(held)&&!holds.has(held),'invalid_arguments');holds.add(held);
|
|
107
|
+
}
|
|
96
108
|
else if(name==='--allow-review'){
|
|
97
109
|
const approval=argv[++index];need(typeof approval==='string'&&!approvals.has(approval),'invalid_arguments');
|
|
98
110
|
const split=approval.lastIndexOf(':'),key=approval.slice(0,split),attempt=approval.slice(split+1);
|
|
@@ -102,15 +114,26 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
102
114
|
need(!developments.size||providerConfig!==null,'protected_configuration_required');
|
|
103
115
|
// Same launch-time assertion as the single-task host, evaluated across every
|
|
104
116
|
// task whose approved contract can select a browser case.
|
|
105
|
-
readBrowserCapability(browserQaFlag,keys.
|
|
106
|
-
&&featureHasBrowserCases(batch.specsDir,key.slice(0,key.lastIndexOf('/')),batch.codeProject)
|
|
117
|
+
readBrowserCapability(browserQaFlag,keys.flatMap(key=>workflows[key]?.qa!=null
|
|
118
|
+
&&featureHasBrowserCases(batch.specsDir,key.slice(0,key.lastIndexOf('/')),batch.codeProject)
|
|
119
|
+
?[workflows[key].qa.environment?.carrier??'browser']:[]));
|
|
107
120
|
need(!approvals.size||review!==null,'review_configuration_required');
|
|
108
121
|
// Same two guards as the single-task host. A batch has no --mode, so the
|
|
109
122
|
// per-task resume check lives in createCmAiBatch rather than here.
|
|
110
123
|
need(!(rerunUnknownQa&&rerunBlockedQa),'qa_recovery_authorization_required');
|
|
111
124
|
need(!(rerunUnknownQa||rerunBlockedQa)||allowQa,'qa_recovery_authorization_required');
|
|
112
125
|
need(allowQa||!Object.values(workflows).some(item=>item?.qa!=null),'qa_authorization_required');
|
|
113
|
-
|
|
126
|
+
// Same rule as single-task create: the reviewer binding is part of every
|
|
127
|
+
// member's durable fingerprint and cannot be added on resume. A batch none
|
|
128
|
+
// of whose member runs exist yet is being created. Batches that already
|
|
129
|
+
// started keep their original launch (older ones may have no review config).
|
|
130
|
+
const created=keys.some(key=>fs.existsSync(path.join(path.resolve(batch.specsDir),'.reviews','.execution',
|
|
131
|
+
batchTaskRunId(batch.batchId,key),'state.json')));
|
|
132
|
+
if(!created&&review===null)throw Object.assign(new Error('review_configuration_required'),{code:'review_configuration_required',
|
|
133
|
+
reason:'新批次必须带 --review-config:审查配置写进每个任务运行的指纹,恢复时不能再补。先用 cm-ai-host.mjs preflight 生成 review.json;'
|
|
134
|
+
+'是否真正派发审查仍由 --allow-review 单独授权'});
|
|
135
|
+
// Tool replies travel on the same input lines, so they share the one limit.
|
|
136
|
+
bridge=createHostToolBridge({responseLimit:parseHostInputLimit(inputLimitRaw)});
|
|
114
137
|
// The current conversation transport accepts one outstanding host call.
|
|
115
138
|
// Queue those calls only; member runners and independent Review stay concurrent.
|
|
116
139
|
let hostCallTail=Promise.resolve();
|
|
@@ -120,7 +143,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
120
143
|
}};
|
|
121
144
|
const driver=createCmAiBatch({configuration:batch,logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
|
|
122
145
|
runtime:runtime??'codex',checkCommands:(providerConfig??protection)?.checkCommands??null,checkTimeoutMs:(providerConfig??protection)?.timeoutMs??60000,
|
|
123
|
-
rerunUnknownQa,rerunBlockedQa,
|
|
146
|
+
rerunUnknownQa,rerunBlockedQa,holdRevisions:[...holds],
|
|
124
147
|
executionFor:async(definition,{parallelMember=false}={})=>{
|
|
125
148
|
const key=`${definition.feature}/${definition.identity.taskId}`;
|
|
126
149
|
const attempts=[1,2].filter(attempt=>approvals.has(`${key}:${attempt}`));
|
|
@@ -142,10 +165,11 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
142
165
|
try{return await driver.handle(request);}catch(cause){return {outcome:'blocked',code:safeCode(cause)};}
|
|
143
166
|
}};
|
|
144
167
|
const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
|
|
145
|
-
try{await
|
|
168
|
+
try{await serveHostTransport({host,input,output,toolBridge:bridge},inputLimitRaw);}
|
|
146
169
|
finally{if(rawMode)input.setRawMode(false);}
|
|
147
170
|
return 0;
|
|
148
|
-
}catch(cause){error.write(JSON.stringify({error:{code
|
|
171
|
+
}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)
|
|
172
|
+
&&typeof cause.reason==='string'?{reason:cause.reason}:{}),...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:{})}})+'\n');return 1;}
|
|
149
173
|
finally{bridge?.close();}
|
|
150
174
|
}
|
|
151
175
|
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
|
@@ -11,6 +11,29 @@ import {claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
|
11
11
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
12
12
|
|
|
13
13
|
const cli=fileURLToPath(new URL('./cm-ai-batch-host.mjs',import.meta.url));
|
|
14
|
+
test('batch host input limit reaches transport without opening a host',async()=>{
|
|
15
|
+
const {serveHostTransport}=await import('./cm-ai-batch-host.mjs');
|
|
16
|
+
assert.equal(typeof serveHostTransport,'function');
|
|
17
|
+
let seen;
|
|
18
|
+
await serveHostTransport({host:{}},'1048576',async options=>{seen=options.inputLimit;});
|
|
19
|
+
assert.equal(seen,1048576);
|
|
20
|
+
for(const raw of ['65535','4194305','1.5'])
|
|
21
|
+
await assert.rejects(serveHostTransport({host:{}},raw,async()=>{}),/invalid_arguments/);
|
|
22
|
+
});
|
|
23
|
+
test('batch host help documents input limit',()=>{
|
|
24
|
+
const help=spawnSync(process.execPath,[cli,'--help'],{encoding:'utf8'});
|
|
25
|
+
assert.equal(help.status,0);assert.match(help.stdout,/--input-limit BYTES/);
|
|
26
|
+
});
|
|
27
|
+
test('batch host CLI rejects out-of-range and non-integer input limits before opening a run',()=>{
|
|
28
|
+
const f=fixture();
|
|
29
|
+
try{
|
|
30
|
+
for(const raw of ['65535','4194305','1.5']){
|
|
31
|
+
const run=spawnSync(process.execPath,[cli,...f.args,'--input-limit',raw],{encoding:'utf8'});
|
|
32
|
+
assert.equal(run.status,1);assert.match(run.stderr,/invalid_arguments/);
|
|
33
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews')),false);
|
|
34
|
+
}
|
|
35
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
36
|
+
});
|
|
14
37
|
function fixture(runtime='codex'){
|
|
15
38
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-host-')));
|
|
16
39
|
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work',bin=path.join(root,'bin');
|
|
@@ -233,11 +256,14 @@ test('provider development grants select worktree runtimes and keep the serial t
|
|
|
233
256
|
const protectedFile=path.join(f.root,'protected.json');fs.writeFileSync(protectedFile,JSON.stringify(protection));
|
|
234
257
|
const stub=path.join(f.root,'stub.mjs'),host=path.join(f.root,'batch-host.mjs');
|
|
235
258
|
const hostModule=new URL('./cm-ai-host.mjs',import.meta.url).href;
|
|
259
|
+
const sessionModule=new URL('../runtime/js/cm-ai/host-session.mjs',import.meta.url).href;
|
|
236
260
|
const workerModule=new URL('../runtime/js/cm-ai/codex-config.mjs',import.meta.url).href;
|
|
237
261
|
fs.writeFileSync(stub,`
|
|
238
262
|
import {configFingerprint} from ${JSON.stringify(workerModule)};
|
|
239
263
|
export {readConversationReviewConfiguration,readConversationProtection} from ${JSON.stringify(hostModule)};
|
|
264
|
+
export {parseHostInputLimit,inputLimitReason} from ${JSON.stringify(sessionModule)};
|
|
240
265
|
export const calls=[];export let scheduler;
|
|
266
|
+
export {batchTaskRunId} from ${JSON.stringify(new URL('./cm-ai-batch-run.mjs',import.meta.url).href)};
|
|
241
267
|
export function createConversationExecution(...args){calls.push(args);return {};}
|
|
242
268
|
export async function runReviewPreflight(definition,{model}){return {model,disabledSkills:[],preflight:{passed:true,
|
|
243
269
|
cli_model:model,prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:definition.codeProject,model})}};}
|
|
@@ -5,18 +5,33 @@ import path from 'node:path';
|
|
|
5
5
|
import {spawnSync} from 'node:child_process';
|
|
6
6
|
import {fileURLToPath} from 'node:url';
|
|
7
7
|
import {openControlRun,validateRunDefinition} from './cm-ai-run.mjs';
|
|
8
|
-
import {developmentRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
8
|
+
import {developmentRetryable,completionRetryable,reviewRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
9
9
|
import {digest,json,shape,need,id,hex} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
10
10
|
import {scanRows,findCmAiQaDecision,latestCmAiQaRun} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
11
11
|
import {checkParallelWrite} from './cm-task-gate.mjs';
|
|
12
12
|
import {parseFeatureTaskText} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
13
|
+
import {approvedTaskGrammar} from '../runtime/js/spec-task-line.mjs';
|
|
13
14
|
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
14
15
|
import {inspectRunClosure} from './cm-log-event.mjs';
|
|
15
16
|
|
|
16
17
|
const writer=fileURLToPath(new URL('./cm-log-event.py',import.meta.url));
|
|
17
18
|
const key=task=>`${task.feature}/${task.taskId}`;
|
|
19
|
+
// Generation-1 member run id; the batch host uses it to tell a new batch from a resumed one.
|
|
20
|
+
export const batchTaskRunId=(batchId,taskKey)=>`task-${digest({batchId,task:taskKey}).slice(0,48)}`;
|
|
21
|
+
// A spec rebind is a single-task resume flag; batch members cannot take it, so
|
|
22
|
+
// never advertise it for them. Name the exits that do exist instead. An idle
|
|
23
|
+
// cancel of a parallel group does not end its member runs, so a parallel
|
|
24
|
+
// member cannot be superseded afterwards and only the spec revert applies.
|
|
25
|
+
export function batchMemberResult(result,{parallel=false}={}){
|
|
26
|
+
if(result?.pendingAction!=='spec_rebind')return result;
|
|
27
|
+
const files=/变更文件:([^;]+)/.exec(result.reason??'')?.[1]??'规格文件';
|
|
28
|
+
const revert=`规格已重新批准(变更:${files},只动了其他任务),但批次成员不能换绑。出口:还原这些规格改动并重新批准后继续本批次`;
|
|
29
|
+
return Object.freeze({...result,pendingAction:'none',
|
|
30
|
+
reason:parallel?`${revert}。并行组成员没有单独重做的出口。`
|
|
31
|
+
:`${revert};或取消本批次,还原该任务已改动的代码后,用单任务宿主 cm-ai-host.mjs 以 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做该任务。`});
|
|
32
|
+
}
|
|
18
33
|
export function createCmAiBatch({configuration,executionFor,logHome,runtime='codex',checkCommands=null,checkTimeoutMs=60000,
|
|
19
|
-
rerunUnknownQa=false,rerunBlockedQa=false}){
|
|
34
|
+
rerunUnknownQa=false,rerunBlockedQa=false,holdRevisions=[]}){
|
|
20
35
|
const config=json(configuration);
|
|
21
36
|
shape(config,['version','repositoryId','batchId','specsDir','codeProject','tasks',...['codeProjects','parallel'].filter(name=>Object.hasOwn(config,name))]);
|
|
22
37
|
need(config.version===1);id(config.repositoryId);id(config.batchId);need(config.batchId.length>=8);
|
|
@@ -28,11 +43,14 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
28
43
|
shape(task,['feature','taskId','scope','requirements']);
|
|
29
44
|
need(!plans.has(key(task)));const definition=validateRunDefinition({version:1,
|
|
30
45
|
specsDir:config.specsDir,codeProject:config.codeProject,...(config.codeProjects?{codeProjects:config.codeProjects}:{}),feature:task.feature,
|
|
31
|
-
identity:{repositoryId:config.repositoryId,runId
|
|
46
|
+
identity:{repositoryId:config.repositoryId,runId:batchTaskRunId(config.batchId,key(task)),
|
|
32
47
|
taskId:task.taskId,attempt:1},scope:task.scope,requirements:task.requirements});
|
|
33
48
|
need(definition.specsDir===config.specsDir&&definition.codeProject===config.codeProject,'invalid_path');
|
|
34
49
|
plans.set(key(task),definition);
|
|
35
50
|
}
|
|
51
|
+
// Tasks whose second-round answer is not written yet stop after a changes_requested review.
|
|
52
|
+
need(Array.isArray(holdRevisions)&&holdRevisions.every(item=>plans.has(item)),'invalid_input');
|
|
53
|
+
const held=new Set(holdRevisions);
|
|
36
54
|
const groups=validateGroups(config,plans),membership=new Map(groups.flatMap(group=>group.map(key=>[key,group])));
|
|
37
55
|
const originalMembership=new Map(membership),originalPlans=new Map(plans);
|
|
38
56
|
const first=plans.keys().next().value,planDigest=digest(config),log=path.join(config.specsDir,'运行日志.jsonl');
|
|
@@ -91,8 +109,10 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
91
109
|
// only the tasks the flag can legally apply to receive it.
|
|
92
110
|
const recovery=mode==='resume'&&execution?.qaExecutor&&(rerunUnknownQa||rerunBlockedQa)
|
|
93
111
|
? {rerunUnknownQa,rerunBlockedQa} : {};
|
|
94
|
-
|
|
112
|
+
const run=await openControlRun(definition,mode,execution,{...recovery,...(held.has(taskKey)?{holdRevision:true}:{}),
|
|
95
113
|
...(membership.has(taskKey)?{parallelSelection:{version:1,group:membership.get(taskKey).map(key=>plans.get(key).identity.taskId)}}:{})});
|
|
114
|
+
if(!run.host)return run;
|
|
115
|
+
return {...run,host:{...run.host,handle:async request=>batchMemberResult(await run.host.handle(request),{parallel:membership.has(taskKey)})}};
|
|
96
116
|
}
|
|
97
117
|
function parallelProgress(rows){
|
|
98
118
|
const done=new Set(),ready=new Map(),merging=new Map(),blocked=new Map();let stopped=false,code=null;
|
|
@@ -198,9 +218,10 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
198
218
|
if(status.code===null&&['ready','changes_requested'].includes(status.state)
|
|
199
219
|
||developmentRetryable(status))await call('start');
|
|
200
220
|
if(['reported','advanced'].includes(status.outcome)&&(status.code===null&&status.state==='awaiting_review'
|
|
201
|
-
||status
|
|
221
|
+
||reviewRetryable(status)))await call('decision');
|
|
202
222
|
if(status.outcome==='advanced'&&status.code===null&&status.state==='changes_requested'&&status.identity.attempt===round+1)continue;
|
|
203
|
-
if(['reported','advanced'].includes(status.outcome)
|
|
223
|
+
if(['reported','advanced'].includes(status.outcome)
|
|
224
|
+
&&(status.code===null&&status.state==='approved'||completionRetryable(status))){
|
|
204
225
|
const completion=completeTail.then(()=>call('complete'));
|
|
205
226
|
completeTail=completion.then(()=>{},()=>{});await completion;
|
|
206
227
|
}
|
|
@@ -303,8 +324,8 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
303
324
|
// Retryable validation, review transport and completed-task QA stay on
|
|
304
325
|
// their existing recovery path; a new run must not bypass those gates.
|
|
305
326
|
const terminal=['blocked','failed','unknown'].includes(status.state)
|
|
306
|
-
|
|
307
|
-
||status.state==='pending_review'&&status.code!==null
|
|
327
|
+
&&!developmentRetryable(status)&&!completionRetryable(status)
|
|
328
|
+
||status.state==='pending_review'&&status.code!==null&&!reviewRetryable(status);
|
|
308
329
|
if(!terminal){waiting??=status;continue;}
|
|
309
330
|
const key=pending[index];
|
|
310
331
|
record('batch_member_blocked',{from_key:key,code:status.code??status.state,
|
|
@@ -427,7 +448,8 @@ export function taskCommitArgs(taskId,description,blockedCode=null,blockedReason
|
|
|
427
448
|
return ['-m',subject,'-m',description+(blockedCode!==null&&blockedReason!==null?`\n\n${blockedReason}`:'')];
|
|
428
449
|
}
|
|
429
450
|
function taskDescription(config,definition){
|
|
430
|
-
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(config.specsDir,definition.feature,'tasks.md'),'utf8'),
|
|
451
|
+
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(config.specsDir,definition.feature,'tasks.md'),'utf8'),
|
|
452
|
+
{allowDependencyPunctuation:true,grammar:approvedTaskGrammar(config.specsDir)});
|
|
431
453
|
need(!parsed.error,'parallel_task_invalid');return parsed.tasks.find(task=>task.id===definition.identity.taskId)?.description??definition.identity.taskId;
|
|
432
454
|
}
|
|
433
455
|
function validateGroups(config,plans){
|
|
@@ -437,7 +459,8 @@ function validateGroups(config,plans){
|
|
|
437
459
|
need(group.every(key=>plans.has(key)&&!used.has(key))&&new Set(group).size===group.length,'invalid_parallel_group');
|
|
438
460
|
const feature=plans.get(group[0]).feature;
|
|
439
461
|
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'),
|
|
462
|
+
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(config.specsDir,feature,'tasks.md'),'utf8'),
|
|
463
|
+
{allowDependencyPunctuation:true,grammar:approvedTaskGrammar(config.specsDir)});
|
|
441
464
|
need(!parsed.error,'parallel_task_invalid');
|
|
442
465
|
const ids=new Set(group.map(key=>plans.get(key).identity.taskId));
|
|
443
466
|
need([...ids].every(id=>parsed.tasks.some(task=>task.id===id&&!task.dropped)),'parallel_task_invalid');
|
|
@@ -18,6 +18,8 @@ test(`real multi-task runner keeps QA and recovery authoritative: ${mode}`,()=>b
|
|
|
18
18
|
|
|
19
19
|
for(const mode of ['parallel','parallel-retry','parallel-conflict','parallel-resume'])
|
|
20
20
|
test(`parallel batch runs real isolated members: ${mode}`,()=>batchFixture(mode));
|
|
21
|
+
test('A4 parallel member retries changed completion checks in its original run',()=>batchFixture('parallel-completion-retry'));
|
|
22
|
+
test('D1 parallel member retries failed develop checks before review',()=>batchFixture('parallel-develop-check-retry'));
|
|
21
23
|
|
|
22
24
|
test('ready member merges before blocked member preserves reason in log and WIP and falls back only once',async()=>{
|
|
23
25
|
for(const withReason of [true,false])await batchFixture('parallel-recovery',{terminalAgain:true,withReason});
|
|
@@ -27,6 +29,8 @@ test('serial fallback resumes from log and automatically commits its completed t
|
|
|
27
29
|
{blockedIds:['T-001']},{blockedIds:['T-001','T-002']}])await batchFixture('parallel-recovery',options);
|
|
28
30
|
});
|
|
29
31
|
test('final serial task commits durably and commit information survives resume',()=>batchFixture('final-commit'));
|
|
32
|
+
test('a batch member whose reviewer failed without a verdict resumes its one review retry',()=>batchFixture('review-provider-retry'));
|
|
33
|
+
test('a parallel member whose reviewer failed without a verdict resumes its one review retry',()=>batchFixture('parallel-review-provider-retry'));
|
|
30
34
|
test('dirty batch entry lists files and creates no member worktrees',()=>batchFixture('parallel-dirty'));
|
|
31
35
|
|
|
32
36
|
test('parallel groups reject transitive prerequisites, not just direct edges',()=>{
|
|
@@ -95,14 +99,14 @@ async function batchFixture(mode,options={}){
|
|
|
95
99
|
const config={version:1,repositoryId:'batch-fixture',batchId:'batch-fixture',specsDir,codeProject,
|
|
96
100
|
...(parallel?{parallel:[[`${feature}/T-001`,`${feature}/T-002`]]}:{}),
|
|
97
101
|
tasks:(parallel?['T-001','T-002','T-003']:['T-001','T-002']).map((taskId,index)=>({feature,taskId,scope:[`file${index}.js`],requirements:['requirements.md']}))};
|
|
98
|
-
const calls=[],qaCalls=[],assessments=[],blockedEvidence=[];let qaReady=mode!=='qa-resume',started;
|
|
102
|
+
const calls=[],qaCalls=[],assessments=[],blockedEvidence=[],checkCalls=new Map();let qaReady=mode!=='qa-resume',started;
|
|
99
103
|
const began=new Promise(resolve=>{started=resolve;});
|
|
100
|
-
let conflictHead=null,interrupted=false;
|
|
104
|
+
let conflictHead=null,interrupted=false,reviewFailed=false;
|
|
101
105
|
const executionFor=async(definition,{parallelMember=false}={})=>({configuration:{kind:'batch-fixture-v1',...(parallelMember?{parallelMember:true}:{})},timeoutMs:3000,
|
|
102
106
|
excludedContexts:['host'],hostDecision:{status:'approved'},applicableAgentFiles:[],
|
|
103
107
|
developer:{provider:'codex',requestedModel:'fixture',contextId:'author',run:createCodexDeveloperRun({requestedModel:'fixture',
|
|
104
108
|
worker:async({prompt},{signal})=>{
|
|
105
|
-
const
|
|
109
|
+
const data=JSON.parse(prompt.split('<cm-developer-data-json>\n')[1]),material=data.specification;
|
|
106
110
|
assert.equal(material.task.id,definition.identity.taskId);
|
|
107
111
|
assert.deepEqual(material.sources,buildManifest(specsDir));
|
|
108
112
|
if(recovery&&!parallelMember&&blockedIds.includes(definition.identity.taskId)){
|
|
@@ -124,7 +128,9 @@ async function batchFixture(mode,options={}){
|
|
|
124
128
|
assert.equal(fs.readFileSync(path.join(codeProject,config.tasks.find(task=>task.taskId===id).scope[0]),'utf8'),'implemented\n');
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
|
-
|
|
131
|
+
// A second attempt must change the rejected bytes (develop_unchanged_after_review).
|
|
132
|
+
calls.push(definition.identity.taskId);fs.writeFileSync(path.join(definition.codeProject,definition.scope[0]),
|
|
133
|
+
data.identity.attempt===1?'implemented\n':'implemented again\n');
|
|
128
134
|
if(recovery&&blockedIds.includes(definition.identity.taskId)&&(parallelMember||options.terminalAgain))
|
|
129
135
|
return {status:'succeeded',value:{outcome:'blocked',...(options.withReason?{reason:'Expected stub throws; waiting for peer'}:{})}};
|
|
130
136
|
if(parallel&&definition.identity.taskId==='T-002')await new Promise(resolve=>setTimeout(resolve,50));
|
|
@@ -145,13 +151,26 @@ async function batchFixture(mode,options={}){
|
|
|
145
151
|
}
|
|
146
152
|
return {status:'succeeded',value:{outcome:'implemented',application,retrospective}};
|
|
147
153
|
}})},
|
|
148
|
-
check:async()=>
|
|
154
|
+
check:async()=>{
|
|
155
|
+
const key=definition.identity.taskId,count=(checkCalls.get(key)??0)+1;checkCalls.set(key,count);
|
|
156
|
+
const failed=parallelMember&&key==='T-002'
|
|
157
|
+
&&(mode==='parallel-completion-retry'&&count===2||mode==='parallel-develop-check-retry'&&count===1);
|
|
158
|
+
return [{id:'fixture',command:['fixture'],outcome:failed?'failed':'passed',exitCode:failed?1:0,
|
|
159
|
+
evidence:failed?'Synthetic transient failure':'Synthetic task check'}];
|
|
160
|
+
},
|
|
149
161
|
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',allowed:true,available:true,
|
|
150
162
|
contexts:['review-1','review-2'],run:(request,{onEvent})=>{
|
|
151
163
|
assert.equal(request.payload.reviewPackage.specification.task.id,definition.identity.taskId);
|
|
152
164
|
assert.deepEqual(request.payload.reviewPackage.specification.sources,buildManifest(specsDir));
|
|
153
165
|
if(mode==='learning'&&request.identity.taskId==='T-001')
|
|
154
166
|
assert(request.payload.reviewPackage.changes.some(change=>change.path==='AGENTS.md'));
|
|
167
|
+
if(mode.endsWith('review-provider-retry')&&request.identity.taskId==='T-001'&&!reviewFailed){
|
|
168
|
+
reviewFailed=true;
|
|
169
|
+
// Claude CLI rate limit: no tool call, no verdict, process exited.
|
|
170
|
+
for(const event of [{event:'thread.started',provider_thread:'review-rate-limited'},{event:'turn.started',item_type:null},
|
|
171
|
+
{event:'process_closed',exit_code:1,signal:null,timed_out:false}])onEvent(event);
|
|
172
|
+
return {status:'failed',code:'reviewer_rate_limited'};
|
|
173
|
+
}
|
|
155
174
|
for(const event of [{event:'thread.started',provider_thread:`review-${request.identity.taskId}`},
|
|
156
175
|
{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},
|
|
157
176
|
{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
@@ -237,6 +256,33 @@ async function batchFixture(mode,options={}){
|
|
|
237
256
|
const recovered=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
238
257
|
assert.equal(recovered.find(row=>row.phase==='batch_handoff').task_commit,commit.task_commit);
|
|
239
258
|
}
|
|
259
|
+
if(mode==='parallel-completion-retry'){
|
|
260
|
+
assert.equal(result.code,'completion_checks_changed',JSON.stringify(result));
|
|
261
|
+
const logfile=path.join(specsDir,'运行日志.jsonl');
|
|
262
|
+
let rows=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
263
|
+
assert.equal(rows.filter(row=>row.phase==='batch_member_blocked').length,0);
|
|
264
|
+
assert(fs.existsSync(path.join(root,'.cm-worktrees',config.batchId.slice(0,8),'T-002')));
|
|
265
|
+
result=await open().handle({operation:'advance',requestId:'retry-completion'});
|
|
266
|
+
assert.equal(result.code,'run_done',JSON.stringify(result));
|
|
267
|
+
rows=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
268
|
+
assert.equal(rows.filter(row=>row.phase==='batch_member_blocked').length,0);
|
|
269
|
+
assert.equal(checkCalls.get('T-002'),3);
|
|
270
|
+
assert.deepEqual(calls,['T-001','T-002','T-003']);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if(mode==='parallel-develop-check-retry'){
|
|
274
|
+
assert.equal(result.code,'develop_checks_not_passed',JSON.stringify(result));
|
|
275
|
+
const logfile=path.join(specsDir,'运行日志.jsonl');
|
|
276
|
+
let rows=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
277
|
+
assert.equal(rows.filter(row=>row.phase==='batch_member_blocked').length,0);
|
|
278
|
+
result=await open().handle({operation:'advance',requestId:'retry-develop-check'});
|
|
279
|
+
assert.equal(result.code,'run_done',JSON.stringify(result));
|
|
280
|
+
rows=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
281
|
+
assert.equal(rows.filter(row=>row.phase==='batch_member_blocked').length,0);
|
|
282
|
+
assert.equal(checkCalls.get('T-002'),3);
|
|
283
|
+
assert.equal(calls.filter(task=>task==='T-002').length,2);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
240
286
|
if(recovery&&options.crashAt){assert(interrupted);result=await open().handle({operation:'advance',requestId:'resume-recovery'});}
|
|
241
287
|
if(recovery){
|
|
242
288
|
// Assert outside the worker: worker exceptions intentionally become unknown terminals.
|
|
@@ -277,6 +323,11 @@ async function batchFixture(mode,options={}){
|
|
|
277
323
|
for(const task of ['T-001','T-002'])assert.throws(()=>git(codeProject,['rev-parse','--verify',`refs/heads/cm/work/${task}`]));
|
|
278
324
|
return;
|
|
279
325
|
}
|
|
326
|
+
if(mode.endsWith('review-provider-retry')){
|
|
327
|
+
assert.equal(result.state,'pending_review',JSON.stringify(result));assert.equal(result.code,'review_provider_failed');
|
|
328
|
+
assert.match(result.reason,/^reviewer_rate_limited: /);assert.deepEqual(calls,parallel?['T-001','T-002']:['T-001']);
|
|
329
|
+
result=await open().handle({operation:'advance',requestId:'retry-review'});
|
|
330
|
+
}
|
|
280
331
|
if(mode==='qa-resume'){
|
|
281
332
|
assert.equal(result.code,'qa_decision_required');assert.deepEqual(calls,['T-001']);
|
|
282
333
|
assert(fs.readFileSync(path.join(specsDir,feature,'tasks.md'),'utf8').includes('[x] T-001'));
|
|
@@ -0,0 +1,45 @@
|
|
|
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 {buildManifest} from './cm-spec-manifest.mjs';
|
|
7
|
+
import {bootstrapDriverGap} from './cm-ai-drive.mjs';
|
|
8
|
+
import {hostResponseFailed} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
9
|
+
|
|
10
|
+
function fixture(t){
|
|
11
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-bootstrap-drive-')));
|
|
12
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
13
|
+
const specsDir=path.join(root,'specs5'),codeProject=path.join(root,'app'),feature='1.bootstrap';
|
|
14
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
15
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'# iOS SwiftUI scaffold and rules\n');
|
|
16
|
+
fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Split specs5/app roots\n');
|
|
17
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [x] T-001: 生成项目骨架 scaffold\n- [ ] T-002: 生成 AGENTS.md 和 .claude/ 规范(cm-init)\n');
|
|
18
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
19
|
+
const configuration=path.join(root,'bootstrap.json');
|
|
20
|
+
fs.writeFileSync(configuration,JSON.stringify({selection:{versionControl:'local',modules:[],analysis:'SwiftUI iOS app'}}));
|
|
21
|
+
const definition={specsDir,codeProject,feature,identity:{repositoryId:'app',runId:'t002',taskId:'T-002',attempt:1},
|
|
22
|
+
scope:['AGENTS.md','.claude/CLAUDE.md','.claude/rules/coding-style.md','.claude/rules/testing.md',
|
|
23
|
+
'.claude/rules/security.md','.claude/rules/git-workflow.md']};
|
|
24
|
+
return {configuration,definition};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
test('rules bootstrap is driver-supported for a pure rules scope on first and second attempt',t=>{
|
|
28
|
+
const f=fixture(t),permissions=['--bootstrap-config',f.configuration,'--allow-bootstrap-write'];
|
|
29
|
+
for(const attempt of [1,2])for(const operation of ['advance','start','resume'])
|
|
30
|
+
assert.equal(bootstrapDriverGap(operation,{...f.definition,identity:{...f.definition.identity,attempt}},permissions),null);
|
|
31
|
+
const provider=bootstrapDriverGap('advance',f.definition,[...permissions,'--protected-config','protected.json']);
|
|
32
|
+
assert.match(provider,/--protected-config/);assert.match(provider,/cm-ai-host\.mjs serve/);
|
|
33
|
+
assert.equal(bootstrapDriverGap('advance',{...f.definition,identity:{...f.definition.identity,taskId:'T-001'}},permissions),null);
|
|
34
|
+
assert.equal(bootstrapDriverGap('advance',f.definition,[]),null);
|
|
35
|
+
assert.equal(bootstrapDriverGap('status',f.definition,permissions),null);
|
|
36
|
+
assert.match(bootstrapDriverGap('advance',{...f.definition,identity:{...f.definition.identity,taskId:'T-999'}},permissions),/预检失败.*宿主未启动/);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('unknown and reconcile host responses are failures even when a result is returned',()=>{
|
|
40
|
+
assert.equal(hostResponseFailed({result:{state:'unknown',code:'execution_error',pendingAction:'reconcile'}}),true);
|
|
41
|
+
assert.equal(hostResponseFailed({result:{state:'unknown',code:'execution_error',pendingAction:null}}),true);
|
|
42
|
+
assert.equal(hostResponseFailed({result:{state:'blocked',pendingAction:'reconcile'}}),true);
|
|
43
|
+
assert.equal(hostResponseFailed({result:{state:'awaiting_review',pendingAction:'decision'}}),false);
|
|
44
|
+
assert.equal(hostResponseFailed({error:{code:'invalid_input'}}),true);
|
|
45
|
+
});
|