@aibyzero/cm-workflow 0.16.8 → 0.17.0

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 (226) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +31 -0
  3. package/README.md +22 -3
  4. package/VERSION +1 -1
  5. package/compat/claude-commands/cm-notify.md +3 -0
  6. package/docs/cm-control-policy-v2.md +331 -0
  7. package/docs/execution-optimizations.md +1 -1
  8. package/docs/external-models.md +3 -3
  9. package/docs/human-correction.md +5 -5
  10. package/docs/installation.md +1 -1
  11. package/docs/js-workflow-control.md +119 -78
  12. package/docs/next-steps.md +19 -2
  13. package/docs/untested-branches.md +2 -3
  14. package/docs/user-guide.md +105 -5
  15. package/package.json +2 -1
  16. package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
  17. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
  18. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
  19. package/runtime/js/cm-ai/code-projects.mjs +4 -1
  20. package/runtime/js/cm-ai/control-policy.mjs +111 -0
  21. package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
  22. package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
  23. package/runtime/js/cm-ai/drive-core.mjs +9 -0
  24. package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
  25. package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
  26. package/runtime/js/cm-ai/effect-contract.mjs +6 -1
  27. package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
  28. package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
  29. package/runtime/js/cm-ai/host-check.mjs +4 -1
  30. package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
  31. package/runtime/js/cm-ai/host-documentation.mjs +53 -12
  32. package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
  33. package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
  34. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
  35. package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
  36. package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
  37. package/runtime/js/cm-ai/host-review-file.mjs +1 -1
  38. package/runtime/js/cm-ai/host-session.mjs +1 -1
  39. package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
  40. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
  41. package/runtime/js/cm-ai/host.mjs +1 -2
  42. package/runtime/js/cm-ai/operator-guidance.mjs +89 -3
  43. package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
  44. package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
  45. package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
  46. package/runtime/js/cm-ai/review-package.mjs +26 -5
  47. package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
  48. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
  49. package/runtime/js/cm-ai/task-commit.mjs +39 -0
  50. package/runtime/js/cm-ai/task-runner.mjs +629 -121
  51. package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
  52. package/runtime/js/cm-ai/worker-claude.mjs +10 -3
  53. package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
  54. package/runtime/js/cm-fix/execution.mjs +176 -48
  55. package/runtime/js/cm-fix/host.mjs +2 -1
  56. package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
  57. package/runtime/js/cm-fix/progress.mjs +13 -3
  58. package/runtime/js/cm-fix/protected-edits.mjs +10 -3
  59. package/runtime/js/cm-fix/repair.mjs +11 -3
  60. package/runtime/js/cm-fix/test-author.mjs +10 -3
  61. package/runtime/js/cm-idea/session.mjs +67 -4
  62. package/runtime/js/cm-init/review-evidence.mjs +3 -1
  63. package/runtime/js/cm-prd/review-correction.mjs +10 -4
  64. package/runtime/js/cm-prd/review-host.mjs +1 -1
  65. package/runtime/js/cm-prd/review-publication.mjs +5 -3
  66. package/runtime/js/cm-prd/session.mjs +43 -0
  67. package/runtime/js/cm-refactor/records.mjs +98 -8
  68. package/runtime/js/cm-refactor/workflow.mjs +80 -10
  69. package/runtime/js/cm-test/host.mjs +10 -3
  70. package/runtime/js/cm-test/session.mjs +45 -6
  71. package/runtime/js/notify-safe-read.mjs +49 -0
  72. package/runtime/js/notify-send.mjs +313 -0
  73. package/runtime/js/notify.mjs +164 -37
  74. package/runtime/js/policy-binding-compat.mjs +55 -0
  75. package/runtime/review.md +52 -7
  76. package/runtime/task-gates.md +107 -9
  77. package/scripts/ci-test-shards.mjs +67 -0
  78. package/scripts/ci-test-shards.test.mjs +64 -0
  79. package/scripts/ci-test-weights.json +222 -0
  80. package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
  81. package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
  82. package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
  83. package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
  84. package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
  85. package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
  86. package/scripts/cm-ai-batch-drive.mjs +98 -34
  87. package/scripts/cm-ai-batch-drive.test.mjs +124 -16
  88. package/scripts/cm-ai-batch-host.mjs +167 -29
  89. package/scripts/cm-ai-batch-host.test.mjs +303 -31
  90. package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
  91. package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
  92. package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
  93. package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
  94. package/scripts/cm-ai-batch-run.mjs +213 -25
  95. package/scripts/cm-ai-batch-run.test.mjs +21 -341
  96. package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
  97. package/scripts/cm-ai-bootstrap.test.mjs +2 -3
  98. package/scripts/cm-ai-control-launch.test.mjs +219 -0
  99. package/scripts/cm-ai-control-policy.test.mjs +124 -0
  100. package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
  101. package/scripts/cm-ai-develop-answer-invalid.test.mjs +97 -0
  102. package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
  103. package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
  104. package/scripts/cm-ai-direct-review.test.mjs +348 -0
  105. package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
  106. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
  107. package/scripts/cm-ai-drive.mjs +142 -58
  108. package/scripts/cm-ai-drive.test.mjs +70 -84
  109. package/scripts/cm-ai-fix-integration.test.mjs +3 -5
  110. package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
  111. package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
  112. package/scripts/cm-ai-host-cli-workflow.test.mjs +267 -0
  113. package/scripts/cm-ai-host-fixture.mjs +296 -0
  114. package/scripts/cm-ai-host-protected.test.mjs +253 -0
  115. package/scripts/cm-ai-host.mjs +122 -100
  116. package/scripts/cm-ai-host.test.mjs +35 -776
  117. package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
  118. package/scripts/cm-ai-legacy-history.test.mjs +53 -0
  119. package/scripts/cm-ai-light-modules.test.mjs +54 -0
  120. package/scripts/cm-ai-multi-root.test.mjs +4 -4
  121. package/scripts/cm-ai-nested-execution.test.mjs +16 -19
  122. package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
  123. package/scripts/cm-ai-progress.test.mjs +10 -8
  124. package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
  125. package/scripts/cm-ai-protected-scope.test.mjs +8 -5
  126. package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
  127. package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
  128. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
  129. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +95 -13
  130. package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
  131. package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
  132. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +59 -14
  133. package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
  134. package/scripts/cm-ai-review-failure.test.mjs +137 -32
  135. package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
  136. package/scripts/cm-ai-review-timeout.test.mjs +132 -67
  137. package/scripts/cm-ai-run.mjs +91 -28
  138. package/scripts/cm-ai-run.test.mjs +11 -38
  139. package/scripts/cm-ai-selection-guard.test.mjs +2 -2
  140. package/scripts/cm-ai-session-chain.test.mjs +18 -15
  141. package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
  142. package/scripts/cm-ai-supersede.test.mjs +489 -51
  143. package/scripts/cm-blocked-reason.test.mjs +2 -3
  144. package/scripts/cm-capability-gate.test.mjs +33 -1
  145. package/scripts/cm-check-drive-files.mjs +8 -0
  146. package/scripts/cm-check-drive.test.mjs +2 -5
  147. package/scripts/cm-check-runtime.sh +4 -2
  148. package/scripts/cm-claude-developer-worker.test.mjs +15 -0
  149. package/scripts/cm-claude-review-stream.test.mjs +21 -16
  150. package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
  151. package/scripts/cm-claude-worker.test.mjs +23 -5
  152. package/scripts/cm-controlled-correction.test.mjs +469 -0
  153. package/scripts/cm-external-batch-host.test.mjs +30 -11
  154. package/scripts/cm-external-model-host.test.mjs +1 -1
  155. package/scripts/cm-external-model-recovery.test.mjs +32 -12
  156. package/scripts/cm-external-qa-fix.test.mjs +1 -1
  157. package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
  158. package/scripts/cm-fix-abandon.test.mjs +163 -10
  159. package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
  160. package/scripts/cm-fix-drive.mjs +25 -7
  161. package/scripts/cm-fix-host.mjs +8 -7
  162. package/scripts/cm-fix-review-budget.test.mjs +13 -0
  163. package/scripts/cm-fix-review-recovery.test.mjs +36 -1
  164. package/scripts/cm-host-answer-timeout.test.mjs +65 -0
  165. package/scripts/cm-host-call-kinds.test.mjs +28 -0
  166. package/scripts/cm-host-documentation.test.mjs +49 -0
  167. package/scripts/cm-host-qa-executor.test.mjs +23 -12
  168. package/scripts/cm-host-qa-policy.test.mjs +43 -16
  169. package/scripts/cm-host-review-authority.test.mjs +0 -31
  170. package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
  171. package/scripts/cm-idea-drive.mjs +49 -11
  172. package/scripts/cm-idea-drive.test.mjs +66 -0
  173. package/scripts/cm-idea-host.mjs +106 -16
  174. package/scripts/cm-init-answer-gaps.test.mjs +258 -0
  175. package/scripts/cm-init-drive.mjs +41 -7
  176. package/scripts/cm-init-host.mjs +61 -12
  177. package/scripts/cm-knowledge-closeout.test.mjs +3 -3
  178. package/scripts/cm-log-event.mjs +21 -10
  179. package/scripts/cm-notify-command.test.mjs +936 -0
  180. package/scripts/cm-notify-read-drift.test.mjs +270 -0
  181. package/scripts/cm-notify.mjs +481 -0
  182. package/scripts/cm-notify.test.mjs +312 -23
  183. package/scripts/cm-patrol.test.mjs +3 -2
  184. package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
  185. package/scripts/cm-prd-drive.mjs +18 -5
  186. package/scripts/cm-prd-drive.test.mjs +15 -0
  187. package/scripts/cm-prd-host.mjs +37 -4
  188. package/scripts/cm-prd-review-disposition.test.mjs +6 -1
  189. package/scripts/cm-prd-review-gate.mjs +56 -0
  190. package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
  191. package/scripts/cm-refactor-drive.mjs +52 -8
  192. package/scripts/cm-refactor-drive.test.mjs +44 -0
  193. package/scripts/cm-refactor-host.test.mjs +10 -6
  194. package/scripts/cm-release-smoke.sh +2 -0
  195. package/scripts/cm-task-gate-correction.test.mjs +69 -16
  196. package/scripts/cm-task-gate.mjs +368 -34
  197. package/scripts/cm-task-gate.py +2 -0
  198. package/scripts/cm-task-gate.test.mjs +252 -4
  199. package/scripts/cm-test-answer-gaps.test.mjs +151 -0
  200. package/scripts/cm-test-drive.mjs +21 -5
  201. package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
  202. package/scripts/fixtures/claude-review-process.mjs +1 -1
  203. package/scripts/fixtures/native-gate-fixture.mjs +18 -0
  204. package/scripts/policy-binding-compat.test.mjs +103 -0
  205. package/scripts/scan-public-safety.py +4 -0
  206. package/scripts/validate-public-repo.py +4 -0
  207. package/skills/cm-ai/SKILL.md +8 -6
  208. package/skills/cm-ai/references/N3-execute-task.md +17 -2
  209. package/skills/cm-ai/references/N4-review.md +11 -21
  210. package/skills/cm-ai/references/N5-mark-done.md +1 -1
  211. package/skills/cm-ai/references/N6-qa-eval.md +49 -21
  212. package/skills/cm-ai/references/js-host-modes.md +35 -14
  213. package/skills/cm-ai/references/js-host-qa-recovery.md +85 -11
  214. package/skills/cm-ai/references/js-host-recovery.md +181 -21
  215. package/skills/cm-ai/references/js-host.md +76 -32
  216. package/skills/cm-check/SKILL.md +3 -3
  217. package/skills/cm-fix/SKILL.md +12 -0
  218. package/skills/cm-fix/references/js-host.md +44 -5
  219. package/skills/cm-idea/references/js-host.md +27 -2
  220. package/skills/cm-init/references/js-host.md +17 -4
  221. package/skills/cm-notify/SKILL.md +34 -0
  222. package/skills/cm-prd/references/js-change-recovery.md +35 -1
  223. package/skills/cm-prd/references/js-host.md +1 -1
  224. package/skills/cm-refactor/SKILL.md +12 -0
  225. package/skills/cm-refactor/references/js-host.md +17 -0
  226. package/skills/cm-test/references/js-host.md +14 -1
