literally-aeo 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/README.md +16 -0
  2. package/dist/cli.mjs +1503 -548
  3. package/dist/lib/agents/methodology.js +3 -3
  4. package/dist/lib/bundle/contracts.js +1 -1
  5. package/dist/lib/bundle/export.js +12 -12
  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 +10 -10
  9. package/dist/lib/bundle/read.js +13 -13
  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-22SP35NA.js → chunk-2ANSPIUT.js} +1 -1
  19. package/dist/lib/chunks/{chunk-ITLJZUKL.js → chunk-54GMIPWV.js} +1 -1
  20. package/dist/lib/chunks/{chunk-QJX6YXXQ.js → chunk-65OIYOUH.js} +2 -2
  21. package/dist/lib/chunks/{chunk-ENPRRXH5.js → chunk-6MGXILUJ.js} +1 -1
  22. package/dist/lib/chunks/chunk-6OURIXQZ.js +472 -0
  23. package/dist/lib/chunks/{chunk-AMK6IHJD.js → chunk-746643QV.js} +1 -1
  24. package/dist/lib/chunks/{chunk-AMF3T5A3.js → chunk-74K4E3ZS.js} +1 -1
  25. package/dist/lib/chunks/{chunk-5EM6J7TG.js → chunk-7HCVSLVG.js} +1 -1
  26. package/dist/lib/chunks/{chunk-RWVXK7XE.js → chunk-7K2XT3WI.js} +5 -5
  27. package/dist/lib/chunks/{chunk-VOK4TUXV.js → chunk-7L4Y6N3V.js} +1 -1
  28. package/dist/lib/chunks/{chunk-TD47AB37.js → chunk-7QWT7LFM.js} +2 -2
  29. package/dist/lib/chunks/{chunk-ATKP5ZW6.js → chunk-7SA2CRSS.js} +1 -1
  30. package/dist/lib/chunks/{chunk-Q6TZB2OQ.js → chunk-ARKZ5PJN.js} +1 -1
  31. package/dist/lib/chunks/{chunk-FBMO6UV4.js → chunk-B6XGNJUU.js} +1 -1
  32. package/dist/lib/chunks/{chunk-RR63UE5H.js → chunk-BNX7S4GK.js} +4 -4
  33. package/dist/lib/chunks/chunk-BWBPEXEU.js +83 -0
  34. package/dist/lib/chunks/{chunk-DKR7LSP2.js → chunk-BZAPAGXM.js} +1 -1
  35. package/dist/lib/chunks/{chunk-FFDMGNRO.js → chunk-C2Q7YE7Y.js} +6 -6
  36. package/dist/lib/chunks/{chunk-NWABYXDQ.js → chunk-D2LJMNH3.js} +2 -2
  37. package/dist/lib/chunks/{chunk-XT5M3PPQ.js → chunk-EVEJ3MFU.js} +3 -3
  38. package/dist/lib/chunks/{chunk-U4AROC2Z.js → chunk-GC7DISQO.js} +1 -1
  39. package/dist/lib/chunks/{chunk-YRXYTCMY.js → chunk-JHUI2K5X.js} +1 -1
  40. package/dist/lib/chunks/chunk-JQFLWUCA.js +123 -0
  41. package/dist/lib/chunks/{chunk-HJEIEMPE.js → chunk-JREYIUNG.js} +4 -4
  42. package/dist/lib/chunks/{chunk-FXCUGNFL.js → chunk-JXQOWHWB.js} +1 -1
  43. package/dist/lib/chunks/{chunk-BKAERR7J.js → chunk-KFJ5O5CL.js} +2 -2
  44. package/dist/lib/chunks/{chunk-6P7EZJI7.js → chunk-KSJ3NZIJ.js} +4 -2
  45. package/dist/lib/chunks/{chunk-EZ23TKTX.js → chunk-L5HFTFFG.js} +2 -2
  46. package/dist/lib/chunks/{chunk-DI4LZR37.js → chunk-LJD37WAV.js} +2 -2
  47. package/dist/lib/chunks/{chunk-YPGJN232.js → chunk-MKA2EP7M.js} +1 -1
  48. package/dist/lib/chunks/{chunk-JN4332MJ.js → chunk-MMJ5UR2E.js} +1 -1
  49. package/dist/lib/chunks/{chunk-A2RW4ZMR.js → chunk-MQFFMD4Q.js} +1 -1
  50. package/dist/lib/chunks/{chunk-CRXJFOCK.js → chunk-NM2LUMQT.js} +4 -4
  51. package/dist/lib/chunks/{chunk-RYV25YGT.js → chunk-P5VVHTZU.js} +1 -1
  52. package/dist/lib/chunks/{chunk-JKBXKACC.js → chunk-PFG3ESJE.js} +7 -7
  53. package/dist/lib/chunks/{chunk-OF3WIGG7.js → chunk-Q7CWM6LZ.js} +6 -6
  54. package/dist/lib/chunks/{chunk-DU3MAXVC.js → chunk-R5NLULQW.js} +1 -1
  55. package/dist/lib/chunks/{chunk-T5Q5CBTA.js → chunk-RM7U5M5L.js} +1 -1
  56. package/dist/lib/chunks/{chunk-JGBJQ3TO.js → chunk-RQ6GUJI5.js} +1 -1
  57. package/dist/lib/chunks/{chunk-CMB2KSW2.js → chunk-RUSMX6JH.js} +16 -7
  58. package/dist/lib/chunks/{chunk-KFYTORIT.js → chunk-UNNRLD2U.js} +4 -4
  59. package/dist/lib/chunks/chunk-VFN2J4Z3.js +626 -0
  60. package/dist/lib/chunks/{chunk-3DVFQMJT.js → chunk-VPJN2GNC.js} +1 -1
  61. package/dist/lib/chunks/{chunk-NZOKSFIA.js → chunk-XSOTCSD3.js} +3 -3
  62. package/dist/lib/chunks/{chunk-M4XGUJMO.js → chunk-YX4EH6FR.js} +1 -1
  63. package/dist/lib/chunks/{chunk-WIRVKAYB.js → chunk-ZC4MKS3J.js} +11 -11
  64. package/dist/lib/chunks/{chunk-KC35BXW7.js → chunk-ZM4RHMBI.js} +1 -1
  65. package/dist/lib/cli/bundle-commands.js +57 -32
  66. package/dist/lib/cli/guide-command.js +1 -1
  67. package/dist/lib/cli/run-commands.js +36 -36
  68. package/dist/lib/cli/status-command.js +18 -18
  69. package/dist/lib/codex-workflow/aggregate.js +2 -2
  70. package/dist/lib/codex-workflow/author.js +3 -3
  71. package/dist/lib/codex-workflow/capture.js +5 -5
  72. package/dist/lib/codex-workflow/copy-editor.js +3 -3
  73. package/dist/lib/codex-workflow/copy.js +2 -2
  74. package/dist/lib/codex-workflow/finish.js +5 -5
  75. package/dist/lib/codex-workflow/loop.js +13 -13
  76. package/dist/lib/codex-workflow/run-source.js +5 -5
  77. package/dist/lib/codex-workflow/stage.js +4 -4
  78. package/dist/lib/engine/audit-file.js +3 -3
  79. package/dist/lib/engine/author.js +10 -10
  80. package/dist/lib/engine/cost-estimate.js +3 -3
  81. package/dist/lib/engine/local-run.js +17 -17
  82. package/dist/lib/engine/preflight.js +3 -3
  83. package/dist/lib/engine/rejudge.js +24 -24
  84. package/dist/lib/engine/resources.js +1 -1
  85. package/dist/lib/engine/run-bindings.js +3 -3
  86. package/dist/lib/engine/run-method.js +2 -2
  87. package/dist/lib/engine/run-models.js +4 -4
  88. package/dist/lib/engine/run-status.js +18 -18
  89. package/dist/lib/engine/templates.js +4 -4
  90. package/dist/lib/grounding/grounding-runtime.js +5 -5
  91. package/dist/lib/grounding/recorded-tools.js +4 -4
  92. package/dist/lib/pipeline.js +4 -4
  93. package/dist/lib/probes/bindings.js +2 -2
  94. package/dist/lib/probes/charged-trace.js +3 -3
  95. package/dist/lib/probes/probes.js +3 -3
  96. package/dist/lib/viewer/alternatives.js +8 -0
  97. package/dist/lib/viewer/cited-domains.js +8 -0
  98. package/dist/lib/viewer/page.js +3 -1
  99. package/dist/lib/viewer/presentation.js +41 -0
  100. package/dist/lib/viewer/server.js +15 -10
  101. package/dist/types/bundle/contracts.d.ts +1 -1
  102. package/dist/types/engine/resources.d.ts +2 -0
  103. package/dist/types/viewer/alternatives.d.ts +16 -0
  104. package/dist/types/viewer/cited-domains.d.ts +22 -0
  105. package/dist/types/viewer/page.d.ts +9 -2
  106. package/dist/types/viewer/presentation.d.ts +112 -0
  107. package/dist/types/viewer/server.d.ts +7 -3
  108. package/package.json +2 -1
  109. package/resources/fonts/Mulish-OFL.txt +93 -0
  110. package/resources/fonts/Mulish-VariableFont_wght.ttf +0 -0
  111. package/resources/fonts/SourceCodePro-OFL.txt +93 -0
  112. package/resources/fonts/SourceCodePro-VariableFont_wght.ttf +0 -0
  113. package/src/bundle/contracts.ts +1 -1
  114. package/src/cli/bundle-commands.ts +21 -0
  115. package/src/engine/resources.ts +9 -5
  116. package/src/report/core/rate-interval.ts +1 -2
  117. package/src/viewer/alternatives.ts +202 -0
  118. package/src/viewer/cited-domains.ts +127 -0
  119. package/src/viewer/page.ts +549 -236
  120. package/src/viewer/presentation.ts +759 -0
  121. package/src/viewer/server.ts +25 -4
  122. package/dist/lib/chunks/chunk-3TF4JGQA.js +0 -323
