@cleocode/cleo 2026.10.2 → 2026.10.4
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/bin/cleo.js +11 -1
- package/dist/cli/adapter-LVXHFBC4.js +158 -0
- package/dist/cli/add-WUAV7LDT.js +443 -0
- package/dist/cli/add-batch-U2DLKAQC.js +163 -0
- package/dist/cli/admin-I7BQYVZD.js +340 -0
- package/dist/cli/adr-K2THMQBS.js +171 -0
- package/dist/cli/agent-WQ6XY2DW.js +2366 -0
- package/dist/cli/agent-outputs-BJIYLVTU.js +84 -0
- package/dist/cli/analyze-PGQZWGOC.js +48 -0
- package/dist/cli/archive-5LZPF7C3.js +64 -0
- package/dist/cli/archive-stats-U6CYC6JM.js +100 -0
- package/dist/cli/attention-SOURWCNI.js +167 -0
- package/dist/cli/audit-FO2Y4LH2.js +122 -0
- package/dist/cli/auth-ED7TAIXI.js +491 -0
- package/dist/cli/backfill-32TRAYRD.js +156 -0
- package/dist/cli/backup-LEJMZJKL.js +587 -0
- package/dist/cli/backup-inspect-6HPLUEI2.js +26 -0
- package/dist/cli/backup-recover-2BTYBZU2.js +29 -0
- package/dist/cli/blockers-5JULUJTV.js +54 -0
- package/dist/cli/brain-273N3FW4.js +400 -0
- package/dist/cli/briefing-7H6OLECX.js +212 -0
- package/dist/cli/caamp-MFQVN6VU.js +181 -0
- package/dist/cli/cancel-SCMJTXZB.js +84 -0
- package/dist/cli/canon-NPF5RODM.js +142 -0
- package/dist/cli/canon-docs-2GTOLF7Y.js +26 -0
- package/dist/cli/cant-46XCUP4P.js +239 -0
- package/dist/cli/changeset-32NMBGG2.js +248 -0
- package/dist/cli/check-RWJLBCI2.js +907 -0
- package/dist/cli/checkpoint-37HMMKD7.js +128 -0
- package/dist/cli/chunk-2JIJD2I7.js +108 -0
- package/dist/cli/chunk-37NU2XDP.js +171 -0
- package/dist/cli/chunk-3IOQVUO7.js +17308 -0
- package/dist/cli/chunk-3PGH67MT.js +175 -0
- package/dist/cli/chunk-3ZO3M37V.js +1002 -0
- package/dist/cli/chunk-47JYZAMS.js +30 -0
- package/dist/cli/chunk-5J2VH3BC.js +66 -0
- package/dist/cli/chunk-5ZFFUFH7.js +92 -0
- package/dist/cli/chunk-6JSJNYH2.js +114 -0
- package/dist/cli/chunk-7INMKEAD.js +85 -0
- package/dist/cli/chunk-A2IUEIM5.js +278 -0
- package/dist/cli/chunk-AWCQH2W5.js +35 -0
- package/dist/cli/chunk-AYA6F4ZT.js +56 -0
- package/dist/cli/chunk-BCEXRFA2.js +76 -0
- package/dist/cli/chunk-BPEVD37G.js +124 -0
- package/dist/cli/chunk-C3B7C43W.js +16 -0
- package/dist/cli/chunk-DVTPIZJM.js +72 -0
- package/dist/cli/chunk-DYABOIHB.js +96 -0
- package/dist/cli/chunk-EBRZ76HS.js +51 -0
- package/dist/cli/chunk-EGOTK2HA.js +57 -0
- package/dist/cli/chunk-EOPQFCSR.js +148 -0
- package/dist/cli/chunk-FORFDPP5.js +288 -0
- package/dist/cli/chunk-GFGLLDXX.js +110 -0
- package/dist/cli/chunk-GH37QXW5.js +280 -0
- package/dist/cli/chunk-GZFVDR44.js +320 -0
- package/dist/cli/chunk-I3CRQQAD.js +225 -0
- package/dist/cli/chunk-J3ZFM3UQ.js +754 -0
- package/dist/cli/chunk-JNZJPIPJ.js +90 -0
- package/dist/cli/chunk-KHB52JNB.js +209 -0
- package/dist/cli/chunk-KJDWWQFY.js +46 -0
- package/dist/cli/chunk-LKNUA3SB.js +83 -0
- package/dist/cli/chunk-LVGIFMCV.js +163 -0
- package/dist/cli/chunk-LWQBJQSE.js +67 -0
- package/dist/cli/chunk-MNJRLSEQ.js +107 -0
- package/dist/cli/chunk-NRKWJLMS.js +91 -0
- package/dist/cli/chunk-NSHV2JNM.js +48 -0
- package/dist/cli/chunk-NWTATTEQ.js +210 -0
- package/dist/cli/chunk-OAPN46TC.js +89 -0
- package/dist/cli/chunk-OGV57L4J.js +59 -0
- package/dist/cli/chunk-OILHT47L.js +252 -0
- package/dist/cli/chunk-OPTEQKBB.js +258 -0
- package/dist/cli/chunk-PKKZPOOP.js +352 -0
- package/dist/cli/chunk-QA6T2LQ5.js +71 -0
- package/dist/cli/chunk-QFFQSKRC.js +4497 -0
- package/dist/cli/chunk-QPUY2HQZ.js +74 -0
- package/dist/cli/chunk-REUTEW3O.js +258 -0
- package/dist/cli/chunk-S24YI723.js +88 -0
- package/dist/cli/chunk-SXXOC6KZ.js +209 -0
- package/dist/cli/chunk-ULN4OKQQ.js +259 -0
- package/dist/cli/chunk-V5GBGOGM.js +46 -0
- package/dist/cli/chunk-VLEYOOPH.js +31 -0
- package/dist/cli/chunk-W33Q3FBH.js +66 -0
- package/dist/cli/chunk-W3JLYKKY.js +140 -0
- package/dist/cli/chunk-XRAX6XFP.js +48 -0
- package/dist/cli/chunk-YGKEECTI.js +78 -0
- package/dist/cli/chunk-YUZJI67I.js +108 -0
- package/dist/cli/chunk-YY66LFZF.js +29 -0
- package/dist/cli/chunk-ZBISIPCK.js +78 -0
- package/dist/cli/chunk-ZZTHTMQP.js +77 -0
- package/dist/cli/claim-KPENYHIQ.js +96 -0
- package/dist/cli/classify-DRVMCFQU.js +117 -0
- package/dist/cli/cli-T3CR7J57.js +48 -0
- package/dist/cli/cloud-PPQ4O5TX.js +565 -0
- package/dist/cli/cockpit-RZKLGYPN.js +790 -0
- package/dist/cli/code-Z5CTMVTD.js +178 -0
- package/dist/cli/complete-UBOCOBRB.js +34 -0
- package/dist/cli/complexity-BV2AGQRZ.js +56 -0
- package/dist/cli/compliance-32PD5Y47.js +276 -0
- package/dist/cli/conduit-VDKCH33F.js +307 -0
- package/dist/cli/config-I72JAXK4.js +516 -0
- package/dist/cli/consensus-LFILLSTK.js +121 -0
- package/dist/cli/context-XUUVFVTP.js +141 -0
- package/dist/cli/contribution-37NQ4N5R.js +111 -0
- package/dist/cli/curator-TFDXU2EX.js +139 -0
- package/dist/cli/current-C4SN5BWV.js +42 -0
- package/dist/cli/daemon-DV25JQ62.js +451 -0
- package/dist/cli/dash-TFU4RLQW.js +70 -0
- package/dist/cli/decide-5VPMNTSI.js +419 -0
- package/dist/cli/decompose-KOYEZNJL.js +77 -0
- package/dist/cli/decomposition-7OHUFIQN.js +121 -0
- package/dist/cli/delete-Q7YCAFY5.js +68 -0
- package/dist/cli/deps-6UZKLDGJ.js +463 -0
- package/dist/cli/detect-FERY35UL.js +45 -0
- package/dist/cli/detect-drift-UL2JTPUK.js +408 -0
- package/dist/cli/diagnostics-TI5QAZXR.js +132 -0
- package/dist/cli/docs-QI2PRN3T.js +3095 -0
- package/dist/cli/doctor-AX5TICQO.js +1253 -0
- package/dist/cli/doctor-ac-bindings-YPMYHU2G.js +26 -0
- package/dist/cli/doctor-acceptance-drift-PYNFGMKB.js +26 -0
- package/dist/cli/doctor-credentials-UZRIADKM.js +26 -0
- package/dist/cli/doctor-db-substrate-Q2TOYM2S.js +27 -0
- package/dist/cli/doctor-dep-cycles-GCVYZY6F.js +26 -0
- package/dist/cli/doctor-exodus-RO5SUTC2.js +26 -0
- package/dist/cli/doctor-exodus-residue-EM2AWQXP.js +26 -0
- package/dist/cli/doctor-fk-check-Q3FOLECE.js +26 -0
- package/dist/cli/doctor-global-delivery-TNOAQ3NP.js +26 -0
- package/dist/cli/doctor-heavy-command-hook-IO3QAQLG.js +26 -0
- package/dist/cli/doctor-legacy-backups-O2YH5VLS.js +26 -0
- package/dist/cli/doctor-legacy-reaper-VSEJEIFA.js +26 -0
- package/dist/cli/doctor-malformed-ids-LQ766V5K.js +26 -0
- package/dist/cli/doctor-manifest-rows-6FQDNHLH.js +26 -0
- package/dist/cli/doctor-memory-guard-J4PSEKB5.js +26 -0
- package/dist/cli/doctor-migrations-ONOH56YM.js +26 -0
- package/dist/cli/doctor-nexus-residency-FUQAX7PV.js +26 -0
- package/dist/cli/doctor-project-identity-GUDK3HYX.js +26 -0
- package/dist/cli/doctor-projects-7L3BNL4O.js +30 -0
- package/dist/cli/doctor-projects-registry-TEAVHFQU.js +26 -0
- package/dist/cli/doctor-release-readiness-IEGHX6SL.js +26 -0
- package/dist/cli/doctor-repair-NBONOSZU.js +26 -0
- package/dist/cli/doctor-skill-fixtures-7Y6L34A3.js +26 -0
- package/dist/cli/doctor-split-brain-TUKIGVHF.js +26 -0
- package/dist/cli/doctor-superseded-store-BHZY2B2L.js +26 -0
- package/dist/cli/doctor-tool-locks-REQMIVYK.js +26 -0
- package/dist/cli/doctor-twin-collapse-222GOSPE.js +26 -0
- package/dist/cli/doctor-worktree-stores-J7TCRVJ3.js +26 -0
- package/dist/cli/done-V3AOO65B.js +195 -0
- package/dist/cli/dynamic-RR4HB7BB.js +29 -0
- package/dist/cli/event-EGNPGE5A.js +372 -0
- package/dist/cli/exists-H4SDCBPL.js +65 -0
- package/dist/cli/exodus-KALO3B3X.js +401 -0
- package/dist/cli/export-ROFOCG4M.js +92 -0
- package/dist/cli/export-tasks-US3WBIEQ.js +96 -0
- package/dist/cli/federation-SUIB5QWT.js +145 -0
- package/dist/cli/find-YICG4BG6.js +177 -0
- package/dist/cli/focus-TKCZPKOM.js +55 -0
- package/dist/cli/gateway-H4HFDC3E.js +77 -0
- package/dist/cli/gateway-auto-start-EDK7XI6E.js +36 -0
- package/dist/cli/gc-5R2TUY5T.js +291 -0
- package/dist/cli/go-PRQFK5YG.js +206 -0
- package/dist/cli/goal-7CZRMLHC.js +212 -0
- package/dist/cli/grade-PY2YRPUS.js +56 -0
- package/dist/cli/graph-XIXMCFKG.js +878 -0
- package/dist/cli/history-EIXADPAD.js +137 -0
- package/dist/cli/hook-UF7J7R6D.js +57 -0
- package/dist/cli/hook-entry.js +244 -19
- package/dist/cli/hygiene-3QZ2NI7P.js +55 -0
- package/dist/cli/import-R73SO444.js +88 -0
- package/dist/cli/import-tasks-O22FZJ4U.js +108 -0
- package/dist/cli/index.js +419 -94607
- package/dist/cli/init-IHEJDQWU.js +40 -0
- package/dist/cli/inject-LSRVWNCP.js +82 -0
- package/dist/cli/install-global-4AZUCH6U.js +95 -0
- package/dist/cli/intelligence-2OSFOGD2.js +181 -0
- package/dist/cli/issue-IIWEDNFC.js +158 -0
- package/dist/cli/janitor-GPMC7VOR.js +111 -0
- package/dist/cli/labels-5NPOIQXN.js +87 -0
- package/dist/cli/lifecycle-4FFS2K2T.js +272 -0
- package/dist/cli/list-47KEUGPQ.js +108 -0
- package/dist/cli/llm-G5B3I6GD.js +703 -0
- package/dist/cli/llm-cost-S7RS6BVA.js +25 -0
- package/dist/cli/llm-stream-24A45NTS.js +27 -0
- package/dist/cli/log-XF6H2XSD.js +75 -0
- package/dist/cli/login-LBPLGHYG.js +43 -0
- package/dist/cli/logout-SX4JSJIV.js +74 -0
- package/dist/cli/manifest-NMCW4PIW.js +353 -0
- package/dist/cli/map-BU72KMGF.js +52 -0
- package/dist/cli/memory-UHYIVGVM.js +1956 -0
- package/dist/cli/migrate-agents-v2-OO7OILZK.js +33 -0
- package/dist/cli/migrate-claude-mem-EDNYUY3K.js +201 -0
- package/dist/cli/next-RZFRG5X7.js +56 -0
- package/dist/cli/nexus-4S4Z5EVU.js +2923 -0
- package/dist/cli/ops-KR7AWCG3.js +51 -0
- package/dist/cli/orchestrate-HOYZY3VX.js +948 -0
- package/dist/cli/otel-U7IIRBCT.js +188 -0
- package/dist/cli/phase-NYZFHUE5.js +220 -0
- package/dist/cli/pivot-FF2CVUZL.js +87 -0
- package/dist/cli/plan-3SL2NTRV.js +48 -0
- package/dist/cli/playbook-2FCBV7N3.js +229 -0
- package/dist/cli/project-WDX2TGMC.js +330 -0
- package/dist/cli/promote-YINYFBZY.js +52 -0
- package/dist/cli/provenance-C7AYD7WG.js +128 -0
- package/dist/cli/provider-QLJEDQBR.js +212 -0
- package/dist/cli/reason-JF5BHBM5.js +137 -0
- package/dist/cli/reconcile-NMISHDGX.js +127 -0
- package/dist/cli/refresh-memory-EY5YNICV.js +45 -0
- package/dist/cli/relates-R3ZPICAY.js +259 -0
- package/dist/cli/release-4ZJTMUUT.js +524 -0
- package/dist/cli/remote-QSONJDIK.js +279 -0
- package/dist/cli/renderers-64OR3IWX.js +37 -0
- package/dist/cli/reorder-J3DOE7ST.js +86 -0
- package/dist/cli/reparent-2OUMKEZX.js +58 -0
- package/dist/cli/req-TZB7OFKO.js +129 -0
- package/dist/cli/research-MTD7EX45.js +365 -0
- package/dist/cli/restore-VEUOX7NF.js +423 -0
- package/dist/cli/revert-3YF2IL5G.js +240 -0
- package/dist/cli/roadmap-7OOQLXKG.js +61 -0
- package/dist/cli/run-2U5NZV5Z.js +211 -0
- package/dist/cli/safestop-VR4VK56D.js +88 -0
- package/dist/cli/saga-SEWPIOX2.js +285 -0
- package/dist/cli/schema-C52WZ35V.js +195 -0
- package/dist/cli/self-update-GQIGUDPS.js +504 -0
- package/dist/cli/selfimprove-3Y5L4ECT.js +88 -0
- package/dist/cli/sentient-M4YMAVGV.js +1088 -0
- package/dist/cli/sequence-6UBMA4IF.js +93 -0
- package/dist/cli/service-5R7SILZ7.js +155 -0
- package/dist/cli/session-3C6AAC4Y.js +707 -0
- package/dist/cli/setup-BTUBW5PU.js +323 -0
- package/dist/cli/show-MXT2V7TF.js +122 -0
- package/dist/cli/skill-GFUZOU2C.js +84 -0
- package/dist/cli/skills-EDWLKAF3.js +928 -0
- package/dist/cli/smoke-provider-SKUFMZXU.js +218 -0
- package/dist/cli/snapshot-GUWMURCM.js +119 -0
- package/dist/cli/src-66GAKPXR.js +80 -0
- package/dist/cli/start-QFG56RGN.js +67 -0
- package/dist/cli/stats-GW55P7RR.js +95 -0
- package/dist/cli/status-46HTKNRR.js +157 -0
- package/dist/cli/sticky-2DUZOUGI.js +338 -0
- package/dist/cli/stop-J2QEUKHX.js +42 -0
- package/dist/cli/sync-GJP2QYT5.js +154 -0
- package/dist/cli/tasks-BNXTM7PB.js +174 -0
- package/dist/cli/telemetry-55Z2XJWL.js +120 -0
- package/dist/cli/templates-7O77TKPV.js +611 -0
- package/dist/cli/testing-37YTBNKP.js +146 -0
- package/dist/cli/token-UAVJMNUI.js +220 -0
- package/dist/cli/transcript-LORQTV5Z.js +440 -0
- package/dist/cli/tui-BPUFHYKK.js +51 -0
- package/dist/cli/update-NVCYV2FT.js +476 -0
- package/dist/cli/upgrade-OXJXOGEF.js +243 -0
- package/dist/cli/verify-LYLDHPT2.js +190 -0
- package/dist/cli/web-QP2RP266.js +275 -0
- package/dist/cli/workgraph-FXBSZDQE.js +232 -0
- package/dist/cli/worktree-6RXAJIST.js +370 -0
- package/package.json +13 -13
- package/studio-dist/client/_app/immutable/chunks/{Buaay_Q8.js → Btgeq_wq.js} +1 -1
- package/studio-dist/client/_app/immutable/chunks/{BJp57kf2.js → CgBjxmu6.js} +1 -1
- package/studio-dist/client/_app/immutable/chunks/{CLP4JZvZ.js → DgEKqO6r.js} +1 -1
- package/studio-dist/client/_app/immutable/chunks/t81h7afa.js +1 -0
- package/studio-dist/client/_app/immutable/entry/{app.CczVILch.js → app.a02HWaRB.js} +2 -2
- package/studio-dist/client/_app/immutable/entry/start.BreMSngo.js +1 -0
- package/studio-dist/client/_app/immutable/nodes/{0.Zy2IsLEl.js → 0.nTXyRfc-.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{1.DJN1QI3l.js → 1.4zrWeHtl.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{15.B4rwqbHV.js → 15.D9mk4JyY.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{16.jn-5BG_L.js → 16._-wt-sQf.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{17.DnWGC4t9.js → 17.CUu6LQDj.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{18.0zddLZOY.js → 18.Dz4QRTkX.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{20.DEKHq9Tc.js → 20.CJ2_EB0U.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{24.CQB9KP-p.js → 24.Igj2FS7k.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{25.BaqToZD-.js → 25.BnATjVGN.js} +2 -2
- package/studio-dist/client/_app/immutable/nodes/{26.BiE1i4iE.js → 26.6iPyjT44.js} +1 -1
- package/studio-dist/client/_app/immutable/nodes/{3.BObAOu_-.js → 3.AA5GwNgP.js} +1 -1
- package/studio-dist/client/_app/version.json +1 -1
- package/studio-dist/server/chunks/{0-BmUoS2yd.js → 0-DGmsoBYm.js} +3 -3
- package/studio-dist/server/chunks/1-8PfxPvlK.js +9 -0
- package/studio-dist/server/chunks/{15-Dt4kqUxW.js → 15-Bg6YTndh.js} +3 -3
- package/studio-dist/server/chunks/{16-kgTLJvbO.js → 16-BObLwgyD.js} +3 -3
- package/studio-dist/server/chunks/{17-mRYB5141.js → 17-BNXGyAHX.js} +3 -3
- package/studio-dist/server/chunks/{18-BjZ325q5.js → 18-UqQFRIID.js} +3 -3
- package/studio-dist/server/chunks/{20-DQ2Vrujq.js → 20-CMn8a_yP.js} +3 -3
- package/studio-dist/server/chunks/{24-DAeuAfXN.js → 24-BuOTDzib.js} +3 -3
- package/studio-dist/server/chunks/{25-DGCNmzAS.js → 25-CIMSmjVx.js} +4 -4
- package/studio-dist/server/chunks/{26-CiN6bbmR.js → 26-DWGObn2T.js} +3 -3
- package/studio-dist/server/chunks/{3-BS2FXYjP.js → 3-CyiffdJZ.js} +3 -3
- package/studio-dist/server/chunks/{_layout.svelte-DJ_UWmGp.js → _layout.svelte-DYtClaIk.js} +4 -4
- package/studio-dist/server/chunks/{_page.svelte-WR6jUiQE.js → _page.svelte-1h9E6s_f.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-BUq8_eQH.js → _page.svelte-BNNF62Nm.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-CRnYa4cW.js → _page.svelte-BT1EUadj.js} +5 -5
- package/studio-dist/server/chunks/{_page.svelte-Dk0znswQ.js → _page.svelte-Bip079LT.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-CcP_KW3Y.js → _page.svelte-CEATWp_5.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-Ca7x-ZvH.js → _page.svelte-CV3xiD1y.js} +4 -4
- package/studio-dist/server/chunks/{_page.svelte-Cfv9tDBA.js → _page.svelte-Cv_KVJDV.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-J4HjPhfO.js → _page.svelte-DSSy6LuK.js} +3 -3
- package/studio-dist/server/chunks/{_page.svelte-D8dLEr7O.js → _page.svelte-TF795TAS.js} +3 -3
- package/studio-dist/server/chunks/{_server.ts-Bih2-_5O.js → _server.ts-BlhRFLY3.js} +2 -2
- package/studio-dist/server/chunks/{_server.ts-Cr57EKWf.js → _server.ts-C4w6UdU0.js} +3 -3
- package/studio-dist/server/chunks/{_server.ts-P4wVVksg.js → _server.ts-CzrwbhkQ.js} +3 -3
- package/studio-dist/server/chunks/{_server.ts-2BazvYRP.js → _server.ts-DWt8Dziu.js} +3 -3
- package/studio-dist/server/chunks/{_server.ts-C0evMKCk.js → _server.ts-Db6mEile.js} +3 -3
- package/studio-dist/server/chunks/{client-Cl295FWH.js → client-D8f2k-H_.js} +2 -2
- package/studio-dist/server/chunks/{dist-CdoCt9zT.js → dist-B8xbIrdB.js} +3 -1
- package/studio-dist/server/chunks/{error.svelte-ajn1HNOb.js → error.svelte-DbbOwIme.js} +3 -3
- package/studio-dist/server/chunks/{http-BiQjEmVU.js → http-1ftNGTs5.js} +2 -2
- package/studio-dist/server/chunks/{internal-D9MtKHIF.js → internal-CTULuLPB.js} +2 -2
- package/studio-dist/server/chunks/{stores-BlknvZ80.js → stores-CS5XOReX.js} +2 -2
- package/studio-dist/server/index.js +1 -1
- package/studio-dist/server/manifest.js +17 -17
- package/studio-dist/client/_app/immutable/chunks/C3l-lTkq.js +0 -1
- package/studio-dist/client/_app/immutable/entry/start.D7gHmBNS.js +0 -1
- package/studio-dist/server/chunks/1-CTjj2MYz.js +0 -9
|
@@ -0,0 +1,4497 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const _installed = Symbol.for('cleocode.cli.sqliteWarningFilter');
|
|
3
|
+
if (globalThis[_installed]) return;
|
|
4
|
+
globalThis[_installed] = true;
|
|
5
|
+
const _origEmitWarning = process.emitWarning;
|
|
6
|
+
process.emitWarning = function(warning, type, code, ctor) {
|
|
7
|
+
if (typeof warning === 'object' && warning.name === 'ExperimentalWarning' && typeof warning.message === 'string' && /SQLite is an experimental feature/i.test(warning.message)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (typeof warning === 'string' && /SQLite is an experimental feature/i.test(warning)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
return _origEmitWarning.call(process, warning, type, code, ctor);
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
|
|
17
|
+
// packages/playbooks/src/approval.ts
|
|
18
|
+
import { createHmac, randomUUID } from "node:crypto";
|
|
19
|
+
var DEFAULT_SECRET = "cleo-playbook-dev-secret-do-not-use-in-production";
|
|
20
|
+
var TOKEN_LENGTH = 32;
|
|
21
|
+
var E_APPROVAL_NOT_FOUND = "E_APPROVAL_NOT_FOUND";
|
|
22
|
+
var E_APPROVAL_ALREADY_DECIDED = "E_APPROVAL_ALREADY_DECIDED";
|
|
23
|
+
function getPlaybookSecret(env = process.env) {
|
|
24
|
+
return env["CLEO_PLAYBOOK_SECRET"] ?? DEFAULT_SECRET;
|
|
25
|
+
}
|
|
26
|
+
function generateResumeToken(runId, nodeId, bindings, secret = getPlaybookSecret()) {
|
|
27
|
+
const canonical = JSON.stringify(bindings, Object.keys(bindings).sort());
|
|
28
|
+
const payload = `${runId}:${nodeId}:${canonical}`;
|
|
29
|
+
return createHmac("sha256", secret).update(payload).digest("hex").slice(0, TOKEN_LENGTH);
|
|
30
|
+
}
|
|
31
|
+
function narrowStatus(s) {
|
|
32
|
+
if (s === "pending" || s === "approved" || s === "rejected") return s;
|
|
33
|
+
throw new Error(`invariant: unknown playbook_approvals.status '${s}'`);
|
|
34
|
+
}
|
|
35
|
+
function readString(row, key) {
|
|
36
|
+
const v = row[key];
|
|
37
|
+
if (typeof v !== "string") {
|
|
38
|
+
throw new Error(`invariant: expected string for column ${key}, got ${typeof v}`);
|
|
39
|
+
}
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
function readInt(row, key) {
|
|
43
|
+
const v = row[key];
|
|
44
|
+
if (typeof v === "number") return v;
|
|
45
|
+
if (typeof v === "bigint") return Number(v);
|
|
46
|
+
throw new Error(`invariant: expected integer for column ${key}, got ${typeof v}`);
|
|
47
|
+
}
|
|
48
|
+
function readOptionalString(row, key) {
|
|
49
|
+
const v = row[key];
|
|
50
|
+
if (v === null || v === void 0) return void 0;
|
|
51
|
+
if (typeof v !== "string") {
|
|
52
|
+
throw new Error(`invariant: expected string|null for column ${key}, got ${typeof v}`);
|
|
53
|
+
}
|
|
54
|
+
return v;
|
|
55
|
+
}
|
|
56
|
+
function rowToApproval(row) {
|
|
57
|
+
const approval = {
|
|
58
|
+
approvalId: readString(row, "approval_id"),
|
|
59
|
+
runId: readString(row, "run_id"),
|
|
60
|
+
nodeId: readString(row, "node_id"),
|
|
61
|
+
token: readString(row, "token"),
|
|
62
|
+
requestedAt: readString(row, "requested_at"),
|
|
63
|
+
status: narrowStatus(readString(row, "status")),
|
|
64
|
+
autoPassed: readInt(row, "auto_passed") === 1
|
|
65
|
+
};
|
|
66
|
+
const approvedAt = readOptionalString(row, "approved_at");
|
|
67
|
+
const approver = readOptionalString(row, "approver");
|
|
68
|
+
const reason = readOptionalString(row, "reason");
|
|
69
|
+
if (approvedAt !== void 0) approval.approvedAt = approvedAt;
|
|
70
|
+
if (approver !== void 0) approval.approver = approver;
|
|
71
|
+
if (reason !== void 0) approval.reason = reason;
|
|
72
|
+
return approval;
|
|
73
|
+
}
|
|
74
|
+
function createApprovalGate(db, input) {
|
|
75
|
+
const token = generateResumeToken(input.runId, input.nodeId, input.bindings, input.secret);
|
|
76
|
+
const approvalId = randomUUID();
|
|
77
|
+
const autoPassed = input.autoPassed ?? false;
|
|
78
|
+
const status = autoPassed ? "approved" : "pending";
|
|
79
|
+
const stmt = db.prepare(`
|
|
80
|
+
INSERT INTO playbook_approvals
|
|
81
|
+
(approval_id, run_id, node_id, token, status, auto_passed, approver, reason)
|
|
82
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
83
|
+
`);
|
|
84
|
+
stmt.run(
|
|
85
|
+
approvalId,
|
|
86
|
+
input.runId,
|
|
87
|
+
input.nodeId,
|
|
88
|
+
token,
|
|
89
|
+
status,
|
|
90
|
+
autoPassed ? 1 : 0,
|
|
91
|
+
input.approver ?? null,
|
|
92
|
+
input.reason ?? null
|
|
93
|
+
);
|
|
94
|
+
const row = db.prepare("SELECT * FROM playbook_approvals WHERE approval_id = ?").get(approvalId);
|
|
95
|
+
if (row === void 0) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`${E_APPROVAL_NOT_FOUND}: insert did not round-trip (approval_id=${approvalId})`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return rowToApproval(row);
|
|
101
|
+
}
|
|
102
|
+
function approveGate(db, token, approver, reason) {
|
|
103
|
+
return transitionGate(db, token, "approved", approver, reason);
|
|
104
|
+
}
|
|
105
|
+
function rejectGate(db, token, approver, reason) {
|
|
106
|
+
return transitionGate(db, token, "rejected", approver, reason);
|
|
107
|
+
}
|
|
108
|
+
function transitionGate(db, token, next, approver, reason) {
|
|
109
|
+
const existing = db.prepare("SELECT * FROM playbook_approvals WHERE token = ?").get(token);
|
|
110
|
+
if (existing === void 0) {
|
|
111
|
+
throw new Error(`${E_APPROVAL_NOT_FOUND}: no approval gate for token`);
|
|
112
|
+
}
|
|
113
|
+
const existingStatus = narrowStatus(readString(existing, "status"));
|
|
114
|
+
if (existingStatus !== "pending") {
|
|
115
|
+
const approvalId = readString(existing, "approval_id");
|
|
116
|
+
throw new Error(
|
|
117
|
+
`${E_APPROVAL_ALREADY_DECIDED}: gate ${approvalId} is already ${existingStatus}`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
db.prepare(
|
|
121
|
+
`UPDATE playbook_approvals
|
|
122
|
+
SET status = ?, approved_at = datetime('now'), approver = ?, reason = ?
|
|
123
|
+
WHERE token = ?`
|
|
124
|
+
).run(next, approver, reason ?? null, token);
|
|
125
|
+
const row = db.prepare("SELECT * FROM playbook_approvals WHERE token = ?").get(token);
|
|
126
|
+
if (row === void 0) {
|
|
127
|
+
throw new Error(`${E_APPROVAL_NOT_FOUND}: row vanished after update (token=${token})`);
|
|
128
|
+
}
|
|
129
|
+
return rowToApproval(row);
|
|
130
|
+
}
|
|
131
|
+
function getPendingApprovals(db) {
|
|
132
|
+
const rows = db.prepare(
|
|
133
|
+
`SELECT * FROM playbook_approvals
|
|
134
|
+
WHERE status = 'pending'
|
|
135
|
+
ORDER BY requested_at ASC, approval_id ASC`
|
|
136
|
+
).all();
|
|
137
|
+
return rows.map(rowToApproval);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// packages/playbooks/src/migrate-e4.ts
|
|
141
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
142
|
+
|
|
143
|
+
// node_modules/.pnpm/js-yaml@4.1.1/node_modules/js-yaml/dist/js-yaml.mjs
|
|
144
|
+
function isNothing(subject) {
|
|
145
|
+
return typeof subject === "undefined" || subject === null;
|
|
146
|
+
}
|
|
147
|
+
function isObject(subject) {
|
|
148
|
+
return typeof subject === "object" && subject !== null;
|
|
149
|
+
}
|
|
150
|
+
function toArray(sequence) {
|
|
151
|
+
if (Array.isArray(sequence)) return sequence;
|
|
152
|
+
else if (isNothing(sequence)) return [];
|
|
153
|
+
return [sequence];
|
|
154
|
+
}
|
|
155
|
+
function extend(target, source) {
|
|
156
|
+
var index, length, key, sourceKeys;
|
|
157
|
+
if (source) {
|
|
158
|
+
sourceKeys = Object.keys(source);
|
|
159
|
+
for (index = 0, length = sourceKeys.length; index < length; index += 1) {
|
|
160
|
+
key = sourceKeys[index];
|
|
161
|
+
target[key] = source[key];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return target;
|
|
165
|
+
}
|
|
166
|
+
function repeat(string, count) {
|
|
167
|
+
var result = "", cycle;
|
|
168
|
+
for (cycle = 0; cycle < count; cycle += 1) {
|
|
169
|
+
result += string;
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
function isNegativeZero(number) {
|
|
174
|
+
return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
|
|
175
|
+
}
|
|
176
|
+
var isNothing_1 = isNothing;
|
|
177
|
+
var isObject_1 = isObject;
|
|
178
|
+
var toArray_1 = toArray;
|
|
179
|
+
var repeat_1 = repeat;
|
|
180
|
+
var isNegativeZero_1 = isNegativeZero;
|
|
181
|
+
var extend_1 = extend;
|
|
182
|
+
var common = {
|
|
183
|
+
isNothing: isNothing_1,
|
|
184
|
+
isObject: isObject_1,
|
|
185
|
+
toArray: toArray_1,
|
|
186
|
+
repeat: repeat_1,
|
|
187
|
+
isNegativeZero: isNegativeZero_1,
|
|
188
|
+
extend: extend_1
|
|
189
|
+
};
|
|
190
|
+
function formatError(exception2, compact) {
|
|
191
|
+
var where = "", message = exception2.reason || "(unknown reason)";
|
|
192
|
+
if (!exception2.mark) return message;
|
|
193
|
+
if (exception2.mark.name) {
|
|
194
|
+
where += 'in "' + exception2.mark.name + '" ';
|
|
195
|
+
}
|
|
196
|
+
where += "(" + (exception2.mark.line + 1) + ":" + (exception2.mark.column + 1) + ")";
|
|
197
|
+
if (!compact && exception2.mark.snippet) {
|
|
198
|
+
where += "\n\n" + exception2.mark.snippet;
|
|
199
|
+
}
|
|
200
|
+
return message + " " + where;
|
|
201
|
+
}
|
|
202
|
+
function YAMLException$1(reason, mark) {
|
|
203
|
+
Error.call(this);
|
|
204
|
+
this.name = "YAMLException";
|
|
205
|
+
this.reason = reason;
|
|
206
|
+
this.mark = mark;
|
|
207
|
+
this.message = formatError(this, false);
|
|
208
|
+
if (Error.captureStackTrace) {
|
|
209
|
+
Error.captureStackTrace(this, this.constructor);
|
|
210
|
+
} else {
|
|
211
|
+
this.stack = new Error().stack || "";
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
YAMLException$1.prototype = Object.create(Error.prototype);
|
|
215
|
+
YAMLException$1.prototype.constructor = YAMLException$1;
|
|
216
|
+
YAMLException$1.prototype.toString = function toString(compact) {
|
|
217
|
+
return this.name + ": " + formatError(this, compact);
|
|
218
|
+
};
|
|
219
|
+
var exception = YAMLException$1;
|
|
220
|
+
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
221
|
+
var head = "";
|
|
222
|
+
var tail = "";
|
|
223
|
+
var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
224
|
+
if (position - lineStart > maxHalfLength) {
|
|
225
|
+
head = " ... ";
|
|
226
|
+
lineStart = position - maxHalfLength + head.length;
|
|
227
|
+
}
|
|
228
|
+
if (lineEnd - position > maxHalfLength) {
|
|
229
|
+
tail = " ...";
|
|
230
|
+
lineEnd = position + maxHalfLength - tail.length;
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "\u2192") + tail,
|
|
234
|
+
pos: position - lineStart + head.length
|
|
235
|
+
// relative position
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function padStart(string, max) {
|
|
239
|
+
return common.repeat(" ", max - string.length) + string;
|
|
240
|
+
}
|
|
241
|
+
function makeSnippet(mark, options) {
|
|
242
|
+
options = Object.create(options || null);
|
|
243
|
+
if (!mark.buffer) return null;
|
|
244
|
+
if (!options.maxLength) options.maxLength = 79;
|
|
245
|
+
if (typeof options.indent !== "number") options.indent = 1;
|
|
246
|
+
if (typeof options.linesBefore !== "number") options.linesBefore = 3;
|
|
247
|
+
if (typeof options.linesAfter !== "number") options.linesAfter = 2;
|
|
248
|
+
var re = /\r?\n|\r|\0/g;
|
|
249
|
+
var lineStarts = [0];
|
|
250
|
+
var lineEnds = [];
|
|
251
|
+
var match;
|
|
252
|
+
var foundLineNo = -1;
|
|
253
|
+
while (match = re.exec(mark.buffer)) {
|
|
254
|
+
lineEnds.push(match.index);
|
|
255
|
+
lineStarts.push(match.index + match[0].length);
|
|
256
|
+
if (mark.position <= match.index && foundLineNo < 0) {
|
|
257
|
+
foundLineNo = lineStarts.length - 2;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
|
|
261
|
+
var result = "", i, line;
|
|
262
|
+
var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
|
|
263
|
+
var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
|
|
264
|
+
for (i = 1; i <= options.linesBefore; i++) {
|
|
265
|
+
if (foundLineNo - i < 0) break;
|
|
266
|
+
line = getLine(
|
|
267
|
+
mark.buffer,
|
|
268
|
+
lineStarts[foundLineNo - i],
|
|
269
|
+
lineEnds[foundLineNo - i],
|
|
270
|
+
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
|
|
271
|
+
maxLineLength
|
|
272
|
+
);
|
|
273
|
+
result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result;
|
|
274
|
+
}
|
|
275
|
+
line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
276
|
+
result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
277
|
+
result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^\n";
|
|
278
|
+
for (i = 1; i <= options.linesAfter; i++) {
|
|
279
|
+
if (foundLineNo + i >= lineEnds.length) break;
|
|
280
|
+
line = getLine(
|
|
281
|
+
mark.buffer,
|
|
282
|
+
lineStarts[foundLineNo + i],
|
|
283
|
+
lineEnds[foundLineNo + i],
|
|
284
|
+
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
|
|
285
|
+
maxLineLength
|
|
286
|
+
);
|
|
287
|
+
result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
288
|
+
}
|
|
289
|
+
return result.replace(/\n$/, "");
|
|
290
|
+
}
|
|
291
|
+
var snippet = makeSnippet;
|
|
292
|
+
var TYPE_CONSTRUCTOR_OPTIONS = [
|
|
293
|
+
"kind",
|
|
294
|
+
"multi",
|
|
295
|
+
"resolve",
|
|
296
|
+
"construct",
|
|
297
|
+
"instanceOf",
|
|
298
|
+
"predicate",
|
|
299
|
+
"represent",
|
|
300
|
+
"representName",
|
|
301
|
+
"defaultStyle",
|
|
302
|
+
"styleAliases"
|
|
303
|
+
];
|
|
304
|
+
var YAML_NODE_KINDS = [
|
|
305
|
+
"scalar",
|
|
306
|
+
"sequence",
|
|
307
|
+
"mapping"
|
|
308
|
+
];
|
|
309
|
+
function compileStyleAliases(map2) {
|
|
310
|
+
var result = {};
|
|
311
|
+
if (map2 !== null) {
|
|
312
|
+
Object.keys(map2).forEach(function(style) {
|
|
313
|
+
map2[style].forEach(function(alias) {
|
|
314
|
+
result[String(alias)] = style;
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
return result;
|
|
319
|
+
}
|
|
320
|
+
function Type$1(tag, options) {
|
|
321
|
+
options = options || {};
|
|
322
|
+
Object.keys(options).forEach(function(name) {
|
|
323
|
+
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
|
324
|
+
throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
this.options = options;
|
|
328
|
+
this.tag = tag;
|
|
329
|
+
this.kind = options["kind"] || null;
|
|
330
|
+
this.resolve = options["resolve"] || function() {
|
|
331
|
+
return true;
|
|
332
|
+
};
|
|
333
|
+
this.construct = options["construct"] || function(data) {
|
|
334
|
+
return data;
|
|
335
|
+
};
|
|
336
|
+
this.instanceOf = options["instanceOf"] || null;
|
|
337
|
+
this.predicate = options["predicate"] || null;
|
|
338
|
+
this.represent = options["represent"] || null;
|
|
339
|
+
this.representName = options["representName"] || null;
|
|
340
|
+
this.defaultStyle = options["defaultStyle"] || null;
|
|
341
|
+
this.multi = options["multi"] || false;
|
|
342
|
+
this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
|
|
343
|
+
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|
344
|
+
throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
var type = Type$1;
|
|
348
|
+
function compileList(schema2, name) {
|
|
349
|
+
var result = [];
|
|
350
|
+
schema2[name].forEach(function(currentType) {
|
|
351
|
+
var newIndex = result.length;
|
|
352
|
+
result.forEach(function(previousType, previousIndex) {
|
|
353
|
+
if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
|
|
354
|
+
newIndex = previousIndex;
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
result[newIndex] = currentType;
|
|
358
|
+
});
|
|
359
|
+
return result;
|
|
360
|
+
}
|
|
361
|
+
function compileMap() {
|
|
362
|
+
var result = {
|
|
363
|
+
scalar: {},
|
|
364
|
+
sequence: {},
|
|
365
|
+
mapping: {},
|
|
366
|
+
fallback: {},
|
|
367
|
+
multi: {
|
|
368
|
+
scalar: [],
|
|
369
|
+
sequence: [],
|
|
370
|
+
mapping: [],
|
|
371
|
+
fallback: []
|
|
372
|
+
}
|
|
373
|
+
}, index, length;
|
|
374
|
+
function collectType(type2) {
|
|
375
|
+
if (type2.multi) {
|
|
376
|
+
result.multi[type2.kind].push(type2);
|
|
377
|
+
result.multi["fallback"].push(type2);
|
|
378
|
+
} else {
|
|
379
|
+
result[type2.kind][type2.tag] = result["fallback"][type2.tag] = type2;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
for (index = 0, length = arguments.length; index < length; index += 1) {
|
|
383
|
+
arguments[index].forEach(collectType);
|
|
384
|
+
}
|
|
385
|
+
return result;
|
|
386
|
+
}
|
|
387
|
+
function Schema$1(definition) {
|
|
388
|
+
return this.extend(definition);
|
|
389
|
+
}
|
|
390
|
+
Schema$1.prototype.extend = function extend2(definition) {
|
|
391
|
+
var implicit = [];
|
|
392
|
+
var explicit = [];
|
|
393
|
+
if (definition instanceof type) {
|
|
394
|
+
explicit.push(definition);
|
|
395
|
+
} else if (Array.isArray(definition)) {
|
|
396
|
+
explicit = explicit.concat(definition);
|
|
397
|
+
} else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
|
|
398
|
+
if (definition.implicit) implicit = implicit.concat(definition.implicit);
|
|
399
|
+
if (definition.explicit) explicit = explicit.concat(definition.explicit);
|
|
400
|
+
} else {
|
|
401
|
+
throw new exception("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");
|
|
402
|
+
}
|
|
403
|
+
implicit.forEach(function(type$1) {
|
|
404
|
+
if (!(type$1 instanceof type)) {
|
|
405
|
+
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
406
|
+
}
|
|
407
|
+
if (type$1.loadKind && type$1.loadKind !== "scalar") {
|
|
408
|
+
throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
|
|
409
|
+
}
|
|
410
|
+
if (type$1.multi) {
|
|
411
|
+
throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
explicit.forEach(function(type$1) {
|
|
415
|
+
if (!(type$1 instanceof type)) {
|
|
416
|
+
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
var result = Object.create(Schema$1.prototype);
|
|
420
|
+
result.implicit = (this.implicit || []).concat(implicit);
|
|
421
|
+
result.explicit = (this.explicit || []).concat(explicit);
|
|
422
|
+
result.compiledImplicit = compileList(result, "implicit");
|
|
423
|
+
result.compiledExplicit = compileList(result, "explicit");
|
|
424
|
+
result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
|
|
425
|
+
return result;
|
|
426
|
+
};
|
|
427
|
+
var schema = Schema$1;
|
|
428
|
+
var str = new type("tag:yaml.org,2002:str", {
|
|
429
|
+
kind: "scalar",
|
|
430
|
+
construct: function(data) {
|
|
431
|
+
return data !== null ? data : "";
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
var seq = new type("tag:yaml.org,2002:seq", {
|
|
435
|
+
kind: "sequence",
|
|
436
|
+
construct: function(data) {
|
|
437
|
+
return data !== null ? data : [];
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
var map = new type("tag:yaml.org,2002:map", {
|
|
441
|
+
kind: "mapping",
|
|
442
|
+
construct: function(data) {
|
|
443
|
+
return data !== null ? data : {};
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
var failsafe = new schema({
|
|
447
|
+
explicit: [
|
|
448
|
+
str,
|
|
449
|
+
seq,
|
|
450
|
+
map
|
|
451
|
+
]
|
|
452
|
+
});
|
|
453
|
+
function resolveYamlNull(data) {
|
|
454
|
+
if (data === null) return true;
|
|
455
|
+
var max = data.length;
|
|
456
|
+
return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
|
|
457
|
+
}
|
|
458
|
+
function constructYamlNull() {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
function isNull(object) {
|
|
462
|
+
return object === null;
|
|
463
|
+
}
|
|
464
|
+
var _null = new type("tag:yaml.org,2002:null", {
|
|
465
|
+
kind: "scalar",
|
|
466
|
+
resolve: resolveYamlNull,
|
|
467
|
+
construct: constructYamlNull,
|
|
468
|
+
predicate: isNull,
|
|
469
|
+
represent: {
|
|
470
|
+
canonical: function() {
|
|
471
|
+
return "~";
|
|
472
|
+
},
|
|
473
|
+
lowercase: function() {
|
|
474
|
+
return "null";
|
|
475
|
+
},
|
|
476
|
+
uppercase: function() {
|
|
477
|
+
return "NULL";
|
|
478
|
+
},
|
|
479
|
+
camelcase: function() {
|
|
480
|
+
return "Null";
|
|
481
|
+
},
|
|
482
|
+
empty: function() {
|
|
483
|
+
return "";
|
|
484
|
+
}
|
|
485
|
+
},
|
|
486
|
+
defaultStyle: "lowercase"
|
|
487
|
+
});
|
|
488
|
+
function resolveYamlBoolean(data) {
|
|
489
|
+
if (data === null) return false;
|
|
490
|
+
var max = data.length;
|
|
491
|
+
return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
|
|
492
|
+
}
|
|
493
|
+
function constructYamlBoolean(data) {
|
|
494
|
+
return data === "true" || data === "True" || data === "TRUE";
|
|
495
|
+
}
|
|
496
|
+
function isBoolean(object) {
|
|
497
|
+
return Object.prototype.toString.call(object) === "[object Boolean]";
|
|
498
|
+
}
|
|
499
|
+
var bool = new type("tag:yaml.org,2002:bool", {
|
|
500
|
+
kind: "scalar",
|
|
501
|
+
resolve: resolveYamlBoolean,
|
|
502
|
+
construct: constructYamlBoolean,
|
|
503
|
+
predicate: isBoolean,
|
|
504
|
+
represent: {
|
|
505
|
+
lowercase: function(object) {
|
|
506
|
+
return object ? "true" : "false";
|
|
507
|
+
},
|
|
508
|
+
uppercase: function(object) {
|
|
509
|
+
return object ? "TRUE" : "FALSE";
|
|
510
|
+
},
|
|
511
|
+
camelcase: function(object) {
|
|
512
|
+
return object ? "True" : "False";
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
defaultStyle: "lowercase"
|
|
516
|
+
});
|
|
517
|
+
function isHexCode(c) {
|
|
518
|
+
return 48 <= c && c <= 57 || 65 <= c && c <= 70 || 97 <= c && c <= 102;
|
|
519
|
+
}
|
|
520
|
+
function isOctCode(c) {
|
|
521
|
+
return 48 <= c && c <= 55;
|
|
522
|
+
}
|
|
523
|
+
function isDecCode(c) {
|
|
524
|
+
return 48 <= c && c <= 57;
|
|
525
|
+
}
|
|
526
|
+
function resolveYamlInteger(data) {
|
|
527
|
+
if (data === null) return false;
|
|
528
|
+
var max = data.length, index = 0, hasDigits = false, ch;
|
|
529
|
+
if (!max) return false;
|
|
530
|
+
ch = data[index];
|
|
531
|
+
if (ch === "-" || ch === "+") {
|
|
532
|
+
ch = data[++index];
|
|
533
|
+
}
|
|
534
|
+
if (ch === "0") {
|
|
535
|
+
if (index + 1 === max) return true;
|
|
536
|
+
ch = data[++index];
|
|
537
|
+
if (ch === "b") {
|
|
538
|
+
index++;
|
|
539
|
+
for (; index < max; index++) {
|
|
540
|
+
ch = data[index];
|
|
541
|
+
if (ch === "_") continue;
|
|
542
|
+
if (ch !== "0" && ch !== "1") return false;
|
|
543
|
+
hasDigits = true;
|
|
544
|
+
}
|
|
545
|
+
return hasDigits && ch !== "_";
|
|
546
|
+
}
|
|
547
|
+
if (ch === "x") {
|
|
548
|
+
index++;
|
|
549
|
+
for (; index < max; index++) {
|
|
550
|
+
ch = data[index];
|
|
551
|
+
if (ch === "_") continue;
|
|
552
|
+
if (!isHexCode(data.charCodeAt(index))) return false;
|
|
553
|
+
hasDigits = true;
|
|
554
|
+
}
|
|
555
|
+
return hasDigits && ch !== "_";
|
|
556
|
+
}
|
|
557
|
+
if (ch === "o") {
|
|
558
|
+
index++;
|
|
559
|
+
for (; index < max; index++) {
|
|
560
|
+
ch = data[index];
|
|
561
|
+
if (ch === "_") continue;
|
|
562
|
+
if (!isOctCode(data.charCodeAt(index))) return false;
|
|
563
|
+
hasDigits = true;
|
|
564
|
+
}
|
|
565
|
+
return hasDigits && ch !== "_";
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (ch === "_") return false;
|
|
569
|
+
for (; index < max; index++) {
|
|
570
|
+
ch = data[index];
|
|
571
|
+
if (ch === "_") continue;
|
|
572
|
+
if (!isDecCode(data.charCodeAt(index))) {
|
|
573
|
+
return false;
|
|
574
|
+
}
|
|
575
|
+
hasDigits = true;
|
|
576
|
+
}
|
|
577
|
+
if (!hasDigits || ch === "_") return false;
|
|
578
|
+
return true;
|
|
579
|
+
}
|
|
580
|
+
function constructYamlInteger(data) {
|
|
581
|
+
var value = data, sign = 1, ch;
|
|
582
|
+
if (value.indexOf("_") !== -1) {
|
|
583
|
+
value = value.replace(/_/g, "");
|
|
584
|
+
}
|
|
585
|
+
ch = value[0];
|
|
586
|
+
if (ch === "-" || ch === "+") {
|
|
587
|
+
if (ch === "-") sign = -1;
|
|
588
|
+
value = value.slice(1);
|
|
589
|
+
ch = value[0];
|
|
590
|
+
}
|
|
591
|
+
if (value === "0") return 0;
|
|
592
|
+
if (ch === "0") {
|
|
593
|
+
if (value[1] === "b") return sign * parseInt(value.slice(2), 2);
|
|
594
|
+
if (value[1] === "x") return sign * parseInt(value.slice(2), 16);
|
|
595
|
+
if (value[1] === "o") return sign * parseInt(value.slice(2), 8);
|
|
596
|
+
}
|
|
597
|
+
return sign * parseInt(value, 10);
|
|
598
|
+
}
|
|
599
|
+
function isInteger(object) {
|
|
600
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 === 0 && !common.isNegativeZero(object));
|
|
601
|
+
}
|
|
602
|
+
var int = new type("tag:yaml.org,2002:int", {
|
|
603
|
+
kind: "scalar",
|
|
604
|
+
resolve: resolveYamlInteger,
|
|
605
|
+
construct: constructYamlInteger,
|
|
606
|
+
predicate: isInteger,
|
|
607
|
+
represent: {
|
|
608
|
+
binary: function(obj) {
|
|
609
|
+
return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
|
|
610
|
+
},
|
|
611
|
+
octal: function(obj) {
|
|
612
|
+
return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
|
|
613
|
+
},
|
|
614
|
+
decimal: function(obj) {
|
|
615
|
+
return obj.toString(10);
|
|
616
|
+
},
|
|
617
|
+
/* eslint-disable max-len */
|
|
618
|
+
hexadecimal: function(obj) {
|
|
619
|
+
return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
defaultStyle: "decimal",
|
|
623
|
+
styleAliases: {
|
|
624
|
+
binary: [2, "bin"],
|
|
625
|
+
octal: [8, "oct"],
|
|
626
|
+
decimal: [10, "dec"],
|
|
627
|
+
hexadecimal: [16, "hex"]
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
var YAML_FLOAT_PATTERN = new RegExp(
|
|
631
|
+
// 2.5e4, 2.5 and integers
|
|
632
|
+
"^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"
|
|
633
|
+
);
|
|
634
|
+
function resolveYamlFloat(data) {
|
|
635
|
+
if (data === null) return false;
|
|
636
|
+
if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
|
|
637
|
+
// Probably should update regexp & check speed
|
|
638
|
+
data[data.length - 1] === "_") {
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
643
|
+
function constructYamlFloat(data) {
|
|
644
|
+
var value, sign;
|
|
645
|
+
value = data.replace(/_/g, "").toLowerCase();
|
|
646
|
+
sign = value[0] === "-" ? -1 : 1;
|
|
647
|
+
if ("+-".indexOf(value[0]) >= 0) {
|
|
648
|
+
value = value.slice(1);
|
|
649
|
+
}
|
|
650
|
+
if (value === ".inf") {
|
|
651
|
+
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
652
|
+
} else if (value === ".nan") {
|
|
653
|
+
return NaN;
|
|
654
|
+
}
|
|
655
|
+
return sign * parseFloat(value, 10);
|
|
656
|
+
}
|
|
657
|
+
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
|
658
|
+
function representYamlFloat(object, style) {
|
|
659
|
+
var res;
|
|
660
|
+
if (isNaN(object)) {
|
|
661
|
+
switch (style) {
|
|
662
|
+
case "lowercase":
|
|
663
|
+
return ".nan";
|
|
664
|
+
case "uppercase":
|
|
665
|
+
return ".NAN";
|
|
666
|
+
case "camelcase":
|
|
667
|
+
return ".NaN";
|
|
668
|
+
}
|
|
669
|
+
} else if (Number.POSITIVE_INFINITY === object) {
|
|
670
|
+
switch (style) {
|
|
671
|
+
case "lowercase":
|
|
672
|
+
return ".inf";
|
|
673
|
+
case "uppercase":
|
|
674
|
+
return ".INF";
|
|
675
|
+
case "camelcase":
|
|
676
|
+
return ".Inf";
|
|
677
|
+
}
|
|
678
|
+
} else if (Number.NEGATIVE_INFINITY === object) {
|
|
679
|
+
switch (style) {
|
|
680
|
+
case "lowercase":
|
|
681
|
+
return "-.inf";
|
|
682
|
+
case "uppercase":
|
|
683
|
+
return "-.INF";
|
|
684
|
+
case "camelcase":
|
|
685
|
+
return "-.Inf";
|
|
686
|
+
}
|
|
687
|
+
} else if (common.isNegativeZero(object)) {
|
|
688
|
+
return "-0.0";
|
|
689
|
+
}
|
|
690
|
+
res = object.toString(10);
|
|
691
|
+
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
|
|
692
|
+
}
|
|
693
|
+
function isFloat(object) {
|
|
694
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
|
|
695
|
+
}
|
|
696
|
+
var float = new type("tag:yaml.org,2002:float", {
|
|
697
|
+
kind: "scalar",
|
|
698
|
+
resolve: resolveYamlFloat,
|
|
699
|
+
construct: constructYamlFloat,
|
|
700
|
+
predicate: isFloat,
|
|
701
|
+
represent: representYamlFloat,
|
|
702
|
+
defaultStyle: "lowercase"
|
|
703
|
+
});
|
|
704
|
+
var json = failsafe.extend({
|
|
705
|
+
implicit: [
|
|
706
|
+
_null,
|
|
707
|
+
bool,
|
|
708
|
+
int,
|
|
709
|
+
float
|
|
710
|
+
]
|
|
711
|
+
});
|
|
712
|
+
var core = json;
|
|
713
|
+
var YAML_DATE_REGEXP = new RegExp(
|
|
714
|
+
"^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"
|
|
715
|
+
);
|
|
716
|
+
var YAML_TIMESTAMP_REGEXP = new RegExp(
|
|
717
|
+
"^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$"
|
|
718
|
+
);
|
|
719
|
+
function resolveYamlTimestamp(data) {
|
|
720
|
+
if (data === null) return false;
|
|
721
|
+
if (YAML_DATE_REGEXP.exec(data) !== null) return true;
|
|
722
|
+
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
|
|
723
|
+
return false;
|
|
724
|
+
}
|
|
725
|
+
function constructYamlTimestamp(data) {
|
|
726
|
+
var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
|
|
727
|
+
match = YAML_DATE_REGEXP.exec(data);
|
|
728
|
+
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|
729
|
+
if (match === null) throw new Error("Date resolve error");
|
|
730
|
+
year = +match[1];
|
|
731
|
+
month = +match[2] - 1;
|
|
732
|
+
day = +match[3];
|
|
733
|
+
if (!match[4]) {
|
|
734
|
+
return new Date(Date.UTC(year, month, day));
|
|
735
|
+
}
|
|
736
|
+
hour = +match[4];
|
|
737
|
+
minute = +match[5];
|
|
738
|
+
second = +match[6];
|
|
739
|
+
if (match[7]) {
|
|
740
|
+
fraction = match[7].slice(0, 3);
|
|
741
|
+
while (fraction.length < 3) {
|
|
742
|
+
fraction += "0";
|
|
743
|
+
}
|
|
744
|
+
fraction = +fraction;
|
|
745
|
+
}
|
|
746
|
+
if (match[9]) {
|
|
747
|
+
tz_hour = +match[10];
|
|
748
|
+
tz_minute = +(match[11] || 0);
|
|
749
|
+
delta = (tz_hour * 60 + tz_minute) * 6e4;
|
|
750
|
+
if (match[9] === "-") delta = -delta;
|
|
751
|
+
}
|
|
752
|
+
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
753
|
+
if (delta) date.setTime(date.getTime() - delta);
|
|
754
|
+
return date;
|
|
755
|
+
}
|
|
756
|
+
function representYamlTimestamp(object) {
|
|
757
|
+
return object.toISOString();
|
|
758
|
+
}
|
|
759
|
+
var timestamp = new type("tag:yaml.org,2002:timestamp", {
|
|
760
|
+
kind: "scalar",
|
|
761
|
+
resolve: resolveYamlTimestamp,
|
|
762
|
+
construct: constructYamlTimestamp,
|
|
763
|
+
instanceOf: Date,
|
|
764
|
+
represent: representYamlTimestamp
|
|
765
|
+
});
|
|
766
|
+
function resolveYamlMerge(data) {
|
|
767
|
+
return data === "<<" || data === null;
|
|
768
|
+
}
|
|
769
|
+
var merge = new type("tag:yaml.org,2002:merge", {
|
|
770
|
+
kind: "scalar",
|
|
771
|
+
resolve: resolveYamlMerge
|
|
772
|
+
});
|
|
773
|
+
var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
|
|
774
|
+
function resolveYamlBinary(data) {
|
|
775
|
+
if (data === null) return false;
|
|
776
|
+
var code, idx, bitlen = 0, max = data.length, map2 = BASE64_MAP;
|
|
777
|
+
for (idx = 0; idx < max; idx++) {
|
|
778
|
+
code = map2.indexOf(data.charAt(idx));
|
|
779
|
+
if (code > 64) continue;
|
|
780
|
+
if (code < 0) return false;
|
|
781
|
+
bitlen += 6;
|
|
782
|
+
}
|
|
783
|
+
return bitlen % 8 === 0;
|
|
784
|
+
}
|
|
785
|
+
function constructYamlBinary(data) {
|
|
786
|
+
var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map2 = BASE64_MAP, bits = 0, result = [];
|
|
787
|
+
for (idx = 0; idx < max; idx++) {
|
|
788
|
+
if (idx % 4 === 0 && idx) {
|
|
789
|
+
result.push(bits >> 16 & 255);
|
|
790
|
+
result.push(bits >> 8 & 255);
|
|
791
|
+
result.push(bits & 255);
|
|
792
|
+
}
|
|
793
|
+
bits = bits << 6 | map2.indexOf(input.charAt(idx));
|
|
794
|
+
}
|
|
795
|
+
tailbits = max % 4 * 6;
|
|
796
|
+
if (tailbits === 0) {
|
|
797
|
+
result.push(bits >> 16 & 255);
|
|
798
|
+
result.push(bits >> 8 & 255);
|
|
799
|
+
result.push(bits & 255);
|
|
800
|
+
} else if (tailbits === 18) {
|
|
801
|
+
result.push(bits >> 10 & 255);
|
|
802
|
+
result.push(bits >> 2 & 255);
|
|
803
|
+
} else if (tailbits === 12) {
|
|
804
|
+
result.push(bits >> 4 & 255);
|
|
805
|
+
}
|
|
806
|
+
return new Uint8Array(result);
|
|
807
|
+
}
|
|
808
|
+
function representYamlBinary(object) {
|
|
809
|
+
var result = "", bits = 0, idx, tail, max = object.length, map2 = BASE64_MAP;
|
|
810
|
+
for (idx = 0; idx < max; idx++) {
|
|
811
|
+
if (idx % 3 === 0 && idx) {
|
|
812
|
+
result += map2[bits >> 18 & 63];
|
|
813
|
+
result += map2[bits >> 12 & 63];
|
|
814
|
+
result += map2[bits >> 6 & 63];
|
|
815
|
+
result += map2[bits & 63];
|
|
816
|
+
}
|
|
817
|
+
bits = (bits << 8) + object[idx];
|
|
818
|
+
}
|
|
819
|
+
tail = max % 3;
|
|
820
|
+
if (tail === 0) {
|
|
821
|
+
result += map2[bits >> 18 & 63];
|
|
822
|
+
result += map2[bits >> 12 & 63];
|
|
823
|
+
result += map2[bits >> 6 & 63];
|
|
824
|
+
result += map2[bits & 63];
|
|
825
|
+
} else if (tail === 2) {
|
|
826
|
+
result += map2[bits >> 10 & 63];
|
|
827
|
+
result += map2[bits >> 4 & 63];
|
|
828
|
+
result += map2[bits << 2 & 63];
|
|
829
|
+
result += map2[64];
|
|
830
|
+
} else if (tail === 1) {
|
|
831
|
+
result += map2[bits >> 2 & 63];
|
|
832
|
+
result += map2[bits << 4 & 63];
|
|
833
|
+
result += map2[64];
|
|
834
|
+
result += map2[64];
|
|
835
|
+
}
|
|
836
|
+
return result;
|
|
837
|
+
}
|
|
838
|
+
function isBinary(obj) {
|
|
839
|
+
return Object.prototype.toString.call(obj) === "[object Uint8Array]";
|
|
840
|
+
}
|
|
841
|
+
var binary = new type("tag:yaml.org,2002:binary", {
|
|
842
|
+
kind: "scalar",
|
|
843
|
+
resolve: resolveYamlBinary,
|
|
844
|
+
construct: constructYamlBinary,
|
|
845
|
+
predicate: isBinary,
|
|
846
|
+
represent: representYamlBinary
|
|
847
|
+
});
|
|
848
|
+
var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
|
849
|
+
var _toString$2 = Object.prototype.toString;
|
|
850
|
+
function resolveYamlOmap(data) {
|
|
851
|
+
if (data === null) return true;
|
|
852
|
+
var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
|
|
853
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
854
|
+
pair = object[index];
|
|
855
|
+
pairHasKey = false;
|
|
856
|
+
if (_toString$2.call(pair) !== "[object Object]") return false;
|
|
857
|
+
for (pairKey in pair) {
|
|
858
|
+
if (_hasOwnProperty$3.call(pair, pairKey)) {
|
|
859
|
+
if (!pairHasKey) pairHasKey = true;
|
|
860
|
+
else return false;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
if (!pairHasKey) return false;
|
|
864
|
+
if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
|
|
865
|
+
else return false;
|
|
866
|
+
}
|
|
867
|
+
return true;
|
|
868
|
+
}
|
|
869
|
+
function constructYamlOmap(data) {
|
|
870
|
+
return data !== null ? data : [];
|
|
871
|
+
}
|
|
872
|
+
var omap = new type("tag:yaml.org,2002:omap", {
|
|
873
|
+
kind: "sequence",
|
|
874
|
+
resolve: resolveYamlOmap,
|
|
875
|
+
construct: constructYamlOmap
|
|
876
|
+
});
|
|
877
|
+
var _toString$1 = Object.prototype.toString;
|
|
878
|
+
function resolveYamlPairs(data) {
|
|
879
|
+
if (data === null) return true;
|
|
880
|
+
var index, length, pair, keys, result, object = data;
|
|
881
|
+
result = new Array(object.length);
|
|
882
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
883
|
+
pair = object[index];
|
|
884
|
+
if (_toString$1.call(pair) !== "[object Object]") return false;
|
|
885
|
+
keys = Object.keys(pair);
|
|
886
|
+
if (keys.length !== 1) return false;
|
|
887
|
+
result[index] = [keys[0], pair[keys[0]]];
|
|
888
|
+
}
|
|
889
|
+
return true;
|
|
890
|
+
}
|
|
891
|
+
function constructYamlPairs(data) {
|
|
892
|
+
if (data === null) return [];
|
|
893
|
+
var index, length, pair, keys, result, object = data;
|
|
894
|
+
result = new Array(object.length);
|
|
895
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
896
|
+
pair = object[index];
|
|
897
|
+
keys = Object.keys(pair);
|
|
898
|
+
result[index] = [keys[0], pair[keys[0]]];
|
|
899
|
+
}
|
|
900
|
+
return result;
|
|
901
|
+
}
|
|
902
|
+
var pairs = new type("tag:yaml.org,2002:pairs", {
|
|
903
|
+
kind: "sequence",
|
|
904
|
+
resolve: resolveYamlPairs,
|
|
905
|
+
construct: constructYamlPairs
|
|
906
|
+
});
|
|
907
|
+
var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
908
|
+
function resolveYamlSet(data) {
|
|
909
|
+
if (data === null) return true;
|
|
910
|
+
var key, object = data;
|
|
911
|
+
for (key in object) {
|
|
912
|
+
if (_hasOwnProperty$2.call(object, key)) {
|
|
913
|
+
if (object[key] !== null) return false;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return true;
|
|
917
|
+
}
|
|
918
|
+
function constructYamlSet(data) {
|
|
919
|
+
return data !== null ? data : {};
|
|
920
|
+
}
|
|
921
|
+
var set = new type("tag:yaml.org,2002:set", {
|
|
922
|
+
kind: "mapping",
|
|
923
|
+
resolve: resolveYamlSet,
|
|
924
|
+
construct: constructYamlSet
|
|
925
|
+
});
|
|
926
|
+
var _default = core.extend({
|
|
927
|
+
implicit: [
|
|
928
|
+
timestamp,
|
|
929
|
+
merge
|
|
930
|
+
],
|
|
931
|
+
explicit: [
|
|
932
|
+
binary,
|
|
933
|
+
omap,
|
|
934
|
+
pairs,
|
|
935
|
+
set
|
|
936
|
+
]
|
|
937
|
+
});
|
|
938
|
+
var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
939
|
+
var CONTEXT_FLOW_IN = 1;
|
|
940
|
+
var CONTEXT_FLOW_OUT = 2;
|
|
941
|
+
var CONTEXT_BLOCK_IN = 3;
|
|
942
|
+
var CONTEXT_BLOCK_OUT = 4;
|
|
943
|
+
var CHOMPING_CLIP = 1;
|
|
944
|
+
var CHOMPING_STRIP = 2;
|
|
945
|
+
var CHOMPING_KEEP = 3;
|
|
946
|
+
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
|
947
|
+
var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
|
948
|
+
var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
|
949
|
+
var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
|
950
|
+
var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
|
951
|
+
function _class(obj) {
|
|
952
|
+
return Object.prototype.toString.call(obj);
|
|
953
|
+
}
|
|
954
|
+
function is_EOL(c) {
|
|
955
|
+
return c === 10 || c === 13;
|
|
956
|
+
}
|
|
957
|
+
function is_WHITE_SPACE(c) {
|
|
958
|
+
return c === 9 || c === 32;
|
|
959
|
+
}
|
|
960
|
+
function is_WS_OR_EOL(c) {
|
|
961
|
+
return c === 9 || c === 32 || c === 10 || c === 13;
|
|
962
|
+
}
|
|
963
|
+
function is_FLOW_INDICATOR(c) {
|
|
964
|
+
return c === 44 || c === 91 || c === 93 || c === 123 || c === 125;
|
|
965
|
+
}
|
|
966
|
+
function fromHexCode(c) {
|
|
967
|
+
var lc;
|
|
968
|
+
if (48 <= c && c <= 57) {
|
|
969
|
+
return c - 48;
|
|
970
|
+
}
|
|
971
|
+
lc = c | 32;
|
|
972
|
+
if (97 <= lc && lc <= 102) {
|
|
973
|
+
return lc - 97 + 10;
|
|
974
|
+
}
|
|
975
|
+
return -1;
|
|
976
|
+
}
|
|
977
|
+
function escapedHexLen(c) {
|
|
978
|
+
if (c === 120) {
|
|
979
|
+
return 2;
|
|
980
|
+
}
|
|
981
|
+
if (c === 117) {
|
|
982
|
+
return 4;
|
|
983
|
+
}
|
|
984
|
+
if (c === 85) {
|
|
985
|
+
return 8;
|
|
986
|
+
}
|
|
987
|
+
return 0;
|
|
988
|
+
}
|
|
989
|
+
function fromDecimalCode(c) {
|
|
990
|
+
if (48 <= c && c <= 57) {
|
|
991
|
+
return c - 48;
|
|
992
|
+
}
|
|
993
|
+
return -1;
|
|
994
|
+
}
|
|
995
|
+
function simpleEscapeSequence(c) {
|
|
996
|
+
return c === 48 ? "\0" : c === 97 ? "\x07" : c === 98 ? "\b" : c === 116 ? " " : c === 9 ? " " : c === 110 ? "\n" : c === 118 ? "\v" : c === 102 ? "\f" : c === 114 ? "\r" : c === 101 ? "\x1B" : c === 32 ? " " : c === 34 ? '"' : c === 47 ? "/" : c === 92 ? "\\" : c === 78 ? "\x85" : c === 95 ? "\xA0" : c === 76 ? "\u2028" : c === 80 ? "\u2029" : "";
|
|
997
|
+
}
|
|
998
|
+
function charFromCodepoint(c) {
|
|
999
|
+
if (c <= 65535) {
|
|
1000
|
+
return String.fromCharCode(c);
|
|
1001
|
+
}
|
|
1002
|
+
return String.fromCharCode(
|
|
1003
|
+
(c - 65536 >> 10) + 55296,
|
|
1004
|
+
(c - 65536 & 1023) + 56320
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
function setProperty(object, key, value) {
|
|
1008
|
+
if (key === "__proto__") {
|
|
1009
|
+
Object.defineProperty(object, key, {
|
|
1010
|
+
configurable: true,
|
|
1011
|
+
enumerable: true,
|
|
1012
|
+
writable: true,
|
|
1013
|
+
value
|
|
1014
|
+
});
|
|
1015
|
+
} else {
|
|
1016
|
+
object[key] = value;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
var simpleEscapeCheck = new Array(256);
|
|
1020
|
+
var simpleEscapeMap = new Array(256);
|
|
1021
|
+
for (i = 0; i < 256; i++) {
|
|
1022
|
+
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|
1023
|
+
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|
1024
|
+
}
|
|
1025
|
+
var i;
|
|
1026
|
+
function State$1(input, options) {
|
|
1027
|
+
this.input = input;
|
|
1028
|
+
this.filename = options["filename"] || null;
|
|
1029
|
+
this.schema = options["schema"] || _default;
|
|
1030
|
+
this.onWarning = options["onWarning"] || null;
|
|
1031
|
+
this.legacy = options["legacy"] || false;
|
|
1032
|
+
this.json = options["json"] || false;
|
|
1033
|
+
this.listener = options["listener"] || null;
|
|
1034
|
+
this.implicitTypes = this.schema.compiledImplicit;
|
|
1035
|
+
this.typeMap = this.schema.compiledTypeMap;
|
|
1036
|
+
this.length = input.length;
|
|
1037
|
+
this.position = 0;
|
|
1038
|
+
this.line = 0;
|
|
1039
|
+
this.lineStart = 0;
|
|
1040
|
+
this.lineIndent = 0;
|
|
1041
|
+
this.firstTabInLine = -1;
|
|
1042
|
+
this.documents = [];
|
|
1043
|
+
}
|
|
1044
|
+
function generateError(state, message) {
|
|
1045
|
+
var mark = {
|
|
1046
|
+
name: state.filename,
|
|
1047
|
+
buffer: state.input.slice(0, -1),
|
|
1048
|
+
// omit trailing \0
|
|
1049
|
+
position: state.position,
|
|
1050
|
+
line: state.line,
|
|
1051
|
+
column: state.position - state.lineStart
|
|
1052
|
+
};
|
|
1053
|
+
mark.snippet = snippet(mark);
|
|
1054
|
+
return new exception(message, mark);
|
|
1055
|
+
}
|
|
1056
|
+
function throwError(state, message) {
|
|
1057
|
+
throw generateError(state, message);
|
|
1058
|
+
}
|
|
1059
|
+
function throwWarning(state, message) {
|
|
1060
|
+
if (state.onWarning) {
|
|
1061
|
+
state.onWarning.call(null, generateError(state, message));
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
var directiveHandlers = {
|
|
1065
|
+
YAML: function handleYamlDirective(state, name, args) {
|
|
1066
|
+
var match, major, minor;
|
|
1067
|
+
if (state.version !== null) {
|
|
1068
|
+
throwError(state, "duplication of %YAML directive");
|
|
1069
|
+
}
|
|
1070
|
+
if (args.length !== 1) {
|
|
1071
|
+
throwError(state, "YAML directive accepts exactly one argument");
|
|
1072
|
+
}
|
|
1073
|
+
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
1074
|
+
if (match === null) {
|
|
1075
|
+
throwError(state, "ill-formed argument of the YAML directive");
|
|
1076
|
+
}
|
|
1077
|
+
major = parseInt(match[1], 10);
|
|
1078
|
+
minor = parseInt(match[2], 10);
|
|
1079
|
+
if (major !== 1) {
|
|
1080
|
+
throwError(state, "unacceptable YAML version of the document");
|
|
1081
|
+
}
|
|
1082
|
+
state.version = args[0];
|
|
1083
|
+
state.checkLineBreaks = minor < 2;
|
|
1084
|
+
if (minor !== 1 && minor !== 2) {
|
|
1085
|
+
throwWarning(state, "unsupported YAML version of the document");
|
|
1086
|
+
}
|
|
1087
|
+
},
|
|
1088
|
+
TAG: function handleTagDirective(state, name, args) {
|
|
1089
|
+
var handle, prefix;
|
|
1090
|
+
if (args.length !== 2) {
|
|
1091
|
+
throwError(state, "TAG directive accepts exactly two arguments");
|
|
1092
|
+
}
|
|
1093
|
+
handle = args[0];
|
|
1094
|
+
prefix = args[1];
|
|
1095
|
+
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|
1096
|
+
throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
1097
|
+
}
|
|
1098
|
+
if (_hasOwnProperty$1.call(state.tagMap, handle)) {
|
|
1099
|
+
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|
1100
|
+
}
|
|
1101
|
+
if (!PATTERN_TAG_URI.test(prefix)) {
|
|
1102
|
+
throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
1103
|
+
}
|
|
1104
|
+
try {
|
|
1105
|
+
prefix = decodeURIComponent(prefix);
|
|
1106
|
+
} catch (err) {
|
|
1107
|
+
throwError(state, "tag prefix is malformed: " + prefix);
|
|
1108
|
+
}
|
|
1109
|
+
state.tagMap[handle] = prefix;
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
function captureSegment(state, start, end, checkJson) {
|
|
1113
|
+
var _position, _length, _character, _result;
|
|
1114
|
+
if (start < end) {
|
|
1115
|
+
_result = state.input.slice(start, end);
|
|
1116
|
+
if (checkJson) {
|
|
1117
|
+
for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
|
|
1118
|
+
_character = _result.charCodeAt(_position);
|
|
1119
|
+
if (!(_character === 9 || 32 <= _character && _character <= 1114111)) {
|
|
1120
|
+
throwError(state, "expected valid JSON character");
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|
1124
|
+
throwError(state, "the stream contains non-printable characters");
|
|
1125
|
+
}
|
|
1126
|
+
state.result += _result;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
function mergeMappings(state, destination, source, overridableKeys) {
|
|
1130
|
+
var sourceKeys, key, index, quantity;
|
|
1131
|
+
if (!common.isObject(source)) {
|
|
1132
|
+
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1133
|
+
}
|
|
1134
|
+
sourceKeys = Object.keys(source);
|
|
1135
|
+
for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
|
|
1136
|
+
key = sourceKeys[index];
|
|
1137
|
+
if (!_hasOwnProperty$1.call(destination, key)) {
|
|
1138
|
+
setProperty(destination, key, source[key]);
|
|
1139
|
+
overridableKeys[key] = true;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startLineStart, startPos) {
|
|
1144
|
+
var index, quantity;
|
|
1145
|
+
if (Array.isArray(keyNode)) {
|
|
1146
|
+
keyNode = Array.prototype.slice.call(keyNode);
|
|
1147
|
+
for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
|
|
1148
|
+
if (Array.isArray(keyNode[index])) {
|
|
1149
|
+
throwError(state, "nested arrays are not supported inside keys");
|
|
1150
|
+
}
|
|
1151
|
+
if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
|
|
1152
|
+
keyNode[index] = "[object Object]";
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
|
|
1157
|
+
keyNode = "[object Object]";
|
|
1158
|
+
}
|
|
1159
|
+
keyNode = String(keyNode);
|
|
1160
|
+
if (_result === null) {
|
|
1161
|
+
_result = {};
|
|
1162
|
+
}
|
|
1163
|
+
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
1164
|
+
if (Array.isArray(valueNode)) {
|
|
1165
|
+
for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
|
|
1166
|
+
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
1167
|
+
}
|
|
1168
|
+
} else {
|
|
1169
|
+
mergeMappings(state, _result, valueNode, overridableKeys);
|
|
1170
|
+
}
|
|
1171
|
+
} else {
|
|
1172
|
+
if (!state.json && !_hasOwnProperty$1.call(overridableKeys, keyNode) && _hasOwnProperty$1.call(_result, keyNode)) {
|
|
1173
|
+
state.line = startLine || state.line;
|
|
1174
|
+
state.lineStart = startLineStart || state.lineStart;
|
|
1175
|
+
state.position = startPos || state.position;
|
|
1176
|
+
throwError(state, "duplicated mapping key");
|
|
1177
|
+
}
|
|
1178
|
+
setProperty(_result, keyNode, valueNode);
|
|
1179
|
+
delete overridableKeys[keyNode];
|
|
1180
|
+
}
|
|
1181
|
+
return _result;
|
|
1182
|
+
}
|
|
1183
|
+
function readLineBreak(state) {
|
|
1184
|
+
var ch;
|
|
1185
|
+
ch = state.input.charCodeAt(state.position);
|
|
1186
|
+
if (ch === 10) {
|
|
1187
|
+
state.position++;
|
|
1188
|
+
} else if (ch === 13) {
|
|
1189
|
+
state.position++;
|
|
1190
|
+
if (state.input.charCodeAt(state.position) === 10) {
|
|
1191
|
+
state.position++;
|
|
1192
|
+
}
|
|
1193
|
+
} else {
|
|
1194
|
+
throwError(state, "a line break is expected");
|
|
1195
|
+
}
|
|
1196
|
+
state.line += 1;
|
|
1197
|
+
state.lineStart = state.position;
|
|
1198
|
+
state.firstTabInLine = -1;
|
|
1199
|
+
}
|
|
1200
|
+
function skipSeparationSpace(state, allowComments, checkIndent) {
|
|
1201
|
+
var lineBreaks = 0, ch = state.input.charCodeAt(state.position);
|
|
1202
|
+
while (ch !== 0) {
|
|
1203
|
+
while (is_WHITE_SPACE(ch)) {
|
|
1204
|
+
if (ch === 9 && state.firstTabInLine === -1) {
|
|
1205
|
+
state.firstTabInLine = state.position;
|
|
1206
|
+
}
|
|
1207
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1208
|
+
}
|
|
1209
|
+
if (allowComments && ch === 35) {
|
|
1210
|
+
do {
|
|
1211
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1212
|
+
} while (ch !== 10 && ch !== 13 && ch !== 0);
|
|
1213
|
+
}
|
|
1214
|
+
if (is_EOL(ch)) {
|
|
1215
|
+
readLineBreak(state);
|
|
1216
|
+
ch = state.input.charCodeAt(state.position);
|
|
1217
|
+
lineBreaks++;
|
|
1218
|
+
state.lineIndent = 0;
|
|
1219
|
+
while (ch === 32) {
|
|
1220
|
+
state.lineIndent++;
|
|
1221
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1222
|
+
}
|
|
1223
|
+
} else {
|
|
1224
|
+
break;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
1228
|
+
throwWarning(state, "deficient indentation");
|
|
1229
|
+
}
|
|
1230
|
+
return lineBreaks;
|
|
1231
|
+
}
|
|
1232
|
+
function testDocumentSeparator(state) {
|
|
1233
|
+
var _position = state.position, ch;
|
|
1234
|
+
ch = state.input.charCodeAt(_position);
|
|
1235
|
+
if ((ch === 45 || ch === 46) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
|
|
1236
|
+
_position += 3;
|
|
1237
|
+
ch = state.input.charCodeAt(_position);
|
|
1238
|
+
if (ch === 0 || is_WS_OR_EOL(ch)) {
|
|
1239
|
+
return true;
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
return false;
|
|
1243
|
+
}
|
|
1244
|
+
function writeFoldedLines(state, count) {
|
|
1245
|
+
if (count === 1) {
|
|
1246
|
+
state.result += " ";
|
|
1247
|
+
} else if (count > 1) {
|
|
1248
|
+
state.result += common.repeat("\n", count - 1);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
1252
|
+
var preceding, following, captureStart, captureEnd, hasPendingContent, _line, _lineStart, _lineIndent, _kind = state.kind, _result = state.result, ch;
|
|
1253
|
+
ch = state.input.charCodeAt(state.position);
|
|
1254
|
+
if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96) {
|
|
1255
|
+
return false;
|
|
1256
|
+
}
|
|
1257
|
+
if (ch === 63 || ch === 45) {
|
|
1258
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1259
|
+
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1260
|
+
return false;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
state.kind = "scalar";
|
|
1264
|
+
state.result = "";
|
|
1265
|
+
captureStart = captureEnd = state.position;
|
|
1266
|
+
hasPendingContent = false;
|
|
1267
|
+
while (ch !== 0) {
|
|
1268
|
+
if (ch === 58) {
|
|
1269
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1270
|
+
if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|
1271
|
+
break;
|
|
1272
|
+
}
|
|
1273
|
+
} else if (ch === 35) {
|
|
1274
|
+
preceding = state.input.charCodeAt(state.position - 1);
|
|
1275
|
+
if (is_WS_OR_EOL(preceding)) {
|
|
1276
|
+
break;
|
|
1277
|
+
}
|
|
1278
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
|
1279
|
+
break;
|
|
1280
|
+
} else if (is_EOL(ch)) {
|
|
1281
|
+
_line = state.line;
|
|
1282
|
+
_lineStart = state.lineStart;
|
|
1283
|
+
_lineIndent = state.lineIndent;
|
|
1284
|
+
skipSeparationSpace(state, false, -1);
|
|
1285
|
+
if (state.lineIndent >= nodeIndent) {
|
|
1286
|
+
hasPendingContent = true;
|
|
1287
|
+
ch = state.input.charCodeAt(state.position);
|
|
1288
|
+
continue;
|
|
1289
|
+
} else {
|
|
1290
|
+
state.position = captureEnd;
|
|
1291
|
+
state.line = _line;
|
|
1292
|
+
state.lineStart = _lineStart;
|
|
1293
|
+
state.lineIndent = _lineIndent;
|
|
1294
|
+
break;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
if (hasPendingContent) {
|
|
1298
|
+
captureSegment(state, captureStart, captureEnd, false);
|
|
1299
|
+
writeFoldedLines(state, state.line - _line);
|
|
1300
|
+
captureStart = captureEnd = state.position;
|
|
1301
|
+
hasPendingContent = false;
|
|
1302
|
+
}
|
|
1303
|
+
if (!is_WHITE_SPACE(ch)) {
|
|
1304
|
+
captureEnd = state.position + 1;
|
|
1305
|
+
}
|
|
1306
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1307
|
+
}
|
|
1308
|
+
captureSegment(state, captureStart, captureEnd, false);
|
|
1309
|
+
if (state.result) {
|
|
1310
|
+
return true;
|
|
1311
|
+
}
|
|
1312
|
+
state.kind = _kind;
|
|
1313
|
+
state.result = _result;
|
|
1314
|
+
return false;
|
|
1315
|
+
}
|
|
1316
|
+
function readSingleQuotedScalar(state, nodeIndent) {
|
|
1317
|
+
var ch, captureStart, captureEnd;
|
|
1318
|
+
ch = state.input.charCodeAt(state.position);
|
|
1319
|
+
if (ch !== 39) {
|
|
1320
|
+
return false;
|
|
1321
|
+
}
|
|
1322
|
+
state.kind = "scalar";
|
|
1323
|
+
state.result = "";
|
|
1324
|
+
state.position++;
|
|
1325
|
+
captureStart = captureEnd = state.position;
|
|
1326
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1327
|
+
if (ch === 39) {
|
|
1328
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1329
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1330
|
+
if (ch === 39) {
|
|
1331
|
+
captureStart = state.position;
|
|
1332
|
+
state.position++;
|
|
1333
|
+
captureEnd = state.position;
|
|
1334
|
+
} else {
|
|
1335
|
+
return true;
|
|
1336
|
+
}
|
|
1337
|
+
} else if (is_EOL(ch)) {
|
|
1338
|
+
captureSegment(state, captureStart, captureEnd, true);
|
|
1339
|
+
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1340
|
+
captureStart = captureEnd = state.position;
|
|
1341
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1342
|
+
throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
1343
|
+
} else {
|
|
1344
|
+
state.position++;
|
|
1345
|
+
captureEnd = state.position;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
1349
|
+
}
|
|
1350
|
+
function readDoubleQuotedScalar(state, nodeIndent) {
|
|
1351
|
+
var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
|
|
1352
|
+
ch = state.input.charCodeAt(state.position);
|
|
1353
|
+
if (ch !== 34) {
|
|
1354
|
+
return false;
|
|
1355
|
+
}
|
|
1356
|
+
state.kind = "scalar";
|
|
1357
|
+
state.result = "";
|
|
1358
|
+
state.position++;
|
|
1359
|
+
captureStart = captureEnd = state.position;
|
|
1360
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1361
|
+
if (ch === 34) {
|
|
1362
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1363
|
+
state.position++;
|
|
1364
|
+
return true;
|
|
1365
|
+
} else if (ch === 92) {
|
|
1366
|
+
captureSegment(state, captureStart, state.position, true);
|
|
1367
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1368
|
+
if (is_EOL(ch)) {
|
|
1369
|
+
skipSeparationSpace(state, false, nodeIndent);
|
|
1370
|
+
} else if (ch < 256 && simpleEscapeCheck[ch]) {
|
|
1371
|
+
state.result += simpleEscapeMap[ch];
|
|
1372
|
+
state.position++;
|
|
1373
|
+
} else if ((tmp = escapedHexLen(ch)) > 0) {
|
|
1374
|
+
hexLength = tmp;
|
|
1375
|
+
hexResult = 0;
|
|
1376
|
+
for (; hexLength > 0; hexLength--) {
|
|
1377
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1378
|
+
if ((tmp = fromHexCode(ch)) >= 0) {
|
|
1379
|
+
hexResult = (hexResult << 4) + tmp;
|
|
1380
|
+
} else {
|
|
1381
|
+
throwError(state, "expected hexadecimal character");
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
state.result += charFromCodepoint(hexResult);
|
|
1385
|
+
state.position++;
|
|
1386
|
+
} else {
|
|
1387
|
+
throwError(state, "unknown escape sequence");
|
|
1388
|
+
}
|
|
1389
|
+
captureStart = captureEnd = state.position;
|
|
1390
|
+
} else if (is_EOL(ch)) {
|
|
1391
|
+
captureSegment(state, captureStart, captureEnd, true);
|
|
1392
|
+
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1393
|
+
captureStart = captureEnd = state.position;
|
|
1394
|
+
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1395
|
+
throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
1396
|
+
} else {
|
|
1397
|
+
state.position++;
|
|
1398
|
+
captureEnd = state.position;
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
1402
|
+
}
|
|
1403
|
+
function readFlowCollection(state, nodeIndent) {
|
|
1404
|
+
var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = /* @__PURE__ */ Object.create(null), keyNode, keyTag, valueNode, ch;
|
|
1405
|
+
ch = state.input.charCodeAt(state.position);
|
|
1406
|
+
if (ch === 91) {
|
|
1407
|
+
terminator = 93;
|
|
1408
|
+
isMapping = false;
|
|
1409
|
+
_result = [];
|
|
1410
|
+
} else if (ch === 123) {
|
|
1411
|
+
terminator = 125;
|
|
1412
|
+
isMapping = true;
|
|
1413
|
+
_result = {};
|
|
1414
|
+
} else {
|
|
1415
|
+
return false;
|
|
1416
|
+
}
|
|
1417
|
+
if (state.anchor !== null) {
|
|
1418
|
+
state.anchorMap[state.anchor] = _result;
|
|
1419
|
+
}
|
|
1420
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1421
|
+
while (ch !== 0) {
|
|
1422
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1423
|
+
ch = state.input.charCodeAt(state.position);
|
|
1424
|
+
if (ch === terminator) {
|
|
1425
|
+
state.position++;
|
|
1426
|
+
state.tag = _tag;
|
|
1427
|
+
state.anchor = _anchor;
|
|
1428
|
+
state.kind = isMapping ? "mapping" : "sequence";
|
|
1429
|
+
state.result = _result;
|
|
1430
|
+
return true;
|
|
1431
|
+
} else if (!readNext) {
|
|
1432
|
+
throwError(state, "missed comma between flow collection entries");
|
|
1433
|
+
} else if (ch === 44) {
|
|
1434
|
+
throwError(state, "expected the node content, but found ','");
|
|
1435
|
+
}
|
|
1436
|
+
keyTag = keyNode = valueNode = null;
|
|
1437
|
+
isPair = isExplicitPair = false;
|
|
1438
|
+
if (ch === 63) {
|
|
1439
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1440
|
+
if (is_WS_OR_EOL(following)) {
|
|
1441
|
+
isPair = isExplicitPair = true;
|
|
1442
|
+
state.position++;
|
|
1443
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
_line = state.line;
|
|
1447
|
+
_lineStart = state.lineStart;
|
|
1448
|
+
_pos = state.position;
|
|
1449
|
+
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1450
|
+
keyTag = state.tag;
|
|
1451
|
+
keyNode = state.result;
|
|
1452
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1453
|
+
ch = state.input.charCodeAt(state.position);
|
|
1454
|
+
if ((isExplicitPair || state.line === _line) && ch === 58) {
|
|
1455
|
+
isPair = true;
|
|
1456
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1457
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1458
|
+
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|
1459
|
+
valueNode = state.result;
|
|
1460
|
+
}
|
|
1461
|
+
if (isMapping) {
|
|
1462
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
|
|
1463
|
+
} else if (isPair) {
|
|
1464
|
+
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
|
|
1465
|
+
} else {
|
|
1466
|
+
_result.push(keyNode);
|
|
1467
|
+
}
|
|
1468
|
+
skipSeparationSpace(state, true, nodeIndent);
|
|
1469
|
+
ch = state.input.charCodeAt(state.position);
|
|
1470
|
+
if (ch === 44) {
|
|
1471
|
+
readNext = true;
|
|
1472
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1473
|
+
} else {
|
|
1474
|
+
readNext = false;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
throwError(state, "unexpected end of the stream within a flow collection");
|
|
1478
|
+
}
|
|
1479
|
+
function readBlockScalar(state, nodeIndent) {
|
|
1480
|
+
var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
|
|
1481
|
+
ch = state.input.charCodeAt(state.position);
|
|
1482
|
+
if (ch === 124) {
|
|
1483
|
+
folding = false;
|
|
1484
|
+
} else if (ch === 62) {
|
|
1485
|
+
folding = true;
|
|
1486
|
+
} else {
|
|
1487
|
+
return false;
|
|
1488
|
+
}
|
|
1489
|
+
state.kind = "scalar";
|
|
1490
|
+
state.result = "";
|
|
1491
|
+
while (ch !== 0) {
|
|
1492
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1493
|
+
if (ch === 43 || ch === 45) {
|
|
1494
|
+
if (CHOMPING_CLIP === chomping) {
|
|
1495
|
+
chomping = ch === 43 ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
1496
|
+
} else {
|
|
1497
|
+
throwError(state, "repeat of a chomping mode identifier");
|
|
1498
|
+
}
|
|
1499
|
+
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|
1500
|
+
if (tmp === 0) {
|
|
1501
|
+
throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
1502
|
+
} else if (!detectedIndent) {
|
|
1503
|
+
textIndent = nodeIndent + tmp - 1;
|
|
1504
|
+
detectedIndent = true;
|
|
1505
|
+
} else {
|
|
1506
|
+
throwError(state, "repeat of an indentation width identifier");
|
|
1507
|
+
}
|
|
1508
|
+
} else {
|
|
1509
|
+
break;
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
if (is_WHITE_SPACE(ch)) {
|
|
1513
|
+
do {
|
|
1514
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1515
|
+
} while (is_WHITE_SPACE(ch));
|
|
1516
|
+
if (ch === 35) {
|
|
1517
|
+
do {
|
|
1518
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1519
|
+
} while (!is_EOL(ch) && ch !== 0);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
while (ch !== 0) {
|
|
1523
|
+
readLineBreak(state);
|
|
1524
|
+
state.lineIndent = 0;
|
|
1525
|
+
ch = state.input.charCodeAt(state.position);
|
|
1526
|
+
while ((!detectedIndent || state.lineIndent < textIndent) && ch === 32) {
|
|
1527
|
+
state.lineIndent++;
|
|
1528
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1529
|
+
}
|
|
1530
|
+
if (!detectedIndent && state.lineIndent > textIndent) {
|
|
1531
|
+
textIndent = state.lineIndent;
|
|
1532
|
+
}
|
|
1533
|
+
if (is_EOL(ch)) {
|
|
1534
|
+
emptyLines++;
|
|
1535
|
+
continue;
|
|
1536
|
+
}
|
|
1537
|
+
if (state.lineIndent < textIndent) {
|
|
1538
|
+
if (chomping === CHOMPING_KEEP) {
|
|
1539
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1540
|
+
} else if (chomping === CHOMPING_CLIP) {
|
|
1541
|
+
if (didReadContent) {
|
|
1542
|
+
state.result += "\n";
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
break;
|
|
1546
|
+
}
|
|
1547
|
+
if (folding) {
|
|
1548
|
+
if (is_WHITE_SPACE(ch)) {
|
|
1549
|
+
atMoreIndented = true;
|
|
1550
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1551
|
+
} else if (atMoreIndented) {
|
|
1552
|
+
atMoreIndented = false;
|
|
1553
|
+
state.result += common.repeat("\n", emptyLines + 1);
|
|
1554
|
+
} else if (emptyLines === 0) {
|
|
1555
|
+
if (didReadContent) {
|
|
1556
|
+
state.result += " ";
|
|
1557
|
+
}
|
|
1558
|
+
} else {
|
|
1559
|
+
state.result += common.repeat("\n", emptyLines);
|
|
1560
|
+
}
|
|
1561
|
+
} else {
|
|
1562
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1563
|
+
}
|
|
1564
|
+
didReadContent = true;
|
|
1565
|
+
detectedIndent = true;
|
|
1566
|
+
emptyLines = 0;
|
|
1567
|
+
captureStart = state.position;
|
|
1568
|
+
while (!is_EOL(ch) && ch !== 0) {
|
|
1569
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1570
|
+
}
|
|
1571
|
+
captureSegment(state, captureStart, state.position, false);
|
|
1572
|
+
}
|
|
1573
|
+
return true;
|
|
1574
|
+
}
|
|
1575
|
+
function readBlockSequence(state, nodeIndent) {
|
|
1576
|
+
var _line, _tag = state.tag, _anchor = state.anchor, _result = [], following, detected = false, ch;
|
|
1577
|
+
if (state.firstTabInLine !== -1) return false;
|
|
1578
|
+
if (state.anchor !== null) {
|
|
1579
|
+
state.anchorMap[state.anchor] = _result;
|
|
1580
|
+
}
|
|
1581
|
+
ch = state.input.charCodeAt(state.position);
|
|
1582
|
+
while (ch !== 0) {
|
|
1583
|
+
if (state.firstTabInLine !== -1) {
|
|
1584
|
+
state.position = state.firstTabInLine;
|
|
1585
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
1586
|
+
}
|
|
1587
|
+
if (ch !== 45) {
|
|
1588
|
+
break;
|
|
1589
|
+
}
|
|
1590
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1591
|
+
if (!is_WS_OR_EOL(following)) {
|
|
1592
|
+
break;
|
|
1593
|
+
}
|
|
1594
|
+
detected = true;
|
|
1595
|
+
state.position++;
|
|
1596
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
1597
|
+
if (state.lineIndent <= nodeIndent) {
|
|
1598
|
+
_result.push(null);
|
|
1599
|
+
ch = state.input.charCodeAt(state.position);
|
|
1600
|
+
continue;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
_line = state.line;
|
|
1604
|
+
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|
1605
|
+
_result.push(state.result);
|
|
1606
|
+
skipSeparationSpace(state, true, -1);
|
|
1607
|
+
ch = state.input.charCodeAt(state.position);
|
|
1608
|
+
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1609
|
+
throwError(state, "bad indentation of a sequence entry");
|
|
1610
|
+
} else if (state.lineIndent < nodeIndent) {
|
|
1611
|
+
break;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
if (detected) {
|
|
1615
|
+
state.tag = _tag;
|
|
1616
|
+
state.anchor = _anchor;
|
|
1617
|
+
state.kind = "sequence";
|
|
1618
|
+
state.result = _result;
|
|
1619
|
+
return true;
|
|
1620
|
+
}
|
|
1621
|
+
return false;
|
|
1622
|
+
}
|
|
1623
|
+
function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
1624
|
+
var following, allowCompact, _line, _keyLine, _keyLineStart, _keyPos, _tag = state.tag, _anchor = state.anchor, _result = {}, overridableKeys = /* @__PURE__ */ Object.create(null), keyTag = null, keyNode = null, valueNode = null, atExplicitKey = false, detected = false, ch;
|
|
1625
|
+
if (state.firstTabInLine !== -1) return false;
|
|
1626
|
+
if (state.anchor !== null) {
|
|
1627
|
+
state.anchorMap[state.anchor] = _result;
|
|
1628
|
+
}
|
|
1629
|
+
ch = state.input.charCodeAt(state.position);
|
|
1630
|
+
while (ch !== 0) {
|
|
1631
|
+
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
1632
|
+
state.position = state.firstTabInLine;
|
|
1633
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
1634
|
+
}
|
|
1635
|
+
following = state.input.charCodeAt(state.position + 1);
|
|
1636
|
+
_line = state.line;
|
|
1637
|
+
if ((ch === 63 || ch === 58) && is_WS_OR_EOL(following)) {
|
|
1638
|
+
if (ch === 63) {
|
|
1639
|
+
if (atExplicitKey) {
|
|
1640
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1641
|
+
keyTag = keyNode = valueNode = null;
|
|
1642
|
+
}
|
|
1643
|
+
detected = true;
|
|
1644
|
+
atExplicitKey = true;
|
|
1645
|
+
allowCompact = true;
|
|
1646
|
+
} else if (atExplicitKey) {
|
|
1647
|
+
atExplicitKey = false;
|
|
1648
|
+
allowCompact = true;
|
|
1649
|
+
} else {
|
|
1650
|
+
throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
|
|
1651
|
+
}
|
|
1652
|
+
state.position += 1;
|
|
1653
|
+
ch = following;
|
|
1654
|
+
} else {
|
|
1655
|
+
_keyLine = state.line;
|
|
1656
|
+
_keyLineStart = state.lineStart;
|
|
1657
|
+
_keyPos = state.position;
|
|
1658
|
+
if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
|
1659
|
+
break;
|
|
1660
|
+
}
|
|
1661
|
+
if (state.line === _line) {
|
|
1662
|
+
ch = state.input.charCodeAt(state.position);
|
|
1663
|
+
while (is_WHITE_SPACE(ch)) {
|
|
1664
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1665
|
+
}
|
|
1666
|
+
if (ch === 58) {
|
|
1667
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1668
|
+
if (!is_WS_OR_EOL(ch)) {
|
|
1669
|
+
throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
1670
|
+
}
|
|
1671
|
+
if (atExplicitKey) {
|
|
1672
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1673
|
+
keyTag = keyNode = valueNode = null;
|
|
1674
|
+
}
|
|
1675
|
+
detected = true;
|
|
1676
|
+
atExplicitKey = false;
|
|
1677
|
+
allowCompact = false;
|
|
1678
|
+
keyTag = state.tag;
|
|
1679
|
+
keyNode = state.result;
|
|
1680
|
+
} else if (detected) {
|
|
1681
|
+
throwError(state, "can not read an implicit mapping pair; a colon is missed");
|
|
1682
|
+
} else {
|
|
1683
|
+
state.tag = _tag;
|
|
1684
|
+
state.anchor = _anchor;
|
|
1685
|
+
return true;
|
|
1686
|
+
}
|
|
1687
|
+
} else if (detected) {
|
|
1688
|
+
throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
1689
|
+
} else {
|
|
1690
|
+
state.tag = _tag;
|
|
1691
|
+
state.anchor = _anchor;
|
|
1692
|
+
return true;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
if (state.line === _line || state.lineIndent > nodeIndent) {
|
|
1696
|
+
if (atExplicitKey) {
|
|
1697
|
+
_keyLine = state.line;
|
|
1698
|
+
_keyLineStart = state.lineStart;
|
|
1699
|
+
_keyPos = state.position;
|
|
1700
|
+
}
|
|
1701
|
+
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
|
1702
|
+
if (atExplicitKey) {
|
|
1703
|
+
keyNode = state.result;
|
|
1704
|
+
} else {
|
|
1705
|
+
valueNode = state.result;
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
if (!atExplicitKey) {
|
|
1709
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
|
|
1710
|
+
keyTag = keyNode = valueNode = null;
|
|
1711
|
+
}
|
|
1712
|
+
skipSeparationSpace(state, true, -1);
|
|
1713
|
+
ch = state.input.charCodeAt(state.position);
|
|
1714
|
+
}
|
|
1715
|
+
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1716
|
+
throwError(state, "bad indentation of a mapping entry");
|
|
1717
|
+
} else if (state.lineIndent < nodeIndent) {
|
|
1718
|
+
break;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
if (atExplicitKey) {
|
|
1722
|
+
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
1723
|
+
}
|
|
1724
|
+
if (detected) {
|
|
1725
|
+
state.tag = _tag;
|
|
1726
|
+
state.anchor = _anchor;
|
|
1727
|
+
state.kind = "mapping";
|
|
1728
|
+
state.result = _result;
|
|
1729
|
+
}
|
|
1730
|
+
return detected;
|
|
1731
|
+
}
|
|
1732
|
+
function readTagProperty(state) {
|
|
1733
|
+
var _position, isVerbatim = false, isNamed = false, tagHandle, tagName, ch;
|
|
1734
|
+
ch = state.input.charCodeAt(state.position);
|
|
1735
|
+
if (ch !== 33) return false;
|
|
1736
|
+
if (state.tag !== null) {
|
|
1737
|
+
throwError(state, "duplication of a tag property");
|
|
1738
|
+
}
|
|
1739
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1740
|
+
if (ch === 60) {
|
|
1741
|
+
isVerbatim = true;
|
|
1742
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1743
|
+
} else if (ch === 33) {
|
|
1744
|
+
isNamed = true;
|
|
1745
|
+
tagHandle = "!!";
|
|
1746
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1747
|
+
} else {
|
|
1748
|
+
tagHandle = "!";
|
|
1749
|
+
}
|
|
1750
|
+
_position = state.position;
|
|
1751
|
+
if (isVerbatim) {
|
|
1752
|
+
do {
|
|
1753
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1754
|
+
} while (ch !== 0 && ch !== 62);
|
|
1755
|
+
if (state.position < state.length) {
|
|
1756
|
+
tagName = state.input.slice(_position, state.position);
|
|
1757
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1758
|
+
} else {
|
|
1759
|
+
throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
1760
|
+
}
|
|
1761
|
+
} else {
|
|
1762
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
1763
|
+
if (ch === 33) {
|
|
1764
|
+
if (!isNamed) {
|
|
1765
|
+
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|
1766
|
+
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
1767
|
+
throwError(state, "named tag handle cannot contain such characters");
|
|
1768
|
+
}
|
|
1769
|
+
isNamed = true;
|
|
1770
|
+
_position = state.position + 1;
|
|
1771
|
+
} else {
|
|
1772
|
+
throwError(state, "tag suffix cannot contain exclamation marks");
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1776
|
+
}
|
|
1777
|
+
tagName = state.input.slice(_position, state.position);
|
|
1778
|
+
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
1779
|
+
throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|
1783
|
+
throwError(state, "tag name cannot contain such characters: " + tagName);
|
|
1784
|
+
}
|
|
1785
|
+
try {
|
|
1786
|
+
tagName = decodeURIComponent(tagName);
|
|
1787
|
+
} catch (err) {
|
|
1788
|
+
throwError(state, "tag name is malformed: " + tagName);
|
|
1789
|
+
}
|
|
1790
|
+
if (isVerbatim) {
|
|
1791
|
+
state.tag = tagName;
|
|
1792
|
+
} else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
|
|
1793
|
+
state.tag = state.tagMap[tagHandle] + tagName;
|
|
1794
|
+
} else if (tagHandle === "!") {
|
|
1795
|
+
state.tag = "!" + tagName;
|
|
1796
|
+
} else if (tagHandle === "!!") {
|
|
1797
|
+
state.tag = "tag:yaml.org,2002:" + tagName;
|
|
1798
|
+
} else {
|
|
1799
|
+
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|
1800
|
+
}
|
|
1801
|
+
return true;
|
|
1802
|
+
}
|
|
1803
|
+
function readAnchorProperty(state) {
|
|
1804
|
+
var _position, ch;
|
|
1805
|
+
ch = state.input.charCodeAt(state.position);
|
|
1806
|
+
if (ch !== 38) return false;
|
|
1807
|
+
if (state.anchor !== null) {
|
|
1808
|
+
throwError(state, "duplication of an anchor property");
|
|
1809
|
+
}
|
|
1810
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1811
|
+
_position = state.position;
|
|
1812
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
1813
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1814
|
+
}
|
|
1815
|
+
if (state.position === _position) {
|
|
1816
|
+
throwError(state, "name of an anchor node must contain at least one character");
|
|
1817
|
+
}
|
|
1818
|
+
state.anchor = state.input.slice(_position, state.position);
|
|
1819
|
+
return true;
|
|
1820
|
+
}
|
|
1821
|
+
function readAlias(state) {
|
|
1822
|
+
var _position, alias, ch;
|
|
1823
|
+
ch = state.input.charCodeAt(state.position);
|
|
1824
|
+
if (ch !== 42) return false;
|
|
1825
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1826
|
+
_position = state.position;
|
|
1827
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|
1828
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1829
|
+
}
|
|
1830
|
+
if (state.position === _position) {
|
|
1831
|
+
throwError(state, "name of an alias node must contain at least one character");
|
|
1832
|
+
}
|
|
1833
|
+
alias = state.input.slice(_position, state.position);
|
|
1834
|
+
if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
|
|
1835
|
+
throwError(state, 'unidentified alias "' + alias + '"');
|
|
1836
|
+
}
|
|
1837
|
+
state.result = state.anchorMap[alias];
|
|
1838
|
+
skipSeparationSpace(state, true, -1);
|
|
1839
|
+
return true;
|
|
1840
|
+
}
|
|
1841
|
+
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|
1842
|
+
var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type2, flowIndent, blockIndent;
|
|
1843
|
+
if (state.listener !== null) {
|
|
1844
|
+
state.listener("open", state);
|
|
1845
|
+
}
|
|
1846
|
+
state.tag = null;
|
|
1847
|
+
state.anchor = null;
|
|
1848
|
+
state.kind = null;
|
|
1849
|
+
state.result = null;
|
|
1850
|
+
allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
|
|
1851
|
+
if (allowToSeek) {
|
|
1852
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
1853
|
+
atNewLine = true;
|
|
1854
|
+
if (state.lineIndent > parentIndent) {
|
|
1855
|
+
indentStatus = 1;
|
|
1856
|
+
} else if (state.lineIndent === parentIndent) {
|
|
1857
|
+
indentStatus = 0;
|
|
1858
|
+
} else if (state.lineIndent < parentIndent) {
|
|
1859
|
+
indentStatus = -1;
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
if (indentStatus === 1) {
|
|
1864
|
+
while (readTagProperty(state) || readAnchorProperty(state)) {
|
|
1865
|
+
if (skipSeparationSpace(state, true, -1)) {
|
|
1866
|
+
atNewLine = true;
|
|
1867
|
+
allowBlockCollections = allowBlockStyles;
|
|
1868
|
+
if (state.lineIndent > parentIndent) {
|
|
1869
|
+
indentStatus = 1;
|
|
1870
|
+
} else if (state.lineIndent === parentIndent) {
|
|
1871
|
+
indentStatus = 0;
|
|
1872
|
+
} else if (state.lineIndent < parentIndent) {
|
|
1873
|
+
indentStatus = -1;
|
|
1874
|
+
}
|
|
1875
|
+
} else {
|
|
1876
|
+
allowBlockCollections = false;
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
if (allowBlockCollections) {
|
|
1881
|
+
allowBlockCollections = atNewLine || allowCompact;
|
|
1882
|
+
}
|
|
1883
|
+
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
|
1884
|
+
if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
|
1885
|
+
flowIndent = parentIndent;
|
|
1886
|
+
} else {
|
|
1887
|
+
flowIndent = parentIndent + 1;
|
|
1888
|
+
}
|
|
1889
|
+
blockIndent = state.position - state.lineStart;
|
|
1890
|
+
if (indentStatus === 1) {
|
|
1891
|
+
if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
|
|
1892
|
+
hasContent = true;
|
|
1893
|
+
} else {
|
|
1894
|
+
if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
|
|
1895
|
+
hasContent = true;
|
|
1896
|
+
} else if (readAlias(state)) {
|
|
1897
|
+
hasContent = true;
|
|
1898
|
+
if (state.tag !== null || state.anchor !== null) {
|
|
1899
|
+
throwError(state, "alias node should not have any properties");
|
|
1900
|
+
}
|
|
1901
|
+
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|
1902
|
+
hasContent = true;
|
|
1903
|
+
if (state.tag === null) {
|
|
1904
|
+
state.tag = "?";
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
if (state.anchor !== null) {
|
|
1908
|
+
state.anchorMap[state.anchor] = state.result;
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
} else if (indentStatus === 0) {
|
|
1912
|
+
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
if (state.tag === null) {
|
|
1916
|
+
if (state.anchor !== null) {
|
|
1917
|
+
state.anchorMap[state.anchor] = state.result;
|
|
1918
|
+
}
|
|
1919
|
+
} else if (state.tag === "?") {
|
|
1920
|
+
if (state.result !== null && state.kind !== "scalar") {
|
|
1921
|
+
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|
1922
|
+
}
|
|
1923
|
+
for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|
1924
|
+
type2 = state.implicitTypes[typeIndex];
|
|
1925
|
+
if (type2.resolve(state.result)) {
|
|
1926
|
+
state.result = type2.construct(state.result);
|
|
1927
|
+
state.tag = type2.tag;
|
|
1928
|
+
if (state.anchor !== null) {
|
|
1929
|
+
state.anchorMap[state.anchor] = state.result;
|
|
1930
|
+
}
|
|
1931
|
+
break;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
} else if (state.tag !== "!") {
|
|
1935
|
+
if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
|
|
1936
|
+
type2 = state.typeMap[state.kind || "fallback"][state.tag];
|
|
1937
|
+
} else {
|
|
1938
|
+
type2 = null;
|
|
1939
|
+
typeList = state.typeMap.multi[state.kind || "fallback"];
|
|
1940
|
+
for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|
1941
|
+
if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
|
|
1942
|
+
type2 = typeList[typeIndex];
|
|
1943
|
+
break;
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
if (!type2) {
|
|
1948
|
+
throwError(state, "unknown tag !<" + state.tag + ">");
|
|
1949
|
+
}
|
|
1950
|
+
if (state.result !== null && type2.kind !== state.kind) {
|
|
1951
|
+
throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type2.kind + '", not "' + state.kind + '"');
|
|
1952
|
+
}
|
|
1953
|
+
if (!type2.resolve(state.result, state.tag)) {
|
|
1954
|
+
throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
|
|
1955
|
+
} else {
|
|
1956
|
+
state.result = type2.construct(state.result, state.tag);
|
|
1957
|
+
if (state.anchor !== null) {
|
|
1958
|
+
state.anchorMap[state.anchor] = state.result;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
if (state.listener !== null) {
|
|
1963
|
+
state.listener("close", state);
|
|
1964
|
+
}
|
|
1965
|
+
return state.tag !== null || state.anchor !== null || hasContent;
|
|
1966
|
+
}
|
|
1967
|
+
function readDocument(state) {
|
|
1968
|
+
var documentStart = state.position, _position, directiveName, directiveArgs, hasDirectives = false, ch;
|
|
1969
|
+
state.version = null;
|
|
1970
|
+
state.checkLineBreaks = state.legacy;
|
|
1971
|
+
state.tagMap = /* @__PURE__ */ Object.create(null);
|
|
1972
|
+
state.anchorMap = /* @__PURE__ */ Object.create(null);
|
|
1973
|
+
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|
1974
|
+
skipSeparationSpace(state, true, -1);
|
|
1975
|
+
ch = state.input.charCodeAt(state.position);
|
|
1976
|
+
if (state.lineIndent > 0 || ch !== 37) {
|
|
1977
|
+
break;
|
|
1978
|
+
}
|
|
1979
|
+
hasDirectives = true;
|
|
1980
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1981
|
+
_position = state.position;
|
|
1982
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
1983
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1984
|
+
}
|
|
1985
|
+
directiveName = state.input.slice(_position, state.position);
|
|
1986
|
+
directiveArgs = [];
|
|
1987
|
+
if (directiveName.length < 1) {
|
|
1988
|
+
throwError(state, "directive name must not be less than one character in length");
|
|
1989
|
+
}
|
|
1990
|
+
while (ch !== 0) {
|
|
1991
|
+
while (is_WHITE_SPACE(ch)) {
|
|
1992
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1993
|
+
}
|
|
1994
|
+
if (ch === 35) {
|
|
1995
|
+
do {
|
|
1996
|
+
ch = state.input.charCodeAt(++state.position);
|
|
1997
|
+
} while (ch !== 0 && !is_EOL(ch));
|
|
1998
|
+
break;
|
|
1999
|
+
}
|
|
2000
|
+
if (is_EOL(ch)) break;
|
|
2001
|
+
_position = state.position;
|
|
2002
|
+
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|
2003
|
+
ch = state.input.charCodeAt(++state.position);
|
|
2004
|
+
}
|
|
2005
|
+
directiveArgs.push(state.input.slice(_position, state.position));
|
|
2006
|
+
}
|
|
2007
|
+
if (ch !== 0) readLineBreak(state);
|
|
2008
|
+
if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
|
|
2009
|
+
directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
|
2010
|
+
} else {
|
|
2011
|
+
throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
skipSeparationSpace(state, true, -1);
|
|
2015
|
+
if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 45 && state.input.charCodeAt(state.position + 1) === 45 && state.input.charCodeAt(state.position + 2) === 45) {
|
|
2016
|
+
state.position += 3;
|
|
2017
|
+
skipSeparationSpace(state, true, -1);
|
|
2018
|
+
} else if (hasDirectives) {
|
|
2019
|
+
throwError(state, "directives end mark is expected");
|
|
2020
|
+
}
|
|
2021
|
+
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|
2022
|
+
skipSeparationSpace(state, true, -1);
|
|
2023
|
+
if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
2024
|
+
throwWarning(state, "non-ASCII line breaks are interpreted as content");
|
|
2025
|
+
}
|
|
2026
|
+
state.documents.push(state.result);
|
|
2027
|
+
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
2028
|
+
if (state.input.charCodeAt(state.position) === 46) {
|
|
2029
|
+
state.position += 3;
|
|
2030
|
+
skipSeparationSpace(state, true, -1);
|
|
2031
|
+
}
|
|
2032
|
+
return;
|
|
2033
|
+
}
|
|
2034
|
+
if (state.position < state.length - 1) {
|
|
2035
|
+
throwError(state, "end of the stream or a document separator is expected");
|
|
2036
|
+
} else {
|
|
2037
|
+
return;
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
function loadDocuments(input, options) {
|
|
2041
|
+
input = String(input);
|
|
2042
|
+
options = options || {};
|
|
2043
|
+
if (input.length !== 0) {
|
|
2044
|
+
if (input.charCodeAt(input.length - 1) !== 10 && input.charCodeAt(input.length - 1) !== 13) {
|
|
2045
|
+
input += "\n";
|
|
2046
|
+
}
|
|
2047
|
+
if (input.charCodeAt(0) === 65279) {
|
|
2048
|
+
input = input.slice(1);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
var state = new State$1(input, options);
|
|
2052
|
+
var nullpos = input.indexOf("\0");
|
|
2053
|
+
if (nullpos !== -1) {
|
|
2054
|
+
state.position = nullpos;
|
|
2055
|
+
throwError(state, "null byte is not allowed in input");
|
|
2056
|
+
}
|
|
2057
|
+
state.input += "\0";
|
|
2058
|
+
while (state.input.charCodeAt(state.position) === 32) {
|
|
2059
|
+
state.lineIndent += 1;
|
|
2060
|
+
state.position += 1;
|
|
2061
|
+
}
|
|
2062
|
+
while (state.position < state.length - 1) {
|
|
2063
|
+
readDocument(state);
|
|
2064
|
+
}
|
|
2065
|
+
return state.documents;
|
|
2066
|
+
}
|
|
2067
|
+
function loadAll$1(input, iterator, options) {
|
|
2068
|
+
if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
|
|
2069
|
+
options = iterator;
|
|
2070
|
+
iterator = null;
|
|
2071
|
+
}
|
|
2072
|
+
var documents = loadDocuments(input, options);
|
|
2073
|
+
if (typeof iterator !== "function") {
|
|
2074
|
+
return documents;
|
|
2075
|
+
}
|
|
2076
|
+
for (var index = 0, length = documents.length; index < length; index += 1) {
|
|
2077
|
+
iterator(documents[index]);
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
function load$1(input, options) {
|
|
2081
|
+
var documents = loadDocuments(input, options);
|
|
2082
|
+
if (documents.length === 0) {
|
|
2083
|
+
return void 0;
|
|
2084
|
+
} else if (documents.length === 1) {
|
|
2085
|
+
return documents[0];
|
|
2086
|
+
}
|
|
2087
|
+
throw new exception("expected a single document in the stream, but found more");
|
|
2088
|
+
}
|
|
2089
|
+
var loadAll_1 = loadAll$1;
|
|
2090
|
+
var load_1 = load$1;
|
|
2091
|
+
var loader = {
|
|
2092
|
+
loadAll: loadAll_1,
|
|
2093
|
+
load: load_1
|
|
2094
|
+
};
|
|
2095
|
+
var _toString = Object.prototype.toString;
|
|
2096
|
+
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2097
|
+
var CHAR_BOM = 65279;
|
|
2098
|
+
var CHAR_TAB = 9;
|
|
2099
|
+
var CHAR_LINE_FEED = 10;
|
|
2100
|
+
var CHAR_CARRIAGE_RETURN = 13;
|
|
2101
|
+
var CHAR_SPACE = 32;
|
|
2102
|
+
var CHAR_EXCLAMATION = 33;
|
|
2103
|
+
var CHAR_DOUBLE_QUOTE = 34;
|
|
2104
|
+
var CHAR_SHARP = 35;
|
|
2105
|
+
var CHAR_PERCENT = 37;
|
|
2106
|
+
var CHAR_AMPERSAND = 38;
|
|
2107
|
+
var CHAR_SINGLE_QUOTE = 39;
|
|
2108
|
+
var CHAR_ASTERISK = 42;
|
|
2109
|
+
var CHAR_COMMA = 44;
|
|
2110
|
+
var CHAR_MINUS = 45;
|
|
2111
|
+
var CHAR_COLON = 58;
|
|
2112
|
+
var CHAR_EQUALS = 61;
|
|
2113
|
+
var CHAR_GREATER_THAN = 62;
|
|
2114
|
+
var CHAR_QUESTION = 63;
|
|
2115
|
+
var CHAR_COMMERCIAL_AT = 64;
|
|
2116
|
+
var CHAR_LEFT_SQUARE_BRACKET = 91;
|
|
2117
|
+
var CHAR_RIGHT_SQUARE_BRACKET = 93;
|
|
2118
|
+
var CHAR_GRAVE_ACCENT = 96;
|
|
2119
|
+
var CHAR_LEFT_CURLY_BRACKET = 123;
|
|
2120
|
+
var CHAR_VERTICAL_LINE = 124;
|
|
2121
|
+
var CHAR_RIGHT_CURLY_BRACKET = 125;
|
|
2122
|
+
var ESCAPE_SEQUENCES = {};
|
|
2123
|
+
ESCAPE_SEQUENCES[0] = "\\0";
|
|
2124
|
+
ESCAPE_SEQUENCES[7] = "\\a";
|
|
2125
|
+
ESCAPE_SEQUENCES[8] = "\\b";
|
|
2126
|
+
ESCAPE_SEQUENCES[9] = "\\t";
|
|
2127
|
+
ESCAPE_SEQUENCES[10] = "\\n";
|
|
2128
|
+
ESCAPE_SEQUENCES[11] = "\\v";
|
|
2129
|
+
ESCAPE_SEQUENCES[12] = "\\f";
|
|
2130
|
+
ESCAPE_SEQUENCES[13] = "\\r";
|
|
2131
|
+
ESCAPE_SEQUENCES[27] = "\\e";
|
|
2132
|
+
ESCAPE_SEQUENCES[34] = '\\"';
|
|
2133
|
+
ESCAPE_SEQUENCES[92] = "\\\\";
|
|
2134
|
+
ESCAPE_SEQUENCES[133] = "\\N";
|
|
2135
|
+
ESCAPE_SEQUENCES[160] = "\\_";
|
|
2136
|
+
ESCAPE_SEQUENCES[8232] = "\\L";
|
|
2137
|
+
ESCAPE_SEQUENCES[8233] = "\\P";
|
|
2138
|
+
var DEPRECATED_BOOLEANS_SYNTAX = [
|
|
2139
|
+
"y",
|
|
2140
|
+
"Y",
|
|
2141
|
+
"yes",
|
|
2142
|
+
"Yes",
|
|
2143
|
+
"YES",
|
|
2144
|
+
"on",
|
|
2145
|
+
"On",
|
|
2146
|
+
"ON",
|
|
2147
|
+
"n",
|
|
2148
|
+
"N",
|
|
2149
|
+
"no",
|
|
2150
|
+
"No",
|
|
2151
|
+
"NO",
|
|
2152
|
+
"off",
|
|
2153
|
+
"Off",
|
|
2154
|
+
"OFF"
|
|
2155
|
+
];
|
|
2156
|
+
var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
|
|
2157
|
+
function compileStyleMap(schema2, map2) {
|
|
2158
|
+
var result, keys, index, length, tag, style, type2;
|
|
2159
|
+
if (map2 === null) return {};
|
|
2160
|
+
result = {};
|
|
2161
|
+
keys = Object.keys(map2);
|
|
2162
|
+
for (index = 0, length = keys.length; index < length; index += 1) {
|
|
2163
|
+
tag = keys[index];
|
|
2164
|
+
style = String(map2[tag]);
|
|
2165
|
+
if (tag.slice(0, 2) === "!!") {
|
|
2166
|
+
tag = "tag:yaml.org,2002:" + tag.slice(2);
|
|
2167
|
+
}
|
|
2168
|
+
type2 = schema2.compiledTypeMap["fallback"][tag];
|
|
2169
|
+
if (type2 && _hasOwnProperty.call(type2.styleAliases, style)) {
|
|
2170
|
+
style = type2.styleAliases[style];
|
|
2171
|
+
}
|
|
2172
|
+
result[tag] = style;
|
|
2173
|
+
}
|
|
2174
|
+
return result;
|
|
2175
|
+
}
|
|
2176
|
+
function encodeHex(character) {
|
|
2177
|
+
var string, handle, length;
|
|
2178
|
+
string = character.toString(16).toUpperCase();
|
|
2179
|
+
if (character <= 255) {
|
|
2180
|
+
handle = "x";
|
|
2181
|
+
length = 2;
|
|
2182
|
+
} else if (character <= 65535) {
|
|
2183
|
+
handle = "u";
|
|
2184
|
+
length = 4;
|
|
2185
|
+
} else if (character <= 4294967295) {
|
|
2186
|
+
handle = "U";
|
|
2187
|
+
length = 8;
|
|
2188
|
+
} else {
|
|
2189
|
+
throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
|
|
2190
|
+
}
|
|
2191
|
+
return "\\" + handle + common.repeat("0", length - string.length) + string;
|
|
2192
|
+
}
|
|
2193
|
+
var QUOTING_TYPE_SINGLE = 1;
|
|
2194
|
+
var QUOTING_TYPE_DOUBLE = 2;
|
|
2195
|
+
function State(options) {
|
|
2196
|
+
this.schema = options["schema"] || _default;
|
|
2197
|
+
this.indent = Math.max(1, options["indent"] || 2);
|
|
2198
|
+
this.noArrayIndent = options["noArrayIndent"] || false;
|
|
2199
|
+
this.skipInvalid = options["skipInvalid"] || false;
|
|
2200
|
+
this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
|
|
2201
|
+
this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
|
|
2202
|
+
this.sortKeys = options["sortKeys"] || false;
|
|
2203
|
+
this.lineWidth = options["lineWidth"] || 80;
|
|
2204
|
+
this.noRefs = options["noRefs"] || false;
|
|
2205
|
+
this.noCompatMode = options["noCompatMode"] || false;
|
|
2206
|
+
this.condenseFlow = options["condenseFlow"] || false;
|
|
2207
|
+
this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
|
|
2208
|
+
this.forceQuotes = options["forceQuotes"] || false;
|
|
2209
|
+
this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
|
|
2210
|
+
this.implicitTypes = this.schema.compiledImplicit;
|
|
2211
|
+
this.explicitTypes = this.schema.compiledExplicit;
|
|
2212
|
+
this.tag = null;
|
|
2213
|
+
this.result = "";
|
|
2214
|
+
this.duplicates = [];
|
|
2215
|
+
this.usedDuplicates = null;
|
|
2216
|
+
}
|
|
2217
|
+
function indentString(string, spaces) {
|
|
2218
|
+
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
|
|
2219
|
+
while (position < length) {
|
|
2220
|
+
next = string.indexOf("\n", position);
|
|
2221
|
+
if (next === -1) {
|
|
2222
|
+
line = string.slice(position);
|
|
2223
|
+
position = length;
|
|
2224
|
+
} else {
|
|
2225
|
+
line = string.slice(position, next + 1);
|
|
2226
|
+
position = next + 1;
|
|
2227
|
+
}
|
|
2228
|
+
if (line.length && line !== "\n") result += ind;
|
|
2229
|
+
result += line;
|
|
2230
|
+
}
|
|
2231
|
+
return result;
|
|
2232
|
+
}
|
|
2233
|
+
function generateNextLine(state, level) {
|
|
2234
|
+
return "\n" + common.repeat(" ", state.indent * level);
|
|
2235
|
+
}
|
|
2236
|
+
function testImplicitResolving(state, str2) {
|
|
2237
|
+
var index, length, type2;
|
|
2238
|
+
for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
|
|
2239
|
+
type2 = state.implicitTypes[index];
|
|
2240
|
+
if (type2.resolve(str2)) {
|
|
2241
|
+
return true;
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
return false;
|
|
2245
|
+
}
|
|
2246
|
+
function isWhitespace(c) {
|
|
2247
|
+
return c === CHAR_SPACE || c === CHAR_TAB;
|
|
2248
|
+
}
|
|
2249
|
+
function isPrintable(c) {
|
|
2250
|
+
return 32 <= c && c <= 126 || 161 <= c && c <= 55295 && c !== 8232 && c !== 8233 || 57344 <= c && c <= 65533 && c !== CHAR_BOM || 65536 <= c && c <= 1114111;
|
|
2251
|
+
}
|
|
2252
|
+
function isNsCharOrWhitespace(c) {
|
|
2253
|
+
return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
|
|
2254
|
+
}
|
|
2255
|
+
function isPlainSafe(c, prev, inblock) {
|
|
2256
|
+
var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
|
|
2257
|
+
var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
|
|
2258
|
+
return (
|
|
2259
|
+
// ns-plain-safe
|
|
2260
|
+
(inblock ? (
|
|
2261
|
+
// c = flow-in
|
|
2262
|
+
cIsNsCharOrWhitespace
|
|
2263
|
+
) : cIsNsCharOrWhitespace && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && c !== CHAR_SHARP && !(prev === CHAR_COLON && !cIsNsChar) || isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP || prev === CHAR_COLON && cIsNsChar
|
|
2264
|
+
);
|
|
2265
|
+
}
|
|
2266
|
+
function isPlainSafeFirst(c) {
|
|
2267
|
+
return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
|
|
2268
|
+
}
|
|
2269
|
+
function isPlainSafeLast(c) {
|
|
2270
|
+
return !isWhitespace(c) && c !== CHAR_COLON;
|
|
2271
|
+
}
|
|
2272
|
+
function codePointAt(string, pos) {
|
|
2273
|
+
var first = string.charCodeAt(pos), second;
|
|
2274
|
+
if (first >= 55296 && first <= 56319 && pos + 1 < string.length) {
|
|
2275
|
+
second = string.charCodeAt(pos + 1);
|
|
2276
|
+
if (second >= 56320 && second <= 57343) {
|
|
2277
|
+
return (first - 55296) * 1024 + second - 56320 + 65536;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
return first;
|
|
2281
|
+
}
|
|
2282
|
+
function needIndentIndicator(string) {
|
|
2283
|
+
var leadingSpaceRe = /^\n* /;
|
|
2284
|
+
return leadingSpaceRe.test(string);
|
|
2285
|
+
}
|
|
2286
|
+
var STYLE_PLAIN = 1;
|
|
2287
|
+
var STYLE_SINGLE = 2;
|
|
2288
|
+
var STYLE_LITERAL = 3;
|
|
2289
|
+
var STYLE_FOLDED = 4;
|
|
2290
|
+
var STYLE_DOUBLE = 5;
|
|
2291
|
+
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
|
|
2292
|
+
var i;
|
|
2293
|
+
var char = 0;
|
|
2294
|
+
var prevChar = null;
|
|
2295
|
+
var hasLineBreak = false;
|
|
2296
|
+
var hasFoldableLine = false;
|
|
2297
|
+
var shouldTrackWidth = lineWidth !== -1;
|
|
2298
|
+
var previousLineBreak = -1;
|
|
2299
|
+
var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
|
|
2300
|
+
if (singleLineOnly || forceQuotes) {
|
|
2301
|
+
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2302
|
+
char = codePointAt(string, i);
|
|
2303
|
+
if (!isPrintable(char)) {
|
|
2304
|
+
return STYLE_DOUBLE;
|
|
2305
|
+
}
|
|
2306
|
+
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2307
|
+
prevChar = char;
|
|
2308
|
+
}
|
|
2309
|
+
} else {
|
|
2310
|
+
for (i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2311
|
+
char = codePointAt(string, i);
|
|
2312
|
+
if (char === CHAR_LINE_FEED) {
|
|
2313
|
+
hasLineBreak = true;
|
|
2314
|
+
if (shouldTrackWidth) {
|
|
2315
|
+
hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
|
|
2316
|
+
i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2317
|
+
previousLineBreak = i;
|
|
2318
|
+
}
|
|
2319
|
+
} else if (!isPrintable(char)) {
|
|
2320
|
+
return STYLE_DOUBLE;
|
|
2321
|
+
}
|
|
2322
|
+
plain = plain && isPlainSafe(char, prevChar, inblock);
|
|
2323
|
+
prevChar = char;
|
|
2324
|
+
}
|
|
2325
|
+
hasFoldableLine = hasFoldableLine || shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ");
|
|
2326
|
+
}
|
|
2327
|
+
if (!hasLineBreak && !hasFoldableLine) {
|
|
2328
|
+
if (plain && !forceQuotes && !testAmbiguousType(string)) {
|
|
2329
|
+
return STYLE_PLAIN;
|
|
2330
|
+
}
|
|
2331
|
+
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2332
|
+
}
|
|
2333
|
+
if (indentPerLevel > 9 && needIndentIndicator(string)) {
|
|
2334
|
+
return STYLE_DOUBLE;
|
|
2335
|
+
}
|
|
2336
|
+
if (!forceQuotes) {
|
|
2337
|
+
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
|
2338
|
+
}
|
|
2339
|
+
return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
|
|
2340
|
+
}
|
|
2341
|
+
function writeScalar(state, string, level, iskey, inblock) {
|
|
2342
|
+
state.dump = (function() {
|
|
2343
|
+
if (string.length === 0) {
|
|
2344
|
+
return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
|
|
2345
|
+
}
|
|
2346
|
+
if (!state.noCompatMode) {
|
|
2347
|
+
if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
|
|
2348
|
+
return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
var indent = state.indent * Math.max(1, level);
|
|
2352
|
+
var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
|
2353
|
+
var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
|
|
2354
|
+
function testAmbiguity(string2) {
|
|
2355
|
+
return testImplicitResolving(state, string2);
|
|
2356
|
+
}
|
|
2357
|
+
switch (chooseScalarStyle(
|
|
2358
|
+
string,
|
|
2359
|
+
singleLineOnly,
|
|
2360
|
+
state.indent,
|
|
2361
|
+
lineWidth,
|
|
2362
|
+
testAmbiguity,
|
|
2363
|
+
state.quotingType,
|
|
2364
|
+
state.forceQuotes && !iskey,
|
|
2365
|
+
inblock
|
|
2366
|
+
)) {
|
|
2367
|
+
case STYLE_PLAIN:
|
|
2368
|
+
return string;
|
|
2369
|
+
case STYLE_SINGLE:
|
|
2370
|
+
return "'" + string.replace(/'/g, "''") + "'";
|
|
2371
|
+
case STYLE_LITERAL:
|
|
2372
|
+
return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
|
|
2373
|
+
case STYLE_FOLDED:
|
|
2374
|
+
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
2375
|
+
case STYLE_DOUBLE:
|
|
2376
|
+
return '"' + escapeString(string) + '"';
|
|
2377
|
+
default:
|
|
2378
|
+
throw new exception("impossible error: invalid scalar style");
|
|
2379
|
+
}
|
|
2380
|
+
})();
|
|
2381
|
+
}
|
|
2382
|
+
function blockHeader(string, indentPerLevel) {
|
|
2383
|
+
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2384
|
+
var clip = string[string.length - 1] === "\n";
|
|
2385
|
+
var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
|
|
2386
|
+
var chomp = keep ? "+" : clip ? "" : "-";
|
|
2387
|
+
return indentIndicator + chomp + "\n";
|
|
2388
|
+
}
|
|
2389
|
+
function dropEndingNewline(string) {
|
|
2390
|
+
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
|
|
2391
|
+
}
|
|
2392
|
+
function foldString(string, width) {
|
|
2393
|
+
var lineRe = /(\n+)([^\n]*)/g;
|
|
2394
|
+
var result = (function() {
|
|
2395
|
+
var nextLF = string.indexOf("\n");
|
|
2396
|
+
nextLF = nextLF !== -1 ? nextLF : string.length;
|
|
2397
|
+
lineRe.lastIndex = nextLF;
|
|
2398
|
+
return foldLine(string.slice(0, nextLF), width);
|
|
2399
|
+
})();
|
|
2400
|
+
var prevMoreIndented = string[0] === "\n" || string[0] === " ";
|
|
2401
|
+
var moreIndented;
|
|
2402
|
+
var match;
|
|
2403
|
+
while (match = lineRe.exec(string)) {
|
|
2404
|
+
var prefix = match[1], line = match[2];
|
|
2405
|
+
moreIndented = line[0] === " ";
|
|
2406
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
2407
|
+
prevMoreIndented = moreIndented;
|
|
2408
|
+
}
|
|
2409
|
+
return result;
|
|
2410
|
+
}
|
|
2411
|
+
function foldLine(line, width) {
|
|
2412
|
+
if (line === "" || line[0] === " ") return line;
|
|
2413
|
+
var breakRe = / [^ ]/g;
|
|
2414
|
+
var match;
|
|
2415
|
+
var start = 0, end, curr = 0, next = 0;
|
|
2416
|
+
var result = "";
|
|
2417
|
+
while (match = breakRe.exec(line)) {
|
|
2418
|
+
next = match.index;
|
|
2419
|
+
if (next - start > width) {
|
|
2420
|
+
end = curr > start ? curr : next;
|
|
2421
|
+
result += "\n" + line.slice(start, end);
|
|
2422
|
+
start = end + 1;
|
|
2423
|
+
}
|
|
2424
|
+
curr = next;
|
|
2425
|
+
}
|
|
2426
|
+
result += "\n";
|
|
2427
|
+
if (line.length - start > width && curr > start) {
|
|
2428
|
+
result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
|
|
2429
|
+
} else {
|
|
2430
|
+
result += line.slice(start);
|
|
2431
|
+
}
|
|
2432
|
+
return result.slice(1);
|
|
2433
|
+
}
|
|
2434
|
+
function escapeString(string) {
|
|
2435
|
+
var result = "";
|
|
2436
|
+
var char = 0;
|
|
2437
|
+
var escapeSeq;
|
|
2438
|
+
for (var i = 0; i < string.length; char >= 65536 ? i += 2 : i++) {
|
|
2439
|
+
char = codePointAt(string, i);
|
|
2440
|
+
escapeSeq = ESCAPE_SEQUENCES[char];
|
|
2441
|
+
if (!escapeSeq && isPrintable(char)) {
|
|
2442
|
+
result += string[i];
|
|
2443
|
+
if (char >= 65536) result += string[i + 1];
|
|
2444
|
+
} else {
|
|
2445
|
+
result += escapeSeq || encodeHex(char);
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
return result;
|
|
2449
|
+
}
|
|
2450
|
+
function writeFlowSequence(state, level, object) {
|
|
2451
|
+
var _result = "", _tag = state.tag, index, length, value;
|
|
2452
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2453
|
+
value = object[index];
|
|
2454
|
+
if (state.replacer) {
|
|
2455
|
+
value = state.replacer.call(object, String(index), value);
|
|
2456
|
+
}
|
|
2457
|
+
if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
|
|
2458
|
+
if (_result !== "") _result += "," + (!state.condenseFlow ? " " : "");
|
|
2459
|
+
_result += state.dump;
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
state.tag = _tag;
|
|
2463
|
+
state.dump = "[" + _result + "]";
|
|
2464
|
+
}
|
|
2465
|
+
function writeBlockSequence(state, level, object, compact) {
|
|
2466
|
+
var _result = "", _tag = state.tag, index, length, value;
|
|
2467
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2468
|
+
value = object[index];
|
|
2469
|
+
if (state.replacer) {
|
|
2470
|
+
value = state.replacer.call(object, String(index), value);
|
|
2471
|
+
}
|
|
2472
|
+
if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
|
|
2473
|
+
if (!compact || _result !== "") {
|
|
2474
|
+
_result += generateNextLine(state, level);
|
|
2475
|
+
}
|
|
2476
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2477
|
+
_result += "-";
|
|
2478
|
+
} else {
|
|
2479
|
+
_result += "- ";
|
|
2480
|
+
}
|
|
2481
|
+
_result += state.dump;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
state.tag = _tag;
|
|
2485
|
+
state.dump = _result || "[]";
|
|
2486
|
+
}
|
|
2487
|
+
function writeFlowMapping(state, level, object) {
|
|
2488
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
|
|
2489
|
+
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2490
|
+
pairBuffer = "";
|
|
2491
|
+
if (_result !== "") pairBuffer += ", ";
|
|
2492
|
+
if (state.condenseFlow) pairBuffer += '"';
|
|
2493
|
+
objectKey = objectKeyList[index];
|
|
2494
|
+
objectValue = object[objectKey];
|
|
2495
|
+
if (state.replacer) {
|
|
2496
|
+
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
2497
|
+
}
|
|
2498
|
+
if (!writeNode(state, level, objectKey, false, false)) {
|
|
2499
|
+
continue;
|
|
2500
|
+
}
|
|
2501
|
+
if (state.dump.length > 1024) pairBuffer += "? ";
|
|
2502
|
+
pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
|
|
2503
|
+
if (!writeNode(state, level, objectValue, false, false)) {
|
|
2504
|
+
continue;
|
|
2505
|
+
}
|
|
2506
|
+
pairBuffer += state.dump;
|
|
2507
|
+
_result += pairBuffer;
|
|
2508
|
+
}
|
|
2509
|
+
state.tag = _tag;
|
|
2510
|
+
state.dump = "{" + _result + "}";
|
|
2511
|
+
}
|
|
2512
|
+
function writeBlockMapping(state, level, object, compact) {
|
|
2513
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
|
|
2514
|
+
if (state.sortKeys === true) {
|
|
2515
|
+
objectKeyList.sort();
|
|
2516
|
+
} else if (typeof state.sortKeys === "function") {
|
|
2517
|
+
objectKeyList.sort(state.sortKeys);
|
|
2518
|
+
} else if (state.sortKeys) {
|
|
2519
|
+
throw new exception("sortKeys must be a boolean or a function");
|
|
2520
|
+
}
|
|
2521
|
+
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2522
|
+
pairBuffer = "";
|
|
2523
|
+
if (!compact || _result !== "") {
|
|
2524
|
+
pairBuffer += generateNextLine(state, level);
|
|
2525
|
+
}
|
|
2526
|
+
objectKey = objectKeyList[index];
|
|
2527
|
+
objectValue = object[objectKey];
|
|
2528
|
+
if (state.replacer) {
|
|
2529
|
+
objectValue = state.replacer.call(object, objectKey, objectValue);
|
|
2530
|
+
}
|
|
2531
|
+
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
|
2532
|
+
continue;
|
|
2533
|
+
}
|
|
2534
|
+
explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
|
|
2535
|
+
if (explicitPair) {
|
|
2536
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2537
|
+
pairBuffer += "?";
|
|
2538
|
+
} else {
|
|
2539
|
+
pairBuffer += "? ";
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2542
|
+
pairBuffer += state.dump;
|
|
2543
|
+
if (explicitPair) {
|
|
2544
|
+
pairBuffer += generateNextLine(state, level);
|
|
2545
|
+
}
|
|
2546
|
+
if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
|
2547
|
+
continue;
|
|
2548
|
+
}
|
|
2549
|
+
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2550
|
+
pairBuffer += ":";
|
|
2551
|
+
} else {
|
|
2552
|
+
pairBuffer += ": ";
|
|
2553
|
+
}
|
|
2554
|
+
pairBuffer += state.dump;
|
|
2555
|
+
_result += pairBuffer;
|
|
2556
|
+
}
|
|
2557
|
+
state.tag = _tag;
|
|
2558
|
+
state.dump = _result || "{}";
|
|
2559
|
+
}
|
|
2560
|
+
function detectType(state, object, explicit) {
|
|
2561
|
+
var _result, typeList, index, length, type2, style;
|
|
2562
|
+
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
|
2563
|
+
for (index = 0, length = typeList.length; index < length; index += 1) {
|
|
2564
|
+
type2 = typeList[index];
|
|
2565
|
+
if ((type2.instanceOf || type2.predicate) && (!type2.instanceOf || typeof object === "object" && object instanceof type2.instanceOf) && (!type2.predicate || type2.predicate(object))) {
|
|
2566
|
+
if (explicit) {
|
|
2567
|
+
if (type2.multi && type2.representName) {
|
|
2568
|
+
state.tag = type2.representName(object);
|
|
2569
|
+
} else {
|
|
2570
|
+
state.tag = type2.tag;
|
|
2571
|
+
}
|
|
2572
|
+
} else {
|
|
2573
|
+
state.tag = "?";
|
|
2574
|
+
}
|
|
2575
|
+
if (type2.represent) {
|
|
2576
|
+
style = state.styleMap[type2.tag] || type2.defaultStyle;
|
|
2577
|
+
if (_toString.call(type2.represent) === "[object Function]") {
|
|
2578
|
+
_result = type2.represent(object, style);
|
|
2579
|
+
} else if (_hasOwnProperty.call(type2.represent, style)) {
|
|
2580
|
+
_result = type2.represent[style](object, style);
|
|
2581
|
+
} else {
|
|
2582
|
+
throw new exception("!<" + type2.tag + '> tag resolver accepts not "' + style + '" style');
|
|
2583
|
+
}
|
|
2584
|
+
state.dump = _result;
|
|
2585
|
+
}
|
|
2586
|
+
return true;
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
return false;
|
|
2590
|
+
}
|
|
2591
|
+
function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
2592
|
+
state.tag = null;
|
|
2593
|
+
state.dump = object;
|
|
2594
|
+
if (!detectType(state, object, false)) {
|
|
2595
|
+
detectType(state, object, true);
|
|
2596
|
+
}
|
|
2597
|
+
var type2 = _toString.call(state.dump);
|
|
2598
|
+
var inblock = block;
|
|
2599
|
+
var tagStr;
|
|
2600
|
+
if (block) {
|
|
2601
|
+
block = state.flowLevel < 0 || state.flowLevel > level;
|
|
2602
|
+
}
|
|
2603
|
+
var objectOrArray = type2 === "[object Object]" || type2 === "[object Array]", duplicateIndex, duplicate;
|
|
2604
|
+
if (objectOrArray) {
|
|
2605
|
+
duplicateIndex = state.duplicates.indexOf(object);
|
|
2606
|
+
duplicate = duplicateIndex !== -1;
|
|
2607
|
+
}
|
|
2608
|
+
if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
|
|
2609
|
+
compact = false;
|
|
2610
|
+
}
|
|
2611
|
+
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
|
2612
|
+
state.dump = "*ref_" + duplicateIndex;
|
|
2613
|
+
} else {
|
|
2614
|
+
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
|
2615
|
+
state.usedDuplicates[duplicateIndex] = true;
|
|
2616
|
+
}
|
|
2617
|
+
if (type2 === "[object Object]") {
|
|
2618
|
+
if (block && Object.keys(state.dump).length !== 0) {
|
|
2619
|
+
writeBlockMapping(state, level, state.dump, compact);
|
|
2620
|
+
if (duplicate) {
|
|
2621
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2622
|
+
}
|
|
2623
|
+
} else {
|
|
2624
|
+
writeFlowMapping(state, level, state.dump);
|
|
2625
|
+
if (duplicate) {
|
|
2626
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
} else if (type2 === "[object Array]") {
|
|
2630
|
+
if (block && state.dump.length !== 0) {
|
|
2631
|
+
if (state.noArrayIndent && !isblockseq && level > 0) {
|
|
2632
|
+
writeBlockSequence(state, level - 1, state.dump, compact);
|
|
2633
|
+
} else {
|
|
2634
|
+
writeBlockSequence(state, level, state.dump, compact);
|
|
2635
|
+
}
|
|
2636
|
+
if (duplicate) {
|
|
2637
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2638
|
+
}
|
|
2639
|
+
} else {
|
|
2640
|
+
writeFlowSequence(state, level, state.dump);
|
|
2641
|
+
if (duplicate) {
|
|
2642
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
} else if (type2 === "[object String]") {
|
|
2646
|
+
if (state.tag !== "?") {
|
|
2647
|
+
writeScalar(state, state.dump, level, iskey, inblock);
|
|
2648
|
+
}
|
|
2649
|
+
} else if (type2 === "[object Undefined]") {
|
|
2650
|
+
return false;
|
|
2651
|
+
} else {
|
|
2652
|
+
if (state.skipInvalid) return false;
|
|
2653
|
+
throw new exception("unacceptable kind of an object to dump " + type2);
|
|
2654
|
+
}
|
|
2655
|
+
if (state.tag !== null && state.tag !== "?") {
|
|
2656
|
+
tagStr = encodeURI(
|
|
2657
|
+
state.tag[0] === "!" ? state.tag.slice(1) : state.tag
|
|
2658
|
+
).replace(/!/g, "%21");
|
|
2659
|
+
if (state.tag[0] === "!") {
|
|
2660
|
+
tagStr = "!" + tagStr;
|
|
2661
|
+
} else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
|
|
2662
|
+
tagStr = "!!" + tagStr.slice(18);
|
|
2663
|
+
} else {
|
|
2664
|
+
tagStr = "!<" + tagStr + ">";
|
|
2665
|
+
}
|
|
2666
|
+
state.dump = tagStr + " " + state.dump;
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
return true;
|
|
2670
|
+
}
|
|
2671
|
+
function getDuplicateReferences(object, state) {
|
|
2672
|
+
var objects = [], duplicatesIndexes = [], index, length;
|
|
2673
|
+
inspectNode(object, objects, duplicatesIndexes);
|
|
2674
|
+
for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
|
|
2675
|
+
state.duplicates.push(objects[duplicatesIndexes[index]]);
|
|
2676
|
+
}
|
|
2677
|
+
state.usedDuplicates = new Array(length);
|
|
2678
|
+
}
|
|
2679
|
+
function inspectNode(object, objects, duplicatesIndexes) {
|
|
2680
|
+
var objectKeyList, index, length;
|
|
2681
|
+
if (object !== null && typeof object === "object") {
|
|
2682
|
+
index = objects.indexOf(object);
|
|
2683
|
+
if (index !== -1) {
|
|
2684
|
+
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
2685
|
+
duplicatesIndexes.push(index);
|
|
2686
|
+
}
|
|
2687
|
+
} else {
|
|
2688
|
+
objects.push(object);
|
|
2689
|
+
if (Array.isArray(object)) {
|
|
2690
|
+
for (index = 0, length = object.length; index < length; index += 1) {
|
|
2691
|
+
inspectNode(object[index], objects, duplicatesIndexes);
|
|
2692
|
+
}
|
|
2693
|
+
} else {
|
|
2694
|
+
objectKeyList = Object.keys(object);
|
|
2695
|
+
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
|
2696
|
+
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
function dump$1(input, options) {
|
|
2703
|
+
options = options || {};
|
|
2704
|
+
var state = new State(options);
|
|
2705
|
+
if (!state.noRefs) getDuplicateReferences(input, state);
|
|
2706
|
+
var value = input;
|
|
2707
|
+
if (state.replacer) {
|
|
2708
|
+
value = state.replacer.call({ "": value }, "", value);
|
|
2709
|
+
}
|
|
2710
|
+
if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
|
|
2711
|
+
return "";
|
|
2712
|
+
}
|
|
2713
|
+
var dump_1 = dump$1;
|
|
2714
|
+
var dumper = {
|
|
2715
|
+
dump: dump_1
|
|
2716
|
+
};
|
|
2717
|
+
function renamed(from, to) {
|
|
2718
|
+
return function() {
|
|
2719
|
+
throw new Error("Function yaml." + from + " is removed in js-yaml 4. Use yaml." + to + " instead, which is now safe by default.");
|
|
2720
|
+
};
|
|
2721
|
+
}
|
|
2722
|
+
var load = loader.load;
|
|
2723
|
+
var loadAll = loader.loadAll;
|
|
2724
|
+
var dump = dumper.dump;
|
|
2725
|
+
var safeLoad = renamed("safeLoad", "load");
|
|
2726
|
+
var safeLoadAll = renamed("safeLoadAll", "loadAll");
|
|
2727
|
+
var safeDump = renamed("safeDump", "dump");
|
|
2728
|
+
|
|
2729
|
+
// packages/playbooks/src/parser.ts
|
|
2730
|
+
import { createHash } from "node:crypto";
|
|
2731
|
+
var PLAYBOOK_VERSION = "1.0";
|
|
2732
|
+
var MAX_ITERATION_CAP = 10;
|
|
2733
|
+
var ERROR_HANDLER_TRIGGERS = /* @__PURE__ */ new Set([
|
|
2734
|
+
"agentic_timeout",
|
|
2735
|
+
"iteration_cap_exceeded",
|
|
2736
|
+
"contract_violation"
|
|
2737
|
+
]);
|
|
2738
|
+
var ERROR_HANDLER_ACTIONS = /* @__PURE__ */ new Set([
|
|
2739
|
+
"inject_hint",
|
|
2740
|
+
"hitl_escalate",
|
|
2741
|
+
"abort"
|
|
2742
|
+
]);
|
|
2743
|
+
var AGENTIC_ROLES = /* @__PURE__ */ new Set([
|
|
2744
|
+
"orchestrator",
|
|
2745
|
+
"lead",
|
|
2746
|
+
"worker"
|
|
2747
|
+
]);
|
|
2748
|
+
var APPROVAL_POLICIES = /* @__PURE__ */ new Set(["conservative", "permissive", "custom"]);
|
|
2749
|
+
var PlaybookParseError = class extends Error {
|
|
2750
|
+
/**
|
|
2751
|
+
* @param message - Human-readable reason the playbook is invalid.
|
|
2752
|
+
* @param field - Offending field path (e.g. `"nodes[0].id"`).
|
|
2753
|
+
* @param value - Offending value for diagnostics (never re-thrown).
|
|
2754
|
+
*/
|
|
2755
|
+
constructor(message, field, value) {
|
|
2756
|
+
super(message);
|
|
2757
|
+
this.field = field;
|
|
2758
|
+
this.value = value;
|
|
2759
|
+
this.name = "PlaybookParseError";
|
|
2760
|
+
}
|
|
2761
|
+
field;
|
|
2762
|
+
value;
|
|
2763
|
+
/** Stable envelope error code for LAFS. */
|
|
2764
|
+
code = "E_PLAYBOOK_PARSE";
|
|
2765
|
+
/** Process exit code used by CLI wrappers when a parse fails. */
|
|
2766
|
+
exitCode = 70;
|
|
2767
|
+
};
|
|
2768
|
+
function parsePlaybook(source) {
|
|
2769
|
+
let raw;
|
|
2770
|
+
try {
|
|
2771
|
+
raw = load(source);
|
|
2772
|
+
} catch (err) {
|
|
2773
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
2774
|
+
throw new PlaybookParseError(`YAML syntax error: ${msg}`);
|
|
2775
|
+
}
|
|
2776
|
+
if (!isRecord(raw)) {
|
|
2777
|
+
throw new PlaybookParseError(".cantbook must be a YAML map at top level");
|
|
2778
|
+
}
|
|
2779
|
+
if (raw.version !== PLAYBOOK_VERSION) {
|
|
2780
|
+
throw new PlaybookParseError(
|
|
2781
|
+
`Unsupported version: ${formatValue(raw.version)}. Only "${PLAYBOOK_VERSION}" is supported.`,
|
|
2782
|
+
"version",
|
|
2783
|
+
raw.version
|
|
2784
|
+
);
|
|
2785
|
+
}
|
|
2786
|
+
const version = raw.version;
|
|
2787
|
+
if (typeof raw.name !== "string" || raw.name.length === 0) {
|
|
2788
|
+
throw new PlaybookParseError("name must be a non-empty string", "name", raw.name);
|
|
2789
|
+
}
|
|
2790
|
+
const name = raw.name;
|
|
2791
|
+
if (!Array.isArray(raw.nodes) || raw.nodes.length === 0) {
|
|
2792
|
+
throw new PlaybookParseError("nodes must be a non-empty array", "nodes", raw.nodes);
|
|
2793
|
+
}
|
|
2794
|
+
const nodes = raw.nodes.map((n, i) => parseNode(n, i));
|
|
2795
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2796
|
+
for (const n of nodes) {
|
|
2797
|
+
if (ids.has(n.id)) {
|
|
2798
|
+
throw new PlaybookParseError(`duplicate node id: ${n.id}`, "nodes", n.id);
|
|
2799
|
+
}
|
|
2800
|
+
ids.add(n.id);
|
|
2801
|
+
}
|
|
2802
|
+
const edgesRaw = raw.edges === void 0 ? [] : raw.edges;
|
|
2803
|
+
if (!Array.isArray(edgesRaw)) {
|
|
2804
|
+
throw new PlaybookParseError("edges must be an array", "edges", edgesRaw);
|
|
2805
|
+
}
|
|
2806
|
+
const edges = edgesRaw.map((e, i) => parseEdge(e, i, ids));
|
|
2807
|
+
for (const n of nodes) {
|
|
2808
|
+
if (!n.depends) continue;
|
|
2809
|
+
for (const dep of n.depends) {
|
|
2810
|
+
if (!ids.has(dep)) {
|
|
2811
|
+
throw new PlaybookParseError(`node ${n.id} depends on unknown node ${dep}`, "depends", dep);
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2815
|
+
for (const n of nodes) {
|
|
2816
|
+
const cap = n.on_failure?.max_iterations;
|
|
2817
|
+
if (cap !== void 0 && (cap < 0 || cap > MAX_ITERATION_CAP)) {
|
|
2818
|
+
throw new PlaybookParseError(
|
|
2819
|
+
`node ${n.id} max_iterations must be 0..${MAX_ITERATION_CAP} (got ${cap})`,
|
|
2820
|
+
"max_iterations",
|
|
2821
|
+
cap
|
|
2822
|
+
);
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
if (hasCycle(nodes, edges)) {
|
|
2826
|
+
throw new PlaybookParseError("playbook contains a cycle in node graph");
|
|
2827
|
+
}
|
|
2828
|
+
const definition = {
|
|
2829
|
+
version,
|
|
2830
|
+
name,
|
|
2831
|
+
description: typeof raw.description === "string" ? raw.description : void 0,
|
|
2832
|
+
inputs: parseInputs(raw.inputs),
|
|
2833
|
+
nodes,
|
|
2834
|
+
edges,
|
|
2835
|
+
error_handlers: parseErrorHandlers(raw.error_handlers)
|
|
2836
|
+
};
|
|
2837
|
+
const sourceHash = createHash("sha256").update(source).digest("hex");
|
|
2838
|
+
return { definition, sourceHash };
|
|
2839
|
+
}
|
|
2840
|
+
function parseNode(raw, index) {
|
|
2841
|
+
if (!isRecord(raw)) {
|
|
2842
|
+
throw new PlaybookParseError(`nodes[${index}] must be an object`, `nodes[${index}]`, raw);
|
|
2843
|
+
}
|
|
2844
|
+
if (typeof raw.id !== "string" || raw.id.length === 0) {
|
|
2845
|
+
throw new PlaybookParseError(
|
|
2846
|
+
`nodes[${index}].id must be a non-empty string`,
|
|
2847
|
+
`nodes[${index}].id`,
|
|
2848
|
+
raw.id
|
|
2849
|
+
);
|
|
2850
|
+
}
|
|
2851
|
+
const id = raw.id;
|
|
2852
|
+
if (typeof raw.type !== "string") {
|
|
2853
|
+
throw new PlaybookParseError(
|
|
2854
|
+
`nodes[${index}].type must be a string`,
|
|
2855
|
+
`nodes[${index}].type`,
|
|
2856
|
+
raw.type
|
|
2857
|
+
);
|
|
2858
|
+
}
|
|
2859
|
+
const type2 = raw.type;
|
|
2860
|
+
const description = typeof raw.description === "string" ? raw.description : void 0;
|
|
2861
|
+
const depends = parseStringArray(raw.depends, `nodes[${index}].depends`);
|
|
2862
|
+
const requires = parseRequires(raw.requires, `nodes[${index}].requires`);
|
|
2863
|
+
const ensures = parseEnsures(raw.ensures, `nodes[${index}].ensures`);
|
|
2864
|
+
const on_failure = parseOnFailure(raw.on_failure, `nodes[${index}].on_failure`);
|
|
2865
|
+
const base = {
|
|
2866
|
+
id,
|
|
2867
|
+
description,
|
|
2868
|
+
depends,
|
|
2869
|
+
requires,
|
|
2870
|
+
ensures,
|
|
2871
|
+
on_failure
|
|
2872
|
+
};
|
|
2873
|
+
switch (type2) {
|
|
2874
|
+
case "agentic":
|
|
2875
|
+
return parseAgenticNode(raw, base, index);
|
|
2876
|
+
case "deterministic":
|
|
2877
|
+
return parseDeterministicNode(raw, base, index);
|
|
2878
|
+
case "approval":
|
|
2879
|
+
return parseApprovalNode(raw, base, index);
|
|
2880
|
+
default:
|
|
2881
|
+
throw new PlaybookParseError(
|
|
2882
|
+
`nodes[${index}].type must be one of agentic | deterministic | approval (got ${formatValue(
|
|
2883
|
+
raw.type
|
|
2884
|
+
)})`,
|
|
2885
|
+
`nodes[${index}].type`,
|
|
2886
|
+
raw.type
|
|
2887
|
+
);
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
function parseAgenticNode(raw, base, index) {
|
|
2891
|
+
const skill = typeof raw.skill === "string" ? raw.skill : void 0;
|
|
2892
|
+
const agent = typeof raw.agent === "string" ? raw.agent : void 0;
|
|
2893
|
+
if (!skill && !agent) {
|
|
2894
|
+
throw new PlaybookParseError(
|
|
2895
|
+
`nodes[${index}] (agentic) must define at least one of 'skill' or 'agent'`,
|
|
2896
|
+
`nodes[${index}]`,
|
|
2897
|
+
raw
|
|
2898
|
+
);
|
|
2899
|
+
}
|
|
2900
|
+
let role;
|
|
2901
|
+
if (raw.role !== void 0) {
|
|
2902
|
+
if (typeof raw.role !== "string" || !AGENTIC_ROLES.has(raw.role)) {
|
|
2903
|
+
throw new PlaybookParseError(
|
|
2904
|
+
`nodes[${index}].role must be one of orchestrator | lead | worker (got ${formatValue(
|
|
2905
|
+
raw.role
|
|
2906
|
+
)})`,
|
|
2907
|
+
`nodes[${index}].role`,
|
|
2908
|
+
raw.role
|
|
2909
|
+
);
|
|
2910
|
+
}
|
|
2911
|
+
role = raw.role;
|
|
2912
|
+
}
|
|
2913
|
+
let inputs;
|
|
2914
|
+
if (raw.inputs !== void 0) {
|
|
2915
|
+
if (!isRecord(raw.inputs)) {
|
|
2916
|
+
throw new PlaybookParseError(
|
|
2917
|
+
`nodes[${index}].inputs must be an object`,
|
|
2918
|
+
`nodes[${index}].inputs`,
|
|
2919
|
+
raw.inputs
|
|
2920
|
+
);
|
|
2921
|
+
}
|
|
2922
|
+
const acc = {};
|
|
2923
|
+
for (const [k, v] of Object.entries(raw.inputs)) {
|
|
2924
|
+
if (typeof v !== "string") {
|
|
2925
|
+
throw new PlaybookParseError(
|
|
2926
|
+
`nodes[${index}].inputs.${k} must be a string`,
|
|
2927
|
+
`nodes[${index}].inputs.${k}`,
|
|
2928
|
+
v
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2931
|
+
acc[k] = v;
|
|
2932
|
+
}
|
|
2933
|
+
inputs = acc;
|
|
2934
|
+
}
|
|
2935
|
+
const context_files = parseStringArray(raw.context_files, `nodes[${index}].context_files`);
|
|
2936
|
+
const profile = parseOptionalNonEmptyString(raw.profile, `nodes[${index}].profile`);
|
|
2937
|
+
const model = parseOptionalNonEmptyString(raw.model, `nodes[${index}].model`);
|
|
2938
|
+
const provider = parseOptionalNonEmptyString(raw.provider, `nodes[${index}].provider`);
|
|
2939
|
+
const allowed_skills = parseStringArray(raw.allowed_skills, `nodes[${index}].allowed_skills`);
|
|
2940
|
+
const allowed_tools = parseStringArray(raw.allowed_tools, `nodes[${index}].allowed_tools`);
|
|
2941
|
+
return {
|
|
2942
|
+
...base,
|
|
2943
|
+
type: "agentic",
|
|
2944
|
+
skill,
|
|
2945
|
+
agent,
|
|
2946
|
+
role,
|
|
2947
|
+
inputs,
|
|
2948
|
+
...context_files !== void 0 ? { context_files } : {},
|
|
2949
|
+
...profile !== void 0 ? { profile } : {},
|
|
2950
|
+
...model !== void 0 ? { model } : {},
|
|
2951
|
+
...provider !== void 0 ? { provider } : {},
|
|
2952
|
+
...allowed_skills !== void 0 ? { allowed_skills } : {},
|
|
2953
|
+
...allowed_tools !== void 0 ? { allowed_tools } : {}
|
|
2954
|
+
};
|
|
2955
|
+
}
|
|
2956
|
+
function parseDeterministicNode(raw, base, index) {
|
|
2957
|
+
if (typeof raw.command !== "string" || raw.command.length === 0) {
|
|
2958
|
+
throw new PlaybookParseError(
|
|
2959
|
+
`nodes[${index}] (deterministic) must have a non-empty 'command'`,
|
|
2960
|
+
`nodes[${index}].command`,
|
|
2961
|
+
raw.command
|
|
2962
|
+
);
|
|
2963
|
+
}
|
|
2964
|
+
const args = parseStringArray(raw.args, `nodes[${index}].args`) ?? [];
|
|
2965
|
+
const cwd = typeof raw.cwd === "string" ? raw.cwd : void 0;
|
|
2966
|
+
let env;
|
|
2967
|
+
if (raw.env !== void 0) {
|
|
2968
|
+
if (!isRecord(raw.env)) {
|
|
2969
|
+
throw new PlaybookParseError(
|
|
2970
|
+
`nodes[${index}].env must be an object`,
|
|
2971
|
+
`nodes[${index}].env`,
|
|
2972
|
+
raw.env
|
|
2973
|
+
);
|
|
2974
|
+
}
|
|
2975
|
+
const acc = {};
|
|
2976
|
+
for (const [k, v] of Object.entries(raw.env)) {
|
|
2977
|
+
if (typeof v !== "string") {
|
|
2978
|
+
throw new PlaybookParseError(
|
|
2979
|
+
`nodes[${index}].env.${k} must be a string`,
|
|
2980
|
+
`nodes[${index}].env.${k}`,
|
|
2981
|
+
v
|
|
2982
|
+
);
|
|
2983
|
+
}
|
|
2984
|
+
acc[k] = v;
|
|
2985
|
+
}
|
|
2986
|
+
env = acc;
|
|
2987
|
+
}
|
|
2988
|
+
let timeout_ms;
|
|
2989
|
+
if (raw.timeout_ms !== void 0) {
|
|
2990
|
+
if (typeof raw.timeout_ms !== "number" || !Number.isFinite(raw.timeout_ms) || raw.timeout_ms < 0) {
|
|
2991
|
+
throw new PlaybookParseError(
|
|
2992
|
+
`nodes[${index}].timeout_ms must be a non-negative number`,
|
|
2993
|
+
`nodes[${index}].timeout_ms`,
|
|
2994
|
+
raw.timeout_ms
|
|
2995
|
+
);
|
|
2996
|
+
}
|
|
2997
|
+
timeout_ms = raw.timeout_ms;
|
|
2998
|
+
}
|
|
2999
|
+
return {
|
|
3000
|
+
...base,
|
|
3001
|
+
type: "deterministic",
|
|
3002
|
+
command: raw.command,
|
|
3003
|
+
args,
|
|
3004
|
+
cwd,
|
|
3005
|
+
env,
|
|
3006
|
+
timeout_ms
|
|
3007
|
+
};
|
|
3008
|
+
}
|
|
3009
|
+
function parseApprovalNode(raw, base, index) {
|
|
3010
|
+
if (typeof raw.prompt !== "string" || raw.prompt.length === 0) {
|
|
3011
|
+
throw new PlaybookParseError(
|
|
3012
|
+
`nodes[${index}] (approval) must have a non-empty 'prompt'`,
|
|
3013
|
+
`nodes[${index}].prompt`,
|
|
3014
|
+
raw.prompt
|
|
3015
|
+
);
|
|
3016
|
+
}
|
|
3017
|
+
let policy;
|
|
3018
|
+
if (raw.policy !== void 0) {
|
|
3019
|
+
if (typeof raw.policy !== "string" || !APPROVAL_POLICIES.has(raw.policy)) {
|
|
3020
|
+
throw new PlaybookParseError(
|
|
3021
|
+
`nodes[${index}].policy must be one of conservative | permissive | custom (got ${formatValue(
|
|
3022
|
+
raw.policy
|
|
3023
|
+
)})`,
|
|
3024
|
+
`nodes[${index}].policy`,
|
|
3025
|
+
raw.policy
|
|
3026
|
+
);
|
|
3027
|
+
}
|
|
3028
|
+
policy = raw.policy;
|
|
3029
|
+
}
|
|
3030
|
+
return {
|
|
3031
|
+
...base,
|
|
3032
|
+
type: "approval",
|
|
3033
|
+
prompt: raw.prompt,
|
|
3034
|
+
policy
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
function parseEdge(raw, index, ids) {
|
|
3038
|
+
if (!isRecord(raw)) {
|
|
3039
|
+
throw new PlaybookParseError(`edges[${index}] must be an object`, `edges[${index}]`, raw);
|
|
3040
|
+
}
|
|
3041
|
+
if (typeof raw.from !== "string" || raw.from.length === 0) {
|
|
3042
|
+
throw new PlaybookParseError(
|
|
3043
|
+
`edges[${index}].from must be a non-empty string`,
|
|
3044
|
+
`edges[${index}].from`,
|
|
3045
|
+
raw.from
|
|
3046
|
+
);
|
|
3047
|
+
}
|
|
3048
|
+
if (typeof raw.to !== "string" || raw.to.length === 0) {
|
|
3049
|
+
throw new PlaybookParseError(
|
|
3050
|
+
`edges[${index}].to must be a non-empty string`,
|
|
3051
|
+
`edges[${index}].to`,
|
|
3052
|
+
raw.to
|
|
3053
|
+
);
|
|
3054
|
+
}
|
|
3055
|
+
if (!ids.has(raw.from)) {
|
|
3056
|
+
throw new PlaybookParseError(
|
|
3057
|
+
`edges[${index}].from references unknown node ${raw.from}`,
|
|
3058
|
+
`edges[${index}].from`,
|
|
3059
|
+
raw.from
|
|
3060
|
+
);
|
|
3061
|
+
}
|
|
3062
|
+
if (!ids.has(raw.to)) {
|
|
3063
|
+
throw new PlaybookParseError(
|
|
3064
|
+
`edges[${index}].to references unknown node ${raw.to}`,
|
|
3065
|
+
`edges[${index}].to`,
|
|
3066
|
+
raw.to
|
|
3067
|
+
);
|
|
3068
|
+
}
|
|
3069
|
+
let contract;
|
|
3070
|
+
if (raw.contract !== void 0) {
|
|
3071
|
+
if (!isRecord(raw.contract)) {
|
|
3072
|
+
throw new PlaybookParseError(
|
|
3073
|
+
`edges[${index}].contract must be an object`,
|
|
3074
|
+
`edges[${index}].contract`,
|
|
3075
|
+
raw.contract
|
|
3076
|
+
);
|
|
3077
|
+
}
|
|
3078
|
+
const requires = parseStringArray(raw.contract.requires, `edges[${index}].contract.requires`);
|
|
3079
|
+
const ensures = parseStringArray(raw.contract.ensures, `edges[${index}].contract.ensures`);
|
|
3080
|
+
contract = { requires, ensures };
|
|
3081
|
+
}
|
|
3082
|
+
const when = parseEdgeCondition(raw.when, `edges[${index}].when`);
|
|
3083
|
+
const edge = { from: raw.from, to: raw.to, contract };
|
|
3084
|
+
if (when !== void 0) edge.when = when;
|
|
3085
|
+
return edge;
|
|
3086
|
+
}
|
|
3087
|
+
var EDGE_CONDITION_OPERATORS = ["equals", "notEquals", "exists", "in", "truthy"];
|
|
3088
|
+
function parseEdgeCondition(raw, field) {
|
|
3089
|
+
if (raw === void 0) return void 0;
|
|
3090
|
+
if (!isRecord(raw)) {
|
|
3091
|
+
throw new PlaybookParseError(`${field} must be an object`, field, raw);
|
|
3092
|
+
}
|
|
3093
|
+
if (typeof raw.field !== "string" || raw.field.length === 0) {
|
|
3094
|
+
throw new PlaybookParseError(
|
|
3095
|
+
`${field}.field must be a non-empty string`,
|
|
3096
|
+
`${field}.field`,
|
|
3097
|
+
raw.field
|
|
3098
|
+
);
|
|
3099
|
+
}
|
|
3100
|
+
const present = EDGE_CONDITION_OPERATORS.filter((op2) => Object.hasOwn(raw, op2));
|
|
3101
|
+
if (present.length === 0) {
|
|
3102
|
+
throw new PlaybookParseError(
|
|
3103
|
+
`${field} must declare exactly one of ${EDGE_CONDITION_OPERATORS.join(" | ")}`,
|
|
3104
|
+
field,
|
|
3105
|
+
raw
|
|
3106
|
+
);
|
|
3107
|
+
}
|
|
3108
|
+
if (present.length > 1) {
|
|
3109
|
+
throw new PlaybookParseError(
|
|
3110
|
+
`${field} declares multiple operators (${present.join(", ")}); exactly one is allowed`,
|
|
3111
|
+
field,
|
|
3112
|
+
raw
|
|
3113
|
+
);
|
|
3114
|
+
}
|
|
3115
|
+
const condition = { field: raw.field };
|
|
3116
|
+
const [op] = present;
|
|
3117
|
+
switch (op) {
|
|
3118
|
+
case "equals":
|
|
3119
|
+
condition.equals = raw.equals;
|
|
3120
|
+
break;
|
|
3121
|
+
case "notEquals":
|
|
3122
|
+
condition.notEquals = raw.notEquals;
|
|
3123
|
+
break;
|
|
3124
|
+
case "in":
|
|
3125
|
+
if (!Array.isArray(raw.in) || raw.in.length === 0) {
|
|
3126
|
+
throw new PlaybookParseError(
|
|
3127
|
+
`${field}.in must be a non-empty array`,
|
|
3128
|
+
`${field}.in`,
|
|
3129
|
+
raw.in
|
|
3130
|
+
);
|
|
3131
|
+
}
|
|
3132
|
+
condition.in = [...raw.in];
|
|
3133
|
+
break;
|
|
3134
|
+
case "exists":
|
|
3135
|
+
if (typeof raw.exists !== "boolean") {
|
|
3136
|
+
throw new PlaybookParseError(
|
|
3137
|
+
`${field}.exists must be a boolean`,
|
|
3138
|
+
`${field}.exists`,
|
|
3139
|
+
raw.exists
|
|
3140
|
+
);
|
|
3141
|
+
}
|
|
3142
|
+
condition.exists = raw.exists;
|
|
3143
|
+
break;
|
|
3144
|
+
case "truthy":
|
|
3145
|
+
if (typeof raw.truthy !== "boolean") {
|
|
3146
|
+
throw new PlaybookParseError(
|
|
3147
|
+
`${field}.truthy must be a boolean`,
|
|
3148
|
+
`${field}.truthy`,
|
|
3149
|
+
raw.truthy
|
|
3150
|
+
);
|
|
3151
|
+
}
|
|
3152
|
+
condition.truthy = raw.truthy;
|
|
3153
|
+
break;
|
|
3154
|
+
default: {
|
|
3155
|
+
const exhaustive = op;
|
|
3156
|
+
throw new PlaybookParseError(`${field} unknown operator ${String(exhaustive)}`, field, raw);
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
return condition;
|
|
3160
|
+
}
|
|
3161
|
+
function parseInputs(raw) {
|
|
3162
|
+
if (raw === void 0) return void 0;
|
|
3163
|
+
if (!Array.isArray(raw)) {
|
|
3164
|
+
throw new PlaybookParseError("inputs must be an array", "inputs", raw);
|
|
3165
|
+
}
|
|
3166
|
+
return raw.map((r, i) => {
|
|
3167
|
+
if (!isRecord(r)) {
|
|
3168
|
+
throw new PlaybookParseError(`inputs[${i}] must be an object`, `inputs[${i}]`, r);
|
|
3169
|
+
}
|
|
3170
|
+
if (typeof r.name !== "string" || r.name.length === 0) {
|
|
3171
|
+
throw new PlaybookParseError(
|
|
3172
|
+
`inputs[${i}].name must be a non-empty string`,
|
|
3173
|
+
`inputs[${i}].name`,
|
|
3174
|
+
r.name
|
|
3175
|
+
);
|
|
3176
|
+
}
|
|
3177
|
+
let required;
|
|
3178
|
+
if (r.required !== void 0) {
|
|
3179
|
+
if (typeof r.required !== "boolean") {
|
|
3180
|
+
throw new PlaybookParseError(
|
|
3181
|
+
`inputs[${i}].required must be boolean`,
|
|
3182
|
+
`inputs[${i}].required`,
|
|
3183
|
+
r.required
|
|
3184
|
+
);
|
|
3185
|
+
}
|
|
3186
|
+
required = r.required;
|
|
3187
|
+
}
|
|
3188
|
+
const description = typeof r.description === "string" ? r.description : void 0;
|
|
3189
|
+
const input = { name: r.name };
|
|
3190
|
+
if (required !== void 0) input.required = required;
|
|
3191
|
+
if (Object.hasOwn(r, "default")) input.default = r.default;
|
|
3192
|
+
if (description !== void 0) input.description = description;
|
|
3193
|
+
return input;
|
|
3194
|
+
});
|
|
3195
|
+
}
|
|
3196
|
+
function parseErrorHandlers(raw) {
|
|
3197
|
+
if (raw === void 0) return void 0;
|
|
3198
|
+
if (!Array.isArray(raw)) {
|
|
3199
|
+
throw new PlaybookParseError("error_handlers must be an array", "error_handlers", raw);
|
|
3200
|
+
}
|
|
3201
|
+
return raw.map((r, i) => {
|
|
3202
|
+
if (!isRecord(r)) {
|
|
3203
|
+
throw new PlaybookParseError(
|
|
3204
|
+
`error_handlers[${i}] must be an object`,
|
|
3205
|
+
`error_handlers[${i}]`,
|
|
3206
|
+
r
|
|
3207
|
+
);
|
|
3208
|
+
}
|
|
3209
|
+
if (typeof r.on !== "string" || !ERROR_HANDLER_TRIGGERS.has(r.on)) {
|
|
3210
|
+
throw new PlaybookParseError(
|
|
3211
|
+
`error_handlers[${i}].on must be one of agentic_timeout | iteration_cap_exceeded | contract_violation (got ${formatValue(
|
|
3212
|
+
r.on
|
|
3213
|
+
)})`,
|
|
3214
|
+
`error_handlers[${i}].on`,
|
|
3215
|
+
r.on
|
|
3216
|
+
);
|
|
3217
|
+
}
|
|
3218
|
+
if (typeof r.action !== "string" || !ERROR_HANDLER_ACTIONS.has(r.action)) {
|
|
3219
|
+
throw new PlaybookParseError(
|
|
3220
|
+
`error_handlers[${i}].action must be one of inject_hint | hitl_escalate | abort (got ${formatValue(
|
|
3221
|
+
r.action
|
|
3222
|
+
)})`,
|
|
3223
|
+
`error_handlers[${i}].action`,
|
|
3224
|
+
r.action
|
|
3225
|
+
);
|
|
3226
|
+
}
|
|
3227
|
+
const message = typeof r.message === "string" ? r.message : void 0;
|
|
3228
|
+
return {
|
|
3229
|
+
on: r.on,
|
|
3230
|
+
action: r.action,
|
|
3231
|
+
message
|
|
3232
|
+
};
|
|
3233
|
+
});
|
|
3234
|
+
}
|
|
3235
|
+
function parseRequires(raw, field) {
|
|
3236
|
+
if (raw === void 0) return void 0;
|
|
3237
|
+
if (!isRecord(raw)) {
|
|
3238
|
+
throw new PlaybookParseError(`${field} must be an object`, field, raw);
|
|
3239
|
+
}
|
|
3240
|
+
const from = typeof raw.from === "string" ? raw.from : void 0;
|
|
3241
|
+
const fields = parseStringArray(raw.fields, `${field}.fields`);
|
|
3242
|
+
const schema2 = typeof raw.schema === "string" ? raw.schema : void 0;
|
|
3243
|
+
return { from, fields, schema: schema2 };
|
|
3244
|
+
}
|
|
3245
|
+
function parseEnsures(raw, field) {
|
|
3246
|
+
if (raw === void 0) return void 0;
|
|
3247
|
+
if (!isRecord(raw)) {
|
|
3248
|
+
throw new PlaybookParseError(`${field} must be an object`, field, raw);
|
|
3249
|
+
}
|
|
3250
|
+
const outputFiles = parseStringArray(raw.outputFiles, `${field}.outputFiles`);
|
|
3251
|
+
let exitCode;
|
|
3252
|
+
if (raw.exitCode !== void 0) {
|
|
3253
|
+
if (typeof raw.exitCode !== "number" || !Number.isInteger(raw.exitCode)) {
|
|
3254
|
+
throw new PlaybookParseError(
|
|
3255
|
+
`${field}.exitCode must be an integer`,
|
|
3256
|
+
`${field}.exitCode`,
|
|
3257
|
+
raw.exitCode
|
|
3258
|
+
);
|
|
3259
|
+
}
|
|
3260
|
+
exitCode = raw.exitCode;
|
|
3261
|
+
}
|
|
3262
|
+
const schema2 = typeof raw.schema === "string" ? raw.schema : void 0;
|
|
3263
|
+
return { outputFiles, exitCode, schema: schema2 };
|
|
3264
|
+
}
|
|
3265
|
+
function parseOnFailure(raw, field) {
|
|
3266
|
+
if (raw === void 0) return void 0;
|
|
3267
|
+
if (!isRecord(raw)) {
|
|
3268
|
+
throw new PlaybookParseError(`${field} must be an object`, field, raw);
|
|
3269
|
+
}
|
|
3270
|
+
const inject_into = typeof raw.inject_into === "string" ? raw.inject_into : void 0;
|
|
3271
|
+
let max_iterations;
|
|
3272
|
+
if (raw.max_iterations !== void 0) {
|
|
3273
|
+
if (typeof raw.max_iterations !== "number" || !Number.isInteger(raw.max_iterations)) {
|
|
3274
|
+
throw new PlaybookParseError(
|
|
3275
|
+
`${field}.max_iterations must be an integer`,
|
|
3276
|
+
`${field}.max_iterations`,
|
|
3277
|
+
raw.max_iterations
|
|
3278
|
+
);
|
|
3279
|
+
}
|
|
3280
|
+
max_iterations = raw.max_iterations;
|
|
3281
|
+
}
|
|
3282
|
+
let escalate;
|
|
3283
|
+
if (raw.escalate !== void 0) {
|
|
3284
|
+
if (typeof raw.escalate !== "boolean") {
|
|
3285
|
+
throw new PlaybookParseError(
|
|
3286
|
+
`${field}.escalate must be boolean`,
|
|
3287
|
+
`${field}.escalate`,
|
|
3288
|
+
raw.escalate
|
|
3289
|
+
);
|
|
3290
|
+
}
|
|
3291
|
+
escalate = raw.escalate;
|
|
3292
|
+
}
|
|
3293
|
+
return { inject_into, max_iterations, escalate };
|
|
3294
|
+
}
|
|
3295
|
+
function parseStringArray(raw, field) {
|
|
3296
|
+
if (raw === void 0) return void 0;
|
|
3297
|
+
if (!Array.isArray(raw)) {
|
|
3298
|
+
throw new PlaybookParseError(`${field} must be an array of strings`, field, raw);
|
|
3299
|
+
}
|
|
3300
|
+
return raw.map((v, i) => {
|
|
3301
|
+
if (typeof v !== "string") {
|
|
3302
|
+
throw new PlaybookParseError(`${field}[${i}] must be a string`, `${field}[${i}]`, v);
|
|
3303
|
+
}
|
|
3304
|
+
return v;
|
|
3305
|
+
});
|
|
3306
|
+
}
|
|
3307
|
+
function parseOptionalNonEmptyString(raw, field) {
|
|
3308
|
+
if (raw === void 0) return void 0;
|
|
3309
|
+
if (typeof raw !== "string" || raw.length === 0) {
|
|
3310
|
+
throw new PlaybookParseError(`${field} must be a non-empty string`, field, raw);
|
|
3311
|
+
}
|
|
3312
|
+
return raw;
|
|
3313
|
+
}
|
|
3314
|
+
function hasCycle(nodes, edges) {
|
|
3315
|
+
const adj = /* @__PURE__ */ new Map();
|
|
3316
|
+
for (const n of nodes) adj.set(n.id, /* @__PURE__ */ new Set());
|
|
3317
|
+
for (const e of edges) adj.get(e.from)?.add(e.to);
|
|
3318
|
+
for (const n of nodes) {
|
|
3319
|
+
if (!n.depends) continue;
|
|
3320
|
+
for (const dep of n.depends) adj.get(dep)?.add(n.id);
|
|
3321
|
+
}
|
|
3322
|
+
const WHITE = 0;
|
|
3323
|
+
const GRAY = 1;
|
|
3324
|
+
const BLACK = 2;
|
|
3325
|
+
const color = /* @__PURE__ */ new Map();
|
|
3326
|
+
for (const n of nodes) color.set(n.id, WHITE);
|
|
3327
|
+
function visit(id) {
|
|
3328
|
+
color.set(id, GRAY);
|
|
3329
|
+
for (const next of adj.get(id) ?? []) {
|
|
3330
|
+
const c = color.get(next) ?? WHITE;
|
|
3331
|
+
if (c === GRAY) return true;
|
|
3332
|
+
if (c === WHITE && visit(next)) return true;
|
|
3333
|
+
}
|
|
3334
|
+
color.set(id, BLACK);
|
|
3335
|
+
return false;
|
|
3336
|
+
}
|
|
3337
|
+
for (const n of nodes) {
|
|
3338
|
+
if (color.get(n.id) === WHITE && visit(n.id)) return true;
|
|
3339
|
+
}
|
|
3340
|
+
return false;
|
|
3341
|
+
}
|
|
3342
|
+
function isRecord(v) {
|
|
3343
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
3344
|
+
}
|
|
3345
|
+
function formatValue(v) {
|
|
3346
|
+
if (v === null) return "null";
|
|
3347
|
+
if (v === void 0) return "undefined";
|
|
3348
|
+
if (typeof v === "string") return JSON.stringify(v);
|
|
3349
|
+
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
3350
|
+
return typeof v;
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
// packages/playbooks/src/migrate-e4.ts
|
|
3354
|
+
function validatePlaybookCompliance(source) {
|
|
3355
|
+
let parsed;
|
|
3356
|
+
try {
|
|
3357
|
+
parsed = parsePlaybook(source);
|
|
3358
|
+
} catch (err) {
|
|
3359
|
+
return {
|
|
3360
|
+
parses: false,
|
|
3361
|
+
parseError: err instanceof PlaybookParseError ? err.message : String(err),
|
|
3362
|
+
hasErrorHandlers: false,
|
|
3363
|
+
nodesMissingRequires: 0,
|
|
3364
|
+
nodesMissingEnsures: 0,
|
|
3365
|
+
nodes: [],
|
|
3366
|
+
compliant: false
|
|
3367
|
+
};
|
|
3368
|
+
}
|
|
3369
|
+
const { definition } = parsed;
|
|
3370
|
+
const hasErrorHandlers = (definition.error_handlers?.length ?? 0) > 0;
|
|
3371
|
+
const nodeEntries = definition.nodes.map((n) => ({
|
|
3372
|
+
id: n.id,
|
|
3373
|
+
type: n.type,
|
|
3374
|
+
hasRequires: n.requires !== void 0,
|
|
3375
|
+
hasEnsures: n.ensures !== void 0
|
|
3376
|
+
}));
|
|
3377
|
+
const workNodes = nodeEntries.filter((e) => e.type !== "approval");
|
|
3378
|
+
const nodesMissingRequires = workNodes.filter((e) => !e.hasRequires).length;
|
|
3379
|
+
const nodesMissingEnsures = workNodes.filter((e) => !e.hasEnsures).length;
|
|
3380
|
+
const compliant = hasErrorHandlers && nodesMissingRequires === 0 && nodesMissingEnsures === 0;
|
|
3381
|
+
return {
|
|
3382
|
+
parses: true,
|
|
3383
|
+
hasErrorHandlers,
|
|
3384
|
+
nodesMissingRequires,
|
|
3385
|
+
nodesMissingEnsures,
|
|
3386
|
+
nodes: nodeEntries,
|
|
3387
|
+
compliant
|
|
3388
|
+
};
|
|
3389
|
+
}
|
|
3390
|
+
function migratePlaybook(source) {
|
|
3391
|
+
parsePlaybook(source);
|
|
3392
|
+
const raw = load(source);
|
|
3393
|
+
if (!Array.isArray(raw.error_handlers) || raw.error_handlers.length === 0) {
|
|
3394
|
+
raw.error_handlers = [
|
|
3395
|
+
{
|
|
3396
|
+
on: "iteration_cap_exceeded",
|
|
3397
|
+
action: "hitl_escalate",
|
|
3398
|
+
message: "Stage exhausted retries \u2014 escalate to human for direction."
|
|
3399
|
+
},
|
|
3400
|
+
{
|
|
3401
|
+
on: "contract_violation",
|
|
3402
|
+
action: "inject_hint",
|
|
3403
|
+
message: "Contract violated at stage boundary \u2014 check requires/ensures fields."
|
|
3404
|
+
}
|
|
3405
|
+
];
|
|
3406
|
+
}
|
|
3407
|
+
if (Array.isArray(raw.nodes)) {
|
|
3408
|
+
raw.nodes = raw.nodes.map((node) => {
|
|
3409
|
+
if (node.type === "approval") return node;
|
|
3410
|
+
const patched = { ...node };
|
|
3411
|
+
if (!patched.requires) patched.requires = {};
|
|
3412
|
+
if (!patched.ensures) patched.ensures = {};
|
|
3413
|
+
return patched;
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
return dump(raw, { lineWidth: 100, noRefs: true });
|
|
3417
|
+
}
|
|
3418
|
+
function migratePlaybookFile(filePath, dryRun = false) {
|
|
3419
|
+
const source = readFileSync(filePath, "utf8");
|
|
3420
|
+
const before = validatePlaybookCompliance(source);
|
|
3421
|
+
if (!before.parses) {
|
|
3422
|
+
return {
|
|
3423
|
+
filePath,
|
|
3424
|
+
before,
|
|
3425
|
+
after: before,
|
|
3426
|
+
written: false,
|
|
3427
|
+
migratedSource: source
|
|
3428
|
+
};
|
|
3429
|
+
}
|
|
3430
|
+
const migratedSource = migratePlaybook(source);
|
|
3431
|
+
const after = validatePlaybookCompliance(migratedSource);
|
|
3432
|
+
if (!dryRun && !before.compliant) {
|
|
3433
|
+
writeFileSync(filePath, migratedSource, "utf8");
|
|
3434
|
+
}
|
|
3435
|
+
return {
|
|
3436
|
+
filePath,
|
|
3437
|
+
before,
|
|
3438
|
+
after,
|
|
3439
|
+
written: !dryRun && !before.compliant,
|
|
3440
|
+
migratedSource
|
|
3441
|
+
};
|
|
3442
|
+
}
|
|
3443
|
+
|
|
3444
|
+
// packages/playbooks/src/policy.ts
|
|
3445
|
+
var DEFAULT_POLICY_RULES = Object.freeze([
|
|
3446
|
+
{ pattern: /\bnpm\s+publish\b/, action: "require-human", reason: "publish" },
|
|
3447
|
+
{ pattern: /\bpnpm\s+publish\b/, action: "require-human", reason: "publish" },
|
|
3448
|
+
{ pattern: /\byarn\s+publish\b/, action: "require-human", reason: "publish" },
|
|
3449
|
+
{ pattern: /\bgit\s+push\b/, action: "require-human", reason: "push" },
|
|
3450
|
+
{ pattern: /\bgit\s+tag\b/, action: "require-human", reason: "tag" },
|
|
3451
|
+
{ pattern: /\bgh\s+release\s+create\b/, action: "require-human", reason: "release" },
|
|
3452
|
+
{ pattern: /\bgh\s+workflow\s+run\b/, action: "require-human", reason: "workflow-trigger" },
|
|
3453
|
+
{
|
|
3454
|
+
pattern: /\b(rm\s+-rf|drop\s+table|truncate|delete\s+from)\b/i,
|
|
3455
|
+
action: "require-human",
|
|
3456
|
+
reason: "destructive"
|
|
3457
|
+
},
|
|
3458
|
+
{
|
|
3459
|
+
pattern: /\b(curl|wget|fetch)\b.*\bhttps?:/i,
|
|
3460
|
+
action: "require-human",
|
|
3461
|
+
reason: "external-api"
|
|
3462
|
+
},
|
|
3463
|
+
{ pattern: /\b(ssh|scp|rsync)\b.+@/, action: "require-human", reason: "remote-access" },
|
|
3464
|
+
{
|
|
3465
|
+
pattern: /^pnpm\s+(test|run\s+test|biome|tsc)\b/,
|
|
3466
|
+
action: "auto-approve",
|
|
3467
|
+
reason: "safe-qa-tool"
|
|
3468
|
+
},
|
|
3469
|
+
{
|
|
3470
|
+
pattern: /^cleo\s+(verify|check|show|find|list|status|current|next)\b/,
|
|
3471
|
+
action: "auto-approve",
|
|
3472
|
+
reason: "safe-cleo-read"
|
|
3473
|
+
}
|
|
3474
|
+
]);
|
|
3475
|
+
function evaluatePolicy(command, rules = DEFAULT_POLICY_RULES) {
|
|
3476
|
+
for (const rule of rules) {
|
|
3477
|
+
if (rule.action === "require-human" && rule.pattern.test(command)) {
|
|
3478
|
+
return {
|
|
3479
|
+
action: "require-human",
|
|
3480
|
+
reason: rule.reason,
|
|
3481
|
+
matchedPattern: rule.pattern.source
|
|
3482
|
+
};
|
|
3483
|
+
}
|
|
3484
|
+
}
|
|
3485
|
+
for (const rule of rules) {
|
|
3486
|
+
if (rule.action === "auto-approve" && rule.pattern.test(command)) {
|
|
3487
|
+
return {
|
|
3488
|
+
action: "auto-approve",
|
|
3489
|
+
reason: rule.reason,
|
|
3490
|
+
matchedPattern: rule.pattern.source
|
|
3491
|
+
};
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
return { action: "require-human", reason: "default" };
|
|
3495
|
+
}
|
|
3496
|
+
|
|
3497
|
+
// packages/playbooks/src/runtime.ts
|
|
3498
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
3499
|
+
import { dirname, join } from "node:path";
|
|
3500
|
+
import { defaultVariableResolver, getEnsuresSchema, listEnsuresSchemaNames } from "@cleocode/core";
|
|
3501
|
+
|
|
3502
|
+
// packages/playbooks/src/state.ts
|
|
3503
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3504
|
+
function parseJsonColumn(raw, column, runId) {
|
|
3505
|
+
try {
|
|
3506
|
+
return JSON.parse(raw);
|
|
3507
|
+
} catch (err) {
|
|
3508
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
3509
|
+
throw new Error(
|
|
3510
|
+
`playbook state: failed to parse JSON column "${column}" for run ${runId}: ${message}`
|
|
3511
|
+
);
|
|
3512
|
+
}
|
|
3513
|
+
}
|
|
3514
|
+
function rowToPlaybookRun(row) {
|
|
3515
|
+
const bindings = parseJsonColumn(row.bindings, "bindings", row.run_id);
|
|
3516
|
+
const iterationCounts = parseJsonColumn(
|
|
3517
|
+
row.iteration_counts,
|
|
3518
|
+
"iteration_counts",
|
|
3519
|
+
row.run_id
|
|
3520
|
+
);
|
|
3521
|
+
return {
|
|
3522
|
+
runId: row.run_id,
|
|
3523
|
+
playbookName: row.playbook_name,
|
|
3524
|
+
playbookHash: row.playbook_hash,
|
|
3525
|
+
currentNode: row.current_node,
|
|
3526
|
+
bindings,
|
|
3527
|
+
errorContext: row.error_context,
|
|
3528
|
+
status: row.status,
|
|
3529
|
+
iterationCounts,
|
|
3530
|
+
epicId: row.epic_id ?? void 0,
|
|
3531
|
+
sessionId: row.session_id ?? void 0,
|
|
3532
|
+
startedAt: row.started_at,
|
|
3533
|
+
completedAt: row.completed_at ?? void 0
|
|
3534
|
+
};
|
|
3535
|
+
}
|
|
3536
|
+
function rowToPlaybookApproval(row) {
|
|
3537
|
+
return {
|
|
3538
|
+
approvalId: row.approval_id,
|
|
3539
|
+
runId: row.run_id,
|
|
3540
|
+
nodeId: row.node_id,
|
|
3541
|
+
token: row.token,
|
|
3542
|
+
requestedAt: row.requested_at,
|
|
3543
|
+
approvedAt: row.approved_at ?? void 0,
|
|
3544
|
+
approver: row.approver ?? void 0,
|
|
3545
|
+
reason: row.reason ?? void 0,
|
|
3546
|
+
status: row.status,
|
|
3547
|
+
autoPassed: row.auto_passed === 1
|
|
3548
|
+
};
|
|
3549
|
+
}
|
|
3550
|
+
function createPlaybookRun(db, input) {
|
|
3551
|
+
const runId = randomUUID2();
|
|
3552
|
+
const bindingsJson = JSON.stringify(input.initialBindings ?? {});
|
|
3553
|
+
const insert = db.prepare(
|
|
3554
|
+
`INSERT INTO playbook_runs (
|
|
3555
|
+
run_id, playbook_name, playbook_hash, bindings, status,
|
|
3556
|
+
iteration_counts, epic_id, session_id
|
|
3557
|
+
) VALUES (?, ?, ?, ?, 'running', '{}', ?, ?)`
|
|
3558
|
+
);
|
|
3559
|
+
insert.run(
|
|
3560
|
+
runId,
|
|
3561
|
+
input.playbookName,
|
|
3562
|
+
input.playbookHash,
|
|
3563
|
+
bindingsJson,
|
|
3564
|
+
input.epicId ?? null,
|
|
3565
|
+
input.sessionId ?? null
|
|
3566
|
+
);
|
|
3567
|
+
const row = db.prepare("SELECT * FROM playbook_runs WHERE run_id = ?").get(runId);
|
|
3568
|
+
if (!row) {
|
|
3569
|
+
throw new Error(`playbook state: failed to read back run ${runId} after insert`);
|
|
3570
|
+
}
|
|
3571
|
+
return rowToPlaybookRun(row);
|
|
3572
|
+
}
|
|
3573
|
+
function getPlaybookRun(db, runId) {
|
|
3574
|
+
const row = db.prepare("SELECT * FROM playbook_runs WHERE run_id = ?").get(runId);
|
|
3575
|
+
return row ? rowToPlaybookRun(row) : null;
|
|
3576
|
+
}
|
|
3577
|
+
function updatePlaybookRun(db, runId, patch) {
|
|
3578
|
+
const sets = [];
|
|
3579
|
+
const values = [];
|
|
3580
|
+
if ("playbookName" in patch && patch.playbookName !== void 0) {
|
|
3581
|
+
sets.push("playbook_name = ?");
|
|
3582
|
+
values.push(patch.playbookName);
|
|
3583
|
+
}
|
|
3584
|
+
if ("playbookHash" in patch && patch.playbookHash !== void 0) {
|
|
3585
|
+
sets.push("playbook_hash = ?");
|
|
3586
|
+
values.push(patch.playbookHash);
|
|
3587
|
+
}
|
|
3588
|
+
if ("currentNode" in patch) {
|
|
3589
|
+
sets.push("current_node = ?");
|
|
3590
|
+
values.push(patch.currentNode ?? null);
|
|
3591
|
+
}
|
|
3592
|
+
if ("bindings" in patch && patch.bindings !== void 0) {
|
|
3593
|
+
sets.push("bindings = ?");
|
|
3594
|
+
values.push(JSON.stringify(patch.bindings));
|
|
3595
|
+
}
|
|
3596
|
+
if ("errorContext" in patch) {
|
|
3597
|
+
sets.push("error_context = ?");
|
|
3598
|
+
values.push(patch.errorContext ?? null);
|
|
3599
|
+
}
|
|
3600
|
+
if ("status" in patch && patch.status !== void 0) {
|
|
3601
|
+
sets.push("status = ?");
|
|
3602
|
+
values.push(patch.status);
|
|
3603
|
+
}
|
|
3604
|
+
if ("iterationCounts" in patch && patch.iterationCounts !== void 0) {
|
|
3605
|
+
sets.push("iteration_counts = ?");
|
|
3606
|
+
values.push(JSON.stringify(patch.iterationCounts));
|
|
3607
|
+
}
|
|
3608
|
+
if ("epicId" in patch) {
|
|
3609
|
+
sets.push("epic_id = ?");
|
|
3610
|
+
values.push(patch.epicId ?? null);
|
|
3611
|
+
}
|
|
3612
|
+
if ("sessionId" in patch) {
|
|
3613
|
+
sets.push("session_id = ?");
|
|
3614
|
+
values.push(patch.sessionId ?? null);
|
|
3615
|
+
}
|
|
3616
|
+
if ("completedAt" in patch) {
|
|
3617
|
+
sets.push("completed_at = ?");
|
|
3618
|
+
values.push(patch.completedAt ?? null);
|
|
3619
|
+
}
|
|
3620
|
+
if (sets.length === 0) {
|
|
3621
|
+
const existing = getPlaybookRun(db, runId);
|
|
3622
|
+
if (!existing) {
|
|
3623
|
+
throw new Error(`playbook state: run ${runId} not found for update`);
|
|
3624
|
+
}
|
|
3625
|
+
return existing;
|
|
3626
|
+
}
|
|
3627
|
+
db.exec("BEGIN");
|
|
3628
|
+
try {
|
|
3629
|
+
const stmt = db.prepare(`UPDATE playbook_runs SET ${sets.join(", ")} WHERE run_id = ?`);
|
|
3630
|
+
values.push(runId);
|
|
3631
|
+
const result = stmt.run(...values);
|
|
3632
|
+
if (result.changes === 0) {
|
|
3633
|
+
throw new Error(`playbook state: run ${runId} not found for update`);
|
|
3634
|
+
}
|
|
3635
|
+
db.exec("COMMIT");
|
|
3636
|
+
} catch (err) {
|
|
3637
|
+
db.exec("ROLLBACK");
|
|
3638
|
+
throw err;
|
|
3639
|
+
}
|
|
3640
|
+
const row = db.prepare("SELECT * FROM playbook_runs WHERE run_id = ?").get(runId);
|
|
3641
|
+
if (!row) {
|
|
3642
|
+
throw new Error(`playbook state: run ${runId} disappeared after update`);
|
|
3643
|
+
}
|
|
3644
|
+
return rowToPlaybookRun(row);
|
|
3645
|
+
}
|
|
3646
|
+
function listPlaybookRuns(db, opts = {}) {
|
|
3647
|
+
const clauses = [];
|
|
3648
|
+
const values = [];
|
|
3649
|
+
if (opts.status) {
|
|
3650
|
+
clauses.push("status = ?");
|
|
3651
|
+
values.push(opts.status);
|
|
3652
|
+
}
|
|
3653
|
+
if (opts.epicId) {
|
|
3654
|
+
clauses.push("epic_id = ?");
|
|
3655
|
+
values.push(opts.epicId);
|
|
3656
|
+
}
|
|
3657
|
+
const where = clauses.length > 0 ? `WHERE ${clauses.join(" AND ")}` : "";
|
|
3658
|
+
const limitClause = typeof opts.limit === "number" ? "LIMIT ?" : "";
|
|
3659
|
+
if (limitClause) values.push(opts.limit ?? 0);
|
|
3660
|
+
const sql = `SELECT * FROM playbook_runs ${where} ORDER BY started_at DESC ${limitClause}`;
|
|
3661
|
+
const rows = db.prepare(sql).all(...values);
|
|
3662
|
+
return rows.map(rowToPlaybookRun);
|
|
3663
|
+
}
|
|
3664
|
+
function deletePlaybookRun(db, runId) {
|
|
3665
|
+
const result = db.prepare("DELETE FROM playbook_runs WHERE run_id = ?").run(runId);
|
|
3666
|
+
return Number(result.changes) > 0;
|
|
3667
|
+
}
|
|
3668
|
+
function createPlaybookApproval(db, input) {
|
|
3669
|
+
const approvalId = randomUUID2();
|
|
3670
|
+
const autoPassed = input.autoPassed ? 1 : 0;
|
|
3671
|
+
db.prepare(
|
|
3672
|
+
`INSERT INTO playbook_approvals (
|
|
3673
|
+
approval_id, run_id, node_id, token, status, auto_passed
|
|
3674
|
+
) VALUES (?, ?, ?, ?, 'pending', ?)`
|
|
3675
|
+
).run(approvalId, input.runId, input.nodeId, input.token, autoPassed);
|
|
3676
|
+
const row = db.prepare("SELECT * FROM playbook_approvals WHERE approval_id = ?").get(approvalId);
|
|
3677
|
+
if (!row) {
|
|
3678
|
+
throw new Error(`playbook state: failed to read back approval ${approvalId} after insert`);
|
|
3679
|
+
}
|
|
3680
|
+
return rowToPlaybookApproval(row);
|
|
3681
|
+
}
|
|
3682
|
+
function getPlaybookApprovalByToken(db, token) {
|
|
3683
|
+
const row = db.prepare("SELECT * FROM playbook_approvals WHERE token = ?").get(token);
|
|
3684
|
+
return row ? rowToPlaybookApproval(row) : null;
|
|
3685
|
+
}
|
|
3686
|
+
function updatePlaybookApproval(db, approvalId, patch) {
|
|
3687
|
+
const sets = [];
|
|
3688
|
+
const values = [];
|
|
3689
|
+
if ("runId" in patch && patch.runId !== void 0) {
|
|
3690
|
+
sets.push("run_id = ?");
|
|
3691
|
+
values.push(patch.runId);
|
|
3692
|
+
}
|
|
3693
|
+
if ("nodeId" in patch && patch.nodeId !== void 0) {
|
|
3694
|
+
sets.push("node_id = ?");
|
|
3695
|
+
values.push(patch.nodeId);
|
|
3696
|
+
}
|
|
3697
|
+
if ("token" in patch && patch.token !== void 0) {
|
|
3698
|
+
sets.push("token = ?");
|
|
3699
|
+
values.push(patch.token);
|
|
3700
|
+
}
|
|
3701
|
+
if ("approvedAt" in patch) {
|
|
3702
|
+
sets.push("approved_at = ?");
|
|
3703
|
+
values.push(patch.approvedAt ?? null);
|
|
3704
|
+
}
|
|
3705
|
+
if ("approver" in patch) {
|
|
3706
|
+
sets.push("approver = ?");
|
|
3707
|
+
values.push(patch.approver ?? null);
|
|
3708
|
+
}
|
|
3709
|
+
if ("reason" in patch) {
|
|
3710
|
+
sets.push("reason = ?");
|
|
3711
|
+
values.push(patch.reason ?? null);
|
|
3712
|
+
}
|
|
3713
|
+
if ("status" in patch && patch.status !== void 0) {
|
|
3714
|
+
sets.push("status = ?");
|
|
3715
|
+
values.push(patch.status);
|
|
3716
|
+
}
|
|
3717
|
+
if ("autoPassed" in patch && patch.autoPassed !== void 0) {
|
|
3718
|
+
sets.push("auto_passed = ?");
|
|
3719
|
+
values.push(patch.autoPassed ? 1 : 0);
|
|
3720
|
+
}
|
|
3721
|
+
if (sets.length === 0) {
|
|
3722
|
+
const row2 = db.prepare("SELECT * FROM playbook_approvals WHERE approval_id = ?").get(approvalId);
|
|
3723
|
+
if (!row2) {
|
|
3724
|
+
throw new Error(`playbook state: approval ${approvalId} not found for update`);
|
|
3725
|
+
}
|
|
3726
|
+
return rowToPlaybookApproval(row2);
|
|
3727
|
+
}
|
|
3728
|
+
db.exec("BEGIN");
|
|
3729
|
+
try {
|
|
3730
|
+
const stmt = db.prepare(
|
|
3731
|
+
`UPDATE playbook_approvals SET ${sets.join(", ")} WHERE approval_id = ?`
|
|
3732
|
+
);
|
|
3733
|
+
values.push(approvalId);
|
|
3734
|
+
const result = stmt.run(...values);
|
|
3735
|
+
if (result.changes === 0) {
|
|
3736
|
+
throw new Error(`playbook state: approval ${approvalId} not found for update`);
|
|
3737
|
+
}
|
|
3738
|
+
db.exec("COMMIT");
|
|
3739
|
+
} catch (err) {
|
|
3740
|
+
db.exec("ROLLBACK");
|
|
3741
|
+
throw err;
|
|
3742
|
+
}
|
|
3743
|
+
const row = db.prepare("SELECT * FROM playbook_approvals WHERE approval_id = ?").get(approvalId);
|
|
3744
|
+
if (!row) {
|
|
3745
|
+
throw new Error(`playbook state: approval ${approvalId} disappeared after update`);
|
|
3746
|
+
}
|
|
3747
|
+
return rowToPlaybookApproval(row);
|
|
3748
|
+
}
|
|
3749
|
+
function listPlaybookApprovals(db, runId) {
|
|
3750
|
+
const rows = db.prepare(
|
|
3751
|
+
"SELECT * FROM playbook_approvals WHERE run_id = ? ORDER BY requested_at ASC, approval_id ASC"
|
|
3752
|
+
).all(runId);
|
|
3753
|
+
return rows.map(rowToPlaybookApproval);
|
|
3754
|
+
}
|
|
3755
|
+
|
|
3756
|
+
// packages/playbooks/src/runtime.ts
|
|
3757
|
+
var E_PLAYBOOK_RUNTIME_INVALID = "E_PLAYBOOK_RUNTIME_INVALID";
|
|
3758
|
+
var E_PLAYBOOK_RESUME_BLOCKED = "E_PLAYBOOK_RESUME_BLOCKED";
|
|
3759
|
+
function buildEdgeIndex(def) {
|
|
3760
|
+
const outgoing = /* @__PURE__ */ new Map();
|
|
3761
|
+
const incoming = /* @__PURE__ */ new Map();
|
|
3762
|
+
const outgoingEdges = /* @__PURE__ */ new Map();
|
|
3763
|
+
for (const n of def.nodes) {
|
|
3764
|
+
outgoing.set(n.id, []);
|
|
3765
|
+
incoming.set(n.id, []);
|
|
3766
|
+
outgoingEdges.set(n.id, []);
|
|
3767
|
+
}
|
|
3768
|
+
for (const e of def.edges) {
|
|
3769
|
+
outgoing.get(e.from)?.push(e.to);
|
|
3770
|
+
incoming.get(e.to)?.push(e.from);
|
|
3771
|
+
outgoingEdges.get(e.from)?.push(e);
|
|
3772
|
+
}
|
|
3773
|
+
for (const n of def.nodes) {
|
|
3774
|
+
if (!n.depends) continue;
|
|
3775
|
+
for (const dep of n.depends) {
|
|
3776
|
+
const out = outgoing.get(dep);
|
|
3777
|
+
if (out && !out.includes(n.id)) out.push(n.id);
|
|
3778
|
+
const inc = incoming.get(n.id);
|
|
3779
|
+
if (inc && !inc.includes(dep)) inc.push(dep);
|
|
3780
|
+
const outE = outgoingEdges.get(dep);
|
|
3781
|
+
if (outE && !outE.some((e) => e.to === n.id)) outE.push({ from: dep, to: n.id });
|
|
3782
|
+
}
|
|
3783
|
+
}
|
|
3784
|
+
return {
|
|
3785
|
+
outgoing: new Map([...outgoing].map(([k, v]) => [k, Object.freeze([...v])])),
|
|
3786
|
+
incoming: new Map([...incoming].map(([k, v]) => [k, Object.freeze([...v])])),
|
|
3787
|
+
outgoingEdges: new Map([...outgoingEdges].map(([k, v]) => [k, Object.freeze([...v])]))
|
|
3788
|
+
};
|
|
3789
|
+
}
|
|
3790
|
+
function resolveEntryNode(def, idx) {
|
|
3791
|
+
for (const n of def.nodes) {
|
|
3792
|
+
const preds = idx.incoming.get(n.id);
|
|
3793
|
+
if (preds && preds.length === 0) return n;
|
|
3794
|
+
}
|
|
3795
|
+
throw new Error(
|
|
3796
|
+
`${E_PLAYBOOK_RUNTIME_INVALID}: no entry node (every node has a predecessor) in ${def.name}`
|
|
3797
|
+
);
|
|
3798
|
+
}
|
|
3799
|
+
function evaluateEdgeCondition(condition, context) {
|
|
3800
|
+
const has = Object.hasOwn(context, condition.field);
|
|
3801
|
+
const value = context[condition.field];
|
|
3802
|
+
if (condition.exists !== void 0) {
|
|
3803
|
+
return condition.exists ? has : !has;
|
|
3804
|
+
}
|
|
3805
|
+
if (condition.truthy !== void 0) {
|
|
3806
|
+
return condition.truthy ? Boolean(value) : !value;
|
|
3807
|
+
}
|
|
3808
|
+
if (Object.hasOwn(condition, "equals")) {
|
|
3809
|
+
return has && Object.is(value, condition.equals);
|
|
3810
|
+
}
|
|
3811
|
+
if (Object.hasOwn(condition, "notEquals")) {
|
|
3812
|
+
return !has || !Object.is(value, condition.notEquals);
|
|
3813
|
+
}
|
|
3814
|
+
if (condition.in !== void 0) {
|
|
3815
|
+
return has && condition.in.some((candidate) => Object.is(value, candidate));
|
|
3816
|
+
}
|
|
3817
|
+
return false;
|
|
3818
|
+
}
|
|
3819
|
+
function resolveNextNodeId(nodeId, idx, context) {
|
|
3820
|
+
const edges = idx.outgoingEdges.get(nodeId) ?? [];
|
|
3821
|
+
if (edges.length === 0) return null;
|
|
3822
|
+
if (edges.length === 1) {
|
|
3823
|
+
const [only] = edges;
|
|
3824
|
+
if (only === void 0) {
|
|
3825
|
+
throw new Error(`${E_PLAYBOOK_RUNTIME_INVALID}: node ${nodeId} has undefined successor`);
|
|
3826
|
+
}
|
|
3827
|
+
if (only.when !== void 0 && !evaluateEdgeCondition(only.when, context)) {
|
|
3828
|
+
throw new Error(
|
|
3829
|
+
`${E_PLAYBOOK_RUNTIME_INVALID}: node ${nodeId} sole successor "${only.to}" is guarded by a "when" predicate that is not satisfied \u2014 branch has no reachable default`
|
|
3830
|
+
);
|
|
3831
|
+
}
|
|
3832
|
+
return only.to;
|
|
3833
|
+
}
|
|
3834
|
+
const unconditional = edges.filter((e) => e.when === void 0);
|
|
3835
|
+
if (unconditional.length > 1) {
|
|
3836
|
+
throw new Error(
|
|
3837
|
+
`${E_PLAYBOOK_RUNTIME_INVALID}: node ${nodeId} has ${unconditional.length} unconditional successors; guarded branching requires every additional edge to carry a "when" predicate`
|
|
3838
|
+
);
|
|
3839
|
+
}
|
|
3840
|
+
const satisfied = [];
|
|
3841
|
+
for (const e of edges) {
|
|
3842
|
+
if (e.when === void 0 || evaluateEdgeCondition(e.when, context)) {
|
|
3843
|
+
satisfied.push(e.to);
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
if (satisfied.length === 0) {
|
|
3847
|
+
throw new Error(
|
|
3848
|
+
`${E_PLAYBOOK_RUNTIME_INVALID}: node ${nodeId} has ${edges.length} successors but no "when" predicate is satisfied \u2014 branch has no reachable default`
|
|
3849
|
+
);
|
|
3850
|
+
}
|
|
3851
|
+
if (satisfied.length > 1) {
|
|
3852
|
+
throw new Error(
|
|
3853
|
+
`${E_PLAYBOOK_RUNTIME_INVALID}: node ${nodeId} has ${satisfied.length} satisfied successors (${satisfied.join(", ")}); branch predicates must be mutually exclusive`
|
|
3854
|
+
);
|
|
3855
|
+
}
|
|
3856
|
+
const [next] = satisfied;
|
|
3857
|
+
if (next === void 0) {
|
|
3858
|
+
throw new Error(`${E_PLAYBOOK_RUNTIME_INVALID}: node ${nodeId} has undefined successor`);
|
|
3859
|
+
}
|
|
3860
|
+
return next;
|
|
3861
|
+
}
|
|
3862
|
+
function resolveNode(nodeId, idx) {
|
|
3863
|
+
const node = idx.get(nodeId);
|
|
3864
|
+
if (node === void 0) {
|
|
3865
|
+
throw new Error(`${E_PLAYBOOK_RUNTIME_INVALID}: unknown node id "${nodeId}"`);
|
|
3866
|
+
}
|
|
3867
|
+
return node;
|
|
3868
|
+
}
|
|
3869
|
+
function resolveStepBindings(node, context) {
|
|
3870
|
+
if (node.inputs === void 0 || Object.keys(node.inputs).length === 0) {
|
|
3871
|
+
return { ...context };
|
|
3872
|
+
}
|
|
3873
|
+
const substitutionContext = {
|
|
3874
|
+
projectContext: context,
|
|
3875
|
+
env: process.env
|
|
3876
|
+
};
|
|
3877
|
+
const resolvedInputs = {};
|
|
3878
|
+
for (const [key, template] of Object.entries(node.inputs)) {
|
|
3879
|
+
const result = defaultVariableResolver.resolve(template, substitutionContext, {
|
|
3880
|
+
strict: false
|
|
3881
|
+
});
|
|
3882
|
+
resolvedInputs[key] = result.text;
|
|
3883
|
+
}
|
|
3884
|
+
return { ...context, ...resolvedInputs };
|
|
3885
|
+
}
|
|
3886
|
+
async function executeAgenticNode(node, runId, context, iteration, dispatcher, playbookName) {
|
|
3887
|
+
const agentId = node.agent ?? node.skill;
|
|
3888
|
+
if (agentId === void 0) {
|
|
3889
|
+
return {
|
|
3890
|
+
kind: "failure",
|
|
3891
|
+
error: `${E_PLAYBOOK_RUNTIME_INVALID}: node ${node.id} is agentic but has no skill or agent`
|
|
3892
|
+
};
|
|
3893
|
+
}
|
|
3894
|
+
const taskIdRaw = context["taskId"];
|
|
3895
|
+
const taskId = typeof taskIdRaw === "string" && taskIdRaw.length > 0 ? taskIdRaw : runId;
|
|
3896
|
+
const bindings = resolveStepBindings(node, context);
|
|
3897
|
+
try {
|
|
3898
|
+
const result = await dispatcher.dispatch({
|
|
3899
|
+
runId,
|
|
3900
|
+
nodeId: node.id,
|
|
3901
|
+
agentId,
|
|
3902
|
+
taskId,
|
|
3903
|
+
context: { ...context },
|
|
3904
|
+
bindings,
|
|
3905
|
+
iteration,
|
|
3906
|
+
// T11759 (M4): forward the playbook name + the node's per-stage LLM pin so
|
|
3907
|
+
// the dispatcher can resolve a declared `profile:` through the E9
|
|
3908
|
+
// chokepoint. All-additive; omitted when the node declares no pin.
|
|
3909
|
+
playbookName,
|
|
3910
|
+
...node.profile !== void 0 ? { profile: node.profile } : {},
|
|
3911
|
+
...node.model !== void 0 ? { model: node.model } : {},
|
|
3912
|
+
...node.provider !== void 0 ? { provider: node.provider } : {},
|
|
3913
|
+
// T1947 (M4): forward the per-step skill/tool allowlists so the dispatcher
|
|
3914
|
+
// can intersect them against the Tier-0/1/2 baseline at spawn time. Omitted
|
|
3915
|
+
// when the node declares no allowlist (additive — baseline unchanged).
|
|
3916
|
+
...node.allowed_skills !== void 0 ? { allowedSkills: node.allowed_skills } : {},
|
|
3917
|
+
...node.allowed_tools !== void 0 ? { allowedTools: node.allowed_tools } : {}
|
|
3918
|
+
});
|
|
3919
|
+
if (result.status === "success") {
|
|
3920
|
+
return { kind: "success", output: result.output };
|
|
3921
|
+
}
|
|
3922
|
+
return { kind: "failure", error: result.error ?? `agent ${agentId} returned failure` };
|
|
3923
|
+
} catch (err) {
|
|
3924
|
+
return {
|
|
3925
|
+
kind: "failure",
|
|
3926
|
+
error: err instanceof Error ? err.message : String(err)
|
|
3927
|
+
};
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
async function executeDeterministicNode(node, runId, context, iteration, dispatcher, runner) {
|
|
3931
|
+
try {
|
|
3932
|
+
if (runner !== void 0) {
|
|
3933
|
+
const input = {
|
|
3934
|
+
runId,
|
|
3935
|
+
nodeId: node.id,
|
|
3936
|
+
command: node.command,
|
|
3937
|
+
args: node.args,
|
|
3938
|
+
context: { ...context },
|
|
3939
|
+
iteration
|
|
3940
|
+
};
|
|
3941
|
+
if (node.cwd !== void 0) input.cwd = node.cwd;
|
|
3942
|
+
if (node.env !== void 0) input.env = node.env;
|
|
3943
|
+
if (node.timeout_ms !== void 0) input.timeout_ms = node.timeout_ms;
|
|
3944
|
+
const result2 = await runner.run(input);
|
|
3945
|
+
if (result2.status === "success") {
|
|
3946
|
+
return { kind: "success", output: result2.output };
|
|
3947
|
+
}
|
|
3948
|
+
return {
|
|
3949
|
+
kind: "failure",
|
|
3950
|
+
error: result2.error ?? `command ${node.command} returned failure`
|
|
3951
|
+
};
|
|
3952
|
+
}
|
|
3953
|
+
const taskIdRaw = context["taskId"];
|
|
3954
|
+
const taskId = typeof taskIdRaw === "string" && taskIdRaw.length > 0 ? taskIdRaw : runId;
|
|
3955
|
+
const agentId = `deterministic:${node.command}`;
|
|
3956
|
+
const result = await dispatcher.dispatch({
|
|
3957
|
+
runId,
|
|
3958
|
+
nodeId: node.id,
|
|
3959
|
+
agentId,
|
|
3960
|
+
taskId,
|
|
3961
|
+
context: {
|
|
3962
|
+
...context,
|
|
3963
|
+
__deterministic: {
|
|
3964
|
+
command: node.command,
|
|
3965
|
+
args: [...node.args],
|
|
3966
|
+
cwd: node.cwd,
|
|
3967
|
+
env: node.env,
|
|
3968
|
+
timeout_ms: node.timeout_ms
|
|
3969
|
+
}
|
|
3970
|
+
},
|
|
3971
|
+
iteration
|
|
3972
|
+
});
|
|
3973
|
+
if (result.status === "success") {
|
|
3974
|
+
return { kind: "success", output: result.output };
|
|
3975
|
+
}
|
|
3976
|
+
return {
|
|
3977
|
+
kind: "failure",
|
|
3978
|
+
error: result.error ?? `command ${node.command} returned failure`
|
|
3979
|
+
};
|
|
3980
|
+
} catch (err) {
|
|
3981
|
+
return {
|
|
3982
|
+
kind: "failure",
|
|
3983
|
+
error: err instanceof Error ? err.message : String(err)
|
|
3984
|
+
};
|
|
3985
|
+
}
|
|
3986
|
+
}
|
|
3987
|
+
function executeApprovalNode(node, runId, context, db, secret) {
|
|
3988
|
+
const gate = createApprovalGate(db, {
|
|
3989
|
+
runId,
|
|
3990
|
+
nodeId: node.id,
|
|
3991
|
+
bindings: context,
|
|
3992
|
+
secret,
|
|
3993
|
+
reason: node.prompt
|
|
3994
|
+
});
|
|
3995
|
+
return { kind: "awaiting_approval", token: gate.token, approvalId: gate.approvalId };
|
|
3996
|
+
}
|
|
3997
|
+
function checkRequires(fields, from, context) {
|
|
3998
|
+
for (const key of fields) {
|
|
3999
|
+
if (!(key in context)) {
|
|
4000
|
+
const source = from !== void 0 ? ` (from node '${from}')` : "";
|
|
4001
|
+
return `requires.fields['${key}']${source} not present in context`;
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
return null;
|
|
4005
|
+
}
|
|
4006
|
+
function resolveEdge(fromId, toId, edges) {
|
|
4007
|
+
return edges.find((e) => e.from === fromId && e.to === toId);
|
|
4008
|
+
}
|
|
4009
|
+
function auditContractViolation(projectRoot, runId, nodeId, field, key, playbookName) {
|
|
4010
|
+
if (!projectRoot) return;
|
|
4011
|
+
try {
|
|
4012
|
+
const filePath = join(projectRoot, ".cleo", "audit", "contract-violations.jsonl");
|
|
4013
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
4014
|
+
const entry = JSON.stringify({
|
|
4015
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4016
|
+
runId,
|
|
4017
|
+
nodeId,
|
|
4018
|
+
field,
|
|
4019
|
+
key,
|
|
4020
|
+
message: `contract_violation: ${field}['${key}'] check failed on node '${nodeId}'`,
|
|
4021
|
+
playbookName
|
|
4022
|
+
});
|
|
4023
|
+
appendFileSync(filePath, `${entry}
|
|
4024
|
+
`, { encoding: "utf-8" });
|
|
4025
|
+
} catch {
|
|
4026
|
+
}
|
|
4027
|
+
}
|
|
4028
|
+
function handleContractErrorHandler(playbook, trigger, _message) {
|
|
4029
|
+
if (!playbook.error_handlers) return null;
|
|
4030
|
+
const handler = playbook.error_handlers.find((h) => h.on === trigger);
|
|
4031
|
+
return handler?.action ?? null;
|
|
4032
|
+
}
|
|
4033
|
+
function iterationCapFor(node, runtimeDefault) {
|
|
4034
|
+
const cap = node.on_failure?.max_iterations;
|
|
4035
|
+
if (typeof cap === "number" && Number.isFinite(cap) && cap >= 0) return cap;
|
|
4036
|
+
return runtimeDefault;
|
|
4037
|
+
}
|
|
4038
|
+
async function runFromNode(args) {
|
|
4039
|
+
const {
|
|
4040
|
+
db,
|
|
4041
|
+
playbook,
|
|
4042
|
+
run,
|
|
4043
|
+
startNodeId,
|
|
4044
|
+
nodeIndex,
|
|
4045
|
+
edgeIndex,
|
|
4046
|
+
context,
|
|
4047
|
+
iterationCounts,
|
|
4048
|
+
dispatcher,
|
|
4049
|
+
deterministicRunner,
|
|
4050
|
+
approvalSecret,
|
|
4051
|
+
maxIterationsDefault,
|
|
4052
|
+
now
|
|
4053
|
+
} = args;
|
|
4054
|
+
let currentId = startNodeId;
|
|
4055
|
+
let lastError;
|
|
4056
|
+
let failedNodeId;
|
|
4057
|
+
let exceededNodeId;
|
|
4058
|
+
while (currentId !== null) {
|
|
4059
|
+
const node = resolveNode(currentId, nodeIndex);
|
|
4060
|
+
const cap = iterationCapFor(node, maxIterationsDefault);
|
|
4061
|
+
const attempt = (iterationCounts[node.id] ?? 0) + 1;
|
|
4062
|
+
iterationCounts[node.id] = attempt;
|
|
4063
|
+
updatePlaybookRun(db, run.runId, {
|
|
4064
|
+
currentNode: node.id,
|
|
4065
|
+
iterationCounts: { ...iterationCounts }
|
|
4066
|
+
});
|
|
4067
|
+
if (node.requires?.fields) {
|
|
4068
|
+
const violation = checkRequires(node.requires.fields, node.requires.from, context);
|
|
4069
|
+
if (violation !== null) {
|
|
4070
|
+
const contractFailure = `contract_violation: ${violation}`;
|
|
4071
|
+
auditContractViolation(
|
|
4072
|
+
args.projectRoot,
|
|
4073
|
+
run.runId,
|
|
4074
|
+
node.id,
|
|
4075
|
+
"requires",
|
|
4076
|
+
violation,
|
|
4077
|
+
playbook.name
|
|
4078
|
+
);
|
|
4079
|
+
const handled = handleContractErrorHandler(playbook, "contract_violation", contractFailure);
|
|
4080
|
+
if (handled === "abort") {
|
|
4081
|
+
failedNodeId = node.id;
|
|
4082
|
+
lastError = contractFailure;
|
|
4083
|
+
break;
|
|
4084
|
+
}
|
|
4085
|
+
if (handled !== null) {
|
|
4086
|
+
context["__lastError"] = contractFailure;
|
|
4087
|
+
context["__lastFailedNode"] = node.id;
|
|
4088
|
+
context["__contractViolation"] = violation;
|
|
4089
|
+
if (handled === "hitl_escalate") {
|
|
4090
|
+
exceededNodeId = node.id;
|
|
4091
|
+
break;
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
}
|
|
4095
|
+
}
|
|
4096
|
+
let outcome;
|
|
4097
|
+
if (node.type === "agentic") {
|
|
4098
|
+
outcome = await executeAgenticNode(
|
|
4099
|
+
node,
|
|
4100
|
+
run.runId,
|
|
4101
|
+
context,
|
|
4102
|
+
attempt,
|
|
4103
|
+
dispatcher,
|
|
4104
|
+
playbook.name
|
|
4105
|
+
);
|
|
4106
|
+
} else if (node.type === "deterministic") {
|
|
4107
|
+
outcome = await executeDeterministicNode(
|
|
4108
|
+
node,
|
|
4109
|
+
run.runId,
|
|
4110
|
+
context,
|
|
4111
|
+
attempt,
|
|
4112
|
+
dispatcher,
|
|
4113
|
+
deterministicRunner
|
|
4114
|
+
);
|
|
4115
|
+
} else if (node.type === "approval") {
|
|
4116
|
+
outcome = executeApprovalNode(node, run.runId, context, db, approvalSecret);
|
|
4117
|
+
} else {
|
|
4118
|
+
const exhaustive = node;
|
|
4119
|
+
throw new Error(
|
|
4120
|
+
`${E_PLAYBOOK_RUNTIME_INVALID}: unknown node kind ${JSON.stringify(exhaustive)}`
|
|
4121
|
+
);
|
|
4122
|
+
}
|
|
4123
|
+
if (outcome.kind === "success") {
|
|
4124
|
+
Object.assign(context, outcome.output);
|
|
4125
|
+
updatePlaybookRun(db, run.runId, { bindings: { ...context } });
|
|
4126
|
+
if (node.ensures?.outputFiles) {
|
|
4127
|
+
for (const key of node.ensures.outputFiles) {
|
|
4128
|
+
if (!(key in context)) {
|
|
4129
|
+
const violation = `ensures.outputFiles[${key}] not present in context after ${node.id}`;
|
|
4130
|
+
auditContractViolation(
|
|
4131
|
+
args.projectRoot,
|
|
4132
|
+
run.runId,
|
|
4133
|
+
node.id,
|
|
4134
|
+
"ensures",
|
|
4135
|
+
key,
|
|
4136
|
+
playbook.name
|
|
4137
|
+
);
|
|
4138
|
+
handleContractErrorHandler(playbook, "contract_violation", violation);
|
|
4139
|
+
context["__ensuresViolation"] = violation;
|
|
4140
|
+
}
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
if (node.ensures?.schema) {
|
|
4144
|
+
let schemaViolation = null;
|
|
4145
|
+
const spec = getEnsuresSchema(node.ensures.schema);
|
|
4146
|
+
if (spec === null) {
|
|
4147
|
+
schemaViolation = `ensures.schema[${node.ensures.schema}] on ${node.id}: unknown schema name. Registered: ${listEnsuresSchemaNames().join(", ")}`;
|
|
4148
|
+
} else {
|
|
4149
|
+
const result = spec.schema.safeParse(context[spec.contextKey]);
|
|
4150
|
+
if (!result.success) {
|
|
4151
|
+
const issue = result.error.issues[0];
|
|
4152
|
+
const path = issue?.path ?? [];
|
|
4153
|
+
const at = path.length > 0 ? ` at ${path.join(".")}` : "";
|
|
4154
|
+
schemaViolation = `ensures.schema[${spec.name}] on ${node.id}: ${issue?.message ?? "invalid shape"}${at}`;
|
|
4155
|
+
}
|
|
4156
|
+
}
|
|
4157
|
+
if (schemaViolation !== null) {
|
|
4158
|
+
auditContractViolation(
|
|
4159
|
+
args.projectRoot,
|
|
4160
|
+
run.runId,
|
|
4161
|
+
node.id,
|
|
4162
|
+
"ensures",
|
|
4163
|
+
node.ensures.schema,
|
|
4164
|
+
playbook.name
|
|
4165
|
+
);
|
|
4166
|
+
const handled = handleContractErrorHandler(
|
|
4167
|
+
playbook,
|
|
4168
|
+
"contract_violation",
|
|
4169
|
+
schemaViolation
|
|
4170
|
+
);
|
|
4171
|
+
if (handled === "abort") {
|
|
4172
|
+
failedNodeId = node.id;
|
|
4173
|
+
lastError = schemaViolation;
|
|
4174
|
+
} else {
|
|
4175
|
+
context["__ensuresSchemaViolation"] = schemaViolation;
|
|
4176
|
+
if (handled === "hitl_escalate") {
|
|
4177
|
+
exceededNodeId = node.id;
|
|
4178
|
+
}
|
|
4179
|
+
}
|
|
4180
|
+
}
|
|
4181
|
+
}
|
|
4182
|
+
if (failedNodeId !== void 0) break;
|
|
4183
|
+
const nextId = resolveNextNodeId(node.id, edgeIndex, context);
|
|
4184
|
+
if (nextId !== null) {
|
|
4185
|
+
const edge = resolveEdge(node.id, nextId, playbook.edges);
|
|
4186
|
+
if (edge?.contract?.requires) {
|
|
4187
|
+
for (const key of edge.contract.requires) {
|
|
4188
|
+
if (!(key in context)) {
|
|
4189
|
+
const violation = `edge.contract.requires[${key}] missing when crossing ${node.id} \u2192 ${nextId}`;
|
|
4190
|
+
auditContractViolation(
|
|
4191
|
+
args.projectRoot,
|
|
4192
|
+
run.runId,
|
|
4193
|
+
node.id,
|
|
4194
|
+
"requires",
|
|
4195
|
+
key,
|
|
4196
|
+
playbook.name
|
|
4197
|
+
);
|
|
4198
|
+
const handled = handleContractErrorHandler(playbook, "contract_violation", violation);
|
|
4199
|
+
if (handled === "abort") {
|
|
4200
|
+
failedNodeId = node.id;
|
|
4201
|
+
lastError = violation;
|
|
4202
|
+
break;
|
|
4203
|
+
}
|
|
4204
|
+
context["__contractViolation"] = violation;
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
if (failedNodeId !== void 0) break;
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
currentId = nextId;
|
|
4211
|
+
continue;
|
|
4212
|
+
}
|
|
4213
|
+
if (outcome.kind === "awaiting_approval") {
|
|
4214
|
+
const pausedAt = now().toISOString();
|
|
4215
|
+
updatePlaybookRun(db, run.runId, {
|
|
4216
|
+
status: "paused",
|
|
4217
|
+
errorContext: null,
|
|
4218
|
+
bindings: { ...context },
|
|
4219
|
+
iterationCounts: { ...iterationCounts }
|
|
4220
|
+
});
|
|
4221
|
+
return {
|
|
4222
|
+
runId: run.runId,
|
|
4223
|
+
terminalStatus: "pending_approval",
|
|
4224
|
+
finalContext: { ...context, __pausedAt: pausedAt },
|
|
4225
|
+
approvalToken: outcome.token
|
|
4226
|
+
};
|
|
4227
|
+
}
|
|
4228
|
+
lastError = outcome.error;
|
|
4229
|
+
const injectTarget = node.on_failure?.inject_into;
|
|
4230
|
+
if (attempt >= cap) {
|
|
4231
|
+
if (injectTarget !== void 0 && injectTarget !== node.id) {
|
|
4232
|
+
if (!nodeIndex.has(injectTarget)) {
|
|
4233
|
+
failedNodeId = node.id;
|
|
4234
|
+
break;
|
|
4235
|
+
}
|
|
4236
|
+
context["__lastError"] = outcome.error;
|
|
4237
|
+
context["__lastFailedNode"] = node.id;
|
|
4238
|
+
updatePlaybookRun(db, run.runId, {
|
|
4239
|
+
errorContext: outcome.error,
|
|
4240
|
+
bindings: { ...context }
|
|
4241
|
+
});
|
|
4242
|
+
currentId = injectTarget;
|
|
4243
|
+
iterationCounts[injectTarget] = 0;
|
|
4244
|
+
continue;
|
|
4245
|
+
}
|
|
4246
|
+
exceededNodeId = node.id;
|
|
4247
|
+
break;
|
|
4248
|
+
}
|
|
4249
|
+
if (injectTarget !== void 0 && injectTarget !== node.id) {
|
|
4250
|
+
if (!nodeIndex.has(injectTarget)) {
|
|
4251
|
+
failedNodeId = node.id;
|
|
4252
|
+
break;
|
|
4253
|
+
}
|
|
4254
|
+
context["__lastError"] = outcome.error;
|
|
4255
|
+
context["__lastFailedNode"] = node.id;
|
|
4256
|
+
updatePlaybookRun(db, run.runId, {
|
|
4257
|
+
errorContext: outcome.error,
|
|
4258
|
+
bindings: { ...context }
|
|
4259
|
+
});
|
|
4260
|
+
currentId = injectTarget;
|
|
4261
|
+
iterationCounts[injectTarget] = 0;
|
|
4262
|
+
continue;
|
|
4263
|
+
}
|
|
4264
|
+
updatePlaybookRun(db, run.runId, { errorContext: outcome.error });
|
|
4265
|
+
}
|
|
4266
|
+
const completedAt = now().toISOString();
|
|
4267
|
+
if (exceededNodeId !== void 0) {
|
|
4268
|
+
updatePlaybookRun(db, run.runId, {
|
|
4269
|
+
status: "failed",
|
|
4270
|
+
errorContext: lastError ?? null,
|
|
4271
|
+
completedAt,
|
|
4272
|
+
bindings: { ...context },
|
|
4273
|
+
iterationCounts: { ...iterationCounts }
|
|
4274
|
+
});
|
|
4275
|
+
const result = {
|
|
4276
|
+
runId: run.runId,
|
|
4277
|
+
terminalStatus: "exceeded_iteration_cap",
|
|
4278
|
+
finalContext: { ...context },
|
|
4279
|
+
exceededNodeId
|
|
4280
|
+
};
|
|
4281
|
+
if (lastError !== void 0) result.errorContext = lastError;
|
|
4282
|
+
return result;
|
|
4283
|
+
}
|
|
4284
|
+
if (failedNodeId !== void 0) {
|
|
4285
|
+
updatePlaybookRun(db, run.runId, {
|
|
4286
|
+
status: "failed",
|
|
4287
|
+
errorContext: lastError ?? null,
|
|
4288
|
+
completedAt,
|
|
4289
|
+
bindings: { ...context },
|
|
4290
|
+
iterationCounts: { ...iterationCounts }
|
|
4291
|
+
});
|
|
4292
|
+
const result = {
|
|
4293
|
+
runId: run.runId,
|
|
4294
|
+
terminalStatus: "failed",
|
|
4295
|
+
finalContext: { ...context },
|
|
4296
|
+
failedNodeId
|
|
4297
|
+
};
|
|
4298
|
+
if (lastError !== void 0) result.errorContext = lastError;
|
|
4299
|
+
return result;
|
|
4300
|
+
}
|
|
4301
|
+
updatePlaybookRun(db, run.runId, {
|
|
4302
|
+
status: "completed",
|
|
4303
|
+
currentNode: null,
|
|
4304
|
+
completedAt,
|
|
4305
|
+
bindings: { ...context },
|
|
4306
|
+
iterationCounts: { ...iterationCounts },
|
|
4307
|
+
errorContext: null
|
|
4308
|
+
});
|
|
4309
|
+
return {
|
|
4310
|
+
runId: run.runId,
|
|
4311
|
+
terminalStatus: "completed",
|
|
4312
|
+
finalContext: { ...context }
|
|
4313
|
+
};
|
|
4314
|
+
}
|
|
4315
|
+
async function executePlaybook(options) {
|
|
4316
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
4317
|
+
const maxIterationsDefault = options.maxIterationsDefault ?? 3;
|
|
4318
|
+
if (!Number.isInteger(maxIterationsDefault) || maxIterationsDefault < 0) {
|
|
4319
|
+
throw new Error(
|
|
4320
|
+
`${E_PLAYBOOK_RUNTIME_INVALID}: maxIterationsDefault must be a non-negative integer (got ${maxIterationsDefault})`
|
|
4321
|
+
);
|
|
4322
|
+
}
|
|
4323
|
+
const approvalSecret = options.approvalSecret ?? getPlaybookSecret();
|
|
4324
|
+
const nodeIndex = new Map(options.playbook.nodes.map((n) => [n.id, n]));
|
|
4325
|
+
const edgeIndex = buildEdgeIndex(options.playbook);
|
|
4326
|
+
const entry = resolveEntryNode(options.playbook, edgeIndex);
|
|
4327
|
+
const createInput = {
|
|
4328
|
+
playbookName: options.playbook.name,
|
|
4329
|
+
playbookHash: options.playbookHash,
|
|
4330
|
+
initialBindings: { ...options.initialContext }
|
|
4331
|
+
};
|
|
4332
|
+
if (options.epicId !== void 0) createInput.epicId = options.epicId;
|
|
4333
|
+
if (options.sessionId !== void 0) createInput.sessionId = options.sessionId;
|
|
4334
|
+
const run = createPlaybookRun(options.db, createInput);
|
|
4335
|
+
const context = { ...options.initialContext };
|
|
4336
|
+
const iterationCounts = {};
|
|
4337
|
+
const runArgs = {
|
|
4338
|
+
db: options.db,
|
|
4339
|
+
playbook: options.playbook,
|
|
4340
|
+
run,
|
|
4341
|
+
startNodeId: entry.id,
|
|
4342
|
+
nodeIndex,
|
|
4343
|
+
edgeIndex,
|
|
4344
|
+
context,
|
|
4345
|
+
iterationCounts,
|
|
4346
|
+
dispatcher: options.dispatcher,
|
|
4347
|
+
deterministicRunner: options.deterministicRunner,
|
|
4348
|
+
approvalSecret,
|
|
4349
|
+
maxIterationsDefault,
|
|
4350
|
+
now,
|
|
4351
|
+
projectRoot: options.projectRoot
|
|
4352
|
+
};
|
|
4353
|
+
return runFromNode(runArgs);
|
|
4354
|
+
}
|
|
4355
|
+
async function resumePlaybook(options) {
|
|
4356
|
+
const approval = getPlaybookApprovalByToken(options.db, options.approvalToken);
|
|
4357
|
+
if (approval === null) {
|
|
4358
|
+
throw new Error(
|
|
4359
|
+
`${E_PLAYBOOK_RESUME_BLOCKED}: no approval gate for token ${options.approvalToken}`
|
|
4360
|
+
);
|
|
4361
|
+
}
|
|
4362
|
+
if (approval.status === "pending") {
|
|
4363
|
+
throw new Error(
|
|
4364
|
+
`${E_PLAYBOOK_RESUME_BLOCKED}: gate ${approval.approvalId} is still pending \u2014 approve before resuming`
|
|
4365
|
+
);
|
|
4366
|
+
}
|
|
4367
|
+
if (approval.status === "rejected") {
|
|
4368
|
+
const run2 = getPlaybookRun(options.db, approval.runId);
|
|
4369
|
+
if (run2 !== null && run2.status !== "failed") {
|
|
4370
|
+
updatePlaybookRun(options.db, approval.runId, {
|
|
4371
|
+
status: "failed",
|
|
4372
|
+
errorContext: approval.reason ?? "gate rejected",
|
|
4373
|
+
completedAt: (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString()
|
|
4374
|
+
});
|
|
4375
|
+
}
|
|
4376
|
+
throw new Error(
|
|
4377
|
+
`${E_PLAYBOOK_RESUME_BLOCKED}: gate ${approval.approvalId} was rejected` + (approval.reason ? ` (${approval.reason})` : "")
|
|
4378
|
+
);
|
|
4379
|
+
}
|
|
4380
|
+
const run = getPlaybookRun(options.db, approval.runId);
|
|
4381
|
+
if (run === null) {
|
|
4382
|
+
throw new Error(
|
|
4383
|
+
`${E_PLAYBOOK_RESUME_BLOCKED}: run ${approval.runId} no longer exists (deleted?)`
|
|
4384
|
+
);
|
|
4385
|
+
}
|
|
4386
|
+
const validResumeStatuses = ["paused", "running"];
|
|
4387
|
+
if (!validResumeStatuses.includes(run.status)) {
|
|
4388
|
+
throw new Error(
|
|
4389
|
+
`${E_PLAYBOOK_RESUME_BLOCKED}: run ${run.runId} is ${run.status}, expected paused|running`
|
|
4390
|
+
);
|
|
4391
|
+
}
|
|
4392
|
+
const nodeIndex = new Map(options.playbook.nodes.map((n) => [n.id, n]));
|
|
4393
|
+
const edgeIndex = buildEdgeIndex(options.playbook);
|
|
4394
|
+
const approvalNode = nodeIndex.get(approval.nodeId);
|
|
4395
|
+
if (approvalNode === void 0 || approvalNode.type !== "approval") {
|
|
4396
|
+
throw new Error(
|
|
4397
|
+
`${E_PLAYBOOK_RESUME_BLOCKED}: approval node ${approval.nodeId} not found in playbook ${options.playbook.name}`
|
|
4398
|
+
);
|
|
4399
|
+
}
|
|
4400
|
+
const now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
4401
|
+
const maxIterationsDefault = options.maxIterationsDefault ?? 3;
|
|
4402
|
+
const approvalSecret = options.approvalSecret ?? getPlaybookSecret();
|
|
4403
|
+
const context = { ...run.bindings };
|
|
4404
|
+
const iterationCounts = { ...run.iterationCounts };
|
|
4405
|
+
context["__lastApproval"] = {
|
|
4406
|
+
nodeId: approval.nodeId,
|
|
4407
|
+
approvalId: approval.approvalId,
|
|
4408
|
+
approver: approval.approver,
|
|
4409
|
+
reason: approval.reason,
|
|
4410
|
+
approvedAt: approval.approvedAt
|
|
4411
|
+
};
|
|
4412
|
+
const successor = resolveNextNodeId(approvalNode.id, edgeIndex, context);
|
|
4413
|
+
if (successor === null) {
|
|
4414
|
+
const completedAt = now().toISOString();
|
|
4415
|
+
updatePlaybookRun(options.db, run.runId, {
|
|
4416
|
+
status: "completed",
|
|
4417
|
+
currentNode: null,
|
|
4418
|
+
completedAt,
|
|
4419
|
+
errorContext: null
|
|
4420
|
+
});
|
|
4421
|
+
return {
|
|
4422
|
+
runId: run.runId,
|
|
4423
|
+
terminalStatus: "completed",
|
|
4424
|
+
finalContext: { ...run.bindings }
|
|
4425
|
+
};
|
|
4426
|
+
}
|
|
4427
|
+
updatePlaybookRun(options.db, run.runId, {
|
|
4428
|
+
status: "running",
|
|
4429
|
+
currentNode: successor,
|
|
4430
|
+
errorContext: null
|
|
4431
|
+
});
|
|
4432
|
+
createPlaybookApproval(options.db, {
|
|
4433
|
+
runId: run.runId,
|
|
4434
|
+
nodeId: approval.nodeId,
|
|
4435
|
+
token: `resume:${approval.token}:${now().getTime()}`,
|
|
4436
|
+
autoPassed: true
|
|
4437
|
+
});
|
|
4438
|
+
const runArgs = {
|
|
4439
|
+
db: options.db,
|
|
4440
|
+
playbook: options.playbook,
|
|
4441
|
+
run,
|
|
4442
|
+
startNodeId: successor,
|
|
4443
|
+
nodeIndex,
|
|
4444
|
+
edgeIndex,
|
|
4445
|
+
context,
|
|
4446
|
+
iterationCounts,
|
|
4447
|
+
dispatcher: options.dispatcher,
|
|
4448
|
+
deterministicRunner: options.deterministicRunner,
|
|
4449
|
+
approvalSecret,
|
|
4450
|
+
maxIterationsDefault,
|
|
4451
|
+
now,
|
|
4452
|
+
projectRoot: options.projectRoot
|
|
4453
|
+
};
|
|
4454
|
+
return runFromNode(runArgs);
|
|
4455
|
+
}
|
|
4456
|
+
|
|
4457
|
+
// packages/playbooks/src/index.ts
|
|
4458
|
+
var PLAYBOOKS_PACKAGE_VERSION = "2026.4.129";
|
|
4459
|
+
|
|
4460
|
+
export {
|
|
4461
|
+
E_APPROVAL_NOT_FOUND,
|
|
4462
|
+
E_APPROVAL_ALREADY_DECIDED,
|
|
4463
|
+
getPlaybookSecret,
|
|
4464
|
+
generateResumeToken,
|
|
4465
|
+
createApprovalGate,
|
|
4466
|
+
approveGate,
|
|
4467
|
+
rejectGate,
|
|
4468
|
+
getPendingApprovals,
|
|
4469
|
+
PlaybookParseError,
|
|
4470
|
+
parsePlaybook,
|
|
4471
|
+
validatePlaybookCompliance,
|
|
4472
|
+
migratePlaybook,
|
|
4473
|
+
migratePlaybookFile,
|
|
4474
|
+
DEFAULT_POLICY_RULES,
|
|
4475
|
+
evaluatePolicy,
|
|
4476
|
+
createPlaybookRun,
|
|
4477
|
+
getPlaybookRun,
|
|
4478
|
+
updatePlaybookRun,
|
|
4479
|
+
listPlaybookRuns,
|
|
4480
|
+
deletePlaybookRun,
|
|
4481
|
+
createPlaybookApproval,
|
|
4482
|
+
getPlaybookApprovalByToken,
|
|
4483
|
+
updatePlaybookApproval,
|
|
4484
|
+
listPlaybookApprovals,
|
|
4485
|
+
E_PLAYBOOK_RUNTIME_INVALID,
|
|
4486
|
+
E_PLAYBOOK_RESUME_BLOCKED,
|
|
4487
|
+
resolveStepBindings,
|
|
4488
|
+
executePlaybook,
|
|
4489
|
+
resumePlaybook,
|
|
4490
|
+
PLAYBOOKS_PACKAGE_VERSION
|
|
4491
|
+
};
|
|
4492
|
+
/*! Bundled license information:
|
|
4493
|
+
|
|
4494
|
+
js-yaml/dist/js-yaml.mjs:
|
|
4495
|
+
(*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT *)
|
|
4496
|
+
*/
|
|
4497
|
+
//# sourceMappingURL=chunk-QFFQSKRC.js.map
|