@aibyzero/cm-workflow 0.16.4 → 0.16.5
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/AGENTS.md +8 -0
- package/CHANGELOG.md +50 -0
- package/README.md +12 -1
- package/VERSION +1 -1
- package/docs/installation.md +21 -1
- package/docs/js-workflow-control.md +245 -33
- package/docs/runtime-failover.md +1 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +115 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +137 -22
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +180 -53
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +305 -0
- package/runtime/js/cm-ai/drive-core.mjs +39 -7
- package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
- package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +12 -4
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +13 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +427 -31
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +502 -65
- package/runtime/js/cm-fix/execution.mjs +109 -25
- package/runtime/js/cm-fix/host-review.mjs +7 -3
- package/runtime/js/cm-fix/host.mjs +3 -1
- package/runtime/js/cm-fix/progress.mjs +1 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/summary.mjs +3 -1
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +10 -3
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +18 -11
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +92 -20
- package/scripts/cm-ai-batch-drive.test.mjs +164 -3
- package/scripts/cm-ai-batch-host.mjs +27 -11
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- package/scripts/cm-ai-batch-run.mjs +33 -10
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +158 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap.test.mjs +99 -7
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +479 -47
- package/scripts/cm-ai-drive.test.mjs +240 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +84 -25
- package/scripts/cm-ai-host.test.mjs +232 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +166 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +917 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +160 -60
- package/scripts/cm-ai-run.test.mjs +4 -3
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.test.mjs +1 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-probe.test.mjs +9 -1
- package/scripts/cm-claude-review-stream.test.mjs +25 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +45 -13
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-host.mjs +9 -6
- package/scripts/cm-fix-review-budget.test.mjs +141 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +192 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-log-event.mjs +17 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-prd-completion.test.mjs +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +9 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +12 -1
- package/scripts/cm-task-gate.mjs +18 -10
- package/scripts/cm-task-gate.py +1 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/process-cleanup.mjs +99 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-npm-install.py +1 -1
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/js-host.md +261 -42
- package/skills/cm-fix/references/js-host.md +22 -1
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
// Journal data grammar. Only the trusted serial host supplies original owner evidence.
|
|
2
2
|
import {digest,hex,id,json,need,shape,validIdentity} from './effect-contract.mjs';
|
|
3
3
|
import {qaFixIdentity} from '../cm-fix/qa-source.mjs';
|
|
4
|
-
import {composeFixCode} from './fix-code-association.mjs';
|
|
4
|
+
import {associationRecord,composeFixCode,readSteps} from './fix-code-association.mjs';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// resolveSteps: steps -> resolved steps from the named runs' verified stores, or
|
|
7
|
+
// null when a store is absent. Pure journal replay has no stores: a version 2
|
|
8
|
+
// record is then checked for shape and chain only, and the runner re-proves its
|
|
9
|
+
// composition against the stores (and every live use refuses what it cannot).
|
|
10
|
+
export function validateAcceptedFix({record,previous,baseline,parentPackage,feature,resolveSteps=null}){
|
|
7
11
|
shape(record,['evidence','association','qaRound']);
|
|
8
12
|
const {evidence:e,association:a,qaRound}=record;
|
|
9
13
|
shape(e,['version','kind','identity','qaSource','checkpointRevision','reviewPackage','reviewRegistrationDigest',
|
|
@@ -21,8 +25,22 @@ export function validateAcceptedFix({record,previous,baseline,parentPackage,feat
|
|
|
21
25
|
}
|
|
22
26
|
need(qaRound===previous.length+1&&qaRound<=2,'fix_chain_invalid');
|
|
23
27
|
need(!previous.some(item=>item.evidence.qaSource.testRunId===e.qaSource.testRunId),'fix_chain_invalid');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
// Version 1: strict chain. Version 2 keeps the previous record's interleaved
|
|
29
|
+
// deliveries as an exact prefix and may add only steps preceding this fix.
|
|
30
|
+
const steps=a?.version===2?a.laterDeliveries:[],prior=previous.at(-1)?.association.laterDeliveries??[];
|
|
31
|
+
need(Array.isArray(steps)&&(a?.version!==2||steps.length>0)&&steps.length>=prior.length
|
|
32
|
+
&&digest(steps.slice(0,prior.length))===digest(prior)
|
|
33
|
+
&&steps.slice(prior.length).every(step=>step?.beforeFix===previous.length),'fix_association_invalid');
|
|
34
|
+
const fixPackages=[...previous.map(item=>item.evidence.reviewPackage),e.reviewPackage];
|
|
35
|
+
readSteps(steps,fixPackages.length);
|
|
36
|
+
const resolved=steps.length?(typeof resolveSteps==='function'?resolveSteps(steps):null):[];
|
|
37
|
+
if(resolved){
|
|
38
|
+
const composed=composeFixCode({baseline,parentPackage,fixPackages,steps:resolved});
|
|
39
|
+
need(digest(a)===digest(associationRecord({...composed,steps})),'fix_association_invalid');
|
|
40
|
+
}else{
|
|
41
|
+
shape(a,['version','kind','parentPackageDigest','fixPackageDigest','currentFilesDigest','laterDeliveries']);
|
|
42
|
+
need(a.kind==='cm-fix-code-association'&&a.parentPackageDigest===parentPackage.packageDigest
|
|
43
|
+
&&a.fixPackageDigest===e.reviewPackage.packageDigest,'fix_association_invalid');hex(a.currentFilesDigest);
|
|
44
|
+
}
|
|
27
45
|
return json(record,12*1024*1024);
|
|
28
46
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {readSpecsStatus} from '../specs-status.mjs';
|
|
2
|
+
|
|
3
|
+
// One feature-name decision. A specs path reads its approved manifest;
|
|
4
|
+
// data-only replay callers pass their already-bound feature list.
|
|
5
|
+
export function identifyApprovedBootstrapFeature(source){
|
|
6
|
+
const status=typeof source==='string'?readSpecsStatus(source):null;
|
|
7
|
+
if(status&&!(status.kind==='valid'&&status.value.status==='approved'))
|
|
8
|
+
throw Object.assign(new Error('bootstrap_approval_required'),{code:'bootstrap_approval_required'});
|
|
9
|
+
const features=status?status.value.features:source;
|
|
10
|
+
if(!Array.isArray(features)||!features.every(name=>typeof name==='string'))
|
|
11
|
+
throw Object.assign(new Error('bootstrap_approval_required'),{code:'bootstrap_approval_required'});
|
|
12
|
+
const candidates=features.filter(name=>/^\d+\.bootstrap$/.test(name));
|
|
13
|
+
if(candidates.length>1)throw Object.assign(new Error('bootstrap_feature_ambiguous'),{code:'bootstrap_feature_ambiguous'});
|
|
14
|
+
return candidates[0]??null;
|
|
15
|
+
}
|
|
@@ -15,6 +15,11 @@ export function reportClaudeDevIntentNotice(onNotice) {
|
|
|
15
15
|
try { onNotice({kind:'claude_system_notice', subtype:'dev_intent'}); } catch {}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
// Error classes observed from Claude CLI 2.1.274; anything else is reviewer_api_error.
|
|
19
|
+
const API_ERROR_CLASSES = Object.freeze({authentication_failed:'reviewer_auth_failed',
|
|
20
|
+
billing_error:'reviewer_billing_error', rate_limit:'reviewer_rate_limited',
|
|
21
|
+
server_error:'reviewer_server_error', model_not_found:'reviewer_model_not_found'});
|
|
22
|
+
|
|
18
23
|
export function createClaudeReviewStream(onEvent, onNotice = null) {
|
|
19
24
|
let session = null, stage = 'init', value, noticeCount = 0, thinkingCount = 0, rejectedAttempts = 0;
|
|
20
25
|
const pendingTools = new Map(), toolIds = new Set();
|
|
@@ -73,6 +78,13 @@ export function createClaudeReviewStream(onEvent, onNotice = null) {
|
|
|
73
78
|
return;
|
|
74
79
|
}
|
|
75
80
|
if (message.type === 'assistant') {
|
|
81
|
+
// CLI 2.1.x reports an API failure as a synthetic assistant message with
|
|
82
|
+
// a string error class, then an is_error result. Before any tool call it
|
|
83
|
+
// carries no verdict: stop with the class so the user knows what to fix.
|
|
84
|
+
if (typeof message.error === 'string' && message.parent_tool_use_id === null
|
|
85
|
+
&& message.message?.role === 'assistant' && toolIds.size === 0) {
|
|
86
|
+
reject(Object.hasOwn(API_ERROR_CLASSES, message.error) ? API_ERROR_CLASSES[message.error] : 'reviewer_api_error');
|
|
87
|
+
}
|
|
76
88
|
if (message.parent_tool_use_id !== null || message.error != null
|
|
77
89
|
|| message.message?.role !== 'assistant') reject('unexpected_assistant');
|
|
78
90
|
const content = message.message.content;
|
|
@@ -5,27 +5,27 @@ import { createHash } from 'node:crypto';
|
|
|
5
5
|
import { spawnSync } from 'node:child_process';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import {readSpecsStatus,writeSpecsStatus} from '../specs-status.mjs';
|
|
8
|
-
import {
|
|
8
|
+
import {identifyApprovedBootstrapFeature} from './bootstrap-feature.mjs';
|
|
9
|
+
import {buildManifest,verifyApprovedManifest} from '../../../scripts/cm-spec-manifest.mjs';
|
|
10
|
+
import {outstandingFeatureQa,describeOutstandingQa} from './project-qa-gate.mjs';
|
|
11
|
+
import {taskLines,taskDeclarations,approvedTaskGrammar,TASK_GRAMMAR,LEGACY_TASK_GRAMMAR} from '../spec-task-line.mjs';
|
|
12
|
+
export {identifyApprovedBootstrapFeature} from './bootstrap-feature.mjs';
|
|
9
13
|
|
|
10
|
-
const
|
|
11
|
-
const DEPENDENCY=/^\s*-\s*(T-[A-Za-z0-9][A-Za-z0-9._-]*)\s+依赖\s+(.+)$/;
|
|
14
|
+
export const DEPENDENCY=/^\s*-\s*(T-[A-Za-z0-9][A-Za-z0-9._-]*)\s+依赖\s+(.+)$/;
|
|
12
15
|
const TASK_ID=/^T-[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
13
16
|
const ACCEPTANCE=/^\s*[-*]\s+(?:\[[ xX]\]\s+)?(?:\[(AC-\d{3,})\]|(AC-\d{3,}))(?=[:\s])/;
|
|
14
17
|
const FEATURE=/^(\d+)\.(.+)$/;
|
|
15
18
|
const TEST_CASE_VALIDATOR=fileURLToPath(new URL('../../../scripts/validate-test-cases.mjs',import.meta.url));
|
|
16
19
|
|
|
17
|
-
export function parseCmAiTaskLine(line){
|
|
18
|
-
const match=line.match(TASK);
|
|
19
|
-
return match?{id:match[2],completed:match[1].toLowerCase()==='x'}:null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
20
|
// Greenfield's T-001 scaffolds; its subsequent instruction task (normally
|
|
23
21
|
// T-002) owns init-equivalent rules. Use the existing parser and approval gate.
|
|
24
22
|
export function inspectCmAiBootstrapTask({specsDir,codeProject,taskId},inProgress=false) {
|
|
25
23
|
const admission=admissionFor({specsDir,codeProject},inProgress?taskId:null);
|
|
26
24
|
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
27
25
|
if(!['ready','complete'].includes(admission.state))fail(admission.reason);
|
|
28
|
-
const
|
|
26
|
+
const feature=identifyApprovedBootstrapFeature(readSpecsStatus(admission.specsDir).value.features);
|
|
27
|
+
if(feature===null)fail('bootstrap_task_required');
|
|
28
|
+
const parsed=readFeature(admission.specsDir,feature);if(parsed.error)fail(parsed.error);
|
|
29
29
|
const task=parsed.tasks.find(item=>item.id===taskId&&!item.dropped);
|
|
30
30
|
const mode=task?.id==='T-001'&&/(?:脚手架|骨架|scaffold)/i.test(task.description)?'scaffold':'instructions';
|
|
31
31
|
if(!task||mode==='instructions'&&(!/(?:cm-init|\.claude\/|AGENTS\.md)/i.test(task.description)
|
|
@@ -87,7 +87,9 @@ function directory(value){
|
|
|
87
87
|
function approvalIntent(response,assumeYes){
|
|
88
88
|
if(assumeYes===true)return 'explicit';
|
|
89
89
|
if(response===undefined||response===null||response==='')return 'none';
|
|
90
|
-
|
|
90
|
+
if(typeof response!=='string')return 'not_approval';
|
|
91
|
+
const normalized=response.trim().replace(/[。!!.~~\s]+$/gu,'');
|
|
92
|
+
return new Set(['开始','开始吧','可以开始','确认开始','开始执行','现在开始']).has(normalized)?'explicit':'not_approval';
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
|
|
@@ -102,12 +104,13 @@ function discoverFeatures(specsDir){
|
|
|
102
104
|
.filter(entry=>entry.isDirectory()&&FEATURE.test(entry.name))
|
|
103
105
|
.map(entry=>entry.name)
|
|
104
106
|
.sort((a,b)=>{
|
|
105
|
-
if(a
|
|
106
|
-
if(b
|
|
107
|
+
if(/^\d+\.bootstrap$/.test(a))return /^\d+\.bootstrap$/.test(b)?0:-1;
|
|
108
|
+
if(/^\d+\.bootstrap$/.test(b))return 1;
|
|
107
109
|
const an=Number(a.match(FEATURE)[1]),bn=Number(b.match(FEATURE)[1]);
|
|
108
110
|
return an-bn||(a<b?-1:a>b?1:0);
|
|
109
111
|
});
|
|
110
112
|
if(!names.length)return {error:'features_missing'};
|
|
113
|
+
try{identifyApprovedBootstrapFeature(names);}catch(error){return {error:error.code};}
|
|
111
114
|
const reviewKeys=names.flatMap(name=>[name,name.replace(/^\d+\./,'')]);
|
|
112
115
|
if(new Set(reviewKeys).size!==reviewKeys.length)return {error:'feature_contract_invalid'};
|
|
113
116
|
for(const name of names){
|
|
@@ -151,7 +154,7 @@ function validTestContract(target,featureName){
|
|
|
151
154
|
try{sources=['requirements.md','design.md','tasks.md'].map(file=>fs.readFileSync(path.join(featureRoot,file),'utf8'));}
|
|
152
155
|
catch{return false;}
|
|
153
156
|
const acIds=new Set(sources.flatMap(source=>source.split(/\r?\n/).map(line=>line.match(ACCEPTANCE)).filter(Boolean).map(match=>match[1]||match[2])));
|
|
154
|
-
const taskIds=new Set(sources[2]
|
|
157
|
+
const taskIds=new Set(taskDeclarations(sources[2],{grammar:approvedTaskGrammar(path.dirname(featureRoot))}).map(task=>task.id));
|
|
155
158
|
return data.cases.every(item=>item.acIds.every(id=>acIds.has(id))&&item.taskIds.every(id=>taskIds.has(id)));
|
|
156
159
|
}
|
|
157
160
|
|
|
@@ -197,7 +200,8 @@ function validateTestCases(specsDir,status,names){
|
|
|
197
200
|
}
|
|
198
201
|
|
|
199
202
|
function readFeature(specsDir,name){
|
|
200
|
-
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8'),
|
|
203
|
+
const parsed=parseFeatureTaskText(fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8'),
|
|
204
|
+
{allowDependencyPunctuation:true,grammar:approvedTaskGrammar(specsDir)});
|
|
201
205
|
if(parsed.error)parsed.detail={feature:name,...parsed.detail};
|
|
202
206
|
return parsed;
|
|
203
207
|
}
|
|
@@ -206,24 +210,26 @@ export function declaredAcceptanceIds(source){
|
|
|
206
210
|
return new Set(source.split(/\r?\n/).map(line=>line.match(ACCEPTANCE)).filter(Boolean).map(match=>match[1]||match[2]));
|
|
207
211
|
}
|
|
208
212
|
|
|
209
|
-
|
|
210
|
-
|
|
213
|
+
// Shared declaration grammar (spec-task-line.mjs), versioned by the approval.
|
|
214
|
+
export function parseFeatureTaskText(source,{allowDependencyPunctuation=false,grammar=TASK_GRAMMAR}={}){
|
|
215
|
+
const lines=taskLines(source,{grammar});
|
|
211
216
|
const tasks=[];
|
|
212
217
|
const taskIds=new Set();
|
|
213
218
|
const dependencies=new Map();
|
|
214
219
|
const dependencyLocations=new Map();
|
|
215
|
-
const location=index=>({line:index+1,text:lines[index].slice(0,120)});
|
|
220
|
+
const location=index=>({line:index+1,text:lines[index].body.slice(0,120)});
|
|
216
221
|
const invalid=(error,index)=>({error,detail:location(index)});
|
|
217
|
-
for(const
|
|
218
|
-
|
|
222
|
+
for(const {index,body:line,fenced,declaration:task} of lines){
|
|
223
|
+
if(fenced)continue;
|
|
219
224
|
if(task){
|
|
220
|
-
if(taskIds.has(task
|
|
221
|
-
taskIds.add(task
|
|
222
|
-
const
|
|
225
|
+
if(taskIds.has(task.id))return invalid('tasks_invalid',index);
|
|
226
|
+
taskIds.add(task.id);
|
|
227
|
+
const rest=task.description;
|
|
228
|
+
const dropped=/\[DROPPED(?:\s[^\]]*)?\]/.test(rest);
|
|
223
229
|
tasks.push({
|
|
224
|
-
id:task
|
|
225
|
-
description:
|
|
226
|
-
completed:task
|
|
230
|
+
id:task.id,
|
|
231
|
+
description:rest.replace(/~~\s*\[DROPPED(?:\s[^\]]*)?\].*$/,'').trim(),
|
|
232
|
+
completed:task.completed,
|
|
227
233
|
dropped,
|
|
228
234
|
});
|
|
229
235
|
continue;
|
|
@@ -239,7 +245,7 @@ export function parseFeatureTaskText(source,{allowDependencyPunctuation=false}={
|
|
|
239
245
|
dependencyLocations.set(dependency[1],location(index));
|
|
240
246
|
}
|
|
241
247
|
}
|
|
242
|
-
if(!tasks.length)return invalid('tasks_invalid',Math.max(0,lines.findIndex(line=>line.trim())));
|
|
248
|
+
if(!tasks.length)return invalid('tasks_invalid',Math.max(0,lines.findIndex(line=>line.body.trim())));
|
|
243
249
|
return {tasks,dependencies,dependencyLocations};
|
|
244
250
|
}
|
|
245
251
|
|
|
@@ -267,10 +273,10 @@ function invalidDependency(tasks,dependencies){
|
|
|
267
273
|
|
|
268
274
|
function validateBootstrap(codeProject,specsDir,names){
|
|
269
275
|
const empty=fs.readdirSync(codeProject).length===0;
|
|
270
|
-
const
|
|
271
|
-
if(empty&&!
|
|
272
|
-
if(!empty&&
|
|
273
|
-
const parsed=readFeature(specsDir,
|
|
276
|
+
const bootstrap=identifyApprovedBootstrapFeature(names);
|
|
277
|
+
if(empty&&!bootstrap)return 'bootstrap_required';
|
|
278
|
+
if(!empty&&bootstrap){
|
|
279
|
+
const parsed=readFeature(specsDir,bootstrap);
|
|
274
280
|
if(parsed.error)return null; // Let selection retain the parser's location and feature summaries.
|
|
275
281
|
const bootstrapTask=parsed.tasks.find(task=>task.id==='T-001');
|
|
276
282
|
if(bootstrapTask&&!bootstrapTask.completed&&!bootstrapTask.dropped)return 'bootstrap_conflict';
|
|
@@ -298,6 +304,13 @@ function missingReviewIds(featureName,tasks,evidenceNames){
|
|
|
298
304
|
});
|
|
299
305
|
}
|
|
300
306
|
|
|
307
|
+
function dependenciesSatisfied(task,parsed,byId){
|
|
308
|
+
return (parsed.dependencies.get(task.id)||[]).every(id=>{
|
|
309
|
+
const dependency=byId.get(id);
|
|
310
|
+
return dependency&&(dependency.completed||dependency.dropped);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
301
314
|
function selectTask(specsDir,names){
|
|
302
315
|
const features=[];
|
|
303
316
|
const warnings=[];
|
|
@@ -322,18 +335,26 @@ function selectTask(specsDir,names){
|
|
|
322
335
|
pending:pending.length,
|
|
323
336
|
});
|
|
324
337
|
if(!pending.length)continue;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
338
|
+
// One dependency rule for nextTask and --task/parallel eligibility: a
|
|
339
|
+
// prerequisite is satisfied once it is completed or DROPPED.
|
|
340
|
+
const ready=task=>dependenciesSatisfied(task,parsed,byId);
|
|
341
|
+
const eligible=pending.find(ready);
|
|
329
342
|
if(!eligible)return {error:'dependencies_not_ready',features,warnings};
|
|
330
343
|
return {features,warnings,nextTask:{feature:name,id:eligible.id,description:eligible.description},
|
|
331
|
-
eligibleTasks:pending.filter(
|
|
332
|
-
.map(task=>({feature:name,id:task.id}))};
|
|
344
|
+
eligibleTasks:pending.filter(ready).map(task=>({feature:name,id:task.id}))};
|
|
333
345
|
}
|
|
334
346
|
return {features,warnings,nextTask:null};
|
|
335
347
|
}
|
|
336
348
|
|
|
349
|
+
// Selection stays tasks.md-driven; an earlier feature's unfinished QA is surfaced
|
|
350
|
+
// here and enforced at N8 (finish/run_finalize), never by reordering tasks.
|
|
351
|
+
function featureQaWarnings(specsDir,features){
|
|
352
|
+
try{
|
|
353
|
+
return outstandingFeatureQa({specsDir,features:features.map(({name,pending})=>({name,pending}))}).map(item=>
|
|
354
|
+
`⚠ QA 未通过: ${describeOutstandingQa(item)};它通过之前项目不能收尾(run_done)`);
|
|
355
|
+
}catch{return ['⚠ QA 日志无法读取,未能确认各 feature 的最新 QA 是否通过'];}
|
|
356
|
+
}
|
|
357
|
+
|
|
337
358
|
export function inspectCmAiAdmission(options){
|
|
338
359
|
return admissionFor(options);
|
|
339
360
|
}
|
|
@@ -343,7 +364,7 @@ export function approveCmAiSpecs(options){
|
|
|
343
364
|
const projects=options.codeProjects??[options.codeProject];
|
|
344
365
|
const inspect=()=>projects.map(codeProject=>inspectCmAiAdmission({...options,codeProject}));
|
|
345
366
|
const projectResults=inspect();
|
|
346
|
-
const refuse=approveRefused=>({projectResults,approveRefused});
|
|
367
|
+
const refuse=(approveRefused,approveReason=null)=>({projectResults,approveRefused,...(approveReason?{approveReason}:{})});
|
|
347
368
|
if(options.assumeYes)return refuse('assume_yes_not_allowed');
|
|
348
369
|
if(typeof options.approvalResponse!=='string'||!options.approvalResponse.trim())
|
|
349
370
|
return refuse('approval_response_required');
|
|
@@ -356,10 +377,36 @@ export function approveCmAiSpecs(options){
|
|
|
356
377
|
try{
|
|
357
378
|
const discovered=discoverFeatures(specsDir);
|
|
358
379
|
if(discovered.error)return refuse(discovered.error);
|
|
380
|
+
// An approval binds grammar 2 to every feature, including ones this change
|
|
381
|
+
// did not touch. Refuse rather than silently re-reading bytes that an older
|
|
382
|
+
// approval parsed differently (e.g. an unfenced `- [ ] T-001:例` becoming a
|
|
383
|
+
// duplicate of the real T-001), and rather than keeping grammar 1, which
|
|
384
|
+
// would leave newly drafted full-width task lines silently not tasks.
|
|
385
|
+
// Moving from the pre-grammar parse must not change which lines are tasks
|
|
386
|
+
// either (e.g. a unique `- [ ] T-099:示例` would become a pending task). The
|
|
387
|
+
// status carries the last approval's grammar through cm-prd publication;
|
|
388
|
+
// once a project is on grammar 2 there is nothing to reconcile.
|
|
389
|
+
// No status at all means nothing was approved before: no earlier meaning to keep.
|
|
390
|
+
const fromLegacy=status.kind==='valid'&&status.value.taskGrammar!==TASK_GRAMMAR;
|
|
391
|
+
for(const name of discovered.names){
|
|
392
|
+
const source=fs.readFileSync(path.join(specsDir,name,'tasks.md'),'utf8');
|
|
393
|
+
const parsed=parseFeatureTaskText(source,{allowDependencyPunctuation:true,grammar:TASK_GRAMMAR});
|
|
394
|
+
if(parsed.error)return refuse('task_grammar_conflict',`${name}/tasks.md 第 ${parsed.detail.line} 行在新任务行语法下无效(${parsed.error}):`
|
|
395
|
+
+`${parsed.detail.text}。此前的批准把它当作说明文字;把这类示例放进 \`\`\` 围栏或删去后再批准。`);
|
|
396
|
+
if(!fromLegacy)continue;
|
|
397
|
+
const view=grammar=>taskDeclarations(source,{grammar}).map(item=>({line:item.index+1,key:`${item.id}\0${item.completed}\0${item.body.trim()}`,text:item.body.trim()}));
|
|
398
|
+
const legacy=view(LEGACY_TASK_GRAMMAR),current=view(TASK_GRAMMAR);
|
|
399
|
+
const legacyKeys=new Set(legacy.map(item=>item.key)),currentKeys=new Set(current.map(item=>item.key));
|
|
400
|
+
const differing=[...current.filter(item=>!legacyKeys.has(item.key)),...legacy.filter(item=>!currentKeys.has(item.key))]
|
|
401
|
+
.sort((a,b)=>a.line-b.line);
|
|
402
|
+
if(differing.length)return refuse('task_grammar_conflict',`${name}/tasks.md 在新任务行语法下任务集合会变化:`
|
|
403
|
+
+differing.slice(0,5).map(item=>`第 ${item.line} 行 ${item.text}`).join(';')+`${differing.length>5?` 等 ${differing.length} 行`:''}`
|
|
404
|
+
+'。此前的批准不把这些行当任务(或反之);是示例就放进 ``` 围栏或删去,是任务就改用英文冒号「:」写法后再批准。');
|
|
405
|
+
}
|
|
359
406
|
const specFiles=buildManifest(specsDir),at=new Date().toISOString();
|
|
360
407
|
writeSpecsStatus(specsDir,{status:'approved',summaryDigest:status.value?.summaryDigest??null,at,
|
|
361
408
|
features:discovered.names,specFiles,testCases:specFiles.filter(item=>item.path.endsWith('/test-cases.json')),
|
|
362
|
-
approval:{response:options.approvalResponse,at},
|
|
409
|
+
approval:{response:options.approvalResponse,at},taskGrammar:TASK_GRAMMAR,
|
|
363
410
|
...(status.value&&Object.hasOwn(status.value,'revisionDigest')?{revisionDigest:status.value.revisionDigest}:{})});
|
|
364
411
|
}catch(error){return refuse(error.code??error.message);}
|
|
365
412
|
return {projectResults:inspect()};
|
|
@@ -383,7 +430,7 @@ function admissionFor(options,inProgressBootstrap=null){
|
|
|
383
430
|
if(featuresProblem==='spec_features_changed')return result(base,'awaiting_spec_approval',featuresProblem);
|
|
384
431
|
if(featuresProblem)return result(base,'blocked',featuresProblem);
|
|
385
432
|
if(Object.hasOwn(status.value,'specFiles')){
|
|
386
|
-
try{
|
|
433
|
+
try{verifyApprovedManifest(specsDir,path.join(specsDir,'.cm-specs-status'));}
|
|
387
434
|
catch{return result(base,'blocked','spec_drift');}
|
|
388
435
|
}
|
|
389
436
|
const testCasesProblem=validateTestCases(specsDir,status.value,discovered.names);
|
|
@@ -395,8 +442,32 @@ function admissionFor(options,inProgressBootstrap=null){
|
|
|
395
442
|
const selection=selectTask(specsDir,discovered.names);
|
|
396
443
|
if(selection.error)return result(base,'blocked',selection.error,{features:selection.features,warnings:selection.warnings,
|
|
397
444
|
...(selection.detail?{detail:selection.detail}:{})});
|
|
398
|
-
|
|
399
|
-
return result(base,'
|
|
445
|
+
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});
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// Diagnostic only: why an explicit --task selection is not eligible. Never used
|
|
451
|
+
// to grant a selection; matchesCmAiTaskSelection remains the sole gate.
|
|
452
|
+
export function explainCmAiTaskSelection(admission,{feature,taskId,selection=null}){
|
|
453
|
+
if(admission.state!=='ready')return `当前准入状态为 ${admission.state}/${admission.reason},不能选择任务`;
|
|
454
|
+
const next=admission.nextTask;
|
|
455
|
+
if(next&&next.feature!==feature)return `--task 只能选择当前 feature ${next.feature} 的任务(运行定义为 ${feature})`;
|
|
456
|
+
if(!admission.specsDir)return `${taskId} 不在可选任务中`;
|
|
457
|
+
let parsed;
|
|
458
|
+
try{parsed=readFeature(admission.specsDir,feature);}catch{return `无法读取 ${feature}/tasks.md`;}
|
|
459
|
+
if(parsed.error)return `${feature}/tasks.md 无法解析(${parsed.error})`;
|
|
460
|
+
const byId=new Map(parsed.tasks.map(task=>[task.id,task]));
|
|
461
|
+
const task=byId.get(taskId);
|
|
462
|
+
if(!task)return `${feature}/tasks.md 中没有任务 ${taskId}`;
|
|
463
|
+
if(task.dropped)return `${taskId} 已标记 DROPPED`;
|
|
464
|
+
if(task.completed)return `${taskId} 已勾选完成`;
|
|
465
|
+
const waiting=(parsed.dependencies.get(taskId)||[]).filter(id=>{const item=byId.get(id);return !item||!item.completed&&!item.dropped;});
|
|
466
|
+
if(waiting.length)return `${taskId} 依赖的 ${waiting.join('、')} 尚未完成`;
|
|
467
|
+
const eligible=(admission.eligibleTasks??[]).filter(item=>item.feature===feature).map(item=>item.id);
|
|
468
|
+
if(selection===null&&next&&next.id!==taskId&&eligible.includes(taskId))
|
|
469
|
+
return `运行定义未写 taskSelection,只能运行 nextTask ${next.id};改选 ${taskId} 请用 cm-ai-admission.mjs --print-run-definition --task ${taskId} 重新生成运行定义`;
|
|
470
|
+
return `${taskId} 不在可选任务中;当前可选:${eligible.join('、')||'无'}`;
|
|
400
471
|
}
|
|
401
472
|
|
|
402
473
|
// Trusted caller selection is data bound by openControlRun, never message authority.
|
|
@@ -404,6 +475,9 @@ export function matchesCmAiTaskSelection(admission,feature,taskId,parallelSelect
|
|
|
404
475
|
if(parallelSelection===null)return admission.state==='ready'
|
|
405
476
|
&&admission.nextTask?.feature===feature&&admission.nextTask.id===taskId;
|
|
406
477
|
const value=parallelSelection;
|
|
478
|
+
if(value?.version===1&&Object.keys(value).sort().join(',')==='taskId,version')
|
|
479
|
+
return value.taskId===taskId&&admission.state==='ready'
|
|
480
|
+
&&admission.eligibleTasks?.some(task=>task.feature===feature&&task.id===taskId)===true;
|
|
407
481
|
return admission.state==='ready'&&value?.version===1
|
|
408
482
|
&&Object.keys(value).sort().join(',')==='group,version'&&Array.isArray(value.group)
|
|
409
483
|
&&value.group.length>=2&&new Set(value.group).size===value.group.length
|
|
@@ -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} from './cm-ai-admission.mjs';
|
|
5
|
+
import {inspectCmAiAdmission,matchesCmAiTaskSelection,identifyApprovedBootstrapFeature} 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'];
|
|
@@ -62,7 +62,8 @@ export function inspectCmAiContextRefresh(input,{admission:trustedAdmission=null
|
|
|
62
62
|
shape(input,['specsDir','codeProject','feature','applicableAgentFiles']);
|
|
63
63
|
text(input.specsDir);text(input.codeProject);text(input.feature);
|
|
64
64
|
const admission=trustedAdmission??inspectCmAiAdmission({specsDir:input.specsDir,codeProject:input.codeProject});
|
|
65
|
-
if(trustedAdmission!==null)need(input.feature===
|
|
65
|
+
if(trustedAdmission!==null)need(input.feature===identifyApprovedBootstrapFeature(
|
|
66
|
+
trustedAdmission.features.map(item=>item.name))
|
|
66
67
|
&&admission.specsDir===input.specsDir&&admission.codeProject===input.codeProject,'context_invalid');
|
|
67
68
|
if(!['ready','complete'].includes(admission.state))return freeze({state:admission.state,reason:admission.reason,
|
|
68
69
|
nextTask:null,eligibleTasks:[],contextDigest:null,contextFiles:[]});
|