@phnx-labs/artifacts-cli 0.4.1 → 0.4.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"icons.js","sourceRoot":"","sources":["../../src/lib/icons.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,0EAA0E;AAC1E,oCAAoC;AAEpC,MAAM,kBAAkB,GAA2B;IACjD,MAAM,EACJ,qxDAAqxD;IACvxD,KAAK,EACH,s7CAAs7C;IACx7C,MAAM,EACJ,8RAA8R;IAChS,MAAM,EACJ,0VAA0V;IAC5V,OAAO,EACL,4lDAA4lD;CAC/lD,CAAC;AAEF,MAAM,aAAa,GACjB,uOAAuO,CAAC;AAE1O,MAAM,UAAU,GACd,wKAAwK,CAAC;AAE3K,MAAM,UAAU,YAAY;IAC1B,OAAO,iEAAiE,UAAU,QAAQ,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,MAAM,IAAI,GAAG,kBAAkB,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,YAAY,IAAI,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC;IAC1D,OAAO,iEAAiE,IAAI,QAAQ,CAAC;AACvF,CAAC;AAED,iFAAiF;AACjF,kDAAkD;AAClD,MAAM,gBAAgB,GAA2B;IAC/C,MAAM,EACJ,0sBAA0sB;IAC5sB,MAAM,EACJ,yVAAyV;IAC3V,IAAI,EACF,oXAAoX;IACtX,MAAM,EACJ,s2BAAs2B;IACx2B,MAAM,EACJ,idAAid;IACnd,SAAS,EACP,6KAA6K;IAC/K,KAAK,EACH,8UAA8U;IAChV,MAAM,EACJ,yWAAyW;IAC3W,KAAK,EACH,w/BAAw/B;IAC1/B,KAAK,EACH,09BAA09B;CAC79B,CAAC;AAEF,0EAA0E;AAC1E,MA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,CAAC;AASD,MAAM,iBAAiB,GAAoB,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1F;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,UAA2B,iBAAiB;IACpF,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAC;IAE5B,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YAAE,SAAS;QAChC,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,IAAI;YAAE,OAAO,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,CAAC;IAED,2EAA2E;IAC3E,OAAO,eAAe,OAAO,CAAC,OAAO,oDAAoD,kBAAkB,CAAC,IAAI,CAAC,sGAAsG,CAAC;AAC1N,CAAC"}
@@ -0,0 +1,22 @@
1
+ export interface OriginMetadata {
2
+ agent: string;
3
+ version: string;
4
+ host: string;
5
+ platform: string;
6
+ arch: string;
7
+ session: string;
8
+ sessionId: string;
9
+ }
10
+ export interface ReaderRevision {
11
+ id: string;
12
+ revisions: {
13
+ number: number;
14
+ createdAt: string;
15
+ }[];
16
+ }
17
+ export declare const REVISION_START = "<!--artifact-revision-start-->";
18
+ export declare const REVISION_END = "<!--artifact-revision-end-->";
19
+ export declare function originMenu(origin: OriginMetadata): string;
20
+ export declare function revisionMenu(history?: ReaderRevision): string;
21
+ export declare const METADATA_CSS = "\n.document-header{position:relative;flex-wrap:wrap;gap:8px;padding-bottom:10px}.artifact-menu{font:12px/1.5 var(--font-body);color:var(--muted)}.artifact-menu>summary{display:flex;align-items:center;gap:7px;cursor:pointer;list-style:none;border:1px solid var(--line);border-radius:999px;background:var(--surface);padding:5px 11px;max-width:270px;overflow-wrap:anywhere}.artifact-menu>summary::-webkit-details-marker{display:none}.artifact-menu>summary:hover{color:var(--accent);border-color:var(--accent)}.artifact-menu>summary:focus-visible,.metadata-copy:focus-visible{outline:2px solid var(--accent);outline-offset:3px}.metadata-popover{position:absolute;z-index:80;right:0;top:calc(100% + 6px);width:min(370px,100%);max-height:70vh;overflow:auto;padding:20px;background:var(--surface);color:var(--text);border:1px solid var(--line);border-radius:14px;box-shadow:0 12px 34px #0002}.metadata-popover h2{font:650 17px/1.4 var(--font-body);margin:0 0 16px;padding:0;border:0}.metadata-popover dl{margin:0}.metadata-row{display:grid;grid-template-columns:82px minmax(0,1fr);align-items:center;gap:12px;min-height:38px}.metadata-row dt{color:var(--muted)}.metadata-row dd{margin:0;min-width:0}.metadata-copy{display:flex;justify-content:space-between;align-items:center;gap:12px;min-height:34px;width:100%;border:0;border-radius:6px;padding:7px 8px;background:transparent;color:var(--text);font:inherit;text-align:left;cursor:pointer;overflow-wrap:anywhere}.metadata-copy:hover{background:var(--surface-alt)}.metadata-copy>span{font-size:10px;color:var(--muted);flex:0 0 auto}.metadata-actions{display:grid;gap:5px;border-top:1px solid var(--line);margin-top:12px;padding-top:12px}.metadata-actions>a{padding:7px 8px;color:var(--accent)}.metadata-note,.metadata-missing{color:var(--muted);font-size:12px}.metadata-feedback:empty{display:none}.metadata-feedback{color:var(--accent);font-size:12px;margin:8px 0 0}.metadata-fallback{width:100%;min-height:110px;color:var(--text);background:var(--bg);border:1px solid var(--line);font:12px/1.5 var(--font-mono);margin-top:8px;resize:vertical}.revision-list{list-style:none;padding:0;margin:0}.revision-list li{display:grid;grid-template-columns:26px 1fr;gap:2px 8px;padding:9px 0;border-bottom:1px solid var(--line)}.revision-list time{color:var(--muted);font-size:11px}.revision-list .metadata-copy{grid-column:2;font-size:12px;padding-left:0}.metadata-popover [hidden]{display:none!important}@media(max-width:480px){.artifact-menu>summary{max-width:220px}.metadata-popover{padding:16px}.metadata-row{grid-template-columns:70px minmax(0,1fr);gap:6px}}@media print{.artifact-menu{display:none}}\n";
22
+ export declare const METADATA_SCRIPT = "<script>\n(() => {\n const menus = [...document.querySelectorAll('.artifact-menu')];\n for (const menu of menus) {\n menu.querySelector('summary').addEventListener('click', () => menus.forEach(other => { if (other !== menu) other.open = false; }));\n menu.querySelectorAll('[data-copy-value]').forEach(button => button.addEventListener('click', async () => {\n const status = menu.querySelector('.metadata-feedback');\n const fallback = menu.querySelector('.metadata-fallback');\n status.textContent = ''; fallback.hidden = true;\n try {\n if (!navigator.clipboard?.writeText) throw new Error('Clipboard unavailable');\n await navigator.clipboard.writeText(button.dataset.copyValue);\n status.textContent = 'Copied';\n } catch {\n status.textContent = 'Could not copy. Select and copy the full value below.';\n fallback.value = button.dataset.copyValue; fallback.hidden = false;\n fallback.focus(); fallback.select();\n }\n }));\n }\n document.addEventListener('click', event => menus.forEach(menu => { if (!menu.contains(event.target)) menu.open = false; }));\n document.addEventListener('keydown', event => { if (event.key === 'Escape') menus.forEach(menu => { if (menu.open) { menu.open = false; menu.querySelector('summary').focus(); } }); });\n})();\n</script>";
@@ -0,0 +1,52 @@
1
+ import { escapeHtml } from './html.js';
2
+ import { shortHost } from './templates.js';
3
+ export const REVISION_START = '<!--artifact-revision-start-->';
4
+ export const REVISION_END = '<!--artifact-revision-end-->';
5
+ const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
6
+ const copy = (label, value, display = label) => `<button type="button" class="metadata-copy" data-copy-value="${escapeHtml(value)}" aria-label="${escapeHtml(label)}" title="${escapeHtml(value)}">${escapeHtml(display)}<span aria-hidden="true">Copy</span></button>`;
7
+ const row = (label, value) => `<div class="metadata-row"><dt>${escapeHtml(label)}</dt><dd>${value ? copy(`Copy ${label.toLowerCase()}`, value, value) : '<span class="metadata-missing">Not recorded</span>'}</dd></div>`;
8
+ const fallback = '<p class="metadata-feedback" role="status" aria-live="polite"></p><textarea class="metadata-fallback" aria-label="Select and copy full value" readonly hidden></textarea>';
9
+ export function originMenu(origin) {
10
+ const device = shortHost(origin.host);
11
+ const session = origin.sessionId || origin.session;
12
+ const full = Boolean(origin.sessionId) || uuid.test(session);
13
+ const short = uuid.test(session) ? session.split('-')[0] : session.slice(0, 12);
14
+ const platform = [origin.platform === 'macos' ? 'macOS' : origin.platform, origin.arch].filter(Boolean).join(' · ');
15
+ const context = `Device: ${device || 'Not recorded'}\nSession${full ? '' : ' (short ID only)'}: ${session || 'Not recorded'}`;
16
+ const all = `${context}\nPlatform: ${platform || 'Not recorded'}\nAgent: ${origin.agent || 'Not recorded'}\nAgent CLI version: ${origin.version || 'Not recorded'}`;
17
+ const trigger = [device, short].filter(Boolean).join(' · ') || 'Origin';
18
+ return `<details class="artifact-menu origin-menu"><summary aria-label="Origin metadata">${escapeHtml(trigger)} <span aria-hidden="true">▾</span></summary><div class="metadata-popover"><h2>Origin</h2><dl>${row('Device', device)}${row('Platform', platform)}${row('Agent', origin.agent)}${row('CLI version', origin.version)}<div class="metadata-row"><dt>Session</dt><dd>${session ? copy(full ? 'Copy full session ID' : 'Copy recorded short session ID', session, short) : '<span class="metadata-missing">Not recorded</span>'}</dd></div></dl>${session && !full ? '<p class="metadata-note">Short ID only. The full session was not recorded.</p>' : ''}<div class="metadata-actions">${session ? copy('Copy device and session', context, 'Device + session') : ''}${copy('Copy all metadata', all, 'All metadata')}${session ? `<a href="agents://session/${encodeURIComponent(session)}">Resume session ↗</a>` : ''}</div>${fallback}</div></details>`;
19
+ }
20
+ export function revisionMenu(history) {
21
+ const latest = history?.revisions.at(-1);
22
+ const content = latest && history ? `<p class="metadata-note">Saved on the rendering device. Copy an open command to run there; it never overwrites the source.</p><ol class="revision-list">${history.revisions.slice(-10).reverse().map((revision) => `<li><span>r${revision.number}</span><time data-relative="true" data-label="Saved" datetime="${escapeHtml(revision.createdAt)}" title="${escapeHtml(revision.createdAt)}">Saved ${escapeHtml(revision.createdAt.replace('T', ' ').slice(0, 16))} UTC</time>${copy(`Copy command to open revision ${revision.number}`, `artifacts history ${history.id} --open ${revision.number}`, revision === latest ? 'This revision' : 'Open command')}</li>`).join('')}</ol>${history.revisions.length > 10 ? copy('Copy complete history command', `artifacts history ${history.id}`, 'All revisions') : ''}` : '<p class="metadata-note">No saved history yet. Render a Markdown file to an output path to start tracking revisions.</p>';
23
+ return `${REVISION_START}<details class="artifact-menu revision-menu"><summary aria-label="Revision history">${latest ? `r${latest.number}` : 'History'} <span aria-hidden="true">▾</span></summary><div class="metadata-popover"><h2>${latest ? `Revision ${latest.number}` : 'Revision history'}</h2>${content}${fallback}</div></details>${REVISION_END}`;
24
+ }
25
+ export const METADATA_CSS = `
26
+ .document-header{position:relative;flex-wrap:wrap;gap:8px;padding-bottom:10px}.artifact-menu{font:12px/1.5 var(--font-body);color:var(--muted)}.artifact-menu>summary{display:flex;align-items:center;gap:7px;cursor:pointer;list-style:none;border:1px solid var(--line);border-radius:999px;background:var(--surface);padding:5px 11px;max-width:270px;overflow-wrap:anywhere}.artifact-menu>summary::-webkit-details-marker{display:none}.artifact-menu>summary:hover{color:var(--accent);border-color:var(--accent)}.artifact-menu>summary:focus-visible,.metadata-copy:focus-visible{outline:2px solid var(--accent);outline-offset:3px}.metadata-popover{position:absolute;z-index:80;right:0;top:calc(100% + 6px);width:min(370px,100%);max-height:70vh;overflow:auto;padding:20px;background:var(--surface);color:var(--text);border:1px solid var(--line);border-radius:14px;box-shadow:0 12px 34px #0002}.metadata-popover h2{font:650 17px/1.4 var(--font-body);margin:0 0 16px;padding:0;border:0}.metadata-popover dl{margin:0}.metadata-row{display:grid;grid-template-columns:82px minmax(0,1fr);align-items:center;gap:12px;min-height:38px}.metadata-row dt{color:var(--muted)}.metadata-row dd{margin:0;min-width:0}.metadata-copy{display:flex;justify-content:space-between;align-items:center;gap:12px;min-height:34px;width:100%;border:0;border-radius:6px;padding:7px 8px;background:transparent;color:var(--text);font:inherit;text-align:left;cursor:pointer;overflow-wrap:anywhere}.metadata-copy:hover{background:var(--surface-alt)}.metadata-copy>span{font-size:10px;color:var(--muted);flex:0 0 auto}.metadata-actions{display:grid;gap:5px;border-top:1px solid var(--line);margin-top:12px;padding-top:12px}.metadata-actions>a{padding:7px 8px;color:var(--accent)}.metadata-note,.metadata-missing{color:var(--muted);font-size:12px}.metadata-feedback:empty{display:none}.metadata-feedback{color:var(--accent);font-size:12px;margin:8px 0 0}.metadata-fallback{width:100%;min-height:110px;color:var(--text);background:var(--bg);border:1px solid var(--line);font:12px/1.5 var(--font-mono);margin-top:8px;resize:vertical}.revision-list{list-style:none;padding:0;margin:0}.revision-list li{display:grid;grid-template-columns:26px 1fr;gap:2px 8px;padding:9px 0;border-bottom:1px solid var(--line)}.revision-list time{color:var(--muted);font-size:11px}.revision-list .metadata-copy{grid-column:2;font-size:12px;padding-left:0}.metadata-popover [hidden]{display:none!important}@media(max-width:480px){.artifact-menu>summary{max-width:220px}.metadata-popover{padding:16px}.metadata-row{grid-template-columns:70px minmax(0,1fr);gap:6px}}@media print{.artifact-menu{display:none}}
27
+ `;
28
+ export const METADATA_SCRIPT = `<script>
29
+ (() => {
30
+ const menus = [...document.querySelectorAll('.artifact-menu')];
31
+ for (const menu of menus) {
32
+ menu.querySelector('summary').addEventListener('click', () => menus.forEach(other => { if (other !== menu) other.open = false; }));
33
+ menu.querySelectorAll('[data-copy-value]').forEach(button => button.addEventListener('click', async () => {
34
+ const status = menu.querySelector('.metadata-feedback');
35
+ const fallback = menu.querySelector('.metadata-fallback');
36
+ status.textContent = ''; fallback.hidden = true;
37
+ try {
38
+ if (!navigator.clipboard?.writeText) throw new Error('Clipboard unavailable');
39
+ await navigator.clipboard.writeText(button.dataset.copyValue);
40
+ status.textContent = 'Copied';
41
+ } catch {
42
+ status.textContent = 'Could not copy. Select and copy the full value below.';
43
+ fallback.value = button.dataset.copyValue; fallback.hidden = false;
44
+ fallback.focus(); fallback.select();
45
+ }
46
+ }));
47
+ }
48
+ document.addEventListener('click', event => menus.forEach(menu => { if (!menu.contains(event.target)) menu.open = false; }));
49
+ document.addEventListener('keydown', event => { if (event.key === 'Escape') menus.forEach(menu => { if (menu.open) { menu.open = false; menu.querySelector('summary').focus(); } }); });
50
+ })();
51
+ </script>`;
52
+ //# sourceMappingURL=metadata-menu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata-menu.js","sourceRoot":"","sources":["../../src/lib/metadata-menu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAiB3C,MAAM,CAAC,MAAM,cAAc,GAAG,gCAAgC,CAAC;AAC/D,MAAM,CAAC,MAAM,YAAY,GAAG,8BAA8B,CAAC;AAC3D,MAAM,IAAI,GAAG,iEAAiE,CAAC;AAC/E,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,KAAa,EAAE,OAAO,GAAG,KAAK,EAAU,EAAE,CACrE,gEAAgE,UAAU,CAAC,KAAK,CAAC,iBAAiB,UAAU,CAAC,KAAK,CAAC,YAAY,UAAU,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC,OAAO,CAAC,+CAA+C,CAAC;AAC1N,MAAM,GAAG,GAAG,CAAC,KAAa,EAAE,KAAa,EAAU,EAAE,CAAC,iCAAiC,UAAU,CAAC,KAAK,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,KAAK,CAAC,WAAW,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,oDAAoD,aAAa,CAAC;AAClP,MAAM,QAAQ,GAAG,2KAA2K,CAAC;AAE7L,MAAM,UAAU,UAAU,CAAC,MAAsB;IAC/C,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,OAAO,CAAC;IACnD,MAAM,IAAI,GAAG,OA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Ac,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,OAAO,CAAC,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,+BAA+B,EAAE,qBAAqB,OAAO,CAAC,EAAE,EAAE,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,0HAA0H,CAAC;IACz7B,OAAO,GAAG,cAAc,uFAAuF,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,iFAAiF,MAAM,CAAC,CAAC,CAAC,YAAY,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,kBAAkB,QAAQ,OAAO,GAAG,QAAQ,mBAAmB,YAAY,EAAE,CAAC;AAC/V,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG;;CAE3B,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;UAuBrB,CAAC"}
@@ -1,5 +1,6 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
1
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
2
2
  import { execFile } from 'node:child_process';
