@dibssoftware/dibs 0.0.181 → 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.
Files changed (105) hide show
  1. package/CHANGELOG.md +103 -1
  2. package/README.md +10 -8
  3. package/bin/dibs.mjs +370 -73
  4. package/docs/agents.md +303 -0
  5. package/docs/council.md +88 -0
  6. package/docs/files.md +3 -3
  7. package/docs/guard.md +86 -11
  8. package/docs/json.md +211 -0
  9. package/docs/later.md +5 -5
  10. package/docs/machines.md +6 -6
  11. package/docs/questions.md +104 -3
  12. package/docs/reference.md +124 -30
  13. package/docs/relay.md +120 -9
  14. package/docs/releasing.md +7 -1
  15. package/docs/scheduling.md +28 -6
  16. package/docs/secrets.md +53 -0
  17. package/docs/simulators.md +3 -3
  18. package/package.json +1 -1
  19. package/skills/dibs/SKILL.md +79 -149
  20. package/src/about.mjs +341 -0
  21. package/src/acquire.mjs +111 -27
  22. package/src/after.mjs +127 -0
  23. package/src/agents.mjs +2 -1
  24. package/src/alerts.mjs +95 -42
  25. package/src/answers.mjs +2 -2
  26. package/src/board.mjs +21 -16
  27. package/src/broker.mjs +23 -7
  28. package/src/carry.mjs +287 -0
  29. package/src/codex.mjs +132 -0
  30. package/src/commands.mjs +243 -82
  31. package/src/config.mjs +85 -14
  32. package/src/connect.mjs +4 -2
  33. package/src/cool.mjs +27 -11
  34. package/src/council.mjs +482 -0
  35. package/src/cwd.mjs +9 -0
  36. package/src/decisions.mjs +250 -0
  37. package/src/declare.mjs +96 -0
  38. package/src/diskreport.mjs +306 -0
  39. package/src/diskuse.mjs +420 -0
  40. package/src/diskwarn.mjs +68 -13
  41. package/src/doctor.mjs +149 -0
  42. package/src/doors.mjs +547 -0
  43. package/src/durable.mjs +143 -0
  44. package/src/envs.mjs +372 -0
  45. package/src/events.mjs +7 -2
  46. package/src/files.mjs +118 -6
  47. package/src/guard.mjs +239 -86
  48. package/src/guardd.mjs +8 -1
  49. package/src/halt.mjs +63 -0
  50. package/src/handoffs.mjs +362 -0
  51. package/src/history.mjs +34 -4
  52. package/src/hogs.mjs +36 -8
  53. package/src/jobprogress.mjs +283 -0
  54. package/src/later.mjs +21 -10
  55. package/src/lock.mjs +33 -9
  56. package/src/measure.mjs +42 -11
  57. package/src/media.mjs +240 -0
  58. package/src/news.mjs +31 -0
  59. package/src/notes.mjs +49 -8
  60. package/src/notices.mjs +126 -43
  61. package/src/ondemand.mjs +25 -2
  62. package/src/outcome.mjs +163 -0
  63. package/src/overlap.mjs +2 -2
  64. package/src/override.mjs +149 -79
  65. package/src/owner.mjs +15 -2
  66. package/src/people.mjs +236 -0
  67. package/src/pickup.mjs +72 -0
  68. package/src/picture.mjs +321 -0
  69. package/src/plain.mjs +84 -18
  70. package/src/platform.mjs +19 -0
  71. package/src/preempt.mjs +123 -15
  72. package/src/primer.mjs +91 -20
  73. package/src/prints.mjs +99 -0
  74. package/src/proc.mjs +1 -1
  75. package/src/progress.mjs +49 -3
  76. package/src/proof.mjs +102 -0
  77. package/src/push.mjs +271 -0
  78. package/src/questions.mjs +328 -57
  79. package/src/quota.mjs +1 -1
  80. package/src/recap.mjs +205 -0
  81. package/src/relay.mjs +139 -20
  82. package/src/remote.mjs +23 -10
  83. package/src/reviewgate.mjs +268 -0
  84. package/src/reviews.mjs +377 -0
  85. package/src/route.mjs +263 -0
  86. package/src/rules.mjs +216 -0
  87. package/src/schedule.mjs +238 -44
  88. package/src/schema.mjs +62 -0
  89. package/src/scratch.mjs +2 -2
  90. package/src/serve.mjs +3 -2
  91. package/src/signed.mjs +97 -0
  92. package/src/simpool.mjs +46 -1
  93. package/src/spend.mjs +375 -0
  94. package/src/state.mjs +43 -17
  95. package/src/talk.mjs +1078 -133
  96. package/src/thin.sh +2 -0
  97. package/src/trail.mjs +290 -0
  98. package/src/trailnote.mjs +209 -0
  99. package/src/util.mjs +7 -0
  100. package/src/vault.mjs +435 -0
  101. package/src/vendors.mjs +327 -0
  102. package/src/version.mjs +1 -1
  103. package/src/web.mjs +353 -60
  104. package/src/work.mjs +487 -0
  105. package/src/worker.mjs +7 -1
