@aibyzero/cm-workflow 0.16.6 → 0.16.8

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 (90) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +29 -0
  3. package/README.md +32 -1
  4. package/VERSION +1 -1
  5. package/assets/readme/workflow-recovery-detailed.png +0 -0
  6. package/assets/readme/workflow-stages-detailed.png +0 -0
  7. package/docs/installation.md +1 -1
  8. package/docs/js-workflow-control.md +84 -9
  9. package/docs/user-guide.md +104 -0
  10. package/package.json +1 -1
  11. package/runtime/js/cm-ai/cm-ai-admission.mjs +37 -11
  12. package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +9 -5
  13. package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +56 -17
  14. package/runtime/js/cm-ai/cm-ai-qa-log.mjs +172 -33
  15. package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -1
  16. package/runtime/js/cm-ai/developer-adapter.mjs +8 -5
  17. package/runtime/js/cm-ai/drive-bootstrap.mjs +2 -2
  18. package/runtime/js/cm-ai/drive-core.mjs +17 -4
  19. package/runtime/js/cm-ai/durable-runner-state.mjs +29 -0
  20. package/runtime/js/cm-ai/execution-store.mjs +4 -2
  21. package/runtime/js/cm-ai/host-conversation-execution.mjs +11 -3
  22. package/runtime/js/cm-ai/host-documentation.mjs +2 -2
  23. package/runtime/js/cm-ai/host-qa-executor.mjs +89 -19
  24. package/runtime/js/cm-ai/host-session.mjs +46 -6
  25. package/runtime/js/cm-ai/host-tool-bridge.mjs +15 -3
  26. package/runtime/js/cm-ai/host-workflow-capabilities.mjs +4 -2
  27. package/runtime/js/cm-ai/log-rows.mjs +36 -0
  28. package/runtime/js/cm-ai/operator-guidance.mjs +3 -0
  29. package/runtime/js/cm-ai/reviewed-deliveries.mjs +29 -6
  30. package/runtime/js/cm-ai/task-runner.mjs +6 -1
  31. package/runtime/js/cm-fix/cause-package.mjs +37 -8
  32. package/runtime/js/cm-fix/diagnosis.mjs +43 -0
  33. package/runtime/js/cm-fix/execution.mjs +189 -148
  34. package/runtime/js/cm-fix/finish.mjs +2 -19
  35. package/runtime/js/cm-fix/investigation.mjs +25 -9
  36. package/runtime/js/cm-fix/log-events.mjs +29 -0
  37. package/runtime/js/cm-fix/metrics.mjs +3 -2
  38. package/runtime/js/cm-fix/progress.mjs +3 -1
  39. package/runtime/js/cm-prd/analysis.mjs +5 -2
  40. package/runtime/js/cm-prd/review-host.mjs +2 -1
  41. package/runtime/js/cm-test/recovery.mjs +4 -4
  42. package/runtime/js/notify-run.mjs +26 -0
  43. package/runtime/js/notify.mjs +388 -0
  44. package/runtime/model-efficiency.md +17 -0
  45. package/scripts/cm-ai-admission.mjs +14 -3
  46. package/scripts/cm-ai-batch-drive.mjs +2 -2
  47. package/scripts/cm-ai-batch-host.mjs +7 -2
  48. package/scripts/cm-ai-batch-run.mjs +11 -2
  49. package/scripts/cm-ai-batch-run.test.mjs +9 -1
  50. package/scripts/cm-ai-drive.mjs +18 -4
  51. package/scripts/cm-ai-drive.test.mjs +30 -0
  52. package/scripts/cm-ai-feature-selection.test.mjs +178 -0
  53. package/scripts/cm-ai-fix-run-delivery.test.mjs +138 -0
  54. package/scripts/cm-ai-host.mjs +20 -8
  55. package/scripts/cm-ai-host.test.mjs +88 -0
  56. package/scripts/cm-ai-project-qa-gate.test.mjs +71 -4
  57. package/scripts/cm-ai-protected-scope.test.mjs +194 -0
  58. package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +77 -4
  59. package/scripts/cm-ai-run.mjs +36 -5
  60. package/scripts/cm-fix-abandon.test.mjs +89 -3
  61. package/scripts/cm-fix-cause-package.test.mjs +33 -0
  62. package/scripts/cm-fix-drive.mjs +9 -1
  63. package/scripts/cm-fix-host.mjs +1 -1
  64. package/scripts/cm-fix-large-log.test.mjs +113 -0
  65. package/scripts/cm-fix-rediagnosis.test.mjs +71 -4
  66. package/scripts/cm-host-qa-executor.test.mjs +429 -3
  67. package/scripts/cm-log-event.mjs +53 -6
  68. package/scripts/cm-notify.test.mjs +468 -0
  69. package/scripts/cm-patrol.mjs +83 -0
  70. package/scripts/cm-patrol.test.mjs +161 -0
  71. package/scripts/cm-prd-host.mjs +13 -2
  72. package/scripts/cm-prd-host.test.mjs +4 -0
  73. package/scripts/cm-prd-review-host.test.mjs +17 -0
  74. package/scripts/cm-prd-session-recovery.test.mjs +44 -2
  75. package/scripts/cm-prd-task-grouping.test.mjs +206 -0
  76. package/scripts/cm-review-scope-recovery.test.mjs +5 -3
  77. package/scripts/cm-test-branch-impact.test.mjs +11 -0
  78. package/scripts/cm-token-report.mjs +497 -0
  79. package/scripts/cm-token-report.test.mjs +346 -0
  80. package/skills/cm-ai/SKILL.md +7 -3
  81. package/skills/cm-ai/references/N1-init.md +1 -1
  82. package/skills/cm-ai/references/N6-qa-eval.md +2 -2
  83. package/skills/cm-ai/references/js-host-modes.md +90 -0
  84. package/skills/cm-ai/references/js-host-qa-recovery.md +110 -0
  85. package/skills/cm-ai/references/js-host-recovery.md +199 -0
  86. package/skills/cm-ai/references/js-host.md +69 -330
  87. package/skills/cm-fix/SKILL.md +2 -0
  88. package/skills/cm-fix/references/js-host.md +16 -9
  89. package/skills/cm-prd/SKILL.md +7 -4
  90. package/skills/cm-prd/references/spec-self-check.md +3 -1
