@aibyzero/cm-workflow 0.19.0 → 0.21.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 (127) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/AGENTS.md +8 -0
  3. package/CHANGELOG.md +38 -0
  4. package/README.md +15 -1
  5. package/VERSION +1 -1
  6. package/docs/architecture.md +3 -0
  7. package/docs/cm-acceptance-completion.md +185 -0
  8. package/docs/installation.md +1 -1
  9. package/docs/js-workflow-control.md +1 -1
  10. package/docs/proposals/spec-amendment-tiers.md +100 -0
  11. package/package.json +1 -1
  12. package/runtime/js/acceptance-language.mjs +32 -0
  13. package/runtime/js/autonomy.mjs +168 -3
  14. package/runtime/js/check-coverage.mjs +130 -0
  15. package/runtime/js/cm-ai/acceptance-contract.mjs +257 -0
  16. package/runtime/js/cm-ai/checkpoint-package-material.mjs +13 -3
  17. package/runtime/js/cm-ai/claude-developer-proposal.schema.json +18 -0
  18. package/runtime/js/cm-ai/cm-ai-admission.mjs +49 -8
  19. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +10 -6
  20. package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +8 -3
  21. package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +1 -1
  22. package/runtime/js/cm-ai/codex-developer-output.schema.json +1 -1
  23. package/runtime/js/cm-ai/codex-review-adapter.mjs +19 -3
  24. package/runtime/js/cm-ai/completion-summary.mjs +187 -0
  25. package/runtime/js/cm-ai/control-policy.mjs +3 -1
  26. package/runtime/js/cm-ai/delivery-evidence.mjs +173 -0
  27. package/runtime/js/cm-ai/developer-adapter.mjs +4 -0
  28. package/runtime/js/cm-ai/drive-core.mjs +15 -4
  29. package/runtime/js/cm-ai/durable-runner-state.mjs +10 -6
  30. package/runtime/js/cm-ai/effect-contract.mjs +8 -1
  31. package/runtime/js/cm-ai/execution-snapshot.mjs +4 -3
  32. package/runtime/js/cm-ai/execution-store-limits.mjs +3 -3
  33. package/runtime/js/cm-ai/execution-store.mjs +7 -4
  34. package/runtime/js/cm-ai/fix-code-association.mjs +27 -6
  35. package/runtime/js/cm-ai/gate-bridge.mjs +13 -1
  36. package/runtime/js/cm-ai/host-conversation-execution.mjs +26 -14
  37. package/runtime/js/cm-ai/host-progress.mjs +2 -1
  38. package/runtime/js/cm-ai/log-rows.mjs +3 -2
  39. package/runtime/js/cm-ai/operator-guidance.mjs +110 -4
  40. package/runtime/js/cm-ai/requirement-evidence.mjs +4 -2
  41. package/runtime/js/cm-ai/review-package.mjs +22 -8
  42. package/runtime/js/cm-ai/review-presentation.mjs +12 -5
  43. package/runtime/js/cm-ai/reviewed-deliveries.mjs +10 -7
  44. package/runtime/js/cm-ai/reviewed-integration.mjs +1 -1
  45. package/runtime/js/cm-ai/spec-amendment.mjs +535 -0
  46. package/runtime/js/cm-ai/specification-material.mjs +57 -12
  47. package/runtime/js/cm-ai/task-commit.mjs +4 -2
  48. package/runtime/js/cm-ai/task-runner.mjs +64 -22
  49. package/runtime/js/cm-ai/user-maintained-paths.mjs +68 -0
  50. package/runtime/js/cm-ai/verification-auto.mjs +6 -4
  51. package/runtime/js/cm-prd/acceptance-preview.mjs +203 -0
  52. package/runtime/js/cm-prd/change.mjs +52 -5
  53. package/runtime/js/cm-prd/self-check.mjs +36 -6
  54. package/runtime/js/cm-prd/session.mjs +8 -3
  55. package/runtime/js/cm-prd/summary.mjs +5 -0
  56. package/runtime/js/cm-prd/task-scope-record.mjs +13 -7
  57. package/runtime/js/node-test-selection.mjs +38 -0
  58. package/runtime/js/run-analysis.mjs +153 -0
  59. package/runtime/js/session-boundary.mjs +17 -5
  60. package/runtime/js/session-handoff.mjs +5 -2
  61. package/runtime/js/task-scope.mjs +4 -1
  62. package/runtime/test-contract.md +1 -0
  63. package/scripts/cm-acceptance-preview.mjs +26 -0
  64. package/scripts/cm-acceptance-preview.test.mjs +156 -0
  65. package/scripts/cm-ai-acceptance-contract.test.mjs +195 -0
  66. package/scripts/cm-ai-admission.mjs +8 -2
  67. package/scripts/cm-ai-admission.test.mjs +20 -4
  68. package/scripts/cm-ai-blockage.test.mjs +120 -0
  69. package/scripts/cm-ai-checklist-coverage.test.mjs +5 -2
  70. package/scripts/cm-ai-checkpoint-package-material.test.mjs +60 -6
  71. package/scripts/cm-ai-checkpoint-package-owner.test.mjs +1 -0
  72. package/scripts/cm-ai-completion-summary.test.mjs +154 -0
  73. package/scripts/cm-ai-conversation-entry-ops.test.mjs +8 -2
  74. package/scripts/cm-ai-develop-driver-gaps.test.mjs +1 -0
  75. package/scripts/cm-ai-drive.mjs +18 -11
  76. package/scripts/cm-ai-fix-later-delivery.test.mjs +2 -2
  77. package/scripts/cm-ai-later-delivery-feature.test.mjs +102 -0
  78. package/scripts/cm-ai-progress.test.mjs +7 -0
  79. package/scripts/cm-ai-project-qa-gate.test.mjs +55 -4
  80. package/scripts/cm-ai-review-input-limit.test.mjs +91 -0
  81. package/scripts/cm-ai-run.test.mjs +23 -1
  82. package/scripts/cm-ai-spec-rebind.test.mjs +51 -15
  83. package/scripts/cm-ai-user-maintained-paths.test.mjs +183 -0
  84. package/scripts/cm-ai-verification-auto.test.mjs +33 -8
  85. package/scripts/cm-ai-verification-gate.test.mjs +1 -1
  86. package/scripts/cm-autonomy-acceptance.test.mjs +212 -0
  87. package/scripts/cm-autonomy-review-r1.test.mjs +142 -0
  88. package/scripts/cm-autonomy.mjs +3 -1
  89. package/scripts/cm-autonomy.test.mjs +10 -9
  90. package/scripts/cm-check-runtime.sh +5 -2
  91. package/scripts/cm-delivery-evidence.mjs +59 -0
  92. package/scripts/cm-delivery-evidence.test.mjs +177 -0
  93. package/scripts/cm-drive-liveness.test.mjs +14 -0
  94. package/scripts/cm-driver-light-import.test.mjs +32 -0
  95. package/scripts/cm-fix-observation-task-id.test.mjs +49 -0
  96. package/scripts/cm-fix-review-storage.test.mjs +14 -4
  97. package/scripts/cm-journal-limit.test.mjs +69 -0
  98. package/scripts/cm-mandatory-check-coverage.test.mjs +82 -0
  99. package/scripts/cm-node-test-selection.test.mjs +108 -0
  100. package/scripts/cm-notify-read-drift.test.mjs +6 -3
  101. package/scripts/cm-prd-completion.test.mjs +49 -0
  102. package/scripts/cm-prd-drive.mjs +1 -1
  103. package/scripts/cm-prd-host.mjs +3 -1
  104. package/scripts/cm-prd-host.test.mjs +19 -2
  105. package/scripts/cm-prd-self-check-rules.test.mjs +23 -11
  106. package/scripts/cm-prd-self-check.test.mjs +24 -1
  107. package/scripts/cm-prd-summary.test.mjs +25 -4
  108. package/scripts/cm-review-inventory.test.mjs +25 -6
  109. package/scripts/cm-run-analysis.mjs +21 -0
  110. package/scripts/cm-run-analysis.test.mjs +120 -0
  111. package/scripts/cm-spec-amend.mjs +68 -0
  112. package/scripts/cm-spec-amend.test.mjs +510 -0
  113. package/scripts/cm-specs-status.test.mjs +6 -0
  114. package/scripts/cm-start-check.mjs +140 -53
  115. package/scripts/cm-start-check.test.mjs +139 -1
  116. package/scripts/cm-task-scope.test.mjs +3 -2
  117. package/scripts/cm-usage-report.py +8 -3
  118. package/scripts/cm019-r1-contract.test.mjs +137 -0
  119. package/scripts/cm019-review-gates.test.mjs +97 -0
  120. package/scripts/test-journal-limit-1mib.mjs +4 -0
  121. package/scripts/validate-public-repo.py +4 -0
  122. package/skills/cm-ai/references/N1-init.md +23 -1
  123. package/skills/cm-ai/references/js-host-qa-recovery.md +3 -2
  124. package/skills/cm-ai/references/js-host-recovery.md +2 -1
  125. package/skills/cm-ai/references/js-host.md +7 -2
  126. package/skills/cm-prd/references/js-change-recovery.md +2 -1
  127. package/skills/cm-prd/references/js-host.md +1 -0
