@aibyzero/cm-workflow 0.16.5 → 0.16.6

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 (177) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +14 -0
  3. package/CHANGELOG.md +7 -0
  4. package/README.md +11 -4
  5. package/THIRD_PARTY_NOTICES.md +9 -0
  6. package/VERSION +1 -1
  7. package/docs/architecture.md +43 -0
  8. package/docs/execution-optimizations.md +33 -0
  9. package/docs/external-models.md +114 -0
  10. package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
  11. package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
  12. package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
  13. package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
  14. package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
  15. package/docs/human-correction.md +31 -0
  16. package/docs/installation.md +28 -7
  17. package/docs/js-workflow-control.md +48 -0
  18. package/docs/live-evidence-drivers.md +62 -0
  19. package/docs/next-steps.md +15 -10
  20. package/docs/untested-branches.md +27 -4
  21. package/docs/user-guide.md +23 -8
  22. package/install-codex.sh +28 -11
  23. package/package.json +1 -1
  24. package/runtime/js/cm-ai/claude-review-adapter.mjs +7 -4
  25. package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
  26. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +79 -20
  27. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +1 -4
  28. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +13 -57
  29. package/runtime/js/cm-ai/codex-config.mjs +3 -2
  30. package/runtime/js/cm-ai/codex-review-adapter.mjs +34 -15
  31. package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
  32. package/runtime/js/cm-ai/drive-bootstrap.mjs +20 -10
  33. package/runtime/js/cm-ai/drive-core.mjs +9 -3
  34. package/runtime/js/cm-ai/durable-runner-state.mjs +117 -14
  35. package/runtime/js/cm-ai/effect-contract.mjs +1 -1
  36. package/runtime/js/cm-ai/execution-policy.mjs +58 -0
  37. package/runtime/js/cm-ai/external-group-models.mjs +53 -0
  38. package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
  39. package/runtime/js/cm-ai/external-models.mjs +52 -0
  40. package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
  41. package/runtime/js/cm-ai/host-bootstrap.mjs +70 -20
  42. package/runtime/js/cm-ai/host-check.mjs +30 -4
  43. package/runtime/js/cm-ai/host-conversation-execution.mjs +50 -16
  44. package/runtime/js/cm-ai/host-progress.mjs +80 -0
  45. package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
  46. package/runtime/js/cm-ai/host-qa-executor.mjs +2 -2
  47. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +22 -5
  48. package/runtime/js/cm-ai/host-session.mjs +1 -1
  49. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +3 -1
  50. package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
  51. package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
  52. package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
  53. package/runtime/js/cm-ai/live-evidence.mjs +96 -0
  54. package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
  55. package/runtime/js/cm-ai/model_configuration_write.py +214 -0
  56. package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
  57. package/runtime/js/cm-ai/operator-guidance.mjs +86 -0
  58. package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
  59. package/runtime/js/cm-ai/provider-review-observation.mjs +15 -0
  60. package/runtime/js/cm-ai/provider-usage.mjs +39 -0
  61. package/runtime/js/cm-ai/review-package.mjs +11 -0
  62. package/runtime/js/cm-ai/review-presentation.mjs +45 -0
  63. package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
  64. package/runtime/js/cm-ai/status-projection.mjs +93 -0
  65. package/runtime/js/cm-ai/task-runner.mjs +171 -25
  66. package/runtime/js/cm-ai/tool-preview.mjs +8 -4
  67. package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
  68. package/runtime/js/cm-ai/worker-claude.mjs +63 -19
  69. package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
  70. package/runtime/js/cm-ai/worker-codex.mjs +45 -19
  71. package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
  72. package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
  73. package/runtime/js/cm-fix/cause-package.mjs +10 -1
  74. package/runtime/js/cm-fix/execution.mjs +183 -40
  75. package/runtime/js/cm-fix/final-review.mjs +18 -10
  76. package/runtime/js/cm-fix/host-review.mjs +25 -6
  77. package/runtime/js/cm-fix/host.mjs +4 -1
  78. package/runtime/js/cm-fix/layout.mjs +1 -1
  79. package/runtime/js/cm-fix/progress.mjs +4 -0
  80. package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
  81. package/runtime/js/cm-prd/response-recovery.mjs +23 -0
  82. package/runtime/js/cm-prd/review-publication.mjs +23 -13
  83. package/runtime/js/cm-prd/review-time.mjs +29 -0
  84. package/runtime/js/cm-prd/session.mjs +53 -6
  85. package/runtime/js/cm-security/finalize.mjs +32 -0
  86. package/runtime/review.md +5 -0
  87. package/runtime/task-gates.md +6 -0
  88. package/runtime/workflow-config.md +10 -1
  89. package/scripts/cm-ai-batch-drive.mjs +50 -21
  90. package/scripts/cm-ai-batch-drive.test.mjs +47 -2
  91. package/scripts/cm-ai-batch-host.mjs +37 -14
  92. package/scripts/cm-ai-batch-run.mjs +71 -27
  93. package/scripts/cm-ai-bootstrap-flow.test.mjs +3 -2
  94. package/scripts/cm-ai-bootstrap-merge.test.mjs +118 -1
  95. package/scripts/cm-ai-bootstrap.test.mjs +80 -87
  96. package/scripts/cm-ai-conversation-entry-ops.test.mjs +15 -0
  97. package/scripts/cm-ai-develop-driver-gaps.test.mjs +102 -0
  98. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +2 -2
  99. package/scripts/cm-ai-drive.mjs +59 -25
  100. package/scripts/cm-ai-drive.test.mjs +97 -1
  101. package/scripts/cm-ai-host.mjs +64 -24
  102. package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
  103. package/scripts/cm-ai-progress.test.mjs +521 -0
  104. package/scripts/cm-ai-qa-config-revision.test.mjs +21 -0
  105. package/scripts/cm-ai-review-failure.test.mjs +71 -11
  106. package/scripts/cm-ai-run.mjs +58 -14
  107. package/scripts/cm-ai-run.test.mjs +2 -1
  108. package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
  109. package/scripts/cm-check-drive.test.mjs +1 -0
  110. package/scripts/cm-check-runtime.sh +11 -0
  111. package/scripts/cm-claude-install-layout.test.mjs +26 -0
  112. package/scripts/cm-claude-probe.test.mjs +1 -1
  113. package/scripts/cm-codex-plugin-metadata.py +83 -0
  114. package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
  115. package/scripts/cm-efficiency-checks.test.mjs +37 -0
  116. package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
  117. package/scripts/cm-efficiency-offline.mjs +35 -0
  118. package/scripts/cm-efficiency-policy.test.mjs +48 -0
  119. package/scripts/cm-efficiency-presentation.test.mjs +35 -0
  120. package/scripts/cm-efficiency-response.test.mjs +117 -0
  121. package/scripts/cm-efficiency-usage.test.mjs +148 -0
  122. package/scripts/cm-external-batch-host.test.mjs +157 -0
  123. package/scripts/cm-external-fix-host.test.mjs +281 -0
  124. package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
  125. package/scripts/cm-external-group-models.test.mjs +60 -0
  126. package/scripts/cm-external-model-host.test.mjs +180 -0
  127. package/scripts/cm-external-model-recovery.test.mjs +108 -0
  128. package/scripts/cm-external-models.test.mjs +89 -0
  129. package/scripts/cm-external-process-cleanup.test.mjs +71 -0
  130. package/scripts/cm-external-qa-fix.test.mjs +170 -0
  131. package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
  132. package/scripts/cm-fix-drive.mjs +28 -13
  133. package/scripts/cm-fix-final-review.test.mjs +11 -6
  134. package/scripts/cm-fix-host.mjs +17 -10
  135. package/scripts/cm-fix-protected-edits.test.mjs +12 -0
  136. package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
  137. package/scripts/cm-fix-review-budget.test.mjs +7 -1
  138. package/scripts/cm-host-qa-executor.test.mjs +21 -0
  139. package/scripts/cm-knowledge-closeout.test.mjs +160 -0
  140. package/scripts/cm-live-evidence.test.mjs +64 -0
  141. package/scripts/cm-log-event.mjs +8 -2
  142. package/scripts/cm-log-event.py +15 -0
  143. package/scripts/cm-model-setup.mjs +79 -0
  144. package/scripts/cm-prd-drive.mjs +32 -11
  145. package/scripts/cm-prd-drive.test.mjs +15 -0
  146. package/scripts/cm-prd-host.mjs +13 -4
  147. package/scripts/cm-release-smoke.sh +5 -1
  148. package/scripts/cm-runtime-i18n.mjs +15 -4
  149. package/scripts/cm-runtime-install.mjs +8 -4
  150. package/scripts/cm-runtime.mjs +116 -23
  151. package/scripts/cm-runtime.test.mjs +121 -12
  152. package/scripts/cm-security.test.mjs +32 -0
  153. package/scripts/cm-task-gate-correction.test.mjs +117 -0
  154. package/scripts/cm-task-gate.mjs +146 -10
  155. package/scripts/cm-task-gate.py +1 -0
  156. package/scripts/cm-test-drive.mjs +10 -4
  157. package/scripts/cm-test-drive.test.mjs +14 -1
  158. package/scripts/cm-tool-preview-context.test.mjs +12 -0
  159. package/scripts/cm-usage-report.py +22 -3
  160. package/scripts/cm-workflow-config.mjs +10 -1
  161. package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
  162. package/scripts/fixtures/live-evidence-driver.mjs +35 -0
  163. package/scripts/fixtures/process-cleanup.mjs +3 -1
  164. package/scripts/test-cm-native-usage.py +62 -0
  165. package/scripts/test-external-model-setup.py +91 -0
  166. package/scripts/test-model-configuration-write.py +201 -0
  167. package/scripts/test-npm-install.py +10 -1
  168. package/skills/cm-ai/SKILL.md +2 -2
  169. package/skills/cm-ai/references/N8-finish.md +5 -0
  170. package/skills/cm-ai/references/js-host.md +13 -5
  171. package/skills/cm-ai/references/knowledge-closeout.md +90 -0
  172. package/skills/cm-fix/SKILL.md +1 -1
  173. package/skills/cm-fix/references/js-host.md +30 -2
  174. package/skills/cm-runtime/SKILL.md +29 -6
  175. package/skills/cm-security/SKILL.md +4 -2
  176. package/skills/cm-security/references/scan-contract.md +1 -0
  177. package/templates/cm-workflow.yml +1 -1
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env node
2
+ import {readLaunchExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
3
+ import {readLaunchExternalModels} from '../runtime/js/cm-ai/external-model-launch.mjs';
4
+ import {loadExternalModels,externalPair} from '../runtime/js/cm-ai/external-models.mjs';
2
5
  // Opt-in current-conversation host. Review requires a separately authorized
3
6
  // attempt and the registered V3 boundary; preflight is only local diagnostics.
7
+ import {selectExternalModels} from '../runtime/js/cm-ai/external-models.mjs';
4
8
  import fs from 'node:fs';
5
9
  import path from 'node:path';
6
10
  import {spawnSync} from 'node:child_process';
@@ -47,7 +51,7 @@ const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-
47
51
  'abandon-review','test-author','repair','cause-review','final-review']
