literally-aeo 0.2.2 → 0.3.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 (304) hide show
  1. package/dist/cli.mjs +6031 -5158
  2. package/dist/lib/agents/author-schema.js +5 -5
  3. package/dist/lib/agents/author-validation.js +7 -7
  4. package/dist/lib/agents/copy-validation.js +9 -9
  5. package/dist/lib/agents/copywriter-input.js +8 -8
  6. package/dist/lib/agents/facts.js +7 -7
  7. package/dist/lib/agents/narrative-facts.js +6 -6
  8. package/dist/lib/agents/verifier.js +13 -12
  9. package/dist/lib/analysis/domain-classifier.js +12 -10
  10. package/dist/lib/analysis/domain-labels.js +4 -4
  11. package/dist/lib/analysis/outreach.js +2 -2
  12. package/dist/lib/analysis/progress.js +8 -8
  13. package/dist/lib/analysis/retrieval.js +5 -5
  14. package/dist/lib/analysis/scoring.js +5 -5
  15. package/dist/lib/analysis/search-analyzer.js +6 -6
  16. package/dist/lib/analysis/sentiment.js +12 -10
  17. package/dist/lib/analysis/source-mix.js +2 -2
  18. package/dist/lib/author/examples.js +6 -6
  19. package/dist/lib/bundle/contracts.js +6 -6
  20. package/dist/lib/bundle/export.js +18 -18
  21. package/dist/lib/bundle/journal.js +7 -7
  22. package/dist/lib/bundle/project-journal.js +10 -10
  23. package/dist/lib/bundle/project.js +16 -16
  24. package/dist/lib/bundle/read.js +19 -19
  25. package/dist/lib/bundle/recorder.js +8 -8
  26. package/dist/lib/bundle/redact.js +7 -7
  27. package/dist/lib/bundle/trace-coverage.js +7 -7
  28. package/dist/lib/bundle/verify-integrity.js +9 -9
  29. package/dist/lib/bundle/verify-measurement.js +22 -13
  30. package/dist/lib/bundle/verify-report.js +23 -15
  31. package/dist/lib/bundle/verify.js +31 -23
  32. package/dist/lib/capture-manifest.js +6 -6
  33. package/dist/lib/checks/crawler-access.js +2 -2
  34. package/dist/lib/checks/renderability.js +2 -2
  35. package/dist/lib/checks/run-checks.js +12 -12
  36. package/dist/lib/chunks/{chunk-3CMPR6ZZ.js → chunk-2C723CW7.js} +1 -1
  37. package/dist/lib/chunks/chunk-2FDSOZ6Q.js +287 -0
  38. package/dist/lib/chunks/{chunk-PWOYEIPF.js → chunk-2U5QSA6Q.js} +7 -7
  39. package/dist/lib/chunks/{chunk-6EI4CVRW.js → chunk-3ESH5NDR.js} +5 -1
  40. package/dist/lib/chunks/{chunk-VHKHYAC5.js → chunk-3S2FAVRE.js} +2 -2
  41. package/dist/lib/chunks/{chunk-LR27H2HZ.js → chunk-44NSZBCP.js} +6 -6
  42. package/dist/lib/chunks/{chunk-JBOOD6MU.js → chunk-4AWFF53U.js} +12 -4
  43. package/dist/lib/chunks/{chunk-MENTBQGB.js → chunk-4HPMLJKC.js} +4 -4
  44. package/dist/lib/chunks/{chunk-S6QOXJAL.js → chunk-4Q2WFZ5J.js} +11 -4
  45. package/dist/lib/chunks/{chunk-7DNLRXEY.js → chunk-5JU2Y2I6.js} +2 -2
  46. package/dist/lib/chunks/{chunk-KFAT65P7.js → chunk-64JFN2Q5.js} +1 -1
  47. package/dist/lib/chunks/chunk-66UE4TT2.js +245 -0
  48. package/dist/lib/chunks/chunk-6N3C6E3D.js +105 -0
  49. package/dist/lib/chunks/{chunk-F2NSJ6PG.js → chunk-6RED3G6K.js} +7 -3
  50. package/dist/lib/chunks/{chunk-HCUJ2J7P.js → chunk-7KLTOVIY.js} +9 -9
  51. package/dist/lib/chunks/{chunk-EOO5RBUW.js → chunk-7ZR3WDF2.js} +38 -5
  52. package/dist/lib/chunks/chunk-A5PF7UE2.js +86 -0
  53. package/dist/lib/chunks/{chunk-PKNODC6Y.js → chunk-AB7DUTX5.js} +1 -1
  54. package/dist/lib/chunks/{chunk-WDT2Y7D7.js → chunk-AQCWKHTE.js} +11 -7
  55. package/dist/lib/chunks/{chunk-UNCUG2YS.js → chunk-ASHFEFCU.js} +3 -3
  56. package/dist/lib/chunks/{chunk-BYHXNFWN.js → chunk-ASIFUJG2.js} +1 -1
  57. package/dist/lib/chunks/{chunk-ZSEY7AHQ.js → chunk-BBK54RVK.js} +14 -11
  58. package/dist/lib/chunks/chunk-BQMUZLHO.js +17 -0
  59. package/dist/lib/chunks/{chunk-QD3JXA3Y.js → chunk-CQNIPZH3.js} +18 -18
  60. package/dist/lib/chunks/{chunk-7HM6IZ3L.js → chunk-CVEXMYPW.js} +2 -2
  61. package/dist/lib/chunks/chunk-CXZIHHLJ.js +95 -0
  62. package/dist/lib/chunks/{chunk-75DMLOQ7.js → chunk-CYJNBVQB.js} +1 -1
  63. package/dist/lib/chunks/{chunk-FAUFE7MI.js → chunk-D7N5OLYL.js} +1 -1
  64. package/dist/lib/chunks/{chunk-E2YTTB6Q.js → chunk-DSK3PM4Z.js} +1 -1
  65. package/dist/lib/chunks/{chunk-TNL2GWYR.js → chunk-EUXNCXCR.js} +22 -0
  66. package/dist/lib/chunks/{chunk-FJL2V6P5.js → chunk-F4EQULFR.js} +6 -6
  67. package/dist/lib/chunks/{chunk-QGZ4QSUE.js → chunk-FHV4PBYG.js} +1 -1
  68. package/dist/lib/chunks/{chunk-K2FZFESR.js → chunk-FONFW67K.js} +4 -4
  69. package/dist/lib/chunks/{chunk-PIFTG6YW.js → chunk-FPPHYGIO.js} +2 -2
  70. package/dist/lib/chunks/{chunk-VXYQWE45.js → chunk-FYE4R5TY.js} +2 -2
  71. package/dist/lib/chunks/{chunk-JYCVBFH5.js → chunk-H2DOBJZC.js} +2 -2
  72. package/dist/lib/chunks/{chunk-XA27KAUV.js → chunk-HEWHNSDP.js} +68 -36
  73. package/dist/lib/chunks/{chunk-RXSHKWZJ.js → chunk-HLC6OHGO.js} +2 -2
  74. package/dist/lib/chunks/{chunk-6HMHXSCS.js → chunk-HXXFRZTJ.js} +2 -2
  75. package/dist/lib/chunks/{chunk-R5UPOEWE.js → chunk-HYMWNGOK.js} +10 -3
  76. package/dist/lib/chunks/chunk-IH67TEGY.js +73 -0
  77. package/dist/lib/chunks/{chunk-JKPBXPCW.js → chunk-IMADI2YP.js} +1 -1
  78. package/dist/lib/chunks/{chunk-AT3XMGES.js → chunk-JBGQFPTY.js} +4 -4
  79. package/dist/lib/chunks/{chunk-JQDQVG3D.js → chunk-JDU3ZCKO.js} +1 -1
  80. package/dist/lib/chunks/{chunk-2KH7LNK7.js → chunk-JGIX427K.js} +7 -7
  81. package/dist/lib/chunks/{chunk-7CW6U5WJ.js → chunk-JIE2ANVD.js} +1 -1
  82. package/dist/lib/chunks/{chunk-YEUCAPKP.js → chunk-JJFOILZK.js} +2 -2
  83. package/dist/lib/chunks/{chunk-F7DBTXKG.js → chunk-JMIK2QN3.js} +4 -3
  84. package/dist/lib/chunks/chunk-JW7DTYSI.js +116 -0
  85. package/dist/lib/chunks/{chunk-BFWK3TBN.js → chunk-JXLCKACO.js} +2 -2
  86. package/dist/lib/chunks/{chunk-7WO3FFPS.js → chunk-K5NQDJLE.js} +1 -1
  87. package/dist/lib/chunks/{chunk-BXF4OC74.js → chunk-KI2FB4Y3.js} +30 -16
  88. package/dist/lib/chunks/{chunk-Y2CZ6FZY.js → chunk-KRWDELRS.js} +30 -7
  89. package/dist/lib/chunks/{chunk-SIJOQRRK.js → chunk-KRXOJJR7.js} +1 -1
  90. package/dist/lib/chunks/chunk-KSUI4DAY.js +15 -0
  91. package/dist/lib/chunks/chunk-KXFZ3CH3.js +98 -0
  92. package/dist/lib/chunks/{chunk-XSER7WEB.js → chunk-LJCWZ5SZ.js} +14 -14
  93. package/dist/lib/chunks/{chunk-HGGRPOSA.js → chunk-LNYQMWJO.js} +3 -3
  94. package/dist/lib/chunks/{chunk-DL6YQDTE.js → chunk-LOIAGEKN.js} +2 -2
  95. package/dist/lib/chunks/{chunk-I3UE52ZV.js → chunk-LPOIMPJK.js} +2 -2
  96. package/dist/lib/chunks/{chunk-66T7JC57.js → chunk-LUKP64NX.js} +2 -2
  97. package/dist/lib/chunks/chunk-MNG5TZRW.js +208 -0
  98. package/dist/lib/chunks/{chunk-HGGOGCPX.js → chunk-MPQXB7HN.js} +7 -7
  99. package/dist/lib/chunks/{chunk-YGLWQFKL.js → chunk-MZ2KN3IH.js} +3 -3
  100. package/dist/lib/chunks/chunk-N62G4EWT.js +91 -0
  101. package/dist/lib/chunks/{chunk-7YDXD4MD.js → chunk-ODIXZHHX.js} +1 -1
  102. package/dist/lib/chunks/{chunk-GLUGYZQO.js → chunk-OTVHGRCO.js} +8 -8
  103. package/dist/lib/chunks/{chunk-RIJERFGU.js → chunk-OVF27NAO.js} +69 -17
  104. package/dist/lib/chunks/chunk-P6LHGBYU.js +90 -0
  105. package/dist/lib/chunks/{chunk-U5USH2HB.js → chunk-PAL5SXIP.js} +1 -1
  106. package/dist/lib/chunks/{chunk-W5XYW6ZM.js → chunk-PT6PK2MJ.js} +26 -19
  107. package/dist/lib/chunks/{chunk-OD36HUXA.js → chunk-Q22FCF4A.js} +6 -7
  108. package/dist/lib/chunks/chunk-QKTKQSPS.js +292 -0
  109. package/dist/lib/chunks/{chunk-K4Y5NT4M.js → chunk-QO5TPMWS.js} +2 -2
  110. package/dist/lib/chunks/{chunk-4GLW3ZRO.js → chunk-QUZYFAGP.js} +4 -4
  111. package/dist/lib/chunks/{chunk-T6XZQOXS.js → chunk-QVMPTT7R.js} +5 -5
  112. package/dist/lib/chunks/{chunk-OOLWU667.js → chunk-RGZY6YUQ.js} +5 -5
  113. package/dist/lib/chunks/{chunk-U6BW6LGX.js → chunk-RM2VVR7Y.js} +1 -1
  114. package/dist/lib/chunks/{chunk-AJO7XVXK.js → chunk-RMSH7RUG.js} +6 -6
  115. package/dist/lib/chunks/{chunk-V5B6UZ3E.js → chunk-RQGEPR6V.js} +1 -0
  116. package/dist/lib/chunks/{chunk-V5JJEEBT.js → chunk-RYB77E7O.js} +6 -5
  117. package/dist/lib/chunks/chunk-S24JGY7B.js +97 -0
  118. package/dist/lib/chunks/{chunk-6GKKALCI.js → chunk-SF4UJ2AY.js} +1 -1
  119. package/dist/lib/chunks/chunk-SJCUR4QX.js +94 -0
  120. package/dist/lib/chunks/{chunk-XAN4CRFP.js → chunk-SQ55KGHO.js} +1 -1
  121. package/dist/lib/chunks/{chunk-ZOGIJGU3.js → chunk-TKOQMB6A.js} +7 -7
  122. package/dist/lib/chunks/{chunk-UYDQXXDQ.js → chunk-TWK6IA4P.js} +1 -1
  123. package/dist/lib/chunks/{chunk-DVFFYY5G.js → chunk-U42I3SBR.js} +13 -9
  124. package/dist/lib/chunks/{chunk-PIF3GL62.js → chunk-UECQONVZ.js} +5 -5
  125. package/dist/lib/chunks/{chunk-FDM2YNQL.js → chunk-VTY53IFN.js} +1 -1
  126. package/dist/lib/chunks/chunk-VYUC772A.js +338 -0
  127. package/dist/lib/chunks/{chunk-WCLKIPJV.js → chunk-WPCBE2NZ.js} +1 -1
  128. package/dist/lib/chunks/{chunk-3OE4UQIB.js → chunk-WRHGLRUK.js} +5 -5
  129. package/dist/lib/chunks/{chunk-J7QKT5E7.js → chunk-WUIY7BXR.js} +34 -17
  130. package/dist/lib/chunks/{chunk-7YYDUHJG.js → chunk-WZA4H4TG.js} +39 -13
  131. package/dist/lib/chunks/{chunk-NH4QGBJV.js → chunk-XBSA7MNJ.js} +7 -2
  132. package/dist/lib/chunks/chunk-XTBCXEH7.js +243 -0
  133. package/dist/lib/chunks/{chunk-ZQ3ER7JD.js → chunk-YPVJAXPP.js} +1 -1
  134. package/dist/lib/chunks/{chunk-SASE7U6E.js → chunk-YQD5ITKI.js} +1 -1
  135. package/dist/lib/chunks/{chunk-LTCDLURT.js → chunk-YY4BH5XM.js} +6 -6
  136. package/dist/lib/chunks/{chunk-J5NPHPXY.js → chunk-Z3BZRBQF.js} +36 -2
  137. package/dist/lib/chunks/{chunk-XFUYEFQP.js → chunk-ZBQU2VU3.js} +1 -1
  138. package/dist/lib/chunks/{chunk-7YZPEX3T.js → chunk-ZHGABG7L.js} +2 -2
  139. package/dist/lib/chunks/chunk-ZZCRYG36.js +31 -0
  140. package/dist/lib/cli/bundle-commands.js +89 -73
  141. package/dist/lib/cli/run-commands.js +136 -92
  142. package/dist/lib/cli/status-command.js +75 -59
  143. package/dist/lib/codex-workflow/aggregate.js +20 -12
  144. package/dist/lib/codex-workflow/author-tools.js +7 -7
  145. package/dist/lib/codex-workflow/author.js +23 -22
  146. package/dist/lib/codex-workflow/capture.js +38 -17
  147. package/dist/lib/codex-workflow/checkpoint.js +7 -7
  148. package/dist/lib/codex-workflow/checks.js +9 -9
  149. package/dist/lib/codex-workflow/copy-editor.js +19 -18
  150. package/dist/lib/codex-workflow/copy-recovery.js +4 -4
  151. package/dist/lib/codex-workflow/copy.js +16 -15
  152. package/dist/lib/codex-workflow/finish.js +28 -24
  153. package/dist/lib/codex-workflow/host-models.js +2 -2
  154. package/dist/lib/codex-workflow/loop.js +51 -46
  155. package/dist/lib/codex-workflow/quality.js +4 -4
  156. package/dist/lib/codex-workflow/run-inputs.js +6 -6
  157. package/dist/lib/codex-workflow/run-source.js +16 -16
  158. package/dist/lib/codex-workflow/schemas.js +6 -6
  159. package/dist/lib/codex-workflow/session.js +8 -8
  160. package/dist/lib/codex-workflow/stage.js +30 -28
  161. package/dist/lib/codex-workflow/workdir.js +18 -11
  162. package/dist/lib/engine/audit-file.js +7 -7
  163. package/dist/lib/engine/author.js +38 -36
  164. package/dist/lib/engine/cost-estimate.js +37 -9
  165. package/dist/lib/engine/local-run.js +74 -58
  166. package/dist/lib/engine/preflight.js +37 -9
  167. package/dist/lib/engine/rejudge.js +80 -64
  168. package/dist/lib/engine/run-bindings.js +62 -0
  169. package/dist/lib/engine/run-status.js +75 -59
  170. package/dist/lib/engine/templates.js +8 -8
  171. package/dist/lib/grounding/controller.js +8 -7
  172. package/dist/lib/grounding/extract.js +8 -6
  173. package/dist/lib/grounding/grounding-runtime.js +22 -21
  174. package/dist/lib/grounding/model-usage.js +2 -2
  175. package/dist/lib/grounding/model.js +7 -5
  176. package/dist/lib/grounding/recorded-tools.js +9 -9
  177. package/dist/lib/harness/report/artifacts.js +5 -5
  178. package/dist/lib/lib/checkpoint.js +5 -5
  179. package/dist/lib/lib/log.js +1 -1
  180. package/dist/lib/models/accounting.js +1 -1
  181. package/dist/lib/models/batching.js +6 -4
  182. package/dist/lib/models/budget-protection.js +1 -1
  183. package/dist/lib/models/cost-coefficients.js +2 -1
  184. package/dist/lib/models/gateway-cost.js +7 -0
  185. package/dist/lib/models/structured.js +5 -3
  186. package/dist/lib/models/supported-models.js +1 -1
  187. package/dist/lib/pipeline.js +36 -17
  188. package/dist/lib/probes/adapter.js +6 -0
  189. package/dist/lib/probes/adapters/cli-agents.js +44 -0
  190. package/dist/lib/probes/adapters/cli-claude-code.js +21 -0
  191. package/dist/lib/probes/adapters/cli-codex.js +23 -0
  192. package/dist/lib/probes/adapters/cli-cursor.js +21 -0
  193. package/dist/lib/probes/adapters/cli-process.js +34 -0
  194. package/dist/lib/probes/adapters/dataforseo-ai-overview.js +20 -0
  195. package/dist/lib/probes/adapters/gateway-chat.js +30 -0
  196. package/dist/lib/probes/adapters/gateway-perplexity.js +19 -0
  197. package/dist/lib/probes/agent-cli-parsers.js +2 -2
  198. package/dist/lib/probes/agent-clis.js +26 -11
  199. package/dist/lib/probes/answer-text.js +21 -0
  200. package/dist/lib/probes/attempt.js +28 -0
  201. package/dist/lib/probes/bindings.js +69 -0
  202. package/dist/lib/probes/charged-trace.js +47 -3
  203. package/dist/lib/probes/dataforseo-locale.js +1 -1
  204. package/dist/lib/probes/dataforseo.js +8 -5
  205. package/dist/lib/probes/grounding-urls.js +6 -4
  206. package/dist/lib/probes/legacy-bindings.js +7 -0
  207. package/dist/lib/probes/limits.js +1 -1
  208. package/dist/lib/probes/probes.js +33 -12
  209. package/dist/lib/runner.js +17 -14
  210. package/dist/lib/schema.js +4 -4
  211. package/dist/lib/section-result.js +6 -6
  212. package/dist/lib/stores/artifacts.js +7 -7
  213. package/dist/lib/stores/files.js +19 -17
  214. package/dist/lib/stores/local-versions.js +5 -5
  215. package/dist/lib/stores/memory.js +19 -14
  216. package/dist/lib/stores/publication.js +10 -10
  217. package/dist/lib/stores/unit-record.js +28 -0
  218. package/dist/lib/viewer/server.js +32 -24
  219. package/dist/lib/workflow/schema.js +3 -3
  220. package/dist/types/bundle/contracts.d.ts +1 -1
  221. package/dist/types/capture-manifest.d.ts +1 -0
  222. package/dist/types/codex-workflow/capture.d.ts +13 -0
  223. package/dist/types/codex-workflow/workdir.d.ts +0 -1
  224. package/dist/types/engine/cost-estimate.d.ts +5 -1
  225. package/dist/types/engine/preflight.d.ts +6 -1
  226. package/dist/types/engine/run-bindings.d.ts +25 -0
  227. package/dist/types/models/accounting.d.ts +7 -0
  228. package/dist/types/models/cost-coefficients.d.ts +5 -5
  229. package/dist/types/models/gateway-cost.d.ts +3 -0
  230. package/dist/types/pipeline.d.ts +2 -0
  231. package/dist/types/probes/adapter.d.ts +112 -0
  232. package/dist/types/probes/adapters/cli-agents.d.ts +19 -0
  233. package/dist/types/probes/adapters/cli-claude-code.d.ts +4 -0
  234. package/dist/types/probes/adapters/cli-codex.d.ts +10 -0
  235. package/dist/types/probes/adapters/cli-cursor.d.ts +4 -0
  236. package/dist/types/probes/adapters/cli-process.d.ts +86 -0
  237. package/dist/types/probes/adapters/dataforseo-ai-overview.d.ts +12 -0
  238. package/dist/types/probes/adapters/gateway-chat.d.ts +32 -0
  239. package/dist/types/probes/adapters/gateway-perplexity.d.ts +10 -0
  240. package/dist/types/probes/agent-clis.d.ts +7 -49
  241. package/dist/types/probes/answer-text.d.ts +20 -0
  242. package/dist/types/probes/attempt.d.ts +113 -0
  243. package/dist/types/probes/bindings.d.ts +79 -0
  244. package/dist/types/probes/charged-trace.d.ts +2 -1
  245. package/dist/types/probes/dataforseo.d.ts +24 -1
  246. package/dist/types/probes/grounding-urls.d.ts +18 -5
  247. package/dist/types/probes/legacy-bindings.d.ts +36 -0
  248. package/dist/types/probes/limits.d.ts +12 -6
  249. package/dist/types/probes/probe-trace.d.ts +10 -0
  250. package/dist/types/probes/probes.d.ts +5 -3
  251. package/dist/types/stores/ports.d.ts +1 -0
  252. package/dist/types/stores/unit-record.d.ts +11 -0
  253. package/package.json +6 -6
  254. package/src/analysis/progress.ts +10 -1
  255. package/src/bundle/contracts.ts +1 -1
  256. package/src/bundle/recorder.ts +47 -1
  257. package/src/capture-manifest.ts +6 -0
  258. package/src/cli/run-commands.ts +37 -1
  259. package/src/codex-workflow/capture.ts +60 -0
  260. package/src/codex-workflow/workdir.ts +3 -4
  261. package/src/engine/cost-estimate.ts +10 -4
  262. package/src/engine/local-run.ts +21 -2
  263. package/src/engine/preflight.ts +113 -17
  264. package/src/engine/rejudge.ts +5 -0
  265. package/src/engine/run-bindings.ts +142 -0
  266. package/src/grounding/extract.ts +1 -0
  267. package/src/grounding/model-usage.ts +4 -0
  268. package/src/lib/log.ts +17 -15
  269. package/src/models/accounting.ts +34 -0
  270. package/src/models/budget-protection.ts +1 -0
  271. package/src/models/cost-coefficients.ts +17 -13
  272. package/src/models/gateway-cost.ts +32 -0
  273. package/src/models/structured.ts +2 -10
  274. package/src/models/supported-models.ts +2 -2
  275. package/src/pipeline.ts +36 -17
  276. package/src/probes/adapter.ts +122 -0
  277. package/src/probes/adapters/cli-agents.ts +123 -0
  278. package/src/probes/adapters/cli-claude-code.ts +119 -0
  279. package/src/probes/adapters/cli-codex.ts +145 -0
  280. package/src/probes/adapters/cli-cursor.ts +95 -0
  281. package/src/probes/adapters/cli-process.ts +522 -0
  282. package/src/probes/adapters/dataforseo-ai-overview.ts +106 -0
  283. package/src/probes/adapters/gateway-chat.ts +339 -0
  284. package/src/probes/adapters/gateway-perplexity.ts +104 -0
  285. package/src/probes/agent-clis.ts +151 -1088
  286. package/src/probes/answer-text.ts +153 -0
  287. package/src/probes/attempt.ts +462 -0
  288. package/src/probes/bindings.ts +344 -0
  289. package/src/probes/charged-trace.ts +54 -13
  290. package/src/probes/dataforseo-locale.ts +13 -2
  291. package/src/probes/dataforseo.ts +265 -188
  292. package/src/probes/grounding-urls.ts +68 -19
  293. package/src/probes/legacy-bindings.ts +40 -0
  294. package/src/probes/limits.ts +31 -18
  295. package/src/probes/probe-trace.ts +10 -0
  296. package/src/probes/probes.ts +64 -736
  297. package/src/runner.ts +13 -0
  298. package/src/stores/files.ts +78 -54
  299. package/src/stores/memory.ts +4 -1
  300. package/src/stores/ports.ts +3 -0
  301. package/src/stores/unit-record.ts +151 -0
  302. package/dist/lib/chunks/chunk-BGAHZIL3.js +0 -563
  303. package/dist/lib/chunks/chunk-IB6RROHE.js +0 -204
  304. package/dist/lib/chunks/chunk-WZGI7UVM.js +0 -937
