@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/media.mjs
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// Files and links that travel with a message (dibs say --file, dibs tell --link, ...).
|
|
2
|
+
//
|
|
3
|
+
// A file is copied at send into ~/.dibs/media, named by a hash of its bytes, so what the
|
|
4
|
+
// person or another agent opens is what was sent, even after the original changes or goes:
|
|
5
|
+
// media/<id>/<name> the bytes, under the name it was sent with (a second name is a hard link)
|
|
6
|
+
// media/<id>.json { id, kind, mime, size, at }, touched at every send
|
|
7
|
+
// A link is a grant for one path on this Mac, read live: media/links/<id>.json { id, path,
|
|
8
|
+
// isDir, name, at }. Reads under it resolve every link and must land inside the granted path.
|
|
9
|
+
//
|
|
10
|
+
// No lock: every write is a whole file renamed into place, and one id names the same bytes
|
|
11
|
+
// whoever writes them. Secret-looking files (SECRET, as src/remote.mjs keeps them home) are
|
|
12
|
+
// refused at send, never listed under a link and never served from one.
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import os from 'node:os';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import crypto from 'node:crypto';
|
|
17
|
+
import { HOME } from './config.mjs';
|
|
18
|
+
import { SECRET } from './remote.mjs';
|
|
19
|
+
import { die, now, size as sized } from './util.mjs';
|
|
20
|
+
|
|
21
|
+
export const MEDIA = path.join(HOME, 'media');
|
|
22
|
+
const LINKS = path.join(MEDIA, 'links');
|
|
23
|
+
// A PDF report, a CSV export or a set of screenshots fits well under this. Past it a file is a
|
|
24
|
+
// build product, not something to read on a phone, and through the relay it would take a dozen
|
|
25
|
+
// round trips of RELAY_CHUNK each: share it live with --link instead.
|
|
26
|
+
export const MAX_FILE = 25 * 1024 ** 2;
|
|
27
|
+
// Every attachment kept, together. This Mac runs near its 5 GB disk floor, and a week of
|
|
28
|
+
// attachments must never be what pushes it under.
|
|
29
|
+
export const MAX_STORE = 500 * 1024 ** 2;
|
|
30
|
+
// As long as the messages that carry them (KEEP_FOR in src/talk.mjs).
|
|
31
|
+
const KEEP_FOR = 7 * 24 * 36e5;
|
|
32
|
+
// More than this in one message is a folder: send it with --link.
|
|
33
|
+
export const MAX_ATTACH = 10;
|
|
34
|
+
// A folder listing past this many entries is cut short and says so.
|
|
35
|
+
const MAX_LIST = 2000;
|
|
36
|
+
// Through the relay a file comes in pieces of at most this many bytes. Base64 grows it by a
|
|
37
|
+
// third, and the answer must fit the relay's largest frame (4 MiB, src/relay.mjs BUCKETS).
|
|
38
|
+
export const RELAY_CHUNK = 2 * 1024 ** 2;
|
|
39
|
+
|
|
40
|
+
const EXT = {
|
|
41
|
+
png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', heic: 'image/heic', heif: 'image/heif', bmp: 'image/bmp', svg: 'image/svg+xml',
|
|
42
|
+
pdf: 'application/pdf', csv: 'text/csv', tsv: 'text/tab-separated-values', md: 'text/markdown', markdown: 'text/markdown',
|
|
43
|
+
txt: 'text/plain', log: 'text/plain', json: 'application/json', html: 'text/html', htm: 'text/html', zip: 'application/zip',
|
|
44
|
+
mov: 'video/quicktime', mp4: 'video/mp4', m4a: 'audio/mp4', mp3: 'audio/mpeg', wav: 'audio/wav',
|
|
45
|
+
};
|
|
46
|
+
// Types a browser may show in place. Anything else (HTML above all, which would run in the
|
|
47
|
+
// page's own origin) is served as a download.
|
|
48
|
+
const INLINE = /^(image\/(png|jpeg|gif|webp|heic|heif|bmp|svg\+xml)|application\/pdf|application\/json|text\/(plain|csv|tab-separated-values|markdown)|video\/(mp4|quicktime)|audio\/(mp4|mpeg|wav))$/;
|
|
49
|
+
export const mimeOf = name => EXT[path.extname(name).slice(1).toLowerCase()] || 'application/octet-stream';
|
|
50
|
+
export const inline = mime => INLINE.test(mime);
|
|
51
|
+
export function kindOf(name, mime = mimeOf(name)) {
|
|
52
|
+
if (mime.startsWith('image/')) return 'image';
|
|
53
|
+
if (mime === 'application/pdf') return 'pdf';
|
|
54
|
+
if (mime === 'text/csv' || mime === 'text/tab-separated-values') return 'csv';
|
|
55
|
+
if (mime === 'text/markdown') return 'report';
|
|
56
|
+
return 'file';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// The name a file is kept and shown under: its own, without anything a path or a terminal reads.
|
|
60
|
+
const cleanName = n => path.basename(String(n)).replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}/\\]+/gu, ' ').trim().slice(0, 120) || 'file';
|
|
61
|
+
const FILE_ID = /^[0-9a-f]{32}$/;
|
|
62
|
+
const LINK_ID = /^[A-Za-z0-9_-]{22}$/;
|
|
63
|
+
|
|
64
|
+
// Why this path may not leave the Mac, or null.
|
|
65
|
+
// SECRET reads / between folders: a Windows path's backslashes become / first, or C:/Users/x/id_ed25519 written with backslashes went out.
|
|
66
|
+
const fwd = x => String(x).replace(/\\/g, '/');
|
|
67
|
+
function refusal(p, real) {
|
|
68
|
+
if (SECRET.test(fwd(p)) || SECRET.test(fwd(real)) || SECRET.test(`${fwd(real)}/`)) return `${p} looks like it holds keys or passwords, so dibs won't send it. Send what the reader needs instead (a redacted copy, or the line that matters in the message).`;
|
|
69
|
+
const home = fs.realpathSync(HOME);
|
|
70
|
+
if (real === home || real.startsWith(home + path.sep)) return `${p} is inside dibs's own folder, which holds its tokens, so dibs won't send it.`;
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function realOrDie(p) {
|
|
75
|
+
try { return fs.realpathSync(p); } catch { return die(`${p} doesn't exist (or can't be read). Nothing was sent.`); }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// One file into the store: { id, kind, name, size, mime }. as: 'report' marks markdown as a report.
|
|
79
|
+
function keep(p, as) {
|
|
80
|
+
const real = realOrDie(p);
|
|
81
|
+
const why = refusal(p, real);
|
|
82
|
+
if (why) die(`${why} Nothing was sent.`);
|
|
83
|
+
const st = fs.statSync(real);
|
|
84
|
+
if (st.isDirectory()) die(`${p} is a folder. Share a folder live with --link ${p}. Nothing was sent.`);
|
|
85
|
+
if (!st.isFile()) die(`${p} isn't a regular file. Nothing was sent.`);
|
|
86
|
+
if (st.size > MAX_FILE) die(`${p} is ${sized(st.size)}; a message carries files up to ${sized(MAX_FILE)}. Share it live instead: --link ${p}. Nothing was sent.`);
|
|
87
|
+
const data = fs.readFileSync(real);
|
|
88
|
+
const id = crypto.createHash('sha256').update(data).digest('hex').slice(0, 32);
|
|
89
|
+
const name = cleanName(p);
|
|
90
|
+
const mime = as === 'report' ? 'text/markdown' : mimeOf(name);
|
|
91
|
+
const kind = as === 'report' ? 'report' : kindOf(name, mime);
|
|
92
|
+
const dir = path.join(MEDIA, id), file = path.join(dir, name), meta = path.join(MEDIA, `${id}.json`);
|
|
93
|
+
const had = fs.existsSync(meta);
|
|
94
|
+
if (!had && stored() + data.length > MAX_STORE) die(`dibs keeps at most ${sized(MAX_STORE)} of attachments, and this would pass it. Older ones go after a week; share this one live with --link ${p}. Nothing was sent.`);
|
|
95
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
96
|
+
if (!fs.existsSync(file)) {
|
|
97
|
+
const other = fs.readdirSync(dir)[0];
|
|
98
|
+
if (other) fs.linkSync(path.join(dir, other), file);
|
|
99
|
+
else { const tmp = `${file}.${process.pid}.tmp`; fs.writeFileSync(tmp, data); fs.renameSync(tmp, file); }
|
|
100
|
+
}
|
|
101
|
+
writeJson(meta, { id, kind, mime, size: data.length, at: now() });
|
|
102
|
+
return { id, kind, name, size: data.length, mime };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// A live share of one file or folder: { id, kind: 'link', name, size, mime, isDir, path }.
|
|
106
|
+
function grant(p) {
|
|
107
|
+
const real = realOrDie(p);
|
|
108
|
+
const why = refusal(p, real);
|
|
109
|
+
if (why) die(`${why} Nothing was sent.`);
|
|
110
|
+
if (real === '/' || real === fs.realpathSync(os.homedir())) die(`${p} would share everything in it. Link the folder that holds what you mean. Nothing was sent.`);
|
|
111
|
+
const st = fs.statSync(real);
|
|
112
|
+
const id = crypto.randomBytes(16).toString('base64url');
|
|
113
|
+
const name = cleanName(real) || real;
|
|
114
|
+
const isDir = st.isDirectory();
|
|
115
|
+
fs.mkdirSync(LINKS, { recursive: true });
|
|
116
|
+
writeJson(path.join(LINKS, `${id}.json`), { id, path: real, isDir, name, at: now() });
|
|
117
|
+
return { id, kind: 'link', name, size: isDir ? 0 : st.size, mime: isDir ? 'inode/directory' : mimeOf(name), isDir, path: real };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function writeJson(file, v) {
|
|
121
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
122
|
+
fs.writeFileSync(tmp, JSON.stringify(v));
|
|
123
|
+
fs.renameSync(tmp, file);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// What the store holds now, after letting go of what's older than a week.
|
|
127
|
+
function stored(t = now()) {
|
|
128
|
+
let total = 0;
|
|
129
|
+
let names = [];
|
|
130
|
+
try { names = fs.readdirSync(MEDIA); } catch { return 0; }
|
|
131
|
+
for (const n of names) {
|
|
132
|
+
if (!n.endsWith('.json')) continue;
|
|
133
|
+
const f = path.join(MEDIA, n);
|
|
134
|
+
try {
|
|
135
|
+
const m = JSON.parse(fs.readFileSync(f, 'utf8'));
|
|
136
|
+
if (t - m.at > KEEP_FOR) { fs.rmSync(path.join(MEDIA, m.id), { recursive: true, force: true }); fs.rmSync(f, { force: true }); continue; }
|
|
137
|
+
total += m.size || 0;
|
|
138
|
+
} catch {}
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
for (const n of fs.readdirSync(LINKS)) {
|
|
142
|
+
const f = path.join(LINKS, n);
|
|
143
|
+
try { if (t - JSON.parse(fs.readFileSync(f, 'utf8')).at > KEEP_FOR) fs.rmSync(f, { force: true }); } catch {}
|
|
144
|
+
}
|
|
145
|
+
} catch {}
|
|
146
|
+
return total;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The flags dibs say, tell and poll share: --file, --report, --link. Returns the args left over
|
|
150
|
+
// and the list asked for, [{ path, as }].
|
|
151
|
+
export function takeFlags(args) {
|
|
152
|
+
const rest = [], want = [];
|
|
153
|
+
for (let i = 0; i < args.length; i++) {
|
|
154
|
+
const a = args[i];
|
|
155
|
+
const as = a === '--file' ? 'file' : a === '--report' ? 'report' : a === '--link' ? 'link' : null;
|
|
156
|
+
if (!as) { rest.push(a); continue; }
|
|
157
|
+
const p = args[++i];
|
|
158
|
+
if (!p) die(`${a} needs a path: dibs say "..." ${a} ./out/${as === 'report' ? 'report.md' : as === 'link' ? 'screenshots' : 'chart.png'}`);
|
|
159
|
+
want.push({ path: p, as });
|
|
160
|
+
}
|
|
161
|
+
if (want.length > MAX_ATTACH) die(`that's ${want.length} attachments; one message carries up to ${MAX_ATTACH}. Put them in a folder and share it with --link. Nothing was sent.`);
|
|
162
|
+
return { rest, want };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Every one checked before any is kept, so one refusal sends nothing.
|
|
166
|
+
export function attach(want) {
|
|
167
|
+
for (const w of want) { const real = realOrDie(w.path); const why = refusal(w.path, real); if (why) die(`${why} Nothing was sent.`); }
|
|
168
|
+
return want.map(w => (w.as === 'link' ? grant(w.path) : keep(w.path, w.as)));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Where an agent on this Mac reads an attachment.
|
|
172
|
+
export const localPath = a => (a.kind === 'link' ? a.path : path.join(MEDIA, a.id, a.name));
|
|
173
|
+
|
|
174
|
+
// A stored file by id: { file, meta } or null.
|
|
175
|
+
export function fileOf(id) {
|
|
176
|
+
if (!FILE_ID.test(String(id))) return null;
|
|
177
|
+
try {
|
|
178
|
+
const meta = JSON.parse(fs.readFileSync(path.join(MEDIA, `${id}.json`), 'utf8'));
|
|
179
|
+
const dir = path.join(MEDIA, id);
|
|
180
|
+
const name = fs.readdirSync(dir).find(n => !n.endsWith('.tmp'));
|
|
181
|
+
return name ? { file: path.join(dir, name), meta: { ...meta, name } } : null;
|
|
182
|
+
} catch { return null; }
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// What a link reads at rel (a path under it, '' for itself): { dir: listing } or { file, meta },
|
|
186
|
+
// { refused } for a path that leaves the grant or looks secret, null for an unknown link or a missing path.
|
|
187
|
+
export function linkOf(id, rel = '') {
|
|
188
|
+
if (!LINK_ID.test(String(id))) return null;
|
|
189
|
+
let g;
|
|
190
|
+
try { g = JSON.parse(fs.readFileSync(path.join(LINKS, `${id}.json`), 'utf8')); } catch { return null; }
|
|
191
|
+
if (now() - g.at > KEEP_FOR) return null;
|
|
192
|
+
if (typeof rel !== 'string' || rel.includes('\0') || path.isAbsolute(rel)) return { refused: 'path is relative to the shared folder' };
|
|
193
|
+
let real;
|
|
194
|
+
try { real = fs.realpathSync(path.resolve(g.path, rel)); } catch { return null; }
|
|
195
|
+
// Inside the grant after every link is resolved: no .., no symlink out.
|
|
196
|
+
if (real !== g.path && !(g.isDir && real.startsWith(g.path + path.sep))) return { refused: 'that path is outside what was shared' };
|
|
197
|
+
if (refusal(real, real)) return { refused: 'that file looks like it holds keys or passwords, so dibs won\'t serve it' };
|
|
198
|
+
const st = fs.statSync(real);
|
|
199
|
+
const name = path.basename(real);
|
|
200
|
+
if (st.isDirectory()) return { dir: listing(g, real) };
|
|
201
|
+
if (!st.isFile()) return { refused: 'that isn\'t a regular file' };
|
|
202
|
+
const mime = mimeOf(name);
|
|
203
|
+
return { file: real, meta: { id, name, mime, kind: kindOf(name, mime), size: st.size, at: st.mtimeMs } };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function listing(g, real) {
|
|
207
|
+
const rel = path.relative(g.path, real);
|
|
208
|
+
let ents = fs.readdirSync(real, { withFileTypes: true }).filter(e => !SECRET.test(path.join(real, e.name)) && !SECRET.test(`${path.join(real, e.name)}/`));
|
|
209
|
+
const more = ents.length > MAX_LIST;
|
|
210
|
+
ents = ents.sort((a, b) => a.name.localeCompare(b.name)).slice(0, MAX_LIST);
|
|
211
|
+
const entries = [];
|
|
212
|
+
for (const e of ents) {
|
|
213
|
+
let st;
|
|
214
|
+
// A symlink that points out of the share isn't listed: it couldn't be opened anyway.
|
|
215
|
+
try { const r = fs.realpathSync(path.join(real, e.name)); if (r !== g.path && !r.startsWith(g.path + path.sep)) continue; st = fs.statSync(r); } catch { continue; }
|
|
216
|
+
const isDir = st.isDirectory();
|
|
217
|
+
const mime = isDir ? 'inode/directory' : mimeOf(e.name);
|
|
218
|
+
entries.push({ name: e.name, path: rel ? `${rel}/${e.name}` : e.name, isDir, size: isDir ? 0 : st.size, mtime: Math.round(st.mtimeMs), kind: isDir ? 'folder' : kindOf(e.name, mime), mime });
|
|
219
|
+
}
|
|
220
|
+
return { id: g.id, name: g.name, root: g.path, path: rel, isDir: true, entries, ...(more && { more: true }) };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// A byte range as HTTP's Range header or the relay's ?range= says it ("bytes=0-99", "0-99", "100-",
|
|
224
|
+
// "-500"), within size: { start, end } inclusive, null for the whole file, false for one that can't be met.
|
|
225
|
+
export function rangeOf(v, size) {
|
|
226
|
+
if (v == null || v === '') return null;
|
|
227
|
+
const m = /^(?:bytes=)?(\d*)-(\d*)$/.exec(String(v).trim());
|
|
228
|
+
if (!m || (m[1] === '' && m[2] === '')) return false;
|
|
229
|
+
let start, end;
|
|
230
|
+
if (m[1] === '') { start = Math.max(0, size - Number(m[2])); end = size - 1; }
|
|
231
|
+
else { start = Number(m[1]); end = m[2] === '' ? size - 1 : Math.min(Number(m[2]), size - 1); }
|
|
232
|
+
return start <= end && start < size ? { start, end } : false;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function readRange(file, start, end) {
|
|
236
|
+
const buf = Buffer.alloc(end - start + 1);
|
|
237
|
+
const fd = fs.openSync(file, 'r');
|
|
238
|
+
try { fs.readSync(fd, buf, 0, buf.length, start); } finally { fs.closeSync(fd); }
|
|
239
|
+
return buf;
|
|
240
|
+
}
|
package/src/news.mjs
CHANGED
|
@@ -37,6 +37,37 @@ export function changelog() {
|
|
|
37
37
|
// The sections after from, up to and including to, oldest first.
|
|
38
38
|
export const since = (from, to) => changelog().filter(c => /^\d/.test(c.version) && newer(c.version, from) && !newer(c.version, to)).reverse();
|
|
39
39
|
|
|
40
|
+
// The what's-new notice every agent session reads once per version is at most this many
|
|
41
|
+
// changes: each version's notes run to a dozen lines, and every session paid for all of them.
|
|
42
|
+
export const NEWS_LINES = 3;
|
|
43
|
+
// A change is cut to its first sentence, and a long first sentence to this.
|
|
44
|
+
const NEWS_WIDTH = 160;
|
|
45
|
+
|
|
46
|
+
// The first sentence of a change: up to the first full stop outside backticks.
|
|
47
|
+
function headline(line) {
|
|
48
|
+
const text = line.replace(/^-\s*/, '').trim();
|
|
49
|
+
let tick = false, end = text.length;
|
|
50
|
+
for (let i = 0; i < text.length; i++) {
|
|
51
|
+
if (text[i] === '`') tick = !tick;
|
|
52
|
+
else if (!tick && text[i] === '.' && (i + 1 === text.length || text[i + 1] === ' ')) { end = i + 1; break; }
|
|
53
|
+
}
|
|
54
|
+
const first = text.slice(0, end);
|
|
55
|
+
if (first.length <= NEWS_WIDTH) return first;
|
|
56
|
+
let cut = first.slice(0, NEWS_WIDTH).replace(/\s+\S*$/, '');
|
|
57
|
+
// Never leave a code span open.
|
|
58
|
+
if ((cut.match(/`/g) || []).length % 2) cut = cut.slice(0, cut.lastIndexOf('`')).trimEnd();
|
|
59
|
+
return `${cut} ...`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// What an agent that last ran from hears on its first command under to: the first change of
|
|
63
|
+
// each version since, newest first, which the changelog puts first because it's what changes
|
|
64
|
+
// what an agent does. At most NEWS_LINES of them; dibs news has the rest.
|
|
65
|
+
export function whatsNew(from, to) {
|
|
66
|
+
const firsts = since(from, to).reverse().map(c => c.body.split('\n').find(l => /^-\s/.test(l))).filter(Boolean);
|
|
67
|
+
const shown = firsts.slice(0, NEWS_LINES).map(l => `- ${headline(l)}`);
|
|
68
|
+
return [`dibs was updated to ${to}. What to do differently (all of it: dibs news):`, ...shown];
|
|
69
|
+
}
|
|
70
|
+
|
|
40
71
|
const readSeen = () => { try { return JSON.parse(fs.readFileSync(paths.seen, 'utf8')); } catch { return {}; } };
|
|
41
72
|
export const seenBy = key => readSeen()[key] || null;
|
|
42
73
|
export function markSeen(key, version) {
|
package/src/notes.mjs
CHANGED
|
@@ -2,14 +2,20 @@
|
|
|
2
2
|
//
|
|
3
3
|
// dibs.md the agent instructions, made from skills/dibs/SKILL.md (one source,
|
|
4
4
|
// no second copy to drift), in the folder dibs is installed in.
|
|
5
|
-
// Rewritten on every install and upgrade,
|
|
5
|
+
// Rewritten on every install and upgrade, and by any dibs command
|
|
6
|
+
// that finds it missing or older than the code (keep()): a git
|
|
7
|
+
// checkout updates by merges, which run no installer.
|
|
6
8
|
// the block a few marked lines in the agents' own instruction files saying to
|
|
7
9
|
// read dibs.md before builds, tests, simulators or deploys:
|
|
8
10
|
// ~/.claude/CLAUDE.md when ~/.claude exists (made if missing)
|
|
9
11
|
// ~/.codex/AGENTS.md when ~/.codex exists (made if missing)
|
|
12
|
+
// ~/.gemini/GEMINI.md when ~/.gemini exists (made if missing)
|
|
13
|
+
// ~/.config/opencode/AGENTS.md when that folder exists (made if missing)
|
|
14
|
+
// Cursor keeps its user rules in its settings, not a file: it reads the
|
|
15
|
+
// repo's AGENTS.md below.
|
|
10
16
|
// 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
|
|
12
|
-
// asked with dibs init --repo
|
|
17
|
+
// when that isn't the home folder or dibs's own source: only files
|
|
18
|
+
// already there, unless asked with dibs init --repo
|
|
13
19
|
//
|
|
14
20
|
// Only what's between the markers is ever written; the rest of a file stays byte for
|
|
15
21
|
// byte. Each write goes to a temp file beside the real one, with its mode, then is
|
|
@@ -41,10 +47,10 @@ export function dibsMd(root = ROOT) {
|
|
|
41
47
|
return [
|
|
42
48
|
'# dibs: instructions for coding agents',
|
|
43
49
|
'',
|
|
44
|
-
`Written by dibs ${VERSION}
|
|
45
|
-
`
|
|
50
|
+
`Written by dibs ${VERSION}, and rewritten whenever dibs changes, so edits don't last.`,
|
|
51
|
+
`The full agent reference: ${path.join(root, 'docs', 'agents.md')}. Every command: \`dibs help all\`. Docs: https://dibs.cc`,
|
|
46
52
|
'',
|
|
47
|
-
body || 'Run builds, tests, simulators and deploys through dibs: `dibs run <resource> -m "why" -- <command>`. `dibs help` lists everything.',
|
|
53
|
+
body || 'Run builds, tests, simulators and deploys through dibs: `dibs run <resource> -m "<what this does and why, in plain words>" -- <command>`. `dibs help` lists everything.',
|
|
48
54
|
'',
|
|
49
55
|
].join('\n');
|
|
50
56
|
}
|
|
@@ -86,11 +92,17 @@ export function withoutBlock(text) {
|
|
|
86
92
|
return before + after;
|
|
87
93
|
}
|
|
88
94
|
|
|
89
|
-
//
|
|
95
|
+
// dibs's own source (this checkout, a worktree of it, a clone): its AGENTS.md and CLAUDE.md
|
|
96
|
+
// are tracked instructions for working on dibs, and a note in them would be committed.
|
|
97
|
+
function dibsSource(top) {
|
|
98
|
+
try { return JSON.parse(fs.readFileSync(path.join(top, 'package.json'), 'utf8')).name === '@dibssoftware/dibs'; } catch { return false; }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// The git repo the command runs in, unless it's the home folder itself or dibs's own source.
|
|
90
102
|
function repoRoot(cwd) {
|
|
91
103
|
try {
|
|
92
104
|
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;
|
|
105
|
+
return top && path.resolve(top) !== path.resolve(os.homedir()) && !dibsSource(top) ? top : null;
|
|
94
106
|
} catch { return null; }
|
|
95
107
|
}
|
|
96
108
|
|
|
@@ -99,6 +111,9 @@ function targets(cwd, repo) {
|
|
|
99
111
|
const home = os.homedir(), out = [];
|
|
100
112
|
if (fs.existsSync(path.join(home, '.claude'))) out.push({ file: path.join(home, '.claude', 'CLAUDE.md'), made: true });
|
|
101
113
|
if (fs.existsSync(path.join(home, '.codex'))) out.push({ file: path.join(home, '.codex', 'AGENTS.md'), made: true });
|
|
114
|
+
if (fs.existsSync(path.join(home, '.gemini'))) out.push({ file: path.join(home, '.gemini', 'GEMINI.md'), made: true });
|
|
115
|
+
const opencode = path.join(process.env.XDG_CONFIG_HOME || path.join(home, '.config'), 'opencode');
|
|
116
|
+
if (fs.existsSync(opencode)) out.push({ file: path.join(opencode, 'AGENTS.md'), made: true });
|
|
102
117
|
const top = repoRoot(cwd);
|
|
103
118
|
if (top) {
|
|
104
119
|
const there = ['CLAUDE.md', 'AGENTS.md'].map(n => path.join(top, n)).filter(f => fs.existsSync(f));
|
|
@@ -115,6 +130,32 @@ function mdPlace(root) {
|
|
|
115
130
|
try { fs.accessSync(root, fs.constants.W_OK); return f; } catch { return path.join(HOME, 'dibs.md'); }
|
|
116
131
|
}
|
|
117
132
|
|
|
133
|
+
const mtime = f => { try { return fs.statSync(f).mtimeMs; } catch { return 0; } };
|
|
134
|
+
|
|
135
|
+
// dibs.md present and current, from any dibs command: three stats when it is, which is
|
|
136
|
+
// nearly always. It's behind when the skill or the version changed after it was written (a
|
|
137
|
+
// git merge in the checkout dibs runs from, an upgrade), or gone (a fresh clone: it's
|
|
138
|
+
// gitignored). Only dibs.md: the notes in the agents' files name its place, which this
|
|
139
|
+
// doesn't move, and they're dibs init's to write. Never throws: the command comes first.
|
|
140
|
+
// DIBS_KEEP_MD=0 turns it off (test/helpers.mjs, so tests don't race on the checkout's copy).
|
|
141
|
+
export function keep(root = ROOT) {
|
|
142
|
+
if (off() || process.env.DIBS_KEEP_MD === '0') return null;
|
|
143
|
+
try {
|
|
144
|
+
const md = mdPlace(root);
|
|
145
|
+
const at = mtime(md);
|
|
146
|
+
const versionFile = path.join(root, 'src', 'version.mjs');
|
|
147
|
+
if (at && at > mtime(path.join(root, 'skills', 'dibs', 'SKILL.md')) && at > mtime(versionFile)) return null;
|
|
148
|
+
// A process started before an update would write the old version's number: the next one writes it.
|
|
149
|
+
if (/VERSION = '([^']+)'/.exec(fs.readFileSync(versionFile, 'utf8'))?.[1] !== VERSION) return null;
|
|
150
|
+
const text = dibsMd(root);
|
|
151
|
+
let old = null;
|
|
152
|
+
try { old = fs.readFileSync(md, 'utf8'); } catch {}
|
|
153
|
+
if (old === text) { const t = new Date(); fs.utimesSync(md, t, t); return null; }
|
|
154
|
+
writeAtomic(md, text);
|
|
155
|
+
return md;
|
|
156
|
+
} catch { return null; }
|
|
157
|
+
}
|
|
158
|
+
|
|
118
159
|
// Write dibs.md and the blocks. Returns the files that changed.
|
|
119
160
|
export function write({ root = ROOT, cwd = process.cwd(), repo = false } = {}) {
|
|
120
161
|
const changed = [];
|
package/src/notices.mjs
CHANGED
|
@@ -13,12 +13,16 @@ import path from 'node:path';
|
|
|
13
13
|
import { paths, HOME } from './config.mjs';
|
|
14
14
|
import { peek, history } from './state.mjs';
|
|
15
15
|
import { notify } from './talk.mjs';
|
|
16
|
-
import { minutes, stuckFor } from './plain.mjs';
|
|
16
|
+
import { minutes, stuckFor, slowText, andList } from './plain.mjs';
|
|
17
|
+
import { slowness, LONG_OVER } from './jobprogress.mjs';
|
|
17
18
|
import { stuckLeases } from './acquire.mjs';
|
|
18
19
|
import { overAskLine } from './measure.mjs';
|
|
19
20
|
import { now, callerPid, clock } from './util.mjs';
|
|
20
|
-
import {
|
|
21
|
+
import { sessionFiles } from './proc.mjs';
|
|
22
|
+
import { read as readPosts, tasks, QUIET_AFTER, FILE as POSTS } from './progress.mjs';
|
|
21
23
|
import { quoted } from './style.mjs';
|
|
24
|
+
import { described } from './declare.mjs';
|
|
25
|
+
import { writeWhole } from './durable.mjs';
|
|
22
26
|
|
|
23
27
|
// Which runs look stuck and which used more memory than they asked for is
|
|
24
28
|
// decided where the board decides it (stuckLeases, l.overAsk), so the notice
|
|
@@ -29,10 +33,12 @@ export const NOTICE_EVERY = 20e3;
|
|
|
29
33
|
let last = 0;
|
|
30
34
|
const sent = new Set();
|
|
31
35
|
|
|
32
|
-
const what = l => `#${l.id} (${l
|
|
36
|
+
const what = l => `#${l.id} ("${described(l)}"${l.cmd ? `, ${l.cmd.slice(0, 60)}` : ''})`;
|
|
33
37
|
|
|
34
|
-
// [lease, once, text] for each notice the state holds, for the lease's agent.
|
|
35
|
-
|
|
38
|
+
// [lease, once, text, quiet] for each notice the state holds, for the lease's agent. quiet: it
|
|
39
|
+
// asks nothing of the agent now, so it doesn't wake a dibs listen (src/talk.mjs notify).
|
|
40
|
+
// hist: run history, for a job running several times its usual time (src/jobprogress.mjs).
|
|
41
|
+
export function noticesIn(s, t = now(), hist = []) {
|
|
36
42
|
const out = [];
|
|
37
43
|
const waiting = (s.queue || []).filter(q => q.pid);
|
|
38
44
|
const stuck = new Set(stuckLeases({ queue: [], leases: [], ...s }, t));
|
|
@@ -40,17 +46,26 @@ export function noticesIn(s, t = now()) {
|
|
|
40
46
|
const others = waiting.filter(q => q.res.some(r => l.res.includes(r)));
|
|
41
47
|
if (stuck.has(l) && others.length)
|
|
42
48
|
out.push([l, `idle:#${l.id}`, `your job ${what(l)} has used no CPU for ${minutes(stuckFor(l, t))} while ${others.length} other `
|
|
43
|
-
+ `${others.length === 1 ? 'job waits' : 'jobs wait'} for ${l.res.join(', ')}.
|
|
44
|
-
+ `running it, or kill ${l.pid} (its dibs run, which takes the whole job down
|
|
49
|
+
+ `${others.length === 1 ? 'job waits' : 'jobs wait'} for ${l.res.join(', ')}. A job waiting on the network or another machine uses no CPU either. `
|
|
50
|
+
+ `Ending it frees the turn: stop the tool call or background task running it, or kill ${l.pid} (its dibs run, which takes the whole job down).`]);
|
|
45
51
|
if (l.overAsk?.used && l.overAsk.asked && l.overAsk.suggest)
|
|
46
|
-
out.push([l, `mem:#${l.id}`, `your job ${what(l)}: ${overAskLine(l.overAsk)}
|
|
52
|
+
out.push([l, `mem:#${l.id}`, `your job ${what(l)}: ${overAskLine(l.overAsk)}`, true]);
|
|
47
53
|
if (l.loadPast)
|
|
48
54
|
out.push([l, `loadpast:#${l.id}`, `your job ${what(l)} waited ${minutes(l.loadWaited || 0)} for the machine's load to fall, so it started anyway at background priority on the efficiency cores. `
|
|
49
|
-
+ 'It runs slower there. If a person is waiting on it now, raise it: dibs boost ' + l.id + ' high -m "why".']);
|
|
55
|
+
+ 'It runs slower there. If a person is waiting on it now, raise it: dibs boost ' + l.id + ' high -m "why".', true]);
|
|
56
|
+
// Far off its own pace: the agent hears once, with who waits behind it. dibs never stops it.
|
|
57
|
+
const sl = slowness(l, hist, t);
|
|
58
|
+
if (sl) {
|
|
59
|
+
const behind = others.slice(0, 3).map(q => `${q.who}${q.purpose ? `'s "${described(q)}"` : ''}`);
|
|
60
|
+
out.push([l, `slow:#${l.id}`, `your job ${what(l)} ${slowText(sl)}`
|
|
61
|
+
+ `${others.length ? `, while ${andList(others.length > 3 ? [...behind, `${others.length - 3} more`] : behind)} ${others.length > 1 ? 'wait' : 'waits'} behind it for ${l.res.join(', ')}` : ''}. `
|
|
62
|
+
+ `dibs won't stop it. If it's stuck or no longer worth it, end it: stop the tool call or background task running it, or kill ${l.pid} (its dibs run). If it's working, leave it`
|
|
63
|
+
+ `${l.progress ? '' : '; reporting progress from it (dibs progress 40%) lets dibs tell slow from stuck next time'}.`, !others.length]);
|
|
64
|
+
}
|
|
50
65
|
const watcher = (l.pauses || []).filter(p => p.watcher && !p.gone);
|
|
51
66
|
if (l.pausedAt && watcher.length)
|
|
52
67
|
out.push([l, `paused:#${l.id}:${l.pausedAt}`, `your job ${what(l)} was paused because free ${watcher.some(p => p.disk) ? 'disk' : 'memory'} is low. `
|
|
53
|
-
+ "It keeps its turn and resumes by itself when there's room: don't run it again or end it."]);
|
|
68
|
+
+ "It keeps its turn and resumes by itself when there's room: don't run it again or end it.", true]);
|
|
54
69
|
}
|
|
55
70
|
return out;
|
|
56
71
|
}
|
|
@@ -62,78 +77,146 @@ export function noticeScan(t = now()) {
|
|
|
62
77
|
last = t;
|
|
63
78
|
try {
|
|
64
79
|
const s = JSON.parse(fs.readFileSync(paths.state, 'utf8'));
|
|
65
|
-
|
|
80
|
+
// History only matters to a job that has run long enough to be long (src/jobprogress.mjs LONG_OVER).
|
|
81
|
+
const hist = (s.leases || []).some(l => l.kind === 'run' && t - l.start > LONG_OVER) ? history() : [];
|
|
82
|
+
for (const [l, once, text, quiet] of noticesIn(s, t, hist)) {
|
|
66
83
|
if (sent.has(once)) continue;
|
|
67
84
|
sent.add(once);
|
|
68
|
-
notify(l, once, text);
|
|
85
|
+
notify(l, once, text, { quiet: !!quiet });
|
|
69
86
|
}
|
|
70
87
|
} catch {}
|
|
71
88
|
}
|
|
72
89
|
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
|
|
90
|
+
// One nudge per task, ever: on 2026-11-03, 5 of 35 notices were these, and agents
|
|
91
|
+
// were posting progress only to stop them; on 2026-11-28 an agent read one every 45
|
|
92
|
+
// minutes. Kept a day, as long as a task can stay open without a post.
|
|
93
|
+
export const NAG_KEEP = 864e5;
|
|
76
94
|
// An agent with no job running or waiting, and none run in this long, isn't
|
|
77
95
|
// working now: its open task waits quietly for it to come back.
|
|
78
96
|
export const AWAY_AFTER = 30 * 6e4;
|
|
79
97
|
const NAGS = path.join(HOME, 'nags.json');
|
|
80
98
|
|
|
81
|
-
// [to, once, text, task] for each task still in progress that needs a word
|
|
99
|
+
// [to, once, text, task, quiet, close] for each task still in progress that needs a word
|
|
82
100
|
// from whoever posted it: past its ETA, or with no post for QUIET_AFTER.
|
|
83
101
|
// Expired tasks are let go. Only tasks posted from a Claude Code session: the
|
|
84
102
|
// hook is how the notice arrives. A subagent's task is nudged to that subagent;
|
|
85
|
-
// once it has ended (ended(k)),
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
|
|
103
|
+
// once it has ended (ended(k)), dibs closes the task (close: the task to close) and its
|
|
104
|
+
// lead hears once: it read "let go 5 hr 15 min from now" (2026-11-28), hours of an open
|
|
105
|
+
// task nobody would post to again.
|
|
106
|
+
// nagged: which tasks were nudged, and when; working(k): whether the agent the notice
|
|
107
|
+
// would go to has worked since its last post (a nudge on a timer alone came at 11 PM with
|
|
108
|
+
// nothing changed, 2026-11-28); running(k): whether a dibs job of its is running or waiting,
|
|
109
|
+
// which is progress the person already sees, so it isn't nudged then.
|
|
110
|
+
// Every nudge is quiet: it asks for a post, not for the agent to wake (src/talk.mjs notify).
|
|
111
|
+
export function progressNoticesIn(posts, t = now(), { nagged = {}, working = () => true, ended = () => false, running = () => false } = {}) {
|
|
89
112
|
const out = [];
|
|
90
113
|
for (const k of tasks(posts, t)) {
|
|
91
114
|
if (k.state !== 'doing' || !k.session) continue;
|
|
92
115
|
const task = `${k.who}:${k.agentId || 'main'}:${k.task || k.project}`;
|
|
93
116
|
const name = k.task ? `"${k.task}"` : `in ${k.project || 'this folder'}`;
|
|
94
117
|
if (k.agentId && ended(k)) {
|
|
95
|
-
// Said once: nothing to do, it expires by itself; the lead only shouldn't be surprised.
|
|
96
118
|
const lead = `${task}:lead`;
|
|
97
|
-
if (nagged[lead]
|
|
119
|
+
if (nagged[lead]) continue;
|
|
98
120
|
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)})
|
|
100
|
-
+ `If the work goes on, post it under your own task.`, lead]);
|
|
121
|
+
+ `(last post at ${clock(k.last)}), so dibs closed it. If the work goes on, post it under your own task.`, lead, true, k]);
|
|
101
122
|
continue;
|
|
102
123
|
}
|
|
103
|
-
|
|
124
|
+
// A post this recent is fresh, even past its ETA: the agent just said where it stands.
|
|
125
|
+
if (nagged[task] || t - k.last <= QUIET_AFTER || running(k) || !working(k)) continue;
|
|
104
126
|
const to = { sessionId: k.session, who: k.who, ...(k.agentId && { agentId: k.agentId }) };
|
|
105
127
|
const again = (...more) => quoted(['dibs', 'progress', 'where it stands', ...(k.task ? ['--task', k.task] : []), ...more]);
|
|
106
128
|
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
|
|
109
|
-
+ `Post where it stands (${again()}), or close it: --done if it's finished, --blocked if it's stuck.`, task]);
|
|
129
|
+
+ `If it's finished, say so: ${again('--done')}. If not, post where it stands with a new time: ${again('--eta', '30m')}.`, task, true]);
|
|
130
|
+
else out.push([to, `quiet:${task}:${k.last}`, `your progress task ${name} has had no post for ${minutes(t - k.last)}. `
|
|
131
|
+
+ `Post where it stands (${again()}), or close it: --done if it's finished, --blocked if it's stuck.`, task, true]);
|
|
110
132
|
}
|
|
111
133
|
return out;
|
|
112
134
|
}
|
|
113
135
|
|
|
114
136
|
const DAY = 864e5;
|
|
137
|
+
// A session's or subagent's dibs job running or waiting now. A subagent counts only its own
|
|
138
|
+
// jobs (they carry its id); a main agent counts any of its session's, or any under its name.
|
|
139
|
+
function runningIn(s) {
|
|
140
|
+
const mine = k => x => x.sessionId === k.session && (k.agentId ? x.agentId === k.agentId : true);
|
|
141
|
+
return k => (s.leases || []).some(mine(k)) || (s.queue || []).some(q => q.pid && mine(k)(q)) || (!k.agentId && (s.leases || []).some(l => l.who === k.who));
|
|
142
|
+
}
|
|
143
|
+
const readNags = () => { try { return JSON.parse(fs.readFileSync(NAGS, 'utf8')); } catch { return {}; } };
|
|
144
|
+
// Each nudge is remembered a day, so a watcher restart can't repeat it.
|
|
145
|
+
function writeNags(nagged, before, t) {
|
|
146
|
+
for (const [k, at] of Object.entries(nagged)) if (t - at >= NAG_KEEP) delete nagged[k];
|
|
147
|
+
if (JSON.stringify(nagged) !== before) writeWhole(NAGS, JSON.stringify(nagged));
|
|
148
|
+
}
|
|
149
|
+
// A subagent's open task closed under dibs's name, so the page and phones stop showing it in progress.
|
|
150
|
+
function closeTask(k, t) {
|
|
151
|
+
const p = { at: t, who: k.who, ...(k.label && { label: k.label }), session: k.session, agentId: k.agentId, ...(k.project && { project: k.project }),
|
|
152
|
+
...(k.task && { task: k.task }), state: 'done', by: 'dibs', text: `closed by dibs: its subagent ended with it open (last post at ${clock(k.last)}).` };
|
|
153
|
+
fs.appendFileSync(POSTS, `${JSON.stringify(p)}\n`);
|
|
154
|
+
}
|
|
155
|
+
|
|
115
156
|
// From the throttle watcher (src/cool.mjs), which is always running: no waiter needed.
|
|
116
|
-
export function progressScan(t = now()) {
|
|
157
|
+
export async function progressScan(t = now()) {
|
|
117
158
|
try {
|
|
118
|
-
|
|
119
|
-
try { nagged = JSON.parse(fs.readFileSync(NAGS, 'utf8')); } catch {}
|
|
159
|
+
const nagged = readNags();
|
|
120
160
|
const s = peek(), hist = history();
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
161
|
+
const running = runningIn(s);
|
|
162
|
+
// At work since its last post: a tool call since then in the last AT_WORK (its transcript), or for
|
|
163
|
+
// a main agent a dibs job run since then in the last AWAY_AFTER (history doesn't say which subagent).
|
|
164
|
+
const { about, workFor } = await import('./about.mjs');
|
|
165
|
+
const toolAt = k => workFor(k.session, k.agentId || 'main')?.tool?.at || 0;
|
|
166
|
+
const working = k => (!k.agentId && hist.some(r => r.who === k.who && r.at > k.last && t - r.at < AWAY_AFTER))
|
|
167
|
+
|| (toolAt(k) > k.last && t - toolAt(k) < AT_WORK);
|
|
168
|
+
// Ended: Claude Code marked the subagent finished, or it has no job and no post in AWAY_AFTER.
|
|
169
|
+
const ended = k => !running(k) && (t - k.last >= AWAY_AFTER || about(k.session, k.agentId)?.finished === true);
|
|
128
170
|
const before = JSON.stringify(nagged);
|
|
129
|
-
for (const [to, once, text, task] of progressNoticesIn(readPosts({ since: t - DAY }), t, { nagged, working, ended })) {
|
|
171
|
+
for (const [to, once, text, task, quiet, close] of progressNoticesIn(readPosts({ since: t - DAY }), t, { nagged, working, ended, running })) {
|
|
130
172
|
if (sent.has(once)) continue;
|
|
131
173
|
sent.add(once);
|
|
132
|
-
if (
|
|
174
|
+
if (close) closeTask(close, t);
|
|
175
|
+
// The closing is what matters: it's remembered even when the lead's notice couldn't be left.
|
|
176
|
+
if (notify(to, once, text, { quiet: !!quiet }) || close) nagged[task] = t;
|
|
133
177
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
178
|
+
writeNags(nagged, before, t);
|
|
179
|
+
} catch {}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// An agent at work this long on the person's newest prompt, with no progress post and no plan
|
|
183
|
+
// since, hears once how to say what it's doing: the person's screens show its plan and posts,
|
|
184
|
+
// and without them only "No update for 20 min" (src/picture.mjs). Once per session: told how,
|
|
185
|
+
// it knows, and telling it again at every prompt is the nag agents learn to skip.
|
|
186
|
+
export const UNSAID_AFTER = 20 * 6e4;
|
|
187
|
+
// At work: a tool call this recent.
|
|
188
|
+
const AT_WORK = 5 * 6e4;
|
|
189
|
+
// [to, once, text, key] for each Claude Code session that should hear it. sessions: sessionFiles()
|
|
190
|
+
// still running; workOf(sessionId): its transcript's work (src/about.mjs workFor); posts: the day's;
|
|
191
|
+
// running(sessionId): a dibs job of the session's running or waiting, which the person already sees.
|
|
192
|
+
export function unsaidNoticesIn(sessions, workOf, posts, t = now(), nagged = {}, running = () => false) {
|
|
193
|
+
const out = [];
|
|
194
|
+
for (const f of sessions) {
|
|
195
|
+
const key = `unsaid:${f.sessionId}`;
|
|
196
|
+
if (nagged[key] || running(f.sessionId)) continue;
|
|
197
|
+
const w = workOf(f.sessionId);
|
|
198
|
+
const from = w?.prompt;
|
|
199
|
+
if (!from || !w.tool?.at || t - w.tool.at > AT_WORK || w.tool.at < from || t - from < UNSAID_AFTER) continue;
|
|
200
|
+
if (w.plan && (w.plan.at || 0) >= from) continue;
|
|
201
|
+
// A post since the prompt, or one still fresh from before it.
|
|
202
|
+
if (posts.some(p => p.session === f.sessionId && !p.agentId && (p.at >= from || t - p.at <= QUIET_AFTER))) continue;
|
|
203
|
+
out.push([{ sessionId: f.sessionId, who: f.name }, `${key}:${from}`, `you've been at work for ${minutes(t - from)} and the person can't see on what: `
|
|
204
|
+
+ 'no progress post and no plan since their last message. Post what you\'re doing: dibs progress "..." --task <name> (now, then as it moves).', key]);
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// From the throttle watcher, beside progressScan. Reads transcripts, so it's loaded only here.
|
|
210
|
+
export async function unsaidScan(t = now()) {
|
|
211
|
+
try {
|
|
212
|
+
const { workFor } = await import('./about.mjs');
|
|
213
|
+
const nagged = readNags(), before = JSON.stringify(nagged);
|
|
214
|
+
const s = peek();
|
|
215
|
+
const busy = id => (s.leases || []).some(l => l.sessionId === id) || (s.queue || []).some(q => q.pid && q.sessionId === id);
|
|
216
|
+
const alive = pid => { try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; } };
|
|
217
|
+
const found = unsaidNoticesIn(sessionFiles().filter(f => alive(f.pid)), id => workFor(id, 'main'), readPosts({ since: t - DAY }), t, nagged, busy);
|
|
218
|
+
for (const [to, once, text, key] of found) if (!sent.has(once) && notify(to, once, text, { quiet: true })) { sent.add(once); nagged[key] = t; }
|
|
219
|
+
writeNags(nagged, before, t);
|
|
137
220
|
} catch {}
|
|
138
221
|
}
|
|
139
222
|
|