@agimon-ai/po-cloudflare 0.0.2-alpha.2 → 0.0.2-alpha.21
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/README.md +4 -3
- package/dist/abort-signals-2GUraIGq.js +34 -0
- package/dist/agent-DZ-OKOHn.js +6850 -0
- package/dist/anthropic-messages-5ODquUB-.js +14317 -0
- package/dist/{apiContracts-CHOiCbS_.js → apiContracts-b33nSAAI.js} +18 -81
- package/dist/{approval-BMXqnTYd.js → approval-r3NnI1VC.js} +19 -3
- package/dist/{approvalPrompt-Bg1JrEEY.js → approvalPrompt-DWoXxu3S.js} +2 -2
- package/dist/artifactFiles-DLCReI0-.js +1 -0
- package/dist/assets/assets/{CodeEditorView-BnyZHaYM.js → CodeEditorView-XeNS0L9M.js} +2 -2
- package/dist/assets/assets/{abnfDiagram-WEYOIA3C-muME0eCj.js → abnfDiagram-WEYOIA3C-B6ZW0nkR.js} +2 -2
- package/dist/assets/assets/{architecture-WOLXFQ4H-DMnhK1WH.js → architecture-WOLXFQ4H-bVR64sHO.js} +1 -1
- package/dist/assets/assets/{architectureDiagram-ZHVYKT53-DKn7XGP7.js → architectureDiagram-ZHVYKT53-D7tZz3io.js} +2 -2
- package/dist/assets/assets/{blockDiagram-RJAE7QA3-DtDctXZg.js → blockDiagram-RJAE7QA3-DdwScfiX.js} +2 -2
- package/dist/assets/assets/{c4Diagram-XDPPPE54-23pGLJeP.js → c4Diagram-XDPPPE54-DgSxZJCV.js} +2 -2
- package/dist/assets/assets/channel-TPcVvp_3.js +2 -0
- package/dist/assets/assets/{chunk-2E7WHVMD-BZ2nGNPa.js → chunk-2E7WHVMD-D5TXC2SM.js} +2 -2
- package/dist/assets/assets/{chunk-4EMNKR2T-Dui1SYFi.js → chunk-4EMNKR2T-BWhOSvo1.js} +2 -2
- package/dist/assets/assets/{chunk-55XCU76K-CUB92Evl.js → chunk-55XCU76K-HkkBzLtZ.js} +2 -2
- package/dist/assets/assets/{chunk-7S6XSTFO-CVayPHfE.js → chunk-7S6XSTFO-CBnjycLU.js} +2 -2
- package/dist/assets/assets/{chunk-AQDTSKZB---wakYqY.js → chunk-AQDTSKZB-75lIIq8T.js} +2 -2
- package/dist/assets/assets/{chunk-DSNLSHJZ-DfbdohUR.js → chunk-DSNLSHJZ-D8PpnXMk.js} +2 -2
- package/dist/assets/assets/{chunk-HAGFOTED-Dr4KRh-b.js → chunk-HAGFOTED-CXRS2NIN.js} +2 -2
- package/dist/assets/assets/{chunk-HNE4Q36P-D06cR91Z.js → chunk-HNE4Q36P-BocUqS94.js} +2 -2
- package/dist/assets/assets/{chunk-NQOKRVIF-Ca4gLeDb.js → chunk-NQOKRVIF-CHf_ogYT.js} +2 -2
- package/dist/assets/assets/{chunk-UHW7PFBP-DmL638jN.js → chunk-UHW7PFBP-DrW1PaIv.js} +2 -2
- package/dist/assets/assets/{chunk-VQ5W62QI-pkxSW5Zj.js → chunk-VQ5W62QI-CLoA7bFm.js} +2 -2
- package/dist/assets/assets/{chunk-WQQL4CDK-Dcc8hV4U.js → chunk-WQQL4CDK-BmBsrj9I.js} +2 -2
- package/dist/assets/assets/chunk-XXDRQBXY-iFE4Tl8c.js +2 -0
- package/dist/assets/assets/{chunk-YZO67HFG-B_HKcFrw.js → chunk-YZO67HFG-DShE_cgv.js} +2 -2
- package/dist/assets/assets/{chunk-ZAUX2LTX-DAzZUysS.js → chunk-ZAUX2LTX-B3oLvSXy.js} +2 -2
- package/dist/assets/assets/{chunk-ZCHMQSOR-DAVgjymL.js → chunk-ZCHMQSOR-B14vKK7C.js} +2 -2
- package/dist/assets/assets/{classDiagram-v2-4MYWR3UA-Fsw8TGPu.js → classDiagram-v2-4MYWR3UA-Da8elIW2.js} +2 -2
- package/dist/assets/assets/{cose-bilkent-JH36ORCC-CgUbISYV.js → cose-bilkent-JH36ORCC-Du4tGtiJ.js} +2 -2
- package/dist/assets/assets/{cynefin-EF2NZ3EQ-D1LxAU2x.js → cynefin-EF2NZ3EQ-Cyj6i_WI.js} +1 -1
- package/dist/assets/assets/{cynefinDiagram-WF24UDRP-D54I1jil.js → cynefinDiagram-WF24UDRP-DFWXwO7A.js} +2 -2
- package/dist/assets/assets/{dagre-NK4GIZVX-DC7zL16U.js → dagre-NK4GIZVX-C1wB_cf-.js} +2 -2
- package/dist/assets/assets/{diagram-CBK3MWTC-DB0ptUdz.js → diagram-CBK3MWTC-MYCOBYl6.js} +2 -2
- package/dist/assets/assets/{diagram-I5XIIV2D-CozSftPJ.js → diagram-I5XIIV2D-BFYbKUFf.js} +2 -2
- package/dist/assets/assets/{diagram-ODIL2UCW-g3WOEWDS.js → diagram-ODIL2UCW-6siqTpv_.js} +2 -2
- package/dist/assets/assets/{diagram-PFBEJUXE-CFxGeOYi.js → diagram-PFBEJUXE-CaBr9CoB.js} +2 -2
- package/dist/assets/assets/{diagram-RJA3I4VV-BQBsLche.js → diagram-RJA3I4VV-DAvmuDpc.js} +2 -2
- package/dist/assets/assets/{diagram-TYUNFSNR-DrjpW2yq.js → diagram-TYUNFSNR-CJnhgCpo.js} +2 -2
- package/dist/assets/assets/{dist-DjL8d1jZ.js → dist-BQ4W1R18.js} +2 -2
- package/dist/assets/assets/{dist-DvgCCshF.js → dist-BnzFckPF.js} +2 -2
- package/dist/assets/assets/{dist-gfbb4ygy.js → dist-CFtBpcYL.js} +2 -2
- package/dist/assets/assets/{dist-BabjcJ3j.js → dist-CIQX1z4W.js} +2 -2
- package/dist/assets/assets/{dist-XIZum9n5.js → dist-ChHYoe9_.js} +2 -2
- package/dist/assets/assets/{dist-1-mhYUBH.js → dist-DKxZO8d9.js} +2 -2
- package/dist/assets/assets/{dist-h6SOnP8-.js → dist-DL6z28wl.js} +2 -2
- package/dist/assets/assets/{dist-B3JXhDWV.js → dist-DNyn1p9Z.js} +2 -2
- package/dist/assets/assets/{dist-Izr2SB3q.js → dist-qYlLXIa8.js} +2 -2
- package/dist/assets/assets/{ebnfDiagram-V4P3TTPT-BZS_aAve.js → ebnfDiagram-V4P3TTPT-AUcqDTM3.js} +2 -2
- package/dist/assets/assets/{elk-QONTBCTQ-B2ksVmMA.js → elk-QONTBCTQ-aA10PEHJ.js} +2 -2
- package/dist/assets/assets/{erDiagram-KYQIGQAA-7P6zF-Z-.js → erDiagram-KYQIGQAA-hhYiqA-x.js} +2 -2
- package/dist/assets/assets/{eventmodeling-K75KTNOO-RoGQoRq-.js → eventmodeling-K75KTNOO-BQZqbRo5.js} +1 -1
- package/dist/assets/assets/flowDiagram-IUGLLWBU-BuyysPYC.js +1 -0
- package/dist/assets/assets/{ganttDiagram-R7GPNTJY-CTOlRy7M.js → ganttDiagram-R7GPNTJY-CLON1GpW.js} +2 -2
- package/dist/assets/assets/{gitGraph-VSP46ZUC-CPqytIt0.js → gitGraph-VSP46ZUC-DbmvNwR2.js} +1 -1
- package/dist/assets/assets/{gitGraphDiagram-PDYL7XHY-BffLxuxg.js → gitGraphDiagram-PDYL7XHY-DJVO0WlL.js} +2 -2
- package/dist/assets/assets/index-BiTVAj5E.js +155 -0
- package/dist/assets/assets/index-CBNQEGK3.css +1 -0
- package/dist/assets/assets/{info-OHQRW6UA-BI8RK0Ow.js → info-OHQRW6UA-CAt3Nt3g.js} +1 -1
- package/dist/assets/assets/{infoDiagram-MVDRKAX5-DUIst1FB.js → infoDiagram-MVDRKAX5-DTuqH-Zb.js} +2 -2
- package/dist/assets/assets/{ishikawaDiagram-HPEHV2GE-CA17Eho5.js → ishikawaDiagram-HPEHV2GE-BnWvdonT.js} +2 -2
- package/dist/assets/assets/{journeyDiagram-BOSHW7O7-CNri5Ap9.js → journeyDiagram-BOSHW7O7-Btxtcgvl.js} +2 -2
- package/dist/assets/assets/{kanban-definition-FNSA4HC5-DnXna7jO.js → kanban-definition-FNSA4HC5-q7ek9o_H.js} +2 -2
- package/dist/assets/assets/{line-BsXJZn93.js → line-B7yLilmC.js} +2 -2
- package/dist/assets/assets/{linear-BHYaD5T0.js → linear-y8aSKEli.js} +2 -2
- package/dist/assets/assets/{mermaid-parser.core-B64Eo-8a.js → mermaid-parser.core-B4rH50nD.js} +4 -4
- package/dist/assets/assets/{mermaid.core-Zw9qmTzg.js → mermaid.core-DnRVHTjE.js} +5 -5
- package/dist/assets/assets/{mindmap-definition-6OY57UG3-E5qz4KNc.js → mindmap-definition-6OY57UG3-DT9Afs2v.js} +2 -2
- package/dist/assets/assets/{packet-JDAUHWVQ-DgfizTr3.js → packet-JDAUHWVQ-CnqNbu4p.js} +1 -1
- package/dist/assets/assets/{pegDiagram-ECIUJNBX-D0WK_agM.js → pegDiagram-ECIUJNBX-cvxdBBFq.js} +2 -2
- package/dist/assets/assets/{pie-XZMESJXO-PJR1sXD4.js → pie-XZMESJXO-etXMNsaL.js} +1 -1
- package/dist/assets/assets/{pieDiagram-GNMPY74T-CPuU-NTs.js → pieDiagram-GNMPY74T-CBN-R3_j.js} +2 -2
- package/dist/assets/assets/{quadrantDiagram-D57K4MC3-5C9yjM1b.js → quadrantDiagram-D57K4MC3-C5jjVPIH.js} +2 -2
- package/dist/assets/assets/{radar-ABXABTNO-BspdXgl0.js → radar-ABXABTNO-CAMd_mrV.js} +1 -1
- package/dist/assets/assets/{railroad-I3PHUGI6-Ct0a6hLD.js → railroad-I3PHUGI6-DIs3auoe.js} +1 -1
- package/dist/assets/assets/{railroad-abnf-LNEFI6M7-fduYB4SA.js → railroad-abnf-LNEFI6M7-CJXr1qWy.js} +1 -1
- package/dist/assets/assets/{railroad-ebnf-DWYD2UWJ-CTQa8Sww.js → railroad-ebnf-DWYD2UWJ-DfwtykqI.js} +1 -1
- package/dist/assets/assets/{railroad-peg-JR7BVNR7-DatoH3GJ.js → railroad-peg-JR7BVNR7-B8beAhTs.js} +1 -1
- package/dist/assets/assets/{railroadDiagram-Y72NRBL7-C8sWN8l2.js → railroadDiagram-Y72NRBL7-BDcQE-EL.js} +2 -2
- package/dist/assets/assets/{requirementDiagram-EQYSW5RA-CqRz4RcT.js → requirementDiagram-EQYSW5RA-KJ4-QjZM.js} +2 -2
- package/dist/assets/assets/{sankeyDiagram-SY24JHO5-bdiuKKlX.js → sankeyDiagram-SY24JHO5-VjIB-Ybr.js} +2 -2
- package/dist/assets/assets/{sequenceDiagram-BLEHNHQU-Zy-8I0Hy.js → sequenceDiagram-BLEHNHQU-MfMuWq1M.js} +2 -2
- package/dist/assets/assets/{src-gihY33R9.js → src-BAxIj8GJ.js} +2 -2
- package/dist/assets/assets/{stateDiagram-v2-A6IESKWZ-DXQERPvz.js → stateDiagram-v2-A6IESKWZ-mHwLRRCY.js} +2 -2
- package/dist/assets/assets/{swimlanes-B3ENRKFQ-1gjZQElg.js → swimlanes-B3ENRKFQ-PArlYoqV.js} +2 -2
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-The09-5S.js +9 -0
- package/dist/assets/assets/{timeline-definition-JXYKGLGB-CTeYEw-9.js → timeline-definition-JXYKGLGB-B2nKiNFU.js} +2 -2
- package/dist/assets/assets/{treeView-D4JQ5SDB-DD-EsLLT.js → treeView-D4JQ5SDB-gU23_RuI.js} +1 -1
- package/dist/assets/assets/{treemap-SAJKECNS-BLdFeS5J.js → treemap-SAJKECNS-CiqoMvZa.js} +1 -1
- package/dist/assets/assets/{usecaseDiagram-WPOLBNNX-C1GikSSP.js → usecaseDiagram-WPOLBNNX-DpeoWpMK.js} +2 -2
- package/dist/assets/assets/{vennDiagram-Q3Y3IDCW-B1FoA3g8.js → vennDiagram-Q3Y3IDCW-C31iGKvM.js} +2 -2
- package/dist/assets/assets/{wardley-7MLQ67FV-BrHb5Bjf.js → wardley-7MLQ67FV-CIzHhzNw.js} +1 -1
- package/dist/assets/assets/{wardleyDiagram-IVAIDKWA-CmPLD1X4.js → wardleyDiagram-IVAIDKWA-DIIkoezc.js} +2 -2
- package/dist/assets/assets/{webpack-BYWDFj_R.js → webpack-RFseiMZW.js} +2 -2
- package/dist/assets/assets/{xychartDiagram-4URNHDU4-DR5pfEjl.js → xychartDiagram-4URNHDU4-QiHL91kC.js} +2 -2
- package/dist/assets/bundle-asset-policy.json +1 -1
- package/dist/assets/index.html +2 -2
- package/dist/assets/plugins/assets/base-CKKRZ7-h.css +2 -0
- package/dist/assets/plugins/assets/browserCaptureWorklet-Droj0fW0-Droj0fW0.js +13 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
- package/dist/assets/plugins/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/assets/plugins/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/assets/plugins/assets/sileroVadWorker-D894njUe-DjN_BMWf.mjs +110 -0
- package/dist/assets/plugins/assets/silero_vad_v6.2.1-SjbCxFXk-SjbCxFXk.onnx +0 -0
- package/dist/assets/plugins/chunks/po-web-runtime-BJDT6Lbw.js +1 -0
- package/dist/assets/plugins/compositions.json +1 -0
- package/dist/assets/plugins/slots/approval.293d9a00-BXIhaPlQ.js +2 -0
- package/dist/assets/plugins/slots/artifacts.24567664-ZzR0gbvy.js +1 -0
- package/dist/assets/plugins/slots/author.0998a880-DAbA-7rb.js +93 -0
- package/dist/assets/plugins/slots/autocompact.dd97d013-IVq4Z6qm.js +1 -0
- package/dist/assets/plugins/slots/builtin-tools.36d7400b-CpCLjRRN.js +7 -0
- package/dist/assets/plugins/slots/codemode.8eaee717-VWt9PqsU.js +10 -0
- package/dist/assets/plugins/slots/domain.5e95fc37-5PIUBqDe.js +1 -0
- package/dist/assets/plugins/slots/edit.385c9aa9-DNAjPNG5.js +7 -0
- package/dist/assets/plugins/slots/files.daf34ed8-CQaTz0i1.js +2 -0
- package/dist/assets/plugins/slots/goal.77ec9930-B8EkarBq.js +1 -0
- package/dist/assets/plugins/slots/grep.02052cdc-CIRhO2gY.js +1 -0
- package/dist/assets/plugins/slots/help.ecd4c0f9-naMF9NN1.js +3 -0
- package/dist/assets/plugins/slots/log.a86eb6d0-D5__rAZJ.js +4 -0
- package/dist/assets/plugins/slots/mcp.974af249-DPNHn9XH.js +109 -0
- package/dist/assets/plugins/slots/plan.bafb8f68-C5GEpybF.js +3 -0
- package/dist/assets/plugins/slots/profile.48851a1d-yX6tzV3x.js +1 -0
- package/dist/assets/plugins/slots/prompts.723d7748-B7zpPeoF.js +3 -0
- package/dist/assets/plugins/slots/read.46bf6536-Cw5Z5z5T.js +1 -0
- package/dist/assets/plugins/slots/runner.53e9bd76-CiQR_FPX.js +8 -0
- package/dist/assets/plugins/slots/skill.086701a4-CL6h_F-x.js +4 -0
- package/dist/assets/plugins/slots/vault.ac9935c8-DKERQYg4.js +1 -0
- package/dist/assets/plugins/slots/voice.e85ca7f9-DEgb-U9m.js +1 -0
- package/dist/assets/pwa/pwa.js +12 -12
- package/dist/assets/pwa/sw.js +4 -4
- package/dist/{atomicJson-BJfPFSYF.js → atomicJson-C_7F2zD1.js} +2 -3
- package/dist/azure-openai-config-COZUaRzM.js +55 -0
- package/dist/azure-openai-responses-Cs4k2HOd.js +183 -0
- package/dist/{backgroundWork-CeFrbRnj.js → backgroundWork-B1mPDYlf.js} +1 -1
- package/dist/browser-BWf8OMfl.js +3 -0
- package/dist/childSession-Cf2-kH4O.js +22 -0
- package/dist/classifier-shared-IhSH9hhh.js +106 -0
- package/dist/cloudflare-workers-ai-system-one-BNnc8MuH.js +52 -0
- package/dist/{codemode-DbPu0yJN.js → codemode-DQFmrosw.js} +5 -2
- package/dist/contracts-DD3f1Lpn.js +19 -0
- package/dist/diagnostics-1lYFeSJe.js +131 -0
- package/dist/{server-D3PQk1Gt.js → dist-B-vqs6tA.js} +1 -546
- package/dist/dist-Dvx5mlIR.js +50 -0
- package/dist/env-api-keys-Bow6MJe2.js +32 -0
- package/dist/error-body-CJk7jMUh.js +102 -0
- package/dist/esm-BKJy3O9-.js +1553 -0
- package/dist/exports-B0WMEXCP.js +34 -0
- package/dist/{remoteMcp-CMqZldeA.js → exports-D09VsUk-.js} +1153 -175
- package/dist/{exports-BNZz2DNU.js → exports-nV43ShA7.js} +25 -9
- package/dist/{extensionFile-CXOa5G4C.js → extensionFile-DNM4xsje.js} +26 -2
- package/dist/github-copilot-headers-D1RedfLn.js +22 -0
- package/dist/google-generative-ai-DXTILNT0.js +328 -0
- package/dist/google-shared-e4JDCTVP.js +19588 -0
- package/dist/google-vertex-a1lzvJfq.js +374 -0
- package/dist/{domains-BNjGTOPj.js → harnessState-Dwrk3lfv.js} +175 -16
- package/dist/{harnessStore-BT706Ly6.js → harnessStore-Z7yDLO45.js} +4 -5
- package/dist/hash-Dt6RIbkn.js +16 -0
- package/dist/headers-CwtEVQvr.js +17 -0
- package/dist/help-w6vVEZGL.js +101 -0
- package/dist/hubChannel-Cm-sxOvU.js +21 -0
- package/dist/hubRevisions-58pU2dW5.js +363 -0
- package/dist/identity-BgfHobJH.js +165 -0
- package/dist/index.edge-COJJ_Dv2.js +937 -0
- package/dist/index.edge-ChYa2LU4.js +14 -0
- package/dist/index.edge-ClLTmPFz.js +191 -0
- package/dist/index.edge-DyYmurS7.js +62 -0
- package/dist/index.edge-K0w5auwG.js +56 -0
- package/dist/index.edge-Xa5LLtxz.js +67 -0
- package/dist/iso-BPQViXM8.js +10 -0
- package/dist/{layeredConfig-DPQAnlXD.js → layeredConfig-CUkYUs1f.js} +193 -15
- package/dist/{majorModes-DbCfLZH3.js → majorModes-BB0PXgFn.js} +4 -14
- package/dist/majorModes-C7vtBs4D.js +1 -0
- package/dist/{mcpProjection-BsP0IEnb.js → mcpProjection-BtKzB6oK.js} +2 -2
- package/dist/migrations-5gbLIQIc.js +32 -0
- package/dist/mistral-conversations-CLwhVDjA.js +689 -0
- package/dist/modeDefinition-C3Zbrw48.js +44 -0
- package/dist/models-Chzm15vC.js +1511 -0
- package/dist/narration-CpRurWLO.js +127 -0
- package/dist/node-BT4GsJQp.js +2479 -0
- package/dist/node-DytJOfYf.js +23 -0
- package/dist/notification-kckG3leF.js +102 -0
- package/dist/openai-codex-responses-DRMONxDE.js +1210 -0
- package/dist/openai-completions-CcNhAv8l.js +984 -0
- package/dist/openai-decisions-BsFjaAGw.js +142 -0
- package/dist/openai-kPrtlgjl.js +17357 -0
- package/dist/openai-prompt-cache-Bc6qNWt0.js +8 -0
- package/dist/openai-responses-C5Gp2UOV.js +281 -0
- package/dist/openai-responses-shared-BbSi-wBR.js +661 -0
- package/dist/openrouter-cost-CvC52g3b.js +30 -0
- package/dist/openrouter-images-BoHl8g8p.js +124 -0
- package/dist/{hubChannel-BHQyzcOo.js → packageApi-t1oCjNDU.js} +4 -41
- package/dist/photon_rs_bg.wasm +0 -0
- package/dist/pi-messages-BXfrZLC7.js +312 -0
- package/dist/piConfig-DQzlbPY4.js +126 -0
- package/dist/piSettings-Cf1QofNe.js +1 -0
- package/dist/platform-BIEiM4TG.js +113 -0
- package/dist/pluginContributions-Be9EnCAW.js +16 -0
- package/dist/pluginProtocol-BqXXyI4z.js +80 -0
- package/dist/{protocol-Xpm_mCNN.js → protocol-DDL8geoS.js} +2 -2
- package/dist/provider-env-CxhHUFiF.js +38 -0
- package/dist/provider-retry-BUoezuw8.js +79 -0
- package/dist/sanitize-unicode-C3Ec8oL6.js +26 -0
- package/dist/sealedChannel-BeWNTWys.js +27 -0
- package/dist/server-AbXyhXlY.js +217 -0
- package/dist/server-B6dqQoh2.js +1518 -0
- package/dist/server-BIHo9TFu.js +505 -0
- package/dist/{server-BZh1ZXz_.js → server-BJ7DNzCp.js} +8 -19
- package/dist/server-BO-j_GbD.js +15106 -0
- package/dist/{server-D4W7EdJY.js → server-BQzAiMns.js} +16 -16
- package/dist/server-BR7SZtj7.js +3125 -0
- package/dist/{server-BE6VqEiA.js → server-BT2ORK83.js} +20 -12
- package/dist/server-BbSHYRnY.js +295 -0
- package/dist/server-BqoKlEGk.js +1806 -0
- package/dist/{server-tvgQ99rv.js → server-Busl0pQI.js} +370 -120
- package/dist/server-CIHM4jqu.js +1116 -0
- package/dist/server-CgWSSdvd.js +576 -0
- package/dist/{server-Dpgh8PDh.js → server-Co_UWKrR.js} +14 -5
- package/dist/{server-BAAL9-NA.js → server-CuEPb7u-.js} +3 -10
- package/dist/{server-Dt4y1rZD.js → server-D40q2Jpx.js} +47 -27
- package/dist/server-DCyf2Asb.js +679 -0
- package/dist/server-DH7PfLln.js +148 -0
- package/dist/server-DJ8bc89M.js +934 -0
- package/dist/server-DYdp0W9v.js +489 -0
- package/dist/server-DsdPEYGu.js +639 -0
- package/dist/server-DymH4Ucq.js +189 -0
- package/dist/server-IqECnUrb.js +834 -0
- package/dist/{server-36iuA3MI.js → server-KBgW77zh.js} +3 -3
- package/dist/server-RW_9R3R3.js +1522 -0
- package/dist/server-aUit8j6r.js +1028 -0
- package/dist/{server-DJAanjoI.js → server-gifRriZK.js} +491 -103
- package/dist/server-nkUlqnAL.js +2658 -0
- package/dist/server-oxyEbv1a.js +1256 -0
- package/dist/{server-D8ndq0wL.js → server-ub3s16Mc.js} +11 -9
- package/dist/{build-2gFaVEfG.js → serverPlugin-CELT6P0Q.js} +3946 -3
- package/dist/{sessionConfig-rBQgzXlT.js → sessionConfig-RQGvfm6E.js} +550 -760
- package/dist/simple-options-CFzI5Pd_.js +156 -0
- package/dist/streaming-json-BWTHTwz-.js +858 -0
- package/dist/system-one-shared-CiIrx29d.js +132 -0
- package/dist/{notification-D76PSL7r.js → telemetry-Csv1ZxAn.js} +1 -92
- package/dist/transform-messages-D77af7Bx.js +356 -0
- package/dist/truncate-M3KbFyVj.js +89 -0
- package/dist/{server-A-_GFpPr.js → type-ASYnCGVW.js} +10 -1031
- package/dist/typesafe-system-one-DGxeggJh.js +37 -0
- package/dist/uuid-B0QJx6Kr.js +31 -0
- package/dist/{validation-D77NZBrx.js → validation-BJxVSAwx.js} +8 -3
- package/dist/{value-Djvc2foV.js → value-_W31So3B.js} +1 -1
- package/dist/vaultSettings-Di3n5YIg.js +328 -0
- package/dist/voiceTools-RMn4HvWo.js +246 -0
- package/dist/web-DCP7ELJj.js +3 -0
- package/dist/worker.js +95288 -49863
- package/dist/workflow-B7qx0Vv9.js +79 -0
- package/package.json +37 -22
- package/wrangler.jsonc +4 -2
- package/dist/assets/assets/channel-CMrEzemr.js +0 -2
- package/dist/assets/assets/chunk-XXDRQBXY-CFf0S6bN.js +0 -2
- package/dist/assets/assets/flowDiagram-IUGLLWBU-BhGbWVf0.js +0 -1
- package/dist/assets/assets/index-Bx_K4Joy.js +0 -155
- package/dist/assets/assets/index-DZM68mTk.css +0 -1
- package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-q91tR8ri.js +0 -9
- package/dist/contextProjection-DVP2Vc5j.js +0 -188
- package/dist/harnessState-gmzJcPGt.js +0 -88
- package/dist/harnessStore-BiH9vSuD.js +0 -1
- package/dist/index.edge-BgSx_gRO.js +0 -45
- package/dist/majorModes-BvWNqoHt.js +0 -1
- package/dist/piSettings-B6fsgIBA.js +0 -1
- package/dist/platform-B4AAgwJ0.js +0 -16
- package/dist/platformFiles-C_bXo4Ig.js +0 -39
- package/dist/server-BZaPPoQp.js +0 -592
- package/dist/server-D75MWDhB.js +0 -118
- package/dist/server-r358hzQg.js +0 -280
- package/dist/serverPlugin-BOI6c6s5.js +0 -3393
|
@@ -0,0 +1,1518 @@
|
|
|
1
|
+
import { S as PO_CONFIG_SERVICE, v as composeServerProviderOverrides } from "./serverPlugin-CELT6P0Q.js";
|
|
2
|
+
import { n as DEFAULT_COMPACTION_POLICY } from "./agent-DZ-OKOHn.js";
|
|
3
|
+
import { S as loadPoConfig } from "./sessionConfig-RQGvfm6E.js";
|
|
4
|
+
import "./exports-nV43ShA7.js";
|
|
5
|
+
import { a as defineHook, c as defineRoot, h as defineServerPlugin, n as composeRootInjects, t as composeRootHooks } from "./extensionFile-DNM4xsje.js";
|
|
6
|
+
import { t as createPoTelemetry } from "./index.edge-ChYa2LU4.js";
|
|
7
|
+
import { a as readArtifactBytes, c as ArtifactAccessError, i as openArtifact, l as artifactRoot, o as removeArtifact, p as COMPACTION_ARTIFACT_DIRECTORY, r as listArtifacts, s as writeArtifactText } from "./index.edge-Xa5LLtxz.js";
|
|
8
|
+
import "./artifactFiles-DLCReI0-.js";
|
|
9
|
+
import { t as minimatch } from "./esm-BKJy3O9-.js";
|
|
10
|
+
//#region ../../core/po-core/src/schemas/contextContributions.ts
|
|
11
|
+
/** Session-scoped broker for bounded context rendered by optional Po packages. */
|
|
12
|
+
const PO_CONTEXT_CONTRIBUTIONS_SERVICE = "po/context-contributions";
|
|
13
|
+
function readPoContextContributions(context) {
|
|
14
|
+
return context.get(PO_CONTEXT_CONTRIBUTIONS_SERVICE);
|
|
15
|
+
}
|
|
16
|
+
function requirePoContextContributions(context) {
|
|
17
|
+
const service = readPoContextContributions(context);
|
|
18
|
+
if (!service) throw new Error("Po context contributions are unavailable. Start a Po session first.");
|
|
19
|
+
return service;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region ../../default/po-autocompact/src/services/admittedModes/index.edge.ts
|
|
23
|
+
/**
|
|
24
|
+
* An edge host has no config files for autocompact to read, so its settings come from the snapshot the host
|
|
25
|
+
* admitted as `po/config`. Each call reads the service's current snapshot, because a settings save replaces it,
|
|
26
|
+
* and throws while the host has admitted none or after its provider unloads.
|
|
27
|
+
*/
|
|
28
|
+
function admittedModes(context) {
|
|
29
|
+
let settings;
|
|
30
|
+
context.inject([PO_CONFIG_SERVICE], (scoped) => {
|
|
31
|
+
const config = scoped.get(PO_CONFIG_SERVICE);
|
|
32
|
+
settings = config ? () => config.getSnapshot().settings : void 0;
|
|
33
|
+
return () => {
|
|
34
|
+
settings = void 0;
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
return () => {
|
|
38
|
+
if (!settings) throw new Error("Autocompact requires injected session configuration.");
|
|
39
|
+
return settings().modes;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region ../../default/po-autocompact/src/services/autocompactTelemetry/index.ts
|
|
44
|
+
const SERVICE_NAME = "po-autocompact";
|
|
45
|
+
const PACKAGE_NAME = "@agimon-ai/po-autocompact";
|
|
46
|
+
const AUTOCOMPACT_EVENT = {
|
|
47
|
+
checkpointStarted: "po_autocompact.checkpoint_started",
|
|
48
|
+
checkpointCompleted: "po_autocompact.checkpoint_completed",
|
|
49
|
+
checkpointFailed: "po_autocompact.checkpoint_failed",
|
|
50
|
+
checkpointInvalid: "po_autocompact.checkpoint_invalid",
|
|
51
|
+
configurationLoadFailed: "po_autocompact.configuration_load_failed",
|
|
52
|
+
contextContributionDegraded: "po_autocompact.context_contribution_degraded",
|
|
53
|
+
contextCommitted: "po_autocompact.context_committed",
|
|
54
|
+
contextApplied: "po_autocompact.context_applied",
|
|
55
|
+
contextMarkerInvalid: "po_autocompact.context_marker_invalid",
|
|
56
|
+
contextHookSlow: "po_autocompact.context_hook_slow",
|
|
57
|
+
nativeCompactionCompleted: "po_autocompact.native_compaction_completed",
|
|
58
|
+
historyWriteFailed: "po_autocompact.history_write_failed"
|
|
59
|
+
};
|
|
60
|
+
function createAutocompactTelemetry(options = {}) {
|
|
61
|
+
const telemetry = createPoTelemetry({
|
|
62
|
+
serviceName: SERVICE_NAME,
|
|
63
|
+
packageName: PACKAGE_NAME,
|
|
64
|
+
cwd: options.cwd,
|
|
65
|
+
workspaceRoot: options.workspaceRoot,
|
|
66
|
+
env: options.env,
|
|
67
|
+
telemetryFactory: options.telemetryFactory,
|
|
68
|
+
warn: options.warn,
|
|
69
|
+
enableLogs: true,
|
|
70
|
+
enableTraces: true
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
recordError: (event, error, attributes, errorOptions) => telemetry.recordError(event, error, attributes, errorOptions),
|
|
74
|
+
recordWarning: (event, error, attributes) => telemetry.recordWarning(event, error, attributes),
|
|
75
|
+
recordEvent: (event, attributes) => telemetry.recordEvent(event, attributes),
|
|
76
|
+
runInSpan: (name, attributes, callback) => telemetry.runInSpan(name, attributes, callback),
|
|
77
|
+
flush: () => telemetry.flush(),
|
|
78
|
+
shutdown: () => telemetry.shutdown()
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region ../../core/po-core/src/schemas/uiHub.ts
|
|
83
|
+
/** The application-scoped UI aggregation service owned by po-ui. */
|
|
84
|
+
const PO_UI_HUB_SERVICE = "po/ui-hub";
|
|
85
|
+
function readPoUiHub(context) {
|
|
86
|
+
return context.get(PO_UI_HUB_SERVICE);
|
|
87
|
+
}
|
|
88
|
+
function requirePoUiHub(context) {
|
|
89
|
+
const hub = readPoUiHub(context);
|
|
90
|
+
if (!hub) throw new Error("Po UI hub is unavailable. Load @agimon-ai/po-ui.");
|
|
91
|
+
return hub;
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region ../../default/po-autocompact/src/constants/autocompact.ts
|
|
95
|
+
const STATE_CUSTOM_TYPE = "po-autocompact-state";
|
|
96
|
+
const CHECKPOINT_MESSAGE_TYPE = "po-autocompact-checkpoint";
|
|
97
|
+
const CONTEXT_MESSAGE_TYPE = "po-autocompact-context";
|
|
98
|
+
const RESUME_MESSAGE_TYPE = "po-autocompact-resume";
|
|
99
|
+
const RUNTIME_STATE_MESSAGE_TYPE = "po-autocompact-runtime-state";
|
|
100
|
+
const COMPACTION_THRESHOLDS = {
|
|
101
|
+
1: {
|
|
102
|
+
ratio: .5,
|
|
103
|
+
capTokens: 2e5
|
|
104
|
+
},
|
|
105
|
+
2: {
|
|
106
|
+
ratio: .75,
|
|
107
|
+
capTokens: 5e5
|
|
108
|
+
},
|
|
109
|
+
3: {
|
|
110
|
+
ratio: .95,
|
|
111
|
+
capTokens: 8e5
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const CHECKPOINT_HEADINGS = [
|
|
115
|
+
"## Goal",
|
|
116
|
+
"## Constraints & Preferences",
|
|
117
|
+
"## Progress",
|
|
118
|
+
"### Done",
|
|
119
|
+
"### In Progress",
|
|
120
|
+
"### Blocked",
|
|
121
|
+
"## Key Decisions",
|
|
122
|
+
"## Next Steps",
|
|
123
|
+
"## Critical Context"
|
|
124
|
+
];
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region ../../default/po-autocompact/src/constants/runtime.ts
|
|
127
|
+
const PLAN_DOCUMENT_ENTRY = "agent-harness-plan-document";
|
|
128
|
+
const FOOTER_SOURCE = "po-autocompact";
|
|
129
|
+
const STATUS_KEY = "po-autocompact";
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region ../../default/po-autocompact/src/services/autocompactRuntime/index.ts
|
|
132
|
+
function errorMessage(error) {
|
|
133
|
+
return error instanceof Error ? error.message : String(error);
|
|
134
|
+
}
|
|
135
|
+
function latestPlanSnapshot(branch) {
|
|
136
|
+
for (const entry of branch.toReversed()) {
|
|
137
|
+
if (entry.type !== "custom" || entry.customType !== "agent-harness-plan-document") continue;
|
|
138
|
+
if (!entry.data || typeof entry.data !== "object") return void 0;
|
|
139
|
+
const data = entry.data;
|
|
140
|
+
if (typeof data.content !== "string" || typeof data.path !== "string") return void 0;
|
|
141
|
+
return {
|
|
142
|
+
content: data.content,
|
|
143
|
+
path: data.path
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const EMPTY_CONTEXT_CONTRIBUTIONS = Object.freeze({
|
|
148
|
+
entries: Object.freeze([]),
|
|
149
|
+
errors: Object.freeze([])
|
|
150
|
+
});
|
|
151
|
+
function readContextContributionsSnapshot(service) {
|
|
152
|
+
if (!service) return EMPTY_CONTEXT_CONTRIBUTIONS;
|
|
153
|
+
try {
|
|
154
|
+
return service.snapshot();
|
|
155
|
+
} catch (error) {
|
|
156
|
+
return {
|
|
157
|
+
entries: [],
|
|
158
|
+
errors: [{
|
|
159
|
+
source: PO_CONTEXT_CONTRIBUTIONS_SERVICE,
|
|
160
|
+
id: "service-snapshot",
|
|
161
|
+
label: "Context contributions",
|
|
162
|
+
order: 0,
|
|
163
|
+
message: errorMessage(error)
|
|
164
|
+
}]
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function formatContextContributions(snapshot) {
|
|
169
|
+
const sections = snapshot.entries.map((entry) => `### ${entry.label}\n${entry.text}`);
|
|
170
|
+
sections.push(...snapshot.errors.map((error) => `### ${error.label}\n(unavailable: ${error.message})`));
|
|
171
|
+
return sections.length > 0 ? sections.join("\n\n") : "(no registered context contributions)";
|
|
172
|
+
}
|
|
173
|
+
function runtimeStateSnapshot(branch, contextContributions) {
|
|
174
|
+
const plan = latestPlanSnapshot(branch);
|
|
175
|
+
return {
|
|
176
|
+
...plan ? { planPath: plan.path } : {},
|
|
177
|
+
contributions: contextContributions.entries,
|
|
178
|
+
contributionErrors: contextContributions.errors
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function formatRuntimeState(snapshot) {
|
|
182
|
+
return `<compaction-runtime-state>
|
|
183
|
+
Authoritative runtime state captured when compaction committed. Use it to resume coordination without reconstructing state from the summary.
|
|
184
|
+
<active-plan>
|
|
185
|
+
${snapshot.planPath ? `Source: ${snapshot.planPath}\nExact plan content is restored separately by Po Plan.` : "(no active plan document)"}
|
|
186
|
+
</active-plan>
|
|
187
|
+
<context-contributions>
|
|
188
|
+
${formatContextContributions({
|
|
189
|
+
entries: snapshot.contributions,
|
|
190
|
+
errors: snapshot.contributionErrors
|
|
191
|
+
})}
|
|
192
|
+
</context-contributions>
|
|
193
|
+
</compaction-runtime-state>`;
|
|
194
|
+
}
|
|
195
|
+
function steeringEnvelope(snapshot) {
|
|
196
|
+
const plan = snapshot.plan ? `Source: ${snapshot.plan.path}\n\n${snapshot.plan.content}` : "(no active plan document)";
|
|
197
|
+
const importantContext = [snapshot.readFiles.length > 0 ? `Read files: ${snapshot.readFiles.join(", ")}` : void 0, snapshot.modifiedFiles.length > 0 ? `Modified files: ${snapshot.modifiedFiles.join(", ")}` : void 0].filter((value) => Boolean(value));
|
|
198
|
+
return `<compaction-steering priority="user,plan,context-contributions,important-context,recent-messages">
|
|
199
|
+
<user-prompt source="conversation">
|
|
200
|
+
Treat the user's explicit goals, constraints, corrections, and preferences in the conversation as authoritative. Newer user instructions override older ones.
|
|
201
|
+
</user-prompt>
|
|
202
|
+
<active-plan>
|
|
203
|
+
${plan}
|
|
204
|
+
</active-plan>
|
|
205
|
+
<context-contributions>
|
|
206
|
+
${formatContextContributions(snapshot.contextContributions)}
|
|
207
|
+
</context-contributions>
|
|
208
|
+
<important-context>
|
|
209
|
+
${importantContext.length > 0 ? importantContext.join("\n") : "(none recorded outside the conversation)"}
|
|
210
|
+
</important-context>
|
|
211
|
+
</compaction-steering>`;
|
|
212
|
+
}
|
|
213
|
+
function checkpointInstructions(pass, steering) {
|
|
214
|
+
const decision = pass === 2 ? "Start with exactly <shouldCompact>true</shouldCompact> or <shouldCompact>false</shouldCompact>. Use true when the staged summary safely retains the important parent context. Use false only when it is not yet sufficient for safe compaction.\n\n" : "";
|
|
215
|
+
return `Create Po autocompact checkpoint pass ${pass}.
|
|
216
|
+
|
|
217
|
+
${steeringEnvelope(steering)}
|
|
218
|
+
|
|
219
|
+
Apply the steering evidence in priority order. Do not invent plan or contributed runtime state. Preserve verified facts and mark unresolved inference explicitly. Newer evidence replaces superseded information.
|
|
220
|
+
|
|
221
|
+
${decision}Return only the decision tag when required, followed by a concise structured checkpoint using every heading below. Keep exact goals, constraints, decisions, blockers, commands, errors, file paths, validation evidence, and the immediate next action. Separate verified facts from unresolved inference.
|
|
222
|
+
|
|
223
|
+
## Goal
|
|
224
|
+
## Constraints & Preferences
|
|
225
|
+
## Progress
|
|
226
|
+
### Done
|
|
227
|
+
### In Progress
|
|
228
|
+
### Blocked
|
|
229
|
+
## Key Decisions
|
|
230
|
+
## Next Steps
|
|
231
|
+
## Critical Context`;
|
|
232
|
+
}
|
|
233
|
+
const DEFAULT_RUNTIME_CONFIG = {
|
|
234
|
+
enabled: true,
|
|
235
|
+
ratios: {},
|
|
236
|
+
overrides: []
|
|
237
|
+
};
|
|
238
|
+
/** While admitted settings cannot be read a disable could be hidden, so autocompact stands down for the host. */
|
|
239
|
+
const UNAVAILABLE_RUNTIME_CONFIG = {
|
|
240
|
+
enabled: false,
|
|
241
|
+
ratios: {},
|
|
242
|
+
overrides: []
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* What the Po config says about this package.
|
|
246
|
+
*
|
|
247
|
+
* `modes.autocompact` is read first and `modes.planning.subagents` is the
|
|
248
|
+
* fallback, because summarization borrowed the planning subagent model before
|
|
249
|
+
* it had keys of its own and existing files still spell it that way.
|
|
250
|
+
*
|
|
251
|
+
* A host that admits its configuration passes `admitted`, and that is read instead of the files. Reading it
|
|
252
|
+
* failing is reported and stands autocompact down, where unreadable files keep the session model and stay on.
|
|
253
|
+
*/
|
|
254
|
+
function autocompactRuntimeConfig(root, onLoadFailure, admitted) {
|
|
255
|
+
let modes;
|
|
256
|
+
try {
|
|
257
|
+
modes = admitted ? admitted() : loadPoConfig(root).modes;
|
|
258
|
+
} catch (error) {
|
|
259
|
+
if (admitted) {
|
|
260
|
+
onLoadFailure?.(error);
|
|
261
|
+
return UNAVAILABLE_RUNTIME_CONFIG;
|
|
262
|
+
}
|
|
263
|
+
process.emitWarning("Po autocompact configuration could not be loaded; using the active session model instead.");
|
|
264
|
+
onLoadFailure?.(error);
|
|
265
|
+
return DEFAULT_RUNTIME_CONFIG;
|
|
266
|
+
}
|
|
267
|
+
const configured = modes?.autocompact;
|
|
268
|
+
const agent = (configured && (configured.model !== void 0 || configured.thinking !== void 0) ? {
|
|
269
|
+
...configured.model ? { model: configured.model } : {},
|
|
270
|
+
...configured.thinking ? { thinking: configured.thinking } : {}
|
|
271
|
+
} : void 0) ?? modes?.planning?.subagents;
|
|
272
|
+
const thresholds = configured?.thresholds;
|
|
273
|
+
return {
|
|
274
|
+
enabled: configured?.enabled ?? true,
|
|
275
|
+
...agent ? { agent } : {},
|
|
276
|
+
ratios: {
|
|
277
|
+
...thresholds?.pass1 === void 0 ? {} : { 1: thresholds.pass1 },
|
|
278
|
+
...thresholds?.pass2 === void 0 ? {} : { 2: thresholds.pass2 },
|
|
279
|
+
...thresholds?.pass3 === void 0 ? {} : { 3: thresholds.pass3 }
|
|
280
|
+
},
|
|
281
|
+
overrides: configured?.overrides ?? []
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region ../../default/po-autocompact/src/services/compactionPolicy/index.ts
|
|
286
|
+
function customMessage(entry) {
|
|
287
|
+
if (entry.type === "custom_message") return entry;
|
|
288
|
+
if (entry.type === "message" && entry.message.role === "custom") return entry.message;
|
|
289
|
+
}
|
|
290
|
+
const SHOULD_COMPACT_PATTERN = /<shouldCompact>\s*(true|false)\s*<\/shouldCompact>/i;
|
|
291
|
+
const FILE_SECTION_PATTERN = /\n*<(?:read-files|modified-files)>[\s\S]*?<\/(?:read-files|modified-files)>/g;
|
|
292
|
+
function isRecord(value) {
|
|
293
|
+
return typeof value === "object" && value !== null;
|
|
294
|
+
}
|
|
295
|
+
function isStringArray(value) {
|
|
296
|
+
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
297
|
+
}
|
|
298
|
+
function isPass(value) {
|
|
299
|
+
return value === 1 || value === 2 || value === 3;
|
|
300
|
+
}
|
|
301
|
+
function assistantText(entry) {
|
|
302
|
+
if (entry.type !== "message" || entry.message.role !== "assistant") return void 0;
|
|
303
|
+
return entry.message.content.filter((block) => block.type === "text").map((block) => block.text).join("\n").trim() || void 0;
|
|
304
|
+
}
|
|
305
|
+
function isAutocompactMessage(value) {
|
|
306
|
+
return isRecord(value) && typeof value.role === "string";
|
|
307
|
+
}
|
|
308
|
+
function contextDetailsFromUnknown(value) {
|
|
309
|
+
if (!isRecord(value) || !isStringArray(value.readFiles) || !isStringArray(value.modifiedFiles)) return void 0;
|
|
310
|
+
if (!Array.isArray(value.retainedMessages) || !value.retainedMessages.every(isAutocompactMessage)) return void 0;
|
|
311
|
+
if (!isRecord(value.poAutocompact)) return void 0;
|
|
312
|
+
const marker = value.poAutocompact;
|
|
313
|
+
if (marker.version !== 2 || marker.pass !== 2 && marker.pass !== 3 || typeof marker.cycle !== "number" || typeof marker.requestId !== "string" || typeof marker.snapshotLeafId !== "string" || typeof marker.tokensBefore !== "number") return void 0;
|
|
314
|
+
return {
|
|
315
|
+
readFiles: [...value.readFiles],
|
|
316
|
+
modifiedFiles: [...value.modifiedFiles],
|
|
317
|
+
retainedMessages: [...value.retainedMessages],
|
|
318
|
+
poAutocompact: {
|
|
319
|
+
version: 2,
|
|
320
|
+
cycle: marker.cycle,
|
|
321
|
+
pass: marker.pass,
|
|
322
|
+
requestId: marker.requestId,
|
|
323
|
+
snapshotLeafId: marker.snapshotLeafId,
|
|
324
|
+
tokensBefore: marker.tokensBefore
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function createInitialState() {
|
|
329
|
+
return {
|
|
330
|
+
version: 2,
|
|
331
|
+
cycle: 1,
|
|
332
|
+
pass: 1,
|
|
333
|
+
phase: "waiting",
|
|
334
|
+
checkpointQueue: [],
|
|
335
|
+
exhaustedPasses: [],
|
|
336
|
+
invalidAttempts: 0,
|
|
337
|
+
baselineTokens: 0,
|
|
338
|
+
baselinePending: false,
|
|
339
|
+
readFiles: [],
|
|
340
|
+
modifiedFiles: []
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* The ratios each pass fires at, with configured values folded in.
|
|
345
|
+
*
|
|
346
|
+
* The ladder only works if it climbs, so a configured pass never sits below the
|
|
347
|
+
* one before it: a file that says pass 2 fires earlier than pass 1 gets pass 1's
|
|
348
|
+
* ratio for pass 2 rather than a pass that can never contribute.
|
|
349
|
+
*/
|
|
350
|
+
function compactionRatios(configured = {}) {
|
|
351
|
+
let previous = 0;
|
|
352
|
+
const ratios = {};
|
|
353
|
+
for (const pass of [
|
|
354
|
+
1,
|
|
355
|
+
2,
|
|
356
|
+
3
|
|
357
|
+
]) {
|
|
358
|
+
const ratio = Math.max(configured[pass] ?? COMPACTION_THRESHOLDS[pass].ratio, previous);
|
|
359
|
+
ratios[pass] = ratio;
|
|
360
|
+
previous = ratio;
|
|
361
|
+
}
|
|
362
|
+
return ratios;
|
|
363
|
+
}
|
|
364
|
+
function thresholdTokens(pass, contextWindow, baselineTokens = 0, configured = {}) {
|
|
365
|
+
const threshold = COMPACTION_THRESHOLDS[pass];
|
|
366
|
+
const ratio = compactionRatios(configured)[pass];
|
|
367
|
+
const baseline = Math.max(0, Math.min(baselineTokens, contextWindow));
|
|
368
|
+
const remaining = contextWindow - baseline;
|
|
369
|
+
const staged = baseline + Math.min(Math.floor(remaining * ratio), threshold.capTokens);
|
|
370
|
+
const nativeTrigger = contextWindow - DEFAULT_COMPACTION_POLICY.reserveTokens;
|
|
371
|
+
return nativeTrigger > baseline ? Math.min(staged, nativeTrigger) : staged;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Where every pass fires, with a matching model's absolute token checkpoints folded in.
|
|
375
|
+
*
|
|
376
|
+
* A configured token count replaces the ratio only when it fires earlier, so an
|
|
377
|
+
* override can bring a checkpoint forward on a very large window without ever
|
|
378
|
+
* pushing one past the point Pi compacts natively.
|
|
379
|
+
*
|
|
380
|
+
* Two rules keep the ladder usable. A token count at or below the baseline is
|
|
381
|
+
* ignored, because a compaction that lands above it would otherwise satisfy that
|
|
382
|
+
* pass the moment the next cycle opens and re-fire it every turn. And a pass never
|
|
383
|
+
* sits below the one before it, for the same reason {@link compactionRatios}
|
|
384
|
+
* climbs: `evaluateUsage` skips any pass below the one already reached, so a later
|
|
385
|
+
* pass that fires first does not merely reorder the ladder, it locks the earlier
|
|
386
|
+
* passes out of the cycle and forces compaction with no summary ever written.
|
|
387
|
+
*/
|
|
388
|
+
function effectiveThresholds(contextWindow, baselineTokens = 0, configured = {}, tokenOverrides = {}) {
|
|
389
|
+
let previous = 0;
|
|
390
|
+
const thresholds = {};
|
|
391
|
+
for (const pass of [
|
|
392
|
+
1,
|
|
393
|
+
2,
|
|
394
|
+
3
|
|
395
|
+
]) {
|
|
396
|
+
const ratioTokens = thresholdTokens(pass, contextWindow, baselineTokens, configured);
|
|
397
|
+
const absolute = tokenOverrides[pass];
|
|
398
|
+
thresholds[pass] = Math.max(absolute !== void 0 && absolute > baselineTokens ? Math.min(ratioTokens, absolute) : ratioTokens, previous);
|
|
399
|
+
previous = thresholds[pass];
|
|
400
|
+
}
|
|
401
|
+
return thresholds;
|
|
402
|
+
}
|
|
403
|
+
function latestCheckpointArtifactEntry(branchEntries) {
|
|
404
|
+
return branchEntries.findLast((entry) => entry.type === "compaction" || entry.type === "custom" && entry.customType === "po-autocompact-checkpoint" || customMessage(entry)?.customType === "po-autocompact-checkpoint" || customMessage(entry)?.customType === "po-autocompact-context");
|
|
405
|
+
}
|
|
406
|
+
function baselineUsageIsSettled(branchEntries) {
|
|
407
|
+
const boundaryIndex = branchEntries.findLastIndex((entry) => entry.type === "compaction" || customMessage(entry)?.customType === "po-autocompact-context");
|
|
408
|
+
return branchEntries.slice(boundaryIndex + 1).some((entry) => {
|
|
409
|
+
if (entry.type !== "message" || entry.message.role !== "assistant") return false;
|
|
410
|
+
const { stopReason, usage } = entry.message;
|
|
411
|
+
if (stopReason === "aborted" || stopReason === "error" || !usage) return false;
|
|
412
|
+
return (usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite) > 0;
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
function projectContextMessages(messages, branchEntries) {
|
|
416
|
+
const nativeCompactionIndex = branchEntries.findLastIndex((entry) => entry.type === "compaction");
|
|
417
|
+
const markerEntry = branchEntries.slice(nativeCompactionIndex + 1).findLast((entry) => customMessage(entry)?.customType === CONTEXT_MESSAGE_TYPE);
|
|
418
|
+
const markerMessage = markerEntry && customMessage(markerEntry);
|
|
419
|
+
if (!markerEntry || !markerMessage) return {
|
|
420
|
+
messages,
|
|
421
|
+
retainedMessageCount: 0
|
|
422
|
+
};
|
|
423
|
+
const details = contextDetailsFromUnknown(markerMessage.details);
|
|
424
|
+
const summary = checkpointSummaryFromEntry(markerEntry);
|
|
425
|
+
if (!details || !summary) return {
|
|
426
|
+
messages,
|
|
427
|
+
invalidMarker: true,
|
|
428
|
+
retainedMessageCount: 0
|
|
429
|
+
};
|
|
430
|
+
const markerMessageIndex = messages.findLastIndex((message) => message.role === "custom" && message.customType === "po-autocompact-context" && contextDetailsFromUnknown(message.details)?.poAutocompact.requestId === details.poAutocompact.requestId);
|
|
431
|
+
if (markerMessageIndex === -1) return {
|
|
432
|
+
messages,
|
|
433
|
+
invalidMarker: true,
|
|
434
|
+
retainedMessageCount: 0
|
|
435
|
+
};
|
|
436
|
+
return {
|
|
437
|
+
messages: [
|
|
438
|
+
{
|
|
439
|
+
role: "compactionSummary",
|
|
440
|
+
summary,
|
|
441
|
+
tokensBefore: details.poAutocompact.tokensBefore,
|
|
442
|
+
timestamp: messages[markerMessageIndex]?.timestamp ?? Date.now()
|
|
443
|
+
},
|
|
444
|
+
...details.retainedMessages,
|
|
445
|
+
...messages.slice(markerMessageIndex + 1)
|
|
446
|
+
],
|
|
447
|
+
marker: details.poAutocompact,
|
|
448
|
+
retainedMessageCount: details.retainedMessages.length
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
function fileOperationsFromMessages(messages) {
|
|
452
|
+
const fileOps = {
|
|
453
|
+
read: /* @__PURE__ */ new Set(),
|
|
454
|
+
written: /* @__PURE__ */ new Set(),
|
|
455
|
+
edited: /* @__PURE__ */ new Set()
|
|
456
|
+
};
|
|
457
|
+
for (const message of messages) {
|
|
458
|
+
if (message.role !== "assistant") continue;
|
|
459
|
+
for (const block of message.content) {
|
|
460
|
+
if (block.type !== "toolCall") continue;
|
|
461
|
+
const path = typeof block.arguments.path === "string" ? block.arguments.path : void 0;
|
|
462
|
+
if (!path) continue;
|
|
463
|
+
if (block.name === "read") fileOps.read.add(path);
|
|
464
|
+
else if (block.name === "write") fileOps.written.add(path);
|
|
465
|
+
else if (block.name === "edit") fileOps.edited.add(path);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return fileOps;
|
|
469
|
+
}
|
|
470
|
+
function parseState(value) {
|
|
471
|
+
if (!isRecord(value)) return void 0;
|
|
472
|
+
if (value.version !== 2 || typeof value.cycle !== "number" || !isPass(value.pass)) return void 0;
|
|
473
|
+
if (value.phase !== "waiting" && value.phase !== "checkpoint_pending" && value.phase !== "checkpoint_ready" && value.phase !== "compacting") return void 0;
|
|
474
|
+
const baselineTokens = value.baselineTokens ?? 0;
|
|
475
|
+
if (typeof baselineTokens !== "number" || baselineTokens < 0) return void 0;
|
|
476
|
+
const baselinePending = value.baselinePending ?? false;
|
|
477
|
+
if (typeof baselinePending !== "boolean") return void 0;
|
|
478
|
+
const checkpointQueue = value.checkpointQueue ?? [];
|
|
479
|
+
if (!Array.isArray(checkpointQueue) || !checkpointQueue.every(isPass) || checkpointQueue.some((pass, index) => index > 0 && pass <= checkpointQueue[index - 1])) return void 0;
|
|
480
|
+
const exhaustedPasses = value.exhaustedPasses ?? [];
|
|
481
|
+
if (!Array.isArray(exhaustedPasses) || !exhaustedPasses.every(isPass)) return void 0;
|
|
482
|
+
const invalidAttempts = value.invalidAttempts ?? 0;
|
|
483
|
+
if (typeof invalidAttempts !== "number" || invalidAttempts < 0) return void 0;
|
|
484
|
+
if (!isStringArray(value.readFiles) || !isStringArray(value.modifiedFiles)) return void 0;
|
|
485
|
+
if (value.requestId !== void 0 && typeof value.requestId !== "string") return void 0;
|
|
486
|
+
if (value.compactionPass !== void 0 && value.compactionPass !== 2 && value.compactionPass !== 3) return void 0;
|
|
487
|
+
if ("latestCheckpointEntryId" in value) return void 0;
|
|
488
|
+
if (value.latestCheckpointSnapshotLeafId !== void 0 && typeof value.latestCheckpointSnapshotLeafId !== "string") return void 0;
|
|
489
|
+
if (value.lastAttemptLeafId !== void 0 && typeof value.lastAttemptLeafId !== "string") return void 0;
|
|
490
|
+
if (value.snapshotLeafId !== void 0 && typeof value.snapshotLeafId !== "string") return void 0;
|
|
491
|
+
if (value.snapshotTokens !== void 0 && (typeof value.snapshotTokens !== "number" || value.snapshotTokens < 0)) return void 0;
|
|
492
|
+
if (value.pendingCheckpoint !== void 0 && typeof value.pendingCheckpoint !== "string") return void 0;
|
|
493
|
+
return {
|
|
494
|
+
version: 2,
|
|
495
|
+
cycle: value.cycle,
|
|
496
|
+
pass: value.pass,
|
|
497
|
+
phase: value.phase,
|
|
498
|
+
checkpointQueue: [...checkpointQueue],
|
|
499
|
+
exhaustedPasses: [...exhaustedPasses],
|
|
500
|
+
invalidAttempts,
|
|
501
|
+
baselineTokens,
|
|
502
|
+
baselinePending,
|
|
503
|
+
readFiles: [...value.readFiles],
|
|
504
|
+
modifiedFiles: [...value.modifiedFiles],
|
|
505
|
+
...value.requestId ? { requestId: value.requestId } : {},
|
|
506
|
+
...value.compactionPass ? { compactionPass: value.compactionPass } : {},
|
|
507
|
+
...value.latestCheckpointSnapshotLeafId ? { latestCheckpointSnapshotLeafId: value.latestCheckpointSnapshotLeafId } : {},
|
|
508
|
+
...value.lastAttemptLeafId ? { lastAttemptLeafId: value.lastAttemptLeafId } : {},
|
|
509
|
+
...value.snapshotLeafId ? { snapshotLeafId: value.snapshotLeafId } : {},
|
|
510
|
+
...value.snapshotTokens !== void 0 ? { snapshotTokens: value.snapshotTokens } : {},
|
|
511
|
+
...value.pendingCheckpoint ? { pendingCheckpoint: value.pendingCheckpoint } : {}
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function checkpointSummaryFromEntry(entry) {
|
|
515
|
+
if (!entry) return void 0;
|
|
516
|
+
if (entry.type === "compaction") return entry.summary.trim() || void 0;
|
|
517
|
+
if (entry.type === "custom") return isRecord(entry.data) && typeof entry.data.summary === "string" ? entry.data.summary.trim() || void 0 : void 0;
|
|
518
|
+
const marker = customMessage(entry);
|
|
519
|
+
if (marker) return (typeof marker.content === "string" ? marker.content : marker.content.filter((block) => block.type === "text").map((block) => block.text).join("\n")).trim() || void 0;
|
|
520
|
+
return assistantText(entry);
|
|
521
|
+
}
|
|
522
|
+
function parseCheckpointDecision(response) {
|
|
523
|
+
const match = response.match(SHOULD_COMPACT_PATTERN);
|
|
524
|
+
const summary = response.replace(SHOULD_COMPACT_PATTERN, "").trim();
|
|
525
|
+
if (!match) return { summary };
|
|
526
|
+
return {
|
|
527
|
+
summary,
|
|
528
|
+
shouldCompact: match[1]?.toLowerCase() === "true"
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
function isStructuredCheckpoint(summary) {
|
|
532
|
+
return CHECKPOINT_HEADINGS.every((heading) => summary.includes(heading));
|
|
533
|
+
}
|
|
534
|
+
function createRequestId(sessionId, cycle, pass, leafId) {
|
|
535
|
+
return `${sessionId}:${cycle}:${pass}:${leafId ?? "root"}`;
|
|
536
|
+
}
|
|
537
|
+
function checkpointRequestDetails(cycle, pass, requestId) {
|
|
538
|
+
return {
|
|
539
|
+
version: 2,
|
|
540
|
+
cycle,
|
|
541
|
+
pass,
|
|
542
|
+
requestId
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
function mergeFileDetails(current, fileOps, additional) {
|
|
546
|
+
const modified = /* @__PURE__ */ new Set([
|
|
547
|
+
...current.modifiedFiles,
|
|
548
|
+
...additional?.modifiedFiles ?? [],
|
|
549
|
+
...fileOps ? [...fileOps.edited, ...fileOps.written] : []
|
|
550
|
+
]);
|
|
551
|
+
const read = /* @__PURE__ */ new Set([
|
|
552
|
+
...current.readFiles,
|
|
553
|
+
...additional?.readFiles ?? [],
|
|
554
|
+
...fileOps ? [...fileOps.read] : []
|
|
555
|
+
]);
|
|
556
|
+
for (const path of modified) read.delete(path);
|
|
557
|
+
const recent = (paths) => [...paths].slice(-500).sort();
|
|
558
|
+
return {
|
|
559
|
+
readFiles: recent(read),
|
|
560
|
+
modifiedFiles: recent(modified)
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
function fileDetailsFromUnknown(value) {
|
|
564
|
+
if (!isRecord(value) || !isStringArray(value.readFiles) || !isStringArray(value.modifiedFiles)) return void 0;
|
|
565
|
+
return {
|
|
566
|
+
readFiles: value.readFiles,
|
|
567
|
+
modifiedFiles: value.modifiedFiles
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function withCanonicalFileSections(summary, details) {
|
|
571
|
+
const sections = [];
|
|
572
|
+
if (details.readFiles.length > 0) sections.push(`<read-files>\n${details.readFiles.join("\n")}\n</read-files>`);
|
|
573
|
+
if (details.modifiedFiles.length > 0) sections.push(`<modified-files>\n${details.modifiedFiles.join("\n")}\n</modified-files>`);
|
|
574
|
+
const normalized = summary.replace(FILE_SECTION_PATTERN, "").trim();
|
|
575
|
+
return sections.length > 0 ? `${normalized}\n\n${sections.join("\n\n")}` : normalized;
|
|
576
|
+
}
|
|
577
|
+
//#endregion
|
|
578
|
+
//#region ../../default/po-autocompact/src/services/compactionHistory/index.ts
|
|
579
|
+
const FORMAT = "po-compaction/1";
|
|
580
|
+
const HEADER = `---\nformat: ${JSON.stringify(FORMAT)}\n`;
|
|
581
|
+
const HISTORY_PATH = new RegExp(`^${COMPACTION_ARTIFACT_DIRECTORY}/(?:epoch-\\d+/(?:summary|checkpoint-\\d+)|in-epoch/checkpoint-\\d+)\\.md$`);
|
|
582
|
+
const NATIVE_PREFIX = "The conversation history before this point was compacted into the following summary:\n\n<summary>\n";
|
|
583
|
+
const NATIVE_SUFFIX = "\n</summary>";
|
|
584
|
+
function historyFile(path, fields, body) {
|
|
585
|
+
const header = Object.entries({
|
|
586
|
+
format: FORMAT,
|
|
587
|
+
...fields
|
|
588
|
+
}).flatMap(([key, value]) => value === void 0 ? [] : [`${key}: ${JSON.stringify(value)}`]);
|
|
589
|
+
return {
|
|
590
|
+
path: `${COMPACTION_ARTIFACT_DIRECTORY}/${path}`,
|
|
591
|
+
text: `---\n${header.join("\n")}\n---\n\n${body}\n`
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
function isoTime(value) {
|
|
595
|
+
const time = new Date(value);
|
|
596
|
+
return Number.isFinite(time.getTime()) ? time.toISOString() : void 0;
|
|
597
|
+
}
|
|
598
|
+
function passOf(value) {
|
|
599
|
+
if (typeof value !== "object" || value === null || !("pass" in value)) return void 0;
|
|
600
|
+
return value.pass === 1 || value.pass === 2 || value.pass === 3 ? value.pass : void 0;
|
|
601
|
+
}
|
|
602
|
+
function committedFields(entry) {
|
|
603
|
+
if (entry.type === "compaction") {
|
|
604
|
+
const summary = entry.summary.trim();
|
|
605
|
+
return {
|
|
606
|
+
body: summary.startsWith(NATIVE_PREFIX) && summary.endsWith(NATIVE_SUFFIX) ? summary.slice(96, -11).trim() : summary,
|
|
607
|
+
fields: {
|
|
608
|
+
source: "compact",
|
|
609
|
+
tokensBefore: entry.tokensBefore > 0 ? entry.tokensBefore : void 0
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
const marker = customMessage(entry);
|
|
614
|
+
const details = marker?.customType === "po-autocompact-context" ? contextDetailsFromUnknown(marker.details) : void 0;
|
|
615
|
+
if (!details) return void 0;
|
|
616
|
+
return {
|
|
617
|
+
body: checkpointSummaryFromEntry(entry) ?? "",
|
|
618
|
+
fields: {
|
|
619
|
+
source: "autocompact",
|
|
620
|
+
pass: details.poAutocompact.pass,
|
|
621
|
+
tokensBefore: details.poAutocompact.tokensBefore
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
/** The only entries `wantedHistory` reads, so mirrors can scan history without keeping the rest. */
|
|
626
|
+
function isHistoryEntry(entry) {
|
|
627
|
+
const type = customMessage(entry)?.customType;
|
|
628
|
+
return entry.type === "compaction" || entry.type === "custom" && entry.customType === "po-autocompact-checkpoint" || type === "po-autocompact-checkpoint" || type === "po-autocompact-context";
|
|
629
|
+
}
|
|
630
|
+
/** Number commits along the active branch so a rewind rewrites the same epoch folders. */
|
|
631
|
+
function wantedHistory(entries) {
|
|
632
|
+
const files = [];
|
|
633
|
+
let staged = [];
|
|
634
|
+
let epoch = 1;
|
|
635
|
+
const checkpoints = (folder) => staged.map(({ entry, summary, pass }, index) => historyFile(`${folder}/checkpoint-${index + 1}.md`, {
|
|
636
|
+
kind: "checkpoint",
|
|
637
|
+
epoch,
|
|
638
|
+
checkpoint: index + 1,
|
|
639
|
+
entryId: entry.id,
|
|
640
|
+
source: "autocompact",
|
|
641
|
+
pass,
|
|
642
|
+
timestamp: isoTime(entry.timestamp)
|
|
643
|
+
}, summary));
|
|
644
|
+
for (const entry of entries) {
|
|
645
|
+
const marker = customMessage(entry);
|
|
646
|
+
if (entry.type === "custom" && entry.customType === "po-autocompact-checkpoint" || marker?.customType === "po-autocompact-checkpoint") {
|
|
647
|
+
const summary = checkpointSummaryFromEntry(entry);
|
|
648
|
+
if (summary) staged.push({
|
|
649
|
+
entry,
|
|
650
|
+
summary,
|
|
651
|
+
pass: passOf(entry.type === "custom" ? entry.data : marker?.details)
|
|
652
|
+
});
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
const committed = committedFields(entry);
|
|
656
|
+
if (!committed) continue;
|
|
657
|
+
files.push(...checkpoints(`epoch-${epoch}`), historyFile(`epoch-${epoch}/summary.md`, {
|
|
658
|
+
kind: "summary",
|
|
659
|
+
epoch,
|
|
660
|
+
entryId: entry.id,
|
|
661
|
+
...committed.fields,
|
|
662
|
+
timestamp: isoTime(entry.timestamp)
|
|
663
|
+
}, committed.body));
|
|
664
|
+
staged = [];
|
|
665
|
+
epoch += 1;
|
|
666
|
+
}
|
|
667
|
+
files.push(...checkpoints("in-epoch"));
|
|
668
|
+
return files;
|
|
669
|
+
}
|
|
670
|
+
async function ownedHistory(root, path) {
|
|
671
|
+
const file = await openArtifact(root, path).catch((error) => {
|
|
672
|
+
if (error instanceof ArtifactAccessError && error.status === 404) return void 0;
|
|
673
|
+
throw error;
|
|
674
|
+
});
|
|
675
|
+
if (!file) return false;
|
|
676
|
+
try {
|
|
677
|
+
const bytes = await readArtifactBytes(file.handle, Math.min(file.stat.size, HEADER.length));
|
|
678
|
+
return new TextDecoder().decode(bytes) === HEADER;
|
|
679
|
+
} finally {
|
|
680
|
+
await file.handle.close();
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
/** Mirror history into the session artifact folder. Pruning touches only files carrying this mirror's header. */
|
|
684
|
+
async function mirrorCompactionHistory(root, entries) {
|
|
685
|
+
const files = wantedHistory(entries);
|
|
686
|
+
if (files.length === 0) return;
|
|
687
|
+
for (const file of files) await writeArtifactText(root, file.path, file.text);
|
|
688
|
+
const listed = await listArtifacts(root);
|
|
689
|
+
if (listed.error) throw new Error(listed.error);
|
|
690
|
+
const wanted = new Set(files.map((file) => file.path));
|
|
691
|
+
const stale = listed.items.filter((item) => HISTORY_PATH.test(item.path) && !wanted.has(item.path));
|
|
692
|
+
for (const item of stale) if (await ownedHistory(root, item.path)) await removeArtifact(root, item.path);
|
|
693
|
+
for (const folder of new Set(stale.map((item) => item.path.slice(0, item.path.lastIndexOf("/"))))) await removeArtifact(root, folder);
|
|
694
|
+
}
|
|
695
|
+
//#endregion
|
|
696
|
+
//#region ../../default/po-autocompact/src/services/modelOverrides/index.ts
|
|
697
|
+
/**
|
|
698
|
+
* A pattern naming a provider is matched against `provider/id`, anything else
|
|
699
|
+
* against the bare id. `*` does not cross `/`, so a bare pattern tested against a
|
|
700
|
+
* qualified subject would never match and would read as a silently dead rule.
|
|
701
|
+
*/
|
|
702
|
+
function matchesModelPattern(pattern, model) {
|
|
703
|
+
const subject = pattern.includes("/") ? `${model.provider}/${model.id}` : model.id;
|
|
704
|
+
return minimatch(subject, pattern, { nocase: true });
|
|
705
|
+
}
|
|
706
|
+
function resolveModelTokenOverrides(model, overrides) {
|
|
707
|
+
if (!model) return {};
|
|
708
|
+
const matched = overrides.find((entry) => matchesModelPattern(entry.model, model));
|
|
709
|
+
if (!matched) return {};
|
|
710
|
+
const { pass1, pass2, pass3 } = matched.tokens;
|
|
711
|
+
return {
|
|
712
|
+
...pass1 === void 0 ? {} : { 1: pass1 },
|
|
713
|
+
...pass2 === void 0 ? {} : { 2: pass2 },
|
|
714
|
+
...pass3 === void 0 ? {} : { 3: pass3 }
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region ../../default/po-autocompact/src/services/summarizationModel/index.ts
|
|
719
|
+
const THINKING_SUFFIX_PATTERN = /:(off|minimal|low|medium|high|xhigh|max)$/;
|
|
720
|
+
/** Splits a `provider/model` reference, tolerating the optional thinking suffix. */
|
|
721
|
+
function parseModelReference(reference) {
|
|
722
|
+
const trimmed = reference.trim();
|
|
723
|
+
const thinking = THINKING_SUFFIX_PATTERN.exec(trimmed)?.[1];
|
|
724
|
+
const identity = trimmed.replace(THINKING_SUFFIX_PATTERN, "");
|
|
725
|
+
const separator = identity.indexOf("/");
|
|
726
|
+
if (separator <= 0 || separator >= identity.length - 1) return void 0;
|
|
727
|
+
return {
|
|
728
|
+
provider: identity.slice(0, separator),
|
|
729
|
+
modelId: identity.slice(separator + 1),
|
|
730
|
+
...thinking ? { thinking } : {}
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
//#endregion
|
|
734
|
+
//#region ../../default/po-autocompact/src/services/nativeAutocompact/index.ts
|
|
735
|
+
/** Exact canonical-prefix comparison refuses to apply summaries to edited or replaced evidence. */
|
|
736
|
+
function tailAfter(snapshot, current) {
|
|
737
|
+
if (snapshot.length > current.length || snapshot.some((message, index) => JSON.stringify(message) !== JSON.stringify(current[index]))) return void 0;
|
|
738
|
+
return current.slice(snapshot.length);
|
|
739
|
+
}
|
|
740
|
+
function leaf(entries) {
|
|
741
|
+
return entries.findLast((entry) => entry.type !== "custom" || entry.customType !== "po-autocompact-state" && entry.customType !== "po-autocompact-checkpoint")?.id ?? "root";
|
|
742
|
+
}
|
|
743
|
+
function createNativeAutocompact(dependencies = {}) {
|
|
744
|
+
const telemetry = dependencies.telemetry ?? createAutocompactTelemetry();
|
|
745
|
+
let active = true;
|
|
746
|
+
let generation = 0;
|
|
747
|
+
let state = createInitialState();
|
|
748
|
+
let snapshot;
|
|
749
|
+
let previousSnapshot;
|
|
750
|
+
let context;
|
|
751
|
+
let contributions;
|
|
752
|
+
let controller;
|
|
753
|
+
let serial = Promise.resolve();
|
|
754
|
+
const work = /* @__PURE__ */ new Set();
|
|
755
|
+
const applied = /* @__PURE__ */ new Set();
|
|
756
|
+
const invalid = /* @__PURE__ */ new Set();
|
|
757
|
+
let configFailureReported = false;
|
|
758
|
+
let footer;
|
|
759
|
+
let navigating = false;
|
|
760
|
+
let degraded = false;
|
|
761
|
+
let lastNativeCompactionId;
|
|
762
|
+
let checkpointBoundary;
|
|
763
|
+
let mirrorQueued = false;
|
|
764
|
+
let historyWarnedSession;
|
|
765
|
+
const attributes = () => ({
|
|
766
|
+
"pi.session.id": context?.sessionId ?? "",
|
|
767
|
+
"autocompact.cycle": state.cycle,
|
|
768
|
+
"autocompact.pass": state.pass,
|
|
769
|
+
...state.requestId ? { "autocompact.request.id": state.requestId } : {},
|
|
770
|
+
...state.snapshotLeafId ? { "autocompact.snapshot_leaf_id": state.snapshotLeafId } : {},
|
|
771
|
+
...state.snapshotTokens === void 0 ? {} : { "autocompact.tokens_before": state.snapshotTokens }
|
|
772
|
+
});
|
|
773
|
+
const configured = (execution) => autocompactRuntimeConfig(execution.repoRoot, (error) => {
|
|
774
|
+
if (!configFailureReported) {
|
|
775
|
+
configFailureReported = true;
|
|
776
|
+
telemetry.recordWarning(AUTOCOMPACT_EVENT.configurationLoadFailed, error, {
|
|
777
|
+
...attributes(),
|
|
778
|
+
"failure.kind": "configuration"
|
|
779
|
+
});
|
|
780
|
+
if (dependencies.modes) Promise.allSettled([Promise.resolve().then(() => execution.client.notify({
|
|
781
|
+
body: `Po autocompact is paused until its configuration is available: ${error instanceof Error ? error.message : String(error)}`,
|
|
782
|
+
level: "warning"
|
|
783
|
+
}))]);
|
|
784
|
+
}
|
|
785
|
+
}, dependencies.modes);
|
|
786
|
+
const alive = (version) => active && !navigating && generation === version;
|
|
787
|
+
const refreshStatus = (execution) => {
|
|
788
|
+
const phase = state.phase === "checkpoint_pending" ? "summarizing" : state.phase === "checkpoint_ready" ? "applying" : void 0;
|
|
789
|
+
footer?.update(phase ? {
|
|
790
|
+
fullText: `Compacting p${state.pass}`,
|
|
791
|
+
compactText: `C${state.pass}`
|
|
792
|
+
} : void 0);
|
|
793
|
+
execution.client.setStatus(STATUS_KEY, phase ? `Compacting pass ${state.pass} (${phase})…` : void 0);
|
|
794
|
+
};
|
|
795
|
+
const enqueue = (callback) => {
|
|
796
|
+
const version = generation;
|
|
797
|
+
const operation = serial.then(async () => {
|
|
798
|
+
if (alive(version)) await callback();
|
|
799
|
+
});
|
|
800
|
+
serial = operation.catch(() => void 0);
|
|
801
|
+
return operation;
|
|
802
|
+
};
|
|
803
|
+
const persist = async (execution, version) => {
|
|
804
|
+
if (!alive(version)) return;
|
|
805
|
+
await execution.session.appendCustomEntry(STATE_CUSTOM_TYPE, {
|
|
806
|
+
...state,
|
|
807
|
+
nativeLastCompactionId: lastNativeCompactionId
|
|
808
|
+
});
|
|
809
|
+
if (alive(version)) refreshStatus(execution);
|
|
810
|
+
};
|
|
811
|
+
const clear = () => {
|
|
812
|
+
delete state.requestId;
|
|
813
|
+
delete state.snapshotLeafId;
|
|
814
|
+
delete state.snapshotTokens;
|
|
815
|
+
delete state.pendingCheckpoint;
|
|
816
|
+
delete state.compactionPass;
|
|
817
|
+
snapshot = void 0;
|
|
818
|
+
};
|
|
819
|
+
const fail = async (execution, version, error, malformed = false, kind = "unknown") => {
|
|
820
|
+
if (!alive(version)) return;
|
|
821
|
+
degraded = true;
|
|
822
|
+
const eventAttributes = attributes();
|
|
823
|
+
const attempts = state.invalidAttempts + 1;
|
|
824
|
+
const pass = state.pass;
|
|
825
|
+
const failedLeaf = state.snapshotLeafId;
|
|
826
|
+
state.invalidAttempts += 1;
|
|
827
|
+
if (state.invalidAttempts >= 3) {
|
|
828
|
+
state.checkpointQueue = state.checkpointQueue.filter((item) => item !== pass);
|
|
829
|
+
state.exhaustedPasses.push(pass);
|
|
830
|
+
state.invalidAttempts = 0;
|
|
831
|
+
}
|
|
832
|
+
state.phase = "waiting";
|
|
833
|
+
clear();
|
|
834
|
+
state.lastAttemptLeafId = failedLeaf;
|
|
835
|
+
const errors = [error];
|
|
836
|
+
try {
|
|
837
|
+
await persist(execution, version);
|
|
838
|
+
} catch (persistError) {
|
|
839
|
+
errors.push(persistError);
|
|
840
|
+
}
|
|
841
|
+
if (!alive(version)) return;
|
|
842
|
+
await Promise.allSettled([Promise.resolve().then(() => execution.client.notify({
|
|
843
|
+
body: `Po autocompact summarization pass ${pass} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
844
|
+
level: "error"
|
|
845
|
+
})), ...errors.map((failure, index) => Promise.resolve().then(() => telemetry.recordError(malformed ? AUTOCOMPACT_EVENT.checkpointInvalid : AUTOCOMPACT_EVENT.checkpointFailed, failure, {
|
|
846
|
+
...eventAttributes,
|
|
847
|
+
"failure.kind": index === 0 ? kind : "persistence",
|
|
848
|
+
"autocompact.checkpoint.attempts": attempts,
|
|
849
|
+
"autocompact.checkpoint.exhausted": attempts >= 3
|
|
850
|
+
}, { includeException: true })))]);
|
|
851
|
+
};
|
|
852
|
+
const matching = async (execution, keep, stopAt) => {
|
|
853
|
+
const entries = [];
|
|
854
|
+
for await (const record of execution.session.entriesNewestFirst()) {
|
|
855
|
+
const entry = record;
|
|
856
|
+
if (entry.id === stopAt) break;
|
|
857
|
+
if (keep(entry)) entries.push(entry);
|
|
858
|
+
}
|
|
859
|
+
return entries.reverse();
|
|
860
|
+
};
|
|
861
|
+
const policyEntries = async (execution, withCheckpoint) => {
|
|
862
|
+
const entries = [...await execution.session.entries({
|
|
863
|
+
type: "custom",
|
|
864
|
+
customType: PLAN_DOCUMENT_ENTRY,
|
|
865
|
+
limit: 1
|
|
866
|
+
})];
|
|
867
|
+
if (withCheckpoint) for await (const record of execution.session.entriesNewestFirst()) {
|
|
868
|
+
const entry = record;
|
|
869
|
+
if (!latestCheckpointArtifactEntry([entry])) continue;
|
|
870
|
+
entries.push(entry);
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
873
|
+
return entries;
|
|
874
|
+
};
|
|
875
|
+
const contextBranch = async (execution) => {
|
|
876
|
+
const entries = [];
|
|
877
|
+
let foundLeaf = false;
|
|
878
|
+
for await (const record of execution.session.entriesNewestFirst()) {
|
|
879
|
+
const entry = record;
|
|
880
|
+
const isLeaf = leaf([entry]) !== "root";
|
|
881
|
+
if (entry.type !== "custom" || !foundLeaf && isLeaf) entries.push(entry);
|
|
882
|
+
if (isLeaf) foundLeaf = true;
|
|
883
|
+
if (entry.type === "compaction" || customMessage(entry)?.customType === "po-autocompact-context") break;
|
|
884
|
+
}
|
|
885
|
+
return entries.reverse();
|
|
886
|
+
};
|
|
887
|
+
const canonical = async (execution, entries) => {
|
|
888
|
+
if (!execution.session.contextMessages) throw new Error("Canonical context is unavailable for autocompact.");
|
|
889
|
+
return projectContextMessages(await execution.session.contextMessages(), entries).messages;
|
|
890
|
+
};
|
|
891
|
+
const scheduleMirror = (execution) => {
|
|
892
|
+
if (mirrorQueued) return;
|
|
893
|
+
mirrorQueued = true;
|
|
894
|
+
enqueue(async () => {
|
|
895
|
+
mirrorQueued = false;
|
|
896
|
+
try {
|
|
897
|
+
await mirrorCompactionHistory(artifactRoot(execution.sessionId, execution.environment), await matching(execution, isHistoryEntry));
|
|
898
|
+
} catch (error) {
|
|
899
|
+
const warn = historyWarnedSession !== execution.sessionId;
|
|
900
|
+
historyWarnedSession = execution.sessionId;
|
|
901
|
+
await Promise.allSettled([Promise.resolve().then(() => telemetry.recordWarning(AUTOCOMPACT_EVENT.historyWriteFailed, error, attributes())), ...warn ? [Promise.resolve().then(() => execution.client.notify({
|
|
902
|
+
body: `Po autocompact could not save compaction history: ${error instanceof Error ? error.message : String(error)}`,
|
|
903
|
+
level: "warning"
|
|
904
|
+
}))] : []]);
|
|
905
|
+
}
|
|
906
|
+
}).finally(() => {
|
|
907
|
+
mirrorQueued = false;
|
|
908
|
+
});
|
|
909
|
+
};
|
|
910
|
+
const contributionSnapshot = async (execution) => {
|
|
911
|
+
const result = readContextContributionsSnapshot(contributions);
|
|
912
|
+
for (const error of result.errors) {
|
|
913
|
+
await execution.client.notify({
|
|
914
|
+
body: `Po autocompact context contribution degraded (${error.source}/${error.id}): ${error.message}`,
|
|
915
|
+
level: "warning"
|
|
916
|
+
});
|
|
917
|
+
await telemetry.recordWarning(AUTOCOMPACT_EVENT.contextContributionDegraded, new Error(error.message), {
|
|
918
|
+
...attributes(),
|
|
919
|
+
"autocompact.context_contribution.source": error.source,
|
|
920
|
+
"autocompact.context_contribution.id": error.id,
|
|
921
|
+
"autocompact.context_contribution.order": error.order
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
return result;
|
|
925
|
+
};
|
|
926
|
+
const runtimeState = async (execution, entries, version, appendMessage = checkpointBoundary?.appendMessage.bind(checkpointBoundary)) => {
|
|
927
|
+
const saved = runtimeStateSnapshot(entries, await contributionSnapshot(execution));
|
|
928
|
+
if (!alive(version)) return;
|
|
929
|
+
await appendMessage?.({
|
|
930
|
+
type: RUNTIME_STATE_MESSAGE_TYPE,
|
|
931
|
+
text: formatRuntimeState(saved),
|
|
932
|
+
display: false,
|
|
933
|
+
details: {
|
|
934
|
+
version: 2,
|
|
935
|
+
...saved
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
return {
|
|
939
|
+
"autocompact.runtime.plan_present": Boolean(saved.planPath),
|
|
940
|
+
"autocompact.runtime.contribution_count": saved.contributions.length,
|
|
941
|
+
"autocompact.runtime.contribution_error_count": saved.contributionErrors.length
|
|
942
|
+
};
|
|
943
|
+
};
|
|
944
|
+
const summaryModel = async (execution, configuration) => {
|
|
945
|
+
const ownReference = configuration.agent?.model ? parseModelReference(configuration.agent.model) : void 0;
|
|
946
|
+
const candidate = ownReference ? `${ownReference.provider}/${ownReference.modelId}` : void 0;
|
|
947
|
+
const reference = candidate && execution.textCompletion.available(candidate) ? candidate : execution.model ? `${execution.model.provider}/${execution.model.id}` : "";
|
|
948
|
+
return {
|
|
949
|
+
reference,
|
|
950
|
+
thinking: configuration.agent?.thinking ?? (reference === candidate ? ownReference?.thinking : void 0) ?? (await execution.session.readModelSettings?.())?.thinkingLevel
|
|
951
|
+
};
|
|
952
|
+
};
|
|
953
|
+
const manualCompaction = async (event, execution) => {
|
|
954
|
+
const configuration = configured(execution);
|
|
955
|
+
if (!configuration.enabled || !execution.textCompletion?.summarize) return;
|
|
956
|
+
try {
|
|
957
|
+
const entries = await contextBranch(execution);
|
|
958
|
+
const pinned = await policyEntries(execution, state.pass > 1);
|
|
959
|
+
const messages = await canonical(execution, entries);
|
|
960
|
+
const delta = state.pass > 1 && previousSnapshot ? tailAfter(previousSnapshot, messages) : void 0;
|
|
961
|
+
const previous = state.pass > 1 ? checkpointSummaryFromEntry(latestCheckpointArtifactEntry(pinned)) : void 0;
|
|
962
|
+
const { reference, thinking } = await summaryModel(execution, configuration);
|
|
963
|
+
const instructions = checkpointInstructions(3, {
|
|
964
|
+
plan: latestPlanSnapshot(pinned),
|
|
965
|
+
contextContributions: await contributionSnapshot(execution),
|
|
966
|
+
readFiles: state.readFiles,
|
|
967
|
+
modifiedFiles: state.modifiedFiles
|
|
968
|
+
});
|
|
969
|
+
const { summary } = parseCheckpointDecision(await execution.textCompletion.summarize(reference, {
|
|
970
|
+
messages: delta ?? messages,
|
|
971
|
+
instructions: typeof event.instructions === "string" && event.instructions.trim() ? `${instructions}\n\n${event.instructions}` : instructions,
|
|
972
|
+
...previous ? { previousSummary: previous } : {},
|
|
973
|
+
...thinking ? { thinkingLevel: thinking } : {},
|
|
974
|
+
...execution.signal ? { signal: execution.signal } : {}
|
|
975
|
+
}));
|
|
976
|
+
if (!isStructuredCheckpoint(summary)) throw new Error("Summarization returned an incomplete checkpoint.");
|
|
977
|
+
const files = mergeFileDetails(state, fileOperationsFromMessages(messages));
|
|
978
|
+
const usage = await execution.session.contextUsage?.();
|
|
979
|
+
return { compaction: {
|
|
980
|
+
summary: withCanonicalFileSections(summary, files),
|
|
981
|
+
tokensBefore: usage?.tokens ?? 0,
|
|
982
|
+
retainedTail: [],
|
|
983
|
+
details: files
|
|
984
|
+
} };
|
|
985
|
+
} catch (error) {
|
|
986
|
+
await execution.client.notify({
|
|
987
|
+
body: `Po autocompact manual compaction failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
988
|
+
level: "error"
|
|
989
|
+
});
|
|
990
|
+
throw error;
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
const resetCycle = () => {
|
|
994
|
+
state.phase = "waiting";
|
|
995
|
+
state.checkpointQueue = [];
|
|
996
|
+
state.exhaustedPasses = [];
|
|
997
|
+
state.invalidAttempts = 0;
|
|
998
|
+
state.baselinePending = true;
|
|
999
|
+
state.cycle += 1;
|
|
1000
|
+
state.pass = 1;
|
|
1001
|
+
delete state.lastAttemptLeafId;
|
|
1002
|
+
delete state.latestCheckpointSnapshotLeafId;
|
|
1003
|
+
clear();
|
|
1004
|
+
previousSnapshot = void 0;
|
|
1005
|
+
};
|
|
1006
|
+
const applyReady = async (execution, version, appendMessage) => {
|
|
1007
|
+
if (state.phase !== "checkpoint_ready" || !state.pendingCheckpoint || !state.requestId || !state.snapshotLeafId) return false;
|
|
1008
|
+
const decision = parseCheckpointDecision(state.pendingCheckpoint);
|
|
1009
|
+
if (!isStructuredCheckpoint(decision.summary)) {
|
|
1010
|
+
await fail(execution, version, /* @__PURE__ */ new Error("Summarization returned an incomplete checkpoint."), true, "validation");
|
|
1011
|
+
return false;
|
|
1012
|
+
}
|
|
1013
|
+
const entries = await contextBranch(execution);
|
|
1014
|
+
const messages = await canonical(execution, entries);
|
|
1015
|
+
if (!alive(version)) return false;
|
|
1016
|
+
const tail = snapshot && tailAfter(snapshot, messages);
|
|
1017
|
+
if (!tail) {
|
|
1018
|
+
await fail(execution, version, /* @__PURE__ */ new Error("Canonical checkpoint evidence changed; summary must be regenerated."), false, "evidence_changed");
|
|
1019
|
+
return false;
|
|
1020
|
+
}
|
|
1021
|
+
const pass = state.pass;
|
|
1022
|
+
if (pass === 1 || pass === 2 && decision.shouldCompact !== true) {
|
|
1023
|
+
await execution.session.appendCustomEntry(CHECKPOINT_MESSAGE_TYPE, {
|
|
1024
|
+
...checkpointRequestDetails(state.cycle, pass, state.requestId),
|
|
1025
|
+
summary: decision.summary
|
|
1026
|
+
});
|
|
1027
|
+
if (!alive(version)) return false;
|
|
1028
|
+
previousSnapshot = snapshot;
|
|
1029
|
+
state.latestCheckpointSnapshotLeafId = state.snapshotLeafId;
|
|
1030
|
+
state.checkpointQueue = state.checkpointQueue.filter((item) => item !== pass);
|
|
1031
|
+
state.pass = pass === 1 ? 2 : 3;
|
|
1032
|
+
state.phase = "waiting";
|
|
1033
|
+
state.invalidAttempts = 0;
|
|
1034
|
+
clear();
|
|
1035
|
+
await persist(execution, version);
|
|
1036
|
+
scheduleMirror(execution);
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
1039
|
+
const files = mergeFileDetails(state, fileOperationsFromMessages(messages));
|
|
1040
|
+
const details = {
|
|
1041
|
+
...files,
|
|
1042
|
+
poAutocompact: {
|
|
1043
|
+
version: 2,
|
|
1044
|
+
cycle: state.cycle,
|
|
1045
|
+
pass,
|
|
1046
|
+
requestId: state.requestId,
|
|
1047
|
+
snapshotLeafId: state.snapshotLeafId,
|
|
1048
|
+
tokensBefore: state.snapshotTokens ?? 0
|
|
1049
|
+
},
|
|
1050
|
+
retainedMessages: tail
|
|
1051
|
+
};
|
|
1052
|
+
const idle = (await execution.session.activity()).isIdle;
|
|
1053
|
+
if (!alive(version)) return false;
|
|
1054
|
+
const id = await appendMessage({
|
|
1055
|
+
type: CONTEXT_MESSAGE_TYPE,
|
|
1056
|
+
text: withCanonicalFileSections(decision.summary, files),
|
|
1057
|
+
display: false,
|
|
1058
|
+
details
|
|
1059
|
+
}, { resetContext: { retainedMessages: tail } });
|
|
1060
|
+
if (!alive(version) || !id) return false;
|
|
1061
|
+
await execution.session.setLabel?.(id, `autocompact:c${state.cycle}:p${pass}`);
|
|
1062
|
+
if (!alive(version)) return false;
|
|
1063
|
+
const runtimeAttributes = await runtimeState(execution, await policyEntries(execution, false), version, appendMessage);
|
|
1064
|
+
if (!alive(version)) return false;
|
|
1065
|
+
const committedAttributes = attributes();
|
|
1066
|
+
state.readFiles = files.readFiles;
|
|
1067
|
+
state.modifiedFiles = files.modifiedFiles;
|
|
1068
|
+
resetCycle();
|
|
1069
|
+
await persist(execution, version);
|
|
1070
|
+
scheduleMirror(execution);
|
|
1071
|
+
if (!alive(version)) return false;
|
|
1072
|
+
await telemetry.recordEvent(AUTOCOMPACT_EVENT.contextCommitted, {
|
|
1073
|
+
...committedAttributes,
|
|
1074
|
+
"autocompact.message_count.before": messages.length,
|
|
1075
|
+
"autocompact.message_count.retained": tail.length,
|
|
1076
|
+
"autocompact.apply_mode": idle ? "idle" : "turn_end",
|
|
1077
|
+
...runtimeAttributes
|
|
1078
|
+
});
|
|
1079
|
+
if (idle && alive(version)) await execution.session.admitPrompt?.("Asynchronous compaction completed. Continue from the compacted checkpoint's immediate next action without repeating completed work.", "steer", void 0, `${RESUME_MESSAGE_TYPE}:${details.poAutocompact.requestId}`);
|
|
1080
|
+
return true;
|
|
1081
|
+
};
|
|
1082
|
+
const ensureCheckpointBoundary = (execution) => {
|
|
1083
|
+
if (checkpointBoundary) return;
|
|
1084
|
+
if (!execution.session.registerCheckpointBoundary) throw new Error("Native checkpoint boundaries are unavailable.");
|
|
1085
|
+
checkpointBoundary = execution.session.registerCheckpointBoundary(async (boundary) => {
|
|
1086
|
+
if (!active || navigating || boundary.signal?.aborted) return;
|
|
1087
|
+
const current = context ?? execution;
|
|
1088
|
+
await enqueue(() => boundary.signal?.aborted ? Promise.resolve() : progress(current, true, boundary.appendMessage.bind(boundary)));
|
|
1089
|
+
});
|
|
1090
|
+
};
|
|
1091
|
+
const advance = async (execution, allowBusy = false, appendMessage = checkpointBoundary?.appendMessage.bind(checkpointBoundary)) => {
|
|
1092
|
+
const version = generation;
|
|
1093
|
+
context = execution;
|
|
1094
|
+
const activity = await execution.session.activity();
|
|
1095
|
+
if (!alive(version) || activity.hasPendingMessages) return;
|
|
1096
|
+
if (appendMessage && (activity.isIdle || allowBusy)) {
|
|
1097
|
+
if (await applyReady(execution, version, appendMessage)) return;
|
|
1098
|
+
}
|
|
1099
|
+
if (!alive(version) || state.phase !== "waiting") return;
|
|
1100
|
+
const configuration = configured(execution);
|
|
1101
|
+
if (!configuration.enabled || !execution.session.contextUsage || !execution.textCompletion?.summarize) return;
|
|
1102
|
+
const usage = await execution.session.contextUsage();
|
|
1103
|
+
if (!alive(version) || !usage || typeof usage.tokens !== "number" || !Number.isFinite(usage.tokens) || usage.tokens < 0) return;
|
|
1104
|
+
const tokens = usage.tokens;
|
|
1105
|
+
const thresholds = effectiveThresholds(usage.contextWindow, state.baselineTokens, configuration.ratios, resolveModelTokenOverrides(execution.model, configuration.overrides));
|
|
1106
|
+
if (!state.baselinePending && !state.checkpointQueue.length && ![
|
|
1107
|
+
1,
|
|
1108
|
+
2,
|
|
1109
|
+
3
|
|
1110
|
+
].some((pass) => pass >= state.pass && !state.exhaustedPasses.includes(pass) && tokens >= thresholds[pass])) return;
|
|
1111
|
+
const entries = await contextBranch(execution);
|
|
1112
|
+
if (!alive(version)) return;
|
|
1113
|
+
if (state.baselinePending) {
|
|
1114
|
+
if (!baselineUsageIsSettled(entries)) return;
|
|
1115
|
+
state.baselineTokens = usage.tokens;
|
|
1116
|
+
state.baselinePending = false;
|
|
1117
|
+
await persist(execution, version);
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
const currentLeaf = leaf(entries);
|
|
1121
|
+
if (currentLeaf === state.lastAttemptLeafId) return;
|
|
1122
|
+
for (const pass of [
|
|
1123
|
+
1,
|
|
1124
|
+
2,
|
|
1125
|
+
3
|
|
1126
|
+
]) if (pass >= state.pass && !state.checkpointQueue.includes(pass) && !state.exhaustedPasses.includes(pass) && usage.tokens >= thresholds[pass]) state.checkpointQueue.push(pass);
|
|
1127
|
+
const pass = state.checkpointQueue[0];
|
|
1128
|
+
if (!pass) return;
|
|
1129
|
+
state.pass = pass;
|
|
1130
|
+
const checkpointEntries = await policyEntries(execution, pass > 1);
|
|
1131
|
+
const messages = await canonical(execution, entries);
|
|
1132
|
+
const steering = await contributionSnapshot(execution);
|
|
1133
|
+
if (!alive(version)) return;
|
|
1134
|
+
snapshot = messages;
|
|
1135
|
+
const previous = pass > 1 ? checkpointSummaryFromEntry(latestCheckpointArtifactEntry(checkpointEntries)) : void 0;
|
|
1136
|
+
const requestId = createRequestId(execution.sessionId, state.cycle, pass, currentLeaf);
|
|
1137
|
+
state.phase = "checkpoint_pending";
|
|
1138
|
+
state.requestId = requestId;
|
|
1139
|
+
state.snapshotLeafId = currentLeaf;
|
|
1140
|
+
state.snapshotTokens = usage.tokens;
|
|
1141
|
+
delete state.lastAttemptLeafId;
|
|
1142
|
+
delete state.pendingCheckpoint;
|
|
1143
|
+
await persist(execution, version);
|
|
1144
|
+
if (!alive(version)) return;
|
|
1145
|
+
degraded = false;
|
|
1146
|
+
controller?.abort();
|
|
1147
|
+
controller = new AbortController();
|
|
1148
|
+
const signal = controller.signal;
|
|
1149
|
+
const requestAttributes = {
|
|
1150
|
+
...attributes(),
|
|
1151
|
+
"autocompact.message_count.before": messages.length
|
|
1152
|
+
};
|
|
1153
|
+
const delta = previousSnapshot ? tailAfter(previousSnapshot, messages) : void 0;
|
|
1154
|
+
let failureKind = "configuration";
|
|
1155
|
+
const completion = telemetry.runInSpan("po_autocompact.checkpoint", requestAttributes, async () => {
|
|
1156
|
+
const { reference, thinking } = await summaryModel(execution, configuration);
|
|
1157
|
+
failureKind = "unknown";
|
|
1158
|
+
if (!alive(version) || signal.aborted) return "";
|
|
1159
|
+
await telemetry.recordEvent(AUTOCOMPACT_EVENT.checkpointStarted, requestAttributes);
|
|
1160
|
+
return execution.textCompletion.summarize(reference, {
|
|
1161
|
+
messages: pass > 1 && delta ? delta : messages,
|
|
1162
|
+
instructions: checkpointInstructions(pass, {
|
|
1163
|
+
plan: latestPlanSnapshot(checkpointEntries),
|
|
1164
|
+
contextContributions: steering,
|
|
1165
|
+
readFiles: state.readFiles,
|
|
1166
|
+
modifiedFiles: state.modifiedFiles
|
|
1167
|
+
}),
|
|
1168
|
+
...previous ? { previousSummary: previous } : {},
|
|
1169
|
+
...thinking ? { thinkingLevel: thinking } : {},
|
|
1170
|
+
signal
|
|
1171
|
+
});
|
|
1172
|
+
}).then(async (summary) => {
|
|
1173
|
+
await enqueue(async () => {
|
|
1174
|
+
if (!alive(version) || signal.aborted || state.requestId !== requestId) return;
|
|
1175
|
+
if (!summary.trim()) {
|
|
1176
|
+
await fail(execution, version, /* @__PURE__ */ new Error("Summarization returned an empty checkpoint."), false, "empty_checkpoint");
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
state.phase = "checkpoint_ready";
|
|
1180
|
+
state.pendingCheckpoint = summary.trim();
|
|
1181
|
+
failureKind = "persistence";
|
|
1182
|
+
await persist(execution, version);
|
|
1183
|
+
failureKind = "unknown";
|
|
1184
|
+
if (!alive(version)) return;
|
|
1185
|
+
await telemetry.recordEvent(AUTOCOMPACT_EVENT.checkpointCompleted, {
|
|
1186
|
+
...requestAttributes,
|
|
1187
|
+
"autocompact.checkpoint.characters": summary.length
|
|
1188
|
+
});
|
|
1189
|
+
if ((await execution.session.activity()).isIdle && alive(version)) await progress(execution);
|
|
1190
|
+
});
|
|
1191
|
+
}).catch(async (error) => {
|
|
1192
|
+
await enqueue(async () => {
|
|
1193
|
+
if (alive(version) && state.requestId === requestId) await fail(execution, version, error, false, failureKind);
|
|
1194
|
+
});
|
|
1195
|
+
});
|
|
1196
|
+
work.add(completion);
|
|
1197
|
+
completion.then(() => work.delete(completion), () => work.delete(completion));
|
|
1198
|
+
};
|
|
1199
|
+
const progress = async (execution, allowBusy = false, appendMessage) => {
|
|
1200
|
+
const version = generation;
|
|
1201
|
+
try {
|
|
1202
|
+
ensureCheckpointBoundary(execution);
|
|
1203
|
+
await advance(execution, allowBusy, appendMessage);
|
|
1204
|
+
} catch (error) {
|
|
1205
|
+
try {
|
|
1206
|
+
await fail(execution, version, error, false, "persistence");
|
|
1207
|
+
} finally {
|
|
1208
|
+
if (alive(version)) delete state.lastAttemptLeafId;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
const load = async (execution) => {
|
|
1213
|
+
if (!active) return;
|
|
1214
|
+
navigating = false;
|
|
1215
|
+
generation += 1;
|
|
1216
|
+
const version = generation;
|
|
1217
|
+
controller?.abort(/* @__PURE__ */ new Error("Autocompact session generation changed."));
|
|
1218
|
+
controller = void 0;
|
|
1219
|
+
context = execution;
|
|
1220
|
+
applied.clear();
|
|
1221
|
+
invalid.clear();
|
|
1222
|
+
const saved = await execution.session.customSnapshot?.(STATE_CUSTOM_TYPE);
|
|
1223
|
+
if (!alive(version)) return;
|
|
1224
|
+
const entry = saved?.available ? saved.entry : void 0;
|
|
1225
|
+
const data = entry?.type === "custom" && entry.data && typeof entry.data === "object" ? entry.data : void 0;
|
|
1226
|
+
state = parseState(data) ?? createInitialState();
|
|
1227
|
+
lastNativeCompactionId = typeof data?.nativeLastCompactionId === "string" ? data.nativeLastCompactionId : void 0;
|
|
1228
|
+
const validMessages = (value) => Array.isArray(value) && value.every((message) => message && typeof message === "object" && typeof message.role === "string");
|
|
1229
|
+
snapshot = validMessages(data?.nativeSnapshot) ? data.nativeSnapshot : void 0;
|
|
1230
|
+
previousSnapshot = validMessages(data?.nativePreviousSnapshot) ? data.nativePreviousSnapshot : void 0;
|
|
1231
|
+
if (entry?.id && state.phase === "checkpoint_ready" && state.requestId) {
|
|
1232
|
+
const artifacts = await matching(execution, (item) => item.type === "custom" && item.customType === "po-autocompact-checkpoint" || customMessage(item)?.customType === "po-autocompact-context", entry?.id);
|
|
1233
|
+
const committed = artifacts.findLast((item) => {
|
|
1234
|
+
const message = item.type === "message" ? item.message : void 0;
|
|
1235
|
+
if (message?.role !== "custom" || message.customType !== "po-autocompact-context") return false;
|
|
1236
|
+
const details = contextDetailsFromUnknown(message.details);
|
|
1237
|
+
return details !== void 0 && details.poAutocompact.requestId === state.requestId && details.poAutocompact.cycle === state.cycle && details.poAutocompact.pass === state.pass && details.poAutocompact.snapshotLeafId === state.snapshotLeafId && isStructuredCheckpoint(checkpointSummaryFromEntry(item) ?? "");
|
|
1238
|
+
});
|
|
1239
|
+
if (committed?.type === "message" && committed.message.role === "custom") {
|
|
1240
|
+
const details = contextDetailsFromUnknown(committed.message.details);
|
|
1241
|
+
state.readFiles = details.readFiles;
|
|
1242
|
+
state.modifiedFiles = details.modifiedFiles;
|
|
1243
|
+
resetCycle();
|
|
1244
|
+
await persist(execution, version);
|
|
1245
|
+
} else if (artifacts.findLast((item) => {
|
|
1246
|
+
if (item.type !== "custom" || item.customType !== "po-autocompact-checkpoint") return false;
|
|
1247
|
+
const details = item.data;
|
|
1248
|
+
return details?.version === 2 && details.requestId === state.requestId && details.cycle === state.cycle && details.pass === state.pass && isStructuredCheckpoint(checkpointSummaryFromEntry(item) ?? "");
|
|
1249
|
+
}) && (state.pass === 1 || state.pass === 2)) {
|
|
1250
|
+
previousSnapshot = snapshot;
|
|
1251
|
+
state.latestCheckpointSnapshotLeafId = state.snapshotLeafId;
|
|
1252
|
+
state.checkpointQueue = state.checkpointQueue.filter((pass) => pass !== state.pass);
|
|
1253
|
+
state.pass = state.pass === 1 ? 2 : 3;
|
|
1254
|
+
state.phase = "waiting";
|
|
1255
|
+
state.invalidAttempts = 0;
|
|
1256
|
+
clear();
|
|
1257
|
+
await persist(execution, version);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
if (state.phase !== "waiting" && (state.phase !== "checkpoint_ready" || !snapshot)) {
|
|
1261
|
+
state.phase = "waiting";
|
|
1262
|
+
clear();
|
|
1263
|
+
delete state.lastAttemptLeafId;
|
|
1264
|
+
await persist(execution, version);
|
|
1265
|
+
}
|
|
1266
|
+
if (!alive(version)) return;
|
|
1267
|
+
const progressed = enqueue(() => progress(execution));
|
|
1268
|
+
scheduleMirror(execution);
|
|
1269
|
+
await progressed;
|
|
1270
|
+
};
|
|
1271
|
+
const restore = async (execution) => {
|
|
1272
|
+
const version = generation + 1;
|
|
1273
|
+
try {
|
|
1274
|
+
await load(execution);
|
|
1275
|
+
} catch (error) {
|
|
1276
|
+
await fail(execution, version, error);
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
return {
|
|
1280
|
+
hooks: [
|
|
1281
|
+
{
|
|
1282
|
+
event: "session_start",
|
|
1283
|
+
handle: (_event, execution) => restore(execution)
|
|
1284
|
+
},
|
|
1285
|
+
{
|
|
1286
|
+
event: "session_tree",
|
|
1287
|
+
handle: (event, execution) => {
|
|
1288
|
+
if (!active) return;
|
|
1289
|
+
if (event.status === "started") {
|
|
1290
|
+
navigating = true;
|
|
1291
|
+
generation += 1;
|
|
1292
|
+
controller?.abort(/* @__PURE__ */ new Error("Autocompact navigation started."));
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
return restore(execution);
|
|
1296
|
+
}
|
|
1297
|
+
},
|
|
1298
|
+
{
|
|
1299
|
+
event: "turn_end",
|
|
1300
|
+
handle: (_event, execution) => enqueue(() => progress(execution))
|
|
1301
|
+
},
|
|
1302
|
+
{
|
|
1303
|
+
event: "agent_settled",
|
|
1304
|
+
handle: (_event, execution) => enqueue(() => progress(execution))
|
|
1305
|
+
},
|
|
1306
|
+
{
|
|
1307
|
+
event: "session_before_compact",
|
|
1308
|
+
handle: (event, execution) => {
|
|
1309
|
+
if (!active || navigating) return;
|
|
1310
|
+
if (event.reason === "manual") return manualCompaction(event, execution);
|
|
1311
|
+
return !degraded && configured(execution).enabled && event.reason === "threshold" && (state.phase === "checkpoint_pending" || state.phase === "checkpoint_ready") ? { cancel: true } : void 0;
|
|
1312
|
+
}
|
|
1313
|
+
},
|
|
1314
|
+
{
|
|
1315
|
+
event: "context",
|
|
1316
|
+
async handle(event, execution) {
|
|
1317
|
+
if (!active || navigating || !Array.isArray(event.messages)) return;
|
|
1318
|
+
const started = Date.now();
|
|
1319
|
+
try {
|
|
1320
|
+
const version = generation;
|
|
1321
|
+
const entries = await contextBranch(execution);
|
|
1322
|
+
if (!alive(version)) return;
|
|
1323
|
+
const projection = projectContextMessages(event.messages, entries);
|
|
1324
|
+
if (projection.invalidMarker) {
|
|
1325
|
+
const id = leaf(entries);
|
|
1326
|
+
if (!invalid.has(id)) {
|
|
1327
|
+
invalid.add(id);
|
|
1328
|
+
await telemetry.recordError(AUTOCOMPACT_EVENT.contextMarkerInvalid, /* @__PURE__ */ new Error("Po autocompact context marker is malformed."), {
|
|
1329
|
+
...attributes(),
|
|
1330
|
+
"autocompact.leaf_id": id
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
return;
|
|
1334
|
+
}
|
|
1335
|
+
if (!projection.marker) return;
|
|
1336
|
+
if (!applied.has(projection.marker.requestId)) {
|
|
1337
|
+
applied.add(projection.marker.requestId);
|
|
1338
|
+
await telemetry.recordEvent(AUTOCOMPACT_EVENT.contextApplied, {
|
|
1339
|
+
...attributes(),
|
|
1340
|
+
"autocompact.request.id": projection.marker.requestId,
|
|
1341
|
+
"autocompact.cycle": projection.marker.cycle,
|
|
1342
|
+
"autocompact.pass": projection.marker.pass,
|
|
1343
|
+
"autocompact.snapshot_leaf_id": projection.marker.snapshotLeafId,
|
|
1344
|
+
"autocompact.tokens_before": projection.marker.tokensBefore,
|
|
1345
|
+
"autocompact.message_count.before": event.messages.length,
|
|
1346
|
+
"autocompact.message_count.after": projection.messages.length,
|
|
1347
|
+
"autocompact.message_count.retained": projection.retainedMessageCount
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
return alive(version) ? { messages: projection.messages } : void 0;
|
|
1351
|
+
} finally {
|
|
1352
|
+
const hookMs = Date.now() - started;
|
|
1353
|
+
if (active && hookMs >= 25) await telemetry.recordEvent(AUTOCOMPACT_EVENT.contextHookSlow, {
|
|
1354
|
+
...attributes(),
|
|
1355
|
+
hook_ms: hookMs,
|
|
1356
|
+
"autocompact.message_count": event.messages.length
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
},
|
|
1361
|
+
{
|
|
1362
|
+
event: "session_compact",
|
|
1363
|
+
handle: (event, execution) => {
|
|
1364
|
+
if (!active || event.status !== "completed" || typeof event.entryId !== "string" || event.entryId === lastNativeCompactionId) return;
|
|
1365
|
+
const observedGeneration = generation;
|
|
1366
|
+
return enqueue(async () => {
|
|
1367
|
+
const compacted = (await execution.session.entries({
|
|
1368
|
+
type: "compaction",
|
|
1369
|
+
limit: 1
|
|
1370
|
+
}))[0];
|
|
1371
|
+
if (!alive(observedGeneration) || !compacted || compacted.type !== "compaction" || compacted.id !== event.entryId || compacted.id === lastNativeCompactionId) return;
|
|
1372
|
+
generation += 1;
|
|
1373
|
+
const version = generation;
|
|
1374
|
+
controller?.abort(/* @__PURE__ */ new Error("Native compaction superseded checkpoint."));
|
|
1375
|
+
controller = void 0;
|
|
1376
|
+
lastNativeCompactionId = compacted.id;
|
|
1377
|
+
const files = mergeFileDetails(state, void 0, fileDetailsFromUnknown("details" in compacted ? compacted.details : void 0));
|
|
1378
|
+
state.readFiles = files.readFiles;
|
|
1379
|
+
state.modifiedFiles = files.modifiedFiles;
|
|
1380
|
+
await execution.session.setLabel?.(compacted.id, `autocompact:c${state.cycle}:external`);
|
|
1381
|
+
if (!alive(version)) return;
|
|
1382
|
+
const plan = await execution.session.entries({
|
|
1383
|
+
type: "custom",
|
|
1384
|
+
customType: PLAN_DOCUMENT_ENTRY,
|
|
1385
|
+
limit: 1
|
|
1386
|
+
});
|
|
1387
|
+
const runtimeAttributes = await runtimeState(execution, plan, version);
|
|
1388
|
+
if (!alive(version)) return;
|
|
1389
|
+
const nativeAttributes = attributes();
|
|
1390
|
+
resetCycle();
|
|
1391
|
+
await persist(execution, version);
|
|
1392
|
+
scheduleMirror(execution);
|
|
1393
|
+
if (alive(version)) await telemetry.recordEvent(AUTOCOMPACT_EVENT.nativeCompactionCompleted, {
|
|
1394
|
+
...nativeAttributes,
|
|
1395
|
+
"autocompact.native.reason": typeof event.reason === "string" ? event.reason : "unknown",
|
|
1396
|
+
"autocompact.native.from_extension": "fromHook" in compacted && compacted.fromHook === true,
|
|
1397
|
+
"autocompact.tokens_before": compacted.tokensBefore,
|
|
1398
|
+
...runtimeAttributes
|
|
1399
|
+
});
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
],
|
|
1404
|
+
plugin(cordis) {
|
|
1405
|
+
cordis.inject([PO_UI_HUB_SERVICE], (injected) => {
|
|
1406
|
+
const contribution = requirePoUiHub(injected).registerFooter({
|
|
1407
|
+
source: FOOTER_SOURCE,
|
|
1408
|
+
id: "autocompact",
|
|
1409
|
+
order: 20
|
|
1410
|
+
});
|
|
1411
|
+
footer = contribution;
|
|
1412
|
+
if (context && active) refreshStatus(context);
|
|
1413
|
+
return () => {
|
|
1414
|
+
contribution.dispose();
|
|
1415
|
+
if (footer === contribution) footer = void 0;
|
|
1416
|
+
};
|
|
1417
|
+
});
|
|
1418
|
+
cordis.inject([PO_CONTEXT_CONTRIBUTIONS_SERVICE], (injected) => {
|
|
1419
|
+
const service = requirePoContextContributions(injected);
|
|
1420
|
+
contributions = service;
|
|
1421
|
+
return () => {
|
|
1422
|
+
if (contributions === service) contributions = void 0;
|
|
1423
|
+
};
|
|
1424
|
+
});
|
|
1425
|
+
},
|
|
1426
|
+
start: restore,
|
|
1427
|
+
async stop() {
|
|
1428
|
+
active = false;
|
|
1429
|
+
checkpointBoundary?.dispose();
|
|
1430
|
+
checkpointBoundary = void 0;
|
|
1431
|
+
generation += 1;
|
|
1432
|
+
controller?.abort(/* @__PURE__ */ new Error("Autocompact is shutting down."));
|
|
1433
|
+
await Promise.allSettled([...work, serial]);
|
|
1434
|
+
context?.client.setStatus(STATUS_KEY, void 0);
|
|
1435
|
+
footer?.update(void 0);
|
|
1436
|
+
footer = void 0;
|
|
1437
|
+
context = void 0;
|
|
1438
|
+
contributions = void 0;
|
|
1439
|
+
await telemetry.shutdown();
|
|
1440
|
+
}
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
//#endregion
|
|
1444
|
+
//#region ../../default/po-autocompact/src/extensions/workspaces/sessions/(backend)/root.server.ts
|
|
1445
|
+
var root_server_default = defineRoot(({ agent, context }) => {
|
|
1446
|
+
const runtime = createNativeAutocompact({
|
|
1447
|
+
telemetry: createAutocompactTelemetry({
|
|
1448
|
+
env: agent?.context.environment,
|
|
1449
|
+
cwd: agent?.context.cwd
|
|
1450
|
+
}),
|
|
1451
|
+
modes: admittedModes(context)
|
|
1452
|
+
});
|
|
1453
|
+
return {
|
|
1454
|
+
value: runtime,
|
|
1455
|
+
services: [runtime.plugin],
|
|
1456
|
+
onDispose: runtime.stop
|
|
1457
|
+
};
|
|
1458
|
+
});
|
|
1459
|
+
//#endregion
|
|
1460
|
+
//#region ../../default/po-autocompact/src/extensions/workspaces/sessions/(backend)/hook/agent-settled.server.ts
|
|
1461
|
+
var agent_settled_server_default = defineHook(({ root }) => root.hooks.find((hook) => hook.event === "agent_settled"));
|
|
1462
|
+
//#endregion
|
|
1463
|
+
//#region ../../default/po-autocompact/src/extensions/workspaces/sessions/(backend)/hook/context.server.ts
|
|
1464
|
+
var context_server_default = defineHook(({ root }) => root.hooks.find((hook) => hook.event === "context"));
|
|
1465
|
+
//#endregion
|
|
1466
|
+
//#region ../../default/po-autocompact/src/extensions/workspaces/sessions/(backend)/hook/session-before-compact.server.ts
|
|
1467
|
+
var session_before_compact_server_default = defineHook(({ root }) => root.hooks.find((hook) => hook.event === "session_before_compact"));
|
|
1468
|
+
//#endregion
|
|
1469
|
+
//#region ../../default/po-autocompact/src/extensions/workspaces/sessions/(backend)/hook/session-compact.server.ts
|
|
1470
|
+
var session_compact_server_default = defineHook(({ root }) => root.hooks.find((hook) => hook.event === "session_compact"));
|
|
1471
|
+
//#endregion
|
|
1472
|
+
//#region ../../default/po-autocompact/src/extensions/workspaces/sessions/(backend)/hook/session-start.server.ts
|
|
1473
|
+
var session_start_server_default = defineHook(({ root }) => root.hooks.find((hook) => hook.event === "session_start"));
|
|
1474
|
+
//#endregion
|
|
1475
|
+
//#region ../../default/po-autocompact/src/extensions/workspaces/sessions/(backend)/hook/session-tree.server.ts
|
|
1476
|
+
var session_tree_server_default = defineHook(({ root }) => root.hooks.find((hook) => hook.event === "session_tree"));
|
|
1477
|
+
//#endregion
|
|
1478
|
+
//#region ../../default/po-autocompact/src/extensions/workspaces/sessions/(backend)/hook/turn-end.server.ts
|
|
1479
|
+
var turn_end_server_default = defineHook(({ root }) => root.hooks.find((hook) => hook.event === "turn_end"));
|
|
1480
|
+
//#endregion
|
|
1481
|
+
//#region ../../default/po-autocompact/generated/server.ts
|
|
1482
|
+
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
1483
|
+
const via = (identity, value) => value === void 0 ? void 0 : {
|
|
1484
|
+
...identity,
|
|
1485
|
+
...value
|
|
1486
|
+
};
|
|
1487
|
+
const serverPlugin = defineServerPlugin({
|
|
1488
|
+
name: "@agimon-ai/po-autocompact",
|
|
1489
|
+
providerOverrides: composeServerProviderOverrides(root_server_default),
|
|
1490
|
+
injects: composeRootInjects({ session: [root_server_default] }),
|
|
1491
|
+
session: async (context) => {
|
|
1492
|
+
const scopeSession = await context.scopeRoot("session", root_server_default, context);
|
|
1493
|
+
const contextSession = {
|
|
1494
|
+
...context,
|
|
1495
|
+
root: scopeSession.value
|
|
1496
|
+
};
|
|
1497
|
+
return {
|
|
1498
|
+
...composeRootHooks(scopeSession),
|
|
1499
|
+
get hooks() {
|
|
1500
|
+
return [
|
|
1501
|
+
via({ event: "agent_settled" }, at(agent_settled_server_default, contextSession)),
|
|
1502
|
+
via({ event: "context" }, at(context_server_default, contextSession)),
|
|
1503
|
+
via({ event: "session_before_compact" }, at(session_before_compact_server_default, contextSession)),
|
|
1504
|
+
via({ event: "session_compact" }, at(session_compact_server_default, contextSession)),
|
|
1505
|
+
via({ event: "session_start" }, at(session_start_server_default, contextSession)),
|
|
1506
|
+
via({ event: "session_tree" }, at(session_tree_server_default, contextSession)),
|
|
1507
|
+
via({ event: "turn_end" }, at(turn_end_server_default, contextSession))
|
|
1508
|
+
];
|
|
1509
|
+
},
|
|
1510
|
+
services: [...scopeSession.services ?? []],
|
|
1511
|
+
get activities() {
|
|
1512
|
+
return [...scopeSession.activities ?? []];
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
});
|
|
1517
|
+
//#endregion
|
|
1518
|
+
export { serverPlugin as default, serverPlugin };
|