@dibssoftware/dibs 0.0.0-stage → 0.0.178
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 +577 -0
- package/LICENSE +670 -0
- package/README.md +234 -2
- package/bin/dibs-guard.mjs +7 -0
- package/bin/dibs.mjs +526 -0
- package/docs/benchmarks.md +193 -0
- package/docs/files.md +30 -0
- package/docs/guard.md +91 -0
- package/docs/later.md +43 -0
- package/docs/machines.md +147 -0
- package/docs/questions.md +78 -0
- package/docs/relay.md +196 -0
- package/docs/releasing.md +25 -0
- package/docs/scheduling.md +163 -0
- package/docs/simulators.md +17 -0
- package/package.json +44 -4
- package/skills/dibs/SKILL.md +162 -0
- package/src/acquire.mjs +697 -0
- package/src/admin.mjs +145 -0
- package/src/agents.mjs +145 -0
- package/src/alerts.mjs +437 -0
- package/src/answers.mjs +65 -0
- package/src/board.mjs +202 -0
- package/src/broker.mjs +369 -0
- package/src/commands.mjs +801 -0
- package/src/config.mjs +320 -0
- package/src/connect.mjs +106 -0
- package/src/cool.mjs +160 -0
- package/src/diskwarn.mjs +161 -0
- package/src/events.mjs +94 -0
- package/src/files.mjs +1100 -0
- package/src/guard.mjs +583 -0
- package/src/history.mjs +247 -0
- package/src/hogs.mjs +214 -0
- package/src/later.mjs +487 -0
- package/src/measure.mjs +262 -0
- package/src/nodecheck.mjs +17 -0
- package/src/notices.mjs +121 -0
- package/src/ondemand.mjs +572 -0
- package/src/overlap.mjs +151 -0
- package/src/override.mjs +351 -0
- package/src/owner.mjs +30 -0
- package/src/plain.mjs +467 -0
- package/src/platform.mjs +357 -0
- package/src/preempt.mjs +438 -0
- package/src/primer.mjs +61 -0
- package/src/proc.mjs +98 -0
- package/src/progress.mjs +158 -0
- package/src/qr.mjs +204 -0
- package/src/questions.mjs +389 -0
- package/src/quota.mjs +81 -0
- package/src/reads.mjs +54 -0
- package/src/relay.mjs +779 -0
- package/src/remote.mjs +584 -0
- package/src/reset.mjs +127 -0
- package/src/schedule.mjs +995 -0
- package/src/scratch.mjs +61 -0
- package/src/serve.mjs +736 -0
- package/src/service.mjs +221 -0
- package/src/shard.mjs +59 -0
- package/src/simctl.mjs +42 -0
- package/src/simpool.mjs +258 -0
- package/src/state.mjs +201 -0
- package/src/stats.mjs +328 -0
- package/src/style.mjs +44 -0
- package/src/talk.mjs +523 -0
- package/src/thin.sh +130 -0
- package/src/trust.mjs +152 -0
- package/src/util.mjs +184 -0
- package/src/version.mjs +2 -0
- package/src/web.mjs +1117 -0
- package/src/worker.mjs +318 -0
package/src/preempt.mjs
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
// Pausing low-priority work instead of making urgent work wait for it.
|
|
2
|
+
//
|
|
3
|
+
// Two things pause a run lease's whole process tree (SIGSTOP on every process
|
|
4
|
+
// group it's spread over) without ending it:
|
|
5
|
+
// - An urgent or high waiter that a low or idle lease is in the way of. The
|
|
6
|
+
// paused lease lends that waiter its slot and its cores, and resumes
|
|
7
|
+
// (SIGCONT) when the waiter's lease ends, however it ends.
|
|
8
|
+
// - Memory pressure, seen by `dibs throttle --watch`. Jobs running on top of
|
|
9
|
+
// a full resource (src/overlap.mjs) pause first, newest first, then idle
|
|
10
|
+
// and low leases, furthest over their memory first, one at a time until
|
|
11
|
+
// pressure eases.
|
|
12
|
+
// - Free disk under minDisk while swap grows on it, also seen by the watcher.
|
|
13
|
+
// Jobs on top pause first, then idle, low and normal work, newest first,
|
|
14
|
+
// one each pass (two when it's falling fast) until it stops, and they resume once there's room again.
|
|
15
|
+
// If swap keeps growing anyway, the paused jobs' memory is what's going to
|
|
16
|
+
// swap: one is stopped each pass, and its dibs run starts it again from the
|
|
17
|
+
// front of its line (diskRequeue). Only on resources marked rerun.
|
|
18
|
+
//
|
|
19
|
+
// A paused lease keeps its lease and its place, and its run clock stops.
|
|
20
|
+
// Stopped processes keep their memory, so a paused lease still counts against
|
|
21
|
+
// the memory budget: the slot and cores are lent, the memory isn't.
|
|
22
|
+
//
|
|
23
|
+
// Each pause is an entry in lease.pauses ({ lease } for a waiter, { watcher }
|
|
24
|
+
// for memory pressure, { watcher, disk } for the disk, { owner, by } for a dibs pause by hand, src/override.mjs). The tree is stopped while there's at least one entry.
|
|
25
|
+
// Signals are queued during a state change and sent once the new state is on
|
|
26
|
+
// disk, still under the lock (flush), so pauses and resumes from different
|
|
27
|
+
// processes can't cross, and a caller that dies mid-change never leaves a job
|
|
28
|
+
// stopped with no record of why. settle() runs at the end of every state
|
|
29
|
+
// change and drops entries whose lease or watcher is gone, so a crashed waker
|
|
30
|
+
// never leaves a job stopped past the next dibs call.
|
|
31
|
+
//
|
|
32
|
+
// Windows has no SIGSTOP. Nothing is ever paused there, and urgent work waits
|
|
33
|
+
// as it always did.
|
|
34
|
+
import fs from 'node:fs';
|
|
35
|
+
import path from 'node:path';
|
|
36
|
+
import { resCfg, HOME } from './config.mjs';
|
|
37
|
+
import { makeAlive, pstart, tag, isMine } from './proc.mjs';
|
|
38
|
+
import { descendants, stopTree, runningIn, OS } from './platform.mjs';
|
|
39
|
+
import { verdict, used, holdsOf, lent, coveredNow, overBy, BACKGROUND, swapGrowing, diskDraining, working, remaining, typical, pausedFor } from './schedule.mjs';
|
|
40
|
+
import { pressureVictim, pausedLine } from './overlap.mjs';
|
|
41
|
+
import { tellOverAsk } from './measure.mjs';
|
|
42
|
+
import { bytes, dur, say, now, sleepSync } from './util.mjs';
|
|
43
|
+
|
|
44
|
+
// Stop rounds for a pause, and the wait before each check: 25 ms lets a stop
|
|
45
|
+
// land on a busy machine, and 5 rounds catch a child that forks once more.
|
|
46
|
+
const STOP_ROUNDS = 5, STOP_GAP = 25;
|
|
47
|
+
|
|
48
|
+
// Waiters that may pause someone else's work.
|
|
49
|
+
const PREEMPTS = new Set(['urgent', 'high']);
|
|
50
|
+
|
|
51
|
+
// Memory pressure readings in a row before acting: two critical ones (20s at
|
|
52
|
+
// the watcher's 10s pace) to pause, six normal ones (a minute) to resume. A
|
|
53
|
+
// warning reading resets both, so nothing flaps while the machine hovers.
|
|
54
|
+
export const PRESSURE = { pauseAfter: 2, resumeAfter: 6 };
|
|
55
|
+
|
|
56
|
+
// A run of low or idle work whose process tree dibs knows, on resources that
|
|
57
|
+
// all allow pausing. Holds are never paused: their pid is the agent itself.
|
|
58
|
+
export function pausable(l, cfg) {
|
|
59
|
+
return OS !== 'windows' && l.kind === 'run' && !!l.pgid && BACKGROUND.has((l.prio || 'normal'))
|
|
60
|
+
&& l.res.every(r => resCfg(cfg, r).pausable === true);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const pressured = l => !!l.pauses?.some(p => p.watcher);
|
|
64
|
+
|
|
65
|
+
// dibs never leaves every job paused. Stopped jobs keep their memory and their
|
|
66
|
+
// swap, so with none running nothing can finish and free any, and every waiter
|
|
67
|
+
// waits on paused memory forever. On 2026-10-15 the watcher paused a Playwright
|
|
68
|
+
// run while a deploy still ran; the deploy ended, and the machine sat with
|
|
69
|
+
// every job stopped. Only a dibs pause by hand (the person's or an agent's) may stop the last one.
|
|
70
|
+
// Every automatic pause goes through mayPause; heal (from settle, so on every
|
|
71
|
+
// state change and every watcher pass) resumes one if all are stopped anyway.
|
|
72
|
+
// A job ended and requeued for the disk (diskRequeue) isn't a pause: it frees
|
|
73
|
+
// its memory and swap, so it may be the last one running.
|
|
74
|
+
//
|
|
75
|
+
// A run inside a paused one (a nested dibs run) is stopped with it.
|
|
76
|
+
function stoppedBy(s, ids) {
|
|
77
|
+
const out = new Set(ids);
|
|
78
|
+
for (let grew = true; grew;) {
|
|
79
|
+
grew = false;
|
|
80
|
+
for (const x of s.leases) if (x.outer != null && out.has(x.outer) && !out.has(x.id)) { out.add(x.id); grew = true; }
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
// Leases making progress: runs not stopped, and holds an urgent pause was lent to.
|
|
85
|
+
function running(s, also = []) {
|
|
86
|
+
const stopped = stoppedBy(s, [...s.leases.filter(l => l.pausedAt).map(l => l.id), ...also]);
|
|
87
|
+
const lentTo = new Set(s.leases.flatMap(l => (l.pauses || []).map(p => p.lease)).filter(x => x != null));
|
|
88
|
+
return s.leases.filter(l => !stopped.has(l.id) && (working(l) || lentTo.has(l.id)));
|
|
89
|
+
}
|
|
90
|
+
// Pausing a job about to finish frees nothing finishing wouldn't free sooner:
|
|
91
|
+
// under NEAR_END left, or the last NEAR_SHARE of its usual run. One that has
|
|
92
|
+
// overrun its usual time by more than NEAR_END isn't about to finish.
|
|
93
|
+
const NEAR_END = 2 * 60e3, NEAR_SHARE = 0.1;
|
|
94
|
+
function nearlyDone(l, hist, t) {
|
|
95
|
+
const e = l.est || typical(hist, l.key);
|
|
96
|
+
if (e == null) return false;
|
|
97
|
+
const left = e - (t - l.start - pausedFor(l, t));
|
|
98
|
+
return left > -NEAR_END && (left < NEAR_END || left < e * NEAR_SHARE);
|
|
99
|
+
}
|
|
100
|
+
// starting: the pause lends to a waiter that starts in this same change.
|
|
101
|
+
export function mayPause(s, l, hist = [], t = now(), starting = false) {
|
|
102
|
+
if (nearlyDone(l, hist, t)) return false;
|
|
103
|
+
return starting || running(s, [l.id]).length > 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// When every run is stopped and dibs stopped at least one, resume the one
|
|
107
|
+
// closest to done. Returns it, or null.
|
|
108
|
+
export function heal(s, t = now(), hist = () => []) {
|
|
109
|
+
if (!s.leases.some(l => l.kind === 'run') || running(s).length) return null;
|
|
110
|
+
// Not one inside a run that stays paused: resuming it would leave it stopped all the same.
|
|
111
|
+
const inside = stoppedBy(s, s.leases.filter(l => l.pausedAt).map(l => l.id));
|
|
112
|
+
const ours = s.leases.filter(l => l.pausedAt && !l.pauses?.some(p => p.owner) && !(l.outer != null && inside.has(l.outer)));
|
|
113
|
+
if (!ours.length) return null;
|
|
114
|
+
const h = hist();
|
|
115
|
+
const left = l => remaining(l, h, t) ?? Infinity;
|
|
116
|
+
const l = ours.sort((a, b) => left(a) - left(b) || a.start - b.start)[0];
|
|
117
|
+
l.pauses = [];
|
|
118
|
+
sync(l);
|
|
119
|
+
try { fs.appendFileSync(path.join(HOME, 'cool.log'), `${new Date(t).toISOString()} every job was paused: resumed ${l.who} ${l.res.join(',')} (${l.prio || 'normal'}), the closest to done, so something can finish\n`); } catch {}
|
|
120
|
+
return l;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Signals waiting for the state file to be written.
|
|
124
|
+
const queued = [];
|
|
125
|
+
export function flush(send = true) {
|
|
126
|
+
for (const f of queued.splice(0)) if (send) f();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// The run's own process is still the one dibs started, not a reused pid.
|
|
130
|
+
const ours = l => !l.pgstart || makeAlive([l.pgid])(l.pgid, l.pgstart);
|
|
131
|
+
|
|
132
|
+
// Stop or continue the tree to match l.pauses, and tell its owner. Called
|
|
133
|
+
// under the state lock.
|
|
134
|
+
function sync(l) {
|
|
135
|
+
if (l.pauses?.length && !l.pausedAt) {
|
|
136
|
+
// Groups the run's tracker hasn't noted yet are found now. A stopped tree
|
|
137
|
+
// can't start new processes, so this list is still whole at resume.
|
|
138
|
+
// If the job has already ended, its numbers may belong to someone else now: stop nothing.
|
|
139
|
+
const groups = new Set();
|
|
140
|
+
if (ours(l)) {
|
|
141
|
+
for (const g of [l.pgid, ...(l.groups || [])]) groups.add(g);
|
|
142
|
+
for (const g of descendants(l.pgid)) groups.add(g);
|
|
143
|
+
}
|
|
144
|
+
l.stopped = [...groups];
|
|
145
|
+
l.pausedAt = now();
|
|
146
|
+
const { stopped } = l;
|
|
147
|
+
// A child forked while the stop goes out isn't in the group yet and runs on
|
|
148
|
+
// while the job reads as paused: 1 pause in 30 left one running on
|
|
149
|
+
// 2026-10-16, and that child may fork again before it's caught. So stop
|
|
150
|
+
// until nothing in the groups is running, and log what still is after
|
|
151
|
+
// STOP_ROUNDS, rather than call it paused. The usual cost is one ps call.
|
|
152
|
+
queued.push(() => {
|
|
153
|
+
for (const g of stopped) stopTree(g, 'SIGSTOP');
|
|
154
|
+
let left = [];
|
|
155
|
+
for (let i = 0; i < STOP_ROUNDS; i++) {
|
|
156
|
+
sleepSync(STOP_GAP);
|
|
157
|
+
left = runningIn(stopped);
|
|
158
|
+
if (!left.length) break;
|
|
159
|
+
for (const g of stopped) stopTree(g, 'SIGSTOP');
|
|
160
|
+
}
|
|
161
|
+
// A process in the kernel (D) reads as stopped only once a stop has reached it, and one
|
|
162
|
+
// forked since the last stop hasn't had one: one more, which a stopped process ignores.
|
|
163
|
+
for (const g of stopped) stopTree(g, 'SIGSTOP');
|
|
164
|
+
if (left.length) try { fs.appendFileSync(path.join(HOME, 'cool.log'), `${new Date().toISOString()} pausing #${l.id} (${l.who} ${l.res.join(',')}): pids ${left.join(' ')} still running after ${STOP_ROUNDS} stops\n`); } catch {}
|
|
165
|
+
});
|
|
166
|
+
tell(l);
|
|
167
|
+
} else if (!l.pauses?.length && l.pausedAt) {
|
|
168
|
+
const groups = new Set([l.pgid, ...(l.stopped || []), ...(l.groups || [])]);
|
|
169
|
+
queued.push(() => { for (const g of groups) if (g) stopTree(g, 'SIGCONT'); });
|
|
170
|
+
l.pausedMs = (l.pausedMs || 0) + now() - l.pausedAt;
|
|
171
|
+
delete l.pausedAt; delete l.stopped; delete l.pauses;
|
|
172
|
+
tell(l);
|
|
173
|
+
} else if (l.pauses && !l.pauses.length) delete l.pauses;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// The owner's `dibs run` reads the lease and says what happened on its stderr.
|
|
177
|
+
// Only runs that asked for it get the signal: SIGUSR2 ends a process that
|
|
178
|
+
// doesn't handle it, such as a run started by an older dibs.
|
|
179
|
+
function tell(l) {
|
|
180
|
+
const { notify, pid } = l;
|
|
181
|
+
if (notify && pid) queued.push(() => { try { process.kill(pid, 'SIGUSR2'); } catch {} });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Fewest new stops first: a lease already paused for memory costs nothing to
|
|
185
|
+
// lend. Then idle before low, then the most recently started.
|
|
186
|
+
const victimOrder = (a, b) => pressured(b) - pressured(a) || (b.prio === 'idle') - (a.prio === 'idle') || b.start - a.start;
|
|
187
|
+
|
|
188
|
+
// Called when an urgent or high waiter can't start because a slot is full.
|
|
189
|
+
// Pauses the fewest low and idle leases that would let it start now, or none:
|
|
190
|
+
// if pausing wouldn't get it going (budget, disk, someone ahead), nothing is
|
|
191
|
+
// touched. Returns the verdict with the paused leases, or null.
|
|
192
|
+
export function preempt(s, me, cfg, hist, t = now()) {
|
|
193
|
+
if (!PREEMPTS.has(me.prio) || OS === 'windows') return null;
|
|
194
|
+
// Raised by its own agent: it may pause that session's runs, nobody else's.
|
|
195
|
+
const mine = holdsOf(s, me);
|
|
196
|
+
const victims = [];
|
|
197
|
+
for (const r of me.res) {
|
|
198
|
+
if (mine.has(r)) continue;
|
|
199
|
+
const need = used(s, r) - resCfg(cfg, r).slots + 1 - victims.filter(l => l.res.includes(r)).length;
|
|
200
|
+
if (need <= 0) continue;
|
|
201
|
+
// A run its own session's hold covers takes no slot, so pausing it frees none.
|
|
202
|
+
const pick = s.leases.filter(l => l.res.includes(r) && !victims.includes(l) && !lent(l) && !coveredNow(s, l, r) && pausable(l, cfg)
|
|
203
|
+
&& mayPause(s, l, hist, t, true)).sort(victimOrder);
|
|
204
|
+
if (pick.length < need) return null;
|
|
205
|
+
victims.push(...pick.slice(0, need));
|
|
206
|
+
}
|
|
207
|
+
if (!victims.length) return null;
|
|
208
|
+
const entry = { lease: me.id, who: tag(me), prio: me.prio, purpose: me.purpose || '', res: me.res, at: t };
|
|
209
|
+
for (const l of victims) (l.pauses ||= []).push({ ...entry });
|
|
210
|
+
const v = verdict(s, me, cfg, hist, t);
|
|
211
|
+
if (!v.ok) {
|
|
212
|
+
for (const l of victims) { l.pauses.pop(); if (!l.pauses.length) delete l.pauses; }
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
for (const l of victims) sync(l);
|
|
216
|
+
return { ...v, paused: victims.map(l => ({ id: l.id, who: tag(l), res: l.res, prio: l.prio })) };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Drop pauses whose waker is gone and resume what that frees: the lease it
|
|
220
|
+
// was lent to has ended (or its process died and was reaped), or the pressure
|
|
221
|
+
// watcher died. Runs at the end of every state change.
|
|
222
|
+
//
|
|
223
|
+
// A disk pause outlives its watcher by WATCHER_GRACE: launchd restarts the
|
|
224
|
+
// watcher within seconds (every release kickstarts it), and the new one adopts
|
|
225
|
+
// the pauses (adoptPauses). Resuming every disk-paused job at once in a disk
|
|
226
|
+
// crunch would undo the pauses it took minutes to make.
|
|
227
|
+
export const WATCHER_GRACE = 60e3;
|
|
228
|
+
export function settle(s, t = now(), hist = () => []) {
|
|
229
|
+
const paused = s.leases.filter(l => l.pauses || l.pausedAt);
|
|
230
|
+
if (!paused.length) return;
|
|
231
|
+
const ids = new Set(s.leases.map(l => l.id));
|
|
232
|
+
const watchers = paused.flatMap(l => (l.pauses || []).filter(p => p.watcher).map(p => p.watcher));
|
|
233
|
+
const alive = watchers.length ? makeAlive(watchers) : () => false;
|
|
234
|
+
const keep = p => {
|
|
235
|
+
if (p.owner) return true;
|
|
236
|
+
if (!p.watcher) return ids.has(p.lease);
|
|
237
|
+
if (alive(p.watcher, p.wstart)) { delete p.gone; return true; }
|
|
238
|
+
if (!p.disk) return false;
|
|
239
|
+
p.gone ??= t;
|
|
240
|
+
return t - p.gone < WATCHER_GRACE;
|
|
241
|
+
};
|
|
242
|
+
for (const l of paused) {
|
|
243
|
+
l.pauses = (l.pauses || []).filter(keep);
|
|
244
|
+
sync(l);
|
|
245
|
+
}
|
|
246
|
+
heal(s, t, hist);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// A new watcher takes over the disk pauses a stopped one left (settle keeps
|
|
250
|
+
// them for WATCHER_GRACE). Returns how many it adopted.
|
|
251
|
+
export function adoptPauses(s, pid = process.pid, wstart = pstart(process.pid)) {
|
|
252
|
+
let n = 0;
|
|
253
|
+
for (const l of s.leases) for (const p of l.pauses || []) if (p.disk && p.watcher && p.watcher !== pid) { Object.assign(p, { watcher: pid, wstart }); delete p.gone; n++; }
|
|
254
|
+
return n;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// One pressure reading: 'pause', 'resume' or null. `track` carries the
|
|
258
|
+
// streaks between readings.
|
|
259
|
+
export function pressureStep(track, level) {
|
|
260
|
+
if (level == null) return null;
|
|
261
|
+
if (level >= 2) {
|
|
262
|
+
track.low = 0;
|
|
263
|
+
if (++track.high >= PRESSURE.pauseAfter) { track.high = 0; return 'pause'; }
|
|
264
|
+
} else if (level === 0) {
|
|
265
|
+
track.high = 0;
|
|
266
|
+
if (++track.low >= PRESSURE.resumeAfter) { track.low = 0; return 'resume'; }
|
|
267
|
+
} else track.high = track.low = 0;
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Free disk under minDisk while swap grows or the disk drains: the jobs running
|
|
272
|
+
// now are what's filling it, so holding new starts isn't enough. Swap grew 2 GB
|
|
273
|
+
// a minute on 2026-10-15, so 3 GB left only 90s; minDisk (5G stock) gives the
|
|
274
|
+
// watcher's 10s passes a few minutes. Never under DISK_FLOOR, whatever minDisk says.
|
|
275
|
+
export const DISK_FLOOR = 3 * 1024 ** 3;
|
|
276
|
+
export const diskLine = cfg => Math.max(bytes(cfg.minDisk), DISK_FLOOR);
|
|
277
|
+
// Still growing or falling now, not just over the last 5 minutes (schedule.mjs swapGrowing).
|
|
278
|
+
export const diskCritical = (m, cfg) => m.diskFree != null && m.diskFree < diskLine(cfg) && (swapGrowing(m) || diskDraining(m));
|
|
279
|
+
|
|
280
|
+
// Draining fast enough to be down to DISK_LAST within DISK_SOON, two runs pause
|
|
281
|
+
// each pass instead of one: at the worst rate seen, one a pass would come too late.
|
|
282
|
+
const DISK_LAST = 1024 ** 3, DISK_SOON = 2 * 6e4;
|
|
283
|
+
export function diskPausesPerPass(m) {
|
|
284
|
+
if (!(m.diskDrain > 0) || m.diskFree == null) return 1;
|
|
285
|
+
const perMs = m.diskDrain / Math.max(m.drainMs || 0, 30e3); // a span under one reading apart isn't a rate
|
|
286
|
+
return m.diskFree - DISK_LAST < perMs * DISK_SOON ? 2 : 1;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// One disk reading: 'pause' while it's critical, 'resume' once free disk has
|
|
290
|
+
// been back over the line pausing uses and steady for a minute. Paused jobs
|
|
291
|
+
// keep their memory, so their swap stays and the disk may never come back over
|
|
292
|
+
// the line: after DISK_STILL readings with nothing growing or falling, one
|
|
293
|
+
// resumes anyway, since waiting frees nothing then. `track` carries the streaks.
|
|
294
|
+
const DISK_STILL = 18; // 3 minutes at the watcher's 10s pace
|
|
295
|
+
export function diskStep(track, m, cfg) {
|
|
296
|
+
if (diskCritical(m, cfg)) { track.diskOk = track.diskStill = 0; return 'pause'; }
|
|
297
|
+
const still = m.diskFree != null && !swapGrowing(m) && !diskDraining(m);
|
|
298
|
+
if (!still) { track.diskOk = track.diskStill = 0; return null; }
|
|
299
|
+
track.diskStill = (track.diskStill || 0) + 1;
|
|
300
|
+
track.diskOk = m.diskFree >= diskLine(cfg) ? (track.diskOk || 0) + 1 : 0;
|
|
301
|
+
if (track.diskOk >= PRESSURE.resumeAfter || track.diskStill >= DISK_STILL) { track.diskOk = track.diskStill = 0; return 'resume'; }
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Pause the next lease while free disk is low and filling: one on top of a full
|
|
306
|
+
// resource first, then idle, low and normal work, newest first (the newest is
|
|
307
|
+
// likeliest to be the one growing). Urgent and high work, holds, and resources
|
|
308
|
+
// that can't pause are left alone. Nothing is killed. Returns it, or null.
|
|
309
|
+
const DISK_ORDER = { idle: 0, low: 1 };
|
|
310
|
+
export function diskPause(s, cfg, t = now(), m = {}, hist = []) {
|
|
311
|
+
const rank = l => DISK_ORDER[(l.prio || 'normal')] ?? 2;
|
|
312
|
+
const l = s.leases.filter(x => OS !== 'windows' && x.kind === 'run' && x.pgid && !x.pausedAt && !PREEMPTS.has((x.prio || 'normal'))
|
|
313
|
+
&& x.res.every(r => resCfg(cfg, r).pausable === true) && mayPause(s, x, hist, t))
|
|
314
|
+
.sort((a, b) => !!b.alongside - !!a.alongside || rank(a) - rank(b) || b.start - a.start)[0];
|
|
315
|
+
if (!l) return null;
|
|
316
|
+
(l.pauses ||= []).push({ watcher: process.pid, wstart: pstart(process.pid), at: t, disk: true, swap: swapGrowing(m) });
|
|
317
|
+
sync(l);
|
|
318
|
+
return { ...l };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// A job paused for low disk keeps its memory, and under memory pressure that
|
|
322
|
+
// memory goes to swap, whose files fill the disk the job waits on: on
|
|
323
|
+
// 2026-10-16 two disk-paused jobs (one 6 GB) took swap from 4 to 10 GB and free
|
|
324
|
+
// disk from 4.5 to 0.9 GB. A job running far past what it booked does the same
|
|
325
|
+
// while it runs: on 2026-10-17 a test run booked at 11 GB used 16 and took swap
|
|
326
|
+
// to 8.9 GB. While the disk is critical and swap still grows, the watcher stops
|
|
327
|
+
// one such job a pass, the most memory first. Its own dibs run puts it back at
|
|
328
|
+
// the front of its line, booked at what it really used, and runs it again from
|
|
329
|
+
// the start once that much memory is really free (src/commands.mjs run), so its
|
|
330
|
+
// agent's call goes on. Only jobs dibs can run again without harm (every
|
|
331
|
+
// resource rerun: true), whose dibs run knows how (requeuable), not nearly done,
|
|
332
|
+
// and not paused by a person or agent.
|
|
333
|
+
//
|
|
334
|
+
// Stopping a running one may leave nothing running, and that's meant: unlike a
|
|
335
|
+
// pause, a stop gives back all of its memory, and a job using this much more
|
|
336
|
+
// than it booked is the hazard itself. Booked at its real size, it can't start
|
|
337
|
+
// again into the same crunch. One that goes past its booking again after that
|
|
338
|
+
// isn't stopped a second time (OVER_AGAIN): its pauses and the person handle it.
|
|
339
|
+
const OVER_FACTOR = 2, OVER_MIN = 4 * 1024 ** 3, OVER_AGAIN = 1;
|
|
340
|
+
export const measured = l => Math.max(l.use?.mem || 0, l.peak?.mem || 0);
|
|
341
|
+
// Far past its booking: at least OVER_MIN over it, and twice it or more than all
|
|
342
|
+
// the memory dibs shares out (a job bigger than the budget is booked at the budget).
|
|
343
|
+
export const overBooked = (l, cfg) => {
|
|
344
|
+
const u = measured(l);
|
|
345
|
+
return u - l.mem >= OVER_MIN && (u >= l.mem * OVER_FACTOR || u > bytes(cfg.budget));
|
|
346
|
+
};
|
|
347
|
+
export function diskRequeue(s, cfg, t = now(), hist = []) {
|
|
348
|
+
const why = x => (x.pausedAt ? (x.pauses?.some(p => p.disk) ? 'disk' : null) : overBooked(x, cfg) && (x.requeues || 0) < OVER_AGAIN ? 'over' : null);
|
|
349
|
+
const l = s.leases.filter(x => x.kind === 'run' && x.requeuable && !x.requeue && why(x) && !x.pauses?.some(p => p.owner)
|
|
350
|
+
&& x.res.every(r => resCfg(cfg, r).rerun === true) && !nearlyDone(x, hist, t))
|
|
351
|
+
.sort((a, b) => (measured(b) || b.mem || 0) - (measured(a) || a.mem || 0))[0];
|
|
352
|
+
if (!l) return null;
|
|
353
|
+
l.requeue = { at: t, why: why(l) };
|
|
354
|
+
// Killed where it stands: SIGKILL ends a stopped process too. Its dibs run sees it end.
|
|
355
|
+
if (ours(l)) {
|
|
356
|
+
const groups = [...new Set([l.pgid, ...(l.stopped || []), ...(l.groups || [])].filter(Boolean))];
|
|
357
|
+
queued.push(() => { for (const g of groups) stopTree(g, 'SIGKILL'); });
|
|
358
|
+
}
|
|
359
|
+
return { ...l };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Pause the next lease under memory pressure: a job running on top of a full
|
|
363
|
+
// resource first, newest first (src/overlap.mjs), since it's the extra load;
|
|
364
|
+
// then the one furthest over the memory it asked for (it's why the books are
|
|
365
|
+
// wrong), then idle before low, then the most memory. Returns it, or null when
|
|
366
|
+
// nothing is left to pause.
|
|
367
|
+
export function pressurePause(s, cfg, t = now(), hist = []) {
|
|
368
|
+
const top = pressureVictim(s, cfg);
|
|
369
|
+
const l = (top && mayPause(s, top, hist, t) ? top : null) || s.leases.filter(x => pausable(x, cfg) && !pressured(x) && mayPause(s, x, hist, t))
|
|
370
|
+
.sort((a, b) => overBy(b) - overBy(a) || (b.prio === 'idle') - (a.prio === 'idle') || b.mem - a.mem)[0];
|
|
371
|
+
if (!l) return null;
|
|
372
|
+
(l.pauses ||= []).push({ watcher: process.pid, wstart: pstart(process.pid), at: t });
|
|
373
|
+
sync(l);
|
|
374
|
+
return { ...l };
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Resume one lease paused for memory pressure (or, with disk, for the disk),
|
|
378
|
+
// in the reverse order: jobs on top last, low before idle, then the least
|
|
379
|
+
// memory. With all = true, every one (the watcher is stopping); 'memory', every
|
|
380
|
+
// memory pause and no disk ones. Returns what it resumed.
|
|
381
|
+
export function pressureResume(s, all = false, disk = false) {
|
|
382
|
+
const ours = p => p.watcher && (all === 'memory' ? !p.disk : all || !!p.disk === disk);
|
|
383
|
+
const ls = s.leases.filter(l => l.pauses?.some(ours)).sort((a, b) => !!a.alongside - !!b.alongside || (a.alongside ? a.start - b.start : 0)
|
|
384
|
+
|| (a.prio === 'idle') - (b.prio === 'idle') || a.mem - b.mem);
|
|
385
|
+
const out = all ? ls : ls.slice(0, 1);
|
|
386
|
+
for (const l of out) { l.pauses = l.pauses.filter(p => !ours(p)); sync(l); }
|
|
387
|
+
return out.map(l => ({ ...l }));
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// The owner's pause: kept until dibs resume or the lease ends, whatever else
|
|
391
|
+
// pauses or resumes it in between. `by` names the agent that paused it (none:
|
|
392
|
+
// the person). Anyone's resume lifts every owner pause.
|
|
393
|
+
export function ownerPause(l, on, t = now(), by = null, reason = '') {
|
|
394
|
+
if (on) (l.pauses ||= []).push({ owner: true, at: t, ...(by && { by }), ...(reason && { reason }) });
|
|
395
|
+
else l.pauses = (l.pauses || []).filter(p => !p.owner);
|
|
396
|
+
sync(l);
|
|
397
|
+
}
|
|
398
|
+
// Who paused it by hand: an agent's name, or 'owner' for the person.
|
|
399
|
+
const pausedBy = l => { const p = l.pauses?.find(x => x.owner); return p ? p.by || 'owner' : null; };
|
|
400
|
+
|
|
401
|
+
// What the board shows next to a paused lease.
|
|
402
|
+
export function pauseLabel(l) {
|
|
403
|
+
if (!l.pausedAt) return '';
|
|
404
|
+
if (pausedBy(l)) return `paused by ${pausedBy(l)}`;
|
|
405
|
+
const by = (l.pauses || []).filter(p => p.lease != null).map(p => p.who);
|
|
406
|
+
if (by.length) return `paused for ${[...new Set(by)].join(', ')}`;
|
|
407
|
+
return l.pauses?.some(p => p.disk) ? 'paused: disk low' : 'paused: memory pressure';
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// The SIGUSR2 handler for the owner's `dibs run`: say on its stderr that the
|
|
411
|
+
// job was paused or resumed. `read` returns the lease from the state file.
|
|
412
|
+
export function noticeHandler(read) {
|
|
413
|
+
let since = null;
|
|
414
|
+
return () => {
|
|
415
|
+
const l = read();
|
|
416
|
+
if (!l) return;
|
|
417
|
+
tellOverAsk(l);
|
|
418
|
+
if (l.pausedAt && !since) {
|
|
419
|
+
since = l.pausedAt;
|
|
420
|
+
const p = (l.pauses || []).find(x => x.lease != null);
|
|
421
|
+
const by = pausedBy(l);
|
|
422
|
+
const why = l.pauses.find(x => x.owner)?.reason;
|
|
423
|
+
say(by ? `${by === 'owner' ? 'the owner (the person at this machine)' : by} paused your job (dibs pause ${l.id})${why ? `: "${why}"` : ''}. It keeps its lease and its place; dibs resume ${l.id} continues it.`
|
|
424
|
+
+ ' Timeouts inside it may fire on resume.'
|
|
425
|
+
: p
|
|
426
|
+
? `paused your job for ${p.who} (${p.prio}${p.purpose ? `: "${p.purpose}"` : ''}), who needed ${p.res.join(', ')}.`
|
|
427
|
+
+ ` It keeps its lease and its place, and resumes when their job ends. Timeouts inside it may fire on resume.`
|
|
428
|
+
: l.pauses?.some(x => x.disk)
|
|
429
|
+
? `paused your job: free disk is low and ${l.pauses.some(x => x.swap) ? 'swap is still growing on it' : 'still falling'}. It keeps its lease and its place, and resumes once there's room again.`
|
|
430
|
+
+ ' If it stays paused, free some disk space. Timeouts inside it may fire on resume.'
|
|
431
|
+
: l.alongside ? pausedLine()
|
|
432
|
+
: `paused your ${l.prio} job: the machine is short on memory. It keeps its lease and resumes when memory pressure eases.`);
|
|
433
|
+
} else if (!l.pausedAt && since) {
|
|
434
|
+
say(`resumed your job after ${dur(now() - since)} paused${l.resumeReason ? `: "${l.resumeReason}"` : ''}.`);
|
|
435
|
+
since = null;
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
}
|
package/src/primer.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// What every new agent session hears about dibs before its first prompt, from
|
|
2
|
+
// the guard hook's SessionStart (and a subagent's SubagentStart). Most agents
|
|
3
|
+
// never read the docs, and many have nobody relaying messages, so the few
|
|
4
|
+
// rules that keep them out of trouble arrive with the session. Loaded only
|
|
5
|
+
// for those events; it reads config.json for the resource names and nothing else.
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
|
|
10
|
+
const DIBS_HOME = process.env.DIBS_HOME || path.join(os.homedir(), '.dibs');
|
|
11
|
+
const BUILT_IN = ['sim', 'sim-own', 'xcode-build', 'test', 'playwright', 'deploy', 'heavy'];
|
|
12
|
+
|
|
13
|
+
// The resources this machine has: the built-in ones plus any config.json adds.
|
|
14
|
+
function resources() {
|
|
15
|
+
let extra = [];
|
|
16
|
+
try { extra = Object.keys(JSON.parse(fs.readFileSync(path.join(DIBS_HOME, 'config.json'), 'utf8')).resources || {}); } catch {}
|
|
17
|
+
return [...new Set([...BUILT_IN, ...extra])].join(', ');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function primerText() {
|
|
21
|
+
return [
|
|
22
|
+
'dibs runs on this machine: agents take turns through it on the simulator, builds, tests, browser runs and deploys.',
|
|
23
|
+
`- Wrap those: dibs run <resource> -m "why" -- <command> (resources: ${resources()}). Across several tool calls: dibs hold sim --for 20m -m "why", `
|
|
24
|
+
+ 'keep wrapping each command (no wait under your hold), dibs release sim. Reads, edits and small commands need nothing.',
|
|
25
|
+
'- Waiting is normal. A call moved to the background is still waiting: don\'t run it again. '
|
|
26
|
+
+ 'A memory, swap or disk wait protects the machine: keep waiting. Never lower --mem or raise -p for it.',
|
|
27
|
+
'- Post progress as often as you commit: dibs progress "what you did or found" --task <name> --eta 30m, then --blocked or --done. The person reads it live.',
|
|
28
|
+
'- Decide two-way doors yourself. Ask the person only what can\'t be undone: dibs question "..." --recommend X -m why --one-way "what is lost", '
|
|
29
|
+
+ 'keep working, then the same command plus --wait reads the answer. "Message from the person:" lines are theirs.',
|
|
30
|
+
'- You may boost, pause or stop any job (--owner <session> if not yours); dibs logs who. A job "stopped by" someone was ended on purpose: find out why first.',
|
|
31
|
+
'- Exit codes: 75 never ran (outside Claude Code; rerun within 2 min), 74 no disk, 76 lost before it started (send again), 77 lost after (check first), 70 dibs crashed. '
|
|
32
|
+
+ 'Quote file globs: dibs hold \'files:src/auth/**\'.',
|
|
33
|
+
'- More: the dibs skill, dibs help. Something wrong with dibs: dibs ask "...".',
|
|
34
|
+
].join('\n');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Each subagent hears it once: SubagentStart also fires every time an agent
|
|
38
|
+
// team teammate takes a new message. A short list of ids it was told, newest last.
|
|
39
|
+
const TOLD = path.join(DIBS_HOME, 'primed.json');
|
|
40
|
+
const REMEMBER = 500;
|
|
41
|
+
function firstTime(agentId) {
|
|
42
|
+
let told = [];
|
|
43
|
+
try { told = JSON.parse(fs.readFileSync(TOLD, 'utf8')); } catch {}
|
|
44
|
+
if (told.includes(agentId)) return false;
|
|
45
|
+
told.push(agentId);
|
|
46
|
+
try {
|
|
47
|
+
fs.mkdirSync(DIBS_HOME, { recursive: true });
|
|
48
|
+
fs.writeFileSync(`${TOLD}.${process.pid}`, JSON.stringify(told.slice(-REMEMBER)));
|
|
49
|
+
fs.renameSync(`${TOLD}.${process.pid}`, TOLD);
|
|
50
|
+
} catch {}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The hook's answer for SessionStart and SubagentStart, merged into out (the
|
|
55
|
+
// subagent limit's own answer, which is null for a start). Null when there is
|
|
56
|
+
// nothing to say.
|
|
57
|
+
export function primer(input, out) {
|
|
58
|
+
const event = input.hook_event_name;
|
|
59
|
+
if (event === 'SubagentStart' && (typeof input.agent_id !== 'string' || !firstTime(input.agent_id))) return out;
|
|
60
|
+
return { ...out, hookSpecificOutput: { hookEventName: event, additionalContext: primerText() } };
|
|
61
|
+
}
|
package/src/proc.mjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Process facts: is a holder still alive, and which agent session is calling.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { starts, parent, AGENTS } from './platform.mjs';
|
|
6
|
+
import { sleep, callerPid } from './util.mjs';
|
|
7
|
+
|
|
8
|
+
const SESSIONS = process.env.DIBS_SESSIONS || path.join(os.homedir(), '.claude', 'sessions');
|
|
9
|
+
|
|
10
|
+
export const pstart = pid => starts([pid])?.get(pid) || null;
|
|
11
|
+
|
|
12
|
+
// One process-table call for a batch of pids, then cheap lookups. If the
|
|
13
|
+
// table can't be read, everyone counts as alive: wrongly reaping a running
|
|
14
|
+
// job kills it, while wrongly keeping a dead one costs a few seconds.
|
|
15
|
+
// Start times read here in the last STARTS_FOR stay good while the pid still
|
|
16
|
+
// answers kill(0): every state read reaps, and one ps per read cost a dibs run
|
|
17
|
+
// 30 to 50 ms each time on a busy Mac. A pid can only be reused after its
|
|
18
|
+
// process is gone, which kill(0) sees.
|
|
19
|
+
const STARTS_FOR = 10e3;
|
|
20
|
+
const known = new Map(); // pid -> { start, at }
|
|
21
|
+
const answers = pid => { try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; } };
|
|
22
|
+
export function makeAlive(pids) {
|
|
23
|
+
const t = Date.now();
|
|
24
|
+
const need = pids.filter(p => p && !(known.has(p) && t - known.get(p).at < STARTS_FOR && answers(p)));
|
|
25
|
+
const st = need.length ? starts(need) : new Map();
|
|
26
|
+
if (!st) return pid => !!pid;
|
|
27
|
+
for (const p of need) if (st.has(p)) known.set(p, { start: st.get(p), at: t }); else known.delete(p);
|
|
28
|
+
const startOf = pid => (st.has(pid) ? st.get(pid) : known.get(pid)?.start);
|
|
29
|
+
return (pid, started) => !!pid && startOf(pid) != null && (!started || startOf(pid) === started);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// The agent session that owns this call (Claude Code, Codex, Cursor...), found
|
|
33
|
+
// by walking up the process tree. Holds outlive a single tool call, so they
|
|
34
|
+
// hang off this process. For Claude Code, its name is the one SendMessage uses.
|
|
35
|
+
let cached;
|
|
36
|
+
function session() {
|
|
37
|
+
if (cached !== undefined) return cached;
|
|
38
|
+
cached = null;
|
|
39
|
+
if (process.env.DIBS_NO_SESSION) return cached; // tests act as several agents from one session
|
|
40
|
+
let pid = callerPid();
|
|
41
|
+
for (let i = 0; i < 25 && pid > 1; i++) {
|
|
42
|
+
const p = parent(pid);
|
|
43
|
+
if (!p) break;
|
|
44
|
+
if (AGENTS.test(p.name)) {
|
|
45
|
+
let name = null;
|
|
46
|
+
try { name = JSON.parse(fs.readFileSync(path.join(SESSIONS, `${pid}.json`), 'utf8')).name || null; } catch {}
|
|
47
|
+
cached = { pid, name, app: p.name.toLowerCase(), start: pstart(pid) };
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
pid = p.ppid;
|
|
51
|
+
}
|
|
52
|
+
return cached;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function identity(o = {}) {
|
|
56
|
+
const se = session();
|
|
57
|
+
const label = o.as || process.env.DIBS_AS || '';
|
|
58
|
+
const agent = process.env.DIBS_AGENT || se?.name || null;
|
|
59
|
+
// Outside an agent session, the folder names you, so hold and release from the same place match.
|
|
60
|
+
const who = agent || (se ? `${label || path.basename(process.cwd())}#${se.pid}` : label || path.basename(process.cwd()));
|
|
61
|
+
return { who, agent, label, spid: se?.pid || null, sstart: se?.start || null };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Claude Code's own record of each session it runs: { pid, sessionId, name }.
|
|
65
|
+
// The person addresses an agent by the name; hooks know it by sessionId.
|
|
66
|
+
export function sessionFiles() {
|
|
67
|
+
let names = [];
|
|
68
|
+
try { names = fs.readdirSync(SESSIONS).filter(n => /^\d+\.json$/.test(n)); } catch { return []; }
|
|
69
|
+
const out = [];
|
|
70
|
+
for (const n of names) {
|
|
71
|
+
try {
|
|
72
|
+
const x = JSON.parse(fs.readFileSync(path.join(SESSIONS, n), 'utf8'));
|
|
73
|
+
if (x.pid && x.sessionId) out.push({ pid: x.pid, sessionId: x.sessionId, name: x.name || null });
|
|
74
|
+
} catch {}
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const tag = x => (x.label && x.label !== x.who ? `${x.who} (${x.label})` : x.who);
|
|
80
|
+
|
|
81
|
+
// A queue entry or lease belongs to the caller if it came from the same agent
|
|
82
|
+
// session; outside one, the same name.
|
|
83
|
+
export const isMine = (x, id) =>
|
|
84
|
+
id.spid ? x.spid === id.spid || (x.kind === 'hold' && x.pid === id.spid) : x.who === id.who;
|
|
85
|
+
|
|
86
|
+
// Long-running services (worker, throttle watcher) run one at a time. If
|
|
87
|
+
// another is alive, wait for it to go away instead of exiting: under a service
|
|
88
|
+
// manager, exiting would only get this one restarted, over and over.
|
|
89
|
+
export async function singleInstance(pidfile, what) {
|
|
90
|
+
let other = 0;
|
|
91
|
+
try { other = Number(fs.readFileSync(pidfile, 'utf8')); } catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
92
|
+
if (other && other !== process.pid && makeAlive([other])(other)) {
|
|
93
|
+
console.log(`${what} (pid ${other})`);
|
|
94
|
+
while (makeAlive([other])(other)) await sleep(30e3);
|
|
95
|
+
}
|
|
96
|
+
fs.mkdirSync(path.dirname(pidfile), { recursive: true });
|
|
97
|
+
fs.writeFileSync(pidfile, String(process.pid));
|
|
98
|
+
}
|