@@ -8,6 +8,7 @@ import {taskLines,TASK_GRAMMAR,recordedTaskGrammar} from '../spec-task-line.mjs'
8
8
  import {readReviewSourceFiles,readReviewSourceExcerpt} from './review-package.mjs';
9
9
  import {json,need,shape,hex,id,freeze,digest} from './effect-contract.mjs';
10
10
  import {readExecutionSnapshot} from './execution-snapshot.mjs';
11
+ import {buildAcceptanceContract,readAcceptanceContract} from './acceptance-contract.mjs';
11
12
 
12
13
  const DESIGN_LIMIT=64*1024;
13
14
  const filenames=['requirements.md','design.md','tasks.md','test-cases.json'];
@@ -17,7 +18,10 @@ const featureName=value=>need(typeof value==='string'&&/^\d+\.[^/\\\x00-\x1f]+$/
17
18
  export function readSpecificationMaterial(raw,taskId){
18
19
  const v=json(raw,2*1024*1024);
19
20
  shape(v,['feature','task','acceptanceCriteria','designExcerpt','testCases','sources',
20
- ...['truncated','taskScopeDigest'].filter(key=>Object.hasOwn(v,key))]);
21
+ ...['truncated','taskScopeDigest','acceptanceContract'].filter(key=>Object.hasOwn(v,key))]);
22
+ if(Object.hasOwn(v,'acceptanceContract')){
23
+ readAcceptanceContract(v.acceptanceContract);need(v.acceptanceContract.taskId===taskId);
24
+ }
21
25
  if(Object.hasOwn(v,'taskScopeDigest'))hex(v.taskScopeDigest);
22
26
  featureName(v.feature);
23
27
  shape(v.task,['id','description',...(Object.hasOwn(v.task,'verification')?['verification']:[])]);
@@ -53,14 +57,14 @@ const TASK_ID_TOKEN=/(?<![A-Za-z0-9])T-[A-Za-z0-9][A-Za-z0-9._-]*/g;
53
57
  const indentOf=line=>/^[ \t]*/.exec(line)[0].length;
54
58
  const MENTIONS_TASK=/(?<![A-Za-z0-9])T-[A-Za-z0-9]/;
55
59
  const namesTask=(text,taskId)=>(text.match(TASK_ID_TOKEN)??[]).some(id=>id.replace(/[._-]+$/,'')===taskId);