3
+ import { createHash } from 'node:crypto';
3
4
  import { basename, dirname, extname, resolve } from 'node:path';
4
5
  import { promisify } from 'node:util';
5
6
  import { Marked } from 'marked';
@@ -15,11 +16,26 @@ import { HIGHLIGHTS_SCRIPT } from './highlights.js';
15
16
  import { READER_ANCHORS_SCRIPT } from './reader-anchors.js';
16
17
  import { SECTION_COLLAPSE_SCRIPT } from './section-collapse.js';
17
18
  import { linkIconHtml } from './icons.js';
19
+ import { COVER_CSS, coverArtwork, coverClass, creatorFavicon, creatorId, creatorMark } from './creator-cover.js';
20
+ import { artifactTimestamp, FRESHNESS_SCRIPT } from './freshness.js';
21
+ import { knownProjects } from './templates.js';
22
+ import { METADATA_CSS, METADATA_SCRIPT, REVISION_START, REVISION_END, originMenu, revisionMenu } from './metadata-menu.js';
23
+ import { saveRevision } from './revisions.js';
18
24
  import { collectReferences, parseArtifactLinks, referencesHtml, transformLinkPills } from './links.js';
19
25
  import { validateMarkdown } from './validate.js';
20
26
  import { parseWorksheet, renderFieldCard, renderRowsGroup } from './worksheet.js';
