sprag-cli 3.85.0 → 3.87.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprag-cli",
3
- "version": "3.85.0",
3
+ "version": "3.87.0",
4
4
  "description": "Model-delegation router for Claude Code and Codex: lookups, checks and test runs go to cheaper models, documents go in as compact Markdown, and a live statusline shows spend and savings.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -116,7 +116,7 @@
116
116
  },
117
117
  {
118
118
  "name": "t1h-worker",
119
- "model": "claude-opus-5-5",
119
+ "model": "opus",
120
120
  "effort": "high",
121
121
  "tier": "T1H",
122
122
  "categories": [
@@ -90,9 +90,12 @@ function catalogCodexModels(home) {
90
90
  * the parent, so the hint never names a model the gateway cannot serve. The
91
91
  * cheapest is T2 and the next one up is T1; with a single candidate T1 stays
92
92
  * on the main agent. T1H is the most expensive cheaper model, and only when
93
- * there are at least three candidates, so that it differs from T1. Returns { targets, reason }.
93
+ * there are at least three candidates, so that it differs from T1. Each target
94
+ * carries the reasoning effort the preset agents give its tier, the value the
95
+ * Claude agent files pin. Returns { targets, reason }.
94
96
  */
95
- export function autoCodexSharedTargets({ dir = userDataDir(), home = codexUserDir(), model, provider, now = Date.now() } = {}) {
97
+ export function autoCodexSharedTargets({ dir = userDataDir(), home = codexUserDir(), model, provider, now = Date.now(),
98
+ agents } = {}) {
96
99
  if (!safeId(model) || !safeId(provider)) return { targets: [], reason: 'unknown parent model or provider' };
97
100
  const book = codexPriceBook(provider, readCodexPrices({ now, home, dir }), { home });
98
101
  if (!book) return { targets: [], reason: `no price table for ${provider}` };
@@ -110,10 +113,25 @@ export function autoCodexSharedTargets({ dir = userDataDir(), home = codexUserDi
110
113
  }
111
114
  const picks = cheaper.slice(0, 2).map((x, i) => ({ tier: i === 0 ? 'T2' : 'T1', x }));
112
115
  if (cheaper.length >= 3) picks.push({ tier: 'T1H', x: cheaper.at(-1) });
113
- const targets = picks.map(({ tier, x }) => ({ tier, from: model, model: x.model, provider, auto: true }));
116
+ agents ??= agentDefinitions();
117
+ const targets = picks.map(({ tier, x }) => {
118
+ const effort = tierPresetEffort(tier, agents);
119
+ return { tier, from: model, model: x.model, ...(effort ? { effort } : {}), provider, auto: true };
120
+ });
114
121
  return { targets, reason: null };
115
122
  }
116
123
 
124
+ /**
125
+ * The effort every preset agent of a tier shares, or undefined when they
126
+ * disagree or name none: a mixed tier leaves Codex on the model's default
127
+ * rather than guessing which role the request will run as.
128
+ */
129
+ export function tierPresetEffort(tier, agents = agentDefinitions()) {
130
+ const efforts = new Set(agents.filter((a) => a && a.tier === tier).map((a) => a.effort));
131
+ const [effort] = efforts;
132
+ return efforts.size === 1 && effort && validEffort(effort) ? effort : undefined;
133
+ }
134
+
117
135
  /**
118
136
  * Explicit mappings win per tier. Without one, a tier resolves automatically
119
137
  * unless the user turned that off; resolution runs only for an enabled Codex
@@ -171,6 +171,19 @@ async function agentsCommand(action, lang) {
171
171
  const st = da.delegationAgentStatus();
172
172
  console.log(ko ? `delegate agents: ${st.enabled ? 'on' : 'off'}` : `delegate agents: ${st.enabled ? 'on' : 'off'}`);
173
173
  const label = { 'installed-by-sprag': ko ? 'sprag 가 설치함' : 'installed by sprag', 'user-file': ko ? '직접 만든 파일' : 'user file', absent: ko ? '없음' : 'absent' };
174
- for (const a of st.agents) console.log(` ${a.name}: ${a.state} (${label[a.state]})`);
174
+ for (const a of st.agents) {
175
+ let extra = '';
176
+ if (a.drift) {
177
+ const { file, preset } = a.drift;
178
+ const parts = [`effort ${file.effort || '-'}`];
179
+ const ps = [`effort ${preset.effort || '-'}`];
180
+ if (da.modelFamily(file.model) !== da.modelFamily(preset.model)) {
181
+ parts.push(ko ? `모델 ${file.model || '-'}` : `model ${file.model || '-'}`);
182
+ ps.push(ko ? `모델 ${preset.model || '-'}` : `model ${preset.model || '-'}`);
183
+ }
184
+ extra = ko ? ` · ${parts.join(' · ')}, 프리셋 ${ps.join(' · ')}` : ` · ${parts.join(' · ')}, preset ${ps.join(' · ')}`;
185
+ }
186
+ console.log(` ${a.name}: ${a.state} (${label[a.state]}${extra})`);
187
+ }
175
188
  console.log(ko ? '켜기 또는 끄기: sprag delegate agents on|off' : 'Toggle with: sprag delegate agents on|off');
176
189
  }
@@ -376,6 +376,8 @@ export async function run({ args, hasFlag, numArg }) {
376
376
  // where the *asking* happens: the model gets one line telling it a newer
377
377
  // version exists and to ask before installing anything. Cached read only
378
378
  // — the refresh runs detached off the statusline path, never here.
379
+ let driftBlock = null;
380
+ try { driftBlock = (await import('../delegation-agents.js')).takeAgentDriftNotice({ lang }); } catch (e) { debug('route-scan:agent-drift', e); }
379
381
  let updateBlock = null;
380
382
  try {
381
383
  const { updateOffer } = await import('../update-notice.js');
@@ -391,6 +393,7 @@ export async function run({ args, hasFlag, numArg }) {
391
393
  if (open.length === 0 && reviewRules.length === 0) {
392
394
  if (teamBlock) console.log(teamBlock);
393
395
  if (updateBlock) console.log(updateBlock);
396
+ if (driftBlock) console.log(driftBlock);
394
397
  if (seedBlock) console.log(seedBlock);
395
398
  if (doc2mdBlock) console.log(doc2mdBlock);
396
399
  if (koreanBlock) console.log(koreanBlock);
@@ -399,6 +402,7 @@ export async function run({ args, hasFlag, numArg }) {
399
402
  }
400
403
  if (teamBlock) console.log(teamBlock);
401
404
  if (updateBlock) console.log(updateBlock);
405
+ if (driftBlock) console.log(driftBlock);
402
406
  if (seedBlock) console.log(seedBlock);
403
407
  if (doc2mdBlock) console.log(doc2mdBlock);
404
408
  // This text is injected straight into the model's context, so it must
@@ -15,8 +15,8 @@
15
15
  import { existsSync, readFileSync, writeFileSync, mkdirSync, unlinkSync, readdirSync } from 'node:fs';
16
16
  import { join } from 'node:path';
17
17
  import { claudeUserDir } from './paths.js';
18
- import { loadConfig } from './config.js';
19
- import { agentDefinitions } from './presets-source.js';
18
+ import { loadConfig, saveConfig } from './config.js';
19
+ import { agentDefinitions, cliVersion, presetSource } from './presets-source.js';
20
20
 
21
21
  export const OWNER_MARK = 'sprag:delegation-agent';
22
22
  const MARK_LINE = `# managed by sprag (${OWNER_MARK}); edits are overwritten`;
@@ -26,9 +26,11 @@ const MARK_LINE = `# managed by sprag (${OWNER_MARK}); edits are overwritten`;
26
26
  // { name, model, effort, tools: [..], description: { ko, en }, body: { ko, en } }
27
27
  //
28
28
  // Models are aliases on purpose: behind a gateway they resolve through
29
- // ANTHROPIC_DEFAULT_*_MODEL, and a full model id would bypass that mapping. The
30
- // exception is t1h-worker, which names the full id: Claude Code resolves a bare
31
- // alias to an older model than the one the tier means.
29
+ // ANTHROPIC_DEFAULT_*_MODEL, and a full model id would bypass that mapping.
30
+ // t1h-worker used to pin claude-opus-5-5 because older Claude Code releases
31
+ // resolved the haiku alias to Haiku 4.5; 2.1.302 resolves opus, sonnet and
32
+ // haiku to the current 5.5 models on the first-party API, so all five agents
33
+ // use aliases (preset v4).
32
34
  //
33
35
  // Effort is a separate axis from the tier and is set by how the work gets
34
36
  // verified, not by how hard it is. Where the check is command output or a file
@@ -141,7 +143,75 @@ export function delegationAgentStatus() {
141
143
  const agents = definitions().map((def) => {
142
144
  const f = existsSync(fileOf(def.name)) ? readOwned(fileOf(def.name)) : null;
143
145
  const state = !f ? 'absent' : isOwned(f.text) ? 'installed-by-sprag' : 'user-file';
144
- return { name: def.name, state };
146
+ return { name: def.name, state, drift: f && state === 'user-file' ? driftOf(def, f.text) : null };
145
147
  });
146
148
  return { enabled, agents };
147
149
  }
150
+
151
+ /** `model` and `effort` from the leading frontmatter block; null when absent. */
152
+ function readFrontmatterSpec(text) {
153
+ const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
154
+ const field = (key) => {
155
+ const hit = m && new RegExp(`^${key}:[ \\t]*(.*?)[ \\t]*$`, 'm').exec(m[1]);
156
+ return hit && hit[1] ? hit[1] : null;
157
+ };
158
+ return { model: field('model'), effort: field('effort') };
159
+ }
160
+
161
+ /** fable, opus, sonnet or haiku, so an alias and a pinned id of one family compare equal. */
162
+ export function modelFamily(model) {
163
+ const hit = /fable|opus|sonnet|haiku/.exec(String(model || '').toLowerCase());
164
+ return hit ? hit[0] : null;
165
+ }
166
+
167
+ function driftOf(def, text) {
168
+ const file = readFrontmatterSpec(text);
169
+ const preset = { model: def.model || null, effort: def.effort || null };
170
+ const same = file.effort === preset.effort && modelFamily(file.model) === modelFamily(preset.model);
171
+ return same ? null : { name: def.name, file, preset };
172
+ }
173
+
174
+ /**
175
+ * User-owned agent files whose model family or effort differs from the preset.
176
+ * sync never touches them, so this is the only place the difference shows.
177
+ */
178
+ export function agentDrift() {
179
+ const out = [];
180
+ for (const def of definitions()) {
181
+ const f = existsSync(fileOf(def.name)) ? readOwned(fileOf(def.name)) : null;
182
+ if (!f || isOwned(f.text)) continue;
183
+ const d = driftOf(def, f.text);
184
+ if (d) out.push(d);
185
+ }
186
+ return out;
187
+ }
188
+
189
+ /**
190
+ * Session-start notice for agentDrift(), shown once per preset version: the
191
+ * key is remembered in config, and a newly published version changes it.
192
+ * Returns null when there is no drift or this key was already announced.
193
+ */
194
+ export function takeAgentDriftNotice({ lang = 'ko' } = {}) {
195
+ const drift = agentDrift();
196
+ if (drift.length === 0) return null;
197
+ const src = presetSource();
198
+ // The bundled presets carry no version of their own; they change with the CLI.
199
+ const key = `${src.kind}:${src.kind === 'remote' ? src.version : cliVersion()}`;
200
+ const cfg = loadConfig();
201
+ if (cfg.agentDriftNoticedKey === key) return null;
202
+ saveConfig({ ...cfg, agentDriftNoticedKey: key });
203
+ const ko = lang === 'ko';
204
+ const label = src.kind === 'remote' ? `v${src.version}` : 'bundled';
205
+ const v = (x) => x || '-';
206
+ return [
207
+ ko
208
+ ? `[sprag agents] 프리셋 ${label}이 지정한 값과 다른 직접 만든 에이전트 파일이 있어서, sync가 이 파일들을 덮어쓰지 않았습니다.`
209
+ : `[sprag agents] Some agent files you made yourself differ from what preset ${label} specifies, so sync did not overwrite them.`,
210
+ ...drift.map((d) => ko
211
+ ? `- ${d.name}: 파일 effort ${v(d.file.effort)} · 모델 ${v(d.file.model)}, 프리셋 effort ${v(d.preset.effort)} · 모델 ${v(d.preset.model)}`
212
+ : `- ${d.name}: file effort ${v(d.file.effort)} · model ${v(d.file.model)}, preset effort ${v(d.preset.effort)} · model ${v(d.preset.model)}`),
213
+ ko
214
+ ? 'sprag가 관리하게 하려면 파일을 지운 뒤 `sprag delegate agents on` 을 실행합니다. 지금 값을 유지하려면 그대로 두면 되고, 이 안내는 프리셋 버전이 바뀔 때만 다시 나옵니다. 사용자에게 이 차이를 한 줄로 알리십시오.'
215
+ : 'To let sprag manage them, delete the files and run `sprag delegate agents on`. To keep the current values, leave them as they are; this notice returns only when the preset version changes. Tell the user about this difference in one line.',
216
+ ].join('\n');
217
+ }