your-cto-jev 0.13.0 → 0.14.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/README.md CHANGED
@@ -417,7 +417,7 @@ Defaults: `credential_leak` 0.5, `destructive_command` 0.7, `infinite_loop` 0.6,
417
417
  On Claude Code, `cto setup` writes a model split:
418
418
 
419
419
  - **Fable** advises the main agent.
420
- - **Sonnet** is the main model.
420
+ - **Sonnet** is the main model by default; `cto models main opus` switches it to Opus (better on long multi-step work, uses more of your plan).
421
421
  - **Haiku** runs the sub-agents.
422
422
  - **Opus** runs `cto-reviewer`, which reviews code with none of the main agent's context.
423
423
 
@@ -425,6 +425,7 @@ The split is written to your user settings (`global`, the default, every project
425
425
 
426
426
  ```sh
427
427
  cto models # status: the split, its scope, and what would change
428
+ cto models main sonnet|opus # the main model
428
429
  cto models advisor fable|opus # the advisor model
429
430
  cto models autofix on|off # let cto write the split (session start, setup, refresh, update)
430
431
  cto models scope global|local # where the split is written, for every project (local in a folder without cto only clears the user level)
package/dist/brain.js CHANGED
@@ -111,13 +111,14 @@ export function saveCredentials(c) {
111
111
  delete raw[k];
112
112
  return writeUserFile({ ...raw, ...c });
113
113
  }
114
- export const DEFAULT_MODELS = { scope: 'global', advisor: 'fable', autoFix: true };
114
+ export const DEFAULT_MODELS = { scope: 'global', main: 'sonnet', advisor: 'fable', autoFix: true };
115
115
  export const modelsPrefs = (p = loadPrefs()) => ({ ...DEFAULT_MODELS, ...p.models });
116
116
  export function loadPrefs() {
117
117
  const raw = readJson(credentialsPath()) ?? {};
118
118
  const m = raw.models;
119
119
  const models = m && typeof m === 'object' && !Array.isArray(m) && {
120
120
  ...((m.scope === 'global' || m.scope === 'local') && { scope: m.scope }),
121
+ ...((m.main === 'sonnet' || m.main === 'opus') && { main: m.main }),
121
122
  ...((m.advisor === 'fable' || m.advisor === 'opus') && { advisor: m.advisor }),
122
123
  ...(typeof m.autoFix === 'boolean' && { autoFix: m.autoFix }),
123
124
  ...((m.seenUserAdvisor === 'fable' || m.seenUserAdvisor === 'opus') && { seenUserAdvisor: m.seenUserAdvisor }),
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
- const text = typeof raw?.last_assistant_message === 'string' ? raw.last_assistant_message : '';
629
- if (raw?.agent_type !== 'cto-reviewer' || !text.trim())
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 生效)`,
@@ -309,17 +309,18 @@ const messages = {
309
309
  models_fable: () => '沒同意 Fable 時顧問不會跑,先在 /model fable 同意;不想用 Fable 就執行 cto models advisor opus。',
310
310
  models_line: (v) => `[cto] 設定檢查:${v.items}`,
311
311
  models_error: (v) => `[cto] 設定檢查失敗:${v.msg}`,
312
- models_split: (v) => `模型分工:主模型 sonnet · 顧問 ${v.advisor} · 子代理 haiku · 審核 cto-reviewer(opus)`,
312
+ models_split: (v) => `模型分工:主模型 ${v.main} · 顧問 ${v.advisor} · 子代理 haiku · 審核 cto-reviewer(opus)`,
313
313
  models_scope: (v) => `範圍:${v.scope}(寫在 ${v.file})`,
314
314
  models_autofix: (v) => `自動修:${v.state}`,
315
315
  models_review: (v) => `審核關卡:${v.state}`,
316
316
  models_no_drift: () => '漂移:無',
317
317
  models_drift_head: () => '漂移:',
318
318
  models_set: (v) => `[cto] ${v.what} 設為 ${v.value}`,
319
- models_usage: () => '用法:cto models [advisor fable|opus | autofix on|off | scope global|local | review on|off]',
319
+ models_usage: () => '用法:cto models [main sonnet|opus | advisor fable|opus | autofix on|off | scope global|local | review on|off]',
320
320
  ui_m_models: () => '模型分工',
321
- ui_models_row: (v) => `Sonnet · 顧問 ${v.advisor} · ${v.scope} · 自動修${v.autofix}`,
322
- ui_models_advisor_q: () => '顧問模型(Sonnet 做事,顧問給建議)',
321
+ ui_models_row: (v) => `${v.main} · 顧問 ${v.advisor} · ${v.scope} · 自動修${v.autofix}`,
322
+ ui_models_main_q: () => '主模型(回訊息、做事;Opus 品質較好、較耗額度)',
323
+ ui_models_advisor_q: () => '顧問模型(主模型做事,顧問給建議)',
323
324
  ui_models_scope_q: () => '分工寫在哪裡',
324
325
  ui_models_global: () => '全域:~/.claude/settings.json(每個 project)',
325
326
  ui_models_local: () => '只有這個 project:.claude/settings.local.json',
@@ -557,7 +558,7 @@ const messages = {
557
558
  doc_bad: () => '[cto] Needs attention:',
558
559
  update_available: (v) => `[cto] Version ${v.latest} is available (you have ${v.current}). Run cto update`,
559
560
  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>',
561
+ 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
562
  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
563
  models_unset: () => '(unset)',
563
564
  models_fixed: (v) => `${v.key} ${v.from} → ${v.to} (takes effect next session)`,
@@ -590,17 +591,18 @@ const messages = {
590
591
  models_fable: () => 'The advisor does not run until you agree to Fable: agree first in `/model fable`; to not use Fable, run `cto models advisor opus`.',
591
592
  models_line: (v) => `[cto] Settings check: ${v.items}`,
592
593
  models_error: (v) => `[cto] Settings check failed: ${v.msg}`,
593
- models_split: (v) => `Model split: main sonnet · advisor ${v.advisor} · sub-agents haiku · review cto-reviewer (opus)`,
594
+ models_split: (v) => `Model split: main ${v.main} · advisor ${v.advisor} · sub-agents haiku · review cto-reviewer (opus)`,
594
595
  models_scope: (v) => `Scope: ${v.scope} (written to ${v.file})`,
595
596
  models_autofix: (v) => `Auto-fix: ${v.state}`,
596
597
  models_review: (v) => `Review gate: ${v.state}`,
597
598
  models_no_drift: () => 'Drift: none',
598
599
  models_drift_head: () => 'Drift:',
599
600
  models_set: (v) => `[cto] ${v.what} set to ${v.value}`,
600
- models_usage: () => 'Usage: cto models [advisor fable|opus | autofix on|off | scope global|local | review on|off]',
601
+ models_usage: () => 'Usage: cto models [main sonnet|opus | advisor fable|opus | autofix on|off | scope global|local | review on|off]',
601
602
  ui_m_models: () => 'Model split',
602
- ui_models_row: (v) => `Sonnet · advisor ${v.advisor} · ${v.scope} · auto-fix ${v.autofix}`,
603
- ui_models_advisor_q: () => 'Advisor model (Sonnet does the work, the advisor advises)',
603
+ ui_models_row: (v) => `${v.main} · advisor ${v.advisor} · ${v.scope} · auto-fix ${v.autofix}`,
604
+ ui_models_main_q: () => 'Main model (answers and does the work; Opus does better, uses more usage)',
605
+ ui_models_advisor_q: () => 'Advisor model (the main model does the work, the advisor advises)',
604
606
  ui_models_scope_q: () => 'Where the split is written',
605
607
  ui_models_global: () => 'Global: ~/.claude/settings.json (every project)',
606
608
  ui_models_local: () => 'This project only: .claude/settings.local.json',
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';
@@ -11,7 +11,7 @@ import { doctor } from './doctor.js';
11
11
  import { detectLang, t } from './i18n.js';
12
12
  import { maskDiff, maskSensitiveState } from './masker.js';
13
13
  import { setModelsLang } from './models.js';
14
- import { applyModelsChange, claudeModels, claudeStart, detectAgents, gitRoot, isSetUp, modelsCommand, planSetup, prefsSaveError, setup, wiredAgents } from './setup.js';
14
+ import { applyModelsChange, claudeModels, claudeStart, detectAgents, gitRoot, isSetUp, modelsChange, modelsCommand, planSetup, prefsSaveError, setup, wiredAgents } from './setup.js';
15
15
  async function readStdin() {
16
16
  if (process.stdin.isTTY)
17
17
  return '';
@@ -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)
@@ -176,7 +190,7 @@ else if (args[0] === 'setup') {
176
190
  const firstRun = !wired.length && !providerOrder().length;
177
191
  const { setupUI } = await import('./setupui.js'); // clack loads only for interactive setup, never on the hook path
178
192
  const before = initial.models;
179
- const changed = (m) => m.advisor !== before.advisor || m.scope !== before.scope || m.autoFix !== before.autoFix;
193
+ const changed = (m) => Object.keys(modelsChange(before, m)).length > 0;
180
194
  // Same rule as the save: setup writes the split when the saved profile's auto-fix is on, a menu change writes it anyway.
181
195
  const plan = (st) => planSetup(root, st.agents, st.flow ?? false, st.goal, { prefs: st.models ?? before, before, write: before.autoFix || changed(st.models ?? before) });
182
196
  const s = await setupUI(initial, firstRun, lang, { detected: detectAgents(), plan });
@@ -288,7 +302,7 @@ else if (args[0] === 'index' || args[0] === 'docs') {
288
302
  else if (args[0] === 'models') {
289
303
  const root = gitRoot(process.cwd());
290
304
  // These write into a project (.cto.json, or the project's settings in scope local): only inside a git repo.
291
- const needsProject = args[1] === 'review' || args[1] === 'scope' || ((args[1] === 'advisor' || args[1] === 'autofix') && modelsPrefs().scope === 'local');
305
+ const needsProject = args[1] === 'review' || args[1] === 'scope' || ((args[1] === 'main' || args[1] === 'advisor' || args[1] === 'autofix') && modelsPrefs().scope === 'local');
292
306
  if (!root && needsProject) {
293
307
  process.stderr.write(t(lang, 'setup_not_git') + '\n');
294
308
  process.exitCode = 1;
@@ -308,6 +322,7 @@ else if (args[0] === '--version' || args[0] === '-v') {
308
322
  console.log(currentVersion());
309
323
  }
310
324
  else {
311
- process.stderr.write(t(lang, 'usage') + '\n');
312
- process.exitCode = args.length ? 1 : 0;
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/dist/models.js CHANGED
@@ -7,7 +7,7 @@ import { appendBlock, isObj, missingIgnores, readSettings, refreshClaudeHooks, w
7
7
  import { AGENT_FILES, FLOW_COMMAND_PATH, FLOW_SKILL_PATH, SKILL_MARK, SKILL_PATH, fileVersion, syncFlowSkill, syncGuidance, tooNew } from './skill.js';
8
8
  import { currentVersion } from './update.js';
9
9
  import { t } from './i18n.js';
10
- // The model split for Claude Code (docs/cto_jev/features/models/SPEC.md): Sonnet does the work, Fable or Opus advises,
10
+ // The model split for Claude Code (docs/cto_jev/features/models/SPEC.md): Sonnet (or Opus, profile.main) does the work, Fable or Opus advises,
11
11
  // Haiku runs sub-agents, an Opus agent reviews. cto keeps the settings in line and says what it fixed.
12
12
  // Every user-visible item in one place; the text is in i18n.ts. English unless the CLI sets the language (tests stay English).
13
13
  let lang = 'en';
@@ -42,7 +42,15 @@ export const MSG = {
42
42
  /** Shown by `cto models` and the setup menu when the advisor is Fable; never at SessionStart (noise). */
43
43
  export const fableReminder = (p = modelsPrefs()) => (p.advisor === 'fable' ? MSG.fable : undefined);
44
44
  // ---------- model matchers (case-insensitive) ----------
45
- export const isMainModel = (v) => typeof v === 'string' && /^(sonnet|claude-sonnet-[\w.-]+)(\[1m\])?$/i.test(v);
45
+ /** sonnet or opus (Opus 5 and up), with or without `[1m]`; anything else undefined. */
46
+ export function mainOf(v) {
47
+ if (typeof v !== 'string')
48
+ return undefined;
49
+ const base = v.replace(/\[1m\]$/i, '');
50
+ if (/^(sonnet|claude-sonnet-[\w.-]+)$/i.test(base))
51
+ return 'sonnet';
52
+ return advisorOf(base) === 'opus' ? 'opus' : undefined;
53
+ }
46
54
  export const isSubagentModel = (v) => typeof v === 'string' && (/^haiku$/i.test(v) || /^claude-haiku-[\w.-]+$/i.test(v));
47
55
  /** fable or opus (Opus 5 and up; the bare alias counts), anything else undefined. */
48
56
  export function advisorOf(v) {
@@ -54,7 +62,7 @@ export function advisorOf(v) {
54
62
  return m && (m[2] === undefined || Number(m[2]) >= 5) ? 'opus' : undefined;
55
63
  }
56
64
  export const MODEL_KEYS = [
57
- { label: 'model', path: ['model'], ok: isMainModel, want: () => 'sonnet' },
65
+ { label: 'model', path: ['model'], ok: (v, p) => mainOf(v) === p.main, want: (p) => p.main },
58
66
  { label: 'advisorModel', path: ['advisorModel'], ok: (v, p) => advisorOf(v) === p.advisor, want: (p) => p.advisor },
59
67
  // Never CLAUDE_CODE_SUBAGENT_MODEL_FORCE: with it Claude Code ignores cto-reviewer's own `model: opus`.
60
68
  { label: 'CLAUDE_CODE_SUBAGENT_MODEL', path: ['env', 'CLAUDE_CODE_SUBAGENT_MODEL'], ok: isSubagentModel, want: () => 'haiku' },
@@ -385,15 +393,18 @@ function checkFiles(root, autoFix, out) {
385
393
  }
386
394
  // ---------- changing the split ----------
387
395
  /**
388
- * A value cto wrote, so clearing a scope may remove it: model sonnet, sub-agents haiku, and any fable or opus advisor
389
- * (whichever one the profile holds now, or one switched with /advisor; the same rule switchScope carries over).
396
+ * A value cto wrote, so clearing a scope may remove it: model equal to the cleared scope's main (`main`, so a user's
397
+ * own `opus` under a sonnet split stays), sub-agents haiku, and any fable or opus advisor (whichever one the profile
398
+ * holds now, or one switched with /advisor; the same rule switchScope carries over).
390
399
  */
391
- export const isOurs = (k, v) => k.label === 'advisorModel' ? advisorOf(v) !== undefined : v === k.want(DEFAULT_MODELS);
400
+ export const isOurs = (k, v, main = modelsPrefs().main) => k.label === 'advisorModel' ? advisorOf(v) !== undefined
401
+ : k.label === 'model' ? v === main
402
+ : v === k.want(DEFAULT_MODELS);
392
403
  /**
393
404
  * Take the split out of one scope: the three keys (only where they still hold the profile's values) and cto's agent
394
405
  * files there. Used when switching scope and when cto is removed.
395
406
  */
396
- export function clearScope(root, scope, opts = {}) {
407
+ export function clearScope(root, scope, opts = {}, main = modelsPrefs().main) {
397
408
  const out = empty();
398
409
  const home = opts.home ?? homedir();
399
410
  const show = display(root, home);
@@ -402,7 +413,7 @@ export function clearScope(root, scope, opts = {}) {
402
413
  if (t.json === null)
403
414
  out.reported.push(fileProblem(t, show(path)));
404
415
  else {
405
- const mine = MODEL_KEYS.filter((k) => isOurs(k, getAt(t.json, k.path)));
416
+ const mine = MODEL_KEYS.filter((k) => isOurs(k, getAt(t.json, k.path), main));
406
417
  for (const k of mine)
407
418
  delAt(t.json, k.path);
408
419
  if (mine.length && writeJsonIfUnchanged(path, t.text, t.json))
@@ -446,11 +457,11 @@ export function switchScope(root, to, opts = {}, also = {}) {
446
457
  const a = p.scope === 'global' ? advisorOf(getAt(readSettings(targetPath(root, p.scope, opts.home ?? homedir())), ['advisorModel'])) : undefined;
447
458
  if (!saveModels({ ...p, ...(a && { advisor: a }), ...also, scope: to }, out))
448
459
  return out; // prefs first: a failed save changes no file
449
- const cleared = clearScope(root, p.scope, opts);
460
+ const cleared = clearScope(root, p.scope, opts, p.main); // the old scope holds the old main
450
461
  const written = driftCheck(root, { ...opts, autoFix: true, files: false, adopt: false });
451
462
  return { fixed: [...cleared.fixed, ...written.fixed], reported: [...cleared.reported, ...written.reported] };
452
463
  }
453
- /** `cto models advisor|autofix|scope`: save the change, then write it at once (turning autofix off writes nothing). */
464
+ /** `cto models main|advisor|autofix|scope`: save the change, then write it at once (turning autofix off writes nothing). */
454
465
  export function applyModels(root, change, opts = {}) {
455
466
  const p = modelsPrefs();
456
467
  const out = empty();
@@ -460,7 +471,7 @@ export function applyModels(root, change, opts = {}) {
460
471
  }
461
472
  if (!saveModels({ ...p, ...change, scope: p.scope }, out))
462
473
  return out;
463
- if (change.advisor !== undefined || change.autoFix === true)
474
+ if (change.main !== undefined || change.advisor !== undefined || change.autoFix === true)
464
475
  return driftCheck(root, { ...opts, autoFix: true, files: false, adopt: false });
465
476
  return out;
466
477
  }
package/dist/setup.js CHANGED
@@ -320,7 +320,7 @@ function planModels(root, claude, wasWired, m, at) {
320
320
  const planClear = (scope) => {
321
321
  const shown = shownIn(scope), target = targetPath(root, scope, home), s = readSettings(target);
322
322
  const hook = scope === 'global' && Array.isArray(s?.hooks?.SessionStart) && s.hooks.SessionStart.some(hasModelsHook);
323
- if (isObj(s) && (hook || MODEL_KEYS.some((k) => isOurs(k, valueAt(s, k.path)))))
323
+ if (isObj(s) && (hook || MODEL_KEYS.some((k) => isOurs(k, valueAt(s, k.path), (m.before ?? p).main))))
324
324
  at(shown(target), 'write', target);
325
325
  for (const n of Object.keys(AGENT_FILES)) {
326
326
  const f = join(agentsDir(root, scope, home), n);
@@ -724,14 +724,21 @@ export function prefsSaveError(e, lang, path) {
724
724
  }
725
725
  /** Apply a model split chosen in the setup menu: only what changed, through the same function as `cto models`. */
726
726
  export function applyModelsChange(root, before, after, opts = {}) {
727
+ const change = modelsChange(before, after);
728
+ return Object.keys(change).length ? applyAndHook(root, change, opts) : [];
729
+ }
730
+ /** What the menu changed in the split; the setup preview and the save both read it, so they agree. */
731
+ export function modelsChange(before, after) {
727
732
  const change = {};
733
+ if (after.main !== before.main)
734
+ change.main = after.main;
728
735
  if (after.advisor !== before.advisor)
729
736
  change.advisor = after.advisor;
730
737
  if (after.autoFix !== before.autoFix)
731
738
  change.autoFix = after.autoFix;
732
739
  if (after.scope !== before.scope)
733
740
  change.scope = after.scope;
734
- return Object.keys(change).length ? applyAndHook(root, change, opts) : [];
741
+ return change;
735
742
  }
736
743
  function applyAndHook(root, change, opts) {
737
744
  const lines = modelsLines(applyModels(root, change, opts));
@@ -742,7 +749,7 @@ function applyAndHook(root, change, opts) {
742
749
  }
743
750
  return lines;
744
751
  }
745
- /** `cto models [advisor fable|opus | autofix on|off | scope global|local | review on|off]`. */
752
+ /** `cto models [main sonnet|opus | advisor fable|opus | autofix on|off | scope global|local | review on|off]`. */
746
753
  export function modelsCommand(root, args, lang, opts = {}) {
747
754
  const [what, value] = args;
748
755
  const onoff = (b) => t(lang, b ? 'ui_on' : 'ui_off');
@@ -761,7 +768,7 @@ export function modelsCommand(root, args, lang, opts = {}) {
761
768
  return {
762
769
  code: 0,
763
770
  lines: [
764
- t(lang, 'models_split', { advisor: p.advisor }),
771
+ t(lang, 'models_split', { main: p.main, advisor: p.advisor }),
765
772
  t(lang, 'models_scope', { scope: t(lang, `models_scope_${p.scope}`), file: p.scope === 'global' ? USER_SETTINGS_SHOWN : '.claude/settings.local.json' }),
766
773
  t(lang, 'models_autofix', { state: onoff(p.autoFix) }),
767
774
  t(lang, 'models_review', { state: onoff(loadConfig(root).review_gate) }),
@@ -777,10 +784,11 @@ export function modelsCommand(root, args, lang, opts = {}) {
777
784
  return { code: 1, lines: [t(lang, 'models_bad_json', { file: '.cto.json' })] };
778
785
  return { code: 0, lines: [t(lang, 'models_set', { what: 'review_gate', value })] };
779
786
  }
780
- const change = what === 'advisor' && (value === 'fable' || value === 'opus') ? { advisor: value }
781
- : what === 'autofix' && (value === 'on' || value === 'off') ? { autoFix: value === 'on' }
782
- : what === 'scope' && (value === 'global' || value === 'local') ? { scope: value }
783
- : undefined;
787
+ const change = what === 'main' && (value === 'sonnet' || value === 'opus') ? { main: value }
788
+ : what === 'advisor' && (value === 'fable' || value === 'opus') ? { advisor: value }
789
+ : what === 'autofix' && (value === 'on' || value === 'off') ? { autoFix: value === 'on' }
790
+ : what === 'scope' && (value === 'global' || value === 'local') ? { scope: value }
791
+ : undefined;
784
792
  if (!change)
785
793
  return { code: 1, lines: [t(lang, 'models_usage')] };
786
794
  // Scope local in a folder without cto's Claude wiring (e.g. right after uninstall): clear the user level, write nothing here.
package/dist/setupui.js CHANGED
@@ -131,8 +131,13 @@ export async function setupUI(initial, firstRun, lang, o = {}) {
131
131
  });
132
132
  return isCancel(r) ? BACK : { ...s, flow: r === 'yes' };
133
133
  };
134
- // Three questions in a row (Esc goes back one); index.ts applies the result with the same function as `cto models`.
134
+ // Four questions in a row (Esc goes back one); index.ts applies the result with the same function as `cto models`.
135
135
  const pick = (message, initialValue, options) => select({ ...io, showInstructions: false, message, initialValue, options: options });
136
+ const mainStep = async (s) => {
137
+ const m = s.models ?? DEFAULT_MODELS;
138
+ const r = await pick(t(lang, 'ui_models_main_q'), m.main, [{ value: 'sonnet', label: 'Sonnet' }, { value: 'opus', label: 'Opus' }]);
139
+ return isCancel(r) ? BACK : { ...s, models: { ...m, main: r } };
140
+ };
136
141
  const advisorStep = async (s) => {
137
142
  const m = s.models ?? DEFAULT_MODELS;
138
143
  const r = await pick(t(lang, 'ui_models_advisor_q'), m.advisor, [{ value: 'fable', label: 'Fable' }, { value: 'opus', label: 'Opus' }]);
@@ -187,7 +192,7 @@ export async function setupUI(initial, firstRun, lang, o = {}) {
187
192
  }
188
193
  for (let first = firstRun;; first = false) {
189
194
  const m = state.models ?? DEFAULT_MODELS;
190
- const modelsNow = t(lang, 'ui_models_row', { advisor: m.advisor === 'fable' ? 'Fable' : 'Opus', scope: t(lang, `models_scope_${m.scope}`), autofix: t(lang, m.autoFix ? 'ui_on' : 'ui_off') });
195
+ const modelsNow = t(lang, 'ui_models_row', { main: m.main === 'opus' ? 'Opus' : 'Sonnet', advisor: m.advisor === 'fable' ? 'Fable' : 'Opus', scope: t(lang, `models_scope_${m.scope}`), autofix: t(lang, m.autoFix ? 'ui_on' : 'ui_off') });
191
196
  const rows = [
192
197
  ['agents', t(lang, 'ui_m_agents'), state.agents.map((n) => agents[n].label).join(', ') || t(lang, 'doc_none')],
193
198
  ['providers', t(lang, 'ui_m_providers'), state.providers.map((p, i) => `${i + 1}. ${providers[p].label}`).join(' ') || t(lang, 'doc_none')],
@@ -224,7 +229,7 @@ export async function setupUI(initial, firstRun, lang, o = {}) {
224
229
  providers: [providersStep, keysStepFor(state.providers)],
225
230
  keys: [keysStepFor(null)],
226
231
  flow: [flowStep],
227
- models: [advisorStep, scopeStep, autoFixStep],
232
+ models: [mainStep, advisorStep, scopeStep, autoFixStep],
228
233
  lang: [langStep],
229
234
  };
230
235
  const r = await walk(steps[choice]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "your-cto-jev",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
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",
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "scripts": {
39
39
  "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc",
40
- "test": "tsc && node --test \"dist/*.test.js\"",
41
- "prepublishOnly": "npm run build && node --test \"dist/*.test.js\"",
40
+ "test": "tsc && node --test --test-timeout=600000 \"dist/*.test.js\"",
41
+ "prepublishOnly": "npm run build && node --test --test-timeout=600000 \"dist/*.test.js\"",
42
42
  "calibrate": "npm run build && node scripts/calibrate.mjs"
43
43
  },
44
44
  "devDependencies": {