sumo-agents 0.7.1 → 0.8.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/CHANGELOG.md +124 -0
- package/README.md +46 -21
- package/package.json +2 -1
- package/prompts/scribe.md +1 -1
- package/src/apply.mjs +16 -12
- package/src/auth.mjs +2 -2
- package/src/card.mjs +3 -2
- package/src/catalog.mjs +100 -13
- package/src/chat.mjs +111 -31
- package/src/check.mjs +17 -15
- package/src/cli.mjs +21 -11
- package/src/cost.mjs +2 -4
- package/src/cursor.mjs +405 -0
- package/src/db.mjs +24 -13
- package/src/dream.mjs +2 -2
- package/src/jobs.mjs +72 -34
- package/src/ledger.mjs +4 -3
- package/src/loop.mjs +157 -77
- package/src/mcp.mjs +7 -9
- package/src/memeval.mjs +2 -3
- package/src/memory.mjs +5 -4
- package/src/model.mjs +5 -0
- package/src/page.mjs +1 -0
- package/src/prime.mjs +11 -7
- package/src/rebuild.mjs +8 -3
- package/src/redact.mjs +13 -1
- package/src/route.mjs +263 -56
- package/src/sandbox.mjs +86 -20
- package/src/scan.mjs +4 -2
- package/src/scorecard.mjs +419 -0
- package/src/scribe.mjs +82 -38
- package/src/sessions.mjs +29 -21
- package/src/settings.mjs +114 -37
- package/src/setup.mjs +33 -14
- package/src/spool.mjs +68 -43
- package/src/tools.mjs +220 -98
- package/src/ui.mjs +14 -5
- package/src/verify.mjs +116 -15
- package/src/worktree.mjs +93 -9
package/src/chat.mjs
CHANGED
|
@@ -13,7 +13,8 @@ import { COMPACT_INSTRUCTIONS, compactionParams, contextFor, converse, describeF
|
|
|
13
13
|
import { logRun, usageOf } from './model.mjs';
|
|
14
14
|
import { closeMcp, compactInput, gateMcp, isMcpTool, mcpLines, mcpReady, splitMcpName } from './mcp.mjs';
|
|
15
15
|
import { EFFORT_MESSAGE_BETA, effortOnly } from './auth.mjs';
|
|
16
|
-
import { assertOn,
|
|
16
|
+
import { ALL_MODELS, assertOn, laneOf, MODEL_IDS, modelId, modelName, usableJobModels, usableModels } from './catalog.mjs';
|
|
17
|
+
import { converseCursor } from './cursor.mjs';
|
|
17
18
|
import { takeLock } from './lock.mjs';
|
|
18
19
|
import { paths, REPO_ROOT } from './paths.mjs';
|
|
19
20
|
import { UsageError } from './memory.mjs';
|
|
@@ -21,6 +22,7 @@ import { openInBrowser, servePage } from './page.mjs';
|
|
|
21
22
|
import { getProject, projectAt, scratchDir } from './projects.mjs';
|
|
22
23
|
import { redact } from './redact.mjs';
|
|
23
24
|
import { chooseChatRoute, EFFORTS } from './route.mjs';
|
|
25
|
+
import { refreshScorecard, scorecardReport } from './scorecard.mjs';
|
|
24
26
|
import { verifyCommands } from './scan.mjs';
|
|
25
27
|
import { passLines, runMemoryPass } from './keeper.mjs';
|
|
26
28
|
import { currentProject, describeSaved, findSaved, loadState, lockFile, noteSessionOutside, recordTurn, saveState, savedSessions, sessionLine, shortId, withoutThinking } from './sessions.mjs';
|
|
@@ -28,7 +30,7 @@ import { ASK_TOOL, BASH_TOOL, cap, capRedacted, DELEGATE_TOOL, EDITOR_TOOL, INTE
|
|
|
28
30
|
import { CONFIG_DEFAULTS } from './setup.mjs';
|
|
29
31
|
import { closest, estimateTokens, head } from './text.mjs';
|
|
30
32
|
import { colourEnabled, createRenderer, explained, header, pathFrom, prompt, renderBlock, safeForTerminal, styles, tilde, toolView, widthOf, wrap } from './tty.mjs';
|
|
31
|
-
import { hasCommit } from './verify.mjs';
|
|
33
|
+
import { changesSince, hasCommit, snapshot } from './verify.mjs';
|
|
32
34
|
import { isWebTool, sourcesOf, WEB_FETCH_TOOL, WEB_SEARCH_TOOL, WEB_TOOLS } from './web.mjs';
|
|
33
35
|
|
|
34
36
|
/**
|
|
@@ -63,6 +65,8 @@ const MODEL_HINTS = {
|
|
|
63
65
|
sonnet: 'everyday features and fixes',
|
|
64
66
|
opus: 'hard problems: design, a bug with no clear cause',
|
|
65
67
|
fable: 'novel work: new algorithms, deep reviews',
|
|
68
|
+
composer: "Cursor's own coding model, from your plan's pool",
|
|
69
|
+
grok: "xAI's Grok through Cursor, from your plan's pool",
|
|
66
70
|
};
|
|
67
71
|
/** And each effort: how much the model thinks before it acts. */
|
|
68
72
|
const EFFORT_HINTS = { low: 'quickest: one spot', medium: 'a few files', high: 'many parts that work together', xhigh: 'more thought still, slower', max: 'the most thought, the slowest' };
|
|
@@ -80,7 +84,7 @@ function commandList(db, { effortNow = () => null, inUse = () => ({}), saved = (
|
|
|
80
84
|
};
|
|
81
85
|
const marked = (name, hint, current) => ({ name, hint: `${hint}${name === current ? ' (current)' : ''}` });
|
|
82
86
|
const modelChoices = (given) => {
|
|
83
|
-
const usable =
|
|
87
|
+
const usable = usableJobModels(db);
|
|
84
88
|
const { model, effort } = inUse();
|
|
85
89
|
if (given.length === 0) return ['auto', ...usable].map((name) => marked(name, MODEL_HINTS[name] ?? '', model));
|
|
86
90
|
return given.length === 1 && usable.includes(given[0]) ? efforts().map((name) => marked(name, EFFORT_HINTS[name] ?? '', model === 'auto' ? null : effort)) : [];
|
|
@@ -97,6 +101,7 @@ function commandList(db, { effortNow = () => null, inUse = () => ({}), saved = (
|
|
|
97
101
|
{ name: 'undo', hint: 'put back the files the last turn edited' },
|
|
98
102
|
{ name: 'stop', args: '[job]', hint: 'stop a job working in the background', choices: (given) => (given.length === 0 ? running().map((id) => `j${id}`) : []) },
|
|
99
103
|
{ name: 'context', hint: 'how full the context is, and what it has cost' },
|
|
104
|
+
{ name: 'scorecard', hint: 'fetch the benchmarks routing reads, step by step' },
|
|
100
105
|
{ name: 'export', args: '[path]', hint: 'save the conversation as a Markdown file' },
|
|
101
106
|
{ name: 'thinking', args: 'on|off', hint: "show or hide the model's thinking as it works", choices: (given) => (given.length === 0 ? ['on', 'off'] : []) },
|
|
102
107
|
{ name: 'config', hint: 'every setting, on one page' },
|
|
@@ -207,7 +212,7 @@ function parseRoute(args, current, db) {
|
|
|
207
212
|
if (effort) throw new UsageError('auto takes no effort — the router picks it each turn');
|
|
208
213
|
return { model: 'auto', effort: null };
|
|
209
214
|
}
|
|
210
|
-
if (!
|
|
215
|
+
if (!ALL_MODELS.includes(model)) throw new UsageError(`no such model "${model}" — one of: auto, ${usableJobModels(db).join(', ')}`);
|
|
211
216
|
assertOn(db, model);
|
|
212
217
|
if (rest.length > 0) throw new UsageError(`/model takes a model and an effort, not "${args}"`);
|
|
213
218
|
if (effort !== undefined && !EFFORTS.includes(effort)) throw new UsageError(`no such effort "${effort}" — one of: ${EFFORTS.join(', ')}`);
|
|
@@ -289,6 +294,11 @@ function configured(db, key) {
|
|
|
289
294
|
return getMeta(db, `config.${key}`) ?? CONFIG_DEFAULTS[key];
|
|
290
295
|
}
|
|
291
296
|
|
|
297
|
+
function isCheck(command) {
|
|
298
|
+
if (/[;&|<>\n`$]/.test(command) || /(?:^|\s)(?:--help|--version|-h|--collect-only)(?:\s|$)/.test(command)) return false;
|
|
299
|
+
return /^(?:node\s+--test|(?:python3?\s+-m\s+)?pytest|python3?\s+-m\s+unittest|go\s+test|cargo\s+test|(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:test|check|lint|typecheck)|make\s+(?:test|check)|test\s+-[efs]\s+\S+)(?:\s|$)/.test(command);
|
|
300
|
+
}
|
|
301
|
+
|
|
292
302
|
/** The chat's own tools, in a fixed order so its cached prefix never moves; the MCP servers' come after them. */
|
|
293
303
|
export const CHAT_TOOLS = [BASH_TOOL, EDITOR_TOOL, DELEGATE_TOOL, ASK_TOOL, ...WEB_TOOLS];
|
|
294
304
|
/**
|
|
@@ -319,14 +329,14 @@ export const chatSystem = () => readFileSync(join(REPO_ROOT, 'AGENTS.md'), 'utf8
|
|
|
319
329
|
* if it is at work, else in a turn of its own (`wake`), which whoever watches
|
|
320
330
|
* starts when told `job-report`.
|
|
321
331
|
*/
|
|
322
|
-
export function createChat(db, { model, effort, cwd = process.cwd(), send = sendToApi, out = () => {}, activity = () => {}, watch = () => {}, herdr = runHerdr, env = process.env, route = chooseChatRoute, approve = null, ask = null, background = false, now = () => new Date().toISOString() } = {}) {
|
|
332
|
+
export function createChat(db, { model, effort, cwd = process.cwd(), send = sendToApi, cursorSdk = null, out = () => {}, activity = () => {}, watch = () => {}, herdr = runHerdr, env = process.env, route = chooseChatRoute, approve = null, ask = null, background = false, now = () => new Date().toISOString() } = {}) {
|
|
323
333
|
// A route the chat was started with holds through a resumed session; one it was not, the saved session brings back.
|
|
324
334
|
const given = { model: model !== undefined, effort: effort !== undefined };
|
|
325
335
|
model ??= configured(db, 'chat.model');
|
|
326
336
|
// A model the user turned off is not chatted on, however the chat came to be on it; auto reads the switches each turn.
|
|
327
337
|
// A full API id is that model too (claude-opus-5-5 is opus), switched off or on with it.
|
|
328
|
-
const named =
|
|
329
|
-
if (named !== 'auto' &&
|
|
338
|
+
const named = modelName(model);
|
|
339
|
+
if (named !== 'auto' && ALL_MODELS.includes(named)) assertOn(db, named, 'pick another Model there');
|
|
330
340
|
effort ??= model === 'auto' ? null : configured(db, 'chat.effort');
|
|
331
341
|
/** On auto, the route the last turn ran on; null otherwise. */
|
|
332
342
|
let routed = null;
|
|
@@ -345,6 +355,8 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
345
355
|
let params;
|
|
346
356
|
let transcript;
|
|
347
357
|
let lastContext = 0;
|
|
358
|
+
/** What this session has done, for /context: the turns the user typed and the tools the model called, on any model. */
|
|
359
|
+
let counts = { turns: 0, calls: 0 };
|
|
348
360
|
let project = null;
|
|
349
361
|
let stopper = null;
|
|
350
362
|
/** The file that says this session is open here, until it ends. */
|
|
@@ -409,6 +421,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
409
421
|
lock = held ?? takeLock(lockFile(sessionId), busy(sessionId));
|
|
410
422
|
ledger.sessionId = sessionId;
|
|
411
423
|
lastContext = saved?.contextTokens ?? 0;
|
|
424
|
+
counts = { turns: 0, calls: 0 };
|
|
412
425
|
costSaid = false;
|
|
413
426
|
project = null;
|
|
414
427
|
seen = new Map();
|
|
@@ -440,8 +453,8 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
440
453
|
const saved = loadState(found.id);
|
|
441
454
|
if (!saved) throw new UsageError(`the saved session ${shortId(found.id)} is gone`);
|
|
442
455
|
// Its model is checked as the chat's own was: a full API id is that model too, and one turned off since is not chatted on.
|
|
443
|
-
const named =
|
|
444
|
-
if (!given.model && named !== 'auto' &&
|
|
456
|
+
const named = modelName(saved.model);
|
|
457
|
+
if (!given.model && named !== 'auto' && ALL_MODELS.includes(named)) assertOn(db, named, '/model <name>');
|
|
445
458
|
const held = takeLock(lockFile(found.id), busy(found.id));
|
|
446
459
|
if (sessionId) end();
|
|
447
460
|
start('resume', saved, held);
|
|
@@ -479,7 +492,8 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
479
492
|
const wanted = e && e !== 'none' ? e : null;
|
|
480
493
|
const switched = params.model !== id;
|
|
481
494
|
const spoken = params.messages.some(effortOnly);
|
|
482
|
-
|
|
495
|
+
// Cursor is never sent the conversation's effort messages: on its models the effort in force is the request's own.
|
|
496
|
+
const inForce = (laneOf(params.model) === 'cursor' ? null : params.messages.findLast(effortOnly)?.output_config.effort) ?? params.output_config?.effort ?? null;
|
|
483
497
|
if (switched) {
|
|
484
498
|
params.model = id;
|
|
485
499
|
if (wanted) params.output_config = { effort: wanted };
|
|
@@ -713,7 +727,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
713
727
|
let ended = [];
|
|
714
728
|
try {
|
|
715
729
|
const outcome = await runJob(db, id, {
|
|
716
|
-
send
|
|
730
|
+
send,
|
|
717
731
|
signal,
|
|
718
732
|
approve,
|
|
719
733
|
inbox: () => inbox.splice(0),
|
|
@@ -894,20 +908,32 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
894
908
|
|
|
895
909
|
async function turn(text, said, images, automated = false, guide = null) {
|
|
896
910
|
stopper = new AbortController();
|
|
897
|
-
// Edits nothing has checked: an editor call that wrote adds its file — one refused, or whose old_str was not found,
|
|
898
|
-
// changed nothing and adds none; one of the project's declared checks running clears them — any command does when
|
|
899
|
-
// the project declares none. The gate at the end of the turn is told what is left. The shell can edit too (`sed -i`,
|
|
900
|
-
// a redirect); that is not seen.
|
|
901
911
|
const unchecked = new Set();
|
|
902
|
-
|
|
903
|
-
|
|
912
|
+
let beforeShell;
|
|
913
|
+
let shellRoot;
|
|
914
|
+
const watchShell = (call) => {
|
|
904
915
|
if (call.name !== BASH_TOOL.name) return;
|
|
905
|
-
const
|
|
906
|
-
if (
|
|
916
|
+
const { cwd } = workspace();
|
|
917
|
+
if (beforeShell === undefined || shellRoot !== cwd) {
|
|
918
|
+
shellRoot = cwd;
|
|
919
|
+
beforeShell = snapshot(cwd);
|
|
920
|
+
}
|
|
907
921
|
};
|
|
908
|
-
|
|
922
|
+
const declared = () => verifyCommands(workspace().cwd).map((c) => c.command);
|
|
923
|
+
// Only completed, foreground checks can cover prior edits. If the project declares none,
|
|
924
|
+
// recognise direct invocations of a test runner or file assertion. Compound commands can mask their exit status.
|
|
909
925
|
const noteResult = (call, result) => {
|
|
910
|
-
if (
|
|
926
|
+
if (result?.isError) return;
|
|
927
|
+
if (call.name === BASH_TOOL.name && (unchecked.size > 0 || beforeShell)) {
|
|
928
|
+
const command = String(call.input?.command ?? '').trim();
|
|
929
|
+
const checks = declared();
|
|
930
|
+
if (checks.includes(command) || (checks.length === 0 && isCheck(command))) {
|
|
931
|
+
unchecked.clear();
|
|
932
|
+
beforeShell = undefined;
|
|
933
|
+
}
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
if (call.name !== EDITOR_TOOL.name || call.input?.command === 'view' || !call.input?.path) return;
|
|
911
937
|
const { cwd: root } = workspace();
|
|
912
938
|
const path = resolve(root, String(call.input.path));
|
|
913
939
|
if (path.startsWith(`${root}${sep}`)) unchecked.add(path);
|
|
@@ -940,7 +966,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
940
966
|
if (stopper.signal.aborted) return { stop: 'interrupted', error: null, text: '' };
|
|
941
967
|
routed = chosen;
|
|
942
968
|
apply(routed);
|
|
943
|
-
logLine(transcript, { type: 'route', ...routed });
|
|
969
|
+
logLine(transcript, { type: 'route', ...routed, reason: routed.reason && redact(routed.reason).text });
|
|
944
970
|
watch({ type: 'route', ...routed });
|
|
945
971
|
}
|
|
946
972
|
settleTail();
|
|
@@ -955,6 +981,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
955
981
|
const events = reports.splice(0).map((r) => eventBlock(r.text));
|
|
956
982
|
const at = params.messages.push(automated ? { role: 'user', content: [eventBlock(text)] } : { role: 'user', content: [...pictures, { type: 'text', text }, ...events] }) - 1;
|
|
957
983
|
spoken = true;
|
|
984
|
+
if (!automated) counts.turns++;
|
|
958
985
|
if (injected) params.messages.push(injection(injected, params.model, params.messages));
|
|
959
986
|
// The log keeps what memory keeps: the user's words without their secrets — and an event as an event.
|
|
960
987
|
logLine(transcript, automated ? { type: 'event', text: redact(text).text } : { type: 'user', message: { role: 'user', content: redact(text).text } });
|
|
@@ -962,8 +989,12 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
962
989
|
// What the editor changes in this turn is kept for /undo in one folder, however many requests the turn takes.
|
|
963
990
|
const undoFolder = nextUndoTurn(undoDir());
|
|
964
991
|
let continued = false;
|
|
992
|
+
// The turn's model, by its name: on Cursor's, the loop is Cursor's (src/cursor.mjs), with this chat's tools, approvals and
|
|
993
|
+
// undo folder; its web search is unseen there, so the session given it is taken to have read the web, as a search here would mark it.
|
|
994
|
+
const onCursor = laneOf(params.model) === 'cursor';
|
|
995
|
+
if (onCursor && params.tools.some(isWebTool)) noteSessionOutside(db, sessionId, 'web_search');
|
|
965
996
|
for (;;) {
|
|
966
|
-
const outcome = await converse(db, params, {
|
|
997
|
+
const outcome = await (onCursor ? cursorTurn : converse)(db, params, {
|
|
967
998
|
send: sendAs,
|
|
968
999
|
// A command the sandbox kept from writing is put to the user as an MCP call off the allow list is, for one run outside it;
|
|
969
1000
|
// so is a change to a file outside the project, once or for the session.
|
|
@@ -981,9 +1012,10 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
981
1012
|
watch({ type: 'retry', ...r });
|
|
982
1013
|
},
|
|
983
1014
|
onTool: (call) => {
|
|
1015
|
+
counts.calls++;
|
|
1016
|
+
watchShell(call);
|
|
984
1017
|
activity(describeCall(call));
|
|
985
1018
|
watch({ type: 'tool', call });
|
|
986
|
-
noteCall(call);
|
|
987
1019
|
// A page or an MCP server read here: what this conversation says from now on may be what it was told.
|
|
988
1020
|
if (isWebTool(call) || isMcpTool(call.name)) noteSessionOutside(db, sessionId, call.name);
|
|
989
1021
|
},
|
|
@@ -993,7 +1025,8 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
993
1025
|
},
|
|
994
1026
|
onTurn: (response, totals) => {
|
|
995
1027
|
lastContext = totals.contextTokens;
|
|
996
|
-
|
|
1028
|
+
const content = response.content.filter((b) => b.type === 'text').map((b) => ({ type: 'text', text: redact(b.text).text }));
|
|
1029
|
+
logLine(transcript, { type: 'assistant', message: { role: 'assistant', model: response.model ?? params.model, usage: response.usage, content } });
|
|
997
1030
|
watch({ type: 'usage', totals });
|
|
998
1031
|
overBudget();
|
|
999
1032
|
// What the reply rests on, said under it: the pages it cites.
|
|
@@ -1014,6 +1047,12 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1014
1047
|
// memory can answer, is told so and continued, once. Only a turn the model ended itself: after an error or a cut-off
|
|
1015
1048
|
// reply the turn is simply over, and the scribe still hears of it.
|
|
1016
1049
|
const asked = outcome.stop === 'end_turn';
|
|
1050
|
+
if (asked && beforeShell) {
|
|
1051
|
+
const { tracked, created, fingerprint } = changesSince(shellRoot, beforeShell);
|
|
1052
|
+
if (fingerprint !== beforeShell.fingerprint) {
|
|
1053
|
+
for (const name of [...tracked.map((file) => file.to ?? file.path), ...created]) unchecked.add(resolve(shellRoot, name));
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1017
1056
|
const edited = [...unchecked].map((path) => relative(workspace().cwd, path));
|
|
1018
1057
|
const checks = declared();
|
|
1019
1058
|
// The reply goes with the event either way, for the journal: also the one a continued turn ends on, which asks nothing more.
|
|
@@ -1034,6 +1073,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1034
1073
|
function undo() {
|
|
1035
1074
|
const done = undoLast(undoDir());
|
|
1036
1075
|
if (!done) return 'nothing to undo: the editor has changed no file in this session — changes made through bash are not tracked';
|
|
1076
|
+
if (done.blocked) return done.blocked;
|
|
1037
1077
|
const { cwd: at } = workspace();
|
|
1038
1078
|
const names = (list) => {
|
|
1039
1079
|
const shown = list.map((path) => pathFrom(path, at));
|
|
@@ -1055,18 +1095,23 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1055
1095
|
stopper = new AbortController();
|
|
1056
1096
|
settleTail();
|
|
1057
1097
|
const row = (model, result, said) => logRun(db, { kind: 'chat', model, result, note: said, now: now(), sessionId });
|
|
1098
|
+
// A hand-off is a request to the API, which has no Cursor model: a conversation on Cursor is handed off by Sonnet, or the
|
|
1099
|
+
// strongest Claude model on. Cursor's calls are in the conversation as calls (src/cursor.mjs), so it reads what was done.
|
|
1100
|
+
const claude = usableModels(db);
|
|
1101
|
+
const writer = claude.includes('sonnet') ? 'sonnet' : claude.at(-1);
|
|
1102
|
+
const by = laneOf(params.model) === 'cursor' ? withFallback({ ...params, model: MODEL_IDS[writer] }, writer) : params;
|
|
1058
1103
|
let summary;
|
|
1059
1104
|
try {
|
|
1060
|
-
summary = await sendAs(compactionParams(
|
|
1105
|
+
summary = await sendAs(compactionParams(by, COMPACT_INSTRUCTIONS), { signal: stopper.signal, retries: QUIET_RETRIES });
|
|
1061
1106
|
} catch (cause) {
|
|
1062
1107
|
const why = describeFailure(cause).slice(0, 200);
|
|
1063
|
-
row(
|
|
1108
|
+
row(by.model, { ok: false, usage: usageOf(by.model, null) }, `hand-off: ${why}`);
|
|
1064
1109
|
if (stopper.signal.aborted) throw new UsageError('the hand-off was stopped: this session goes on');
|
|
1065
1110
|
throw new UsageError(`no hand-off could be written: ${why} — /new starts fresh; the memory brings the thread back`);
|
|
1066
1111
|
}
|
|
1067
1112
|
const block = summary.content.find((b) => b.type === 'compaction' && b.content);
|
|
1068
|
-
const
|
|
1069
|
-
row(
|
|
1113
|
+
const answered = summary.model ?? by.model;
|
|
1114
|
+
row(answered, { ok: Boolean(block), usage: usageOf(answered, summary.usage) }, block ? 'hand-off' : 'hand-off: no summary came back');
|
|
1070
1115
|
if (!block) throw new UsageError('no hand-off came back from the model — /new starts fresh; the memory brings the thread back');
|
|
1071
1116
|
const text = redact(String(block.content)).text.trim();
|
|
1072
1117
|
const from = shortId(sessionId);
|
|
@@ -1098,7 +1143,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1098
1143
|
const [, name, args = ''] = m;
|
|
1099
1144
|
if (name === 'exit' || name === 'quit') return { control: 'quit' };
|
|
1100
1145
|
if (name === 'new' || name === 'clear') return { control: 'new' };
|
|
1101
|
-
if (name === 'memory' || name === 'undo' || name === 'context' || name === 'handoff' || name === 'config') return { control: name };
|
|
1146
|
+
if (name === 'memory' || name === 'undo' || name === 'context' || name === 'handoff' || name === 'config' || name === 'scorecard') return { control: name };
|
|
1102
1147
|
if (name === 'model' || name === 'resume' || name === 'mcp' || name === 'copy' || name === 'help' || name === 'stop' || name === 'export' || name === 'thinking') return { control: name, args: args.trim() };
|
|
1103
1148
|
const make = Object.hasOwn(COMMANDS, name) ? COMMANDS[name] : undefined;
|
|
1104
1149
|
if (make) return { ...make(args.trim()), said: args.trim() };
|
|
@@ -1107,6 +1152,36 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1107
1152
|
return { error: close ? `no command /${name} — did you mean /${close}?` : `no command /${name} — one of: ${commands.map((c) => `/${c.name}`).join(' ')}` };
|
|
1108
1153
|
}
|
|
1109
1154
|
|
|
1155
|
+
/**
|
|
1156
|
+
* One request of a turn on a Cursor model, answered as `converse` answers: the chat's own callbacks for the tools and the words,
|
|
1157
|
+
* and, after each request to the model, what `onTurn` does on Claude — the context gauge and the cost notice. The reply is
|
|
1158
|
+
* written to the transcript once the run ends, as a reply on Claude is.
|
|
1159
|
+
*/
|
|
1160
|
+
async function cursorTurn(_db, turnParams, options) {
|
|
1161
|
+
const outcome = await converseCursor(db, turnParams, {
|
|
1162
|
+
...options,
|
|
1163
|
+
onUsage: (totals) => {
|
|
1164
|
+
lastContext = totals.contextTokens;
|
|
1165
|
+
watch({ type: 'usage', totals });
|
|
1166
|
+
overBudget();
|
|
1167
|
+
},
|
|
1168
|
+
now,
|
|
1169
|
+
sdk: cursorSdk,
|
|
1170
|
+
});
|
|
1171
|
+
if (outcome.text) logLine(transcript, { type: 'assistant', message: { role: 'assistant', model: turnParams.model, content: [{ type: 'text', text: redact(outcome.text).text }] } });
|
|
1172
|
+
return outcome;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* `/scorecard`: the benchmarks routing reads, fetched again and saved, as Discover fetches them. Each source is told to
|
|
1177
|
+
* `onSource` as it is read — its requests, what it kept and left out, where it placed Sumo's routes — and what was saved
|
|
1178
|
+
* comes back as a table. The model is told nothing: what to route by is not the conversation's.
|
|
1179
|
+
*/
|
|
1180
|
+
async function scorecard(onSource) {
|
|
1181
|
+
const result = await refreshScorecard(db, { onSource, now: now() });
|
|
1182
|
+
return scorecardReport(db, result, EFFORTS);
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1110
1185
|
/** `/mcp`: the servers as `sumo mcp` lists them. They connect once, while the first turn is typed, so an early look waits for them. */
|
|
1111
1186
|
async function mcp() {
|
|
1112
1187
|
await connecting;
|
|
@@ -1188,6 +1263,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1188
1263
|
tell,
|
|
1189
1264
|
shell,
|
|
1190
1265
|
undo,
|
|
1266
|
+
scorecard,
|
|
1191
1267
|
expand,
|
|
1192
1268
|
memoryPage,
|
|
1193
1269
|
mcp,
|
|
@@ -1221,6 +1297,10 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1221
1297
|
get contextTokens() {
|
|
1222
1298
|
return lastContext;
|
|
1223
1299
|
},
|
|
1300
|
+
/** The turns typed and the tools called in this session. */
|
|
1301
|
+
get counts() {
|
|
1302
|
+
return { ...counts };
|
|
1303
|
+
},
|
|
1224
1304
|
};
|
|
1225
1305
|
}
|
|
1226
1306
|
|
|
@@ -1370,7 +1450,7 @@ export async function chat(db, { model, effort, resume = null, send, input = pro
|
|
|
1370
1450
|
continue;
|
|
1371
1451
|
}
|
|
1372
1452
|
if (control === 'context') {
|
|
1373
|
-
reply.write(contextReport({ contextTokens: session.contextTokens, rows: session.usage() }));
|
|
1453
|
+
reply.write(contextReport({ contextTokens: session.contextTokens, rows: session.usage(), ...session.counts }));
|
|
1374
1454
|
reply.flush();
|
|
1375
1455
|
write('\n');
|
|
1376
1456
|
continue;
|
package/src/check.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { getMeta, setMeta } from './db.mjs';
|
|
2
2
|
import { replaySetAside } from './hooks.mjs';
|
|
3
3
|
import { tidyDue } from './dream.mjs';
|
|
4
|
-
import { emptyRun, extractorVersion, filingState } from './ledger.mjs';
|
|
4
|
+
import { emptyRun, extractorVersion, filingState, memoryModel } from './ledger.mjs';
|
|
5
5
|
import { localServerStatus } from './local-server.mjs';
|
|
6
6
|
import { paths } from './paths.mjs';
|
|
7
7
|
import { heartbeat } from './prime.mjs';
|
|
8
|
-
import { modelStats } from './scribe.mjs';
|
|
8
|
+
import { lockHolder, modelStats } from './scribe.mjs';
|
|
9
9
|
import { searchAll } from './search.mjs';
|
|
10
|
-
import { lastHeard, sessionsAwaitingExtraction } from './sessions.mjs';
|
|
11
|
-
import {
|
|
10
|
+
import { FINISHED_AFTER_MS, lastHeard, sessionsAwaitingExtraction } from './sessions.mjs';
|
|
11
|
+
import { modelFileOf } from './setup.mjs';
|
|
12
12
|
import { spoolStatus } from './spool.mjs';
|
|
13
13
|
import { STOPWORDS } from './text.mjs';
|
|
14
14
|
|
|
@@ -48,7 +48,7 @@ const EMPTY_RUN_WARN = 10;
|
|
|
48
48
|
* said — the command that reads it is in the line.
|
|
49
49
|
*/
|
|
50
50
|
function unreadLong(db, now) {
|
|
51
|
-
if ((
|
|
51
|
+
if (memoryModel(db) === 'off') return { count: 0, since: null };
|
|
52
52
|
const cutoff = new Date(Date.parse(now) - UNREAD_FAIL_MS).toISOString();
|
|
53
53
|
const answered = db.prepare('SELECT MAX(ts) AS at FROM replies WHERE session_id = ?');
|
|
54
54
|
const quietSince = (s) => {
|
|
@@ -70,7 +70,7 @@ function unreadLong(db, now) {
|
|
|
70
70
|
* - `emptyRun`: how many conversations read last, in a row, filed nothing (ledger.mjs).
|
|
71
71
|
* `filing` is handed in by a caller that already read it.
|
|
72
72
|
*/
|
|
73
|
-
export function memoryHealth(db, now = new Date().toISOString(), { filing = filingState(db
|
|
73
|
+
export function memoryHealth(db, now = new Date().toISOString(), { filing = filingState(db) } = {}) {
|
|
74
74
|
const scans = db
|
|
75
75
|
.prepare(`SELECT slug, scanned_at FROM projects WHERE status = 'active' AND scanned_at IS NOT NULL ORDER BY scanned_at`)
|
|
76
76
|
.all()
|
|
@@ -123,13 +123,11 @@ const CANARY_MIN = 3;
|
|
|
123
123
|
const CANARY_SHOWN = 50;
|
|
124
124
|
/** A backup older than this is said: one is made weekly, at a session's start. */
|
|
125
125
|
const BACKUP_STALE_DAYS = 14;
|
|
126
|
-
/** A pass still `running` after this long was left by a process that died: a batch takes minutes. */
|
|
126
|
+
/** A pass still `running` after this long was left by a process that died, and one holding its lock this long is stuck: a batch takes minutes. */
|
|
127
127
|
const RUN_DEAD_AFTER_MS = 30 * 60_000;
|
|
128
128
|
/** The finished conversations of a harness looked at for replies, and how many without one are no accident. */
|
|
129
129
|
const REPLY_LOOKS = 10;
|
|
130
130
|
const REPLY_MISSING = 3;
|
|
131
|
-
/** A conversation nobody has spoken in for this long is over (as in sessions.mjs). */
|
|
132
|
-
const FINISHED_AFTER_MS = 30 * 60_000;
|
|
133
131
|
|
|
134
132
|
/** What SQLite says is wrong with a full-text index — its own structure, and against the table it indexes — or null. */
|
|
135
133
|
function indexProblem(db, name) {
|
|
@@ -220,7 +218,7 @@ function repliesCheck(db, now) {
|
|
|
220
218
|
* `sumo doctor` carries them. `fix: true` rebuilds an index that fails, and replays the spool's set-aside lines, before judging. `filing` is handed in by a
|
|
221
219
|
* caller that already read it.
|
|
222
220
|
*/
|
|
223
|
-
export function memoryCheck(db, now = new Date().toISOString(), { fix = false, filing = filingState(db
|
|
221
|
+
export function memoryCheck(db, now = new Date().toISOString(), { fix = false, filing = filingState(db) } = {}) {
|
|
224
222
|
const checks = [];
|
|
225
223
|
const check = (name, { ok, label, fix: how = '' }) => checks.push({ name, ok, label, fix: ok ? '' : how });
|
|
226
224
|
|
|
@@ -255,10 +253,14 @@ export function memoryCheck(db, now = new Date().toISOString(), { fix = false, f
|
|
|
255
253
|
check('backup', backupCheck(db, now));
|
|
256
254
|
|
|
257
255
|
const dead = db.prepare(`SELECT COUNT(*) AS n, MIN(started_at) AS since FROM extractions WHERE status = 'running' AND started_at < ?`).get(new Date(Date.parse(now) - RUN_DEAD_AFTER_MS).toISOString());
|
|
256
|
+
// A lock a live pass has held past any batch's time: every pass after it is turned away while it holds on.
|
|
257
|
+
const stuck = ['scribe', 'dream'].map(lockHolder).find((h) => h && Date.parse(now) - h.since > RUN_DEAD_AFTER_MS);
|
|
258
258
|
check('passes', {
|
|
259
|
-
ok: dead.n === 0,
|
|
260
|
-
label:
|
|
261
|
-
|
|
259
|
+
ok: dead.n === 0 && !stuck,
|
|
260
|
+
label: stuck
|
|
261
|
+
? `the memory pass has been held by process ${stuck.pid} for ${Math.floor((Date.parse(now) - stuck.since) / 60_000)} minutes`
|
|
262
|
+
: dead.n === 0 ? 'no memory pass was left unfinished' : `${many(dead.n, 'memory pass', 'memory passes')} left running by a process that died (since ${dead.since?.slice(0, 16)})`,
|
|
263
|
+
fix: stuck ? `a pass takes minutes: if process ${stuck.pid} is stuck, end it (kill ${stuck.pid}) and the next pass takes over` : 'sumo memory run reads those conversations again',
|
|
262
264
|
});
|
|
263
265
|
|
|
264
266
|
check('replies', repliesCheck(db, now));
|
|
@@ -339,9 +341,9 @@ const row = (label, value) => `${label.padEnd(LABEL_WIDTH)}${value}`;
|
|
|
339
341
|
* and not heard.
|
|
340
342
|
*/
|
|
341
343
|
export async function memoryStatus(db, now = new Date().toISOString()) {
|
|
342
|
-
const filing = filingState(db
|
|
344
|
+
const filing = filingState(db);
|
|
343
345
|
const health = memoryHealthLine(memoryHealth(db, now, { filing }), now);
|
|
344
|
-
const model =
|
|
346
|
+
const model = memoryModel(db);
|
|
345
347
|
const server = model === 'local' ? await localServerStatus(db, { file: modelFileOf(db) }) : null;
|
|
346
348
|
const rung = model === 'off' ? 'none: the pass is off, what is said is still kept and found by search' : filing.fallbackUsed ? 'the fallback: the local model could not answer the last pass' : model === 'local' ? 'the local model' : `${model}, as set`;
|
|
347
349
|
const version = extractorVersion(db);
|
package/src/cli.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { StringDecoder } from 'node:string_decoder';
|
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
4
|
import { applyOps } from './apply.mjs';
|
|
5
5
|
import { card } from './card.mjs';
|
|
6
|
-
import { knownModel,
|
|
6
|
+
import { ALL_MODELS, cursorKeyIn, knownModel, laneOf, modelId, modelLines } from './catalog.mjs';
|
|
7
7
|
import { openDb } from './db.mjs';
|
|
8
8
|
import { backup, damaged, exportJson, exportMarkdown, liveDatabase, purgeFromBackups, purgeRowFromBackups, restoreCandidate, restoreHint, restoreLines, restoreQuestion } from './export.mjs';
|
|
9
9
|
import { resolveAnthropicCredential } from './auth.mjs';
|
|
@@ -41,7 +41,7 @@ const HELP = `sumo — one chat across your projects, memory that lasts, and job
|
|
|
41
41
|
sumo job new --project S --title T [--agent A] a job, its task on stdin
|
|
42
42
|
by id: run · watch · tell · note · ask · answer · show · brief · baseline · verify · changes
|
|
43
43
|
finish <id> --status DONE|FAILED · abandon · retry · list [--all] · stats
|
|
44
|
-
sumo prime · sumo
|
|
44
|
+
sumo prime · sumo version the block a session starts with · which sumo
|
|
45
45
|
sumo export [--json] · sumo backup [restore [file]] · sumo cost [--days N] [--project S]
|
|
46
46
|
sumo config every setting, on one page; /config in a chat
|
|
47
47
|
sumo models · sumo mcp [tools <name>] the API models · the MCP servers, as set
|
|
@@ -120,7 +120,7 @@ sumo job list [--all] [--json]`,
|
|
|
120
120
|
apply: 'sumo apply <ops.json> [--source scribe|dream]',
|
|
121
121
|
export: 'sumo export [--json]',
|
|
122
122
|
backup: 'sumo backup [restore [file] [--yes]] (restore: the newest copy, or the one named, put back, the one there kept aside; over a database that is fine it asks first, or --yes)',
|
|
123
|
-
models: 'sumo models every model Sumo knows: on or off, its API id, and why — switched on and off, and
|
|
123
|
+
models: 'sumo models every model Sumo knows: on or off, its API id, and why, then the scorecard routing reads — switched on and off, discovered and scored, on the settings page (sumo config)',
|
|
124
124
|
mcp: `sumo mcp every server: where it is, its tools or why it failed, what may run unasked
|
|
125
125
|
sumo mcp tools <name> the server's tools, one a line
|
|
126
126
|
added, removed and allowed on the settings page: /config in the chat, or sumo config`,
|
|
@@ -740,7 +740,10 @@ async function runJob(db, { args, flags }) {
|
|
|
740
740
|
case 'run': {
|
|
741
741
|
// The job runs here, in Sumo's own loop, on the route the router chose; it closes itself the way its brief says.
|
|
742
742
|
// On a terminal the work is shown as it happens — the lines a Herdr pane shows; piped, only how it ended.
|
|
743
|
-
|
|
743
|
+
// A job on a Cursor model is run with Cursor's key, and needs no other; one on Claude, with an Anthropic credential.
|
|
744
|
+
if (laneOf(jobs.getJob(db, id).model ?? '') === 'cursor') {
|
|
745
|
+
if (!cursorKeyIn()) throw new NeedsCredential(`j${id} not started — it is routed to a Cursor model and this shell has no CURSOR_API_KEY: export it first`);
|
|
746
|
+
} else if (!resolveAnthropicCredential()) {
|
|
744
747
|
throw new NeedsCredential(`j${id} not started — this shell has no Anthropic credential. Inside the chat, the delegate tool runs it; in a terminal, export CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY first`);
|
|
745
748
|
}
|
|
746
749
|
// The run's own machinery, loaded only for a run: the loop brings the SDK, and no other command needs any of it.
|
|
@@ -805,7 +808,7 @@ async function runJob(db, { args, flags }) {
|
|
|
805
808
|
default: {
|
|
806
809
|
// Taking work unverified is the user's call: never granted from inside a job's own shell, whatever the command looked like.
|
|
807
810
|
if (flags.accept !== undefined && process.env.SUMO_JOB) {
|
|
808
|
-
throw new Refusal(`Refused: j${process.env.SUMO_JOB} runs this command, and work is never taken unverified on its author's word.
|
|
811
|
+
throw new Refusal(`Refused: j${process.env.SUMO_JOB} runs this command, and work is never taken unverified on its author's word. ${jobs.ASK_TO_ACCEPT}`);
|
|
809
812
|
}
|
|
810
813
|
const { job, learned, verdict, unverified } = jobs.finish(db, id, { status: String(flags.status ?? '').toUpperCase(), report: stdinText(flags), accept: flags.accept });
|
|
811
814
|
// A worker's plain DONE means the checks agreed; the verdict is in the report. Only the exceptions are said here.
|
|
@@ -837,13 +840,17 @@ async function runMemoryCommand(db, { args, flags }) {
|
|
|
837
840
|
// Nor with no terminal: piped or in a script, nobody is there to look at it, or to press Ctrl-C.
|
|
838
841
|
if (args[0] === undefined && (!process.stdin.isTTY || !process.stdout.isTTY)) throw new UsageError('the memory page runs until Ctrl-C, so it needs a terminal — run sumo memory in one; sumo memory status and sumo search work anywhere');
|
|
839
842
|
if (args[0] === undefined) return runMemoryPage(db);
|
|
840
|
-
if (args[0] === 'run')
|
|
843
|
+
if (args[0] === 'run') {
|
|
844
|
+
const pass = await runMemoryPass(db, { tidy: flags.tidy === true, auto: flags.auto === true });
|
|
845
|
+
// Turned away by another pass holding the lock, it read nothing: a script must not take that for done.
|
|
846
|
+
return pass.filed.locked ? Object.assign(memoryPassLines(pass), { exitCode: 1 }) : memoryPassLines(pass, { asked: flags.tidy === true });
|
|
847
|
+
}
|
|
841
848
|
if (args[0] === 'rebuild') {
|
|
842
849
|
// It lets memories go, past the bound with --yes: from the model's shell — this command runs outside the sandbox — only the difference is shown.
|
|
843
850
|
if (fromTool() && flags['dry-run'] !== true) throw new Refusal("rebuilding memory is the user's to do: they run sumo memory rebuild themselves. sumo memory rebuild --dry-run shows what it would change");
|
|
844
851
|
const { rebuild } = await import('./rebuild.mjs');
|
|
845
852
|
const limit = flags.limit === undefined ? undefined : positiveInteger(flags.limit, '--limit needs a positive number');
|
|
846
|
-
return rebuild(db, { dryRun: flags['dry-run'] === true, since: dayFlag(flags.since, '--since', { back: true }), limit, yes: flags.yes === true });
|
|
853
|
+
return rebuild(db, { dryRun: flags['dry-run'] === true, since: dayFlag(flags.since, '--since', { back: true }), limit, yes: flags.yes === true, fromShell: fromTool() });
|
|
847
854
|
}
|
|
848
855
|
// The checks load with the commands that report them: a hook reaches this file on every prompt.
|
|
849
856
|
if (args[0] === 'status') return (await import('./check.mjs')).memoryStatus(db);
|
|
@@ -900,9 +907,12 @@ async function runMemoryPage(db) {
|
|
|
900
907
|
return ['stopped'];
|
|
901
908
|
}
|
|
902
909
|
|
|
903
|
-
/** The models Sumo can run on and their switches, as the settings page set them. */
|
|
904
|
-
function runModels(db, { args }) {
|
|
905
|
-
if (args[0] === undefined)
|
|
910
|
+
/** The models Sumo can run on and their switches, as the settings page set them, then how the saved scorecard scores each. */
|
|
911
|
+
async function runModels(db, { args }) {
|
|
912
|
+
if (args[0] === undefined) {
|
|
913
|
+
const [{ EFFORTS }, { scorecardLines }] = await Promise.all([import('./route.mjs'), import('./scorecard.mjs')]);
|
|
914
|
+
return [...modelLines(db), '', ...scorecardLines(db, EFFORTS)];
|
|
915
|
+
}
|
|
906
916
|
if (['enable', 'disable', 'discover'].includes(args[0])) throw new UsageError(ON_THE_PAGE(`which models are on (${args[0]})`));
|
|
907
917
|
throw new UsageError(`usage: ${USAGE.models}`);
|
|
908
918
|
}
|
|
@@ -1038,7 +1048,7 @@ export async function main(argv) {
|
|
|
1038
1048
|
const resume = flags.resume ? (given[0] ?? 'last') : null;
|
|
1039
1049
|
// Said once, before the screen: past here every turn would fail the same way.
|
|
1040
1050
|
// A full API id is taken too (claude-opus-5-5), as the chat itself takes one.
|
|
1041
|
-
if (flags.model !== undefined && flags.model !== 'auto' && !
|
|
1051
|
+
if (flags.model !== undefined && flags.model !== 'auto' && !ALL_MODELS.map(modelId).includes(flags.model)) knownModel(flags.model, ['auto'], ALL_MODELS);
|
|
1042
1052
|
if (flags.effort !== undefined && !CHAT_EFFORTS.includes(flags.effort)) throw new UsageError(`no such effort "${flags.effort}" — one of: ${CHAT_EFFORTS.join(', ')}`);
|
|
1043
1053
|
if (!resolveAnthropicCredential()) throw new NeedsCredential('the chat needs an Anthropic credential — export ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN in this shell, then: sumo chat');
|
|
1044
1054
|
const db = openDb();
|
package/src/cost.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { modelName } from './catalog.mjs';
|
|
3
3
|
import { CACHE_WRITE, priceOf } from './model.mjs';
|
|
4
4
|
import { getProject } from './projects.mjs';
|
|
5
5
|
|
|
@@ -136,8 +136,6 @@ export function breakdown(rows) {
|
|
|
136
136
|
const dollars = (usd) => `$${usd.toFixed(2)}`;
|
|
137
137
|
const count = (n, word) => `${n.toLocaleString('en-US')} ${word}${n === 1 ? '' : 's'}`;
|
|
138
138
|
const percent = (part, whole) => (whole > 0 ? ` (${Math.round((part / whole) * 100)}%)` : '');
|
|
139
|
-
/** A model by the name Sumo calls it; a local model or one the list does not know, as the ledger has it. */
|
|
140
|
-
const nameOf = (model) => MODELS.find((name) => MODEL_IDS[name] === model) ?? model;
|
|
141
139
|
/** Who made a request, in the words the user knows: the ledger keeps its own short kinds. */
|
|
142
140
|
const KIND_NAMES = { scribe: 'memory pass, filing', dream: 'memory pass, tidying', local: 'router' };
|
|
143
141
|
const kindOf = (kind) => KIND_NAMES[kind] ?? kind;
|
|
@@ -179,7 +177,7 @@ export function costLines(db, { days, project } = {}) {
|
|
|
179
177
|
return [
|
|
180
178
|
`${scope}: ${count(total.requests, 'request')}, ${dollars(total.usd)} — ${split(total, total.usd)}`,
|
|
181
179
|
// A group that cost nothing — the local model's — has nothing to split.
|
|
182
|
-
...groups.map((g) => ` ${kindOf(g.kind)} · ${
|
|
180
|
+
...groups.map((g) => ` ${kindOf(g.kind)} · ${modelName(g.model)}: ${count(g.requests, 'request')}, ${dollars(g.usd)}${g.usd >= 0.005 ? ` — ${split(g)}` : ''}`),
|
|
183
181
|
`cache rewrites: ${count(rewrites.requests, 'request')} read under ${REWRITE_READ_UNDER / 1000}k from the cache and wrote most of their context again, under ${CACHE_LIVES_MS / 60_000} minutes after the request before — ${dollars(rewrites.usd)} of cache writes${share}`,
|
|
184
182
|
// Told apart at the time, whatever the gap: the ones a longer cache would have kept are the gap ones.
|
|
185
183
|
...(told.length > 0 ? [` why: ${told.map(([cause, sum]) => `${cause} ${count(sum.requests, 'request')}, ${dollars(sum.usd)}`).join(' · ')}`, ...told.map(([cause]) => ` ${cause}: ${CAUSES[cause]}`)] : []),
|