literally-aeo 0.0.0-stage → 0.1.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 (770) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -2
  3. package/dist/author-tools.js +3031 -0
  4. package/dist/cli.mjs +25536 -0
  5. package/dist/lib/access/schema.js +24 -0
  6. package/dist/lib/agents/author-schema.js +28 -0
  7. package/dist/lib/agents/author-validation.js +46 -0
  8. package/dist/lib/agents/copy-schema.js +30 -0
  9. package/dist/lib/agents/copy-validation.js +62 -0
  10. package/dist/lib/agents/copywriter-input.js +31 -0
  11. package/dist/lib/agents/credentials.js +6 -0
  12. package/dist/lib/agents/facts.js +31 -0
  13. package/dist/lib/agents/narrative-facts.js +12 -0
  14. package/dist/lib/agents/verifier.js +62 -0
  15. package/dist/lib/analysis/answer-text.js +19 -0
  16. package/dist/lib/analysis/competitor-classifier.js +6 -0
  17. package/dist/lib/analysis/domain-classifier.js +73 -0
  18. package/dist/lib/analysis/domain-labels.js +32 -0
  19. package/dist/lib/analysis/domain-match.js +12 -0
  20. package/dist/lib/analysis/name-forms.js +12 -0
  21. package/dist/lib/analysis/outreach.js +17 -0
  22. package/dist/lib/analysis/progress-schema.js +13 -0
  23. package/dist/lib/analysis/progress.js +39 -0
  24. package/dist/lib/analysis/qualified-competitors.js +7 -0
  25. package/dist/lib/analysis/retrieval.js +16 -0
  26. package/dist/lib/analysis/scoring.js +12 -0
  27. package/dist/lib/analysis/search-analyzer.js +17 -0
  28. package/dist/lib/analysis/sentiment.js +61 -0
  29. package/dist/lib/analysis/source-classifier.js +22 -0
  30. package/dist/lib/analysis/source-mix.js +16 -0
  31. package/dist/lib/analysis/verbatim.js +6 -0
  32. package/dist/lib/api/errors.js +10 -0
  33. package/dist/lib/author/examples.js +34 -0
  34. package/dist/lib/bundle/checks.js +16 -0
  35. package/dist/lib/bundle/contracts.js +66 -0
  36. package/dist/lib/bundle/export.js +69 -0
  37. package/dist/lib/bundle/journal.js +41 -0
  38. package/dist/lib/bundle/json.js +13 -0
  39. package/dist/lib/bundle/lineage.js +13 -0
  40. package/dist/lib/bundle/paths.js +6 -0
  41. package/dist/lib/bundle/project-journal.js +36 -0
  42. package/dist/lib/bundle/project.js +55 -0
  43. package/dist/lib/bundle/read.js +60 -0
  44. package/dist/lib/bundle/recorder.js +46 -0
  45. package/dist/lib/bundle/redact.js +35 -0
  46. package/dist/lib/bundle/trace-coverage.js +33 -0
  47. package/dist/lib/bundle/verify-integrity.js +41 -0
  48. package/dist/lib/bundle/verify-measurement.js +49 -0
  49. package/dist/lib/bundle/verify-report.js +62 -0
  50. package/dist/lib/bundle/verify.js +71 -0
  51. package/dist/lib/bundle/writer-lock.js +11 -0
  52. package/dist/lib/bundle/zip.js +13 -0
  53. package/dist/lib/capture-manifest.js +42 -0
  54. package/dist/lib/checks/crawler-access.js +16 -0
  55. package/dist/lib/checks/renderability.js +8 -0
  56. package/dist/lib/checks/run-checks.js +38 -0
  57. package/dist/lib/chunks/chunk-2KJZ326K.js +253 -0
  58. package/dist/lib/chunks/chunk-2MGARWKY.js +138 -0
  59. package/dist/lib/chunks/chunk-2NJEWPCV.js +94 -0
  60. package/dist/lib/chunks/chunk-2PAO43CH.js +43 -0
  61. package/dist/lib/chunks/chunk-2QLAFBCG.js +8 -0
  62. package/dist/lib/chunks/chunk-2ROSV4HD.js +64 -0
  63. package/dist/lib/chunks/chunk-2URYGUMH.js +27 -0
  64. package/dist/lib/chunks/chunk-3BFCI7LI.js +34 -0
  65. package/dist/lib/chunks/chunk-3BJWRD4O.js +0 -0
  66. package/dist/lib/chunks/chunk-3EBWDHPK.js +133 -0
  67. package/dist/lib/chunks/chunk-3UFZ2XPE.js +73 -0
  68. package/dist/lib/chunks/chunk-4E4NDGOZ.js +47 -0
  69. package/dist/lib/chunks/chunk-4QQJXCD2.js +113 -0
  70. package/dist/lib/chunks/chunk-4US3OBKJ.js +136 -0
  71. package/dist/lib/chunks/chunk-4ZY6P5SO.js +303 -0
  72. package/dist/lib/chunks/chunk-55U7PRRM.js +26 -0
  73. package/dist/lib/chunks/chunk-565CYND6.js +93 -0
  74. package/dist/lib/chunks/chunk-56VOFZ7T.js +1486 -0
  75. package/dist/lib/chunks/chunk-5B3RNVZ6.js +193 -0
  76. package/dist/lib/chunks/chunk-5EX5DKMA.js +812 -0
  77. package/dist/lib/chunks/chunk-5GZVDGTX.js +316 -0
  78. package/dist/lib/chunks/chunk-5H3SNUQT.js +101 -0
  79. package/dist/lib/chunks/chunk-5HT55QYX.js +53 -0
  80. package/dist/lib/chunks/chunk-5KKLUM7M.js +105 -0
  81. package/dist/lib/chunks/chunk-5SOTF3XD.js +56 -0
  82. package/dist/lib/chunks/chunk-5T3V6XJS.js +41 -0
  83. package/dist/lib/chunks/chunk-5VNYUCLL.js +352 -0
  84. package/dist/lib/chunks/chunk-5ZITQDVE.js +149 -0
  85. package/dist/lib/chunks/chunk-6AUEDSTU.js +52 -0
  86. package/dist/lib/chunks/chunk-6EH4N3EU.js +113 -0
  87. package/dist/lib/chunks/chunk-6EI4CVRW.js +33 -0
  88. package/dist/lib/chunks/chunk-6GKKALCI.js +538 -0
  89. package/dist/lib/chunks/chunk-6GSQKCKF.js +48 -0
  90. package/dist/lib/chunks/chunk-6KHQ7DXP.js +100 -0
  91. package/dist/lib/chunks/chunk-6KO7HGCQ.js +229 -0
  92. package/dist/lib/chunks/chunk-6RAKXYSR.js +226 -0
  93. package/dist/lib/chunks/chunk-72P6NOKD.js +190 -0
  94. package/dist/lib/chunks/chunk-74UNVGWB.js +0 -0
  95. package/dist/lib/chunks/chunk-7GXRDAUY.js +554 -0
  96. package/dist/lib/chunks/chunk-7MR6IJ7I.js +0 -0
  97. package/dist/lib/chunks/chunk-7O3M6I2X.js +123 -0
  98. package/dist/lib/chunks/chunk-7PLK6VGC.js +12 -0
  99. package/dist/lib/chunks/chunk-7QYZSP7Q.js +190 -0
  100. package/dist/lib/chunks/chunk-7YYDUHJG.js +113 -0
  101. package/dist/lib/chunks/chunk-7ZOJE6BH.js +73 -0
  102. package/dist/lib/chunks/chunk-AKKFERA4.js +99 -0
  103. package/dist/lib/chunks/chunk-AP5DLF36.js +150 -0
  104. package/dist/lib/chunks/chunk-AUB5THIS.js +341 -0
  105. package/dist/lib/chunks/chunk-AWOJWMPN.js +213 -0
  106. package/dist/lib/chunks/chunk-B5L2KMTU.js +108 -0
  107. package/dist/lib/chunks/chunk-BEQLSAVX.js +202 -0
  108. package/dist/lib/chunks/chunk-C6CMSW5J.js +13 -0
  109. package/dist/lib/chunks/chunk-CFFPOTP4.js +356 -0
  110. package/dist/lib/chunks/chunk-CJ5YD3CU.js +237 -0
  111. package/dist/lib/chunks/chunk-CPT2GKKW.js +188 -0
  112. package/dist/lib/chunks/chunk-CQ62GN7P.js +30 -0
  113. package/dist/lib/chunks/chunk-CRVCWDH6.js +0 -0
  114. package/dist/lib/chunks/chunk-CS24IL3K.js +115 -0
  115. package/dist/lib/chunks/chunk-D2INDP5W.js +240 -0
  116. package/dist/lib/chunks/chunk-D2LPQO6Y.js +39 -0
  117. package/dist/lib/chunks/chunk-D5B4ZOW6.js +61 -0
  118. package/dist/lib/chunks/chunk-D7GEQVLL.js +115 -0
  119. package/dist/lib/chunks/chunk-DC6PN7QJ.js +193 -0
  120. package/dist/lib/chunks/chunk-DYJVVQHD.js +60 -0
  121. package/dist/lib/chunks/chunk-E3CDKC5B.js +45 -0
  122. package/dist/lib/chunks/chunk-E4HADK7C.js +18 -0
  123. package/dist/lib/chunks/chunk-E6NQQU6V.js +111 -0
  124. package/dist/lib/chunks/chunk-EBXOHAMQ.js +131 -0
  125. package/dist/lib/chunks/chunk-EPQHVILQ.js +348 -0
  126. package/dist/lib/chunks/chunk-EV4DRS5M.js +61 -0
  127. package/dist/lib/chunks/chunk-EYKINDNK.js +29 -0
  128. package/dist/lib/chunks/chunk-EZD2C7QS.js +10 -0
  129. package/dist/lib/chunks/chunk-FBFZBLTY.js +752 -0
  130. package/dist/lib/chunks/chunk-FFOVLI3U.js +235 -0
  131. package/dist/lib/chunks/chunk-FKLNEB2P.js +529 -0
  132. package/dist/lib/chunks/chunk-FT5NSQYX.js +0 -0
  133. package/dist/lib/chunks/chunk-FWBVTM7F.js +11 -0
  134. package/dist/lib/chunks/chunk-GLXY73MK.js +165 -0
  135. package/dist/lib/chunks/chunk-GMGKKE5N.js +11 -0
  136. package/dist/lib/chunks/chunk-GVC4LH2N.js +130 -0
  137. package/dist/lib/chunks/chunk-GVOF5ZUG.js +44 -0
  138. package/dist/lib/chunks/chunk-H2KDLDK6.js +13 -0
  139. package/dist/lib/chunks/chunk-H3G3VTT7.js +259 -0
  140. package/dist/lib/chunks/chunk-H56DDRKE.js +85 -0
  141. package/dist/lib/chunks/chunk-HOJXKHPX.js +34 -0
  142. package/dist/lib/chunks/chunk-HSZ3DM74.js +55 -0
  143. package/dist/lib/chunks/chunk-HXHFMFQU.js +29 -0
  144. package/dist/lib/chunks/chunk-I7VNIW6Q.js +196 -0
  145. package/dist/lib/chunks/chunk-IAR6XGEW.js +184 -0
  146. package/dist/lib/chunks/chunk-IB6RROHE.js +204 -0
  147. package/dist/lib/chunks/chunk-IBOWGKN7.js +98 -0
  148. package/dist/lib/chunks/chunk-IEVAFDW7.js +513 -0
  149. package/dist/lib/chunks/chunk-IPNK7FYT.js +70 -0
  150. package/dist/lib/chunks/chunk-IRPKBDB7.js +13 -0
  151. package/dist/lib/chunks/chunk-ISN6MBNB.js +70 -0
  152. package/dist/lib/chunks/chunk-J46W3EMQ.js +237 -0
  153. package/dist/lib/chunks/chunk-J6IJGYP5.js +147 -0
  154. package/dist/lib/chunks/chunk-JQ3P552S.js +0 -0
  155. package/dist/lib/chunks/chunk-JS3GBU3R.js +46 -0
  156. package/dist/lib/chunks/chunk-KMRQSIZW.js +90 -0
  157. package/dist/lib/chunks/chunk-KRFHQQS7.js +323 -0
  158. package/dist/lib/chunks/chunk-KZR25REO.js +95 -0
  159. package/dist/lib/chunks/chunk-LIZX4N3H.js +110 -0
  160. package/dist/lib/chunks/chunk-M2OD74GP.js +93 -0
  161. package/dist/lib/chunks/chunk-MHAKYFDF.js +741 -0
  162. package/dist/lib/chunks/chunk-MIF5IYNR.js +139 -0
  163. package/dist/lib/chunks/chunk-MRRWMAPA.js +0 -0
  164. package/dist/lib/chunks/chunk-MX6Y4RD2.js +22 -0
  165. package/dist/lib/chunks/chunk-N2XIGMJ6.js +0 -0
  166. package/dist/lib/chunks/chunk-N2ZZ6JRF.js +188 -0
  167. package/dist/lib/chunks/chunk-NANJGMEJ.js +108 -0
  168. package/dist/lib/chunks/chunk-NCLFZOZU.js +74 -0
  169. package/dist/lib/chunks/chunk-NH4QGBJV.js +61 -0
  170. package/dist/lib/chunks/chunk-NL2LDKXX.js +125 -0
  171. package/dist/lib/chunks/chunk-NZFMOQHU.js +32 -0
  172. package/dist/lib/chunks/chunk-O2DKE2RO.js +77 -0
  173. package/dist/lib/chunks/chunk-O7M2OY3H.js +35 -0
  174. package/dist/lib/chunks/chunk-OBXAHX3L.js +46 -0
  175. package/dist/lib/chunks/chunk-OL746E4T.js +350 -0
  176. package/dist/lib/chunks/chunk-OORO55OM.js +922 -0
  177. package/dist/lib/chunks/chunk-OVUCZLH2.js +114 -0
  178. package/dist/lib/chunks/chunk-OX656HYK.js +46 -0
  179. package/dist/lib/chunks/chunk-OYKV5NDM.js +28 -0
  180. package/dist/lib/chunks/chunk-P4K6BP3L.js +104 -0
  181. package/dist/lib/chunks/chunk-PCYNBDZ7.js +386 -0
  182. package/dist/lib/chunks/chunk-PDS5KWO3.js +256 -0
  183. package/dist/lib/chunks/chunk-PKB6JRJM.js +53 -0
  184. package/dist/lib/chunks/chunk-PO2J5OQ3.js +46 -0
  185. package/dist/lib/chunks/chunk-PYLJISDZ.js +206 -0
  186. package/dist/lib/chunks/chunk-Q2PWES4B.js +822 -0
  187. package/dist/lib/chunks/chunk-QBD24WTZ.js +37 -0
  188. package/dist/lib/chunks/chunk-QFVRCSJ2.js +54 -0
  189. package/dist/lib/chunks/chunk-QTXOW5XC.js +14 -0
  190. package/dist/lib/chunks/chunk-RBOO4NDG.js +33 -0
  191. package/dist/lib/chunks/chunk-RMFT4KKK.js +281 -0
  192. package/dist/lib/chunks/chunk-S2AM76LT.js +90 -0
  193. package/dist/lib/chunks/chunk-S2SFHTJD.js +152 -0
  194. package/dist/lib/chunks/chunk-S42BCLHP.js +0 -0
  195. package/dist/lib/chunks/chunk-S7KJZIUR.js +241 -0
  196. package/dist/lib/chunks/chunk-SBAZBOPI.js +33 -0
  197. package/dist/lib/chunks/chunk-SBQ4TWGJ.js +33 -0
  198. package/dist/lib/chunks/chunk-SDWYZM64.js +371 -0
  199. package/dist/lib/chunks/chunk-SREGO3PU.js +25 -0
  200. package/dist/lib/chunks/chunk-SWJ7KQSL.js +318 -0
  201. package/dist/lib/chunks/chunk-SZ2UBZKG.js +13 -0
  202. package/dist/lib/chunks/chunk-TCOH3FGE.js +66 -0
  203. package/dist/lib/chunks/chunk-TGTM5ZFR.js +82 -0
  204. package/dist/lib/chunks/chunk-TNL2GWYR.js +345 -0
  205. package/dist/lib/chunks/chunk-UGCT46PC.js +20 -0
  206. package/dist/lib/chunks/chunk-ULRXHSJL.js +85 -0
  207. package/dist/lib/chunks/chunk-URUODEVG.js +0 -0
  208. package/dist/lib/chunks/chunk-V5B6UZ3E.js +47 -0
  209. package/dist/lib/chunks/chunk-VHDVKEWO.js +102 -0
  210. package/dist/lib/chunks/chunk-W46Y7KBR.js +29 -0
  211. package/dist/lib/chunks/chunk-W5XYW6ZM.js +133 -0
  212. package/dist/lib/chunks/chunk-WDSCJEDG.js +371 -0
  213. package/dist/lib/chunks/chunk-WE2WPNG2.js +104 -0
  214. package/dist/lib/chunks/chunk-WJUHRJVW.js +55 -0
  215. package/dist/lib/chunks/chunk-WKH6BJAZ.js +167 -0
  216. package/dist/lib/chunks/chunk-WTQWU522.js +343 -0
  217. package/dist/lib/chunks/chunk-WUELMJ22.js +345 -0
  218. package/dist/lib/chunks/chunk-X2Y2ZNG3.js +776 -0
  219. package/dist/lib/chunks/chunk-X6E44EGV.js +261 -0
  220. package/dist/lib/chunks/chunk-XHWRSGX3.js +95 -0
  221. package/dist/lib/chunks/chunk-XI5H46DF.js +47 -0
  222. package/dist/lib/chunks/chunk-XJVXASDD.js +281 -0
  223. package/dist/lib/chunks/chunk-XU6WQ5UL.js +257 -0
  224. package/dist/lib/chunks/chunk-Y4OGZ3Q5.js +365 -0
  225. package/dist/lib/chunks/chunk-Y6D6IVOM.js +299 -0
  226. package/dist/lib/chunks/chunk-YHS5IEVZ.js +252 -0
  227. package/dist/lib/chunks/chunk-YIEAIIND.js +6 -0
  228. package/dist/lib/chunks/chunk-YOZNLFSB.js +297 -0
  229. package/dist/lib/chunks/chunk-YR67JG2V.js +65 -0
  230. package/dist/lib/chunks/chunk-YWJPJI3W.js +51 -0
  231. package/dist/lib/chunks/chunk-Z4LMDKBU.js +369 -0
  232. package/dist/lib/chunks/chunk-Z7V63UZA.js +108 -0
  233. package/dist/lib/chunks/chunk-ZCOI3HE2.js +45 -0
  234. package/dist/lib/chunks/chunk-ZLOOC46D.js +142 -0
  235. package/dist/lib/chunks/chunk-ZSEY7AHQ.js +123 -0
  236. package/dist/lib/chunks/chunk-ZVAKKRRD.js +11 -0
  237. package/dist/lib/chunks/chunk-ZXQPD4OC.js +202 -0
  238. package/dist/lib/chunks/chunk-ZYSPTOKK.js +302 -0
  239. package/dist/lib/cli/bundle-commands.js +371 -0
  240. package/dist/lib/cli/io.js +12 -0
  241. package/dist/lib/cli/run-commands.js +614 -0
  242. package/dist/lib/codex-workflow/aggregate.js +56 -0
  243. package/dist/lib/codex-workflow/author-search.js +48 -0
  244. package/dist/lib/codex-workflow/author-tools.js +63 -0
  245. package/dist/lib/codex-workflow/author.js +99 -0
  246. package/dist/lib/codex-workflow/batch-input.js +7 -0
  247. package/dist/lib/codex-workflow/batch-layout.js +8 -0
  248. package/dist/lib/codex-workflow/capture.js +62 -0
  249. package/dist/lib/codex-workflow/checkpoint.js +39 -0
  250. package/dist/lib/codex-workflow/checks.js +44 -0
  251. package/dist/lib/codex-workflow/codex-home.js +17 -0
  252. package/dist/lib/codex-workflow/copy-editor.js +66 -0
  253. package/dist/lib/codex-workflow/copy-recovery.js +32 -0
  254. package/dist/lib/codex-workflow/copy.js +66 -0
  255. package/dist/lib/codex-workflow/finish.js +84 -0
  256. package/dist/lib/codex-workflow/host-models.js +15 -0
  257. package/dist/lib/codex-workflow/loop.js +140 -0
  258. package/dist/lib/codex-workflow/pending.js +8 -0
  259. package/dist/lib/codex-workflow/prompts.js +8 -0
  260. package/dist/lib/codex-workflow/quality.js +31 -0
  261. package/dist/lib/codex-workflow/run-inputs.js +38 -0
  262. package/dist/lib/codex-workflow/run-source.js +55 -0
  263. package/dist/lib/codex-workflow/schemas.js +58 -0
  264. package/dist/lib/codex-workflow/session.js +40 -0
  265. package/dist/lib/codex-workflow/stage.js +98 -0
  266. package/dist/lib/codex-workflow/workdir.js +42 -0
  267. package/dist/lib/configs/literally-2026-q3.js +6 -0
  268. package/dist/lib/container/protocol.js +20 -0
  269. package/dist/lib/coverage-schema.js +6 -0
  270. package/dist/lib/engine/audit-file.js +46 -0
  271. package/dist/lib/engine/author.js +97 -0
  272. package/dist/lib/engine/budget.js +16 -0
  273. package/dist/lib/engine/env-file.js +8 -0
  274. package/dist/lib/engine/local-run.js +149 -0
  275. package/dist/lib/engine/package-root.js +8 -0
  276. package/dist/lib/engine/preflight.js +43 -0
  277. package/dist/lib/engine/rejudge.js +151 -0
  278. package/dist/lib/engine/resources.js +7 -0
  279. package/dist/lib/engine/run-configuration.js +15 -0
  280. package/dist/lib/engine/templates.js +33 -0
  281. package/dist/lib/grounding/controller.js +31 -0
  282. package/dist/lib/grounding/extract.js +38 -0
  283. package/dist/lib/grounding/fetch.js +23 -0
  284. package/dist/lib/grounding/file-store.js +17 -0
  285. package/dist/lib/grounding/grounding-runtime.js +62 -0
  286. package/dist/lib/grounding/model-usage.js +9 -0
  287. package/dist/lib/grounding/model.js +30 -0
  288. package/dist/lib/grounding/profile.js +15 -0
  289. package/dist/lib/grounding/recorded-tools.js +35 -0
  290. package/dist/lib/grounding/schema.js +42 -0
  291. package/dist/lib/grounding/session.js +30 -0
  292. package/dist/lib/grounding/tools.js +25 -0
  293. package/dist/lib/grounding/validation.js +28 -0
  294. package/dist/lib/grounding.js +13 -0
  295. package/dist/lib/harness/checkpoint.js +17 -0
  296. package/dist/lib/harness/contracts.js +30 -0
  297. package/dist/lib/harness/criteria.js +14 -0
  298. package/dist/lib/harness/policy.js +25 -0
  299. package/dist/lib/harness/report/artifacts.js +36 -0
  300. package/dist/lib/harness/report/capture-coverage.js +11 -0
  301. package/dist/lib/harness/store.js +46 -0
  302. package/dist/lib/lib/analysis-checkpoint.js +10 -0
  303. package/dist/lib/lib/canonical-json.js +8 -0
  304. package/dist/lib/lib/checkpoint.js +34 -0
  305. package/dist/lib/lib/env.js +14 -0
  306. package/dist/lib/lib/log.js +7 -0
  307. package/dist/lib/lib/paths.js +8 -0
  308. package/dist/lib/lib/progress-comparison.js +16 -0
  309. package/dist/lib/lib/report-presentation.js +13 -0
  310. package/dist/lib/lib/run-id.js +8 -0
  311. package/dist/lib/lib/type-guards.js +8 -0
  312. package/dist/lib/models/accounting.js +22 -0
  313. package/dist/lib/models/batching.js +18 -0
  314. package/dist/lib/models/budget-protection.js +6 -0
  315. package/dist/lib/models/context.js +0 -0
  316. package/dist/lib/models/coverage-rounds.js +6 -0
  317. package/dist/lib/models/errors.js +8 -0
  318. package/dist/lib/models/failure-diagnostics.js +6 -0
  319. package/dist/lib/models/profiles.js +30 -0
  320. package/dist/lib/models/served-model.js +6 -0
  321. package/dist/lib/models/structured-images.js +10 -0
  322. package/dist/lib/models/structured.js +25 -0
  323. package/dist/lib/models/wire-schema.js +6 -0
  324. package/dist/lib/pipeline.js +57 -0
  325. package/dist/lib/probes/agent-cli-parsers.js +23 -0
  326. package/dist/lib/probes/agent-clis.js +64 -0
  327. package/dist/lib/probes/chat-retrieval.js +17 -0
  328. package/dist/lib/probes/child-process.js +13 -0
  329. package/dist/lib/probes/dataforseo-locale.js +10 -0
  330. package/dist/lib/probes/dataforseo.js +10 -0
  331. package/dist/lib/probes/failure.js +26 -0
  332. package/dist/lib/probes/grounding-urls.js +19 -0
  333. package/dist/lib/probes/limits.js +12 -0
  334. package/dist/lib/probes/outcomes.js +13 -0
  335. package/dist/lib/probes/probe-trace.js +12 -0
  336. package/dist/lib/probes/probes.js +40 -0
  337. package/dist/lib/probes/web-tool-guard.js +18 -0
  338. package/dist/lib/report/contracts.js +34 -0
  339. package/dist/lib/report/core/answer-text.js +18 -0
  340. package/dist/lib/report/core/copy-schema.js +10 -0
  341. package/dist/lib/report/core/domain-match.js +11 -0
  342. package/dist/lib/report/core/grounding.js +12 -0
  343. package/dist/lib/report/core/normalize-domain.js +6 -0
  344. package/dist/lib/report/core/progress-comparison.js +15 -0
  345. package/dist/lib/report/core/progress-question-sets.js +16 -0
  346. package/dist/lib/report/core/progress-schema.js +12 -0
  347. package/dist/lib/report/core/progress-slot-key.js +6 -0
  348. package/dist/lib/report/core/qualified-competitors.js +6 -0
  349. package/dist/lib/report/core/report-presentation.js +12 -0
  350. package/dist/lib/report/core/retrieval.js +10 -0
  351. package/dist/lib/report/core/schema.js +70 -0
  352. package/dist/lib/report/core/source-classifier.js +21 -0
  353. package/dist/lib/report/core/surfaces.js +18 -0
  354. package/dist/lib/retrieval.js +11 -0
  355. package/dist/lib/runner.js +71 -0
  356. package/dist/lib/schema.js +110 -0
  357. package/dist/lib/section-result.js +34 -0
  358. package/dist/lib/stores/artifacts.js +35 -0
  359. package/dist/lib/stores/content-hash.js +10 -0
  360. package/dist/lib/stores/file-publication.js +20 -0
  361. package/dist/lib/stores/files.js +76 -0
  362. package/dist/lib/stores/fs-errors.js +6 -0
  363. package/dist/lib/stores/local-versions.js +40 -0
  364. package/dist/lib/stores/memory.js +312 -0
  365. package/dist/lib/stores/ports.js +6 -0
  366. package/dist/lib/stores/publication-history.js +10 -0
  367. package/dist/lib/stores/publication.js +50 -0
  368. package/dist/lib/stores/run-lifecycle.js +12 -0
  369. package/dist/lib/stores/versions.js +6 -0
  370. package/dist/lib/surfaces.js +19 -0
  371. package/dist/lib/viewer/page.js +6 -0
  372. package/dist/lib/viewer/server.js +71 -0
  373. package/dist/lib/workflow/callbacks.js +15 -0
  374. package/dist/lib/workflow/lineage.js +8 -0
  375. package/dist/lib/workflow/schema.js +52 -0
  376. package/dist/types/access/schema.d.ts +75 -0
  377. package/dist/types/agents/author-schema.d.ts +76 -0
  378. package/dist/types/agents/author-validation.d.ts +73 -0
  379. package/dist/types/agents/copy-schema.d.ts +345 -0
  380. package/dist/types/agents/copy-validation.d.ts +158 -0
  381. package/dist/types/agents/copywriter-input.d.ts +46 -0
  382. package/dist/types/agents/credentials.d.ts +10 -0
  383. package/dist/types/agents/facts.d.ts +69 -0
  384. package/dist/types/agents/narrative-facts.d.ts +8 -0
  385. package/dist/types/agents/verifier.d.ts +167 -0
  386. package/dist/types/analysis/answer-text.d.ts +1 -0
  387. package/dist/types/analysis/competitor-classifier.d.ts +1 -0
  388. package/dist/types/analysis/domain-classifier.d.ts +105 -0
  389. package/dist/types/analysis/domain-labels.d.ts +30 -0
  390. package/dist/types/analysis/domain-match.d.ts +1 -0
  391. package/dist/types/analysis/name-forms.d.ts +25 -0
  392. package/dist/types/analysis/outreach.d.ts +6 -0
  393. package/dist/types/analysis/progress-schema.d.ts +1 -0
  394. package/dist/types/analysis/progress.d.ts +15 -0
  395. package/dist/types/analysis/qualified-competitors.d.ts +1 -0
  396. package/dist/types/analysis/retrieval.d.ts +22 -0
  397. package/dist/types/analysis/scoring.d.ts +55 -0
  398. package/dist/types/analysis/search-analyzer.d.ts +23 -0
  399. package/dist/types/analysis/sentiment.d.ts +99 -0
  400. package/dist/types/analysis/source-classifier.d.ts +1 -0
  401. package/dist/types/analysis/source-mix.d.ts +6 -0
  402. package/dist/types/analysis/verbatim.d.ts +1 -0
  403. package/dist/types/api/errors.d.ts +30 -0
  404. package/dist/types/author/examples.d.ts +31 -0
  405. package/dist/types/bundle/checks.d.ts +45 -0
  406. package/dist/types/bundle/contracts.d.ts +354 -0
  407. package/dist/types/bundle/export.d.ts +46 -0
  408. package/dist/types/bundle/journal.d.ts +39 -0
  409. package/dist/types/bundle/json.d.ts +8 -0
  410. package/dist/types/bundle/lineage.d.ts +13 -0
  411. package/dist/types/bundle/paths.d.ts +2 -0
  412. package/dist/types/bundle/project-journal.d.ts +31 -0
  413. package/dist/types/bundle/project.d.ts +30 -0
  414. package/dist/types/bundle/read.d.ts +9 -0
  415. package/dist/types/bundle/recorder.d.ts +89 -0
  416. package/dist/types/bundle/redact.d.ts +17 -0
  417. package/dist/types/bundle/trace-coverage.d.ts +36 -0
  418. package/dist/types/bundle/verify-integrity.d.ts +11 -0
  419. package/dist/types/bundle/verify-measurement.d.ts +26 -0
  420. package/dist/types/bundle/verify-report.d.ts +16 -0
  421. package/dist/types/bundle/verify.d.ts +31 -0
  422. package/dist/types/bundle/writer-lock.d.ts +23 -0
  423. package/dist/types/bundle/zip.d.ts +24 -0
  424. package/dist/types/capture-manifest.d.ts +122 -0
  425. package/dist/types/checks/crawler-access.d.ts +25 -0
  426. package/dist/types/checks/renderability.d.ts +4 -0
  427. package/dist/types/checks/run-checks.d.ts +8 -0
  428. package/dist/types/cli/bundle-commands.d.ts +5 -0
  429. package/dist/types/cli/io.d.ts +10 -0
  430. package/dist/types/cli/literally-aeo.d.ts +1 -0
  431. package/dist/types/cli/run-commands.d.ts +14 -0
  432. package/dist/types/codex-workflow/aggregate.d.ts +76 -0
  433. package/dist/types/codex-workflow/author-search.d.ts +26 -0
  434. package/dist/types/codex-workflow/author-tools-server.d.ts +1 -0
  435. package/dist/types/codex-workflow/author-tools.d.ts +145 -0
  436. package/dist/types/codex-workflow/author.d.ts +101 -0
  437. package/dist/types/codex-workflow/batch-input.d.ts +12 -0
  438. package/dist/types/codex-workflow/batch-layout.d.ts +16 -0
  439. package/dist/types/codex-workflow/capture.d.ts +37 -0
  440. package/dist/types/codex-workflow/checkpoint.d.ts +18 -0
  441. package/dist/types/codex-workflow/checks.d.ts +53 -0
  442. package/dist/types/codex-workflow/codex-home.d.ts +47 -0
  443. package/dist/types/codex-workflow/copy-editor.d.ts +164 -0
  444. package/dist/types/codex-workflow/copy-recovery.d.ts +30 -0
  445. package/dist/types/codex-workflow/copy.d.ts +62 -0
  446. package/dist/types/codex-workflow/finish.d.ts +53 -0
  447. package/dist/types/codex-workflow/host-models.d.ts +5 -0
  448. package/dist/types/codex-workflow/loop.d.ts +177 -0
  449. package/dist/types/codex-workflow/pending.d.ts +6 -0
  450. package/dist/types/codex-workflow/prompts.d.ts +14 -0
  451. package/dist/types/codex-workflow/quality.d.ts +25 -0
  452. package/dist/types/codex-workflow/run-inputs.d.ts +951 -0
  453. package/dist/types/codex-workflow/run-source.d.ts +34 -0
  454. package/dist/types/codex-workflow/schemas.d.ts +493 -0
  455. package/dist/types/codex-workflow/session.d.ts +13 -0
  456. package/dist/types/codex-workflow/stage.d.ts +136 -0
  457. package/dist/types/codex-workflow/workdir.d.ts +40 -0
  458. package/dist/types/configs/literally-2026-q3.d.ts +2 -0
  459. package/dist/types/container/protocol.d.ts +72 -0
  460. package/dist/types/coverage-schema.d.ts +6 -0
  461. package/dist/types/engine/audit-file.d.ts +126 -0
  462. package/dist/types/engine/author.d.ts +52 -0
  463. package/dist/types/engine/budget.d.ts +68 -0
  464. package/dist/types/engine/env-file.d.ts +13 -0
  465. package/dist/types/engine/local-run.d.ts +62 -0
  466. package/dist/types/engine/package-root.d.ts +8 -0
  467. package/dist/types/engine/preflight.d.ts +27 -0
  468. package/dist/types/engine/rejudge.d.ts +14 -0
  469. package/dist/types/engine/resources.d.ts +8 -0
  470. package/dist/types/engine/run-configuration.d.ts +36 -0
  471. package/dist/types/engine/templates.d.ts +38 -0
  472. package/dist/types/grounding/controller.d.ts +110 -0
  473. package/dist/types/grounding/extract.d.ts +103 -0
  474. package/dist/types/grounding/fetch.d.ts +53 -0
  475. package/dist/types/grounding/file-store.d.ts +2 -0
  476. package/dist/types/grounding/grounding-runtime.d.ts +43 -0
  477. package/dist/types/grounding/model-usage.d.ts +13 -0
  478. package/dist/types/grounding/model.d.ts +51 -0
  479. package/dist/types/grounding/profile.d.ts +15 -0
  480. package/dist/types/grounding/recorded-tools.d.ts +12 -0
  481. package/dist/types/grounding/schema.d.ts +521 -0
  482. package/dist/types/grounding/session.d.ts +143 -0
  483. package/dist/types/grounding/tools.d.ts +135 -0
  484. package/dist/types/grounding/validation.d.ts +35 -0
  485. package/dist/types/grounding.d.ts +1 -0
  486. package/dist/types/harness/checkpoint.d.ts +29 -0
  487. package/dist/types/harness/contracts.d.ts +141 -0
  488. package/dist/types/harness/criteria.d.ts +34 -0
  489. package/dist/types/harness/policy.d.ts +9 -0
  490. package/dist/types/harness/report/artifacts.d.ts +287 -0
  491. package/dist/types/harness/report/capture-coverage.d.ts +11 -0
  492. package/dist/types/harness/store.d.ts +116 -0
  493. package/dist/types/lib/analysis-checkpoint.d.ts +20 -0
  494. package/dist/types/lib/canonical-json.d.ts +11 -0
  495. package/dist/types/lib/checkpoint.d.ts +33 -0
  496. package/dist/types/lib/env.d.ts +31 -0
  497. package/dist/types/lib/log.d.ts +11 -0
  498. package/dist/types/lib/paths.d.ts +2 -0
  499. package/dist/types/lib/progress-comparison.d.ts +1 -0
  500. package/dist/types/lib/report-presentation.d.ts +1 -0
  501. package/dist/types/lib/run-id.d.ts +2 -0
  502. package/dist/types/lib/type-guards.d.ts +9 -0
  503. package/dist/types/models/accounting.d.ts +147 -0
  504. package/dist/types/models/batching.d.ts +17 -0
  505. package/dist/types/models/budget-protection.d.ts +10 -0
  506. package/dist/types/models/context.d.ts +8 -0
  507. package/dist/types/models/coverage-rounds.d.ts +47 -0
  508. package/dist/types/models/errors.d.ts +12 -0
  509. package/dist/types/models/failure-diagnostics.d.ts +8 -0
  510. package/dist/types/models/profiles.d.ts +551 -0
  511. package/dist/types/models/served-model.d.ts +11 -0
  512. package/dist/types/models/structured-images.d.ts +9 -0
  513. package/dist/types/models/structured.d.ts +111 -0
  514. package/dist/types/models/wire-schema.d.ts +27 -0
  515. package/dist/types/pipeline.d.ts +117 -0
  516. package/dist/types/probes/agent-cli-parsers.d.ts +46 -0
  517. package/dist/types/probes/agent-clis.d.ts +132 -0
  518. package/dist/types/probes/chat-retrieval.d.ts +14 -0
  519. package/dist/types/probes/child-process.d.ts +28 -0
  520. package/dist/types/probes/dataforseo-locale.d.ts +8 -0
  521. package/dist/types/probes/dataforseo.d.ts +15 -0
  522. package/dist/types/probes/failure.d.ts +30 -0
  523. package/dist/types/probes/grounding-urls.d.ts +18 -0
  524. package/dist/types/probes/limits.d.ts +30 -0
  525. package/dist/types/probes/outcomes.d.ts +20 -0
  526. package/dist/types/probes/probe-trace.d.ts +51 -0
  527. package/dist/types/probes/probes.d.ts +47 -0
  528. package/dist/types/probes/web-tool-guard.d.ts +59 -0
  529. package/dist/types/report/contracts.d.ts +973 -0
  530. package/dist/types/report/core/answer-text.d.ts +24 -0
  531. package/dist/types/report/core/copy-schema.d.ts +47 -0
  532. package/dist/types/report/core/domain-match.d.ts +9 -0
  533. package/dist/types/report/core/grounding.d.ts +4 -0
  534. package/dist/types/report/core/normalize-domain.d.ts +2 -0
  535. package/dist/types/report/core/progress-comparison.d.ts +52 -0
  536. package/dist/types/report/core/progress-question-sets.d.ts +16 -0
  537. package/dist/types/report/core/progress-schema.d.ts +101 -0
  538. package/dist/types/report/core/progress-slot-key.d.ts +9 -0
  539. package/dist/types/report/core/qualified-competitors.d.ts +6 -0
  540. package/dist/types/report/core/report-presentation.d.ts +10 -0
  541. package/dist/types/report/core/retrieval.d.ts +6 -0
  542. package/dist/types/report/core/schema.d.ts +745 -0
  543. package/dist/types/report/core/source-classifier.d.ts +21 -0
  544. package/dist/types/report/core/surfaces.d.ts +11 -0
  545. package/dist/types/retrieval.d.ts +1 -0
  546. package/dist/types/runner.d.ts +96 -0
  547. package/dist/types/schema.d.ts +858 -0
  548. package/dist/types/section-result.d.ts +4 -0
  549. package/dist/types/stores/artifacts.d.ts +2 -0
  550. package/dist/types/stores/content-hash.d.ts +2 -0
  551. package/dist/types/stores/file-publication.d.ts +31 -0
  552. package/dist/types/stores/files.d.ts +87 -0
  553. package/dist/types/stores/fs-errors.d.ts +5 -0
  554. package/dist/types/stores/local-versions.d.ts +54 -0
  555. package/dist/types/stores/memory.d.ts +76 -0
  556. package/dist/types/stores/ports.d.ts +150 -0
  557. package/dist/types/stores/publication-history.d.ts +27 -0
  558. package/dist/types/stores/publication.d.ts +53 -0
  559. package/dist/types/stores/run-lifecycle.d.ts +7 -0
  560. package/dist/types/stores/versions.d.ts +71 -0
  561. package/dist/types/surfaces.d.ts +1 -0
  562. package/dist/types/viewer/page.d.ts +2 -0
  563. package/dist/types/viewer/server.d.ts +14 -0
  564. package/dist/types/workflow/callbacks.d.ts +22 -0
  565. package/dist/types/workflow/lineage.d.ts +20 -0
  566. package/dist/types/workflow/schema.d.ts +1572 -0
  567. package/package.json +95 -3
  568. package/resources/author/COPY_RULES.md +95 -0
  569. package/resources/author/RULES.md +104 -0
  570. package/resources/author/banlist.json +38 -0
  571. package/resources/editorial/COMPANY.md +11 -0
  572. package/resources/editorial/positioning.md +8 -0
  573. package/resources/editorial/services.md +4 -0
  574. package/src/access/schema.ts +96 -0
  575. package/src/agents/author-schema.ts +49 -0
  576. package/src/agents/author-validation.ts +409 -0
  577. package/src/agents/copy-schema.ts +214 -0
  578. package/src/agents/copy-validation.ts +1170 -0
  579. package/src/agents/copywriter-input.ts +90 -0
  580. package/src/agents/credentials.ts +60 -0
  581. package/src/agents/facts.ts +343 -0
  582. package/src/agents/narrative-facts.ts +174 -0
  583. package/src/agents/verifier.ts +603 -0
  584. package/src/analysis/answer-text.ts +1 -0
  585. package/src/analysis/competitor-classifier.ts +15 -0
  586. package/src/analysis/domain-classifier.ts +804 -0
  587. package/src/analysis/domain-labels.ts +67 -0
  588. package/src/analysis/domain-match.ts +1 -0
  589. package/src/analysis/name-forms.ts +59 -0
  590. package/src/analysis/outreach.ts +107 -0
  591. package/src/analysis/progress-schema.ts +1 -0
  592. package/src/analysis/progress.ts +346 -0
  593. package/src/analysis/qualified-competitors.ts +1 -0
  594. package/src/analysis/retrieval.ts +105 -0
  595. package/src/analysis/scoring.ts +167 -0
  596. package/src/analysis/search-analyzer.ts +83 -0
  597. package/src/analysis/sentiment.ts +558 -0
  598. package/src/analysis/source-classifier.ts +1 -0
  599. package/src/analysis/source-mix.ts +56 -0
  600. package/src/analysis/verbatim.ts +107 -0
  601. package/src/api/errors.ts +50 -0
  602. package/src/author/COPY_RULES.md +95 -0
  603. package/src/author/RULES.md +104 -0
  604. package/src/author/banlist.json +38 -0
  605. package/src/author/examples.ts +79 -0
  606. package/src/bundle/checks.ts +146 -0
  607. package/src/bundle/contracts.ts +289 -0
  608. package/src/bundle/export.ts +448 -0
  609. package/src/bundle/journal.ts +270 -0
  610. package/src/bundle/json.ts +157 -0
  611. package/src/bundle/lineage.ts +45 -0
  612. package/src/bundle/paths.ts +36 -0
  613. package/src/bundle/project-journal.ts +179 -0
  614. package/src/bundle/project.ts +434 -0
  615. package/src/bundle/read.ts +154 -0
  616. package/src/bundle/recorder.ts +497 -0
  617. package/src/bundle/redact.ts +134 -0
  618. package/src/bundle/trace-coverage.ts +168 -0
  619. package/src/bundle/verify-integrity.ts +322 -0
  620. package/src/bundle/verify-measurement.ts +384 -0
  621. package/src/bundle/verify-report.ts +260 -0
  622. package/src/bundle/verify.ts +400 -0
  623. package/src/bundle/writer-lock.ts +133 -0
  624. package/src/bundle/zip.ts +281 -0
  625. package/src/capture-manifest.ts +348 -0
  626. package/src/checks/crawler-access.ts +373 -0
  627. package/src/checks/renderability.ts +164 -0
  628. package/src/checks/run-checks.ts +74 -0
  629. package/src/cli/bundle-commands.ts +249 -0
  630. package/src/cli/io.ts +63 -0
  631. package/src/cli/literally-aeo.ts +121 -0
  632. package/src/cli/run-commands.ts +535 -0
  633. package/src/codex-workflow/aggregate.ts +336 -0
  634. package/src/codex-workflow/author-search.ts +76 -0
  635. package/src/codex-workflow/author-tools-server.ts +208 -0
  636. package/src/codex-workflow/author-tools.ts +1202 -0
  637. package/src/codex-workflow/author.ts +512 -0
  638. package/src/codex-workflow/batch-input.ts +145 -0
  639. package/src/codex-workflow/batch-layout.ts +47 -0
  640. package/src/codex-workflow/capture.ts +255 -0
  641. package/src/codex-workflow/checkpoint.ts +127 -0
  642. package/src/codex-workflow/checks.ts +510 -0
  643. package/src/codex-workflow/codex-home.ts +187 -0
  644. package/src/codex-workflow/copy-editor.ts +322 -0
  645. package/src/codex-workflow/copy-recovery.ts +134 -0
  646. package/src/codex-workflow/copy.ts +195 -0
  647. package/src/codex-workflow/finish.ts +433 -0
  648. package/src/codex-workflow/host-models.ts +35 -0
  649. package/src/codex-workflow/loop.ts +1159 -0
  650. package/src/codex-workflow/pending.ts +24 -0
  651. package/src/codex-workflow/prompts.ts +153 -0
  652. package/src/codex-workflow/quality.ts +97 -0
  653. package/src/codex-workflow/run-inputs.ts +117 -0
  654. package/src/codex-workflow/run-source.ts +149 -0
  655. package/src/codex-workflow/schemas.ts +222 -0
  656. package/src/codex-workflow/session.ts +70 -0
  657. package/src/codex-workflow/stage.ts +2344 -0
  658. package/src/codex-workflow/workdir.ts +242 -0
  659. package/src/configs/literally-2026-q3.ts +199 -0
  660. package/src/container/protocol.ts +152 -0
  661. package/src/coverage-schema.ts +7 -0
  662. package/src/engine/audit-file.ts +254 -0
  663. package/src/engine/author.ts +279 -0
  664. package/src/engine/budget.ts +164 -0
  665. package/src/engine/editorial/COMPANY.md +11 -0
  666. package/src/engine/editorial/positioning.md +8 -0
  667. package/src/engine/editorial/services.md +4 -0
  668. package/src/engine/env-file.ts +87 -0
  669. package/src/engine/local-run.ts +323 -0
  670. package/src/engine/package-root.ts +47 -0
  671. package/src/engine/preflight.ts +156 -0
  672. package/src/engine/rejudge.ts +118 -0
  673. package/src/engine/resources.ts +45 -0
  674. package/src/engine/run-configuration.ts +70 -0
  675. package/src/engine/templates.ts +66 -0
  676. package/src/grounding/controller.ts +1211 -0
  677. package/src/grounding/extract.ts +830 -0
  678. package/src/grounding/fetch.ts +448 -0
  679. package/src/grounding/file-store.ts +131 -0
  680. package/src/grounding/grounding-runtime.ts +318 -0
  681. package/src/grounding/model-usage.ts +48 -0
  682. package/src/grounding/model.ts +508 -0
  683. package/src/grounding/profile.ts +63 -0
  684. package/src/grounding/recorded-tools.ts +40 -0
  685. package/src/grounding/schema.ts +262 -0
  686. package/src/grounding/session.ts +681 -0
  687. package/src/grounding/tools.ts +500 -0
  688. package/src/grounding/validation.ts +435 -0
  689. package/src/grounding.ts +1 -0
  690. package/src/harness/checkpoint.ts +53 -0
  691. package/src/harness/contracts.ts +169 -0
  692. package/src/harness/criteria.ts +166 -0
  693. package/src/harness/policy.ts +28 -0
  694. package/src/harness/report/artifacts.ts +130 -0
  695. package/src/harness/report/capture-coverage.ts +40 -0
  696. package/src/harness/store.ts +167 -0
  697. package/src/lib/analysis-checkpoint.ts +94 -0
  698. package/src/lib/canonical-json.ts +90 -0
  699. package/src/lib/checkpoint.ts +140 -0
  700. package/src/lib/env.ts +80 -0
  701. package/src/lib/log.ts +192 -0
  702. package/src/lib/paths.ts +14 -0
  703. package/src/lib/progress-comparison.ts +1 -0
  704. package/src/lib/report-presentation.ts +1 -0
  705. package/src/lib/run-id.ts +39 -0
  706. package/src/lib/type-guards.ts +14 -0
  707. package/src/models/accounting.ts +656 -0
  708. package/src/models/batching.ts +68 -0
  709. package/src/models/budget-protection.ts +68 -0
  710. package/src/models/context.ts +9 -0
  711. package/src/models/coverage-rounds.ts +125 -0
  712. package/src/models/errors.ts +39 -0
  713. package/src/models/failure-diagnostics.ts +157 -0
  714. package/src/models/profiles.ts +511 -0
  715. package/src/models/served-model.ts +20 -0
  716. package/src/models/structured-images.ts +95 -0
  717. package/src/models/structured.ts +634 -0
  718. package/src/models/wire-schema.ts +453 -0
  719. package/src/pipeline.ts +496 -0
  720. package/src/probes/agent-cli-parsers.ts +835 -0
  721. package/src/probes/agent-clis.ts +1482 -0
  722. package/src/probes/chat-retrieval.ts +238 -0
  723. package/src/probes/child-process.ts +280 -0
  724. package/src/probes/dataforseo-locale.ts +71 -0
  725. package/src/probes/dataforseo.ts +286 -0
  726. package/src/probes/failure.ts +182 -0
  727. package/src/probes/grounding-urls.ts +182 -0
  728. package/src/probes/limits.ts +181 -0
  729. package/src/probes/outcomes.ts +40 -0
  730. package/src/probes/probe-trace.ts +109 -0
  731. package/src/probes/probes.ts +789 -0
  732. package/src/probes/web-tool-guard.ts +195 -0
  733. package/src/report/contracts.ts +161 -0
  734. package/src/report/core/answer-text.ts +144 -0
  735. package/src/report/core/copy-schema.ts +75 -0
  736. package/src/report/core/domain-match.ts +52 -0
  737. package/src/report/core/grounding.ts +32 -0
  738. package/src/report/core/normalize-domain.ts +16 -0
  739. package/src/report/core/progress-comparison.ts +362 -0
  740. package/src/report/core/progress-question-sets.ts +93 -0
  741. package/src/report/core/progress-schema.ts +150 -0
  742. package/src/report/core/progress-slot-key.ts +20 -0
  743. package/src/report/core/qualified-competitors.ts +15 -0
  744. package/src/report/core/report-presentation.ts +112 -0
  745. package/src/report/core/retrieval.ts +49 -0
  746. package/src/report/core/schema.ts +489 -0
  747. package/src/report/core/source-classifier.ts +239 -0
  748. package/src/report/core/surfaces.ts +64 -0
  749. package/src/retrieval.ts +1 -0
  750. package/src/runner.ts +461 -0
  751. package/src/schema.ts +181 -0
  752. package/src/section-result.ts +315 -0
  753. package/src/stores/artifacts.ts +74 -0
  754. package/src/stores/content-hash.ts +8 -0
  755. package/src/stores/file-publication.ts +194 -0
  756. package/src/stores/files.ts +1069 -0
  757. package/src/stores/fs-errors.ts +12 -0
  758. package/src/stores/local-versions.ts +412 -0
  759. package/src/stores/memory.ts +432 -0
  760. package/src/stores/ports.ts +231 -0
  761. package/src/stores/publication-history.ts +48 -0
  762. package/src/stores/publication.ts +221 -0
  763. package/src/stores/run-lifecycle.ts +72 -0
  764. package/src/stores/versions.ts +113 -0
  765. package/src/surfaces.ts +1 -0
  766. package/src/viewer/page.ts +208 -0
  767. package/src/viewer/server.ts +215 -0
  768. package/src/workflow/callbacks.ts +201 -0
  769. package/src/workflow/lineage.ts +36 -0
  770. package/src/workflow/schema.ts +256 -0
