literally-aeo 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/README.md +42 -6
  2. package/dist/author-tools.js +33 -64
  3. package/dist/cli.mjs +2723 -1616
  4. package/dist/lib/agents/author-schema.js +4 -5
  5. package/dist/lib/agents/author-validation.js +5 -6
  6. package/dist/lib/agents/copy-validation.js +4 -5
  7. package/dist/lib/agents/verifier.js +8 -8
  8. package/dist/lib/analysis/domain-classifier.js +8 -8
  9. package/dist/lib/analysis/domain-labels.js +3 -4
  10. package/dist/lib/analysis/progress.js +3 -4
  11. package/dist/lib/analysis/sentiment.js +8 -8
  12. package/dist/lib/author/examples.js +5 -6
  13. package/dist/lib/bundle/contracts.js +5 -6
  14. package/dist/lib/bundle/export.js +22 -19
  15. package/dist/lib/bundle/isolation.js +17 -0
  16. package/dist/lib/bundle/journal.js +6 -7
  17. package/dist/lib/bundle/project-journal.js +11 -10
  18. package/dist/lib/bundle/project.js +19 -16
  19. package/dist/lib/bundle/read.js +23 -20
  20. package/dist/lib/bundle/recorder.js +9 -8
  21. package/dist/lib/bundle/redact.js +6 -7
  22. package/dist/lib/bundle/trace-coverage.js +6 -7
  23. package/dist/lib/bundle/verify-integrity.js +8 -9
  24. package/dist/lib/bundle/verify-measurement.js +10 -11
  25. package/dist/lib/bundle/verify-report.js +11 -12
  26. package/dist/lib/bundle/verify.js +17 -18
  27. package/dist/lib/bundle/writer-lock.js +3 -1
  28. package/dist/lib/capture-manifest.js +3 -4
  29. package/dist/lib/checks/run-checks.js +10 -9
  30. package/dist/lib/chunks/chunk-2B5QF6UQ.js +159 -0
  31. package/dist/lib/chunks/{chunk-ZBDUE3A5.js → chunk-2GU6CNQI.js} +12 -7
  32. package/dist/lib/chunks/{chunk-CKUTDJAB.js → chunk-2ROXN2EC.js} +42 -7
  33. package/dist/lib/chunks/{chunk-XHWRSGX3.js → chunk-3JO5TXBA.js} +1 -1
  34. package/dist/lib/chunks/{chunk-XL4JIQ5X.js → chunk-4PD65FRJ.js} +7 -3
  35. package/dist/lib/chunks/{chunk-GMKF2FU4.js → chunk-5JPYM4MD.js} +1 -1
  36. package/dist/lib/chunks/{chunk-5VNYUCLL.js → chunk-622NMXN6.js} +6 -9
  37. package/dist/lib/chunks/{chunk-XNRSHATN.js → chunk-663HABKP.js} +5 -5
  38. package/dist/lib/chunks/{chunk-RMFT4KKK.js → chunk-6G25V4CF.js} +1 -1
  39. package/dist/lib/chunks/{chunk-GVC4LH2N.js → chunk-6GHHNPFJ.js} +1 -1
  40. package/dist/lib/chunks/{chunk-KMRQSIZW.js → chunk-6GOBBNDU.js} +16 -1
  41. package/dist/lib/chunks/{chunk-SBAZBOPI.js → chunk-6P7EZJI7.js} +4 -2
  42. package/dist/lib/chunks/chunk-7XO3SQAX.js +117 -0
  43. package/dist/lib/chunks/{chunk-SWS3K62X.js → chunk-7Z27HQWL.js} +3 -3
  44. package/dist/lib/chunks/{chunk-IPNK7FYT.js → chunk-AYY4MYTW.js} +1 -1
  45. package/dist/lib/chunks/{chunk-WDSCJEDG.js → chunk-BE4ENGUY.js} +10 -10
  46. package/dist/lib/chunks/{chunk-FKLNEB2P.js → chunk-BGOIPHJZ.js} +39 -11
  47. package/dist/lib/chunks/{chunk-7GXRDAUY.js → chunk-BLKLPUYR.js} +2 -2
  48. package/dist/lib/chunks/chunk-BSRKN6FU.js +93 -0
  49. package/dist/lib/chunks/{chunk-PCYNBDZ7.js → chunk-CO5T6WU5.js} +14 -9
  50. package/dist/lib/chunks/{chunk-E3OEE5XN.js → chunk-CUYVHXHI.js} +2 -2
  51. package/dist/lib/chunks/{chunk-2GY42RIJ.js → chunk-D3GE3OCB.js} +1 -1
  52. package/dist/lib/chunks/chunk-DVFFYY5G.js +74 -0
  53. package/dist/lib/chunks/{chunk-ZXGATMMH.js → chunk-EBUQPCKB.js} +1 -1
  54. package/dist/lib/chunks/{chunk-4E4NDGOZ.js → chunk-EE26FNSY.js} +1 -1
  55. package/dist/lib/chunks/{chunk-AUB5THIS.js → chunk-EJ655TVU.js} +1 -1
  56. package/dist/lib/chunks/{chunk-S2AM76LT.js → chunk-F4W5YHDZ.js} +2 -2
  57. package/dist/lib/chunks/chunk-FAUFE7MI.js +31 -0
  58. package/dist/lib/chunks/{chunk-FNDJUELJ.js → chunk-FOCJ7HPC.js} +7 -7
  59. package/dist/lib/chunks/{chunk-FPAN3VRW.js → chunk-FUAUPNRO.js} +26 -18
  60. package/dist/lib/chunks/{chunk-OQVIRYT5.js → chunk-G62E525I.js} +2 -2
  61. package/dist/lib/chunks/{chunk-2NJEWPCV.js → chunk-GDKGZQ3T.js} +2 -2
  62. package/dist/lib/chunks/{chunk-HSZ3DM74.js → chunk-GEFKDW7X.js} +15 -2
  63. package/dist/lib/chunks/{chunk-47IZBMP2.js → chunk-GESHTTSA.js} +2 -2
  64. package/dist/lib/chunks/chunk-GNMFJ2OK.js +321 -0
  65. package/dist/lib/chunks/{chunk-NVBMIPXR.js → chunk-HFRAHG5C.js} +44 -26
  66. package/dist/lib/chunks/{chunk-MHAKYFDF.js → chunk-HQG63ZKO.js} +11 -11
  67. package/dist/lib/chunks/{chunk-OORO55OM.js → chunk-HTOD4W4E.js} +21 -6
  68. package/dist/lib/chunks/{chunk-Q2PWES4B.js → chunk-I3XGRGXE.js} +1 -1
  69. package/dist/lib/chunks/{chunk-WUELMJ22.js → chunk-IE7NAL6B.js} +1 -1
  70. package/dist/lib/chunks/{chunk-KRFHQQS7.js → chunk-JXMDOAKA.js} +17 -17
  71. package/dist/lib/chunks/{chunk-S7KJZIUR.js → chunk-KJMU5KH4.js} +2 -2
  72. package/dist/lib/chunks/{chunk-POUSX3T4.js → chunk-L7MEIRJB.js} +1 -1
  73. package/dist/lib/chunks/{chunk-CPT2GKKW.js → chunk-LOBXOZ2R.js} +1 -1
  74. package/dist/lib/chunks/{chunk-IAR6XGEW.js → chunk-ML4W6KC6.js} +1 -1
  75. package/dist/lib/chunks/{chunk-WKH6BJAZ.js → chunk-MNWO7EHC.js} +4 -4
  76. package/dist/lib/chunks/{chunk-D2LPQO6Y.js → chunk-MRL5RUP7.js} +1 -1
  77. package/dist/lib/chunks/{chunk-IEVAFDW7.js → chunk-NCXSNHXX.js} +3 -3
  78. package/dist/lib/chunks/{chunk-HFOYASRQ.js → chunk-NGHAP2P5.js} +4 -4
  79. package/dist/lib/chunks/{chunk-ZLOOC46D.js → chunk-OKL7GN2F.js} +3 -3
  80. package/dist/lib/chunks/{chunk-3DG7GHFA.js → chunk-OQU5IXAJ.js} +5 -5
  81. package/dist/lib/chunks/{chunk-I7VNIW6Q.js → chunk-OU73OUX4.js} +16 -10
  82. package/dist/lib/chunks/{chunk-56VOFZ7T.js → chunk-QHUDJVPJ.js} +90 -24
  83. package/dist/lib/chunks/{chunk-KHU5DRBE.js → chunk-QSJ4IKUF.js} +9 -9
  84. package/dist/lib/chunks/{chunk-FBFZBLTY.js → chunk-R6XDZWUL.js} +7 -8
  85. package/dist/lib/chunks/{chunk-CJ5YD3CU.js → chunk-RJ5R6YYA.js} +5 -5
  86. package/dist/lib/chunks/{chunk-LPND3VNQ.js → chunk-RR46EDDR.js} +33 -25
  87. package/dist/lib/chunks/chunk-RYCRL3YA.js +106 -0
  88. package/dist/lib/chunks/{chunk-Z4LMDKBU.js → chunk-SHUMCKCS.js} +2 -2
  89. package/dist/lib/chunks/{chunk-3EBWDHPK.js → chunk-TJQ5OPLQ.js} +10 -12
  90. package/dist/lib/chunks/chunk-U64NCRRR.js +97 -0
  91. package/dist/lib/chunks/chunk-U772TN32.js +67 -0
  92. package/dist/lib/chunks/{chunk-YR67JG2V.js → chunk-UEMZYHYJ.js} +8 -3
  93. package/dist/lib/chunks/{chunk-J46W3EMQ.js → chunk-UZJSTJFP.js} +5 -5
  94. package/dist/lib/chunks/{chunk-XJVXASDD.js → chunk-V7OAPKNF.js} +3 -3
  95. package/dist/lib/chunks/{chunk-WE2WPNG2.js → chunk-VKM6MMA4.js} +66 -7
  96. package/dist/lib/chunks/{chunk-YWJPJI3W.js → chunk-VL253W5C.js} +3 -1
  97. package/dist/lib/chunks/{chunk-MD4AVTK2.js → chunk-VPZQGND4.js} +3 -3
  98. package/dist/lib/chunks/{chunk-X2Y2ZNG3.js → chunk-W2VGLWTS.js} +3 -3
  99. package/dist/lib/chunks/{chunk-6AUEDSTU.js → chunk-W5DC23OP.js} +1 -1
  100. package/dist/lib/chunks/chunk-W5X7WJYL.js +91 -0
  101. package/dist/lib/chunks/{chunk-QFVRCSJ2.js → chunk-WDOA5JEH.js} +2 -0
  102. package/dist/lib/chunks/{chunk-I3TMFPK4.js → chunk-WVACVWBL.js} +2 -2
  103. package/dist/lib/chunks/{chunk-MIF5IYNR.js → chunk-XDG6NPJB.js} +26 -29
  104. package/dist/lib/chunks/{chunk-X6E44EGV.js → chunk-XR44YSHT.js} +2 -2
  105. package/dist/lib/chunks/chunk-Y2CZ6FZY.js +61 -0
  106. package/dist/lib/chunks/{chunk-5KKLUM7M.js → chunk-YAAUWCJ4.js} +1 -1
  107. package/dist/lib/chunks/{chunk-3KQFLOC7.js → chunk-YRBIC5QH.js} +1 -1
  108. package/dist/lib/chunks/chunk-ZIGNJAPC.js +11 -0
  109. package/dist/lib/cli/bundle-commands.js +71 -65
  110. package/dist/lib/cli/guide-command.js +25 -0
  111. package/dist/lib/cli/io.js +1 -1
  112. package/dist/lib/cli/run-commands.js +270 -104
  113. package/dist/lib/cli/status-command.js +234 -0
  114. package/dist/lib/codex-workflow/aggregate.js +8 -9
  115. package/dist/lib/codex-workflow/author-tools.js +6 -7
  116. package/dist/lib/codex-workflow/author.js +17 -17
  117. package/dist/lib/codex-workflow/capture.js +10 -9
  118. package/dist/lib/codex-workflow/checkpoint.js +6 -7
  119. package/dist/lib/codex-workflow/checks.js +6 -7
  120. package/dist/lib/codex-workflow/codex-binary.js +13 -0
  121. package/dist/lib/codex-workflow/codex-home.js +6 -3
  122. package/dist/lib/codex-workflow/copy-editor.js +14 -14
  123. package/dist/lib/codex-workflow/copy-recovery.js +3 -4
  124. package/dist/lib/codex-workflow/copy.js +11 -11
  125. package/dist/lib/codex-workflow/finish.js +17 -18
  126. package/dist/lib/codex-workflow/host-models.js +7 -7
  127. package/dist/lib/codex-workflow/loop.js +42 -38
  128. package/dist/lib/codex-workflow/quality.js +3 -4
  129. package/dist/lib/codex-workflow/run-inputs.js +5 -6
  130. package/dist/lib/codex-workflow/run-source.js +14 -13
  131. package/dist/lib/codex-workflow/schemas.js +5 -6
  132. package/dist/lib/codex-workflow/session.js +7 -8
  133. package/dist/lib/codex-workflow/stage.js +26 -23
  134. package/dist/lib/codex-workflow/workdir.js +6 -7
  135. package/dist/lib/engine/audit-file.js +7 -6
  136. package/dist/lib/engine/author.js +37 -31
  137. package/dist/lib/engine/budget.js +7 -1
  138. package/dist/lib/engine/cost-estimate.js +41 -0
  139. package/dist/lib/engine/local-run.js +48 -42
  140. package/dist/lib/engine/preflight.js +10 -6
  141. package/dist/lib/engine/rejudge.js +56 -50
  142. package/dist/lib/engine/resources.js +1 -1
  143. package/dist/lib/engine/run-configuration.js +2 -1
  144. package/dist/lib/engine/run-status.js +151 -0
  145. package/dist/lib/engine/templates.js +8 -7
  146. package/dist/lib/grounding/controller.js +7 -7
  147. package/dist/lib/grounding/extract.js +6 -6
  148. package/dist/lib/grounding/grounding-runtime.js +18 -17
  149. package/dist/lib/grounding/model.js +5 -5
  150. package/dist/lib/grounding/recorded-tools.js +10 -9
  151. package/dist/lib/harness/report/artifacts.js +4 -5
  152. package/dist/lib/lib/checkpoint.js +3 -4
  153. package/dist/lib/models/batching.js +5 -5
  154. package/dist/lib/models/cost-coefficients.js +20 -0
  155. package/dist/lib/models/local-profile.js +10 -0
  156. package/dist/lib/models/pricing.js +6 -0
  157. package/dist/lib/models/profiles.js +7 -14
  158. package/dist/lib/models/structured-images.js +1 -1
  159. package/dist/lib/models/structured.js +4 -4
  160. package/dist/lib/models/supported-models.js +20 -0
  161. package/dist/lib/pipeline.js +9 -8
  162. package/dist/lib/probes/agent-cli-parsers.js +1 -1
  163. package/dist/lib/probes/agent-clis.js +6 -5
  164. package/dist/lib/probes/charged-trace.js +10 -0
  165. package/dist/lib/probes/probes.js +6 -6
  166. package/dist/lib/runner.js +10 -10
  167. package/dist/lib/schema.js +3 -4
  168. package/dist/lib/section-result.js +3 -4
  169. package/dist/lib/stores/artifacts.js +3 -4
  170. package/dist/lib/stores/files.js +9 -9
  171. package/dist/lib/stores/local-versions.js +4 -5
  172. package/dist/lib/stores/memory.js +6 -7
  173. package/dist/lib/stores/publication.js +5 -6
  174. package/dist/lib/viewer/server.js +18 -19
  175. package/dist/lib/workflow/schema.js +2 -3
  176. package/dist/types/agents/copy-validation.d.ts +4 -4
  177. package/dist/types/agents/verifier.d.ts +6 -6
  178. package/dist/types/bundle/contracts.d.ts +1 -1
  179. package/dist/types/bundle/isolation.d.ts +37 -0
  180. package/dist/types/bundle/project-journal.d.ts +2 -0
  181. package/dist/types/bundle/recorder.d.ts +4 -0
  182. package/dist/types/bundle/writer-lock.d.ts +9 -0
  183. package/dist/types/cli/guide-command.d.ts +4 -0
  184. package/dist/types/cli/status-command.d.ts +2 -0
  185. package/dist/types/codex-workflow/codex-binary.d.ts +26 -0
  186. package/dist/types/codex-workflow/codex-home.d.ts +24 -20
  187. package/dist/types/codex-workflow/copy-editor.d.ts +1 -1
  188. package/dist/types/codex-workflow/copy.d.ts +3 -4
  189. package/dist/types/codex-workflow/finish.d.ts +5 -3
  190. package/dist/types/codex-workflow/host-models.d.ts +7 -3
  191. package/dist/types/codex-workflow/loop.d.ts +10 -1
  192. package/dist/types/codex-workflow/run-inputs.d.ts +28 -113
  193. package/dist/types/codex-workflow/stage.d.ts +16 -5
  194. package/dist/types/engine/audit-file.d.ts +3 -2
  195. package/dist/types/engine/author.d.ts +7 -1
  196. package/dist/types/engine/budget.d.ts +46 -15
  197. package/dist/types/engine/cost-estimate.d.ts +40 -0
  198. package/dist/types/engine/local-run.d.ts +6 -0
  199. package/dist/types/engine/preflight.d.ts +5 -0
  200. package/dist/types/engine/resources.d.ts +2 -0
  201. package/dist/types/engine/run-configuration.d.ts +4 -3
  202. package/dist/types/engine/run-status.d.ts +75 -0
  203. package/dist/types/engine/templates.d.ts +1 -2
  204. package/dist/types/models/cost-coefficients.d.ts +106 -0
  205. package/dist/types/models/local-profile.d.ts +12 -0
  206. package/dist/types/models/pricing.d.ts +8 -0
  207. package/dist/types/models/profiles.d.ts +55 -160
  208. package/dist/types/models/served-model.d.ts +2 -3
  209. package/dist/types/models/structured.d.ts +3 -3
  210. package/dist/types/models/supported-models.d.ts +48 -0
  211. package/dist/types/probes/charged-trace.d.ts +8 -0
  212. package/dist/types/probes/probe-trace.d.ts +2 -0
  213. package/dist/types/schema.d.ts +28 -113
  214. package/dist/types/workflow/schema.d.ts +79 -152
  215. package/package.json +2 -1
  216. package/resources/guide/OPERATOR.md +180 -0
  217. package/src/agents/copy-validation.ts +8 -12
  218. package/src/agents/verifier.ts +10 -14
  219. package/src/bundle/contracts.ts +3 -3
  220. package/src/bundle/isolation.ts +157 -0
  221. package/src/bundle/project-journal.ts +4 -0
  222. package/src/bundle/project.ts +20 -7
  223. package/src/bundle/recorder.ts +5 -0
  224. package/src/bundle/writer-lock.ts +27 -0
  225. package/src/cli/guide-command.ts +28 -0
  226. package/src/cli/io.ts +2 -0
  227. package/src/cli/literally-aeo.ts +39 -19
  228. package/src/cli/run-commands.ts +236 -18
  229. package/src/cli/status-command.ts +113 -0
  230. package/src/codex-workflow/codex-binary.ts +105 -0
  231. package/src/codex-workflow/codex-home.ts +50 -40
  232. package/src/codex-workflow/copy.ts +7 -10
  233. package/src/codex-workflow/finish.ts +13 -8
  234. package/src/codex-workflow/host-models.ts +33 -24
  235. package/src/codex-workflow/loop.ts +36 -9
  236. package/src/codex-workflow/stage.ts +126 -17
  237. package/src/engine/audit-file.ts +10 -8
  238. package/src/engine/author.ts +47 -2
  239. package/src/engine/budget.ts +138 -43
  240. package/src/engine/cost-estimate.ts +178 -0
  241. package/src/engine/guide/OPERATOR.md +180 -0
  242. package/src/engine/local-run.ts +38 -8
  243. package/src/engine/preflight.ts +90 -7
  244. package/src/engine/resources.ts +9 -4
  245. package/src/engine/run-configuration.ts +19 -1
  246. package/src/engine/run-status.ts +452 -0
  247. package/src/engine/templates.ts +5 -2
  248. package/src/models/cost-coefficients.ts +140 -0
  249. package/src/models/local-profile.ts +150 -0
  250. package/src/models/pricing.ts +31 -0
  251. package/src/models/profiles.ts +58 -419
  252. package/src/models/served-model.ts +2 -3
  253. package/src/models/structured-images.ts +5 -4
  254. package/src/models/structured.ts +20 -7
  255. package/src/models/supported-models.ts +112 -0
  256. package/src/probes/agent-clis.ts +24 -2
  257. package/src/probes/charged-trace.ts +87 -0
  258. package/src/probes/probe-trace.ts +2 -0
  259. package/src/probes/probes.ts +48 -2
  260. package/dist/lib/chunks/chunk-CFFPOTP4.js +0 -356
  261. package/dist/lib/chunks/chunk-LIZX4N3H.js +0 -110
  262. package/dist/lib/chunks/chunk-OYKV5NDM.js +0 -28
