@dibssoftware/dibs 0.0.180 → 0.0.195
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 +111 -1
- package/README.md +10 -8
- package/bin/dibs.mjs +379 -74
- package/docs/agents.md +303 -0
- package/docs/council.md +88 -0
- package/docs/files.md +3 -3
- package/docs/guard.md +86 -11
- package/docs/json.md +211 -0
- package/docs/later.md +5 -5
- package/docs/machines.md +6 -6
- package/docs/questions.md +104 -3
- package/docs/reference.md +124 -30
- package/docs/relay.md +135 -11
- package/docs/releasing.md +7 -1
- package/docs/scheduling.md +28 -6
- package/docs/secrets.md +53 -0
- package/docs/simulators.md +3 -3
- package/docs/windows.md +3 -3
- package/package.json +1 -1
- package/skills/dibs/SKILL.md +79 -149
- package/src/about.mjs +341 -0
- package/src/acquire.mjs +113 -28
- package/src/after.mjs +127 -0
- package/src/agents.mjs +2 -1
- package/src/alerts.mjs +109 -48
- package/src/answers.mjs +2 -2
- package/src/board.mjs +21 -16
- package/src/broker.mjs +23 -7
- package/src/carry.mjs +287 -0
- package/src/codex.mjs +132 -0
- package/src/commands.mjs +254 -86
- package/src/config.mjs +85 -14
- package/src/connect.mjs +4 -2
- package/src/cool.mjs +28 -12
- package/src/council.mjs +482 -0
- package/src/cwd.mjs +9 -0
- package/src/decisions.mjs +250 -0
- package/src/declare.mjs +96 -0
- package/src/diskreport.mjs +306 -0
- package/src/diskuse.mjs +420 -0
- package/src/diskwarn.mjs +68 -13
- package/src/doctor.mjs +149 -0
- package/src/doors.mjs +547 -0
- package/src/durable.mjs +143 -0
- package/src/envs.mjs +372 -0
- package/src/events.mjs +7 -2
- package/src/files.mjs +121 -7
- package/src/guard.mjs +288 -105
- package/src/guardd.mjs +8 -1
- package/src/halt.mjs +63 -0
- package/src/handoffs.mjs +362 -0
- package/src/history.mjs +34 -4
- package/src/hogs.mjs +36 -8
- package/src/jobprogress.mjs +283 -0
- package/src/later.mjs +21 -10
- package/src/lock.mjs +51 -11
- package/src/measure.mjs +60 -14
- package/src/media.mjs +240 -0
- package/src/news.mjs +31 -0
- package/src/notes.mjs +49 -8
- package/src/notices.mjs +126 -43
- package/src/ondemand.mjs +25 -2
- package/src/outcome.mjs +163 -0
- package/src/overlap.mjs +2 -2
- package/src/override.mjs +149 -79
- package/src/owner.mjs +15 -2
- package/src/people.mjs +236 -0
- package/src/pickup.mjs +72 -0
- package/src/picture.mjs +321 -0
- package/src/plain.mjs +84 -18
- package/src/platform.mjs +29 -7
- package/src/preempt.mjs +123 -15
- package/src/primer.mjs +91 -20
- package/src/prints.mjs +99 -0
- package/src/proc.mjs +11 -1
- package/src/progress.mjs +49 -3
- package/src/proof.mjs +102 -0
- package/src/push.mjs +271 -0
- package/src/questions.mjs +328 -57
- package/src/quota.mjs +1 -1
- package/src/recap.mjs +205 -0
- package/src/relay.mjs +262 -26
- package/src/remote.mjs +23 -10
- package/src/reviewgate.mjs +268 -0
- package/src/reviews.mjs +377 -0
- package/src/route.mjs +263 -0
- package/src/rules.mjs +216 -0
- package/src/schedule.mjs +238 -44
- package/src/schema.mjs +62 -0
- package/src/scratch.mjs +2 -2
- package/src/serve.mjs +3 -2
- package/src/service.mjs +5 -1
- package/src/signed.mjs +97 -0
- package/src/simpool.mjs +46 -1
- package/src/spend.mjs +375 -0
- package/src/state.mjs +43 -17
- package/src/talk.mjs +1082 -134
- package/src/thin.sh +2 -0
- package/src/trail.mjs +290 -0
- package/src/trailnote.mjs +209 -0
- package/src/util.mjs +7 -0
- package/src/vault.mjs +435 -0
- package/src/vendors.mjs +327 -0
- package/src/version.mjs +1 -1
- package/src/web.mjs +354 -60
- package/src/work.mjs +487 -0
- package/src/worker.mjs +7 -1
package/src/acquire.mjs
CHANGED
|
@@ -2,27 +2,29 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { spawn } from 'node:child_process';
|
|
5
|
-
import {
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { resCfg, machine, paths, HOME, loadConfig, isEnv } from './config.mjs';
|
|
6
7
|
import { identity, pstart, tag } from './proc.mjs';
|
|
7
8
|
import { processes, parent, OS } from './platform.mjs';
|
|
8
9
|
import { withState, peek, history, setLockDeadline, KEEP_PLACE } from './state.mjs';
|
|
9
|
-
import { preempt } from './preempt.mjs';
|
|
10
|
+
import { preempt, yieldFor } from './preempt.mjs';
|
|
10
11
|
import { isFiles, short, shellRes, projectKey } from './files.mjs';
|
|
11
12
|
import { jobSize } from './simpool.mjs';
|
|
12
13
|
import { sized, grewLine, grewPlain, treeOf } from './measure.mjs';
|
|
13
14
|
import { isQuota, quotaProblem, quotaBlock, takeQuota } from './quota.mjs';
|
|
14
15
|
import { capWaiter, inversions, lift } from './override.mjs';
|
|
15
|
-
import { verdict, forecast, expected, remaining, byRank, holdingOf, PRIORITY_SHIFT, PRIORITIES, NEEDS_REASON, used, overBy, STALL, neverFits, explicitAsk, capToMachine, quickPass } from './schedule.mjs';
|
|
16
|
+
import { verdict, forecast, expected, remaining, byRank, holdingOf, PRIORITY_SHIFT, PRIORITIES, NEEDS_REASON, used, overBy, STALL, neverFits, explicitAsk, capToMachine, quickPass, freesOnly } from './schedule.mjs';
|
|
16
17
|
import { event } from './events.mjs';
|
|
17
18
|
import { startLine } from './overlap.mjs';
|
|
18
|
-
import { dur, clock, die, say, sleep, now, ms, gb, SIGNALS, signalExit, KEY_SPLIT, noSpace, OFF_LIMITS, callerPid, POLLED_EVERY, UNPOLLED, GHOST_AFTER } from './util.mjs';
|
|
19
|
+
import { dur, clock, die, say, sleep, now, ms, gb, SIGNALS, signalExit, KEY_SPLIT, noSpace, OFF_LIMITS, callerPid, codexThread, POLLED_EVERY, UNPOLLED, GHOST_AFTER } from './util.mjs';
|
|
19
20
|
import { plainBoard, startPhrase, askFirst, named, andList, lower, ordinal, moves, stuckFor, STUCK_AFTER } from './plain.mjs';
|
|
20
21
|
import { quoted, wrap, width } from './style.mjs';
|
|
21
22
|
import { noticeScan } from './notices.mjs';
|
|
22
23
|
import { notify } from './talk.mjs';
|
|
23
24
|
import { mayShip, loadShipTarget } from './remote.mjs';
|
|
25
|
+
import { described } from './declare.mjs';
|
|
24
26
|
|
|
25
|
-
const BIN = path.join(path.dirname(
|
|
27
|
+
const BIN = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'bin', 'dibs.mjs');
|
|
26
28
|
|
|
27
29
|
// How long dibs run waits in line outside Claude Code, where nothing moves a
|
|
28
30
|
// long call to the background and the tool may kill it.
|
|
@@ -72,6 +74,31 @@ export const backgroundable = (env = process.env) =>
|
|
|
72
74
|
export const defaultMaxWait = () =>
|
|
73
75
|
backgroundable() ? Infinity : process.env.DIBS_MAX_WAIT ? ms(process.env.DIBS_MAX_WAIT) : DEFAULT_MAX_WAIT;
|
|
74
76
|
|
|
77
|
+
// A timeout(1) around dibs counts the wait in line against the command: on 2026-11-28
|
|
78
|
+
// `timeout 3600 dibs run heavy ...` waited its hour behind three solver runs and was
|
|
79
|
+
// killed before it started. { limit } is its duration as --time-limit takes it (null
|
|
80
|
+
// when it can't be read), or null when the caller isn't a timeout.
|
|
81
|
+
const TIMEOUT = /^\S*\bg?timeout\s+(.*)$/;
|
|
82
|
+
const UNIT = { s: 1e3, m: 6e4, h: 3.6e6, d: 8.64e7 };
|
|
83
|
+
export function wrapper(pid) {
|
|
84
|
+
if (!pid || OS === 'windows') return null;
|
|
85
|
+
const m = processes().find(p => p.pid === pid)?.args.match(TIMEOUT);
|
|
86
|
+
if (!m) return null;
|
|
87
|
+
const words = m[1].split(/\s+/);
|
|
88
|
+
for (let i = 0; i < words.length; i++) {
|
|
89
|
+
if (/^(-s|-k|--signal|--kill-after)$/.test(words[i])) { i++; continue; }
|
|
90
|
+
if (words[i].startsWith('-')) continue;
|
|
91
|
+
const d = words[i].match(/^(\d+(?:\.\d+)?)([smhd]?)$/);
|
|
92
|
+
return { limit: d ? asFlag(parseFloat(d[1]) * UNIT[d[2] || 's']) : null };
|
|
93
|
+
}
|
|
94
|
+
return { limit: null };
|
|
95
|
+
}
|
|
96
|
+
// A duration the way --time-limit reads it: 1h, 90m, 45s.
|
|
97
|
+
const asFlag = t => (t % 3.6e6 === 0 ? `${t / 3.6e6}h` : t % 6e4 === 0 ? `${t / 6e4}m` : `${Math.ceil(t / 1e3)}s`);
|
|
98
|
+
const limitWord = x => `--time-limit ${x?.limit || '<how long it may run>'}`;
|
|
99
|
+
const wrapperLine = x => `You started dibs under timeout${x.limit ? ` (${x.limit})` : ''}, and its clock counts this wait in line too:`
|
|
100
|
+
+ ` it can end the job before it ever starts. Drop the timeout and add ${limitWord(x)} to dibs run instead, which counts from the start.`;
|
|
101
|
+
|
|
75
102
|
// Said once, when the wait starts, so nobody has to guess what happens at the end of it.
|
|
76
103
|
function waitTerms(w, disk) {
|
|
77
104
|
if (w.maxWait === Infinity)
|
|
@@ -120,7 +147,7 @@ export const idleFor = (l, t = now()) => (l.idleSince && t - l.idleSince > IDLE_
|
|
|
120
147
|
export function describeLease(l, hist, t = now()) {
|
|
121
148
|
const left = remaining(l, hist, t);
|
|
122
149
|
const idle = idleFor(l, t);
|
|
123
|
-
return `${tag(l)} for ${dur(t - l.start)}
|
|
150
|
+
return `${tag(l)} for ${dur(t - l.start)} ("${described(l)}")${l.cmd ? `: ${l.cmd.slice(0, 60)}` : ' (hold)'}`
|
|
124
151
|
+ `${left != null ? `, ~${dur(left)} left` : ''}${idle ? `, but its command has used no CPU for ${dur(idle)}` : ''}`
|
|
125
152
|
+ `${overBy(l) ? `, using ${gb(l.use.mem)} of the ${gb(l.mem)} it asked for` : ''}`;
|
|
126
153
|
}
|
|
@@ -243,17 +270,46 @@ const note = (w, what, extra) => event({ kind: what, id: w.me.id, res: w.me.res,
|
|
|
243
270
|
const left = (w, why) => { if (w.blocked) note(w, 'left', { ms: now() - w.me.enq, why }); };
|
|
244
271
|
|
|
245
272
|
// On a full disk the place stays on record under this pid, and the next
|
|
246
|
-
// state read drops it once this process is gone.
|
|
247
|
-
|
|
273
|
+
// state read drops it once this process is gone. sig: a signal ended the wait;
|
|
274
|
+
// returns what to say about it, worked out before the place changes.
|
|
275
|
+
function leave(w, keep, sig) {
|
|
276
|
+
let text = '';
|
|
248
277
|
try {
|
|
249
278
|
// A low job lifted for this waiter alone goes back down as it leaves (src/override.mjs inversions).
|
|
250
279
|
lift(withState(s => {
|
|
251
280
|
const q = s.queue.find(x => x.id === w.me.id);
|
|
281
|
+
if (sig && q) text = leftText(s, q, sig, { again: w.info.again, started: w.started, ppid: w.info.ppid }, w.hist);
|
|
252
282
|
if (keep && q) Object.assign(q, { pid: null, keepUntil: now() + KEEP_PLACE });
|
|
253
283
|
else s.queue = s.queue.filter(x => x.id !== w.me.id);
|
|
254
284
|
return inversions(s, w.cfg);
|
|
255
285
|
}));
|
|
256
286
|
} catch (e) { if (!noSpace(e)) throw e; }
|
|
287
|
+
return text;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// A signal ended a wait (a timeout, a tool's time limit, Ctrl-C). The waiter used to leave
|
|
291
|
+
// without a word: on 2026-11-28 an agent read its hour-long wait as a run that printed nothing. Says the command never ran, how long it waited, what was ahead, and
|
|
292
|
+
// how to get back in line; the place is kept KEEP_PLACE for that. info: { again, started, ppid }.
|
|
293
|
+
export function leftText(s, q, sig, info, hist) {
|
|
294
|
+
const t = now();
|
|
295
|
+
const shares = x => x.res.some(r => q.res.includes(r));
|
|
296
|
+
const line = s.queue.filter(x => (x.pid || x.id === q.id) && shares(x)).sort(byRank(hist, t));
|
|
297
|
+
const place = line.findIndex(x => x.id === q.id) + 1;
|
|
298
|
+
const job = x => `#${x.id} (${tag(x)}, "${described(x)}")`;
|
|
299
|
+
const few = xs => andList([...xs.slice(0, 3).map(job), ...(xs.length > 3 ? [`${xs.length - 3} more`] : [])]);
|
|
300
|
+
const ahead = line.slice(0, Math.max(0, place - 1)), using = s.leases.filter(shares);
|
|
301
|
+
const res = q.res.join(',');
|
|
302
|
+
const where = [place ? `It was ${place === 1 ? 'next' : ordinal(place)} in line for ${res}${ahead.length ? `, behind ${few(ahead)}` : ''}.` : '',
|
|
303
|
+
using.length ? `${few(using)} ${using.length > 1 ? 'were' : 'was'} using it.` : ''].filter(Boolean).join(' ');
|
|
304
|
+
// A person's Ctrl-C needs no advice; a timeout's or a tool's signal does.
|
|
305
|
+
const wrapped = sig === 'SIGINT' ? null : wrapper(info.ppid) || { generic: true };
|
|
306
|
+
const advice = !wrapped ? ''
|
|
307
|
+
: wrapped.generic ? `If a timeout or a tool's time limit sent it, that clock counted the wait. To limit only the run, add ${limitWord(null)} to dibs run (it counts from the start), and run it in the background if the wait may be long.`
|
|
308
|
+
: `It ran under timeout${wrapped.limit ? ` (${wrapped.limit})` : ''}, whose clock counted the wait. Drop the timeout and add ${limitWord(wrapped)} to dibs run: it counts from the start.`;
|
|
309
|
+
const waited = info.started ? dur(t - info.started) : dur(t - q.enq);
|
|
310
|
+
return saidText(`${sig} ended this wait (#${q.id}) after ${waited} in the queue. Your command never ran (exit ${signalExit(sig)}).`,
|
|
311
|
+
where, advice, info.again ? `Your place is kept until ${clock(t + KEEP_PLACE)}. To keep it, run the same command again before then:` : '')
|
|
312
|
+
+ (info.again ? ` ${info.again}\n` : '');
|
|
257
313
|
}
|
|
258
314
|
|
|
259
315
|
// A wait ended from outside it: leaves the line, closes it in the history, says why.
|
|
@@ -302,7 +358,8 @@ export { UNPOLLED }; // src/board.mjs reads it from here
|
|
|
302
358
|
function resize(cur, w) {
|
|
303
359
|
if (cur.sent) return;
|
|
304
360
|
const base = { mem: cur.asked ?? cur.mem, cpu: cur.cpu, disk: cur.disk };
|
|
305
|
-
const n = sized(base, w.hist, cur.key, w.cfg);
|
|
361
|
+
const n = sized(base, w.hist, cur.key, w.cfg, cur.repo);
|
|
362
|
+
if (n.learnedMem) cur.learnedMem = true;
|
|
306
363
|
if (n.mem === cur.mem && n.usual === cur.usual) return;
|
|
307
364
|
cur.mem = n.mem;
|
|
308
365
|
if (n.usual != null) cur.usual = n.usual; else delete cur.usual;
|
|
@@ -354,6 +411,9 @@ function judge(s, w) {
|
|
|
354
411
|
// A rate limit that would stop it anyway is checked before pausing anyone for it. The quick lane never pauses anyone.
|
|
355
412
|
if (!v.ok && v.rule === 'slot' && !cur.quickPass) v = quotaBlock(s, cur, cfg, hist) || preempt(s, cur, cfg, hist) || v;
|
|
356
413
|
if (v.ok) v = quotaBlock(s, cur, cfg, hist) || v;
|
|
414
|
+
// Still held, for memory or a slot pausing didn't free: a waiter that's urgent, high or has waited long may
|
|
415
|
+
// have a --pausable job checkpoint and step aside (src/preempt.mjs yieldFor). It starts on a later poll, once that job has gone.
|
|
416
|
+
const asked = !v.ok && !cur.quickPass ? yieldFor(s, cur, cfg, hist, v) : null;
|
|
357
417
|
// What held it and for how long, for its start event: on 2026-10-24 a 2-second test waited
|
|
358
418
|
// 3 minutes with 11 GB of disk free, and the log said only that it waited.
|
|
359
419
|
heldFor(cur, v.ok ? null : v.rule || 'other', looked);
|
|
@@ -382,18 +442,20 @@ function judge(s, w) {
|
|
|
382
442
|
// Sitting on one resource while waiting for another wastes it for everyone.
|
|
383
443
|
// A file lease doesn't count: it keeps edits off files while you work, and a job waiting for a test slot doesn't change that.
|
|
384
444
|
const sitting = s.leases.filter(l => l.kind === 'hold' && me.spid && l.pid === me.spid && !l.res.some(x => me.res.includes(x)) && !l.res.every(isFiles));
|
|
385
|
-
return { v, line: waitLine(s, cur, v, cfg, hist, w.talk.told), sitting, holding: cur.holding };
|
|
445
|
+
return { v, line: waitLine(s, cur, v, cfg, hist, w.talk.told), sitting, holding: cur.holding, ...(asked?.asked && { asked: asked.asked }) };
|
|
386
446
|
}
|
|
387
447
|
s.queue = s.queue.filter(x => x.id !== me.id);
|
|
388
448
|
takeQuota(s, cur, cfg);
|
|
389
449
|
const lease = { id: me.id, res: me.res, ...info.size, kind: me.kind, who: me.who, agent: me.agent, label: me.label, spid: me.spid,
|
|
390
450
|
purpose: cur.purpose, cmd: me.cmd, key: me.key, est: info.est, prio: cur.prio, by: cur.by,
|
|
391
451
|
cwd: info.cwd, ppid: info.ppid, start: now(), waited: now() - cur.enq, agentId: info.agentId, sessionId: info.sessionId,
|
|
392
|
-
owner: cur.owner, askedPrio: cur.askedPrio };
|
|
452
|
+
owner: cur.owner, askedPrio: cur.askedPrio, ...((info.codex || cur.codex) && { codex: info.codex || cur.codex }) };
|
|
393
453
|
if (cur.held) lease.held = Object.fromEntries(Object.entries(cur.held).map(([k, x]) => [k, Math.round(x)]));
|
|
394
454
|
if (v.covered.length) lease.covered = v.covered;
|
|
395
455
|
if (v.alongside) lease.alongside = v.alongside;
|
|
396
456
|
if (v.trial) lease.trial = true;
|
|
457
|
+
if (v.eased) lease.eased = true; // let through warning pressure: the next one waits until its memory holds steady (src/schedule.mjs easesPast)
|
|
458
|
+
if (cur.pausable) lease.pausable = true; // safe to pause or stop at a checkpoint (src/preempt.mjs, the yield protocol)
|
|
397
459
|
if (v.quick) lease.quick = true;
|
|
398
460
|
if (cur.repo) lease.repo = cur.repo;
|
|
399
461
|
if (v.loadPast) Object.assign(lease, { loadPast: true, loadWaited: v.loadWaited });
|
|
@@ -434,7 +496,8 @@ export function step(r, w) {
|
|
|
434
496
|
left(w, 'never fits');
|
|
435
497
|
const text = neverText(r.never, me, cfg, null);
|
|
436
498
|
// Through the hook too: an agent that only reads its tool's result hears why its job left the line.
|
|
437
|
-
|
|
499
|
+
// Quiet: the tool call that ran it ends with the same words, and that wakes the agent.
|
|
500
|
+
notify({ sessionId: w.info.sessionId, who: me.who, agentId: w.info.agentId }, `never:${me.id}`, `#${me.id} ${text}`, { quiet: true });
|
|
438
501
|
return out.die(text, 2);
|
|
439
502
|
}
|
|
440
503
|
if (r.lease) {
|
|
@@ -446,6 +509,8 @@ export function step(r, w) {
|
|
|
446
509
|
}
|
|
447
510
|
// A wait is a request that couldn't start at once; one that starts on its first try isn't one.
|
|
448
511
|
if (!w.blocked) { w.blocked = true; note(w, 'wait', { rule: r.v.rule || 'other' }); }
|
|
512
|
+
for (const a of r.asked || [])
|
|
513
|
+
out.say(`asked #${a.id} (${a.who}'s ${a.prio === 'normal' ? '' : `${a.prio} `}job on ${andList(a.res.map(x => named(cfg, x).the))}, started with --pausable) to save its progress and step aside so you can start. It goes back in line behind you.`);
|
|
449
514
|
if (r.holding && !w.saidAhead) {
|
|
450
515
|
w.saidAhead = true;
|
|
451
516
|
out.say(`you already have ${andList(r.holding.res.map(x => named(cfg, x).the))}, so you go ahead of anyone who has nothing yet (urgent work still goes first).`);
|
|
@@ -458,7 +523,7 @@ export function step(r, w) {
|
|
|
458
523
|
w.warnedHolding = true;
|
|
459
524
|
const kept = r.sitting.flatMap(l => l.res).filter(x => !isFiles(x));
|
|
460
525
|
out.say(`you're keeping ${andList(kept.map(x => named(cfg, x).the))} reserved while you wait, so nobody else can use it.`
|
|
461
|
-
+ ` Give it back (dibs release ${kept[0]}) or ask for everything at once: dibs run ${[...new Set([...kept, ...me.res])].join(',')} -- <command>`);
|
|
526
|
+
+ ` Give it back (dibs release ${kept[0]}) or ask for everything at once: dibs run ${[...new Set([...kept, ...me.res])].join(',')} -m "..." -- <command>`);
|
|
462
527
|
}
|
|
463
528
|
// Low disk is waited out, like memory: a person or a job ending frees space, and the run
|
|
464
529
|
// starts the moment there's room, checked again at every poll. Until 0.0.179 a run with
|
|
@@ -482,7 +547,7 @@ export function step(r, w) {
|
|
|
482
547
|
if (!w.maxWait)
|
|
483
548
|
return out.die(`not free yet. ${r.line.why} --no-wait doesn't wait, so your command did NOT run (exit 75).`
|
|
484
549
|
+ ` See when it frees up: dibs when ${shellRes(me.res.map(x => short(x)))}`, 75);
|
|
485
|
-
out.said(`gave up after ${dur(now() - w.started)} in the queue. Your command did NOT run (exit 75, not a failure).`,
|
|
550
|
+
out.said(`gave up after ${dur(now() - w.started)} in the queue (#${me.id}). Your command did NOT run (exit 75, not a failure).`,
|
|
486
551
|
r.line.head, `Your place is kept until ${clock(now() + KEEP_PLACE)}. To keep it, run the same command again before then:`);
|
|
487
552
|
// The command on a line of its own, unwrapped, so it can be pasted as is.
|
|
488
553
|
out.raw(` ${w.info.again}\n`);
|
|
@@ -510,7 +575,11 @@ export function step(r, w) {
|
|
|
510
575
|
// every MOVE_EVERY), or now and then.
|
|
511
576
|
const l = r.line;
|
|
512
577
|
const what = w.talk.step(l);
|
|
513
|
-
if (what === 'full')
|
|
578
|
+
if (what === 'full') {
|
|
579
|
+
const wrapped = wrapper(w.info.ppid);
|
|
580
|
+
out.said(`queued for ${andList(me.res.map(x => named(cfg, x).the))} as #${me.id}.${me.kind === 'hold' ? ' dibs hold waits for its turn like dibs run, then returns.' : ''}`, l.head, l.why, l.ask,
|
|
581
|
+
w.maxWait > 0 ? waitTerms(w, r.v.disk) : '', wrapped ? wrapperLine(wrapped) : '');
|
|
582
|
+
}
|
|
514
583
|
else if (what === 'change') out.said(`still queued (${dur(now() - w.started)}). ${l.head}`, l.why);
|
|
515
584
|
else if (what === 'moved') out.say(`still queued (${dur(now() - w.started)}). You ${l.moved}`);
|
|
516
585
|
else if (what === 'repeat') out.say(`still queued (${dur(now() - w.started)}). ${l.head}`);
|
|
@@ -533,6 +602,8 @@ const HELD_BY = {
|
|
|
533
602
|
load: "the machine's load", cpu: 'the cores dibs shares out on this machine', memory: 'the memory dibs shares out on this machine',
|
|
534
603
|
ram: "this machine's free memory", oversize: "this machine's free memory", pressure: "this machine's memory pressure",
|
|
535
604
|
swap: "this machine's swapping", swaproom: 'the free disk swap needs here', drain: 'free disk falling here',
|
|
605
|
+
// Under the disk floor: the VM has its own disk. On 2026-11-26 eight agents' jobs sat for hours under it with boat-1 asleep.
|
|
606
|
+
disk: 'too little free disk here',
|
|
536
607
|
ahead: 'a job ahead of it waiting for memory',
|
|
537
608
|
};
|
|
538
609
|
// The waits on memory: those may also go to a VM made beside a full boat-1.
|
|
@@ -618,9 +689,16 @@ async function fitsElsewhere(need) {
|
|
|
618
689
|
// Plain dibs gives other machines 1.5 s (AGENTS.md); a refusal can afford as much.
|
|
619
690
|
const ELSEWHERE_WAIT = 1500;
|
|
620
691
|
|
|
692
|
+
// DIBS_THIN_WAIT, read once and kept from the command's own environment.
|
|
693
|
+
function carried() {
|
|
694
|
+
const v = process.env.DIBS_THIN_WAIT;
|
|
695
|
+
delete process.env.DIBS_THIN_WAIT;
|
|
696
|
+
try { return v ? JSON.parse(v) : null; } catch { return null; }
|
|
697
|
+
}
|
|
698
|
+
|
|
621
699
|
export async function acquire(o, kind, cfg) {
|
|
622
700
|
if (o.lease) return ownLease(o.lease, kind);
|
|
623
|
-
if (!o.res.length) die('which resource? Name it, like dibs hold sim. The list: dibs help all');
|
|
701
|
+
if (!o.res.length) die('which resource? Name it, like dibs hold sim -m "...". The list: dibs help all');
|
|
624
702
|
if (o.prio && !(o.prio in PRIORITY_SHIFT)) die(`priority is one of ${PRIORITIES.join(', ')} (or 1-5)`);
|
|
625
703
|
if (NEEDS_REASON.has(o.prio) && !o.purpose) die(`${o.prio} priority needs a reason everyone can see: -m "why"`);
|
|
626
704
|
const id = identity(o);
|
|
@@ -631,7 +709,10 @@ export async function acquire(o, kind, cfg) {
|
|
|
631
709
|
const hist = history();
|
|
632
710
|
// Planned at what this command really used last time, when that's more than it asked for.
|
|
633
711
|
const sent = !!process.env.DIBS_REMOTE_JOB;
|
|
634
|
-
|
|
712
|
+
// Its project, for resources one at a time per project (deploys) and for what its runs here used: a job sent from another
|
|
713
|
+
// machine carries its sender's (DIBS_REPO, src/worker.mjs), since its copy here has no .git.
|
|
714
|
+
const repo = process.env.DIBS_REPO || projectKey(process.cwd());
|
|
715
|
+
const size = { ...sized(jobSize(cfg, res, o), hist, key, cfg, repo), sent, declared: o.mem != null, cpuDeclared: o.cpu != null, ...(o.disk != null && { diskDeclared: true }) };
|
|
635
716
|
// More than this machine ever hands out, asked for in so many words: it would
|
|
636
717
|
// wait forever, and as the oldest waiter hold others back. Refused now, unless
|
|
637
718
|
// an outer run or hold already has the resources (it runs inside what that
|
|
@@ -641,8 +722,8 @@ export async function acquire(o, kind, cfg) {
|
|
|
641
722
|
const never = !nested && neverFits(cfg, explicitAsk(size));
|
|
642
723
|
if (never) die(neverText(never, null, cfg, await fitsElsewhere(explicitAsk(size))));
|
|
643
724
|
if (!nested) capToMachine(cfg, size);
|
|
644
|
-
const { mem, cpu, disk, asked, askedCpu, usual } = size;
|
|
645
|
-
const grew = grewPlain({ mem, cpu, asked, askedCpu, usual }, key.split('|')[1]);
|
|
725
|
+
const { mem, cpu, disk, asked, askedCpu, usual, used } = size;
|
|
726
|
+
const grew = grewPlain({ mem, cpu, asked, askedCpu, usual, used }, key.split('|')[1]);
|
|
646
727
|
// Booked at what it really used, not at its ask: dibs's own bookkeeping, kept
|
|
647
728
|
// in the history and said to nobody. On 2026-11-03 these were 6 of 35 notices,
|
|
648
729
|
// and "typecheck used up to 4 cores, pass --cpu 4" came on every merge.
|
|
@@ -657,15 +738,17 @@ export async function acquire(o, kind, cfg) {
|
|
|
657
738
|
|
|
658
739
|
const quotaWrong = quotaProblem(cfg, res, o.cost);
|
|
659
740
|
if (quotaWrong) die(quotaWrong);
|
|
660
|
-
const unknown = res.filter(r => !isQuota(r) && !isFiles(r) && !cfg.resources[r] && !hist.some(h => h.key.split('|')[0].split(',').includes(r)));
|
|
741
|
+
const unknown = res.filter(r => !isQuota(r) && !isFiles(r) && !isEnv(r) && !cfg.resources[r] && !hist.some(h => h.key.split('|')[0].split(',').includes(r)));
|
|
661
742
|
if (unknown.length)
|
|
662
743
|
said(`note: ${unknown.join(', ')} isn't a resource dibs knows, so this starts a new queue for it: one job at a time, planned at ${resCfg(cfg, unknown[0]).mem} of memory.`
|
|
663
744
|
+ ` Known: ${Object.keys(cfg.resources).join(', ')}. Use the same name as the other agents, or you'll each have your own queue for one thing.`);
|
|
664
745
|
if (machine().diskFree == null) say("couldn't read free disk space, so the disk check is off for this request.");
|
|
665
746
|
|
|
666
|
-
|
|
747
|
+
// A thin waiter's shell getting in line again carries on the wait its first Node began (src/broker.mjs inlineCall).
|
|
748
|
+
const carry = carried();
|
|
749
|
+
const started = carry?.started ?? now();
|
|
667
750
|
if (maxWait !== Infinity) setLockDeadline(started + maxWait);
|
|
668
|
-
const w = waiter({ started, maxWait, waitSet: o.maxWait != null, for: o.for, est: o.est, agentId: o.agentId, sessionId: process.env.CLAUDE_CODE_SESSION_ID,
|
|
751
|
+
const w = waiter({ ...carry, started, maxWait, waitSet: o.maxWait != null, for: o.for, est: o.est, agentId: o.agentId, sessionId: process.env.CLAUDE_CODE_SESSION_ID, codex: codexThread(),
|
|
669
752
|
cwd: process.cwd(), ppid: callerPid(), sstart: id.sstart, size: { mem, cpu, asked, askedCpu, usual }, again: again(), path: o.thin?.fifo,
|
|
670
753
|
notify: o.notify ? path.resolve(o.notify) : undefined, follow: process.env.DIBS_REMOTE_JOB ? { pid: callerPid(), pstart: pstart(callerPid()) } : undefined }, cfg, hist, stderrOut);
|
|
671
754
|
// A signal while getting in line is held until there's a place to give up,
|
|
@@ -686,16 +769,15 @@ export async function acquire(o, kind, cfg) {
|
|
|
686
769
|
// Stamped as looked-at now: a place picked up is decided for again from here on.
|
|
687
770
|
if (q) { Object.assign(q, { pid, pstart: myStart, keepUntil: null, polledAt: now() }); delete q.wake; delete q.keptFor; }
|
|
688
771
|
else {
|
|
689
|
-
q = { id: ++s.seq, ticket, res, mem, cpu, disk, asked, askedCpu, usual, pid, pstart: myStart, enq: now(), polledAt: now(),
|
|
772
|
+
q = { id: o.afterId ?? ++s.seq, ticket, res, mem, cpu, disk, asked, askedCpu, usual, pid, pstart: myStart, enq: now(), polledAt: now(),
|
|
690
773
|
who: id.who, agent: id.agent, label: id.label, spid: id.spid, purpose: o.purpose || '', cmd, key, kind,
|
|
691
|
-
agentId: o.agentId, sessionId: process.env.CLAUDE_CODE_SESSION_ID, cwd: process.cwd(), ppid: callerPid(),
|
|
692
|
-
// Its project, for resources one at a time per project (deploys): a job sent from another machine
|
|
693
|
-
// carries its sender's (DIBS_REPO, src/worker.mjs), since its copy here has no .git.
|
|
694
|
-
repo: process.env.DIBS_REPO || projectKey(process.cwd()) };
|
|
774
|
+
agentId: o.agentId, sessionId: process.env.CLAUDE_CODE_SESSION_ID, ...(codexThread() && { codex: codexThread() }), cwd: process.cwd(), ppid: callerPid(), repo };
|
|
695
775
|
if (outer) q.outer = outer.id;
|
|
696
776
|
if (sent) q.sent = true; // placed here by the coordinator for its size (neverFits)
|
|
697
777
|
s.queue.push(q);
|
|
698
778
|
}
|
|
779
|
+
// Waiting --after another job, it joins the line under the same id, in this one change (src/after.mjs).
|
|
780
|
+
if (o.afterId && s.afters) { s.afters = s.afters.filter(x => x.id !== o.afterId); if (!s.afters.length) delete s.afters; }
|
|
699
781
|
// A process waits for one thing: any other place under it was left behind, and only holds others back.
|
|
700
782
|
s.queue = s.queue.filter(x => x === q || !(me(x) || (!x.pid && x.keptFor === pid)));
|
|
701
783
|
// Without -m, a wait for the rest of what a ship needs says what the ship is for.
|
|
@@ -705,17 +787,20 @@ export async function acquire(o, kind, cfg) {
|
|
|
705
787
|
if (o.by) q.by = o.by;
|
|
706
788
|
if (o.est) q.est = o.est;
|
|
707
789
|
if (o.quick) q.quick = true; // trusted the first time; its runs decide after (quickPass)
|
|
790
|
+
if (o.pausable && kind === 'run') q.pausable = true; // safe to pause, or to checkpoint and step aside (src/preempt.mjs yieldFor)
|
|
708
791
|
if (o.cost != null) q.cost = o.cost;
|
|
709
792
|
if (o.mem != null) q.declared = true; // a size to go on before dibs has measured it (src/overlap.mjs)
|
|
793
|
+
if (size.learnedMem) q.learnedMem = true; // planned at what its runs used, whatever --mem said (src/measure.mjs sized)
|
|
710
794
|
if (o.cpu != null) q.cpuDeclared = true; // asked for in so many words, which alone can make it never fit (neverFits)
|
|
711
795
|
if (o.disk != null) q.diskDeclared = true; // its own word on the disk it writes beats what earlier runs seemed to eat
|
|
796
|
+
if (kind === 'run' && freesOnly(o.cmd)) q.frees = true; // simctl shutdown and the like: no disk or memory gates (src/schedule.mjs)
|
|
712
797
|
return { ...q };
|
|
713
798
|
});
|
|
714
799
|
const me = w.me;
|
|
715
800
|
|
|
716
801
|
if (me.owner?.act === 'cap') say(`the person at this machine capped ${me.agent || me.who}'s work at ${me.prio} priority, so this waits and runs at ${me.prio}, not ${me.askedPrio}.`);
|
|
717
802
|
|
|
718
|
-
const bail = sig => { left(w, sig); leave(w,
|
|
803
|
+
const bail = sig => { left(w, sig); process.stderr.write(leave(w, true, sig)); process.exit(signalExit(sig)); };
|
|
719
804
|
for (const sig of SIGNALS) { process.removeListener(sig, hold); process.on(sig, bail); }
|
|
720
805
|
if (early) bail(early);
|
|
721
806
|
|
package/src/after.mjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// dibs run --after <job>: a job that waits for another to end before it gets
|
|
2
|
+
// in line, so "run the flop test after the drift test" can be said. It waits
|
|
3
|
+
// outside the line, in state.afters, shown on the board as "after #N". That
|
|
4
|
+
// wait counts against no limit (not --max-wait, not dibs's own): its turn in
|
|
5
|
+
// line, once the other job ends, gets the whole limit. Its id is the one it
|
|
6
|
+
// keeps in line and on its lease, so a third job can come --after it.
|
|
7
|
+
//
|
|
8
|
+
// It never runs silently past what it waited on: a job it waited on that never
|
|
9
|
+
// ran (it left the line, or its dibs died first), or with --after-ok one that
|
|
10
|
+
// failed, ends this one too with exit 75, nothing run. Its caller dying leaves
|
|
11
|
+
// its entry for the next state read to reap (src/state.mjs), like any waiter.
|
|
12
|
+
import { withState } from './state.mjs';
|
|
13
|
+
import { identity, isMine, pstart, tag } from './proc.mjs';
|
|
14
|
+
import { readEvents, event } from './events.mjs';
|
|
15
|
+
import { short } from './files.mjs';
|
|
16
|
+
import { dur, die, say, sleep, now, SIGNALS, signalExit } from './util.mjs';
|
|
17
|
+
|
|
18
|
+
const POLL = 1500; // a job's end is a human-scale event: a second and a half late costs nothing
|
|
19
|
+
|
|
20
|
+
// Every job on the board now: leases, waiters and other --after waits.
|
|
21
|
+
const live = s => [...s.leases, ...s.queue.filter(q => q.pid), ...(s.afters || [])];
|
|
22
|
+
|
|
23
|
+
// What `--after <what>` names: a job by its number (42 or #42), an agent by name (everything it
|
|
24
|
+
// holds and waits for now; web-app:test for one resource), or the words a job was run with (-m).
|
|
25
|
+
// Several jobs by words: the caller's own, if that's one.
|
|
26
|
+
function find(s, what, me) {
|
|
27
|
+
const n = /^#?(\d+)$/.exec(what);
|
|
28
|
+
if (n) {
|
|
29
|
+
const id = Number(n[1]);
|
|
30
|
+
return live(s).some(x => x.id === id) ? { ids: [id] } : { past: id };
|
|
31
|
+
}
|
|
32
|
+
const [who, res] = what.split(':');
|
|
33
|
+
const named = live(s).filter(x => (x.agent === who || x.who === who) && (!res || x.res.includes(res)));
|
|
34
|
+
if (named.length) return { ids: named.map(x => x.id) };
|
|
35
|
+
const low = what.toLowerCase();
|
|
36
|
+
const said = live(s).filter(x => x.purpose && x.purpose.toLowerCase().includes(low) && x.pid !== process.pid);
|
|
37
|
+
const own = said.filter(x => isMine(x, me));
|
|
38
|
+
const hits = own.length === 1 ? own : said;
|
|
39
|
+
if (hits.length === 1) return { ids: [hits[0].id] };
|
|
40
|
+
return hits.length ? { many: hits } : { none: true };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// How each job ended, by the event log: { code, hold } once it ran, null when it never did.
|
|
44
|
+
// known: the ids the log has any record of, run or not.
|
|
45
|
+
function endings(ids) {
|
|
46
|
+
const out = new Map(ids.map(id => [id, null]));
|
|
47
|
+
const known = new Set();
|
|
48
|
+
for (const e of readEvents()) {
|
|
49
|
+
if (!out.has(e.id) || !['end', 'left', 'start'].includes(e.kind)) continue;
|
|
50
|
+
known.add(e.id);
|
|
51
|
+
if (e.kind === 'end') out.set(e.id, { code: e.code, hold: e.type === 'hold' });
|
|
52
|
+
}
|
|
53
|
+
out.known = known;
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
const okEnd = e => e.code === 0 || (e.code == null && e.hold);
|
|
57
|
+
const howEnded = (id, e) => (!e ? `#${id} never ran (it left the line, or its dibs ended before its turn)`
|
|
58
|
+
: e.code == null ? (e.hold ? `#${id} ended (a hold, given back)` : `#${id} ended without an exit code (it was killed)`)
|
|
59
|
+
: e.code === 0 ? `#${id} passed (exit 0)` : `#${id} failed (exit ${e.code})`);
|
|
60
|
+
|
|
61
|
+
// Waits until every job it's after has ended, then returns the id its place in line takes
|
|
62
|
+
// (o.afterId, src/acquire.mjs), or exits 75 (it can't follow them) or 1 (nothing matched).
|
|
63
|
+
export async function afterJob(o) {
|
|
64
|
+
const me = identity(o);
|
|
65
|
+
const what = String(o.after);
|
|
66
|
+
const found = withState(s => {
|
|
67
|
+
const f = find(s, what, me);
|
|
68
|
+
if (!f.ids) return f;
|
|
69
|
+
const x = { id: ++s.seq, after: f.ids, ...(o.afterOk && { ok: true }), res: [...new Set(o.res)], who: me.who, agent: me.agent, label: me.label, spid: me.spid,
|
|
70
|
+
purpose: o.purpose || '', cmd: (o.cmd || []).join(' ').slice(0, 200), kind: o.cmd ? 'run' : 'hold', pid: process.pid, pstart: pstart(process.pid), enq: now(),
|
|
71
|
+
cwd: process.cwd(), sessionId: process.env.CLAUDE_CODE_SESSION_ID, agentId: o.agentId,
|
|
72
|
+
deps: live(s).filter(d => f.ids.includes(d.id)).map(d => ({ id: d.id, who: tag(d), res: d.res.map(r => short(r)), purpose: d.purpose || '' })) };
|
|
73
|
+
(s.afters ||= []).push(x);
|
|
74
|
+
return { mine: x };
|
|
75
|
+
});
|
|
76
|
+
if (found.many) die(`"${what}" matches ${found.many.length} jobs: ${found.many.map(x => `#${x.id} (${tag(x)}, "${x.purpose}")`).join(', ')}. Say which: --after #<id>. Your command did NOT run.`, 2);
|
|
77
|
+
if (found.none) die(`nothing on the board is "${what}": no job number, agent or -m words match. Your command did NOT run (exit 1). The numbers: dibs --detail, or dibs mine for yours`, 1);
|
|
78
|
+
if (found.past) return settle([found.past], o, null);
|
|
79
|
+
const x = found.mine;
|
|
80
|
+
const leave = (why, code, text) => {
|
|
81
|
+
withState(s => { if (s.afters) s.afters = s.afters.filter(a => a.id !== x.id); });
|
|
82
|
+
event({ kind: 'left', id: x.id, res: x.res, who: x.who, type: 'after', ms: now() - x.enq, why });
|
|
83
|
+
die(text, code);
|
|
84
|
+
};
|
|
85
|
+
const bail = sig => { try { leave(sig, signalExit(sig), `stopped by ${sig} while waiting for ${x.after.map(id => `#${id}`).join(', ')}. Nothing ran.`); } catch { process.exit(signalExit(sig)); } };
|
|
86
|
+
for (const sig of SIGNALS) process.on(sig, bail);
|
|
87
|
+
const deps = x.deps.map(d => `#${d.id} (${d.who}, ${d.res.join(',')}${d.purpose ? `, "${d.purpose}"` : ''})`).join(', ');
|
|
88
|
+
say(`#${x.id} waits for ${deps} to end${o.afterOk ? ', and runs only if it succeeds' : ''}, then joins the line. This wait counts against no time limit. Waiting is normal: don't run it again.`);
|
|
89
|
+
const t0 = now();
|
|
90
|
+
for (;;) {
|
|
91
|
+
const r = withState(s => {
|
|
92
|
+
if (!(s.afters || []).some(a => a.id === x.id)) return { gone: true };
|
|
93
|
+
const ids = new Set(live(s).map(l => l.id));
|
|
94
|
+
return { left: x.after.filter(id => ids.has(id)) };
|
|
95
|
+
});
|
|
96
|
+
if (r.gone) { for (const sig of SIGNALS) process.removeListener(sig, bail); die(`#${x.id} was taken off the board while it waited. Your command did NOT run (exit 75).`, 75); }
|
|
97
|
+
if (!r.left.length) break;
|
|
98
|
+
await sleep(POLL);
|
|
99
|
+
}
|
|
100
|
+
for (const sig of SIGNALS) process.removeListener(sig, bail);
|
|
101
|
+
return settle(x.after, o, { x, leave, waited: now() - t0 });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// The jobs it waited on have ended: go on, or say why not and stop. The --after entry stays
|
|
105
|
+
// until acquire puts the same id in line, so nobody after it sees it vanish in between.
|
|
106
|
+
function settle(ids, o, w) {
|
|
107
|
+
const ends = endings(ids);
|
|
108
|
+
const bad = ids.find(id => !ends.get(id) || (o.afterOk && !okEnd(ends.get(id))));
|
|
109
|
+
if (!w && !ids.some(id => ends.known.has(id)))
|
|
110
|
+
die(`nothing on the board is #${ids[0]}, and dibs has no record of it ending. Your command did NOT run (exit 1). The numbers: dibs --detail, or dibs mine for yours`, 1);
|
|
111
|
+
const how = ids.map(id => howEnded(id, ends.get(id))).join('; ');
|
|
112
|
+
if (bad != null) {
|
|
113
|
+
const why = !ends.get(bad) ? 'it never ran' : 'it failed';
|
|
114
|
+
const text = `${how}, so this didn't join the line${o.afterOk && ends.get(bad) ? ' (--after-ok runs only after a success)' : ''}. Your command did NOT run (exit 75). Find out why #${bad} ${why === 'it failed' ? 'failed' : "didn't run"} before running both again.`;
|
|
115
|
+
return w ? w.leave(why, 75, text) : die(text, 75);
|
|
116
|
+
}
|
|
117
|
+
say(`${how}${w ? ` after ${dur(w.waited)}` : ' already'}; joining the line.`);
|
|
118
|
+
if (w) o.afterId = w.x.id;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// The board's rows for jobs waiting on another: what, whose, and after which.
|
|
122
|
+
export const aftersNow = (s, t = now()) => (s.afters || []).map(a => ({ id: a.id, res: a.res, who: a.who, agent: a.agent, label: a.label, spid: a.spid, agentId: a.agentId,
|
|
123
|
+
purpose: a.purpose, after: a.after, ok: !!a.ok, waited: t - a.enq, deps: a.deps || [] }));
|
|
124
|
+
export const afterText = a => `after ${a.after.map(id => `#${id}`).join(', ')}${a.ok ? ', only if it succeeds' : ''}`;
|
|
125
|
+
// Detail board lines (dibs --detail), under the queue.
|
|
126
|
+
export const afterLines = (rows, you = () => '') => (rows.length ? ['', 'AFTER (each joins the line once the job it waits on ends)', ...rows.map(a =>
|
|
127
|
+
` ${a.res.join(',').padEnd(11)} ${(a.label && a.label !== a.who ? `${a.who} (${a.label})` : a.who).padEnd(28)} waited ${dur(a.waited).padStart(6)}${a.purpose ? ` "${a.purpose}"` : ''} [${afterText(a)}]${you(a)}`)] : []);
|
package/src/agents.mjs
CHANGED
|
@@ -15,6 +15,7 @@ import { HOME } from './config.mjs';
|
|
|
15
15
|
import { identity, makeAlive } from './proc.mjs';
|
|
16
16
|
import { underLock, commit } from './lock.mjs';
|
|
17
17
|
import { now, fakeFull } from './util.mjs';
|
|
18
|
+
import { readJSON } from './durable.mjs';
|
|
18
19
|
|
|
19
20
|
const FILE = path.join(HOME, 'agents.json');
|
|
20
21
|
const LOCK = path.join(HOME, 'agents.lock');
|
|
@@ -41,7 +42,7 @@ export const agentSlots = cfg => (Number(cfg?.agents?.slots) > 0 ? Number(cfg.ag
|
|
|
41
42
|
function locked(fn) {
|
|
42
43
|
const r = underLock(LOCK, h => {
|
|
43
44
|
let list = [];
|
|
44
|
-
try { list =
|
|
45
|
+
try { list = readJSON(FILE).agents || []; } catch (e) { if (e.code !== 'ENOENT' && !(e instanceof SyntaxError)) throw e; }
|
|
45
46
|
const before = JSON.stringify(list);
|
|
46
47
|
list = reap(list);
|
|
47
48
|
const out = fn(list);
|