21
27
  const execFileAsync = promisify(execFile);
22
28
  const ARTIFACT_SOURCE_ID = 'artifacts-source';
29
+ // The single canonical live-reload marker: a SHA-256 over the WHOLE finished
30
+ // document (body plus every metadata surface), so any re-render change — content
31
+ // or metadata-only — flips it. Computed by hashing the document with this fixed
32
+ // placeholder standing in for the value, then substituting the real digest, so
33
+ // the hash never has to include itself. The loopback reload poll (reloadScript)
34
+ // and the collab body-revision (collab.ts) are deliberately separate concerns:
35
+ // body-revision is body-only so a comment stays anchored across a metadata edit,
36
+ // while this marker must notice exactly those metadata edits.
37
+ const CONTENT_HASH_META = 'artifacts-content-hash';
38
+ const CONTENT_HASH_PLACEHOLDER = '__ARTIFACTS_CONTENT_HASH__';
23
39
  // Marks a heading that came from Markdown, so it can be told apart from an <h2>
24
40
  // an author wrote inside an embedded block. A private-use character rather than
25
41
  // an attribute: an attribute would have to be allowlisted through the sanitizer,
@@ -113,6 +129,12 @@ const HARNESS_PRODUCT_NAMES = {
113
129
  droid: 'Droid',
114
130
  antigravity: 'Antigravity',
115
131
  kimi: 'Kimi',
132
+ opencode: 'OpenCode',
133
+ openclaw: 'OpenClaw',
134
+ hermes: 'Hermes',
135
+ muse: 'Muse',
136
+ warp: 'Warp',
137
+ pi: 'Pi',
116
138
  };
