@sedum-dev/reporters 0.1.0-alpha.11 → 0.1.0-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { RunResult, ResultStep, ResultTest } from '@sedum-dev/core';
1
+ import { RunResult, ResultStep, ResultTest, ExploreRunResult } from '@sedum-dev/core';
2
2
 
3
3
  interface HtmlReportOptions {
4
4
  /** Captured replay JPEGs, keyed by the relative path recorded in RunResult. */
@@ -136,9 +136,36 @@ interface JunitReportOptions {
136
136
  declare function isEvidenceDirectory(value: string): boolean;
137
137
  declare function renderJunit(input: RunResult, options: JunitReportOptions): string;
138
138
 
139
+ /**
140
+ * `report.md` of `sedum explore`, for a person or a coding agent: the
141
+ * verdict, then every finding with its evidence and a way to reproduce it,
142
+ * then what the walk covered, changed and cost. It sits in the run
143
+ * directory, so `frames/…` and test paths resolve from it as written.
144
+ * Page and browser text is fenced and labelled untrusted.
145
+ */
146
+ interface ExploreMarkdownOptions {
147
+ /** How to invoke sedum in commands, e.g. `npx sedum`. Default `sedum`. */
148
+ readonly command?: string;
149
+ }
150
+ declare function renderExploreMarkdown(result: ExploreRunResult, options?: ExploreMarkdownOptions): string;
151
+
152
+ /**
153
+ * `report.html` of `sedum explore`: one offline file. Findings come first,
154
+ * each with its frame and the test `--shrink` wrote; then a step viewer
155
+ * over the run's frames (with `--replay`), what the walk changed on the
156
+ * server, what it covered and what Jev cost. Page text is escaped.
157
+ */
158
+ interface ExploreHtmlOptions {
159
+ /** Frame bytes by their path in the run directory (`frames/…`). */
160
+ readonly frames?: ReadonlyMap<string, Uint8Array>;
161
+ /** How to invoke sedum in commands, e.g. `npx sedum`. Default `sedum`. */
162
+ readonly command?: string;
163
+ }
164
+ declare function renderExploreHtml(result: ExploreRunResult, options?: ExploreHtmlOptions): string;
165
+
139
166
  /** Reporter implementations will consume the single core result contract. */
140
167
  type ReportInput = RunResult;
141
168
  /** The JSON reporter serializes the canonical result without reinterpreting it. */
142
169
  declare function renderJson(result: RunResult): string;
143
170
 
144
- export { type HtmlReportOptions, type JunitReportOptions, type MarkdownReportOptions, type ReportInput, type Reporter, type ReporterContext, type ReporterEvent, ReporterLifecycle, type TerminalReporterName, type TestStatus, createTerminalReporter, isEvidenceDirectory, needsAttention, renderHtml, renderJson, renderJunit, renderMarkdown, rerunArgs, runIsTrustworthy, score, stepText, testLabel, testOrder, testStatus, testStatusLabel, usageLines, visionSummary };
171
+ export { type ExploreHtmlOptions, type ExploreMarkdownOptions, type HtmlReportOptions, type JunitReportOptions, type MarkdownReportOptions, type ReportInput, type Reporter, type ReporterContext, type ReporterEvent, ReporterLifecycle, type TerminalReporterName, type TestStatus, createTerminalReporter, isEvidenceDirectory, needsAttention, renderExploreHtml, renderExploreMarkdown, renderHtml, renderJson, renderJunit, renderMarkdown, rerunArgs, runIsTrustworthy, score, stepText, testLabel, testOrder, testStatus, testStatusLabel, usageLines, visionSummary };
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ function visionSummary(step) {
18
18
  step.calls.filter((c) => c.modality === "vision").map((c) => c.model)
19
19
  )
20
20
  ];
21
- return `Vision fallback: ${vision.outcome ?? (vision.failure ? "failed" : "outcome unrecorded")} \xB7 ${models.join(", ") || "model unrecorded"} \xB7 ${Math.round(vision.elapsedMs)} ms` + (vision.reason ? ` \xB7 trigger: ${vision.reason}` : "") + (vision.abstentionReason ? ` \xB7 abstention: ${vision.abstentionReason}` : "") + (vision.failure ? ` \xB7 ${vision.failure}` : "") + (vision.httpStatus ? ` \xB7 HTTP ${vision.httpStatus}` : "");
21
+ return `Vision fallback: ${vision.outcome ?? (vision.failure ? "failed" : "outcome unrecorded")} \xB7 ${models.join(", ") || "model unrecorded"} \xB7 ${Math.round(vision.elapsedMs)} ms` + (vision.reason ? ` \xB7 trigger: ${vision.reason}` : "") + (vision.abstentionReason ? ` \xB7 abstention: ${vision.abstentionReason}` : "") + (vision.failure ? ` \xB7 ${vision.failure}` : "");
22
22
  }
