@double_geste/agent-standup 1.32.0 → 1.33.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.
@@ -174,9 +174,7 @@
174
174
  "Characters": "角色",
175
175
  "Reload": "重新加载",
176
176
  "Open folder": "打开文件夹",
177
- "custom character(s) loaded": "个自定义角色已加载",
178
177
  "Demo": "演示",
179
- "Drop your pixel art (PNG) in this folder to replace the characters:": "把你的像素画(PNG)放进此文件夹即可替换角色:",
180
178
  "lead.png = the lead · you.png = you · others = the sub-agents · name-talk.png = open mouth": "lead.png = 主代理 · you.png = 你 · 其他 = 子代理 · name-talk.png = 张嘴",
181
179
  "Downloading, you can carry on: the agents babble meanwhile.": "正在下载,你可以继续:在此期间代理会用咿呀语说话。",
182
180
  "Good-quality local voices, in English. Free, nothing leaves your machine.": "高质量的本地语音,仅英语。免费,数据不会离开你的电脑。",
@@ -257,5 +255,54 @@
257
255
  "Mark as done": "标记为已处理",
258
256
  "Open the pull request": "打开拉取请求",
259
257
  "Reopen": "重新打开",
260
- "Pinned: click to unpin": "已固定:点击以取消固定"
258
+ "Pinned: click to unpin": "已固定:点击以取消固定",
259
+ "Halloween pack": "万圣节包",
260
+ "This code is not valid.": "此代码无效。",
261
+ "This purchase was refunded.": "此购买已退款。",
262
+ "This payment is not complete yet.": "此付款尚未完成。",
263
+ "The shop is not open yet.": "商店尚未开放。",
264
+ "The shop cannot be reached. Check your connection and try again.": "无法连接商店。请检查网络连接后重试。",
265
+ "Hand-drawn Halloween characters, each in its own room.": "手绘万圣节角色,每个角色都有自己的房间。",
266
+ "One payment, by card, on a Stripe page. No account.": "在 Stripe 页面用银行卡一次性付款。无需账户。",
267
+ "Buy": "购买",
268
+ "I already bought it": "我已购买",
269
+ "Purchase code": "购买代码",
270
+ "Opening the payment page…": "正在打开付款页面…",
271
+ "Waiting for the payment. The pack installs by itself once it is paid.": "正在等待付款。付款完成后,角色包会自动安装。",
272
+ "Your purchase code, to install the pack on another computer:": "您的购买代码,用于在另一台电脑上安装角色包:",
273
+ "Update the pack": "更新角色包",
274
+ "Add pictures": "添加图片",
275
+ "characters": "个角色",
276
+ "Choose a picture": "选择图片",
277
+ "Free, from the Halloween pack": "免费,来自万圣节角色包",
278
+ "Hand-drawn, each in its own room": "手绘,每个角色都有自己的房间",
279
+ "Like the cast": "和团队一样",
280
+ "No picture yet.": "还没有图片。",
281
+ "Open mouth (optional)": "张嘴的图片(可选)",
282
+ "Remove": "移除",
283
+ "See the pack": "查看角色包",
284
+ "Sub-agent": "子代理",
285
+ "Sub-agents": "子代理",
286
+ "The app’s own": "应用自带",
287
+ "The cast": "团队",
288
+ "The drawn character": "绘制的角色",
289
+ "The vampire": "吸血鬼",
290
+ "This Halloween, you are the vampire. The rest of the cast is in the Halloween pack.": "这个万圣节,你就是吸血鬼。团队的其他成员在万圣节角色包里。",
291
+ "This picture could not be added: PNG, GIF, WebP or JPEG, up to 300 KB.": "无法添加此图片:仅限 PNG、GIF、WebP 或 JPEG,最大 300 KB。",
292
+ "You: like the cast": "你:和团队一样",
293
+ "You: the vampire": "你:吸血鬼",
294
+ "Your own pictures": "你自己的图片",
295
+ "Your pictures are in this folder:": "你的图片在这个文件夹里:",
296
+ "Yours": "已拥有",
297
+ "character": "个角色",
298
+ "Drawn by": "绘制:",
299
+ "⚙ All settings (display, alerts…)": "⚙ 全部设置(显示、提醒…)",
300
+ "All settings": "全部设置",
301
+ "More": "更多",
302
+ "Sound and alerts": "声音与提醒",
303
+ "Click again to reset them all": "再点一次即可全部重置",
304
+ "Got it": "知道了",
305
+ "Reset to defaults": "恢复默认设置",
306
+ "Your settings moved: the everyday ones are here, the rest in “All settings”.": "设置换了位置:常用的在这里,其余的在“全部设置”里。",
307
+ "2 € minimum: you can pay more on the payment page if you like.": "最低 2 欧元:如果愿意,可以在付款页面多付一些。"
261
308
  }
@@ -59,9 +59,7 @@
59
59
  "Characters": "角色",
60
60
  "Reload": "重新載入",
61
61
  "Open folder": "開啟資料夾",
62
- "custom character(s) loaded": "個自訂角色已載入",
63
62
  "Demo": "示範",
64
- "Drop your pixel art (PNG) in this folder to replace the characters:": "把你的像素畫(PNG)放進此資料夾即可替換角色:",
65
63
  "lead.png = the lead · you.png = you · others = the sub-agents · name-talk.png = open mouth": "lead.png = 主代理 · you.png = 你 · 其他 = 子代理 · name-talk.png = 張嘴畫面",
