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
@@ -0,0 +1,93 @@
1
+ Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+
5
+ This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -69,7 +69,10 @@ run needs reports present.
69
69
 
70
70
  Coding-agent surfaces (Claude Code, Codex, Cursor) are measured with the
71
71
  CLI's own login on this machine. They matter most when the buyers are
72
- developers. If the user cannot or will not set one up, remove it from
72
+ developers. A logged-in Claude Code tells the model the account's email, so
73
+ when the user audits their own company from their own account, suggest
74
+ `ANTHROPIC_API_KEY`, or `ANTHROPIC_AUTH_TOKEN` with `ANTHROPIC_BASE_URL`
75
+ for a gateway, in `.env` instead. If the user cannot or will not set one up, remove it from
73
76
  `surfaces` in `audit.json` in checkpoint 5 and tell them it is now out of
74
77
  scope for this audit.
75
78
 
@@ -13,7 +13,7 @@ import { canonicalDigest } from './json';
13
13
  export const toolId = 'literally-aeo';
14
14
  // The package version, recorded in every journal and bundle; the build and
15
15
  // version.spec.ts refuse a mismatch with package.json.
16
- export const toolVersion = '0.4.2';
16
+ export const toolVersion = '0.4.4';
17
17
  // Version 2: config.json may set chatProbes, and agentProbes.runsPerPrompt
18
18
  // above 2. A verifier that reads only version 1 then refuses the bundle as
19
19
  // unsupported instead of dropping its depth and failing it.
@@ -1,3 +1,4 @@
1
+ import { readFile } from 'node:fs/promises';
1
2
  import path from 'node:path';
