sumo-agents 0.5.0 → 0.7.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 +86 -0
- package/README.md +50 -37
- package/guides/memory.md +21 -14
- package/package.json +2 -2
- package/prompts/dream.md +3 -16
- package/prompts/scribe.md +20 -15
- package/src/apply.mjs +364 -230
- package/src/card.mjs +16 -11
- package/src/catalog.mjs +3 -3
- package/src/chat.mjs +44 -23
- package/src/check.mjs +371 -0
- package/src/cli.mjs +218 -144
- package/src/db.mjs +147 -2
- package/src/dream.mjs +97 -189
- package/src/export.mjs +43 -18
- package/src/herdr.mjs +1 -3
- package/src/hooks.mjs +115 -22
- package/src/jobs.mjs +4 -2
- package/src/keeper.mjs +14 -51
- package/src/ledger.mjs +126 -0
- package/src/logs.mjs +10 -5
- package/src/loop.mjs +4 -4
- package/src/mcp.mjs +129 -51
- package/src/memeval.mjs +167 -0
- package/src/memory.mjs +261 -130
- package/src/page.mjs +3 -3
- package/src/paths.mjs +1 -0
- package/src/prime.mjs +82 -13
- package/src/rebuild.mjs +162 -0
- package/src/render.mjs +22 -0
- package/src/route.mjs +1 -1
- package/src/sandbox.mjs +5 -2
- package/src/scan.mjs +16 -4
- package/src/scribe.mjs +361 -113
- package/src/search.mjs +48 -0
- package/src/sessions.mjs +304 -53
- package/src/settings.mjs +868 -0
- package/src/setup.mjs +57 -65
- package/src/spool.mjs +308 -0
- package/src/text.mjs +118 -6
- package/src/tools.mjs +18 -7
- package/src/transcript.mjs +3 -47
- package/src/tty.mjs +102 -63
- package/src/ui.mjs +313 -271
- package/src/verify.mjs +23 -27
package/src/verify.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
-
import { closeSync, existsSync, fstatSync, openSync, readFileSync, readSync, renameSync,
|
|
3
|
+
import { closeSync, existsSync, fstatSync, ftruncateSync, openSync, readFileSync, readSync, renameSync, writeFileSync, writeSync } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { isSecretPath } from './guard.mjs';
|
|
6
6
|
import { UsageError } from './memory.mjs';
|
|
7
7
|
import { secretShape } from './redact.mjs';
|
|
8
|
-
import { verifyCommands } from './scan.mjs';
|
|
8
|
+
import { readPlainFile, verifyCommands } from './scan.mjs';
|
|
9
9
|
import { killGroup } from './tools.mjs';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -129,19 +129,14 @@ function timeoutMs() {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
/** The last lines of a check's log, read from its end rather than whole. */
|
|
132
|
-
function tailOf(
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (start > 0 && lines.length > 1) lines.shift();
|
|
141
|
-
return lines.slice(-OUTPUT_TAIL_LINES).join('\n');
|
|
142
|
-
} finally {
|
|
143
|
-
closeSync(fd);
|
|
144
|
-
}
|
|
132
|
+
function tailOf(fd) {
|
|
133
|
+
const size = fstatSync(fd).size;
|
|
134
|
+
const start = Math.max(0, size - OUTPUT_TAIL_BYTES);
|
|
135
|
+
const bytes = Buffer.alloc(size - start);
|
|
136
|
+
const lines = bytes.subarray(0, readSync(fd, bytes, 0, bytes.length, start)).toString('utf8').trimEnd().split('\n');
|
|
137
|
+
// Read from inside a line, the first piece is half of one.
|
|
138
|
+
if (start > 0 && lines.length > 1) lines.shift();
|
|
139
|
+
return lines.slice(-OUTPUT_TAIL_LINES).join('\n');
|
|
145
140
|
}
|
|
146
141
|
|
|
147
142
|
/** The sandbox a job's process hands down for its checks: the wrap's words, or null — none given, or one that is not a list of words. */
|
|
@@ -167,25 +162,26 @@ function runChecks(root, commands, dir, prefix) {
|
|
|
167
162
|
named.set(name, nth);
|
|
168
163
|
const file = join(dir, `${prefix}-${name}${nth > 1 ? `-${nth}` : ''}.txt`);
|
|
169
164
|
// Printed into the file, not a pipe: a pipe stays open while anything the check left running holds it, and would be waited on to the time limit.
|
|
170
|
-
|
|
171
|
-
|
|
165
|
+
// Its end is read and written back through the same descriptor, so the file kept is the file the check printed into.
|
|
166
|
+
const into = openSync(file, 'w+', 0o600);
|
|
172
167
|
try {
|
|
173
168
|
// A job's checks run the project's code, perhaps tests the model wrote: in the sandbox its shell is in, handed down by the
|
|
174
169
|
// job's own process (SUMO_CHECKS_WRAP), while this process — which records the verdict in sumo's memory — stays outside it.
|
|
175
170
|
const wrap = checksWrapOf(process.env);
|
|
176
171
|
const script = `${watcher}${command}`;
|
|
177
|
-
run = wrap
|
|
172
|
+
const run = wrap
|
|
178
173
|
? spawnSync(wrap[0], [...wrap.slice(1), '/bin/sh', '-c', script], { cwd: root, detached: true, stdio: ['ignore', into, into], timeout: timeoutMs(), killSignal: 'SIGKILL' })
|
|
179
174
|
: spawnSync(script, { cwd: root, shell: true, detached: true, stdio: ['ignore', into, into], timeout: timeoutMs(), killSignal: 'SIGKILL' });
|
|
175
|
+
const timedOut = run.error?.code === 'ETIMEDOUT';
|
|
176
|
+
// Whatever it left running goes with it, so nothing writes to the file once it is read.
|
|
177
|
+
killGroup(run.pid);
|
|
178
|
+
const output = tailOf(into);
|
|
179
|
+
ftruncateSync(into);
|
|
180
|
+
writeSync(into, `$ ${command}\n${output}\n${timedOut ? '\n(stopped: it ran past the time limit)\n' : ''}`, 0);
|
|
181
|
+
return { name, command, ok: run.status === 0, status: run.status, timedOut, ms: Date.now() - started, file };
|
|
180
182
|
} finally {
|
|
181
183
|
closeSync(into);
|
|
182
184
|
}
|
|
183
|
-
const timedOut = run.error?.code === 'ETIMEDOUT';
|
|
184
|
-
// Whatever it left running goes with it, so nothing writes to the file once it is read.
|
|
185
|
-
killGroup(run.pid);
|
|
186
|
-
const output = tailOf(file);
|
|
187
|
-
writeFileSync(file, `$ ${command}\n${output}\n${timedOut ? '\n(stopped: it ran past the time limit)\n' : ''}`, { mode: 0o600 });
|
|
188
|
-
return { name, command, ok: run.status === 0, status: run.status, timedOut, ms: Date.now() - started, file };
|
|
189
185
|
});
|
|
190
186
|
}
|
|
191
187
|
|
|
@@ -253,9 +249,9 @@ function scanAdded(root, snap, changes) {
|
|
|
253
249
|
// A new file is read whole, and so is one that git never tracked: there is no diff to take its added lines from.
|
|
254
250
|
for (const created of [...changes.created, ...changes.tracked.filter((c) => c.untracked && c.status === 'M').map((c) => c.path)]) {
|
|
255
251
|
try {
|
|
256
|
-
const
|
|
257
|
-
if (
|
|
258
|
-
|
|
252
|
+
const text = readPlainFile(join(root, created), MAX_SCANNED_FILE_BYTES);
|
|
253
|
+
if (text === null) continue;
|
|
254
|
+
text.split('\n').forEach((l, i) => look(`${created}:${i + 1}`, l));
|
|
259
255
|
} catch {
|
|
260
256
|
// unreadable or binary: nothing to say about it
|
|
261
257
|
}
|