66
64
  "failing in a loop?": "卡在失敗迴圈?",
67
65
  "Fetching ": "擷取 ",
@@ -257,5 +255,54 @@
257
255
  "Mark as done": "標記為已處理",
258
256
  "Open the pull request": "開啟拉取請求",
259
257
  "Reopen": "重新開啟",
260
- "Pinned: click to unpin": "已固定:點擊以取消固定"
258
+ "Pinned: click to unpin": "已固定:點擊以取消固定",
259
+ "Halloween pack": "萬聖節包",
260
+ "This code is not valid.": "此代碼無效。",
261
+ "This purchase was refunded.": "此購買已退款。",
262
+ "This payment is not complete yet.": "此付款尚未完成。",
263
+ "The shop is not open yet.": "商店尚未開放。",
264
+ "The shop cannot be reached. Check your connection and try again.": "無法連線到商店。請檢查網路連線後再試一次。",
265
+ "Hand-drawn Halloween characters, each in its own room.": "手繪萬聖節角色,每個角色都有自己的房間。",
266
+ "One payment, by card, on a Stripe page. No account.": "在 Stripe 頁面以信用卡一次付清。不需要帳戶。",
267
+ "Buy": "購買",
268
+ "I already bought it": "我已購買",
269
+ "Purchase code": "購買代碼",
270
+ "Opening the payment page…": "正在開啟付款頁面…",
271
+ "Waiting for the payment. The pack installs by itself once it is paid.": "正在等待付款。付款完成後,角色包會自動安裝。",
272
+ "Your purchase code, to install the pack on another computer:": "您的購買代碼,用於在另一台電腦上安裝角色包:",
273
+ "Update the pack": "更新角色包",
274
+ "Add pictures": "新增圖片",
275
+ "characters": "個角色",
276
+ "Choose a picture": "選擇圖片",
277
+ "Free, from the Halloween pack": "免費,來自萬聖節角色包",
278
+ "Hand-drawn, each in its own room": "手繪,每個角色都有自己的房間",
279
+ "Like the cast": "和團隊一樣",
280
+ "No picture yet.": "還沒有圖片。",
281
+ "Open mouth (optional)": "張嘴的圖片(選用)",
282
+ "Remove": "移除",
283
+ "See the pack": "查看角色包",
284
+ "Sub-agent": "子代理",
285
+ "Sub-agents": "子代理",
286
+ "The app’s own": "應用程式內建",
287
+ "The cast": "團隊",
288
+ "The drawn character": "繪製的角色",
289
+ "The vampire": "吸血鬼",
290
+ "This Halloween, you are the vampire. The rest of the cast is in the Halloween pack.": "這個萬聖節,你就是吸血鬼。團隊的其他成員在萬聖節角色包裡。",
291
+ "This picture could not be added: PNG, GIF, WebP or JPEG, up to 300 KB.": "無法新增此圖片:僅限 PNG、GIF、WebP 或 JPEG,最大 300 KB。",
292
+ "You: like the cast": "你:和團隊一樣",
293
+ "You: the vampire": "你:吸血鬼",
294
+ "Your own pictures": "你自己的圖片",
295
+ "Your pictures are in this folder:": "你的圖片在這個資料夾裡:",
296
+ "Yours": "已擁有",
297
+ "character": "個角色",
298
+ "Drawn by": "繪製:",
299
+ "⚙ All settings (display, alerts…)": "⚙ 全部設定(顯示、提醒…)",
300
+ "All settings": "全部設定",
301
+ "More": "更多",
302
+ "Sound and alerts": "聲音與提醒",
303
+ "Click again to reset them all": "再按一次即可全部重設",
304
+ "Got it": "知道了",
305
+ "Reset to defaults": "恢復預設設定",
306
+ "Your settings moved: the everyday ones are here, the rest in “All settings”.": "設定換了位置:常用的在這裡,其餘的在「全部設定」裡。",
307
+ "2 € minimum: you can pay more on the payment page if you like.": "最低 2 歐元:如果願意,可以在付款頁面多付一些。"
261
308
  }
Binary file
package/server.js CHANGED
@@ -364,7 +364,7 @@ function boardRows0() {
364
364
  }
365
365
  rows.sort((a, b) => b.st.mtimeMs - a.st.mtimeMs);
