@aibyzero/cm-workflow 0.16.9 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +9 -1
  4. package/VERSION +1 -1
  5. package/docs/cm-control-policy-v2.md +331 -0
  6. package/docs/execution-optimizations.md +1 -1
  7. package/docs/external-models.md +3 -3
  8. package/docs/human-correction.md +5 -5
  9. package/docs/installation.md +1 -1
  10. package/docs/js-workflow-control.md +101 -84
  11. package/docs/next-steps.md +11 -0
  12. package/docs/untested-branches.md +2 -3
  13. package/docs/user-guide.md +3 -3
  14. package/package.json +1 -1
  15. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +13 -69
  16. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +10 -5
  17. package/runtime/js/cm-ai/control-policy.mjs +111 -0
  18. package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
  19. package/runtime/js/cm-ai/durable-runner-state.mjs +32 -126
  20. package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
  21. package/runtime/js/cm-ai/host-conversation-execution.mjs +22 -20
  22. package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
  23. package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
  24. package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
  25. package/runtime/js/cm-ai/host-review-file.mjs +1 -1
  26. package/runtime/js/cm-ai/host-tool-bridge.mjs +3 -0
  27. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
  28. package/runtime/js/cm-ai/host.mjs +1 -2
  29. package/runtime/js/cm-ai/operator-guidance.mjs +1 -24
  30. package/runtime/js/cm-ai/review-package.mjs +16 -4
  31. package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
  32. package/runtime/js/cm-ai/task-runner.mjs +36 -99
  33. package/runtime/js/cm-init/review-evidence.mjs +3 -1
  34. package/runtime/js/cm-prd/review-host.mjs +1 -1
  35. package/runtime/js/cm-prd/review-publication.mjs +5 -3
  36. package/runtime/js/cm-refactor/workflow.mjs +1 -1
  37. package/runtime/js/notify-send.mjs +15 -14
  38. package/runtime/js/notify.mjs +27 -4
  39. package/runtime/js/policy-binding-compat.mjs +2 -1
  40. package/runtime/review.md +52 -7
  41. package/runtime/task-gates.md +107 -9
  42. package/scripts/cm-ai-abandon-effect-position.test.mjs +1 -8
  43. package/scripts/cm-ai-answer-gap-driver.test.mjs +12 -12
  44. package/scripts/cm-ai-answer-gap-fixture.mjs +1 -8
  45. package/scripts/cm-ai-batch-drive.mjs +50 -31
  46. package/scripts/cm-ai-batch-drive.test.mjs +62 -19
  47. package/scripts/cm-ai-batch-host.mjs +39 -20
  48. package/scripts/cm-ai-batch-host.test.mjs +62 -38
  49. package/scripts/cm-ai-batch-run-fixture.mjs +6 -53
  50. package/scripts/cm-ai-batch-run-member-stops.test.mjs +0 -12
  51. package/scripts/cm-ai-batch-run.mjs +34 -8
  52. package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
  53. package/scripts/cm-ai-bootstrap.test.mjs +2 -3
  54. package/scripts/cm-ai-control-launch.test.mjs +219 -0
  55. package/scripts/cm-ai-control-policy.test.mjs +124 -0
  56. package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
  57. package/scripts/cm-ai-develop-answer-invalid.test.mjs +1 -8
  58. package/scripts/cm-ai-develop-call-timeout.test.mjs +1 -8
  59. package/scripts/cm-ai-develop-driver-gaps.test.mjs +33 -20
  60. package/scripts/cm-ai-direct-review.test.mjs +348 -0
  61. package/scripts/cm-ai-documentation-sync-gap.test.mjs +3 -3
  62. package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
  63. package/scripts/cm-ai-drive.mjs +96 -54
  64. package/scripts/cm-ai-drive.test.mjs +43 -84
  65. package/scripts/cm-ai-fix-integration.test.mjs +3 -5
  66. package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
  67. package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
  68. package/scripts/cm-ai-host-cli-workflow.test.mjs +6 -10
  69. package/scripts/cm-ai-host-fixture.mjs +38 -10
  70. package/scripts/cm-ai-host-protected.test.mjs +35 -33
  71. package/scripts/cm-ai-host.mjs +103 -93
  72. package/scripts/cm-ai-host.test.mjs +19 -18
  73. package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
  74. package/scripts/cm-ai-legacy-history.test.mjs +53 -0
  75. package/scripts/cm-ai-light-modules.test.mjs +4 -7
  76. package/scripts/cm-ai-multi-root.test.mjs +4 -4
  77. package/scripts/cm-ai-nested-execution.test.mjs +16 -19
  78. package/scripts/cm-ai-progress.test.mjs +10 -8
  79. package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
  80. package/scripts/cm-ai-protected-scope.test.mjs +1 -2
  81. package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
  82. package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
  83. package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -3
  84. package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
  85. package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
  86. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +3 -4
  87. package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
  88. package/scripts/cm-ai-review-failure.test.mjs +13 -19
  89. package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
  90. package/scripts/cm-ai-review-timeout.test.mjs +15 -128
  91. package/scripts/cm-ai-run.mjs +78 -24
  92. package/scripts/cm-ai-run.test.mjs +11 -38
  93. package/scripts/cm-ai-selection-guard.test.mjs +2 -2
  94. package/scripts/cm-ai-session-chain.test.mjs +18 -15
  95. package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
  96. package/scripts/cm-ai-supersede.test.mjs +3 -10
  97. package/scripts/cm-blocked-reason.test.mjs +2 -3
  98. package/scripts/cm-capability-gate.test.mjs +33 -1
  99. package/scripts/cm-check-drive-files.mjs +1 -1
  100. package/scripts/cm-check-runtime.sh +1 -1
  101. package/scripts/cm-claude-worker.test.mjs +5 -3
  102. package/scripts/cm-controlled-correction.test.mjs +469 -0
  103. package/scripts/cm-external-batch-host.test.mjs +30 -11
  104. package/scripts/cm-external-model-host.test.mjs +1 -1
  105. package/scripts/cm-external-model-recovery.test.mjs +3 -9
  106. package/scripts/cm-external-qa-fix.test.mjs +1 -1
  107. package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
  108. package/scripts/cm-fix-review-recovery.test.mjs +1 -1
  109. package/scripts/cm-host-qa-executor.test.mjs +1 -2
  110. package/scripts/cm-host-qa-policy.test.mjs +43 -16
  111. package/scripts/cm-host-review-authority.test.mjs +0 -31
  112. package/scripts/cm-knowledge-closeout.test.mjs +3 -3
  113. package/scripts/cm-notify-command.test.mjs +54 -18
  114. package/scripts/cm-notify-read-drift.test.mjs +69 -4
  115. package/scripts/cm-notify.mjs +16 -4
  116. package/scripts/cm-notify.test.mjs +91 -19
  117. package/scripts/cm-patrol.test.mjs +3 -2
  118. package/scripts/cm-task-gate-correction.test.mjs +69 -16
  119. package/scripts/cm-task-gate.mjs +368 -34
  120. package/scripts/cm-task-gate.py +2 -0
  121. package/scripts/cm-task-gate.test.mjs +252 -4
  122. package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
  123. package/scripts/fixtures/native-gate-fixture.mjs +18 -0
  124. package/scripts/policy-binding-compat.test.mjs +4 -0
  125. package/skills/cm-ai/SKILL.md +8 -6
  126. package/skills/cm-ai/references/N3-execute-task.md +17 -2
  127. package/skills/cm-ai/references/N4-review.md +11 -21
  128. package/skills/cm-ai/references/N5-mark-done.md +1 -1
  129. package/skills/cm-ai/references/N6-qa-eval.md +49 -21
  130. package/skills/cm-ai/references/js-host-modes.md +35 -14
  131. package/skills/cm-ai/references/js-host-qa-recovery.md +60 -12
  132. package/skills/cm-ai/references/js-host-recovery.md +95 -47
  133. package/skills/cm-ai/references/js-host.md +65 -28
  134. package/skills/cm-fix/SKILL.md +12 -0
  135. package/skills/cm-init/references/js-host.md +1 -1
  136. package/skills/cm-prd/references/js-host.md +1 -1
  137. package/skills/cm-refactor/SKILL.md +12 -0
  138. package/runtime/js/cm-ai/review-dispatch-limits.mjs +0 -18
  139. package/scripts/cm-ai-review-dispatch-exit.test.mjs +0 -475