56
- export function taskScopeText(tasks,taskId,grammar=TASK_GRAMMAR){
60
+ export function taskScopeText(tasks,taskId,grammar=TASK_GRAMMAR,includeHeadings=false){
57
61
  const kept=[];let owner=null,ownerIndent=0;
58
62
  for(const {body,fenced,declaration} of taskLines(tasks,{grammar})){
59
63
  if(!body.trim())continue;
60
64
  if(declaration){owner=declaration.id;ownerIndent=indentOf(body);}
61
65
  // Only lines indented under an item belong to it; a fence or heading at
62
66
  // its level ends it, leaving the rest to the shared/named rules below.
63
- else if(owner!==null&&!(indentOf(body)>ownerIndent&&!/^\s*#/.test(body)))owner=null;
67
+ else if(owner!==null&&!(indentOf(body)>ownerIndent&&(includeHeadings||!/^\s*#/.test(body))))owner=null;
64
68
  const dependency=fenced||declaration?null:body.match(DEPENDENCY);
65
69
  const belongs=declaration?declaration.id:owner??dependency?.[1]??null;
66
70
  if(namesTask(body,taskId)||belongs===taskId||belongs===null&&!MENTIONS_TASK.test(body))kept.push(body);
@@ -90,7 +94,41 @@ function verificationFor(source,taskId){
90
94
  return lines.join('\n');
91
95
  }
92
96
 
93
- export function captureSpecificationMaterial({specsRoot,feature,taskId}){
97
+ // Acceptance selection is narrower than the conservative rebind drift scope.
98
+ // A mention in another task, dependency, heading or version table is not an
99
+ // acceptance declaration for this task; only its own list body and children are.
100
+ export function taskAcceptanceText(tasks,taskId,grammar=TASK_GRAMMAR){
101
+ const kept=[];let owner=null,ownerIndent=0;
102
+ for(const {body,declaration} of taskLines(tasks,{grammar})){
103
+ if(declaration){owner=declaration.id;ownerIndent=indentOf(body);}
104
+ else if(body.trim()&&owner!==null&&indentOf(body)<=ownerIndent)owner=null;
105
+ if(owner===taskId&&body.trim())kept.push(body);
106
+ }
107
+ // The dedicated verification section is an explicit task-keyed declaration,
108
+ // unlike incidental mentions elsewhere in the document.
109
+ let level=null;
110
+ for(const body of tasks.split(/\r?\n/)){
111
+ const heading=/^\s*(#{1,6})\s+(.+)$/.exec(body);
112
+ if(heading){if(level!==null&&heading[1].length<=level)level=null;if(heading[2].includes('验证要求'))level=heading[1].length;continue;}
113
+ const key=/^\s*(?:[-*]\s+)?(T-[A-Za-z0-9][A-Za-z0-9._-]*)(?=[::\s])/.exec(body)?.[1];
114
+ if(level!==null&&key===taskId)kept.push(body);
115
+ }
116
+ return kept.join('\n');
117
+ }
118
+
119
+ // Draft previews and approved captures use exactly the same source selection.
120
+ // This pure projection carries no approval, filesystem access or execution.
121
+ export function buildTaskAcceptanceContract({texts,taskId,grammar=TASK_GRAMMAR}){
122
+ const tasks=normalizeRuntimeMarks(texts['tasks.md'],'tasks.md');
123
+ const requirements=normalizeRuntimeMarks(texts['requirements.md'],'requirements.md');
124
+ const cases=texts['test-cases.json']===undefined?[]:JSON.parse(texts['test-cases.json']).cases;
125
+ need(Array.isArray(cases)&&cases.every(item=>item&&Array.isArray(item.taskIds)),'acceptance_preview_cases_invalid');
126
+ const taskText=taskAcceptanceText(tasks,taskId,grammar);
127
+ return buildAcceptanceContract({taskId,taskText,explicitOnly:true,
128
+ requirementsText:requirements,testCases:cases.filter(item=>item.taskIds.includes(taskId))});
129
+ }
130
+
131
+ export function captureSpecificationMaterial({specsRoot,feature,taskId,acceptance=true}){
94
132
  try{
95
133
  featureName(feature);
96
134
  need(path.isAbsolute(specsRoot)&&fs.realpathSync(specsRoot)===specsRoot);
@@ -129,27 +167,33 @@ export function captureSpecificationMaterial({specsRoot,feature,taskId}){
129
167
  [...declaredAcceptanceIds(line)].map(id=>({id,text:line.trim()})));
130
168
  const cases=texts['test-cases.json']===undefined?[]:JSON.parse(texts['test-cases.json']).cases;
131
169
  need(Array.isArray(cases)&&cases.every(item=>item&&Array.isArray(item.taskIds)));
170
+ const acceptanceContract=acceptance?buildTaskAcceptanceContract({texts,taskId,grammar}):null;
132
171
  return readSpecificationMaterial({feature,task,acceptanceCriteria,designExcerpt:design.excerpt,
133
172
  ...(design.truncated?{truncated:true}:{}),testCases:cases.filter(item=>item.taskIds.includes(taskId)),sources,
134
- taskScopeDigest:taskScopeDigest(texts,taskId,grammar)},taskId);
173
+ taskScopeDigest:taskScopeDigest(texts,taskId,grammar),
174
+ ...(acceptanceContract?{acceptanceContract}:{})},taskId);
135
175
  }catch{throw Object.assign(new Error('spec_drift'),{code:'spec_drift'});}
136
176
  }
137
177
 
138
178
  // Material captured by older versions has no taskScopeDigest; compare a fresh
139
179
  // capture in the bound representation so their runs keep verifying.
140
180
  const asBound=(bound,current)=>{
141
- if(Object.hasOwn(bound,'taskScopeDigest'))return current;
142
- const {taskScopeDigest:unused,...legacy}=current;return legacy;
181
+ const result={...current};
182
+ for(const key of ['taskScopeDigest','acceptanceContract'])if(!Object.hasOwn(bound,key))delete result[key];
183
+ // Stored contracts are data in the original validated baseline, not executable
184
+ // parser rules. The source digests and all other material still compare below.
185
+ if(Object.hasOwn(bound,'acceptanceContract'))result.acceptanceContract=bound.acceptanceContract;
186
+ return result;
143
187
  };
144
188
  // Rebind eligibility, deliberately conservative: requirements.md and design.md
145
189
  // must be unchanged as whole files (acceptance items may span lines, and prose
146
190
  // can state requirements); in tasks.md and test-cases.json only other tasks'
147
191
  // items, dependency lines and cases may differ (taskScopeDigest). A run bound
148
192
  // before taskScopeDigest existed cannot prove that and is never rebindable.
149
- const CONTENT_FIELDS=['feature','task','acceptanceCriteria','designExcerpt','truncated','testCases','taskScopeDigest'];
193
+ const CONTENT_FIELDS=['feature','task','acceptanceCriteria','designExcerpt','truncated','testCases','taskScopeDigest','acceptanceContract'];
150
194
  const FIELD_NAMES={feature:'feature',task:'本任务描述/验证要求',acceptanceCriteria:'验收标准',
151
195
  designExcerpt:'设计摘录',truncated:'设计摘录',testCases:'本任务测试用例',
152
- taskScopeDigest:'tasks.md/test-cases.json 中本任务的条目、续行、依赖、用例或共用说明'};
196
+ taskScopeDigest:'tasks.md/test-cases.json 中本任务的条目、续行、依赖、用例或共用说明',acceptanceContract:'冻结的必验合同'};
153
197
  const WHOLE_FILES={'requirements.md':'requirements.md(整份核对,含验收标准续行与说明)','design.md':'design.md(整份核对)'};
154
198
 
155
199
  // Explicit, journaled rebind (task-runner rebindSpecification). It can only ever
@@ -194,7 +238,7 @@ const accepted=(baseline,captured)=>{
194
238
 
195
239
  export function verifySpecificationMaterial(baseline){
196
240
  const current=captureSpecificationMaterial({specsRoot:baseline.specificationRoot,
197
- feature:baseline.specification.feature,taskId:baseline.identity.taskId});
241
+ feature:baseline.specification.feature,taskId:baseline.identity.taskId,acceptance:false});
198
242
  need(accepted(baseline,current),'spec_drift');
199
243
  return baseline.specification;
200
244
  }
@@ -213,9 +257,10 @@ export function boundSpecificationMaterial(baseline,captured){
213
257
  export function inspectSpecificationDrift(baseline){
214
258
  let current;
215
259
  try{current=captureSpecificationMaterial({specsRoot:baseline.specificationRoot,
216
- feature:baseline.specification.feature,taskId:baseline.identity.taskId});}
260
+ feature:baseline.specification.feature,taskId:baseline.identity.taskId,acceptance:false});}
217
261
  catch{return freeze({approved:false,files:[],fields:[],rebindable:false});}
218
262
  if(accepted(baseline,current))return null;
263
+ current=asBound(baseline.specification,current);
219
264
  const bound=baseline.specification,before=new Map(bound.sources.map(row=>[row.path,row.sha256]));
220
265
  const after=new Map(current.sources.map(row=>[row.path,row.sha256]));
221
266
  const files=[...new Set([...before.keys(),...after.keys()])].filter(file=>before.get(file)!==after.get(file)).sort();
@@ -223,7 +268,7 @@ export function inspectSpecificationDrift(baseline){
223
268
  ...files.map(file=>WHOLE_FILES[file.split('/').at(-1)]).filter(Boolean),
224
269
  ...(before.size!==after.size?['test-cases.json 的有无']:[]),
225
270
  ...(Object.hasOwn(bound,'taskScopeDigest')?[]:['本运行由旧版本创建,未记录本任务段落摘要,无法证明其未变']),
226
- ...CONTENT_FIELDS.filter(field=>Object.hasOwn(bound,'taskScopeDigest')||field!=='taskScopeDigest')
271
+ ...CONTENT_FIELDS.filter(field=>!['taskScopeDigest','acceptanceContract'].includes(field)||Object.hasOwn(bound,field))
227
272
  .filter(field=>digest(current[field]??null)!==digest(bound[field]??null)).map(field=>FIELD_NAMES[field])])];
228
273
  return freeze({approved:true,files,fields,rebindable:fields.length===0,sources:current.sources});
229
274
  }
@@ -6,7 +6,7 @@ import { types } from 'node:util';
6
6
  import {createRequire} from 'node:module';
7
7
  import { verifyCompletionReviewPackage,reviewSpecsPath } from './review-package.mjs';
8
8
  import { checkCompletion } from './gate-bridge.mjs';
9
- import { need,shape,json,digest,validIdentity } from './effect-contract.mjs';
9
+ import { need,shape,json,digest,validIdentity,JOURNAL_PAYLOAD_LIMIT } from './effect-contract.mjs';
10
10
  import {planBytes,readCommitIntent,readCommitResult} from './task-commit-codec.mjs';
11
11
  import {resolveFixtureCommit} from './task-runner.mjs';
12
12
  import {readRunnerHistory} from './durable-runner-state.mjs';
@@ -73,7 +73,9 @@ function ownerMatch(store,owner,initial,revision) {
73
73
  need(equal(s.identity,initial.identity) && equal(s.fingerprints,initial.fingerprints),'identity_mismatch');
74
74
  need(s.revision===revision,'commit_store_changed');return s;
75
75
  }
76
- function boundedRecord(record) {need(Buffer.byteLength(JSON.stringify(record))<=MiB,'limit_exceeded');}
76
+ // The store's own record bound (payload limit plus the 1 KiB envelope): a fixed 1 MiB
77
+ // refused every commit of a run whose develop checkpoint the store had accepted.
78
+ function boundedRecord(record) {need(Buffer.byteLength(JSON.stringify(record))<=JOURNAL_PAYLOAD_LIMIT+1024,'limit_exceeded');}
77
79
  function append(store,current,id,kind,payload) {
78
80
  const data={version:1,seq:current.records.length+1,id,kind,payload,previousDigest:current.records.at(-1)?.digest??null};
79
81
  const record={...data,digest:digest(data)};boundedRecord(record);
@@ -1,4 +1,5 @@
1
- import {packageMaterialEligible,checkpointStoragePlan,checkpointPackageBudget,packageMaterialReference} from './checkpoint-package-material.mjs';
1
+ import {packageMaterialEligible,checkpointStoragePlan,checkpointPackageBudget,packageMaterialReference,INLINE_PACKAGE_LIMIT} from './checkpoint-package-material.mjs';
2
+ import {reviewInputFit} from './codex-review-adapter.mjs';
2
3
  import {taskDeclarations,approvedTaskGrammar} from '../spec-task-line.mjs';
3
4
  import {readIntegrationEvidenceFile,validateIntegrationRecord,verifyReviewedIntegration} from './reviewed-integration.mjs';
4
5
  import {beginHostStage} from './host-stage-observer.mjs';
@@ -7,6 +8,7 @@ import {readExternalModels} from './external-models.mjs';
7
8
  import {beforeFirstQaRound,readQaConfigRevision} from './qa-config-revision.mjs';
8
9
  import {readCloseoutPolicy} from './knowledge-closeout.mjs';
9
10
  import {readQaAttachment} from './qa-attachment.mjs';
11
+ import {acceptanceProblems,encodeAcceptanceEvidence,acceptanceCoverage,describeAcceptanceProblems} from './acceptance-contract.mjs';
10
12
  // Trusted synthetic fixture host; explicit V2 supports isolated task-file writes.
11
13
  import { randomUUID } from 'node:crypto';
12
14
  import { types } from 'node:util';
@@ -17,7 +19,7 @@ import {verifySpecificationMaterial,boundSpecificationMaterial,inspectSpecificat
17
19
  readSpecificationRebind} from './specification-material.mjs';
18
20
  import { captureReviewBaseline, captureScopeRevisionSources, captureReviewInventory, compareReviewBaseline, createReviewPackage, verifyReviewPackage, verifyCompletionReviewPackage, validChecks, readReviewSourceFiles } from './review-package.mjs';
19
21
  import { digest,need,shape,id,text,json,freeze,arrayItems,validIdentity,validTaskLearningInput,validCallTimeout,requestFor,terminalFor,failureCode,
20
- JOURNAL_PAYLOAD_LIMIT,developCheckpointReserve,taskReviewScope,boundedReason } from './effect-contract.mjs';
22
+ JOURNAL_PAYLOAD_LIMIT,JOURNAL_REASON_LIMIT,developCheckpointReserve,taskReviewScope,boundedReason } from './effect-contract.mjs';
21
23
  import { reviewResult,reviewReceipt,boundReviewText,reviewPaths } from './review-runner.mjs';
22
24
  import { checkCompletion } from './gate-bridge.mjs';
23
25
  import { runnerPayload,runnerPayloadV3,readRunnerHistory,attemptBaseline,boundRunnerRecord,
@@ -177,7 +179,7 @@ export function createTaskRunner(options) {
177
179
  // only block: passing it grants nothing and never substitutes for that review.
178
180
  const verificationGate=options.verificationGate??null;
179
181
  // The latest satisfied gate's handoff entry; reset on every gate run.
180
- let requirementEvidence=null,hostReplayEvidence=null;
182
+ let requirementEvidence=null,hostReplayEvidence=null,acceptanceEvidence=null;
181
183
  need(verificationGate===null||typeof verificationGate==='function');
182
184
  if(taskMode)need(Object.hasOwn(options,'persistence'),'runner_completion');
183
185
  const config=json({root:options.root,identity:options.identity,scope:options.scope,requirements:options.requirements,
@@ -294,7 +296,7 @@ export function createTaskRunner(options) {
294
296
  const calls=[],cache=new Map(),session=restored?.session??randomUUID(),registered=new Map(),receipts=[];
295
297
  let state=reviewers.some(r=>r.allowed&&r.available)?'ready':'pending_review',code=null,attempt=1;
296
298
  let busy=false,pending=null,sequence=0,base=original,reviewPackage=null,currentChecks=null,workflowRunning=false;
297
- let reason=null,checkNewPaths=null;
299
+ let reason=null,checkNewPaths=null,verificationReason=null;
298
300
  let receipt=null,priorReview=null,cancelAfterCommit=false,workflowError=null,cancellationRequested=false,reviewInvocation=null;
299
301
  let learningResult=null;
300
302
  // Journaled supersession context: shown, never counted as a review verdict.
@@ -345,10 +347,11 @@ export function createTaskRunner(options) {
345
347
  // Other task runs' committed, reviewed deliveries in this specs root, only
346
348
  // those reviewed after this run's own approving review, and the live proof
347
349
  // that recorded interleaving steps are exactly such deliveries.
348
- const laterDeliveries=()=>completedReviewedDeliveries({specsRoot:completion.owner.specsRoot,root:config.root,identity:config.identity});
350
+ const laterDeliveries=()=>completedReviewedDeliveries({specsRoot:completion.owner.specsRoot,root:config.root,identity:config.identity,
351
+ tasksPath:completion.owner.tasksPath??null});
349
352
  const reviewedAt=()=>approvedReviewAt({reviewInvocation,reviewPackage});
350
353
  const resolveSteps=(steps,allowAbsent=false)=>resolveDeliverySteps({specsRoot:completion.owner.specsRoot,root:config.root,
351
- identity:config.identity,after:reviewedAt(),steps,allowAbsent});
354
+ identity:config.identity,tasksPath:completion.owner.tasksPath??null,after:reviewedAt(),steps,allowAbsent});
352
355
  // This run's own QA fixes take their place in the same order at the final
353
356
  // review time their completion evidence cites (evidence: a fix not yet accepted).
354
357
  const fixTime=(evidence=null)=>fix=>{
@@ -461,7 +464,7 @@ export function createTaskRunner(options) {
461
464
  const baseline=captureReviewBaseline({...configToBaseline(effectiveMetadata()),version:original.version,
462
465
  ...(Object.hasOwn(original,'specification')?{specification:{specsRoot:original.specificationRoot,feature:original.specification.feature}}:{})},
463
466
  !Object.hasOwn(original,'ignorePolicy'),original.ignorePolicy?.version??2,
464
- original.ignorePolicy?.version===2?original.ignorePolicy:null);
467
+ original.ignorePolicy?.version===2?original.ignorePolicy:null,Boolean(original.specification?.acceptanceContract));
465
468
  return splitDocumentationState(baseline.files,paths);
466
469
  }
467
470
  const documentationRefusal=(refusal,detail)=>Object.assign(new Error(refusal),{code:refusal,reason:{
@@ -702,13 +705,15 @@ export function createTaskRunner(options) {
702
705
  need(digest(readReviewSourceFiles(path.dirname(handoff),[path.basename(handoff)])[0])===digest(reviewPackage.handoff),'package_mismatch');
703
706
  }
704
707
  explainCompletedDelivery({root:config.root,baseline:base,parentPackage:reviewPackage,deliveries:laterDeliveries(),after:reviewedAt(),
708
+ tasksPath:completion.owner.tasksPath??null,
705
709
  since:firstReviewAt(journal,config.identity)});
706
710
  }
707
711
  return current;
708
712
  } catch(error){
709
713
  return freeze({...current,code:'correction_review_required',...(error?.code==='fix_current_code_unexplained'
710
714
  ?{reason:`未经审查的改动:${error.paths.slice(0,20).join(', ')}${error.paths.length>20?` 等 ${error.paths.length} 个路径`:''}`}
711
- :error?.code==='fix_association_unverified'?{reason:'已登记 QA 修复所接续的后续交付无法按其运行存档核实(存档缺失、未完成或内容不符)'}:{})});
715
+ :error?.code==='fix_association_unverified'?{reason:'已登记 QA 修复所接续的后续交付无法按其运行存档核实(存档缺失、未完成或内容不符)'}
716
+ :error?.code==='user_maintained_invalid'?{reason:`代码根的用户维护文件声明 .cm-user-maintained.json 无效:${error.detail}`}:{})});
712
717
  }
713
718
  };
714
719
  const halt=(next,why,detail=null)=>{state=next;code=why;reason=detail;};
@@ -716,7 +721,7 @@ export function createTaskRunner(options) {
716
721
  compareReviewBaseline(withBoundSpecification(captureReviewBaseline({...configToBaseline(effectiveMetadata()),version:original.version,
717
722
  ...(Object.hasOwn(original,'specification')?{specification:{specsRoot:original.specificationRoot,feature:original.specification.feature}}:{})},
718
723
  !Object.hasOwn(original,'ignorePolicy'),original.ignorePolicy?.version??2,
719
- original.ignorePolicy?.version===2?original.ignorePolicy:null)),original);
724
+ original.ignorePolicy?.version===2?original.ignorePolicy:null,Boolean(original.specification?.acceptanceContract))),original);
720
725
  }