@@ -316,7 +316,7 @@ export function reviewSpecsPath(root,specsRoot) {
316
316
  need(root!==specsRoot&&!root.startsWith(specsRoot+path.sep),'overlapping_roots');
317
317
  return specsRoot.startsWith(root+path.sep)?filePath(path.relative(root,specsRoot).split(path.sep).join('/')):null;
318
318
  }
319
- function snapshot(root,specsPath=null,projectPaths=null,retainedPaths=[],selected=null,policy=null) {
319
+ function snapshot(root,specsPath=null,projectPaths=null,retainedPaths=[],selected=null,policy=null,inventoryOnly=false) {
320
320
  if(specsPath!==null){
321
321
  const target=path.join(root,specsPath);
322
322
  need(fs.realpathSync(target)===target&&fs.lstatSync(target).isDirectory(),'unsupported_path');
@@ -324,9 +324,9 @@ function snapshot(root,specsPath=null,projectPaths=null,retainedPaths=[],selecte
324
324
  const files=[],seen=new Set(); let total=0,materialBytes=0,materialCount=0,visitedSpecs=false;
325
325
  function add(p,s){
326
326
  if(!s.isFile()||s.isSymbolicLink()||s.nlink!==1)throw diagnostic('unsupported_file',p);
327
- const includeContent=selected===null||materialPath(p,selected);
328
- const countLimit=selected===null?FILE_COUNT:INVENTORY_COUNT;
329
- const byteLimit=selected===null?SNAPSHOT_LIMIT:INVENTORY_LIMIT;
327
+ const includeContent=!inventoryOnly&&(selected===null||materialPath(p,selected));
328
+ const countLimit=selected===null&&!inventoryOnly?FILE_COUNT:INVENTORY_COUNT;
329
+ const byteLimit=selected===null&&!inventoryOnly?SNAPSHOT_LIMIT:INVENTORY_LIMIT;
330
330
  if(files.length>=countLimit)throw diagnostic('limit_exceeded',p,`file count > ${countLimit}`);
331
331
  if(total+s.size>byteLimit)throw diagnostic('limit_exceeded',p,`inventory bytes > ${byteLimit}`);
332
332
  if(includeContent&&materialCount>=FILE_COUNT)
@@ -354,7 +354,14 @@ function snapshot(root,specsPath=null,projectPaths=null,retainedPaths=[],selecte
354
354
  try { names=fs.readdirSync(path.join(root,rel)).sort(); } catch { fail('read_failed'); }
355
355
  for(const name of names) {
356
356
  const p=rel ? rel+'/'+name : name;
357
+ // Compatibility evidence is outside the code inventory: only the code
358
+ // root's own .reviews and the specs subtree. A nested directory that
359
+ // merely shares the name is ordinary code and stays in the inventory.
360
+ // Existing JS snapshots retain their historical selection and record shape.
357
361
  let s; try { s=fs.lstatSync(path.join(root,p)); } catch { fail('read_failed'); }
362
+ if(inventoryOnly&&p==='.reviews'&&p!==specsPath){
363
+ need(s.isDirectory()&&!s.isSymbolicLink(),'unsupported_path');continue;
364
+ }
358
365
  // Linked worktrees use a regular .git pointer file instead of a directory.
359
366
  // Treat both as Git metadata, never read/follow the pointer or traverse it.
360
367
  // Scope and requirement paths still cannot select any .git entry.
@@ -874,7 +881,16 @@ export function verifyCompletionReviewPackage(options) {
874
881
  const checkIdentities=checks=>checks.map(c=>c.kind==='visual'
875
882
  ?{id:c.id,kind:c.kind}
876
883
  :{id:c.id,command:c.command});
877
- need(digest(checkIdentities(current.checks))===digest(checkIdentities(v.reviewPackage.checks)),'package_mismatch');
884
+ // A42: the completion re-check answered with another check list (ids or
885
+ // commands) than the reviewed delivery. The code is unchanged, so this is a
886
+ // retryable re-check block that names the difference, not a terminal mismatch.
887
+ if(digest(checkIdentities(current.checks))!==digest(checkIdentities(v.reviewPackage.checks))){
888
+ const ids=checks=>checks.map(c=>String(c.id)).join(', ').slice(0,600)||'(无)';
889
+ const sameIds=ids(current.checks)===ids(v.reviewPackage.checks);
890
+ throw Object.assign(new Error(`completion_checks_changed: 完成复查的检查清单与审查包不一致(${sameIds
891
+ ?`编号相同但命令不同:${ids(current.checks)}`:`审查包:${ids(v.reviewPackage.checks)};本次:${ids(current.checks)}`})。按审查包的检查清单原样重跑后再发送 complete`),
892
+ {code:'completion_checks_changed'});
893
+ }
878
894
  const checkResults=checks=>checks.map(c=>c.kind==='visual'
879
895
  ?{outcome:c.outcome}
880
896
  :{outcome:c.outcome,exitCode:c.exitCode});
@@ -915,3 +931,8 @@ export function readReviewBaseline(raw) {
915
931
  export function readReviewPackage(raw) {
916
932
  const value=plain(raw);validPackage(value);return freeze(value);
917
933
  }
934
+
935
+ // Reuse the same bounded scanner and two-sided stable policy for compatibility
936
+ // inventories; the default snapshot mode above is unchanged for JS callers.
937
+ export {snapshot,rootPath,stableIgnorePolicy,stablePublicPolicy,stableSnapshotPolicy,
938
+ comparableFiles,validateStablePolicy,filePath,INVENTORY_COUNT,INVENTORY_LIMIT};
@@ -64,7 +64,7 @@ export function fixReviewedAt(specsRoot,evidence){
64
64
  // Journals without a registered V3 review have no order and never qualify.
65
65
  export function approvedReviewAt(state){
66
66
  const registration=state?.reviewInvocation?.registration;
67
- return registration&&registration.grant?.packageDigest===state.reviewPackage?.packageDigest
67
+ return registration&&registration.binding?.packageDigest===state.reviewPackage?.packageDigest
68
68
  &&Number.isSafeInteger(registration.registeredAt)?registration.registeredAt:null;
69
69
  }
70
70
 
@@ -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');}