@aibyzero/cm-workflow 0.16.4 → 0.16.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +8 -0
  3. package/CHANGELOG.md +50 -0
  4. package/README.md +12 -1
  5. package/VERSION +1 -1
  6. package/docs/installation.md +21 -1
  7. package/docs/js-workflow-control.md +245 -33
  8. package/docs/runtime-failover.md +1 -1
  9. package/package.json +1 -1
  10. package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
  11. package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
  12. package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
  13. package/runtime/js/cm-ai/cm-ai-admission.mjs +115 -41
  14. package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
  15. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +137 -22
  16. package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
  17. package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
  18. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +180 -53
  19. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
  20. package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
  21. package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
  22. package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
  23. package/runtime/js/cm-ai/drive-bootstrap.mjs +305 -0
  24. package/runtime/js/cm-ai/drive-core.mjs +39 -7
  25. package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
  26. package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
  27. package/runtime/js/cm-ai/effect-contract.mjs +44 -2
  28. package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
  29. package/runtime/js/cm-ai/execution-store.mjs +6 -4
  30. package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
  31. package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
  32. package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
  33. package/runtime/js/cm-ai/host-handoff.mjs +13 -6
  34. package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
  35. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
  36. package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
  37. package/runtime/js/cm-ai/host-session.mjs +12 -4
  38. package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
  39. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +13 -4
  40. package/runtime/js/cm-ai/host.mjs +1 -1
  41. package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
  42. package/runtime/js/cm-ai/log-rows.mjs +21 -0
  43. package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
  44. package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
  45. package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
  46. package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
  47. package/runtime/js/cm-ai/review-package.mjs +427 -31
  48. package/runtime/js/cm-ai/review-runner.mjs +47 -1
  49. package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
  50. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
  51. package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
  52. package/runtime/js/cm-ai/specification-material.mjs +154 -12
  53. package/runtime/js/cm-ai/task-commit.mjs +2 -2
  54. package/runtime/js/cm-ai/task-runner.mjs +502 -65
  55. package/runtime/js/cm-fix/execution.mjs +109 -25
  56. package/runtime/js/cm-fix/host-review.mjs +7 -3
  57. package/runtime/js/cm-fix/host.mjs +3 -1
  58. package/runtime/js/cm-fix/progress.mjs +1 -0
  59. package/runtime/js/cm-fix/protected-edits.mjs +15 -4
  60. package/runtime/js/cm-fix/qa-source.mjs +6 -4
  61. package/runtime/js/cm-prd/analysis.mjs +2 -1
  62. package/runtime/js/cm-prd/change.mjs +28 -10
  63. package/runtime/js/cm-prd/draft.mjs +5 -2
  64. package/runtime/js/cm-prd/review-preparation.mjs +10 -3
  65. package/runtime/js/cm-prd/review-publication.mjs +4 -2
  66. package/runtime/js/cm-prd/self-check.mjs +6 -3
  67. package/runtime/js/cm-prd/summary.mjs +3 -1
  68. package/runtime/js/cm-prd/validation-reason.mjs +20 -0
  69. package/runtime/js/spec-task-line.mjs +117 -0
  70. package/runtime/js/specs-status.mjs +10 -3
  71. package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
  72. package/scripts/cm-ai-admission.mjs +18 -11
  73. package/scripts/cm-ai-admission.test.mjs +65 -1
  74. package/scripts/cm-ai-batch-drive.mjs +92 -20
  75. package/scripts/cm-ai-batch-drive.test.mjs +164 -3
  76. package/scripts/cm-ai-batch-host.mjs +27 -11
  77. package/scripts/cm-ai-batch-host.test.mjs +2 -1
  78. package/scripts/cm-ai-batch-run.mjs +33 -10
  79. package/scripts/cm-ai-batch-run.test.mjs +56 -5
  80. package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
  81. package/scripts/cm-ai-bootstrap-flow.test.mjs +158 -0
  82. package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
  83. package/scripts/cm-ai-bootstrap.test.mjs +99 -7
  84. package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
  85. package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -0
  86. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
  87. package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
  88. package/scripts/cm-ai-drive.mjs +479 -47
  89. package/scripts/cm-ai-drive.test.mjs +240 -10
  90. package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
  91. package/scripts/cm-ai-host.mjs +84 -25
  92. package/scripts/cm-ai-host.test.mjs +232 -12
  93. package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
  94. package/scripts/cm-ai-multi-root.test.mjs +9 -3
  95. package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
  96. package/scripts/cm-ai-qa-config-revision.test.mjs +166 -15
  97. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
  98. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
  99. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
  100. package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
  101. package/scripts/cm-ai-review-failure.test.mjs +917 -0
  102. package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
  103. package/scripts/cm-ai-review-timeout.test.mjs +199 -4
  104. package/scripts/cm-ai-run.mjs +160 -60
  105. package/scripts/cm-ai-run.test.mjs +4 -3
  106. package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
  107. package/scripts/cm-ai-selection-guard.test.mjs +100 -0
  108. package/scripts/cm-ai-session-chain.test.mjs +7 -3
  109. package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
  110. package/scripts/cm-ai-supersede.test.mjs +571 -17
  111. package/scripts/cm-ai-verification-gate.test.mjs +2 -1
  112. package/scripts/cm-capability-gate.test.mjs +21 -2
  113. package/scripts/cm-check-drive.test.mjs +1 -1
  114. package/scripts/cm-check-host.test.mjs +1 -1
  115. package/scripts/cm-check-runtime.sh +1 -1
  116. package/scripts/cm-claude-developer-worker.test.mjs +3 -1
  117. package/scripts/cm-claude-probe.test.mjs +9 -1
  118. package/scripts/cm-claude-review-stream.test.mjs +25 -0
  119. package/scripts/cm-claude-worker.test.mjs +11 -4
  120. package/scripts/cm-codex-developer-worker.test.mjs +4 -2
  121. package/scripts/cm-failover.mjs +8 -8
  122. package/scripts/cm-fix-abandon.test.mjs +123 -5
  123. package/scripts/cm-fix-cause-package.test.mjs +2 -0
  124. package/scripts/cm-fix-drive.mjs +45 -13
  125. package/scripts/cm-fix-drive.test.mjs +36 -1
  126. package/scripts/cm-fix-host.mjs +9 -6
  127. package/scripts/cm-fix-review-budget.test.mjs +141 -0
  128. package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
  129. package/scripts/cm-host-check.test.mjs +6 -3
  130. package/scripts/cm-host-qa-executor.test.mjs +192 -17
  131. package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
  132. package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
  133. package/scripts/cm-log-event.mjs +17 -0
  134. package/scripts/cm-log-event.test.mjs +31 -0
  135. package/scripts/cm-prd-completion.test.mjs +75 -0
  136. package/scripts/cm-prd-draft.test.mjs +14 -0
  137. package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
  138. package/scripts/cm-prd-review-gate.mjs +126 -81
  139. package/scripts/cm-prd-review-gate.test.mjs +105 -1
  140. package/scripts/cm-prd-review-preparation.test.mjs +15 -0
  141. package/scripts/cm-prd-review-publication.test.mjs +6 -0
  142. package/scripts/cm-prd-self-check.test.mjs +6 -0
  143. package/scripts/cm-prd-summary.test.mjs +9 -0
  144. package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
  145. package/scripts/cm-review-inventory.test.mjs +253 -1
  146. package/scripts/cm-spec-manifest.mjs +28 -10
  147. package/scripts/cm-spec-manifest.test.mjs +8 -4
  148. package/scripts/cm-spec-task-line.test.mjs +138 -0
  149. package/scripts/cm-specs-status.test.mjs +12 -1
  150. package/scripts/cm-task-gate.mjs +18 -10
  151. package/scripts/cm-task-gate.py +1 -1
  152. package/scripts/cm-test-branch-impact.test.mjs +6 -3
  153. package/scripts/fixtures/claude-review-process.mjs +1 -0
  154. package/scripts/fixtures/process-cleanup.mjs +99 -0
  155. package/scripts/test-cm-log-event.py +2 -0
  156. package/scripts/test-cm-prd-review-gate.py +2 -1
  157. package/scripts/test-npm-install.py +1 -1
  158. package/scripts/test-scan-public-safety.py +1 -1
  159. package/scripts/test-spec-manifest.py +16 -8
  160. package/scripts/test-task-gate.py +2 -2
  161. package/scripts/test-workflow-config.py +1 -0
  162. package/scripts/validate-public-repo.py +1 -0
  163. package/skills/cm-ai/references/N1-init.md +1 -1
  164. package/skills/cm-ai/references/js-host.md +261 -42
  165. package/skills/cm-fix/references/js-host.md +22 -1
  166. package/skills/cm-prd/references/js-change-recovery.md +1 -1
  167. package/skills/cm-prd/references/js-host.md +6 -0
