@aibyzero/cm-workflow 0.16.5 → 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 +14 -0
- package/CHANGELOG.md +7 -0
- package/README.md +11 -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 +28 -7
- package/docs/js-workflow-control.md +48 -0
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- 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/claude-review-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +79 -20
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +1 -4
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +13 -57
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +34 -15
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +20 -10
- package/runtime/js/cm-ai/drive-core.mjs +9 -3
- package/runtime/js/cm-ai/durable-runner-state.mjs +117 -14
- package/runtime/js/cm-ai/effect-contract.mjs +1 -1
- package/runtime/js/cm-ai/execution-policy.mjs +58 -0
- 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/host-bootstrap.mjs +70 -20
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +50 -16
- 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 +2 -2
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +22 -5
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +3 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -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/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/provider-review-observation.mjs +15 -0
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- package/runtime/js/cm-ai/review-package.mjs +11 -0
- 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/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-runner.mjs +171 -25
- 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 +183 -40
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/host-review.mjs +25 -6
- package/runtime/js/cm-fix/host.mjs +4 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/progress.mjs +4 -0
- package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
- package/runtime/js/cm-prd/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-publication.mjs +23 -13
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- package/scripts/cm-ai-batch-drive.mjs +50 -21
- package/scripts/cm-ai-batch-drive.test.mjs +47 -2
- package/scripts/cm-ai-batch-host.mjs +37 -14
- package/scripts/cm-ai-batch-run.mjs +71 -27
- package/scripts/cm-ai-bootstrap-flow.test.mjs +3 -2
- package/scripts/cm-ai-bootstrap-merge.test.mjs +118 -1
- package/scripts/cm-ai-bootstrap.test.mjs +80 -87
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +15 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +102 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +2 -2
- package/scripts/cm-ai-drive.mjs +59 -25
- package/scripts/cm-ai-drive.test.mjs +97 -1
- package/scripts/cm-ai-host.mjs +64 -24
- package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +21 -0
- package/scripts/cm-ai-review-failure.test.mjs +71 -11
- package/scripts/cm-ai-run.mjs +58 -14
- package/scripts/cm-ai-run.test.mjs +2 -1
- package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-check-drive.test.mjs +1 -0
- package/scripts/cm-check-runtime.sh +11 -0
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +1 -1
- 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-fix-drive.mjs +28 -13
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +17 -10
- 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 +7 -1
- package/scripts/cm-host-qa-executor.test.mjs +21 -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 +8 -2
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +13 -4
- package/scripts/cm-release-smoke.sh +5 -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-task-gate-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +146 -10
- package/scripts/cm-task-gate.py +1 -0
- 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/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +3 -1
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +10 -1
- package/skills/cm-ai/SKILL.md +2 -2
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +13 -5
- 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 +30 -2
- 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,64 @@
|
|
|
1
|
+
import test 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 {createLiveEvidence} from '../runtime/js/cm-ai/live-evidence.mjs';
|
|
7
|
+
|
|
8
|
+
function fixture(t){
|
|
9
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-live-evidence-')));
|
|
10
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
11
|
+
const project=path.join(root,'project');fs.mkdirSync(project);
|
|
12
|
+
return {root,project,directory:path.join(root,'exchange')};
|
|
13
|
+
}
|
|
14
|
+
const row={type:'host_request',sessionId:'session-a',callId:'call-a',requestDigest:'a'.repeat(64),kind:'qa_logic',payload:{case:{id:'TC-001'}}};
|
|
15
|
+
test('fresh live request accepts only its session/call/digest and leaves request evidence',async t=>{
|
|
16
|
+
const f=fixture(t);let requestPath;
|
|
17
|
+
const live=createLiveEvidence({directory:f.directory,kinds:['qa_logic'],timeoutMs:1000},{base:f.root,protectedRoots:[f.project],
|
|
18
|
+
notify:p=>{requestPath=p;const request=JSON.parse(fs.readFileSync(p));
|
|
19
|
+
fs.writeFileSync(p.replace('.request.json','.result.json'),JSON.stringify({type:'host_result',sessionId:request.sessionId,
|
|
20
|
+
callId:request.callId,requestDigest:request.requestDigest,result:{verdict:'SUPPORTED',evidence:['observed']}}));}});
|
|
21
|
+
const result=await live.answer(row);
|
|
22
|
+
assert.equal(result.verdict,'SUPPORTED');assert.ok(fs.existsSync(requestPath));
|
|
23
|
+
assert.equal(fs.statSync(path.dirname(requestPath)).mode&0o777,0o700);
|
|
24
|
+
assert.equal(await live.answer({...row,kind:'check'}),null);
|
|
25
|
+
});
|
|
26
|
+
test('stale reply is refused rather than rebound to the current request',async t=>{
|
|
27
|
+
const f=fixture(t);const live=createLiveEvidence({directory:f.directory,kinds:['qa_logic'],timeoutMs:1000},
|
|
28
|
+
{base:f.root,protectedRoots:[f.project],notify:p=>fs.writeFileSync(p.replace('.request.json','.result.json'),
|
|
29
|
+
JSON.stringify({type:'host_result',sessionId:'old-session',callId:row.callId,requestDigest:row.requestDigest,result:{verdict:'PASS'}}))});
|
|
30
|
+
await assert.rejects(live.answer(row),/live_evidence_binding_mismatch/);
|
|
31
|
+
});
|
|
32
|
+
test('no response times out and cancellation interrupts the wait',async t=>{
|
|
33
|
+
const f=fixture(t);const live=createLiveEvidence({directory:f.directory,kinds:['qa_logic'],timeoutMs:30},
|
|
34
|
+
{base:f.root,protectedRoots:[f.project],notify:()=>{}});
|
|
35
|
+
await assert.rejects(live.answer(row),/live_evidence_timeout/);
|
|
36
|
+
const controller=new AbortController();controller.abort();
|
|
37
|
+
await assert.rejects(live.answer({...row,callId:'call-b'},{signal:controller.signal}),/live_evidence_cancelled/);
|
|
38
|
+
});
|
|
39
|
+
test('preflight refuses protected trees, symlinks, unknown kinds and malformed settings',t=>{
|
|
40
|
+
const f=fixture(t),options={base:f.root,protectedRoots:[f.project]};
|
|
41
|
+
fs.symlinkSync(f.project,path.join(f.root,'linked'));
|
|
42
|
+
for(const config of [{directory:f.project,kinds:['qa_logic']},{directory:path.join(f.project,'exchange'),kinds:['qa_logic']},
|
|
43
|
+
{directory:path.join(f.root,'linked','exchange'),kinds:['qa_logic']},{directory:f.directory,kinds:['develop']},
|
|
44
|
+
{directory:f.directory,kinds:['qa_logic'],timeoutMs:0},{directory:f.directory,kinds:['qa_logic'],extra:true}])
|
|
45
|
+
assert.throws(()=>createLiveEvidence(config,options),/live_evidence_/);
|
|
46
|
+
});
|
|
47
|
+
for(const bad of ['symlink','oversize','malformed'])test(`live result refuses ${bad} rather than claiming execution`,async t=>{
|
|
48
|
+
const f=fixture(t);const live=createLiveEvidence({directory:f.directory,kinds:['qa_logic'],timeoutMs:1000},
|
|
49
|
+
{base:f.root,protectedRoots:[f.project],maxBytes:100,notify:file=>{
|
|
50
|
+
const target=file.replace('.request.json','.result.json');
|
|
51
|
+
if(bad==='symlink')fs.symlinkSync(file,target);
|
|
52
|
+
else fs.writeFileSync(target,bad==='oversize'?'x'.repeat(101):'{');
|
|
53
|
+
}});
|
|
54
|
+
await assert.rejects(live.answer(row),bad==='malformed'?/live_evidence_invalid_json/:/live_evidence_unsafe_result|ELOOP/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('future parallel worktree roots are protected before they exist, including an aliased parent',t=>{
|
|
58
|
+
const f=fixture(t),future=path.join(f.root,'.cm-worktrees');
|
|
59
|
+
assert.throws(()=>createLiveEvidence({directory:path.join(future,'run','exchange'),kinds:['qa_logic']},
|
|
60
|
+
{protectedRoots:[future]}),/live_evidence_protected_directory/);
|
|
61
|
+
const alias=path.join(f.root,'alias');fs.symlinkSync(f.root,alias);
|
|
62
|
+
assert.throws(()=>createLiveEvidence({directory:path.join(future,'run','exchange'),kinds:['qa_logic']},
|
|
63
|
+
{protectedRoots:[path.join(alias,'.cm-worktrees')]}),/live_evidence_protected_directory/);
|
|
64
|
+
});
|
package/scripts/cm-log-event.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import fs from 'node:fs';
|
|
|
5
5
|
import os from 'node:os';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {statusProjectionCommand} from '../runtime/js/cm-ai/status-projection.mjs';
|
|
8
9
|
|
|
9
10
|
const IDENTIFIER=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/;
|
|
10
11
|
const RESOURCE_ID=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
@@ -20,7 +21,7 @@ export const RESOURCE_GUARDED_EVENTS=new Set([...TERMINAL_EVENTS,'task_done']);
|
|
|
20
21
|
const RESOURCE_PHASES=new Set(['acquired','released','cleanup_failed']);
|
|
21
22
|
const TEST_RUN_GUARDED_EVENTS=new Set([...TERMINAL_EVENTS,'task_done']);
|
|
22
23
|
const TEST_RUN_PHASES=new Set(['start','case_start','case_complete','case_blocked','complete','abandoned','superseded']);
|
|
23
|
-
const MODEL_USAGE_TOKEN_FIELDS=new Set(['input_tokens','output_tokens','cache_read_tokens','cache_write_tokens']);
|
|
24
|
+
const MODEL_USAGE_TOKEN_FIELDS=new Set(['input_tokens','output_tokens','cache_read_tokens','cache_write_tokens','reasoning_tokens']);
|
|
24
25
|
const MODEL_USAGE_STATES=new Set(['observed','unavailable']);
|
|
25
26
|
const MODEL_USAGE_OUTCOMES=new Set(['success','error','blocked','cancelled']);
|
|
26
27
|
const MODEL_USAGE_ALLOWED_FIELDS=new Set([...MODEL_USAGE_TOKEN_FIELDS,'call_id','role','adapter','requested_model',
|
|
@@ -90,6 +91,7 @@ function validateModelUsageEvent(event,phase,data){
|
|
|
90
91
|
throw new UsageError('unavailable model_usage cannot contain token counts');
|
|
91
92
|
if(data.usage_state==='observed')for(const field of ['input_tokens','output_tokens'])
|
|
92
93
|
if(!Object.hasOwn(data,field))throw new UsageError(`observed model_usage requires ${field}`);
|
|
94
|
+
if(Object.hasOwn(data,'reasoning_tokens')&&data.reasoning_tokens>data.output_tokens)throw new UsageError('reasoning_tokens must be an output subset');
|
|
93
95
|
for(const field of [...MODEL_USAGE_TOKEN_FIELDS,'duration_ms'])if(Object.hasOwn(data,field)){
|
|
94
96
|
const value=data[field];
|
|
95
97
|
if(!Number.isInteger(value)||value<0)throw new UsageError(`model_usage ${field} must be a non-negative integer`);
|
|
@@ -493,7 +495,7 @@ export function writeLogEvent(rawInput,{environment=process.env,now=new Date(),u
|
|
|
493
495
|
if(existingUsage!==null&&existingUsage.event_id!==event.event_id)
|
|
494
496
|
throw new UsageError('model_usage call_id already used with different payload');
|
|
495
497
|
const existingClaim=findModelEvent(authoritativeLog,built.runId,'model_call',event.call_id);
|
|
496
|
-
if(event.adapter==='openai-compatible'&&existingClaim===null)
|
|
498
|
+
if((event.adapter==='openai-compatible'||event.source==='native-cli-terminal')&&existingClaim===null)
|
|
497
499
|
throw new UsageError('managed model_usage requires a prior model_call claim');
|
|
498
500
|
if(existingClaim!==null&&modelCallIdentity(existingClaim).some((value,index)=>value!==modelCallIdentity(event)[index]))
|
|
499
501
|
throw new UsageError('model_usage identity does not match model_call claim');
|
|
@@ -601,6 +603,10 @@ function usage(){return 'usage: cm-log-event.py --workflow NAME --event NAME --r
|
|
|
601
603
|
|
|
602
604
|
export function main(argv=process.argv.slice(2),environment=process.env){
|
|
603
605
|
try{
|
|
606
|
+
if(argv[0]==='--status-only'){
|
|
607
|
+
const result=statusProjectionCommand(argv,environment);
|
|
608
|
+
if(result!==null)process.stdout.write(`${asciiJson(result)}\n`);return 0;
|
|
609
|
+
}
|
|
604
610
|
const input=parseCli(argv);if(input.help){process.stdout.write(`${usage()}\n`);return 0;}
|
|
605
611
|
if(environment.CM_LOG_PREFLIGHT==='1'){prepareInput(input);return 0;}
|
|
606
612
|
const result=writeLogEvent(input,{environment});process.stdout.write(`${asciiJson(result)}\n`);return 0;
|
package/scripts/cm-log-event.py
CHANGED
|
@@ -73,6 +73,7 @@ def run_node(entry: Path, arguments: List[str], environment: dict) -> int:
|
|
|
73
73
|
|
|
74
74
|
def main() -> int:
|
|
75
75
|
arguments = sys.argv[1:]
|
|
76
|
+
status_only = arguments[:1] == ["--status-only"]
|
|
76
77
|
entry = Path(__file__).resolve().with_name("cm-log-event.mjs")
|
|
77
78
|
|
|
78
79
|
if "--help" in arguments or "-h" in arguments:
|
|
@@ -92,6 +93,10 @@ def main() -> int:
|
|
|
92
93
|
)
|
|
93
94
|
if specs_dir is not None:
|
|
94
95
|
try:
|
|
96
|
+
if status_only:
|
|
97
|
+
lock = specs_dir / ".cm-run.lock"
|
|
98
|
+
if lock.is_symlink() or (lock.exists() and (not lock.is_file() or lock.stat().st_nlink != 1)):
|
|
99
|
+
raise OSError("invalid status lock")
|
|
95
100
|
acquire_file_lock(specs_dir / ".cm-run.lock", private=False)
|
|
96
101
|
except OSError as error:
|
|
97
102
|
print(
|
|
@@ -100,6 +105,16 @@ def main() -> int:
|
|
|
100
105
|
)
|
|
101
106
|
return 1
|
|
102
107
|
|
|
108
|
+
# Status is a projection, not a log event. Reuse the project lock, including
|
|
109
|
+
# its automatic release on process exit; do not touch the global mirror or
|
|
110
|
+
# active-run pointer for a display-only write.
|
|
111
|
+
if status_only:
|
|
112
|
+
environment = os.environ.copy()
|
|
113
|
+
environment["CM_LOG_LOCK_ADAPTER"] = "1"
|
|
114
|
+
environment["CM_LOG_LOCK_PARENT_PID"] = str(os.getpid())
|
|
115
|
+
environment["CM_LOG_PROJECT_LOCK"] = str(specs_dir / ".cm-run.lock")
|
|
116
|
+
return run_node(entry, arguments, environment)
|
|
117
|
+
|
|
103
118
|
global_home = Path(
|
|
104
119
|
os.environ.get("CM_WORKFLOW_LOG_HOME", "~/.cm-workflow/logs")
|
|
105
120
|
).expanduser().resolve(strict=False)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// External providers only. No role picker, model catalog or background discovery.
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {fileURLToPath} from 'node:url';
|
|
5
|
+
import readline from 'node:readline/promises';
|
|
6
|
+
import {externalModelsPath,externalSettingsRecord,externalPair,readExternalModels,saveExternalModels,describeExternalModels} from '../runtime/js/cm-ai/external-models.mjs';
|
|
7
|
+
import {readModelJsonRecord} from '../runtime/js/cm-ai/model-configuration-file.mjs';
|
|
8
|
+
import {previewLegacyExternalModels} from '../runtime/js/cm-ai/legacy-model-settings.mjs';
|
|
9
|
+
import {need} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
10
|
+
import {previewLegacyModelRun} from '../runtime/js/cm-ai/legacy-model-run-preview.mjs';
|
|
11
|
+
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
12
|
+
import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
13
|
+
const usage=`cm-model-setup.mjs show
|
|
14
|
+
cm-model-setup.mjs configure --provider codex|claude [--model ID] [--effort VALUE|default] [--yes]
|
|
15
|
+
cm-model-setup.mjs legacy-preview --input OLD_SETTINGS [--task OLD_TASK] [--project OLD_PROJECT] [--global OLD_GLOBAL]
|
|
16
|
+
cm-model-setup.mjs inspect-run --input RUN_JSON
|
|
17
|
+
cm-model-setup.mjs legacy-run-preview --input OLD_SNAPSHOT
|
|
18
|
+
cm-model-setup.mjs adopt-legacy --provider codex|claude --input OLD_SETTINGS [--task OLD_TASK] [--project OLD_PROJECT] [--global OLD_GLOBAL] [--yes]
|
|
19
|
+
Only external CLI requests are configured. Host work keeps the current session model.
|
|
20
|
+
No model is selected by default; optional effort keeps Codex high / Claude unsent.
|
|
21
|
+
Old choices and runs are never rewritten. Conflicting effective old tuples require configure.`;
|
|
22
|
+
export async function main(argv,{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
23
|
+
let rl;
|
|
24
|
+
try{
|
|
25
|
+
if(argv.length===0||argv[0]==='--help'){output.write(usage+'\n');return 0;}
|
|
26
|
+
const [action,...rest]=argv,flags=new Map();
|
|
27
|
+
for(let i=0;i<rest.length;i++){
|
|
28
|
+
const flag=rest[i];need(!flags.has(flag),'invalid_arguments');
|
|
29
|
+
need(['--provider','--model','--effort','--yes','--input','--task','--project','--global'].includes(flag),'invalid_arguments');
|
|
30
|
+
if(flag==='--yes')flags.set(flag,true);
|
|
31
|
+
else{need(typeof rest[i+1]==='string'&&!rest[i+1].startsWith('--'),'invalid_arguments');flags.set(flag,rest[++i]);}
|
|
32
|
+
}
|
|
33
|
+
if(['inspect-run','legacy-run-preview'].includes(action)){
|
|
34
|
+
need(flags.size===1&&flags.has('--input'),'invalid_arguments');
|
|
35
|
+
const raw=readModelJsonRecord(path.resolve(flags.get('--input'))).value;
|
|
36
|
+
if(action==='legacy-run-preview'){output.write(JSON.stringify(previewLegacyModelRun(raw))+'\n');return 0;}
|
|
37
|
+
const {readRunDefinition}=await import('./cm-ai-run.mjs');
|
|
38
|
+
// Definition validation is the same as the runner, without acquiring a writer.
|
|
39
|
+
const definition=readRunDefinition(path.resolve(flags.get('--input')));
|
|
40
|
+
const snapshot=readExecutionSnapshot({specsRoot:definition.specsDir,identity:{repositoryId:definition.identity.repositoryId,runId:definition.identity.runId}});
|
|
41
|
+
const init=snapshot.records[0].payload,history=readRunnerHistory(snapshot.records,init.config,init.version);
|
|
42
|
+
output.write(JSON.stringify({readOnly:true,identity:{...init.config.identity,attempt:history.state.attempt},state:history.state.state,
|
|
43
|
+
externalModels:init.config.externalModels??null,revision:snapshot.revision,
|
|
44
|
+
attempts:snapshot.records.filter(row=>row.payload.type.startsWith('review-invocation-')).map(row=>row.payload),
|
|
45
|
+
effectiveModel:'unknown',providerConfirmed:false})+'\n');return 0;
|
|
46
|
+
}
|
|
47
|
+
const file=externalModelsPath(),record=externalSettingsRecord(file);
|
|
48
|
+
const value=record?readExternalModels(record.value):{schemaVersion:1,providers:{}};
|
|
49
|
+
if(action==='show'){need(flags.size===0,'invalid_arguments');output.write(JSON.stringify(describeExternalModels(value))+'\n');return 0;}
|
|
50
|
+
let legacy=null,guards=[];
|
|
51
|
+
if(['legacy-preview','adopt-legacy'].includes(action)){
|
|
52
|
+
need(flags.has('--input')&&!flags.has('--model')&&!flags.has('--effort'),'invalid_arguments');
|
|
53
|
+
const read=flag=>{if(!flags.has(flag))return null;const name=path.resolve(flags.get(flag)),old=readModelJsonRecord(name);guards.push({file:name,sha256:old.sha256});return old.value;};
|
|
54
|
+
legacy=previewLegacyExternalModels({settings:read('--input'),task:read('--task'),project:read('--project'),global:read('--global')});
|
|
55
|
+
if(action==='legacy-preview'){need(!flags.has('--provider')&&!flags.has('--yes'),'invalid_arguments');output.write(JSON.stringify({readOnly:true,providers:legacy})+'\n');return 0;}
|
|
56
|
+
}else need(action==='configure'&&![...flags.keys()].some(flag=>['--input','--task','--project','--global'].includes(flag)),'invalid_arguments');
|
|
57
|
+
const provider=flags.get('--provider');need(['codex','claude'].includes(provider),'invalid_external_provider');
|
|
58
|
+
const ask=async text=>{need(input.isTTY===true&&output.isTTY===true,'external_model_setup_required');rl??=readline.createInterface({input,output});return rl.question(text);};
|
|
59
|
+
let pair;
|
|
60
|
+
if(legacy){need(!legacy[provider].conflict,'legacy_external_model_conflict');
|
|
61
|
+
need(guards.length===1&&path.dirname(guards[0].file)===path.dirname(file),'legacy_adoption_requires_explicit_choice');pair=legacy[provider].pair;}
|
|
62
|
+
else{
|
|
63
|
+
const model=flags.get('--model')??(await ask(`${provider} external model ID: `)).trim();
|
|
64
|
+
let effort=flags.get('--effort');
|
|
65
|
+
if(!flags.has('--model')&&effort===undefined)effort=(await ask('Effort (Enter = adapter default): ')).trim()||'default';
|
|
66
|
+
pair=externalPair(provider,{model,...(effort===undefined||effort==='default'?{}:{effort})});
|
|
67
|
+
}
|
|
68
|
+
const next=readExternalModels({...value,providers:{...value.providers,[provider]:pair}});
|
|
69
|
+
output.write(JSON.stringify({provider,pair,affects:'new external runs only',host:'current-session',file})+'\n');
|
|
70
|
+
if(!flags.has('--yes')&&!/^(y|yes)$/i.test((await ask('Save this provider pair? [y/N] ')).trim())){output.write('cancelled; no write\n');return 0;}
|
|
71
|
+
// Bind both target and each legacy source to the bytes shown before waiting.
|
|
72
|
+
for(const guard of guards)need(readModelJsonRecord(guard.file).sha256===guard.sha256,'model_configuration_changed');
|
|
73
|
+
saveExternalModels(next,{file,expectedSha256:record?.sha256??null,
|
|
74
|
+
sourceGuard:guards.length===1?guards[0]:null});
|
|
75
|
+
output.write('saved\n');return 0;
|
|
76
|
+
}catch(cause){error.write(JSON.stringify({error:{code:cause.code??cause.message}})+'\n');return 1;}
|
|
77
|
+
finally{if(rl){rl.close();input.pause();input.unref?.();}}
|
|
78
|
+
}
|
|
79
|
+
if(process.argv[1]===fileURLToPath(import.meta.url))process.exitCode=await main(process.argv.slice(2));
|
package/scripts/cm-prd-drive.mjs
CHANGED
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
// prd_materials needs PDF/browser observation; this driver has no such runner and refuses it.
|
|
25
25
|
// prd_self_check evidence comes from actual PLAN.contextChecks commands, never a static evidence file.
|
|
26
26
|
import fs from 'node:fs';
|
|
27
|
+
import {readPrdRepairBinding,recoverPrdResponse} from '../runtime/js/cm-prd/response-recovery.mjs';
|
|
28
|
+
import {inspectPrdReviewResponse} from '../runtime/js/cm-prd/review-publication.mjs';
|
|
27
29
|
import path from 'node:path';
|
|
28
30
|
import {fileURLToPath} from 'node:url';
|
|
29
31
|
import {createHash} from 'node:crypto';
|
|
@@ -42,10 +44,12 @@ import {inspectPrdSummaryEvidence} from '../runtime/js/cm-prd/summary.mjs';
|
|
|
42
44
|
import {prdDesignRiskSignals} from '../runtime/js/cm-prd/design-risk.mjs';
|
|
43
45
|
import {reviewResultForPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
44
46
|
import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
47
|
+
import {driverLiveEvidence} from '../runtime/js/cm-ai/live-evidence.mjs';
|
|
45
48
|
|
|
49
|
+
// PLAN.liveEvidence: fresh current-session evidence; see docs/live-evidence-drivers.md.
|
|
46
50
|
const HOST=fileURLToPath(new URL('./cm-prd-host.mjs',import.meta.url));
|
|
47
51
|
const SKILL=fileURLToPath(new URL('../skills/cm-prd',import.meta.url));
|
|
48
|
-
const KNOWN=new Set(['start','advance','plan_design','promote_design','select_design_reviews','status','cancel',
|
|
52
|
+
const KNOWN=new Set(['repair_review_response','start','advance','plan_design','promote_design','select_design_reviews','status','cancel',
|
|
49
53
|
'final_review_package','final_review','review_findings','review_disposition','save_draft','save_design',
|
|
50
54
|
'correct_findings','prepare_summary','publish_summary','inspect_correction','resume_correction',
|
|
51
55
|
'prepare_revision','decision','resume','read_batch','replace_inputs']);
|
|
@@ -75,14 +79,14 @@ function load(){
|
|
|
75
79
|
catch(e){fail('准入或配置无效',e.code??e.message);}
|
|
76
80
|
if(admission.status!=='ready'&&!(plan.session&&admission.mode==='change'&&admission.reason==='feature_missing'))
|
|
77
81
|
fail('准入失败',admission.reason??admission.status);
|
|
78
|
-
if(!Array.isArray(plan.permissions??[])||!(plan.permissions??[]).every(p=>['--allow-spec-write','--allow-review-write','--allow-disposition-write'].includes(p)))
|
|
82
|
+
if(!Array.isArray(plan.permissions??[])||!(plan.permissions??[]).every(p=>['--execution-optimizations','--allow-spec-write','--allow-review-write','--allow-disposition-write'].includes(p)))
|
|
79
83
|
stop(2,'permissions 只能包含宿主支持的写入开关');
|
|
80
84
|
if(new Set(plan.permissions??[]).size!==(plan.permissions??[]).length)stop(2,'permissions 不可重复');
|
|
81
85
|
if(plan.predecessor&&!fs.existsSync(resolve(plan.predecessor)))stop(2,`predecessor 文件不存在: ${resolve(plan.predecessor)}`);
|
|
82
86
|
if(plan.permissions?.includes('--allow-review-write')&&!nonempty(plan.hostContext))stop(2,'--allow-review-write 需要 hostContext');
|
|
83
87
|
if(['save_draft','save_design','publish_summary','resume_correction','correct_findings'].includes(operation)
|
|
84
88
|
&&!plan.permissions?.includes('--allow-spec-write'))stop(2,`${operation} 需要 --allow-spec-write`);
|
|
85
|
-
if(
|
|
89
|
+
if(['final_review','repair_review_response'].includes(operation)&&!plan.permissions?.includes('--allow-review-write'))stop(2,'final_review 需要 --allow-review-write');
|
|
86
90
|
if(operation==='review_disposition'&&!plan.permissions?.includes('--allow-disposition-write'))stop(2,'review_disposition 需要 --allow-disposition-write');
|
|
87
91
|
if(['correct_findings','resume_correction'].includes(operation)&&!plan.permissions?.includes('--allow-review-write'))
|
|
88
92
|
stop(2,`${operation} 需要 --allow-review-write`);
|
|
@@ -96,20 +100,32 @@ function load(){
|
|
|
96
100
|
if(identity?.entry?.project!==project||identity.entry.specs!==specs||identity.entry.skillDir!==SKILL
|
|
97
101
|
||identity.entry.change!==entry.change||identity.entry.cases!==entry.cases||identity.runtime!==runtime)
|
|
98
102
|
stop(2,'恢复身份不匹配:project/specs/skillDir/change/cases/runtime');
|
|
99
|
-
if(state.active
|
|
103
|
+
if(state.active&&!['resume','repair_review_response'].includes(operation)&&!['status','read_batch','replace_inputs','cancel'].includes(operation))
|
|
100
104
|
stop(2,`待恢复操作 ${state.active.request.operation}:先用 resume`);
|
|
101
105
|
if(operation==='resume'&&!state.active)stop(2,'恢复存档没有待定操作');
|
|
102
106
|
}
|
|
103
107
|
const request=plan.request??{};
|
|
104
108
|
exact(request,['text','stage','feature','mode','packageDigest','decisions','artifacts','summaryDigest','draftDigest',
|
|
105
|
-
'risks','reason','proposalDigest','approved','allowUserCaseChanges','resolution','successorSpecs','successorSessionId'], 'PLAN.request');
|
|
106
|
-
const needed={start:['text'],advance:['text'],plan_design:['text'],promote_design:['draftDigest','reason'],
|
|
109
|
+
'risks','reason','proposalDigest','approved','allowUserCaseChanges','resolution','successorSpecs','successorSessionId','binding'], 'PLAN.request');
|
|
110
|
+
const needed={repair_review_response:['binding'],start:['text'],advance:['text'],plan_design:['text'],promote_design:['draftDigest','reason'],
|
|
107
111
|
select_design_reviews:['draftDigest','risks'],final_review_package:['stage','feature'],final_review:['stage','feature','mode'],
|
|
108
112
|
review_findings:['stage','feature'],review_disposition:['stage','feature','packageDigest','decisions','artifacts'],
|
|
109
113
|
correct_findings:['stage','feature'],inspect_correction:['stage','feature'],resume_correction:['stage','feature'],
|
|
110
114
|
publish_summary:['summaryDigest'],prepare_revision:['reason'],decision:['proposalDigest','approved','allowUserCaseChanges'],
|
|
111
115
|
replace_inputs:['approved','reason','successorSpecs','successorSessionId']};
|
|
112
116
|
for(const key of needed[operation]??[])if(!Object.hasOwn(request,key))stop(2,`${operation} 缺少 PLAN.request.${key}`);
|
|
117
|
+
if(operation==='repair_review_response'){
|
|
118
|
+
try{
|
|
119
|
+
const binding=readPrdRepairBinding(request.binding);
|
|
120
|
+
const call=state?.active?.calls?.find(item=>item.callId===binding.callId)
|
|
121
|
+
??state?.responseRepairs?.find(item=>item.originalCall.callId===binding.callId)?.originalCall;
|
|
122
|
+
check(state?.version===2&&call?.kind==='prd_review'&&Object.hasOwn(call,'result')
|
|
123
|
+
&&call.requestDigest===binding.requestDigest&&digest(call.result)===binding.resultDigest
|
|
124
|
+
&&call.payload.package.packageDigest===binding.packageDigest,'prd_recovery_binding');
|
|
125
|
+
const {packageDigest,...reviewPackage}=call.payload.package;
|
|
126
|
+
recoverPrdResponse({original:call.result,reviewPackage,packageDigest,authorContextId:call.payload.authorContextId});
|
|
127
|
+
}catch(error){fail('原响应修复预检失败',error.code??error.message);}
|
|
128
|
+
}
|
|
113
129
|
if(['review_disposition','correct_findings'].includes(operation)){
|
|
114
130
|
let review;try{review=inspectPrdFindings({specs,stage:request.stage,feature:request.feature});}
|
|
115
131
|
catch(e){fail('原审查记录无效',e.code??e.message);}
|
|
@@ -161,7 +177,10 @@ function load(){
|
|
|
161
177
|
const pending=state.active.calls.find(c=>!Object.hasOwn(c,'result'));
|
|
162
178
|
if(pending)stop(2,`resume 尚缺原调用结果:${pending.kind} ${pending.callId} ${pending.requestDigest}`);
|
|
163
179
|
}
|
|
164
|
-
|
|
180
|
+
let live;
|
|
181
|
+
try{live=driverLiveEvidence(plan,{base,protectedRoots:[project,specs],allowedKinds:['prd_materials']});}
|
|
182
|
+
catch(error){stop(2,error.message);}
|
|
183
|
+
if(asks.includes('prd_materials')&&!live.has('prd_materials'))stop(2,'缺少真实执行 runner: prd_materials(PDF/HTML 读取或浏览器交互);不能从静态答案文件应答');
|
|
165
184
|
const answersRoot=plan.answers?resolve(plan.answers):null;
|
|
166
185
|
if(answersRoot&&fs.existsSync(path.join(answersRoot,'materials.json')))
|
|
167
186
|
stop(2,'materials.json 是执行证据;不能从静态答案文件应答 prd_materials');
|
|
@@ -195,7 +214,7 @@ function load(){
|
|
|
195
214
|
if(answersRoot&&fs.existsSync(path.join(answersRoot,'self-check.json')))
|
|
196
215
|
stop(2,'self-check.json 是执行证据;不能从静态答案文件应答 prd_self_check');
|
|
197
216
|
}
|
|
198
|
-
return {operation,plan,base,project,specs,runtime,entry,admission,config,sources,state,request,asks,answers,answersRoot};
|
|
217
|
+
return {operation,plan,base,project,specs,runtime,entry,admission,config,sources,state,request,asks,answers,answersRoot,live};
|
|
199
218
|
}
|
|
200
219
|
function validate(kind,value,ctx){
|
|
201
220
|
if(kind==='prd_analyze'){
|
|
@@ -246,7 +265,7 @@ function validate(kind,value,ctx){
|
|
|
246
265
|
const prepared=preparePrdReview({specs:ctx.specs,draft,stage:ctx.request.stage,feature:ctx.request.feature});
|
|
247
266
|
const paths=(ctx.request.stage==='design'?['requirements.md','design.md']:['requirements.md','design.md','tasks.md'])
|
|
248
267
|
.map(name=>`${ctx.request.feature}/${name}`).sort();
|
|
249
|
-
|
|
268
|
+
inspectPrdReviewResponse({reviewPackage:prepared.reviewPackage,packageDigest:prepared.packageDigest,authorContextId:ctx.hostContext,response:value});}
|
|
250
269
|
catch(e){fail('review.json 与当前原审查包不匹配',e.code??e.message);}
|
|
251
270
|
}else if(kind==='prd_correct'){
|
|
252
271
|
exact(value,['decisions','documents'],'correct.json');
|
|
@@ -286,7 +305,8 @@ export async function runPrdContextChecks(cwd,commands){
|
|
|
286
305
|
}
|
|
287
306
|
return results;
|
|
288
307
|
}
|
|
289
|
-
async function answerFor(row,answers){
|
|
308
|
+
async function answerFor(row,answers,paths,control){
|
|
309
|
+
if(loaded.live.has(row.kind))return loaded.live.answer(row,control);
|
|
290
310
|
const v=answers[row.kind];
|
|
291
311
|
if(row.kind==='prd_materials')return null;
|
|
292
312
|
if(row.kind==='prd_self_check'){
|
|
@@ -297,7 +317,8 @@ async function answerFor(row,answers){
|
|
|
297
317
|
loaded.plan.contextJudgements[f.directory][id]:'failed',evidence}))}))};
|
|
298
318
|
}
|
|
299
319
|
if(row.kind==='prd_review'){
|
|
300
|
-
|
|
320
|
+
const {packageDigest,...reviewPackage}=row.payload.package;
|
|
321
|
+
inspectPrdReviewResponse({reviewPackage,packageDigest,authorContextId:row.payload.authorContextId,response:v});
|
|
301
322
|
return v;
|
|
302
323
|
}
|
|
303
324
|
if(row.kind==='prd_summary')return {...v,evidenceDigest:row.payload.evidenceDigest};
|
|
@@ -7,6 +7,7 @@ import {spawn,spawnSync} from 'node:child_process';
|
|
|
7
7
|
import {createInterface} from 'node:readline';
|
|
8
8
|
import {fileURLToPath} from 'node:url';
|
|
9
9
|
import {runPrdContextChecks} from './cm-prd-drive.mjs';
|
|
10
|
+
import {runLiveDriver} from './fixtures/live-evidence-driver.mjs';
|
|
10
11
|
|
|
11
12
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
12
13
|
const driver=path.join(root,'scripts/cm-prd-drive.mjs');
|
|
@@ -30,6 +31,20 @@ function fixture(t,{pdf=false}={}){
|
|
|
30
31
|
return {dir,project,answers,plan,write,drive,store:id=>path.join(project,'.reviews/prd-sessions',id,'state.json')};
|
|
31
32
|
}
|
|
32
33
|
const analyzed={status:'analyzed',summary:'Developer need',sourcePaths:['docs/input.md'],openQuestions:[]};
|
|
34
|
+
for(const format of ['pdf','html'])test(`${format} live material request is hash-bound and an unavailable reader stops honestly`,async t=>{
|
|
35
|
+
const f=fixture(t,{pdf:format==='pdf'});
|
|
36
|
+
if(format==='html')fs.writeFileSync(path.join(f.project,'docs/input.html'),'<button>Fixture</button>');
|
|
37
|
+
f.write('analyze.json',{status:'blocked',reason:'No material reader'});
|
|
38
|
+
const plan=path.join(f.dir,'live-plan.json');fs.writeFileSync(plan,JSON.stringify({...f.plan,
|
|
39
|
+
liveEvidence:{directory:'exchange',kinds:['prd_materials'],timeoutMs:1000}}));
|
|
40
|
+
const out=await runLiveDriver(driver,plan,'start',row=>{
|
|
41
|
+
assert.equal(row.kind,'prd_materials');assert.equal(row.payload.sources[0].format,format);
|
|
42
|
+
assert.match(row.payload.sources[0].sha256,/^[a-f0-9]{64}$/);
|
|
43
|
+
return {status:'blocked',reason:'Fixture intentionally has no reader; no processing claimed'};
|
|
44
|
+
},{env:{...process.env,CM_WORKFLOW_LOG_HOME:path.join(f.dir,'mirror')}});
|
|
45
|
+
assert.equal(out.status,0,out.stderr);assert.equal(out.requests.length,1);
|
|
46
|
+
assert.equal(JSON.parse(out.stdout).result.stage,'blocked');
|
|
47
|
+
});
|
|
33
48
|
const draft={status:'draft',summary:'Synthetic documentation draft',features:[{name:'guide',testCasesReason:'no_observable_behavior',
|
|
34
49
|
documents:[{path:'requirements.md',content:'## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Document setup.'},
|
|
35
50
|
{path:'design.md',content:'## 方案摘要\nSynthetic design'},
|
package/scripts/cm-prd-host.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Current conversation transport; original platform adapter owns log locking.
|
|
3
3
|
import fs from 'node:fs';
|
|
4
|
+
import {EXECUTION_POLICY_V1} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
4
5
|
import {readPrdInputsReplacement,replacePrdInputs,bindPrdPredecessor,readPrdPredecessor} from '../runtime/js/cm-prd/inputs-replaced.mjs';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import {readCmInitSource} from '../runtime/js/cm-init/draft-inspection.mjs';
|
|
@@ -26,6 +27,7 @@ const sessionFailureCodes=new Set(['prd_operation_recovery_required','prd_host_r
|
|
|
26
27
|
'prd_recovery_binding','prd_recovery_evidence_required','prd_replay_inputs_changed','cancelled','prd_turn_not_ready',
|
|
27
28
|
'prd_review_recovery_required','prd_batch_inputs_replaced','prd_inputs_changed','prd_replacement_authorization_required',
|
|
28
29
|
'prd_inputs_not_changed','prd_successor_not_fresh','prd_replacement_conflict','prd_replacement_not_ready',
|
|
30
|
+
'execution_policy_required','execution_policy_legacy_run','prd_response_already_canonical',
|
|
29
31
|
'prd_predecessor_binding','prd_successor_inputs_changed']);
|
|
30
32
|
|
|
31
33
|
export async function main(argv=process.argv.slice(2),{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
@@ -49,7 +51,8 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
49
51
|
need(argv.filter(x=>x==='--allow-spec-write').length<=1,'invalid_arguments');
|
|
50
52
|
need(argv.filter(x=>x==='--allow-disposition-write').length<=1,'invalid_arguments');
|
|
51
53
|
need(argv.filter(x=>x==='--allow-review-write').length<=1,'invalid_arguments');
|
|
52
|
-
|
|
54
|
+
need(argv.filter(x=>x==='--execution-optimizations').length<=1,'invalid_arguments');
|
|
55
|
+
const args=argv.slice(1).filter(x=>!['--execution-optimizations','--allow-log-write','--allow-review-write','--allow-disposition-write','--allow-spec-write'].includes(x)),options={};
|
|
53
56
|
for(let i=0;i<args.length;i+=2){
|
|
54
57
|
need(['--skill-dir','--project','--specs','--runtime','--cases','--host-context','--change','--session','--predecessor'].includes(args[i])
|
|
55
58
|
&&!Object.hasOwn(options,args[i])&&typeof args[i+1]==='string','invalid_arguments');
|
|
@@ -67,7 +70,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
67
70
|
need(ended||admission.status==='ready'||options['--session']&&admission.mode==='change'&&admission.reason==='feature_missing','prd_admission_blocked');
|
|
68
71
|
need(fileURLToPath(import.meta.url)===path.join(admission.workflowRoot,'scripts/cm-prd-host.mjs'),'entry_path_invalid');
|
|
69
72
|
const predecessor=bindPrdPredecessor({entry,runtime,sessionId:runId,predecessor:options['--predecessor']});
|
|
70
|
-
session=openPrdSession({specs:admission.specs,sessionId:runId,identity:{entry,runtime,...(predecessor?{predecessor}:{})}});
|
|
73
|
+
session=openPrdSession({specs:admission.specs,sessionId:runId,identity:{entry,runtime,...(predecessor?{predecessor}:{})},executionPolicy:argv.includes('--execution-optimizations')?EXECUTION_POLICY_V1:null});
|
|
71
74
|
if(!ended&&admission.status!=='ready')need(session.state.checkpoint?.change?.stage==='awaiting_review'
|
|
72
75
|
||session.state.active?.request.operation==='save_draft','prd_admission_blocked');
|
|
73
76
|
record=({event,phase='analysis',data={},at=null})=>{
|
|
@@ -244,6 +247,11 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
244
247
|
const dispatch=async request=>{
|
|
245
248
|
ended=readPrdInputsReplacement(admission.specs,runId);
|
|
246
249
|
if(request.operation==='status')return status();
|
|
250
|
+
if(request.operation==='repair_review_response'){
|
|
251
|
+
shape(request,['requestId','operation','binding']);need(reviewEnabled,'prd_review_not_enabled');
|
|
252
|
+
need(!ended,'prd_batch_inputs_replaced');
|
|
253
|
+
return {outcome:'original_response_repaired',repair:session.repairReviewResponse(request.binding),completionAuthorized:false};
|
|
254
|
+
}
|
|
247
255
|
if(request.operation==='read_batch')return ended??session.state;
|
|
248
256
|
if(request.operation==='replace_inputs'){
|
|
249
257
|
shape(request,['requestId','operation','approved','reason','successorSpecs','successorSessionId']);
|
|
@@ -276,9 +284,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
276
284
|
need(reviewEnabled,'prd_review_not_enabled');const original=active.calls.find(call=>call.kind==='prd_review');
|
|
277
285
|
const prepared=analysis.prepareReview(operation.stage,operation.feature);
|
|
278
286
|
need(prepared.packageDigest===original.payload.package.packageDigest,'prd_review_inputs_changed');
|
|
279
|
-
|
|
287
|
+
const response=session.reviewResponse(original);
|
|
288
|
+
validatePrdReviewMode(operation.mode,response);
|
|
280
289
|
reviewState={status:'review_recorded',...publishPrdReview({specs:admission.specs,reviewPackage:prepared.reviewPackage,
|
|
281
|
-
packageDigest:prepared.packageDigest,authorContextId:original.payload.authorContextId,response
|
|
290
|
+
packageDigest:prepared.packageDigest,authorContextId:original.payload.authorContextId,response})};
|
|
282
291
|
session.commit(checkpoint());return status();
|
|
283
292
|
}
|
|
284
293
|
}else{replaying=false;session.begin(request,checkpoint());}
|
|
@@ -5,6 +5,10 @@ set -euo pipefail
|
|
|
5
5
|
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
|
6
6
|
SOURCE_CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
|
|
7
7
|
SOURCE_CREATOR="$SOURCE_CODEX_HOME/skills/.system/plugin-creator"
|
|
8
|
+
if [ ! -f "$SOURCE_CREATOR/scripts/create_basic_plugin.py" ] &&
|
|
9
|
+
[ -f "$SOURCE_CODEX_HOME/.tmp/plugins/.agents/skills/plugin-creator/scripts/create_basic_plugin.py" ]; then
|
|
10
|
+
SOURCE_CREATOR="$SOURCE_CODEX_HOME/.tmp/plugins/.agents/skills/plugin-creator"
|
|
11
|
+
fi
|
|
8
12
|
TMP_ROOT=""
|
|
9
13
|
PYTHON_BIN=""
|
|
10
14
|
|
|
@@ -33,7 +37,7 @@ trap 'exit 143' TERM
|
|
|
33
37
|
|
|
34
38
|
command -v byz >/dev/null 2>&1 || blocked "byz command not found"
|
|
35
39
|
command -v codex >/dev/null 2>&1 || blocked "codex command not found"
|
|
36
|
-
[ -
|
|
40
|
+
[ -f "$SOURCE_CREATOR/scripts/create_basic_plugin.py" ] || blocked "Codex plugin creator not found at $SOURCE_CREATOR"
|
|
37
41
|
for candidate in python3 python; do
|
|
38
42
|
if command -v "$candidate" >/dev/null 2>&1 &&
|
|
39
43
|
"$candidate" -c 'import sys; raise SystemExit(sys.version_info < (3, 9))' >/dev/null 2>&1; then
|
|
@@ -6,16 +6,27 @@ export function runtimeLanguage(env=process.env,intlLocale=()=>Intl.DateTimeForm
|
|
|
6
6
|
try{return /^zh/i.test(intlLocale()||'')?'zh':'en';}catch{return 'en';}
|
|
7
7
|
}
|
|
8
8
|
export const messages={
|
|
9
|
+
menu:{zh:'运行时配置:[1] 保留当前配置(推荐,默认) [2] 修改运行时预设 [3] 查看高级模型配置说明 [1]: ',en:'Runtime configuration: [1] Keep current configuration (recommended, default) [2] Change runtime preset [3] Advanced model configuration [1]: '},
|
|
10
|
+
kept:{zh:'已保留当前配置,未写入文件。\n',en:'Kept current configuration; no files written.\n'},
|
|
11
|
+
builtin:{zh:'内置默认(未声明)',en:'Built-in defaults (undeclared)'},
|
|
9
12
|
tools:{zh:'你手上有哪个 AI 工具?[1] 只有 Codex [2] 只有 Claude [3] 两个都有: ',en:'Which AI tools do you have? [1] Codex only [2] Claude only [3] Both: '},
|
|
10
13
|
coder:{zh:'谁写代码?[1] Codex(Claude 审,推荐) [2] Claude(Codex 审): ',en:'Who writes code? [1] Codex (Claude reviews, recommended) [2] Claude (Codex reviews): '},
|
|
11
14
|
scope:{zh:'改哪一层?[1] 当前项目({project}) [2] 用户级默认({user}) [{default}]: ',en:'Which scope? [1] Current project ({project}) [2] User default ({user}) [{default}]: '},
|
|
12
15
|
create:{zh:'将从模板新建项目配置:{file}\n',en:'Will create project configuration from the template: {file}\n'},
|
|
13
16
|
current:{zh:'当前用户级默认: {available} / {preset}\n',en:'Current user default: {available} / {preset}\n'},
|
|
14
|
-
invalid:{zh:'
|
|
17
|
+
invalid:{zh:'当前用户级默认无效({file}): {error};文件已保留,请先修正后重试。\n',en:'Invalid user default ({file}): {error}; file preserved. Correct it before retrying.\n'},
|
|
15
18
|
keep:{zh:'保留?[Y/n] ',en:'Keep it? [Y/n] '},
|
|
16
|
-
|
|
19
|
+
configure:{zh:'现在配置用户默认?可跳过,稍后用 cm-runtime 配置。[y/N] ',en:'Configure a user default now? Optional; use cm-runtime later. [y/N] '},
|
|
20
|
+
preview:{zh:'将写入: {file}\n范围: {scope}\n预设: {preset}\n写入字段(当前值 -> 候选值):\n{fields}\n影响: {impact}\n当前项目有效值:\n{current}\n保存后当前项目有效值:\n{effective}\n',en:'Will write: {file}\nScope: {scope}\nPreset: {preset}\nFields to write (current -> candidate):\n{fields}\nImpact: {impact}\nCurrent project effective values:\n{current}\nProject effective values after saving:\n{effective}\n'},
|
|
21
|
+
overridden:{zh:'项目已声明 runtimes.available,当前项目继续使用项目声明;用户默认仅供未声明的项目继承。已有 run 不变。',en:'The project declares runtimes.available and overrides this user default; only undeclared projects inherit it. Existing runs unchanged.'},
|
|
22
|
+
userImpact:{zh:'只影响未声明 runtimes.available 的项目;项目显式角色字段仍优先,其他项目须各自校验。已有 run 不变。',en:'Applies only to projects without runtimes.available; explicit project role fields still win. Other projects require their own validation. Existing runs unchanged.'},
|
|
23
|
+
projectImpact:{zh:'当前项目将使用此声明,只影响新 run。模型别名和其他已有字段保留。',en:'This project will use the declaration for new runs. Model aliases and other existing fields are retained.'},
|
|
24
|
+
notProject:{zh:'安装器只配置用户默认,未核对任何项目的有效值。',en:'Installer configures user defaults only; no project effective values were checked.'},
|
|
25
|
+
modelWarning:{zh:'模型别名原样保留;更换 adapter 后,非默认模型未必兼容。校验通过仅证明配置合同有效,不证明模型可调用或配额可用。\n',en:'Model aliases are retained; a non-default model may be incompatible with a changed adapter. Validation proves the configuration contract only, not model access or quota.\n'},
|
|
26
|
+
drift:{zh:'预览后的配置已改变: {file};未保存,请重新预览并确认。',en:'Configuration changed after preview: {file}; not saved. Generate a fresh preview and confirm again.'},
|
|
27
|
+
advanced:{zh:'高级模型配置说明:建议保留当前默认,仅在有明确需要时手工编辑项目 .cm-workflow.yml 的模型别名。\n合同说明: {doc}\n校验: node "{validator}" --project "<项目路径>" --print-effective\n校验不证明 provider 兼容或配额可用;预设切换保留模型别名。\nunset --user 只删除用户默认,项目声明仍优先,不是恢复所有默认值。\n',en:'Advanced model configuration: keep current defaults unless you have a specific need; edit model aliases manually in the project .cm-workflow.yml.\nContract: {doc}\nValidate: node "{validator}" --project "<project path>" --print-effective\nValidation does not prove provider compatibility or quota; preset changes preserve model aliases.\nunset --user removes only user defaults; project declarations still win. It is not a reset of all settings.\n'},
|
|
17
28
|
absent:{zh:'未声明',en:'Undeclared'},
|
|
18
|
-
confirm:{zh:'确认?[
|
|
29
|
+
confirm:{zh:'确认?[y/N] ',en:'Confirm? [y/N] '},
|
|
19
30
|
cancelled:{zh:'已放弃,未修改运行时声明。\n',en:'Cancelled; runtime declaration unchanged.\n'},
|
|
20
31
|
installed:{zh:'✓ 用户级运行时默认已写入 {file} ({preset})\n',en:'✓ User runtime default saved to {file} ({preset})\n'},
|
|
21
32
|
comment:{zh:'用 cm-runtime set --user <preset> 修改用户级默认。',en:'Use cm-runtime set --user <preset> to change the user default.'},
|
|
@@ -24,7 +35,7 @@ export const messages={
|
|
|
24
35
|
warning:{zh:'WARN: runtimes.available 声明 {available},但本机 {runtime} CLI 不可解析(可解析≠配额可用)',en:'WARN: runtimes.available declares {available}, but {runtime} CLI is not resolvable (presence does not prove quota)'},
|
|
25
36
|
saved:{zh:'已保存 {file}: {preset} ({source});已有 run 不变',en:'Saved {file}: {preset} ({source}); existing runs unchanged'},
|
|
26
37
|
removed:{zh:'已删除用户默认: {file};项目声明仍优先',en:'Removed user default: {file}; project declarations still take precedence'},
|
|
27
|
-
help:{zh:'cm-runtime [--project PATH]:无参数在 TTY
|
|
38
|
+
help:{zh:'cm-runtime [--project PATH]:无参数在 TTY 下先查看配置,默认保留;非 TTY 显示用法并退出 2。',en:'cm-runtime [--project PATH]: no command shows current configuration in a TTY and defaults to keeping it; non-TTY prints usage and exits 2.'},
|
|
28
39
|
failed:{zh:'运行时声明未完成: {error}',en:'Runtime declaration incomplete: {error}'},
|
|
29
40
|
};
|
|
30
41
|
export function runtimeText(key,lang=runtimeLanguage(),values={}){
|
|
@@ -5,7 +5,7 @@ import path from 'node:path';
|
|
|
5
5
|
import {fileURLToPath} from 'node:url';
|
|
6
6
|
import {createInterface} from 'node:readline';
|
|
7
7
|
import {userRuntimesPath,readConfigText,parseUserRuntimes} from './cm-workflow-config.mjs';
|
|
8
|
-
import {writeUserRuntime} from './cm-runtime.mjs';
|
|
8
|
+
import {writeUserRuntime,prepareRuntimePreview,formatRuntimePreview} from './cm-runtime.mjs';
|
|
9
9
|
import {runtimeLanguage,runtimeText as t} from './cm-runtime-i18n.mjs';
|
|
10
10
|
|
|
11
11
|
export class PromptCancelled extends Error {}
|
|
@@ -54,12 +54,16 @@ export async function promptRuntime(argv=process.argv.slice(2),input=process.std
|
|
|
54
54
|
try{
|
|
55
55
|
const current=parseUserRuntimes(readConfigText(file));
|
|
56
56
|
output.write(t('current',lang,{available:current.runtimes.available,preset:current.preset}));
|
|
57
|
-
}catch(error){output.write(t('invalid',lang,{error:error.message}));}
|
|
57
|
+
}catch(error){output.write(t('invalid',lang,{file,error:error.message}));return;}
|
|
58
58
|
const keep=await ask(t('keep',lang));
|
|
59
59
|
if(keep!=='n'&&keep!=='N')return;
|
|
60
|
-
}
|
|
60
|
+
}else if((await ask(t('configure',lang))).toLowerCase()!=='y')return;
|
|
61
61
|
const preset=await askRuntimePreset(ask,lang);
|
|
62
|
-
|
|
62
|
+
const preview=prepareRuntimePreview(null,preset,{user:true,lang});
|
|
63
|
+
output.write(formatRuntimePreview(preview,lang));
|
|
64
|
+
let confirm;do{confirm=(await ask(t('confirm',lang))).toLowerCase();}while(!['','y','n'].includes(confirm));
|
|
65
|
+
if(confirm!=='y')throw new PromptCancelled();
|
|
66
|
+
output.write(t('installed',lang,{file:writeUserRuntime(preset,{lang,preview}),preset}));
|
|
63
67
|
}catch(error){if(error instanceof PromptCancelled)output.write(t('cancelled',lang));else throw error;}
|
|
64
68
|
finally{questions.close();}
|
|
65
69
|
}
|