@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/notes.mjs
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// dibs init: telling the coding agents on this machine that dibs is here.
|
|
2
|
+
//
|
|
3
|
+
// dibs.md the agent instructions, made from skills/dibs/SKILL.md (one source,
|
|
4
|
+
// no second copy to drift), in the folder dibs is installed in.
|
|
5
|
+
// Rewritten on every install and upgrade, so it matches the version.
|
|
6
|
+
// the block a few marked lines in the agents' own instruction files saying to
|
|
7
|
+
// read dibs.md before builds, tests, simulators or deploys:
|
|
8
|
+
// ~/.claude/CLAUDE.md when ~/.claude exists (made if missing)
|
|
9
|
+
// ~/.codex/AGENTS.md when ~/.codex exists (made if missing)
|
|
10
|
+
// CLAUDE.md and AGENTS.md at the root of the git repo dibs runs in,
|
|
11
|
+
// when that isn't the home folder: only files already there, unless
|
|
12
|
+
// asked with dibs init --repo
|
|
13
|
+
//
|
|
14
|
+
// Only what's between the markers is ever written; the rest of a file stays byte for
|
|
15
|
+
// byte. Each write goes to a temp file beside the real one, with its mode, then is
|
|
16
|
+
// renamed over it: a full disk once emptied a file written in place. A symlinked
|
|
17
|
+
// file is written where the link points, so the link stays a link.
|
|
18
|
+
// DIBS_NO_AGENT_NOTES=1 turns all of it off.
|
|
19
|
+
import fs from 'node:fs';
|
|
20
|
+
import os from 'node:os';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
import { execFileSync } from 'node:child_process';
|
|
23
|
+
import { fileURLToPath } from 'node:url';
|
|
24
|
+
import { HOME } from './config.mjs';
|
|
25
|
+
import { VERSION } from './version.mjs';
|
|
26
|
+
import { die } from './util.mjs';
|
|
27
|
+
|
|
28
|
+
export const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
29
|
+
const START = '<!-- dibs:start -->', END = '<!-- dibs:end -->';
|
|
30
|
+
const BLOCK_RE = /<!-- dibs:start -->[\s\S]*?<!-- dibs:end -->(\r?\n)?/;
|
|
31
|
+
// Which version and folder the notes were last written for (src/notes.mjs stale()).
|
|
32
|
+
const STAMP = path.join(HOME, 'notes.json');
|
|
33
|
+
export const off = () => !!process.env.DIBS_NO_AGENT_NOTES && process.env.DIBS_NO_AGENT_NOTES !== '0';
|
|
34
|
+
|
|
35
|
+
// The agent instructions: SKILL.md without its front matter and title, under a header
|
|
36
|
+
// saying where it came from.
|
|
37
|
+
export function dibsMd(root = ROOT) {
|
|
38
|
+
let skill = '';
|
|
39
|
+
try { skill = fs.readFileSync(path.join(root, 'skills', 'dibs', 'SKILL.md'), 'utf8'); } catch {}
|
|
40
|
+
const body = skill.replace(/^---\n[\s\S]*?\n---\n/, '').replace(/^\s*# dibs\s*\n/, '').replace(/<!-- dibs:rules:(start|end) -->\n/g, '').trim();
|
|
41
|
+
return [
|
|
42
|
+
'# dibs: instructions for coding agents',
|
|
43
|
+
'',
|
|
44
|
+
`Written by dibs ${VERSION} when it was installed here, and rewritten on every install and upgrade, so edits don't last.`,
|
|
45
|
+
`Docs: https://dibs.cc, and ${path.join(root, 'README.md')}. Every command: \`dibs help all\`.`,
|
|
46
|
+
'',
|
|
47
|
+
body || 'Run builds, tests, simulators and deploys through dibs: `dibs run <resource> -m "why" -- <command>`. `dibs help` lists everything.',
|
|
48
|
+
'',
|
|
49
|
+
].join('\n');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const block = file => [START, '## dibs',
|
|
53
|
+
`This machine runs dibs, the CLI that coding agents use to share simulators, builds, tests and deploys. Read ${file} before running builds, tests, simulators or deploys. Docs: https://dibs.cc`,
|
|
54
|
+
END].join('\n');
|
|
55
|
+
|
|
56
|
+
// Write whole and rename into place, keeping the old file's mode.
|
|
57
|
+
function writeAtomic(file, text) {
|
|
58
|
+
let real = file, mode = 0o644;
|
|
59
|
+
try { real = fs.realpathSync(file); mode = fs.statSync(real).mode & 0o7777; } catch {}
|
|
60
|
+
fs.mkdirSync(path.dirname(real), { recursive: true });
|
|
61
|
+
const tmp = `${real}.dibs-${process.pid}`;
|
|
62
|
+
try {
|
|
63
|
+
fs.writeFileSync(tmp, text, { mode });
|
|
64
|
+
fs.chmodSync(tmp, mode);
|
|
65
|
+
fs.renameSync(tmp, real);
|
|
66
|
+
} catch (e) { try { fs.rmSync(tmp, { force: true }); } catch {} throw e; }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// text with the block in it: replaced where the markers are, else added at the end.
|
|
70
|
+
// Line endings follow the file's own.
|
|
71
|
+
export function withBlock(text, b) {
|
|
72
|
+
const nl = /\r\n/.test(text) ? '\r\n' : '\n';
|
|
73
|
+
const mine = b.replace(/\n/g, nl);
|
|
74
|
+
if (BLOCK_RE.test(text)) return text.replace(BLOCK_RE, (m, end) => mine + (end || ''));
|
|
75
|
+
if (!text) return mine + nl;
|
|
76
|
+
const gap = text.endsWith(nl + nl) ? '' : text.endsWith(nl) ? nl : nl + nl;
|
|
77
|
+
return text + gap + mine + nl;
|
|
78
|
+
}
|
|
79
|
+
// text without the block. At the end of the file, the blank line withBlock put in front goes too.
|
|
80
|
+
export function withoutBlock(text) {
|
|
81
|
+
const m = text.match(BLOCK_RE);
|
|
82
|
+
if (!m) return text;
|
|
83
|
+
let before = text.slice(0, m.index);
|
|
84
|
+
const after = text.slice(m.index + m[0].length);
|
|
85
|
+
if (!after) before = before.replace(/(\r?\n)\r?\n$/, '$1');
|
|
86
|
+
return before + after;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The git repo the command runs in, unless it's the home folder itself.
|
|
90
|
+
function repoRoot(cwd) {
|
|
91
|
+
try {
|
|
92
|
+
const top = execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 3000 }).trim();
|
|
93
|
+
return top && path.resolve(top) !== path.resolve(os.homedir()) ? top : null;
|
|
94
|
+
} catch { return null; }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// The instruction files the block goes in. made: may be created when missing.
|
|
98
|
+
function targets(cwd, repo) {
|
|
99
|
+
const home = os.homedir(), out = [];
|
|
100
|
+
if (fs.existsSync(path.join(home, '.claude'))) out.push({ file: path.join(home, '.claude', 'CLAUDE.md'), made: true });
|
|
101
|
+
if (fs.existsSync(path.join(home, '.codex'))) out.push({ file: path.join(home, '.codex', 'AGENTS.md'), made: true });
|
|
102
|
+
const top = repoRoot(cwd);
|
|
103
|
+
if (top) {
|
|
104
|
+
const there = ['CLAUDE.md', 'AGENTS.md'].map(n => path.join(top, n)).filter(f => fs.existsSync(f));
|
|
105
|
+
for (const f of there) out.push({ file: f, made: false });
|
|
106
|
+
if (repo && !there.length) out.push({ file: path.join(top, 'CLAUDE.md'), made: true });
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Where dibs.md goes: the install folder, or ~/.dibs when that can't be written
|
|
112
|
+
// (an npm install owned by root, say).
|
|
113
|
+
function mdPlace(root) {
|
|
114
|
+
const f = path.join(root, 'dibs.md');
|
|
115
|
+
try { fs.accessSync(root, fs.constants.W_OK); return f; } catch { return path.join(HOME, 'dibs.md'); }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Write dibs.md and the blocks. Returns the files that changed.
|
|
119
|
+
export function write({ root = ROOT, cwd = process.cwd(), repo = false } = {}) {
|
|
120
|
+
const changed = [];
|
|
121
|
+
const md = mdPlace(root);
|
|
122
|
+
const text = dibsMd(root);
|
|
123
|
+
let old = null;
|
|
124
|
+
try { old = fs.readFileSync(md, 'utf8'); } catch {}
|
|
125
|
+
if (old !== text) { writeAtomic(md, text); changed.push(md); }
|
|
126
|
+
const b = block(md);
|
|
127
|
+
for (const t of targets(cwd, repo)) {
|
|
128
|
+
let cur = null;
|
|
129
|
+
try { cur = fs.readFileSync(t.file, 'utf8'); } catch (e) { if (e.code !== 'ENOENT') throw e; }
|
|
130
|
+
if (cur == null && !t.made) continue;
|
|
131
|
+
const next = withBlock(cur || '', b);
|
|
132
|
+
if (next !== cur) { writeAtomic(t.file, next); changed.push(t.file); }
|
|
133
|
+
}
|
|
134
|
+
try { fs.mkdirSync(HOME, { recursive: true }); fs.writeFileSync(STAMP, JSON.stringify({ version: VERSION, root })); } catch {}
|
|
135
|
+
return changed;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Take dibs.md and every block back out. Returns the files that changed.
|
|
139
|
+
export function remove({ root = ROOT, cwd = process.cwd() } = {}) {
|
|
140
|
+
const changed = [];
|
|
141
|
+
for (const md of new Set([path.join(root, 'dibs.md'), path.join(HOME, 'dibs.md')])) {
|
|
142
|
+
if (fs.existsSync(md)) { fs.rmSync(md); changed.push(md); }
|
|
143
|
+
}
|
|
144
|
+
for (const t of targets(cwd, false)) {
|
|
145
|
+
let cur;
|
|
146
|
+
try { cur = fs.readFileSync(t.file, 'utf8'); } catch { continue; }
|
|
147
|
+
const next = withoutBlock(cur);
|
|
148
|
+
if (next !== cur) { writeAtomic(t.file, next); changed.push(t.file); }
|
|
149
|
+
}
|
|
150
|
+
try { fs.rmSync(STAMP, { force: true }); } catch {}
|
|
151
|
+
return changed;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Whether the notes are behind this version or this folder: an npm install has no
|
|
155
|
+
// install script to write them (the package runs no scripts, by design), so its
|
|
156
|
+
// first dibs command after an install or upgrade does.
|
|
157
|
+
export function stale(root = ROOT) {
|
|
158
|
+
if (off()) return false;
|
|
159
|
+
try { const s = JSON.parse(fs.readFileSync(STAMP, 'utf8')); return s.version !== VERSION || s.root !== root; } catch { return true; }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// dibs init [--repo] [--remove] [--quiet]
|
|
163
|
+
export function init(args) {
|
|
164
|
+
const bad = args.find(a => !['--repo', '--remove', '--quiet'].includes(a));
|
|
165
|
+
if (bad) die(`unknown ${bad}. dibs init [--repo] [--remove]`);
|
|
166
|
+
if (off()) return console.log('DIBS_NO_AGENT_NOTES is set, so dibs leaves the agents\' instruction files alone.');
|
|
167
|
+
const quiet = args.includes('--quiet');
|
|
168
|
+
const changed = args.includes('--remove') ? remove() : write({ repo: args.includes('--repo') });
|
|
169
|
+
for (const f of changed) console.log(`${args.includes('--remove') ? 'cleaned' : 'wrote'} ${f}`);
|
|
170
|
+
if (!changed.length && !quiet) console.log('Nothing to change: dibs.md and the notes are up to date.');
|
|
171
|
+
}
|
package/src/notices.mjs
CHANGED
|
@@ -9,13 +9,15 @@
|
|
|
9
9
|
// dibs and every running one. Each notice has a name (idle:#12), so however
|
|
10
10
|
// many of them scan, an agent hears about each thing once.
|
|
11
11
|
import fs from 'node:fs';
|
|
12
|
-
import
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { paths, HOME } from './config.mjs';
|
|
14
|
+
import { peek, history } from './state.mjs';
|
|
13
15
|
import { notify } from './talk.mjs';
|
|
14
16
|
import { minutes, stuckFor } from './plain.mjs';
|
|
15
17
|
import { stuckLeases } from './acquire.mjs';
|
|
16
18
|
import { overAskLine } from './measure.mjs';
|
|
17
19
|
import { now, callerPid, clock } from './util.mjs';
|
|
18
|
-
import { read as readPosts, tasks, QUIET_AFTER } from './progress.mjs';
|
|
20
|
+
import { read as readPosts, tasks, QUIET_AFTER, EXPIRE_AFTER } from './progress.mjs';
|
|
19
21
|
import { quoted } from './style.mjs';
|
|
20
22
|
|
|
21
23
|
// Which runs look stuck and which used more memory than they asked for is
|
|
@@ -68,20 +70,43 @@ export function noticeScan(t = now()) {
|
|
|
68
70
|
} catch {}
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
// At most one nudge per task this often. On 2026-11-03, 5 of 35 notices were
|
|
74
|
+
// these, and agents were posting progress only to stop them.
|
|
75
|
+
export const NAG_EVERY = 2 * 36e5;
|
|
76
|
+
// An agent with no job running or waiting, and none run in this long, isn't
|
|
77
|
+
// working now: its open task waits quietly for it to come back.
|
|
78
|
+
export const AWAY_AFTER = 30 * 6e4;
|
|
79
|
+
const NAGS = path.join(HOME, 'nags.json');
|
|
80
|
+
|
|
81
|
+
// [to, once, text, task] for each task still in progress that needs a word
|
|
82
|
+
// from whoever posted it: past its ETA, or with no post for QUIET_AFTER.
|
|
83
|
+
// Expired tasks are let go. Only tasks posted from a Claude Code session: the
|
|
84
|
+
// hook is how the notice arrives. A subagent's task is nudged to that subagent;
|
|
85
|
+
// once it has ended (ended(k)), its lead hears once that it was left open.
|
|
86
|
+
// nagged: when each task was last nudged; working(k): whether the agent the
|
|
87
|
+
// notice would go to is at work now.
|
|
88
|
+
export function progressNoticesIn(posts, t = now(), { nagged = {}, working = () => true, ended = () => false } = {}) {
|
|
75
89
|
const out = [];
|
|
76
90
|
for (const k of tasks(posts, t)) {
|
|
77
91
|
if (k.state !== 'doing' || !k.session) continue;
|
|
78
|
-
const
|
|
92
|
+
const task = `${k.who}:${k.agentId || 'main'}:${k.task || k.project}`;
|
|
79
93
|
const name = k.task ? `"${k.task}"` : `in ${k.project || 'this folder'}`;
|
|
94
|
+
if (k.agentId && ended(k)) {
|
|
95
|
+
// Said once: nothing to do, it expires by itself; the lead only shouldn't be surprised.
|
|
96
|
+
const lead = `${task}:lead`;
|
|
97
|
+
if (nagged[lead] || !working({ ...k, agentId: null }) || !(k.overdue || t - k.last > QUIET_AFTER)) continue;
|
|
98
|
+
out.push([{ sessionId: k.session, who: k.who }, `left:${task}`, `your subagent ${k.label || k.agentId.slice(0, 8)} ended with its progress task ${name} still open `
|
|
99
|
+
+ `(last post at ${clock(k.last)}). Nothing to do: it's let go ${minutes(Math.max(k.last, k.eta || 0) + EXPIRE_AFTER - t)} from now. `
|
|
100
|
+
+ `If the work goes on, post it under your own task.`, lead]);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (t - (nagged[task] || 0) < NAG_EVERY || !working(k)) continue;
|
|
104
|
+
const to = { sessionId: k.session, who: k.who, ...(k.agentId && { agentId: k.agentId }) };
|
|
80
105
|
const again = (...more) => quoted(['dibs', 'progress', 'where it stands', ...(k.task ? ['--task', k.task] : []), ...more]);
|
|
81
|
-
if (k.overdue) out.push([to, `late:${
|
|
82
|
-
+ `If it's finished, say so: ${again('--done')}. If not, post where it stands with a new time: ${again('--eta', '30m')}
|
|
83
|
-
else if (t - k.last > QUIET_AFTER) out.push([to, `quiet:${
|
|
84
|
-
+ `Post where it stands (${again()}), or close it: --done if it's finished, --blocked if it's stuck
|
|
106
|
+
if (k.overdue) out.push([to, `late:${task}:${k.eta}`, `your progress task ${name} was due at ${clock(k.eta)} and is still open. `
|
|
107
|
+
+ `If it's finished, say so: ${again('--done')}. If not, post where it stands with a new time: ${again('--eta', '30m')}.`, task]);
|
|
108
|
+
else if (t - k.last > QUIET_AFTER) out.push([to, `quiet:${task}:${k.last}`, `your progress task ${name} has had no post for ${minutes(t - k.last)}. `
|
|
109
|
+
+ `Post where it stands (${again()}), or close it: --done if it's finished, --blocked if it's stuck.`, task]);
|
|
85
110
|
}
|
|
86
111
|
return out;
|
|
87
112
|
}
|
|
@@ -90,11 +115,25 @@ const DAY = 864e5;
|
|
|
90
115
|
// From the throttle watcher (src/cool.mjs), which is always running: no waiter needed.
|
|
91
116
|
export function progressScan(t = now()) {
|
|
92
117
|
try {
|
|
93
|
-
|
|
118
|
+
let nagged = {};
|
|
119
|
+
try { nagged = JSON.parse(fs.readFileSync(NAGS, 'utf8')); } catch {}
|
|
120
|
+
const s = peek(), hist = history();
|
|
121
|
+
// At work: a job running or waiting, or one run in the last AWAY_AFTER. A
|
|
122
|
+
// subagent counts only its own jobs (they carry its id) and its own posts.
|
|
123
|
+
const mine = k => x => x.sessionId === k.session && (k.agentId ? x.agentId === k.agentId : true);
|
|
124
|
+
const busy = k => (s.leases || []).some(mine(k)) || (s.queue || []).some(q => q.pid && mine(k)(q));
|
|
125
|
+
const working = k => (k.agentId ? busy(k) || t - k.last < AWAY_AFTER
|
|
126
|
+
: busy(k) || (s.leases || []).some(l => l.who === k.who) || hist.some(r => r.who === k.who && t - r.at < AWAY_AFTER));
|
|
127
|
+
const ended = k => !busy(k) && t - k.last >= AWAY_AFTER;
|
|
128
|
+
const before = JSON.stringify(nagged);
|
|
129
|
+
for (const [to, once, text, task] of progressNoticesIn(readPosts({ since: t - DAY }), t, { nagged, working, ended })) {
|
|
94
130
|
if (sent.has(once)) continue;
|
|
95
131
|
sent.add(once);
|
|
96
|
-
notify(to, once, text);
|
|
132
|
+
if (notify(to, once, text)) nagged[task] = t;
|
|
97
133
|
}
|
|
134
|
+
// A lead's one word about a subagent's task is kept as long as the task can be: never twice.
|
|
135
|
+
for (const [k, at] of Object.entries(nagged)) if (t - at >= (k.endsWith(':lead') ? DAY : NAG_EVERY)) delete nagged[k];
|
|
136
|
+
if (JSON.stringify(nagged) !== before) fs.writeFileSync(NAGS, JSON.stringify(nagged));
|
|
98
137
|
} catch {}
|
|
99
138
|
}
|
|
100
139
|
|
package/src/ondemand.mjs
CHANGED
|
@@ -26,6 +26,7 @@ import fs from 'node:fs';
|
|
|
26
26
|
import os from 'node:os';
|
|
27
27
|
import path from 'node:path';
|
|
28
28
|
import { spawn, execFile } from 'node:child_process';
|
|
29
|
+
import { runnable } from './platform.mjs';
|
|
29
30
|
import { fileURLToPath } from 'node:url';
|
|
30
31
|
import { HOME } from './config.mjs';
|
|
31
32
|
import { event } from './events.mjs';
|
|
@@ -186,7 +187,8 @@ const hhmm = (t = now()) => new Date(t).toTimeString().slice(0, 5);
|
|
|
186
187
|
export function boat(args, { timeout = 60e3 } = {}) {
|
|
187
188
|
return new Promise(resolve => {
|
|
188
189
|
// --no-update first: after `--` it would go to the command run on the VM.
|
|
189
|
-
|
|
190
|
+
const [cmd, ...argv] = runnable([process.env.DIBS_BOAT || 'boat', '--no-update', ...args]);
|
|
191
|
+
execFile(cmd, argv, { timeout, maxBuffer: 16 * 1024 ** 2, encoding: 'utf8', windowsVerbatimArguments: cmd === 'cmd.exe', windowsHide: true }, (e, out, err) => {
|
|
190
192
|
const r = { code: e ? (typeof e.code === 'number' ? e.code : 1) : 0, out: out || '', err: (err || e?.message || '').trim() };
|
|
191
193
|
const j = args[0] === 'exec' && !args.includes('--detach') ? json(r.out) : null;
|
|
192
194
|
if (j && typeof j.stdout === 'string') Object.assign(r, { out: j.stdout, err: (j.stderr || r.err).trim(), code: j.exitCode ?? r.code });
|
|
@@ -288,7 +290,8 @@ export function ondemand(list, srv, { port, tick = TICK, log: say = log, clock =
|
|
|
288
290
|
// The reverse forward lives as long as the VM is up, started again if it drops.
|
|
289
291
|
const forward = vm => {
|
|
290
292
|
if (vm.forward || !['waking', 'running'].includes(vm.state)) return;
|
|
291
|
-
const
|
|
293
|
+
const [cmd, ...argv] = runnable([process.env.DIBS_BOAT || 'boat', '--no-update', 'forward', vm.id, '--reverse', '--local', String(port)]);
|
|
294
|
+
const p = spawn(cmd, argv, { stdio: 'ignore', windowsVerbatimArguments: cmd === 'cmd.exe', windowsHide: true });
|
|
292
295
|
vm.forward = p;
|
|
293
296
|
p.on('exit', () => { vm.forward = null; if (['waking', 'running'].includes(vm.state)) setTimeout(() => forward(vm), 2000).unref(); });
|
|
294
297
|
p.on('error', () => {});
|
|
@@ -306,7 +309,7 @@ export function ondemand(list, srv, { port, tick = TICK, log: say = log, clock =
|
|
|
306
309
|
const w = workers.get(vm.name);
|
|
307
310
|
if (w) Object.assign(w, { pending: [], assigned: 0 });
|
|
308
311
|
};
|
|
309
|
-
// Marked can't-wake until a retry time: placement skips it, --on
|
|
312
|
+
// Marked can't-wake until a retry time: placement skips it, a job sent --on it runs on its sender with the reason, and dibs machines says so.
|
|
310
313
|
const block = (vm, why) => {
|
|
311
314
|
vm.cantWake = { why, until: now() + (QUOTA.test(why) ? QUOTA_BACKOFF : WAKE_BACKOFF) };
|
|
312
315
|
say(`${vm.name}: can't wake (${why}); not trying again until ${new Date(vm.cantWake.until).toISOString()}`);
|
package/src/override.mjs
CHANGED
|
@@ -20,10 +20,10 @@ import { tag, makeAlive, identity, isMine } from './proc.mjs';
|
|
|
20
20
|
import { descendants, processes, pidsIn, stopTree, lower, raise, OS } from './platform.mjs';
|
|
21
21
|
import { withState, history } from './state.mjs';
|
|
22
22
|
import { ownerPause, pauseLabel } from './preempt.mjs';
|
|
23
|
-
import { PRIORITIES, BACKGROUND, NEEDS_REASON, priority, byRank } from './schedule.mjs';
|
|
23
|
+
import { PRIORITIES, BACKGROUND, NEEDS_REASON, priority, byRank, roomFor } from './schedule.mjs';
|
|
24
24
|
import { actor } from './owner.mjs';
|
|
25
25
|
import { event } from './events.mjs';
|
|
26
|
-
import { die, now } from './util.mjs';
|
|
26
|
+
import { die, now, say, sleepSync, unpolled } from './util.mjs';
|
|
27
27
|
import { takeAgent, callKey } from './files.mjs';
|
|
28
28
|
import { quoted } from './style.mjs';
|
|
29
29
|
|
|
@@ -125,8 +125,9 @@ function setPrio(x, prio, act, who, reason = '') {
|
|
|
125
125
|
// cores, the rest off them. `from` is its priority before the change (runs
|
|
126
126
|
// started by an older dibs don't record their QoS). Returns the pids to move,
|
|
127
127
|
// found under the lock; they're moved after it, since a big tree takes a while.
|
|
128
|
-
//
|
|
129
|
-
|
|
128
|
+
// After a boost moves a job, the whole group is moved again this many times, CATCH_GAP ms
|
|
129
|
+
// apart: for children forked meanwhile, and a move lost to a fork in progress.
|
|
130
|
+
const CATCH_UP = 3, CATCH_GAP = 100;
|
|
130
131
|
function requeue(l, from) {
|
|
131
132
|
if (l.kind !== 'run' || !l.pgid || OS === 'windows') return null;
|
|
132
133
|
const bg = BACKGROUND.has(l.prio);
|
|
@@ -142,9 +143,16 @@ function requeue(l, from) {
|
|
|
142
143
|
export function boost(args) {
|
|
143
144
|
const who = actor();
|
|
144
145
|
const me = caller('boost');
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
const
|
|
146
|
+
const parsed = argsOf('boost', args);
|
|
147
|
+
let { words: [target, p] } = parsed;
|
|
148
|
+
const { reason, owner } = parsed;
|
|
149
|
+
// The priority before the id (dibs boost high 17727) reads the same.
|
|
150
|
+
if (target && p && !/^\d+$/.test(target) && PRIORITIES.includes(target) && /^\d+$/.test(p)) [target, p] = [p, target];
|
|
151
|
+
if (!target) die(`boost which job? Use: ${USAGE.boost}. ${IDS}`);
|
|
152
|
+
// A boost with a reason and no priority means move it up (2026-11-03: dibs boost 17727 --owner x -m "..." was a usage error).
|
|
153
|
+
if (!p && reason) say(`no priority given, so #${target} goes to high`);
|
|
154
|
+
else if (!p) die(`boost ${target} to what? Name a priority: dibs boost ${target} high -m "why" (or ${PRIORITIES.join(', ')}). Nothing changed.`);
|
|
155
|
+
const prio = prioArg('boost', p || 'high');
|
|
148
156
|
// Everyone sees an agent's high or urgent, and why, as they do on dibs run -p.
|
|
149
157
|
if (who.agent && NEEDS_REASON.has(prio) && !reason) die(`${prio} needs a reason everyone can see: dibs boost ${target} ${prio} -m "why". Nothing changed.`);
|
|
150
158
|
const hist = history();
|
|
@@ -174,17 +182,18 @@ export function boost(args) {
|
|
|
174
182
|
// One that exited meanwhile has nothing left to move, a zombie its parent hasn't reaped included.
|
|
175
183
|
const gone = pid => !/^[^Z]/.test(spawnSync('ps', ['-o', 'stat=', '-p', String(pid)], { encoding: 'utf8' }).stdout.trim());
|
|
176
184
|
const move = pid => (c.qos.bg ? lower(pid) : raise(pid)) || gone(pid);
|
|
177
|
-
|
|
178
|
-
|
|
185
|
+
// Whether each process was moved, the last time it was tried.
|
|
186
|
+
const done = new Map(c.qos.pids.map(pid => [pid, move(pid)]));
|
|
179
187
|
// A child forked between reading the process table and moving its parent kept the old
|
|
180
188
|
// priority, and at background priority on a busy machine even a sleep 0.05 can last
|
|
181
|
-
// seconds.
|
|
189
|
+
// seconds. And a move that lands while its process forks can be lost: on 2026-11-03,
|
|
190
|
+
// under a full suite, a raised loop shell still read background priority 10 s later.
|
|
191
|
+
// So the whole group is moved again a few times, a moment apart (a move is idempotent).
|
|
182
192
|
for (let i = 0; i < CATCH_UP; i++) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
for (const pid of late) tried.add(pid);
|
|
186
|
-
moved += late.filter(move).length;
|
|
193
|
+
sleepSync(CATCH_GAP);
|
|
194
|
+
for (const pid of pidsIn(c.qos.groups)) done.set(pid, move(pid));
|
|
187
195
|
}
|
|
196
|
+
const tried = done, moved = [...done.values()].filter(Boolean).length;
|
|
188
197
|
line += c.qos.bg ? ', moved to background priority (efficiency cores)' : ', moved off background priority';
|
|
189
198
|
if (moved < tried.size) line += ` (${tried.size - moved} of its ${tried.size} processes couldn't be moved${OS === 'linux' && !c.qos.bg ? ': Linux lets only root raise a priority' : ''})`;
|
|
190
199
|
}
|
|
@@ -194,6 +203,35 @@ export function boost(args) {
|
|
|
194
203
|
recordAll('boost', r.filter(c => !c.same).map(({ id, res, who, prio, from }) => ({ id, res, who, prio, from })), who, reason);
|
|
195
204
|
}
|
|
196
205
|
|
|
206
|
+
// Priority inversion: a low or idle run is at background QoS, which macOS starves while
|
|
207
|
+
// normal work fills every core (a 0.08 s loop took 13.6 s at load 35, 2026-11-03). One
|
|
208
|
+
// holding a full slot that a normal-or-higher waiter wants makes that waiter wait on the
|
|
209
|
+
// starving, so it's lifted to normal QoS while such a waiter is in line, and dropped back
|
|
210
|
+
// once none is. Under the state lock: marks the leases and returns the moves, made after it.
|
|
211
|
+
export function inversions(s, cfg) {
|
|
212
|
+
const moves = [];
|
|
213
|
+
for (const l of s.leases) {
|
|
214
|
+
if (l.kind !== 'run' || !l.pgid || !(l.background ?? BACKGROUND.has(l.prio))) continue;
|
|
215
|
+
const stuck = s.queue.find(q => q.pid && !BACKGROUND.has(q.prio || 'normal') && q.res.some(r => l.res.includes(r) && roomFor(s, q, r, cfg).open <= 0));
|
|
216
|
+
if (stuck && !l.lifted) { l.lifted = stuck.id; moves.push({ id: l.id, res: l.res, who: l.who, pgid: l.pgid, pgstart: l.pgstart, groups: l.groups, bg: false, for: stuck.id }); }
|
|
217
|
+
else if (!stuck && l.lifted) { moves.push({ id: l.id, res: l.res, who: l.who, pgid: l.pgid, pgstart: l.pgstart, groups: l.groups, bg: true, for: l.lifted }); delete l.lifted; }
|
|
218
|
+
}
|
|
219
|
+
return moves;
|
|
220
|
+
}
|
|
221
|
+
// Make the moves inversions() decided, after the lock, with boost's catch-up rounds.
|
|
222
|
+
export function lift(moves) {
|
|
223
|
+
for (const m of moves) {
|
|
224
|
+
const groups = [...groupsOf(m)];
|
|
225
|
+
const move = pid => (m.bg ? lower(pid) : raise(pid));
|
|
226
|
+
for (let i = 0; i <= CATCH_UP; i++) {
|
|
227
|
+
if (i) sleepSync(CATCH_GAP);
|
|
228
|
+
for (const pid of pidsIn(groups)) move(pid);
|
|
229
|
+
}
|
|
230
|
+
event({ kind: 'override', act: m.bg ? 'unlift' : 'lift', id: m.id, res: m.res, who: m.who, for: m.for,
|
|
231
|
+
why: m.bg ? `dropped #${m.id} back to background priority: nobody is stuck behind it now` : `lifted #${m.id} so #${m.for} isn't stuck behind it` });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
197
235
|
// Why the owner can't pause this lease, or null. Resources marked pausable:
|
|
198
236
|
// false (sim, xcode-build and deploy by default) stay unpaused unless --force:
|
|
199
237
|
// a frozen deploy, simulator or build can time out against the services it
|
|
@@ -287,6 +325,14 @@ export function stop(args) {
|
|
|
287
325
|
x.ownerStop = now();
|
|
288
326
|
if (who.agent || who.via) x.stopBy = who.name;
|
|
289
327
|
if (reason) x.stopReason = reason;
|
|
328
|
+
if (c.kind === 'wait') {
|
|
329
|
+
// Recorded apart from the place, so its waiter can say why once the place is gone. A place
|
|
330
|
+
// its dibs is still deciding for stays until that dibs sees the stop (its waiter says so and
|
|
331
|
+
// leaves; src/state.mjs reap takes it after STOP_GRACE); one nothing decides for goes now.
|
|
332
|
+
// On 2026-11-04 "took #19783 out of line" left #19783 at the head of heavy, twice.
|
|
333
|
+
(s.stopped ||= {})[x.id] = { at: x.ownerStop, by: x.stopBy, reason: x.stopReason };
|
|
334
|
+
if (unpolled(x, now())) s.queue = s.queue.filter(q => q !== x);
|
|
335
|
+
}
|
|
290
336
|
// SIGKILL ends stopped processes too, so a paused run needs no SIGCONT first.
|
|
291
337
|
// The lock is still held, so the run's own dibs can't remove the lease
|
|
292
338
|
// (and its group number can't be handed out again) in between.
|
package/src/plain.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// job in the way has a run time from history or --est, "as soon as X finishes"
|
|
8
8
|
// when X has none, and "unknown" when the wait is on the machine (disk, memory,
|
|
9
9
|
// load), which no clock predicts.
|
|
10
|
-
import { IDLE_MEM_FREE, verdict, forecastDetail, expected, known, remaining, rankParts, byRank, recentUse, coveredNow, memUsed, memHolders, shownFree, NOT_PRIORITY, swapping, diskSqueeze, overLoad, STALL } from './schedule.mjs';
|
|
10
|
+
import { IDLE_MEM_FREE, verdict, forecastDetail, expected, known, remaining, rankParts, byRank, recentUse, coveredNow, memUsed, memHolders, shownFree, NOT_PRIORITY, swapping, diskSqueeze, overLoad, STALL, QUICK_LINE } from './schedule.mjs';
|
|
11
11
|
import { quotaBlock, isQuota, QUOTA } from './quota.mjs';
|
|
12
12
|
import { isFiles, short, elsewhere } from './files.mjs';
|
|
13
13
|
import { machine, resCfg } from './config.mjs';
|
|
@@ -219,7 +219,7 @@ function waitingFor(s, q, v, cfg, hist, t, m, f) {
|
|
|
219
219
|
+ `${v.high ? ' with memory pressure high' : ''}${v.growing ? ' and swap growing' : ''}, and it needs ${GB(v.need)} plus ${GB(v.reserve)} to spare`;
|
|
220
220
|
return `room in memory: ${memoryPicture(s, cfg, m, v.need, t)}`;
|
|
221
221
|
case 'cpu': return `free processor cores (jobs running now are using ${v.used} of the ${v.of} cores dibs shares out, and it needs ${v.need})`;
|
|
222
|
-
case 'disk': return `more free disk (${GB(v.free)} free, it needs ${GB(v.need)})${hogHint()}`;
|
|
222
|
+
case 'disk': return `more free disk (${GB(v.free)} free, it needs ${GB(v.need)}${v.floorWhy ? `: ${v.floorWhy}` : ''})${hogHint()}`;
|
|
223
223
|
case 'pressure': return `memory pressure to ease (the OS says it's high, so dibs starts nothing new until it eases): ${memoryPicture(s, cfg, m, q.mem, t)}`;
|
|
224
224
|
case 'swaproom': return `more free disk for swap to grow into (${GB(v.free)} free; while this machine swaps, dibs starts nothing new until ${GB(v.need)} is free or nothing else is running)${hogHint()}`;
|
|
225
225
|
case 'drain': return `free disk to stop falling (it fell ${GB(v.fell)} in 5 min to ${GB(v.free)}; dibs starts nothing new while it falls this fast and anything else is running)${hogHint()}`;
|
|
@@ -272,6 +272,9 @@ export function moves(q, hist, t, cfg) {
|
|
|
272
272
|
} else if (p.label === 'recent use') {
|
|
273
273
|
label = 'taking turns';
|
|
274
274
|
reason = `this agent used ${andList(recentUse(hist, q.who, q.res, t).res.map(r => named(cfg, r).the))} a lot in the last hour`;
|
|
275
|
+
} else if (p.label === 'quick') {
|
|
276
|
+
label = 'quick';
|
|
277
|
+
reason = "it runs in seconds (the quick lane), so it goes before anyone who'd hold the slot for longer";
|
|
275
278
|
} else if (p.label === 'let ahead') {
|
|
276
279
|
label = 'let ahead';
|
|
277
280
|
reason = `${q.yieldBy || 'another agent'} let it go first`;
|
|
@@ -390,7 +393,7 @@ export function plainBoard(s, cfg, hist, t = now(), m = machine(), me = null) {
|
|
|
390
393
|
const someoneWaits = order.length > 0;
|
|
391
394
|
const held = new Map(s.leases.map(l => [l.id, {
|
|
392
395
|
headline: l.res.map((r, i) => (i ? lower(named(cfg, r).doing) : named(cfg, r).doing)).join(' and '),
|
|
393
|
-
endsText: ends(l, hist, t).endsText, paused: pausedText(l, cfg), ...(l.alongside ? { alongside: alongsideText(l.alongside) } : l.breaker ? { alongside: `Let in although the machine is short of disk or memory, since nothing had started for ${STALL / 6e4} min` } : {}),
|
|
396
|
+
endsText: ends(l, hist, t).endsText, paused: pausedText(l, cfg), ...(l.alongside ? { alongside: alongsideText(l.alongside) } : l.breaker ? { alongside: `Let in although the machine is short of disk or memory, since nothing had started for ${STALL / 6e4} min` } : l.quick ? { alongside: upper(QUICK_LINE) } : {}),
|
|
394
397
|
...(someoneWaits && stuckFor(l, t) ? { stuck: `${stuckText(l, t)} (#${l.id}${l.purpose ? `, "${l.purpose}"` : ''})` } : {}) }]));
|
|
395
398
|
return { lines, held, waiting, rules, names: new Map(s.queue.map(q => [q.id, holderName(q)])), holds: new Set(s.leases.filter(l => l.kind === 'hold').map(l => l.id)), cfg,
|
|
396
399
|
hold: machineHold(s, cfg, m) };
|
|
@@ -414,7 +417,7 @@ export function lineParts(p) {
|
|
|
414
417
|
let now = rows.length ? usingText(rows, named(p.cfg, l.res)) : 'free';
|
|
415
418
|
if (notes.length) now += ` (${rows.length > 1 ? notes.map(([w, x]) => `${w} is ${lower(x)}`).join('; ') : lower(notes[0][1])})`;
|
|
416
419
|
let next = '';
|
|
417
|
-
const names = l.waiting.map(id => p.names.get(id));
|
|
420
|
+
const names = l.waiting.map(id => `${p.names.get(id)} (#${id})`); // the id, for dibs why, boost or stop
|
|
418
421
|
if (names.length) {
|
|
419
422
|
// Say why the next one waits only when it isn't simply its turn here:
|
|
420
423
|
// stuck on the machine, or on another resource it needs too.
|