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,1170 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { canonicalJson } from '../lib/canonical-json';
|
|
3
|
+
import banlist from '../author/banlist.json';
|
|
4
|
+
import {
|
|
5
|
+
aeoAuditConfigSchema,
|
|
6
|
+
type AeoAuditConfig,
|
|
7
|
+
type AeoSnapshot,
|
|
8
|
+
} from '../schema';
|
|
9
|
+
import type { GroundingBundle } from '../grounding/schema';
|
|
10
|
+
import { validateGroundingBundle } from '../grounding/validation';
|
|
11
|
+
import {
|
|
12
|
+
internalModelRoleDigest,
|
|
13
|
+
resolveInternalModelProfile,
|
|
14
|
+
type InternalModelRoleConfig,
|
|
15
|
+
} from '../models/profiles';
|
|
16
|
+
import { ModelBudgetError } from '../models/accounting';
|
|
17
|
+
import { ModelCallAbortError } from '../models/errors';
|
|
18
|
+
import { structuredFailureDiagnostic } from '../models/failure-diagnostics';
|
|
19
|
+
import { isRecord } from '../lib/type-guards';
|
|
20
|
+
import { credentialDetected } from './credentials';
|
|
21
|
+
import {
|
|
22
|
+
buildFactCatalog,
|
|
23
|
+
factCatalogVersion,
|
|
24
|
+
factFingerprint,
|
|
25
|
+
methodologyNote,
|
|
26
|
+
type ReportFact,
|
|
27
|
+
} from './facts';
|
|
28
|
+
import {
|
|
29
|
+
aeoAgentCopyDraftSchema,
|
|
30
|
+
aeoReportCopySchema,
|
|
31
|
+
pendingReportCopy,
|
|
32
|
+
type AeoAgentCopyDraft,
|
|
33
|
+
type AeoReportCopy,
|
|
34
|
+
type CopyBlock,
|
|
35
|
+
} from './copy-schema';
|
|
36
|
+
|
|
37
|
+
export const copyCheckerVersion = 7;
|
|
38
|
+
export const premiseVerifierPromptVersion = 3;
|
|
39
|
+
|
|
40
|
+
/** Host framing every narrative block rests on whether or not the writer
|
|
41
|
+
* declares it: the report identity and publisher, the captured surfaces,
|
|
42
|
+
* the mention/citation definitions and the capture count. Verification
|
|
43
|
+
* supplies them with every narrative block; the verifier's editing turn
|
|
44
|
+
* keeps them in reach. */
|
|
45
|
+
export const narrativeContextFactIds = [
|
|
46
|
+
'scope:report',
|
|
47
|
+
'scope:surfaces',
|
|
48
|
+
'scope:mentions-citations',
|
|
49
|
+
'aggregate:captured',
|
|
50
|
+
] as const;
|
|
51
|
+
|
|
52
|
+
export type CopyValidationError = {
|
|
53
|
+
code: string;
|
|
54
|
+
path: string;
|
|
55
|
+
message: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** Distinguishable outcomes (orchestrator spec §7.3): a writer is asked to
|
|
59
|
+
* revise only for `invalid_copy`; every other outcome retries verification of
|
|
60
|
+
* the same draft, blocks, or stops. */
|
|
61
|
+
export type CopyValidationOutcome =
|
|
62
|
+
| 'valid'
|
|
63
|
+
| 'invalid_copy'
|
|
64
|
+
| 'invalid_review'
|
|
65
|
+
| 'verifier_unavailable'
|
|
66
|
+
| 'budget_exhausted'
|
|
67
|
+
| 'cancelled'
|
|
68
|
+
| 'integrity_error';
|
|
69
|
+
|
|
70
|
+
export type VerifierFailureOutcome = Exclude<
|
|
71
|
+
CopyValidationOutcome,
|
|
72
|
+
'valid' | 'invalid_copy'
|
|
73
|
+
>;
|
|
74
|
+
|
|
75
|
+
type InvalidReviewReason =
|
|
76
|
+
'unreviewed_blocks' | 'duplicate_verdict' | 'inconsistent_verdict';
|
|
77
|
+
|
|
78
|
+
const describeInvalidReview = (
|
|
79
|
+
reason: InvalidReviewReason,
|
|
80
|
+
blockCount: number,
|
|
81
|
+
) => {
|
|
82
|
+
switch (reason) {
|
|
83
|
+
case 'unreviewed_blocks': {
|
|
84
|
+
return `Semantic verification returned no verdict for ${blockCount} block(s) after repeated requests`;
|
|
85
|
+
}
|
|
86
|
+
case 'duplicate_verdict': {
|
|
87
|
+
return 'Semantic verification returned more than one verdict for a block';
|
|
88
|
+
}
|
|
89
|
+
case 'inconsistent_verdict': {
|
|
90
|
+
return `Semantic verification returned a verdict that contradicts its own findings or skipped a declared premise for ${blockCount} block(s)`;
|
|
91
|
+
}
|
|
92
|
+
default: {
|
|
93
|
+
const unhandled: never = reason;
|
|
94
|
+
|
|
95
|
+
throw new Error(`Unhandled invalid review reason: ${String(unhandled)}.`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** The verifier answered, but not with a verdict the host can act on: a
|
|
101
|
+
* block left without one even after asking again, two verdicts for one
|
|
102
|
+
* block, a verdict that contradicts its own premise findings, or a declared
|
|
103
|
+
* premise it skipped. That is a failed review of an unchanged draft
|
|
104
|
+
* (`invalid_review`), never a finding against the copy: only block paths
|
|
105
|
+
* travel with it, no prose. */
|
|
106
|
+
export class InvalidReviewError extends Error {
|
|
107
|
+
readonly reason: InvalidReviewReason;
|
|
108
|
+
readonly paths: readonly string[];
|
|
109
|
+
/** Host-written rule names per block, never provider text. */
|
|
110
|
+
readonly details: readonly string[];
|
|
111
|
+
|
|
112
|
+
constructor(
|
|
113
|
+
reason: InvalidReviewReason,
|
|
114
|
+
paths: readonly string[],
|
|
115
|
+
details: readonly string[] = [],
|
|
116
|
+
) {
|
|
117
|
+
super(describeInvalidReview(reason, paths.length));
|
|
118
|
+
|
|
119
|
+
this.name = 'InvalidReviewError';
|
|
120
|
+
this.reason = reason;
|
|
121
|
+
this.paths = paths;
|
|
122
|
+
this.details = details;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* classifyVerifierFailure maps an error to an outcome. Only allowlisted labels
|
|
128
|
+
* leave the error; no provider body or prompt text.
|
|
129
|
+
*/
|
|
130
|
+
export const classifyVerifierFailure = (
|
|
131
|
+
error: unknown,
|
|
132
|
+
signal?: AbortSignal,
|
|
133
|
+
): VerifierFailureOutcome => {
|
|
134
|
+
if (signal?.aborted && !(error instanceof ModelCallAbortError)) {
|
|
135
|
+
return 'cancelled';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (error instanceof ModelCallAbortError) {
|
|
139
|
+
return error.reason === 'cancelled' ? 'cancelled' : 'verifier_unavailable';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (error instanceof ModelBudgetError) {
|
|
143
|
+
return error.kind === 'exhausted' || error.kind === 'deadline'
|
|
144
|
+
? 'budget_exhausted'
|
|
145
|
+
: 'integrity_error';
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (error instanceof InvalidReviewError) {
|
|
149
|
+
return 'invalid_review';
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (error instanceof Error) {
|
|
153
|
+
if (error.message === 'model_input_limit') {
|
|
154
|
+
return 'invalid_review';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (error.message === 'model_output_limit') {
|
|
158
|
+
return 'invalid_review';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (error.name === 'ZodError') {
|
|
162
|
+
return 'invalid_review';
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const diagnostic = structuredFailureDiagnostic(error, signal);
|
|
167
|
+
|
|
168
|
+
if (diagnostic.classification === 'schema') {
|
|
169
|
+
return 'invalid_review';
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (diagnostic.classification === 'outputlimit') {
|
|
173
|
+
return 'invalid_review';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (diagnostic.classification === 'abort') {
|
|
177
|
+
return 'cancelled';
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return 'verifier_unavailable';
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const verifierFailureCodes: Record<VerifierFailureOutcome, string> = {
|
|
184
|
+
invalid_review: 'premise_verifier_invalid',
|
|
185
|
+
verifier_unavailable: 'premise_verifier_unavailable',
|
|
186
|
+
budget_exhausted: 'model_budget_exhausted',
|
|
187
|
+
cancelled: 'cancelled',
|
|
188
|
+
integrity_error: 'integrity_error',
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export type RecommendationInput = {
|
|
192
|
+
text: string;
|
|
193
|
+
kind: 'recommendation' | 'narrative' | 'human_copy';
|
|
194
|
+
intendedAction: string | null;
|
|
195
|
+
premises: { proposition: string; basisFactIds: string[] }[];
|
|
196
|
+
facts: ReportFact[];
|
|
197
|
+
path: string;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export type RecommendationVerifier = (
|
|
201
|
+
recommendations: RecommendationInput[],
|
|
202
|
+
signal?: AbortSignal,
|
|
203
|
+
) => Promise<{
|
|
204
|
+
valid: boolean;
|
|
205
|
+
errors: string[];
|
|
206
|
+
issues?: CopyValidationError[];
|
|
207
|
+
model: string;
|
|
208
|
+
basisFactIds?: string[];
|
|
209
|
+
}>;
|
|
210
|
+
|
|
211
|
+
type CopyDependencies = {
|
|
212
|
+
catalogVersion: number;
|
|
213
|
+
groundingDigest: string | null;
|
|
214
|
+
sourceBundleDigest: string | null;
|
|
215
|
+
assessmentDigests: Record<string, string>;
|
|
216
|
+
verifierProfileDigest: string;
|
|
217
|
+
verifierPromptVersion: number;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
export type AgentCopyProvenance = {
|
|
221
|
+
kind: 'agent';
|
|
222
|
+
runId: string;
|
|
223
|
+
draft: AeoAgentCopyDraft;
|
|
224
|
+
factFingerprints: Record<string, string>;
|
|
225
|
+
} & CopyDependencies;
|
|
226
|
+
|
|
227
|
+
export type HumanCopyProvenance = {
|
|
228
|
+
kind: 'human';
|
|
229
|
+
runId: string;
|
|
230
|
+
factFingerprints: Record<string, string>;
|
|
231
|
+
} & CopyDependencies;
|
|
232
|
+
|
|
233
|
+
export type CopyProvenance = AgentCopyProvenance | HumanCopyProvenance;
|
|
234
|
+
|
|
235
|
+
export type CopyValidationReceipt = {
|
|
236
|
+
checkerVersion: number;
|
|
237
|
+
runId: string;
|
|
238
|
+
reportKey: string;
|
|
239
|
+
configVersion: number | null;
|
|
240
|
+
configDigest: string;
|
|
241
|
+
digest: string;
|
|
242
|
+
verifierModel: string;
|
|
243
|
+
verifierProfile: InternalModelRoleConfig;
|
|
244
|
+
validatedAt: string;
|
|
245
|
+
} & CopyDependencies;
|
|
246
|
+
|
|
247
|
+
export type CopyValidationResult = {
|
|
248
|
+
valid: boolean;
|
|
249
|
+
errors: CopyValidationError[];
|
|
250
|
+
outcome: CopyValidationOutcome;
|
|
251
|
+
copy?: AeoReportCopy;
|
|
252
|
+
provenance?: AgentCopyProvenance;
|
|
253
|
+
receipt?: CopyValidationReceipt;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export const validateAgentCopy = async (args: {
|
|
257
|
+
draft: unknown;
|
|
258
|
+
config: AeoAuditConfig;
|
|
259
|
+
snapshot: AeoSnapshot;
|
|
260
|
+
runId: string;
|
|
261
|
+
configVersion?: number;
|
|
262
|
+
grounding?: GroundingBundle;
|
|
263
|
+
verifierProfile?: InternalModelRoleConfig;
|
|
264
|
+
verifier: RecommendationVerifier;
|
|
265
|
+
previous?: AeoReportCopy | null;
|
|
266
|
+
brandLogo?: AeoReportCopy['brandLogo'];
|
|
267
|
+
secrets?: readonly string[];
|
|
268
|
+
signal?: AbortSignal;
|
|
269
|
+
}): Promise<CopyValidationResult> => {
|
|
270
|
+
const errors: CopyValidationError[] = [];
|
|
271
|
+
const fail = (code: string, path: string, message: string) => {
|
|
272
|
+
errors.push({ code, path, message });
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
if (credentialDetected(JSON.stringify(args.draft), args.secrets)) {
|
|
276
|
+
return {
|
|
277
|
+
valid: false,
|
|
278
|
+
outcome: 'invalid_copy',
|
|
279
|
+
errors: [
|
|
280
|
+
{
|
|
281
|
+
code: 'credential_detected',
|
|
282
|
+
path: '',
|
|
283
|
+
message: 'Credential-shaped output is forbidden',
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const parsed = aeoAgentCopyDraftSchema.safeParse(args.draft);
|
|
290
|
+
|
|
291
|
+
if (!parsed.success) {
|
|
292
|
+
return {
|
|
293
|
+
valid: false,
|
|
294
|
+
outcome: 'invalid_copy',
|
|
295
|
+
errors: parsed.error.issues.map((issue) => ({
|
|
296
|
+
code: 'schema_invalid',
|
|
297
|
+
path: issue.path.join('.'),
|
|
298
|
+
message: issue.message,
|
|
299
|
+
})),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const draft = parsed.data;
|
|
304
|
+
|
|
305
|
+
if (draft.hero && !draft.intro.some((block) => block.kind === 'narrative')) {
|
|
306
|
+
return {
|
|
307
|
+
valid: false,
|
|
308
|
+
outcome: 'invalid_copy',
|
|
309
|
+
errors: [
|
|
310
|
+
{
|
|
311
|
+
code: 'narrative_format_invalid',
|
|
312
|
+
path: 'hero',
|
|
313
|
+
message: 'The final opening requires a completed insight narrative',
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const hasSectionCopy = Object.values(draft.sections).some(
|
|
320
|
+
(section) =>
|
|
321
|
+
section.subtitle.length > 0 ||
|
|
322
|
+
(section.perceptionCopy?.length ?? 0) > 0 ||
|
|
323
|
+
(section.retrievalCopy?.length ?? 0) > 0,
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
if (
|
|
327
|
+
draft.intro.some((block) => block.kind === 'narrative') &&
|
|
328
|
+
(draft.intro.length !== 1 ||
|
|
329
|
+
(draft.actionPlan?.length ?? 0) > 0 ||
|
|
330
|
+
hasSectionCopy)
|
|
331
|
+
) {
|
|
332
|
+
return {
|
|
333
|
+
valid: false,
|
|
334
|
+
outcome: 'invalid_copy',
|
|
335
|
+
errors: [
|
|
336
|
+
{
|
|
337
|
+
code: 'narrative_format_invalid',
|
|
338
|
+
path: 'intro',
|
|
339
|
+
message:
|
|
340
|
+
'Write one concise introduction; tables own the section measurements and action plans are not requested',
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const profile =
|
|
347
|
+
args.verifierProfile ?? resolveInternalModelProfile().roles.premiseVerifier;
|
|
348
|
+
let catalog;
|
|
349
|
+
|
|
350
|
+
try {
|
|
351
|
+
if (args.grounding) {
|
|
352
|
+
validateGroundingBundle(args.grounding, {
|
|
353
|
+
reportKey: args.config.reportKey,
|
|
354
|
+
runId: args.runId,
|
|
355
|
+
configVersion: args.configVersion,
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
catalog = buildFactCatalog({
|
|
360
|
+
snapshot: args.snapshot,
|
|
361
|
+
config: args.config,
|
|
362
|
+
runId: args.runId,
|
|
363
|
+
grounding: args.grounding,
|
|
364
|
+
});
|
|
365
|
+
} catch {
|
|
366
|
+
return {
|
|
367
|
+
valid: false,
|
|
368
|
+
outcome: 'integrity_error',
|
|
369
|
+
errors: [
|
|
370
|
+
{
|
|
371
|
+
code: 'grounding_invalid',
|
|
372
|
+
path: 'grounding',
|
|
373
|
+
message: 'Grounding does not match the immutable run and config',
|
|
374
|
+
},
|
|
375
|
+
],
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const facts = new Map(catalog.facts.map((fact) => [fact.factId, fact]));
|
|
380
|
+
const used = new Map<string, ReportFact>();
|
|
381
|
+
const recommendations: RecommendationInput[] = [];
|
|
382
|
+
const sectionKeys = new Set(
|
|
383
|
+
args.config.sections.map((section) => section.key),
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
for (const key of sectionKeys) {
|
|
387
|
+
if (!Object.hasOwn(draft.sections, key)) {
|
|
388
|
+
fail(
|
|
389
|
+
'section_missing',
|
|
390
|
+
`sections.${key}`,
|
|
391
|
+
'Every configured section needs copy',
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
for (const key of Object.keys(draft.sections)) {
|
|
397
|
+
if (!sectionKeys.has(key)) {
|
|
398
|
+
fail('section_missing', `sections.${key}`, 'Unknown section');
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const select = (id: string, section: string | null, path: string) => {
|
|
403
|
+
const fact = facts.get(id);
|
|
404
|
+
|
|
405
|
+
if (
|
|
406
|
+
!fact ||
|
|
407
|
+
(section !== null &&
|
|
408
|
+
(fact.kind === 'assessment' || fact.kind === 'observed_claim'
|
|
409
|
+
? !fact.candidate.occurrences.some(
|
|
410
|
+
(occurrence) => occurrence.section === section,
|
|
411
|
+
)
|
|
412
|
+
: fact.section !== section && fact.section !== null))
|
|
413
|
+
) {
|
|
414
|
+
fail(
|
|
415
|
+
'fact_reference_invalid',
|
|
416
|
+
path,
|
|
417
|
+
`Unknown or out-of-scope fact: ${id}`,
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
used.set(id, fact);
|
|
424
|
+
|
|
425
|
+
return fact;
|
|
426
|
+
};
|
|
427
|
+
const compile = (
|
|
428
|
+
blocks: CopyBlock[],
|
|
429
|
+
section: string | null,
|
|
430
|
+
path: string,
|
|
431
|
+
): string => {
|
|
432
|
+
return blocks
|
|
433
|
+
.map((block, index) => {
|
|
434
|
+
const location = `${path}.${index}`;
|
|
435
|
+
|
|
436
|
+
if (block.kind === 'fact') {
|
|
437
|
+
return select(block.factId, section, location)?.sentence ?? '';
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (block.kind === 'assessment') {
|
|
441
|
+
return (
|
|
442
|
+
select(`assessment:${block.assessmentId}`, section, location)
|
|
443
|
+
?.sentence ?? ''
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (
|
|
448
|
+
block.kind === 'narrative' &&
|
|
449
|
+
!['intro', 'hero.title', 'hero.subtitle'].includes(path)
|
|
450
|
+
) {
|
|
451
|
+
fail(
|
|
452
|
+
'narrative_location_invalid',
|
|
453
|
+
location,
|
|
454
|
+
'Narrative belongs in the report introduction or final opening',
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// A premise already declares its basis; a block that cites it only
|
|
459
|
+
// in the premise is complete, not wrong. The verifier sees the union.
|
|
460
|
+
const basisIds = new Set([
|
|
461
|
+
...block.basisFactIds,
|
|
462
|
+
...block.premises.flatMap((premise) => premise.basisFactIds),
|
|
463
|
+
// The host knows the report's framing even when the writer uses
|
|
464
|
+
// it implicitly instead of as a declared premise.
|
|
465
|
+
...(block.kind === 'narrative' ? narrativeContextFactIds : []),
|
|
466
|
+
]);
|
|
467
|
+
const bases = [...basisIds]
|
|
468
|
+
.map((id) => select(id, section, location))
|
|
469
|
+
.filter((fact): fact is ReportFact => fact !== null);
|
|
470
|
+
const text = block.text;
|
|
471
|
+
|
|
472
|
+
if (
|
|
473
|
+
block.kind === 'recommendation' &&
|
|
474
|
+
!/^(?:Consider|Review|Test|Create|Add|Update|Check|Compare|Improve|Explore|Document|Publish|Clarify|Measure|Investigate|Verify|Develop|Build|Try)\b/.test(
|
|
475
|
+
text,
|
|
476
|
+
)
|
|
477
|
+
) {
|
|
478
|
+
fail(
|
|
479
|
+
'unverified_claim_asserted',
|
|
480
|
+
location,
|
|
481
|
+
'Recommendations must describe proposed work',
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (
|
|
486
|
+
block.kind === 'recommendation' &&
|
|
487
|
+
/\d|\b(?:percent|percentage|twice|double|half|first|best|worst|leading|higher|lower|more than|less than|most|least|outperform|false|incorrect|wrong|proven|guarantee)\b|["“”]/i.test(
|
|
488
|
+
text,
|
|
489
|
+
)
|
|
490
|
+
) {
|
|
491
|
+
fail(
|
|
492
|
+
'unverified_claim_asserted',
|
|
493
|
+
location,
|
|
494
|
+
'Recommendations cannot assert measurements, rankings, quotations, or proven errors',
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (
|
|
499
|
+
/(?:ignore|override|disregard).{0,40}(?:instruction|rule|prompt)|(?:system|developer)\s*(?:message|prompt)|(?:reveal|print|send).{0,30}(?:secret|token|credential)/i.test(
|
|
500
|
+
text,
|
|
501
|
+
)
|
|
502
|
+
) {
|
|
503
|
+
fail(
|
|
504
|
+
'snapshot_instruction_detected',
|
|
505
|
+
location,
|
|
506
|
+
'Instructions in source material cannot enter copy',
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const lower = text.toLowerCase();
|
|
511
|
+
|
|
512
|
+
if (
|
|
513
|
+
banlist.phrases.some((phrase) => lower.includes(phrase)) ||
|
|
514
|
+
banlist.characters.some((character) => text.includes(character))
|
|
515
|
+
) {
|
|
516
|
+
fail(
|
|
517
|
+
'voice_rule_violation',
|
|
518
|
+
location,
|
|
519
|
+
'Rewrite the flagged stock phrase or punctuation',
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
recommendations.push({
|
|
524
|
+
text,
|
|
525
|
+
kind: block.kind,
|
|
526
|
+
intendedAction:
|
|
527
|
+
block.kind === 'recommendation' ? block.intendedAction : null,
|
|
528
|
+
premises: block.premises,
|
|
529
|
+
facts: bases,
|
|
530
|
+
path: location,
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
return text;
|
|
534
|
+
})
|
|
535
|
+
.join(' ');
|
|
536
|
+
};
|
|
537
|
+
const copy = pendingReportCopy(args.config);
|
|
538
|
+
copy.intro = compile(draft.intro, null, 'intro');
|
|
539
|
+
|
|
540
|
+
if (
|
|
541
|
+
draft.intro.some((block) => block.kind === 'narrative') &&
|
|
542
|
+
!copy.intro.toLowerCase().includes(args.config.brand.name.toLowerCase())
|
|
543
|
+
) {
|
|
544
|
+
fail('intro_not_specific', 'intro', 'Name the company in its introduction');
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (draft.hero) {
|
|
548
|
+
const pendingTitle = copy.title;
|
|
549
|
+
copy.title = compile([draft.hero.title], null, 'hero.title');
|
|
550
|
+
copy.subtitle = compile([draft.hero.subtitle], null, 'hero.subtitle');
|
|
551
|
+
copy.metaDescription = copy.subtitle;
|
|
552
|
+
|
|
553
|
+
if (
|
|
554
|
+
!copy.title
|
|
555
|
+
.toLowerCase()
|
|
556
|
+
.includes(args.config.brand.name.toLowerCase()) ||
|
|
557
|
+
copy.title.toLowerCase() === pendingTitle.toLowerCase()
|
|
558
|
+
) {
|
|
559
|
+
fail(
|
|
560
|
+
'hero_not_specific',
|
|
561
|
+
'hero.title',
|
|
562
|
+
'Name the company and frame its measured market in the headline',
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
for (const [key, section] of Object.entries(draft.sections)) {
|
|
568
|
+
if (!copy.sections[key]) {
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
copy.sections[key].subtitle = compile(
|
|
573
|
+
section.subtitle,
|
|
574
|
+
key,
|
|
575
|
+
`sections.${key}.subtitle`,
|
|
576
|
+
);
|
|
577
|
+
|
|
578
|
+
if (section.perceptionCopy) {
|
|
579
|
+
copy.sections[key].perceptionCopy = compile(
|
|
580
|
+
section.perceptionCopy,
|
|
581
|
+
key,
|
|
582
|
+
`sections.${key}.perceptionCopy`,
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
if (section.retrievalCopy) {
|
|
587
|
+
copy.sections[key].retrievalCopy = compile(
|
|
588
|
+
section.retrievalCopy,
|
|
589
|
+
key,
|
|
590
|
+
`sections.${key}.retrievalCopy`,
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (draft.actionPlan?.length) {
|
|
596
|
+
copy.actionPlan = {
|
|
597
|
+
heading: 'What to work on next',
|
|
598
|
+
intro: 'Proposed work based on this audit.',
|
|
599
|
+
items: draft.actionPlan.map((item, index) => ({
|
|
600
|
+
title: `Suggested action ${index + 1}`,
|
|
601
|
+
body: compile(item.body, null, `actionPlan.${index}.body`),
|
|
602
|
+
})),
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
copy.methodologyNote = methodologyNote(args.snapshot);
|
|
607
|
+
copy.footerNote =
|
|
608
|
+
'This report records the answers captured during this audit. AI answers can change.';
|
|
609
|
+
const brandLogo = args.previous?.brandLogo ?? args.brandLogo;
|
|
610
|
+
|
|
611
|
+
if (brandLogo) {
|
|
612
|
+
copy.brandLogo = brandLogo;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (args.previous?.heroEyebrow) {
|
|
616
|
+
copy.heroEyebrow = args.previous.heroEyebrow;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const checked = aeoReportCopySchema.safeParse(copy);
|
|
620
|
+
|
|
621
|
+
if (!checked.success) {
|
|
622
|
+
checked.error.issues.forEach((issue) =>
|
|
623
|
+
fail('schema_invalid', issue.path.join('.'), issue.message),
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (errors.length) {
|
|
628
|
+
return { valid: false, outcome: 'invalid_copy', errors };
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
let verifierModel = 'no-recommendations';
|
|
632
|
+
|
|
633
|
+
if (recommendations.length) {
|
|
634
|
+
let result: Awaited<ReturnType<RecommendationVerifier>>;
|
|
635
|
+
|
|
636
|
+
try {
|
|
637
|
+
result = await args.verifier(recommendations, args.signal);
|
|
638
|
+
} catch (error) {
|
|
639
|
+
// The draft is unchanged and retained. Only the verifier is retried;
|
|
640
|
+
// an unavailable verifier never asks the writer for another draft.
|
|
641
|
+
const outcome = classifyVerifierFailure(error, args.signal);
|
|
642
|
+
// The reason and the block paths are the whole diagnostic: without
|
|
643
|
+
// them an operator sees only that a review was refused (2026-09-12).
|
|
644
|
+
// Block paths carry no prose; nothing from the provider is copied.
|
|
645
|
+
const detail =
|
|
646
|
+
error instanceof InvalidReviewError
|
|
647
|
+
? ` (${error.reason}: ${(error.details.length ? error.details : error.paths).join('; ')})`
|
|
648
|
+
: '';
|
|
649
|
+
|
|
650
|
+
return {
|
|
651
|
+
valid: false,
|
|
652
|
+
outcome,
|
|
653
|
+
errors: [
|
|
654
|
+
{
|
|
655
|
+
code: verifierFailureCodes[outcome],
|
|
656
|
+
path: 'recommendations',
|
|
657
|
+
// Compact, rule first: the journal stores a bounded message and
|
|
658
|
+
// the rule name is what an operator needs from it.
|
|
659
|
+
message:
|
|
660
|
+
outcome === 'invalid_review'
|
|
661
|
+
? `invalid review${detail}`
|
|
662
|
+
: 'Semantic verification was unavailable',
|
|
663
|
+
},
|
|
664
|
+
],
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
verifierModel = result.model;
|
|
669
|
+
|
|
670
|
+
if (
|
|
671
|
+
typeof result.model !== 'string' ||
|
|
672
|
+
!result.model.trim() ||
|
|
673
|
+
(args.grounding && result.model !== profile.model) ||
|
|
674
|
+
!Array.isArray(result.errors)
|
|
675
|
+
) {
|
|
676
|
+
return {
|
|
677
|
+
valid: false,
|
|
678
|
+
outcome: 'invalid_review',
|
|
679
|
+
errors: [
|
|
680
|
+
{
|
|
681
|
+
code: 'premise_verifier_invalid',
|
|
682
|
+
path: 'recommendations',
|
|
683
|
+
message: 'Semantic verification did not use the pinned verifier',
|
|
684
|
+
},
|
|
685
|
+
],
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
if (result.valid !== true || result.errors.length !== 0) {
|
|
690
|
+
const reasons = result.errors.join('; ');
|
|
691
|
+
|
|
692
|
+
fail(
|
|
693
|
+
'claim_not_in_snapshot',
|
|
694
|
+
'recommendations',
|
|
695
|
+
reasons === '' ? 'Verifier rejected the recommendations' : reasons,
|
|
696
|
+
);
|
|
697
|
+
|
|
698
|
+
// Structured issue details give the writer exact locations to repair.
|
|
699
|
+
for (const issue of (result.issues ?? []).slice(0, 20)) {
|
|
700
|
+
if (recommendations.some((input) => input.path === issue.path)) {
|
|
701
|
+
fail(
|
|
702
|
+
'premise_unsupported',
|
|
703
|
+
issue.path,
|
|
704
|
+
credentialDetected(issue.message, args.secrets)
|
|
705
|
+
? 'Unsupported premise; sensitive diagnostic omitted'
|
|
706
|
+
: issue.message
|
|
707
|
+
.replace(/[\u0000-\u001f\u007f]/g, ' ')
|
|
708
|
+
.slice(0, 1000),
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
if (errors.length) {
|
|
716
|
+
return { valid: false, outcome: 'invalid_copy', errors };
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
const provenance: AgentCopyProvenance = {
|
|
720
|
+
kind: 'agent',
|
|
721
|
+
runId: args.runId,
|
|
722
|
+
...copyDependencies(args.grounding, profile),
|
|
723
|
+
draft,
|
|
724
|
+
factFingerprints: Object.fromEntries(
|
|
725
|
+
[...used].map(([id, fact]) => [id, factFingerprint(fact)]),
|
|
726
|
+
),
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
return {
|
|
730
|
+
valid: true,
|
|
731
|
+
outcome: 'valid',
|
|
732
|
+
errors: [],
|
|
733
|
+
copy,
|
|
734
|
+
provenance,
|
|
735
|
+
receipt: {
|
|
736
|
+
checkerVersion: copyCheckerVersion,
|
|
737
|
+
runId: args.runId,
|
|
738
|
+
reportKey: args.config.reportKey,
|
|
739
|
+
configVersion:
|
|
740
|
+
args.configVersion ??
|
|
741
|
+
args.grounding?.configIdentity.configVersion ??
|
|
742
|
+
null,
|
|
743
|
+
configDigest: jsonDigest(args.config),
|
|
744
|
+
...copyDependencies(args.grounding, profile),
|
|
745
|
+
digest: copyReceiptDigest(copy, provenance),
|
|
746
|
+
verifierModel,
|
|
747
|
+
verifierProfile: profile,
|
|
748
|
+
validatedAt: new Date().toISOString(),
|
|
749
|
+
},
|
|
750
|
+
};
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
/** Receipts from this checker on hash the reviewed content without the brand
|
|
754
|
+
* logo. The logo is presentation, not reviewed prose: it is applied to the
|
|
755
|
+
* copy after validation, so a receipt that bound the logo failed at
|
|
756
|
+
* publication for every first report with one (harness era, 2026-09).
|
|
757
|
+
* Earlier receipts hashed the exact bytes they were issued for and keep
|
|
758
|
+
* validating only those bytes. */
|
|
759
|
+
const logoAgnosticReceiptVersion = 7;
|
|
760
|
+
|
|
761
|
+
export const copyReceiptDigest = (
|
|
762
|
+
copy: AeoReportCopy,
|
|
763
|
+
provenance: CopyProvenance,
|
|
764
|
+
checkerVersion = copyCheckerVersion,
|
|
765
|
+
): string => {
|
|
766
|
+
const { brandLogo: _brandLogo, ...reviewed } = copy;
|
|
767
|
+
|
|
768
|
+
return jsonDigest({
|
|
769
|
+
copy: checkerVersion >= logoAgnosticReceiptVersion ? reviewed : copy,
|
|
770
|
+
provenance,
|
|
771
|
+
});
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
export type CopyFactsUnchangedOptions = {
|
|
775
|
+
snapshot: AeoSnapshot;
|
|
776
|
+
config: AeoAuditConfig;
|
|
777
|
+
runId: string;
|
|
778
|
+
grounding?: GroundingBundle;
|
|
779
|
+
verifierProfile?: InternalModelRoleConfig;
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
export const copyFactsUnchanged = (
|
|
783
|
+
provenance: CopyProvenance,
|
|
784
|
+
{
|
|
785
|
+
snapshot,
|
|
786
|
+
config,
|
|
787
|
+
runId,
|
|
788
|
+
grounding,
|
|
789
|
+
verifierProfile = resolveInternalModelProfile().roles.premiseVerifier,
|
|
790
|
+
}: CopyFactsUnchangedOptions,
|
|
791
|
+
): boolean => {
|
|
792
|
+
const facts = new Map(
|
|
793
|
+
buildFactCatalog({ snapshot, config, runId, grounding }).facts.map(
|
|
794
|
+
(fact) => [fact.factId, fact],
|
|
795
|
+
),
|
|
796
|
+
);
|
|
797
|
+
|
|
798
|
+
return (
|
|
799
|
+
[1, 2, premiseVerifierPromptVersion].includes(
|
|
800
|
+
provenance.verifierPromptVersion,
|
|
801
|
+
) &&
|
|
802
|
+
canonicalJson(
|
|
803
|
+
copyDependencies(
|
|
804
|
+
grounding,
|
|
805
|
+
verifierProfile,
|
|
806
|
+
provenance.verifierPromptVersion,
|
|
807
|
+
),
|
|
808
|
+
) ===
|
|
809
|
+
canonicalJson({
|
|
810
|
+
catalogVersion: provenance.catalogVersion,
|
|
811
|
+
groundingDigest: provenance.groundingDigest,
|
|
812
|
+
sourceBundleDigest: provenance.sourceBundleDigest,
|
|
813
|
+
assessmentDigests: provenance.assessmentDigests,
|
|
814
|
+
verifierProfileDigest: provenance.verifierProfileDigest,
|
|
815
|
+
verifierPromptVersion: provenance.verifierPromptVersion,
|
|
816
|
+
}) &&
|
|
817
|
+
Object.entries(provenance.factFingerprints).every(([id, fingerprint]) => {
|
|
818
|
+
const fact = facts.get(id);
|
|
819
|
+
|
|
820
|
+
return !!fact && factFingerprint(fact) === fingerprint;
|
|
821
|
+
})
|
|
822
|
+
);
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
const jsonDigest = (value: unknown): string => {
|
|
826
|
+
return createHash('sha256').update(canonicalJson(value)).digest('hex');
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* configDigests returns the digests that identify one approved config. A
|
|
831
|
+
* config stored before a schema default existed (`surfaces`, 15 September
|
|
832
|
+
* 2026) hashes differently raw and parsed: the report job issues receipts
|
|
833
|
+
* over the parsed config while gates and publication read the stored row.
|
|
834
|
+
*/
|
|
835
|
+
const configDigests = (config: AeoAuditConfig): string[] => {
|
|
836
|
+
return [jsonDigest(config), jsonDigest(aeoAuditConfigSchema.parse(config))];
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
const copyDependencies = (
|
|
840
|
+
grounding: GroundingBundle | undefined,
|
|
841
|
+
profile: InternalModelRoleConfig,
|
|
842
|
+
verifierPromptVersion = premiseVerifierPromptVersion,
|
|
843
|
+
): CopyDependencies => {
|
|
844
|
+
return {
|
|
845
|
+
catalogVersion: factCatalogVersion,
|
|
846
|
+
groundingDigest: grounding?.digest ?? null,
|
|
847
|
+
sourceBundleDigest: grounding?.sourceBundleDigest ?? null,
|
|
848
|
+
assessmentDigests: Object.fromEntries(
|
|
849
|
+
(grounding?.assessments ?? []).map((assessment) => [
|
|
850
|
+
assessment.claimId,
|
|
851
|
+
assessment.digest,
|
|
852
|
+
]),
|
|
853
|
+
),
|
|
854
|
+
verifierProfileDigest: internalModelRoleDigest(profile),
|
|
855
|
+
verifierPromptVersion,
|
|
856
|
+
};
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* validateHumanCopy reviews human copy. Human authors keep their wording; every
|
|
861
|
+
* assertion and implied premise gets the same evidence review as generated
|
|
862
|
+
* recommendations. Call outside a DB tx.
|
|
863
|
+
*/
|
|
864
|
+
export const validateHumanCopy = async (args: {
|
|
865
|
+
copy: unknown;
|
|
866
|
+
config: AeoAuditConfig;
|
|
867
|
+
snapshot: AeoSnapshot;
|
|
868
|
+
runId: string;
|
|
869
|
+
configVersion: number;
|
|
870
|
+
grounding: GroundingBundle;
|
|
871
|
+
verifier: RecommendationVerifier;
|
|
872
|
+
verifierProfile?: InternalModelRoleConfig;
|
|
873
|
+
secrets?: readonly string[];
|
|
874
|
+
signal?: AbortSignal;
|
|
875
|
+
}): Promise<
|
|
876
|
+
Omit<CopyValidationResult, 'provenance'> & {
|
|
877
|
+
provenance?: HumanCopyProvenance;
|
|
878
|
+
}
|
|
879
|
+
> => {
|
|
880
|
+
const reject = (
|
|
881
|
+
code: string,
|
|
882
|
+
message: string,
|
|
883
|
+
outcome: CopyValidationOutcome = 'invalid_copy',
|
|
884
|
+
) => {
|
|
885
|
+
return {
|
|
886
|
+
valid: false,
|
|
887
|
+
outcome,
|
|
888
|
+
errors: [{ code, path: 'copy', message }],
|
|
889
|
+
};
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
if (credentialDetected(JSON.stringify(args.copy), args.secrets)) {
|
|
893
|
+
return reject(
|
|
894
|
+
'credential_detected',
|
|
895
|
+
'Credential-shaped output is forbidden',
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
const parsed = aeoReportCopySchema.safeParse(args.copy);
|
|
900
|
+
|
|
901
|
+
if (!parsed.success || parsed.data.reportKey !== args.config.reportKey) {
|
|
902
|
+
return reject(
|
|
903
|
+
'schema_invalid',
|
|
904
|
+
'Human copy must belong to the report and match the copy schema',
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
const copy = parsed.data;
|
|
909
|
+
|
|
910
|
+
if (
|
|
911
|
+
args.config.sections.some(
|
|
912
|
+
({ key }) => !Object.hasOwn(copy.sections, key),
|
|
913
|
+
) ||
|
|
914
|
+
Object.keys(copy.sections).some(
|
|
915
|
+
(key) => !args.config.sections.some((section) => section.key === key),
|
|
916
|
+
)
|
|
917
|
+
) {
|
|
918
|
+
return reject(
|
|
919
|
+
'section_missing',
|
|
920
|
+
'Human copy must cover exactly the configured sections',
|
|
921
|
+
);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
const profile =
|
|
925
|
+
args.verifierProfile ?? resolveInternalModelProfile().roles.premiseVerifier;
|
|
926
|
+
let facts: ReportFact[];
|
|
927
|
+
|
|
928
|
+
try {
|
|
929
|
+
validateGroundingBundle(args.grounding, {
|
|
930
|
+
reportKey: args.config.reportKey,
|
|
931
|
+
runId: args.runId,
|
|
932
|
+
configVersion: args.configVersion,
|
|
933
|
+
});
|
|
934
|
+
facts = buildFactCatalog({
|
|
935
|
+
snapshot: args.snapshot,
|
|
936
|
+
config: args.config,
|
|
937
|
+
runId: args.runId,
|
|
938
|
+
grounding: args.grounding,
|
|
939
|
+
}).facts;
|
|
940
|
+
} catch {
|
|
941
|
+
return reject(
|
|
942
|
+
'grounding_invalid',
|
|
943
|
+
'Human copy requires valid frozen evidence for this run',
|
|
944
|
+
'integrity_error',
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
const inputs: RecommendationInput[] = [];
|
|
949
|
+
const pending = pendingReportCopy(args.config);
|
|
950
|
+
// These exact host values describe the publisher, pending UI and frozen run
|
|
951
|
+
// metadata. Any edited wording still receives the full semantic review.
|
|
952
|
+
const hostValues = new Map<string, string>([
|
|
953
|
+
['copy.preparedBy', pending.preparedBy],
|
|
954
|
+
['copy.pendingBadge', pending.pendingBadge],
|
|
955
|
+
['copy.pendingBody', pending.pendingBody],
|
|
956
|
+
['copy.methodologyNote', methodologyNote(args.snapshot)],
|
|
957
|
+
]);
|
|
958
|
+
const visit = (value: unknown, path: string) => {
|
|
959
|
+
if (hostValues.has(path) && value === hostValues.get(path)) {
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
if (typeof value === 'string' && value.trim()) {
|
|
964
|
+
inputs.push({
|
|
965
|
+
kind: 'human_copy',
|
|
966
|
+
text: value,
|
|
967
|
+
intendedAction: null,
|
|
968
|
+
premises: [],
|
|
969
|
+
facts,
|
|
970
|
+
path,
|
|
971
|
+
});
|
|
972
|
+
} else if (Array.isArray(value)) {
|
|
973
|
+
value.forEach((child, index) => visit(child, `${path}.${index}`));
|
|
974
|
+
} else if (value && typeof value === 'object') {
|
|
975
|
+
Object.entries(value).forEach(([key, child]) => {
|
|
976
|
+
if (!['reportKey', 'anchor', 'brandLogo'].includes(key)) {
|
|
977
|
+
visit(child, `${path}.${key}`);
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
visit(copy, 'copy');
|
|
983
|
+
let result: Awaited<ReturnType<RecommendationVerifier>>;
|
|
984
|
+
|
|
985
|
+
try {
|
|
986
|
+
result = await args.verifier(inputs, args.signal);
|
|
987
|
+
} catch (error) {
|
|
988
|
+
const outcome = classifyVerifierFailure(error, args.signal);
|
|
989
|
+
|
|
990
|
+
return reject(
|
|
991
|
+
verifierFailureCodes[outcome],
|
|
992
|
+
'Human copy requires a successful semantic evidence review',
|
|
993
|
+
outcome,
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
if (result.model !== profile.model) {
|
|
998
|
+
return reject(
|
|
999
|
+
'premise_verifier_invalid',
|
|
1000
|
+
'Semantic verification did not use the pinned verifier',
|
|
1001
|
+
'invalid_review',
|
|
1002
|
+
);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
if (result.valid !== true || result.errors.length) {
|
|
1006
|
+
const issues = (result.issues ?? [])
|
|
1007
|
+
.flatMap((issue) => {
|
|
1008
|
+
if (!inputs.some((input) => input.path === issue.path)) {
|
|
1009
|
+
return [];
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
return [
|
|
1013
|
+
{
|
|
1014
|
+
code: 'premise_unsupported',
|
|
1015
|
+
path: issue.path,
|
|
1016
|
+
message: credentialDetected(issue.message, args.secrets)
|
|
1017
|
+
? 'Unsupported premise; sensitive diagnostic omitted'
|
|
1018
|
+
: issue.message
|
|
1019
|
+
.replace(/[\u0000-\u001f\u007f]/g, ' ')
|
|
1020
|
+
.slice(0, 1000),
|
|
1021
|
+
},
|
|
1022
|
+
];
|
|
1023
|
+
})
|
|
1024
|
+
.slice(0, 20);
|
|
1025
|
+
|
|
1026
|
+
return issues.length
|
|
1027
|
+
? { valid: false, outcome: 'invalid_copy' as const, errors: issues }
|
|
1028
|
+
: reject(
|
|
1029
|
+
'premise_unsupported',
|
|
1030
|
+
'Human copy contains unsupported or irrelevant factual premises',
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
const usedBasisIds = result.basisFactIds ?? [];
|
|
1035
|
+
|
|
1036
|
+
if (usedBasisIds.some((id) => !facts.some((fact) => fact.factId === id))) {
|
|
1037
|
+
return reject(
|
|
1038
|
+
'premise_basis_invalid',
|
|
1039
|
+
'Verifier referenced an unknown factual basis',
|
|
1040
|
+
'invalid_review',
|
|
1041
|
+
);
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
const dependencies = copyDependencies(args.grounding, profile);
|
|
1045
|
+
const provenance: HumanCopyProvenance = {
|
|
1046
|
+
kind: 'human',
|
|
1047
|
+
runId: args.runId,
|
|
1048
|
+
...dependencies,
|
|
1049
|
+
factFingerprints: Object.fromEntries(
|
|
1050
|
+
facts
|
|
1051
|
+
.filter((fact) => usedBasisIds.includes(fact.factId))
|
|
1052
|
+
.map((fact) => [fact.factId, factFingerprint(fact)]),
|
|
1053
|
+
),
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
return {
|
|
1057
|
+
valid: true,
|
|
1058
|
+
outcome: 'valid',
|
|
1059
|
+
errors: [],
|
|
1060
|
+
copy,
|
|
1061
|
+
provenance,
|
|
1062
|
+
receipt: {
|
|
1063
|
+
checkerVersion: copyCheckerVersion,
|
|
1064
|
+
reportKey: args.config.reportKey,
|
|
1065
|
+
runId: args.runId,
|
|
1066
|
+
configVersion: args.configVersion,
|
|
1067
|
+
configDigest: jsonDigest(args.config),
|
|
1068
|
+
...dependencies,
|
|
1069
|
+
digest: copyReceiptDigest(copy, provenance),
|
|
1070
|
+
verifierModel: profile.model,
|
|
1071
|
+
verifierProfile: profile,
|
|
1072
|
+
validatedAt: new Date().toISOString(),
|
|
1073
|
+
},
|
|
1074
|
+
};
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
// The stored receipt and provenance are checked field by field against
|
|
1078
|
+
// recomputed evidence below, and the receipt digest hashes the whole
|
|
1079
|
+
// provenance, so these guards only establish the shape those checks read.
|
|
1080
|
+
const isStoredReceipt = (
|
|
1081
|
+
value: unknown,
|
|
1082
|
+
): value is CopyValidationReceipt & Record<string, unknown> => {
|
|
1083
|
+
return isRecord(value);
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
const isStoredProvenance = (value: unknown): value is CopyProvenance => {
|
|
1087
|
+
return isRecord(value) && (value.kind === 'agent' || value.kind === 'human');
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* assertCopyValidation checks the stored receipt, recomputed from immutable
|
|
1092
|
+
* data inside every publication transaction. No human approval or allowPartial
|
|
1093
|
+
* switch can replace the evidence receipt.
|
|
1094
|
+
*/
|
|
1095
|
+
export const assertCopyValidation = (args: {
|
|
1096
|
+
copy: AeoReportCopy;
|
|
1097
|
+
provenance: unknown;
|
|
1098
|
+
receipt: unknown;
|
|
1099
|
+
config: AeoAuditConfig;
|
|
1100
|
+
configVersion: number;
|
|
1101
|
+
snapshot: AeoSnapshot;
|
|
1102
|
+
runId: string;
|
|
1103
|
+
grounding: unknown;
|
|
1104
|
+
verifierProfile?: InternalModelRoleConfig;
|
|
1105
|
+
}): CopyValidationReceipt => {
|
|
1106
|
+
const grounding = validateGroundingBundle(args.grounding, {
|
|
1107
|
+
reportKey: args.config.reportKey,
|
|
1108
|
+
configVersion: args.configVersion,
|
|
1109
|
+
runId: args.runId,
|
|
1110
|
+
});
|
|
1111
|
+
const receipt = isStoredReceipt(args.receipt) ? args.receipt : null;
|
|
1112
|
+
const provenance = isStoredProvenance(args.provenance)
|
|
1113
|
+
? args.provenance
|
|
1114
|
+
: null;
|
|
1115
|
+
const profile =
|
|
1116
|
+
args.verifierProfile ?? resolveInternalModelProfile().roles.premiseVerifier;
|
|
1117
|
+
const verifierPromptVersions: Record<number, number> = {
|
|
1118
|
+
3: 1,
|
|
1119
|
+
4: 2,
|
|
1120
|
+
5: 3,
|
|
1121
|
+
6: 3,
|
|
1122
|
+
[copyCheckerVersion]: premiseVerifierPromptVersion,
|
|
1123
|
+
};
|
|
1124
|
+
const verifierPromptVersion = receipt
|
|
1125
|
+
? verifierPromptVersions[receipt.checkerVersion]
|
|
1126
|
+
: undefined;
|
|
1127
|
+
const expected = copyDependencies(grounding, profile, verifierPromptVersion);
|
|
1128
|
+
const draft =
|
|
1129
|
+
provenance?.kind === 'agent'
|
|
1130
|
+
? aeoAgentCopyDraftSchema.parse(provenance.draft)
|
|
1131
|
+
: undefined;
|
|
1132
|
+
const hasNarrative = draft?.intro.some((block) => block.kind === 'narrative');
|
|
1133
|
+
|
|
1134
|
+
if (
|
|
1135
|
+
!receipt ||
|
|
1136
|
+
!provenance ||
|
|
1137
|
+
!verifierPromptVersion ||
|
|
1138
|
+
(draft?.hero && receipt.checkerVersion < 5) ||
|
|
1139
|
+
(hasNarrative &&
|
|
1140
|
+
(receipt.checkerVersion === 3 ||
|
|
1141
|
+
receipt.verifierModel !== profile.model)) ||
|
|
1142
|
+
receipt.reportKey !== args.config.reportKey ||
|
|
1143
|
+
receipt.runId !== args.runId ||
|
|
1144
|
+
provenance.runId !== args.runId ||
|
|
1145
|
+
receipt.configVersion !== args.configVersion ||
|
|
1146
|
+
!configDigests(args.config).includes(receipt.configDigest) ||
|
|
1147
|
+
receipt.digest !==
|
|
1148
|
+
copyReceiptDigest(args.copy, provenance, receipt.checkerVersion) ||
|
|
1149
|
+
!Number.isFinite(Date.parse(receipt.validatedAt)) ||
|
|
1150
|
+
!['no-recommendations', profile.model].includes(receipt.verifierModel) ||
|
|
1151
|
+
internalModelRoleDigest(receipt.verifierProfile) !==
|
|
1152
|
+
expected.verifierProfileDigest ||
|
|
1153
|
+
Object.entries(expected).some(
|
|
1154
|
+
([key, value]) => canonicalJson(receipt[key]) !== canonicalJson(value),
|
|
1155
|
+
) ||
|
|
1156
|
+
!copyFactsUnchanged(provenance, {
|
|
1157
|
+
snapshot: args.snapshot,
|
|
1158
|
+
config: args.config,
|
|
1159
|
+
runId: args.runId,
|
|
1160
|
+
grounding,
|
|
1161
|
+
verifierProfile: profile,
|
|
1162
|
+
})
|
|
1163
|
+
) {
|
|
1164
|
+
throw new Error(
|
|
1165
|
+
`Copy validation receipt is missing, stale, or inconsistent with frozen evidence for run: ${args.runId}.`,
|
|
1166
|
+
);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
return receipt;
|
|
1170
|
+
};
|