@aibyzero/cm-workflow 0.16.4 → 0.16.6
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 +22 -0
- package/CHANGELOG.md +57 -0
- package/README.md +22 -4
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/VERSION +1 -1
- package/docs/architecture.md +43 -0
- package/docs/execution-optimizations.md +33 -0
- package/docs/external-models.md +114 -0
- package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
- package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
- package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
- package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
- package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
- package/docs/human-correction.md +31 -0
- package/docs/installation.md +48 -7
- package/docs/js-workflow-control.md +293 -33
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- package/docs/runtime-failover.md +1 -1
- package/docs/untested-branches.md +27 -4
- package/docs/user-guide.md +23 -8
- package/install-codex.sh +28 -11
- 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-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- 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 +208 -34
- 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 +181 -57
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +15 -58
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +56 -17
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- 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 +315 -0
- package/runtime/js/cm-ai/drive-core.mjs +47 -9
- package/runtime/js/cm-ai/durable-runner-state.mjs +413 -56
- 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-policy.mjs +58 -0
- 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/external-group-models.mjs +53 -0
- package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
- package/runtime/js/cm-ai/external-models.mjs +52 -0
- package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +126 -29
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +66 -20
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-progress.mjs +80 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
- package/runtime/js/cm-ai/host-qa-executor.mjs +23 -9
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +23 -6
- 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 +16 -5
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
- package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
- package/runtime/js/cm-ai/live-evidence.mjs +96 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
- package/runtime/js/cm-ai/model_configuration_write.py +214 -0
- package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +86 -0
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +68 -9
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- 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 +438 -31
- package/runtime/js/cm-ai/review-presentation.mjs +45 -0
- package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
- 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/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +658 -75
- package/runtime/js/cm-ai/tool-preview.mjs +8 -4
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-ai/worker-claude.mjs +63 -19
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
- package/runtime/js/cm-ai/worker-codex.mjs +45 -19
- package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
- package/runtime/js/cm-fix/cause-package.mjs +10 -1
- package/runtime/js/cm-fix/execution.mjs +279 -52
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/host-review.mjs +32 -9
- package/runtime/js/cm-fix/host.mjs +6 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/progress.mjs +5 -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-fix/review-reconciliation.mjs +64 -0
- 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/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +27 -15
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-prd/summary.mjs +3 -1
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +10 -3
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- 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 +135 -34
- package/scripts/cm-ai-batch-drive.test.mjs +209 -3
- package/scripts/cm-ai-batch-host.mjs +63 -24
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- package/scripts/cm-ai-batch-run.mjs +101 -34
- 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 +159 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +162 -0
- package/scripts/cm-ai-bootstrap.test.mjs +174 -89
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +97 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +924 -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 +526 -60
- package/scripts/cm-ai-drive.test.mjs +336 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +142 -43
- 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-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +187 -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 +977 -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 +206 -62
- package/scripts/cm-ai-run.test.mjs +6 -4
- 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-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.test.mjs +2 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +12 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +10 -2
- 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-codex-plugin-metadata.py +83 -0
- package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
- package/scripts/cm-efficiency-checks.test.mjs +37 -0
- package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
- package/scripts/cm-efficiency-offline.mjs +35 -0
- package/scripts/cm-efficiency-policy.test.mjs +48 -0
- package/scripts/cm-efficiency-presentation.test.mjs +35 -0
- package/scripts/cm-efficiency-response.test.mjs +117 -0
- package/scripts/cm-efficiency-usage.test.mjs +148 -0
- package/scripts/cm-external-batch-host.test.mjs +157 -0
- package/scripts/cm-external-fix-host.test.mjs +281 -0
- package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
- package/scripts/cm-external-group-models.test.mjs +60 -0
- package/scripts/cm-external-model-host.test.mjs +180 -0
- package/scripts/cm-external-model-recovery.test.mjs +108 -0
- package/scripts/cm-external-models.test.mjs +89 -0
- package/scripts/cm-external-process-cleanup.test.mjs +71 -0
- package/scripts/cm-external-qa-fix.test.mjs +170 -0
- package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
- 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 +70 -23
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +24 -14
- package/scripts/cm-fix-protected-edits.test.mjs +12 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
- package/scripts/cm-fix-review-budget.test.mjs +147 -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 +213 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +25 -2
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-completion.test.mjs +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-host.mjs +13 -4
- 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-release-smoke.sh +5 -1
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-runtime-i18n.mjs +15 -4
- package/scripts/cm-runtime-install.mjs +8 -4
- package/scripts/cm-runtime.mjs +116 -23
- package/scripts/cm-runtime.test.mjs +121 -12
- package/scripts/cm-security.test.mjs +32 -0
- 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-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +164 -20
- package/scripts/cm-task-gate.py +2 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/cm-test-drive.mjs +10 -4
- package/scripts/cm-test-drive.test.mjs +14 -1
- package/scripts/cm-tool-preview-context.test.mjs +12 -0
- package/scripts/cm-usage-report.py +22 -3
- package/scripts/cm-workflow-config.mjs +10 -1
- package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +101 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +11 -2
- 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/SKILL.md +2 -2
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +270 -43
- package/skills/cm-ai/references/knowledge-closeout.md +90 -0
- package/skills/cm-fix/SKILL.md +1 -1
- package/skills/cm-fix/references/js-host.md +52 -3
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
- package/skills/cm-runtime/SKILL.md +29 -6
- package/skills/cm-security/SKILL.md +4 -2
- package/skills/cm-security/references/scan-contract.md +1 -0
- package/templates/cm-workflow.yml +1 -1
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import test,{after} from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
+
import {cmInitRuleTargets} from '../runtime/js/cm-init/draft-generation.mjs';
|
|
10
|
+
import {bootstrapDriverGap} from './cm-ai-drive.mjs';
|
|
11
|
+
import {inspectDriverBootstrap,readBootstrapRulesAnswers,createBootstrapRulesResponder} from '../runtime/js/cm-ai/drive-bootstrap.mjs';
|
|
12
|
+
|
|
13
|
+
// In-process helpers never touch the invoking user's workflow or log home.
|
|
14
|
+
const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-drive-rules-home-'));
|
|
15
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedHome,'user');
|
|
16
|
+
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedHome,'logs');
|
|
17
|
+
after(()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
|
|
18
|
+
const DRIVER=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
|
|
19
|
+
const HOST=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
20
|
+
const selection={versionControl:'local',modules:[],analysis:'SwiftUI iOS app: Package.swift, Sources/AITide, local Git'};
|
|
21
|
+
const scaffold={'Package.swift':'// swift-tools-version:5.9\nimport PackageDescription\nlet package = Package(name: "AITide", targets: [.executableTarget(name: "AITide")])\n',
|
|
22
|
+
'Sources/AITide/AITideApp.swift':'import SwiftUI\n@main struct AITideApp: App { var body: some Scene { WindowGroup { Text("AITide") } } }\n',
|
|
23
|
+
'scripts/verify.sh':'set -e\ntest -f Package.swift\ntest -f Sources/AITide/AITideApp.swift\nif [ "$1" = "--strict" ]; then test -f Sources/AITide/Missing.swift; fi\n'};
|
|
24
|
+
const learning={application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}};
|
|
25
|
+
|
|
26
|
+
function fixture(t,{scaffolded=false,nested=false}={}){
|
|
27
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-drive-rules-')));
|
|
28
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
29
|
+
const codeProject=path.join(root,'app'),specsDir=nested?path.join(codeProject,'specs5'):path.join(root,'specs5'),feature='1.bootstrap';
|
|
30
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
31
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'# SwiftUI scaffold and rules\n');
|
|
32
|
+
fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Split specs5 and app roots; SwiftUI; local Git\n');
|
|
33
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),
|
|
34
|
+
`- [${scaffolded?'x':' '}] T-001: 生成项目骨架 scaffold\n- [ ] T-002: 生成 AGENTS.md 和 .claude/ 规范(cm-init)\n`);
|
|
35
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
36
|
+
if(scaffolded)for(const [file,content] of Object.entries(scaffold)){
|
|
37
|
+
fs.mkdirSync(path.dirname(path.join(codeProject,file)),{recursive:true});fs.writeFileSync(path.join(codeProject,file),content);
|
|
38
|
+
}
|
|
39
|
+
const answers=path.join(root,'answers'),bin=path.join(root,'bin');fs.mkdirSync(answers);fs.mkdirSync(bin);
|
|
40
|
+
const env={...process.env,PATH:bin+path.delimiter+process.env.PATH,
|
|
41
|
+
CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')};
|
|
42
|
+
const write=(name,value)=>{const file=path.join(answers,name);fs.mkdirSync(path.dirname(file),{recursive:true});
|
|
43
|
+
fs.writeFileSync(file,typeof value==='string'?value:JSON.stringify(value));};
|
|
44
|
+
// key names the run definition file and its runId; a task may get a fresh run.
|
|
45
|
+
const writeRun=(taskId,scope,key=taskId)=>fs.writeFileSync(path.join(root,`run-${key}.json`),JSON.stringify({version:1,specsDir,codeProject,feature,
|
|
46
|
+
identity:{repositoryId:'app',runId:`bootstrap-${key}`,taskId,attempt:1},scope,requirements:[]}));
|
|
47
|
+
const writeBootstrap=value=>fs.writeFileSync(path.join(root,'bootstrap.json'),JSON.stringify({selection:value}));
|
|
48
|
+
// create requires a bound review configuration; this placeholder grants no review.
|
|
49
|
+
fs.writeFileSync(path.join(root,'placeholder-review.json'),JSON.stringify({model:'fixture',preflight:{}}));
|
|
50
|
+
const plan=(key,mode,permissions,extra={})=>{
|
|
51
|
+
const file=path.join(root,`plan-${Math.random().toString(36).slice(2)}.json`);
|
|
52
|
+
const bound=permissions.includes('--review-config')?permissions:[...permissions,'--review-config','placeholder-review.json'];
|
|
53
|
+
fs.writeFileSync(file,JSON.stringify({config:`run-${key}.json`,mode,hostContext:'drive-rules-host',runtime:'claude',
|
|
54
|
+
permissions:bound,answers:'answers',checks:[{id:'structure',command:['/bin/sh','scripts/verify.sh']}],...extra}));
|
|
55
|
+
return file;
|
|
56
|
+
};
|
|
57
|
+
const drive=(file,operation)=>spawnSync(process.execPath,[DRIVER,'--plan',file,operation],{encoding:'utf8',timeout:60000,env});
|
|
58
|
+
const store=key=>path.join(specsDir,'.reviews','.execution',`bootstrap-${key}`);
|
|
59
|
+
const targets=cmInitRuleTargets(selection,codeProject);
|
|
60
|
+
return {root,specsDir,codeProject,feature,answers,bin,env,write,writeRun,writeBootstrap,plan,drive,store,targets};
|
|
61
|
+
}
|
|
62
|
+
const rulesPermissions=['--bootstrap-config','bootstrap.json','--allow-bootstrap-write'];
|
|
63
|
+
|
|
64
|
+
// The session's own instruction documents for one attempt, as content files.
|
|
65
|
+
function rulesDocuments(f,attempt,{agents}={}){
|
|
66
|
+
const baseAgents='# AITide\n\n## 常用命令\n\n- 结构检查: `sh scripts/verify.sh`\n';
|
|
67
|
+
const contents={
|
|
68
|
+
'AGENTS.md':agents??(attempt===1?baseAgents:baseAgents+'\n## 修订补充\n\n- 严格检查: `sh scripts/verify.sh --strict`(新增模块后)\n'),
|
|
69
|
+
'.claude/CLAUDE.md':'# AITide\n\n## 规则\n\n@rules/coding-style.md\n@rules/testing.md\n@rules/security.md\n@rules/git-workflow.md\n',
|
|
70
|
+
'.claude/rules/coding-style.md':'# 代码风格\n\nSwiftUI 视图放 Sources/AITide。\n',
|
|
71
|
+
'.claude/rules/testing.md':attempt===1?'# 测试\n\n运行 `sh scripts/verify.sh`。\n'
|
|
72
|
+
:'# 测试\n\n运行 `sh scripts/verify.sh`;新增 Swift 文件后补结构检查。\n',
|
|
73
|
+
'.claude/rules/security.md':'# 安全\n\n不提交密钥。\n',
|
|
74
|
+
'.claude/rules/git-workflow.md':'# Git\n\n本地仓库,无远端。\n'};
|
|
75
|
+
const documents=f.targets.map(file=>{const local=`t002-a${attempt}/${file.replace(/[/.]/g,'_')}.md`;
|
|
76
|
+
f.write(local,contents[file]);return {path:file,contentFile:local};});
|
|
77
|
+
return {generate:{status:'generated',documents},contents};
|
|
78
|
+
}
|
|
79
|
+
function verifyAnswer(commands=[{id:'verify',command:['/bin/sh','scripts/verify.sh'],timeoutMs:60000}],extra={}){
|
|
80
|
+
const checks=Object.fromEntries(['globs','file_references','constraint_preservation','rule_applicability']
|
|
81
|
+
.map(name=>[name,{status:'verified',evidence:`Session checked ${name} against app/ before writing this file`}]));
|
|
82
|
+
return {commands,commandsNotRun:null,checks,constraintChanges:[],...learning,...extra};
|
|
83
|
+
}
|
|
84
|
+
function prepareRules(f,attempt,options={}){
|
|
85
|
+
const suffix=attempt===1?'':`-a${attempt}`,docs=rulesDocuments(f,attempt,options);
|
|
86
|
+
f.write(`init-generate${suffix}.json`,docs.generate);
|
|
87
|
+
f.write(`init-verify${suffix}.json`,verifyAnswer(options.commands,options.retrospective?{retrospective:options.retrospective}:{}));
|
|
88
|
+
return docs.contents;
|
|
89
|
+
}
|
|
90
|
+
// A create-mode refusal after host_ready leaves the host-created run at ready with no effect.
|
|
91
|
+
function assertReadyWithoutEffect(f,key){
|
|
92
|
+
const saved=JSON.parse(fs.readFileSync(path.join(f.store(key),'state.json'),'utf8'));
|
|
93
|
+
assert.deepEqual(saved.records.map(row=>row.payload.type),['init']);
|
|
94
|
+
}
|
|
95
|
+
function assertRefusedBeforeLaunch(f,run,pattern){
|
|
96
|
+
assert.equal(run.status,2,run.stderr);assert.match(run.stderr,pattern);
|
|
97
|
+
assert.equal(fs.existsSync(f.store('T-002')),false,'preflight must not create the T-002 run store');
|
|
98
|
+
assert.equal(fs.existsSync(path.join(f.codeProject,'.claude')),false);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
test('help names the rules answer files and that command results come only from real runs',()=>{
|
|
102
|
+
const help=spawnSync(process.execPath,[DRIVER,'--help'],{encoding:'utf8'});
|
|
103
|
+
assert.equal(help.status,0);
|
|
104
|
+
for(const pattern of [/init-generate\.json/,/init-verify\.json/,/init-generate-a2\.json 与 init-verify-a2\.json/,
|
|
105
|
+
/commands 在宿主接受启动后、发送操作前由驾驶员实跑(须先带 --allow-bootstrap-write/,/结果只来自实跑,答案文件不能提供/])
|
|
106
|
+
assert.match(help.stdout,pattern);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('rules task driver support covers only pure single-root non-provider scope',t=>{
|
|
110
|
+
const f=fixture(t,{scaffolded:true});f.writeBootstrap(selection);
|
|
111
|
+
const config=path.join(f.root,'bootstrap.json');
|
|
112
|
+
const definition={specsDir:f.specsDir,codeProject:f.codeProject,feature:f.feature,scope:[...f.targets],
|
|
113
|
+
identity:{repositoryId:'app',runId:'t002',taskId:'T-002',attempt:1}};
|
|
114
|
+
const permissions=['--bootstrap-config',config,'--allow-bootstrap-write'];
|
|
115
|
+
for(const operation of ['advance','start','resume'])assert.equal(bootstrapDriverGap(operation,definition,permissions),null);
|
|
116
|
+
assert.match(bootstrapDriverGap('advance',definition,[...permissions,'--protected-config','x.json']),/--protected-config/);
|
|
117
|
+
assert.match(bootstrapDriverGap('advance',{...definition,codeProjects:['ios']},permissions),/codeProjects/);
|
|
118
|
+
assert.match(bootstrapDriverGap('advance',{...definition,scope:[...f.targets,'README.md']},permissions),/业务文件 README\.md/);
|
|
119
|
+
assert.match(bootstrapDriverGap('advance',{...definition,scope:f.targets.slice(1)},permissions),/缺少固定目标 AGENTS\.md/);
|
|
120
|
+
f.writeBootstrap(null);
|
|
121
|
+
assert.match(bootstrapDriverGap('advance',definition,permissions),/selection/);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('rules answer files are validated before the host starts',t=>{
|
|
125
|
+
const f=fixture(t,{scaffolded:true});f.writeRun('T-002',[...f.targets]);f.writeBootstrap(selection);
|
|
126
|
+
const run=(extra={})=>f.drive(f.plan('T-002','create',[...rulesPermissions,...(extra.permissions??[])],extra.plan),'advance');
|
|
127
|
+
assertRefusedBeforeLaunch(f,run(),/会反问 init_generate,但答案文件不存在: .*init-generate\.json/);
|
|
128
|
+
const {generate}=rulesDocuments(f,1);
|
|
129
|
+
const cases=[
|
|
130
|
+
['blocked generation',()=>f.write('init-generate.json',{status:'blocked',documents:[]}),/status 只能是 generated/],
|
|
131
|
+
['missing target',()=>f.write('init-generate.json',{...generate,documents:generate.documents.slice(1)}),/须逐项覆盖 targets/],
|
|
132
|
+
['unsafe content file',()=>f.write('init-generate.json',{...generate,documents:generate.documents.map((item,index)=>
|
|
133
|
+
index===0?{...item,contentFile:'../outside.md'}:item)}),/路径无效/],
|
|
134
|
+
['structural issue',()=>{f.write(generate.documents[1].contentFile,'# x\n'+'line\n'.repeat(160));
|
|
135
|
+
f.write('init-generate.json',generate);},/结构检查未通过: \.claude\/CLAUDE\.md:claude_line_limit/],
|
|
136
|
+
['extra key',()=>f.write('init-generate.json',{...generate,note:'x'}),/只允许 status 与 documents/],
|
|
137
|
+
['non UTF-8 content',()=>{fs.writeFileSync(path.join(f.answers,generate.documents[3].contentFile),Buffer.from([0xff,0xfe,0x41]));
|
|
138
|
+
f.write('init-generate.json',generate);},/不是 UTF-8 文本/],
|
|
139
|
+
['symlinked content',()=>{const target=path.join(f.answers,generate.documents[4].contentFile);fs.rmSync(target);
|
|
140
|
+
fs.writeFileSync(path.join(f.root,'outside.md'),'# outside\n');fs.symlinkSync(path.join(f.root,'outside.md'),target);
|
|
141
|
+
f.write('init-generate.json',generate);},/缺少安全的内容文件/],
|
|
142
|
+
['oversized reply',()=>{f.write(generate.documents[2].contentFile,'# big\n'+'x'.repeat(70*1024)+'\n');
|
|
143
|
+
f.write('init-generate.json',generate);},/超过宿主单次回复 64 KiB/],
|
|
144
|
+
];
|
|
145
|
+
for(const [name,setup,pattern] of cases){
|
|
146
|
+
for(const item of generate.documents)fs.rmSync(path.join(f.answers,item.contentFile),{force:true});
|
|
147
|
+
rulesDocuments(f,1);f.write('init-verify.json',verifyAnswer());setup();
|
|
148
|
+
assertRefusedBeforeLaunch(f,run(),pattern);
|
|
149
|
+
t.diagnostic(`refused: ${name}`);
|
|
150
|
+
}
|
|
151
|
+
rulesDocuments(f,1);f.write('init-generate.json',generate);fs.rmSync(path.join(f.answers,'init-verify.json'));
|
|
152
|
+
assertRefusedBeforeLaunch(f,run(),/会反问 init_verify,但答案文件不存在/);
|
|
153
|
+
const verifyCases=[
|
|
154
|
+
['static command result',verifyAnswer(undefined,{checks:{...verifyAnswer().checks,commands:{status:'verified',evidence:'ran ok'}}}),
|
|
155
|
+
/checks 不能包含 commands;命令核验只由驾驶员实跑/],
|
|
156
|
+
['no commands',verifyAnswer([]),/commands 须列出 1\.\.32 条/],
|
|
157
|
+
['unverified group',verifyAnswer(undefined,{checks:{...verifyAnswer().checks,globs:{status:'unverified',evidence:'no match yet'}}}),
|
|
158
|
+
/checks\.globs 为 unverified:宿主只接受 verified\/not_applicable/],
|
|
159
|
+
['constraint change',verifyAnswer(undefined,{constraintChanges:['AGENTS.md']}),/constraintChanges 必须为空/],
|
|
160
|
+
['invalid Learning',verifyAnswer(undefined,{application:{status:'applied',note:null}}),/application 须为原 Learning/],
|
|
161
|
+
['rebound Learning',verifyAnswer(undefined,{application:{...learning.application,feature:'2.other'}}),/application 须为原 Learning/],
|
|
162
|
+
['invalid retrospective',verifyAnswer(undefined,{retrospective:{status:'lesson_candidate',candidates:[],reason:null}}),
|
|
163
|
+
/retrospective 须为原 Learning/],
|
|
164
|
+
['bad command',verifyAnswer([{id:'bad id',command:['/bin/sh']}]),/init-verify\.json\.commands/],
|
|
165
|
+
['extra key',{...verifyAnswer(),passed:true},/init-verify\.json 需要 commands/],
|
|
166
|
+
['multi-line note',verifyAnswer(undefined,{commandsNotRun:'line one\nline two'}),/commandsNotRun 须为 null 或单行说明/],
|
|
167
|
+
['missing group',verifyAnswer(undefined,{checks:{...verifyAnswer().checks,globs:undefined}}),/checks 须恰好包含/],
|
|
168
|
+
['empty evidence',verifyAnswer(undefined,{checks:{...verifyAnswer().checks,globs:{status:'verified',evidence:' '}}}),
|
|
169
|
+
/checks\.globs 须为 \{status,evidence\}/],
|
|
170
|
+
];
|
|
171
|
+
for(const [name,value,pattern] of verifyCases){
|
|
172
|
+
f.write('init-verify.json',value);assertRefusedBeforeLaunch(f,run(),pattern);t.diagnostic(`refused: ${name}`);
|
|
173
|
+
}
|
|
174
|
+
f.write('init-verify.json',verifyAnswer());f.write('init-verify-a1.json',verifyAnswer());
|
|
175
|
+
assertRefusedBeforeLaunch(f,run(),/init-verify\.json 与 init-verify-a1\.json 不能同时存在/);
|
|
176
|
+
fs.rmSync(path.join(f.answers,'init-verify-a1.json'));
|
|
177
|
+
// A revision written before its findings exist is refused, even when preloaded.
|
|
178
|
+
const pattern=/advance 不能带 --allow-review-attempt 1 直接进入第 2 轮.*\.reviews\/bootstrap-T-002-r1\.md.*init-verify-a2\.json/;
|
|
179
|
+
assertRefusedBeforeLaunch(f,run({permissions:['--allow-review-attempt','1']}),pattern);
|
|
180
|
+
const {generate:revision}=rulesDocuments(f,2);f.write('init-generate-a2.json',revision);f.write('init-verify-a2.json',verifyAnswer());
|
|
181
|
+
assertRefusedBeforeLaunch(f,run({permissions:['--allow-review-attempt','1']}),pattern);
|
|
182
|
+
// The host inspects the raw draft before merging AGENTS.md lessons; so does the driver.
|
|
183
|
+
rulesDocuments(f,1);fs.writeFileSync(path.join(f.codeProject,'AGENTS.md'),'## 项目教训\n\n- 骨架教训\n');
|
|
184
|
+
f.write(generate.documents[0].contentFile,' \n');
|
|
185
|
+
assertRefusedBeforeLaunch(f,run(),/^\[drive\] init-generate\.json 无效: init_draft_invalid/m);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('attempt 1 refuses existing instructions the host would not overwrite',t=>{
|
|
189
|
+
const f=fixture(t,{scaffolded:true});f.writeRun('T-002',[...f.targets]);f.writeBootstrap(selection);prepareRules(f,1);
|
|
190
|
+
const run=()=>f.drive(f.plan('T-002','create',rulesPermissions),'advance');
|
|
191
|
+
fs.writeFileSync(path.join(f.codeProject,'AGENTS.md'),'# User-owned rules\n');
|
|
192
|
+
assertRefusedBeforeLaunch(f,run(),/规范目标 AGENTS\.md 与本运行可信基准不一致/);
|
|
193
|
+
// A T-001 Learning section is allowed; the draft must keep every other existing line.
|
|
194
|
+
fs.writeFileSync(path.join(f.codeProject,'AGENTS.md'),'# User-owned rules\n\n## 项目教训\n\n- 保留骨架教训\n');
|
|
195
|
+
assertRefusedBeforeLaunch(f,run(),/必须逐字保留当前「## 项目教训」段/);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('init-verify commands never run unless the host itself accepted the launch and the task',t=>{
|
|
199
|
+
const cases=[
|
|
200
|
+
['no write grant',{},f=>['--bootstrap-config','bootstrap.json'],
|
|
201
|
+
{status:2,pattern:/规范任务需要 --allow-bootstrap-write.*驾驶员不运行 init-verify 命令、不启动宿主/}],
|
|
202
|
+
['symlinked bootstrap config',{},f=>{const real=path.join(f.root,'bootstrap-real.json');
|
|
203
|
+
fs.renameSync(path.join(f.root,'bootstrap.json'),real);fs.symlinkSync(real,path.join(f.root,'bootstrap.json'));return rulesPermissions;},
|
|
204
|
+
{status:2,pattern:/bootstrap-config 无效或缺少有效的 cm-init selection: invalid_bootstrap_config/}],
|
|
205
|
+
['malformed protected config',{},f=>{fs.writeFileSync(path.join(f.root,'protection.json'),JSON.stringify({checkCommands:[]}));
|
|
206
|
+
return [...rulesPermissions,'--protected-conversation-config','protection.json'];},
|
|
207
|
+
{status:2,pattern:/--protected-conversation-config 无效.*宿主以同一读取器拒绝启动.*不运行 init-verify 命令/}],
|
|
208
|
+
['T-001 still pending',{pending:true},f=>rulesPermissions,
|
|
209
|
+
{status:2,pattern:/T-002 现在不能新建运行:admission ready,nextTask T-001.*不运行 init-verify 命令/}],
|
|
210
|
+
// No driver replica: the host's own launch check refuses before host_ready.
|
|
211
|
+
['nested specs without protection',{nested:true},f=>rulesPermissions,
|
|
212
|
+
{status:1,pattern:/nested_specs_protection_required/}],
|
|
213
|
+
];
|
|
214
|
+
for(const [name,options,permissions,expected] of cases){
|
|
215
|
+
const f=fixture(t,{scaffolded:!options.pending,nested:options.nested});
|
|
216
|
+
f.writeRun('T-002',[...f.targets]);f.writeBootstrap(selection);
|
|
217
|
+
const marker=path.join(f.root,'ran.marker');
|
|
218
|
+
prepareRules(f,1,{commands:[{id:'marker',command:['/bin/sh','-c',`echo ran > ${marker}`]}]});
|
|
219
|
+
const run=f.drive(f.plan('T-002','create',permissions(f)),'advance');
|
|
220
|
+
assert.equal(run.status,expected.status,`${name}: ${run.stderr}`);assert.match(run.stderr,expected.pattern,name);
|
|
221
|
+
assert.equal(fs.existsSync(marker),false,`${name}: no command may run`);
|
|
222
|
+
assert.equal(fs.existsSync(f.store('T-002')),false,name);
|
|
223
|
+
assert.equal(fs.existsSync(path.join(f.codeProject,'.claude')),false,name);
|
|
224
|
+
t.diagnostic(`refused: ${name}`);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('init-verify commands that change what the preflight bound are refused before launch',
|
|
229
|
+
{skip:process.platform==='win32'},t=>{
|
|
230
|
+
const f=fixture(t,{scaffolded:true});f.writeRun('T-002',[...f.targets]);f.writeBootstrap(selection);
|
|
231
|
+
const bootstrapFile=path.join(f.root,'bootstrap.json'),tasks=path.join(f.specsDir,f.feature,'tasks.md');
|
|
232
|
+
const original={bootstrap:fs.readFileSync(bootstrapFile),tasks:fs.readFileSync(tasks)};
|
|
233
|
+
for(const [index,[script,changed]] of [
|
|
234
|
+
['mkdir -p .claude && echo rewritten > .claude/CLAUDE.md','.claude/CLAUDE.md'],
|
|
235
|
+
[`printf ' ' >> ${bootstrapFile}`,bootstrapFile],
|
|
236
|
+
[`printf '\\n' >> ${tasks}`,tasks]].entries()){
|
|
237
|
+
const key=`T-002-${index}`;f.writeRun('T-002',[...f.targets],key);
|
|
238
|
+
prepareRules(f,1,{commands:[{id:'writer',command:['/bin/sh','-c',script]}]});
|
|
239
|
+
const run=f.drive(f.plan(key,'create',rulesPermissions),'advance');
|
|
240
|
+
assert.equal(run.status,2,run.stderr);
|
|
241
|
+
assert.match(run.stderr,new RegExp(`预检已核对的文件在发送操作前被改动: ${changed.replace(/[.*+?^${}()|[\]\\/]/g,'\\$&')}.*PLAN\\.mode 改为 resume`));
|
|
242
|
+
assert.doesNotMatch(run.stderr,/应答 init_generate/);
|
|
243
|
+
assertReadyWithoutEffect(f,key);
|
|
244
|
+
fs.rmSync(path.join(f.codeProject,'.claude'),{recursive:true,force:true});
|
|
245
|
+
fs.writeFileSync(bootstrapFile,original.bootstrap);fs.writeFileSync(tasks,original.tasks);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('protected mode runs init-verify commands inside the same specs sandbox as its task checks',
|
|
250
|
+
{skip:process.platform!=='darwin'},t=>{
|
|
251
|
+
const f=fixture(t,{scaffolded:true});f.writeRun('T-002',[...f.targets]);f.writeBootstrap(selection);
|
|
252
|
+
fs.writeFileSync(path.join(f.root,'protection.json'),JSON.stringify({checkCommands:[{id:'structure',
|
|
253
|
+
command:['/bin/sh','scripts/verify.sh']}],timeoutMs:60000}));
|
|
254
|
+
const leak=path.join(f.specsDir,'leak.txt');
|
|
255
|
+
prepareRules(f,1,{commands:[{id:'leak',command:['/bin/sh','-c',`echo leak > ${leak}`],timeoutMs:60000}]});
|
|
256
|
+
const run=f.drive(f.plan('T-002','create',[...rulesPermissions,'--protected-conversation-config','protection.json']),'advance');
|
|
257
|
+
assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/init-verify\.json 的命令在发送操作前实跑未通过:leak:/);
|
|
258
|
+
assert.equal(fs.existsSync(leak),false,'the specs root stays read-only for init-verify commands');
|
|
259
|
+
assertReadyWithoutEffect(f,'T-002');
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test('responder binds each host request to the preflighted attempt and its own command runs',
|
|
263
|
+
{skip:process.platform==='win32'},async t=>{
|
|
264
|
+
const f=fixture(t,{scaffolded:true});f.writeBootstrap(selection);
|
|
265
|
+
const identity={repositoryId:'app',runId:'t002',taskId:'T-002',attempt:1};
|
|
266
|
+
const definition={specsDir:f.specsDir,codeProject:f.codeProject,feature:f.feature,scope:[...f.targets],identity};
|
|
267
|
+
const bootstrap=inspectDriverBootstrap({advance:true,definition,
|
|
268
|
+
permissions:['--bootstrap-config',path.join(f.root,'bootstrap.json')]});
|
|
269
|
+
const contents=prepareRules(f,1,{commands:[{id:'strict',command:['/bin/sh','scripts/verify.sh','--strict'],timeoutMs:60000}]});
|
|
270
|
+
const answers=readBootstrapRulesAnswers({answers:f.answers,operation:'advance',definition,plan:{},bootstrap,
|
|
271
|
+
permissions:['--bootstrap-config',path.join(f.root,'bootstrap.json'),'--allow-bootstrap-write'],
|
|
272
|
+
reachable:{attempts:[1],reviewFirst:false,packageDigest:null,learning:null,journal:null}});
|
|
273
|
+
// Even answer data that carried a commands entry cannot replace the driver's own run.
|
|
274
|
+
answers.get(1).verify.checks={...answers.get(1).verify.checks,commands:{status:'verified',evidence:'static pass'}};
|
|
275
|
+
const responder=createBootstrapRulesResponder({definition,plan:{},bootstrap,answers});
|
|
276
|
+
const generate=(attempt=1,targets=f.targets)=>({kind:'init_generate',payload:{project:f.codeProject,selection:bootstrap.selection,
|
|
277
|
+
targets,bootstrap:{identity:{...identity,attempt}}}});
|
|
278
|
+
const documents=f.targets.map(file=>({path:file,content:contents[file]}));
|
|
279
|
+
const verify=(attempt=1,docs=documents)=>({kind:'init_verify',payload:{project:f.codeProject,documents:docs,
|
|
280
|
+
categories:['commands','globs','file_references','constraint_preservation','rule_applicability'],
|
|
281
|
+
learningInput:{identity:{...identity,attempt}}}});
|
|
282
|
+
await assert.rejects(async()=>responder.init_verify(verify()),/尚未应答对应的 init_generate/);
|
|
283
|
+
responder.init_generate(generate());
|
|
284
|
+
await assert.rejects(async()=>responder.init_verify(verify()),/命令尚未由本驾驶员实跑/);
|
|
285
|
+
// prepare really runs the listed command before the host starts and refuses its failure.
|
|
286
|
+
assert.match(await responder.prepare(),/init-verify\.json 的命令在发送操作前实跑未通过:strict: failed(host check exited 1)。未发送操作,运行存档不变/);
|
|
287
|
+
assert.match(await responder.prepare('create'),/宿主已按 create 建好运行(ready,未执行开发步骤);修正后把 PLAN\.mode 改为 resume 重试/);
|
|
288
|
+
assert.throws(()=>responder.init_generate({...generate(),payload:{...generate().payload,project:f.root}}),/项目根与运行定义不一致/);
|
|
289
|
+
assert.throws(()=>responder.init_generate({...generate(),payload:{...generate().payload,selection:{...selection,modules:['frontend']}}}),
|
|
290
|
+
/selection 与 bootstrap-config 不一致/);
|
|
291
|
+
responder.init_generate(generate());
|
|
292
|
+
await assert.rejects(async()=>responder.init_verify({...verify(),payload:{...verify().payload,project:f.root}}),/项目根与运行定义不一致/);
|
|
293
|
+
responder.init_generate(generate());
|
|
294
|
+
await assert.rejects(async()=>responder.init_verify({...verify(),payload:{...verify().payload,categories:['commands']}}),/核验分组与合同不一致/);
|
|
295
|
+
assert.throws(()=>responder.init_generate(generate(2)),/第 2 轮未预检/);
|
|
296
|
+
assert.throws(()=>responder.init_generate(generate(1,f.targets.slice(1))),/targets 与预检不一致/);
|
|
297
|
+
assert.deepEqual(responder.init_generate(generate()).documents,documents);
|
|
298
|
+
await assert.rejects(async()=>responder.init_verify(verify(2)),/轮次与刚应答的 init_generate 不一致/);
|
|
299
|
+
responder.init_generate(generate());
|
|
300
|
+
await assert.rejects(async()=>responder.init_verify(verify(1,documents.map(item=>item.path==='AGENTS.md'
|
|
301
|
+
?{...item,content:item.content+'drift\n'}:item))),/草稿与 init-generate 答案.*不一致/);
|
|
302
|
+
responder.init_generate(generate());
|
|
303
|
+
const reply=await responder.init_verify(verify());
|
|
304
|
+
assert.equal(reply.checks.commands.status,'failed');
|
|
305
|
+
assert.match(reply.checks.commands.evidence,/驾驶员在发送本操作前实跑 1\/1 条草稿命令(\d{4}-\d{2}-\d{2}T[\d:]+Z): strict: failed(host check exited 1)/);
|
|
306
|
+
assert.deepEqual(reply.constraintChanges,[]);assert.deepEqual(reply.application,learning.application);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
function reviewFixture(f,{revise:requestRevision=true}={}){
|
|
310
|
+
const source=fs.readFileSync(fileURLToPath(new URL('./fixtures/claude-review-process.mjs',import.meta.url)),'utf8');
|
|
311
|
+
const revise=requestRevision?"data.reviewPackage.identity.taskId==='T-002'&&data.reviewPackage.identity.attempt===1":'false';
|
|
312
|
+
const fake=source.replace("verdict:'approved'",`verdict:${revise}?'changes_requested':'approved'`)
|
|
313
|
+
.replace('findings:[]',`findings:${revise}?[{id:'F1',severity:'P2',path:'.claude/rules/testing.md',message:'Name the structure check for new Swift files',evidence:'Synthetic revision fixture'}]:[]`);
|
|
314
|
+
assert.notEqual(fake,source);
|
|
315
|
+
const cli=path.join(f.bin,'claude');fs.writeFileSync(cli,fake,{mode:0o700});
|
|
316
|
+
const preview=spawnSync(process.execPath,[HOST,'preflight','--config',path.join(f.root,'run-T-001.json'),
|
|
317
|
+
'--review-model','fixture','--runtime','claude'],{encoding:'utf8',timeout:10000,env:f.env});
|
|
318
|
+
assert.equal(preview.status,0,preview.stderr);fs.writeFileSync(path.join(f.root,'review.json'),preview.stdout);
|
|
319
|
+
}
|
|
320
|
+
const result=run=>JSON.parse(run.stdout).result;
|
|
321
|
+
const read=(f,file)=>fs.readFileSync(path.join(f.codeProject,file),'utf8');
|
|
322
|
+
|
|
323
|
+
test('real host drives split-root T-001 scaffold, then T-002 rules with a revision round',
|
|
324
|
+
{skip:process.platform!=='darwin',timeout:180000},t=>{
|
|
325
|
+
const f=fixture(t);
|
|
326
|
+
const scope=Object.keys(scaffold);f.writeRun('T-001',scope);f.writeBootstrap(null);
|
|
327
|
+
for(const [file,content] of Object.entries(scaffold))f.write(`t001/${file}`,content);
|
|
328
|
+
f.write('develop.json',{status:'succeeded',value:{outcome:'implemented',...learning},
|
|
329
|
+
edits:Object.fromEntries(scope.map(file=>[file,`t001/${file}`]))});
|
|
330
|
+
reviewFixture(f);
|
|
331
|
+
const review=['--review-config','review.json'];
|
|
332
|
+
let run=f.drive(f.plan('T-001','create',[...rulesPermissions,...review]),'advance');
|
|
333
|
+
assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'awaiting_review');
|
|
334
|
+
run=f.drive(f.plan('T-001','resume',[...rulesPermissions,...review,'--allow-review-attempt','1'],{packageDigest:result(run).packageDigest}),'decision');
|
|
335
|
+
assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'approved');
|
|
336
|
+
run=f.drive(f.plan('T-001','resume',[...rulesPermissions,...review]),'advance');
|
|
337
|
+
assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'fixture_completed');
|
|
338
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,f.feature,'tasks.md'),'utf8'),/\[x\] T-001/);
|
|
339
|
+
|
|
340
|
+
f.writeRun('T-002',[...f.targets]);f.writeBootstrap(selection);
|
|
341
|
+
// Missing answers are refused before the T-002 run exists.
|
|
342
|
+
assertRefusedBeforeLaunch(f,f.drive(f.plan('T-002','create',[...rulesPermissions,...review]),'advance'),/init-generate\.json/);
|
|
343
|
+
// Attempt 1 records a real lesson: the host writes it back into AGENTS.md after the rules.
|
|
344
|
+
const lesson={status:'lesson_candidate',candidates:[{classification:'structured',trigger:'SwiftUI rules bootstrap',
|
|
345
|
+
action:'Keep scripts/verify.sh as the structure check',evidence:['scripts/verify.sh']}],reason:null};
|
|
346
|
+
const first=prepareRules(f,1,{retrospective:lesson});
|
|
347
|
+
// Every target except AGENTS.md (which also carries the written-back lesson) matches the draft.
|
|
348
|
+
const matches=(docs)=>{for(const file of f.targets)if(file==='AGENTS.md'){
|
|
349
|
+
assert(read(f,file).startsWith(docs[file]),file);assert.match(read(f,file),/## 项目教训[\s\S]*Keep scripts\/verify\.sh/);}
|
|
350
|
+
else assert.equal(read(f,file),docs[file],file);};
|
|
351
|
+
run=f.drive(f.plan('T-002','create',[...rulesPermissions,...review]),'advance');
|
|
352
|
+
assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'awaiting_review',run.stdout);
|
|
353
|
+
assert.match(run.stderr,/应答 init_generate/);assert.match(run.stderr,/应答 init_verify/);assert.match(run.stderr,/应答 check/);
|
|
354
|
+
assert.doesNotMatch(run.stderr,/应答 develop/);
|
|
355
|
+
matches(first);
|
|
356
|
+
const waiting=result(run).packageDigest,state=path.join(f.store('T-002'),'state.json');
|
|
357
|
+
// Review may lead straight into attempt 2 inside this advance: the revision must wait for findings.
|
|
358
|
+
let before=fs.readFileSync(state);
|
|
359
|
+
run=f.drive(f.plan('T-002','resume',[...rulesPermissions,...review,'--allow-review-attempt','1']),'advance');
|
|
360
|
+
assert.equal(run.status,2,run.stderr);
|
|
361
|
+
assert.match(run.stderr,new RegExp(`须在读取首轮审查 findings 之后编写:请先以 decision 和当前 packageDigest ${waiting}.*bootstrap-T-002-r1\\.md`));
|
|
362
|
+
assert.deepEqual(fs.readFileSync(state),before);
|
|
363
|
+
run=f.drive(f.plan('T-002','resume',[...rulesPermissions,...review,'--allow-review-attempt','1'],{packageDigest:waiting}),'decision');
|
|
364
|
+
assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'changes_requested');
|
|
365
|
+
assert(fs.existsSync(path.join(f.specsDir,'.reviews','bootstrap-T-002-r1.md')));
|
|
366
|
+
|
|
367
|
+
before=fs.readFileSync(state);
|
|
368
|
+
const again=()=>f.drive(f.plan('T-002','resume',[...rulesPermissions,...review]),'advance');
|
|
369
|
+
run=again();assert.equal(run.status,2,run.stderr);
|
|
370
|
+
assert.match(run.stderr,/第 2 轮规范修订,但答案文件不存在: .*init-generate-a2\.json.*bootstrap-T-002-r1\.md/);
|
|
371
|
+
assert.deepEqual(fs.readFileSync(state),before);
|
|
372
|
+
// The revision must keep the AGENTS.md that attempt 1 wrote; refused before launch.
|
|
373
|
+
prepareRules(f,2,{agents:'# AITide rewritten\n'});
|
|
374
|
+
run=again();assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/init-generate-a2\.json 的 AGENTS\.md 必须逐字保留/);
|
|
375
|
+
assert.deepEqual(fs.readFileSync(state),before);
|
|
376
|
+
// A resume the host itself refuses to open (other session, other runtime) runs no command.
|
|
377
|
+
const marker=path.join(f.root,'ran.marker');
|
|
378
|
+
prepareRules(f,2,{commands:[{id:'marker',command:['/bin/sh','-c',`echo ran > ${marker}`]}]});
|
|
379
|
+
for(const extra of [{hostContext:'another-session'},{runtime:'codex'}]){
|
|
380
|
+
run=f.drive(f.plan('T-002','resume',[...rulesPermissions,...review],extra),'advance');
|
|
381
|
+
assert.equal(run.status,1,run.stderr);assert.match(run.stderr,/fingerprint_mismatch/);
|
|
382
|
+
assert.doesNotMatch(run.stderr,/\[drive init_verify/);
|
|
383
|
+
assert.equal(fs.existsSync(marker),false);assert.deepEqual(fs.readFileSync(state),before);
|
|
384
|
+
}
|
|
385
|
+
// A failing attempt-2 command is refused before launch: the run stays changes_requested.
|
|
386
|
+
prepareRules(f,2,{commands:[{id:'strict',command:['/bin/sh','scripts/verify.sh','--strict'],timeoutMs:60000}]});
|
|
387
|
+
run=again();assert.equal(run.status,2,run.stderr);
|
|
388
|
+
assert.match(run.stderr,/init-verify-a2\.json 的命令在发送操作前实跑未通过:strict: failed(host check exited 1)。未发送操作,运行存档不变/);
|
|
389
|
+
assert.doesNotMatch(run.stderr,/应答 init_generate/);
|
|
390
|
+
assert.deepEqual(fs.readFileSync(state),before);
|
|
391
|
+
matches(first);
|
|
392
|
+
const second=prepareRules(f,2);
|
|
393
|
+
run=again();assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'awaiting_review',run.stdout);
|
|
394
|
+
assert.equal(result(run).identity.attempt,2);
|
|
395
|
+
matches(second);
|
|
396
|
+
assert.notEqual(second['.claude/rules/testing.md'],first['.claude/rules/testing.md']);
|
|
397
|
+
// The driver's decision request carries the run definition's attempt-1 identity;
|
|
398
|
+
// the second review runs inside advance with the attempt-2 review grant.
|
|
399
|
+
run=f.drive(f.plan('T-002','resume',[...rulesPermissions,...review,'--allow-review-attempt','2']),'advance');
|
|
400
|
+
assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'fixture_completed',run.stdout);
|
|
401
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,f.feature,'tasks.md'),'utf8'),/\[x\] T-002/);
|
|
402
|
+
const handoff=JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','bootstrap-T-002-a2-handoff.json'),'utf8'));
|
|
403
|
+
assert.deepEqual([...handoff.changed_files].sort(),[...f.targets].sort());
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test('a failing init_verify command really runs after the host accepts the launch and before any operation',
|
|
407
|
+
{skip:process.platform!=='darwin',timeout:120000},t=>{
|
|
408
|
+
const f=fixture(t,{scaffolded:true});f.writeRun('T-002',[...f.targets]);f.writeBootstrap(selection);
|
|
409
|
+
f.writeRun('T-001',Object.keys(scaffold));reviewFixture(f);
|
|
410
|
+
const permissions=[...rulesPermissions,'--review-config','review.json'];
|
|
411
|
+
// The session's semantic groups say verified; only the real command decides the commands group.
|
|
412
|
+
fs.writeFileSync(path.join(f.codeProject,'scripts/verify.sh'),'echo strict-check-ran >&2\n'+scaffold['scripts/verify.sh']);
|
|
413
|
+
prepareRules(f,1,{commands:[{id:'strict',command:['/bin/sh','scripts/verify.sh','--strict'],timeoutMs:60000}]});
|
|
414
|
+
const failed=f.drive(f.plan('T-002','create',permissions),'advance');
|
|
415
|
+
assert.equal(failed.status,2,failed.stderr);
|
|
416
|
+
assert.match(failed.stderr,/init-verify\.json 的命令在发送操作前实跑未通过:strict: failed(host check exited 1)/);
|
|
417
|
+
assert.match(failed.stderr,/PLAN\.mode 改为 resume/);
|
|
418
|
+
assert.match(failed.stderr,/\[drive init_verify strict stderr\] strict-check-ran/);
|
|
419
|
+
assert.doesNotMatch(failed.stderr,/应答 init_generate/);
|
|
420
|
+
assertReadyWithoutEffect(f,'T-002');
|
|
421
|
+
assert.equal(fs.existsSync(path.join(f.codeProject,'AGENTS.md')),false);
|
|
422
|
+
assert.equal(fs.existsSync(path.join(f.codeProject,'.claude')),false);
|
|
423
|
+
// Fix the draft's command list; the host-created ready run then advances on resume.
|
|
424
|
+
const contents=prepareRules(f,1);
|
|
425
|
+
const fixed=f.drive(f.plan('T-002','resume',permissions),'advance');
|
|
426
|
+
assert.equal(fixed.status,0,fixed.stderr);assert.equal(result(fixed).state,'awaiting_review',fixed.stdout);
|
|
427
|
+
assert.match(fixed.stderr,/\[drive init_verify verify /);
|
|
428
|
+
for(const file of f.targets)assert.equal(read(f,file),contents[file],file);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
test('rules written by this run survive a failed task check: fix the environment, advance again, reach review',
|
|
432
|
+
{skip:process.platform!=='darwin',timeout:180000},t=>{
|
|
433
|
+
const f=fixture(t,{scaffolded:true});f.writeRun('T-002',[...f.targets]);f.writeBootstrap(selection);
|
|
434
|
+
f.writeRun('T-001',Object.keys(scaffold));reviewFixture(f,{revise:false});
|
|
435
|
+
const permissions=[...rulesPermissions,'--review-config','review.json'];
|
|
436
|
+
// The task check depends on an environment marker outside the code root.
|
|
437
|
+
const checks=[{id:'environment',command:['/bin/sh','-c','test -f ../environment.ready']}];
|
|
438
|
+
const contents=prepareRules(f,1);
|
|
439
|
+
let run=f.drive(f.plan('T-002','create',permissions,{checks}),'advance');
|
|
440
|
+
assert.equal(run.status,0,run.stderr);
|
|
441
|
+
assert.equal(result(run).state,'blocked',run.stdout);assert.equal(result(run).code,'develop_checks_not_passed');
|
|
442
|
+
assert.equal(result(run).pendingAction,'resume');
|
|
443
|
+
for(const file of f.targets)assert.equal(read(f,file),contents[file],file);
|
|
444
|
+
// Rules edited by someone else after this run wrote them are refused before launch.
|
|
445
|
+
const state=path.join(f.store('T-002'),'state.json'),before=fs.readFileSync(state);
|
|
446
|
+
fs.appendFileSync(path.join(f.codeProject,'.claude/rules/security.md'),'foreign edit\n');
|
|
447
|
+
run=f.drive(f.plan('T-002','resume',permissions,{checks}),'advance');
|
|
448
|
+
assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/\.claude\/rules\/security\.md 与本运行已记录的写入不一致/);
|
|
449
|
+
assert.deepEqual(fs.readFileSync(state),before);
|
|
450
|
+
fs.writeFileSync(path.join(f.codeProject,'.claude/rules/security.md'),contents['.claude/rules/security.md']);
|
|
451
|
+
// The rules effect only enters the admitted next task (host-bootstrap.mjs run()).
|
|
452
|
+
const tasks=path.join(f.specsDir,f.feature,'tasks.md'),taskList=fs.readFileSync(tasks,'utf8');
|
|
453
|
+
fs.writeFileSync(tasks,taskList.replace('[ ] T-002','[x] T-002'));
|
|
454
|
+
run=f.drive(f.plan('T-002','resume',permissions,{checks}),'advance');
|
|
455
|
+
assert.equal(run.status,2,run.stderr);
|
|
456
|
+
assert.match(run.stderr,/T-002 不是当前可进入的 bootstrap 任务(nextTask 无,宿主以 bootstrap_task_required 拒绝);驾驶员不运行 init-verify 命令/);
|
|
457
|
+
assert.deepEqual(fs.readFileSync(state),before);
|
|
458
|
+
fs.writeFileSync(tasks,taskList);
|
|
459
|
+
fs.writeFileSync(path.join(f.root,'environment.ready'),'ok\n');
|
|
460
|
+
run=f.drive(f.plan('T-002','resume',permissions,{checks}),'advance');
|
|
461
|
+
assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'awaiting_review',run.stdout);
|
|
462
|
+
assert.equal(result(run).identity.attempt,1);
|
|
463
|
+
for(const file of f.targets)assert.equal(read(f,file),contents[file],file);
|
|
464
|
+
run=f.drive(f.plan('T-002','resume',[...permissions,'--allow-review-attempt','1'],{checks,packageDigest:result(run).packageDigest}),'decision');
|
|
465
|
+
assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'approved',run.stdout);
|
|
466
|
+
run=f.drive(f.plan('T-002','resume',permissions,{checks}),'advance');
|
|
467
|
+
assert.equal(run.status,0,run.stderr);assert.equal(result(run).state,'fixture_completed',run.stdout);
|
|
468
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import {planCheckTimeout} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
4
|
+
|
|
5
|
+
test('D1 driver check timeout defaults to 15 minutes and item override wins',()=>{
|
|
6
|
+
assert.equal(planCheckTimeout({}),900000);
|
|
7
|
+
assert.equal(planCheckTimeout({checkTimeoutMs:70000}),70000);
|
|
8
|
+
assert.equal(planCheckTimeout({checkTimeoutMs:1000},{timeoutMs:65000}),65000);
|
|
9
|
+
assert.equal(planCheckTimeout({},{timeoutMs:3600000}),3600000);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('D1 driver rejects invalid plan and item timeouts before dispatch',()=>{
|
|
13
|
+
for(const value of [0,3600001,1.5,null,'65000']){
|
|
14
|
+
assert.throws(()=>planCheckTimeout({checkTimeoutMs:value}),/checkTimeoutMs/);
|
|
15
|
+
assert.throws(()=>planCheckTimeout({},{timeoutMs:value}),/timeoutMs/);
|
|
16
|
+
}
|
|
17
|
+
});
|