366
366
  return rows.filter((r) => !r.cx && r.proj !== COWORK).slice(0, 40).concat(...SOURCES.map((m) => rows.filter((r) => r.src === m).slice(0, 20)), rows.filter((r) => r.proj === COWORK).slice(0, 20)).sort((a, b) => b.st.mtimeMs - a.st.mtimeMs).map(({ proj, id, st, cx, src }) => {
367
- if (cx) return guard(() => src.boardRow(cx, now), null);
367
+ 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)
368
368
  const file = path.join(projDir(proj, id), id + '.jsonl'); let p; try { p = parseTail(file, st); } catch { p = { pending: [] }; }
369
369
  const age = now - st.mtimeMs, lp = (p.pending || [])[(p.pending || []).length - 1]; let state = 'idle', tool = '', ageMs = age;
370
370
  if (age < 30 * 60e3) {
@@ -377,7 +377,7 @@ function boardRows0() {
377
377
  }
378
378
  let subActive = 0, subTotal = 0;
379
379
  for (const x of subFiles(proj, id)) { subTotal++; if (now - mtimeOf(x.file) < 90e3) subActive++; }
380
- return { proj, id, title: coworkTitle(proj, id) || p.title || id, mtime: st.mtimeMs, state, tool, ageMs, subActive, subTotal, asked: p.asked || 0, ...(p.pr ? { pr: p.pr } : {}), ...(state === 'blocked' && lp && lp.q ? { ask: lp.q } : {}), ...(p.esc ? { cut: 1 } : {}) }; // cut: stopped by you, which is no news to tell you
380
+ return { proj, id, title: coworkTitle(proj, id) || p.title || id, mtime: st.mtimeMs, state, tool, ageMs, subActive, subTotal, asked: p.asked || 0, ...(p.pr ? { pr: p.pr } : {}), ...(state === 'blocked' && lp && lp.q ? { ask: lp.q } : {}), ...(p.esc ? { cut: 1 } : {}), ...(tmpKey(proj) ? { tmp: 1 } : {}) }; // cut: stopped by you, which is no news to tell you
381
381
  }).filter(Boolean);
382
382
  }
383
383
  // 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).
