@aibyzero/cm-workflow 0.16.7 → 0.16.9

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.
Files changed (182) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +37 -0
  3. package/README.md +39 -3
  4. package/VERSION +1 -1
  5. package/assets/readme/workflow-recovery-detailed.png +0 -0
  6. package/assets/readme/workflow-stages-detailed.png +0 -0
  7. package/compat/claude-commands/cm-notify.md +3 -0
  8. package/docs/installation.md +1 -1
  9. package/docs/js-workflow-control.md +61 -4
  10. package/docs/next-steps.md +8 -2
  11. package/docs/user-guide.md +204 -0
  12. package/package.json +2 -1
  13. package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
  14. package/runtime/js/cm-ai/cm-ai-admission.mjs +3 -1
  15. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +138 -26
  16. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +142 -21
  17. package/runtime/js/cm-ai/code-projects.mjs +4 -1
  18. package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -1
  19. package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
  20. package/runtime/js/cm-ai/drive-core.mjs +26 -4
  21. package/runtime/js/cm-ai/durable-runner-state.mjs +951 -43
  22. package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
  23. package/runtime/js/cm-ai/effect-contract.mjs +6 -1
  24. package/runtime/js/cm-ai/execution-store.mjs +4 -2
  25. package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
  26. package/runtime/js/cm-ai/host-check.mjs +4 -1
  27. package/runtime/js/cm-ai/host-conversation-execution.mjs +11 -4
  28. package/runtime/js/cm-ai/host-documentation.mjs +53 -12
  29. package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
  30. package/runtime/js/cm-ai/host-qa-executor.mjs +86 -17
  31. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +44 -9
  32. package/runtime/js/cm-ai/host-session.mjs +47 -7
  33. package/runtime/js/cm-ai/host-tool-bridge.mjs +55 -6
  34. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +4 -2
  35. package/runtime/js/cm-ai/operator-guidance.mjs +112 -3
  36. package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
  37. package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
  38. package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
  39. package/runtime/js/cm-ai/review-dispatch-limits.mjs +18 -0
  40. package/runtime/js/cm-ai/review-package.mjs +10 -1
  41. package/runtime/js/cm-ai/reviewed-deliveries.mjs +29 -6
  42. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
  43. package/runtime/js/cm-ai/task-commit.mjs +39 -0
  44. package/runtime/js/cm-ai/task-runner.mjs +636 -65
  45. package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
  46. package/runtime/js/cm-ai/worker-claude.mjs +10 -3
  47. package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
  48. package/runtime/js/cm-fix/cause-package.mjs +37 -8
  49. package/runtime/js/cm-fix/diagnosis.mjs +43 -0
  50. package/runtime/js/cm-fix/execution.mjs +356 -187
  51. package/runtime/js/cm-fix/host.mjs +2 -1
  52. package/runtime/js/cm-fix/investigation.mjs +25 -9
  53. package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
  54. package/runtime/js/cm-fix/progress.mjs +15 -3
  55. package/runtime/js/cm-fix/protected-edits.mjs +10 -3
  56. package/runtime/js/cm-fix/repair.mjs +11 -3
  57. package/runtime/js/cm-fix/test-author.mjs +10 -3
  58. package/runtime/js/cm-idea/session.mjs +67 -4
  59. package/runtime/js/cm-prd/review-correction.mjs +10 -4
  60. package/runtime/js/cm-prd/session.mjs +43 -0
  61. package/runtime/js/cm-refactor/records.mjs +98 -8
  62. package/runtime/js/cm-refactor/workflow.mjs +79 -9
  63. package/runtime/js/cm-test/host.mjs +10 -3
  64. package/runtime/js/cm-test/session.mjs +45 -6
  65. package/runtime/js/notify-run.mjs +26 -0
  66. package/runtime/js/notify-safe-read.mjs +49 -0
  67. package/runtime/js/notify-send.mjs +312 -0
  68. package/runtime/js/notify.mjs +492 -0
  69. package/runtime/js/policy-binding-compat.mjs +54 -0
  70. package/runtime/model-efficiency.md +17 -0
  71. package/scripts/ci-test-shards.mjs +67 -0
  72. package/scripts/ci-test-shards.test.mjs +64 -0
  73. package/scripts/ci-test-weights.json +222 -0
  74. package/scripts/cm-ai-abandon-effect-position.test.mjs +70 -2
  75. package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
  76. package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
  77. package/scripts/cm-ai-answer-gap-fixture.mjs +96 -0
  78. package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
  79. package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
  80. package/scripts/cm-ai-batch-drive.mjs +55 -10
  81. package/scripts/cm-ai-batch-drive.test.mjs +65 -0
  82. package/scripts/cm-ai-batch-host.mjs +132 -13
  83. package/scripts/cm-ai-batch-host.test.mjs +255 -7
  84. package/scripts/cm-ai-batch-run-fixture.mjs +499 -0
  85. package/scripts/cm-ai-batch-run-member-stops.test.mjs +38 -0
  86. package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
  87. package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
  88. package/scripts/cm-ai-batch-run.mjs +189 -22
  89. package/scripts/cm-ai-batch-run.test.mjs +22 -334
  90. package/scripts/cm-ai-develop-answer-invalid.test.mjs +104 -0
  91. package/scripts/cm-ai-develop-call-timeout.test.mjs +153 -0
  92. package/scripts/cm-ai-develop-driver-gaps.test.mjs +4 -3
  93. package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
  94. package/scripts/cm-ai-drive.mjs +68 -23
  95. package/scripts/cm-ai-drive.test.mjs +37 -2
  96. package/scripts/cm-ai-fix-run-delivery.test.mjs +138 -0
  97. package/scripts/cm-ai-host-cli-workflow.test.mjs +271 -0
  98. package/scripts/cm-ai-host-fixture.mjs +268 -0
  99. package/scripts/cm-ai-host-protected.test.mjs +251 -0
  100. package/scripts/cm-ai-host.mjs +28 -16
  101. package/scripts/cm-ai-host.test.mjs +17 -759
  102. package/scripts/cm-ai-light-modules.test.mjs +57 -0
  103. package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
  104. package/scripts/cm-ai-project-qa-gate.test.mjs +71 -4
  105. package/scripts/cm-ai-protected-scope.test.mjs +7 -3
  106. package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
  107. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +78 -11
  108. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +127 -8
  109. package/scripts/cm-ai-review-dispatch-exit.test.mjs +475 -0
  110. package/scripts/cm-ai-review-failure.test.mjs +124 -13
  111. package/scripts/cm-ai-review-timeout.test.mjs +188 -10
  112. package/scripts/cm-ai-run.mjs +15 -6
  113. package/scripts/cm-ai-supersede.test.mjs +486 -41
  114. package/scripts/cm-check-drive-files.mjs +8 -0
  115. package/scripts/cm-check-drive.test.mjs +2 -5
  116. package/scripts/cm-check-runtime.sh +4 -2
  117. package/scripts/cm-claude-developer-worker.test.mjs +15 -0
  118. package/scripts/cm-claude-review-stream.test.mjs +21 -16
  119. package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
  120. package/scripts/cm-claude-worker.test.mjs +18 -2
  121. package/scripts/cm-external-model-recovery.test.mjs +29 -3
  122. package/scripts/cm-fix-abandon.test.mjs +249 -10
  123. package/scripts/cm-fix-cause-package.test.mjs +33 -0
  124. package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
  125. package/scripts/cm-fix-drive.mjs +34 -8
  126. package/scripts/cm-fix-host.mjs +8 -7
  127. package/scripts/cm-fix-rediagnosis.test.mjs +71 -4
  128. package/scripts/cm-fix-review-budget.test.mjs +13 -0
  129. package/scripts/cm-fix-review-recovery.test.mjs +35 -0
  130. package/scripts/cm-host-answer-timeout.test.mjs +65 -0
  131. package/scripts/cm-host-call-kinds.test.mjs +28 -0
  132. package/scripts/cm-host-documentation.test.mjs +49 -0
  133. package/scripts/cm-host-qa-executor.test.mjs +143 -10
  134. package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
  135. package/scripts/cm-idea-drive.mjs +49 -11
  136. package/scripts/cm-idea-drive.test.mjs +66 -0
  137. package/scripts/cm-idea-host.mjs +106 -16
  138. package/scripts/cm-init-answer-gaps.test.mjs +258 -0
  139. package/scripts/cm-init-drive.mjs +41 -7
  140. package/scripts/cm-init-host.mjs +61 -12
  141. package/scripts/cm-log-event.mjs +49 -12
  142. package/scripts/cm-notify-command.test.mjs +900 -0
  143. package/scripts/cm-notify-read-drift.test.mjs +205 -0
  144. package/scripts/cm-notify.mjs +469 -0
  145. package/scripts/cm-notify.test.mjs +685 -0
  146. package/scripts/cm-patrol.mjs +83 -0
  147. package/scripts/cm-patrol.test.mjs +161 -0
  148. package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
  149. package/scripts/cm-prd-drive.mjs +18 -5
  150. package/scripts/cm-prd-drive.test.mjs +15 -0
  151. package/scripts/cm-prd-host.mjs +37 -4
  152. package/scripts/cm-prd-review-disposition.test.mjs +6 -1
  153. package/scripts/cm-prd-review-gate.mjs +56 -0
  154. package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
  155. package/scripts/cm-refactor-drive.mjs +52 -8
  156. package/scripts/cm-refactor-drive.test.mjs +44 -0
  157. package/scripts/cm-refactor-host.test.mjs +10 -6
  158. package/scripts/cm-release-smoke.sh +2 -0
  159. package/scripts/cm-test-answer-gaps.test.mjs +151 -0
  160. package/scripts/cm-test-drive.mjs +21 -5
  161. package/scripts/cm-token-report.mjs +497 -0
  162. package/scripts/cm-token-report.test.mjs +346 -0
  163. package/scripts/fixtures/claude-review-process.mjs +1 -1
  164. package/scripts/policy-binding-compat.test.mjs +99 -0
  165. package/scripts/scan-public-safety.py +4 -0
  166. package/scripts/validate-public-repo.py +4 -0
  167. package/skills/cm-ai/SKILL.md +7 -3
  168. package/skills/cm-ai/references/N6-qa-eval.md +2 -2
  169. package/skills/cm-ai/references/js-host-modes.md +90 -0
  170. package/skills/cm-ai/references/js-host-qa-recovery.md +136 -0
  171. package/skills/cm-ai/references/js-host-recovery.md +311 -0
  172. package/skills/cm-ai/references/js-host.md +76 -331
  173. package/skills/cm-check/SKILL.md +3 -3
  174. package/skills/cm-fix/SKILL.md +2 -0
  175. package/skills/cm-fix/references/js-host.md +56 -10
  176. package/skills/cm-idea/references/js-host.md +27 -2
  177. package/skills/cm-init/references/js-host.md +16 -3
  178. package/skills/cm-notify/SKILL.md +34 -0
  179. package/skills/cm-prd/SKILL.md +2 -0
  180. package/skills/cm-prd/references/js-change-recovery.md +35 -1
  181. package/skills/cm-refactor/references/js-host.md +17 -0
  182. package/skills/cm-test/references/js-host.md +14 -1
