@double_geste/agent-standup 1.39.1 → 1.40.0
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/bin/agent-standup.js +1 -0
- package/package.json +1 -1
- package/public/index.html +170 -58
- package/public/locales/da.json +27 -2
- package/public/locales/de.json +27 -2
- package/public/locales/en.json +27 -2
- package/public/locales/es.json +27 -2
- package/public/locales/ja.json +27 -2
- package/public/locales/ko.json +27 -2
- package/public/locales/pt-BR.json +27 -2
- package/public/locales/zh-CN.json +27 -2
- package/public/locales/zh-TW.json +27 -2
- package/server.js +164 -25
- package/vibe.js +1 -1
package/server.js
CHANGED
|
@@ -59,6 +59,7 @@ function transcripts(proj) { // the sessions of a project: { id, file }
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const blocks = (rec) => {
|
|
62
|
+
if (typeof rec.type === 'string' && rec.type.startsWith('api-request')) return []; // a request Claude Code kept (2.1.300 on): its blocks repeat the conversation sent, calls and edits included, which happened once, in their own records
|
|
62
63
|
const c = rec.message && rec.message.content;
|
|
63
64
|
if (typeof c === 'string') return [{ type: 'text', text: c }];
|
|
64
65
|
return Array.isArray(c) ? c : [];
|
|
@@ -90,6 +91,26 @@ function docPaths(text, cd) {
|
|
|
90
91
|
return out;
|
|
91
92
|
}
|
|
92
93
|
const absPath = (f, cwd) => (/^~([\\/]|$)/.test(f) ? path.join(os.homedir(), f.slice(1)) : path.isAbsolute(f) ? path.normalize(f) : cwd ? path.resolve(cwd, f) : f); // cwd: the folder the session was in when it wrote that record
|
|
94
|
+
// A call that drives a browser (Claude in Chrome, written claude-in-chrome by Claude Code and Claude_in_Chrome by the desktop app; the desktop app's own browser): its steps (one, or those of a browser_batch, in order), for the browser window of the shared screen.
|
|
95
|
+
// a: what it did · x, y: where it clicked, in the frame of the page's screenshots · t: what it typed or the key it pressed · u: the address it went to · q: what it looked for · n: its own one-line account of the step
|
|
96
|
+
const BROWSER_MCP = /^mcp__(?:[^_]+__)?(claude-in-chrome|Claude_in_Chrome|Claude_Browser)__/;
|
|
97
|
+
const browserStep = (name, i) => {
|
|
98
|
+
i = i && typeof i === 'object' ? i : {}; const s = { a: String(i.action || name || '').slice(0, 30) }, c = Array.isArray(i.coordinate) ? i.coordinate : null;
|
|
99
|
+
if (c && Number.isFinite(+c[0]) && Number.isFinite(+c[1])) { s.x = +c[0]; s.y = +c[1]; }
|
|
100
|
+
if (typeof i.url === 'string') s.u = clip(i.url, 300); if (typeof i.text === 'string' && /type|key/.test(s.a)) s.t = clip(i.text, 80); if (typeof i.query === 'string') s.q = clip(i.query, 120); if (typeof i.action_summary === 'string') s.n = clip(i.action_summary, 140);
|
|
101
|
+
return s;
|
|
102
|
+
};
|
|
103
|
+
const browserLabel = (name, i) => ({ kind: 'browser', steps: (Array.isArray(i.actions) ? i.actions.slice(-12).map((x) => browserStep(x && x.name, x && x.input)) : [browserStep(name, i)]) });
|
|
104
|
+
// What a browser call answered about the page: its address and title, the frame its clicks are counted in (a screenshot at half scale is still clicked in full-size coordinates),
|
|
105
|
+
// and p: where its last click landed, which the desktop app's browser says when the agent named an element instead of a point ("left_click at (628, 441) [ref_112]"). Its tabs have names ("seed"), not numbers; the desktop app's Chrome writes a tab's address without quotes
|
|
106
|
+
function browserSeen(text) {
|
|
107
|
+
const all = (re) => [...text.matchAll(re)].pop(), web = {}, tab = (text.match(/Executed on tabId: ([\w-]+)/) || [])[1], row = tab && all(new RegExp(`tabId ${tab}: "(.*)" \\("?([^"\\s]*?)"?\\)\\s*$`, 'gm'));
|
|
108
|
+
const u = all(/(?:[Nn]avigated to|URL:) *(\S+)/g), t = all(/^Title: *(.+)$/gm), f = all(/coordinate frame: *(\d+)x(\d+)/g) || all(/captured screenshot \((\d+)x(\d+)/g) || all(/Screenshot size: *(\d+)x(\d+)/g), p = all(/\b(?:left_click|right_click|double_click|triple_click|hover) at \((\d+), *(\d+)\)/g);
|
|
109
|
+
const url = (u && u[1]) || (row && row[2]) || ''; if (/^(https?|file|chrome|about):/i.test(url)) web.u = clip(url, 300);
|
|
110
|
+
const title = (t && t[1]) || (row && row[1] !== row[2] && row[1]) || ''; if (title) web.t = clip(title.trim(), 120);
|
|
111
|
+
if (f && +f[1] > 0 && +f[2] > 0) web.f = [+f[1], +f[2]]; if (p) web.p = [+p[1], +p[2]];
|
|
112
|
+
return Object.keys(web).length ? { web } : {};
|
|
113
|
+
}
|
|
93
114
|
// What each tool call looks like on a screen ("d"), plus its id/timestamp so the result can be matched later.
|
|
94
115
|
const toolLabel = (b, ts) => {
|
|
95
116
|
const i = b.input || {};
|
|
@@ -113,7 +134,8 @@ const toolLabel = (b, ts) => {
|
|
|
113
134
|
case 'Artifact': if ((!i.action || i.action === 'publish') && !i.asset) { out.d = { kind: 'artifact', file: typeof i.file_path === 'string' ? i.file_path : '', title: clip(i.title, 120), note: clip(i.description, 240) }; const sent = i.files ? artSentOf(i) : [], pg = !/\.html?$/i.test(out.d.file) && sent.find((f) => /\.html?$/i.test(f)); if (sent.length > 1) out.d.sent = sent; if (pg) out.d.page = pg; break; } // a page published on claude.ai: the call shows it in a browser window (see artifactPage). Any other use of the tool (a read, a list, an upload) is a call like any other
|
|
114
135
|
if (i.action === 'open') { out.d = { kind: 'artifact', file: '', title: '', note: '', open: 1 }; break; } // a page put on the person's screen: in the line of files when this session did not make it (see artOf)
|
|
115
136
|
// falls through
|
|
116
|
-
default: if (
|
|
137
|
+
default: if (BROWSER_MCP.test(b.name)) { out.d = browserLabel(mcp[mcp.length - 1], i); const s = out.d.steps[out.d.steps.length - 1]; if (s) out.arg = String(s.n || s.u || s.q || s.a).slice(0, 90); break; }
|
|
138
|
+
if (mcp && /(^|_)Claude_Docs$/.test(mcp[1] || '') && mcp[2] === 'batch' && i.container && i.container.create && typeof i.container.create.name === 'string') { out.d = { kind: 'artifact', file: '', title: clip(i.container.create.name, 120), note: '', doc: 1 }; break; } // a doc of the Claude Docs connector being born (its later edits are calls like any other)
|
|
117
139
|
out.d = mcp ? { kind: 'text', what: 'mcp', v: (mcp[1] || '') + ' · ' + (mcp.slice(2).join('__') || ''), text: clip(JSON.stringify(i), 400) } : { kind: 'text', text: clip(JSON.stringify(i), 300) };
|
|
118
140
|
}
|
|
119
141
|
return out;
|
|
@@ -366,6 +388,12 @@ const feedSince = (entry, after) => { const ev = entry.tl.events, sq = entry.sq,
|
|
|
366
388
|
// ---- Board: one cheap row per recent session (state from the tail of its transcript), so many parallel sessions can be watched at once.
|
|
367
389
|
const readTail = (file, bytes) => { const fd = fs.openSync(file, 'r'); try { const sz = fs.fstatSync(fd).size, n = Math.min(bytes, sz), buf = Buffer.alloc(n); fs.readSync(fd, buf, 0, n, sz - n); return { text: buf.toString('utf8'), cut: sz > bytes }; } finally { fs.closeSync(fd); } };
|
|
368
390
|
const readHead = (file, bytes) => { const fd = fs.openSync(file, 'r'); try { const n = Math.min(bytes, fs.fstatSync(fd).size), buf = Buffer.alloc(n); fs.readSync(fd, buf, 0, n, 0); return buf.toString('utf8'); } finally { fs.closeSync(fd); } };
|
|
391
|
+
// Since Claude Code 2.1.300 a transcript also keeps each request it sent (system prompt, tools, parameters) and a snapshot of the prompt: lines of 100 KB and more, about 40% of a new file.
|
|
392
|
+
// A card reads the last 192 KB of the other records: further back when those fill it (3 MB at most). Right after an order, the order itself was out of the 192 KB 1 time in 20.
|
|
393
|
+
const BULKY = /^\{"type":"api-request|"attachment":\{"type":"prompt_snapshot"/, TAIL = 192 * 1024;
|
|
394
|
+
function boardTail(file) {
|
|
395
|
+
for (let n = TAIL; ; n *= 4) { const { text, cut } = readTail(file, n), lines = text.split('\n'); if (cut) lines.shift(); let rest = 0; for (const l of lines) if (!BULKY.test(l.slice(0, 200))) rest += l.length; if (!cut || rest >= TAIL || n >= 3 * 1024 * 1024) return { lines, cut }; }
|
|
396
|
+
}
|
|
369
397
|
const APPROVAL = /^(Edit|Write|MultiEdit|NotebookEdit)/, ASKS = /^(AskUserQuestion|ExitPlanMode)/, SUBTOOL = /^(Task|Agent)$/;
|
|
370
398
|
// A turn that ended without doing what was asked ("I couldn't verify how old the posts were, so 0 drafts"): to the eye, the same "your turn" as one that did. It says so in its first sentence;
|
|
371
399
|
// later on, "I couldn't" is mostly a caveat on work that was done ("Done. I couldn't test on Windows"), and so is a first sentence that says what worked before a "but". On 1,676 real ends of turn
|
|
@@ -405,9 +433,9 @@ const menuOf = (b) => { // what a menu waiting for you shows, from the call it
|
|
|
405
433
|
// It is the only sign of a Bash approval: in the transcript, a command waiting for your go-ahead looks just like one that runs. A file whose process has ended is left out.
|
|
406
434
|
const CC_SESSIONS = process.env.AGENT_STANDUP_CC_SESSIONS || path.join(process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude'), 'sessions');
|
|
407
435
|
const alive = (pid) => { try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; } };
|
|
408
|
-
function liveStatus() { // session id → { status, since }
|
|
436
|
+
function liveStatus() { // session id → { status, since, pid, ep (where it runs: claude-vscode, cli, claude-desktop, sdk-cli…) }
|
|
409
437
|
const out = new Map(); let names = []; try { names = fs.readdirSync(CC_SESSIONS); } catch { return out; }
|
|
410
|
-
for (const n of names) { if (!/^\d+\.json$/.test(n)) continue; try { const s = JSON.parse(fs.readFileSync(path.join(CC_SESSIONS, n), 'utf8')); if (s && typeof s.sessionId === 'string' && /^(busy|idle|waiting)$/.test(s.status) && Number.isInteger(s.pid) && s.pid > 0 && alive(s.pid)) out.set(s.sessionId, { status: s.status
|
|
438
|
+
for (const n of names) { if (!/^\d+\.json$/.test(n)) continue; try { const s = JSON.parse(fs.readFileSync(path.join(CC_SESSIONS, n), 'utf8')); if (s && typeof s.sessionId === 'string' && /^(busy|idle|waiting)$/.test(s.status) && Number.isInteger(s.pid) && s.pid > 0 && alive(s.pid)) out.set(s.sessionId, { status: s.status !== 'waiting' ? s.status : s.waitingFor === 'dialog open' ? 'idle' : s.entrypoint === 'sdk-cli' ? 'busy' : s.status, since: Number(s.statusUpdatedAt) || 0, pid: s.pid, ep: String(s.entrypoint || '') }); } catch {} } /* a dialog you opened yourself (/model, /config, /mcp…) also says waiting: it is not a question for you. Nor is a menu of a session started with claude -p (entrypoint sdk-cli): its question goes to the program that started it. An Agent SDK host (sdk-ts, sdk-py: Zed, a home-made app) may show its menus to a person, so those are kept */
|
|
411
439
|
return out;
|
|
412
440
|
}
|
|
413
441
|
// When the person last did something in a session: an order, a slash command, a "!" command, an order typed while the lead was working. It is what moves the live call (see currentSession).
|
|
@@ -426,22 +454,77 @@ function typedBefore(file) { // the first look at a session whose last order i
|
|
|
426
454
|
for (let i = lines.length - 1; i >= (cut ? 1 : 0); i--) { if (!lines[i].includes('"type":"user"') && !lines[i].includes('"queued_command"')) continue; try { const a = typedAt(JSON.parse(lines[i])); if (a) return a; } catch {} }
|
|
427
455
|
return 0;
|
|
428
456
|
}
|
|
457
|
+
// Answer in Claude Code: a click on what needs you goes where it can be answered. The session's process (its status file) leads to the editor window that runs it: each Agent Standup
|
|
458
|
+
// extension notes its window in <settings folder>/editors/<extension host pid>.json (its link scheme, its window number), and Claude Code's extension opens
|
|
459
|
+
// <scheme>://anthropic.claude-code/open?session=<id>&windowId=<n> in that window, which brings up the session's tab. Without that note: the editor among the session's parent processes (macOS),
|
|
460
|
+
// in whichever window was last used. A session in a terminal or in the Claude app (macOS): that app is brought to the front. Nothing leaves the computer: a local link or app is opened.
|
|
461
|
+
const editorsDir = () => path.join(path.dirname(PREFS), 'editors'), EDITOR_APPS = [[/Visual Studio Code - Insiders\.app|Code - Insiders\.app/, 'vscode-insiders'], [/Visual Studio Code\.app|\/Code\.app\//, 'vscode'], [/\/Cursor\.app\//, 'cursor'], [/\/Windsurf\.app\//, 'windsurf'], [/\/VSCodium\.app\//, 'vscodium']];
|
|
462
|
+
function noteEditor(info) { // the extension, for its window: { scheme, windowId } (forgetEditor when the window closes)
|
|
463
|
+
try {
|
|
464
|
+
const d = editorsDir(); fs.mkdirSync(d, { recursive: true }); fs.writeFileSync(path.join(d, process.pid + '.json'), JSON.stringify({ pid: process.pid, ppid: process.ppid, scheme: String((info && info.scheme) || ''), windowId: String((info && info.windowId) || '') })); // ppid: a note left by a crash is not taken for another process that gets its number
|
|
465
|
+
for (const n of fs.readdirSync(d)) { const p = +n.replace(/\.json$/, ''); if (/^\d+\.json$/.test(n) && !alive(p)) try { fs.unlinkSync(path.join(d, n)); } catch {} } // the notes of windows that closed without saying so
|
|
466
|
+
} catch (e) { logError('editor note', e); }
|
|
467
|
+
}
|
|
468
|
+
function forgetEditor() { try { fs.unlinkSync(path.join(editorsDir(), process.pid + '.json')); } catch {} }
|
|
469
|
+
function procTree() { // pid → { ppid, cmd }: one look at every process (macOS and Linux; nothing on Windows)
|
|
470
|
+
const m = new Map(); if (process.platform === 'win32') return m;
|
|
471
|
+
try { for (const l of execFileSync('ps', ['-axo', 'pid=,ppid=,comm='], { encoding: 'utf8', timeout: 3000, maxBuffer: 16 << 20 }).split('\n')) { const x = /^\s*(\d+)\s+(\d+)\s+(.*)$/.exec(l); if (x) m.set(+x[1], { ppid: +x[2], cmd: x[3] }); } } catch {}
|
|
472
|
+
return m;
|
|
473
|
+
}
|
|
474
|
+
function openLocal(args) { // a link or an app, opened as a click on it would be (AGENT_STANDUP_ANSWER=dry: said, not opened, for the tests)
|
|
475
|
+
if (process.env.AGENT_STANDUP_ANSWER === 'dry') return;
|
|
476
|
+
const [cmd, a] = process.platform === 'darwin' ? ['open', args] : process.platform === 'win32' ? ['rundll32', ['url.dll,FileProtocolHandler', args[args.length - 1]]] : ['xdg-open', [args[args.length - 1]]];
|
|
477
|
+
try { spawn(cmd, a, { stdio: 'ignore', detached: true, windowsHide: true }).on('error', () => {}).unref(); } catch {}
|
|
478
|
+
}
|
|
479
|
+
function answerIn(id, opts = {}) { // { how: 'editor' | 'app' | '', app, link }: where the session that waits can be answered, opened. opts.here(id): the extension, for a session of its own window (no link, and no prompt from the editor)
|
|
480
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(String(id))) return { how: '' };
|
|
481
|
+
const w = liveStatus().get(String(id)); if (!w || !w.pid || !/^(claude-vscode|cli|claude-desktop)$/.test(w.ep)) return { how: '' }; // a session a program runs (sdk-…) has no one to answer it there
|
|
482
|
+
const tree = procTree(), up = []; for (let p = w.pid, i = 0; p > 1 && i < 20 && tree.has(p); i++) { up.push(p); p = tree.get(p).ppid; }
|
|
483
|
+
const link = (scheme, win) => `${scheme}://anthropic.claude-code/open?session=${String(id).toLowerCase()}${win ? '&windowId=' + win : ''}`;
|
|
484
|
+
if (w.ep === 'claude-vscode') {
|
|
485
|
+
for (const p of up) { // the window that runs it: its extension host is one of its parents
|
|
486
|
+
let e = null; try { e = JSON.parse(fs.readFileSync(path.join(editorsDir(), p + '.json'), 'utf8')); } catch {} if (!e || e.ppid !== tree.get(p).ppid) continue;
|
|
487
|
+
if (e.pid === process.pid && typeof opts.here === 'function') { try { opts.here(String(id).toLowerCase()); } catch {} return { how: 'editor', here: 1 }; }
|
|
488
|
+
if (/^[a-z][a-z0-9+.-]{1,30}$/.test(e.scheme) && /^\d{1,9}$/.test(String(e.windowId))) { const l = link(e.scheme, e.windowId); openLocal([l]); return { how: 'editor', link: l }; }
|
|
489
|
+
}
|
|
490
|
+
for (const p of up) for (const [re, scheme] of EDITOR_APPS) if (re.test(tree.get(p).cmd)) { // no note: the link goes to the editor's last used window, so only when it has one (one extension host); else the editor comes to the front, and its tab is yours to pick
|
|
491
|
+
const host = tree.get(p).cmd, hosts = [...tree.values()].filter((x) => x.cmd === host && (tree.get(x.ppid) || {}).cmd !== host).length; // an extension host per window, started by the app itself (language servers and the like are its children)
|
|
492
|
+
if (hosts === 1 && /Helper \(Plugin\)/.test(host)) { const l = link(scheme, ''); openLocal([l]); return { how: 'editor', link: l }; }
|
|
493
|
+
break;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (process.platform === 'darwin' && up.some((p) => /\/iTermServer/.test(tree.get(p).cmd))) { openLocal(['-b', 'com.googlecode.iterm2']); return { how: 'app', app: 'iTerm' }; } // iTerm2 runs its shells under a server of its own, not under the app
|
|
497
|
+
if (process.platform === 'darwin') for (const p of up.slice().reverse()) { const m = /^(\/.+?\.app)\//.exec(tree.get(p).cmd); if (m) { openLocal(['-a', m[1]]); return { how: 'app', app: path.basename(m[1], '.app') }; } } // the outermost app: Terminal, iTerm, Claude…
|
|
498
|
+
return { how: '' };
|
|
499
|
+
}
|
|
500
|
+
// Does this session's Claude Code write a status in ~/.claude/sessions (the terminal since 2.1.221; the VS Code panel, the desktop app's Code tab and the Agent SDK since 2.1.269; Cowork keeps its own elsewhere)?
|
|
501
|
+
// Where it does, no status means its process has ended: a question left open there was given up, not asked.
|
|
502
|
+
const verAtLeast = (v, min) => { const x = String(v || '').split('.').map((n) => parseInt(n, 10) || 0); for (let i = 0; i < 3; i++) if ((x[i] || 0) !== min[i]) return (x[i] || 0) > min[i]; return true; };
|
|
503
|
+
const statusWritten = (proj, p) => proj !== COWORK && !!p.ver && p.ep !== 'local-agent' && verAtLeast(p.ver, p.ep === 'cli' ? [2, 1, 221] : [2, 1, 269]);
|
|
429
504
|
function parseTail(file, st) {
|
|
430
505
|
const sig = st.mtimeMs + ':' + st.size, hit = boardCache.get(file); if (hit && hit.sig === sig) return hit;
|
|
431
|
-
const {
|
|
432
|
-
const pend = new Map(); let lastType = null, lastTool = false, lastStop = null, stops = false, esc = false, lastTs = 0, custom = (hit && hit.custom) || null, ai = (hit && hit.ai) || null, first = hit ? hit.first : undefined, pr = (hit && hit.pr) || null, asked = (hit && hit.asked) || 0, plan = (hit && hit.plan) || null, say = '', err = ''; // say: the first text since the last call or message of yours, the start of what closes the turn; err: an error that closed it
|
|
506
|
+
const { lines, cut } = boardTail(file);
|
|
507
|
+
const pend = new Map(), bg = new Map(); let ver = '', ep = '', idle = false, lastType = null, lastTool = false, lastStop = null, stops = false, esc = false, lastTs = 0, custom = (hit && hit.custom) || null, ai = (hit && hit.ai) || null, first = hit ? hit.first : undefined, pr = (hit && hit.pr) || null, asked = (hit && hit.asked) || 0, plan = (hit && hit.plan) || null, say = '', err = ''; // say: the first text since the last call or message of yours, the start of what closes the turn; err: an error that closed it
|
|
433
508
|
for (const l of lines) try { // one odd record costs that record, not the whole card
|
|
434
509
|
if (!l) continue; let r; try { r = JSON.parse(l); } catch { continue; }
|
|
435
|
-
const a = typedAt(r); if (a > asked) asked = a;
|
|
510
|
+
const a = typedAt(r); if (a > asked) asked = a; if (a && r.type === 'user') pend.clear(); if (typeof r.version === 'string') ver = r.version; if (typeof r.entrypoint === 'string') ep = r.entrypoint; /* which Claude Code, and where: does it write a status that says a menu is open (statusWritten) */ /* an order of yours: a call still without its answer was given up (a menu you passed over by typing, a session closed mid-call), it waits on nothing any more */
|
|
436
511
|
if (r.type === 'custom-title' && typeof r.customTitle === 'string') custom = r.customTitle; else if (r.type === 'ai-title' && typeof r.aiTitle === 'string') ai = r.aiTitle; // a session is renamed, or named, long after its row was first shown: the latest one read wins
|
|
437
512
|
if (r.type === 'pr-link' && PR_URL.test(r.prUrl)) pr = { n: +r.prUrl.slice(r.prUrl.lastIndexOf('/') + 1), url: r.prUrl }; // the pull request Claude Code noted for the session: the latest one, shown on its card
|
|
438
513
|
const t = Date.parse(r.timestamp) || 0, bl = blocks(r);
|
|
439
|
-
if (r.type === '
|
|
514
|
+
if (r.type === 'system' && r.subtype === 'compact_boundary') idle = /^idle/.test(String((r.compactMetadata && r.compactMetadata.trigger) || '')); // Claude Code 2.1.299 compacts a large session left idle for about 54 minutes: nobody moved there
|
|
515
|
+
if (r.isCompactSummary) continue; // the summary of a compaction is not a message: the turn stands as it was
|
|
516
|
+
if (r.type === 'assistant' || r.type === 'user') { idle = false; lastType = r.type; lastTool = bl.some((b) => b.type === 'tool_use'); lastStop = (r.type === 'assistant' && r.message && r.message.stop_reason) || null; if (lastStop) stops = true; if (t) lastTs = t;
|
|
440
517
|
esc = r.type === 'user' && bl.some((b) => b.type === 'text' && /^\s*\[Request interrupted/i.test(b.text || '')); if (esc) pend.clear(); } // Esc: the turn stops there, and no call is waited for any more
|
|
441
518
|
if (r.type === 'user' || (r.type === 'assistant' && lastTool)) { say = ''; err = ''; }
|
|
442
519
|
else if (r.type === 'assistant' && !r.isSidechain) { const tx = bl.filter((b) => b.type === 'text' && typeof b.text === 'string').map((b) => b.text).join('\n').trim(), m = r.message || {}; err = (r.isApiErrorMessage || m.model === '<synthetic>') && tx && !/^No response requested/i.test(tx) ? tx : ''; if (tx && !say) say = tx; }
|
|
443
520
|
for (const b of bl) if (b.type === 'tool_use' && /^(Write|Edit|MultiEdit)$/.test(b.name) && b.input && planFile(String(b.input.file_path || ''))) plan = { file: String(b.input.file_path), ts: t }; // the plan, written in its own file before it is shown for approval
|
|
444
521
|
for (const b of bl) { if (b.type === 'tool_use') pend.set(b.id, { id: String(b.id || ''), name: b.name, ts: t, q: askOf(b), c: callOf(b), m: menuOf(b) }); else if (b.type === 'tool_result') pend.delete(b.tool_use_id); }
|
|
522
|
+
if (r.type === 'user' && !r.isSidechain) for (const b of bl) { // the sub-agents the lead launched in the background, until the news that each one ended (Claude Code 2.1.302 runs them all in the background in VS Code and the desktop app)
|
|
523
|
+
if (b.type === 'tool_result') { const m = /^\s*Async agent launched[\s\S]*?agentId: ?([\w-]+)/i.exec(resultText(b.content)); if (m) bg.set(m[1], t); }
|
|
524
|
+
else if (b.type === 'text') for (const m of String(b.text || '').matchAll(/<task-notification>[\s\S]*?<task-id>([\w-]+)<\/task-id>/g)) bg.delete(m[1]);
|
|
525
|
+
}
|
|
526
|
+
const queued = r.isSidechain ? '' : r.type === 'attachment' && r.attachment && r.attachment.type === 'queued_command' && typeof r.attachment.prompt === 'string' ? r.attachment.prompt : r.type === 'queue-operation' && r.operation === 'enqueue' && typeof r.content === 'string' ? r.content : '';
|
|
527
|
+
for (const m of queued.matchAll(/<task-notification>[\s\S]*?<task-id>([\w-]+)<\/task-id>/g)) bg.delete(m[1]); // before Claude Code 2.1.302 the news that a background agent ended is often only queued (and handed over inside the next order): it has ended all the same
|
|
445
528
|
} catch {}
|
|
446
529
|
if (!hit && !custom) { // first look at this file: a little further back than the lines read above, and without needing whole lines
|
|
447
530
|
const big = readTail(file, 256 * 1024).text, un = (m) => { try { return m ? JSON.parse('"' + m[1] + '"') : null; } catch { return null; } };
|
|
@@ -450,7 +533,7 @@ function parseTail(file, st) {
|
|
|
450
533
|
if (!custom && !ai && first == null) first = firstPrompt(file) || (st.size > 64 * 1024 ? '' : null); // '' = looked for and not there; a file that has just been created is looked at again
|
|
451
534
|
if (!hit && !asked && cut) asked = typedBefore(file);
|
|
452
535
|
const out = { sig, title: custom || ai || first || null, custom, ai, first, pr, lastType, lastTool, lastStop, stops, esc, lastTs, pending: [...pend.values()], ...(lastType === 'assistant' && (err || gaveUp(say)) ? { gave: (err || gaveUp(say)).replace(/\s+/g, ' ').slice(0, 240) } : {}) }; // a title the person typed wins over the generated one, and both over the first prompt
|
|
453
|
-
out.asked = asked; out.plan = plan; boardCache.set(file, out); if (boardCache.size > 3 * ROWS_MAX) boardCache.delete(boardCache.keys().next().value); return out; // more than the list can hold: a full list never pushes its own rows out, which read every row again at each scan
|
|
536
|
+
out.ver = ver || (hit && hit.ver) || ''; out.ep = ep || (hit && hit.ep) || ''; out.asked = asked; out.plan = plan; out.bg = [...bg].filter(([, ts]) => ts >= asked); if (idle && lastTs) out.quiet = lastTs; boardCache.set(file, out); if (boardCache.size > 3 * ROWS_MAX) boardCache.delete(boardCache.keys().next().value); return out; // more than the list can hold: a full list never pushes its own rows out, which read every row again at each scan
|
|
454
537
|
}
|
|
455
538
|
function firstPrompt(file) { // the first thing the person typed, read record by record: a pattern over the raw text ran from a user record into the assistant's first answer and took that as the title
|
|
456
539
|
const ONE = (t) => t.replace(/\s+/g, ' ').trim().slice(0, 90);
|
|
@@ -475,6 +558,14 @@ function capRows(list, most, folderOf) { // list: newest first
|
|
|
475
558
|
for (const r of real) { if (keep.size >= ROWS_MAX) break; const k = folderOf(r), n = per.get(k) || 0; if (n < PER_FOLDER) { keep.add(r); per.set(k, n + 1); } }
|
|
476
559
|
return real.filter((r) => keep.has(r)).concat(list.filter((r) => tmpKey(folderOf(r))).slice(0, TMP_ROWS));
|
|
477
560
|
}
|
|
561
|
+
function bgAtWork(proj, id, bg, now) { // bg: [agent id, launched at]. Still at work: not marked finished in its meta file (Claude Code 2.1.302 on) and written to, or launched, in the last 30 minutes
|
|
562
|
+
for (const [aid, ts] of bg || []) {
|
|
563
|
+
if (!/^[\w-]+$/.test(aid)) continue; const f = path.join(projDir(proj, id), id, 'subagents', 'agent-' + aid);
|
|
564
|
+
let done = false; try { done = JSON.parse(fs.readFileSync(f + '.meta.json', 'utf8')).finished === true; } catch {}
|
|
565
|
+
if (!done && now - Math.max(mtimeOf(f + '.jsonl'), ts || 0) < 30 * 60e3) return true;
|
|
566
|
+
}
|
|
567
|
+
return false;
|
|
568
|
+
}
|
|
478
569
|
function boardRows0() {
|
|
479
570
|
const now = Date.now(), rows = [], live = liveStatus();
|
|
480
571
|
for (const m of SOURCES) for (const r of guard(() => m.sessions(), [])) if (now - r.mtime < 12 * 3600e3) rows.push({ proj: m.PROJ, id: r.id, st: { mtimeMs: r.mtime, size: r.size }, cx: r, src: m });
|
|
@@ -486,22 +577,23 @@ function boardRows0() {
|
|
|
486
577
|
return capRows(rows.filter((r) => !r.cx && r.proj !== COWORK), 40, own).concat(...SOURCES.map((m) => capRows(rows.filter((r) => r.src === m), 20, folder)), rows.filter((r) => r.proj === COWORK).slice(0, 20)).sort((a, b) => b.st.mtimeMs - a.st.mtimeMs).map(({ proj, id, st, cx, src }) => {
|
|
487
578
|
if (cx) { const r = guard(() => src.boardRow(cx, now), null); if (r && tmpKey(r.dir)) r.tmp = 1; return r; } // tmp: started in the temporary folder (see tmpKey)
|
|
488
579
|
const file = path.join(projDir(proj, id), id + '.jsonl'); let p; try { p = parseTail(file, st); } catch { p = { pending: [] }; }
|
|
489
|
-
const
|
|
580
|
+
const moved = p.quiet || st.mtimeMs, age = now - moved, pend = p.pending || [], w = live.get(id), lp = (w && w.status === 'waiting' && pend.find((c) => !SUBTOOL.test(c.name))) || pend[pend.length - 1]; let state = 'idle', tool = '', ageMs = age, since = 0, open = null, maybe = 0, asks = 0; // lp: with a menu open and several calls waiting, Claude Code asks about the first of them
|
|
490
581
|
if (w && w.status === 'waiting' && lp) { state = 'blocked'; tool = lp.name; since = w.since || lp.ts || st.mtimeMs; ageMs = now - since; } // a menu is open in the session and a call waits on it: it needs you now, however long ago it was written
|
|
491
582
|
else if (w && w.status === 'waiting') { state = 'blocked'; since = w.since || st.mtimeMs; ageMs = now - since; const pt = p.plan && p.plan.ts > (p.asked || 0) ? planText(p.plan.file) : ''; open = { id: 'w' + since, tool: pt ? 'ExitPlanMode' : '', ...(pt ? { kind: 'plan', text: pt } : { kind: 'menu' }), sure: 1 }; } // a menu is open and the transcript has no call waiting on it: the plan to approve (Claude Code writes that call only once it is answered, the plan itself is in its file, written this turn), or a menu it does not record
|
|
492
583
|
else if (age < 30 * 60e3) {
|
|
493
584
|
if (lp) { ageMs = now - (lp.ts || st.mtimeMs); tool = lp.name;
|
|
494
|
-
state = SUBTOOL.test(lp.name) ? 'waiting' : (ASKS.test(lp.name) && ageMs > 4000) || (APPROVAL.test(lp.name) && ageMs > 15000)
|
|
585
|
+
state = SUBTOOL.test(lp.name) ? 'waiting' : 'working'; if (!w && ASKS.test(lp.name) && ageMs > 4000 && !statusWritten(proj, p)) { state = 'blocked'; asks = 1; since = lp.ts || st.mtimeMs; } else if (!w && ((APPROVAL.test(lp.name) && ageMs > 15000) || (ASKS.test(lp.name) && ageMs > 4000))) { maybe = 1; since = lp.ts || st.mtimeMs; } } // asks: no status (Cowork, Claude Code before 2.1.269), but a question or a plan open in the transcript is one: it needs you // maybe: only a guess from how long a call has waited, for a session whose status Claude Code does not write (Cowork, before 2.1.2xx): shown on its tile, never as "needs you" (no visitor, no red, no notification). A status that says busy or idle is believed: the panel in VS Code also says "waiting" while it asks
|
|
495
586
|
else if (p.esc) state = 'turn'; // you stopped it (Esc): it is your turn there, not "working" for the next ten minutes
|
|
496
|
-
else if (p.lastType === 'assistant' && !p.lastTool && p.lastStop !== 'tool_use' && !(p.lastStop == null && p.stops && age < 45000)) state = 'turn'; // a line whose message goes on with a tool call is not the end of the turn: the call is written after it, a long one many seconds after.
|
|
587
|
+
else if (p.lastType === 'assistant' && !p.lastTool && p.lastStop !== 'tool_use' && !(p.lastStop == null && p.stops && age < 45000)) state = !p.gave && bgAtWork(proj, id, p.bg, now) ? 'waiting' : 'turn'; // a line whose message goes on with a tool call is not the end of the turn: the call is written after it, a long one many seconds after.
|
|
588
|
+
// A lead that ends its turn on "the agents are running, I'll wait" is not waiting for you: it goes on when they report (a sub-agent launched in the background, and not since an order of yours)
|
|
497
589
|
// Claude Code up to 2.1.87 writes that line without saying why it stopped: in a transcript that does say it elsewhere, such a line is given 45 s for its call to come (1 in 100 takes longer than 25 s)
|
|
498
590
|
else state = age < 10 * 60e3 ? 'working' : 'idle';
|
|
499
591
|
if (state === 'turn') since = p.lastTs || st.mtimeMs;
|
|
500
592
|
}
|
|
501
593
|
let subActive = 0, subTotal = 0;
|
|
502
594
|
for (const x of subFiles(proj, id)) { subTotal++; if (now - mtimeOf(x.file) < 90e3) subActive++; }
|
|
503
|
-
const ran = since && p.asked && p.asked < since ? since - p.asked : 0, ask = state === 'blocked' && lp ? lp.q || lp.c : ''; // since: when it started to wait on you; ran: how long it worked, from your last order to then
|
|
504
|
-
return { proj, id, title: coworkTitle(proj, id) || p.title || id, mtime:
|
|
595
|
+
const ran = since && p.asked && p.asked < since ? since - p.asked : 0, ask = (state === 'blocked' || maybe) && lp ? lp.q || lp.c : ''; // since: when it started to wait on you; ran: how long it worked, from your last order to then
|
|
596
|
+
return { proj, id, title: coworkTitle(proj, id) || p.title || id, mtime: moved, state, tool, ageMs, subActive, subTotal, asked: p.asked || 0, ...(since ? { since } : {}), ...(ran ? { ran } : {}), ...(p.pr ? { pr: p.pr } : {}), ...(ask ? { ask } : {}), ...(state === 'blocked' && ((w && w.status === 'waiting') || asks) ? { sure: 1 } : {}), ...(maybe ? { maybe } : {}), ...(w ? { known: 1 } : {}), ...(open ? { menu: open } : (state === 'blocked' || maybe) && lp && lp.m && !SUBTOOL.test(lp.name) ? { menu: { id: lp.id, tool: lp.name, ...lp.m, ...((w && w.status === 'waiting') || asks ? { sure: 1 } : {}) } } : {}), ...(state === 'turn' && p.gave ? { gave: p.gave } : {}), ...(p.esc ? { cut: 1 } : {}), ...(tmpKey(proj) ? { tmp: 1 } : {}) }; // cut: stopped by you, which is no news to tell you
|
|
505
597
|
}).filter(Boolean);
|
|
506
598
|
}
|
|
507
599
|
// Settings live in a file, not only in the page's localStorage: the port changes between VS Code windows and reloads, and localStorage is per origin (port included).
|
|
@@ -564,7 +656,7 @@ const RATE_STORES = /^https:\/\/(marketplace\.visualstudio\.com|open-vsx\.org)\/
|
|
|
564
656
|
function appKind() {
|
|
565
657
|
const h = String(process.env.AGENT_STANDUP_HOST || ''), rate = String(process.env.AGENT_STANDUP_RATE || '');
|
|
566
658
|
const kind = h === 'desktop app' ? 'desktop' : h === 'command line' ? 'cli' : h === 'claude code plugin' ? 'plugin' : h ? 'editor' : '';
|
|
567
|
-
return { kind, rate: kind === 'editor' && RATE_STORES.test(rate) ? rate : GITHUB_REPO, track: !noTrack() }; // track: false when DO_NOT_TRACK is set, and the page does not ask about usage
|
|
659
|
+
return { kind, rate: kind === 'editor' && RATE_STORES.test(rate) ? rate : GITHUB_REPO, track: !noTrack(), updates: !noUpdate() }; // track: false when DO_NOT_TRACK is set, and the page does not ask about usage
|
|
568
660
|
}
|
|
569
661
|
// Usage, counted only for those who said yes, in the desktop app, the command line and the Claude Code plugin (the editor counts itself: extension.js, pingWeek). The page asks once
|
|
570
662
|
// (prefs.shareUsage, which this server reads again in the settings file before it sends anything); when the call is opened it asks this server, which sends at most one empty request a week (weeks from Monday, UTC) for the 1-pixel file of its kind in the "stats"
|
|
@@ -588,6 +680,46 @@ function usageWeek(now = new Date()) {
|
|
|
588
680
|
} catch (e) { logError('usage', e); }
|
|
589
681
|
return { sent: true, week };
|
|
590
682
|
}
|
|
683
|
+
// A newer version, told in the desktop app, the command line and the Claude Code plugin (the editor updates itself from its store). At most once a day, this server asks the npm registry which
|
|
684
|
+
// version is the latest: one request for the package's small manifest, with nothing about you or your sessions in it (the registry sees your IP address, as when npx starts the app). The answer is
|
|
685
|
+
// kept beside the settings (update-check.json), so every server and page share one request a day; after a failure it tries again an hour later. The page shows it once per version, by the menu,
|
|
686
|
+
// with the step that updates this app (index.html, updTip); the command line prints it when it starts. Off until the person says yes: the page asks once (prefs.updateNotice, read here
|
|
687
|
+
// from the settings file, as for usage; ⚙ › All settings turns it on or off). Never with DO_NOT_TRACK or NO_UPDATE_NOTIFIER set. AGENT_STANDUP_UPDATE_URL: where the tests answer.
|
|
688
|
+
const UPDATE_KINDS = ['desktop', 'cli', 'plugin'], UPDATE_FILE = path.join(path.dirname(PREFS), 'update-check.json'), VER_RE = /^\d{1,4}\.\d{1,5}\.\d{1,6}$/;
|
|
689
|
+
const noUpdate = () => noTrack() || /^(1|true|yes)$/i.test(String(process.env.NO_UPDATE_NOTIFIER || '').trim());
|
|
690
|
+
const verParts = (v) => String(v || '').split('-')[0].split('.').map((n) => parseInt(n, 10) || 0);
|
|
691
|
+
const newerThan = (a, b) => { const x = verParts(a), y = verParts(b); for (let i = 0; i < 3; i++) if ((x[i] || 0) !== (y[i] || 0)) return (x[i] || 0) > (y[i] || 0); return false; };
|
|
692
|
+
function updateHow(kind) { // the step that updates this app: the desktop app is downloaded again, the plugin is updated by Claude Code, the command line by npx (it runs from npx's cache, a folder named _npx) or npm
|
|
693
|
+
if (kind === 'desktop') return { how: 'download', url: GITHUB_REPO + '/releases/latest' };
|
|
694
|
+
if (kind === 'plugin') return { how: 'plugin', cmd: 'claude plugin marketplace update double-geste && claude plugin update agent-standup@double-geste' };
|
|
695
|
+
return __dirname.split(path.sep).includes('_npx') ? { how: 'npx', cmd: 'npx @double_geste/agent-standup@latest --open' } : { how: 'npm', cmd: 'npm i -g @double_geste/agent-standup@latest' };
|
|
696
|
+
}
|
|
697
|
+
function latestFromNpm() { // the version npm calls latest, or '' (offline, an error, anything unexpected)
|
|
698
|
+
return new Promise((done) => {
|
|
699
|
+
try {
|
|
700
|
+
const u = new URL(process.env.AGENT_STANDUP_UPDATE_URL || 'https://registry.npmjs.org/@double_geste/agent-standup/latest');
|
|
701
|
+
const r = require(u.protocol === 'http:' ? 'http' : 'https').get(u, { headers: { 'user-agent': 'agent-standup', accept: 'application/json' }, timeout: 5000 }, (m) => {
|
|
702
|
+
let b = ''; m.setEncoding('utf8'); m.on('data', (d) => { b += d; if (b.length > 65536) m.destroy(); }); m.on('error', () => done('')); m.on('close', () => done(''));
|
|
703
|
+
m.on('end', () => { try { const v = m.statusCode === 200 ? String(JSON.parse(b).version || '') : ''; done(VER_RE.test(v) ? v : ''); } catch { done(''); } });
|
|
704
|
+
});
|
|
705
|
+
r.on('error', () => done('')); r.on('timeout', () => r.destroy());
|
|
706
|
+
} catch (e) { logError('update', e); done(''); }
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
let updateAsking = null;
|
|
710
|
+
function updateInfo() { // what /api/update and the command line tell: { on, current, latest, newer, notes, how, cmd or url }
|
|
711
|
+
const kind = appKind().kind, off = { on: false, current: VERSION };
|
|
712
|
+
if (!UPDATE_KINDS.includes(kind) || noUpdate() || (readPrefs() || {}).updateNotice !== true) return Promise.resolve(off); // the answer is read here, from the settings file: the page asking is not enough
|
|
713
|
+
const tell = (latest) => (latest ? { on: true, current: VERSION, latest, newer: newerThan(latest, VERSION), notes: `${GITHUB_REPO}/releases/tag/v${latest}`, ...updateHow(kind) } : { ...off, on: true });
|
|
714
|
+
let c = null; try { c = JSON.parse(fs.readFileSync(UPDATE_FILE, 'utf8')); } catch {}
|
|
715
|
+
const known = c && typeof c.latest === 'string' && VER_RE.test(c.latest) ? c.latest : '', at = (c && +c.t) || 0, now = Date.now();
|
|
716
|
+
if (at <= now && now - at < (c && c.failed ? 3600e3 : 864e5)) return Promise.resolve(tell(known));
|
|
717
|
+
if (!updateAsking) updateAsking = latestFromNpm().then((v) => {
|
|
718
|
+
try { fs.mkdirSync(path.dirname(UPDATE_FILE), { recursive: true }); fs.writeFileSync(UPDATE_FILE, JSON.stringify(v ? { t: Date.now(), latest: v } : { t: Date.now(), latest: known, failed: true })); } catch (e) { logError('update', e); }
|
|
719
|
+
return v || known;
|
|
720
|
+
}).finally(() => { updateAsking = null; });
|
|
721
|
+
return updateAsking.then(tell);
|
|
722
|
+
}
|
|
591
723
|
function errorReport() { // what ⚙ › Report a problem shows: the app, the system and the last errors of the log
|
|
592
724
|
let errors = []; try { errors = fs.readFileSync(ERRLOG, 'utf8').split('\n').filter(Boolean).slice(-40).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter((x) => x && typeof x === 'object'); } catch {}
|
|
593
725
|
return { version: VERSION, host: String(process.env.AGENT_STANDUP_HOST || '').slice(0, 80), platform: `${process.platform} ${os.release()} ${process.arch}`, node: process.version, electron: process.versions.electron || '', file: tidy(ERRLOG, 300), errors };
|
|
@@ -683,6 +815,7 @@ function parseRecord(st, r) {
|
|
|
683
815
|
if (ts > (st.lastTs || 0)) st.lastTs = ts;
|
|
684
816
|
if (st.journal) { if (r.type === 'result' && r.agentId) push({ ts: 0, agent, kind: 'wfdone', child: String(r.agentId).replace(/[^\w.-]/g, '_') }); return; } // a workflow's journal: one line when an agent starts, one when it hands its result back (no time on them)
|
|
685
817
|
if (r.type === 'system' && r.subtype === 'compact_boundary') { push({ ts, agent, kind: 'compact' }); return; } // Claude Code compacted the conversation
|
|
818
|
+
if (r.type === 'cost-state') { const usd = Number(r.totalCostUSD); if (agent === 'main' && Number.isFinite(usd) && usd >= 0) st.cost = { usd, at: st.lastTs || 0 }; return; } // Claude Code's own count of what the session cost, sub-agents included, written when its process ends or restarts (2.1.300 on): the latest one read
|
|
686
819
|
if (r.type === 'queue-operation' && typeof r.content === 'string' && r.content.includes('<task-notification>')) { // how Claude Code reports that a background sub-agent has stopped
|
|
687
820
|
const id = (r.content.match(/<tool-use-id>([^<]+)<\/tool-use-id>/) || [])[1], status = (r.content.match(/<status>([^<]+)<\/status>/) || [])[1];
|
|
688
821
|
if (id && status && status !== 'running') push({ ts, agent, kind: 'agentdone', toolId: id });
|
|
@@ -701,7 +834,7 @@ function parseRecord(st, r) {
|
|
|
701
834
|
for (const b of blocks(r)) if (b.type === 'tool_result' && (st.toolName[b.tool_use_id] === 'Agent' || st.toolName[b.tool_use_id] === 'Task') && !(st.bg && st.bg[b.tool_use_id]) && !/^\s*Async agent launched/i.test(resultText(b.content))) push({ ts, agent, kind: 'agentdone', toolId: b.tool_use_id }); // a synchronous call: the lead got the sub-agent's answer back, so it has finished (async launches answer immediately and are not a completion)
|
|
702
835
|
for (const b of blocks(r)) if (b.type === 'tool_result' && st.toolName[b.tool_use_id] && !NO_RESULT.has(st.toolName[b.tool_use_id])) {
|
|
703
836
|
const n = st.toolName[b.tool_use_id], img = resultImages(b.content).length, files = n === 'Bash' && !b.is_error ? docPaths(resultText(b.content), false).map((f) => absPath(f, r.cwd)) : [], art = !b.is_error && st.pubs && st.pubs.has(b.tool_use_id) ? artOf(st, st.pubs.get(b.tool_use_id), r.toolUseResult, resultText(b.content)) : null;
|
|
704
|
-
items.push({ id: b.tool_use_id, err: !!b.is_error, out: clip(resultText(b.content).replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g, '').trimEnd(), RESULT_MAX[n] || (/^mcp__/.test(n) ? 900 : 600)), ...(img ? { img } : {}), ...(files.length ? { files } : {}), ...(art ? { art } : {}) }); // img: how many pictures came back; the page fetches them from /api/media · files: the documents a command says it made
|
|
837
|
+
items.push({ id: b.tool_use_id, err: !!b.is_error, out: clip(resultText(b.content).replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g, '').trimEnd(), RESULT_MAX[n] || (/^mcp__/.test(n) ? 900 : 600)), ...(img ? { img } : {}), ...(files.length ? { files } : {}), ...(art ? { art } : {}), ...(BROWSER_MCP.test(n) && !b.is_error ? browserSeen(resultText(b.content)) : {}) }); // img: how many pictures came back; the page fetches them from /api/media · files: the documents a command says it made
|
|
705
838
|
}
|
|
706
839
|
if (items.length) push({ ts, agent, kind: 'results', items });
|
|
707
840
|
const typed = blocks(r).filter((b) => b.type === 'text').map((b) => b.text).join('\n').replace(HARNESS, ''), cut = /^\s*\[Request interrupted[^\]]*\]/i.test(typed); // what the human typed, without the blocks the harness wraps around it
|
|
@@ -714,7 +847,8 @@ function parseRecord(st, r) {
|
|
|
714
847
|
if (agent === 'main') { st.lead = 1; if (m.stop_reason) st.stops = 1; } // this transcript says why each message stopped: its turns end with a mark, and until one comes the lead is at work (see marks, below)
|
|
715
848
|
if (m.id && m.usage) { // the same message is repeated once per content block with identical numbers: keep one per message id
|
|
716
849
|
const u = m.usage, prev = st.msgUsage.get(m.id);
|
|
717
|
-
|
|
850
|
+
const ef = String(r.perTurnEffort || r.effort || ''), adv = String(r.advisorModel || ''); // the effort it worked at and the model it may ask for advice, when Claude Code wrote them (2.1.275 on)
|
|
851
|
+
st.msgUsage.set(m.id, { ts: prev ? prev.ts : ts, u: { i: u.input_tokens || 0, o: u.output_tokens || 0, r: u.cache_read_input_tokens || 0, w: u.cache_creation_input_tokens || 0 }, model: m.model, ...(/^[a-z]{2,12}$/.test(ef) ? { ef } : {}), ...(/^[\w.:\-\[\]]{1,80}$/.test(adv) && adv !== m.model ? { adv } : {}) });
|
|
718
852
|
}
|
|
719
853
|
const th = () => { const t = st.th; st.th = ''; return t ? { th: t } : {}; }; // what the agent was thinking before this line or call, when Claude Code kept it (most of the time it only keeps a signature): the call shows it as an inner thought
|
|
720
854
|
for (const b of blocks(r)) {
|
|
@@ -775,6 +909,7 @@ function buildTimeline(proj, id, files = []) {
|
|
|
775
909
|
let recentUntil = 0; for (const a of Object.values(agents)) if (a.id !== 'main' && a.mtime && now0 - a.mtime <= 240000) recentUntil = Math.max(recentUntil, a.mtime + 241000);
|
|
776
910
|
for (const a of Object.values(agents)) if (a.id !== 'main' && now0 - (a.mtime || 0) > 240000) finished.add(a.id); // old transcripts without a completion record: silent for 4 min counts as finished
|
|
777
911
|
const events = [], parent = {}, doneSeen = new Set(), lastTs = {}; for (const st of states) if (st) lastTs[st.agent] = st.lastTs || 0;
|
|
912
|
+
const usageBy = new Map(); for (const st of states) if (st) for (const [mid, mu] of st.msgUsage) { if (!/^msg_/.test(mid)) continue; const o = usageBy.get(mid); if (!o || mu.ts < o.msgUsage.get(mid).ts || (mu.ts === o.msgUsage.get(mid).ts && st.agent === 'main')) usageBy.set(mid, st); } // a fork (on by default since Claude Code 2.1.302) starts its file with a copy of the message that launched it: its tokens count once, for the agent that wrote it first. Only the API's own message ids (msg_…) name one message across files: Codex and Vibe number theirs in each agent (t0, v1…), the same name in two agents is two messages
|
|
778
913
|
const finish = (to, ts, by) => { if (!doneSeen.has(to)) { doneSeen.add(to); events.push({ ts, agent: to, kind: 'finish', to: by, k: 'f/' + to }); } }; // one per agent, whichever record says it first: the key is the agent, not the record
|
|
779
914
|
for (const st of states) {
|
|
780
915
|
if (!st) continue;
|
|
@@ -782,15 +917,16 @@ function buildTimeline(proj, id, files = []) {
|
|
|
782
917
|
if (st.agent !== 'main' && finished.has(st.agent)) for (let i = st.raw.length - 1; i >= 0; i--) if (st.raw[i].kind === 'say') { lastSay = i; break; }
|
|
783
918
|
const run = agents[st.agent] && agents[st.agent].wf ? runs[agents[st.agent].wf] : null;
|
|
784
919
|
if (run && st.prompt) { parent[st.agent] = run.by || 'main'; events.push({ ts: st.prompt.ts, agent: parent[st.agent], to: st.agent, kind: 'order', ...(run.toolId ? { toolId: run.toolId } : {}), bg: true, wf: agents[st.agent].wf, text: st.prompt.text, title: agents[st.agent].role, k: 'o/' + st.agent }); } // the order a workflow gave is the first message of the agent's own file: shown as an order from whoever launched the workflow (the lead when nothing says who), given in the background, when the agent started
|
|
920
|
+
// a fork's file starts with a copy of the call that launched it (Claude Code 2.1.302 turns forks on by default): that copy is not the fork launching or finishing itself
|
|
785
921
|
st.raw.forEach((e, i) => {
|
|
786
|
-
if (e.kind === 'agentdone') { const to = childByTool[e.toolId], wr = runByTool[e.toolId]; if (to) finish(to, e.ts, e.agent); else if (wr) for (const a of Object.values(wr.agents)) if (!wr.done.has(a)) finish(a, Math.max(e.ts, lastTs[a] || 0), e.agent); } // the agents the journal knows about are finished below, at their own time
|
|
787
|
-
else if (e.kind === 'agentcall') { const to = childByTool[e.toolId]; if (to) { parent[to] = e.agent; events.push({ ts: e.ts, agent: e.agent, to, kind: 'order', toolId: e.toolId, bg: e.bg, text: e.text, title: e.title, k: e.k }); } }
|
|
922
|
+
if (e.kind === 'agentdone') { const to = childByTool[e.toolId] === e.agent ? null : childByTool[e.toolId], wr = runByTool[e.toolId]; if (to) finish(to, e.ts, e.agent); else if (wr) for (const a of Object.values(wr.agents)) if (!wr.done.has(a)) finish(a, Math.max(e.ts, lastTs[a] || 0), e.agent); } // the agents the journal knows about are finished below, at their own time
|
|
923
|
+
else if (e.kind === 'agentcall') { const to = childByTool[e.toolId]; if (to && to !== e.agent) { parent[to] = e.agent; events.push({ ts: e.ts, agent: e.agent, to, kind: 'order', toolId: e.toolId, bg: e.bg, text: e.text, title: e.title, k: e.k }); } }
|
|
788
924
|
else if (e.kind === 'wfrun' || e.kind === 'wfdone') return;
|
|
789
925
|
else if (i === lastSay) events.push({ ...e, kind: 'report', to: null }); // `to` filled below, once every order is known
|
|
790
926
|
else events.push(e);
|
|
791
927
|
});
|
|
792
928
|
if (run && run.done.has(st.agent) && st.lastTs) finish(st.agent, st.lastTs, parent[st.agent] || 'main'); // the journal has no times: the agent finished when it last wrote
|
|
793
|
-
for (const [mid, mu] of st.msgUsage) events.push({ ts: mu.ts, agent: st.agent, kind: 'usage', u: mu.u, model: mu.model, ...(mu.cw ? { cw: mu.cw } : {}), k: 'u/' + st.agent + '/' + mid });
|
|
929
|
+
for (const [mid, mu] of st.msgUsage) if (!usageBy.has(mid) || usageBy.get(mid) === st) events.push({ ts: mu.ts, agent: st.agent, kind: 'usage', u: mu.u, model: mu.model, ...(mu.cw ? { cw: mu.cw } : {}), ...(mu.ef ? { ef: mu.ef } : {}), ...(mu.adv ? { adv: mu.adv } : {}), k: 'u/' + st.agent + '/' + mid });
|
|
794
930
|
}
|
|
795
931
|
for (const e of events) if (e.kind === 'report' && e.to === null) e.to = parent[e.agent] || 'main';
|
|
796
932
|
|
|
@@ -804,7 +940,8 @@ function buildTimeline(proj, id, files = []) {
|
|
|
804
940
|
}
|
|
805
941
|
const real = merged.find((e) => e.kind !== 'usage' && e.kind !== 'finish' && e.kind !== 'compact'), first = real ? real.ts : 0, last = merged.length ? merged[merged.length - 1].ts : 0; // time zero = the first thing said or done
|
|
806
942
|
const marks = !sx && states[0] && (states[0].stops || !states[0].lead) ? { marks: 1 } : {}; // a Claude Code session whose turns end with a mark, also before the lead has written anything: a session that has not closed a turn yet is not one without marks, and its lead is not "done" each time it thinks for a while
|
|
807
|
-
|
|
943
|
+
const ms = states.find((x) => x && x.agent === 'main'), cost = ms && ms.cost ? { usd: Math.round(ms.cost.usd * 1e4) / 1e4, final: !merged.some((e) => e.kind === 'usage' && e.ts > ms.cost.at) } : null; // final: nothing was spent after Claude Code counted it (else it is a floor)
|
|
944
|
+
return { id, proj, agents: Object.values(agents), events: merged.map((e) => ({ ...e, t: Math.max(0, e.ts - first) })), durationMs: last - first, recentUntil, ...marks, ...(cost ? { cost } : {}) };
|
|
808
945
|
}
|
|
809
946
|
|
|
810
947
|
// Ask the local `claude` CLI (uses the user's existing login) to map a JSON array of strings to another array. Cached.
|
|
@@ -1123,7 +1260,7 @@ function start(port = PORT) {
|
|
|
1123
1260
|
const sendFile = (fp) => { const s = fs.createReadStream(fp); s.on('error', () => res.destroy()); s.pipe(res); }; // a file that vanished between the check and the read ends this answer, not the server
|
|
1124
1261
|
// Endpoints with side effects (they spawn programs or claim the sound), and the one that serves pictures from a session, refuse requests that a browser marks as coming from another site, e.g. an <img> on a web page.
|
|
1125
1262
|
const sfs = req.headers['sec-fetch-site'];
|
|
1126
|
-
if (sfs && sfs !== 'same-origin' && sfs !== 'none' && (req.method !== 'GET' || ['/api/translate', '/api/quips', '/api/warm', '/api/audio', '/api/tts', '/api/prefs', '/api/prefs.js', '/api/voices', '/api/kokoro', '/api/kokoro/install', '/api/media', '/api/artifact', '/api/errors', '/api/packs'].includes(url.pathname))) { res.writeHead(403); return res.end('forbidden'); }
|
|
1263
|
+
if (sfs && sfs !== 'same-origin' && sfs !== 'none' && (req.method !== 'GET' || ['/api/translate', '/api/quips', '/api/warm', '/api/audio', '/api/tts', '/api/prefs', '/api/prefs.js', '/api/voices', '/api/kokoro', '/api/kokoro/install', '/api/media', '/api/artifact', '/api/errors', '/api/packs', '/api/update'].includes(url.pathname))) { res.writeHead(403); return res.end('forbidden'); }
|
|
1127
1264
|
const readBody = (cb, max = 262144) => { // request bodies are small JSON: stop reading beyond 256 KB (or max) and give up after 10 s
|
|
1128
1265
|
const chunks = []; let size = 0, over = false; req.setTimeout(10000, () => req.destroy());
|
|
1129
1266
|
if (+req.headers['content-length'] > max) { res.writeHead(413); res.end('too large'); return req.destroy(); }
|
|
@@ -1154,6 +1291,7 @@ function start(port = PORT) {
|
|
|
1154
1291
|
return loadVoices().then((v) => json(v));
|
|
1155
1292
|
}
|
|
1156
1293
|
if (url.pathname === '/api/kokoro/install' && req.method === 'POST') return json(kokoro.install()); if (url.pathname === '/api/usage' && req.method === 'POST') return json(usageWeek());
|
|
1294
|
+
if (url.pathname === '/api/update') return updateInfo().then(json, () => json({ on: false, current: VERSION })); /* a newer version, at most one request to npm a day (updateInfo) */
|
|
1157
1295
|
if (url.pathname === '/api/kokoro') return json(kokoro.status());
|
|
1158
1296
|
if (url.pathname === '/api/tts') {
|
|
1159
1297
|
return tts(url.searchParams.get('text') || '', url.searchParams.get('voice'), url.searchParams.get('rate'), url.searchParams.get('engine'), url.searchParams.get('fb'))
|
|
@@ -1161,8 +1299,9 @@ function start(port = PORT) {
|
|
|
1161
1299
|
.catch((e) => json({ error: String(e.message) }, 400));
|
|
1162
1300
|
}
|
|
1163
1301
|
if (url.pathname === '/api/prefs.js') { res.writeHead(200, { 'content-type': 'application/javascript', 'cache-control': 'no-store' }); return res.end('window.SAVED_PREFS = ' + JSON.stringify(readPrefs()).replace(/</g, '\\u003c') + '; window.AS_APP = ' + JSON.stringify(appKind()).replace(/</g, '\\u003c') + ';'); }
|
|
1164
|
-
if (url.pathname === '/api/prefs' && req.method === 'PUT') return readBody((body) => { try { const v = JSON.parse(body); if (!v || typeof v !== 'object' || Array.isArray(v)) throw new Error('prefs must be an object'); const cur = readPrefs() || {}; if ((+cur.shareUsageT || 0) > (+v.shareUsageT || 0)) { v.shareUsage = cur.shareUsage; v.shareUsageT = cur.shareUsageT; v.usageAsked = cur.usageAsked; } writePrefs(v); /* the usage answer: a page opened before it was changed elsewhere (another tab, the desktop app) writes back its old settings, not its old answer */ json({ ok: true }); } catch (e) { json({ error: String(e.message || e) }, 400); } });
|
|
1302
|
+
if (url.pathname === '/api/prefs' && req.method === 'PUT') return readBody((body) => { try { const v = JSON.parse(body); if (!v || typeof v !== 'object' || Array.isArray(v)) throw new Error('prefs must be an object'); const cur = readPrefs() || {}; if ((+cur.shareUsageT || 0) > (+v.shareUsageT || 0)) { v.shareUsage = cur.shareUsage; v.shareUsageT = cur.shareUsageT; v.usageAsked = cur.usageAsked; } if ((+cur.updateNoticeT || 0) > (+v.updateNoticeT || 0)) { v.updateNotice = cur.updateNotice; v.updateNoticeT = cur.updateNoticeT; v.updateAsked = cur.updateAsked; } writePrefs(v); /* the usage answer: a page opened before it was changed elsewhere (another tab, the desktop app) writes back its old settings, not its old answer */ json({ ok: true }); } catch (e) { json({ error: String(e.message || e) }, 400); } });
|
|
1165
1303
|
if (url.pathname === '/api/prefs') return json(readPrefs() || {});
|
|
1304
|
+
if (url.pathname === '/api/answer' && req.method === 'POST') return readBody((body) => { let v = {}; try { v = JSON.parse(body); } catch {} json(answerIn(String((v && v.id) || ''))); }); /* a click on what needs you: open it where it can be answered (answerIn) */
|
|
1166
1305
|
if (url.pathname === '/api/done' && req.method === 'POST') return readBody((body) => { try { const v = JSON.parse(body); json({ ok: setDone(String(v.proj || ''), String(v.id || ''), v.on !== false) }); } catch (e) { logError('done', e); json({ error: String(e.message || e) }, 400); } });
|
|
1167
1306
|
if (url.pathname === '/api/errors' && req.method === 'POST') return readBody((body) => { try { const b = JSON.parse(body) || {}; logError('page' + (typeof b.where === 'string' && b.where ? ' ' + b.where.slice(0, 40) : ''), { message: String(b.msg || ''), stack: String(b.stack || '') }); json({ ok: true }); } catch (e) { json({ error: String(e.message || e) }, 400); } }); // an error of the page, written to the local log
|
|
1168
1307
|
if (url.pathname === '/api/errors') return json(errorReport());
|
|
@@ -1216,8 +1355,8 @@ function start(port = PORT) {
|
|
|
1216
1355
|
}
|
|
1217
1356
|
if (ep == null) return json({ id: tl.id, agents: tl.agents, total: tl.events.length, events: tl.events.slice(+after) }); // a page loaded before 1.25.7 still asks by position
|
|
1218
1357
|
const a = +after; if (ep !== tl.ep || !(a >= 0 && a <= tl.seq)) return json({ resync: true }); // not the feed this page was following (restart, session dropped from memory, transcript rewritten): it loads the session again
|
|
1219
|
-
if (a === tl.seq) { if (!entry.idle) entry.idle = JSON.stringify({ id: tl.id, agents: tl.agents, ep: tl.ep, seq: tl.seq, marks: tl.marks, events: [] }); res.writeHead(200, { 'content-type': 'application/json' }); return res.end(entry.idle); } // nothing new, which is the answer to nearly every poll: written once
|
|
1220
|
-
return json({ id: tl.id, agents: tl.agents, ep: tl.ep, seq: tl.seq, marks: tl.marks, events: feedSince(entry, a) }); // new events and changed ones alike, whole, under the key they always had
|
|
1358
|
+
if (a === tl.seq) { if (!entry.idle) entry.idle = JSON.stringify({ id: tl.id, agents: tl.agents, ep: tl.ep, seq: tl.seq, marks: tl.marks, ...(tl.cost ? { cost: tl.cost } : {}), events: [] }); res.writeHead(200, { 'content-type': 'application/json' }); return res.end(entry.idle); } // nothing new, which is the answer to nearly every poll: written once
|
|
1359
|
+
return json({ id: tl.id, agents: tl.agents, ep: tl.ep, seq: tl.seq, marks: tl.marks, ...(tl.cost ? { cost: tl.cost } : {}), events: feedSince(entry, a) }); // new events and changed ones alike, whole, under the key they always had
|
|
1221
1360
|
}
|
|
1222
1361
|
const pk = url.pathname.match(/^\/packs\/([a-z]+)\/(.*)$/);
|
|
1223
1362
|
if (url.pathname.startsWith('/characters/') || (pk && packDir(pk[1]))) { // only plain image files of the characters folder (or of a built-in pack), by exact name
|
|
@@ -1235,7 +1374,7 @@ function start(port = PORT) {
|
|
|
1235
1374
|
} catch (e) { logError(req.method + ' ' + url.pathname, e); if (res.headersSent) return res.destroy(); json({ error: String(e.message || e) }, 500); }
|
|
1236
1375
|
}).listen(port, '127.0.0.1', function () { console.log(`Agent Standup → http://localhost:${this.address().port}`); });
|
|
1237
1376
|
}
|
|
1238
|
-
module.exports = { _winArg: winArg, start, currentSession, shutdown, findClaude, bundledClaude, boardRows, sessionRows: listSessions, charactersDir, listCharacters, packsDir, installPack, logError, _reveal: reveal, _scrub: { tidy, homeRe }, _artifact: { page: artifactPage, csp: artifactCsp } };
|
|
1377
|
+
module.exports = { answerIn, noteEditor, forgetEditor, _winArg: winArg, start, currentSession, shutdown, findClaude, bundledClaude, boardRows, sessionRows: listSessions, charactersDir, listCharacters, packsDir, installPack, logError, updateInfo, _reveal: reveal, _scrub: { tidy, homeRe }, _artifact: { page: artifactPage, csp: artifactCsp } };
|
|
1239
1378
|
if (require.main === module && process.env.AGENT_STANDUP_CHILD === '1' && typeof process.send === 'function') { // started by the VS Code extension in a process of its own (see extension.js): reading a large session no longer stops the editor's extensions. Asked for by name: pm2 and others give any app a channel too
|
|
1240
1379
|
const srv = start(+process.env.PORT || 0), tell = (m) => { try { process.send(m); } catch {} };
|
|
1241
1380
|
srv.on('listening', () => tell({ port: srv.address().port })).on('error', (e) => { tell({ error: e.code || String(e) }); process.exit(1); });
|
package/vibe.js
CHANGED
|
@@ -115,7 +115,7 @@ function boardRow(r, now) {
|
|
|
115
115
|
if (r.uni) { // the current format says it outright: idle, running, or blocked on an approval or a question
|
|
116
116
|
const u = uniSummary(r), kind = u.status, age = now - r.mtime, live = u.live;
|
|
117
117
|
const state = age >= 30 * 60e3 ? 'idle' : kind === 'blocked' ? 'blocked' : kind === 'running' ? (u.waiting ? 'waiting' : 'working') : kind === 'idle' || kind === 'failed' ? 'turn' : age < 10 * 60e3 ? 'working' : 'idle';
|
|
118
|
-
return { proj: PROJ, id: r.id, title: title(r), mtime: r.mtime, state, tool: '', ageMs: age, subActive: state === 'idle' || state === 'turn' ? 0 : live, subTotal: u.kids, asked: u.asked || 0, dir: dirKey(meta(r.dir).cwd), source: SOURCE };
|
|
118
|
+
return { proj: PROJ, id: r.id, title: title(r), mtime: r.mtime, state, tool: '', ageMs: age, subActive: state === 'idle' || state === 'turn' ? 0 : live, subTotal: u.kids, asked: u.asked || 0, dir: dirKey(meta(r.dir).cwd), source: SOURCE, ...(state === 'blocked' ? { sure: 1 } : {}) }; /* blocked: Vibe wrote that it waits on an approval or a question, not a guess */
|
|
119
119
|
}
|
|
120
120
|
const sig = r.mtime + ':' + r.size; let t = tailCache.get(r.file);
|
|
121
121
|
if (!t || t.sig !== sig) {
|