literally-aeo 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/README.md +42 -6
  2. package/dist/author-tools.js +33 -64
  3. package/dist/cli.mjs +2723 -1616
  4. package/dist/lib/agents/author-schema.js +4 -5
  5. package/dist/lib/agents/author-validation.js +5 -6
  6. package/dist/lib/agents/copy-validation.js +4 -5
  7. package/dist/lib/agents/verifier.js +8 -8
  8. package/dist/lib/analysis/domain-classifier.js +8 -8
  9. package/dist/lib/analysis/domain-labels.js +3 -4
  10. package/dist/lib/analysis/progress.js +3 -4
  11. package/dist/lib/analysis/sentiment.js +8 -8
  12. package/dist/lib/author/examples.js +5 -6
  13. package/dist/lib/bundle/contracts.js +5 -6
  14. package/dist/lib/bundle/export.js +22 -19
  15. package/dist/lib/bundle/isolation.js +17 -0
  16. package/dist/lib/bundle/journal.js +6 -7
  17. package/dist/lib/bundle/project-journal.js +11 -10
  18. package/dist/lib/bundle/project.js +19 -16
  19. package/dist/lib/bundle/read.js +23 -20
  20. package/dist/lib/bundle/recorder.js +9 -8
  21. package/dist/lib/bundle/redact.js +6 -7
  22. package/dist/lib/bundle/trace-coverage.js +6 -7
  23. package/dist/lib/bundle/verify-integrity.js +8 -9
  24. package/dist/lib/bundle/verify-measurement.js +10 -11
  25. package/dist/lib/bundle/verify-report.js +11 -12
  26. package/dist/lib/bundle/verify.js +17 -18
  27. package/dist/lib/bundle/writer-lock.js +3 -1
  28. package/dist/lib/capture-manifest.js +3 -4
  29. package/dist/lib/checks/run-checks.js +10 -9
  30. package/dist/lib/chunks/chunk-2B5QF6UQ.js +159 -0
  31. package/dist/lib/chunks/{chunk-4US3OBKJ.js → chunk-2GU6CNQI.js} +12 -7
  32. package/dist/lib/chunks/{chunk-AWOJWMPN.js → chunk-2ROXN2EC.js} +42 -7
  33. package/dist/lib/chunks/{chunk-XHWRSGX3.js → chunk-3JO5TXBA.js} +1 -1
  34. package/dist/lib/chunks/{chunk-5GZVDGTX.js → chunk-4PD65FRJ.js} +7 -3
  35. package/dist/lib/chunks/{chunk-P4K6BP3L.js → chunk-5JPYM4MD.js} +1 -1
  36. package/dist/lib/chunks/{chunk-5VNYUCLL.js → chunk-622NMXN6.js} +6 -9
  37. package/dist/lib/chunks/{chunk-4ZY6P5SO.js → chunk-663HABKP.js} +5 -5
  38. package/dist/lib/chunks/{chunk-RMFT4KKK.js → chunk-6G25V4CF.js} +1 -1
  39. package/dist/lib/chunks/{chunk-GVC4LH2N.js → chunk-6GHHNPFJ.js} +1 -1
  40. package/dist/lib/chunks/{chunk-KMRQSIZW.js → chunk-6GOBBNDU.js} +16 -1
  41. package/dist/lib/chunks/{chunk-SBAZBOPI.js → chunk-6P7EZJI7.js} +4 -2
  42. package/dist/lib/chunks/chunk-7XO3SQAX.js +117 -0
  43. package/dist/lib/chunks/{chunk-M2OD74GP.js → chunk-7Z27HQWL.js} +3 -3
  44. package/dist/lib/chunks/{chunk-IPNK7FYT.js → chunk-AYY4MYTW.js} +1 -1
  45. package/dist/lib/chunks/{chunk-WDSCJEDG.js → chunk-BE4ENGUY.js} +10 -10
  46. package/dist/lib/chunks/{chunk-FKLNEB2P.js → chunk-BGOIPHJZ.js} +39 -11
  47. package/dist/lib/chunks/{chunk-7GXRDAUY.js → chunk-BLKLPUYR.js} +2 -2
  48. package/dist/lib/chunks/chunk-BSRKN6FU.js +93 -0
  49. package/dist/lib/chunks/{chunk-PCYNBDZ7.js → chunk-CO5T6WU5.js} +14 -9
  50. package/dist/lib/chunks/{chunk-BEQLSAVX.js → chunk-CUYVHXHI.js} +2 -2
  51. package/dist/lib/chunks/{chunk-RBOO4NDG.js → chunk-D3GE3OCB.js} +1 -1
  52. package/dist/lib/chunks/chunk-DVFFYY5G.js +74 -0
  53. package/dist/lib/chunks/{chunk-5H3SNUQT.js → chunk-EBUQPCKB.js} +1 -1
  54. package/dist/lib/chunks/{chunk-4E4NDGOZ.js → chunk-EE26FNSY.js} +1 -1
  55. package/dist/lib/chunks/{chunk-AUB5THIS.js → chunk-EJ655TVU.js} +1 -1
  56. package/dist/lib/chunks/{chunk-S2AM76LT.js → chunk-F4W5YHDZ.js} +2 -2
  57. package/dist/lib/chunks/chunk-FAUFE7MI.js +31 -0
  58. package/dist/lib/chunks/{chunk-2KJZ326K.js → chunk-FOCJ7HPC.js} +7 -7
  59. package/dist/lib/chunks/{chunk-OL746E4T.js → chunk-FUAUPNRO.js} +26 -18
  60. package/dist/lib/chunks/{chunk-J6IJGYP5.js → chunk-G62E525I.js} +2 -2
  61. package/dist/lib/chunks/{chunk-2NJEWPCV.js → chunk-GDKGZQ3T.js} +2 -2
  62. package/dist/lib/chunks/{chunk-HSZ3DM74.js → chunk-GEFKDW7X.js} +15 -2
  63. package/dist/lib/chunks/{chunk-CS24IL3K.js → chunk-GESHTTSA.js} +2 -2
  64. package/dist/lib/chunks/chunk-GNMFJ2OK.js +321 -0
  65. package/dist/lib/chunks/{chunk-H3G3VTT7.js → chunk-HFRAHG5C.js} +44 -26
  66. package/dist/lib/chunks/{chunk-MHAKYFDF.js → chunk-HQG63ZKO.js} +11 -11
  67. package/dist/lib/chunks/{chunk-OORO55OM.js → chunk-HTOD4W4E.js} +21 -6
  68. package/dist/lib/chunks/{chunk-Q2PWES4B.js → chunk-I3XGRGXE.js} +1 -1
  69. package/dist/lib/chunks/{chunk-WUELMJ22.js → chunk-IE7NAL6B.js} +1 -1
  70. package/dist/lib/chunks/{chunk-KRFHQQS7.js → chunk-JXMDOAKA.js} +17 -17
  71. package/dist/lib/chunks/{chunk-S7KJZIUR.js → chunk-KJMU5KH4.js} +2 -2
  72. package/dist/lib/chunks/{chunk-2ROSV4HD.js → chunk-L7MEIRJB.js} +1 -1
  73. package/dist/lib/chunks/{chunk-CPT2GKKW.js → chunk-LOBXOZ2R.js} +1 -1
  74. package/dist/lib/chunks/{chunk-IAR6XGEW.js → chunk-ML4W6KC6.js} +1 -1
  75. package/dist/lib/chunks/{chunk-WKH6BJAZ.js → chunk-MNWO7EHC.js} +4 -4
  76. package/dist/lib/chunks/{chunk-D2LPQO6Y.js → chunk-MRL5RUP7.js} +1 -1
  77. package/dist/lib/chunks/{chunk-IEVAFDW7.js → chunk-NCXSNHXX.js} +3 -3
  78. package/dist/lib/chunks/{chunk-AKKFERA4.js → chunk-NGHAP2P5.js} +4 -4
  79. package/dist/lib/chunks/{chunk-ZLOOC46D.js → chunk-OKL7GN2F.js} +3 -3
  80. package/dist/lib/chunks/{chunk-YOZNLFSB.js → chunk-OQU5IXAJ.js} +5 -5
  81. package/dist/lib/chunks/{chunk-I7VNIW6Q.js → chunk-OU73OUX4.js} +16 -10
  82. package/dist/lib/chunks/{chunk-56VOFZ7T.js → chunk-QHUDJVPJ.js} +90 -24
  83. package/dist/lib/chunks/{chunk-WTQWU522.js → chunk-QSJ4IKUF.js} +9 -9
  84. package/dist/lib/chunks/{chunk-FBFZBLTY.js → chunk-R6XDZWUL.js} +7 -8
  85. package/dist/lib/chunks/{chunk-CJ5YD3CU.js → chunk-RJ5R6YYA.js} +5 -5
  86. package/dist/lib/chunks/{chunk-5EX5DKMA.js → chunk-RR46EDDR.js} +33 -25
  87. package/dist/lib/chunks/chunk-RYCRL3YA.js +106 -0
  88. package/dist/lib/chunks/{chunk-Z4LMDKBU.js → chunk-SHUMCKCS.js} +2 -2
  89. package/dist/lib/chunks/{chunk-3EBWDHPK.js → chunk-TJQ5OPLQ.js} +10 -12
  90. package/dist/lib/chunks/chunk-U64NCRRR.js +97 -0
  91. package/dist/lib/chunks/chunk-U772TN32.js +67 -0
  92. package/dist/lib/chunks/{chunk-YR67JG2V.js → chunk-UEMZYHYJ.js} +8 -3
  93. package/dist/lib/chunks/{chunk-J46W3EMQ.js → chunk-UZJSTJFP.js} +5 -5
  94. package/dist/lib/chunks/{chunk-XJVXASDD.js → chunk-V7OAPKNF.js} +3 -3
  95. package/dist/lib/chunks/{chunk-WE2WPNG2.js → chunk-VKM6MMA4.js} +66 -7
  96. package/dist/lib/chunks/{chunk-YWJPJI3W.js → chunk-VL253W5C.js} +3 -1
  97. package/dist/lib/chunks/{chunk-XU6WQ5UL.js → chunk-VPZQGND4.js} +3 -3
  98. package/dist/lib/chunks/{chunk-X2Y2ZNG3.js → chunk-W2VGLWTS.js} +3 -3
  99. package/dist/lib/chunks/{chunk-6AUEDSTU.js → chunk-W5DC23OP.js} +1 -1
  100. package/dist/lib/chunks/chunk-W5X7WJYL.js +91 -0
  101. package/dist/lib/chunks/{chunk-QFVRCSJ2.js → chunk-WDOA5JEH.js} +2 -0
  102. package/dist/lib/chunks/{chunk-6KO7HGCQ.js → chunk-WVACVWBL.js} +2 -2
  103. package/dist/lib/chunks/{chunk-MIF5IYNR.js → chunk-XDG6NPJB.js} +26 -29
  104. package/dist/lib/chunks/{chunk-X6E44EGV.js → chunk-XR44YSHT.js} +2 -2
  105. package/dist/lib/chunks/chunk-Y2CZ6FZY.js +61 -0
  106. package/dist/lib/chunks/{chunk-5KKLUM7M.js → chunk-YAAUWCJ4.js} +1 -1
  107. package/dist/lib/chunks/{chunk-N2ZZ6JRF.js → chunk-YRBIC5QH.js} +1 -1
  108. package/dist/lib/chunks/chunk-ZIGNJAPC.js +11 -0
  109. package/dist/lib/cli/bundle-commands.js +71 -65
  110. package/dist/lib/cli/guide-command.js +25 -0
  111. package/dist/lib/cli/io.js +1 -1
  112. package/dist/lib/cli/run-commands.js +270 -104
  113. package/dist/lib/cli/status-command.js +234 -0
  114. package/dist/lib/codex-workflow/aggregate.js +8 -9
  115. package/dist/lib/codex-workflow/author-tools.js +6 -7
  116. package/dist/lib/codex-workflow/author.js +17 -17
  117. package/dist/lib/codex-workflow/capture.js +10 -9
  118. package/dist/lib/codex-workflow/checkpoint.js +6 -7
  119. package/dist/lib/codex-workflow/checks.js +6 -7
  120. package/dist/lib/codex-workflow/codex-binary.js +13 -0
  121. package/dist/lib/codex-workflow/codex-home.js +6 -3
  122. package/dist/lib/codex-workflow/copy-editor.js +14 -14
  123. package/dist/lib/codex-workflow/copy-recovery.js +3 -4
  124. package/dist/lib/codex-workflow/copy.js +11 -11
  125. package/dist/lib/codex-workflow/finish.js +17 -18
  126. package/dist/lib/codex-workflow/host-models.js +7 -7
  127. package/dist/lib/codex-workflow/loop.js +42 -38
  128. package/dist/lib/codex-workflow/quality.js +3 -4
  129. package/dist/lib/codex-workflow/run-inputs.js +5 -6
  130. package/dist/lib/codex-workflow/run-source.js +14 -13
  131. package/dist/lib/codex-workflow/schemas.js +5 -6
  132. package/dist/lib/codex-workflow/session.js +7 -8
  133. package/dist/lib/codex-workflow/stage.js +26 -23
  134. package/dist/lib/codex-workflow/workdir.js +6 -7
  135. package/dist/lib/engine/audit-file.js +7 -6
  136. package/dist/lib/engine/author.js +37 -31
  137. package/dist/lib/engine/budget.js +7 -1
  138. package/dist/lib/engine/cost-estimate.js +41 -0
  139. package/dist/lib/engine/local-run.js +48 -42
  140. package/dist/lib/engine/preflight.js +10 -6
  141. package/dist/lib/engine/rejudge.js +56 -50
  142. package/dist/lib/engine/resources.js +1 -1
  143. package/dist/lib/engine/run-configuration.js +2 -1
  144. package/dist/lib/engine/run-status.js +151 -0
  145. package/dist/lib/engine/templates.js +8 -7
  146. package/dist/lib/grounding/controller.js +7 -7
  147. package/dist/lib/grounding/extract.js +6 -6
  148. package/dist/lib/grounding/grounding-runtime.js +18 -17
  149. package/dist/lib/grounding/model.js +5 -5
  150. package/dist/lib/grounding/recorded-tools.js +10 -9
  151. package/dist/lib/harness/report/artifacts.js +4 -5
  152. package/dist/lib/lib/checkpoint.js +3 -4
  153. package/dist/lib/models/batching.js +5 -5
  154. package/dist/lib/models/cost-coefficients.js +20 -0
  155. package/dist/lib/models/local-profile.js +10 -0
  156. package/dist/lib/models/pricing.js +6 -0
  157. package/dist/lib/models/profiles.js +7 -14
  158. package/dist/lib/models/structured-images.js +1 -1
  159. package/dist/lib/models/structured.js +4 -4
  160. package/dist/lib/models/supported-models.js +20 -0
  161. package/dist/lib/pipeline.js +9 -8
  162. package/dist/lib/probes/agent-cli-parsers.js +1 -1
  163. package/dist/lib/probes/agent-clis.js +6 -5
  164. package/dist/lib/probes/charged-trace.js +10 -0
  165. package/dist/lib/probes/probes.js +6 -6
  166. package/dist/lib/runner.js +10 -10
  167. package/dist/lib/schema.js +3 -4
  168. package/dist/lib/section-result.js +3 -4
  169. package/dist/lib/stores/artifacts.js +3 -4
  170. package/dist/lib/stores/files.js +9 -9
  171. package/dist/lib/stores/local-versions.js +4 -5
  172. package/dist/lib/stores/memory.js +6 -7
  173. package/dist/lib/stores/publication.js +5 -6
  174. package/dist/lib/viewer/server.js +18 -19
  175. package/dist/lib/workflow/schema.js +2 -3
  176. package/dist/types/agents/copy-validation.d.ts +4 -4
  177. package/dist/types/agents/verifier.d.ts +6 -6
  178. package/dist/types/bundle/contracts.d.ts +1 -1
  179. package/dist/types/bundle/isolation.d.ts +37 -0
  180. package/dist/types/bundle/project-journal.d.ts +2 -0
  181. package/dist/types/bundle/recorder.d.ts +4 -0
  182. package/dist/types/bundle/writer-lock.d.ts +9 -0
  183. package/dist/types/cli/guide-command.d.ts +4 -0
  184. package/dist/types/cli/status-command.d.ts +2 -0
  185. package/dist/types/codex-workflow/codex-binary.d.ts +26 -0
  186. package/dist/types/codex-workflow/codex-home.d.ts +24 -20
  187. package/dist/types/codex-workflow/copy-editor.d.ts +1 -1
  188. package/dist/types/codex-workflow/copy.d.ts +3 -4
  189. package/dist/types/codex-workflow/finish.d.ts +5 -3
  190. package/dist/types/codex-workflow/host-models.d.ts +7 -3
  191. package/dist/types/codex-workflow/loop.d.ts +10 -1
  192. package/dist/types/codex-workflow/run-inputs.d.ts +28 -113
  193. package/dist/types/codex-workflow/stage.d.ts +16 -5
  194. package/dist/types/engine/audit-file.d.ts +3 -2
  195. package/dist/types/engine/author.d.ts +7 -1
  196. package/dist/types/engine/budget.d.ts +46 -15
  197. package/dist/types/engine/cost-estimate.d.ts +40 -0
  198. package/dist/types/engine/local-run.d.ts +6 -0
  199. package/dist/types/engine/preflight.d.ts +5 -0
  200. package/dist/types/engine/resources.d.ts +2 -0
  201. package/dist/types/engine/run-configuration.d.ts +4 -3
  202. package/dist/types/engine/run-status.d.ts +75 -0
  203. package/dist/types/engine/templates.d.ts +1 -2
  204. package/dist/types/models/cost-coefficients.d.ts +106 -0
  205. package/dist/types/models/local-profile.d.ts +12 -0
  206. package/dist/types/models/pricing.d.ts +8 -0
  207. package/dist/types/models/profiles.d.ts +55 -160
  208. package/dist/types/models/served-model.d.ts +2 -3
  209. package/dist/types/models/structured.d.ts +3 -3
  210. package/dist/types/models/supported-models.d.ts +48 -0
  211. package/dist/types/probes/charged-trace.d.ts +8 -0
  212. package/dist/types/probes/probe-trace.d.ts +2 -0
  213. package/dist/types/schema.d.ts +28 -113
  214. package/dist/types/workflow/schema.d.ts +79 -152
  215. package/package.json +2 -1
  216. package/resources/guide/OPERATOR.md +180 -0
  217. package/src/agents/copy-validation.ts +8 -12
  218. package/src/agents/verifier.ts +10 -14
  219. package/src/bundle/contracts.ts +3 -3
  220. package/src/bundle/isolation.ts +157 -0
  221. package/src/bundle/project-journal.ts +4 -0
  222. package/src/bundle/project.ts +20 -7
  223. package/src/bundle/recorder.ts +5 -0
  224. package/src/bundle/writer-lock.ts +27 -0
  225. package/src/cli/guide-command.ts +28 -0
  226. package/src/cli/io.ts +2 -0
  227. package/src/cli/literally-aeo.ts +39 -19
  228. package/src/cli/run-commands.ts +236 -18
  229. package/src/cli/status-command.ts +113 -0
  230. package/src/codex-workflow/codex-binary.ts +105 -0
  231. package/src/codex-workflow/codex-home.ts +50 -40
  232. package/src/codex-workflow/copy.ts +7 -10
  233. package/src/codex-workflow/finish.ts +13 -8
  234. package/src/codex-workflow/host-models.ts +33 -24
  235. package/src/codex-workflow/loop.ts +36 -9
  236. package/src/codex-workflow/stage.ts +126 -17
  237. package/src/engine/audit-file.ts +10 -8
  238. package/src/engine/author.ts +47 -2
  239. package/src/engine/budget.ts +138 -43
  240. package/src/engine/cost-estimate.ts +178 -0
  241. package/src/engine/guide/OPERATOR.md +180 -0
  242. package/src/engine/local-run.ts +38 -8
  243. package/src/engine/preflight.ts +90 -7
  244. package/src/engine/resources.ts +9 -4
  245. package/src/engine/run-configuration.ts +19 -1
  246. package/src/engine/run-status.ts +452 -0
  247. package/src/engine/templates.ts +5 -2
  248. package/src/models/cost-coefficients.ts +140 -0
  249. package/src/models/local-profile.ts +150 -0
  250. package/src/models/pricing.ts +31 -0
  251. package/src/models/profiles.ts +58 -419
  252. package/src/models/served-model.ts +2 -3
  253. package/src/models/structured-images.ts +5 -4
  254. package/src/models/structured.ts +20 -7
  255. package/src/models/supported-models.ts +112 -0
  256. package/src/probes/agent-clis.ts +24 -2
  257. package/src/probes/charged-trace.ts +87 -0
  258. package/src/probes/probe-trace.ts +2 -0
  259. package/src/probes/probes.ts +48 -2
  260. package/dist/lib/chunks/chunk-CFFPOTP4.js +0 -356
  261. package/dist/lib/chunks/chunk-LIZX4N3H.js +0 -110
  262. package/dist/lib/chunks/chunk-OYKV5NDM.js +0 -28
