your-cto-jev 0.13.0 → 0.13.1
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/dist/hooks.js +35 -2
- package/dist/i18n.js +2 -2
- package/dist/index.js +18 -3
- package/package.json +1 -1
package/dist/hooks.js
CHANGED
|
@@ -613,6 +613,35 @@ function dispatchTexts(path) {
|
|
|
613
613
|
return []; /* unreadable: no prompt, so no pairing */
|
|
614
614
|
}
|
|
615
615
|
}
|
|
616
|
+
/**
|
|
617
|
+
* A background subagent hands its report back through a SubagentHandback tool call, so SubagentStop's
|
|
618
|
+
* last_assistant_message is empty: the report is the newest such call's `message` in the transcript.
|
|
619
|
+
* Format checked on a real Claude Code 2026-11 transcript: {type:"assistant", message.content:[{type:"tool_use", name:"SubagentHandback", input:{message}}]}.
|
|
620
|
+
*/
|
|
621
|
+
function handbackText(path) {
|
|
622
|
+
if (typeof path !== 'string')
|
|
623
|
+
return '';
|
|
624
|
+
try {
|
|
625
|
+
for (const line of readFileSync(path, 'utf8').split('\n').reverse()) {
|
|
626
|
+
if (!line.includes('"SubagentHandback"'))
|
|
627
|
+
continue;
|
|
628
|
+
let e;
|
|
629
|
+
try {
|
|
630
|
+
e = JSON.parse(line);
|
|
631
|
+
}
|
|
632
|
+
catch {
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
if (e?.type !== 'assistant' || !Array.isArray(e?.message?.content))
|
|
636
|
+
continue;
|
|
637
|
+
const call = e.message.content.findLast((x) => x?.type === 'tool_use' && x.name === 'SubagentHandback');
|
|
638
|
+
if (typeof call?.input?.message === 'string')
|
|
639
|
+
return call.input.message;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
catch { /* unreadable: no report */ }
|
|
643
|
+
return '';
|
|
644
|
+
}
|
|
616
645
|
/**
|
|
617
646
|
* SubagentStop (Claude Code): keep cto-reviewer's final message with the hash of the code it saw. A review is recorded
|
|
618
647
|
* only when a start of its session has the same code hash and a dispatch prompt that appears in the subagent's
|
|
@@ -625,8 +654,12 @@ function dispatchTexts(path) {
|
|
|
625
654
|
*/
|
|
626
655
|
export function recordReview(raw, { root, now }) {
|
|
627
656
|
try {
|
|
628
|
-
|
|
629
|
-
|
|
657
|
+
if (raw?.agent_type !== 'cto-reviewer')
|
|
658
|
+
return { code: 0, stderr: [] };
|
|
659
|
+
const last = typeof raw?.last_assistant_message === 'string' ? raw.last_assistant_message : '';
|
|
660
|
+
// Both: a background reviewer may hand its findings back and then close with a short line; neither alone is the whole report.
|
|
661
|
+
const text = [handbackText(raw?.agent_transcript_path), last].filter((s) => s.trim()).join('\n\n');
|
|
662
|
+
if (!text.trim())
|
|
630
663
|
return { code: 0, stderr: [] };
|
|
631
664
|
const diffHash = treeHash(root);
|
|
632
665
|
const sessionId = sid(raw);
|
package/dist/i18n.js
CHANGED
|
@@ -276,7 +276,7 @@ const messages = {
|
|
|
276
276
|
doc_bad: () => '[cto] 有問題需要處理:',
|
|
277
277
|
update_available: (v) => `[cto] 有新版 ${v.latest}(目前 ${v.current}),執行 cto update 更新`,
|
|
278
278
|
update_done: () => '[cto] 已更新。已設定過的專案不用重跑 cto setup。',
|
|
279
|
-
usage: () => '用法:cto brief | cto check [--base origin/main] | cto log | cto report [n] | cto doctor | cto index | cto docs | cto models | cto update | cto --version | cto setup [--refresh] [--agents claude,cursor,gemini,codex] [--yes] [--uninstall] | cto --hook <git-commit|AGENT-pre|AGENT-post>',
|
|
279
|
+
usage: () => '用法:cto brief | cto check [--base origin/main] | cto log | cto report [n] | cto doctor | cto index | cto docs | cto models | cto update | cto --version | cto setup [--refresh] [--agents claude,cursor,gemini,codex] [--flow|--no-flow] [--yes] [--uninstall] | cto --hook <git-commit|AGENT-pre|AGENT-post>',
|
|
280
280
|
prefs_broken: (v) => `[cto] ${v.path} 不是有效的 JSON,裡面有 API key,cto 不會覆寫它。修好或刪掉後再試一次。`,
|
|
281
281
|
models_unset: () => '(未設定)',
|
|
282
282
|
models_fixed: (v) => `${v.key} ${v.from} → ${v.to}(下次開 session 生效)`,
|
|
@@ -557,7 +557,7 @@ const messages = {
|
|
|
557
557
|
doc_bad: () => '[cto] Needs attention:',
|
|
558
558
|
update_available: (v) => `[cto] Version ${v.latest} is available (you have ${v.current}). Run cto update`,
|
|
559
559
|
update_done: () => '[cto] Updated. Projects already set up do not need cto setup again.',
|
|
560
|
-
usage: () => 'Usage: cto brief | cto check [--base origin/main] | cto log | cto report [n] | cto doctor | cto index | cto docs | cto models | cto update | cto --version | cto setup [--refresh] [--agents claude,cursor,gemini,codex] [--yes] [--uninstall] | cto --hook <git-commit|AGENT-pre|AGENT-post>',
|
|
560
|
+
usage: () => 'Usage: cto brief | cto check [--base origin/main] | cto log | cto report [n] | cto doctor | cto index | cto docs | cto models | cto update | cto --version | cto setup [--refresh] [--agents claude,cursor,gemini,codex] [--flow|--no-flow] [--yes] [--uninstall] | cto --hook <git-commit|AGENT-pre|AGENT-post>',
|
|
561
561
|
prefs_broken: (v) => `[cto] ${v.path} is not valid JSON and holds API keys, so cto will not overwrite it. Fix or delete it, then try again.`,
|
|
562
562
|
models_unset: () => '(unset)',
|
|
563
563
|
models_fixed: (v) => `${v.key} ${v.from} → ${v.to} (takes effect next session)`,
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { writeFileSync } from 'node:fs';
|
|
3
|
+
import { writeFileSync, writeSync } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { agentNames, agents } from './agents.js';
|
|
6
6
|
import { applyCredentials, credentialsPath, findRoot, loadConfig, loadCredentials, loadPrefs, modelsPrefs, saveCredentials, savePrefs } from './brain.js';
|
|
@@ -132,6 +132,20 @@ if (args[0] === '--hook' && args[1]) {
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
else if (args[0] === 'setup') {
|
|
135
|
+
// An unknown flag (--help, a typo) prints usage instead of running the whole setup with defaults.
|
|
136
|
+
const SETUP_FLAGS = ['--uninstall', '--refresh', '--flow', '--no-flow', '--yes', '--agents'];
|
|
137
|
+
const unknown = args.slice(1).filter((a, i, all) => !SETUP_FLAGS.includes(a) && (all[i - 1] !== '--agents' || a.startsWith('-')));
|
|
138
|
+
// --agents once, with at least one name cto knows and no other: a missing value, an empty list or a typo ("claud")
|
|
139
|
+
// would set up no agents at all, and a second --agents would be ignored.
|
|
140
|
+
const agentValues = args.flatMap((a, i) => (a === '--agents' ? [args[i + 1] ?? ''] : []));
|
|
141
|
+
const names = (v) => v.split(',').map((s) => s.trim()).filter(Boolean);
|
|
142
|
+
if (agentValues.length > 1 || agentValues.some((v) => v.startsWith('-') || !names(v).length || names(v).some((s) => !agentNames.includes(s))))
|
|
143
|
+
unknown.push(`--agents ${agentValues.join(' ')}`);
|
|
144
|
+
if (unknown.length) {
|
|
145
|
+
const help = args.includes('--help') || args.includes('-h'); // asked for help: usage is the answer, not an error
|
|
146
|
+
writeSync(help ? 1 : 2, t(lang, 'usage') + '\n'); // sync: process.exit right after must not cut a piped write short
|
|
147
|
+
process.exit(help ? 0 : 1);
|
|
148
|
+
}
|
|
135
149
|
const uninstall = args.includes('--uninstall');
|
|
136
150
|
let chosen;
|
|
137
151
|
let interactive = false; // the menu lists every agent, so what is left unticked loses its cto hooks (exact mode)
|
|
@@ -308,6 +322,7 @@ else if (args[0] === '--version' || args[0] === '-v') {
|
|
|
308
322
|
console.log(currentVersion());
|
|
309
323
|
}
|
|
310
324
|
else {
|
|
311
|
-
|
|
312
|
-
process.
|
|
325
|
+
const asked = !args.length || args[0] === '--help' || args[0] === '-h';
|
|
326
|
+
(asked ? process.stdout : process.stderr).write(t(lang, 'usage') + '\n');
|
|
327
|
+
process.exitCode = asked ? 0 : 1;
|
|
313
328
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "your-cto-jev",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "A sharp-tongued CTO gatekeeper for AI coding agents: blocks leaked secrets in git commits and destructive shell commands in Claude Code, Cursor, Gemini CLI and Codex, using TypeSafe Jev.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|