sumo-agents 0.7.2 → 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 +88 -0
- package/README.md +43 -20
- 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 +71 -16
- 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 +32 -14
- package/src/ledger.mjs +4 -3
- package/src/loop.mjs +124 -73
- 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 +9 -7
- package/src/settings.mjs +114 -37
- package/src/setup.mjs +33 -14
- package/src/spool.mjs +68 -43
- package/src/tools.mjs +170 -77
- package/src/ui.mjs +14 -5
- package/src/verify.mjs +68 -12
- package/src/worktree.mjs +23 -16
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';
|
|
@@ -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(', ')}`);
|
|
@@ -324,14 +329,14 @@ export const chatSystem = () => readFileSync(join(REPO_ROOT, 'AGENTS.md'), 'utf8
|
|
|
324
329
|
* if it is at work, else in a turn of its own (`wake`), which whoever watches
|
|
325
330
|
* starts when told `job-report`.
|
|
326
331
|
*/
|
|
327
|
-
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() } = {}) {
|
|
328
333
|
// A route the chat was started with holds through a resumed session; one it was not, the saved session brings back.
|
|
329
334
|
const given = { model: model !== undefined, effort: effort !== undefined };
|
|
330
335
|
model ??= configured(db, 'chat.model');
|
|
331
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.
|
|
332
337
|
// A full API id is that model too (claude-opus-5-5 is opus), switched off or on with it.
|
|
333
|
-
const named =
|
|
334
|
-
if (named !== 'auto' &&
|
|
338
|
+
const named = modelName(model);
|
|
339
|
+
if (named !== 'auto' && ALL_MODELS.includes(named)) assertOn(db, named, 'pick another Model there');
|
|
335
340
|
effort ??= model === 'auto' ? null : configured(db, 'chat.effort');
|
|
336
341
|
/** On auto, the route the last turn ran on; null otherwise. */
|
|
337
342
|
let routed = null;
|
|
@@ -350,6 +355,8 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
350
355
|
let params;
|
|
351
356
|
let transcript;
|
|
352
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 };
|
|
353
360
|
let project = null;
|
|
354
361
|
let stopper = null;
|
|
355
362
|
/** The file that says this session is open here, until it ends. */
|
|
@@ -414,6 +421,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
414
421
|
lock = held ?? takeLock(lockFile(sessionId), busy(sessionId));
|
|
415
422
|
ledger.sessionId = sessionId;
|
|
416
423
|
lastContext = saved?.contextTokens ?? 0;
|
|
424
|
+
counts = { turns: 0, calls: 0 };
|
|
417
425
|
costSaid = false;
|
|
418
426
|
project = null;
|
|
419
427
|
seen = new Map();
|
|
@@ -445,8 +453,8 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
445
453
|
const saved = loadState(found.id);
|
|
446
454
|
if (!saved) throw new UsageError(`the saved session ${shortId(found.id)} is gone`);
|
|
447
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.
|
|
448
|
-
const named =
|
|
449
|
-
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>');
|
|
450
458
|
const held = takeLock(lockFile(found.id), busy(found.id));
|
|
451
459
|
if (sessionId) end();
|
|
452
460
|
start('resume', saved, held);
|
|
@@ -484,7 +492,8 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
484
492
|
const wanted = e && e !== 'none' ? e : null;
|
|
485
493
|
const switched = params.model !== id;
|
|
486
494
|
const spoken = params.messages.some(effortOnly);
|
|
487
|
-
|
|
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;
|
|
488
497
|
if (switched) {
|
|
489
498
|
params.model = id;
|
|
490
499
|
if (wanted) params.output_config = { effort: wanted };
|
|
@@ -972,6 +981,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
972
981
|
const events = reports.splice(0).map((r) => eventBlock(r.text));
|
|
973
982
|
const at = params.messages.push(automated ? { role: 'user', content: [eventBlock(text)] } : { role: 'user', content: [...pictures, { type: 'text', text }, ...events] }) - 1;
|
|
974
983
|
spoken = true;
|
|
984
|
+
if (!automated) counts.turns++;
|
|
975
985
|
if (injected) params.messages.push(injection(injected, params.model, params.messages));
|
|
976
986
|
// The log keeps what memory keeps: the user's words without their secrets — and an event as an event.
|
|
977
987
|
logLine(transcript, automated ? { type: 'event', text: redact(text).text } : { type: 'user', message: { role: 'user', content: redact(text).text } });
|
|
@@ -979,8 +989,12 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
979
989
|
// What the editor changes in this turn is kept for /undo in one folder, however many requests the turn takes.
|
|
980
990
|
const undoFolder = nextUndoTurn(undoDir());
|
|
981
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');
|
|
982
996
|
for (;;) {
|
|
983
|
-
const outcome = await converse(db, params, {
|
|
997
|
+
const outcome = await (onCursor ? cursorTurn : converse)(db, params, {
|
|
984
998
|
send: sendAs,
|
|
985
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;
|
|
986
1000
|
// so is a change to a file outside the project, once or for the session.
|
|
@@ -998,6 +1012,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
998
1012
|
watch({ type: 'retry', ...r });
|
|
999
1013
|
},
|
|
1000
1014
|
onTool: (call) => {
|
|
1015
|
+
counts.calls++;
|
|
1001
1016
|
watchShell(call);
|
|
1002
1017
|
activity(describeCall(call));
|
|
1003
1018
|
watch({ type: 'tool', call });
|
|
@@ -1080,18 +1095,23 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1080
1095
|
stopper = new AbortController();
|
|
1081
1096
|
settleTail();
|
|
1082
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;
|
|
1083
1103
|
let summary;
|
|
1084
1104
|
try {
|
|
1085
|
-
summary = await sendAs(compactionParams(
|
|
1105
|
+
summary = await sendAs(compactionParams(by, COMPACT_INSTRUCTIONS), { signal: stopper.signal, retries: QUIET_RETRIES });
|
|
1086
1106
|
} catch (cause) {
|
|
1087
1107
|
const why = describeFailure(cause).slice(0, 200);
|
|
1088
|
-
row(
|
|
1108
|
+
row(by.model, { ok: false, usage: usageOf(by.model, null) }, `hand-off: ${why}`);
|
|
1089
1109
|
if (stopper.signal.aborted) throw new UsageError('the hand-off was stopped: this session goes on');
|
|
1090
1110
|
throw new UsageError(`no hand-off could be written: ${why} — /new starts fresh; the memory brings the thread back`);
|
|
1091
1111
|
}
|
|
1092
1112
|
const block = summary.content.find((b) => b.type === 'compaction' && b.content);
|
|
1093
|
-
const
|
|
1094
|
-
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');
|
|
1095
1115
|
if (!block) throw new UsageError('no hand-off came back from the model — /new starts fresh; the memory brings the thread back');
|
|
1096
1116
|
const text = redact(String(block.content)).text.trim();
|
|
1097
1117
|
const from = shortId(sessionId);
|
|
@@ -1123,7 +1143,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1123
1143
|
const [, name, args = ''] = m;
|
|
1124
1144
|
if (name === 'exit' || name === 'quit') return { control: 'quit' };
|
|
1125
1145
|
if (name === 'new' || name === 'clear') return { control: 'new' };
|
|
1126
|
-
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 };
|
|
1127
1147
|
if (name === 'model' || name === 'resume' || name === 'mcp' || name === 'copy' || name === 'help' || name === 'stop' || name === 'export' || name === 'thinking') return { control: name, args: args.trim() };
|
|
1128
1148
|
const make = Object.hasOwn(COMMANDS, name) ? COMMANDS[name] : undefined;
|
|
1129
1149
|
if (make) return { ...make(args.trim()), said: args.trim() };
|
|
@@ -1132,6 +1152,36 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1132
1152
|
return { error: close ? `no command /${name} — did you mean /${close}?` : `no command /${name} — one of: ${commands.map((c) => `/${c.name}`).join(' ')}` };
|
|
1133
1153
|
}
|
|
1134
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
|
+
|
|
1135
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. */
|
|
1136
1186
|
async function mcp() {
|
|
1137
1187
|
await connecting;
|
|
@@ -1213,6 +1263,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1213
1263
|
tell,
|
|
1214
1264
|
shell,
|
|
1215
1265
|
undo,
|
|
1266
|
+
scorecard,
|
|
1216
1267
|
expand,
|
|
1217
1268
|
memoryPage,
|
|
1218
1269
|
mcp,
|
|
@@ -1246,6 +1297,10 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1246
1297
|
get contextTokens() {
|
|
1247
1298
|
return lastContext;
|
|
1248
1299
|
},
|
|
1300
|
+
/** The turns typed and the tools called in this session. */
|
|
1301
|
+
get counts() {
|
|
1302
|
+
return { ...counts };
|
|
1303
|
+
},
|
|
1249
1304
|
};
|
|
1250
1305
|
}
|
|
1251
1306
|
|
|
@@ -1395,7 +1450,7 @@ export async function chat(db, { model, effort, resume = null, send, input = pro
|
|
|
1395
1450
|
continue;
|
|
1396
1451
|
}
|
|
1397
1452
|
if (control === 'context') {
|
|
1398
|
-
reply.write(contextReport({ contextTokens: session.contextTokens, rows: session.usage() }));
|
|
1453
|
+
reply.write(contextReport({ contextTokens: session.contextTokens, rows: session.usage(), ...session.counts }));
|
|
1399
1454
|
reply.flush();
|
|
1400
1455
|
write('\n');
|
|
1401
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]}`)] : []),
|