@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
@@ -2,21 +2,26 @@
2
2
  // same specs root. A delivery counts only after its own journal replays through
3
3
  // the runner grammar to a committed fixture_completed state: its review package
4
4
  // (and any accepted QA-fix packages) then describe reviewed before->after file
5
- // transitions. This grants nothing, never repairs, and never opens a writer.
5
+ // transitions. A standalone cm-fix run counts the same way once its own owner
6
+ // replays it to its normal completed closeout: its independently approved final
7
+ // review package is the transition. This grants nothing, never repairs, and
8
+ // never opens a writer.
6
9
  import fs from 'node:fs';
7
10
  import path from 'node:path';
8
11
  import {readExecutionSnapshot} from './execution-snapshot.mjs';
9
12
  import {readRunnerHistory} from './durable-runner-state.mjs';
13
+ import {inspectFixCompletionHistory} from '../cm-fix/execution.mjs';
10
14
  import {deliveredAfter,deliveryStep} from './fix-code-association.mjs';
11
15
  import {digest,need} from './effect-contract.mjs';
12
16
 
13
17
  const RUN_ID=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
14
18
  const cache=new Map();
15
19
 
16
- function readDelivery(specsRoot,identity){
20
+ function readDelivery(specsRoot,identity,read={}){
17
21
  try{
18
22
  const snapshot=readExecutionSnapshot({specsRoot,identity});
19
23
  const init=snapshot.records[0]?.payload;
24
+ if(init?.workflow==='cm-fix-stages-v1'){read.fix=true;return readFixDelivery(specsRoot,identity,init.configuration);}
20
25
  if(init?.protocol!=='cm-task-runner'||init.type!=='init'||![2,3].includes(init.version))return null;
21
26
  const history=readRunnerHistory(snapshot.records,init.config,init.version);
22
27
  const state=history.state;
@@ -29,6 +34,18 @@ function readDelivery(specsRoot,identity){
29
34
  ...history.acceptedFixes.map(item=>({pkg:item.evidence.reviewPackage,reviewedAt:fixReviewedAt(specsRoot,item.evidence)}))])});
30
35
  }catch{return null;}
31
36
  }
37
+ // A standalone cm-fix run in this specs root, read through its own owner's
38
+ // read-only replay and completion projection: only a run whose approved final
39
+ // review of the exact package was closed by task_done and run_done qualifies
40
+ // (never a running, abandoned, cancelled or escalated one). A QA-fix child is
41
+ // its parent's delivery, through the parent's acceptance, never its own; a bare
42
+ // archive lives outside any specs root.
43
+ function readFixDelivery(specsRoot,identity,configuration){
44
+ if(Object.hasOwn(configuration??{},'qaSource')||configuration?.archiveMode!==undefined)return null;
45
+ const {identity:fixIdentity,evidence}=inspectFixCompletionHistory({specsRoot,identity});
46
+ return Object.freeze({runId:identity.runId,root:fs.realpathSync(configuration.reproduction.cwd),taskId:fixIdentity.taskId,
47
+ packages:Object.freeze([{pkg:evidence.reviewPackage,reviewedAt:fixReviewedAt(specsRoot,evidence)}])});
48
+ }
32
49
  // A QA fix package's durable review time: the final review registration its
33
50
  // completion evidence cites, read from the fix child's own store, for exactly
34
51
  // that package. Anything else has no time and never orders.
@@ -51,11 +68,17 @@ export function approvedReviewAt(state){
51
68
  &&Number.isSafeInteger(registration.registeredAt)?registration.registeredAt:null;
52
69
  }
53
70
 
71
+ const statVersion=stat=>stat?[stat.dev,stat.ino,stat.size,stat.mtimeMs,stat.ctimeMs].join(':'):null;
72
+ // A cm-fix run completes through its closeout rows in the run log, not its
73
+ // journal, so its entry also follows the log's version.
74
+ function logVersion(specsRoot){try{return statVersion(fs.lstatSync(path.join(specsRoot,'运行日志.jsonl')));}catch{return null;}}
54
75
  function cachedDelivery(specsRoot,repositoryId,runId,stat){
55
- const slot=[specsRoot,repositoryId,runId].join('\0');
56
- const version=[stat.dev,stat.ino,stat.size,stat.mtimeMs,stat.ctimeMs].join(':');
57
- if(cache.get(slot)?.version!==version)cache.set(slot,{version,delivery:readDelivery(specsRoot,{repositoryId,runId})});
58
- return cache.get(slot).delivery;
76
+ const slot=[specsRoot,repositoryId,runId].join('\0'),version=statVersion(stat),hit=cache.get(slot);
77
+ if(hit?.version===version&&(!hit.fix||hit.log===logVersion(specsRoot)))return hit.delivery;
78
+ // Read the log version first: an append during the read is seen next time.
79
+ const log=logVersion(specsRoot),read={fix:false},delivery=readDelivery(specsRoot,{repositoryId,runId},read);
80
+ cache.set(slot,{version,fix:read.fix,log,delivery});
81
+ return delivery;
59
82
  }
