@double_geste/agent-standup 1.33.0 → 1.35.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/package.json +1 -1
- package/public/index.html +23 -16
- package/public/locales/da.json +1 -0
- package/public/locales/de.json +1 -0
- package/public/locales/en.json +1 -0
- package/public/locales/es.json +1 -0
- package/public/locales/ja.json +1 -0
- package/public/locales/ko.json +1 -0
- package/public/locales/pt-BR.json +1 -0
- package/public/locales/zh-CN.json +1 -0
- package/public/locales/zh-TW.json +1 -0
- package/server.js +99 -31
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@double_geste/agent-standup",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.35.0",
|
|
4
4
|
"description": "Your Claude Code, Codex and Mistral Vibe agents as a live video call, from the terminal: a local page in your browser, plus one-line status for status bars. Free, open source, zero token cost.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"agent-standup": "bin/agent-standup.js"
|
package/public/index.html
CHANGED
|
@@ -1304,7 +1304,7 @@ function syncUI() {
|
|
|
1304
1304
|
// ---------- tool ticker, shared screen, flying messages ----------
|
|
1305
1305
|
// ---------- what each agent is doing: tool calls with their real outputs ----------
|
|
1306
1306
|
S.term = {}; S.todos = {}; S.run = {}; S.act = {}; S.usage = {}; S.errs = {}; S.lastAct = {}; S.waitOn = {}; S.orderTs = {}; S.prevState = {}; S.ctx = {}; S.model = {}; S.cw = {}; S.compacts = {}; S.ctxWarned = {}; S.rep = {}; S.loops = {}; S.present = null; S.camFor = null; let presentTimer = null;
|
|
1307
|
-
S.files = new Map(); S.cands = new Map(); S.turnN = 0; S.turnSaid = ''; S.fgone = new Set(); S.fmade = new Map(); S.arts = new Map(); S.artCalls = new Map(); S.artOk = new Map(); S.artPin = null; // files: path → the Write call that created it, in the order they were written · cands: the documents the commands name (see candFile) · turnN: how many orders you gave so far · turnSaid: what you and the lead said in this turn · fgone: the files found missing on a click · fmade: what the server answered about a document a command names
|
|
1307
|
+
S.files = new Map(); S.cands = new Map(); S.turnN = 0; S.turnSaid = ''; S.fgone = new Set(); S.fmade = new Map(); S.arts = new Map(); S.artCalls = new Map(); S.artOk = new Map(); S.artPin = null; S.artWhole = null; S.wholeSeen = new Set(); // files: path → the Write call that created it, in the order they were written · cands: the documents the commands name (see candFile) · turnN: how many orders you gave so far · turnSaid: what you and the lead said in this turn · fgone: the files found missing on a click · fmade: what the server answered about a document a command names
|
|
1308
1308
|
const later = (k, fn, ms = 160) => { later.p = later.p || {}; if (later.p[k]) return; later.p[k] = setTimeout(() => { later.p[k] = 0; fn(); }, ms); }; // coalesce bursts of repaints
|
|
1309
1309
|
const fmtTok = (n) => (n < 1000 ? String(n) : n < 1e6 ? (n / 1000).toFixed(n < 1e4 ? 1 : 0) + 'k' : (n / 1e6).toFixed(n < 1e7 ? 2 : 1) + 'M');
|
|
1310
1310
|
const tokTotal = (u) => (u ? u.i + u.o + u.w : 0); // headline = input + output + cache writes; cache reads are cheap and shown separately
|
|
@@ -1465,7 +1465,7 @@ function activityLabel(t) { // the short "what is on their screen" tag
|
|
|
1465
1465
|
case 'grep': return L('Cherche « ', 'Searching “') + String(d.pattern || '').slice(0, 22) + L(' »', '”');
|
|
1466
1466
|
case 'glob': return L('Liste ', 'Listing ') + String(d.pattern || '').slice(0, 24);
|
|
1467
1467
|
case 'todo': return L('Met à jour sa todo', 'Updating todo list');
|
|
1468
|
-
case 'artifact': return L('Publie ', 'Publishing ') + (d.title || f).slice(0, 30);
|
|
1468
|
+
case 'artifact': return (d.open ? L('Montre ', 'Showing ') : d.doc ? L('Crée ', 'Writing ') : L('Publie ', 'Publishing ')) + (d.title || (d.open ? 'Artifact' : f)).slice(0, 30);
|
|
1469
1469
|
case 'web': return d.url ? L('Consulte ', 'Fetching ') + d.url.replace(/^https?:\/\//, '').slice(0, 26) : L('Recherche sur le web', 'Web search');
|
|
1470
1470
|
case 'text': { const w = d.what; if (w === 'question') return L('Pose une question', 'Asking a question'); if (w === 'skill') return L('Utilise ', 'Using skill ') + (d.v || ''); if (w === 'mcp') return d.v || t.name; if (w === 'toolsearch') return L('Cherche un outil', 'Looking for a tool'); return t.name; }
|
|
1471
1471
|
default: return t.name;
|
|
@@ -1540,7 +1540,7 @@ const lineHtml = (l, view) => view === 'editor'
|
|
|
1540
1540
|
// ---------- screen sharing: a real video-call presentation (window + presenter camera) ----------
|
|
1541
1541
|
function renderPresent() {
|
|
1542
1542
|
const id = S.present, p = S.agents[id]; if (!p) return; if (S.artPin && !S.arts.has(S.artPin)) { S.artPin = null; armPresent(); }
|
|
1543
|
-
const pinned = S.artPin ? S.arts.get(S.artPin) : null, m = pinned ? artModel(pinned, id) : termModel(id), shape = m.view === 'web' && pinned ? 'pin' : m.view === 'web' || m.view === 'image' ? 'pic' : '';
|
|
1543
|
+
const pinned = S.artPin ? S.arts.get(S.artPin) : null, whole = !pinned && S.artWhole ? S.arts.get(S.artWhole) : null, m = pinned ? artModel(pinned, id) : whole ? artModel(whole, id) : termModel(id), shape = m.view === 'web' && pinned ? 'pin' : m.view === 'web' || m.view === 'image' ? 'pic' : '';
|
|
1544
1544
|
$('#present .pwin').className = 'pwin ' + (m.view === 'term' ? 'term' : m.view); $('#present').classList.toggle('pic', shape === 'pic'); $('#present').classList.toggle('pin', shape === 'pin'); if (shape !== S.picUp) { S.picUp = shape; layout(); } // a picture or a page gets a taller window, a pinned page the tallest
|
|
1545
1545
|
$('#ptitle').textContent = m.view === 'term' ? `${p.name} — zsh — 96×24` : m.title;
|
|
1546
1546
|
const pb = $('#pbody'), shown = m.view === 'image' ? m.imgs.join(' ') : m.view === 'web' ? m.key : ''; pb.dataset.art = m.view === 'web' ? m.a.url : '';
|
|
@@ -1562,40 +1562,46 @@ function armPresent() { // stays up while a command is still running, then ~4
|
|
|
1562
1562
|
clearTimeout(presentTimer); if (S.hold || S.artPin) return;
|
|
1563
1563
|
presentTimer = setTimeout(() => { if (S.present && S.run[S.present] && S.playing) armPresent(); else hidePresent(); }, ($('#present .pwin').classList.contains('web') ? 20000 : $('#present').classList.contains('pic') ? 9000 : 4200) / Math.max(1, spd() / 1.2));
|
|
1564
1564
|
}
|
|
1565
|
-
function showPresent(id) {
|
|
1566
|
-
if (S.artPin || S.boost > 1 || (S.speakers.size && !S.speakers.has(id))) return; // a page you pinned stays up · catching up, or someone else has the floor
|
|
1565
|
+
function showPresent(id, keep) { // keep: the whole document that is being shown (see shareWhole); anything else the agent does takes its place
|
|
1566
|
+
if (!keep) S.artWhole = null; if (S.artPin || S.boost > 1 || (S.speakers.size && !S.speakers.has(id))) return; // a page you pinned stays up · catching up, or someone else has the floor
|
|
1567
1567
|
const first = S.present !== id; S.present = id; $('#present').classList.add('on'); document.body.classList.add('presenting'); document.querySelectorAll('.tile.presenter').forEach((t) => t.classList.remove('presenter')); const pt = $('#t-' + id); if (pt) pt.classList.add('presenter'); renderPresent(); if (first) { layout(); AUD.tone(880, .12, 'sine', .05); }
|
|
1568
1568
|
armPresent();
|
|
1569
1569
|
}
|
|
1570
1570
|
function hidePresent() {
|
|
1571
|
-
clearTimeout(presentTimer); if (!S.present || S.artPin) return; if ($('#pbody').dataset.art) { $('#pbody').innerHTML = ''; $('#pbody').dataset.img = $('#pbody').dataset.art = ''; } /* the page of an artifact does not go on running behind a closed window */
|
|
1571
|
+
clearTimeout(presentTimer); if (!S.present || S.artPin) return; S.artWhole = null; if ($('#pbody').dataset.art) { $('#pbody').innerHTML = ''; $('#pbody').dataset.img = $('#pbody').dataset.art = ''; } /* the page of an artifact does not go on running behind a closed window */
|
|
1572
1572
|
S.present = null; $('#present').classList.remove('on'); document.body.classList.remove('presenting'); document.querySelectorAll('.tile.presenter').forEach((t) => t.classList.remove('presenter')); $('#pcap').textContent = ''; layout();
|
|
1573
1573
|
}
|
|
1574
1574
|
// ---------- artifacts: the pages the session published on claude.ai, shown the way a call shows a browser window someone shares ----------
|
|
1575
1575
|
// When a publish succeeds its author shares the page for a moment; afterwards it is in the line of files, and a click there pins it: the window takes the room, stays until you close it (✕, Esc),
|
|
1576
1576
|
// follows the next versions and steps through the other artifacts of the session (‹ ›). The page itself comes from the server, which puts it together from the session file (claude.ai lets nobody frame it):
|
|
1577
|
-
// a frame that can reach neither the app nor, unless you ask for the libraries, the network. Where there is no page to show (
|
|
1577
|
+
// a frame that can reach neither the app nor, unless you ask for the libraries, the network. Where there is no page to show (a claude.ai template that was sent no page, or one written another way) the window says so and gives the link.
|
|
1578
1578
|
const artSrc = (a) => `/api/artifact?proj=${encodeURIComponent(S.cur.proj)}&id=${encodeURIComponent(S.cur.id)}&agent=${encodeURIComponent(a.agent)}&tool=${encodeURIComponent(a.id)}`;
|
|
1579
1579
|
function noteArts(ev) { // one entry per artifact, the last publish of it: published again, it is the newest and shows its new version
|
|
1580
|
-
if (ev.kind === 'tools') { for (const t of ev.tools) if (t.d && t.d.kind === 'artifact') S.artCalls.set(t.id, { agent: ev.agent, title: t.d.title || '', note: t.d.note || '' }); return; }
|
|
1580
|
+
if (ev.kind === 'tools') { for (const t of ev.tools) if (t.d && t.d.kind === 'artifact') S.artCalls.set(t.id, { agent: ev.agent, title: t.d.title || '', note: t.d.note || '', pub: !t.d.open && !t.d.doc }); return; }
|
|
1581
1581
|
if (ev.kind !== 'results') return;
|
|
1582
1582
|
for (const it of ev.items) { const c = it.art && S.artCalls.get(it.id); if (!c) continue; const u = it.art.url, was = S.arts.get(u) || {}; S.arts.delete(u); S.arts.set(u, { url: u, title: it.art.title || c.title || was.title || 'Artifact', note: c.note || was.note || '', agent: c.agent, id: it.id, v: it.art.v || 0, typed: !!it.art.typed, turn: S.turnN }); if (S.artPin === u) later('art', renderPresent); }
|
|
1583
1583
|
}
|
|
1584
|
+
// A document of several pages made from a claude.ai type (the artboards of a design): each page is shared as it is published, and the whole document once, while the lead says it is done,
|
|
1585
|
+
// since the page on claude.ai cannot be shown here. Pinned from the line of files, it is the whole document too.
|
|
1586
|
+
function shareWhole() {
|
|
1587
|
+
const a = [...S.arts.values()].reverse().find((x) => x.typed && x.turn === S.turnN && (S.artOk.get(x.id) || {}).pages > 1 && !S.wholeSeen.has(x.url + '|' + x.id)), st = a && S.artOk.get(a.id); if (!st || !st.ok || !(st.pages > 1)) return;
|
|
1588
|
+
S.wholeSeen.add(a.url + '|' + a.id); S.artWhole = a.url; showPresent(S.agents[a.agent] ? a.agent : 'main', true); if (S.present !== (S.agents[a.agent] ? a.agent : 'main')) S.artWhole = null;
|
|
1589
|
+
}
|
|
1584
1590
|
function askArt(a) { // is there a page to show for that publish? Asked once: null while the answer is on its way
|
|
1585
|
-
if (S.artOk.has(a.id)) return S.artOk.get(a.id); if (
|
|
1591
|
+
if (S.artOk.has(a.id)) return S.artOk.get(a.id); if (S.demo || !S.cur) { S.artOk.set(a.id, { ok: false }); return S.artOk.get(a.id); }
|
|
1586
1592
|
const cur = S.cur; S.artOk.set(a.id, null);
|
|
1587
|
-
fetch(artSrc(a) + '&check=1').then((r) => r.json()).then((j) => { if (S.cur !== cur) return; S.artOk.set(a.id, { ok: !!j.ok, net: !!j.net }); if (S.present) renderPresent(); }).catch(() => { if (S.cur === cur) S.artOk.delete(a.id); });
|
|
1593
|
+
fetch(artSrc(a) + '&check=1').then((r) => r.json()).then((j) => { if (S.cur !== cur) return; S.artOk.set(a.id, { ok: !!j.ok, net: !!j.net, pages: +j.pages || 0, label: j.label || '' }); if (S.present) renderPresent(); }).catch(() => { if (S.cur === cur) S.artOk.delete(a.id); });
|
|
1588
1594
|
return null;
|
|
1589
1595
|
}
|
|
1590
1596
|
function artModel(a, id) {
|
|
1591
|
-
const st = askArt(a), all = [...S.arts.keys()], pinned = S.artPin === a.url, buf = S.term[id] || [];
|
|
1592
|
-
return { view: 'web', title: a.title, lines: [], a, st, pinned, n: all.length, i: all.indexOf(a.url), stat: a.note || statOf(buf[buf.length - 1], id), key: [a.url, a.id, st ? (st.ok ? 'ok' : 'no') : '?', st && st.net ? 'n' : '', prefs.artNet ? 'N' : '', pinned ? 'p' + all.indexOf(a.url) + '/' + all.length : '', prefs.lang].join('|') };
|
|
1597
|
+
const st = askArt(a), all = [...S.arts.keys()], pinned = S.artPin === a.url, buf = S.term[id] || [], whole = !!(st && st.ok && st.pages > 1 && (pinned || S.artWhole === a.url));
|
|
1598
|
+
return { view: 'web', title: a.title, lines: [], a, st, pinned, whole, n: all.length, i: all.indexOf(a.url), stat: a.note || statOf(buf[buf.length - 1], id), key: [a.url, a.id, st ? (st.ok ? 'ok' : 'no') : '?', st && st.net ? 'n' : '', prefs.artNet ? 'N' : '', pinned ? 'p' + all.indexOf(a.url) + '/' + all.length : '', whole ? 'w' : '', prefs.lang].join('|') };
|
|
1593
1599
|
}
|
|
1594
1600
|
function artHtml(m) {
|
|
1595
1601
|
const a = m.a, ok = m.st && m.st.ok, libs = ok && m.st.net && !prefs.artNet, open = esc(L('Ouvrir sur claude.ai', 'Open on claude.ai'));
|
|
1596
1602
|
const nav = m.pinned && m.n > 1 ? `<button class="pnb" data-go="-1">‹</button><span class="pnn">${m.i + 1}/${m.n}</span><button class="pnb" data-go="1">›</button>` : '';
|
|
1597
|
-
const bar = `<div class="pnav">${nav}<span class="purl">🔒 ${esc(a.url.replace(/^https:\/\//, ''))}</span>${a.v > 1 ? `<span class="pnn">v${a.v}</span>` : ''}${libs ? `<button class="pnb lib" data-lib title="${esc(L('Cette page utilise des bibliothèques hébergées ailleurs : elles ne sont chargées que si vous le demandez', 'This page uses libraries kept on other servers: they are loaded only if you ask'))}">${esc(L('Charger ses bibliothèques', 'Load its libraries'))}</button>` : ''}<button class="pnb" data-open title="${open}" aria-label="${open}">↗</button>${m.pinned ? `<button class="pnb" data-x title="${esc(L('Fermer', 'Close'))}" aria-label="${esc(L('Fermer', 'Close'))}">✕</button>` : ''}</div>`;
|
|
1598
|
-
const page = ok ? `<iframe sandbox="allow-scripts" referrerpolicy="no-referrer" title="${esc(a.title)}" src="${esc(artSrc(a) + (prefs.artNet ? '&net=1' : ''))}"></iframe>` + (m.pinned ? '' : `<button class="pzoom" data-pin title="${esc(L('Cliquer pour agrandir', 'Click to enlarge'))}" aria-label="${esc(L('Cliquer pour agrandir', 'Click to enlarge'))}"></button>`)
|
|
1603
|
+
const bar = `<div class="pnav">${nav}<span class="purl">🔒 ${esc(a.url.replace(/^https:\/\//, ''))}</span>${ok && m.st.pages > 1 ? `<span class="pnn">${esc(m.whole ? L(`${m.st.pages} pages`, `${m.st.pages} pages`) : m.st.label)}</span>` : ''}${a.v > 1 ? `<span class="pnn">v${a.v}</span>` : ''}${libs ? `<button class="pnb lib" data-lib title="${esc(L('Cette page utilise des bibliothèques hébergées ailleurs : elles ne sont chargées que si vous le demandez', 'This page uses libraries kept on other servers: they are loaded only if you ask'))}">${esc(L('Charger ses bibliothèques', 'Load its libraries'))}</button>` : ''}<button class="pnb" data-open title="${open}" aria-label="${open}">↗</button>${m.pinned ? `<button class="pnb" data-x title="${esc(L('Fermer', 'Close'))}" aria-label="${esc(L('Fermer', 'Close'))}">✕</button>` : ''}</div>`;
|
|
1604
|
+
const page = ok ? `<iframe sandbox="allow-scripts" referrerpolicy="no-referrer" title="${esc(a.title)}" src="${esc(artSrc(a) + (prefs.artNet ? '&net=1' : '') + (m.whole ? '&whole=1' + (m.pinned ? '&fit=w' : '') : ''))}"></iframe>` + (m.pinned ? '' : `<button class="pzoom" data-pin title="${esc(L('Cliquer pour agrandir', 'Click to enlarge'))}" aria-label="${esc(L('Cliquer pour agrandir', 'Click to enlarge'))}"></button>`)
|
|
1599
1605
|
: `<div class="pcard"><i>🌐</i><b>${esc(a.title)}</b>${a.note ? `<p>${esc(a.note)}</p>` : ''}${m.st ? `<em>${esc(L('Pas d’aperçu ici : la page est sur claude.ai', 'No preview here: the page is on claude.ai'))}</em><button class="pnb" data-open>${open} ↗</button>` : '<span class="spin"></span>'}</div>`;
|
|
1600
1606
|
return bar + `<div class="pweb">${page}</div>`;
|
|
1601
1607
|
}
|
|
@@ -2286,8 +2292,9 @@ async function run(i) {
|
|
|
2286
2292
|
if (ev.kind === 'usage' || ev.kind === 'compact') { if (ev.kind === 'compact' && S.live && prefs.banter) toast(`${nameOf(ev.agent)}: ${L('contexte compacté 🗜', 'context compacted 🗜')}`); i++; continue; }
|
|
2287
2293
|
if (ev.kind === 'finish') { applyStatus(ev); paintStatus(); i++; continue; }
|
|
2288
2294
|
const backlog = S.live ? S.events.length - i : 0, quick = S.live ? Math.min(1, 40 / Math.max(1, backlog)) : 1; // live: hundreds of tool events from parallel sub-agents must not take minutes to scroll past
|
|
2289
|
-
if (ev.kind === 'results') { applyResults(ev, S.boost > 1); await sleep((S.boost === 1 && S.present === ev.agent && ev.items.some((it) => it.img) ? (S.live ? 900 : 1800) : S.demo ? 900 : S.live ? 30 * quick : 80) / spd()); i++; continue; } // a picture gets a moment on screen
|
|
2295
|
+
if (ev.kind === 'results') { applyResults(ev, S.boost > 1); await sleep((S.boost === 1 && S.present === ev.agent && ev.items.some((it) => it.img) ? (S.live ? 900 : 1800) : S.boost === 1 && S.present === ev.agent && ev.items.some((it) => it.art && (S.artCalls.get(it.id) || {}).pub) ? (S.live ? 2500 : 4000) : S.demo ? 900 : S.live ? 30 * quick : 80) / spd()); i++; continue; } // a picture gets a moment on screen
|
|
2290
2296
|
if (ev.kind === 'tools') { applyStatus(ev); tickTools(ev); AUD.click(); OFFICE.kick(ev.tools[ev.tools.length - 1].name); paintStatus(); if (S.live && S.owed && ev.agent === 'main') { await leadAck(ev, token); if (token !== S.token) return; } if (quick === 1) await smallTalk(token); await sleep((S.demo ? 1100 : S.live ? 110 * quick : 250) / spd()); i++; continue; }
|
|
2297
|
+
if (ev.kind === 'say' && ev.end && ev.agent === 'main' && S.boost <= 1) shareWhole(); // the lead says it is done: the whole document it made, if it has several pages
|
|
2291
2298
|
const group = [ev]; let j = i + 1; // sub-agents talking back-to-back were running in parallel: their lines are taken together and said one after the other
|
|
2292
2299
|
if (ev.kind === 'order') { // several orders in a row (a parallel launch): the new agents all appear now, the first order is read, the others are named in one line
|
|
2293
2300
|
while (j < Math.min(S.events.length, i + 40) && group.length < 8) { const e2 = S.events[j]; if (e2.kind === 'usage' || e2.kind === 'compact') { tally(e2); j++; continue; } if (e2.kind === 'order' && e2.agent === ev.agent) { group.push(e2); j++; } else break; }
|
|
@@ -2362,7 +2369,7 @@ async function loadSession(proj, id) {
|
|
|
2362
2369
|
const data = await (await fetch(`/api/session?proj=${encodeURIComponent(proj)}&id=${id}`)).json();
|
|
2363
2370
|
if (mine !== S.loadN || data.error) return false;
|
|
2364
2371
|
S.term = {}; S.camFor = null; S.focus = null; S.agents = {}; for (const k in nameBook) delete nameBook[k]; [{ id: 'user' }, ...data.agents].forEach((a) => (S.agents[a.id] = persona(a)));
|
|
2365
|
-
clearThoughts(); Object.assign(TH, { since: {}, next: {}, said: {}, last: 0 }); S.events = data.events; stampT(0); S.byK = new Map(data.events.map((e) => [e.k, e])); S.seq = data.seq || 0; S.ep = data.ep || ''; S.sawEnd = !!data.marks || data.events.some((e) => e.end); S.late = []; S.pos = 0; S.joinAt = Date.now(); S.idx = 0; S.status = {}; S.tc = {}; S.cur = { proj, id }; S.logTo = 0; S.detail = null; $('#detail').classList.remove('on'); S.fgone = new Set(); S.fmade = new Map(); S.artOk = new Map(); S.artPin = null;
|
|
2372
|
+
clearThoughts(); Object.assign(TH, { since: {}, next: {}, said: {}, last: 0 }); S.events = data.events; stampT(0); S.byK = new Map(data.events.map((e) => [e.k, e])); S.seq = data.seq || 0; S.ep = data.ep || ''; S.sawEnd = !!data.marks || data.events.some((e) => e.end); S.late = []; S.pos = 0; S.joinAt = Date.now(); S.idx = 0; S.status = {}; S.tc = {}; S.cur = { proj, id }; S.logTo = 0; S.detail = null; $('#detail').classList.remove('on'); S.fgone = new Set(); S.fmade = new Map(); S.artOk = new Map(); S.artPin = null; S.artWhole = null; S.wholeSeen = new Set();
|
|
2366
2373
|
const opt = $('#sessions').selectedOptions[0]; S.title = (S.live ? niceProj(proj) : opt && opt.dataset.title) || '';
|
|
2367
2374
|
if (proj === '_demo') S.events.forEach((e) => { if (e.fr) trMem.set(baseText(e), e.fr, 'fr'); }); // the demo ships its own French
|
|
2368
2375
|
$('#subtitle').textContent = S.title; recomputeStatus(0); buildStage(); renderHighlights(); setFocus('main'); renderLog(true); computeGantt(); layout(); paintStatus(); prefetchTr(0); return true;
|
package/public/locales/da.json
CHANGED
|
@@ -250,6 +250,7 @@
|
|
|
250
250
|
"No preview here: the page is on claude.ai": "Ingen forhåndsvisning her: siden ligger på claude.ai",
|
|
251
251
|
"Open on claude.ai": "Åbn på claude.ai",
|
|
252
252
|
"Publishing ": "Udgiver ",
|
|
253
|
+
"Showing ": "Viser ",
|
|
253
254
|
"This page uses libraries kept on other servers: they are loaded only if you ask": "Denne side bruger biblioteker, der ligger på andre servere: de indlæses kun, hvis du beder om det",
|
|
254
255
|
"Mark as done": "Markér som færdig",
|
|
255
256
|
"Open the pull request": "Åbn pull requesten",
|
package/public/locales/de.json
CHANGED
|
@@ -251,6 +251,7 @@
|
|
|
251
251
|
"No preview here: the page is on claude.ai": "Keine Vorschau hier: Die Seite liegt auf claude.ai",
|
|
252
252
|
"Open on claude.ai": "Auf claude.ai öffnen",
|
|
253
253
|
"Publishing ": "Veröffentliche ",
|
|
254
|
+
"Showing ": "Zeige ",
|
|
254
255
|
"This page uses libraries kept on other servers: they are loaded only if you ask": "Diese Seite nutzt Bibliotheken von anderen Servern: Sie werden nur geladen, wenn Sie es verlangen",
|
|
255
256
|
"Mark as done": "Als erledigt markieren",
|
|
256
257
|
"Open the pull request": "Pull Request öffnen",
|
package/public/locales/en.json
CHANGED
|
@@ -175,6 +175,7 @@
|
|
|
175
175
|
"Project to follow": "Project to follow",
|
|
176
176
|
"Prompt from": "Prompt from",
|
|
177
177
|
"Publishing ": "Publishing ",
|
|
178
|
+
"Showing ": "Showing ",
|
|
178
179
|
"Purchase code": "Purchase code",
|
|
179
180
|
"Quiet": "Quiet",
|
|
180
181
|
"Radio unreachable: check your connection or pick another station.": "Radio unreachable: check your connection or pick another station.",
|
package/public/locales/es.json
CHANGED
|
@@ -251,6 +251,7 @@
|
|
|
251
251
|
"No preview here: the page is on claude.ai": "Sin vista previa aquí: la página está en claude.ai",
|
|
252
252
|
"Open on claude.ai": "Abrir en claude.ai",
|
|
253
253
|
"Publishing ": "Publicando ",
|
|
254
|
+
"Showing ": "Mostrando ",
|
|
254
255
|
"This page uses libraries kept on other servers: they are loaded only if you ask": "Esta página usa bibliotecas alojadas en otros servidores: solo se cargan si lo pides",
|
|
255
256
|
"Mark as done": "Marcar como hecha",
|
|
256
257
|
"Open the pull request": "Abrir la pull request",
|
package/public/locales/ja.json
CHANGED
|
@@ -251,6 +251,7 @@
|
|
|
251
251
|
"No preview here: the page is on claude.ai": "ここではプレビューできません: ページは claude.ai にあります",
|
|
252
252
|
"Open on claude.ai": "claude.ai で開く",
|
|
253
253
|
"Publishing ": "公開中: ",
|
|
254
|
+
"Showing ": "表示中: ",
|
|
254
255
|
"This page uses libraries kept on other servers: they are loaded only if you ask": "このページは他のサーバーにあるライブラリを使います: 求めたときだけ読み込まれます",
|
|
255
256
|
"Mark as done": "完了にする",
|
|
256
257
|
"Open the pull request": "プルリクエストを開く",
|
package/public/locales/ko.json
CHANGED
|
@@ -251,6 +251,7 @@
|
|
|
251
251
|
"No preview here: the page is on claude.ai": "여기서는 미리 볼 수 없습니다: 페이지는 claude.ai에 있습니다",
|
|
252
252
|
"Open on claude.ai": "claude.ai에서 열기",
|
|
253
253
|
"Publishing ": "게시 중: ",
|
|
254
|
+
"Showing ": "보여 주는 중: ",
|
|
254
255
|
"This page uses libraries kept on other servers: they are loaded only if you ask": "이 페이지는 다른 서버에 있는 라이브러리를 사용합니다: 요청할 때만 불러옵니다",
|
|
255
256
|
"Mark as done": "완료로 표시",
|
|
256
257
|
"Open the pull request": "풀 리퀘스트 열기",
|
|
@@ -251,6 +251,7 @@
|
|
|
251
251
|
"No preview here: the page is on claude.ai": "Sem prévia aqui: a página está em claude.ai",
|
|
252
252
|
"Open on claude.ai": "Abrir em claude.ai",
|
|
253
253
|
"Publishing ": "Publicando ",
|
|
254
|
+
"Showing ": "Mostrando ",
|
|
254
255
|
"This page uses libraries kept on other servers: they are loaded only if you ask": "Esta página usa bibliotecas hospedadas em outros servidores: elas só são carregadas se você pedir",
|
|
255
256
|
"Mark as done": "Marcar como concluída",
|
|
256
257
|
"Open the pull request": "Abrir o pull request",
|
|
@@ -251,6 +251,7 @@
|
|
|
251
251
|
"No preview here: the page is on claude.ai": "此处无法预览:页面在 claude.ai 上",
|
|
252
252
|
"Open on claude.ai": "在 claude.ai 上打开",
|
|
253
253
|
"Publishing ": "正在发布 ",
|
|
254
|
+
"Showing ": "正在展示 ",
|
|
254
255
|
"This page uses libraries kept on other servers: they are loaded only if you ask": "此页面使用存放在其他服务器上的库:仅在你要求时才加载",
|
|
255
256
|
"Mark as done": "标记为已处理",
|
|
256
257
|
"Open the pull request": "打开拉取请求",
|
|
@@ -251,6 +251,7 @@
|
|
|
251
251
|
"No preview here: the page is on claude.ai": "此處無法預覽:頁面在 claude.ai 上",
|
|
252
252
|
"Open on claude.ai": "在 claude.ai 上開啟",
|
|
253
253
|
"Publishing ": "發布 ",
|
|
254
|
+
"Showing ": "展示 ",
|
|
254
255
|
"This page uses libraries kept on other servers: they are loaded only if you ask": "此頁面使用存放在其他伺服器上的函式庫:只有在你要求時才會載入",
|
|
255
256
|
"Mark as done": "標記為已處理",
|
|
256
257
|
"Open the pull request": "開啟拉取請求",
|
package/server.js
CHANGED
|
@@ -110,15 +110,33 @@ const toolLabel = (b, ts) => {
|
|
|
110
110
|
case 'AskUserQuestion': out.d = { kind: 'text', what: 'question', text: clip((q0 ? q0.question + '\n' + (q0.options || []).map((o) => '• ' + (o.label || '')).join('\n') : ''), 500) }; break;
|
|
111
111
|
case 'Skill': out.d = { kind: 'text', what: 'skill', v: i.skill, text: clip(i.skill + (i.args ? ' ' + i.args : ''), 200) }; break;
|
|
112
112
|
case 'ToolSearch': out.d = { kind: 'text', what: 'toolsearch', text: clip(i.query, 200) }; break;
|
|
113
|
-
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) }; 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
|
|
113
|
+
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
|
+
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)
|
|
114
115
|
// falls through
|
|
115
|
-
default:
|
|
116
|
+
default: 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
|
+
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) };
|
|
116
118
|
}
|
|
117
119
|
return out;
|
|
118
120
|
};
|
|
119
121
|
// What a publish answered: the link of the page on claude.ai, its title and which version this is. typed: made from an Artifact type (a deck, a design, a document), whose page is the type's and not the file that was sent.
|
|
122
|
+
// What a publish sent along with its files (the artboards of a design, its canvas.json), as absolute paths, the way the Write calls that made them name them. page: the page of a publish whose main file is not one.
|
|
123
|
+
function artSentOf(i) {
|
|
124
|
+
const out = [], root = typeof i.root === 'string' && path.isAbsolute(i.root) ? i.root : '', add = (f) => { const p = typeof f !== 'string' || !f ? '' : path.isAbsolute(f) ? f : root ? path.join(root, f) : ''; if (p && !out.includes(p) && out.length < 60) out.push(p); };
|
|
125
|
+
add(i.file_path); for (const v of Array.isArray(i.files) ? i.files : i.files && typeof i.files === 'object' ? Object.values(i.files) : []) add(typeof v === 'string' ? v : v && (v.from || v.path));
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
120
128
|
const ART_URL = /^https:\/\/claude\.ai\/(code\/)?artifact\/[\w-]{6,80}$/;
|
|
121
129
|
const artifactOf = (u) => (u && typeof u === 'object' && typeof u.url === 'string' && ART_URL.test(u.url) ? { url: u.url, title: clip(u.title, 120), ...(u.seq > 0 ? { v: +u.seq } : {}), ...(u.type || u.created_from_type ? { typed: 1 } : {}) } : null);
|
|
130
|
+
// What a call that put an artifact in front of the person answered, for the line of files: a publish (above); a doc the Claude Docs connector created, whose answer names the doc and its address;
|
|
131
|
+
// an artifact opened on the person's screen, only when this session did not publish or create it already (the same artifact under its other address would show twice, and an open would take the place of the publish that has the preview).
|
|
132
|
+
const DOC_ID = /"created":\{[^{}]*"minted":"([\w-]{6,80})"/, DOC_URL = /"frame":\{[^{}]*"url":"(https:\/\/claude\.ai\/(?:code\/)?artifact\/[\w-]{6,80})"/;
|
|
133
|
+
function artOf(st, how, u, text) {
|
|
134
|
+
const seen = (st.artIds = st.artIds || new Set()), note = (id, url) => { if (id) seen.add('id ' + id); seen.add('url ' + url); }; // known by its id and by its address: a publish may answer without an id
|
|
135
|
+
if (how === 'doc') { const id = DOC_ID.exec(text), m = DOC_URL.exec(text); if (!id || !m || !ART_URL.test(m[1])) return null; note(id[1], m[1]); return { url: m[1], title: '', typed: 1 }; }
|
|
136
|
+
const a = artifactOf(u), id = a && typeof u.artifact_id === 'string' ? u.artifact_id : ''; if (!a) return null;
|
|
137
|
+
if (how === 'open') { if ((id && seen.has('id ' + id)) || seen.has('url ' + a.url)) return null; note(id, a.url); return { ...a, typed: 1 }; } // opened, not made here: the window gives its title and its link
|
|
138
|
+
note(id, a.url); return a;
|
|
139
|
+
}
|
|
122
140
|
const resultText = (c) => (typeof c === 'string' ? c : Array.isArray(c) ? c.map((x) => x.text || '').join('\n') : '');
|
|
123
141
|
// Pictures a tool returned (a screenshot, an image file that was read). They are served from the transcript itself, so nothing outside the session files is ever read, and only bitmap types are sent.
|
|
124
142
|
const IMG_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp']), mediaMemo = new Map();
|
|
@@ -167,52 +185,102 @@ function toolImage(file, toolId, n) { // looks for the tool's result line in t
|
|
|
167
185
|
}
|
|
168
186
|
// ---- Artifacts: a page a session published on claude.ai is shown in the call, in a browser window on the shared screen. claude.ai lets no other page frame it, and the file that was published
|
|
169
187
|
// is most often in a temporary folder that is emptied later: the page is put together again from the session file, which keeps in full the Write call that created it and the Edit calls that followed,
|
|
170
|
-
// up to the publish that is asked for (so an old session shows each version as it was). Nothing outside the session files is read, as for the pictures.
|
|
188
|
+
// up to the publish that is asked for (so an old session shows each version as it was). Nothing outside the session files is read, as for the pictures. An artifact made from a type (a design) shows the page
|
|
189
|
+
// that publish sent, an artboard, without the type's own page around it, which only claude.ai has: its scripts do not run, the rest of it reads as it is. A page made another way (by a command,
|
|
171
190
|
// or written by another agent) has no preview: the call shows its title and its link. The page is served to a frame that can reach neither this server nor, unless the person asked, the network (see /api/artifact).
|
|
172
191
|
const artMemo = new Map(), ART_MAX = 8 * 1024 * 1024;
|
|
173
192
|
const editOnce = (text, e) => { const a = e && typeof e.old_string === 'string' ? e.old_string : '', b = e && typeof e.new_string === 'string' ? e.new_string : ''; if (!a) return text; if (e.replace_all) return text.split(a).join(b); const i = text.indexOf(a); return i < 0 ? text : text.slice(0, i) + b + text.slice(i + a.length); };
|
|
174
|
-
function
|
|
175
|
-
const key = file + '|' +
|
|
176
|
-
const
|
|
177
|
-
const
|
|
193
|
+
function artifactFiles(file, wants) { // wants: [{ fp, until }] → for each, the text of the file at fp as it was when the publish until sent it, or null. One pass over the session file for them all
|
|
194
|
+
const key = file + '|' + wants.map((w) => w.fp + '@' + w.until).join('|'), memo = artMemo.get(key); if (memo && memo.found) return memo.found;
|
|
195
|
+
const W = wants.map((w) => ({ fp: w.fp, until: w.until, path: Buffer.from(JSON.stringify(w.fp).slice(1, -1)), id: Buffer.from('"' + w.until + '"'), ops: [], seen: false }));
|
|
196
|
+
const errMark = Buffer.from('"is_error":true'), until = Date.now() + 2000, failed = new Set(); let fd, carry = Buffer.alloc(0), pos = 0, size = 0;
|
|
178
197
|
try {
|
|
179
|
-
fd = fs.openSync(file, 'r'); size = fs.fstatSync(fd).size; if (memo && memo.miss === size) return null; // already looked for in vain, and nothing was written since
|
|
198
|
+
fd = fs.openSync(file, 'r'); size = fs.fstatSync(fd).size; if (memo && memo.miss === size) return W.map(() => null); // already looked for in vain, and nothing was written since
|
|
180
199
|
while (pos < size && Date.now() < until) {
|
|
181
200
|
const buf = Buffer.alloc(Math.min(8 * 1024 * 1024, size - pos)); fs.readSync(fd, buf, 0, buf.length, pos); pos += buf.length;
|
|
182
201
|
const all = carry.length ? Buffer.concat([carry, buf]) : buf; let a = 0;
|
|
183
202
|
for (let b; (b = all.indexOf(10, a)) >= 0; a = b + 1) {
|
|
184
|
-
const line = all.subarray(a, b), mine = !seen && (line.indexOf(
|
|
203
|
+
const line = all.subarray(a, b), mine = W.some((w) => !w.seen && (line.indexOf(w.path) >= 0 || line.indexOf(w.id) >= 0)); if (!mine && line.indexOf(errMark) < 0) continue;
|
|
185
204
|
let r; try { r = JSON.parse(line.toString('utf8')); } catch { continue; }
|
|
186
205
|
for (const blk of blocks(r)) {
|
|
187
206
|
if (blk.type === 'tool_result' && blk.is_error) failed.add(blk.tool_use_id); // a write or an edit that was refused changed nothing (its answer may come after the publish, when both were asked at once)
|
|
188
|
-
if (blk.type !== 'tool_use'
|
|
189
|
-
if (blk.id ===
|
|
190
|
-
else if (i.file_path === fp && (blk.name === 'Write' || blk.name === 'Edit' || blk.name === 'MultiEdit')) ops.push({ id: blk.id, name: blk.name, i });
|
|
207
|
+
if (blk.type !== 'tool_use') continue; const i = blk.input || {}, op = blk.name === 'Write' || blk.name === 'Edit' || blk.name === 'MultiEdit';
|
|
208
|
+
for (const w of W) { if (w.seen) continue; if (blk.id === w.until) w.seen = true; else if (op && i.file_path === w.fp) w.ops.push({ id: blk.id, name: blk.name, i }); } // what was written after that publish belongs to the next one
|
|
191
209
|
}
|
|
192
210
|
}
|
|
193
211
|
carry = Buffer.from(all.subarray(a));
|
|
194
212
|
}
|
|
195
213
|
} catch {} finally { if (fd != null) fs.closeSync(fd); }
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
214
|
+
const found = W.map((w) => {
|
|
215
|
+
let html = null; if (!w.seen || pos < size) return null;
|
|
216
|
+
for (const op of w.ops) {
|
|
217
|
+
if (failed.has(op.id)) continue;
|
|
218
|
+
if (op.name === 'Write') html = typeof op.i.content === 'string' ? op.i.content : null;
|
|
219
|
+
else if (html != null) for (const e of op.name === 'MultiEdit' ? (Array.isArray(op.i.edits) ? op.i.edits : []) : [op.i]) html = editOnce(html, e);
|
|
220
|
+
}
|
|
221
|
+
return html != null && html.length <= ART_MAX ? { html, net: /<script\b[^>]*\bsrc\s*=\s*["']?https?:/i.test(html) } : null; // net: it names a library kept on another server, which the frame does not load unless asked
|
|
222
|
+
});
|
|
223
|
+
artMemo.delete(key); artMemo.set(key, found.some(Boolean) ? { found } : { miss: size }); if (artMemo.size > 24) artMemo.delete(artMemo.keys().next().value);
|
|
205
224
|
return found;
|
|
206
225
|
}
|
|
207
|
-
|
|
208
|
-
|
|
226
|
+
const artifactPage = (file, toolId, fp) => artifactFiles(file, [{ fp, until: toolId }])[0]; // the text of the page at fp as it was when the call toolId published it, or null
|
|
227
|
+
// What the call shows for a publish of that very session, published without error: the page it sent. For an artifact made from a type that was sent several pages (the artboards of a design),
|
|
228
|
+
// also each page as its last publish up to this one sent it, and the canvas.json that places them, if one was sent: the whole document, once it is made, since claude.ai cannot be shown here.
|
|
229
|
+
const CANVAS = /(^|[\\/])canvas\.json$/i;
|
|
230
|
+
const ART_LS = new RegExp('[' + String.fromCharCode(0x2028, 0x2029) + ']', 'g'); // the two line ends JSON keeps and a script does not
|
|
231
|
+
function artifactPlan(proj, id, agent, toolId) {
|
|
232
|
+
const d = new Map(), ok = new Map(); let url = '', typed = false;
|
|
209
233
|
for (const e of timeline(proj, id).events) {
|
|
210
234
|
if (e.agent !== agent) continue;
|
|
211
|
-
if (e.kind === 'tools') { for (const t of e.tools) if (t.
|
|
212
|
-
else if (e.kind === 'results') { for (const it of e.items) if (it.id === toolId
|
|
235
|
+
if (e.kind === 'tools') { for (const t of e.tools) if (t.d && t.d.kind === 'artifact') d.set(t.id, t.d); }
|
|
236
|
+
else if (e.kind === 'results') { for (const it of e.items) if (it.art && d.has(it.id)) { ok.set(it.id, it.art.url); if (it.id === toolId) { url = it.art.url; typed = !!it.art.typed; } } }
|
|
213
237
|
}
|
|
214
|
-
|
|
238
|
+
const me = d.get(toolId), fp = me ? (typed && me.page) || me.file : ''; if (!url || !/\.html?$/i.test(fp)) return null; // the page sent beside a canvas.json counts for a template only: a plain artifact is its main file
|
|
239
|
+
const plan = { fp, pages: [], canvas: null }; if (!typed) return plan;
|
|
240
|
+
const last = new Map(); for (const [tid, u] of ok) { if (u === url) for (const f of d.get(tid).sent || [d.get(tid).file]) if (/\.html?$/i.test(f) || CANVAS.test(f)) last.set(f, tid); if (tid === toolId) break; } // in the order they were first sent
|
|
241
|
+
for (const [f, tid] of last) { if (CANVAS.test(f)) plan.canvas = { fp: f, until: tid }; else plan.pages.push({ fp: f, until: tid }); }
|
|
242
|
+
return plan;
|
|
243
|
+
}
|
|
244
|
+
function artifactBuild(file, toolId, plan, whole) { // the page to show, or null. pages, label: how many pages the document has so far, and the name the canvas gives this one
|
|
245
|
+
const one = artifactPage(file, toolId, plan.fp); if (!plan.pages.length) return one;
|
|
246
|
+
const got = artifactFiles(file, plan.canvas ? [...plan.pages, plan.canvas] : plan.pages), list = plan.pages.map((w, k) => ({ fp: w.fp, page: got[k] })).filter((x) => x.page);
|
|
247
|
+
let canvas = null; try { canvas = plan.canvas && got[plan.pages.length] ? JSON.parse(got[plan.pages.length].html) : null; } catch {}
|
|
248
|
+
const boards = canvas && canvas.boards && typeof canvas.boards === 'object' ? canvas.boards : {}, keyOf = (fp) => Object.keys(boards).find((k) => fp === k || fp.endsWith('/' + k)), board = (fp) => (keyOf(fp) ? boards[keyOf(fp)] : null);
|
|
249
|
+
const name = (fp) => clip((board(fp) || {}).title, 80) || path.basename(fp).replace(/(\.dc)?\.html?$/i, ''), label = name(plan.fp);
|
|
250
|
+
if (!whole || list.length < 2) return one && { ...one, pages: list.length, label };
|
|
251
|
+
const order = canvas && Array.isArray(canvas.order) ? canvas.order : [], rank = (x) => { const n = order.indexOf(keyOf(x.fp)); return n < 0 ? 1e6 : n; }; list.sort((a, b) => rank(a) - rank(b));
|
|
252
|
+
const num = (v, dflt) => (Number.isFinite(+v) && +v > 0 ? Math.min(+v, 20000) : dflt), pos = (v) => (Number.isFinite(+v) ? Math.max(-1e5, Math.min(1e5, +v)) : 0), PREV = /"\$preview"\s*:\s*\{\s*"width"\s*:\s*(\d+)\s*,\s*"height"\s*:\s*(\d+)/;
|
|
253
|
+
const items = list.map((x) => { const b = board(x.fp), pv = PREV.exec(x.page.html); return { html: x.page.html, title: name(x.fp), x: b ? pos(b.x) : null, y: b ? pos(b.y) : null, w: num(b && b.w, pv ? +pv[1] : 1100), h: num(b && b.h, pv ? +pv[2] : 800) }; });
|
|
254
|
+
const notes = canvas && canvas.notes && typeof canvas.notes === 'object' ? Object.values(canvas.notes).filter((n) => n && typeof n.text === 'string').slice(0, 40).map((n) => ({ text: clip(n.text, 120), x: pos(n.x), y: pos(n.y), big: /^title/.test(n.kind || '') })) : [];
|
|
255
|
+
const data = JSON.stringify({ items, notes }).replace(/</g, '\\u003c').replace(ART_LS, (ch) => '\\u' + ch.charCodeAt(0).toString(16));
|
|
256
|
+
return { html: ARTIFACT_WHOLE.replace('%DATA%', () => data), net: list.some((x) => x.page.net), pages: list.length, label };
|
|
215
257
|
}
|
|
258
|
+
// The whole document: each page in a shadow root of its own (its styles stay its own; its script tags do not run, its inline handlers do, in the same sandbox as the frame of one page). Shared, every page at once in the grid that shows them
|
|
259
|
+
// largest; pinned (fit=w), where the canvas puts them (or three to a row), to the width of the window, to scroll through. No backslash in this script: the template literal would eat it.
|
|
260
|
+
const ARTIFACT_WHOLE = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style>html,body{margin:0;background:#e8e8ec}#o{position:relative;margin:0 auto;overflow:hidden}#c{position:absolute;left:0;top:0;transform-origin:0 0}.b{position:absolute;overflow:hidden;background:#fff;box-shadow:0 2px 14px rgba(0,0,0,.18);font:initial;color:initial}.t,.n{position:absolute;white-space:nowrap;font:600 22px system-ui,sans-serif;color:#666}.n{font-size:30px;color:#333}.n.big{font-size:44px;font-weight:700}</style><div id="o"><div id="c"></div></div><script type="application/json" id="d">%DATA%</script><script>
|
|
261
|
+
(function () {
|
|
262
|
+
var D = JSON.parse(document.getElementById('d').textContent), c = document.getElementById('c'), o = document.getElementById('o'), M = 60, wide = /[?&]fit=w(&|$)/.test(location.search);
|
|
263
|
+
var placed = D.items.filter(function (it) { return it.x != null; }), gy = placed.length ? Math.max.apply(null, placed.map(function (it) { return it.y + it.h; })) + 160 : 0, gx = 0, col = 0, rowH = 0;
|
|
264
|
+
D.items.forEach(function (it) { if (it.x != null) return; if (col === 3) { col = 0; gx = 0; gy += rowH + 120; rowH = 0; } it.x = gx; it.y = gy; gx += it.w + 80; rowH = Math.max(rowH, it.h); col++; }); // pages the canvas does not place: three to a row, below it
|
|
265
|
+
var els = D.items.map(function (it) {
|
|
266
|
+
var b = document.createElement('div'), t = document.createElement('div'); b.className = 'b'; b.attachShadow({ mode: 'open' }).innerHTML = it.html; t.className = 't'; t.textContent = it.title; c.appendChild(t); c.appendChild(b); return { it: it, b: b, t: t };
|
|
267
|
+
});
|
|
268
|
+
var notes = D.notes.map(function (n) { var e = document.createElement('div'); e.className = 'n' + (n.big ? ' big' : ''); e.textContent = n.text; c.appendChild(e); return { n: n, e: e }; });
|
|
269
|
+
var fit = function () { // pinned (fit=w): where the canvas puts each page, to the width of the window, to scroll through; shared: every page at once, in the grid that shows them largest
|
|
270
|
+
var x0 = 1e9, y0 = 1e9, x1 = -1e9, y1 = -1e9, box = function (x, y, w, h) { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x + w); y1 = Math.max(y1, y + h); };
|
|
271
|
+
var put = function (e, x, y) { e.b.style.cssText = 'left:' + x + 'px;top:' + y + 'px;width:' + e.it.w + 'px;height:' + e.it.h + 'px'; e.t.style.cssText = 'left:' + x + 'px;top:' + (y - 38) + 'px'; box(x, y - 44, e.it.w, e.it.h + 44); };
|
|
272
|
+
if (wide) { els.forEach(function (e) { put(e, e.it.x, e.it.y); }); notes.forEach(function (n) { n.e.style.cssText = 'left:' + n.n.x + 'px;top:' + n.n.y + 'px'; box(n.n.x, n.n.y, 400, 60); }); }
|
|
273
|
+
else {
|
|
274
|
+
var n = els.length, cw = Math.max.apply(null, els.map(function (e) { return e.it.w; })) + 60, ch = Math.max.apply(null, els.map(function (e) { return e.it.h; })) + 84, k = 1, best = 0;
|
|
275
|
+
for (var j = 1; j <= n; j++) { var r = Math.ceil(n / j), s0 = Math.min(innerWidth / (j * cw + 2 * M), innerHeight / (r * ch + 2 * M)); if (s0 > best) { best = s0; k = j; } }
|
|
276
|
+
els.forEach(function (e, i) { put(e, (i % k) * cw, Math.floor(i / k) * ch + 44); }); notes.forEach(function (n) { n.e.style.cssText = 'display:none'; });
|
|
277
|
+
}
|
|
278
|
+
var bw = x1 - x0 + 2 * M, bh = y1 - y0 + 2 * M, s = wide ? innerWidth / bw : Math.min(innerWidth / bw, innerHeight / bh);
|
|
279
|
+
o.style.width = bw * s + 'px'; o.style.height = bh * s + 'px'; o.style.marginTop = wide ? '0' : Math.max(0, (innerHeight - bh * s) / 2) + 'px'; c.style.transform = 'scale(' + s + ') translate(' + (M - x0) + 'px,' + (M - y0) + 'px)';
|
|
280
|
+
};
|
|
281
|
+
fit(); addEventListener('resize', fit);
|
|
282
|
+
})();
|
|
283
|
+
</script>`;
|
|
216
284
|
// What the frame of an artifact may do: run the page's own scripts, and nothing else. "sandbox" without allow-same-origin gives the page an origin of its own, also when its address is opened in a tab:
|
|
217
285
|
// it cannot read this server (which refuses what does not come from its own page), keep anything, open a window or send a form. Without net, nothing is fetched from anywhere. With net (the person
|
|
218
286
|
// asked for the libraries of the pages, ⚙ or the button in the window), scripts and fonts come from the servers claude.ai itself lets an artifact use, and from nowhere else; the page still cannot send anything out.
|
|
@@ -534,7 +602,7 @@ function parseRecord(st, r) {
|
|
|
534
602
|
for (const b of blocks(r)) if (b.type === 'tool_result' && wf) push({ ts, agent, kind: 'wfrun', toolId: b.tool_use_id, run: wf }); // the answer to a Workflow call names the run it started: its agents are in subagents/workflows/<run>/
|
|
535
603
|
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)
|
|
536
604
|
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])) {
|
|
537
|
-
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) ?
|
|
605
|
+
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;
|
|
538
606
|
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
|
|
539
607
|
}
|
|
540
608
|
if (items.length) push({ ts, agent, kind: 'results', items });
|
|
@@ -558,7 +626,7 @@ function parseRecord(st, r) {
|
|
|
558
626
|
else if (b.type === 'tool_use') {
|
|
559
627
|
st.toolName[b.id] = b.name; (st.out = st.out || new Set()).add(b.id); if (b.input && b.input.run_in_background) (st.bg = st.bg || {})[b.id] = true; // out: the calls that have no answer yet
|
|
560
628
|
if (b.name === 'Agent' || b.name === 'Task') push({ ts, agent, kind: 'agentcall', toolId: b.id, bg: !!(b.input && b.input.run_in_background), text: (b.input && b.input.prompt) || '', title: (b.input && b.input.description) || '', ...(b.input && typeof b.input.name === 'string' && b.input.name.trim() ? { nm: b.input.name.trim() } : {}) });
|
|
561
|
-
else { const tool = toolLabel(b, ts); if (tool.d && tool.d.outs) tool.d.outs = tool.d.outs.map((f) => absPath(f, r.cwd)); if (tool.d && tool.d.kind === 'artifact') (st.pubs = st.pubs || new
|
|
629
|
+
else { const tool = toolLabel(b, ts); if (tool.d && tool.d.outs) tool.d.outs = tool.d.outs.map((f) => absPath(f, r.cwd)); if (tool.d && tool.d.kind === 'artifact') (st.pubs = st.pubs || new Map()).set(b.id, tool.d.open ? 'open' : tool.d.doc ? 'doc' : 'pub'); push({ ts, agent, kind: 'tool', tool, ...th() }); st.act = st.raw.length - 1; }
|
|
562
630
|
}
|
|
563
631
|
}
|
|
564
632
|
if (agent === 'main' && (m.stop_reason === 'end_turn' || ((r.isApiErrorMessage || (m.model === '<synthetic>' && m.stop_reason === 'stop_sequence')) && !(st.out && st.out.size)))) { // also a turn that ends on a message Claude Code writes itself, in the place of the model's: the API is down, the limit is reached, the request was refused, or there was nothing to answer. Nothing follows it, unless a call of the lead is still out: the connection dropped while its agents worked, and it goes on when they answer. (A message of the model that a safety check cuts is not the end either: Claude Code tells the model, which goes on.) The lead's turn is over: Claude Code writes one record per content block, each with the message's stop reason, so the mark goes on the line this record carries (a thinking block carries none)
|
|
@@ -1015,11 +1083,11 @@ function start(port = PORT) {
|
|
|
1015
1083
|
if (!im) { res.writeHead(bad ? 400 : 404); return res.end(bad ? 'bad request' : 'not found'); }
|
|
1016
1084
|
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);
|
|
1017
1085
|
}
|
|
1018
|
-
if (url.pathname === '/api/artifact') { // the page a publish of this session sent, for the frame of the shared screen · check=1: is there one, and does it name libraries (asked before the frame is drawn)
|
|
1086
|
+
if (url.pathname === '/api/artifact') { // the page a publish of this session sent, for the frame of the shared screen · check=1: is there one, and does it name libraries (asked before the frame is drawn) · whole=1: the whole document
|
|
1019
1087
|
const q = (k) => url.searchParams.get(k) || '', SAFE = /^[\w.\-]+$/, bad = [q('proj'), q('id'), q('agent'), q('tool')].some((v) => !SAFE.test(v) || v === '..' || v.length > 200) || q('tool').length < 6;
|
|
1020
1088
|
if (bad) { res.writeHead(400); return res.end('bad request'); }
|
|
1021
|
-
const file = sourceOf(q('proj')) ? null : mediaFile(q('proj'), q('id'), q('agent')),
|
|
1022
|
-
if (q('check')) return json(page ? { ok: true, net: page.net } : { ok: false }, page ? 200 : 404);
|
|
1089
|
+
const file = sourceOf(q('proj')) ? null : mediaFile(q('proj'), q('id'), q('agent')), plan = file && fs.existsSync(file) && fs.existsSync(mediaFile(q('proj'), q('id'), 'main')) ? artifactPlan(q('proj'), q('id'), q('agent'), q('tool')) : null, page = plan && artifactBuild(file, q('tool'), plan, q('whole') === '1');
|
|
1090
|
+
if (q('check')) return json(page ? { ok: true, net: page.net, ...(page.pages > 1 ? { pages: page.pages, label: page.label } : {}) } : { ok: false }, page ? 200 : 404); // pages: a document of several pages, which can be shown whole (whole=1)
|
|
1023
1091
|
if (!page) { res.writeHead(404); return res.end('not found'); }
|
|
1024
1092
|
const body = Buffer.from((/^\s*<!doctype/i.test(page.html) ? '' : '<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">') + page.html, 'utf8'); // an artifact is published as the inside of a page: claude.ai adds the rest, and so does this
|
|
1025
1093
|
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8', 'content-length': body.length, 'content-security-policy': artifactCsp(q('net') === '1'), 'x-content-type-options': 'nosniff', 'referrer-policy': 'no-referrer', 'cache-control': 'private, no-store' }); return res.end(body);
|