package/src/acquire.mjs CHANGED
@@ -3,25 +3,26 @@ import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { spawn } from 'node:child_process';
5
5
  import { fileURLToPath } from 'node:url';
6
- import { resCfg, machine, paths, HOME, loadConfig } from './config.mjs';
6
+ import { resCfg, machine, paths, HOME, loadConfig, isEnv } from './config.mjs';
7
7
  import { identity, pstart, tag } from './proc.mjs';
8
8
  import { processes, parent, OS } from './platform.mjs';
9
9
  import { withState, peek, history, setLockDeadline, KEEP_PLACE } from './state.mjs';
10
- import { preempt } from './preempt.mjs';
10
+ import { preempt, yieldFor } from './preempt.mjs';
11
11
  import { isFiles, short, shellRes, projectKey } from './files.mjs';
12
12
  import { jobSize } from './simpool.mjs';
13
13
  import { sized, grewLine, grewPlain, treeOf } from './measure.mjs';
14
14
  import { isQuota, quotaProblem, quotaBlock, takeQuota } from './quota.mjs';
15
15
  import { capWaiter, inversions, lift } from './override.mjs';
16
- 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';
17
17
  import { event } from './events.mjs';
18
18
  import { startLine } from './overlap.mjs';
19
- 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';
20
20
  import { plainBoard, startPhrase, askFirst, named, andList, lower, ordinal, moves, stuckFor, STUCK_AFTER } from './plain.mjs';
21
21
  import { quoted, wrap, width } from './style.mjs';
22
22
  import { noticeScan } from './notices.mjs';
23
23
  import { notify } from './talk.mjs';
24
24
  import { mayShip, loadShipTarget } from './remote.mjs';
25
+ import { described } from './declare.mjs';
25
26
 
26
27
  const BIN = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'bin', 'dibs.mjs');
27
28
 
@@ -73,6 +74,31 @@ export const backgroundable = (env = process.env) =>
73
74
  export const defaultMaxWait = () =>
74
75
  backgroundable() ? Infinity : process.env.DIBS_MAX_WAIT ? ms(process.env.DIBS_MAX_WAIT) : DEFAULT_MAX_WAIT;
75
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
+
76
102
  // Said once, when the wait starts, so nobody has to guess what happens at the end of it.
