sprag-cli 3.102.0 → 3.103.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/README.ko.md CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  [English](https://github.com/rootstudioyaml/sprag/blob/main/README.md) · [한국어](https://github.com/rootstudioyaml/sprag/blob/main/README.ko.md)
17
17
 
18
- [sprag.io](https://sprag.io) · [벤치마크](https://github.com/rootstudioyaml/sprag/blob/main/docs/BENCHMARK.md)
18
+ [sprag.io](https://sprag.io) · [벤치마크](https://github.com/rootstudioyaml/sprag/blob/main/docs/BENCHMARK.md) · [검증 사례](https://sprag.io/proof/)
19
19
 
20
20
  <a href="https://github.com/rootstudioyaml/sprag/blob/main/README.ko.md#팀"><img src="https://raw.githubusercontent.com/rootstudioyaml/sprag/main/docs/plan-pro-ko.gif" width="640" alt="팀원마다 동물 캐릭터로 앉아 있는 가상 사무실, 지출과 절감액, 좌석, 30일 차트가 있는 조직 대시보드, 한 번 승인하면 모든 컴퓨터에 적용되는 팀 규칙을 차례로 보여 줍니다."></a>
21
21
 
package/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  [English](https://github.com/rootstudioyaml/sprag/blob/main/README.md) · [한국어](https://github.com/rootstudioyaml/sprag/blob/main/README.ko.md)
17
17
 
18
- [sprag.io](https://sprag.io) · [Benchmark](https://github.com/rootstudioyaml/sprag/blob/main/docs/BENCHMARK.md)
18
+ [sprag.io](https://sprag.io) · [Benchmark](https://github.com/rootstudioyaml/sprag/blob/main/docs/BENCHMARK.md) · [Proof](https://sprag.io/proof/)
19
19
 
20
20
  <a href="https://github.com/rootstudioyaml/sprag#teams"><img src="https://raw.githubusercontent.com/rootstudioyaml/sprag/main/docs/plan-pro-en.gif" width="640" alt="A virtual office where every teammate sits as an animal character, then the organization dashboard with spend, savings, seats and a 30-day chart, then team rules approved once and picked up by every machine."></a>
21
21
 
package/bin/cli.js CHANGED
@@ -1005,10 +1005,13 @@ async function main() {
1005
1005
  // The same cached scan says how old the savings figures are: the ledger is
1006
1006
  // filled by route-scan, so a stale scan means a stale total.
1007
1007
  let routeScanAt = null;
1008
+ // Sonnet delegations sprag ran at high effort (see buildDelegatedSeg).
1009
+ let effortRaises = null;
1008
1010
  try {
1009
1011
  const { readRouteScan } = await import('../src/route-scan.js');
1010
1012
  const scan = readRouteScan();
1011
1013
  unresolvedRuns = Number(scan?.unresolvedRuns) || 0;
1014
+ if (scan?.effortRaises && typeof scan.effortRaises === 'object') effortRaises = scan.effortRaises;
1012
1015
  const scannedAt = Date.parse(scan?.scannedAt);
1013
1016
  routeScanAt = Number.isFinite(scannedAt) ? scannedAt : null;
1014
1017
  } catch (e) {
@@ -1092,6 +1095,7 @@ async function main() {
1092
1095
  unresolvedRuns,
1093
1096
  // Statusline-only; left undefined elsewhere so --format json keeps its shape.
1094
1097
  routeScanAt: isStatusline ? routeScanAt : undefined,
1098
+ effortRaises: isStatusline ? effortRaises : undefined,
1095
1099
  sessionDelegation,
1096
1100
  ruleStats,
1097
1101
  ttlBucket,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprag-cli",
3
- "version": "3.102.0",
3
+ "version": "3.103.1",
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": {
package/src/agents.js CHANGED
@@ -97,7 +97,7 @@ export function agentForRule(rule, { agents = agentDefinitions() } = {}) {
97
97
  }
98
98
 
99
99
  /** Model alias an agent (or a legacy agent name) is pinned to, or undefined. */
100
- const modelOf = (name) => AGENT_MODEL[Object.hasOwn(LEGACY_AGENT_NAMES, name) ? LEGACY_AGENT_NAMES[name] : name];
100
+ export const modelOf = (name) => AGENT_MODEL[Object.hasOwn(LEGACY_AGENT_NAMES, name) ? LEGACY_AGENT_NAMES[name] : name];
101
101
 
102
102
  /** Agent a bare tier name stands for when that agent's file exists. */
103
103
  const TIER_AGENT = { sonnet: 't1-worker', opus: 't1h-worker', haiku: 't2-explore' };
@@ -70,6 +70,28 @@ async function refreshRuleSavings(ko, rescan) {
70
70
  }
71
71
  }
72
72
 
73
+ /**
74
+ * Sonnet delegations the guard ran at high effort because the call passed none
75
+ * (src/delegation-guard.js), from the last route-scan. The statusline shows only
76
+ * the count; the cost is said here, along with the fact that the saving above
77
+ * already paid for it. Silent when nothing was raised or the scan is unreadable.
78
+ */
79
+ function printEffortRaises({ ko, money, readScan }) {
80
+ let r;
81
+ try {
82
+ r = readScan()?.effortRaises;
83
+ } catch (e) {
84
+ debug('saved:effort-raises', e);
85
+ return;
86
+ }
87
+ const count = Number(r?.count) || 0;
88
+ if (count <= 0) return;
89
+ const cost = money(Number(r.cost) || 0);
90
+ console.log(ko
91
+ ? `effort 상향: ${count}회 · 실행 비용 ${cost} (effort 없이 Sonnet에 보낸 위임을 high로 올렸습니다. 절감액에는 이미 반영돼 있습니다)`
92
+ : `Effort raised: ${count} runs · run cost ${cost} (sonnet delegations sent without an effort were run at high; the saving above is already net of it)`);
93
+ }
94
+
73
95
  const FAMILY_NAMES = { opus: 'Opus', sonnet: 'Sonnet', haiku: 'Haiku', fable: 'Fable', mythos: 'Mythos' };
74
96
 
75
97
  /**
@@ -118,7 +140,7 @@ async function printModelShare({ ko, dir, money }) {
118
140
  }
119
141
  }
120
142
 
121
- export async function run({ args, hasFlag, agent = 'claude', dir: dirArg, rescan }) {
143
+ export async function run({ args, hasFlag, agent = 'claude', dir: dirArg, rescan, readScan: readScanArg }) {
122
144
  const { userLanguage } = await import('../config.js');
123
145
  const { userDataDir } = await import('../paths.js');
124
146
  const { readResetMarks, resetSaved, undoReset } = await import('../saved-reset.cjs');
@@ -150,12 +172,14 @@ export async function run({ args, hasFlag, agent = 'claude', dir: dirArg, rescan
150
172
 
151
173
  if (sub === undefined) {
152
174
  const marks = readResetMarks(dir);
175
+ const readScan = readScanArg || (await import('../route-scan.js')).readRouteScan;
153
176
  for (const s of scopes) {
154
177
  const t = await currentTotals(s, dir);
155
178
  const since = marks[s] === null
156
179
  ? (ko ? '초기화한 적 없음' : 'not reset')
157
180
  : (ko ? `${fmtTime(marks[s])} 이후` : `since ${fmtTime(marks[s])}`);
158
181
  console.log(`${label(s)}: ${fmtTotal(t)} (${since})`);
182
+ if (s === 'routing') printEffortRaises({ ko, money, readScan });
159
183
  }
160
184
  if (agent !== 'codex') {
161
185
  console.log(ko
@@ -27,6 +27,7 @@ import { homedir } from 'node:os';
27
27
  import { loadConfig, saveConfig } from './config.js';
28
28
  import { recentToolPaths } from './session-paths.js';
29
29
  import { routeCapsFor } from './route-caps.js';
30
+ import { modelOf } from './agents.js';
30
31
 
31
32
  const packageRoot = join(dirname(fileURLToPath(import.meta.url)), '..');
32
33
 
@@ -120,8 +121,12 @@ export async function buildAppendix(payload, { cfg = loadConfig(), home = homedi
120
121
 
121
122
  // Read from `model` first — it is the more specific field when both are set
122
123
  // — falling back to `subagent_type`. Hoisted out of the bounds section
123
- // because the Korean section below weighs the same answer.
124
- const modelHint = String(payload?.tool_input?.model || payload?.tool_input?.subagent_type || '');
124
+ // because the Korean section below weighs the same answer. The preset agents
125
+ // are named by tier (t2-explore, t1h-worker), so a bare subagent_type says
126
+ // nothing about the model until it is looked up; without that every
127
+ // tier-named delegation got the 20-call / 8,000-token sonnet cap.
128
+ const agentName = String(payload?.tool_input?.subagent_type || '');
129
+ const modelHint = String(payload?.tool_input?.model || modelOf(agentName) || agentName);
125
130
  const isHaiku = /haiku/i.test(modelHint);
126
131
  const isOpus = /opus/i.test(modelHint);
127
132
 
@@ -253,10 +258,55 @@ export async function decideForDelegation(payload, { cfg = loadConfig(), home =
253
258
  // same tool_name, must not stack the appendix onto itself.
254
259
  if (prompt.includes(DELEGATION_MARKER)) return null;
255
260
 
261
+ const raise = wantsEffortRaise(toolInput);
256
262
  const appendix = await buildAppendix(payload, { cfg, home, routeCaps });
257
- if (!appendix) return null;
263
+ if (!appendix && !raise) return null;
258
264
 
259
- return { updatedInput: { ...toolInput, prompt: `${prompt}\n\n${appendix}` } };
265
+ const parts = [prompt];
266
+ if (appendix) parts.push(appendix);
267
+ // The marker line goes into the prompt as well as the input: the prompt is
268
+ // what the subagent transcript keeps, so route-scan can later tell a raise
269
+ // this hook made from an effort the caller chose (see src/route-scan.js).
270
+ if (raise) parts.push(EFFORT_RAISE_MARKER);
271
+ const updatedInput = { ...toolInput, prompt: parts.join('\n\n') };
272
+ if (raise) updatedInput.effort = RAISED_EFFORT;
273
+ return { updatedInput };
274
+ }
275
+
276
+ /** Effort a sonnet delegation runs at when the call passed none. */
277
+ export const RAISED_EFFORT = 'high';
278
+
279
+ /**
280
+ * Line appended to the prompt of a delegation whose effort this hook set.
281
+ * route-scan greps subagent transcripts for it, so the text is part of the
282
+ * ledger's contract: change it and the count of raises resets to zero.
283
+ */
284
+ export const EFFORT_RAISE_MARKER = 'Effort for this delegation: high (set by sprag; the call did not pass one).';
285
+
286
+ /**
287
+ * True when the call hands work to a sonnet target that pins no effort of
288
+ * its own, and the caller passed none.
289
+ *
290
+ * Why sonnet, and why high. A `general-purpose` call with `model: sonnet` is
291
+ * the route the rules give a lookup that spans several files or a delegated
292
+ * investigation, and without an effort argument Claude Code runs it at
293
+ * medium. Replayed on fixed cases (2026-11-07, blind-graded): the multi-file
294
+ * lookup was relayable at medium in 0 of 3 runs and at high in 2 of 3, for
295
+ * about 25% more cost; across six new cases sonnet at high was relayable in
296
+ * 5 at 30–60% of the Opus cost. Medium was where the silent losses came
297
+ * from, so high is the floor this hook sets.
298
+ *
299
+ * Left alone: the preset agents (t1-worker is high, the t2 agents low —
300
+ * their files pin it, and the haiku agents were fine at low on the work the
301
+ * rules send them), a call that names an effort (the caller's choice,
302
+ * including the escalation step that passes the next level up), and haiku or
303
+ * opus targets, where no measurement backs a change.
304
+ */
305
+ export function wantsEffortRaise(toolInput) {
306
+ if (!toolInput || typeof toolInput !== 'object') return false;
307
+ if (typeof toolInput.effort === 'string' && toolInput.effort !== '') return false;
308
+ if (modelOf(String(toolInput.subagent_type || ''))) return false;
309
+ return /sonnet/i.test(String(toolInput.model || ''));
260
310
  }
261
311
 
262
312
  /**
@@ -1146,6 +1146,15 @@ function buildDelegatedSeg(data, singleLine, c, isIcon, verbose, g) {
1146
1146
  const delegateSeg = savingsChip || (delegationSaved === 0 ? unresolvedSeg : null);
1147
1147
  const delegateExtra = savingsChip && delegationSaved === 0 ? unresolvedSeg : null;
1148
1148
 
1149
+ // Sonnet delegations the guard ran at high effort because the call passed
1150
+ // none. Gray, since it is a cost and not a saving: the savings beside it are
1151
+ // already net of it, and `sprag saved` prints what the runs cost.
1152
+ // icon: "🔬↑3" | text: "effort↑3" | verbose: "effort raised ×3"
1153
+ const raised = Number(data.effortRaises && data.effortRaises.count) || 0;
1154
+ const raisedSeg = raised > 0
1155
+ ? `${c(GRAY)}${verbose ? `effort raised ×${raised}` : isIcon ? `${g.effort}↑${raised}` : `effort↑${raised}`}${c(RESET)}`
1156
+ : null;
1157
+
1149
1158
  // Routing-savings headline line (multi-line layout). The lifetime sum from
1150
1159
  // the delegation ledger — the number the whole tool exists to grow, so it
1151
1160
  // gets line 1 to itself while the diagnostics move to line 2.
@@ -1194,7 +1203,10 @@ function buildDelegatedSeg(data, singleLine, c, isIcon, verbose, g) {
1194
1203
  // would otherwise repeat it on line 2. The unresolved-runs chip survives the
1195
1204
  // headline when that headline is a dated zero, since a zero is exactly when
1196
1205
  // the dropped runs matter.
1197
- chips: totalsLine ? (totalsNum === 0 ? [unresolvedSeg] : []) : [delegateSeg, delegateExtra],
1206
+ // The raise count is not part of that story, so it stays on line 2 either way.
1207
+ chips: totalsLine
1208
+ ? (totalsNum === 0 ? [unresolvedSeg, raisedSeg] : [raisedSeg])
1209
+ : [delegateSeg, raisedSeg, delegateExtra],
1198
1210
  headline: totalsLine ? { usd: Number(totals && totals.total) || 0, line: totalsLine } : null,
1199
1211
  };
1200
1212
  }
@@ -307,7 +307,13 @@ export function renderModelRatchet(rules, lang = userLanguage(), { root } = {})
307
307
  ' 위임하지 않습니다.',
308
308
  '- 웹에서 뉴스나 대안, 후보를 찾는 열린 조사는 위임하지 않습니다. 하위 모델이',
309
309
  ' 몇 번 검색하고 멈춰도 무엇을 빠뜨렸는지 드러나지 않기 때문입니다. 조사를',
310
- ' 위임한 결과를 전달할 때는 어디까지 찾았는지 먼저 확인합니다.',
310
+ ' 위임한 결과를 전달할 때는 어디까지 찾았는지 먼저 확인합니다. 사용자가 그래도',
311
+ ' 위임을 원하면 sonnet에 effort xhigh로 보냅니다(실측: 최근 뉴스 조사에서 medium과',
312
+ ' high는 6회 중 한 번도 핵심 소식을 찾지 못했고 xhigh는 3회 모두 찾았으며 비용은',
313
+ ' Opus의 약 80%였습니다).',
314
+ '- 사용자만 아는 맥락(이미 반려된 후보, 앞서 정한 조건)은 위임 지시문에 적습니다.',
315
+ ' 서브에이전트는 그 맥락을 볼 수 없어서 effort를 올려도 찾지 못합니다(실측: effort를',
316
+ ' 바꿔 9회 돌렸고 9회 모두 반려된 후보를 다시 추천했습니다).',
311
317
  '',
312
318
  '## 티어 판별 기준 (모든 룰에 공통 적용)',
313
319
  '',
@@ -327,6 +333,9 @@ export function renderModelRatchet(rules, lang = userLanguage(), { root } = {})
327
333
  ' 구현하는 위임(sonnet 워커)과 범위가 큰 구현·디버깅 위임(opus 워커)은 high다.',
328
334
  ' 두 워커는 effort가 아니라 모델 티어로 나뉜다. 메인 세션의 effort는 바꾸지 않고,',
329
335
  ' CLAUDE_CODE_EFFORT_LEVEL은 서브에이전트의 effort를 덮어쓰므로 설정하지 않는다.',
336
+ ' 여러 파일을 뒤져야 답이 나오는 조회는 effort high 이상에서 맡긴다. t1-worker는',
337
+ ' 이미 high이고, general-purpose로 보낼 때는 Agent 호출의 effort 인자에 high를',
338
+ ' 넘긴다(실측: medium은 3회 모두 일부를 놓쳤고 high는 3회 중 2회 모두 찾았다).',
330
339
  '- **고난도 구현(T1H)**: 설계는 메인이 확정하고, 범위가 크거나 sonnet 이 틀린',
331
340
  ' 적 있는 구현·디버깅은 opus 에 위임한다. Fable·Mythos 세션에서만 적용되며,',
332
341
  ' 설계 판단과 되돌릴 수 없는 작업은 메인 모델에 남긴다.',
@@ -379,6 +388,13 @@ export function renderModelRatchet(rules, lang = userLanguage(), { root } = {})
379
388
  '- Do not delegate open research on the web (news, alternatives, candidates):',
380
389
  ' a cheaper model stops after a few searches and nothing shows what it missed.',
381
390
  ' Before relaying any delegated research, check how far it actually searched.',
391
+ ' If the user still wants it delegated, send it to sonnet at effort xhigh',
392
+ ' (measured: on a recent-news search, medium and high found the key story in',
393
+ ' 0 of 6 runs, xhigh in 3 of 3, at about 80% of the Opus cost).',
394
+ '- Write context only the user knows (candidates already rejected, conditions',
395
+ ' settled earlier) into the delegation prompt. The subagent cannot see it, and',
396
+ ' no effort level makes up for that (measured: 9 runs across efforts, all 9',
397
+ ' recommended the rejected candidate again).',
382
398
  '',
383
399
  '## Tier criteria (apply to every rule below)',
384
400
  '',
@@ -401,6 +417,10 @@ export function renderModelRatchet(rules, lang = userLanguage(), { root } = {})
401
417
  ' sonnet worker) and for large implementation or debugging (the opus',
402
418
  ' worker); the tier, not the effort, separates the two workers. Leave the main session\'s effort alone, and never set',
403
419
  ' CLAUDE_CODE_EFFORT_LEVEL: it overrides every subagent\'s own value.',
420
+ ' A lookup that has to search across many files runs at effort high or',
421
+ ' above. t1-worker already is; through general-purpose, pass high in the',
422
+ ' Agent call\'s effort argument (measured: medium missed part of the answer',
423
+ ' in 3 of 3 runs, high found all of it in 2 of 3).',
404
424
  '- **Heavy implementation (T1H)**: the main model fixes the design; large-scope',
405
425
  ' implementation or debugging, or work sonnet has already got wrong, goes to',
406
426
  ' opus. Applies in Fable/Mythos sessions only; design judgement and',
package/src/route-scan.js CHANGED
@@ -724,6 +724,12 @@ export async function runRouteScan({ days = 14, trace = null } = {}) {
724
724
  const delegatedStats = new Map(); // "tier|category|project" → outcome aggregate
725
725
  let unresolvedRuns = 0; // delegated runs dropped for an unpriceable model id
726
726
  const unresolvedModels = new Set();
727
+ // Sonnet delegations the guard ran at high effort because the call passed
728
+ // none (src/delegation-guard.js). Counted whether or not a rule covers the
729
+ // run: the raise is sprag's own action, so its price is shown even where no
730
+ // saving is claimed. The figure is what those runs cost on their own model,
731
+ // priced the way the ledger prices `cost`; the savings already include it.
732
+ const effortRaises = { count: 0, cost: 0, since: null };
727
733
  // `sprag saved reset routing` zeroes the money, not the rule-health sample:
728
734
  // see tallyDelegatedRun. readResetMarks never throws (no file = no reset).
729
735
  const routingMark = readResetMarks(userDataDir()).routing;
@@ -765,6 +771,18 @@ export async function runRouteScan({ days = 14, trace = null } = {}) {
765
771
  // registry credit a run to the same rule.
766
772
  const ruleForRun = (tier, catId, projectDir) => ruleForProject(ledgerRules, tier, catId, projectDir);
767
773
  for (const [sessionPath, index] of runIndexBySession) {
774
+ // Every run of the session, not only those joined to a categorized episode
775
+ // and past the tier gate: a sonnet run under a sonnet main session saves
776
+ // nothing, yet the guard raised it all the same. The reset mark applies as
777
+ // it does to savings (tallyDelegatedRun).
778
+ for (const run of index.all) {
779
+ if (!run.effortRaised || isBeforeReset(run.endedAt ?? run.startedAt, routingMark)) continue;
780
+ effortRaises.count += 1;
781
+ const cost = isRecognizedModelId(run.model) ? exactCost(runTotals(run), run.model, { at: runTime(run) }) : null;
782
+ if (Number.isFinite(cost)) effortRaises.cost += cost;
783
+ const at = run.startedAt ?? run.endedAt;
784
+ if (Number.isFinite(at) && (effortRaises.since === null || at < effortRaises.since)) effortRaises.since = at;
785
+ }
768
786
  const used = new Set();
769
787
  const eps = all.filter((x) => x.sessionPath === sessionPath);
770
788
  // Two passes over the session, not one per episode: every exact tool_use
@@ -909,6 +927,8 @@ export async function runRouteScan({ days = 14, trace = null } = {}) {
909
927
  resolved: [...resolved],
910
928
  unresolvedRuns,
911
929
  unresolvedModels: [...unresolvedModels].slice(0, 5),
930
+ // `since` is the earliest counted run (ms), so a reader can date the count.
931
+ effortRaises: { ...effortRaises, cost: Math.round(effortRaises.cost * 100) / 100 },
912
932
  };
913
933
  try {
914
934
  const dir = stateDir();
@@ -31,6 +31,8 @@ import { readdir, readFile, stat } from 'node:fs/promises';
31
31
  import { join, dirname, basename } from 'node:path';
32
32
  import { collectSessionRecords, normalizeModelId } from './session-records.js';
33
33
  import { LONG_PROMPT_THRESHOLD } from './cost.js';
34
+ import { transcriptLines } from './transcript-lines.js';
35
+ import { EFFORT_RAISE_MARKER } from './delegation-guard.js';
34
36
 
35
37
  /** Directory holding a session's subagent transcripts (may not exist). */
36
38
  export function subagentDirFor(sessionPath) {
@@ -45,6 +47,47 @@ async function readMeta(metaPath) {
45
47
  }
46
48
  }
47
49
 
50
+ function messageText(content) {
51
+ if (typeof content === 'string') return content;
52
+ if (!Array.isArray(content)) return '';
53
+ return content.map((b) => (b && b.type === 'text' && typeof b.text === 'string' ? b.text : '')).join('\n');
54
+ }
55
+
56
+ /**
57
+ * What the run was told about its effort: whether the delegation guard raised
58
+ * it (the marker line it appends to the prompt), and the level the transcript
59
+ * records on its entries.
60
+ *
61
+ * collectSessionRecords runs with content off for subagent transcripts, since
62
+ * the text of every turn is never needed here, so the prompt is read on its own.
63
+ * Only the head of the file is: the prompt is the first user entry and the first
64
+ * assistant entry carries the effort, so the read stops after a few lines. A
65
+ * transcript that records no effort at all is read to the end, and the
66
+ * substring test keeps those lines from being parsed.
67
+ */
68
+ async function readRunEffort(jsonlPath) {
69
+ let raised = null;
70
+ let effort = null;
71
+ try {
72
+ for await (const line of transcriptLines(jsonlPath)) {
73
+ const wantsPrompt = raised === null && line.includes('"type":"user"');
74
+ const wantsEffort = effort === null && line.includes('"effort"');
75
+ if (!wantsPrompt && !wantsEffort) continue;
76
+ let entry;
77
+ try { entry = JSON.parse(line); } catch { continue; }
78
+ if (effort === null && typeof entry.effort === 'string' && entry.effort) effort = entry.effort;
79
+ if (raised === null && entry.type === 'user' && entry.message) {
80
+ // The guard appends the marker as the prompt's last line, so only a
81
+ // prompt that ends with it was raised. A prompt that merely quotes the
82
+ // line (a delegation about this very feature did) is not one.
83
+ raised = messageText(entry.message.content).trimEnd().endsWith(EFFORT_RAISE_MARKER);
84
+ }
85
+ if (raised !== null && effort !== null) break;
86
+ }
87
+ } catch { /* unreadable here means unreadable above too; report no raise */ }
88
+ return { effortRaised: raised === true, effort };
89
+ }
90
+
48
91
  /**
49
92
  * A run's model when several appear in one transcript (a harness retry can
50
93
  * switch tiers mid-run): the one that produced the most output, since that is
@@ -139,6 +182,9 @@ export async function collectSubagentRun(jsonlPath) {
139
182
  run.toolUseId = meta.toolUseId ?? null;
140
183
  run.spawnDepth = meta.spawnDepth ?? null;
141
184
  }
185
+ // A raise is sprag's own doing, so route-scan counts these runs and their
186
+ // cost apart from any rule (see effortRaises there).
187
+ Object.assign(run, await readRunEffort(jsonlPath));
142
188
  try {
143
189
  run.bytes = (await stat(jsonlPath)).size;
144
190
  } catch { /* size only feeds the rescan gate — 0 is a safe under-estimate */ }