@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/util.mjs
CHANGED
|
@@ -51,10 +51,12 @@ export async function inProcessAsync(fn) {
|
|
|
51
51
|
}
|
|
52
52
|
// What die() last said and the code it exited with, for bin/dibs.mjs's record
|
|
53
53
|
// of a lost job or a crash: a command that exits 76 on its own is neither.
|
|
54
|
-
export let lastDie = '', lastDieCode = null;
|
|
54
|
+
export let lastDie = '', lastDieCode = null, lastDieAt = '';
|
|
55
55
|
export function die(msg, code = 2) {
|
|
56
56
|
lastDie = String(msg);
|
|
57
57
|
lastDieCode = code;
|
|
58
|
+
// Where dibs gave up, for the record of a crash or a service that gave up (bin/dibs.mjs).
|
|
59
|
+
if (code === 70 || code === 75) lastDieAt = new Error().stack;
|
|
58
60
|
if (throwing) throw Object.assign(new Error(msg), { status: code === 75 ? 503 : 500, exitCode: code, ...(code === 75 && { retryAfter: RETRY_AFTER }) });
|
|
59
61
|
const red = !CALM.has(code) && !process.env.NO_COLOR && (!!process.env.FORCE_COLOR || (process.stderr.isTTY && process.env.TERM !== 'dumb'));
|
|
60
62
|
process.stderr.write(`${red ? '\x1b[31mdibs:\x1b[39m' : 'dibs:'} ${msg}\n`);
|
|
@@ -147,7 +149,14 @@ export function dur(t) {
|
|
|
147
149
|
const SECRETISH = /\b([A-Z0-9_]*(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|AUTH)[A-Z0-9_]*=)\S+|(--?(?:token|password|secret|api-key|key)[= ])\S+/gi;
|
|
148
150
|
export const masked = s => (typeof s === 'string' ? s.replace(SECRETISH, (m, a, b) => `${a || b}***`) : s);
|
|
149
151
|
|
|
150
|
-
|
|
152
|
+
// One formatter for every clock: toLocaleTimeString builds a new one each call, about
|
|
153
|
+
// 0.1 ms, and the board prints hundreds (24 to 157 ms of a board on a busy Mac).
|
|
154
|
+
let clockFormat;
|
|
155
|
+
export const clock = t => {
|
|
156
|
+
const d = new Date(t);
|
|
157
|
+
if (Number.isNaN(d.getTime())) return d.toLocaleTimeString();
|
|
158
|
+
return (clockFormat ??= new Intl.DateTimeFormat([], { hour: '2-digit', minute: '2-digit' })).format(d);
|
|
159
|
+
};
|
|
151
160
|
// A time later today reads as a clock; another day gets its date too, so a retry weeks off doesn't look like tonight.
|
|
152
161
|
export const when = (t, from = now()) => new Date(t).toDateString() === new Date(from).toDateString() ? `at ${clock(t)}` : `on ${new Date(t).toLocaleDateString('en-CA')} at ${clock(t)}`;
|
|
153
162
|
|
|
@@ -182,3 +191,20 @@ export function indexed(hist) {
|
|
|
182
191
|
INDEX.set(hist, x);
|
|
183
192
|
return x;
|
|
184
193
|
}
|
|
194
|
+
|
|
195
|
+
// A waiter's dibs stamps polledAt on its place at most this often (src/acquire.mjs decide).
|
|
196
|
+
export const POLLED_EVERY = 60e3;
|
|
197
|
+
// Longer than this without a stamp, nobody is deciding for the place: it holds nobody back
|
|
198
|
+
// (src/schedule.mjs), and the board says so.
|
|
199
|
+
export const UNPOLLED = 3 * POLLED_EVERY;
|
|
200
|
+
// Longer than this, it leaves the line (src/state.mjs reap). On 2026-11-04 a place its own
|
|
201
|
+
// process had stopped deciding for sat at the head of heavy for 21 h.
|
|
202
|
+
export const GHOST_AFTER = 10 * POLLED_EVERY;
|
|
203
|
+
// A place without a stamp (made before dibs stamped them) isn't judged.
|
|
204
|
+
export const unpolled = (q, t, after = UNPOLLED) => !!q.pid && q.polledAt != null && t - q.polledAt > after;
|
|
205
|
+
// A mkdir lock someone else holds: EEXIST, or on Windows EPERM, while the last
|
|
206
|
+
// holder's lock folder is still being deleted (a dibs crashed on it, 2026-11-03).
|
|
207
|
+
export const lockHeld = e => e.code === 'EEXIST' || (process.platform === 'win32' && e.code === 'EPERM');
|
|
208
|
+
// Giving a mkdir lock back. Windows won't delete a file another process has open,
|
|
209
|
+
// as a waiter reading the lock's pid does, so it's tried a few more times.
|
|
210
|
+
export const unlock = dir => fs.rmSync(dir, { recursive: true, force: true, maxRetries: 10, retryDelay: 10 });
|
package/src/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Bump with every release and add a matching section at the top of CHANGELOG.md.
|
|
2
|
-
export const VERSION = '0.0.
|
|
2
|
+
export const VERSION = '0.0.180';
|
package/src/web.mjs
CHANGED
|
@@ -37,6 +37,7 @@ import { AGENT_ENV, logChange } from './owner.mjs';
|
|
|
37
37
|
import { PRIORITIES } from './schedule.mjs';
|
|
38
38
|
import { die, now, log, dur, clock, masked, inProcess } from './util.mjs';
|
|
39
39
|
import { peek } from './state.mjs';
|
|
40
|
+
import { underLock, commit } from './lock.mjs';
|
|
40
41
|
import { boardJson, paceJson } from './commands.mjs';
|
|
41
42
|
import { questionsJson, hours as hoursOf } from './questions.mjs';
|
|
42
43
|
import { threadsJson } from './talk.mjs';
|
|
@@ -57,6 +58,8 @@ const ASSETS = path.join(ROOT, 'web');
|
|
|
57
58
|
export const DEFAULT_WEB_PORT = 7421; // the coordinator has 7420
|
|
58
59
|
const FILE = path.join(HOME, 'web.json');
|
|
59
60
|
const LOCK = path.join(HOME, 'web.lock');
|
|
61
|
+
// Writes take milliseconds: a holder still at it past this is stuck on something else.
|
|
62
|
+
const LOCK_WAIT = 5000;
|
|
60
63
|
|
|
61
64
|
const MIN = 6e4, HOUR = 36e5, DAY = 24 * HOUR;
|
|
62
65
|
// Long enough to walk from the terminal to the browser, short enough that a code
|
|
@@ -136,37 +139,19 @@ function load() {
|
|
|
136
139
|
|
|
137
140
|
// `dibs pair` and the server both write web.json; a short mkdir lock keeps one from undoing the other.
|
|
138
141
|
function locked(fn) {
|
|
139
|
-
|
|
140
|
-
const t0 = now();
|
|
141
|
-
for (;;) {
|
|
142
|
-
try { fs.mkdirSync(LOCK); break; } catch (e) {
|
|
143
|
-
if (e.code !== 'EEXIST') throw e;
|
|
144
|
-
// A stale lock is renamed aside before it's removed: two processes breaking it at
|
|
145
|
-
// once can't then delete the fresh lock one of them just took.
|
|
146
|
-
try {
|
|
147
|
-
if (now() - fs.statSync(LOCK).mtimeMs > 5000) {
|
|
148
|
-
const aside = `${LOCK}.stale.${process.pid}`;
|
|
149
|
-
fs.renameSync(LOCK, aside);
|
|
150
|
-
fs.rmSync(aside, { recursive: true, force: true });
|
|
151
|
-
}
|
|
152
|
-
} catch {}
|
|
153
|
-
if (now() - t0 > 5000) throw new Error(`${LOCK} stayed locked; remove it if no dibs is running`);
|
|
154
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
try {
|
|
142
|
+
const r = underLock(LOCK, h => {
|
|
158
143
|
const w = load();
|
|
159
144
|
const out = fn(w);
|
|
160
145
|
const t = now();
|
|
161
146
|
w.codes = w.codes.filter(c => c.exp > t);
|
|
162
147
|
// Remote entries are {at, ip, client}; local ones (and older remote ones) are bare times.
|
|
163
148
|
for (const k of ['fails', 'rfails', 'registered', 'rregistered']) w[k] = w[k].filter(x => t - (x?.at ?? x) < FAIL_WINDOW);
|
|
164
|
-
for (const k of ['grants', 'tokens']) for (const [
|
|
165
|
-
|
|
166
|
-
fs.writeFileSync(tmp, JSON.stringify(w), { mode: 0o600 });
|
|
167
|
-
fs.renameSync(tmp, FILE);
|
|
149
|
+
for (const k of ['grants', 'tokens']) for (const [key, x] of Object.entries(w[k])) if (x.exp <= t) delete w[k][key];
|
|
150
|
+
commit(h, FILE, JSON.stringify(w), { mode: 0o600 });
|
|
168
151
|
return out;
|
|
169
|
-
}
|
|
152
|
+
}, { wait: LOCK_WAIT, files: [FILE] });
|
|
153
|
+
if (!r) throw new Error(`${LOCK} is held by a dibs that's still running; try again in a moment`);
|
|
154
|
+
return r.out;
|
|
170
155
|
}
|
|
171
156
|
|
|
172
157
|
const norm = s => String(s || '').toUpperCase().replace(/[^0-9A-Z]/g, '').replace(/O/g, '0').replace(/[IL]/g, '1');
|
|
@@ -321,18 +306,20 @@ export function snapshot(j, t = now()) {
|
|
|
321
306
|
// What's wrong and what fixes it (src/alerts.mjs), open ones first.
|
|
322
307
|
alerts: (j.alerts || []).map(a => ({ id: a.id, cause: a.cause, level: a.level, title: a.title, why: a.why || null, detail: a.detail || null, fix: a.fix,
|
|
323
308
|
job: a.job ?? null, who: a.who || null, since: a.since, resolvedAt: a.resolvedAt || null, dismissed: !!a.dismissed })),
|
|
309
|
+
// Agents waiting on dibs listen: a message to them wakes them within seconds.
|
|
310
|
+
listening: Array.isArray(j.listening) ? j.listening : [],
|
|
324
311
|
};
|
|
325
312
|
}
|
|
326
313
|
|
|
327
314
|
// The agents, merged from their jobs and their progress posts.
|
|
328
315
|
function people(b, posts) {
|
|
329
316
|
const ts = taskList(posts);
|
|
330
|
-
const names = new Set([...b.jobs.map(x => x.who), ...b.later.map(x => x.who), ...ts.map(x => x.who)]);
|
|
317
|
+
const names = new Set([...b.jobs.map(x => x.who), ...b.later.map(x => x.who), ...ts.map(x => x.who), ...(b.listening || [])]);
|
|
331
318
|
const last = new Map();
|
|
332
319
|
for (const p of posts) last.set(p.who, p);
|
|
333
320
|
return [...names].map(who => ({
|
|
334
321
|
who, jobs: b.jobs.filter(x => x.who === who), later: b.later.filter(x => x.who === who), tasks: ts.filter(x => x.who === who),
|
|
335
|
-
lastPost: last.get(who) || null,
|
|
322
|
+
lastPost: last.get(who) || null, listening: (b.listening || []).includes(who),
|
|
336
323
|
})).sort((a, b2) => (b2.lastPost?.at || 0) - (a.lastPost?.at || 0) || b2.jobs.length - a.jobs.length);
|
|
337
324
|
}
|
|
338
325
|
|
|
@@ -488,7 +475,7 @@ function historyOf(since, b, t = now()) {
|
|
|
488
475
|
// local-only: telling an agent something or answering its question arrives as "Message
|
|
489
476
|
// from the person", which agents act on, shell commands included; the hook edits
|
|
490
477
|
// ~/.claude/settings.json; the hours decide when the person gets asked.
|
|
491
|
-
const REMOTE_READ = new Set(['/api/board', '/api/questions', '/api/threads', '/api/later', '/api/history', '/api/stats', '/api/settings', '/api/machines']);
|
|
478
|
+
const REMOTE_READ = new Set(['/api/board', '/api/posts', '/api/questions', '/api/threads', '/api/later', '/api/history', '/api/stats', '/api/settings', '/api/machines']);
|
|
492
479
|
// Only for a device paired with --allow-actions.
|
|
493
480
|
const REMOTE_ACT = [/^\/api\/jobs\/[^/]+\/(boost|pause|resume|stop)$/, /^\/api\/cap$/, /^\/api\/pace$/, /^\/api\/later\/[^/]+\/cancel$/];
|
|
494
481
|
// null when a remote device may make this call, else 'look' (it needs --allow-actions) or 'local' (never remotely).
|
|
@@ -527,8 +514,13 @@ export async function api({ method = 'GET', path: where = '/', body = null, sess
|
|
|
527
514
|
const b = await board();
|
|
528
515
|
const t = now();
|
|
529
516
|
const posts = readPosts({ since: t - DAY, limit: POSTS_SHOWN }).map(shown);
|
|
517
|
+
// ?posts=0: the day's posts (most of the board's bytes) stay apart, at GET /api/posts, for
|
|
518
|
+
// the one view that lists them; the agents still carry each one's tasks and last post.
|
|
519
|
+
// The page's first paint through the relay waits on a third of the bytes.
|
|
520
|
+
if (q.get('posts') === '0') return ok({ ...b, agents: people(b, posts), posts: [], postsApart: true, now: t });
|
|
530
521
|
return ok({ ...b, agents: people(b, posts), posts, now: t });
|
|
531
522
|
}
|
|
523
|
+
if (route === '/api/posts') return ok(readPosts({ since: now() - DAY, limit: POSTS_SHOWN }).map(shown));
|
|
532
524
|
if (route === '/api/questions') return ok(scrub(fresh('questions', () => questionsJson(loadConfig()))));
|
|
533
525
|
if (route === '/api/threads') {
|
|
534
526
|
const j = fresh('threads', () => threadsJson());
|
package/src/worker.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
8
|
import { HOME, machine, resCfg } from './config.mjs';
|
|
9
9
|
import { withState, history } from './state.mjs';
|
|
10
10
|
import { used } from './schedule.mjs';
|
|
11
|
-
import { markIdle } from './acquire.mjs';
|
|
11
|
+
import { markIdle, tableFirst } from './acquire.mjs';
|
|
12
12
|
import { boardOf } from './board.mjs';
|
|
13
13
|
import { singleInstance } from './proc.mjs';
|
|
14
14
|
import { OS, stopTree } from './platform.mjs';
|
|
@@ -39,6 +39,7 @@ const EPHEMERAL_LOST_BUSY = 10 * 6e4;
|
|
|
39
39
|
function report(cfg, name, running, inUse = new Set()) {
|
|
40
40
|
const m = machine();
|
|
41
41
|
const hist = history();
|
|
42
|
+
tableFirst();
|
|
42
43
|
const { busy, board } = withState(s => {
|
|
43
44
|
markIdle(s);
|
|
44
45
|
const out = {};
|