@dibssoftware/dibs 0.0.178 → 0.0.180
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 +40 -2
- package/README.md +49 -196
- package/bin/dibs-guard.mjs +10 -1
- package/bin/dibs.mjs +72 -31
- package/docs/benchmarks.md +1 -1
- package/docs/files.md +1 -1
- package/docs/guard.md +6 -0
- package/docs/machines.md +1 -1
- package/docs/questions.md +7 -3
- package/docs/reference.md +157 -0
- package/docs/relay.md +9 -7
- package/docs/releasing.md +11 -8
- package/docs/scheduling.md +6 -6
- package/docs/windows.md +14 -0
- package/package.json +2 -1
- package/skills/dibs/SKILL.md +104 -83
- package/src/acquire.mjs +102 -34
- package/src/agents.mjs +7 -22
- package/src/alerts.mjs +157 -57
- package/src/answers.mjs +2 -2
- package/src/board.mjs +3 -4
- package/src/broker.mjs +26 -11
- package/src/commands.mjs +39 -14
- package/src/config.mjs +27 -6
- package/src/cool.mjs +104 -9
- package/src/diskwarn.mjs +32 -35
- package/src/events.mjs +13 -2
- package/src/files.mjs +52 -67
- package/src/guard.mjs +52 -6
- package/src/guardd.mjs +97 -0
- package/src/guardw.mjs +19 -0
- package/src/hogs.mjs +18 -5
- package/src/later.mjs +20 -25
- package/src/lock.mjs +292 -0
- package/src/measure.mjs +9 -4
- package/src/news.mjs +101 -0
- package/src/notes.mjs +171 -0
- package/src/notices.mjs +52 -13
- package/src/ondemand.mjs +6 -3
- package/src/override.mjs +60 -14
- package/src/plain.mjs +7 -4
- package/src/platform.mjs +165 -35
- package/src/preempt.mjs +54 -6
- package/src/primer.mjs +43 -15
- package/src/proc.mjs +39 -8
- package/src/progress.mjs +33 -4
- package/src/questions.mjs +8 -22
- package/src/relay.mjs +10 -22
- package/src/remote.mjs +12 -8
- package/src/schedule.mjs +182 -44
- package/src/serve.mjs +22 -3
- package/src/service.mjs +4 -3
- package/src/state.mjs +139 -47
- package/src/stats.mjs +3 -2
- package/src/talk.mjs +335 -73
- package/src/trust.mjs +7 -1
- package/src/util.mjs +28 -2
- package/src/version.mjs +1 -1
- package/src/web.mjs +19 -27
- package/src/worker.mjs +2 -1
package/src/schedule.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Who goes next. Pure functions of the state, config, history and clock, so
|
|
2
2
|
// they can be tested without processes.
|
|
3
3
|
import { resCfg, machine, hardware, RECENT, SWAP_WINDOW } from './config.mjs';
|
|
4
|
-
import { bytes, ms, dur, gb, now, runsOf, indexed } from './util.mjs';
|
|
4
|
+
import { bytes, ms, dur, gb, now, runsOf, indexed, unpolled } from './util.mjs';
|
|
5
5
|
import { tag, isMine } from './proc.mjs';
|
|
6
6
|
import { isFiles, overlap, short, clash, coversAgent, elsewhere } from './files.mjs';
|
|
7
7
|
import { poolBlock } from './simpool.mjs';
|
|
@@ -178,6 +178,8 @@ const HOLDING_SHIFT = 10 * MIN;
|
|
|
178
178
|
export function rankParts(q, hist, t = now()) {
|
|
179
179
|
const parts = [];
|
|
180
180
|
const add = (label, shift) => { if (Math.abs(shift) >= 1000) parts.push({ label, shift: Math.round(shift) }); };
|
|
181
|
+
// The quick lane goes to the front of its line, ahead of any priority: it's over in seconds.
|
|
182
|
+
if (q.quickPass) add('quick', QUICK_FRONT);
|
|
181
183
|
add(q.prio, PRIORITY_SHIFT[q.prio] || 0);
|
|
182
184
|
if (q.holding && (!q.prio || q.prio === 'normal')) add(`holds ${q.holding.res.join(',')}`, HOLDING_SHIFT);
|
|
183
185
|
if (q.by) {
|
|
@@ -208,10 +210,17 @@ export const sum = (xs, f) => xs.reduce((a, x) => a + f(x), 0);
|
|
|
208
210
|
// never queue behind yourself. Two subagents of one session are different
|
|
209
211
|
// agents when the guard told dibs which is which (src/files.mjs).
|
|
210
212
|
const covers = (h, x) => (h.kind === 'hold' && !!x.spid && h.pid === x.spid && coversAgent(h, x)) || (!!x.outer && h.id === x.outer);
|
|
211
|
-
|
|
213
|
+
// A hold or outer run is one slot, so it covers one run on each of its resources at a time; a
|
|
214
|
+
// second run alongside the first needs a slot of its own. On 2026-11-10 at 23:44 a session's hold
|
|
215
|
+
// on playwright covered four of its subagents' runs at once, each 5 to 7.5 GB, past slots: 2 and
|
|
216
|
+
// past the memory budget (a covered run is charged nothing): swap reached 13.7 GB and the Mac froze.
|
|
217
|
+
const inside = (s, h, r, not) => s.leases.filter(o => o !== h && o.id !== not && o.covered?.includes(r) && covers(h, o));
|
|
218
|
+
export const holdsOf = (s, me) => new Set(s.leases.filter(l => covers(l, me)).flatMap(l => l.res.filter(r => !inside(s, l, r, me.id).length)));
|
|
212
219
|
// Slots of r in use. A run covered by its own hold or outer run doesn't count
|
|
213
|
-
// twice, but only while that lasts: once it ends, the run is a user again.
|
|
214
|
-
|
|
220
|
+
// twice, but only while that lasts: once it ends, the run is a user again. Of several runs that
|
|
221
|
+
// say they're covered by one hold (a state written before the rule above), only the first is.
|
|
222
|
+
export const coveredNow = (s, l, r) => l.covered?.includes(r)
|
|
223
|
+
&& s.leases.some(h => h !== l && h.res.includes(r) && covers(h, l) && !inside(s, h, r, l.id).some(o => o.id < l.id));
|
|
215
224
|
|
|
216
225
|
// What a waiter already holds while it waits, or null: the dibs run it's
|
|
217
226
|
// nested in, unless that runs at low or idle priority, and its session's holds
|
|
@@ -366,12 +375,36 @@ const usedNow = l => (l.kind === 'run' && l.use?.mem != null ? l.use.mem : plann
|
|
|
366
375
|
export const memOf = (l, t = now()) => {
|
|
367
376
|
const planned = plannedOf(l);
|
|
368
377
|
if (l.kind !== 'run' || l.use?.mem == null) return planned;
|
|
378
|
+
// Stopped, it keeps every byte it had (they go to swap, not back to the machine), and it isn't
|
|
379
|
+
// measured while paused: never the idle discount, always the most it was seen using.
|
|
380
|
+
if (l.pausedAt) return Math.max(planned, l.peak?.mem || 0);
|
|
369
381
|
if (steady(l, t)) return l.idleSince && t - l.idleSince >= IDLE_BOOK ? l.use.mem : l.use.mem + BUSY_MARGIN;
|
|
370
382
|
if (t - l.start - pausedFor(l, t) < BOOK_AFTER) return planned;
|
|
371
383
|
const peak = Math.max(l.peak?.mem || 0, l.use.mem);
|
|
372
384
|
return Math.min(peak + BUSY_MARGIN, Math.max(planned, peak));
|
|
373
385
|
};
|
|
374
386
|
|
|
387
|
+
// How far into a run this command reaches its peak, the latest of its last
|
|
388
|
+
// PEAK_RUNS measured runs, or null when one of them didn't say (recorded before
|
|
389
|
+
// 0.0.180) or none was measured.
|
|
390
|
+
const PEAK_RUNS = 5;
|
|
391
|
+
function peaksBy(hist, key) {
|
|
392
|
+
const runs = runsOf(hist || [], key).filter(h => h.mem > 0).slice(-PEAK_RUNS);
|
|
393
|
+
return runs.length && runs.every(h => h.peakIn != null) ? Math.max(...runs.map(h => h.peakIn)) : null;
|
|
394
|
+
}
|
|
395
|
+
// A measured run that has gone well past where its command's runs peak is done
|
|
396
|
+
// growing into its ask: it books what memOf says, not the ask. On 2026-11-03 an
|
|
397
|
+
// Xcode job booked at 11G, measured at 0.1 GB, held a 6G deploy on "the machine
|
|
398
|
+
// doesn't have the room" for as long as it ran. A command that peaks late (a
|
|
399
|
+
// link, an archive) keeps its ask until then, so its ramp has the room.
|
|
400
|
+
const PEAK_SLACK = 2 * MIN;
|
|
401
|
+
const pastPeak = (l, hist, t) => {
|
|
402
|
+
if (l.kind !== 'run' || l.use?.mem == null || !l.key || !hist) return false;
|
|
403
|
+
const p = peaksBy(hist, l.key);
|
|
404
|
+
return p != null && t - l.start - pausedFor(l, t) > p * 1.25 + PEAK_SLACK;
|
|
405
|
+
};
|
|
406
|
+
export const growTo = (hist, t = now()) => l => (pastPeak(l, hist, t) ? memOf(l, t) : plannedOf(l));
|
|
407
|
+
|
|
375
408
|
// The lease a run sits inside, when its own hold or outer dibs run covers all
|
|
376
409
|
// it asked for, or null.
|
|
377
410
|
const coverOf = (s, l) => (l.covered && l.res.every(r => coveredNow(s, l, r)) ? s.leases.find(h => h !== l && covers(h, l)) || null : null);
|
|
@@ -395,7 +428,10 @@ export function memUsed(s, of = memOf) {
|
|
|
395
428
|
// The leases taking the most memory, biggest first, for a memory wait to name.
|
|
396
429
|
// asked: what it asked for (--mem or its resource's default); use: what its
|
|
397
430
|
// last measurement found, or null before the first.
|
|
398
|
-
|
|
431
|
+
// Ranked by what each one was measured using, where there's a measurement: on 2026-11-03 an
|
|
432
|
+
// 11 GB booking using 0.1 GB took the blame for a pressure wait it wasn't causing.
|
|
433
|
+
const blame = l => l.use?.mem ?? memOf(l);
|
|
434
|
+
export const memHolders = (s, n = 3) => s.leases.filter(l => memOf(l) > 0 && !coverOf(s, l)).sort((a, b) => blame(b) - blame(a)).slice(0, n)
|
|
399
435
|
.map(l => ({ id: l.id, who: l.agent || l.who, label: l.label, purpose: l.purpose || '', mem: memOf(l), asked: l.asked ?? l.mem ?? 0, use: l.use?.mem ?? null, idleSince: l.idleSince || null }));
|
|
400
436
|
|
|
401
437
|
// Memory the OS says is free right now, in bytes, or null.
|
|
@@ -476,7 +512,8 @@ export const cpuUsed = s => Math.round(sum(s.leases.filter(l => !lent(l) && !l.p
|
|
|
476
512
|
const YOUNG = 3 * MIN, REAL_WAIT = 2 * MIN;
|
|
477
513
|
export const swapTaken = m => (swapGrowing(m) ? m.swapGrowth : 0);
|
|
478
514
|
// noSwap: swap growth doesn't count (the stall breaker let it by).
|
|
479
|
-
|
|
515
|
+
// hist: what the running jobs' own runs say about when they peak (growTo); without it, asks stand.
|
|
516
|
+
function overBudget(s, q, cfg, strict = false, noSwap = false, t = now(), hist = null) {
|
|
480
517
|
// A job as big as the whole budget runs when nothing else is.
|
|
481
518
|
if (!othersOf(s, q).length) return null;
|
|
482
519
|
const m = machine();
|
|
@@ -491,7 +528,9 @@ function overBudget(s, q, cfg, strict = false, noSwap = false, t = now()) {
|
|
|
491
528
|
// growing, the job plus a reserve free): it starts. Booking keeps a job's peak
|
|
492
529
|
// for minutes after it falls; on 2026-10-20 twenty jobs waited "blocked by
|
|
493
530
|
// memory" with 8.6 GB free and 1 of 10 cores busy.
|
|
494
|
-
|
|
531
|
+
// A light job can't make the paging worse, so only critical pressure takes the room away from it (as for the swap gate).
|
|
532
|
+
const room = () => ((q.mem || 0) <= LIGHT_MEM && !(m.vmPressure >= 2)) || realRoom(q, cfg, m);
|
|
533
|
+
const fitsUse = () => memUsed(s, usedNow) + swap + q.mem <= budget && room();
|
|
495
534
|
if (mem + q.mem > budget && !fitsUse())
|
|
496
535
|
return { rule: 'memory', used: mem, of: budget, need: q.mem, ...(swap && { swap }),
|
|
497
536
|
why: `memory budget: ${gb(mem)} of ${gb(budget)} handed out or in use${swap ? ` (${gb(swap)} of it swap that grew in the last 5 min)` : ''}, you need ${gb(q.mem)}` };
|
|
@@ -499,7 +538,8 @@ function overBudget(s, q, cfg, strict = false, noSwap = false, t = now()) {
|
|
|
499
538
|
// what they asked for. One of them may still grow into its ask, so the room
|
|
500
539
|
// must be real: memory pressure normal, swap still, and the job plus a
|
|
501
540
|
// reserve free on the machine.
|
|
502
|
-
|
|
541
|
+
// A running job past where its command's runs peak counts at what it books (growTo), not its ask.
|
|
542
|
+
if (memUsed(s, growTo(hist, t)) + swap + q.mem > budget && !room())
|
|
503
543
|
return { rule: 'memory', used: mem, of: budget, need: q.mem, pressure: true, free: realFree(m), reserve: ROOM_RESERVE, high: m.vmPressure >= 1, growing: swapGrowing(m),
|
|
504
544
|
why: `memory: running jobs ask for more than they use, but the machine doesn't have the room to show for it (${realFree(m) == null ? 'free memory unknown' : `${gb(realFree(m))} free`}${m.vmPressure >= 1 ? ', memory pressure high' : ''}${swapGrowing(m) ? ', swap growing' : ''}), you need ${gb(q.mem)} plus ${gb(ROOM_RESERVE)} to spare` };
|
|
505
545
|
// Within the budget, the machine must still have it: what's really available
|
|
@@ -595,7 +635,7 @@ function soonestStart(s, q, cfg, hist, t = now()) {
|
|
|
595
635
|
at = Math.max(at, Math.min(...s.leases.filter(l => l.res.includes(r) && !lent(l, r) && !onTop(l, r) && (across || !byRepo(cfg, r) || laneOf(l) === laneOf(q))).map(l => slotEnd(s, l, hist, t, r))));
|
|
596
636
|
}
|
|
597
637
|
}
|
|
598
|
-
if (overBudget(s, q, cfg)) at = Math.max(at, budgetFrees(s, q, cfg, hist, t));
|
|
638
|
+
if (overBudget(s, q, cfg, false, false, t, hist)) at = Math.max(at, budgetFrees(s, q, cfg, hist, t));
|
|
599
639
|
return at;
|
|
600
640
|
}
|
|
601
641
|
// Whether q's turn at the budget rests only on jobs whose run time dibs knows
|
|
@@ -718,13 +758,8 @@ function clashOf(s, me, hist) {
|
|
|
718
758
|
return null;
|
|
719
759
|
}
|
|
720
760
|
|
|
721
|
-
//
|
|
722
|
-
//
|
|
723
|
-
// machine's memory, disk, load and swap gates still hold. On 2026-10-21 most of
|
|
724
|
-
// the jobs that waited longer than they ran were checks of under a minute that
|
|
725
|
-
// waited tens of seconds for a browser slot. Only on resources whose slots are
|
|
726
|
-
// capacity: never an exclusive one (the shared simulator, deploys, a lock) or a
|
|
727
|
-
// pool that hands each job its own simulator.
|
|
761
|
+
// A run this short (the middle of its runs) is over in seconds: featherweight below. The quick
|
|
762
|
+
// lane (quickPass) goes by cfg.quickUnder, which is 15 s unless set.
|
|
728
763
|
const INSTANT = 15e3;
|
|
729
764
|
// A job over in seconds that has never been seen using much memory: its middle
|
|
730
765
|
// run under INSTANT (or, before dibs has seen it, an --est that short with no --mem
|
|
@@ -733,6 +768,14 @@ const INSTANT = 15e3;
|
|
|
733
768
|
// (2 GB for a test run) doesn't book it past the budget. Critical pressure and
|
|
734
769
|
// the disk floor still do. On 2026-10-23 a 70 ms node --test of one file waited
|
|
735
770
|
// minutes on "memory pressure high" behind a 4 GB Docker build.
|
|
771
|
+
// Light by its own runs: the last ten measured at LIGHT_MEM or less, at least LIGHT_RUNS of them,
|
|
772
|
+
// whatever it asked for. On 2026-11-03 a deploy that asked for 6 GB and used under 0.5 GB waited on
|
|
773
|
+
// memory pressure that an 11 GB Xcode booking using 0.1 GB was blamed for.
|
|
774
|
+
const LIGHT_RUNS = 3;
|
|
775
|
+
export function measuredLight(me, hist) {
|
|
776
|
+
const runs = runsOf(hist, me.key).slice(-10).filter(h => h.mem != null);
|
|
777
|
+
return runs.length >= LIGHT_RUNS && runs.every(h => h.mem <= LIGHT_MEM);
|
|
778
|
+
}
|
|
736
779
|
export function featherweight(me, hist) {
|
|
737
780
|
const d = typical(hist, me.key) ?? (me.declared ? null : me.est);
|
|
738
781
|
if (d == null || d >= INSTANT) return false;
|
|
@@ -753,11 +796,34 @@ export function probation(s, me, cfg, hist, t) {
|
|
|
753
796
|
if (!me.res.every(r => !isFiles(r) && resCfg(cfg, r).pausable === true)) return false;
|
|
754
797
|
return !s.leases.some(l => l.trial);
|
|
755
798
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
799
|
+
// The quick lane (2026-11-03, the person: "let one really really quick thing go instantly ...
|
|
800
|
+
// if it takes under 15 seconds"). A command whose runs here take under quickUnder at the
|
|
801
|
+
// middle, or one run with --quick (or an --est that short) before dibs has seen it, starts at
|
|
802
|
+
// once: past the line, the slots of shared and pool resources, warning memory pressure, swap
|
|
803
|
+
// and the load ceiling. The disk floor, critical pressure, file leases and someone else's hold
|
|
804
|
+
// still hold it, and it never pauses anyone. A run that went over quickUnder takes the pass
|
|
805
|
+
// away from its command until a run comes in under again and the middle is back under.
|
|
806
|
+
// On an exclusive resource it doesn't run alongside: it goes to the front of the line, unless
|
|
807
|
+
// the resource says quickAlongside: "other-repo" (a deploy is one at a time per project) and
|
|
808
|
+
// every job on it is from another repo.
|
|
809
|
+
export const QUICK_MAX = 2; // quick jobs at once, machine-wide: a lane, not a way around dibs
|
|
810
|
+
// What the board says about a job the quick lane let in, so others see why it went first.
|
|
811
|
+
export const QUICK_LINE = 'quick: it runs in seconds, so it went first';
|
|
812
|
+
const QUICK_FRONT = 24 * 36e5;
|
|
813
|
+
export function quickPass(q, hist, cfg) {
|
|
814
|
+
if (q.kind === 'hold' || !q.key || cfg.quickUnder === null) return false;
|
|
815
|
+
const under = ms(cfg.quickUnder ?? '15s');
|
|
816
|
+
const runs = runsOf(hist, q.key);
|
|
817
|
+
if (runs.length && runs.at(-1).dur >= under) return false;
|
|
818
|
+
const d = typical(hist, q.key);
|
|
819
|
+
if (d != null) return d < under;
|
|
820
|
+
// An --est that short counts as --quick, as for featherweight, unless the job asked for memory itself.
|
|
821
|
+
return !!q.quick || (q.est != null && q.est < under && !q.declared);
|
|
760
822
|
}
|
|
823
|
+
// Every job on r is another repo's, so a quick one may start beside them (quickAlongside).
|
|
824
|
+
const otherRepos = (s, me, r) => !!me.repo && s.leases.filter(l => l.res.includes(r)).every(l => l.repo && l.repo !== me.repo);
|
|
825
|
+
// A hold on r by someone else: the quick lane never goes past it.
|
|
826
|
+
const heldByOther = (s, mine, r) => !mine.has(r) && s.leases.some(l => l.kind === 'hold' && l.res.includes(r));
|
|
761
827
|
|
|
762
828
|
// Can this waiter start now? If not: the rule that stops it (slot, ahead,
|
|
763
829
|
// reset, disk, pressure, swap, swaproom, drain, memory, cpu, ram, load, idle), a sentence, and what it's stuck on.
|
|
@@ -779,7 +845,9 @@ function ownDisk(hist, key) {
|
|
|
779
845
|
// A --disk given in so many words is the job's own: on 2026-10-26 a streaming loader that writes one
|
|
780
846
|
// 12 MB chunk was held for 23 GB it had "eaten" on a run whose swap grew while it sat paused.
|
|
781
847
|
export function diskNeed(s, me, cfg, hist) {
|
|
782
|
-
const floor =
|
|
848
|
+
const floor = floorFor(me, cfg);
|
|
849
|
+
// A job that writes next to nothing keeps only ALONE_ROOM free, under the floor (tinyDisk).
|
|
850
|
+
if (tinyDisk(me, hist, cfg)) return { need: (me.diskDeclared ? me.disk || 0 : 0) + ALONE_ROOM, ate: null, others: othersOf(s, me).length > 0, tiny: true };
|
|
783
851
|
// With others running, a resource that declares disk (simulators, builds, browsers, heavy) also
|
|
784
852
|
// counts what its kind of job usually eats. Alone, or on a resource that declares none, the
|
|
785
853
|
// job's own runs still count: starting a job that always eats more than there is only fails it.
|
|
@@ -795,7 +863,60 @@ export function diskNeed(s, me, cfg, hist) {
|
|
|
795
863
|
return { need: Math.max(learned ?? me.disk ?? 0, floor, ate != null ? ate + (others ? floor : ALONE_ROOM) : 0), ate, others };
|
|
796
864
|
}
|
|
797
865
|
// A job alone still leaves this much free past what it eats: the system writes while it runs too.
|
|
798
|
-
const ALONE_ROOM = 1024 ** 3;
|
|
866
|
+
export const ALONE_ROOM = 1024 ** 3;
|
|
867
|
+
|
|
868
|
+
// A job the person is waiting on (high, urgent, or a --by deadline with its reason) may take the headroom
|
|
869
|
+
// down to this, the same hard floor the watcher pauses jobs at (src/preempt.mjs DISK_FLOOR),
|
|
870
|
+
// and isn't held for the room kept for swap. On 2026-11-02 and 03 a Shop ship
|
|
871
|
+
// (#18328) waited about a day while idle sessions' swap kept free disk under 9 GB.
|
|
872
|
+
const HARD_FLOOR = 3 * 1024 ** 3;
|
|
873
|
+
// A --by deadline counts only with its reason (-m): a bare one costs nothing to type.
|
|
874
|
+
export const waitedOn = q => q.prio === 'high' || q.prio === 'urgent' || (q.by != null && !!q.purpose);
|
|
875
|
+
const floorFor = (q, cfg) => (waitedOn(q) ? Math.min(bytes(cfg.minDisk), HARD_FLOOR) : bytes(cfg.minDisk));
|
|
876
|
+
|
|
877
|
+
// A job that eats less than this of the disk starts under minDisk: holding it back
|
|
878
|
+
// frees nothing. On 2026-11-02 and 03 a post-deploy check that only makes HTTP calls,
|
|
879
|
+
// a test suite that writes nothing (--disk 200M) and a later job that uploads a 100 MB
|
|
880
|
+
// archive were all refused (exit 74) with 4.4 to 5 GB free, and a prod build went out unchecked.
|
|
881
|
+
export const TINY_DISK = 100 * 1024 ** 2;
|
|
882
|
+
// Whether a job is that small. Its own runs say first: at least TINY_RUNS good ones, the
|
|
883
|
+
// middle of the last ten (the most of them until there are DISK_RUNS) under TINY_DISK, and
|
|
884
|
+
// the last run, failed or not, under it too: one that ate more takes the exemption away
|
|
885
|
+
// until it's back down. A failed run alone, stopped early, says nothing about what a whole
|
|
886
|
+
// one eats. With too few runs, only a small --disk does (diskNeed takes it at its word).
|
|
887
|
+
export function tinyDisk(me, hist, cfg) {
|
|
888
|
+
// A --disk of minDisk or more says it isn't small, whatever its resource.
|
|
889
|
+
if (me.diskDeclared && (me.disk || 0) >= bytes(cfg.minDisk)) return false;
|
|
890
|
+
// A run the watcher cleared caches under reads low: the clean's room hid what it wrote (src/diskwarn.mjs clean).
|
|
891
|
+
const runs = runsOf(hist || [], me.key).filter(h => h.ate != null && !h.cleaned).slice(-10);
|
|
892
|
+
if (runs.length && runs.at(-1).ate >= TINY_DISK) return false;
|
|
893
|
+
const good = runs.filter(h => !h.failed).map(h => h.ate);
|
|
894
|
+
if (good.length >= TINY_RUNS) return (good.length < DISK_RUNS ? Math.max(...good) : mid(good)) < TINY_DISK;
|
|
895
|
+
// Too few runs to go by: only its own word makes it small. A first npm ci or a bundling deploy
|
|
896
|
+
// writes gigabytes, so a resource's kind alone never does. Up to CLAIM_MAX on a resource that
|
|
897
|
+
// declares no disk (tests, deploys, locks), or under TINY_DISK anywhere.
|
|
898
|
+
if (!me.diskDeclared) return false;
|
|
899
|
+
const claim = me.disk || 0;
|
|
900
|
+
return claim < TINY_DISK || (claim <= CLAIM_MAX && me.res.every(r => isFiles(r) || !resCfg(cfg, r).disk));
|
|
901
|
+
}
|
|
902
|
+
// Why a job held at the floor is held there, and, when its --disk is smaller, why that didn't
|
|
903
|
+
// lower it: agents read --disk 1G as the floor's size, and a deploy hit exit 74 twice at 2.6 GB
|
|
904
|
+
// free on 2026-11-10 with --disk 1G.
|
|
905
|
+
const GBs = b => gb(b).replace(/G$/, ' GB');
|
|
906
|
+
export function floorWhy(me, cfg) {
|
|
907
|
+
const floor = floorFor(me, cfg);
|
|
908
|
+
const base = `the ${GBs(floor)} dibs keeps free${waitedOn(me) && floor < bytes(cfg.minDisk) ? ' for a job a person waits on' : ''}`;
|
|
909
|
+
if (!me.diskDeclared || (me.disk || 0) >= floor) return base;
|
|
910
|
+
const little = me.res.every(r => isFiles(r) || !resCfg(cfg, r).disk);
|
|
911
|
+
return `${base}; --disk ${GBs(me.disk || 0)} doesn't lower that: only a --disk ${little ? 'of 1 GB or less' : 'under 100 MB'}`
|
|
912
|
+
+ ` starts a job below it, or two runs of the same command that each wrote under 100 MB`;
|
|
913
|
+
}
|
|
914
|
+
// Runs it takes to be small by history alone: one could be a run that happened to write little.
|
|
915
|
+
const TINY_RUNS = 2;
|
|
916
|
+
// The most a --disk alone can claim on a resource that declares no disk, itself included: agents
|
|
917
|
+
// write --disk 1G, and a deploy that said so waited out 2.6 GB free twice on 2026-11-10. On
|
|
918
|
+
// 2026-11-03 a test suite that writes nothing said --disk 200M and was refused at 4.4 GB free.
|
|
919
|
+
const CLAIM_MAX = 1024 ** 3;
|
|
799
920
|
|
|
800
921
|
// The verdict, and for a job held by something else (its turn, memory, cores) a
|
|
801
922
|
// word that free disk will hold it next, while there's still time to free some.
|
|
@@ -811,7 +932,11 @@ export function verdict(s, me, cfg, hist, t = now()) {
|
|
|
811
932
|
}
|
|
812
933
|
|
|
813
934
|
function decide(s, me, cfg, hist, t) {
|
|
814
|
-
|
|
935
|
+
// In the quick lane while there's room in it; the cap counts quick jobs running now.
|
|
936
|
+
const quick = !!(me.quickPass ?? quickPass(me, hist, cfg)) && s.leases.filter(l => l.quick).length < QUICK_MAX;
|
|
937
|
+
// A quick job dibs hasn't seen use much memory is booked small, as a featherweight is.
|
|
938
|
+
const lightQuick = quick && !me.declared && runsOf(hist, me.key).slice(-10).every(h => h.mem == null || h.mem <= LIGHT_MEM);
|
|
939
|
+
if ((me.mem || 0) > LIGHT_MEM && (featherweight(me, hist) || lightQuick || measuredLight(me, hist))) me = { ...me, mem: LIGHT_MEM, feather: true };
|
|
815
940
|
const myRank = rank(me, hist, t);
|
|
816
941
|
// When it would be done, at its slow runs: passing a waiter is a promise not to delay it.
|
|
817
942
|
const myEnd = t + Math.max(expected(me, hist), slow(hist, me.key) || 0);
|
|
@@ -825,10 +950,13 @@ function decide(s, me, cfg, hist, t) {
|
|
|
825
950
|
// don't hold it (over minDisk, it goes). On 2026-10-21 0.5 GB deploys waited 79 and 92 s
|
|
826
951
|
// on the room kept for swap, and one waited 9 minutes on load.
|
|
827
952
|
const lightTurn = (me.mem || 0) <= LIGHT_MEM && me.res.every(r => cfg.resources[r]?.exclusive);
|
|
828
|
-
const pastCeiling = pastsCeiling(me) ||
|
|
953
|
+
const pastCeiling = pastsCeiling(me) || quick || lightTurn;
|
|
829
954
|
// Over the ceiling, a waiter that passes it doesn't wait behind ones the ceiling holds back.
|
|
955
|
+
// Nor behind a place nobody is deciding for (its dibs stopped looking), or one the owner stopped:
|
|
956
|
+
// neither can start, so neither holds anyone back. Just after the machine wakes (graceUntil,
|
|
957
|
+
// src/state.mjs) every place is old, so none is taken for one nobody decides for.
|
|
830
958
|
const ahead = s.queue
|
|
831
|
-
.filter(q => q.pid && q.id !== me.id && !(hot && pastCeiling && !pastsCeiling(q)))
|
|
959
|
+
.filter(q => q.pid && q.id !== me.id && !q.ownerStop && !(unpolled(q, t) && !(s.graceUntil > t)) && !(hot && pastCeiling && !pastsCeiling(q)))
|
|
832
960
|
.filter(q => { const r = rank(q, hist, t); return r < myRank || (r === myRank && q.id < me.id); })
|
|
833
961
|
.filter(q => reservesFor(s, q, me, cfg))
|
|
834
962
|
.sort(byRank(hist, t));
|
|
@@ -838,18 +966,17 @@ function decide(s, me, cfg, hist, t) {
|
|
|
838
966
|
// whole heavy line. It keeps its place, and once the disk has room for it,
|
|
839
967
|
// it's ahead of everyone again. A job that would eat into that room waits.
|
|
840
968
|
const floor = bytes(cfg.minDisk);
|
|
841
|
-
const diskStuck = q => m.diskFree != null && m.diskFree < Math.max(q.disk || 0, floor);
|
|
969
|
+
const diskStuck = q => m.diskFree != null && m.diskFree < (tinyDisk(q, hist, cfg) ? (q.diskDeclared ? q.disk || 0 : 0) + ALONE_ROOM : Math.max(q.disk || 0, floor));
|
|
842
970
|
const leavesRoom = m.diskFree != null && m.diskFree - floor >= (me.disk || 0);
|
|
843
971
|
const blocks = q => {
|
|
844
972
|
if (leavesRoom && diskStuck(q)) return false;
|
|
845
973
|
// A waiter held for memory blocks a job of known length only when its own start is known, and comes first.
|
|
846
|
-
if (known(me, hist) && overBudget(s, q, cfg) && !budgetSure(s, q, cfg, hist, t)) return false;
|
|
974
|
+
if (known(me, hist) && overBudget(s, q, cfg, false, false, t, hist) && !budgetSure(s, q, cfg, hist, t)) return false;
|
|
847
975
|
const at = soonestStart(s, q, cfg, hist, t);
|
|
848
976
|
if (q.mem >= BIG_SHARE * bytes(cfg.budget) && at - t > RESERVE_SOON) return false;
|
|
849
977
|
return at < myEnd;
|
|
850
978
|
};
|
|
851
979
|
const side = [];
|
|
852
|
-
const quick = instant(me, cfg, hist);
|
|
853
980
|
for (const r of me.res) {
|
|
854
981
|
if (mine.has(r)) continue;
|
|
855
982
|
if (isFiles(r)) {
|
|
@@ -857,7 +984,9 @@ function decide(s, me, cfg, hist, t) {
|
|
|
857
984
|
if (f) return f;
|
|
858
985
|
continue;
|
|
859
986
|
}
|
|
860
|
-
|
|
987
|
+
// A resource's own config: a name dibs doesn't know takes cfg.unknown's exclusive, which resCfg mixes into every one.
|
|
988
|
+
const own = cfg.resources[r];
|
|
989
|
+
if (quick && own && !heldByOther(s, mine, r) && (!own.exclusive || (own.quickAlongside === 'other-repo' && otherRepos(s, me, r)))) continue;
|
|
861
990
|
const { open, across } = roomFor(s, me, r, cfg);
|
|
862
991
|
if (open <= 0) {
|
|
863
992
|
// Full, but the machine may have room for one more on top (src/overlap.mjs).
|
|
@@ -874,7 +1003,7 @@ function decide(s, me, cfg, hist, t) {
|
|
|
874
1003
|
// Learned clashes: a job that runs SLOW_PAIR times as slow beside one running now, or
|
|
875
1004
|
// makes it that slow, waits for it, but no longer than its own run time since it
|
|
876
1005
|
// joined, so it can't starve. Both finish sooner one after the other.
|
|
877
|
-
const pair = t - me.enq < expected(me, hist) && clashOf(s, me, hist);
|
|
1006
|
+
const pair = !quick && t - me.enq < expected(me, hist) && clashOf(s, me, hist);
|
|
878
1007
|
if (pair) return { ok: false, rule: 'together', why: pair.why, on: pair.res, ahead: pair.lease };
|
|
879
1008
|
// The last user's onRelease is still putting it back (src/reset.mjs).
|
|
880
1009
|
const reset = (s.resets || []).find(x => me.res.includes(x.res) && !mine.has(x.res));
|
|
@@ -886,14 +1015,17 @@ function decide(s, me, cfg, hist, t) {
|
|
|
886
1015
|
// checking the disk again refused (exit 74) a run right after "you already have the
|
|
887
1016
|
// simulator, so you go ahead" (2026-11-03). The watcher's low-disk pauses still hold it.
|
|
888
1017
|
if (me.res.every(r => mine.has(r))) return { ok: true, covered: [...me.res] };
|
|
889
|
-
// Below minDisk nothing else starts, urgent work included
|
|
890
|
-
// a full disk breaks every job on the machine, and on macOS swap needs it too.
|
|
1018
|
+
// Below minDisk nothing else starts, urgent work included, but a job that writes next to
|
|
1019
|
+
// nothing (tinyDisk): a full disk breaks every job on the machine, and on macOS swap needs it too.
|
|
891
1020
|
const others = othersOf(s, me);
|
|
892
1021
|
// The floor plus what it usually eats (diskNeed).
|
|
893
|
-
const { need: needDisk, ate, others: crowded } = diskNeed(s, me, cfg, hist);
|
|
1022
|
+
const { need: needDisk, ate, others: crowded, tiny } = diskNeed(s, me, cfg, hist);
|
|
894
1023
|
// An unreadable disk (null) doesn't stop work; the board and dibs run say it's unknown.
|
|
895
|
-
if (m.diskFree != null && m.diskFree < needDisk)
|
|
896
|
-
|
|
1024
|
+
if (m.diskFree != null && m.diskFree < needDisk) {
|
|
1025
|
+
const floored = !tiny && needDisk === floorFor(me, cfg) && floorWhy(me, cfg);
|
|
1026
|
+
if (floored) return { ok: false, rule: 'disk', why: `disk: ${gb(m.diskFree)} free, you need ${gb(needDisk)} (${floored})`, disk: true, free: m.diskFree, need: needDisk, floorWhy: floored };
|
|
1027
|
+
return { ok: false, rule: 'disk', why: `disk: ${gb(m.diskFree)} free, you need ${gb(needDisk)}${tiny ? (me.diskDeclared ? ` (the ${gb(me.disk || 0)} its --disk says, and ${gb(ALONE_ROOM)} kept free)` : ` (a job that writes next to nothing still leaves ${gb(ALONE_ROOM)} free)`) : ate != null && ate + (crowded ? floorFor(me, cfg) : ALONE_ROOM) >= needDisk ? ` (${crowded ? `the ${gb(floorFor(me, cfg))} dibs keeps free` : `${gb(ALONE_ROOM)} to spare`}, plus the ${gb(ate)} this usually takes; --disk <size> says this run needs less)` : ''}`, disk: true, free: m.diskFree, need: needDisk, ...(ate != null && { usual: ate }) };
|
|
1028
|
+
}
|
|
897
1029
|
// While the machine swaps, only urgent work starts on top of what's running.
|
|
898
1030
|
// With nothing else working, one job may start: waiting can't make the swap
|
|
899
1031
|
// go down then, and swap the OS hasn't reclaimed yet mustn't stop dibs for good.
|
|
@@ -905,37 +1037,43 @@ function decide(s, me, cfg, hist, t) {
|
|
|
905
1037
|
let sw = (me.prio || 'normal') !== 'urgent' && busy && swapping(cfg, m);
|
|
906
1038
|
let trial = false;
|
|
907
1039
|
if (sw && sw.level !== 'critical' && !light && sw.rule === 'pressure' && probation(s, me, cfg, hist, t)) trial = true;
|
|
908
|
-
if (sw && (light || trial) && sw.level !== 'critical') sw = null;
|
|
1040
|
+
if (sw && (light || trial || quick) && sw.level !== 'critical') sw = null;
|
|
909
1041
|
// The same for the disk swap grows on: one job may still start alone, since waiting frees nothing then.
|
|
1042
|
+
// Swap grows with memory, not with what a job writes, so a job let under the floor (tinyDisk) keeps the room past the floor.
|
|
910
1043
|
// A light job can't grow the swap, so on a resource that writes little (exclusive, or declaring
|
|
911
1044
|
// no disk: tests, deploys) only the floor holds it. On 2026-10-26 every start waited on the room
|
|
912
1045
|
// kept for swap with 6.8 GB free, one-second test runs included.
|
|
913
1046
|
const writesLittle = me.res.every(r => cfg.resources[r]?.exclusive || !resCfg(cfg, r).disk);
|
|
914
|
-
const squeeze = (me
|
|
1047
|
+
const squeeze = !waitedOn(me) && busy && !sw && !quick && !(light && writesLittle) && diskSqueeze(cfg, tiny ? Math.max(needDisk, bytes(cfg.minDisk)) : needDisk, m);
|
|
915
1048
|
let breaker = (sw || squeeze) && breaksStall(s, me, cfg, hist, t, m);
|
|
916
1049
|
if (sw && !breaker) return { ok: false, why: swapWhy(sw), ...sw, machine: true };
|
|
917
1050
|
if (squeeze && !breaker) return { ok: false, ...squeeze, machine: true };
|
|
918
1051
|
// A light job may pass one stuck on the budget, but not once that one has
|
|
919
1052
|
// waited long, unless it'll be done before that one could start. Waiters
|
|
920
1053
|
// stuck on something else (machine memory, disk) don't hold anyone up.
|
|
921
|
-
const head = ahead.find(q => q.res.every(r => roomFor(s, q, r, cfg).open > 0) && !neverFits(cfg, q) && overBudget(s, q, cfg));
|
|
922
|
-
if (head && t - head.enq > ms(cfg.starveAfter) && blocks(head))
|
|
1054
|
+
const head = ahead.find(q => q.res.every(r => roomFor(s, q, r, cfg).open > 0) && !neverFits(cfg, q) && overBudget(s, q, cfg, false, false, t, hist));
|
|
1055
|
+
if (!quick && head && t - head.enq > ms(cfg.starveAfter) && blocks(head))
|
|
923
1056
|
return { ok: false, rule: 'ahead', why: `${tag(head)} has waited ${dur(t - head.enq)}, so it goes first`, ahead: head, starved: true };
|
|
924
|
-
let budget = overBudget(s, me, cfg, side.length > 0, breaker, t);
|
|
1057
|
+
let budget = overBudget(s, me, cfg, side.length > 0, breaker, t, hist);
|
|
925
1058
|
// Nothing starts past the memory budget (0.0.125). Jobs book what they're
|
|
926
1059
|
// measured using once they've run a few minutes (memOf), so the gap between
|
|
927
1060
|
// asks and use goes to waiters that way, with the machine's pressure as the guard.
|
|
928
1061
|
// Held only by swap growth, the budget is a machine gate like swap itself: the stall breaker may pass it.
|
|
929
|
-
const swapOnly = budget?.swap && !overBudget(s, me, cfg, side.length > 0, true);
|
|
1062
|
+
const swapOnly = budget?.swap && !overBudget(s, me, cfg, side.length > 0, true, t, hist);
|
|
930
1063
|
if (swapOnly && breaksStall(s, me, cfg, hist, t, m)) { budget = null; breaker = true; }
|
|
1064
|
+
// A quick job booked as a featherweight is done before the budget it would pass means
|
|
1065
|
+
// anything; the machine's own pressure still holds it at critical. On 2026-11-03 a
|
|
1066
|
+
// test whose last run took 14.9 s at 95 MB waited 29 minutes on the budget, then ran in 0.8 s (#18336).
|
|
1067
|
+
if (budget && quick && me.feather) budget = null;
|
|
931
1068
|
if (budget) return { ok: false, ...budget, ...(swapOnly && { machine: true }) };
|
|
932
1069
|
if (me.mem >= BIG_JOB && m.memFree < cfg.minFreeMem && s.leases.some(working) && !breaker)
|
|
933
1070
|
return { ok: false, rule: 'ram', why: `machine memory: ${m.memFree}% free, big jobs need ${cfg.minFreeMem}%` };
|
|
934
1071
|
// Stopped last time for using far more than it booked (src/preempt.mjs diskRequeue):
|
|
935
1072
|
// it starts again only once what it's now booked at is really free and swap
|
|
936
1073
|
// has stopped growing, or it would land in the same crunch.
|
|
937
|
-
|
|
938
|
-
|
|
1074
|
+
// Stopped under memory pressure that pausing couldn't ease (pressureRequeue): the same.
|
|
1075
|
+
if ((me.requeued === 'over' || me.requeued === 'memory') && ((realFree(m) ?? 0) < me.mem || swapGrowing(m)))
|
|
1076
|
+
return { ok: false, rule: 'oversize', machine: true, why: `${gb(me.mem)} of memory to be really free and swap to hold still, since ${me.requeued === 'over' ? 'it used far more than it booked last time' : 'memory pressure stopped it last time'}`
|
|
939
1077
|
+ ` (now ${gb(realFree(m) ?? 0)} free${swapGrowing(m) ? ', swap growing' : ''})` };
|
|
940
1078
|
const pool = poolBlock(s, me, cfg, mine, m);
|
|
941
1079
|
if (pool) return { ok: false, ...pool };
|
|
@@ -951,7 +1089,7 @@ function decide(s, me, cfg, hist, t) {
|
|
|
951
1089
|
if ((me.prio || 'normal') === 'idle') {
|
|
952
1090
|
if (m.memFree < IDLE_MEM_FREE) return { ok: false, rule: 'idle', why: `idle work waits for ${IDLE_MEM_FREE}% memory free (now ${m.memFree}%)` };
|
|
953
1091
|
}
|
|
954
|
-
return { ok: true, covered: me.res.filter(r => mine.has(r)), ...(quick && {
|
|
1092
|
+
return { ok: true, covered: me.res.filter(r => mine.has(r)), ...(quick && { quick: true }), ...(trial && { trial: true }), ...(side.length && { alongside: merge(side) }), ...(breaker && { breaker: true }), ...(loadPast && { loadPast: true, loadWaited: t - since }),
|
|
955
1093
|
...(!breaker && (me.prio || 'normal') !== 'urgent' && { gated: true }) };
|
|
956
1094
|
}
|
|
957
1095
|
|
package/src/serve.mjs
CHANGED
|
@@ -103,6 +103,12 @@ export function place(workers, need, t = now()) {
|
|
|
103
103
|
const bad = fits(w, need, t);
|
|
104
104
|
// A VM that can't be found (src/ondemand.mjs findVm) is said plainly, and the job runs where it came from.
|
|
105
105
|
if (bad && w.ondemand?.problem && need.from) return { machine: need.from, why: `${bad}, so it runs here` };
|
|
106
|
+
// One already marked can't-wake (boat's starts used up) sends the job back the way a refused wake
|
|
107
|
+
// does. Refused here instead, a send that came just after the coordinator's own check of boat's
|
|
108
|
+
// limits exited 2, while one just before it ran on its sender (2026-11-03).
|
|
109
|
+
const no = cantWake(w.ondemand, t);
|
|
110
|
+
if (bad && no && bad.startsWith(`${w.name} can't wake`) && need.from)
|
|
111
|
+
return { machine: need.from, why: `${w.name} can't wake (${no.why}), so it runs on ${need.from}` };
|
|
106
112
|
// Too big for it: a VM made for the job (src/ondemand.mjs create), when that's on.
|
|
107
113
|
const big = w.ondemand?.bigger && workers.get(w.ondemand.bigger);
|
|
108
114
|
const short = bad || ((need.askedCpu || 0) > w.cores && `${w.name} has fewer cores than the job asked for`);
|
|
@@ -134,6 +140,18 @@ export function place(workers, need, t = now()) {
|
|
|
134
140
|
// The Tailscale address of this machine. Ask Tailscale itself when its CLI is
|
|
135
141
|
// around; otherwise a 100.64.0.0/10 address on a tunnel interface. That range
|
|
136
142
|
// alone isn't enough: carrier-grade NAT and some hotspots use it too.
|
|
143
|
+
// A log line said once for as long as it stays the same, per key: the Tailscale
|
|
144
|
+
// address is tried every 30 s, and on 2026-11-10 failed all day (EADDRNOTAVAIL),
|
|
145
|
+
// one line each time. null clears the key, so the next failure is said again.
|
|
146
|
+
export function oncePerChange(log) {
|
|
147
|
+
const last = new Map();
|
|
148
|
+
return (key, line) => {
|
|
149
|
+
if (line == null) return last.delete(key);
|
|
150
|
+
if (last.get(key) !== line) log(line);
|
|
151
|
+
last.set(key, line);
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
137
155
|
function tailscaleIp() {
|
|
138
156
|
for (const cli of TS_CLI) {
|
|
139
157
|
try {
|
|
@@ -686,14 +704,15 @@ export async function serve(o) {
|
|
|
686
704
|
const addrs = () => [...listening.keys()].filter(h => h !== '127.0.0.1').map(h => `http://${h}:${port}`);
|
|
687
705
|
try { made = makeServer({ token: rc.token, log, self: rc.name, joinUrl, port, addrs }); } catch (e) { die(e.message); }
|
|
688
706
|
const { server } = made;
|
|
707
|
+
const first = o.bind || '127.0.0.1';
|
|
708
|
+
const failed = oncePerChange(log);
|
|
689
709
|
const listen = host => new Promise(resolve => {
|
|
690
710
|
if (listening.has(host)) return resolve(true);
|
|
691
711
|
const s = server();
|
|
692
|
-
s.once('error', e => {
|
|
693
|
-
s.listen(port, host, () => { listening.set(host, s); resolve(true); });
|
|
712
|
+
s.once('error', e => { failed(host, `can't listen on ${host}:${port}: ${e.message}${host === first ? '' : '. Trying again every 30 s, quietly'}`); resolve(false); });
|
|
713
|
+
s.listen(port, host, () => { failed(host, null); listening.set(host, s); resolve(true); });
|
|
694
714
|
});
|
|
695
715
|
const up = host => log(`listening on http://${host}:${port}`);
|
|
696
|
-
const first = o.bind || '127.0.0.1';
|
|
697
716
|
if (!await listen(first)) die(o.bind ? `can't listen on ${o.bind}:${port}` : `port ${port} is taken. Is a coordinator already running? (dibs machines)`);
|
|
698
717
|
// "listening" comes after remote.json is saved: whatever waits for the line
|
|
699
718
|
// and then reads the file (a test on 2026-10-16) found it missing.
|
package/src/service.mjs
CHANGED
|
@@ -20,9 +20,10 @@ const KINDS = {
|
|
|
20
20
|
throttle: { args: ['throttle', '--watch'], what: 'moves hot work outside dibs to background priority' },
|
|
21
21
|
web: { args: ['web'], what: 'the page and MCP server showing your agents\' work' },
|
|
22
22
|
relay: { args: ['relay'], what: 'reach the page from any browser through the encrypted relay (dibs pair --remote)' },
|
|
23
|
+
guard: { args: ['guard', 'serve'], what: 'answers the Claude Code hook without starting Node for every tool call' },
|
|
23
24
|
};
|
|
24
25
|
// Things started by hand before the service existed; stopped so the service can take over.
|
|
25
|
-
const PIDFILES = { worker: 'worker.pid', throttle: 'cool.pid' };
|
|
26
|
+
const PIDFILES = { worker: 'worker.pid', throttle: 'cool.pid', guard: 'guard.pid' };
|
|
26
27
|
|
|
27
28
|
const label = k => `dev.dibs.${k}`;
|
|
28
29
|
// DIBS_LAUNCH_AGENTS and DIBS_LAUNCHCTL stand in for ~/Library/LaunchAgents and launchctl in tests.
|
|
@@ -88,7 +89,7 @@ function install(k) {
|
|
|
88
89
|
if (PIDFILES[k]) stopManual(k);
|
|
89
90
|
if (OS === 'macos') {
|
|
90
91
|
// Jobs a worker runs inherit its scheduling class, so it can't be Background.
|
|
91
|
-
const type = { serve: 'Standard', worker: 'Interactive', throttle: 'Background', web: 'Standard', relay: 'Standard' }[k];
|
|
92
|
+
const type = { serve: 'Standard', worker: 'Interactive', throttle: 'Background', web: 'Standard', relay: 'Standard', guard: 'Interactive' }[k];
|
|
92
93
|
fs.mkdirSync(path.dirname(plist(k)), { recursive: true });
|
|
93
94
|
fs.writeFileSync(plist(k), `<?xml version="1.0" encoding="UTF-8"?>
|
|
94
95
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
@@ -210,7 +211,7 @@ export async function service(args) {
|
|
|
210
211
|
if (kinds.includes('relay')) { const s = await relayStatus(); if (s) console.log(` relay: ${s}`); }
|
|
211
212
|
return;
|
|
212
213
|
}
|
|
213
|
-
if (!kinds.length) die(`which? dibs service ${action} serve|worker|throttle|web|relay (several at once is fine)`);
|
|
214
|
+
if (!kinds.length) die(`which? dibs service ${action} serve|worker|throttle|web|relay|guard (several at once is fine)`);
|
|
214
215
|
// A service runs for weeks and listens on the network: not on a Node with a known hole.
|
|
215
216
|
const hole = action === 'install' && !process.env.DIBS_ALLOW_UNPATCHED && unpatched();
|
|
216
217
|
if (hole) die(`${hole}. The service would run on that Node (${process.execPath}): put a fixed one first on your PATH and run this again.`);
|