48
52
  .map(name=>[`--allow-qa-fix-${name}`,`--allow-${name}`]));
49
53
 
50
- const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development --review-config PATH (required at create; resume passes the same file) [--original-host-context ID] [--runtime codex|claude] [--input-limit BYTES] [--failover] [--allow-review-attempt 1|2] [--allow-abandon-review] [--allow-abandon-effect] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nInput limit is transport-only: integer 65536-4194304 bytes, default 65536; it bounds every input line and every tool reply, and may change on resume. A longer line stops the session with request_too_large. Review config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 900000), independent of protected mode and outside the authorized configuration digest. --browser-qa declares interactive QA capability for applicable carriers including browser and ios-simulator.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
54
+ const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development --review-config PATH (required at create; resume passes the same file) [--original-host-context ID] [--runtime codex|claude] [--input-limit BYTES] [--failover] [--allow-review-attempt 1|2] [--allow-abandon-review] [--allow-abandon-effect] [--allow-bootstrap-review-recovery] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nInput limit is transport-only: integer 65536-4194304 bytes, default 65536; it bounds every input line and every tool reply, and may change on resume. A longer line stops the session with request_too_large. Review config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 900000), independent of protected mode and outside the authorized configuration digest. --browser-qa declares interactive QA capability for applicable carriers including browser and ios-simulator.\nNew runs: --external-models [--external-models-config FILE] freezes one pair per actual external provider; resume reads only its snapshot. preflight --config RUN_DEFINITION.json --external-provider codex|claude uses the saved pair.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
51
55
 
