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,448 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mkdir,
|
|
3
|
+
open,
|
|
4
|
+
readdir,
|
|
5
|
+
readFile,
|
|
6
|
+
rename,
|
|
7
|
+
rm,
|
|
8
|
+
stat,
|
|
9
|
+
} from 'node:fs/promises';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { mintRunId } from '../lib/run-id';
|
|
12
|
+
import { hasErrorCode } from '../stores/fs-errors';
|
|
13
|
+
import {
|
|
14
|
+
bundleManifestSchema,
|
|
15
|
+
bundlePaths,
|
|
16
|
+
bundleSchemaVersion,
|
|
17
|
+
calculationVersion,
|
|
18
|
+
canonicalization,
|
|
19
|
+
digestManifest,
|
|
20
|
+
toolId,
|
|
21
|
+
toolVersion,
|
|
22
|
+
traceSchemaVersion,
|
|
23
|
+
type BundleManifest,
|
|
24
|
+
} from './contracts';
|
|
25
|
+
import { encodeBundleJson, parseBundleJson, sha256Hex } from './json';
|
|
26
|
+
import { openJournal, readJournal } from './journal';
|
|
27
|
+
import { projectWorkdir, type CredentialFinding } from './project';
|
|
28
|
+
import { redactBundle, type Redactions } from './redact';
|
|
29
|
+
import { runJournalDir } from './recorder';
|
|
30
|
+
import { acquireWriterLock } from './writer-lock';
|
|
31
|
+
import { writeArchive } from './zip';
|
|
32
|
+
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// Finalization and export (specs/aeo-open-source-cli-spec.md §8.2, §9). A
|
|
35
|
+
// finalized revision is an immutable directory under REVISIONS/ in the work
|
|
36
|
+
// directory; export packs the latest one, or finalizes a descendant when the
|
|
37
|
+
// working state has moved on. The manifest holds no export-time field, so
|
|
38
|
+
// re-exporting a revision yields the same bundle digest and the same bytes.
|
|
39
|
+
// ============================================================================
|
|
40
|
+
|
|
41
|
+
export const revisionsDir = 'REVISIONS';
|
|
42
|
+
const identityFile = 'identity.json';
|
|
43
|
+
|
|
44
|
+
/** Thrown when export refuses to write an archive (exit code 1). */
|
|
45
|
+
export class ExportBlockedError extends Error {
|
|
46
|
+
readonly findings: readonly CredentialFinding[];
|
|
47
|
+
|
|
48
|
+
constructor(message: string, findings: readonly CredentialFinding[] = []) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = 'ExportBlockedError';
|
|
51
|
+
this.findings = findings;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const syncPath = async (target: string): Promise<void> => {
|
|
56
|
+
const handle = await open(target, 'r');
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
await handle.sync();
|
|
60
|
+
} finally {
|
|
61
|
+
await handle.close();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const writeSynced = async (file: string, bytes: Buffer): Promise<void> => {
|
|
66
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
67
|
+
|
|
68
|
+
const handle = await open(file, 'wx');
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
await handle.writeFile(bytes);
|
|
72
|
+
await handle.sync();
|
|
73
|
+
} finally {
|
|
74
|
+
await handle.close();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** The measurement identity is minted once per work directory: a later
|
|
79
|
+
* revision of the same collection keeps it (spec §5). */
|
|
80
|
+
const readOrMintIdentity = async (dir: string) => {
|
|
81
|
+
const file = path.join(dir, revisionsDir, identityFile);
|
|
82
|
+
const existing = await readFile(file, 'utf8').catch((err: unknown) => {
|
|
83
|
+
if (hasErrorCode(err, 'ENOENT')) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
throw err;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (existing !== undefined) {
|
|
91
|
+
const parsed = bundleManifestSchema.shape.run
|
|
92
|
+
.pick({ measurementId: true })
|
|
93
|
+
.parse(JSON.parse(existing));
|
|
94
|
+
|
|
95
|
+
return parsed;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const identity = { measurementId: mintRunId() };
|
|
99
|
+
|
|
100
|
+
await writeSynced(file, encodeBundleJson(identity));
|
|
101
|
+
await syncPath(path.dirname(file));
|
|
102
|
+
|
|
103
|
+
return identity;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type FinalizedRevision = {
|
|
107
|
+
dir: string;
|
|
108
|
+
manifest: BundleManifest;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/** readFinalizedRevisions lists the finalized revisions of a work
|
|
112
|
+
* directory, oldest first (revision ids sort by creation time). */
|
|
113
|
+
export const readFinalizedRevisions = async (
|
|
114
|
+
dir: string,
|
|
115
|
+
): Promise<FinalizedRevision[]> => {
|
|
116
|
+
const root = path.join(dir, revisionsDir);
|
|
117
|
+
const entries = await readdir(root, { withFileTypes: true }).catch(
|
|
118
|
+
(err: unknown) => {
|
|
119
|
+
if (hasErrorCode(err, 'ENOENT')) {
|
|
120
|
+
return [];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
throw err;
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const revisions: FinalizedRevision[] = [];
|
|
128
|
+
|
|
129
|
+
for (const entry of entries.filter((item) => item.isDirectory()).sort()) {
|
|
130
|
+
if (entry.name.endsWith('.tmp')) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const revisionDir = path.join(root, entry.name);
|
|
135
|
+
const text = await readFile(
|
|
136
|
+
path.join(revisionDir, bundlePaths.manifest),
|
|
137
|
+
'utf8',
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
revisions.push({
|
|
141
|
+
dir: revisionDir,
|
|
142
|
+
manifest: bundleManifestSchema.parse(parseBundleJson(text)),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return revisions.sort((left, right) =>
|
|
147
|
+
left.manifest.revision.id < right.manifest.revision.id ? -1 : 1,
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const sameInventory = (
|
|
152
|
+
manifest: BundleManifest,
|
|
153
|
+
files: ReadonlyMap<string, Buffer>,
|
|
154
|
+
): boolean => {
|
|
155
|
+
if (manifest.files.length !== files.size) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return manifest.files.every((file) => {
|
|
160
|
+
const bytes = files.get(file.path);
|
|
161
|
+
|
|
162
|
+
return bytes !== undefined && sha256Hex(bytes) === file.sha256;
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const mediaTypeOf = (file: string) => {
|
|
167
|
+
return file.endsWith('.jsonl') ? 'application/x-ndjson' : 'application/json';
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export type ExportOptions = {
|
|
171
|
+
/** The run's own credentials: found in any exported file, they block. */
|
|
172
|
+
secrets?: readonly string[];
|
|
173
|
+
/** Accept generic credential-pattern findings (`--accept-findings`). */
|
|
174
|
+
acceptFindings?: boolean;
|
|
175
|
+
now?: () => Date;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* finalizeRevision freezes the work directory's current state as a
|
|
180
|
+
* revision, or returns the latest revision when nothing changed since.
|
|
181
|
+
*/
|
|
182
|
+
export const finalizeRevision = async (
|
|
183
|
+
dir: string,
|
|
184
|
+
options: ExportOptions = {},
|
|
185
|
+
): Promise<FinalizedRevision & { reused: boolean }> => {
|
|
186
|
+
// Never a snapshot of a directory a live writer is changing (spec §8.2).
|
|
187
|
+
const writer = await acquireWriterLock(dir, 'export');
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
return await finalizeLockedRevision(dir, options);
|
|
191
|
+
} finally {
|
|
192
|
+
await writer.release();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/** How much of the journal the latest revision froze, when everything
|
|
197
|
+
* appended since is that revision's own revision_finalized event: then the
|
|
198
|
+
* run has not moved on, and its revision is reused as it is. */
|
|
199
|
+
const unchangedEventCount = async (
|
|
200
|
+
dir: string,
|
|
201
|
+
latest: FinalizedRevision | undefined,
|
|
202
|
+
): Promise<number | undefined> => {
|
|
203
|
+
if (!latest) {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const text = await readFile(
|
|
208
|
+
path.join(dir, runJournalDir, 'events.jsonl'),
|
|
209
|
+
'utf8',
|
|
210
|
+
).catch(() => '');
|
|
211
|
+
const { events } = readJournal(text);
|
|
212
|
+
const { count, head } = latest.manifest.events;
|
|
213
|
+
const sameHead = count === 0 || events[count - 1]?.digest === head;
|
|
214
|
+
const onlyFinalized = events
|
|
215
|
+
.slice(count)
|
|
216
|
+
.every((event) => event.type === 'revision_finalized');
|
|
217
|
+
|
|
218
|
+
return sameHead && onlyFinalized ? count : undefined;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const finalizeLockedRevision = async (
|
|
222
|
+
dir: string,
|
|
223
|
+
{
|
|
224
|
+
secrets = [],
|
|
225
|
+
acceptFindings = false,
|
|
226
|
+
now = () => new Date(),
|
|
227
|
+
}: ExportOptions,
|
|
228
|
+
): Promise<FinalizedRevision & { reused: boolean }> => {
|
|
229
|
+
const journalFile = path.join(dir, runJournalDir, 'events.jsonl');
|
|
230
|
+
const hasJournal = await stat(journalFile).then(
|
|
231
|
+
() => true,
|
|
232
|
+
() => false,
|
|
233
|
+
);
|
|
234
|
+
// Opening the journal quarantines a torn last append before anything is
|
|
235
|
+
// frozen, and is how this revision records its own finalization.
|
|
236
|
+
const journal = hasJournal
|
|
237
|
+
? await openJournal(path.join(dir, runJournalDir))
|
|
238
|
+
: undefined;
|
|
239
|
+
const latest = (await readFinalizedRevisions(dir)).at(-1);
|
|
240
|
+
const projection = await projectWorkdir(dir, {
|
|
241
|
+
secrets,
|
|
242
|
+
eventLimit: await unchangedEventCount(dir, latest),
|
|
243
|
+
});
|
|
244
|
+
const runCredentials = projection.findings.filter(
|
|
245
|
+
(finding) => finding.kind === 'run_credential',
|
|
246
|
+
);
|
|
247
|
+
const patterns = projection.findings.filter(
|
|
248
|
+
(finding) => finding.kind === 'credential_pattern',
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
if (runCredentials.length > 0) {
|
|
252
|
+
throw new ExportBlockedError(
|
|
253
|
+
`Export blocked: one of this run's own credentials appears in ${runCredentials.map((finding) => finding.path).join(', ')}. Please remove it from the run before exporting; a redacted export is not available yet.`,
|
|
254
|
+
runCredentials,
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (patterns.length > 0 && !acceptFindings) {
|
|
259
|
+
throw new ExportBlockedError(
|
|
260
|
+
`Export blocked: text that looks like a credential appears in ${patterns.map((finding) => finding.path).join(', ')}. Probed answers often quote example keys; please inspect these files and rerun with --accept-findings if they hold no real credential.`,
|
|
261
|
+
patterns,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (latest && sameInventory(latest.manifest, projection.files)) {
|
|
266
|
+
return { ...latest, reused: true };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const identity = await readOrMintIdentity(dir);
|
|
270
|
+
const revisionId = mintRunId(now().getTime());
|
|
271
|
+
const unsigned: Omit<BundleManifest, 'bundleDigest'> = {
|
|
272
|
+
bundleSchemaVersion,
|
|
273
|
+
traceSchemaVersion,
|
|
274
|
+
canonicalization,
|
|
275
|
+
calculationVersion,
|
|
276
|
+
tool: {
|
|
277
|
+
id: toolId,
|
|
278
|
+
version: toolVersion,
|
|
279
|
+
sourceRevision: null,
|
|
280
|
+
distributionDigest: null,
|
|
281
|
+
customBuild: false,
|
|
282
|
+
},
|
|
283
|
+
run: {
|
|
284
|
+
id: projection.inputs.runId,
|
|
285
|
+
kind: 'measurement',
|
|
286
|
+
// As the journal's run_started declared it; a directory without a
|
|
287
|
+
// journal is a historical artifact (spec §13, Phase 1).
|
|
288
|
+
origin: projection.journal.origin,
|
|
289
|
+
captureAuthenticity: 'self_reported',
|
|
290
|
+
measurementId: identity.measurementId,
|
|
291
|
+
reportKey: projection.inputs.reportKey,
|
|
292
|
+
execution: projection.execution,
|
|
293
|
+
needsImprovement: projection.needsImprovement,
|
|
294
|
+
...(projection.derivedFrom && {
|
|
295
|
+
derivedFrom: {
|
|
296
|
+
kind: projection.derivedFrom.kind,
|
|
297
|
+
runId: projection.derivedFrom.runId,
|
|
298
|
+
revisionId: projection.derivedFrom.revisionId,
|
|
299
|
+
bundleDigest: projection.derivedFrom.bundleDigest,
|
|
300
|
+
},
|
|
301
|
+
}),
|
|
302
|
+
},
|
|
303
|
+
revision: {
|
|
304
|
+
id: revisionId,
|
|
305
|
+
finalizedAt: now().toISOString(),
|
|
306
|
+
predecessor: latest
|
|
307
|
+
? {
|
|
308
|
+
id: latest.manifest.revision.id,
|
|
309
|
+
bundleDigest: latest.manifest.bundleDigest,
|
|
310
|
+
}
|
|
311
|
+
: null,
|
|
312
|
+
},
|
|
313
|
+
digests: projection.digests,
|
|
314
|
+
files: [...projection.files.entries()]
|
|
315
|
+
.sort(([left], [right]) => (left < right ? -1 : 1))
|
|
316
|
+
.map(([file, bytes]) => ({
|
|
317
|
+
path: file,
|
|
318
|
+
bytes: bytes.length,
|
|
319
|
+
mediaType: mediaTypeOf(file),
|
|
320
|
+
sha256: sha256Hex(bytes),
|
|
321
|
+
})),
|
|
322
|
+
events: projection.journal.events,
|
|
323
|
+
trace: projection.journal.trace,
|
|
324
|
+
acceptedFindings: patterns.map((finding) => ({
|
|
325
|
+
path: finding.path,
|
|
326
|
+
kind: 'credential_pattern' as const,
|
|
327
|
+
})),
|
|
328
|
+
};
|
|
329
|
+
const manifest = bundleManifestSchema.parse({
|
|
330
|
+
...unsigned,
|
|
331
|
+
bundleDigest: digestManifest(unsigned),
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const root = path.join(dir, revisionsDir);
|
|
335
|
+
const staging = path.join(root, `${revisionId}.tmp`);
|
|
336
|
+
const target = path.join(root, revisionId);
|
|
337
|
+
|
|
338
|
+
await rm(staging, { recursive: true, force: true });
|
|
339
|
+
|
|
340
|
+
for (const [file, bytes] of projection.files) {
|
|
341
|
+
await writeSynced(path.join(staging, file), bytes);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
await writeSynced(
|
|
345
|
+
path.join(staging, bundlePaths.manifest),
|
|
346
|
+
encodeBundleJson(manifest),
|
|
347
|
+
);
|
|
348
|
+
await rename(staging, target);
|
|
349
|
+
await syncPath(root);
|
|
350
|
+
// After the prefix it freezes, so later revisions carry this one's lineage
|
|
351
|
+
// without a hash cycle (spec §7.3).
|
|
352
|
+
await journal?.append({
|
|
353
|
+
type: 'revision_finalized',
|
|
354
|
+
payload: {
|
|
355
|
+
revisionId,
|
|
356
|
+
eventCount: manifest.events.count,
|
|
357
|
+
head: manifest.events.head,
|
|
358
|
+
bundleDigest: manifest.bundleDigest,
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
return { dir: target, manifest, reused: false };
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
/** The bundle files of a finalized revision directory, manifest included. */
|
|
366
|
+
export const readRevisionFiles = async (
|
|
367
|
+
revision: FinalizedRevision,
|
|
368
|
+
): Promise<Map<string, Buffer>> => {
|
|
369
|
+
const files = new Map<string, Buffer>();
|
|
370
|
+
|
|
371
|
+
for (const file of [
|
|
372
|
+
bundlePaths.manifest,
|
|
373
|
+
...revision.manifest.files.map((entry) => entry.path),
|
|
374
|
+
]) {
|
|
375
|
+
files.set(file, await readFile(path.join(revision.dir, file)));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return files;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
export type ExportResult = {
|
|
382
|
+
archive: string;
|
|
383
|
+
archiveSha256: string;
|
|
384
|
+
manifest: BundleManifest;
|
|
385
|
+
reusedRevision: boolean;
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* exportRun packs the work directory's latest finalized revision into a
|
|
390
|
+
* new .aeo.zip archive. It never overwrites an existing archive.
|
|
391
|
+
*/
|
|
392
|
+
export const exportRun = async (
|
|
393
|
+
dir: string,
|
|
394
|
+
{
|
|
395
|
+
output,
|
|
396
|
+
redactions,
|
|
397
|
+
...options
|
|
398
|
+
}: ExportOptions & { output?: string; redactions?: Redactions } = {},
|
|
399
|
+
): Promise<ExportResult> => {
|
|
400
|
+
const suffix = redactions ? '.redacted.aeo.zip' : '.aeo.zip';
|
|
401
|
+
const archive = path.resolve(output ?? `${path.resolve(dir)}${suffix}`);
|
|
402
|
+
const exists = await open(archive, 'r').then(
|
|
403
|
+
async (handle) => {
|
|
404
|
+
await handle.close();
|
|
405
|
+
|
|
406
|
+
return true;
|
|
407
|
+
},
|
|
408
|
+
() => false,
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
if (exists) {
|
|
412
|
+
throw new ExportBlockedError(
|
|
413
|
+
`Please choose another --output: ${archive} already exists and export never overwrites an archive.`,
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const revision = await finalizeRevision(dir, options);
|
|
418
|
+
const full = await readRevisionFiles(revision);
|
|
419
|
+
// A redacted derivative is an export, never a revision of the run: the
|
|
420
|
+
// finalized original stays as it is (spec §9).
|
|
421
|
+
const files = redactions
|
|
422
|
+
? redactBundle(full, revision.manifest, redactions)
|
|
423
|
+
: full;
|
|
424
|
+
const manifest = redactions
|
|
425
|
+
? bundleManifestSchema.parse(
|
|
426
|
+
parseBundleJson(
|
|
427
|
+
files.get(bundlePaths.manifest)?.toString('utf8') ?? '',
|
|
428
|
+
),
|
|
429
|
+
)
|
|
430
|
+
: revision.manifest;
|
|
431
|
+
const bytes = writeArchive(
|
|
432
|
+
[...files.entries()].map(([file, content]) => ({
|
|
433
|
+
path: file,
|
|
434
|
+
bytes: content,
|
|
435
|
+
})),
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
await writeSynced(archive, bytes);
|
|
439
|
+
|
|
440
|
+
const result: ExportResult = {
|
|
441
|
+
archive,
|
|
442
|
+
archiveSha256: sha256Hex(bytes),
|
|
443
|
+
manifest,
|
|
444
|
+
reusedRevision: revision.reused,
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
return result;
|
|
448
|
+
};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { access, mkdir, open, readFile, rename } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { mintRunId } from '../lib/run-id';
|
|
4
|
+
import { hasErrorCode } from '../stores/fs-errors';
|
|
5
|
+
import {
|
|
6
|
+
bundleEventSchema,
|
|
7
|
+
objectPathPrefix,
|
|
8
|
+
type BundleEvent,
|
|
9
|
+
type EventType,
|
|
10
|
+
} from './contracts';
|
|
11
|
+
import { canonicalDigest, parseBundleJson, sha256Hex } from './json';
|
|
12
|
+
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// The run journal (specs/aeo-open-source-cli-spec.md §7.3): one host-owned
|
|
15
|
+
// JSONL sequence per run, hash-chained, written as work happens. Objects an
|
|
16
|
+
// event references are durable before the event; an event is durable before
|
|
17
|
+
// the work that depends on it. Hash chaining detects an edit relative to a
|
|
18
|
+
// retained head; the owner can still regenerate the whole chain, which is
|
|
19
|
+
// why a bundle's authenticity stays self-reported.
|
|
20
|
+
// ============================================================================
|
|
21
|
+
|
|
22
|
+
/** The digest an event carries: its canonical form without the digest. */
|
|
23
|
+
export const digestEvent = (event: Omit<BundleEvent, 'digest'>): string => {
|
|
24
|
+
return canonicalDigest(event);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type JournalEntry = {
|
|
28
|
+
type: EventType;
|
|
29
|
+
operationId?: string;
|
|
30
|
+
payload?: Record<string, unknown>;
|
|
31
|
+
objects?: readonly string[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** buildEvent chains one entry onto the journal head. */
|
|
35
|
+
export const buildEvent = (
|
|
36
|
+
entry: JournalEntry,
|
|
37
|
+
head: { count: number; digest: string | null },
|
|
38
|
+
at: string,
|
|
39
|
+
): BundleEvent => {
|
|
40
|
+
const unsigned = {
|
|
41
|
+
seq: head.count,
|
|
42
|
+
id: mintRunId(),
|
|
43
|
+
type: entry.type,
|
|
44
|
+
at,
|
|
45
|
+
operationId: entry.operationId ?? null,
|
|
46
|
+
payload: entry.payload ?? {},
|
|
47
|
+
objects: [...(entry.objects ?? [])],
|
|
48
|
+
previousDigest: head.digest,
|
|
49
|
+
};
|
|
50
|
+
const event = { ...unsigned, digest: digestEvent(unsigned) };
|
|
51
|
+
|
|
52
|
+
return event;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type JournalReading = {
|
|
56
|
+
events: BundleEvent[];
|
|
57
|
+
errors: string[];
|
|
58
|
+
/** A final line without its newline: an append the process lost. */
|
|
59
|
+
tornTail: string | undefined;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** readJournal parses and chain-checks events.jsonl text. */
|
|
63
|
+
export const readJournal = (text: string): JournalReading => {
|
|
64
|
+
const events: BundleEvent[] = [];
|
|
65
|
+
const errors: string[] = [];
|
|
66
|
+
const lines = text.split('\n');
|
|
67
|
+
const last = lines.pop();
|
|
68
|
+
const tornTail = last === undefined || last === '' ? undefined : last;
|
|
69
|
+
let previous: string | null = null;
|
|
70
|
+
|
|
71
|
+
for (const [index, line] of lines.entries()) {
|
|
72
|
+
let parsed: unknown;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
parsed = parseBundleJson(line);
|
|
76
|
+
} catch (err) {
|
|
77
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
78
|
+
|
|
79
|
+
errors.push(`Line ${index + 1} is not valid JSON: ${message}`);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const result = bundleEventSchema.safeParse(parsed);
|
|
84
|
+
|
|
85
|
+
if (!result.success) {
|
|
86
|
+
errors.push(`Line ${index + 1} is not a valid event.`);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const { digest, ...unsigned } = result.data;
|
|
91
|
+
|
|
92
|
+
if (result.data.seq !== index) {
|
|
93
|
+
errors.push(`Line ${index + 1} has sequence ${result.data.seq}.`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (result.data.previousDigest !== previous) {
|
|
97
|
+
errors.push(`Line ${index + 1} does not chain to the line before it.`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (digestEvent(unsigned) !== digest) {
|
|
101
|
+
errors.push(`Line ${index + 1} does not match its own digest.`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
events.push(result.data);
|
|
105
|
+
previous = digest;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return { events, errors, tornTail };
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const syncDirectory = async (dir: string): Promise<void> => {
|
|
112
|
+
const handle = await open(dir, 'r');
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await handle.sync();
|
|
116
|
+
} finally {
|
|
117
|
+
await handle.close();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const writeDurably = async (file: string, bytes: string | Buffer) => {
|
|
122
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
123
|
+
const handle = await open(temporary, 'w');
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
await handle.writeFile(bytes);
|
|
127
|
+
await handle.sync();
|
|
128
|
+
} finally {
|
|
129
|
+
await handle.close();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
await rename(temporary, file);
|
|
133
|
+
await syncDirectory(path.dirname(file));
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/** putObject stores immutable bytes under objects/sha256/ and returns the
|
|
137
|
+
* digest an event references; durable before it returns. */
|
|
138
|
+
// Writes in flight, by object file. Two operations that store the same
|
|
139
|
+
// bytes at once (two technical checks with the same parameters, two empty
|
|
140
|
+
// answers) share one write: separate writes would race on one temporary
|
|
141
|
+
// name and the second rename would find it gone. One process writes a run
|
|
142
|
+
// directory (the writer lock), so this covers every writer of it.
|
|
143
|
+
const objectWrites = new Map<string, Promise<void>>();
|
|
144
|
+
|
|
145
|
+
const writeObject = async (file: string, bytes: string | Buffer) => {
|
|
146
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
147
|
+
|
|
148
|
+
// Content-addressed: an existing file already holds exactly these bytes.
|
|
149
|
+
const exists = await access(file).then(
|
|
150
|
+
() => true,
|
|
151
|
+
() => false,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
if (!exists) {
|
|
155
|
+
await writeDurably(file, bytes);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const putObject = async (
|
|
160
|
+
root: string,
|
|
161
|
+
bytes: string | Buffer,
|
|
162
|
+
): Promise<string> => {
|
|
163
|
+
const digest = sha256Hex(bytes);
|
|
164
|
+
const file = path.join(root, objectPathPrefix, digest);
|
|
165
|
+
let write = objectWrites.get(file);
|
|
166
|
+
|
|
167
|
+
if (!write) {
|
|
168
|
+
write = writeObject(file, bytes).finally(() => objectWrites.delete(file));
|
|
169
|
+
objectWrites.set(file, write);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
await write;
|
|
173
|
+
|
|
174
|
+
return digest;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* openJournal opens a run directory's events.jsonl for appending. A torn
|
|
179
|
+
* final line is quarantined beside the journal and recorded as an
|
|
180
|
+
* interruption; any other defect refuses the journal, since resuming over a
|
|
181
|
+
* broken chain would deliver a trace that looks complete and is not.
|
|
182
|
+
*/
|
|
183
|
+
export const openJournal = async (
|
|
184
|
+
root: string,
|
|
185
|
+
{ now = () => new Date() } = {},
|
|
186
|
+
) => {
|
|
187
|
+
const file = path.join(root, 'events.jsonl');
|
|
188
|
+
|
|
189
|
+
await mkdir(root, { recursive: true });
|
|
190
|
+
|
|
191
|
+
const text = await readFile(file, 'utf8').catch((err: unknown) => {
|
|
192
|
+
if (hasErrorCode(err, 'ENOENT')) {
|
|
193
|
+
return '';
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
throw err;
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const reading = readJournal(text);
|
|
200
|
+
|
|
201
|
+
if (reading.errors.length > 0) {
|
|
202
|
+
throw new Error(
|
|
203
|
+
`The run journal ${file} is damaged: ${reading.errors.join(' ')}`,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const head = {
|
|
208
|
+
count: reading.events.length,
|
|
209
|
+
digest: reading.events.at(-1)?.digest ?? null,
|
|
210
|
+
};
|
|
211
|
+
let queue = Promise.resolve();
|
|
212
|
+
|
|
213
|
+
const appendNow = async (entry: JournalEntry): Promise<BundleEvent> => {
|
|
214
|
+
const event = buildEvent(entry, head, now().toISOString());
|
|
215
|
+
const handle = await open(file, 'a');
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
await handle.write(`${JSON.stringify(event)}\n`);
|
|
219
|
+
await handle.sync();
|
|
220
|
+
} finally {
|
|
221
|
+
await handle.close();
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
head.count = event.seq + 1;
|
|
225
|
+
head.digest = event.digest;
|
|
226
|
+
|
|
227
|
+
return event;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/** Appends are serialized: concurrent stages never interleave lines. */
|
|
231
|
+
const append = (entry: JournalEntry): Promise<BundleEvent> => {
|
|
232
|
+
const appended = queue.then(() => appendNow(entry));
|
|
233
|
+
|
|
234
|
+
queue = appended.then(
|
|
235
|
+
() => undefined,
|
|
236
|
+
() => undefined,
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
return appended;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
if (reading.tornTail !== undefined) {
|
|
243
|
+
const quarantine = path.join(
|
|
244
|
+
root,
|
|
245
|
+
`events.torn.${now().toISOString().replace(/[:.]/g, '-')}.jsonl`,
|
|
246
|
+
);
|
|
247
|
+
const intact = text.slice(0, text.length - reading.tornTail.length);
|
|
248
|
+
|
|
249
|
+
await writeDurably(quarantine, reading.tornTail);
|
|
250
|
+
await writeDurably(file, intact);
|
|
251
|
+
await append({
|
|
252
|
+
type: 'run_interrupted',
|
|
253
|
+
payload: {
|
|
254
|
+
reason: 'torn_append',
|
|
255
|
+
quarantined: path.basename(quarantine),
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
} else {
|
|
259
|
+
await syncDirectory(root);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const journal = {
|
|
263
|
+
append,
|
|
264
|
+
head: () => ({ ...head }),
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
return journal;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export type Journal = Awaited<ReturnType<typeof openJournal>>;
|