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.
- package/LICENSE +21 -0
- package/README.md +73 -2
- package/dist/author-tools.js +3031 -0
- package/dist/cli.mjs +25536 -0
- package/dist/lib/access/schema.js +24 -0
- package/dist/lib/agents/author-schema.js +28 -0
- package/dist/lib/agents/author-validation.js +46 -0
- package/dist/lib/agents/copy-schema.js +30 -0
- package/dist/lib/agents/copy-validation.js +62 -0
- package/dist/lib/agents/copywriter-input.js +31 -0
- package/dist/lib/agents/credentials.js +6 -0
- package/dist/lib/agents/facts.js +31 -0
- package/dist/lib/agents/narrative-facts.js +12 -0
- package/dist/lib/agents/verifier.js +62 -0
- package/dist/lib/analysis/answer-text.js +19 -0
- package/dist/lib/analysis/competitor-classifier.js +6 -0
- package/dist/lib/analysis/domain-classifier.js +73 -0
- package/dist/lib/analysis/domain-labels.js +32 -0
- package/dist/lib/analysis/domain-match.js +12 -0
- package/dist/lib/analysis/name-forms.js +12 -0
- package/dist/lib/analysis/outreach.js +17 -0
- package/dist/lib/analysis/progress-schema.js +13 -0
- package/dist/lib/analysis/progress.js +39 -0
- package/dist/lib/analysis/qualified-competitors.js +7 -0
- package/dist/lib/analysis/retrieval.js +16 -0
- package/dist/lib/analysis/scoring.js +12 -0
- package/dist/lib/analysis/search-analyzer.js +17 -0
- package/dist/lib/analysis/sentiment.js +61 -0
- package/dist/lib/analysis/source-classifier.js +22 -0
- package/dist/lib/analysis/source-mix.js +16 -0
- package/dist/lib/analysis/verbatim.js +6 -0
- package/dist/lib/api/errors.js +10 -0
- package/dist/lib/author/examples.js +34 -0
- package/dist/lib/bundle/checks.js +16 -0
- package/dist/lib/bundle/contracts.js +66 -0
- package/dist/lib/bundle/export.js +69 -0
- package/dist/lib/bundle/journal.js +41 -0
- package/dist/lib/bundle/json.js +13 -0
- package/dist/lib/bundle/lineage.js +13 -0
- package/dist/lib/bundle/paths.js +6 -0
- package/dist/lib/bundle/project-journal.js +36 -0
- package/dist/lib/bundle/project.js +55 -0
- package/dist/lib/bundle/read.js +60 -0
- package/dist/lib/bundle/recorder.js +46 -0
- package/dist/lib/bundle/redact.js +35 -0
- package/dist/lib/bundle/trace-coverage.js +33 -0
- package/dist/lib/bundle/verify-integrity.js +41 -0
- package/dist/lib/bundle/verify-measurement.js +49 -0
- package/dist/lib/bundle/verify-report.js +62 -0
- package/dist/lib/bundle/verify.js +71 -0
- package/dist/lib/bundle/writer-lock.js +11 -0
- package/dist/lib/bundle/zip.js +13 -0
- package/dist/lib/capture-manifest.js +42 -0
- package/dist/lib/checks/crawler-access.js +16 -0
- package/dist/lib/checks/renderability.js +8 -0
- package/dist/lib/checks/run-checks.js +38 -0
- package/dist/lib/chunks/chunk-2KJZ326K.js +253 -0
- package/dist/lib/chunks/chunk-2MGARWKY.js +138 -0
- package/dist/lib/chunks/chunk-2NJEWPCV.js +94 -0
- package/dist/lib/chunks/chunk-2PAO43CH.js +43 -0
- package/dist/lib/chunks/chunk-2QLAFBCG.js +8 -0
- package/dist/lib/chunks/chunk-2ROSV4HD.js +64 -0
- package/dist/lib/chunks/chunk-2URYGUMH.js +27 -0
- package/dist/lib/chunks/chunk-3BFCI7LI.js +34 -0
- package/dist/lib/chunks/chunk-3BJWRD4O.js +0 -0
- package/dist/lib/chunks/chunk-3EBWDHPK.js +133 -0
- package/dist/lib/chunks/chunk-3UFZ2XPE.js +73 -0
- package/dist/lib/chunks/chunk-4E4NDGOZ.js +47 -0
- package/dist/lib/chunks/chunk-4QQJXCD2.js +113 -0
- package/dist/lib/chunks/chunk-4US3OBKJ.js +136 -0
- package/dist/lib/chunks/chunk-4ZY6P5SO.js +303 -0
- package/dist/lib/chunks/chunk-55U7PRRM.js +26 -0
- package/dist/lib/chunks/chunk-565CYND6.js +93 -0
- package/dist/lib/chunks/chunk-56VOFZ7T.js +1486 -0
- package/dist/lib/chunks/chunk-5B3RNVZ6.js +193 -0
- package/dist/lib/chunks/chunk-5EX5DKMA.js +812 -0
- package/dist/lib/chunks/chunk-5GZVDGTX.js +316 -0
- package/dist/lib/chunks/chunk-5H3SNUQT.js +101 -0
- package/dist/lib/chunks/chunk-5HT55QYX.js +53 -0
- package/dist/lib/chunks/chunk-5KKLUM7M.js +105 -0
- package/dist/lib/chunks/chunk-5SOTF3XD.js +56 -0
- package/dist/lib/chunks/chunk-5T3V6XJS.js +41 -0
- package/dist/lib/chunks/chunk-5VNYUCLL.js +352 -0
- package/dist/lib/chunks/chunk-5ZITQDVE.js +149 -0
- package/dist/lib/chunks/chunk-6AUEDSTU.js +52 -0
- package/dist/lib/chunks/chunk-6EH4N3EU.js +113 -0
- package/dist/lib/chunks/chunk-6EI4CVRW.js +33 -0
- package/dist/lib/chunks/chunk-6GKKALCI.js +538 -0
- package/dist/lib/chunks/chunk-6GSQKCKF.js +48 -0
- package/dist/lib/chunks/chunk-6KHQ7DXP.js +100 -0
- package/dist/lib/chunks/chunk-6KO7HGCQ.js +229 -0
- package/dist/lib/chunks/chunk-6RAKXYSR.js +226 -0
- package/dist/lib/chunks/chunk-72P6NOKD.js +190 -0
- package/dist/lib/chunks/chunk-74UNVGWB.js +0 -0
- package/dist/lib/chunks/chunk-7GXRDAUY.js +554 -0
- package/dist/lib/chunks/chunk-7MR6IJ7I.js +0 -0
- package/dist/lib/chunks/chunk-7O3M6I2X.js +123 -0
- package/dist/lib/chunks/chunk-7PLK6VGC.js +12 -0
- package/dist/lib/chunks/chunk-7QYZSP7Q.js +190 -0
- package/dist/lib/chunks/chunk-7YYDUHJG.js +113 -0
- package/dist/lib/chunks/chunk-7ZOJE6BH.js +73 -0
- package/dist/lib/chunks/chunk-AKKFERA4.js +99 -0
- package/dist/lib/chunks/chunk-AP5DLF36.js +150 -0
- package/dist/lib/chunks/chunk-AUB5THIS.js +341 -0
- package/dist/lib/chunks/chunk-AWOJWMPN.js +213 -0
- package/dist/lib/chunks/chunk-B5L2KMTU.js +108 -0
- package/dist/lib/chunks/chunk-BEQLSAVX.js +202 -0
- package/dist/lib/chunks/chunk-C6CMSW5J.js +13 -0
- package/dist/lib/chunks/chunk-CFFPOTP4.js +356 -0
- package/dist/lib/chunks/chunk-CJ5YD3CU.js +237 -0
- package/dist/lib/chunks/chunk-CPT2GKKW.js +188 -0
- package/dist/lib/chunks/chunk-CQ62GN7P.js +30 -0
- package/dist/lib/chunks/chunk-CRVCWDH6.js +0 -0
- package/dist/lib/chunks/chunk-CS24IL3K.js +115 -0
- package/dist/lib/chunks/chunk-D2INDP5W.js +240 -0
- package/dist/lib/chunks/chunk-D2LPQO6Y.js +39 -0
- package/dist/lib/chunks/chunk-D5B4ZOW6.js +61 -0
- package/dist/lib/chunks/chunk-D7GEQVLL.js +115 -0
- package/dist/lib/chunks/chunk-DC6PN7QJ.js +193 -0
- package/dist/lib/chunks/chunk-DYJVVQHD.js +60 -0
- package/dist/lib/chunks/chunk-E3CDKC5B.js +45 -0
- package/dist/lib/chunks/chunk-E4HADK7C.js +18 -0
- package/dist/lib/chunks/chunk-E6NQQU6V.js +111 -0
- package/dist/lib/chunks/chunk-EBXOHAMQ.js +131 -0
- package/dist/lib/chunks/chunk-EPQHVILQ.js +348 -0
- package/dist/lib/chunks/chunk-EV4DRS5M.js +61 -0
- package/dist/lib/chunks/chunk-EYKINDNK.js +29 -0
- package/dist/lib/chunks/chunk-EZD2C7QS.js +10 -0
- package/dist/lib/chunks/chunk-FBFZBLTY.js +752 -0
- package/dist/lib/chunks/chunk-FFOVLI3U.js +235 -0
- package/dist/lib/chunks/chunk-FKLNEB2P.js +529 -0
- package/dist/lib/chunks/chunk-FT5NSQYX.js +0 -0
- package/dist/lib/chunks/chunk-FWBVTM7F.js +11 -0
- package/dist/lib/chunks/chunk-GLXY73MK.js +165 -0
- package/dist/lib/chunks/chunk-GMGKKE5N.js +11 -0
- package/dist/lib/chunks/chunk-GVC4LH2N.js +130 -0
- package/dist/lib/chunks/chunk-GVOF5ZUG.js +44 -0
- package/dist/lib/chunks/chunk-H2KDLDK6.js +13 -0
- package/dist/lib/chunks/chunk-H3G3VTT7.js +259 -0
- package/dist/lib/chunks/chunk-H56DDRKE.js +85 -0
- package/dist/lib/chunks/chunk-HOJXKHPX.js +34 -0
- package/dist/lib/chunks/chunk-HSZ3DM74.js +55 -0
- package/dist/lib/chunks/chunk-HXHFMFQU.js +29 -0
- package/dist/lib/chunks/chunk-I7VNIW6Q.js +196 -0
- package/dist/lib/chunks/chunk-IAR6XGEW.js +184 -0
- package/dist/lib/chunks/chunk-IB6RROHE.js +204 -0
- package/dist/lib/chunks/chunk-IBOWGKN7.js +98 -0
- package/dist/lib/chunks/chunk-IEVAFDW7.js +513 -0
- package/dist/lib/chunks/chunk-IPNK7FYT.js +70 -0
- package/dist/lib/chunks/chunk-IRPKBDB7.js +13 -0
- package/dist/lib/chunks/chunk-ISN6MBNB.js +70 -0
- package/dist/lib/chunks/chunk-J46W3EMQ.js +237 -0
- package/dist/lib/chunks/chunk-J6IJGYP5.js +147 -0
- package/dist/lib/chunks/chunk-JQ3P552S.js +0 -0
- package/dist/lib/chunks/chunk-JS3GBU3R.js +46 -0
- package/dist/lib/chunks/chunk-KMRQSIZW.js +90 -0
- package/dist/lib/chunks/chunk-KRFHQQS7.js +323 -0
- package/dist/lib/chunks/chunk-KZR25REO.js +95 -0
- package/dist/lib/chunks/chunk-LIZX4N3H.js +110 -0
- package/dist/lib/chunks/chunk-M2OD74GP.js +93 -0
- package/dist/lib/chunks/chunk-MHAKYFDF.js +741 -0
- package/dist/lib/chunks/chunk-MIF5IYNR.js +139 -0
- package/dist/lib/chunks/chunk-MRRWMAPA.js +0 -0
- package/dist/lib/chunks/chunk-MX6Y4RD2.js +22 -0
- package/dist/lib/chunks/chunk-N2XIGMJ6.js +0 -0
- package/dist/lib/chunks/chunk-N2ZZ6JRF.js +188 -0
- package/dist/lib/chunks/chunk-NANJGMEJ.js +108 -0
- package/dist/lib/chunks/chunk-NCLFZOZU.js +74 -0
- package/dist/lib/chunks/chunk-NH4QGBJV.js +61 -0
- package/dist/lib/chunks/chunk-NL2LDKXX.js +125 -0
- package/dist/lib/chunks/chunk-NZFMOQHU.js +32 -0
- package/dist/lib/chunks/chunk-O2DKE2RO.js +77 -0
- package/dist/lib/chunks/chunk-O7M2OY3H.js +35 -0
- package/dist/lib/chunks/chunk-OBXAHX3L.js +46 -0
- package/dist/lib/chunks/chunk-OL746E4T.js +350 -0
- package/dist/lib/chunks/chunk-OORO55OM.js +922 -0
- package/dist/lib/chunks/chunk-OVUCZLH2.js +114 -0
- package/dist/lib/chunks/chunk-OX656HYK.js +46 -0
- package/dist/lib/chunks/chunk-OYKV5NDM.js +28 -0
- package/dist/lib/chunks/chunk-P4K6BP3L.js +104 -0
- package/dist/lib/chunks/chunk-PCYNBDZ7.js +386 -0
- package/dist/lib/chunks/chunk-PDS5KWO3.js +256 -0
- package/dist/lib/chunks/chunk-PKB6JRJM.js +53 -0
- package/dist/lib/chunks/chunk-PO2J5OQ3.js +46 -0
- package/dist/lib/chunks/chunk-PYLJISDZ.js +206 -0
- package/dist/lib/chunks/chunk-Q2PWES4B.js +822 -0
- package/dist/lib/chunks/chunk-QBD24WTZ.js +37 -0
- package/dist/lib/chunks/chunk-QFVRCSJ2.js +54 -0
- package/dist/lib/chunks/chunk-QTXOW5XC.js +14 -0
- package/dist/lib/chunks/chunk-RBOO4NDG.js +33 -0
- package/dist/lib/chunks/chunk-RMFT4KKK.js +281 -0
- package/dist/lib/chunks/chunk-S2AM76LT.js +90 -0
- package/dist/lib/chunks/chunk-S2SFHTJD.js +152 -0
- package/dist/lib/chunks/chunk-S42BCLHP.js +0 -0
- package/dist/lib/chunks/chunk-S7KJZIUR.js +241 -0
- package/dist/lib/chunks/chunk-SBAZBOPI.js +33 -0
- package/dist/lib/chunks/chunk-SBQ4TWGJ.js +33 -0
- package/dist/lib/chunks/chunk-SDWYZM64.js +371 -0
- package/dist/lib/chunks/chunk-SREGO3PU.js +25 -0
- package/dist/lib/chunks/chunk-SWJ7KQSL.js +318 -0
- package/dist/lib/chunks/chunk-SZ2UBZKG.js +13 -0
- package/dist/lib/chunks/chunk-TCOH3FGE.js +66 -0
- package/dist/lib/chunks/chunk-TGTM5ZFR.js +82 -0
- package/dist/lib/chunks/chunk-TNL2GWYR.js +345 -0
- package/dist/lib/chunks/chunk-UGCT46PC.js +20 -0
- package/dist/lib/chunks/chunk-ULRXHSJL.js +85 -0
- package/dist/lib/chunks/chunk-URUODEVG.js +0 -0
- package/dist/lib/chunks/chunk-V5B6UZ3E.js +47 -0
- package/dist/lib/chunks/chunk-VHDVKEWO.js +102 -0
- package/dist/lib/chunks/chunk-W46Y7KBR.js +29 -0
- package/dist/lib/chunks/chunk-W5XYW6ZM.js +133 -0
- package/dist/lib/chunks/chunk-WDSCJEDG.js +371 -0
- package/dist/lib/chunks/chunk-WE2WPNG2.js +104 -0
- package/dist/lib/chunks/chunk-WJUHRJVW.js +55 -0
- package/dist/lib/chunks/chunk-WKH6BJAZ.js +167 -0
- package/dist/lib/chunks/chunk-WTQWU522.js +343 -0
- package/dist/lib/chunks/chunk-WUELMJ22.js +345 -0
- package/dist/lib/chunks/chunk-X2Y2ZNG3.js +776 -0
- package/dist/lib/chunks/chunk-X6E44EGV.js +261 -0
- package/dist/lib/chunks/chunk-XHWRSGX3.js +95 -0
- package/dist/lib/chunks/chunk-XI5H46DF.js +47 -0
- package/dist/lib/chunks/chunk-XJVXASDD.js +281 -0
- package/dist/lib/chunks/chunk-XU6WQ5UL.js +257 -0
- package/dist/lib/chunks/chunk-Y4OGZ3Q5.js +365 -0
- package/dist/lib/chunks/chunk-Y6D6IVOM.js +299 -0
- package/dist/lib/chunks/chunk-YHS5IEVZ.js +252 -0
- package/dist/lib/chunks/chunk-YIEAIIND.js +6 -0
- package/dist/lib/chunks/chunk-YOZNLFSB.js +297 -0
- package/dist/lib/chunks/chunk-YR67JG2V.js +65 -0
- package/dist/lib/chunks/chunk-YWJPJI3W.js +51 -0
- package/dist/lib/chunks/chunk-Z4LMDKBU.js +369 -0
- package/dist/lib/chunks/chunk-Z7V63UZA.js +108 -0
- package/dist/lib/chunks/chunk-ZCOI3HE2.js +45 -0
- package/dist/lib/chunks/chunk-ZLOOC46D.js +142 -0
- package/dist/lib/chunks/chunk-ZSEY7AHQ.js +123 -0
- package/dist/lib/chunks/chunk-ZVAKKRRD.js +11 -0
- package/dist/lib/chunks/chunk-ZXQPD4OC.js +202 -0
- package/dist/lib/chunks/chunk-ZYSPTOKK.js +302 -0
- package/dist/lib/cli/bundle-commands.js +371 -0
- package/dist/lib/cli/io.js +12 -0
- package/dist/lib/cli/run-commands.js +614 -0
- package/dist/lib/codex-workflow/aggregate.js +56 -0
- package/dist/lib/codex-workflow/author-search.js +48 -0
- package/dist/lib/codex-workflow/author-tools.js +63 -0
- package/dist/lib/codex-workflow/author.js +99 -0
- package/dist/lib/codex-workflow/batch-input.js +7 -0
- package/dist/lib/codex-workflow/batch-layout.js +8 -0
- package/dist/lib/codex-workflow/capture.js +62 -0
- package/dist/lib/codex-workflow/checkpoint.js +39 -0
- package/dist/lib/codex-workflow/checks.js +44 -0
- package/dist/lib/codex-workflow/codex-home.js +17 -0
- package/dist/lib/codex-workflow/copy-editor.js +66 -0
- package/dist/lib/codex-workflow/copy-recovery.js +32 -0
- package/dist/lib/codex-workflow/copy.js +66 -0
- package/dist/lib/codex-workflow/finish.js +84 -0
- package/dist/lib/codex-workflow/host-models.js +15 -0
- package/dist/lib/codex-workflow/loop.js +140 -0
- package/dist/lib/codex-workflow/pending.js +8 -0
- package/dist/lib/codex-workflow/prompts.js +8 -0
- package/dist/lib/codex-workflow/quality.js +31 -0
- package/dist/lib/codex-workflow/run-inputs.js +38 -0
- package/dist/lib/codex-workflow/run-source.js +55 -0
- package/dist/lib/codex-workflow/schemas.js +58 -0
- package/dist/lib/codex-workflow/session.js +40 -0
- package/dist/lib/codex-workflow/stage.js +98 -0
- package/dist/lib/codex-workflow/workdir.js +42 -0
- package/dist/lib/configs/literally-2026-q3.js +6 -0
- package/dist/lib/container/protocol.js +20 -0
- package/dist/lib/coverage-schema.js +6 -0
- package/dist/lib/engine/audit-file.js +46 -0
- package/dist/lib/engine/author.js +97 -0
- package/dist/lib/engine/budget.js +16 -0
- package/dist/lib/engine/env-file.js +8 -0
- package/dist/lib/engine/local-run.js +149 -0
- package/dist/lib/engine/package-root.js +8 -0
- package/dist/lib/engine/preflight.js +43 -0
- package/dist/lib/engine/rejudge.js +151 -0
- package/dist/lib/engine/resources.js +7 -0
- package/dist/lib/engine/run-configuration.js +15 -0
- package/dist/lib/engine/templates.js +33 -0
- package/dist/lib/grounding/controller.js +31 -0
- package/dist/lib/grounding/extract.js +38 -0
- package/dist/lib/grounding/fetch.js +23 -0
- package/dist/lib/grounding/file-store.js +17 -0
- package/dist/lib/grounding/grounding-runtime.js +62 -0
- package/dist/lib/grounding/model-usage.js +9 -0
- package/dist/lib/grounding/model.js +30 -0
- package/dist/lib/grounding/profile.js +15 -0
- package/dist/lib/grounding/recorded-tools.js +35 -0
- package/dist/lib/grounding/schema.js +42 -0
- package/dist/lib/grounding/session.js +30 -0
- package/dist/lib/grounding/tools.js +25 -0
- package/dist/lib/grounding/validation.js +28 -0
- package/dist/lib/grounding.js +13 -0
- package/dist/lib/harness/checkpoint.js +17 -0
- package/dist/lib/harness/contracts.js +30 -0
- package/dist/lib/harness/criteria.js +14 -0
- package/dist/lib/harness/policy.js +25 -0
- package/dist/lib/harness/report/artifacts.js +36 -0
- package/dist/lib/harness/report/capture-coverage.js +11 -0
- package/dist/lib/harness/store.js +46 -0
- package/dist/lib/lib/analysis-checkpoint.js +10 -0
- package/dist/lib/lib/canonical-json.js +8 -0
- package/dist/lib/lib/checkpoint.js +34 -0
- package/dist/lib/lib/env.js +14 -0
- package/dist/lib/lib/log.js +7 -0
- package/dist/lib/lib/paths.js +8 -0
- package/dist/lib/lib/progress-comparison.js +16 -0
- package/dist/lib/lib/report-presentation.js +13 -0
- package/dist/lib/lib/run-id.js +8 -0
- package/dist/lib/lib/type-guards.js +8 -0
- package/dist/lib/models/accounting.js +22 -0
- package/dist/lib/models/batching.js +18 -0
- package/dist/lib/models/budget-protection.js +6 -0
- package/dist/lib/models/context.js +0 -0
- package/dist/lib/models/coverage-rounds.js +6 -0
- package/dist/lib/models/errors.js +8 -0
- package/dist/lib/models/failure-diagnostics.js +6 -0
- package/dist/lib/models/profiles.js +30 -0
- package/dist/lib/models/served-model.js +6 -0
- package/dist/lib/models/structured-images.js +10 -0
- package/dist/lib/models/structured.js +25 -0
- package/dist/lib/models/wire-schema.js +6 -0
- package/dist/lib/pipeline.js +57 -0
- package/dist/lib/probes/agent-cli-parsers.js +23 -0
- package/dist/lib/probes/agent-clis.js +64 -0
- package/dist/lib/probes/chat-retrieval.js +17 -0
- package/dist/lib/probes/child-process.js +13 -0
- package/dist/lib/probes/dataforseo-locale.js +10 -0
- package/dist/lib/probes/dataforseo.js +10 -0
- package/dist/lib/probes/failure.js +26 -0
- package/dist/lib/probes/grounding-urls.js +19 -0
- package/dist/lib/probes/limits.js +12 -0
- package/dist/lib/probes/outcomes.js +13 -0
- package/dist/lib/probes/probe-trace.js +12 -0
- package/dist/lib/probes/probes.js +40 -0
- package/dist/lib/probes/web-tool-guard.js +18 -0
- package/dist/lib/report/contracts.js +34 -0
- package/dist/lib/report/core/answer-text.js +18 -0
- package/dist/lib/report/core/copy-schema.js +10 -0
- package/dist/lib/report/core/domain-match.js +11 -0
- package/dist/lib/report/core/grounding.js +12 -0
- package/dist/lib/report/core/normalize-domain.js +6 -0
- package/dist/lib/report/core/progress-comparison.js +15 -0
- package/dist/lib/report/core/progress-question-sets.js +16 -0
- package/dist/lib/report/core/progress-schema.js +12 -0
- package/dist/lib/report/core/progress-slot-key.js +6 -0
- package/dist/lib/report/core/qualified-competitors.js +6 -0
- package/dist/lib/report/core/report-presentation.js +12 -0
- package/dist/lib/report/core/retrieval.js +10 -0
- package/dist/lib/report/core/schema.js +70 -0
- package/dist/lib/report/core/source-classifier.js +21 -0
- package/dist/lib/report/core/surfaces.js +18 -0
- package/dist/lib/retrieval.js +11 -0
- package/dist/lib/runner.js +71 -0
- package/dist/lib/schema.js +110 -0
- package/dist/lib/section-result.js +34 -0
- package/dist/lib/stores/artifacts.js +35 -0
- package/dist/lib/stores/content-hash.js +10 -0
- package/dist/lib/stores/file-publication.js +20 -0
- package/dist/lib/stores/files.js +76 -0
- package/dist/lib/stores/fs-errors.js +6 -0
- package/dist/lib/stores/local-versions.js +40 -0
- package/dist/lib/stores/memory.js +312 -0
- package/dist/lib/stores/ports.js +6 -0
- package/dist/lib/stores/publication-history.js +10 -0
- package/dist/lib/stores/publication.js +50 -0
- package/dist/lib/stores/run-lifecycle.js +12 -0
- package/dist/lib/stores/versions.js +6 -0
- package/dist/lib/surfaces.js +19 -0
- package/dist/lib/viewer/page.js +6 -0
- package/dist/lib/viewer/server.js +71 -0
- package/dist/lib/workflow/callbacks.js +15 -0
- package/dist/lib/workflow/lineage.js +8 -0
- package/dist/lib/workflow/schema.js +52 -0
- package/dist/types/access/schema.d.ts +75 -0
- package/dist/types/agents/author-schema.d.ts +76 -0
- package/dist/types/agents/author-validation.d.ts +73 -0
- package/dist/types/agents/copy-schema.d.ts +345 -0
- package/dist/types/agents/copy-validation.d.ts +158 -0
- package/dist/types/agents/copywriter-input.d.ts +46 -0
- package/dist/types/agents/credentials.d.ts +10 -0
- package/dist/types/agents/facts.d.ts +69 -0
- package/dist/types/agents/narrative-facts.d.ts +8 -0
- package/dist/types/agents/verifier.d.ts +167 -0
- package/dist/types/analysis/answer-text.d.ts +1 -0
- package/dist/types/analysis/competitor-classifier.d.ts +1 -0
- package/dist/types/analysis/domain-classifier.d.ts +105 -0
- package/dist/types/analysis/domain-labels.d.ts +30 -0
- package/dist/types/analysis/domain-match.d.ts +1 -0
- package/dist/types/analysis/name-forms.d.ts +25 -0
- package/dist/types/analysis/outreach.d.ts +6 -0
- package/dist/types/analysis/progress-schema.d.ts +1 -0
- package/dist/types/analysis/progress.d.ts +15 -0
- package/dist/types/analysis/qualified-competitors.d.ts +1 -0
- package/dist/types/analysis/retrieval.d.ts +22 -0
- package/dist/types/analysis/scoring.d.ts +55 -0
- package/dist/types/analysis/search-analyzer.d.ts +23 -0
- package/dist/types/analysis/sentiment.d.ts +99 -0
- package/dist/types/analysis/source-classifier.d.ts +1 -0
- package/dist/types/analysis/source-mix.d.ts +6 -0
- package/dist/types/analysis/verbatim.d.ts +1 -0
- package/dist/types/api/errors.d.ts +30 -0
- package/dist/types/author/examples.d.ts +31 -0
- package/dist/types/bundle/checks.d.ts +45 -0
- package/dist/types/bundle/contracts.d.ts +354 -0
- package/dist/types/bundle/export.d.ts +46 -0
- package/dist/types/bundle/journal.d.ts +39 -0
- package/dist/types/bundle/json.d.ts +8 -0
- package/dist/types/bundle/lineage.d.ts +13 -0
- package/dist/types/bundle/paths.d.ts +2 -0
- package/dist/types/bundle/project-journal.d.ts +31 -0
- package/dist/types/bundle/project.d.ts +30 -0
- package/dist/types/bundle/read.d.ts +9 -0
- package/dist/types/bundle/recorder.d.ts +89 -0
- package/dist/types/bundle/redact.d.ts +17 -0
- package/dist/types/bundle/trace-coverage.d.ts +36 -0
- package/dist/types/bundle/verify-integrity.d.ts +11 -0
- package/dist/types/bundle/verify-measurement.d.ts +26 -0
- package/dist/types/bundle/verify-report.d.ts +16 -0
- package/dist/types/bundle/verify.d.ts +31 -0
- package/dist/types/bundle/writer-lock.d.ts +23 -0
- package/dist/types/bundle/zip.d.ts +24 -0
- package/dist/types/capture-manifest.d.ts +122 -0
- package/dist/types/checks/crawler-access.d.ts +25 -0
- package/dist/types/checks/renderability.d.ts +4 -0
- package/dist/types/checks/run-checks.d.ts +8 -0
- package/dist/types/cli/bundle-commands.d.ts +5 -0
- package/dist/types/cli/io.d.ts +10 -0
- package/dist/types/cli/literally-aeo.d.ts +1 -0
- package/dist/types/cli/run-commands.d.ts +14 -0
- package/dist/types/codex-workflow/aggregate.d.ts +76 -0
- package/dist/types/codex-workflow/author-search.d.ts +26 -0
- package/dist/types/codex-workflow/author-tools-server.d.ts +1 -0
- package/dist/types/codex-workflow/author-tools.d.ts +145 -0
- package/dist/types/codex-workflow/author.d.ts +101 -0
- package/dist/types/codex-workflow/batch-input.d.ts +12 -0
- package/dist/types/codex-workflow/batch-layout.d.ts +16 -0
- package/dist/types/codex-workflow/capture.d.ts +37 -0
- package/dist/types/codex-workflow/checkpoint.d.ts +18 -0
- package/dist/types/codex-workflow/checks.d.ts +53 -0
- package/dist/types/codex-workflow/codex-home.d.ts +47 -0
- package/dist/types/codex-workflow/copy-editor.d.ts +164 -0
- package/dist/types/codex-workflow/copy-recovery.d.ts +30 -0
- package/dist/types/codex-workflow/copy.d.ts +62 -0
- package/dist/types/codex-workflow/finish.d.ts +53 -0
- package/dist/types/codex-workflow/host-models.d.ts +5 -0
- package/dist/types/codex-workflow/loop.d.ts +177 -0
- package/dist/types/codex-workflow/pending.d.ts +6 -0
- package/dist/types/codex-workflow/prompts.d.ts +14 -0
- package/dist/types/codex-workflow/quality.d.ts +25 -0
- package/dist/types/codex-workflow/run-inputs.d.ts +951 -0
- package/dist/types/codex-workflow/run-source.d.ts +34 -0
- package/dist/types/codex-workflow/schemas.d.ts +493 -0
- package/dist/types/codex-workflow/session.d.ts +13 -0
- package/dist/types/codex-workflow/stage.d.ts +136 -0
- package/dist/types/codex-workflow/workdir.d.ts +40 -0
- package/dist/types/configs/literally-2026-q3.d.ts +2 -0
- package/dist/types/container/protocol.d.ts +72 -0
- package/dist/types/coverage-schema.d.ts +6 -0
- package/dist/types/engine/audit-file.d.ts +126 -0
- package/dist/types/engine/author.d.ts +52 -0
- package/dist/types/engine/budget.d.ts +68 -0
- package/dist/types/engine/env-file.d.ts +13 -0
- package/dist/types/engine/local-run.d.ts +62 -0
- package/dist/types/engine/package-root.d.ts +8 -0
- package/dist/types/engine/preflight.d.ts +27 -0
- package/dist/types/engine/rejudge.d.ts +14 -0
- package/dist/types/engine/resources.d.ts +8 -0
- package/dist/types/engine/run-configuration.d.ts +36 -0
- package/dist/types/engine/templates.d.ts +38 -0
- package/dist/types/grounding/controller.d.ts +110 -0
- package/dist/types/grounding/extract.d.ts +103 -0
- package/dist/types/grounding/fetch.d.ts +53 -0
- package/dist/types/grounding/file-store.d.ts +2 -0
- package/dist/types/grounding/grounding-runtime.d.ts +43 -0
- package/dist/types/grounding/model-usage.d.ts +13 -0
- package/dist/types/grounding/model.d.ts +51 -0
- package/dist/types/grounding/profile.d.ts +15 -0
- package/dist/types/grounding/recorded-tools.d.ts +12 -0
- package/dist/types/grounding/schema.d.ts +521 -0
- package/dist/types/grounding/session.d.ts +143 -0
- package/dist/types/grounding/tools.d.ts +135 -0
- package/dist/types/grounding/validation.d.ts +35 -0
- package/dist/types/grounding.d.ts +1 -0
- package/dist/types/harness/checkpoint.d.ts +29 -0
- package/dist/types/harness/contracts.d.ts +141 -0
- package/dist/types/harness/criteria.d.ts +34 -0
- package/dist/types/harness/policy.d.ts +9 -0
- package/dist/types/harness/report/artifacts.d.ts +287 -0
- package/dist/types/harness/report/capture-coverage.d.ts +11 -0
- package/dist/types/harness/store.d.ts +116 -0
- package/dist/types/lib/analysis-checkpoint.d.ts +20 -0
- package/dist/types/lib/canonical-json.d.ts +11 -0
- package/dist/types/lib/checkpoint.d.ts +33 -0
- package/dist/types/lib/env.d.ts +31 -0
- package/dist/types/lib/log.d.ts +11 -0
- package/dist/types/lib/paths.d.ts +2 -0
- package/dist/types/lib/progress-comparison.d.ts +1 -0
- package/dist/types/lib/report-presentation.d.ts +1 -0
- package/dist/types/lib/run-id.d.ts +2 -0
- package/dist/types/lib/type-guards.d.ts +9 -0
- package/dist/types/models/accounting.d.ts +147 -0
- package/dist/types/models/batching.d.ts +17 -0
- package/dist/types/models/budget-protection.d.ts +10 -0
- package/dist/types/models/context.d.ts +8 -0
- package/dist/types/models/coverage-rounds.d.ts +47 -0
- package/dist/types/models/errors.d.ts +12 -0
- package/dist/types/models/failure-diagnostics.d.ts +8 -0
- package/dist/types/models/profiles.d.ts +551 -0
- package/dist/types/models/served-model.d.ts +11 -0
- package/dist/types/models/structured-images.d.ts +9 -0
- package/dist/types/models/structured.d.ts +111 -0
- package/dist/types/models/wire-schema.d.ts +27 -0
- package/dist/types/pipeline.d.ts +117 -0
- package/dist/types/probes/agent-cli-parsers.d.ts +46 -0
- package/dist/types/probes/agent-clis.d.ts +132 -0
- package/dist/types/probes/chat-retrieval.d.ts +14 -0
- package/dist/types/probes/child-process.d.ts +28 -0
- package/dist/types/probes/dataforseo-locale.d.ts +8 -0
- package/dist/types/probes/dataforseo.d.ts +15 -0
- package/dist/types/probes/failure.d.ts +30 -0
- package/dist/types/probes/grounding-urls.d.ts +18 -0
- package/dist/types/probes/limits.d.ts +30 -0
- package/dist/types/probes/outcomes.d.ts +20 -0
- package/dist/types/probes/probe-trace.d.ts +51 -0
- package/dist/types/probes/probes.d.ts +47 -0
- package/dist/types/probes/web-tool-guard.d.ts +59 -0
- package/dist/types/report/contracts.d.ts +973 -0
- package/dist/types/report/core/answer-text.d.ts +24 -0
- package/dist/types/report/core/copy-schema.d.ts +47 -0
- package/dist/types/report/core/domain-match.d.ts +9 -0
- package/dist/types/report/core/grounding.d.ts +4 -0
- package/dist/types/report/core/normalize-domain.d.ts +2 -0
- package/dist/types/report/core/progress-comparison.d.ts +52 -0
- package/dist/types/report/core/progress-question-sets.d.ts +16 -0
- package/dist/types/report/core/progress-schema.d.ts +101 -0
- package/dist/types/report/core/progress-slot-key.d.ts +9 -0
- package/dist/types/report/core/qualified-competitors.d.ts +6 -0
- package/dist/types/report/core/report-presentation.d.ts +10 -0
- package/dist/types/report/core/retrieval.d.ts +6 -0
- package/dist/types/report/core/schema.d.ts +745 -0
- package/dist/types/report/core/source-classifier.d.ts +21 -0
- package/dist/types/report/core/surfaces.d.ts +11 -0
- package/dist/types/retrieval.d.ts +1 -0
- package/dist/types/runner.d.ts +96 -0
- package/dist/types/schema.d.ts +858 -0
- package/dist/types/section-result.d.ts +4 -0
- package/dist/types/stores/artifacts.d.ts +2 -0
- package/dist/types/stores/content-hash.d.ts +2 -0
- package/dist/types/stores/file-publication.d.ts +31 -0
- package/dist/types/stores/files.d.ts +87 -0
- package/dist/types/stores/fs-errors.d.ts +5 -0
- package/dist/types/stores/local-versions.d.ts +54 -0
- package/dist/types/stores/memory.d.ts +76 -0
- package/dist/types/stores/ports.d.ts +150 -0
- package/dist/types/stores/publication-history.d.ts +27 -0
- package/dist/types/stores/publication.d.ts +53 -0
- package/dist/types/stores/run-lifecycle.d.ts +7 -0
- package/dist/types/stores/versions.d.ts +71 -0
- package/dist/types/surfaces.d.ts +1 -0
- package/dist/types/viewer/page.d.ts +2 -0
- package/dist/types/viewer/server.d.ts +14 -0
- package/dist/types/workflow/callbacks.d.ts +22 -0
- package/dist/types/workflow/lineage.d.ts +20 -0
- package/dist/types/workflow/schema.d.ts +1572 -0
- package/package.json +95 -3
- package/resources/author/COPY_RULES.md +95 -0
- package/resources/author/RULES.md +104 -0
- package/resources/author/banlist.json +38 -0
- package/resources/editorial/COMPANY.md +11 -0
- package/resources/editorial/positioning.md +8 -0
- package/resources/editorial/services.md +4 -0
- package/src/access/schema.ts +96 -0
- package/src/agents/author-schema.ts +49 -0
- package/src/agents/author-validation.ts +409 -0
- package/src/agents/copy-schema.ts +214 -0
- package/src/agents/copy-validation.ts +1170 -0
- package/src/agents/copywriter-input.ts +90 -0
- package/src/agents/credentials.ts +60 -0
- package/src/agents/facts.ts +343 -0
- package/src/agents/narrative-facts.ts +174 -0
- package/src/agents/verifier.ts +603 -0
- package/src/analysis/answer-text.ts +1 -0
- package/src/analysis/competitor-classifier.ts +15 -0
- package/src/analysis/domain-classifier.ts +804 -0
- package/src/analysis/domain-labels.ts +67 -0
- package/src/analysis/domain-match.ts +1 -0
- package/src/analysis/name-forms.ts +59 -0
- package/src/analysis/outreach.ts +107 -0
- package/src/analysis/progress-schema.ts +1 -0
- package/src/analysis/progress.ts +346 -0
- package/src/analysis/qualified-competitors.ts +1 -0
- package/src/analysis/retrieval.ts +105 -0
- package/src/analysis/scoring.ts +167 -0
- package/src/analysis/search-analyzer.ts +83 -0
- package/src/analysis/sentiment.ts +558 -0
- package/src/analysis/source-classifier.ts +1 -0
- package/src/analysis/source-mix.ts +56 -0
- package/src/analysis/verbatim.ts +107 -0
- package/src/api/errors.ts +50 -0
- package/src/author/COPY_RULES.md +95 -0
- package/src/author/RULES.md +104 -0
- package/src/author/banlist.json +38 -0
- package/src/author/examples.ts +79 -0
- package/src/bundle/checks.ts +146 -0
- package/src/bundle/contracts.ts +289 -0
- package/src/bundle/export.ts +448 -0
- package/src/bundle/journal.ts +270 -0
- package/src/bundle/json.ts +157 -0
- package/src/bundle/lineage.ts +45 -0
- package/src/bundle/paths.ts +36 -0
- package/src/bundle/project-journal.ts +179 -0
- package/src/bundle/project.ts +434 -0
- package/src/bundle/read.ts +154 -0
- package/src/bundle/recorder.ts +497 -0
- package/src/bundle/redact.ts +134 -0
- package/src/bundle/trace-coverage.ts +168 -0
- package/src/bundle/verify-integrity.ts +322 -0
- package/src/bundle/verify-measurement.ts +384 -0
- package/src/bundle/verify-report.ts +260 -0
- package/src/bundle/verify.ts +400 -0
- package/src/bundle/writer-lock.ts +133 -0
- package/src/bundle/zip.ts +281 -0
- package/src/capture-manifest.ts +348 -0
- package/src/checks/crawler-access.ts +373 -0
- package/src/checks/renderability.ts +164 -0
- package/src/checks/run-checks.ts +74 -0
- package/src/cli/bundle-commands.ts +249 -0
- package/src/cli/io.ts +63 -0
- package/src/cli/literally-aeo.ts +121 -0
- package/src/cli/run-commands.ts +535 -0
- package/src/codex-workflow/aggregate.ts +336 -0
- package/src/codex-workflow/author-search.ts +76 -0
- package/src/codex-workflow/author-tools-server.ts +208 -0
- package/src/codex-workflow/author-tools.ts +1202 -0
- package/src/codex-workflow/author.ts +512 -0
- package/src/codex-workflow/batch-input.ts +145 -0
- package/src/codex-workflow/batch-layout.ts +47 -0
- package/src/codex-workflow/capture.ts +255 -0
- package/src/codex-workflow/checkpoint.ts +127 -0
- package/src/codex-workflow/checks.ts +510 -0
- package/src/codex-workflow/codex-home.ts +187 -0
- package/src/codex-workflow/copy-editor.ts +322 -0
- package/src/codex-workflow/copy-recovery.ts +134 -0
- package/src/codex-workflow/copy.ts +195 -0
- package/src/codex-workflow/finish.ts +433 -0
- package/src/codex-workflow/host-models.ts +35 -0
- package/src/codex-workflow/loop.ts +1159 -0
- package/src/codex-workflow/pending.ts +24 -0
- package/src/codex-workflow/prompts.ts +153 -0
- package/src/codex-workflow/quality.ts +97 -0
- package/src/codex-workflow/run-inputs.ts +117 -0
- package/src/codex-workflow/run-source.ts +149 -0
- package/src/codex-workflow/schemas.ts +222 -0
- package/src/codex-workflow/session.ts +70 -0
- package/src/codex-workflow/stage.ts +2344 -0
- package/src/codex-workflow/workdir.ts +242 -0
- package/src/configs/literally-2026-q3.ts +199 -0
- package/src/container/protocol.ts +152 -0
- package/src/coverage-schema.ts +7 -0
- package/src/engine/audit-file.ts +254 -0
- package/src/engine/author.ts +279 -0
- package/src/engine/budget.ts +164 -0
- package/src/engine/editorial/COMPANY.md +11 -0
- package/src/engine/editorial/positioning.md +8 -0
- package/src/engine/editorial/services.md +4 -0
- package/src/engine/env-file.ts +87 -0
- package/src/engine/local-run.ts +323 -0
- package/src/engine/package-root.ts +47 -0
- package/src/engine/preflight.ts +156 -0
- package/src/engine/rejudge.ts +118 -0
- package/src/engine/resources.ts +45 -0
- package/src/engine/run-configuration.ts +70 -0
- package/src/engine/templates.ts +66 -0
- package/src/grounding/controller.ts +1211 -0
- package/src/grounding/extract.ts +830 -0
- package/src/grounding/fetch.ts +448 -0
- package/src/grounding/file-store.ts +131 -0
- package/src/grounding/grounding-runtime.ts +318 -0
- package/src/grounding/model-usage.ts +48 -0
- package/src/grounding/model.ts +508 -0
- package/src/grounding/profile.ts +63 -0
- package/src/grounding/recorded-tools.ts +40 -0
- package/src/grounding/schema.ts +262 -0
- package/src/grounding/session.ts +681 -0
- package/src/grounding/tools.ts +500 -0
- package/src/grounding/validation.ts +435 -0
- package/src/grounding.ts +1 -0
- package/src/harness/checkpoint.ts +53 -0
- package/src/harness/contracts.ts +169 -0
- package/src/harness/criteria.ts +166 -0
- package/src/harness/policy.ts +28 -0
- package/src/harness/report/artifacts.ts +130 -0
- package/src/harness/report/capture-coverage.ts +40 -0
- package/src/harness/store.ts +167 -0
- package/src/lib/analysis-checkpoint.ts +94 -0
- package/src/lib/canonical-json.ts +90 -0
- package/src/lib/checkpoint.ts +140 -0
- package/src/lib/env.ts +80 -0
- package/src/lib/log.ts +192 -0
- package/src/lib/paths.ts +14 -0
- package/src/lib/progress-comparison.ts +1 -0
- package/src/lib/report-presentation.ts +1 -0
- package/src/lib/run-id.ts +39 -0
- package/src/lib/type-guards.ts +14 -0
- package/src/models/accounting.ts +656 -0
- package/src/models/batching.ts +68 -0
- package/src/models/budget-protection.ts +68 -0
- package/src/models/context.ts +9 -0
- package/src/models/coverage-rounds.ts +125 -0
- package/src/models/errors.ts +39 -0
- package/src/models/failure-diagnostics.ts +157 -0
- package/src/models/profiles.ts +511 -0
- package/src/models/served-model.ts +20 -0
- package/src/models/structured-images.ts +95 -0
- package/src/models/structured.ts +634 -0
- package/src/models/wire-schema.ts +453 -0
- package/src/pipeline.ts +496 -0
- package/src/probes/agent-cli-parsers.ts +835 -0
- package/src/probes/agent-clis.ts +1482 -0
- package/src/probes/chat-retrieval.ts +238 -0
- package/src/probes/child-process.ts +280 -0
- package/src/probes/dataforseo-locale.ts +71 -0
- package/src/probes/dataforseo.ts +286 -0
- package/src/probes/failure.ts +182 -0
- package/src/probes/grounding-urls.ts +182 -0
- package/src/probes/limits.ts +181 -0
- package/src/probes/outcomes.ts +40 -0
- package/src/probes/probe-trace.ts +109 -0
- package/src/probes/probes.ts +789 -0
- package/src/probes/web-tool-guard.ts +195 -0
- package/src/report/contracts.ts +161 -0
- package/src/report/core/answer-text.ts +144 -0
- package/src/report/core/copy-schema.ts +75 -0
- package/src/report/core/domain-match.ts +52 -0
- package/src/report/core/grounding.ts +32 -0
- package/src/report/core/normalize-domain.ts +16 -0
- package/src/report/core/progress-comparison.ts +362 -0
- package/src/report/core/progress-question-sets.ts +93 -0
- package/src/report/core/progress-schema.ts +150 -0
- package/src/report/core/progress-slot-key.ts +20 -0
- package/src/report/core/qualified-competitors.ts +15 -0
- package/src/report/core/report-presentation.ts +112 -0
- package/src/report/core/retrieval.ts +49 -0
- package/src/report/core/schema.ts +489 -0
- package/src/report/core/source-classifier.ts +239 -0
- package/src/report/core/surfaces.ts +64 -0
- package/src/retrieval.ts +1 -0
- package/src/runner.ts +461 -0
- package/src/schema.ts +181 -0
- package/src/section-result.ts +315 -0
- package/src/stores/artifacts.ts +74 -0
- package/src/stores/content-hash.ts +8 -0
- package/src/stores/file-publication.ts +194 -0
- package/src/stores/files.ts +1069 -0
- package/src/stores/fs-errors.ts +12 -0
- package/src/stores/local-versions.ts +412 -0
- package/src/stores/memory.ts +432 -0
- package/src/stores/ports.ts +231 -0
- package/src/stores/publication-history.ts +48 -0
- package/src/stores/publication.ts +221 -0
- package/src/stores/run-lifecycle.ts +72 -0
- package/src/stores/versions.ts +113 -0
- package/src/surfaces.ts +1 -0
- package/src/viewer/page.ts +208 -0
- package/src/viewer/server.ts +215 -0
- package/src/workflow/callbacks.ts +201 -0
- package/src/workflow/lineage.ts +36 -0
- package/src/workflow/schema.ts +256 -0
|
@@ -0,0 +1,1486 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forgetSession,
|
|
3
|
+
readSession,
|
|
4
|
+
saveSession
|
|
5
|
+
} from "./chunk-4E4NDGOZ.js";
|
|
6
|
+
import {
|
|
7
|
+
CopyVerificationUnavailableError,
|
|
8
|
+
recoverEditorialRounds
|
|
9
|
+
} from "./chunk-KZR25REO.js";
|
|
10
|
+
import {
|
|
11
|
+
authorFiles,
|
|
12
|
+
authorPacket,
|
|
13
|
+
authorSessionInputs
|
|
14
|
+
} from "./chunk-WDSCJEDG.js";
|
|
15
|
+
import {
|
|
16
|
+
copyDir
|
|
17
|
+
} from "./chunk-3EBWDHPK.js";
|
|
18
|
+
import {
|
|
19
|
+
batchInput
|
|
20
|
+
} from "./chunk-VHDVKEWO.js";
|
|
21
|
+
import {
|
|
22
|
+
killChildProcessGroup
|
|
23
|
+
} from "./chunk-7QYZSP7Q.js";
|
|
24
|
+
import {
|
|
25
|
+
mergeBatches,
|
|
26
|
+
restoreQualificationQuotes,
|
|
27
|
+
validateStage
|
|
28
|
+
} from "./chunk-AUB5THIS.js";
|
|
29
|
+
import {
|
|
30
|
+
sessionPrompt,
|
|
31
|
+
stagePrompts
|
|
32
|
+
} from "./chunk-4QQJXCD2.js";
|
|
33
|
+
import {
|
|
34
|
+
codexModel,
|
|
35
|
+
prepareCodexHome
|
|
36
|
+
} from "./chunk-MIF5IYNR.js";
|
|
37
|
+
import {
|
|
38
|
+
writePendingJson
|
|
39
|
+
} from "./chunk-MX6Y4RD2.js";
|
|
40
|
+
import {
|
|
41
|
+
isStageName,
|
|
42
|
+
qualifyRowSchema,
|
|
43
|
+
stageJsonSchema,
|
|
44
|
+
stageVersions
|
|
45
|
+
} from "./chunk-GVC4LH2N.js";
|
|
46
|
+
import {
|
|
47
|
+
isAuthError
|
|
48
|
+
} from "./chunk-7O3M6I2X.js";
|
|
49
|
+
import {
|
|
50
|
+
isObject
|
|
51
|
+
} from "./chunk-7PLK6VGC.js";
|
|
52
|
+
import {
|
|
53
|
+
getEnvironment,
|
|
54
|
+
readEnv
|
|
55
|
+
} from "./chunk-PO2J5OQ3.js";
|
|
56
|
+
import {
|
|
57
|
+
maxReviewRounds
|
|
58
|
+
} from "./chunk-SDWYZM64.js";
|
|
59
|
+
|
|
60
|
+
// src/codex-workflow/stage.ts
|
|
61
|
+
import { spawn } from "node:child_process";
|
|
62
|
+
import { createWriteStream } from "node:fs";
|
|
63
|
+
import { createHash } from "node:crypto";
|
|
64
|
+
import {
|
|
65
|
+
appendFile,
|
|
66
|
+
mkdir,
|
|
67
|
+
readdir,
|
|
68
|
+
readFile,
|
|
69
|
+
rename,
|
|
70
|
+
rm,
|
|
71
|
+
writeFile
|
|
72
|
+
} from "node:fs/promises";
|
|
73
|
+
import path from "node:path";
|
|
74
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
75
|
+
import { z } from "zod";
|
|
76
|
+
var defaultBatchSize = 10;
|
|
77
|
+
var defaultConcurrency = 25;
|
|
78
|
+
var maxAttempts = 3;
|
|
79
|
+
var rowsOutSchema = z.looseObject({
|
|
80
|
+
rows: z.array(z.record(z.string(), z.unknown())).optional()
|
|
81
|
+
});
|
|
82
|
+
var readOut = async (dir, { stage, required }) => {
|
|
83
|
+
const raw = await readFile(
|
|
84
|
+
path.join(dir, "OUT", `${stage}.json`),
|
|
85
|
+
"utf8"
|
|
86
|
+
).catch(() => null);
|
|
87
|
+
if (raw === null && required) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`OUT/${stage}.json is missing: the ${stage} stage runs first.`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return raw ? rowsOutSchema.parse(JSON.parse(raw)) : {};
|
|
93
|
+
};
|
|
94
|
+
var rowsOf = (batch, out) => {
|
|
95
|
+
const files = new Set(batch.files.map((file) => file.file));
|
|
96
|
+
return (out.rows ?? []).filter(
|
|
97
|
+
(row) => typeof row.file === "string" && files.has(row.file)
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
var fixedInputs = (files) => {
|
|
101
|
+
return () => Promise.resolve([...files]);
|
|
102
|
+
};
|
|
103
|
+
var batchPacket = (stage) => {
|
|
104
|
+
return (args) => batchInput({ ...args, stage });
|
|
105
|
+
};
|
|
106
|
+
var reportStage = {
|
|
107
|
+
sandbox: "stage",
|
|
108
|
+
research: false,
|
|
109
|
+
verdict: false
|
|
110
|
+
};
|
|
111
|
+
var stageSpecs = {
|
|
112
|
+
analyze: {
|
|
113
|
+
...reportStage,
|
|
114
|
+
batched: true,
|
|
115
|
+
judgedOn: "batch",
|
|
116
|
+
persistent: false,
|
|
117
|
+
sharedInputs: fixedInputs([
|
|
118
|
+
"CONFIG.json",
|
|
119
|
+
"RULES/analysis.md",
|
|
120
|
+
"CRITERIA.md"
|
|
121
|
+
]),
|
|
122
|
+
input: (_ctx, batch) => Promise.resolve({
|
|
123
|
+
name: `${batch.index}.index.json`,
|
|
124
|
+
content: batch.files.map(({ body: _body, ...entry }) => entry)
|
|
125
|
+
}),
|
|
126
|
+
packet: batchPacket("analyze"),
|
|
127
|
+
corrects: false,
|
|
128
|
+
hostVerdict: false,
|
|
129
|
+
passes: false,
|
|
130
|
+
deliversUnjudged: true
|
|
131
|
+
},
|
|
132
|
+
qualify: {
|
|
133
|
+
...reportStage,
|
|
134
|
+
batched: true,
|
|
135
|
+
judgedOn: "batch",
|
|
136
|
+
persistent: false,
|
|
137
|
+
sharedInputs: fixedInputs([
|
|
138
|
+
"CONFIG.json",
|
|
139
|
+
"RULES/analysis.md",
|
|
140
|
+
"CRITERIA.md"
|
|
141
|
+
]),
|
|
142
|
+
input: async (ctx, batch, required) => ({
|
|
143
|
+
name: `${batch.index}.rows.json`,
|
|
144
|
+
content: {
|
|
145
|
+
rows: rowsOf(
|
|
146
|
+
batch,
|
|
147
|
+
await readOut(ctx.dir, { stage: "analyze", required })
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
}),
|
|
151
|
+
packet: batchPacket("qualify"),
|
|
152
|
+
corrects: true,
|
|
153
|
+
hostVerdict: false,
|
|
154
|
+
passes: false,
|
|
155
|
+
deliversUnjudged: true
|
|
156
|
+
},
|
|
157
|
+
review: {
|
|
158
|
+
...reportStage,
|
|
159
|
+
batched: true,
|
|
160
|
+
judgedOn: "batch",
|
|
161
|
+
persistent: true,
|
|
162
|
+
sharedInputs: fixedInputs([
|
|
163
|
+
"CONFIG.json",
|
|
164
|
+
"CRITERIA.md",
|
|
165
|
+
"RULES/analysis.md"
|
|
166
|
+
]),
|
|
167
|
+
input: async (ctx, batch, required) => ({
|
|
168
|
+
name: `${batch.index}.rows.json`,
|
|
169
|
+
content: {
|
|
170
|
+
analyze: rowsOf(
|
|
171
|
+
batch,
|
|
172
|
+
await readOut(ctx.dir, { stage: "analyze", required })
|
|
173
|
+
),
|
|
174
|
+
qualify: rowsOf(
|
|
175
|
+
batch,
|
|
176
|
+
await readOut(ctx.dir, { stage: "qualify", required })
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
}),
|
|
180
|
+
packet: batchPacket("review"),
|
|
181
|
+
corrects: true,
|
|
182
|
+
hostVerdict: false,
|
|
183
|
+
passes: true,
|
|
184
|
+
deliversUnjudged: false
|
|
185
|
+
},
|
|
186
|
+
write: {
|
|
187
|
+
...reportStage,
|
|
188
|
+
batched: false,
|
|
189
|
+
judgedOn: "all",
|
|
190
|
+
persistent: true,
|
|
191
|
+
// Everything under COPY/, listed at digest time.
|
|
192
|
+
sharedInputs: async (dir) => {
|
|
193
|
+
const files = [];
|
|
194
|
+
const walk = async (relative) => {
|
|
195
|
+
for (const entry of await readdir(path.join(dir, relative), {
|
|
196
|
+
withFileTypes: true
|
|
197
|
+
}).catch(() => [])) {
|
|
198
|
+
if (entry.isDirectory()) {
|
|
199
|
+
await walk(path.posix.join(relative, entry.name));
|
|
200
|
+
} else {
|
|
201
|
+
files.push(path.posix.join(relative, entry.name));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
await walk(copyDir);
|
|
206
|
+
return files.sort();
|
|
207
|
+
},
|
|
208
|
+
input: () => Promise.resolve(null),
|
|
209
|
+
packet: () => Promise.resolve(null),
|
|
210
|
+
corrects: false,
|
|
211
|
+
hostVerdict: true,
|
|
212
|
+
passes: false,
|
|
213
|
+
deliversUnjudged: false
|
|
214
|
+
},
|
|
215
|
+
// The config author (specs/aeo-codex-author-spec.md §3.1): one retained
|
|
216
|
+
// session over the brief, researching through the host's tools under a
|
|
217
|
+
// read-only sandbox, judged by the host's verdict after it submits.
|
|
218
|
+
author: {
|
|
219
|
+
batched: false,
|
|
220
|
+
judgedOn: "all",
|
|
221
|
+
persistent: true,
|
|
222
|
+
sharedInputs: authorFiles,
|
|
223
|
+
sessionInputs: authorSessionInputs,
|
|
224
|
+
input: () => Promise.resolve(null),
|
|
225
|
+
packet: ({ dir, continuation }) => authorPacket({ dir, continuation }),
|
|
226
|
+
corrects: false,
|
|
227
|
+
hostVerdict: false,
|
|
228
|
+
passes: false,
|
|
229
|
+
deliversUnjudged: false,
|
|
230
|
+
sandbox: "read-only",
|
|
231
|
+
research: true,
|
|
232
|
+
verdict: true
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var sumUsage = (usages) => {
|
|
236
|
+
const reported = usages.flatMap((usage) => usage ? [usage] : []);
|
|
237
|
+
if (!reported.length) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
inputTokens: reported.reduce(
|
|
242
|
+
(total, usage) => total + usage.inputTokens,
|
|
243
|
+
0
|
|
244
|
+
),
|
|
245
|
+
outputTokens: reported.reduce(
|
|
246
|
+
(total, usage) => total + usage.outputTokens,
|
|
247
|
+
0
|
|
248
|
+
)
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
var sha = (value) => {
|
|
252
|
+
return createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
253
|
+
};
|
|
254
|
+
var partition = (answers, size = defaultBatchSize) => {
|
|
255
|
+
if (size === Infinity) {
|
|
256
|
+
return [{ index: 0, files: [] }];
|
|
257
|
+
}
|
|
258
|
+
const ordered = [...answers].sort(
|
|
259
|
+
(a, b) => a.sectionKey.localeCompare(b.sectionKey) || a.promptId.localeCompare(b.promptId) || a.surface.localeCompare(b.surface) || a.runIndex - b.runIndex
|
|
260
|
+
);
|
|
261
|
+
const batches = [];
|
|
262
|
+
for (let at = 0; at < ordered.length; at += size) {
|
|
263
|
+
batches.push({
|
|
264
|
+
index: batches.length,
|
|
265
|
+
files: ordered.slice(at, at + size)
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return batches;
|
|
269
|
+
};
|
|
270
|
+
var stageBatches = (ctx, stage) => {
|
|
271
|
+
if (stageSpecs[stage].batched && ctx.batchLayout?.size === (ctx.batchSize ?? defaultBatchSize)) {
|
|
272
|
+
const answers = new Map(ctx.answers.map((answer) => [answer.file, answer]));
|
|
273
|
+
return ctx.batchLayout.batches.map((files, index) => ({
|
|
274
|
+
index,
|
|
275
|
+
files: files.flatMap((file) => answers.get(file) ?? [])
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
278
|
+
return partition(
|
|
279
|
+
ctx.answers,
|
|
280
|
+
stageSpecs[stage].batched ? ctx.batchSize : Infinity
|
|
281
|
+
);
|
|
282
|
+
};
|
|
283
|
+
var scopeFor = (ctx, stage, batch) => {
|
|
284
|
+
return {
|
|
285
|
+
brand: ctx.brand,
|
|
286
|
+
answers: stageSpecs[stage].judgedOn === "all" ? ctx.answers : batch.files,
|
|
287
|
+
sections: ctx.sections,
|
|
288
|
+
ownedDomains: ctx.ownedDomains,
|
|
289
|
+
coverage: true
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
var batchInputsDigest = async (ctx, stage, batch) => {
|
|
293
|
+
const spec = stageSpecs[stage];
|
|
294
|
+
const parts = {
|
|
295
|
+
model: JSON.stringify(codexModel),
|
|
296
|
+
prompt: stagePrompts[stage],
|
|
297
|
+
version: String(stageVersions[stage]),
|
|
298
|
+
schema: JSON.stringify(stageJsonSchema(stage)),
|
|
299
|
+
rows: JSON.stringify(
|
|
300
|
+
(await spec.input(ctx, batch, false))?.content ?? null
|
|
301
|
+
)
|
|
302
|
+
};
|
|
303
|
+
for (const file of await spec.sharedInputs(ctx.dir)) {
|
|
304
|
+
parts[file] = await readFile(path.join(ctx.dir, file), "utf8").catch(
|
|
305
|
+
() => ""
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
for (const answer of batch.files) {
|
|
309
|
+
parts[answer.file] = sha(answer.body);
|
|
310
|
+
}
|
|
311
|
+
return sha(parts);
|
|
312
|
+
};
|
|
313
|
+
var stageInputsDigest = async (ctx, stage) => {
|
|
314
|
+
const digests = [];
|
|
315
|
+
for (const batch of stageBatches(ctx, stage)) {
|
|
316
|
+
digests.push(await batchInputsDigest(ctx, stage, batch));
|
|
317
|
+
}
|
|
318
|
+
return sha(digests);
|
|
319
|
+
};
|
|
320
|
+
var isStageFresh = async (ctx, stage) => {
|
|
321
|
+
const recorded = await readFile(
|
|
322
|
+
path.join(ctx.dir, "OUT", `${stage}.inputs.sha`),
|
|
323
|
+
"utf8"
|
|
324
|
+
).catch(() => null);
|
|
325
|
+
if (!recorded) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
const out = await readFile(
|
|
329
|
+
path.join(ctx.dir, "OUT", `${stage}.json`),
|
|
330
|
+
"utf8"
|
|
331
|
+
).catch(() => null);
|
|
332
|
+
return out !== null && recorded.trim() === await stageInputsDigest(ctx, stage);
|
|
333
|
+
};
|
|
334
|
+
var sessionSandbox = (spec) => {
|
|
335
|
+
if (spec.sandbox === "read-only") {
|
|
336
|
+
return "read-only";
|
|
337
|
+
}
|
|
338
|
+
const AEO_CODEX_STAGE_SANDBOX = readEnv("AEO_CODEX_STAGE_SANDBOX");
|
|
339
|
+
return AEO_CODEX_STAGE_SANDBOX === "danger-full-access" ? "danger-full-access" : "workspace-write";
|
|
340
|
+
};
|
|
341
|
+
var eventText = z.string().optional().catch(void 0);
|
|
342
|
+
var eventTokens = z.number().optional().catch(void 0);
|
|
343
|
+
var eventUsage = z.looseObject({ input_tokens: eventTokens, output_tokens: eventTokens }).optional().catch(void 0);
|
|
344
|
+
var codexEventSchema = z.looseObject({
|
|
345
|
+
type: eventText,
|
|
346
|
+
thread_id: eventText,
|
|
347
|
+
message: eventText,
|
|
348
|
+
error: z.looseObject({ message: eventText }).optional().catch(void 0),
|
|
349
|
+
item: z.looseObject({
|
|
350
|
+
type: eventText,
|
|
351
|
+
command: eventText,
|
|
352
|
+
text: eventText,
|
|
353
|
+
status: eventText
|
|
354
|
+
}).optional().catch(void 0),
|
|
355
|
+
usage: eventUsage,
|
|
356
|
+
info: z.looseObject({ total_token_usage: eventUsage }).optional().catch(void 0)
|
|
357
|
+
});
|
|
358
|
+
var parseCodexEvent = (line) => {
|
|
359
|
+
let json;
|
|
360
|
+
try {
|
|
361
|
+
json = JSON.parse(line);
|
|
362
|
+
} catch {
|
|
363
|
+
return void 0;
|
|
364
|
+
}
|
|
365
|
+
const parsed = codexEventSchema.safeParse(json);
|
|
366
|
+
return parsed.success ? parsed.data : void 0;
|
|
367
|
+
};
|
|
368
|
+
var describeItem = (item) => {
|
|
369
|
+
if (item.type === "command_execution") {
|
|
370
|
+
return `ran: ${(item.command ?? "").slice(0, 100)}`;
|
|
371
|
+
}
|
|
372
|
+
if (item.type === "agent_message") {
|
|
373
|
+
return `said: ${(item.text ?? "").replace(/\s+/g, " ").slice(0, 140)}`;
|
|
374
|
+
}
|
|
375
|
+
if (item.type === "reasoning") {
|
|
376
|
+
return "reasoned";
|
|
377
|
+
}
|
|
378
|
+
return item.type ?? "item";
|
|
379
|
+
};
|
|
380
|
+
var execCodex = async (ctx, { stage, batch, feedback, attempt }) => {
|
|
381
|
+
const env = ctx.codexEnv;
|
|
382
|
+
const spec = stageSpecs[stage];
|
|
383
|
+
const label = `${stage}-${batch.index}`;
|
|
384
|
+
const sharedFiles = await spec.sharedInputs(ctx.dir);
|
|
385
|
+
const boundFiles = spec.sessionInputs?.(sharedFiles) ?? sharedFiles;
|
|
386
|
+
const contract = sha({
|
|
387
|
+
stage,
|
|
388
|
+
version: stageVersions[stage],
|
|
389
|
+
model: codexModel,
|
|
390
|
+
prompt: stagePrompts[stage],
|
|
391
|
+
continuation: sessionPrompt(stage, batch.index, { continuation: true }),
|
|
392
|
+
schema: stageJsonSchema(stage),
|
|
393
|
+
answers: batch.files.map(({ file, body }) => [file, sha(body)]),
|
|
394
|
+
inputs: await Promise.all(
|
|
395
|
+
boundFiles.map(async (file) => [
|
|
396
|
+
file,
|
|
397
|
+
await readFile(path.join(ctx.dir, file), "utf8").catch(() => "")
|
|
398
|
+
])
|
|
399
|
+
)
|
|
400
|
+
});
|
|
401
|
+
const session = spec.persistent ? await readSession(ctx.dir, { label, contract }) : null;
|
|
402
|
+
const instruction = sessionPrompt(stage, batch.index, {
|
|
403
|
+
...feedback,
|
|
404
|
+
continuation: session !== null
|
|
405
|
+
});
|
|
406
|
+
const input = await spec.packet({
|
|
407
|
+
dir: ctx.dir,
|
|
408
|
+
index: batch.index,
|
|
409
|
+
answers: batch.files,
|
|
410
|
+
sharedFiles,
|
|
411
|
+
continuation: session !== null
|
|
412
|
+
});
|
|
413
|
+
const resumeInput = session && input !== null;
|
|
414
|
+
const stdin = resumeInput ? `${instruction}
|
|
415
|
+
|
|
416
|
+
${input}` : input;
|
|
417
|
+
const args = [
|
|
418
|
+
"exec",
|
|
419
|
+
"--json",
|
|
420
|
+
"--skip-git-repo-check",
|
|
421
|
+
...!spec.persistent ? ["--ephemeral"] : [],
|
|
422
|
+
"--sandbox",
|
|
423
|
+
sessionSandbox(spec),
|
|
424
|
+
"--cd",
|
|
425
|
+
ctx.dir,
|
|
426
|
+
...session ? ["resume", session.threadId] : [],
|
|
427
|
+
resumeInput ? "-" : instruction
|
|
428
|
+
];
|
|
429
|
+
let threadId = session?.threadId ?? null;
|
|
430
|
+
ctx.signal?.throwIfAborted();
|
|
431
|
+
const operation = await ctx.recorder?.start({
|
|
432
|
+
kind: "codex_session",
|
|
433
|
+
stage,
|
|
434
|
+
batch: batch.index,
|
|
435
|
+
...attempt !== void 0 && { attempt },
|
|
436
|
+
inputs: {
|
|
437
|
+
instruction,
|
|
438
|
+
stdin: stdin ?? void 0,
|
|
439
|
+
arguments: JSON.stringify(args)
|
|
440
|
+
},
|
|
441
|
+
details: {
|
|
442
|
+
requestedModel: codexModel.model,
|
|
443
|
+
provider: codexModel.providerName,
|
|
444
|
+
reasoningEffort: codexModel.reasoningEffort,
|
|
445
|
+
sandbox: sessionSandbox(spec),
|
|
446
|
+
resumedThreadId: session?.threadId ?? null
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
const transcript = [];
|
|
450
|
+
const result = await new Promise((resolve) => {
|
|
451
|
+
const child = spawn(ctx.command ?? "codex", args, {
|
|
452
|
+
cwd: ctx.dir,
|
|
453
|
+
env,
|
|
454
|
+
detached: true,
|
|
455
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
456
|
+
});
|
|
457
|
+
const abort = () => {
|
|
458
|
+
failure = "the host stopped the work";
|
|
459
|
+
killChildProcessGroup(child, "SIGKILL");
|
|
460
|
+
};
|
|
461
|
+
ctx.signal?.addEventListener("abort", abort, { once: true });
|
|
462
|
+
let usage = null;
|
|
463
|
+
let buffer = "";
|
|
464
|
+
let stderr = "";
|
|
465
|
+
let failure = null;
|
|
466
|
+
child.stdin.on("error", (error) => {
|
|
467
|
+
failure = `could not deliver batch input: ${error.message}`;
|
|
468
|
+
killChildProcessGroup(child, "SIGKILL");
|
|
469
|
+
});
|
|
470
|
+
child.stdin.end(stdin ?? void 0);
|
|
471
|
+
const events = createWriteStream(
|
|
472
|
+
path.join(ctx.dir, "JOURNAL", `${label}.events.jsonl`),
|
|
473
|
+
{ flags: "a" }
|
|
474
|
+
);
|
|
475
|
+
child.stdout.on("data", (chunk) => {
|
|
476
|
+
buffer += chunk.toString();
|
|
477
|
+
let at = buffer.indexOf("\n");
|
|
478
|
+
while (at >= 0) {
|
|
479
|
+
const line = buffer.slice(0, at);
|
|
480
|
+
buffer = buffer.slice(at + 1);
|
|
481
|
+
events.write(`${line}
|
|
482
|
+
`);
|
|
483
|
+
transcript.push(line);
|
|
484
|
+
const event = parseCodexEvent(line);
|
|
485
|
+
if (event?.type === "thread.started" && event.thread_id) {
|
|
486
|
+
threadId = event.thread_id;
|
|
487
|
+
}
|
|
488
|
+
const found = event?.usage ?? event?.info?.total_token_usage;
|
|
489
|
+
if (found) {
|
|
490
|
+
usage = {
|
|
491
|
+
inputTokens: found.input_tokens ?? 0,
|
|
492
|
+
outputTokens: found.output_tokens ?? 0
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
if (event?.type === "turn.failed" || event?.type === "error") {
|
|
496
|
+
failure = event.error?.message ?? event.message ?? failure;
|
|
497
|
+
}
|
|
498
|
+
if (event?.type === "item.completed" && event.item) {
|
|
499
|
+
printProgress(`${label} ${describeItem(event.item)}`);
|
|
500
|
+
}
|
|
501
|
+
at = buffer.indexOf("\n");
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
child.stderr.on("data", (chunk) => {
|
|
505
|
+
stderr += chunk.toString();
|
|
506
|
+
});
|
|
507
|
+
const timeoutMs = ctx.timeoutMs ?? 20 * 6e4;
|
|
508
|
+
const timer = setTimeout(() => {
|
|
509
|
+
failure = `the session exceeded ${Math.round(timeoutMs / 1e3)}s and was killed`;
|
|
510
|
+
killChildProcessGroup(child, "SIGKILL");
|
|
511
|
+
}, timeoutMs);
|
|
512
|
+
child.on("error", (error) => {
|
|
513
|
+
failure = error.message;
|
|
514
|
+
});
|
|
515
|
+
child.on("close", (code) => {
|
|
516
|
+
killChildProcessGroup(child, "SIGKILL");
|
|
517
|
+
clearTimeout(timer);
|
|
518
|
+
ctx.signal?.removeEventListener("abort", abort);
|
|
519
|
+
events.end();
|
|
520
|
+
resolve({ usage, exitCode: code ?? 1, stderr, failure });
|
|
521
|
+
});
|
|
522
|
+
});
|
|
523
|
+
await operation?.finish({
|
|
524
|
+
outcome: result.exitCode === 0 && result.failure === null ? "succeeded" : "failed",
|
|
525
|
+
outputs: {
|
|
526
|
+
events: transcript.length ? `${transcript.join("\n")}
|
|
527
|
+
` : void 0
|
|
528
|
+
},
|
|
529
|
+
details: {
|
|
530
|
+
exitCode: result.exitCode,
|
|
531
|
+
failure: result.failure,
|
|
532
|
+
threadId,
|
|
533
|
+
sessionUsage: result.usage
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
if (spec.persistent && threadId) {
|
|
537
|
+
const files = await saveSession(ctx.dir, label, { contract, threadId });
|
|
538
|
+
await ctx.checkpoint?.(files);
|
|
539
|
+
}
|
|
540
|
+
return {
|
|
541
|
+
...result,
|
|
542
|
+
resumed: session !== null,
|
|
543
|
+
...operation && { operationId: operation.id }
|
|
544
|
+
};
|
|
545
|
+
};
|
|
546
|
+
var fieldPath = (field) => {
|
|
547
|
+
return field.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
|
|
548
|
+
};
|
|
549
|
+
var readPath = (row, segments) => {
|
|
550
|
+
let at = row;
|
|
551
|
+
for (const segment of segments) {
|
|
552
|
+
if (!isObject(at)) {
|
|
553
|
+
return void 0;
|
|
554
|
+
}
|
|
555
|
+
at = at[segment];
|
|
556
|
+
}
|
|
557
|
+
return at;
|
|
558
|
+
};
|
|
559
|
+
var writePath = (row, { segments, value }) => {
|
|
560
|
+
const parent = readPath(row, segments.slice(0, -1));
|
|
561
|
+
const last = segments[segments.length - 1];
|
|
562
|
+
if (!isObject(parent) || last === void 0 || !(last in parent)) {
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
parent[last] = value;
|
|
566
|
+
return true;
|
|
567
|
+
};
|
|
568
|
+
var correctionValue = (text) => {
|
|
569
|
+
try {
|
|
570
|
+
return JSON.parse(text);
|
|
571
|
+
} catch {
|
|
572
|
+
return text;
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
var readCorrectable = async (file) => {
|
|
576
|
+
const raw = await readFile(file, "utf8");
|
|
577
|
+
return rowsOutSchema.parse(JSON.parse(raw));
|
|
578
|
+
};
|
|
579
|
+
var isQualifyRow = (row) => {
|
|
580
|
+
return qualifyRowSchema.safeParse(row).success;
|
|
581
|
+
};
|
|
582
|
+
var applyCorrection = (output, correction, { stage, scope, answers }) => {
|
|
583
|
+
const row = output.rows?.find((entry) => entry.file === correction.file);
|
|
584
|
+
if (!row) {
|
|
585
|
+
return {
|
|
586
|
+
output,
|
|
587
|
+
outcome: "refused: no row for that file",
|
|
588
|
+
applied: false
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
const segments = fieldPath(correction.field);
|
|
592
|
+
const before = readPath(row, segments);
|
|
593
|
+
const next = correctionValue(correction.to);
|
|
594
|
+
if (!writePath(row, { segments, value: next })) {
|
|
595
|
+
return {
|
|
596
|
+
output,
|
|
597
|
+
outcome: `refused: no field ${correction.field} on that row`,
|
|
598
|
+
applied: false
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
const validated = validateStage(scope, stage, output);
|
|
602
|
+
if (validated.value === void 0 || validated.errors.length) {
|
|
603
|
+
writePath(row, { segments, value: before });
|
|
604
|
+
return {
|
|
605
|
+
output,
|
|
606
|
+
outcome: `refused: ${validated.errors[0] ?? "the output is invalid"}`,
|
|
607
|
+
applied: false
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
const reconciled = rowsOutSchema.parse(validated.value);
|
|
611
|
+
const after = readPath(
|
|
612
|
+
reconciled.rows?.find((entry) => entry.file === correction.file) ?? {},
|
|
613
|
+
segments
|
|
614
|
+
);
|
|
615
|
+
const expected = stage === "qualify" && isQualifyRow(row) ? readPath(
|
|
616
|
+
restoreQualificationQuotes(
|
|
617
|
+
row,
|
|
618
|
+
answers.find((answer) => answer.file === correction.file)?.body ?? ""
|
|
619
|
+
),
|
|
620
|
+
segments
|
|
621
|
+
) : next;
|
|
622
|
+
if (JSON.stringify(after) !== JSON.stringify(expected)) {
|
|
623
|
+
writePath(row, { segments, value: before });
|
|
624
|
+
return {
|
|
625
|
+
output,
|
|
626
|
+
outcome: "refused: the host rules reverse it",
|
|
627
|
+
applied: false
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
return { output: reconciled, outcome: "applied", applied: true };
|
|
631
|
+
};
|
|
632
|
+
var alignBatchRows = async (batchDir, output) => {
|
|
633
|
+
const rows = new Map(output.rows?.map((row) => [row.file, row]));
|
|
634
|
+
const names = await readdir(batchDir).catch(() => []);
|
|
635
|
+
for (const name of names) {
|
|
636
|
+
if (!/^\d+\.json$/.test(name)) {
|
|
637
|
+
continue;
|
|
638
|
+
}
|
|
639
|
+
const batchFile = path.join(batchDir, name);
|
|
640
|
+
const batch = await readCorrectable(batchFile);
|
|
641
|
+
if (!batch.rows) {
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
batch.rows = batch.rows.map((row) => rows.get(row.file) ?? row);
|
|
645
|
+
await writeFile(batchFile, JSON.stringify(batch, null, 2));
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
var applyCorrections = async (ctx, from, corrections) => {
|
|
649
|
+
let applied = 0;
|
|
650
|
+
let refused = 0;
|
|
651
|
+
const outcomes = [];
|
|
652
|
+
const byStage = /* @__PURE__ */ new Map();
|
|
653
|
+
for (const correction of corrections) {
|
|
654
|
+
byStage.set(correction.stage, [
|
|
655
|
+
...byStage.get(correction.stage) ?? [],
|
|
656
|
+
correction
|
|
657
|
+
]);
|
|
658
|
+
}
|
|
659
|
+
const answers = ctx.allAnswers ?? ctx.answers;
|
|
660
|
+
const scope = { brand: ctx.brand, answers, coverage: false };
|
|
661
|
+
for (const [stage, list] of byStage) {
|
|
662
|
+
const file = path.join(ctx.dir, "OUT", `${stage}.json`);
|
|
663
|
+
const raw = await readFile(file, "utf8").catch(() => null);
|
|
664
|
+
if (!raw || !isStageName(stage)) {
|
|
665
|
+
for (const correction of list) {
|
|
666
|
+
outcomes.push({ correction, outcome: "refused: no such stage output" });
|
|
667
|
+
}
|
|
668
|
+
refused += list.length;
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
let output = rowsOutSchema.parse(JSON.parse(raw));
|
|
672
|
+
for (const correction of list) {
|
|
673
|
+
const result = applyCorrection(output, correction, {
|
|
674
|
+
stage,
|
|
675
|
+
scope,
|
|
676
|
+
answers
|
|
677
|
+
});
|
|
678
|
+
output = result.output;
|
|
679
|
+
if (result.applied) {
|
|
680
|
+
applied += 1;
|
|
681
|
+
} else {
|
|
682
|
+
refused += 1;
|
|
683
|
+
}
|
|
684
|
+
outcomes.push({ correction, outcome: result.outcome });
|
|
685
|
+
}
|
|
686
|
+
await writeFile(file, JSON.stringify(output, null, 2));
|
|
687
|
+
await alignBatchRows(path.join(ctx.dir, "OUT", stage), output);
|
|
688
|
+
}
|
|
689
|
+
const trailFile = path.join(ctx.dir, "OUT", "corrections.json");
|
|
690
|
+
const trail = z.array(z.unknown()).parse(
|
|
691
|
+
JSON.parse(await readFile(trailFile, "utf8").catch(() => "[]") || "[]")
|
|
692
|
+
);
|
|
693
|
+
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
694
|
+
trail.push(
|
|
695
|
+
...outcomes.map(({ correction, outcome }) => ({
|
|
696
|
+
by: from,
|
|
697
|
+
at,
|
|
698
|
+
outcome,
|
|
699
|
+
...correction
|
|
700
|
+
}))
|
|
701
|
+
);
|
|
702
|
+
await writeFile(trailFile, JSON.stringify(trail, null, 2));
|
|
703
|
+
for (const { correction, outcome } of outcomes) {
|
|
704
|
+
await ctx.recorder?.record(
|
|
705
|
+
outcome === "applied" ? "correction_applied" : "correction_refused",
|
|
706
|
+
{ by: from, outcome, ...correction }
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
return { applied, refused };
|
|
710
|
+
};
|
|
711
|
+
var archiveNotes = async (dir, label) => {
|
|
712
|
+
const notes = path.join(dir, "JOURNAL", `${label}.md`);
|
|
713
|
+
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
714
|
+
await rename(notes, path.join(dir, "JOURNAL", `${label}.${stamp}.md`)).catch(
|
|
715
|
+
() => void 0
|
|
716
|
+
);
|
|
717
|
+
};
|
|
718
|
+
var clock = () => {
|
|
719
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(11, 19);
|
|
720
|
+
};
|
|
721
|
+
var printProgress = (line) => {
|
|
722
|
+
console.log(`${clock()} ${line}`);
|
|
723
|
+
};
|
|
724
|
+
var journal = async (ctx, {
|
|
725
|
+
label,
|
|
726
|
+
file,
|
|
727
|
+
entry
|
|
728
|
+
}) => {
|
|
729
|
+
const relative = `JOURNAL/${label}.${file}.jsonl`;
|
|
730
|
+
await appendFile(
|
|
731
|
+
path.join(ctx.dir, relative),
|
|
732
|
+
`${JSON.stringify({ ...entry, at: (/* @__PURE__ */ new Date()).toISOString() })}
|
|
733
|
+
`
|
|
734
|
+
);
|
|
735
|
+
await ctx.checkpoint?.([relative]);
|
|
736
|
+
};
|
|
737
|
+
var recordIncomplete = async (ctx, {
|
|
738
|
+
label,
|
|
739
|
+
attempt,
|
|
740
|
+
retrying,
|
|
741
|
+
error
|
|
742
|
+
}) => {
|
|
743
|
+
printProgress(
|
|
744
|
+
`${label} failed (attempt ${attempt}${retrying ? ", retrying" : ""}): ${error}`
|
|
745
|
+
);
|
|
746
|
+
await journal(ctx, {
|
|
747
|
+
label,
|
|
748
|
+
file: "failures",
|
|
749
|
+
entry: { attempt, retrying, errors: [error] }
|
|
750
|
+
});
|
|
751
|
+
};
|
|
752
|
+
var recordRefusal = async (ctx, {
|
|
753
|
+
label,
|
|
754
|
+
attempt,
|
|
755
|
+
errors
|
|
756
|
+
}) => {
|
|
757
|
+
const reasons = errors.slice(0, 20);
|
|
758
|
+
printProgress(
|
|
759
|
+
`${label} refused (attempt ${attempt}): ${reasons.join("; ").slice(0, 600)}`
|
|
760
|
+
);
|
|
761
|
+
await journal(ctx, {
|
|
762
|
+
label,
|
|
763
|
+
file: "refusals",
|
|
764
|
+
entry: { attempt, errors: reasons }
|
|
765
|
+
});
|
|
766
|
+
};
|
|
767
|
+
var dropSession = async (ctx, label) => {
|
|
768
|
+
printProgress(
|
|
769
|
+
`${label}: the resumed conversation produced no output; the next session starts fresh`
|
|
770
|
+
);
|
|
771
|
+
const files = await forgetSession(ctx.dir, label);
|
|
772
|
+
await ctx.checkpoint?.(files);
|
|
773
|
+
};
|
|
774
|
+
var incompleteError = (result) => {
|
|
775
|
+
return `codex exited ${result.exitCode} without an output file: ${(result.failure ?? result.stderr).slice(-600)}`;
|
|
776
|
+
};
|
|
777
|
+
var storedBatchSchema = z.record(z.string(), z.unknown());
|
|
778
|
+
var runCodexBatch = async (ctx, { stage, batch, files, scope }) => {
|
|
779
|
+
const { label, outFile, refusedFile } = files;
|
|
780
|
+
const usages = [];
|
|
781
|
+
let errors = [];
|
|
782
|
+
let refusals = 0;
|
|
783
|
+
let attempt = 0;
|
|
784
|
+
let fatal;
|
|
785
|
+
let feedback = {};
|
|
786
|
+
while (attempt < maxAttempts) {
|
|
787
|
+
ctx.signal?.throwIfAborted();
|
|
788
|
+
attempt += 1;
|
|
789
|
+
const result = await execCodex(ctx, { stage, batch, feedback, attempt });
|
|
790
|
+
const decision = {
|
|
791
|
+
stage,
|
|
792
|
+
batch: batch.index,
|
|
793
|
+
attempt,
|
|
794
|
+
operationId: result.operationId ?? null
|
|
795
|
+
};
|
|
796
|
+
usages.push(result.usage);
|
|
797
|
+
const raw = await readFile(outFile, "utf8").catch(() => null);
|
|
798
|
+
if (raw === null) {
|
|
799
|
+
const error = incompleteError(result);
|
|
800
|
+
if (isAuthError(result.failure ?? result.stderr)) {
|
|
801
|
+
fatal = "auth";
|
|
802
|
+
}
|
|
803
|
+
const retrying = !ctx.signal?.aborted && attempt < maxAttempts && fatal === void 0;
|
|
804
|
+
errors = [error];
|
|
805
|
+
await recordIncomplete(ctx, { label, attempt, retrying, error });
|
|
806
|
+
if (result.resumed) {
|
|
807
|
+
await dropSession(ctx, label);
|
|
808
|
+
}
|
|
809
|
+
if (!retrying) {
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
feedback = { incomplete: true };
|
|
813
|
+
continue;
|
|
814
|
+
}
|
|
815
|
+
if (result.exitCode !== 0) {
|
|
816
|
+
printProgress(
|
|
817
|
+
`${label}: CLI exited ${result.exitCode}; validating its saved output`
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
let output;
|
|
821
|
+
try {
|
|
822
|
+
output = JSON.parse(raw);
|
|
823
|
+
} catch {
|
|
824
|
+
errors = ["the output file is not JSON"];
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
const validated = validateStage(scope, stage, output);
|
|
828
|
+
let value = validated.value;
|
|
829
|
+
errors = validated.errors;
|
|
830
|
+
if (value !== void 0 && !errors.length && stageSpecs[stage].verdict) {
|
|
831
|
+
if (!ctx.verdict) {
|
|
832
|
+
throw new Error(`The ${stage} stage needs the host's verdict.`);
|
|
833
|
+
}
|
|
834
|
+
const judged = await ctx.verdict(value);
|
|
835
|
+
errors = judged.errors;
|
|
836
|
+
if (judged.value !== void 0) {
|
|
837
|
+
value = judged.value;
|
|
838
|
+
}
|
|
839
|
+
if (judged.fatal) {
|
|
840
|
+
refusals += 1;
|
|
841
|
+
await recordRefusal(ctx, { label, attempt, errors });
|
|
842
|
+
await ctx.recorder?.record(
|
|
843
|
+
"output_refused",
|
|
844
|
+
{ ...decision, errors, fatal: true },
|
|
845
|
+
{ output: raw }
|
|
846
|
+
);
|
|
847
|
+
await rename(outFile, refusedFile);
|
|
848
|
+
break;
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
if (value !== void 0 && !errors.length) {
|
|
852
|
+
await ctx.recorder?.record("output_accepted", decision, {
|
|
853
|
+
output: raw
|
|
854
|
+
});
|
|
855
|
+
return {
|
|
856
|
+
value,
|
|
857
|
+
attempts: attempt,
|
|
858
|
+
refusals,
|
|
859
|
+
usage: sumUsage(usages),
|
|
860
|
+
errors: []
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
refusals += 1;
|
|
864
|
+
await recordRefusal(ctx, { label, attempt, errors });
|
|
865
|
+
await ctx.recorder?.record(
|
|
866
|
+
"output_refused",
|
|
867
|
+
{ ...decision, errors },
|
|
868
|
+
{ output: raw }
|
|
869
|
+
);
|
|
870
|
+
await rename(outFile, refusedFile);
|
|
871
|
+
feedback = { refusal: errors };
|
|
872
|
+
}
|
|
873
|
+
return {
|
|
874
|
+
attempts: attempt,
|
|
875
|
+
refusals,
|
|
876
|
+
usage: sumUsage(usages),
|
|
877
|
+
errors,
|
|
878
|
+
...fatal !== void 0 && { fatal }
|
|
879
|
+
};
|
|
880
|
+
};
|
|
881
|
+
var pendingSchema = z.object({
|
|
882
|
+
version: z.literal(2).optional(),
|
|
883
|
+
digest: z.string(),
|
|
884
|
+
// A draft the writer never produced is absent from the written file.
|
|
885
|
+
draft: z.unknown().optional(),
|
|
886
|
+
rounds: z.number(),
|
|
887
|
+
errors: z.array(z.string())
|
|
888
|
+
});
|
|
889
|
+
var savePending = async (ctx, { pendingFile, pending }) => {
|
|
890
|
+
await writePendingJson(path.join(ctx.dir, pendingFile), pending);
|
|
891
|
+
await ctx.checkpoint?.([pendingFile]);
|
|
892
|
+
};
|
|
893
|
+
var readPending = async (ctx, { label, pendingFile, digest }) => {
|
|
894
|
+
const raw = await readFile(path.join(ctx.dir, pendingFile), "utf8").catch(
|
|
895
|
+
() => "null"
|
|
896
|
+
);
|
|
897
|
+
const parsed = pendingSchema.safeParse(JSON.parse(raw));
|
|
898
|
+
if (!parsed.success || parsed.data.digest !== digest) {
|
|
899
|
+
return null;
|
|
900
|
+
}
|
|
901
|
+
const saved = parsed.data;
|
|
902
|
+
if (saved.version === 2) {
|
|
903
|
+
return saved;
|
|
904
|
+
}
|
|
905
|
+
const journalText = await readFile(
|
|
906
|
+
path.join(ctx.dir, "JOURNAL", `${label}.refusals.jsonl`),
|
|
907
|
+
"utf8"
|
|
908
|
+
).catch(() => "");
|
|
909
|
+
const pending = {
|
|
910
|
+
...saved,
|
|
911
|
+
...recoverEditorialRounds(saved, journalText),
|
|
912
|
+
version: 2
|
|
913
|
+
};
|
|
914
|
+
await savePending(ctx, { pendingFile, pending });
|
|
915
|
+
return pending;
|
|
916
|
+
};
|
|
917
|
+
var writeInitialDraft = async (ctx, {
|
|
918
|
+
stage,
|
|
919
|
+
batch,
|
|
920
|
+
files,
|
|
921
|
+
usages
|
|
922
|
+
}) => {
|
|
923
|
+
const { label, outFile } = files;
|
|
924
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
925
|
+
ctx.signal?.throwIfAborted();
|
|
926
|
+
const result = await execCodex(ctx, {
|
|
927
|
+
stage,
|
|
928
|
+
batch,
|
|
929
|
+
feedback: attempt > 1 ? { incomplete: true } : {}
|
|
930
|
+
});
|
|
931
|
+
usages.push(result.usage);
|
|
932
|
+
const raw = await readFile(outFile, "utf8").catch(() => null);
|
|
933
|
+
if (raw !== null) {
|
|
934
|
+
if (result.exitCode !== 0) {
|
|
935
|
+
printProgress(
|
|
936
|
+
`${label}: CLI exited ${result.exitCode}; handing its saved draft to the verifier`
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
try {
|
|
940
|
+
return JSON.parse(raw);
|
|
941
|
+
} catch {
|
|
942
|
+
return raw;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
const error = incompleteError(result);
|
|
946
|
+
const retrying = !ctx.signal?.aborted && attempt < maxAttempts;
|
|
947
|
+
await recordIncomplete(ctx, { label, attempt, retrying, error });
|
|
948
|
+
if (result.resumed) {
|
|
949
|
+
await dropSession(ctx, label);
|
|
950
|
+
}
|
|
951
|
+
if (!retrying) {
|
|
952
|
+
throw new Error(error);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
var copyVerdict = async (ctx, { label, ask }) => {
|
|
957
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
958
|
+
const verdict = await ask();
|
|
959
|
+
if (verdict.ok || verdict.fixable && verdict.editedDraft !== void 0) {
|
|
960
|
+
return verdict;
|
|
961
|
+
}
|
|
962
|
+
const outcome = verdict.outcome && verdict.outcome !== "valid" && verdict.outcome !== "invalid_copy" ? verdict.outcome : "verifier_unavailable";
|
|
963
|
+
const retrying = attempt < maxAttempts && (outcome === "verifier_unavailable" || outcome === "invalid_review");
|
|
964
|
+
printProgress(
|
|
965
|
+
`${label} verification unavailable (${outcome}${retrying ? ", retrying" : ""}); editorial rounds unchanged`
|
|
966
|
+
);
|
|
967
|
+
await journal(ctx, {
|
|
968
|
+
label,
|
|
969
|
+
file: "failures",
|
|
970
|
+
entry: {
|
|
971
|
+
phase: "verification",
|
|
972
|
+
attempt,
|
|
973
|
+
outcome,
|
|
974
|
+
retrying,
|
|
975
|
+
errors: verdict.errors
|
|
976
|
+
}
|
|
977
|
+
});
|
|
978
|
+
if (!retrying) {
|
|
979
|
+
throw new CopyVerificationUnavailableError(outcome, verdict.errors);
|
|
980
|
+
}
|
|
981
|
+
await delay(attempt * 1e3, void 0, { signal: ctx.signal });
|
|
982
|
+
}
|
|
983
|
+
};
|
|
984
|
+
var runVerifiedCopy = async (ctx, {
|
|
985
|
+
stage,
|
|
986
|
+
batch,
|
|
987
|
+
files,
|
|
988
|
+
validateCopy
|
|
989
|
+
}) => {
|
|
990
|
+
const { label, digest } = files;
|
|
991
|
+
const pendingFile = `PENDING/${label}.json`;
|
|
992
|
+
const usages = [];
|
|
993
|
+
const start = async () => {
|
|
994
|
+
const draft = ctx.initialCopyDraft !== void 0 ? ctx.initialCopyDraft : await writeInitialDraft(ctx, { stage, batch, files, usages });
|
|
995
|
+
const pending2 = {
|
|
996
|
+
version: 2,
|
|
997
|
+
digest,
|
|
998
|
+
draft,
|
|
999
|
+
rounds: 0,
|
|
1000
|
+
errors: []
|
|
1001
|
+
};
|
|
1002
|
+
await savePending(ctx, { pendingFile, pending: pending2 });
|
|
1003
|
+
return pending2;
|
|
1004
|
+
};
|
|
1005
|
+
let pending = await readPending(ctx, { label, pendingFile, digest }) ?? await start();
|
|
1006
|
+
const persist = async (next) => {
|
|
1007
|
+
pending = next;
|
|
1008
|
+
await savePending(ctx, { pendingFile, pending: next });
|
|
1009
|
+
};
|
|
1010
|
+
let copy;
|
|
1011
|
+
let refusals = 0;
|
|
1012
|
+
let round = pending.rounds;
|
|
1013
|
+
while (round < maxReviewRounds) {
|
|
1014
|
+
round += 1;
|
|
1015
|
+
ctx.signal?.throwIfAborted();
|
|
1016
|
+
const verdict = await copyVerdict(ctx, {
|
|
1017
|
+
label,
|
|
1018
|
+
ask: () => (
|
|
1019
|
+
// The initial review's findings are persisted before the paid edit,
|
|
1020
|
+
// so a retry after a failed recheck resumes from them.
|
|
1021
|
+
validateCopy(pending.draft, {
|
|
1022
|
+
round,
|
|
1023
|
+
previousFindings: pending.errors,
|
|
1024
|
+
reviewed: (findings) => persist({ ...pending, errors: [...findings] })
|
|
1025
|
+
})
|
|
1026
|
+
)
|
|
1027
|
+
});
|
|
1028
|
+
if (verdict.ok) {
|
|
1029
|
+
copy = {
|
|
1030
|
+
...verdict.payload,
|
|
1031
|
+
draft: verdict.editedDraft ?? pending.draft
|
|
1032
|
+
};
|
|
1033
|
+
break;
|
|
1034
|
+
}
|
|
1035
|
+
refusals += 1;
|
|
1036
|
+
await persist({
|
|
1037
|
+
...pending,
|
|
1038
|
+
draft: verdict.editedDraft,
|
|
1039
|
+
rounds: round,
|
|
1040
|
+
errors: [...verdict.errors]
|
|
1041
|
+
});
|
|
1042
|
+
await recordRefusal(ctx, { label, attempt: round, errors: verdict.errors });
|
|
1043
|
+
}
|
|
1044
|
+
return {
|
|
1045
|
+
copy,
|
|
1046
|
+
attempts: copy === void 0 ? pending.rounds : round,
|
|
1047
|
+
refusals,
|
|
1048
|
+
usage: sumUsage(usages),
|
|
1049
|
+
errors: copy === void 0 ? [...pending.errors] : []
|
|
1050
|
+
};
|
|
1051
|
+
};
|
|
1052
|
+
var reusedBatch = async (ctx, {
|
|
1053
|
+
stage,
|
|
1054
|
+
batch,
|
|
1055
|
+
previous,
|
|
1056
|
+
appliedFile
|
|
1057
|
+
}) => {
|
|
1058
|
+
const spec = stageSpecs[stage];
|
|
1059
|
+
const stored = storedBatchSchema.parse(JSON.parse(previous));
|
|
1060
|
+
if (spec.hostVerdict) {
|
|
1061
|
+
const copy = { ...stored, draft: stored.draft };
|
|
1062
|
+
const validated2 = validateStage(
|
|
1063
|
+
scopeFor(ctx, stage, batch),
|
|
1064
|
+
stage,
|
|
1065
|
+
copy.draft
|
|
1066
|
+
);
|
|
1067
|
+
if (validated2.errors.length) {
|
|
1068
|
+
return void 0;
|
|
1069
|
+
}
|
|
1070
|
+
await ctx.recorder?.record(
|
|
1071
|
+
"artifact_reused",
|
|
1072
|
+
{ stage, batch: batch.index },
|
|
1073
|
+
{ output: previous }
|
|
1074
|
+
);
|
|
1075
|
+
return {
|
|
1076
|
+
batch,
|
|
1077
|
+
ok: true,
|
|
1078
|
+
reused: true,
|
|
1079
|
+
attempts: 0,
|
|
1080
|
+
refusals: 0,
|
|
1081
|
+
usage: null,
|
|
1082
|
+
errors: [],
|
|
1083
|
+
copy,
|
|
1084
|
+
correctionsApplied: false
|
|
1085
|
+
};
|
|
1086
|
+
}
|
|
1087
|
+
const validated = validateStage(scopeFor(ctx, stage, batch), stage, stored);
|
|
1088
|
+
if (validated.value === void 0 || validated.errors.length) {
|
|
1089
|
+
return void 0;
|
|
1090
|
+
}
|
|
1091
|
+
const appliedSha = await readFile(appliedFile, "utf8").catch(() => "");
|
|
1092
|
+
await ctx.recorder?.record(
|
|
1093
|
+
"artifact_reused",
|
|
1094
|
+
{ stage, batch: batch.index },
|
|
1095
|
+
{ output: previous }
|
|
1096
|
+
);
|
|
1097
|
+
return {
|
|
1098
|
+
batch,
|
|
1099
|
+
ok: true,
|
|
1100
|
+
reused: true,
|
|
1101
|
+
attempts: 0,
|
|
1102
|
+
refusals: 0,
|
|
1103
|
+
usage: null,
|
|
1104
|
+
errors: [],
|
|
1105
|
+
value: validated.value,
|
|
1106
|
+
correctionsApplied: "corrections" in stored && appliedSha === sha(stored.corrections)
|
|
1107
|
+
};
|
|
1108
|
+
};
|
|
1109
|
+
var runBatch = async (ctx, {
|
|
1110
|
+
stage,
|
|
1111
|
+
batch,
|
|
1112
|
+
previousAccepted,
|
|
1113
|
+
force
|
|
1114
|
+
}) => {
|
|
1115
|
+
const spec = stageSpecs[stage];
|
|
1116
|
+
const label = `${stage}-${batch.index}`;
|
|
1117
|
+
if (spec.batched && !batch.files.length) {
|
|
1118
|
+
return {
|
|
1119
|
+
batch,
|
|
1120
|
+
ok: true,
|
|
1121
|
+
reused: true,
|
|
1122
|
+
attempts: 0,
|
|
1123
|
+
refusals: 0,
|
|
1124
|
+
usage: null,
|
|
1125
|
+
errors: [],
|
|
1126
|
+
value: mergeBatches(stage, [])
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
const outDir = path.join(ctx.dir, "OUT", stage);
|
|
1130
|
+
const outFile = path.join(outDir, `${batch.index}.json`);
|
|
1131
|
+
const shaFile = path.join(outDir, `${batch.index}.inputs.sha`);
|
|
1132
|
+
const appliedFile = path.join(outDir, `${batch.index}.corrections.sha`);
|
|
1133
|
+
const refusedFile = path.join(outDir, `${batch.index}.refused.json`);
|
|
1134
|
+
const scope = scopeFor(ctx, stage, batch);
|
|
1135
|
+
const digest = await batchInputsDigest(ctx, stage, batch);
|
|
1136
|
+
const previous = await readFile(outFile, "utf8").catch(() => null);
|
|
1137
|
+
const recorded = (await readFile(shaFile, "utf8").catch(() => "")).trim();
|
|
1138
|
+
if (previous !== null && recorded === digest && (!force || previousAccepted)) {
|
|
1139
|
+
const reused = await reusedBatch(ctx, {
|
|
1140
|
+
stage,
|
|
1141
|
+
batch,
|
|
1142
|
+
previous,
|
|
1143
|
+
appliedFile
|
|
1144
|
+
});
|
|
1145
|
+
if (reused) {
|
|
1146
|
+
return reused;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
if (!spec.persistent) {
|
|
1150
|
+
await archiveNotes(ctx.dir, label);
|
|
1151
|
+
}
|
|
1152
|
+
const input = await spec.input(ctx, batch, true);
|
|
1153
|
+
if (input) {
|
|
1154
|
+
await writeFile(
|
|
1155
|
+
path.join(outDir, input.name),
|
|
1156
|
+
JSON.stringify(input.content, null, 2)
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
if (spec.passes) {
|
|
1160
|
+
const previousPass = path.join(outDir, `${batch.index}.previous.json`);
|
|
1161
|
+
if (previous !== null) {
|
|
1162
|
+
await writeFile(previousPass, previous);
|
|
1163
|
+
} else {
|
|
1164
|
+
await rm(previousPass, { force: true });
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
for (const file of [outFile, shaFile, appliedFile, refusedFile]) {
|
|
1168
|
+
await rm(file, { force: true });
|
|
1169
|
+
}
|
|
1170
|
+
const files = { label, digest, outFile, refusedFile };
|
|
1171
|
+
let run;
|
|
1172
|
+
if (spec.hostVerdict) {
|
|
1173
|
+
if (!ctx.validateCopy) {
|
|
1174
|
+
throw new Error(`Copy draft has no editing verifier: ${label}.`);
|
|
1175
|
+
}
|
|
1176
|
+
run = await runVerifiedCopy(ctx, {
|
|
1177
|
+
stage,
|
|
1178
|
+
batch,
|
|
1179
|
+
files,
|
|
1180
|
+
validateCopy: ctx.validateCopy
|
|
1181
|
+
});
|
|
1182
|
+
} else {
|
|
1183
|
+
run = await runCodexBatch(ctx, { stage, batch, files, scope });
|
|
1184
|
+
}
|
|
1185
|
+
const accepted = run.copy ?? run.value;
|
|
1186
|
+
if (accepted !== void 0) {
|
|
1187
|
+
await writeFile(outFile, JSON.stringify(accepted, null, 2));
|
|
1188
|
+
await writeFile(shaFile, digest);
|
|
1189
|
+
if (spec.hostVerdict) {
|
|
1190
|
+
await rm(path.join(ctx.dir, "PENDING", `${label}.json`), { force: true });
|
|
1191
|
+
}
|
|
1192
|
+
await ctx.checkpoint?.([
|
|
1193
|
+
`OUT/${stage}/${batch.index}.json`,
|
|
1194
|
+
`OUT/${stage}/${batch.index}.inputs.sha`,
|
|
1195
|
+
`OUT/${stage}/${batch.index}.corrections.sha`,
|
|
1196
|
+
`JOURNAL/${label}.md`,
|
|
1197
|
+
`JOURNAL/${label}.failures.jsonl`,
|
|
1198
|
+
`JOURNAL/${label}.refusals.jsonl`,
|
|
1199
|
+
...spec.hostVerdict ? [`PENDING/${label}.json`] : [],
|
|
1200
|
+
...spec.research ? [`JOURNAL/${label}.research.jsonl`] : []
|
|
1201
|
+
]);
|
|
1202
|
+
printProgress(
|
|
1203
|
+
`${label} accepted${ctx.checkpoint ? "; checkpoint saved" : ""}`
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
return {
|
|
1207
|
+
batch,
|
|
1208
|
+
ok: accepted !== void 0,
|
|
1209
|
+
reused: false,
|
|
1210
|
+
attempts: run.attempts,
|
|
1211
|
+
refusals: run.refusals,
|
|
1212
|
+
usage: run.usage,
|
|
1213
|
+
errors: run.errors.map((error) => `batch ${batch.index}: ${error}`),
|
|
1214
|
+
value: run.value,
|
|
1215
|
+
copy: run.copy,
|
|
1216
|
+
...run.fatal !== void 0 && { fatal: run.fatal }
|
|
1217
|
+
};
|
|
1218
|
+
};
|
|
1219
|
+
var pool = async (items, {
|
|
1220
|
+
concurrency,
|
|
1221
|
+
work
|
|
1222
|
+
}) => {
|
|
1223
|
+
let next = 0;
|
|
1224
|
+
const workers = Array.from(
|
|
1225
|
+
{ length: Math.min(concurrency, items.length) },
|
|
1226
|
+
async () => {
|
|
1227
|
+
for (let item = items[next]; item !== void 0; item = items[next]) {
|
|
1228
|
+
next += 1;
|
|
1229
|
+
await work(item);
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
);
|
|
1233
|
+
await Promise.all(workers);
|
|
1234
|
+
};
|
|
1235
|
+
var acceptedReviewSchema = z.looseObject({
|
|
1236
|
+
verdict: z.unknown().optional(),
|
|
1237
|
+
corrections: z.array(z.unknown()).optional()
|
|
1238
|
+
});
|
|
1239
|
+
var previouslyAccepted = async (ctx, stage, batch) => {
|
|
1240
|
+
if (!stageSpecs[stage].passes) {
|
|
1241
|
+
return false;
|
|
1242
|
+
}
|
|
1243
|
+
const own = await readFile(
|
|
1244
|
+
path.join(ctx.dir, "OUT", stage, `${batch.index}.json`),
|
|
1245
|
+
"utf8"
|
|
1246
|
+
).catch(() => null);
|
|
1247
|
+
if (own === null) {
|
|
1248
|
+
return false;
|
|
1249
|
+
}
|
|
1250
|
+
const parsed = acceptedReviewSchema.safeParse(JSON.parse(own));
|
|
1251
|
+
return parsed.success && parsed.data.verdict === "accepted" && !parsed.data.corrections?.length;
|
|
1252
|
+
};
|
|
1253
|
+
var mergeAccepted = (ctx, { stage, runs }) => {
|
|
1254
|
+
if (stageSpecs[stage].hostVerdict) {
|
|
1255
|
+
return { copy: runs.find((run) => run.ok)?.copy, errors: [] };
|
|
1256
|
+
}
|
|
1257
|
+
const values = runs.flatMap((run) => {
|
|
1258
|
+
if (!run.ok || !run.value) {
|
|
1259
|
+
return [];
|
|
1260
|
+
}
|
|
1261
|
+
return [
|
|
1262
|
+
run.reused && run.correctionsApplied && "corrections" in run.value ? { ...run.value, corrections: [] } : run.value
|
|
1263
|
+
];
|
|
1264
|
+
});
|
|
1265
|
+
if (!values.length) {
|
|
1266
|
+
return { errors: [] };
|
|
1267
|
+
}
|
|
1268
|
+
const degraded = new Set(
|
|
1269
|
+
runs.filter((run) => !run.ok).flatMap((run) => run.batch.files.map((file) => file.file))
|
|
1270
|
+
);
|
|
1271
|
+
const covered = ctx.answers.filter((answer) => !degraded.has(answer.file));
|
|
1272
|
+
const checked = validateStage(
|
|
1273
|
+
{ brand: ctx.brand, answers: covered, coverage: true },
|
|
1274
|
+
stage,
|
|
1275
|
+
mergeBatches(stage, values)
|
|
1276
|
+
);
|
|
1277
|
+
if (checked.value === void 0 || checked.errors.length) {
|
|
1278
|
+
return { errors: checked.errors.map((error) => `merged: ${error}`) };
|
|
1279
|
+
}
|
|
1280
|
+
return { value: checked.value, errors: [] };
|
|
1281
|
+
};
|
|
1282
|
+
var refreshQualifyDigests = async (ctx) => {
|
|
1283
|
+
for (const batch of stageBatches(ctx, "qualify")) {
|
|
1284
|
+
await writeFile(
|
|
1285
|
+
path.join(ctx.dir, "OUT", "qualify", `${batch.index}.inputs.sha`),
|
|
1286
|
+
await batchInputsDigest(ctx, "qualify", batch)
|
|
1287
|
+
);
|
|
1288
|
+
}
|
|
1289
|
+
await writeFile(
|
|
1290
|
+
path.join(ctx.dir, "OUT", "qualify.inputs.sha"),
|
|
1291
|
+
await stageInputsDigest(ctx, "qualify")
|
|
1292
|
+
);
|
|
1293
|
+
};
|
|
1294
|
+
var recordStageDigests = async (ctx, { stage, runs }) => {
|
|
1295
|
+
for (const run of runs) {
|
|
1296
|
+
if (!run.ok) {
|
|
1297
|
+
continue;
|
|
1298
|
+
}
|
|
1299
|
+
const { batch } = run;
|
|
1300
|
+
await writeFile(
|
|
1301
|
+
path.join(ctx.dir, "OUT", stage, `${batch.index}.inputs.sha`),
|
|
1302
|
+
await batchInputsDigest(ctx, stage, batch)
|
|
1303
|
+
);
|
|
1304
|
+
if (run.value && "corrections" in run.value) {
|
|
1305
|
+
await writeFile(
|
|
1306
|
+
path.join(ctx.dir, "OUT", stage, `${batch.index}.corrections.sha`),
|
|
1307
|
+
sha(run.value.corrections)
|
|
1308
|
+
);
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
await writeFile(
|
|
1312
|
+
path.join(ctx.dir, "OUT", `${stage}.inputs.sha`),
|
|
1313
|
+
await stageInputsDigest(ctx, stage)
|
|
1314
|
+
);
|
|
1315
|
+
};
|
|
1316
|
+
var summarizeStage = ({
|
|
1317
|
+
batchCount,
|
|
1318
|
+
runs,
|
|
1319
|
+
degraded,
|
|
1320
|
+
value,
|
|
1321
|
+
copy,
|
|
1322
|
+
corrections
|
|
1323
|
+
}) => {
|
|
1324
|
+
const summary = {
|
|
1325
|
+
batches: batchCount,
|
|
1326
|
+
reused: runs.filter((run) => run.reused).length,
|
|
1327
|
+
attempts: runs.reduce((total, run) => total + run.attempts, 0),
|
|
1328
|
+
refusals: runs.reduce((total, run) => total + run.refusals, 0)
|
|
1329
|
+
};
|
|
1330
|
+
if (degraded.length) {
|
|
1331
|
+
summary.degraded = degraded.length;
|
|
1332
|
+
}
|
|
1333
|
+
if (value && "rows" in value) {
|
|
1334
|
+
summary.rows = value.rows.length;
|
|
1335
|
+
}
|
|
1336
|
+
if (corrections) {
|
|
1337
|
+
summary.corrections = corrections.applied;
|
|
1338
|
+
if (corrections.refused) {
|
|
1339
|
+
summary.refusedCorrections = corrections.refused;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
if (copy) {
|
|
1343
|
+
summary.confidence = copy.confidence;
|
|
1344
|
+
summary.outcome = copy.outcome;
|
|
1345
|
+
}
|
|
1346
|
+
if (value && "verdict" in value) {
|
|
1347
|
+
summary.verdict = value.verdict;
|
|
1348
|
+
summary.unresolved = value.unresolved.length;
|
|
1349
|
+
summary.failed = value.criteria.filter((criterion) => criterion.outcome === "fail").map((criterion) => criterion.criterionId);
|
|
1350
|
+
}
|
|
1351
|
+
return summary;
|
|
1352
|
+
};
|
|
1353
|
+
var runStage = async (initial, stage, options = {}) => {
|
|
1354
|
+
const started = Date.now();
|
|
1355
|
+
const spec = stageSpecs[stage];
|
|
1356
|
+
await mkdir(path.join(initial.dir, "OUT", stage), { recursive: true });
|
|
1357
|
+
await mkdir(path.join(initial.dir, "JOURNAL"), { recursive: true });
|
|
1358
|
+
if (spec.research && !initial.research) {
|
|
1359
|
+
throw new Error(`The ${stage} stage needs its research tool server.`);
|
|
1360
|
+
}
|
|
1361
|
+
const ctx = {
|
|
1362
|
+
...initial,
|
|
1363
|
+
codexEnv: await prepareCodexHome(
|
|
1364
|
+
initial.dir,
|
|
1365
|
+
getEnvironment(),
|
|
1366
|
+
spec.research ? initial.research : void 0
|
|
1367
|
+
)
|
|
1368
|
+
};
|
|
1369
|
+
const batches = stageBatches(ctx, stage);
|
|
1370
|
+
const qualificationWasFresh = stage === "review" && await isStageFresh(ctx, "qualify");
|
|
1371
|
+
const runsByIndex = /* @__PURE__ */ new Map();
|
|
1372
|
+
await pool(batches, {
|
|
1373
|
+
concurrency: ctx.concurrency ?? defaultConcurrency,
|
|
1374
|
+
work: async (batch) => {
|
|
1375
|
+
ctx.signal?.throwIfAborted();
|
|
1376
|
+
runsByIndex.set(
|
|
1377
|
+
batch.index,
|
|
1378
|
+
await runBatch(ctx, {
|
|
1379
|
+
stage,
|
|
1380
|
+
batch,
|
|
1381
|
+
previousAccepted: await previouslyAccepted(ctx, stage, batch),
|
|
1382
|
+
force: options.force ?? false
|
|
1383
|
+
})
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1386
|
+
});
|
|
1387
|
+
const runs = batches.flatMap((batch) => {
|
|
1388
|
+
const run = runsByIndex.get(batch.index);
|
|
1389
|
+
return run ? [run] : [];
|
|
1390
|
+
});
|
|
1391
|
+
const usage = sumUsage(runs.map((run) => run.usage));
|
|
1392
|
+
let degraded = runs.filter((run) => !run.ok).flatMap((run) => run.batch.files.map((file) => file.file));
|
|
1393
|
+
const merged = mergeAccepted(ctx, { stage, runs });
|
|
1394
|
+
const errors = [...runs.flatMap((run) => run.errors), ...merged.errors];
|
|
1395
|
+
const fatal = runs.find((run) => run.fatal !== void 0)?.fatal;
|
|
1396
|
+
const { copy } = merged;
|
|
1397
|
+
let { value } = merged;
|
|
1398
|
+
if (!value && !copy && spec.deliversUnjudged) {
|
|
1399
|
+
value = mergeBatches(stage, []);
|
|
1400
|
+
degraded = ctx.answers.map((answer) => answer.file);
|
|
1401
|
+
}
|
|
1402
|
+
if (spec.passes && value && degraded.length && "verdict" in value) {
|
|
1403
|
+
value.verdict = "needs_another_pass";
|
|
1404
|
+
value.unresolved.push({
|
|
1405
|
+
criterionId: "host_batch_unvalidated",
|
|
1406
|
+
stage: "host",
|
|
1407
|
+
file: null,
|
|
1408
|
+
problem: `The review of ${degraded.length} answer file(s) never validated: ${errors.slice(0, 3).join("; ").slice(0, 1500)}`,
|
|
1409
|
+
evidence: degraded.slice(0, 5).join(", ").slice(0, 600),
|
|
1410
|
+
whyNotFixed: "the host retried the batch and gave up; the next pass tries again"
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
const output = value ?? copy;
|
|
1414
|
+
let corrections = null;
|
|
1415
|
+
if (output !== void 0) {
|
|
1416
|
+
await writeFile(
|
|
1417
|
+
path.join(ctx.dir, "OUT", `${stage}.json`),
|
|
1418
|
+
JSON.stringify(output, null, 2)
|
|
1419
|
+
);
|
|
1420
|
+
if (spec.corrects && value && "corrections" in value) {
|
|
1421
|
+
corrections = await applyCorrections(ctx, stage, value.corrections);
|
|
1422
|
+
}
|
|
1423
|
+
if (spec.passes && value && corrections?.refused && "unresolved" in value) {
|
|
1424
|
+
value.verdict = "needs_another_pass";
|
|
1425
|
+
value.unresolved.push({
|
|
1426
|
+
criterionId: "host_correction_refused",
|
|
1427
|
+
stage: "host",
|
|
1428
|
+
file: null,
|
|
1429
|
+
problem: `${corrections.refused} correction(s) did not pass the evidence checks.`,
|
|
1430
|
+
evidence: "OUT/corrections.json",
|
|
1431
|
+
whyNotFixed: "Continue reviewing the current accepted state and correct the proposed changes."
|
|
1432
|
+
});
|
|
1433
|
+
await writeFile(
|
|
1434
|
+
path.join(ctx.dir, "OUT", `${stage}.json`),
|
|
1435
|
+
JSON.stringify(value, null, 2)
|
|
1436
|
+
);
|
|
1437
|
+
}
|
|
1438
|
+
if (qualificationWasFresh && corrections?.applied) {
|
|
1439
|
+
await refreshQualifyDigests(ctx);
|
|
1440
|
+
}
|
|
1441
|
+
await recordStageDigests(ctx, { stage, runs });
|
|
1442
|
+
if (spec.passes) {
|
|
1443
|
+
await mkdir(path.join(ctx.dir, "REVIEW"), { recursive: true });
|
|
1444
|
+
await writeFile(
|
|
1445
|
+
path.join(ctx.dir, "REVIEW", `${options.pass ?? 1}.json`),
|
|
1446
|
+
JSON.stringify(output, null, 2)
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
const result = {
|
|
1451
|
+
stage,
|
|
1452
|
+
model: codexModel.model,
|
|
1453
|
+
ok: output !== void 0,
|
|
1454
|
+
durationMs: Date.now() - started,
|
|
1455
|
+
usage,
|
|
1456
|
+
errors,
|
|
1457
|
+
degraded,
|
|
1458
|
+
...fatal !== void 0 && { fatal },
|
|
1459
|
+
summary: summarizeStage({
|
|
1460
|
+
batchCount: batches.length,
|
|
1461
|
+
runs,
|
|
1462
|
+
degraded,
|
|
1463
|
+
value,
|
|
1464
|
+
copy,
|
|
1465
|
+
corrections
|
|
1466
|
+
})
|
|
1467
|
+
};
|
|
1468
|
+
await writeFile(
|
|
1469
|
+
path.join(ctx.dir, "OUT", `${stage}.result.json`),
|
|
1470
|
+
JSON.stringify(result)
|
|
1471
|
+
);
|
|
1472
|
+
await ctx.checkpoint?.();
|
|
1473
|
+
return result;
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1476
|
+
export {
|
|
1477
|
+
defaultBatchSize,
|
|
1478
|
+
defaultConcurrency,
|
|
1479
|
+
partition,
|
|
1480
|
+
stageInputsDigest,
|
|
1481
|
+
isStageFresh,
|
|
1482
|
+
fieldPath,
|
|
1483
|
+
correctionValue,
|
|
1484
|
+
applyCorrections,
|
|
1485
|
+
runStage
|
|
1486
|
+
};
|