117
139
  /**
118
140
  * Single human-facing agent string: product + model (e.g. "Grok 4.5"),
@@ -125,7 +147,7 @@ export function agentDisplayName(harness, agent) {
125
147
  return '';
126
148
  if (!h)
127
149
  return a;
128
- const product = HARNESS_PRODUCT_NAMES[h.toLowerCase()]
150
+ const product = (Object.hasOwn(HARNESS_PRODUCT_NAMES, h.toLowerCase()) ? HARNESS_PRODUCT_NAMES[h.toLowerCase()] : undefined)
129
151
  ?? (h.charAt(0).toUpperCase() + h.slice(1));
130
152
  if (!a)
131
153
  return product;
@@ -136,6 +158,14 @@ export function agentDisplayName(harness, agent) {
136
158
  return `${product} ${stripped}`;
137
159
  return `${product} ${a}`;
138
160
  }
161
+ /** Cap the project prefix used in the browser <title> so a long/dotted/dashed
162
+ * project name can never push the artifact's own topic out of the tab. The hero
163
+ * still shows the project verbatim; only the tab prefix is bounded. */
164
+ function boundedTitlePrefix(project, max = 24) {
165
+ const trimmed = project.trim();
166
+ const points = [...trimmed];
167
+ return points.length > max ? `${points.slice(0, max - 1).join('').trimEnd()}…` : trimmed;
168
+ }
139
169
  function metadataValue(value) {
140
170
  if (value instanceof Date)
141
171
  return value.toISOString().slice(0, 10);
@@ -148,6 +178,24 @@ function repositoryHref(repository) {
148
178
  ? `https://github.com/${repository}`
149
179
  : undefined;
150
180
  }
181
+ /** The bare project name from an `owner/repo` (or plain) repository string. */
182
+ function repositoryBasename(repository) {
183
+ return repository.split('/').filter(Boolean).at(-1) || '';
184
+ }
185
+ /** Explicit author dates, otherwise the source mtime; never the render time. */
186
+ function buildTimestamps(data, sourceMtimeIso) {
187
+ const stamp = (label, value) => ({ label, ...value, display: value.iso.slice(0, 10) });
188
+ const created = artifactTimestamp(data.created);
189
+ const updated = artifactTimestamp(data.updated);
190
+ const stamps = [];
191
+ if (created)
192
+ stamps.push(stamp('Created', created));
193
+ if (updated)
194
+ stamps.push(stamp('Updated', updated));
195
+ else if (sourceMtimeIso)
196
+ stamps.push(stamp('Source updated', { iso: sourceMtimeIso, relative: true }));
197
+ return stamps;
198
+ }
151
199
  /**
152
200
  * A deep link that resumes this session. Clicking it hands the URL to the OS,
153
201
  * which routes it to the registered `agents open` handler (agents-cli) — the CLI
@@ -159,36 +207,49 @@ function sessionDeepLink(id) {
159
207
  const trimmed = id.trim();
160
208
  return trimmed ? `agents://session/${encodeURIComponent(trimmed)}` : undefined;
161
209
  }
162
- function artifactMetadata(data) {
210
+ function artifactMetadata(data, sourceMtimeIso = '') {
163
211
  const field = (name) => metadataValue(data[name]);
164
212
  const facts = Array.isArray(data.facts)
165
213
  ? data.facts.map(metadataValue).filter(Boolean)
166
214
  : [];
167
215
  const repository = field('repository');
168
216
  const branch = field('branch');
169
- const harness = field('harness');
217
+ const harness = creatorId(field('harness'));
170
218
  const agent = field('agent');
171
219
  const agentLabel = agentDisplayName(harness, agent);
172
220
  const { links } = parseArtifactLinks(data.links);
173
- // Work-first kicker: project · kind (context stays out of the eyebrow).
174
- const kicker = [field('project'), field('kind')].filter(Boolean);
175
- if (!kicker.length && field('context'))
176
- kicker.push(field('context'));
221
+ // The project the artifact is *about* — prominent, and linked when we can point
222
+ // somewhere honest. An explicit project wins; otherwise fall back to the
223
+ // repository's bare name (the render-layer fallback; project detection itself
224
+ // lives in templates.ts and is out of scope here). The link is an explicit
225
+ // `projectUrl` when it is HTTP(S), else the repository's own GitHub page.
226
+ const projectId = field('project');
227
+ const registered = projectId ? knownProjects().filter((project) => project.name === projectId) : [];
228
+ const known = registered.length === 1 ? registered[0] : undefined;
229
+ const projectValue = known?.displayName || projectId || repositoryBasename(repository);
230
+ const projectUrl = field('projectUrl');
231
+ const projectHref = (/^https?:\/\//i.test(projectUrl) ? projectUrl : undefined)
232
+ ?? known?.url ?? repositoryHref(repository || known?.repo || '');
233
+ const project = projectValue ? { value: projectValue, href: projectHref } : null;
177
234
  return {
178
- kicker,
235
+ project,
236
+ kind: field('kind') || field('context'),
179
237
  status: field('status'),
238
+ creator: { agent: agentLabel, harness, human: field('human') },
239
+ origin: { agent: agentLabel, version: field('harnessVersion'), host: field('host'), platform: field('hostPlatform'), arch: field('hostArch'), session: field('session'), sessionId: field('sessionId') },
240
+ timestamps: buildTimestamps(data, sourceMtimeIso),
180
241
  facts,
181
242
  links: links.map((link) => ({
182
243
  value: link.label,
183
244
  href: link.url,
184
245
  icon: linkIconHtml(link.url),
185
246
  })),
247
+ // The long tail — everything a reader rarely needs at a glance. Folded behind
248
+ // a <details> in the hero. Creator and freshness moved up to their own lines.
186
249
  provenance: [
187
250
  repository ? { value: repository, href: repositoryHref(repository) } : undefined,
188
251
  branch ? { value: branch } : undefined,
189
252
  field('tracking') ? { value: field('tracking') } : undefined,
190
- agentLabel ? { value: agentLabel } : undefined,
191
- field('human') ? { value: field('human') } : undefined,
192
253
  field('host') ? { value: field('host') } : undefined,
193
254
  field('session') ? { value: field('session'), href: sessionDeepLink(field('sessionId') || field('session')) } : undefined,
194
255
  field('date') ? { value: field('date') } : undefined,
@@ -207,11 +268,44 @@ function statusBadge(status) {
207
268
  const slug = slugify(status) || 'unknown';
208
269
  return `<span class="status-badge status-${escapeHtml(slug)}">${escapeHtml(status)}</span>`;
209
270
  }
271
+ /**
272
+ * The eyebrow above the title. The project comes first and prominent — linked
273
+ * when a URL is known — followed by the kind, then the status badge. An artifact
274
+ * with no project or kind still shows a stable "Artifact" label.
275
+ */
210
276
  function kickerHtml(metadata) {
211
- const parts = (metadata.kicker.length ? metadata.kicker : ['Artifact'])
212
- .map((part) => `<span class="kicker-part">${escapeHtml(part)}</span>`)
213
- .join('<span class="kicker-separator" aria-hidden="true">&middot;</span>');
214
- return `<div class="kicker">${parts}${statusBadge(metadata.status)}</div>`;
277
+ const parts = [];
278
+ if (metadata.kind)
279
+ parts.push(`<span class="kicker-part">${escapeHtml(metadata.kind)}</span>`);
280
+ if (!parts.length)
281
+ parts.push(`<span class="kicker-part">Artifact</span>`);
282
+ return `<div class="kicker">${parts.join('<span class="kicker-separator" aria-hidden="true">&middot;</span>')}${statusBadge(metadata.status)}</div>`;
283
+ }
284
+ /**
285
+ * The compact "who made this, and how fresh is it" line under the title: the
286
+ * agent's brand mark + product name, the human, then the truthful freshness
287
+ * stamps. Date-only values stay absolute; precise instants gain relative text.
288
+ */
289
+ function creatorLine(metadata) {
290
+ const parts = [];
291
+ const { human } = metadata.creator;
292
+ if (human)
293
+ parts.push(`<span class="creator-human">${escapeHtml(human)}</span>`);
294
+ for (const time of metadata.timestamps) {
295
+ parts.push(`<time class="creator-time" datetime="${escapeHtml(time.iso)}" title="${escapeHtml(time.label + ' ' + time.iso)}" data-label="${escapeHtml(time.label)}" data-relative="${time.relative}">${escapeHtml(time.label)} ${escapeHtml(time.display)}</time>`);
296
+ }
297
+ if (!parts.length)
298
+ return '';
299
+ return `<p class="creator-line" aria-label="Creator and freshness">${parts.join('<span class="meta-sep" aria-hidden="true">·</span>')}</p>`;
300
+ }
301
+ function coverTop(metadata) {
302
+ const { agent, harness } = metadata.creator;
303
+ const producer = `<div class="cover-creator creator-agent">${creatorMark(harness)}<span>${escapeHtml(agent || 'Artifact')}</span></div>`;
304
+ const project = metadata.project;
305
+ const home = !project ? '' : project.href
306
+ ? `<a class="cover-project kicker-project" href="${escapeHtml(project.href)}" title="${escapeHtml(project.value)}" target="_blank" rel="noopener">${escapeHtml(project.value)}<span aria-hidden="true">↗</span></a>`
307
+ : `<span class="cover-project kicker-project">${escapeHtml(project.value)}</span>`;
308
+ return `<div class="cover-top">${producer}${home}</div>`;
215
309
  }
216
310
  function factsLine(facts) {
217
311
  if (!facts.length)
@@ -238,11 +332,21 @@ function provenanceLine(parts) {
238
332
  });
239
333
  return `<p class="provenance-line" aria-label="Provenance">${items.join('<span class="meta-sep" aria-hidden="true">·</span>')}</p>`;
240
334
  }
335
+ /**
336
+ * The long provenance tail — repository, branch, tracking, host, session, date —
337
+ * folded behind a disclosure so the hero stays scannable. Print events open it
338
+ * and restore the reader's state afterward, so a PDF never drops provenance.
339
+ */
340
+ function provenanceDetails(parts) {
341
+ if (!parts.length)
342
+ return '';
343
+ return `<details class="provenance-details"><summary>Details</summary>${provenanceLine(parts)}</details>`;
344
+ }
241
345
  function metadataBlock(metadata) {
242
346
  const body = [
243
347
  factsLine(metadata.facts),
244
348
  linksBlock(metadata.links),
245
- provenanceLine(metadata.provenance),
349
+ provenanceDetails(metadata.provenance),
246
350
  ].filter(Boolean).join('');
247
351
  return body ? `<div class="meta" aria-label="Artifact metadata">${body}</div>` : '';
248
352
  }
@@ -273,6 +377,16 @@ function inlineLocalAssets(html, baseDir, diagnostics) {
273
377
  return ` src="data:${mimeFor(path)};base64,${data}"`;
274
378
  });
275
379
  }
380
+ /** The source file's last-modified instant as ISO 8601, or '' when it cannot be
381
+ * stat'd. The honest fallback for freshness when no explicit `updated:` exists. */
382
+ function fileMtimeIso(path) {
383
+ try {
384
+ return statSync(path).mtime.toISOString();
385
+ }
386
+ catch {
387
+ return '';
388
+ }
389
+ }
276
390
  export function slugify(text) {
277
391
  return text.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
278
392
  }
