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
@@ -12,8 +12,15 @@ import type { RunPlan } from '../runner';
12
12
  import type { AeoAuditConfig, RunRequest } from '../schema';
13
13
  import { contentHash } from '../stores/content-hash';
14
14
  import type { CapturedUnitRecord, ProbeStore, Stores } from '../stores/ports';
15
+ import { parseUnitRecord } from '../stores/unit-record';
15
16
  import { isAgentSurface, type AeoAgentSurface } from '../surfaces';
16
17
  import type { ProbeTrace } from '../probes/probe-trace';
18
+ import {
19
+ bankBindingMismatches,
20
+ RunBindingsError,
21
+ type ProbeDependencies,
22
+ type RunBindings,
23
+ } from '../probes/bindings';
17
24
 
18
25
  // ============================================================================
19
26
  // The paid half of a run: every planned probe unit captured or reused from
@@ -35,6 +42,9 @@ export type CaptureDeps = {
35
42
  /** The run journal, when the capture is recorded (a local run). */
36
43
  trace?: ProbeTrace;
37
44
  signal?: AbortSignal;
45
+ /** What the probe adapters are created with: the gateway, credentials,
46
+ * clients. */
47
+ probeDependencies: ProbeDependencies;
38
48
  logContext: Record<string, unknown>;
39
49
  now?: () => Date;
40
50
  /** The section capture service; tests inject one. */
@@ -92,11 +102,54 @@ const sectionArgs = (
92
102
  agentRuntime: deps.agentRuntime,
93
103
  trace: deps.trace,
94
104
  signal: deps.signal,
105
+ probeDependencies: deps.probeDependencies,
95
106
  internalModels: deps.internalModels,
96
107
  logContext: { ...deps.logContext, sectionKey: section.key },
97
108
  };
98
109
  };
99
110
 
111
+ /**
112
+ * assertBankUsable refuses a bank the run cannot build on, before anything
113
+ * is dispatched: a row no release wrote (phase 3 item 6), or a banked
114
+ * answer the plan reuses that another binding captured. captureForRun runs
115
+ * it before its first section, where the sections would otherwise settle
116
+ * independently and spend while one fails; a host runs it before its agent
117
+ * canaries too.
118
+ */
119
+ export const assertBankUsable = async (
120
+ probeStore: Pick<ProbeStore, 'list'>,
121
+ plan: RunPlan,
122
+ bindings: RunBindings,
123
+ ): Promise<void> => {
124
+ const banked = await probeStore.list();
125
+
126
+ for (const record of banked) {
127
+ parseUnitRecord(record, unitRecordKey(record));
128
+ }
129
+
130
+ // A banked answer is reused only under the binding that captured it; a
131
+ // mismatch stops the run, never re-probed silently.
132
+ const plannedKeys = new Set(plan.units.map(unitRecordKey));
133
+ const mismatched = bankBindingMismatches(
134
+ banked.filter(
135
+ (record): record is CapturedUnitRecord =>
136
+ record.status === 'captured' && plannedKeys.has(unitRecordKey(record)),
137
+ ),
138
+ bindings,
139
+ );
140
+
141
+ if (mismatched.length > 0) {
142
+ const surfaces = [...new Set(mismatched.map((record) => record.surface))];
143
+ const bound = surfaces
144
+ .map((surface) => `${surface} (${bindings[surface].adapter})`)
145
+ .join(', ');
146
+
147
+ throw new RunBindingsError(
148
+ `${mismatched.length} banked answers were captured with another adapter than this run's binding of ${bound}. A banked answer is never probed again under another binding: start a fresh run (a new run directory, or mode fresh) to measure them this way.`,
149
+ );
150
+ }
151
+ };
152
+
100
153
  /** Orders by UTF-16 code units, independent of the host's locale. */