23
23
  function usageLines(result) {
24
24
  const steps = result.tests.flatMap((t) => t.attempts.flatMap((a) => a.steps));
@@ -79,6 +79,17 @@ function stepStatus(step) {
79
79
  if (step.flags.length) return "passed, flagged";
80
80
  return step.verdict ?? "measured";
81
81
  }
82
+ function detectionTexts(step) {
83
+ return (step.detections ?? []).map(
84
+ (detection) => `suspected bug: ${detection.check}${evidence(detection)}: ${detection.message}`
85
+ );
86
+ }
87
+ function evidence(detection) {
88
+ if (!detection.source) return "";
89
+ const probability = detection.probability === void 0 ? "" : ` p=${detection.probability.toFixed(2)}`;
90
+ const severity = detection.severity === void 0 ? "" : `, severity ${detection.severity.toFixed(1)}/3`;
91
+ return ` (${detection.source}${probability}${severity})`;
92
+ }
82
93
  function needsAttention(step) {
83
94
  return step.verdict === "failed" || step.state === "error" || step.state === "interrupted" || step.flags.length > 0;
84
95
  }
@@ -318,6 +329,17 @@ function bar(step) {
318
329
  const note = step.kind === "measure" ? "observation, no decision line" : !lines ? "decision lines unavailable" : "fails below " + score(lines.fail) + "; passes at " + score(lines.pass);
319
330
  return '<span class="pwrap" title="' + esc("holds " + shown + "; " + note) + '"><span class="ptrack"><span class="pfill ' + tone + '" style="width:' + width.toFixed(1) + '%"></span>' + ticks + '</span><span class="pnum">' + shown + "</span></span>";
320
331
  }
332
+ function observationsHtml(step) {
333
+ if (!step.observations.length) return "";
334
+ return "<div><b>observations</b> " + step.observations.map(
335
+ (o) => esc(
336
+ "#" + o.ordinal + " " + o.outcome + (o.reason ? " (" + o.reason + ")" : "") + (o.timeoutReason ? " timeout: " + o.timeoutReason : "")
337
+ )
338
+ ).join(" \xB7 ") + "</div>";
339
+ }
340
+ function detectionsHtml(step) {
341
+ return detectionTexts(step).map((text) => '<div class="error">' + esc(text) + "</div>").join("");
342
+ }
321
343
  function stepDetails(step) {
322
344
  const judgement = step.judgement;
323
345
  const locator = step.locator;
@@ -331,14 +353,10 @@ function stepDetails(step) {
331
353
  option.label + (option.role ? " [" + option.role + "]" : "") + " " + score(option.probability)
332
354
  )
333
355
  ).join(" \xB7 ") : "none recorded") + "</div>" : "";
334
- const observations = step.observations.length ? "<div><b>observations</b> " + step.observations.map(
335
- (o) => esc(
336
- "#" + o.ordinal + " " + o.outcome + (o.reason ? " (" + o.reason + ")" : "") + (o.timeoutReason ? " timeout: " + o.timeoutReason : "")
337
- )
338
- ).join(" \xB7 ") + "</div>" : "";
356
+ const observations = observationsHtml(step);
339
357
  const error = step.error ? '<div class="error"><b>' + esc(step.error.code) + "</b> " + esc(step.error.message) + (step.error.callLog?.length ? "<pre>" + esc(step.error.callLog.join("\n")) + "</pre>" : "") + "</div>" : "";
340
- const evidence = "<div><b>evidence</b> " + esc(step.evidence.status) + (step.evidence.status === "captured" ? " \xB7 " + esc(step.evidence.path) : " \xB7 " + esc(step.evidence.reason)) + " \xB7 <b>replay</b> " + esc(step.replayFrame?.status ?? "not requested") + "</div>";
341
- return '<div class="step-detail"><div><b>source</b> ' + esc(sourceStack(step.sourceStack)) + " \xB7 " + esc(step.phase) + " \xB7 " + duration(step.elapsedMs) + "</div>" + page + scores + choices + (visionSummary(step) ? "<div><b>vision</b> " + esc(visionSummary(step)) + "</div>" : "") + observations + error + evidence + "</div>";
358
+ const evidence2 = "<div><b>evidence</b> " + esc(step.evidence.status) + (step.evidence.status === "captured" ? " \xB7 " + esc(step.evidence.path) : " \xB7 " + esc(step.evidence.reason)) + " \xB7 <b>replay</b> " + esc(step.replayFrame?.status ?? "not requested") + "</div>";
359
+ return '<div class="step-detail"><div><b>source</b> ' + esc(sourceStack(step.sourceStack)) + " \xB7 " + esc(step.phase) + " \xB7 " + duration(step.elapsedMs) + "</div>" + page + detectionsHtml(step) + scores + choices + (visionSummary(step) ? "<div><b>vision</b> " + esc(visionSummary(step)) + "</div>" : "") + observations + error + evidence2 + "</div>";
342
360
  }