@@ -5,9 +5,27 @@ import {validateHostWorkflowConfiguration} from './host-workflow-capabilities.mj
5
5
  import {preQaConfigurations,readQaAttachment} from './qa-attachment.mjs';
6
6
 
7
7
  const workflow=material=>material.execution?.workflow?.configuration??material.execution?.workflow;
8
+ const BUILT_IN='cm-host-qa-executor-v1';
9
+ // Store fingerprint form of a QA executor. The built-in executor's plan (the
10
+ // loaded project/user CM config and the mode, case count, cases, commands and
11
+ // stage order derived from it) follows .cm-workflow.yml, ~/.cm-workflow/
12
+ // runtimes.yml and the plugin's built-in defaults, all of which legitimately
13
+ // change during a project. Version 2 binds only the host's QA inputs; each QA
14
+ // round freezes its own plan at N6 (prepare) and records mode/case_count in its
15
+ // test_run rows. Version 1 is the historical form: stores created with it keep
16
+ // opening only while their original configuration is unchanged.
17
+ export function hasLegacyQaPlanFingerprint(executor){return executor?.configuration?.kind===BUILT_IN;}
18
+ export function qaExecutorMaterial(executor,legacy=false){
19
+ if(legacy||!hasLegacyQaPlanFingerprint(executor))return {version:1,mode:executor.mode,caseCount:executor.caseCount,
20
+ timeoutMs:executor.timeoutMs,...(Object.hasOwn(executor,'configuration')?{configuration:executor.configuration}:{})};
21
+ const {plan,...configuration}=executor.configuration;
22
+ return {version:2,timeoutMs:executor.timeoutMs,configuration};
23
+ }
8
24
  export function qaConfigurationSlice(material){
9
25
  const qa=workflow(material)?.qa,executor=material.qaExecutor,c=executor?.configuration;
10
- need(qa&&c?.kind==='cm-host-qa-executor-v1','qa_revision_configuration_required');
26
+ need(qa&&c?.kind===BUILT_IN,'qa_revision_configuration_required');
27
+ if(executor.version===2)return json({qa,timeoutMs:executor.timeoutMs,
28
+ executor:{commands:c.commands,environment:c.environment,timeoutMs:c.timeoutMs}});
11
29
  return json({qa,mode:executor.mode,caseCount:executor.caseCount,timeoutMs:executor.timeoutMs,
12
30
  executor:{commands:c.commands,environment:c.environment,timeoutMs:c.timeoutMs,
13
31
  commandsPlan:c.plan.commands,modes:c.plan.modes}});
@@ -15,12 +33,15 @@ export function qaConfigurationSlice(material){
15
33
  function withQaConfiguration(material,slice){
16
34
  const result=structuredClone(json(material)),c=result.qaExecutor.configuration;
17
35
  workflow(result).qa=slice.qa;
18
- Object.assign(result.qaExecutor,{mode:slice.mode,caseCount:slice.caseCount,timeoutMs:slice.timeoutMs});
19
36
  Object.assign(c,{commands:slice.executor.commands,environment:slice.executor.environment,timeoutMs:slice.executor.timeoutMs});
37
+ if(result.qaExecutor.version===2){result.qaExecutor.timeoutMs=slice.timeoutMs;return result;}
38
+ Object.assign(result.qaExecutor,{mode:slice.mode,caseCount:slice.caseCount,timeoutMs:slice.timeoutMs});
20
39
  Object.assign(c.plan,{commands:slice.executor.commandsPlan,modes:slice.executor.modes});
21
40
  return result;
22
41
  }
23
42
  export function qaInvariantDigest(material){
43
+ if(material.qaExecutor?.version===2)return digest(withQaConfiguration(material,{qa:null,timeoutMs:null,
44
+ executor:{commands:null,environment:null,timeoutMs:null}}));
24
45
  return digest(withQaConfiguration(material,{qa:null,mode:null,caseCount:null,timeoutMs:null,
25
46
  executor:{commands:null,environment:null,timeoutMs:null,commandsPlan:null,modes:null}}));
26
47
  }
@@ -30,30 +51,43 @@ export function previousQaMaterial(material,previousWorkflow){
30
51
  need(prior.qa!==null,'qa_revision_configuration_required');
31
52
  need(digest({...prior,qa:null})===digest({...current,qa:null}),'fingerprint_mismatch');
32
53
  const result=structuredClone(json(material)),{kind,plan,capabilities,...configuration}=result.qaExecutor.configuration;
33
- need(kind==='cm-host-qa-executor-v1','qa_revision_configuration_required');
34
- // Rebuild the old plan using the same executor validator and unchanged project
35
- // policy. These callbacks are capability markers and are never dispatched.
54
+ need(kind===BUILT_IN,'qa_revision_configuration_required');
55
+ // Rebuild the old executor with the same validator. A version 2 fingerprint
56
+ // carries no plan, so the current CM config cannot make the previous one
57
+ // irreproducible; version 1 still rebuilds its plan from the current policy.
58
+ // These callbacks are capability markers and are never dispatched.
36
59
  const executor=createHostQaExecutor({...configuration,commands:prior.qa.commands,environment:prior.qa.environment,
37
60
  ...(capabilities.logic?{logic:()=>{}}:{}),...(capabilities.browser?{browser:()=>{}}:{})});
38
- result.qaExecutor={version:1,mode:executor.mode,caseCount:executor.caseCount,timeoutMs:executor.timeoutMs,configuration:executor.configuration};
61
+ result.qaExecutor=qaExecutorMaterial(executor,result.qaExecutor.version!==2);
39
62
  workflow(result).qa=prior.qa;
40
63
  need(qaInvariantDigest(result)===qaInvariantDigest(material),'fingerprint_mismatch');
41
64
  return result;
42
65
  }
66
+ // qaRound 0 with testRunId null records a revision made before any QA round
67
+ // ran: nothing is superseded and no round is consumed. packageDigest is the
68
+ // task's current review package, or null before one exists.
69
+ export const beforeFirstQaRound=r=>r.qaRound===0;
43
70
  export function readQaConfigRevision(raw){
44
71
  const r=json(raw);
45
72
  shape(r,['version','fromFingerprint','toFingerprint','invariantDigest','previousQaDigest','qaDigest','reason','hostContextId',
46
73
  'revisedAt','packageDigest','testRunId','qaRound','taskAttempt']);
47
74
  need(r.version===1,'qa_revision_invalid');
48
- for(const key of ['fromFingerprint','toFingerprint','invariantDigest','packageDigest','previousQaDigest','qaDigest'])hex(r[key]);
75
+ for(const key of ['fromFingerprint','toFingerprint','invariantDigest','previousQaDigest','qaDigest'])hex(r[key]);
76
+ if(!(beforeFirstQaRound(r)&&r.packageDigest===null))hex(r.packageDigest);
49
77
  need(r.fromFingerprint!==r.toFingerprint&&r.previousQaDigest!==r.qaDigest,'qa_revision_unchanged');
50
- id(r.hostContextId);id(r.testRunId);text(r.reason);
78
+ id(r.hostContextId);
79
+ if(beforeFirstQaRound(r))need(r.testRunId===null,'qa_revision_invalid');else id(r.testRunId);
80
+ text(r.reason);
51
81
  need(r.reason.trim().length>0&&r.reason.length<=500&&!/[\r\n\0]/.test(r.reason),'qa_revision_authorization_required');
52
82
  need(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$/.test(r.revisedAt)&&Number.isFinite(Date.parse(r.revisedAt)),'qa_revision_invalid');
53
83
  need([1,2].includes(r.taskAttempt),'qa_revision_invalid');
54
- need(Number.isInteger(r.qaRound)&&r.qaRound>=1&&r.qaRound<3,'qa_round_invalid');
84
+ need(Number.isInteger(r.qaRound)&&r.qaRound>=0&&r.qaRound<3,'qa_round_invalid');
55
85
  return r;
56
86
  }
87
+ // Rounds strictly increase once QA has run; any number of revisions may
88
+ // precede the first round, and none may follow a completed round at round 0.
89
+ export const qaRevisionFollows=(next,previous)=>next.qaRound>previous.qaRound
90
+ ||beforeFirstQaRound(next)&&beforeFirstQaRound(previous);
57
91
  export function qaRevisionChain(snapshot){
58
92
  let fingerprint=snapshot.fingerprints.config,invariant=null,attached=false;const revisions=[];
59
93
  for(const row of snapshot.records){
@@ -65,7 +99,7 @@ export function qaRevisionChain(snapshot){
65
99
  const r=readQaConfigRevision(row.payload.record);
66
100
  need(r.fromFingerprint===fingerprint&&(invariant===null||r.invariantDigest===invariant)
67
101
  &&(!revisions.length||(r.previousQaDigest===revisions.at(-1).qaDigest
68
- &&r.qaRound>revisions.at(-1).qaRound)),'qa_revision_chain_invalid');
102
+ &&qaRevisionFollows(r,revisions.at(-1)))),'qa_revision_chain_invalid');
69
103
  fingerprint=r.toFingerprint;invariant=r.invariantDigest;revisions.push(r);
70
104
  }
71
105
  return {fingerprint,revisions};
@@ -0,0 +1,21 @@
1
+ // Repeating this projection on resume repairs a crash after the journal append.
2
+ import {spawnSync} from 'node:child_process';
3
+ import {fileURLToPath} from 'node:url';
4
+ import {digest,need} from './effect-contract.mjs';
5
+
6
+ const writer=fileURLToPath(new URL('../../../scripts/cm-log-event.py',import.meta.url));
7
+ export function recordReviewAbandonment({specsDir,codeProject,feature,identity,record,logHome,runtime='codex'}){
8
+ const p=record.payload;
9
+ const data={node:'N4',feature,task:identity.taskId,effect_id:p.effectId,
10
+ invocation_id:p.invocationId,registered_digest:p.registeredDigest,
11
+ started_digest:p.startedDigest,...(Object.hasOwn(p,'resultDigest')?{result_digest:p.resultDigest}:{}),
12
+ record_digest:record.digest,reason:p.reason};
13
+ const args=[writer,'--workflow','cm-ai','--event','review_abandoned','--runtime',runtime,
14
+ '--project-root',codeProject,'--specs-dir',specsDir,'--run-id',identity.runId,
15
+ '--at',p.at,'--detail',Object.hasOwn(p,'resultDigest')?'显式放弃结论未被接收的独立审查调用':'显式放弃无结果的独立审查调用',
16
+ '--data-json',JSON.stringify(data)];
17
+ const result=spawnSync('python3',args,{timeout:10000,maxBuffer:1024*1024,
18
+ ...(logHome?{env:{...process.env,CM_WORKFLOW_LOG_HOME:logHome}}:{})});
19
+ need(!result.error&&result.status===0,'review_abandon_log_failed');
20
+ return digest(data);
21
+ }