@double_geste/agent-standup 1.41.2 → 1.43.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/server.js CHANGED
@@ -15,7 +15,33 @@ const { execFileSync, execFile } = require('child_process');
15
15
 
16
16
  const PORT = process.env.PORT || 4747;
17
17
  // Same place Claude Code writes to: honours CLAUDE_CONFIG_DIR (custom config dirs are common on Linux); AGENT_STANDUP_PROJECTS overrides it.
18
- const ROOT = process.env.AGENT_STANDUP_PROJECTS || path.join(process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude'), 'projects');
18
+ const CLAUDE_HOME = process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude'), ONE_FOLDER = !!process.env.AGENT_STANDUP_PROJECTS, EXTRA_HOMES = String(process.env.AGENT_STANDUP_CLAUDE_DIRS || '');
19
+ const ROOT = process.env.AGENT_STANDUP_PROJECTS || path.join(CLAUDE_HOME, 'projects');
20
+ // Some people keep one Claude Code folder per account, each started with its own CLAUDE_CONFIG_DIR (alias claude-pro="CLAUDE_CONFIG_DIR=~/.claude-pro claude", issue #9): the app is started without it and would read neither.
21
+ // So every such folder is read too: ~/.claude, each ~/.claude-<name> (or .claude_<name>, .claude.<name>) that holds a projects folder, and the ones AGENT_STANDUP_CLAUDE_DIRS names ("off": none of them). The one of this process comes first.
22
+ // A ~/.claude-<name> is an account only if Claude Code was started with it: it then keeps its own .claude.json there (.config.json for one an old Claude Code made, .claude-custom-oauth.json…; the default one is in the home folder, so a copy of ~/.claude has none), and its name does not end like a backup's (.bak, -old, " copy 2", -20251001…).
23
+ // A session id is unique, so a session found in two folders (a copy) is taken from the one whose last record is the latest (resumed there), then the larger, then the first: a copy made with cp -r has fresh file dates, which say nothing. With AGENT_STANDUP_PROJECTS (--projects, the tests) that one folder alone is read, as before.
24
+ const sizeOf = (f) => { try { return fs.statSync(f).size; } catch { return -1; } }; // -1 for a file that is gone: an empty one still counts
25
+ const isFile = (f) => { try { return fs.statSync(f).isFile(); } catch { return false; } };
26
+ const stampMemo = new Map();
27
+ function lastStamp(f) { // the time of a transcript's last record, read from its end (-1: no file); a copy keeps it, where its file date is the copy's. None in the last 64 KB (a huge last record): the file's date
28
+ let st; try { st = fs.statSync(f); } catch { return -1; } const m = stampMemo.get(f); if (m && m.size === st.size && m.mt === st.mtimeMs) return m.t;
29
+ let t = st.mtimeMs; try { const fd = fs.openSync(f, 'r'); try { const n = Math.min(st.size, 65536), buf = Buffer.alloc(n); fs.readSync(fd, buf, 0, n, st.size - n); const all = buf.toString('utf8').match(/"timestamp":\s*"[^"]{10,40}"/g); if (all) t = Date.parse(all[all.length - 1].split('"')[3]) || t; } finally { fs.closeSync(fd); } } catch {}
30
+ stampMemo.delete(f); if (stampMemo.size >= 20000) stampMemo.delete(stampMemo.keys().next().value); stampMemo.set(f, { size: st.size, mt: st.mtimeMs, t }); return t; /* the oldest out, one at a time */
31
+ }
32
+ const fuller = (a, b) => { const sa = sizeOf(a), sb = sizeOf(b); if (sa === sb) return false; const ta = lastStamp(a), tb = lastStamp(b); return ta !== tb ? ta > tb : sa > sb; }; // of two copies of one session, a the one to read: written later, or holding more. The same size: a copy left as it was, b (the first) without reading either
33
+ let homesMemo = { at: 0, list: [] };
34
+ function claudeHomes() { // [CLAUDE_HOME, the other folders that hold sessions]; looked for again every 30 s, for an account added while the app runs
35
+ if (ONE_FOLDER || /^(0|off|no|false)$/i.test(EXTRA_HOMES.trim())) return [CLAUDE_HOME]; // AGENT_STANDUP_CLAUDE_DIRS=off: that one folder (the command line's --config)
36
+ const now = Date.now(); if (now - homesMemo.at < 30e3) return homesMemo.list;
37
+ const home = os.homedir(), real = (d) => { try { return fs.statSync(d).isDirectory() ? fs.realpathSync(d) : ''; } catch { return ''; } };
38
+ let names = []; try { names = fs.readdirSync(home).filter((n) => /^\.claude[-_.][^\\/]+$/.test(n) && !/([-_.~ ](bak|bkp|backup|old|orig|copy|save|saved|prev|archive|snapshot)[\dT_.-]*| \(copy( \d+)?\)| \d+|[-_.]\d{6,}[\dT_.-]*|~)$/i.test(n) && ['.claude.json', '.config.json', '.claude-custom-oauth.json'].some((j) => isFile(path.join(home, n, j)))).sort(); } catch {}
39
+ const extra = EXTRA_HOMES.split(path.delimiter).map((d) => d.trim()).filter(Boolean).map((d) => path.resolve(d.replace(/^~(?=$|[\\/])/, home)));
40
+ const list = [CLAUDE_HOME], seen = new Set([real(path.join(CLAUDE_HOME, 'projects')) || path.join(CLAUDE_HOME, 'projects')]);
41
+ for (const d of [path.join(home, '.claude'), ...names.map((n) => path.join(home, n)), ...extra]) { const r = real(path.join(d, 'projects')); if (r && !seen.has(r)) { seen.add(r); list.push(d); } }
42
+ homesMemo = { at: now, list }; return list;
43
+ }
44
+ const projRoots = () => { const h = claudeHomes(); return h.length < 2 ? [ROOT] : h.map((d) => path.join(d, 'projects')); }; // one folder, as most people have: exactly the one read before
19
45
  const PUBLIC = path.join(__dirname, 'public');
20
46
  // Cowork, a tab of the Claude desktop app, keeps each of its sessions in the app's own folder, in the format of Claude Code: <folder>/<account>/<organisation>/<session>/.claude/projects/<project>/<id>.jsonl.
21
47
  // They are listed under one made-up project, as the sessions of the other tools are, and read like any Claude Code session from there on.
@@ -57,12 +83,31 @@ function coworkTitle(proj, id) { // the name the desktop app gave the session,
57
83
  let title = ''; try { const j = JSON.parse(fs.readFileSync(f, 'utf8')); if (typeof j.title === 'string') title = j.title.trim().slice(0, 200); } catch {}
58
84
  coworkNotes.set(f, { sig, title }); return title;
59
85
  }
60
- const projDir = (proj, id) => (proj === COWORK && coworkMap().get(id)) || path.join(ROOT, proj); // the folder that holds <id>.jsonl and the sub-agents of that session
61
- const projects = () => { let names = []; try { names = fs.readdirSync(ROOT); } catch {} return coworkMap().size ? names.concat(COWORK) : names; };
86
+ const dirOf = new Map(); // with several folders: proj/id → the project folder its transcript was found in (a transcript stays where it was written)
87
+ function projDir(proj, id) { // the folder that holds <id>.jsonl and the sub-agents of that session
88
+ const cw = proj === COWORK && coworkMap().get(id); if (cw) return cw;
89
+ const roots = projRoots(); if (roots.length < 2) return path.join(roots[0], proj);
90
+ const k = proj + '/' + id, known = dirOf.get(k); if (known) return known;
91
+ let best = ''; for (const r of roots) { const d = path.join(r, proj); if (sizeOf(path.join(d, id + '.jsonl')) >= 0 && (!best || fuller(path.join(d, id + '.jsonl'), path.join(best, id + '.jsonl')))) best = d; } // in two folders (one copied from the other, the session resumed in it): the one written later (fuller)
92
+ if (best) { if (dirOf.size > 5000) dirOf.clear(); dirOf.set(k, best); return best; }
93
+ return path.join(roots[0], proj);
94
+ }
95
+ const projects = () => { const roots = projRoots(); let names = []; for (const r of roots) try { names = names.concat(fs.readdirSync(r)); } catch {} if (roots.length > 1) names = [...new Set(names)]; return coworkMap().size ? names.concat(COWORK) : names; };
62
96
  function transcripts(proj) { // the sessions of a project: { id, file }
63
97
  const cw = proj === COWORK ? coworkMap() : null; if (cw && cw.size) return [...cw].map(([id, dir]) => ({ id, file: path.join(dir, id + '.jsonl') }));
64
- const dir = path.join(ROOT, proj); let files; try { files = fs.readdirSync(dir); } catch { return []; }
65
- return files.filter((f) => f.endsWith('.jsonl')).map((f) => ({ id: f.slice(0, -6), file: path.join(dir, f) }));
98
+ const roots = projRoots(), out = [], seen = new Map();
99
+ for (const r of roots) {
100
+ const dir = path.join(r, proj); let files; try { files = fs.readdirSync(dir); } catch { continue; }
101
+ for (const f of files) {
102
+ if (!f.endsWith('.jsonl')) continue; const id = f.slice(0, -6), row = { id, file: path.join(dir, f) };
103
+ if (roots.length > 1) { // a session in two folders is listed once, from the one written later (fuller, see projDir), which dirOf keeps up to date at each look
104
+ const was = seen.get(id); if (was && !fuller(row.file, was.file)) continue;
105
+ if (dirOf.size > 5000) dirOf.clear(); dirOf.set(proj + '/' + id, dir); if (was) { was.file = row.file; continue; } seen.set(id, row);
106
+ }
107
+ out.push(row);
108
+ }
109
+ }
110
+ return out;
66
111
  }
67
112
 
68
113
  const blocks = (rec) => {
@@ -478,7 +523,7 @@ function timelineEntry(proj, id) {
478
523
  // ---- Live feed. The timeline is sorted again at each build and events already sent can change (an order typed mid-turn is stamped at typing time and lands before what the page has; a sub-agent's last line becomes its report; a tool call joins an earlier beat),
479
524
  // so a page cannot ask for "what comes after index n". Every event has a key `k` that never changes, each build that changes something gets the next sequence number, and a page asks for the events that are new or different since the number it holds.
480
525
  // `ep` names this memory: it is a new one after a restart, after the session left the cache, or when a transcript was rewritten, and the page then loads the whole session again.
481
- const sigOf = (e) => e.kind + '|' + e.agent + '|' + (e.to || '') + '|' + (e.end || '') + '|' + (e.kind === 'tools' ? e.tools.length + ':' + e.tools[e.tools.length - 1].id + ':' + e.tools.map((t) => (t.d && t.d.kind === 'plan' ? (t.d.text || '').length + (t.d.text || '').slice(-24) : '')).join(',') : e.kind === 'usage' ? e.u.i + ',' + e.u.o + ',' + e.u.r + ',' + e.u.w + ',' + e.model : e.kind === 'order' ? e.toolId + ',' + e.bg + ',' + e.title : e.kind === 'finish' ? e.ts : ''); // everything about an event that can differ from one build to the next (a plan's text too: its answer names the plan approved). Its text, its tool calls, its results and its time never do: they come from one transcript record (same key = same record); and `t` moves only when time zero does, which feedStep looks at once for all
526
+ const sigOf = (e) => e.kind + '|' + e.agent + '|' + (e.to || '') + '|' + (e.end || '') + '|' + (e.kind === 'tools' ? e.tools.length + ':' + e.tools[e.tools.length - 1].id + ':' + e.tools.map((t) => (t.d && t.d.kind === 'plan' ? (t.d.text || '').length + (t.d.text || '').slice(-24) : '')).join(',') : e.kind === 'usage' ? e.u.i + ',' + e.u.o + ',' + e.u.r + ',' + e.u.w + ',' + e.model : e.kind === 'order' ? e.toolId + ',' + e.bg + ',' + e.title + ',' + e.text : e.kind === 'finish' ? e.ts : ''); // everything about an event that can differ from one build to the next (a plan's text too: its answer names the plan approved). Except for an order's late-arriving prompt, its text, its tool calls, its results and its time never do: they come from one transcript record (same key = same record); and `t` moves only when time zero does, which feedStep looks at once for all
482
527
  function feedStep(prev, tl, files) {
483
528
  let f = prev && files.every((x) => { const was = prev.gens.get(x); return was === undefined || was === (fileStates.get(x) || {}).gen; }) ? prev : null; // a transcript read again from its start numbers its events again: the keys no longer mean the same thing
484
529
  for (let pass = 0; ; pass++) {
@@ -531,7 +576,7 @@ const PR_URL = /^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/pull\/\d+$/; // noth
531
576
  const askOf = (b) => { const q = b.name === 'AskUserQuestion' && b.input && Array.isArray(b.input.questions) && b.input.questions[0] && b.input.questions[0].question; return typeof q === 'string' ? clip(q.trim(), 200) : ''; }; // the question a session stopped on, for its card
532
577
  const callOf = (b) => { const i = b.input || {}, v = b.name === 'Bash' ? i.command : /^(Edit|Write|MultiEdit|NotebookEdit)$/.test(b.name) ? path.basename(String(i.file_path || i.notebook_path || '')) : b.name === 'WebFetch' ? i.url : ''; return typeof v === 'string' && v.trim() ? b.name + '(' + clip(v.replace(/\s+/g, ' ').trim(), 160) + ')' : ''; }; // what a call waiting for your go-ahead would do, written the way Claude Code shows it: Bash(npm test)
533
578
  const PLAN_FILE = /[\\/]\.claude[\\/]plans[\\/][^\\/]+\.md$/, PLAN_DIR = process.env.CLAUDE_CONFIG_DIR ? path.join(process.env.CLAUDE_CONFIG_DIR, 'plans') + path.sep : '';
534
- const planFile = (f) => PLAN_FILE.test(f) || (!!PLAN_DIR && f.startsWith(PLAN_DIR) && f.endsWith('.md')); // also where a CLAUDE_CONFIG_DIR set elsewhere keeps them
579
+ const planFile = (f) => PLAN_FILE.test(f) || (!!PLAN_DIR && f.startsWith(PLAN_DIR) && f.endsWith('.md')) || (f.endsWith('.md') && claudeHomes().slice(1).some((h) => f.startsWith(path.join(h, 'plans') + path.sep))); // also where a CLAUDE_CONFIG_DIR set elsewhere keeps them, and the other folders read (claudeHomes)
535
580
  const planDoc = (f) => { try { const st = fs.statSync(f); if (!st.isFile() || st.size > 262144) return ''; return clip(fs.readFileSync(f, 'utf8').trim(), 4000); } catch { return ''; } }; // the whole plan, for the shared screen
536
581
  const planText = (f) => { try { const st = fs.statSync(f); if (!st.isFile() || st.size > 262144) return ''; return clip(fs.readFileSync(f, 'utf8').trim(), 1200); } catch { return ''; } };
537
582
  const menuOf = (b) => { // what a menu waiting for you shows, from the call it waits on, word for word: the questions and their options in their order (the terminal numbers them the same way), the command, the file, the plan
@@ -545,31 +590,35 @@ const menuOf = (b) => { // what a menu waiting for you shows, from the call it
545
590
  };
546
591
  // Claude Code also keeps <config>/sessions/<pid>.json for each open session: its status (busy, idle, or waiting while a menu waits for your answer: a permission, a question) and since when.
547
592
  // 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.
548
- const CC_SESSIONS = process.env.AGENT_STANDUP_CC_SESSIONS || path.join(process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude'), 'sessions');
593
+ const CC_SESSIONS = process.env.AGENT_STANDUP_CC_SESSIONS || path.join(process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), '.claude'), 'sessions'), CC_SESSIONS_SET = !!process.env.AGENT_STANDUP_CC_SESSIONS;
594
+ const statusDirs = () => { const h = CC_SESSIONS_SET ? [] : claudeHomes(); return h.length < 2 ? [CC_SESSIONS] : h.map((d) => path.join(d, 'sessions')); }; // each folder read keeps the status of its own sessions
549
595
  const alive = (pid) => { try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; } };
550
596
  function liveStatus() { // session id → { status, since, pid, ep (where it runs: claude-vscode, cli, claude-desktop, sdk-cli…), and for missingTranscripts: raw (the status as written), cwd, kind, startedAt, version, updatedAt (when the file was last written: a /clear moves it, and the id, but not statusUpdatedAt) }
551
- const out = new Map(); let names = []; try { names = fs.readdirSync(CC_SESSIONS); } catch { return out; }
552
- 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 || ''), raw: s.status, cwd: typeof s.cwd === 'string' ? s.cwd : '', kind: typeof s.kind === 'string' ? s.kind : '', startedAt: Number(s.startedAt) || 0, version: typeof s.version === 'string' ? s.version : '', updatedAt: Number(s.updatedAt) || 0 }); } 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 */
597
+ const out = new Map(), later = (a, b) => Math.max(a.updatedAt, a.since) > Math.max(b.updatedAt, b.since);
598
+ for (const [i, dir] of statusDirs().entries()) { const into = i ? new Map() : out; let names = []; try { names = fs.readdirSync(dir); } catch { continue; }
599
+ for (const n of names) { if (!/^\d+\.json$/.test(n)) continue; try { const s = JSON.parse(fs.readFileSync(path.join(dir, n), 'utf8')); if (s && typeof s.sessionId === 'string' && /^(busy|idle|waiting)$/.test(s.status) && Number.isInteger(s.pid) && s.pid > 0 && alive(s.pid)) into.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 || ''), raw: s.status, cwd: typeof s.cwd === 'string' ? s.cwd : '', kind: typeof s.kind === 'string' ? s.kind : '', startedAt: Number(s.startedAt) || 0, version: typeof s.version === 'string' ? s.version : '', updatedAt: Number(s.updatedAt) || 0 }); } 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 */
600
+ if (i) { const byPid = new Map([...out].map(([k, v]) => [v.pid, k])); for (const [k, v] of into) { const o = out.get(k), pk = byPid.get(v.pid), p = pk != null && pk !== k ? out.get(pk) : null; if ((o && !later(v, o)) || (p && !later(v, p))) continue; if (p) out.delete(pk); out.set(k, v); byPid.set(v.pid, k); } } // a folder copied while a session ran keeps its status frozen: of two that name the same session, or the same process (its id changed since with /clear), the one written last
601
+ }
553
602
  return out;
554
603
  }