@@ -447,15 +447,21 @@ process.on('uncaughtExceptionMonitor', (e, origin) => { try { if (OWN || String(
447
447
  // One exception, so that the call is not left on an empty room: when the session you last typed in has finished and been quiet for STICK_MS while another one is at work, the call
448
448
  // goes to that one. A session you went to by hand is not left that way.
449
449
  const STICK_MS = 90000;
450
+ // Sessions started in the system's temporary folder: a program running Claude Code there for a moment (a test, a script, a tool that makes a folder per run), not a session someone works in.
451
+ // When the call looks everywhere it leaves them out, unless there is nothing else; they have no tab then and send no visitor. They stay in the Sessions view, and a window open on such a folder follows it.
452
+ // macOS: /var/folders/… (/private/… once resolved) and /tmp; Linux: /tmp; Windows: …\AppData\Local\Temp; and wherever TMPDIR points. A key is a folder as Claude Code names it, every other character a "-".
453
+ const TMP_KEYS = [...new Set([os.tmpdir(), (() => { try { return fs.realpathSync(os.tmpdir()); } catch { return ''; } })()].filter((d) => d && d.length > 4).map((d) => d.replace(/[^a-zA-Z0-9]/g, '-')))];
454
+ const tmpKey = (k) => !!k && (/^-(private-)?(tmp|var-folders)(-|$)/.test(k) || /-AppData-Local-Temp(-|$)/i.test(k) || TMP_KEYS.some((t) => k === t || k.startsWith(t + '-')));
455
+ const tmpSession = (proj, id) => { const sx = sourceOf(proj); return sx ? tmpKey(String(guard(() => sx.cwd(id), '') || '').replace(/[^a-zA-Z0-9]/g, '-')) : tmpKey(proj); }; // a Codex or Vibe session: the folder it was started in
450
456
  function sessionMtime(proj, id) {
451
457
  const sx = sourceOf(proj), r = sx ? guard(() => sx.row(id), null) : null; if (sx && (!r || !sx.subFiles)) return r ? r.mtime : 0;
452
458
  let m = sx ? r.mtime : mtimeOf(path.join(projDir(proj, id), id + '.jsonl')); if (!m) return 0; const subs = subFilesOf(proj, id);
453
459
  for (const x of subs) m = Math.max(m, mtimeOf(x.file)); for (const d of subs.dirs) m = Math.max(m, mtimeOf(d)); return m; // the folders too: a new file in them is activity, as when every file around the transcripts was looked at
454
460
  }
455
- function currentSession(projFilter, pick, stick) { // pick: { proj, id, since } the session you went to by hand, and the latest order there was then · stick: the session the call is in
461
+ function currentSession(projFilter, pick, stick, anyTmp) { // pick: { proj, id, since } the session you went to by hand, and the latest order there was then · stick: the session the call is in · anyTmp: sessions in the temporary folder count too (see tmpKey)
456
462
  const safe = (x) => typeof x === 'string' && /^[\w.\-]+$/.test(x) && x !== '..', now = Date.now();
457
463
  const there = (c) => !!c && safe(c.id) && safe(c.proj) && (sourceOf(c.proj) ? !!guard(() => sourceOf(c.proj).fileOf(c.id), null) : fs.existsSync(path.join(projDir(c.proj, c.id), c.id + '.jsonl')));
458
- const inScope = (c) => !projFilter || c.proj === projFilter || c.proj.startsWith(projFilter + '-') || !!(sourceOf(c.proj) && guard(() => sourceOf(c.proj).inProject(c.id, projFilter), false)); // a Codex or Vibe session counts for a project when it was started in that folder
464
+ const inScope = (c) => (!projFilter ? anyTmp || !tmpSession(c.proj, c.id) : c.proj === projFilter || c.proj.startsWith(projFilter + '-') || !!(sourceOf(c.proj) && guard(() => sourceOf(c.proj).inProject(c.id, projFilter), false))); // a Codex or Vibe session counts for a project when it was started in that folder
459
465
  const same = (a, b) => !!a && !!b && a.proj === b.proj && a.id === b.id, all = boardRows(), rows = all.filter(inScope), mine = there(pick) ? all.find((r) => same(r, pick)) : null;
460
466
  const asked = Math.max(0, (mine && mine.asked) || 0, ...rows.map((r) => r.asked || 0)); // the latest order, in the folder the call follows or in the session you went to
461
467
  const moved = pick && pick.pin ? Math.max(0, ...rows.filter((r) => !same(r, pick)).map((r) => r.asked || 0)) : asked; // pick.pin: a call pinned by a click on its tab (📌) is left for an order typed in another session only; what you type in it keeps it there
@@ -468,10 +474,11 @@ function currentSession(projFilter, pick, stick) { // pick: { proj, id, since
468
474
  const consider = (proj, id, m) => { if (!best || m > best.mtime) best = { proj, id, mtime: m }; };
469
475
  for (const m of SOURCES) for (const r of guard(() => m.sessions(), [])) if (inScope({ proj: m.PROJ, id: r.id })) consider(m.PROJ, r.id, r.mtime);
470
476
  for (const proj of projects()) {
471
- if (projFilter && proj !== projFilter && !proj.startsWith(projFilter + '-')) continue; // the folder itself, or a folder inside it (a Cowork session is in no folder of yours: it counts when the call looks everywhere, or at Cowork)
477
+ if (projFilter ? proj !== projFilter && !proj.startsWith(projFilter + '-') : !anyTmp && tmpKey(proj)) continue; // the folder itself, or a folder inside it (a Cowork session is in no folder of yours: it counts when the call looks everywhere, or at Cowork)
472
478
  for (const { id } of transcripts(proj)) { const m = sessionMtime(proj, id); if (m) consider(proj, id, m); } // 0: a link to a transcript that is gone
473
479
  }
474
- if (!best && projFilter) return { ...currentSession('', null, stick), wide: 1 }; // nothing in that folder (an editor open on another one than the sessions): the latest of anywhere, and the page is told, so its tabs follow the same rule
480
+ if (!best && projFilter) return { ...currentSession('', null, stick), wide: 1 };
481
+ if (!best && !projFilter && !anyTmp) return currentSession('', pick, stick, true); // nothing but sessions in the temporary folder: one of them rather than an empty call // nothing in that folder (an editor open on another one than the sessions): the latest of anywhere, and the page is told, so its tabs follow the same rule
475
482
  return best ? { ...best, asked } : {}; // a call that is opened while nobody is at work: the session that was written to last
476
483
  }
477
484
 
@@ -806,19 +813,103 @@ const MIME = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css
806
813
 
807
814
  // ---- Custom characters: the person's own pixel art replaces the drawn characters. Plain image files in one folder, nothing else is ever served from it.
808
815
  // lead.png / claude.png → the lead · you.png → the human · any other image → a pool for the sub-agents · name-talk.png → optional open-mouth frame of name.png
809
- const CHAR_NAME = /^[\w][\w .()\-]{0,78}\.(png|gif|webp|jpe?g)$/i, CHAR_MAX = 300 * 1024, CHAR_TYPES = { png: 'image/png', gif: 'image/gif', webp: 'image/webp', jpg: 'image/jpeg', jpeg: 'image/jpeg' };
816
+ // name-bg.png → optional room of name.png: the whole picture behind it, desk included (its bottom sixth is drawn again in front of the character)
817
+ // name-head.png → optional head of name.png, drawn above it and nodding while it speaks: name.png is then the body, and name-talk.png the head with its mouth open
818
+ // name-hands.png → optional hands of name.png, on their own: they type while the agent works · name-desk.png, name-desk-dark.png… → optional laptops of name.png, drawn over its hands:
819
+ // the page gives each agent one of them, out now and then for a few seconds (all the time with ⚙ → Characters → laptop)
820
+ // name+hat-1.png, name+hat-2.png, name+glasses-1.png… → optional extras of name.png, by kind (the word after the +): pictures drawn over it. Each agent that gets this character wears one of each kind or none,
821
+ // so one character becomes many: it is the one given again when there are more agents than characters
822
+ // an extra whose kind starts with "sticker" (name+sticker1-2.png) is worn by the thing on the desk, not by the character: drawn over the laptop, under the hands
823
+ const CHAR_NAME = /^[\w][\w .()+\-]{0,78}\.(png|gif|webp|jpe?g)$/i, CHAR_MAX = 300 * 1024, CHAR_TYPES = { png: 'image/png', gif: 'image/gif', webp: 'image/webp', jpg: 'image/jpeg', jpeg: 'image/jpeg' };
810
824
  const charactersDir = () => process.env.AGENT_STANDUP_CHARACTERS || path.join(os.homedir(), '.agent-standup', 'characters');
811
825
  // lstat, not stat: a symlink is not a regular file, so it is skipped and never served
812
826
  // Built-in character packs, shipped with the app (examples/<folder>): picked in ⚙ → Characters. examples/characters stays in the repository as a model for one's own folder; it is not shipped
813
- const PACKS = { cats: 'cats' }, packDir = (name) => (Object.prototype.hasOwnProperty.call(PACKS, name) ? path.join(__dirname, 'examples', PACKS[name]) : null); // its own names only: 'constructor' or 'toString' is not a pack (they answered 500)
827
+ const PACKS = { cats: 'cats', vampire: 'vampire' }; // vampire: the one character of the Halloween pack that everyone gets, as the human (see the page's charYou)
828
+ // Packs sold in the shop of the website (api/ in the repository): their pictures are neither in the app nor in the repository. A bought pack is unpacked in the packs folder and is then a pack like a built-in one.
829
+ const SHOP_PACKS = { halloween: { price: '2 €', artist: 'Fabien Coupas', artistUrl: 'https://www.instagram.com/fabien_coupas/' } }, // the artist is credited wherever the pack is shown
830
+ PACK_MAX = 20 * 1024 * 1024;
831
+ const shopUrl = () => (process.env.AGENT_STANDUP_STORE || 'https://agent-standup.com').replace(/\/+$/, ''), packsDir = () => process.env.AGENT_STANDUP_PACKS || path.join(os.homedir(), '.agent-standup', 'packs');
832
+ const hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k); // its own names only: 'constructor' or 'toString' is not a pack (they answered 500)
833
+ const packDir = (name) => (hasOwn(PACKS, name) ? path.join(__dirname, 'examples', PACKS[name]) : hasOwn(SHOP_PACKS, name) ? path.join(packsDir(), name) : null);
814
834
  function listCharacters(pack) {
815
835
  const dir = pack ? packDir(pack) : charactersDir(); let names = []; if (!dir) return { dir: '', max: CHAR_MAX, chars: [] }; try { names = fs.readdirSync(dir); } catch {}
816
- const ok = names.filter((f) => CHAR_NAME.test(f)).filter((f) => { try { const st = fs.lstatSync(path.join(dir, f)); return st.isFile() && st.size <= CHAR_MAX; } catch { return false; } }).slice(0, 80);
836
+ const ok = names.filter((f) => CHAR_NAME.test(f)).filter((f) => { try { const st = fs.lstatSync(path.join(dir, f)); return st.isFile() && st.size <= CHAR_MAX; } catch { return false; } }).sort().slice(0, 200);
817
837
  const stem = (f) => f.replace(/\.[^.]+$/, ''), by = new Map(ok.map((f) => [stem(f).toLowerCase(), f]));
818
- const chars = ok.filter((f) => !/-talk$/i.test(stem(f))).map((f) => { const st = stem(f), l = st.toLowerCase();
819
- return { stem: st, file: f, talk: by.get(l + '-talk') || null, role: /^(lead|claude)$/.test(l) ? 'lead' : /^(you|human|user)$/.test(l) ? 'you' : 'agent' }; }).sort((a, b) => a.stem.localeCompare(b.stem));
838
+ const extra = (f) => stem(f).match(/^(.+)\+([a-z]+\d*)[-_ ]?\w*$/i); // the kind may end with a number: sticker1, sticker2… are kinds of their own
839
+ const layer = (f) => { const m = stem(f).match(/^(.+)-(bg|head|hands|desk(-\w+)?)$/i); return !!(m && by.has(m[1].toLowerCase())); }; // a layer only when its character is there: help-desk.png alone is a character
840
+ const chars = ok.filter((f) => !/-talk$/i.test(stem(f)) && !layer(f) && !extra(f)).map((f) => { const st = stem(f), l = st.toLowerCase(), extras = {};
841
+ for (const x of ok) { const m = extra(x), k = m && m[1].toLowerCase() === l ? m[2].toLowerCase() : ''; if (k) (extras[k] = extras[k] || []).push(x); }
842
+ return { stem: st, file: f, talk: by.get(l + '-talk') || null, bg: by.get(l + '-bg') || null, desks: ok.filter((x) => { const s = stem(x).toLowerCase(); return s === l + '-desk' || s.startsWith(l + '-desk-'); }), head: by.get(l + '-head') || null, hands: by.get(l + '-hands') || null, extras: Object.keys(extras).length ? extras : null, role: /^(lead|claude)$/.test(l) ? 'lead' : /^(you|human|user)$/.test(l) ? 'you' : 'agent' }; }).sort((a, b) => a.stem.localeCompare(b.stem));
820
843
  return { dir, max: CHAR_MAX, chars };
821
844
  }
845
+ // ---- Buying a pack. The app never sees a card: it asks the shop for a payment page (Stripe's), opens it in the browser, then asks the shop for the pack with the code of that purchase until the shop,
846
+ // which asks Stripe, says it is paid. The code is kept beside the packs: it is the proof of the purchase, and what installs the pack on another computer. Nothing else is sent, and nothing is asked again once the pack is here.
847
+ const codesFile = () => path.join(packsDir(), 'codes.json');
848
+ const readCodes = () => { try { const v = JSON.parse(fs.readFileSync(codesFile(), 'utf8')); return v && typeof v === 'object' && !Array.isArray(v) ? v : {}; } catch { return {}; } };
849
+ const writeCode = (name, v) => { const all = readCodes(); all[name] = v; fs.mkdirSync(packsDir(), { recursive: true }); const tmp = codesFile() + '.' + process.pid + '.tmp'; fs.writeFileSync(tmp, JSON.stringify(all, null, 1), { mode: 0o600 }); fs.renameSync(tmp, codesFile()); };
850
+ const packList = () => [...Object.keys(PACKS).map((name) => ({ name, n: listCharacters(name).chars.length })),
851
+ ...Object.keys(SHOP_PACKS).map((name) => { const c = readCodes()[name] || {}; return { name, n: listCharacters(name).chars.length, shop: true, price: SHOP_PACKS[name].price, artist: SHOP_PACKS[name].artist || '', artistUrl: SHOP_PACKS[name].artistUrl || '', code: c.short || c.code || '', waiting: !!(c.pending && c.pending.length) }; })]; // the code shown is the one for people when there is one
852
+ // A pack arrives as a zip of plain image files, read here without a library: stored or deflated entries only, kept under their bare name and only if a characters folder would accept that name, each within the size of a character.
853
+ function unzipImages(buf) {
854
+ let e = buf.length - 22; while (e >= 0 && buf.readUInt32LE(e) !== 0x06054b50) e--; if (e < 0) throw new Error('not a zip');
855
+ const n = buf.readUInt16LE(e + 10), out = []; let p = buf.readUInt32LE(e + 16); if (n > 400) throw new Error('too many files');
856
+ for (let i = 0; i < n; i++) {
857
+ if (p + 46 > buf.length || buf.readUInt32LE(p) !== 0x02014b50) throw new Error('bad zip');
858
+ const method = buf.readUInt16LE(p + 10), csize = buf.readUInt32LE(p + 20), size = buf.readUInt32LE(p + 24), nl = buf.readUInt16LE(p + 28), off = buf.readUInt32LE(p + 42), name = buf.toString('utf8', p + 46, p + 46 + nl).split(/[\\/]/).pop();
859
+ p += 46 + nl + buf.readUInt16LE(p + 30) + buf.readUInt16LE(p + 32);
860
+ const note = /^(LICEN[CS]E|README)\.txt$/i.test(name); if (!note && !CHAR_NAME.test(name)) continue; // a folder, a hidden file, anything that is not a picture or the pack's two notes: left out
861
+ if (size > (note ? 65536 : CHAR_MAX) || off + 30 > buf.length) throw new Error('bad entry: ' + name);
862
+ const from = off + 30 + buf.readUInt16LE(off + 26) + buf.readUInt16LE(off + 28), raw = buf.subarray(from, from + csize);
863
+ const data = method === 0 ? raw : method === 8 ? zlib.inflateRawSync(raw, { maxOutputLength: CHAR_MAX }) : null; if (!data || data.length !== size) throw new Error('bad entry: ' + name);
864
+ if (!out.some((f) => f.name.toLowerCase() === name.toLowerCase())) out.push({ name, data });
865
+ }
866
+ if (!out.some((f) => CHAR_NAME.test(f.name))) throw new Error('no picture in the pack');
867
+ return out.slice(0, 200);
868
+ }
869
+ // ---- Pictures added from the page (⚙ → Characters → My folder): written in the characters folder under the name of their role, or under their own name for a sub-agent.
870
+ // The picture a new one replaces is moved to a "replaced" folder beside it, never deleted, and nothing but the four image types is written.
871
+ const IMG_MAGIC = [['png', (b) => b.length > 8 && b.readUInt32BE(0) === 0x89504e47], ['gif', (b) => b.toString('latin1', 0, 4) === 'GIF8'], ['webp', (b) => b.toString('latin1', 0, 4) === 'RIFF' && b.toString('latin1', 8, 12) === 'WEBP'], ['jpg', (b) => b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff]];
872
+ const ROLE_FILES = { you: 'you', 'you-talk': 'you-talk', lead: 'lead', 'lead-talk': 'lead-talk' };
873
+ function putAside(dir, stem) { // the pictures of this name, whatever their type, go to dir/replaced/ under a name that says when
874
+ let names = []; try { names = fs.readdirSync(dir); } catch {} const stamp = new Date().toISOString().replace(/[:.]/g, '-');
875
+ for (const f of names) if (CHAR_NAME.test(f) && f.replace(/\.[^.]+$/, '').toLowerCase() === stem) { fs.mkdirSync(path.join(dir, 'replaced'), { recursive: true }); fs.renameSync(path.join(dir, f), path.join(dir, 'replaced', stamp + ' ' + f)); }
876
+ }
877
+ function addCharacter(role, name, b64) { // → { file } or throws a word the page can say: 'type', 'size', 'name'
878
+ const data = Buffer.from(String(b64 || ''), 'base64'), type = (IMG_MAGIC.find(([, ok]) => ok(data)) || [])[0]; if (!type) throw Object.assign(new Error('type'), { word: 'type' }); if (data.length > CHAR_MAX) throw Object.assign(new Error('size'), { word: 'size' });
879
+ const dir = charactersDir(); fs.mkdirSync(dir, { recursive: true });
880
+ let stem = ROLE_FILES[role]; if (!stem) { stem = String(name || '').replace(/\.[^.]*$/, '').replace(/[^\w .()\-]+/g, ' ').trim().slice(0, 60).replace(/^[^\w]+/, '') || 'agent'; if (/^(lead|claude|you|human|user)(-talk)?$/i.test(stem) || /-(talk|bg|head|hands|desk(-\w+)?)$/i.test(stem)) stem += ' 2'; } // a sub-agent never takes the name of a role
881
+ const file = stem + '.' + type; if (!CHAR_NAME.test(file)) throw Object.assign(new Error('name'), { word: 'name' });
882
+ if (!ROLE_FILES[role]) { let k = 2, f = file; while (fs.existsSync(path.join(dir, f))) f = `${stem} ${k++}.${type}`; fs.writeFileSync(path.join(dir, f), data); return { file: f }; } // a sub-agent's picture never replaces another one
883
+ putAside(dir, stem.toLowerCase()); if (!/-talk$/.test(stem)) for (const s of ['-talk', '-head', '-hands', '-bg', '-desk', '-desk-dark']) putAside(dir, stem + s); // a new face: the old open mouth and layers go aside with the old picture
884
+ fs.writeFileSync(path.join(dir, file), data); return { file };
885
+ }
886
+ function removeCharacter(file) { // moved to replaced/, with its open mouth and its room; only a picture the folder lists
887
+ const f = String(file || ''), dir = charactersDir(); if (!CHAR_NAME.test(f) || !listCharacters('').chars.some((c) => c.file === f)) return false;
888
+ const stem = f.replace(/\.[^.]+$/, '').toLowerCase(); for (const s of [stem, stem + '-talk', stem + '-head', stem + '-bg', stem + '-desk', stem + '-desk-dark', stem + '-hands']) putAside(dir, s); return true;
889
+ }
890
+ function installPack(name, zip) { // written beside its place first, then swapped in: a pack is never half there
891
+ const files = unzipImages(zip), dir = packDir(name), tmp = dir + '.' + process.pid + '.tmp'; fs.rmSync(tmp, { recursive: true, force: true }); fs.mkdirSync(tmp, { recursive: true });
892
+ for (const f of files) fs.writeFileSync(path.join(tmp, f.name), f.data); fs.rmSync(dir, { recursive: true, force: true }); fs.renameSync(tmp, dir);
893
+ }
894
+ const askShop = (p, body) => fetch(shopUrl() + p, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body), signal: AbortSignal.timeout(30000) });
895
+ async function buyPack(name) { // → { status, url } the payment page to open, or { status, error }
896
+ let r; try { r = await askShop('/api/checkout', { pack: name }); } catch { return { status: 502, error: 'offline' }; }
897
+ const j = await r.json().catch(() => ({})); if (!r.ok) return { status: r.status, error: j.error || 'shop' };
898
+ if (typeof j.url !== 'string' || typeof j.code !== 'string' || !/^(https:\/\/|http:\/\/localhost[:/])/.test(j.url)) return { status: 502, error: 'shop' };
899
+ const c = readCodes()[name] || {}, pending = [j.code, ...(c.pending || [])].slice(0, 5), short = typeof j.short === 'string' && /^[A-Z]{2}-[\w-]{9}$/.test(j.short) ? j.short : '';
900
+ writeCode(name, { code: c.code || '', short: c.short || '', pending, shorts: Object.fromEntries(pending.map((k) => [k, k === j.code ? short : (c.shorts || {})[k] || ''])) }); return { status: 200, url: j.url }; // shorts: the code for people (HW-…) of each payment page opened // a few, in case the button was pressed more than once: any of them may be the one that gets paid
901
+ }
902
+ async function claimPack(name, typed) { // typed: a code the person pastes (another computer); else the purchases started here
903
+ const c = readCodes()[name] || {}, tries = typed ? [typed] : [c.code, ...(c.pending || [])].filter(Boolean); if (!tries.length) return { status: 400, error: 'code' };
904
+ let last = { status: 402, error: 'unpaid' };
905
+ for (const code of tries) {
906
+ let r; try { r = await askShop('/api/pack', { pack: name, code }); } catch { return { status: 502, error: 'offline' }; }
907
+ if (r.ok) { const zip = Buffer.from(await r.arrayBuffer()); if (zip.length > PACK_MAX) return { status: 502, error: 'shop' }; try { installPack(name, zip); } catch (e) { logError('pack ' + name, e); return { status: 502, error: 'shop' }; }
908
+ writeCode(name, { code, short: (c.shorts || {})[code] || (/^[A-Z]{2}-/i.test(code) ? code.toUpperCase() : c.short || ''), pending: [] }); return { status: 200, ok: true, n: listCharacters(name).chars.length }; }
909
+ last = { status: r.status, error: (await r.json().catch(() => ({}))).error || 'shop' }; if (r.status !== 402 && r.status !== 404) break; // not paid yet, or not a purchase of this pack: the next one may be; anything else is the shop's trouble
910
+ }
911
+ return last;
912
+ }
822
913
  // ---- Shared files: a file the session created is shown in its folder (Finder, Explorer, the file manager) when the page asks. Only a file a Write call of that very session names, and only if it is still there:
823
914
  // the page cannot have any other path opened, nothing is read and nothing is run. A Codex or Vibe session may name a file from the folder it was started in.
824
915
  // The same goes for a document one of its commands names (an export, a report made by a script), from the moment that command started: an older file by that name is not one of its files.
@@ -856,11 +947,11 @@ function start(port = PORT) {
856
947
  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
857
948
  // 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.
858
949
  const sfs = req.headers['sec-fetch-site'];
859
- 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'].includes(url.pathname))) { res.writeHead(403); return res.end('forbidden'); }
860
- const readBody = (cb) => { // request bodies are small JSON: stop reading beyond 256 KB and give up after 10 s
950
+ 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'); }
951
+ const readBody = (cb, max = 262144) => { // request bodies are small JSON: stop reading beyond 256 KB (or max) and give up after 10 s
861
952
  const chunks = []; let size = 0, over = false; req.setTimeout(10000, () => req.destroy());
862
- if (+req.headers['content-length'] > 262144) { res.writeHead(413); res.end('too large'); return req.destroy(); }
863
- req.on('data', (d) => { if (over) return; size += d.length; if (size > 262144) { over = true; res.writeHead(413); res.end('too large'); req.destroy(); } else chunks.push(d); }); // bytes, not characters
953
+ if (+req.headers['content-length'] > max) { res.writeHead(413); res.end('too large'); return req.destroy(); }
954
+ req.on('data', (d) => { if (over) return; size += d.length; if (size > max) { over = true; res.writeHead(413); res.end('too large'); req.destroy(); } else chunks.push(d); }); // bytes, not characters
864
955
  req.on('end', () => { if (!over) cb(Buffer.concat(chunks).toString('utf8')); });
865
956
  };
866
957
  const textList = (x) => (Array.isArray(x) ? x : []).slice(0, 200).map((t) => String(t).slice(0, 2000));
@@ -901,7 +992,13 @@ function start(port = PORT) {
901
992
  if (url.pathname === '/api/current') { const q = (k) => url.searchParams.get(k) || ''; return json(currentSession(q('proj'), q('pid') ? { proj: q('pproj'), id: q('pid'), since: q('since') ? +q('since') : NaN, pin: q('pin') === '1' } : null, { proj: q('sproj'), id: q('sid') })); }
902
993
  if (url.pathname === '/api/board') return json(boardRows());
903
994
  if (url.pathname === '/api/characters') return json(listCharacters(url.searchParams.get('pack') || ''));
904
- if (url.pathname === '/api/packs') return json(Object.keys(PACKS).map((name) => ({ name, n: listCharacters(name).chars.length })));
995
+ if (url.pathname === '/api/characters/add' && req.method === 'POST') return readBody((body) => { try { const b = JSON.parse(body || '{}') || {}; json(addCharacter(String(b.role || ''), b.name, b.data)); } catch (e) { if (!e.word) logError('add character', e); json({ error: e.word || 'write' }, e.word ? 400 : 500); } }, 512 * 1024); // a picture of 300 KB is 400 KB once written as text
996
+ if (url.pathname === '/api/characters/remove' && req.method === 'POST') return readBody((body) => { let b = {}; try { b = JSON.parse(body || '{}') || {}; } catch {} try { json(removeCharacter(b.file) ? { ok: true } : { error: 'file' }, 200); } catch (e) { logError('remove character', e); json({ error: 'write' }, 500); } });
997
+ if (url.pathname === '/api/packs') return json(packList());
998
+ if ((url.pathname === '/api/packs/buy' || url.pathname === '/api/packs/claim') && req.method === 'POST') return readBody((body) => {
999
+ let b = {}; try { b = JSON.parse(body || '{}') || {}; } catch {} const name = String(b.pack || ''); if (!hasOwn(SHOP_PACKS, name)) return json({ error: 'pack' }, 404);
1000
+ (url.pathname.endsWith('/buy') ? buyPack(name) : claimPack(name, typeof b.code === 'string' ? b.code.trim().slice(0, 260) : '')).then((r) => json(r, r.status), (e) => { logError('shop', e); json({ error: 'shop' }, 500); });
1001
+ });
905
1002
  if (url.pathname === '/api/reveal' && req.method === 'POST') return readBody((body) => { // 404: not a file this session created · 410: created, and no longer there
906
1003
  try {
907
1004
  let b = null; try { b = JSON.parse(body); } catch {} const SAFE = /^[\w.\-]+$/, ok = (v) => typeof v === 'string' && SAFE.test(v) && v !== '..' && v.length <= 200;
@@ -961,7 +1058,7 @@ function start(port = PORT) {
961
1058
  } catch (e) { logError(req.method + ' ' + url.pathname, e); if (res.headersSent) return res.destroy(); json({ error: String(e.message || e) }, 500); }
962
1059
  }).listen(port, '127.0.0.1', function () { console.log(`Agent Standup → http://localhost:${this.address().port}`); });
963
1060
  }
964
- module.exports = { start, currentSession, shutdown, findClaude, bundledClaude, boardRows, sessionRows: listSessions, charactersDir, listCharacters, logError, _reveal: reveal, _scrub: { tidy, homeRe }, _artifact: { page: artifactPage, csp: artifactCsp } };
1061
+ module.exports = { start, currentSession, shutdown, findClaude, bundledClaude, boardRows, sessionRows: listSessions, charactersDir, listCharacters, packsDir, installPack, logError, _reveal: reveal, _scrub: { tidy, homeRe }, _artifact: { page: artifactPage, csp: artifactCsp } };
965
1062
  if (require.main === module) {
966
1063
  start().on('error', (e) => {
967
1064
  console.error(e.code === 'EADDRINUSE' ? `Port ${PORT} is already in use (maybe Agent Standup is already running, e.g. inside VS Code). Try: PORT=4790 node server.js` : String(e));