literally-aeo 0.1.1 → 0.2.1

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 (369) hide show
  1. package/README.md +71 -7
  2. package/dist/author-tools.js +512 -461
  3. package/dist/cli.mjs +3512 -2010
  4. package/dist/lib/access/schema.js +6 -6
  5. package/dist/lib/agents/author-schema.js +11 -12
  6. package/dist/lib/agents/author-validation.js +19 -20
  7. package/dist/lib/agents/copy-validation.js +22 -22
  8. package/dist/lib/agents/copywriter-input.js +22 -7
  9. package/dist/lib/agents/facts.js +21 -6
  10. package/dist/lib/agents/narrative-facts.js +20 -2
  11. package/dist/lib/agents/verifier.js +26 -25
  12. package/dist/lib/analysis/domain-classifier.js +21 -22
  13. package/dist/lib/analysis/domain-labels.js +11 -12
  14. package/dist/lib/analysis/progress-schema.js +2 -2
  15. package/dist/lib/analysis/progress.js +19 -21
  16. package/dist/lib/analysis/retrieval.js +20 -3
  17. package/dist/lib/analysis/scoring.js +20 -3
  18. package/dist/lib/analysis/search-analyzer.js +19 -5
  19. package/dist/lib/analysis/sentiment.js +18 -19
  20. package/dist/lib/author/examples.js +12 -13
  21. package/dist/lib/bundle/contracts.js +15 -14
  22. package/dist/lib/bundle/export.js +34 -31
  23. package/dist/lib/bundle/isolation.js +17 -0
  24. package/dist/lib/bundle/journal.js +14 -15
  25. package/dist/lib/bundle/project-journal.js +19 -18
  26. package/dist/lib/bundle/project.js +31 -28
  27. package/dist/lib/bundle/read.js +35 -32
  28. package/dist/lib/bundle/recorder.js +17 -16
  29. package/dist/lib/bundle/redact.js +14 -15
  30. package/dist/lib/bundle/trace-coverage.js +14 -15
  31. package/dist/lib/bundle/verify-integrity.js +16 -17
  32. package/dist/lib/bundle/verify-measurement.js +22 -23
  33. package/dist/lib/bundle/verify-report.js +29 -30
  34. package/dist/lib/bundle/verify.js +37 -38
  35. package/dist/lib/bundle/writer-lock.js +3 -1
  36. package/dist/lib/capture-manifest.js +13 -14
  37. package/dist/lib/checks/crawler-access.js +4 -1
  38. package/dist/lib/checks/renderability.js +5 -1
  39. package/dist/lib/checks/run-checks.js +23 -19
  40. package/dist/lib/chunks/chunk-2B5QF6UQ.js +159 -0
  41. package/dist/lib/chunks/chunk-2FOKEIIN.js +93 -0
  42. package/dist/lib/chunks/{chunk-KRFHQQS7.js → chunk-2KH7LNK7.js} +24 -24
  43. package/dist/lib/chunks/{chunk-NVBMIPXR.js → chunk-3GPUCXVA.js} +44 -26
  44. package/dist/lib/chunks/{chunk-3EBWDHPK.js → chunk-3OE4UQIB.js} +14 -16
  45. package/dist/lib/chunks/{chunk-FNDJUELJ.js → chunk-3OWJBGQE.js} +14 -14
  46. package/dist/lib/chunks/{chunk-Y4OGZ3Q5.js → chunk-46PVVQYR.js} +1 -1
  47. package/dist/lib/chunks/{chunk-EV4DRS5M.js → chunk-4XIAXX7K.js} +1 -1
  48. package/dist/lib/chunks/{chunk-IBOWGKN7.js → chunk-52F5XYOW.js} +1 -1
  49. package/dist/lib/chunks/{chunk-3DG7GHFA.js → chunk-66DVMLGR.js} +10 -10
  50. package/dist/lib/chunks/{chunk-FFOVLI3U.js → chunk-66T7JC57.js} +12 -10
  51. package/dist/lib/chunks/{chunk-KMRQSIZW.js → chunk-6GOBBNDU.js} +16 -1
  52. package/dist/lib/chunks/{chunk-WUELMJ22.js → chunk-6HMHXSCS.js} +2 -2
  53. package/dist/lib/chunks/{chunk-SWS3K62X.js → chunk-6JICXLDA.js} +3 -3
  54. package/dist/lib/chunks/{chunk-SBAZBOPI.js → chunk-6P7EZJI7.js} +4 -2
  55. package/dist/lib/chunks/chunk-75DMLOQ7.js +127 -0
  56. package/dist/lib/chunks/{chunk-RMFT4KKK.js → chunk-7CW6U5WJ.js} +1 -1
  57. package/dist/lib/chunks/{chunk-5VNYUCLL.js → chunk-7HM6IZ3L.js} +6 -9
  58. package/dist/lib/chunks/{chunk-X6E44EGV.js → chunk-7LBSNDRR.js} +10 -8
  59. package/dist/lib/chunks/{chunk-S2AM76LT.js → chunk-7WO3FFPS.js} +3 -3
  60. package/dist/lib/chunks/{chunk-ULRXHSJL.js → chunk-7YDXD4MD.js} +9 -6
  61. package/dist/lib/chunks/{chunk-HFOYASRQ.js → chunk-AAFHXNLU.js} +4 -4
  62. package/dist/lib/chunks/{chunk-OBXAHX3L.js → chunk-AASWJR7Q.js} +1 -5
  63. package/dist/lib/chunks/{chunk-MD4AVTK2.js → chunk-AJKV46SM.js} +3 -3
  64. package/dist/lib/chunks/{chunk-IEVAFDW7.js → chunk-AJO7XVXK.js} +12 -12
  65. package/dist/lib/chunks/{chunk-GMKF2FU4.js → chunk-AK6YNTCV.js} +1 -1
  66. package/dist/lib/chunks/{chunk-WKH6BJAZ.js → chunk-BFWK3TBN.js} +6 -6
  67. package/dist/lib/chunks/{chunk-FKLNEB2P.js → chunk-BGAHZIL3.js} +51 -17
  68. package/dist/lib/chunks/{chunk-ZCOI3HE2.js → chunk-BRENK356.js} +1 -1
  69. package/dist/lib/chunks/{chunk-S7KJZIUR.js → chunk-BXF4OC74.js} +18 -9
  70. package/dist/lib/chunks/{chunk-NCLFZOZU.js → chunk-CH7OCYDL.js} +1 -1
  71. package/dist/lib/chunks/{chunk-FPAN3VRW.js → chunk-DDS4G4DO.js} +27 -19
  72. package/dist/lib/chunks/{chunk-ZLOOC46D.js → chunk-DL6YQDTE.js} +34 -8
  73. package/dist/lib/chunks/chunk-DVFFYY5G.js +74 -0
  74. package/dist/lib/chunks/{chunk-PDS5KWO3.js → chunk-E2YTTB6Q.js} +56 -42
  75. package/dist/lib/chunks/{chunk-YR67JG2V.js → chunk-E3OGPTUY.js} +8 -3
  76. package/dist/lib/chunks/{chunk-SDWYZM64.js → chunk-EDQTINTL.js} +5 -1
  77. package/dist/lib/chunks/chunk-ESEMYWUH.js +257 -0
  78. package/dist/lib/chunks/{chunk-YHS5IEVZ.js → chunk-F2NSJ6PG.js} +12 -8
  79. package/dist/lib/chunks/{chunk-7GXRDAUY.js → chunk-F7DBTXKG.js} +6 -6
  80. package/dist/lib/chunks/chunk-FAUFE7MI.js +31 -0
  81. package/dist/lib/chunks/{chunk-4E4NDGOZ.js → chunk-FDM2YNQL.js} +1 -1
  82. package/dist/lib/chunks/{chunk-47IZBMP2.js → chunk-FIC7JSR4.js} +2 -2
  83. package/dist/lib/chunks/{chunk-CJ5YD3CU.js → chunk-FJL2V6P5.js} +6 -6
  84. package/dist/lib/chunks/{chunk-KHU5DRBE.js → chunk-FL6LN2K6.js} +9 -9
  85. package/dist/lib/chunks/{chunk-HSZ3DM74.js → chunk-GEFKDW7X.js} +15 -2
  86. package/dist/lib/chunks/{chunk-XNRSHATN.js → chunk-HI3PD3KR.js} +8 -8
  87. package/dist/lib/chunks/{chunk-AUB5THIS.js → chunk-I3UE52ZV.js} +2 -2
  88. package/dist/lib/chunks/{chunk-IAR6XGEW.js → chunk-J5NPHPXY.js} +5 -4
  89. package/dist/lib/chunks/{chunk-XJVXASDD.js → chunk-JBOOD6MU.js} +11 -10
  90. package/dist/lib/chunks/{chunk-5KKLUM7M.js → chunk-JKPBXPCW.js} +3 -3
  91. package/dist/lib/chunks/{chunk-5HT55QYX.js → chunk-JQDQVG3D.js} +1 -1
  92. package/dist/lib/chunks/{chunk-3KQFLOC7.js → chunk-JXBLGCXZ.js} +1 -1
  93. package/dist/lib/chunks/{chunk-D2INDP5W.js → chunk-JYFEXVWC.js} +7 -6
  94. package/dist/lib/chunks/{chunk-X2Y2ZNG3.js → chunk-K2FZFESR.js} +8 -8
  95. package/dist/lib/chunks/{chunk-DC6PN7QJ.js → chunk-K4Y5NT4M.js} +11 -7
  96. package/dist/lib/chunks/chunk-K7YFL5KB.js +182 -0
  97. package/dist/lib/chunks/{chunk-ZYSPTOKK.js → chunk-KQCRJIEG.js} +1 -1
  98. package/dist/lib/chunks/{chunk-LPND3VNQ.js → chunk-KSOHZKV5.js} +43 -35
  99. package/dist/lib/chunks/{chunk-FBFZBLTY.js → chunk-LR27H2HZ.js} +15 -16
  100. package/dist/lib/chunks/{chunk-KZR25REO.js → chunk-LTI2YYU3.js} +1 -1
  101. package/dist/lib/chunks/{chunk-EPQHVILQ.js → chunk-MA27TFEY.js} +5 -3
  102. package/dist/lib/chunks/{chunk-J46W3EMQ.js → chunk-MENTBQGB.js} +8 -7
  103. package/dist/lib/chunks/chunk-MPJCZN4G.js +155 -0
  104. package/dist/lib/chunks/{chunk-56VOFZ7T.js → chunk-MTDYBJXH.js} +92 -26
  105. package/dist/lib/chunks/{chunk-PCYNBDZ7.js → chunk-OD36HUXA.js} +17 -12
  106. package/dist/lib/chunks/{chunk-WDSCJEDG.js → chunk-OQFAMKLN.js} +11 -11
  107. package/dist/lib/chunks/{chunk-Z4LMDKBU.js → chunk-PWOYEIPF.js} +4 -4
  108. package/dist/lib/chunks/{chunk-XL4JIQ5X.js → chunk-PXB4PWJI.js} +7 -3
  109. package/dist/lib/chunks/{chunk-7ZOJE6BH.js → chunk-QGZ4QSUE.js} +8 -7
  110. package/dist/lib/chunks/chunk-QJZTDZMB.js +321 -0
  111. package/dist/lib/chunks/{chunk-MHAKYFDF.js → chunk-R2AJYV6A.js} +22 -22
  112. package/dist/lib/chunks/{chunk-5B3RNVZ6.js → chunk-RK57YZKM.js} +1 -1
  113. package/dist/lib/chunks/{chunk-ZXGATMMH.js → chunk-RPTADJXD.js} +1 -1
  114. package/dist/lib/chunks/{chunk-2NJEWPCV.js → chunk-RXSHKWZJ.js} +3 -3
  115. package/dist/lib/chunks/chunk-RYCRL3YA.js +106 -0
  116. package/dist/lib/chunks/{chunk-E3OEE5XN.js → chunk-SD7LR26G.js} +3 -3
  117. package/dist/lib/chunks/{chunk-GVC4LH2N.js → chunk-SIJOQRRK.js} +1 -1
  118. package/dist/lib/chunks/{chunk-ZBDUE3A5.js → chunk-SLAPBFRH.js} +12 -7
  119. package/dist/lib/chunks/{chunk-CKUTDJAB.js → chunk-SMPP7B7F.js} +45 -10
  120. package/dist/lib/chunks/{chunk-POUSX3T4.js → chunk-SQQ56UP2.js} +15 -6
  121. package/dist/lib/chunks/{chunk-I3TMFPK4.js → chunk-T5XQ6NXD.js} +6 -4
  122. package/dist/lib/chunks/{chunk-EYKINDNK.js → chunk-TAPVCSCR.js} +1 -1
  123. package/dist/lib/chunks/{chunk-ISN6MBNB.js → chunk-U5USH2HB.js} +7 -7
  124. package/dist/lib/chunks/chunk-U64NCRRR.js +97 -0
  125. package/dist/lib/chunks/{chunk-D2LPQO6Y.js → chunk-U6BW6LGX.js} +10 -3
  126. package/dist/lib/chunks/chunk-U772TN32.js +67 -0
  127. package/dist/lib/chunks/{chunk-XHWRSGX3.js → chunk-UYDQXXDQ.js} +4 -4
  128. package/dist/lib/chunks/{chunk-CPT2GKKW.js → chunk-V5JJEEBT.js} +1 -1
  129. package/dist/lib/chunks/{chunk-YWJPJI3W.js → chunk-VL253W5C.js} +3 -1
  130. package/dist/lib/chunks/{chunk-I7VNIW6Q.js → chunk-VPXYGN4I.js} +86 -15
  131. package/dist/lib/chunks/{chunk-Z7V63UZA.js → chunk-VXDMOB7O.js} +4 -4
  132. package/dist/lib/chunks/chunk-W5X7WJYL.js +91 -0
  133. package/dist/lib/chunks/{chunk-6AUEDSTU.js → chunk-WCLKIPJV.js} +1 -1
  134. package/dist/lib/chunks/{chunk-QFVRCSJ2.js → chunk-WDOA5JEH.js} +2 -0
  135. package/dist/lib/chunks/chunk-WDT2Y7D7.js +117 -0
  136. package/dist/lib/chunks/{chunk-OVUCZLH2.js → chunk-WIBMVNIH.js} +2 -2
  137. package/dist/lib/chunks/{chunk-5T3V6XJS.js → chunk-WNIXDMJL.js} +1 -1
  138. package/dist/lib/chunks/{chunk-OORO55OM.js → chunk-WZGI7UVM.js} +23 -8
  139. package/dist/lib/chunks/{chunk-2GY42RIJ.js → chunk-XAKME6NM.js} +1 -1
  140. package/dist/lib/chunks/{chunk-Q2PWES4B.js → chunk-XAN4CRFP.js} +33 -41
  141. package/dist/lib/chunks/{chunk-MIF5IYNR.js → chunk-XDG6NPJB.js} +26 -29
  142. package/dist/lib/chunks/{chunk-IPNK7FYT.js → chunk-XFUYEFQP.js} +1 -1
  143. package/dist/lib/chunks/{chunk-OQVIRYT5.js → chunk-XNTFOVCE.js} +2 -2
  144. package/dist/lib/chunks/chunk-Y2CZ6FZY.js +61 -0
  145. package/dist/lib/chunks/{chunk-D7GEQVLL.js → chunk-YKJHFD64.js} +1 -1
  146. package/dist/lib/chunks/chunk-YZEZRQIG.js +194 -0
  147. package/dist/lib/chunks/chunk-ZIGNJAPC.js +11 -0
  148. package/dist/lib/chunks/{chunk-5ZITQDVE.js → chunk-ZQ3ER7JD.js} +12 -13
  149. package/dist/lib/cli/bundle-commands.js +102 -94
  150. package/dist/lib/cli/guide-command.js +25 -0
  151. package/dist/lib/cli/io.js +1 -1
  152. package/dist/lib/cli/run-commands.js +310 -140
  153. package/dist/lib/cli/status-command.js +236 -0
  154. package/dist/lib/codex-workflow/aggregate.js +22 -24
  155. package/dist/lib/codex-workflow/author-search.js +4 -3
  156. package/dist/lib/codex-workflow/author-tools.js +18 -17
  157. package/dist/lib/codex-workflow/author.js +39 -36
  158. package/dist/lib/codex-workflow/capture.js +26 -25
  159. package/dist/lib/codex-workflow/checkpoint.js +14 -15
  160. package/dist/lib/codex-workflow/checks.js +16 -18
  161. package/dist/lib/codex-workflow/codex-binary.js +13 -0
  162. package/dist/lib/codex-workflow/codex-home.js +6 -3
  163. package/dist/lib/codex-workflow/copy-editor.js +33 -32
  164. package/dist/lib/codex-workflow/copy-recovery.js +12 -13
  165. package/dist/lib/codex-workflow/copy.js +30 -29
  166. package/dist/lib/codex-workflow/finish.js +37 -38
  167. package/dist/lib/codex-workflow/host-models.js +7 -7
  168. package/dist/lib/codex-workflow/loop.js +71 -65
  169. package/dist/lib/codex-workflow/quality.js +12 -13
  170. package/dist/lib/codex-workflow/run-inputs.js +13 -14
  171. package/dist/lib/codex-workflow/run-source.js +28 -24
  172. package/dist/lib/codex-workflow/schemas.js +12 -13
  173. package/dist/lib/codex-workflow/session.js +15 -16
  174. package/dist/lib/codex-workflow/stage.js +51 -45
  175. package/dist/lib/codex-workflow/workdir.js +14 -15
  176. package/dist/lib/engine/audit-file.js +18 -13
  177. package/dist/lib/engine/author.js +62 -53
  178. package/dist/lib/engine/budget.js +7 -1
  179. package/dist/lib/engine/cost-estimate.js +43 -0
  180. package/dist/lib/engine/local-run.js +79 -71
  181. package/dist/lib/engine/preflight.js +17 -13
  182. package/dist/lib/engine/rejudge.js +87 -79
  183. package/dist/lib/engine/resources.js +1 -1
  184. package/dist/lib/engine/run-configuration.js +2 -1
  185. package/dist/lib/engine/run-status.js +153 -0
  186. package/dist/lib/engine/templates.js +19 -14
  187. package/dist/lib/grounding/chromium-guard.js +13 -0
  188. package/dist/lib/grounding/controller.js +13 -12
  189. package/dist/lib/grounding/extract.js +12 -11
  190. package/dist/lib/grounding/fetch.js +4 -7
  191. package/dist/lib/grounding/file-store.js +5 -5
  192. package/dist/lib/grounding/grounding-runtime.js +34 -32
  193. package/dist/lib/grounding/guarded-request.js +18 -0
  194. package/dist/lib/grounding/model.js +11 -10
  195. package/dist/lib/grounding/profile.js +4 -4
  196. package/dist/lib/grounding/recorded-tools.js +18 -17
  197. package/dist/lib/grounding/session.js +3 -3
  198. package/dist/lib/grounding/tools.js +4 -3
  199. package/dist/lib/grounding/validation.js +2 -2
  200. package/dist/lib/harness/report/artifacts.js +12 -13
  201. package/dist/lib/harness/report/capture-coverage.js +4 -4
  202. package/dist/lib/lib/checkpoint.js +11 -12
  203. package/dist/lib/lib/progress-comparison.js +2 -2
  204. package/dist/lib/models/batching.js +5 -5
  205. package/dist/lib/models/cost-coefficients.js +20 -0
  206. package/dist/lib/models/local-profile.js +10 -0
  207. package/dist/lib/models/pricing.js +6 -0
  208. package/dist/lib/models/profiles.js +7 -14
  209. package/dist/lib/models/structured-images.js +1 -1
  210. package/dist/lib/models/structured.js +4 -4
  211. package/dist/lib/models/supported-models.js +20 -0
  212. package/dist/lib/pipeline.js +21 -21
  213. package/dist/lib/probes/agent-cli-parsers.js +1 -1
  214. package/dist/lib/probes/agent-clis.js +13 -12
  215. package/dist/lib/probes/charged-trace.js +10 -0
  216. package/dist/lib/probes/probes.js +12 -12
  217. package/dist/lib/probes/web-tool-guard.js +3 -3
  218. package/dist/lib/report/contracts.js +4 -4
  219. package/dist/lib/report/core/progress-comparison.js +2 -2
  220. package/dist/lib/report/core/progress-schema.js +2 -2
  221. package/dist/lib/report/core/schema.js +2 -4
  222. package/dist/lib/report/core/surfaces.js +1 -3
  223. package/dist/lib/runner.js +25 -26
  224. package/dist/lib/schema.js +20 -15
  225. package/dist/lib/section-result.js +15 -17
  226. package/dist/lib/stores/artifacts.js +18 -19
  227. package/dist/lib/stores/files.js +32 -32
  228. package/dist/lib/stores/local-versions.js +11 -12
  229. package/dist/lib/stores/memory.js +34 -35
  230. package/dist/lib/stores/publication.js +23 -23
  231. package/dist/lib/surfaces.js +1 -3
  232. package/dist/lib/viewer/server.js +38 -39
  233. package/dist/lib/workflow/schema.js +9 -10
  234. package/dist/types/agents/author-schema.d.ts +3 -3
  235. package/dist/types/agents/copy-validation.d.ts +4 -4
  236. package/dist/types/agents/verifier.d.ts +6 -6
  237. package/dist/types/analysis/scoring.d.ts +2 -2
  238. package/dist/types/bundle/contracts.d.ts +3 -2
  239. package/dist/types/bundle/isolation.d.ts +37 -0
  240. package/dist/types/bundle/project-journal.d.ts +2 -0
  241. package/dist/types/bundle/recorder.d.ts +4 -0
  242. package/dist/types/bundle/writer-lock.d.ts +9 -0
  243. package/dist/types/checks/crawler-access.d.ts +3 -2
  244. package/dist/types/checks/renderability.d.ts +8 -1
  245. package/dist/types/cli/guide-command.d.ts +4 -0
  246. package/dist/types/cli/status-command.d.ts +2 -0
  247. package/dist/types/codex-workflow/author-tools.d.ts +3 -3
  248. package/dist/types/codex-workflow/codex-binary.d.ts +26 -0
  249. package/dist/types/codex-workflow/codex-home.d.ts +24 -20
  250. package/dist/types/codex-workflow/copy-editor.d.ts +1 -1
  251. package/dist/types/codex-workflow/copy.d.ts +3 -4
  252. package/dist/types/codex-workflow/finish.d.ts +5 -3
  253. package/dist/types/codex-workflow/host-models.d.ts +7 -3
  254. package/dist/types/codex-workflow/loop.d.ts +10 -1
  255. package/dist/types/codex-workflow/run-inputs.d.ts +31 -113
  256. package/dist/types/codex-workflow/schemas.d.ts +6 -6
  257. package/dist/types/codex-workflow/stage.d.ts +16 -5
  258. package/dist/types/engine/audit-file.d.ts +9 -3
  259. package/dist/types/engine/author.d.ts +7 -1
  260. package/dist/types/engine/budget.d.ts +46 -15
  261. package/dist/types/engine/cost-estimate.d.ts +40 -0
  262. package/dist/types/engine/local-run.d.ts +6 -0
  263. package/dist/types/engine/preflight.d.ts +7 -0
  264. package/dist/types/engine/resources.d.ts +2 -0
  265. package/dist/types/engine/run-configuration.d.ts +4 -3
  266. package/dist/types/engine/run-status.d.ts +75 -0
  267. package/dist/types/engine/templates.d.ts +1 -2
  268. package/dist/types/grounding/chromium-guard.d.ts +41 -0
  269. package/dist/types/grounding/fetch.d.ts +0 -10
  270. package/dist/types/grounding/guarded-request.d.ts +76 -0
  271. package/dist/types/harness/report/artifacts.d.ts +1 -0
  272. package/dist/types/lib/checkpoint.d.ts +5 -6
  273. package/dist/types/models/cost-coefficients.d.ts +106 -0
  274. package/dist/types/models/local-profile.d.ts +12 -0
  275. package/dist/types/models/pricing.d.ts +8 -0
  276. package/dist/types/models/profiles.d.ts +55 -160
  277. package/dist/types/models/served-model.d.ts +2 -3
  278. package/dist/types/models/structured.d.ts +3 -3
  279. package/dist/types/models/supported-models.d.ts +48 -0
  280. package/dist/types/pipeline.d.ts +2 -1
  281. package/dist/types/probes/charged-trace.d.ts +8 -0
  282. package/dist/types/probes/probe-trace.d.ts +2 -0
  283. package/dist/types/probes/probes.d.ts +2 -1
  284. package/dist/types/report/contracts.d.ts +2 -0
  285. package/dist/types/report/core/schema.d.ts +3 -1
  286. package/dist/types/report/core/surfaces.d.ts +0 -1
  287. package/dist/types/schema.d.ts +50 -113
  288. package/dist/types/section-result.d.ts +1 -1
  289. package/dist/types/workflow/schema.d.ts +79 -152
  290. package/package.json +2 -1
  291. package/resources/guide/OPERATOR.md +189 -0
  292. package/src/agents/author-schema.ts +13 -1
  293. package/src/agents/author-validation.ts +2 -5
  294. package/src/agents/copy-validation.ts +8 -12
  295. package/src/agents/facts.ts +8 -8
  296. package/src/agents/narrative-facts.ts +9 -20
  297. package/src/agents/verifier.ts +12 -16
  298. package/src/analysis/progress.ts +1 -0
  299. package/src/analysis/scoring.ts +9 -13
  300. package/src/bundle/contracts.ts +9 -4
  301. package/src/bundle/isolation.ts +157 -0
  302. package/src/bundle/project-journal.ts +4 -0
  303. package/src/bundle/project.ts +20 -7
  304. package/src/bundle/recorder.ts +5 -0
  305. package/src/bundle/verify.ts +3 -3
  306. package/src/bundle/writer-lock.ts +27 -0
  307. package/src/capture-manifest.ts +4 -0
  308. package/src/checks/crawler-access.ts +70 -50
  309. package/src/checks/renderability.ts +113 -87
  310. package/src/checks/run-checks.ts +16 -3
  311. package/src/cli/guide-command.ts +28 -0
  312. package/src/cli/io.ts +2 -0
  313. package/src/cli/literally-aeo.ts +39 -19
  314. package/src/cli/run-commands.ts +238 -18
  315. package/src/cli/status-command.ts +113 -0
  316. package/src/codex-workflow/aggregate.ts +1 -0
  317. package/src/codex-workflow/author-tools.ts +39 -60
  318. package/src/codex-workflow/capture.ts +1 -0
  319. package/src/codex-workflow/codex-binary.ts +105 -0
  320. package/src/codex-workflow/codex-home.ts +50 -40
  321. package/src/codex-workflow/copy-editor.ts +3 -3
  322. package/src/codex-workflow/copy.ts +7 -10
  323. package/src/codex-workflow/finish.ts +13 -8
  324. package/src/codex-workflow/host-models.ts +33 -24
  325. package/src/codex-workflow/loop.ts +38 -11
  326. package/src/codex-workflow/stage.ts +126 -17
  327. package/src/engine/audit-file.ts +98 -9
  328. package/src/engine/author.ts +47 -2
  329. package/src/engine/budget.ts +138 -43
  330. package/src/engine/cost-estimate.ts +178 -0
  331. package/src/engine/guide/OPERATOR.md +189 -0
  332. package/src/engine/local-run.ts +38 -8
  333. package/src/engine/preflight.ts +140 -7
  334. package/src/engine/resources.ts +9 -4
  335. package/src/engine/run-configuration.ts +19 -1
  336. package/src/engine/run-status.ts +452 -0
  337. package/src/engine/templates.ts +5 -2
  338. package/src/grounding/chromium-guard.ts +273 -0
  339. package/src/grounding/controller.ts +1 -1
  340. package/src/grounding/fetch.ts +39 -276
  341. package/src/grounding/guarded-request.ts +428 -0
  342. package/src/grounding/tools.ts +2 -1
  343. package/src/grounding/validation.ts +1 -1
  344. package/src/lib/checkpoint.ts +15 -16
  345. package/src/models/cost-coefficients.ts +140 -0
  346. package/src/models/local-profile.ts +150 -0
  347. package/src/models/pricing.ts +31 -0
  348. package/src/models/profiles.ts +58 -419
  349. package/src/models/served-model.ts +2 -3
  350. package/src/models/structured-images.ts +5 -4
  351. package/src/models/structured.ts +20 -7
  352. package/src/models/supported-models.ts +112 -0
  353. package/src/pipeline.ts +13 -7
  354. package/src/probes/agent-clis.ts +26 -5
  355. package/src/probes/charged-trace.ts +87 -0
  356. package/src/probes/probe-trace.ts +2 -0
  357. package/src/probes/probes.ts +72 -12
  358. package/src/report/core/schema.ts +4 -1
  359. package/src/report/core/surfaces.ts +4 -8
  360. package/src/runner.ts +1 -0
  361. package/src/schema.ts +68 -4
  362. package/src/section-result.ts +6 -5
  363. package/dist/lib/chunks/chunk-6EH4N3EU.js +0 -113
  364. package/dist/lib/chunks/chunk-CFFPOTP4.js +0 -356
  365. package/dist/lib/chunks/chunk-LIZX4N3H.js +0 -110
  366. package/dist/lib/chunks/chunk-OYKV5NDM.js +0 -28
  367. package/dist/lib/chunks/chunk-SWJ7KQSL.js +0 -318
  368. package/dist/lib/chunks/chunk-WE2WPNG2.js +0 -104
  369. package/dist/lib/chunks/{chunk-XI5H46DF.js → chunk-SASE7U6E.js} +3 -3