555
604
  // A Claude Code session that is open and has worked, yet whose transcript is nowhere in the projects folder read here. The call cannot show it; the page says so, and why it may be (issue #9). Read from the status files alone, nothing sent.
556
605
  // Only one cause is visible this way (Claude Code 2.1.304, tried): CLAUDE_CODE_SKIP_PROMPT_HISTORY=1 writes the status file (interactive, idle/busy) and shows "Transcript saving is off", but no transcript.
557
- // An inherited CLAUDE_CODE_CHILD_SESSION=1 writes neither, and another CLAUDE_CONFIG_DIR puts the status file in that other folder: neither leaves anything here. What is listed may also be a cause not known yet.
606
+ // An inherited CLAUDE_CODE_CHILD_SESSION=1 writes neither, and another CLAUDE_CONFIG_DIR puts the status file in that other folder: neither leaves anything here (that folder is read too when it is one of claudeHomes). What is listed may also be a cause not known yet.
558
607
  // Listed only once this server has seen the session busy, under its current id, for 5 s: a session just opened, one where you opened /model or /config, and one right after /clear
559
608
  // (a new id and updatedAt, while status and statusUpdatedAt are still those of the id before) have written no transcript yet, and need none.
560
609
  let missingMemo = { at: 0, list: [] }; const transcriptSeen = new Set(), busySeen = new Map(); // transcriptSeen: ids found once are not looked for again, a transcript stays where it was written · busySeen: id → when it was first seen busy (at most 500)