77
103
  function waitTerms(w, disk) {
78
104
  if (w.maxWait === Infinity)
@@ -121,7 +147,7 @@ export const idleFor = (l, t = now()) => (l.idleSince && t - l.idleSince > IDLE_
121
147
  export function describeLease(l, hist, t = now()) {
122
148
  const left = remaining(l, hist, t);
123
149
  const idle = idleFor(l, t);
124
- return `${tag(l)} for ${dur(t - l.start)}${l.purpose ? ` ("${l.purpose}")` : ''}${l.cmd ? `: ${l.cmd.slice(0, 60)}` : ' (hold)'}`
150
+ return `${tag(l)} for ${dur(t - l.start)} ("${described(l)}")${l.cmd ? `: ${l.cmd.slice(0, 60)}` : ' (hold)'}`
125
151
  + `${left != null ? `, ~${dur(left)} left` : ''}${idle ? `, but its command has used no CPU for ${dur(idle)}` : ''}`
126
152
  + `${overBy(l) ? `, using ${gb(l.use.mem)} of the ${gb(l.mem)} it asked for` : ''}`;
127
153
  }
@@ -244,17 +270,46 @@ const note = (w, what, extra) => event({ kind: what, id: w.me.id, res: w.me.res,
244
270
  const left = (w, why) => { if (w.blocked) note(w, 'left', { ms: now() - w.me.enq, why }); };
245
271
 
246
272
  // On a full disk the place stays on record under this pid, and the next
247
- // state read drops it once this process is gone.
248
- function leave(w, keep) {
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 = '';
249
277
  try {
250
278
  // A low job lifted for this waiter alone goes back down as it leaves (src/override.mjs inversions).
251
279
  lift(withState(s => {
252
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);
253
282
  if (keep && q) Object.assign(q, { pid: null, keepUntil: now() + KEEP_PLACE });
254
283
  else s.queue = s.queue.filter(x => x.id !== w.me.id);
255
284
  return inversions(s, w.cfg);
256
285
  }));
257
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` : '');
258
313
  }
259
314
 
260
315
  // A wait ended from outside it: leaves the line, closes it in the history, says why.
@@ -303,7 +358,8 @@ export { UNPOLLED }; // src/board.mjs reads it from here
303
358
  function resize(cur, w) {
304
359
  if (cur.sent) return;
305
360
  const base = { mem: cur.asked ?? cur.mem, cpu: cur.cpu, disk: cur.disk };
306
- 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;
307
363
  if (n.mem === cur.mem && n.usual === cur.usual) return;
308
364
  cur.mem = n.mem;
309
365
  if (n.usual != null) cur.usual = n.usual; else delete cur.usual;
@@ -355,6 +411,9 @@ function judge(s, w) {
355
411
  // A rate limit that would stop it anyway is checked before pausing anyone for it. The quick lane never pauses anyone.
356
412
  if (!v.ok && v.rule === 'slot' && !cur.quickPass) v = quotaBlock(s, cur, cfg, hist) || preempt(s, cur, cfg, hist) || v;
357
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;
358
417
  // What held it and for how long, for its start event: on 2026-10-24 a 2-second test waited
359
418
  // 3 minutes with 11 GB of disk free, and the log said only that it waited.
360
419
  heldFor(cur, v.ok ? null : v.rule || 'other', looked);
@@ -383,18 +442,20 @@ function judge(s, w) {
383
442
  // Sitting on one resource while waiting for another wastes it for everyone.
384
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.
385
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));
386
- 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 }) };
387
446
  }
388
447
  s.queue = s.queue.filter(x => x.id !== me.id);
389
448
  takeQuota(s, cur, cfg);
390
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,
391
450
  purpose: cur.purpose, cmd: me.cmd, key: me.key, est: info.est, prio: cur.prio, by: cur.by,
392
451
  cwd: info.cwd, ppid: info.ppid, start: now(), waited: now() - cur.enq, agentId: info.agentId, sessionId: info.sessionId,
393
- owner: cur.owner, askedPrio: cur.askedPrio };
452
+ owner: cur.owner, askedPrio: cur.askedPrio, ...((info.codex || cur.codex) && { codex: info.codex || cur.codex }) };
394
453
  if (cur.held) lease.held = Object.fromEntries(Object.entries(cur.held).map(([k, x]) => [k, Math.round(x)]));
395
454
  if (v.covered.length) lease.covered = v.covered;
396
455
  if (v.alongside) lease.alongside = v.alongside;
397
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)
398
459
  if (v.quick) lease.quick = true;
399
460
  if (cur.repo) lease.repo = cur.repo;
400
461
  if (v.loadPast) Object.assign(lease, { loadPast: true, loadWaited: v.loadWaited });
@@ -435,7 +496,8 @@ export function step(r, w) {
435
496
  left(w, 'never fits');
436
497
  const text = neverText(r.never, me, cfg, null);
437
498
  // Through the hook too: an agent that only reads its tool's result hears why its job left the line.
438
- notify({ sessionId: w.info.sessionId, who: me.who, agentId: w.info.agentId }, `never:${me.id}`, `#${me.id} ${text}`);
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 });
439
501
  return out.die(text, 2);
440
502
  }
441
503
  if (r.lease) {
@@ -447,6 +509,8 @@ export function step(r, w) {
447
509
  }
448
510
  // A wait is a request that couldn't start at once; one that starts on its first try isn't one.
449
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.`);
450
514
  if (r.holding && !w.saidAhead) {
451
515
  w.saidAhead = true;
452
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).`);
@@ -459,7 +523,7 @@ export function step(r, w) {
459
523
  w.warnedHolding = true;
460
524
  const kept = r.sitting.flatMap(l => l.res).filter(x => !isFiles(x));
461
525
  out.say(`you're keeping ${andList(kept.map(x => named(cfg, x).the))} reserved while you wait, so nobody else can use it.`
462
- + ` 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>`);
463
527
  }
464
528
  // Low disk is waited out, like memory: a person or a job ending frees space, and the run
465
529
  // starts the moment there's room, checked again at every poll. Until 0.0.179 a run with
@@ -483,7 +547,7 @@ export function step(r, w) {
483
547
  if (!w.maxWait)
484
548
  return out.die(`not free yet. ${r.line.why} --no-wait doesn't wait, so your command did NOT run (exit 75).`
485
549
  + ` See when it frees up: dibs when ${shellRes(me.res.map(x => short(x)))}`, 75);
486
- 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).`,
487
551
  r.line.head, `Your place is kept until ${clock(now() + KEEP_PLACE)}. To keep it, run the same command again before then:`);
488
552
  // The command on a line of its own, unwrapped, so it can be pasted as is.
489
553
  out.raw(` ${w.info.again}\n`);
@@ -511,7 +575,11 @@ export function step(r, w) {
511
575
  // every MOVE_EVERY), or now and then.
512
576
  const l = r.line;
513
577
  const what = w.talk.step(l);
514
- if (what === 'full') out.said(`queued for ${andList(me.res.map(x => named(cfg, x).the))}.${me.kind === 'hold' ? ' dibs hold waits for its turn like dibs run, then returns.' : ''}`, l.head, l.why, l.ask, w.maxWait > 0 ? waitTerms(w, r.v.disk) : '');
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
+ }
515
583
  else if (what === 'change') out.said(`still queued (${dur(now() - w.started)}). ${l.head}`, l.why);
516
584
  else if (what === 'moved') out.say(`still queued (${dur(now() - w.started)}). You ${l.moved}`);
517
585
  else if (what === 'repeat') out.say(`still queued (${dur(now() - w.started)}). ${l.head}`);
@@ -534,6 +602,8 @@ const HELD_BY = {
534
602
  load: "the machine's load", cpu: 'the cores dibs shares out on this machine', memory: 'the memory dibs shares out on this machine',
535
603
  ram: "this machine's free memory", oversize: "this machine's free memory", pressure: "this machine's memory pressure",
536
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',
537
607
  ahead: 'a job ahead of it waiting for memory',
538
608
  };
539
609
  // The waits on memory: those may also go to a VM made beside a full boat-1.
@@ -619,9 +689,16 @@ async function fitsElsewhere(need) {
619
689
  // Plain dibs gives other machines 1.5 s (AGENTS.md); a refusal can afford as much.
620
690
  const ELSEWHERE_WAIT = 1500;
621
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
+
622
699
  export async function acquire(o, kind, cfg) {
623
700
  if (o.lease) return ownLease(o.lease, kind);
624
- 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');
625
702
  if (o.prio && !(o.prio in PRIORITY_SHIFT)) die(`priority is one of ${PRIORITIES.join(', ')} (or 1-5)`);
626
703
  if (NEEDS_REASON.has(o.prio) && !o.purpose) die(`${o.prio} priority needs a reason everyone can see: -m "why"`);
627
704
  const id = identity(o);
@@ -632,7 +709,10 @@ export async function acquire(o, kind, cfg) {
632
709
  const hist = history();
633
710
  // Planned at what this command really used last time, when that's more than it asked for.
634
711
  const sent = !!process.env.DIBS_REMOTE_JOB;
635
- const size = { ...sized(jobSize(cfg, res, o), hist, key, cfg), sent, declared: o.mem != null, cpuDeclared: o.cpu != null, ...(o.disk != null && { diskDeclared: true }) };
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 }) };
636
716
  // More than this machine ever hands out, asked for in so many words: it would
637
717
  // wait forever, and as the oldest waiter hold others back. Refused now, unless
638
718
  // an outer run or hold already has the resources (it runs inside what that
@@ -642,8 +722,8 @@ export async function acquire(o, kind, cfg) {
642
722
  const never = !nested && neverFits(cfg, explicitAsk(size));
643
723
  if (never) die(neverText(never, null, cfg, await fitsElsewhere(explicitAsk(size))));
644
724
  if (!nested) capToMachine(cfg, size);
645
- const { mem, cpu, disk, asked, askedCpu, usual } = size;
646
- 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]);
647
727
  // Booked at what it really used, not at its ask: dibs's own bookkeeping, kept
648
728
  // in the history and said to nobody. On 2026-11-03 these were 6 of 35 notices,
649
729
  // and "typecheck used up to 4 cores, pass --cpu 4" came on every merge.
@@ -658,15 +738,17 @@ export async function acquire(o, kind, cfg) {
658
738
 
659
739
  const quotaWrong = quotaProblem(cfg, res, o.cost);
660
740
  if (quotaWrong) die(quotaWrong);
661
- 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)));
662
742
  if (unknown.length)
663
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.`
664
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.`);
665
745
  if (machine().diskFree == null) say("couldn't read free disk space, so the disk check is off for this request.");
666
746
 
667
- const started = now();
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();
668
750
  if (maxWait !== Infinity) setLockDeadline(started + maxWait);
669
- 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(),
670
752
  cwd: process.cwd(), ppid: callerPid(), sstart: id.sstart, size: { mem, cpu, asked, askedCpu, usual }, again: again(), path: o.thin?.fifo,
671
753
  notify: o.notify ? path.resolve(o.notify) : undefined, follow: process.env.DIBS_REMOTE_JOB ? { pid: callerPid(), pstart: pstart(callerPid()) } : undefined }, cfg, hist, stderrOut);
672
754
  // A signal while getting in line is held until there's a place to give up,
@@ -687,16 +769,15 @@ export async function acquire(o, kind, cfg) {
687
769
  // Stamped as looked-at now: a place picked up is decided for again from here on.
688
770
  if (q) { Object.assign(q, { pid, pstart: myStart, keepUntil: null, polledAt: now() }); delete q.wake; delete q.keptFor; }
689
771
  else {
690
- 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(),
691
773
  who: id.who, agent: id.agent, label: id.label, spid: id.spid, purpose: o.purpose || '', cmd, key, kind,
692
- agentId: o.agentId, sessionId: process.env.CLAUDE_CODE_SESSION_ID, cwd: process.cwd(), ppid: callerPid(),
693
- // Its project, for resources one at a time per project (deploys): a job sent from another machine
694
- // carries its sender's (DIBS_REPO, src/worker.mjs), since its copy here has no .git.
695
- 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 };
696
775
  if (outer) q.outer = outer.id;
697
776
  if (sent) q.sent = true; // placed here by the coordinator for its size (neverFits)
698
777
  s.queue.push(q);
699
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; }
700
781
  // A process waits for one thing: any other place under it was left behind, and only holds others back.
701
782
  s.queue = s.queue.filter(x => x === q || !(me(x) || (!x.pid && x.keptFor === pid)));
702
783
  // Without -m, a wait for the rest of what a ship needs says what the ship is for.
@@ -706,17 +787,20 @@ export async function acquire(o, kind, cfg) {
706
787
  if (o.by) q.by = o.by;
707
788
  if (o.est) q.est = o.est;
708
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)
709
791
  if (o.cost != null) q.cost = o.cost;
710
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)
711
794
  if (o.cpu != null) q.cpuDeclared = true; // asked for in so many words, which alone can make it never fit (neverFits)
712
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)
713
797
  return { ...q };
714
798
  });
715
799
  const me = w.me;
716
800
 
717
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}.`);
718
802
 
719
- const bail = sig => { left(w, sig); leave(w, false); process.exit(signalExit(sig)); };
803
+ const bail = sig => { left(w, sig); process.stderr.write(leave(w, true, sig)); process.exit(signalExit(sig)); };
720
804
  for (const sig of SIGNALS) { process.removeListener(sig, hold); process.on(sig, bail); }
721
805
  if (early) bail(early);
722
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 = JSON.parse(fs.readFileSync(FILE, 'utf8')).agents || []; } catch (e) { if (e.code !== 'ENOENT' && !(e instanceof SyntaxError)) throw e; }
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);