@@ -0,0 +1,428 @@
1
+ import type { LookupAddress } from 'node:dns';
2
+ import { lookup } from 'node:dns/promises';
3
+ import { request } from 'node:https';
4
+ import { isIP } from 'node:net';
5
+ import { setTimeout as delay } from 'node:timers/promises';
6
+ import { isPublicAddress } from '../workflow/callbacks';
7
+
8
+ // ============================================================================
9
+ // The one guard every request to a site passes through
10
+ // (specs/aeo-checks-and-reach-spec.md §3.1): https on port 443 with no
11
+ // credentials, every DNS answer public and the socket pinned to the checked
12
+ // address, each redirect hop validated again, an identity-encoded body bounded
13
+ // in bytes. The research fetch, the site checks and the Chromium proxy all
14
+ // decide destinations here.
15
+ // ============================================================================
16
+
17
+ export type SourceRetrievalReason =
18
+ | 'unsafe_destination'
19
+ | 'timeout'
20
+ | 'too_large'
21
+ | 'unsupported_content'
22
+ | 'http_error'
23
+ | 'empty_content'
24
+ | 'network_error';
25
+
26
+ export class SourceRetrievalError extends Error {
27
+ readonly reason: SourceRetrievalReason;
28
+ readonly status: number | undefined;
29
+
30
+ constructor(
31
+ reason: SourceRetrievalReason,
32
+ message: string,
33
+ { status, cause }: { status?: number; cause?: unknown } = {},
34
+ ) {
35
+ super(message, cause === undefined ? undefined : { cause });
36
+ this.name = 'SourceRetrievalError';
37
+ this.reason = reason;
38
+ this.status = status;
39
+ }
40
+ }
41
+
42
+ export const validateResearchUrl = (value: string): URL => {
43
+ let url: URL;
44
+
45
+ try {
46
+ url = new URL(value);
47
+ } catch {
48
+ throw new SourceRetrievalError(
49
+ 'unsafe_destination',
50
+ `Invalid source URL: ${value}.`,
51
+ );
52
+ }
53
+
54
+ if (
55
+ url.protocol !== 'https:' ||
56
+ url.username ||
57
+ url.password ||
58
+ url.port ||
59
+ url.hostname === 'localhost' ||
60
+ url.hostname.endsWith('.localhost') ||
61
+ url.hostname.endsWith('.local') ||
62
+ url.hostname.endsWith('.internal') ||
63
+ url.hostname === 'metadata.google.internal'
64
+ ) {
65
+ throw new SourceRetrievalError(
66
+ 'unsafe_destination',
67
+ `Source must use public HTTPS with no credentials: ${url.hostname}.`,
68
+ );
69
+ }
70
+
71
+ const host = url.hostname.replace(/^\[|\]$/g, '');
72
+
73
+ if (isIP(host) && !isPublicAddress(host)) {
74
+ throw new SourceRetrievalError(
75
+ 'unsafe_destination',
76
+ `Private source destination: ${host}.`,
77
+ );
78
+ }
79
+
80
+ url.hash = '';
81
+
82
+ return url;
83
+ };
84
+
85
+ const withAbort = <T>(promise: Promise<T>, signal: AbortSignal): Promise<T> => {
86
+ signal.throwIfAborted();
87
+
88
+ return new Promise((resolve, reject) => {
89
+ const aborted = () => {
90
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors -- AbortSignal.reason is typed any; rejecting with it keeps the caller's abort error.
91
+ reject(signal.reason);
92
+ };
93
+
94
+ signal.addEventListener('abort', aborted, { once: true });
95
+
96
+ promise.then(resolve, reject).finally(() => {
97
+ signal.removeEventListener('abort', aborted);
98
+ });
99
+ });
100
+ };
101
+
102
+ export type LookupAll = (host: string) => Promise<LookupAddress[]>;
103
+
104
+ const lookupAll: LookupAll = (host) => {
105
+ return lookup(host, { all: true });
106
+ };
107
+
108
+ /**
109
+ * resolvePublicAddress returns the address a connection to the host is
110
+ * pinned to. Every DNS answer must be public, not only the first: a host
111
+ * that also answers with a private address could hand it to the next
112
+ * lookup, so the socket never looks the name up again.
113
+ */
114
+ export const resolvePublicAddress = async (
115
+ hostname: string,
116
+ signal: AbortSignal,
117
+ lookupHost: LookupAll = lookupAll,
118
+ ): Promise<LookupAddress> => {
119
+ const host = hostname.replace(/^\[|\]$/g, '');
120
+ const addresses = await withAbort(lookupHost(host), signal);
121
+
122
+ if (
123
+ addresses.length === 0 ||
124
+ addresses.some(({ address }) => !isPublicAddress(address))
125
+ ) {
126
+ throw new SourceRetrievalError(
127
+ 'unsafe_destination',
128
+ `Source DNS must resolve exclusively to public addresses: ${host}.`,
129
+ );
130
+ }
131
+
132
+ const [firstAddress] = addresses;
133
+
134
+ if (!firstAddress) {
135
+ throw new SourceRetrievalError(
136
+ 'unsafe_destination',
137
+ `Source DNS returned no address: ${host}.`,
138
+ );
139
+ }
140
+
141
+ return firstAddress;
142
+ };
143
+
144
+ /**
145
+ * HostPacer runs one request at a time per host, each starting a fixed
146
+ * interval after the previous one ended. One pacer serves every request of
147
+ * a phase, so checks that run side by side still reach a site one by one.
148
+ */
149
+ export type HostPacer = <T>(url: URL, send: () => Promise<T>) => Promise<T>;
150
+
151
+ export const createHostPacer = (
152
+ intervalInMs: number,
153
+ wait: (ms: number) => Promise<unknown> = delay,
154
+ ): HostPacer => {
155
+ const lastRequestByHost = new Map<string, Promise<unknown>>();
156
+
157
+ return (url, send) => {
158
+ const previous = lastRequestByHost.get(url.hostname);
159
+ const current = (async () => {
160
+ if (previous) {
161
+ await previous;
162
+ await wait(intervalInMs);
163
+ }
164
+
165
+ return send();
166
+ })();
167
+
168
+ lastRequestByHost.set(
169
+ url.hostname,
170
+ current.catch(() => undefined),
171
+ );
172
+
173
+ return current;
174
+ };
175
+ };
176
+
177
+ /** How a successful response's body is read. */
178
+ export type BodyPolicy = {
179
+ /** Content types the body may have; any other is refused unread. */
180
+ contentTypes: RegExp | 'any';
181
+ maxBytes: number;
182
+ /** Past maxBytes: keep the prefix and say so, or refuse the response. */
183
+ oversize: 'truncate' | 'refuse';
184
+ };
185
+
186
+ export type GuardedRequestOptions = {
187
+ url: string;
188
+ /** Bounds each hop from when it is sent; a wait for the host's turn in
189
+ * the pacer is not counted, or a request queued behind a slow render
190
+ * would time out without ever being sent. */
191
+ timeoutInMs: number;
192
+ signal?: AbortSignal;
193
+ userAgent: string;
194
+ accept: string;
195
+ /** Redirects followed before the request is refused. */
196
+ redirects: number;
197
+ /** Absent: only the status and headers are read, never the body. */
198
+ body?: BodyPolicy;
199
+ /** Wraps every hop's request: the caller's spacing per host. */
200
+ pace?: HostPacer;
201
+ };
202
+
203
+ export type GuardedHop = { url: string; status: number };
204
+
205
+ export type GuardedResponse = {
206
+ /** The URL of the final hop. */
207
+ url: string;
208
+ status: number;
209
+ contentType: string;
210
+ /** Read only for a 2xx under a body policy. */
211
+ body: Buffer | undefined;
212
+ isTruncated: boolean;
213
+ /** Every response received, the final one last. */
214
+ hops: GuardedHop[];
215
+ };
216
+
217
+ /** A failure as a site check records it: a refused destination or redirect
218
+ * names its reason (`unsafe_destination: …`). */
219
+ export const describeSiteError = (error: unknown): string => {
220
+ if (error instanceof SourceRetrievalError) {
221
+ return `${error.reason}: ${error.message}`;
222
+ }
223
+
224
+ return error instanceof Error ? error.message : String(error);
225
+ };
226
+
227
+ /** A request bound to a phase's pacer: what the site checks receive. */
228
+ export type SiteRequest = (
229
+ options: Omit<GuardedRequestOptions, 'pace'>,
230
+ ) => Promise<GuardedResponse>;
231
+
232
+ type HopResponse = Omit<GuardedResponse, 'url' | 'hops'> & {
233
+ location: string | undefined;
234
+ };
235
+
236
+ const isRedirect = (status: number): boolean => {
237
+ return status >= 300 && status < 400;
238
+ };
239
+
240
+ const isSuccess = (status: number): boolean => {
241
+ return status >= 200 && status < 300;
242
+ };
243
+
244
+ const requestHop = async (
245
+ url: URL,
246
+ options: GuardedRequestOptions,
247
+ signal: AbortSignal,
248
+ ): Promise<HopResponse> => {
249
+ const address = await resolvePublicAddress(url.hostname, signal);
250
+
251
+ signal.throwIfAborted();
252
+
253
+ return new Promise((resolve, reject) => {
254
+ const req = request(
255
+ url,
256
+ {
257
+ method: 'GET',
258
+ signal,
259
+ headers: {
260
+ 'accept': options.accept,
261
+ // Never a compressed body: nothing to decompress, so no bomb to
262
+ // bound. An encoded body despite this is refused below.
263
+ 'accept-encoding': 'identity',
264
+ 'user-agent': options.userAgent,
265
+ },
266
+ lookup: (_host, lookupOptions, callback) => {
267
+ if (lookupOptions.all) {
268
+ callback(null, [address]);
269
+ } else {
270
+ callback(null, address.address, address.family);
271
+ }
272
+ },
273
+ },
274
+ (response) => {
275
+ const status = response.statusCode ?? 0;
276
+ const contentType = response.headers['content-type'] ?? '';
277
+ const encoding = response.headers['content-encoding'];
278
+ const policy = options.body;
279
+ const settle = (body: Buffer | undefined, isTruncated: boolean) => {
280
+ resolve({
281
+ status,
282
+ location: response.headers.location,
283
+ contentType,
284
+ body,
285
+ isTruncated,
286
+ });
287
+ };
288
+
289
+ if (!policy || !isSuccess(status)) {
290
+ response.destroy();
291
+ settle(undefined, false);
292
+
293
+ return;
294
+ }
295
+
296
+ if (
297
+ (policy.contentTypes !== 'any' &&
298
+ !policy.contentTypes.test(contentType)) ||
299
+ (encoding && encoding !== 'identity')
300
+ ) {
301
+ response.destroy();
302
+ reject(
303
+ new SourceRetrievalError(
304
+ 'unsupported_content',
305
+ `Unsupported source content: ${contentType}.`,
306
+ ),
307
+ );
308
+
309
+ return;
310
+ }
311
+
312
+ const chunks: Buffer[] = [];
313
+ let bytes = 0;
314
+
315
+ response.on('data', (chunk: Buffer) => {
316
+ bytes += chunk.length;
317
+
318
+ if (bytes <= policy.maxBytes) {
319
+ chunks.push(chunk);
320
+
321
+ return;
322
+ }
323
+
324
+ response.destroy();
325
+
326
+ if (policy.oversize === 'refuse') {
327
+ reject(
328
+ new SourceRetrievalError(
329
+ 'too_large',
330
+ `Source response exceeds byte limit: ${bytes} bytes.`,
331
+ ),
332
+ );
333
+
334
+ return;
335
+ }
336
+
337
+ const kept = Buffer.concat(chunks);
338
+
339
+ settle(
340
+ Buffer.concat([
341
+ kept,
342
+ chunk.subarray(0, policy.maxBytes - kept.length),
343
+ ]),
344
+ true,
345
+ );
346
+ });
347
+
348
+ response.once('error', reject);
349
+ response.once('end', () => {
350
+ settle(Buffer.concat(chunks), false);
351
+ });
352
+ },
353
+ );
354
+
355
+ req.once('error', reject);
356
+ req.end();
357
+ });
358
+ };
359
+
360
+ /**
361
+ * guardedRequest sends a GET under the guard and returns any status: the
362
+ * caller decides what a 403 or a 5xx means. A redirect it cannot follow
363
+ * (no Location, or past the limit) and an unsafe hop are refused.
364
+ */
365
+ export const guardedRequest = async (
366
+ options: GuardedRequestOptions,
367
+ ): Promise<GuardedResponse> => {
368
+ const pace: HostPacer = options.pace ?? ((_url, send) => send());
369
+ const hops: GuardedHop[] = [];
370
+ let url = validateResearchUrl(options.url);
371
+ let hopSignal: AbortSignal | undefined;
372
+
373
+ try {
374
+ for (let redirects = 0; ; redirects += 1) {
375
+ const target = url;
376
+ const response = await pace(target, () => {
377
+ options.signal?.throwIfAborted();
378
+
379
+ const signal = AbortSignal.any([
380
+ AbortSignal.timeout(options.timeoutInMs),
381
+ ...(options.signal ? [options.signal] : []),
382
+ ]);
383
+
384
+ hopSignal = signal;
385
+
386
+ return requestHop(target, options, signal);
387
+ });
388
+
389
+ hops.push({ url: target.href, status: response.status });
390
+
391
+ if (!isRedirect(response.status)) {
392
+ const { location: _location, ...final } = response;
393
+
394
+ return { ...final, url: target.href, hops };
395
+ }
396
+
397
+ if (!response.location) {
398
+ throw new SourceRetrievalError(
399
+ 'http_error',
400
+ `Source redirect without a location: ${target.href}.`,
401
+ );
402
+ }
403
+
404
+ if (redirects === options.redirects) {
405
+ throw new SourceRetrievalError(
406
+ 'http_error',
407
+ `Source redirect limit exceeded: ${target.href}.`,
408
+ );
409
+ }
410
+
411
+ url = validateResearchUrl(new URL(response.location, target).href);
412
+ }
413
+ } catch (error) {
414
+ if (options.signal?.aborted) {
415
+ throw options.signal.reason;
416
+ }
417
+
418
+ if (error instanceof SourceRetrievalError) {
419
+ throw error;
420
+ }
421
+
422
+ throw new SourceRetrievalError(
423
+ hopSignal?.aborted ? 'timeout' : 'network_error',
424
+ `Source retrieval failed: ${url.href}.`,
425
+ { cause: error },
426
+ );
427
+ }
428
+ };
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { contentHash } from '../stores/content-hash';
3
- import { fetchGroundingSource, validateResearchUrl } from './fetch';
3
+ import { fetchGroundingSource } from './fetch';
4
+ import { validateResearchUrl } from './guarded-request';
4
5
  import { GroundingIntegrityError } from './validation';