561
610
  function missingTranscripts() { // [{ id, cwd, name, version, ep, since }]: one look every 10 s at most
562
611
  if (process.env.AGENT_STANDUP_PROJECTS && !process.env.AGENT_STANDUP_CC_SESSIONS) return []; // sessions read from another folder than the one these status files belong to: every live session would look as if it wrote nothing
563
612
  const now = Date.now(); if (now - missingMemo.at < 10e3) return missingMemo.list;
564
- const list = []; let dirs = null;
613
+ const list = [], roots = projRoots(); let dirs = null;
565
614
  for (const [id, w] of liveStatus()) {
566
615
  if ((w.kind && w.kind !== 'interactive') || /^sdk-(cli|ts|py)$/.test(w.ep) || transcriptSeen.has(id) || !/^[\w-]+$/.test(id)) continue; // a session a program runs keeps no transcript a person would look for
567
616
  if (w.raw === 'busy' && w.since >= w.updatedAt && !busySeen.has(id)) { if (busySeen.size >= 500) busySeen.delete(busySeen.keys().next().value); busySeen.set(id, Math.min(now, w.since || now)); } // a status written for this id (an older Claude Code writes no updatedAt: 0)
568
617
  if (!(now - (busySeen.get(id) || now) >= 5e3)) continue; // Claude Code writes the transcript with the first message: never busy yet, or only just
569
618
  const name = id + '.jsonl', key = w.cwd.replace(/[^a-zA-Z0-9]/g, '-'); // Claude Code's project folder naming: the folder of its cwd, looked at first
570
- if ((key && mtimeOf(path.join(ROOT, key, name))) || coworkMap().has(id)) { transcriptSeen.add(id); continue; }
571
- if (!dirs) { dirs = []; try { dirs = fs.readdirSync(ROOT); } catch {} } // a long path is shortened in its folder name: every folder, then
572
- if (dirs.some((d) => mtimeOf(path.join(ROOT, d, name)))) { transcriptSeen.add(id); continue; }
619
+ if ((key && roots.some((r) => mtimeOf(path.join(r, key, name)))) || coworkMap().has(id)) { transcriptSeen.add(id); continue; }
620
+ if (!dirs) { dirs = []; for (const r of roots) try { dirs = dirs.concat(fs.readdirSync(r).map((d) => path.join(r, d))); } catch {} } // a long path is shortened in its folder name: every folder, then
621
+ if (dirs.some((d) => mtimeOf(path.join(d, name)))) { transcriptSeen.add(id); continue; }
573
622
  list.push({ id, cwd: w.cwd, name: w.cwd ? path.basename(w.cwd) : '', version: w.version, ep: w.ep, since: w.startedAt || w.since });
574
623
  }
575
624
  missingMemo = { at: now, list }; return list;
@@ -808,9 +857,9 @@ function logError(where, e) {
808
857
  // (a star on GitHub: they have no store). Only the desktop app and the command line ask on their own, on the third day: the extension asks in its own way (extension.js, noteUse).
809
858
  const RATE_STORES = /^https:\/\/(marketplace\.visualstudio\.com|open-vsx\.org)\//, GITHUB_REPO = 'https://github.com/Atoll92/agent-standup';
810
859
  function appKind() {
811
- const h = String(process.env.AGENT_STANDUP_HOST || ''), rate = String(process.env.AGENT_STANDUP_RATE || '');
860
+ const h = String(process.env.AGENT_STANDUP_HOST || ''), rate = String(process.env.AGENT_STANDUP_RATE || ''), lead = String(process.env.AGENT_STANDUP_LEAD_NAME || '').trim().slice(0, 100);
812
861
  const kind = h === 'desktop app' ? 'desktop' : h === 'command line' ? 'cli' : h === 'claude code plugin' ? 'plugin' : h ? 'editor' : '';
813
- 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
862
+ return { kind, rate: kind === 'editor' && RATE_STORES.test(rate) ? rate : GITHUB_REPO, track: !noTrack(), updates: !noUpdate(), ...(lead ? { lead } : {}) }; // track: false when DO_NOT_TRACK is set, and the page does not ask about usage. lead: the lead's name set in the editor (agentStandup.leadName), which the page cleans and prefers to its own setting
814
863
  }
815
864
  // 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
816
865
  // (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"
@@ -905,7 +954,7 @@ const projCwds = new Map(), dirKey = (d) => String(d || '').replace(/[^a-zA-Z0-9
905
954
  const foldKey = (k) => (process.platform === 'win32' ? String(k).toLowerCase() : k); // Windows: a folder is the same whatever its case (the editor sends C:, Claude Code may have written c:)
906
955
  function projCwd(proj) {
907
956
  if (projCwds.has(proj)) return projCwds.get(proj);
908
- let cwd = ''; for (const { id } of transcripts(proj).slice(0, 3)) { try { const m = /"cwd":"((?:[^"\\]|\\.)*)"/.exec(readHead(path.join(projDir(proj, id), id + '.jsonl'), 64 * 1024)); if (m) { cwd = JSON.parse('"' + m[1] + '"'); break; } } catch {} }
957
+ let cwd = ''; for (const { id } of transcripts(proj).slice(0, 3)) { try { const m = /"cwd":"((?:[^"\\]|\\.)*)"/.exec(readHead(path.join(projDir(proj, id), id + '.jsonl'), 64 * 1024)); if (m) { const c = JSON.parse('"' + m[1] + '"'); if (foldKey(dirKey(c)) === foldKey(proj)) { cwd = c; break; } } } catch {} } /* a session that started elsewhere (a scratch folder) does not hide the others */
909
958
  const sure = !!cwd && foldKey(dirKey(cwd)) === foldKey(proj); if (sure) projCwds.set(proj, cwd); return sure ? cwd : ''; // kept once it is sure: the folder whose name is the project's
910
959
  }
911
960
  const inFolder = (proj, key) => { const p = foldKey(proj), k = foldKey(key); if (p === k) return true; if (!p.startsWith(k + '-')) return false; const cwd = projCwd(proj); if (!cwd) return true; for (let d = cwd; d;) { if (foldKey(dirKey(d)) === k) return true; const up = path.dirname(d); if (up === d) return false; d = up; } return false; };
@@ -947,7 +996,7 @@ function readNew(file, agent, journal, record = parseRecord) {
947
996
  let size, mtime; try { const s = fs.statSync(file); size = s.size; mtime = s.mtimeMs; } catch { fileStates.delete(file); return null; }
948
997
  let st = fileStates.get(file);
949
998
  if (st && size >= st.offset && mtime !== st.mtime && st.fp.length && !sameBytes(file, st)) st = null; // rewritten in place and not shorter: checked only when the file was written to, with one small read
950
- if (!st || size < st.offset) { st = { agent, file, journal: !!journal, gen: ++fileGen, offset: 0, mtime: 0, fp: Buffer.alloc(0), tail: Buffer.alloc(0), raw: [], toolName: {}, msgUsage: new Map() }; fileStates.set(file, st); }
999
+ if (!st || st.agent !== agent || size < st.offset) { st = { agent, file, journal: !!journal, gen: ++fileGen, offset: 0, mtime: 0, fp: Buffer.alloc(0), tail: Buffer.alloc(0), raw: [], toolName: {}, msgUsage: new Map() }; fileStates.set(file, st); }
951
1000
  st.mtime = mtime;
952
1001
  while (size > st.offset) { // read in chunks of at most 16 MB so a huge transcript never needs one giant buffer
953
1002
  const fd = fs.openSync(file, 'r'); let buf;
@@ -967,6 +1016,7 @@ function readNew(file, agent, journal, record = parseRecord) {
967
1016
  return st;
968
1017
  }
969
1018
  function parseRecord(st, r) {
1019
+ if (!st.cwd && typeof r.cwd === 'string' && r.cwd) st.cwd = r.cwd; // the folder the session started in; later cd records do not change its project
970
1020
  const agent = st.agent, ts = Date.parse(r.timestamp) || 0, push = (e) => { e.k = agent + ':' + st.raw.length; st.raw.push(e); return e; }; // k: the event's key in the live feed = whose file + its rank in it. A file is only ever appended to, so the rank never changes (and when it is not, the whole file is read again under a new number, see readNew)
971
1021
  if (ts > (st.lastTs || 0)) st.lastTs = ts;
972
1022
  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)
@@ -1046,36 +1096,60 @@ function readMeta(f) {
1046
1096
  try { const mt = fs.statSync(f).mtimeMs, c = metaCache.get(f); if (c && c.mtime === mt) return c.value; const v = JSON.parse(fs.readFileSync(f, 'utf8')); if (metaCache.size > 3000) metaCache.clear(); metaCache.set(f, { mtime: mt, value: v }); return v; } catch { return {}; }
1047
1097
  }
1048
1098
 
1099
+ // The actual project behind a session, not the provider bucket (_codex, _vibe).
1100
+ // Keep the full folder: dashed project keys cannot distinguish app/old from app-old.
1101
+ // A Claude Code session is filed under its project's folder: the folder whose name that is comes first (projCwd), so a session that started in a scratch folder, an old transcript without cwd and a live one whose first cwd is not written yet all share their project's name.
1102
+ const leadProjects = new Map(), bareDir = (d) => { const n = path.normalize(d), root = path.parse(n).root; return n.length > root.length ? n.replace(/[\\/]+$/, '') : n; }; // /work/app/ and /work/app are one folder
1103
+ function leadProject(proj, id, recordedCwd) {
1104
+ const memo = proj + '/' + id; if (leadProjects.has(memo)) return leadProjects.get(memo);
1105
+ const sx = sourceOf(proj), cwd = sx ? guard(() => sx.cwd(id), '') : projCwd(proj) || recordedCwd;
1106
+ // Cowork's folders live in separate VMs: identical cwd strings there need not be one project.
1107
+ if (proj === COWORK) return { key: 'cowork:' + projDir(proj, id), label: cwd || coworkTitle(proj, id) || id };
1108
+ if (cwd) { const v = { key: 'cwd:' + foldKey(bareDir(cwd)), label: cwd }; if (leadProjects.size > 3000) leadProjects.clear(); leadProjects.set(memo, v); return v; } // kept once a folder is known: it no longer changes
1109
+ return sx ? null : { key: 'claude:' + proj, label: proj }; // older Claude transcripts without cwd still have a project folder; an unknown provider folder has no override
1110
+ }
1111
+
1049
1112
  function buildTimeline(proj, id, files = []) {
1050
- const sx = sourceOf(proj), rec = recordOf(sx), base = projDir(proj, id), mainFile = sx ? sx.fileOf(id) || '' : path.join(base, id + '.jsonl'); // a Codex or Vibe session is kept somewhere else, in another format (rec); from here on it is a session like any other (Codex without sub-agents)
1113
+ const sx = sourceOf(proj), rec = recordOf(sx), base = projDir(proj, id), mainFile = sx ? sx.fileOf(id) || '' : path.join(base, id + '.jsonl'); // source readers supply their own session and child files; the timeline and page are shared
1051
1114
  if (!fs.existsSync(mainFile)) throw new Error('session not found');
1052
1115
  const agents = { main: { id: 'main', role: 'Lead', type: 'main' } }; // the lead has the same name whatever tool runs the session: the page gives it
1053
1116
  const states = [(sx && sx.state && guard(() => sx.state(id), null)) || readNew(mainFile, 'main', false, rec)], subs = subFilesOf(proj, id), runs = {}; files.push(mainFile); // sx.state: a format that is not read line by line hands over the events of the session whole // runs: workflow run → { agents (file name → agent id), by (who launched it), toolId, done }
1054
1117
  for (const x of subs) {
1055
1118
  const aid = x.aid, m = x.meta || readMeta(x.file.replace(/\.jsonl$/, '.meta.json'));
1056
1119
  agents[aid] = { id: aid, role: m.description || m.workflowPhase || m.agentType || 'Agent', type: m.agentType || 'agent', toolUseId: m.toolUseId };
1120
+ if (m.parent) Object.assign(agents[aid], { parent: m.parent, name: m.name, startedAt: m.startedAt }); // Codex records the parent explicitly, even when its spawn prompt is encrypted
1057
1121
  if (x.run) { agents[aid].wf = x.run; if (m.workflowPhase) agents[aid].phase = m.workflowPhase; (runs[x.run] = runs[x.run] || { agents: {}, done: new Set() }).agents[x.id0] = aid; } // launched by a workflow: no Agent call of the lead points at it
1058
1122
  agents[aid].mtime = x.mtime || mtimeOf(x.file) || undefined;
1059
- const st = x.st || readNew(x.file, aid, false, rec); if (st) states.push(st); files.push(x.file);
1123
+ const st = x.st || (x.zst ? sx && sx.state && guard(() => sx.state(aid, aid), null) : readNew(x.file, aid, false, rec)); if (st) states.push(st); files.push(x.file); // x.zst: a compressed Codex child, read whole here only
1060
1124
  }
1061
1125
  for (const j of subs.journals) { const st = readNew(j.file, 'wf:' + j.run, true), run = runs[j.run]; files.push(j.file); if (st && run) for (const e of st.raw) if (run.agents[e.child]) run.done.add(run.agents[e.child]); }
1062
1126
  const childByTool = {}; // Agent tool_use id → the sub-agent it created, so we know who ordered whom
1063
1127
  for (const a of Object.values(agents)) if (a.toolUseId) childByTool[a.toolUseId] = a.id;
1064
- const called = {}, born = {}; for (const st of states) if (st) { if (st.raw.length) born[st.agent] = st.raw[0].ts; for (const e of st.raw) if (e.kind === 'agentcall' && e.nm && childByTool[e.toolId]) called[childByTool[e.toolId]] = e.nm; }
1128
+ const called = {}, born = {}; for (const st of states) if (st) { const b0 = (st.prompt && st.prompt.ts) || (st.raw.length && st.raw[0].ts); if (b0) born[st.agent] = b0; for (const e of st.raw) if (e.kind === 'agentcall' && e.nm && childByTool[e.toolId]) called[childByTool[e.toolId]] = e.nm; }
1065
1129
  const sameName = {}; for (const a of Object.values(agents).filter((x) => x.id !== 'main').sort((x, y) => (born[x.id] || Infinity) - (born[y.id] || Infinity) || (x.id < y.id ? -1 : 1))) { // in the order they started, so that a second agent of the same name is the one numbered 2 and stays so
1066
- const n = ownName(called[a.id]) || ownName(a.type, true); if (n) { const k = n.toLowerCase(); sameName[k] = (sameName[k] || 0) + 1; a.own = sameName[k] > 1 ? n + ' ' + sameName[k] : n; }
1130
+ if (born[a.id] || a.startedAt > 0) a.born = born[a.id] || a.startedAt; // when it started (its prompt, its first line, or what Codex recorded): the page names the agents in that order (byBorn in index.html), so that a reload gives each the same name
1131
+ const n = ownName(called[a.id]) || ownName(a.name) || ownName(a.type, true); if (n) { const k = n.toLowerCase(); sameName[k] = (sameName[k] || 0) + 1; a.own = sameName[k] > 1 ? n + ' ' + sameName[k] : n; }
1067
1132
  }
1068
1133
  const runByTool = {}; for (const st of states) if (st) for (const e of st.raw) if (e.kind === 'wfrun' && runs[e.run] && !runs[e.run].by) { runs[e.run].by = e.agent; runs[e.run].toolId = e.toolId; runByTool[e.toolId] = runs[e.run]; } // Workflow tool_use id → the run it started
1069
1134
 
1070
1135
  const finished = new Set(), now0 = Date.now(); for (const st of states) if (st) for (const e of st.raw) if (e.kind === 'agentdone') { if (childByTool[e.toolId]) finished.add(childByTool[e.toolId]); else if (runByTool[e.toolId]) for (const a of Object.values(runByTool[e.toolId].agents)) finished.add(a); } // a run that stopped: so did every agent in it
1071
1136
  for (const run of Object.values(runs)) for (const a of run.done) finished.add(a);
1137
+ for (const st of states) if (st && st.agent !== 'main' && st.completed) finished.add(st.agent);
1072
1138
  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);
1073
1139
  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
1074
1140
  const events = [], parent = {}, doneSeen = new Set(), lastTs = {}; for (const st of states) if (st) lastTs[st.agent] = st.lastTs || 0;
1141
+ for (const a of Object.values(agents)) if (a.parent && a.parent !== a.id && agents[a.parent]) parent[a.id] = a.parent;
1075
1142
  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
1076
1143
  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
1077
1144
  for (const st of states) {
1078
1145
  if (!st) continue;
1146
+ const a = agents[st.agent];
1147
+ if (a && a.parent && parent[st.agent]) {
1148
+ events.push({ ts: a.startedAt || (st.prompt && st.prompt.ts) || born[st.agent] || 0, agent: parent[st.agent], to: st.agent, kind: 'order', bg: true,
1149
+ text: st.prompt ? st.prompt.text : a.role, title: a.role, k: 'o/' + st.agent });
1150
+ for (const [n, q] of (st.prompts || []).entries()) events.push({ ts: q.ts, agent: parent[st.agent], to: st.agent, kind: 'order', bg: true, text: q.text, title: a.role, k: 'o/' + st.agent + '/' + (n + 1) }); // more work for a worker that had finished
1151
+ if (st.completedAt) finish(st.agent, st.completedAt, parent[st.agent]); // kept while it works again (its time moves to the next end): an event that vanished would make the page load the call again
1152
+ }
1079
1153
  let lastSay = -1; // the last thing a sub-agent says is its report back to the lead
1080
1154
  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; }
1081
1155
  const run = agents[st.agent] && agents[st.agent].wf ? runs[agents[st.agent].wf] : null;
@@ -1104,7 +1178,7 @@ function buildTimeline(proj, id, files = []) {
1104
1178
  const real = merged.find((e) => e.kind !== 'usage' && e.kind !== 'finish' && e.kind !== 'compact' && e.kind !== 'tasks'), first = real ? real.ts : 0, last = merged.length ? merged[merged.length - 1].ts : 0; // time zero = the first thing said or done
1105
1179
  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
1106
1180
  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)
1107
- 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 } : {}) };
1181
+ return { id, proj, project: leadProject(proj, id, ms && ms.cwd), agents: Object.values(agents), events: merged.map((e) => ({ ...e, t: Math.max(0, e.ts - first) })), durationMs: last - first, recentUntil, ...marks, ...(cost ? { cost } : {}) };
1108
1182
  }
