@aibyzero/cm-workflow 0.21.6 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +58 -0
- package/README.md +18 -3
- package/VERSION +1 -1
- package/docs/architecture.md +9 -0
- package/docs/cm-acceptance-completion.md +3 -1
- package/docs/cm-control-policy-v2.md +35 -3
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +1 -0
- package/docs/human-correction.md +1 -1
- package/docs/installation.md +42 -16
- package/docs/js-workflow-control.md +65 -30
- package/docs/next-steps.md +10 -0
- package/docs/runtime-failover.md +5 -3
- package/docs/user-guide.md +6 -6
- package/package.json +1 -1
- package/runtime/js/cm-ai/batch-location.mjs +14 -0
- package/runtime/js/cm-ai/batch-plan.mjs +6 -2
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +9 -2
- package/runtime/js/cm-ai/cm-ai-admission.mjs +9 -3
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +51 -8
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +30 -4
- package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -4
- package/runtime/js/cm-ai/delivery-evidence.mjs +3 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +15 -1
- package/runtime/js/cm-ai/drive-core.mjs +50 -6
- package/runtime/js/cm-ai/drive-next-step.mjs +61 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +85 -23
- package/runtime/js/cm-ai/execution-snapshot.mjs +5 -2
- package/runtime/js/cm-ai/execution-store.mjs +21 -3
- package/runtime/js/cm-ai/external-run-guard.mjs +9 -1
- package/runtime/js/cm-ai/host-check.mjs +4 -2
- package/runtime/js/cm-ai/host-conversation-execution.mjs +23 -2
- package/runtime/js/cm-ai/host-handoff.mjs +7 -0
- package/runtime/js/cm-ai/host-progress.mjs +18 -0
- package/runtime/js/cm-ai/host-qa-executor.mjs +47 -15
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +24 -14
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +1 -1
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/operator-guidance.mjs +126 -2
- package/runtime/js/cm-ai/project-qa-gate.mjs +13 -2
- package/runtime/js/cm-ai/provider-review-observation.mjs +7 -3
- package/runtime/js/cm-ai/qa-plan-notes.mjs +106 -0
- package/runtime/js/cm-ai/review-continuation.mjs +102 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +11 -0
- package/runtime/js/cm-ai/review-package.mjs +25 -4
- package/runtime/js/cm-ai/review-presentation.mjs +31 -14
- package/runtime/js/cm-ai/review-runner.mjs +5 -4
- package/runtime/js/cm-ai/review-verdict-rules.mjs +7 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +30 -1
- package/runtime/js/cm-ai/task-commit-codec.mjs +11 -1
- package/runtime/js/cm-ai/task-commit.mjs +7 -4
- package/runtime/js/cm-ai/task-owner.mjs +5 -2
- package/runtime/js/cm-ai/task-runner.mjs +343 -52
- package/runtime/js/cm-ai/tool-preview.mjs +6 -0
- package/runtime/js/cm-fix/diagnosis.mjs +16 -3
- package/runtime/js/cm-fix/execution.mjs +47 -9
- package/runtime/js/cm-fix/finish.mjs +9 -1
- package/runtime/js/cm-fix/step-timing.mjs +222 -0
- package/runtime/js/cm-idea/session.mjs +22 -3
- package/runtime/js/cm-init/review-evidence.mjs +20 -7
- package/runtime/js/cm-prd/ai-draft.mjs +260 -0
- package/runtime/js/cm-prd/analysis.mjs +27 -9
- package/runtime/js/cm-prd/change.mjs +29 -8
- package/runtime/js/cm-prd/failed-correction.mjs +24 -4
- package/runtime/js/cm-prd/narrow-review.mjs +63 -3
- package/runtime/js/cm-prd/review-correction.mjs +65 -5
- package/runtime/js/cm-prd/review-disposition.mjs +10 -1
- package/runtime/js/cm-prd/self-check.mjs +121 -9
- package/runtime/js/cm-prd/session.mjs +55 -13
- package/runtime/js/cm-prd/summary.mjs +34 -6
- package/runtime/js/cm-prd/task-scope-record.mjs +40 -15
- package/runtime/js/cm-refactor/records.mjs +82 -11
- package/runtime/js/cm-refactor/workflow.mjs +3 -1
- package/runtime/js/executor-version.mjs +81 -0
- package/runtime/js/python-log-writer.mjs +15 -0
- package/runtime/js/run-analysis.mjs +136 -11
- package/runtime/logging.md +6 -0
- package/runtime/review.md +3 -1
- package/runtime/workflow-config.md +1 -1
- package/scripts/ci-test-weights.json +1 -0
- package/scripts/cm-ai-admission.mjs +27 -1
- package/scripts/cm-ai-admission.test.mjs +34 -2
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +3 -2
- package/scripts/cm-ai-batch-drive.mjs +54 -17
- package/scripts/cm-ai-batch-drive.test.mjs +123 -6
- package/scripts/cm-ai-batch-host.mjs +55 -9
- package/scripts/cm-ai-batch-host.test.mjs +22 -3
- package/scripts/cm-ai-batch-location.test.mjs +22 -1
- package/scripts/cm-ai-batch-merge.mjs +102 -0
- package/scripts/cm-ai-batch-plan.mjs +55 -2
- package/scripts/cm-ai-batch-plan.test.mjs +228 -6
- package/scripts/cm-ai-batch-run-fixture.mjs +239 -15
- package/scripts/cm-ai-batch-run-parallel.test.mjs +23 -1
- package/scripts/cm-ai-batch-run.mjs +435 -33
- package/scripts/cm-ai-batch-session-member.test.mjs +85 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +23 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +28 -0
- package/scripts/cm-ai-completion-summary.test.mjs +2 -1
- package/scripts/cm-ai-control-v2-drive.test.mjs +39 -9
- package/scripts/cm-ai-direct-review.test.mjs +1 -1
- package/scripts/cm-ai-disk-edits.test.mjs +229 -0
- package/scripts/cm-ai-drive-next-step.test.mjs +191 -0
- package/scripts/cm-ai-drive.mjs +66 -14
- package/scripts/cm-ai-drive.test.mjs +13 -3
- package/scripts/cm-ai-host-cli-workflow.test.mjs +4 -2
- package/scripts/cm-ai-host.mjs +16 -8
- package/scripts/cm-ai-host.test.mjs +12 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +132 -1
- package/scripts/cm-ai-project-qa-gate.test.mjs +26 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -0
- package/scripts/cm-ai-review-continuation.test.mjs +335 -0
- package/scripts/cm-ai-review-failure.test.mjs +13 -10
- package/scripts/cm-ai-review-timeout.test.mjs +1 -1
- package/scripts/cm-ai-run.mjs +42 -11
- package/scripts/cm-ai-run.test.mjs +26 -0
- package/scripts/cm-ai-supersede.test.mjs +10 -2
- package/scripts/cm-capability-gate.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +9 -0
- package/scripts/cm-codex-clean-env.test.mjs +40 -0
- package/scripts/cm-codex-prompt-input.test.mjs +2 -1
- package/scripts/cm-developer-self-review.test.mjs +27 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +4 -3
- package/scripts/cm-efficiency-response.test.mjs +2 -1
- package/scripts/cm-executor-version-draft.test.mjs +251 -0
- package/scripts/cm-executor-version-entries.test.mjs +93 -0
- package/scripts/cm-executor-version-prd.test.mjs +154 -0
- package/scripts/cm-executor-version-records.test.mjs +256 -0
- package/scripts/cm-executor-version.test.mjs +250 -0
- package/scripts/cm-external-model-host.test.mjs +6 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +1 -1
- package/scripts/cm-fix-closeout-preflight.test.mjs +123 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +5 -1
- package/scripts/cm-fix-drive.mjs +7 -2
- package/scripts/cm-fix-drive.test.mjs +45 -0
- package/scripts/cm-fix-entry.mjs +5 -2
- package/scripts/cm-fix-frozen-baseline.test.mjs +50 -0
- package/scripts/cm-fix-host.mjs +9 -2
- package/scripts/cm-fix-test-extension.test.mjs +30 -2
- package/scripts/cm-host-check.test.mjs +12 -0
- package/scripts/cm-host-qa-executor.test.mjs +172 -1
- package/scripts/cm-host-qa-policy.test.mjs +55 -1
- package/scripts/cm-idea-drive.mjs +5 -2
- package/scripts/cm-idea-entry.mjs +5 -2
- package/scripts/cm-idea-host.mjs +3 -1
- package/scripts/cm-init-drive.mjs +8 -5
- package/scripts/cm-init-entry.mjs +5 -2
- package/scripts/cm-init-host.mjs +6 -2
- package/scripts/cm-log-event.mjs +10 -2
- package/scripts/cm-log-event.test.mjs +29 -0
- package/scripts/cm-prd-ai-draft-fixture.mjs +18 -0
- package/scripts/cm-prd-ai-draft.test.mjs +505 -0
- package/scripts/cm-prd-answer-gaps.test.mjs +110 -5
- package/scripts/cm-prd-completion.test.mjs +67 -4
- package/scripts/cm-prd-design-phase.test.mjs +48 -13
- package/scripts/cm-prd-drive.mjs +89 -20
- package/scripts/cm-prd-drive.test.mjs +109 -4
- package/scripts/cm-prd-entry.mjs +5 -2
- package/scripts/cm-prd-host.mjs +89 -20
- package/scripts/cm-prd-host.test.mjs +17 -8
- package/scripts/cm-prd-narrow-review.test.mjs +49 -1
- package/scripts/cm-prd-review-disposition.test.mjs +94 -1
- package/scripts/cm-prd-review-gate.mjs +11 -4
- package/scripts/cm-prd-self-check-rules.test.mjs +175 -10
- package/scripts/cm-prd-self-check.test.mjs +1 -1
- package/scripts/cm-refactor-drive.mjs +10 -4
- package/scripts/cm-refactor-entry.mjs +5 -2
- package/scripts/cm-refactor-host.mjs +3 -1
- package/scripts/cm-run-analysis.test.mjs +373 -1
- package/scripts/cm-runtime-i18n.mjs +3 -3
- package/scripts/cm-runtime-install.mjs +19 -10
- package/scripts/cm-runtime.mjs +2 -4
- package/scripts/cm-runtime.test.mjs +55 -13
- package/scripts/cm-skill-hints-autowire.test.mjs +1 -1
- package/scripts/cm-skill-hints-exam.mjs +3 -1
- package/scripts/cm-skill-hints-install.test.mjs +1 -1
- package/scripts/cm-skill-hints.mjs +106 -10
- package/scripts/cm-skill-hints.test.mjs +162 -6
- package/scripts/cm-skill-judge.mjs +2 -1
- package/scripts/cm-statusline.test.mjs +54 -0
- package/scripts/cm-task-gate.mjs +88 -18
- package/scripts/cm-task-scope.test.mjs +1 -1
- package/scripts/cm-test-drive.mjs +13 -8
- package/scripts/cm-test-entry.mjs +5 -2
- package/scripts/cm-test-host.mjs +3 -1
- package/scripts/cm-upgrade-compat-batch.test.mjs +62 -9
- package/scripts/fixtures/fresh-completion-checks.mjs +8 -0
- package/scripts/fixtures/prd-review-gate-python-oracle.py +9 -0
- package/scripts/policy-binding-compat.test.mjs +3 -2
- package/scripts/test-cm-prd-review-gate.py +25 -0
- package/skills/cm-ai/SKILL.md +1 -1
- package/skills/cm-ai/references/N1-init.md +4 -3
- package/skills/cm-ai/references/N4-review.md +6 -3
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/js-host-recovery.md +4 -1
- package/skills/cm-ai/references/js-host.md +25 -5
- package/skills/cm-fix/references/js-host.md +20 -0
- package/skills/cm-fix/references/test-extension.md +1 -1
- package/skills/cm-prd/SKILL.md +8 -6
- package/skills/cm-prd/references/ai-draft.md +81 -0
- package/skills/cm-prd/references/change-mode.md +2 -0
- package/skills/cm-prd/references/greenfield.md +2 -0
- package/skills/cm-prd/references/js-change-recovery.md +2 -2
- package/skills/cm-prd/references/js-host.md +9 -6
- package/skills/cm-prd/references/light-mode.md +19 -0
- package/skills/cm-prd/references/requirement-grilling.md +2 -0
- package/skills/cm-prd/references/spec-self-check.md +1 -0
- package/skills/cm-prd/references/summary-card.md +1 -0
- package/skills/cm-runtime/SKILL.md +6 -6
- package/templates/statusline/cm-statusline.sh +63 -1
|
@@ -135,9 +135,22 @@ function tty(){
|
|
|
135
135
|
let text='';output.on('data',chunk=>{text+=chunk;});
|
|
136
136
|
return {input,output,text:()=>text};
|
|
137
137
|
}
|
|
138
|
+
// 逐行喂入:每个提问(不以换行结尾的输出)出现后才送下一行;{CODE} 换成提示里显示的确认码。
|
|
139
|
+
function feed(io,answers){
|
|
140
|
+
const lines=answers.split(/(?<=\n)/);let seen='';
|
|
141
|
+
io.output.on('data',chunk=>{
|
|
142
|
+
seen+=chunk;
|
|
143
|
+
if(String(chunk).endsWith('\n'))return;
|
|
144
|
+
let next=lines.shift();
|
|
145
|
+
if(next===undefined){io.input.end();return;}
|
|
146
|
+
if(next.includes('{CODE}')){const code=(/(?:confirmation code|确认码) (\w{8})/.exec(String(chunk))??[])[1];next=next.replace('{CODE}',code??'????');}
|
|
147
|
+
if(lines.length===0)io.input.end(next);else io.input.write(next);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
138
150
|
async function wizard(root,answers,lang='en'){
|
|
139
|
-
const io=tty();
|
|
140
|
-
|
|
151
|
+
const io=tty();feed(io,answers);
|
|
152
|
+
const running=main(['--project',root],{...io,lang});
|
|
153
|
+
const code=await running;return {code,text:io.text()};
|
|
141
154
|
}
|
|
142
155
|
test('wizard and installer share the same preset question function',()=>assert.equal(wizardPreset,installerPreset));
|
|
143
156
|
test('entry keeps missing and existing configuration by default, without logs or run writes',()=>wizardFixture(async root=>{
|
|
@@ -156,7 +169,7 @@ test('advanced model information is read-only and has no model editing prompt',(
|
|
|
156
169
|
assert.deepEqual(fs.readdirSync(root),[]);
|
|
157
170
|
}));
|
|
158
171
|
test('Enter at the final confirmation declines the proposed change',()=>wizardFixture(async root=>{
|
|
159
|
-
const result=await wizard(root,'2\n2\n1\n\n');assert.equal(result.code,0);assert.match(result.text,/
|
|
172
|
+
const result=await wizard(root,'2\n2\n1\n\n');assert.equal(result.code,0);assert.match(result.text,/confirmation code/);
|
|
160
173
|
assert.match(result.text,/Cancelled/);assert.deepEqual(fs.readdirSync(root),[]);
|
|
161
174
|
}));
|
|
162
175
|
test('first-install declaration is optional and Enter skips it',()=>wizardFixture(async root=>{
|
|
@@ -180,7 +193,7 @@ test('TTY project wizard changes exactly five fields, logs decision and shows re
|
|
|
180
193
|
const before='\ufeff# keep\r\nversion: 1\r\nruntimes: {available: codex}\r\nroles:\r\n coder: {adapter: current-ai, source: local, model: default} # keep coder\r\n reviewer: {adapter: current-ai, source: local, model: default}\r\n';
|
|
181
194
|
const initial=before;
|
|
182
195
|
fs.writeFileSync(file,initial);
|
|
183
|
-
const result=await wizard(root,'2\n1\n3\n1\
|
|
196
|
+
const result=await wizard(root,'2\n1\n3\n1\n{CODE}\n');assert.equal(result.code,0,result.text);
|
|
184
197
|
assert.equal(fs.readFileSync(file,'utf8'),initial.replace('available: codex','available: both').replace('adapter: current-ai','adapter: codex-cli').replace('adapter: current-ai','adapter: claude-cli').replaceAll('source: local','source: subscription'));
|
|
185
198
|
assert.match(result.text,/Which AI tools do you have/);assert.match(result.text,/Who writes code/);
|
|
186
199
|
assert.match(result.text,/preset: codex-codes/);assert.match(result.text,/runtimes_source: project/);
|
|
@@ -189,12 +202,12 @@ test('TTY project wizard changes exactly five fields, logs decision and shows re
|
|
|
189
202
|
assert.equal(event.event,'decision');assert.equal(event.preset,'codex-codes');
|
|
190
203
|
}));
|
|
191
204
|
test('missing project defaults to user scope and Chinese preset/comment/output',()=>wizardFixture(async root=>{
|
|
192
|
-
const result=await wizard(root,'2\n\n2\
|
|
205
|
+
const result=await wizard(root,'2\n\n2\n{CODE}\n','zh');assert.equal(result.code,0);
|
|
193
206
|
assert(!fs.existsSync(path.join(root,'.cm-workflow.yml')));
|
|
194
207
|
assert.match(fs.readFileSync(path.join(root,'user','runtimes.yml'),'utf8'),/# 用 cm-runtime.*\npreset: claude-only/s);
|
|
195
|
-
assert.match(result.text,/你手上有哪个 AI 工具/);assert.match(result.text
|
|
208
|
+
assert.match(result.text,/你手上有哪个 AI 工具/);assert.match(result.text,/确认码/);assert.match(result.text,/runtimes_source: user/);
|
|
196
209
|
}));
|
|
197
|
-
test('
|
|
210
|
+
test('empty final confirmation, refusal, EOF and SIGINT do not write',()=>wizardFixture(async root=>{
|
|
198
211
|
for(const [lang,cancelled] of [['en',/Cancelled/],['zh',/已放弃/]]){
|
|
199
212
|
for(const answers of ['2\n2\n\n\n\n','2\n2\n1\nn\n','2\n2\n','2\n2\n1\n']){
|
|
200
213
|
const result=await wizard(root,answers,lang);assert.equal(result.code,0);
|
|
@@ -204,9 +217,38 @@ test('three empty mandatory answers, refusal, EOF and SIGINT do not write',()=>w
|
|
|
204
217
|
assert.equal(await running,0);assert.match(io.text(),cancelled);assert.deepEqual(fs.readdirSync(root),[]);
|
|
205
218
|
}
|
|
206
219
|
}));
|
|
220
|
+
test('empty answers default to Claude: tools question and coder question',async()=>{
|
|
221
|
+
const feed=list=>async()=>list.shift();
|
|
222
|
+
assert.equal(await installerPreset(feed([''])),'claude-only');
|
|
223
|
+
assert.equal(await installerPreset(feed(['3',''])),'claude-codes');
|
|
224
|
+
assert.equal(await installerPreset(feed(['3','1'])),'codex-codes');
|
|
225
|
+
assert.equal(await installerPreset(feed(['1'])),'codex-only');
|
|
226
|
+
});
|
|
227
|
+
test('saving needs the preview confirmation code: pasted y, n, Enter, wrong code and unterminated EOF code never write',()=>wizardFixture(async root=>{
|
|
228
|
+
const cancelled=/Cancelled/;
|
|
229
|
+
// 提前粘贴(含猜测 y):确认码预览前不可知 → 取消,不写。
|
|
230
|
+
const pasted=tty(),running=main(['--project',root],{...pasted,lang:'en'});
|
|
231
|
+
pasted.input.end('2\n2\n\ny\n');assert.equal(await running,0);
|
|
232
|
+
assert.match(pasted.text(),cancelled);assert.deepEqual(fs.readdirSync(root),[]);
|
|
233
|
+
// y、n、回车、错码:立即取消(不挂起、不吞输入),不写。
|
|
234
|
+
for(const answer of ['y\n','n\n','\n','zzzz\n']){
|
|
235
|
+
const r=await wizard(root,`2\n2\n\n${answer}`);assert.equal(r.code,0);
|
|
236
|
+
assert.match(r.text,cancelled);assert.deepEqual(fs.readdirSync(root),[]);
|
|
237
|
+
}
|
|
238
|
+
// 确认码每次提问随机生成:同一预览两次提问的码不同,上一次的码复用不了。
|
|
239
|
+
const codes=[];for(let i=0;i<2;i++){const r=await wizard(root,'2\n2\n\nn\n');codes.push(/(?:confirmation code|确认码) (\w{8})/.exec(r.text)[1]);}
|
|
240
|
+
assert.notEqual(codes[0],codes[1]);
|
|
241
|
+
const reused=await wizard(root,`2\n2\n\n${codes[0]}\n`);assert.match(reused.text,cancelled);assert.deepEqual(fs.readdirSync(root),[]);
|
|
242
|
+
// 正确确认码但没回车就 EOF:不算数,不写。
|
|
243
|
+
const tail=await wizard(root,'2\n2\n\n{CODE}');assert.equal(tail.code,0);
|
|
244
|
+
assert.match(tail.text,cancelled);assert.deepEqual(fs.readdirSync(root),[]);
|
|
245
|
+
// 对照:输入显示的确认码并回车才写入,且确认码大小写不敏感。
|
|
246
|
+
const ok=await wizard(root,'2\n2\n\n{CODE}\n');assert.equal(ok.code,0);
|
|
247
|
+
assert.match(ok.text,/Saved|已保存|installed/i);assert(fs.existsSync(path.join(root,'user','runtimes.yml')));
|
|
248
|
+
}));
|
|
207
249
|
test('explicit project creation, existing-project scope default and invalid choice retry',()=>wizardFixture(async root=>{
|
|
208
|
-
const created=await wizard(root,'2\n1\nwrong\n1\
|
|
209
|
-
const changed=await wizard(root,'2\n\n3\n2\
|
|
250
|
+
const created=await wizard(root,'2\n1\nwrong\n1\n{CODE}\n');assert.equal(created.code,0);assert.match(created.text,/Will create project configuration/);
|
|
251
|
+
const changed=await wizard(root,'2\n\n3\n2\n{CODE}\n');assert.equal(changed.code,0);assert.match(changed.text,/preset: claude-codes/);
|
|
210
252
|
assert.equal(loadConfig({projectRoot:root}).roles.coder.adapter,'claude-cli');
|
|
211
253
|
}));
|
|
212
254
|
test('non-TTY no command exits 2 with usage and no writes',()=>fixture((root,run)=>{
|
|
@@ -234,8 +276,8 @@ test('installer culture reaches shared prompts and comments; explicit override w
|
|
|
234
276
|
for(const key of keys)delete process.env[key];
|
|
235
277
|
for(const [culture,override,expected] of [['zh-CN',undefined,'zh'],['en-US',undefined,'en'],['zh-CN','en','en']]){
|
|
236
278
|
if(override)process.env.CM_WORKFLOW_LANG=override;else delete process.env.CM_WORKFLOW_LANG;
|
|
237
|
-
const io=tty(),running=promptRuntime(['--lang',culture],io.input,io.output);
|
|
238
|
-
|
|
279
|
+
const io=tty();feed(io,'y\n3\n2\n{CODE}\n');const running=promptRuntime(['--lang',culture],io.input,io.output);
|
|
280
|
+
await running;
|
|
239
281
|
assert.match(io.text(),expected==='zh'?/你手上有哪个 AI 工具/:/Which AI tools do you have/);
|
|
240
282
|
const file=path.join(root,'user','runtimes.yml');assert.match(fs.readFileSync(file,'utf8'),expected==='zh'?/# 用 cm-runtime/:/# Use cm-runtime/);
|
|
241
283
|
fs.unlinkSync(file);
|
|
@@ -297,7 +339,7 @@ test('project preview save refuses target edits and preserves the external write
|
|
|
297
339
|
test('TTY confirmation cannot overwrite edits made after its preview',()=>wizardFixture(async root=>{
|
|
298
340
|
const file=path.join(root,'.cm-workflow.yml');fs.writeFileSync(file,'version: 1\n');
|
|
299
341
|
const io=tty(),external='version: 1\n# external edit\n';let changed=false;
|
|
300
|
-
io.output.on('data',chunk=>{
|
|
342
|
+
io.output.on('data',chunk=>{const m=/(?:confirmation code|确认码) (\w{8})/.exec(String(chunk));if(m){fs.writeFileSync(file,external);changed=true;io.input.end(`${m[1]}\n`);}});
|
|
301
343
|
const running=main(['--project',root],{...io,lang:'en'});io.input.write('2\n1\n1\n');
|
|
302
344
|
assert.equal(await running,1);assert(changed);assert.equal(fs.readFileSync(file,'utf8'),external);
|
|
303
345
|
assert(!fs.existsSync(path.join(root,'logs')));
|
|
@@ -310,7 +352,7 @@ test('installer keeps existing defaults, defaults No at final confirmation and r
|
|
|
310
352
|
assert.deepEqual(fs.readFileSync(file),before);
|
|
311
353
|
}
|
|
312
354
|
const io=tty();let changed=false;
|
|
313
|
-
io.output.on('data',chunk=>{
|
|
355
|
+
io.output.on('data',chunk=>{const m=/(?:confirmation code|确认码) (\w{8})/.exec(String(chunk));if(m){writeUserRuntime('claude-codes');changed=true;io.input.end(`${m[1]}\n`);}});
|
|
314
356
|
const running=promptRuntime([],io.input,io.output);io.input.write('n\n2\n');
|
|
315
357
|
await assert.rejects(running,/fresh preview|重新预览/);assert(changed);
|
|
316
358
|
assert.match(fs.readFileSync(file,'utf8'),/preset: claude-codes/);
|
|
@@ -50,7 +50,7 @@ test('first install wires only its own host, records it and says how to turn it
|
|
|
50
50
|
assert.match(claude.out,/关掉提醒:在 .* 写 \{"enabled": false\}/);
|
|
51
51
|
assert.match(claude.out,/--no-skill-hints 只是不自动挂,不会摘掉已挂的钩子/);
|
|
52
52
|
assert.doesNotMatch(claude.out,/或重装时加 --no-skill-hints/);
|
|
53
|
-
assert.match(claude.out
|
|
53
|
+
assert.match(claude.out,/默认只用本机关键词判断,不外发;在本地文件写 "judge": true 且有 TypeSafe 密钥时,才把消息前 500 字/);
|
|
54
54
|
assert.doesNotMatch(claude.out,/信任/);
|
|
55
55
|
|
|
56
56
|
const codex=await b.run('codex');
|
|
@@ -80,7 +80,9 @@ export async function runExam({exam=readExam(),fetchImpl,key='exam-key',keywords
|
|
|
80
80
|
for(const item of exam.cases){
|
|
81
81
|
const home=fs.mkdtempSync(path.join(os.tmpdir(),'cm-skill-exam-'));
|
|
82
82
|
try{
|
|
83
|
-
|
|
83
|
+
// Jev is off unless asked for, so the exam turns it on explicitly, and only with a
|
|
84
|
+
// transport the caller passed in: without one the judge would fall back to real fetch.
|
|
85
|
+
fs.writeFileSync(path.join(home,'skill-hints.local.json'),JSON.stringify({judge:!keywordsOnly&&Boolean(fetchImpl)}));
|
|
84
86
|
const env={HOME:home,CM_WORKFLOW_HOME:home,CM_WORKFLOW_LOG_HOME:path.join(home,'logs')};
|
|
85
87
|
const transport=fetchImpl&&(async(url,options)=>{
|
|
86
88
|
const response=await fetchImpl(url,options);
|
|
@@ -99,7 +99,7 @@ for (const [script, scripts, host] of [
|
|
|
99
99
|
assert.match(bytesOf(own) ?? '', new RegExp(`skill-hints/cm-skill-hints\\.mjs hook --host ${host}`));
|
|
100
100
|
assert.doesNotMatch(bytesOf(other) ?? '', /cm-skill-hints/);
|
|
101
101
|
assert.ok(fs.existsSync(path.join(box.copy, 'cm-skill-hints.mjs')));
|
|
102
|
-
assert.match(output(result), /已给 (Claude|Codex) 挂上技能提醒钩子.*--no-skill-hints
|
|
102
|
+
assert.match(output(result), /已给 (Claude|Codex) 挂上技能提醒钩子.*--no-skill-hints.*默认只用本机关键词判断,不外发;在本地文件写 "judge": true 且有 TypeSafe 密钥时/);
|
|
103
103
|
if (host === 'codex') assert.match(output(result), /确认信任/);
|
|
104
104
|
assert.ok(!fs.existsSync(box.trust) || !/cm-skill-hints/.test(bytesOf(box.trust)), 'CM never trusts the hook for the user');
|
|
105
105
|
});
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
// start itself (`disable-model-invocation`) get a rule with `invoke`. When one fits, the
|
|
23
23
|
// hook tells the model to read that skill's SKILL.md and follow it (mode "direct"), or to
|
|
24
24
|
// ask the user first (mode "ask"), and shows the user one line saying so. Whether it fits
|
|
25
|
-
// is judged by
|
|
25
|
+
// is judged by the rule's keywords; only when the local file says "judge": true (off by
|
|
26
|
+
// default since 2026-11-27) and a TypeSafe key exists does Jev judge (cm-skill-judge.mjs: first 500 characters
|
|
26
27
|
// only, never a message that looks like it holds a secret, 3 seconds at most), else and
|
|
27
28
|
// on any Jev failure by the rule's keywords. Only the pinned author version is started.
|
|
28
29
|
import fs from 'node:fs';
|
|
@@ -149,7 +150,9 @@ export function loadRules({env=process.env,rulesFile=defaultRulesPath()}={}){
|
|
|
149
150
|
const replaced=new Set(user.map(rule=>rule.id));
|
|
150
151
|
const cm=(Array.isArray(defaults.value?.rules)?defaults.value.rules:[])
|
|
151
152
|
.map(rule=>normalizeRule(rule,false)).filter(rule=>rule&&!disabled.has(rule.id)&&!replaced.has(rule.id));
|
|
152
|
-
|
|
153
|
+
// Jev is opt-in (2026-11-27, maintainer): message text leaves the machine only after the
|
|
154
|
+
// user writes "judge": true, not merely because a TypeSafe key happens to be set.
|
|
155
|
+
return {enabled:true,rules:[...user,...cm],judge:settings.judge===true,judgeSet:typeof settings.judge==='boolean',localError:null,defaultsError:defaults.error??(defaults.missing?'missing':null),
|
|
153
156
|
userCount:user.length,disabledCount:disabled.size,cmCount:cm.length};
|
|
154
157
|
}
|
|
155
158
|
|
|
@@ -428,7 +431,9 @@ function isOurs(hook,env,host){
|
|
|
428
431
|
const tail=' '+managedTail(env,host);
|
|
429
432
|
if(!hook.command.endsWith(tail))return false;
|
|
430
433
|
const word=hook.command.slice(0,-tail.length);
|
|
431
|
-
|
|
434
|
+
// Exactly the forms shellWord writes: a plain word, or one '…' word. Anything sh would
|
|
435
|
+
// expand (`$(…)`, variables, globs) is not ours (review 2026-12-03).
|
|
436
|
+
const interpreter=/^[\w@%+=:,./-]+$/.test(word)?word:/^'[^']+'$/.test(word)?word.slice(1,-1):null;
|
|
432
437
|
return Boolean(interpreter)&&/^node(?:\.exe)?$/i.test(path.basename(interpreter));
|
|
433
438
|
}
|
|
434
439
|
// A UserPromptSubmit that is not a list holds no hook of ours. A config of the wrong shape
|
|
@@ -442,6 +447,76 @@ export function shapeError(config){
|
|
|
442
447
|
const list=promptHooks(config);
|
|
443
448
|
return list!==undefined&&!Array.isArray(list)?'UserPromptSubmit 不是列表':null;
|
|
444
449
|
}
|
|
450
|
+
// Split one plain command line into words the way sh would. Only literal characters,
|
|
451
|
+
// '…', "…" and backslash escapes (a backslash-newline is a continuation) are read;
|
|
452
|
+
// anything sh would expand, redirect or run as another command (variables, globs, ~,
|
|
453
|
+
// braces, ;, &, |, a bare line break …) returns null, and the caller reports the hook.
|
|
454
|
+
function shellWords(command){
|
|
455
|
+
const words=[];let word=null,i=0;
|
|
456
|
+
const add=char=>{word=(word??'')+char;};
|
|
457
|
+
while(i<command.length){
|
|
458
|
+
const char=command[i];
|
|
459
|
+
if(char===' '||char==='\t'){if(word!==null){words.push(word);word=null;}i++;continue;}
|
|
460
|
+
if(char==="'"){const end=command.indexOf("'",i+1);if(end<0)return null;add(command.slice(i+1,end));i=end+1;continue;}
|
|
461
|
+
if(char==='"'){
|
|
462
|
+
let j=i+1,text='';
|
|
463
|
+
for(;j<command.length&&command[j]!=='"';j++){
|
|
464
|
+
if(command[j]==='$'||command[j]==='`')return null;
|
|
465
|
+
if(command[j]==='\\'&&command[j+1]==='\n'){j++;continue;}
|
|
466
|
+
if(command[j]==='\\'&&/["\\$`]/.test(command[j+1]??'')){text+=command[++j];continue;}
|
|
467
|
+
text+=command[j];
|
|
468
|
+
}
|
|
469
|
+
if(j>=command.length)return null;
|
|
470
|
+
add(text);i=j+1;continue;
|
|
471
|
+
}
|
|
472
|
+
if(char==='\\'){if(i+1>=command.length)return null;if(command[i+1]!=='\n')add(command[i+1]);i+=2;continue;}
|
|
473
|
+
if(!/[\w@%+=:,./-]/.test(char))return null;
|
|
474
|
+
add(char);i++;
|
|
475
|
+
}
|
|
476
|
+
if(word!==null)words.push(word);
|
|
477
|
+
return words;
|
|
478
|
+
}
|
|
479
|
+
const NODE=/^node(?:\.exe)?$/i;
|
|
480
|
+
const PREFIX=/^(?:env|exec|command|nohup)(?:\.exe)?$/i;
|
|
481
|
+
// 'ours' | 'foreign' | 'unknown' | null (not a hint hook). Conservative on purpose
|
|
482
|
+
// (review rounds 2–7, 2026-12-02/03): a command that names the script is ours only as
|
|
483
|
+
// one plain line `[env|exec …] node <this copy, absolute> hook …`, and
|
|
484
|
+
// foreign only as the same line naming another absolute copy. Everything else that names
|
|
485
|
+
// the script (shells, wrappers, variables, globs, several commands, other subcommands)
|
|
486
|
+
// is reported as unknown: a false alarm is fine, a missed old sender is not. A command
|
|
487
|
+
// that builds the file name piece by piece is not recognised (documented gap).
|
|
488
|
+
function hintHookKind(command,env){
|
|
489
|
+
if(!command.includes(SCRIPT_NAME))return null;
|
|
490
|
+
const words=shellWords(command);
|
|
491
|
+
if(!words||command.split(SCRIPT_NAME).length!==2)return 'unknown';
|
|
492
|
+
const at=words.findIndex(word=>path.basename(word)===SCRIPT_NAME);
|
|
493
|
+
if(at<0||words[at+1]!=='hook')return 'unknown';
|
|
494
|
+
let first=0;
|
|
495
|
+
// A prefix is a bare command word; `NODE_OPTIONS=…/env` is an assignment, not `env`.
|
|
496
|
+
while(first<at&&!words[first].includes('=')&&PREFIX.test(path.basename(words[first])))first++;
|
|
497
|
+
// node must be followed directly by the script: a node option (--eval, --require,
|
|
498
|
+
// --import …) or a variable such as NODE_OPTIONS can run other code first.
|
|
499
|
+
if(first+1!==at||!NODE.test(path.basename(words[first])))return 'unknown';
|
|
500
|
+
const script=words[at];
|
|
501
|
+
if(!path.isAbsolute(script))return 'unknown';
|
|
502
|
+
return path.resolve(script)===path.join(installDir(env),SCRIPT_NAME)?'ours':'foreign';
|
|
503
|
+
}
|
|
504
|
+
// Hint hooks in a host config that run some other CM directory's copy (CM_WORKFLOW_HOME
|
|
505
|
+
// changed after wiring). Their copy may be a version that sends to Jev with just a key
|
|
506
|
+
// (review 2026-12-02), so status, refresh and install name them instead of staying quiet.
|
|
507
|
+
// Only the file and position are printed: a command can carry a key (`KEY=… node …`).
|
|
508
|
+
export function foreignHintHooks(env){
|
|
509
|
+
return HOSTS.flatMap(host=>{
|
|
510
|
+
let config;try{config=readJson(configFile(host,env)).value;}catch{return [];}
|
|
511
|
+
const list=promptHooks(config);
|
|
512
|
+
if(!Array.isArray(list))return [];
|
|
513
|
+
return list.flatMap((group,g)=>(Array.isArray(group?.hooks)?group.hooks:[]).map((hook,h)=>({hook,place:`UserPromptSubmit 第 ${g+1} 组第 ${h+1} 条`})))
|
|
514
|
+
.filter(({hook})=>hook?.type==='command'&&typeof hook.command==='string'&&!isOurs(hook,env,host))
|
|
515
|
+
.map(({hook,place})=>({host,file:configFile(host,env),place,kind:hintHookKind(hook.command,env)}))
|
|
516
|
+
.filter(item=>item.kind==='foreign'||item.kind==='unknown');
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
const FOREIGN_NOTE=found=>found.map(item=>`⚠ ${LABEL[item.host]} 的 ${item.file}(${item.place})${item.kind==='foreign'?'是另一个 CM 目录的技能提醒钩子':'像是技能提醒钩子,但 CM 读不准它跑的是哪份副本'}:它跑的副本可能是旧版本,有 TypeSafe 密钥就会把消息前 500 字发给 Jev;不需要就删掉这一条`).join('\n');
|
|
445
520
|
export const hasHintHook=(config,env,host)=>{
|
|
446
521
|
const list=promptHooks(config);
|
|
447
522
|
return Array.isArray(list)&&list.some(group=>Array.isArray(group?.hooks)&&group.hooks.some(hook=>isOurs(hook,env,host)));
|
|
@@ -496,10 +571,12 @@ const refreshCommand=()=>`node ${shellWord(fileURLToPath(import.meta.url))} refr
|
|
|
496
571
|
// copied files are replaced; host configs, Codex trust, session state and logs are not
|
|
497
572
|
// touched, and a user who never enabled hints gets nothing. Failure is a warning.
|
|
498
573
|
export function refresh({env=process.env,write=text=>process.stdout.write(text)}={}){
|
|
574
|
+
const foreign=foreignHintHooks(env);
|
|
575
|
+
if(foreign.length)write(FOREIGN_NOTE(foreign)+'\n');
|
|
499
576
|
if(!hintsInstalled(env))return 0;
|
|
500
577
|
if(runningFromCopy(env)){write(`⚠ 这是运行副本本身(${installDir(env)}),拿不到已装版本,未刷新;请运行已装 CM 里的 cm-skill-hints.mjs refresh\n`);return 1;}
|
|
501
578
|
try{copyInstall(env);}
|
|
502
|
-
catch(error){write(`⚠ 技能提醒运行副本未刷新(${installDir(env)}):${error.message};可稍后运行 ${refreshCommand()}\n`);return 1;}
|
|
579
|
+
catch(error){write(`⚠ 技能提醒运行副本未刷新(${installDir(env)}):${error.message};可稍后运行 ${refreshCommand()}。${OLD_COPY_NOTE(env)}\n`);return 1;}
|
|
503
580
|
write(`技能提醒:运行副本已刷新(${installDir(env)})。\n`);
|
|
504
581
|
return 0;
|
|
505
582
|
}
|
|
@@ -519,8 +596,10 @@ export async function enable({env=process.env,hosts=HOSTS,node=process.execPath,
|
|
|
519
596
|
write(noted.warning);
|
|
520
597
|
if(requireRecord)return 1;
|
|
521
598
|
}
|
|
599
|
+
// A copy already there (another host's) keeps running when this copy fails.
|
|
600
|
+
const hadCopy=fs.existsSync(path.join(installDir(env),SCRIPT_NAME));
|
|
522
601
|
try{copyFiles(env);}
|
|
523
|
-
catch(error){write(`✗ 复制提醒脚本到 ${installDir(env)} 失败:${error.message}\n`);return 1;}
|
|
602
|
+
catch(error){write(`✗ 复制提醒脚本到 ${installDir(env)} 失败:${error.message}${hadCopy?`。${OLD_COPY_NOTE(env)}`:''}\n`);return 1;}
|
|
524
603
|
let failed=0;
|
|
525
604
|
const done=[];
|
|
526
605
|
for(const host of hosts){
|
|
@@ -617,7 +696,10 @@ async function noteRecord(env,add,{lockWaitMs,beforeReplace,lock}={}){
|
|
|
617
696
|
}
|
|
618
697
|
|
|
619
698
|
const OFF_NOTE=env=>`关掉提醒:在 ${localPath(env)} 写 {"enabled": false}`;
|
|
620
|
-
|
|
699
|
+
// Versions before 2026-11-27 send to Jev with just a key and no "judge" field; every
|
|
700
|
+
// version honours "judge": false, so that is the way to stop an old copy at once.
|
|
701
|
+
const OLD_COPY_NOTE=env=>`旧副本可能仍在运行:旧版本只要有 TypeSafe 密钥就会把消息前 500 字发给 Jev;想立刻停止外发,在 ${localPath(env)} 写 "judge": false`;
|
|
702
|
+
const TYPESAFE_NOTE='handoff、wayfinder、improve-codebase-architecture 三个作者技能默认只用本机关键词判断,不外发;在本地文件写 "judge": true 且有 TypeSafe 密钥时,才把消息前 500 字发给 TypeSafe 判断。';
|
|
621
703
|
|
|
622
704
|
// Why an install must not add the hook now, or null. `optOut` is the user skipping this
|
|
623
705
|
// run; `off` is "enabled": false; `pause` is a local file CM cannot use, so it does nothing.
|
|
@@ -672,6 +754,9 @@ export async function install({env=process.env,host,skip=false,node=process.exec
|
|
|
672
754
|
+`(重装加 --no-skill-hints 只是不自动挂,不会摘掉已挂的钩子)。${TYPESAFE_NOTE}\n`);
|
|
673
755
|
if(host==='codex')write(CODEX_TRUST);
|
|
674
756
|
}
|
|
757
|
+
// Every other path above goes through refresh, which names these already.
|
|
758
|
+
const foreign=foreignHintHooks(env);
|
|
759
|
+
if(foreign.length)write(FOREIGN_NOTE(foreign)+'\n');
|
|
675
760
|
return code;
|
|
676
761
|
}catch(error){
|
|
677
762
|
write(`⚠ 技能提醒钩子未处理:${error.message}\n`);
|
|
@@ -701,20 +786,31 @@ export function statusText({env=process.env,rulesFile=defaultRulesPath()}={}){
|
|
|
701
786
|
:gate?.pause?` 安装时自动挂:暂停(${gate.pause})`
|
|
702
787
|
:settled.state==='invalid'?` 安装时自动挂:暂停(${autoPath(env)} 异常:${settled.reason})`
|
|
703
788
|
:` 安装时自动挂:开;已处理过:${settled.hosts.length?`${settled.hosts.map(host=>LABEL[host]).join('、')}(这些端不会再被自动挂上)`:'无'}`);
|
|
789
|
+
// Whether the copy the hook runs may be an older version than this one.
|
|
790
|
+
let unverified=false;
|
|
704
791
|
if(!hintsInstalled(env))lines.push(' 运行副本:未建(还没开启)');
|
|
705
|
-
else if(runningFromCopy(env))
|
|
706
|
-
|
|
792
|
+
else if(runningFromCopy(env)){
|
|
793
|
+
unverified=true;
|
|
794
|
+
lines.push(' ⚠ 这是从运行副本本身查的,无法核验它与已装版本是否一致;请用已装 CM 里的 cm-skill-hints.mjs status');
|
|
795
|
+
}else{
|
|
707
796
|
const kind=copyDirKind(env);
|
|
708
797
|
const stale=kind==='dir'?staleCopies(env):[];
|
|
798
|
+
// Only the hook script decides whether to send; a differing rules table alone does not.
|
|
799
|
+
// A missing script cannot run, so it sends nothing either.
|
|
800
|
+
unverified=kind==='other'||(stale.includes(SCRIPT_NAME)&&fs.existsSync(path.join(installDir(env),SCRIPT_NAME)));
|
|
709
801
|
lines.push(kind==='missing'?` ⚠ 运行副本缺失(${installDir(env)}),钩子跑不起来;运行 ${refreshCommand()} 补上`
|
|
710
802
|
:kind==='other'?` ⚠ 运行副本目录不是普通目录(${installDir(env)}),CM 不会写进去;请移走后运行 ${refreshCommand()}`
|
|
711
803
|
:stale.length?` ⚠ 运行副本与已装版本不一致(${stale.join('、')});运行 ${refreshCommand()} 刷新`
|
|
712
804
|
:' 运行副本:与已装版本一致');
|
|
713
805
|
}
|
|
806
|
+
const foreign=foreignHintHooks(env);
|
|
807
|
+
if(foreign.length)lines.push(FOREIGN_NOTE(foreign).split('\n').map(line=>` ${line}`).join('\n'));
|
|
714
808
|
if(loaded.enabled){
|
|
715
809
|
lines.push(` 对照表:CM 自带 ${loaded.defaultsError?`读取失败(${loaded.defaultsError})`:`${loaded.cmCount} 条`};用户自加 ${loaded.userCount} 条;关掉自带 ${loaded.disabledCount} 条`);
|
|
716
|
-
|
|
717
|
-
|
|
810
|
+
// An unset judge means "off" only for this version; the old copy may still send.
|
|
811
|
+
lines.push(unverified&&!loaded.judgeSet?` 自动调用:运行副本未刷新,挂着的钩子可能按旧副本判断。${OLD_COPY_NOTE(env)}`
|
|
812
|
+
:loaded.judge?` 自动调用:已开 Jev(${localPath(env)} 里 judge 为 true),有 TypeSafe 密钥(TYPESAFE_API_KEY 或钥匙串)时由 Jev 判断,否则用关键词`
|
|
813
|
+
:` 自动调用:${foreign.length?'本目录的钩子':''}只用本机关键词(默认不开 Jev;要开在 ${localPath(env)} 写 "judge": true)${foreign.length?';上方 ⚠ 列出的钩子可能仍在外发':''}`);
|
|
718
814
|
}
|
|
719
815
|
return lines.join('\n')+'\n';
|
|
720
816
|
}
|
|
@@ -6,7 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import crypto from 'node:crypto';
|
|
7
7
|
import {execFileSync} from 'node:child_process';
|
|
8
8
|
import {
|
|
9
|
-
hook,main,enable,refresh,statusText,loadRules,stripCode,hookCommand,hasHintHook,
|
|
9
|
+
hook,main,enable,refresh,install,foreignHintHooks,statusText,loadRules,stripCode,hookCommand,hasHintHook,
|
|
10
10
|
localPath,logFile,installDir,claudeSettingsPath,codexHooksPath,defaultRulesPath,
|
|
11
11
|
MAX_PROMPT,ADOPT_WINDOW,LOG_LIMIT,SCRIPT_NAME,RULES_NAME,patternMatches,typed,readJson,loadAuthorCheck,
|
|
12
12
|
} from './cm-skill-hints.mjs';
|
|
@@ -331,12 +331,166 @@ test('status reports wiring, switch and table counts',async t=>{
|
|
|
331
331
|
let text=statusText({env:f.env,rulesFile:f.rulesFile});
|
|
332
332
|
assert.match(text,/Claude 未挂,Codex 未挂;开关 开/);
|
|
333
333
|
assert.match(text,/CM 自带 3 条;用户自加 1 条;关掉自带 1 条/);
|
|
334
|
-
assert.match(text
|
|
334
|
+
assert.match(text,/自动调用:只用本机关键词(默认不开 Jev/);
|
|
335
|
+
fs.writeFileSync(localPath(f.env),JSON.stringify({judge:true}));
|
|
336
|
+
assert.match(statusText({env:f.env,rulesFile:f.rulesFile}),/自动调用:已开 Jev.*有 TypeSafe 密钥/);
|
|
335
337
|
fs.writeFileSync(localPath(f.env),JSON.stringify({enabled:false}));
|
|
336
338
|
text=statusText({env:f.env,rulesFile:f.rulesFile});
|
|
337
339
|
assert.match(text,/开关 关/);
|
|
338
340
|
});
|
|
339
341
|
|
|
342
|
+
// Review 2026-11-27: a refresh that fails leaves the old copy running, and versions before
|
|
343
|
+
// Jev went opt-in send with just a key. Status and the warning must not claim keywords only.
|
|
344
|
+
test('a stale or unrefreshable copy is not reported as keywords only, and says how to stop sending',async t=>{
|
|
345
|
+
const f=fixture(t,{});
|
|
346
|
+
fs.mkdirSync(installDir(f.env),{recursive:true});
|
|
347
|
+
fs.writeFileSync(path.join(installDir(f.env),SCRIPT_NAME),'// old version\n');
|
|
348
|
+
const text=statusText({env:f.env,rulesFile:f.rulesFile});
|
|
349
|
+
assert.doesNotMatch(text,/只用本机关键词/);
|
|
350
|
+
assert.match(text,/自动调用:运行副本未刷新.*旧副本.*"judge": false/);
|
|
351
|
+
fs.mkdirSync(path.join(installDir(f.env),'cm-config-lock.mjs','blocker'),{recursive:true});
|
|
352
|
+
let out='';
|
|
353
|
+
assert.equal(refresh({env:f.env,write:text=>{out+=text;}}),1);
|
|
354
|
+
assert.match(out,/未刷新.*旧副本可能仍在运行.*"judge": false/);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
// Review round 2: only the hook script decides whether to send, so a rules table that
|
|
358
|
+
// differs alone does not mean an old sender is running.
|
|
359
|
+
test('a copy that differs only in its rules table is not reported as an old sender',async t=>{
|
|
360
|
+
const f=fixture(t,{});
|
|
361
|
+
fs.mkdirSync(installDir(f.env),{recursive:true});
|
|
362
|
+
fs.copyFileSync(new URL(`./${SCRIPT_NAME}`,import.meta.url),path.join(installDir(f.env),SCRIPT_NAME));
|
|
363
|
+
fs.writeFileSync(path.join(installDir(f.env),RULES_NAME),'{}\n');
|
|
364
|
+
const text=statusText({env:f.env,rulesFile:f.rulesFile});
|
|
365
|
+
assert.match(text,/运行副本与已装版本不一致/);
|
|
366
|
+
assert.doesNotMatch(text,/旧副本可能仍在运行/);
|
|
367
|
+
assert.match(text,/自动调用:只用本机关键词/);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
// Review round 2: a first enable for a second host that cannot copy leaves the first
|
|
371
|
+
// host's old copy running, so it warns like a failed refresh.
|
|
372
|
+
test('enable that cannot copy over an existing old copy says the old copy may still send',async t=>{
|
|
373
|
+
const f=fixture(t,{});
|
|
374
|
+
fs.mkdirSync(installDir(f.env),{recursive:true});
|
|
375
|
+
fs.writeFileSync(path.join(installDir(f.env),SCRIPT_NAME),'// old version\n');
|
|
376
|
+
let out='';
|
|
377
|
+
const code=await enable({env:f.env,hosts:['codex'],write:text=>{out+=text;},copyFiles:()=>{throw new Error('blocked');}});
|
|
378
|
+
assert.equal(code,1);
|
|
379
|
+
assert.match(out,/复制提醒脚本.*失败.*旧副本可能仍在运行.*"judge": false/);
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// Review 2026-12-02: after CM_WORKFLOW_HOME changes, a hook still running the old
|
|
383
|
+
// directory's copy (which may send with just a key) must be named by status, refresh and
|
|
384
|
+
// a first install for the new directory, not reported as keywords only.
|
|
385
|
+
test('a hint hook that runs another CM directory\'s copy is named by status, refresh and install',async t=>{
|
|
386
|
+
const f=fixture(t,{});
|
|
387
|
+
const oldDir=path.join(f.env.HOME,'old-cm');
|
|
388
|
+
const oldCommand=`node ${path.join(oldDir,'skill-hints',SCRIPT_NAME)} hook --host claude`;
|
|
389
|
+
fs.mkdirSync(path.dirname(claudeSettingsPath(f.env)),{recursive:true});
|
|
390
|
+
fs.writeFileSync(claudeSettingsPath(f.env),JSON.stringify({hooks:{UserPromptSubmit:[{hooks:[{type:'command',command:oldCommand}]}]}}));
|
|
391
|
+
assert.deepEqual(foreignHintHooks(f.env).map(item=>[item.host,item.kind]),[['claude','foreign']]);
|
|
392
|
+
const text=statusText({env:f.env,rulesFile:f.rulesFile});
|
|
393
|
+
assert.match(text,/Claude 的 .*settings\.json(UserPromptSubmit 第 1 组第 1 条)是另一个 CM 目录的技能提醒钩子.*发给 Jev/);
|
|
394
|
+
assert.match(text,/自动调用:本目录的钩子只用本机关键词.*上方 ⚠ 列出的钩子可能仍在外发/);
|
|
395
|
+
let out='';
|
|
396
|
+
assert.equal(refresh({env:f.env,write:line=>{out+=line;}}),0);
|
|
397
|
+
assert.match(out,/第 1 组第 1 条)是另一个 CM 目录的技能提醒钩子/);
|
|
398
|
+
out='';
|
|
399
|
+
await install({env:f.env,host:'claude',write:line=>{out+=line;}});
|
|
400
|
+
assert.ok(hasHintHook(readJson(claudeSettingsPath(f.env)).value,f.env,'claude'),'the new directory is wired');
|
|
401
|
+
assert.match(out,/第 1 组第 1 条)是另一个 CM 目录的技能提醒钩子/);
|
|
402
|
+
assert.equal(foreignHintHooks(f.env).length,1,'only the old hook is foreign; the new one is ours');
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
test('a hook of this directory, or no hint hook at all, is never reported as foreign',async t=>{
|
|
406
|
+
const f=fixture(t,{});
|
|
407
|
+
fs.mkdirSync(path.dirname(claudeSettingsPath(f.env)),{recursive:true});
|
|
408
|
+
fs.writeFileSync(claudeSettingsPath(f.env),JSON.stringify({hooks:{UserPromptSubmit:[{hooks:[
|
|
409
|
+
{type:'command',command:hookCommand(f.env,'claude')},{type:'command',command:'echo other'}]}]}}));
|
|
410
|
+
assert.deepEqual(foreignHintHooks(f.env),[]);
|
|
411
|
+
assert.doesNotMatch(statusText({env:f.env,rulesFile:f.rulesFile}),/另一个 CM 目录/);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// Review round 2 (2026-12-02): the warning never prints the command (it can carry a
|
|
415
|
+
// key), quoting does not hide an old hook, and an echo or this directory's own copy run
|
|
416
|
+
// with node options is not called foreign.
|
|
417
|
+
test('foreign hint hooks: read like a shell, never echo the command, and report what CM cannot read',async t=>{
|
|
418
|
+
const f=fixture(t,{});
|
|
419
|
+
const own=path.join(installDir(f.env),SCRIPT_NAME);
|
|
420
|
+
const old=path.join(f.env.HOME,'old cm','skill-hints',SCRIPT_NAME);
|
|
421
|
+
const cases=[
|
|
422
|
+
[`TYPESAFE_API_KEY=sk-fake-123 node '${old}' hook --host claude`,'unknown'],
|
|
423
|
+
[`node '${old}' "hook" --host claude`,'foreign'],
|
|
424
|
+
[`env /usr/local/bin/node "${old}" hook --host claude`,'foreign'],
|
|
425
|
+
[`env A=1 /usr/local/bin/node --no-warnings "${old}" hook --host claude`,'unknown'],
|
|
426
|
+
[`exec node '${old}' hook --host claude`,'foreign'],
|
|
427
|
+
[`/usr/bin/env node '${old}' hook --host codex`,'foreign'],
|
|
428
|
+
// Review round 7: a node option or a variable (NODE_OPTIONS) can run other code first.
|
|
429
|
+
[`node --no-warnings ${own} hook --host claude`,'unknown'],
|
|
430
|
+
[`node --eval='require(1)' ${own} hook --host claude`,'unknown'],
|
|
431
|
+
[`NODE_OPTIONS=--require=/tmp/x.js node ${own} hook --host claude`,'unknown'],
|
|
432
|
+
[`NODE_OPTIONS=--require=/opt/legacy/env node ${own} hook --host claude`,'unknown'],
|
|
433
|
+
[`exec node ${own} hook --host claude`,null],
|
|
434
|
+
// Review round 3: an option with its own value, or a relative script path, is not
|
|
435
|
+
// read as plain, so it is reported rather than resolved against status's own cwd.
|
|
436
|
+
[`node --require node:path '${old}' hook --host claude`,'unknown'],
|
|
437
|
+
[`node --require node:path ${own} hook --host claude`,'unknown'],
|
|
438
|
+
[`node ./.cm-workflow/skill-hints/${SCRIPT_NAME} hook --host claude`,'unknown'],
|
|
439
|
+
// Printing text or another subcommand is not running the hook, but CM reports any
|
|
440
|
+
// command naming the script that is not one plain hook line (a false alarm is fine).
|
|
441
|
+
[`echo '${old}' hook --host claude`,'unknown'],
|
|
442
|
+
[`echo "Run node ${old} status"; true`,'unknown'],
|
|
443
|
+
[`node '${old}' status`,'unknown'],
|
|
444
|
+
[`bash -c 'node ${old} hook --host claude'`,'unknown'],
|
|
445
|
+
[`node $HOME/old/skill-hints/${SCRIPT_NAME} hook --host claude`,'unknown'],
|
|
446
|
+
// Review round 4: a variable or a line continuation can still become `hook`.
|
|
447
|
+
[`node "$HOME/old/skill-hints/${SCRIPT_NAME}" "$CM_HINT_ACTION" --host claude`,'unknown'],
|
|
448
|
+
[`node '${old}' \\\nhook --host claude`,'foreign'],
|
|
449
|
+
[`node "${old}" "\\\nhook" --host claude`,'foreign'],
|
|
450
|
+
[`node '${old}'`,'unknown'],
|
|
451
|
+
// Review round 5: a second command after a line break, or a second mention, is not
|
|
452
|
+
// hidden by a first command that runs this directory's copy.
|
|
453
|
+
[`node ${own} \\\n hook --host claude\nnode '${old}' hook --host claude`,'unknown'],
|
|
454
|
+
[`node ${own} hook --host claude && node '${old}' hook --host claude`,'unknown'],
|
|
455
|
+
[`node ${own} hook --host claude\nnode ${own} status`,'unknown'],
|
|
456
|
+
[`node ${own} hook --host claude ${old}`,'unknown'],
|
|
457
|
+
[`node ${own} hook --host claude\nnode --version`,'unknown'],
|
|
458
|
+
// Review round 6: wrappers that pass `hook` themselves, globs sh would expand, and a
|
|
459
|
+
// script name mentioned again elsewhere are all reported.
|
|
460
|
+
[`sh -c 'exec node "$1" hook --host claude' sh ${old} status`,'unknown'],
|
|
461
|
+
[`node ${path.dirname(path.dirname(own))}[1]/skill-hints/${SCRIPT_NAME} hook --host claude`,'unknown'],
|
|
462
|
+
[`node ~/old/skill-hints/${SCRIPT_NAME} hook --host claude`,'unknown'],
|
|
463
|
+
[`node ${own} hook --host "$(cat /tmp/host)"`,'unknown'],
|
|
464
|
+
[`node '${old}' hook --host claude '/a/${SCRIPT_NAME} status'`,'unknown'],
|
|
465
|
+
];
|
|
466
|
+
fs.mkdirSync(path.dirname(claudeSettingsPath(f.env)),{recursive:true});
|
|
467
|
+
fs.writeFileSync(claudeSettingsPath(f.env),JSON.stringify({hooks:{UserPromptSubmit:cases.map(([command])=>({hooks:[{type:'command',command}]}))}}));
|
|
468
|
+
const found=foreignHintHooks(f.env);
|
|
469
|
+
const expected=cases.map(([,kind],i)=>kind&&[`UserPromptSubmit 第 ${i+1} 组第 1 条`,kind]).filter(Boolean);
|
|
470
|
+
assert.deepEqual(found.map(item=>[item.place,item.kind]),expected);
|
|
471
|
+
const text=statusText({env:f.env,rulesFile:f.rulesFile});
|
|
472
|
+
let out='';refresh({env:f.env,write:line=>{out+=line;}});
|
|
473
|
+
for(const shown of [text,out]){
|
|
474
|
+
assert.doesNotMatch(shown,/sk-fake-123/);
|
|
475
|
+
assert.doesNotMatch(shown,/old cm/);
|
|
476
|
+
assert.match(shown,/CM 读不准它跑的是哪份副本/);
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
// Review round 7: an interpreter word that sh would expand is not our hook, even when the
|
|
481
|
+
// rest of the command matches, so it is listed rather than skipped.
|
|
482
|
+
test('a hook whose interpreter word runs a command substitution is not ours and is listed',async t=>{
|
|
483
|
+
const f=fixture(t,{});
|
|
484
|
+
const sneaky=`$(node${'${IFS}'}/old/skill-hints/${SCRIPT_NAME}${'${IFS}'}hook)/usr/local/bin/node ${path.join(installDir(f.env),SCRIPT_NAME)} hook --host claude`;
|
|
485
|
+
const config={hooks:{UserPromptSubmit:[{hooks:[{type:'command',command:sneaky}]}]}};
|
|
486
|
+
assert.equal(hasHintHook(config,f.env,'claude'),false);
|
|
487
|
+
assert.equal(hasHintHook({hooks:{UserPromptSubmit:[{hooks:[{type:'command',command:hookCommand(f.env,'claude','/usr/local/bin/node')}]}]}},f.env,'claude'),true);
|
|
488
|
+
assert.equal(hasHintHook({hooks:{UserPromptSubmit:[{hooks:[{type:'command',command:hookCommand(f.env,'claude','/Applications/My Node/node')}]}]}},f.env,'claude'),true);
|
|
489
|
+
fs.mkdirSync(path.dirname(claudeSettingsPath(f.env)),{recursive:true});
|
|
490
|
+
fs.writeFileSync(claudeSettingsPath(f.env),JSON.stringify(config));
|
|
491
|
+
assert.deepEqual(foreignHintHooks(f.env).map(item=>item.kind),['unknown']);
|
|
492
|
+
});
|
|
493
|
+
|
|
340
494
|
test('CM-launched Claude and Codex sessions carry the off switch',async()=>{
|
|
341
495
|
const {claudeEnvironment}=await import('../runtime/js/cm-ai/worker-claude.mjs');
|
|
342
496
|
const {cleanEnvironment}=await import('../runtime/js/cm-ai/codex-config.mjs');
|
|
@@ -699,8 +853,10 @@ const INVOKE_RULES={version:1,rules:[
|
|
|
699
853
|
fallback:{skill:'cm-prd',reason:'拆规格'},invoke:{mode:'ask',when:'拆决策票',near:'排个计划'}},
|
|
700
854
|
{id:'fix-bug',skill:'cm-fix',keywords:['修这个 bug'],reason:'先复现'},
|
|
701
855
|
]};
|
|
702
|
-
|
|
703
|
-
|
|
856
|
+
// Jev is off unless the local file says "judge": true, so these fixtures turn it on;
|
|
857
|
+
// `jev:false` leaves the field out to check the default.
|
|
858
|
+
function invoking(t,{installed=['handoff','wayfinder'],local,jev=true,answer={none:1},key='fake-key'}={}){
|
|
859
|
+
const f=fixture(t,{rules:INVOKE_RULES,local:jev?{judge:true,...local}:local,authorNames:['handoff','wayfinder'],
|
|
704
860
|
authorSkills:installed.flatMap(name=>[['.claude/skills',name],['.agents/skills',name]])});
|
|
705
861
|
const calls=[];
|
|
706
862
|
const fetchImpl=async(url,options)=>{
|
|
@@ -796,8 +952,8 @@ test('a skill that is not the installed author version is never judged or starte
|
|
|
796
952
|
assert.equal(none.calls.length,0);
|
|
797
953
|
});
|
|
798
954
|
|
|
799
|
-
test('judge:false, no key or a missing judge module
|
|
800
|
-
for(const options of [{local:{judge:false}},{key:''}]){
|
|
955
|
+
test('Jev is off by default; judge:false, no key or a missing judge module also fall back to keywords without a call',async t=>{
|
|
956
|
+
for(const options of [{jev:false},{jev:false,local:{rules:[]}},{local:{judge:false}},{key:''}]){
|
|
801
957
|
const f=invoking(t,{...options,answer:{handoff:1}});
|
|
802
958
|
assert.equal(await f.run('今天先到这'),null);
|
|
803
959
|
assert.match((await f.run('会话太长了',{session:'s2'})).systemMessage,/已让模型用 \/handoff/);
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// skill (`invoke` in cm-skill-hints.json); keywords stay the fallback.
|
|
4
4
|
//
|
|
5
5
|
// Decided 2026-10-25 (方案-技能自动调用): only with a TypeSafe key (env or the macOS
|
|
6
|
-
// keychain)
|
|
6
|
+
// keychain), and since 2026-11-27 only when the hook's local file says "judge": true
|
|
7
|
+
// (checked by the hook, which does not call this module otherwise); only the first SEND_CHARS characters leave the machine, and a message
|
|
7
8
|
// that looks like it holds a secret is never sent. At most BUDGET_MS in all and at most
|
|
8
9
|
// two requests: the second goes out at once when the first fails, or alongside it when
|
|
9
10
|
// the first has not answered within HEDGE_MS. Measured 2026-10-25 from fresh processes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// 状态条只显示属于当前会话项目的 CM 状态(按 stdin 的 cwd 判断)。
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import {spawnSync} from 'node:child_process';
|
|
8
|
+
import {fileURLToPath} from 'node:url';
|
|
9
|
+
|
|
10
|
+
const script=fileURLToPath(new URL('../templates/statusline/cm-statusline.sh',import.meta.url));
|
|
11
|
+
function fixture(fn){
|
|
12
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-statusline-')));
|
|
13
|
+
try{
|
|
14
|
+
const home=path.join(root,'home'),project=path.join(root,'proj'),specs=path.join(project,'specs','feat');
|
|
15
|
+
fs.mkdirSync(path.join(home,'.claude'),{recursive:true});fs.mkdirSync(specs,{recursive:true});
|
|
16
|
+
fs.mkdirSync(path.join(root,'proj2'));fs.mkdirSync(path.join(root,'other'));
|
|
17
|
+
fs.writeFileSync(path.join(home,'.claude','cm-current-specs'),specs);
|
|
18
|
+
fs.writeFileSync(path.join(specs,'.cm-status.json'),JSON.stringify({node:'N3',feature:'1.x',task:'T-001',detail:'正在开发接口',state:'running'}));
|
|
19
|
+
fn({root,home,project,specs});
|
|
20
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
21
|
+
}
|
|
22
|
+
const run=(home,input)=>spawnSync('/bin/bash',[script],{input:JSON.stringify(input),env:{...process.env,HOME:home},encoding:'utf8'}).stdout;
|
|
23
|
+
|
|
24
|
+
test('shows CM status when cwd is the project, inside specs, or via workspace.current_dir',()=>fixture(({home,project,specs})=>{
|
|
25
|
+
for(const input of [{cwd:project},{cwd:specs},{workspace:{current_dir:project}}])
|
|
26
|
+
assert.match(run(home,input),/正在开发接口/,JSON.stringify(input));
|
|
27
|
+
}));
|
|
28
|
+
test('hides another project\'s status, a prefix-lookalike dir, and a missing cwd',()=>fixture(({root,home})=>{
|
|
29
|
+
for(const input of [{cwd:path.join(root,'other')},{cwd:path.join(root,'proj2')},{model:{display_name:'M'}}]){
|
|
30
|
+
const out=run(home,input);
|
|
31
|
+
assert(!out.includes('正在开发接口')&&!out.includes('可能已中断'),JSON.stringify(input)+out);
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
test('inherited GIT_DIR / GIT_WORK_TREE cannot pull in another project\'s status',()=>fixture(({root,home,project})=>{
|
|
36
|
+
assert.equal(spawnSync('git',['init','-q',project]).status,0);
|
|
37
|
+
const env={...process.env,HOME:home,GIT_DIR:path.join(project,'.git'),GIT_WORK_TREE:project};
|
|
38
|
+
const out=spawnSync('/bin/bash',[script],{input:JSON.stringify({cwd:path.join(root,'other')}),env,encoding:'utf8'}).stdout;
|
|
39
|
+
assert(!out.includes('正在开发接口'),out);
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
test('a cwd that is "/", an ancestor of HOME, or a deleted directory never shows another project\'s status',()=>fixture(({root,home})=>{
|
|
43
|
+
const gone=path.join(root,'gone');fs.mkdirSync(gone);fs.rmSync(gone,{recursive:true});
|
|
44
|
+
for(const cwd of ['/',root,home,gone]){
|
|
45
|
+
const out=run(home,{cwd});assert(!out.includes('正在开发接口')&&!out.includes('可能已中断'),cwd+out);
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
test('a pointer to HOME with a stale status file never leaks into projects under HOME',()=>fixture(({home})=>{
|
|
50
|
+
const other=path.join(home,'work','other');fs.mkdirSync(other,{recursive:true});
|
|
51
|
+
fs.writeFileSync(path.join(home,'.claude','cm-current-specs'),home);
|
|
52
|
+
fs.writeFileSync(path.join(home,'.cm-status.json'),JSON.stringify({node:'N3',feature:'1.x',task:'T-001',detail:'正在开发接口',state:'running'}));
|
|
53
|
+
const out=run(home,{cwd:other});assert(!out.includes('正在开发接口')&&!out.includes('可能已中断'),out);
|
|
54
|
+
}));
|