@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,2658 @@
|
|
|
1
|
+
import { i as __toESM, t as __commonJSMin } from "./rolldown-runtime-B-lAHAz2.js";
|
|
2
|
+
import { Hn as BACKGROUND_CONTEXT, Qn as readPoFs, Sn as getOrThrow, V as String$1, _n as fileMutationRunner, ht as Optional, mn as piAgentDirectory, pt as _Object_, tr as requirePoFs, v as composeServerProviderOverrides } from "./serverPlugin-CELT6P0Q.js";
|
|
3
|
+
import { r as PO_EDIT_PRESENCE_SERVICE } from "./packageApi-t1oCjNDU.js";
|
|
4
|
+
import { i as FileTooLargeError, o as readBoundedFile, s as readTextIfExists } from "./platform-BIEiM4TG.js";
|
|
5
|
+
import { p as resolvePlanningPlansDirectory } from "./layeredConfig-CUkYUs1f.js";
|
|
6
|
+
import "./piSettings-Cf1QofNe.js";
|
|
7
|
+
import { u as readPoConfig } from "./harnessState-Dwrk3lfv.js";
|
|
8
|
+
import "./value-_W31So3B.js";
|
|
9
|
+
import "./exports-nV43ShA7.js";
|
|
10
|
+
import { a as WORKFLOW_STEP_SESSION_PROVENANCE } from "./hubChannel-Cm-sxOvU.js";
|
|
11
|
+
import { a as defineHook, c as defineRoot, g as runCleanups, h as defineServerPlugin, l as defineRoute, n as composeRootInjects, r as defineChannel, t as composeRootHooks } from "./extensionFile-DNM4xsje.js";
|
|
12
|
+
import { r as PO_CHILD_SESSION_HOOK_REGISTRY_SERVICE, s as readPoChildSessionLabels } from "./childSession-Cf2-kH4O.js";
|
|
13
|
+
import { t as createPoTelemetry } from "./index.edge-ChYa2LU4.js";
|
|
14
|
+
import { f as parseFileHeader, i as computeFileTag, n as resolveInputPath, o as displayPath, r as resolveReadInputPath } from "./index.edge-ClLTmPFz.js";
|
|
15
|
+
import { t as Hono } from "./dist-B-vqs6tA.js";
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
//#region ../../default/po-file-edit/src/constants/editPresence.ts
|
|
19
|
+
const PRESENCE_NOTE_TITLE = "[Po: other active agents edited files in this result]";
|
|
20
|
+
const PRESENCE_NOTE_GUIDANCE = "Preserve unrelated edits. If coordination would help, you can use intercom to send to the session id, or ask the subagent by name if it is on your team. Contact is optional; this notice does not block editing.";
|
|
21
|
+
const SUBAGENT_PARENT_SESSION_ENV = "PI_SUBAGENT_PARENT_SESSION";
|
|
22
|
+
_Object_({
|
|
23
|
+
parentSessionId: String$1({ minLength: 1 }),
|
|
24
|
+
workingDirectory: String$1({ minLength: 1 }),
|
|
25
|
+
mode: Optional(String$1({ minLength: 1 }))
|
|
26
|
+
}, { additionalProperties: false });
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region ../../default/po-file-edit/src/services/editPathNames/index.ts
|
|
29
|
+
/** The directory this package owns, under whichever root holds agent state. */
|
|
30
|
+
const STATE_DIRECTORY = "po-file-edit";
|
|
31
|
+
/** A stable short name for a path or session key, so state files are found from those two alone. */
|
|
32
|
+
function pathHash(value) {
|
|
33
|
+
return createHash("sha256").update(value).digest("hex").slice(0, 16);
|
|
34
|
+
}
|
|
35
|
+
/** A subagent child writes to its parent's timeline, so the two stay one session to every reader. */
|
|
36
|
+
function sessionKeyFor(sessionId, environment) {
|
|
37
|
+
if (environment["PI_SUBAGENT_CHILD"]) {
|
|
38
|
+
const parent = environment[SUBAGENT_PARENT_SESSION_ENV];
|
|
39
|
+
if (parent) return parent;
|
|
40
|
+
}
|
|
41
|
+
return sessionId;
|
|
42
|
+
}
|
|
43
|
+
/** Where every session's state lives: beside the other Po packages' agent state, never in the working tree. */
|
|
44
|
+
function stateDirectoryFor(environment) {
|
|
45
|
+
return path.join(piAgentDirectory(environment, environment.HOME), STATE_DIRECTORY);
|
|
46
|
+
}
|
|
47
|
+
/** Snapshots sit beside their timeline and take its name, so the two are found and cleared together. */
|
|
48
|
+
function snapshotsPathOf(timelinePath) {
|
|
49
|
+
return `${timelinePath.replace(/\.jsonl$/u, "")}.blobs`;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region ../../default/po-file-edit/src/services/fileSystemEditPaths/index.ts
|
|
53
|
+
var FileSystemEditPaths = class {
|
|
54
|
+
files;
|
|
55
|
+
environment;
|
|
56
|
+
constructor(files, environment = {}) {
|
|
57
|
+
this.files = files;
|
|
58
|
+
this.environment = environment;
|
|
59
|
+
}
|
|
60
|
+
sessionKey(sessionId, environment = this.environment) {
|
|
61
|
+
return sessionKeyFor(sessionId, environment);
|
|
62
|
+
}
|
|
63
|
+
stateDirectory() {
|
|
64
|
+
return stateDirectoryFor(this.environment);
|
|
65
|
+
}
|
|
66
|
+
async timelinePath(cwd, sessionKey) {
|
|
67
|
+
const directory = this.stateDirectory();
|
|
68
|
+
getOrThrow(await this.files.createDir(directory, { recursive: true }, BACKGROUND_CONTEXT));
|
|
69
|
+
const real = getOrThrow(await this.files.canonicalPath(cwd, BACKGROUND_CONTEXT));
|
|
70
|
+
return path.join(directory, `${pathHash(real)}-${pathHash(sessionKey)}.jsonl`);
|
|
71
|
+
}
|
|
72
|
+
async snapshotsPath(cwd, sessionKey) {
|
|
73
|
+
return snapshotsPathOf(await this.timelinePath(cwd, sessionKey));
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region ../../default/po-file-edit/src/services/fileSystemPresenceFiles/index.ts
|
|
78
|
+
function createFileSystemPresenceFiles(files) {
|
|
79
|
+
return {
|
|
80
|
+
async isFile(filePath) {
|
|
81
|
+
const real = await files.canonicalPath(filePath, BACKGROUND_CONTEXT);
|
|
82
|
+
if (!real.ok) return false;
|
|
83
|
+
const info = await files.fileInfo(real.value, BACKGROUND_CONTEXT);
|
|
84
|
+
return info.ok && info.value.kind === "file";
|
|
85
|
+
},
|
|
86
|
+
async realpath(filePath) {
|
|
87
|
+
const result = await files.canonicalPath(filePath, BACKGROUND_CONTEXT);
|
|
88
|
+
return result.ok ? result.value : void 0;
|
|
89
|
+
},
|
|
90
|
+
async read(filePath) {
|
|
91
|
+
const result = await files.readBinaryFile(filePath, BACKGROUND_CONTEXT);
|
|
92
|
+
return result.ok ? result.value : void 0;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region ../../default/po-file-edit/src/services/fileChanges/index.ts
|
|
98
|
+
const TOOLS = /* @__PURE__ */ new Set([
|
|
99
|
+
"edit",
|
|
100
|
+
"write",
|
|
101
|
+
"bash",
|
|
102
|
+
"user"
|
|
103
|
+
]);
|
|
104
|
+
function isRecord(value) {
|
|
105
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
106
|
+
}
|
|
107
|
+
function optionalString(value) {
|
|
108
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
109
|
+
}
|
|
110
|
+
function optionalCount(value) {
|
|
111
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
112
|
+
}
|
|
113
|
+
/** Narrows one parsed line, or answers null so a malformed line can be skipped. */
|
|
114
|
+
function parseTimelineEvent(value) {
|
|
115
|
+
if (!isRecord(value)) return null;
|
|
116
|
+
const { version, path: filePath, tool, at } = value;
|
|
117
|
+
if (typeof filePath !== "string" || filePath === "") return null;
|
|
118
|
+
if (typeof at !== "number" || !Number.isFinite(at)) return null;
|
|
119
|
+
if (typeof tool !== "string" || !TOOLS.has(tool)) return null;
|
|
120
|
+
if (version === 1) {
|
|
121
|
+
if (tool === "user") return null;
|
|
122
|
+
return {
|
|
123
|
+
version: 1,
|
|
124
|
+
path: filePath,
|
|
125
|
+
tool,
|
|
126
|
+
at
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (version !== 2) return null;
|
|
130
|
+
return {
|
|
131
|
+
version: 2,
|
|
132
|
+
path: filePath,
|
|
133
|
+
tool,
|
|
134
|
+
at,
|
|
135
|
+
origin: value.origin === "scan" ? "scan" : "tool",
|
|
136
|
+
...optionalString(value.before) === void 0 ? {} : { before: value.before },
|
|
137
|
+
...optionalString(value.after) === void 0 ? {} : { after: value.after },
|
|
138
|
+
...optionalCount(value.additions) === void 0 ? {} : { additions: value.additions },
|
|
139
|
+
...optionalCount(value.removals) === void 0 ? {} : { removals: value.removals },
|
|
140
|
+
...value.verified === true ? { verified: true } : {},
|
|
141
|
+
...value.created === true ? { created: true } : {}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/** Every recorded line of the timeline, malformed ones dropped, in file order. */
|
|
145
|
+
function parseTimeline(content, onMalformed) {
|
|
146
|
+
const events = [];
|
|
147
|
+
for (const line of content.split("\n")) {
|
|
148
|
+
if (line === "") continue;
|
|
149
|
+
let parsed;
|
|
150
|
+
try {
|
|
151
|
+
parsed = JSON.parse(line);
|
|
152
|
+
} catch {
|
|
153
|
+
onMalformed?.(line);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const event = parseTimelineEvent(parsed);
|
|
157
|
+
if (event === null) onMalformed?.(line);
|
|
158
|
+
else events.push(event);
|
|
159
|
+
}
|
|
160
|
+
return events;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Whether a recorded change is evidence that the file's content actually moved.
|
|
164
|
+
*
|
|
165
|
+
* A tool change names its file and reads both sides, so it always is. A scan
|
|
166
|
+
* change is a tree comparison of size and modification time, which a checkout,
|
|
167
|
+
* an install, or a command that merely touched a file moves as readily as an
|
|
168
|
+
* edit does; only a scan the tracker confirmed carries `verified`. Version 1
|
|
169
|
+
* lines predate the distinction entirely, so a bash one cannot be trusted.
|
|
170
|
+
*/
|
|
171
|
+
function isConfirmedChange(event) {
|
|
172
|
+
if (event.version !== 2) return event.tool !== "bash";
|
|
173
|
+
return event.origin !== "scan" || event.verified === true;
|
|
174
|
+
}
|
|
175
|
+
/** The recorded changes worth listing, which is every change but an unconfirmed touch. */
|
|
176
|
+
function confirmedChanges(events) {
|
|
177
|
+
return events.filter(isConfirmedChange);
|
|
178
|
+
}
|
|
179
|
+
/** One row per file, newest change first, which is the order both docks list in. */
|
|
180
|
+
function foldEntries(events) {
|
|
181
|
+
const folded = /* @__PURE__ */ new Map();
|
|
182
|
+
for (const event of events) {
|
|
183
|
+
const current = folded.get(event.path);
|
|
184
|
+
folded.set(event.path, {
|
|
185
|
+
path: event.path,
|
|
186
|
+
tool: event.at >= (current?.at ?? 0) ? event.tool : current?.tool ?? event.tool,
|
|
187
|
+
at: Math.max(event.at, current?.at ?? 0),
|
|
188
|
+
count: (current?.count ?? 0) + 1
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return [...folded.values()].sort((left, right) => right.at - left.at);
|
|
192
|
+
}
|
|
193
|
+
/** One file's history, oldest first, numbered so a reader can name a version. */
|
|
194
|
+
function foldVersions(events, filePath) {
|
|
195
|
+
return events.filter((event) => event.path === filePath).sort((left, right) => left.at - right.at).map((event, offset) => {
|
|
196
|
+
const version = {
|
|
197
|
+
index: offset + 1,
|
|
198
|
+
tool: event.tool,
|
|
199
|
+
at: event.at,
|
|
200
|
+
origin: event.version === 2 ? event.origin : "scan"
|
|
201
|
+
};
|
|
202
|
+
if (event.version !== 2) return version;
|
|
203
|
+
return {
|
|
204
|
+
...version,
|
|
205
|
+
...event.before === void 0 ? {} : { before: event.before },
|
|
206
|
+
...event.after === void 0 ? {} : { after: event.after },
|
|
207
|
+
...event.additions === void 0 ? {} : { additions: event.additions },
|
|
208
|
+
...event.removals === void 0 ? {} : { removals: event.removals },
|
|
209
|
+
...event.verified === true ? { verified: true } : {},
|
|
210
|
+
...event.created === true ? { created: true } : {}
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Whether a file can be diffed at all: some version has to give the diff a
|
|
216
|
+
* starting point. A captured baseline is one. So is a version that created the
|
|
217
|
+
* file, whose starting point is nothing at all.
|
|
218
|
+
*
|
|
219
|
+
* A file only ever seen after the fact, which is every file a bash script
|
|
220
|
+
* wrote, still cannot be.
|
|
221
|
+
*/
|
|
222
|
+
function isDiffable(versions) {
|
|
223
|
+
return versions.some((version) => version.before !== void 0 || version.created === true);
|
|
224
|
+
}
|
|
225
|
+
/** The oldest captured baseline for a file, which is what the whole-session diff starts from. */
|
|
226
|
+
function baselineOf(versions) {
|
|
227
|
+
return versions.find((version) => version.before !== void 0)?.before;
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region ../../default/po-file-edit/src/services/poIgnore/index.ts
|
|
231
|
+
var import_ignore = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
232
|
+
function makeArray(subject) {
|
|
233
|
+
return Array.isArray(subject) ? subject : [subject];
|
|
234
|
+
}
|
|
235
|
+
const UNDEFINED = void 0;
|
|
236
|
+
const EMPTY = "";
|
|
237
|
+
const SPACE = " ";
|
|
238
|
+
const ESCAPE = "\\";
|
|
239
|
+
const REGEX_LITERAL_SPECIAL = /[.*+?()[\]{}^$|\\/]/;
|
|
240
|
+
const BOM = "";
|
|
241
|
+
const REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
|
|
242
|
+
const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
|
|
243
|
+
const REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
|
|
244
|
+
const REGEX_SPLITALL_CRLF = /\r?\n/g;
|
|
245
|
+
const DOUBLE_SLASH = "//";
|
|
246
|
+
const SLASH_CODE = 47;
|
|
247
|
+
const DOT_CODE = 46;
|
|
248
|
+
const SLASH = "/";
|
|
249
|
+
let TMP_KEY_IGNORE = "node-ignore";
|
|
250
|
+
/* istanbul ignore else */
|
|
251
|
+
if (typeof Symbol !== "undefined") TMP_KEY_IGNORE = Symbol.for("node-ignore");
|
|
252
|
+
const KEY_IGNORE = TMP_KEY_IGNORE;
|
|
253
|
+
const define = (object, key, value) => {
|
|
254
|
+
Object.defineProperty(object, key, { value });
|
|
255
|
+
return value;
|
|
256
|
+
};
|
|
257
|
+
const RETURN_FALSE = () => false;
|
|
258
|
+
const cleanRangeBackSlash = (slashes) => {
|
|
259
|
+
const { length } = slashes;
|
|
260
|
+
return slashes.slice(0, length - length % 2);
|
|
261
|
+
};
|
|
262
|
+
const POSIX_CLASSES = {
|
|
263
|
+
alnum: "0-9A-Za-z",
|
|
264
|
+
alpha: "A-Za-z",
|
|
265
|
+
blank: " \\t",
|
|
266
|
+
cntrl: "\\x00-\\x1f\\x7f",
|
|
267
|
+
digit: "0-9",
|
|
268
|
+
graph: "!-.0-~",
|
|
269
|
+
lower: "a-z",
|
|
270
|
+
print: " -.0-~",
|
|
271
|
+
punct: "!-.:-@\\[-`{-~",
|
|
272
|
+
space: " \\t\\n\\r",
|
|
273
|
+
upper: "A-Z",
|
|
274
|
+
xdigit: "0-9A-Fa-f"
|
|
275
|
+
};
|
|
276
|
+
const CLASS_MEMBERS_TO_ESCAPE = "\\]^-[";
|
|
277
|
+
const escapeMember = (char) => CLASS_MEMBERS_TO_ESCAPE.indexOf(char) < 0 ? char : ESCAPE + char;
|
|
278
|
+
const NON_SLASH = "(?!\\/)";
|
|
279
|
+
const classSource = (negated, body) => {
|
|
280
|
+
if (negated) return `[^\\/${body}]`;
|
|
281
|
+
const source = `[${body}]`;
|
|
282
|
+
return new RegExp(source).test("/") ? NON_SLASH + source : source;
|
|
283
|
+
};
|
|
284
|
+
const scanBracket = (pattern, start) => {
|
|
285
|
+
const { length } = pattern;
|
|
286
|
+
let index = start + 1;
|
|
287
|
+
let negated = EMPTY;
|
|
288
|
+
const lead = pattern[index];
|
|
289
|
+
if (lead === "!" || lead === "^") {
|
|
290
|
+
negated = "^";
|
|
291
|
+
index++;
|
|
292
|
+
}
|
|
293
|
+
let body = EMPTY;
|
|
294
|
+
let prev = EMPTY;
|
|
295
|
+
for (;;) {
|
|
296
|
+
const char = pattern[index];
|
|
297
|
+
if (char === UNDEFINED) return null;
|
|
298
|
+
if (char === ESCAPE) {
|
|
299
|
+
const escaped = pattern[index + 1];
|
|
300
|
+
if (escaped === UNDEFINED) return null;
|
|
301
|
+
body += escapeMember(escaped);
|
|
302
|
+
prev = escaped;
|
|
303
|
+
index++;
|
|
304
|
+
} else if (char === "-" && prev && index + 1 < length && pattern[index + 1] !== "]") {
|
|
305
|
+
index++;
|
|
306
|
+
let to = pattern[index];
|
|
307
|
+
if (to === ESCAPE) to = pattern[index += 1];
|
|
308
|
+
if (prev <= to) body += `-${escapeMember(to)}`;
|
|
309
|
+
prev = EMPTY;
|
|
310
|
+
} else if (char === "[" && pattern[index + 1] === ":") {
|
|
311
|
+
const nameStart = index + 2;
|
|
312
|
+
let end = nameStart;
|
|
313
|
+
while (end < length && pattern[end] !== "]") end++;
|
|
314
|
+
if (end === length) return null;
|
|
315
|
+
if (end > nameStart && pattern[end - 1] === ":") {
|
|
316
|
+
const expanded = POSIX_CLASSES[pattern.slice(nameStart, end - 1)];
|
|
317
|
+
if (expanded === UNDEFINED) return null;
|
|
318
|
+
body += expanded;
|
|
319
|
+
prev = EMPTY;
|
|
320
|
+
index = end;
|
|
321
|
+
} else {
|
|
322
|
+
body += escapeMember("[");
|
|
323
|
+
prev = "[";
|
|
324
|
+
index = nameStart - 2;
|
|
325
|
+
}
|
|
326
|
+
} else {
|
|
327
|
+
body += escapeMember(char);
|
|
328
|
+
prev = char;
|
|
329
|
+
}
|
|
330
|
+
index++;
|
|
331
|
+
if (pattern[index] === "]") return {
|
|
332
|
+
end: index,
|
|
333
|
+
source: classSource(negated, body)
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
const NEVER_MATCH = "[]";
|
|
338
|
+
const PLACEHOLDER = "\0";
|
|
339
|
+
const REGEX_RESTORE_PLACEHOLDER = new RegExp(`${PLACEHOLDER}(\\d+)${PLACEHOLDER}`, "g");
|
|
340
|
+
const TRAILING_WILDCARD = "";
|
|
341
|
+
const TRAILING_DOUBLESTAR = "";
|
|
342
|
+
const extractBrackets = (pattern) => {
|
|
343
|
+
const sources = [];
|
|
344
|
+
const hold = (source) => `${PLACEHOLDER}${sources.push(source) - 1}${PLACEHOLDER}`;
|
|
345
|
+
const { length } = pattern;
|
|
346
|
+
let out = EMPTY;
|
|
347
|
+
let index = 0;
|
|
348
|
+
while (index < length) {
|
|
349
|
+
const char = pattern[index];
|
|
350
|
+
if (char === ESCAPE) {
|
|
351
|
+
const escaped = pattern[index + 1];
|
|
352
|
+
if (escaped === UNDEFINED || escaped === SLASH && index + 2 === length) out += hold(NEVER_MATCH);
|
|
353
|
+
else if (escaped === "*" || escaped === "[" || escaped === SPACE || escaped === ESCAPE) out += pattern.slice(index, index + 2);
|
|
354
|
+
else out += hold(REGEX_LITERAL_SPECIAL.test(escaped) ? ESCAPE + escaped : escaped);
|
|
355
|
+
index += 2;
|
|
356
|
+
} else if (char === PLACEHOLDER) {
|
|
357
|
+
out += hold(`[${PLACEHOLDER}]`);
|
|
358
|
+
index++;
|
|
359
|
+
} else if (char === "[") {
|
|
360
|
+
const scanned = scanBracket(pattern, index);
|
|
361
|
+
if (scanned === null) {
|
|
362
|
+
out += hold(NEVER_MATCH);
|
|
363
|
+
index = length;
|
|
364
|
+
} else {
|
|
365
|
+
out += hold(scanned.source);
|
|
366
|
+
index = scanned.end + 1;
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
out += char;
|
|
370
|
+
index++;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
source: out,
|
|
375
|
+
sources
|
|
376
|
+
};
|
|
377
|
+
};
|
|
378
|
+
const DIRECT = null;
|
|
379
|
+
const REGEX_INNER_SLASH = /\/(?!$)/;
|
|
380
|
+
const REPLACERS = [
|
|
381
|
+
[
|
|
382
|
+
/(\\+)( ?)/g,
|
|
383
|
+
(_, run, space) => space ? run.slice(0, run.length - run.length % 2) + SPACE : run,
|
|
384
|
+
"\\ "
|
|
385
|
+
],
|
|
386
|
+
[/[\\$.|*+(){^]/g, (match) => `\\${match}`],
|
|
387
|
+
[
|
|
388
|
+
/(?!\\)\?/g,
|
|
389
|
+
() => "[^/]",
|
|
390
|
+
"?"
|
|
391
|
+
],
|
|
392
|
+
[
|
|
393
|
+
/^\//,
|
|
394
|
+
() => "^",
|
|
395
|
+
SLASH
|
|
396
|
+
],
|
|
397
|
+
[
|
|
398
|
+
/\//g,
|
|
399
|
+
() => "\\/",
|
|
400
|
+
SLASH
|
|
401
|
+
],
|
|
402
|
+
[
|
|
403
|
+
/^\^*(?:\\\*\\\*\\\/)+/,
|
|
404
|
+
() => "^(?:.*\\/)?",
|
|
405
|
+
"*"
|
|
406
|
+
],
|
|
407
|
+
[DIRECT, (source, pattern) => {
|
|
408
|
+
if (!source || source[0] === "^") return source;
|
|
409
|
+
return (!REGEX_INNER_SLASH.test(pattern) ? "(?:^|\\/)" : "^") + source;
|
|
410
|
+
}],
|
|
411
|
+
[
|
|
412
|
+
/\\\/\\\*\\\*(?=\\\/|$)/g,
|
|
413
|
+
(_, index, str) => index + 6 < str.length ? str.slice(index + 6) === "\\/" ? "(?:\\/[^\\/]+)+" : "(?:\\/[^\\/]+)*" : `\\/${TRAILING_DOUBLESTAR}`,
|
|
414
|
+
"*"
|
|
415
|
+
],
|
|
416
|
+
[
|
|
417
|
+
/(^|[^\\]+)(\\\*)+(?=.+)/g,
|
|
418
|
+
(_, p1, p2) => {
|
|
419
|
+
return p1 + p2.replace(/\\\*/g, "[^\\/]*");
|
|
420
|
+
},
|
|
421
|
+
"*"
|
|
422
|
+
],
|
|
423
|
+
[
|
|
424
|
+
/(^|[^\\])((?:\\\\)*)\\\*$/,
|
|
425
|
+
(match, p1, p2) => p2.length / 2 % 2 === 0 ? p1 + p2 + TRAILING_WILDCARD : match,
|
|
426
|
+
"*"
|
|
427
|
+
],
|
|
428
|
+
[
|
|
429
|
+
/\\\\\\(?=[$.|*+(){^])/g,
|
|
430
|
+
() => ESCAPE,
|
|
431
|
+
"\\\\"
|
|
432
|
+
],
|
|
433
|
+
[
|
|
434
|
+
/\\\\/g,
|
|
435
|
+
() => ESCAPE,
|
|
436
|
+
"\\\\"
|
|
437
|
+
],
|
|
438
|
+
[
|
|
439
|
+
/\\\[([^\]/]*?)(\\*)($|\])/g,
|
|
440
|
+
(match, range, endEscape, close) => `\\[${range}${cleanRangeBackSlash(endEscape)}${close}`,
|
|
441
|
+
"["
|
|
442
|
+
],
|
|
443
|
+
[DIRECT, (source) => {
|
|
444
|
+
const last = source[source.length - 1];
|
|
445
|
+
if (!last || last === TRAILING_WILDCARD || last === TRAILING_DOUBLESTAR) return source;
|
|
446
|
+
return last === SLASH ? `${source}$` : `${source}(?=$|\\/$)`;
|
|
447
|
+
}]
|
|
448
|
+
];
|
|
449
|
+
const REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\uE000$/;
|
|
450
|
+
const MODE_IGNORE = "regex";
|
|
451
|
+
const MODE_CHECK_IGNORE = "checkRegex";
|
|
452
|
+
const replaceTrailingWildcard = (_, p1) => {
|
|
453
|
+
return `${p1 ? `${p1}[^/]+` : "[^/]*"}(?=$|\\/$)`;
|
|
454
|
+
};
|
|
455
|
+
const REGEX_REPLACE_TRAILING_DOUBLESTAR = /\uE001$/;
|
|
456
|
+
const replaceTrailingDoublestar = () => ".+(?=$|\\/$)";
|
|
457
|
+
const WILDCARD = "[^\\/]*";
|
|
458
|
+
const separatorAfter = (run, at) => {
|
|
459
|
+
let separator = EMPTY;
|
|
460
|
+
for (let index = at + 1; index < run.length && !run[index].wildcard; index++) separator += run[index].single;
|
|
461
|
+
return separator;
|
|
462
|
+
};
|
|
463
|
+
const pinWildcards = (source) => {
|
|
464
|
+
if (source.indexOf(WILDCARD) < 0) return source;
|
|
465
|
+
const tokens = [];
|
|
466
|
+
const { length } = source;
|
|
467
|
+
let index = 0;
|
|
468
|
+
while (index < length) {
|
|
469
|
+
const char = source[index];
|
|
470
|
+
if (source.startsWith(WILDCARD, index)) {
|
|
471
|
+
tokens.push({ wildcard: true });
|
|
472
|
+
index += 6;
|
|
473
|
+
} else if (char === "[") {
|
|
474
|
+
let end = index + 1;
|
|
475
|
+
if (source[end] === "^") end++;
|
|
476
|
+
if (source[end] === "]") end++;
|
|
477
|
+
while (end < length && source[end] !== "]") end += source[end] === ESCAPE ? 2 : 1;
|
|
478
|
+
end++;
|
|
479
|
+
tokens.push({ single: source.slice(index, end) });
|
|
480
|
+
index = end;
|
|
481
|
+
} else if (char === ESCAPE) {
|
|
482
|
+
tokens.push({ single: source.slice(index, index + 2) });
|
|
483
|
+
index += 2;
|
|
484
|
+
} else if (char === "(") {
|
|
485
|
+
let depth = 0;
|
|
486
|
+
let end = index;
|
|
487
|
+
do {
|
|
488
|
+
if (source[end] === ESCAPE) end++;
|
|
489
|
+
else if (source[end] === "(") depth++;
|
|
490
|
+
else if (source[end] === ")") depth--;
|
|
491
|
+
end++;
|
|
492
|
+
} while (end < length && depth > 0);
|
|
493
|
+
if ("*+?".indexOf(source[end]) >= 0) end++;
|
|
494
|
+
tokens.push({ boundary: source.slice(index, end) });
|
|
495
|
+
index = end;
|
|
496
|
+
} else if (char === "^" || char === "$") {
|
|
497
|
+
tokens.push({ boundary: char });
|
|
498
|
+
index++;
|
|
499
|
+
} else {
|
|
500
|
+
tokens.push({ single: char });
|
|
501
|
+
index++;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
let out = EMPTY;
|
|
505
|
+
let run = [];
|
|
506
|
+
const flush = () => {
|
|
507
|
+
let lastWildcard;
|
|
508
|
+
run.forEach((token, at) => {
|
|
509
|
+
if (token.wildcard) lastWildcard = at;
|
|
510
|
+
});
|
|
511
|
+
run.forEach((token, at) => {
|
|
512
|
+
if (!token.wildcard) {
|
|
513
|
+
out += token.single;
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
out += at === lastWildcard ? WILDCARD : `(?:(?!${separatorAfter(run, at)})[^\\/])*`;
|
|
517
|
+
});
|
|
518
|
+
run = [];
|
|
519
|
+
};
|
|
520
|
+
tokens.forEach((token) => {
|
|
521
|
+
if (token.boundary === void 0) {
|
|
522
|
+
run.push(token);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
flush();
|
|
526
|
+
out += token.boundary;
|
|
527
|
+
});
|
|
528
|
+
flush();
|
|
529
|
+
return out;
|
|
530
|
+
};
|
|
531
|
+
const makeRegexPrefix = (pattern) => {
|
|
532
|
+
const { source, sources } = extractBrackets(pattern);
|
|
533
|
+
const replaced = REPLACERS.reduce((prev, [matcher, replacer, required]) => {
|
|
534
|
+
if (matcher === DIRECT) return replacer(prev, pattern);
|
|
535
|
+
if (required !== UNDEFINED && prev.indexOf(required) < 0) return prev;
|
|
536
|
+
return matcher.test(prev) ? prev.replace(matcher, replacer.bind(pattern)) : prev;
|
|
537
|
+
}, source);
|
|
538
|
+
return sources.length ? replaced.replace(REGEX_RESTORE_PLACEHOLDER, (match, index) => sources[index]) : replaced;
|
|
539
|
+
};
|
|
540
|
+
const checkSourceOf = (body, prefix) => {
|
|
541
|
+
if (body[body.length - 1] === SLASH) prefix = makeRegexPrefix(body.slice(0, -1));
|
|
542
|
+
const head = prefix.slice(0, -1);
|
|
543
|
+
const last = prefix[prefix.length - 1];
|
|
544
|
+
return last === TRAILING_WILDCARD ? `${head}$` : last === TRAILING_DOUBLESTAR ? `${head}.*$` : NEVER_MATCH;
|
|
545
|
+
};
|
|
546
|
+
const matchesBasename = (body) => {
|
|
547
|
+
const index = body.indexOf(SLASH);
|
|
548
|
+
return index < 0 || index === body.length - 1;
|
|
549
|
+
};
|
|
550
|
+
const basenameOf = (path) => {
|
|
551
|
+
const end = path.length - 1;
|
|
552
|
+
const index = path.lastIndexOf(SLASH, path[end] === SLASH ? end - 1 : end);
|
|
553
|
+
return index < 0 ? path : path.slice(index + 1);
|
|
554
|
+
};
|
|
555
|
+
const parentOf = (path) => {
|
|
556
|
+
if (path.charCodeAt(0) === SLASH_CODE || path.indexOf(DOUBLE_SLASH) >= 0) {
|
|
557
|
+
const slices = path.split(SLASH).filter(Boolean);
|
|
558
|
+
slices.pop();
|
|
559
|
+
return slices.length ? slices.join(SLASH) + SLASH : EMPTY;
|
|
560
|
+
}
|
|
561
|
+
const end = path.length - 1;
|
|
562
|
+
const cut = path.lastIndexOf(SLASH, path.charCodeAt(end) === SLASH_CODE ? end - 1 : end);
|
|
563
|
+
return cut < 0 ? EMPTY : path.slice(0, cut + 1);
|
|
564
|
+
};
|
|
565
|
+
const isString = (subject) => typeof subject === "string";
|
|
566
|
+
const checkPattern = (pattern) => pattern && isString(pattern) && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern);
|
|
567
|
+
const splitPattern = (pattern) => pattern.split(REGEX_SPLITALL_CRLF).filter(Boolean);
|
|
568
|
+
var IgnoreRule = class {
|
|
569
|
+
constructor(pattern, mark, body, ignoreCase, negative, prefix) {
|
|
570
|
+
this.pattern = pattern;
|
|
571
|
+
this.mark = mark;
|
|
572
|
+
this.negative = negative;
|
|
573
|
+
define(this, "body", body);
|
|
574
|
+
define(this, "ignoreCase", ignoreCase);
|
|
575
|
+
define(this, "regexPrefix", prefix);
|
|
576
|
+
}
|
|
577
|
+
get _basenameOnly() {
|
|
578
|
+
return define(this, "_basenameOnly", matchesBasename(this.body));
|
|
579
|
+
}
|
|
580
|
+
get regex() {
|
|
581
|
+
const key = "_regex";
|
|
582
|
+
if (this[key]) return this[key];
|
|
583
|
+
return this._make(MODE_IGNORE, key);
|
|
584
|
+
}
|
|
585
|
+
get checkRegex() {
|
|
586
|
+
const key = "_checkRegex";
|
|
587
|
+
if (this[key]) return this[key];
|
|
588
|
+
return this._make(MODE_CHECK_IGNORE, key);
|
|
589
|
+
}
|
|
590
|
+
_make(mode, key) {
|
|
591
|
+
const str = pinWildcards(mode === MODE_IGNORE ? this.regexPrefix.replace(REGEX_REPLACE_TRAILING_WILDCARD, replaceTrailingWildcard).replace(REGEX_REPLACE_TRAILING_DOUBLESTAR, replaceTrailingDoublestar) : checkSourceOf(this.body, this.regexPrefix));
|
|
592
|
+
const regex = this.ignoreCase ? new RegExp(str, "i") : new RegExp(str);
|
|
593
|
+
return define(this, key, regex);
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
const isLineEnd = (char) => char === "\r" || char === "\n";
|
|
597
|
+
const trimEnd = (body) => {
|
|
598
|
+
let end = body.length;
|
|
599
|
+
while (end && isLineEnd(body[end - 1])) end--;
|
|
600
|
+
const lineEnd = end;
|
|
601
|
+
while (end && body[end - 1] === SPACE) end--;
|
|
602
|
+
if (end === lineEnd) return body.slice(0, end);
|
|
603
|
+
let backslashes = 0;
|
|
604
|
+
while (backslashes < end && body[end - backslashes - 1] === ESCAPE) backslashes++;
|
|
605
|
+
return backslashes % 2 ? body.slice(0, end - 1) + SPACE : body.slice(0, end);
|
|
606
|
+
};
|
|
607
|
+
const createRule = ({ pattern, mark }, ignoreCase) => {
|
|
608
|
+
let body = pattern[0] === BOM ? pattern.slice(1) : pattern;
|
|
609
|
+
if (body[0] === "#") return;
|
|
610
|
+
let negative = false;
|
|
611
|
+
if (body[0] === "!") {
|
|
612
|
+
negative = true;
|
|
613
|
+
body = body.slice(1);
|
|
614
|
+
}
|
|
615
|
+
const last = body[body.length - 1];
|
|
616
|
+
if (last === SPACE || last === "\r" || last === "\n") body = trimEnd(body);
|
|
617
|
+
if (!body) return;
|
|
618
|
+
body = body.replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, "!").replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, "#");
|
|
619
|
+
const regexPrefix = makeRegexPrefix(body);
|
|
620
|
+
return new IgnoreRule(pattern, mark, body, ignoreCase, negative, regexPrefix);
|
|
621
|
+
};
|
|
622
|
+
var RuleManager = class {
|
|
623
|
+
constructor(ignoreCase) {
|
|
624
|
+
this._ignoreCase = ignoreCase;
|
|
625
|
+
this._rules = [];
|
|
626
|
+
this._basenameCount = 0;
|
|
627
|
+
}
|
|
628
|
+
_add(pattern) {
|
|
629
|
+
if (pattern && pattern[KEY_IGNORE]) {
|
|
630
|
+
this._rules = this._rules.concat(pattern._rules._rules);
|
|
631
|
+
this._basenameCount += pattern._rules._basenameCount;
|
|
632
|
+
this._added = true;
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
if (isString(pattern)) pattern = { pattern };
|
|
636
|
+
const rule = checkPattern(pattern.pattern) && createRule(pattern, this._ignoreCase);
|
|
637
|
+
if (rule) {
|
|
638
|
+
this._added = true;
|
|
639
|
+
this._rules.push(rule);
|
|
640
|
+
if (matchesBasename(rule.body)) this._basenameCount++;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
add(pattern) {
|
|
644
|
+
this._added = false;
|
|
645
|
+
makeArray(isString(pattern) ? splitPattern(pattern) : pattern).forEach(this._add, this);
|
|
646
|
+
if (this._added) this._literalRules = UNDEFINED;
|
|
647
|
+
return this._added;
|
|
648
|
+
}
|
|
649
|
+
testLiteral(path) {
|
|
650
|
+
const rules = this._literalRules || (this._literalRules = this._rules.filter(({ body }) => body[body.length - (body[body.length - 1] === SLASH ? 2 : 1)] === "*"));
|
|
651
|
+
let ignored = false;
|
|
652
|
+
let unignored = false;
|
|
653
|
+
let matchedRule;
|
|
654
|
+
for (let index = rules.length - 1; index >= 0; index--) {
|
|
655
|
+
const rule = rules[index];
|
|
656
|
+
if (rule.checkRegex.test(path)) {
|
|
657
|
+
ignored = !rule.negative;
|
|
658
|
+
unignored = rule.negative;
|
|
659
|
+
matchedRule = rule.negative ? UNDEFINED : rule;
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
const ret = {
|
|
664
|
+
ignored,
|
|
665
|
+
unignored
|
|
666
|
+
};
|
|
667
|
+
if (matchedRule) ret.rule = matchedRule;
|
|
668
|
+
return ret;
|
|
669
|
+
}
|
|
670
|
+
test(path, checkUnignored, mode) {
|
|
671
|
+
let ignored = false;
|
|
672
|
+
let unignored = false;
|
|
673
|
+
let matchedRule;
|
|
674
|
+
const rules = this._rules;
|
|
675
|
+
const { length } = rules;
|
|
676
|
+
const shortcut = this._basenameCount * 2 >= length;
|
|
677
|
+
const basename = shortcut ? basenameOf(path) : path;
|
|
678
|
+
for (let index = 0; index < length; index++) {
|
|
679
|
+
const rule = rules[index];
|
|
680
|
+
const { negative } = rule;
|
|
681
|
+
if (!(unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) && rule[mode].test(shortcut && rule._basenameOnly ? basename : path)) {
|
|
682
|
+
ignored = !negative;
|
|
683
|
+
unignored = negative;
|
|
684
|
+
matchedRule = negative ? UNDEFINED : rule;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
const ret = {
|
|
688
|
+
ignored,
|
|
689
|
+
unignored
|
|
690
|
+
};
|
|
691
|
+
if (matchedRule) ret.rule = matchedRule;
|
|
692
|
+
return ret;
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
const throwError = (message, Ctor) => {
|
|
696
|
+
throw new Ctor(message);
|
|
697
|
+
};
|
|
698
|
+
const checkPath = (path, originalPath, doThrow) => {
|
|
699
|
+
if (!isString(path)) return doThrow(`path must be a string, but got \`${originalPath}\``, TypeError);
|
|
700
|
+
if (!path) return doThrow(`path must not be empty`, TypeError);
|
|
701
|
+
if (checkPath.isNotRelative(path)) return doThrow(`path should be a \`path.relative()\`d string, but got "${originalPath}"`, RangeError);
|
|
702
|
+
return true;
|
|
703
|
+
};
|
|
704
|
+
const isNotRelative = (path) => {
|
|
705
|
+
const first = path.charCodeAt(0);
|
|
706
|
+
if (first === SLASH_CODE) return true;
|
|
707
|
+
if (first !== DOT_CODE) return false;
|
|
708
|
+
if (path.length === 1) return true;
|
|
709
|
+
const second = path.charCodeAt(1);
|
|
710
|
+
if (second === SLASH_CODE) return true;
|
|
711
|
+
if (second !== DOT_CODE) return false;
|
|
712
|
+
return path.length === 2 || path.charCodeAt(2) === SLASH_CODE;
|
|
713
|
+
};
|
|
714
|
+
checkPath.isNotRelative = isNotRelative;
|
|
715
|
+
/* istanbul ignore next */
|
|
716
|
+
checkPath.convert = (p) => p;
|
|
717
|
+
var Ignore = class {
|
|
718
|
+
constructor({ ignorecase = true, ignoreCase = ignorecase, allowRelativePaths = false } = {}) {
|
|
719
|
+
define(this, KEY_IGNORE, true);
|
|
720
|
+
this._rules = new RuleManager(ignoreCase);
|
|
721
|
+
this._strictPathCheck = !allowRelativePaths;
|
|
722
|
+
this._initCache();
|
|
723
|
+
}
|
|
724
|
+
_initCache() {
|
|
725
|
+
this._ignoreCache = Object.create(null);
|
|
726
|
+
this._testCache = Object.create(null);
|
|
727
|
+
}
|
|
728
|
+
add(pattern) {
|
|
729
|
+
if (this._rules.add(pattern)) this._initCache();
|
|
730
|
+
return this;
|
|
731
|
+
}
|
|
732
|
+
addPattern(pattern) {
|
|
733
|
+
return this.add(pattern);
|
|
734
|
+
}
|
|
735
|
+
_test(originalPath, cache, checkUnignored) {
|
|
736
|
+
const path = originalPath && checkPath.convert(originalPath);
|
|
737
|
+
checkPath(path, originalPath, this._strictPathCheck ? throwError : RETURN_FALSE);
|
|
738
|
+
return this._t(path, cache, checkUnignored);
|
|
739
|
+
}
|
|
740
|
+
checkIgnore(path) {
|
|
741
|
+
if (path.charCodeAt(path.length - 1) !== SLASH_CODE) return this.test(path);
|
|
742
|
+
const dir = this._t(path, this._testCache, true);
|
|
743
|
+
if (dir.ignored) return dir;
|
|
744
|
+
const literal = this._rules.testLiteral(path);
|
|
745
|
+
return literal.ignored || literal.unignored ? literal : dir;
|
|
746
|
+
}
|
|
747
|
+
_t(path, cache, checkUnignored) {
|
|
748
|
+
if (path in cache) return cache[path];
|
|
749
|
+
const parentPath = parentOf(path);
|
|
750
|
+
const parent = parentPath ? this._t(parentPath, cache, checkUnignored) : UNDEFINED;
|
|
751
|
+
return cache[path] = parent && parent.ignored ? parent : this._rules.test(path, checkUnignored, MODE_IGNORE);
|
|
752
|
+
}
|
|
753
|
+
ignores(path) {
|
|
754
|
+
return this._test(path, this._ignoreCache, false).ignored;
|
|
755
|
+
}
|
|
756
|
+
createFilter() {
|
|
757
|
+
return (path) => !this.ignores(path);
|
|
758
|
+
}
|
|
759
|
+
filter(paths) {
|
|
760
|
+
return makeArray(paths).filter(this.createFilter());
|
|
761
|
+
}
|
|
762
|
+
test(path) {
|
|
763
|
+
return this._test(path, this._testCache, true);
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
const factory = (options) => new Ignore(options);
|
|
767
|
+
const isPathValid = (path) => checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
|
|
768
|
+
/* istanbul ignore next */
|
|
769
|
+
const setupWindows = () => {
|
|
770
|
+
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
771
|
+
checkPath.convert = makePosix;
|
|
772
|
+
const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
773
|
+
checkPath.isNotRelative = (path) => REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path) || isNotRelative(path);
|
|
774
|
+
};
|
|
775
|
+
/* istanbul ignore next */
|
|
776
|
+
if (typeof process !== "undefined" && process.platform === "win32") setupWindows();
|
|
777
|
+
module.exports = factory;
|
|
778
|
+
factory.default = factory;
|
|
779
|
+
module.exports.isPathValid = isPathValid;
|
|
780
|
+
define(module.exports, Symbol.for("setupWindows"), setupWindows);
|
|
781
|
+
})))(), 1);
|
|
782
|
+
function matchablePath(relPath) {
|
|
783
|
+
const normalized = relPath.replace(/\\/gu, "/");
|
|
784
|
+
if (normalized.length === 0 || normalized.includes("\0") || normalized === ".." || normalized.startsWith("../") || normalized.startsWith("/") || /^[A-Za-z]:\//u.test(normalized)) return;
|
|
785
|
+
return normalized;
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Builds the project's ignore test, or nothing when there are no rules.
|
|
789
|
+
*
|
|
790
|
+
* Shared because the same rules are needed twice: once when deciding what to
|
|
791
|
+
* record, and once when deciding what to list. A caller that built its own
|
|
792
|
+
* matcher would let the two drift apart.
|
|
793
|
+
*
|
|
794
|
+
* The test answers false for anything it cannot safely match, so a path that
|
|
795
|
+
* escapes the project stays visible rather than being hidden by accident.
|
|
796
|
+
*/
|
|
797
|
+
function createPoIgnoreMatcher(content) {
|
|
798
|
+
try {
|
|
799
|
+
if (content.trim().length === 0) return void 0;
|
|
800
|
+
const matcher = (0, import_ignore.default)().add(content);
|
|
801
|
+
return (relPath) => {
|
|
802
|
+
const candidate = matchablePath(relPath);
|
|
803
|
+
return candidate !== void 0 && matcher.ignores(candidate);
|
|
804
|
+
};
|
|
805
|
+
} catch {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
/** Applies project-local gitignore rules while keeping unsafe candidates visible. */
|
|
810
|
+
function filterPoIgnoredFiles(items, content) {
|
|
811
|
+
const ignored = createPoIgnoreMatcher(content);
|
|
812
|
+
if (ignored === void 0) return items;
|
|
813
|
+
return items.filter((item) => !ignored(item.relPath));
|
|
814
|
+
}
|
|
815
|
+
//#endregion
|
|
816
|
+
//#region ../../default/po-file-edit/src/services/sessionFileRows/index.ts
|
|
817
|
+
/**
|
|
818
|
+
* Presents a session's timeline as the rows the dock lists.
|
|
819
|
+
*
|
|
820
|
+
* A file the session changed and then removed is left out, and so is a path a
|
|
821
|
+
* bash call only touched: a command that moves a modification time without
|
|
822
|
+
* changing a byte is not an edit, and listing it buries the ones that are. The
|
|
823
|
+
* dock is a list of things to open, and a row that can only ever answer "this
|
|
824
|
+
* is gone" is a dead end; the timeline still holds the change, so a tab already
|
|
825
|
+
* open on the file keeps working and says so.
|
|
826
|
+
*/
|
|
827
|
+
async function sessionFileRows({ content, cwd, exists, readPoIgnore }) {
|
|
828
|
+
const events = confirmedChanges(parseTimeline(content));
|
|
829
|
+
const entries = foldEntries(events);
|
|
830
|
+
const present = await Promise.all(entries.map((entry) => exists(entry.path)));
|
|
831
|
+
const items = entries.filter((_entry, index) => present[index]).map((entry) => ({
|
|
832
|
+
path: entry.path,
|
|
833
|
+
relPath: path.relative(cwd, entry.path) || entry.path,
|
|
834
|
+
tool: entry.tool,
|
|
835
|
+
at: entry.at,
|
|
836
|
+
count: entry.count,
|
|
837
|
+
diffable: isDiffable(foldVersions(events, entry.path))
|
|
838
|
+
}));
|
|
839
|
+
try {
|
|
840
|
+
return filterPoIgnoredFiles(items, await readPoIgnore());
|
|
841
|
+
} catch {
|
|
842
|
+
return items;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
//#endregion
|
|
846
|
+
//#region ../../default/po-file-edit/src/services/fileSystemSessionFiles/index.ts
|
|
847
|
+
async function readSessionFilesFrom(files, timelinePath, cwd) {
|
|
848
|
+
const result = await files.readTextFile(timelinePath, BACKGROUND_CONTEXT);
|
|
849
|
+
if (!result.ok) return [];
|
|
850
|
+
return sessionFileRows({
|
|
851
|
+
content: result.value,
|
|
852
|
+
cwd,
|
|
853
|
+
async exists(filePath) {
|
|
854
|
+
const real = await files.canonicalPath(filePath, BACKGROUND_CONTEXT);
|
|
855
|
+
if (!real.ok) return false;
|
|
856
|
+
const info = await files.fileInfo(real.value, BACKGROUND_CONTEXT);
|
|
857
|
+
return info.ok && info.value.kind === "file";
|
|
858
|
+
},
|
|
859
|
+
readPoIgnore: async () => getOrThrow(await files.readTextFile(path.join(cwd, ".poignore"), BACKGROUND_CONTEXT))
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
//#endregion
|
|
863
|
+
//#region ../../default/po-file-edit/src/constants/snapshots.ts
|
|
864
|
+
/** Past this, a file is listed as changed without content rather than snapshotted. */
|
|
865
|
+
const MAX_SNAPSHOT_BYTES = 1048576;
|
|
866
|
+
//#endregion
|
|
867
|
+
//#region ../../default/po-file-edit/src/services/followedFileInfo/index.ts
|
|
868
|
+
/**
|
|
869
|
+
* File metadata that follows symbolic links, as a stat call does.
|
|
870
|
+
*
|
|
871
|
+
* `FileSystem.fileInfo` describes a link as a link. The Node adapters this
|
|
872
|
+
* package grew from all used `stat`, so a link to a file counted as that file
|
|
873
|
+
* and a link to a directory as a directory. Asking through here keeps every
|
|
874
|
+
* host answering the same, and the failure stays a real one: a dangling link
|
|
875
|
+
* is not found, a path through a file is not a directory.
|
|
876
|
+
*/
|
|
877
|
+
async function followedFileInfo(files, filePath) {
|
|
878
|
+
const named = await files.fileInfo(filePath, BACKGROUND_CONTEXT);
|
|
879
|
+
if (!named.ok || named.value.kind !== "symlink") return named;
|
|
880
|
+
const target = await files.canonicalPath(filePath, BACKGROUND_CONTEXT);
|
|
881
|
+
return target.ok ? files.fileInfo(target.value, BACKGROUND_CONTEXT) : target;
|
|
882
|
+
}
|
|
883
|
+
//#endregion
|
|
884
|
+
//#region ../../default/po-file-edit/src/services/fileSystemSnapshotStore/index.ts
|
|
885
|
+
var FileSystemSnapshotStore = class {
|
|
886
|
+
files;
|
|
887
|
+
directory;
|
|
888
|
+
constructor(files) {
|
|
889
|
+
this.files = files;
|
|
890
|
+
}
|
|
891
|
+
initialize(directory) {
|
|
892
|
+
this.directory = directory;
|
|
893
|
+
}
|
|
894
|
+
async capture(filePath) {
|
|
895
|
+
const info = await followedFileInfo(this.files, filePath);
|
|
896
|
+
if (!info.ok) {
|
|
897
|
+
if (info.error.code === "not_found" || info.error.code === "not_directory") return void 0;
|
|
898
|
+
throw info.error;
|
|
899
|
+
}
|
|
900
|
+
if (info.value.kind !== "file" || info.value.size > 1048576) return void 0;
|
|
901
|
+
let bytes;
|
|
902
|
+
try {
|
|
903
|
+
bytes = await readBoundedFile(this.files, filePath, MAX_SNAPSHOT_BYTES, BACKGROUND_CONTEXT);
|
|
904
|
+
} catch (error) {
|
|
905
|
+
if (error instanceof FileTooLargeError) return void 0;
|
|
906
|
+
throw error;
|
|
907
|
+
}
|
|
908
|
+
if (bytes.subarray(0, 8192).includes(0)) return void 0;
|
|
909
|
+
return this.put(new TextDecoder().decode(bytes));
|
|
910
|
+
}
|
|
911
|
+
async put(content) {
|
|
912
|
+
const directory = this.requireDirectory();
|
|
913
|
+
const hash = createHash("sha256").update(content, "utf8").digest("hex");
|
|
914
|
+
const target = path.join(directory, hash);
|
|
915
|
+
if (getOrThrow(await this.files.exists(target, BACKGROUND_CONTEXT))) return hash;
|
|
916
|
+
getOrThrow(await this.files.createDir(directory, { recursive: true }, BACKGROUND_CONTEXT));
|
|
917
|
+
getOrThrow(await this.files.writeFile(target, content, BACKGROUND_CONTEXT));
|
|
918
|
+
return hash;
|
|
919
|
+
}
|
|
920
|
+
async read(hash) {
|
|
921
|
+
if (!/^[0-9a-f]{64}$/u.test(hash)) return void 0;
|
|
922
|
+
const result = await this.files.readTextFile(path.join(this.requireDirectory(), hash), BACKGROUND_CONTEXT);
|
|
923
|
+
if (!result.ok && result.error.code === "not_found") return void 0;
|
|
924
|
+
return getOrThrow(result);
|
|
925
|
+
}
|
|
926
|
+
async clear() {
|
|
927
|
+
if (this.directory === void 0) return;
|
|
928
|
+
getOrThrow(await this.files.remove(this.directory, {
|
|
929
|
+
recursive: true,
|
|
930
|
+
force: true
|
|
931
|
+
}, BACKGROUND_CONTEXT));
|
|
932
|
+
}
|
|
933
|
+
requireDirectory() {
|
|
934
|
+
if (this.directory === void 0) throw new Error("Snapshot store is not initialized");
|
|
935
|
+
return this.directory;
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
//#endregion
|
|
939
|
+
//#region ../../default/po-file-edit/src/services/fileSystemTimelineStore/index.ts
|
|
940
|
+
/** The owning isolate serializes appends; cross-process Node writers retain TimelineStore's file lock. */
|
|
941
|
+
var FileSystemTimelineStore = class {
|
|
942
|
+
files;
|
|
943
|
+
filePath;
|
|
944
|
+
constructor(files) {
|
|
945
|
+
this.files = files;
|
|
946
|
+
}
|
|
947
|
+
initialize(filePath) {
|
|
948
|
+
this.filePath = filePath;
|
|
949
|
+
}
|
|
950
|
+
async append(event) {
|
|
951
|
+
const filePath = this.requirePath();
|
|
952
|
+
await fileMutationRunner.forKey(filePath)(async () => {
|
|
953
|
+
getOrThrow(await this.files.appendFile(filePath, `${JSON.stringify(event)}\n`, BACKGROUND_CONTEXT));
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
async list() {
|
|
957
|
+
return foldEntries(confirmedChanges(await this.events()));
|
|
958
|
+
}
|
|
959
|
+
async versions(filePath) {
|
|
960
|
+
return foldVersions(confirmedChanges(await this.events()), filePath);
|
|
961
|
+
}
|
|
962
|
+
async clear() {
|
|
963
|
+
getOrThrow(await this.files.remove(this.requirePath(), { force: true }, BACKGROUND_CONTEXT));
|
|
964
|
+
}
|
|
965
|
+
async events() {
|
|
966
|
+
const result = await this.files.readTextFile(this.requirePath(), BACKGROUND_CONTEXT);
|
|
967
|
+
if (!result.ok && result.error.code === "not_found") return [];
|
|
968
|
+
return parseTimeline(getOrThrow(result), (line) => console.warn(`Ignoring malformed file edit timeline line: ${line.slice(0, 200)}`));
|
|
969
|
+
}
|
|
970
|
+
requirePath() {
|
|
971
|
+
if (!this.filePath) throw new Error("Timeline store is not initialized");
|
|
972
|
+
return this.filePath;
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
//#endregion
|
|
976
|
+
//#region ../../default/po-file-edit/src/services/manifestComparison/index.ts
|
|
977
|
+
/**
|
|
978
|
+
* Directories a working tree fills with output nobody wants listed as an edit.
|
|
979
|
+
*
|
|
980
|
+
* Two kinds live here. Most are the build and dependency trees every checkout
|
|
981
|
+
* grows. The rest are where tooling, including this agent's own, writes while a
|
|
982
|
+
* session runs: a telemetry log under `logs`, a test run's artifacts under
|
|
983
|
+
* `test-results` and `playwright-report`, scratch space under `tmp`, and agent
|
|
984
|
+
* state under `.pi`. Those are skipped by construction rather than judged file
|
|
985
|
+
* by file, because a walk that enters them reports the session watching itself.
|
|
986
|
+
*/
|
|
987
|
+
const IGNORED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
988
|
+
".git",
|
|
989
|
+
".hg",
|
|
990
|
+
".svn",
|
|
991
|
+
".cache",
|
|
992
|
+
".gradle",
|
|
993
|
+
".next",
|
|
994
|
+
".nuxt",
|
|
995
|
+
".nx",
|
|
996
|
+
".pi",
|
|
997
|
+
".pnpm-store",
|
|
998
|
+
".turbo",
|
|
999
|
+
".venv",
|
|
1000
|
+
"__pycache__",
|
|
1001
|
+
"build",
|
|
1002
|
+
"coverage",
|
|
1003
|
+
"dist",
|
|
1004
|
+
"logs",
|
|
1005
|
+
"node_modules",
|
|
1006
|
+
"out",
|
|
1007
|
+
"playwright-report",
|
|
1008
|
+
"target",
|
|
1009
|
+
"test-results",
|
|
1010
|
+
"tmp",
|
|
1011
|
+
"vendor",
|
|
1012
|
+
"venv"
|
|
1013
|
+
]);
|
|
1014
|
+
/**
|
|
1015
|
+
* How a file is summarised. Size and modification time are what a walk can read
|
|
1016
|
+
* cheaply for thousands of files; hashing every one of them would turn a scan
|
|
1017
|
+
* into a read of the whole tree.
|
|
1018
|
+
*/
|
|
1019
|
+
function fingerprintOf(size, modifiedMs) {
|
|
1020
|
+
return `${size}:${modifiedMs}`;
|
|
1021
|
+
}
|
|
1022
|
+
/** The size half of a fingerprint, which only the adapter that wrote it can read. */
|
|
1023
|
+
function sizeOf(fingerprint) {
|
|
1024
|
+
const separator = fingerprint.indexOf(":");
|
|
1025
|
+
return separator === -1 ? fingerprint : fingerprint.slice(0, separator);
|
|
1026
|
+
}
|
|
1027
|
+
/** Every path added, removed, or modified between two manifests, sorted. */
|
|
1028
|
+
function changedBetween(before, after) {
|
|
1029
|
+
const moved = /* @__PURE__ */ new Set();
|
|
1030
|
+
for (const [filePath, fingerprint] of after.entries) if (before.entries.get(filePath) !== fingerprint) moved.add(filePath);
|
|
1031
|
+
for (const filePath of before.entries.keys()) if (!after.entries.has(filePath)) moved.add(filePath);
|
|
1032
|
+
return [...moved].sort();
|
|
1033
|
+
}
|
|
1034
|
+
/** Whether two fingerprints disagree about size; false when either side is absent. */
|
|
1035
|
+
function sizesDiffer(before, after) {
|
|
1036
|
+
if (before === void 0 || after === void 0) return false;
|
|
1037
|
+
return sizeOf(before) !== sizeOf(after);
|
|
1038
|
+
}
|
|
1039
|
+
//#endregion
|
|
1040
|
+
//#region ../../default/po-file-edit/src/services/fileSystemTreeManifest/index.ts
|
|
1041
|
+
var FileSystemTreeManifestAdapter = class {
|
|
1042
|
+
files;
|
|
1043
|
+
options;
|
|
1044
|
+
constructor(files, options = {}) {
|
|
1045
|
+
this.files = files;
|
|
1046
|
+
this.options = options;
|
|
1047
|
+
}
|
|
1048
|
+
async take(root, exclude = []) {
|
|
1049
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1050
|
+
const skipped = new Set(exclude.map((entry) => path.resolve(entry)));
|
|
1051
|
+
return {
|
|
1052
|
+
entries,
|
|
1053
|
+
truncated: await this.walk(root, 0, entries, skipped)
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
1056
|
+
async fingerprint(filePath) {
|
|
1057
|
+
const stat = await followedFileInfo(this.files, filePath);
|
|
1058
|
+
return stat.ok && stat.value.kind === "file" ? fingerprintOf(stat.value.size, stat.value.mtimeMs) : void 0;
|
|
1059
|
+
}
|
|
1060
|
+
async modifiedAt(filePath) {
|
|
1061
|
+
const stat = await followedFileInfo(this.files, filePath);
|
|
1062
|
+
return stat.ok && stat.value.kind === "file" ? stat.value.mtimeMs : void 0;
|
|
1063
|
+
}
|
|
1064
|
+
changed(before, after) {
|
|
1065
|
+
return changedBetween(before, after);
|
|
1066
|
+
}
|
|
1067
|
+
sizeChanged(before, after) {
|
|
1068
|
+
return sizesDiffer(before, after);
|
|
1069
|
+
}
|
|
1070
|
+
async walk(directory, depth, entries, skipped) {
|
|
1071
|
+
if (depth > (this.options.maxDepth ?? 12)) return true;
|
|
1072
|
+
const listing = await this.files.listDir(directory, BACKGROUND_CONTEXT);
|
|
1073
|
+
if (!listing.ok) return false;
|
|
1074
|
+
let truncated = false;
|
|
1075
|
+
for (const entry of listing.value) {
|
|
1076
|
+
if (entries.size >= (this.options.maxEntries ?? 2e4)) return true;
|
|
1077
|
+
const entryPath = path.join(directory, entry.name);
|
|
1078
|
+
if (skipped.has(entryPath)) continue;
|
|
1079
|
+
if (entry.kind === "directory") {
|
|
1080
|
+
if ((this.options.ignoredDirectories ?? IGNORED_DIRECTORIES).has(entry.name)) continue;
|
|
1081
|
+
truncated = await this.walk(entryPath, depth + 1, entries, skipped) || truncated;
|
|
1082
|
+
} else if (entry.kind === "file") entries.set(entryPath, fingerprintOf(entry.size, entry.mtimeMs));
|
|
1083
|
+
}
|
|
1084
|
+
return truncated;
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
//#endregion
|
|
1088
|
+
//#region ../../default/po-file-edit/src/services/lineDiff/index.ts
|
|
1089
|
+
/**
|
|
1090
|
+
* The line difference between two versions of a file, as bounded hunks.
|
|
1091
|
+
*
|
|
1092
|
+
* This is deliberately the package's own rather than Pi's `generateDiffString`:
|
|
1093
|
+
* that helper reaches the session process through an optional peer dependency,
|
|
1094
|
+
* and these routes run in a host that imports only the built entry, so its
|
|
1095
|
+
* presence is an assumption rather than a fact. A line diff is small enough to
|
|
1096
|
+
* own outright, and owning it means the wire carries structured rows instead of
|
|
1097
|
+
* a formatted string the browser has to parse back apart.
|
|
1098
|
+
*
|
|
1099
|
+
* Bounded twice over. Common prefix and suffix are trimmed first, which is what
|
|
1100
|
+
* makes a one-line change in a large file cheap. What remains is matched with a
|
|
1101
|
+
* longest-common-subsequence table, and only while that table stays under
|
|
1102
|
+
* MAX_MATRIX_CELLS: past it the changed region is reported as one replacement
|
|
1103
|
+
* rather than growing a matrix that would outweigh the file.
|
|
1104
|
+
*/
|
|
1105
|
+
/** Lines of unchanged context kept either side of a change. */
|
|
1106
|
+
const CONTEXT_LINES = 3;
|
|
1107
|
+
/** The largest LCS table worth building; past it the changed region is one replacement. */
|
|
1108
|
+
const MAX_MATRIX_CELLS = 1e6;
|
|
1109
|
+
function splitLines(text) {
|
|
1110
|
+
const normalized = text.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
|
1111
|
+
return normalized === "" ? [] : normalized.split("\n");
|
|
1112
|
+
}
|
|
1113
|
+
/** How many leading lines the two sides share. */
|
|
1114
|
+
function commonPrefix(before, after) {
|
|
1115
|
+
const limit = Math.min(before.length, after.length);
|
|
1116
|
+
let count = 0;
|
|
1117
|
+
while (count < limit && before[count] === after[count]) count += 1;
|
|
1118
|
+
return count;
|
|
1119
|
+
}
|
|
1120
|
+
/** How many trailing lines the two sides share, never overlapping the prefix. */
|
|
1121
|
+
function commonSuffix(before, after, prefix) {
|
|
1122
|
+
const limit = Math.min(before.length, after.length) - prefix;
|
|
1123
|
+
let count = 0;
|
|
1124
|
+
while (count < limit && before[before.length - 1 - count] === after[after.length - 1 - count]) count += 1;
|
|
1125
|
+
return count;
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* The classic LCS length table. Only ever called once the caller has checked
|
|
1129
|
+
* the region against MAX_MATRIX_CELLS, so the allocation is bounded.
|
|
1130
|
+
*/
|
|
1131
|
+
function lcsTable(before, after) {
|
|
1132
|
+
const rows = before.length + 1;
|
|
1133
|
+
const columns = after.length + 1;
|
|
1134
|
+
const table = new Uint32Array(rows * columns);
|
|
1135
|
+
for (let row = before.length - 1; row >= 0; row -= 1) for (let column = after.length - 1; column >= 0; column -= 1) {
|
|
1136
|
+
const index = row * columns + column;
|
|
1137
|
+
table[index] = before[row] === after[column] ? (table[index + columns + 1] ?? 0) + 1 : Math.max(table[index + columns] ?? 0, table[index + 1] ?? 0);
|
|
1138
|
+
}
|
|
1139
|
+
return table;
|
|
1140
|
+
}
|
|
1141
|
+
/** Walks the table to turn it back into an ordered run of keeps, removals and additions. */
|
|
1142
|
+
function backtrack(before, after, beforeStart, afterStart) {
|
|
1143
|
+
const table = lcsTable(before, after);
|
|
1144
|
+
const columns = after.length + 1;
|
|
1145
|
+
const steps = [];
|
|
1146
|
+
let row = 0;
|
|
1147
|
+
let column = 0;
|
|
1148
|
+
while (row < before.length && column < after.length) {
|
|
1149
|
+
if (before[row] === after[column]) {
|
|
1150
|
+
steps.push({
|
|
1151
|
+
marker: " ",
|
|
1152
|
+
content: after[column] ?? "",
|
|
1153
|
+
line: afterStart + column
|
|
1154
|
+
});
|
|
1155
|
+
row += 1;
|
|
1156
|
+
column += 1;
|
|
1157
|
+
continue;
|
|
1158
|
+
}
|
|
1159
|
+
if ((table[(row + 1) * columns + column] ?? 0) >= (table[row * columns + column + 1] ?? 0)) {
|
|
1160
|
+
steps.push({
|
|
1161
|
+
marker: "-",
|
|
1162
|
+
content: before[row] ?? "",
|
|
1163
|
+
line: beforeStart + row
|
|
1164
|
+
});
|
|
1165
|
+
row += 1;
|
|
1166
|
+
continue;
|
|
1167
|
+
}
|
|
1168
|
+
steps.push({
|
|
1169
|
+
marker: "+",
|
|
1170
|
+
content: after[column] ?? "",
|
|
1171
|
+
line: afterStart + column
|
|
1172
|
+
});
|
|
1173
|
+
column += 1;
|
|
1174
|
+
}
|
|
1175
|
+
while (row < before.length) {
|
|
1176
|
+
steps.push({
|
|
1177
|
+
marker: "-",
|
|
1178
|
+
content: before[row] ?? "",
|
|
1179
|
+
line: beforeStart + row
|
|
1180
|
+
});
|
|
1181
|
+
row += 1;
|
|
1182
|
+
}
|
|
1183
|
+
while (column < after.length) {
|
|
1184
|
+
steps.push({
|
|
1185
|
+
marker: "+",
|
|
1186
|
+
content: after[column] ?? "",
|
|
1187
|
+
line: afterStart + column
|
|
1188
|
+
});
|
|
1189
|
+
column += 1;
|
|
1190
|
+
}
|
|
1191
|
+
return steps;
|
|
1192
|
+
}
|
|
1193
|
+
/** The whole changed region as one replacement, for a region too large to match. */
|
|
1194
|
+
function wholesale(before, after, beforeStart, afterStart) {
|
|
1195
|
+
return [...before.map((content, offset) => ({
|
|
1196
|
+
marker: "-",
|
|
1197
|
+
content,
|
|
1198
|
+
line: beforeStart + offset
|
|
1199
|
+
})), ...after.map((content, offset) => ({
|
|
1200
|
+
marker: "+",
|
|
1201
|
+
content,
|
|
1202
|
+
line: afterStart + offset
|
|
1203
|
+
}))];
|
|
1204
|
+
}
|
|
1205
|
+
/** Groups the steps into hunks, keeping CONTEXT_LINES of unchanged text either side of a change. */
|
|
1206
|
+
function toHunks(steps) {
|
|
1207
|
+
const keep = Array.from({ length: steps.length }, () => false);
|
|
1208
|
+
for (const [index, step] of steps.entries()) {
|
|
1209
|
+
if (step.marker === " ") continue;
|
|
1210
|
+
const from = Math.max(0, index - CONTEXT_LINES);
|
|
1211
|
+
const to = Math.min(steps.length - 1, index + CONTEXT_LINES);
|
|
1212
|
+
for (let cursor = from; cursor <= to; cursor += 1) keep[cursor] = true;
|
|
1213
|
+
}
|
|
1214
|
+
const hunks = [];
|
|
1215
|
+
let rows = [];
|
|
1216
|
+
for (const [index, step] of steps.entries()) {
|
|
1217
|
+
if (!keep[index]) {
|
|
1218
|
+
if (rows.length > 0) {
|
|
1219
|
+
hunks.push({
|
|
1220
|
+
start: rows[0]?.line ?? 1,
|
|
1221
|
+
rows
|
|
1222
|
+
});
|
|
1223
|
+
rows = [];
|
|
1224
|
+
}
|
|
1225
|
+
continue;
|
|
1226
|
+
}
|
|
1227
|
+
rows.push({
|
|
1228
|
+
marker: step.marker,
|
|
1229
|
+
line: step.line,
|
|
1230
|
+
content: step.content
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
if (rows.length > 0) hunks.push({
|
|
1234
|
+
start: rows[0]?.line ?? 1,
|
|
1235
|
+
rows
|
|
1236
|
+
});
|
|
1237
|
+
return hunks;
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* The difference between a file that did not exist and the one that now does.
|
|
1241
|
+
*
|
|
1242
|
+
* Kept separate from a two-sided diff because an empty baseline is the one case
|
|
1243
|
+
* where the trailing newline matters. `splitLines` reads "a\n" as a line and
|
|
1244
|
+
* then an empty one, which is invisible in a normal diff because both sides
|
|
1245
|
+
* carry it and it cancels, but against nothing it would report a file of three
|
|
1246
|
+
* lines as four. A creation is counted on the lines the file actually holds.
|
|
1247
|
+
*/
|
|
1248
|
+
function lineDiffFromEmpty(after) {
|
|
1249
|
+
return lineDiff("", after.endsWith("\n") ? after.slice(0, -1) : after);
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* The difference between two versions of a file.
|
|
1253
|
+
*
|
|
1254
|
+
* Line numbers are the new file's for context and additions, and the old
|
|
1255
|
+
* file's for removals, which is the pairing a reader expects: the number
|
|
1256
|
+
* beside a line is where that line actually lives.
|
|
1257
|
+
*/
|
|
1258
|
+
function lineDiff(before, after) {
|
|
1259
|
+
const beforeLines = splitLines(before);
|
|
1260
|
+
const afterLines = splitLines(after);
|
|
1261
|
+
const prefix = commonPrefix(beforeLines, afterLines);
|
|
1262
|
+
const suffix = commonSuffix(beforeLines, afterLines, prefix);
|
|
1263
|
+
const beforeMiddle = beforeLines.slice(prefix, beforeLines.length - suffix);
|
|
1264
|
+
const afterMiddle = afterLines.slice(prefix, afterLines.length - suffix);
|
|
1265
|
+
const approximate = beforeMiddle.length * afterMiddle.length > MAX_MATRIX_CELLS;
|
|
1266
|
+
const middle = approximate ? wholesale(beforeMiddle, afterMiddle, prefix + 1, prefix + 1) : backtrack(beforeMiddle, afterMiddle, prefix + 1, prefix + 1);
|
|
1267
|
+
const head = beforeLines.slice(0, prefix).map((content, offset) => ({
|
|
1268
|
+
marker: " ",
|
|
1269
|
+
content,
|
|
1270
|
+
line: offset + 1
|
|
1271
|
+
}));
|
|
1272
|
+
const tail = afterLines.slice(afterLines.length - suffix).map((content, offset) => ({
|
|
1273
|
+
marker: " ",
|
|
1274
|
+
content,
|
|
1275
|
+
line: afterLines.length - suffix + offset + 1
|
|
1276
|
+
}));
|
|
1277
|
+
const steps = [
|
|
1278
|
+
...head,
|
|
1279
|
+
...middle,
|
|
1280
|
+
...tail
|
|
1281
|
+
];
|
|
1282
|
+
return {
|
|
1283
|
+
hunks: toHunks(steps),
|
|
1284
|
+
additions: steps.filter((step) => step.marker === "+").length,
|
|
1285
|
+
removals: steps.filter((step) => step.marker === "-").length,
|
|
1286
|
+
approximate
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
//#endregion
|
|
1290
|
+
//#region ../../default/po-file-edit/src/services/fileEditsViews/index.ts
|
|
1291
|
+
/** Past this, the working view reports the file rather than carrying it. */
|
|
1292
|
+
const MAX_WORKING_BYTES = 1048576;
|
|
1293
|
+
const NO_BASELINE_NOTE = "changed by a command, so no baseline was captured; showing the file as it stands";
|
|
1294
|
+
/**
|
|
1295
|
+
* A change the tool layer named but never captured content for. That is what
|
|
1296
|
+
* every record written before this package learned to snapshot looks like, and
|
|
1297
|
+
* calling those "changed by a command" would be wrong: the tool is right there
|
|
1298
|
+
* in the record.
|
|
1299
|
+
*/
|
|
1300
|
+
const NO_SNAPSHOT_NOTE = "recorded before this session began capturing content, so there is no diff for it";
|
|
1301
|
+
const NO_AFTER_NOTE = "the new content could not be captured: the file is binary or past the size cap";
|
|
1302
|
+
const NO_BEFORE_NOTE = "the previous content could not be captured: it was binary or past the size cap";
|
|
1303
|
+
const APPROXIMATE_NOTE = "the changed region was too large to match line by line";
|
|
1304
|
+
/** Like Node's utf8 read, a byte-order mark stays in the text. */
|
|
1305
|
+
const decoder = new TextDecoder("utf-8", {
|
|
1306
|
+
fatal: false,
|
|
1307
|
+
ignoreBOM: true
|
|
1308
|
+
});
|
|
1309
|
+
function hashOf(content) {
|
|
1310
|
+
return createHash("sha256").update(content, "utf8").digest("hex");
|
|
1311
|
+
}
|
|
1312
|
+
function isInside(root, candidate) {
|
|
1313
|
+
return candidate === root || candidate.startsWith(`${root}${path.sep}`);
|
|
1314
|
+
}
|
|
1315
|
+
/** A file the source view cannot show, with the reason it says instead. */
|
|
1316
|
+
function unavailable(reason) {
|
|
1317
|
+
return {
|
|
1318
|
+
content: "",
|
|
1319
|
+
hash: "",
|
|
1320
|
+
unavailable: true,
|
|
1321
|
+
reason
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
/** The source view of a file's bytes: refused when oversized or binary, otherwise its text and hash. */
|
|
1325
|
+
function workingViewOf(raw) {
|
|
1326
|
+
if (raw.byteLength > 1048576) return unavailable(`the file is larger than ${MAX_WORKING_BYTES} bytes`);
|
|
1327
|
+
if (raw.subarray(0, 8192).includes(0)) return unavailable("the file is binary");
|
|
1328
|
+
const content = decoder.decode(raw);
|
|
1329
|
+
return {
|
|
1330
|
+
content,
|
|
1331
|
+
hash: hashOf(content),
|
|
1332
|
+
unavailable: false
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
/**
|
|
1336
|
+
* One recorded change as the page renders it. A change with both sides captured
|
|
1337
|
+
* carries its own diff; one without says why, rather than showing nothing.
|
|
1338
|
+
*
|
|
1339
|
+
* A file this session created counts as captured on both sides. Its baseline is
|
|
1340
|
+
* empty rather than missing, so the whole file reads as arriving at once, which
|
|
1341
|
+
* is exactly what happened.
|
|
1342
|
+
*/
|
|
1343
|
+
async function toVersionView(version, snapshots) {
|
|
1344
|
+
const view = {
|
|
1345
|
+
index: version.index,
|
|
1346
|
+
tool: version.tool,
|
|
1347
|
+
at: version.at,
|
|
1348
|
+
origin: version.origin,
|
|
1349
|
+
additions: version.additions ?? 0,
|
|
1350
|
+
removals: version.removals ?? 0
|
|
1351
|
+
};
|
|
1352
|
+
const createdHere = version.before === void 0 && version.created === true;
|
|
1353
|
+
if (version.after === void 0 || version.before === void 0 && !createdHere) {
|
|
1354
|
+
if (version.origin === "tool") return {
|
|
1355
|
+
...view,
|
|
1356
|
+
note: version.after === void 0 ? NO_AFTER_NOTE : NO_BEFORE_NOTE
|
|
1357
|
+
};
|
|
1358
|
+
return {
|
|
1359
|
+
...view,
|
|
1360
|
+
note: version.tool === "bash" ? NO_BASELINE_NOTE : NO_SNAPSHOT_NOTE
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
const after = await snapshots.read(version.after);
|
|
1364
|
+
if (after === void 0) return {
|
|
1365
|
+
...view,
|
|
1366
|
+
note: "the content behind this change is no longer held"
|
|
1367
|
+
};
|
|
1368
|
+
if (version.before === void 0) {
|
|
1369
|
+
const fresh = lineDiffFromEmpty(after);
|
|
1370
|
+
return {
|
|
1371
|
+
...view,
|
|
1372
|
+
additions: fresh.additions,
|
|
1373
|
+
removals: fresh.removals,
|
|
1374
|
+
hunks: fresh.hunks,
|
|
1375
|
+
...fresh.approximate ? { note: APPROXIMATE_NOTE } : {}
|
|
1376
|
+
};
|
|
1377
|
+
}
|
|
1378
|
+
const before = await snapshots.read(version.before);
|
|
1379
|
+
if (before === void 0) return {
|
|
1380
|
+
...view,
|
|
1381
|
+
note: "the content behind this change is no longer held"
|
|
1382
|
+
};
|
|
1383
|
+
const diff = lineDiff(before, after);
|
|
1384
|
+
return {
|
|
1385
|
+
...view,
|
|
1386
|
+
additions: diff.additions,
|
|
1387
|
+
removals: diff.removals,
|
|
1388
|
+
hunks: diff.hunks,
|
|
1389
|
+
...diff.approximate ? { note: APPROXIMATE_NOTE } : {}
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
/** Everything the session did to the file: its oldest baseline against what is on disk now. */
|
|
1393
|
+
async function toCumulativeView(versions, working, snapshots) {
|
|
1394
|
+
const createdHere = versions[0]?.created === true;
|
|
1395
|
+
const baseline = baselineOf(versions);
|
|
1396
|
+
if (!createdHere && baseline === void 0) return {
|
|
1397
|
+
additions: 0,
|
|
1398
|
+
removals: 0,
|
|
1399
|
+
note: versions[0]?.origin === "tool" ? NO_BEFORE_NOTE : NO_BASELINE_NOTE
|
|
1400
|
+
};
|
|
1401
|
+
if (working.unavailable) return {
|
|
1402
|
+
additions: 0,
|
|
1403
|
+
removals: 0,
|
|
1404
|
+
note: working.reason ?? "the file cannot be read"
|
|
1405
|
+
};
|
|
1406
|
+
if (createdHere || baseline === void 0) {
|
|
1407
|
+
const fresh = lineDiffFromEmpty(working.content);
|
|
1408
|
+
return {
|
|
1409
|
+
additions: fresh.additions,
|
|
1410
|
+
removals: fresh.removals,
|
|
1411
|
+
hunks: fresh.hunks,
|
|
1412
|
+
...fresh.approximate ? { note: APPROXIMATE_NOTE } : {}
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
const before = await snapshots.read(baseline);
|
|
1416
|
+
if (before === void 0) return {
|
|
1417
|
+
additions: 0,
|
|
1418
|
+
removals: 0,
|
|
1419
|
+
note: "the content this session started from is no longer held"
|
|
1420
|
+
};
|
|
1421
|
+
const diff = lineDiff(before, working.content);
|
|
1422
|
+
return {
|
|
1423
|
+
additions: diff.additions,
|
|
1424
|
+
removals: diff.removals,
|
|
1425
|
+
hunks: diff.hunks,
|
|
1426
|
+
...diff.approximate ? { note: APPROXIMATE_NOTE } : {}
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
//#endregion
|
|
1430
|
+
//#region ../../default/po-file-edit/src/services/fileSystemWorkingFiles/index.ts
|
|
1431
|
+
/**
|
|
1432
|
+
* The routes' file operations over the file system the host gave the session.
|
|
1433
|
+
*
|
|
1434
|
+
* What a request may do is decided by the routes and is the same everywhere.
|
|
1435
|
+
* This is only how a file is read and changed safely: a read pins the file it
|
|
1436
|
+
* checked by the handle it opened, and a write or delete is serialised per
|
|
1437
|
+
* target and checks again, against the link-resolved path, right before it acts.
|
|
1438
|
+
*
|
|
1439
|
+
* A `FileSystem` has no writable handle, so a save cannot pin the descriptor the
|
|
1440
|
+
* way Node does. It narrows the window instead, by writing to the resolved
|
|
1441
|
+
* target only after the same file, the same path and the same root were
|
|
1442
|
+
* confirmed under the per-target queue every cooperating writer shares.
|
|
1443
|
+
*/
|
|
1444
|
+
const CANNOT_READ = "the file no longer exists or cannot be safely read";
|
|
1445
|
+
const PATH_CHANGED = "the file path changed or leaves its readable directory";
|
|
1446
|
+
const NOT_REGULAR = "the file is not a regular file";
|
|
1447
|
+
/** Opening these means the path names something other than a regular file. */
|
|
1448
|
+
const NOT_A_FILE = /* @__PURE__ */ new Set(["is_directory", "invalid"]);
|
|
1449
|
+
function describe(error) {
|
|
1450
|
+
return error instanceof Error ? error.message : String(error);
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* The same containment check after links are followed. A path that does not
|
|
1454
|
+
* exist yet resolves to nothing, and there is nothing to hand out, so it
|
|
1455
|
+
* passes and the read reports it missing.
|
|
1456
|
+
*/
|
|
1457
|
+
async function isRealPathInside(files, root, candidate) {
|
|
1458
|
+
const realRoot = await files.canonicalPath(root, BACKGROUND_CONTEXT);
|
|
1459
|
+
if (!realRoot.ok) return realRoot.error.code === "not_found";
|
|
1460
|
+
const real = await files.canonicalPath(candidate, BACKGROUND_CONTEXT);
|
|
1461
|
+
if (!real.ok) return real.error.code === "not_found";
|
|
1462
|
+
return isInside(realRoot.value, real.value);
|
|
1463
|
+
}
|
|
1464
|
+
async function isInsideRoot(files, root, filePath) {
|
|
1465
|
+
return isInside(root, filePath) && await isRealPathInside(files, root, filePath);
|
|
1466
|
+
}
|
|
1467
|
+
/** Reads the file as the source view will show it, or says why it cannot. */
|
|
1468
|
+
async function readWorking(files, filePath, allowedRoot) {
|
|
1469
|
+
if (allowedRoot !== void 0 && !await isRealPathInside(files, allowedRoot, filePath)) return unavailable(CANNOT_READ);
|
|
1470
|
+
const opened = await files.openBinaryReader(filePath, {}, BACKGROUND_CONTEXT);
|
|
1471
|
+
if (!opened.ok) return unavailable(NOT_A_FILE.has(opened.error.code) ? NOT_REGULAR : CANNOT_READ);
|
|
1472
|
+
const reader = opened.value;
|
|
1473
|
+
try {
|
|
1474
|
+
const pinned = await reader.info(BACKGROUND_CONTEXT);
|
|
1475
|
+
const named = await files.fileInfo(filePath, BACKGROUND_CONTEXT);
|
|
1476
|
+
if (!pinned.ok || !named.ok) return unavailable(CANNOT_READ);
|
|
1477
|
+
if (named.value.kind !== "file" || named.value.size !== pinned.value.size || named.value.mtimeMs !== pinned.value.mtimeMs || allowedRoot !== void 0 && !await isRealPathInside(files, allowedRoot, filePath)) return unavailable(PATH_CHANGED);
|
|
1478
|
+
const raw = await reader.read(0, 1048577, BACKGROUND_CONTEXT);
|
|
1479
|
+
return raw.ok ? workingViewOf(raw.value) : unavailable(CANNOT_READ);
|
|
1480
|
+
} finally {
|
|
1481
|
+
await reader.close(BACKGROUND_CONTEXT);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
var FileSystemWorkingFiles = class {
|
|
1485
|
+
files;
|
|
1486
|
+
constructor(files) {
|
|
1487
|
+
this.files = files;
|
|
1488
|
+
}
|
|
1489
|
+
readWorking(filePath, allowedRoot) {
|
|
1490
|
+
return readWorking(this.files, filePath, allowedRoot);
|
|
1491
|
+
}
|
|
1492
|
+
isRealPathInside(root, candidate) {
|
|
1493
|
+
return isRealPathInside(this.files, root, candidate);
|
|
1494
|
+
}
|
|
1495
|
+
async save({ filePath, root, content, expectedHash }) {
|
|
1496
|
+
const canonical = getOrThrow(await this.files.canonicalPath(filePath, BACKGROUND_CONTEXT));
|
|
1497
|
+
return fileMutationRunner.forKey(canonical)(async () => {
|
|
1498
|
+
const current = await readWorking(this.files, filePath, root);
|
|
1499
|
+
if (current.unavailable) return {
|
|
1500
|
+
status: "unreadable",
|
|
1501
|
+
reason: current.reason ?? "The file cannot be read."
|
|
1502
|
+
};
|
|
1503
|
+
if (current.hash !== expectedHash) return {
|
|
1504
|
+
status: "stale",
|
|
1505
|
+
hash: current.hash
|
|
1506
|
+
};
|
|
1507
|
+
const named = await this.files.fileInfo(filePath, BACKGROUND_CONTEXT);
|
|
1508
|
+
const resolved = await this.files.canonicalPath(filePath, BACKGROUND_CONTEXT);
|
|
1509
|
+
if (!named.ok || named.value.kind !== "file" || !resolved.ok || resolved.value !== canonical || !await isInsideRoot(this.files, root, filePath)) return { status: "moved" };
|
|
1510
|
+
getOrThrow(await this.files.writeFile(canonical, content, BACKGROUND_CONTEXT));
|
|
1511
|
+
return {
|
|
1512
|
+
status: "saved",
|
|
1513
|
+
hash: hashOf(content)
|
|
1514
|
+
};
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
async remove(filePath, root) {
|
|
1518
|
+
const resolved = await this.files.canonicalPath(filePath, BACKGROUND_CONTEXT);
|
|
1519
|
+
if (!resolved.ok && resolved.error.code !== "not_found") return {
|
|
1520
|
+
status: "failed",
|
|
1521
|
+
reason: describe(resolved.error)
|
|
1522
|
+
};
|
|
1523
|
+
return fileMutationRunner.forKey(resolved.ok ? resolved.value : filePath)(async () => {
|
|
1524
|
+
if (!await isInsideRoot(this.files, root, filePath)) return { status: "outside" };
|
|
1525
|
+
const removed = await this.files.remove(filePath, { force: true }, BACKGROUND_CONTEXT);
|
|
1526
|
+
return removed.ok ? { status: "removed" } : {
|
|
1527
|
+
status: "failed",
|
|
1528
|
+
reason: describe(removed.error)
|
|
1529
|
+
};
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
//#endregion
|
|
1534
|
+
//#region ../../default/po-file-edit/src/services/fileEditStorage/index.edge.ts
|
|
1535
|
+
/**
|
|
1536
|
+
* The storage a session's file history uses where the host gives it a file
|
|
1537
|
+
* system and nothing else: a Durable Object's.
|
|
1538
|
+
*
|
|
1539
|
+
* Replaces `index.ts` in the edge build and exports the same name. Everything
|
|
1540
|
+
* is read and written through the injected file system, and the session's
|
|
1541
|
+
* environment and home directory come from what the host admitted for it.
|
|
1542
|
+
*/
|
|
1543
|
+
/**
|
|
1544
|
+
* A session's file system holds no git repository, so git can vouch for no
|
|
1545
|
+
* path. Saying so is the real answer for such a tree, not a stand-in: the
|
|
1546
|
+
* tracker then keeps recording every path it saw change.
|
|
1547
|
+
*/
|
|
1548
|
+
const noRepositoryGit = { unchanged: async () => /* @__PURE__ */ new Set() };
|
|
1549
|
+
/**
|
|
1550
|
+
* The plans directory Plan mode writes to, resolved the way Plan resolves it, so
|
|
1551
|
+
* a plan link in the transcript opens in the file view. A config that cannot be
|
|
1552
|
+
* read admits nothing extra rather than failing the preview.
|
|
1553
|
+
*/
|
|
1554
|
+
async function plansRoots(files, cwd, environment, homeDirectory) {
|
|
1555
|
+
const home = homeDirectory ?? environment.HOME;
|
|
1556
|
+
try {
|
|
1557
|
+
const config = await readPoConfig(files, cwd, BACKGROUND_CONTEXT, {
|
|
1558
|
+
environment,
|
|
1559
|
+
...home === void 0 ? {} : { homeDirectory: home }
|
|
1560
|
+
});
|
|
1561
|
+
return [resolvePlanningPlansDirectory(config.modes?.planning?.plansDirectory, cwd, home)];
|
|
1562
|
+
} catch {
|
|
1563
|
+
return [];
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
function createFileEditStorage(fileSystem) {
|
|
1567
|
+
if (fileSystem === void 0) throw new Error("File-edit storage on the edge requires the session file system.");
|
|
1568
|
+
const files = fileSystem;
|
|
1569
|
+
return {
|
|
1570
|
+
paths: (environment = {}) => new FileSystemEditPaths(files, environment),
|
|
1571
|
+
timeline: () => new FileSystemTimelineStore(files),
|
|
1572
|
+
snapshots: () => new FileSystemSnapshotStore(files),
|
|
1573
|
+
manifests: () => new FileSystemTreeManifestAdapter(files),
|
|
1574
|
+
git: () => noRepositoryGit,
|
|
1575
|
+
workingFiles: () => new FileSystemWorkingFiles(files),
|
|
1576
|
+
presenceFiles: () => createFileSystemPresenceFiles(files),
|
|
1577
|
+
sessionFiles: (timelinePath, cwd) => readSessionFilesFrom(files, timelinePath, cwd),
|
|
1578
|
+
readableRoots: ({ cwd, environment, homeDirectory }) => {
|
|
1579
|
+
let roots;
|
|
1580
|
+
return () => roots ??= plansRoots(files, cwd, environment, homeDirectory);
|
|
1581
|
+
},
|
|
1582
|
+
clearOnClose: false
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
//#endregion
|
|
1586
|
+
//#region ../../default/po-file-edit/src/services/editPresence/index.ts
|
|
1587
|
+
const PATH_TOOLS = /* @__PURE__ */ new Set([
|
|
1588
|
+
"read",
|
|
1589
|
+
"edit",
|
|
1590
|
+
"write"
|
|
1591
|
+
]);
|
|
1592
|
+
const EDIT_TOOLS = /* @__PURE__ */ new Set(["edit", "write"]);
|
|
1593
|
+
const MAX_GREP_FILES = 50;
|
|
1594
|
+
const MAX_NOTE_LINES = 10;
|
|
1595
|
+
const MINUTE_MS = 6e4;
|
|
1596
|
+
const SHORT_ID_LENGTH = 8;
|
|
1597
|
+
/** Pi's built-in grep prints match rows as `relative/path:line: text`. */
|
|
1598
|
+
const PI_GREP_ROW = /^(.+?):(\d+): /u;
|
|
1599
|
+
function stringArg(args, key) {
|
|
1600
|
+
if (typeof args !== "object" || args === null) return void 0;
|
|
1601
|
+
const value = args[key];
|
|
1602
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
1603
|
+
}
|
|
1604
|
+
function textOf(content) {
|
|
1605
|
+
return content.map((part) => part.type === "text" && "text" in part && typeof part.text === "string" ? part.text : "").join("\n");
|
|
1606
|
+
}
|
|
1607
|
+
async function grepFiles(call, files) {
|
|
1608
|
+
const lines = textOf(call.content).split("\n");
|
|
1609
|
+
const headers = lines.flatMap((line) => {
|
|
1610
|
+
const header = parseFileHeader(line);
|
|
1611
|
+
return header === void 0 ? [] : [resolveInputPath(header.path, call.cwd)];
|
|
1612
|
+
});
|
|
1613
|
+
if (headers.length > 0) return [...new Set(headers)].slice(0, MAX_GREP_FILES);
|
|
1614
|
+
const rows = lines.flatMap((line) => {
|
|
1615
|
+
const match = PI_GREP_ROW.exec(line)?.[1];
|
|
1616
|
+
return match === void 0 ? [] : [match];
|
|
1617
|
+
});
|
|
1618
|
+
if (rows.length === 0) return [];
|
|
1619
|
+
const searchPath = resolveInputPath(stringArg(call.args, "path") ?? ".", call.cwd);
|
|
1620
|
+
if (await files.isFile(searchPath)) return [searchPath];
|
|
1621
|
+
return [...new Set(rows.map((row) => path.resolve(searchPath, row)))].slice(0, MAX_GREP_FILES);
|
|
1622
|
+
}
|
|
1623
|
+
async function touchedFiles(call, files) {
|
|
1624
|
+
if (PATH_TOOLS.has(call.toolName)) {
|
|
1625
|
+
const input = stringArg(call.args, "path");
|
|
1626
|
+
return input === void 0 ? [] : [await resolveReadInputPath(input, call.cwd)];
|
|
1627
|
+
}
|
|
1628
|
+
return call.toolName === "grep" ? grepFiles(call, files) : [];
|
|
1629
|
+
}
|
|
1630
|
+
function ago(elapsed) {
|
|
1631
|
+
const minutes = Math.floor(elapsed / MINUTE_MS);
|
|
1632
|
+
return minutes < 1 ? "under 1m ago" : `${minutes}m ago`;
|
|
1633
|
+
}
|
|
1634
|
+
function renderNote(lines) {
|
|
1635
|
+
const shown = lines.slice(0, MAX_NOTE_LINES);
|
|
1636
|
+
const more = lines.length - shown.length;
|
|
1637
|
+
return [
|
|
1638
|
+
PRESENCE_NOTE_TITLE,
|
|
1639
|
+
...shown,
|
|
1640
|
+
...more > 0 ? [`- and ${more} more`] : [],
|
|
1641
|
+
PRESENCE_NOTE_GUIDANCE
|
|
1642
|
+
].join("\n");
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Notes live editors of the files a tool call touched, then records the caller's own successful edit.
|
|
1646
|
+
* Returns the content with one note appended, or undefined when there is nothing to add, so callers
|
|
1647
|
+
* never rewrite a result needlessly.
|
|
1648
|
+
*/
|
|
1649
|
+
async function observePresence(presence, agent, call, now = Date.now(), files = createFileEditStorage().presenceFiles()) {
|
|
1650
|
+
const recording = EDIT_TOOLS.has(call.toolName) && !call.isError;
|
|
1651
|
+
const lines = [];
|
|
1652
|
+
for (const file of await touchedFiles(call, files)) {
|
|
1653
|
+
const real = await files.realpath(file);
|
|
1654
|
+
if (real === void 0) continue;
|
|
1655
|
+
const others = presence.touch(real, agent);
|
|
1656
|
+
let bytes;
|
|
1657
|
+
if (others.length > 0) {
|
|
1658
|
+
bytes = await files.read(real);
|
|
1659
|
+
const current = bytes === void 0 ? void 0 : computeFileTag(bytes);
|
|
1660
|
+
const shown = displayPath(file, call.cwd);
|
|
1661
|
+
for (const entry of others) {
|
|
1662
|
+
const state = entry.tag === current ? "unchanged" : "changed";
|
|
1663
|
+
lines.push(`- ${shown}: ${entry.agent.label()}, ${ago(now - entry.at)}, file ${state} since their edit.`);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
if (recording) {
|
|
1667
|
+
bytes ??= await files.read(real);
|
|
1668
|
+
if (bytes !== void 0) presence.record(real, {
|
|
1669
|
+
agent,
|
|
1670
|
+
tag: computeFileTag(bytes),
|
|
1671
|
+
at: now
|
|
1672
|
+
});
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
if (lines.length === 0) return void 0;
|
|
1676
|
+
return [...call.content, {
|
|
1677
|
+
type: "text",
|
|
1678
|
+
text: renderNote(lines)
|
|
1679
|
+
}];
|
|
1680
|
+
}
|
|
1681
|
+
/** Edit presence for one hub session and the in-process children it spawns. */
|
|
1682
|
+
function createSessionPresence(options) {
|
|
1683
|
+
const { sessionId, presence } = options;
|
|
1684
|
+
const sessionAgent = {
|
|
1685
|
+
key: `session:${sessionId}`,
|
|
1686
|
+
label: () => `session ${sessionId}${options.workflowStep ? " (workflow step)" : ""}`,
|
|
1687
|
+
contact: sessionId,
|
|
1688
|
+
isLive: options.isLive
|
|
1689
|
+
};
|
|
1690
|
+
const safely = async (work) => {
|
|
1691
|
+
try {
|
|
1692
|
+
return await work();
|
|
1693
|
+
} catch (error) {
|
|
1694
|
+
options.onError?.(error);
|
|
1695
|
+
return;
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
return {
|
|
1699
|
+
toolResult: {
|
|
1700
|
+
event: "tool_result",
|
|
1701
|
+
async handle(event, execution) {
|
|
1702
|
+
const toolName = event.toolName;
|
|
1703
|
+
if (execution.sessionId !== sessionId || typeof toolName !== "string" || !Array.isArray(event.content)) return;
|
|
1704
|
+
const content = event.content;
|
|
1705
|
+
const next = await safely(() => observePresence(presence, sessionAgent, {
|
|
1706
|
+
toolName,
|
|
1707
|
+
args: event.args,
|
|
1708
|
+
content,
|
|
1709
|
+
isError: event.isError === true,
|
|
1710
|
+
cwd: execution.cwd
|
|
1711
|
+
}, void 0, options.files));
|
|
1712
|
+
return next === void 0 ? void 0 : { content: next };
|
|
1713
|
+
}
|
|
1714
|
+
},
|
|
1715
|
+
childHooks: { bind(scope) {
|
|
1716
|
+
const { runId, parentSessionId, agent } = scope.request;
|
|
1717
|
+
const child = {
|
|
1718
|
+
key: `run:${runId}`,
|
|
1719
|
+
label: () => `${options.labelFor(runId) ?? `${agent} (run ${runId.slice(0, SHORT_ID_LENGTH)})`} (subagent of session ${parentSessionId})`,
|
|
1720
|
+
contact: parentSessionId,
|
|
1721
|
+
isLive: () => !scope.signal.aborted
|
|
1722
|
+
};
|
|
1723
|
+
return {
|
|
1724
|
+
beforeTool: () => void 0,
|
|
1725
|
+
async afterTool(event) {
|
|
1726
|
+
const next = await safely(() => observePresence(presence, child, {
|
|
1727
|
+
toolName: event.toolName,
|
|
1728
|
+
args: event.args,
|
|
1729
|
+
content: event.content,
|
|
1730
|
+
isError: event.isError,
|
|
1731
|
+
cwd: scope.request.cwd || options.cwd
|
|
1732
|
+
}, void 0, options.files));
|
|
1733
|
+
return next === void 0 ? void 0 : { content: next };
|
|
1734
|
+
},
|
|
1735
|
+
dispose: async () => presence.forget(child.key)
|
|
1736
|
+
};
|
|
1737
|
+
} },
|
|
1738
|
+
dispose: () => presence.forget(sessionAgent.key)
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
//#endregion
|
|
1742
|
+
//#region ../../default/po-file-edit/src/services/editTracker/index.ts
|
|
1743
|
+
const EDIT_TOOL = "edit";
|
|
1744
|
+
const WRITE_TOOL = "write";
|
|
1745
|
+
const BASH_TOOL = "bash";
|
|
1746
|
+
/** Code mode scripts can write files like a shell can, so they get the same before/after scan. */
|
|
1747
|
+
const EXEC_TOOL = "exec";
|
|
1748
|
+
function objectValue(value, key) {
|
|
1749
|
+
if (!value || typeof value !== "object") return void 0;
|
|
1750
|
+
const found = value[key];
|
|
1751
|
+
return typeof found === "string" ? found : void 0;
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* How far before a call started a write may claim to have happened and still be
|
|
1755
|
+
* attributed to it. A working tree can sit on a filesystem that stores whole
|
|
1756
|
+
* seconds, which floors a write made just after the call began to a stamp just
|
|
1757
|
+
* before it, and the cost of being generous here is one second of the staleness
|
|
1758
|
+
* this check exists to remove.
|
|
1759
|
+
*/
|
|
1760
|
+
const MODIFIED_TOLERANCE_MS = 1e3;
|
|
1761
|
+
var EditTracker = class {
|
|
1762
|
+
timeline;
|
|
1763
|
+
snapshots;
|
|
1764
|
+
manifests;
|
|
1765
|
+
pending = /* @__PURE__ */ new Map();
|
|
1766
|
+
/** Start time per in-flight bash call, so its end knows what it may claim. */
|
|
1767
|
+
bracketed = /* @__PURE__ */ new Map();
|
|
1768
|
+
/**
|
|
1769
|
+
* The tree as this tracker last saw it. A bash call compares against it and
|
|
1770
|
+
* then replaces it, so each call costs one walk rather than two, and a change
|
|
1771
|
+
* made between calls is still noticed on the next one.
|
|
1772
|
+
*/
|
|
1773
|
+
manifest;
|
|
1774
|
+
/**
|
|
1775
|
+
* This package's own storage, which the walk must never report. The timeline
|
|
1776
|
+
* and its snapshots can land inside the tree being watched, and recording
|
|
1777
|
+
* them would make every change cause another one.
|
|
1778
|
+
*/
|
|
1779
|
+
excluded = [];
|
|
1780
|
+
/**
|
|
1781
|
+
* The project's own ignore rules. A path the project disowns is not worth a
|
|
1782
|
+
* git call, a read, or a stored copy of its content, so it is dropped before
|
|
1783
|
+
* it costs any of them.
|
|
1784
|
+
*/
|
|
1785
|
+
isIgnored;
|
|
1786
|
+
/**
|
|
1787
|
+
* The last content hash this session saw per path, from either mechanism.
|
|
1788
|
+
* A candidate whose hash has not moved was touched, not edited.
|
|
1789
|
+
*/
|
|
1790
|
+
contents = /* @__PURE__ */ new Map();
|
|
1791
|
+
now;
|
|
1792
|
+
git;
|
|
1793
|
+
/**
|
|
1794
|
+
* The scan deferred by the last bash call. Every bracket joins this chain, so
|
|
1795
|
+
* at most one walk runs at a time and each one sees the baseline the previous
|
|
1796
|
+
* one left behind.
|
|
1797
|
+
*/
|
|
1798
|
+
scanning = Promise.resolve();
|
|
1799
|
+
constructor(timeline, snapshots, manifests, options = {}) {
|
|
1800
|
+
this.timeline = timeline;
|
|
1801
|
+
this.snapshots = snapshots;
|
|
1802
|
+
this.manifests = manifests;
|
|
1803
|
+
this.now = options.now ?? Date.now;
|
|
1804
|
+
this.git = options.git;
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* Forgets the previous session's tree so a new one does not inherit its
|
|
1808
|
+
* baseline, and takes the paths this session's own bookkeeping occupies.
|
|
1809
|
+
*/
|
|
1810
|
+
reset(options = {}) {
|
|
1811
|
+
this.pending.clear();
|
|
1812
|
+
this.bracketed.clear();
|
|
1813
|
+
this.contents.clear();
|
|
1814
|
+
this.manifest = void 0;
|
|
1815
|
+
this.scanning = Promise.resolve();
|
|
1816
|
+
this.excluded = options.exclude ?? [];
|
|
1817
|
+
this.isIgnored = options.isIgnored;
|
|
1818
|
+
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Awaits a scan still running in the background. A caller that is about to
|
|
1821
|
+
* clear the timeline needs this, or the scan appends after the clear.
|
|
1822
|
+
*/
|
|
1823
|
+
async flush() {
|
|
1824
|
+
await this.scanning;
|
|
1825
|
+
}
|
|
1826
|
+
async start(id, tool, args, cwd) {
|
|
1827
|
+
await this.scanning;
|
|
1828
|
+
if (tool === EDIT_TOOL || tool === WRITE_TOOL) {
|
|
1829
|
+
const supplied = objectValue(args, "path");
|
|
1830
|
+
if (!supplied) return false;
|
|
1831
|
+
const filePath = path.resolve(cwd, supplied);
|
|
1832
|
+
const [before, fingerprint] = await Promise.all([this.snapshots.capture(filePath), this.manifests.fingerprint(filePath)]);
|
|
1833
|
+
this.pending.set(id, {
|
|
1834
|
+
tool,
|
|
1835
|
+
filePath,
|
|
1836
|
+
before,
|
|
1837
|
+
existed: fingerprint !== void 0
|
|
1838
|
+
});
|
|
1839
|
+
return true;
|
|
1840
|
+
}
|
|
1841
|
+
if (tool !== BASH_TOOL && tool !== EXEC_TOOL) return false;
|
|
1842
|
+
this.bracketed.set(id, this.now());
|
|
1843
|
+
this.manifest ??= await this.manifests.take(cwd, this.excluded);
|
|
1844
|
+
return true;
|
|
1845
|
+
}
|
|
1846
|
+
async end(id, isError, cwd) {
|
|
1847
|
+
const pending = this.pending.get(id);
|
|
1848
|
+
this.pending.delete(id);
|
|
1849
|
+
const startedAt = this.bracketed.get(id);
|
|
1850
|
+
this.bracketed.delete(id);
|
|
1851
|
+
if (pending) {
|
|
1852
|
+
if (!isError) await this.recordTool(pending);
|
|
1853
|
+
return;
|
|
1854
|
+
}
|
|
1855
|
+
if (startedAt === void 0) return;
|
|
1856
|
+
this.scanning = this.scanning.then(async () => {
|
|
1857
|
+
try {
|
|
1858
|
+
await this.recordScan(cwd, startedAt);
|
|
1859
|
+
} catch {}
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1862
|
+
/** An `edit` or `write` whose file was read on both sides of the call. */
|
|
1863
|
+
async recordTool(pending) {
|
|
1864
|
+
const after = await this.snapshots.capture(pending.filePath);
|
|
1865
|
+
const created = !pending.existed;
|
|
1866
|
+
const counts = await this.countChanges(pending.before, after, created);
|
|
1867
|
+
if (after !== void 0) this.contents.set(pending.filePath, after);
|
|
1868
|
+
await this.append({
|
|
1869
|
+
version: 2,
|
|
1870
|
+
path: pending.filePath,
|
|
1871
|
+
tool: pending.tool,
|
|
1872
|
+
at: this.now(),
|
|
1873
|
+
origin: "tool",
|
|
1874
|
+
...pending.before === void 0 ? {} : { before: pending.before },
|
|
1875
|
+
...after === void 0 ? {} : { after },
|
|
1876
|
+
...created ? { created: true } : {},
|
|
1877
|
+
...counts
|
|
1878
|
+
});
|
|
1879
|
+
await this.remember(pending.filePath);
|
|
1880
|
+
}
|
|
1881
|
+
/** Whatever a bash call actually edited, however the command wrote it. */
|
|
1882
|
+
async recordScan(cwd, startedAt) {
|
|
1883
|
+
const before = this.manifest;
|
|
1884
|
+
if (before === void 0) return;
|
|
1885
|
+
const after = await this.manifests.take(cwd, this.excluded);
|
|
1886
|
+
this.manifest = after;
|
|
1887
|
+
const disowned = this.isIgnored;
|
|
1888
|
+
const named = this.manifests.changed(before, after).filter((filePath) => disowned === void 0 || !disowned(filePath));
|
|
1889
|
+
const candidates = await this.writtenDuring(named, startedAt);
|
|
1890
|
+
if (candidates.length === 0) return;
|
|
1891
|
+
const unchanged = await this.unchangedInGit(cwd, candidates);
|
|
1892
|
+
for (const filePath of candidates) {
|
|
1893
|
+
const known = this.contents.get(filePath);
|
|
1894
|
+
if (known === void 0 && unchanged.has(filePath)) continue;
|
|
1895
|
+
const beforePrint = before.entries.get(filePath);
|
|
1896
|
+
const afterPrint = after.entries.get(filePath);
|
|
1897
|
+
const captured = afterPrint === void 0 ? void 0 : await this.snapshots.capture(filePath);
|
|
1898
|
+
if (captured !== void 0) this.contents.set(filePath, captured);
|
|
1899
|
+
if (captured !== void 0 && captured === known) continue;
|
|
1900
|
+
const proven = beforePrint === void 0 || afterPrint === void 0 || this.manifests.sizeChanged(beforePrint, afterPrint) || known !== void 0 && captured !== void 0 && captured !== known;
|
|
1901
|
+
await this.append({
|
|
1902
|
+
version: 2,
|
|
1903
|
+
path: filePath,
|
|
1904
|
+
tool: BASH_TOOL,
|
|
1905
|
+
at: this.now(),
|
|
1906
|
+
origin: "scan",
|
|
1907
|
+
...proven ? { verified: true } : {},
|
|
1908
|
+
...captured === void 0 ? {} : { after: captured }
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Narrows candidates to the ones that could have been written by the call
|
|
1914
|
+
* being closed.
|
|
1915
|
+
*
|
|
1916
|
+
* This is what keeps a working tree that was already dirty out of the list. A
|
|
1917
|
+
* file whose bytes were last written before the call began was differed by
|
|
1918
|
+
* something else, whatever moved its fingerprint. A file that is no longer
|
|
1919
|
+
* there has no time to read and a delete is a change the call may well have
|
|
1920
|
+
* made, so it stays a candidate.
|
|
1921
|
+
*/
|
|
1922
|
+
async writtenDuring(candidates, startedAt) {
|
|
1923
|
+
const floor = startedAt - MODIFIED_TOLERANCE_MS;
|
|
1924
|
+
const written = [];
|
|
1925
|
+
for (const filePath of candidates) {
|
|
1926
|
+
const modifiedAt = await this.manifests.modifiedAt(filePath);
|
|
1927
|
+
if (modifiedAt === void 0 || modifiedAt >= floor) written.push(filePath);
|
|
1928
|
+
}
|
|
1929
|
+
return written;
|
|
1930
|
+
}
|
|
1931
|
+
/** Which candidates git tracks and reports as untouched; empty when it cannot say. */
|
|
1932
|
+
async unchangedInGit(cwd, candidates) {
|
|
1933
|
+
const unseen = candidates.filter((filePath) => !this.contents.has(filePath));
|
|
1934
|
+
if (this.git === void 0 || unseen.length === 0) return /* @__PURE__ */ new Set();
|
|
1935
|
+
return this.git.unchanged(cwd, unseen);
|
|
1936
|
+
}
|
|
1937
|
+
/** How many lines moved, when there is enough captured content to say. */
|
|
1938
|
+
async countChanges(before, after, created) {
|
|
1939
|
+
if (after === void 0) return {};
|
|
1940
|
+
if (before === void 0) {
|
|
1941
|
+
if (!created) return {};
|
|
1942
|
+
const createdText = await this.snapshots.read(after);
|
|
1943
|
+
if (createdText === void 0) return {};
|
|
1944
|
+
const fresh = lineDiffFromEmpty(createdText);
|
|
1945
|
+
return {
|
|
1946
|
+
additions: fresh.additions,
|
|
1947
|
+
removals: fresh.removals
|
|
1948
|
+
};
|
|
1949
|
+
}
|
|
1950
|
+
if (before === after) return {
|
|
1951
|
+
additions: 0,
|
|
1952
|
+
removals: 0
|
|
1953
|
+
};
|
|
1954
|
+
const [beforeText, afterText] = await Promise.all([this.snapshots.read(before), this.snapshots.read(after)]);
|
|
1955
|
+
if (beforeText === void 0 || afterText === void 0) return {};
|
|
1956
|
+
const diff = lineDiff(beforeText, afterText);
|
|
1957
|
+
return {
|
|
1958
|
+
additions: diff.additions,
|
|
1959
|
+
removals: diff.removals
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1962
|
+
/** Records the change unless it turned out to be no change at all. */
|
|
1963
|
+
async append(event) {
|
|
1964
|
+
if (event.before !== void 0 && event.before === event.after) return;
|
|
1965
|
+
await this.timeline.append(event);
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* Folds a path the tool layer just handled into the tracked manifest, so the
|
|
1969
|
+
* next bash comparison sees it as already accounted for.
|
|
1970
|
+
*
|
|
1971
|
+
* The fingerprint has to be the one a walk would read, not a stand-in, or the
|
|
1972
|
+
* next comparison reports the file again under bash and every tool edit is
|
|
1973
|
+
* recorded twice.
|
|
1974
|
+
*/
|
|
1975
|
+
async remember(filePath) {
|
|
1976
|
+
if (this.manifest === void 0) return;
|
|
1977
|
+
const entries = new Map(this.manifest.entries);
|
|
1978
|
+
const fingerprint = await this.manifests.fingerprint(filePath);
|
|
1979
|
+
if (fingerprint === void 0) entries.delete(filePath);
|
|
1980
|
+
else entries.set(filePath, fingerprint);
|
|
1981
|
+
this.manifest = {
|
|
1982
|
+
entries,
|
|
1983
|
+
truncated: this.manifest.truncated
|
|
1984
|
+
};
|
|
1985
|
+
}
|
|
1986
|
+
};
|
|
1987
|
+
//#endregion
|
|
1988
|
+
//#region ../../default/po-file-edit/src/types/webFiles.ts
|
|
1989
|
+
/** The frame type the hub publishes and the web plugin claims; declared in the poWeb block too. */
|
|
1990
|
+
const filesChannelType = "file_edits";
|
|
1991
|
+
/** Footer status key whose presence shows the activity group; the extension publishes it. */
|
|
1992
|
+
const filesStatusKey = "po-file-edit-files";
|
|
1993
|
+
//#endregion
|
|
1994
|
+
//#region ../../default/po-file-edit/src/types/apiRoutes.ts
|
|
1995
|
+
/**
|
|
1996
|
+
* This package's routes, as data.
|
|
1997
|
+
*
|
|
1998
|
+
* No scope and no base path. The build reads both off
|
|
1999
|
+
* `src/extensions/workspaces/sessions/(backend)/api/file-edits/`, so the mount
|
|
2000
|
+
* is stated once, by the folder that creates it. They used to be written here,
|
|
2001
|
+
* in the contract and again inside every URL the page built, and the copies
|
|
2002
|
+
* were free to disagree.
|
|
2003
|
+
*
|
|
2004
|
+
* This is the one file the routes, the Hono app and the browser all read, so a
|
|
2005
|
+
* path cannot move on one side alone.
|
|
2006
|
+
*/
|
|
2007
|
+
const routes = {
|
|
2008
|
+
detail: {
|
|
2009
|
+
method: "GET",
|
|
2010
|
+
path: "/detail",
|
|
2011
|
+
query: ["path"],
|
|
2012
|
+
response: void 0
|
|
2013
|
+
},
|
|
2014
|
+
preview: {
|
|
2015
|
+
method: "GET",
|
|
2016
|
+
path: "/preview",
|
|
2017
|
+
query: ["path"],
|
|
2018
|
+
response: void 0
|
|
2019
|
+
},
|
|
2020
|
+
save: {
|
|
2021
|
+
method: "PUT",
|
|
2022
|
+
path: "/content",
|
|
2023
|
+
response: void 0
|
|
2024
|
+
},
|
|
2025
|
+
/** The same path as `save`; the method is the whole of the difference. */
|
|
2026
|
+
remove: {
|
|
2027
|
+
method: "DELETE",
|
|
2028
|
+
path: "/content",
|
|
2029
|
+
query: ["path"]
|
|
2030
|
+
},
|
|
2031
|
+
/**
|
|
2032
|
+
* The host's own bytes route, not this package's.
|
|
2033
|
+
*
|
|
2034
|
+
* `host: true` hangs it off the session root rather than under `/plugins`,
|
|
2035
|
+
* which is how the cockpit already serves it. Declaring it here is the first
|
|
2036
|
+
* time anything records that this package's previews depend on it.
|
|
2037
|
+
*/
|
|
2038
|
+
file: {
|
|
2039
|
+
method: "GET",
|
|
2040
|
+
path: "/file",
|
|
2041
|
+
raw: true,
|
|
2042
|
+
query: ["path"],
|
|
2043
|
+
host: true
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
//#endregion
|
|
2047
|
+
//#region ../../default/po-file-edit/src/types/fileEditsApi.ts
|
|
2048
|
+
/**
|
|
2049
|
+
* The wire vocabulary this package's API shares with whatever calls it.
|
|
2050
|
+
*
|
|
2051
|
+
* It lives under src/types because that is the one server root a browser
|
|
2052
|
+
* bundle may read: the cockpit plugin builds its URLs from these and the
|
|
2053
|
+
* routes answer them, so neither half can drift from the other.
|
|
2054
|
+
*
|
|
2055
|
+
* Routes live in `./apiRoutes`, which the contract, the Hono app and the
|
|
2056
|
+
* generated client all read. This file holds the shapes that travel over them.
|
|
2057
|
+
*
|
|
2058
|
+
* Opening a changed file wants its whole history at once, so `detail` answers
|
|
2059
|
+
* in one round trip rather than making the page stitch three reads together;
|
|
2060
|
+
* `content` takes the manual save back; `preview` reads a file the session
|
|
2061
|
+
* never changed, which has no history to answer with.
|
|
2062
|
+
*/
|
|
2063
|
+
/** Where a host mounts this package's API; the segment after /api/plugins/. */
|
|
2064
|
+
const API_BASE_PATH = "file-edits";
|
|
2065
|
+
/** Query parameter naming the file a request is about. */
|
|
2066
|
+
const PATH_QUERY_PARAM = "path";
|
|
2067
|
+
//#endregion
|
|
2068
|
+
//#region ../../default/po-file-edit/src/services/fileEditsApi/index.ts
|
|
2069
|
+
function createFileEditsApi(options = {}) {
|
|
2070
|
+
const storage = options.storage ?? createFileEditStorage();
|
|
2071
|
+
const timeline = options.timeline ?? storage.timeline();
|
|
2072
|
+
const snapshots = options.snapshots ?? storage.snapshots();
|
|
2073
|
+
const paths = options.paths ?? storage.paths();
|
|
2074
|
+
const files = options.files ?? storage.workingFiles();
|
|
2075
|
+
const cwd = options.cwd ?? "";
|
|
2076
|
+
const app = new Hono();
|
|
2077
|
+
if (options.sessionId !== void 0 && cwd !== "") {
|
|
2078
|
+
const sessionKey = paths.sessionKey(options.sessionId);
|
|
2079
|
+
let initializing;
|
|
2080
|
+
app.use(async (_context, next) => {
|
|
2081
|
+
initializing ??= (async () => {
|
|
2082
|
+
if (options.timeline === void 0) timeline.initialize(await paths.timelinePath(cwd, sessionKey));
|
|
2083
|
+
if (options.snapshots === void 0) snapshots.initialize(await paths.snapshotsPath(cwd, sessionKey));
|
|
2084
|
+
})();
|
|
2085
|
+
await initializing;
|
|
2086
|
+
await next();
|
|
2087
|
+
});
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* The file a request names, rejected unless this session actually recorded a
|
|
2091
|
+
* change to it. That check is the authorization: these routes read and write
|
|
2092
|
+
* whatever path they are handed, so the timeline is what bounds them to files
|
|
2093
|
+
* the session already touched.
|
|
2094
|
+
*/
|
|
2095
|
+
const recordedVersions = async (filePath) => {
|
|
2096
|
+
if (filePath === void 0 || filePath === "") return void 0;
|
|
2097
|
+
const versions = await timeline.versions(path.resolve(cwd, filePath));
|
|
2098
|
+
return versions.length === 0 ? void 0 : versions;
|
|
2099
|
+
};
|
|
2100
|
+
const isInsideSession = async (filePath) => {
|
|
2101
|
+
if (cwd === "") return false;
|
|
2102
|
+
const root = path.resolve(cwd);
|
|
2103
|
+
return isInside(root, filePath) && await files.isRealPathInside(root, filePath);
|
|
2104
|
+
};
|
|
2105
|
+
/** The Po-owned folder holding the file, checked the same two ways as the working directory. */
|
|
2106
|
+
const readableRootOf = async (filePath) => {
|
|
2107
|
+
for (const root of await options.readableRoots?.() ?? []) {
|
|
2108
|
+
const resolved = path.resolve(root);
|
|
2109
|
+
if (isInside(resolved, filePath) && await files.isRealPathInside(resolved, filePath)) return resolved;
|
|
2110
|
+
}
|
|
2111
|
+
};
|
|
2112
|
+
app.get(routes.detail.path, async (context) => {
|
|
2113
|
+
const requested = context.req.query(PATH_QUERY_PARAM);
|
|
2114
|
+
const versions = await recordedVersions(requested);
|
|
2115
|
+
if (versions === void 0 || requested === void 0) return context.json({ error: "This session recorded no changes to that file." }, 404);
|
|
2116
|
+
const filePath = path.resolve(cwd, requested);
|
|
2117
|
+
const allowedRoot = cwd !== "" && isInside(path.resolve(cwd), filePath) ? path.resolve(cwd) : void 0;
|
|
2118
|
+
const working = await files.readWorking(filePath, allowedRoot);
|
|
2119
|
+
const body = {
|
|
2120
|
+
path: filePath,
|
|
2121
|
+
relPath: cwd === "" ? filePath : path.relative(cwd, filePath),
|
|
2122
|
+
versions: await Promise.all(versions.map((version) => toVersionView(version, snapshots))),
|
|
2123
|
+
cumulative: await toCumulativeView(versions, working, snapshots),
|
|
2124
|
+
working
|
|
2125
|
+
};
|
|
2126
|
+
return context.json(body);
|
|
2127
|
+
});
|
|
2128
|
+
/**
|
|
2129
|
+
* The file a request names, read only, for a file the timeline knows nothing
|
|
2130
|
+
* about: a path the agent read but never changed is still a path the reader
|
|
2131
|
+
* clicked, and refusing it would leave the link dead.
|
|
2132
|
+
*
|
|
2133
|
+
* The working directory is the boundary here, since the timeline is not.
|
|
2134
|
+
* Containment is checked lexically and again on the real path, so a symlink
|
|
2135
|
+
* inside the tree cannot hand out something beyond it, and a host that gave
|
|
2136
|
+
* these routes no working directory has no boundary to enforce and so serves
|
|
2137
|
+
* nothing.
|
|
2138
|
+
*/
|
|
2139
|
+
app.get(routes.preview.path, async (context) => {
|
|
2140
|
+
const requested = context.req.query(PATH_QUERY_PARAM);
|
|
2141
|
+
if (requested === void 0 || requested === "" || requested.includes("\0")) return context.json({ error: "A preview names a path." }, 400);
|
|
2142
|
+
if (cwd === "") return context.json({ error: "This session has no working directory to read from." }, 403);
|
|
2143
|
+
const root = path.resolve(cwd);
|
|
2144
|
+
const filePath = path.resolve(root, requested);
|
|
2145
|
+
const inSession = await isInsideSession(filePath);
|
|
2146
|
+
const allowedRoot = inSession ? root : await readableRootOf(filePath);
|
|
2147
|
+
if (allowedRoot === void 0) return context.json({ error: "The path leaves the session directory." }, 403);
|
|
2148
|
+
const body = {
|
|
2149
|
+
path: filePath,
|
|
2150
|
+
relPath: inSession ? path.relative(root, filePath) : filePath,
|
|
2151
|
+
working: await files.readWorking(filePath, allowedRoot)
|
|
2152
|
+
};
|
|
2153
|
+
return context.json(body);
|
|
2154
|
+
});
|
|
2155
|
+
app.put(routes.save.path, async (context) => {
|
|
2156
|
+
let request;
|
|
2157
|
+
try {
|
|
2158
|
+
request = await context.req.json();
|
|
2159
|
+
} catch {
|
|
2160
|
+
return context.json({ error: "The save body is not JSON." }, 400);
|
|
2161
|
+
}
|
|
2162
|
+
if (typeof request !== "object" || request === null || Array.isArray(request) || !("path" in request) || typeof request.path !== "string" || !("content" in request) || typeof request.content !== "string" || !("expectedHash" in request) || typeof request.expectedHash !== "string") return context.json({ error: "A save names a path, the content to write and the hash it was read at." }, 400);
|
|
2163
|
+
const { path: requested, content, expectedHash } = request;
|
|
2164
|
+
if (await recordedVersions(requested) === void 0) return context.json({ error: "This session recorded no changes to that file." }, 404);
|
|
2165
|
+
const filePath = path.resolve(cwd, requested);
|
|
2166
|
+
if (!await isInsideSession(filePath)) return context.json({ error: "Files outside the session directory are read-only." }, 403);
|
|
2167
|
+
if (new TextEncoder().encode(content).byteLength > 1048576) return context.json({ error: `The file is larger than ${MAX_WORKING_BYTES} bytes.` }, 413);
|
|
2168
|
+
try {
|
|
2169
|
+
const outcome = await files.save({
|
|
2170
|
+
filePath,
|
|
2171
|
+
root: path.resolve(cwd),
|
|
2172
|
+
content,
|
|
2173
|
+
expectedHash
|
|
2174
|
+
});
|
|
2175
|
+
switch (outcome.status) {
|
|
2176
|
+
case "saved": {
|
|
2177
|
+
const body = { hash: outcome.hash };
|
|
2178
|
+
return context.json(body);
|
|
2179
|
+
}
|
|
2180
|
+
case "stale": return context.json({
|
|
2181
|
+
error: "The file changed since it was opened.",
|
|
2182
|
+
hash: outcome.hash
|
|
2183
|
+
}, 409);
|
|
2184
|
+
case "unreadable": return context.json({ error: outcome.reason }, 409);
|
|
2185
|
+
case "moved": return context.json({ error: "The file changed before it could be written." }, 409);
|
|
2186
|
+
}
|
|
2187
|
+
} catch {
|
|
2188
|
+
return context.json({ error: "The file cannot be safely written." }, 409);
|
|
2189
|
+
}
|
|
2190
|
+
});
|
|
2191
|
+
app.delete(routes.remove.path, async (context) => {
|
|
2192
|
+
const requested = context.req.query(PATH_QUERY_PARAM);
|
|
2193
|
+
if (await recordedVersions(requested) === void 0 || requested === void 0) return context.json({ error: "This session recorded no changes to that file." }, 404);
|
|
2194
|
+
const filePath = path.resolve(cwd, requested);
|
|
2195
|
+
if (!await isInsideSession(filePath)) return context.json({ error: "Files outside the session directory are read-only." }, 403);
|
|
2196
|
+
const outcome = await files.remove(filePath, path.resolve(cwd));
|
|
2197
|
+
switch (outcome.status) {
|
|
2198
|
+
case "outside": return context.json({ error: "Files outside the session directory are read-only." }, 403);
|
|
2199
|
+
case "failed": return context.json({ error: `The file could not be deleted: ${outcome.reason}` }, 409);
|
|
2200
|
+
case "removed": return context.body(null, 204);
|
|
2201
|
+
}
|
|
2202
|
+
});
|
|
2203
|
+
return app;
|
|
2204
|
+
}
|
|
2205
|
+
/** The named export a host mounts, built over the storage it runs on. */
|
|
2206
|
+
function createFileEditsPoApi(storage) {
|
|
2207
|
+
return {
|
|
2208
|
+
basePath: API_BASE_PATH,
|
|
2209
|
+
start(context) {
|
|
2210
|
+
const environment = context.environment ?? {};
|
|
2211
|
+
const cwd = context.cwd;
|
|
2212
|
+
const app = createFileEditsApi({
|
|
2213
|
+
storage,
|
|
2214
|
+
paths: storage.paths({
|
|
2215
|
+
...environment,
|
|
2216
|
+
HOME: context.homeDirectory ?? environment.HOME
|
|
2217
|
+
}),
|
|
2218
|
+
...context.sessionId === void 0 ? {} : { sessionId: context.sessionId },
|
|
2219
|
+
...cwd === void 0 ? {} : {
|
|
2220
|
+
cwd,
|
|
2221
|
+
readableRoots: storage.readableRoots({
|
|
2222
|
+
cwd,
|
|
2223
|
+
environment,
|
|
2224
|
+
...context.homeDirectory === void 0 ? {} : { homeDirectory: context.homeDirectory }
|
|
2225
|
+
})
|
|
2226
|
+
}
|
|
2227
|
+
});
|
|
2228
|
+
return {
|
|
2229
|
+
fetch: (request) => app.fetch(request),
|
|
2230
|
+
close: () => void 0
|
|
2231
|
+
};
|
|
2232
|
+
}
|
|
2233
|
+
};
|
|
2234
|
+
}
|
|
2235
|
+
//#endregion
|
|
2236
|
+
//#region ../../default/po-file-edit/src/services/fileEditSession/index.ts
|
|
2237
|
+
const PO_IGNORE_FILE = ".poignore";
|
|
2238
|
+
async function readPoIgnore(cwd, fs) {
|
|
2239
|
+
try {
|
|
2240
|
+
const content = await readTextIfExists(fs, path.join(cwd, PO_IGNORE_FILE), BACKGROUND_CONTEXT);
|
|
2241
|
+
if (content === void 0) return void 0;
|
|
2242
|
+
const matcher = createPoIgnoreMatcher(content);
|
|
2243
|
+
return matcher === void 0 ? void 0 : (filePath) => matcher(path.relative(cwd, filePath));
|
|
2244
|
+
} catch {
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
/** Export only fixed categories from structured tool details, never displayed output. */
|
|
2249
|
+
function failureAttributes(result) {
|
|
2250
|
+
if (!result || typeof result !== "object" || !("details" in result)) return {};
|
|
2251
|
+
const details = result.details;
|
|
2252
|
+
if (!details || typeof details !== "object") return {};
|
|
2253
|
+
const failure = "failure" in details ? details.failure : void 0;
|
|
2254
|
+
const kind = failure && typeof failure === "object" && "kind" in failure ? failure.kind : void 0;
|
|
2255
|
+
return {
|
|
2256
|
+
...typeof kind === "string" && [
|
|
2257
|
+
"timeout",
|
|
2258
|
+
"exit_code",
|
|
2259
|
+
"not_found",
|
|
2260
|
+
"permission",
|
|
2261
|
+
"validation",
|
|
2262
|
+
"aborted",
|
|
2263
|
+
"unknown"
|
|
2264
|
+
].includes(kind) ? { "failure.kind": kind } : {},
|
|
2265
|
+
..."exit_code" in details && typeof details.exit_code === "number" && Number.isFinite(details.exit_code) ? { exit_code: details.exit_code } : {}
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2268
|
+
function stringValue(value, key) {
|
|
2269
|
+
const candidate = value[key];
|
|
2270
|
+
return typeof candidate === "string" && candidate.length > 0 ? candidate : void 0;
|
|
2271
|
+
}
|
|
2272
|
+
function createFileEditSession({ agent, host }, fs, storage = createFileEditStorage(fs)) {
|
|
2273
|
+
const fileEditsApi = createFileEditsPoApi(storage);
|
|
2274
|
+
if (!agent) return { api: [fileEditsApi] };
|
|
2275
|
+
const environment = Object.freeze({ ...host.context.environment });
|
|
2276
|
+
const paths = storage.paths(environment);
|
|
2277
|
+
const timeline = storage.timeline();
|
|
2278
|
+
const snapshots = storage.snapshots();
|
|
2279
|
+
const editTracker = new EditTracker(timeline, snapshots, storage.manifests(), { git: storage.git() });
|
|
2280
|
+
if (host.context.directEvents === void 0) throw new Error("File-edit server plugin requires the session direct event bus.");
|
|
2281
|
+
const directEvents = host.context.directEvents;
|
|
2282
|
+
const telemetry = createPoTelemetry({
|
|
2283
|
+
serviceName: "po-file-edit",
|
|
2284
|
+
packageName: "@agimon-ai/po-file-edit",
|
|
2285
|
+
env: environment,
|
|
2286
|
+
enableLogs: true,
|
|
2287
|
+
enableTraces: true
|
|
2288
|
+
});
|
|
2289
|
+
const toolStartedAt = /* @__PURE__ */ new Map();
|
|
2290
|
+
const pending = /* @__PURE__ */ new Set();
|
|
2291
|
+
let closed = false;
|
|
2292
|
+
let disposal;
|
|
2293
|
+
let stopping;
|
|
2294
|
+
let starting;
|
|
2295
|
+
let initialized = false;
|
|
2296
|
+
const track = (work) => {
|
|
2297
|
+
const task = work();
|
|
2298
|
+
pending.add(task);
|
|
2299
|
+
task.finally(() => pending.delete(task)).catch(() => {});
|
|
2300
|
+
return task;
|
|
2301
|
+
};
|
|
2302
|
+
let active;
|
|
2303
|
+
let lastRuntime;
|
|
2304
|
+
/**
|
|
2305
|
+
* The channel carries the rows; the status decides whether the group exists.
|
|
2306
|
+
*
|
|
2307
|
+
* A cockpit drives this server plugin and never the Pi runtime, so without the status
|
|
2308
|
+
* the dock had the file list on the wire and no frame to draw it in. The empty
|
|
2309
|
+
* string is deliberate: the group declares `hideWhenEmpty`, so a session that
|
|
2310
|
+
* has edited nothing publishes a key with no content and stays hidden.
|
|
2311
|
+
*/
|
|
2312
|
+
const publish = async (runtime) => {
|
|
2313
|
+
const items = await storage.sessionFiles(runtime.timelinePath, runtime.context.cwd);
|
|
2314
|
+
if (active !== runtime || closed || stopping) return;
|
|
2315
|
+
directEvents.publish(filesChannelType, runtime.context.sessionId, { items });
|
|
2316
|
+
runtime.context.client.setStatus(filesStatusKey, items.length === 0 ? "" : `${items.length} ${items.length === 1 ? "file" : "files"}`);
|
|
2317
|
+
};
|
|
2318
|
+
const stopActivity = () => {
|
|
2319
|
+
if (stopping) return stopping;
|
|
2320
|
+
const runtime = active;
|
|
2321
|
+
active = void 0;
|
|
2322
|
+
stopping = (async () => {
|
|
2323
|
+
while (pending.size > 0) await Promise.allSettled(pending);
|
|
2324
|
+
const startedRuntime = active;
|
|
2325
|
+
active = void 0;
|
|
2326
|
+
await editTracker.flush();
|
|
2327
|
+
editTracker.reset();
|
|
2328
|
+
toolStartedAt.clear();
|
|
2329
|
+
(runtime ?? startedRuntime)?.context.client.setStatus(filesStatusKey, void 0);
|
|
2330
|
+
})();
|
|
2331
|
+
return stopping;
|
|
2332
|
+
};
|
|
2333
|
+
const dispose = () => {
|
|
2334
|
+
if (disposal) return disposal;
|
|
2335
|
+
closed = true;
|
|
2336
|
+
disposal = runCleanups([
|
|
2337
|
+
stopActivity,
|
|
2338
|
+
async () => {
|
|
2339
|
+
if (storage.clearOnClose && lastRuntime && !environment["PI_SUBAGENT_CHILD"]) await timeline.clear();
|
|
2340
|
+
},
|
|
2341
|
+
async () => {
|
|
2342
|
+
if (storage.clearOnClose && lastRuntime && !environment["PI_SUBAGENT_CHILD"]) await snapshots.clear();
|
|
2343
|
+
},
|
|
2344
|
+
async () => {
|
|
2345
|
+
if (lastRuntime) await telemetry.recordEvent("po_file_edit.timeline_finished", { outcome: "closed" });
|
|
2346
|
+
},
|
|
2347
|
+
() => telemetry.shutdown()
|
|
2348
|
+
], "File-edit session cleanup failed.");
|
|
2349
|
+
return disposal;
|
|
2350
|
+
};
|
|
2351
|
+
return {
|
|
2352
|
+
api: [fileEditsApi],
|
|
2353
|
+
activities: [{
|
|
2354
|
+
name: "file-edits",
|
|
2355
|
+
start: async (executionContext) => {
|
|
2356
|
+
if (closed) throw new Error("File-edit session is closed.");
|
|
2357
|
+
if (starting) return starting;
|
|
2358
|
+
if (active) return stopActivity;
|
|
2359
|
+
if (stopping) await stopping;
|
|
2360
|
+
if (closed) throw new Error("File-edit session is closed.");
|
|
2361
|
+
if (starting) return starting;
|
|
2362
|
+
stopping = void 0;
|
|
2363
|
+
starting = track(async () => {
|
|
2364
|
+
const sessionKey = paths.sessionKey(executionContext.sessionId);
|
|
2365
|
+
const timelinePath = await paths.timelinePath(executionContext.cwd, sessionKey);
|
|
2366
|
+
const snapshotsPath = await paths.snapshotsPath(executionContext.cwd, sessionKey);
|
|
2367
|
+
timeline.initialize(timelinePath);
|
|
2368
|
+
snapshots.initialize(snapshotsPath);
|
|
2369
|
+
const isIgnored = await readPoIgnore(executionContext.cwd, fs);
|
|
2370
|
+
editTracker.reset({
|
|
2371
|
+
exclude: [
|
|
2372
|
+
timelinePath,
|
|
2373
|
+
`${timelinePath}.lock`,
|
|
2374
|
+
snapshotsPath
|
|
2375
|
+
],
|
|
2376
|
+
...isIgnored === void 0 ? {} : { isIgnored }
|
|
2377
|
+
});
|
|
2378
|
+
const runtime = {
|
|
2379
|
+
context: executionContext,
|
|
2380
|
+
timelinePath,
|
|
2381
|
+
snapshotsPath
|
|
2382
|
+
};
|
|
2383
|
+
active = runtime;
|
|
2384
|
+
lastRuntime = runtime;
|
|
2385
|
+
await publish(runtime);
|
|
2386
|
+
track(async () => {
|
|
2387
|
+
try {
|
|
2388
|
+
await storage.sweepAbandoned?.(paths.stateDirectory(), timelinePath);
|
|
2389
|
+
} catch {}
|
|
2390
|
+
});
|
|
2391
|
+
if (!initialized) {
|
|
2392
|
+
initialized = true;
|
|
2393
|
+
await track(() => telemetry.recordEvent("po_file_edit.timeline_started", { outcome: "initialized" }));
|
|
2394
|
+
}
|
|
2395
|
+
return () => active === runtime ? stopActivity() : Promise.resolve();
|
|
2396
|
+
});
|
|
2397
|
+
try {
|
|
2398
|
+
return await starting;
|
|
2399
|
+
} finally {
|
|
2400
|
+
starting = void 0;
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
}],
|
|
2404
|
+
hooks: [{
|
|
2405
|
+
event: "tool_execution_start",
|
|
2406
|
+
handle: (event, executionContext) => {
|
|
2407
|
+
if (closed || stopping) return;
|
|
2408
|
+
const runtime = active;
|
|
2409
|
+
const toolCallId = stringValue(event, "toolCallId");
|
|
2410
|
+
const toolName = stringValue(event, "toolName");
|
|
2411
|
+
if (runtime === void 0 || runtime.context.sessionId !== executionContext.sessionId || !toolCallId || !toolName) return;
|
|
2412
|
+
return track(async () => {
|
|
2413
|
+
const hookStartedAt = Date.now();
|
|
2414
|
+
if (!await editTracker.start(toolCallId, toolName, event.args, executionContext.cwd) || active !== runtime) return;
|
|
2415
|
+
toolStartedAt.set(toolCallId, hookStartedAt);
|
|
2416
|
+
await telemetry.recordEvent("po_file_edit.edit_started", {
|
|
2417
|
+
"tool.name": toolName,
|
|
2418
|
+
hook_ms: Date.now() - hookStartedAt
|
|
2419
|
+
});
|
|
2420
|
+
});
|
|
2421
|
+
}
|
|
2422
|
+
}, {
|
|
2423
|
+
event: "tool_execution_end",
|
|
2424
|
+
handle: (event, executionContext) => {
|
|
2425
|
+
if (closed || stopping) return;
|
|
2426
|
+
const runtime = active;
|
|
2427
|
+
const toolCallId = stringValue(event, "toolCallId");
|
|
2428
|
+
const toolName = stringValue(event, "toolName");
|
|
2429
|
+
if (runtime === void 0 || runtime.context.sessionId !== executionContext.sessionId || !toolCallId || !toolName) return;
|
|
2430
|
+
return track(async () => {
|
|
2431
|
+
const startedAt = toolStartedAt.get(toolCallId);
|
|
2432
|
+
if (startedAt === void 0) return;
|
|
2433
|
+
toolStartedAt.delete(toolCallId);
|
|
2434
|
+
const hookStartedAt = Date.now();
|
|
2435
|
+
const isError = event.isError === true;
|
|
2436
|
+
await editTracker.end(toolCallId, isError, executionContext.cwd);
|
|
2437
|
+
if (active !== runtime) return;
|
|
2438
|
+
await publish(runtime);
|
|
2439
|
+
await telemetry.recordEvent("po_file_edit.edit_finished", {
|
|
2440
|
+
"tool.name": toolName,
|
|
2441
|
+
"tool.result.error": isError,
|
|
2442
|
+
...failureAttributes(event.result),
|
|
2443
|
+
...startedAt === void 0 ? {} : { duration_ms: Date.now() - startedAt },
|
|
2444
|
+
hook_ms: Date.now() - hookStartedAt,
|
|
2445
|
+
outcome: isError ? "failed" : "completed"
|
|
2446
|
+
});
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2449
|
+
}],
|
|
2450
|
+
onDispose: dispose
|
|
2451
|
+
};
|
|
2452
|
+
}
|
|
2453
|
+
//#endregion
|
|
2454
|
+
//#region ../../default/po-file-edit/src/extensions/workspaces/sessions/(backend)/_lib/serverRoot.ts
|
|
2455
|
+
function createPresence({ agent, host, context }, presence, files) {
|
|
2456
|
+
if (!agent || !presence) return void 0;
|
|
2457
|
+
const execution = agent.context;
|
|
2458
|
+
return createSessionPresence({
|
|
2459
|
+
presence,
|
|
2460
|
+
sessionId: execution.sessionId,
|
|
2461
|
+
cwd: execution.cwd,
|
|
2462
|
+
files,
|
|
2463
|
+
workflowStep: execution.sessionContext?.provenance === WORKFLOW_STEP_SESSION_PROVENANCE,
|
|
2464
|
+
isLive: () => host.context.sessionService?.isLive(execution.sessionId) ?? true,
|
|
2465
|
+
labelFor: (runId) => readPoChildSessionLabels(context)?.labelFor(runId),
|
|
2466
|
+
onError: (error) => host.context.onNotice(`Edit presence failed: ${error instanceof Error ? error.message : String(error)}`)
|
|
2467
|
+
});
|
|
2468
|
+
}
|
|
2469
|
+
const createFileEditServerRoot = (context, fs) => {
|
|
2470
|
+
const storage = createFileEditStorage(fs);
|
|
2471
|
+
const runtime = createFileEditSession(context, fs, storage);
|
|
2472
|
+
let presence;
|
|
2473
|
+
let disposePresence = () => {};
|
|
2474
|
+
let closed = false;
|
|
2475
|
+
let disposal;
|
|
2476
|
+
return {
|
|
2477
|
+
value: {
|
|
2478
|
+
...runtime,
|
|
2479
|
+
get presence() {
|
|
2480
|
+
return presence;
|
|
2481
|
+
}
|
|
2482
|
+
},
|
|
2483
|
+
activities: runtime.activities,
|
|
2484
|
+
services: [(cordis) => {
|
|
2485
|
+
cordis.inject([PO_EDIT_PRESENCE_SERVICE], (presenceContext) => {
|
|
2486
|
+
if (closed) return;
|
|
2487
|
+
const bound = createPresence(context, presenceContext.get(PO_EDIT_PRESENCE_SERVICE), storage.presenceFiles());
|
|
2488
|
+
if (!bound) return;
|
|
2489
|
+
presence = bound;
|
|
2490
|
+
let disposed = false;
|
|
2491
|
+
const cleanup = () => {
|
|
2492
|
+
if (disposed) return;
|
|
2493
|
+
disposed = true;
|
|
2494
|
+
if (presence === bound) presence = void 0;
|
|
2495
|
+
bound.dispose();
|
|
2496
|
+
};
|
|
2497
|
+
disposePresence = cleanup;
|
|
2498
|
+
presenceContext.inject([PO_CHILD_SESSION_HOOK_REGISTRY_SERVICE], (registryContext) => {
|
|
2499
|
+
const registration = registryContext.get(PO_CHILD_SESSION_HOOK_REGISTRY_SERVICE).register(bound.childHooks);
|
|
2500
|
+
return () => registration.dispose();
|
|
2501
|
+
});
|
|
2502
|
+
return cleanup;
|
|
2503
|
+
});
|
|
2504
|
+
}],
|
|
2505
|
+
onDispose: (pluginContext) => {
|
|
2506
|
+
closed = true;
|
|
2507
|
+
return disposal ??= runCleanups([() => disposePresence(), () => runtime.onDispose?.(pluginContext)], "File-edit root cleanup failed.");
|
|
2508
|
+
}
|
|
2509
|
+
};
|
|
2510
|
+
};
|
|
2511
|
+
//#endregion
|
|
2512
|
+
//#region ../../default/po-file-edit/src/extensions/workspaces/sessions/(backend)/root.server.ts
|
|
2513
|
+
var root_server_default = defineRoot((context) => createFileEditServerRoot(context, requirePoFs(context.context)));
|
|
2514
|
+
//#endregion
|
|
2515
|
+
//#region ../../default/po-file-edit/src/services/filesChannel/index.ts
|
|
2516
|
+
/**
|
|
2517
|
+
* The changed-files channel consumes snapshots emitted by the owning session's
|
|
2518
|
+
* server plugin. Durable timeline reads seed a channel that starts after session
|
|
2519
|
+
* startup.
|
|
2520
|
+
*/
|
|
2521
|
+
function filesPayload(value) {
|
|
2522
|
+
return typeof value === "object" && value !== null && Array.isArray(value.items);
|
|
2523
|
+
}
|
|
2524
|
+
/**
|
|
2525
|
+
* The files data channel: one direct-event subscription per managed session,
|
|
2526
|
+
* published as { items } payloads under the 'file_edits' frame type.
|
|
2527
|
+
*/
|
|
2528
|
+
function createFilesChannel(storage) {
|
|
2529
|
+
return {
|
|
2530
|
+
frameType: filesChannelType,
|
|
2531
|
+
start(host) {
|
|
2532
|
+
const latest = /* @__PURE__ */ new Map();
|
|
2533
|
+
const subscriptions = /* @__PURE__ */ new Map();
|
|
2534
|
+
return {
|
|
2535
|
+
payloadFor(scope) {
|
|
2536
|
+
const items = latest.get(scope.sessionId);
|
|
2537
|
+
return items === void 0 ? void 0 : { items };
|
|
2538
|
+
},
|
|
2539
|
+
sessionAdded(scope) {
|
|
2540
|
+
subscriptions.get(scope.sessionId)?.();
|
|
2541
|
+
const paths = storage.paths(scope.environment);
|
|
2542
|
+
let current = true;
|
|
2543
|
+
let receivedDirect = false;
|
|
2544
|
+
const unsubscribe = host.directEvents.subscribe(filesChannelType, scope.sessionId, (payload) => {
|
|
2545
|
+
if (!filesPayload(payload)) return;
|
|
2546
|
+
receivedDirect = true;
|
|
2547
|
+
latest.set(scope.sessionId, payload.items);
|
|
2548
|
+
host.publish(scope.sessionId, payload);
|
|
2549
|
+
}, { replayLatest: true });
|
|
2550
|
+
subscriptions.set(scope.sessionId, () => {
|
|
2551
|
+
current = false;
|
|
2552
|
+
unsubscribe();
|
|
2553
|
+
});
|
|
2554
|
+
(async () => {
|
|
2555
|
+
let items = [];
|
|
2556
|
+
try {
|
|
2557
|
+
const timelinePath = await paths.timelinePath(scope.cwd, paths.sessionKey(scope.sessionId));
|
|
2558
|
+
items = await storage.sessionFiles(timelinePath, scope.cwd);
|
|
2559
|
+
} catch {}
|
|
2560
|
+
if (!current || receivedDirect) return;
|
|
2561
|
+
latest.set(scope.sessionId, items);
|
|
2562
|
+
host.publish(scope.sessionId, { items });
|
|
2563
|
+
})().catch((error) => host.onNotice(`File-edit channel seed failed: ${String(error)}`));
|
|
2564
|
+
},
|
|
2565
|
+
sessionRemoved(sessionId) {
|
|
2566
|
+
subscriptions.get(sessionId)?.();
|
|
2567
|
+
subscriptions.delete(sessionId);
|
|
2568
|
+
latest.delete(sessionId);
|
|
2569
|
+
},
|
|
2570
|
+
close() {
|
|
2571
|
+
for (const unsubscribe of subscriptions.values()) unsubscribe();
|
|
2572
|
+
subscriptions.clear();
|
|
2573
|
+
latest.clear();
|
|
2574
|
+
}
|
|
2575
|
+
};
|
|
2576
|
+
}
|
|
2577
|
+
};
|
|
2578
|
+
}
|
|
2579
|
+
//#endregion
|
|
2580
|
+
//#region ../../default/po-file-edit/src/extensions/(backend)/channel/fileEdits.server.ts
|
|
2581
|
+
var fileEdits_server_default = defineChannel(function fileEditsChannel(context) {
|
|
2582
|
+
return createFilesChannel(createFileEditStorage(readPoFs(context.context)));
|
|
2583
|
+
}, { context: true });
|
|
2584
|
+
//#endregion
|
|
2585
|
+
//#region ../../default/po-file-edit/src/extensions/workspaces/sessions/(backend)/api/file-edits/route.server.ts
|
|
2586
|
+
/**
|
|
2587
|
+
* Mounts this package's HTTP API at `file-edits`, which the folder names.
|
|
2588
|
+
*
|
|
2589
|
+
* Until this file existed the API was never mounted at all. The session root
|
|
2590
|
+
* returns a runtime carrying `api`, but a root's `api` is not folded into the
|
|
2591
|
+
* generated entry the way its services and activities are, so the registration
|
|
2592
|
+
* was dropped in silence and the cockpit called routes that answered 404.
|
|
2593
|
+
*
|
|
2594
|
+
* The API reads the files of the host it runs on, so it is built from the file
|
|
2595
|
+
* system the session was given.
|
|
2596
|
+
*/
|
|
2597
|
+
var route_server_default = defineRoute((context) => createFileEditsPoApi(createFileEditStorage(readPoFs(context.context))));
|
|
2598
|
+
//#endregion
|
|
2599
|
+
//#region ../../default/po-file-edit/src/extensions/workspaces/sessions/(backend)/hook/tool-execution-end.server.ts
|
|
2600
|
+
var tool_execution_end_server_default = defineHook((context) => context.root.hooks[1]);
|
|
2601
|
+
//#endregion
|
|
2602
|
+
//#region ../../default/po-file-edit/src/extensions/workspaces/sessions/(backend)/hook/tool-execution-start.server.ts
|
|
2603
|
+
var tool_execution_start_server_default = defineHook((context) => context.root.hooks[0]);
|
|
2604
|
+
//#endregion
|
|
2605
|
+
//#region ../../default/po-file-edit/src/extensions/workspaces/sessions/(backend)/hook/tool-result.server.ts
|
|
2606
|
+
var tool_result_server_default = defineHook(({ root }) => ({
|
|
2607
|
+
event: "tool_result",
|
|
2608
|
+
handle: async (event, execution) => root.presence?.toolResult.handle(event, execution)
|
|
2609
|
+
}));
|
|
2610
|
+
//#endregion
|
|
2611
|
+
//#region ../../default/po-file-edit/generated/server.ts
|
|
2612
|
+
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
2613
|
+
/* v8 ignore next -- generated normalization branch */
|
|
2614
|
+
const defined = (values) => values.filter((value) => value !== void 0);
|
|
2615
|
+
const via = (identity, value) => value === void 0 ? void 0 : {
|
|
2616
|
+
...identity,
|
|
2617
|
+
...value
|
|
2618
|
+
};
|
|
2619
|
+
const serverPlugin = defineServerPlugin({
|
|
2620
|
+
name: "@agimon-ai/po-file-edit",
|
|
2621
|
+
providerOverrides: composeServerProviderOverrides(root_server_default),
|
|
2622
|
+
injects: composeRootInjects({ session: [root_server_default] }),
|
|
2623
|
+
global: (context) => ({ get channels() {
|
|
2624
|
+
return [() => via({ frameType: "file_edits" }, at(fileEdits_server_default, context))];
|
|
2625
|
+
} }),
|
|
2626
|
+
workspace: (context) => ({ get channels() {
|
|
2627
|
+
return defined([context.hosted("global") ? void 0 : () => via({ frameType: "file_edits" }, at(fileEdits_server_default, context))]);
|
|
2628
|
+
} }),
|
|
2629
|
+
session: async (context) => {
|
|
2630
|
+
const scopeSession = await context.scopeRoot("session", root_server_default, context);
|
|
2631
|
+
const contextSession = {
|
|
2632
|
+
...context,
|
|
2633
|
+
root: scopeSession.value
|
|
2634
|
+
};
|
|
2635
|
+
return {
|
|
2636
|
+
...composeRootHooks(scopeSession),
|
|
2637
|
+
get api() {
|
|
2638
|
+
return [at(route_server_default, contextSession)];
|
|
2639
|
+
},
|
|
2640
|
+
get channels() {
|
|
2641
|
+
return defined([context.hosted("global") ? void 0 : () => via({ frameType: "file_edits" }, at(fileEdits_server_default, context))]);
|
|
2642
|
+
},
|
|
2643
|
+
get hooks() {
|
|
2644
|
+
return [
|
|
2645
|
+
via({ event: "tool_execution_end" }, at(tool_execution_end_server_default, contextSession)),
|
|
2646
|
+
via({ event: "tool_execution_start" }, at(tool_execution_start_server_default, contextSession)),
|
|
2647
|
+
via({ event: "tool_result" }, at(tool_result_server_default, contextSession))
|
|
2648
|
+
];
|
|
2649
|
+
},
|
|
2650
|
+
services: [...scopeSession.services ?? []],
|
|
2651
|
+
get activities() {
|
|
2652
|
+
return [...scopeSession.activities ?? []];
|
|
2653
|
+
}
|
|
2654
|
+
};
|
|
2655
|
+
}
|
|
2656
|
+
});
|
|
2657
|
+
//#endregion
|
|
2658
|
+
export { serverPlugin as default, serverPlugin };
|