@@ -0,0 +1,105 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { readFileSync } from 'node:fs';
3
+ import { createRequire } from 'node:module';
4
+ import path from 'node:path';
5
+ import { promisify } from 'node:util';
6
+ import { z } from 'zod';
7
+ import { getEnvironment } from '../lib/env';
8
+
9
+ // ============================================================================
10
+ // The Codex binary (specs/aeo-claude-operator-spec.md §4.3). The stage
11
+ // runtime is part of the method, so it is a pinned dependency of this
12
+ // package, never whatever `codex` happens to be on PATH. AEO_CODEX_BIN
13
+ // points elsewhere for a maintainer; every Codex session records which
14
+ // binary it ran, and its version when that is known without running it.
15
+ // ============================================================================
16
+
17
+ export type CodexBinarySource = 'dependency' | 'AEO_CODEX_BIN';
18
+
19
+ export type CodexBinary = {
20
+ /** What to spawn, and the arguments that come before Codex's own. */
21
+ command: string;
22
+ prefixArgs: readonly string[];
23
+ /** The file that was resolved, for doctor and the run record. */
24
+ path: string;
25
+ source: CodexBinarySource;
26
+ /** The installed dependency's version, from its manifest; null for a
27
+ * binary named from outside, whose version only running it can tell. */
28
+ version: string | null;
29
+ };
30
+
31
+ const codexManifestSchema = z.object({
32
+ version: z.string().min(1),
33
+ bin: z.object({ codex: z.string().min(1) }),
34
+ });
35
+
36
+ /**
37
+ * resolveCodexBinary returns the Codex the stages run: AEO_CODEX_BIN when
38
+ * set, else this package's own dependency, started with the running Node so
39
+ * no file mode or PATH entry is involved.
40
+ */
41
+ export const resolveCodexBinary = (
42
+ env: Record<string, string | undefined> = getEnvironment(),
43
+ ): CodexBinary => {
44
+ const override = env.AEO_CODEX_BIN;
45
+
46
+ if (override !== undefined && override !== '') {
47
+ return codexBinaryAt(override);
48
+ }
49
+
50
+ const require = createRequire(import.meta.url);
51
+ const manifestFile = require.resolve('@openai/codex/package.json');
52
+ const manifest = codexManifestSchema.parse(
53
+ JSON.parse(readFileSync(manifestFile, 'utf8')),
54
+ );
55
+ const script = path.join(path.dirname(manifestFile), manifest.bin.codex);
56
+
57
+ const binary: CodexBinary = {
58
+ command: process.execPath,
59
+ prefixArgs: [script],
60
+ path: script,
61
+ source: 'dependency',
62
+ version: manifest.version,
63
+ };
64
+
65
+ return binary;
66
+ };
67
+
68
+ /** codexBinaryAt names a Codex executable directly, for a host or a test
69
+ * that supplies its own, as AEO_CODEX_BIN does. */
70
+ export const codexBinaryAt = (command: string): CodexBinary => {
71
+ return {
72
+ command,
73
+ prefixArgs: [],
74
+ path: command,
75
+ source: 'AEO_CODEX_BIN',
76
+ version: null,
77
+ };
78
+ };
79
+
80
+ /** codexArgs puts the binary's own prefix in front of Codex's arguments. */
81
+ export const codexArgs = (
82
+ binary: CodexBinary,
83
+ args: readonly string[],
84
+ ): string[] => {
85
+ return [...binary.prefixArgs, ...args];
86
+ };
87
+
88
+ /** The version the binary reports (`codex-cli 0.150.1`), or null when it
89
+ * cannot be started. */
90
+ export const codexBinaryVersion = async (
91
+ binary: CodexBinary = resolveCodexBinary(),
92
+ ): Promise<string | null> => {
93
+ try {
94
+ const { stdout } = await promisify(execFile)(
95
+ binary.command,
96
+ codexArgs(binary, ['--version']),
97
+ { timeout: 15_000 },
98
+ );
99
+ const [firstLine] = stdout.trim().split('\n');
100
+
101
+ return firstLine === undefined || firstLine === '' ? null : firstLine;
102
+ } catch {
103
+ return null;
104
+ }
105
+ };
@@ -1,23 +1,22 @@
1
- import { execFile } from 'node:child_process';
2
1
  import { mkdir, writeFile } from 'node:fs/promises';
