literally-aeo 0.0.0-stage → 0.1.1
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-2GY42RIJ.js +33 -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-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-3DG7GHFA.js +297 -0
- package/dist/lib/chunks/chunk-3EBWDHPK.js +133 -0
- package/dist/lib/chunks/chunk-3KQFLOC7.js +188 -0
- package/dist/lib/chunks/chunk-3UFZ2XPE.js +73 -0
- package/dist/lib/chunks/chunk-47IZBMP2.js +115 -0
- package/dist/lib/chunks/chunk-4E4NDGOZ.js +47 -0
- package/dist/lib/chunks/chunk-4QQJXCD2.js +113 -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-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-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-AP5DLF36.js +150 -0
- package/dist/lib/chunks/chunk-AUB5THIS.js +341 -0
- package/dist/lib/chunks/chunk-B5L2KMTU.js +108 -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-CKUTDJAB.js +213 -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-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-E3OEE5XN.js +202 -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-FNDJUELJ.js +253 -0
- package/dist/lib/chunks/chunk-FPAN3VRW.js +350 -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-GMKF2FU4.js +104 -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-H56DDRKE.js +85 -0
- package/dist/lib/chunks/chunk-HFOYASRQ.js +99 -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-I3TMFPK4.js +229 -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-JQ3P552S.js +0 -0
- package/dist/lib/chunks/chunk-JS3GBU3R.js +46 -0
- package/dist/lib/chunks/chunk-KHU5DRBE.js +343 -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-LPND3VNQ.js +812 -0
- package/dist/lib/chunks/chunk-MD4AVTK2.js +257 -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-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-NVBMIPXR.js +259 -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-OORO55OM.js +922 -0
- package/dist/lib/chunks/chunk-OQVIRYT5.js +147 -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-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-POUSX3T4.js +64 -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-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-SWS3K62X.js +93 -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-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-XL4JIQ5X.js +316 -0
- package/dist/lib/chunks/chunk-XNRSHATN.js +303 -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-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-ZBDUE3A5.js +136 -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-ZXGATMMH.js +101 -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,1159 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { contentHash } from '../stores/content-hash';
|
|
5
|
+
import { type VerifierHistory, verdictSchemaFor } from '../agents/verifier';
|
|
6
|
+
import {
|
|
7
|
+
classifyVerifierFailure,
|
|
8
|
+
type VerifierFailureOutcome,
|
|
9
|
+
} from '../agents/copy-validation';
|
|
10
|
+
import { RunOrigin, measurementDigest } from '../bundle/contracts';
|
|
11
|
+
import {
|
|
12
|
+
openRecorder,
|
|
13
|
+
recordingAccounting,
|
|
14
|
+
type ExecutionRecorder,
|
|
15
|
+
} from '../bundle/recorder';
|
|
16
|
+
import { acquireWriterLock, type WriterLock } from '../bundle/writer-lock';
|
|
17
|
+
import { capturePlan } from '../capture-manifest';
|
|
18
|
+
import type { GroundingBundle } from '../grounding/schema';
|
|
19
|
+
import { aeoReportCopySchema, type AeoReportCopy } from '../agents/copy-schema';
|
|
20
|
+
import { aeoSnapshotSchema, type AeoAuditConfig } from '../schema';
|
|
21
|
+
import type { InternalModelRoleConfig } from '../models/profiles';
|
|
22
|
+
import type { InternalModelContext } from '../models/context';
|
|
23
|
+
import { ModelBudgetError } from '../models/accounting';
|
|
24
|
+
import { GroundingIntegrityError } from '../grounding/validation';
|
|
25
|
+
import { structuredFailureDiagnostic } from '../models/failure-diagnostics';
|
|
26
|
+
import { isObject } from '../lib/type-guards';
|
|
27
|
+
import { aggregateWorkdir, type AggregateInputs } from './aggregate';
|
|
28
|
+
import { codexModel } from './codex-home';
|
|
29
|
+
import { CopyVerificationUnavailableError } from './copy-recovery';
|
|
30
|
+
import { copyEditHistory, editCopyDraft, readCopyEdits } from './copy-editor';
|
|
31
|
+
import { validateStage } from './checks';
|
|
32
|
+
import {
|
|
33
|
+
materializeCopyInputs,
|
|
34
|
+
readSnapshot,
|
|
35
|
+
validateCopyDraft,
|
|
36
|
+
copywriterFiles,
|
|
37
|
+
} from './copy';
|
|
38
|
+
import {
|
|
39
|
+
finishRun,
|
|
40
|
+
writeFinished,
|
|
41
|
+
type FinishResult,
|
|
42
|
+
type GroundRun,
|
|
43
|
+
} from './finish';
|
|
44
|
+
import { hostModels } from './host-models';
|
|
45
|
+
import type { StageName } from './schemas';
|
|
46
|
+
import type { RunSource } from './run-source';
|
|
47
|
+
import {
|
|
48
|
+
isStageFresh,
|
|
49
|
+
runStage,
|
|
50
|
+
stageInputsDigest,
|
|
51
|
+
defaultBatchSize,
|
|
52
|
+
partition,
|
|
53
|
+
type StageContext,
|
|
54
|
+
type StageRun,
|
|
55
|
+
} from './stage';
|
|
56
|
+
import { materializeWorkdir } from './workdir';
|
|
57
|
+
import { stableBatchLayout } from './batch-layout';
|
|
58
|
+
import {
|
|
59
|
+
maxReviewRounds,
|
|
60
|
+
readStoredReview,
|
|
61
|
+
reportQuality,
|
|
62
|
+
type ReportQuality,
|
|
63
|
+
} from './quality';
|
|
64
|
+
import { writePendingJson } from './pending';
|
|
65
|
+
import { writeRunInputs } from './run-inputs';
|
|
66
|
+
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// The loop (specs/aeo-codex-workflow-spec.md §5), shared by the local CLI
|
|
69
|
+
// and the container job: analyze, qualify, the host's aggregate, scrutiny
|
|
70
|
+
// passes until one is accepted, finish, then the copy. A judgment problem
|
|
71
|
+
// degrades the run and is recorded on the delivered snapshot. Everything is reused by
|
|
72
|
+
// digest, so calling it again on the same directory is the resume.
|
|
73
|
+
// ============================================================================
|
|
74
|
+
|
|
75
|
+
export const defaultMaxPasses = maxReviewRounds;
|
|
76
|
+
|
|
77
|
+
export type WorkflowContext = StageContext & {
|
|
78
|
+
aggregate: AggregateInputs;
|
|
79
|
+
source: RunSource;
|
|
80
|
+
/** Credential values a draft must never contain; the caller's, never
|
|
81
|
+
* read from the environment here. */
|
|
82
|
+
secrets: readonly string[];
|
|
83
|
+
/** The job's pinned accounting, when supplied. Local host steps start
|
|
84
|
+
* their own memory budgets when they run, after the Codex stages. */
|
|
85
|
+
internalModels?: InternalModelContext;
|
|
86
|
+
signal?: AbortSignal;
|
|
87
|
+
log: (line: string) => void;
|
|
88
|
+
/** Gives the run directory back; the caller's, once its work is done. */
|
|
89
|
+
releaseWriter: () => Promise<void>;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** The host's model context for one step: the job's pinned accounting,
|
|
93
|
+
* or a fresh memory budget, recorded either way when the run records (the
|
|
94
|
+
* pinned one is wrapped once, by prepareWorkdir). */
|
|
95
|
+
const hostModelsOf = (
|
|
96
|
+
ctx: Pick<WorkflowContext, 'internalModels' | 'recorder'>,
|
|
97
|
+
): InternalModelContext => {
|
|
98
|
+
if (ctx.internalModels) {
|
|
99
|
+
return ctx.internalModels;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const models = hostModels();
|
|
103
|
+
|
|
104
|
+
return ctx.recorder
|
|
105
|
+
? {
|
|
106
|
+
...models,
|
|
107
|
+
accounting: recordingAccounting(models.accounting, ctx.recorder),
|
|
108
|
+
}
|
|
109
|
+
: models;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** What the copy stage writes from and is held to. A run's own inputs come
|
|
113
|
+
* from its source (`copyInputsOf`); a rewrite pass over a committed run
|
|
114
|
+
* supplies them from the store, with the draft the reviewer saw. */
|
|
115
|
+
export type CopyInputs = {
|
|
116
|
+
config: AeoAuditConfig;
|
|
117
|
+
runId: string;
|
|
118
|
+
configVersion: number | undefined;
|
|
119
|
+
grounding: GroundingBundle | null;
|
|
120
|
+
verifierRole?: InternalModelRoleConfig;
|
|
121
|
+
brandLogo?: AeoReportCopy['brandLogo'];
|
|
122
|
+
previous?: AeoReportCopy | null;
|
|
123
|
+
notes?: readonly string[];
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const copyInputsOf = (
|
|
127
|
+
source: RunSource,
|
|
128
|
+
extra: Pick<CopyInputs, 'brandLogo' | 'previous' | 'notes'> = {},
|
|
129
|
+
): CopyInputs => {
|
|
130
|
+
return {
|
|
131
|
+
config: source.config,
|
|
132
|
+
runId: source.request.runId,
|
|
133
|
+
configVersion: source.request.configVersion,
|
|
134
|
+
grounding: source.grounding,
|
|
135
|
+
verifierRole: source.request.modelProfile?.roles.premiseVerifier,
|
|
136
|
+
...extra,
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/** What the copy stage keeps when the host accepts a draft. A key whose
|
|
141
|
+
* value was undefined is absent from the written file. */
|
|
142
|
+
const copyPayloadSchema = z.looseObject({
|
|
143
|
+
copy: aeoReportCopySchema,
|
|
144
|
+
provenance: z.unknown().optional(),
|
|
145
|
+
receipt: z.unknown().optional(),
|
|
146
|
+
confidence: z.number(),
|
|
147
|
+
outcome: z.string(),
|
|
148
|
+
draft: z.unknown().optional(),
|
|
149
|
+
quality: aeoSnapshotSchema.shape.meta.shape.quality,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
export type CopyPayload = z.infer<typeof copyPayloadSchema>;
|
|
153
|
+
|
|
154
|
+
export type WorkflowResult = {
|
|
155
|
+
verdict: 'accepted' | 'needs_another_pass';
|
|
156
|
+
degraded: string[];
|
|
157
|
+
finish: FinishResult | null;
|
|
158
|
+
/** The validated copy, when the copy stage produced one. */
|
|
159
|
+
copy: CopyPayload | null;
|
|
160
|
+
/** Validated copy includes the deterministic fact compilation used when
|
|
161
|
+
* narrative review needs further work. Errors describe host failures. */
|
|
162
|
+
copyOutcome: 'validated' | 'refused' | 'errored' | 'skipped';
|
|
163
|
+
scorecard: Record<string, unknown>;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/** The work directory from a source: answers, config, rules, schemas. */
|
|
167
|
+
export const prepareWorkdir = async (
|
|
168
|
+
source: RunSource,
|
|
169
|
+
dir: string,
|
|
170
|
+
options: {
|
|
171
|
+
secrets?: readonly string[];
|
|
172
|
+
internalModels?: InternalModelContext;
|
|
173
|
+
signal?: AbortSignal;
|
|
174
|
+
log?: (line: string) => void;
|
|
175
|
+
/** Who runs the workflow: the CLI on an operator's machine, or the
|
|
176
|
+
* hosted job. Recorded in the run journal; never inferred. */
|
|
177
|
+
origin?: RunOrigin;
|
|
178
|
+
/** A caller that already holds the directory and its journal, because
|
|
179
|
+
* it recorded the capture before the workflow (a local run). Its
|
|
180
|
+
* internalModels must already charge through that journal. */
|
|
181
|
+
held?: { writer: WriterLock; recorder: ExecutionRecorder };
|
|
182
|
+
} = {},
|
|
183
|
+
): Promise<WorkflowContext> => {
|
|
184
|
+
if (options.held) {
|
|
185
|
+
return prepareLockedWorkdir(source, dir, {
|
|
186
|
+
...options,
|
|
187
|
+
writer: options.held.writer,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
await mkdir(dir, { recursive: true });
|
|
192
|
+
|
|
193
|
+
const writer = await acquireWriterLock(dir, 'codex workflow');
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
return await prepareLockedWorkdir(source, dir, {
|
|
197
|
+
...options,
|
|
198
|
+
writer,
|
|
199
|
+
});
|
|
200
|
+
} catch (err) {
|
|
201
|
+
await writer.release();
|
|
202
|
+
|
|
203
|
+
throw err;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const prepareLockedWorkdir = async (
|
|
208
|
+
source: RunSource,
|
|
209
|
+
dir: string,
|
|
210
|
+
options: Parameters<typeof prepareWorkdir>[2] & { writer: WriterLock },
|
|
211
|
+
): Promise<WorkflowContext> => {
|
|
212
|
+
const { writer } = options;
|
|
213
|
+
const answers = await materializeWorkdir({
|
|
214
|
+
dir,
|
|
215
|
+
config: source.config,
|
|
216
|
+
captured: source.captured,
|
|
217
|
+
copyRules: (await copywriterFiles())['RULES.md'] ?? '',
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
await writeRunInputs(dir, source);
|
|
221
|
+
|
|
222
|
+
const recorder =
|
|
223
|
+
options.held?.recorder ??
|
|
224
|
+
(await openRecorder(dir, {
|
|
225
|
+
origin: options.origin ?? RunOrigin.LOCAL,
|
|
226
|
+
runId: source.request.runId,
|
|
227
|
+
measurementDigest: measurementDigest({
|
|
228
|
+
config: source.config,
|
|
229
|
+
surfaces: source.surfaces,
|
|
230
|
+
sections: source.request.sections ?? null,
|
|
231
|
+
}),
|
|
232
|
+
planDigest: capturePlan(
|
|
233
|
+
source.config,
|
|
234
|
+
source.surfaces,
|
|
235
|
+
source.request.sections,
|
|
236
|
+
).digest,
|
|
237
|
+
...(writer.takenOver && { takenOver: writer.takenOver }),
|
|
238
|
+
}));
|
|
239
|
+
const internalModels = options.held
|
|
240
|
+
? options.internalModels
|
|
241
|
+
: options.internalModels && {
|
|
242
|
+
...options.internalModels,
|
|
243
|
+
accounting: recordingAccounting(
|
|
244
|
+
options.internalModels.accounting,
|
|
245
|
+
recorder,
|
|
246
|
+
),
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const log =
|
|
250
|
+
options.log ??
|
|
251
|
+
((line: string) => {
|
|
252
|
+
// eslint-disable-next-line no-console -- Without a caller's sink, the run's progress lines are the CLI's terminal output.
|
|
253
|
+
console.log(line);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
log(
|
|
257
|
+
`${source.reportKey} ${source.id}: ${answers.length} captured answers in ${dir}`,
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
return {
|
|
261
|
+
dir,
|
|
262
|
+
brand: source.config.brand,
|
|
263
|
+
answers,
|
|
264
|
+
allAnswers: answers,
|
|
265
|
+
batchLayout: await stableBatchLayout(dir, {
|
|
266
|
+
config: source.config,
|
|
267
|
+
files: partition(answers).flatMap((batch) =>
|
|
268
|
+
batch.files.map((answer) => answer.file),
|
|
269
|
+
),
|
|
270
|
+
size: defaultBatchSize,
|
|
271
|
+
}),
|
|
272
|
+
sections: source.config.sections.map((section) => section.key),
|
|
273
|
+
ownedDomains: source.config.competitorQualification?.ownedDomains,
|
|
274
|
+
source,
|
|
275
|
+
secrets: options.secrets ?? [],
|
|
276
|
+
internalModels,
|
|
277
|
+
recorder,
|
|
278
|
+
releaseWriter: writer.release,
|
|
279
|
+
signal: options.signal,
|
|
280
|
+
log,
|
|
281
|
+
aggregate: {
|
|
282
|
+
dir,
|
|
283
|
+
config: source.config,
|
|
284
|
+
surfaces: source.surfaces,
|
|
285
|
+
capture: source.capture,
|
|
286
|
+
captured: source.captured,
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// The verifier's own history, written by this module; the review entries
|
|
292
|
+
// are kept as the verifier wrote them.
|
|
293
|
+
const savedVerifierMemorySchema = z
|
|
294
|
+
.object({
|
|
295
|
+
scope: z.string(),
|
|
296
|
+
history: z.record(
|
|
297
|
+
z.string(),
|
|
298
|
+
z.array(
|
|
299
|
+
z.object({
|
|
300
|
+
text: z.string(),
|
|
301
|
+
review: verdictSchemaFor([], []).shape.reviews.element,
|
|
302
|
+
}),
|
|
303
|
+
),
|
|
304
|
+
),
|
|
305
|
+
})
|
|
306
|
+
.nullable();
|
|
307
|
+
|
|
308
|
+
/** The copy stage's inputs from the finished snapshot, and the host's
|
|
309
|
+
* verdict on what the writer produces. */
|
|
310
|
+
export const withCopy = async <
|
|
311
|
+
T extends StageContext &
|
|
312
|
+
Pick<WorkflowContext, 'secrets' | 'internalModels'> &
|
|
313
|
+
Partial<Pick<WorkflowContext, 'log'>>,
|
|
314
|
+
>(
|
|
315
|
+
ctx: T,
|
|
316
|
+
inputs: CopyInputs,
|
|
317
|
+
): Promise<T> => {
|
|
318
|
+
const snapshot = await readSnapshot(ctx.dir);
|
|
319
|
+
|
|
320
|
+
await materializeCopyInputs({
|
|
321
|
+
dir: ctx.dir,
|
|
322
|
+
config: inputs.config,
|
|
323
|
+
snapshot,
|
|
324
|
+
runId: inputs.runId,
|
|
325
|
+
grounding: inputs.grounding,
|
|
326
|
+
previous: inputs.previous,
|
|
327
|
+
notes: inputs.notes,
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
const internalModels = hostModelsOf(ctx);
|
|
331
|
+
const memoryFile = path.join(ctx.dir, 'PENDING', 'verifier-history.json');
|
|
332
|
+
const memoryScope = contentHash({
|
|
333
|
+
config: inputs.config,
|
|
334
|
+
runId: inputs.runId,
|
|
335
|
+
snapshot,
|
|
336
|
+
grounding: inputs.grounding,
|
|
337
|
+
role: inputs.verifierRole,
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const verifierMemory = {
|
|
341
|
+
read: async () => {
|
|
342
|
+
const raw = await readFile(memoryFile, 'utf8').catch(() => 'null');
|
|
343
|
+
const saved = savedVerifierMemorySchema.parse(JSON.parse(raw));
|
|
344
|
+
|
|
345
|
+
return saved?.scope === memoryScope ? saved.history : {};
|
|
346
|
+
},
|
|
347
|
+
write: async (history: VerifierHistory) => {
|
|
348
|
+
await writePendingJson(memoryFile, { scope: memoryScope, history });
|
|
349
|
+
await ctx.checkpoint?.(['PENDING/verifier-history.json']);
|
|
350
|
+
},
|
|
351
|
+
edits: async () =>
|
|
352
|
+
copyEditHistory(await readCopyEdits(ctx.dir, memoryScope)),
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const validation = {
|
|
356
|
+
config: inputs.config,
|
|
357
|
+
snapshot,
|
|
358
|
+
runId: inputs.runId,
|
|
359
|
+
configVersion: inputs.configVersion,
|
|
360
|
+
grounding: inputs.grounding,
|
|
361
|
+
secrets: ctx.secrets,
|
|
362
|
+
verifierRole:
|
|
363
|
+
inputs.verifierRole ?? internalModels.profile.roles.premiseVerifier,
|
|
364
|
+
previous: inputs.previous,
|
|
365
|
+
brandLogo: inputs.brandLogo,
|
|
366
|
+
accounting: internalModels.accounting,
|
|
367
|
+
signal: ctx.signal,
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const review = async (draft: unknown) => {
|
|
371
|
+
const shape = validateStage(
|
|
372
|
+
{ brand: ctx.brand, answers: [], sections: ctx.sections, coverage: true },
|
|
373
|
+
'write',
|
|
374
|
+
draft,
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
return shape.errors.length
|
|
378
|
+
? {
|
|
379
|
+
valid: false as const,
|
|
380
|
+
outcome: 'invalid_copy' as const,
|
|
381
|
+
errors: shape.errors.map((message) => ({
|
|
382
|
+
path: 'draft',
|
|
383
|
+
code: 'schema_invalid',
|
|
384
|
+
message,
|
|
385
|
+
})),
|
|
386
|
+
}
|
|
387
|
+
: validateCopyDraft({ ...validation, draft, verifierMemory });
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
return {
|
|
391
|
+
...ctx,
|
|
392
|
+
validateCopy: async (
|
|
393
|
+
initialDraft,
|
|
394
|
+
{ round = 1, previousFindings, reviewed } = {},
|
|
395
|
+
) => {
|
|
396
|
+
// Findings already in hand (a previous round's recheck, or the initial
|
|
397
|
+
// review a retry resumes after) are complete: the draft is not
|
|
398
|
+
// reviewed again, and the edit is made from exactly them.
|
|
399
|
+
const requestedNotes =
|
|
400
|
+
round === 1
|
|
401
|
+
? (inputs.notes ?? []).map((note) => `Requested edit: ${note}`)
|
|
402
|
+
: [];
|
|
403
|
+
|
|
404
|
+
let draft = initialDraft;
|
|
405
|
+
let result =
|
|
406
|
+
previousFindings?.length || requestedNotes.length
|
|
407
|
+
? null
|
|
408
|
+
: await review(draft);
|
|
409
|
+
|
|
410
|
+
const findings = previousFindings?.length
|
|
411
|
+
? [...previousFindings]
|
|
412
|
+
: [
|
|
413
|
+
...(result?.errors ?? []).map(
|
|
414
|
+
(error) => `${error.path}: ${error.message} (${error.code})`,
|
|
415
|
+
),
|
|
416
|
+
...requestedNotes,
|
|
417
|
+
];
|
|
418
|
+
|
|
419
|
+
let editedDraft: unknown;
|
|
420
|
+
|
|
421
|
+
if (!result || result.outcome === 'invalid_copy') {
|
|
422
|
+
if (result) {
|
|
423
|
+
await reviewed?.(findings);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
try {
|
|
427
|
+
editedDraft = await editCopyDraft({
|
|
428
|
+
dir: ctx.dir,
|
|
429
|
+
scope: memoryScope,
|
|
430
|
+
round,
|
|
431
|
+
draft,
|
|
432
|
+
errors: findings,
|
|
433
|
+
validation,
|
|
434
|
+
reviewHistory: await verifierMemory.read(),
|
|
435
|
+
checkpoint: ctx.checkpoint,
|
|
436
|
+
});
|
|
437
|
+
// This includes the fifth edit: a repaired final draft is never
|
|
438
|
+
// discarded merely because its recheck would fall beyond the loop.
|
|
439
|
+
result = await review(editedDraft);
|
|
440
|
+
draft = editedDraft;
|
|
441
|
+
} catch (error) {
|
|
442
|
+
const outcome = classifyVerifierFailure(error, ctx.signal);
|
|
443
|
+
|
|
444
|
+
ctx.log?.(
|
|
445
|
+
`copy verifier edit/recheck unavailable: ${outcome}; ${JSON.stringify(structuredFailureDiagnostic(error, ctx.signal))}`,
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
return {
|
|
449
|
+
ok: false,
|
|
450
|
+
fixable: false,
|
|
451
|
+
outcome,
|
|
452
|
+
errors: [
|
|
453
|
+
'The verifier could not complete its edit and recheck; its saved work is retained',
|
|
454
|
+
],
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (result.valid) {
|
|
460
|
+
return {
|
|
461
|
+
ok: true,
|
|
462
|
+
fixable: false,
|
|
463
|
+
errors: [],
|
|
464
|
+
editedDraft,
|
|
465
|
+
payload: {
|
|
466
|
+
copy: result.copy,
|
|
467
|
+
provenance: result.provenance,
|
|
468
|
+
receipt: result.receipt,
|
|
469
|
+
confidence: isObject(draft) ? draft.confidence : undefined,
|
|
470
|
+
outcome: result.outcome,
|
|
471
|
+
},
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return {
|
|
476
|
+
ok: false,
|
|
477
|
+
outcome: result.outcome,
|
|
478
|
+
fixable: result.outcome === 'invalid_copy',
|
|
479
|
+
editedDraft,
|
|
480
|
+
errors: result.errors.map(
|
|
481
|
+
(error) => `${error.path}: ${error.message} (${error.code})`,
|
|
482
|
+
),
|
|
483
|
+
};
|
|
484
|
+
},
|
|
485
|
+
};
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
export type FinishOptions = {
|
|
489
|
+
degraded: readonly string[];
|
|
490
|
+
write: boolean;
|
|
491
|
+
ground?: GroundRun;
|
|
492
|
+
quality?: ReportQuality;
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
/** The report snapshot from the accepted outputs, into the work directory
|
|
496
|
+
* and, when asked and permitted, the report store. */
|
|
497
|
+
export const finish = async (
|
|
498
|
+
ctx: WorkflowContext,
|
|
499
|
+
{ degraded, write, ground, quality }: FinishOptions,
|
|
500
|
+
): Promise<FinishResult> => {
|
|
501
|
+
const result = await finishRun({
|
|
502
|
+
source: ctx.source,
|
|
503
|
+
dir: ctx.dir,
|
|
504
|
+
degraded,
|
|
505
|
+
write,
|
|
506
|
+
ground,
|
|
507
|
+
internalModels: hostModelsOf(ctx),
|
|
508
|
+
signal: ctx.signal,
|
|
509
|
+
quality,
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
// The bundle the copy stage and the commit read is the one the snapshot
|
|
513
|
+
// was assembled with; the run source is the state they share.
|
|
514
|
+
// eslint-disable-next-line no-param-reassign -- The shared run source carries the grounding to the copy stage and the commit.
|
|
515
|
+
ctx.source.grounding = result.grounding;
|
|
516
|
+
await ctx.checkpoint?.();
|
|
517
|
+
|
|
518
|
+
const labels = Object.entries(result.labelStats)
|
|
519
|
+
.map(([key, value]) => `${key} ${value}`)
|
|
520
|
+
.join(', ');
|
|
521
|
+
|
|
522
|
+
ctx.log(
|
|
523
|
+
`finish: snapshot ${path.relative(process.cwd(), result.snapshotFile)}, ${result.partialFailures.length} partial failure(s), labels ${labels}; store ${result.written}${result.writeMessage ? ` (${result.writeMessage})` : ''}`,
|
|
524
|
+
);
|
|
525
|
+
|
|
526
|
+
return result;
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
/** The host's arithmetic over the corrected outputs; rerun whenever a row
|
|
530
|
+
* changed, so METRICS.json is always the numbers the current rows give. */
|
|
531
|
+
export const aggregate = async (ctx: WorkflowContext) => {
|
|
532
|
+
const output = await aggregateWorkdir(ctx.aggregate);
|
|
533
|
+
|
|
534
|
+
for (const [key, result] of Object.entries(output.sections)) {
|
|
535
|
+
const { summary, matrix } = result.visibility;
|
|
536
|
+
|
|
537
|
+
ctx.log(
|
|
538
|
+
`aggregate ${key}: ${matrix.length} rows, sov ${summary.prospectShareOfVoice ?? 'n/a'} chat / ${summary.agentShareOfVoice ?? 'n/a'} agent, top competitor ${summary.topCompetitorDomain ?? 'none'}`,
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const runVerdict = (run: StageRun, reused: boolean) => {
|
|
544
|
+
if (reused) {
|
|
545
|
+
return 'reused';
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
return run.ok ? 'ok' : 'FAILED';
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
const report = (
|
|
552
|
+
ctx: Pick<WorkflowContext, 'log'>,
|
|
553
|
+
run: StageRun,
|
|
554
|
+
{ reused = false }: { reused?: boolean } = {},
|
|
555
|
+
) => {
|
|
556
|
+
const verdict = runVerdict(run, reused);
|
|
557
|
+
const usage = run.usage
|
|
558
|
+
? ` ${run.usage.inputTokens} in / ${run.usage.outputTokens} out`
|
|
559
|
+
: '';
|
|
560
|
+
|
|
561
|
+
ctx.log(
|
|
562
|
+
`${verdict.padEnd(7)} ${run.stage} (${Math.round(run.durationMs / 1000)}s${usage}) ${JSON.stringify(run.summary)}`,
|
|
563
|
+
);
|
|
564
|
+
|
|
565
|
+
for (const error of run.errors) {
|
|
566
|
+
ctx.log(` ${error.slice(0, 300)}`);
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
const workflowStateSchema = z.looseObject({
|
|
571
|
+
stages: z.array(z.record(z.string(), z.unknown())).optional(),
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
const writeState = async (dir: string, run: StageRun) => {
|
|
575
|
+
const file = path.join(dir, 'STATE.json');
|
|
576
|
+
const raw = (await readFile(file, 'utf8').catch(() => '{}')) || '{}';
|
|
577
|
+
const state = workflowStateSchema.parse(JSON.parse(raw));
|
|
578
|
+
|
|
579
|
+
state.stages = [
|
|
580
|
+
...(state.stages ?? []),
|
|
581
|
+
{ ...run, at: new Date().toISOString() },
|
|
582
|
+
];
|
|
583
|
+
await writeFile(file, JSON.stringify(state, null, 2));
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// A recorded stage result, as far as a reused run carries it forward.
|
|
587
|
+
const recordedRunSchema = z
|
|
588
|
+
.looseObject({
|
|
589
|
+
degraded: z.array(z.string()).optional(),
|
|
590
|
+
summary: z.record(z.string(), z.unknown()).optional(),
|
|
591
|
+
})
|
|
592
|
+
.nullable();
|
|
593
|
+
|
|
594
|
+
export const runOne = async (
|
|
595
|
+
ctx: StageContext & Pick<WorkflowContext, 'log'>,
|
|
596
|
+
stage: StageName,
|
|
597
|
+
{ force, pass }: { force: boolean; pass?: number },
|
|
598
|
+
): Promise<StageRun> => {
|
|
599
|
+
if (!force && (await isStageFresh(ctx, stage))) {
|
|
600
|
+
const raw = await readFile(
|
|
601
|
+
path.join(ctx.dir, 'OUT', `${stage}.result.json`),
|
|
602
|
+
'utf8',
|
|
603
|
+
).catch(() => 'null');
|
|
604
|
+
|
|
605
|
+
const previous = recordedRunSchema.parse(JSON.parse(raw));
|
|
606
|
+
const run: StageRun = {
|
|
607
|
+
stage,
|
|
608
|
+
model: codexModel.model,
|
|
609
|
+
ok: true,
|
|
610
|
+
durationMs: 0,
|
|
611
|
+
usage: null,
|
|
612
|
+
errors: [],
|
|
613
|
+
degraded: previous?.degraded ?? [],
|
|
614
|
+
summary: { ...previous?.summary, reused: true },
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
report(ctx, run, { reused: true });
|
|
618
|
+
|
|
619
|
+
return run;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const run = await runStage(ctx, stage, { pass, force });
|
|
623
|
+
|
|
624
|
+
report(ctx, run);
|
|
625
|
+
await writeState(ctx.dir, run);
|
|
626
|
+
|
|
627
|
+
return run;
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
/** The generated narrative is an enrichment. If its review limit is
|
|
631
|
+
* exhausted, compile only frozen facts through the same receipt checker
|
|
632
|
+
* and deliver the complete measurement with an explicit improvement note. */
|
|
633
|
+
export const deliverableCopy = async (
|
|
634
|
+
ctx:
|
|
635
|
+
| WorkflowContext
|
|
636
|
+
| (StageContext &
|
|
637
|
+
Pick<WorkflowContext, 'secrets' | 'internalModels' | 'log'>),
|
|
638
|
+
inputs: CopyInputs,
|
|
639
|
+
written: StageRun,
|
|
640
|
+
): Promise<CopyPayload> => {
|
|
641
|
+
if (written.ok) {
|
|
642
|
+
const raw = await readFile(path.join(ctx.dir, 'OUT', 'write.json'), 'utf8');
|
|
643
|
+
|
|
644
|
+
return copyPayloadSchema.parse(JSON.parse(raw));
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
const draft = {
|
|
648
|
+
intro: [{ kind: 'fact', factId: 'aggregate:captured' }],
|
|
649
|
+
sections: Object.fromEntries(
|
|
650
|
+
inputs.config.sections.map((section) => [section.key, { subtitle: [] }]),
|
|
651
|
+
),
|
|
652
|
+
confidence: 1,
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
const validated = await validateCopyDraft({
|
|
656
|
+
...inputs,
|
|
657
|
+
draft,
|
|
658
|
+
snapshot: await readSnapshot(ctx.dir),
|
|
659
|
+
secrets: ctx.secrets,
|
|
660
|
+
accounting: ctx.internalModels?.accounting,
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
if (
|
|
664
|
+
!validated.valid ||
|
|
665
|
+
!validated.copy ||
|
|
666
|
+
!validated.provenance ||
|
|
667
|
+
!validated.receipt
|
|
668
|
+
) {
|
|
669
|
+
throw new Error(
|
|
670
|
+
`Frozen report facts did not validate: ${validated.errors.map((error) => error.code).join(', ')}.`,
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const quality: ReportQuality = {
|
|
675
|
+
needsImprovement: true,
|
|
676
|
+
reviewRounds: Math.min(
|
|
677
|
+
Number(written.summary.attempts ?? defaultMaxPasses),
|
|
678
|
+
defaultMaxPasses,
|
|
679
|
+
),
|
|
680
|
+
issues: [
|
|
681
|
+
{
|
|
682
|
+
stage: 'write',
|
|
683
|
+
code: 'narrative_needs_improvement',
|
|
684
|
+
message:
|
|
685
|
+
'The report uses verified measurement facts while its narrative needs improvement.',
|
|
686
|
+
},
|
|
687
|
+
...written.errors.map((message) => ({
|
|
688
|
+
stage: 'write',
|
|
689
|
+
code: 'copy_review',
|
|
690
|
+
message,
|
|
691
|
+
})),
|
|
692
|
+
],
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
const payload: CopyPayload = {
|
|
696
|
+
copy: validated.copy,
|
|
697
|
+
provenance: validated.provenance,
|
|
698
|
+
receipt: validated.receipt,
|
|
699
|
+
outcome: validated.outcome,
|
|
700
|
+
confidence: 1,
|
|
701
|
+
draft,
|
|
702
|
+
quality,
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
await writeFile(
|
|
706
|
+
path.join(ctx.dir, 'OUT', 'write.json'),
|
|
707
|
+
JSON.stringify(payload, null, 2),
|
|
708
|
+
);
|
|
709
|
+
await writeFile(
|
|
710
|
+
path.join(ctx.dir, 'OUT', 'write.inputs.sha'),
|
|
711
|
+
await stageInputsDigest(ctx, 'write'),
|
|
712
|
+
);
|
|
713
|
+
await ctx.checkpoint?.();
|
|
714
|
+
ctx.log(
|
|
715
|
+
'copy: delivering verified report facts; narrative improvement notes retained',
|
|
716
|
+
);
|
|
717
|
+
|
|
718
|
+
return payload;
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
/** Verifier outcomes the copy ships without (the pipeline is additive: a
|
|
722
|
+
* verifier that keeps answering unusably after its tries costs the report
|
|
723
|
+
* its narrative, never its delivery). Budget, deadline, integrity and
|
|
724
|
+
* cancellation are the host's blockers and stay thrown. */
|
|
725
|
+
const shipWithoutVerifier = new Set<VerifierFailureOutcome>([
|
|
726
|
+
'invalid_review',
|
|
727
|
+
'verifier_unavailable',
|
|
728
|
+
]);
|
|
729
|
+
|
|
730
|
+
export const writeReportCopy = async (
|
|
731
|
+
ctx: StageContext &
|
|
732
|
+
Pick<WorkflowContext, 'secrets' | 'internalModels' | 'log'>,
|
|
733
|
+
inputs: CopyInputs,
|
|
734
|
+
{ force }: { force: boolean },
|
|
735
|
+
): Promise<{ run: StageRun; copy: CopyPayload }> => {
|
|
736
|
+
// Only actual draft refusals exhaust editorial rounds. Worker failures
|
|
737
|
+
// preserve the checkpoint for recovery and cannot manufacture a review.
|
|
738
|
+
let run: StageRun;
|
|
739
|
+
|
|
740
|
+
try {
|
|
741
|
+
run = await runOne(ctx, 'write', { force });
|
|
742
|
+
} catch (error) {
|
|
743
|
+
if (
|
|
744
|
+
!(error instanceof CopyVerificationUnavailableError) ||
|
|
745
|
+
!shipWithoutVerifier.has(error.outcome) ||
|
|
746
|
+
ctx.signal?.aborted
|
|
747
|
+
) {
|
|
748
|
+
throw error;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
// The verifier stayed unusable through its tries (Botpress, 2026-09-15:
|
|
752
|
+
// six invalid reviews failed the pipeline). The report ships on its
|
|
753
|
+
// verified facts with the improvement note; the saved draft is kept.
|
|
754
|
+
ctx.log(
|
|
755
|
+
`copy verifier stayed ${error.outcome} after its tries; delivering the verified facts without the narrative`,
|
|
756
|
+
);
|
|
757
|
+
run = {
|
|
758
|
+
stage: 'write',
|
|
759
|
+
model: codexModel.model,
|
|
760
|
+
ok: false,
|
|
761
|
+
durationMs: 0,
|
|
762
|
+
usage: null,
|
|
763
|
+
errors: error.errors.map(
|
|
764
|
+
(message) => `verifier ${error.outcome}: ${message}`,
|
|
765
|
+
),
|
|
766
|
+
degraded: [],
|
|
767
|
+
summary: { attempts: defaultMaxPasses, verifier: error.outcome },
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
return { run, copy: await deliverableCopy(ctx, inputs, run) };
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
/** The answers a later stage still judges once a batch degraded;
|
|
775
|
+
* `allAnswers` stays the run's full set. */
|
|
776
|
+
const withoutAnswers = (
|
|
777
|
+
ctx: WorkflowContext,
|
|
778
|
+
files: readonly string[],
|
|
779
|
+
): WorkflowContext => {
|
|
780
|
+
const gone = new Set(files);
|
|
781
|
+
|
|
782
|
+
return {
|
|
783
|
+
...ctx,
|
|
784
|
+
answers: ctx.answers.filter((answer) => !gone.has(answer.file)),
|
|
785
|
+
};
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
const correctionTrailSchema = z.array(
|
|
789
|
+
z.looseObject({ outcome: z.string().optional() }),
|
|
790
|
+
);
|
|
791
|
+
|
|
792
|
+
type ScorecardFinish = { partialFailures: number; store: string };
|
|
793
|
+
|
|
794
|
+
/** What one run of the pipeline was worth (Andrei, 2026-09-13: measure
|
|
795
|
+
* the pipeline and iterate). Written to SCORECARD.json at the end, one
|
|
796
|
+
* shape every run, so runs compare. */
|
|
797
|
+
class Scorecard {
|
|
798
|
+
readonly #ctx: WorkflowContext;
|
|
799
|
+
readonly #startedAt: string;
|
|
800
|
+
readonly #runs: StageRun[];
|
|
801
|
+
readonly #stages: Record<string, unknown>[];
|
|
802
|
+
#finish: ScorecardFinish | null;
|
|
803
|
+
#copyOutcome: WorkflowResult['copyOutcome'];
|
|
804
|
+
|
|
805
|
+
constructor(ctx: WorkflowContext) {
|
|
806
|
+
this.#ctx = ctx;
|
|
807
|
+
this.#startedAt = new Date().toISOString();
|
|
808
|
+
this.#runs = [];
|
|
809
|
+
this.#stages = [];
|
|
810
|
+
this.#finish = null;
|
|
811
|
+
this.#copyOutcome = 'skipped';
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
finished(partialFailures: number, store: string) {
|
|
815
|
+
this.#finish = { partialFailures, store };
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
copy(outcome: WorkflowResult['copyOutcome']) {
|
|
819
|
+
this.#copyOutcome = outcome;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
stage(run: StageRun, pass?: number) {
|
|
823
|
+
this.#runs.push(run);
|
|
824
|
+
this.#stages.push({
|
|
825
|
+
stage: run.stage,
|
|
826
|
+
...(pass ? { pass } : {}),
|
|
827
|
+
ok: run.ok,
|
|
828
|
+
durationMs: run.durationMs,
|
|
829
|
+
usage: run.usage,
|
|
830
|
+
...run.summary,
|
|
831
|
+
...(run.degraded.length ? { degradedFiles: run.degraded } : {}),
|
|
832
|
+
...(run.errors.length
|
|
833
|
+
? { errors: run.errors.map((error) => error.slice(0, 300)) }
|
|
834
|
+
: {}),
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
async write(
|
|
839
|
+
verdict: WorkflowResult['verdict'],
|
|
840
|
+
): Promise<Record<string, unknown>> {
|
|
841
|
+
const { dir } = this.#ctx;
|
|
842
|
+
const review = await readStoredReview(dir);
|
|
843
|
+
const trailText =
|
|
844
|
+
(await readFile(path.join(dir, 'OUT', 'corrections.json'), 'utf8').catch(
|
|
845
|
+
() => '[]',
|
|
846
|
+
)) || '[]';
|
|
847
|
+
|
|
848
|
+
const trail = correctionTrailSchema.parse(JSON.parse(trailText));
|
|
849
|
+
const runs = this.#runs;
|
|
850
|
+
|
|
851
|
+
const total = (key: 'inputTokens' | 'outputTokens') => {
|
|
852
|
+
return runs.reduce((sum, run) => sum + (run.usage?.[key] ?? 0), 0);
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
const card = {
|
|
856
|
+
version: 1,
|
|
857
|
+
startedAt: this.#startedAt,
|
|
858
|
+
finishedAt: new Date().toISOString(),
|
|
859
|
+
model: codexModel.model,
|
|
860
|
+
answers: this.#ctx.answers.length,
|
|
861
|
+
verdict,
|
|
862
|
+
stages: this.#stages,
|
|
863
|
+
corrections: {
|
|
864
|
+
applied: trail.filter((entry) => entry.outcome === 'applied').length,
|
|
865
|
+
refused: trail.filter((entry) => entry.outcome?.startsWith('refused'))
|
|
866
|
+
.length,
|
|
867
|
+
},
|
|
868
|
+
reviewPasses: runs.filter((run) => run.stage === 'review').length,
|
|
869
|
+
failedCriteria: (review?.criteria ?? [])
|
|
870
|
+
.filter((criterion) => criterion.outcome === 'fail')
|
|
871
|
+
.map((criterion) => criterion.criterionId),
|
|
872
|
+
unresolved: review?.unresolved.length ?? 0,
|
|
873
|
+
finish: this.#finish,
|
|
874
|
+
copy: this.#copyOutcome,
|
|
875
|
+
degraded: runs.flatMap((run) => run.degraded),
|
|
876
|
+
durationMs: runs.reduce((sum, run) => sum + run.durationMs, 0),
|
|
877
|
+
usage: {
|
|
878
|
+
inputTokens: total('inputTokens'),
|
|
879
|
+
outputTokens: total('outputTokens'),
|
|
880
|
+
},
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
await writeFile(
|
|
884
|
+
path.join(dir, 'SCORECARD.json'),
|
|
885
|
+
JSON.stringify(card, null, 2),
|
|
886
|
+
);
|
|
887
|
+
this.#ctx.log(
|
|
888
|
+
`scorecard: ${verdict}, ${card.reviewPasses} pass(es), ${card.corrections.applied} corrections (${card.corrections.refused} refused), ${card.unresolved} unresolved, ${card.degraded.length} degraded, ${Math.round(card.durationMs / 60000)} min, ${Math.round(card.usage.inputTokens / 1000)}k in / ${Math.round(card.usage.outputTokens / 1000)}k out`,
|
|
889
|
+
);
|
|
890
|
+
|
|
891
|
+
return card;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
const reviewProgressSchema = z
|
|
896
|
+
.object({ rounds: z.number(), digest: z.string(), accepted: z.boolean() })
|
|
897
|
+
.nullable();
|
|
898
|
+
|
|
899
|
+
/** The whole loop over one work directory. Never throws for a judgment
|
|
900
|
+
* problem; the source is left open for the caller to close. */
|
|
901
|
+
type RunWorkflowOptions = {
|
|
902
|
+
maxPasses?: number;
|
|
903
|
+
force?: boolean;
|
|
904
|
+
write?: boolean;
|
|
905
|
+
/** Factual grounding over the run's capture manifest (the container
|
|
906
|
+
* job); a source that already carries a bundle needs none. */
|
|
907
|
+
ground?: GroundRun;
|
|
908
|
+
/** The report's logo for the validated copy, resolved once the copy
|
|
909
|
+
* stage is due (the job's; a local run has none). */
|
|
910
|
+
brandLogo?: () => Promise<AeoReportCopy['brandLogo'] | undefined>;
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* runWorkflow runs the loop over a prepared work directory. A run that
|
|
915
|
+
* throws records why in the run journal before the error travels on:
|
|
916
|
+
* run_interrupted when the host stopped the work, run_failed otherwise.
|
|
917
|
+
*/
|
|
918
|
+
export const runWorkflow = async (
|
|
919
|
+
prepared: WorkflowContext,
|
|
920
|
+
options: RunWorkflowOptions = {},
|
|
921
|
+
): Promise<WorkflowResult> => {
|
|
922
|
+
try {
|
|
923
|
+
return await runWorkflowSteps(prepared, options);
|
|
924
|
+
} catch (err) {
|
|
925
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
926
|
+
|
|
927
|
+
try {
|
|
928
|
+
await prepared.recorder?.record(
|
|
929
|
+
prepared.signal?.aborted ? 'run_interrupted' : 'run_failed',
|
|
930
|
+
{
|
|
931
|
+
error: err instanceof Error ? err.name : typeof err,
|
|
932
|
+
// Bounded: the message names what broke, not a dump of state.
|
|
933
|
+
reason: reason.slice(0, 500),
|
|
934
|
+
},
|
|
935
|
+
);
|
|
936
|
+
} catch (recordError) {
|
|
937
|
+
// The run's own failure is what the caller must see; a journal that
|
|
938
|
+
// cannot take the entry ends open, which reads as interrupted.
|
|
939
|
+
prepared.log(
|
|
940
|
+
`run journal: the failure could not be recorded: ${String(recordError).slice(0, 200)}`,
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
throw err;
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
|
|
948
|
+
const runWorkflowSteps = async (
|
|
949
|
+
prepared: WorkflowContext,
|
|
950
|
+
options: RunWorkflowOptions,
|
|
951
|
+
): Promise<WorkflowResult> => {
|
|
952
|
+
const force = options.force ?? false;
|
|
953
|
+
const maxPasses = Math.max(
|
|
954
|
+
1,
|
|
955
|
+
Math.min(options.maxPasses ?? defaultMaxPasses, defaultMaxPasses),
|
|
956
|
+
);
|
|
957
|
+
|
|
958
|
+
const scorecard = new Scorecard(prepared);
|
|
959
|
+
let ctx = prepared;
|
|
960
|
+
|
|
961
|
+
for (const stage of ['analyze', 'qualify'] as const) {
|
|
962
|
+
// Nothing judgment-related stops a run: a stage that accepted nothing
|
|
963
|
+
// delivers its empty output with every answer degraded.
|
|
964
|
+
const run = await runOne(ctx, stage, { force });
|
|
965
|
+
|
|
966
|
+
scorecard.stage(run);
|
|
967
|
+
|
|
968
|
+
if (run.degraded.length) {
|
|
969
|
+
ctx = withoutAnswers(ctx, run.degraded);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
await aggregate(ctx);
|
|
974
|
+
await ctx.checkpoint?.();
|
|
975
|
+
|
|
976
|
+
const progressFile = path.join(ctx.dir, 'REVIEW', 'progress.json');
|
|
977
|
+
const savedProgress = reviewProgressSchema.parse(
|
|
978
|
+
JSON.parse(await readFile(progressFile, 'utf8').catch(() => 'null')),
|
|
979
|
+
);
|
|
980
|
+
// Progress counts only while it describes the current reviewed state.
|
|
981
|
+
const progress =
|
|
982
|
+
!force && savedProgress?.digest === (await stageInputsDigest(ctx, 'review'))
|
|
983
|
+
? savedProgress
|
|
984
|
+
: null;
|
|
985
|
+
|
|
986
|
+
let rounds = progress?.rounds ?? 0;
|
|
987
|
+
let verdict: WorkflowResult['verdict'] = progress?.accepted
|
|
988
|
+
? 'accepted'
|
|
989
|
+
: 'needs_another_pass';
|
|
990
|
+
|
|
991
|
+
for (
|
|
992
|
+
let pass = rounds + 1;
|
|
993
|
+
verdict !== 'accepted' && pass <= maxPasses;
|
|
994
|
+
pass += 1
|
|
995
|
+
) {
|
|
996
|
+
// The same reviewer continues over its corrected state. Accepted
|
|
997
|
+
// batches stay accepted; no earlier stage is re-entered.
|
|
998
|
+
const run = await runOne(ctx, 'review', { force: pass > 1 || force, pass });
|
|
999
|
+
|
|
1000
|
+
scorecard.stage(run, pass);
|
|
1001
|
+
rounds = pass;
|
|
1002
|
+
|
|
1003
|
+
if (!run.ok) {
|
|
1004
|
+
ctx.log(
|
|
1005
|
+
`review pass ${pass} produced nothing the host could accept; the state stands as it is`,
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
if (Number(run.summary.corrections ?? 0) > 0) {
|
|
1010
|
+
await aggregate(ctx);
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
// A reused pass carries its recorded verdict; only an acceptance with
|
|
1014
|
+
// nothing corrected ends the scrutiny.
|
|
1015
|
+
if (
|
|
1016
|
+
run.ok &&
|
|
1017
|
+
!Number(run.summary.corrections ?? 0) &&
|
|
1018
|
+
!Number(run.summary.refusedCorrections ?? 0) &&
|
|
1019
|
+
run.summary.verdict === 'accepted'
|
|
1020
|
+
) {
|
|
1021
|
+
verdict = 'accepted';
|
|
1022
|
+
ctx.log(`accepted after ${pass} scrutiny pass${pass === 1 ? '' : 'es'}`);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
await mkdir(path.dirname(progressFile), { recursive: true });
|
|
1026
|
+
await writeFile(
|
|
1027
|
+
progressFile,
|
|
1028
|
+
JSON.stringify({
|
|
1029
|
+
rounds,
|
|
1030
|
+
digest: await stageInputsDigest(ctx, 'review'),
|
|
1031
|
+
accepted: verdict === 'accepted',
|
|
1032
|
+
}),
|
|
1033
|
+
);
|
|
1034
|
+
await ctx.checkpoint?.();
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
if (verdict !== 'accepted') {
|
|
1038
|
+
ctx.log(
|
|
1039
|
+
`not accepted after ${maxPasses} scrutiny passes; the report ships with the open notes in REVIEW/`,
|
|
1040
|
+
);
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
const degraded = prepared.answers
|
|
1044
|
+
.map((answer) => answer.file)
|
|
1045
|
+
.filter((file) => !ctx.answers.some((answer) => answer.file === file));
|
|
1046
|
+
let finished: FinishResult | null = null;
|
|
1047
|
+
|
|
1048
|
+
try {
|
|
1049
|
+
finished = await finish(ctx, {
|
|
1050
|
+
degraded,
|
|
1051
|
+
write: false,
|
|
1052
|
+
ground: options.ground,
|
|
1053
|
+
quality: await reportQuality(ctx.dir, {
|
|
1054
|
+
rounds,
|
|
1055
|
+
degraded,
|
|
1056
|
+
accepted: verdict === 'accepted',
|
|
1057
|
+
}),
|
|
1058
|
+
});
|
|
1059
|
+
scorecard.finished(finished.partialFailures.length, finished.written);
|
|
1060
|
+
} catch (error) {
|
|
1061
|
+
if (isBlocker(error, ctx.signal)) {
|
|
1062
|
+
throw error;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
ctx.log(`finish failed: ${String(error).slice(0, 400)}`);
|
|
1066
|
+
scorecard.finished(-1, 'failed');
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
// Copy enriches the completed measurement. Bounded review delivers either
|
|
1070
|
+
// the verified narrative or compiled facts with improvement notes.
|
|
1071
|
+
let copy: CopyPayload | null = null;
|
|
1072
|
+
let copyOutcome: WorkflowResult['copyOutcome'] = 'skipped';
|
|
1073
|
+
|
|
1074
|
+
if (finished) {
|
|
1075
|
+
try {
|
|
1076
|
+
const inputs = copyInputsOf(ctx.source, {
|
|
1077
|
+
brandLogo: await options.brandLogo?.(),
|
|
1078
|
+
});
|
|
1079
|
+
const copyContext = await withCopy(ctx, inputs);
|
|
1080
|
+
const { run: written, copy: delivered } = await writeReportCopy(
|
|
1081
|
+
copyContext,
|
|
1082
|
+
inputs,
|
|
1083
|
+
{ force },
|
|
1084
|
+
);
|
|
1085
|
+
|
|
1086
|
+
scorecard.stage(written);
|
|
1087
|
+
copy = delivered;
|
|
1088
|
+
copyOutcome = 'validated';
|
|
1089
|
+
|
|
1090
|
+
if (copy.quality) {
|
|
1091
|
+
const quality = finished.snapshot.meta.quality;
|
|
1092
|
+
|
|
1093
|
+
if (!quality) {
|
|
1094
|
+
throw new Error(
|
|
1095
|
+
`The finished snapshot has no quality record: ${finished.snapshotFile}.`,
|
|
1096
|
+
);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
quality.needsImprovement = true;
|
|
1100
|
+
quality.issues.push(...copy.quality.issues);
|
|
1101
|
+
await writeFile(
|
|
1102
|
+
finished.snapshotFile,
|
|
1103
|
+
JSON.stringify(finished.snapshot, null, 2),
|
|
1104
|
+
);
|
|
1105
|
+
await ctx.checkpoint?.();
|
|
1106
|
+
}
|
|
1107
|
+
} catch (error) {
|
|
1108
|
+
if (isBlocker(error, ctx.signal)) {
|
|
1109
|
+
throw error;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
ctx.log(`copy stage failed: ${String(error).slice(0, 400)}`);
|
|
1113
|
+
copyOutcome = 'errored';
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
scorecard.copy(copyOutcome);
|
|
1118
|
+
|
|
1119
|
+
if (finished && options.write) {
|
|
1120
|
+
finished = await writeFinished(ctx.source, finished);
|
|
1121
|
+
scorecard.finished(finished.partialFailures.length, finished.written);
|
|
1122
|
+
ctx.log(
|
|
1123
|
+
`store: ${finished.written}${finished.writeMessage ? ` (${finished.writeMessage})` : ''}`,
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
const finalScorecard = await scorecard.write(verdict);
|
|
1128
|
+
|
|
1129
|
+
await ctx.recorder?.record('run_completed', {
|
|
1130
|
+
verdict,
|
|
1131
|
+
copyOutcome,
|
|
1132
|
+
finished: finished !== null,
|
|
1133
|
+
degradedAnswers: degraded.length,
|
|
1134
|
+
});
|
|
1135
|
+
await ctx.checkpoint?.();
|
|
1136
|
+
|
|
1137
|
+
return {
|
|
1138
|
+
verdict,
|
|
1139
|
+
degraded,
|
|
1140
|
+
finish: finished,
|
|
1141
|
+
copy,
|
|
1142
|
+
copyOutcome,
|
|
1143
|
+
scorecard: finalScorecard,
|
|
1144
|
+
};
|
|
1145
|
+
};
|
|
1146
|
+
|
|
1147
|
+
/** What the loop must not absorb as a host defect: a budget or deadline
|
|
1148
|
+
* the job blocks on resumably, a grounding integrity failure, or the host
|
|
1149
|
+
* stopping the work. Everything else degrades the run and is recorded. */
|
|
1150
|
+
const isBlocker = (
|
|
1151
|
+
error: unknown,
|
|
1152
|
+
signal: AbortSignal | undefined,
|
|
1153
|
+
): boolean => {
|
|
1154
|
+
return (
|
|
1155
|
+
error instanceof ModelBudgetError ||
|
|
1156
|
+
error instanceof GroundingIntegrityError ||
|
|
1157
|
+
signal?.aborted === true
|
|
1158
|
+
);
|
|
1159
|
+
};
|