literally-aeo 0.4.2 → 0.4.4

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.
Files changed (143) hide show
  1. package/README.md +21 -1
  2. package/dist/cli.mjs +1528 -551
  3. package/dist/lib/agents/methodology.js +9 -9
  4. package/dist/lib/bundle/contracts.js +1 -1
  5. package/dist/lib/bundle/export.js +18 -18
  6. package/dist/lib/bundle/journal.js +2 -2
  7. package/dist/lib/bundle/project-journal.js +5 -5
  8. package/dist/lib/bundle/project.js +16 -16
  9. package/dist/lib/bundle/read.js +19 -19
  10. package/dist/lib/bundle/recorder.js +3 -3
  11. package/dist/lib/bundle/redact.js +2 -2
  12. package/dist/lib/bundle/trace-coverage.js +2 -2
  13. package/dist/lib/bundle/verify-integrity.js +4 -4
  14. package/dist/lib/bundle/verify-measurement.js +2 -2
  15. package/dist/lib/bundle/verify-report.js +3 -3
  16. package/dist/lib/bundle/verify.js +8 -8
  17. package/dist/lib/checks/run-checks.js +4 -4
  18. package/dist/lib/chunks/{chunk-U4AROC2Z.js → chunk-22QIMTQJ.js} +1 -1
  19. package/dist/lib/chunks/{chunk-KFYTORIT.js → chunk-2IZ2LTBQ.js} +4 -4
  20. package/dist/lib/chunks/{chunk-22SP35NA.js → chunk-2S2NKIK2.js} +1 -1
  21. package/dist/lib/chunks/{chunk-3USKGGFT.js → chunk-2WBJER62.js} +15 -5
  22. package/dist/lib/chunks/{chunk-DU3MAXVC.js → chunk-3RSF2PY4.js} +6 -1
  23. package/dist/lib/chunks/{chunk-ITLJZUKL.js → chunk-4M6CQKSH.js} +1 -1
  24. package/dist/lib/chunks/{chunk-RR63UE5H.js → chunk-4SPKLFJK.js} +4 -4
  25. package/dist/lib/chunks/{chunk-5EM6J7TG.js → chunk-4VURIRL7.js} +2 -2
  26. package/dist/lib/chunks/{chunk-T4Z3GAEH.js → chunk-5EE3IOLY.js} +1 -1
  27. package/dist/lib/chunks/{chunk-ATKP5ZW6.js → chunk-5YXU5WAK.js} +1 -1
  28. package/dist/lib/chunks/{chunk-RWVXK7XE.js → chunk-6OV2GIKK.js} +5 -5
  29. package/dist/lib/chunks/{chunk-XT5M3PPQ.js → chunk-6ZZ4MHYW.js} +3 -3
  30. package/dist/lib/chunks/{chunk-T5Q5CBTA.js → chunk-AC5YND5N.js} +1 -1
  31. package/dist/lib/chunks/{chunk-NZOKSFIA.js → chunk-ALORJCG4.js} +3 -3
  32. package/dist/lib/chunks/{chunk-OF3WIGG7.js → chunk-AQVARUFR.js} +6 -6
  33. package/dist/lib/chunks/{chunk-BKAERR7J.js → chunk-AR2LGUP4.js} +2 -2
  34. package/dist/lib/chunks/{chunk-EZ23TKTX.js → chunk-ATYDD4EM.js} +2 -2
  35. package/dist/lib/chunks/{chunk-ENPRRXH5.js → chunk-BC53CVOM.js} +1 -1
  36. package/dist/lib/chunks/chunk-BWBPEXEU.js +83 -0
  37. package/dist/lib/chunks/chunk-C34NR35E.js +472 -0
  38. package/dist/lib/chunks/{chunk-32LZRJ3P.js → chunk-CYTHCMYY.js} +2 -2
  39. package/dist/lib/chunks/{chunk-WIRVKAYB.js → chunk-DH7D4KNR.js} +12 -12
  40. package/dist/lib/chunks/{chunk-QJX6YXXQ.js → chunk-DOV622W3.js} +3 -3
  41. package/dist/lib/chunks/{chunk-DI4LZR37.js → chunk-EI6P2B4R.js} +3 -3
  42. package/dist/lib/chunks/{chunk-CRXJFOCK.js → chunk-FX4Y7GVR.js} +4 -4
  43. package/dist/lib/chunks/{chunk-R2HFGAOO.js → chunk-GKLCM5K2.js} +2 -2
  44. package/dist/lib/chunks/{chunk-BWI4M36B.js → chunk-GTQORFWR.js} +4 -4
  45. package/dist/lib/chunks/{chunk-HJEIEMPE.js → chunk-GV47I7MF.js} +4 -4
  46. package/dist/lib/chunks/{chunk-M4XGUJMO.js → chunk-GVDOWLYF.js} +1 -1
  47. package/dist/lib/chunks/{chunk-JGBJQ3TO.js → chunk-GZRG3QSS.js} +1 -1
  48. package/dist/lib/chunks/{chunk-JKBXKACC.js → chunk-J66AN3MF.js} +7 -7
  49. package/dist/lib/chunks/{chunk-YRXYTCMY.js → chunk-JHUI2K5X.js} +1 -1
  50. package/dist/lib/chunks/{chunk-3DVFQMJT.js → chunk-JMWS4PZR.js} +8 -3
  51. package/dist/lib/chunks/chunk-JQFLWUCA.js +123 -0
  52. package/dist/lib/chunks/{chunk-FXCUGNFL.js → chunk-JXQOWHWB.js} +1 -1
  53. package/dist/lib/chunks/{chunk-STNUFF7H.js → chunk-K6MHEUSS.js} +2 -2
  54. package/dist/lib/chunks/{chunk-CMB2KSW2.js → chunk-KNX75J6T.js} +16 -7
  55. package/dist/lib/chunks/{chunk-6P7EZJI7.js → chunk-KSJ3NZIJ.js} +4 -2
  56. package/dist/lib/chunks/{chunk-FBMO6UV4.js → chunk-L5FM3KGF.js} +1 -1
  57. package/dist/lib/chunks/{chunk-7QYZSP7Q.js → chunk-LQIBRJWR.js} +4 -0
  58. package/dist/lib/chunks/{chunk-A2RW4ZMR.js → chunk-MI4GIMHK.js} +1 -1
  59. package/dist/lib/chunks/{chunk-YPGJN232.js → chunk-MKA2EP7M.js} +1 -1
  60. package/dist/lib/chunks/{chunk-NWABYXDQ.js → chunk-NAFSRHVZ.js} +2 -2
  61. package/dist/lib/chunks/{chunk-JN4332MJ.js → chunk-OSELZPPA.js} +1 -1
  62. package/dist/lib/chunks/{chunk-TD47AB37.js → chunk-OXNS5JNZ.js} +2 -2
  63. package/dist/lib/chunks/{chunk-KC35BXW7.js → chunk-R5VAHYBF.js} +1 -1
  64. package/dist/lib/chunks/{chunk-Q6TZB2OQ.js → chunk-RF2V6XQ3.js} +1 -1
  65. package/dist/lib/chunks/{chunk-AMK6IHJD.js → chunk-SVVA7MIE.js} +1 -1
  66. package/dist/lib/chunks/{chunk-RYV25YGT.js → chunk-V4VBRJEK.js} +1 -1
  67. package/dist/lib/chunks/chunk-VFN2J4Z3.js +626 -0
  68. package/dist/lib/chunks/{chunk-AMF3T5A3.js → chunk-WQXXNDBO.js} +1 -1
  69. package/dist/lib/chunks/{chunk-VOK4TUXV.js → chunk-WZ5A77WN.js} +1 -1
  70. package/dist/lib/chunks/{chunk-DKR7LSP2.js → chunk-YGW3HTTH.js} +1 -1
  71. package/dist/lib/chunks/{chunk-FFDMGNRO.js → chunk-YHHWIOO5.js} +6 -6
  72. package/dist/lib/cli/bundle-commands.js +64 -39
  73. package/dist/lib/cli/guide-command.js +1 -1
  74. package/dist/lib/cli/run-commands.js +43 -43
  75. package/dist/lib/cli/status-command.js +25 -25
  76. package/dist/lib/codex-workflow/aggregate.js +2 -2
  77. package/dist/lib/codex-workflow/author.js +3 -3
  78. package/dist/lib/codex-workflow/capture.js +12 -12
  79. package/dist/lib/codex-workflow/copy-editor.js +3 -3
  80. package/dist/lib/codex-workflow/copy.js +2 -2
  81. package/dist/lib/codex-workflow/finish.js +11 -11
  82. package/dist/lib/codex-workflow/loop.js +19 -19
  83. package/dist/lib/codex-workflow/run-source.js +5 -5
  84. package/dist/lib/codex-workflow/stage.js +5 -5
  85. package/dist/lib/engine/audit-file.js +9 -9
  86. package/dist/lib/engine/author.js +16 -16
  87. package/dist/lib/engine/cost-estimate.js +9 -9
  88. package/dist/lib/engine/local-run.js +24 -24
  89. package/dist/lib/engine/preflight.js +10 -10
  90. package/dist/lib/engine/rejudge.js +31 -31
  91. package/dist/lib/engine/resources.js +1 -1
  92. package/dist/lib/engine/run-bindings.js +9 -9
  93. package/dist/lib/engine/run-method.js +2 -2
  94. package/dist/lib/engine/run-models.js +4 -4
  95. package/dist/lib/engine/run-status.js +25 -25
  96. package/dist/lib/engine/templates.js +10 -10
  97. package/dist/lib/grounding/grounding-runtime.js +5 -5
  98. package/dist/lib/grounding/recorded-tools.js +4 -4
  99. package/dist/lib/pipeline.js +11 -11
  100. package/dist/lib/probes/adapters/cli-agents.js +6 -6
  101. package/dist/lib/probes/adapters/cli-claude-code.js +3 -3
  102. package/dist/lib/probes/adapters/cli-codex.js +3 -3
  103. package/dist/lib/probes/adapters/cli-cursor.js +3 -3
  104. package/dist/lib/probes/adapters/cli-process.js +2 -2
  105. package/dist/lib/probes/agent-clis.js +7 -7
  106. package/dist/lib/probes/bindings.js +8 -8
  107. package/dist/lib/probes/charged-trace.js +9 -9
  108. package/dist/lib/probes/child-process.js +1 -1
  109. package/dist/lib/probes/probes.js +9 -9
  110. package/dist/lib/viewer/alternatives.js +8 -0
  111. package/dist/lib/viewer/cited-domains.js +8 -0
  112. package/dist/lib/viewer/page.js +3 -1
  113. package/dist/lib/viewer/presentation.js +41 -0
  114. package/dist/lib/viewer/server.js +15 -10
  115. package/dist/types/bundle/contracts.d.ts +1 -1
  116. package/dist/types/engine/resources.d.ts +2 -0
  117. package/dist/types/engine/templates.d.ts +1 -1
  118. package/dist/types/viewer/alternatives.d.ts +16 -0
  119. package/dist/types/viewer/cited-domains.d.ts +22 -0
  120. package/dist/types/viewer/page.d.ts +9 -2
  121. package/dist/types/viewer/presentation.d.ts +112 -0
  122. package/dist/types/viewer/server.d.ts +7 -3
  123. package/package.json +2 -1
  124. package/resources/fonts/Mulish-OFL.txt +93 -0
  125. package/resources/fonts/Mulish-VariableFont_wght.ttf +0 -0
  126. package/resources/fonts/SourceCodePro-OFL.txt +93 -0
  127. package/resources/fonts/SourceCodePro-VariableFont_wght.ttf +0 -0
  128. package/resources/guide/OPERATOR.md +4 -1
  129. package/src/bundle/contracts.ts +1 -1
  130. package/src/cli/bundle-commands.ts +21 -0
  131. package/src/engine/guide/OPERATOR.md +4 -1
  132. package/src/engine/preflight.ts +4 -1
  133. package/src/engine/resources.ts +9 -5
  134. package/src/engine/templates.ts +5 -0
  135. package/src/probes/adapters/cli-claude-code.ts +14 -4
  136. package/src/probes/child-process.ts +4 -0
  137. package/src/report/core/rate-interval.ts +1 -2
  138. package/src/viewer/alternatives.ts +202 -0
  139. package/src/viewer/cited-domains.ts +127 -0
  140. package/src/viewer/page.ts +549 -236
  141. package/src/viewer/presentation.ts +759 -0
  142. package/src/viewer/server.ts +25 -4
  143. package/dist/lib/chunks/chunk-3TF4JGQA.js +0 -323
package/dist/cli.mjs CHANGED
@@ -2180,7 +2180,7 @@ var encodeBundleJson = (value) => {
2180
2180
 
2181
2181
  // src/bundle/contracts.ts
2182
2182
  var toolId = "literally-aeo";
2183
- var toolVersion = "0.4.2";
2183
+ var toolVersion = "0.4.4";
2184
2184
  var bundleSchemaVersion = 3;
2185
2185
  var readableBundleSchemaVersions = [1, 2, 3];
2186
2186
  var traceSchemaVersion = 1;
@@ -2394,7 +2394,8 @@ var predecessorPrefix = (revisionId) => {
2394
2394
  };
2395
2395
 
2396
2396
  // src/cli/bundle-commands.ts
2397
- import path32 from "node:path";
2397
+ import { readFile as readFile29 } from "node:fs/promises";
2398
+ import path34 from "node:path";
2398
2399
 
2399
2400
  // src/bundle/export.ts
2400
2401
  import {
@@ -3389,6 +3390,18 @@ var reportSectionTitle = (title) => {
3389
3390
  });
3390
3391
  return sectionTitle;
3391
3392
  };
3393
+ var formatReportDate = (iso) => {
3394
+ const date2 = new Date(iso);
3395
+ if (Number.isNaN(date2.getTime())) {
3396
+ return iso;
3397
+ }
3398
+ return date2.toLocaleDateString("en-GB", {
3399
+ year: "numeric",
3400
+ month: "long",
3401
+ day: "numeric",
3402
+ timeZone: "UTC"
3403
+ });
3404
+ };
3392
3405
 
3393
3406
  // src/agents/copy-schema.ts