@@ -687,6 +801,16 @@ function shell(title, summary, header, footer, metadata, body, source, styles, d
687
801
  </script>`;
688
802
  const readerScript = `<script>
689
803
  (() => {
804
+ const disclosures = [...document.querySelectorAll('.provenance-details')];
805
+ const printState = new Map();
806
+ addEventListener('beforeprint', () => disclosures.forEach((details) => {
807
+ if (!printState.has(details)) printState.set(details, details.open);
808
+ details.open = true;
809
+ }));
810
+ addEventListener('afterprint', () => {
811
+ printState.forEach((open, details) => { details.open = open; });
812
+ printState.clear();
813
+ });
690
814
  // Scroll-spy: mark the section the reader is currently in. The active heading
691
815
  // is the last one whose top has passed the reading line, so a heading is
692
816
  // "current" from the moment it reaches the top, not when it leaves.
@@ -746,19 +870,40 @@ function shell(title, summary, header, footer, metadata, body, source, styles, d
746
870
  } catch {}
747
871
  })();
748
872
  </script>`;
873
+ // Live-reload detection, keyed to the single canonical marker the renderer
874
+ // emits: <meta name="artifacts-content-hash">, hashed over the whole document,
875
+ // so a metadata-only re-render (a new `updated:` stamp, a changed project) is
876
+ // detected too. Manual by default — a new version reveals the chip rather than
877
+ // reloading under the reader, so an unsaved worksheet field or scroll position
878
+ // survives until they choose to reload.
879
+ //
880
+ // Only http(s) can be watched: a loopback dev server (`artifacts render --open`)
881
+ // re-renders the file on save, and a same-origin poll of this page sees the new
882
+ // hash. A file:// page has no server to re-serve it, so disk changes are
883
+ // invisible to the page; the chip stays hidden there by design.
749
884
  const reloadScript = `<script>
750
885
  (() => {
751
- const current = document.querySelector('meta[name="artifacts-content-hash"]')?.content;
886
+ const marker = (html) => html.match(/<meta name="artifacts-content-hash" content="([^"]+)">/)?.[1] || '';
887
+ const current = document.querySelector('meta[name="artifacts-content-hash"]')?.content || '';
752
888
  const chip = document.querySelector('.reload-chip');
753
- if (!current || !chip || !['127.0.0.1', 'localhost', '::1'].includes(location.hostname)) return;
889
+ if (!current || !chip) return;
890
+ // file:// (and any non-web scheme) cannot be re-fetched for a fresh render.
891
+ if (location.protocol !== 'http:' && location.protocol !== 'https:') return;
754
892
  chip.addEventListener('click', () => location.reload());
893
+ let inFlight = false;
755
894
  const check = async () => {
895
+ // Pause while the tab is hidden and never overlap a slow fetch with the next.
896
+ if (inFlight || document.hidden) return;
897
+ inFlight = true;
756
898
  try {
757
- const response = await fetch(location.href, { cache: 'no-store' });
758
- const html = await response.text();
759
- const next = html.match(/<meta name="artifacts-content-hash" content="([^"]+)">/)?.[1];
899
+ // Same-origin by construction (this page's own URL); only a successful
900
+ // response is trusted — a transient 5xx or a dropped dev server never
901
+ // flips the chip.
902
+ const response = await fetch(location.href, { cache: 'no-store', redirect: 'error', signal: AbortSignal.timeout(8000) });
903
+ if (!response.ok) return;
904
+ const next = marker(await response.text());
760
905
  if (next && next !== current) chip.hidden = false;
761
- } catch {}
906
+ } catch {} finally { inFlight = false; }
762
907
  };
763
908
  setInterval(check, 1500);
764
909
  })();
@@ -856,21 +1001,32 @@ function shell(title, summary, header, footer, metadata, body, source, styles, d
856
1001
  })();
