@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.
Files changed (107) hide show
  1. package/CHANGELOG.md +111 -1
  2. package/README.md +10 -8
  3. package/bin/dibs.mjs +379 -74
  4. package/docs/agents.md +303 -0
  5. package/docs/council.md +88 -0
  6. package/docs/files.md +3 -3
  7. package/docs/guard.md +86 -11
  8. package/docs/json.md +211 -0
  9. package/docs/later.md +5 -5
  10. package/docs/machines.md +6 -6
  11. package/docs/questions.md +104 -3
  12. package/docs/reference.md +124 -30
  13. package/docs/relay.md +135 -11
  14. package/docs/releasing.md +7 -1
  15. package/docs/scheduling.md +28 -6
  16. package/docs/secrets.md +53 -0
  17. package/docs/simulators.md +3 -3
  18. package/docs/windows.md +3 -3
  19. package/package.json +1 -1
  20. package/skills/dibs/SKILL.md +79 -149
  21. package/src/about.mjs +341 -0
  22. package/src/acquire.mjs +113 -28
  23. package/src/after.mjs +127 -0
  24. package/src/agents.mjs +2 -1
  25. package/src/alerts.mjs +109 -48
  26. package/src/answers.mjs +2 -2
  27. package/src/board.mjs +21 -16
  28. package/src/broker.mjs +23 -7
  29. package/src/carry.mjs +287 -0
  30. package/src/codex.mjs +132 -0
  31. package/src/commands.mjs +254 -86
  32. package/src/config.mjs +85 -14
  33. package/src/connect.mjs +4 -2
  34. package/src/cool.mjs +28 -12
  35. package/src/council.mjs +482 -0
  36. package/src/cwd.mjs +9 -0
  37. package/src/decisions.mjs +250 -0
  38. package/src/declare.mjs +96 -0
  39. package/src/diskreport.mjs +306 -0
  40. package/src/diskuse.mjs +420 -0
  41. package/src/diskwarn.mjs +68 -13
  42. package/src/doctor.mjs +149 -0
  43. package/src/doors.mjs +547 -0
  44. package/src/durable.mjs +143 -0
  45. package/src/envs.mjs +372 -0
  46. package/src/events.mjs +7 -2
  47. package/src/files.mjs +121 -7
  48. package/src/guard.mjs +288 -105
  49. package/src/guardd.mjs +8 -1
  50. package/src/halt.mjs +63 -0
  51. package/src/handoffs.mjs +362 -0
  52. package/src/history.mjs +34 -4
  53. package/src/hogs.mjs +36 -8
  54. package/src/jobprogress.mjs +283 -0
  55. package/src/later.mjs +21 -10
  56. package/src/lock.mjs +51 -11
  57. package/src/measure.mjs +60 -14
  58. package/src/media.mjs +240 -0
  59. package/src/news.mjs +31 -0
  60. package/src/notes.mjs +49 -8
  61. package/src/notices.mjs +126 -43
  62. package/src/ondemand.mjs +25 -2
  63. package/src/outcome.mjs +163 -0
  64. package/src/overlap.mjs +2 -2
  65. package/src/override.mjs +149 -79
  66. package/src/owner.mjs +15 -2
  67. package/src/people.mjs +236 -0
  68. package/src/pickup.mjs +72 -0
  69. package/src/picture.mjs +321 -0
  70. package/src/plain.mjs +84 -18
  71. package/src/platform.mjs +29 -7
  72. package/src/preempt.mjs +123 -15
  73. package/src/primer.mjs +91 -20
  74. package/src/prints.mjs +99 -0
  75. package/src/proc.mjs +11 -1
  76. package/src/progress.mjs +49 -3
  77. package/src/proof.mjs +102 -0
  78. package/src/push.mjs +271 -0
  79. package/src/questions.mjs +328 -57
  80. package/src/quota.mjs +1 -1
  81. package/src/recap.mjs +205 -0
  82. package/src/relay.mjs +262 -26
  83. package/src/remote.mjs +23 -10
  84. package/src/reviewgate.mjs +268 -0
  85. package/src/reviews.mjs +377 -0
  86. package/src/route.mjs +263 -0
  87. package/src/rules.mjs +216 -0
  88. package/src/schedule.mjs +238 -44
  89. package/src/schema.mjs +62 -0
  90. package/src/scratch.mjs +2 -2
  91. package/src/serve.mjs +3 -2
  92. package/src/service.mjs +5 -1
  93. package/src/signed.mjs +97 -0
  94. package/src/simpool.mjs +46 -1
  95. package/src/spend.mjs +375 -0
  96. package/src/state.mjs +43 -17
  97. package/src/talk.mjs +1082 -134
  98. package/src/thin.sh +2 -0
  99. package/src/trail.mjs +290 -0
  100. package/src/trailnote.mjs +209 -0
  101. package/src/util.mjs +7 -0
  102. package/src/vault.mjs +435 -0
  103. package/src/vendors.mjs +327 -0
  104. package/src/version.mjs +1 -1
  105. package/src/web.mjs +354 -60
  106. package/src/work.mjs +487 -0
  107. package/src/worker.mjs +7 -1