@@ -34,8 +34,8 @@ export function inspectCmAiBootstrapTask({specsDir,codeProject,taskId},inProgres
34
34
  }
35
35
 
36
36
  // Read N6 task counts with the original task parser, including later features.
37
- export function inspectCmAiQaTaskContext({specsDir,codeProject,feature,taskId}) {
38
- const admission=inspectCmAiAdmission({specsDir,codeProject});
37
+ export function inspectCmAiQaTaskContext({specsDir,codeProject,feature,taskId,featureSelection}) {
38
+ const admission=inspectCmAiAdmission({specsDir,codeProject,...selectedFeature(featureSelection)});
39
39
  const fail=code=>{throw Object.assign(new Error(code),{code});};
40
40
  if(!['ready','complete'].includes(admission.state))fail(admission.reason);
41
41
  const discovered=discoverFeatures(admission.specsDir);if(discovered.error)fail(discovered.error);
@@ -49,13 +49,15 @@ export function inspectCmAiQaTaskContext({specsDir,codeProject,feature,taskId})
49
49
  // Plan construction happens before task completion; decisions still bind a completed task.
50
50
  if(!selected||(taskId!==undefined&&!selected.some(task=>task.id===taskId&&task.completed&&!task.dropped)))fail('qa_not_ready');
51
51
  const pending=selected.filter(task=>!task.completed&&!task.dropped).length;
52
- return frozen({completed,pendingFeatures,pending,mergeEligible:pending===1&&admission.nextTask?.feature===feature});
52
+ // The feature's [DROPPED] task ids: N6 does not plan a case bound only to them.
53
+ const dropped=selected.filter(task=>task.dropped).map(task=>task.id);
54
+ return frozen({completed,pendingFeatures,pending,dropped,mergeEligible:pending===1&&admission.nextTask?.feature===feature});
53
55
  }
54
56
 
55
57
  // Admission's public feature summary stops at the selected feature. Count all
56
58
  // approved features with the same parser before treating a task as the last one.
57
- export function isFinalCmAiTask({specsDir,codeProject,feature,taskId,parallelSelection=null}) {
58
- const admission=inspectCmAiAdmission({specsDir,codeProject});
59
+ export function isFinalCmAiTask({specsDir,codeProject,feature,taskId,parallelSelection=null,featureSelection}) {
60
+ const admission=inspectCmAiAdmission({specsDir,codeProject,...selectedFeature(featureSelection)});
59
61
  if(!matchesCmAiTaskSelection(admission,feature,taskId,parallelSelection))
60
62
  throw Object.assign(new Error('documentation_admission_required'),{code:'documentation_admission_required'});
61
63
  const discovered=discoverFeatures(admission.specsDir);
@@ -69,6 +71,11 @@ export function isFinalCmAiTask({specsDir,codeProject,feature,taskId,parallelSel
69
71
  return pending===1;
70
72
  }
71
73
 
74
+ // An explicit feature selection is bound by the run definition (featureSelection)
75
+ // and only then passed to admission. Without it, selection is the original
76
+ // lowest-numbered feature with pending tasks.
77
+ export const selectedFeature=feature=>feature===undefined||feature===null?{}:{feature};
78
+
72
79
  function frozen(value){
73
80
  if(value && typeof value==='object'){for(const item of Object.values(value))frozen(item);Object.freeze(value);}
74
81
  return value;
@@ -89,7 +96,7 @@ function approvalIntent(response,assumeYes){
89
96
  if(response===undefined||response===null||response==='')return 'none';
90
97
  if(typeof response!=='string')return 'not_approval';
91
98
  const normalized=response.trim().replace(/[。!!.~~\s]+$/gu,'');
92
- return new Set(['开始','开始吧','可以开始','确认开始','开始执行','现在开始']).has(normalized)?'explicit':'not_approval';
99
+ return new Set(['开始','开始吧','可以开始','确认开始','开始执行','现在开始','可以,请开始开发']).has(normalized)?'explicit':'not_approval';
93
100
  }
94
101
 
95
102
 
@@ -311,7 +318,7 @@ function dependenciesSatisfied(task,parsed,byId){
311
318
  });
312
319
  }
313
320
 
314
- function selectTask(specsDir,names){
321
+ function selectTask(specsDir,names,requestedFeature=null){
315
322
  const features=[];
316
323
  const warnings=[];
317
324
  const evidence=reviewEvidenceNames(specsDir);
@@ -335,6 +342,9 @@ function selectTask(specsDir,names){
335
342
  pending:pending.length,
336
343
  });
337
344
  if(!pending.length)continue;
345
+ // An explicitly selected later feature passes over earlier unfinished ones;
346
+ // they stay pending and unchanged, with their counts in features.
347
+ if(requestedFeature!==null&&name!==requestedFeature)continue;
338
348
  // One dependency rule for nextTask and --task/parallel eligibility: a
339
349
  // prerequisite is satisfied once it is completed or DROPPED.
340
350
  const ready=task=>dependenciesSatisfied(task,parsed,byId);
@@ -343,6 +353,16 @@ function selectTask(specsDir,names){
343
353
  return {features,warnings,nextTask:{feature:name,id:eligible.id,description:eligible.description},
344
354
  eligibleTasks:pending.filter(ready).map(task=>({feature:name,id:task.id}))};
345
355
  }
356
+ // The selected feature has nothing left: say so, and report the project's own
357
+ // next task rather than "complete". Callers never bind it to the selection.
358
+ // Keep this loop's feature summaries (every feature, the selected one too):
359
+ // the run of that feature still refreshes its context after its last task.
360
+ if(requestedFeature!==null){
361
+ const project=selectTask(specsDir,names);
362
+ if(project.error)return project;
363
+ return {...project,features,warnings:[...warnings,`所选 feature ${requestedFeature} 已无待办任务;`
364
+ +'不会为其他 feature 建运行或生成运行定义,请明确选择下一个 feature'],requestedFeatureComplete:requestedFeature};
365
+ }
346
366
  return {features,warnings,nextTask:null};
347
367
  }
348
368
 
@@ -420,6 +440,9 @@ function admissionFor(options,inProgressBootstrap=null){
420
440
  if(!codeProject)return result(base,'blocked','code_project_missing');
421
441
  const discovered=discoverFeatures(specsDir);
422
442
  if(discovered.error)return result(base,'blocked',discovered.error);
443
+ const requestedFeature=input.feature===undefined?null:input.feature;
444
+ if(requestedFeature!==null&&!discovered.names.includes(requestedFeature))
445
+ return result(base,'blocked','feature_selection_invalid');
423
446
  const status=readSpecsStatus(specsDir);
424
447
  if(status.kind==='invalid')return result(base,'blocked','spec_status_invalid');
425
448
  if(status.kind==='missing'||status.value.status==='awaiting_review'){
@@ -439,12 +462,13 @@ function admissionFor(options,inProgressBootstrap=null){
439
462
  const bootstrapProblem=validateBootstrap(codeProject,specsDir,discovered.names);
440
463
  if(bootstrapProblem&&!(bootstrapProblem==='bootstrap_conflict'&&inProgressBootstrap==='T-001'))
441
464
  return result(base,'blocked',bootstrapProblem);
442
- const selection=selectTask(specsDir,discovered.names);
465
+ const selection=selectTask(specsDir,discovered.names,requestedFeature);
443
466
  if(selection.error)return result(base,'blocked',selection.error,{features:selection.features,warnings:selection.warnings,
444
467
  ...(selection.detail?{detail:selection.detail}:{})});
445
468
  const warnings=[...selection.warnings,...featureQaWarnings(specsDir,selection.features)];
446
- if(!selection.nextTask)return result(base,'complete','all_tasks_terminal',{features:selection.features,warnings});
447
- return result(base,'ready','task_selected',{features:selection.features,nextTask:selection.nextTask,eligibleTasks:selection.eligibleTasks,warnings});
469
+ const requested=selection.requestedFeatureComplete?{requestedFeatureComplete:selection.requestedFeatureComplete}:{};
470
+ if(!selection.nextTask)return result(base,'complete','all_tasks_terminal',{features:selection.features,warnings,...requested});
471
+ return result(base,'ready','task_selected',{features:selection.features,nextTask:selection.nextTask,eligibleTasks:selection.eligibleTasks,warnings,...requested});
448
472
  }
449
473
 
450
474
  // Diagnostic only: why an explicit --task selection is not eligible. Never used
@@ -452,7 +476,9 @@ function admissionFor(options,inProgressBootstrap=null){
452
476
  export function explainCmAiTaskSelection(admission,{feature,taskId,selection=null}){
453
477
  if(admission.state!=='ready')return `当前准入状态为 ${admission.state}/${admission.reason},不能选择任务`;
454
478
  const next=admission.nextTask;
455
- if(next&&next.feature!==feature)return `--task 只能选择当前 feature ${next.feature} 的任务(运行定义为 ${feature})`;
479
+ if(admission.requestedFeatureComplete===feature)return `所选 feature ${feature} 已无待办任务,不能为它新建运行;请明确选择下一个 feature`;
480
+ if(next&&next.feature!==feature)return `--task 只能选择当前 feature ${next.feature} 的任务(运行定义为 ${feature})`
481
+ +(admission.requestedFeatureComplete===undefined?`;已批准的跨 feature 顺序要先做 ${feature} 时,用 cm-ai-admission.mjs --feature ${feature} --print-run-definition 重新生成运行定义,或给 cm-ai-host.mjs 加 --feature ${feature}`:'');
456
482
  if(!admission.specsDir)return `${taskId} 不在可选任务中`;
457
483
  let parsed;
458
484
  try{parsed=readFeature(admission.specsDir,feature);}catch{return `无法读取 ${feature}/tasks.md`;}
@@ -2,7 +2,7 @@
2
2
  import {createHash} from 'node:crypto';
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
- import {inspectCmAiAdmission,matchesCmAiTaskSelection,identifyApprovedBootstrapFeature} from './cm-ai-admission.mjs';
5
+ import {inspectCmAiAdmission,matchesCmAiTaskSelection,identifyApprovedBootstrapFeature,selectedFeature} from './cm-ai-admission.mjs';
6
6
  import {arrayItems,digest,freeze,hex,json,need,shape,text,validIdentity,validTaskLearningInput} from './effect-contract.mjs';
7
7
 
8
8
  const BASELINE_RULES=['coding-style.md','testing.md','security.md'];
@@ -59,9 +59,12 @@ export function readProjectInstructionContext(codeProject,applicableAgentFiles=[
59
59
  }
60
60
 
61
61
  export function inspectCmAiContextRefresh(input,{admission:trustedAdmission=null}={}) {
62
- shape(input,['specsDir','codeProject','feature','applicableAgentFiles']);
62
+ shape(input,['specsDir','codeProject','feature','applicableAgentFiles',...(Object.hasOwn(input,'featureSelection')?['featureSelection']:[])]);
63
63
  text(input.specsDir);text(input.codeProject);text(input.feature);
64
- const admission=trustedAdmission??inspectCmAiAdmission({specsDir:input.specsDir,codeProject:input.codeProject});
64
+ // A run bound to an explicit feature (featureSelection) reads admission for it.
65
+ need(!Object.hasOwn(input,'featureSelection')||input.featureSelection===input.feature,'context_invalid');
66
+ const admission=trustedAdmission??inspectCmAiAdmission({specsDir:input.specsDir,codeProject:input.codeProject,
67
+ ...selectedFeature(input.featureSelection)});
65
68
  if(trustedAdmission!==null)need(input.feature===identifyApprovedBootstrapFeature(
66
69
  trustedAdmission.features.map(item=>item.name))
67
70
  &&admission.specsDir===input.specsDir&&admission.codeProject===input.codeProject,'context_invalid');
@@ -80,10 +83,11 @@ export function inspectCmAiContextRefresh(input,{admission:trustedAdmission=null
80
83
  }
81
84
 
82
85
  export function inspectCmAiTaskLearningInput(input,authority={}) {
83
- shape(input,['specsDir','codeProject','feature','identity','applicableAgentFiles']);
86
+ shape(input,['specsDir','codeProject','feature','identity','applicableAgentFiles',...(Object.hasOwn(input,'featureSelection')?['featureSelection']:[])]);
84
87
  text(input.feature);const identity=json(input.identity);validIdentity(identity);
85
88
  const refresh=inspectCmAiContextRefresh({specsDir:input.specsDir,codeProject:input.codeProject,
86
- feature:input.feature,applicableAgentFiles:input.applicableAgentFiles},authority);
89
+ feature:input.feature,applicableAgentFiles:input.applicableAgentFiles,
90
+ ...(Object.hasOwn(input,'featureSelection')?{featureSelection:input.featureSelection}:{})},authority);
87
91
  need(matchesCmAiTaskSelection(refresh,input.feature,identity.taskId,authority.parallelSelection??null),'learning_context_invalid');
88
92
  const agentPaths=new Set(['AGENTS.md',...arrayItems(input.applicableAgentFiles)]);
89
93
  const selected=refresh.contextFiles.filter(file=>file.scope==='specs'?file.path==='LESSONS.md':
@@ -1,5 +1,5 @@
1
1
  // Fixed Codex-host entry for the existing cm-ai admission and V3 task runner.
2
- import {inspectCmAiAdmission,matchesCmAiTaskSelection} from './cm-ai-admission.mjs';
2
+ import {inspectCmAiAdmission,matchesCmAiTaskSelection,selectedFeature} from './cm-ai-admission.mjs';
3
3
  import {inspectCmAiContextRefresh,inspectCmAiTaskLearningInput} from './cm-ai-context-refresh.mjs';
4
4
  import {findCmAiQaDecision,inspectCmAiQaDecision,inspectCmAiQaResult,recordCmAiQaDecision,
5
5
  latestCmAiQaRun,recordCmAiQaRun,inspectCmAiQaRecovery,inspectCmAiQaConfigurationRecovery,timedOutQaDecision,
@@ -69,7 +69,7 @@ const correctionSummary=(operation,status)=>status.code==='correction_review_req
69
69
  // run_done is a project claim: every approved feature's latest mandatory QA must
70
70
  // have passed, not only this final run's own. Read with the strict owner validator.
71
71
  function projectQaSummary(operation,status,options){
72
- const admission=inspectCmAiAdmission({specsDir:options.specsDir,codeProject:options.codeProject});
72
+ const admission=inspectCmAiAdmission({specsDir:options.specsDir,codeProject:options.codeProject,...selectedFeature(options.featureSelection)});
73
73
  const outstanding=outstandingFeatureQa({specsDir:options.specsDir,features:admission.features.map(({name,pending})=>({name,pending})),
74
74
  currentRunId:status.identity.runId,inspect:latestCmAiQaRun});
75
75
  if(!outstanding.length)return null;
@@ -196,7 +196,9 @@ export function createCmAiConversationEntry(options) {
196
196
  if(options&&Object.hasOwn(options,'allowAbandonEffect'))optionKeys.push('allowAbandonEffect');
197
197
  if(options&&Object.hasOwn(options,'allowBootstrapReviewRecovery'))optionKeys.push('allowBootstrapReviewRecovery');
198
198
  if(options&&Object.hasOwn(options,'holdRevision'))optionKeys.push('holdRevision');
199
+ if(options&&Object.hasOwn(options,'featureSelection'))optionKeys.push('featureSelection');
199
200
  shape(options,optionKeys);
201
+ need(!Object.hasOwn(options,'featureSelection')||options.featureSelection===options.feature,'invalid_input');
200
202
  need(!Object.hasOwn(options,'holdRevision')||options.holdRevision===true,'invalid_input');
201
203
  if(Object.hasOwn(options,'developmentAttempt'))need([1,2].includes(options.developmentAttempt),'invalid_development_attempt');
202
204
  text(options.specsDir);text(options.codeProject);text(options.feature);
@@ -263,16 +265,20 @@ export function createCmAiConversationEntry(options) {
263
265
  // Operator declaration that the latest FAIL came from the environment; only
264
266
  // meaningful with the one-shot rerun authorization and consumed with it.
265
267
  const qaEnvironmentFailure=options.qaEnvironmentFailure??null;
266
- need(qaEnvironmentFailure===null||rerunBlockedQa&&validEnvironmentFailureReason(qaEnvironmentFailure),'qa_recovery_authorization_required');
268
+ // With --rerun-unknown-qa it is the operator's attestation that older timed-out
269
+ // case rows (no host_request_timeout field) had no session answer.
270
+ need(qaEnvironmentFailure===null||(rerunBlockedQa||rerunUnknownQa)&&validEnvironmentFailureReason(qaEnvironmentFailure),'qa_recovery_authorization_required');
267
271
  if(Object.hasOwn(options,'qaExecutor')){
268
272
  shape(options.qaExecutor,['mode','caseCount','timeoutMs','run',
269
273
  ...(Object.hasOwn(options.qaExecutor,'configuration')?['configuration']:[]),
274
+ ...(Object.hasOwn(options.qaExecutor,'requestTimeoutMs')?['requestTimeoutMs']:[]),
270
275
  ...(Object.hasOwn(options.qaExecutor,'prepare')?['prepare']:[])]);
271
276
  const {run,prepare,...config}=options.qaExecutor;
272
277
  need(typeof run==='function'&&(prepare===undefined||typeof prepare==='function'));
273
278
  qaExecutor={...json(config),run,...(prepare?{prepare}:{})};
274
279
  need(['commands','browser','all'].includes(config.mode)&&Number.isSafeInteger(config.caseCount)&&config.caseCount>0);
275
280
  need(Number.isInteger(config.timeoutMs)&&config.timeoutMs>=1&&config.timeoutMs<=3600000);
281
+ need(config.requestTimeoutMs===undefined||Number.isInteger(config.requestTimeoutMs)&&config.requestTimeoutMs>=1&&config.requestTimeoutMs<=3600000);
276
282
  }
277
283
  const applicableAgentFiles=Object.hasOwn(options,'applicableAgentFiles')?json(options.applicableAgentFiles):null;
278
284
  const documentationResult=Object.hasOwn(options,'documentationResult')?json(options.documentationResult):null;
@@ -313,7 +319,7 @@ export function createCmAiConversationEntry(options) {
313
319
  need(!controller.signal.aborted,'cancelled');need(result.syncId===syncId,'stale_documentation');
314
320
  const current=boundStatus(runner.status(),status.identity);
315
321
  need(current.state==='fixture_completed'&&current.code==null&&current.packageDigest===status.packageDigest,'stale_documentation');
316
- const reread=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,
322
+ const reread=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,...(options.featureSelection===undefined?{}:{featureSelection:options.featureSelection}),
317
323
  feature:options.feature,applicableAgentFiles});
318
324
  need(reread.state==='complete'&&reread.contextDigest===refresh.contextDigest,'stale_documentation');
319
325
  validateDocumentationResult(result,current,reread,knowledgeCloseout);
@@ -330,7 +336,7 @@ export function createCmAiConversationEntry(options) {
330
336
  need(sameTask(operation.identity,ownerIdentity),'identity_mismatch');
331
337
  need(operation.identity.attempt>=ownerIdentity.attempt,'identity_mismatch');
332
338
  const admission=['start','resume'].includes(operation.operation)
333
- ?runner.inspectBootstrapAdmission?.()??inspectCmAiAdmission({specsDir:options.specsDir,codeProject:options.codeProject}):null;
339
+ ?runner.inspectBootstrapAdmission?.()??inspectCmAiAdmission({specsDir:options.specsDir,codeProject:options.codeProject,...selectedFeature(options.featureSelection)}):null;
334
340
  if(admission&&admission.state!=='ready'){
335
341
  // Original callers still stop before reading runner state. A caller using
336
342
  // a newer attempt must bind it to the runner before we report its block.
@@ -384,7 +390,9 @@ export function createCmAiConversationEntry(options) {
384
390
  notCancelled();
385
391
  need(pendingExecution===null,'qa_execution_pending');
386
392
  const binding={specsDir:options.specsDir,feature:options.feature,identity:result.identity,packageDigest:result.packageDigest};
387
- let previous,recovery=null,configurationRecovery=false;
393
+ let previous,recovery=null,configurationRecovery=false,incompleteReport=false,timedOutCall=false;
394
+ const timedOutRecovery=()=>inspectCmAiQaRecovery(binding,{timedOut:true,requestTimeoutMs:qaExecutor.requestTimeoutMs??null,
395
+ attestation:rerunUnknownQa?qaEnvironmentFailure:null});
388
396
  try{previous=latestCmAiQaRun(binding);}
389
397
  catch(error){
390
398
  if(error.code==='qa_result_superseded'){
@@ -395,6 +403,26 @@ export function createCmAiConversationEntry(options) {
395
403
  if(rerunUnknownQa){
396
404
  try{recovery=inspectCmAiQaRecovery(binding);}
397
405
  catch(error){if(error.code!=='qa_execution_unknown')throw error;}
406
+ // A call stopped by qa_execution_timeout whose only non-PASS
407
+ // cases are host request timeouts: supersede it into the next round.
408
+ if(recovery===null)try{recovery=timedOutRecovery();timedOutCall=true;}
409
+ catch(error){if(error.code!=='qa_execution_unknown')throw error;}
410
+ }
411
+ // The call wrote its fixed report but no complete row (a host before
412
+ // this fix rejected stale_qa in between). --rerun-blocked-qa reads
413
+ // that report under the ordinary blocked-evidence rules.
414
+ if(recovery===null&&rerunBlockedQa){
415
+ try{recovery=inspectCmAiQaRecovery(binding,{blocked:true,environment:qaExecutor.configuration?.environment,
416
+ environmentFailure:qaEnvironmentFailure});}
417
+ catch(error){
418
+ // Name the flag that does recover a timed-out call.
419
+ let timedOutCallRecoverable=false;try{timedOutRecovery();timedOutCallRecoverable=true;}
420
+ catch(probe){timedOutCallRecoverable=probe?.code==='qa_environment_failure_required';}
421
+ if(error.code==='qa_rerun_not_blocked_by_evidence'&&timedOutCallRecoverable)
422
+ throw Object.assign(new Error('use --rerun-unknown-qa'),{code:'qa_rerun_unknown_qa_required'});
423
+ throw error;
424
+ }
425
+ incompleteReport=true;
398
426
  }
399
427
  if(recovery===null)return summary(operation,{...runner.status(),code:'qa_execution_unknown'},'blocked');
400
428
  previous=null;
@@ -404,7 +432,7 @@ export function createCmAiConversationEntry(options) {
404
432
  // decision with no QA run under it yet (just written, or written
405
433
  // before an interruption): run the ordinary first round, not a rerun.
406
434
  if(rerunBlockedQa&&previous===null&&replacesTimedOutQaDecision(binding))rerunBlockedQa=false;
407
- if(rerunBlockedQa){
435
+ if(rerunBlockedQa&&!incompleteReport){
408
436
  need(previous!==null,'qa_rerun_not_blocked_by_evidence');
409
437
  recovery=inspectCmAiQaRecovery(binding,{blocked:true,environment:qaExecutor.configuration?.environment,
410
438
  environmentFailure:qaEnvironmentFailure});
@@ -417,7 +445,7 @@ export function createCmAiConversationEntry(options) {
417
445
  if(previous===null||repaired||rerunBlockedQa){
418
446
  // Later rounds require an accepted completed repair or explicit
419
447
  // evidence recovery/configuration revision. Unknown execution stops.
420
- const qaRound=recovery?recovery.qaRound+(rerunBlockedQa||configurationRecovery?1:0):(repaired?accepted.qaRound+1:1);
448
+ const qaRound=recovery?recovery.qaRound+(rerunBlockedQa||configurationRecovery||timedOutCall?1:0):(repaired?accepted.qaRound+1:1);
421
449
  need(qaRound>=1&&qaRound<=3,'qa_round_invalid');
422
450
  testRunId=`qa-${digest(recovery?{...binding,previousTestRunId:recovery.testRunId}:
423
451
  repaired?{...binding,qaRound,repair:accepted.evidenceDigest}:binding).slice(0,48)}`;
@@ -427,13 +455,16 @@ export function createCmAiConversationEntry(options) {
427
455
  notCancelled();
428
456
  if(recovery&&!configurationRecovery){
429
457
  recordCmAiQaRun({...logInput,testRunId:recovery.testRunId,mode:recovery.mode,
430
- caseCount:recovery.caseCount,qaRound:recovery.qaRound,phase:rerunBlockedQa?'superseded':'abandoned',
458
+ caseCount:recovery.caseCount,qaRound:recovery.qaRound,phase:rerunBlockedQa||timedOutCall?'superseded':'abandoned',
459
+ ...(timedOutCall?{timedOutRecovery:{requestTimeoutMs:recovery.requestTimeoutMs,attestation:recovery.attestation}}:{}),
431
460
  ...(rerunBlockedQa?{expectedEnvironment:qaExecutor.configuration?.environment??null}:{}),
432
461
  ...(rerunBlockedQa&&qaEnvironmentFailure!==null?{environmentFailure:qaEnvironmentFailure}:{})});
433
462
  rerunUnknownQa=false;rerunBlockedQa=false;
434
463
  }
435
464
  recordCmAiQaRun({...logInput,phase:'start',
436
465
  deferredCases:qaExecutor.configuration?.plan?.deferred_cases??[],
466
+ ...(qaExecutor.configuration?.plan?.dropped_task_cases?{droppedTaskCases:qaExecutor.configuration.plan.dropped_task_cases}:{}),
467
+ ...(qaExecutor.configuration?.plan?.dropped_task_commands?{droppedTaskCommands:qaExecutor.configuration.plan.dropped_task_commands}:{}),
437
468
  ...(recovery?{previousTestRunId:recovery.testRunId}:{})});
438
469
  const controller=new AbortController();pendingExecution=controller;
439
470
  let timer,timedOut=false;
@@ -449,9 +480,16 @@ export function createCmAiConversationEntry(options) {
449
480
  return qaExecutor.run(freeze(invocation),controller.signal);
450
481
  }),interrupted]);
451
482
  need(!controller.signal.aborted,'cancelled');
483
+ // A run that moved on meanwhile (for example files in scope replaced):
484
+ // still record a BLOCKED or FAIL this call observed, so the restored run
485
+ // can take the ordinary --rerun-blocked-qa path instead of staying
486
+ // qa_execution_unknown (a source change is already BLOCKED/sourceChanged).
487
+ // A PASS is never recorded unconfirmed; it stays unknown, and only
488
+ // --rerun-unknown-qa may discard that fully backed all-PASS report.
452
489
  const current=boundStatus(runner.status(),result.identity);
453
- need(current.state==='fixture_completed'&&current.code==null&&current.packageDigest===result.packageDigest,'stale_qa');
454
- recordCmAiQaRun({...logInput,phase:'complete',result:executed});
490
+ const fresh=current.state==='fixture_completed'&&current.code==null&&current.packageDigest===result.packageDigest;
491
+ if(fresh||executed.result!=='PASS')recordCmAiQaRun({...logInput,phase:'complete',result:executed});
492
+ need(fresh,'stale_qa');
455
493
  }finally{clearTimeout(timer);pendingExecution=null;}
456
494
  }
457
495
  result=await call('qa_result',result.packageDigest,{testRunId});
@@ -622,7 +660,7 @@ export function createCmAiConversationEntry(options) {
622
660
  }
623
661
  if(decision===null)return summary(operation,{...status,code:'qa_decision_required'},'awaiting');
624
662
  if(decision.status==='skipped'){
625
- const admission=inspectCmAiAdmission({specsDir:options.specsDir,codeProject:options.codeProject});
663
+ const admission=inspectCmAiAdmission({specsDir:options.specsDir,codeProject:options.codeProject,...selectedFeature(options.featureSelection)});
626
664
  if(!['ready','complete'].includes(admission.state))
627
665
  return summary(operation,{...status,code:admission.reason},'awaiting');
628
666
  const feature=admission.features.find(item=>item.name===options.feature);
@@ -663,7 +701,7 @@ export function createCmAiConversationEntry(options) {
663
701
  need(status.state==='fixture_completed','context_not_ready');
664
702
  contextEvidence(options,identity,operation);
665
703
  need(applicableAgentFiles!==null,'context_invalid');
666
- const refresh=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,
704
+ const refresh=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,...(options.featureSelection===undefined?{}:{featureSelection:options.featureSelection}),
667
705
  feature:options.feature,applicableAgentFiles});
668
706
  if(!['ready','complete'].includes(refresh.state))return summary(operation,{state:refresh.state,
669
707
  code:refresh.reason,identity,packageDigest:status.packageDigest},'awaiting');
@@ -676,7 +714,7 @@ export function createCmAiConversationEntry(options) {
676
714
  need(status.state==='fixture_completed','run_not_ready');
677
715
  contextEvidence(options,identity,operation);
678
716
  need(applicableAgentFiles!==null,'context_invalid');
679
- const refresh=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,
717
+ const refresh=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,...(options.featureSelection===undefined?{}:{featureSelection:options.featureSelection}),
680
718
  feature:options.feature,applicableAgentFiles});
681
719
  need(refresh.state==='complete','run_not_ready');
682
720
  const projectQa=projectQaSummary(operation,status,options);if(projectQa)return projectQa;
@@ -701,7 +739,7 @@ export function createCmAiConversationEntry(options) {
701
739
  need(status.state==='fixture_completed','run_not_ready');
702
740
  contextEvidence(options,identity,operation);
703
741
  need(applicableAgentFiles!==null,'context_invalid');
704
- const refresh=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,
742
+ const refresh=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,...(options.featureSelection===undefined?{}:{featureSelection:options.featureSelection}),
705
743
  feature:options.feature,applicableAgentFiles});
706
744
  need(refresh.state==='complete','run_not_ready');
707
745
  const projectQa=projectQaSummary(operation,status,options);if(projectQa)return projectQa;
@@ -712,7 +750,7 @@ export function createCmAiConversationEntry(options) {
712
750
  const current=boundStatus(runner.status(),identity);
713
751
  need(!current.cancellationRequested&&!current.cancelAfterCommit,'cancelled');
714
752
  need(current.state==='fixture_completed'&&current.code==null&&current.packageDigest===status.packageDigest,'stale_documentation');
715
- const finalContext=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,
753
+ const finalContext=inspectCmAiContextRefresh({specsDir:options.specsDir,codeProject:options.codeProject,...(options.featureSelection===undefined?{}:{featureSelection:options.featureSelection}),
716
754
  feature:options.feature,applicableAgentFiles});
717
755
  need(finalContext.state==='complete'&&finalContext.contextDigest===refresh.contextDigest,'stale_documentation');
718
756
  const documentationStatus=validateDocumentationResult(documentation,status,refresh,knowledgeCloseout);
@@ -747,7 +785,8 @@ export function createCmAiConversationEntry(options) {
747
785
  if(options.holdRevision===true&&status.state==='changes_requested')
748
786
  return summary(operation,{...status,code:'revision_answer_required'},'awaiting');
749
787
  const learningInput=inspectCmAiTaskLearningInput({specsDir:options.specsDir,codeProject:options.codeProject,
750
- feature:options.feature,identity,applicableAgentFiles:applicableAgentFiles??[]},
788
+ feature:options.feature,identity,applicableAgentFiles:applicableAgentFiles??[],
789
+ ...(options.featureSelection===undefined?{}:{featureSelection:options.featureSelection})},
751
790
  {admission:runner.inspectBootstrapAdmission?.()??null,parallelSelection:options.parallelSelection??null});
752
791
  // Keep rejected effects immutable. A run-wide rejection count gives each
753
792
  // corrected result a new effect id without changing the provider attempt.