@dibssoftware/dibs 0.0.180 → 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 +111 -1
- package/README.md +10 -8
- package/bin/dibs.mjs +379 -74
- 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 +135 -11
- 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/docs/windows.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 +113 -28
- package/src/after.mjs +127 -0
- package/src/agents.mjs +2 -1
- package/src/alerts.mjs +109 -48
- 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 +254 -86
- package/src/config.mjs +85 -14
- package/src/connect.mjs +4 -2
- package/src/cool.mjs +28 -12
- 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 +121 -7
- package/src/guard.mjs +288 -105
- 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 +51 -11
- package/src/measure.mjs +60 -14
- 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 +29 -7
- package/src/preempt.mjs +123 -15
- package/src/primer.mjs +91 -20
- package/src/prints.mjs +99 -0
- package/src/proc.mjs +11 -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 +262 -26
- 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/service.mjs +5 -1
- 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 +1082 -134
- 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 +354 -60
- package/src/work.mjs +487 -0
- package/src/worker.mjs +7 -1
package/src/config.mjs
CHANGED
|
@@ -4,7 +4,8 @@ import os from 'node:os';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { pressure, dibsMem } from './platform.mjs';
|
|
6
6
|
import { isFiles, FILES_COST } from './files.mjs';
|
|
7
|
-
import { die, ms, now, bytes } from './util.mjs';
|
|
7
|
+
import { die, ms, now, bytes, say } from './util.mjs';
|
|
8
|
+
import { parsed, lastGood, bakOf, writeWhole, note } from './durable.mjs';
|
|
8
9
|
|
|
9
10
|
export const HOME = process.env.DIBS_HOME || path.join(os.homedir(), '.dibs');
|
|
10
11
|
export const paths = {
|
|
@@ -22,11 +23,25 @@ export const paths = {
|
|
|
22
23
|
// lease: other-agent (the last user was someone else), always, never.
|
|
23
24
|
export const POOL_DEFAULTS = { deviceType: null, runtime: null, perSim: '2G', erase: 'other-agent' };
|
|
24
25
|
|
|
26
|
+
// The stock budget and cores, from this machine. A 16 GB, 10-core Mac running a dozen agents was
|
|
27
|
+
// retuned by hand from 8G and 6 to 11G and 10 within a day of install (2026-10-13), and kept there:
|
|
28
|
+
// running jobs count at what they're measured using (src/schedule.mjs memOf), and the OS's memory
|
|
29
|
+
// pressure is the guard, so 70% of memory leaves the rest to the apps and sessions outside dibs.
|
|
30
|
+
// Cores are counted as measured, and too many busy cores only slows everyone a little.
|
|
31
|
+
const BUDGET_SHARE = 0.7;
|
|
32
|
+
const stockBudget = () => `${Math.max(1, Math.round(hardware().mem * BUDGET_SHARE / 1024 ** 3 * 2) / 2)}G`;
|
|
33
|
+
// What dibs wrote as stock before it sized them from the machine: a file still holding these was never
|
|
34
|
+
// changed by hand, so a pace's numbers win over them (paced). A new file leaves both out (writeDefault),
|
|
35
|
+
// so one there now was set by someone, even if it matches this machine's stock: 11G on a 16 GB Mac
|
|
36
|
+
// set by hand stays the person's word over a pace.
|
|
37
|
+
const OLD_STOCK = { budget: '8G', cores: 6 };
|
|
38
|
+
|
|
25
39
|
export const DEFAULT_CONFIG = {
|
|
26
|
-
budget:
|
|
27
|
-
cores:
|
|
40
|
+
budget: stockBudget(), // memory dibs hands out at once across running jobs: 70% of the machine's (11G on 16 GB)
|
|
41
|
+
cores: hardware().cores, // CPU cores running jobs may use at once: what each was last measured using, or asked for until then. Lower means a quieter fan and slower queues
|
|
28
42
|
minFreeMem: 15, // jobs of 2G+ wait while the OS reports less than this % of memory free
|
|
29
43
|
minDisk: '5G', // nothing starts below this much free disk
|
|
44
|
+
diskShare: null, // disk each agent session may fill before dibs tells it it's over its share. null: an even split of what's free (src/diskuse.mjs)
|
|
30
45
|
starveAfter: '3m', // after this long at the head of the line, nobody jumps it
|
|
31
46
|
quickUnder: '15s', // a command that runs under this goes in the quick lane: it starts at once (src/schedule.mjs quickPass)
|
|
32
47
|
roomyMemFree: 35, // with at least this % of memory free...
|
|
@@ -46,6 +61,10 @@ export const DEFAULT_CONFIG = {
|
|
|
46
61
|
overlap: null, // off, fit or squeeze: whether a job may start on top of a full resource when the machine has room (src/overlap.mjs). null: the pace decides
|
|
47
62
|
squeezeUnder: '60s', // with overlap squeeze, jobs that usually take less than this may squeeze in whatever the load
|
|
48
63
|
maintainer: null, // agent name `dibs ask` points people to for a faster answer
|
|
64
|
+
// Phone notifications an hour at most (dibs attention). Past it, everything but urgent questions waits
|
|
65
|
+
// for the next batch once the hour frees up, or for the recap. One every ten minutes on average:
|
|
66
|
+
// with batching, each one can carry several things. null: no cap.
|
|
67
|
+
attention: 6,
|
|
49
68
|
hours: null, // the person's working hours, {"start": "09:00", "end": "23:00"}: outside them, questions below urgent wait. null: any time
|
|
50
69
|
agents: false, // no limit; { slots: 8 } caps subagents running at once across every Claude Code session here (dibs guard install)
|
|
51
70
|
// thin: dibs run and dibs hold wait as a 1.5 MB shell, and one broker process decides for every
|
|
@@ -80,25 +99,34 @@ export const DEFAULT_CONFIG = {
|
|
|
80
99
|
// project's TestFlight upload (2026-11-03). slots is per project, so a config's slots: 1 reads so too. A quick deploy of
|
|
81
100
|
// another project may go past across (quickAlongside).
|
|
82
101
|
deploy: { slots: 1, mem: '0.5G', cpu: 1, pausable: false, exclusive: true, exclusiveBy: 'repo', across: 3, quickAlongside: 'other-repo' },
|
|
83
|
-
heavy
|
|
102
|
+
// 10G here held every heavy job back on a Mac with 4 to 6 GB free (2026-10-15), and was set to 3G
|
|
103
|
+
// by hand: solvers and data jobs write little, and what one really eats is learned (typicalDisk).
|
|
104
|
+
heavy: { slots: 1, mem: '4G', cpu: 4, disk: '3G', pausable: true, rerun: true },
|
|
84
105
|
},
|
|
85
106
|
// A name dibs doesn't know is often someone's lock ("one migration at a time"), so it never overlaps.
|
|
86
107
|
unknown: { slots: 1, mem: '1G', cpu: 1, pausable: false, exclusive: true },
|
|
87
108
|
};
|
|
88
109
|
|
|
110
|
+
// Every headless agent dibs council starts takes one token (src/council.mjs). A debate of four
|
|
111
|
+
// voices over three rounds and its judge is 13 calls: 60 an hour is four of those, enough for a
|
|
112
|
+
// person asking by hand and few enough that a script looping councils can't spend an account's
|
|
113
|
+
// limits in minutes. quiet: off the board until a council has used it. config.json's
|
|
114
|
+
// "quotas": { "council": ... } replaces it.
|
|
115
|
+
const COUNCIL_QUOTA = { per: '1h', limit: 60, quiet: true };
|
|
116
|
+
|
|
89
117
|
// The user's file only needs the keys they change. Resources merge one level deep,
|
|
90
118
|
// so overriding sim's slots keeps sim's memory cost.
|
|
91
119
|
export function loadConfig() {
|
|
92
120
|
fs.mkdirSync(HOME, { recursive: true });
|
|
93
121
|
if (!fs.existsSync(paths.config)) writeDefault();
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const merged = { ...DEFAULT_CONFIG, ...c, resources: { ...DEFAULT_CONFIG.resources } };
|
|
122
|
+
const c = readConfig();
|
|
123
|
+
const merged = { ...DEFAULT_CONFIG, ...c, resources: { ...DEFAULT_CONFIG.resources }, quotas: { council: COUNCIL_QUOTA, ...c.quotas } };
|
|
97
124
|
for (const [k, v] of Object.entries(c.resources || {})) merged.resources[k] = { ...(DEFAULT_CONFIG.resources[k] || {}), ...v };
|
|
98
125
|
if (c.pace != null && !PACES[c.pace]) die(`pace in ${paths.config} is one of ${Object.keys(PACES).join(', ')}, or null`);
|
|
99
126
|
if (merged.maxLoad != null && !(merged.maxLoad > 0)) die(`maxLoad in ${paths.config} is a load average above 0, or null for no ceiling`);
|
|
100
127
|
if (c.overlap != null && !OVERLAP_MODES.includes(c.overlap)) die(`overlap in ${paths.config} is one of ${OVERLAP_MODES.join(', ')}, or null to let the pace decide`);
|
|
101
128
|
ms(merged.squeezeUnder);
|
|
129
|
+
if (merged.attention != null && !(Number.isInteger(merged.attention) && merged.attention >= 0)) die(`attention in ${paths.config} is how many phone notifications an hour (6, or 0 for urgent questions only), or null for no cap`);
|
|
102
130
|
// Read here so a bad value names its key, instead of every dibs run failing on "can't read size".
|
|
103
131
|
if (!isSize(merged.budget)) die(`budget in ${paths.config} is a size like 8G (the memory dibs hands out at once), not ${JSON.stringify(merged.budget)}`);
|
|
104
132
|
// null means no floor, as it does for maxSwap and swapRoom. The watcher still pauses jobs under its own 3G line.
|
|
@@ -107,6 +135,7 @@ export function loadConfig() {
|
|
|
107
135
|
if (!['thin', 'fat', 'node'].includes(merged.waits)) die(`waits in ${paths.config} is "thin" or "fat", not ${JSON.stringify(merged.waits)}`);
|
|
108
136
|
if (merged.maxSwap != null) bytes(merged.maxSwap);
|
|
109
137
|
if (merged.swapRoom != null) bytes(merged.swapRoom);
|
|
138
|
+
if (merged.diskShare != null && !isSize(merged.diskShare)) die(`diskShare in ${paths.config} is a size like 10G, or null for an even split of free disk, not ${JSON.stringify(merged.diskShare)}`);
|
|
110
139
|
for (const [k, v] of Object.entries(merged.resources)) {
|
|
111
140
|
if (v.onRelease != null && typeof v.onRelease !== 'string') die(`resources.${k}.onRelease in ${paths.config} is a shell command, as a string`);
|
|
112
141
|
if (v.onReleaseTimeout != null) ms(v.onReleaseTimeout);
|
|
@@ -223,26 +252,60 @@ export function paceKnobs(pace, hw = hardware()) {
|
|
|
223
252
|
// value counts as unset: only one someone changed wins over the pace.
|
|
224
253
|
export function paced(c, hw = hardware()) {
|
|
225
254
|
const knobs = paceKnobs(c.pace, hw);
|
|
226
|
-
const pinned = Object.keys(knobs).filter(k => c[k] != null && c[k] !== DEFAULT_CONFIG[k]);
|
|
255
|
+
const pinned = Object.keys(knobs).filter(k => c[k] != null && c[k] !== (k in OLD_STOCK ? OLD_STOCK[k] : DEFAULT_CONFIG[k]));
|
|
227
256
|
for (const k of pinned) delete knobs[k];
|
|
228
257
|
return { knobs, pinned };
|
|
229
258
|
}
|
|
230
259
|
|
|
260
|
+
// The person's settings file, as written (loadConfig adds the defaults). One that doesn't parse (a typo mid-edit, a disk error) used to stop every
|
|
261
|
+
// dibs command on the machine. Now dibs runs on the last copy that parsed, config.json.bak (kept
|
|
262
|
+
// whenever the file changes and parses), says so on every command and once in the alerts, and never
|
|
263
|
+
// writes over the person's file: they may be editing it.
|
|
264
|
+
let warned = false;
|
|
265
|
+
export function readConfig() {
|
|
266
|
+
let raw;
|
|
267
|
+
try { raw = fs.readFileSync(paths.config, 'utf8'); } catch (e) { die(`can't read ${paths.config}: ${e.message}`); }
|
|
268
|
+
const c = parsed(raw);
|
|
269
|
+
if (c) { keepGood(raw); return c; }
|
|
270
|
+
const good = lastGood(paths.config);
|
|
271
|
+
let why = 'empty';
|
|
272
|
+
try { JSON.parse(raw); } catch (e) { why = e.message; }
|
|
273
|
+
if (!good) die(`${paths.config} isn't valid JSON (${why}). Fix it, or remove it to get the defaults back.`);
|
|
274
|
+
if (!warned) say(`${paths.config} isn't valid JSON (${why}), so dibs is using the copy from ${new Date(good.at).toLocaleString()} until it's fixed.`);
|
|
275
|
+
warned = true;
|
|
276
|
+
// Once per broken version: the copy of it kept for the alert is made only if it isn't there yet.
|
|
277
|
+
try {
|
|
278
|
+
const saved = `${paths.config}.corrupt-${Math.round(fs.statSync(paths.config).mtimeMs)}`;
|
|
279
|
+
fs.writeFileSync(saved, raw, { flag: 'wx' });
|
|
280
|
+
note({ kind: 'recovered', file: paths.config, saved, from: good.at, using: true });
|
|
281
|
+
} catch {}
|
|
282
|
+
return good.v;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function keepGood(raw) {
|
|
286
|
+
try {
|
|
287
|
+
const bak = bakOf(paths.config);
|
|
288
|
+
let had = 0;
|
|
289
|
+
try { had = fs.statSync(bak).mtimeMs; } catch {}
|
|
290
|
+
if (had < fs.statSync(paths.config).mtimeMs) writeWhole(bak, raw);
|
|
291
|
+
} catch {}
|
|
292
|
+
}
|
|
293
|
+
|
|
231
294
|
// dibs pace: set or clear the pace in the user's file, leaving the rest as written.
|
|
232
295
|
export function writePace(pace) {
|
|
233
296
|
loadConfig();
|
|
234
|
-
const c =
|
|
297
|
+
const c = parsed(fs.readFileSync(paths.config, 'utf8')) || die(`${paths.config} isn't valid JSON. Fix it first, then set the pace.`);
|
|
235
298
|
c.pace = pace;
|
|
236
|
-
|
|
237
|
-
fs.writeFileSync(tmp, JSON.stringify(c, null, 2) + '\n');
|
|
238
|
-
fs.renameSync(tmp, paths.config);
|
|
299
|
+
writeWhole(paths.config, JSON.stringify(c, null, 2) + '\n');
|
|
239
300
|
}
|
|
240
301
|
|
|
241
302
|
// Two first calls can race here. Written aside and linked into place, so a
|
|
242
303
|
// reader never sees half a file and a config that appeared meanwhile is kept.
|
|
243
304
|
function writeDefault() {
|
|
244
305
|
const tmp = `${paths.config}.${process.pid}`;
|
|
245
|
-
|
|
306
|
+
// budget and cores come from the machine each time they're read (OLD_STOCK says why they're left out).
|
|
307
|
+
const { budget, cores, ...rest } = DEFAULT_CONFIG;
|
|
308
|
+
fs.writeFileSync(tmp, JSON.stringify(rest, null, 2) + '\n');
|
|
246
309
|
try { fs.linkSync(tmp, paths.config); } catch (e) { if (e.code !== 'EEXIST') throw e; }
|
|
247
310
|
finally { fs.rmSync(tmp, { force: true }); }
|
|
248
311
|
}
|
|
@@ -251,7 +314,15 @@ function writeDefault() {
|
|
|
251
314
|
// memory or cores. Its slots only need to never run out; finite, so the
|
|
252
315
|
// forecast can list them.
|
|
253
316
|
const QUOTA_RES = { slots: 1000, mem: 0, cpu: 0, disk: 0, pausable: false };
|
|
254
|
-
|
|
317
|
+
// An environment or account (env:staging, account:asc: src/envs.mjs) exists once per project:
|
|
318
|
+
// one holder at a time in each project, any number of projects at once, never paused (a deploy
|
|
319
|
+
// frozen half way) and never run on top of. Holding it costs nothing; the command run under it
|
|
320
|
+
// is measured and booked like any other. across only needs to never run out.
|
|
321
|
+
export const ENV_RE = /^(env|account):[\w.-]+$/;
|
|
322
|
+
export const isEnv = r => ENV_RE.test(r);
|
|
323
|
+
export const ENV_RES = { slots: 1, mem: 0, cpu: 0, disk: 0, pausable: false, exclusive: true, exclusiveBy: 'repo', across: 1000 };
|
|
324
|
+
export const resCfg = (cfg, r) => (r.startsWith('quota:') ? QUOTA_RES : isFiles(r) ? { ...FILES_COST } : isEnv(r) ? { ...ENV_RES, ...(cfg.resources[r] || {}) }
|
|
325
|
+
: { ...cfg.unknown, ...(cfg.resources[r] || {}) });
|
|
255
326
|
|
|
256
327
|
// How much swap grew and free disk fell lately. macOS leaves swap allocated
|
|
257
328
|
// long after the memory crunch that filled it, so what counts is swap growing
|
package/src/connect.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { die } from './util.mjs';
|
|
|
6
6
|
|
|
7
7
|
const CHOICES = [
|
|
8
8
|
['browser', 'this browser', 'a one-time code for the page at http://127.0.0.1:7421', 'dibs connect --browser'],
|
|
9
|
-
['phone', 'a phone or another browser', 'a link and QR code, end-to-end encrypted through the relay', 'dibs connect --phone [--allow-actions]'],
|
|
9
|
+
['phone', 'a phone or another browser', 'a link and QR code, end-to-end encrypted through the relay', 'dibs connect --phone [--allow-actions | --allow-talk] [--for <person>]'],
|
|
10
10
|
['account', 'your dibs account', 'every browser you sign in with at app.dibs.cc opens this Mac', 'dibs connect --account [--allow-actions]'],
|
|
11
11
|
['mcp', 'another Claude account', 'its connector reads dibs (or acts) over MCP at mcp.dibs.cc', 'dibs connect --mcp [--allow-actions]'],
|
|
12
12
|
['machine', 'another machine', 'it takes jobs from this one and sends its own', 'dibs connect --machine [--name <name>]'],
|
|
@@ -51,8 +51,10 @@ export async function connect(args) {
|
|
|
51
51
|
return connect([`--${pick[0]}`]);
|
|
52
52
|
}
|
|
53
53
|
if (first === '--browser') return (await web()).pair([]);
|
|
54
|
-
if (first === '--phone') return (await web()).pair(['--remote', ...
|
|
54
|
+
if (first === '--phone') return (await web()).pair(['--remote', ...rest]);
|
|
55
55
|
if (first === '--account') {
|
|
56
|
+
// An account's browsers all share one device key, and a talking key belongs to one phone.
|
|
57
|
+
if (rest.includes('--allow-talk')) die('an account can\'t talk: its browsers share one key, and talking needs a Face ID key on one phone. Pair that phone with dibs connect --phone --allow-talk');
|
|
56
58
|
if (rest.some(a => a !== '--allow-actions')) die('dibs connect --account [--allow-actions]');
|
|
57
59
|
return (await relay()).pairAccount({ act: rest.includes('--allow-actions') });
|
|
58
60
|
}
|
package/src/cool.mjs
CHANGED
|
@@ -13,15 +13,18 @@ import { withState, history, peek } from './state.mjs';
|
|
|
13
13
|
import { singleInstance } from './proc.mjs';
|
|
14
14
|
import { processes, lower, memPressure, isDibs, runtimes } from './platform.mjs';
|
|
15
15
|
import { hogsOnce, hogHint } from './hogs.mjs';
|
|
16
|
+
import { useOnce } from './diskuse.mjs';
|
|
17
|
+
import { reportOnce } from './diskreport.mjs';
|
|
16
18
|
import { pressureStep, pressurePause, pressureRequeue, pressureResume, diskStep, diskPause, diskPausesPerPass, diskLine, diskCritical, adoptPauses, diskRequeue, measured, hardStop, hardResume, HARD_STOP, HARD_RESUME } from './preempt.mjs';
|
|
17
19
|
import { inversions, lift } from './override.mjs';
|
|
18
20
|
import { swapGrowing } from './schedule.mjs';
|
|
19
21
|
import { event } from './events.mjs';
|
|
20
|
-
import { notify } from './talk.mjs';
|
|
22
|
+
import { notify, unheardScan } from './talk.mjs';
|
|
21
23
|
import { watchBroker } from './broker.mjs';
|
|
22
|
-
import { progressScan } from './notices.mjs';
|
|
24
|
+
import { progressScan, unsaidScan } from './notices.mjs';
|
|
23
25
|
import { scan as scanAlerts, CPU_FILE } from './alerts.mjs';
|
|
24
|
-
import { say, sleep, now, noSpace, gb } from './util.mjs';
|
|
26
|
+
import { say, sleep, now, noSpace, gb, bytes } from './util.mjs';
|
|
27
|
+
import { described } from './declare.mjs';
|
|
25
28
|
|
|
26
29
|
const PIDFILE = path.join(HOME, 'cool.pid');
|
|
27
30
|
const LOG = path.join(HOME, 'cool.log');
|
|
@@ -113,9 +116,9 @@ export function pressureOnce(cfg, track, read = memPressure) {
|
|
|
113
116
|
const used = measured(l) || l.mem;
|
|
114
117
|
fs.appendFileSync(LOG, `${new Date().toISOString()} memory pressure still critical with jobs paused: stopped ${l.who} ${l.res.join(',')} (${l.prio || 'normal'}), using ${gb(used)}, to run again at the front of its line: ${l.cmd.slice(0, 60)}\n`);
|
|
115
118
|
event({ kind: 'requeue', id: l.id, res: l.res, who: l.who, agent: l.agent, prio: l.prio || 'normal', why: 'memory', mem: used, booked: l.mem });
|
|
116
|
-
notify(l, `requeue:#${l.id}`, `your job #${l.id} (
|
|
119
|
+
notify(l, `requeue:#${l.id}`, `your job #${l.id} ("${described(l)}", ${l.cmd.slice(0, 60)}) was paused for memory pressure, and pausing frees no memory`
|
|
117
120
|
+ ` (a stopped job's memory goes to swap), so with the pressure still critical dibs stopped it. Its dibs run put it back at the front of its line and runs it again`
|
|
118
|
-
+ ` from the start once there's room. Don't run it again yourself, and don't end it: the same tool call carries on
|
|
121
|
+
+ ` from the start once there's room. Don't run it again yourself, and don't end it: the same tool call carries on.`, { quiet: true });
|
|
119
122
|
return { act: 'requeue', leases: [l] };
|
|
120
123
|
}
|
|
121
124
|
}
|
|
@@ -143,13 +146,13 @@ export function diskOnce(cfg, track, m = machine()) {
|
|
|
143
146
|
fs.appendFileSync(LOG, `${new Date().toISOString()} ${why}: stopped ${l.who} ${l.res.join(',')} (${l.prio || 'normal'}), `
|
|
144
147
|
+ `${over ? `using ${gb(used)} of the ${gb(l.mem)} it booked` : 'paused for the disk'}, to run again at the front of its line: ${l.cmd.slice(0, 60)}\n`);
|
|
145
148
|
event({ kind: 'requeue', id: l.id, res: l.res, who: l.who, agent: l.agent, prio: l.prio || 'normal', why: l.requeue.why, mem: used || l.mem, booked: l.mem, diskFree: m.diskFree });
|
|
146
|
-
const job = `your job #${l.id} (
|
|
149
|
+
const job = `your job #${l.id} ("${described(l)}", ${l.cmd.slice(0, 60)})`;
|
|
147
150
|
notify(l, `requeue:#${l.id}`, (over
|
|
148
151
|
? `${job} was using ${gb(used)} of memory, far more than the ${gb(l.mem)} it booked, while swap filled the disk, so dibs stopped it.`
|
|
149
152
|
+ ` Its dibs run put it back at the front of its line booked at what it really used, and runs it again from the start once that much memory is really free.`
|
|
150
153
|
: `${job} was paused for low disk, and while it sat paused its memory was going to swap and filling the disk it was waiting for, so dibs stopped it.`
|
|
151
154
|
+ ` Its dibs run put it back at the front of its line and runs it again from the start when there's room.`)
|
|
152
|
-
+ ` Don't run it again yourself, and don't end it: the same tool call carries on
|
|
155
|
+
+ ` Don't run it again yourself, and don't end it: the same tool call carries on.`, { quiet: true });
|
|
153
156
|
return { act: 'requeue', leases: [l] };
|
|
154
157
|
}
|
|
155
158
|
}
|
|
@@ -159,7 +162,7 @@ export function diskOnce(cfg, track, m = machine()) {
|
|
|
159
162
|
for (const l of ls) {
|
|
160
163
|
fs.appendFileSync(LOG, `${new Date().toISOString()} disk ${act === 'pause' ? `low (${(m.diskFree / 1024 ** 3).toFixed(1)}G free, under ${(diskLine(cfg) / 1024 ** 3).toFixed(1)}G and filling): paused` : 'has room again, or has held still: resumed'} ${l.who} ${l.res.join(',')} (${l.prio || 'normal'}): ${l.cmd.slice(0, 60)}\n`);
|
|
161
164
|
// Its agent hears it now, through the hook, not only when the tool call returns: it may need to save work or free space.
|
|
162
|
-
if (act === 'pause') notify(l, `diskpause:#${l.id}:${l.pausedAt}`, `your job #${l.id} (
|
|
165
|
+
if (act === 'pause') notify(l, `diskpause:#${l.id}:${l.pausedAt}`, `your job #${l.id} ("${described(l)}", ${l.cmd.slice(0, 60)}) is paused: free disk is low `
|
|
163
166
|
+ `(${(m.diskFree / 1024 ** 3).toFixed(1)} GB) and still falling${hogHint()}. It keeps its lease and its place and resumes once there's room. `
|
|
164
167
|
+ "Free what you can of your own: build output, scratch folders and merged worktrees your session made. Don't end the job or run it again.");
|
|
165
168
|
}
|
|
@@ -174,13 +177,13 @@ function hardOnce(m) {
|
|
|
174
177
|
for (const l of r.resumed) {
|
|
175
178
|
fs.appendFileSync(LOG, `${new Date().toISOString()} disk back to ${free}: resumed ${l.who} ${l.res.join(',')} (${l.prio || 'normal'}): ${l.cmd.slice(0, 60)}\n`);
|
|
176
179
|
event({ kind: 'resume', id: l.id, res: l.res, who: l.who, why: 'hard stop over', diskFree: m.diskFree });
|
|
177
|
-
notify(l, `hardresume:#${l.id}:${now()}`, `your job #${l.id} (${l.cmd.slice(0, 60)}) is running again: free disk is back to ${free}
|
|
180
|
+
notify(l, `hardresume:#${l.id}:${now()}`, `your job #${l.id} (${l.cmd.slice(0, 60)}) is running again: free disk is back to ${free}.`, { quiet: true });
|
|
178
181
|
}
|
|
179
182
|
const l = r.paused;
|
|
180
183
|
if (l) {
|
|
181
184
|
fs.appendFileSync(LOG, `${new Date().toISOString()} disk at ${free}, under ${gb(HARD_STOP)}: hard stop, paused ${l.who} ${l.res.join(',')} (${l.prio || 'normal'}), writing fastest: ${l.cmd.slice(0, 60)}\n`);
|
|
182
185
|
event({ kind: 'pause', id: l.id, res: l.res, who: l.who, prio: l.prio || 'normal', why: 'hard stop', diskFree: m.diskFree });
|
|
183
|
-
notify(l, `hardstop:#${l.id}:${l.pausedAt}`, `your job #${l.id} (
|
|
186
|
+
notify(l, `hardstop:#${l.id}:${l.pausedAt}`, `your job #${l.id} ("${described(l)}", ${l.cmd.slice(0, 60)}) is paused: free disk is down to ${free}, `
|
|
184
187
|
+ `under the ${gb(HARD_STOP).replace(/G$/, ' GB')} where every job on the machine is about to fail, and it was writing the most. It resumes once there's ${gb(HARD_RESUME).replace(/G$/, ' GB')}. `
|
|
185
188
|
+ "Free what you can of your own now: build output, scratch folders and merged worktrees your session made. Don't end the job or run it again.");
|
|
186
189
|
}
|
|
@@ -241,10 +244,23 @@ export async function throttle(o, cfg) {
|
|
|
241
244
|
try { lift(withState(s => inversions(s, cfg))); } catch (e) { if (!noSpace(e)) throw e; }
|
|
242
245
|
// Not awaited: measuring a full temp folder can take a minute, and this loop keeps the machine's pace meanwhile.
|
|
243
246
|
hogsOnce(cfg, machine());
|
|
247
|
+
// Each session's share of the disk, and the folders of sessions that ended (src/diskuse.mjs). Not awaited either.
|
|
248
|
+
useOnce(cfg, machine());
|
|
249
|
+
// Under twice the floor, the report of the biggest users the notices and the alert name (src/diskreport.mjs). Not awaited.
|
|
250
|
+
reportOnce(bytes(cfg.minDisk || '0'), machine());
|
|
244
251
|
// Alerts open and close even while nobody looks at the board (src/alerts.mjs); the scan itself keeps its pace.
|
|
245
|
-
scanAlerts({ s: peek(), cfg, hist: history() });
|
|
252
|
+
scanAlerts({ s: peek(), cfg, hist: history(), watcher: true });
|
|
246
253
|
// Open progress tasks gone quiet or past their ETA: their agents hear about it (src/notices.mjs).
|
|
247
|
-
|
|
254
|
+
// And agents at work a while without a word about what on (unsaidScan): not awaited, it reads transcripts.
|
|
255
|
+
if (now() - nudged >= SAMPLE_EVERY) {
|
|
256
|
+
nudged = now();
|
|
257
|
+
progressScan();
|
|
258
|
+
unsaidScan();
|
|
259
|
+
// Messages between agents that sat undelivered a while: their senders hear (src/talk.mjs).
|
|
260
|
+
unheardScan();
|
|
261
|
+
// Sessions that ended mid-task: their work becomes a handoff (src/carry.mjs). Loaded only here, and not waited on: it reads git.
|
|
262
|
+
import('./carry.mjs').then(m => m.sweepSoon()).catch(e => fs.appendFileSync(LOG, `${new Date().toISOString()} couldn't look for work left unfinished: ${e.message}\n`));
|
|
263
|
+
}
|
|
248
264
|
if (now() - sampled >= SAMPLE_EVERY) {
|
|
249
265
|
sampled = now();
|
|
250
266
|
const m = machine();
|