@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.
- package/CHANGELOG.md +103 -1
- package/README.md +10 -8
- package/bin/dibs.mjs +370 -73
- package/docs/agents.md +303 -0
- package/docs/council.md +88 -0
- package/docs/files.md +3 -3
- package/docs/guard.md +86 -11
- package/docs/json.md +211 -0
- package/docs/later.md +5 -5
- package/docs/machines.md +6 -6
- package/docs/questions.md +104 -3
- package/docs/reference.md +124 -30
- package/docs/relay.md +120 -9
- package/docs/releasing.md +7 -1
- package/docs/scheduling.md +28 -6
- package/docs/secrets.md +53 -0
- package/docs/simulators.md +3 -3
- package/package.json +1 -1
- package/skills/dibs/SKILL.md +79 -149
- package/src/about.mjs +341 -0
- package/src/acquire.mjs +111 -27
- package/src/after.mjs +127 -0
- package/src/agents.mjs +2 -1
- package/src/alerts.mjs +95 -42
- package/src/answers.mjs +2 -2
- package/src/board.mjs +21 -16
- package/src/broker.mjs +23 -7
- package/src/carry.mjs +287 -0
- package/src/codex.mjs +132 -0
- package/src/commands.mjs +243 -82
- package/src/config.mjs +85 -14
- package/src/connect.mjs +4 -2
- package/src/cool.mjs +27 -11
- package/src/council.mjs +482 -0
- package/src/cwd.mjs +9 -0
- package/src/decisions.mjs +250 -0
- package/src/declare.mjs +96 -0
- package/src/diskreport.mjs +306 -0
- package/src/diskuse.mjs +420 -0
- package/src/diskwarn.mjs +68 -13
- package/src/doctor.mjs +149 -0
- package/src/doors.mjs +547 -0
- package/src/durable.mjs +143 -0
- package/src/envs.mjs +372 -0
- package/src/events.mjs +7 -2
- package/src/files.mjs +118 -6
- package/src/guard.mjs +239 -86
- package/src/guardd.mjs +8 -1
- package/src/halt.mjs +63 -0
- package/src/handoffs.mjs +362 -0
- package/src/history.mjs +34 -4
- package/src/hogs.mjs +36 -8
- package/src/jobprogress.mjs +283 -0
- package/src/later.mjs +21 -10
- package/src/lock.mjs +33 -9
- package/src/measure.mjs +42 -11
- package/src/media.mjs +240 -0
- package/src/news.mjs +31 -0
- package/src/notes.mjs +49 -8
- package/src/notices.mjs +126 -43
- package/src/ondemand.mjs +25 -2
- package/src/outcome.mjs +163 -0
- package/src/overlap.mjs +2 -2
- package/src/override.mjs +149 -79
- package/src/owner.mjs +15 -2
- package/src/people.mjs +236 -0
- package/src/pickup.mjs +72 -0
- package/src/picture.mjs +321 -0
- package/src/plain.mjs +84 -18
- package/src/platform.mjs +19 -0
- package/src/preempt.mjs +123 -15
- package/src/primer.mjs +91 -20
- package/src/prints.mjs +99 -0
- package/src/proc.mjs +1 -1
- package/src/progress.mjs +49 -3
- package/src/proof.mjs +102 -0
- package/src/push.mjs +271 -0
- package/src/questions.mjs +328 -57
- package/src/quota.mjs +1 -1
- package/src/recap.mjs +205 -0
- package/src/relay.mjs +139 -20
- package/src/remote.mjs +23 -10
- package/src/reviewgate.mjs +268 -0
- package/src/reviews.mjs +377 -0
- package/src/route.mjs +263 -0
- package/src/rules.mjs +216 -0
- package/src/schedule.mjs +238 -44
- package/src/schema.mjs +62 -0
- package/src/scratch.mjs +2 -2
- package/src/serve.mjs +3 -2
- package/src/signed.mjs +97 -0
- package/src/simpool.mjs +46 -1
- package/src/spend.mjs +375 -0
- package/src/state.mjs +43 -17
- package/src/talk.mjs +1078 -133
- package/src/thin.sh +2 -0
- package/src/trail.mjs +290 -0
- package/src/trailnote.mjs +209 -0
- package/src/util.mjs +7 -0
- package/src/vault.mjs +435 -0
- package/src/vendors.mjs +327 -0
- package/src/version.mjs +1 -1
- package/src/web.mjs +353 -60
- package/src/work.mjs +487 -0
- package/src/worker.mjs +7 -1
package/src/state.mjs
CHANGED
|
@@ -21,7 +21,9 @@ import { stopTree, starts, liveGroups, wokeAt, OS } from './platform.mjs';
|
|
|
21
21
|
import { settle, flush } from './preempt.mjs';
|
|
22
22
|
import { reapPool } from './simpool.mjs';
|
|
23
23
|
import { queueResets, startResets, reapResets } from './reset.mjs';
|
|
24
|
+
import { noteEnds, recordEnds } from './envs.mjs';
|
|
24
25
|
import { logChanges, event } from './events.mjs';
|
|
26
|
+
import { parsed, lastGood, heal, jsonLines } from './durable.mjs';
|
|
25
27
|
import { die, now, say, dur, noSpace, fakeFull, unpolled, GHOST_AFTER, POLLED_EVERY, UNPOLLED } from './util.mjs';
|
|
26
28
|
|
|
27
29
|
export const KEEP_PLACE = 120e3; // a waiter that gave up keeps its place this long
|
|
@@ -81,7 +83,9 @@ function change(fn, lock) {
|
|
|
81
83
|
reap(s);
|
|
82
84
|
const out = fn(s);
|
|
83
85
|
settle(s, now(), history); // resume work paused for a lease that has ended, and never leave every job paused
|
|
84
|
-
|
|
86
|
+
const gone = before.filter(l => !s.leases.some(x => x.id === l.id));
|
|
87
|
+
queueResets(s, gone); // onRelease for every lease this change ended
|
|
88
|
+
noteEnds(gone); // and what each environment it ended a lease on now has (src/envs.mjs)
|
|
85
89
|
// Nothing changed, nothing written: most waiters' polls change nothing, and
|
|
86
90
|
// an unchanged file tells a waiter it can poll less often (src/acquire.mjs nextPoll).
|
|
87
91
|
const text = JSON.stringify(s, null, 1);
|
|
@@ -101,11 +105,12 @@ function change(fn, lock) {
|
|
|
101
105
|
lock.release();
|
|
102
106
|
if (moved && kicks) try { kick(); } catch {} // after the lock, which the broker takes next
|
|
103
107
|
startResets(written);
|
|
108
|
+
recordEnds(written);
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
// Every pid the state names, whose start times reap() checks.
|
|
108
|
-
export const pidsOf = s => [...(s.leases || []).map(l => l.pid), ...(s.queue || []).map(q => q.pid || q.keptFor), ...(s.resets || []).flatMap(x => [x.pid, x.cpid])];
|
|
113
|
+
export const pidsOf = s => [...(s.leases || []).map(l => l.pid), ...(s.queue || []).map(q => q.pid || q.keptFor), ...(s.resets || []).flatMap(x => [x.pid, x.cpid]), ...(s.afters || []).map(x => x.pid)];
|
|
109
114
|
|
|
110
115
|
// Read those start times before taking the lock, so reap() under it finds them in
|
|
111
116
|
// makeAlive's cache instead of running ps: on 2026-11-11 that ps (100 to 700 ms on a
|
|
@@ -140,18 +145,26 @@ export function withStateIfRoom(fn) {
|
|
|
140
145
|
// The state as last written, without the lock and without reaping: what dibs
|
|
141
146
|
// web shows. Writes are a rename, so this never sees half a file; a holder that
|
|
142
147
|
// died shows until the next dibs call reaps it.
|
|
143
|
-
export function peek() { return read().s; }
|
|
148
|
+
export function peek() { return read(false).s; }
|
|
144
149
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
150
|
+
// A state file that doesn't parse (a disk error, a power cut, an editor) is put right under the
|
|
151
|
+
// lock before anyone reads it (src/lock.mjs heals it from state.json.bak, src/durable.mjs), and
|
|
152
|
+
// what came back and what was lost goes in the alerts. Looked at again here in case that couldn't
|
|
153
|
+
// be done; a reader without the lock shows the last good copy and changes nothing. A file that
|
|
154
|
+
// can't be read at all (not one that's broken) throws: starting fresh over it would forget
|
|
155
|
+
// every lease for a passing error.
|
|
156
|
+
function read(locked = true) {
|
|
157
|
+
let raw = null;
|
|
158
|
+
const load = () => { try { raw = fs.readFileSync(paths.state, 'utf8'); } catch (e) { if (e.code !== 'ENOENT') throw e; raw = null; } };
|
|
159
|
+
load();
|
|
160
|
+
let s = raw == null ? null : parsed(raw);
|
|
161
|
+
if (raw != null && !s && locked && heal(paths.state)) { load(); s = raw == null ? null : parsed(raw); }
|
|
162
|
+
if (raw != null && !s) {
|
|
163
|
+
// Moved aside first, so the write that follows doesn't keep the broken file as the last good copy.
|
|
164
|
+
if (locked) try { fs.renameSync(paths.state, `${paths.state}.corrupt-${now()}`); } catch {}
|
|
165
|
+
s = lastGood(paths.state)?.v; raw = null;
|
|
154
166
|
}
|
|
167
|
+
s ||= { seq: 0, leases: [], queue: [] };
|
|
155
168
|
s.seq ||= 0; s.leases ||= []; s.queue ||= [];
|
|
156
169
|
return { s, raw };
|
|
157
170
|
}
|
|
@@ -169,7 +182,7 @@ function reap(s) {
|
|
|
169
182
|
killLease(l);
|
|
170
183
|
// Its dibs was killed, so nobody recorded what it measured. A job big enough
|
|
171
184
|
// to get its dibs killed is the one the next run most needs to plan for.
|
|
172
|
-
if (l.peak?.mem) record(l.key, t - l.start - (l.pausedMs || 0), l.who, peakOf(l), true);
|
|
185
|
+
if (l.peak?.mem) record(l.key, t - l.start - (l.pausedMs || 0), l.who, peakOf(l), true, l.repo);
|
|
173
186
|
return false;
|
|
174
187
|
});
|
|
175
188
|
// A waiter whose process is gone leaves the line, however it went: a place
|
|
@@ -209,6 +222,17 @@ function reap(s) {
|
|
|
209
222
|
}
|
|
210
223
|
return q.pid || (q.keepUntil && t < q.keepUntil);
|
|
211
224
|
});
|
|
225
|
+
// A job waiting --after another (src/after.mjs) whose dibs is gone leaves with it, as a waiter does.
|
|
226
|
+
if (s.afters) {
|
|
227
|
+
s.afters = s.afters.filter(x => {
|
|
228
|
+
if (alive(x.pid, x.pstart)) return true;
|
|
229
|
+
vanished.push({ at: t, kind: 'left', id: x.id, res: x.res, who: x.who, type: 'after', ms: t - x.enq, why: 'gone' });
|
|
230
|
+
return false;
|
|
231
|
+
});
|
|
232
|
+
if (!s.afters.length) delete s.afters;
|
|
233
|
+
}
|
|
234
|
+
// A dibs halt past its time lifts itself (src/halt.mjs).
|
|
235
|
+
if (s.halt?.until != null && t >= s.halt.until) delete s.halt;
|
|
212
236
|
// What the owner stopped, for a waiter that finds its place gone to say why.
|
|
213
237
|
if (s.stopped) {
|
|
214
238
|
for (const id of Object.keys(s.stopped)) if (t - s.stopped[id].at > STOPPED_FOR) delete s.stopped[id];
|
|
@@ -257,7 +281,7 @@ const HISTORY_CHUNK = 256 * 1024; // about 2,000 lines, so one read nearly alw
|
|
|
257
281
|
export function history() {
|
|
258
282
|
const lines = tail(paths.history, HISTORY_KEEP);
|
|
259
283
|
if (lines.length < HISTORY_KEEP) lines.unshift(...tail(paths.historyOlder, HISTORY_KEEP - lines.length));
|
|
260
|
-
return lines.slice(-HISTORY_KEEP).
|
|
284
|
+
return jsonLines(lines.slice(-HISTORY_KEEP).join('\n'));
|
|
261
285
|
}
|
|
262
286
|
|
|
263
287
|
// The last `need` lines of a file (fewer if it has fewer), none for an empty or missing one.
|
|
@@ -286,8 +310,10 @@ function tail(file, need) {
|
|
|
286
310
|
// only: its time says nothing about a run's (schedule.mjs typical skips it).
|
|
287
311
|
// Run times are worth less than the run: on a full disk this one goes unrecorded.
|
|
288
312
|
// A lease's peak for its history line, marked when the watcher cleared caches during it.
|
|
289
|
-
|
|
290
|
-
export
|
|
291
|
-
|
|
313
|
+
// cpuMs: the CPU it had in all (src/measure.mjs), so a later run of the same command is judged against its own.
|
|
314
|
+
export const peakOf = l => (l.peak ? { ...l.peak, ...(l.cleaned && { cleaned: true }), ...(l.cpuMs != null && { cpuMs: l.cpuMs }) } : l.peak);
|
|
315
|
+
// repo: the project it ran in, so a size learned in one repo isn't lent to the same command in another (src/measure.mjs learned).
|
|
316
|
+
export function record(key, duration, who, peak, failed = false, repo = null) {
|
|
317
|
+
try { fs.appendFileSync(paths.history, JSON.stringify({ key, dur: duration, who, at: now(), ...(repo && { repo }), ...(peak ? { mem: peak.mem, cpu: peak.cpu, ...(peak.fit && { fit: true }), ...(peak.in != null && { peakIn: Math.round(peak.in) }), ...(peak.ate != null && { ate: Math.round(peak.ate) }), ...(peak.cleaned && { cleaned: true }), ...(peak.cpuMs != null && { cpuMs: Math.round(peak.cpuMs) }) } : {}), ...(failed && { failed: true }) }) + '\n'); }
|
|
292
318
|
catch (e) { if (!noSpace(e)) throw e; }
|
|
293
319
|
}
|