60
83
 
61
84
  // Resolve recorded steps to the real, completed, later reviewed packages of the
@@ -121,7 +121,7 @@ export function prepareReviewedEvidenceSupersession({specsDir,codeProject,featur
121
121
  if(first.version!==3)unavailable(`旧运行 ${entry.name} 的 journal 版本无法验证`);
122
122
  const history=readRunnerHistory(snapshot.records,first.config,3);
123
123
  if(history.pending){
124
- const exit=history.pendingAbandonable?'abandon_effect':
124
+ const exit=history.pendingAbandonable||history.pendingInterruptible||history.pendingReviewExhausted?'abandon_effect':
125
125
  history.pending.kind==='review'&&history.state.reviewInvocation?.registration
126
126
  &&history.state.reviewInvocation.result===null?'abandon_review':'原运行恢复入口';
127
127
  unavailable(`旧运行 ${entry.name} 的 ${history.pending.kind} effect 已中断且未结;先确认旧 host 和子进程已退出,再在原 run 上使用 ${exit},随后重新发起 supersede`);
@@ -176,6 +176,45 @@ function observeImage(owner,p) {
176
176
  }catch{/* Unsafe/missing/changed target is observation conflict, not write authority. */}
177
177
  return observation;
178
178
  }
179
+ // A45: the host died after the commit intent and before its result. Only the
180
+ // journaled plan is followed. tasks.md already holding the planned bytes is the
181
+ // finished commit (observed_after). tasks.md still holding the exact bytes and
182
+ // revision the plan started from, every planned evidence revision unchanged and
183
+ // the reviewed code still in place (beforeRollForward) lets the planned rename
184
+ // finish now. Anything else is a conflict for a person; nothing is compensated.
185
+ export function recoverRunnerCommitImage(owner,intent,beforeRollForward){
186
+ need(typeof beforeRollForward==='function','invalid_input');
187
+ const observation=observeImage(owner,intent);
188
+ if(observation==='observed_after')return 'observed_after';
189
+ need(observation==='observed_before','commit_recovery_conflict');
190
+ const {plan,parent}=intent,{after}=planBytes(plan);
191
+ try{
192
+ need(equal(parentRevision(parent.path),parent),'snapshot_changed');
193
+ for(const e of plan.evidence)need(nativeRevision(e.path,readFile(e.path))===e.revision,'snapshot_changed');
194
+ need(nativeRevision(owner.tasksPath,readFile(owner.tasksPath))===plan.taskRevision,'snapshot_changed');
195
+ }catch{need(false,'commit_recovery_conflict');}
196
+ try{beforeRollForward();}catch{need(false,'commit_recovery_code_changed');}
197
+ // The interrupted writer's own temporary file: removed only while its bytes
198
+ // are a prefix of the planned image (it can be nothing else of ours).
199
+ const leftover=path.join(parent.path,intent.temporaryName);
200
+ try{const f=readFile(leftover);need(after.subarray(0,f.bytes.length).equals(f.bytes),'commit_recovery_conflict');fs.unlinkSync(leftover);}
201
+ catch(error){if(error.code==='commit_recovery_conflict')throw error;if(error.code!=='ENOENT')need(false,'commit_recovery_conflict');}
202
+ const temporary=path.join(parent.path,`.cm-task.${randomUUID()}.tmp`);let fd;
203
+ try{
204
+ fd=fs.openSync(temporary,fs.constants.O_WRONLY|fs.constants.O_CREAT|fs.constants.O_EXCL|fs.constants.O_NOFOLLOW,0o600);
205
+ fs.writeFileSync(fd,after);fs.fchmodSync(fd,plan.mode);fs.fsyncSync(fd);fs.closeSync(fd);fd=undefined;
206
+ const written=readFile(temporary);need(written.bytes.equals(after)&&mode(written.stat)===plan.mode,'temporary_changed');
207
+ need(nativeRevision(owner.tasksPath,readFile(owner.tasksPath))===plan.taskRevision,'snapshot_changed');
208
+ fs.renameSync(temporary,owner.tasksPath);
209
+ const dir=fs.openSync(parent.path,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
210
+ try{fs.fsyncSync(dir);}finally{fs.closeSync(dir);}
211
+ }catch{
212
+ if(fd!==undefined)try{fs.closeSync(fd);}catch{/* retain unknown */}
213
+ need(false,'commit_unknown');
214
+ }
215
+ need(observeImage(owner,intent)==='observed_after','commit_unknown');
216
+ return 'observed_before_finished';
217
+ }
179
218
  export function observeFixtureCommit(store) {
180
219
  const owner=taskOwnerTarget(store);let h;
181
220
  try{h=history(store,owner);}catch(error){if(error.code==='commit_missing')throw error;need(false,'commit_history_invalid');}