package/src/about.mjs ADDED
@@ -0,0 +1,341 @@
1
+ // What an agent is and what it's doing, for the person's screens: read from Claude Code's own
2
+ // transcripts, never from anything the agent has to post. A session's title (Claude Code names
3
+ // each one), its project and branch, its model, what it was asked, and the tool it called last;
4
+ // a subagent's brief (the description its lead gave it) and its kind.
5
+ //
6
+ // Transcripts are megabytes, so only their last TAIL bytes are read, and each file's reading is
7
+ // kept until it grows. Nothing here runs in the hook: only threadsJson (the page, the apps,
8
+ // dibs threads --json) asks.
9
+ import fs from 'node:fs';
10
+ import os from 'node:os';
11
+ import path from 'node:path';
12
+ import { outcomeOf, firstSentence } from './outcome.mjs';
13
+
14
+ const fwd = p => (process.platform === 'win32' ? p.replace(/\\/g, '/') : p);
15
+
16
+ const PROJECTS = process.env.DIBS_CLAUDE_PROJECTS || path.join(os.homedir(), '.claude', 'projects');
17
+ // The last 256 KB holds the newest title, tool call and model in all but the longest tool outputs.
18
+ const TAIL = 256 * 1024;
19
+ // What it was asked is the transcript's first prompt; one longer than this is cut.
20
+ const HEAD = 64 * 1024;
21
+ // The brief as it reaches a phone screen: the first lines of it.
22
+ const PROMPT_SHOWN = 600;
23
+
24
+ const kept = new Map();
25
+ let dirs = null, dirsAt = 0;
26
+
27
+ // Claude Code keeps a session's transcript under a folder named for its project; find it by name.
28
+ function transcriptOf(session) {
29
+ if (!/^[\w-]{1,128}$/.test(session || '')) return null;
30
+ const hit = kept.get(`path:${session}`);
31
+ if (hit && fs.existsSync(hit)) return hit;
32
+ if (!dirs || Date.now() - dirsAt > 30e3) {
33
+ try { dirs = fs.readdirSync(PROJECTS); } catch { dirs = []; }
34
+ dirsAt = Date.now();
35
+ }
36
+ for (const d of dirs) {
37
+ const f = path.join(PROJECTS, d, `${session}.jsonl`);
38
+ if (fs.existsSync(f)) { kept.set(`path:${session}`, f); return f; }
39
+ }
40
+ return null;
41
+ }
42
+
43
+ function slice(file, from, length) {
44
+ const fd = fs.openSync(file, 'r');
45
+ try {
46
+ const buf = Buffer.alloc(length);
47
+ const n = fs.readSync(fd, buf, 0, length, from);
48
+ return buf.subarray(0, n).toString('utf8');
49
+ } finally { fs.closeSync(fd); }
50
+ }
51
+
52
+ function lines(text, { dropFirst = false, dropLast = false } = {}) {
53
+ const parts = text.split('\n');
54
+ if (dropFirst) parts.shift();
55
+ if (dropLast) parts.pop();
56
+ const out = [];
57
+ for (const l of parts) { if (!l) continue; try { out.push(JSON.parse(l)); } catch {} }
58
+ return out;
59
+ }
60
+
61
+ // "claude-opus-5-5" -> "Opus 5.5". Other models keep their own names.
62
+ export function modelName(id) {
63
+ const m = /^claude-(opus|sonnet|haiku|fable)-(\d+)(?:-(\d{1,2}))?(?:-\d{8})?$/.exec(id || '');
64
+ if (!m) return id || null;
65
+ return `${m[1][0].toUpperCase()}${m[1].slice(1)} ${m[2]}${m[3] ? `.${m[3]}` : ''}`;
66
+ }
67
+
68
+ const base = p => (typeof p === 'string' && p ? path.basename(p) : null);
69
+ const cut = (s, n) => (s.length > n ? `${s.slice(0, n - 3).trimEnd()}...` : s);
70
+
71
+ // The tool it called last, in the words a person reads. A Bash call says only its description:
72
+ // a command line can carry a token.
73
+ export function doing(name, input = {}) {
74
+ const i = input || {};
75
+ switch (name) {
76
+ case 'Bash': return i.description ? cut(String(i.description), 90) : 'Running a command';
77
+ case 'Edit': case 'MultiEdit': return `Editing ${base(i.file_path) || 'a file'}`;
78
+ case 'Write': return `Writing ${base(i.file_path) || 'a file'}`;
79
+ case 'Read': return `Reading ${base(i.file_path) || 'a file'}`;
80
+ case 'NotebookEdit': return `Editing ${base(i.notebook_path) || 'a notebook'}`;
81
+ case 'Grep': case 'Glob': return 'Searching the code';
82
+ case 'Agent': case 'Task': return i.description ? `Started a subagent: ${cut(String(i.description), 70)}` : 'Started a subagent';
83
+ case 'WebSearch': return 'Searching the web';
84
+ case 'WebFetch': { try { return `Reading ${new URL(i.url).hostname}`; } catch { return 'Reading a web page'; } }
85
+ case 'AskUserQuestion': return 'Asking you a question';
86
+ case 'TodoWrite': case 'TaskCreate': case 'TaskUpdate': return 'Updating its to-do list';
87
+ case 'Skill': return i.skill ? `Using the ${i.skill} skill` : 'Using a skill';
88
+ }
89
+ const mcp = /^mcp__(.+?)__(.+)$/.exec(name || '');
90
+ if (mcp) return `Using ${mcp[1].replace(/^plugin_|^claude_ai_/, '').replace(/[_-]+/g, ' ')}: ${mcp[2].replace(/[_-]+/g, ' ')}`;
91
+ return name ? `Using ${name}` : null;
92
+ }
93
+
94
+ // The first thing the person (or its lead) asked, without the reminders Claude Code wraps around it.
95
+ function firstPrompt(entries) {
96
+ for (const e of entries) {
97
+ if (e.type !== 'user' || e.isMeta || e.message?.role !== 'user') continue;
98
+ const c = e.message.content;
99
+ const text = typeof c === 'string' ? c : Array.isArray(c) ? c.filter(x => x?.type === 'text').map(x => x.text).join('\n') : '';
100
+ const plain = text.replace(/<([\w-]+)>[\s\S]*?<\/\1>/g, '').trim();
101
+ if (plain && !plain.startsWith('<') && !plain.startsWith('Caveat:')) return cut(plain, PROMPT_SHOWN);
102
+ }
103
+ return null;
104
+ }
105
+
106
+ // Newest first: the newest title, branch, folder, model and tool call in the tail.
107
+ function fromTail(entries) {
108
+ const out = {};
109
+ let seen = false;
110
+ for (let k = entries.length - 1; k >= 0; k--) {
111
+ const e = entries[k];
112
+ if (!out.title && e.type === 'ai-title' && e.aiTitle) out.title = String(e.aiTitle);
113
+ if (!out.title && e.type === 'custom-title' && e.customTitle) out.title = String(e.customTitle);
114
+ if (out.branch === undefined && typeof e.gitBranch === 'string') out.branch = e.gitBranch && e.gitBranch !== 'HEAD' ? e.gitBranch : null;
115
+ if (!out.cwd && typeof e.cwd === 'string') out.cwd = e.cwd;
116
+ if (e.type === 'assistant' && e.message) {
117
+ if (!out.model && e.message.model && e.message.model !== '<synthetic>') out.model = e.message.model;
118
+ // Only its newest turn says what it's doing: a reply after the tool call means it's done with it.
119
+ if (!seen) {
120
+ seen = true;
121
+ const use = (Array.isArray(e.message.content) ? e.message.content : []).filter(x => x?.type === 'tool_use').at(-1);
122
+ if (use) out.now = { text: doing(use.name, use.input), at: Date.parse(e.timestamp) || null };
123
+ }
124
+ }
125
+ }
126
+ return out;
127
+ }
128
+
129
+ // A plan item's status in three words: done, doing, todo. Deleted ones are dropped (null).
130
+ const STATUS = { completed: 'done', done: 'done', in_progress: 'doing', doing: 'doing', pending: 'todo', todo: 'todo' };
131
+ const status = s => (s === 'deleted' ? null : STATUS[s] || 'todo');
132
+ export function planItems(list, textOf) {
133
+ return (Array.isArray(list) ? list : []).map(x => {
134
+ const st = status(x?.status);
135
+ const text = String(textOf(x) || '').trim();
136
+ if (!st || !text) return null;
137
+ return { text: cut(text, PLAN_ITEM_SHOWN), status: st, ...(st === 'doing' && x.activeForm && { active: cut(String(x.activeForm), PLAN_ITEM_SHOWN) }) };
138
+ }).filter(Boolean).slice(0, PLAN_ITEMS);
139
+ }
140
+ const PLAN_ITEMS = 30, PLAN_ITEM_SHOWN = 120;
141
+ // Runs kept per transcript, newest: a day's worth for any agent that waits its turn.
142
+ const RUNS_KEPT = 20;
143
+ // A tool result's text, whatever shape Claude Code stored it in.
144
+ const resultText = c => (typeof c === 'string' ? c : Array.isArray(c) ? c.map(x => (typeof x === 'string' ? x : x?.type === 'text' ? x.text : '')).join('\n') : '');
145
+ // The ids on dibs run's last line: "dibs: tests passed in 2m 4s (waited 3s). #26565", or before 0.0.191 "dibs: #26565 test, waited ...".
146
+ export const runIds = text => [...new Set([...String(text).matchAll(/^dibs: (?:#(\d+) \S+, waited |.*\. #(\d+)\s*$)/gm)].map(m => Number(m[1] || m[2])))];
147
+ const textOf = c => (typeof c === 'string' ? c : Array.isArray(c) ? c.filter(x => x?.type === 'text').map(x => x.text).join('\n') : '');
148
+
149
+ // What the agent says about its own work, oldest to newest through the tail: its plan (the newest
150
+ // list it wrote, in any of Claude Code's and Claude desktop's shapes), its wrap-up, the newest
151
+ // thing it wrote and its newest tool call (in order: whether the words came after the call), the
152
+ // person's newest prompt, and each Bash call that ran dibs with its output's outcome and the
153
+ // first words the agent wrote after it.
154
+ function workOf(entries) {
155
+ const out = { runs: [] };
156
+ const plans = {};
157
+ const tasks = new Map();
158
+ const calls = new Map();
159
+ let order = 0, after = null, taskSeq = 0;
160
+ for (const e of entries) {
161
+ const at = Date.parse(e.timestamp) || null;
162
+ const content = e.message?.content;
163
+ if (e.type === 'user' && !e.isMeta && e.message?.role === 'user') {
164
+ const prompt = textOf(content).replace(/<([\w-]+)>[\s\S]*?<\/\1>/g, '').trim();
165
+ if (prompt && !prompt.startsWith('<') && !prompt.startsWith('Caveat:')) out.prompt = at;
166
+ for (const r of Array.isArray(content) ? content : []) {
167
+ if (r?.type !== 'tool_result') continue;
168
+ const call = calls.get(r.tool_use_id);
169
+ if (!call) continue;
170
+ calls.delete(r.tool_use_id);
171
+ const text = resultText(r.content) || [e.toolUseResult?.stdout, e.toolUseResult?.stderr].filter(Boolean).join('\n');
172
+ if (call.name === 'TaskCreate') { const id = /Task #(\w+)/.exec(text)?.[1]; if (id && tasks.has(call.key)) { tasks.set(id, tasks.get(call.key)); tasks.delete(call.key); } continue; }
173
+ if (call.name !== 'Bash') continue;
174
+ const ids = runIds(text);
175
+ if (!ids.length && !call.dibs) continue;
176
+ const run = { at: call.at, doneAt: at, ids, outcome: outcomeOf(text) };
177
+ out.runs.push(run);
178
+ after = run;
179
+ }
180
+ continue;
181
+ }
182
+ if (e.type !== 'assistant' || !Array.isArray(content)) continue;
183
+ for (const c of content) {
184
+ if (c?.type === 'text' && c.text?.trim()) {
185
+ out.said = { text: c.text.trim(), at, order: ++order };
186
+ if (after && after.reading === undefined) after.reading = firstSentence(c.text);
187
+ }
188
+ if (c?.type !== 'tool_use') continue;
189
+ const i = c.input || {};
190
+ out.tool = { at, order: ++order };
191
+ calls.set(c.id, { name: c.name, at, key: c.id, dibs: c.name === 'Bash' && /(^|[\s;&|(])dibs\s+(run|hold)\b/.test(String(i.command || '')) });
192
+ if (c.name === 'TodoWrite') plans.todo = { from: 'todo', at, items: planItems(i.todos, x => x.content) };
193
+ else if (c.name === 'TaskCreate') { tasks.set(c.id, { text: i.subject || i.description, status: 'pending', activeForm: i.activeForm, n: ++taskSeq }); plans.task = { from: 'task', at }; }
194
+ else if (c.name === 'TaskUpdate') {
195
+ // By the id its result gave, else by the order it was made in (Claude Code numbers them from 1).
196
+ const x = tasks.get(String(i.taskId)) || [...tasks.values()].find(y => String(y.n) === String(i.taskId));
197
+ if (x) { Object.assign(x, i.status && { status: i.status }, i.subject && { text: i.subject }, i.activeForm && { activeForm: i.activeForm }); plans.task = { from: 'task', at }; }
198
+ } else if (c.name === 'mcp__ccd_turn__update_plan') plans.desktop = { from: 'desktop', at, items: planItems(i.items, x => x.content) };
199
+ else if (c.name === 'mcp__ccd_turn__wrap_up') out.wrap = { at, recap: i.recap ? String(i.recap) : null, ask: i.ask ? String(i.ask) : null,
200
+ options: (Array.isArray(i.actions) ? i.actions : []).map(a => String(a?.label || '')).filter(Boolean), blocked: i.blocked === true };
201
+ }
202
+ // Words after a run's result, then another tool call: the words were the agent's reading of it.
203
+ if (after && content.some(c => c?.type === 'tool_use')) after = null;
204
+ }
205
+ if (plans.task) plans.task.items = planItems([...tasks.values()].sort((a, b) => a.n - b.n), x => x.text);
206
+ const newest = Object.values(plans).filter(p => p.items?.length).sort((a, b) => (b.at || 0) - (a.at || 0))[0];
207
+ if (newest) out.plan = newest;
208
+ out.runs = out.runs.slice(-RUNS_KEPT);
209
+ return out;
210
+ }
211
+
212
+ // One transcript, read once per change of its size.
213
+ function read(file, { head = false } = {}) {
214
+ let st;
215
+ try { st = fs.statSync(file); } catch { return null; }
216
+ const hit = kept.get(file);
217
+ if (hit && hit.size === st.size && hit.mtime === st.mtimeMs) return hit.v;
218
+ let v = {};
219
+ try {
220
+ const from = Math.max(0, st.size - TAIL);
221
+ const tail = lines(slice(file, from, st.size - from), { dropFirst: from > 0 });
222
+ v = fromTail(tail);
223
+ v.work = workOf(tail);
224
+ const first = hit?.v?.asked !== undefined ? hit.v.asked : firstPrompt(lines(slice(file, 0, Math.min(HEAD, st.size)), { dropLast: st.size > HEAD }));
225
+ if (head || first) v.asked = first;
226
+ } catch { v = {}; }
227
+ kept.set(file, { size: st.size, mtime: st.mtimeMs, v });
228
+ return v;
229
+ }
230
+
231
+ // { title, project, branch, model, started, asked, now, kind, brief, finished } as far as known.
232
+ // session: Claude Code's session id; agentId: "main" or a subagent's id.
233
+ export function about(session, agentId, { started = null } = {}) {
234
+ const file = transcriptOf(session);
235
+ if (!file) return null;
236
+ const main = read(file) || {};
237
+ const project = base(main.cwd);
238
+ if (!agentId || agentId === 'main') {
239
+ return clean({ title: main.title, project, branch: main.branch, model: modelName(main.model), started, asked: main.asked, now: main.now });
240
+ }
241
+ if (!/^[\w-]{1,128}$/.test(agentId)) return null;
242
+ const dir = path.join(file.replace(/\.jsonl$/, ''), 'subagents');
243
+ let meta = {};
244
+ try { meta = JSON.parse(fs.readFileSync(path.join(dir, `agent-${agentId}.meta.json`), 'utf8')); } catch {}
245
+ const sub = read(path.join(dir, `agent-${agentId}.jsonl`), { head: true }) || {};
246
+ return clean({
247
+ kind: meta.agentType || null, brief: meta.description || null, finished: meta.finished === true || undefined,
248
+ model: modelName(sub.model || meta.model), project: base(sub.cwd) || project, branch: sub.branch ?? main.branch,
249
+ asked: sub.asked, now: sub.now, lead: main.title,
250
+ });
251
+ }
252
+
253
+ // The files an agent changed and read, for dibs who knows (src/route.mjs): the tool calls in its
254
+ // transcript and its subagents'. More of the transcript than about() reads, since an edit from an
255
+ // hour ago still says who knows a file; only dibs who knows asks, never the hook.
256
+ const TOUCH_TAIL = 2 * 1024 * 1024;
257
+ const WRITES = new Set(['Edit', 'MultiEdit', 'Write', 'NotebookEdit']);
258
+
259
+ // { path, at, how: 'edited' | 'read' } for each file, its newest call of each kind, and the folder it works in.
260
+ function touchedIn(file) {
261
+ let st;
262
+ try { st = fs.statSync(file); } catch { return null; }
263
+ const hit = kept.get(`touch:${file}`);
264
+ if (hit && hit.size === st.size && hit.mtime === st.mtimeMs) return hit.v;
265
+ const v = { cwd: null, files: [] };
266
+ try {
267
+ const from = Math.max(0, st.size - TOUCH_TAIL);
268
+ const newest = new Map();
269
+ for (const e of lines(slice(file, from, st.size - from), { dropFirst: from > 0 })) {
270
+ if (typeof e.cwd === 'string') v.cwd = e.cwd;
271
+ if (e.type !== 'assistant' || !Array.isArray(e.message?.content)) continue;
272
+ const at = Date.parse(e.timestamp);
273
+ if (!at) continue;
274
+ for (const use of e.message.content) {
275
+ if (use?.type !== 'tool_use' || (!WRITES.has(use.name) && use.name !== 'Read')) continue;
276
+ const p = use.input?.file_path ?? use.input?.notebook_path;
277
+ if (typeof p !== 'string' || !p) continue;
278
+ const how = WRITES.has(use.name) ? 'edited' : 'read';
279
+ // With / between folders, as dibs writes paths everywhere (src/files.mjs): on Windows a
280
+ // transcript path with backslashes never matched dibs who knows.
281
+ const abs = fwd(path.resolve(typeof e.cwd === 'string' ? e.cwd : '/', p));
282
+ newest.set(`${how}\0${abs}`, { path: abs, at, how });
283
+ }
284
+ }
285
+ v.files = [...newest.values()];
286
+ } catch {}
287
+ kept.set(`touch:${file}`, { size: st.size, mtime: st.mtimeMs, v });
288
+ return v;
289
+ }
290
+
291
+ // What a session's agents touched since then: { cwd, files: [{ path, at, how, agentId? }] }, or
292
+ // null with no transcript. A subagent's calls carry its id.
293
+ export function touched(session, since) {
294
+ const file = transcriptOf(session);
295
+ if (!file) return null;
296
+ const main = touchedIn(file) || { cwd: null, files: [] };
297
+ const out = { cwd: main.cwd, files: main.files.filter(x => x.at >= since) };
298
+ const dir = path.join(file.replace(/\.jsonl$/, ''), 'subagents');
299
+ let names = [];
300
+ try { names = fs.readdirSync(dir).filter(n => /^agent-[\w-]+\.jsonl$/.test(n)); } catch {}
301
+ for (const n of names) {
302
+ const f = path.join(dir, n);
303
+ try { if (fs.statSync(f).mtimeMs < since) continue; } catch { continue; }
304
+ const agentId = n.slice('agent-'.length, -'.jsonl'.length);
305
+ for (const x of touchedIn(f)?.files || []) if (x.at >= since) out.files.push({ ...x, agentId });
306
+ }
307
+ return out;
308
+ }
309
+
310
+ // Where a session last worked and what it was called, for src/carry.mjs when the session is gone:
311
+ // its folder in full, its branch, its title, what it was asked, and when its transcript last
312
+ // changed. null when Claude Code keeps no transcript of it here.
313
+ export function lastSeen(session) {
314
+ const file = transcriptOf(session);
315
+ if (!file) return null;
316
+ let touched = 0;
317
+ try { touched = fs.statSync(file).mtimeMs; } catch { return null; }
318
+ const v = read(file, { head: true }) || {};
319
+ return { cwd: v.cwd || null, branch: v.branch ?? null, title: v.title || null, asked: v.asked || null, touched };
320
+ }
321
+
322
+ // The folder a session works in, from its transcript: which project it's in (src/reviews.mjs).
323
+ export function cwdOf(session) {
324
+ const file = transcriptOf(session);
325
+ return (file && read(file)?.cwd) || null;
326
+ }
327
+
328
+ function clean(o) {
329
+ for (const k of Object.keys(o)) if (o[k] == null || o[k] === '') delete o[k];
330
+ return Object.keys(o).length ? o : null;
331
+ }
332
+
333
+ // What the agent says about its own work, from its transcript (workOf): plan, wrap-up, newest
334
+ // words and tool call, newest prompt, and its dibs runs. null without a transcript.
335
+ export function workFor(session, agentId) {
336
+ const file = transcriptOf(session);
337
+ if (!file) return null;
338
+ if (!agentId || agentId === 'main') return read(file)?.work || null;
339
+ if (!/^[\w-]{1,128}$/.test(agentId)) return null;
340
+ return read(path.join(file.replace(/\.jsonl$/, ''), 'subagents', `agent-${agentId}.jsonl`), { head: true })?.work || null;
341
+ }