857
1002
  </script>` : '';
858
1003
  const worksheetToolbar = worksheet ? `<div class="wq-toolbar" role="toolbar" aria-label="Worksheet actions"><button type="button" data-wq-action="save">Save</button><button type="button" data-wq-action="export">Export answers</button><button type="button" data-wq-action="copy-markdown">Copy answers as Markdown</button><button type="button" data-wq-action="print">Print / PDF</button><button type="button" data-wq-action="reset">Reset drafts</button><span class="wq-status" aria-live="polite">loading</span></div>` : '';
859
- return `<!doctype html>
1004
+ // Prefix the browser tab with the project, so a wall of open plan tabs is
1005
+ // scannable by project rather than by identical leading words. The prefix is
1006
+ // length-bounded (the hero shows the project verbatim); a very long project
1007
+ // name is truncated with an ellipsis so the artifact's own topic always
1008
+ // survives in the tab title.
1009
+ const documentTitle = metadata.project
1010
+ ? `${boundedTitlePrefix(metadata.project.value)} — ${title}`
1011
+ : title;
1012
+ const document = `<!doctype html>
860
1013
  <html lang="en"${themeAttribute}>
861
1014
  <head>
862
1015
  <meta charset="utf-8">
863
1016
  <meta name="viewport" content="width=device-width, initial-scale=1">
864
1017
  <meta name="robots" content="noindex">
1018
+ <meta name="${CONTENT_HASH_META}" content="${CONTENT_HASH_PLACEHOLDER}">
865
1019
  <meta name="${BODY_REVISION_META}" content="${escapeHtml(revision)}">
866
- <title>${escapeHtml(title)}</title>
1020
+ <title>${escapeHtml(documentTitle)}</title>
1021
+ ${creatorFavicon(metadata.creator.harness)}
867
1022
  <style>
868
1023
  ${styles}
869
1024
  .reader-highlight{background:color-mix(in srgb,var(--warn) 38%,var(--bg));color:inherit;border-radius:2px;box-decoration-break:clone;-webkit-box-decoration-break:clone;cursor:pointer}.reader-highlight:hover{background:color-mix(in srgb,var(--warn) 55%,var(--bg))}.reload-chip{display:inline-flex;align-items:center;height:30px;margin-right:8px;padding:0 12px;border:1px solid color-mix(in srgb,var(--accent) 40%,var(--line));border-radius:999px;background:color-mix(in srgb,var(--accent) 12%,var(--surface));color:var(--accent);font:500 12px/1 var(--font-mono);cursor:pointer}.reload-chip[hidden]{display:none}
1025
+ .kicker-project{color:var(--accent);font-weight:700;letter-spacing:.1em;text-decoration:none}.kicker-project:hover{text-decoration:underline}.creator-line{display:flex;flex-wrap:wrap;align-items:center;margin:14px 0 0;color:var(--muted);font-family:var(--font-mono);font-size:12px;line-height:1.6}.creator-agent{display:inline-flex;align-items:center;color:var(--text)}.creator-agent .chip-icon{width:13px;height:13px;margin-right:6px;vertical-align:-2px;fill:currentColor;flex:0 0 auto}.creator-human{color:var(--muted)}.creator-time{color:var(--muted)}.provenance-details{color:var(--muted);font-family:var(--font-mono);font-size:12px}.provenance-details>summary{cursor:pointer;color:var(--muted);text-transform:uppercase;letter-spacing:.1em;font-size:10.5px;list-style:none;width:fit-content}.provenance-details>summary::-webkit-details-marker{display:none}.provenance-details>summary::before{content:"\\25B8";display:inline-block;margin-right:6px;font-size:9px;transition:transform .12s ease}.provenance-details[open]>summary::before{transform:rotate(90deg)}.provenance-details>summary:hover{color:var(--accent)}.provenance-details .provenance-line{margin-top:8px}
870
1026
  *{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--text);font-family:var(--font-body);line-height:1.6;-webkit-font-smoothing:antialiased;transition:background-color .15s ease,color .15s ease}main{width:100%;max-width:var(--content-width);min-width:0;margin:0 auto;padding:24px var(--page-padding) 80px}.document-header{display:flex;align-items:center;justify-content:flex-end;min-height:42px;border-bottom:1px solid var(--line);color:var(--muted);font-family:var(--font-mono);font-size:12px}.header-label{min-width:0;margin-right:auto;padding-right:12px;overflow-wrap:anywhere;color:var(--text);font-weight:650}.theme-toggle{display:inline-flex;flex:0 0 auto;align-items:center;gap:6px;height:30px;padding:0 12px;border:1px solid var(--line);border-radius:999px;background:var(--surface);color:var(--muted);font:500 12px/1 var(--font-mono);cursor:pointer}.theme-toggle:hover{color:var(--accent);border-color:var(--accent)}.theme-toggle:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.hero{padding:var(--hero-top) 0 var(--hero-bottom);border-bottom:1px solid var(--line)}.kicker{display:flex;flex-wrap:wrap;align-items:center;gap:8px 10px;font-family:var(--font-mono);font-size:12px;text-transform:uppercase;letter-spacing:.14em;color:var(--accent);font-weight:500}.kicker-part{color:var(--accent)}.kicker-separator{color:var(--muted);padding:0 2px}.status-badge{display:inline-flex;align-items:center;height:22px;padding:0 9px;border-radius:999px;border:1px solid color-mix(in srgb,var(--warn) 40%,var(--line));background:color-mix(in srgb,var(--warn) 14%,transparent);color:var(--warn);font-family:var(--font-mono);font-size:10.5px;font-weight:650;letter-spacing:.1em;text-transform:uppercase;line-height:1}.status-badge.status-implementing,.status-badge.status-in-progress,.status-badge.status-review,.status-badge.status-done,.status-badge.status-complete{border-color:color-mix(in srgb,var(--accent) 40%,var(--line));background:color-mix(in srgb,var(--accent) 12%,transparent);color:var(--accent)}.hero h1{font-family:var(--font-display);font-size:clamp(30px,4vw,44px);line-height:1.1;margin:12px 0 14px;letter-spacing:-.01em}.summary{max-width:760px;color:var(--muted);font-size:17px;margin:0}.meta{display:grid;gap:14px;margin-top:20px}.facts-line{margin:0;color:var(--muted);font-family:var(--font-mono);font-size:12.5px;line-height:1.7}.meta-block{display:grid;gap:8px}.meta-label{font-family:var(--font-mono);font-size:10.5px;letter-spacing:.12em;text-transform:uppercase;color:var(--muted);font-weight:500}.meta-row{display:flex;flex-wrap:wrap;gap:8px;list-style:none;margin:0;padding:0}.chip{display:inline-flex;align-items:center;gap:4px;max-width:100%;border:1px solid var(--line);background:var(--surface);border-radius:999px;padding:4px 11px;color:var(--muted);font-family:var(--font-mono);font-size:11.5px;line-height:1.5}.chip-value{color:var(--text);overflow-wrap:anywhere}.chip-icon{display:inline-block;width:12px;height:12px;margin-right:5px;vertical-align:-1.5px;fill:currentColor;flex:0 0 auto}.chip-favicon{display:inline-block;width:12px;height:12px;margin-right:5px;vertical-align:-1.5px;border-radius:2px;object-fit:contain;flex:0 0 auto}.chip-value a{color:inherit;text-decoration:none}.chip-value a:hover{text-decoration:underline}.provenance-line{margin:0;color:var(--muted);font-family:var(--font-mono);font-size:12.5px;line-height:1.7}.provenance-line a{color:var(--accent-alt);text-decoration:none}.provenance-line a:hover{text-decoration:underline}.provenance-part{color:var(--muted)}.meta-sep{margin:0 7px;opacity:.45}.toc{display:grid;gap:4px;margin:24px 0 8px;font-family:var(--font-mono);font-size:13px}.toc-item{display:block;padding:2px 0 2px 10px;border-left:2px solid transparent;color:var(--muted);text-decoration:none;overflow-wrap:anywhere}.toc-item.toc-sub{padding-left:24px;font-size:.92em;opacity:.85}.toc-item:hover{color:var(--accent)}.toc-item.is-active{color:var(--accent);border-left-color:var(--accent)}.toc-item.is-active .toc-index{opacity:1}@media (min-width:1380px){.toc{position:fixed;top:88px;left:max(20px,calc(50% - var(--content-width)/2 - 236px));width:212px;max-height:calc(100vh - 132px);overflow-y:auto;margin:0;z-index:5;scrollbar-width:thin}.toc::-webkit-scrollbar{width:6px}.toc::-webkit-scrollbar-thumb{background:var(--line);border-radius:3px}}@media (max-width:1379px){.toc-item.toc-sub{display:none}}.code-diff{margin:var(--figure-spacing) 0;border:1px solid var(--line);border-radius:var(--radius);overflow:hidden;background:var(--code)}.code-diff-pre{margin:0;padding:10px 0;background:none;border:none;border-radius:0;overflow-x:auto;font-family:var(--font-mono);font-size:12.5px;line-height:1.55;color:var(--code-text)}.cd-line{display:block;white-space:pre;padding:0 14px}.cd-sign{display:inline-block;width:1.4ch;color:var(--muted);user-select:none}.cd-add{background:color-mix(in srgb,var(--accent) 15%,transparent)}.cd-add .cd-sign{color:var(--accent)}.cd-del{background:color-mix(in srgb,var(--danger) 15%,transparent)}.cd-del .cd-sign{color:var(--danger)}.cd-hunk,.cd-meta{color:var(--muted);opacity:.8}.code-diff>summary{list-style:none;cursor:pointer;padding:8px 14px;font-family:var(--font-mono);font-size:12px;color:var(--code-text);background:color-mix(in srgb,var(--code-text) 8%,var(--code));border-bottom:1px solid transparent;user-select:none}.code-diff[open]>summary{border-bottom-color:color-mix(in srgb,var(--code-text) 15%,transparent)}.code-diff>summary::-webkit-details-marker{display:none}.code-diff>summary::before{content:"\\25B8";display:inline-block;margin-right:7px;color:color-mix(in srgb,var(--code-text) 55%,transparent);font-size:10px;transition:transform .12s ease}.code-diff[open]>summary::before{transform:rotate(90deg)}.checklist{margin:var(--figure-spacing) 0;border:1px solid var(--line);border-radius:var(--radius);background:var(--surface);padding:var(--panel-padding)}.checklist-head{font-family:var(--font-mono);font-size:11px;text-transform:uppercase;letter-spacing:.1em;color:var(--muted);margin-bottom:10px}.checklist-items{list-style:none;margin:0;padding:0;display:grid;gap:7px}.cl-item{display:flex;align-items:baseline;gap:9px}.cl-box{flex:0 0 auto;font-family:var(--font-mono);font-size:.95em}.cl-done .cl-box{color:var(--accent)}.cl-todo .cl-box{color:var(--muted)}.cl-doing .cl-box{color:var(--warn)}.cl-done .cl-text{color:var(--muted);text-decoration:line-through;text-decoration-color:var(--line)}.toc a{color:var(--muted);text-decoration:none}.toc a:hover{color:var(--accent)}.toc a:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.toc-index{color:var(--accent);font-family:var(--font-mono);font-size:.9em}.artifact-body{min-width:0;padding-top:18px;counter-reset:section}h2{font-size:24px;margin:var(--section-spacing) 0 12px;line-height:1.2;letter-spacing:-.01em}.artifact-section>h2{counter-increment:section}.artifact-section>h2::before{content:counter(section,decimal-leading-zero);font-family:var(--font-mono);font-size:.62em;color:var(--accent);margin-right:10px;opacity:.85}h3{font-size:17px;margin:calc(var(--section-spacing) * .78) 0 10px}.artifact-section-body[hidden]{display:none}.section-toggle{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;margin-left:8px;padding:0;border:1px solid var(--line);border-radius:6px;background:var(--surface);color:var(--muted);cursor:pointer;vertical-align:middle;flex:0 0 auto}.section-toggle:hover{color:var(--accent);border-color:var(--accent)}.section-toggle:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.section-toggle::before{content:"\\25BE";display:block;font-size:10px;line-height:1;transition:transform .12s ease}.section-toggle[aria-expanded="false"]::before{transform:rotate(-90deg)}.toc-collapse-actions{display:flex;gap:10px;margin:0 0 8px 10px}.toc-collapse-actions button{border:none;background:none;padding:0;color:var(--muted);font-family:var(--font-mono);font-size:11px;text-transform:uppercase;letter-spacing:.06em;cursor:pointer}.toc-collapse-actions button:hover{color:var(--accent)}.toc-collapse-actions button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}a{color:var(--accent);text-decoration:none}a:hover{text-decoration:underline}.link-pill{display:inline-flex;align-items:center;gap:4px;max-width:100%;padding:0 6px;border:1px solid var(--line);border-radius:6px;background:var(--surface-alt);color:var(--text);font-size:.92em;line-height:1.35;text-decoration:none;vertical-align:baseline;transition:border-color .12s ease,color .12s ease,background-color .12s ease}.link-pill:hover{border-color:var(--accent);color:var(--accent);background:color-mix(in srgb,var(--accent) 10%,var(--surface-alt));text-decoration:none}.link-pill:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.link-pill-icon{width:12px;height:12px;flex:0 0 auto;fill:currentColor;opacity:.9}.link-pill-favicon{display:inline-block;width:12px;height:12px;flex:0 0 auto;border-radius:3px;object-fit:contain}.link-pill-text{min-width:0;overflow-wrap:anywhere}.link-pill code{background:none;border:none;padding:0;color:inherit}td .link-pill,li .link-pill{vertical-align:-1px}p,li,dd,figcaption{overflow-wrap:anywhere}pre{background:var(--code);color:var(--code-text);padding:var(--panel-padding);border-radius:12px;overflow:auto;border:1px solid var(--line)}code{font-family:var(--font-mono);font-size:.88em;background:var(--surface-alt);border:1px solid var(--line);border-radius:5px;padding:1.5px 6px;color:var(--accent-alt)}pre code{background:none;border:none;padding:0;color:inherit}table{width:100%;border-collapse:collapse;margin:18px 0}th,td{border-bottom:1px solid var(--line);padding:10px;text-align:left;vertical-align:top}th{font-family:var(--font-mono);font-size:11.5px;letter-spacing:.06em;text-transform:uppercase;color:var(--muted);font-weight:500}blockquote{border-left:3px solid var(--accent);padding-left:var(--panel-padding);color:var(--muted);margin-left:0}img{display:block;max-width:100%;height:auto}svg{max-width:100%;height:auto}.artifact-body>p>img{margin:var(--figure-spacing) auto}.artifact-grid{display:grid;gap:var(--panel-padding);margin:var(--figure-spacing) 0}.artifact-grid-2{grid-template-columns:repeat(2,minmax(0,1fr))}.artifact-grid-3{grid-template-columns:repeat(3,minmax(0,1fr))}.artifact-panel,.artifact-stat{min-width:0;border:1px solid var(--line);border-radius:var(--radius);background:var(--surface);padding:var(--panel-padding)}.artifact-panel h3{margin:10px 0 8px;font-size:16px}.artifact-stat-value,.artifact-stat-label{display:block}.artifact-stat-value{color:var(--text);font-family:var(--font-display);font-size:24px;line-height:1.15}.artifact-stat-label{margin-top:6px;color:var(--muted);font-size:13px}.artifact-tag{display:inline-block;--tag-color:var(--muted);background:color-mix(in srgb,var(--tag-color) 12%,transparent);border:1px solid color-mix(in srgb,var(--tag-color) 30%,transparent);border-radius:6px;padding:2px 8px;color:var(--tag-color);font-family:var(--font-mono);font-size:11px;font-weight:600;text-transform:uppercase}.artifact-tag-accent{--tag-color:var(--accent)}.artifact-callout{margin:var(--figure-spacing) 0;border:1px solid var(--line);border-left:3px solid var(--accent);border-radius:0 var(--radius) var(--radius) 0;background:var(--surface-alt);padding:var(--panel-padding)}.artifact-callout-warn{border-left-color:var(--warn)}.artifact-callout-danger{border-left-color:var(--danger)}.artifact-callout strong{color:var(--text)}.artifact-figure{margin:var(--figure-spacing) 0;border:1px solid var(--line);border-radius:var(--radius);background:var(--surface);padding:var(--panel-padding);overflow-x:auto}.artifact-figure>img,.artifact-image{width:auto;max-width:100%;height:auto;margin:0 auto}.artifact-figure-diagram{background:#0e120f;border-color:#26302a}.artifact-diagram{display:block;width:100%;height:auto;margin:0 auto}.artifact-figure-tall{width:100%;max-width:394px;margin-left:auto;margin-right:auto}.artifact-figure figcaption{margin-top:12px;color:var(--muted);font-family:var(--font-mono);font-size:12px;text-align:center}.artifact-figure.artifact-figure-diagram figcaption{color:#8b938c}.artifact-legend{display:flex;flex-wrap:wrap;gap:8px 16px;margin:12px 0;color:var(--muted);font-family:var(--font-mono);font-size:11.5px}.artifact-behavior{margin:var(--figure-spacing) 0;border:1px solid var(--line);border-radius:var(--radius);overflow:hidden;display:grid;grid-template-columns:1fr 1fr}.artifact-behavior-panel{padding:var(--panel-padding);background:var(--surface)}.artifact-behavior-panel+.artifact-behavior-panel{border-left:1px solid var(--line)}.artifact-behavior-panel::before{display:block;font-family:var(--font-mono);font-size:10.5px;text-transform:uppercase;letter-spacing:.12em;color:var(--muted);font-weight:500;margin-bottom:8px;content:""}.artifact-behavior-panel[data-state="current"]::before{content:"Current"}.artifact-behavior-panel[data-state="proposed"]{background:color-mix(in srgb,var(--accent) 6%,var(--surface))}.artifact-behavior-panel[data-state="proposed"]::before{content:"Proposed";color:var(--accent)}.document-footer{margin-top:var(--footer-spacing);padding-top:18px;border-top:1px solid var(--line);color:var(--muted);font-family:var(--font-mono);font-size:12px}.references-list{margin:0;padding-left:1.6em;display:grid;gap:7px}.reference-item{color:var(--muted)}.reference-item::marker{font-family:var(--font-mono);font-size:.86em;color:var(--muted)}.reference-link{display:inline-flex;align-items:center;gap:7px;max-width:100%;color:var(--text);text-decoration:none;overflow-wrap:anywhere}.reference-link:hover{color:var(--accent);text-decoration:none}.reference-link:hover .reference-text{text-decoration:underline}.reference-host{color:var(--muted);font-family:var(--font-mono);font-size:.82em}.view-count{color:var(--muted);font-family:var(--font-mono);font-size:11.5px;margin-right:12px;white-space:nowrap}
871
1027
  .artifact-figure-diagram{--artifact-fg:#e7ece8;--artifact-muted:#b7c0b8;--artifact-accent:#a3e635}.artifact-figure.artifact-figure-diagram figcaption{color:var(--artifact-muted)}
872
1028
  @media(max-width:720px){main{padding:32px var(--mobile-page-padding) 64px}.artifact-grid-2,.artifact-grid-3{grid-template-columns:1fr}.artifact-figure{padding:min(12px,var(--panel-padding))}.artifact-figure-wide .artifact-diagram{min-width:640px}.artifact-behavior{grid-template-columns:1fr}.artifact-behavior-panel+.artifact-behavior-panel{border-left:none;border-top:1px solid var(--line)}table{display:block;max-width:100%;overflow-x:auto}th,td{min-width:140px;overflow-wrap:anywhere}pre{white-space:pre-wrap;overflow-wrap:anywhere}}
873
- @media print{body{transition:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}.toc,.theme-toggle,.view-count{display:none}.section-toggle{display:none}.artifact-section-body[hidden]{display:block!important}.document-header-empty{display:none}main{max-width:none;padding:0}:root[data-pdf-layout="poster"] main{max-width:var(--content-width);margin:0 auto;padding:var(--print-margin)}.chip{background:var(--surface)}.chip-value{color:var(--text)}.provenance-line,.provenance-line a,.facts-line{color:var(--text)}.status-badge{color:var(--text);border-color:var(--line)}h2,h3{break-after:avoid-page}.artifact-figure,.artifact-grid,.artifact-panel,.artifact-stat,.artifact-callout,.artifact-behavior,pre,table,blockquote,.meta{break-inside:avoid}.artifact-figure-wide .artifact-diagram{min-width:0}.artifact-figure-tall{max-width:330px}pre{white-space:pre-wrap;overflow-wrap:anywhere}a{color:var(--text);text-decoration:underline}.link-pill{color:var(--text);text-decoration:none;background:var(--surface);border-color:var(--line);break-inside:avoid}}
1029
+ @media print{body{transition:none;-webkit-print-color-adjust:exact;print-color-adjust:exact}.toc,.theme-toggle,.view-count{display:none}.section-toggle{display:none}.artifact-section-body[hidden]{display:block!important}.document-header-empty{display:none}main{max-width:none;padding:0}:root[data-pdf-layout="poster"] main{max-width:var(--content-width);margin:0 auto;padding:var(--print-margin)}.chip{background:var(--surface)}.chip-value{color:var(--text)}.provenance-line,.provenance-line a,.facts-line{color:var(--text)}.creator-line,.creator-agent,.creator-human,.creator-time{color:var(--text)}.provenance-details>summary{display:none}.provenance-details>.provenance-line{display:block!important}.status-badge{color:var(--text);border-color:var(--line)}h2,h3{break-after:avoid-page}.artifact-figure,.artifact-grid,.artifact-panel,.artifact-stat,.artifact-callout,.artifact-behavior,pre,table,blockquote,.meta{break-inside:avoid}.artifact-figure-wide .artifact-diagram{min-width:0}.artifact-figure-tall{max-width:330px}pre{white-space:pre-wrap;overflow-wrap:anywhere}a{color:var(--text);text-decoration:underline}.link-pill{color:var(--text);text-decoration:none;background:var(--surface);border-color:var(--line);break-inside:avoid}}
874
1030
  </style>
875
1031
  ${worksheet ? `<style>
