@aibyzero/cm-workflow 0.21.6 → 0.25.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.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +58 -0
- package/README.md +18 -3
- package/VERSION +1 -1
- package/docs/architecture.md +9 -0
- package/docs/cm-acceptance-completion.md +3 -1
- package/docs/cm-control-policy-v2.md +35 -3
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +1 -0
- package/docs/human-correction.md +1 -1
- package/docs/installation.md +42 -16
- package/docs/js-workflow-control.md +65 -30
- package/docs/next-steps.md +10 -0
- package/docs/runtime-failover.md +5 -3
- package/docs/user-guide.md +6 -6
- package/package.json +1 -1
- package/runtime/js/cm-ai/batch-location.mjs +14 -0
- package/runtime/js/cm-ai/batch-plan.mjs +6 -2
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +9 -2
- package/runtime/js/cm-ai/cm-ai-admission.mjs +9 -3
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +51 -8
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +30 -4
- package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -4
- package/runtime/js/cm-ai/delivery-evidence.mjs +3 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +15 -1
- package/runtime/js/cm-ai/drive-core.mjs +50 -6
- package/runtime/js/cm-ai/drive-next-step.mjs +61 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +85 -23
- package/runtime/js/cm-ai/execution-snapshot.mjs +5 -2
- package/runtime/js/cm-ai/execution-store.mjs +21 -3
- package/runtime/js/cm-ai/external-run-guard.mjs +9 -1
- package/runtime/js/cm-ai/host-check.mjs +4 -2
- package/runtime/js/cm-ai/host-conversation-execution.mjs +23 -2
- package/runtime/js/cm-ai/host-handoff.mjs +7 -0
- package/runtime/js/cm-ai/host-progress.mjs +18 -0
- package/runtime/js/cm-ai/host-qa-executor.mjs +47 -15
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +24 -14
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +1 -1
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/operator-guidance.mjs +126 -2
- package/runtime/js/cm-ai/project-qa-gate.mjs +13 -2
- package/runtime/js/cm-ai/provider-review-observation.mjs +7 -3
- package/runtime/js/cm-ai/qa-plan-notes.mjs +106 -0
- package/runtime/js/cm-ai/review-continuation.mjs +102 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +11 -0
- package/runtime/js/cm-ai/review-package.mjs +25 -4
- package/runtime/js/cm-ai/review-presentation.mjs +31 -14
- package/runtime/js/cm-ai/review-runner.mjs +5 -4
- package/runtime/js/cm-ai/review-verdict-rules.mjs +7 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +30 -1
- package/runtime/js/cm-ai/task-commit-codec.mjs +11 -1
- package/runtime/js/cm-ai/task-commit.mjs +7 -4
- package/runtime/js/cm-ai/task-owner.mjs +5 -2
- package/runtime/js/cm-ai/task-runner.mjs +343 -52
- package/runtime/js/cm-ai/tool-preview.mjs +6 -0
- package/runtime/js/cm-fix/diagnosis.mjs +16 -3
- package/runtime/js/cm-fix/execution.mjs +47 -9
- package/runtime/js/cm-fix/finish.mjs +9 -1
- package/runtime/js/cm-fix/step-timing.mjs +222 -0
- package/runtime/js/cm-idea/session.mjs +22 -3
- package/runtime/js/cm-init/review-evidence.mjs +20 -7
- package/runtime/js/cm-prd/ai-draft.mjs +260 -0
- package/runtime/js/cm-prd/analysis.mjs +27 -9
- package/runtime/js/cm-prd/change.mjs +29 -8
- package/runtime/js/cm-prd/failed-correction.mjs +24 -4
- package/runtime/js/cm-prd/narrow-review.mjs +63 -3
- package/runtime/js/cm-prd/review-correction.mjs +65 -5
- package/runtime/js/cm-prd/review-disposition.mjs +10 -1
- package/runtime/js/cm-prd/self-check.mjs +121 -9
- package/runtime/js/cm-prd/session.mjs +55 -13
- package/runtime/js/cm-prd/summary.mjs +34 -6
- package/runtime/js/cm-prd/task-scope-record.mjs +40 -15
- package/runtime/js/cm-refactor/records.mjs +82 -11
- package/runtime/js/cm-refactor/workflow.mjs +3 -1
- package/runtime/js/executor-version.mjs +81 -0
- package/runtime/js/python-log-writer.mjs +15 -0
- package/runtime/js/run-analysis.mjs +136 -11
- package/runtime/logging.md +6 -0
- package/runtime/review.md +3 -1
- package/runtime/workflow-config.md +1 -1
- package/scripts/ci-test-weights.json +1 -0
- package/scripts/cm-ai-admission.mjs +27 -1
- package/scripts/cm-ai-admission.test.mjs +34 -2
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +3 -2
- package/scripts/cm-ai-batch-drive.mjs +54 -17
- package/scripts/cm-ai-batch-drive.test.mjs +123 -6
- package/scripts/cm-ai-batch-host.mjs +55 -9
- package/scripts/cm-ai-batch-host.test.mjs +22 -3
- package/scripts/cm-ai-batch-location.test.mjs +22 -1
- package/scripts/cm-ai-batch-merge.mjs +102 -0
- package/scripts/cm-ai-batch-plan.mjs +55 -2
- package/scripts/cm-ai-batch-plan.test.mjs +228 -6
- package/scripts/cm-ai-batch-run-fixture.mjs +239 -15
- package/scripts/cm-ai-batch-run-parallel.test.mjs +23 -1
- package/scripts/cm-ai-batch-run.mjs +435 -33
- package/scripts/cm-ai-batch-session-member.test.mjs +85 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +23 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +28 -0
- package/scripts/cm-ai-completion-summary.test.mjs +2 -1
- package/scripts/cm-ai-control-v2-drive.test.mjs +39 -9
- package/scripts/cm-ai-direct-review.test.mjs +1 -1
- package/scripts/cm-ai-disk-edits.test.mjs +229 -0
- package/scripts/cm-ai-drive-next-step.test.mjs +191 -0
- package/scripts/cm-ai-drive.mjs +66 -14
- package/scripts/cm-ai-drive.test.mjs +13 -3
- package/scripts/cm-ai-host-cli-workflow.test.mjs +4 -2
- package/scripts/cm-ai-host.mjs +16 -8
- package/scripts/cm-ai-host.test.mjs +12 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +132 -1
- package/scripts/cm-ai-project-qa-gate.test.mjs +26 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -0
- package/scripts/cm-ai-review-continuation.test.mjs +335 -0
- package/scripts/cm-ai-review-failure.test.mjs +13 -10
- package/scripts/cm-ai-review-timeout.test.mjs +1 -1
- package/scripts/cm-ai-run.mjs +42 -11
- package/scripts/cm-ai-run.test.mjs +26 -0
- package/scripts/cm-ai-supersede.test.mjs +10 -2
- package/scripts/cm-capability-gate.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +9 -0
- package/scripts/cm-codex-clean-env.test.mjs +40 -0
- package/scripts/cm-codex-prompt-input.test.mjs +2 -1
- package/scripts/cm-developer-self-review.test.mjs +27 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +4 -3
- package/scripts/cm-efficiency-response.test.mjs +2 -1
- package/scripts/cm-executor-version-draft.test.mjs +251 -0
- package/scripts/cm-executor-version-entries.test.mjs +93 -0
- package/scripts/cm-executor-version-prd.test.mjs +154 -0
- package/scripts/cm-executor-version-records.test.mjs +256 -0
- package/scripts/cm-executor-version.test.mjs +250 -0
- package/scripts/cm-external-model-host.test.mjs +6 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +1 -1
- package/scripts/cm-fix-closeout-preflight.test.mjs +123 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +5 -1
- package/scripts/cm-fix-drive.mjs +7 -2
- package/scripts/cm-fix-drive.test.mjs +45 -0
- package/scripts/cm-fix-entry.mjs +5 -2
- package/scripts/cm-fix-frozen-baseline.test.mjs +50 -0
- package/scripts/cm-fix-host.mjs +9 -2
- package/scripts/cm-fix-test-extension.test.mjs +30 -2
- package/scripts/cm-host-check.test.mjs +12 -0
- package/scripts/cm-host-qa-executor.test.mjs +172 -1
- package/scripts/cm-host-qa-policy.test.mjs +55 -1
- package/scripts/cm-idea-drive.mjs +5 -2
- package/scripts/cm-idea-entry.mjs +5 -2
- package/scripts/cm-idea-host.mjs +3 -1
- package/scripts/cm-init-drive.mjs +8 -5
- package/scripts/cm-init-entry.mjs +5 -2
- package/scripts/cm-init-host.mjs +6 -2
- package/scripts/cm-log-event.mjs +10 -2
- package/scripts/cm-log-event.test.mjs +29 -0
- package/scripts/cm-prd-ai-draft-fixture.mjs +18 -0
- package/scripts/cm-prd-ai-draft.test.mjs +505 -0
- package/scripts/cm-prd-answer-gaps.test.mjs +110 -5
- package/scripts/cm-prd-completion.test.mjs +67 -4
- package/scripts/cm-prd-design-phase.test.mjs +48 -13
- package/scripts/cm-prd-drive.mjs +89 -20
- package/scripts/cm-prd-drive.test.mjs +109 -4
- package/scripts/cm-prd-entry.mjs +5 -2
- package/scripts/cm-prd-host.mjs +89 -20
- package/scripts/cm-prd-host.test.mjs +17 -8
- package/scripts/cm-prd-narrow-review.test.mjs +49 -1
- package/scripts/cm-prd-review-disposition.test.mjs +94 -1
- package/scripts/cm-prd-review-gate.mjs +11 -4
- package/scripts/cm-prd-self-check-rules.test.mjs +175 -10
- package/scripts/cm-prd-self-check.test.mjs +1 -1
- package/scripts/cm-refactor-drive.mjs +10 -4
- package/scripts/cm-refactor-entry.mjs +5 -2
- package/scripts/cm-refactor-host.mjs +3 -1
- package/scripts/cm-run-analysis.test.mjs +373 -1
- package/scripts/cm-runtime-i18n.mjs +3 -3
- package/scripts/cm-runtime-install.mjs +19 -10
- package/scripts/cm-runtime.mjs +2 -4
- package/scripts/cm-runtime.test.mjs +55 -13
- package/scripts/cm-skill-hints-autowire.test.mjs +1 -1
- package/scripts/cm-skill-hints-exam.mjs +3 -1
- package/scripts/cm-skill-hints-install.test.mjs +1 -1
- package/scripts/cm-skill-hints.mjs +106 -10
- package/scripts/cm-skill-hints.test.mjs +162 -6
- package/scripts/cm-skill-judge.mjs +2 -1
- package/scripts/cm-statusline.test.mjs +54 -0
- package/scripts/cm-task-gate.mjs +88 -18
- package/scripts/cm-task-scope.test.mjs +1 -1
- package/scripts/cm-test-drive.mjs +13 -8
- package/scripts/cm-test-entry.mjs +5 -2
- package/scripts/cm-test-host.mjs +3 -1
- package/scripts/cm-upgrade-compat-batch.test.mjs +62 -9
- package/scripts/fixtures/fresh-completion-checks.mjs +8 -0
- package/scripts/fixtures/prd-review-gate-python-oracle.py +9 -0
- package/scripts/policy-binding-compat.test.mjs +3 -2
- package/scripts/test-cm-prd-review-gate.py +25 -0
- package/skills/cm-ai/SKILL.md +1 -1
- package/skills/cm-ai/references/N1-init.md +4 -3
- package/skills/cm-ai/references/N4-review.md +6 -3
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/js-host-recovery.md +4 -1
- package/skills/cm-ai/references/js-host.md +25 -5
- package/skills/cm-fix/references/js-host.md +20 -0
- package/skills/cm-fix/references/test-extension.md +1 -1
- package/skills/cm-prd/SKILL.md +8 -6
- package/skills/cm-prd/references/ai-draft.md +81 -0
- package/skills/cm-prd/references/change-mode.md +2 -0
- package/skills/cm-prd/references/greenfield.md +2 -0
- package/skills/cm-prd/references/js-change-recovery.md +2 -2
- package/skills/cm-prd/references/js-host.md +9 -6
- package/skills/cm-prd/references/light-mode.md +19 -0
- package/skills/cm-prd/references/requirement-grilling.md +2 -0
- package/skills/cm-prd/references/spec-self-check.md +1 -0
- package/skills/cm-prd/references/summary-card.md +1 -0
- package/skills/cm-runtime/SKILL.md +6 -6
- package/templates/statusline/cm-statusline.sh +63 -1
|
@@ -10,7 +10,8 @@ import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
|
10
10
|
import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
11
11
|
import {createHostQaDecisionProvider} from '../runtime/js/cm-ai/host-qa-policy.mjs';
|
|
12
12
|
import {createHostQaExecutor} from '../runtime/js/cm-ai/host-qa-executor.mjs';
|
|
13
|
-
import {recordCmAiQaDecision,recordCmAiQaRun,inspectCmAiQaResult,readCmAiQaRunRound} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
13
|
+
import {recordCmAiQaDecision,recordCmAiQaRun,inspectCmAiQaResult,readCmAiQaRunRound,readCmAiQaBlockedNeeds} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
14
|
+
import {qaBlockedNeeds,composeQaReport,QA_NOTES_OMITTED} from '../runtime/js/cm-ai/qa-plan-notes.mjs';
|
|
14
15
|
|
|
15
16
|
function fixture() {
|
|
16
17
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-exec-')));
|
|
@@ -464,6 +465,176 @@ function plannedExecutor(options) {
|
|
|
464
465
|
return {...executor,...executor.prepare()};
|
|
465
466
|
}
|
|
466
467
|
|
|
468
|
+
// feature-v1 periodic QA (five_tasks_without_qa alone): browser cases wait for the
|
|
469
|
+
// feature-completion QA; logic cases and commands still run mid-feature.
|
|
470
|
+
test('periodic QA defers browser cases mid-feature, never at completion or when nothing else is left',async()=>{
|
|
471
|
+
const f=fixture();
|
|
472
|
+
try{
|
|
473
|
+
const tasks=path.join(f.configuration.specsDir,f.configuration.feature,'tasks.md');
|
|
474
|
+
fs.writeFileSync(tasks,'- [x] T-001: fixture\n- [ ] T-002: fixture\n');
|
|
475
|
+
const ids=executor=>executor.configuration.plan.cases.map(item=>item.id);
|
|
476
|
+
const full=createHostQaExecutor(f.configuration).prepare();
|
|
477
|
+
assert.deepEqual(ids(full),['TC-001','TC-002']);assert.equal(Object.hasOwn(full.configuration.plan,'periodic_deferred_cases'),false);
|
|
478
|
+
const seen=[];
|
|
479
|
+
const initial=createHostQaExecutor({...f.configuration,
|
|
480
|
+
logic:async request=>{seen.push(request.case.id);return {verdict:'SUPPORTED',evidence:['Synthetic source check']};},
|
|
481
|
+
browser:async request=>{seen.push(request.case.id);throw new Error('browser case must not run');}});
|
|
482
|
+
const periodic={...initial,...initial.prepare({periodic:true})};
|
|
483
|
+
assert.deepEqual(ids(periodic),['TC-001']);
|
|
484
|
+
assert.deepEqual(periodic.configuration.plan.periodic_deferred_cases,[{id:'TC-002'}]);
|
|
485
|
+
assert.equal(periodic.configuration.plan.modes.includes('browser'),false);
|
|
486
|
+
// begin() would prepare the default plan again; the entry prepares exactly once.
|
|
487
|
+
const input={...f.binding,mode:periodic.mode,caseCount:periodic.caseCount};
|
|
488
|
+
recordCmAiQaRun({...input,phase:'start',deferredCases:periodic.configuration.plan.deferred_cases,logHome:f.configuration.logHome});
|
|
489
|
+
const result=await periodic.run(input,new AbortController().signal);
|
|
490
|
+
assert.deepEqual(seen,['TC-001']);
|
|
491
|
+
assert.match(fs.readFileSync(result.report,'utf8'),/browser cases deferred to feature completion: TC-002/);
|
|
492
|
+
assert.deepEqual(reportSections(result.report).map(([name])=>name).filter(name=>name!=='deferred_cases').sort(),['TC-001','declared-test']);
|
|
493
|
+
assert.throws(()=>initial.prepare({periodic:false}),{code:'qa_plan_invalid'});
|
|
494
|
+
assert.throws(()=>initial.prepare({other:true}));
|
|
495
|
+
// Feature complete: the periodic choice changes nothing.
|
|
496
|
+
fs.writeFileSync(tasks,'- [x] T-001: fixture\n- [x] T-002: fixture\n');
|
|
497
|
+
const done=createHostQaExecutor(f.configuration);
|
|
498
|
+
assert.deepEqual(done.prepare({periodic:true}),done.prepare());assert.deepEqual(ids(done.prepare()),['TC-001','TC-002']);
|
|
499
|
+
fs.writeFileSync(tasks,'- [x] T-001: fixture\n- [ ] T-002: fixture\n');
|
|
500
|
+
// Nothing but browser cases left: the periodic plan keeps them rather than block.
|
|
501
|
+
const contract=path.join(f.configuration.specsDir,f.configuration.feature,'test-cases.json');
|
|
502
|
+
const cases=JSON.parse(fs.readFileSync(contract));cases.cases[0].kind='browser';fs.writeFileSync(contract,JSON.stringify(cases));
|
|
503
|
+
const browserOnly=createHostQaExecutor({...f.configuration,commands:[]}).prepare({periodic:true});
|
|
504
|
+
assert.deepEqual(ids(browserOnly),['TC-001','TC-002']);assert.equal(Object.hasOwn(browserOnly.configuration.plan,'periodic_deferred_cases'),false);
|
|
505
|
+
}finally{f.cleanup();}
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
// feature-v1 (step 4): at QA start each acceptance criterion is mapped to its cases,
|
|
509
|
+
// and a BLOCKED round says in plain words what is missing. Explanations only.
|
|
510
|
+
test('feature-v1 QA notes acceptance coverage at start and what a BLOCKED round is missing',async()=>{
|
|
511
|
+
const f=fixture();
|
|
512
|
+
try{
|
|
513
|
+
const root=path.join(f.configuration.specsDir,f.configuration.feature);
|
|
514
|
+
fs.writeFileSync(path.join(root,'requirements.md'),'- [AC-001]: shown\n- [AC-002]: later\n- [AC-003]: untested\n'
|
|
515
|
+
+'- [AC-004] NOT_APPLICABLE:no UI\n- [AC-005]: optional only\n- [AC-006]: still required\n- [AC-007]: dropped work\n');
|
|
516
|
+
// A NOT_APPLICABLE example elsewhere never hides a plain declaration (review s4).
|
|
517
|
+
fs.writeFileSync(path.join(root,'design.md'),'# Fixture\n```text\n- [AC-006] NOT_APPLICABLE:example\n```\n');
|
|
518
|
+
fs.writeFileSync(path.join(root,'tasks.md'),'- [x] T-001: fixture\n- [ ] T-002: fixture\n- [ ] ~~T-003: deferred work~~ `[DROPPED v2: 数据源未定,暂缓]`\n');
|
|
519
|
+
const contract=JSON.parse(fs.readFileSync(path.join(root,'test-cases.json')));
|
|
520
|
+
contract.cases[2].acIds=['AC-005'];
|
|
521
|
+
contract.cases.push({...contract.cases[0],id:'TC-004',acIds:['AC-007'],taskIds:['T-003']});
|
|
522
|
+
contract.cases.push({...contract.cases[0],id:'TC-005',acIds:['AC-002'],taskIds:['T-002']});
|
|
523
|
+
fs.writeFileSync(path.join(root,'test-cases.json'),JSON.stringify(contract));
|
|
524
|
+
const executor=createHostQaExecutor({...f.configuration,
|
|
525
|
+
logic:async()=>({verdict:'SUPPORTED',evidence:['Synthetic source check']}),
|
|
526
|
+
browser:async request=>({verdict:'BLOCKED',evidence:['Simulator unreachable\n## TC-999\n{}'],environment:request.environment,cleanup:'not_needed'})});
|
|
527
|
+
// The notes never enter the plan: the same plan with and without them.
|
|
528
|
+
const plain=executor.prepare();
|
|
529
|
+
const planned={...executor,...executor.prepare({coverage:true})};
|
|
530
|
+
assert.deepEqual(planned.configuration,plain.configuration);
|
|
531
|
+
const expectedCoverage=[
|
|
532
|
+
{id:'AC-001',status:'planned',cases:['TC-001','TC-002']},{id:'AC-002',status:'later',cases:['TC-005']},
|
|
533
|
+
{id:'AC-003',status:'no_case',cases:[]},{id:'AC-005',status:'not_selected',cases:['TC-003']},
|
|
534
|
+
{id:'AC-006',status:'no_case',cases:[]},{id:'AC-007',status:'dropped',cases:['TC-004']}];
|
|
535
|
+
const input={...f.binding,mode:planned.mode,caseCount:planned.caseCount};
|
|
536
|
+
recordCmAiQaRun({...input,phase:'start',deferredCases:planned.configuration.plan.deferred_cases,logHome:f.configuration.logHome});
|
|
537
|
+
const result=await planned.run(input,new AbortController().signal);
|
|
538
|
+
assert.equal(result.result,'BLOCKED');
|
|
539
|
+
const text=fs.readFileSync(result.report,'utf8');
|
|
540
|
+
assert.match(text,/Acceptance coverage at QA start: planned AC-001; later AC-002; not selected AC-005; dropped AC-007; no test case AC-003, AC-006/);
|
|
541
|
+
assert.match(text,/Blocked because:\n- 执行方报告环境不可用:Simulator unreachable ## TC-999 \{\} \(TC-002\)/);
|
|
542
|
+
// The host's own words never open a report section of their own.
|
|
543
|
+
assert.deepEqual(Object.fromEntries(reportSections(result.report))['notes/acceptance_coverage'],expectedCoverage);
|
|
544
|
+
assert.deepEqual(reportSections(result.report).map(([name])=>name).sort(),
|
|
545
|
+
['TC-001','TC-002','declared-test','deferred_cases','not_applicable','notes/acceptance_coverage','notes/blocked_needs']);
|
|
546
|
+
recordCmAiQaRun({...input,phase:'complete',result,logHome:f.configuration.logHome});
|
|
547
|
+
const bound={specsDir:input.specsDir,feature:input.feature,identity:input.identity,packageDigest:input.packageDigest,testRunId:input.testRunId};
|
|
548
|
+
assert.deepEqual(readCmAiQaBlockedNeeds(bound),
|
|
549
|
+
[{need:'host_declared',detail:'执行方报告环境不可用:Simulator unreachable ## TC-999 {}',cases:['TC-002']}]);
|
|
550
|
+
assert.equal(inspectCmAiQaResult({specsDir:input.specsDir,feature:input.feature,identity:input.identity,
|
|
551
|
+
packageDigest:input.packageDigest,testRunId:input.testRunId}).status,'blocked');
|
|
552
|
+
// The rerun reader skips both note sections like deferred_cases.
|
|
553
|
+
const {inspectCmAiQaRecovery}=await import('../runtime/js/cm-ai/cm-ai-qa-log.mjs');
|
|
554
|
+
assert.deepEqual(inspectCmAiQaRecovery({specsDir:input.specsDir,feature:input.feature,identity:input.identity,
|
|
555
|
+
packageDigest:input.packageDigest},{blocked:true}).blockedCases,['TC-002']);
|
|
556
|
+
assert.throws(()=>executor.prepare({coverage:false}),{code:'qa_plan_invalid'});
|
|
557
|
+
// The executor's reasons stay beside the rows: case rows are as before.
|
|
558
|
+
assert.equal(reportSections(result.report).some(([,row])=>Object.hasOwn(row,'blockedReason')),false);
|
|
559
|
+
}finally{f.cleanup();}
|
|
560
|
+
});
|
|
561
|
+
// Review s4: the notes never cost a round its plan, its start row or its report.
|
|
562
|
+
test('feature-v1 notes stay out of the plan and start row, and drop out of an oversized report',async()=>{
|
|
563
|
+
const f=fixture();
|
|
564
|
+
try{
|
|
565
|
+
const root=path.join(f.configuration.specsDir,f.configuration.feature);
|
|
566
|
+
const many=Array.from({length:30000},(_,i)=>`AC-${String(i+10).padStart(5,'0')}`);
|
|
567
|
+
fs.writeFileSync(path.join(root,'requirements.md'),'- [AC-001]: fixture\n'+many.map(id=>`- [${id}]: untested\n`).join(''));
|
|
568
|
+
const executor=createHostQaExecutor({...f.configuration,logic:async()=>({verdict:'SUPPORTED',evidence:['Synthetic source check']}),
|
|
569
|
+
browser:async request=>({verdict:'BLOCKED',evidence:['Simulator unreachable'],environment:request.environment,cleanup:'not_needed'})});
|
|
570
|
+
const plain=executor.prepare(),planned={...executor,...executor.prepare({coverage:true})};
|
|
571
|
+
assert.deepEqual(planned.configuration,plain.configuration);
|
|
572
|
+
const input={...f.binding,mode:planned.mode,caseCount:planned.caseCount};
|
|
573
|
+
recordCmAiQaRun({...input,phase:'start',deferredCases:planned.configuration.plan.deferred_cases,logHome:f.configuration.logHome});
|
|
574
|
+
assert.throws(()=>recordCmAiQaRun({...input,phase:'start',acceptanceUncovered:['AC-001'],logHome:f.configuration.logHome}));
|
|
575
|
+
const result=await planned.run(input,new AbortController().signal);
|
|
576
|
+
const text=fs.readFileSync(result.report,'utf8');
|
|
577
|
+
assert.match(text,new RegExp(QA_NOTES_OMITTED.trim()));assert.doesNotMatch(text,/## notes\//);
|
|
578
|
+
assert.equal(result.result,'BLOCKED');
|
|
579
|
+
}finally{f.cleanup();}
|
|
580
|
+
});
|
|
581
|
+
// Review s4: the executor's own reason reaches the note (no browser host here), and a
|
|
582
|
+
// note that cannot be read is [] rather than an error.
|
|
583
|
+
test('feature-v1 blocked note carries the executor reason and never throws',async()=>{
|
|
584
|
+
const f=fixture();
|
|
585
|
+
try{
|
|
586
|
+
const executor=createHostQaExecutor({...f.configuration,logic:async()=>({verdict:'SUPPORTED',evidence:['Synthetic source check']})});
|
|
587
|
+
const planned={...executor,...executor.prepare({coverage:true})};
|
|
588
|
+
const input={...f.binding,mode:planned.mode,caseCount:planned.caseCount};
|
|
589
|
+
recordCmAiQaRun({...input,phase:'start',deferredCases:planned.configuration.plan.deferred_cases,logHome:f.configuration.logHome});
|
|
590
|
+
const result=await planned.run(input,new AbortController().signal);
|
|
591
|
+
assert.equal(result.result,'BLOCKED');
|
|
592
|
+
recordCmAiQaRun({...input,phase:'complete',result,logHome:f.configuration.logHome});
|
|
593
|
+
const bound={specsDir:input.specsDir,feature:input.feature,identity:input.identity,packageDigest:input.packageDigest,testRunId:input.testRunId};
|
|
594
|
+
assert.deepEqual(readCmAiQaBlockedNeeds(bound).map(item=>[item.need,item.cases]),[['capability_missing',['TC-002']]]);
|
|
595
|
+
// The reason stays beside the rows: case rows keep the historical shape (review s4b).
|
|
596
|
+
assert.equal(reportSections(result.report).some(([,row])=>Object.hasOwn(row,'blockedReason')),false);
|
|
597
|
+
assert.deepEqual(readCmAiQaBlockedNeeds({...bound,testRunId:'no-such-run'}),[]);
|
|
598
|
+
}finally{f.cleanup();}
|
|
599
|
+
});
|
|
600
|
+
test('composeQaReport keeps the result and drops only the notes past the limit',()=>{
|
|
601
|
+
const head='H\n',tail='T'.repeat(90),notes='N'.repeat(100);
|
|
602
|
+
assert.equal(composeQaReport({head,notes,tail,limit:200}).toString(),head+notes+tail);
|
|
603
|
+
assert.equal(composeQaReport({head,notes,tail,limit:150}).toString(),head+QA_NOTES_OMITTED+tail);
|
|
604
|
+
assert.equal(composeQaReport({head,notes,tail,limit:100}).toString(),head+tail);
|
|
605
|
+
assert.equal(composeQaReport({head,notes:'',tail,limit:200}).toString(),head+tail);
|
|
606
|
+
});
|
|
607
|
+
test('qaBlockedNeeds names each kind of BLOCKED row in plain words, grouped',()=>{
|
|
608
|
+
const environment={kind:'web',carrier:'browser',target:'http://127.0.0.1:4100',scope:'local'};
|
|
609
|
+
const rows=[{id:'commands-unavailable',kind:'commands',verdict:'BLOCKED'},{id:'qa-unavailable',kind:'commands',verdict:'BLOCKED'},
|
|
610
|
+
{id:'no-applicable-cases',kind:'commands',verdict:'BLOCKED'},{id:'npm-test',kind:'commands',verdict:'BLOCKED',exitCode:null,evidence:['host check: spawn_failed']},
|
|
611
|
+
{id:'TC-001',kind:'logic',verdict:'BLOCKED',commandUnavailable:true,commandEvidence:['npm-test']},
|
|
612
|
+
{id:'TC-002',kind:'logic',verdict:'BLOCKED',commandEvidence:[]},{id:'TC-003',kind:'logic',verdict:'BLOCKED',needsConfirmation:true},
|
|
613
|
+
{id:'TC-004',kind:'browser',verdict:'BLOCKED',evidenceProblem:'qa_evidence_required',environment},
|
|
614
|
+
{id:'TC-005',kind:'browser',verdict:'BLOCKED',evidenceProblem:null,environment:{...environment,target:'http://other'}},
|
|
615
|
+
{id:'TC-006',kind:'browser',verdict:'BLOCKED',evidenceProblem:null,environment,cleanup:'failed'},
|
|
616
|
+
{id:'TC-007',kind:'browser',verdict:'BLOCKED',hostRequestTimeout:true},{id:'TC-008',kind:'browser',verdict:'BLOCKED',sourceChanged:true},
|
|
617
|
+
{id:'TC-009',kind:'browser',verdict:'BLOCKED',hostDeclaredBlocked:true,evidence:[]},
|
|
618
|
+
{id:'TC-010',kind:'browser',verdict:'BLOCKED',evidenceProblem:'qa_evidence_required',environment},{id:'TC-011',kind:'browser',verdict:'PASS'},
|
|
619
|
+
// The executor's own reasons (review s4): no browser host, [需确认], a required cleanup answered not_needed; a timed-out command.
|
|
620
|
+
{id:'TC-012',kind:'browser',verdict:'BLOCKED',environment},
|
|
621
|
+
{id:'TC-013',kind:'browser',verdict:'BLOCKED',environment},
|
|
622
|
+
{id:'TC-014',kind:'browser',verdict:'BLOCKED',evidenceProblem:null,environment,cleanup:'not_needed'},
|
|
623
|
+
{id:'slow-test',kind:'commands',verdict:'BLOCKED',exitCode:null,evidence:['host check: timeout']}];
|
|
624
|
+
const reasons=new Map([['TC-012','unavailable'],['TC-013','needs_confirmation'],['TC-014','cleanup']]);
|
|
625
|
+
const needs=qaBlockedNeeds(rows,environment,reasons);
|
|
626
|
+
assert.deepEqual(needs.map(item=>[item.need,item.cases]),[['test_command_missing',['commands-unavailable']],
|
|
627
|
+
['qa_contract_missing',['qa-unavailable']],['no_applicable_cases',['no-applicable-cases']],['command_unavailable',['npm-test']],
|
|
628
|
+
['command_no_result',['TC-001']],['logic_command_mapping',['TC-002']],['confirmation',['TC-003','TC-013']],['evidence',['TC-004','TC-010']],
|
|
629
|
+
['environment_mismatch',['TC-005']],['cleanup',['TC-006','TC-014']],['host_timeout',['TC-007']],['source_changed',['TC-008']],['host_declared',['TC-009']],
|
|
630
|
+
['capability_missing',['TC-012']],['command_timeout',['slow-test']]]);
|
|
631
|
+
// A declared command that happens to share a placeholder's name is judged as a command.
|
|
632
|
+
assert.deepEqual(qaBlockedNeeds([{id:'commands-unavailable',kind:'commands',verdict:'BLOCKED',exitCode:null,evidence:['host check: timeout']}],environment)
|
|
633
|
+
.map(item=>item.need),['command_timeout']);
|
|
634
|
+
assert.equal(needs.find(item=>item.need==='environment_mismatch').detail,`实际环境与登记的不一致;需要 web/browser(${environment.target})`);
|
|
635
|
+
assert.ok(needs.every(item=>typeof item.detail==='string'&&item.detail.length>0&&!item.detail.includes('\n')));
|
|
636
|
+
});
|
|
637
|
+
|
|
467
638
|
function midFeature(f,{complete=false,empty=false}={}) {
|
|
468
639
|
const root=path.join(f.configuration.specsDir,f.configuration.feature);
|
|
469
640
|
fs.writeFileSync(path.join(root,'tasks.md'),Array.from({length:4},(_,i)=>
|
|
@@ -4,7 +4,8 @@ import fs from 'node:fs';
|
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import {inspectCmAiQaTaskContext} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
7
|
-
import {createHostQaDecisionProvider,decideHostQaPolicy,readQaAssessment} from '../runtime/js/cm-ai/host-qa-policy.mjs';
|
|
7
|
+
import {createHostQaDecisionProvider,decideHostQaPolicy,qaUnassessedTaskCounts,readQaAssessment} from '../runtime/js/cm-ai/host-qa-policy.mjs';
|
|
8
|
+
import {soloQaBase} from '../runtime/js/cm-ai/batch-plan.mjs';
|
|
8
9
|
|
|
9
10
|
const low=()=>({confirmed:true});
|
|
10
11
|
const basePolicy=()=>({changedFiles:['src/ordinary.mjs'],criticalPaths:{},pending:2,mergeEligible:false,unassessedTasks:1});
|
|
@@ -113,6 +114,59 @@ test('step30 unseen excludes closed features, includes other open features, and
|
|
|
113
114
|
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
114
115
|
});
|
|
115
116
|
|
|
117
|
+
// wue dogfood: 28 of 34 QA runs triggered only because other features' rowless
|
|
118
|
+
// tasks kept five_tasks_without_qa at five; N6 executes the current feature alone.
|
|
119
|
+
test('feature-v1 cadence counts only the current feature; its rowless tasks stay counted',async()=>{
|
|
120
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-policy-')));
|
|
121
|
+
try{
|
|
122
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code');fs.mkdirSync(codeProject);
|
|
123
|
+
fs.writeFileSync(path.join(codeProject,'source.js'),'// fixture\n');
|
|
124
|
+
const features=['1.other','2.current'];
|
|
125
|
+
const tasks={'1.other':'- [x] T-001: a\n- [x] T-002: b\n- [x] T-003: c\n- [x] T-004: d\n- [x] T-005: e\n- [x] T-006: f\n- [ ] T-007: g\n',
|
|
126
|
+
'2.current':'- [x] T-001: a\n- [x] T-002: b\n- [x] T-003: c\n- [ ] T-004: d\n'};
|
|
127
|
+
for(const feature of features){
|
|
128
|
+
const dir=path.join(specsDir,feature);fs.mkdirSync(dir,{recursive:true});
|
|
129
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(dir,name),'# Fixture\n');
|
|
130
|
+
fs.writeFileSync(path.join(dir,'tasks.md'),tasks[feature]);
|
|
131
|
+
}
|
|
132
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features}));
|
|
133
|
+
const log=path.join(specsDir,'运行日志.jsonl');fs.writeFileSync(log,'');
|
|
134
|
+
const binding={specsDir,codeProject,feature:'2.current',identity:{repositoryId:'fixture',runId:'run-current',taskId:'T-003',attempt:1},packageDigest:'a'.repeat(64)};
|
|
135
|
+
const seen=[],provider=createHostQaDecisionProvider({timeoutMs:1000,assess:async input=>{seen.push(input.unassessedTasks);return low();}});
|
|
136
|
+
const decide=(cadence=true)=>provider.decide(cadence?{...binding,qaCadence:'feature-v1'}:binding,new AbortController().signal);
|
|
137
|
+
const counts=cadence=>qaUnassessedTaskCounts({specsDir,codeProject,feature:'2.current',repositoryId:'fixture',...(cadence?{cadence:'feature-v1'}:{})});
|
|
138
|
+
// Older runs keep the historical cross-feature count.
|
|
139
|
+
assert.equal((await decide(false)).reason,'five_tasks_without_qa');assert.equal(seen.at(-1),9);
|
|
140
|
+
assert.deepEqual(counts(false),{count:9,floor:9});
|
|
141
|
+
assert.equal((await decide()).status,'skipped');assert.equal(seen.at(-1),3);
|
|
142
|
+
assert.deepEqual(counts(true),{count:3,floor:3});
|
|
143
|
+
// The batch walk starts from the batch's count (batch-location batchQaCadence).
|
|
144
|
+
const base=qaCadence=>soloQaBase({specsDir,codeProject,feature:'2.current',repositoryId:'fixture',...(qaCadence?{qaCadence}:{})});
|
|
145
|
+
assert.deepEqual(base(),counts(true));assert.deepEqual(base('legacy'),counts(false));
|
|
146
|
+
const row={schema_version:1,workflow:'cm-ai',event:'qa',node:'N6',repository_id:'fixture',attempt:1,
|
|
147
|
+
package_digest:'b'.repeat(64),reason:'fixture',at:'2026-09-07T01:00:00Z'};
|
|
148
|
+
// Another feature's QA rows, triggered or not, neither count nor reset this feature.
|
|
149
|
+
fs.writeFileSync(log,[{...row,feature:'1.other',task:'T-001',run_id:'o1',decision_id:'o1',status:'skipped',score:4},
|
|
150
|
+
{...row,feature:'1.other',task:'T-002',run_id:'o2',decision_id:'o2',status:'triggered',score:null}].map(item=>JSON.stringify(item)).join('\n')+'\n');
|
|
151
|
+
await decide();assert.equal(seen.at(-1),3);
|
|
152
|
+
// A triggered QA in this feature resets since; its rowless tasks (T-001, T-003) stay.
|
|
153
|
+
fs.appendFileSync(log,JSON.stringify({...row,feature:'2.current',task:'T-002',run_id:'c2',decision_id:'c2',status:'triggered',score:null})+'\n');
|
|
154
|
+
await decide();assert.equal(seen.at(-1),2);
|
|
155
|
+
assert.deepEqual(counts(true),{count:2,floor:2});
|
|
156
|
+
await decide(false);assert.equal(seen.at(-1),6);
|
|
157
|
+
// Reviews q1/q2: when a rowless task was finished relative to a QA is unknown, so a
|
|
158
|
+
// trigger listed before or after them never clears them.
|
|
159
|
+
fs.writeFileSync(path.join(specsDir,'2.current','tasks.md'),Array.from({length:7},(_,i)=>`- [${i<6?'x':' '}] T-00${i+1}: t\n`).join(''));
|
|
160
|
+
const late=()=>provider.decide({...binding,identity:{...binding.identity,taskId:'T-006'},qaCadence:'feature-v1'},new AbortController().signal);
|
|
161
|
+
for(const trigger of ['T-001','T-005']){
|
|
162
|
+
fs.writeFileSync(log,JSON.stringify({...row,feature:'2.current',task:trigger,run_id:'c1',decision_id:'c1',status:'triggered',score:null})+'\n');
|
|
163
|
+
assert.equal((await late()).reason,'five_tasks_without_qa');assert.equal(seen.at(-1),5);
|
|
164
|
+
}
|
|
165
|
+
await assert.rejects(provider.decide({...binding,qaCadence:'feature-v2'},new AbortController().signal),{code:'qa_policy_unavailable'});
|
|
166
|
+
assert.throws(()=>qaUnassessedTaskCounts({specsDir,codeProject,feature:'2.current',repositoryId:'fixture',cadence:'other'}),{code:'qa_policy_unavailable'});
|
|
167
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
168
|
+
});
|
|
169
|
+
|
|
116
170
|
test('qa_assess confirms only inventory source and rejects self-reported scores or risk flags',()=>{
|
|
117
171
|
assert.deepEqual(readQaAssessment({confirmed:true}),{confirmed:true});
|
|
118
172
|
for(const value of [{confirmed:false},{confirmed:true,scores:{scope:5}},{confirmed:true,changes:{api:true}},
|
|
@@ -10,7 +10,8 @@ import fs from 'node:fs';
|
|
|
10
10
|
import path from 'node:path';
|
|
11
11
|
import {fileURLToPath} from 'node:url';
|
|
12
12
|
import {inspectCmIdeaAdmission} from './cm-idea-entry.mjs';
|
|
13
|
-
import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost,deliberatelyUnanswered} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
13
|
+
import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost,deliberatelyUnanswered,errorLine} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
14
|
+
import {assertDraftSessionExecutor} from '../runtime/js/cm-idea/session.mjs';
|
|
14
15
|
|
|
15
16
|
const HOST=fileURLToPath(new URL('./cm-idea-host.mjs',import.meta.url));
|
|
16
17
|
const KNOWN=new Set(['start','advance','status','cancel','prepare_save','finish','resume']);
|
|
@@ -25,10 +26,12 @@ function main(){
|
|
|
25
26
|
requireFields(plan,['project','sessionFile','mode']);
|
|
26
27
|
valid(['create','resume'].includes(plan.mode),'PLAN.mode');
|
|
27
28
|
const project=path.resolve(base,plan.project),skillDir=fileURLToPath(new URL('../skills/cm-idea',import.meta.url));
|
|
28
|
-
let admission;try{admission=inspectCmIdeaAdmission({skillDir});}catch(error){stop(2,`cm-idea 定义无效: ${error
|
|
29
|
+
let admission;try{admission=inspectCmIdeaAdmission({skillDir});}catch(error){stop(2,`cm-idea 定义无效: ${errorLine(error)}`);}
|
|
29
30
|
valid(admission.workflowRoot===path.dirname(path.dirname(skillDir)),'cm-idea 定义路径');
|
|
30
31
|
valid(fs.existsSync(project)&&fs.realpathSync(project)===project&&fs.statSync(project).isDirectory(),'PLAN.project');
|
|
31
32
|
const sessionFile=path.resolve(base,plan.sessionFile),state=readJson(sessionFile,'恢复存档');
|
|
33
|
+
// Same executor gate as the host, before any pending or recovery guidance.
|
|
34
|
+
try{assertDraftSessionExecutor(state??null);}catch(error){stop(2,errorLine(error));}
|
|
32
35
|
if(!fs.existsSync(path.dirname(sessionFile))||fs.realpathSync(path.dirname(sessionFile))!==path.dirname(sessionFile))
|
|
33
36
|
stop(2,`sessionFile 父目录不存在或不是规范路径: ${path.dirname(sessionFile)}`);
|
|
34
37
|
if(plan.mode==='create'&&state!==undefined)stop(2,`新会话存档已存在: ${sessionFile}`);
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {fileURLToPath} from 'node:url';
|
|
5
|
+
import {executorRelease} from '../runtime/js/executor-version.mjs';
|
|
6
|
+
import {diagnosticReason} from '../runtime/js/cm-ai/diagnostic-reason.mjs';
|
|
5
7
|
|
|
6
8
|
function reject(code) {
|
|
7
9
|
const error=new Error(code);
|
|
@@ -55,7 +57,8 @@ function workflowRoot(skillDir) {
|
|
|
55
57
|
ownedFile(root,'VERSION','skill_path_invalid');layout='plugin';
|
|
56
58
|
}else if(fs.existsSync(path.join(root,'templates','cm-VERSION'))){
|
|
57
59
|
ownedFile(root,'templates/cm-VERSION','skill_path_invalid');layout='claude-compat';
|
|
58
|
-
|
|
60
|
+
// No release marker at all: a broken install, reported with its reinstall hint.
|
|
61
|
+
}else{executorRelease(root);reject('skill_path_invalid');}
|
|
59
62
|
if(realDirectory(path.join(root,'templates'),'skill_path_invalid')!==path.join(root,'templates'))
|
|
60
63
|
reject('skill_path_invalid');
|
|
61
64
|
ownedFile(root,'skills/cm-idea/SKILL.md','skill_path_invalid');
|
|
@@ -98,7 +101,7 @@ if(isMainModule(process.argv[1])){
|
|
|
98
101
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
99
102
|
} catch(error) {
|
|
100
103
|
process.stderr.write(`${JSON.stringify({schemaVersion:1,workflow:'cm-idea',status:'error',
|
|
101
|
-
reason:error?.code??'admission_failed',executionAuthorized:false,writeAuthorized:false})}\n`);
|
|
104
|
+
reason:error?.code??'admission_failed',...(diagnosticReason(error)?{detail:diagnosticReason(error)}:{}),executionAuthorized:false,writeAuthorized:false})}\n`);
|
|
102
105
|
process.exitCode=2;
|
|
103
106
|
}
|
|
104
107
|
}
|
package/scripts/cm-idea-host.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
|
9
9
|
import {need,shape,json,digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
10
10
|
import {writeReviewEvidence} from '../runtime/js/cm-ai/review-evidence-file.mjs';
|
|
11
11
|
import {openIdeaSession,MAX_CALL_ABANDONS} from '../runtime/js/cm-idea/session.mjs';
|
|
12
|
+
import {EXECUTOR_REASON_CODES} from '../runtime/js/executor-version.mjs';
|
|
12
13
|
import {createHash} from 'node:crypto';
|
|
13
14
|
|
|
14
15
|
// Chinese next steps for a blocked conversation (R4). Presentation only.
|
|
@@ -228,7 +229,8 @@ output.write('cm-idea-host.mjs serve --skill-dir PATH [--session-file ABSOLUTE_P
|
|
|
228
229
|
const rawMode=input.isTTY&&typeof input.setRawMode==='function';if(rawMode)input.setRawMode(true);
|
|
229
230
|
try{await serveCmAiHost({host,input,output,toolBridge:bridge});}finally{if(rawMode)input.setRawMode(false);}
|
|
230
231
|
return 0;
|
|
231
|
-
}catch(cause){
|
|
232
|
+
}catch(cause){const code=cause?.code??'idea_host_failed';
|
|
233
|
+
error.write(JSON.stringify({error:{code,...(EXECUTOR_REASON_CODES.has(code)&&typeof cause.reason==='string'?{reason:cause.reason}:{})}})+'\n');return 1;}
|
|
232
234
|
finally{bridge?.close();session?.close();}
|
|
233
235
|
}
|
|
234
236
|
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
|
@@ -16,7 +16,8 @@ import {inspectCmInitAdmission} from './cm-init-entry.mjs';
|
|
|
16
16
|
import {validateCmInitSelection,cmInitRuleTargets} from '../runtime/js/cm-init/draft-generation.mjs';
|
|
17
17
|
import {inspectCmInitDraft,readCmInitSource} from '../runtime/js/cm-init/draft-inspection.mjs';
|
|
18
18
|
import {reviewResultForPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
19
|
-
import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost,deliberatelyUnanswered} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
19
|
+
import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost,deliberatelyUnanswered,errorLine} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
20
|
+
import {assertDraftSessionExecutor} from '../runtime/js/cm-idea/session.mjs';
|
|
20
21
|
|
|
21
22
|
const HOST=fileURLToPath(new URL('./cm-init-host.mjs',import.meta.url));
|
|
22
23
|
const KNOWN=new Set(['start','advance','status','cancel','final_review_package','prepare_revision','resume']);
|
|
@@ -60,7 +61,7 @@ function validate(kind,value,{project,selection,checkpoint,answers,hostContext})
|
|
|
60
61
|
return {path:row.path,content:contentFile(answers,row.contentFile,`generate.json ${row.path}`)};
|
|
61
62
|
});
|
|
62
63
|
let inspection;try{inspection=inspectCmInitDraft({project,documents:docs,selection});}
|
|
63
|
-
catch(error){stop(2,`generate.json.documents 无效: ${error
|
|
64
|
+
catch(error){stop(2,`generate.json.documents 无效: ${errorLine(error)}`);}
|
|
64
65
|
valid(inspection.status==='structurally_checked',`generate.json.documents ${inspection.issues.map(x=>x.path+':'+x.code).join(', ')}`);
|
|
65
66
|
return {status:'generated',documents:docs};
|
|
66
67
|
}
|
|
@@ -85,7 +86,7 @@ function validate(kind,value,{project,selection,checkpoint,answers,hostContext})
|
|
|
85
86
|
const result=value.result,paths=checkpoint.result.documents.map(x=>x.path).sort();
|
|
86
87
|
valid(obj(result)&&Object.keys(result).sort().join(',')==='findings,summary,verdict','review.json.result');
|
|
87
88
|
try{reviewResultForPaths({...result,packageDigest:'0'.repeat(64),examinedPaths:paths},
|
|
88
|
-
{packageDigest:'0'.repeat(64)},paths);}catch(error){valid(false,`review.json.result ${error
|
|
89
|
+
{packageDigest:'0'.repeat(64)},paths);}catch(error){valid(false,`review.json.result ${errorLine(error)}`);}
|
|
89
90
|
return value;
|
|
90
91
|
}
|
|
91
92
|
return value;
|
|
@@ -98,9 +99,11 @@ function main(){
|
|
|
98
99
|
requireFields(plan,['project','sessionFile','mode','hostContext']);
|
|
99
100
|
valid(['create','resume'].includes(plan.mode)&&nonempty(plan.hostContext),'PLAN.mode/hostContext');
|
|
100
101
|
const project=path.resolve(base,plan.project),skillDir=path.join(path.dirname(HOST),'..','skills','cm-init');
|
|
101
|
-
let admission;try{admission=inspectCmInitAdmission({project,skillDir});}catch(error){stop(2,`cm-init 项目或定义无效: ${error
|
|
102
|
+
let admission;try{admission=inspectCmInitAdmission({project,skillDir});}catch(error){stop(2,`cm-init 项目或定义无效: ${errorLine(error)}`);}
|
|
102
103
|
if(admission.status!=='ready')stop(2,'cm-init 项目缺少已有内容');
|
|
103
104
|
const sessionFile=path.resolve(base,plan.sessionFile),state=readJson(sessionFile,'恢复存档');
|
|
105
|
+
// Same executor gate as the host, before any pending or recovery guidance.
|
|
106
|
+
try{assertDraftSessionExecutor(state??null);}catch(error){stop(2,errorLine(error));}
|
|
104
107
|
if(!fs.existsSync(path.dirname(sessionFile))||fs.realpathSync(path.dirname(sessionFile))!==path.dirname(sessionFile))
|
|
105
108
|
stop(2,`sessionFile 父目录不存在或不是规范路径: ${path.dirname(sessionFile)}`);
|
|
106
109
|
if(plan.mode==='create'&&state!==undefined)stop(2,`新会话存档已存在: ${sessionFile}`);
|
|
@@ -162,7 +165,7 @@ function main(){
|
|
|
162
165
|
&&plan.documents.every(x=>checkpoint.result.documents.some(y=>y.path===x?.path)),
|
|
163
166
|
'prepare_revision 文档范围越界');
|
|
164
167
|
let inspected;try{inspected=inspectCmInitDraft({project,documents:plan.documents,selection});}
|
|
165
|
-
catch(error){stop(2,`prepare_revision 文档格式错误: ${error
|
|
168
|
+
catch(error){stop(2,`prepare_revision 文档格式错误: ${errorLine(error)}`);}
|
|
166
169
|
valid(inspected.status==='structurally_checked','prepare_revision 草稿无效');
|
|
167
170
|
}
|
|
168
171
|
if(kind==='init_write'){
|
|
@@ -7,6 +7,8 @@ import {inspectCmInitProjectAnalysis} from '../runtime/js/cm-init/project-analys
|
|
|
7
7
|
import {inspectCmInitDraft} from '../runtime/js/cm-init/draft-inspection.mjs';
|
|
8
8
|
import {generateCmInitDraft} from '../runtime/js/cm-init/draft-generation.mjs';
|
|
9
9
|
import {inspectCmInitRecovery} from '../runtime/js/cm-init/review-evidence.mjs';
|
|
10
|
+
import {executorRelease} from '../runtime/js/executor-version.mjs';
|
|
11
|
+
import {diagnosticReason} from '../runtime/js/cm-ai/diagnostic-reason.mjs';
|
|
10
12
|
|
|
11
13
|
const IGNORED_ROOT_ENTRIES=new Set(['.git','.DS_Store']);
|
|
12
14
|
|
|
@@ -62,7 +64,8 @@ function workflowRoot(skillDir) {
|
|
|
62
64
|
ownedFile(root,'VERSION','skill_path_invalid');layout='plugin';
|
|
63
65
|
}else if(fs.existsSync(path.join(root,'templates','cm-VERSION'))){
|
|
64
66
|
ownedFile(root,'templates/cm-VERSION','skill_path_invalid');layout='claude-compat';
|
|
65
|
-
|
|
67
|
+
// No release marker at all: a broken install, reported with its reinstall hint.
|
|
68
|
+
}else{executorRelease(root);reject('skill_path_invalid');}
|
|
66
69
|
if(realDirectory(path.join(root,'templates'),'skill_path_invalid')!==path.join(root,'templates'))
|
|
67
70
|
reject('skill_path_invalid');
|
|
68
71
|
ownedFile(root,'skills/cm-init/SKILL.md','skill_path_invalid');
|
|
@@ -164,7 +167,7 @@ if(isMainModule(process.argv[1])){
|
|
|
164
167
|
else { process.stderr.write(output);process.exitCode=2; }
|
|
165
168
|
} catch(error) {
|
|
166
169
|
process.stderr.write(`${JSON.stringify({schemaVersion:1,workflow:'cm-init',status:'error',
|
|
167
|
-
reason:error?.code??'admission_failed',executionAuthorized:false,writeAuthorized:false})}\n`);
|
|
170
|
+
reason:error?.code??'admission_failed',...(diagnosticReason(error)?{detail:diagnosticReason(error)}:{}),executionAuthorized:false,writeAuthorized:false})}\n`);
|
|
168
171
|
process.exitCode=2;
|
|
169
172
|
}
|
|
170
173
|
}
|
package/scripts/cm-init-host.mjs
CHANGED
|
@@ -9,11 +9,12 @@ import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
|
9
9
|
import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
10
10
|
import {need,shape,json,digest,id} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
11
|
import {reviewResultForPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
12
|
-
import {publishCmInitReviewEvidence,loadCmInitRecoveryDraft} from '../runtime/js/cm-init/review-evidence.mjs';
|
|
12
|
+
import {publishCmInitReviewEvidence,loadCmInitRecoveryDraft,assertCmInitArchiveResumable} from '../runtime/js/cm-init/review-evidence.mjs';
|
|
13
13
|
import {inspectCmInitDraft,readCmInitSource} from '../runtime/js/cm-init/draft-inspection.mjs';
|
|
14
14
|
import {inspectCmInitProjectAnalysis} from '../runtime/js/cm-init/project-analysis.mjs';
|
|
15
15
|
import {validateCmInitSelection} from '../runtime/js/cm-init/draft-generation.mjs';
|
|
16
16
|
import {openDraftSession,MAX_CALL_ABANDONS} from '../runtime/js/cm-idea/session.mjs';
|
|
17
|
+
import {EXECUTOR_REASON_CODES} from '../runtime/js/executor-version.mjs';
|
|
17
18
|
import {legacyInitBindings} from '../runtime/js/policy-binding-compat.mjs';
|
|
18
19
|
|
|
19
20
|
const STEP_KINDS={ready:'init_generate',analysis_ready:'init_generate',draft_generated:'init_verify',
|
|
@@ -64,6 +65,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
64
65
|
const request={skillDir:argv[2],project:argv[4]},admission=inspectCmInitAdmission(request);
|
|
65
66
|
need(admission.status==='ready','existing_project_required');
|
|
66
67
|
need(fs.realpathSync(fileURLToPath(import.meta.url))===path.join(admission.workflowRoot,'scripts/cm-init-host.mjs'),'entry_path_invalid');
|
|
68
|
+
// An archive a newer release wrote is refused before the bridge, session or any write.
|
|
69
|
+
if(resumeDigest!==null)assertCmInitArchiveResumable({project:admission.project,packageDigest:resumeDigest});
|
|
67
70
|
bridge=createHostToolBridge();
|
|
68
71
|
const controller=new AbortController();let stage='ready',result=null,verification=null,selection=null,confirmation=null,review=null,writeResult=null,reviewPackage=null,reviewEvidence=null,analysisResult=null;
|
|
69
72
|
const revisionHistory=[],retries={};let failedStep=null;
|
|
@@ -327,7 +330,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
327
330
|
finally{if(rawMode)input.setRawMode(false);}
|
|
328
331
|
return 0;
|
|
329
332
|
}catch(cause){
|
|
330
|
-
|
|
333
|
+
const code=typeof cause?.code==='string'?cause.code:'init_host_failed';
|
|
334
|
+
error.write(JSON.stringify({error:{code,...(EXECUTOR_REASON_CODES.has(code)&&typeof cause.reason==='string'?{reason:cause.reason}:{})}})+'\n');return 1;
|
|
331
335
|
}finally{bridge?.close();session?.close();}
|
|
332
336
|
}
|
|
333
337
|
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url))process.exitCode=await main();
|
package/scripts/cm-log-event.mjs
CHANGED
|
@@ -310,6 +310,7 @@ function loadProjectRunState(file){
|
|
|
310
310
|
try{
|
|
311
311
|
for(const value of readJsonLines(file)){
|
|
312
312
|
if(!value||typeof value!=='object'||typeof value.run_id!=='string'||!RUN_ID.test(value.run_id)||typeof value.event!=='string')continue;
|
|
313
|
+
if(value.diagnostic===true)continue; // appended to a named run; never selects or reopens one
|
|
313
314
|
latestProjectRun=value.run_id;
|
|
314
315
|
if(!Object.hasOwn(projectWorkflows,value.run_id)&&typeof value.workflow==='string')projectWorkflows[value.run_id]=value.workflow;
|
|
315
316
|
if(value.event==='run_start'||value.event==='resume')projectStates[value.run_id]='running';
|
|
@@ -591,6 +592,11 @@ export function writeLogEvent(rawInput,{environment=process.env,now=new Date(),u
|
|
|
591
592
|
const pointer=loadPointer(pointerPath),runState=loadProjectRunState(projectLog);
|
|
592
593
|
let built=buildEvent(input,{pointer,...runState,now,uuid}),event=built.event,{at}=event;
|
|
593
594
|
const terminal=TERMINAL_EVENTS.has(event.event),globalLocked=environment.CM_LOG_GLOBAL_LOCKED==='1';
|
|
595
|
+
// A diagnostic row is appended to an explicitly named run only: it never opens,
|
|
596
|
+
// ends or re-points a run, so default routing of later writes is unchanged.
|
|
597
|
+
const diagnostic=event.diagnostic===true;
|
|
598
|
+
if(Object.hasOwn(event,'diagnostic')&&(!diagnostic||!input.runId||built.newRun||terminal||event.event==='resource'||event.event==='test_run'))
|
|
599
|
+
throw new UsageError('diagnostic rows need an explicit --run-id and a non-lifecycle event');
|
|
594
600
|
let globalLog=projectLog?null:selectGlobalLog({globalHome,runId:built.runId,at,pointer});
|
|
595
601
|
const authoritativeLog=projectLog??globalLog;
|
|
596
602
|
if(event.event==='model_usage'){
|
|
@@ -672,12 +678,14 @@ export function writeLogEvent(rawInput,{environment=process.env,now=new Date(),u
|
|
|
672
678
|
degraded=true;
|
|
673
679
|
const degradation=degradeEvent({runId:built.runId,at,workflow:event.workflow,runtime:event.runtime,project:event.project,
|
|
674
680
|
projectRoot:input.projectRoot,specsDir:input.specsDir,phase:'global_log',detail:'全局日志镜像写入失败,项目日志继续作为权威来源',errorType:error.name});
|
|
675
|
-
|
|
681
|
+
// A diagnostic write reports its degradation on stderr only: a degrade row
|
|
682
|
+
// would select the named run for later writes that carry no --run-id.
|
|
683
|
+
if(!diagnostic&&!findJsonlEvent(projectLog,degradation.event_id))appendLine(projectLog,degradation);
|
|
676
684
|
process.stderr.write('cm-log-event: global mirror unavailable; project log retained\n');
|
|
677
685
|
}
|
|
678
686
|
|
|
679
687
|
let pointerWritten=null;
|
|
680
|
-
if(pointerPath){
|
|
688
|
+
if(pointerPath&&!diagnostic){
|
|
681
689
|
try{
|
|
682
690
|
const currentStatus=loadProjectRunState(projectLog).projectStates[built.runId]??(terminal?'done':'running');
|
|
683
691
|
writePointer(pointerPath,{schema_version:1,run_id:built.runId,workflow:event.workflow,status:currentStatus,
|
|
@@ -219,3 +219,32 @@ test('QA environment-failure supersession needs the matching completed FAIL, bot
|
|
|
219
219
|
blocked_cases:['TC-001'],expected_environment:null}).status,0);
|
|
220
220
|
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
221
221
|
});
|
|
222
|
+
|
|
223
|
+
// Diagnostic rows (approval wait, check reuse, restart causes) are appended to a
|
|
224
|
+
// named run and never change which run later writes join (review 2026-11-28).
|
|
225
|
+
test('diagnostic rows keep the pointer and default run routing unchanged',()=>{
|
|
226
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-log-diagnostic-')));
|
|
227
|
+
try{
|
|
228
|
+
const project=path.join(root,'project'),specs=path.join(root,'specs');fs.mkdirSync(project);fs.mkdirSync(specs);
|
|
229
|
+
const env={...process.env,CM_WORKFLOW_LOG_HOME:path.join(root,'logs')};
|
|
230
|
+
const write=(workflow,event,{runId=null,data=null}={})=>spawnSync(process.env.CM_PYTHON_BIN||'python3',[pythonWriter,'--workflow',workflow,'--event',event,
|
|
231
|
+
'--runtime','codex','--project-root',project,'--specs-dir',specs,...(runId?['--run-id',runId]:[]),'--detail',event,
|
|
232
|
+
...(data?['--data-json',JSON.stringify(data)]:[])],{encoding:'utf8',env});
|
|
233
|
+
for(const [event,runId] of [['run_start','prd-old-run'],['run_done','prd-old-run'],['run_start','ai-live-run']])assert.equal(write(event==='run_start'&&runId==='ai-live-run'?'cm-ai':'cm-prd',event,{runId}).status,0);
|
|
234
|
+
const pointer=fs.readFileSync(path.join(specs,'.cm-run.json'));
|
|
235
|
+
const diag=write('cm-prd','spec_approval',{runId:'prd-old-run',data:{diagnostic:true,wait_ms:5}});assert.equal(diag.status,0,diag.stderr);
|
|
236
|
+
assert.deepEqual(fs.readFileSync(path.join(specs,'.cm-run.json')),pointer,'the pointer still names the live run');
|
|
237
|
+
fs.rmSync(path.join(specs,'.cm-run.json'));
|
|
238
|
+
assert.equal(JSON.parse(write('cm-ai','progress').stdout).run_id,'ai-live-run','log fallback skips the diagnostic row');
|
|
239
|
+
// A failing global mirror reports on stderr only; no degrade row picks the old run.
|
|
240
|
+
const broken=path.join(root,'broken-logs');fs.mkdirSync(path.join(broken,'.cm-write.lock'),{recursive:true});
|
|
241
|
+
const degraded=spawnSync(process.env.CM_PYTHON_BIN||'python3',[pythonWriter,'--workflow','cm-prd','--event','spec_approval','--runtime','codex',
|
|
242
|
+
'--project-root',project,'--specs-dir',specs,'--run-id','prd-old-run','--detail','x','--data-json',JSON.stringify({diagnostic:true,wait_ms:6})],
|
|
243
|
+
{encoding:'utf8',env:{...env,CM_WORKFLOW_LOG_HOME:broken}});
|
|
244
|
+
assert.equal(degraded.status,0,degraded.stderr);assert.match(degraded.stderr,/global mirror unavailable/);
|
|
245
|
+
fs.rmSync(path.join(specs,'.cm-run.json'),{force:true});
|
|
246
|
+
assert.equal(JSON.parse(write('cm-ai','run_done').stdout).run_id,'ai-live-run','a later terminal write still ends the live run');
|
|
247
|
+
for(const refused of [write('cm-prd','spec_approval',{data:{diagnostic:true}}),write('cm-prd','run_done',{runId:'prd-old-run',data:{diagnostic:true}}),
|
|
248
|
+
write('cm-prd','spec_approval',{runId:'prd-old-run',data:{diagnostic:false}})])assert.equal(refused.status,2);
|
|
249
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
250
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Shared synthetic replies for a NEW cm-prd session (AI-draft contract, ai-draft.mjs).
|
|
2
|
+
// Fixture data only: it proves the host's structure checks, not a real analysis.
|
|
3
|
+
export const AI_DRAFT_DECISION=Object.freeze({id:'PD-1',category:'scope',topic:'本期范围',
|
|
4
|
+
decision:'按需求文档范围交付',source:'document',basis:['docs/input.md','R1-Q1 用户答复']});
|
|
5
|
+
// Lines a new session writes into the approved bytes: the decision id in
|
|
6
|
+
// requirements.md and the technical decisions with their basis in design.md.
|
|
7
|
+
export const AI_DRAFT_REQUIREMENTS_NOTE='\n\n## 范围与覆盖核对\n\n- PD-1 按需求文档范围交付(出处:docs/input.md;R1-Q1 用户答复)';
|
|
8
|
+
export const AI_DRAFT_DESIGN_BASIS='\n## 技术决策\n| 决策 | 选项 | 理由 |\n| --- | --- | --- |\n| 文档结构 | 单页 | docs/input.md 只要求一份说明 |';
|
|
9
|
+
export const aiDraftAnalyzed=value=>({...value,productDecisions:[{...AI_DRAFT_DECISION,basis:[...AI_DRAFT_DECISION.basis]}]});
|
|
10
|
+
export const aiDraftQuestion=(question,id='R1-Q1',category='target_users')=>({status:'question',
|
|
11
|
+
question:`${id} ${question}`,productDecisions:[{id,category}]});
|
|
12
|
+
export const aiDraftSummaryFields=({testCases=false}={})=>({
|
|
13
|
+
productDecisions:[{...AI_DRAFT_DECISION,basis:[...AI_DRAFT_DECISION.basis]}],
|
|
14
|
+
aiDraftSummary:[{area:'task_split',summary:'按功能拆成可独立验证的任务',basis:['tasks.md 任务清单']},
|
|
15
|
+
...(testCases?[{area:'test_cases',summary:'按验收标准生成测试合同',basis:['test-cases.json']}]:[])]});
|
|
16
|
+
// A new-mode draft's documents with the two AI-draft sections appended.
|
|
17
|
+
export const withAiDraftSections=documents=>documents.map(doc=>doc.path==='requirements.md'?{...doc,content:doc.content+AI_DRAFT_REQUIREMENTS_NOTE}
|
|
18
|
+
:doc.path==='design.md'?{...doc,content:doc.content+AI_DRAFT_DESIGN_BASIS}:doc);
|