3394
3407
  var catalogFactIdSchema = z15.string().min(1).describe(
@@ -6711,6 +6724,10 @@ var runChild = (command, args, options) => {
6711
6724
  var baseEnvKeys = [
6712
6725
  "PATH",
6713
6726
  "HOME",
6727
+ // macOS: a CLI's own login lives in the login Keychain, which Claude Code
6728
+ // looks up by account name; without these it reports "Not logged in".
6729
+ "USER",
6730
+ "LOGNAME",
6714
6731
  "TMPDIR",
6715
6732
  "LANG",
6716
6733
  "LC_ALL",
@@ -7052,7 +7069,18 @@ var claudeCodeProfile = {
7052
7069
  secret: true,
7053
7070
  group: "auth",
7054
7071
  billsAccount: "Anthropic"
7055
- }
7072
+ },
7073
+ // A bearer token for an Anthropic-compatible gateway at
7074
+ // ANTHROPIC_BASE_URL. Unlike the CLI's own login, it carries no account
7075
+ // identity: a logged-in Claude Code tells the model the account's email,
7076
+ // which tilts an audit run from the audited company's own account.
7077
+ {
7078
+ name: "ANTHROPIC_AUTH_TOKEN",
7079
+ secret: true,
7080
+ group: "auth",
7081
+ billsAccount: "gateway"
7082
+ },
7083
+ { name: "ANTHROPIC_BASE_URL", secret: false }
7056
7084
  ],
7057
7085
  pool: "claude_code",
7058
7086
  retry: "agent",
@@ -7061,7 +7089,7 @@ var claudeCodeProfile = {
7061
7089
  resolvesRedirects: false
7062
7090
  };
7063
7091
  var claudeEnvKeys = [
7064
- ...authSettingNames(claudeCodeProfile),
7092
+ ...claudeCodeProfile.settings.map((setting) => setting.name),
7065
7093
  "CLAUDE_CONFIG_DIR"
7066
7094
  ];
7067
7095
  var runClaudeCodeProbe = async (promptText, runtime, signal) => {
@@ -23428,7 +23456,9 @@ var credentialSettingNames = [
23428
23456
  var runSettingNames = [
23429
23457
  gatewaySetting,
23430
23458
  ...overviewSettings,
23431
- ...Object.values(agentAuthEnv).flatMap((auth) => auth.anyOf)
23459
+ ...Object.values(cliAdapterProfiles).flatMap(
23460
+ (profile) => profile.settings.map((setting) => setting.name)
23461
+ )
23432
23462
  ];
23433
23463
  var agentAuthDetail = (binding, auth) => {
23434
23464
  if (auth.kind === "cli_session") {
@@ -23631,68 +23661,282 @@ var runPreflight = async (args) => {
23631
23661
  return checks;
23632
23662
  };
23633
23663
 
23634
- // src/viewer/server.ts
23635
- import { randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
23636
- import {
23637
- createServer as createServer2
23638
- } from "node:http";
23639
- import { z as z63 } from "zod";
23664
+ // src/engine/resources.ts
23665
+ import { access as access2 } from "node:fs/promises";
23666
+ import path33 from "node:path";
23667
+
23668
+ // src/engine/package-root.ts
23669
+ import { readFileSync as readFileSync2 } from "node:fs";
23670
+ import path32 from "node:path";
23671
+ import { fileURLToPath } from "node:url";
23672
+ var enginePackageName = "literally-aeo";
23673
+ var isEngineManifest = (file) => {
23674
+ try {
23675
+ const manifest = JSON.parse(readFileSync2(file, "utf8"));
23676
+ return typeof manifest === "object" && manifest !== null && "name" in manifest && manifest.name === enginePackageName;
23677
+ } catch {
23678
+ return false;
23679
+ }
23680
+ };
23681
+ var enginePackageRoot = () => {
23682
+ const start = path32.dirname(fileURLToPath(import.meta.url));
23683
+ let dir = start;
23684
+ for (; ; ) {
23685
+ if (isEngineManifest(path32.join(dir, "package.json"))) {
23686
+ return dir;
23687
+ }
23688
+ const parent = path32.dirname(dir);
23689
+ if (parent === dir) {
23690
+ throw new Error(
23691
+ `No ${enginePackageName} package.json above ${start}; the engine runs from its own package.`
23692
+ );
23693
+ }
23694
+ dir = parent;
23695
+ }
23696
+ };
23697
+
23698
+ // src/engine/resources.ts
23699
+ var exists = async (file) => {
23700
+ return access2(file).then(
23701
+ () => true,
23702
+ () => false
23703
+ );
23704
+ };
23705
+ var engineResources = async () => {
23706
+ const root = enginePackageRoot();
23707
+ const packed = path33.join(root, "resources");
23708
+ if (await exists(path33.join(packed, "author", "COPY_RULES.md"))) {
23709
+ return {
23710
+ root,
23711
+ author: path33.join(packed, "author"),
23712
+ editorial: path33.join(packed, "editorial"),
23713
+ guide: path33.join(packed, "guide", "OPERATOR.md"),
23714
+ fonts: path33.join(packed, "fonts")
23715
+ };
23716
+ }
23717
+ return {
23718
+ root,
23719
+ author: path33.join(root, "src", "author"),
23720
+ editorial: path33.join(root, "src", "engine", "editorial"),
23721
+ guide: path33.join(root, "src", "engine", "guide", "OPERATOR.md"),
23722
+ fonts: path33.join(root, "src", "viewer", "fonts")
23723
+ };
23724
+ };
23640
23725
 
23641
23726
  // src/viewer/page.ts
23642
23727
  var styles = `
23643
23728
  :root {
23644
- --bg: #ffffff; --fg: #16181d; --muted: #5d6470; --line: #e3e6eb;
23645
- --panel: #f6f7f9; --accent: #3651d4; --pass: #1f7a46; --fail: #b3261e;
23646
- --warn: #8a5a00;
23729
+ --darkest: #000; --lightest: #fff; --brand-1: #ffd08a; --brand-1-light: #ffedd2;
23730
+ --neutral-1: #f1f1f1; --neutral-2: #c8c8c8; --positive: #059669;
23731
+ --positive-deep: #065f46; --mention: #8b5cf6; --mention-deep: #5b21b6;
23732
+ --negative: #ef4444; --muted: rgb(0 0 0 / 0.6); --muted-strong: rgb(0 0 0 / 0.7);
23733
+ --backdrop: rgb(0 0 0 / 0.25);
23734
+ --font-body: Mulish, system-ui, -apple-system, "Segoe UI", sans-serif;
23735
+ --font-mono: "Source Code Pro", ui-monospace, SFMono-Regular, Menlo, monospace;
23736
+ /* Light only, as the hosted report is, whatever the system theme. */
23647
23737
  color-scheme: light;
23648
23738
  }
23649
- @media (prefers-color-scheme: dark) {
23650
- :root {
23651
- --bg: #111317; --fg: #e8eaee; --muted: #9aa1ad; --line: #2a2e36;
23652
- --panel: #181b21; --accent: #8fa2ff; --pass: #5fd08f; --fail: #ff8a80;
23653
- --warn: #e5b45a;
23654
- color-scheme: dark;
23655
- }
23656
- }
23657
23739
  * { box-sizing: border-box; }
23658
- body { margin: 0; background: var(--bg); color: var(--fg);
23659
- font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
23660
- main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
23661
- h1 { font-size: 24px; margin: 0 0 4px; }
23662
- h2 { font-size: 18px; margin: 32px 0 12px; }
23663
- h3 { font-size: 15px; margin: 20px 0 8px; }
23740
+ html { -webkit-text-size-adjust: 100%; }
23741
+ body { margin: 0; background: var(--lightest); color: var(--darkest);
23742
+ font: 16px/1.5 var(--font-body); }
23743
+ p, h1, h2, h3, ul { margin: 0; }
23744
+ ul { padding: 0; list-style: none; }
23745
+ button { font: inherit; color: inherit; }
23746
+ button:not(:disabled) { cursor: pointer; }
23747
+ :focus-visible { outline: 2px solid var(--darkest); outline-offset: 2px; }
23748
+ .mono { font-family: var(--font-mono); }
23664
23749
  .muted { color: var(--muted); }
23665
- .banner { border: 1px solid var(--line); background: var(--panel);
23666
- padding: 12px 14px; border-radius: 8px; margin: 16px 0; }
23667
- .banner.warn { border-color: var(--warn); }
23668
- .grid { display: grid; gap: 12px;
23669
- grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
23670
- .stat { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
23671
- .stat b { display: block; font-size: 22px; }
23672
- .interval { display: block; color: var(--muted); font-size: 13px; }
23673
- button.tip-trigger { background: none; border: 0; padding: 0; color: inherit; font: inherit;
23674
- text-align: left; cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; }
23675
- button.tip-trigger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
23676
- .tip { display: block; color: var(--fg); }
23750
+ .container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 20px; }
23751
+ .band { background: var(--lightest); }
23752
+ .band.soft { background: var(--neutral-1); }
23753
+ .band > .container > .band-inner { padding: 60px 0; }
23754
+ .banner { background: var(--darkest); color: var(--lightest); padding: 12px 20px;
23755
+ text-align: center; font-size: 14px; }
23756
+ .eyebrow { font-family: var(--font-mono); font-size: 14px; line-height: 20px;
23757
+ font-weight: 500; text-transform: uppercase; }
23758
+ .h1 { font-size: 32px; line-height: 37px; font-weight: 900; text-wrap: balance; }
23759
+ .h2 { font-size: 28px; line-height: 34px; font-weight: 900; text-wrap: balance; }
23760
+ .h5 { font-size: 18px; line-height: 25px; font-weight: 800; }
23761
+ .body-1 { font-size: 20px; line-height: 24px; font-weight: 500; }
23762
+ .body-2 { font-size: 18px; line-height: 22px; font-weight: 500; }
23763
+ .hero { background: var(--brand-1-light); }
23764
+ .hero-grid { display: grid; gap: 40px; padding: 40px 0 60px; }
23765
+ .hero-copy { display: flex; flex-direction: column; align-items: flex-start; gap: 20px; }
23766
+ .hero-copy .body-1 { max-width: 720px; }
23767
+ .measured { font-family: var(--font-mono); font-size: 14px; font-weight: 500; color: var(--muted); }
23768
+ .measurement { border: 1px solid var(--neutral-2); border-radius: 8px; background: var(--lightest);
23769
+ padding: 20px; box-shadow: 8px 8px var(--neutral-2); }
23770
+ .measurement-figure { font-size: 50px; line-height: 56px; font-weight: 900; margin-top: 12px; }
23771
+ .facts { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
23772
+ .facts li { font-family: var(--font-mono); font-size: 14px; line-height: 20px; font-weight: 500;
23773
+ border: 1px solid var(--neutral-2); border-radius: 4px; background: var(--neutral-1); padding: 12px; }
23774
+ .header { display: grid; gap: 16px; }
23775
+ .header-title { display: flex; flex-direction: column; gap: 12px; }
23776
+ .header.center { display: flex; flex-direction: column; align-items: center; text-align: center; }
23777
+ .header.center .body-2 { max-width: 820px; }
23778
+ .scorecards { margin-top: 40px; border-radius: 16px; background: var(--brand-1-light); padding: 30px 20px; }
23779
+ .scorecards-grid { display: grid; grid-template-columns: 1fr; gap: 30px; }
23780
+ .stat { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
23781
+ .stat-figure { font-family: var(--font-mono); font-size: 40px; line-height: 36px;
23782
+ font-variant-numeric: tabular-nums; }
23783
+ .stat-label { font-size: 16px; font-weight: 700; }
23784
+ .stat-detail { font-size: 14px; color: var(--muted-strong); }
23785
+ .interval { display: block; }
23786
+ .tip-trigger { background: none; border: 0; padding: 0; margin: 0; text-align: left;
23787
+ font-size: 14px; color: var(--muted-strong); text-decoration: underline dotted;
23788
+ text-underline-offset: 4px; cursor: help; }
23789
+ .tip { display: block; margin-top: 4px; font-size: 12px; color: var(--muted-strong); }
23677
23790
  .tip[hidden] { display: none; }
23678
- table { width: 100%; border-collapse: collapse; font-size: 14px; }
23679
- th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line);
23680
- vertical-align: top; }
23681
- th { color: var(--muted); font-weight: 600; }
23682
- tr.row { cursor: pointer; }
23683
- tr.row:hover, tr.row:focus { background: var(--panel); outline: none; }
23684
- .pass { color: var(--pass); } .fail { color: var(--fail); }
23685
- .limited { color: var(--warn); }
23686
- .drawer { border: 1px solid var(--line); border-radius: 8px; padding: 14px;
23687
- margin-top: 12px; background: var(--panel); }
23688
- pre { white-space: pre-wrap; word-break: break-word; font: 13px/1.5 ui-monospace,
23689
- SFMono-Regular, Menlo, monospace; margin: 8px 0 0; }
23690
- button.link { background: none; border: 0; color: var(--accent); padding: 0;
23691
- font: inherit; cursor: pointer; text-decoration: underline; }
23692
- .table-wrap { overflow-x: auto; }
23693
- ul.methodology { padding-left: 20px; color: var(--muted); font-size: 14px; }
23694
- ul.methodology li { margin: 6px 0; }
23695
- footer { margin-top: 48px; color: var(--muted); font-size: 13px; }
23791
+ .subsection { margin-top: 40px; }
23792
+ .card { margin-top: 20px; border: 1px solid var(--neutral-2); border-radius: 8px;
23793
+ background: var(--lightest); padding: 20px; }
23794
+ .card-title { font-size: 16px; font-weight: 700; }
23795
+ .card-lead { margin-top: 4px; font-size: 14px; color: var(--muted); }
23796
+ .scroll { overflow-x: auto; }
23797
+ table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
23798
+ th { font-family: var(--font-mono); font-weight: 500; color: var(--muted); text-align: left;
23799
+ border-bottom: 1px solid var(--neutral-2); padding: 8px 12px; }
23800
+ td { border-bottom: 1px solid var(--neutral-2); padding: 10px 12px; vertical-align: top; }
23801
+ .num { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
23802
+ .rate { font-weight: 600; font-variant-numeric: tabular-nums; }
23803
+ tr.total td { border-bottom: 0; font-weight: 700; color: var(--darkest); }
23804
+ tr.selectable { cursor: pointer; }
23805
+ tr.selectable:hover { background: var(--neutral-1); }
23806
+ .row-button { background: none; border: 0; padding: 0; text-align: left; }
23807
+ .matrix-card { margin-top: 40px; padding: 16px; }
23808
+ .matrix { min-width: 640px; }
23809
+ .matrix th, .matrix td { text-align: center; padding: 8px 12px; }
23810
+ .matrix th.prompt-head, .matrix td.prompt { text-align: left; position: sticky; left: 0;
23811
+ z-index: 1; background: var(--lightest); }
23812
+ .matrix td.prompt { max-width: 280px; }
23813
+ .matrix .group { border-bottom: 0; padding-bottom: 4px; font-size: 11px; letter-spacing: 0.05em;
23814
+ text-transform: uppercase; }
23815
+ .matrix .agents-start { border-left: 1px solid var(--neutral-2); }
23816
+ .prompt-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
23817
+ overflow: hidden; font-size: 12px; line-height: 1.375; }
23818
+ .prompt-category { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.05em;
23819
+ text-transform: uppercase; color: var(--muted); }
23820
+ .cell { display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
23821
+ gap: 2px; min-width: 36px; min-height: 36px; padding: 4px 6px; border: 1px solid transparent;
23822
+ border-radius: 6px; background: none; }
23823
+ .cell:hover { border-color: var(--neutral-2); background: var(--neutral-1); }
23824
+ .cell-count { font-size: 9px; line-height: 1; color: var(--muted); font-variant-numeric: tabular-nums; }
23825
+ .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--neutral-2); }
23826
+ .dot.primary { width: 10px; height: 10px; background: var(--positive); }
23827
+ .dot.mentioned { background: var(--mention); }
23828
+ .dot.absent { background: var(--negative); opacity: 0.7; }
23829
+ .legend { display: flex; flex-wrap: wrap; gap: 4px 20px; margin-top: 12px; font-size: 11px; color: var(--muted); }
23830
+ .legend li { display: flex; align-items: center; gap: 8px; }
23831
+ .hint { margin-top: 12px; border: 1px solid var(--brand-1); border-radius: 6px;
23832
+ background: var(--brand-1-light); padding: 8px 12px; font-size: 12px; line-height: 1.625; }
23833
+ .bars { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
23834
+ .bars li { display: grid; grid-template-columns: minmax(0, 11rem) 1fr auto; align-items: center; gap: 12px; }
23835
+ .bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 500; }
23836
+ .bar-domain { margin-left: 6px; font-size: 12px; font-weight: 400; color: var(--muted); }
23837
+ .bar { height: 6px; overflow: hidden; border-radius: 999px; background: var(--neutral-1); }
23838
+ .bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--darkest); }
23839
+ .bar-value { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
23840
+ .hosts { margin-left: 8px; font-size: 12px; color: var(--muted); }
23841
+ .more { margin-top: 12px; background: none; border: 0; padding: 0; font-family: var(--font-mono);
23842
+ font-size: 12px; text-decoration: underline; text-decoration-color: var(--brand-1);
23843
+ text-decoration-thickness: 2px; text-underline-offset: 4px; }
23844
+ .label { font-family: var(--font-mono); font-size: 11px; font-weight: 500; letter-spacing: 0.14em;
23845
+ text-transform: uppercase; color: var(--muted); }
23846
+ .pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
23847
+ .pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--neutral-2);
23848
+ border-radius: 999px; background: var(--neutral-1); padding: 4px 10px; font-size: 12px; }
23849
+ .pill.plain { background: var(--lightest); }
23850
+ .pill.dashed { border-style: dashed; background: none; color: var(--muted); }
23851
+ .pill.mono { font-family: var(--font-mono); }
23852
+ .pill.pass, .pill.primary { border-color: rgb(5 150 105 / 0.3); background: rgb(5 150 105 / 0.1);
23853
+ color: var(--positive-deep); font-weight: 500; }
23854
+ .pill.mentioned { border-color: rgb(139 92 246 / 0.3); background: rgb(139 92 246 / 0.1);
23855
+ color: var(--mention-deep); font-weight: 500; }
23856
+ .pill.fail, .pill.absent { border-color: rgb(239 68 68 / 0.2); background: rgb(239 68 68 / 0.1);
23857
+ font-weight: 500; }
23858
+ .pill-count { color: var(--muted); font-variant-numeric: tabular-nums; }
23859
+ .verification td:nth-child(2) { white-space: nowrap; }
23860
+ .footer { max-width: 720px; margin: 0 auto; text-align: center; font-size: 14px;
23861
+ line-height: 1.625; color: var(--muted); }
23862
+ .footer > * + * { margin-top: 12px; }
23863
+ .footer h2 { margin-top: 24px; font-size: 14px; font-weight: 700; color: var(--muted-strong); }
23864
+ .footer ul { margin-top: 8px; padding-left: 20px; list-style: disc; text-align: left; }
23865
+ .footer ul li + li { margin-top: 4px; }
23866
+ .footer-note { margin-top: 32px; border-top: 1px solid var(--neutral-2); padding-top: 24px; }
23867
+ .sheet-backdrop { position: fixed; inset: 0; z-index: 1000; background: var(--backdrop); cursor: pointer; }
23868
+ .sheet { position: fixed; top: 0; right: 0; bottom: 0; z-index: 1001; display: flex;
23869
+ flex-direction: column; width: 100%; max-width: 560px; background: var(--lightest);
23870
+ padding: 20px; box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1); }
23871
+ .sheet[hidden], .sheet-backdrop[hidden] { display: none; }
23872
+ .sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
23873
+ .sheet-description { margin-top: 4px; font-size: 14px; color: var(--muted); }
23874
+ .sheet-close { flex-shrink: 0; border: 1px solid var(--neutral-2); border-radius: 6px;
23875
+ background: none; padding: 4px 10px; font-family: var(--font-mono); font-size: 14px; }
23876
+ .sheet-close:hover { background: var(--neutral-1); }
23877
+ .sheet-body { display: flex; flex-direction: column; gap: 20px; flex: 1; min-height: 0;
23878
+ margin-top: 20px; padding-right: 4px; overflow-y: auto; }
23879
+ .prompt-box { border: 1px solid var(--neutral-2); border-radius: 8px; background: var(--neutral-1); padding: 16px; }
23880
+ .prompt-box p { margin-top: 8px; font-size: 14px; line-height: 1.625; }
23881
+ .prompt-box p.prompt-category { font-size: 11px; letter-spacing: 0.14em; }
23882
+ .run { border: 1px solid var(--neutral-2); border-radius: 8px; background: var(--lightest); padding: 16px; }
23883
+ .run-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
23884
+ .run-head .pills { margin-top: 0; justify-content: flex-end; }
23885
+ .run-title { font-size: 14px; font-weight: 700; }
23886
+ .run-surface { font-size: 12px; color: var(--muted); }
23887
+ .run-block { margin-top: 16px; }
23888
+ .snippet { margin-top: 16px; border-radius: 6px; background: var(--neutral-1); padding: 12px; }
23889
+ .answer { margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.625; }
23890
+ .answer mark { background: var(--brand-1-light); color: inherit; border-radius: 2px;
23891
+ box-shadow: 0 0 0 1px var(--brand-1); }
23892
+ .links { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
23893
+ .source { max-width: 100%; background: none; border: 0; padding: 0; text-align: left;
23894
+ overflow-wrap: anywhere; font-size: 12px; font-weight: 500; text-decoration: underline;
23895
+ text-decoration-color: var(--brand-1); text-decoration-thickness: 2px; text-underline-offset: 4px; }
23896
+ .source:hover { text-decoration-color: var(--darkest); }
23897
+ .source-meta { margin-top: 2px; font-size: 11px; color: var(--muted); }
23898
+ .empty { border: 1px dashed var(--neutral-2); border-radius: 6px; padding: 12px; font-size: 14px; color: var(--muted); }
23899
+ @media (min-width: 480px) {
23900
+ .h1 { font-size: 40px; line-height: 50px; }
23901
+ .h2 { font-size: 32px; line-height: 38px; }
23902
+ .scorecards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
23903
+ .sheet { padding: 32px; }
23904
+ }
23905
+ @media (min-width: 768px) {
23906
+ .container { padding: 0 30px; }
23907
+ .h1 { font-size: 44px; line-height: 56px; }
23908
+ .h2 { font-size: 36px; line-height: 42px; }
23909
+ .h5 { font-size: 20px; }
23910
+ .body-1 { font-size: 22px; line-height: 28px; }
23911
+ .body-2 { font-size: 20px; line-height: 25px; }
23912
+ .hero-grid { padding-top: 80px; }
23913
+ .measurement { padding: 30px; }
23914
+ .header.split { grid-template-columns: 0.8fr 1fr; align-items: start; gap: 40px; }
23915
+ .scorecards { padding: 30px 40px; }
23916
+ .scorecards-grid { gap: 40px; }
23917
+ .matrix-card { padding: 20px; }
23918
+ }
23919
+ @media (min-width: 992px) {
23920
+ .container { padding: 0 40px; }
23921
+ .band > .container > .band-inner { padding: 100px 0; }
23922
+ .eyebrow { font-size: 16px; }
23923
+ .h2 { font-size: 42px; line-height: 50px; }
23924
+ .body-1 { font-size: 24px; line-height: 30px; }
23925
+ .hero-grid { grid-template-columns: minmax(0, 1fr) minmax(340px, 0.62fr); align-items: center;
23926
+ padding: 100px 0; }
23927
+ .measurement-figure { font-size: 72px; line-height: 78px; }
23928
+ .facts li { font-size: 16px; }
23929
+ .scorecards { padding: 40px 60px; }
23930
+ .scorecards-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
23931
+ .scorecards-grid.five { grid-template-columns: repeat(3, minmax(0, 1fr)); }
23932
+ .stat-figure { font-size: 56px; line-height: 48px; }
23933
+ }
23934
+ @media (min-width: 1280px) {
23935
+ .scorecards-grid.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
23936
+ }
23937
+ @media (prefers-reduced-motion: reduce) {
23938
+ * { scroll-behavior: auto; transition: none; }
23939
+ }
23696
23940
  `;
23697
23941
  var script = `
23698
23942
  const token = new URLSearchParams(location.search).get('t');
@@ -23708,46 +23952,31 @@ const el = (tag, attrs = {}, ...children) => {
23708
23952
  else if (key.startsWith('on')) node.addEventListener(key.slice(2), value);
23709
23953
  else node.setAttribute(key, value);
23710
23954
  }
23711
- for (const child of children) {
23712
- if (child === null || child === undefined) continue;
23955
+ for (const child of children.flat()) {
23956
+ if (child === null || child === undefined || child === false) continue;
23713
23957
  node.append(typeof child === 'string' ? document.createTextNode(child) : child);
23714
23958
  }
23715
23959
  return node;
23716
23960
  };
23717
- const percent = (value) =>
23718
- typeof value === 'number' && Number.isFinite(value) ? Math.round(value * 100) + '%' : 'n/a';
23719
- const isShare = (value) => typeof value === 'number' && value >= 0 && value <= 1;
23720
- const isCount = (value) => Number.isSafeInteger(value) && value >= 0;
23721
- // The evidence beside a rate (calculation version 2), or null when the
23722
- // bundle has none or it is malformed: a bundle is shown even when it fails
23723
- // verification, so its numbers are checked before they are displayed.
23724
- const evidenceOf = (evidence) =>
23725
- evidence && isShare(evidence.low) && isShare(evidence.high) && evidence.low <= evidence.high
23726
- && isCount(evidence.count) && isCount(evidence.captured) && isCount(evidence.planned)
23727
- ? evidence : null;
23728
- // Outward to whole percents, so the range shown always contains the computed
23729
- // interval. The bounds are stored to 6 decimals; scaling them to an integer
23730
- // first keeps a bound of 0.07 (7.000000000000001 once multiplied) at 7%.
23731
- // The rule of report/core/rate-interval.ts, repeated here because this page
23732
- // is one self-contained script; page.spec.ts holds the two to the same
23733
- // answers.
23734
- const intervalText = (evidence) =>
23735
- Math.floor(Math.round(evidence.low * 1e6) / 1e4) + '\u2013'
23736
- + Math.ceil(Math.round(evidence.high * 1e6) / 1e4) + '%';
23961
+ const plural = (count, noun) => count + ' ' + noun + (count === 1 ? '' : 's');
23962
+
23963
+ // Escape closes whatever is open: a tooltip, or the evidence sheet.
23964
+ const dismissals = [];
23965
+ document.addEventListener('keydown', (event) => {
23966
+ if (event.key === 'Escape') for (const dismiss of dismissals) dismiss();
23967
+ });
23968
+
23737
23969
  // The counts behind an interval, in a tooltip (WCAG 1.4.13). It opens on
23738
23970
  // hover, on keyboard focus and on a tap; it stays open while the pointer is
23739
23971
  // over it; Escape closes it; and a screen reader reads it as the interval's
23740
23972
  // description. It sits in the flow under the interval, so a scrolling table
23741
23973
  // cannot clip it and it hides nothing.
23742
- const tipDismissals = [];
23743
- document.addEventListener('keydown', (event) => {
23744
- if (event.key === 'Escape') for (const dismiss of tipDismissals) dismiss();
23745
- });
23746
23974
  let tipCount = 0;
23747
- const withTip = (label, name, text) => {
23975
+ const intervalOf = (interval) => {
23976
+ if (!interval) return null;
23748
23977
  tipCount += 1;
23749
23978
  const id = 'tip-' + tipCount;
23750
- const tip = el('span', { class: 'tip', role: 'tooltip', id, hidden: '' }, text);
23979
+ const tip = el('span', { class: 'tip', role: 'tooltip', id, hidden: '' }, interval.counts);
23751
23980
  let hovered = false;
23752
23981
  let focused = false;
23753
23982
  const sync = () => {
@@ -23755,193 +23984,351 @@ const withTip = (label, name, text) => {
23755
23984
  else tip.setAttribute('hidden', '');
23756
23985
  };
23757
23986
  const trigger = el('button', { type: 'button', class: 'tip-trigger',
23758
- 'aria-label': name, 'aria-describedby': id,
23987
+ 'aria-label': interval.label, 'aria-describedby': id,
23759
23988
  // Safari focuses no button on a click or a tap, and a button that kept
23760
23989
  // focus through Escape gets no new focus event: a click (or Enter or
23761
23990
  // Space) opens the tip itself, until focus moves on.
23762
23991
  onclick: () => { trigger.focus(); focused = true; sync(); },
23763
23992
  onfocus: () => { focused = true; sync(); },
23764
23993
  onblur: () => { focused = false; sync(); },
23765
- }, label);
23766
- tipDismissals.push(() => { hovered = false; focused = false; sync(); });
23994
+ }, interval.text);
23995
+ dismissals.push(() => { hovered = false; focused = false; sync(); });
23767
23996
  return el('span', { class: 'interval',
23768
23997
  onmouseenter: () => { hovered = true; sync(); },
23769
23998
  onmouseleave: () => { hovered = false; sync(); },
23770
23999
  }, trigger, tip);
23771
24000
  };
23772
- // A rate, with its interval and counts beneath when the bundle carries them.
23773
- // subject names the rate for a screen reader, which reaches the interval
23774
- // without the label or the column heading beside it.
23775
- const rateFigure = (rate, recorded, subject, counted) => {
23776
- const figure = el('b', {}, percent(rate));
23777
- const evidence = evidenceOf(recorded);
23778
- if (!evidence) return [figure];
23779
- const interval = 'approx. 95% interval ' + intervalText(evidence);
23780
- return [figure, withTip(interval, interval + ' for ' + subject,
23781
- counted + ' in ' + evidence.count + ' of ' + evidence.planned + ' planned answers; '
23782
- + evidence.captured + ' captured')];
23783
- };
23784
- const rateStat = (label, rate, recorded, counted) =>
23785
- el('div', { class: 'stat' }, ...rateFigure(rate, recorded, label.toLowerCase(), counted), label);
23786
- // Every surface that ran, each with its own pair of rates.
23787
- const modelTable = (byModel, labelOf) => {
23788
- const rows = Object.entries(byModel && typeof byModel === 'object' ? byModel : {})
23789
- .map(([surface, rates]) => {
23790
- const { shareOfVoice, citationRate, shareOfVoiceEvidence, citationRateEvidence } = rates || {};
23791
- const model = labelOf(surface);
23792
- return el('tr', {},
23793
- el('td', {}, model),
23794
- el('td', {}, ...rateFigure(shareOfVoice, shareOfVoiceEvidence, model + ' share of voice', 'Mentioned')),
23795
- el('td', {}, ...rateFigure(citationRate, citationRateEvidence, model + ' citation rate', 'Cited')),
23796
- );
23797
- });
23798
- if (!rows.length) return [];
23799
- return [el('h3', {}, 'By model'), el('table', { class: 'by-model' },
23800
- el('thead', {}, el('tr', {}, el('th', {}, 'Model'), el('th', {}, 'Share of voice'),
23801
- el('th', {}, 'Citation rate'))),
23802
- el('tbody', {}, ...rows))];
23803
- };
23804
- const answerKey = (section, promptId, surface, runIndex) =>
23805
- section + '|' + promptId + '|' + surface + '|' + runIndex;
23806
-
23807
- const sourceLink = (url) => {
23808
- // External sources open only on a deliberate click, in a new context.
23809
- const button = el('button', { class: 'link', type: 'button' }, url);
23810
- button.addEventListener('click', () => {
23811
- if (/^https?:\\/\\//.test(url)) window.open(url, '_blank', 'noopener,noreferrer');
23812
- });
23813
- return button;
23814
- };
24001
+
24002
+ // External sources open only on a deliberate click, in a new context.
24003
+ const sourceLink = (url) => el('button', { class: 'source', type: 'button',
24004
+ onclick: () => { if (/^https?:\\/\\//.test(url)) window.open(url, '_blank', 'noopener,noreferrer'); },
24005
+ }, url);
24006
+
24007
+ // The brand's name marked in a captured answer, every piece of it text.
24008
+ const highlighted = (text, term) => {
24009
+ const needle = term.trim().toLowerCase();
24010
+ if (!needle) return [text];
24011
+ const haystack = text.toLowerCase();
24012
+ const pieces = [];
24013
+ let from = 0;
24014
+ for (let at = haystack.indexOf(needle); at !== -1; at = haystack.indexOf(needle, from)) {
24015
+ pieces.push(text.slice(from, at), el('mark', {}, text.slice(at, at + needle.length)));
24016
+ from = at + needle.length;
24017
+ }
24018
+ pieces.push(text.slice(from));
24019
+ return pieces.filter((piece) => piece !== '');
24020
+ };
24021
+
24022
+ // The side sheet behind a matrix cell or a cited domain.
24023
+ const createSheet = () => {
24024
+ const title = el('h2', { class: 'h5', id: 'sheet-title' });
24025
+ const description = el('p', { class: 'sheet-description' });
24026
+ const body = el('div', { class: 'sheet-body' });
24027
+ let opener = null;
24028
+ let isOpen = false;
24029
+ const backdrop = el('div', { class: 'sheet-backdrop', hidden: '', onclick: () => close() });
24030
+ const closeButton = el('button', { type: 'button', class: 'sheet-close', onclick: () => close() }, 'Close');
24031
+ const panel = el('div', { class: 'sheet', role: 'dialog', 'aria-modal': 'true',
24032
+ 'aria-labelledby': 'sheet-title', hidden: '' },
24033
+ el('div', { class: 'sheet-head' }, el('div', {}, title, description), closeButton), body);
24034
+ const close = () => {
24035
+ if (!isOpen) return;
24036
+ isOpen = false;
24037
+ backdrop.setAttribute('hidden', '');
24038
+ panel.setAttribute('hidden', '');
24039
+ // Focus returns to what opened the sheet.
24040
+ opener?.focus();
24041
+ };
24042
+ dismissals.push(close);
24043
+ const open = (from, heading, summary, content) => {
24044
+ opener = from;
24045
+ title.replaceChildren(heading);
24046
+ description.replaceChildren(summary);
24047
+ body.replaceChildren(...content);
24048
+ backdrop.removeAttribute('hidden');
24049
+ panel.removeAttribute('hidden');
24050
+ isOpen = true;
24051
+ closeButton.focus();
24052
+ };
24053
+ return { nodes: [backdrop, panel], open };
24054
+ };
24055
+
24056
+ const band = (tone, ...content) => el('section', { class: tone === 'soft' ? 'band soft' : 'band' },
24057
+ el('div', { class: 'container' }, el('div', { class: 'band-inner' }, ...content)));
24058
+
24059
+ const sectionHeader = (eyebrow, heading, lead, layout) => {
24060
+ const title = el('div', { class: 'header-title' },
24061
+ el('p', { class: 'eyebrow' }, eyebrow), el('h2', { class: 'h2' }, heading));
24062
+ return el('div', { class: 'header ' + (layout || (lead ? 'split' : '')) },
24063
+ title, lead ? el('p', { class: 'body-2' }, lead) : null);
24064
+ };
24065
+
24066
+ const statusLabels = { primary: 'Primary', mentioned: 'Mentioned', absent: 'Absent', no_overview: 'No AI Overview' };
24067
+ const retrievalLabels = { searched: 'searched the web', memory: 'answered from memory', unknown: 'retrieval unknown' };
24068
+
24069
+ const runCard = (run, brandName) => el('article', { class: 'run' },
24070
+ el('div', { class: 'run-head' },
24071
+ el('div', {}, el('p', { class: 'run-title' }, 'Run ' + run.runNumber),
24072
+ el('p', { class: 'run-surface' }, run.surface + (run.cliVersion ? ' \xB7 ' + run.cliVersion : ''))),
24073
+ el('div', { class: 'pills' },
24074
+ run.retrieval ? el('span', { class: 'pill mono' + (run.retrieval === 'unknown' ? ' dashed' : '') },
24075
+ retrievalLabels[run.retrieval]) : null,
24076
+ el('span', { class: 'pill ' + (run.status === 'no_overview' ? 'dashed' : run.status) }, statusLabels[run.status]))),
24077
+ run.snippet ? el('div', { class: 'snippet' }, el('p', { class: 'label' }, 'Detected mention'),
24078
+ el('p', { class: 'answer' }, ...highlighted(run.snippet, brandName))) : null,
24079
+ run.answer ? el('div', { class: 'run-block' }, el('p', { class: 'label' }, 'Full captured answer'),
24080
+ el('p', { class: 'answer' }, ...highlighted(run.answer, brandName)))
24081
+ : el('p', { class: 'empty run-block' }, run.status === 'no_overview'
24082
+ ? 'The results page showed no AI Overview: there is no answer to show.'
24083
+ : 'No captured answer in this bundle matches this run.'),
24084
+ run.mentionedBrands.length ? el('div', { class: 'run-block' }, el('p', { class: 'label' }, 'Mentioned companies'),
24085
+ el('ul', { class: 'pills' }, run.mentionedBrands.map((brand) => el('li', {}, el('span', { class: 'pill plain' }, brand))))) : null,
24086
+ run.citedUrls.length ? el('div', { class: 'run-block' }, el('p', { class: 'label' }, 'URLs in response'),
24087
+ el('ul', { class: 'links' }, run.citedUrls.map((url) => el('li', {}, sourceLink(url))))) : null,
24088
+ );
24089
+
24090
+ const scorecards = (cards) => el('div', { class: 'scorecards' },
24091
+ el('div', { class: cards.length >= 5 ? 'scorecards-grid five' : 'scorecards-grid' },
24092
+ cards.map((card) => el('div', { class: 'stat' },
24093
+ el('p', { class: 'stat-figure' }, card.headline),
24094
+ intervalOf(card.headlineInterval),
24095
+ el('p', { class: 'stat-label' }, card.label),
24096
+ card.detail ? el('p', { class: 'stat-detail' }, card.detail) : null,
24097
+ intervalOf(card.detailInterval)))));
24098
+
24099
+ const surfaceRates = (rows) => rows.length === 0 ? null : el('section', { class: 'subsection', 'aria-label': 'Rates by AI surface' },
24100
+ el('p', { class: 'h5' }, 'By AI surface'),
24101
+ el('div', { class: 'scroll' }, el('table', { class: 'by-model' },
24102
+ el('thead', {}, el('tr', {}, el('th', {}, 'AI surface'), el('th', {}, 'Share of voice'), el('th', {}, 'Citation rate'))),
24103
+ el('tbody', {}, rows.map((row) => el('tr', {},
24104
+ el('td', {}, row.surface),
24105
+ el('td', {}, el('span', { class: 'rate' }, row.shareOfVoice.percent), intervalOf(row.shareOfVoice.interval)),
24106
+ el('td', {}, el('span', { class: 'rate' }, row.citationRate.percent), intervalOf(row.citationRate.interval))))))));
24107
+
24108
+ const dot = (status) => el('span', { class: 'dot ' + status, role: 'img',
24109
+ 'aria-label': { primary: 'Primary mention', mentioned: 'Secondary mention', absent: 'Not mentioned', no_data: 'No data' }[status] });
24110
+
24111
+ const matrix = (section, brandName, sheet) => {
24112
+ const { assistantSurfaces, agentSurfaces, rows } = section.matrix;
24113
+ const surfaces = [...assistantSurfaces, ...agentSurfaces];
24114
+ const firstAgent = assistantSurfaces.length;
24115
+ const edge = (index, base) => base + (agentSurfaces.length && index === firstAgent ? ' agents-start' : '');
24116
+ const groups = agentSurfaces.length === 0 ? null : el('tr', {},
24117
+ el('td', { class: 'prompt group', 'aria-hidden': 'true' }),
24118
+ assistantSurfaces.length ? el('th', { class: 'group', colspan: String(assistantSurfaces.length), scope: 'colgroup' }, 'AI assistants') : null,
24119
+ el('th', { class: 'group agents-start', colspan: String(agentSurfaces.length), scope: 'colgroup' }, 'Coding agents'));
24120
+ const body = rows.map((row, promptIdx) => el('tr', {},
24121
+ el('td', { class: 'prompt', title: row.prompt },
24122
+ el('span', { class: 'prompt-text' }, row.prompt), el('span', { class: 'prompt-category' }, row.category)),
24123
+ row.cells.map((cell, index) => el('td', { class: edge(index, '') },
24124
+ cell.status === 'no_data' ? dot('no_data') : (() => {
24125
+ const button = el('button', { type: 'button', class: 'cell',
24126
+ 'aria-label': surfaces[index] + ', prompt ' + (promptIdx + 1) + ': ' + cell.status + '. Inspect evidence.',
24127
+ onclick: () => sheet.open(button, surfaces[index] + ' evidence',
24128
+ 'Prompt ' + (promptIdx + 1) + ' \xB7 ' + cell.mentioned + '/' + cell.runs.length + ' runs mentioned ' + brandName,
24129
+ [el('section', { class: 'prompt-box' }, el('h3', { class: 'label' }, 'Prompt'), el('p', {}, row.prompt),
24130
+ el('p', { class: 'prompt-category' }, row.category)),
24131
+ ...cell.runs.map((run) => runCard(run, brandName))]),
24132
+ }, dot(cell.status), el('span', { class: 'cell-count' }, cell.mentioned + '/' + cell.runs.length));
24133
+ return button;
24134
+ })()))));
24135
+ return el('div', { class: 'card matrix-card' },
24136
+ el('div', { class: 'scroll', role: 'group', 'aria-label': 'AI answer evidence matrix', tabindex: '0' },
24137
+ el('table', { class: 'matrix' },
24138
+ el('thead', {}, groups, el('tr', {}, el('th', { class: 'prompt-head' }, 'Prompt'),
24139
+ surfaces.map((surface, index) => el('th', { class: edge(index, '') }, surface)))),
24140
+ el('tbody', {}, body))),
24141
+ el('ul', { class: 'legend' },
24142
+ [['primary', 'Primary recommendation'], ['mentioned', 'Mentioned secondarily'], ['absent', 'Not mentioned'], ['no_data', 'No data']]
24143
+ .map(([status, text]) => el('li', {}, el('span', { class: 'dot ' + status }), text))),
24144
+ el('p', { class: 'hint' }, 'Click any dot with a run count to inspect the captured AI answers, cited URLs, and highlighted mentions behind that result.'));
24145
+ };
24146
+
24147
+ const alternatives = (rows) => rows.length === 0 ? null : el('div', { class: 'card' },
24148
+ el('h3', { class: 'card-title' }, 'Who buyers hear about instead'),
24149
+ el('p', { class: 'card-lead' }, 'Competing companies and products named in the answers, ranked by share of voice (answers that mention them / answers captured).'),
24150
+ el('ul', { class: 'bars' }, rows.map((row) => {
24151
+ const fill = el('span', { class: 'bar-fill' });
24152
+ // CSSOM, which the page's Content Security Policy allows, unlike a style attribute.
24153
+ if (fill.style) fill.style.width = (row.share * 100) + '%';
24154
+ return el('li', {},
24155
+ el('span', { class: 'bar-name', title: row.domain || row.name }, row.name,
24156
+ row.domain && row.domain.toLowerCase() !== row.name.trim().toLowerCase() ? el('span', { class: 'bar-domain' }, row.domain) : null),
24157
+ el('span', { class: 'bar' }, fill),
24158
+ el('span', { class: 'bar-value' }, row.percent + ' ' + row.mentioning + '/' + row.captured));
24159
+ })));
24160
+
24161
+ const citedDomains = (domains, sheet) => {
24162
+ const total = domains.reduce((sum, domain) => sum + domain.count, 0);
24163
+ const shown = 10;
24164
+ const body = el('tbody');
24165
+ const more = el('button', { type: 'button', class: 'more' });
24166
+ let showAll = false;
24167
+ const rowOf = (domain) => {
24168
+ const inspect = (from) => sheet.open(from, domain.domain, plural(domain.count, 'citation') + ' across the captured answers',
24169
+ [el('ul', { class: 'links' }, domain.urls.map((url) => el('li', {}, sourceLink(url.url),
24170
+ el('p', { class: 'source-meta' }, plural(url.count, 'citation') + ' \xB7 ' + url.surfaces.join(', ')),
24171
+ ...url.prompts.map((prompt) => el('p', { class: 'source-meta' }, prompt)))))]);
24172
+ const name = el('span', { class: domain.isBrand ? 'rate' : '' }, domain.domain);
24173
+ const hosts = domain.hosts ? el('span', { class: 'hosts' }, domain.hosts.map((host) => host.label + ' ' + host.count).join(' \xB7 ')) : null;
24174
+ if (domain.count === 0) return el('tr', {}, el('td', {}, name, hosts), el('td', { class: 'num' }, '0'));
24175
+ const button = el('button', { type: 'button', class: 'row-button',
24176
+ 'aria-label': 'Inspect the ' + domain.count + ' cited URLs behind ' + domain.domain,
24177
+ onclick: (event) => { event.stopPropagation?.(); inspect(button); } }, name, hosts);
24178
+ return el('tr', { class: 'selectable', onclick: () => inspect(button) },
24179
+ el('td', {}, button), el('td', { class: 'num' }, String(domain.count)));
24180
+ };
24181
+ const sync = () => {
24182
+ body.replaceChildren(...(showAll ? domains : domains.slice(0, shown)).map(rowOf));
24183
+ const hidden = domains.length - shown;
24184
+ more.replaceChildren(showAll ? 'Show fewer domains' : '+' + plural(hidden, 'more domain'));
24185
+ if (hidden > 0) more.removeAttribute('hidden'); else more.setAttribute('hidden', '');
24186
+ };
24187
+ more.addEventListener('click', () => { showAll = !showAll; sync(); });
24188
+ sync();
24189
+ return el('div', { class: 'card' },
24190
+ el('h3', { class: 'card-title' }, 'What gets cited'),
24191
+ el('p', { class: 'card-lead' }, 'Domains behind the URLs cited in these answers'
24192
+ + (total > 0 ? ' (' + total + ' citations captured). Click a domain to inspect the URLs behind it.' : '.')),
24193
+ el('div', { class: 'scroll' }, el('table', {},
24194
+ el('thead', {}, el('tr', {}, el('th', {}, 'Domain'), el('th', { class: 'num' }, 'Citations'))), body)),
24195
+ more);
24196
+ };
24197
+
24198
+ const sourceCategories = [['owned', 'Owned'], ['competitor', 'Competitor'], ['social', 'Social & community'],
24199
+ ['institutional', 'Institutional'], ['earned', 'Earned']];
24200
+
24201
+ const sourceMix = (mix) => !mix || mix.rows.length === 0 ? null : el('div', { class: 'card' },
24202
+ el('h3', { class: 'card-title' }, 'Where the citations come from'),
24203
+ el('p', { class: 'card-lead' }, 'Every cited URL classified: the brand\u2019s own pages, competitor pages, social and community threads, institutional references, or earned media. Each surface leans differently.'),
24204
+ el('div', { class: 'scroll', role: 'group', 'aria-label': 'Citation sources by AI surface', tabindex: '0' },
24205
+ el('table', {},
24206
+ el('thead', {}, el('tr', {}, el('th', {}, 'Surface'), sourceCategories.map(([, label]) => el('th', { class: 'num' }, label)))),
24207
+ el('tbody', {},
24208
+ mix.rows.map((row) => el('tr', {}, el('td', { class: 'rate' }, row.surface),
24209
+ sourceCategories.map(([key]) => el('td', { class: 'num' }, row.counts[key] ? String(row.counts[key]) : '\u2014')))),
24210
+ el('tr', { class: 'total' }, el('td', {}, 'All surfaces'),
24211
+ sourceCategories.map(([key]) => el('td', { class: 'num' }, mix.total[key] ? String(mix.total[key]) : '\u2014')))))));
24212
+
24213
+ const perception = (view, brandName) => {
24214
+ if (!view) return null;
24215
+ const mentions = view.positive + view.neutral + view.negative;
24216
+ if (mentions === 0 && view.phrases.length === 0) return null;
24217
+ return el('div', { class: 'card' },
24218
+ el('h3', { class: 'card-title' }, 'How the answers talk about ' + brandName),
24219
+ mentions > 0 ? el('p', { class: 'card-lead' }, 'Across ' + mentions + ' answers that mention ' + brandName + ': '
24220
+ + view.positive + ' positive, ' + view.neutral + ' neutral, ' + view.negative + ' negative.') : null,
24221
+ view.phrases.length ? el('div', { class: 'run-block' },
24222
+ el('p', { class: 'label' }, 'Phrases the answers attach to ' + brandName),
24223
+ el('ul', { class: 'pills' }, view.phrases.map((phrase) => el('li', {},
24224
+ el('span', { class: 'pill', title: 'Said by ' + phrase.surfaces.join(', ') },
24225
+ el('span', {}, '\u201C' + phrase.text + '\u201D'),
24226
+ phrase.count > 1 ? el('span', { class: 'pill-count' }, '\xD7' + phrase.count) : null))))) : null);
24227
+ };
24228
+
24229
+ const verification = (result) => el('div', { class: 'card' },
24230
+ el('h3', { class: 'card-title' }, 'Checks'),
24231
+ el('p', { class: 'card-lead' }, 'Capture authenticity: self-reported. Checks run on this machine, offline.'),
24232
+ el('div', { class: 'scroll' }, el('table', { class: 'verification' },
24233
+ el('thead', {}, el('tr', {}, el('th', {}, 'Check'), el('th', {}, 'Outcome'), el('th', {}, 'Why'))),
24234
+ el('tbody', {}, result.checks.map((check) => el('tr', {},
24235
+ el('td', {}, check.title),
24236
+ el('td', {}, el('span', { class: 'pill ' + (check.outcome === 'pass' ? 'pass' : check.outcome === 'fail' ? 'fail' : 'dashed') },
24237
+ check.outcome.replace('_', ' '))),
24238
+ el('td', { class: 'muted' }, check.outcome === 'pass' ? '' : check.explanation)))))));
24239
+
24240
+ const hero = (report, info) => el('section', { class: 'hero' }, el('div', { class: 'container' },
24241
+ el('div', { class: 'hero-grid' },
24242
+ el('div', { class: 'hero-copy' },
24243
+ el('p', { class: 'eyebrow' }, 'AI visibility audit'),
24244
+ el('h1', { class: 'h1' }, report.hero.title),
24245
+ el('p', { class: 'body-1' }, report.hero.subtitle),
24246
+ el('p', { class: 'measured' }, 'Measured ' + report.hero.measuredOn + ' \xB7 ' + info.originLabel)),
24247
+ el('div', { class: 'measurement' },
24248
+ el('p', { class: 'eyebrow' }, 'The measurement'),
24249
+ el('p', { class: 'measurement-figure' }, String(report.hero.probeCount)),
24250
+ el('p', { class: 'h5' }, 'captured AI answers'),
24251
+ el('ul', { class: 'facts' }, report.hero.facts.map((fact) => el('li', {}, fact)))))));
24252
+
24253
+ const plainHero = (info) => el('section', { class: 'hero' }, el('div', { class: 'container' },
24254
+ el('div', { class: 'hero-grid' }, el('div', { class: 'hero-copy' },
24255
+ el('p', { class: 'eyebrow' }, 'Literally.dev AEO'),
24256
+ el('h1', { class: 'h1' }, 'AI visibility audit'),
24257
+ el('p', { class: 'measured' }, info.originLabel)))));
23815
24258
 
23816
24259
  const render = async () => {
23817
24260
  const root = document.getElementById('app');
23818
- const [info, verification, snapshot, captures, config] = await Promise.all([
23819
- get('__viewer'), get('__verification'), get('report/snapshot.json'),
23820
- get('captures/units.json'), get('inputs/config.json'),
23821
- ]);
24261
+ const [info, result, report] = await Promise.all([get('__viewer'), get('__verification'), get('__report')]);
23822
24262
  root.replaceChildren();
23823
- if (!info) {
23824
- root.append(el('p', {}, 'This viewer link is not valid. Start it again with literally-aeo view.'));
24263
+ if (!info || !report) {
24264
+ root.append(el('p', { class: 'container' }, 'This viewer link is not valid. Start it again with literally-aeo view.'));
23825
24265
  return;
23826
24266
  }
23827
- const brand = (snapshot && snapshot.brand && snapshot.brand.name)
23828
- || (config && config.brand && config.brand.name) || 'Audit';
23829
- root.append(
23830
- el('h1', {}, brand + ': AI visibility audit'),
23831
- el('p', { class: 'muted' }, info.originLabel + ' \xB7 ' + info.source),
23832
- );
24267
+ const sheet = createSheet();
24268
+ const shown = report.outcome === 'shown';
23833
24269
  if (info.workingState) {
23834
- root.append(el('div', { class: 'banner warn' },
24270
+ root.append(el('div', { class: 'banner' },
23835
24271
  'Working state, not a finalized revision: this is not an integrity receipt. Export the run to finalize it.'));
23836
24272
  }
23837
- if (verification) {
23838
- const rows = verification.checks.map((check) => el('tr', {},
23839
- el('td', {}, check.title),
23840
- el('td', { class: check.outcome === 'pass' ? 'pass' : check.outcome === 'fail' ? 'fail' : 'limited' },
23841
- check.outcome.replace('_', ' ')),
23842
- el('td', { class: 'muted' }, check.outcome === 'pass' ? '' : check.explanation),
23843
- ));
23844
- root.append(el('h2', {}, 'Verification'),
23845
- el('p', { class: 'muted' }, 'Capture authenticity: self-reported. Checks run on this machine, offline.'),
23846
- el('div', { class: 'table-wrap' }, el('table', {}, el('tbody', {}, ...rows))));
23847
- }
23848
- if (!snapshot) {
23849
- root.append(el('div', { class: 'banner' }, 'This run has no report yet: the measurement did not finish.'));
23850
- return;
23851
- }
23852
- const answers = new Map();
23853
- for (const record of captures || []) {
23854
- answers.set(answerKey(record.sectionKey, record.promptId, record.surface, record.runIndex), record);
23855
- }
23856
- // The snapshot names prompts by text; their ids, which key the captured
23857
- // answers, come from the frozen configuration in the same order.
23858
- const promptIds = new Map();
23859
- for (const configured of (config && config.sections) || []) {
23860
- promptIds.set(configured.key, configured.prompts.map((prompt) => prompt.id));
24273
+ root.append(shown ? hero(report, info) : plainHero(info));
24274
+ const bands = [];
24275
+ if (shown && report.intro) {
24276
+ bands.push([sectionHeader('AI search visibility', report.intro.heading, report.intro.lead, 'center')]);
24277
+ }
24278
+ if (result || !shown) {
24279
+ // A working state is not verified: no claim that it was.
24280
+ bands.push([sectionHeader('Evidence', 'Verification', result
24281
+ ? 'The bundle re-checked on this machine: its hashes, its event chain and every metric recomputed from its own judgments. A check that cannot run says so.'
24282
+ : undefined),
24283
+ result ? verification(result) : null,
24284
+ shown ? null : el('p', { class: 'card empty' }, report.outcome === 'missing'
24285
+ ? 'This run has no report yet: the measurement did not finish.'
24286
+ : 'The report cannot be shown: ' + report.reason)]);
24287
+ }
24288
+ for (const section of shown ? report.sections : []) {
24289
+ bands.push([
24290
+ sectionHeader('AI search visibility', section.title),
24291
+ scorecards(section.scorecards),
24292
+ surfaceRates(section.surfaceRates),
24293
+ matrix(section, report.brand.name, sheet),
24294
+ alternatives(section.alternatives),
24295
+ citedDomains(section.citedDomains, sheet),
24296
+ sourceMix(section.sourceMix),
24297
+ perception(section.perception, report.brand.name),
24298
+ ]);
23861
24299
  }
23862
-
23863
- // A surface asked of another model than its default, and every custom
23864
- // surface, carries its own label in the snapshot; any other is shown by
23865
- // its ID. Like every string of a bundle, a label is inserted as text.
23866
- const labels = (snapshot.meta && snapshot.meta.surfaceLabels) || {};
23867
- const labelOf = (surface) =>
23868
- typeof labels[surface] === 'string' && labels[surface] ? labels[surface] : surface;
23869
-
23870
- for (const section of snapshot.sections) {
23871
- const { summary, matrix, prompts } = section.visibility;
23872
- root.append(el('h2', {}, 'Section ' + section.key));
23873
- root.append(el('div', { class: 'grid' },
23874
- rateStat('Assistant share of voice', summary.prospectShareOfVoice,
23875
- summary.prospectShareOfVoiceEvidence, 'Mentioned'),
23876
- rateStat('Assistant citation rate', summary.prospectCitationRate,
23877
- summary.prospectCitationRateEvidence, 'Cited'),
23878
- rateStat('Coding-agent share of voice', summary.agentShareOfVoice,
23879
- summary.agentShareOfVoiceEvidence, 'Mentioned'),
23880
- rateStat('Coding-agent citation rate', summary.agentCitationRate,
23881
- summary.agentCitationRateEvidence, 'Cited'),
23882
- // The scraped consumer apps, only for a run that planned one.
23883
- ...(summary.consumerShareOfVoice === undefined ? [] : [
23884
- rateStat('Consumer-app share of voice', summary.consumerShareOfVoice,
23885
- summary.consumerShareOfVoiceEvidence, 'Mentioned'),
23886
- rateStat('Consumer-app citation rate', summary.consumerCitationRate,
23887
- summary.consumerCitationRateEvidence, 'Cited'),
23888
- ]),
23889
- el('div', { class: 'stat' }, el('b', {}, summary.topCompetitorDomain || 'none'), 'Most mentioned competitor'),
23890
- ));
23891
- root.append(el('p', { class: 'muted' },
23892
- 'Share of voice is how often the measured answers name the product, not market share.'));
23893
- root.append(...modelTable(summary.byModel, labelOf));
23894
- const drawer = el('div', { class: 'drawer', hidden: '' });
23895
- const body = el('tbody');
23896
- for (const row of matrix) {
23897
- const prompt = prompts[row.promptIdx] || { text: '' };
23898
- const promptId = (promptIds.get(section.key) || [])[row.promptIdx];
23899
- const record = answers.get(answerKey(section.key, promptId, row.surface, row.runIndex || 0));
23900
- const open = () => {
23901
- drawer.removeAttribute('hidden');
23902
- drawer.replaceChildren(
23903
- el('h3', {}, labelOf(row.surface) + ', run ' + (row.runIndex || 0)),
23904
- el('p', {}, prompt.text),
23905
- record ? el('pre', {}, record.probe.text)
23906
- : el('p', { class: 'limited' }, 'The answer is not in this bundle.'),
23907
- ...(row.citedUrls && row.citedUrls.length
23908
- ? [el('h3', {}, 'Cited sources'), ...row.citedUrls.map((url) => el('div', {}, sourceLink(url)))]
23909
- : []),
23910
- );
23911
- drawer.scrollIntoView({ block: 'nearest' });
23912
- };
23913
- body.append(el('tr', { class: 'row', tabindex: '0', onclick: open,
23914
- onkeydown: (event) => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); open(); } } },
23915
- el('td', {}, prompt.text),
23916
- el('td', {}, labelOf(row.surface)),
23917
- el('td', {}, String(row.runIndex || 0)),
23918
- el('td', {}, row.prospectMentioned ? 'mentioned' + (row.prospectPosition ? ' (' + row.prospectPosition + ')' : '') : 'not mentioned'),
23919
- el('td', {}, (row.qualifiedCompetitors || []).map((entry) => entry.name).join(', ')),
23920
- ));
23921
- }
23922
- root.append(el('div', { class: 'table-wrap' }, el('table', {},
23923
- el('thead', {}, el('tr', {}, el('th', {}, 'Question'), el('th', {}, 'Surface'),
23924
- el('th', {}, 'Run'), el('th', {}, 'Product'), el('th', {}, 'Alternatives named'))),
23925
- body)), drawer);
23926
- }
23927
- const methodology = snapshot.meta && Array.isArray(snapshot.meta.methodology)
23928
- ? snapshot.meta.methodology.filter((sentence) => typeof sentence === 'string')
23929
- : [];
23930
- if (methodology.length) {
23931
- root.append(el('h2', {}, 'Methodology'),
23932
- el('ul', { class: 'methodology' },
23933
- ...methodology.map((sentence) => el('li', {}, sentence))));
23934
- }
23935
- root.append(el('footer', {},
23936
- 'Generated with Literally.dev AEO, an open-source AI visibility audit tool. ',
23937
- info.originLabel + '. Literally.dev did not review this result. Engine ' + info.toolVersion + '.'));
24300
+ bands.push([el('div', { class: 'footer' },
24301
+ shown ? el('p', {}, report.footer.baseline) : null,
24302
+ shown && report.footer.methodology.length ? el('section', { 'aria-labelledby': 'methodology' },
24303
+ el('h2', { id: 'methodology' }, 'Methodology'),
24304
+ el('ul', { class: 'methodology' }, report.footer.methodology.map((sentence) => el('li', {}, sentence)))) : null,
24305
+ ...(shown ? report.footer.notes : []).map((note) => el('p', {}, note)),
24306
+ el('p', { class: 'footer-note' },
24307
+ 'Generated with Literally.dev AEO ' + info.toolVersion + ', an open-source AI visibility audit tool. '
24308
+ + info.originLabel + '. Literally.dev did not review this result. Bundle: ' + info.source + '.'))]);
24309
+ bands.forEach((content, index) => root.append(band(index % 2 === 1 ? 'soft' : 'plain', ...content)));
24310
+ root.append(...sheet.nodes);
23938
24311
  };
23939
24312
 
23940
24313
  render().catch((error) => {
23941
24314
  document.getElementById('app').textContent = 'The viewer could not load this bundle: ' + error.message;
23942
24315
  });
23943
24316
  `;
23944
- var viewerPage = (nonce) => {
24317
+ var viewerFontFiles = {
24318
+ body: "Mulish-VariableFont_wght.ttf",
24319
+ mono: "SourceCodePro-VariableFont_wght.ttf"
24320
+ };
24321
+ var fontFaces = (token) => {
24322
+ const source = (file) => `url("/fonts/${file}?t=${encodeURIComponent(token)}") format("truetype")`;
24323
+ return `
24324
+ @font-face { font-family: Mulish; font-weight: 200 1000; font-display: swap;
24325
+ src: ${source(viewerFontFiles.body)}; }
24326
+ @font-face { font-family: "Source Code Pro"; font-weight: 200 900; font-display: swap;
24327
+ src: ${source(viewerFontFiles.mono)}; }
24328
+ `;
24329
+ };
24330
+ var viewerPage = (nonce, fontToken) => {
24331
+ const faces = fontToken === void 0 ? "" : fontFaces(fontToken);
23945
24332
  return `<!doctype html>
23946
24333
  <html lang="en">
23947
24334
  <head>
@@ -23949,23 +24336,649 @@ var viewerPage = (nonce) => {
23949
24336
  <meta name="viewport" content="width=device-width, initial-scale=1">
23950
24337
  <meta name="referrer" content="no-referrer">
23951
24338
  <title>Literally.dev AEO</title>
23952
- <style nonce="${nonce}">${styles}</style>
24339
+ <style nonce="${nonce}">${faces}${styles}</style>
23953
24340
  </head>
23954
24341
  <body>
23955
- <main id="app"><p class="muted">Loading the audit\u2026</p></main>
24342
+ <main id="app"><p class="container">Loading the audit\u2026</p></main>
23956
24343
  <script nonce="${nonce}">${script}</script>
23957
24344
  </body>
23958
24345
  </html>`;
23959
24346
  };
23960
24347
 
24348
+ // src/viewer/server.ts
24349
+ import { randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
24350
+ import {
24351
+ createServer as createServer2
24352
+ } from "node:http";
24353
+ import { z as z64 } from "zod";
24354
+
24355
+ // src/viewer/presentation.ts
24356
+ import { z as z63 } from "zod";
24357
+
24358
+ // src/viewer/alternatives.ts
24359
+ var rankAlternatives = (matrix, prospect) => {
24360
+ const isProspect = matchesProspect(prospect);
24361
+ const ranked = [...foldNameOnlySightings(collectSightings(matrix)).values()].filter((sighting) => !isProspect(sighting)).map((sighting) => ({
24362
+ name: displayName(sighting),
24363
+ ...sighting.domain !== void 0 && { domain: sighting.domain },
24364
+ mentioning: sighting.rowIndices.size,
24365
+ captured: matrix.length
24366
+ })).sort(
24367
+ (a, b) => b.mentioning - a.mentioning || a.name.localeCompare(b.name)
24368
+ );
24369
+ return ranked;
24370
+ };
24371
+ var collectSightings = (matrix) => {
24372
+ const sightings = /* @__PURE__ */ new Map();
24373
+ matrix.forEach((row, rowIndex) => {
24374
+ for (const brand of qualifiedCompetitorsForRow(row)) {
24375
+ const name = brand.name.trim();
24376
+ const domain = brand.domain ? normalizeDomain(brand.domain) : void 0;
24377
+ const key2 = domain ?? name.toLowerCase();
24378
+ const sighting = sightings.get(key2) ?? {
24379
+ key: key2,
24380
+ names: /* @__PURE__ */ new Map(),
24381
+ rowIndices: /* @__PURE__ */ new Set()
24382
+ };
24383
+ const nameRows = sighting.names.get(name) ?? /* @__PURE__ */ new Set();
24384
+ sighting.domain ??= domain;
24385
+ nameRows.add(rowIndex);
24386
+ sighting.names.set(name, nameRows);
24387
+ sighting.rowIndices.add(rowIndex);
24388
+ sightings.set(key2, sighting);
24389
+ }
24390
+ });
24391
+ return sightings;
24392
+ };
24393
+ var foldNameOnlySightings = (sightings) => {
24394
+ const domainKeysByName = /* @__PURE__ */ new Map();
24395
+ for (const sighting of sightings.values()) {
24396
+ if (sighting.domain === void 0) {
24397
+ continue;
24398
+ }
24399
+ for (const name of sighting.names.keys()) {
24400
+ const lowered = name.toLowerCase();
24401
+ const keys = domainKeysByName.get(lowered) ?? /* @__PURE__ */ new Set();
24402
+ keys.add(sighting.key);
24403
+ domainKeysByName.set(lowered, keys);
24404
+ }
24405
+ }
24406
+ const folded = new Map(sightings);
24407
+ for (const sighting of sightings.values()) {
24408
+ if (sighting.domain !== void 0) {
24409
+ continue;
24410
+ }
24411
+ const [ownerKey, ...otherKeys] = [
24412
+ ...domainKeysByName.get(sighting.key) ?? []
24413
+ ];
24414
+ const owner = ownerKey === void 0 ? void 0 : folded.get(ownerKey);
24415
+ if (!owner || otherKeys.length > 0) {
24416
+ continue;
24417
+ }
24418
+ folded.set(owner.key, mergeSightings(owner, sighting));
24419
+ folded.delete(sighting.key);
24420
+ }
24421
+ return folded;
24422
+ };
24423
+ var mergeSightings = (owner, nameOnly) => {
24424
+ const names = new Map(
24425
+ [...owner.names].map(([name, rows]) => [name, new Set(rows)])
24426
+ );
24427
+ for (const [name, rows] of nameOnly.names) {
24428
+ names.set(name, /* @__PURE__ */ new Set([...names.get(name) ?? [], ...rows]));
24429
+ }
24430
+ const merged = {
24431
+ ...owner,
24432
+ names,
24433
+ rowIndices: /* @__PURE__ */ new Set([...owner.rowIndices, ...nameOnly.rowIndices])
24434
+ };
24435
+ return merged;
24436
+ };
24437
+ var displayName = (sighting) => {
24438
+ const spellings = [...sighting.names].map(([name, rows]) => ({
24439
+ name,
24440
+ words: name.toLowerCase().split(/\s+/),
24441
+ answers: rows.size
24442
+ }));
24443
+ const [base] = [...spellings].sort(
24444
+ (a, b) => a.words.length - b.words.length || b.answers - a.answers || a.name.localeCompare(b.name)
24445
+ );
24446
+ if (!base) {
24447
+ throw new Error(`Alternative has no recorded name: ${sighting.key}.`);
24448
+ }
24449
+ const isSharedBase = spellings.every(
24450
+ (spelling) => base.words.every((word, index) => spelling.words[index] === word)
24451
+ );
24452
+ if (!isSharedBase && sighting.domain !== void 0) {
24453
+ return sighting.domain;
24454
+ }
24455
+ const [label] = spellings.filter((spelling) => spelling.words.length === base.words.length).sort((a, b) => b.answers - a.answers || a.name.localeCompare(b.name));
24456
+ return (label ?? base).name;
24457
+ };
24458
+ var matchesProspect = (prospect) => {
24459
+ const prospectName = prospect.name.trim().toLowerCase();
24460
+ const prospectDomain = normalizeDomain(prospect.domain);
24461
+ return (sighting) => {
24462
+ const identity2 = sighting.domain ?? sighting.key;
24463
+ const isProspectDomain = identity2 === prospectDomain || identity2.endsWith(`.${prospectDomain}`);
24464
+ const isProspectName = [...sighting.names.keys()].some(
24465
+ (name) => name.toLowerCase() === prospectName
24466
+ );
24467
+ return isProspectDomain || isProspectName;
24468
+ };
24469
+ };
24470
+
24471
+ // src/viewer/cited-domains.ts
24472
+ var groupCitedDomains = (visibility, brandDomain) => {
24473
+ const brand = normalizeDomain(brandDomain);
24474
+ const urlsByDomain = /* @__PURE__ */ new Map();
24475
+ const brandHostCounts = /* @__PURE__ */ new Map();
24476
+ for (const row of visibility.matrix) {
24477
+ for (const url of row.citedUrls ?? []) {
24478
+ const host = isGroundingRedirectUrl(url) ? void 0 : hostOf(url);
24479
+ if (host === void 0) {
24480
+ continue;
24481
+ }
24482
+ const isBrandHost = host === brand || host.endsWith(`.${brand}`);
24483
+ const domain = isBrandHost ? brand : apexOf(host);
24484
+ const urls = urlsByDomain.get(domain) ?? /* @__PURE__ */ new Map();
24485
+ const cited = urls.get(url) ?? {
24486
+ url,
24487
+ count: 0,
24488
+ surfaces: [],
24489
+ prompts: []
24490
+ };
24491
+ const promptText = visibility.prompts[row.promptIdx]?.text;
24492
+ cited.count += 1;
24493
+ if (!cited.surfaces.includes(row.surface)) {
24494
+ cited.surfaces.push(row.surface);
24495
+ }
24496
+ if (promptText !== void 0 && !cited.prompts.includes(promptText)) {
24497
+ cited.prompts.push(promptText);
24498
+ }
24499
+ urls.set(url, cited);
24500
+ urlsByDomain.set(domain, urls);
24501
+ if (isBrandHost) {
24502
+ const label = brandHostLabel(host, brand);
24503
+ brandHostCounts.set(label, (brandHostCounts.get(label) ?? 0) + 1);
24504
+ }
24505
+ }
24506
+ }
24507
+ const domainOf = (domain) => {
24508
+ const urls = [...urlsByDomain.get(domain)?.values() ?? []].sort(
24509
+ (a, b) => b.count - a.count || a.url.localeCompare(b.url)
24510
+ );
24511
+ const cited = {
24512
+ domain,
24513
+ count: urls.reduce((sum, url) => sum + url.count, 0),
24514
+ isBrand: domain === brand,
24515
+ urls
24516
+ };
24517
+ return cited;
24518
+ };
24519
+ const brandRow = {
24520
+ ...domainOf(brand),
24521
+ ...brandHostCounts.size > 0 && {
24522
+ hosts: [...brandHostCounts].map(([label, count]) => ({ label, count })).sort((a, b) => b.count - a.count)
24523
+ }
24524
+ };
24525
+ const others = [...urlsByDomain.keys()].filter((domain) => domain !== brand).map(domainOf).sort((a, b) => b.count - a.count || a.domain.localeCompare(b.domain));
24526
+ const domains = [brandRow, ...others];
24527
+ return domains;
24528
+ };
24529
+ var hostOf = (url) => {
24530
+ try {
24531
+ return normalizeDomain(new URL(url).hostname);
24532
+ } catch {
24533
+ return void 0;
24534
+ }
24535
+ };
24536
+ var apexOf = (host) => {
24537
+ const labels = host.split(".");
24538
+ return labels.length <= 2 ? host : labels.slice(-2).join(".");
24539
+ };
24540
+ var brandHostLabel = (host, brand) => {
24541
+ return host === brand ? "site" : host.slice(0, -(brand.length + 1));
24542
+ };
24543
+
24544
+ // src/viewer/presentation.ts
24545
+ var viewedSnapshotSchema = z63.object({
24546
+ brand: brandSchema.optional(),
24547
+ sections: aeoSnapshotSchema.shape.sections,
24548
+ sourceMix: aeoSourceMixSchema.optional(),
24549
+ perception: aeoPerceptionSchema.optional(),
24550
+ meta: aeoSnapshotSchema.shape.meta.pick({
24551
+ generatedAt: true,
24552
+ promptCount: true,
24553
+ probeCount: true,
24554
+ partialFailures: true,
24555
+ surfaceLabels: true,
24556
+ methodology: true,
24557
+ reusedProbes: true
24558
+ }).partial({ promptCount: true, probeCount: true, partialFailures: true })
24559
+ });
24560
+ var configBrandSchema = z63.object({
24561
+ brand: z63.object({ name: z63.string().min(1), domain: z63.string().min(1) })
24562
+ });
24563
+ var presentReport = (files) => {
24564
+ const snapshotFile = files.get(bundlePaths.snapshot);
24565
+ if (snapshotFile === void 0) {
24566
+ return { outcome: "missing" };
24567
+ }
24568
+ const snapshot = parseDocument(snapshotFile, viewedSnapshotSchema);
24569
+ if (snapshot === void 0) {
24570
+ return {
24571
+ outcome: "unreadable",
24572
+ reason: `${bundlePaths.snapshot} does not match the report contract of this release.`
24573
+ };
24574
+ }
24575
+ const brand = snapshot.brand ?? parseDocument(files.get(bundlePaths.config), configBrandSchema)?.brand;
24576
+ if (brand === void 0) {
24577
+ return {
24578
+ outcome: "unreadable",
24579
+ reason: `Neither ${bundlePaths.snapshot} nor ${bundlePaths.config} names the audited brand.`
24580
+ };
24581
+ }
24582
+ const copy = parseDocument(
24583
+ files.get(bundlePaths.copy),
24584
+ aeoFinalCopyDraftSchema
24585
+ );
24586
+ const captured = parseDocument(
24587
+ files.get(bundlePaths.captures),
24588
+ capturedRecordsSchema
24589
+ );
24590
+ const answers = new Map(
24591
+ (captured ?? []).map((record) => [answerKey(record), record.probe.text])
24592
+ );
24593
+ const { meta } = snapshot;
24594
+ const measuredOn = measurementPeriod(meta);
24595
+ const labelOf = surfaceLabelFor(meta.surfaceLabels ?? {});
24596
+ const visibilities = snapshot.sections.map((s) => s.visibility);
24597
+ const surfaces = [...new Set(visibilities.flatMap((v) => v.surfaces))];
24598
+ const promptCount = meta.promptCount ?? visibilities.reduce((sum, v) => sum + v.prompts.length, 0);
24599
+ const probeCount = meta.probeCount ?? visibilities.reduce((sum, v) => sum + v.matrix.length, 0);
24600
+ const presentation = {
24601
+ outcome: "shown",
24602
+ brand: { name: brand.name, domain: brand.domain },
24603
+ hero: {
24604
+ title: copy?.hero.title.text ?? `How AI engines see ${brand.name}`,
24605
+ subtitle: copy?.hero.subtitle.text ?? defaultSubtitle(brand.name, surfaces, labelOf),
24606
+ measuredOn,
24607
+ probeCount,
24608
+ facts: [
24609
+ `${promptCount} buyer-style prompts`,
24610
+ `${surfaces.length} AI surfaces${surfaces.some(isAgentSurface) ? ", coding agents included" : ""}`,
24611
+ // Only when the bundle holds them: a redaction can withhold them all.
24612
+ ...answers.size > 0 ? ["Raw answers preserved and inspectable"] : []
24613
+ ]
24614
+ },
24615
+ ...copy?.intro[0] !== void 0 && {
24616
+ intro: {
24617
+ heading: `How AI engines see ${brand.name}`,
24618
+ lead: copy.intro[0].text
24619
+ }
24620
+ },
24621
+ sections: snapshot.sections.map(
24622
+ (section) => presentSection(section, {
24623
+ brand,
24624
+ sourceMix: snapshot.sourceMix?.sections.find(
24625
+ (s) => s.key === section.key
24626
+ ),
24627
+ perception: snapshot.perception?.sections.find(
24628
+ (s) => s.key === section.key
24629
+ ),
24630
+ labelOf,
24631
+ answers
24632
+ })
24633
+ ),
24634
+ footer: {
24635
+ baseline: `Measured ${measuredOn}: ${promptCount} prompts, ${probeCount} captured answers across ${listOf(surfaces.map(labelOf))}.`,
24636
+ methodology: meta.methodology ?? [],
24637
+ notes: [
24638
+ ...reusedNote(meta.reusedProbes),
24639
+ ...unanalyzedNote(meta.partialFailures ?? [])
24640
+ ]
24641
+ }
24642
+ };
24643
+ return presentation;
24644
+ };
24645
+ var presentSection = ({ key: key2, visibility }, { brand, sourceMix, perception, labelOf, answers }) => {
24646
+ const alternatives = rankAlternatives(visibility.matrix, brand);
24647
+ const assistantSurfaces = visibility.surfaces.filter(
24648
+ (s) => !isAgentSurface(s)
24649
+ );
24650
+ const agentSurfaces2 = visibility.surfaces.filter(isAgentSurface);
24651
+ const runViewOf = (row, index) => {
24652
+ const answer = row.runIndex === void 0 ? void 0 : answers.get(
24653
+ answerKey({
24654
+ sectionKey: key2,
24655
+ promptText: visibility.prompts[row.promptIdx]?.text ?? "",
24656
+ surface: row.surface,
24657
+ runIndex: row.runIndex
24658
+ })
24659
+ );
24660
+ return presentRun(row, {
24661
+ runNumber: row.runIndex ?? index + 1,
24662
+ label: labelOf(row.surface),
24663
+ answer
24664
+ });
24665
+ };
24666
+ const section = {
24667
+ key: key2,
24668
+ title: reportSectionTitle(key2.replace(/_/g, " ")),
24669
+ scorecards: presentScorecards(visibility, alternatives[0], labelOf),
24670
+ surfaceRates: visibility.surfaces.flatMap((surface) => {
24671
+ const rates = visibility.summary.byModel[surface];
24672
+ const name = labelOf(surface);
24673
+ return rates?.shareOfVoiceEvidence === void 0 ? [] : [
24674
+ {
24675
+ surface: name,
24676
+ shareOfVoice: rateOf(
24677
+ rates.shareOfVoice,
24678
+ rates.shareOfVoiceEvidence,
24679
+ { subject: `${name} share of voice`, counted: "Mentioned" }
24680
+ ),
24681
+ citationRate: rateOf(
24682
+ rates.citationRate,
24683
+ rates.citationRateEvidence,
24684
+ { subject: `${name} citation rate`, counted: "Cited" }
24685
+ )
24686
+ }
24687
+ ];
24688
+ }),
24689
+ matrix: {
24690
+ assistantSurfaces: assistantSurfaces.map(labelOf),
24691
+ agentSurfaces: agentSurfaces2.map(labelOf),
24692
+ rows: visibility.prompts.map((prompt, promptIdx) => ({
24693
+ prompt: prompt.text,
24694
+ category: prompt.category.replace(/_/g, " "),
24695
+ cells: [...assistantSurfaces, ...agentSurfaces2].map(
24696
+ (surface) => presentCell(
24697
+ visibility.matrix.filter(
24698
+ (row) => row.promptIdx === promptIdx && row.surface === surface
24699
+ ).map(runViewOf)
24700
+ )
24701
+ )
24702
+ }))
24703
+ },
24704
+ alternatives: alternatives.slice(0, 10).map((alternative) => {
24705
+ const share = alternative.mentioning / alternative.captured;
24706
+ return { ...alternative, share, percent: percentOf(share) };
24707
+ }),
24708
+ citedDomains: groupCitedDomains(visibility, brand.domain).map((domain) => ({
24709
+ ...domain,
24710
+ urls: domain.urls.map((url) => ({
24711
+ ...url,
24712
+ surfaces: url.surfaces.map(labelOf)
24713
+ }))
24714
+ })),
24715
+ ...sourceMix !== void 0 && {
24716
+ sourceMix: {
24717
+ rows: sourceMix.perSurface.filter(
24718
+ ({ counts }) => sourceCategories.some((category) => counts[category] > 0)
24719
+ ).map(({ surface, counts }) => ({
24720
+ surface: labelOf(surface),
24721
+ counts
24722
+ })),
24723
+ total: sourceMix.total
24724
+ }
24725
+ },
24726
+ ...perception !== void 0 && {
24727
+ perception: {
24728
+ ...perception.sentiment,
24729
+ phrases: groupPhrases(perception.narratives, labelOf)
24730
+ }
24731
+ }
24732
+ };
24733
+ return section;
24734
+ };
24735
+ var presentScorecards = (visibility, topAlternative, labelOf) => {
24736
+ const { summary } = visibility;
24737
+ const namesOf = (family) => listOf(
24738
+ visibility.surfaces.filter((s) => surfaceFamilyOf(s) === family).map(labelOf)
24739
+ );
24740
+ const familyCard = (family, scope, rates) => {
24741
+ if (rates.shareOfVoice === null || rates.shareOfVoice === void 0) {
24742
+ return [];
24743
+ }
24744
+ const headline = rateOf(rates.shareOfVoice, rates.shareOfVoiceEvidence, {
24745
+ subject: `share of voice across ${scope}`,
24746
+ counted: "Mentioned"
24747
+ });
24748
+ const detail = rateOf(rates.citationRate ?? 0, rates.citationRateEvidence, {
24749
+ subject: `citation rate across ${scope}`,
24750
+ counted: "Cited"
24751
+ });
24752
+ const card = {
24753
+ headline: headline.percent,
24754
+ ...headline.interval !== void 0 && {
24755
+ headlineInterval: headline.interval
24756
+ },
24757
+ label: `Share of voice \u2014 ${scope}`,
24758
+ detail: `${detail.percent} citation rate across ${namesOf(family)}`,
24759
+ ...detail.interval !== void 0 && { detailInterval: detail.interval }
24760
+ };
24761
+ return [card];
24762
+ };
24763
+ const cellMentions = /* @__PURE__ */ new Map();
24764
+ for (const row of visibility.matrix) {
24765
+ const cell = `${row.promptIdx}:${row.surface}`;
24766
+ cellMentions.set(
24767
+ cell,
24768
+ (cellMentions.get(cell) ?? false) || row.prospectMentioned
24769
+ );
24770
+ }
24771
+ const absentCells = [...cellMentions.values()].filter(
24772
+ (mentioned) => !mentioned
24773
+ ).length;
24774
+ const scorecards = [
24775
+ ...familyCard("chat", "AI assistants", {
24776
+ shareOfVoice: summary.prospectShareOfVoice,
24777
+ citationRate: summary.prospectCitationRate,
24778
+ shareOfVoiceEvidence: summary.prospectShareOfVoiceEvidence,
24779
+ citationRateEvidence: summary.prospectCitationRateEvidence
24780
+ }),
24781
+ ...familyCard("consumer", "consumer apps", {
24782
+ shareOfVoice: summary.consumerShareOfVoice,
24783
+ citationRate: summary.consumerCitationRate,
24784
+ shareOfVoiceEvidence: summary.consumerShareOfVoiceEvidence,
24785
+ citationRateEvidence: summary.consumerCitationRateEvidence
24786
+ }),
24787
+ ...familyCard("agents", "coding agents", {
24788
+ shareOfVoice: summary.agentShareOfVoice,
24789
+ citationRate: summary.agentCitationRate,
24790
+ shareOfVoiceEvidence: summary.agentShareOfVoiceEvidence,
24791
+ citationRateEvidence: summary.agentCitationRateEvidence
24792
+ }),
24793
+ ...topAlternative === void 0 ? [] : [
24794
+ {
24795
+ headline: percentOf(
24796
+ topAlternative.mentioning / topAlternative.captured
24797
+ ),
24798
+ label: `${topAlternative.name} share of voice`,
24799
+ detail: `Named most often: ${topAlternative.mentioning} of ${topAlternative.captured} captured answers`
24800
+ }
24801
+ ],
24802
+ {
24803
+ headline: `${absentCells}/${cellMentions.size}`,
24804
+ label: "Cells with zero mentions",
24805
+ detail: "Prompts and surfaces where the brand was absent"
24806
+ }
24807
+ ];
24808
+ return scorecards;
24809
+ };
24810
+ var presentRun = (row, {
24811
+ runNumber,
24812
+ label,
24813
+ answer
24814
+ }) => {
24815
+ const mentionedBrands = [
24816
+ ...new Set(
24817
+ (row.mentionedBrands ?? []).map((brand) => brand.domain ?? brand.name)
24818
+ )
24819
+ ];
24820
+ const run = {
24821
+ runNumber,
24822
+ surface: label,
24823
+ ...row.agentCliVersion !== void 0 && {
24824
+ cliVersion: row.agentCliVersion
24825
+ },
24826
+ status: statusOf(row),
24827
+ ...row.usedWebSearch !== void 0 && {
24828
+ retrieval: retrievalOf(row.usedWebSearch)
24829
+ },
24830
+ ...row.contextSnippet !== null && { snippet: row.contextSnippet },
24831
+ ...answer !== void 0 && { answer },
24832
+ mentionedBrands,
24833
+ citedUrls: row.citedUrls ?? []
24834
+ };
24835
+ return run;
24836
+ };
24837
+ var retrievalOf = (usedWebSearch) => {
24838
+ if (usedWebSearch === null) {
24839
+ return "unknown";
24840
+ }
24841
+ return usedWebSearch ? "searched" : "memory";
24842
+ };
24843
+ var statusOf = (row) => {
24844
+ if (row.noOverview) {
24845
+ return "no_overview";
24846
+ }
24847
+ if (!row.prospectMentioned) {
24848
+ return "absent";
24849
+ }
24850
+ return row.prospectPosition === "primary" ? "primary" : "mentioned";
24851
+ };
24852
+ var presentCell = (runs) => {
24853
+ const mentioned = runs.filter(
24854
+ (run) => run.status === "primary" || run.status === "mentioned"
24855
+ ).length;
24856
+ if (runs.length === 0) {
24857
+ return { status: "no_data", mentioned, runs };
24858
+ }
24859
+ if (mentioned === 0) {
24860
+ return { status: "absent", mentioned, runs };
24861
+ }
24862
+ const status = runs.some((run) => run.status === "primary") ? "primary" : "mentioned";
24863
+ return { status, mentioned, runs };
24864
+ };
24865
+ var rateOf = (rate, evidence, {
24866
+ subject,
24867
+ counted
24868
+ }) => {
24869
+ const percent = percentOf(rate);
24870
+ if (evidence === void 0 || evidence.low > evidence.high) {
24871
+ return { percent };
24872
+ }
24873
+ const { low, high } = intervalPercents(evidence);
24874
+ const text = `approx. 95% interval ${low}\u2013${high}%`;
24875
+ const view = {
24876
+ percent,
24877
+ interval: {
24878
+ text,
24879
+ label: `${text} for ${subject}`,
24880
+ counts: `${counted} in ${evidence.count} of ${evidence.planned} planned answers; ${evidence.captured} captured`
24881
+ }
24882
+ };
24883
+ return view;
24884
+ };
24885
+ var groupPhrases = (narratives, labelOf) => {
24886
+ const byPhrase = /* @__PURE__ */ new Map();
24887
+ for (const narrative of narratives) {
24888
+ const text = narrative.phrase.trim();
24889
+ const key2 = text.toLowerCase();
24890
+ if (key2 === "") {
24891
+ continue;
24892
+ }
24893
+ const entry = byPhrase.get(key2) ?? { text, count: 0, surfaces: [] };
24894
+ const surface = labelOf(narrative.surface);
24895
+ entry.count += 1;
24896
+ if (!entry.surfaces.includes(surface)) {
24897
+ entry.surfaces.push(surface);
24898
+ }
24899
+ byPhrase.set(key2, entry);
24900
+ }
24901
+ const phrases = [...byPhrase.values()].sort((a, b) => b.count - a.count).slice(0, 20);
24902
+ return phrases;
24903
+ };
24904
+ var surfaceLabelFor = (runLabels) => (surface) => {
24905
+ return runLabels[surface] ?? surfaceLabels[surface]?.replace(/ \(API\)$/, "") ?? surface;
24906
+ };
24907
+ var defaultSubtitle = (brandName, surfaces, labelOf) => {
24908
+ const assistants = surfaces.filter((s) => !isAgentSurface(s)).map(labelOf);
24909
+ const agents = surfaces.filter(isAgentSurface).map(labelOf);
24910
+ const asked = assistants.length > 0 ? `How often ${listOf(assistants)} mention and cite ${brandName}.` : `How often AI answers mention and cite ${brandName}.`;
24911
+ const subtitle = agents.length > 0 ? `${asked} Plus ${agents.length === 1 ? "one coding agent" : `${agents.length} coding agents`}: ${listOf(agents)}.` : asked;
24912
+ return subtitle;
24913
+ };
24914
+ var measurementPeriod = ({
24915
+ generatedAt,
24916
+ reusedProbes
24917
+ }) => {
24918
+ const generated = formatReportDate(generatedAt);
24919
+ if (reusedProbes === void 0) {
24920
+ return generated;
24921
+ }
24922
+ return reusedProbes.oldestCapturedAt === null ? `by ${generated}` : `${formatReportDate(reusedProbes.oldestCapturedAt)} to ${generated}`;
24923
+ };
24924
+ var reusedNote = (reusedProbes) => {
24925
+ if (reusedProbes === void 0) {
24926
+ return [];
24927
+ }
24928
+ const { count } = reusedProbes;
24929
+ return [
24930
+ `${count} answer${count === 1 ? " was" : "s were"} reused from an earlier capture, not asked again by this run.`
24931
+ ];
24932
+ };
24933
+ var unanalyzedNote = (partialFailures) => {
24934
+ const count = partialFailures.filter(
24935
+ (f) => f.step.startsWith("analysis:search:")
24936
+ ).length;
24937
+ if (count === 0) {
24938
+ return [];
24939
+ }
24940
+ return [
24941
+ `${count} prompt${count === 1 ? "" : "s"} could not be analyzed in this run and show${count === 1 ? "s" : ""} as no data.`
24942
+ ];
24943
+ };
24944
+ var answerKey = ({
24945
+ sectionKey,
24946
+ promptText,
24947
+ surface,
24948
+ runIndex
24949
+ }) => {
24950
+ return JSON.stringify([sectionKey, promptText, surface, runIndex]);
24951
+ };
24952
+ var percentOf = (share) => {
24953
+ return `${(share * 100).toFixed(0)}%`;
24954
+ };
24955
+ var listOf = (names) => {
24956
+ const unique = [...new Set(names)];
24957
+ if (unique.length <= 1) {
24958
+ return unique[0] ?? "the measured surfaces";
24959
+ }
24960
+ return `${unique.slice(0, -1).join(", ")} and ${unique.at(-1) ?? ""}`;
24961
+ };
24962
+ var parseDocument = (file, schema) => {
24963
+ if (file === void 0) {
24964
+ return void 0;
24965
+ }
24966
+ try {
24967
+ const parsed = schema.safeParse(parseBundleJson(file.toString("utf8")));
24968
+ return parsed.success ? parsed.data : void 0;
24969
+ } catch {
24970
+ return void 0;
24971
+ }
24972
+ };
24973
+
23961
24974
  // src/viewer/server.ts
23962
24975
  var originLabels = {
23963
24976
  [RunOrigin.LOCAL]: "Run locally by the report owner",
23964
24977
  [RunOrigin.HOSTED]: "Run by Literally.dev",
23965
24978
  [RunOrigin.LEGACY_IMPORT]: "Imported from a run without an execution trace"
23966
24979
  };
23967
- var manifestOriginSchema = z63.looseObject({
23968
- run: z63.looseObject({ origin: z63.string() })
24980
+ var manifestOriginSchema = z64.looseObject({
24981
+ run: z64.looseObject({ origin: z64.string() })
23969
24982
  });
23970
24983
  var sameToken = (expected, received) => {
23971
24984
  if (received === null) {
@@ -24012,10 +25025,11 @@ var derivedDocuments = (bundle) => {
24012
25025
  originLabel: origin === void 0 ? "Run locally by the report owner" : originLabels[origin] ?? "Origin unknown"
24013
25026
  }
24014
25027
  ],
24015
- ["__verification", bundle.workingState ? null : verification]
25028
+ ["__verification", bundle.workingState ? null : verification],
25029
+ ["__report", presentReport(bundle.files)]
24016
25030
  ]);
24017
25031
  };
24018
- var startViewer = async (bundle, { port = 0 } = {}) => {
25032
+ var startViewer = async (bundle, { port = 0, fonts = /* @__PURE__ */ new Map() } = {}) => {
24019
25033
  const token = randomBytes2(32).toString("hex");
24020
25034
  const derived = derivedDocuments(bundle);
24021
25035
  let host = "";
@@ -24033,12 +25047,17 @@ var startViewer = async (bundle, { port = 0 } = {}) => {
24033
25047
  const nonce = randomBytes2(16).toString("base64");
24034
25048
  send(response, {
24035
25049
  status: 200,
24036
- body: viewerPage(nonce),
25050
+ body: viewerPage(nonce, fonts.size > 0 ? token : void 0),
24037
25051
  contentType: "text/html; charset=utf-8",
24038
- csp: `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'nonce-${nonce}'; connect-src 'self'; img-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`
25052
+ csp: `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'nonce-${nonce}'; font-src 'self'; connect-src 'self'; img-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`
24039
25053
  });
24040
25054
  return;
24041
25055
  }
25056
+ const font = url.pathname.startsWith("/fonts/") ? fonts.get(url.pathname.slice("/fonts/".length)) : void 0;
25057
+ if (font !== void 0) {
25058
+ send(response, { status: 200, body: font, contentType: "font/ttf" });
25059
+ return;
25060
+ }
24042
25061
  const file = decodeURIComponent(url.pathname.replace(/^\/data\//, ""));
24043
25062
  const derivedDocument = derived.get(file);
24044
25063
  if (url.pathname.startsWith("/data/") && derivedDocument !== void 0) {
@@ -24188,10 +25207,10 @@ var runExport = async (flags, usage) => {
24188
25207
  if (dir === void 0) {
24189
25208
  throw new Error(usage);
24190
25209
  }
24191
- if (await runDirectoryState(path32.resolve(dir)) === "new") {
25210
+ if (await runDirectoryState(path34.resolve(dir)) === "new") {
24192
25211
  writeErr(
24193
25212
  [
24194
- `${path32.resolve(dir)} holds no run to export (it has no INPUTS.json).`,
25213
+ `${path34.resolve(dir)} holds no run to export (it has no INPUTS.json).`,
24195
25214
  ` A local run: measure first with literally-aeo run --output ${dir}`,
24196
25215
  ` A hosted work directory from before INPUTS.json: pnpm aeo:codex prepare --report <reportKey> --workdir ${dir}`
24197
25216
  ].join("\n")
@@ -24200,7 +25219,7 @@ var runExport = async (flags, usage) => {
24200
25219
  }
24201
25220
  const settings = await readSettings(flags.options.get("--env-file"));
24202
25221
  const redactFile = flags.options.get("--redact");
24203
- const redactions = redactFile ? await readRedactions(path32.resolve(redactFile)) : void 0;
25222
+ const redactions = redactFile ? await readRedactions(path34.resolve(redactFile)) : void 0;
24204
25223
  try {
24205
25224
  const result = await exportRun(dir, {
24206
25225
  output: flags.options.get("--output"),
@@ -24261,7 +25280,7 @@ var runVerify = async (flags, usage) => {
24261
25280
  writeErr(err.message);
24262
25281
  return 1;
24263
25282
  }
24264
- verification = refusedVerification(path32.resolve(target), {
25283
+ verification = refusedVerification(path34.resolve(target), {
24265
25284
  id: "bundle.integrity",
24266
25285
  title: "Bundle integrity",
24267
25286
  outcome: "fail",
@@ -24275,12 +25294,26 @@ var runVerify = async (flags, usage) => {
24275
25294
  );
24276
25295
  return verification.exitCode;
24277
25296
  };
25297
+ var readViewerFonts = async () => {
25298
+ const { fonts } = await engineResources();
25299
+ const entries = await Promise.all(
25300
+ Object.values(viewerFontFiles).map(
25301
+ async (file) => [file, await readFile29(path34.join(fonts, file))]
25302
+ )
25303
+ ).catch((err) => {
25304
+ throw new Error(
25305
+ `The viewer's fonts are missing from ${fonts}. In a checkout, run pnpm build to refresh resources/; otherwise reinstall literally-aeo.`,
25306
+ { cause: err }
25307
+ );
25308
+ });
25309
+ return new Map(entries);
25310
+ };
24278
25311
  var runView = async (flags, usage) => {
24279
25312
  const target = flags.positional[0];
24280
25313
  if (target === void 0) {
24281
25314
  throw new Error(usage);
24282
25315
  }
24283
- const resolved = path32.resolve(target);
25316
+ const resolved = path34.resolve(target);
24284
25317
  const revisions = await readFinalizedRevisions(resolved).catch(() => []);
24285
25318
  const isRunDirectory = await runDirectoryState(resolved).then(
24286
25319
  (state) => state !== "new",
@@ -24294,7 +25327,8 @@ var runView = async (flags, usage) => {
24294
25327
  } : { ...await readBundleSource(resolved), workingState: false };
24295
25328
  const portOption = flags.options.get("--port");
24296
25329
  const viewer = await startViewer(bundle, {
24297
- port: portOption === void 0 ? 0 : Number(portOption)
25330
+ port: portOption === void 0 ? 0 : Number(portOption),
25331
+ fonts: await readViewerFonts()
24298
25332
  });
24299
25333
  writeOut(
24300
25334
  flags.switches.has("--json") ? JSON.stringify({ resultVersion: 1, command: "view", url: viewer.url }) : `Viewing ${bundle.description}
@@ -24310,72 +25344,10 @@ Press Ctrl-C to stop.`
24310
25344
  };
24311
25345
 
24312
25346
  // src/cli/guide-command.ts
24313
- import { readFile as readFile29 } from "node:fs/promises";
24314
-
24315
- // src/engine/resources.ts
24316
- import { access as access2 } from "node:fs/promises";
24317
- import path34 from "node:path";
24318
-
24319
- // src/engine/package-root.ts
24320
- import { readFileSync as readFileSync2 } from "node:fs";
24321
- import path33 from "node:path";
24322
- import { fileURLToPath } from "node:url";
24323
- var enginePackageName = "literally-aeo";
24324
- var isEngineManifest = (file) => {
24325
- try {
24326
- const manifest = JSON.parse(readFileSync2(file, "utf8"));
24327
- return typeof manifest === "object" && manifest !== null && "name" in manifest && manifest.name === enginePackageName;
24328
- } catch {
24329
- return false;
24330
- }
24331
- };
24332
- var enginePackageRoot = () => {
24333
- const start = path33.dirname(fileURLToPath(import.meta.url));
24334
- let dir = start;
24335
- for (; ; ) {
24336
- if (isEngineManifest(path33.join(dir, "package.json"))) {
24337
- return dir;
24338
- }
24339
- const parent = path33.dirname(dir);
24340
- if (parent === dir) {
24341
- throw new Error(
24342
- `No ${enginePackageName} package.json above ${start}; the engine runs from its own package.`
24343
- );
24344
- }
24345
- dir = parent;
24346
- }
24347
- };
24348
-
24349
- // src/engine/resources.ts
24350
- var exists = async (file) => {
24351
- return access2(file).then(
24352
- () => true,
24353
- () => false
24354
- );
24355
- };
24356
- var engineResources = async () => {
24357
- const root = enginePackageRoot();
24358
- const packed = path34.join(root, "resources");
24359
- if (await exists(path34.join(packed, "author", "COPY_RULES.md"))) {
24360
- return {
24361
- root,
24362
- author: path34.join(packed, "author"),
24363
- editorial: path34.join(packed, "editorial"),
24364
- guide: path34.join(packed, "guide", "OPERATOR.md")
24365
- };
24366
- }
24367
- return {
24368
- root,
24369
- author: path34.join(root, "src", "author"),
24370
- editorial: path34.join(root, "src", "engine", "editorial"),
24371
- guide: path34.join(root, "src", "engine", "guide", "OPERATOR.md")
24372
- };
24373
- };
24374
-
24375
- // src/cli/guide-command.ts
25347
+ import { readFile as readFile30 } from "node:fs/promises";
24376
25348
  var readOperatorGuide = async () => {
24377
25349
  const { guide } = await engineResources();
24378
- return readFile29(guide, "utf8");
25350
+ return readFile30(guide, "utf8");
24379
25351
  };
24380
25352
  var runGuide = async (flags) => {
24381
25353
  const guide = await readOperatorGuide();
@@ -24390,34 +25362,34 @@ import { writeFile as writeFile23 } from "node:fs/promises";
24390
25362
  import path48 from "node:path";
24391
25363
 
24392
25364
  // src/codex-workflow/loop.ts
24393
- import { mkdir as mkdir20, readFile as readFile40, writeFile as writeFile20 } from "node:fs/promises";
25365
+ import { mkdir as mkdir20, readFile as readFile41, writeFile as writeFile20 } from "node:fs/promises";
24394
25366
  import path45 from "node:path";
24395
- import { z as z74 } from "zod";
25367
+ import { z as z75 } from "zod";
24396
25368
 
24397
25369
  // src/agents/verifier.ts
24398
- import { z as z64 } from "zod";
24399
- var verdictSchema = z64.object({
24400
- reviews: z64.array(
24401
- z64.object({
24402
- path: z64.string(),
25370
+ import { z as z65 } from "zod";
25371
+ var verdictSchema = z65.object({
25372
+ reviews: z65.array(
25373
+ z65.object({
25374
+ path: z65.string(),
24403
25375
  /** The verdict itself. The premise findings and the flag must
24404
25376
  * agree, and only the flag lets `errors` reject a block: a
24405
25377
  * passing review may still carry stray text there: a measured
24406
25378
  * model wrote "None found." and "none" into `errors` for blocks
24407
25379
  * it had approved, and each cost a copy generation. */
24408
- passed: z64.boolean(),
24409
- allPremisesCovered: z64.boolean(),
24410
- actionAppropriate: z64.boolean(),
24411
- premises: z64.array(
24412
- z64.object({
24413
- proposition: z64.string().min(1),
24414
- declaredPremiseIndex: z64.number().int().nonnegative().nullable(),
24415
- basisFactIds: z64.array(z64.string()),
24416
- supported: z64.boolean(),
24417
- relevant: z64.boolean()
25380
+ passed: z65.boolean(),
25381
+ allPremisesCovered: z65.boolean(),
25382
+ actionAppropriate: z65.boolean(),
25383
+ premises: z65.array(
25384
+ z65.object({
25385
+ proposition: z65.string().min(1),
25386
+ declaredPremiseIndex: z65.number().int().nonnegative().nullable(),
25387
+ basisFactIds: z65.array(z65.string()),
25388
+ supported: z65.boolean(),
25389
+ relevant: z65.boolean()
24418
25390
  }).strict()
24419
25391
  ).max(40),
24420
- errors: z64.array(z64.string()).max(20)
25392
+ errors: z65.array(z65.string()).max(20)
24421
25393
  }).strict()
24422
25394
  ).max(200)
24423
25395
  }).strict();
@@ -24437,14 +25409,14 @@ ${rateComparison.id}: ${rateComparison.guidance} A narrative that breaks this fa
24437
25409
  var verdictSchemaFor = (paths, factIds) => {
24438
25410
  const enumOf = (values) => {
24439
25411
  const [first, ...rest] = values;
24440
- return first === void 0 ? z64.string().min(1) : z64.enum([first, ...rest]);
25412
+ return first === void 0 ? z65.string().min(1) : z65.enum([first, ...rest]);
24441
25413
  };
24442
25414
  const review2 = verdictSchema.shape.reviews.element;
24443
- return z64.object({
24444
- reviews: z64.array(
25415
+ return z65.object({
25416
+ reviews: z65.array(
24445
25417
  review2.extend({
24446
25418
  path: enumOf(paths),
24447
- premises: review2.shape.premises.element.extend({ basisFactIds: z64.array(enumOf(factIds)) }).array().max(40)
25419
+ premises: review2.shape.premises.element.extend({ basisFactIds: z65.array(enumOf(factIds)) }).array().max(40)
24448
25420
  })
24449
25421
  ).min(1).max(Math.max(1, paths.length))
24450
25422
  });
@@ -24722,28 +25694,28 @@ var verifierChunks = (recommendations, profile, context = {}) => {
24722
25694
  };
24723
25695
 
24724
25696
  // src/codex-workflow/copy-recovery.ts
24725
- import { z as z66 } from "zod";
25697
+ import { z as z67 } from "zod";
24726
25698
 
24727
25699
  // src/codex-workflow/quality.ts
24728
- import { readFile as readFile30 } from "node:fs/promises";
25700
+ import { readFile as readFile31 } from "node:fs/promises";
24729
25701
  import path35 from "node:path";
24730
- import { z as z65 } from "zod";
24731
- var storedReviewSchema = z65.looseObject({
24732
- criteria: z65.array(
24733
- z65.looseObject({ criterionId: z65.string(), outcome: z65.string() })
25702
+ import { z as z66 } from "zod";
25703
+ var storedReviewSchema = z66.looseObject({
25704
+ criteria: z66.array(
25705
+ z66.looseObject({ criterionId: z66.string(), outcome: z66.string() })
24734
25706
  ),
24735
- unresolved: z65.array(
24736
- z65.looseObject({
24737
- criterionId: z65.string(),
24738
- stage: z65.string(),
24739
- file: z65.string().nullable(),
24740
- problem: z65.string(),
24741
- evidence: z65.string()
25707
+ unresolved: z66.array(
25708
+ z66.looseObject({
25709
+ criterionId: z66.string(),
25710
+ stage: z66.string(),
25711
+ file: z66.string().nullable(),
25712
+ problem: z66.string(),
25713
+ evidence: z66.string()
24742
25714
  })
24743
25715
  )
24744
25716
  });
24745
25717
  var readStoredReview = async (dir) => {
24746
- const raw = await readFile30(path35.join(dir, "OUT", "review.json"), "utf8").catch(
25718
+ const raw = await readFile31(path35.join(dir, "OUT", "review.json"), "utf8").catch(
24747
25719
  () => "null"
24748
25720
  ) || "null";
24749
25721
  const review2 = storedReviewSchema.nullable().parse(JSON.parse(raw));
@@ -24791,9 +25763,9 @@ var reportQuality = async (dir, { rounds, degraded, accepted }) => {
24791
25763
  };
24792
25764
 
24793
25765
  // src/codex-workflow/copy-recovery.ts
24794
- var legacyRefusal = z66.object({
24795
- attempt: z66.number().int(),
24796
- errors: z66.array(z66.string())
25766
+ var legacyRefusal = z67.object({
25767
+ attempt: z67.number().int(),
25768
+ errors: z67.array(z67.string())
24797
25769
  });
24798
25770
  var operationalErrors = (errors) => {
24799
25771
  return errors.length > 0 && errors.every(
@@ -24840,19 +25812,19 @@ var CopyVerificationUnavailableError = class extends Error {
24840
25812
  this.errors = errors;
24841
25813
  }
24842
25814
  };
24843
- var windowSchema = z66.object({
24844
- passId: z66.string(),
24845
- startedAt: z66.iso.datetime(),
24846
- deadlineAt: z66.iso.datetime()
25815
+ var windowSchema = z67.object({
25816
+ passId: z67.string(),
25817
+ startedAt: z67.iso.datetime(),
25818
+ deadlineAt: z67.iso.datetime()
24847
25819
  }).strict();
24848
25820
 
24849
25821
  // src/codex-workflow/copy-editor.ts
24850
- import { readFile as readFile32 } from "node:fs/promises";
25822
+ import { readFile as readFile33 } from "node:fs/promises";
24851
25823
  import path37 from "node:path";
24852
- import { z as z67 } from "zod";
25824
+ import { z as z68 } from "zod";
24853
25825
 
24854
25826
  // src/codex-workflow/copy.ts
24855
- import { mkdir as mkdir15, readFile as readFile31, writeFile as writeFile13 } from "node:fs/promises";
25827
+ import { mkdir as mkdir15, readFile as readFile32, writeFile as writeFile13 } from "node:fs/promises";
24856
25828
  import path36 from "node:path";
24857
25829
 
24858
25830
  // src/agents/copywriter-input.ts
@@ -24925,11 +25897,11 @@ var authorDir = async (env = getEnvironment()) => {
24925
25897
  var copywriterFiles = async (env = getEnvironment()) => {
24926
25898
  const { author: author2, company } = await authorDir(env);
24927
25899
  const files = {
24928
- "RULES.md": await readFile31(path36.join(author2, "COPY_RULES.md"), "utf8"),
24929
- "banlist.json": await readFile31(path36.join(author2, "banlist.json"), "utf8")
25900
+ "RULES.md": await readFile32(path36.join(author2, "COPY_RULES.md"), "utf8"),
25901
+ "banlist.json": await readFile32(path36.join(author2, "banlist.json"), "utf8")
24930
25902
  };
24931
25903
  for (const file of ["COMPANY", "positioning", "services"]) {
24932
- files[`company/${file}.md`] = await readFile31(
25904
+ files[`company/${file}.md`] = await readFile32(
24933
25905
  path36.join(company, `${file}.md`),
24934
25906
  "utf8"
24935
25907
  );
@@ -24937,7 +25909,7 @@ var copywriterFiles = async (env = getEnvironment()) => {
24937
25909
  return files;
24938
25910
  };
24939
25911
  var readSnapshot = async (dir) => {
24940
- const raw = await readFile31(
25912
+ const raw = await readFile32(
24941
25913
  path36.join(dir, "OUT", "snapshot.json"),
24942
25914
  "utf8"
24943
25915
  ).catch(() => null);
@@ -24990,7 +25962,7 @@ var readCopyDocuments = async (dir, files) => {
24990
25962
  const entries = await Promise.all(
24991
25963
  files.map(async (file) => {
24992
25964
  const name = path36.posix.relative(copyDir, file);
24993
- return [name, await readFile31(path36.join(dir, file), "utf8")];
25965
+ return [name, await readFile32(path36.join(dir, file), "utf8")];
24994
25966
  })
24995
25967
  );
24996
25968
  return Object.fromEntries(entries);
@@ -25216,21 +26188,21 @@ This is your editing turn: return only the complete edited draft required by the
25216
26188
  }
25217
26189
  return { ...call(), trimmed };
25218
26190
  };
25219
- var savedCopyEditsSchema = z67.object({
25220
- scope: z67.string(),
25221
- edits: z67.array(
25222
- z67.object({
25223
- inputDigest: z67.string(),
25224
- draft: z67.unknown().optional(),
25225
- round: z67.number(),
25226
- errors: z67.array(z67.string()),
26191
+ var savedCopyEditsSchema = z68.object({
26192
+ scope: z68.string(),
26193
+ edits: z68.array(
26194
+ z68.object({
26195
+ inputDigest: z68.string(),
26196
+ draft: z68.unknown().optional(),
26197
+ round: z68.number(),
26198
+ errors: z68.array(z68.string()),
25227
26199
  editedDraft: writeOutputSchema,
25228
- trimmed: z67.array(z67.string()).optional()
26200
+ trimmed: z68.array(z68.string()).optional()
25229
26201
  })
25230
26202
  )
25231
26203
  }).nullable();
25232
26204
  var readCopyEdits = async (dir, scope) => {
25233
- const raw = await readFile32(
26205
+ const raw = await readFile33(
25234
26206
  path37.join(dir, "PENDING/copy-edits.json"),
25235
26207
  "utf8"
25236
26208
  ).catch(() => "null");
@@ -25306,9 +26278,9 @@ var editCopyDraft = async (args) => {
25306
26278
 
25307
26279
  // src/codex-workflow/finish.ts
25308
26280
  import { createHash as createHash9 } from "node:crypto";
25309
- import { readFile as readFile33, writeFile as writeFile14 } from "node:fs/promises";
26281
+ import { readFile as readFile34, writeFile as writeFile14 } from "node:fs/promises";
25310
26282
  import path38 from "node:path";
25311
- import { z as z68 } from "zod";
26283
+ import { z as z69 } from "zod";
25312
26284
 
25313
26285
  // src/agents/methodology.ts
25314
26286
  var maxNamedModels = 3;
@@ -25416,7 +26388,7 @@ var codexAnalyzer = (model) => {
25416
26388
  var finishRun = async (args) => {
25417
26389
  const { source, dir, signal } = args;
25418
26390
  const { config, request: request2, plan } = source;
25419
- const aggregateText = await readFile33(
26391
+ const aggregateText = await readFile34(
25420
26392
  path38.join(dir, "OUT", "aggregate.json"),
25421
26393
  "utf8"
25422
26394
  );
@@ -25638,7 +26610,7 @@ var isGroundingBundle = (value) => {
25638
26610
  };
25639
26611
  var reuseFinish = async (dir, digest5, aggregate2) => {
25640
26612
  const out = (name) => {
25641
- return readFile33(path38.join(dir, "OUT", name), "utf8");
26613
+ return readFile34(path38.join(dir, "OUT", name), "utf8");
25642
26614
  };
25643
26615
  const recorded2 = await out("finish.inputs.sha").catch(() => null);
25644
26616
  if (recorded2?.trim() !== digest5) {
@@ -25654,9 +26626,9 @@ var reuseFinish = async (dir, digest5, aggregate2) => {
25654
26626
  const captureManifest = captureManifestSchema.parse(
25655
26627
  JSON.parse(await out("capture-manifest.json"))
25656
26628
  );
25657
- const partialFailures = z68.array(partialFailureSchema).parse(JSON.parse(await out("partial-failures.json")));
26629
+ const partialFailures = z69.array(partialFailureSchema).parse(JSON.parse(await out("partial-failures.json")));
25658
26630
  const grounding = JSON.parse(await out("grounding.json"));
25659
- const labelStats = z68.record(z68.string(), z68.number()).parse(JSON.parse(await out("label-stats.json")));
26631
+ const labelStats = z69.record(z69.string(), z69.number()).parse(JSON.parse(await out("label-stats.json")));
25660
26632
  if (grounding !== null && !isGroundingBundle(grounding)) {
25661
26633
  throw new Error("OUT/grounding.json is not a grounding bundle.");
25662
26634
  }
@@ -25711,14 +26683,14 @@ import {
25711
26683
  appendFile as appendFile2,
25712
26684
  mkdir as mkdir18,
25713
26685
  readdir as readdir7,
25714
- readFile as readFile38,
26686
+ readFile as readFile39,
25715
26687
  rename as rename10,
25716
26688
  rm as rm9,
25717
26689
  writeFile as writeFile18
25718
26690
  } from "node:fs/promises";
25719
26691
  import path43 from "node:path";
25720
26692
  import { setTimeout as delay3 } from "node:timers/promises";
25721
- import { z as z72 } from "zod";
26693
+ import { z as z73 } from "zod";
25722
26694
 
25723
26695
  // src/models/pricing.ts
25724
26696
  var tokenCostUsd = (pricing, usage) => {
@@ -25733,7 +26705,7 @@ import {
25733
26705
  access as access3,
25734
26706
  mkdir as mkdir17,
25735
26707
  readdir as readdir6,
25736
- readFile as readFile35,
26708
+ readFile as readFile36,
25737
26709
  rm as rm7,
25738
26710
  writeFile as writeFile16
25739
26711
  } from "node:fs/promises";
@@ -26229,9 +27201,9 @@ var authorExamples = (names = authorExampleNames) => {
26229
27201
  };
26230
27202
 
26231
27203
  // src/codex-workflow/author-tools.ts
26232
- import { appendFile, mkdir as mkdir16, readFile as readFile34, writeFile as writeFile15 } from "node:fs/promises";
27204
+ import { appendFile, mkdir as mkdir16, readFile as readFile35, writeFile as writeFile15 } from "node:fs/promises";
26233
27205
  import path39 from "node:path";
26234
- import { z as z69 } from "zod";
27206
+ import { z as z70 } from "zod";
26235
27207
  var researchDir = "RESEARCH";
26236
27208
  var authorToolCaps = {
26237
27209
  search: 20,
@@ -26244,59 +27216,59 @@ var authorToolCaps = {
26244
27216
  pageTextBytes: 32 * 1024,
26245
27217
  links: 100
26246
27218
  };
26247
- var researchIndexSchema = z69.object({
26248
- next: z69.number(),
26249
- byUrl: z69.record(
26250
- z69.string(),
26251
- z69.object({ n: z69.number(), kind: z69.enum(["fetch", "render"]) })
27219
+ var researchIndexSchema = z70.object({
27220
+ next: z70.number(),
27221
+ byUrl: z70.record(
27222
+ z70.string(),
27223
+ z70.object({ n: z70.number(), kind: z70.enum(["fetch", "render"]) })
26252
27224
  )
26253
27225
  });
26254
- var researchJournalEntrySchema = z69.object({
26255
- at: z69.string(),
26256
- tool: z69.string(),
26257
- args: z69.record(z69.string(), z69.unknown()),
26258
- outcome: z69.enum(["ok", "refused", "error"]),
26259
- reason: z69.string().optional(),
26260
- elapsedMs: z69.number(),
26261
- bytes: z69.number().optional(),
26262
- costUsd: z69.number().nullable().optional(),
26263
- provider: z69.string().optional(),
26264
- path: z69.string().optional(),
26265
- urls: z69.array(z69.string()).optional(),
26266
- cached: z69.boolean().optional()
27226
+ var researchJournalEntrySchema = z70.object({
27227
+ at: z70.string(),
27228
+ tool: z70.string(),
27229
+ args: z70.record(z70.string(), z70.unknown()),
27230
+ outcome: z70.enum(["ok", "refused", "error"]),
27231
+ reason: z70.string().optional(),
27232
+ elapsedMs: z70.number(),
27233
+ bytes: z70.number().optional(),
27234
+ costUsd: z70.number().nullable().optional(),
27235
+ provider: z70.string().optional(),
27236
+ path: z70.string().optional(),
27237
+ urls: z70.array(z70.string()).optional(),
27238
+ cached: z70.boolean().optional()
26267
27239
  });
26268
27240
  var isGroundingSource = (value) => {
26269
27241
  return groundingSourceSchema.safeParse(value).success;
26270
27242
  };
26271
- var searchArgs = z69.object({
26272
- query: z69.string().trim().min(1).max(300),
26273
- purpose: z69.string().trim().min(1).max(300)
27243
+ var searchArgs = z70.object({
27244
+ query: z70.string().trim().min(1).max(300),
27245
+ purpose: z70.string().trim().min(1).max(300)
26274
27246
  }).strict();
26275
- var urlArgs = z69.object({ url: z69.string().trim().min(1).max(4096) }).strict();
26276
- var submitArgs = z69.object({ config: z69.unknown(), notes: z69.unknown() }).strict();
27247
+ var urlArgs = z70.object({ url: z70.string().trim().min(1).max(4096) }).strict();
27248
+ var submitArgs = z70.object({ config: z70.unknown(), notes: z70.unknown() }).strict();
26277
27249
  var researchToolDefinitions = [
26278
27250
  {
26279
27251
  name: "search",
26280
27252
  description: "Web search. Returns up to 10 results with url, title and a short snippet; fetch a result to read it. Say what you are trying to find in purpose; it is journaled for the reviewer. Capped per session.",
26281
- inputSchema: z69.toJSONSchema(searchArgs),
27253
+ inputSchema: z70.toJSONSchema(searchArgs),
26282
27254
  annotations: { readOnlyHint: true, openWorldHint: true }
26283
27255
  },
26284
27256
  {
26285
27257
  name: "fetch",
26286
27258
  description: "Fetch a public HTTPS page without JavaScript. Returns the extracted text (up to 32 KB), the links on the page, and the RESEARCH/ path the page was saved under: cite that path in notes.reasons and the url in proposedFacts.sourceUrls. A page already fetched is returned from the saved copy. Capped per session and per host.",
26287
- inputSchema: z69.toJSONSchema(urlArgs),
27259
+ inputSchema: z70.toJSONSchema(urlArgs),
26288
27260
  annotations: { readOnlyHint: true, openWorldHint: true }
26289
27261
  },
26290
27262
  {
26291
27263
  name: "render",
26292
27264
  description: "Fetch a page with a headless browser, for pages that return little text without JavaScript. Same result shape as fetch. Small cap per session: use it only when fetch returned too little.",
26293
- inputSchema: z69.toJSONSchema(urlArgs),
27265
+ inputSchema: z70.toJSONSchema(urlArgs),
26294
27266
  annotations: { readOnlyHint: true, openWorldHint: true }
26295
27267
  },
26296
27268
  {
26297
27269
  name: "submit",
26298
27270
  description: 'Submit the config and the notes. Both are checked against the schema; on success the output file is written and the result is {"ok":true}. On errors, nothing is written and the errors are returned: fix them and submit again. Every call replaces the previous submission. Pass config and notes as JSON objects; a JSON string holding the object is decoded too, so do not retry a call because of how it was serialized.',
26299
- inputSchema: z69.toJSONSchema(submitArgs)
27271
+ inputSchema: z70.toJSONSchema(submitArgs)
26300
27272
  }
26301
27273
  ];
26302
27274
  var researchDocumentPath = (n) => {
@@ -26325,7 +27297,7 @@ var parseResearchDocument = (content) => {
26325
27297
  };
26326
27298
  };
26327
27299
  var readIndex = async (dir) => {
26328
- const raw = await readFile34(
27300
+ const raw = await readFile35(
26329
27301
  path39.join(dir, researchDir, "INDEX.json"),
26330
27302
  "utf8"
26331
27303
  ).catch(() => null);
@@ -26335,7 +27307,7 @@ var readIndex = async (dir) => {
26335
27307
  return researchIndexSchema.parse(JSON.parse(raw));
26336
27308
  };
26337
27309
  var readResearchJournal = async (dir, label) => {
26338
- const raw = await readFile34(
27310
+ const raw = await readFile35(
26339
27311
  path39.join(dir, "JOURNAL", `${label}.research.jsonl`),
26340
27312
  "utf8"
26341
27313
  ).catch(() => "");
@@ -26350,7 +27322,7 @@ var readResearchDocuments = async (dir) => {
26350
27322
  continue;
26351
27323
  }
26352
27324
  seen.add(n);
26353
- const content = await readFile34(
27325
+ const content = await readFile35(
26354
27326
  path39.join(dir, researchDocumentPath(n)),
26355
27327
  "utf8"
26356
27328
  ).catch(() => null);
@@ -26359,7 +27331,7 @@ var readResearchDocuments = async (dir) => {
26359
27331
  continue;
26360
27332
  }
26361
27333
  const savedSource = JSON.parse(
26362
- await readFile34(path39.join(dir, researchSourcePath(n)), "utf8").catch(
27334
+ await readFile35(path39.join(dir, researchSourcePath(n)), "utf8").catch(
26363
27335
  () => "null"
26364
27336
  )
26365
27337
  );
@@ -26464,11 +27436,11 @@ var materializeAuthorWorkdir = async (args) => {
26464
27436
  await writeFile16(path40.join(base, "BRIEF.md"), briefDocument(args.brief));
26465
27437
  await writeFile16(
26466
27438
  path40.join(base, "RULES.md"),
26467
- await readFile35(path40.join(author2, "RULES.md"), "utf8")
27439
+ await readFile36(path40.join(author2, "RULES.md"), "utf8")
26468
27440
  );
26469
27441
  await writeFile16(
26470
27442
  path40.join(base, "banlist.json"),
26471
- await readFile35(path40.join(author2, "banlist.json"), "utf8")
27443
+ await readFile36(path40.join(author2, "banlist.json"), "utf8")
26472
27444
  );
26473
27445
  await writeFile16(
26474
27446
  path40.join(base, "SCHEMA.json"),
@@ -26521,7 +27493,7 @@ var authorPacket = async (args) => {
26521
27493
  if (args.continuation && !file.startsWith(`${authorWorkDir}/PREVIOUS/`)) {
26522
27494
  continue;
26523
27495
  }
26524
- const content = await readFile35(path40.join(args.dir, file), "utf8");
27496
+ const content = await readFile36(path40.join(args.dir, file), "utf8");
26525
27497
  files[file] = file.endsWith(".json") ? JSON.parse(content) : content;
26526
27498
  }
26527
27499
  return JSON.stringify({
@@ -26581,7 +27553,7 @@ var researchServerConfig = async (dir, env = getEnvironment()) => {
26581
27553
  };
26582
27554
  };
26583
27555
  var readAuthorOutput = async (dir) => {
26584
- const raw = await readFile35(path40.join(dir, authorOutputFile), "utf8").catch(
27556
+ const raw = await readFile36(path40.join(dir, authorOutputFile), "utf8").catch(
26585
27557
  () => null
26586
27558
  );
26587
27559
  if (raw === null) {
@@ -26633,15 +27605,15 @@ var validateAuthorStage = async (args) => {
26633
27605
  };
26634
27606
 
26635
27607
  // src/codex-workflow/session.ts
26636
- import { readFile as readFile36, rm as rm8, writeFile as writeFile17 } from "node:fs/promises";
27608
+ import { readFile as readFile37, rm as rm8, writeFile as writeFile17 } from "node:fs/promises";
26637
27609
  import path41 from "node:path";
26638
- import { z as z70 } from "zod";
26639
- var savedSessionSchema = z70.looseObject({
26640
- contract: z70.string(),
26641
- threadId: z70.string()
27610
+ import { z as z71 } from "zod";
27611
+ var savedSessionSchema = z71.looseObject({
27612
+ contract: z71.string(),
27613
+ threadId: z71.string()
26642
27614
  });
26643
27615
  var readSession = async (dir, { label, contract }) => {
26644
- const raw = await readFile36(
27616
+ const raw = await readFile37(
26645
27617
  path41.join(dir, "JOURNAL", `${label}.session.json`),
26646
27618
  "utf8"
26647
27619
  ).catch(() => null);
@@ -26731,23 +27703,23 @@ var reserveWhenAffordable = async (ledger, reserve, signal) => {
26731
27703
  };
26732
27704
 
26733
27705
  // src/codex-workflow/batch-input.ts
26734
- import { readFile as readFile37 } from "node:fs/promises";
27706
+ import { readFile as readFile38 } from "node:fs/promises";
26735
27707
  import path42 from "node:path";
26736
- import { z as z71 } from "zod";
26737
- var trailEntrySchema = z71.looseObject({
26738
- by: z71.string(),
26739
- at: z71.string(),
26740
- outcome: z71.string(),
26741
- stage: z71.string(),
26742
- file: z71.string(),
26743
- field: z71.string(),
26744
- to: z71.string()
27708
+ import { z as z72 } from "zod";
27709
+ var trailEntrySchema = z72.looseObject({
27710
+ by: z72.string(),
27711
+ at: z72.string(),
27712
+ outcome: z72.string(),
27713
+ stage: z72.string(),
27714
+ file: z72.string(),
27715
+ field: z72.string(),
27716
+ to: z72.string()
26745
27717
  });
26746
27718
  var isTrailEntry = (entry) => {
26747
27719
  return trailEntrySchema.safeParse(entry).success;
26748
27720
  };
26749
- var previousPassSchema = z71.record(z71.string(), z71.unknown()).nullable();
26750
- var previousCorrectionsSchema = z71.array(z71.record(z71.string(), z71.unknown()));
27721
+ var previousPassSchema = z72.record(z72.string(), z72.unknown()).nullable();
27722
+ var previousCorrectionsSchema = z72.array(z72.record(z72.string(), z72.unknown()));
26751
27723
  var readUnlessMissing = async (read, { file, fallback }) => {
26752
27724
  try {
26753
27725
  return await read(file);
@@ -26761,7 +27733,7 @@ var readUnlessMissing = async (read, { file, fallback }) => {
26761
27733
  var batchInput = async (args) => {
26762
27734
  const { dir, stage, index } = args;
26763
27735
  const read = (file) => {
26764
- return readFile37(path42.join(dir, file), "utf8");
27736
+ return readFile38(path42.join(dir, file), "utf8");
26765
27737
  };
26766
27738
  const inputFile = `OUT/${stage}/${index}.${stage === "analyze" ? "index" : "rows"}.json`;
26767
27739
  const current = JSON.parse(await read(inputFile));
@@ -26775,7 +27747,7 @@ var batchInput = async (args) => {
26775
27747
  ) : void 0;
26776
27748
  let hostFeedback;
26777
27749
  if (previous) {
26778
- const trail = z71.array(z71.unknown()).parse(
27750
+ const trail = z72.array(z72.unknown()).parse(
26779
27751
  JSON.parse(
26780
27752
  await readUnlessMissing(read, {
26781
27753
  file: "OUT/corrections.json",
@@ -26829,11 +27801,11 @@ var batchInput = async (args) => {
26829
27801
  var defaultBatchSize = 10;
26830
27802
  var defaultConcurrency = 25;
26831
27803
  var maxAttempts = 3;
26832
- var rowsOutSchema = z72.looseObject({
26833
- rows: z72.array(z72.record(z72.string(), z72.unknown())).optional()
27804
+ var rowsOutSchema = z73.looseObject({
27805
+ rows: z73.array(z73.record(z73.string(), z73.unknown())).optional()
26834
27806
  });
26835
27807
  var readOut = async (dir, { stage, required }) => {
26836
- const raw = await readFile38(
27808
+ const raw = await readFile39(
26837
27809
  path43.join(dir, "OUT", `${stage}.json`),
26838
27810
  "utf8"
26839
27811
  ).catch(() => null);
@@ -27062,7 +28034,7 @@ var batchInputsDigest = async (ctx, stage, batch) => {
27062
28034
  )
27063
28035
  };
27064
28036
  for (const file of await spec.sharedInputs(ctx.dir)) {
27065
- parts[file] = await readFile38(path43.join(ctx.dir, file), "utf8").catch(
28037
+ parts[file] = await readFile39(path43.join(ctx.dir, file), "utf8").catch(
27066
28038
  () => ""
27067
28039
  );
27068
28040
  }
@@ -27079,14 +28051,14 @@ var stageInputsDigest = async (ctx, stage) => {
27079
28051
  return sha(digests);
27080
28052
  };
27081
28053
  var isStageFresh = async (ctx, stage) => {
27082
- const recorded2 = await readFile38(
28054
+ const recorded2 = await readFile39(
27083
28055
  path43.join(ctx.dir, "OUT", `${stage}.inputs.sha`),
27084
28056
  "utf8"
27085
28057
  ).catch(() => null);
27086
28058
  if (!recorded2) {
27087
28059
  return false;
27088
28060
  }
27089
- const out = await readFile38(
28061
+ const out = await readFile39(
27090
28062
  path43.join(ctx.dir, "OUT", `${stage}.json`),
27091
28063
  "utf8"
27092
28064
  ).catch(() => null);
@@ -27099,26 +28071,26 @@ var sessionSandbox = (spec) => {
27099
28071
  const AEO_CODEX_STAGE_SANDBOX = readEnv("AEO_CODEX_STAGE_SANDBOX");
27100
28072
  return AEO_CODEX_STAGE_SANDBOX === "danger-full-access" ? "danger-full-access" : "workspace-write";
27101
28073
  };
27102
- var eventText = z72.string().optional().catch(void 0);
27103
- var eventTokens = z72.number().optional().catch(void 0);
27104
- var eventUsage = z72.looseObject({
28074
+ var eventText = z73.string().optional().catch(void 0);
28075
+ var eventTokens = z73.number().optional().catch(void 0);
28076
+ var eventUsage = z73.looseObject({
27105
28077
  input_tokens: eventTokens,
27106
28078
  cached_input_tokens: eventTokens,
27107
28079
  output_tokens: eventTokens
27108
28080
  }).optional().catch(void 0);
27109
- var codexEventSchema = z72.looseObject({
28081
+ var codexEventSchema = z73.looseObject({
27110
28082
  type: eventText,
27111
28083
  thread_id: eventText,
27112
28084
  message: eventText,
27113
- error: z72.looseObject({ message: eventText }).optional().catch(void 0),
27114
- item: z72.looseObject({
28085
+ error: z73.looseObject({ message: eventText }).optional().catch(void 0),
28086
+ item: z73.looseObject({
27115
28087
  type: eventText,
27116
28088
  command: eventText,
27117
28089
  text: eventText,
27118
28090
  status: eventText
27119
28091
  }).optional().catch(void 0),
27120
28092
  usage: eventUsage,
27121
- info: z72.looseObject({ total_token_usage: eventUsage }).optional().catch(void 0)
28093
+ info: z73.looseObject({ total_token_usage: eventUsage }).optional().catch(void 0)
27122
28094
  });
27123
28095
  var parseCodexEvent = (line) => {
27124
28096
  let json;
@@ -27219,7 +28191,7 @@ var execReservedCodex = async (ctx, { stage, batch, feedback, attempt }, reserve
27219
28191
  inputs: await Promise.all(
27220
28192
  boundFiles.map(async (file) => [
27221
28193
  file,
27222
- await readFile38(path43.join(ctx.dir, file), "utf8").catch(() => "")
28194
+ await readFile39(path43.join(ctx.dir, file), "utf8").catch(() => "")
27223
28195
  ])
27224
28196
  )
27225
28197
  });
@@ -27403,7 +28375,7 @@ var correctionValue = (text) => {
27403
28375
  }
27404
28376
  };
27405
28377
  var readCorrectable = async (file) => {
27406
- const raw = await readFile38(file, "utf8");
28378
+ const raw = await readFile39(file, "utf8");
27407
28379
  return rowsOutSchema.parse(JSON.parse(raw));
27408
28380
  };
27409
28381
  var isQualifyRow = (row) => {
@@ -27490,7 +28462,7 @@ var applyCorrections = async (ctx, from, corrections) => {
27490
28462
  const scope = { brand: ctx.brand, answers, coverage: false };
27491
28463
  for (const [stage, list] of byStage) {
27492
28464
  const file = path43.join(ctx.dir, "OUT", `${stage}.json`);
27493
- const raw = await readFile38(file, "utf8").catch(() => null);
28465
+ const raw = await readFile39(file, "utf8").catch(() => null);
27494
28466
  if (!raw || !isStageName(stage)) {
27495
28467
  for (const correction of list) {
27496
28468
  outcomes.push({ correction, outcome: "refused: no such stage output" });
@@ -27517,8 +28489,8 @@ var applyCorrections = async (ctx, from, corrections) => {
27517
28489
  await alignBatchRows(path43.join(ctx.dir, "OUT", stage), output);
27518
28490
  }
27519
28491
  const trailFile = path43.join(ctx.dir, "OUT", "corrections.json");
27520
- const trail = z72.array(z72.unknown()).parse(
27521
- JSON.parse(await readFile38(trailFile, "utf8").catch(() => "[]") || "[]")
28492
+ const trail = z73.array(z73.unknown()).parse(
28493
+ JSON.parse(await readFile39(trailFile, "utf8").catch(() => "[]") || "[]")
27522
28494
  );
27523
28495
  const at = (/* @__PURE__ */ new Date()).toISOString();
27524
28496
  trail.push(
@@ -27604,7 +28576,7 @@ var dropSession = async (ctx, label) => {
27604
28576
  var incompleteError = (result) => {
27605
28577
  return `codex exited ${result.exitCode} without an output file: ${(result.failure ?? result.stderr).slice(-600)}`;
27606
28578
  };
27607
- var storedBatchSchema = z72.record(z72.string(), z72.unknown());
28579
+ var storedBatchSchema = z73.record(z73.string(), z73.unknown());
27608
28580
  var runCodexBatch = async (ctx, { stage, batch, files, scope }) => {
27609
28581
  const { label, outFile, refusedFile } = files;
27610
28582
  const usages = [];
@@ -27624,7 +28596,7 @@ var runCodexBatch = async (ctx, { stage, batch, files, scope }) => {
27624
28596
  operationId: result.operationId ?? null
27625
28597
  };
27626
28598
  usages.push(result.usage);
27627
- const raw = await readFile38(outFile, "utf8").catch(() => null);
28599
+ const raw = await readFile39(outFile, "utf8").catch(() => null);
27628
28600
  if (raw === null) {
27629
28601
  const error = incompleteError(result);
27630
28602
  if (isAuthError(result.failure ?? result.stderr)) {
@@ -27708,20 +28680,20 @@ var runCodexBatch = async (ctx, { stage, batch, files, scope }) => {
27708
28680
  ...fatal !== void 0 && { fatal }
27709
28681
  };
27710
28682
  };
27711
- var pendingSchema = z72.object({
27712
- version: z72.literal(2).optional(),
27713
- digest: z72.string(),
28683
+ var pendingSchema = z73.object({
28684
+ version: z73.literal(2).optional(),
28685
+ digest: z73.string(),
27714
28686
  // A draft the writer never produced is absent from the written file.
27715
- draft: z72.unknown().optional(),
27716
- rounds: z72.number(),
27717
- errors: z72.array(z72.string())
28687
+ draft: z73.unknown().optional(),
28688
+ rounds: z73.number(),
28689
+ errors: z73.array(z73.string())
27718
28690
  });
27719
28691
  var savePending = async (ctx, { pendingFile, pending }) => {
27720
28692
  await writePendingJson(path43.join(ctx.dir, pendingFile), pending);
27721
28693
  await ctx.checkpoint?.([pendingFile]);
27722
28694
  };
27723
28695
  var readPending = async (ctx, { label, pendingFile, digest: digest5 }) => {
27724
- const raw = await readFile38(path43.join(ctx.dir, pendingFile), "utf8").catch(
28696
+ const raw = await readFile39(path43.join(ctx.dir, pendingFile), "utf8").catch(
27725
28697
  () => "null"
27726
28698
  );
27727
28699
  const parsed = pendingSchema.safeParse(JSON.parse(raw));
@@ -27732,7 +28704,7 @@ var readPending = async (ctx, { label, pendingFile, digest: digest5 }) => {
27732
28704
  if (saved.version === 2) {
27733
28705
  return saved;
27734
28706
  }
27735
- const journalText = await readFile38(
28707
+ const journalText = await readFile39(
27736
28708
  path43.join(ctx.dir, "JOURNAL", `${label}.refusals.jsonl`),
27737
28709
  "utf8"
27738
28710
  ).catch(() => "");
@@ -27900,7 +28872,7 @@ var reusedBatch = async (ctx, {
27900
28872
  if (validated.value === void 0 || validated.errors.length) {
27901
28873
  return void 0;
27902
28874
  }
27903
- const appliedSha = await readFile38(appliedFile, "utf8").catch(() => "");
28875
+ const appliedSha = await readFile39(appliedFile, "utf8").catch(() => "");
27904
28876
  await ctx.recorder?.record(
27905
28877
  "artifact_reused",
27906
28878
  { stage, batch: batch.index },
@@ -27945,8 +28917,8 @@ var runBatch = async (ctx, {
27945
28917
  const refusedFile = path43.join(outDir, `${batch.index}.refused.json`);
27946
28918
  const scope = scopeFor(ctx, stage, batch);
27947
28919
  const digest5 = await batchInputsDigest(ctx, stage, batch);
27948
- const previous = await readFile38(outFile, "utf8").catch(() => null);
27949
- const recorded2 = (await readFile38(shaFile, "utf8").catch(() => "")).trim();
28920
+ const previous = await readFile39(outFile, "utf8").catch(() => null);
28921
+ const recorded2 = (await readFile39(shaFile, "utf8").catch(() => "")).trim();
27950
28922
  if (previous !== null && recorded2 === digest5 && (!force || previousAccepted)) {
27951
28923
  const reused = await reusedBatch(ctx, {
27952
28924
  stage,
@@ -28044,15 +29016,15 @@ var pool = async (items, {
28044
29016
  );
28045
29017
  await Promise.all(workers);
28046
29018
  };
28047
- var acceptedReviewSchema = z72.looseObject({
28048
- verdict: z72.unknown().optional(),
28049
- corrections: z72.array(z72.unknown()).optional()
29019
+ var acceptedReviewSchema = z73.looseObject({
29020
+ verdict: z73.unknown().optional(),
29021
+ corrections: z73.array(z73.unknown()).optional()
28050
29022
  });
28051
29023
  var previouslyAccepted = async (ctx, stage, batch) => {
28052
29024
  if (!stageSpecs[stage].passes) {
28053
29025
  return false;
28054
29026
  }
28055
- const own = await readFile38(
29027
+ const own = await readFile39(
28056
29028
  path43.join(ctx.dir, "OUT", stage, `${batch.index}.json`),
28057
29029
  "utf8"
28058
29030
  ).catch(() => null);
@@ -28286,19 +29258,19 @@ var runStage = async (initial, stage, options = {}) => {
28286
29258
  };
28287
29259
 
28288
29260
  // src/codex-workflow/batch-layout.ts
28289
- import { mkdir as mkdir19, readFile as readFile39, writeFile as writeFile19 } from "node:fs/promises";
29261
+ import { mkdir as mkdir19, readFile as readFile40, writeFile as writeFile19 } from "node:fs/promises";
28290
29262
  import path44 from "node:path";
28291
- import { z as z73 } from "zod";
28292
- var layoutSchema = z73.object({
28293
- scope: z73.string(),
28294
- size: z73.number().int().positive(),
28295
- batches: z73.array(z73.array(z73.string()))
29263
+ import { z as z74 } from "zod";
29264
+ var layoutSchema = z74.object({
29265
+ scope: z74.string(),
29266
+ size: z74.number().int().positive(),
29267
+ batches: z74.array(z74.array(z74.string()))
28296
29268
  });
28297
29269
  var stableBatchLayout = async (dir, { config, files, size }) => {
28298
29270
  const file = path44.join(dir, "OUT", "batches.json");
28299
29271
  const scope = contentHash(config);
28300
29272
  const old = layoutSchema.safeParse(
28301
- JSON.parse(await readFile39(file, "utf8").catch(() => "null"))
29273
+ JSON.parse(await readFile40(file, "utf8").catch(() => "null"))
28302
29274
  );
28303
29275
  const layout = old.success && old.data.scope === scope && old.data.size === size ? old.data : { scope, size, batches: [] };
28304
29276
  const assigned = new Set(layout.batches.flat());
@@ -28333,13 +29305,13 @@ var copyInputsOf = (source, extra = {}) => {
28333
29305
  ...extra
28334
29306
  };
28335
29307
  };
28336
- var copyPayloadSchema = z74.looseObject({
29308
+ var copyPayloadSchema = z75.looseObject({
28337
29309
  copy: aeoReportCopySchema,
28338
- provenance: z74.unknown().optional(),
28339
- receipt: z74.unknown().optional(),
28340
- confidence: z74.number(),
28341
- outcome: z74.string(),
28342
- draft: z74.unknown().optional(),
29310
+ provenance: z75.unknown().optional(),
29311
+ receipt: z75.unknown().optional(),
29312
+ confidence: z75.number(),
29313
+ outcome: z75.string(),
29314
+ draft: z75.unknown().optional(),
28343
29315
  quality: aeoSnapshotSchema.shape.meta.shape.quality
28344
29316
  });
28345
29317
  var prepareWorkdir = async (source, dir, options = {}) => {
@@ -28436,13 +29408,13 @@ var prepareLockedWorkdir = async (source, dir, options) => {
28436
29408
  }
28437
29409
  };
28438
29410
  };
28439
- var savedVerifierMemorySchema = z74.object({
28440
- scope: z74.string(),
28441
- history: z74.record(
28442
- z74.string(),
28443
- z74.array(
28444
- z74.object({
28445
- text: z74.string(),
29411
+ var savedVerifierMemorySchema = z75.object({
29412
+ scope: z75.string(),
29413
+ history: z75.record(
29414
+ z75.string(),
29415
+ z75.array(
29416
+ z75.object({
29417
+ text: z75.string(),
28446
29418
  review: verdictSchemaFor([], []).shape.reviews.element
28447
29419
  })
28448
29420
  )
@@ -28470,7 +29442,7 @@ var withCopy = async (ctx, inputs) => {
28470
29442
  });
28471
29443
  const verifierMemory = {
28472
29444
  read: async () => {
28473
- const raw = await readFile40(memoryFile, "utf8").catch(() => "null");
29445
+ const raw = await readFile41(memoryFile, "utf8").catch(() => "null");
28474
29446
  const saved = savedVerifierMemorySchema.parse(JSON.parse(raw));
28475
29447
  return saved?.scope === memoryScope ? saved.history : {};
28476
29448
  },
@@ -28644,12 +29616,12 @@ var report = (ctx, run, { reused = false } = {}) => {
28644
29616
  ctx.log(` ${error.slice(0, 300)}`);
28645
29617
  }
28646
29618
  };
28647
- var workflowStateSchema = z74.looseObject({
28648
- stages: z74.array(z74.record(z74.string(), z74.unknown())).optional()
29619
+ var workflowStateSchema = z75.looseObject({
29620
+ stages: z75.array(z75.record(z75.string(), z75.unknown())).optional()
28649
29621
  });
28650
29622
  var writeState = async (dir, run) => {
28651
29623
  const file = path45.join(dir, "STATE.json");
28652
- const raw = await readFile40(file, "utf8").catch(() => "{}") || "{}";
29624
+ const raw = await readFile41(file, "utf8").catch(() => "{}") || "{}";
28653
29625
  const state = workflowStateSchema.parse(JSON.parse(raw));
28654
29626
  state.stages = [
28655
29627
  ...state.stages ?? [],
@@ -28657,13 +29629,13 @@ var writeState = async (dir, run) => {
28657
29629
  ];
28658
29630
  await writeFile20(file, JSON.stringify(state, null, 2));
28659
29631
  };
28660
- var recordedRunSchema = z74.looseObject({
28661
- degraded: z74.array(z74.string()).optional(),
28662
- summary: z74.record(z74.string(), z74.unknown()).optional()
29632
+ var recordedRunSchema = z75.looseObject({
29633
+ degraded: z75.array(z75.string()).optional(),
29634
+ summary: z75.record(z75.string(), z75.unknown()).optional()
28663
29635
  }).nullable();
28664
29636
  var runOne = async (ctx, stage, { force, pass }) => {
28665
29637
  if (!force && await isStageFresh(ctx, stage)) {
28666
- const raw = await readFile40(
29638
+ const raw = await readFile41(
28667
29639
  path45.join(ctx.dir, "OUT", `${stage}.result.json`),
28668
29640
  "utf8"
28669
29641
  ).catch(() => "null");
@@ -28688,7 +29660,7 @@ var runOne = async (ctx, stage, { force, pass }) => {
28688
29660
  };
28689
29661
  var deliverableCopy = async (ctx, inputs, written) => {
28690
29662
  if (written.ok) {
28691
- const raw = await readFile40(path45.join(ctx.dir, "OUT", "write.json"), "utf8");
29663
+ const raw = await readFile41(path45.join(ctx.dir, "OUT", "write.json"), "utf8");
28692
29664
  return copyPayloadSchema.parse(JSON.parse(raw));
28693
29665
  }
28694
29666
  const draft = {
@@ -28790,8 +29762,8 @@ var withoutAnswers = (ctx, files) => {
28790
29762
  answers: ctx.answers.filter((answer) => !gone.has(answer.file))
28791
29763
  };
28792
29764
  };
28793
- var correctionTrailSchema = z74.array(
28794
- z74.looseObject({ outcome: z74.string().optional() })
29765
+ var correctionTrailSchema = z75.array(
29766
+ z75.looseObject({ outcome: z75.string().optional() })
28795
29767
  );
28796
29768
  var Scorecard = class {
28797
29769
  #ctx;
@@ -28830,7 +29802,7 @@ var Scorecard = class {
28830
29802
  async write(verdict) {
28831
29803
  const { dir } = this.#ctx;
28832
29804
  const review2 = await readStoredReview(dir);
28833
- const trailText = await readFile40(path45.join(dir, "OUT", "corrections.json"), "utf8").catch(
29805
+ const trailText = await readFile41(path45.join(dir, "OUT", "corrections.json"), "utf8").catch(
28834
29806
  () => "[]"
28835
29807
  ) || "[]";
28836
29808
  const trail = correctionTrailSchema.parse(JSON.parse(trailText));
@@ -28872,7 +29844,7 @@ var Scorecard = class {
28872
29844
  return card;
28873
29845
  }
28874
29846
  };
28875
- var reviewProgressSchema = z74.object({ rounds: z74.number(), digest: z74.string(), accepted: z74.boolean() }).nullable();
29847
+ var reviewProgressSchema = z75.object({ rounds: z75.number(), digest: z75.string(), accepted: z75.boolean() }).nullable();
28876
29848
  var runWorkflow = async (prepared, options = {}) => {
28877
29849
  try {
28878
29850
  return await runWorkflowSteps(prepared, options);
@@ -28914,7 +29886,7 @@ var runWorkflowSteps = async (prepared, options) => {
28914
29886
  await ctx.checkpoint?.();
28915
29887
  const progressFile = path45.join(ctx.dir, "REVIEW", "progress.json");
28916
29888
  const savedProgress = reviewProgressSchema.parse(
28917
- JSON.parse(await readFile40(progressFile, "utf8").catch(() => "null"))
29889
+ JSON.parse(await readFile41(progressFile, "utf8").catch(() => "null"))
28918
29890
  );
28919
29891
  const progress = !force && savedProgress?.digest === await stageInputsDigest(ctx, "review") ? savedProgress : null;
28920
29892
  let rounds = progress?.rounds ?? 0;
@@ -29218,16 +30190,16 @@ var prepareRejudgment = async ({
29218
30190
  };
29219
30191
 
29220
30192
  // src/engine/author.ts
29221
- import { readFile as readFile41, writeFile as writeFile22 } from "node:fs/promises";
30193
+ import { readFile as readFile42, writeFile as writeFile22 } from "node:fs/promises";
29222
30194
  import path47 from "node:path";
29223
- import { z as z75 } from "zod";
29224
- var authorRecordSchema = z75.looseObject({
29225
- version: z75.literal(1),
29226
- runId: z75.string(),
29227
- brief: z75.unknown(),
29228
- proposed: z75.unknown(),
29229
- notes: z75.unknown(),
29230
- research: z75.unknown()
30195
+ import { z as z76 } from "zod";
30196
+ var authorRecordSchema = z76.looseObject({
30197
+ version: z76.literal(1),
30198
+ runId: z76.string(),
30199
+ brief: z76.unknown(),
30200
+ proposed: z76.unknown(),
30201
+ notes: z76.unknown(),
30202
+ research: z76.unknown()
29231
30203
  });
29232
30204
  var proposalOf = (file) => {
29233
30205
  const {
@@ -29239,7 +30211,7 @@ var proposalOf = (file) => {
29239
30211
  return measured;
29240
30212
  };
29241
30213
  var readBrief = async (file) => {
29242
- const text = await readFile41(file, "utf8").catch((err) => {
30214
+ const text = await readFile42(file, "utf8").catch((err) => {
29243
30215
  throw new Error(`Please check --brief: ${file} cannot be read.`, {
29244
30216
  cause: err
29245
30217
  });
@@ -29389,7 +30361,7 @@ var readAuthorEvidence = async (configFile, file) => {
29389
30361
  return { kind: "manual" };
29390
30362
  }
29391
30363
  const reference2 = file.author;
29392
- const text = await readFile41(
30364
+ const text = await readFile42(
29393
30365
  path47.join(path47.dirname(configFile), reference2.record),
29394
30366
  "utf8"
29395
30367
  ).catch((err) => {
@@ -29474,6 +30446,11 @@ DATAFORSEO_PASSWORD=
29474
30446
  CLAUDE_CODE_OAUTH_TOKEN=
29475
30447
  OPENAI_API_KEY=
29476
30448
  CURSOR_API_KEY=
30449
+
30450
+ # Claude Code through an Anthropic-compatible gateway, with no account
30451
+ # identity (a logged-in Claude Code tells the model the account's email).
30452
+ ANTHROPIC_AUTH_TOKEN=
30453
+ ANTHROPIC_BASE_URL=
29477
30454
  `;
29478
30455
 
29479
30456
  // src/cli/run-commands.ts
@@ -30156,9 +31133,9 @@ var executeRun = async ({
30156
31133
  import path50 from "node:path";
30157
31134
 
30158
31135
  // src/engine/run-status.ts
30159
- import { readFile as readFile42, stat as stat3 } from "node:fs/promises";
31136
+ import { readFile as readFile43, stat as stat3 } from "node:fs/promises";
30160
31137
  import path49 from "node:path";
30161
- import { z as z76 } from "zod";
31138
+ import { z as z77 } from "zod";
30162
31139
  var SpendCategory = {
30163
31140
  PROBES: "probes",
30164
31141
  STAGES: "stages",
@@ -30177,31 +31154,31 @@ var spendCategoryOf = (role) => {
30177
31154
  }
30178
31155
  return SpendCategory.HOST_CALLS;
30179
31156
  };
30180
- var ledgerCallSchema = z76.looseObject({
30181
- callId: z76.string(),
30182
- role: z76.string(),
30183
- reservedUsd: z76.number(),
30184
- inputTokens: z76.number(),
30185
- maxOutputTokens: z76.number(),
30186
- usage: z76.looseObject({
30187
- costUsd: z76.number().optional(),
30188
- inputTokens: z76.number().optional(),
30189
- outputTokens: z76.number().optional()
31157
+ var ledgerCallSchema = z77.looseObject({
31158
+ callId: z77.string(),
31159
+ role: z77.string(),
31160
+ reservedUsd: z77.number(),
31161
+ inputTokens: z77.number(),
31162
+ maxOutputTokens: z77.number(),
31163
+ usage: z77.looseObject({
31164
+ costUsd: z77.number().optional(),
31165
+ inputTokens: z77.number().optional(),
31166
+ outputTokens: z77.number().optional()
30190
31167
  }).optional()
30191
31168
  });
30192
- var ledgerSchema = z76.looseObject({
30193
- limits: z76.looseObject({ maxUsd: z76.number(), deadlineAt: z76.string() }),
30194
- calls: z76.record(z76.string(), ledgerCallSchema)
31169
+ var ledgerSchema = z77.looseObject({
31170
+ limits: z77.looseObject({ maxUsd: z77.number(), deadlineAt: z77.string() }),
31171
+ calls: z77.record(z77.string(), ledgerCallSchema)
30195
31172
  });
30196
- var budgetStateSchema2 = z76.looseObject({
30197
- current: z76.looseObject({ maxUsd: z76.number() }),
30198
- deadlineAt: z76.string(),
30199
- model: z76.string().optional()
31173
+ var budgetStateSchema2 = z77.looseObject({
31174
+ current: z77.looseObject({ maxUsd: z77.number() }),
31175
+ deadlineAt: z77.string(),
31176
+ model: z77.string().optional()
30200
31177
  });
30201
31178
  var workflowStages = ["analyze", "qualify", "review", "write"];
30202
31179
  var readText2 = async (file) => {
30203
31180
  try {
30204
- return await readFile42(file, "utf8");
31181
+ return await readFile43(file, "utf8");
30205
31182
  } catch (err) {
30206
31183
  if (hasErrorCode(err, "ENOENT")) {
30207
31184
  return void 0;