3
2
  import path from 'node:path';
4
- import { promisify } from 'node:util';
5
3
  import { getEnvironment } from '../lib/env';
4
+ import type { CodexStageModel } from '../models/profiles';
5
+ import {
6
+ codexBinaryVersion,
7
+ resolveCodexBinary,
8
+ type CodexBinary,
9
+ } from './codex-binary';
6
10
 
7
11
  // ============================================================================
8
12
  // An isolated Codex home per work directory (specs/aeo-codex-workflow-spec.md
9
13
  // §7). Codex reads its configuration, auth and state from CODEX_HOME; giving
10
14
  // every run its own, written by the host, means a stage can never inherit the
11
- // operator's global model, service tier, MCP servers or login. The first
12
- // three local loops ran on the operator's default (GPT-6 Astra at xhigh on
13
- // the priority tier) for exactly that reason.
15
+ // operator's global model, service tier, MCP servers or login.
14
16
  // ============================================================================
15
17
 
16
- /** The one model the workflow's stages run on: DeepSeek V4.1 Flash through
17
- * the Vercel AI Gateway, at the highest effort the family takes (the same
18
- * pin `src/models/profiles.ts` uses for the DeepSeek bulk roles). Part of
19
- * every stage's inputs digest. */
20
- export const codexModel = {
18
+ /** The gateway the Codex stages reach their model through. */
19
+ export const codexGateway = {
21
20
  provider: 'vercel',
22
21
  providerName: 'Vercel AI Gateway',
23
22
  baseUrl: 'https://ai-gateway.vercel.sh/v1',
@@ -25,16 +24,27 @@ export const codexModel = {
25
24
  * secret the child process sees. */
26
25
  apiKeyEnv: 'AI_GATEWAY_API_KEY',
27
26
  wireApi: 'responses',
28
- model: 'deepseek/deepseek-v4.1-flash',
29
- reasoningEffort: 'high',
30
- /** The model's context window as the gateway reports it (`/v1/models`,
31
- * 2026-09-13). Codex has no metadata for gateway models and otherwise
32
- * falls back to a default window, which decides when it compacts the
33
- * session history; a qualify or review batch that read ten answers and
34
- * their rows would be compacted for no reason. */
35
- contextWindow: 1_000_000,
36
27
  } as const;
37
28
 
29
+ /** Everything a stage's Codex configuration says about its model, in a
30
+ * fixed key order: part of every stage's inputs digest and session
31
+ * contract, so a resume reruns a batch only when the model changed. */
32
+ export type CodexStageConfig = typeof codexGateway &
33
+ Pick<CodexStageModel, 'model' | 'reasoningEffort' | 'contextWindow'>;
34
+
35
+ export const codexStageConfig = (
36
+ stageModel: CodexStageModel,
37
+ ): CodexStageConfig => {
38
+ const config: CodexStageConfig = {
39
+ ...codexGateway,
40
+ model: stageModel.model,
41
+ reasoningEffort: stageModel.reasoningEffort,
42
+ contextWindow: stageModel.contextWindow,
43
+ };
44
+
45
+ return config;
46
+ };
47
+
38
48
  export const codexHomeDir = (workdir: string): string => {
39
49
  return path.join(workdir, '.codex-home');
40
50
  };
@@ -57,10 +67,16 @@ const tomlString = (value: string): string => {
57
67
  * directory is the only writable root: a session must not touch /tmp (an
58
68
  * empty /tmp/.git appeared during a run, 2026-09-13), unless the work
59
69
  * directory itself lives there, as it does in the container. */
70
+ type CodexConfigOptions = {
71
+ stageModel: CodexStageModel;
72
+ research?: ResearchServerConfig;
73
+ };
74
+
60
75
  export const codexConfigToml = (
61
76
  workdir: string,
62
- research?: ResearchServerConfig,
77
+ { stageModel, research }: CodexConfigOptions,
63
78
  ): string => {
79
+ const codexModel = codexStageConfig(stageModel);
64
80
  const underTmp = workdir === '/tmp' || workdir.startsWith('/tmp/');
65
81
 
66
82
  return [
@@ -126,16 +142,19 @@ export const codexConfigToml = (
126
142
 
127
143
  /** Write the isolated home and return the environment a stage runs with:
128
144
  * the path, the home, and the gateway key. Nothing else from the host. */
145
+ type PrepareCodexHomeOptions = CodexConfigOptions & {
146
+ env?: Record<string, string | undefined>;
147
+ };
148
+
129
149
  export const prepareCodexHome = async (
130
150
  workdir: string,
131
- env: Record<string, string | undefined> = getEnvironment(),
132
- research?: ResearchServerConfig,
151
+ { stageModel, research, env = getEnvironment() }: PrepareCodexHomeOptions,
133
152
  ): Promise<Record<string, string>> => {
134
- const apiKey = env[codexModel.apiKeyEnv];
153
+ const apiKey = env[codexGateway.apiKeyEnv];
135
154
 
136
155
  if (!apiKey) {
137
156
  throw new Error(
138
- `${codexModel.apiKeyEnv} is not set; the Codex stages run on ${codexModel.model} through the gateway and need it.`,
157
+ `${codexGateway.apiKeyEnv} is not set; the Codex stages run on ${stageModel.model} through the gateway and need it.`,
139
158
  );
140
159
  }
141
160
 
@@ -147,7 +166,7 @@ export const prepareCodexHome = async (
147
166
  await writeFile(path.join(workdir, '.aeo-report-root'), '');
148
167
  await writeFile(
149
168
  path.join(home, 'config.toml'),
150
- codexConfigToml(workdir, research),
169
+ codexConfigToml(workdir, { stageModel, research }),
151
170
  );
152
171
 
153
172
  return {
@@ -155,27 +174,18 @@ export const prepareCodexHome = async (
155
174
  HOME: home,
156
175
  CODEX_HOME: home,
157
176
  TMPDIR: temporaryDirectory,
158
- [codexModel.apiKeyEnv]: apiKey,
177
+ [codexGateway.apiKeyEnv]: apiKey,
159
178
  };
160
179
  };
161
180
 
162
- /** The version of the Codex binary the stages spawn, or null when it is not
163
- * on PATH. This is the binary itself, not a probe worker's login: the
164
- * stages and the author run it from the host process with an isolated home
165
- * and the gateway key, so no agent credential is involved. */
181
+ /** The version of the Codex binary the stages spawn, or null when it
182
+ cannot be started. The stages and the author run it from the host process
183
+ with an isolated home and the gateway key, so no agent credential is
184
+ involved. */
166
185
  export const codexCliVersion = async (
167
- command = 'codex',
186
+ binary: CodexBinary = resolveCodexBinary(),
168
187
  ): Promise<string | null> => {
169
- try {
170
- const { stdout } = await promisify(execFile)(command, ['--version'], {
171
- timeout: 15_000,
172
- });
173
- const [firstLine] = stdout.trim().split('\n');
174
-
175
- return firstLine === undefined || firstLine === '' ? null : firstLine;
176
- } catch {
177
- return null;
178
- }
188
+ return codexBinaryVersion(binary);
179
189
  };
180
190
 
181
191
  /** The values the work directory's journals must never carry: the store
@@ -21,13 +21,13 @@ import type { ModelCallAccounting } from '../models/accounting';
21
21
  import type { InternalModelRoleConfig } from '../models/profiles';
22
22
  import { engineResources } from '../engine/resources';
23
23
  import { getEnvironment } from '../lib/env';
24
- import { copyVerifierProfile, hostModels } from './host-models';
24
+ import { hostStepAccounting } from './host-models';
25
25
 
26
26
  // ============================================================================
27
27
  // The copy stage's host half (specs/aeo-codex-workflow-spec.md §4, §6):
28
28
  // the writer's documents built from the finished snapshot by the existing
29
29
  // copywriter input projection, and the draft held to the existing copy
30
- // validation, premise verifier included, on the DeepSeek role.
30
+ // validation, premise verifier included, on the run's pinned role.
31
31
  // ============================================================================
32
32
 
33
33
  export const copyDir = 'COPY';
@@ -143,7 +143,7 @@ export const materializeCopyInputs = async (args: {
143
143
  };
144
144
 
145
145
  /** The host's verdict on a draft: schema, facts, banlist, premises, and
146
- * the premise verifier on the DeepSeek role. `invalid_copy` is the only
146
+ * the premise verifier on the run's pinned role. `invalid_copy` is the only
147
147
  * outcome that requires a verifier edit; operational failures retain the draft. */
148
148
  export const validateCopyDraft = async (args: {
149
149
  draft: unknown;
@@ -155,9 +155,8 @@ export const validateCopyDraft = async (args: {
155
155
  secrets: readonly string[];
156
156
  /** The premise verifier role the run pinned: the publication gate
157
157
  * re-checks the receipt against exactly that role, so the draft must be
158
- * verified by it. Absent (a local run), the DeepSeek-only profile's
159
- * role. */
160
- verifierRole?: InternalModelRoleConfig;
158
+ * verified by it. */
159
+ verifierRole: InternalModelRoleConfig;
161
160
  /** A rewrite pass keeps what the reviewer did not question: the logo
162
161
  * and eyebrow of the draft they saw. */
163
162
  previous?: AeoReportCopy | null;
@@ -169,10 +168,8 @@ export const validateCopyDraft = async (args: {
169
168
  verifierMemory?: VerifierMemory;
170
169
  signal?: AbortSignal;
171
170
  }): Promise<CopyValidationResult> => {
172
- const models = hostModels(copyVerifierProfile);
173
- const verifierProfile =
174
- args.verifierRole ?? models.profile.roles.premiseVerifier;
175
- const accounting = args.accounting ?? models.accounting;
171
+ const verifierProfile = args.verifierRole;
172
+ const accounting = args.accounting ?? hostStepAccounting();
176
173
 
177
174
  return validateAgentCopy({
178
175
  draft: args.draft,
@@ -40,18 +40,19 @@ import { StoreConflictError } from '../stores/versions';
40
40
  import type { ModelCallAccounting } from '../models/accounting';
41
41
  import type { InternalModelContext } from '../models/context';
42
42
  import { parseAggregateOutput, type AggregateOutput } from './aggregate';
43
- import { codexModel } from './codex-home';
44
43
  import { stageVersions, workflowVersion } from './schemas';
45
- import { hostModels } from './host-models';
44
+ import { hostModels, pinnedProfileOf } from './host-models';
46
45
  import type { RunSource } from './run-source';
47
46
  import type { ReportQuality } from './quality';
48
47
 
49
48
  /** The snapshot's analyzer provenance: the Codex analyze stage under the
50
49
  * workflow version, in a number space of its own (the retired in-process
51
- * analyzer counted 1 to 8), and the pinned stage model. */
52
- export const codexAnalyzer = {
53
- version: workflowVersion * 100 + stageVersions.analyze,
54
- model: codexModel.model,
50
+ * analyzer counted 1 to 8), and the run's stage model. */
51
+ export const codexAnalyzer = (model: string) => {
52
+ return {
53
+ version: workflowVersion * 100 + stageVersions.analyze,
54
+ model,
55
+ };
55
56
  };
56
57
 
57
58
  // ============================================================================
@@ -95,6 +96,8 @@ export const finishRun = async (args: {
95
96
  /** Files excluded by degraded batches, recorded as partial failures. */
96
97
  degraded: readonly string[];
97
98
  write: boolean;
99
+ /** The model ID the Codex stages ran on, the analyzer's provenance. */
100
+ stageModelId: string;
98
101
  /** Factual grounding over the run's manifest (the container job); a
99
102
  * source that already carries a bundle needs none. */
100
103
  ground?: GroundRun;
@@ -161,7 +164,9 @@ export const finishRun = async (args: {
161
164
  })),
162
165
  ];
163
166
 
164
- const internalModels = args.internalModels ?? hostModels();
167
+ const internalModels =
168
+ args.internalModels ??
169
+ hostModels(pinnedProfileOf(source.request.modelProfile));
165
170
  const logContext = {
166
171
  reportKey: config.reportKey,
167
172
  runId: request.runId,
@@ -247,7 +252,7 @@ export const finishRun = async (args: {
247
252
  ),
248
253
  partialFailures,
249
254
  generatedAt: createdAt,
250
- analyzer: codexAnalyzer,
255
+ analyzer: codexAnalyzer(args.stageModelId),
251
256
  });
252
257
 
253
258
  const snapshotFile = path.join(dir, 'OUT', 'snapshot.json');
@@ -1,35 +1,44 @@
1
- import { createMemoryModelAccounting } from '../models/accounting';
2
- import type { InternalModelContext } from '../models/context';
3
1
  import {
4
- codexRunnerProfile,
5
- configuredModelProfileId,
6
- resolveInternalModelProfile,
7
- type InternalModelProfileId,
8
- } from '../models/profiles';
2
+ createMemoryModelAccounting,
3
+ type ModelCallAccounting,
4
+ } from '../models/accounting';
5
+ import type { InternalModelContext } from '../models/context';
6
+ import type { InternalModelProfile } from '../models/profiles';
9
7
 
10
8
  // ============================================================================
11
9
  // The host's own model calls in the Codex workflow (perception, source
12
- // labels, the copy premise verifier) run under a small memory budget per
13
- // step; there is no run ledger here. The premise verifier follows the role
14
- // the run pinned at admission, because the publication gate re-checks the
15
- // copy receipt against that role; a local run has no pin and falls back to
16
- // the DeepSeek-only profile's verifier. Every admission pins
17
- // `deepseek-harness-v1` (policy.ts) so no judgment role resolves to a
18
- // premium model (Andrei, 2026-09-13).
10
+ // labels, the copy premise verifier) when the caller supplies no ledger: a
11
+ // small memory budget per step, on the profile the run pinned. A local run
12
+ // always supplies its ledger; this is the fallback for a host that does
13
+ // not.
19
14
  // ============================================================================
20
15
 
21
16
  export const hostStepMaxUsd = 5;
22
- export const copyVerifierProfile: InternalModelProfileId = codexRunnerProfile;
17
+
18
+ /** A fresh memory budget for one host step. */
19
+ export const hostStepAccounting = (): ModelCallAccounting => {
20
+ return createMemoryModelAccounting({
21
+ maxUsd: hostStepMaxUsd,
22
+ maxTokens: 5_000_000,
23
+ deadlineAt: new Date(Date.now() + 30 * 60_000).toISOString(),
24
+ });
25
+ };
23
26
 
24
27
  export const hostModels = (
25
- profileId: InternalModelProfileId = configuredModelProfileId(),
28
+ profile: InternalModelProfile,
26
29
  ): InternalModelContext => {
27
- return {
28
- profile: resolveInternalModelProfile(profileId),
29
- accounting: createMemoryModelAccounting({
30
- maxUsd: hostStepMaxUsd,
31
- maxTokens: 5_000_000,
32
- deadlineAt: new Date(Date.now() + 30 * 60_000).toISOString(),
33
- }),
34
- };
30
+ return { profile, accounting: hostStepAccounting() };
31
+ };
32
+
33
+ /** The profile a run pinned; a run without one cannot call a model. */
34
+ export const pinnedProfileOf = (
35
+ profile: InternalModelProfile | undefined,
36
+ ): InternalModelProfile => {
37
+ if (!profile) {
38
+ throw new Error(
39
+ 'The run request pins no model profile; the host model steps need one.',
40
+ );
41
+ }
42
+
43
+ return profile;
35
44
  };
@@ -18,14 +18,19 @@ import { capturePlan } from '../capture-manifest';
18
18
  import type { GroundingBundle } from '../grounding/schema';
19
19
  import { aeoReportCopySchema, type AeoReportCopy } from '../agents/copy-schema';
20
20
  import { aeoSnapshotSchema, type AeoAuditConfig } from '../schema';
21
- import type { InternalModelRoleConfig } from '../models/profiles';
21
+ import type {
22
+ CodexStageModel,
23
+ InternalModelRoleConfig,
24
+ } from '../models/profiles';
22
25
  import type { InternalModelContext } from '../models/context';
23
- import { ModelBudgetError } from '../models/accounting';
26
+ import {
27
+ ModelBudgetError,
28
+ type ModelCallAccounting,
29
+ } from '../models/accounting';
24
30
  import { GroundingIntegrityError } from '../grounding/validation';
25
31
  import { structuredFailureDiagnostic } from '../models/failure-diagnostics';
26
32
  import { isObject } from '../lib/type-guards';
27
33
  import { aggregateWorkdir, type AggregateInputs } from './aggregate';
28
- import { codexModel } from './codex-home';
29
34
  import { CopyVerificationUnavailableError } from './copy-recovery';
30
35
  import { copyEditHistory, editCopyDraft, readCopyEdits } from './copy-editor';
31
36
  import { validateStage } from './checks';
@@ -41,7 +46,7 @@ import {
41
46
  type FinishResult,
42
47
  type GroundRun,
43
48
  } from './finish';
44
- import { hostModels } from './host-models';
49
+ import { hostModels, pinnedProfileOf } from './host-models';
45
50
  import type { StageName } from './schemas';
46
51
  import type { RunSource } from './run-source';
47
52
  import {
@@ -93,13 +98,14 @@ export type WorkflowContext = StageContext & {
93
98
  * or a fresh memory budget, recorded either way when the run records (the
94
99
  * pinned one is wrapped once, by prepareWorkdir). */
95
100
  const hostModelsOf = (
96
- ctx: Pick<WorkflowContext, 'internalModels' | 'recorder'>,
101
+ ctx: Pick<WorkflowContext, 'internalModels' | 'recorder'> &
102
+ Partial<Pick<WorkflowContext, 'source'>>,
97
103
  ): InternalModelContext => {
98
104
  if (ctx.internalModels) {
99
105
  return ctx.internalModels;
100
106
  }
101
107
 
102
- const models = hostModels();
108
+ const models = hostModels(pinnedProfileOf(ctx.source?.request.modelProfile));
103
109
 
104
110
  return ctx.recorder
105
111
  ? {
@@ -179,6 +185,14 @@ export const prepareWorkdir = async (
179
185
  * it recorded the capture before the workflow (a local run). Its
180
186
  * internalModels must already charge through that journal. */
181
187
  held?: { writer: WriterLock; recorder: ExecutionRecorder };
188
+ /** The Codex stages' model for a run whose pinned profile carries none
189
+ * (one pinned before profiles did). A profile's own always wins. */
190
+ stageModel?: CodexStageModel;
191
+ /** The run's ledger, unwrapped: every Codex session is reserved and
192
+ * settled on it beside the host's model calls (specs/aeo-claude-
193
+ * operator-spec.md §4.2). A session is a codex_session operation of
194
+ * its own, so it never goes through the recording wrapper. */
195
+ ledger?: ModelCallAccounting;
182
196
  } = {},
183
197
  ): Promise<WorkflowContext> => {
184
198
  if (options.held) {
@@ -246,6 +260,14 @@ const prepareLockedWorkdir = async (
246
260
  ),
247
261
  };
248
262
 
263
+ const stageModel = source.request.modelProfile?.stages ?? options.stageModel;
264
+
265
+ if (!stageModel) {
266
+ throw new Error(
267
+ 'The run pins no Codex stage model: its profile has no `stages` and the caller supplied none.',
268
+ );
269
+ }
270
+
249
271
  const log =
250
272
  options.log ??
251
273
  ((line: string) => {
@@ -274,6 +296,8 @@ const prepareLockedWorkdir = async (
274
296
  source,
275
297
  secrets: options.secrets ?? [],
276
298
  internalModels,
299
+ stageModel,
300
+ ...(options.ledger && { accounting: options.ledger }),
277
301
  recorder,
278
302
  releaseWriter: writer.release,
279
303
  signal: options.signal,
@@ -504,6 +528,7 @@ export const finish = async (
504
528
  degraded,
505
529
  write,
506
530
  ground,
531
+ stageModelId: ctx.stageModel.model,
507
532
  internalModels: hostModelsOf(ctx),
508
533
  signal: ctx.signal,
509
534
  quality,
@@ -605,7 +630,7 @@ export const runOne = async (
605
630
  const previous = recordedRunSchema.parse(JSON.parse(raw));
606
631
  const run: StageRun = {
607
632
  stage,
608
- model: codexModel.model,
633
+ model: ctx.stageModel.model,
609
634
  ok: true,
610
635
  durationMs: 0,
611
636
  usage: null,
@@ -657,6 +682,8 @@ export const deliverableCopy = async (
657
682
  draft,
658
683
  snapshot: await readSnapshot(ctx.dir),
659
684
  secrets: ctx.secrets,
685
+ verifierRole:
686
+ inputs.verifierRole ?? hostModelsOf(ctx).profile.roles.premiseVerifier,
660
687
  accounting: ctx.internalModels?.accounting,
661
688
  });
662
689
 
@@ -756,7 +783,7 @@ export const writeReportCopy = async (
756
783
  );
757
784
  run = {
758
785
  stage: 'write',
759
- model: codexModel.model,
786
+ model: ctx.stageModel.model,
760
787
  ok: false,
761
788
  durationMs: 0,
762
789
  usage: null,
@@ -856,7 +883,7 @@ class Scorecard {
856
883
  version: 1,
857
884
  startedAt: this.#startedAt,
858
885
  finishedAt: new Date().toISOString(),
859
- model: codexModel.model,
886
+ model: this.#ctx.stageModel.model,
860
887
  answers: this.#ctx.answers.length,
861
888
  verdict,
862
889
  stages: this.#stages,