@tangle-network/agent-eval 0.75.0 → 0.77.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.
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Authenticity — "is this real, or convincing BS?"
3
+ *
4
+ * Pass/build-style scoring rewards anything that compiles and renders, so an
5
+ * agent can ship a polished frontend with a FAKE in-browser engine and zero of
6
+ * the required on-chain/contract work, and outscore a half-finished real
7
+ * implementation. This module scores what buildability does not: did the agent
8
+ * actually build the intended thing on the intended infra, or fake it.
9
+ *
10
+ * Two layers:
11
+ * - DETERMINISTIC `scoreAuthenticity` — calibrated by construction (no LLM,
12
+ * trustworthy today). Structural signals over the produced files, driven by
13
+ * a domain `AuthenticitySignals` config: required artifact present, real
14
+ * implementation of the hard part, real infra calls, wiring, fake-shim
15
+ * detection, mock/stub density.
16
+ * - LLM NUANCE `scoreAuthenticityNuance` — mocked% / fake% / unique% for the
17
+ * "looks real but is hollow" cases structure can't see.
18
+ *
19
+ * `gateRealness` is the anti-Goodhart gate: a submission missing the required
20
+ * artifact (or faking it) is capped and cannot rank high regardless of how
21
+ * buildable it is. Domain-agnostic; ships a Solidity/Fhenix preset.
22
+ *
23
+ * Input is the produced-state currency: `{ path, content }[]` — exactly what
24
+ * `extractProducedState(...).artifacts` yields, so any consumer can feed a run's
25
+ * produced state straight in.
26
+ */
27
+ interface ProducedFile {
28
+ path: string;
29
+ content?: string;
30
+ }
31
+ interface AuthenticitySignals {
32
+ /** Human label for the domain (e.g. 'fhenix-fhe'). */
33
+ label: string;
34
+ /** A file the task REQUIRES (e.g. /\.sol$/ for an on-chain task). */
35
+ requiredArtifact?: RegExp;
36
+ /** Vendored/3rd-party paths to exclude from required-artifact detection. */
37
+ vendored?: RegExp;
38
+ /** Real implementation of the hard part, inside the required artifact
39
+ * (e.g. Fhenix encrypted types + FHE.* ops). Matched against content, so it
40
+ * fails on comments/strings only if the regex is written tightly. */
41
+ realImpl: RegExp;
42
+ /** Real use of the intended client infra (e.g. cofhejs.encrypt() calls). */
43
+ realInfra: RegExp;
44
+ /** Evidence the artifact is actually wired/used (e.g. contract writes). */
45
+ wiring?: RegExp;
46
+ /** A fake shim standing in for the real thing — matched on file path AND body. */
47
+ fakeShim: RegExp;
48
+ /** Mock/stub/TODO markers. Defaults to a generic set. */
49
+ mock?: RegExp;
50
+ /** Score weights (default 40/25/20/15). */
51
+ weights?: {
52
+ artifact?: number;
53
+ impl?: number;
54
+ infra?: number;
55
+ wiring?: number;
56
+ };
57
+ }
58
+ interface AuthenticityResult {
59
+ /** Deterministic realness, 0 (BS) … 100 (real on real infra). */
60
+ realness: number;
61
+ requiredArtifactPresent: boolean;
62
+ requiredArtifactCount: number;
63
+ usesRealImpl: boolean;
64
+ realInfra: boolean;
65
+ wired: boolean;
66
+ fakeShim: boolean;
67
+ /** mock/stub markers per 1000 LOC, capped at 100. */
68
+ mockDensity: number;
69
+ /** Human-readable BS flags — what's missing or faked. */
70
+ flags: string[];
71
+ }
72
+ /** Deterministic authenticity scan of produced files. Pure — same files in,
73
+ * same score out. No LLM, no IO. */
74
+ declare function scoreAuthenticity(files: readonly ProducedFile[], signals: AuthenticitySignals): AuthenticityResult;
75
+ interface RealnessGate {
76
+ gated: boolean;
77
+ reason?: string;
78
+ }
79
+ /** Anti-Goodhart gate: a required-artifact-missing or faked submission is
80
+ * capped and cannot rank high regardless of buildability. */
81
+ declare function gateRealness(r: AuthenticityResult, opts?: {
82
+ floor?: number;
83
+ requireArtifact?: boolean;
84
+ }): RealnessGate;
85
+ interface AuthenticityNuance {
86
+ /** 0 (nothing mocked) … 100 (entirely mocked). */
87
+ mockedPct: number;
88
+ /** 0 (genuine) … 100 (a hollow facade / cargo-culted). */
89
+ fakePct: number;
90
+ /** 0 (boilerplate/template clone) … 100 (distinctive real work). */
91
+ uniquePct: number;
92
+ verdict: string;
93
+ }
94
+ /** A minimal completion fn — inject your model caller (router/tcloud). Keeps
95
+ * this module free of any specific LLM client. */
96
+ type CompleteFn = (system: string, user: string) => Promise<string>;
97
+ /**
98
+ * LLM nuance scoring — judges the "looks real but is hollow" axis structure
99
+ * misses. Inject a `complete` caller; returns mocked/fake/unique % + a verdict.
100
+ * Fail-soft: a bad/unparseable response yields a worst-case (fully-fake) read,
101
+ * never a false pass.
102
+ */
103
+ declare function scoreAuthenticityNuance(files: readonly ProducedFile[], complete: CompleteFn, opts?: {
104
+ intent?: string;
105
+ prioritize?: RegExp;
106
+ }): Promise<AuthenticityNuance>;
107
+
108
+ export { type AuthenticityNuance, type AuthenticityResult, type AuthenticitySignals, type CompleteFn, type ProducedFile, type RealnessGate, gateRealness, scoreAuthenticity, scoreAuthenticityNuance };
@@ -0,0 +1,128 @@
1
+ import "../chunk-PZ5AY32C.js";
2
+
3
+ // src/authenticity/index.ts
4
+ var DEFAULT_MOCK = /\bmock|\bfake|\bdummy|\bstub\b|simulat|hardcoded|placeholder|TODO|not\s+implemented|FIXME/i;
5
+ function basename(p) {
6
+ return p.split("/").pop() ?? p;
7
+ }
8
+ function scoreAuthenticity(files, signals) {
9
+ const w = {
10
+ artifact: signals.weights?.artifact ?? 40,
11
+ impl: signals.weights?.impl ?? 25,
12
+ infra: signals.weights?.infra ?? 20,
13
+ wiring: signals.weights?.wiring ?? 15
14
+ };
15
+ const mockRe = signals.mock ?? DEFAULT_MOCK;
16
+ const required = signals.requiredArtifact ? files.filter(
17
+ (f) => signals.requiredArtifact.test(f.path) && !(signals.vendored?.test(f.path) ?? false)
18
+ ) : [];
19
+ const others = signals.requiredArtifact ? files.filter((f) => !required.includes(f)) : files;
20
+ const requiredText = required.map((f) => f.content ?? "").join("\n");
21
+ const otherText = others.map((f) => f.content ?? "").join("\n");
22
+ const allText = files.map((f) => f.content ?? "").join("\n");
23
+ const requiredArtifactPresent = signals.requiredArtifact ? required.length > 0 : true;
24
+ const usesRealImpl = signals.realImpl.test(signals.requiredArtifact ? requiredText : allText);
25
+ const realInfra = signals.realInfra.test(allText);
26
+ const wired = signals.wiring ? signals.wiring.test(otherText || allText) : false;
27
+ const fakeShim = files.some(
28
+ (f) => signals.fakeShim.test(basename(f.path)) || signals.fakeShim.test(f.content ?? "")
29
+ );
30
+ const mockHits = (allText.match(
31
+ new RegExp(mockRe.source, mockRe.flags.includes("g") ? mockRe.flags : `${mockRe.flags}g`)
32
+ ) ?? []).length;
33
+ const loc = Math.max(1, allText.split("\n").length);
34
+ const mockDensity = Math.min(100, Math.round(mockHits / loc * 1e3));
35
+ let realness = 0;
36
+ if (requiredArtifactPresent) realness += w.artifact;
37
+ if (usesRealImpl) realness += w.impl;
38
+ if (realInfra) realness += w.infra;
39
+ if (wired) realness += w.wiring;
40
+ if (fakeShim) realness -= 25;
41
+ realness -= Math.min(20, mockDensity);
42
+ realness = Math.max(0, Math.min(100, realness));
43
+ const flags = [];
44
+ if (signals.requiredArtifact && !requiredArtifactPresent) {
45
+ flags.push(
46
+ `NO_REQUIRED_ARTIFACT: task needs ${signals.label} artifact (${signals.requiredArtifact}); none produced`
47
+ );
48
+ }
49
+ if (requiredArtifactPresent && signals.requiredArtifact && !usesRealImpl) {
50
+ flags.push("ARTIFACT_NO_REAL_IMPL: required artifact exists but lacks the real implementation");
51
+ }
52
+ if (fakeShim) flags.push("FAKE_SHIM: ships a client-side stand-in simulating the real infra");
53
+ if (!realInfra && !requiredArtifactPresent)
54
+ flags.push("NO_REAL_INFRA: no real infra calls \u2014 cosmetic at best");
55
+ if (mockDensity >= 8)
56
+ flags.push(`HIGH_MOCK_DENSITY: ${mockDensity} mock/stub markers per 1000 LOC`);
57
+ if (signals.wiring && requiredArtifactPresent && !wired)
58
+ flags.push("NOT_WIRED: artifact exists but is never used by the client");
59
+ return {
60
+ realness,
61
+ requiredArtifactPresent,
62
+ requiredArtifactCount: required.length,
63
+ usesRealImpl,
64
+ realInfra,
65
+ wired,
66
+ fakeShim,
67
+ mockDensity,
68
+ flags
69
+ };
70
+ }
71
+ function gateRealness(r, opts = {}) {
72
+ const floor = opts.floor ?? 30;
73
+ if ((opts.requireArtifact ?? true) && !r.requiredArtifactPresent) {
74
+ return { gated: true, reason: "required artifact missing" };
75
+ }
76
+ if (r.fakeShim && !r.usesRealImpl) {
77
+ return { gated: true, reason: "fake shim with no real implementation" };
78
+ }
79
+ if (r.realness < floor)
80
+ return { gated: true, reason: `realness ${r.realness} below floor ${floor}` };
81
+ return { gated: false };
82
+ }
83
+ function fileDigest(files, opts = {}) {
84
+ const maxFiles = opts.maxFiles ?? 14;
85
+ const perFile = opts.perFile ?? 1200;
86
+ const ordered = opts.prioritize ? [...files].sort(
87
+ (a, b) => Number(opts.prioritize.test(b.path)) - Number(opts.prioritize.test(a.path))
88
+ ) : files;
89
+ return ordered.slice(0, maxFiles).map((f) => `// ${f.path}
90
+ ${(f.content ?? "").slice(0, perFile)}`).join("\n\n");
91
+ }
92
+ function clampPct(v) {
93
+ const n = typeof v === "number" ? v : Number(v);
94
+ return Number.isFinite(n) ? Math.max(0, Math.min(100, Math.round(n))) : 0;
95
+ }
96
+ async function scoreAuthenticityNuance(files, complete, opts = {}) {
97
+ const system = 'You audit whether an agent BUILT THE REAL THING or faked it. Be skeptical: a pretty UI, cosmetic labels, simulated/in-memory stand-ins for real infra, and cargo-culted imports do NOT count as real. Respond with ONLY JSON: {"mockedPct":0-100,"fakePct":0-100,"uniquePct":0-100,"verdict":"one sentence"}. mockedPct = how much is mocked/stubbed; fakePct = how hollow/facade it is; uniquePct = how distinctive vs boilerplate.';
98
+ const user = (opts.intent ? `Intended deliverable: ${opts.intent}
99
+
100
+ ` : "") + `Produced files:
101
+ ${fileDigest(files, { prioritize: opts.prioritize })}`;
102
+ try {
103
+ const raw = await complete(system, user);
104
+ const m = raw.match(/\{[\s\S]*\}/);
105
+ if (!m)
106
+ return { mockedPct: 100, fakePct: 100, uniquePct: 0, verdict: "unparseable judge response" };
107
+ const j = JSON.parse(m[0]);
108
+ return {
109
+ mockedPct: clampPct(j.mockedPct),
110
+ fakePct: clampPct(j.fakePct),
111
+ uniquePct: clampPct(j.uniquePct),
112
+ verdict: typeof j.verdict === "string" ? j.verdict : ""
113
+ };
114
+ } catch (err) {
115
+ return {
116
+ mockedPct: 100,
117
+ fakePct: 100,
118
+ uniquePct: 0,
119
+ verdict: `judge error: ${err instanceof Error ? err.message : String(err)}`
120
+ };
121
+ }
122
+ }
123
+ export {
124
+ gateRealness,
125
+ scoreAuthenticity,
126
+ scoreAuthenticityNuance
127
+ };
128
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/authenticity/index.ts"],"sourcesContent":["/**\n * Authenticity — \"is this real, or convincing BS?\"\n *\n * Pass/build-style scoring rewards anything that compiles and renders, so an\n * agent can ship a polished frontend with a FAKE in-browser engine and zero of\n * the required on-chain/contract work, and outscore a half-finished real\n * implementation. This module scores what buildability does not: did the agent\n * actually build the intended thing on the intended infra, or fake it.\n *\n * Two layers:\n * - DETERMINISTIC `scoreAuthenticity` — calibrated by construction (no LLM,\n * trustworthy today). Structural signals over the produced files, driven by\n * a domain `AuthenticitySignals` config: required artifact present, real\n * implementation of the hard part, real infra calls, wiring, fake-shim\n * detection, mock/stub density.\n * - LLM NUANCE `scoreAuthenticityNuance` — mocked% / fake% / unique% for the\n * \"looks real but is hollow\" cases structure can't see.\n *\n * `gateRealness` is the anti-Goodhart gate: a submission missing the required\n * artifact (or faking it) is capped and cannot rank high regardless of how\n * buildable it is. Domain-agnostic; ships a Solidity/Fhenix preset.\n *\n * Input is the produced-state currency: `{ path, content }[]` — exactly what\n * `extractProducedState(...).artifacts` yields, so any consumer can feed a run's\n * produced state straight in.\n */\n\nexport interface ProducedFile {\n path: string\n content?: string\n}\n\nexport interface AuthenticitySignals {\n /** Human label for the domain (e.g. 'fhenix-fhe'). */\n label: string\n /** A file the task REQUIRES (e.g. /\\.sol$/ for an on-chain task). */\n requiredArtifact?: RegExp\n /** Vendored/3rd-party paths to exclude from required-artifact detection. */\n vendored?: RegExp\n /** Real implementation of the hard part, inside the required artifact\n * (e.g. Fhenix encrypted types + FHE.* ops). Matched against content, so it\n * fails on comments/strings only if the regex is written tightly. */\n realImpl: RegExp\n /** Real use of the intended client infra (e.g. cofhejs.encrypt() calls). */\n realInfra: RegExp\n /** Evidence the artifact is actually wired/used (e.g. contract writes). */\n wiring?: RegExp\n /** A fake shim standing in for the real thing — matched on file path AND body. */\n fakeShim: RegExp\n /** Mock/stub/TODO markers. Defaults to a generic set. */\n mock?: RegExp\n /** Score weights (default 40/25/20/15). */\n weights?: { artifact?: number; impl?: number; infra?: number; wiring?: number }\n}\n\nexport interface AuthenticityResult {\n /** Deterministic realness, 0 (BS) … 100 (real on real infra). */\n realness: number\n requiredArtifactPresent: boolean\n requiredArtifactCount: number\n usesRealImpl: boolean\n realInfra: boolean\n wired: boolean\n fakeShim: boolean\n /** mock/stub markers per 1000 LOC, capped at 100. */\n mockDensity: number\n /** Human-readable BS flags — what's missing or faked. */\n flags: string[]\n}\n\nconst DEFAULT_MOCK =\n /\\bmock|\\bfake|\\bdummy|\\bstub\\b|simulat|hardcoded|placeholder|TODO|not\\s+implemented|FIXME/i\n\nfunction basename(p: string): string {\n return p.split('/').pop() ?? p\n}\n\n/** Deterministic authenticity scan of produced files. Pure — same files in,\n * same score out. No LLM, no IO. */\nexport function scoreAuthenticity(\n files: readonly ProducedFile[],\n signals: AuthenticitySignals,\n): AuthenticityResult {\n const w = {\n artifact: signals.weights?.artifact ?? 40,\n impl: signals.weights?.impl ?? 25,\n infra: signals.weights?.infra ?? 20,\n wiring: signals.weights?.wiring ?? 15,\n }\n const mockRe = signals.mock ?? DEFAULT_MOCK\n\n const required = signals.requiredArtifact\n ? files.filter(\n (f) => signals.requiredArtifact!.test(f.path) && !(signals.vendored?.test(f.path) ?? false),\n )\n : []\n const others = signals.requiredArtifact ? files.filter((f) => !required.includes(f)) : files\n\n const requiredText = required.map((f) => f.content ?? '').join('\\n')\n const otherText = others.map((f) => f.content ?? '').join('\\n')\n const allText = files.map((f) => f.content ?? '').join('\\n')\n\n const requiredArtifactPresent = signals.requiredArtifact ? required.length > 0 : true\n // Real impl looked for in the required artifact when there is one, else anywhere.\n const usesRealImpl = signals.realImpl.test(signals.requiredArtifact ? requiredText : allText)\n const realInfra = signals.realInfra.test(allText)\n const wired = signals.wiring ? signals.wiring.test(otherText || allText) : false\n const fakeShim = files.some(\n (f) => signals.fakeShim.test(basename(f.path)) || signals.fakeShim.test(f.content ?? ''),\n )\n\n const mockHits = (\n allText.match(\n new RegExp(mockRe.source, mockRe.flags.includes('g') ? mockRe.flags : `${mockRe.flags}g`),\n ) ?? []\n ).length\n const loc = Math.max(1, allText.split('\\n').length)\n const mockDensity = Math.min(100, Math.round((mockHits / loc) * 1000))\n\n let realness = 0\n if (requiredArtifactPresent) realness += w.artifact\n if (usesRealImpl) realness += w.impl\n if (realInfra) realness += w.infra\n if (wired) realness += w.wiring\n if (fakeShim) realness -= 25\n realness -= Math.min(20, mockDensity)\n realness = Math.max(0, Math.min(100, realness))\n\n const flags: string[] = []\n if (signals.requiredArtifact && !requiredArtifactPresent) {\n flags.push(\n `NO_REQUIRED_ARTIFACT: task needs ${signals.label} artifact (${signals.requiredArtifact}); none produced`,\n )\n }\n if (requiredArtifactPresent && signals.requiredArtifact && !usesRealImpl) {\n flags.push('ARTIFACT_NO_REAL_IMPL: required artifact exists but lacks the real implementation')\n }\n if (fakeShim) flags.push('FAKE_SHIM: ships a client-side stand-in simulating the real infra')\n if (!realInfra && !requiredArtifactPresent)\n flags.push('NO_REAL_INFRA: no real infra calls — cosmetic at best')\n if (mockDensity >= 8)\n flags.push(`HIGH_MOCK_DENSITY: ${mockDensity} mock/stub markers per 1000 LOC`)\n if (signals.wiring && requiredArtifactPresent && !wired)\n flags.push('NOT_WIRED: artifact exists but is never used by the client')\n\n return {\n realness,\n requiredArtifactPresent,\n requiredArtifactCount: required.length,\n usesRealImpl,\n realInfra,\n wired,\n fakeShim,\n mockDensity,\n flags,\n }\n}\n\nexport interface RealnessGate {\n gated: boolean\n reason?: string\n}\n\n/** Anti-Goodhart gate: a required-artifact-missing or faked submission is\n * capped and cannot rank high regardless of buildability. */\nexport function gateRealness(\n r: AuthenticityResult,\n opts: { floor?: number; requireArtifact?: boolean } = {},\n): RealnessGate {\n const floor = opts.floor ?? 30\n if ((opts.requireArtifact ?? true) && !r.requiredArtifactPresent) {\n return { gated: true, reason: 'required artifact missing' }\n }\n if (r.fakeShim && !r.usesRealImpl) {\n return { gated: true, reason: 'fake shim with no real implementation' }\n }\n if (r.realness < floor)\n return { gated: true, reason: `realness ${r.realness} below floor ${floor}` }\n return { gated: false }\n}\n\n// ── LLM nuance layer ─────────────────────────────────────────────────────────\n\nexport interface AuthenticityNuance {\n /** 0 (nothing mocked) … 100 (entirely mocked). */\n mockedPct: number\n /** 0 (genuine) … 100 (a hollow facade / cargo-culted). */\n fakePct: number\n /** 0 (boilerplate/template clone) … 100 (distinctive real work). */\n uniquePct: number\n verdict: string\n}\n\n/** A minimal completion fn — inject your model caller (router/tcloud). Keeps\n * this module free of any specific LLM client. */\nexport type CompleteFn = (system: string, user: string) => Promise<string>\n\nfunction fileDigest(\n files: readonly ProducedFile[],\n opts: { maxFiles?: number; perFile?: number; prioritize?: RegExp } = {},\n): string {\n const maxFiles = opts.maxFiles ?? 14\n const perFile = opts.perFile ?? 1200\n // Lead with the required-artifact files (e.g. .sol) so a truncated digest\n // never hides the very thing the judge must assess.\n const ordered = opts.prioritize\n ? [...files].sort(\n (a, b) => Number(opts.prioritize!.test(b.path)) - Number(opts.prioritize!.test(a.path)),\n )\n : files\n return ordered\n .slice(0, maxFiles)\n .map((f) => `// ${f.path}\\n${(f.content ?? '').slice(0, perFile)}`)\n .join('\\n\\n')\n}\n\nfunction clampPct(v: unknown): number {\n const n = typeof v === 'number' ? v : Number(v)\n return Number.isFinite(n) ? Math.max(0, Math.min(100, Math.round(n))) : 0\n}\n\n/**\n * LLM nuance scoring — judges the \"looks real but is hollow\" axis structure\n * misses. Inject a `complete` caller; returns mocked/fake/unique % + a verdict.\n * Fail-soft: a bad/unparseable response yields a worst-case (fully-fake) read,\n * never a false pass.\n */\nexport async function scoreAuthenticityNuance(\n files: readonly ProducedFile[],\n complete: CompleteFn,\n opts: { intent?: string; prioritize?: RegExp } = {},\n): Promise<AuthenticityNuance> {\n const system =\n 'You audit whether an agent BUILT THE REAL THING or faked it. Be skeptical: ' +\n 'a pretty UI, cosmetic labels, simulated/in-memory stand-ins for real infra, ' +\n 'and cargo-culted imports do NOT count as real. Respond with ONLY JSON: ' +\n '{\"mockedPct\":0-100,\"fakePct\":0-100,\"uniquePct\":0-100,\"verdict\":\"one sentence\"}. ' +\n 'mockedPct = how much is mocked/stubbed; fakePct = how hollow/facade it is; ' +\n 'uniquePct = how distinctive vs boilerplate.'\n const user =\n (opts.intent ? `Intended deliverable: ${opts.intent}\\n\\n` : '') +\n `Produced files:\\n${fileDigest(files, { prioritize: opts.prioritize })}`\n try {\n const raw = await complete(system, user)\n const m = raw.match(/\\{[\\s\\S]*\\}/)\n if (!m)\n return { mockedPct: 100, fakePct: 100, uniquePct: 0, verdict: 'unparseable judge response' }\n const j = JSON.parse(m[0]) as Record<string, unknown>\n return {\n mockedPct: clampPct(j.mockedPct),\n fakePct: clampPct(j.fakePct),\n uniquePct: clampPct(j.uniquePct),\n verdict: typeof j.verdict === 'string' ? j.verdict : '',\n }\n } catch (err) {\n return {\n mockedPct: 100,\n fakePct: 100,\n uniquePct: 0,\n verdict: `judge error: ${err instanceof Error ? err.message : String(err)}`,\n }\n }\n}\n\n// Domain `AuthenticitySignals` (e.g. a Solidity/Fhenix preset) live in the\n// CONSUMER, not the substrate — this module stays domain-agnostic.\n"],"mappings":";;;AAsEA,IAAM,eACJ;AAEF,SAAS,SAAS,GAAmB;AACnC,SAAO,EAAE,MAAM,GAAG,EAAE,IAAI,KAAK;AAC/B;AAIO,SAAS,kBACd,OACA,SACoB;AACpB,QAAM,IAAI;AAAA,IACR,UAAU,QAAQ,SAAS,YAAY;AAAA,IACvC,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AC;AACzB,WAAO;AAAA,MACL,WAAW,SAAS,EAAE,SAAS;AAAA,MAC/B,SAAS,SAAS,EAAE,OAAO;AAAA,MAC3B,WAAW,SAAS,EAAE,SAAS;AAAA,MAC/B,SAAS,OAAO,EAAE,YAAY,WAAW,EAAE,UAAU;AAAA,IACvD;AAAA,EACF,SAAS,KAAK;AACZ,WAAO;AAAA,MACL,WAAW;AAAA,MACX,SAAS;AAAA,MACT,WAAW;AAAA,MACX,SAAS,gBAAgB,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CAAC;AAAA,IAC3E;AAAA,EACF;AACF;","names":[]}
package/dist/openapi.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.1.0",
3
3
  "info": {
4
4
  "title": "@tangle-network/agent-eval — wire protocol",
5
- "version": "0.75.0",
5
+ "version": "0.77.0",
6
6
  "description": "HTTP and stdio RPC interface to agent-eval. The TypeScript runtime is the source of truth; this spec is the contract that cross-language clients (Python, Rust, Go) generate from.\n\nWire-protocol version: 1.0.0. Bumps on breaking changes to request/response schemas.",
7
7
  "contact": {
8
8
  "name": "Tangle Network",
@@ -84,7 +84,7 @@ declare function renderCodeAnimationHtml(source: readonly Span[] | readonly Code
84
84
  */
85
85
 
86
86
  /** What the agent meaningfully did — the compressed vocabulary. */
87
- type SemanticKind = 'understood_task' | 'reasoned' | 'ran_command' | 'read_file' | 'edited_code' | 'searched' | 'used_browser' | 'used_computer' | 'called_api' | 'called_tool' | 'evaluated' | 'observed_failure' | 'completed';
87
+ type SemanticKind = 'understood_task' | 'user_message' | 'agent_reply' | 'reasoned' | 'ran_command' | 'read_file' | 'edited_code' | 'searched' | 'used_browser' | 'used_computer' | 'called_api' | 'called_tool' | 'evaluated' | 'observed_failure' | 'completed';
88
88
  /** The modality-typed payload a scene shows. This is what makes any agent
89
89
  * action — screen, browser, shell, code, API — actually viewable. */
90
90
  type SceneVisual = {
@@ -141,13 +141,15 @@ interface ReduceOptions {
141
141
  collapseAdjacent?: boolean;
142
142
  }
143
143
  /**
144
- * Reduce a span tree into the meaningful moments a viewer cares about. Each
145
- * span is classified + has its modality visual extracted; adjacent same-kind
146
- * moments collapse (the compression step), carrying the latest visual so the
147
- * scene shows the most recent state. A failure always stands alone.
144
+ * Reduce a span tree into the meaningful moments a viewer cares about. The
145
+ * conversation (user asks, agent replies) is lifted from LLM spans first so the
146
+ * dialogue is first-class; the remaining work spans are classified + have their
147
+ * modality visual extracted. Adjacent same-kind work moments collapse (the
148
+ * compression step), carrying the latest visual; failures and conversation
149
+ * turns never collapse.
148
150
  */
149
151
  declare function reduceToSemanticEvents(spans: readonly Span[], opts?: ReduceOptions): SemanticEvent[];
150
- type SceneType = 'title_card' | 'reasoning' | 'terminal' | 'file' | 'diff' | 'search' | 'browser' | 'computer' | 'api' | 'tool' | 'eval' | 'error' | 'summary';
152
+ type SceneType = 'title_card' | 'prompt' | 'reply' | 'reasoning' | 'terminal' | 'file' | 'diff' | 'search' | 'browser' | 'computer' | 'api' | 'tool' | 'eval' | 'error' | 'summary';
151
153
  interface Scene {
152
154
  sceneType: SceneType;
153
155
  title: string;
@@ -352,7 +352,9 @@ function classify(span) {
352
352
  return { kind: "called_tool", importance: 2, label: span.name };
353
353
  }
354
354
  var KIND_VERB = {
355
- understood_task: "Received the task",
355
+ understood_task: "Understood the task",
356
+ user_message: "User said",
357
+ agent_reply: "Agent replied",
356
358
  reasoned: "Reasoned",
357
359
  ran_command: "Ran a command",
358
360
  read_file: "Read files",
@@ -366,12 +368,63 @@ var KIND_VERB = {
366
368
  observed_failure: "Hit a failure",
367
369
  completed: "Finished"
368
370
  };
371
+ var STANDALONE_KINDS = /* @__PURE__ */ new Set([
372
+ "observed_failure",
373
+ "understood_task",
374
+ "user_message",
375
+ "agent_reply"
376
+ ]);
377
+ function conversationEvents(span, seen, state) {
378
+ if (span.kind !== "llm") return [];
379
+ const out = [];
380
+ const emit = (kind, text, importance) => {
381
+ const t = text.trim();
382
+ if (!t) return;
383
+ const who = kind === "agent_reply" ? "a" : "u";
384
+ const key = `${who}
385
+ ${t}`;
386
+ if (seen.has(key)) return;
387
+ seen.add(key);
388
+ const speaker = kind === "understood_task" ? "Task" : kind === "user_message" ? "User" : "Agent";
389
+ out.push({
390
+ kind,
391
+ title: `${speaker}: ${truncate(t, 64)}`,
392
+ summary: truncate(t, 280),
393
+ visual: { type: "prose", text: truncate(t, 1200) },
394
+ evidenceSpanIds: [span.spanId],
395
+ importance,
396
+ startTs: span.startedAt,
397
+ endTs: span.endedAt ?? span.startedAt
398
+ });
399
+ };
400
+ for (const m of span.messages ?? []) {
401
+ const content = str(m.content);
402
+ if (!content) continue;
403
+ if (m.role === "user") {
404
+ emit(state.sawUser ? "user_message" : "understood_task", content, state.sawUser ? 4 : 5);
405
+ state.sawUser = true;
406
+ } else if (m.role === "assistant") {
407
+ emit("agent_reply", content, 3);
408
+ }
409
+ }
410
+ const reply = str(span.output);
411
+ if (reply) emit("agent_reply", reply, 3);
412
+ return out;
413
+ }
369
414
  function reduceToSemanticEvents(spans, opts = {}) {
370
415
  const collapse = opts.collapseAdjacent ?? true;
371
416
  const ordered = [...spans].sort((a, b) => a.startedAt - b.startedAt);
372
- const raw = ordered.map((s) => {
417
+ const seen = /* @__PURE__ */ new Set();
418
+ const convState = { sawUser: false };
419
+ const raw = [];
420
+ for (const s of ordered) {
421
+ const conv = conversationEvents(s, seen, convState);
422
+ if (conv.length > 0) {
423
+ raw.push(...conv);
424
+ continue;
425
+ }
373
426
  const c = classify(s);
374
- return {
427
+ raw.push({
375
428
  kind: c.kind,
376
429
  title: c.label,
377
430
  summary: `${KIND_VERB[c.kind]} \u2014 ${c.label}`,
@@ -380,13 +433,13 @@ function reduceToSemanticEvents(spans, opts = {}) {
380
433
  importance: c.importance,
381
434
  startTs: s.startedAt,
382
435
  endTs: s.endedAt ?? s.startedAt
383
- };
384
- });
436
+ });
437
+ }
385
438
  if (!collapse) return raw;
386
439
  const merged = [];
387
440
  for (const ev of raw) {
388
441
  const prev = merged[merged.length - 1];
389
- if (prev && prev.kind === ev.kind && ev.kind !== "observed_failure") {
442
+ if (prev && prev.kind === ev.kind && !STANDALONE_KINDS.has(ev.kind)) {
390
443
  prev.evidenceSpanIds.push(...ev.evidenceSpanIds);
391
444
  prev.endTs = Math.max(prev.endTs, ev.endTs);
392
445
  if (ev.visual.type !== "none") prev.visual = ev.visual;
@@ -401,6 +454,8 @@ function reduceToSemanticEvents(spans, opts = {}) {
401
454
  }
402
455
  var KIND_TO_SCENE = {
403
456
  understood_task: "title_card",
457
+ user_message: "prompt",
458
+ agent_reply: "reply",
404
459
  reasoned: "reasoning",
405
460
  ran_command: "terminal",
406
461
  read_file: "file",
@@ -424,7 +479,8 @@ var DURATION_BY_IMPORTANCE = {
424
479
  function compileStoryboard(events, opts = {}) {
425
480
  const title = opts.title ?? "Agent run";
426
481
  const maxScenes = opts.maxScenes ?? 16;
427
- const indexed = events.map((ev, i) => ({ ev, i }));
482
+ const taskEvent = events.find((e) => e.kind === "understood_task");
483
+ const indexed = events.filter((ev) => ev.kind !== "understood_task").map((ev, i) => ({ ev, i }));
428
484
  const mustKeep = indexed.filter(({ ev }) => ev.importance >= 4);
429
485
  const rest = indexed.filter(({ ev }) => ev.importance < 4).sort((a, b) => b.ev.importance - a.ev.importance || a.i - b.i);
430
486
  const budget = Math.max(0, maxScenes - mustKeep.length);
@@ -445,10 +501,10 @@ function compileStoryboard(events, opts = {}) {
445
501
  {
446
502
  sceneType: "title_card",
447
503
  title,
448
- narration: "The agent receives its task.",
449
- visual: { type: "none" },
504
+ narration: taskEvent ? taskEvent.summary : "The agent receives its task.",
505
+ visual: taskEvent ? taskEvent.visual : { type: "none" },
450
506
  durationMs: 3e3,
451
- evidenceSpanIds: []
507
+ evidenceSpanIds: taskEvent ? taskEvent.evidenceSpanIds : []
452
508
  },
453
509
  ...actionScenes,
454
510
  {
@@ -464,6 +520,8 @@ function compileStoryboard(events, opts = {}) {
464
520
  }
465
521
  var SCENE_ICON = {
466
522
  title_card: "\u{1F3AC}",
523
+ prompt: "\u{1F4AC}",
524
+ reply: "\u{1F916}",
467
525
  reasoning: "\u{1F9E0}",
468
526
  terminal: "\u2328\uFE0F",
469
527
  file: "\u{1F4C4}",
@@ -631,6 +689,7 @@ function renderStoryboardHtml(storyboard, opts = {}) {
631
689
  .type-error { --accent: #ef4444; } .type-diff { --accent: #22c55e; } .type-terminal { --accent: #eab308; }
632
690
  .type-browser { --accent: #06b6d4; } .type-computer { --accent: #14b8a6; } .type-api { --accent: #79c0ff; }
633
691
  .type-summary { --accent: #a855f7; } .type-title_card { --accent: #3b82f6; }
692
+ .type-prompt { --accent: #f59e0b; } .type-reply { --accent: #10b981; }
634
693
  .scene-enter { animation: pop .45s cubic-bezier(.2,.7,.3,1.2); }
635
694
  @keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }
636
695
  .bar { height: 4px; background: #1e2a3a; border-radius: 4px; margin-top: 14px; overflow: hidden; }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/storyboard/code-edit.ts","../../src/storyboard/index.ts"],"sourcesContent":["/**\n * Code-edit extraction + the \"watch the agent write code\" animation.\n *\n * The base storyboard (./index) compresses a run into scenes but keeps scenes\n * payload-free (title + narration + evidence span ids). To actually SHOW the\n * code an agent wrote, this module pulls the concrete edit (path, diff,\n * before/after, language) out of the raw edit-tool spans and renders a\n * self-contained HTML replay that types each file out, character by character,\n * like an editor recording.\n *\n * Additive on purpose: it reuses the canonical `Span` (trace/schema) and the\n * `Storyboard` IR (./index) without modifying the reducer/compiler — so it\n * composes with the existing pipeline and a Remotion consumer can read the same\n * `CodeEdit[]` to render an MP4.\n */\n\nimport type { Span } from '../trace/schema'\nimport type { Scene, Storyboard } from './index'\n\nconst EDIT_TOOLS =\n /(edit|write|patch|apply|str_replace|create.*file|save|insert|update.*file|multi_edit)/i\n\n/** A concrete code change lifted from a tool span. */\nexport interface CodeEdit {\n /** Span the edit came from — back-reference into the trace. */\n spanId: string\n path: string\n language?: string\n /** Unified diff, when the tool carried one. */\n diff?: string\n /** Full file body before / after, when present — enables true keystroke\n * animation rather than only flashing a diff. */\n before?: string\n after?: string\n additions: number\n deletions: number\n startedAt: number\n}\n\nfunction languageOf(path: string): string | undefined {\n const ext = path.includes('.') ? path.split('.').pop()?.toLowerCase() : undefined\n if (!ext) return undefined\n const map: Record<string, string> = {\n ts: 'ts',\n tsx: 'tsx',\n js: 'js',\n jsx: 'jsx',\n mjs: 'js',\n cjs: 'js',\n py: 'python',\n rs: 'rust',\n go: 'go',\n sol: 'solidity',\n java: 'java',\n rb: 'ruby',\n php: 'php',\n c: 'c',\n cpp: 'cpp',\n cs: 'csharp',\n css: 'css',\n scss: 'scss',\n html: 'html',\n json: 'json',\n yaml: 'yaml',\n yml: 'yaml',\n toml: 'toml',\n md: 'markdown',\n sh: 'bash',\n sql: 'sql',\n }\n return map[ext] ?? ext\n}\n\nfunction pick(obj: unknown, keys: string[]): string | undefined {\n if (!obj || typeof obj !== 'object') return undefined\n const rec = obj as Record<string, unknown>\n for (const k of Object.keys(rec)) {\n if (keys.includes(k.toLowerCase())) {\n const v = rec[k]\n if (typeof v === 'string') return v\n }\n }\n return undefined\n}\n\nfunction countDiff(diff?: string): { additions: number; deletions: number } {\n if (!diff) return { additions: 0, deletions: 0 }\n let additions = 0\n let deletions = 0\n for (const line of diff.split('\\n')) {\n if (line.startsWith('+') && !line.startsWith('+++')) additions++\n else if (line.startsWith('-') && !line.startsWith('---')) deletions++\n }\n return { additions, deletions }\n}\n\n/** Extract a CodeEdit from a single span, or undefined if it is not an edit. */\nexport function codeEditFromSpan(span: Span): CodeEdit | undefined {\n if (span.kind !== 'tool') return undefined\n const tool = span as Extract<Span, { kind: 'tool' }>\n if (!EDIT_TOOLS.test(tool.toolName)) return undefined\n const path = pick(tool.args, ['path', 'file_path', 'filepath', 'filename', 'file'])\n if (!path) return undefined\n const diff = pick(tool.args, ['diff', 'patch'])\n const after = pick(tool.args, ['content', 'new_str', 'new_string', 'newtext', 'text', 'body'])\n const before = pick(tool.args, ['old_str', 'old_string', 'oldtext', 'original'])\n const counts = countDiff(diff)\n return {\n spanId: span.spanId,\n path,\n language: languageOf(path),\n diff,\n before,\n after,\n additions: diff ? counts.additions : after ? after.split('\\n').length : 0,\n deletions: diff ? counts.deletions : 0,\n startedAt: span.startedAt,\n }\n}\n\n/** All code edits in a run, in chronological order. */\nexport function extractCodeEdits(spans: readonly Span[]): CodeEdit[] {\n return spans\n .map(codeEditFromSpan)\n .filter((e): e is CodeEdit => e != null)\n .sort((a, b) => a.startedAt - b.startedAt)\n}\n\n/** Pair each code-edit (`diff`) scene with its concrete edit, matched via the\n * scene's evidence span ids. Scenes without a recoverable edit are dropped. */\nexport function codeEditsForStoryboard(\n storyboard: Storyboard,\n spans: readonly Span[],\n): Array<{ scene: Scene; edit: CodeEdit }> {\n const bySpan = new Map(extractCodeEdits(spans).map((e) => [e.spanId, e]))\n const out: Array<{ scene: Scene; edit: CodeEdit }> = []\n for (const scene of storyboard.scenes) {\n if (scene.sceneType !== 'diff') continue\n const edit = scene.evidenceSpanIds\n .map((id) => bySpan.get(id))\n .find((e): e is CodeEdit => e != null)\n if (edit) out.push({ scene, edit })\n }\n return out\n}\n\n/** The text the animation types for an edit: prefer the full new file body,\n * then the added lines of a diff, then a minimal placeholder so the scene is\n * never blank. */\nexport function editAnimationText(edit: CodeEdit): string {\n if (edit.after && edit.after.trim()) return edit.after\n if (edit.diff) {\n const added = edit.diff\n .split('\\n')\n .filter((l) => l.startsWith('+') && !l.startsWith('+++'))\n .map((l) => l.slice(1))\n .join('\\n')\n if (added.trim()) return added\n }\n return `// ${edit.path}\\n// (${edit.additions} line${edit.additions === 1 ? '' : 's'} written)`\n}\n\nfunction esc(s: string): string {\n return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n}\n\nexport interface CodeAnimationOptions {\n /** Page title. Default \"Agent writing code\". */\n title?: string\n /** Characters typed per animation tick. Higher = faster. Default 4. */\n charsPerTick?: number\n /** Pause between files, ms. Default 900. */\n pauseBetweenMs?: number\n}\n\n/**\n * Render a self-contained HTML page that animates the agent writing each file,\n * character by character, with a filename tab, line numbers, and a blinking\n * cursor — the shareable \"watch it build\" clip. No build step, no assets, no\n * deps. The same `CodeEdit[]` feeds a Remotion MP4 renderer in a consumer\n * package; this is the dependency-free baseline.\n */\nexport function renderCodeAnimationHtml(\n source: readonly Span[] | readonly CodeEdit[],\n opts: CodeAnimationOptions = {},\n): string {\n const edits: CodeEdit[] =\n source.length > 0 && 'path' in (source[0] as object)\n ? (source as CodeEdit[])\n : extractCodeEdits(source as readonly Span[])\n\n const files = edits.map((e) => ({\n path: e.path,\n language: e.language ?? '',\n additions: e.additions,\n deletions: e.deletions,\n code: editAnimationText(e),\n }))\n const title = opts.title ?? 'Agent writing code'\n const charsPerTick = opts.charsPerTick ?? 4\n const pauseBetweenMs = opts.pauseBetweenMs ?? 900\n const filesJson = JSON.stringify(files)\n\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<title>${esc(title)}</title>\n<style>\n :root { color-scheme: dark; }\n * { box-sizing: border-box; }\n body { margin: 0; background: #0b0f17; color: #e6edf3;\n font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;\n display: flex; flex-direction: column; min-height: 100vh; align-items: center; justify-content: center; gap: 14px; }\n h1 { font-family: ui-sans-serif, system-ui, sans-serif; font-size: 1rem; font-weight: 600; color: #9aa7b5; margin: 0; }\n .editor { width: min(900px, 94vw); background: #0d1320; border: 1px solid #1e2a3a; border-radius: 12px;\n overflow: hidden; box-shadow: 0 16px 50px rgba(0,0,0,.5); }\n .tabbar { display: flex; align-items: center; gap: 8px; background: #111a29; padding: 9px 14px; border-bottom: 1px solid #1e2a3a; }\n .dot { width: 11px; height: 11px; border-radius: 50%; }\n .dot.r { background: #ff5f56; } .dot.y { background: #ffbd2e; } .dot.g { background: #27c93f; }\n .tab { margin-left: 10px; background: #0d1320; padding: 5px 12px; border-radius: 7px 7px 0 0;\n color: #cdd9e5; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .85rem; }\n .lang { color: #5b6b7d; font-size: .75rem; margin-left: 6px; }\n .adds { margin-left: auto; color: #3fb950; font-size: .78rem; font-family: ui-sans-serif, system-ui, sans-serif; }\n .dels { color: #f85149; margin-left: 8px; }\n .codewrap { display: flex; max-height: 60vh; overflow: auto; }\n .gutter { padding: 14px 10px 14px 14px; text-align: right; color: #3a4757; user-select: none; white-space: pre; }\n pre { margin: 0; padding: 14px 18px 14px 6px; white-space: pre; tab-size: 2; flex: 1; }\n .cursor { display: inline-block; width: 8px; margin-left: 1px; background: #58a6ff; animation: blink .9s steps(1) infinite; }\n @keyframes blink { 50% { opacity: 0; } }\n .controls { display: flex; gap: 10px; align-items: center; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .85rem; color: #8b98a6; }\n button { background: #1b2636; color: #e6edf3; border: 1px solid #2a3a4f; border-radius: 8px; padding: 6px 12px; cursor: pointer; font: inherit; }\n button:hover { background: #243349; }\n .empty { padding: 40px; color: #5b6b7d; }\n</style>\n</head>\n<body>\n <h1>✏️ ${esc(title)}</h1>\n <div class=\"editor\">\n <div class=\"tabbar\">\n <span class=\"dot r\"></span><span class=\"dot y\"></span><span class=\"dot g\"></span>\n <span class=\"tab\" id=\"tab\">—</span><span class=\"lang\" id=\"lang\"></span>\n <span class=\"adds\" id=\"adds\"></span>\n </div>\n <div class=\"codewrap\"><div class=\"gutter\" id=\"gutter\">1</div><pre id=\"code\"></pre></div>\n </div>\n <div class=\"controls\">\n <button id=\"pp\">⏸ Pause</button><button id=\"restart\">↻ Restart</button>\n <span id=\"counter\"></span>\n </div>\n<script>\n const FILES = ${filesJson};\n const CPT = ${charsPerTick}, PAUSE = ${pauseBetweenMs};\n const codeEl = document.getElementById('code'), gutterEl = document.getElementById('gutter');\n const tabEl = document.getElementById('tab'), langEl = document.getElementById('lang');\n const addsEl = document.getElementById('adds'), counterEl = document.getElementById('counter');\n let fi = 0, ci = 0, playing = true, raf = 0, paused = false;\n if (!FILES.length) { codeEl.innerHTML = '<span class=\"empty\">No code edits in this run.</span>'; }\n function esc(s){return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');}\n function setHeader(){ const f = FILES[fi]; tabEl.textContent = f.path; langEl.textContent = f.language || '';\n addsEl.innerHTML = '+' + f.additions + (f.deletions ? ' <span class=\"dels\">-' + f.deletions + '</span>' : '');\n counterEl.textContent = (fi+1) + ' / ' + FILES.length + ' files'; }\n function paint(){ const f = FILES[fi]; const shown = f.code.slice(0, ci);\n const lines = (shown.match(/\\\\n/g) || []).length + 1;\n gutterEl.textContent = Array.from({length: lines}, (_, k) => k+1).join('\\\\n');\n codeEl.innerHTML = esc(shown) + '<span class=\"cursor\">&nbsp;</span>';\n const wrap = codeEl.parentElement; wrap.scrollTop = wrap.scrollHeight; }\n function tick(){ if (paused || !FILES.length) return;\n const f = FILES[fi];\n if (ci < f.code.length){ ci = Math.min(f.code.length, ci + CPT); paint(); raf = requestAnimationFrame(tick); }\n else if (fi < FILES.length - 1){ setTimeout(() => { fi++; ci = 0; setHeader(); paint(); raf = requestAnimationFrame(tick); }, PAUSE); }\n else { playing = false; document.getElementById('pp').textContent = '▶ Play'; } }\n document.getElementById('pp').onclick = () => { if (!playing){ playing = true; paused = false; tick(); } else { paused = !paused; if (!paused) tick(); } document.getElementById('pp').textContent = paused ? '▶ Play' : '⏸ Pause'; };\n document.getElementById('restart').onclick = () => { fi = 0; ci = 0; playing = true; paused = false; document.getElementById('pp').textContent = '⏸ Pause'; setHeader(); paint(); cancelAnimationFrame(raf); tick(); };\n if (FILES.length){ setHeader(); paint(); tick(); }\n</script>\n</body>\n</html>\n`\n}\n","/**\n * Storyboard — compile a raw agent trace into a small set of meaningful scenes,\n * then render them as a shareable, watchable replay.\n *\n * Span[] → SemanticEvent[] → Storyboard{scenes} → { markdown | html }\n *\n * The trace is the source of truth; the storyboard is the IR; markdown/html\n * (and, in a consumer package, Remotion/MP4) are compiled targets. Everything\n * here is PURE — same spans in, same bytes out (no clock/random) — so a run's\n * replay is deterministic and diffable.\n *\n * Crucially, every scene carries a modality-typed VISUAL extracted from the\n * span — a browser/computer screenshot, a code diff, a terminal command +\n * output, file content, an API request/response, or reasoning prose — so no\n * matter what the agent did, the replay SHOWS it, not just narrates it. The\n * reducer is rules-based; an LLM pass can refine titles/summaries later, but\n * the structure + visuals do not depend on one. Renderers that need a browser\n * (Remotion, React) live in consumers; this module only emits strings.\n */\n\nimport type { Span } from '../trace/schema'\n\n/** What the agent meaningfully did — the compressed vocabulary. */\nexport type SemanticKind =\n | 'understood_task'\n | 'reasoned'\n | 'ran_command'\n | 'read_file'\n | 'edited_code'\n | 'searched'\n | 'used_browser'\n | 'used_computer'\n | 'called_api'\n | 'called_tool'\n | 'evaluated'\n | 'observed_failure'\n | 'completed'\n\n/** The modality-typed payload a scene shows. This is what makes any agent\n * action — screen, browser, shell, code, API — actually viewable. */\nexport type SceneVisual =\n | { type: 'screenshot'; src: string; caption?: string }\n | { type: 'browser'; url?: string; action?: string; screenshot?: string }\n | { type: 'diff'; path: string; patch: string }\n | { type: 'code'; path: string; content: string }\n | { type: 'terminal'; command: string; output?: string }\n | {\n type: 'api'\n method?: string\n url: string\n status?: number\n request?: string\n response?: string\n }\n | { type: 'prose'; text: string }\n | { type: 'none' }\n\nexport interface SemanticEvent {\n kind: SemanticKind\n /** One-line headline (the ticket/scene title). */\n title: string\n /** Short human summary. */\n summary: string\n /** The modality payload to show for this moment. */\n visual: SceneVisual\n /** Span ids backing this moment — the evidence trail. */\n evidenceSpanIds: string[]\n /** 1 (noise) … 5 (pivotal: failures, edits). Drives selection + duration. */\n importance: 1 | 2 | 3 | 4 | 5\n startTs: number\n endTs: number\n}\n\nexport interface ReduceOptions {\n /** Collapse adjacent same-kind moments into one. Default true. */\n collapseAdjacent?: boolean\n}\n\n// ── Modality extraction ─────────────────────────────────────────────────────\n\nfunction str(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined\n}\n\nfunction num(v: unknown): number | undefined {\n return typeof v === 'number' ? v : undefined\n}\n\nfunction attr(span: Span, ...keys: string[]): unknown {\n const a = span.attributes as Record<string, unknown> | undefined\n if (!a) return undefined\n for (const k of keys) if (a[k] != null) return a[k]\n return undefined\n}\n\nfunction asObj(v: unknown): Record<string, unknown> | undefined {\n return v && typeof v === 'object' && !Array.isArray(v)\n ? (v as Record<string, unknown>)\n : undefined\n}\n\nfunction safeJson(v: unknown): string | undefined {\n if (v == null) return undefined\n if (typeof v === 'string') return v\n try {\n return JSON.stringify(v, null, 2)\n } catch {\n return String(v)\n }\n}\n\n/** Is this string an embeddable image (data URI or http URL)? */\nfunction isImageSrc(s: string | undefined): s is string {\n return !!s && (s.startsWith('data:image') || /^https?:\\/\\//.test(s))\n}\n\n/** Pull the modality-appropriate visual out of whatever the span carries.\n * Conventions (checked in priority order): an image rides on\n * `attributes.screenshot|image|frame|videoFrame` or `result.screenshot`; a\n * diff on `attributes.diff|patch` or `args.diff`; a command on `args` /\n * `args.command`; an API call on a `url`/`method` in args; file content on\n * `result`. Unknown tools degrade to an args/result inspector. */\nfunction extractVisual(span: Span): SceneVisual {\n const shot =\n str(attr(span, 'screenshot', 'screenshotUrl', 'image', 'frame', 'videoFrame')) ??\n (span.kind === 'tool'\n ? (str(asObj(span.result)?.screenshot) ?? str(asObj(span.result)?.image))\n : undefined)\n\n if (span.kind === 'tool') {\n const tn = span.toolName.toLowerCase()\n const a = asObj(span.args)\n // computer use (GUI / desktop control)\n if (/computer|cua|desktop|\\bgui\\b|xdotool|mouse|keyboard|screen_|pyautogui/.test(tn)) {\n return {\n type: 'browser',\n action: str(a?.action) ?? span.toolName,\n url: str(a?.target),\n screenshot: shot,\n }\n }\n // browser use\n if (\n /browser|playwright|puppeteer|\\bpage\\b|navigate|goto|\\bclick\\b|\\btype\\b|screenshot|dom/.test(\n tn,\n )\n ) {\n return {\n type: 'browser',\n url: str(a?.url) ?? str(attr(span, 'url')),\n action: str(a?.action) ?? str(a?.selector) ?? span.toolName,\n screenshot: shot,\n }\n }\n // code edit → diff\n const diff = str(attr(span, 'diff', 'patch')) ?? str(a?.diff) ?? str(a?.patch)\n if (diff && /edit|write|patch|apply|str_replace|create|save|file/.test(tn)) {\n return {\n type: 'diff',\n path: str(a?.path) ?? str(a?.file) ?? str(attr(span, 'path')) ?? '',\n patch: truncate(diff, 2000),\n }\n }\n if (/edit|write|patch|apply|str_replace/.test(tn)) {\n const newText = str(a?.new_str) ?? str(a?.content) ?? str(a?.text)\n return {\n type: 'diff',\n path: str(a?.path) ?? str(a?.file) ?? '',\n patch: newText ? `+ ${truncate(newText, 1600)}` : '(no diff captured)',\n }\n }\n // file read → code\n if (/read|\\bcat\\b|open|view|get_file|load|fetch_file/.test(tn)) {\n const content =\n str(asObj(span.result)?.content) ??\n (typeof span.result === 'string' ? span.result : undefined) ??\n str(attr(span, 'content'))\n return {\n type: 'code',\n path: str(a?.path) ?? str(a?.file) ?? '',\n content: truncate(content ?? '', 1400),\n }\n }\n // search\n if (/search|grep|find|glob|query/.test(tn)) {\n return {\n type: 'terminal',\n command: `search ${str(a?.query) ?? str(a?.pattern) ?? ''}`.trim(),\n output: truncate(safeJson(span.result) ?? '', 1000),\n }\n }\n // api / http / network\n const url = str(a?.url) ?? str(attr(span, 'url'))\n if (url || /http|\\bapi\\b|fetch|request|webhook|rest|graphql|endpoint/.test(tn)) {\n return {\n type: 'api',\n method: str(a?.method) ?? str(attr(span, 'method')),\n url: url ?? span.toolName,\n status: num(attr(span, 'status', 'statusCode')) ?? num(asObj(span.result)?.status),\n request: truncate(str(a?.body) ?? safeJson(span.args) ?? '', 900),\n response: truncate(str(attr(span, 'response')) ?? safeJson(span.result) ?? '', 900),\n }\n }\n // shell / sandbox exec\n if (/shell|exec|bash|\\brun\\b|terminal|command|sandbox|process/.test(tn)) {\n const command =\n typeof span.args === 'string'\n ? span.args\n : (str(a?.command) ?? str(a?.cmd) ?? span.toolName)\n const output =\n str(attr(span, 'output', 'stdout')) ??\n (typeof span.result === 'string' ? span.result : safeJson(span.result))\n return {\n type: 'terminal',\n command: truncate(command, 240),\n output: truncate(output ?? '', 1400),\n }\n }\n // generic tool — show the call\n return {\n type: 'api',\n url: span.toolName,\n request: truncate(safeJson(span.args) ?? '', 900),\n response: truncate(safeJson(span.result) ?? '', 900),\n }\n }\n\n if (isImageSrc(shot)) return { type: 'screenshot', src: shot }\n if (span.kind === 'llm') {\n const text = str(span.output) ?? str(span.messages?.[span.messages.length - 1]?.content)\n return text ? { type: 'prose', text: truncate(text, 900) } : { type: 'none' }\n }\n if (span.kind === 'sandbox')\n return { type: 'terminal', command: span.name, output: str(attr(span, 'output')) }\n return { type: 'none' }\n}\n\n// ── Classification ──────────────────────────────────────────────────────────\n\ninterface Classified {\n kind: SemanticKind\n importance: 1 | 2 | 3 | 4 | 5\n label: string\n}\n\nfunction toolLabel(span: Span): string {\n if (span.kind === 'tool') {\n const a = asObj(span.args)\n const arg =\n typeof span.args === 'string'\n ? span.args\n : a\n ? (str(a.path) ??\n str(a.url) ??\n str(a.command) ??\n str(a.query) ??\n Object.values(a).find((v) => typeof v === 'string'))\n : undefined\n return typeof arg === 'string' && arg.length > 0\n ? `${span.toolName}: ${truncate(arg, 60)}`\n : span.toolName\n }\n return span.name\n}\n\nfunction classify(span: Span): Classified {\n if (span.status === 'error' || span.error) {\n return { kind: 'observed_failure', importance: 5, label: span.error ?? span.name }\n }\n if (span.kind === 'llm' || span.kind === 'agent')\n return { kind: 'reasoned', importance: 2, label: span.name }\n if (span.kind === 'judge') return { kind: 'evaluated', importance: 2, label: span.name }\n if (span.kind === 'retrieval') return { kind: 'searched', importance: 2, label: span.name }\n if (span.kind === 'sandbox') return { kind: 'ran_command', importance: 3, label: span.name }\n if (span.kind === 'tool') {\n const tn = span.toolName.toLowerCase()\n const label = toolLabel(span)\n if (/computer|cua|desktop|\\bgui\\b|xdotool|pyautogui/.test(tn))\n return { kind: 'used_computer', importance: 3, label }\n if (/browser|playwright|puppeteer|\\bpage\\b|navigate|goto|\\bclick\\b|screenshot|dom/.test(tn))\n return { kind: 'used_browser', importance: 3, label }\n if (/edit|write|patch|apply|str_replace|create.*file|save/.test(tn))\n return { kind: 'edited_code', importance: 4, label }\n if (/read|\\bcat\\b|open|view|get.*file|load/.test(tn))\n return { kind: 'read_file', importance: 2, label }\n if (/search|grep|find|glob|query/.test(tn)) return { kind: 'searched', importance: 2, label }\n if (\n /http|\\bapi\\b|fetch|request|webhook|rest|graphql|endpoint/.test(tn) ||\n str(asObj(span.args)?.url)\n ) {\n return { kind: 'called_api', importance: 3, label }\n }\n if (/shell|exec|bash|\\brun\\b|terminal|command|process/.test(tn))\n return { kind: 'ran_command', importance: 3, label }\n return { kind: 'called_tool', importance: 3, label }\n }\n return { kind: 'called_tool', importance: 2, label: span.name }\n}\n\nconst KIND_VERB: Record<SemanticKind, string> = {\n understood_task: 'Received the task',\n reasoned: 'Reasoned',\n ran_command: 'Ran a command',\n read_file: 'Read files',\n edited_code: 'Edited code',\n searched: 'Searched',\n used_browser: 'Used the browser',\n used_computer: 'Controlled the computer',\n called_api: 'Called an API',\n called_tool: 'Used a tool',\n evaluated: 'Evaluated the result',\n observed_failure: 'Hit a failure',\n completed: 'Finished',\n}\n\n/**\n * Reduce a span tree into the meaningful moments a viewer cares about. Each\n * span is classified + has its modality visual extracted; adjacent same-kind\n * moments collapse (the compression step), carrying the latest visual so the\n * scene shows the most recent state. A failure always stands alone.\n */\nexport function reduceToSemanticEvents(\n spans: readonly Span[],\n opts: ReduceOptions = {},\n): SemanticEvent[] {\n const collapse = opts.collapseAdjacent ?? true\n const ordered = [...spans].sort((a, b) => a.startedAt - b.startedAt)\n const raw: SemanticEvent[] = ordered.map((s) => {\n const c = classify(s)\n return {\n kind: c.kind,\n title: c.label,\n summary: `${KIND_VERB[c.kind]} — ${c.label}`,\n visual: extractVisual(s),\n evidenceSpanIds: [s.spanId],\n importance: c.importance,\n startTs: s.startedAt,\n endTs: s.endedAt ?? s.startedAt,\n }\n })\n if (!collapse) return raw\n\n const merged: SemanticEvent[] = []\n for (const ev of raw) {\n const prev = merged[merged.length - 1]\n if (prev && prev.kind === ev.kind && ev.kind !== 'observed_failure') {\n prev.evidenceSpanIds.push(...ev.evidenceSpanIds)\n prev.endTs = Math.max(prev.endTs, ev.endTs)\n if (ev.visual.type !== 'none') prev.visual = ev.visual // keep the latest state\n const n = prev.evidenceSpanIds.length\n prev.title = `${KIND_VERB[ev.kind]} (${n}×)`\n prev.summary = `${KIND_VERB[ev.kind]} ${n} time${n === 1 ? '' : 's'} — latest: ${ev.title}`\n } else {\n merged.push({ ...ev, evidenceSpanIds: [...ev.evidenceSpanIds] })\n }\n }\n return merged\n}\n\n// ── Storyboard ────────────────────────────────────────────────────────────\n\nexport type SceneType =\n | 'title_card'\n | 'reasoning'\n | 'terminal'\n | 'file'\n | 'diff'\n | 'search'\n | 'browser'\n | 'computer'\n | 'api'\n | 'tool'\n | 'eval'\n | 'error'\n | 'summary'\n\nexport interface Scene {\n sceneType: SceneType\n title: string\n narration: string\n /** The modality payload the renderer shows. */\n visual: SceneVisual\n durationMs: number\n evidenceSpanIds: string[]\n}\n\nexport interface Storyboard {\n title: string\n totalMs: number\n scenes: Scene[]\n}\n\nexport interface CompileOptions {\n /** Headline for the title card. Default \"Agent run\". */\n title?: string\n /** Max action scenes between the title + summary cards. Default 16. */\n maxScenes?: number\n}\n\nconst KIND_TO_SCENE: Record<SemanticKind, SceneType> = {\n understood_task: 'title_card',\n reasoned: 'reasoning',\n ran_command: 'terminal',\n read_file: 'file',\n edited_code: 'diff',\n searched: 'search',\n used_browser: 'browser',\n used_computer: 'computer',\n called_api: 'api',\n called_tool: 'tool',\n evaluated: 'eval',\n observed_failure: 'error',\n completed: 'summary',\n}\n\nconst DURATION_BY_IMPORTANCE: Record<1 | 2 | 3 | 4 | 5, number> = {\n 1: 2500,\n 2: 3000,\n 3: 4000,\n 4: 5000,\n 5: 6000,\n}\n\n/**\n * Select the moments worth showing and lay them out as scenes. Every failure\n * (importance 5) and edit (4) is always kept; the rest fill the budget by\n * importance, then re-sort chronological. A title card opens, a summary closes.\n */\nexport function compileStoryboard(\n events: readonly SemanticEvent[],\n opts: CompileOptions = {},\n): Storyboard {\n const title = opts.title ?? 'Agent run'\n const maxScenes = opts.maxScenes ?? 16\n\n const indexed = events.map((ev, i) => ({ ev, i }))\n const mustKeep = indexed.filter(({ ev }) => ev.importance >= 4)\n const rest = indexed\n .filter(({ ev }) => ev.importance < 4)\n .sort((a, b) => b.ev.importance - a.ev.importance || a.i - b.i)\n const budget = Math.max(0, maxScenes - mustKeep.length)\n const selected = [...mustKeep, ...rest.slice(0, budget)].sort((a, b) => a.i - b.i)\n\n const actionScenes: Scene[] = selected.map(({ ev }) => ({\n sceneType: KIND_TO_SCENE[ev.kind],\n title: ev.title,\n narration: ev.summary,\n visual: ev.visual,\n durationMs: DURATION_BY_IMPORTANCE[ev.importance],\n evidenceSpanIds: ev.evidenceSpanIds,\n }))\n\n const failures = events.filter((e) => e.kind === 'observed_failure').length\n const edits = events.filter((e) => e.kind === 'edited_code').length\n const commands = events.filter((e) => e.kind === 'ran_command').length\n const summaryNarration =\n `${events.length} moments · ${commands} command${commands === 1 ? '' : 's'} · ` +\n `${edits} edit${edits === 1 ? '' : 's'} · ${failures} failure${failures === 1 ? '' : 's'}`\n\n const scenes: Scene[] = [\n {\n sceneType: 'title_card',\n title,\n narration: 'The agent receives its task.',\n visual: { type: 'none' },\n durationMs: 3000,\n evidenceSpanIds: [],\n },\n ...actionScenes,\n {\n sceneType: 'summary',\n title: failures > 0 ? 'Finished — with failures' : 'Finished',\n narration: summaryNarration,\n visual: { type: 'none' },\n durationMs: 4000,\n evidenceSpanIds: [],\n },\n ]\n return { title, totalMs: scenes.reduce((s, sc) => s + sc.durationMs, 0), scenes }\n}\n\n// ── Renderers (pure string out) ─────────────────────────────────────────────\n\nconst SCENE_ICON: Record<SceneType, string> = {\n title_card: '🎬',\n reasoning: '🧠',\n terminal: '⌨️',\n file: '📄',\n diff: '✏️',\n search: '🔎',\n browser: '🌐',\n computer: '🖥️',\n api: '🔌',\n tool: '🔧',\n eval: '⚖️',\n error: '❌',\n summary: '🏁',\n}\n\nfunction mmss(ms: number): string {\n const s = Math.round(ms / 1000)\n return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`\n}\n\nfunction truncate(s: string, max: number): string {\n return s.length <= max ? s : `${s.slice(0, Math.max(0, max - 1))}…`\n}\n\nfunction escapeHtml(s: string): string {\n return s\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n}\n\n/** A short modality tag for the markdown shot list. */\nfunction visualMarkdown(v: SceneVisual): string {\n switch (v.type) {\n case 'screenshot':\n return `🖼 screenshot (${truncate(v.src, 60)})`\n case 'browser':\n return `🌐 ${v.action ?? 'browser'}${v.url ? ` → ${v.url}` : ''}${v.screenshot ? ' [screenshot]' : ''}`\n case 'diff':\n return `\\n\\n\\`\\`\\`diff\\n${truncate(v.patch, 600)}\\n\\`\\`\\`${v.path ? `\\n_${v.path}_` : ''}`\n case 'code':\n return `\\n\\n\\`\\`\\`\\n${truncate(v.content, 500)}\\n\\`\\`\\`${v.path ? `\\n_${v.path}_` : ''}`\n case 'terminal':\n return `\\n\\n\\`\\`\\`sh\\n$ ${v.command}${v.output ? `\\n${truncate(v.output, 500)}` : ''}\\n\\`\\`\\``\n case 'api':\n return `🔌 ${v.method ?? 'CALL'} ${v.url}${v.status != null ? ` → ${v.status}` : ''}`\n case 'prose':\n return `\\n\\n> ${truncate(v.text, 400).replace(/\\n/g, '\\n> ')}`\n default:\n return ''\n }\n}\n\n/** Build the (escaped, structured) HTML for a scene's visual. We never inject\n * raw agent markup — every text part is escaped; only image `src` (data/http)\n * is passed through as an attribute. */\nfunction visualHtml(v: SceneVisual): string {\n switch (v.type) {\n case 'screenshot':\n return `<img class=\"shot\" src=\"${escapeHtml(v.src)}\" alt=\"screenshot\" loading=\"lazy\"/>`\n case 'browser': {\n const bar = `<div class=\"urlbar\">${escapeHtml(v.url ?? v.action ?? 'browser')}</div>`\n const body = isImageSrc(v.screenshot)\n ? `<img class=\"shot\" src=\"${escapeHtml(v.screenshot)}\" alt=\"page\" loading=\"lazy\"/>`\n : `<div class=\"browser-action\">${escapeHtml(v.action ?? 'navigated')}</div>`\n return `<div class=\"browser\">${bar}${body}</div>`\n }\n case 'diff': {\n const lines = v.patch.split('\\n').map((l) => {\n const cls = l.startsWith('+') ? 'add' : l.startsWith('-') ? 'del' : ''\n return `<span class=\"${cls}\">${escapeHtml(l)}</span>`\n })\n return `${v.path ? `<div class=\"pathhdr\">${escapeHtml(v.path)}</div>` : ''}<pre class=\"diff\">${lines.join('\\n')}</pre>`\n }\n case 'code':\n return `${v.path ? `<div class=\"pathhdr\">${escapeHtml(v.path)}</div>` : ''}<pre class=\"code\">${escapeHtml(v.content)}</pre>`\n case 'terminal':\n return `<pre class=\"term\"><span class=\"cmd\">$ ${escapeHtml(v.command)}</span>${v.output ? `\\n${escapeHtml(v.output)}` : ''}</pre>`\n case 'api': {\n const badge = `<span class=\"method\">${escapeHtml(v.method ?? 'CALL')}</span> <span class=\"url\">${escapeHtml(v.url)}</span>${v.status != null ? ` <span class=\"status s${Math.floor(v.status / 100)}\">${v.status}</span>` : ''}`\n const req = v.request\n ? `<div class=\"kv\"><b>req</b><pre>${escapeHtml(v.request)}</pre></div>`\n : ''\n const res = v.response\n ? `<div class=\"kv\"><b>res</b><pre>${escapeHtml(v.response)}</pre></div>`\n : ''\n return `<div class=\"api\"><div class=\"apihdr\">${badge}</div>${req}${res}</div>`\n }\n case 'prose':\n return `<div class=\"prose\">${escapeHtml(v.text)}</div>`\n default:\n return ''\n }\n}\n\n/** Render the storyboard as a Markdown timeline — the human-readable shot list. */\nexport function renderStoryboardMarkdown(storyboard: Storyboard): string {\n const out: string[] = [\n `# 🎬 ${storyboard.title}`,\n '',\n `_${storyboard.scenes.length} scenes · ${mmss(storyboard.totalMs)} replay_`,\n '',\n ]\n let elapsed = 0\n for (const sc of storyboard.scenes) {\n out.push(`### [${mmss(elapsed)}] ${SCENE_ICON[sc.sceneType]} ${sc.title}`)\n out.push('')\n out.push(sc.narration)\n const vm = visualMarkdown(sc.visual)\n if (vm) out.push(vm)\n if (sc.evidenceSpanIds.length > 0) {\n out.push('')\n out.push(`_evidence: ${sc.evidenceSpanIds.length} span(s)_`)\n }\n out.push('')\n elapsed += sc.durationMs\n }\n return out.join('\\n')\n}\n\nexport interface HtmlRenderOptions {\n /** Document title + on-page heading. Defaults to the storyboard title. */\n title?: string\n}\n\n/**\n * Render the storyboard as a self-contained, auto-playing HTML replay — one\n * shareable file, no build step, no external assets. Each scene animates in\n * for its duration and SHOWS its modality (screenshot / diff / terminal / API\n * / browser / prose); controls let a viewer scrub. This is the \"free clip\" a\n * run produces; an MP4 is the same storyboard fed to Remotion in a consumer.\n */\nexport function renderStoryboardHtml(storyboard: Storyboard, opts: HtmlRenderOptions = {}): string {\n const docTitle = opts.title ?? storyboard.title\n // Pre-render each scene's visual to safe HTML here (testable, escaped); the\n // player just sets innerHTML. `<` is escaped in the JSON so a payload can't\n // break out of the <script> tag.\n const scenesJson = JSON.stringify(\n storyboard.scenes.map((s) => ({\n icon: SCENE_ICON[s.sceneType],\n type: s.sceneType,\n title: s.title,\n narration: s.narration,\n durationMs: s.durationMs,\n evidence: s.evidenceSpanIds.length,\n visual: visualHtml(s.visual),\n })),\n ).replace(/</g, '\\\\u003c')\n\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<title>${escapeHtml(docTitle)}</title>\n<style>\n :root { color-scheme: dark; }\n * { box-sizing: border-box; }\n body { margin: 0; font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, sans-serif;\n background: #0b0f17; color: #e6edf3; display: flex; min-height: 100vh; align-items: center; justify-content: center; }\n .stage { width: min(900px, 95vw); }\n h1 { font-size: 1.1rem; font-weight: 600; color: #9aa7b5; margin: 0 0 14px; letter-spacing: .02em; }\n .card { background: #111824; border: 1px solid #1e2a3a; border-radius: 14px; padding: 24px 28px;\n min-height: 300px; box-shadow: 0 12px 40px rgba(0,0,0,.45); position: relative; overflow: hidden; }\n .card::before { content: \"\"; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--accent, #3b82f6); }\n .head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }\n .icon { font-size: 2rem; line-height: 1; }\n .title { font-size: 1.3rem; font-weight: 650; }\n .narration { color: #9fb0c0; font-size: .95rem; margin-bottom: 14px; }\n .visual { margin-top: 6px; }\n .visual img.shot { max-width: 100%; max-height: 360px; border-radius: 8px; border: 1px solid #1e2a3a; display: block; }\n .visual pre { background: #0a0e15; border: 1px solid #1e2a3a; border-radius: 8px; padding: 12px 14px;\n overflow: auto; max-height: 340px; font: 13px/1.5 ui-monospace, \"SF Mono\", Menlo, monospace; white-space: pre-wrap; word-break: break-word; }\n .pathhdr { font: 12px ui-monospace, monospace; color: #7d8da0; margin-bottom: 4px; }\n .diff .add { color: #56d364; } .diff .del { color: #f85149; }\n .term .cmd { color: #eab308; }\n .browser { border: 1px solid #1e2a3a; border-radius: 8px; overflow: hidden; }\n .urlbar { background: #0a0e15; padding: 7px 12px; font: 12px ui-monospace, monospace; color: #8b98a6; border-bottom: 1px solid #1e2a3a; }\n .browser-action { padding: 28px; color: #9fb0c0; text-align: center; }\n .api .apihdr { font: 13px ui-monospace, monospace; margin-bottom: 8px; }\n .method { background: #1b2636; padding: 2px 8px; border-radius: 5px; color: #79c0ff; }\n .status.s2 { color: #56d364; } .status.s4, .status.s5 { color: #f85149; }\n .kv { margin-top: 6px; } .kv b { color: #7d8da0; font-weight: 600; font-size: 12px; }\n .prose { color: #c9d4e0; font-size: 1rem; white-space: pre-wrap; max-height: 340px; overflow: auto; }\n .type-error { --accent: #ef4444; } .type-diff { --accent: #22c55e; } .type-terminal { --accent: #eab308; }\n .type-browser { --accent: #06b6d4; } .type-computer { --accent: #14b8a6; } .type-api { --accent: #79c0ff; }\n .type-summary { --accent: #a855f7; } .type-title_card { --accent: #3b82f6; }\n .scene-enter { animation: pop .45s cubic-bezier(.2,.7,.3,1.2); }\n @keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }\n .bar { height: 4px; background: #1e2a3a; border-radius: 4px; margin-top: 14px; overflow: hidden; }\n .bar > i { display: block; height: 100%; width: 0; background: var(--accent, #3b82f6); transition: width .1s linear; }\n .controls { display: flex; gap: 10px; align-items: center; margin-top: 14px; color: #8b98a6; font-size: .85rem; }\n button { background: #1b2636; color: #e6edf3; border: 1px solid #2a3a4f; border-radius: 8px; padding: 6px 12px; cursor: pointer; font: inherit; }\n button:hover { background: #243349; }\n .dots { display: flex; gap: 5px; margin-left: auto; flex-wrap: wrap; }\n .dot { width: 7px; height: 7px; border-radius: 50%; background: #2a3a4f; cursor: pointer; }\n .dot.on { background: var(--accent, #3b82f6); }\n</style>\n</head>\n<body>\n<div class=\"stage\">\n <h1>🎬 ${escapeHtml(docTitle)}</h1>\n <div class=\"card\" id=\"card\">\n <div class=\"head\"><span class=\"icon\" id=\"icon\"></span><span class=\"title\" id=\"title\"></span></div>\n <div class=\"narration\" id=\"narration\"></div>\n <div class=\"visual\" id=\"visual\"></div>\n <div class=\"bar\"><i id=\"fill\"></i></div>\n </div>\n <div class=\"controls\">\n <button id=\"playPause\">⏸ Pause</button>\n <button id=\"prev\">◀ Prev</button>\n <button id=\"next\">Next ▶</button>\n <span id=\"counter\"></span>\n <span class=\"dots\" id=\"dots\"></span>\n </div>\n</div>\n<script>\n const SCENES = ${scenesJson};\n let i = 0, playing = true, raf = 0, start = 0;\n const card = document.getElementById('card'), counter = document.getElementById('counter'), dotsEl = document.getElementById('dots');\n SCENES.forEach((_, k) => { const d = document.createElement('span'); d.className = 'dot'; d.onclick = () => go(k); dotsEl.appendChild(d); });\n function paint() {\n const s = SCENES[i];\n card.className = 'card scene-enter type-' + s.type;\n document.getElementById('icon').textContent = s.icon;\n document.getElementById('title').textContent = s.title;\n document.getElementById('narration').textContent = s.narration;\n document.getElementById('visual').innerHTML = s.visual || '';\n counter.textContent = (i + 1) + ' / ' + SCENES.length;\n [...dotsEl.children].forEach((d, k) => d.className = 'dot' + (k === i ? ' on' : ''));\n void card.offsetWidth;\n }\n function tick(t) {\n if (!start) start = t;\n const s = SCENES[i], p = Math.min(1, (t - start) / s.durationMs);\n document.getElementById('fill').style.width = (p * 100) + '%';\n if (p >= 1) { if (i < SCENES.length - 1) { go(i + 1); } else { playing = false; updateBtn(); return; } }\n if (playing) raf = requestAnimationFrame(tick);\n }\n function go(n) { i = Math.max(0, Math.min(SCENES.length - 1, n)); start = 0; cancelAnimationFrame(raf); paint(); if (playing) raf = requestAnimationFrame(tick); }\n function updateBtn() { document.getElementById('playPause').textContent = playing ? '⏸ Pause' : '▶ Play'; }\n document.getElementById('playPause').onclick = () => { playing = !playing; updateBtn(); start = 0; if (playing) raf = requestAnimationFrame(tick); else cancelAnimationFrame(raf); };\n document.getElementById('next').onclick = () => go(i + 1);\n document.getElementById('prev').onclick = () => go(i - 1);\n paint(); raf = requestAnimationFrame(tick);\n</script>\n</body>\n</html>\n`\n}\n\n// The \"watch the agent write code\" keystroke animation + the CodeEdit IR a\n// Remotion consumer reads. Composes with this pipeline: a 'diff' scene shows an\n// inline card here; renderCodeAnimationHtml types the whole file out there.\nexport * from './code-edit'\n"],"mappings":";;;AAmBA,IAAM,aACJ;AAmBF,SAAS,WAAW,MAAkC;AACpD,QAAM,MAAM,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI,GAAG,YAAY,IAAI;AACxE,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,MAA8B;AAAA,IAClC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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgC7B;","names":[]}
1
+ {"version":3,"sources":["../../src/storyboard/code-edit.ts","../../src/storyboard/index.ts"],"sourcesContent":["/**\n * Code-edit extraction + the \"watch the agent write code\" animation.\n *\n * The base storyboard (./index) compresses a run into scenes but keeps scenes\n * payload-free (title + narration + evidence span ids). To actually SHOW the\n * code an agent wrote, this module pulls the concrete edit (path, diff,\n * before/after, language) out of the raw edit-tool spans and renders a\n * self-contained HTML replay that types each file out, character by character,\n * like an editor recording.\n *\n * Additive on purpose: it reuses the canonical `Span` (trace/schema) and the\n * `Storyboard` IR (./index) without modifying the reducer/compiler — so it\n * composes with the existing pipeline and a Remotion consumer can read the same\n * `CodeEdit[]` to render an MP4.\n */\n\nimport type { Span } from '../trace/schema'\nimport type { Scene, Storyboard } from './index'\n\nconst EDIT_TOOLS =\n /(edit|write|patch|apply|str_replace|create.*file|save|insert|update.*file|multi_edit)/i\n\n/** A concrete code change lifted from a tool span. */\nexport interface CodeEdit {\n /** Span the edit came from — back-reference into the trace. */\n spanId: string\n path: string\n language?: string\n /** Unified diff, when the tool carried one. */\n diff?: string\n /** Full file body before / after, when present — enables true keystroke\n * animation rather than only flashing a diff. */\n before?: string\n after?: string\n additions: number\n deletions: number\n startedAt: number\n}\n\nfunction languageOf(path: string): string | undefined {\n const ext = path.includes('.') ? path.split('.').pop()?.toLowerCase() : undefined\n if (!ext) return undefined\n const map: Record<string, string> = {\n ts: 'ts',\n tsx: 'tsx',\n js: 'js',\n jsx: 'jsx',\n mjs: 'js',\n cjs: 'js',\n py: 'python',\n rs: 'rust',\n go: 'go',\n sol: 'solidity',\n java: 'java',\n rb: 'ruby',\n php: 'php',\n c: 'c',\n cpp: 'cpp',\n cs: 'csharp',\n css: 'css',\n scss: 'scss',\n html: 'html',\n json: 'json',\n yaml: 'yaml',\n yml: 'yaml',\n toml: 'toml',\n md: 'markdown',\n sh: 'bash',\n sql: 'sql',\n }\n return map[ext] ?? ext\n}\n\nfunction pick(obj: unknown, keys: string[]): string | undefined {\n if (!obj || typeof obj !== 'object') return undefined\n const rec = obj as Record<string, unknown>\n for (const k of Object.keys(rec)) {\n if (keys.includes(k.toLowerCase())) {\n const v = rec[k]\n if (typeof v === 'string') return v\n }\n }\n return undefined\n}\n\nfunction countDiff(diff?: string): { additions: number; deletions: number } {\n if (!diff) return { additions: 0, deletions: 0 }\n let additions = 0\n let deletions = 0\n for (const line of diff.split('\\n')) {\n if (line.startsWith('+') && !line.startsWith('+++')) additions++\n else if (line.startsWith('-') && !line.startsWith('---')) deletions++\n }\n return { additions, deletions }\n}\n\n/** Extract a CodeEdit from a single span, or undefined if it is not an edit. */\nexport function codeEditFromSpan(span: Span): CodeEdit | undefined {\n if (span.kind !== 'tool') return undefined\n const tool = span as Extract<Span, { kind: 'tool' }>\n if (!EDIT_TOOLS.test(tool.toolName)) return undefined\n const path = pick(tool.args, ['path', 'file_path', 'filepath', 'filename', 'file'])\n if (!path) return undefined\n const diff = pick(tool.args, ['diff', 'patch'])\n const after = pick(tool.args, ['content', 'new_str', 'new_string', 'newtext', 'text', 'body'])\n const before = pick(tool.args, ['old_str', 'old_string', 'oldtext', 'original'])\n const counts = countDiff(diff)\n return {\n spanId: span.spanId,\n path,\n language: languageOf(path),\n diff,\n before,\n after,\n additions: diff ? counts.additions : after ? after.split('\\n').length : 0,\n deletions: diff ? counts.deletions : 0,\n startedAt: span.startedAt,\n }\n}\n\n/** All code edits in a run, in chronological order. */\nexport function extractCodeEdits(spans: readonly Span[]): CodeEdit[] {\n return spans\n .map(codeEditFromSpan)\n .filter((e): e is CodeEdit => e != null)\n .sort((a, b) => a.startedAt - b.startedAt)\n}\n\n/** Pair each code-edit (`diff`) scene with its concrete edit, matched via the\n * scene's evidence span ids. Scenes without a recoverable edit are dropped. */\nexport function codeEditsForStoryboard(\n storyboard: Storyboard,\n spans: readonly Span[],\n): Array<{ scene: Scene; edit: CodeEdit }> {\n const bySpan = new Map(extractCodeEdits(spans).map((e) => [e.spanId, e]))\n const out: Array<{ scene: Scene; edit: CodeEdit }> = []\n for (const scene of storyboard.scenes) {\n if (scene.sceneType !== 'diff') continue\n const edit = scene.evidenceSpanIds\n .map((id) => bySpan.get(id))\n .find((e): e is CodeEdit => e != null)\n if (edit) out.push({ scene, edit })\n }\n return out\n}\n\n/** The text the animation types for an edit: prefer the full new file body,\n * then the added lines of a diff, then a minimal placeholder so the scene is\n * never blank. */\nexport function editAnimationText(edit: CodeEdit): string {\n if (edit.after && edit.after.trim()) return edit.after\n if (edit.diff) {\n const added = edit.diff\n .split('\\n')\n .filter((l) => l.startsWith('+') && !l.startsWith('+++'))\n .map((l) => l.slice(1))\n .join('\\n')\n if (added.trim()) return added\n }\n return `// ${edit.path}\\n// (${edit.additions} line${edit.additions === 1 ? '' : 's'} written)`\n}\n\nfunction esc(s: string): string {\n return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n}\n\nexport interface CodeAnimationOptions {\n /** Page title. Default \"Agent writing code\". */\n title?: string\n /** Characters typed per animation tick. Higher = faster. Default 4. */\n charsPerTick?: number\n /** Pause between files, ms. Default 900. */\n pauseBetweenMs?: number\n}\n\n/**\n * Render a self-contained HTML page that animates the agent writing each file,\n * character by character, with a filename tab, line numbers, and a blinking\n * cursor — the shareable \"watch it build\" clip. No build step, no assets, no\n * deps. The same `CodeEdit[]` feeds a Remotion MP4 renderer in a consumer\n * package; this is the dependency-free baseline.\n */\nexport function renderCodeAnimationHtml(\n source: readonly Span[] | readonly CodeEdit[],\n opts: CodeAnimationOptions = {},\n): string {\n const edits: CodeEdit[] =\n source.length > 0 && 'path' in (source[0] as object)\n ? (source as CodeEdit[])\n : extractCodeEdits(source as readonly Span[])\n\n const files = edits.map((e) => ({\n path: e.path,\n language: e.language ?? '',\n additions: e.additions,\n deletions: e.deletions,\n code: editAnimationText(e),\n }))\n const title = opts.title ?? 'Agent writing code'\n const charsPerTick = opts.charsPerTick ?? 4\n const pauseBetweenMs = opts.pauseBetweenMs ?? 900\n const filesJson = JSON.stringify(files)\n\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<title>${esc(title)}</title>\n<style>\n :root { color-scheme: dark; }\n * { box-sizing: border-box; }\n body { margin: 0; background: #0b0f17; color: #e6edf3;\n font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;\n display: flex; flex-direction: column; min-height: 100vh; align-items: center; justify-content: center; gap: 14px; }\n h1 { font-family: ui-sans-serif, system-ui, sans-serif; font-size: 1rem; font-weight: 600; color: #9aa7b5; margin: 0; }\n .editor { width: min(900px, 94vw); background: #0d1320; border: 1px solid #1e2a3a; border-radius: 12px;\n overflow: hidden; box-shadow: 0 16px 50px rgba(0,0,0,.5); }\n .tabbar { display: flex; align-items: center; gap: 8px; background: #111a29; padding: 9px 14px; border-bottom: 1px solid #1e2a3a; }\n .dot { width: 11px; height: 11px; border-radius: 50%; }\n .dot.r { background: #ff5f56; } .dot.y { background: #ffbd2e; } .dot.g { background: #27c93f; }\n .tab { margin-left: 10px; background: #0d1320; padding: 5px 12px; border-radius: 7px 7px 0 0;\n color: #cdd9e5; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .85rem; }\n .lang { color: #5b6b7d; font-size: .75rem; margin-left: 6px; }\n .adds { margin-left: auto; color: #3fb950; font-size: .78rem; font-family: ui-sans-serif, system-ui, sans-serif; }\n .dels { color: #f85149; margin-left: 8px; }\n .codewrap { display: flex; max-height: 60vh; overflow: auto; }\n .gutter { padding: 14px 10px 14px 14px; text-align: right; color: #3a4757; user-select: none; white-space: pre; }\n pre { margin: 0; padding: 14px 18px 14px 6px; white-space: pre; tab-size: 2; flex: 1; }\n .cursor { display: inline-block; width: 8px; margin-left: 1px; background: #58a6ff; animation: blink .9s steps(1) infinite; }\n @keyframes blink { 50% { opacity: 0; } }\n .controls { display: flex; gap: 10px; align-items: center; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .85rem; color: #8b98a6; }\n button { background: #1b2636; color: #e6edf3; border: 1px solid #2a3a4f; border-radius: 8px; padding: 6px 12px; cursor: pointer; font: inherit; }\n button:hover { background: #243349; }\n .empty { padding: 40px; color: #5b6b7d; }\n</style>\n</head>\n<body>\n <h1>✏️ ${esc(title)}</h1>\n <div class=\"editor\">\n <div class=\"tabbar\">\n <span class=\"dot r\"></span><span class=\"dot y\"></span><span class=\"dot g\"></span>\n <span class=\"tab\" id=\"tab\">—</span><span class=\"lang\" id=\"lang\"></span>\n <span class=\"adds\" id=\"adds\"></span>\n </div>\n <div class=\"codewrap\"><div class=\"gutter\" id=\"gutter\">1</div><pre id=\"code\"></pre></div>\n </div>\n <div class=\"controls\">\n <button id=\"pp\">⏸ Pause</button><button id=\"restart\">↻ Restart</button>\n <span id=\"counter\"></span>\n </div>\n<script>\n const FILES = ${filesJson};\n const CPT = ${charsPerTick}, PAUSE = ${pauseBetweenMs};\n const codeEl = document.getElementById('code'), gutterEl = document.getElementById('gutter');\n const tabEl = document.getElementById('tab'), langEl = document.getElementById('lang');\n const addsEl = document.getElementById('adds'), counterEl = document.getElementById('counter');\n let fi = 0, ci = 0, playing = true, raf = 0, paused = false;\n if (!FILES.length) { codeEl.innerHTML = '<span class=\"empty\">No code edits in this run.</span>'; }\n function esc(s){return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');}\n function setHeader(){ const f = FILES[fi]; tabEl.textContent = f.path; langEl.textContent = f.language || '';\n addsEl.innerHTML = '+' + f.additions + (f.deletions ? ' <span class=\"dels\">-' + f.deletions + '</span>' : '');\n counterEl.textContent = (fi+1) + ' / ' + FILES.length + ' files'; }\n function paint(){ const f = FILES[fi]; const shown = f.code.slice(0, ci);\n const lines = (shown.match(/\\\\n/g) || []).length + 1;\n gutterEl.textContent = Array.from({length: lines}, (_, k) => k+1).join('\\\\n');\n codeEl.innerHTML = esc(shown) + '<span class=\"cursor\">&nbsp;</span>';\n const wrap = codeEl.parentElement; wrap.scrollTop = wrap.scrollHeight; }\n function tick(){ if (paused || !FILES.length) return;\n const f = FILES[fi];\n if (ci < f.code.length){ ci = Math.min(f.code.length, ci + CPT); paint(); raf = requestAnimationFrame(tick); }\n else if (fi < FILES.length - 1){ setTimeout(() => { fi++; ci = 0; setHeader(); paint(); raf = requestAnimationFrame(tick); }, PAUSE); }\n else { playing = false; document.getElementById('pp').textContent = '▶ Play'; } }\n document.getElementById('pp').onclick = () => { if (!playing){ playing = true; paused = false; tick(); } else { paused = !paused; if (!paused) tick(); } document.getElementById('pp').textContent = paused ? '▶ Play' : '⏸ Pause'; };\n document.getElementById('restart').onclick = () => { fi = 0; ci = 0; playing = true; paused = false; document.getElementById('pp').textContent = '⏸ Pause'; setHeader(); paint(); cancelAnimationFrame(raf); tick(); };\n if (FILES.length){ setHeader(); paint(); tick(); }\n</script>\n</body>\n</html>\n`\n}\n","/**\n * Storyboard — compile a raw agent trace into a small set of meaningful scenes,\n * then render them as a shareable, watchable replay.\n *\n * Span[] → SemanticEvent[] → Storyboard{scenes} → { markdown | html }\n *\n * The trace is the source of truth; the storyboard is the IR; markdown/html\n * (and, in a consumer package, Remotion/MP4) are compiled targets. Everything\n * here is PURE — same spans in, same bytes out (no clock/random) — so a run's\n * replay is deterministic and diffable.\n *\n * Crucially, every scene carries a modality-typed VISUAL extracted from the\n * span — a browser/computer screenshot, a code diff, a terminal command +\n * output, file content, an API request/response, or reasoning prose — so no\n * matter what the agent did, the replay SHOWS it, not just narrates it. The\n * reducer is rules-based; an LLM pass can refine titles/summaries later, but\n * the structure + visuals do not depend on one. Renderers that need a browser\n * (Remotion, React) live in consumers; this module only emits strings.\n */\n\nimport type { Span } from '../trace/schema'\n\n/** What the agent meaningfully did — the compressed vocabulary. */\nexport type SemanticKind =\n | 'understood_task'\n | 'user_message'\n | 'agent_reply'\n | 'reasoned'\n | 'ran_command'\n | 'read_file'\n | 'edited_code'\n | 'searched'\n | 'used_browser'\n | 'used_computer'\n | 'called_api'\n | 'called_tool'\n | 'evaluated'\n | 'observed_failure'\n | 'completed'\n\n/** The modality-typed payload a scene shows. This is what makes any agent\n * action — screen, browser, shell, code, API — actually viewable. */\nexport type SceneVisual =\n | { type: 'screenshot'; src: string; caption?: string }\n | { type: 'browser'; url?: string; action?: string; screenshot?: string }\n | { type: 'diff'; path: string; patch: string }\n | { type: 'code'; path: string; content: string }\n | { type: 'terminal'; command: string; output?: string }\n | {\n type: 'api'\n method?: string\n url: string\n status?: number\n request?: string\n response?: string\n }\n | { type: 'prose'; text: string }\n | { type: 'none' }\n\nexport interface SemanticEvent {\n kind: SemanticKind\n /** One-line headline (the ticket/scene title). */\n title: string\n /** Short human summary. */\n summary: string\n /** The modality payload to show for this moment. */\n visual: SceneVisual\n /** Span ids backing this moment — the evidence trail. */\n evidenceSpanIds: string[]\n /** 1 (noise) … 5 (pivotal: failures, edits). Drives selection + duration. */\n importance: 1 | 2 | 3 | 4 | 5\n startTs: number\n endTs: number\n}\n\nexport interface ReduceOptions {\n /** Collapse adjacent same-kind moments into one. Default true. */\n collapseAdjacent?: boolean\n}\n\n// ── Modality extraction ─────────────────────────────────────────────────────\n\nfunction str(v: unknown): string | undefined {\n return typeof v === 'string' && v.length > 0 ? v : undefined\n}\n\nfunction num(v: unknown): number | undefined {\n return typeof v === 'number' ? v : undefined\n}\n\nfunction attr(span: Span, ...keys: string[]): unknown {\n const a = span.attributes as Record<string, unknown> | undefined\n if (!a) return undefined\n for (const k of keys) if (a[k] != null) return a[k]\n return undefined\n}\n\nfunction asObj(v: unknown): Record<string, unknown> | undefined {\n return v && typeof v === 'object' && !Array.isArray(v)\n ? (v as Record<string, unknown>)\n : undefined\n}\n\nfunction safeJson(v: unknown): string | undefined {\n if (v == null) return undefined\n if (typeof v === 'string') return v\n try {\n return JSON.stringify(v, null, 2)\n } catch {\n return String(v)\n }\n}\n\n/** Is this string an embeddable image (data URI or http URL)? */\nfunction isImageSrc(s: string | undefined): s is string {\n return !!s && (s.startsWith('data:image') || /^https?:\\/\\//.test(s))\n}\n\n/** Pull the modality-appropriate visual out of whatever the span carries.\n * Conventions (checked in priority order): an image rides on\n * `attributes.screenshot|image|frame|videoFrame` or `result.screenshot`; a\n * diff on `attributes.diff|patch` or `args.diff`; a command on `args` /\n * `args.command`; an API call on a `url`/`method` in args; file content on\n * `result`. Unknown tools degrade to an args/result inspector. */\nfunction extractVisual(span: Span): SceneVisual {\n const shot =\n str(attr(span, 'screenshot', 'screenshotUrl', 'image', 'frame', 'videoFrame')) ??\n (span.kind === 'tool'\n ? (str(asObj(span.result)?.screenshot) ?? str(asObj(span.result)?.image))\n : undefined)\n\n if (span.kind === 'tool') {\n const tn = span.toolName.toLowerCase()\n const a = asObj(span.args)\n // computer use (GUI / desktop control)\n if (/computer|cua|desktop|\\bgui\\b|xdotool|mouse|keyboard|screen_|pyautogui/.test(tn)) {\n return {\n type: 'browser',\n action: str(a?.action) ?? span.toolName,\n url: str(a?.target),\n screenshot: shot,\n }\n }\n // browser use\n if (\n /browser|playwright|puppeteer|\\bpage\\b|navigate|goto|\\bclick\\b|\\btype\\b|screenshot|dom/.test(\n tn,\n )\n ) {\n return {\n type: 'browser',\n url: str(a?.url) ?? str(attr(span, 'url')),\n action: str(a?.action) ?? str(a?.selector) ?? span.toolName,\n screenshot: shot,\n }\n }\n // code edit → diff\n const diff = str(attr(span, 'diff', 'patch')) ?? str(a?.diff) ?? str(a?.patch)\n if (diff && /edit|write|patch|apply|str_replace|create|save|file/.test(tn)) {\n return {\n type: 'diff',\n path: str(a?.path) ?? str(a?.file) ?? str(attr(span, 'path')) ?? '',\n patch: truncate(diff, 2000),\n }\n }\n if (/edit|write|patch|apply|str_replace/.test(tn)) {\n const newText = str(a?.new_str) ?? str(a?.content) ?? str(a?.text)\n return {\n type: 'diff',\n path: str(a?.path) ?? str(a?.file) ?? '',\n patch: newText ? `+ ${truncate(newText, 1600)}` : '(no diff captured)',\n }\n }\n // file read → code\n if (/read|\\bcat\\b|open|view|get_file|load|fetch_file/.test(tn)) {\n const content =\n str(asObj(span.result)?.content) ??\n (typeof span.result === 'string' ? span.result : undefined) ??\n str(attr(span, 'content'))\n return {\n type: 'code',\n path: str(a?.path) ?? str(a?.file) ?? '',\n content: truncate(content ?? '', 1400),\n }\n }\n // search\n if (/search|grep|find|glob|query/.test(tn)) {\n return {\n type: 'terminal',\n command: `search ${str(a?.query) ?? str(a?.pattern) ?? ''}`.trim(),\n output: truncate(safeJson(span.result) ?? '', 1000),\n }\n }\n // api / http / network\n const url = str(a?.url) ?? str(attr(span, 'url'))\n if (url || /http|\\bapi\\b|fetch|request|webhook|rest|graphql|endpoint/.test(tn)) {\n return {\n type: 'api',\n method: str(a?.method) ?? str(attr(span, 'method')),\n url: url ?? span.toolName,\n status: num(attr(span, 'status', 'statusCode')) ?? num(asObj(span.result)?.status),\n request: truncate(str(a?.body) ?? safeJson(span.args) ?? '', 900),\n response: truncate(str(attr(span, 'response')) ?? safeJson(span.result) ?? '', 900),\n }\n }\n // shell / sandbox exec\n if (/shell|exec|bash|\\brun\\b|terminal|command|sandbox|process/.test(tn)) {\n const command =\n typeof span.args === 'string'\n ? span.args\n : (str(a?.command) ?? str(a?.cmd) ?? span.toolName)\n const output =\n str(attr(span, 'output', 'stdout')) ??\n (typeof span.result === 'string' ? span.result : safeJson(span.result))\n return {\n type: 'terminal',\n command: truncate(command, 240),\n output: truncate(output ?? '', 1400),\n }\n }\n // generic tool — show the call\n return {\n type: 'api',\n url: span.toolName,\n request: truncate(safeJson(span.args) ?? '', 900),\n response: truncate(safeJson(span.result) ?? '', 900),\n }\n }\n\n if (isImageSrc(shot)) return { type: 'screenshot', src: shot }\n if (span.kind === 'llm') {\n const text = str(span.output) ?? str(span.messages?.[span.messages.length - 1]?.content)\n return text ? { type: 'prose', text: truncate(text, 900) } : { type: 'none' }\n }\n if (span.kind === 'sandbox')\n return { type: 'terminal', command: span.name, output: str(attr(span, 'output')) }\n return { type: 'none' }\n}\n\n// ── Classification ──────────────────────────────────────────────────────────\n\ninterface Classified {\n kind: SemanticKind\n importance: 1 | 2 | 3 | 4 | 5\n label: string\n}\n\nfunction toolLabel(span: Span): string {\n if (span.kind === 'tool') {\n const a = asObj(span.args)\n const arg =\n typeof span.args === 'string'\n ? span.args\n : a\n ? (str(a.path) ??\n str(a.url) ??\n str(a.command) ??\n str(a.query) ??\n Object.values(a).find((v) => typeof v === 'string'))\n : undefined\n return typeof arg === 'string' && arg.length > 0\n ? `${span.toolName}: ${truncate(arg, 60)}`\n : span.toolName\n }\n return span.name\n}\n\nfunction classify(span: Span): Classified {\n if (span.status === 'error' || span.error) {\n return { kind: 'observed_failure', importance: 5, label: span.error ?? span.name }\n }\n if (span.kind === 'llm' || span.kind === 'agent')\n return { kind: 'reasoned', importance: 2, label: span.name }\n if (span.kind === 'judge') return { kind: 'evaluated', importance: 2, label: span.name }\n if (span.kind === 'retrieval') return { kind: 'searched', importance: 2, label: span.name }\n if (span.kind === 'sandbox') return { kind: 'ran_command', importance: 3, label: span.name }\n if (span.kind === 'tool') {\n const tn = span.toolName.toLowerCase()\n const label = toolLabel(span)\n if (/computer|cua|desktop|\\bgui\\b|xdotool|pyautogui/.test(tn))\n return { kind: 'used_computer', importance: 3, label }\n if (/browser|playwright|puppeteer|\\bpage\\b|navigate|goto|\\bclick\\b|screenshot|dom/.test(tn))\n return { kind: 'used_browser', importance: 3, label }\n if (/edit|write|patch|apply|str_replace|create.*file|save/.test(tn))\n return { kind: 'edited_code', importance: 4, label }\n if (/read|\\bcat\\b|open|view|get.*file|load/.test(tn))\n return { kind: 'read_file', importance: 2, label }\n if (/search|grep|find|glob|query/.test(tn)) return { kind: 'searched', importance: 2, label }\n if (\n /http|\\bapi\\b|fetch|request|webhook|rest|graphql|endpoint/.test(tn) ||\n str(asObj(span.args)?.url)\n ) {\n return { kind: 'called_api', importance: 3, label }\n }\n if (/shell|exec|bash|\\brun\\b|terminal|command|process/.test(tn))\n return { kind: 'ran_command', importance: 3, label }\n return { kind: 'called_tool', importance: 3, label }\n }\n return { kind: 'called_tool', importance: 2, label: span.name }\n}\n\nconst KIND_VERB: Record<SemanticKind, string> = {\n understood_task: 'Understood the task',\n user_message: 'User said',\n agent_reply: 'Agent replied',\n reasoned: 'Reasoned',\n ran_command: 'Ran a command',\n read_file: 'Read files',\n edited_code: 'Edited code',\n searched: 'Searched',\n used_browser: 'Used the browser',\n used_computer: 'Controlled the computer',\n called_api: 'Called an API',\n called_tool: 'Used a tool',\n evaluated: 'Evaluated the result',\n observed_failure: 'Hit a failure',\n completed: 'Finished',\n}\n\n/** Kinds that must never collapse into a neighbour — each is its own beat:\n * a failure, and every conversation turn (so the dialogue reads in full). */\nconst STANDALONE_KINDS = new Set<SemanticKind>([\n 'observed_failure',\n 'understood_task',\n 'user_message',\n 'agent_reply',\n])\n\n/** Lift the conversation turns out of an LLM span. The user/assistant text\n * lives in `LlmSpan.messages` (role:'user'|'assistant') and the new reply in\n * `output`; the full history repeats across spans, so `seen` dedupes turns to\n * the first time each is said. The first user turn becomes `understood_task`\n * (the premise), later user turns `user_message`, assistant text `agent_reply`. */\nfunction conversationEvents(\n span: Span,\n seen: Set<string>,\n state: { sawUser: boolean },\n): SemanticEvent[] {\n if (span.kind !== 'llm') return []\n const out: SemanticEvent[] = []\n const emit = (kind: SemanticKind, text: string, importance: 1 | 2 | 3 | 4 | 5) => {\n const t = text.trim()\n if (!t) return\n const who = kind === 'agent_reply' ? 'a' : 'u'\n const key = `${who}\\n${t}`\n if (seen.has(key)) return\n seen.add(key)\n const speaker = kind === 'understood_task' ? 'Task' : kind === 'user_message' ? 'User' : 'Agent'\n out.push({\n kind,\n title: `${speaker}: ${truncate(t, 64)}`,\n summary: truncate(t, 280),\n visual: { type: 'prose', text: truncate(t, 1200) },\n evidenceSpanIds: [span.spanId],\n importance,\n startTs: span.startedAt,\n endTs: span.endedAt ?? span.startedAt,\n })\n }\n for (const m of span.messages ?? []) {\n const content = str(m.content)\n if (!content) continue\n if (m.role === 'user') {\n emit(state.sawUser ? 'user_message' : 'understood_task', content, state.sawUser ? 4 : 5)\n state.sawUser = true\n } else if (m.role === 'assistant') {\n emit('agent_reply', content, 3)\n }\n }\n const reply = str(span.output)\n if (reply) emit('agent_reply', reply, 3)\n return out\n}\n\n/**\n * Reduce a span tree into the meaningful moments a viewer cares about. The\n * conversation (user asks, agent replies) is lifted from LLM spans first so the\n * dialogue is first-class; the remaining work spans are classified + have their\n * modality visual extracted. Adjacent same-kind work moments collapse (the\n * compression step), carrying the latest visual; failures and conversation\n * turns never collapse.\n */\nexport function reduceToSemanticEvents(\n spans: readonly Span[],\n opts: ReduceOptions = {},\n): SemanticEvent[] {\n const collapse = opts.collapseAdjacent ?? true\n const ordered = [...spans].sort((a, b) => a.startedAt - b.startedAt)\n const seen = new Set<string>()\n const convState = { sawUser: false }\n const raw: SemanticEvent[] = []\n for (const s of ordered) {\n const conv = conversationEvents(s, seen, convState)\n if (conv.length > 0) {\n // this LLM span IS dialogue — surface the turns, not a generic \"reasoned\"\n raw.push(...conv)\n continue\n }\n const c = classify(s)\n raw.push({\n kind: c.kind,\n title: c.label,\n summary: `${KIND_VERB[c.kind]} — ${c.label}`,\n visual: extractVisual(s),\n evidenceSpanIds: [s.spanId],\n importance: c.importance,\n startTs: s.startedAt,\n endTs: s.endedAt ?? s.startedAt,\n })\n }\n if (!collapse) return raw\n\n const merged: SemanticEvent[] = []\n for (const ev of raw) {\n const prev = merged[merged.length - 1]\n if (prev && prev.kind === ev.kind && !STANDALONE_KINDS.has(ev.kind)) {\n prev.evidenceSpanIds.push(...ev.evidenceSpanIds)\n prev.endTs = Math.max(prev.endTs, ev.endTs)\n if (ev.visual.type !== 'none') prev.visual = ev.visual // keep the latest state\n const n = prev.evidenceSpanIds.length\n prev.title = `${KIND_VERB[ev.kind]} (${n}×)`\n prev.summary = `${KIND_VERB[ev.kind]} ${n} time${n === 1 ? '' : 's'} — latest: ${ev.title}`\n } else {\n merged.push({ ...ev, evidenceSpanIds: [...ev.evidenceSpanIds] })\n }\n }\n return merged\n}\n\n// ── Storyboard ────────────────────────────────────────────────────────────\n\nexport type SceneType =\n | 'title_card'\n | 'prompt'\n | 'reply'\n | 'reasoning'\n | 'terminal'\n | 'file'\n | 'diff'\n | 'search'\n | 'browser'\n | 'computer'\n | 'api'\n | 'tool'\n | 'eval'\n | 'error'\n | 'summary'\n\nexport interface Scene {\n sceneType: SceneType\n title: string\n narration: string\n /** The modality payload the renderer shows. */\n visual: SceneVisual\n durationMs: number\n evidenceSpanIds: string[]\n}\n\nexport interface Storyboard {\n title: string\n totalMs: number\n scenes: Scene[]\n}\n\nexport interface CompileOptions {\n /** Headline for the title card. Default \"Agent run\". */\n title?: string\n /** Max action scenes between the title + summary cards. Default 16. */\n maxScenes?: number\n}\n\nconst KIND_TO_SCENE: Record<SemanticKind, SceneType> = {\n understood_task: 'title_card',\n user_message: 'prompt',\n agent_reply: 'reply',\n reasoned: 'reasoning',\n ran_command: 'terminal',\n read_file: 'file',\n edited_code: 'diff',\n searched: 'search',\n used_browser: 'browser',\n used_computer: 'computer',\n called_api: 'api',\n called_tool: 'tool',\n evaluated: 'eval',\n observed_failure: 'error',\n completed: 'summary',\n}\n\nconst DURATION_BY_IMPORTANCE: Record<1 | 2 | 3 | 4 | 5, number> = {\n 1: 2500,\n 2: 3000,\n 3: 4000,\n 4: 5000,\n 5: 6000,\n}\n\n/**\n * Select the moments worth showing and lay them out as scenes. Every failure\n * (importance 5) and edit (4) is always kept; the rest fill the budget by\n * importance, then re-sort chronological. A title card opens, a summary closes.\n */\nexport function compileStoryboard(\n events: readonly SemanticEvent[],\n opts: CompileOptions = {},\n): Storyboard {\n const title = opts.title ?? 'Agent run'\n const maxScenes = opts.maxScenes ?? 16\n\n // The first user turn is the premise — it frames the title card rather than\n // being shown twice, so it's excluded from the action selection below.\n const taskEvent = events.find((e) => e.kind === 'understood_task')\n\n const indexed = events.filter((ev) => ev.kind !== 'understood_task').map((ev, i) => ({ ev, i }))\n const mustKeep = indexed.filter(({ ev }) => ev.importance >= 4)\n const rest = indexed\n .filter(({ ev }) => ev.importance < 4)\n .sort((a, b) => b.ev.importance - a.ev.importance || a.i - b.i)\n const budget = Math.max(0, maxScenes - mustKeep.length)\n const selected = [...mustKeep, ...rest.slice(0, budget)].sort((a, b) => a.i - b.i)\n\n const actionScenes: Scene[] = selected.map(({ ev }) => ({\n sceneType: KIND_TO_SCENE[ev.kind],\n title: ev.title,\n narration: ev.summary,\n visual: ev.visual,\n durationMs: DURATION_BY_IMPORTANCE[ev.importance],\n evidenceSpanIds: ev.evidenceSpanIds,\n }))\n\n const failures = events.filter((e) => e.kind === 'observed_failure').length\n const edits = events.filter((e) => e.kind === 'edited_code').length\n const commands = events.filter((e) => e.kind === 'ran_command').length\n const summaryNarration =\n `${events.length} moments · ${commands} command${commands === 1 ? '' : 's'} · ` +\n `${edits} edit${edits === 1 ? '' : 's'} · ${failures} failure${failures === 1 ? '' : 's'}`\n\n const scenes: Scene[] = [\n {\n sceneType: 'title_card',\n title,\n narration: taskEvent ? taskEvent.summary : 'The agent receives its task.',\n visual: taskEvent ? taskEvent.visual : { type: 'none' },\n durationMs: 3000,\n evidenceSpanIds: taskEvent ? taskEvent.evidenceSpanIds : [],\n },\n ...actionScenes,\n {\n sceneType: 'summary',\n title: failures > 0 ? 'Finished — with failures' : 'Finished',\n narration: summaryNarration,\n visual: { type: 'none' },\n durationMs: 4000,\n evidenceSpanIds: [],\n },\n ]\n return { title, totalMs: scenes.reduce((s, sc) => s + sc.durationMs, 0), scenes }\n}\n\n// ── Renderers (pure string out) ─────────────────────────────────────────────\n\nconst SCENE_ICON: Record<SceneType, string> = {\n title_card: '🎬',\n prompt: '💬',\n reply: '🤖',\n reasoning: '🧠',\n terminal: '⌨️',\n file: '📄',\n diff: '✏️',\n search: '🔎',\n browser: '🌐',\n computer: '🖥️',\n api: '🔌',\n tool: '🔧',\n eval: '⚖️',\n error: '❌',\n summary: '🏁',\n}\n\nfunction mmss(ms: number): string {\n const s = Math.round(ms / 1000)\n return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`\n}\n\nfunction truncate(s: string, max: number): string {\n return s.length <= max ? s : `${s.slice(0, Math.max(0, max - 1))}…`\n}\n\nfunction escapeHtml(s: string): string {\n return s\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n}\n\n/** A short modality tag for the markdown shot list. */\nfunction visualMarkdown(v: SceneVisual): string {\n switch (v.type) {\n case 'screenshot':\n return `🖼 screenshot (${truncate(v.src, 60)})`\n case 'browser':\n return `🌐 ${v.action ?? 'browser'}${v.url ? ` → ${v.url}` : ''}${v.screenshot ? ' [screenshot]' : ''}`\n case 'diff':\n return `\\n\\n\\`\\`\\`diff\\n${truncate(v.patch, 600)}\\n\\`\\`\\`${v.path ? `\\n_${v.path}_` : ''}`\n case 'code':\n return `\\n\\n\\`\\`\\`\\n${truncate(v.content, 500)}\\n\\`\\`\\`${v.path ? `\\n_${v.path}_` : ''}`\n case 'terminal':\n return `\\n\\n\\`\\`\\`sh\\n$ ${v.command}${v.output ? `\\n${truncate(v.output, 500)}` : ''}\\n\\`\\`\\``\n case 'api':\n return `🔌 ${v.method ?? 'CALL'} ${v.url}${v.status != null ? ` → ${v.status}` : ''}`\n case 'prose':\n return `\\n\\n> ${truncate(v.text, 400).replace(/\\n/g, '\\n> ')}`\n default:\n return ''\n }\n}\n\n/** Build the (escaped, structured) HTML for a scene's visual. We never inject\n * raw agent markup — every text part is escaped; only image `src` (data/http)\n * is passed through as an attribute. */\nfunction visualHtml(v: SceneVisual): string {\n switch (v.type) {\n case 'screenshot':\n return `<img class=\"shot\" src=\"${escapeHtml(v.src)}\" alt=\"screenshot\" loading=\"lazy\"/>`\n case 'browser': {\n const bar = `<div class=\"urlbar\">${escapeHtml(v.url ?? v.action ?? 'browser')}</div>`\n const body = isImageSrc(v.screenshot)\n ? `<img class=\"shot\" src=\"${escapeHtml(v.screenshot)}\" alt=\"page\" loading=\"lazy\"/>`\n : `<div class=\"browser-action\">${escapeHtml(v.action ?? 'navigated')}</div>`\n return `<div class=\"browser\">${bar}${body}</div>`\n }\n case 'diff': {\n const lines = v.patch.split('\\n').map((l) => {\n const cls = l.startsWith('+') ? 'add' : l.startsWith('-') ? 'del' : ''\n return `<span class=\"${cls}\">${escapeHtml(l)}</span>`\n })\n return `${v.path ? `<div class=\"pathhdr\">${escapeHtml(v.path)}</div>` : ''}<pre class=\"diff\">${lines.join('\\n')}</pre>`\n }\n case 'code':\n return `${v.path ? `<div class=\"pathhdr\">${escapeHtml(v.path)}</div>` : ''}<pre class=\"code\">${escapeHtml(v.content)}</pre>`\n case 'terminal':\n return `<pre class=\"term\"><span class=\"cmd\">$ ${escapeHtml(v.command)}</span>${v.output ? `\\n${escapeHtml(v.output)}` : ''}</pre>`\n case 'api': {\n const badge = `<span class=\"method\">${escapeHtml(v.method ?? 'CALL')}</span> <span class=\"url\">${escapeHtml(v.url)}</span>${v.status != null ? ` <span class=\"status s${Math.floor(v.status / 100)}\">${v.status}</span>` : ''}`\n const req = v.request\n ? `<div class=\"kv\"><b>req</b><pre>${escapeHtml(v.request)}</pre></div>`\n : ''\n const res = v.response\n ? `<div class=\"kv\"><b>res</b><pre>${escapeHtml(v.response)}</pre></div>`\n : ''\n return `<div class=\"api\"><div class=\"apihdr\">${badge}</div>${req}${res}</div>`\n }\n case 'prose':\n return `<div class=\"prose\">${escapeHtml(v.text)}</div>`\n default:\n return ''\n }\n}\n\n/** Render the storyboard as a Markdown timeline — the human-readable shot list. */\nexport function renderStoryboardMarkdown(storyboard: Storyboard): string {\n const out: string[] = [\n `# 🎬 ${storyboard.title}`,\n '',\n `_${storyboard.scenes.length} scenes · ${mmss(storyboard.totalMs)} replay_`,\n '',\n ]\n let elapsed = 0\n for (const sc of storyboard.scenes) {\n out.push(`### [${mmss(elapsed)}] ${SCENE_ICON[sc.sceneType]} ${sc.title}`)\n out.push('')\n out.push(sc.narration)\n const vm = visualMarkdown(sc.visual)\n if (vm) out.push(vm)\n if (sc.evidenceSpanIds.length > 0) {\n out.push('')\n out.push(`_evidence: ${sc.evidenceSpanIds.length} span(s)_`)\n }\n out.push('')\n elapsed += sc.durationMs\n }\n return out.join('\\n')\n}\n\nexport interface HtmlRenderOptions {\n /** Document title + on-page heading. Defaults to the storyboard title. */\n title?: string\n}\n\n/**\n * Render the storyboard as a self-contained, auto-playing HTML replay — one\n * shareable file, no build step, no external assets. Each scene animates in\n * for its duration and SHOWS its modality (screenshot / diff / terminal / API\n * / browser / prose); controls let a viewer scrub. This is the \"free clip\" a\n * run produces; an MP4 is the same storyboard fed to Remotion in a consumer.\n */\nexport function renderStoryboardHtml(storyboard: Storyboard, opts: HtmlRenderOptions = {}): string {\n const docTitle = opts.title ?? storyboard.title\n // Pre-render each scene's visual to safe HTML here (testable, escaped); the\n // player just sets innerHTML. `<` is escaped in the JSON so a payload can't\n // break out of the <script> tag.\n const scenesJson = JSON.stringify(\n storyboard.scenes.map((s) => ({\n icon: SCENE_ICON[s.sceneType],\n type: s.sceneType,\n title: s.title,\n narration: s.narration,\n durationMs: s.durationMs,\n evidence: s.evidenceSpanIds.length,\n visual: visualHtml(s.visual),\n })),\n ).replace(/</g, '\\\\u003c')\n\n return `<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\" />\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n<title>${escapeHtml(docTitle)}</title>\n<style>\n :root { color-scheme: dark; }\n * { box-sizing: border-box; }\n body { margin: 0; font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, sans-serif;\n background: #0b0f17; color: #e6edf3; display: flex; min-height: 100vh; align-items: center; justify-content: center; }\n .stage { width: min(900px, 95vw); }\n h1 { font-size: 1.1rem; font-weight: 600; color: #9aa7b5; margin: 0 0 14px; letter-spacing: .02em; }\n .card { background: #111824; border: 1px solid #1e2a3a; border-radius: 14px; padding: 24px 28px;\n min-height: 300px; box-shadow: 0 12px 40px rgba(0,0,0,.45); position: relative; overflow: hidden; }\n .card::before { content: \"\"; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--accent, #3b82f6); }\n .head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }\n .icon { font-size: 2rem; line-height: 1; }\n .title { font-size: 1.3rem; font-weight: 650; }\n .narration { color: #9fb0c0; font-size: .95rem; margin-bottom: 14px; }\n .visual { margin-top: 6px; }\n .visual img.shot { max-width: 100%; max-height: 360px; border-radius: 8px; border: 1px solid #1e2a3a; display: block; }\n .visual pre { background: #0a0e15; border: 1px solid #1e2a3a; border-radius: 8px; padding: 12px 14px;\n overflow: auto; max-height: 340px; font: 13px/1.5 ui-monospace, \"SF Mono\", Menlo, monospace; white-space: pre-wrap; word-break: break-word; }\n .pathhdr { font: 12px ui-monospace, monospace; color: #7d8da0; margin-bottom: 4px; }\n .diff .add { color: #56d364; } .diff .del { color: #f85149; }\n .term .cmd { color: #eab308; }\n .browser { border: 1px solid #1e2a3a; border-radius: 8px; overflow: hidden; }\n .urlbar { background: #0a0e15; padding: 7px 12px; font: 12px ui-monospace, monospace; color: #8b98a6; border-bottom: 1px solid #1e2a3a; }\n .browser-action { padding: 28px; color: #9fb0c0; text-align: center; }\n .api .apihdr { font: 13px ui-monospace, monospace; margin-bottom: 8px; }\n .method { background: #1b2636; padding: 2px 8px; border-radius: 5px; color: #79c0ff; }\n .status.s2 { color: #56d364; } .status.s4, .status.s5 { color: #f85149; }\n .kv { margin-top: 6px; } .kv b { color: #7d8da0; font-weight: 600; font-size: 12px; }\n .prose { color: #c9d4e0; font-size: 1rem; white-space: pre-wrap; max-height: 340px; overflow: auto; }\n .type-error { --accent: #ef4444; } .type-diff { --accent: #22c55e; } .type-terminal { --accent: #eab308; }\n .type-browser { --accent: #06b6d4; } .type-computer { --accent: #14b8a6; } .type-api { --accent: #79c0ff; }\n .type-summary { --accent: #a855f7; } .type-title_card { --accent: #3b82f6; }\n .type-prompt { --accent: #f59e0b; } .type-reply { --accent: #10b981; }\n .scene-enter { animation: pop .45s cubic-bezier(.2,.7,.3,1.2); }\n @keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }\n .bar { height: 4px; background: #1e2a3a; border-radius: 4px; margin-top: 14px; overflow: hidden; }\n .bar > i { display: block; height: 100%; width: 0; background: var(--accent, #3b82f6); transition: width .1s linear; }\n .controls { display: flex; gap: 10px; align-items: center; margin-top: 14px; color: #8b98a6; font-size: .85rem; }\n button { background: #1b2636; color: #e6edf3; border: 1px solid #2a3a4f; border-radius: 8px; padding: 6px 12px; cursor: pointer; font: inherit; }\n button:hover { background: #243349; }\n .dots { display: flex; gap: 5px; margin-left: auto; flex-wrap: wrap; }\n .dot { width: 7px; height: 7px; border-radius: 50%; background: #2a3a4f; cursor: pointer; }\n .dot.on { background: var(--accent, #3b82f6); }\n</style>\n</head>\n<body>\n<div class=\"stage\">\n <h1>🎬 ${escapeHtml(docTitle)}</h1>\n <div class=\"card\" id=\"card\">\n <div class=\"head\"><span class=\"icon\" id=\"icon\"></span><span class=\"title\" id=\"title\"></span></div>\n <div class=\"narration\" id=\"narration\"></div>\n <div class=\"visual\" id=\"visual\"></div>\n <div class=\"bar\"><i id=\"fill\"></i></div>\n </div>\n <div class=\"controls\">\n <button id=\"playPause\">⏸ Pause</button>\n <button id=\"prev\">◀ Prev</button>\n <button id=\"next\">Next ▶</button>\n <span id=\"counter\"></span>\n <span class=\"dots\" id=\"dots\"></span>\n </div>\n</div>\n<script>\n const SCENES = ${scenesJson};\n let i = 0, playing = true, raf = 0, start = 0;\n const card = document.getElementById('card'), counter = document.getElementById('counter'), dotsEl = document.getElementById('dots');\n SCENES.forEach((_, k) => { const d = document.createElement('span'); d.className = 'dot'; d.onclick = () => go(k); dotsEl.appendChild(d); });\n function paint() {\n const s = SCENES[i];\n card.className = 'card scene-enter type-' + s.type;\n document.getElementById('icon').textContent = s.icon;\n document.getElementById('title').textContent = s.title;\n document.getElementById('narration').textContent = s.narration;\n document.getElementById('visual').innerHTML = s.visual || '';\n counter.textContent = (i + 1) + ' / ' + SCENES.length;\n [...dotsEl.children].forEach((d, k) => d.className = 'dot' + (k === i ? ' on' : ''));\n void card.offsetWidth;\n }\n function tick(t) {\n if (!start) start = t;\n const s = SCENES[i], p = Math.min(1, (t - start) / s.durationMs);\n document.getElementById('fill').style.width = (p * 100) + '%';\n if (p >= 1) { if (i < SCENES.length - 1) { go(i + 1); } else { playing = false; updateBtn(); return; } }\n if (playing) raf = requestAnimationFrame(tick);\n }\n function go(n) { i = Math.max(0, Math.min(SCENES.length - 1, n)); start = 0; cancelAnimationFrame(raf); paint(); if (playing) raf = requestAnimationFrame(tick); }\n function updateBtn() { document.getElementById('playPause').textContent = playing ? '⏸ Pause' : '▶ Play'; }\n document.getElementById('playPause').onclick = () => { playing = !playing; updateBtn(); start = 0; if (playing) raf = requestAnimationFrame(tick); else cancelAnimationFrame(raf); };\n document.getElementById('next').onclick = () => go(i + 1);\n document.getElementById('prev').onclick = () => go(i - 1);\n paint(); raf = requestAnimationFrame(tick);\n</script>\n</body>\n</html>\n`\n}\n\n// The \"watch the agent write code\" keystroke animation + the CodeEdit IR a\n// Remotion consumer reads. Composes with this pipeline: a 'diff' scene shows an\n// inline card here; renderCodeAnimationHtml types the whole file out there.\nexport * from './code-edit'\n"],"mappings":";;;AAmBA,IAAM,aACJ;AAmBF,SAAS,WAAW,MAAkC;AACpD,QAAM,MAAM,KAAK,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI,GAAG,YAAY,IAAI;AACxE,MAAI,CAAC,IAAK,QAAO;AACjB,QAAM,MAA8B;AAAA,IAClC,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,KAAK;AAAA,IAC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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAgDlB,WAAW,QAAQ,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAgBZ,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgC7B;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-eval",
3
- "version": "0.75.0",
3
+ "version": "0.77.0",
4
4
  "description": "Substrate for self-improving agents: traces, verifiable rewards, preferences, GEPA / reflective mutation, auto-research, replay, sequential anytime-valid stats, and release gates.",
5
5
  "homepage": "https://github.com/tangle-network/agent-eval#readme",
6
6
  "repository": {
@@ -114,6 +114,11 @@
114
114
  "import": "./dist/storyboard/index.js",
115
115
  "default": "./dist/storyboard/index.js"
116
116
  },
117
+ "./authenticity": {
118
+ "types": "./dist/authenticity/index.d.ts",
119
+ "import": "./dist/authenticity/index.js",
120
+ "default": "./dist/authenticity/index.js"
121
+ },
117
122
  "./workflow": {
118
123
  "types": "./dist/workflow/index.d.ts",
119
124
  "import": "./dist/workflow/index.js",