52
56
  export function formatClaudeModelHint(config,version=null){
53
57
  const marker=config?.preflight?.request_checks?.find(check=>check?.model_recognized===false);
@@ -67,11 +71,13 @@ export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHo
67
71
  return serve({...options,inputLimit:parseHostInputLimit(rawInputLimit)});
68
72
  }
69
73
 
70
- function reviewConfiguration(file){
74
+ function reviewConfiguration(file,pair=null){
71
75
  const info=fs.lstatSync(file);
72
76
  need(info.isFile()&&!info.isSymbolicLink()&&info.size<=64*1024,'invalid_review_config');
73
- const config=json(JSON.parse(fs.readFileSync(file,'utf8')));
74
- shape(config,['model','preflight',...(Object.hasOwn(config,'disabledSkills')?['disabledSkills']:[]),
77
+ let config=json(JSON.parse(fs.readFileSync(file,'utf8')));
78
+ if(pair){need(!Object.hasOwn(config,'model')||config.model===pair.model,'external_model_configuration_conflict');
79
+ need(!Object.hasOwn(config,'effort')||config.effort===pair.effort,'external_model_configuration_conflict');config={...config,...pair};}
80
+ shape(config,['model','preflight',...(pair?['effort']:[]),...(Object.hasOwn(config,'disabledSkills')?['disabledSkills']:[]),
75
81
  ...(Object.hasOwn(config,'timeoutMs')?['timeoutMs']:[])]);
76
82
  need(typeof config.model==='string'&&/^[a-zA-Z0-9._-]+$/.test(config.model),'invalid_review_config');
77
83
  const disabledSkills=config.disabledSkills??[];
@@ -85,24 +91,24 @@ function reviewConfiguration(file){
85
91
  }
86
92
 
87
93
  // Shared synthetic loopback diagnostic; a receipt never grants Review permission.
88
- export async function runReviewPreflight(definition,{model,runtime='codex',disabledSkills}={}){
94
+ export async function runReviewPreflight(definition,{model,effort,runtime='codex',disabledSkills}={}){
89
95
  need(['codex','claude'].includes(runtime),'invalid_runtime');
90
96
  if(runtime==='claude'){
91
97
  const {previewClaudeTools}=await import('../runtime/js/cm-ai/claude-tool-preview.mjs');
92
- const config=await previewClaudeTools({cwd:definition.codeProject,model});
98
+ const config=await previewClaudeTools({cwd:definition.codeProject,model,effort});
93
99
  return config;
94
100
  }
95
101
  const {previewIsolated,previewTools}=await import('../runtime/js/cm-ai/tool-preview.mjs');
96
102
  const preview=disabledSkills===undefined?previewIsolated:previewTools;
97
- const receipt=await preview({cwd:definition.codeProject,model,allowCodeProject:true,promptTransport:'stdin',
103
+ const receipt=await preview({cwd:definition.codeProject,model,effort,allowCodeProject:true,promptTransport:'stdin',
98
104
  ...(disabledSkills===undefined?{}:{disabledSkills})});
99
105
  // No raw startup diagnostics, headers, prompt or discovered content.
100
- return {model,disabledSkills:receipt.disabledSkillFolders,preflight:{passed:receipt.passed,
106
+ return {model,...(effort===undefined?{}:{effort}),disabledSkills:receipt.disabledSkillFolders,preflight:{passed:receipt.passed,
101
107
  cli_model:receipt.cli_model,config_fingerprint:receipt.config_fingerprint,prompt_transport:receipt.prompt_transport,
102
108
  real_model_requests:receipt.real_model_requests,listener_closed:receipt.listener_closed}};
103
109
  }
104
110
 
105
- async function protectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null){
111
+ async function protectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null,externalModels=null,executionPolicy=null){
106
112
  const runtime=extra.get('--runtime')??'codex';
107
113
  const selected=resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),runtime);
108
114
  need(review!==null,'review_configuration_required');
@@ -112,13 +118,18 @@ async function protectedExecutionFor(definition,hostContextId,extra,review,mode,
112
118
  // Child fix configuration is checked before opening the parent store below.
113
119
  const file=extra.get('--protected-config'),info=fs.lstatSync(file);
114
120
  need(info.isFile()&&!info.isSymbolicLink()&&info.size<=64*1024,'invalid_protected_config');
115
- const config=json(JSON.parse(fs.readFileSync(file,'utf8')));shape(config,['model','checkCommands','timeoutMs']);
121
+ let config=json(JSON.parse(fs.readFileSync(file,'utf8')));
122
+ if(externalModels){const pair=externalModels.providers[selected.coderRuntime];need(!Object.hasOwn(config,'model')||config.model===pair.model,'external_model_configuration_conflict');need(!Object.hasOwn(config,'effort')||config.effort===pair.effort,'external_model_configuration_conflict');config={...config,...pair};}
123
+ shape(config,['model','checkCommands','timeoutMs',...(externalModels?['effort']:[])]);
116
124
  return executionFor(definition,hostContextId,bridge,review,
117
125
  extra.has('--allow-review-attempt')?Number(extra.get('--allow-review-attempt')):null,
118
126
  workflow,extra.has('--allow-qa'),runtime,{
119
127
  ...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),
120
128
  protection:{checkCommands:config.checkCommands,timeoutMs:config.timeoutMs},
121
- providerDevelopment:{model:config.model,attempt,...selected},
129
+ providerDevelopment:{model:config.model,attempt,...selected,...(externalModels?{effort:config.effort}:{})},
130
+ ...(executionPolicy?{executionPolicy}:{}),
131
+ ...(externalModels?{externalModels}:{}),
132
+ ...(extra.has('--verification-precheck')?{verificationPrecheck:true}:{}),
122
133
  ...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{}),
123
134
  });
124
135
  }
@@ -129,6 +140,7 @@ async function protectedExecutionFor(definition,hostContextId,extra,review,mode,
129
140
  // no migration, journal rewrite, or in-flight provider switch is permitted.
130
141
  async function legacyProtectedExecutionFor(definition,hostContextId,extra,review,mode,workflow,bridge,bootstrap=null){
131
142
  need((extra.get('--runtime')??'codex')==='codex','protected_runtime_unsupported');
143
+ need(!extra.has('--verification-precheck'),'verification_precheck_unavailable');
132
144
  need(review!==null,'review_configuration_required');
133
145
  need(['1','2'].includes(extra.get('--allow-provider-development-attempt')),'provider_development_authorization_required');
134
146
  const attempt=Number(extra.get('--allow-provider-development-attempt'));
@@ -159,6 +171,7 @@ function canResumeLegacyProtected(definition,runtime){
159
171
  }
160
172
 
161
173
  export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
174
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Optional --execution-optimizations freezes policy v1 for new runs only; recovery retains the original policy and legacy runs reject retrofit. See docs/execution-optimizations.md.\n');
162
175
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--original-host-context ID is resume-only: keep the creating session in durable configuration while --host-context remains the real live session. Omit it for same-session resume; a different session must declare the creating session. Equal IDs are equivalent to omission. Parent conversation runs only; legacy protected runs, batch and QA-fix children are unchanged.\n');
163
176
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Approved bootstrap feature (0.bootstrap or a single numbered *.bootstrap): --bootstrap-config PATH {selection:null for scaffold, or original cm-init selection for rules} and --allow-bootstrap-write. Original scope must include fixed instruction targets; they are host-written inside the original task effect, checked/reviewed and reloaded. No Git/install/network grant. Optional codeProjects selects disjoint real roots below codeProject; prefix scope/requirements and use protected current-session checks with a declared codeProject per command.\n');
164
177
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected current-session mode (Codex or Claude; also batch): --protected-conversation-config PATH with {checkCommands,timeoutMs}; timeoutMs bounds check commands and is the reviewer budget only when review-config has no timeoutMs. A review transport timeout with no result can resume once per attempt with fresh review authorization; a result-bearing timeout still requires reconciliation. No extra model call. The current host returns scoped UTF-8 edits (optional mode "0755"/"0644" on written files; new files are 0644); native Codex sandbox applies them and runs the declared checks. Original author runtime, per-attempt Review and QA permissions remain required. Do not combine with --protected-config. The input limit defaults to 64 KiB and may be raised with --input-limit; unavailable/binary changes stop, never switch to direct writes.\n');
@@ -179,13 +192,20 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
179
192
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('For a QA decision an older host recorded as blocked/host_request_timeout, --rerun-blocked-qa instead re-asks qa_assess once and appends a decision linked by previous_decision_id; history is kept (current hosts report a missed qa_assess window as retryable rejected/qa_decision_timeout and record nothing). --qa-environment-failure REASON (with --rerun-blocked-qa, single line, at most 500 UTF-8 bytes) declares that the non-zero QA command exits of the latest completed FAIL came from the environment: only command exits and logic cases failed solely by them qualify, never browser FAIL or CONTRADICTED; the superseded row records reason, failed_cases and blocked_cases. Every rerun reuses the three-round QA budget. Single-task host only.\n');
180
193
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-abandon-review: resume 原 run 后发送 abandon_review,request.reason 必须是单行且不超过 500 UTF-8 字节。操作员先确认旧 host 与 review 进程已退出;旗标只消费一次,不写入配置。\n');
181
194
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-abandon-effect: resume 原 run 后发送 abandon_effect,request.reason 必须是单行且不超过 500 UTF-8 字节。操作员须确认旧 host 和 effect 启动的检查/构建进程均已退出;仅当前会话 develop/complete 且无 task-commit-intent 时可用。\n');
195
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-bootstrap-review-recovery: resume 原 run 后发送 bootstrap_review_recover;只在 bootstrap develop 已完成且审查包构建失败时核对现有文件、handoff 与原始证据,并追加恢复记录,不重新派发开发。\n');
182
196
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--supersede-reviewed-evidence --supersede-reason REASON:仅新建同任务运行;旧运行都已终止且 tasks.md 未勾选时,先在新 journal 记授权,再归档旧审查证据。若保留直接前驱运行留下的代码漂移,可额外使用 --accept-superseded-code-drift;漂移文件会作为新运行的已有代码并记录当前 SHA-256。\n');
183
197
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rebind-spec-material --spec-rebind-reason REASON:仅 resume。规格经 cm-prd --change 重新批准后,若本任务的描述、验证要求、验收标准、设计摘录与测试用例都未变,只换绑批准哈希并写 specification-rebound 记录,已有开发与审查结论保留;内容有变则拒绝并列出变化。status 的 spec_drift 会说明是否可换绑。\n');
184
198
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('当前会话手动驱动请用 scripts/cm-ai-drive.mjs(批次 cm-ai-batch-drive.mjs;修复 cm-fix-drive.mjs;规格 cm-prd-drive.mjs);详情见 skills/cm-ai/references/js-host.md。\n');
199
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('External-model mode freezes one model/effort pair per provider. Unknown or invalid external results require reconciliation; automatic retries and abandonment are disabled. See docs/external-models.md.\n');
185
200
  if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\n');return 0;}
186
201
  let run,bridge;
187
202
  try{
188
203
  if(argv[0]==='preflight'){
204
+ if([5,7].includes(argv.length)&&argv[1]==='--config'&&argv[3]==='--external-provider'){
205
+ need(argv.length===5||argv[5]==='--external-models-config','invalid_arguments');
206
+ const runtime=argv[4],pair=loadExternalModels(argv[6]).providers[runtime];need(pair,'external_model_setup_required');
207
+ const config=await runReviewPreflight(readRunDefinition(argv[2]),{...pair,runtime});output.write(JSON.stringify({...config,timeoutMs:900000})+'\n');return config.preflight.passed?0:1;
208
+ }
189
209
  need((argv.length===5||argv.length===7)&&argv[1]==='--config'&&argv[3]==='--review-model','invalid_arguments');
190
210
  const runtime=argv.length===5?'codex':argv[6];
191
211
  need(argv.length===5||argv[5]==='--runtime','invalid_arguments');
@@ -203,8 +223,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
203
223
  const extra=new Map();
204
224
  for(let index=8;index<argv.length;index++){
205
225
  const name=argv[index];refuse(!extra.has(name),'invalid_arguments',`参数重复:${name}`);
206
- refuse(['--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure','--supersede-reviewed-evidence','--supersede-reason','--accept-superseded-code-drift','--rebind-spec-material','--spec-rebind-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--allow-abandon-review','--allow-abandon-effect','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--input-limit','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments',`未知参数:${name}`);
207
- if(['--supersede-reviewed-evidence','--accept-superseded-code-drift','--rebind-spec-material','--allow-bootstrap-write','--allow-qa','--allow-abandon-review','--allow-abandon-effect','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
226
+ refuse(['--execution-optimizations','--external-models','--external-models-config','--verification-precheck','--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure','--supersede-reviewed-evidence','--supersede-reason','--accept-superseded-code-drift','--rebind-spec-material','--spec-rebind-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--input-limit','--failover','--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name),'invalid_arguments',`未知参数:${name}`);
227
+ if(['--execution-optimizations','--external-models','--verification-precheck','--supersede-reviewed-evidence','--accept-superseded-code-drift','--rebind-spec-material','--allow-bootstrap-write','--allow-qa','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
208
228
  else{refuse(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments',`${name} 需要一个值`);extra.set(name,argv[++index]);}
209
229
  }
210
230
  let inputLimit;
@@ -220,12 +240,13 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
220
240
  refuse(extra.has('--rebind-spec-material')===extra.has('--spec-rebind-reason')&&(!extra.has('--rebind-spec-material')||argv[4]==='resume'),
221
241
  'spec_rebind_unavailable','--rebind-spec-material 只用于 --mode resume,并须同时提供单行 --spec-rebind-reason 原因');
222
242
  need(!extra.has('--allow-abandon-effect')||argv[4]==='resume','effect_abandon_unavailable');
243
+ need(!extra.has('--allow-bootstrap-review-recovery')||argv[4]==='resume','bootstrap_review_recovery_unavailable');
223
244
  const qaConfigRevision=revisionRequested?{previousWorkflow:readHostWorkflowConfiguration(extra.get('--revise-qa-config')),
224
245
  reason:extra.get('--qa-config-revision-reason')}:null;
225
246
  const originalHostContextId=extra.get('--original-host-context')??null;
226
247
  if(originalHostContextId!==null){need(argv[4]==='resume','original_host_context_unavailable');id(originalHostContextId);}
227
248
  if(originalHostContextId===argv[6])extra.delete('--original-host-context');
228
- const review=extra.has('--review-config')?reviewConfiguration(extra.get('--review-config')):null;
249
+ let review=null;
229
250
  const workflow=extra.has('--workflow-config')?readHostWorkflowConfiguration(extra.get('--workflow-config')):null;
230
251
  let allowedAttempt=null;
231
252
  if(extra.has('--allow-review-attempt')){refuse(['1','2'].includes(extra.get('--allow-review-attempt')),'invalid_arguments','--allow-review-attempt 只接受 1 或 2');allowedAttempt=Number(extra.get('--allow-review-attempt'));}
@@ -248,6 +269,12 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
248
269
  // Checked before the definition is read so the conflict is reported on its own.
249
270
  need(!(extra.has('--failover')&&extra.has('--protected-config')),'failover_unsupported_in_protected_mode');
250
271
  const definition=readRunDefinition(argv[2]);
272
+ const boundRuntime=extra.get('--runtime')??'codex';
273
+ const routes=extra.has('--protected-config')?resolveProtectedRuntimes(loadConfig({projectRoot:definition.codeProject}),boundRuntime):{reviewerRuntime:boundRuntime};
274
+ const executionPolicy=readLaunchExecutionPolicy({definition,mode:argv[4],enabled:extra.has('--execution-optimizations')});
275
+ const externalModels=readLaunchExternalModels({definition,mode:argv[4],enabled:extra.has('--external-models'),inputFile:extra.get('--external-models-config'),providers:[routes.coderRuntime,routes.reviewerRuntime].filter(Boolean)});
276
+ need(!externalModels||!extra.has('--failover'),'external_model_failover_unsupported');
277
+ review=extra.has('--review-config')?reviewConfiguration(extra.get('--review-config'),externalModels?.providers[routes.reviewerRuntime]??null):null;
251
278
  // Launch-time capability assertion. See host-workflow-capabilities: this is a
252
279
  // fresh declaration, not a probe the host performs.
253
280
  readBrowserCapability(extra.get('--browser-qa'),
@@ -288,10 +315,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
288
315
  refuse(argv[4]!=='create'||review!==null,'review_configuration_required',
289
316
  'create 必须带 --review-config:审查配置写进运行指纹,resume 时不能再补。先用 cm-ai-host.mjs preflight --config 运行定义 --review-model 模型 --runtime 端 生成 review.json;是否真正派发审查仍由 --allow-review-attempt 单独授权');
290
317
  let execution;
291
- if(argv[4]==='resume'&&!extra.has('--original-host-context')&&extra.has('--protected-config')&&canResumeLegacyProtected(definition,runtime)){
318
+ if(argv[4]==='resume'&&!extra.has('--original-host-context')&&extra.has('--protected-config')&&!externalModels&&!executionPolicy&&canResumeLegacyProtected(definition,runtime)){
292
319
  try{
293
320
  execution=await legacyProtectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap);
294
- run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:extra.has('--allow-abandon-review'),allowAbandonEffect:extra.has('--allow-abandon-effect'),specRebindReason:extra.get('--spec-rebind-reason')??null});
321
+ run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:extra.has('--allow-abandon-review'),allowAbandonEffect:extra.has('--allow-abandon-effect'),allowBootstrapReviewRecovery:extra.has('--allow-bootstrap-review-recovery'),specRebindReason:extra.get('--spec-rebind-reason')??null});
295
322
  error.write('cm-ai-host: resumed original Codex protected execution after exact fingerprint validation.\n');
296
323
  }catch(cause){
297
324
  if(!['fingerprint_mismatch','tool_preflight_missing'].includes(cause.code))throw cause;
@@ -300,10 +327,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
300
327
  }
301
328
  if(!run){
302
329
  execution=extra.has('--protected-config')
303
- ?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap)
330
+ ?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap,externalModels,executionPolicy)
304
331
  :executionFor(definition,argv[6],bridge,review,allowedAttempt,workflow,extra.has('--allow-qa'),runtime,
305
- {...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{})});
306
- run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:extra.has('--allow-abandon-review'),allowAbandonEffect:extra.has('--allow-abandon-effect'),specRebindReason:extra.get('--spec-rebind-reason')??null});
332
+ {...(executionPolicy?{executionPolicy}:{}),...(externalModels?{externalModels}:{}),...(extra.has('--verification-precheck')?{verificationPrecheck:true}:{}),...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{})});
333
+ run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),qaEnvironmentFailure:extra.get('--qa-environment-failure')??null,supersedeReason:extra.get('--supersede-reason')??null,acceptSupersededCodeDrift:extra.has('--accept-superseded-code-drift'),allowAbandonReview:extra.has('--allow-abandon-review'),allowAbandonEffect:extra.has('--allow-abandon-effect'),allowBootstrapReviewRecovery:extra.has('--allow-bootstrap-review-recovery'),specRebindReason:extra.get('--spec-rebind-reason')??null});
307
334
  }
308
335
  if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
309
336
  if(hasFix){
@@ -313,15 +340,24 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
313
340
  if(templated)need(digest(fix.identity)===digest(definition.identity),'qa_fix_source_mismatch');
314
341
  if(extra.has('--allow-qa-fix-start'))need((fix.configuration.runtime??'codex')===runtime,'qa_fix_host_mismatch');
315
342
  const fixPermissions=[...fixLocalPermissions].filter(([flag])=>extra.has(flag)).map(([,permission])=>permission);
316
- const fixReview=extra.has('--qa-fix-review-config')?reviewConfiguration(extra.get('--qa-fix-review-config')):null;
343
+ const fixRuntime=fix.configuration.runtime??'codex';
344
+ const fixModels=externalModels?selectExternalModels(externalModels,[fixRuntime]):null;
345
+ const fixReview=extra.has('--qa-fix-review-config')?reviewConfiguration(extra.get('--qa-fix-review-config'),fixModels?.providers[fixRuntime]??null):null;
317
346
  need(!fixPermissions.includes('--allow-test-author')||(fix.configuration.testAuthor&&fixReview),'test_author_configuration_required');
318
347
  need(!fixPermissions.includes('--allow-repair')||(fix.configuration.repair&&fixReview),'repair_configuration_required');
319
348
  const fixReviewHost=createFixReviewHost({codeProject:definition.codeProject,
320
349
  hostContextId:argv[6],runtime:fix.configuration.runtime??'codex',
321
- review:fixReview,permissions:fixPermissions});
322
- if(fixReview)need(digest(fix.configuration.causeReview??null)===digest(fixReviewHost.reviewer),'qa_fix_review_configuration_mismatch');
350
+ review:fixReview,permissions:fixPermissions,externalModels:fixModels,executionPolicy,specsDir:definition.specsDir});
351
+ if(fixModels||executionPolicy){
352
+ if(fixModels&&fix.configuration.causeReview)need(fix.configuration.causeReview.requestedModel===fixModels.providers[fixRuntime].model&&fix.configuration.causeReview.provider===fixRuntime,'external_model_pair_conflict');
353
+ if(fixReview){
354
+ // Preserve explicit reviewer contexts/exclusions; changing them changes the durable run.
355
+ need(!fix.configuration.causeReview||digest(fix.configuration.causeReview)===digest(fixReviewHost.reviewer),'qa_fix_review_configuration_mismatch');
356
+ fix={...fix,configuration:{...fix.configuration,causeReview:fixReviewHost.reviewer,...(fixModels?{externalModels:fixModels}:{})}};
357
+ }
358
+ }else if(fixReview)need(digest(fix.configuration.causeReview??null)===digest(fixReviewHost.reviewer),'qa_fix_review_configuration_mismatch');
323
359
  const host=createQaFixOwnerHost({parent:run,hostContextId:argv[6],parentHostContextId:execution.configuration.hostContextId,...(templated?{template:fix}:{fix}),reopenParent:()=>openControlRun(definition,'resume',execution),
324
- fixPermissions,fixAuthorities:{authority:fixReviewHost.authority,finalAuthority:fixReviewHost.finalAuthority},
360
+ externalModels:fixModels,executionPolicy,fixPermissions,fixAuthorities:{authority:fixReviewHost.authority,finalAuthority:fixReviewHost.finalAuthority},
325
361
  allowStart:extra.has('--allow-qa-fix-start'),autoFix:extra.has('--auto-qa-fix'),fixExecution:{bridge,...fixReviewHost.execution,
326
362
  prepare:createFixLearningPreparation({bridge,codeProject:definition.codeProject,
327
363
  applicableAgentFiles:fix.configuration.applicableAgentFiles??[]})}});
@@ -335,6 +371,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
335
371
  finally{if(rawMode)input.setRawMode(false);}
336
372
  return 0;
337
373
  }catch(cause){
374
+ const preflightDiagnostic=argv[0]==='preflight'&&['EPERM','EACCES'].includes(cause?.code)
375
+ &&cause?.syscall==='listen'&&cause?.address==='127.0.0.1'
376
+ ?{operation:'listen',systemCode:cause.code,address:'loopback'}:null;
338
377
  const code=typeof cause?.code==='string'&&(/^[a-z][a-z0-9_]{0,63}$/.test(cause.code)
339
378
  ||cause.code.startsWith('invalid_config: '))?cause.code:'host_launch_failed';
340
379
  const snapshotReason=['out_of_scope','unsupported_file','limit_exceeded','package_mismatch'].includes(code)
@@ -347,7 +386,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
347
386
  if(snapshotReason)error.write(`[host] ${snapshotReason}\n`);
348
387
  const limitReason=code==='request_too_large'?inputLimitReason(cause.limit):null;
349
388
  if(limitReason)error.write(`[host] request_too_large: ${limitReason}\n`);
350
- error.write(JSON.stringify({error:{code,...(snapshotReason?{reason:snapshotReason}:{}),...(limitReason?{reason:limitReason}:{}),...(reason?{reason}:{})}})+'\n');return 1;
389
+ error.write(JSON.stringify({error:{code,...(snapshotReason?{reason:snapshotReason}:{}),...(limitReason?{reason:limitReason}:{}),...(reason?{reason}:{}),
390
+ ...(preflightDiagnostic?{diagnostic:preflightDiagnostic}:{})}})+'\n');return 1;
351
391
  }finally{bridge?.close();run?.close();}
352
392
  }
353
393
  if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
@@ -0,0 +1,94 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import {operatorGuidance,guidanceText} from '../runtime/js/cm-ai/operator-guidance.mjs';
4
+ import {batchMemberResult} from './cm-ai-batch-run.mjs';
5
+
6
+ const identity={repositoryId:'fixture',runId:'guidance-run',taskId:'T-001',attempt:1};
7
+ const result=(state,code,pendingAction,extra={})=>({workflow:'cm-ai',identity,state,code,pendingAction,outcome:'reported',...extra});
8
+ const explain=(...args)=>operatorGuidance(result(...args));
9
+
10
+ test('only native resume paths advertise same-run development and never grant permission',()=>{
11
+ for(const code of ['develop_checks_not_passed','develop_package_too_large','developer_result_invalid',
12
+ 'verification_precheck_failed','check_output_out_of_scope','develop_empty_changes','develop_unchanged_after_review',
13
+ 'develop_requirement_missing','bootstrap_verification_failed']){
14
+ const input=result('blocked',code,'resume',{reason:'technical detail'}),before=JSON.stringify(input);
15
+ const guidance=operatorGuidance(input);
16
+ assert.equal(guidance.recoveryOperation,'advance',code);assert.equal(guidance.authorizationGranted,false);
17
+ assert.match(guidance.nextStep,/本轮交付和检查/);assert.match(guidance.prerequisites.join(' '),/原配置、runId/);
18
+ assert.equal(JSON.stringify(input),before,'guidance cannot mutate authority');
19
+ assert.equal(explain('blocked',code,'none').recoveryOperation,null,'no action when native recovery unavailable');
20
+ assert.equal(explain('unknown',code,'reconcile').recoveryOperation,null,'same code is not retry permission');
21
+ }
22
+ assert.match(explain('blocked','develop_package_too_large','resume').nextStep,/先走规格变更/);
23
+ assert.match(explain('blocked','develop_checks_not_passed','resume').summary,/尚未进入独立审查/);
24
+ });
25
+ test('bootstrap recovery restores the package without redispatching developer',()=>{
26
+ const g=explain('blocked','bootstrap_review_mismatch','bootstrap_review_recover');
27
+ assert.equal(g.recoveryOperation,'bootstrap_review_recover');assert.match(g.nextStep,/不重新派发开发/);
28
+ assert.match(g.prerequisites.join(' '),/--allow-bootstrap-review-recovery/);
29
+ assert.equal(explain('blocked','bootstrap_review_mismatch','none').recoveryOperation,null);
30
+ });
31
+ test('spec drift and rejection precede otherwise retryable package or development actions',()=>{
32
+ assert.equal(explain('blocked','spec_drift','bootstrap_review_recover').recoveryOperation,null);
33
+ assert.equal(explain('blocked','spec_drift','spec_rebind').recoveryOperation,null);
34
+ for(const outcome of ['rejected','denied']){
35
+ const g=explain('blocked','develop_checks_not_passed','resume',{outcome});
36
+ assert.equal(g.recoveryOperation,null);assert.match(g.summary,/拒绝/);
37
+ }
38
+ });
39
+ test('unknown must be audited; abandonment is conditional and never an advance instruction',()=>{
40
+ for(const action of ['abandon_effect','abandon_review']){
41
+ const g=explain('unknown','execution_error',action);
42
+ assert.equal(g.recoveryOperation,action);assert.match(g.nextStep,/子进程已退出/);
43
+ assert.match(g.nextStep,/不代表成功/);assert.equal(g.authorizationGranted,false);
44
+ }
45
+ assert.equal(explain('unknown','limit_exceeded','reconcile').recoveryOperation,null);
46
+ assert.match(explain('unknown','execution_error','reconcile').nextStep,/只读核对/);
47
+ });
48
+ test('active operation suppresses recovery and completion is kept separate from development',()=>{
49
+ const g=operatorGuidance(result('unknown','execution_error','abandon_effect'),{executionActive:true});
50
+ assert.equal(g.recoveryOperation,null);assert.match(g.nextStep,/不重复派发/);
51
+ assert.equal(explain('blocked','completion_package_changed','complete').recoveryOperation,'complete');
52
+ assert.match(explain('blocked','completion_checks_changed','complete').nextStep,/不重新开发/);
53
+ assert.equal(explain('blocked','checks_not_passed','none').recoveryOperation,null);
54
+ assert.match(explain('blocked','checks_not_passed','none').summary,/旧完成阶段/);
55
+ assert.equal(explain('fixture_completed','correction_review_required','none').recoveryOperation,null);
56
+ });
57
+ test('unrecognized and successful states do not invent a recovery contract',()=>{
58
+ assert.equal(explain('blocked','unrecognized_code','none').recoveryOperation,null);
59
+ for(const code of ['constructor','__proto__','toString'])assert.equal(explain('blocked',code,'resume').recoveryOperation,null);
60
+ assert.equal(explain('blocked','bootstrap_instruction_conflict','none').recoveryOperation,null);
61
+ for(const state of ['ready','awaiting_review','approved','fixture_completed','run_done'])assert.equal(explain(state,null,'none'),null);
62
+ assert.equal(operatorGuidance(null),null);assert.equal(operatorGuidance({workflow:'cm-fix',state:'blocked',identity}),null);
63
+ });
64
+ test('review redispatch keeps package and fresh authorization prerequisites',()=>{
65
+ const g=explain('pending_review','review_transport_timeout','resume');
66
+ assert.equal(g.recoveryOperation,'advance');assert.match(g.prerequisites.join(' '),/审查包绑定不变/);
67
+ assert.match(g.nextStep,/本轮绑定/);
68
+ });
69
+ test('rendering never uses raw reason and malformed foreign guidance is ignored',()=>{
70
+ const value=result('unknown','execution_error','reconcile',{reason:'private raw provider message'});
71
+ value.guidance=operatorGuidance(value);const rendered=guidanceText(value);
72
+ assert(!rendered.includes(value.reason));assert.match(rendered,/只读核对/);
73
+ assert.equal(guidanceText({...value,workflow:'cm-fix'}),null);
74
+ for(const change of [{authorizationGranted:true},{summary:'control\nline'},{prerequisites:null},{nextStep:'x'.repeat(2001)}])
75
+ assert.equal(guidanceText({...value,guidance:{...value.guidance,...change}}),null);
76
+ });
77
+
78
+ test('batch guidance matches its narrower control surface and never advertises single-host flags',()=>{
79
+ const member=(...args)=>{const value=result(...args);return {...value,guidance:operatorGuidance(value)};};
80
+ const blocked=member('blocked','develop_checks_not_passed','resume');
81
+ const wrapped=batchMemberResult(blocked);
82
+ assert.equal(wrapped.pendingAction,blocked.pendingAction);assert.equal(wrapped.guidance.recoveryOperation,'advance');
83
+ assert.match(guidanceText(wrapped),/原批次入口/);assert.doesNotMatch(guidanceText(wrapped),/--mode/);
84
+ assert.match(guidanceText(batchMemberResult(member('blocked','completion_checks_changed','complete'))),/成员宿主继续完成复核/);
85
+ for(const [state,code,action] of [['unknown','execution_error','abandon_effect'],
86
+ ['unknown','execution_error','abandon_review'],['blocked','bootstrap_review_mismatch','bootstrap_review_recover']]){
87
+ const output=batchMemberResult(member(state,code,action));
88
+ assert.equal(output.guidance.recoveryOperation,null);assert.doesNotMatch(guidanceText(output),/--allow-/);
89
+ assert.match(guidanceText(output),/批次入口不支持/);
90
+ }
91
+ const rebound=batchMemberResult(member('blocked','spec_drift','spec_rebind'));
92
+ assert.equal(rebound.pendingAction,'none');assert.match(rebound.guidance.nextStep,/不能换绑/);
93
+ assert.equal(rebound.guidance.recoveryOperation,null);
94
+ });