@@ -0,0 +1,112 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ codexStageModelSchema,
4
+ internalModelRoleSchema,
5
+ modelPricingSchema,
6
+ } from './profiles';
7
+
8
+ // ============================================================================
9
+ // The models a local run may judge, research and write with
10
+ // (specs/aeo-claude-operator-spec.md §4.1): one gateway model runs every
11
+ // text role and the Codex stages. Each entry holds public facts only (list
12
+ // prices with the date they were checked, the context window, the output
13
+ // ceiling) and what the engine has verified about it. Adding or changing a
14
+ // model is a release of the package; a run records the profile built from
15
+ // the entry it resolved (src/models/local-profile.ts).
16
+ // ============================================================================
17
+
18
+ export const supportedModelSchema = z
19
+ .object({
20
+ /** The gateway model ID, as audit.json's `model` names it. */
21
+ id: z.string().min(1),
22
+ label: z.string().min(1),
23
+ pricingUsdPerMillion: modelPricingSchema,
24
+ pricingCheckedAt: z.iso.date(),
25
+ contextWindow: z.number().int().positive(),
26
+ maxOutputTokens: z.number().int().positive(),
27
+ /** The model's hidden reasoning is billed inside the output allowance,
28
+ * so every role is given room to think on top of its answer. */
29
+ thinkingInOutput: z.boolean(),
30
+ providerOptions: internalModelRoleSchema.shape.providerOptions,
31
+ stageReasoningEffort: codexStageModelSchema.shape.reasoningEffort,
32
+ /** The date a real batch ran through the gateway on Codex's Responses
33
+ * wire API with this model (the spike, spec §4.3); null until then. */
34
+ stageRuntimeVerifiedAt: z.iso.date().nullable(),
35
+ })
36
+ .strict();
37
+
38
+ export type SupportedModel = z.infer<typeof supportedModelSchema>;
39
+
40
+ export const supportedModels: readonly SupportedModel[] = [
41
+ {
42
+ id: 'anthropic/claude-opus-5.5',
43
+ label: 'Claude Opus 5.5',
44
+ pricingUsdPerMillion: { input: 4, output: 20, cachedInput: 0.2 },
45
+ pricingCheckedAt: '2026-11-04',
46
+ contextWindow: 1_000_000,
47
+ maxOutputTokens: 128_000,
48
+ thinkingInOutput: true,
49
+ providerOptions: { gateway: { reasoning: { effort: 'high' } } },
50
+ stageReasoningEffort: 'high',
51
+ stageRuntimeVerifiedAt: '2026-11-04',
52
+ },
53
+ {
54
+ id: 'anthropic/claude-sonnet-5.5',
55
+ label: 'Claude Sonnet 5.5',
56
+ pricingUsdPerMillion: { input: 2, output: 10, cachedInput: 0.2 },
57
+ pricingCheckedAt: '2026-11-04',
58
+ contextWindow: 1_000_000,
59
+ maxOutputTokens: 128_000,
60
+ thinkingInOutput: true,
61
+ providerOptions: { gateway: { reasoning: { effort: 'high' } } },
62
+ stageReasoningEffort: 'high',
63
+ stageRuntimeVerifiedAt: '2026-11-04',
64
+ },
65
+ ];
66
+
67
+ /** The model a run uses when audit.json names none: the strongest the
68
+ * engine supports, because judgment and copy quality are the report. */
69
+ export const recommendedModelId = 'anthropic/claude-opus-5.5';
70
+
71
+ /** The supported models as a list a person or an agent can read. */
72
+ export const describeSupportedModels = (): string[] => {
73
+ const lines = supportedModels.map((model) => {
74
+ const { input, cachedInput, output } = model.pricingUsdPerMillion;
75
+ const recommended = model.id === recommendedModelId ? ' (recommended)' : '';
76
+
77
+ return `${model.id}${recommended}: ${model.label}, $${input} in / $${cachedInput} cached / $${output} out per million tokens (checked ${model.pricingCheckedAt})`;
78
+ });
79
+
80
+ return lines;
81
+ };
82
+
83
+ /** findSupportedModel returns the list's entry for a gateway model ID. */
84
+ export const findSupportedModel = (id: string): SupportedModel | undefined => {
85
+ return supportedModels.find((model) => model.id === id);
86
+ };
87
+
88
+ export class UnsupportedModelError extends Error {
89
+ constructor(id: string) {
90
+ super(
91
+ [
92
+ `${id} is not a supported model. Set audit.json's "model" to one of:`,
93
+ ...describeSupportedModels().map((line) => ` ${line}`),
94
+ ].join('\n'),
95
+ );
96
+ this.name = 'UnsupportedModelError';
97
+ }
98
+ }
99
+
100
+ /** resolveSupportedModel returns the entry a run uses: the named model, or
101
+ * the recommended one when none is named. An unknown ID is refused. */
102
+ export const resolveSupportedModel = (
103
+ id: string = recommendedModelId,
104
+ ): SupportedModel => {
105
+ const model = findSupportedModel(id);
106
+
107
+ if (!model) {
108
+ throw new UnsupportedModelError(id);
109
+ }
110
+
111
+ return model;
112
+ };
@@ -14,6 +14,7 @@ import { agentSurfaces, surfaceRunCounts, retrievalLogSchema } from '../schema';
14
14
  import { createLog } from '../lib/log';