343
361
  function stepRow(step, attemptId) {
344
362
  const tone = step.verdict === "failed" ? "failed" : step.flags.length ? "marginal" : "ok";
@@ -570,13 +588,13 @@ var ReporterLifecycle = class {
570
588
 
571
589
  // src/terminal.ts
572
590
  import path from "path";
573
- function label(state, verdict) {
574
- return verdict === "passed" ? "PASSED" : verdict === "failed" ? "FAILED" : state.toUpperCase();
591
+ function label(state, verdict2) {
592
+ return verdict2 === "passed" ? "PASSED" : verdict2 === "failed" ? "FAILED" : state.toUpperCase();
575
593
  }
576
- function coloredLabel(state, verdict, context) {
577
- const text = label(state, verdict);
594
+ function coloredLabel(state, verdict2, context) {
595
+ const text = label(state, verdict2);
578
596
  if (!context.stdoutIsTTY || !context.color) return text;
579
- const color = verdict === "passed" ? 32 : verdict === "failed" || state === "error" ? 31 : 36;
597
+ const color = verdict2 === "passed" ? 32 : verdict2 === "failed" || state === "error" ? 31 : 36;
580
598
  return `\x1B[${color}m${text}\x1B[0m`;
581
599
  }
582
600
  function flags(value) {
@@ -585,10 +603,13 @@ function flags(value) {
585
603
  function source(stack) {
586
604
  return stack.map((item) => `${item.file}:${item.line}`).join(" <- ");
587
605
  }
606
+ function findings(step) {
607
+ return detectionTexts(step).map((text) => ` ${text}`);
608
+ }
588
609
  function attention(result, context) {
589
610
  const lines = [];
590
611
  const reruns = /* @__PURE__ */ new Set();
591
- const evidence = /* @__PURE__ */ new Set();
612
+ const evidence2 = /* @__PURE__ */ new Set();
592
613
  for (const test of result.tests) {
593
614
  const attempt = selectedAttempt(test);
594
615
  if (!attempt) continue;
@@ -605,7 +626,7 @@ needs attention: ${testLabel(test)}`);
605
626
  lines.push(
606
627
  ` ${label(step.state, step.verdict)}${flags(step.flags)} ${step.phase} step ${step.index}: ${stepText(step)}`
607
628
  );
608
- lines.push(` at ${source(step.sourceStack)}`);
629
+ lines.push(` at ${source(step.sourceStack)}`, ...findings(step));
609
630
  if (step.detail) lines.push(` result ${step.detail}`);
610
631
  const linkedProblems = attempt.problems.filter(
611
632
  (problem) => problem.stepId === step.id
@@ -641,7 +662,7 @@ needs attention: ${testLabel(test)}`);
641
662
  if (step.evidence.status === "captured") {
642
663
  const framePath = context.authoritative ? path.join(path.dirname(context.resultPath), step.evidence.path) : step.evidence.path;
643
664
  lines.push(` frame ${framePath}`);
644
- if (context.authoritative) evidence.add(framePath);
665
+ if (context.authoritative) evidence2.add(framePath);
645
666
  } else
646
667
  lines.push(
647
668
  ` frame ${step.evidence.status}: ${step.evidence.reason}`
@@ -666,7 +687,7 @@ needs attention: ${testLabel(test)}`);
666
687
  } else if (context.authoritative) {
667
688
  lines.push(` read ${context.resultPath}`);
668
689
  lines.push(` read ${context.progressPath}`);
669
- for (const path2 of evidence) lines.push(` read ${path2}`);
690
+ for (const path2 of evidence2) lines.push(` read ${path2}`);
670
691
  } else lines.push(` result unavailable (intended ${context.resultPath})`);
671
692
  for (const args of reruns) lines.push(` rerun sedum run ${args}`);
672
693
  if (reruns.size === 0)
@@ -795,6 +816,20 @@ function earlierAttempts(test) {
795
816
  return `#${attempt.ordinal} ${attempt.verdict ?? attempt.state}` + (primary ? ` (${code(primary)})` : "");
796
817
  }).join(", ");
797
818
  }
819
+ function locatorLines(locator) {
820
+ if (!locator) return [];
821
+ const cache = locator.cache ? ` \xB7 cache ${locator.cache.outcome}` + (locator.cache.reason ? ` (${inline(locator.cache.reason)})` : "") + (locator.cache.targetChanged ? ", target changed" : "") : "";
822
+ const options = locator.options.length ? locator.options.map(
823
+ (option) => ` - ${inline(option.label) || "(unlabeled)"}` + (option.role ? ` (${inline(option.role)})` : "") + `: ${score(option.probability)}`
824
+ ) : [" - no candidates weighed"];
825
+ return [
826
+ `- **locator**: ${locator.source} \xB7 ${locator.vision ? "text-model " : ""}confidence ${score(locator.confidence)}${cache}`,
827
+ ...options
828
+ ];
829
+ }
830
+ function detectionBullets(step) {
831
+ return detectionTexts(step).map((text) => `- **${inline(text)}**`);
832
+ }
798
833
  function stepSection(number, test, attempt, step) {
799
834
  const out = [
800
835
  `### ${number}. ${stepStatus(step)} \xB7 ${code(testLabel(test))} \xB7 ${step.phase} step ${step.index} \xB7 ${step.kind}`,
@@ -816,19 +851,7 @@ function stepSection(number, test, attempt, step) {
816
851
  out.push(
817
852
  step.page.status === "available" ? `- **page**: ${code(step.page.url)} \u2014 "${inline(step.page.title)}"` : `- **page**: ${step.page.status} (${inline(step.page.reason)})`
818
853
  );
819
- const locator = step.locator;
820
- if (locator) {
821
- const cache = locator.cache ? ` \xB7 cache ${locator.cache.outcome}` + (locator.cache.reason ? ` (${inline(locator.cache.reason)})` : "") + (locator.cache.targetChanged ? ", target changed" : "") : "";
822
- out.push(
823
- `- **locator**: ${locator.source} \xB7 ${locator.vision ? "text-model " : ""}confidence ${score(locator.confidence)}${cache}`
824
- );
825
- if (locator.options.length)
826
- for (const option of locator.options)
827
- out.push(
828
- ` - ${inline(option.label) || "(unlabeled)"}` + (option.role ? ` (${inline(option.role)})` : "") + `: ${score(option.probability)}`
829
- );
830
- else out.push(" - no candidates weighed");
831
- }
854
+ out.push(...detectionBullets(step), ...locatorLines(step.locator));
832
855
  out.push(
833
856
  step.evidence.status === "captured" ? `- **frame**: ![step ${step.index} frame](${step.evidence.path}) ${code(step.evidence.path)}` : `- **frame**: ${step.evidence.status} (${inline(step.evidence.reason)})`
834
857
  );
@@ -909,12 +932,12 @@ function flowDetail(test) {
909
932
  `### ${testStatusLabel(test)} \xB7 ${code(test.file)}` + (test.description ? ` \u2014 ${inline(test.description)}` : ""),
910
933
  ""
911
934
  ];
912
- const facts = [
935
+ const facts2 = [
913
936
  `${steps.length} ${steps.length === 1 ? "step" : "steps"}`,
914
937
  attempt ? duration(attempt.elapsedMs) : null,
915
938
  test.tags.length ? `tags ${test.tags.map(inline).join(", ")}` : null
916
939
  ].filter(Boolean);
917
- out.push(facts.join(" \xB7 "), "");
940
+ out.push(facts2.join(" \xB7 "), "");
918
941
  const earlier = earlierAttempts(test);
919
942
  if (earlier) out.push(`Earlier attempts: ${earlier}`, "");
920
943
  if (!test.attempts.length) {
@@ -949,7 +972,7 @@ function flowDetail(test) {
949
972
  return out;
950
973
  }
951
974
  function verdictLine(result, counts2) {
952
- const verdict = result.state === "error" || result.state === "interrupted" || result.state === "running" ? result.state : counts2.failed ? "failed" : counts2.incomplete ? "incomplete" : counts2.flagged ? "passed, flagged" : "passed";
975
+ const verdict2 = result.state === "error" || result.state === "interrupted" || result.state === "running" ? result.state : counts2.failed ? "failed" : counts2.incomplete ? "incomplete" : counts2.flagged ? "passed, flagged" : "passed";
953
976
  const parts = [
954
977
  `${counts2.failed} failed`,
955
978
  `${counts2.incomplete} incomplete`,
@@ -962,7 +985,7 @@ function verdictLine(result, counts2) {
962
985
  `${result.totals.flaggedSteps} flagged steps`,
963
986
  duration(result.elapsedMs)
964
987
  ].filter(Boolean);
965
- return `**${verdict}** \u2014 ${parts.join(" \xB7 ")} (${extra.join(", ")})`;
988
+ return `**${verdict2}** \u2014 ${parts.join(" \xB7 ")} (${extra.join(", ")})`;
966
989
  }
967
990
  function renderMarkdownBody(input) {
968
991
  const result = validateRunResult3(input);
@@ -1191,14 +1214,17 @@ function renderSuite(suite) {
1191
1214
  ` + properties(suite.properties) + suite.cases.map(renderCase).join("") + " </testsuite>\n";
1192
1215
  }
1193
1216
  function flagCounts(result) {
1194
- const total = { low_confidence: 0, contradiction: 0 };
1217
+ const total = { low_confidence: 0, contradiction: 0, suspected_bug: 0 };
1195
1218
  for (const test of result.tests)
1196
1219
  for (const step of selectedAttempt(test)?.steps ?? [])
1197
1220
  for (const flag of step.flags) total[flag] += 1;
1198
1221
  return total;
1199
1222
  }
1223
+ function suspectedSummary(count) {
1224
+ return count ? `, suspected_bug ${count}` : "";
1225
+ }
1200
1226
  function flagSummary(counted) {
1201
- return `low_confidence ${counted.low_confidence}, contradiction ${counted.contradiction}`;
1227
+ return `low_confidence ${counted.low_confidence}, contradiction ${counted.contradiction}${suspectedSummary(counted.suspected_bug)}`;
1202
1228
  }
1203
1229
  function frameLine(frame, evidenceDirectory) {
1204
1230
  if (frame.status !== "captured")
@@ -1220,6 +1246,7 @@ function stepLines(attempt, step, evidenceDirectory) {
1220
1246
  ` contradiction ${score(judgement.contradicted, [judgement.contradictionCutoff])} / cutoff ${score(judgement.contradictionCutoff)}`
1221
1247
  );
1222
1248
  }
1249
+ out.push(...detectionTexts(step).map((text) => ` ${oneLine(text)}`));
1223
1250
  out.push(
1224
1251
  step.page.status === "available" ? ` page: ${step.page.url} "${oneLine(step.page.title)}"` : ` page: ${step.page.status} (${step.page.reason})`
1225
1252
  );
@@ -1310,7 +1337,7 @@ function testSuite(test, result, options) {
1310
1337
  );
1311
1338
  const output = [];
1312
1339
  if (test.flags.length && attempt) {
1313
- const stepFlags = { low_confidence: 0, contradiction: 0 };
1340
+ const stepFlags = { low_confidence: 0, contradiction: 0, suspected_bug: 0 };
1314
1341
  for (const step of attempt.steps)
1315
1342
  for (const flag of step.flags) stepFlags[flag] += 1;
1316
1343
  output.push(
@@ -1465,6 +1492,297 @@ function renderJunit(input, options) {
1465
1492
  return command === "sedum" ? body : body.replaceAll("rerun: sedum run ", `rerun: ${command} run `);
1466
1493
  }
1467
1494
 
1495
+ // src/explore-markdown.ts
1496
+ function money2(usd) {
1497
+ return usd === null ? "unknown" : `$${usd.toFixed(4)}`;
1498
+ }
1499
+ function verdict(result) {
1500
+ const n = result.findings.length;
1501
+ const head = n ? `**${n} finding${n === 1 ? "" : "s"}**` : "**No findings**";
1502
+ const stop = result.stopReason ? ` Stopped early: ${inline(result.stopReason)}` : "";
1503
+ return `${head} in ${result.steps.taken} of ${result.steps.requested} steps on ${code(result.startUrl)}.${stop}`;
1504
+ }
1505
+ function summaryTable(result) {
1506
+ const rows = [
1507
+ ["Seed", String(result.seed)],
1508
+ ["Mode", result.mode],
1509
+ ["Safety", result.safety],
1510
+ [
1511
+ "Checks",
1512
+ result.detect === "semantic" ? "browser + page checks" : "browser"
1513
+ ],
1514
+ ["Duration", `${(result.durationMs / 1e3).toFixed(1)} s`],
1515
+ ["States", String(result.coverage.states)],
1516
+ ["Kinds of page", String(result.coverage.routes.length)],
1517
+ ["Server writes", String(result.writes.reduce((n, w) => n + w.count, 0))],
1518
+ ["Jev", `${result.jev.calls} calls, ${money2(result.jev.costUsd)}`]
1519
+ ];
1520
+ return ["| | |", "| --- | --- |", ...rows.map(([k, v]) => `| ${k} | ${v} |`)];
1521
+ }
1522
+ function frameLink(frame) {
1523
+ return frame ? [`- Frame: [${inline(frame)}](${frame})`] : [];
1524
+ }
1525
+ function testLines(finding, result, command) {
1526
+ const test = finding.test;
1527
+ const at = (file) => `${result.artifacts.directory}/${file}`;
1528
+ const rerun = `${command} explore --rerun ${at(result.artifacts.trace)}`;
1529
+ if (!test) return [`- Reproduce the whole walk: ${code(rerun)}`];
1530
+ if ("notShrunk" in test)
1531
+ return [
1532
+ `- Not shrunk: ${inline(test.notShrunk)}`,
1533
+ `- Reproduce the whole walk: ${code(rerun)}`
1534
+ ];
1535
+ return [
1536
+ `- Test: [${inline(test.path)}](${test.path}), shrunk from ${test.actionsBefore} to ${test.actionsAfter} actions; ${test.sentences.matched} of ${test.sentences.located} sentences matched the recorded element; ${test.reproduced ? "the sentences reproduce the failure" : "the sentences did **not** reproduce the failure"}.`,
1537
+ `- Run it with the error flagged: ${code(`${command} run ${at(test.path)} --detect browser`)}`,
1538
+ "",
1539
+ "```yaml",
1540
+ test.yaml.replace(/\s+$/u, ""),
1541
+ "```"
1542
+ ];
1543
+ }
1544
+ function findingSection(finding, result, command) {
1545
+ return [
1546
+ `### ${finding.id} \xB7 ${finding.kind} at step ${finding.step}`,
1547
+ "",
1548
+ `- Signature: ${code(finding.signature)}`,
1549
+ `- Page: ${code(finding.route)}`,
1550
+ ...frameLink(finding.frame),
1551
+ ...testLines(finding, result, command),
1552
+ "",
1553
+ "**What the browser or page said** (untrusted)",
1554
+ "",
1555
+ fence(finding.message),
1556
+ ""
1557
+ ];
1558
+ }
1559
+ function coverageLines(result) {
1560
+ const kinds = Object.entries(result.coverage.pageKinds).sort((a, b) => b[1] - a[1]).map(([kind, n]) => `${kind} ${n}`).join(", ");
1561
+ return [
1562
+ "## Coverage",
1563
+ "",
1564
+ `${result.coverage.states} distinct states.${kinds ? ` Page kinds: ${kinds}.` : ""}`,
1565
+ "",
1566
+ "| Page | Steps |",
1567
+ "| --- | --- |",
1568
+ ...result.coverage.routes.slice(0, 30).map((r) => `| ${code(r.route, true)} | ${r.visits} |`),
1569
+ ""
1570
+ ];
1571
+ }
1572
+ function writeLines(result) {
1573
+ if (!result.writes.length)
1574
+ return ["## What the walk changed", "", "No server writes observed.", ""];
1575
+ return [
1576
+ "## What the walk changed",
1577
+ "",
1578
+ "Successful requests that may change data (not reads, beacons or failures).",
1579
+ "",
1580
+ "| Request | Count | First step |",
1581
+ "| --- | --- | --- |",
1582
+ ...result.writes.map(
1583
+ (w) => `| ${code(w.endpoint, true)} | ${w.count} | ${w.firstStep} |`
1584
+ ),
1585
+ ""
1586
+ ];
1587
+ }
1588
+ function receiptLines(result) {
1589
+ const { jev } = result;
1590
+ const latency = jev.latencyMs ? `, p50 ${jev.latencyMs.p50} ms, p95 ${jev.latencyMs.p95} ms` : "";
1591
+ return [
1592
+ "## Jev",
1593
+ "",
1594
+ `${jev.calls} calls, ${jev.inputTokens} input tokens, ${money2(jev.costUsd)}${latency}.`,
1595
+ ...jev.errors.length ? ["", "Failed calls (untrusted):", "", fence(jev.errors.join("\n"))] : [],
1596
+ ""
1597
+ ];
1598
+ }
1599
+ function renderExploreMarkdown(result, options = {}) {
1600
+ const command = options.command ?? "sedum";
1601
+ const skipped = result.skipped.length ? [
1602
+ "## Not clicked",
1603
+ "",
1604
+ result.safety === "off" ? "Safety was off; these would have ended the session:" : `Safety was ${result.safety}; skipped as destructive or session-ending:`,
1605
+ "",
1606
+ ...result.skipped.map((name) => `- ${inline(name)}`),
1607
+ ""
1608
+ ] : [];
1609
+ return `${[
1610
+ `# Exploration of ${inline(result.startUrl)}`,
1611
+ "",
1612
+ verdict(result),
1613
+ "",
1614
+ ...summaryTable(result),
1615
+ "",
1616
+ "## Findings",
1617
+ "",
1618
+ ...result.findings.length ? result.findings.flatMap((f) => findingSection(f, result, command)) : ["None.", ""],
1619
+ ...writeLines(result),
1620
+ ...coverageLines(result),
1621
+ ...skipped,
1622
+ ...receiptLines(result)
1623
+ ].join("\n")}
1624
+ `;
1625
+ }
1626
+
1627
+ // src/explore-html.ts
1628
+ var STYLE = `
1629
+ :root{--bg:#F6F4ED;--card:#FBFAF5;--ink:#1A2420;--soft:#57655C;--rule:#D9D4C5;--green:#1D5B3E;--red:#C24328;--wash:#E8EEE7;
1630
+ --serif:"Fraunces",Georgia,serif;--sans:"Inter",Helvetica,Arial,sans-serif;--mono:"IBM Plex Mono",ui-monospace,monospace}
1631
+ @media (prefers-color-scheme:dark){:root{--bg:#141A17;--card:#1B231F;--ink:#E7E4DA;--soft:#9AA79F;--rule:#34403A;--green:#7BC59C;--red:#F08A6E;--wash:#22302A}}
1632
+ *{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.5 var(--sans)}
1633
+ main{max-width:1180px;margin:0 auto;padding:28px 24px 64px}
1634
+ h1,h2,h3{font-family:var(--serif);font-weight:500;margin:0}h1{font-size:34px}h2{font-size:26px;margin:40px 0 14px;border-top:3px solid var(--ink);padding-top:12px}
1635
+ h3{font-size:20px}code,pre,.mono{font-family:var(--mono);font-size:13.5px}
1636
+ pre{background:var(--card);border:1px solid var(--rule);padding:10px 12px;overflow:auto;white-space:pre-wrap;word-break:break-word;margin:8px 0}
1637
+ .brand{display:flex;gap:10px;align-items:center;font-family:var(--serif);font-size:20px;color:var(--soft)}
1638
+ .verdict{display:inline-block;margin:10px 0 4px;padding:4px 12px;font-weight:600;border:1.5px solid var(--green);color:var(--green)}
1639
+ .verdict.bad{border-color:var(--red);color:var(--red)}
1640
+ .facts{display:grid;grid-template-columns:repeat(auto-fit,minmax(118px,1fr));gap:8px;margin-top:14px}
1641
+ .fact{background:var(--card);border:1px solid var(--rule);padding:8px 10px}.fact b{display:block;font-size:18px}.fact span{color:var(--soft);font-size:13px}
1642
+ .finding{background:var(--card);border:1px solid var(--rule);border-left:4px solid var(--red);padding:14px 16px;margin:14px 0}
1643
+ .finding .head{display:flex;gap:10px;align-items:baseline;flex-wrap:wrap}.tag{font-family:var(--mono);font-weight:600;color:var(--red)}
1644
+ .chip{font-family:var(--mono);font-size:12px;border:1px solid var(--rule);padding:1px 7px;color:var(--soft)}
1645
+ .label{font-size:12px;letter-spacing:.08em;text-transform:uppercase;color:var(--soft);margin-top:10px}
1646
+ .cols{display:grid;grid-template-columns:1.1fr 1fr;gap:16px}@media (max-width:860px){.cols{grid-template-columns:1fr}}
1647
+ .frame{position:relative;border:1px solid var(--rule);background:#fff}.frame img{display:block;width:100%}
1648
+ .box{position:absolute;border:3px solid var(--red);box-shadow:0 0 0 2px #fff}
1649
+ table{border-collapse:collapse;width:100%;font-size:14px}th,td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--rule);vertical-align:top}
1650
+ th{font-weight:600;color:var(--soft);font-size:12px;text-transform:uppercase;letter-spacing:.06em}
1651
+ tr.hit td{background:var(--wash)}tr.ev td:first-child{border-left:3px solid var(--red)}
1652
+ .bar{height:10px;background:var(--green)}
1653
+ .viewer{background:var(--card);border:1px solid var(--rule);padding:12px}.controls{display:flex;gap:10px;align-items:center;margin:10px 0}
1654
+ .controls input{flex:1}button{font:inherit;padding:4px 12px;border:1px solid var(--rule);background:var(--bg);color:var(--ink);cursor:pointer}
1655
+ .events{color:var(--red);font-family:var(--mono);font-size:13px}.soft{color:var(--soft)}a{color:var(--green)}
1656
+ `;
1657
+ function json2(value) {
1658
+ return JSON.stringify(value).replace(
1659
+ /[<>&\u2028\u2029]/g,
1660
+ (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`
1661
+ );
1662
+ }
1663
+ function money3(usd) {
1664
+ return usd === null ? "unknown" : `$${usd.toFixed(4)}`;
1665
+ }
1666
+ function dataUrl(frames, path2) {
1667
+ const bytes = path2 ? frames?.get(path2) : void 0;
1668
+ return bytes ? `data:image/jpeg;base64,${Buffer.from(bytes).toString("base64")}` : null;
1669
+ }
1670
+ function frameFigure(finding, frames) {
1671
+ const src = dataUrl(frames, finding.frame);
1672
+ if (!src)
1673
+ return `<p class="soft">No frame: run with <code>--replay</code> to capture them.</p>`;
1674
+ return `<div class="frame"><img alt="The page at step ${finding.step}" src="${src}"></div>`;
1675
+ }
1676
+ function testBlock(finding, artifacts, command) {
1677
+ const test = finding.test;
1678
+ const at = (file) => `${artifacts.directory}/${file}`;
1679
+ const rerun = `${command} explore --rerun ${at(artifacts.trace)}`;
1680
+ if (!test || "notShrunk" in test)
1681
+ return `${test ? `<p class="soft">Not shrunk: ${esc(test.notShrunk)}</p>` : ""}<div class="label">Reproduce the whole walk</div><pre>${esc(rerun)}</pre>`;
1682
+ return `<div class="label">Plain-English test \xB7 ${test.actionsBefore} \u2192 ${test.actionsAfter} actions \xB7 ${test.reproduced ? "reproduces" : "does not reproduce"} the failure</div>
1683
+ <pre>${esc(test.yaml)}</pre><div class="label">Run it with the error flagged</div><pre>${esc(`${command} run ${at(test.path)} --detect browser`)}</pre>`;
1684
+ }
1685
+ function findingCard(finding, result, options) {
1686
+ return `<section class="finding" id="finding-${esc(finding.id)}">
1687
+ <div class="head"><span class="tag">${esc(finding.id)}</span><h3>${esc(finding.signature)}</h3></div>
1688
+ <div class="soft"><span class="chip">${esc(finding.kind)}</span> step <a href="#step-${finding.step}" data-step="${finding.step}">${finding.step}</a> on <code>${esc(finding.route)}</code></div>
1689
+ <div class="cols"><div><div class="label">What the browser or page said (untrusted)</div><pre>${esc(finding.message)}</pre>
1690
+ ${testBlock(finding, result.artifacts, options.command ?? "sedum")}</div><div>${frameFigure(finding, options.frames)}</div></div></section>`;
1691
+ }
1692
+ function facts(result) {
1693
+ const writes2 = result.writes.reduce((n, w) => n + w.count, 0);
1694
+ const items = [
1695
+ [`${result.steps.taken} / ${result.steps.requested}`, "steps"],
1696
+ [String(result.coverage.states), "states"],
1697
+ [String(result.coverage.routes.length), "kinds of page"],
1698
+ [String(writes2), "server writes"],
1699
+ [`${(result.durationMs / 1e3).toFixed(1)} s`, "duration"],
1700
+ [money3(result.jev.costUsd), `Jev, ${result.jev.calls} calls`],
1701
+ [result.safety, "safety"],
1702
+ [String(result.seed), `seed \xB7 ${result.mode}`]
1703
+ ];
1704
+ return `<div class="facts">${items.map(([v, k]) => `<div class="fact"><b>${esc(v)}</b><span>${esc(k)}</span></div>`).join("")}</div>`;
1705
+ }
1706
+ function viewer(result, frames) {
1707
+ const shots = result.timeline.flatMap((s) => {
1708
+ const src = dataUrl(frames, s.frames?.before) ?? dataUrl(frames, s.frames?.after);
1709
+ if (!src) return [];
1710
+ const box = s.frames?.before ? s.frames.box : void 0;
1711
+ return [
1712
+ {
1713
+ step: s.step,
1714
+ src,
1715
+ box,
1716
+ action: s.action,
1717
+ route: s.route,
1718
+ events: s.signatures
1719
+ }
1720
+ ];
1721
+ });
1722
+ if (!shots.length)
1723
+ return `<p class="soft">This run captured no frames. Run with <code>--replay</code> to step through it here.</p>`;
1724
+ return `<div class="viewer" id="viewer"><div class="frame"><img id="v-img" alt=""><div class="box" id="v-box" hidden></div></div>
1725
+ <div class="controls"><button id="v-prev" type="button">\u25C0</button><input id="v-range" type="range" min="0" max="${shots.length - 1}" value="0" aria-label="Step"><button id="v-next" type="button">\u25B6</button></div>
1726
+ <div><b id="v-step"></b> <span id="v-action"></span> <span class="soft" id="v-route"></span></div><div class="events" id="v-events"></div></div>
1727
+ <script type="application/json" id="v-data">${json2(shots)}</script>
1728
+ <script>(() => {
1729
+ const shots = JSON.parse(document.getElementById("v-data").textContent);
1730
+ const $ = (id) => document.getElementById(id);
1731
+ let at = 0;
1732
+ const show = (i) => { at = Math.max(0, Math.min(shots.length - 1, i)); const s = shots[at];
1733
+ $("v-img").src = s.src; $("v-range").value = at; $("v-step").textContent = "Step " + s.step;
1734
+ $("v-action").textContent = s.action; $("v-route").textContent = s.route; $("v-events").textContent = s.events.join(" \xB7 ");
1735
+ const box = $("v-box"); box.hidden = !s.box;
1736
+ if (s.box) Object.assign(box.style, { left: s.box.x * 100 + "%", top: s.box.y * 100 + "%", width: s.box.width * 100 + "%", height: s.box.height * 100 + "%" }); };
1737
+ $("v-prev").onclick = () => show(at - 1); $("v-next").onclick = () => show(at + 1);
1738
+ $("v-range").oninput = (e) => show(Number(e.target.value));
1739
+ document.addEventListener("keydown", (e) => { if (e.key === "ArrowLeft") show(at - 1); if (e.key === "ArrowRight") show(at + 1); });
1740
+ document.querySelectorAll("[data-step]").forEach((a) => a.addEventListener("click", () => { const i = shots.findIndex((s) => s.step === Number(a.dataset.step)); if (i >= 0) show(i); }));
1741
+ show(0); })();</script>`;
1742
+ }
1743
+ function stepRows(result) {
1744
+ return result.timeline.map(
1745
+ (s) => `<tr id="step-${s.step}" class="${s.signatures.length ? "ev" : ""}"><td class="mono"><a href="#viewer" data-step="${s.step}">${s.step}</a></td><td><code>${esc(s.route)}</code>${s.pageKind ? ` <span class="chip">${esc(s.pageKind)}</span>` : ""}</td><td>${esc(s.action)}${s.planned ? ' <span class="chip">plan</span>' : ""}${s.outcome === "acted" ? "" : ` <span class="soft">(${esc(s.outcome)})</span>`}</td><td class="events">${esc(s.signatures.join(" \xB7 "))}${s.writes.length ? `<div class="soft">${esc(s.writes.join(", "))}</div>` : ""}</td></tr>`
1746
+ ).join("");
1747
+ }
1748
+ function coverage(result) {
1749
+ const kinds = Object.entries(result.coverage.pageKinds).sort(
1750
+ (a, b) => b[1] - a[1]
1751
+ );
1752
+ const max = Math.max(1, ...kinds.map(([, n]) => n));
1753
+ return `<div class="cols"><table><tr><th>Page kind</th><th>Visits</th><th></th></tr>${kinds.map(([k, n]) => `<tr><td>${esc(k)}</td><td>${n}</td><td style="width:50%"><div class="bar" style="width:${100 * n / max}%"></div></td></tr>`).join("")}</table>
1754
+ <table><tr><th>Page</th><th>Steps</th></tr>${result.coverage.routes.slice(0, 30).map(
1755
+ (r) => `<tr><td><code>${esc(r.route)}</code></td><td>${r.visits}</td></tr>`
1756
+ ).join("")}</table></div>`;
1757
+ }
1758
+ function writes(result) {
1759
+ if (!result.writes.length) return `<p>No server writes observed.</p>`;
1760
+ return `<p class="soft">Successful requests that may change data: not reads, beacons or failures.</p><table><tr><th>Request</th><th>Count</th><th>First step</th></tr>${result.writes.map((w) => `<tr><td><code>${esc(w.endpoint)}</code></td><td>${w.count}</td><td><a href="#step-${w.firstStep}">${w.firstStep}</a></td></tr>`).join("")}</table>`;
1761
+ }
1762
+ function receipt2(result) {
1763
+ const { jev } = result;
1764
+ const latency = jev.latencyMs ? `, p50 ${jev.latencyMs.p50} ms, p95 ${jev.latencyMs.p95} ms` : "";
1765
+ return `<p>${jev.calls} calls, ${jev.inputTokens} input tokens, ${esc(money3(jev.costUsd))}${latency}.</p>${jev.errors.length ? `<div class="label">Failed calls (untrusted)</div><pre>${esc(jev.errors.join("\n"))}</pre>` : ""}`;
1766
+ }
1767
+ function renderExploreHtml(result, options = {}) {
1768
+ const n = result.findings.length;
1769
+ const skipped = result.skipped.length ? `<h2>Not clicked</h2><p class="soft">${result.safety === "off" ? "Safety was off; these would have ended the session." : `Safety was ${esc(result.safety)}: destructive or session-ending.`}</p><p>${result.skipped.map((s) => `<span class="chip">${esc(s)}</span>`).join(" ")}</p>` : "";
1770
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
1771
+ <title>Exploration of ${esc(result.startUrl)}</title><style>${REPORT_FONTS}${STYLE}</style></head><body><main>
1772
+ <div class="brand">sedum explore <span class="chip">experimental</span></div>
1773
+ <h1>Exploration of <code>${esc(result.startUrl)}</code></h1>
1774
+ <div class="verdict ${n ? "bad" : ""}">${n ? `${n} finding${n === 1 ? "" : "s"}` : "No findings"}</div>${result.stopReason ? `<p class="soft">Stopped early: ${esc(result.stopReason)}</p>` : ""}
1775
+ ${facts(result)}
1776
+ <h2>Findings</h2>${n ? result.findings.map((f) => findingCard(f, result, options)).join("") : "<p>None.</p>"}
1777
+ <h2>Steps</h2>${viewer(result, options.frames)}
1778
+ <table><tr><th>Step</th><th>Page</th><th>Action</th><th>Findings and writes</th></tr>${stepRows(result)}</table>
1779
+ <h2>What the walk changed</h2>${writes(result)}
1780
+ <h2>Coverage</h2>${coverage(result)}${skipped}
1781
+ <h2>Jev</h2>${receipt2(result)}
1782
+ </main></body></html>
1783
+ `;
1784
+ }
1785
+
1468
1786
  // src/index.ts
1469
1787
  function renderJson(result) {
1470
1788
  return `${JSON.stringify(validateRunResult5(result), null, 2)}
@@ -1475,6 +1793,8 @@ export {
1475
1793
  createTerminalReporter,
1476
1794
  isEvidenceDirectory,
1477
1795
  needsAttention,
1796
+ renderExploreHtml,
1797
+ renderExploreMarkdown,
1478
1798
  renderHtml,
1479
1799
  renderJson,
1480
1800
  renderJunit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sedum-dev/reporters",
3
- "version": "0.1.0-alpha.11",
3
+ "version": "0.1.0-alpha.17",
4
4
  "repository": "https://github.com/sedum-dev/sedum",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -20,7 +20,7 @@
20
20
  "assets"
21
21
  ],
22
22
  "dependencies": {
23
- "@sedum-dev/core": "0.1.0-alpha.11"
23
+ "@sedum-dev/core": "0.1.0-alpha.17"
24
24
  },
25
25
  "scripts": {
26
26
  "build": "tsup src/index.ts --format esm --dts --clean --out-dir dist",