@aibyzero/cm-workflow 0.16.2 → 0.16.4

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 (155) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +4 -0
  3. package/CHANGELOG.md +147 -0
  4. package/README.md +44 -3
  5. package/VERSION +1 -1
  6. package/docs/installation.md +1 -1
  7. package/docs/js-workflow-control.md +46 -7
  8. package/docs/next-steps.md +100 -0
  9. package/docs/untested-branches.md +24 -18
  10. package/package.json +1 -1
  11. package/runtime/js/cm-ai/claude-review-stream.mjs +18 -0
  12. package/runtime/js/cm-ai/claude-tool-preview.mjs +45 -6
  13. package/runtime/js/cm-ai/cm-ai-admission.mjs +7 -1
  14. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +22 -12
  15. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +70 -5
  16. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +5 -5
  17. package/runtime/js/cm-ai/drive-core.mjs +68 -0
  18. package/runtime/js/cm-ai/durable-runner-state.mjs +42 -9
  19. package/runtime/js/cm-ai/effect-contract.mjs +4 -3
  20. package/runtime/js/cm-ai/execution-snapshot.mjs +40 -0
  21. package/runtime/js/cm-ai/host-conversation-execution.mjs +8 -5
  22. package/runtime/js/cm-ai/host-handoff.mjs +9 -14
  23. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +12 -7
  24. package/runtime/js/cm-ai/host-session.mjs +10 -3
  25. package/runtime/js/cm-ai/host.mjs +1 -1
  26. package/runtime/js/cm-ai/qa-config-revision.mjs +85 -0
  27. package/runtime/js/cm-ai/review-evidence-file.mjs +18 -1
  28. package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +144 -0
  29. package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +34 -0
  30. package/runtime/js/cm-ai/task-runner.mjs +41 -8
  31. package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
  32. package/runtime/js/cm-fix/cause-invocation.mjs +9 -5
  33. package/runtime/js/cm-fix/cause-package.mjs +21 -0
  34. package/runtime/js/cm-fix/dossier.mjs +40 -1
  35. package/runtime/js/cm-fix/execution.mjs +360 -83
  36. package/runtime/js/cm-fix/host.mjs +7 -3
  37. package/runtime/js/cm-fix/layout.mjs +14 -6
  38. package/runtime/js/cm-fix/progress.mjs +14 -0
  39. package/runtime/js/cm-fix/protected-edits.mjs +1 -1
  40. package/runtime/js/cm-fix/red-test.mjs +7 -6
  41. package/runtime/js/cm-fix/regression-evidence.mjs +6 -3
  42. package/runtime/js/cm-fix/regression.mjs +16 -10
  43. package/runtime/js/cm-fix/repair.mjs +16 -13
  44. package/runtime/js/cm-fix/test-author.mjs +2 -1
  45. package/runtime/js/cm-fix/test-extension.mjs +45 -0
  46. package/runtime/js/cm-prd/accepted-design.mjs +28 -9
  47. package/runtime/js/cm-prd/analysis.mjs +68 -16
  48. package/runtime/js/cm-prd/change.mjs +21 -1
  49. package/runtime/js/cm-prd/draft-save.mjs +96 -2
  50. package/runtime/js/cm-prd/failed-correction.mjs +51 -0
  51. package/runtime/js/cm-prd/inputs-replaced.mjs +122 -0
  52. package/runtime/js/cm-prd/review-correction.mjs +3 -0
  53. package/runtime/js/cm-prd/review-disposition.mjs +33 -15
  54. package/runtime/js/cm-prd/review-findings.mjs +2 -2
  55. package/runtime/js/cm-prd/review-host.mjs +2 -0
  56. package/runtime/js/cm-prd/review-preparation.mjs +28 -1
  57. package/runtime/js/cm-prd/review-publication.mjs +4 -2
  58. package/runtime/js/cm-prd/self-check-revision.mjs +81 -0
  59. package/runtime/js/cm-prd/session.mjs +5 -5
  60. package/runtime/js/cm-prd/split-design.mjs +67 -0
  61. package/runtime/js/cm-prd/summary.mjs +57 -10
  62. package/runtime/js/cm-refactor/workflow.mjs +100 -19
  63. package/runtime/js/specs-status.mjs +6 -2
  64. package/scripts/cm-ai-admission.mjs +2 -0
  65. package/scripts/cm-ai-batch-drive.mjs +251 -0
  66. package/scripts/cm-ai-batch-drive.test.mjs +159 -0
  67. package/scripts/cm-ai-batch-host.mjs +13 -5
  68. package/scripts/cm-ai-batch-host.test.mjs +25 -0
  69. package/scripts/cm-ai-contracts.test.mjs +30 -0
  70. package/scripts/cm-ai-conversation-entry-ops.test.mjs +62 -0
  71. package/scripts/cm-ai-drive.mjs +335 -0
  72. package/scripts/cm-ai-drive.test.mjs +258 -0
  73. package/scripts/cm-ai-fix-integration.test.mjs +1 -1
  74. package/scripts/cm-ai-host.mjs +48 -20
  75. package/scripts/cm-ai-host.test.mjs +79 -0
  76. package/scripts/cm-ai-qa-config-revision.test.mjs +328 -0
  77. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +255 -0
  78. package/scripts/cm-ai-qa-fix-policy.test.mjs +79 -0
  79. package/scripts/cm-ai-review-timeout.test.mjs +30 -0
  80. package/scripts/cm-ai-run.mjs +59 -11
  81. package/scripts/cm-ai-runner-error-code-regression.test.mjs +29 -0
  82. package/scripts/cm-ai-session-chain.test.mjs +261 -0
  83. package/scripts/cm-ai-supersede.test.mjs +320 -0
  84. package/scripts/cm-check-drive.mjs +94 -0
  85. package/scripts/cm-check-drive.test.mjs +78 -0
  86. package/scripts/cm-check-entry.mjs +13 -2
  87. package/scripts/cm-check-host.mjs +2 -2
  88. package/scripts/cm-check-host.test.mjs +103 -0
  89. package/scripts/cm-check-runtime.sh +15 -6
  90. package/scripts/cm-claude-developer-worker.test.mjs +40 -1
  91. package/scripts/cm-claude-probe.test.mjs +117 -2
  92. package/scripts/cm-claude-review-stream.test.mjs +43 -0
  93. package/scripts/cm-fix-abandon.test.mjs +383 -0
  94. package/scripts/cm-fix-cause-package.test.mjs +31 -1
  95. package/scripts/cm-fix-cross-session-host.test.mjs +17 -5
  96. package/scripts/cm-fix-drive.mjs +168 -0
  97. package/scripts/cm-fix-drive.test.mjs +117 -0
  98. package/scripts/cm-fix-escalation.test.mjs +214 -0
  99. package/scripts/cm-fix-execution.test.mjs +26 -0
  100. package/scripts/cm-fix-host.mjs +4 -2
  101. package/scripts/cm-fix-observation-dossier.test.mjs +34 -9
  102. package/scripts/cm-fix-qa-source.test.mjs +3 -3
  103. package/scripts/cm-fix-session-chain.test.mjs +244 -0
  104. package/scripts/cm-fix-test-extension.test.mjs +246 -0
  105. package/scripts/cm-fix-visual-carrier.test.mjs +66 -0
  106. package/scripts/cm-host-handoff.test.mjs +37 -0
  107. package/scripts/cm-idea-drive.mjs +99 -0
  108. package/scripts/cm-idea-drive.test.mjs +50 -0
  109. package/scripts/cm-init-drive.mjs +191 -0
  110. package/scripts/cm-init-drive.test.mjs +59 -0
  111. package/scripts/cm-log-event.mjs +9 -0
  112. package/scripts/cm-prd-completion.test.mjs +30 -2
  113. package/scripts/cm-prd-design-phase.test.mjs +355 -15
  114. package/scripts/cm-prd-drive.mjs +314 -0
  115. package/scripts/cm-prd-drive.test.mjs +164 -0
  116. package/scripts/cm-prd-host.mjs +46 -17
  117. package/scripts/cm-prd-inputs-replaced.test.mjs +237 -0
  118. package/scripts/cm-prd-review-disposition.test.mjs +133 -7
  119. package/scripts/cm-prd-review-gate.mjs +23 -4
  120. package/scripts/cm-prd-self-check-revision.test.mjs +302 -0
  121. package/scripts/cm-prd-summary.test.mjs +79 -4
  122. package/scripts/cm-refactor-drive.mjs +237 -0
  123. package/scripts/cm-refactor-drive.test.mjs +77 -0
  124. package/scripts/cm-refactor-gaps.test.mjs +276 -0
  125. package/scripts/cm-refactor-host.test.mjs +1 -48
  126. package/scripts/cm-refactor-judge-revision.test.mjs +253 -0
  127. package/scripts/cm-specs-status.test.mjs +19 -0
  128. package/scripts/cm-test-drive.mjs +132 -0
  129. package/scripts/cm-test-drive.test.mjs +91 -0
  130. package/scripts/cm-test-session.test.mjs +117 -0
  131. package/scripts/correction-check.test.mjs +38 -0
  132. package/scripts/fixtures/claude-model-marker.mjs +6 -0
  133. package/scripts/fixtures/claude-review-process.mjs +7 -0
  134. package/scripts/fixtures/cm-refactor.mjs +56 -0
  135. package/scripts/test-shell-compat.sh +67 -0
  136. package/skills/cm-ai/SKILL.md +1 -1
  137. package/skills/cm-ai/references/N4-review.md +2 -0
  138. package/skills/cm-ai/references/N8-finish.md +1 -0
  139. package/skills/cm-ai/references/js-host.md +85 -3
  140. package/skills/cm-check/SKILL.md +6 -1
  141. package/skills/cm-check/references/js-host.md +4 -2
  142. package/skills/cm-fix/SKILL.md +11 -4
  143. package/skills/cm-fix/references/js-host.md +67 -2
  144. package/skills/cm-fix/references/test-extension.md +57 -0
  145. package/skills/cm-idea/references/js-host.md +2 -0
  146. package/skills/cm-init/references/js-host.md +2 -0
  147. package/skills/cm-prd/SKILL.md +8 -8
  148. package/skills/cm-prd/references/js-change-recovery.md +71 -0
  149. package/skills/cm-prd/references/js-host.md +64 -2
  150. package/skills/cm-prd/references/spec-self-check.md +14 -2
  151. package/skills/cm-refactor/SKILL.md +5 -0
  152. package/skills/cm-refactor/references/js-batch.md +3 -1
  153. package/skills/cm-refactor/references/js-host.md +49 -0
  154. package/skills/cm-test/references/js-host.md +5 -0
  155. package/skills/cm-test/references/unit-coverage.md +2 -2