15
15
  import { isRecord } from '../lib/type-guards';
16
16
  import { getEnvironment, readEnv } from '../lib/env';
17
+ import { codexArgs, resolveCodexBinary } from '../codex-workflow/codex-binary';
17
18
  import type { ProbePromptInput, ProbeResult } from './probes';
18
19
  import {
19
20
  AgentStreamError,
@@ -321,6 +322,23 @@ const probeForSurface = (surface: AeoAgentSurface): AgentProbeFn => {
321
322
  }
322
323
  };
323
324
 
325
+ /** What to spawn for an agent CLI on this machine. Codex is this package's
326
+ * own pinned dependency (specs/aeo-claude-operator-spec.md §4.3), run with
327
+ * the operator's Codex login when it is measured; the others come from
328
+ * PATH. */
329
+ const localCommand = (
330
+ command: string,
331
+ args: readonly string[],
332
+ ): { command: string; args: string[] } => {
333
+ if (command !== 'codex') {
334
+ return { command, args: [...args] };
335
+ }
336
+
337
+ const binary = resolveCodexBinary();
338
+
339
+ return { command: binary.command, args: codexArgs(binary, args) };
340
+ };
341
+
324
342
  const cliVersion = async (
325
343
  command: string,
326
344
  args: string[],
@@ -340,7 +358,10 @@ const cliVersion = async (
340
358
  requireWorkerTransport();
341
359
  }
342
360
 
343
- const { stdout } = await execFileAsync(command, args, { timeout: 15_000 });
361
+ const local = localCommand(command, args);
362
+ const { stdout } = await execFileAsync(local.command, local.args, {
363
+ timeout: 15_000,
364
+ });
344
365
 
345
366
  return stdout.trim().split('\n')[0] ?? null;
346
367
  } catch {
@@ -1218,7 +1239,8 @@ const execCli = async (
1218
1239
  command: string,
1219
1240
  { cliArgs, cwd, runtime, env, signal }: ExecCliOptions,
1220
1241
  ): Promise<CliOutput> => {
1221
- const result = await runChild(command, cliArgs, {
1242
+ const local = localCommand(command, cliArgs);
1243
+ const result = await runChild(local.command, local.args, {
1222
1244
  cwd,
1223
1245
  env,
1224
1246
  timeoutMs: runtime.timeoutMs ?? agentProbeTimeoutMs,
@@ -0,0 +1,87 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import {
3
+ ModelBudgetError,
4
+ type ModelCallAccounting,
5
+ } from '../models/accounting';
6
+ import { probeUsd } from '../models/cost-coefficients';
7
+ import type { ProbeTrace } from './probe-trace';
8
+
9
+ // ============================================================================
10
+ // Probes on the run's ledger (specs/aeo-claude-operator-spec.md §4.2): every
11
+ // probe attempt is reserved at its surface's high estimate before it is
12
+ // dispatched and settled with the cost the gateway reported; one that
13
+ // reported none keeps charging its estimate. An attempt the cap cannot afford is never
14
+ // dispatched; the run learns of it through `exhausted` and stops resumable,
15
+ // with every answer captured so far banked.
16
+ // ============================================================================
17
+
18
+ export type ChargedTrace = {
19
+ trace: ProbeTrace;
20
+ /** The first refusal of the cap, once an attempt was refused. */
21
+ exhausted: () => ModelBudgetError | undefined;
22
+ };
23
+
24
+ export const chargedProbeTrace = (
25
+ trace: ProbeTrace,
26
+ ledger: ModelCallAccounting,
27
+ ): ChargedTrace => {
28
+ let refused: ModelBudgetError | undefined;
29
+
30
+ const charged: ProbeTrace = {
31
+ start: async (attempt) => {
32
+ const estimateUsd = probeUsd[attempt.surface].high;
33
+ const callId = `probe:${attempt.surface}:${attempt.promptId}:${attempt.runIndex}:${attempt.attempt}:${randomUUID()}`;
34
+ // The coding-agent surfaces run on the operator's own login.
35
+ const isPaid = estimateUsd > 0;
36
+
37
+ if (isPaid) {
38
+ try {
39
+ await ledger.reserve({
40
+ callId,
41
+ role: `probe:${attempt.surface}`,
42
+ ...(attempt.requestedModel !== null && {
43
+ requestedModel: attempt.requestedModel,
44
+ }),
45
+ reservedUsd: estimateUsd,
46
+ inputTokens: 0,
47
+ maxOutputTokens: 0,
48
+ });
49
+ } catch (error) {
50
+ if (error instanceof ModelBudgetError) {
51
+ refused ??= error;
52
+ }
53
+
54
+ throw error;
55
+ }
56
+ }
57
+
58
+ const handle = await trace.start(attempt);
59
+
60
+ return {
61
+ id: handle.id,
62
+ end: async (result) => {
63
+ await handle.end(result);
64
+
65
+ if (!isPaid) {
66
+ return;
67
+ }
68
+
69
+ const reportedUsd =
70
+ result.outcome === 'succeeded' ? result.costUsd : undefined;
71
+
72
+ // Without a reported cost the call keeps charging its estimate,
73
+ // and the ledger records no cost the provider did not report.
74
+ await ledger.settle(callId, {
75
+ ...(attempt.requestedModel !== null && {
76
+ requestedModel: attempt.requestedModel,
77
+ }),
78
+ ...(reportedUsd !== undefined && { costUsd: reportedUsd }),
79
+ ...(result.outcome !== 'succeeded' && { valid: false }),
80
+ });
81
+ },
82
+ };
83
+ },
84
+ };
85
+
86
+ return { trace: charged, exhausted: () => refused };
87
+ };
@@ -29,6 +29,8 @@ export type ProbeAttemptEnd =
29
29
  requestedModel: string | null;
30
30
  reportedModel?: string;
31
31
  noOverview?: true;
32
+ /** What the provider reported the attempt cost, when it did. */
33
+ costUsd?: number;
32
34
  }
33
35
  | {
34
36
  outcome: 'failed' | 'cancelled';
@@ -8,6 +8,7 @@ import { chatSurfaces, surfaceRunCounts } from '../schema';
8
8
  import { surfaceRetrievalExposure } from '../retrieval';
9
9
  import { createLog } from '../lib/log';
10
10
  import { servedModelOf } from '../models/served-model';
11
+ import { isObject } from '../lib/type-guards';
11
12
  import {
12
13
  endAttempt,
13
14
  ProbeTraceError,
@@ -141,6 +142,36 @@ type ProbeAnswer = {
141
142
  retrieval: RetrievalLog | null;
142
143
  noOverview?: true;
143
144
  reportedModel?: string;
145
+ /** What the gateway reported the probe's calls cost; absent when it did
146
+ * not say. The ledger then settles the probe at its estimate. */
147
+ reportedCostUsd?: number;
148
+ };
149
+
150
+ /** The cost the gateway reports in a response's provider metadata. */
151
+ const gatewayCostOf = (metadata: unknown): number | undefined => {
152
+ const cost =
153
+ isObject(metadata) && isObject(metadata.gateway)
154
+ ? metadata.gateway.cost
155
+ : undefined;
156
+ const usd = typeof cost === 'string' && cost.trim() ? Number(cost) : cost;
157
+
158
+ return typeof usd === 'number' && Number.isFinite(usd) && usd >= 0
159
+ ? usd
160
+ : undefined;
161
+ };
162
+
163
+ /** The reported costs of a probe's calls, summed; absent unless every call
164
+ * reported one. */
165
+ const reportedCostOf = (
166
+ costs: readonly (number | undefined)[],
167
+ ): { reportedCostUsd?: number } => {
168
+ if (costs.some((cost) => cost === undefined)) {
169
+ return {};
170
+ }
171
+
172
+ return {
173
+ reportedCostUsd: costs.reduce<number>((sum, cost) => sum + (cost ?? 0), 0),
174
+ };
144
175
  };
145
176
 
146
177
  type ProbeModelConfig = {
@@ -289,11 +320,14 @@ const runSearchRequiredProbe = async (args: {
289
320
  retrieval = null;
290
321
  }
291
322
 
323
+ const firstCost = gatewayCostOf(first.providerMetadata);
324
+
292
325
  if (first.text.trim().length > 0) {
293
326
  return {
294
327
  text: withProbeSources(first.text, first.sources),
295
328
  retrieval,
296
329
  ...served,
330
+ ...reportedCostOf([firstCost]),
297
331
  };
298
332
  }
299
333
 
@@ -329,9 +363,10 @@ const runSearchRequiredProbe = async (args: {
329
363
  abortSignal: AbortSignal.timeout(chatProbeTimeoutMs),
330
364
  });
331
365
 
332
- const [followupText, followupSources] = await Promise.all([
366
+ const [followupText, followupSources, followupMetadata] = await Promise.all([
333
367
  followupStream.text,
334
368
  followupStream.sources,
369
+ followupStream.providerMetadata,
335
370
  ]).catch((error: unknown) => {
336
371
  throw followupFailure ?? error;
337
372
  });
@@ -346,6 +381,7 @@ const runSearchRequiredProbe = async (args: {
346
381
  ),
347
382
  retrieval,
348
383
  ...served,
384
+ ...reportedCostOf([firstCost, gatewayCostOf(followupMetadata)]),
349
385
  };
350
386
  }
351
387
 
@@ -443,8 +479,14 @@ const buildProbeModels = (args: {
443
479
  stream.text,
444
480
  stream.sources,
445
481
  stream.response,
482
+ stream.providerMetadata,
446
483
  ])
447
- .then(([text, sources, response]) => ({ text, sources, response }))
484
+ .then(([text, sources, response, providerMetadata]) => ({
485
+ text,
486
+ sources,
487
+ response,
488
+ providerMetadata,
489
+ }))
448
490
  .catch((error: unknown) => {
449
491
  throw streamFailure ?? error;
450
492
  });
@@ -465,6 +507,7 @@ const buildProbeModels = (args: {
465
507
  text: withProbeSources(result.text, result.sources),
466
508
  retrieval: unexposedRetrieval('perplexity'),
467
509
  ...(reportedModel === undefined ? {} : { reportedModel }),
510
+ ...reportedCostOf([gatewayCostOf(result.providerMetadata)]),
468
511
  };
469
512
  },
470
513
  },
@@ -744,6 +787,9 @@ const runChatUnit = async (
744
787
  requestedModel: chatProbeRequestedModel(model.name),
745
788
  ...(answer.reportedModel ? { reportedModel: answer.reportedModel } : {}),
746
789
  ...(answer.noOverview ? { noOverview: true as const } : {}),
790
+ ...(answer.reportedCostUsd === undefined
791
+ ? {}
792
+ : { costUsd: answer.reportedCostUsd }),
747
793
  });
748
794
 
749
795
  if (unrecorded !== null) {