@@ -0,0 +1,472 @@
1
+ import {
2
+ rankAlternatives
3
+ } from "./chunk-JQFLWUCA.js";
4
+ import {
5
+ groupCitedDomains
6
+ } from "./chunk-BWBPEXEU.js";
7
+ import {
8
+ capturedRecordsSchema
9
+ } from "./chunk-M3WZCV65.js";
10
+ import {
11
+ bundlePaths
12
+ } from "./chunk-6MGXILUJ.js";
13
+ import {
14
+ parseBundleJson
15
+ } from "./chunk-E6NQQU6V.js";
16
+ import {
17
+ intervalPercents
18
+ } from "./chunk-FXR6P7HY.js";
19
+ import {
20
+ aeoPerceptionSchema,
21
+ aeoSnapshotSchema,
22
+ aeoSourceMixSchema,
23
+ brandSchema,
24
+ sourceCategories
25
+ } from "./chunk-N5IAPSLM.js";
26
+ import {
27
+ isAgentSurface,
28
+ surfaceFamilyOf,
29
+ surfaceLabels
30
+ } from "./chunk-LTPLZSXI.js";
31
+ import {
32
+ aeoFinalCopyDraftSchema
33
+ } from "./chunk-2MGARWKY.js";
34
+ import {
35
+ formatReportDate,
36
+ reportSectionTitle
37
+ } from "./chunk-H56DDRKE.js";
38
+
39
+ // src/viewer/presentation.ts
40
+ import { z } from "zod";
41
+ var viewedSnapshotSchema = z.object({
42
+ brand: brandSchema.optional(),
43
+ sections: aeoSnapshotSchema.shape.sections,
44
+ sourceMix: aeoSourceMixSchema.optional(),
45
+ perception: aeoPerceptionSchema.optional(),
46
+ meta: aeoSnapshotSchema.shape.meta.pick({
47
+ generatedAt: true,
48
+ promptCount: true,
49
+ probeCount: true,
50
+ partialFailures: true,
51
+ surfaceLabels: true,
52
+ methodology: true,
53
+ reusedProbes: true
54
+ }).partial({ promptCount: true, probeCount: true, partialFailures: true })
55
+ });
56
+ var configBrandSchema = z.object({
57
+ brand: z.object({ name: z.string().min(1), domain: z.string().min(1) })
58
+ });
59
+ var presentReport = (files) => {
60
+ const snapshotFile = files.get(bundlePaths.snapshot);
61
+ if (snapshotFile === void 0) {
62
+ return { outcome: "missing" };
63
+ }
64
+ const snapshot = parseDocument(snapshotFile, viewedSnapshotSchema);
65
+ if (snapshot === void 0) {
66
+ return {
67
+ outcome: "unreadable",
68
+ reason: `${bundlePaths.snapshot} does not match the report contract of this release.`
69
+ };
70
+ }
71
+ const brand = snapshot.brand ?? parseDocument(files.get(bundlePaths.config), configBrandSchema)?.brand;
72
+ if (brand === void 0) {
73
+ return {
74
+ outcome: "unreadable",
75
+ reason: `Neither ${bundlePaths.snapshot} nor ${bundlePaths.config} names the audited brand.`
76
+ };
77
+ }
78
+ const copy = parseDocument(
79
+ files.get(bundlePaths.copy),
80
+ aeoFinalCopyDraftSchema
81
+ );
82
+ const captured = parseDocument(
83
+ files.get(bundlePaths.captures),
84
+ capturedRecordsSchema
85
+ );
86
+ const answers = new Map(
87
+ (captured ?? []).map((record) => [answerKey(record), record.probe.text])
88
+ );
89
+ const { meta } = snapshot;
90
+ const measuredOn = measurementPeriod(meta);
91
+ const labelOf = surfaceLabelFor(meta.surfaceLabels ?? {});
92
+ const visibilities = snapshot.sections.map((s) => s.visibility);
93
+ const surfaces = [...new Set(visibilities.flatMap((v) => v.surfaces))];
94
+ const promptCount = meta.promptCount ?? visibilities.reduce((sum, v) => sum + v.prompts.length, 0);
95
+ const probeCount = meta.probeCount ?? visibilities.reduce((sum, v) => sum + v.matrix.length, 0);
96
+ const presentation = {
97
+ outcome: "shown",
98
+ brand: { name: brand.name, domain: brand.domain },
99
+ hero: {
100
+ title: copy?.hero.title.text ?? `How AI engines see ${brand.name}`,
101
+ subtitle: copy?.hero.subtitle.text ?? defaultSubtitle(brand.name, surfaces, labelOf),
102
+ measuredOn,
103
+ probeCount,
104
+ facts: [
105
+ `${promptCount} buyer-style prompts`,
106
+ `${surfaces.length} AI surfaces${surfaces.some(isAgentSurface) ? ", coding agents included" : ""}`,
107
+ // Only when the bundle holds them: a redaction can withhold them all.
108
+ ...answers.size > 0 ? ["Raw answers preserved and inspectable"] : []
109
+ ]
110
+ },
111
+ ...copy?.intro[0] !== void 0 && {
112
+ intro: {
113
+ heading: `How AI engines see ${brand.name}`,
114
+ lead: copy.intro[0].text
115
+ }
116
+ },
117
+ sections: snapshot.sections.map(
118
+ (section) => presentSection(section, {
119
+ brand,
120
+ sourceMix: snapshot.sourceMix?.sections.find(
121
+ (s) => s.key === section.key
122
+ ),
123
+ perception: snapshot.perception?.sections.find(
124
+ (s) => s.key === section.key
125
+ ),
126
+ labelOf,
127
+ answers
128
+ })
129
+ ),
130
+ footer: {
131
+ baseline: `Measured ${measuredOn}: ${promptCount} prompts, ${probeCount} captured answers across ${listOf(surfaces.map(labelOf))}.`,
132
+ methodology: meta.methodology ?? [],
133
+ notes: [
134
+ ...reusedNote(meta.reusedProbes),
135
+ ...unanalyzedNote(meta.partialFailures ?? [])
136
+ ]
137
+ }
138
+ };
139
+ return presentation;
140
+ };
141
+ var presentSection = ({ key, visibility }, { brand, sourceMix, perception, labelOf, answers }) => {
142
+ const alternatives = rankAlternatives(visibility.matrix, brand);
143
+ const assistantSurfaces = visibility.surfaces.filter(
144
+ (s) => !isAgentSurface(s)
145
+ );
146
+ const agentSurfaces = visibility.surfaces.filter(isAgentSurface);
147
+ const runViewOf = (row, index) => {
148
+ const answer = row.runIndex === void 0 ? void 0 : answers.get(
149
+ answerKey({
150
+ sectionKey: key,
151
+ promptText: visibility.prompts[row.promptIdx]?.text ?? "",
152
+ surface: row.surface,
153
+ runIndex: row.runIndex
154
+ })
155
+ );
156
+ return presentRun(row, {
157
+ runNumber: row.runIndex ?? index + 1,
158
+ label: labelOf(row.surface),
159
+ answer
160
+ });
161
+ };
162
+ const section = {
163
+ key,
164
+ title: reportSectionTitle(key.replace(/_/g, " ")),
165
+ scorecards: presentScorecards(visibility, alternatives[0], labelOf),
166
+ surfaceRates: visibility.surfaces.flatMap((surface) => {
167
+ const rates = visibility.summary.byModel[surface];
168
+ const name = labelOf(surface);
169
+ return rates?.shareOfVoiceEvidence === void 0 ? [] : [
170
+ {
171
+ surface: name,
172
+ shareOfVoice: rateOf(
173
+ rates.shareOfVoice,
174
+ rates.shareOfVoiceEvidence,
175
+ { subject: `${name} share of voice`, counted: "Mentioned" }
176
+ ),
177
+ citationRate: rateOf(
178
+ rates.citationRate,
179
+ rates.citationRateEvidence,
180
+ { subject: `${name} citation rate`, counted: "Cited" }
181
+ )
182
+ }
183
+ ];
184
+ }),
185
+ matrix: {
186
+ assistantSurfaces: assistantSurfaces.map(labelOf),
187
+ agentSurfaces: agentSurfaces.map(labelOf),
188
+ rows: visibility.prompts.map((prompt, promptIdx) => ({
189
+ prompt: prompt.text,
190
+ category: prompt.category.replace(/_/g, " "),
191
+ cells: [...assistantSurfaces, ...agentSurfaces].map(
192
+ (surface) => presentCell(
193
+ visibility.matrix.filter(
194
+ (row) => row.promptIdx === promptIdx && row.surface === surface
195
+ ).map(runViewOf)
196
+ )
197
+ )
198
+ }))
199
+ },
200
+ alternatives: alternatives.slice(0, 10).map((alternative) => {
201
+ const share = alternative.mentioning / alternative.captured;
202
+ return { ...alternative, share, percent: percentOf(share) };
203
+ }),
204
+ citedDomains: groupCitedDomains(visibility, brand.domain).map((domain) => ({
205
+ ...domain,
206
+ urls: domain.urls.map((url) => ({
207
+ ...url,
208
+ surfaces: url.surfaces.map(labelOf)
209
+ }))
210
+ })),
211
+ ...sourceMix !== void 0 && {
212
+ sourceMix: {
213
+ rows: sourceMix.perSurface.filter(
214
+ ({ counts }) => sourceCategories.some((category) => counts[category] > 0)
215
+ ).map(({ surface, counts }) => ({
216
+ surface: labelOf(surface),
217
+ counts
218
+ })),
219
+ total: sourceMix.total
220
+ }
221
+ },
222
+ ...perception !== void 0 && {
223
+ perception: {
224
+ ...perception.sentiment,
225
+ phrases: groupPhrases(perception.narratives, labelOf)
226
+ }
227
+ }
228
+ };
229
+ return section;
230
+ };
231
+ var presentScorecards = (visibility, topAlternative, labelOf) => {
232
+ const { summary } = visibility;
233
+ const namesOf = (family) => listOf(
234
+ visibility.surfaces.filter((s) => surfaceFamilyOf(s) === family).map(labelOf)
235
+ );
236
+ const familyCard = (family, scope, rates) => {
237
+ if (rates.shareOfVoice === null || rates.shareOfVoice === void 0) {
238
+ return [];
239
+ }
240
+ const headline = rateOf(rates.shareOfVoice, rates.shareOfVoiceEvidence, {
241
+ subject: `share of voice across ${scope}`,
242
+ counted: "Mentioned"
243
+ });
244
+ const detail = rateOf(rates.citationRate ?? 0, rates.citationRateEvidence, {
245
+ subject: `citation rate across ${scope}`,
246
+ counted: "Cited"
247
+ });
248
+ const card = {
249
+ headline: headline.percent,
250
+ ...headline.interval !== void 0 && {
251
+ headlineInterval: headline.interval
252
+ },
253
+ label: `Share of voice \u2014 ${scope}`,
254
+ detail: `${detail.percent} citation rate across ${namesOf(family)}`,
255
+ ...detail.interval !== void 0 && { detailInterval: detail.interval }
256
+ };
257
+ return [card];
258
+ };
259
+ const cellMentions = /* @__PURE__ */ new Map();
260
+ for (const row of visibility.matrix) {
261
+ const cell = `${row.promptIdx}:${row.surface}`;
262
+ cellMentions.set(
263
+ cell,
264
+ (cellMentions.get(cell) ?? false) || row.prospectMentioned
265
+ );
266
+ }
267
+ const absentCells = [...cellMentions.values()].filter(
268
+ (mentioned) => !mentioned
269
+ ).length;
270
+ const scorecards = [
271
+ ...familyCard("chat", "AI assistants", {
272
+ shareOfVoice: summary.prospectShareOfVoice,
273
+ citationRate: summary.prospectCitationRate,
274
+ shareOfVoiceEvidence: summary.prospectShareOfVoiceEvidence,
275
+ citationRateEvidence: summary.prospectCitationRateEvidence
276
+ }),
277
+ ...familyCard("consumer", "consumer apps", {
278
+ shareOfVoice: summary.consumerShareOfVoice,
279
+ citationRate: summary.consumerCitationRate,
280
+ shareOfVoiceEvidence: summary.consumerShareOfVoiceEvidence,
281
+ citationRateEvidence: summary.consumerCitationRateEvidence
282
+ }),
283
+ ...familyCard("agents", "coding agents", {
284
+ shareOfVoice: summary.agentShareOfVoice,
285
+ citationRate: summary.agentCitationRate,
286
+ shareOfVoiceEvidence: summary.agentShareOfVoiceEvidence,
287
+ citationRateEvidence: summary.agentCitationRateEvidence
288
+ }),
289
+ ...topAlternative === void 0 ? [] : [
290
+ {
291
+ headline: percentOf(
292
+ topAlternative.mentioning / topAlternative.captured
293
+ ),
294
+ label: `${topAlternative.name} share of voice`,
295
+ detail: `Named most often: ${topAlternative.mentioning} of ${topAlternative.captured} captured answers`
296
+ }
297
+ ],
298
+ {
299
+ headline: `${absentCells}/${cellMentions.size}`,
300
+ label: "Cells with zero mentions",
301
+ detail: "Prompts and surfaces where the brand was absent"
302
+ }
303
+ ];
304
+ return scorecards;
305
+ };
306
+ var presentRun = (row, {
307
+ runNumber,
308
+ label,
309
+ answer
310
+ }) => {
311
+ const mentionedBrands = [
312
+ ...new Set(
313
+ (row.mentionedBrands ?? []).map((brand) => brand.domain ?? brand.name)
314
+ )
315
+ ];
316
+ const run = {
317
+ runNumber,
318
+ surface: label,
319
+ ...row.agentCliVersion !== void 0 && {
320
+ cliVersion: row.agentCliVersion
321
+ },
322
+ status: statusOf(row),
323
+ ...row.usedWebSearch !== void 0 && {
324
+ retrieval: retrievalOf(row.usedWebSearch)
325
+ },
326
+ ...row.contextSnippet !== null && { snippet: row.contextSnippet },
327
+ ...answer !== void 0 && { answer },
328
+ mentionedBrands,
329
+ citedUrls: row.citedUrls ?? []
330
+ };
331
+ return run;
332
+ };
333
+ var retrievalOf = (usedWebSearch) => {
334
+ if (usedWebSearch === null) {
335
+ return "unknown";
336
+ }
337
+ return usedWebSearch ? "searched" : "memory";
338
+ };
339
+ var statusOf = (row) => {
340
+ if (row.noOverview) {
341
+ return "no_overview";
342
+ }
343
+ if (!row.prospectMentioned) {
344
+ return "absent";
345
+ }
346
+ return row.prospectPosition === "primary" ? "primary" : "mentioned";
347
+ };
348
+ var presentCell = (runs) => {
349
+ const mentioned = runs.filter(
350
+ (run) => run.status === "primary" || run.status === "mentioned"
351
+ ).length;
352
+ if (runs.length === 0) {
353
+ return { status: "no_data", mentioned, runs };
354
+ }
355
+ if (mentioned === 0) {
356
+ return { status: "absent", mentioned, runs };
357
+ }
358
+ const status = runs.some((run) => run.status === "primary") ? "primary" : "mentioned";
359
+ return { status, mentioned, runs };
360
+ };
361
+ var rateOf = (rate, evidence, {
362
+ subject,
363
+ counted
364
+ }) => {
365
+ const percent = percentOf(rate);
366
+ if (evidence === void 0 || evidence.low > evidence.high) {
367
+ return { percent };
368
+ }
369
+ const { low, high } = intervalPercents(evidence);
370
+ const text = `approx. 95% interval ${low}\u2013${high}%`;
371
+ const view = {
372
+ percent,
373
+ interval: {
374
+ text,
375
+ label: `${text} for ${subject}`,
376
+ counts: `${counted} in ${evidence.count} of ${evidence.planned} planned answers; ${evidence.captured} captured`
377
+ }
378
+ };
379
+ return view;
380
+ };
381
+ var groupPhrases = (narratives, labelOf) => {
382
+ const byPhrase = /* @__PURE__ */ new Map();
383
+ for (const narrative of narratives) {
384
+ const text = narrative.phrase.trim();
385
+ const key = text.toLowerCase();
386
+ if (key === "") {
387
+ continue;
388
+ }
389
+ const entry = byPhrase.get(key) ?? { text, count: 0, surfaces: [] };
390
+ const surface = labelOf(narrative.surface);
391
+ entry.count += 1;
392
+ if (!entry.surfaces.includes(surface)) {
393
+ entry.surfaces.push(surface);
394
+ }
395
+ byPhrase.set(key, entry);
396
+ }
397
+ const phrases = [...byPhrase.values()].sort((a, b) => b.count - a.count).slice(0, 20);
398
+ return phrases;
399
+ };
400
+ var surfaceLabelFor = (runLabels) => (surface) => {
401
+ return runLabels[surface] ?? surfaceLabels[surface]?.replace(/ \(API\)$/, "") ?? surface;
402
+ };
403
+ var defaultSubtitle = (brandName, surfaces, labelOf) => {
404
+ const assistants = surfaces.filter((s) => !isAgentSurface(s)).map(labelOf);
405
+ const agents = surfaces.filter(isAgentSurface).map(labelOf);
406
+ const asked = assistants.length > 0 ? `How often ${listOf(assistants)} mention and cite ${brandName}.` : `How often AI answers mention and cite ${brandName}.`;
407
+ const subtitle = agents.length > 0 ? `${asked} Plus ${agents.length === 1 ? "one coding agent" : `${agents.length} coding agents`}: ${listOf(agents)}.` : asked;
408
+ return subtitle;
409
+ };
410
+ var measurementPeriod = ({
411
+ generatedAt,
412
+ reusedProbes
413
+ }) => {
414
+ const generated = formatReportDate(generatedAt);
415
+ if (reusedProbes === void 0) {
416
+ return generated;
417
+ }
418
+ return reusedProbes.oldestCapturedAt === null ? `by ${generated}` : `${formatReportDate(reusedProbes.oldestCapturedAt)} to ${generated}`;
419
+ };
420
+ var reusedNote = (reusedProbes) => {
421
+ if (reusedProbes === void 0) {
422
+ return [];
423
+ }
424
+ const { count } = reusedProbes;
425
+ return [
426
+ `${count} answer${count === 1 ? " was" : "s were"} reused from an earlier capture, not asked again by this run.`
427
+ ];
428
+ };
429
+ var unanalyzedNote = (partialFailures) => {
430
+ const count = partialFailures.filter(
431
+ (f) => f.step.startsWith("analysis:search:")
432
+ ).length;
433
+ if (count === 0) {
434
+ return [];
435
+ }
436
+ return [
437
+ `${count} prompt${count === 1 ? "" : "s"} could not be analyzed in this run and show${count === 1 ? "s" : ""} as no data.`
438
+ ];
439
+ };
440
+ var answerKey = ({
441
+ sectionKey,
442
+ promptText,
443
+ surface,
444
+ runIndex
445
+ }) => {
446
+ return JSON.stringify([sectionKey, promptText, surface, runIndex]);
447
+ };
448
+ var percentOf = (share) => {
449
+ return `${(share * 100).toFixed(0)}%`;
450
+ };
451
+ var listOf = (names) => {
452
+ const unique = [...new Set(names)];
453
+ if (unique.length <= 1) {
454
+ return unique[0] ?? "the measured surfaces";
455
+ }
456
+ return `${unique.slice(0, -1).join(", ")} and ${unique.at(-1) ?? ""}`;
457
+ };
458
+ var parseDocument = (file, schema) => {
459
+ if (file === void 0) {
460
+ return void 0;
461
+ }
462
+ try {
463
+ const parsed = schema.safeParse(parseBundleJson(file.toString("utf8")));
464
+ return parsed.success ? parsed.data : void 0;
465
+ } catch {
466
+ return void 0;
467
+ }
468
+ };
469
+
470
+ export {
471
+ presentReport
472
+ };
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  bindingOf,
9
9
  probeEstimateUsd