2
3
  import {
3
4
  ExportBlockedError,
@@ -17,6 +18,8 @@ import { BundleRefusedError } from '../bundle/zip';
17
18
  import { readSettings } from '../engine/env-file';
18
19
  import { runDirectoryState } from '../engine/local-run';
19
20
  import { credentialSettingNames } from '../engine/preflight';
21
+ import { engineResources } from '../engine/resources';
22
+ import { viewerFontFiles } from '../viewer/page';
20
23
  import { startViewer } from '../viewer/server';
21
24
  import { formatLine, writeErr, writeOut, type Flags } from './io';
22
25
 
@@ -204,6 +207,23 @@ export const runVerify = async (flags: Flags, usage: string) => {
204
207
  return verification.exitCode;
205
208
  };
206
209
 
210
+ /** The viewer's fonts, from the engine's own resources. */
211
+ const readViewerFonts = async (): Promise<Map<string, Buffer>> => {
212
+ const { fonts } = await engineResources();
213
+ const entries = await Promise.all(
214
+ Object.values(viewerFontFiles).map(
215
+ async (file) => [file, await readFile(path.join(fonts, file))] as const,
216
+ ),
217
+ ).catch((err: unknown) => {
218
+ throw new Error(
219
+ `The viewer's fonts are missing from ${fonts}. In a checkout, run pnpm build to refresh resources/; otherwise reinstall literally-aeo.`,
220
+ { cause: err },
221
+ );
222
+ });
223
+
224
+ return new Map(entries);
225
+ };
226
+
207
227
  /** view serves a bundle or a run directory on loopback until Ctrl-C. */
208
228
  export const runView = async (flags: Flags, usage: string) => {
209
229
  const target = flags.positional[0];
@@ -231,6 +251,7 @@ export const runView = async (flags: Flags, usage: string) => {
231
251
  const portOption = flags.options.get('--port');
232
252
  const viewer = await startViewer(bundle, {
233
253
  port: portOption === undefined ? 0 : Number(portOption),
254
+ fonts: await readViewerFonts(),
234
255
  });
235
256
 
236
257
  writeOut(
@@ -69,7 +69,10 @@ run needs reports present.
69
69
 
70
70
  Coding-agent surfaces (Claude Code, Codex, Cursor) are measured with the
71
71
  CLI's own login on this machine. They matter most when the buyers are
72
- developers. If the user cannot or will not set one up, remove it from
72
+ developers. A logged-in Claude Code tells the model the account's email, so
73
+ when the user audits their own company from their own account, suggest
74
+ `ANTHROPIC_API_KEY`, or `ANTHROPIC_AUTH_TOKEN` with `ANTHROPIC_BASE_URL`
75
+ for a gateway, in `.env` instead. If the user cannot or will not set one up, remove it from
73
76
  `surfaces` in `audit.json` in checkpoint 5 and tell them it is now out of
74
77
  scope for this audit.
75
78
 
@@ -7,6 +7,7 @@ import {
7
7
  detectAgentClis,
8
8
  versionForSurface,
9
9
  } from '../probes/agent-clis';
10
+ import { cliAdapterProfiles } from '../probes/adapters/cli-agents';
10
11
  import {
11
12
  bindingOf,
12
13
  probeAdapterProfiles,
@@ -81,7 +82,9 @@ export const credentialSettingNames: readonly string[] = [
81
82
  export const runSettingNames = [
82
83
  gatewaySetting,
83
84
  ...overviewSettings,
84
- ...Object.values(agentAuthEnv).flatMap((auth) => auth.anyOf),
85
+ ...Object.values(cliAdapterProfiles).flatMap((profile) =>
86
+ profile.settings.map((setting) => setting.name),
87
+ ),
85
88
  ];
86
89
 
87
90
  // A coding agent's probes bill its own plan, outside the run's cap; an
@@ -4,11 +4,11 @@ import { enginePackageRoot } from './package-root';
4
4
 
5
5
  // ============================================================================
6
6
  // The engine's own files (specs/aeo-open-source-cli-spec.md §4.1): the copy
7
- // and author rules, the banlist, the neutral editorial context and the
8
- // operator guide. A packed install carries them in resources/; a checkout
9
- // reads them in place under src/. Never the caller's working directory, and
10
- // never a publisher's private editorial files unless AEO_EDITORIAL_DIR names
11
- // them.
7
+ // and author rules, the banlist, the neutral editorial context, the operator
8
+ // guide and the report viewer's fonts. A packed install carries them in
9
+ // resources/; a checkout reads them in place under src/. Never the caller's
10
+ // working directory, and never a publisher's private editorial files unless
11
+ // AEO_EDITORIAL_DIR names them.
12
12
  // ============================================================================
13
13
 
14
14
  export type EngineResources = {
@@ -18,6 +18,8 @@ export type EngineResources = {
18
18
  editorial: string;
19
19
  /** The operator guide `literally-aeo guide` prints. */
20
20
  guide: string;
21
+ /** The report viewer's fonts, served on loopback beside the page. */
22
+ fonts: string;
21
23
  };
22
24
 
23
25
  const exists = async (file: string) => {
@@ -38,6 +40,7 @@ export const engineResources = async (): Promise<EngineResources> => {
38
40
  author: path.join(packed, 'author'),
39
41
  editorial: path.join(packed, 'editorial'),
40
42
  guide: path.join(packed, 'guide', 'OPERATOR.md'),
43
+ fonts: path.join(packed, 'fonts'),
41
44
  };
42
45
  }
43
46
 
@@ -46,5 +49,6 @@ export const engineResources = async (): Promise<EngineResources> => {
46
49
  author: path.join(root, 'src', 'author'),
47
50
  editorial: path.join(root, 'src', 'engine', 'editorial'),
48
51
  guide: path.join(root, 'src', 'engine', 'guide', 'OPERATOR.md'),
52
+ fonts: path.join(root, 'src', 'viewer', 'fonts'),
49
53
  };
50
54
  };
@@ -71,4 +71,9 @@ DATAFORSEO_PASSWORD=
71
71
  CLAUDE_CODE_OAUTH_TOKEN=
72
72
  OPENAI_API_KEY=
73
73
  CURSOR_API_KEY=
74
+
75
+ # Claude Code through an Anthropic-compatible gateway, with no account
76
+ # identity (a logged-in Claude Code tells the model the account's email).
77
+ ANTHROPIC_AUTH_TOKEN=
78
+ ANTHROPIC_BASE_URL=
74
79
  `;
@@ -6,7 +6,6 @@ import { parseClaudeCodeStream } from '../agent-cli-parsers';
6
6
  import { childEnv } from '../child-process';
7
7
  import {
8
8
  attachCliOutput,
9
- authSettingNames,
10
9
  execCli,
11
10
  withScratchDir,
12
11
  type AgentProbeFn,
@@ -23,6 +22,17 @@ export const claudeCodeProfile: ProbeAdapterProfile = {
23
22
  group: 'auth',
24
23
  billsAccount: 'Anthropic',
25
24
  },
25
+ // A bearer token for an Anthropic-compatible gateway at
26
+ // ANTHROPIC_BASE_URL. Unlike the CLI's own login, it carries no account
27
+ // identity: a logged-in Claude Code tells the model the account's email,
28
+ // which tilts an audit run from the audited company's own account.
29
+ {
30
+ name: 'ANTHROPIC_AUTH_TOKEN',
31
+ secret: true,
32
+ group: 'auth',
33
+ billsAccount: 'gateway',
34
+ },
35
+ { name: 'ANTHROPIC_BASE_URL', secret: false },
26
36
  ],
27
37
  pool: 'claude_code',
28
38
  retry: 'agent',
@@ -31,10 +41,10 @@ export const claudeCodeProfile: ProbeAdapterProfile = {
31
41
  resolvesRedirects: false,
32
42
  };
33
43
 
34
- // Claude Code's auth variables and its config directory, nothing else from
35
- // the parent (§4.5).
44
+ // Claude Code's settings and its config directory, nothing else from the
45
+ // parent (§4.5).
36
46
  const claudeEnvKeys = [
37
- ...authSettingNames(claudeCodeProfile),
47
+ ...claudeCodeProfile.settings.map((setting) => setting.name),
38
48
  'CLAUDE_CONFIG_DIR',
39
49
  ];
40
50
 
@@ -237,6 +237,10 @@ export const runChild = (
237
237
  const baseEnvKeys = [
238
238
  'PATH',
239
239
  'HOME',
240
+ // macOS: a CLI's own login lives in the login Keychain, which Claude Code
241
+ // looks up by account name; without these it reports "Not logged in".
242
+ 'USER',
243
+ 'LOGNAME',
240
244
  'TMPDIR',
241
245
  'LANG',
242
246
  'LC_ALL',
@@ -3,8 +3,7 @@
3
3
  // percents, so the range a reader sees always contains the computed one.
4
4
  // Zod-free: the report page's client island imports it, and the fact
5
5
  // sentences use it, so every place that states an interval rounds it the
6
- // same way. The local viewer's page is a self-contained script and carries
7
- // its own copy of this rule (viewer/page.ts, `intervalText`).
6
+ // same way, the local viewer included (viewer/presentation.ts).
8
7
  // ============================================================================
9
8
 
10
9
  /** The whole-percent range that contains [low, high], two shares in 0..1.
@@ -0,0 +1,202 @@
1
+ import { normalizeDomain } from '../report/core/normalize-domain';
2
+ import { qualifiedCompetitorsForRow } from '../report/core/qualified-competitors';
3
+ import type { AeoMatrixRow } from '../report/core/schema';
4
+
5
+ // ============================================================================
6
+ // "Who buyers hear about instead": a section's qualified alternatives,
7
+ // grouped as the hosted report groups them (its `groupAlternatives`), so a
8
+ // business carries one name and one count on both pages. Entries on one
9
+ // domain are one alternative; a name given without a domain joins the one
10
+ // domain whose answers used that name.
11
+ // ============================================================================
12
+
13
+ export type RankedAlternative = {
14
+ name: string;
15
+ domain?: string;
16
+ /** Answers that name the alternative, each counted once. */
17
+ mentioning: number;
18
+ captured: number;
19
+ };
20
+
21
+ type Sighting = {
22
+ key: string;
23
+ domain?: string;
24
+ // Every spelling the answers used, with the rows that used it.
25
+ names: Map<string, Set<number>>;
26
+ rowIndices: Set<number>;
27
+ };
28
+
29
+ type Prospect = { name: string; domain: string };
30
+
31
+ /** rankAlternatives orders a section's alternatives by the answers that
32
+ * name them, most first. */
33
+ export const rankAlternatives = (
34
+ matrix: ReadonlyArray<
35
+ Pick<AeoMatrixRow, 'qualifiedCompetitors' | 'competitors'>
36
+ >,
37
+ prospect: Prospect,
38
+ ): RankedAlternative[] => {
39
+ const isProspect = matchesProspect(prospect);
40
+ const ranked = [...foldNameOnlySightings(collectSightings(matrix)).values()]
41
+ .filter((sighting) => !isProspect(sighting))
42
+ .map((sighting) => ({
43
+ name: displayName(sighting),
44
+ ...(sighting.domain !== undefined && { domain: sighting.domain }),
45
+ mentioning: sighting.rowIndices.size,
46
+ captured: matrix.length,
47
+ }))
48
+ .sort(
49
+ (a, b) => b.mentioning - a.mentioning || a.name.localeCompare(b.name),
50
+ );
51
+
52
+ return ranked;
53
+ };
54
+
55
+ const collectSightings = (
56
+ matrix: ReadonlyArray<
57
+ Pick<AeoMatrixRow, 'qualifiedCompetitors' | 'competitors'>
58
+ >,
59
+ ): Map<string, Sighting> => {
60
+ const sightings = new Map<string, Sighting>();
61
+
62
+ matrix.forEach((row, rowIndex) => {
63
+ for (const brand of qualifiedCompetitorsForRow(row)) {
64
+ const name = brand.name.trim();
65
+ const domain = brand.domain ? normalizeDomain(brand.domain) : undefined;
66
+ const key = domain ?? name.toLowerCase();
67
+ const sighting = sightings.get(key) ?? {
68
+ key,
69
+ names: new Map<string, Set<number>>(),
70
+ rowIndices: new Set<number>(),
71
+ };
72
+ const nameRows = sighting.names.get(name) ?? new Set<number>();
73
+
74
+ // A name-only first sighting takes the domain a later entry supplies.
75
+ sighting.domain ??= domain;
76
+ nameRows.add(rowIndex);
77
+ sighting.names.set(name, nameRows);
78
+ sighting.rowIndices.add(rowIndex);
79
+ sightings.set(key, sighting);
80
+ }
81
+ });
82
+
83
+ return sightings;
84
+ };
85
+
86
+ // The analyzer sometimes returns one brand with and without a domain, which
87
+ // lands under two keys.
88
+ const foldNameOnlySightings = (
89
+ sightings: ReadonlyMap<string, Sighting>,
90
+ ): Map<string, Sighting> => {
91
+ const domainKeysByName = new Map<string, Set<string>>();
92
+
93
+ for (const sighting of sightings.values()) {
94
+ if (sighting.domain === undefined) {
95
+ continue;
96
+ }
97
+
98
+ for (const name of sighting.names.keys()) {
99
+ const lowered = name.toLowerCase();
100
+ const keys = domainKeysByName.get(lowered) ?? new Set<string>();
101
+
102
+ keys.add(sighting.key);
103
+ domainKeysByName.set(lowered, keys);
104
+ }
105
+ }
106
+
107
+ const folded = new Map(sightings);
108
+
109
+ for (const sighting of sightings.values()) {
110
+ if (sighting.domain !== undefined) {
111
+ continue;
112
+ }
113
+
114
+ const [ownerKey, ...otherKeys] = [
115
+ ...(domainKeysByName.get(sighting.key) ?? []),
116
+ ];
117
+ const owner = ownerKey === undefined ? undefined : folded.get(ownerKey);
118
+
119
+ if (!owner || otherKeys.length > 0) {
120
+ continue;
121
+ }
122
+
123
+ folded.set(owner.key, mergeSightings(owner, sighting));
124
+ folded.delete(sighting.key);
125
+ }
126
+
127
+ return folded;
128
+ };
129
+
130
+ const mergeSightings = (owner: Sighting, nameOnly: Sighting): Sighting => {
131
+ const names = new Map(
132
+ [...owner.names].map(([name, rows]) => [name, new Set(rows)]),
133
+ );
134
+
135
+ for (const [name, rows] of nameOnly.names) {
136
+ names.set(name, new Set([...(names.get(name) ?? []), ...rows]));
137
+ }
138
+
139
+ const merged = {
140
+ ...owner,
141
+ names,
142
+ rowIndices: new Set([...owner.rowIndices, ...nameOnly.rowIndices]),
143
+ };
144
+
145
+ return merged;
146
+ };
147
+
148
+ /**
149
+ * displayName labels an alternative by what all its mentions share. When
150
+ * every name the answers used starts with the shortest one ("Rivalstack",
151
+ * "Rivalstack Edge"), that name, in its most-used spelling. Otherwise the
152
+ * entries are different products of one vendor, and the domain names the
153
+ * alternative, so no product is credited with its siblings' mentions.
154
+ */
155
+ const displayName = (sighting: Sighting): string => {
156
+ const spellings = [...sighting.names].map(([name, rows]) => ({
157
+ name,
158
+ words: name.toLowerCase().split(/\s+/),
159
+ answers: rows.size,
160
+ }));
161
+ const [base] = [...spellings].sort(
162
+ (a, b) =>
163
+ a.words.length - b.words.length ||
164
+ b.answers - a.answers ||
165
+ a.name.localeCompare(b.name),
166
+ );
167
+
168
+ if (!base) {
169
+ throw new Error(`Alternative has no recorded name: ${sighting.key}.`);
170
+ }
171
+
172
+ const isSharedBase = spellings.every((spelling) =>
173
+ base.words.every((word, index) => spelling.words[index] === word),
174
+ );
175
+
176
+ if (!isSharedBase && sighting.domain !== undefined) {
177
+ return sighting.domain;
178
+ }
179
+
180
+ // The base name's spellings ("RivalStack", "Rivalstack"): the one most answers used.
181
+ const [label] = spellings
182
+ .filter((spelling) => spelling.words.length === base.words.length)
183
+ .sort((a, b) => b.answers - a.answers || a.name.localeCompare(b.name));
184
+
185
+ return (label ?? base).name;
186
+ };
187
+
188
+ const matchesProspect = (prospect: Prospect) => {
189
+ const prospectName = prospect.name.trim().toLowerCase();
190
+ const prospectDomain = normalizeDomain(prospect.domain);
191
+
192
+ return (sighting: Sighting): boolean => {
193
+ const identity = sighting.domain ?? sighting.key;
194
+ const isProspectDomain =
195
+ identity === prospectDomain || identity.endsWith(`.${prospectDomain}`);
196
+ const isProspectName = [...sighting.names.keys()].some(
197
+ (name) => name.toLowerCase() === prospectName,
198
+ );
199
+
200
+ return isProspectDomain || isProspectName;
201
+ };
202
+ };
@@ -0,0 +1,127 @@
1
+ import { isGroundingRedirectUrl } from '../report/core/grounding';
2
+ import { normalizeDomain } from '../report/core/normalize-domain';
3
+ import type { AeoVisibility } from '../report/core/schema';
4
+
5
+ // ============================================================================
6
+ // "What gets cited": every URL a section's answers cited, grouped by domain
7
+ // as the hosted report groups them. The brand's own domain leads, even at
8
+ // zero (an answer that never cites the brand is the finding), with its
9
+ // citations split by host (site, blog, docs); every other host groups under
10
+ // its last two labels.
11
+ // ============================================================================
12
+
13
+ export type CitedUrl = {
14
+ url: string;
15
+ count: number;
16
+ /** Distinct surfaces and question texts that cited the URL, first seen first. */
17
+ surfaces: string[];
18
+ prompts: string[];
19
+ };
20
+
21
+ export type CitedDomain = {
22
+ domain: string;
23
+ count: number;
24
+ isBrand: boolean;
25
+ /** The brand's citations by host; present on the brand's row only. */
26
+ hosts?: Array<{ label: string; count: number }>;
27
+ urls: CitedUrl[];
28
+ };
29
+
30
+ /** groupCitedDomains lists the brand's row first, then every other domain
31
+ * by citations, most first. */
32
+ export const groupCitedDomains = (
33
+ visibility: Pick<AeoVisibility, 'matrix' | 'prompts'>,
34
+ brandDomain: string,
35
+ ): CitedDomain[] => {
36
+ const brand = normalizeDomain(brandDomain);
37
+ const urlsByDomain = new Map<string, Map<string, CitedUrl>>();
38
+ const brandHostCounts = new Map<string, number>();
39
+
40
+ for (const row of visibility.matrix) {
41
+ for (const url of row.citedUrls ?? []) {
42
+ // An unresolved grounding redirect is an opaque wrapper, not a
43
+ // citation of Google.
44
+ const host = isGroundingRedirectUrl(url) ? undefined : hostOf(url);
45
+
46
+ if (host === undefined) {
47
+ continue;
48
+ }
49
+
50
+ const isBrandHost = host === brand || host.endsWith(`.${brand}`);
51
+ const domain = isBrandHost ? brand : apexOf(host);
52
+ const urls = urlsByDomain.get(domain) ?? new Map<string, CitedUrl>();
53
+ const cited = urls.get(url) ?? {
54
+ url,
55
+ count: 0,
56
+ surfaces: [],
57
+ prompts: [],
58
+ };
59
+ const promptText = visibility.prompts[row.promptIdx]?.text;
60
+
61
+ cited.count += 1;
62
+ if (!cited.surfaces.includes(row.surface)) {
63
+ cited.surfaces.push(row.surface);
64
+ }
65
+ if (promptText !== undefined && !cited.prompts.includes(promptText)) {
66
+ cited.prompts.push(promptText);
67
+ }
68
+ urls.set(url, cited);
69
+ urlsByDomain.set(domain, urls);
70
+ if (isBrandHost) {
71
+ const label = brandHostLabel(host, brand);
72
+
73
+ brandHostCounts.set(label, (brandHostCounts.get(label) ?? 0) + 1);
74
+ }
75
+ }
76
+ }
77
+
78
+ const domainOf = (domain: string): CitedDomain => {
79
+ const urls = [...(urlsByDomain.get(domain)?.values() ?? [])].sort(
80
+ (a, b) => b.count - a.count || a.url.localeCompare(b.url),
81
+ );
82
+ const cited = {
83
+ domain,
84
+ count: urls.reduce((sum, url) => sum + url.count, 0),
85
+ isBrand: domain === brand,
86
+ urls,
87
+ };
88
+
89
+ return cited;
90
+ };
91
+ const brandRow: CitedDomain = {
92
+ ...domainOf(brand),
93
+ ...(brandHostCounts.size > 0 && {
94
+ hosts: [...brandHostCounts]
95
+ .map(([label, count]) => ({ label, count }))
96
+ .sort((a, b) => b.count - a.count),
97
+ }),
98
+ };
99
+ const others = [...urlsByDomain.keys()]
100
+ .filter((domain) => domain !== brand)
101
+ .map(domainOf)
102
+ .sort((a, b) => b.count - a.count || a.domain.localeCompare(b.domain));
103
+ const domains = [brandRow, ...others];
104
+
105
+ return domains;
106
+ };
107
+
108
+ const hostOf = (url: string): string | undefined => {
109
+ try {
110
+ return normalizeDomain(new URL(url).hostname);
111
+ } catch {
112
+ return undefined;
113
+ }
114
+ };
115
+
116
+ // The last two labels approximate the registrable domain (reddit.com). A
117
+ // multi-part public suffix (co.uk) collapses a level: the table is a
118
+ // grouping aid, not a registry.
119
+ const apexOf = (host: string): string => {
120
+ const labels = host.split('.');
121
+
122
+ return labels.length <= 2 ? host : labels.slice(-2).join('.');
123
+ };
124
+
125
+ const brandHostLabel = (host: string, brand: string): string => {
126
+ return host === brand ? 'site' : host.slice(0, -(brand.length + 1));
127
+ };