@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
@@ -5,6 +5,9 @@ import {findCmAiQaDecision,inspectCmAiQaDecision,inspectCmAiQaResult,recordCmAiQ
5
5
  latestCmAiQaRun,recordCmAiQaRun,inspectCmAiQaRecovery,inspectCmAiQaConfigurationRecovery,timedOutQaDecision,
6
6
  replacesTimedOutQaDecision,validEnvironmentFailureReason} from './cm-ai-qa-log.mjs';
7
7
  import {recordCmAiRunDone} from './cm-ai-run-finalizer.mjs';
8
+ import {releaseVerifiedQaResources} from './qa-resource-release.mjs';
9
+ import {QA_MAX_ROUNDS} from './qa-round-budget.mjs';
10
+ import {qaRoundDeadlineMs} from './host-qa-executor.mjs';
8
11
  import {projectHostResult} from './host-progress.mjs';
9
12
  import {operatorGuidance} from './operator-guidance.mjs';
10
13
  import {outstandingFeatureQa,describeOutstandingQa} from './project-qa-gate.mjs';
@@ -21,22 +24,40 @@ const boundStatus=(status,identity)=>{validIdentity(status?.identity);
21
24
  // verdict and a verdict that broke the written contract share one redispatch
22
25
  // per attempt. Exported for the batch driver, like developmentRetryable.
23
26
  export const reviewRetryable=status=>status.state==='pending_review'
24
- &&['review_transport_timeout','review_abandoned','review_provider_failed','review_verdict_invalid'].includes(status.code);
27
+ &&(['review_transport_timeout','review_abandoned','review_provider_failed','review_verdict_invalid'].includes(status.code)
28
+ // Registered but never dispatched (expired grant, clock ran backwards): no reviewer
29
+ // ran, so a fresh authorization redispatches it (REVIEW_NOT_DISPATCHED_CODES; the
30
+ // runner's not_dispatched halt is the only source of pending_review with these codes).
31
+ ||['grant_expired','clock_invalid'].includes(status.code)
32
+ // A refused authorization the operator has since confirmed (abandon_review): the same
33
+ // round asks for a fresh authorization. Unconfirmed (reviewDispatchConfirmRequired) it
34
+ // is not retryable here, so neither advance nor the batch driver ever redispatches it.
35
+ ||status.code==='permission_denied_confirmed');
25
36
  const retryReview=reviewRetryable;
26
37
  // Both mean the delivery itself must be redone: an invalid developer result, or
27
38
  // one that does not satisfy the task's own written verification. Exported so the
28
39
  // batch driver decides retryability from the same predicate instead of keeping a
29
40
  // second copy of the code list that silently drifts.
30
41
  export const developmentRetryable=status=>status.state==='blocked'
31
- &&['developer_result_invalid','verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed','develop_unchanged_after_review','develop_empty_changes','develop_requirement_missing','develop_package_too_large','bootstrap_verification_failed'].includes(status.code);
42
+ &&['developer_result_invalid','verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed','develop_unchanged_after_review','develop_empty_changes','develop_requirement_missing','develop_package_too_large','bootstrap_verification_failed','develop_call_timeout','develop_answer_invalid',
43
+ 'check_answer_missing','check_answer_invalid','develop_out_of_scope','develop_answer_missing','develop_dispatch_failed','develop_interrupted',
44
+ // Q16/Q17: only documentation_sync is asked again (durable-runner-state.mjs DOCUMENTATION_SYNC_CODES).
45
+ 'documentation_sync_answer_missing','documentation_sync_answer_invalid','documentation_sync_answer_blocked','documentation_sync_out_of_scope','documentation_sync_interrupted'].includes(status.code)
46
+ // Shown before the operator confirmed the session stopped: not yet redoable.
47
+ &&status.developRedoRequired!==true;
32
48
  const retryDeveloper=developmentRetryable;
33
49
  export const completionRetryable=status=>status.state==='blocked'
34
- &&['completion_checks_changed','completion_package_changed'].includes(status.code)
50
+ &&['completion_checks_changed','completion_package_changed','complete_recheck_failed','complete_commit_interrupted'].includes(status.code)
35
51
  &&status.retryReady!==false;
36
52
  const pendingAction=status=>status.state==='awaiting_spec_approval'?'spec_approval':
37
53
  // The runner reports spec_drift over any state whose next effect would be refused.
38
54
  status.code==='spec_drift'?(status.specificationRebind==='available'?'spec_rebind':'none'):
39
55
  status.bootstrapReviewRecovery===true?'bootstrap_review_recover':
56
+ status.developRedoRequired===true?'develop_redo':
57
+ // V5: the round's second no-result redispatch needs the operator's stop confirmation.
58
+ status.reviewRedispatchStopRequired===true?'abandon_review':
59
+ // A review that never started and needs the operator's confirmation (abandon_review).
60
+ status.reviewDispatchConfirmRequired===true?'abandon_review':
40
61
  status.reviewReconciliation?.available?'reconcile_review':
41
62
  status.state==='changes_requested'||retryDeveloper(status)||retryReview(status)?'resume':
42
63
  status.state==='awaiting_review'?'decision':status.state==='unknown'
@@ -60,6 +81,11 @@ const summary=(operation,status,outcome)=>freeze({version:1,workflow:'cm-ai',ope
60
81
  requestDigest:digest(operation),identity:status.identity,outcome,state:status.state,code:status.code??null,
61
82
  packageDigest:status.packageDigest??null,pendingAction:pendingAction(status),
62
83
  ...(status.reviewReconciliation?{reviewReconciliation:status.reviewReconciliation}:{}),
84
+ ...(status.developRedoRequired===true?{developRedoRequired:true}:{}),
85
+ ...(status.documentationSyncPending===true?{documentationSyncPending:true}:{}),
86
+ ...(status.reviewRedispatchStopRequired===true?{reviewRedispatchStopRequired:true}:{}),
87
+ ...(status.reviewDispatchConfirmRequired===true?{reviewDispatchConfirmRequired:true}:{}),
88
+ ...(typeof status.reviewAbandonRefusal==='string'?{reviewAbandonRefusal:status.reviewAbandonRefusal}:{}),
63
89
  ...(typeof status.reason==='string'?{reason:status.reason}:{}),
64
90
  ...(status.code==='handoff_exists'?{reason:REVIEWED_HANDOFF_HINT}:{}),
65
91
  ...(status.state==='blocked'&&status.calls?.at(-1)?.blockedReason!==undefined
@@ -82,11 +108,11 @@ function readOperation(raw) {
82
108
  const operation=json(raw),keys=['version','operation','requestId','identity'];
83
109
  if(['decision','complete','qa','qa_result','context_refresh','finish','run_finalize'].includes(operation?.operation))keys.push('packageDigest');
84
110
  if(['qa_result','context_refresh','finish','run_finalize'].includes(operation?.operation))keys.push('testRunId');
85
- if(['abandon_review','abandon_effect','bootstrap_review_recover'].includes(operation?.operation))keys.push('reason');
111
+ if(['abandon_review','abandon_effect','bootstrap_review_recover','develop_redo'].includes(operation?.operation))keys.push('reason');
86
112
  if(operation?.operation==='reconcile_review')keys.push('invocationId');
87
113
  shape(operation,keys);
88
114
  if(operation?.operation==='reconcile_review')id(operation.invocationId);
89
- need(operation.version===1&&['advance','start','status','decision','complete','qa','qa_result','context_refresh','finish','run_finalize','cancel','resume','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover']
115
+ need(operation.version===1&&['advance','start','status','decision','complete','qa','qa_result','context_refresh','finish','run_finalize','cancel','resume','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover','develop_redo']
90
116
  .includes(operation.operation));
91
117
  id(operation.requestId);validIdentity(operation.identity);
92
118
  if(operation.operation==='abandon_review')need(typeof operation.reason==='string'
@@ -95,6 +121,9 @@ function readOperation(raw) {
95
121
  if(operation.operation==='abandon_effect')need(typeof operation.reason==='string'
96
122
  &&operation.reason.trim().length>0&&Buffer.byteLength(operation.reason,'utf8')<=500
97
123
  &&!/[\r\n\0]/.test(operation.reason),'effect_abandon_reason_required');
124
+ if(operation.operation==='develop_redo')need(typeof operation.reason==='string'
125
+ &&operation.reason.trim().length>0&&Buffer.byteLength(operation.reason,'utf8')<=500
126
+ &&!/[\r\n\0]/.test(operation.reason),'develop_redo_reason_required');
98
127
  if(operation.operation==='bootstrap_review_recover')need(typeof operation.reason==='string'
99
128
  &&operation.reason.trim().length>0&&Buffer.byteLength(operation.reason,'utf8')<=500
100
129
  &&!/[\r\n\0]/.test(operation.reason),'bootstrap_review_recovery_reason_required');
@@ -136,6 +165,11 @@ function effectSummary(operation,result,runner,identity) {
136
165
  boundStatus(runner.status(),next);
137
166
  return summary(operation,boundStatus(result,next),'advanced');
138
167
  }
168
+ // A rejected current-session answer is checkpointed blocked/failed; the
169
+ // runner's status shows it as the retryable develop_answer_invalid block.
170
+ if(result?.state==='blocked'&&['failed','unavailable'].includes(result.code)){
171
+ const current=runner.status();if(['develop_answer_invalid','develop_answer_missing'].includes(current.code))result=current;
172
+ }
139
173
  return summary(operation,boundStatus(result,identity),result?.code==='handoff_exists'?'blocked':'advanced');
140
174
  }
141
175
 
@@ -195,6 +229,7 @@ export function createCmAiConversationEntry(options) {
195
229
  if(options&&Object.hasOwn(options,'allowAbandonReview'))optionKeys.push('allowAbandonReview');
196
230
  if(options&&Object.hasOwn(options,'allowAbandonEffect'))optionKeys.push('allowAbandonEffect');
197
231
  if(options&&Object.hasOwn(options,'allowBootstrapReviewRecovery'))optionKeys.push('allowBootstrapReviewRecovery');
232
+ if(options&&Object.hasOwn(options,'allowDevelopRedo'))optionKeys.push('allowDevelopRedo');
198
233
  if(options&&Object.hasOwn(options,'holdRevision'))optionKeys.push('holdRevision');
199
234
  if(options&&Object.hasOwn(options,'featureSelection'))optionKeys.push('featureSelection');
200
235
  shape(options,optionKeys);
@@ -207,6 +242,8 @@ export function createCmAiConversationEntry(options) {
207
242
  const runnerKeys=['executeEffect','status','cancel','run'];
208
243
  if(runner&&Object.hasOwn(runner,'verificationBlocks'))runnerKeys.push('verificationBlocks');
209
244
  if(runner&&Object.hasOwn(runner,'completionBlocks'))runnerKeys.push('completionBlocks');
245
+ if(runner&&Object.hasOwn(runner,'reviewEffectIds'))runnerKeys.push('reviewEffectIds');
246
+ if(runner&&Object.hasOwn(runner,'recheckLearningInput'))runnerKeys.push('recheckLearningInput');
210
247
  if(runner&&Object.hasOwn(runner,'attachLearningEvidence'))runnerKeys.push('attachLearningEvidence');
211
248
  if(runner&&Object.hasOwn(runner,'inspectFixAssociation'))runnerKeys.push('inspectFixAssociation');
212
249
  if(runner&&Object.hasOwn(runner,'acceptCompletedFix'))runnerKeys.push('acceptCompletedFix');
@@ -218,10 +255,15 @@ export function createCmAiConversationEntry(options) {
218
255
  if(runner&&Object.hasOwn(runner,'reconcileReview'))runnerKeys.push('reconcileReview');
219
256
  if(runner&&Object.hasOwn(runner,'abandonEffect'))runnerKeys.push('abandonEffect');
220
257
  if(runner&&Object.hasOwn(runner,'recoverBootstrapReview'))runnerKeys.push('recoverBootstrapReview');
258
+ if(runner&&Object.hasOwn(runner,'redoDevelop'))runnerKeys.push('redoDevelop');
259
+ if(runner&&Object.hasOwn(runner,'recoverCommit'))runnerKeys.push('recoverCommit');
260
+ if(runner&&Object.hasOwn(runner,'interruptions'))runnerKeys.push('interruptions');
221
261
  if(runner&&Object.hasOwn(runner,'inspectBootstrapAdmission'))runnerKeys.push('inspectBootstrapAdmission');
222
262
  shape(runner,runnerKeys);
223
263
  for(const name of ['executeEffect','status','cancel','run'])need(typeof runner[name]==='function');
224
264
  if(Object.hasOwn(runner,'completionBlocks'))need(typeof runner.completionBlocks==='function');
265
+ if(Object.hasOwn(runner,'reviewEffectIds'))need(typeof runner.reviewEffectIds==='function');
266
+ if(Object.hasOwn(runner,'recheckLearningInput'))need(typeof runner.recheckLearningInput==='function');
225
267
  if(Object.hasOwn(runner,'attachLearningEvidence'))need(typeof runner.attachLearningEvidence==='function');
226
268
  if(Object.hasOwn(runner,'inspectFixAssociation'))need(typeof runner.inspectFixAssociation==='function');
227
269
  if(Object.hasOwn(runner,'acceptCompletedFix'))need(typeof runner.acceptCompletedFix==='function');
@@ -231,6 +273,9 @@ export function createCmAiConversationEntry(options) {
231
273
  if(Object.hasOwn(runner,'reconcileReview'))need(typeof runner.reconcileReview==='function');
232
274
  if(Object.hasOwn(runner,'abandonEffect'))need(typeof runner.abandonEffect==='function');
233
275
  if(Object.hasOwn(runner,'recoverBootstrapReview'))need(typeof runner.recoverBootstrapReview==='function');
276
+ if(Object.hasOwn(runner,'redoDevelop'))need(typeof runner.redoDevelop==='function');
277
+ if(Object.hasOwn(runner,'recoverCommit'))need(typeof runner.recoverCommit==='function');
278
+ if(Object.hasOwn(runner,'interruptions'))need(typeof runner.interruptions==='function');
234
279
  if(Object.hasOwn(runner,'inspectBootstrapAdmission'))need(typeof runner.inspectBootstrapAdmission==='function');
235
280
  need(options.allowAbandonReview===undefined||typeof options.allowAbandonReview==='boolean','invalid_input');
236
281
  let abandonPermission=options.allowAbandonReview===true;
@@ -238,6 +283,8 @@ export function createCmAiConversationEntry(options) {
238
283
  let abandonEffectPermission=options.allowAbandonEffect===true;
239
284
  need(options.allowBootstrapReviewRecovery===undefined||typeof options.allowBootstrapReviewRecovery==='boolean','invalid_input');
240
285
  let bootstrapReviewRecoveryPermission=options.allowBootstrapReviewRecovery===true;
286
+ need(options.allowDevelopRedo===undefined||typeof options.allowDevelopRedo==='boolean','invalid_input');
287
+ let developRedoPermission=options.allowDevelopRedo===true;
241
288
 
242
289
  const hostDecision=Object.hasOwn(options,'hostDecision')?json(options.hostDecision):null;
243
290
  let hostDecisionProvider=null,pendingReviewDecision=null;
@@ -258,6 +305,12 @@ export function createCmAiConversationEntry(options) {
258
305
  const decideQa=qaProvider?.decide,qaTimeout=qaProvider?.timeoutMs;
259
306
  let pendingQa=null;
260
307
  let qaExecutor=null,pendingExecution=null,cancellationEpoch=0;
308
+ // Q13: a scan failure (no log yet) leaves resources as they are; the writer still refuses closure.
309
+ const releaseQaResources=identity=>{
310
+ try{return releaseVerifiedQaResources({specsDir:options.specsDir,codeProject:options.codeProject,runId:identity.runId,
311
+ ...(Object.hasOwn(options,'qaLogHome')?{logHome:options.qaLogHome}:{})});}
312
+ catch(error){if(error?.code==='qa_resource_release_failed')throw error;return {released:[],open:[]};}
313
+ };
261
314
  const inFlightHandles=new Set();
262
315
  let rerunUnknownQa=options.rerunUnknownQa??false;need(typeof rerunUnknownQa==='boolean');
263
316
  let rerunBlockedQa=options.rerunBlockedQa??false;need(typeof rerunBlockedQa==='boolean');
@@ -265,16 +318,20 @@ export function createCmAiConversationEntry(options) {
265
318
  // Operator declaration that the latest FAIL came from the environment; only
266
319
  // meaningful with the one-shot rerun authorization and consumed with it.
267
320
  const qaEnvironmentFailure=options.qaEnvironmentFailure??null;
268
- need(qaEnvironmentFailure===null||rerunBlockedQa&&validEnvironmentFailureReason(qaEnvironmentFailure),'qa_recovery_authorization_required');
321
+ // With --rerun-unknown-qa it is the operator's attestation that older timed-out
322
+ // case rows (no host_request_timeout field) had no session answer.
323
+ need(qaEnvironmentFailure===null||(rerunBlockedQa||rerunUnknownQa)&&validEnvironmentFailureReason(qaEnvironmentFailure),'qa_recovery_authorization_required');
269
324
  if(Object.hasOwn(options,'qaExecutor')){
270
325
  shape(options.qaExecutor,['mode','caseCount','timeoutMs','run',
271
326
  ...(Object.hasOwn(options.qaExecutor,'configuration')?['configuration']:[]),
327
+ ...(Object.hasOwn(options.qaExecutor,'requestTimeoutMs')?['requestTimeoutMs']:[]),
272
328
  ...(Object.hasOwn(options.qaExecutor,'prepare')?['prepare']:[])]);
273
329
  const {run,prepare,...config}=options.qaExecutor;
274
330
  need(typeof run==='function'&&(prepare===undefined||typeof prepare==='function'));
275
331
  qaExecutor={...json(config),run,...(prepare?{prepare}:{})};
276
332
  need(['commands','browser','all'].includes(config.mode)&&Number.isSafeInteger(config.caseCount)&&config.caseCount>0);
277
333
  need(Number.isInteger(config.timeoutMs)&&config.timeoutMs>=1&&config.timeoutMs<=3600000);
334
+ need(config.requestTimeoutMs===undefined||Number.isInteger(config.requestTimeoutMs)&&config.requestTimeoutMs>=1&&config.requestTimeoutMs<=3600000);
278
335
  }
279
336
  const applicableAgentFiles=Object.hasOwn(options,'applicableAgentFiles')?json(options.applicableAgentFiles):null;
280
337
  const documentationResult=Object.hasOwn(options,'documentationResult')?json(options.documentationResult):null;
@@ -347,7 +404,7 @@ export function createCmAiConversationEntry(options) {
347
404
  need(sameTask(identity,ownerIdentity)&&identity.attempt>=ownerIdentity.attempt,'identity_mismatch');
348
405
  // Stable run-definition identity can query/control or resume the current
349
406
  // attempt. Package-bound mutations must name the current attempt exactly.
350
- const stableControl=['status','cancel','advance','resume','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover'].includes(operation.operation)
407
+ const stableControl=['status','cancel','advance','resume','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover','develop_redo'].includes(operation.operation)
351
408
  &&sameIdentity(operation.identity,ownerIdentity);
352
409
  need(sameIdentity(operation.identity,identity)||stableControl,'identity_mismatch');
353
410
  if(operation.operation==='advance'){
@@ -386,7 +443,11 @@ export function createCmAiConversationEntry(options) {
386
443
  notCancelled();
387
444
  need(pendingExecution===null,'qa_execution_pending');
388
445
  const binding={specsDir:options.specsDir,feature:options.feature,identity:result.identity,packageDigest:result.packageDigest};
389
- let previous,recovery=null,configurationRecovery=false,incompleteReport=false;
446
+ // Q13: close cleanup_failed command resources whose process group is proven gone.
447
+ releaseQaResources(result.identity);
448
+ let previous,recovery=null,configurationRecovery=false,incompleteReport=false,timedOutCall=false;
449
+ const timedOutRecovery=()=>inspectCmAiQaRecovery(binding,{timedOut:true,requestTimeoutMs:qaExecutor.requestTimeoutMs??null,
450
+ attestation:rerunUnknownQa?qaEnvironmentFailure:null});
390
451
  try{previous=latestCmAiQaRun(binding);}
391
452
  catch(error){
392
453
  if(error.code==='qa_result_superseded'){
@@ -397,13 +458,25 @@ export function createCmAiConversationEntry(options) {
397
458
  if(rerunUnknownQa){
398
459
  try{recovery=inspectCmAiQaRecovery(binding);}
399
460
  catch(error){if(error.code!=='qa_execution_unknown')throw error;}
461
+ // A call stopped by qa_execution_timeout whose only non-PASS
462
+ // cases are host request timeouts: supersede it into the next round.
463
+ if(recovery===null)try{recovery=timedOutRecovery();timedOutCall=true;}
464
+ catch(error){if(error.code!=='qa_execution_unknown')throw error;}
400
465
  }
401
466
  // The call wrote its fixed report but no complete row (a host before
402
467
  // this fix rejected stale_qa in between). --rerun-blocked-qa reads
403
468
  // that report under the ordinary blocked-evidence rules.
404
469
  if(recovery===null&&rerunBlockedQa){
405
- recovery=inspectCmAiQaRecovery(binding,{blocked:true,environment:qaExecutor.configuration?.environment,
406
- environmentFailure:qaEnvironmentFailure});
470
+ try{recovery=inspectCmAiQaRecovery(binding,{blocked:true,environment:qaExecutor.configuration?.environment,
471
+ environmentFailure:qaEnvironmentFailure});}
472
+ catch(error){
473
+ // Name the flag that does recover a timed-out call.
474
+ let timedOutCallRecoverable=false;try{timedOutRecovery();timedOutCallRecoverable=true;}
475
+ catch(probe){timedOutCallRecoverable=probe?.code==='qa_environment_failure_required';}
476
+ if(error.code==='qa_rerun_not_blocked_by_evidence'&&timedOutCallRecoverable)
477
+ throw Object.assign(new Error('use --rerun-unknown-qa'),{code:'qa_rerun_unknown_qa_required'});
478
+ throw error;
479
+ }
407
480
  incompleteReport=true;
408
481
  }
409
482
  if(recovery===null)return summary(operation,{...runner.status(),code:'qa_execution_unknown'},'blocked');
@@ -427,8 +500,8 @@ export function createCmAiConversationEntry(options) {
427
500
  if(previous===null||repaired||rerunBlockedQa){
428
501
  // Later rounds require an accepted completed repair or explicit
429
502
  // evidence recovery/configuration revision. Unknown execution stops.
430
- const qaRound=recovery?recovery.qaRound+(rerunBlockedQa||configurationRecovery?1:0):(repaired?accepted.qaRound+1:1);
431
- need(qaRound>=1&&qaRound<=3,'qa_round_invalid');
503
+ const qaRound=recovery?recovery.qaRound+(rerunBlockedQa||configurationRecovery||timedOutCall?1:0):(repaired?accepted.qaRound+1:1);
504
+ need(qaRound>=1&&qaRound<=QA_MAX_ROUNDS,'qa_round_invalid');
432
505
  testRunId=`qa-${digest(recovery?{...binding,previousTestRunId:recovery.testRunId}:
433
506
  repaired?{...binding,qaRound,repair:accepted.evidenceDigest}:binding).slice(0,48)}`;
434
507
  const invocation={...binding,codeProject:options.codeProject,testRunId,mode:qaExecutor.mode,caseCount:qaExecutor.caseCount,
@@ -437,13 +510,16 @@ export function createCmAiConversationEntry(options) {
437
510
  notCancelled();
438
511
  if(recovery&&!configurationRecovery){
439
512
  recordCmAiQaRun({...logInput,testRunId:recovery.testRunId,mode:recovery.mode,
440
- caseCount:recovery.caseCount,qaRound:recovery.qaRound,phase:rerunBlockedQa?'superseded':'abandoned',
513
+ caseCount:recovery.caseCount,qaRound:recovery.qaRound,phase:rerunBlockedQa||timedOutCall?'superseded':'abandoned',
514
+ ...(timedOutCall?{timedOutRecovery:{requestTimeoutMs:recovery.requestTimeoutMs,attestation:recovery.attestation}}:{}),
441
515
  ...(rerunBlockedQa?{expectedEnvironment:qaExecutor.configuration?.environment??null}:{}),
442
516
  ...(rerunBlockedQa&&qaEnvironmentFailure!==null?{environmentFailure:qaEnvironmentFailure}:{})});
443
517
  rerunUnknownQa=false;rerunBlockedQa=false;
444
518
  }
445
519
  recordCmAiQaRun({...logInput,phase:'start',
446
520
  deferredCases:qaExecutor.configuration?.plan?.deferred_cases??[],
521
+ ...(qaExecutor.configuration?.plan?.dropped_task_cases?{droppedTaskCases:qaExecutor.configuration.plan.dropped_task_cases}:{}),
522
+ ...(qaExecutor.configuration?.plan?.dropped_task_commands?{droppedTaskCommands:qaExecutor.configuration.plan.dropped_task_commands}:{}),
447
523
  ...(recovery?{previousTestRunId:recovery.testRunId}:{})});
448
524
  const controller=new AbortController();pendingExecution=controller;
449
525
  let timer,timedOut=false;
@@ -451,7 +527,8 @@ export function createCmAiConversationEntry(options) {
451
527
  const interrupted=new Promise((_,reject)=>{
452
528
  controller.signal.addEventListener('abort',()=>reject(Object.assign(new Error('QA interrupted'),
453
529
  {code:timedOut?'qa_execution_timeout':'cancelled'})),{once:true});
454
- timer=setTimeout(()=>{timedOut=true;controller.abort();},qaExecutor.timeoutMs);
530
+ // Q12: the round deadline scales with the frozen plan.
531
+ timer=setTimeout(()=>{timedOut=true;controller.abort();},qaRoundDeadlineMs(qaExecutor));
455
532
  });
456
533
  const executed=await Promise.race([Promise.resolve().then(()=>{
457
534
  notCancelled();
@@ -522,7 +599,8 @@ export function createCmAiConversationEntry(options) {
522
599
  abandonPermission=false;
523
600
  const result=runner.abandonReview?.({allowed:true,reason:operation.reason})
524
601
  ??{outcome:'rejected',code:'review_abandon_unavailable'};
525
- if(result.outcome==='rejected')return summary(operation,{...runner.status(),code:result.code},'rejected');
602
+ if(result.outcome==='rejected')return summary(operation,{...runner.status(),code:result.code,
603
+ ...(typeof result.reason==='string'?{reason:result.reason}:{})},'rejected');
526
604
  return summary(operation,boundStatus(result,identity),'abandoned');
527
605
  }
528
606
  if(operation.operation==='abandon_effect'){
@@ -533,7 +611,18 @@ export function createCmAiConversationEntry(options) {
533
611
  ??{outcome:'rejected',code:'effect_abandon_unavailable'};
534
612
  if(result.outcome==='rejected')return summary(operation,{...runner.status(),code:result.code,
535
613
  ...(result.reason?{reason:result.reason}:{})},'rejected');
536
- return summary(operation,boundStatus(result,identity),'abandoned');
614
+ // V8: an interrupted step continues in the run (recorded); a void ends it.
615
+ return summary(operation,boundStatus(result,identity),result.code==='effect_abandoned'?'abandoned':'recorded');
616
+ }
617
+ if(operation.operation==='develop_redo'){
618
+ if(!developRedoPermission)return summary(operation,{...runner.status(),
619
+ code:'develop_redo_authorization_required'},'rejected');
620
+ developRedoPermission=false;
621
+ const result=runner.redoDevelop?.({allowed:true,reason:operation.reason})
622
+ ??{outcome:'rejected',code:'develop_redo_unavailable'};
623
+ if(result.outcome==='rejected')return summary(operation,{...runner.status(),code:result.code,
624
+ ...(result.reason?{reason:result.reason}:{})},'rejected');
625
+ return summary(operation,boundStatus(result,identity),'recorded');
537
626
  }
538
627
  if(operation.operation==='bootstrap_review_recover'){
539
628
  if(!bootstrapReviewRecoveryPermission)return summary(operation,{...runner.status(),
@@ -579,10 +668,21 @@ export function createCmAiConversationEntry(options) {
579
668
  if(decision===null)return summary(operation,{...status,code:'decision_required'},'awaiting');
580
669
  if(validateHostDecision(decision,status)==='denied')
581
670
  return summary(operation,{...status,code:'permission_denied'},'denied');
582
- const retries=retryReview(status)?status.calls.filter(call=>call.channel==='host-authorized'
583
- &&['failed','abandoned'].includes(call.terminal)
584
- &&call.contextId===status.reviewInvocation.registration.grant.logicalContextId).length:0;
585
- const effectId=`review-${identity.attempt}${retries?`-retry-${retries}`:''}`;
671
+ // A redispatch takes the next free id: at least the number of review effects THIS round's cache
672
+ // holds (runner.reviewEffectIds) and at least the host-authorized calls that ended without a
673
+ // verdict (an abandoned intent has a call but no cache entry), then skips any id already
674
+ // cached. A refused authorization leaves no call and keeps the previous round's
675
+ // reviewInvocation, so the call count alone can repeat an id and the cache would answer.
676
+ const resumed=runner.interruptions?.('review')??0,roundIds=runner.reviewEffectIds?.();
677
+ const idFor=n=>`review-${identity.attempt}${n?`-retry-${n}`:''}${resumed?`-resume-${resumed}`:''}`;
678
+ let retries=0;
679
+ if(retryReview(status)){
680
+ retries=Math.max(Array.isArray(roundIds)?roundIds.length:0,
681
+ status.calls.filter(call=>call.channel==='host-authorized'&&['failed','abandoned','not_dispatched'].includes(call.terminal)
682
+ &&call.contextId===status.reviewInvocation?.registration?.grant.logicalContextId).length);
683
+ if(Array.isArray(roundIds))while(roundIds.includes(idFor(retries)))retries++;
684
+ }
685
+ const effectId=idFor(retries);
586
686
  const result=await runner.executeEffect({version:1,id:effectId,identity,kind:'review'});
587
687
  return effectSummary(operation,result,runner,identity);
588
688
  }
@@ -593,8 +693,13 @@ export function createCmAiConversationEntry(options) {
593
693
  if(status.code==='completion_package_changed'&&status.retryReady===false)return summary(operation,status,'rejected');
594
694
  const correction=correctionSummary(operation,status);if(correction)return correction;
595
695
  need(['approved','fixture_completed'].includes(status.state)||completionRetryable(status),'completion_not_ready');
596
- const retries=runner.completionBlocks?.()??0;
597
- const effectId=`complete-${identity.attempt}${retries?`-retry-${retries}`:''}`;
696
+ // A45: finish the interrupted task commit from its journaled plan only.
697
+ if(status.code==='complete_commit_interrupted'){
698
+ const recovered=runner.recoverCommit?.()??{outcome:'rejected',code:'commit_recovery_unavailable'};
699
+ return effectSummary(operation,recovered,runner,identity);
700
+ }
701
+ const retries=runner.completionBlocks?.()??0,resumed=runner.interruptions?.('complete')??0;
702
+ const effectId=`complete-${identity.attempt}${retries?`-retry-${retries}`:''}${resumed?`-resume-${resumed}`:''}`;
598
703
  const result=await runner.executeEffect({version:1,id:effectId,identity,kind:'complete'});
599
704
  return effectSummary(operation,result,runner,identity);
600
705
  }
@@ -737,6 +842,10 @@ export function createCmAiConversationEntry(options) {
737
842
  return freeze({...summary(operation,{...status,code:'documentation_sync_blocked'},'blocked'),
738
843
  ...closeoutSummary(knowledgeCloseout,documentation)});
739
844
  const finalQa=projectQaSummary(operation,status,options);if(finalQa)return finalQa;
845
+ const resources=releaseQaResources(identity);
846
+ if(resources.open.length)return summary(operation,{...status,code:'qa_resources_open',
847
+ reason:`qa_resources_open: 以下运行资源仍未释放(写入器会拒绝 run_done):${resources.open.slice(0,10).map(item=>`${item.resourceId}(${item.verdict})`).join('、')}。`
848
+ +'宿主只在运行日志记有该命令进程组身份且核对进程组已退出时补记释放;先结束残留进程后重发 run_finalize,记录里没有进程身份的旧资源需人工处理。'},'blocked');
740
849
  const input={specsDir:options.specsDir,codeProject:options.codeProject,feature:options.feature,identity,
741
850
  packageDigest:operation.packageDigest,contextDigest:refresh.contextDigest,
742
851
  documentationSyncId:documentation.syncId};
@@ -763,7 +872,10 @@ export function createCmAiConversationEntry(options) {
763
872
  // the review that asked for it, before any develop intent, and say so.
764
873
  if(options.holdRevision===true&&status.state==='changes_requested')
765
874
  return summary(operation,{...status,code:'revision_answer_required'},'awaiting');
766
- const learningInput=inspectCmAiTaskLearningInput({specsDir:options.specsDir,codeProject:options.codeProject,
875
+ // A re-check (check_answer_*) re-runs the checks of the delivery already made:
876
+ // it binds that delivery's Learning input, never a freshly read one (its
877
+ // writeback may already have changed AGENTS.md).
878
+ const learningInput=runner.recheckLearningInput?.()??inspectCmAiTaskLearningInput({specsDir:options.specsDir,codeProject:options.codeProject,
767
879
  feature:options.feature,identity,applicableAgentFiles:applicableAgentFiles??[],
768
880
  ...(options.featureSelection===undefined?{}:{featureSelection:options.featureSelection})},
769
881
  {admission:runner.inspectBootstrapAdmission?.()??null,parallelSelection:options.parallelSelection??null});
@@ -773,8 +885,8 @@ export function createCmAiConversationEntry(options) {
773
885
  &&call.failureResult?.code==='invalid_result'&&call.failureResult.retryable===true).length;
774
886
  // Both kinds of local rejection need a fresh effect id: an invalid developer
775
887
  // result, and one the host gate blocked before the review package existed.
776
- const retries=rejectedValues+(runner.verificationBlocks?.()??0);
777
- const effectId=`develop-${identity.attempt}${retries?`-retry-${retries}`:''}`;
888
+ const retries=rejectedValues+(runner.verificationBlocks?.()??0),resumed=runner.interruptions?.('develop')??0;
889
+ const effectId=`develop-${identity.attempt}${retries?`-retry-${retries}`:''}${resumed?`-resume-${resumed}`:''}`;
778
890
  const result=await runner.executeEffect({version:1,id:effectId,identity,kind:'develop',learningInput});
779
891
  return effectSummary(operation,result,runner,identity);
780
892
  }
@@ -782,7 +894,7 @@ export function createCmAiConversationEntry(options) {
782
894
  let token=null,operation=null;const epoch=cancellationEpoch;
783
895
  try{
784
896
  operation=readOperation(raw);
785
- if(!['status','cancel','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover'].includes(operation.operation)){
897
+ if(!['status','cancel','reconcile_review','abandon_review','abandon_effect','bootstrap_review_recover','develop_redo'].includes(operation.operation)){
786
898
  token=Symbol(operation.operation);inFlightHandles.add(token);
787
899
  }
788
900
  const routed=await route(operation);