package/src/lib/log.ts CHANGED
@@ -30,12 +30,11 @@ const levelOrder: Record<LogLevel, number> = {
30
30
  // Console formatting
31
31
  // ---------------------------------------------------------------------------
32
32
 
33
- // The logger reads the environment directly because `src/lib/env.ts` loads
34
- // dotenv on import, and every module imports this one.
35
- const NO_COLOR = readEnv('NO_COLOR');
36
- const AEO_DEBUG = readEnv('AEO_DEBUG');
37
-
38
- const useColor = Boolean(process.stdout.isTTY) && !NO_COLOR;
33
+ // Read when a line is emitted, never into a constant at import: every
34
+ // module imports this one, and importing a library module reads nothing.
35
+ const useColor = (): boolean => {
36
+ return Boolean(process.stdout.isTTY) && !readEnv('NO_COLOR');
37
+ };
39
38
 
40
39
  const ansi = {
41
40
  reset: '\u001b[0m',
@@ -47,14 +46,14 @@ const ansi = {
47
46
  };
48
47
 
49
48
  const paint = (text: string, color: string): string => {
50
- return useColor ? `${color}${text}${ansi.reset}` : text;
49
+ return useColor() ? `${color}${text}${ansi.reset}` : text;
51
50
  };
52
51
 
53
- const levelTags: Record<LogLevel, string> = {
54
- debug: paint('DEBUG', ansi.gray),
55
- info: paint('INFO ', ansi.cyan),
56
- warn: paint('WARN ', ansi.yellow),
57
- error: paint('ERROR', ansi.red),
52
+ const levelTags: Record<LogLevel, { text: string; color: string }> = {
53
+ debug: { text: 'DEBUG', color: ansi.gray },
54
+ info: { text: 'INFO ', color: ansi.cyan },
55
+ warn: { text: 'WARN ', color: ansi.yellow },
56
+ error: { text: 'ERROR', color: ansi.red },
58
57
  };
59
58
 
60
59
  const formatClockTime = (date: Date): string => {
@@ -89,18 +88,21 @@ const formatFields = (fields?: LogFields): string => {
89
88
  return ` ${parts.join(' ')}`;
90
89
  };
91
90
 
92
- const consoleMinLevel: LogLevel = AEO_DEBUG ? 'debug' : 'info';
91
+ const consoleMinLevel = (): LogLevel => {
92
+ return readEnv('AEO_DEBUG') ? 'debug' : 'info';
93
+ };
93
94
 
94
95
  // ---------------------------------------------------------------------------
95
96
  // Emission
96
97
  // ---------------------------------------------------------------------------
97
98
 
98
99
  const emit = ({ level, component, message, fields }: LogEntry): void => {
99
- if (levelOrder[level] < levelOrder[consoleMinLevel]) {
100
+ if (levelOrder[level] < levelOrder[consoleMinLevel()]) {
100
101
  return;
101
102
  }
102
103
 
103
- const line = `${paint(formatClockTime(new Date()), ansi.dim)} ${levelTags[level]} ${paint(
104
+ const tag = levelTags[level];
105
+ const line = `${paint(formatClockTime(new Date()), ansi.dim)} ${paint(tag.text, tag.color)} ${paint(
104
106
  `[${component}]`,
105
107
  ansi.dim,
106
108
  )} ${message}${paint(formatFields(fields), ansi.dim)}`;
@@ -127,6 +127,13 @@ export type ModelCallAccounting = {
127
127
  reserve(call: ModelCallReservation): Promise<void>;
128
128
  assertOwned(): Promise<void>;
129
129
  settle(callId: string, usage: ModelCallUsage): Promise<void>;
130
+ /**
131
+ * Withdraws a reservation whose call was never dispatched (its operation
132
+ * could not be recorded first). Unlike a settlement at $0, it records no
133
+ * cost the provider did not report: the call leaves the ledger. A settled
134
+ * call cannot be released.
135
+ */
136
+ release(callId: string): Promise<void>;
130
137
  /** Present when the run records its execution: the request before
131
138
  * dispatch, the response before settlement. A failure stops the call. */
132
139
  observe?(callId: string, evidence: ModelCallEvidence): Promise<void>;
@@ -318,6 +325,22 @@ const settleCall = (
318
325
  return settled;
319
326
  };
320
327
 
328
+ const releaseCall = (state: BudgetState, callId: string): BudgetState => {
329
+ const call = state.calls[callId];
330
+
331
+ if (!call) {
332
+ throw new ModelBudgetError('Model call was not reserved');
333
+ }
334
+
335
+ if (call.usage) {
336
+ throw new ModelBudgetError('A settled model call cannot be released');
337
+ }
338
+
339
+ const { [callId]: _released, ...calls } = state.calls;
340
+
341
+ return { ...state, calls };
342
+ };
343
+
321
344
  // Runs synchronous work so that a throw becomes a rejected promise, as it would
322
345
  // inside an async function.
323
346
  const runAsPromise = (work: () => void) => {
@@ -348,6 +371,11 @@ export const createMemoryModelAccounting = (
348
371
  state.calls = settleCall(state, { callId, usage }).calls;
349
372
  });
350
373
  },
374
+ release: (callId: string) => {
375
+ return runAsPromise(() => {
376
+ state.calls = releaseCall(state, callId).calls;
377
+ });
378
+ },
351
379
  };
352
380
 
353
381
  return accounting;
@@ -463,6 +491,9 @@ export const createFileModelAccounting = (args: {
463
491
  settle: async (callId, usage) => {
464
492
  await update((state) => settleCall(state, { callId, usage }));
465
493
  },
494
+ release: async (callId) => {
495
+ await update((state) => releaseCall(state, callId));
496
+ },
466
497
  };
467
498
 
468
499
  return accounting;
@@ -650,6 +681,9 @@ export const createPostgresModelAccounting = (args: {
650
681
  settle: async (callId, usage) => {
651
682
  await update((state) => settleCall(state, { callId, usage }));
652
683
  },
684
+ release: async (callId) => {
685
+ await update((state) => releaseCall(state, callId));
686
+ },
653
687
  };
654
688
 
655
689
  return accounting;
@@ -35,6 +35,7 @@ export const withModelBudgetProtection = (
35
35
  observe: (callId, evidence) =>
36
36
  accounting.observe?.(callId, evidence) ?? Promise.resolve(),
37
37
  settle: (callId, usage) => accounting.settle(callId, usage),
38
+ release: (callId) => accounting.release(callId),
38
39
  reserve: (call) => {
39
40
  let usd = copy.usd + verifier.usd;
40
41
  let tokens = copy.tokens + verifier.tokens;
@@ -1,4 +1,4 @@
1
- import type { AeoSurface } from '../surfaces';
1
+ import { ProbeAdapterId } from '../probes/adapter';
2
2
  import type { TokenUsage } from './pricing';
3
3
 
4
4
  // ============================================================================
@@ -29,9 +29,13 @@ import type { TokenUsage } from './pricing';
29
29
  // The probe and search figures are not calibrated yet: they are rough
30
30
  // per-request assumptions (a probe's model tokens and its provider's search
31
31
  // fee), to be replaced by the costs the gateway reports.
32
+ //
33
+ // Version 2 (probe adapters spec §4.8) keys the probe figures by adapter
34
+ // rather than by surface, with version 1's numbers for every default
35
+ // adapter: a surface costs what the adapter it is bound to costs.
32
36
  // ============================================================================
33
37
 
34
- export const costCoefficientsVersion = 1;
38
+ export const costCoefficientsVersion = 2;
35
39
 
36
40
  export type TokenRange = {
37
41
  input: number;
@@ -85,17 +89,17 @@ export const hostTokensPerAnswer = {
85
89
  /** Grounding search per captured answer under full grounding. */
86
90
  export const searchUsdPerAnswer = { low: 0.001, high: 0.01 } as const;
87
91
 
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 },
92
+ /** One probe unit, by adapter, in USD. The coding-agent CLIs run on the
93
+ * operator's own plan and bill nothing to the run's cap. */
94
+ export const probeUsd: Readonly<Record<ProbeAdapterId, Range<number>>> = {
95
+ [ProbeAdapterId.GATEWAY_OPENAI]: { low: 0.01, high: 0.05 },
96
+ [ProbeAdapterId.GATEWAY_GOOGLE]: { low: 0.02, high: 0.06 },
97
+ [ProbeAdapterId.GATEWAY_ANTHROPIC]: { low: 0.02, high: 0.08 },
98
+ [ProbeAdapterId.GATEWAY_PERPLEXITY]: { low: 0.01, high: 0.03 },
99
+ [ProbeAdapterId.DATAFORSEO_AI_OVERVIEW]: { low: 0.002, high: 0.006 },
100
+ [ProbeAdapterId.CLI_CLAUDE_CODE]: { low: 0, high: 0 },
101
+ [ProbeAdapterId.CLI_CODEX]: { low: 0, high: 0 },
102
+ [ProbeAdapterId.CLI_CURSOR]: { low: 0, high: 0 },
99
103
  };
100
104
 
101
105
  /** The calibrated workload a Codex session is: a batch of answer files
@@ -0,0 +1,32 @@
1
+ import { isObject } from '../lib/type-guards';
2
+
3
+ // ============================================================================
4
+ // The cost the Vercel AI Gateway reports for a call, read one way for every
5
+ // caller: host model calls (structured.ts) and chat probes alike. A value the
6
+ // gateway did not report, or reported in a shape that is not a cost, is
7
+ // unknown (undefined), never zero.
8
+ // ============================================================================
9
+
10
+ /** reportedNumber reads a non-negative number given as a number or a
11
+ * numeric string. */
12
+ const reportedNumber = (value: unknown): number | undefined => {
13
+ const number =
14
+ typeof value === 'string' && value.trim() ? Number(value) : value;
15
+
16
+ return typeof number === 'number' && Number.isFinite(number) && number >= 0
17
+ ? number
18
+ : undefined;
19
+ };
20
+
21
+ /** gatewayCostUsd is the cost in a response's provider metadata, when the
22
+ * gateway reported one. */
23
+ export const gatewayCostUsd = (
24
+ providerMetadata: unknown,
25
+ ): number | undefined => {
26
+ const cost =
27
+ isObject(providerMetadata) && isObject(providerMetadata.gateway)
28
+ ? providerMetadata.gateway.cost
29
+ : undefined;
30
+
31
+ return reportedNumber(cost);
32
+ };
@@ -23,6 +23,7 @@ import {
23
23
  type InternalModelRoleConfig,
24
24
  } from './profiles';
25
25
  import { servedModelOf } from './served-model';
26
+ import { gatewayCostUsd } from './gateway-cost';
26
27
 
27
28
  export type StructuredCallUsage = {
28
29
  callId: string;
@@ -147,15 +148,6 @@ const reasoningEffortOf = (
147
148
  return openai?.reasoningEffort ?? gatewayEffort;
148
149
  };
149
150
 
150
- const reportedNumber = (value: unknown): number | undefined => {
151
- const number =
152
- typeof value === 'string' && value.trim() ? Number(value) : value;
153
-
154
- return typeof number === 'number' && Number.isFinite(number) && number >= 0
155
- ? number
156
- : undefined;
157
- };
158
-
159
151
  const isGatewayCreditRefusal = (error: unknown): boolean => {
160
152
  // Gateway requires a positive balance before routing even BYOK requests:
161
153
  // https://vercel.com/docs/ai-gateway/authentication-and-byok/byok
@@ -320,7 +312,7 @@ const gatewayTransport: StructuredTransport = async (input) => {
320
312
  outputTokens: reported.outputTokens,
321
313
  cachedInputTokens: reported.inputTokenDetails.cacheReadTokens,
322
314
  reasoningTokens: reported.outputTokenDetails.reasoningTokens,
323
- costUsd: reportedNumber(providerMetadata?.gateway?.cost),
315
+ costUsd: gatewayCostUsd(providerMetadata),
324
316
  };
325
317
 
326
318
  try {
@@ -42,7 +42,7 @@ export const supportedModels: readonly SupportedModel[] = [
42
42
  id: 'anthropic/claude-opus-5.5',
43
43
  label: 'Claude Opus 5.5',
44
44
  pricingUsdPerMillion: { input: 4, output: 20, cachedInput: 0.2 },
45
- pricingCheckedAt: '2026-11-08',
45
+ pricingCheckedAt: '2026-11-09',
46
46
  contextWindow: 1_000_000,
47
47
  maxOutputTokens: 128_000,
48
48
  thinkingInOutput: true,
@@ -54,7 +54,7 @@ export const supportedModels: readonly SupportedModel[] = [
54
54
  id: 'anthropic/claude-sonnet-5.5',
55
55
  label: 'Claude Sonnet 5.5',
56
56
  pricingUsdPerMillion: { input: 2, output: 10, cachedInput: 0.1 },
57
- pricingCheckedAt: '2026-11-08',
57
+ pricingCheckedAt: '2026-11-09',
58
58
  contextWindow: 1_000_000,
59
59
  maxOutputTokens: 128_000,
60
60
  thinkingInOutput: true,
package/src/pipeline.ts CHANGED
@@ -12,11 +12,7 @@ import type {
12
12
  } from './schema';
13
13
  import { agentProbedPrompts, isAgentSurface } from './schema';
14
14
  import { createLog } from './lib/log';
15
- import {
16
- aiSearchProbeModels,
17
- runProbesForPrompts,
18
- type ProbeResult,
19
- } from './probes/probes';
15
+ import { runProbesForPrompts, type ProbeResult } from './probes/probes';
20
16
  import {
21
17
  runAgentProbesForPrompts,
22
18
  type AgentCliVersions,
@@ -27,6 +23,9 @@ import type { ProbeOutcome } from './probes/outcomes';
27
23
  import type { ProbeFailureKind } from './probes/failure';
28
24
  import type { ProbeLimiter } from './probes/limits';
29
25
  import { withSection, type ProbeTrace } from './probes/probe-trace';
26
+ import { requestedModelOf } from './probes/attempt';
27
+ import type { ProbeDependencies, RunBindings } from './probes/bindings';
28
+ import { legacyProbeBindings } from './probes/legacy-bindings';
30
29
  import {
31
30
  plannedProbeUnitsForSection,
32
31
  probeUnitKey,
@@ -148,6 +147,9 @@ export type SectionRunArgs = {
148
147
  // The run journal: every probe attempt becomes an operation.
149
148
  trace?: ProbeTrace;
150
149
  signal?: AbortSignal;
150
+ // What the probe adapters are created with: the gateway, credentials,
151
+ // clients.
152
+ probeDependencies: ProbeDependencies;
151
153
  logContext: Record<string, unknown>;
152
154
  };
153
155
 
@@ -207,20 +209,29 @@ export type SectionCaptureSummary = Omit<SectionCapture, 'probes'> & {
207
209
  probeCount: number;
208
210
  };
209
211
 
210
- // The model a capture asked for: the pinned chat model for an AI-search
211
- // surface, the pinned CLI model for an agent probe, null for a CLI default.
212
- const requestedModelOf = (probe: CheckpointProbe): string | null => {
213
- if (isProbeModelSurface(probe.modelName)) {
214
- return aiSearchProbeModels[probe.modelName];
215
- }
216
-
217
- return 'requestedModel' in probe ? (probe.requestedModel ?? null) : null;
212
+ // The model a capture asked for, by the binding that captured it: the bound
213
+ // model of a model API, else the one an agent's answer names, else none.
214
+ const capturedRequestedModel = (
215
+ probe: CheckpointProbe,
216
+ bindings: RunBindings,
217
+ ): string | null => {
218
+ return requestedModelOf(
219
+ bindings[probe.modelName],
220
+ 'requestedModel' in probe ? probe.requestedModel : undefined,
221
+ );
218
222
  };
219
223
 
220
- const isProbeModelSurface = (
224
+ // The adapter a capture records (probe adapters spec §4.6): only one that
225
+ // is not the surface's legacy adapter, so a capture taken with the legacy
226
+ // adapter keeps the bytes, profile and collection digest older releases
227
+ // gave it. Absent means the legacy adapter.
228
+ const recordedAdapterOf = (
221
229
  surface: AeoSurface,
222
- ): surface is keyof typeof aiSearchProbeModels => {
223
- return surface in aiSearchProbeModels;
230
+ bindings: RunBindings,
231
+ ): { adapter?: string } => {
232
+ const { adapter } = bindings[surface];
233
+
234
+ return adapter === legacyProbeBindings[surface].adapter ? {} : { adapter };
224
235
  };
225
236
 
226
237
  const isAgentProbe = (probe: Probe): probe is AgentProbeResult => {
@@ -330,7 +341,10 @@ export const captureSectionProbes = async (
330
341
  runId: args.runId,
331
342
  capturedAt: new Date().toISOString(),
332
343
  captureMetadata: {
333
- requestedModel: requestedModelOf(probe),
344
+ requestedModel: capturedRequestedModel(
345
+ probe,
346
+ args.probeDependencies.bindings,
347
+ ),
334
348
  reportedModel: probe.reportedModel ?? null,
335
349
  // Progress comparisons hash these into each answer's collection
336
350
  // method, so they stay as earlier releases recorded them. Chat
@@ -342,6 +356,10 @@ export const captureSectionProbes = async (
342
356
  language: args.language,
343
357
  agentProbes: args.agentProbes,
344
358
  },
359
+ ...recordedAdapterOf(
360
+ probe.modelName,
361
+ args.probeDependencies.bindings,
362
+ ),
345
363
  },
346
364
  probe,
347
365
  });
@@ -378,6 +396,7 @@ export const captureSectionProbes = async (
378
396
  trace,
379
397
  limiter: args.limiter,
380
398
  signal: args.signal,
399
+ dependencies: args.probeDependencies,
381
400
  },
382
401
  { logContext: args.logContext },
383
402
  )
@@ -0,0 +1,122 @@
1
+ import type { LanguageModel } from 'ai';
2
+ import type { Range } from '../models/cost-coefficients';
3
+ import type { RetrievalExposure, RetrievalLog } from '../schema';
4
+ import type { AeoSurface } from '../surfaces';
5
+ import type { AIOverviewReference } from './dataforseo';
6
+ import type { ProbeFailureKind } from './failure';
7
+ import type { ProbeProvider } from './limits';
8
+
9
+ // ============================================================================
10
+ // The probe port (specs/aeo-probe-adapters-spec.md §4.2): one vendor's way
11
+ // of asking one buyer question on one surface. An adapter translates the
12
+ // vendor's request and response and classifies its errors; the host's
13
+ // attempt loop (attempt.ts) owns the pools, the journal, retries, answer
14
+ // finalisation and banking. Importing this module loads no SDK.
15
+ // ============================================================================
16
+
17
+ /** Every registered adapter, with its version. A change to an adapter's
18
+ * request or parsing bumps its version. */
19
+ export const ProbeAdapterId = {
20
+ GATEWAY_OPENAI: 'gateway.openai@1',
21
+ GATEWAY_GOOGLE: 'gateway.google@1',
22
+ GATEWAY_ANTHROPIC: 'gateway.anthropic@1',
23
+ GATEWAY_PERPLEXITY: 'gateway.perplexity@1',
24
+ DATAFORSEO_AI_OVERVIEW: 'dataforseo.ai_overview@1',
25
+ CLI_CLAUDE_CODE: 'cli.claude_code@1',
26
+ CLI_CODEX: 'cli.codex@1',
27
+ CLI_CURSOR: 'cli.cursor@1',
28
+ } as const;
29
+
30
+ export type ProbeAdapterId =
31
+ (typeof ProbeAdapterId)[keyof typeof ProbeAdapterId];
32
+
33
+ /** A setting an adapter reads. Settings that share a group are
34
+ * alternatives: any one of them is enough. `billsAccount` names the
35
+ * provider account an auth setting bills per use, outside the run's cap;
36
+ * plan and doctor disclose it. */
37
+ export type ProbeSetting = {
38
+ name: string;
39
+ secret: boolean;
40
+ group?: 'auth';
41
+ billsAccount?: string;
42
+ };
43
+
44
+ /** The retry family whose rules the host applies (attempt.ts). */
45
+ export type ProbeRetryFamily = 'chat' | 'agent';
46
+
47
+ /** `metered`: every attempt is reserved against the run's budget;
48
+ * `subscription`: the operator's own plan pays, and nothing is reserved. */
49
+ export type ProbeBilling = 'metered' | 'subscription';
50
+
51
+ /** How the host reads the model an answer names: through servedModelOf
52
+ * against the requested model, as the CLI reported it, or not at all. */
53
+ export type ServedModelRule = 'compare_to_requested' | 'raw' | 'none';
54
+
55
+ /** What an adapter is, independent of a run: what it observes, what it
56
+ * needs, which pool and retry rules it runs under, and what it costs. */
57
+ export type ProbeAdapterProfile = {
58
+ id: ProbeAdapterId;
59
+ observes: { retrieval: RetrievalExposure; servedModel: ServedModelRule };
60
+ settings: readonly ProbeSetting[];
61
+ pool: Exclude<ProbeProvider, 'analyzer'>;
62
+ retry: ProbeRetryFamily;
63
+ estimateUsd: Range<number>;
64
+ billing: ProbeBilling;
65
+ /** Google's grounding redirects in the answer and its retrieval log are
66
+ * resolved to their targets before the answer is banked. */
67
+ resolvesRedirects: boolean;
68
+ };
69
+
70
+ /** The sources an answer cites, rendered after the body (answer-text.ts). */
71
+ export type AnswerSources =
72
+ | { format: 'search'; sources: readonly unknown[] }
73
+ | { format: 'ai_overview'; references: readonly AIOverviewReference[] }
74
+ | { format: 'none' };
75
+
76
+ export type ProbeAnswer = {
77
+ /** The body, without the source block. */
78
+ answerText: string;
79
+ sources: AnswerSources;
80
+ /** null: the log could not be captured. */
81
+ retrieval: RetrievalLog | null;
82
+ /** Google AI Overview's honest absence. */
83
+ noOverview?: true;
84
+ /** The model asked for, when the request names it only at answer time
85
+ * (Codex); null when the CLI's own default answered. */
86
+ requestedModel?: string | null;
87
+ /** The model the provider or CLI named, raw; observes.servedModel says
88
+ * how the host reads it. */
89
+ servedModel?: string;
90
+ reportedCostUsd?: number;
91
+ /** Coding agents only; null stays unknown. */
92
+ usedWebSearch?: boolean | null;
93
+ };
94
+
95
+ export type ProbeContext = { signal?: AbortSignal };
96
+
97
+ /** A request as the adapter dispatches it: the prompt it sends, with any
98
+ * prefix, and the parameters that shape the answer. Recorded when an
99
+ * attempt starts (spec §4.9). */
100
+ export type ProbeRequest = {
101
+ prompt: string;
102
+ parameters: Readonly<Record<string, unknown>>;
103
+ };
104
+
105
+ /** The models a chat adapter asks through, by model ID: the run's Vercel AI
106
+ * Gateway provider, created with the run's own key. */
107
+ export type ChatModelProvider = (modelId: string) => LanguageModel;
108
+
109
+ export type ProbeFailureClass = { kind: ProbeFailureKind; message: string };
110
+
111
+ /** One adapter instance, serving one surface. */
112
+ export type ProbeAdapter = ProbeAdapterProfile & {
113
+ surface: AeoSurface;
114
+ /** The model the binding pins, for an adapter that calls a model API. */
115
+ model?: string;
116
+ /** The request `probe` dispatches for `promptText`, built from the same
117
+ * values the dispatch uses. */
118
+ request: (promptText: string) => ProbeRequest;
119
+ probe: (promptText: string, ctx: ProbeContext) => Promise<ProbeAnswer>;
120
+ /** The message is journaled, so it never carries the prompt. */
121
+ classifyError: (error: unknown) => ProbeFailureClass;
122
+ };
@@ -0,0 +1,123 @@
1
+ import { z } from 'zod';
2
+ import { retrievalLogSchema } from '../../schema';
3
+ import type { AeoAgentSurface } from '../../surfaces';
4
+ import type {
5
+ ProbeAdapter,
6
+ ProbeAdapterProfile,
7
+ ProbeAnswer,
8
+ } from '../adapter';
9
+ import { claudeCodeProfile, runClaudeCodeProbe } from './cli-claude-code';
10
+ import {
11
+ codexProfile,
12
+ codexRequestParameters,
13
+ runCodexProbe,
14
+ } from './cli-codex';
15
+ import { cursorProfile, runCursorProbe } from './cli-cursor';
16
+ import {
17
+ agentProbeTimeoutMs,
18
+ classifyAgentError,
19
+ type AgentProbeFn,
20
+ type AgentRuntime,
21
+ } from './cli-process';
22
+
23
+ // ============================================================================
24
+ // The coding-agent CLI adapters (cli.claude_code, cli.codex, cli.cursor):
25
+ // one CLI run per attempt, on this machine or, in the hosted platform,
26
+ // through the isolated worker transport. The answer is the CLI's own final
27
+ // message; whether a web tool ran and what it retrieved come from the CLI's
28
+ // structured events, never from the answer text.
29
+ // ============================================================================
30
+
31
+ export const cliAdapterProfiles = {
32
+ claude_code: claudeCodeProfile,
33
+ codex: codexProfile,
34
+ cursor: cursorProfile,
35
+ } satisfies Record<AeoAgentSurface, ProbeAdapterProfile>;
36
+
37
+ // What a worker sends back for a probe or a version request.
38
+ const agentAnswerSchema = z.object({
39
+ text: z.string(),
40
+ usedWebSearch: z.boolean().nullable(),
41
+ retrieval: retrievalLogSchema,
42
+ requestedModel: z.string().nullable().optional(),
43
+ reportedModel: z.string().optional(),
44
+ });
45
+
46
+ // What a CLI probe's request records beyond its prompt: the CLI, and for
47
+ // Codex the model and sandbox it is started with.
48
+ const requestParameters: Readonly<
49
+ Record<AeoAgentSurface, (env: NodeJS.ProcessEnv) => Record<string, unknown>>
50
+ > = {
51
+ claude_code: () => ({ cli: 'claude' }),
52
+ codex: codexRequestParameters,
53
+ cursor: () => ({ cli: 'cursor-agent' }),
54
+ };
55
+
56
+ const localProbes: Readonly<Record<AeoAgentSurface, AgentProbeFn>> = {
57
+ claude_code: runClaudeCodeProbe,
58
+ codex: runCodexProbe,
59
+ cursor: runCursorProbe,
60
+ };
61
+
62
+ /** probeForSurface is one CLI run: through the runtime's worker transport
63
+ * when it has one, else on this machine. */
64
+ export const probeForSurface = (surface: AeoAgentSurface): AgentProbeFn => {
65
+ return async (prompt, runtime, signal) => {
66
+ if (!runtime.transport) {
67
+ return localProbes[surface](prompt, runtime, signal);
68
+ }
69
+
70
+ const answer = await runtime.transport.invoke(
71
+ surface,
72
+ {
73
+ task: 'probe',
74
+ prompt,
75
+ timeoutMs: Math.min(runtime.timeoutMs ?? agentProbeTimeoutMs, 300_000),
76
+ },
77
+ signal,
78
+ );
79
+
80
+ return agentAnswerSchema.parse(answer);
81
+ };
82
+ };
83
+
84
+ /**
85
+ * createCliAdapter is the adapter of `surface`'s CLI, running each attempt
86
+ * with `runtime`: its environment, its config directory, its deadline and,
87
+ * hosted, its worker transport.
88
+ */
89
+ export const createCliAdapter = (
90
+ surface: AeoAgentSurface,
91
+ { runtime }: { runtime: AgentRuntime },
92
+ ): ProbeAdapter => {
93
+ const run = probeForSurface(surface);
94
+
95
+ const adapter: ProbeAdapter = {
96
+ ...cliAdapterProfiles[surface],
97
+ surface,
98
+ request: (promptText) => ({
99
+ prompt: promptText,
100
+ parameters: requestParameters[surface](runtime.env),
101
+ }),
102
+ probe: async (promptText, { signal }) => {
103
+ const answer = await run(promptText, runtime, signal);
104
+ const probeAnswer: ProbeAnswer = {
105
+ answerText: answer.text,
106
+ sources: { format: 'none' },
107
+ retrieval: answer.retrieval,
108
+ usedWebSearch: answer.usedWebSearch,
109
+ ...(answer.requestedModel !== undefined && {
110
+ requestedModel: answer.requestedModel,
111
+ }),
112
+ ...(answer.reportedModel !== undefined && {
113
+ servedModel: answer.reportedModel,
114
+ }),
115
+ };
116
+
117
+ return probeAnswer;
118
+ },
119
+ classifyError: classifyAgentError,
120
+ };
121
+
122
+ return adapter;
123
+ };