@@ -4,18 +4,26 @@
4
4
  import fs from 'node:fs';
5
5
  import path from 'node:path';
6
6
  import {fileURLToPath} from 'node:url';
7
+ import {REVIEWED_HANDOFF_HINT} from '../runtime/js/cm-ai/host-handoff.mjs';
7
8
  import {readRunDefinition,openControlRun,createCodexExecution} from './cm-ai-run.mjs';
8
9
  import {createConversationExecution as executionFor} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
9
10
  import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
10
- import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
11
+ import {serveCmAiHost,parseHostInputLimit} from '../runtime/js/cm-ai/host-session.mjs';
11
12
  import {createQaFixOwnerHost} from '../runtime/js/cm-ai/host-qa-fix-owner.mjs';
12
13
  import {createFixLearningPreparation} from '../runtime/js/cm-fix/learning.mjs';
13
14
  import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
14
15
  import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
15
16
  import {loadConfig,declaredRuntimes,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
16
17
  import {readHostWorkflowConfiguration,featureHasBrowserCases,readBrowserCapability} from '../runtime/js/cm-ai/host-workflow-capabilities.mjs';
17
- import {digest,json,need,shape} from '../runtime/js/cm-ai/effect-contract.mjs';
18
+ import {digest,json,need,shape,id} from '../runtime/js/cm-ai/effect-contract.mjs';
18
19
  export {executionFor as createConversationExecution,reviewConfiguration as readConversationReviewConfiguration};
20
+ export function withHandoffDiagnostic(host,error){
21
+ return {...host,async handle(request){
22
+ const result=await host.handle(request);
23
+ if(result?.code==='handoff_exists')error.write(`[host] ${REVIEWED_HANDOFF_HINT}\n`);
24
+ return result;
25
+ }};
26
+ }
19
27
  export {conversationProtection} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
20
28
  export function readConversationProtection(file){
21
29
  const stat=fs.lstatSync(file);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_protected_config');
@@ -25,11 +33,15 @@ export function readBootstrapConfiguration(file){
25
33
  const stat=fs.lstatSync(file);need(stat.isFile()&&!stat.isSymbolicLink()&&stat.size<=64*1024,'invalid_bootstrap_config');
26
34
  const config=json(JSON.parse(fs.readFileSync(file,'utf8')));shape(config,['selection']);return config;
27
35
  }
28
- const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-writeback','walkthrough','finish',
36
+ const fixLocalPermissions=new Map(['red-test','baseline','regression','learning-writeback','walkthrough','finish','abandon',
29
37
  'test-author','repair','cause-review','final-review']
30
38
  .map(name=>[`--allow-qa-fix-${name}`,`--allow-${name}`]));
31
39
 
32
- const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development [--runtime codex|claude] [--failover] [--review-config PATH] [--allow-review-attempt 1|2] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nReview config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 60000), independent of protected mode and outside the authorized configuration digest.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
40
+ const usage='cm-ai-host.mjs serve --config RUN_DEFINITION.json --mode create|resume --host-context ID --allow-development [--original-host-context ID] [--runtime codex|claude] [--input-limit BYTES] [--failover] [--review-config PATH] [--allow-review-attempt 1|2] [--workflow-config PATH] [--allow-qa] [--browser-qa available|unavailable]\nInput limit is transport-only: integer 65536-4194304 bytes, default 65536; it may change on resume. Review config is {model,preflight[,disabledSkills][,timeoutMs]}; timeoutMs is the reviewer transport budget in milliseconds (integer 1-3600000, default 60000), independent of protected mode and outside the authorized configuration digest.\ncm-ai-host.mjs preflight --config RUN_DEFINITION.json --review-model MODEL [--runtime codex|claude] (synthetic loopback only)';
41
+
42
+ export async function serveHostTransport(options,rawInputLimit,serve=serveCmAiHost){
43
+ return serve({...options,inputLimit:parseHostInputLimit(rawInputLimit)});
44
+ }
33
45
 
34
46
  function reviewConfiguration(file){
35
47
  const info=fs.lstatSync(file);
@@ -80,6 +92,7 @@ async function protectedExecutionFor(definition,hostContextId,extra,review,mode,
80
92
  return executionFor(definition,hostContextId,bridge,review,
81
93
  extra.has('--allow-review-attempt')?Number(extra.get('--allow-review-attempt')):null,
82
94
  workflow,extra.has('--allow-qa'),runtime,{
95
+ ...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),
83
96
  protection:{checkCommands:config.checkCommands,timeoutMs:config.timeoutMs},
84
97
  providerDevelopment:{model:config.model,attempt,...selected},
85
98
  ...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{}),
@@ -122,21 +135,24 @@ function canResumeLegacyProtected(definition,runtime){
122
135
  }
123
136
 
124
137
  export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
138
+ 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. Equal IDs mean a same-session reopen. Parent conversation runs only; legacy protected runs, batch and QA-fix children are unchanged.\n');
125
139
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Approved 0.bootstrap only: --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');
126
- 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 both check commands and the reviewer process. 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; 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. Same original 64KiB transport limit; unavailable/binary changes stop, never switch to direct writes.\n');
140
+ 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 both check commands and the reviewer process. 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; 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');
127
141
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected single-task CLI mode: add --protected-config PATH --allow-provider-development-attempt 1|2 and --review-config PATH. Protected config is {model,checkCommands,timeoutMs}; roots and host identity come from the original run definition and launch. This explicitly permits one task attempt of real developer execution and its declared native-sandbox checks; --allow-development alone does not. Review separately requires --allow-review-attempt 1|2. Diagnostics are required but are not review authorization. Optional original --workflow-config PATH and --allow-qa connect protected QA commands and documentation within the same developer invocation before Review; host semantic/browser/inspection requests retain their original contracts, not arbitrary writes. Default current-session mode is unchanged. Protected parent mode selects coder/reviewer CLIs from the project declaration; Claude returns protected-text-v1 proposals for host validation and sandbox application; original QA-fix options require child configuration.protectSpecs=true and all original child action permissions. Protected fix writes use text proposals, not direct host edits. The original QA/documentation/finalizer gates remain required. No installation or Git authority.\n');
128
142
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--browser-qa is required when the approved contract for this feature contains blocking browser cases or policy-enabled browser cases and QA is enabled, and must not be given otherwise. It is a declaration by the launching session, not a probe: the host cannot verify that this session can drive a browser. The gate applies to create and resume alike, so every launch must assert it again; the assertion is not persisted, because a stored assertion would only repeat the claim made by whichever session wrote it. unavailable refuses to start; either launch from a browser-capable session or remove browser cases from the approved contract.\n');
143
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--revise-qa-config PREVIOUS_WORKFLOW.json --qa-config-revision-reason REASON: 仅 resume 且 --allow-qa;核对旧配置后追加 QA 修订,旧 QA 作废留史,下一轮仍受三轮上限约束。未知 QA 须先处理;不能修改开发配置或重开 N5。\n');
129
144
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--auto-qa-fix optionally connects parent advance -> fix_run -> re-QA. Requires --qa-fix-template-config, --allow-qa-fix-start, original action permissions and project policies.auto_fix=auto. Explicit/never policies stop. Unknown, blocked or incomplete repair stops; status/cancel remain available and no fourth QA round is dispatched.\n');
130
145
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--qa-fix-template-config PATH is an alternative to --qa-fix-owner-config. Supply {specsRoot, feature, identity: parent identity, configuration: original fix configuration without qaSource}. Each fix request binds it to the latest completed QA failure; identity/digests are generated, commands/scope/permissions are not. Existing child configuration remains immutable.\n');
131
- if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_run continuously executes normal stages of the fixed QA child using the same binding as fix_advance. Requires --allow-qa-fix-start and every original per-action permission/configuration. Stops on unknown, blocked, observation, revision-required or unchanged state. It does not auto-switch child configuration or run parent QA.\n');
132
- if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_action delegates to the shared original cm-fix dispatcher. Local flags: --allow-qa-fix-red-test, --allow-qa-fix-baseline, --allow-qa-fix-regression, --allow-qa-fix-learning-writeback, --allow-qa-fix-walkthrough, --allow-qa-fix-finish. Adapter flags: --allow-qa-fix-test-author, --allow-qa-fix-repair, --allow-qa-fix-cause-review, --allow-qa-fix-final-review, with separate --qa-fix-review-config PATH and matching original child reviewer metadata. All require --allow-qa-fix-start and the original action configuration/gates. Parent --review-config/--allow-review-attempt do not grant child review permission.\n');
133
- if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-qa-fix-start additionally permits fix_advance to create or resume the fixed QA child and run only its original Learning/reproduction/diagnosis stages. Child hostContextId and runtime must match this host. It does not authorize test authoring, repair, independent provider Review, finish, Git or re-QA. Active child status/cancel use the original child owner; repeated advance never resets an unknown or completed step.\n');
146
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_run continuously executes normal stages of the fixed QA child using the same binding as fix_advance. Requires --allow-qa-fix-start and every original per-action permission/configuration. Stops on unknown, blocked, observation, revision-required or unchanged state; a design-change child closes as escalated and reports qa_fix_incomplete, never qa_fix_completed. It does not auto-switch child configuration or run parent QA.\n');
147
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('fix_action delegates to the shared original cm-fix dispatcher. Local flags: --allow-qa-fix-red-test, --allow-qa-fix-baseline, --allow-qa-fix-regression, --allow-qa-fix-learning-writeback, --allow-qa-fix-walkthrough, --allow-qa-fix-finish, --allow-qa-fix-abandon. abandon_step also requires a reason in the fix_action request and only applies to eligible local unknown steps. Adapter flags: --allow-qa-fix-test-author, --allow-qa-fix-repair, --allow-qa-fix-cause-review, --allow-qa-fix-final-review, with separate --qa-fix-review-config PATH and matching original child reviewer metadata. All require --allow-qa-fix-start and the original action configuration/gates. Parent --review-config/--allow-review-attempt do not grant child review permission.\n');
148
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--allow-qa-fix-start additionally permits fix_advance to create or resume the fixed QA child and run only its original Learning/reproduction/diagnosis stages. Child runtime must match this host. A new child hostContextId must be the live session or the parent durable creator; an existing child retains its fingerprint-verified configuration. Child opens and review grants use the live session. It does not authorize test authoring, repair, independent provider Review, finish, Git or re-QA. Active child status/cancel use the original child owner; repeated advance never resets an unknown or completed step.\n');
134
149
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--qa-fix-owner-config PATH enables read-only fix_status. The file contains the existing fix owner definition {specsRoot, identity, configuration}, including its exact original qaSource and immutable configuration, not provider grants. fix_status binds the parent identity/packageDigest/testRunId, serially closes the parent writer, opens only an existing child, reads its original completion evidence, closes it and resumes the same parent. It does not create/execute repairs, rerun QA or clear correction gates.\n');
135
150
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Protected current-session invalid_result means local value/Learning validation failed before file writes. Fix the reply, keep the same configuration, host identity and runId, restart with --mode resume and advance: blocked/developer_result_invalid retries develop at the same attempt. no_new_lesson requires reason:null (dogfood incident: nonempty reason previously wrote files then stranded the run as unknown). Already-applied proposals must match expected disk hashes; conflicts block as protected_edit_stale. Worker exceptions/timeouts and old unknown history are not retryable.\n');
136
151
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('New cm-ai runs carry approved specification data in developer requests and review packages: task/verification, all AC lines, design (64 KiB UTF-8 maximum, truncated:true above it), task-related test cases and manifest hashes. Sources must match .cm-specs-status.specFiles or spec_drift blocks. requirements may be [] or additional code-project files; specs never become writable scope. Legacy runs/packages retain their original representation. Dogfood: separate specs/code roots previously left developers and reviewers without task/interface contracts.\n');
137
152
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('Completed fixture_completed runs originally without QA may explicitly attach N6 once on --mode resume with --workflow-config (non-null qa) and --allow-qa. Original definition, scope, requirements, identity and non-workflow configuration must match. The immutable qa-attached journal record binds the full resumed config fingerprint; later resumes require that same configuration and fresh --allow-qa. qa still requests qa_assess; no automatic decision or repeated development/Review. Dogfood: missing workflow at create previously stranded mandatory feature QA.\n');
138
153
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rerun-unknown-qa requires --mode resume and fresh --allow-qa with the original workflow config. Only an unfinished QA invocation whose recorded case results are all PASS and which has no fixed execution report may be abandoned and rerun under a new testRunId at the same qaRound. The abandoned record lists partial_pass_cases; every case is rerun and old PASS evidence is history only. FAIL/BLOCKED results and unclosed resources remain blocked; no complete is fabricated.\n');
139
154
  if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--rerun-blocked-qa requires --mode resume, the original --workflow-config and fresh --allow-qa. Only the latest completed BLOCKED invocation with zero failures and exclusively host/environment evidence gaps can be superseded: browser evidenceProblem, failed cleanup, environment mismatch or host timeout; logic INSUFFICIENT_EVIDENCE. Commands BLOCKED and source drift are excluded. A new testRunId reruns every case at qaRound+1 (maximum 3); superseded and start link previous_test_run_id. The flag is consumed once, never persisted; no development/Review/task replay or new QA decision. Do not combine with --rerun-unknown-qa.\n');
155
+ if(argv.length===1&&['--help','-h'].includes(argv[0]))output.write('--supersede-reviewed-evidence --supersede-reason REASON:仅新建同任务运行;旧运行都已终止且 tasks.md 未勾选时,先在新 journal 记授权,再归档旧审查证据。\n');
140
156
  if(argv.length===1&&['--help','-h'].includes(argv[0])){output.write(usage+'\n');return 0;}
141
157
  let run,bridge;
142
158
  try{
@@ -154,10 +170,22 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
154
170
  const extra=new Map();
155
171
  for(let index=8;index<argv.length;index++){
156
172
  const name=argv[index];need(!extra.has(name),'invalid_arguments');
157
- need(['--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--workflow-config','--allow-qa','--browser-qa','--rerun-unknown-qa','--rerun-blocked-qa','--runtime','--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');
158
- if(['--allow-bootstrap-write','--allow-qa','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
173
+ need(['--revise-qa-config','--qa-config-revision-reason','--supersede-reviewed-evidence','--supersede-reason','--original-host-context','--bootstrap-config','--allow-bootstrap-write','--protected-conversation-config','--protected-config','--allow-provider-development-attempt','--review-config','--allow-review-attempt','--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');
174
+ if(['--supersede-reviewed-evidence','--allow-bootstrap-write','--allow-qa','--rerun-unknown-qa','--rerun-blocked-qa','--failover','--allow-qa-fix-start','--auto-qa-fix',...fixLocalPermissions.keys()].includes(name))extra.set(name,true);
159
175
  else{need(typeof argv[index+1]==='string'&&!argv[index+1].startsWith('--'),'invalid_arguments');extra.set(name,argv[++index]);}
160
176
  }
177
+ parseHostInputLimit(extra.get('--input-limit'));
178
+ const revisionRequested=extra.has('--revise-qa-config')||extra.has('--qa-config-revision-reason');
179
+ need(!extra.has('--supersede-reviewed-evidence')&&!extra.has('--supersede-reason')
180
+ ||(argv[4]==='create'&&extra.has('--supersede-reviewed-evidence')&&extra.has('--supersede-reason')),
181
+ 'supersede_unavailable');
182
+ need(!revisionRequested||(argv[4]==='resume'&&extra.has('--allow-qa')&&extra.has('--revise-qa-config')
183
+ &&extra.has('--qa-config-revision-reason')&&!extra.has('--rerun-unknown-qa')&&!extra.has('--rerun-blocked-qa')),'qa_revision_authorization_required');
184
+ const qaConfigRevision=revisionRequested?{previousWorkflow:readHostWorkflowConfiguration(extra.get('--revise-qa-config')),
185
+ reason:extra.get('--qa-config-revision-reason')}:null;
186
+ const originalHostContextId=extra.get('--original-host-context')??null;
187
+ if(originalHostContextId!==null){need(argv[4]==='resume','original_host_context_unavailable');id(originalHostContextId);}
188
+ if(originalHostContextId===argv[6])extra.delete('--original-host-context');
161
189
  const review=extra.has('--review-config')?reviewConfiguration(extra.get('--review-config')):null;
162
190
  const workflow=extra.has('--workflow-config')?readHostWorkflowConfiguration(extra.get('--workflow-config')):null;
163
191
  let allowedAttempt=null;
@@ -211,10 +239,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
211
239
  if(extra.has('--protected-config')||protection)need(fix.configuration?.protectSpecs===true,'protected_fix_required');
212
240
  }
213
241
  let execution;
214
- if(argv[4]==='resume'&&extra.has('--protected-config')&&canResumeLegacyProtected(definition,runtime)){
242
+ if(argv[4]==='resume'&&!extra.has('--original-host-context')&&extra.has('--protected-config')&&canResumeLegacyProtected(definition,runtime)){
215
243
  try{
216
244
  execution=await legacyProtectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap);
217
- run=await openControlRun(definition,argv[4],execution,{rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa')});
245
+ run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),supersedeReason:extra.get('--supersede-reason')??null});
218
246
  error.write('cm-ai-host: resumed original Codex protected execution after exact fingerprint validation.\n');
219
247
  }catch(cause){
220
248
  if(!['fingerprint_mismatch','tool_preflight_missing'].includes(cause.code))throw cause;
@@ -225,8 +253,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
225
253
  execution=extra.has('--protected-config')
226
254
  ?await protectedExecutionFor(definition,argv[6],extra,review,argv[4],workflow,bridge,bootstrap)
227
255
  :executionFor(definition,argv[6],bridge,review,allowedAttempt,workflow,extra.has('--allow-qa'),runtime,
228
- {...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{})});
229
- run=await openControlRun(definition,argv[4],execution,{rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa')});
256
+ {...(extra.has('--original-host-context')?{originalHostContextId:extra.get('--original-host-context')}:{}),...(protection?{protection}:{}),...(bootstrap?{bootstrap:{...bootstrap,allowWrite:extra.has('--allow-bootstrap-write')}}:{})});
257
+ run=await openControlRun(definition,argv[4],execution,{qaConfigRevision,rerunUnknownQa:extra.has('--rerun-unknown-qa'),rerunBlockedQa:extra.has('--rerun-blocked-qa'),supersedeReason:extra.get('--supersede-reason')??null});
230
258
  }
231
259
  if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
232
260
  if(hasFix){
@@ -234,17 +262,16 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
234
262
  &&fs.realpathSync(fix.configuration.reproduction.cwd)===fs.realpathSync(definition.codeProject)
235
263
  &&(templated?fix.feature:fix.configuration.qaSource.feature)===definition.feature,'qa_fix_source_mismatch');
236
264
  if(templated)need(digest(fix.identity)===digest(definition.identity),'qa_fix_source_mismatch');
237
- if(extra.has('--allow-qa-fix-start'))need(fix.configuration.hostContextId===argv[6]
238
- &&(fix.configuration.runtime??'codex')===runtime,'qa_fix_host_mismatch');
265
+ if(extra.has('--allow-qa-fix-start'))need((fix.configuration.runtime??'codex')===runtime,'qa_fix_host_mismatch');
239
266
  const fixPermissions=[...fixLocalPermissions].filter(([flag])=>extra.has(flag)).map(([,permission])=>permission);
240
267
  const fixReview=extra.has('--qa-fix-review-config')?reviewConfiguration(extra.get('--qa-fix-review-config')):null;
241
268
  need(!fixPermissions.includes('--allow-test-author')||(fix.configuration.testAuthor&&fixReview),'test_author_configuration_required');
242
269
  need(!fixPermissions.includes('--allow-repair')||(fix.configuration.repair&&fixReview),'repair_configuration_required');
243
270
  const fixReviewHost=createFixReviewHost({codeProject:definition.codeProject,
244
- hostContextId:fix.configuration.hostContextId,runtime:fix.configuration.runtime??'codex',
271
+ hostContextId:argv[6],runtime:fix.configuration.runtime??'codex',
245
272
  review:fixReview,permissions:fixPermissions});
246
273
  if(fixReview)need(digest(fix.configuration.causeReview??null)===digest(fixReviewHost.reviewer),'qa_fix_review_configuration_mismatch');
247
- const host=createQaFixOwnerHost({parent:run,...(templated?{template:fix}:{fix}),reopenParent:()=>openControlRun(definition,'resume',execution),
274
+ const host=createQaFixOwnerHost({parent:run,hostContextId:argv[6],parentHostContextId:execution.configuration.hostContextId,...(templated?{template:fix}:{fix}),reopenParent:()=>openControlRun(definition,'resume',execution),
248
275
  fixPermissions,fixAuthorities:{authority:fixReviewHost.authority,finalAuthority:fixReviewHost.finalAuthority},
249
276
  allowStart:extra.has('--allow-qa-fix-start'),autoFix:extra.has('--auto-qa-fix'),fixExecution:{bridge,...fixReviewHost.execution,
250
277
  prepare:createFixLearningPreparation({bridge,codeProject:definition.codeProject,
@@ -254,13 +281,14 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
254
281
  // PTY sessions are used by desktop tool hosts. Disable echo only on this
255
282
  // process's own terminal so tool results are not mistaken for output frames.
256
283
  const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
257
- try{await serveCmAiHost({host:run.host,input,output,toolBridge:bridge});}
284
+ const diagnosticHost=withHandoffDiagnostic(run.host,error);
285
+ try{await serveHostTransport({host:diagnosticHost,input,output,toolBridge:bridge,errorOutput:error},extra.get('--input-limit'));}
258
286
  finally{if(rawMode)input.setRawMode(false);}
259
287
  return 0;
260
288
  }catch(cause){
261
289
  const code=typeof cause?.code==='string'&&(/^[a-z][a-z0-9_]{0,63}$/.test(cause.code)
262
290
  ||cause.code.startsWith('invalid_config: '))?cause.code:'host_launch_failed';
263
- error.write(JSON.stringify({error:{code}})+'\n');return 1;
291
+ error.write(JSON.stringify({error:{code,...(code==='supersede_unavailable'&&typeof cause.reason==='string'?{reason:cause.reason}:{})}})+'\n');return 1;
264
292
  }finally{bridge?.close();run?.close();}
265
293
  }
266
294
  if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
@@ -8,6 +8,7 @@ import {spawn,spawnSync} from 'node:child_process';
8
8
  import {fileURLToPath} from 'node:url';
9
9
  import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
10
10
  import {createConversationExecution} from './cm-ai-host.mjs';
11
+ import {readRunDefinition,openControlRun} from './cm-ai-run.mjs';
11
12
  import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
12
13
 
13
14
  // Keep runtime declarations and log mirrors independent of the invoking user's home.
@@ -19,6 +20,47 @@ after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
19
20
  const cli=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
20
21
  const identity={repositoryId:'host-fixture',runId:'host-fixture-run',taskId:'T-001',attempt:1};
21
22
  const request=(operation,requestId=operation)=>({version:1,operation,requestId,identity});
23
+ test('single host input limit parsing and transport pass-through need no running host',async()=>{
24
+ const {serveHostTransport}=await import('./cm-ai-host.mjs');
25
+ assert.equal(typeof serveHostTransport,'function');
26
+ const seen=[];
27
+ for(const raw of [undefined,'65536','1048576','4194304']){
28
+ await serveHostTransport({host:{}},raw,async options=>{seen.push(options.inputLimit);});
29
+ }
30
+ assert.deepEqual(seen,[65536,65536,1048576,4194304]);
31
+ for(const raw of ['65535','4194305','1.5','NaN']){
32
+ await assert.rejects(serveHostTransport({host:{}},raw,async()=>{}),/invalid_arguments/);
33
+ }
34
+ });
35
+ test('single host help documents input limit',()=>{
36
+ const help=spawnSync(process.execPath,[cli,'--help'],{encoding:'utf8'});
37
+ assert.equal(help.status,0);assert.match(help.stdout,/--input-limit BYTES/);
38
+ });
39
+ test('single host CLI rejects out-of-range and non-integer input limits before opening a run',()=>{
40
+ for(const raw of ['65535','4194305','1.5']){
41
+ const run=spawnSync(process.execPath,[cli,'serve','--config','unused','--mode','create',
42
+ '--host-context','fixture','--allow-development','--input-limit',raw],{encoding:'utf8'});
43
+ assert.equal(run.status,1);assert.match(run.stderr,/invalid_arguments/);
44
+ }
45
+ });
46
+ test('resume accepts a changed transport input limit without changing the durable fingerprint',async()=>{
47
+ const f=fixture(),bridge=createHostToolBridge();
48
+ try{
49
+ const definition=readRunDefinition(f.config);
50
+ const execution=createConversationExecution(definition,'native-host-fixture',bridge,null,null,null,false,'codex');
51
+ const first=await openControlRun(definition,'create',execution);first.close();
52
+ const state=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
53
+ const before=JSON.parse(fs.readFileSync(state,'utf8')).fingerprints;
54
+ let limit;
55
+ const {serveHostTransport}=await import('./cm-ai-host.mjs');
56
+ await serveHostTransport({host:{}},'65536',async options=>{limit=options.inputLimit;});
57
+ assert.equal(limit,65536);
58
+ const resumed=await openControlRun(definition,'resume',execution);resumed.close();
59
+ await serveHostTransport({host:{}},'1048576',async options=>{limit=options.inputLimit;});
60
+ assert.equal(limit,1048576);
61
+ assert.deepEqual(JSON.parse(fs.readFileSync(state,'utf8')).fingerprints,before);
62
+ }finally{bridge.close();fs.rmSync(f.root,{recursive:true,force:true});}
63
+ });
22
64
  function fixture(){
23
65
  const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-native-host-')));
24
66
  const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work',config=path.join(root,'run.json');
@@ -951,3 +993,40 @@ test('step31 CLI resumes completed evidence BLOCKED QA and reaches the original
951
993
  }
952
994
  }finally{fs.rmSync(f.root,{recursive:true,force:true});}
953
995
  });
996
+
997
+ test('F7 CLI explicitly revises missing QA commands after N5 and resumes the same run',async()=>{
998
+ const f=fixture();
999
+ try{
1000
+ f.workflow=true;
1001
+ const definition=JSON.parse(fs.readFileSync(f.config));definition.scope.push('README.md');
1002
+ fs.writeFileSync(f.config,JSON.stringify(definition));
1003
+ const bin=path.join(f.root,'bin');fs.mkdirSync(bin);
1004
+ const fake=path.join(bin,'codex');fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),fake);
1005
+ fs.chmodSync(fake,0o700);f.env={...process.env,PATH:bin+path.delimiter+process.env.PATH};
1006
+ const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture'],
1007
+ {encoding:'utf8',env:f.env,timeout:15000});assert.equal(preview.status,0,preview.stderr);
1008
+ const review=path.join(f.root,'review.json');fs.writeFileSync(review,preview.stdout);
1009
+ const oldWorkflow={documentationPaths:['README.md'],applicableAgentFiles:[],qa:{commands:[],
1010
+ environment:{kind:'web',carrier:'browser',target:'fixture',scope:'local'}}};
1011
+ const oldFile=path.join(f.root,'workflow-old.json'),file=path.join(f.root,'workflow.json');
1012
+ fs.writeFileSync(oldFile,JSON.stringify(oldWorkflow));fs.writeFileSync(file,JSON.stringify(oldWorkflow));
1013
+ f.args.push('--review-config',review,'--allow-review-attempt','1','--workflow-config',file,'--allow-qa');
1014
+ const first=await runCli(f,'normal');assert.equal(first.code,0,first.stderr);
1015
+ assert.equal(first.rows.find(row=>row.requestId==='advance').result.code,'qa_result_blocked');
1016
+ const stateFile=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
1017
+ const before=JSON.parse(fs.readFileSync(stateFile));
1018
+ fs.writeFileSync(file,JSON.stringify({...oldWorkflow,qa:{...oldWorkflow.qa,
1019
+ commands:[{id:'syntax',command:[process.execPath,'--check','target.mjs'],caseIds:[]}]}}));
1020
+ const denied=await runCli(f,'normal','resume');assert.equal(denied.code,1);assert.match(denied.stderr,/fingerprint_mismatch/);
1021
+ f.args.push('--revise-qa-config',oldFile,'--qa-config-revision-reason','Correct missing QA command');
1022
+ const resumed=await runCli(f,'authorized-review','resume');assert.equal(resumed.code,0,resumed.stderr);
1023
+ assert.equal(resumed.rows.find(row=>row.requestId==='advance').result.code,'run_done');
1024
+ assert.deepEqual(resumed.calls,['documentation_inspect']);
1025
+ const after=JSON.parse(fs.readFileSync(stateFile));assert.deepEqual(after.records.slice(0,before.records.length),before.records);
1026
+ assert.equal(after.records.filter(row=>row.payload.type==='qa-config-revised').length,1);
1027
+ f.args.splice(-4);
1028
+ const again=await runCli(f,'normal','resume');assert.equal(again.code,0,again.stderr);
1029
+ assert.equal(again.rows.find(row=>row.requestId==='advance').result.code,'run_done');
1030
+ assert.deepEqual(JSON.parse(fs.readFileSync(stateFile)),after);
1031
+ }finally{fs.rmSync(f.root,{recursive:true,force:true});}
1032
+ });