721
726
  const specificationLive=(currentState,currentCode)=>Object.hasOwn(original,'specification')
722
727
  &&['develop','review','complete'].some(kind=>stageAllowed(kind,currentState,currentCode,priorReview?.verdict));
@@ -1167,25 +1172,48 @@ export function createTaskRunner(options) {
1167
1172
  return {files};
1168
1173
  }
1169
1174
  async function verificationSatisfied(checks) {
1170
- requirementEvidence=null;hostReplayEvidence=null;
1171
- if(verificationGate===null)return true;
1175
+ requirementEvidence=null;hostReplayEvidence=null;acceptanceEvidence=null;verificationReason=null;
1172
1176
  // The description carries hard requirements too ("also confirm X/Y/Z do not
1173
1177
  // regress", "do not modify A"), and a gate that reads only the verification
1174
1178
  // section lets exactly those through to the independent review. Both are
1175
1179
  // sent; neither is required to exist.
1176
1180
  const specification=Object.hasOwn(original,'specification')?verifySpecificationMaterial(original):null;
1181
+ const contract=specification?.acceptanceContract??null;
1182
+ if(verificationGate===null){
1183
+ if(contract)verificationReason='verification_precheck_failed: 冻结合同需要验证入口,当前宿主未提供 verificationGate';
1184
+ return contract===null;
1185
+ }
1177
1186
  const verification=specification?.task?.verification??null;
1178
1187
  const description=specification?.task?.description??null;
1179
1188
  const written=value=>typeof value==='string'&&value.trim().length>0;
1180
- if(!written(verification)&&!written(description))return true;
1189
+ if(!contract&&!written(verification)&&!written(description))return true;
1181
1190
  const verdict=json(await bounded(verificationGate,
1182
1191
  json({identity:{...config.identity,attempt},
1183
1192
  ...(written(description)?{description}:{}),
1184
- ...(written(verification)?{verification}:{}),checks,
1193
+ ...(written(verification)?{verification}:{}),...(contract?{acceptanceContract:contract}:{}),checks,
1185
1194
  ...(parsedHistory?.scopeRevisions?{scope:effectiveScope}: {})}),{baselineSnapshot:baselineSnapshot()}));
1186
- shape(verdict,['satisfied',...['items','hostRecord'].filter(key=>Object.hasOwn(verdict,key))]);
1195
+ shape(verdict,['satisfied',...['items','hostRecord','coverage','reason'].filter(key=>Object.hasOwn(verdict,key))]);
1187
1196
  need(typeof verdict.satisfied==='boolean','invalid_result');
1188
1197
  need(verdict.satisfied||!Object.hasOwn(verdict,'items')&&!Object.hasOwn(verdict,'hostRecord'),'invalid_result');
1198
+ if(Object.hasOwn(verdict,'reason')){
1199
+ need(!verdict.satisfied&&typeof verdict.reason==='string'
1200
+ &&verdict.reason.startsWith('verification_precheck_failed: ')
1201
+ &&verdict.reason.length<=JOURNAL_REASON_LIMIT&&!/[\x00-\x1f\x7f]/.test(verdict.reason),'invalid_result');
1202
+ verificationReason=verdict.reason;
1203
+ }
1204
+ if(contract){
1205
+ const coverage=acceptanceCoverage(contract,checks);
1206
+ const problems=verdict.satisfied?acceptanceProblems(contract,verdict.items,verdict.hostRecord??null):[];
1207
+ if(!coverage.satisfied)problems.push('mandatory checks missing or unverifiable: '+JSON.stringify(coverage));
1208
+ if(!verdict.satisfied||problems.length){
1209
+ if(problems.length)verificationReason=boundedReason('verification_precheck_failed: ',
1210
+ [...(verificationReason?[verificationReason.replace(/^verification_precheck_failed:\s*/, '')]:[]),
1211
+ ...describeAcceptanceProblems(contract,problems)]);
1212
+ return false;
1213
+ }
1214
+ acceptanceEvidence=encodeAcceptanceEvidence({contract,identity:{...config.identity,attempt},items:verdict.items,
1215
+ facts:verdict.hostRecord??null,coverage});
1216
+ }
1189
1217
  // The host's own replay record (host-replay.mjs) is a separate handoff entry.
1190
1218
  hostReplayEvidence=Object.hasOwn(verdict,'hostRecord')
1191
1219
  ?encodeHostReplayEvidence({identity:{...config.identity,attempt},facts:verdict.hostRecord}):null;
@@ -1240,7 +1268,7 @@ export function createTaskRunner(options) {
1240
1268
  async function hostDeliveryChecks(){
1241
1269
  currentChecks=await collectChecks();active();
1242
1270
  if(failedChecks(currentChecks).length){halt('blocked','develop_checks_not_passed',checkFailureReason(currentChecks,'develop_checks_not_passed'));return false;}
1243
- if(!await verificationSatisfied(currentChecks)){halt('blocked','verification_precheck_failed');return false;}
1271
+ if(!await verificationSatisfied(currentChecks)){halt('blocked','verification_precheck_failed',verificationReason);return false;}
1244
1272
  active();
1245
1273
  // unchangedSinceRejection builds a package too, so an empty delivery or a
1246
1274
  // deleted in-scope requirement surfaces there first and takes the same
@@ -1251,7 +1279,8 @@ export function createTaskRunner(options) {
1251
1279
  try{createHostHandoff({root:config.root,baseline:base,checks:currentChecks,
1252
1280
  handoffPath:completion.handoffs[attempt-1],evidence:[...journal.filter(row=>row.payload.type==='completion-rework-requested')
1253
1281
  .map(row=>'cm-completion-rework-v1: '+JSON.stringify({identity:{...config.identity,attempt:2},recordDigest:row.digest})),
1254
- ...(requirementEvidence===null?[]:[requirementEvidence]),...(hostReplayEvidence===null?[]:[hostReplayEvidence])]});}
1282
+ ...(requirementEvidence===null?[]:[requirementEvidence]),...(hostReplayEvidence===null?[]:[hostReplayEvidence]),
1283
+ ...(acceptanceEvidence===null?[]:[acceptanceEvidence])]});}
1255
1284
  catch(error){emptyDelivery(error);return false;}