@@ -1,4 +1,4 @@
1
- // N6 policy over host semantic assessment; no provider, QA execution or new state.
1
+ // N6 fixed checkpoints over registered paths and runner-proven changes.
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import {inspectCmAiQaTaskContext} from './cm-ai-admission.mjs';
@@ -28,43 +28,85 @@ function history(binding,context) {
28
28
  return new Set([...unseen,...since,key(binding.feature,binding.identity.taskId)]).size;
29
29
  }
30
30
 
31
- export function decideHostQaPolicy({assessment,pending,mergeEligible,unassessedTasks}) {
32
- const value=json(assessment);shape(value,['scores','changes']);
33
- shape(value.scores,['scope','risk','accumulation','boundary']);
34
- shape(value.changes,['api','migration','authentication','authorization','payment']);
35
- for(const score of Object.values(value.scores))need(Number.isInteger(score)&&score>=1&&score<=5,'qa_assessment_invalid');
36
- for(const flag of Object.values(value.changes))need(typeof flag==='boolean','qa_assessment_invalid');
31
+ const categories=['migration','authentication','authorization','payment','api'];
32
+
33
+ // Deliberately bounded POSIX glob grammar: literals, *, ?, and whole-segment **.
34
+ // A registry never imports executable patterns, absolute roots or parent traversal.
35
+ function relativePath(value,pattern=false){
36
+ need(typeof value==='string'&&value.length>0&&value.length<=1024&&!/[\\\r\n\0]/.test(value)
37
+ &&!value.startsWith('/')&&!/^[A-Za-z]:/.test(value),'qa_assessment_invalid');
38
+ const parts=value.split('/');
39
+ need(parts.every(part=>part.length>0&&part!=='.'&&part!=='..'),'qa_assessment_invalid');
40
+ if(pattern)need(!/[\[\]{}()!+@]/.test(value)&&parts.every(part=>!part.includes('**')||part==='**'),'qa_assessment_invalid');
41
+ return value;
42
+ }
43
+ export function readQaCriticalPaths(raw={}){
44
+ const registry=json(raw);need(registry&&typeof registry==='object'&&!Array.isArray(registry),'qa_assessment_invalid');
45
+ need(Object.keys(registry).every(name=>categories.includes(name)),'qa_assessment_invalid');
46
+ for(const patterns of Object.values(registry)){
47
+ need(Array.isArray(patterns)&&patterns.length<=256&&new Set(patterns).size===patterns.length,'qa_assessment_invalid');
48
+ patterns.forEach(pattern=>relativePath(pattern,true));
49
+ }
50
+ return registry;
51
+ }
52
+ function matchesPath(file,pattern){
53
+ const segments=pattern.split('/');
54
+ const source=segments.map((part,index)=>part==='**'
55
+ ?index===segments.length-1?'.*':'(?:[^/]+/)*'
56
+ :part.replace(/[.*+?^${}()|[\]\\]/g,char=>char==='*'?'[^/]*':char==='?'?'[^/]':`\\${char}`)
57
+ +(index===segments.length-1?'':'/')).join('');
58
+ return new RegExp(`^${source}$`).test(file);
59
+ }
60
+ export function readQaAssessment(raw){
61
+ const value=json(raw);shape(value,['confirmed']);need(value.confirmed===true,'qa_assessment_invalid');
62
+ return value;
63
+ }
64
+ export function readQaChangedFiles(raw){
65
+ const value=json(raw);shape(value,['paths','source']);
66
+ need(['review_package','handoff_only','unavailable'].includes(value.source),'qa_policy_unavailable');
67
+ need(Array.isArray(value.paths)&&value.paths.length<=10000&&new Set(value.paths).size===value.paths.length,'qa_policy_unavailable');
68
+ value.paths.forEach(file=>relativePath(file));
69
+ need(value.source!=='unavailable'||value.paths.length===0,'qa_policy_unavailable');
70
+ return value;
71
+ }
72
+ export function decideHostQaPolicy({changedFiles,criticalPaths={},pending,mergeEligible,unassessedTasks}) {
73
+ const registry=readQaCriticalPaths(criticalPaths);
74
+ need(Array.isArray(changedFiles)&&new Set(changedFiles).size===changedFiles.length,'qa_policy_unavailable');
75
+ changedFiles.forEach(file=>relativePath(file));
37
76
  need(Number.isSafeInteger(pending)&&pending>=0&&typeof mergeEligible==='boolean'
38
77
  &&Number.isSafeInteger(unassessedTasks)&&unassessedTasks>=1,'qa_policy_unavailable');
39
78
  need(!mergeEligible||pending===1,'qa_policy_unavailable');
40
- const score=Object.values(value.scores).reduce((sum,item)=>sum+item,0);
79
+ const hits=new Set(categories.filter(name=>(registry[name]??[]).some(pattern=>changedFiles.some(file=>matchesPath(file,pattern)))));
41
80
  const reasons=[];
42
81
  if(pending===0)reasons.push('feature_complete');
43
- for(const name of ['migration','authentication','authorization','payment'])if(value.changes[name])reasons.push(name);
82
+ for(const name of categories.slice(0,-1))if(hits.has(name))reasons.push(name);
44
83
  if(unassessedTasks>=5)reasons.push('five_tasks_without_qa');
45
- if(value.changes.api&&!mergeEligible)reasons.push('api_change');
84
+ if(hits.has('api')&&!mergeEligible)reasons.push('api');
46
85
  if(reasons.length)return {status:'triggered',score:null,reason:reasons.join(',')};
47
- if(score>=8)return {status:'triggered',score,reason:'risk_score'};
48
- return {status:'skipped',score,reason:value.changes.api&&mergeEligible?'merged_to_feature_qa':'risk_score_below_threshold'};
86
+ return {status:'skipped',score:null,reason:hits.has('api')&&mergeEligible?'merged_to_feature_qa':'no_fixed_trigger'};
49
87
  }
50
88
 
51
89
  // Plug directly into the existing trusted qaDecisionProvider seam. The host
52
- // classifies meaning; this function owns the mechanical decision and binding.
53
- export function createHostQaDecisionProvider({assess,timeoutMs}) {
90
+ // confirms the supplied inventory source; JS owns the decision and binding.
91
+ export function createHostQaDecisionProvider({assess,timeoutMs,criticalPaths={}}) {
92
+ const registry=readQaCriticalPaths(criticalPaths);
54
93
  need(typeof assess==='function'&&Number.isSafeInteger(timeoutMs)&&timeoutMs>0&&timeoutMs<=60000,'qa_assessment_invalid');
55
94
  return Object.freeze({timeoutMs,async decide(raw,signal){
56
95
  const input=json(raw);
57
- shape(input,['specsDir','codeProject','feature','identity','packageDigest',...(Object.hasOwn(input,'previousDecisionId')?['previousDecisionId']:[])]);
96
+ shape(input,['specsDir','codeProject','feature','identity','packageDigest',...(Object.hasOwn(input,'previousDecisionId')?['previousDecisionId']:[]),
97
+ ...(Object.hasOwn(input,'changedFiles')?['changedFiles']:[])]);
58
98
  // previousDecisionId names an older recorded decision that an explicit
59
99
  // recovery supersedes; it only derives a distinct id, never the assessment.
60
- const {previousDecisionId=null,...binding}=input;if(previousDecisionId!==null)id(previousDecisionId);
100
+ const {previousDecisionId=null,changedFiles:rawFiles={paths:[],source:'unavailable'},...binding}=input;
101
+ const changedFiles=readQaChangedFiles(rawFiles);
102
+ need(changedFiles.source!=='unavailable'||!Object.values(registry).some(patterns=>patterns.length),'qa_policy_unavailable');
103
+ if(previousDecisionId!==null)id(previousDecisionId);
61
104
  validIdentity(binding.identity);hex(binding.packageDigest);
62
105
  const context=inspectCmAiQaTaskContext({...binding,taskId:binding.identity.taskId});
63
106
  const unassessedTasks=history(binding,context);
64
107
  need(!signal.aborted,'cancelled');
65
- let assessment;
66
- try{assessment=await assess(freeze({...binding,pending:context.pending,mergeEligible:context.mergeEligible,
67
- unassessedTasks}),signal);}
108
+ try{readQaAssessment(await assess(freeze({...binding,pending:context.pending,mergeEligible:context.mergeEligible,
109
+ unassessedTasks,changedFiles,criticalPaths:registry}),signal));}
68
110
  catch(error){
69
111
  // A missed answer window is a transport outcome, not a QA decision. It is
70
112
  // reported like the outer decision timer: retryable, and nothing durable.
@@ -76,9 +118,9 @@ export function createHostQaDecisionProvider({assess,timeoutMs}) {
76
118
  // another decision; do not bind an answer to different policy inputs.
77
119
  const current=inspectCmAiQaTaskContext({...binding,taskId:binding.identity.taskId});
78
120
  need(digest(current)===digest(context)&&history(binding,current)===unassessedTasks,'stale_qa');
79
- const result=decideHostQaPolicy({assessment,pending:context.pending,mergeEligible:context.mergeEligible,unassessedTasks});
121
+ const result=decideHostQaPolicy({changedFiles:changedFiles.paths,criticalPaths:registry,pending:context.pending,mergeEligible:context.mergeEligible,unassessedTasks});
80
122
  const bound={identity:binding.identity,packageDigest:binding.packageDigest,...(previousDecisionId===null?{}:{previousDecisionId})};
81
123
  return freeze({...result,decisionId:`qa-${digest(bound).slice(0,48)}`,
82
- identity:binding.identity,packageDigest:binding.packageDigest,at:new Date().toISOString().replace(/\.\d{3}Z$/,'Z')});
124
+ identity:binding.identity,packageDigest:binding.packageDigest,changedFilesSource:changedFiles.source,at:new Date().toISOString().replace(/\.\d{3}Z$/,'Z')});
83
125
  }});
84
126
  }
@@ -1,5 +1,5 @@
1
- // Trusted host decision -> existing V3 synchronous grant. No dispatch or durable
2
- // authority database. The runner alone registers, consumes and replays grants.
1
+ // CMFIX legacy decision-to-grant consistency adapter. It does not verify a person
2
+ // or an independent identity. cm-ai no longer calls this adapter.
3
3
  import {randomUUID} from 'node:crypto';
4
4
  import {digest,id,json,need,shape,validIdentity} from './effect-contract.mjs';
5
5
 
@@ -15,7 +15,7 @@ export function publishHostReview({reviewsDir,feature,handoffPath,reviewPackage,
15
15
  const {receiptDigest,...body}=r;
16
16
  need(receiptDigest===digest(body)&&r.packageDigest===pkg.packageDigest
17
17
  &&digest(r.identity)===digest(pkg.identity),'review_package_mismatch');
18
- need(r.execution.channel==='host-authorized'&&r.execution.started===true
18
+ need(['host-review','host-authorized'].includes(r.execution.channel)&&r.execution.started===true
19
19
  &&r.execution.terminal==='succeeded'&&['codex','claude'].includes(r.execution.provider),'execution_mismatch');
20
20
  id(r.execution.providerThreadId);
21
21
  const result=reviewResult(r.result,pkg);
@@ -30,6 +30,9 @@ export function hostAnswerTimeoutMs(env=process.env){
30
30
  need(/^[1-9][0-9]?$/.test(raw)&&Number(raw)<=60,'host_answer_timeout_invalid');
31
31
  return Number(raw)*60000;
32
32
  }
33
+ // qa_assess carries runner-proven changedFiles and project criticalPaths. Its
34
+ // consumer validates only {confirmed:true}; scores/semantic risk flags are not
35
+ // part of this kind's business contract. The bridge remains transport-only.
33
36
  // Every kind a workflow host may ask the session. A kind missing here makes
34
37
  // that step throw host_operation_invalid on every attempt (O20: the second-round
35
38
  // refactor judge revision, refactor_revise_tests, was missing).
@@ -2,7 +2,7 @@
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import {digest,json,need,shape,validIdentity,hex} from './effect-contract.mjs';
5
- import {createHostQaDecisionProvider} from './host-qa-policy.mjs';
5
+ import {createHostQaDecisionProvider,readQaCriticalPaths} from './host-qa-policy.mjs';
6
6
  import {createHostQaExecutor} from './host-qa-executor.mjs';
7
7
  import {loadConfig} from '../../../scripts/cm-workflow-config.mjs';
8
8
  import {validateTestCases} from '../../../scripts/validate-test-cases.mjs';
@@ -56,7 +56,9 @@ export function validateHostWorkflowConfiguration(raw){
56
56
  for(const key of ['documentationPaths','applicableAgentFiles'])
57
57
  need(Array.isArray(config[key])&&config[key].length<=256&&config[key].every(item=>typeof item==='string'),'invalid_workflow_config');
58
58
  if(config.qa!==null){
59
- shape(config.qa,['commands','environment',...(Object.hasOwn(config.qa,'timeoutMs')?['timeoutMs']:[])]);
59
+ shape(config.qa,['commands','environment',...(Object.hasOwn(config.qa,'timeoutMs')?['timeoutMs']:[]),
60
+ ...(Object.hasOwn(config.qa,'criticalPaths')?['criticalPaths']:[])]);
61
+ if(Object.hasOwn(config.qa,'criticalPaths'))readQaCriticalPaths(config.qa.criticalPaths);
60
62
  // A real browser walkthrough of one blocking case runs for minutes, so this
61
63
  // follows the shared call-timeout range rather than a fixed minute. The
62
64
  // default below is unchanged; only an explicit configuration may raise it.
@@ -66,7 +68,7 @@ export function validateHostWorkflowConfiguration(raw){
66
68
  return config;
67
69
  }
68
70
 
69
- export function createHostWorkflowCapabilities({definition,configuration,bridge,allowQa,runtime='codex',protectedExecution=false,bootstrap=null,parallelMember=false}){
71
+ export function createHostWorkflowCapabilities({definition,configuration,bridge,allowQa,runtime='codex',protectedExecution=false,bootstrap=null,parallelMember=false,controlPolicy=null}){
70
72
  need(['codex','claude'].includes(runtime),'invalid_runtime');
71
73
  const {specsDir,codeProject,feature,requirements}=definition;
72
74
  const logHome=path.join(specsDir,'.reviews','host-log-mirror');
@@ -74,18 +76,25 @@ export function createHostWorkflowCapabilities({definition,configuration,bridge,
74
76
  documentationProvider:{timeoutMs:60000,inspect:(request,signal)=>bridge.call('documentation_inspect',request,signal)}};
75
77
  if(!protectedExecution&&configuration.documentationPaths.length)result.documentationSync={paths:configuration.documentationPaths,
76
78
  run:(request,signal)=>bridge.call('documentation_sync',request,signal)};
77
- if(configuration.qa!==null){
78
- need(allowQa===true,'qa_authorization_required');
79
+ // The N6 disposition is required even when execution is disabled. Its
80
+ // fixed checkpoints and registered path matches may require QA;
81
+ // only a configured executor can then supply actual execution evidence.
82
+ // Legacy qa:null keeps its historical caller-supplied disposition contract.
83
+ if(configuration.qa!==null||controlPolicy!==null){
79
84
  result.qaLogHome=logHome;
80
- const requestTimeout={timeoutMs:configuration.qa.timeoutMs??60000};
81
- result.qaDecisionProvider=parallelMember?createParallelMemberQaDecisionProvider():createHostQaDecisionProvider({timeoutMs:60000,
85
+ const requestTimeout={timeoutMs:configuration.qa?.timeoutMs??60000};
86
+ result.qaDecisionProvider=parallelMember?createParallelMemberQaDecisionProvider():createHostQaDecisionProvider({timeoutMs:60000,criticalPaths:configuration.qa?.criticalPaths??{},
82
87
  assess:(request,signal)=>bridge.call('qa_assess',request,signal,requestTimeout)});
88
+ }
89
+ if(configuration.qa!==null&&(controlPolicy===null||controlPolicy.qa==='run')){
90
+ need(allowQa===true,'qa_authorization_required');
91
+ const requestTimeout={timeoutMs:configuration.qa.timeoutMs??60000};
83
92
  // requestTimeoutMs stays outside the fingerprinted executor configuration;
84
93
  // timed-out QA recovery reads older case_blocked rows against it.
85
94
  result.qaExecutor=Object.freeze({...createHostQaExecutor({specsDir,codeProject,feature,requirements,runtime,
86
95
  ...(definition.codeProjects?{codeProjects:definition.codeProjects}:{}),
87
96
  ...(bootstrap?{bootstrap:{requirements:bootstrap.configuration.bootstrapRequirements,scope:definition.scope}}:{}),
88
- ...configuration.qa,timeoutMs:1800000,logHome,
97
+ commands:configuration.qa.commands,environment:configuration.qa.environment,timeoutMs:1800000,logHome,
89
98
  ...(protectedExecution?{specsRoot:specsDir}:{}),
90
99
  logic:(request,signal)=>bridge.call('qa_logic',request,signal,requestTimeout),
91
100
  browser:(request,signal)=>bridge.call('qa_browser',request,signal,requestTimeout)}),requestTimeoutMs:requestTimeout.timeoutMs});
@@ -95,10 +104,12 @@ export function createHostWorkflowCapabilities({definition,configuration,bridge,
95
104
 
96
105
  export function createParallelMemberQaDecisionProvider(){
97
106
  return Object.freeze({timeoutMs:60000,async decide(raw,signal){
98
- const binding=json(raw);shape(binding,['specsDir','codeProject','feature','identity','packageDigest']);
107
+ const binding=json(raw);shape(binding,['specsDir','codeProject','feature','identity','packageDigest',
108
+ ...(Object.hasOwn(binding,'changedFiles')?['changedFiles']:[])]);
99
109
  validIdentity(binding.identity);hex(binding.packageDigest);need(!signal.aborted,'cancelled');
100
110
  return {decisionId:`qa-${digest({identity:binding.identity,packageDigest:binding.packageDigest}).slice(0,48)}`,
101
111
  identity:binding.identity,packageDigest:binding.packageDigest,status:'skipped',
102
- reason:'parallel_member_deferred',score:4,at:new Date().toISOString().replace(/\.\d{3}Z$/,'Z')};
112
+ reason:'parallel_member_deferred',score:null,
113
+ ...(binding.changedFiles?{changedFilesSource:binding.changedFiles.source}:{}),at:new Date().toISOString().replace(/\.\d{3}Z$/,'Z')};
103
114
  }});
104
115
  }
@@ -7,12 +7,11 @@ export function createCmAiHost(options) {
7
7
  need(arguments.length===1,'invalid_input');
8
8
  shape(options,['runner','entry']);
9
9
  const keys=Object.keys(options.entry);shape(options.entry,keys);
10
- const {hostDecisionProvider,qaDecisionProvider,qaExecutor,documentationProvider,...data}=options.entry;
10
+ const {qaDecisionProvider,qaExecutor,documentationProvider,...data}=options.entry;
11
11
  const entryOptions=json(data);
12
12
  need(!Object.hasOwn(entryOptions,'runner'),'invalid_input');
13
13
  const runner=createTaskRunner(options.runner);
14
14
  const entry=createCmAiConversationEntry({...entryOptions,runner,
15
- ...(hostDecisionProvider===undefined?{}:{hostDecisionProvider}),
16
15
  ...(qaExecutor===undefined?{}:{qaExecutor}),
17
16
  ...(documentationProvider===undefined?{}:{documentationProvider}),
18
17
  ...(qaDecisionProvider===undefined?{}:{qaDecisionProvider})});
@@ -1,5 +1,3 @@
1
- import {REVIEW_NEVER_STARTED_MANUAL_STEP,MAX_REVIEW_NOT_DISPATCHED_RETRIES as REDISPATCHES,MAX_REVIEW_NOT_DISPATCHED_EXTENSIONS as EXTENSIONS,
2
- MAX_REVIEW_DENIAL_CONFIRMATIONS as DENIALS} from './review-dispatch-limits.mjs';
3
1
  // Presentation only. Native pendingAction decides the available path; guidance
4
2
  // never grants permission, changes retryability, or writes execution history.
5
3
  const deliveryMessages={
@@ -60,29 +58,8 @@ export function operatorGuidance(result,{executionActive=false}={}){
60
58
  return explain('执行结果尚未确认,不能判断这一步成功或失败。',
61
59
  '只读核对原运行记录、进程及实际文件;当前没有已确认的直接重试入口,不新建运行绕过历史。');
62
60
  }
63
- // A review round that never started a reviewer (nothing ran, nothing to prove stopped).
64
- if(action==='abandon_review'&&result.reviewDispatchConfirmRequired===true&&code==='permission_denied')
65
- return explain('本轮独立审查的授权没有取得(被拒绝,或授权已失效),审查没有登记、没有派发、审查进程从未启动,不会有任何写入;宿主不会自动重试。',
66
- '先查清是谁拒绝、为什么;确认现在可以授权后,用 --allow-abandon-review 恢复原运行并发送 abandon_review(单行 reason 写明依据)登记确认,再按原方式重新取得本轮独立审查授权,然后 advance。',
67
- 'abandon_review',['保留原配置、runId 与历史,以 --mode resume 启动','显式 --allow-abandon-review,并提供单行 reason',`每轮最多确认 ${DENIALS} 次,用满为 review_permission_denied_limit;每次重派前仍须新的审查授权`]);
68
- if(action==='abandon_review'&&result.reviewDispatchConfirmRequired===true&&code==='review_not_dispatched_limit')
69
- return explain(`本轮独立审查已登记 ${REDISPATCHES+1} 次,每次都在派发前作废(授权过期或派发时钟倒退),审查进程从未启动、没有写入;自动重派已用满。`,
70
- `先查清宿主从授权到派发为何超过授权有效期(60 秒内)或本机时钟为何倒退,并修好;然后用 --allow-abandon-review 恢复原运行并发送 abandon_review(单行 reason 写明修好了什么)登记确认,再按原方式取得新的审查授权后 advance。本轮因此再多重派 ${REDISPATCHES} 次。`,
71
- 'abandon_review',['保留原配置、runId 与历史,以 --mode resume 启动','显式 --allow-abandon-review,并提供单行 reason',`每轮只能确认 ${EXTENSIONS} 次;再用满为 review_not_dispatched_limit,之后没有这个出口`]);
72
- if(code==='review_not_dispatched_limit')return explain(`本轮独立审查已在派发前作废 ${REDISPATCHES*(1+EXTENSIONS)+1} 次、已确认延长 ${EXTENSIONS} 次,不再提供继续重派的操作;审查进程从未启动,也没有写入。`,
73
- `先查清宿主从授权到派发为何超过授权有效期(60 秒内)或本机时钟为何倒退。${REVIEW_NEVER_STARTED_MANUAL_STEP}`,
74
- null,['原运行记录保留,不改写','本运行留在盘上的改动需另存或还原,不要加 --accept-superseded-code-drift']);
75
- if(state==='pending_review'&&action==='resume'&&['grant_expired','clock_invalid'].includes(code))return explain('本轮独立审查已登记,但派发前授权过期或派发时钟倒退,审查进程从未启动、没有结论。',
76
- '恢复原运行,按原方式重新取得本轮独立审查的新的审查授权,再发送 advance;派发要在授权后 60 秒内完成。',
77
- 'advance',['保留原配置、runId 与历史,以 --mode resume 启动','不算审查轮次,不占调用与 effect 名额',`每轮最多重派 ${REDISPATCHES} 次,用满为 review_not_dispatched_limit,再确认 ${EXTENSIONS} 次后才能多重派 ${REDISPATCHES} 次`]);
78
- if(code==='review_permission_denied_limit')return explain(`本轮独立审查的授权已被拒绝 ${DENIALS+1} 次、已确认重新授权 ${DENIALS} 次,不再提供重新授权的操作;审查从未启动,也没有写入。`,
79
- `先查清授权为何一直被拒绝(宿主是否配了审查权限、授权是否在 60 秒内用完)。${REVIEW_NEVER_STARTED_MANUAL_STEP}`,
80
- null,['原运行记录保留,不改写','本运行留在盘上的改动需另存或还原,不要加 --accept-superseded-code-drift']);
81
- if(state==='pending_review'&&action==='resume'&&code==='permission_denied_confirmed')return explain('审查授权被拒绝的情况已由操作员确认,本轮可以重新申请授权;审查从未启动。',
82
- '恢复原运行,按原方式重新取得本轮独立审查的新的审查授权(旧授权不复用),再发送 advance;仍被拒绝时需要再确认一次。',
83
- 'advance',['保留原配置、runId 与历史,以 --mode resume 启动','本轮独立审查授权须是新取得的','不算审查轮次,不占调用与 effect 名额']);
84
61
  if(state==='blocked'&&action==='abandon_review')return explain('本轮独立审查第二次没有结论,本轮还剩 1 次无结论重派,但宿主不能证明原审查进程已停止。',
85
- '先确认原审查进程(含子进程)已退出;再恢复原运行并发送 abandon_review 登记确认,之后 advance 重新取得授权并重派。不算审查轮次。',
62
+ '先确认原审查进程(含子进程)已退出;再恢复原运行并发送 abandon_review 登记确认,之后 advance 重派。不算审查轮次。',
86
63
  'abandon_review',['保留原配置、runId 与历史,以 --mode resume 启动','显式 --allow-abandon-review,并提供单行 reason','用满 2 次后为 review_redispatch_limit']);
87
64
  // Q16/Q17: the final task's documentation_sync failed after develop answered.
88
65
  // R3: whatever the failure, the host cannot see whether the session still writes.
@@ -316,7 +316,7 @@ export function reviewSpecsPath(root,specsRoot) {
316
316
  need(root!==specsRoot&&!root.startsWith(specsRoot+path.sep),'overlapping_roots');
317
317
  return specsRoot.startsWith(root+path.sep)?filePath(path.relative(root,specsRoot).split(path.sep).join('/')):null;
318
318
  }
319
- function snapshot(root,specsPath=null,projectPaths=null,retainedPaths=[],selected=null,policy=null) {
319
+ function snapshot(root,specsPath=null,projectPaths=null,retainedPaths=[],selected=null,policy=null,inventoryOnly=false) {
320
320
  if(specsPath!==null){
321
321
  const target=path.join(root,specsPath);
322
322
  need(fs.realpathSync(target)===target&&fs.lstatSync(target).isDirectory(),'unsupported_path');
@@ -324,9 +324,9 @@ function snapshot(root,specsPath=null,projectPaths=null,retainedPaths=[],selecte
324
324
  const files=[],seen=new Set(); let total=0,materialBytes=0,materialCount=0,visitedSpecs=false;
325
325
  function add(p,s){
326
326
  if(!s.isFile()||s.isSymbolicLink()||s.nlink!==1)throw diagnostic('unsupported_file',p);
327
- const includeContent=selected===null||materialPath(p,selected);
328
- const countLimit=selected===null?FILE_COUNT:INVENTORY_COUNT;
329
- const byteLimit=selected===null?SNAPSHOT_LIMIT:INVENTORY_LIMIT;
327
+ const includeContent=!inventoryOnly&&(selected===null||materialPath(p,selected));
328
+ const countLimit=selected===null&&!inventoryOnly?FILE_COUNT:INVENTORY_COUNT;
329
+ const byteLimit=selected===null&&!inventoryOnly?SNAPSHOT_LIMIT:INVENTORY_LIMIT;
330
330
  if(files.length>=countLimit)throw diagnostic('limit_exceeded',p,`file count > ${countLimit}`);
331
331
  if(total+s.size>byteLimit)throw diagnostic('limit_exceeded',p,`inventory bytes > ${byteLimit}`);
332
332
  if(includeContent&&materialCount>=FILE_COUNT)
@@ -354,7 +354,14 @@ function snapshot(root,specsPath=null,projectPaths=null,retainedPaths=[],selecte
354
354
  try { names=fs.readdirSync(path.join(root,rel)).sort(); } catch { fail('read_failed'); }
355
355
  for(const name of names) {
356
356
  const p=rel ? rel+'/'+name : name;
357
+ // Compatibility evidence is outside the code inventory: only the code
358
+ // root's own .reviews and the specs subtree. A nested directory that
359
+ // merely shares the name is ordinary code and stays in the inventory.
360
+ // Existing JS snapshots retain their historical selection and record shape.
357
361
  let s; try { s=fs.lstatSync(path.join(root,p)); } catch { fail('read_failed'); }
362
+ if(inventoryOnly&&p==='.reviews'&&p!==specsPath){
363
+ need(s.isDirectory()&&!s.isSymbolicLink(),'unsupported_path');continue;
364
+ }
358
365
  // Linked worktrees use a regular .git pointer file instead of a directory.
359
366
  // Treat both as Git metadata, never read/follow the pointer or traverse it.
360
367
  // Scope and requirement paths still cannot select any .git entry.
@@ -924,3 +931,8 @@ export function readReviewBaseline(raw) {
924
931
  export function readReviewPackage(raw) {
925
932
  const value=plain(raw);validPackage(value);return freeze(value);
926
933
  }
934
+
935
+ // Reuse the same bounded scanner and two-sided stable policy for compatibility
936
+ // inventories; the default snapshot mode above is unchanged for JS callers.
937
+ export {snapshot,rootPath,stableIgnorePolicy,stablePublicPolicy,stableSnapshotPolicy,
938
+ comparableFiles,validateStablePolicy,filePath,INVENTORY_COUNT,INVENTORY_LIMIT};
@@ -64,7 +64,7 @@ export function fixReviewedAt(specsRoot,evidence){
64
64
  // Journals without a registered V3 review have no order and never qualify.
65
65
  export function approvedReviewAt(state){
66
66
  const registration=state?.reviewInvocation?.registration;
67
- return registration&&registration.grant?.packageDigest===state.reviewPackage?.packageDigest
67
+ return registration&&registration.binding?.packageDigest===state.reviewPackage?.packageDigest
68
68
  &&Number.isSafeInteger(registration.registeredAt)?registration.registeredAt:null;
69
69
  }
70
70