1109
1183
 
1110
1184
  // Ask the local `claude` CLI (uses the user's existing login) to map a JSON array of strings to another array. Cached.
@@ -1464,7 +1538,7 @@ function start(port = PORT) {
1464
1538
  .catch((e) => json({ error: String(e.message) }, 400));
1465
1539
  }
1466
1540
  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') + ';'); }
1467
- 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); } });
1541
+ if (url.pathname === '/api/prefs' && req.method === 'PUT') return readBody((body) => { try { let v = JSON.parse(body); if (!v || typeof v !== 'object' || Array.isArray(v)) throw new Error('prefs must be an object'); const cur = readPrefs() || {}; const pt = v._patch && typeof v._patch === 'object' && !Array.isArray(v._patch) ? v._patch : null, set = pt && pt.set && typeof pt.set === 'object' && !Array.isArray(pt.set) ? pt.set : {}; if (pt && (!('_t' in set) || !('_t' in v) || +set._t === +v._t)) { const del = Array.isArray(pt.del) ? pt.del : []; v = { ...cur, ...set }; for (const k of del) if (typeof k === 'string' && !(k in set)) delete v[k]; } delete v._patch; /* a patch dated otherwise than the settings it came with is a stale copy (a page before 1.42 that read one from the file): those settings are written whole */ /* a page sends what it changed, merged into the file as it is now: a window opened earlier no longer puts back what another one changed. A whole object (an older page) still replaces the file */ 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); } });
1468
1542
  if (url.pathname === '/api/prefs') return json(readPrefs() || {});