@@ -0,0 +1,1069 @@
1
+ import { existsSync } from 'node:fs';
2
+ import {
3
+ chmod,
4
+ mkdir,
5
+ mkdtemp,
6
+ open,
7
+ readFile,
8
+ readdir,
9
+ rename,
10
+ rm,
11
+ writeFile,
12
+ } from 'node:fs/promises';
13
+ import path from 'node:path';
14
+ import { z, type ZodType } from 'zod';
15
+ import {
16
+ domainLabelsFile,
17
+ domainLabelsFileSchema,
18
+ type DomainLabelsFile,
19
+ } from '../analysis/domain-labels';
20
+ import { projectProgressMeasurement } from '../analysis/progress';
21
+ import { parseProgressMeasurement } from '../analysis/progress-schema';
22
+ import { entryMatches, unitRecordKey } from '../lib/checkpoint';
23
+ import { createLog } from '../lib/log';
24
+ import { aeoCheckpointDir, aeoContentDir } from '../lib/paths';
25
+ import type { ProgressMeasurement } from '../lib/progress-comparison';
26
+ import {
27
+ aeoAuditConfigSchema,
28
+ aeoEvidenceChunkSchema,
29
+ aeoSnapshotSchema,
30
+ evidenceChunkFileName,
31
+ type AeoEvidenceChunk,
32
+ type AeoSnapshot,
33
+ } from '../schema';
34
+ import { validateReportArtifacts } from './artifacts';
35
+ import { contentHash } from './content-hash';
36
+ import {
37
+ filePublicationHistory,
38
+ readFilePublication,
39
+ withFilePublicationLock,
40
+ writeAtomicJson,
41
+ writeFilePublication,
42
+ } from './file-publication';
43
+ import { hasErrorCode } from './fs-errors';
44
+ import { openFileVersionStores } from './local-versions';
45
+ import type { AnalysisEntry } from './memory';
46
+ import {
47
+ UnitConflictError,
48
+ type AnalysisEntryMeta,
49
+ type AnalysisStore,
50
+ type CapturedUnitRecord,
51
+ type CheckpointMatch,
52
+ type FailedUnitRecord,
53
+ type ProbeStore,
54
+ type ProbeUnit,
55
+ type ReportArtifacts,
56
+ type ReportStore,
57
+ type RunClaim,
58
+ type RunClaimResult,
59
+ type RunReconciliation,
60
+ type RunRecord,
61
+ type RunStore,
62
+ type Stores,
63
+ type UnitRecord,
64
+ } from './ports';
65
+ import {
66
+ assertPublishable,
67
+ sameTriple,
68
+ type PublicationTriple,
69
+ type PublishReceipt,
70
+ } from './publication';
71
+ import { publicationTripleSchema } from './publication-history';
72
+ import {
73
+ evaluateRunClaim,
74
+ isTerminalRun,
75
+ serializeRunFile,
76
+ } from './run-lifecycle';
77
+ import {
78
+ StoreConflictError,
79
+ type ConfigStore,
80
+ type CopyStore,
81
+ } from './versions';
82
+
83
+ const log = createLog('FileStores');
84
+
85
+ // ============================================================================
86
+ // File-backed implementations of the storage ports — the interim backend
87
+ // (hardening spec §4.4) until the Postgres stores take over. Probe and
88
+ // analysis records are append-only JSONL under aeo/checkpoints/ (crash-safe:
89
+ // a torn tail line is skipped on load; gitignored: entries carry raw client
90
+ // answers). Reports are the committed content/aeo-insights/<reportKey>/
91
+ // layout (snapshot.json, domain-labels.json, evidence/), written atomically
92
+ // through a temp directory. A write failure rejects — never swallowed.
93
+ // ============================================================================
94
+
95
+ type JsonlLine = {
96
+ key: string;
97
+ value: unknown;
98
+ };
99
+
100
+ const readJsonl = async (filePath: string): Promise<unknown[]> => {
101
+ let raw: string;
102
+
103
+ try {
104
+ raw = await readFile(filePath, 'utf8');
105
+ } catch {
106
+ return [];
107
+ }
108
+
109
+ const rows: unknown[] = [];
110
+
111
+ for (const line of raw.split('\n')) {
112
+ if (!line.trim()) {
113
+ continue;
114
+ }
115
+
116
+ try {
117
+ rows.push(JSON.parse(line));
118
+ } catch {
119
+ // Torn tail line from an interrupted append — the unit it held simply
120
+ // reruns.
121
+ }
122
+ }
123
+
124
+ return rows;
125
+ };
126
+
127
+ // Appends are chained so parallel completions never interleave lines.
128
+ class JsonlFile {
129
+ readonly filePath: string;
130
+ #queue: Promise<void> = Promise.resolve();
131
+
132
+ constructor(filePath: string) {
133
+ this.filePath = filePath;
134
+ }
135
+
136
+ append(line: string): Promise<void> {
137
+ return this.#write(`${line}\n`, 'a');
138
+ }
139
+
140
+ rewrite(lines: string[]): Promise<void> {
141
+ return this.#write(lines.map((line) => `${line}\n`).join(''), 'w');
142
+ }
143
+
144
+ #write(content: string, flag: 'a' | 'w'): Promise<void> {
145
+ const write = this.#queue.then(async () => {
146
+ const directory = path.dirname(this.filePath);
147
+
148
+ await mkdir(directory, { recursive: true, mode: 0o700 });
149
+ await chmod(directory, 0o700);
150
+
151
+ const file = await open(this.filePath, flag, 0o600);
152
+
153
+ try {
154
+ // Existing checkpoints may predate private diagnostics. Restrict the
155
+ // opened file before writing any further customer evidence.
156
+ await file.chmod(0o600);
157
+ await file.writeFile(content, 'utf8');
158
+ } finally {
159
+ await file.close();
160
+ }
161
+ });
162
+
163
+ // The chain must survive a rejected write; the caller still sees it.
164
+ this.#queue = write.catch(() => undefined);
165
+
166
+ return write;
167
+ }
168
+ }
169
+
170
+ // The stored probe payload is trusted as written by put(); a line is only
171
+ // checked for the unit key and its outcome fields.
172
+ const hasUnitKey = (row: object): row is ProbeUnit => {
173
+ return (
174
+ 'sectionKey' in row &&
175
+ typeof row.sectionKey === 'string' &&
176
+ 'promptId' in row &&
177
+ typeof row.promptId === 'string' &&
178
+ 'promptText' in row &&
179
+ typeof row.promptText === 'string' &&
180
+ 'surface' in row &&
181
+ typeof row.surface === 'string' &&
182
+ 'runIndex' in row &&
183
+ typeof row.runIndex === 'number'
184
+ );
185
+ };
186
+
187
+ const isFailedUnitLine = (row: ProbeUnit): row is FailedUnitRecord => {
188
+ return 'status' in row && row.status === 'failed';
189
+ };
190
+
191
+ const isCapturedUnitLine = (
192
+ row: ProbeUnit,
193
+ ): row is Omit<CapturedUnitRecord, 'status'> => {
194
+ return (
195
+ 'probe' in row &&
196
+ Boolean(row.probe) &&
197
+ 'capturedAt' in row &&
198
+ typeof row.capturedAt === 'string'
199
+ );
200
+ };
201
+
202
+ // Stored line shape: the record as-is. Lines written before unit outcomes
203
+ // existed carry no `status`; they are captured records.
204
+ const parseUnitRecord = (row: unknown): UnitRecord | null => {
205
+ if (!row || typeof row !== 'object' || !hasUnitKey(row)) {
206
+ return null;
207
+ }
208
+
209
+ if (isFailedUnitLine(row)) {
210
+ return row;
211
+ }
212
+
213
+ if (isCapturedUnitLine(row)) {
214
+ return { ...row, status: 'captured' };
215
+ }
216
+
217
+ return null;
218
+ };
219
+
220
+ export class FileProbeStore implements ProbeStore {
221
+ readonly #file: JsonlFile;
222
+ readonly #records: Map<string, UnitRecord>;
223
+
224
+ private constructor(filePath: string, records: Map<string, UnitRecord>) {
225
+ this.#file = new JsonlFile(filePath);
226
+ this.#records = records;
227
+ }
228
+
229
+ static async open(
230
+ reportKey: string,
231
+ opts: { dir?: string } = {},
232
+ ): Promise<FileProbeStore> {
233
+ const filePath = path.join(
234
+ opts.dir ?? aeoCheckpointDir,
235
+ `${reportKey}.jsonl`,
236
+ );
237
+ const records = new Map<string, UnitRecord>();
238
+
239
+ for (const row of await readJsonl(filePath)) {
240
+ const record = parseUnitRecord(row);
241
+
242
+ // Last line wins on load — the file is a log of writes.
243
+ if (record) {
244
+ records.set(unitRecordKey(record), record);
245
+ }
246
+ }
247
+
248
+ return new FileProbeStore(filePath, records);
249
+ }
250
+
251
+ get size(): number {
252
+ return this.#records.size;
253
+ }
254
+
255
+ get(unit: ProbeUnit): Promise<UnitRecord | null> {
256
+ return Promise.resolve(this.#records.get(unitRecordKey(unit)) ?? null);
257
+ }
258
+
259
+ async put(record: UnitRecord): Promise<void> {
260
+ const key = unitRecordKey(record);
261
+ const existing = this.#records.get(key);
262
+
263
+ if (existing?.status === 'captured') {
264
+ // A capture is the record of value: a second capture is refused and
265
+ // a later failure never erases it (same rule as the Postgres store).
266
+ if (record.status === 'captured') {
267
+ throw new UnitConflictError(key);
268
+ }
269
+
270
+ return;
271
+ }
272
+
273
+ this.#records.set(key, record);
274
+
275
+ await this.#file.append(JSON.stringify(record));
276
+ }
277
+
278
+ async invalidate(match: CheckpointMatch): Promise<number> {
279
+ let removed = 0;
280
+
281
+ for (const [key, record] of this.#records) {
282
+ if (!entryMatches(record, match)) {
283
+ continue;
284
+ }
285
+
286
+ this.#records.delete(key);
287
+ removed += 1;
288
+ }
289
+
290
+ if (removed > 0) {
291
+ await this.#rewrite();
292
+ }
293
+
294
+ return removed;
295
+ }
296
+
297
+ list(): Promise<UnitRecord[]> {
298
+ return Promise.resolve([...this.#records.values()]);
299
+ }
300
+
301
+ /**
302
+ * rewriteRecords rewrites stored probes in place (one-off data repairs):
303
+ * `patch` returns the replacement record or null to leave the entry
304
+ * untouched.
305
+ */
306
+ async rewriteRecords(
307
+ patch: (record: UnitRecord) => UnitRecord | null,
308
+ ): Promise<number> {
309
+ let changed = 0;
310
+
311
+ for (const [key, record] of this.#records) {
312
+ const next = patch(record);
313
+
314
+ if (!next) {
315
+ continue;
316
+ }
317
+
318
+ this.#records.set(key, next);
319
+ changed += 1;
320
+ }
321
+
322
+ if (changed > 0) {
323
+ await this.#rewrite();
324
+ }
325
+
326
+ return changed;
327
+ }
328
+
329
+ #rewrite(): Promise<void> {
330
+ return this.#file.rewrite(
331
+ [...this.#records.values()].map((record) => JSON.stringify(record)),
332
+ );
333
+ }
334
+ }
335
+
336
+ export const analysisCheckpointPath = (
337
+ reportKey: string,
338
+ dir: string = aeoCheckpointDir,
339
+ ): string => {
340
+ return path.join(dir, `${reportKey}.analysis.jsonl`);
341
+ };
342
+
343
+ const isAnalysisEntryLine = (row: unknown): row is AnalysisEntry => {
344
+ return (
345
+ typeof row === 'object' &&
346
+ row !== null &&
347
+ 'key' in row &&
348
+ typeof row.key === 'string' &&
349
+ 'value' in row
350
+ );
351
+ };
352
+
353
+ export class FileAnalysisStore implements AnalysisStore {
354
+ readonly #file: JsonlFile;
355
+ readonly #entries: Map<string, AnalysisEntry>;
356
+
357
+ private constructor(filePath: string, entries: Map<string, AnalysisEntry>) {
358
+ this.#file = new JsonlFile(filePath);
359
+ this.#entries = entries;
360
+ }
361
+
362
+ static async open(
363
+ reportKey: string,
364
+ opts: { dir?: string } = {},
365
+ ): Promise<FileAnalysisStore> {
366
+ const filePath = analysisCheckpointPath(reportKey, opts.dir);
367
+ const entries = new Map<string, AnalysisEntry>();
368
+
369
+ for (const row of await readJsonl(filePath)) {
370
+ if (isAnalysisEntryLine(row)) {
371
+ entries.set(row.key, row);
372
+ }
373
+ }
374
+
375
+ return new FileAnalysisStore(filePath, entries);
376
+ }
377
+
378
+ get<T>(key: string, schema: ZodType<T>): Promise<T | null> {
379
+ const entry = this.#entries.get(key);
380
+
381
+ if (!entry) {
382
+ return Promise.resolve(null);
383
+ }
384
+
385
+ const parsed = schema.safeParse(entry.value);
386
+
387
+ if (!parsed.success) {
388
+ log.warn('Ignoring invalid cached analysis entry', {
389
+ key: key.slice(0, 80),
390
+ error: parsed.error.message.slice(0, 200),
391
+ });
392
+
393
+ return Promise.resolve(null);
394
+ }
395
+
396
+ return Promise.resolve(parsed.data);
397
+ }
398
+
399
+ async put(
400
+ key: string,
401
+ value: unknown,
402
+ meta?: AnalysisEntryMeta,
403
+ ): Promise<void> {
404
+ const entry: AnalysisEntry = {
405
+ key,
406
+ storedAt: new Date().toISOString(),
407
+ value,
408
+ ...(meta ? { meta } : {}),
409
+ };
410
+
411
+ this.#entries.set(key, entry);
412
+
413
+ await this.#file.append(JSON.stringify(entry));
414
+ }
415
+
416
+ async clear(): Promise<number> {
417
+ const size = this.#entries.size;
418
+
419
+ this.#entries.clear();
420
+
421
+ await rm(this.#file.filePath, { force: true });
422
+
423
+ return size;
424
+ }
425
+
426
+ count(): Promise<number> {
427
+ return Promise.resolve(this.#entries.size);
428
+ }
429
+ }
430
+
431
+ const publishedPointerSchema = z.object({ runId: z.string() });
432
+
433
+ // Fields are compared, not trusted: a mismatch is a conflict. zod requires a
434
+ // `z.unknown()` key to be present, so each one is marked optional.
435
+ const storedProgressSchema = z.object({
436
+ reportKey: z.unknown().optional(),
437
+ configVersion: z.unknown().optional(),
438
+ sourceDigest: z.unknown().optional(),
439
+ measurement: z.unknown().optional(),
440
+ });
441
+
442
+ // Only what publication checks; a missing or malformed field fails those
443
+ // checks as a conflict rather than as a parse error. An ungrounded run omits
444
+ // the grounding and captureManifest keys from artifacts.json.
445
+ const storedArtifactSchema = z.object({
446
+ fullScope: z.boolean().catch(false),
447
+ configVersion: z.number().nullish().catch(null),
448
+ snapshot: z.unknown().optional(),
449
+ grounding: z.unknown().optional(),
450
+ captureManifest: z.unknown().optional(),
451
+ });
452
+
453
+ type StoredArtifact = z.infer<typeof storedArtifactSchema>;
454
+
455
+ type PublicationStores = {
456
+ configStore: ConfigStore;
457
+ copyStore: CopyStore;
458
+ runStore: RunStore;
459
+ };
460
+
461
+ type ProgressSource = {
462
+ config: unknown;
463
+ artifact: StoredArtifact;
464
+ };
465
+
466
+ export class FileReportStore implements ReportStore {
467
+ readonly contentDir: string;
468
+ readonly #publicationStores: PublicationStores | undefined;
469
+
470
+ constructor(
471
+ contentDir: string = aeoContentDir,
472
+ publicationStores?: PublicationStores,
473
+ ) {
474
+ this.contentDir = contentDir;
475
+ this.#publicationStores = publicationStores;
476
+ }
477
+
478
+ #runDir(reportKey: string, runId: string): string {
479
+ for (const value of [reportKey, runId]) {
480
+ if (!/^[a-zA-Z0-9_-]+$/.test(value)) {
481
+ throw new Error(`Invalid report or run identity provided: ${value}.`);
482
+ }
483
+ }
484
+
485
+ const runsDir =
486
+ this.contentDir === aeoContentDir
487
+ ? path.join(aeoCheckpointDir, 'reports')
488
+ : path.join(this.contentDir, '.runs');
489
+
490
+ return path.join(runsDir, reportKey, runId);
491
+ }
492
+
493
+ async #readableDir(reportKey: string, runId?: string): Promise<string> {
494
+ if (runId) {
495
+ return this.#runDir(reportKey, runId);
496
+ }
497
+
498
+ try {
499
+ const publication = publishedPointerSchema.parse(
500
+ JSON.parse(
501
+ await readFile(
502
+ path.join(this.reportDir(reportKey), 'published.json'),
503
+ 'utf8',
504
+ ),
505
+ ),
506
+ );
507
+
508
+ return this.#runDir(reportKey, publication.runId);
509
+ } catch (error) {
510
+ if (!hasErrorCode(error, 'ENOENT')) {
511
+ throw error;
512
+ }
513
+
514
+ return this.reportDir(reportKey);
515
+ }
516
+ }
517
+
518
+ reportDir(reportKey: string): string {
519
+ return path.join(this.contentDir, reportKey);
520
+ }
521
+
522
+ async readArtifacts(
523
+ reportKey: string,
524
+ runId: string,
525
+ ): Promise<ReportArtifacts | null> {
526
+ try {
527
+ return validateReportArtifacts(
528
+ JSON.parse(
529
+ await readFile(
530
+ path.join(this.#runDir(reportKey, runId), 'artifacts.json'),
531
+ 'utf8',
532
+ ),
533
+ ),
534
+ reportKey,
535
+ runId,
536
+ );
537
+ } catch (error) {
538
+ if (hasErrorCode(error, 'ENOENT')) {
539
+ return null;
540
+ }
541
+
542
+ throw error;
543
+ }
544
+ }
545
+
546
+ /** readProgressArtifacts serves the server-side history projection, which
547
+ * validates its envelope and capture metadata separately so corrupt old
548
+ * provenance becomes an invalid chart point. */
549
+ async readProgressArtifacts(
550
+ reportKey: string,
551
+ runId: string,
552
+ ): Promise<unknown> {
553
+ try {
554
+ const artifacts: unknown = JSON.parse(
555
+ await readFile(
556
+ path.join(this.#runDir(reportKey, runId), 'artifacts.json'),
557
+ 'utf8',
558
+ ),
559
+ );
560
+
561
+ return artifacts;
562
+ } catch (error) {
563
+ if (hasErrorCode(error, 'ENOENT')) {
564
+ return null;
565
+ }
566
+
567
+ throw error;
568
+ }
569
+ }
570
+
571
+ async readProgressMeasurement(
572
+ reportKey: string,
573
+ runId: string,
574
+ configVersion: number,
575
+ ): Promise<ProgressMeasurement | null> {
576
+ try {
577
+ const value = storedProgressSchema.parse(
578
+ JSON.parse(
579
+ await readFile(
580
+ path.join(this.#runDir(reportKey, runId), 'progress.json'),
581
+ 'utf8',
582
+ ),
583
+ ),
584
+ );
585
+
586
+ if (
587
+ value.reportKey !== reportKey ||
588
+ value.configVersion !== configVersion
589
+ ) {
590
+ throw new StoreConflictError(
591
+ `Stored progress projection of run ${runId} belongs to another report or config.`,
592
+ );
593
+ }
594
+
595
+ return parseProgressMeasurement(value.measurement, runId);
596
+ } catch (error) {
597
+ if (hasErrorCode(error, 'ENOENT')) {
598
+ return null;
599
+ }
600
+
601
+ throw error;
602
+ }
603
+ }
604
+
605
+ async #freezeProgressMeasurement(
606
+ { reportKey, runId }: PublicationTriple,
607
+ { config, artifact }: ProgressSource,
608
+ ): Promise<void> {
609
+ const directory = this.#runDir(reportKey, runId);
610
+ const sourceDigest = contentHash({
611
+ config,
612
+ snapshot: artifact.snapshot,
613
+ captureManifest: artifact.captureManifest ?? null,
614
+ });
615
+
616
+ try {
617
+ const existing = storedProgressSchema.parse(
618
+ JSON.parse(
619
+ await readFile(path.join(directory, 'progress.json'), 'utf8'),
620
+ ),
621
+ );
622
+
623
+ parseProgressMeasurement(existing.measurement, runId);
624
+
625
+ if (
626
+ existing.reportKey !== reportKey ||
627
+ existing.configVersion !== artifact.configVersion ||
628
+ existing.sourceDigest !== sourceDigest
629
+ ) {
630
+ throw new StoreConflictError(
631
+ `Stored progress projection of run ${runId} has a different immutable source.`,
632
+ );
633
+ }
634
+
635
+ return;
636
+ } catch (error) {
637
+ if (!hasErrorCode(error, 'ENOENT')) {
638
+ throw error;
639
+ }
640
+ }
641
+
642
+ const measurement = parseProgressMeasurement(
643
+ projectProgressMeasurement({
644
+ runId,
645
+ config: aeoAuditConfigSchema.parse(config),
646
+ snapshot: aeoSnapshotSchema.parse(artifact.snapshot),
647
+ captureManifest: artifact.captureManifest,
648
+ }),
649
+ runId,
650
+ );
651
+
652
+ await writeAtomicJson(directory, 'progress.json', {
653
+ reportKey,
654
+ configVersion: artifact.configVersion,
655
+ sourceDigest,
656
+ measurement,
657
+ });
658
+ }
659
+
660
+ async readSnapshot(
661
+ reportKey: string,
662
+ runId?: string,
663
+ ): Promise<AeoSnapshot | null> {
664
+ const filePath = path.join(
665
+ await this.#readableDir(reportKey, runId),
666
+ 'snapshot.json',
667
+ );
668
+
669
+ if (!existsSync(filePath)) {
670
+ return null;
671
+ }
672
+
673
+ const snapshot = aeoSnapshotSchema.parse(
674
+ JSON.parse(await readFile(filePath, 'utf8')),
675
+ );
676
+
677
+ if (snapshot.reportKey !== reportKey) {
678
+ throw new Error(
679
+ `${filePath} belongs to report '${snapshot.reportKey}', not '${reportKey}'.`,
680
+ );
681
+ }
682
+
683
+ return snapshot;
684
+ }
685
+
686
+ async readLabels(
687
+ reportKey: string,
688
+ runId?: string,
689
+ ): Promise<DomainLabelsFile | null> {
690
+ const filePath = path.join(
691
+ await this.#readableDir(reportKey, runId),
692
+ domainLabelsFile,
693
+ );
694
+
695
+ if (!existsSync(filePath)) {
696
+ return null;
697
+ }
698
+
699
+ // An unparseable committed labels file is a defect, never a silent
700
+ // re-classification (§2.10).
701
+ const labels = domainLabelsFileSchema.parse(
702
+ JSON.parse(await readFile(filePath, 'utf8')),
703
+ );
704
+
705
+ return labels;
706
+ }
707
+
708
+ async readEvidenceChunk(
709
+ reportKey: string,
710
+ runIdOrFile: string,
711
+ requestedFile?: string,
712
+ ): Promise<AeoEvidenceChunk> {
713
+ const file = requestedFile ?? runIdOrFile;
714
+
715
+ if (!/^evidence\/[a-zA-Z0-9_-]+-\d+\.json$/.test(file)) {
716
+ throw new Error(`Invalid evidence file provided: ${file}.`);
717
+ }
718
+
719
+ const filePath = path.join(
720
+ await this.#readableDir(
721
+ reportKey,
722
+ requestedFile ? runIdOrFile : undefined,
723
+ ),
724
+ file,
725
+ );
726
+
727
+ const chunk = aeoEvidenceChunkSchema.parse(
728
+ JSON.parse(await readFile(filePath, 'utf8')),
729
+ );
730
+
731
+ return chunk;
732
+ }
733
+
734
+ /** writeReport saves an immutable run in a private directory; publication
735
+ * is explicit. */
736
+ async writeReport(
737
+ reportKey: string,
738
+ runId: string,
739
+ artifacts: ReportArtifacts,
740
+ ): Promise<void> {
741
+ validateReportArtifacts(artifacts, reportKey, runId);
742
+
743
+ if (artifacts.snapshot.reportKey !== reportKey) {
744
+ throw new StoreConflictError(
745
+ `Snapshot belongs to another report than ${reportKey}.`,
746
+ );
747
+ }
748
+
749
+ const targetDir = this.#runDir(reportKey, runId);
750
+
751
+ if (existsSync(targetDir)) {
752
+ const existing: unknown = JSON.parse(
753
+ await readFile(path.join(targetDir, 'artifacts.json'), 'utf8'),
754
+ );
755
+
756
+ if (JSON.stringify(existing) !== JSON.stringify(artifacts)) {
757
+ throw new StoreConflictError(
758
+ `Run artifacts are immutable: ${reportKey}/${runId}.`,
759
+ );
760
+ }
761
+
762
+ return;
763
+ }
764
+
765
+ await mkdir(this.contentDir, { recursive: true });
766
+
767
+ const tempDir = await mkdtemp(path.join(this.contentDir, '.tmp-'));
768
+
769
+ try {
770
+ await mkdir(path.join(tempDir, 'evidence'), { recursive: true });
771
+ await writeFile(
772
+ path.join(tempDir, 'snapshot.json'),
773
+ `${JSON.stringify(artifacts.snapshot, null, 2)}\n`,
774
+ 'utf8',
775
+ );
776
+ await writeFile(
777
+ path.join(tempDir, domainLabelsFile),
778
+ `${JSON.stringify(artifacts.labels, null, 2)}\n`,
779
+ 'utf8',
780
+ );
781
+
782
+ for (const chunk of artifacts.chunks) {
783
+ await writeFile(
784
+ path.join(
785
+ tempDir,
786
+ evidenceChunkFileName(chunk.sectionKey, chunk.promptIdx),
787
+ ),
788
+ JSON.stringify(chunk),
789
+ 'utf8',
790
+ );
791
+ }
792
+
793
+ await writeFile(
794
+ path.join(tempDir, 'artifacts.json'),
795
+ JSON.stringify(artifacts),
796
+ 'utf8',
797
+ );
798
+ await mkdir(path.dirname(targetDir), { recursive: true });
799
+ await rename(tempDir, targetDir);
800
+ } catch (error) {
801
+ await rm(tempDir, { recursive: true, force: true });
802
+
803
+ throw error;
804
+ }
805
+ }
806
+
807
+ async publish(
808
+ requested: PublicationTriple,
809
+ receipt: PublishReceipt,
810
+ ): Promise<void> {
811
+ const triple = publicationTripleSchema.parse({
812
+ reportKey: requested.reportKey,
813
+ runId: requested.runId,
814
+ configVersion: requested.configVersion,
815
+ copyVersion: requested.copyVersion,
816
+ });
817
+ const { reportKey, runId, configVersion, copyVersion } = triple;
818
+ const directory = this.reportDir(reportKey);
819
+
820
+ await withFilePublicationLock(directory, async () => {
821
+ const previous = await readFilePublication(directory, reportKey);
822
+
823
+ if (previous && sameTriple(previous, triple)) {
824
+ return;
825
+ }
826
+
827
+ const stores = this.#publicationStores ?? {
828
+ ...openFileVersionStores(),
829
+ runStore: new FileRunStore(),
830
+ };
831
+ const [storedConfig, storedCopy, storedRun] = await Promise.all([
832
+ stores.configStore.getVersion(reportKey, configVersion),
833
+ stores.copyStore.getVersion(reportKey, copyVersion),
834
+ stores.runStore.get(runId),
835
+ ]);
836
+ const storedArtifact = storedArtifactSchema.parse(
837
+ JSON.parse(
838
+ await readFile(
839
+ path.join(this.#runDir(reportKey, runId), 'artifacts.json'),
840
+ 'utf8',
841
+ ),
842
+ ),
843
+ );
844
+
845
+ const { config, artifact } = assertPublishable({
846
+ triple,
847
+ receipt,
848
+ priorPublication: previous?.history?.find((entry) =>
849
+ sameTriple(entry, triple),
850
+ ),
851
+ config: storedConfig,
852
+ copy: storedCopy,
853
+ run: storedRun,
854
+ artifact: storedArtifact,
855
+ });
856
+
857
+ const now = new Date().toISOString();
858
+
859
+ // A failed pointer commit may leave this private cache, but cannot publish it.
860
+ await this.#freezeProgressMeasurement(triple, {
861
+ config: config.config,
862
+ artifact,
863
+ });
864
+
865
+ const history = previous ? filePublicationHistory(previous, now) : [];
866
+
867
+ if (previous?.history === undefined) {
868
+ await this.#assertLegacyPublication(stores, previous);
869
+ }
870
+
871
+ if (!history.some((entry) => sameTriple(entry, triple))) {
872
+ history.push({
873
+ ...triple,
874
+ firstPublishedAt: now,
875
+ recordedAt: now,
876
+ origin: 'publication',
877
+ });
878
+ }
879
+
880
+ await writeFilePublication(directory, { ...receipt, history });
881
+ });
882
+ }
883
+
884
+ // A pointer written before history existed must still point at a valid,
885
+ // approved publication before its backfilled history is trusted.
886
+ async #assertLegacyPublication(
887
+ stores: PublicationStores,
888
+ previous: PublicationTriple | null,
889
+ ): Promise<void> {
890
+ if (!previous) {
891
+ return;
892
+ }
893
+
894
+ const { reportKey } = previous;
895
+ const [oldArtifact, oldConfig, oldCopy] = await Promise.all([
896
+ this.readArtifacts(reportKey, previous.runId),
897
+ stores.configStore.getVersion(reportKey, previous.configVersion),
898
+ stores.copyStore.getVersion(reportKey, previous.copyVersion),
899
+ ]);
900
+
901
+ if (
902
+ !oldArtifact?.fullScope ||
903
+ oldArtifact.configVersion !== previous.configVersion ||
904
+ oldConfig?.config.reportKey !== reportKey ||
905
+ oldCopy?.copy.reportKey !== reportKey ||
906
+ !['approved', 'superseded'].includes(oldConfig.status) ||
907
+ !['approved', 'superseded'].includes(oldCopy.status)
908
+ ) {
909
+ throw new StoreConflictError(
910
+ `Existing file publication of ${reportKey} cannot establish valid history.`,
911
+ );
912
+ }
913
+ }
914
+
915
+ /** rewriteReport rewrites the snapshot and labels of an existing report in
916
+ * place. */
917
+ async rewriteReport(
918
+ reportKey: string,
919
+ artifacts: Pick<ReportArtifacts, 'snapshot' | 'labels'>,
920
+ ): Promise<void> {
921
+ const dir = this.reportDir(reportKey);
922
+
923
+ // Labels first: a crash between the two writes leaves a snapshot the
924
+ // next run rebuilds from the labels, never the reverse.
925
+ await writeFile(
926
+ path.join(dir, domainLabelsFile),
927
+ `${JSON.stringify(artifacts.labels, null, 2)}\n`,
928
+ 'utf8',
929
+ );
930
+ await writeFile(
931
+ path.join(dir, 'snapshot.json'),
932
+ `${JSON.stringify(artifacts.snapshot, null, 2)}\n`,
933
+ 'utf8',
934
+ );
935
+ }
936
+
937
+ async listReportKeys(): Promise<string[]> {
938
+ if (!existsSync(this.contentDir)) {
939
+ return [];
940
+ }
941
+
942
+ const entries = await readdir(this.contentDir, { withFileTypes: true });
943
+ const reportKeys = entries
944
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))
945
+ .map((entry) => entry.name)
946
+ .sort();
947
+
948
+ return reportKeys;
949
+ }
950
+ }
951
+
952
+ // Lines are written only by this store, from typed records.
953
+ const isRunRecordLine = (row: unknown): row is RunRecord => {
954
+ return (
955
+ typeof row === 'object' &&
956
+ row !== null &&
957
+ 'runId' in row &&
958
+ typeof row.runId === 'string'
959
+ );
960
+ };
961
+
962
+ export class FileRunStore implements RunStore {
963
+ readonly #file: JsonlFile;
964
+
965
+ constructor(dir: string = aeoCheckpointDir) {
966
+ this.#file = new JsonlFile(path.join(dir, 'runs.jsonl'));
967
+ }
968
+
969
+ async start(record: RunRecord): Promise<void> {
970
+ await serializeRunFile(this.#file.filePath, async () => {
971
+ if (!(await this.get(record.runId))) {
972
+ await this.#file.append(JSON.stringify(record));
973
+ }
974
+ });
975
+ }
976
+
977
+ async claim(runId: string, claim: RunClaim): Promise<RunClaimResult> {
978
+ return serializeRunFile(this.#file.filePath, async () => {
979
+ const result = evaluateRunClaim(await this.get(runId), claim);
980
+
981
+ if (result.status === 'claimed') {
982
+ await this.#file.append(JSON.stringify(result.record));
983
+ }
984
+
985
+ return result;
986
+ });
987
+ }
988
+
989
+ async reconcile(
990
+ runId: string,
991
+ outcome: RunReconciliation,
992
+ claim: RunClaim,
993
+ ): Promise<boolean> {
994
+ return serializeRunFile(this.#file.filePath, async () => {
995
+ const record = await this.get(runId);
996
+
997
+ if (
998
+ !record ||
999
+ isTerminalRun(record) ||
1000
+ record.batchJobId !== claim.batchJobId ||
1001
+ record.batchAttempt !== claim.attempt
1002
+ ) {
1003
+ return false;
1004
+ }
1005
+
1006
+ await this.#file.append(JSON.stringify({ ...record, ...outcome }));
1007
+
1008
+ return true;
1009
+ });
1010
+ }
1011
+
1012
+ async finish(
1013
+ runId: string,
1014
+ outcome: Pick<RunRecord, 'status' | 'finishedAt' | 'partialFailures'> &
1015
+ Partial<Pick<RunRecord, 'logLocation'>>,
1016
+ ): Promise<void> {
1017
+ await serializeRunFile(this.#file.filePath, async () => {
1018
+ const existing = await this.get(runId);
1019
+
1020
+ if (!existing) {
1021
+ throw new Error(`Unknown run: ${runId}.`);
1022
+ }
1023
+
1024
+ if (isTerminalRun(existing)) {
1025
+ return;
1026
+ }
1027
+
1028
+ await this.#file.append(JSON.stringify({ ...existing, ...outcome }));
1029
+ });
1030
+ }
1031
+
1032
+ async get(runId: string): Promise<RunRecord | null> {
1033
+ let found: RunRecord | null = null;
1034
+
1035
+ for (const row of await readJsonl(this.#file.filePath)) {
1036
+ if (isRunRecordLine(row) && row.runId === runId) {
1037
+ found = row;
1038
+ }
1039
+ }
1040
+
1041
+ return found;
1042
+ }
1043
+ }
1044
+
1045
+ export const openFileStores = async (
1046
+ reportKey: string,
1047
+ opts: { checkpointDir?: string; contentDir?: string } = {},
1048
+ ): Promise<
1049
+ Stores & {
1050
+ probeStore: FileProbeStore;
1051
+ analysisStore: FileAnalysisStore;
1052
+ reportStore: FileReportStore;
1053
+ }
1054
+ > => {
1055
+ const stores = {
1056
+ probeStore: await FileProbeStore.open(reportKey, {
1057
+ dir: opts.checkpointDir,
1058
+ }),
1059
+ analysisStore: await FileAnalysisStore.open(reportKey, {
1060
+ dir: opts.checkpointDir,
1061
+ }),
1062
+ reportStore: new FileReportStore(opts.contentDir),
1063
+ runStore: new FileRunStore(opts.checkpointDir),
1064
+ };
1065
+
1066
+ return stores;
1067
+ };
1068
+
1069
+ export type { JsonlLine };