sumo-agents 0.0.0-stage → 0.3.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/AGENTS.md +38 -0
- package/LICENSE +21 -0
- package/README.md +111 -2
- package/bin/sumo.mjs +33 -0
- package/guides/delegation.md +33 -0
- package/guides/feature.md +14 -0
- package/guides/fix.md +14 -0
- package/guides/memory.md +23 -0
- package/guides/projects.md +27 -0
- package/guides/review.md +16 -0
- package/guides/workflows.md +26 -0
- package/logo.txt +19 -0
- package/package.json +42 -4
- package/prompts/agent.md +7 -0
- package/prompts/dream.md +13 -0
- package/prompts/scribe.md +21 -0
- package/spinner.txt +90 -0
- package/src/advisor.mjs +59 -0
- package/src/apply.mjs +368 -0
- package/src/auth.mjs +80 -0
- package/src/card.mjs +72 -0
- package/src/catalog.mjs +167 -0
- package/src/chat.mjs +1162 -0
- package/src/cli.mjs +815 -0
- package/src/cost.mjs +128 -0
- package/src/db.mjs +384 -0
- package/src/dream.mjs +97 -0
- package/src/editor.mjs +198 -0
- package/src/export.mjs +132 -0
- package/src/guard.mjs +121 -0
- package/src/guides.mjs +86 -0
- package/src/herdr.mjs +117 -0
- package/src/hooks.mjs +270 -0
- package/src/images.mjs +89 -0
- package/src/jobs.mjs +1184 -0
- package/src/jobtools.mjs +82 -0
- package/src/local-server.mjs +169 -0
- package/src/lock.mjs +45 -0
- package/src/loop.mjs +838 -0
- package/src/mcp.mjs +604 -0
- package/src/memory.mjs +400 -0
- package/src/model.mjs +270 -0
- package/src/page.html +304 -0
- package/src/page.mjs +135 -0
- package/src/paths.mjs +33 -0
- package/src/prime.mjs +177 -0
- package/src/projects.mjs +232 -0
- package/src/recall.mjs +45 -0
- package/src/redact.mjs +173 -0
- package/src/render.mjs +45 -0
- package/src/route.mjs +287 -0
- package/src/sandbox.mjs +173 -0
- package/src/scan.mjs +204 -0
- package/src/scribe.mjs +349 -0
- package/src/sessions.mjs +371 -0
- package/src/setup.mjs +528 -0
- package/src/sqlite.mjs +66 -0
- package/src/text.mjs +97 -0
- package/src/tools.mjs +987 -0
- package/src/transcript.mjs +106 -0
- package/src/tty.mjs +529 -0
- package/src/ui.mjs +1363 -0
- package/src/verify.mjs +369 -0
- package/src/web.mjs +49 -0
- package/src/workflows.mjs +270 -0
- package/src/worktree.mjs +128 -0
package/src/page.html
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<meta name="referrer" content="no-referrer">
|
|
7
|
+
<title>Sumo memory</title>
|
|
8
|
+
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ctext y='.9em' font-size='90'%3E%F0%9F%A6%81%3C/text%3E%3C/svg%3E">
|
|
9
|
+
<style nonce="__NONCE__">
|
|
10
|
+
:root {
|
|
11
|
+
color-scheme: light dark;
|
|
12
|
+
--bg: #f7f6f3; --surface: #ffffff; --text: #1f1d1a; --muted: #6b665f; --line: #e5e1da;
|
|
13
|
+
--accent: #9a4a0c; --on-accent: #ffffff; --accent-soft: #fbf1e6; --danger: #b42318; --focus: #2563eb;
|
|
14
|
+
}
|
|
15
|
+
@media (prefers-color-scheme: dark) {
|
|
16
|
+
:root {
|
|
17
|
+
--bg: #131211; --surface: #1c1b19; --text: #ece9e4; --muted: #a39d95; --line: #2e2c29;
|
|
18
|
+
--accent: #f0a35e; --on-accent: #1a1209; --accent-soft: #261e16; --danger: #f97066; --focus: #7aa2ff;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
* { box-sizing: border-box; }
|
|
22
|
+
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
|
|
23
|
+
.wrap { max-width: 880px; margin: 0 auto; padding: 0 20px; }
|
|
24
|
+
header { position: sticky; top: 0; z-index: 2; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
|
|
25
|
+
header .wrap { padding-top: 18px; padding-bottom: 12px; display: grid; gap: 10px; }
|
|
26
|
+
.title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
|
|
27
|
+
h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
|
|
28
|
+
.summary { color: var(--muted); font-size: 13px; }
|
|
29
|
+
#filter { width: 100%; font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }
|
|
30
|
+
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
31
|
+
.chip { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--surface); }
|
|
32
|
+
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
|
|
33
|
+
.chip .n { opacity: 0.6; margin-left: 4px; }
|
|
34
|
+
main { padding-top: 20px; padding-bottom: 96px; }
|
|
35
|
+
section { margin-bottom: 30px; }
|
|
36
|
+
h2 { font-size: 16px; margin: 0 0 2px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
|
|
37
|
+
h2 .path { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); font-weight: normal; overflow-wrap: anywhere; }
|
|
38
|
+
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 16px 0 6px; font-weight: 600; }
|
|
39
|
+
.n { font-weight: normal; }
|
|
40
|
+
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
|
|
41
|
+
.waiting .list { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
|
|
42
|
+
.waiting h2::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); align-self: center; }
|
|
43
|
+
.item { padding: 11px 14px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; }
|
|
44
|
+
.item:first-child { border-top: 0; }
|
|
45
|
+
.item > .content, .item > .meta { grid-column: 1; }
|
|
46
|
+
.text, .steps { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
|
|
47
|
+
.steps { font-size: 14px; margin-top: 4px; }
|
|
48
|
+
.ptitle { font-weight: 600; }
|
|
49
|
+
.cue { font-size: 13px; color: var(--muted); }
|
|
50
|
+
blockquote { margin: 4px 0 0; padding-left: 10px; border-left: 2px solid color-mix(in srgb, var(--accent) 50%, var(--line)); color: var(--muted); font-size: 13px; }
|
|
51
|
+
.meta { font-size: 12px; color: var(--muted); }
|
|
52
|
+
.actions { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 6px; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; opacity: 0; transition: opacity 0.12s; }
|
|
53
|
+
.item:hover .actions, .item:focus-within .actions, .waiting .actions, .item.open .actions { opacity: 1; }
|
|
54
|
+
.ask { font-size: 13px; color: var(--muted); align-self: center; }
|
|
55
|
+
.item.open { grid-template-columns: 1fr; }
|
|
56
|
+
.item.open .actions { grid-column: 1; grid-row: auto; justify-content: flex-start; align-items: center; }
|
|
57
|
+
button { font: inherit; font-size: 13px; padding: 3px 10px; border-radius: 7px; border: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer; }
|
|
58
|
+
button:hover { border-color: var(--muted); }
|
|
59
|
+
button:disabled { opacity: 0.5; cursor: default; }
|
|
60
|
+
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
|
|
61
|
+
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
|
|
62
|
+
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
|
|
63
|
+
textarea { width: 100%; font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--focus); background: var(--bg); color: var(--text); resize: vertical; }
|
|
64
|
+
.hint { font-size: 12px; color: var(--muted); margin-left: auto; }
|
|
65
|
+
.empty { color: var(--muted); text-align: center; padding: 48px 0; }
|
|
66
|
+
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: opacity 0.18s, transform 0.18s; pointer-events: none; max-width: calc(100% - 32px); }
|
|
67
|
+
.toast.show { opacity: 1; transform: translate(-50%, 0); }
|
|
68
|
+
.toast.error { background: var(--danger); color: #fff; }
|
|
69
|
+
@media (hover: none) { .actions { opacity: 1; } }
|
|
70
|
+
@media (max-width: 600px) {
|
|
71
|
+
.item { grid-template-columns: 1fr; }
|
|
72
|
+
.actions { grid-column: 1; grid-row: auto; justify-content: flex-start; opacity: 1; }
|
|
73
|
+
}
|
|
74
|
+
</style>
|
|
75
|
+
</head>
|
|
76
|
+
<body>
|
|
77
|
+
<header>
|
|
78
|
+
<div class="wrap">
|
|
79
|
+
<div class="title"><h1>Memory</h1><span class="summary" id="summary"></span></div>
|
|
80
|
+
<input id="filter" type="search" placeholder="Filter — press / to jump here" aria-label="Filter memories" autocomplete="off">
|
|
81
|
+
<nav class="chips" id="scopes" aria-label="Show"></nav>
|
|
82
|
+
</div>
|
|
83
|
+
</header>
|
|
84
|
+
<main class="wrap" id="main"></main>
|
|
85
|
+
<div class="toast" id="toast" role="status" aria-live="polite"></div>
|
|
86
|
+
<script nonce="__NONCE__">
|
|
87
|
+
const BASE = location.pathname.endsWith('/') ? location.pathname : location.pathname + '/';
|
|
88
|
+
const SAID = { stated: 'you said it', observed: 'observed', scanned: 'scanned from the repo', inferred: 'a guess' };
|
|
89
|
+
const ui = { data: null, scope: 'all', query: '', editing: null, drafts: new Map(), forgetting: null, busy: false };
|
|
90
|
+
const $ = (id) => document.getElementById(id);
|
|
91
|
+
|
|
92
|
+
/** Every piece of text goes in as text: what is remembered is never read as markup. */
|
|
93
|
+
function h(tag, props, ...kids) {
|
|
94
|
+
const node = document.createElement(tag);
|
|
95
|
+
for (const [k, v] of Object.entries(props || {})) {
|
|
96
|
+
if (v === undefined || v === null || v === false) continue;
|
|
97
|
+
if (k === 'class') node.className = v;
|
|
98
|
+
else if (k.startsWith('on')) node.addEventListener(k.slice(2), v);
|
|
99
|
+
else node.setAttribute(k, v === true ? '' : String(v));
|
|
100
|
+
}
|
|
101
|
+
for (const kid of kids.flat(Infinity)) if (kid !== undefined && kid !== null && kid !== false) node.append(kid);
|
|
102
|
+
return node;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let toastTimer;
|
|
106
|
+
function toast(text, error) {
|
|
107
|
+
const t = $('toast');
|
|
108
|
+
t.textContent = text;
|
|
109
|
+
t.className = 'toast show' + (error ? ' error' : '');
|
|
110
|
+
clearTimeout(toastTimer);
|
|
111
|
+
toastTimer = setTimeout(() => (t.className = 'toast' + (error ? ' error' : '')), error ? 6000 : 3500);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const gone = 'The page has lost Sumo — run `sumo memory`, or /memory in the chat, and use the new address.';
|
|
115
|
+
|
|
116
|
+
async function load() {
|
|
117
|
+
if (ui.editing !== null || ui.busy) return;
|
|
118
|
+
try {
|
|
119
|
+
const res = await fetch(BASE + 'memories', { cache: 'no-store' });
|
|
120
|
+
if (!res.ok) throw new Error('the memory could not be read (' + res.status + ')');
|
|
121
|
+
ui.data = await res.json();
|
|
122
|
+
render();
|
|
123
|
+
} catch (e) {
|
|
124
|
+
toast(e instanceof TypeError ? gone : e.message, true);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function act(id, action, payload) {
|
|
129
|
+
ui.busy = true;
|
|
130
|
+
render();
|
|
131
|
+
try {
|
|
132
|
+
const res = await fetch(BASE + 'memories/' + id + '/' + action, {
|
|
133
|
+
method: 'POST',
|
|
134
|
+
headers: { 'content-type': 'application/json' },
|
|
135
|
+
body: JSON.stringify(payload || {}),
|
|
136
|
+
});
|
|
137
|
+
const out = await res.json().catch(() => ({}));
|
|
138
|
+
if (!res.ok) throw new Error(out.error || 'that did not work (' + res.status + ')');
|
|
139
|
+
return out;
|
|
140
|
+
} catch (e) {
|
|
141
|
+
throw e instanceof TypeError ? new Error(gone) : e;
|
|
142
|
+
} finally {
|
|
143
|
+
ui.busy = false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function run(id, action, payload, said) {
|
|
148
|
+
try {
|
|
149
|
+
const out = await act(id, action, payload);
|
|
150
|
+
if (action === 'edit') ui.drafts.delete(id);
|
|
151
|
+
ui.editing = null;
|
|
152
|
+
ui.forgetting = null;
|
|
153
|
+
toast(said(out));
|
|
154
|
+
} catch (e) {
|
|
155
|
+
toast(e.message, true);
|
|
156
|
+
render();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
await load();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const scopeName = (scope) => {
|
|
163
|
+
if (scope === 'global') return 'Global';
|
|
164
|
+
const slug = scope.slice('project:'.length);
|
|
165
|
+
const p = ui.data.projects.find((x) => x.slug === slug);
|
|
166
|
+
return p ? p.name : slug;
|
|
167
|
+
};
|
|
168
|
+
const scopePath = (scope) => {
|
|
169
|
+
const p = ui.data.projects.find((x) => 'project:' + x.slug === scope);
|
|
170
|
+
return p ? p.path : '';
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
function meta(m, withScope) {
|
|
174
|
+
const parts = ['m' + m.id, SAID[m.provenance] || m.provenance, 'since ' + m.valid_from.slice(0, 10)];
|
|
175
|
+
if (withScope) parts.unshift(scopeName(m.scope));
|
|
176
|
+
if (m.topic) parts.push(m.topic);
|
|
177
|
+
if (m.pinned) parts.push('pinned');
|
|
178
|
+
return h('div', { class: 'meta' }, parts.join(' · '));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function content(m) {
|
|
182
|
+
if (m.type !== 'procedure') return h('div', { class: 'content' }, h('p', { class: 'text' }, m.body));
|
|
183
|
+
return h('div', { class: 'content' },
|
|
184
|
+
h('div', { class: 'ptitle' }, m.title),
|
|
185
|
+
m.cue && h('div', { class: 'cue' }, 'when: ' + m.cue),
|
|
186
|
+
h('pre', { class: 'steps' }, m.body));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function editor(m) {
|
|
190
|
+
const area = h('textarea', { 'aria-label': 'Edit m' + m.id, disabled: ui.busy, rows: Math.min(14, Math.max(2, m.body.split('\n').length + Math.floor(m.body.length / 90))) });
|
|
191
|
+
area.value = ui.drafts.get(m.id) ?? m.body;
|
|
192
|
+
area.addEventListener('input', () => ui.drafts.set(m.id, area.value));
|
|
193
|
+
const cancel = () => { ui.drafts.delete(m.id); ui.editing = null; render(); };
|
|
194
|
+
const save = () => {
|
|
195
|
+
const body = area.value.trim();
|
|
196
|
+
if (!body || body === m.body.trim()) return body ? cancel() : toast('A memory cannot be empty — use Forget instead.', true);
|
|
197
|
+
run(m.id, 'edit', { body }, (out) => 'Saved as m' + out.memory.id + ' — m' + m.id + ' stays in its history' + (out.redacted ? '; a secret-looking value was taken out' : ''));
|
|
198
|
+
};
|
|
199
|
+
area.addEventListener('keydown', (e) => {
|
|
200
|
+
if (e.key === 'Escape') cancel();
|
|
201
|
+
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) save();
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
area,
|
|
205
|
+
actions: [
|
|
206
|
+
h('button', { class: 'primary', onclick: save, disabled: ui.busy }, 'Save'),
|
|
207
|
+
h('button', { onclick: cancel }, 'Cancel'),
|
|
208
|
+
h('span', { class: 'hint' }, '⌘/Ctrl ↵ saves · Esc cancels'),
|
|
209
|
+
],
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function item(m) {
|
|
214
|
+
if (ui.editing === m.id) {
|
|
215
|
+
const { area, actions } = editor(m);
|
|
216
|
+
return h('li', { class: 'item open', id: 'm' + m.id },
|
|
217
|
+
m.type === 'procedure' && h('div', { class: 'ptitle' }, m.title),
|
|
218
|
+
area, h('div', { class: 'actions' }, actions));
|
|
219
|
+
}
|
|
220
|
+
const forgetting = ui.forgetting === m.id;
|
|
221
|
+
const actions = forgetting
|
|
222
|
+
? [
|
|
223
|
+
h('span', { class: 'ask' }, 'Stop remembering this? Its history is kept.'),
|
|
224
|
+
h('button', { class: 'danger', disabled: ui.busy, onclick: () => run(m.id, 'forget', {}, () => 'Forgot m' + m.id) }, 'Forget'),
|
|
225
|
+
h('button', { onclick: () => { ui.forgetting = null; render(); } }, 'Keep'),
|
|
226
|
+
]
|
|
227
|
+
: [
|
|
228
|
+
h('button', { disabled: ui.busy, onclick: () => { ui.editing = m.id; ui.forgetting = null; render(); } }, 'Edit'),
|
|
229
|
+
h('button', { class: 'danger', disabled: ui.busy, onclick: () => { ui.forgetting = m.id; render(); } }, 'Forget'),
|
|
230
|
+
];
|
|
231
|
+
return h('li', { class: 'item' + (forgetting ? ' open' : ''), id: 'm' + m.id }, content(m), meta(m, false), h('div', { class: 'actions' }, actions));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function guess(m) {
|
|
235
|
+
const kind = (ui.data.sections.find(([t]) => t === m.type) || [m.type, m.type])[1].replace(/s$/, '').toLowerCase();
|
|
236
|
+
return h('li', { class: 'item', id: 'm' + m.id },
|
|
237
|
+
h('div', { class: 'content' },
|
|
238
|
+
content(m),
|
|
239
|
+
m.source_quote && h('blockquote', {}, m.source_quote)),
|
|
240
|
+
h('div', { class: 'meta' }, scopeName(m.scope) + ' · ' + kind + ' · m' + m.id + ' · since ' + m.valid_from.slice(0, 10)),
|
|
241
|
+
h('div', { class: 'actions' },
|
|
242
|
+
h('button', { class: 'primary', disabled: ui.busy, onclick: () => run(m.id, 'confirm', {}, () => 'Kept m' + m.id + ' as something you said') }, 'Yes, keep it'),
|
|
243
|
+
h('button', { disabled: ui.busy, onclick: () => run(m.id, 'reject', {}, () => 'Dropped m' + m.id) }, 'No')));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function render() {
|
|
247
|
+
if (!ui.data) return;
|
|
248
|
+
const { memories, sections, machine } = ui.data;
|
|
249
|
+
const q = ui.query.trim().toLowerCase();
|
|
250
|
+
const matches = (m) => !q || [m.body, m.title, m.cue, m.topic, 'm' + m.id].some((t) => t && t.toLowerCase().includes(q));
|
|
251
|
+
const shown = (m) => (ui.scope === 'all' || m.scope === ui.scope) && matches(m);
|
|
252
|
+
const active = memories.filter((m) => m.state === 'active');
|
|
253
|
+
const waiting = memories.filter((m) => m.state === 'unconfirmed');
|
|
254
|
+
const scopes = ['global', ...[...new Set(memories.map((m) => m.scope))].filter((s) => s !== 'global').sort()];
|
|
255
|
+
|
|
256
|
+
$('summary').textContent = [machine, active.length + ' remembered', waiting.length ? waiting.length + ' waiting for you' : null].filter(Boolean).join(' · ');
|
|
257
|
+
$('scopes').replaceChildren(
|
|
258
|
+
...['all', ...scopes].map((s) => {
|
|
259
|
+
const n = s === 'all' ? memories.length : memories.filter((m) => m.scope === s).length;
|
|
260
|
+
return h('button', { class: 'chip', 'aria-pressed': ui.scope === s ? 'true' : 'false', onclick: () => { ui.scope = s; render(); } },
|
|
261
|
+
s === 'all' ? 'All' : scopeName(s), h('span', { class: 'n' }, String(n)));
|
|
262
|
+
}));
|
|
263
|
+
|
|
264
|
+
const out = [];
|
|
265
|
+
const ask = waiting.filter(shown);
|
|
266
|
+
if (ask.length) {
|
|
267
|
+
out.push(h('section', { class: 'waiting' },
|
|
268
|
+
h('h2', {}, 'Waiting for your yes or no', h('span', { class: 'n summary' }, String(ask.length))),
|
|
269
|
+
h('h3', {}, 'Guesses from what you said — kept only if you say yes'),
|
|
270
|
+
h('ul', { class: 'list' }, ask.map(guess))));
|
|
271
|
+
}
|
|
272
|
+
for (const scope of scopes) {
|
|
273
|
+
const mine = active.filter((m) => m.scope === scope && shown(m));
|
|
274
|
+
if (!mine.length) continue;
|
|
275
|
+
const groups = sections
|
|
276
|
+
.map(([type, heading]) => [heading, mine.filter((m) => m.type === type)])
|
|
277
|
+
.filter(([, list]) => list.length)
|
|
278
|
+
.map(([heading, list]) => [h('h3', {}, heading, ' ', h('span', { class: 'n' }, String(list.length))), h('ul', { class: 'list' }, list.map(item))]);
|
|
279
|
+
out.push(h('section', {}, h('h2', {}, scopeName(scope), scopePath(scope) && h('span', { class: 'path' }, scopePath(scope))), groups));
|
|
280
|
+
}
|
|
281
|
+
if (!out.length) out.push(h('p', { class: 'empty' }, memories.length ? 'Nothing matches “' + ui.query.trim() + '”.' : 'Nothing remembered yet.'));
|
|
282
|
+
$('main').replaceChildren(...out);
|
|
283
|
+
|
|
284
|
+
const area = document.querySelector('textarea');
|
|
285
|
+
// Typing in the filter redraws too; the edit box takes focus only when the filter does not hold it.
|
|
286
|
+
if (area && document.activeElement !== area && document.activeElement !== $('filter')) {
|
|
287
|
+
area.focus();
|
|
288
|
+
area.setSelectionRange(area.value.length, area.value.length);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
$('filter').addEventListener('input', (e) => { ui.query = e.target.value; render(); });
|
|
293
|
+
document.addEventListener('keydown', (e) => {
|
|
294
|
+
if (e.key === '/' && !/^(INPUT|TEXTAREA)$/.test(document.activeElement.tagName)) {
|
|
295
|
+
e.preventDefault();
|
|
296
|
+
$('filter').focus();
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
// What the background writer filed while the page sat in another tab shows up on coming back to it.
|
|
300
|
+
window.addEventListener('focus', load);
|
|
301
|
+
load();
|
|
302
|
+
</script>
|
|
303
|
+
</body>
|
|
304
|
+
</html>
|
package/src/page.mjs
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { appendFileSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { createServer } from 'node:http';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { getMeta } from './db.mjs';
|
|
7
|
+
import { SECTIONS } from './export.mjs';
|
|
8
|
+
import * as memory from './memory.mjs';
|
|
9
|
+
import { UsageError } from './memory.mjs';
|
|
10
|
+
import { REPO_ROOT } from './paths.mjs';
|
|
11
|
+
|
|
12
|
+
const PAGE = readFileSync(join(REPO_ROOT, 'src', 'page.html'), 'utf8');
|
|
13
|
+
const MAX_BODY = 64 * 1024;
|
|
14
|
+
|
|
15
|
+
/** What the page may do. Erasing for good is not here: `sumo forget --purge` stays a command someone types. */
|
|
16
|
+
const ACTIONS = {
|
|
17
|
+
confirm: (db, id) => ({ memory: memory.confirm(db, id) }),
|
|
18
|
+
reject: (db, id) => ({ memory: memory.reject(db, id) }),
|
|
19
|
+
forget: (db, id) => ({ memory: memory.forget(db, id) }),
|
|
20
|
+
edit: (db, id, { body }) => edit(db, id, body),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** An edit is a new memory in the old one's place, so `sumo history` still shows what it said before. */
|
|
24
|
+
function edit(db, id, body) {
|
|
25
|
+
const old = memory.get(db, id);
|
|
26
|
+
// A fact read from the project's files would come back, unedited, beside the edit at the next rescan.
|
|
27
|
+
if (old.scan_key !== null) {
|
|
28
|
+
throw new UsageError(`m${id} was read from the project's files — change it there, then: sumo project rescan ${old.scope.slice('project:'.length)}`);
|
|
29
|
+
}
|
|
30
|
+
const { memory: saved, redacted } = memory.add(db, {
|
|
31
|
+
type: old.type,
|
|
32
|
+
project: old.scope === 'global' ? undefined : old.scope.slice('project:'.length),
|
|
33
|
+
title: old.title,
|
|
34
|
+
cue: old.cue,
|
|
35
|
+
gate: old.gate ?? undefined,
|
|
36
|
+
topic: old.topic,
|
|
37
|
+
pin: old.pinned === 1,
|
|
38
|
+
body: String(body ?? ''),
|
|
39
|
+
writtenBy: 'user',
|
|
40
|
+
supersedes: id,
|
|
41
|
+
});
|
|
42
|
+
return { memory: saved, redacted };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function snapshot(db) {
|
|
46
|
+
return {
|
|
47
|
+
machine: getMeta(db, 'machine'),
|
|
48
|
+
sections: SECTIONS,
|
|
49
|
+
projects: db.prepare('SELECT slug, name, path FROM projects ORDER BY slug').all(),
|
|
50
|
+
memories: db.prepare(`SELECT * FROM memories WHERE state IN ('active', 'unconfirmed') ORDER BY id`).all(),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function readJson(req) {
|
|
55
|
+
let text = '';
|
|
56
|
+
// Decoded across chunks: a character split between two of them still arrives whole.
|
|
57
|
+
req.setEncoding('utf8');
|
|
58
|
+
for await (const chunk of req) {
|
|
59
|
+
text += chunk;
|
|
60
|
+
if (text.length > MAX_BODY) throw new UsageError('that is more than a memory');
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
return text.trim() ? JSON.parse(text) : {};
|
|
64
|
+
} catch {
|
|
65
|
+
throw new UsageError('the request was not JSON');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The memory as a page, at http://127.0.0.1:<port>/<token>/. Anything else on the
|
|
71
|
+
* machine can reach the port, so the address carries a secret; a browser can be
|
|
72
|
+
* pointed here by another site, so a request must name this host, and a change
|
|
73
|
+
* must come as JSON from this page — which another site cannot send without asking.
|
|
74
|
+
* `unref`: the page lives only as long as whatever else keeps the process alive.
|
|
75
|
+
*/
|
|
76
|
+
export function servePage(db, { unref = false } = {}) {
|
|
77
|
+
const token = randomBytes(16).toString('hex');
|
|
78
|
+
const nonce = randomBytes(16).toString('base64');
|
|
79
|
+
const html = PAGE.replaceAll('__NONCE__', nonce);
|
|
80
|
+
const csp = `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'nonce-${nonce}'; img-src data:; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`;
|
|
81
|
+
let origin = '';
|
|
82
|
+
|
|
83
|
+
const server = createServer(async (req, res) => {
|
|
84
|
+
// No connection outlives its answer: a browser holding one open would keep the process from ending.
|
|
85
|
+
const send = (status, type, body, headers = {}) => {
|
|
86
|
+
res.writeHead(status, { 'content-type': type, 'cache-control': 'no-store', 'x-content-type-options': 'nosniff', 'referrer-policy': 'no-referrer', connection: 'close', ...headers });
|
|
87
|
+
res.end(body);
|
|
88
|
+
};
|
|
89
|
+
const json = (status, data) => send(status, 'application/json; charset=utf-8', JSON.stringify(data));
|
|
90
|
+
try {
|
|
91
|
+
if (`http://${req.headers.host}` !== origin) return json(403, { error: 'not this page' });
|
|
92
|
+
const { pathname } = new URL(req.url, origin);
|
|
93
|
+
const prefix = `/${token}/`;
|
|
94
|
+
if (!pathname.startsWith(prefix)) return json(404, { error: 'no such page' });
|
|
95
|
+
const path = pathname.slice(prefix.length);
|
|
96
|
+
if (req.method === 'GET' && path === '') return send(200, 'text/html; charset=utf-8', html, { 'content-security-policy': csp });
|
|
97
|
+
if (req.method === 'GET' && path === 'memories') return json(200, snapshot(db));
|
|
98
|
+
|
|
99
|
+
const action = /^memories\/(\d+)\/(\w+)$/.exec(path);
|
|
100
|
+
if (req.method !== 'POST' || !action || !Object.hasOwn(ACTIONS, action[2])) return json(404, { error: 'no such page' });
|
|
101
|
+
if (req.headers.origin !== undefined && req.headers.origin !== origin) return json(403, { error: 'not from this page' });
|
|
102
|
+
if (!/^application\/json\b/.test(req.headers['content-type'] ?? '')) return json(415, { error: 'changes come as JSON' });
|
|
103
|
+
return json(200, ACTIONS[action[2]](db, Number(action[1]), await readJson(req)));
|
|
104
|
+
} catch (cause) {
|
|
105
|
+
return json(cause instanceof UsageError ? 400 : 500, { error: cause.message });
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
server.once('error', reject);
|
|
111
|
+
server.listen(0, '127.0.0.1', () => {
|
|
112
|
+
if (unref) server.unref();
|
|
113
|
+
origin = `http://127.0.0.1:${server.address().port}`;
|
|
114
|
+
resolve({
|
|
115
|
+
url: `${origin}/${token}/`,
|
|
116
|
+
close: () => new Promise((done) => server.close(() => done())),
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Asks the desktop to open the page. SUMO_AGENTS_SPAWN_LOG records the request
|
|
124
|
+
* instead, as spawnDetached does, so the tests never open a browser.
|
|
125
|
+
*/
|
|
126
|
+
export function openInBrowser(url) {
|
|
127
|
+
if (process.env.SUMO_AGENTS_SPAWN_LOG) {
|
|
128
|
+
appendFileSync(process.env.SUMO_AGENTS_SPAWN_LOG, `open ${url}\n`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const child = spawn(process.platform === 'darwin' ? 'open' : 'xdg-open', [url], { detached: true, stdio: 'ignore' });
|
|
132
|
+
// No opener (a server, a container): the address has been printed, and that is enough.
|
|
133
|
+
child.on('error', () => {});
|
|
134
|
+
child.unref();
|
|
135
|
+
}
|
package/src/paths.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { dirname, join, resolve } from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The binary `npm run build:bin` makes runs its code from inside itself (Bun's /$bunfs/), with the files sumo reads
|
|
7
|
+
* (AGENTS.md, guides, prompts…) laid out in the folder beside it: that folder stands for the repo, the binary for the entry.
|
|
8
|
+
*/
|
|
9
|
+
export const COMPILED = import.meta.url.startsWith('file:///$bunfs/');
|
|
10
|
+
export const REPO_ROOT = COMPILED ? dirname(process.execPath) : resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
11
|
+
export const ENTRY = COMPILED ? process.execPath : join(REPO_ROOT, 'bin', 'sumo.mjs');
|
|
12
|
+
/** The words that start this sumo again: the binary alone, or this node on the entry. */
|
|
13
|
+
export const SELF = COMPILED ? [ENTRY] : [process.execPath, '--disable-warning=ExperimentalWarning', ENTRY];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Everything learned lives here, outside the repo and never in git.
|
|
17
|
+
* SUMO_AGENTS_HOME exists so tests (and a second profile) never touch the real one.
|
|
18
|
+
* Made absolute here: the launcher link and a job's Herdr tab use it from another directory.
|
|
19
|
+
*/
|
|
20
|
+
export function paths() {
|
|
21
|
+
const home = resolve(process.env.SUMO_AGENTS_HOME || join(homedir(), '.sumo-agents'));
|
|
22
|
+
return {
|
|
23
|
+
home,
|
|
24
|
+
db: join(home, 'memory.db'),
|
|
25
|
+
bin: join(home, 'bin'),
|
|
26
|
+
launcher: join(home, 'bin', 'sumo'),
|
|
27
|
+
logs: join(home, 'logs'),
|
|
28
|
+
backups: join(home, 'backups'),
|
|
29
|
+
jobs: join(home, 'jobs'),
|
|
30
|
+
models: join(home, 'models'),
|
|
31
|
+
scratch: join(home, 'scratch'),
|
|
32
|
+
};
|
|
33
|
+
}
|
package/src/prime.mjs
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { ago } from './card.mjs';
|
|
3
|
+
import { getMeta } from './db.mjs';
|
|
4
|
+
import { paths } from './paths.mjs';
|
|
5
|
+
import { isScratch, listProjects, scratchDays } from './projects.mjs';
|
|
6
|
+
import { CONFIG_DEFAULTS } from './setup.mjs';
|
|
7
|
+
import { clip, estimateTokens } from './text.mjs';
|
|
8
|
+
|
|
9
|
+
const LINE_MAX = 120;
|
|
10
|
+
const NAME_MAX = 60;
|
|
11
|
+
const MAX_PROJECTS = 12;
|
|
12
|
+
const MAX_LEFT_OFF = 3;
|
|
13
|
+
const MAX_CONFIRM = 3;
|
|
14
|
+
const MAX_NOTICES = 2;
|
|
15
|
+
const SCRIBE_FAILURES_TO_WARN = 3;
|
|
16
|
+
/** A preference never used, and said more days ago than this, is the first to leave the block when room is short. */
|
|
17
|
+
const UNUSED_DAYS = 60;
|
|
18
|
+
|
|
19
|
+
// Only a whole leading directory: /Users/sumo2 is not inside /Users/sumo.
|
|
20
|
+
const tilde = (path) => (path === homedir() || path.startsWith(`${homedir()}/`) ? `~${path.slice(homedir().length)}` : path);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The block every session starts with. It is generated, never hand-kept, and
|
|
24
|
+
* it has a hard ceiling — which is the whole answer to "memory files grow until
|
|
25
|
+
* they are the problem". Everything that does not fit is reachable by search,
|
|
26
|
+
* and the block says so rather than silently pretending to be complete.
|
|
27
|
+
*/
|
|
28
|
+
export function prime(db, { budget, now = new Date().toISOString() } = {}) {
|
|
29
|
+
const asked = budget ?? Number(getMeta(db, 'config.prime.budget') ?? CONFIG_DEFAULTS['prime.budget']);
|
|
30
|
+
// A budget that is not a number would hold nothing back: the default stands in for it.
|
|
31
|
+
const limit = Number.isInteger(asked) && asked > 0 ? asked : Number(CONFIG_DEFAULTS['prime.budget']);
|
|
32
|
+
const machine = getMeta(db, 'machine');
|
|
33
|
+
const open = `<sumo-memory${machine ? ` machine="${machine}"` : ''}>`;
|
|
34
|
+
const close = '</sumo-memory>';
|
|
35
|
+
|
|
36
|
+
// The small, time-sensitive sections are fixed first; preferences get whatever room is left.
|
|
37
|
+
// Preserve the compact layout normally; when it cannot fit, keep time-sensitive lines first.
|
|
38
|
+
const sections = [workflows(db), projectsLine(db), leftOff(db, now), jobs(db, now), toConfirm(db), warnings(db)];
|
|
39
|
+
// Where the work with no project goes is said every time, and is not something remembered.
|
|
40
|
+
const remembered = sections.flat().length;
|
|
41
|
+
sections.splice(2, 0, scratchLine(db));
|
|
42
|
+
const fixed = sections.flat();
|
|
43
|
+
const spent = estimateTokens([open, ...fixed, close].join('\n'));
|
|
44
|
+
const prefs = preferences(db, limit - spent, now);
|
|
45
|
+
|
|
46
|
+
const lines = [open, ...prefs, ...fixed, close];
|
|
47
|
+
if (prefs.length + remembered === 0) lines.splice(1, 0, 'Nothing remembered yet. It fills in as the user talks.');
|
|
48
|
+
const block = lines.join('\n');
|
|
49
|
+
if (estimateTokens(block) <= limit) return block;
|
|
50
|
+
|
|
51
|
+
const more = 'More memory: sumo search · sumo project list · sumo job list';
|
|
52
|
+
const wrap = (body) => [open, ...body, close].join('\n');
|
|
53
|
+
// A budget too small for even the envelope carries a bounded pointer instead.
|
|
54
|
+
if (estimateTokens(wrap([more])) > limit) return clip('Memory: sumo search', limit * 4);
|
|
55
|
+
const kept = [];
|
|
56
|
+
for (const text of [...sections.slice().reverse().flat(), ...prefs]) {
|
|
57
|
+
if (estimateTokens(wrap([...kept, text, more])) <= limit) kept.push(text);
|
|
58
|
+
}
|
|
59
|
+
return wrap([...kept, more]);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The user's global preferences and decisions under a budget: a heading, then one line each. Pinned come first, then
|
|
64
|
+
* the weightier kind; within those, what was used last — found by a search, or handed over before a question — comes
|
|
65
|
+
* first, and one not used yet counts from the day it was said. So where room is short, one never used and said more
|
|
66
|
+
* than UNUSED_DAYS ago leaves first, then the least recently used. Left out is not lost: a search finds it, and being
|
|
67
|
+
* found brings it back.
|
|
68
|
+
*/
|
|
69
|
+
export function preferences(db, room, now = new Date().toISOString()) {
|
|
70
|
+
const unusedSince = new Date(Date.parse(now) - UNUSED_DAYS * 86_400_000).toISOString();
|
|
71
|
+
const rows = db
|
|
72
|
+
.prepare(
|
|
73
|
+
`SELECT * FROM memories WHERE scope = 'global' AND state = 'active' AND type IN ('preference', 'decision')
|
|
74
|
+
ORDER BY pinned DESC, importance DESC, (last_hit_at IS NULL AND created_at < ?), COALESCE(last_hit_at, created_at) DESC, hits DESC, id DESC`,
|
|
75
|
+
)
|
|
76
|
+
.all(unusedSince);
|
|
77
|
+
if (rows.length === 0) return [];
|
|
78
|
+
|
|
79
|
+
// Room for the heading, written at its longest, is set aside before any line is chosen.
|
|
80
|
+
const heading = (shown, rest) =>
|
|
81
|
+
rest.length === 0
|
|
82
|
+
? 'Preferences:'
|
|
83
|
+
: `Preferences (${shown} of ${rows.length} shown · more on: ${topics(rest)} — sumo search before assuming):`;
|
|
84
|
+
let used = estimateTokens(heading(rows.length, rows)) + 1;
|
|
85
|
+
|
|
86
|
+
const shown = [];
|
|
87
|
+
for (const m of rows) {
|
|
88
|
+
const text = `- m${m.id} ${clip(m.body, LINE_MAX)}`;
|
|
89
|
+
const cost = estimateTokens(text) + 1;
|
|
90
|
+
if (used + cost > room) break;
|
|
91
|
+
used += cost;
|
|
92
|
+
shown.push(text);
|
|
93
|
+
}
|
|
94
|
+
const rest = rows.slice(shown.length);
|
|
95
|
+
return [heading(shown.length, rest), ...shown];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** What the hidden preferences are about, so the agent knows what to search for instead of assuming there is nothing. */
|
|
99
|
+
function topics(rows) {
|
|
100
|
+
const counts = new Map();
|
|
101
|
+
for (const m of rows) counts.set(m.topic ?? 'other', (counts.get(m.topic ?? 'other') ?? 0) + 1);
|
|
102
|
+
return [...counts.entries()]
|
|
103
|
+
.sort((a, b) => b[1] - a[1])
|
|
104
|
+
.slice(0, 6)
|
|
105
|
+
.map(([topic, n]) => `${topic}(${n})`)
|
|
106
|
+
.join(' ');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function workflows(db) {
|
|
110
|
+
const rows = db.prepare(`SELECT * FROM memories WHERE scope = 'global' AND state = 'active' AND type = 'procedure' ORDER BY hits DESC, id DESC LIMIT 10`).all();
|
|
111
|
+
if (rows.length === 0) return [];
|
|
112
|
+
// Named, not quoted in full: sumo show has the rest, and the block has a ceiling to keep.
|
|
113
|
+
return [`Workflows — before doing what one covers, run sumo show <id> and follow it: ${rows.map((m) => `m${m.id} "${clip(m.title, NAME_MAX)}"${m.cue ? ` — when: ${clip(m.cue, NAME_MAX)}` : ''}`).join(' · ')}`];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function projectsLine(db) {
|
|
117
|
+
const all = listProjects(db).filter((p) => !isScratch(p));
|
|
118
|
+
if (all.length === 0) return [];
|
|
119
|
+
const shown = all.slice(0, MAX_PROJECTS).map((p) => `${p.slug} (${tilde(p.path)})`);
|
|
120
|
+
const more = all.length > MAX_PROJECTS ? ` · +${all.length - MAX_PROJECTS} more: sumo project list` : '';
|
|
121
|
+
return [`Projects: ${shown.join(' · ')}${more}`];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function scratchLine(db) {
|
|
125
|
+
return [`Scratch: ${tilde(paths().scratch)} — work that belongs to no project goes here, a folder per chore; one idle ${scratchDays(db)} days is deleted`];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function leftOff(db, now) {
|
|
129
|
+
const rows = db
|
|
130
|
+
.prepare(
|
|
131
|
+
`SELECT c.* FROM checkpoints c
|
|
132
|
+
JOIN (SELECT project, MAX(id) AS id FROM checkpoints GROUP BY project) latest ON latest.id = c.id
|
|
133
|
+
JOIN projects p ON p.slug = c.project AND p.status = 'active'
|
|
134
|
+
ORDER BY c.ts DESC LIMIT ?`,
|
|
135
|
+
)
|
|
136
|
+
.all(MAX_LEFT_OFF);
|
|
137
|
+
return rows.map((c) => clip(`Left off: ${c.project} — ${c.done}${c.next_step ? ` → next: ${c.next_step}` : ''} (${ago(c.ts, now)})`, LINE_MAX * 2));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function jobs(db, now) {
|
|
141
|
+
const rows = db.prepare(`SELECT * FROM jobs WHERE status IN ('running', 'needs_input') ORDER BY updated_at DESC LIMIT 5`).all();
|
|
142
|
+
return rows.map((j) => `Job j${j.id} ${j.project} "${clip(j.title, 60)}" ${j.status.toUpperCase()} (${ago(j.updated_at, now)}) → sumo job show ${j.id}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function toConfirm(db) {
|
|
146
|
+
const guesses = db.prepare(`SELECT * FROM memories WHERE state = 'unconfirmed' ORDER BY id LIMIT ?`).all(MAX_CONFIRM);
|
|
147
|
+
const out = guesses.map(
|
|
148
|
+
(m) => `Ask the user (then sumo confirm|reject m${m.id}): is this right? "${clip(m.type === 'procedure' ? `workflow "${m.title}"` : m.body, LINE_MAX)}"`,
|
|
149
|
+
);
|
|
150
|
+
// A notice stands only while both memories are still true; superseding or forgetting either settles it.
|
|
151
|
+
const notices = db
|
|
152
|
+
.prepare(
|
|
153
|
+
`SELECT n.* FROM notices n
|
|
154
|
+
JOIN memories a ON a.id = n.memory_a AND a.state = 'active'
|
|
155
|
+
JOIN memories b ON b.id = n.memory_b AND b.state = 'active'
|
|
156
|
+
ORDER BY n.id LIMIT ?`,
|
|
157
|
+
)
|
|
158
|
+
.all(MAX_NOTICES);
|
|
159
|
+
for (const n of notices) {
|
|
160
|
+
const verb = n.kind === 'lookalike' ? 'look alike' : 'disagree';
|
|
161
|
+
out.push(`Ask the user: m${n.memory_a} and m${n.memory_b} ${verb} — ${clip(n.note, LINE_MAX)} (sumo show both; settle with sumo supersede or sumo forget)`);
|
|
162
|
+
}
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function warnings(db) {
|
|
167
|
+
const out = [];
|
|
168
|
+
// AGENTS.md says a background writer files what the user says; with it off, nothing does unless the model is told.
|
|
169
|
+
if ((getMeta(db, 'config.scribe.model') ?? CONFIG_DEFAULTS['scribe.model']) === 'off') {
|
|
170
|
+
out.push('The memory writer is off (scribe.model): save what the user states that should last, as it is said, with sumo add.');
|
|
171
|
+
}
|
|
172
|
+
const failures = Number(getMeta(db, 'scribe.failures') ?? 0);
|
|
173
|
+
if (failures >= SCRIBE_FAILURES_TO_WARN) out.push(`Warning: the background memory writer has failed ${failures} times in a row — nothing new is being remembered. Tell the user; sumo scribe status shows why.`);
|
|
174
|
+
const backup = getMeta(db, 'backup.failed');
|
|
175
|
+
if (backup) out.push(`Warning: the weekly backup could not be written (${backup}). Tell the user; sumo backup tries again.`);
|
|
176
|
+
return out;
|
|
177
|
+
}
|