1469
1543
  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) */
1470
1544
  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); } });
@@ -1495,7 +1569,7 @@ function start(port = PORT) {
1495
1569
  if (url.pathname === '/api/media') {
1496
1570
  const q = (k) => url.searchParams.get(k) || '', SAFE = /^[\w.\-]+$/, n = +q('n') || 0, bad = [q('proj'), q('id'), q('agent'), q('tool')].some((v) => !SAFE.test(v) || v === '..' || v.length > 200) || q('tool').length < 6; // no tool call has an id that short, and looking for one meant reading the whole transcript
1497
1571
  const sx = sourceOf(q('proj')), user = q('agent') === 'user', ok = !bad && Number.isInteger(n) && n >= 0 && n <= 9, file = ok && !sx ? mediaFile(q('proj'), q('id'), q('agent')) : null;
1498
- const im = !ok ? null : q('proj') === '_demo' ? require('./demo.js').picture(q('tool'), n) : sx ? (sx.image ? guard(() => sx.image(q('id'), q('tool'), n, user), null) : null) : file && toolImage(file, q('tool'), n, user); // a Codex session: from its rollout, plain or compressed (codex.js)
1572
+ const im = !ok ? null : q('proj') === '_demo' ? require('./demo.js').picture(q('tool'), n) : sx ? (sx.image ? guard(() => sx.image(q('id'), q('tool'), n, user, q('agent') || 'main'), null) : null) : file && toolImage(file, q('tool'), n, user); // a Codex session: from the lead or the specified child rollout, plain or compressed
1499
1573
  if (!im) { res.writeHead(bad ? 400 : 404); return res.end(bad ? 'bad request' : 'not found'); }
1500
1574
  res.writeHead(200, { 'content-type': im.type, 'content-length': im.buf.length, 'cache-control': 'private, max-age=3600', 'x-content-type-options': 'nosniff' }); return res.end(im.buf);
1501
1575
  }
@@ -1527,10 +1601,10 @@ function start(port = PORT) {
1527
1601
  res.writeHead(200, { 'content-type': 'application/json', ...(gz ? { 'content-encoding': 'gzip' } : {}), vary: 'accept-encoding' });
1528
1602
  return res.end(gz ? entry.gz : entry.json);
1529
1603
  }
1530
- 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
1604
+ if (ep == null) return json({ id: tl.id, project: tl.project, agents: tl.agents, total: tl.events.length, events: tl.events.slice(+after) }); // a page loaded before 1.25.7 still asks by position
1531
1605
  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
1532
- 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
1533
- 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
1606
+ if (a === tl.seq) { if (!entry.idle) entry.idle = JSON.stringify({ id: tl.id, project: tl.project, 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
1607
+ return json({ id: tl.id, project: tl.project, 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
1534
1608
  }
1535
1609
  const pk = url.pathname.match(/^\/packs\/([a-z]+)\/(.*)$/);
1536
1610
  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
@@ -1548,7 +1622,7 @@ function start(port = PORT) {
1548
1622
  } catch (e) { logError(req.method + ' ' + url.pathname, e); if (res.headersSent) return res.destroy(); json({ error: String(e.message || e) }, 500); }
1549
1623
  }).listen(port, '127.0.0.1', function () { console.log(`Agent Standup → http://localhost:${this.address().port}`); });
1550
1624
  }
1551
- module.exports = { answerIn, missingTranscripts, 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 } };
1625
+ module.exports = { answerIn, missingTranscripts, noteEditor, forgetEditor, _winArg: winArg, start, currentSession, shutdown, findClaude, bundledClaude, boardRows, transcriptFile: (proj, id) => path.join(projDir(proj, id), id + '.jsonl'), sessionRows: listSessions, charactersDir, listCharacters, packsDir, installPack, logError, updateInfo, _reveal: reveal, _scrub: { tidy, homeRe }, _artifact: { page: artifactPage, csp: artifactCsp } };
1552
1626
  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
1553
1627
  const srv = start(+process.env.PORT || 0), tell = (m) => { try { process.send(m); } catch {} };
1554
1628
  srv.on('listening', () => tell({ port: srv.address().port })).on('error', (e) => { tell({ error: e.code || String(e) }); process.exit(1); });