@@ -0,0 +1,70 @@
1
+ // V3 (P1-1): the developer call succeeded and its delivery is on disk, but the
2
+ // later task check (or the completion re-check) never got a usable answer. The
3
+ // run shows a retryable block; advance journals develop-recheck/complete-recheck
4
+ // and re-runs only those steps. The developer is never dispatched again.
5
+ import test from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+ import {readRunnerHistory,projectedRunnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
10
+ import {gapFixture,gapExecution,gapSession,records,added} from './cm-ai-answer-gap-fixture.mjs';
11
+
12
+ test('check_answer_missing: a timed-out check after a delivered develop re-runs only the checks, then complete_recheck_failed re-runs only completion',async t=>{
13
+ const f=gapFixture(t,'recheck');
14
+ // Round 1 delivers; its check never answers (the runner limit stops it).
15
+ const [stuck]=await gapSession(f,'create',gapExecution(f,{developer:['round-1\n'],checks:['hang']}),[['advance',1]]);
16
+ assert.deepEqual([stuck.state,stuck.code,stuck.pendingAction],['blocked','check_answer_missing','resume'],JSON.stringify(stuck));
17
+ assert.match(stuck.reason,/原记录 unknown\/call_timeout/);
18
+ assert.equal(stuck.guidance.recoveryOperation,'advance');assert.match(stuck.guidance.nextStep,/只重跑检查/);
19
+ const before=records(f),checkpoint=before.at(-1).payload.checkpoint;
20
+ // The journal keeps exactly what older runtimes wrote (real T-005/T-008 shape).
21
+ assert.deepEqual([checkpoint.state,checkpoint.code,checkpoint.calls.at(-1).terminal],['unknown','call_timeout','succeeded']);
22
+ assert.equal(readRunnerHistory(before,before[0].payload.config,3).state.state,'unknown');
23
+ assert.equal(f.calls.developer,1);
24
+ // Resume: re-check approves; then the completion re-check never answers.
25
+ const resumed=gapExecution(f,{checks:['ok','hang'],verdicts:['approved']});
26
+ const [status,advanced]=await gapSession(f,'resume',resumed,[['status',1],['advance',1]]);
27
+ assert.deepEqual([status.state,status.code,status.pendingAction],['blocked','check_answer_missing','resume']);
28
+ assert.equal(f.calls.developer,1,'the re-check never dispatches the developer');
29
+ assert.deepEqual([advanced.state,advanced.code,advanced.pendingAction],['blocked','complete_recheck_failed','complete'],JSON.stringify(advanced));
30
+ assert.equal(advanced.guidance.recoveryOperation,'complete');
31
+ const steps=added(f,before);
32
+ assert.deepEqual(steps.slice(0,3),['develop-recheck','intent:develop-1-retry-1','effect-checkpoint']);
33
+ assert.ok(steps.includes('intent:review-1')&&steps.includes('intent:complete-1'));
34
+ const after=records(f);assert.deepEqual(after.slice(0,before.length),before,'journal is append-only');
35
+ const rechecked=after[before.length+2].payload.checkpoint;
36
+ assert.equal(rechecked.state,'awaiting_review');assert.equal(rechecked.calls.length,1,'no new developer call');
37
+ assert.equal(Buffer.from(rechecked.reviewPackage.changes.find(c=>c.path==='a.mjs').after.contentBase64,'base64').toString(),'round-1\n');
38
+ // Re-checked completion: complete-recheck, then the run completes.
39
+ const middle=records(f);
40
+ const [done]=await gapSession(f,'resume',gapExecution(f,{checks:['ok']}),[['advance',1]]);
41
+ assert.deepEqual([done.state,done.pendingAction],['fixture_completed','qa'],JSON.stringify(done));
42
+ assert.deepEqual(added(f,middle).slice(0,2),['complete-recheck','intent:complete-1-retry-1']);
43
+ assert.match(fs.readFileSync(path.join(f.specsDir,f.feature,'tasks.md'),'utf8'),/\[x\] T-002/);
44
+ const final=readRunnerHistory(records(f),records(f)[0].payload.config,3);
45
+ assert.equal(final.state.state,'fixture_completed');
46
+ assert.deepEqual([final.answerGaps.developRecheck,final.answerGaps.completeRecheck],[1,1]);
47
+ assert.equal(final.state.receipts.length,1,'one review round');
48
+ });
49
+
50
+ test('check_answer_invalid: a malformed check answer is re-checked at most twice per run, then shows check_answer_retry_limit',async t=>{
51
+ const f=gapFixture(t,'invalid');
52
+ const [stuck]=await gapSession(f,'create',gapExecution(f,{developer:['round-1\n'],checks:['invalid']}),[['advance',1]]);
53
+ assert.deepEqual([stuck.state,stuck.code,stuck.pendingAction],['blocked','check_answer_invalid','resume'],JSON.stringify(stuck));
54
+ const [first]=await gapSession(f,'resume',gapExecution(f,{checks:['hang']}),[['advance',1]]);
55
+ assert.deepEqual([first.state,first.code],['blocked','check_answer_missing'],JSON.stringify(first));
56
+ const [second]=await gapSession(f,'resume',gapExecution(f,{checks:['invalid']}),[['advance',1]]);
57
+ // The cap is spent: an explicit limit block naming the exit that is left, not unknown/reconcile.
58
+ assert.deepEqual([second.state,second.code,second.pendingAction],['blocked','check_answer_retry_limit','none'],JSON.stringify(second));
59
+ assert.match(second.reason,/--supersede-reviewed-evidence/);assert.match(second.guidance.summary,/用满 2 次/);
60
+ // Replay shows the same block (journal only), and the journal keeps unknown/invalid_input.
61
+ const rows=records(f),replayed=projectedRunnerStatus(readRunnerHistory(rows,rows[0].payload.config,3),rows[0].payload.config);
62
+ assert.deepEqual([replayed.state,replayed.code],['blocked','check_answer_retry_limit']);
63
+ assert.deepEqual([rows.at(-1).payload.checkpoint.state,rows.at(-1).payload.checkpoint.code],['unknown','invalid_input']);
64
+ assert.equal(f.calls.developer,1);
65
+ const history=readRunnerHistory(records(f),records(f)[0].payload.config,3);
66
+ assert.equal(history.answerGaps.developRecheck,2);
67
+ // Effects and calls stay inside the run budget: the sources hold no slot.
68
+ assert.deepEqual(records(f).filter(row=>row.payload.type==='effect-intent').map(row=>row.payload.effect.id),
69
+ ['develop-1','develop-1-retry-1','develop-1-retry-2']);
70
+ });
@@ -0,0 +1,103 @@
1
+ // V2 + R3 (P1-2): a current-session develop whose answer never arrived (timed
2
+ // out after writing, disconnected) cannot be redispatched until the operator
3
+ // confirms the session stopped (develop_redo + reason, journaled). The redo
4
+ // keeps the edits on disk; the package is built against the task baseline and
5
+ // reviewed, so nothing written during the lost answer skips review.
6
+ import test from 'node:test';
7
+ import assert from 'node:assert/strict';
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+ import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
11
+ import {gapFixture,gapExecution,gapSession,records,added} from './cm-ai-answer-gap-fixture.mjs';
12
+
13
+ const hangAfterWrite={write:'half written\n',response:new Promise(()=>{})};
14
+
15
+ test('develop_answer_missing: a develop that timed out after writing waits for develop_redo, then redoes the round',async t=>{
16
+ const f=gapFixture(t,'redo');
17
+ const [stuck]=await gapSession(f,'create',gapExecution(f,{developer:[hangAfterWrite]}),[['advance',1]]);
18
+ assert.deepEqual([stuck.state,stuck.code,stuck.pendingAction],['blocked','develop_answer_missing','develop_redo'],JSON.stringify(stuck));
19
+ assert.match(stuck.reason,/代码根已变化/);assert.equal(stuck.guidance.recoveryOperation,'develop_redo');
20
+ const before=records(f);
21
+ // The journal is what older runtimes wrote: unknown/call_timeout.
22
+ assert.deepEqual([before.at(-1).payload.checkpoint.state,before.at(-1).payload.checkpoint.code],['unknown','call_timeout']);
23
+ // advance alone never redispatches; develop_redo needs its launch flag.
24
+ const [advanced,refused]=await gapSession(f,'resume',gapExecution(f),[['advance',1],['develop_redo',1,{reason:'会话已停止'}]]);
25
+ // advance reports the block without even trying a develop effect.
26
+ assert.deepEqual([advanced.outcome,advanced.code,advanced.pendingAction],['reported','develop_answer_missing','develop_redo'],JSON.stringify(advanced));
27
+ assert.equal(records(f).length,before.length);
28
+ assert.deepEqual([refused.outcome,refused.code],['rejected','develop_redo_authorization_required']);
29
+ // Confirmed: develop-answer-redo, then advance redoes the round with a new effect id.
30
+ const [confirmed,status]=await gapSession(f,'resume',gapExecution(f),
31
+ [['develop_redo',1,{reason:'会话已停止修改代码'}],['status',1]],{allowDevelopRedo:true});
32
+ assert.equal(confirmed.outcome,'recorded',JSON.stringify(confirmed));
33
+ assert.deepEqual([status.state,status.code,status.pendingAction],['blocked','develop_answer_missing','resume']);
34
+ assert.equal(f.calls.developer,1);
35
+ const redo=records(f).at(-1).payload;
36
+ assert.deepEqual([redo.type,redo.cause,redo.reason],['develop-answer-redo','call_timeout','会话已停止修改代码']);
37
+ const middle=records(f);
38
+ const [delivered]=await gapSession(f,'resume',gapExecution(f,{developer:['final\n'],verdicts:['approved']}),[['advance',1]]);
39
+ assert.equal(f.calls.developer,2);
40
+ assert.deepEqual(added(f,middle).slice(0,2),['intent:develop-1-retry-1','effect-checkpoint']);
41
+ assert.ok(added(f,middle).includes('intent:review-1'),JSON.stringify(delivered));
42
+ const checkpoint=records(f)[middle.length+1].payload.checkpoint;
43
+ assert.equal(checkpoint.state,'awaiting_review');
44
+ // Reviewed against the task baseline, not re-captured after the lost answer.
45
+ assert.equal(Buffer.from(checkpoint.reviewPackage.changes.find(c=>c.path==='a.mjs').before.contentBase64,'base64').toString(),'old\n');
46
+ const history=readRunnerHistory(records(f),records(f)[0].payload.config,3);
47
+ assert.equal(history.answerGaps.developRedo,1);
48
+ assert.deepEqual(records(f).slice(0,before.length),before,'journal is append-only');
49
+ });
50
+
51
+ test('develop_answer_missing: a disconnected develop (unknown/unknown) takes the same confirmed redo; the cap is two per run',async t=>{
52
+ const f=gapFixture(t,'disconnect');
53
+ const disconnect=write=>({write,throw:'host_disconnected'});
54
+ const [stuck]=await gapSession(f,'create',gapExecution(f,{developer:[disconnect('one\n')]}),[['advance',1]]);
55
+ assert.deepEqual([stuck.state,stuck.code,stuck.pendingAction],['blocked','develop_answer_missing','develop_redo'],JSON.stringify(stuck));
56
+ assert.deepEqual([records(f).at(-1).payload.checkpoint.state,records(f).at(-1).payload.checkpoint.code],['unknown','unknown']);
57
+ for(const [index,write] of ['two\n','three\n'].entries()){
58
+ const [ok]=await gapSession(f,'resume',gapExecution(f,{developer:[disconnect(write)]}),
59
+ [['develop_redo',1,{reason:`确认第 ${index+1} 次`}],['advance',1]],{allowDevelopRedo:true});
60
+ assert.equal(ok.outcome,'recorded');
61
+ }
62
+ // Two redos used: the third stuck develop has no redo exit left.
63
+ const [last,third]=await gapSession(f,'resume',gapExecution(f),[['status',1],['develop_redo',1,{reason:'第三次'}]],{allowDevelopRedo:true});
64
+ assert.deepEqual([third.outcome,third.code],['rejected','develop_redo_unavailable']);
65
+ assert.deepEqual([last.state,last.code,last.pendingAction],['blocked','develop_redo_limit','none'],JSON.stringify(last));
66
+ assert.match(last.reason,/--supersede-reviewed-evidence/);
67
+ assert.equal(fs.readFileSync(path.join(f.codeProject,'a.mjs'),'utf8'),'three\n');
68
+ assert.deepEqual(records(f).filter(row=>row.payload.type==='effect-intent').map(row=>row.payload.effect.id),
69
+ ['develop-1','develop-1-retry-1','develop-1-retry-2']);
70
+ });
71
+
72
+ test('develop_answer_missing: a bare failed answer (blocked/failed without a result) also needs develop_redo; the driver checks the plan',async t=>{
73
+ const f=gapFixture(t,'bare');
74
+ const [stuck]=await gapSession(f,'create',gapExecution(f,{developer:[{write:'tried\n',response:{status:'failed',code:'session_error'}}]}),[['advance',1]]);
75
+ assert.deepEqual([stuck.state,stuck.code,stuck.pendingAction],['blocked','develop_answer_missing','develop_redo'],JSON.stringify(stuck));
76
+ assert.match(stuck.reason,/只回了 failed/);
77
+ const {developRedoPlanError}=await import('./cm-ai-drive.mjs');
78
+ assert.equal(developRedoPlanError('develop_redo',{mode:'resume',reason:'已停'},['--allow-develop-redo']),null);
79
+ assert.match(developRedoPlanError('develop_redo',{mode:'resume',reason:'已停'},[]),/--allow-develop-redo/);
80
+ assert.match(developRedoPlanError('develop_redo',{mode:'create',reason:'已停'},['--allow-develop-redo']),/resume/);
81
+ });
82
+
83
+ test('develop_redo passes the shared JSONL transport (serveCmAiHost) and is journaled',async t=>{
84
+ const {PassThrough}=await import('node:stream');
85
+ const {serveCmAiHost}=await import('../runtime/js/cm-ai/host-session.mjs');
86
+ const {openControlRun}=await import('./cm-ai-run.mjs');
87
+ const {definition,identity}=await import('./cm-ai-answer-gap-fixture.mjs');
88
+ const f=gapFixture(t,'transport');
89
+ await gapSession(f,'create',gapExecution(f,{developer:[{write:'one\n',throw:'host_disconnected'}]}),[['advance',1]]);
90
+ const run=await openControlRun(definition(f),'resume',gapExecution(f),{allowDevelopRedo:true});
91
+ const input=new PassThrough(),output=new PassThrough(),errors=new PassThrough();let text='';
92
+ output.on('data',chunk=>{text+=chunk;});
93
+ try{
94
+ const served=serveCmAiHost({host:run.host,input,output,errorOutput:errors});
95
+ input.write(JSON.stringify({version:1,operation:'develop_redo',requestId:'redo-1',identity:identity(1),reason:'会话已停止修改代码'})+'\n');
96
+ input.end();await served;
97
+ }finally{run.close();}
98
+ const rows=text.trim().split('\n').map(line=>JSON.parse(line));
99
+ const reply=rows.find(row=>row.requestId==='redo-1');
100
+ assert.ok(reply&&!reply.error,text);
101
+ assert.deepEqual([reply.result.outcome,reply.result.code,reply.result.pendingAction],['recorded','develop_answer_missing','resume']);
102
+ assert.equal(records(f).at(-1).payload.type,'develop-answer-redo');
103
+ });
@@ -13,6 +13,8 @@
13
13
  // status/cancel -> none: batch-run.mjs handle routes only these and advance;
14
14
  // host-session.mjs operationNames admits all three. Other operationNames belong
15
15
  // to child/single-task hosts and are not batch operations.
16
+ // develop_redo/abandon_effect/abandon_review/bootstrap_review_recover -> none:
17
+ // batch-run.mjs memberAction forwards one to the stopped member's cm-ai entry (Q24).
16
18
  import {readBatchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
17
19
  import {readBatchExternalModels,batchModelsFile} from '../runtime/js/cm-ai/external-group-models.mjs';
18
20
  import {loadConfig,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
@@ -29,7 +31,7 @@ import {readConversationReviewConfiguration,readConversationProtection} from './
29
31
  import {validateCmAiAnswer,developFilename,preflightDevelopDeliveries,baselineScope,inputLimitFrom,
30
32
  applyDevelopEdits,protectedDevelopEdits,developPreview,plannedCheckResults,journalRestBytes} from './cm-ai-drive.mjs';
31
33
  import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
32
- import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
34
+ import {readRunnerHistory,projectedRunnerStatus,RECHECK_CODES,DOCUMENTATION_SYNC_CODES} from '../runtime/js/cm-ai/durable-runner-state.mjs';
33
35
  import {developmentRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
34
36
  import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost,planCheckTimeout} from '../runtime/js/cm-ai/drive-core.mjs';
35
37
 
@@ -39,15 +41,36 @@ import {driverLiveEvidence} from '../runtime/js/cm-ai/live-evidence.mjs';
39
41
  const HOST=fileURLToPath(new URL('./cm-ai-batch-host.mjs',import.meta.url));
40
42
  const KINDS={develop:'develop.json',qa_assess:'qa-assess.json',
41
43
  documentation_sync:'documentation-sync.json',documentation_inspect:'documentation-inspect.json'};
44
+ // Q24: per-member recovery grants (cm-ai-batch-host.mjs) and their batch operation.
45
+ const MEMBER_ACTION_FLAGS={develop_redo:'--allow-develop-redo',abandon_effect:'--allow-abandon-effect',
46
+ abandon_review:'--allow-abandon-review',bootstrap_review_recover:'--allow-bootstrap-review-recovery'};
42
47
  const PAIRS=new Set(['--external-models-config','--runtime','--review-config','--browser-qa','--protected-conversation-config',
43
- '--protected-config','--allow-provider-development','--allow-review','--input-limit']);
48
+ '--protected-config','--allow-provider-development','--allow-review','--input-limit','--qa-environment-failure',...Object.values(MEMBER_ACTION_FLAGS)]);
44
49
  const FLAGS=new Set(['--execution-optimizations','--external-models','--allow-qa','--rerun-unknown-qa','--rerun-blocked-qa','--verification-precheck',
45
50
  '--allow-bootstrap-write']);
46
51
  const isObject=x=>x!==null&&typeof x==='object'&&!Array.isArray(x);
47
52
  const nonempty=x=>typeof x==='string'&&x.trim().length>0;
48
53
  function taskKey(task){return `${task.feature}/${task.taskId}`;}
54
+ export function batchMemberActionPlanError(operation,plan,permissions,keys){
55
+ const flag=MEMBER_ACTION_FLAGS[operation];if(!flag)return null;
56
+ if(plan.mode!=='resume')return `${operation} 只用于 mode resume`;
57
+ if(!keys.includes(plan.taskKey))return `${operation} 需要 PLAN.taskKey 为本批次当前停住的成员 FEATURE/TASK`;
58
+ if(!(typeof plan.reason==='string'&&plan.reason.trim().length>0&&Buffer.byteLength(plan.reason,'utf8')<=500&&!/[\r\n\0]/.test(plan.reason)))
59
+ return `${operation} 需要单行 PLAN.reason(最多 500 UTF-8 字节)`;
60
+ if(!permissions.some((name,index)=>name===flag&&permissions[index+1]===plan.taskKey))return `${operation} 需要 permissions 中的 ${flag} ${plan.taskKey}`;
61
+ return null;
62
+ }
49
63
  export function batchDevelopAttempts(state,key,permissions){
50
- if(developmentRetryable(state))return [state.attempt];
64
+ // The round-1 review this launch authorizes may lead into round 2 within the
65
+ // same advance (Codex round 1 on Q28): list it too; a missing a2 answer then
66
+ // holds the task after that review (revision_answer_required) instead of
67
+ // sending an unanswerable develop request.
68
+ const reviewNext=state.attempt===1&&permissions.some((flag,index)=>flag==='--allow-review'&&permissions[index+1]===`${key}:1`);
69
+ // A re-check (check_answer_*) re-runs only the checks: no developer answer for this round.
70
+ if(state.state==='blocked'&&RECHECK_CODES.includes(state.code))return reviewNext?[2]:[];
71
+ // Q16/Q17: a documentation-only redo reuses the journaled developer answer.
72
+ if(state.state==='blocked'&&DOCUMENTATION_SYNC_CODES.includes(state.code))return reviewNext?[2]:[];
73
+ if(developmentRetryable(state))return reviewNext?[1,2]:[state.attempt];
51
74
  if(state.state==='ready'&&state.attempt===1&&permissions.some((flag,index)=>
52
75
  flag==='--allow-review'&&permissions[index+1]===`${key}:1`))return [1,2];
53
76
  if(['ready','changes_requested'].includes(state.state))return [state.attempt];
@@ -83,13 +106,13 @@ function checkCommandShape(commands,key,plan,executionPolicy){
83
106
  function preflight(){
84
107
  if(process.argv.length===3&&['--help','-h'].includes(process.argv[2])){
85
108
  process.stdout.write('用法: cm-ai-batch-drive.mjs --plan PLAN.json <operation>\n'
86
- +'operation: advance, status, cancel。PLAN: config, mode, hostContext, permissions, answers, checks, checkTimeoutMs。\n'
109
+ +'operation: advance, status, cancel, reconcile_review(taskKey、invocationId), develop_redo / abandon_effect / abandon_review / bootstrap_review_recover(resume、PLAN.taskKey、单行 PLAN.reason,permissions 带对应 --allow-… 任务)。PLAN: config, mode, hostContext, permissions, answers, checks, checkTimeoutMs。\n'
87
110
  +'checks 每项为 {id,command,timeoutMs?};超时为 1..3600000 整数,默认 900000 ms(15 分钟)。\n'
88
111
  +'develop.json.edits 与单任务驾驶员相同:内容文件、{file,mode}、{mode}、{delete:true};启动前同样拒绝超限、空交付与受保护模式下的非 UTF-8 内容(尚未开跑的后续任务不看代码树,只做答案本身就能判定的检查:单文件 1 MiB、答案写入的 scope 文件合计 2 MiB,等等;运行存档单条记录上限要看该任务开跑时的代码树,驾驶员事先算不出,超限交付写入后由宿主拦下,停在可重试的 blocked/develop_package_too_large)。\n'
89
112
  +'带 --allow-review 任务:1 但还没有 develop-a2.json 时照常启动:审查若要求修改,该任务停在 changes_requested(revision_answer_required),读 .reviews/<feature>-<task>-r1.md 的 findings 写好 develop-a2.json 后再 advance。\n');
90
113
  process.exit(0);
91
114
  }
92
- const loaded=loadPlanFile({name:'cm-ai-batch-drive.mjs',known:new Set(['advance','status','cancel','reconcile_review'])});
115
+ const loaded=loadPlanFile({name:'cm-ai-batch-drive.mjs',known:new Set(['advance','status','cancel','reconcile_review',...Object.keys(MEMBER_ACTION_FLAGS)])});
93
116
  const {plan,base,operation}=loaded;
94
117
  requireFields(plan,['config','mode','hostContext','permissions']);
95
118
  try{planCheckTimeout(plan);}catch(error){stop(2,error.message);}
@@ -135,6 +158,18 @@ function preflight(){
135
158
  logHome:path.join(batch.specsDir,'.reviews','host-log-mirror')});
136
159
  }catch(error){stop(2,`批次定义、scope 或 workflow 无效: ${error.code??error.message}${error.code==='protected_scope'&&typeof error.reason==='string'?`;${error.reason}`:''}`);}
137
160
  const log=path.join(batch.specsDir,'运行日志.jsonl');
161
+ // Members the batch already rescheduled into a serial second generation
162
+ // (batch_member_blocked). Their gen-2 run starts fresh at attempt 1.
163
+ const rescheduled=new Set(),handedOff=new Set();
164
+ if(fs.existsSync(log))for(const line of fs.readFileSync(log,'utf8').split('\n')){
165
+ if(!line.trim())continue;let row;try{row=JSON.parse(line);}catch{continue;}
166
+ if(row?.workflow==='cm-ai'&&row.event==='decision'&&row.phase==='batch_member_blocked'&&row.run_id===batch.batchId
167
+ &&row.generation===2&&typeof row.from_key==='string')rescheduled.add(row.from_key);
168
+ // A handed-off task never develops again; a merged parallel member's worktree is gone,
169
+ // so its journal cannot be replayed here (the batch host verifies it on its own).
170
+ if(row?.workflow==='cm-ai'&&row.event==='decision'&&row.phase==='batch_handoff'&&row.run_id===batch.batchId
171
+ &&typeof row.from_key==='string')handedOff.add(row.from_key);
172
+ }
138
173
  const stores=Array.from(definitions.values(),d=>path.join(batch.specsDir,'.reviews','.execution',d.identity.runId,'state.json'));
139
174
  const hasLog=fs.existsSync(log),hasStore=stores.some(file=>fs.existsSync(file));
140
175
  if(plan.mode==='resume'&&!hasLog&&!hasStore)
@@ -151,6 +186,7 @@ function preflight(){
151
186
  let externalModels;
152
187
  try{externalModels=readBatchExternalModels({batch,started:hasStore,enabled:permissions.includes('--external-models'),inputFile:argumentValue('--external-models-config'),providers:[routes.coderRuntime,routes.reviewerRuntime].filter(Boolean)});}catch(error){stop(2,error.code??'external_model_configuration_invalid');}
153
188
  if(operation==='reconcile_review'&&(plan.mode!=='resume'||!keys.includes(plan.taskKey)||!nonempty(plan.invocationId)))stop(2,'reconcile_review requires resume, taskKey and original invocationId');
189
+ const memberError=batchMemberActionPlanError(operation,plan,permissions,keys);if(memberError)stop(2,memberError);
154
190
  for(let i=0;i<permissions.length;i++)if(PAIRS.has(permissions[i])){
155
191
  const name=permissions[i],value=permissions[++i];
156
192
  if(['--review-config','--protected-conversation-config','--protected-config'].includes(name)){
@@ -168,6 +204,8 @@ function preflight(){
168
204
  }
169
205
  }catch(error){stop(2,`${name} 配置无效: ${file}: ${error.code??error.message}`);}
170
206
  permissions[i]=file;
207
+ }else if(Object.values(MEMBER_ACTION_FLAGS).includes(name)){
208
+ if(!keys.includes(value))stop(2,`${name} 需要本批次的 FEATURE/TASK: ${value}`);
171
209
  }else if(['--allow-review','--allow-provider-development'].includes(name)){
172
210
  const cut=value.lastIndexOf(':');
173
211
  if(!keys.includes(value.slice(0,cut))||!['1','2'].includes(value.slice(cut+1)))
@@ -209,7 +247,8 @@ function preflight(){
209
247
  if(workflow?.documentationPaths?.length)kinds.push('documentation_sync');
210
248
  }
211
249
  if(workflow?.qa){
212
- if(!batch.parallel?.some(group=>group.includes(key)))kinds.push('qa_assess');
250
+ // A rescheduled second generation runs serially and asks qa_assess like a serial task.
251
+ if(!batch.parallel?.some(group=>group.includes(key))||rescheduled.has(key))kinds.push('qa_assess');
213
252
  const cases=readJson(path.join(batch.specsDir,task.feature,'test-cases.json'),'test-cases');
214
253
  for(const kind of ['logic','browser'])if(cases?.cases?.some(item=>item.kind===kind))kinds.push(`qa_${kind}`);
215
254
  }
@@ -221,13 +260,18 @@ function preflight(){
221
260
  const perAttempt=new Map();
222
261
  if(kinds.includes('develop')){
223
262
  let attempts=[1],current=1,journal=null;
224
- if(plan.mode==='resume'){
263
+ if(plan.mode==='resume'&&handedOff.has(key)){attempts=[];journal={handedOff:true};}
264
+ else if(plan.mode==='resume'){
225
265
  const runIds=[...runs].filter(([,binding])=>binding.key===key).sort((a,b)=>b[1].generation-a[1].generation);
226
- const existing=runIds.find(([runId])=>fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',runId,'state.json')));
266
+ // A rescheduled member whose gen-2 run does not exist yet is a new run: preflight
267
+ // its attempt-1 answer instead of the finished first generation.
268
+ const existing=runIds.find(([runId,binding])=>(binding.generation===2||!rescheduled.has(key))
269
+ &&fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',runId,'state.json')));
227
270
  if(existing)try{
228
271
  const snapshot=readExecutionSnapshot({specsRoot:batch.specsDir,identity:{repositoryId:batch.repositoryId,runId:existing[0]}});
229
272
  const history=readRunnerHistory(snapshot.records,snapshot.records[0].payload.config,3);
230
- attempts=batchDevelopAttempts(history.state,key,permissions);current=history.state.attempt;
273
+ // Q28: decide from what the host will show (projected answer-gap blocks), not the raw replay state.
274
+ attempts=batchDevelopAttempts(projectedRunnerStatus(history,snapshot.records[0].payload.config),key,permissions);current=history.state.attempt;
231
275
  journal={baseline:snapshot.records[0].payload.baseline,generation:existing[1].generation,
232
276
  frame:journalRestBytes(snapshot.records)};
233
277
  }catch(error){stop(2,`任务 ${key} 无法只读检查恢复存档: ${error.code??error.message}`);}
@@ -346,7 +390,8 @@ function main(){
346
390
  loaded=preflight();
347
391
  const {plan,operation,bundle,config,permissions}=loaded;
348
392
  driveHost({host:HOST,args:['serve','--config',config,'--host-context',plan.hostContext,
349
- '--allow-development',...permissions,...loaded.holds.flatMap(key=>['--hold-revision',key])],cwd:bundle.batch.codeProject,operation,request:operation==='reconcile_review'?{taskKey:plan.taskKey,invocationId:plan.invocationId}:{},
393
+ '--allow-development',...permissions,...loaded.holds.flatMap(key=>['--hold-revision',key])],cwd:bundle.batch.codeProject,operation,request:operation==='reconcile_review'?{taskKey:plan.taskKey,invocationId:plan.invocationId}
394
+ :Object.hasOwn(MEMBER_ACTION_FLAGS,operation)?{taskKey:plan.taskKey,reason:plan.reason}:{},
350
395
  answers:loaded.answers,answerFor});
351
396
  }
352
397
  if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))main();
@@ -363,3 +363,68 @@ test('optimized real batch driver shares only a declared same-plan check and rej
363
363
  assert.equal(out.status,0,out.stderr);assert.equal(JSON.parse(out.stdout).result.state,'awaiting_review',out.stdout+out.stderr);
364
364
  assert.equal(fs.readFileSync(counter,'utf8'),'x');
365
365
  });
366
+
367
+ // Q24 driver: develop_redo goes through the batch host to the stopped member; the
368
+ // next advance still preflights the develop answer from the projected state (Q28).
369
+ test('Q24 batch driver forwards develop_redo to the stopped member, then advance redoes the round',t=>{
370
+ const f=fixture(t);prepared(f);
371
+ f.write('develop.json',{status:'failed',code:'session_error'});
372
+ const stuck=f.drive(f.plan(),'advance');assert.equal(stuck.status,0,stuck.stderr);
373
+ const first=JSON.parse(stuck.stdout).result;
374
+ assert.deepEqual([first.state,first.code,first.pendingAction],['blocked','develop_answer_missing','develop_redo'],stuck.stdout);
375
+ const resume={mode:'resume',originalHostContext:'batch-host-a'};
376
+ const missing=f.drive(f.plan({...resume,taskKey:key,reason:'会话已停止修改代码'}),'develop_redo');
377
+ assert.equal(missing.status,2);assert.match(missing.stderr,/--allow-develop-redo 1\.work\/T-001/);
378
+ const noReason=f.drive(f.plan({...resume,taskKey:key,permissions:['--allow-qa','--allow-develop-redo',key]}),'develop_redo');
379
+ assert.equal(noReason.status,2);assert.match(noReason.stderr,/reason/);
380
+ const unknownTask=f.drive(f.plan({...resume,taskKey:key,reason:'已停',permissions:['--allow-qa','--allow-develop-redo','1.work/T-009']}),'develop_redo');
381
+ assert.equal(unknownTask.status,2);assert.match(unknownTask.stderr,/--allow-develop-redo/);
382
+ const redo=f.drive(f.plan({...resume,taskKey:key,reason:'会话已停止修改代码',permissions:['--allow-qa','--allow-develop-redo',key]}),'develop_redo');
383
+ assert.equal(redo.status,0,redo.stderr);
384
+ const recorded=JSON.parse(redo.stdout).result;
385
+ assert.deepEqual([recorded.outcome,recorded.pendingAction,recorded.taskKey],['recorded','resume',key],redo.stdout);
386
+ prepared(f);
387
+ const again=f.drive(f.plan(resume),'advance');assert.equal(again.status,0,again.stderr);
388
+ assert.match(again.stderr,/应答 develop/);
389
+ assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 42;\n');
390
+ });
391
+
392
+ // Review round 1 (major): in a strict batch (and, batch 4, an ordinary one) a terminal parallel member is rescheduled
393
+ // into a serial second generation. The host stops at batch_member_rescheduled; the next
394
+ // resume advance preflights the gen-2 attempt-1 answer (the finished gen-1 run would
395
+ // have yielded none) and the batch continues without a host_close mid-run.
396
+ for(const [label,strict] of [['strict',true],['ordinary',false]])
397
+ test(`${label} batch driver preflights a rescheduled second generation before it is developed`,t=>{
398
+ const f=fixture(t,3);
399
+ const bundlePath=path.join(f.root,'batch.json'),bundle=JSON.parse(fs.readFileSync(bundlePath,'utf8'));
400
+ bundle.batch.parallel=[['1.work/T-001','1.work/T-002']];
401
+ fs.writeFileSync(bundlePath,JSON.stringify(bundle));
402
+ const dir=id=>{const d=path.join(f.root,'answers','1.work',id);fs.mkdirSync(d,{recursive:true});return d;};
403
+ const answer=(id,file,content,outcome='implemented')=>{
404
+ fs.writeFileSync(path.join(dir(id),`${file}.txt`),content);
405
+ fs.writeFileSync(path.join(dir(id),'develop.json'),JSON.stringify({...develop,
406
+ value:outcome==='implemented'?develop.value:{outcome:'blocked',reason:'Synthetic dependency is missing'},edits:{[`${file}.mjs`]:`${file}.txt`}}));
407
+ for(const [name,value] of [['qa-assess.json',{scores:{scope:2,risk:2,accumulation:2,boundary:2},
408
+ changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}}],
409
+ ['documentation-inspect.json',{status:'completed',reason:'README and task artifacts inspected'}]])
410
+ fs.writeFileSync(path.join(dir(id),name),JSON.stringify(value));
411
+ };
412
+ answer('T-001','target','export const value = 42;\n');
413
+ answer('T-002','target2','export const value = 2;\n','blocked');
414
+ answer('T-003','target3','export const value = 3;\n');
415
+ const checks=Object.fromEntries(['T-001','T-002','T-003'].map((id,n)=>[`1.work/${id}`,
416
+ [{id:'syntax',command:[process.execPath,'--check',n===0?'target.mjs':`target${n+1}.mjs`]}]]));
417
+ const permissions=['--allow-qa',...(strict?['--execution-optimizations']:[]),...['T-001','T-002','T-003'].flatMap(id=>['--allow-review',`1.work/${id}:1`])];
418
+ const first=f.drive(f.plan({permissions,checks}),'advance');assert.equal(first.status,0,first.stderr);
419
+ const stopped=JSON.parse(first.stdout).result;
420
+ assert.equal(stopped.code,'batch_member_rescheduled',first.stdout+first.stderr);assert.deepEqual(stopped.rescheduled,['1.work/T-002']);
421
+ // The gen-2 answer replaces the blocked one; the resume preflight must load it.
422
+ answer('T-002','target2','export const value = 2;\n');
423
+ const resumed=f.drive(f.plan({mode:'resume',originalHostContext:'batch-host-a',
424
+ permissions:permissions.filter(flag=>flag!=='--execution-optimizations'),checks}),'advance');
425
+ assert.equal(resumed.status,0,resumed.stderr);
426
+ assert.doesNotMatch(resumed.stderr,/未预检/);
427
+ const done=JSON.parse(resumed.stdout).result;
428
+ assert.equal(done.state,'run_done',resumed.stdout+resumed.stderr);
429
+ assert.equal(fs.readFileSync(path.join(f.codeProject,'target2.mjs'),'utf8'),'export const value = 2;\n');
430
+ });