10
- } from "./chunk-5EM6J7TG.js";
10
+ } from "./chunk-7HCVSLVG.js";
11
11
  import {
12
12
  authorSearchLowUsd,
13
13
  authorTokens,
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-WNIXDMJL.js";
7
7
  import {
8
8
  recordedGroundingTools
9
- } from "./chunk-RYV25YGT.js";
9
+ } from "./chunk-P5VVHTZU.js";
10
10
  import {
11
11
  runGroundingResearch
12
12
  } from "./chunk-4MOZ3DVS.js";
@@ -41,7 +41,7 @@ import {
41
41
  } from "./chunk-IDNT2WBK.js";
42
42
  import {
43
43
  toolVersion
44
- } from "./chunk-ENPRRXH5.js";
44
+ } from "./chunk-6MGXILUJ.js";
45
45
  import {
46
46
  allSurfaces,
47
47
  customSurfacePrefix,
@@ -2,19 +2,19 @@ import {
2
2
  checkIntegrity,
3
3
  checkTraceChain,
4
4
  checkTraceCoverage
5
- } from "./chunk-XT5M3PPQ.js";
5
+ } from "./chunk-EVEJ3MFU.js";
6
6
  import {
7
7
  checkJudgments,
8
8
  checkPlan
9
- } from "./chunk-JGBJQ3TO.js";
9
+ } from "./chunk-RQ6GUJI5.js";
10
10
  import {
11
11
  checkCopy,
12
12
  checkGrounding,
13
13
  checkMetrics
14
- } from "./chunk-BKAERR7J.js";
14
+ } from "./chunk-KFJ5O5CL.js";
15
15
  import {
16
16
  capturedAnswerOf
17
- } from "./chunk-VOK4TUXV.js";
17
+ } from "./chunk-7L4Y6N3V.js";
18
18
  import {
19
19
  CheckOutcome,
20
20
  checkFrom,
@@ -29,7 +29,7 @@ import {
29
29
  predecessorPrefix,
30
30
  readableBundleSchemaVersions,
31
31
  traceSchemaVersion
32
- } from "./chunk-ENPRRXH5.js";
32
+ } from "./chunk-6MGXILUJ.js";
33
33
  import {
34
34
  parseBundleJson
35
35
  } from "./chunk-E6NQQU6V.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  operationKindsOf
