sumo-agents 0.3.0 → 0.5.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 +8 -6
- package/CHANGELOG.md +155 -0
- package/README.md +82 -19
- 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 +289 -89
- 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 +113 -11
- package/src/export.mjs +105 -7
- package/src/guard.mjs +57 -11
- package/src/guides.mjs +5 -4
- package/src/herdr.mjs +9 -4
- package/src/hooks.mjs +35 -19
- 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 +94 -12
- package/src/redact.mjs +10 -0
- package/src/render.mjs +2 -1
- package/src/route.mjs +39 -25
- package/src/sandbox.mjs +82 -3
- package/src/scan.mjs +35 -1
- package/src/scribe.mjs +10 -22
- package/src/sessions.mjs +49 -13
- package/src/setup.mjs +425 -76
- package/src/text.mjs +100 -1
- package/src/tools.mjs +258 -21
- package/src/tty.mjs +481 -105
- package/src/ui.mjs +1205 -276
- package/src/verify.mjs +17 -1
package/src/cost.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { MODEL_IDS, MODELS } from './catalog.mjs';
|
|
3
|
+
import { CACHE_WRITE, priceOf } from './model.mjs';
|
|
3
4
|
import { getProject } from './projects.mjs';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -19,11 +20,56 @@ const CACHE_LIVES_MS = 5 * 60_000;
|
|
|
19
20
|
|
|
20
21
|
const PARTS = ['uncached', 'read', 'write', 'output'];
|
|
21
22
|
|
|
23
|
+
/** Why a request wrote its context again, in the order they are told apart; what each one means, for `sumo cost`. */
|
|
24
|
+
const CAUSES = {
|
|
25
|
+
model: 'the model changed, and a cache is never shared between models',
|
|
26
|
+
cleared: 'the context was compacted or cleared',
|
|
27
|
+
prefix: 'the system prompt or the tools changed',
|
|
28
|
+
gap: `over ${CACHE_LIVES_MS / 60_000} minutes since the request before, which a 1-hour cache would have kept`,
|
|
29
|
+
unknown: 'nothing seen here explains it',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** Whether a request found next to nothing of its context in the cache and wrote most of it again. */
|
|
33
|
+
const wroteAgain = (read, written, input) => read < REWRITE_READ_UNDER && written > input * REWRITE_SHARE;
|
|
34
|
+
|
|
35
|
+
/** What the cache is keyed on before the messages: the system prompt and the tools, as one digest. */
|
|
36
|
+
export const prefixOf = (params) => createHash('sha256').update(JSON.stringify([params.system ?? null, params.tools ?? null])).digest('hex').slice(0, 16);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Why a request wrote its context again, told at the time from what the ledger's rows cannot show: the digest of the
|
|
40
|
+
* prefix, kept in memory on the conversation's ledger. `last` is the request before in the same conversation, or null
|
|
41
|
+
* for its first — which writes its context, as expected. Null when the request found its context in the cache.
|
|
42
|
+
*/
|
|
43
|
+
export function rewriteCause(last, now) {
|
|
44
|
+
if (!last || last.key !== now.key || !wroteAgain(now.read, now.written, now.input)) return null;
|
|
45
|
+
if (now.model !== last.model) return 'model';
|
|
46
|
+
if (now.cleared) return 'cleared';
|
|
47
|
+
if (now.prefix !== last.prefix) return 'prefix';
|
|
48
|
+
if (now.at - last.at > CACHE_LIVES_MS) return 'gap';
|
|
49
|
+
return 'unknown';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* After a response is in the ledger: its cause, if it wrote its context again, written to its row — the row logRun just
|
|
54
|
+
* inserted, on this connection. `ledger` is the conversation's (a job's, or the chat's, whose session may change): the
|
|
55
|
+
* request before is kept on it, and so is a clear made between requests (`ledger.cleared`, set where the context is
|
|
56
|
+
* compacted). The advisor's rows and failed ones pass through neither.
|
|
57
|
+
*/
|
|
58
|
+
export function noteRewrite(db, ledger, { at, model, prefix, usage, cleared = false }) {
|
|
59
|
+
const key = ledger.jobId !== null && ledger.jobId !== undefined ? `j${ledger.jobId}` : ledger.sessionId ? `s${ledger.sessionId}` : null;
|
|
60
|
+
const now = { key, at, model, prefix, cleared: cleared || Boolean(ledger.cleared), read: usage.cacheReadTokens ?? 0, written: usage.cacheCreationTokens ?? 0, input: usage.inputTokens ?? 0 };
|
|
61
|
+
const cause = key === null ? null : rewriteCause(ledger.last ?? null, now);
|
|
62
|
+
ledger.cleared = false;
|
|
63
|
+
if (key !== null) ledger.last = { key, at, model, prefix };
|
|
64
|
+
if (cause) db.prepare('UPDATE model_runs SET cache_cause = ? WHERE id = last_insert_rowid()').run(cause);
|
|
65
|
+
return cause;
|
|
66
|
+
}
|
|
67
|
+
|
|
22
68
|
/** What one request paid for each part, from its tokens and the price list; a model the list does not know splits into nothing. */
|
|
23
69
|
function partsOf(row) {
|
|
24
|
-
|
|
70
|
+
// The ledger keeps the whole input, which is the prompt a rate card is chosen by; what was read fresh is what the cache neither gave nor took.
|
|
71
|
+
const price = priceOf(row.model, { input_tokens: row.input_tokens ?? 0 });
|
|
25
72
|
if (!price) return { uncached: 0, read: 0, write: 0, output: 0 };
|
|
26
|
-
// The ledger keeps the whole input; what was read fresh is what the cache neither gave nor took.
|
|
27
73
|
const read = row.cache_read_tokens ?? 0;
|
|
28
74
|
const written = row.cache_creation_tokens ?? 0;
|
|
29
75
|
const plain = Math.max(0, (row.input_tokens ?? 0) - read - written);
|
|
@@ -55,6 +101,8 @@ export function breakdown(rows) {
|
|
|
55
101
|
const total = empty();
|
|
56
102
|
const groups = new Map();
|
|
57
103
|
const rewrites = { requests: 0, usd: 0 };
|
|
104
|
+
/** The rewrites told apart at the time, by cause: each one's requests and what writing again cost. */
|
|
105
|
+
const causes = new Map();
|
|
58
106
|
const last = new Map();
|
|
59
107
|
const ordered = [...rows].sort((a, b) => (a.ts < b.ts ? -1 : a.ts > b.ts ? 1 : 0));
|
|
60
108
|
for (const row of ordered) {
|
|
@@ -63,6 +111,11 @@ export function breakdown(rows) {
|
|
|
63
111
|
const key = `${row.kind}\n${row.model}`;
|
|
64
112
|
if (!groups.has(key)) groups.set(key, { kind: row.kind, model: row.model, ...empty() });
|
|
65
113
|
add(groups.get(key), row, parts);
|
|
114
|
+
if (row.cache_cause) {
|
|
115
|
+
if (!causes.has(row.cache_cause)) causes.set(row.cache_cause, { requests: 0, usd: 0 });
|
|
116
|
+
causes.get(row.cache_cause).requests++;
|
|
117
|
+
causes.get(row.cache_cause).usd += parts.write;
|
|
118
|
+
}
|
|
66
119
|
|
|
67
120
|
const conversation = row.job_id !== null && row.job_id !== undefined ? `j${row.job_id}` : row.session_id ? `s${row.session_id}` : null;
|
|
68
121
|
if (conversation === null || !(row.input_tokens > 0)) continue;
|
|
@@ -77,7 +130,7 @@ export function breakdown(rows) {
|
|
|
77
130
|
rewrites.usd += parts.write;
|
|
78
131
|
}
|
|
79
132
|
}
|
|
80
|
-
return { total, groups: [...groups.values()].sort((a, b) => b.usd - a.usd), rewrites };
|
|
133
|
+
return { total, groups: [...groups.values()].sort((a, b) => b.usd - a.usd), rewrites, causes: Object.fromEntries(Object.keys(CAUSES).filter((c) => causes.has(c)).map((c) => [c, causes.get(c)])) };
|
|
81
134
|
}
|
|
82
135
|
|
|
83
136
|
const dollars = (usd) => `$${usd.toFixed(2)}`;
|
|
@@ -85,6 +138,9 @@ const count = (n, word) => `${n.toLocaleString('en-US')} ${word}${n === 1 ? '' :
|
|
|
85
138
|
const percent = (part, whole) => (whole > 0 ? ` (${Math.round((part / whole) * 100)}%)` : '');
|
|
86
139
|
/** A model by the name Sumo calls it; a local model or one the list does not know, as the ledger has it. */
|
|
87
140
|
const nameOf = (model) => MODELS.find((name) => MODEL_IDS[name] === model) ?? model;
|
|
141
|
+
/** Who made a request, in the words the user knows: the ledger keeps its own short kinds. */
|
|
142
|
+
const KIND_NAMES = { scribe: 'memory pass, filing', dream: 'memory pass, tidying', local: 'router' };
|
|
143
|
+
const kindOf = (kind) => KIND_NAMES[kind] ?? kind;
|
|
88
144
|
|
|
89
145
|
/** The four parts of a sum, and a search when one was paid for; with `of`, each part's share of it. */
|
|
90
146
|
function split(sum, of = null) {
|
|
@@ -104,7 +160,7 @@ export function costLines(db, { days, project } = {}) {
|
|
|
104
160
|
const since = days === undefined ? null : new Date(Date.now() - days * 86_400_000).toISOString();
|
|
105
161
|
const rows = db
|
|
106
162
|
.prepare(
|
|
107
|
-
`SELECT ts, kind, model, input_tokens, output_tokens, cost_usd, cache_read_tokens, cache_creation_tokens, job_id, session_id
|
|
163
|
+
`SELECT ts, kind, model, input_tokens, output_tokens, cost_usd, cache_read_tokens, cache_creation_tokens, job_id, session_id, cache_cause
|
|
108
164
|
FROM model_runs
|
|
109
165
|
WHERE (? IS NULL OR ts >= ?)
|
|
110
166
|
AND (? IS NULL
|
|
@@ -116,13 +172,16 @@ export function costLines(db, { days, project } = {}) {
|
|
|
116
172
|
const window = days === undefined ? null : `the last ${count(days, 'day')}`;
|
|
117
173
|
if (rows.length === 0) return [`nothing was spent ${window ? `in ${window}` : 'yet'}${slug ? ` on ${slug}` : ''}`];
|
|
118
174
|
|
|
119
|
-
const { total, groups, rewrites } = breakdown(rows);
|
|
175
|
+
const { total, groups, rewrites, causes } = breakdown(rows);
|
|
176
|
+
const told = Object.entries(causes);
|
|
120
177
|
const share = total.usd > 0 ? `, ${Math.round((rewrites.usd / total.usd) * 100)}% of the total` : '';
|
|
121
178
|
const scope = `${window ?? `since ${rows[0].ts.slice(0, 10)}`}${slug ? ` · ${slug}` : ''}`;
|
|
122
179
|
return [
|
|
123
180
|
`${scope}: ${count(total.requests, 'request')}, ${dollars(total.usd)} — ${split(total, total.usd)}`,
|
|
124
181
|
// A group that cost nothing — the local model's — has nothing to split.
|
|
125
|
-
...groups.map((g) => ` ${g.kind} · ${nameOf(g.model)}: ${count(g.requests, 'request')}, ${dollars(g.usd)}${g.usd >= 0.005 ? ` — ${split(g)}` : ''}`),
|
|
182
|
+
...groups.map((g) => ` ${kindOf(g.kind)} · ${nameOf(g.model)}: ${count(g.requests, 'request')}, ${dollars(g.usd)}${g.usd >= 0.005 ? ` — ${split(g)}` : ''}`),
|
|
126
183
|
`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
|
+
// Told apart at the time, whatever the gap: the ones a longer cache would have kept are the gap ones.
|
|
185
|
+
...(told.length > 0 ? [` why: ${told.map(([cause, sum]) => `${cause} ${count(sum.requests, 'request')}, ${dollars(sum.usd)}`).join(' · ')}`, ...told.map(([cause]) => ` ${cause}: ${CAUSES[cause]}`)] : []),
|
|
127
186
|
];
|
|
128
187
|
}
|
package/src/db.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { chmodSync, closeSync, existsSync, mkdirSync, openSync, statSync } from 'node:fs';
|
|
2
|
-
import { dirname } from 'node:path';
|
|
3
|
-
import { paths } from './paths.mjs';
|
|
1
|
+
import { chmodSync, closeSync, existsSync, mkdirSync, openSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
2
|
+
import { basename, dirname, join } from 'node:path';
|
|
3
|
+
import { homeProblem, paths } from './paths.mjs';
|
|
4
4
|
import { DatabaseSync } from './sqlite.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -269,6 +269,51 @@ const MIGRATIONS = [
|
|
|
269
269
|
// 9 — whether the router called a job's work risky (security, credentials, money, migrations, concurrency): 1 or 0, so such
|
|
270
270
|
// work is reviewed once it is done. Nullable: a job routed before this migration was never asked.
|
|
271
271
|
(db) => addColumnsIfMissing(db, 'jobs', ['risky INTEGER']),
|
|
272
|
+
// 10 — why a request wrote its context to the cache again when the cache should have held it: gap, prefix, cleared, model
|
|
273
|
+
// or unknown (cost.mjs). Nullable: a request that found its context, a conversation's first, or a row from before this.
|
|
274
|
+
(db) => addColumnsIfMissing(db, 'model_runs', ['cache_cause TEXT']),
|
|
275
|
+
// 11 — two memories the tidy pass has had judged (dream.mjs): same, replaces, conflict or unrelated, so a pair is put to
|
|
276
|
+
// the model once. Either memory going takes the pair with it.
|
|
277
|
+
`
|
|
278
|
+
CREATE TABLE IF NOT EXISTS memory_pairs (
|
|
279
|
+
a INTEGER NOT NULL REFERENCES memories(id) ON DELETE CASCADE,
|
|
280
|
+
b INTEGER NOT NULL REFERENCES memories(id) ON DELETE CASCADE,
|
|
281
|
+
label TEXT NOT NULL,
|
|
282
|
+
judged_at TEXT NOT NULL,
|
|
283
|
+
PRIMARY KEY (a, b)
|
|
284
|
+
) STRICT;
|
|
285
|
+
`,
|
|
286
|
+
// 12 — the writer and the tidier are one memory pass with one setting, memory.model. The writer's choice is kept: it is
|
|
287
|
+
// the one that runs after every turn (the user who turned it off still has it off). The tidier's alone is not taken —
|
|
288
|
+
// it would move every turn's filing onto the model chosen for a weekly tidy, a paid one perhaps. The old keys go.
|
|
289
|
+
`
|
|
290
|
+
INSERT OR IGNORE INTO meta (key, value) SELECT 'config.memory.model', value FROM meta WHERE key = 'config.scribe.model';
|
|
291
|
+
DELETE FROM meta WHERE key IN ('config.scribe.model', 'config.dream.model');
|
|
292
|
+
`,
|
|
293
|
+
// 13 — what a conversation read past the machine (a web search or fetch, an MCP server), one tool name a line, each
|
|
294
|
+
// once: what the memory pass files from its replies is held for the user (sessions.mjs, apply.mjs). On the session's
|
|
295
|
+
// own row, not in meta: the pass runs in a process of its own and reads it with the session's turns. Nullable: a
|
|
296
|
+
// conversation that read nothing, or one from before this.
|
|
297
|
+
(db) => addColumnsIfMissing(db, 'sessions', ['outside_read TEXT']),
|
|
298
|
+
// 14 — why a memory is held for the user beyond being a guess: 'outside' when what it says came from a conversation that
|
|
299
|
+
// read the web or an MCP server. Only the user confirms such a one: the model that read the page may not vouch for it.
|
|
300
|
+
(db) => addColumnsIfMissing(db, 'memories', ['held_for TEXT']),
|
|
301
|
+
// 15 — fewer settings. chat.plain and chat.motion are one, chat.screen: plain wins, then a motion turned off is still.
|
|
302
|
+
// model.source, model.repo and model.file are one, model.url, the address they made (the defaults of the time fill in a
|
|
303
|
+
// part not set) — the same file is fetched. prime.budget, scratch.days, jobs.escalate and guides.auto are fixed now.
|
|
304
|
+
`
|
|
305
|
+
INSERT OR IGNORE INTO meta (key, value)
|
|
306
|
+
SELECT 'config.chat.screen', CASE WHEN EXISTS (SELECT 1 FROM meta WHERE key = 'config.chat.plain' AND value = 'on') THEN 'plain' ELSE 'still' END
|
|
307
|
+
WHERE EXISTS (SELECT 1 FROM meta WHERE (key = 'config.chat.plain' AND value = 'on') OR (key = 'config.chat.motion' AND value = 'off'));
|
|
308
|
+
INSERT OR IGNORE INTO meta (key, value)
|
|
309
|
+
SELECT 'config.model.url',
|
|
310
|
+
COALESCE((SELECT value FROM meta WHERE key = 'config.model.source'), 'https://huggingface.co') || '/' ||
|
|
311
|
+
COALESCE((SELECT value FROM meta WHERE key = 'config.model.repo'), 'Qwen/Qwen3-4B-GGUF') || '/resolve/main/' ||
|
|
312
|
+
COALESCE((SELECT value FROM meta WHERE key = 'config.model.file'), 'Qwen3-4B-Q4_K_M.gguf')
|
|
313
|
+
WHERE EXISTS (SELECT 1 FROM meta WHERE key IN ('config.model.source', 'config.model.repo', 'config.model.file'));
|
|
314
|
+
DELETE FROM meta WHERE key IN ('config.chat.plain', 'config.chat.motion', 'config.model.source', 'config.model.repo', 'config.model.file',
|
|
315
|
+
'config.prime.budget', 'config.scratch.days', 'config.jobs.escalate', 'config.guides.auto');
|
|
316
|
+
`,
|
|
272
317
|
];
|
|
273
318
|
|
|
274
319
|
/**
|
|
@@ -295,6 +340,17 @@ const BUSY_MS = 3000;
|
|
|
295
340
|
* secure_delete zeroes what is deleted, so an erased memory does not linger in the file's free space.
|
|
296
341
|
*/
|
|
297
342
|
export function openDb(file = paths().db) {
|
|
343
|
+
try {
|
|
344
|
+
return opened(file);
|
|
345
|
+
} catch (cause) {
|
|
346
|
+
// A home that is a file, or one sumo may not write, is said as that, with what to do — not as Node's or SQLite's words.
|
|
347
|
+
const said = homeProblem(cause, dirname(file));
|
|
348
|
+
if (said === null) throw cause;
|
|
349
|
+
throw new Error(said, { cause });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function opened(file) {
|
|
298
354
|
mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
|
|
299
355
|
// SQLite gives the -wal and -shm files the database's own mode: the file is made private before SQLite first opens
|
|
300
356
|
// it, or they are born readable by everyone (umask 022) and keep the latest writes there.
|
|
@@ -309,10 +365,57 @@ export function openDb(file = paths().db) {
|
|
|
309
365
|
const db = new DatabaseSync(file);
|
|
310
366
|
db.exec(`PRAGMA busy_timeout = ${BUSY_MS}; PRAGMA foreign_keys = ON; PRAGMA secure_delete = ON;`);
|
|
311
367
|
useWal(db);
|
|
368
|
+
const found = schemaVersion(db);
|
|
369
|
+
// A newer sumo's tables are not this one's to write: its migrations would be taken for undone, or its rows misread.
|
|
370
|
+
if (found > MIGRATIONS.length) {
|
|
371
|
+
db.close();
|
|
372
|
+
throw new Error(`the database is from a newer sumo (schema ${found}; this one knows ${MIGRATIONS.length}) — upgrade: npm update -g sumo-agents`);
|
|
373
|
+
}
|
|
374
|
+
if (found > 0 && found < MIGRATIONS.length) copyAside(db, file, found);
|
|
312
375
|
migrate(db);
|
|
313
376
|
return db;
|
|
314
377
|
}
|
|
315
378
|
|
|
379
|
+
/** How many copies made before a migration are kept: the newest. */
|
|
380
|
+
const PRE_MIGRATION_KEPT = 3;
|
|
381
|
+
/** How long an empty copy may be another process's copy still being made, before it is taken for one that died half-way. */
|
|
382
|
+
const HALF_MADE_MS = 60_000;
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* The database as it is, copied beside it before it is migrated — `<db>.pre-v<N>.bak`, N the version it was at — so an
|
|
386
|
+
* upgrade that goes wrong can be undone by hand. VACUUM INTO writes a consistent copy while others read; it writes into
|
|
387
|
+
* a file made empty and private first, so the copy is never readable by others for a moment. A copy already there was
|
|
388
|
+
* made by a process that got here first. One that cannot be made is let go: the migrations only add.
|
|
389
|
+
*/
|
|
390
|
+
function copyAside(db, file, version) {
|
|
391
|
+
const copy = `${file}.pre-v${version}.bak`;
|
|
392
|
+
// An empty copy left a while ago is one a process died making: it is made again. A fresh empty one is another
|
|
393
|
+
// process's at work.
|
|
394
|
+
try {
|
|
395
|
+
const left = statSync(copy);
|
|
396
|
+
if (left.size === 0 && Date.now() - left.mtimeMs > HALF_MADE_MS) rmSync(copy, { force: true });
|
|
397
|
+
} catch {
|
|
398
|
+
// Not there: the usual case.
|
|
399
|
+
}
|
|
400
|
+
try {
|
|
401
|
+
closeSync(openSync(copy, 'wx', 0o600));
|
|
402
|
+
} catch {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
db.exec(`VACUUM INTO '${copy.replaceAll("'", "''")}'`);
|
|
407
|
+
} catch {
|
|
408
|
+
rmSync(copy, { force: true });
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const mine = `${basename(file)}.pre-v`;
|
|
412
|
+
const copies = readdirSync(dirname(file))
|
|
413
|
+
.filter((name) => name.startsWith(mine) && name.endsWith('.bak'))
|
|
414
|
+
.map((name) => join(dirname(file), name))
|
|
415
|
+
.sort((a, b) => statSync(b).mtimeMs - statSync(a).mtimeMs);
|
|
416
|
+
for (const old of copies.slice(PRE_MIGRATION_KEPT)) rmSync(old, { force: true });
|
|
417
|
+
}
|
|
418
|
+
|
|
316
419
|
/**
|
|
317
420
|
* The switch to WAL needs the file to itself, and SQLite does not wait for that the way it waits for a lock:
|
|
318
421
|
* of two processes opening a new database at the same moment, one is told "locked" at once. It asks again.
|