5
6
  import {
6
7
  groundingSourceSchema,
@@ -1,5 +1,5 @@
1
1
  import { contentHash } from '../stores/content-hash';
2
- import { validateResearchUrl } from './fetch';
2
+ import { validateResearchUrl } from './guarded-request';
3
3
  import {
4
4
  groundingBundleSchema,
5
5
  type GroundingBundle,
@@ -1,6 +1,6 @@
1
1
  import { createHash } from 'node:crypto';
2
- import type { AeoPrompt, AeoSurface, AgentProbeConfig } from '../schema';
3
- import { surfaceRunCounts, isAgentSurface } from '../schema';
2
+ import type { AeoPrompt, AeoSurface, ProbeDepth } from '../schema';
3
+ import { agentProbedPrompts, isAgentSurface, runsPerPromptOn } from '../schema';
4
4
  import type { CheckpointMatch, ProbeUnit } from '../stores/ports';
5
5
 
6
6
  export type {
@@ -51,27 +51,26 @@ export const unitRecordKey = (unit: ProbeUnit): string => {
51
51
 
52
52
  /**
53
53
  * The probe units a run plans for one section: chat surfaces cover every
54
- * prompt at the canonical run counts; agent surfaces follow the config's
55
- * agentProbes volume. Mirrors the pipeline's fan-out exactly — the planned
56
- * set is both the resume scope and the scoring denominator.
54
+ * prompt, agent surfaces the config's agentProbes subset, each at the depth
55
+ * runsPerPromptOn gives it. Mirrors the pipeline's fan-out exactly — the
56
+ * planned set is both the resume scope and the scoring denominator.
57
57
  */
58
- export const plannedProbeUnitsForSection = (args: {
59
- sectionKey: string;
60
- prompts: AeoPrompt[];
61
- surfaces: readonly AeoSurface[];
62
- agentProbes: AgentProbeConfig;
63
- }): ProbeUnit[] => {
58
+ export const plannedProbeUnitsForSection = (
59
+ args: ProbeDepth & {
60
+ sectionKey: string;
61
+ prompts: AeoPrompt[];
62
+ surfaces: readonly AeoSurface[];
63
+ },
64
+ ): ProbeUnit[] => {
64
65
  const chatSurfaces = args.surfaces.filter((s) => !isAgentSurface(s));
65
66
  const agentSurfaces = args.surfaces.filter(isAgentSurface);
66
- const agentPrompts = args.agentProbes.maxPromptsPerSection
67
- ? args.prompts.slice(0, args.agentProbes.maxPromptsPerSection)
68
- : args.prompts;
67
+ const agentPrompts = agentProbedPrompts(args.prompts, args.agentProbes);
69
68
 
70
69
  const units: ProbeUnit[] = [];
71
70
 
72
71
  for (const prompt of args.prompts) {
73
72
  for (const surface of chatSurfaces) {
74
- for (let run = 1; run <= surfaceRunCounts[surface]; run += 1) {
73
+ for (let run = 1; run <= runsPerPromptOn(surface, args); run += 1) {
75
74
  units.push(
76
75
  createUnit({
77
76
  sectionKey: args.sectionKey,
@@ -86,7 +85,7 @@ export const plannedProbeUnitsForSection = (args: {
86
85
 
87
86
  for (const prompt of agentPrompts) {
88
87
  for (const surface of agentSurfaces) {
89
- for (let run = 1; run <= args.agentProbes.runsPerPrompt; run += 1) {
88
+ for (let run = 1; run <= runsPerPromptOn(surface, args); run += 1) {
90
89
  units.push(
91
90
  createUnit({
92
91
  sectionKey: args.sectionKey,
@@ -0,0 +1,140 @@
1
+ import type { AeoSurface } from '../surfaces';
2
+ import type { TokenUsage } from './pricing';
3
+
4
+ // ============================================================================
5
+ // The coefficients the cost estimate and the ledger's reservations are
6
+ // computed from (specs/aeo-claude-operator-spec.md §4.2): tokens per
7
+ // captured answer and per run for the Codex stages and the host's calls,
8
+ // and dollars per probe and per search. A versioned resource, recalibrated
9
+ // each release from recorded runs' journals, which hold every session's
10
+ // usage. The estimate is a range, never a quote.
11
+ //
12
+ // Calibration 1 (2026-11-04): four local runs of 16 and 32 answers and one
13
+ // author session (src/models/__fixtures__/calibration-runs.json). The
14
+ // per-answer stages (analyze, qualify, review) used 34,000 to 62,000 input
15
+ // and 4,500 to 11,000 output tokens per answer; the write stage 280,000 to
16
+ // 760,000 input and 11,000 to 27,000 output tokens per run; 71 to 94
17
+ // percent of stage input was served from cache. The host calls used 2,000
18
+ // to 4,500 input and 4,400 to 8,000 output tokens per answer under
19
+ // extraction-only grounding, and 7,700 to 13,500 input and 11,000 to 13,000
20
+ // output under full grounding: reasoning is billed as output. The high
21
+ // ends carry headroom for a stronger model's longer reasoning and for
22
+ // review rounds.
23
+ //
24
+ // The spike (2026-11-04) ran one analyze batch of ten answers on each
25
+ // supported model: about 7,000 input and 300 to 450 output tokens per
26
+ // answer, none of the input served from cache. The cached share therefore
27
+ // runs from none at the dear end to the measured share at the cheap end.
28
+ //
29
+ // The probe and search figures are not calibrated yet: they are rough
30
+ // per-request assumptions (a probe's model tokens and its provider's search
31
+ // fee), to be replaced by the costs the gateway reports.
32
+ // ============================================================================
33
+
34
+ export const costCoefficientsVersion = 1;
35
+
36
+ export type TokenRange = {
37
+ input: number;
38
+ output: number;
39
+ };
40
+
41
+ export type Range<T> = { low: T; high: T };
42
+
43
+ /** Codex stage tokens. `perAnswer` covers every stage that reads answer
44
+ * files; `perRun` the write stage, which reads the whole report. */
45
+ export const stageTokens = {
46
+ perAnswer: {
47
+ low: { input: 30_000, output: 4000 },
48
+ high: { input: 90_000, output: 16_000 },
49
+ },
50
+ perRun: {
51
+ low: { input: 250_000, output: 10_000 },
52
+ high: { input: 900_000, output: 40_000 },
53
+ },
54
+ /** The share of stage input served from cache: high is cheap. The
55
+ * supported models reported none through the gateway in the spike. */
56
+ cachedShare: { low: 0, high: 0.8 },
57
+ } as const;
58
+
59
+ /** The one author session. */
60
+ export const authorTokens = {
61
+ session: {
62
+ low: { input: 250_000, output: 10_000 },
63
+ high: { input: 800_000, output: 45_000 },
64
+ },
65
+ } as const;
66
+
67
+ /** The author's research searches at the low end; the high end is the
68
+ * research tools' own spend cap (`authorToolCaps.searchSpendUsd`). */
69
+ export const authorSearchLowUsd = 0.05;
70
+
71
+ /** The host's own model calls per captured answer, by grounding:
72
+ * perception, source labels and the copy verifier always; claim research
73
+ * and adjudication under full grounding. */
74
+ export const hostTokensPerAnswer = {
75
+ extraction_only: {
76
+ low: { input: 1500, output: 3000 },
77
+ high: { input: 8000, output: 12_000 },
78
+ },
79
+ full: {
80
+ low: { input: 6000, output: 6000 },
81
+ high: { input: 24_000, output: 18_000 },
82
+ },
83
+ } as const;
84
+
85
+ /** Grounding search per captured answer under full grounding. */
86
+ export const searchUsdPerAnswer = { low: 0.001, high: 0.01 } as const;
87
+
88
+ /** One probe unit, by surface, in USD. The coding-agent surfaces run on
89
+ * the operator's own login and bill nothing to the run. */
90
+ export const probeUsd: Record<AeoSurface, Range<number>> = {
91
+ chatgpt: { low: 0.01, high: 0.05 },
92
+ gemini: { low: 0.02, high: 0.06 },
93
+ claude: { low: 0.02, high: 0.08 },
94
+ perplexity: { low: 0.01, high: 0.03 },
95
+ google_ai_overview: { low: 0.002, high: 0.006 },
96
+ claude_code: { low: 0, high: 0 },
97
+ codex: { low: 0, high: 0 },
98
+ cursor: { low: 0, high: 0 },
99
+ };
100
+
101
+ /** The calibrated workload a Codex session is: a batch of answer files
102
+ * (analyze, qualify, review), the whole report (write) or a brief
103
+ * (author). Each stage's descriptor names its own. */
104
+ export type SessionCost = 'answers' | 'report' | 'brief';
105
+
106
+ /**
107
+ * sessionReservation is what one Codex session is reserved at before it
108
+ * starts: the same high figures, cache share included, that the estimate's
109
+ * high end assumes, so a run under the cap the estimate recommends is never
110
+ * refused for its reservations. The session settles at the tokens it
111
+ * reports; its reservation bounds how far one session can carry the run
112
+ * past its cap.
113
+ */
114
+ export const sessionReservation = ({
115
+ cost,
116
+ answers,
117
+ }: {
118
+ cost: SessionCost;
119
+ answers: number;
120
+ }): TokenUsage => {
121
+ // One session is one stage over its batch; the per-answer high covers
122
+ // all three such stages, the heaviest two of which take about half each.
123
+ const batch = {
124
+ input: 50_000 + answers * (stageTokens.perAnswer.high.input / 2),
125
+ output: 8000 + answers * (stageTokens.perAnswer.high.output / 2),
126
+ };
127
+ const tokens = {
128
+ answers: batch,
129
+ report: stageTokens.perRun.high,
130
+ brief: authorTokens.session.high,
131
+ }[cost];
132
+
133
+ const reservation: TokenUsage = {
134
+ inputTokens: tokens.input,
135
+ cachedInputTokens: Math.round(tokens.input * stageTokens.cachedShare.low),
136
+ outputTokens: tokens.output,
137
+ };
138
+
139
+ return reservation;
140
+ };