876
1032
  .wq-toolbar{position:sticky;top:0;z-index:10;display:flex;flex-wrap:wrap;align-items:center;gap:8px;padding:10px 0;border-bottom:1px solid var(--line);background:var(--bg)}
@@ -890,21 +1046,26 @@ ${worksheet ? `<style>
890
1046
  </head>
891
1047
  <body>
892
1048
  <main>
893
- <header class="document-header${header ? '' : ' document-header-empty'}">${header ? `<div class="header-label">${escapeHtml(header)}</div>` : ''}<span class="view-count" hidden></span><button class="reload-chip" type="button" hidden>Updated · Reload</button><button class="theme-toggle" type="button" aria-label="Toggle color theme" aria-pressed="false" title="Toggle color theme"><span aria-hidden="true">&#9680;</span> theme</button></header>
1049
+ <header class="document-header${header ? '' : ' document-header-empty'}">${header ? `<div class="header-label">${escapeHtml(header)}</div>` : ''}<span class="view-count" hidden></span><button class="reload-chip" type="button" hidden>New version available · Reload</button>${originMenu(metadata.origin)}${revisionMenu()}<button class="theme-toggle" type="button" aria-label="Toggle color theme" aria-pressed="false" title="Toggle color theme"><span aria-hidden="true">&#9680;</span> theme</button></header>
894
1050
  ${worksheetToolbar}
895
- <section class="hero">
1051
+ <style>${COVER_CSS}</style>
1052
+ <section class="hero creator-cover cover-${coverClass(metadata.creator.harness)}">
1053
+ ${coverArtwork(metadata.creator.harness)}
1054
+ ${coverTop(metadata)}
896
1055
  ${kickerHtml(metadata)}
897
1056
  <h1>${escapeHtml(title)}</h1>
898
1057
  ${summary ? `<p class="summary">${summary}</p>` : ''}
899
- ${metadataBlock(metadata)}
1058
+ ${creatorLine(metadata)}
900
1059
  </section>
1060
+ <div class="hero-metadata">${metadataBlock(metadata)}</div>
901
1061
  ${body}
902
1062
  ${footer ? `<footer class="document-footer">${escapeHtml(footer)}</footer>` : ''}
903
1063
  </main>
904
1064
  ${sourceJson}
905
- ${themeScript}${readerScript}${reloadScript}${worksheetScript}${SECTION_COLLAPSE_SCRIPT}${READER_ANCHORS_SCRIPT}${HIGHLIGHTS_SCRIPT}${COLLAB_SCRIPT}
1065
+ <style>${METADATA_CSS}</style>${METADATA_SCRIPT}${themeScript}${FRESHNESS_SCRIPT}${readerScript}${reloadScript}${worksheetScript}${SECTION_COLLAPSE_SCRIPT}${READER_ANCHORS_SCRIPT}${HIGHLIGHTS_SCRIPT}${COLLAB_SCRIPT}
906
1066
  </body>
907
1067
  </html>`;
1068
+ return document.replace(CONTENT_HASH_PLACEHOLDER, createHash('sha256').update(document).digest('hex').slice(0, 16));
908
1069
  }