3
- } from "./chunk-ENPRRXH5.js";
3
+ } from "./chunk-6MGXILUJ.js";
4
4
  import {
5
5
  sha256Hex
6
6
  } from "./chunk-E6NQQU6V.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  readFinalizedRevisions
3
- } from "./chunk-FFDMGNRO.js";
3
+ } from "./chunk-C2Q7YE7Y.js";
4
4
  import {
5
5
  BundleRefusedError,
6
6
  archiveLimits,
@@ -14,7 +14,7 @@ import {
14
14
  } from "./chunk-2QLAFBCG.js";
15
15
  import {
16
16
  bundlePaths
17
- } from "./chunk-ENPRRXH5.js";
17
+ } from "./chunk-6MGXILUJ.js";
18
18
 
19
19
  // src/bundle/read.ts
20
20
  import { lstat, readdir, readFile } from "node:fs/promises";
@@ -2,7 +2,7 @@ import {
2
2
  bindingOf,
3
3
  probeEstimateUsd,
4
4
  profileOf
5
- } from "./chunk-5EM6J7TG.js";
5
+ } from "./chunk-7HCVSLVG.js";
6
6
  import {
7
7
  createLog
8
8
  } from "./chunk-BBK54RVK.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-ST6IVXHT.js";
4
4
  import {
5
5
  runTechnicalChecks
6
- } from "./chunk-M4XGUJMO.js";
6
+ } from "./chunk-YX4EH6FR.js";
7
7
  import {
8
8
  writeFileAtomically
9
9
  } from "./chunk-MX6Y4RD2.js";
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-SXVKFPC4.js";
5
5
  import {
6
6
  createChatAdapter
7
- } from "./chunk-5EM6J7TG.js";
7
+ } from "./chunk-7HCVSLVG.js";
8
8
  import {
9
9
  createLog
10
10
  } from "./chunk-BBK54RVK.js";
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  localRunDigests,
3
3
  runDirectoryState
