@dibssoftware/dibs 0.0.179 → 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 +23 -2
- package/README.md +4 -2
- package/bin/dibs-guard.mjs +10 -1
- package/bin/dibs.mjs +28 -9
- package/docs/benchmarks.md +1 -1
- package/docs/files.md +1 -1
- package/docs/guard.md +6 -0
- package/docs/questions.md +6 -2
- package/docs/reference.md +4 -4
- package/docs/relay.md +9 -7
- package/docs/releasing.md +4 -3
- package/docs/scheduling.md +4 -4
- package/docs/windows.md +14 -0
- package/package.json +1 -1
- package/skills/dibs/SKILL.md +5 -5
- package/src/acquire.mjs +91 -26
- package/src/agents.mjs +7 -22
- package/src/alerts.mjs +59 -21
- package/src/board.mjs +1 -2
- package/src/broker.mjs +26 -11
- package/src/commands.mjs +25 -9
- package/src/config.mjs +21 -4
- package/src/cool.mjs +104 -9
- package/src/diskwarn.mjs +4 -0
- package/src/events.mjs +10 -1
- package/src/files.mjs +49 -87
- package/src/guard.mjs +24 -8
- package/src/guardd.mjs +97 -0
- package/src/guardw.mjs +19 -0
- package/src/later.mjs +20 -25
- package/src/lock.mjs +292 -0
- package/src/measure.mjs +9 -4
- package/src/ondemand.mjs +5 -2
- package/src/override.mjs +39 -2
- package/src/plain.mjs +2 -2
- package/src/platform.mjs +165 -35
- package/src/preempt.mjs +51 -3
- package/src/primer.mjs +1 -1
- package/src/proc.mjs +35 -5
- package/src/questions.mjs +8 -22
- package/src/relay.mjs +10 -22
- package/src/remote.mjs +12 -8
- package/src/schedule.mjs +139 -26
- package/src/serve.mjs +16 -3
- package/src/service.mjs +4 -3
- package/src/state.mjs +139 -47
- package/src/stats.mjs +3 -2
- package/src/talk.mjs +160 -77
- package/src/trust.mjs +7 -1
- package/src/util.mjs +28 -2
- package/src/version.mjs +1 -1
- package/src/web.mjs +15 -25
- package/src/worker.mjs +2 -1
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');
|
|
@@ -490,7 +475,7 @@ function historyOf(since, b, t = now()) {
|
|
|
490
475
|
// local-only: telling an agent something or answering its question arrives as "Message
|
|
491
476
|
// from the person", which agents act on, shell commands included; the hook edits
|
|
492
477
|
// ~/.claude/settings.json; the hours decide when the person gets asked.
|
|
493
|
-
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']);
|
|
494
479
|
// Only for a device paired with --allow-actions.
|
|
495
480
|
const REMOTE_ACT = [/^\/api\/jobs\/[^/]+\/(boost|pause|resume|stop)$/, /^\/api\/cap$/, /^\/api\/pace$/, /^\/api\/later\/[^/]+\/cancel$/];
|
|
496
481
|
// null when a remote device may make this call, else 'look' (it needs --allow-actions) or 'local' (never remotely).
|
|
@@ -529,8 +514,13 @@ export async function api({ method = 'GET', path: where = '/', body = null, sess
|
|
|
529
514
|
const b = await board();
|
|
530
515
|
const t = now();
|
|
531
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 });
|
|
532
521
|
return ok({ ...b, agents: people(b, posts), posts, now: t });
|
|
533
522
|
}
|
|
523
|
+
if (route === '/api/posts') return ok(readPosts({ since: now() - DAY, limit: POSTS_SHOWN }).map(shown));
|
|
534
524
|
if (route === '/api/questions') return ok(scrub(fresh('questions', () => questionsJson(loadConfig()))));
|
|
535
525
|
if (route === '/api/threads') {
|
|
536
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 = {};
|