101
154
  const compareCodeUnits = (left: string, right: string) => {
102
155
  if (left === right) {
@@ -112,6 +165,13 @@ export const captureForRun = async (
112
165
  const { config, plan } = deps;
113
166
  const now = deps.now ?? (() => new Date());
114
167
  const captureSection = deps.captureSection ?? captureSectionProbes;
168
+
169
+ await assertBankUsable(
170
+ deps.stores.probeStore,
171
+ plan,
172
+ deps.probeDependencies.bindings,
173
+ );
174
+
115
175
  const startedAt = now().toISOString();
116
176
  const settled = await Promise.allSettled(
117
177
  plan.sections.map((section) => captureSection(sectionArgs(deps, section))),
@@ -2,6 +2,7 @@ import { mkdir, writeFile } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
  import { criteriaForRole, producerGuidance } from '../harness/criteria';
4
4
  import type { AeoAuditConfig } from '../schema';
5
+ import { searchSourcesMarker } from '../probes/answer-text';
5
6
  import type { CapturedUnitRecord } from '../stores/ports';
6
7
  import { isStageName, stageJsonSchema, stageSchemas } from './schemas';
7
8
 
@@ -14,8 +15,6 @@ import { isStageName, stageJsonSchema, stageSchemas } from './schemas';
14
15
  // publisher for a mention.
15
16
  // ============================================================================
16
17
 
17
- export const sourcesMarker = 'Sources used by search:';
18
-
19
18
  export type AnswerFile = {
20
19
  /** Path relative to the work directory. */
21
20
  file: string;
@@ -79,7 +78,7 @@ export const answerFilePath = (record: {
79
78
 
80
79
  /** The body of a captured answer: everything before the sources block. */
81
80
  export const answerBody = (text: string): string => {
82
- const at = text.lastIndexOf(sourcesMarker);
81
+ const at = text.lastIndexOf(searchSourcesMarker);
83
82
 
84
83
  return (at < 0 ? text : text.slice(0, at)).trim();
85
84
  };
@@ -121,7 +120,7 @@ export const materializeWorkdir = async (args: {
121
120
  for (const record of args.captured) {
122
121
  const file = answerFilePath(record);
123
122
  const text = record.probe.text;
124
- const at = text.lastIndexOf(sourcesMarker);
123
+ const at = text.lastIndexOf(searchSourcesMarker);
125
124
  const body = answerBody(text);
126
125
  const sources = at < 0 ? '' : text.slice(at);
127
126
  const content = [
@@ -4,7 +4,6 @@ import {
4
4
  authorTokens,
5
5
  costCoefficientsVersion,
6
6
  hostTokensPerAnswer,
7
- probeUsd,
8
7
  searchUsdPerAnswer,
9
8
  stageTokens,
10
9
  type Range,
@@ -12,6 +11,7 @@ import {
12
11
  } from '../models/cost-coefficients';
13
12
  import { tokenCostUsd } from '../models/pricing';
14
13
  import type { SupportedModel } from '../models/supported-models';
14
+ import { profileOf, type RunBindings } from '../probes/bindings';
15
15
  import type { RunPlan } from '../runner';
16
16
 
17
17
  // ============================================================================
@@ -87,6 +87,9 @@ type EstimateRunOptions = {
87
87
  plan: Pick<RunPlan, 'units' | 'probesBySurface'>;
88
88
  model: SupportedModel;
89
89
  grounding: 'full' | 'extraction_only';
90
+ /** The bindings the run measures with: each surface's probes cost what
91
+ * its bound adapter costs. */
92
+ bindings: RunBindings;
90
93
  };
91
94
 
92
95
  /** estimateRunCost estimates a whole run as planned; a resume spends less,
@@ -95,14 +98,17 @@ export const estimateRunCost = ({
95
98
  plan,
96
99
  model,
97
100
  grounding,
101
+ bindings,
98
102
  }: EstimateRunOptions): RunCostEstimate => {
99
103
  const answers = plan.units.length;
100
104
  const { cachedShare } = stageTokens;
101
105
 
102
106
  const probes = sumOf(
103
- [...plan.probesBySurface].map(([surface, count]) =>
104
- rangeOf(probeUsd[surface].low * count, probeUsd[surface].high * count),
105
- ),
107
+ [...plan.probesBySurface].map(([surface, count]) => {
108
+ const usd = profileOf(bindings[surface]).estimateUsd;
109
+
110
+ return rangeOf(usd.low * count, usd.high * count);
111
+ }),
106
112
  );
107
113
  // The cheap end assumes the cache serves most input; the dear end less.
108
114
  const stages = rangeOf(
@@ -11,6 +11,7 @@ import {
11
11
  import { acquireWriterLock, type WriterLock } from '../bundle/writer-lock';
12
12
  import { capturePlan } from '../capture-manifest';
13
13
  import {
14
+ assertBankUsable,
14
15
  captureForRun,
15
16
  agentSurfacesToCapture,
16
17
  } from '../codex-workflow/capture';
@@ -34,6 +35,7 @@ import {
34
35
  } from '../models/accounting';
35
36
  import { resolveSupportedModel } from '../models/supported-models';
36
37
  import { chargedProbeTrace } from '../probes/charged-trace';
38
+ import { probeDependenciesOf } from '../probes/bindings';
37
39
  import type { InternalModelContext } from '../models/context';
38
40
  import { ProbeLimiter } from '../probes/limits';
39
41
  import { planRun, type RunPlan } from '../runner';
@@ -43,7 +45,9 @@ import { openFileStores } from '../stores/files';
43
45
  import type { CapturedUnitRecord } from '../stores/ports';
44
46
  import { getEnvironment } from '../lib/env';
45
47
  import { toAuditConfig, toRunRequest, type AuditFile } from './audit-file';
48
+ import { resolveRunBindings } from './run-bindings';
46
49
  import {
50
+ readFrozenBudget,
47
51
  resolveRunBudget,
48
52
  type BudgetAmendment,
49
53
  type RunBudget,
@@ -228,6 +232,14 @@ const openLockedLocalRun = async (
228
232
  },
229
233
  ): Promise<LocalRun> => {
230
234
  const { recorder } = held;
235
+ const bank = path.join(dir, bankDir);
236
+ // Frozen before the budget and the first canary, then kept on every
237
+ // resume: a directory that holds a budget but no bindings started before
238
+ // bindings were frozen. Frozen after the budget, an attempt stopped
239
+ // between the two (a refused plan, a crash) would read as one.
240
+ const bindings = await resolveRunBindings(bank, {
241
+ startedBefore: (await readFrozenBudget(dir)) !== undefined,
242
+ });
231
243
  const budget = await resolveRunBudget(dir, file.runPolicy.budget, {
232
244
  model: resolveSupportedModel(file.model).id,
233
245
  ...(maxUsd !== undefined && { maxUsd }),
@@ -239,7 +251,6 @@ const openLockedLocalRun = async (
239
251
  ...(derivedFromRunId !== undefined && { derivedFromRunId }),
240
252
  };
241
253
  const plan = planRun(config, request);
242
- const bank = path.join(dir, bankDir);
243
254
  const stores = await openFileStores(config.reportKey, {
244
255
  checkpointDir: bank,
245
256
  contentDir: path.join(bank, 'report'),
@@ -280,6 +291,9 @@ const openLockedLocalRun = async (
280
291
  recorder,
281
292
  ),
282
293
  };
294
+ // Before the canaries, which dispatch: a bank the run cannot build on
295
+ // stops it with nothing sent.
296
+ await assertBankUsable(stores.probeStore, plan, bindings);
283
297
  const agents = await agentSurfacesToCapture(plan, stores.probeStore);
284
298
  const agentCliVersions = await detectAgentClis();
285
299
 
@@ -297,8 +311,13 @@ const openLockedLocalRun = async (
297
311
  );
298
312
  }
299
313
 
300
- const probes = chargedProbeTrace(probeTraceOf(recorder, 'probe'), ledger);
314
+ const probes = chargedProbeTrace(
315
+ probeTraceOf(recorder, 'probe'),
316
+ ledger,
317
+ bindings,
318
+ );
301
319
  const capture = await captureForRun({
320
+ probeDependencies: probeDependenciesOf(getEnvironment(), bindings),
302
321
  config,
303
322
  request,
304
323
  plan,
@@ -7,6 +7,12 @@ import {
7
7
  detectAgentClis,
8
8
  versionForSurface,
9
9
  } from '../probes/agent-clis';
10
+ import {
11
+ probeAdapterProfiles,
12
+ profileOf,
13
+ type ProbeBinding,
14
+ type RunBindings,
15
+ } from '../probes/bindings';
10
16
  import {
11
17
  agentSurfaces,
12
18
  isAgentSurface,
@@ -43,22 +49,32 @@ export type PreflightCheck = {
43
49
  const gatewaySetting = 'AI_GATEWAY_API_KEY';
44
50
  const overviewSettings = ['DATAFORSEO_LOGIN', 'DATAFORSEO_PASSWORD'] as const;
45
51
 
46
- // The run's own credentials, by variable name: their values never enter a
47
- // bundle. Values only; the names are not secret.
48
- export const credentialSettingNames = [
52
+ // The engine's own secrets, outside the probe adapters' settings.
53
+ export const engineSecretSettingNames = [
49
54
  'AI_GATEWAY_API_KEY',
50
55
  'DATAFORSEO_PASSWORD',
51
56
  'AEO_DATABASE_URL',
52
57
  'AEO_SITE_DATABASE_URL',
53
58
  'AEO_API_TOKEN',
54
- 'OPENAI_API_KEY',
55
- 'ANTHROPIC_API_KEY',
56
- 'CLAUDE_CODE_OAUTH_TOKEN',
57
59
  'GOOGLE_GENERATIVE_AI_API_KEY',
58
60
  'PERPLEXITY_API_KEY',
59
- 'CURSOR_API_KEY',
60
61
  ] as const;
61
62
 
63
+ // The run's own credentials, by variable name: their values never enter a
64
+ // bundle. Values only; the names are not secret. A probe adapter's
65
+ // non-secret settings (a login name, a directory) stay out, or an export
66
+ // would refuse a bundle that merely mentions them.
67
+ export const credentialSettingNames: readonly string[] = [
68
+ ...new Set([
69
+ ...engineSecretSettingNames,
70
+ ...Object.values(probeAdapterProfiles).flatMap((profile) =>
71
+ profile.settings
72
+ .filter((setting) => setting.secret)
73
+ .map((setting) => setting.name),
74
+ ),
75
+ ]),
76
+ ];
77
+
62
78
  /** Every setting a run may read, for applying the env file. */
63
79
  export const runSettingNames = [
64
80
  gatewaySetting,
@@ -66,6 +82,26 @@ export const runSettingNames = [
66
82
  ...Object.values(agentAuthEnv).flatMap((auth) => auth.anyOf),
67
83
  ];
68
84
 
85
+ // A coding agent's probes bill its own plan, outside the run's cap; an
86
+ // auth setting that bills a provider account per use (an API key) says so,
87
+ // since the cap does not see that spend either.
88
+ const agentAuthDetail = (
89
+ binding: ProbeBinding,
90
+ auth: ReturnType<typeof agentAuthMode>,
91
+ ): string => {
92
+ if (auth.kind === 'cli_session') {
93
+ return 'uses the CLI login on this machine, checked by a canary before the run';
94
+ }
95
+
96
+ const account = profileOf(binding).settings.find(
97
+ (setting) => setting.name === auth.name,
98
+ )?.billsAccount;
99
+
100
+ return account === undefined
101
+ ? `authenticates with ${auth.name}`
102
+ : `authenticates with ${auth.name}, billed to that ${account} account outside the run's cap`;
103
+ };
104
+
69
105
  /** How an agent surface authenticates on this machine: a variable, or the
70
106
  * CLI's own login, which only the run's canary can prove. */
71
107
  export const agentAuthMode = (
@@ -81,6 +117,46 @@ export const agentAuthMode = (
81
117
  : { kind: 'variable', name };
82
118
  };
83
119
 
120
+ const sourceLabel = (name: string, settings: Settings): string => {
121
+ const source = settings.sourceOf(name);
122
+
123
+ if (source === undefined) {
124
+ return `${name} not set`;
125
+ }
126
+
127
+ return `${name} from the ${source === 'environment' ? 'process environment' : 'env file'}`;
128
+ };
129
+
130
+ /** bindingLabel names an adapter and the model it is bound to. */
131
+ const bindingLabel = (binding: ProbeBinding): string => {
132
+ return binding.model === undefined
133
+ ? binding.adapter
134
+ : `${binding.adapter} with ${binding.model}`;
135
+ };
136
+
137
+ /** A chat surface's bound adapter, with the settings it needs by name and
138
+ * where each is set, never its value. */
139
+ const chatBindingCheck = (
140
+ surface: AeoSurface,
141
+ binding: ProbeBinding,
142
+ settings: Settings,
143
+ ): PreflightCheck => {
144
+ const required = profileOf(binding).settings.filter(
145
+ (setting) => setting.group === undefined,
146
+ );
147
+
148
+ return {
149
+ name: `${surface} probes`,
150
+ ok: required.every(
151
+ (setting) => settings.sourceOf(setting.name) !== undefined,
152
+ ),
153
+ detail: [
154
+ bindingLabel(binding),
155
+ ...required.map((setting) => sourceLabel(setting.name, settings)),
156
+ ].join('; '),
157
+ };
158
+ };
159
+
84
160
  const settingCheck = (name: string, settings: Settings): PreflightCheck => {
85
161
  const source = settings.sourceOf(name);
86
162
 
@@ -220,8 +296,11 @@ export const runPreflight = async (args: {
220
296
  groundingSearch?: boolean;
221
297
  /** Money pages are rendered in Chromium by the renderability check. */
222
298
  rendersPages?: boolean;
299
+ /** The bindings the run measures with: each surface's adapter, whose
300
+ * settings preflight requires. */
301
+ bindings: RunBindings;
223
302
  }): Promise<PreflightCheck[]> => {
224
- const { surfaces, settings } = args;
303
+ const { surfaces, settings, bindings } = args;
225
304
  const nodeMajor = Number(process.versions.node.split('.')[0]);
226
305
  const versions = await detectAgentClis();
227
306
  const agents = surfaces.filter(isAgentSurface);
@@ -235,28 +314,45 @@ export const runPreflight = async (args: {
235
314
  modelCheck(args.model),
236
315
  // Every stage session runs on Codex, whatever is measured.
237
316
  await codexCheck(),
238
- settingCheck(gatewaySetting, settings),
239
317
  ];
240
318
 
241
- // A pinned search provider without its credential never degrades to
319
+ // Each setting the run needs once: the gateway key always, for the
320
+ // host's own model calls whatever is measured; every ungrouped setting of
321
+ // a bound adapter in scope; and the search provider's pair when full
322
+ // grounding searches through it, so a pinned provider never degrades to
242
323
  // `unavailable` searches mid-run (spec §3.3).
243
- if (surfaces.includes('google_ai_overview') || args.groundingSearch) {
244
- checks.push(
245
- ...overviewSettings.map((name) => settingCheck(name, settings)),
246
- );
247
- }
324
+ const chatSurfaces = surfaces.filter((surface) => !isAgentSurface(surface));
325
+ const required = new Set<string>([
326
+ gatewaySetting,
327
+ ...chatSurfaces.flatMap((surface) =>
328
+ profileOf(bindings[surface])
329
+ .settings.filter((setting) => setting.group === undefined)
330
+ .map((setting) => setting.name),
331
+ ),
332
+ ...(args.groundingSearch ? overviewSettings : []),
333
+ ]);
334
+
335
+ checks.push(
336
+ ...[...required].map((name) => settingCheck(name, settings)),
337
+ ...chatSurfaces.map((surface) =>
338
+ chatBindingCheck(surface, bindings[surface], settings),
339
+ ),
340
+ );
248
341
 
342
+ // A coding agent authenticates with any one of its adapter's auth
343
+ // settings, or with the CLI's own login, which only the canary can prove.
249
344
  for (const surface of agents) {
250
345
  const version = versionForSurface(surface, versions);
251
346
  const auth = agentAuthMode(surface, settings);
347
+ const binding = bindingLabel(bindings[surface]);
252
348
 
253
349
  checks.push({
254
350
  name: `${surface} probes`,
255
351
  ok: version !== null,
256
352
  detail:
257
353
  version === null
258
- ? `\`${cliNameForSurface(surface)}\` not found on PATH`
259
- : `${cliNameForSurface(surface)} ${version}; ${auth.kind === 'variable' ? `authenticates with ${auth.name}` : 'uses the CLI login on this machine, checked by a canary before the run'}`,
354
+ ? `${binding}; \`${cliNameForSurface(surface)}\` not found on PATH`
355
+ : `${binding}; ${cliNameForSurface(surface)} ${version}; ${agentAuthDetail(bindings[surface], auth)}`,
260
356
  });
261
357
  }
262
358
 
@@ -11,6 +11,7 @@ import { readRunInputs } from '../codex-workflow/run-inputs';
11
11
  import { hasErrorCode } from '../stores/fs-errors';
12
12
  import { localReportKey, type AuditFile } from './audit-file';
13
13
  import { bankDir, planLocalRun, runDirectoryState } from './local-run';
14
+ import { carryFrozenBindings } from './run-bindings';
14
15
 
15
16
  const technicalFile = 'TECHNICAL.json';
16
17
 
@@ -87,6 +88,10 @@ export const prepareRejudgment = async ({
87
88
  path.join(source, bankDir, `${reportKey}.jsonl`),
88
89
  path.join(target, bankDir, `${reportKey}.jsonl`),
89
90
  );
91
+ await carryFrozenBindings(
92
+ path.join(source, bankDir),
93
+ path.join(target, bankDir),
94
+ );
90
95
  // The technical checks are part of the measurement, like the captures:
91
96
  // a rejudgment judges the site as it was, never as it is today.
92
97
  await copyFile(
@@ -0,0 +1,142 @@
1
+ import { copyFile, readFile } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { z } from 'zod';
4
+ import { writeFileAtomically } from '../codex-workflow/pending';
5
+ import {
6
+ availableBindings,
7
+ defaultProbeBindings,
8
+ RunBindingsError,
9
+ type RunBindings,
10
+ } from '../probes/bindings';
11
+ import { legacyProbeBindings } from '../probes/legacy-bindings';
12
+ import { hasErrorCode } from '../stores/fs-errors';
13
+
14
+ // ============================================================================
15
+ // A run's frozen bindings (specs/aeo-probe-adapters-spec.md §4.5): written
16
+ // to BANK/bindings.json before the first canary and read back on every
17
+ // resume, like the budget's cap and model. A directory from before this
18
+ // file existed is frozen with the legacy bindings, the ones its banked
19
+ // answers were captured with.
20
+ // ============================================================================
21
+
22
+ export const bindingsFile = 'bindings.json';
23
+
24
+ const frozenBindingsSchema = z
25
+ .object({
26
+ version: z.literal(1),
27
+ bindings: z.record(
28
+ z.string(),
29
+ z
30
+ .object({
31
+ adapter: z.string().min(1),
32
+ model: z.string().min(1).optional(),
33
+ })
34
+ .strict(),
35
+ ),
36
+ })
37
+ .strict();
38
+
39
+ /**
40
+ * estimateBindingsOf is the bindings a run directory's estimate prices: its
41
+ * frozen bindings once it has usable ones, else the defaults a new run
42
+ * would freeze. Read-only. A frozen binding the engine cannot build is the
43
+ * run's start to refuse (exit 2), not the estimate's.
44
+ */
45
+ export const estimateBindingsOf = async (
46
+ bankPath: string,
47
+ ): Promise<RunBindings> => {
48
+ const text = await readFile(path.join(bankPath, bindingsFile), 'utf8').catch(
49
+ (err: unknown) => {
50
+ if (hasErrorCode(err, 'ENOENT')) {
51
+ return undefined;
52
+ }
53
+
54
+ throw err;
55
+ },
56
+ );
57
+
58
+ if (text === undefined) {
59
+ return defaultProbeBindings;
60
+ }
61
+
62
+ try {
63
+ return availableBindings(
64
+ frozenBindingsSchema.parse(JSON.parse(text)).bindings,
65
+ );
66
+ } catch {
67
+ // Refused with its reason when the run starts.
68
+ return defaultProbeBindings;
69
+ }
70
+ };
71
+
72
+ /**
73
+ * resolveRunBindings returns the bindings a run measures with: the frozen
74
+ * ones on a resume, refused when the installed engine cannot build them;
75
+ * otherwise the defaults for a new run, or the legacy bindings for a run
76
+ * that started before bindings were frozen, written before they are used.
77
+ */
78
+ export const resolveRunBindings = async (
79
+ bankPath: string,
80
+ { startedBefore }: { startedBefore: boolean },
81
+ ): Promise<RunBindings> => {
82
+ const file = path.join(bankPath, bindingsFile);
83
+ const text = await readFile(file, 'utf8').catch((err: unknown) => {
84
+ if (hasErrorCode(err, 'ENOENT')) {
85
+ return undefined;
86
+ }
87
+
88
+ throw err;
89
+ });
90
+
91
+ if (text !== undefined) {
92
+ let frozen: z.infer<typeof frozenBindingsSchema>;
93
+
94
+ try {
95
+ frozen = frozenBindingsSchema.parse(JSON.parse(text));
96
+ } catch (error) {
97
+ throw new RunBindingsError(
98
+ `${file} is not a frozen bindings file (${error instanceof Error ? error.message.slice(0, 200) : String(error)}). Please restore it; a run never re-chooses how it measures.`,
99
+ );
100
+ }
101
+
102
+ return availableBindings(frozen.bindings);
103
+ }
104
+
105
+ const bindings = startedBefore ? legacyProbeBindings : defaultProbeBindings;
106
+
107
+ await freezeBindings(bankPath, bindings);
108
+
109
+ return bindings;
110
+ };
111
+
112
+ /**
113
+ * carryFrozenBindings gives a derived run directory (a rejudgment) the
114
+ * bindings its reused answers were captured under: the source's frozen
115
+ * file, or, from before bindings were frozen, the legacy bindings. Never
116
+ * the installed defaults.
117
+ */
118
+ export const carryFrozenBindings = async (
119
+ sourceBank: string,
120
+ targetBank: string,
121
+ ): Promise<void> => {
122
+ await copyFile(
123
+ path.join(sourceBank, bindingsFile),
124
+ path.join(targetBank, bindingsFile),
125
+ ).catch(async (err: unknown) => {
126
+ if (!hasErrorCode(err, 'ENOENT')) {
127
+ throw err;
128
+ }
129
+
130
+ await freezeBindings(targetBank, legacyProbeBindings);
131
+ });
132
+ };
133
+
134
+ const freezeBindings = async (
135
+ bankPath: string,
136
+ bindings: RunBindings,
137
+ ): Promise<void> => {
138
+ await writeFileAtomically(
139
+ path.join(bankPath, bindingsFile),
140
+ `${JSON.stringify({ version: 1, bindings }, null, 2)}\n`,
141
+ );
142
+ };
@@ -556,6 +556,7 @@ export const extractClaimCandidates = async (args: {
556
556
  observe: (id, evidence) =>
557
557
  args.accounting.observe?.(id, evidence) ?? Promise.resolve(),
558
558
  settle: (id, usage) => args.accounting.settle(id, usage),
559
+ release: (id) => args.accounting.release(id),
559
560
  reserve: async (call) => {
560
561
  const hadInFlight = inFlight.size > 0;
561
562
 
@@ -41,6 +41,10 @@ export const trackResearchUsage = async <T>(
41
41
  call.usage = usage;
42
42
  }
43
43
  },
44
+ release: async (id) => {
45
+ await accounting.release(id);
46
+ calls.delete(id);
47
+ },
44
48
  });
45
49
  } finally {
46
50
  onUsage?.(chargedTotal(calls.values()));