4
- } from "./chunk-WIRVKAYB.js";
4
+ } from "./chunk-ZC4MKS3J.js";
5
5
  import {
6
6
  localReportKey
7
- } from "./chunk-ITLJZUKL.js";
7
+ } from "./chunk-54GMIPWV.js";
8
8
  import {
9
9
  finalizeRevision,
10
10
  revisionsDir
11
- } from "./chunk-FFDMGNRO.js";
11
+ } from "./chunk-C2Q7YE7Y.js";
12
12
  import {
13
13
  carryFrozenBindings
14
- } from "./chunk-JN4332MJ.js";
14
+ } from "./chunk-MMJ5UR2E.js";
15
15
  import {
16
16
  bankDir
17
17
  } from "./chunk-N4PQ6RPQ.js";
@@ -0,0 +1,83 @@
1
+ import {
2
+ isGroundingRedirectUrl
3
+ } from "./chunk-UGCT46PC.js";
4
+ import {
5
+ normalizeDomain
6
+ } from "./chunk-QTXOW5XC.js";
7
+
8
+ // src/viewer/cited-domains.ts
9
+ var groupCitedDomains = (visibility, brandDomain) => {
10
+ const brand = normalizeDomain(brandDomain);
11
+ const urlsByDomain = /* @__PURE__ */ new Map();
12
+ const brandHostCounts = /* @__PURE__ */ new Map();
13
+ for (const row of visibility.matrix) {
14
+ for (const url of row.citedUrls ?? []) {
15
+ const host = isGroundingRedirectUrl(url) ? void 0 : hostOf(url);
16
+ if (host === void 0) {
17
+ continue;
18
+ }
19
+ const isBrandHost = host === brand || host.endsWith(`.${brand}`);
20
+ const domain = isBrandHost ? brand : apexOf(host);
21
+ const urls = urlsByDomain.get(domain) ?? /* @__PURE__ */ new Map();
22
+ const cited = urls.get(url) ?? {
23
+ url,
24
+ count: 0,
25
+ surfaces: [],
26
+ prompts: []
27
+ };
28
+ const promptText = visibility.prompts[row.promptIdx]?.text;
29
+ cited.count += 1;
30
+ if (!cited.surfaces.includes(row.surface)) {
31
+ cited.surfaces.push(row.surface);
32
+ }
33
+ if (promptText !== void 0 && !cited.prompts.includes(promptText)) {
34
+ cited.prompts.push(promptText);
35
+ }
36
+ urls.set(url, cited);
37
+ urlsByDomain.set(domain, urls);
38
+ if (isBrandHost) {
39
+ const label = brandHostLabel(host, brand);
40
+ brandHostCounts.set(label, (brandHostCounts.get(label) ?? 0) + 1);
41
+ }
42
+ }
43
+ }
44
+ const domainOf = (domain) => {
45
+ const urls = [...urlsByDomain.get(domain)?.values() ?? []].sort(
46
+ (a, b) => b.count - a.count || a.url.localeCompare(b.url)
47
+ );
48
+ const cited = {
49
+ domain,
50
+ count: urls.reduce((sum, url) => sum + url.count, 0),
51
+ isBrand: domain === brand,
52
+ urls
53
+ };
54
+ return cited;
55
+ };
56
+ const brandRow = {
57
+ ...domainOf(brand),
58
+ ...brandHostCounts.size > 0 && {
59
+ hosts: [...brandHostCounts].map(([label, count]) => ({ label, count })).sort((a, b) => b.count - a.count)
60
+ }
61
+ };
62
+ const others = [...urlsByDomain.keys()].filter((domain) => domain !== brand).map(domainOf).sort((a, b) => b.count - a.count || a.domain.localeCompare(b.domain));
63
+ const domains = [brandRow, ...others];
64
+ return domains;
65
+ };
66
+ var hostOf = (url) => {
67
+ try {
68
+ return normalizeDomain(new URL(url).hostname);
69
+ } catch {
70
+ return void 0;
71
+ }
72
+ };
73
+ var apexOf = (host) => {
74
+ const labels = host.split(".");
75
+ return labels.length <= 2 ? host : labels.slice(-2).join(".");
76
+ };
77
+ var brandHostLabel = (host, brand) => {
78
+ return host === brand ? "site" : host.slice(0, -(brand.length + 1));
79
+ };
80
+
81
+ export {
82
+ groupCitedDomains
83
+ };