1256
1285
  return true;
1257
1286
  }
@@ -1383,7 +1412,7 @@ export function createTaskRunner(options) {
1383
1412
  if(taskLearning?.hostHandoff!==true){
1384
1413
  currentChecks=await collectChecks();active();
1385
1414
  if(failedChecks(currentChecks).length){halt('blocked','develop_checks_not_passed',checkFailureReason(currentChecks,'develop_checks_not_passed'));return;}
1386
- if(!await verificationSatisfied(currentChecks)){halt('blocked','verification_precheck_failed');return;}
1415
+ if(!await verificationSatisfied(currentChecks)){halt('blocked','verification_precheck_failed',verificationReason);return;}
1387
1416
  active();
1388
1417
  let unchanged;
1389
1418
  try{unchanged=unchangedSinceRejection();}catch(error){emptyDelivery(error);return;}
@@ -1599,15 +1628,28 @@ export function createTaskRunner(options) {
1599
1628
  const size=value=>Buffer.byteLength(JSON.stringify(value??null));
1600
1629
  const reserve=developCheckpointReserve({examinedPathsBytes:size(reviewPaths(reviewPackage)),
1601
1630
  receiptsBytes:size(receipts),callsBytes:size(calls),writebackBytes:size(learningResult?.writeback)});
1602
- const budget=JOURNAL_PAYLOAD_LIMIT-reserve;
1603
1631
  const enabled=packageMaterialEnabled();
1604
- const capacity=enabled?checkpointPackageBudget({inlineBytes:bytes,packageBytes:size(reviewPackage),reserve,enabled,
1605
- referenced:packageMaterialReference(journal,reviewPackage,{...config.identity,attempt})!==null}):{fits:bytes<=budget};
1606
- if(!capacity.fits){
1632
+ // One budget for both: without a material archive the package repeats in
1633
+ // every later checkpoint, so it keeps the original inline budget.
1634
+ const capacity=checkpointPackageBudget({inlineBytes:bytes,packageBytes:size(reviewPackage),reserve,enabled,
1635
+ referenced:enabled&&packageMaterialReference(journal,reviewPackage,{...config.identity,attempt})!==null});
1636
+ const budget=capacity.budget;
1637
+ const reviewer=reviewers.find(candidate=>candidate.allowed&&candidate.available);
1638
+ const input=capacity.fits&&reviewer?reviewInputFit({reviewPackage,payload:{priorReview,...supersededReviewPayload(carriedReview,attempt)},
1639
+ provider:reviewer.provider,executionPolicy:metadata.executionPolicy??null}):null;
1640
+ if(input&&!input.fits){
1641
+ const changed=reviewPackage.changes.filter(change=>change.after).map(change=>change.after);
1642
+ reviewPackage=packageBefore;
1643
+ halt('blocked','develop_package_too_large',boundedReason(`develop_package_too_large: the review input for ${reviewer.provider} would exceed its limit of ${input.limit} bytes, `
1644
+ +'so no review could take this delivery; largest changed files: ',largestFiles(changed),
1645
+ '; shrink them or move them out of scope, then resume to redo this attempt'));
1646
+ result=privateStatus();cache.set(v.id,{effect:v,digest:digest(v),result});
1647
+ }
1648
+ else if(!capacity.fits){
1607
1649
  const changed=reviewPackage.changes.filter(change=>change.after).map(change=>change.after);
1608
1650
  reviewPackage=packageBefore;
1609
1651
  halt('blocked','develop_package_too_large',boundedReason(`develop_package_too_large: the review checkpoint would be ${bytes} bytes, `
1610
- +`above ${budget} (journal record limit ${JOURNAL_PAYLOAD_LIMIT} minus ${reserve} kept for the bounded review `
1652
+ +`above ${budget} (${enabled?`journal record limit ${JOURNAL_PAYLOAD_LIMIT}`:`inline package limit ${Math.min(JOURNAL_PAYLOAD_LIMIT,INLINE_PACKAGE_LIMIT)} for a package without a material archive`} minus ${reserve} kept for the bounded review `
1611
1653
  +'and completion records); largest changed files: ',largestFiles(changed),
1612
1654
  '; shrink them or move them out of scope, then resume to redo this attempt'));
1613
1655
  result=privateStatus();cache.set(v.id,{effect:v,digest:digest(v),result});
@@ -0,0 +1,68 @@
1
+ // A code project may declare files its user maintains by hand, outside any task
2
+ // (AI潮: Baseline/glass-verdicts.json, edited only by the user). Only the plain
3
+ // completed-run delivery chain tolerates their differences, like the root CM
4
+ // config; QA-fix chains and integration acceptance stay strict. Exact relative
5
+ // files only, under the review inventory's own path contract: no directories,
6
+ // globs, agent instructions, CM config or this declaration itself, compared
7
+ // case-insensitively. A malformed declaration tolerates nothing and fails closed.
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+ import {createHash} from 'node:crypto';
11
+ import {parseModelJson} from './model-configuration-file.mjs';
12
+ import {CONFIG_FILENAMES} from '../../../scripts/cm-workflow-config.mjs';
13
+
14
+ export const USER_MAINTAINED_FILE='.cm-user-maintained.json';
15
+ const MAX_BYTES=16*1024,MAX_PATHS=64,MAX_PATH=512;
16
+ const INSTRUCTIONS=new Set(['agents.md','claude.md']);
17
+ const RESERVED=new Set([...CONFIG_FILENAMES,USER_MAINTAINED_FILE].map(name=>name.toLowerCase()));
18
+ const SECRET_SEGMENTS=new Set(['.git','.ssh','.aws','.gnupg']);
19
+
20
+ export function userMaintainedInvalid(detail){
21
+ return Object.assign(new Error(`user_maintained_invalid: ${detail}`),{code:'user_maintained_invalid',detail});
22
+ }
23
+ // review-package.mjs filePath, plus the declaration's own refusals.
24
+ function readPath(root,value){
25
+ if(typeof value!=='string'||value.length===0||value.length>MAX_PATH||/[\\:*?[\]{}\x00-\x1f\x7f-\x9f]/.test(value)
26
+ ||value.startsWith('/')||value.normalize('NFC')!==value)
27
+ throw userMaintainedInvalid('路径必须是代码根下的相对文件路径(NFC,无控制字符、反斜杠、冒号或通配符)');
28
+ const parts=value.split('/');
29
+ if(parts.some(part=>part===''||part==='.'||part==='..'))throw userMaintainedInvalid(`路径不规范:${value}`);
30
+ if(parts.some(part=>SECRET_SEGMENTS.has(part.toLowerCase())||/^\.env(?:\.|$)/i.test(part))
31
+ ||INSTRUCTIONS.has(parts.at(-1).toLowerCase())||RESERVED.has(value.toLowerCase()))
32
+ throw userMaintainedInvalid(`不能声明:${value}`);
33
+ let stat=null;
34
+ try{stat=fs.lstatSync(path.join(root,value));}catch(error){if(error.code!=='ENOENT')throw userMaintainedInvalid(`无法检查:${value}`);}
35
+ if(stat&&!stat.isFile())throw userMaintainedInvalid(`只能声明普通文件:${value}`);
36
+ return value;
37
+ }
38
+
39
+ // {paths, sha256}: the declared paths and the exact declaration bytes' digest
40
+ // (null when the code root has no declaration). The caller binds sha256 to the
41
+ // inventory it compares, so a declaration replaced mid-check is refused.
42
+ export function readUserMaintainedPaths(root){
43
+ const file=path.join(root,USER_MAINTAINED_FILE);
44
+ let before;
45
+ try{before=fs.lstatSync(file);}
46
+ catch(error){if(error.code==='ENOENT')return {paths:[],sha256:null};throw userMaintainedInvalid('无法读取');}
47
+ if(!before.isFile()||before.nlink!==1||before.size>MAX_BYTES)throw userMaintainedInvalid('必须是普通单链接文件且不超过 16 KiB');
48
+ let bytes;
49
+ try{
50
+ const descriptor=fs.openSync(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
51
+ try{
52
+ bytes=fs.readFileSync(descriptor);const after=fs.fstatSync(descriptor);
53
+ if(!['dev','ino','size','mtimeMs','ctimeMs'].every(key=>after[key]===before[key])||bytes.length!==before.size)
54
+ throw userMaintainedInvalid('读取期间被修改');
55
+ }finally{fs.closeSync(descriptor);}
56
+ }catch(error){throw error.code==='user_maintained_invalid'?error:userMaintainedInvalid('无法读取');}
57
+ let value;
58
+ try{value=parseModelJson(new TextDecoder('utf-8',{fatal:true}).decode(bytes));}
59
+ catch{throw userMaintainedInvalid('不是严格的 UTF-8 JSON(含重复键)');}
60
+ if(value===null||typeof value!=='object'||Array.isArray(value)
61
+ ||Object.keys(value).sort().join(',')!=='paths,version'||value.version!==1)
62
+ throw userMaintainedInvalid('格式必须是 {"version":1,"paths":[...]}');
63
+ if(!Array.isArray(value.paths)||value.paths.length===0||value.paths.length>MAX_PATHS)
64
+ throw userMaintainedInvalid(`paths 必须有 1 到 ${MAX_PATHS} 项`);
65
+ const paths=value.paths.map(item=>readPath(root,item));
66
+ if(new Set(paths.map(item=>item.toLowerCase())).size!==paths.length)throw userMaintainedInvalid('paths 有重复项(不区分大小写)');
67
+ return {paths,sha256:createHash('sha256').update(bytes).digest('hex')};
68
+ }
@@ -8,18 +8,20 @@
8
8
  // run "red" needs the test-files-only run to have run and failed; run "baseline"
9
9
  // needs the baseline to have run (a run that could not start proves nothing) and,
10
10
  // with a result, to have that result. An untagged item is not a run claim here.
11
- // The same limit as the session-answered gate: coverage of every written
12
- // requirement, and the tagging of every run claim, are not proven.
11
+ // Legacy material has no expected set. New material supplies a frozen contract:
12
+ // coverage and run tags are checked against it before accepting any report.
13
+ // Neither mode proves arbitrary prose/physical evidence true; independent review remains.
14
+ import {acceptanceProblems} from './acceptance-contract.mjs';
13
15
  const ran=run=>run&&['passed','failed'].includes(run.outcome);
14
16
  const redFact=facts=>facts.status!=='replayed'?`未实跑(${facts.reason})`
15
17
  :facts.red.skipped?'tasks.md 未写测试文件,没有只放入测试文件的实跑'
16
18
  :`只放入测试文件时检查 ${facts.red.outcome}`;
17
19
 
18
20
  // report: the developer's items, null (absent) or 'invalid'. facts: replayDelivery's result.
19
- export function autoVerificationVerdict({report,facts}){
21
+ export function autoVerificationVerdict({report,facts,contract=null}){
20
22
  if(report===null)return {satisfied:false,unsatisfied:['开发结果没有逐条要求与证据(requirements)']};
21
23
  if(report==='invalid')return {satisfied:false,unsatisfied:['开发结果的逐条要求与证据(requirements)格式不合法']};
22
- const unsatisfied=[],replayed=facts.status==='replayed';
24
+ const unsatisfied=contract?acceptanceProblems(contract,report,facts):[],replayed=facts.status==='replayed';
23
25
  for(const item of report){
24
26
  if(item.satisfied!==true){unsatisfied.push(item.requirement);continue;}
25
27
  if(item.run==='red'&&!(replayed&&!facts.red.skipped&&facts.red.outcome==='failed'))