909
1070
  function paletteVariables(palette) {
910
1071
  return `--bg:${palette.background};--surface:${palette.surface};--surface-alt:${palette.surfaceAlt};--line:${palette.line};--text:${palette.text};--muted:${palette.muted};--accent:${palette.accent};--accent-alt:${palette.accentAlt};--warn:${palette.warn};--danger:${palette.danger};--artifact-fg:${palette.text};--artifact-muted:${palette.muted};--artifact-accent:${palette.accent};`;
@@ -956,7 +1117,7 @@ export async function renderMarkdown(filePath, options = {}) {
956
1117
  const summary = renderInlineMarkdown(String(data.summary || ''));
957
1118
  const header = metadataValue(data.header);
958
1119
  const footer = metadataValue(data.footer);
959
- const metadata = artifactMetadata(data);
1120
+ const metadata = artifactMetadata(data, fileMtimeIso(abs));
960
1121
  let body = String(await markdownRenderer.parse(markInProgressTasks(content), { gfm: true, breaks: false }));
961
1122
  body = transformChecklists(body);
962
1123
  // Pills are applied after the sanitizer so the brand marks, favicons, and pill
@@ -999,7 +1160,7 @@ export function normalizeHtml(filePath) {
999
1160
  const design = cssFromDesign(dirname(abs));
1000
1161
  const body = sanitizeBody(raw);
1001
1162
  return {
1002
- html: shell(basename(abs, extname(abs)), '', '', '', { kicker: [], status: '', facts: [], links: [], provenance: [] }, `<article class="artifact-body">${body}</article>`, null, design.css, design.defaultTheme, bodyRevision(body)),
1163
+ html: shell(basename(abs, extname(abs)), '', '', '', { project: null, kind: '', status: '', creator: { agent: '', harness: '', human: '' }, origin: { agent: '', version: '', host: '', platform: '', arch: '', session: '', sessionId: '' }, timestamps: [], facts: [], links: [], provenance: [] }, `<article class="artifact-body">${body}</article>`, null, design.css, design.defaultTheme, bodyRevision(body)),
1003
1164
  diagnostics: design.diagnostics,
1004
1165
  };
1005
1166
  }
@@ -1033,14 +1194,25 @@ export async function publishArtifact(outPath, options = {}) {
1033
1194
  }
1034
1195
  }
1035
1196
  export async function compileArtifact(input, out, options = {}) {
1036
- const result = /\.md$/i.test(input) ? await renderMarkdown(input) : normalizeHtml(input);
1197
+ const markdown = /\.md$/i.test(input);
1198
+ let result;
1199
+ try {
1200
+ result = markdown && out
1201
+ ? await saveRevision(input, out, () => renderMarkdown(input), decorateRevision)
1202
+ : markdown ? await renderMarkdown(input) : normalizeHtml(input);
1203
+ }
1204
+ catch (error) {
1205
+ return { html: '', diagnostics: [{ level: 'error', message: `Could not save artifact: ${error instanceof Error ? error.message : String(error)}` }] };
1206
+ }
1037
1207
  // Never leave a half-valid HTML on disk when the Markdown failed validation.
1038
1208
  // Agents previously opened the written file despite exit code 1 and presented
1039
1209
  // prose-only plans as if they were review-ready.
1040
1210
  const hasErrors = result.diagnostics.some((diagnostic) => diagnostic.level === 'error');
1041
1211
  if (out && !hasErrors) {
1042
- mkdirSync(dirname(out), { recursive: true });
1043
- writeFileSync(out, result.html);
1212
+ if (!markdown) {
1213
+ mkdirSync(dirname(out), { recursive: true });
1214
+ writeFileSync(out, result.html);
1215
+ }
1044
1216
  result.outPath = out;
1045
1217
  const published = await publishArtifact(out, options);
1046
1218
  result.diagnostics.push(...published.diagnostics);
@@ -1048,6 +1220,16 @@ export async function compileArtifact(input, out, options = {}) {
1048
1220
  }
1049
1221
  return result;
1050
1222
  }
1223
+ /** Summaries only: no archived HTML, source paths, or local file links enter a share. */
1224
+ function decorateRevision(html, history) {
1225
+ const start = html.indexOf(REVISION_START);
1226
+ const end = html.indexOf(REVISION_END, start);
1227
+ if (start < 0 || end < 0)
1228
+ throw new Error('Rendered artifact is missing its revision menu slot.');
1229
+ const decorated = html.slice(0, start) + revisionMenu(history) + html.slice(end + REVISION_END.length);
1230
+ const unhashed = decorated.replace(/(<meta name="artifacts-content-hash" content=")[^"]*(">)/, `$1${CONTENT_HASH_PLACEHOLDER}$2`);
1231
+ return unhashed.replace(CONTENT_HASH_PLACEHOLDER, createHash('sha256').update(unhashed).digest('hex').slice(0, 16));
1232
+ }
1051
1233
  export function decompileHtml(input) {
1052
1234
  const raw = readFileSync(input, 'utf8');
1053
1235
  const match = raw.match(new RegExp(`<script[^>]+id=["']${ARTIFACT_SOURCE_ID}["'][^>]*>([\\s\\S]*?)<\\/script>`));