sumo-agents 0.4.0 → 0.6.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/AGENTS.md +8 -6
- package/CHANGELOG.md +187 -0
- package/README.md +76 -18
- package/bin/sumo.mjs +13 -2
- package/guides/feature.md +2 -1
- package/guides/memory.md +6 -4
- package/guides/projects.md +1 -1
- package/guides/review.md +1 -1
- package/package.json +5 -4
- package/prompts/dream.md +6 -0
- package/spinner.txt +25 -1
- package/src/apply.mjs +146 -18
- package/src/auth.mjs +32 -5
- package/src/card.mjs +39 -2
- package/src/catalog.mjs +6 -3
- package/src/chat.mjs +186 -75
- package/src/cli.mjs +359 -135
- package/src/cost.mjs +67 -8
- package/src/db.mjs +106 -3
- package/src/dream.mjs +445 -19
- package/src/editor.mjs +3 -2
- package/src/export.mjs +105 -7
- package/src/guard.mjs +57 -11
- package/src/guides.mjs +5 -4
- package/src/herdr.mjs +1 -1
- package/src/hooks.mjs +31 -18
- package/src/jobs.mjs +118 -39
- package/src/jobtools.mjs +6 -4
- package/src/keeper.mjs +77 -0
- package/src/local-server.mjs +9 -16
- package/src/lock.mjs +2 -1
- package/src/logs.mjs +165 -0
- package/src/loop.mjs +121 -44
- package/src/mcp.mjs +72 -16
- package/src/memory.mjs +142 -15
- package/src/model.mjs +41 -21
- package/src/paths.mjs +38 -0
- package/src/prime.mjs +19 -31
- package/src/projects.mjs +76 -12
- package/src/redact.mjs +10 -0
- package/src/render.mjs +2 -1
- package/src/route.mjs +16 -22
- package/src/sandbox.mjs +82 -3
- package/src/scan.mjs +35 -1
- package/src/scribe.mjs +10 -22
- package/src/sessions.mjs +46 -11
- package/src/setup.mjs +423 -78
- package/src/text.mjs +100 -1
- package/src/tools.mjs +258 -21
- package/src/tty.mjs +210 -44
- package/src/ui.mjs +816 -226
- package/src/verify.mjs +17 -1
package/src/sessions.mjs
CHANGED
|
@@ -2,10 +2,10 @@ import { closeSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, re
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { ago } from './card.mjs';
|
|
4
4
|
import { heldBy } from './lock.mjs';
|
|
5
|
-
import { UsageError } from './memory.mjs';
|
|
5
|
+
import { Refusal, UsageError } from './memory.mjs';
|
|
6
6
|
import { paths } from './paths.mjs';
|
|
7
7
|
import { redact } from './redact.mjs';
|
|
8
|
-
import { clip, head } from './text.mjs';
|
|
8
|
+
import { cjkTerms, clip, containing, head } from './text.mjs';
|
|
9
9
|
import { readBackwards } from './transcript.mjs';
|
|
10
10
|
|
|
11
11
|
const TURN_MAX_CHARS = 4000;
|
|
@@ -52,6 +52,28 @@ export function recordTurn(db, { sessionId, text, now }) {
|
|
|
52
52
|
return Number(lastInsertRowid);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* A call that reached past the machine — a web search or fetch, an MCP server — written on its session, each tool once:
|
|
57
|
+
* what the conversation says after it may be what a page told it, so the memory pass holds what it would file from the
|
|
58
|
+
* conversation's replies for the user (arXiv 2503.03704: memory written from injected content is read later as trusted).
|
|
59
|
+
* A session not recorded yet gets nothing: a call comes after the turn that recorded it.
|
|
60
|
+
*/
|
|
61
|
+
export function noteSessionOutside(db, sessionId, tool) {
|
|
62
|
+
if (!sessionId) return;
|
|
63
|
+
const name = String(tool).replace(/\s+/g, ' ');
|
|
64
|
+
const row = db.prepare('SELECT outside_read FROM sessions WHERE id = ?').get(sessionId);
|
|
65
|
+
if (!row || (row.outside_read ?? '').split('\n').includes(name)) return;
|
|
66
|
+
db.prepare('UPDATE sessions SET outside_read = ? WHERE id = ?').run(row.outside_read ? `${row.outside_read}\n${name}` : name, sessionId);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The tools any of these sessions read past the machine with, each once, in the order first seen. */
|
|
70
|
+
export function outsideReadsOf(db, sessionIds) {
|
|
71
|
+
const ids = [...new Set(sessionIds)].filter(Boolean);
|
|
72
|
+
if (ids.length === 0) return [];
|
|
73
|
+
const rows = db.prepare(`SELECT outside_read FROM sessions WHERE id IN (${ids.map(() => '?').join(', ')}) AND outside_read IS NOT NULL`).all(...ids);
|
|
74
|
+
return [...new Set(rows.flatMap((r) => r.outside_read.split('\n')))];
|
|
75
|
+
}
|
|
76
|
+
|
|
55
77
|
export function endSession(db, id, now) {
|
|
56
78
|
db.prepare('UPDATE sessions SET ended_at = ? WHERE id = ?').run(now, id);
|
|
57
79
|
}
|
|
@@ -108,14 +130,27 @@ export function sessionsAwaitingDream(db, now, limit = 5, { includeOpen = false
|
|
|
108
130
|
.all(includeOpen ? 1 : 0, cutoff, limit);
|
|
109
131
|
}
|
|
110
132
|
|
|
111
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* What the user actually typed, searched word for word: `match` is `ftsQuery`'s expression. A Chinese, Japanese or
|
|
135
|
+
* Korean word sits inside a run the index keeps as one word, so it is looked for in the text itself: what holds the most
|
|
136
|
+
* of those words, newest first, after what the index found.
|
|
137
|
+
*/
|
|
112
138
|
export function searchTurns(db, match, limit = 8) {
|
|
113
|
-
|
|
139
|
+
const found = db
|
|
114
140
|
.prepare(
|
|
115
141
|
`SELECT t.* FROM user_turns_fts JOIN user_turns t ON t.id = user_turns_fts.rowid
|
|
116
142
|
WHERE user_turns_fts MATCH ? ORDER BY bm25(user_turns_fts), t.id DESC LIMIT ?`,
|
|
117
143
|
)
|
|
118
144
|
.all(match, limit);
|
|
145
|
+
const terms = cjkTerms(match);
|
|
146
|
+
if (terms.length === 0 || found.length >= limit) return found;
|
|
147
|
+
const holds = terms.map(() => `(text LIKE ? ESCAPE '\\')`);
|
|
148
|
+
const patterns = terms.map(containing);
|
|
149
|
+
const seen = new Set(found.map((t) => t.id));
|
|
150
|
+
const more = db
|
|
151
|
+
.prepare(`SELECT * FROM user_turns WHERE ${holds.join(' OR ')} ORDER BY ${holds.join(' + ')} DESC, id DESC LIMIT ?`)
|
|
152
|
+
.all(...patterns, ...patterns, limit + found.length);
|
|
153
|
+
return [...found, ...more.filter((t) => !seen.has(t.id))].slice(0, limit);
|
|
119
154
|
}
|
|
120
155
|
|
|
121
156
|
/**
|
|
@@ -162,8 +197,8 @@ const inK = (tokens) => `${Math.round(tokens / 1000)}k`;
|
|
|
162
197
|
*/
|
|
163
198
|
export function contextNudge(band, focus) {
|
|
164
199
|
const hint = `hint: focus on ${focus}; keep decisions and open job ids in a note; drop tool output and file contents.`;
|
|
165
|
-
if (band === 'act') return `context: very large — start fresh now: note where you are (sumo job note; the end of the turn records "Left off"), then tell the user to type /new. ${hint}`;
|
|
166
|
-
return `context: large — quality drops from here. Finish the piece in hand, then tell the user to type /
|
|
200
|
+
if (band === 'act') return `context: very large — start fresh now: note where you are (sumo job note; the end of the turn records "Left off"), then tell the user to type /handoff, which carries your hand-off into a fresh session, or /new. ${hint}`;
|
|
201
|
+
return `context: large — quality drops from here. Finish the piece in hand, then tell the user to type /handoff: a fresh session starts from your hand-off, and the memory block brings the thread back. ${hint}`;
|
|
167
202
|
}
|
|
168
203
|
|
|
169
204
|
/**
|
|
@@ -218,7 +253,7 @@ function keepBlock(block) {
|
|
|
218
253
|
}
|
|
219
254
|
|
|
220
255
|
/** The conversation as it is kept on disk: no pictures, no secrets, no cache markers (they are placed again when it is sent). */
|
|
221
|
-
|
|
256
|
+
function keepable(messages) {
|
|
222
257
|
return messages.map((m) => ({ role: m.role, content: typeof m.content === 'string' ? redact(m.content).text : m.content.map(keepBlock) }));
|
|
223
258
|
}
|
|
224
259
|
|
|
@@ -253,9 +288,9 @@ export function loadState(id) {
|
|
|
253
288
|
state = JSON.parse(readFileSync(stateFile(id), 'utf8'));
|
|
254
289
|
} catch (cause) {
|
|
255
290
|
if (cause.code === 'ENOENT') return null;
|
|
256
|
-
throw new
|
|
291
|
+
throw new Refusal(`the saved session ${shortId(id)} cannot be read: ${cause.message}`);
|
|
257
292
|
}
|
|
258
|
-
if (state?.version !== 1 || !Array.isArray(state.messages)) throw new
|
|
293
|
+
if (state?.version !== 1 || !Array.isArray(state.messages)) throw new Refusal(`the saved session ${shortId(id)} is not one this version can resume`);
|
|
259
294
|
return state;
|
|
260
295
|
}
|
|
261
296
|
|
|
@@ -321,12 +356,12 @@ export function savedSessions(db, { now, except = null } = {}) {
|
|
|
321
356
|
export function findSaved(db, ref, options) {
|
|
322
357
|
const all = savedSessions(db, options);
|
|
323
358
|
if (ref === 'last') {
|
|
324
|
-
if (all.length === 0) throw new
|
|
359
|
+
if (all.length === 0) throw new Refusal('no saved session to resume');
|
|
325
360
|
return all[0];
|
|
326
361
|
}
|
|
327
362
|
const hits = all.filter((s) => s.id.startsWith(ref));
|
|
328
363
|
if (hits.length === 1) return hits[0];
|
|
329
|
-
if (hits.length === 0) throw new
|
|
364
|
+
if (hits.length === 0) throw new Refusal(`no saved session starts with "${ref}"${all.length > 0 ? ` — one of: ${all.map((s) => shortId(s.id)).join(', ')}` : ''}`);
|
|
330
365
|
throw new UsageError(`"${ref}" could be ${hits.map((s) => shortId(s.id)).join(' or ')} — give more of the id`);
|
|
331
366
|
}
|
|
332
367
|
|