@youweichen/pi-harness 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +74 -2
- package/bin/pi-harness.mjs +1819 -0
- package/deploy/com.youweichen.pi-harness.plist +48 -0
- package/deploy/nginx-subpath.conf +88 -0
- package/deploy/pi-harness-task.xml +71 -0
- package/deploy/pi-harness.service +31 -0
- package/dist/server/agent-service.js +3051 -0
- package/dist/server/app-version.js +19 -0
- package/dist/server/attachments.js +526 -0
- package/dist/server/auth-file.js +61 -0
- package/dist/server/bg-servers.js +154 -0
- package/dist/server/client-eviction.js +19 -0
- package/dist/server/client-id.js +9 -0
- package/dist/server/client-state.js +202 -0
- package/dist/server/codemode-image-routes.js +36 -0
- package/dist/server/codemode-presentation.js +19 -0
- package/dist/server/component-updates.js +135 -0
- package/dist/server/context-breakdown.js +56 -0
- package/dist/server/control-socket.js +177 -0
- package/dist/server/conversation.js +65 -0
- package/dist/server/dir-browser.js +77 -0
- package/dist/server/editor-snapshot.js +38 -0
- package/dist/server/ensure-bash.js +80 -0
- package/dist/server/extension-display.js +23 -0
- package/dist/server/extensions-catalog.js +64 -0
- package/dist/server/extensions-model.js +46 -0
- package/dist/server/extensions-routes.js +255 -0
- package/dist/server/extensions-worker.js +187 -0
- package/dist/server/files-service.js +795 -0
- package/dist/server/index.js +1029 -0
- package/dist/server/markdown-images.js +42 -0
- package/dist/server/model-admin.js +801 -0
- package/dist/server/model-config-merge.js +32 -0
- package/dist/server/native-mcp-config.js +103 -0
- package/dist/server/native-mcp-presentation.js +12 -0
- package/dist/server/native-prompt-template.js +12 -0
- package/dist/server/native-tools.js +32 -0
- package/dist/server/node-sources.js +142 -0
- package/dist/server/node-workbench.js +668 -0
- package/dist/server/origin-policy.js +50 -0
- package/dist/server/patch-node-pty.js +96 -0
- package/dist/server/pi-environment.js +203 -0
- package/dist/server/plan/extension.js +74 -0
- package/dist/server/plan/progress.js +90 -0
- package/dist/server/plan/settings.js +41 -0
- package/dist/server/plan/state.js +113 -0
- package/dist/server/plugin-facilities.js +304 -0
- package/dist/server/plugin-updater.js +245 -0
- package/dist/server/plugins.js +712 -0
- package/dist/server/private-file.js +28 -0
- package/dist/server/process-utils.js +112 -0
- package/dist/server/prompt-delivery.js +80 -0
- package/dist/server/protocol-version.js +11 -0
- package/dist/server/protocol.js +6 -0
- package/dist/server/provider-auth.js +99 -0
- package/dist/server/query-cache.js +45 -0
- package/dist/server/recovery-state.js +37 -0
- package/dist/server/scm.js +459 -0
- package/dist/server/security-headers.js +24 -0
- package/dist/server/serialize.js +254 -0
- package/dist/server/session-file-read.js +225 -0
- package/dist/server/session-record-worker.js +21 -0
- package/dist/server/session-reload.js +13 -0
- package/dist/server/session-tree-controller.js +250 -0
- package/dist/server/session-tree.js +191 -0
- package/dist/server/settings-service.js +53 -0
- package/dist/server/skills-service.js +87 -0
- package/dist/server/slash-commands.js +280 -0
- package/dist/server/sqlite-preview.js +58 -0
- package/dist/server/sqlite-query.js +67 -0
- package/dist/server/sqlite-worker.js +12 -0
- package/dist/server/system-prompt-files.js +158 -0
- package/dist/server/system-prompt-routes.js +40 -0
- package/dist/server/system-prompt-view.js +49 -0
- package/dist/server/task-progress.js +233 -0
- package/dist/server/terminals.js +833 -0
- package/dist/server/text-sniff.js +269 -0
- package/dist/server/thinking-timing.js +91 -0
- package/dist/server/token-auth.js +37 -0
- package/dist/server/tool-output.js +97 -0
- package/dist/server/tool-text-incidents.js +82 -0
- package/dist/server/tool-text.js +67 -0
- package/dist/server/uploads.js +112 -0
- package/dist/server/user-attachments.js +96 -0
- package/dist/server/webui-context.js +257 -0
- package/dist/server/wiki-links.js +136 -0
- package/dist/server/wiki-pdf-worker.js +23 -0
- package/dist/server/wiki-pdf.js +36 -0
- package/dist/server/wiki-routes.js +177 -0
- package/dist/server/wiki-service.js +511 -0
- package/electron/main.mjs +607 -0
- package/extensions/webui.ts +192 -0
- package/package.json +122 -4
- package/web/dist/apple-touch-icon.png +0 -0
- package/web/dist/assets/NodeWorkbench-C4U1PldE.js +3 -0
- package/web/dist/assets/TerminalPanel-CWh6vw_N.js +2 -0
- package/web/dist/assets/abnfDiagram-VCTEODGH-D5Ti0Kpa.js +1 -0
- package/web/dist/assets/arc-DKJilLd6.js +1 -0
- package/web/dist/assets/architectureDiagram-5GKGNRK7-Cf0w38g-.js +36 -0
- package/web/dist/assets/blockDiagram-I7D4REHJ-BOTLWLIL.js +129 -0
- package/web/dist/assets/c4Diagram-7LVT6UL2-CLCCoJs3.js +38 -0
- package/web/dist/assets/channel-D8Hd7T4P.js +1 -0
- package/web/dist/assets/chunk-2Q5K7J3B-BHjga2Ge.js +1 -0
- package/web/dist/assets/chunk-5VM5RSS4-CQJ5VfDZ.js +15 -0
- package/web/dist/assets/chunk-F27PBJKO-C67qoPJH.js +1 -0
- package/web/dist/assets/chunk-IMKFNOWR-CgXXGwI8.js +231 -0
- package/web/dist/assets/chunk-JWPE2WC7-D0RPyByP.js +1 -0
- package/web/dist/assets/chunk-POPQ4Y6H-BeYC9s9x.js +1 -0
- package/web/dist/assets/chunk-SVP7TREG-eQPl4UBQ.js +88 -0
- package/web/dist/assets/chunk-TICWLB2K-DT73arPU.js +206 -0
- package/web/dist/assets/chunk-XXDRQBXY-B4FwQcP-.js +1 -0
- package/web/dist/assets/classDiagram-ZZMXUADV-B_btgYRB.js +1 -0
- package/web/dist/assets/classDiagram-v2-VYDZK3BY-B_btgYRB.js +1 -0
- package/web/dist/assets/cose-bilkent-JH36ORCC-Bnn5nlQN.js +1 -0
- package/web/dist/assets/cynefin-OW5HDTMX-CStWX9kE.js +178 -0
- package/web/dist/assets/cynefinDiagram-5FMLGOSQ-BMVHC03f.js +62 -0
- package/web/dist/assets/cytoscape.esm-Bch-eiPH.js +331 -0
- package/web/dist/assets/dagre-GXQ25YYZ-ClSaO4ml.js +4 -0
- package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/web/dist/assets/diagram-S7CK7UJ4-C43LL08C.js +30 -0
- package/web/dist/assets/diagram-UQ7AKVKN-BPVn_ySW.js +41 -0
- package/web/dist/assets/diagram-VSXAHHWV-C34FFhRi.js +3 -0
- package/web/dist/assets/diagram-VX7I27RA-BRk4bncf.js +24 -0
- package/web/dist/assets/diagram-Z3DM3KII-O5hYPLEd.js +24 -0
- package/web/dist/assets/ebnfDiagram-PWID7BFC-DVGEBm99.js +1 -0
- package/web/dist/assets/erDiagram-RLTQ6QDP-M-BLpTEV.js +99 -0
- package/web/dist/assets/flowDiagram-HODETNUW-BwdLopEx.js +168 -0
- package/web/dist/assets/ganttDiagram-EL5Y4UJY-DYxx2ppA.js +292 -0
- package/web/dist/assets/gitGraphDiagram-WWUBYQGX-DUU0wMYB.js +106 -0
- package/web/dist/assets/index-CI2KfVSr.css +10 -0
- package/web/dist/assets/index-DQcpggFU.js +275 -0
- package/web/dist/assets/infoDiagram-27XIBGKW-CFaW5C0C.js +2 -0
- package/web/dist/assets/init-Gi6I4Gst.js +1 -0
- package/web/dist/assets/ishikawaDiagram-5VMMS53U--ENP1MTB.js +70 -0
- package/web/dist/assets/journeyDiagram-3NMN7TZE-DgnAzSTj.js +139 -0
- package/web/dist/assets/kanban-definition-UXKFOSKX-_STZN1vU.js +89 -0
- package/web/dist/assets/katex-C5jXJg4s.js +257 -0
- package/web/dist/assets/layout-CkUClkXt.js +1 -0
- package/web/dist/assets/linear-sYHiUOxa.js +1 -0
- package/web/dist/assets/markdown-vNTCZJ6d.js +51 -0
- package/web/dist/assets/mermaid.core-B8fKGWsc.js +312 -0
- package/web/dist/assets/mindmap-definition-YA3MSWOX-DP0BYOEx.js +96 -0
- package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/web/dist/assets/pegDiagram-XKGWAZYB-DkWTmZre.js +1 -0
- package/web/dist/assets/pieDiagram-E7YTZNPT-DfZgMV4u.js +39 -0
- package/web/dist/assets/quadrantDiagram-AXDQQJYC-Djl4TT7q.js +7 -0
- package/web/dist/assets/railroadDiagram-O6MQD6OU-DbKF6zXn.js +1 -0
- package/web/dist/assets/react-BNj3n7jX.js +24 -0
- package/web/dist/assets/requirementDiagram-BXWQKSXE-idola5qb.js +84 -0
- package/web/dist/assets/sankeyDiagram-P5KCCOFB-KA0hQOle.js +40 -0
- package/web/dist/assets/sequenceDiagram-WJ2MYXX4-BXSKvxzP.js +162 -0
- package/web/dist/assets/sizeCapture-INFHLROL-C_Ewv3S5.js +1 -0
- package/web/dist/assets/stateDiagram-D77RDMKH-DIf5X8oo.js +1 -0
- package/web/dist/assets/stateDiagram-v2-MP3YSRHH-DYwe_2mB.js +1 -0
- package/web/dist/assets/swimlanes-42K2YHIH-Cx_Rc8M2.js +1 -0
- package/web/dist/assets/swimlanesDiagram-VR7AAH4N-52Y8tgRV.js +8 -0
- package/web/dist/assets/timeline-definition-24CTP7MA-BRrDhWVz.js +120 -0
- package/web/dist/assets/vennDiagram-4TSXK5OY-Ad6G0YwD.js +34 -0
- package/web/dist/assets/wardleyDiagram-VM6X3IG4-X6-ENpSi.js +78 -0
- package/web/dist/assets/xterm-6GBZ9nXN.css +32 -0
- package/web/dist/assets/xterm-D1D2FVe3.js +38 -0
- package/web/dist/assets/xychartDiagram-S5SC5T6Z-DhegNS6d.js +7 -0
- package/web/dist/brand-mark.svg +5 -0
- package/web/dist/favicon-32.png +0 -0
- package/web/dist/favicon.svg +5 -0
- package/web/dist/fonts/WIKI-FONTS.md +5 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-600-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-400-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-500-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-600-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-sans/LICENSE +93 -0
- package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-400-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-500-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-600-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-400-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-500-normal.woff2 +0 -0
- package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-600-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-400-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-500-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-600-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-700-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-800-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-ext-500-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
- package/web/dist/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
- package/web/dist/fonts/jetbrains-mono/LICENSE +93 -0
- package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
- package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-500-normal.woff2 +0 -0
- package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-600-normal.woff2 +0 -0
- package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
- package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-ext-500-normal.woff2 +0 -0
- package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-ext-600-normal.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/LICENSE +94 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-0.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-1.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-10.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-100.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-11.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-12.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-13.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-14.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-15.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-16.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-17.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-18.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-19.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-2.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-20.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-21.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-22.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-23.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-24.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-25.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-26.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-27.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-28.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-29.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-3.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-30.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-31.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-32.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-33.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-34.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-35.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-36.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-37.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-38.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-39.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-4.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-40.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-41.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-42.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-43.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-44.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-45.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-46.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-47.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-48.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-49.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-5.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-50.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-51.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-52.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-53.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-54.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-55.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-56.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-57.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-58.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-59.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-6.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-60.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-61.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-62.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-63.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-64.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-65.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-66.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-67.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-68.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-69.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-7.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-70.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-71.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-72.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-73.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-74.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-75.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-76.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-77.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-78.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-79.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-8.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-80.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-81.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-82.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-83.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-84.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-85.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-86.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-87.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-88.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-89.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-9.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-90.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-91.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-92.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-93.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-94.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-95.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-96.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-97.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-98.woff2 +0 -0
- package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-99.woff2 +0 -0
- package/web/dist/fonts/source-serif-4/LICENSE +93 -0
- package/web/dist/fonts/source-serif-4/source-serif-4-500-0.woff2 +0 -0
- package/web/dist/fonts/source-serif-4/source-serif-4-500-1.woff2 +0 -0
- package/web/dist/fonts/source-serif-4/source-serif-4-500-2.woff2 +0 -0
- package/web/dist/fonts/source-serif-4/source-serif-4-500-3.woff2 +0 -0
- package/web/dist/fonts/source-serif-4/source-serif-4-500-4.woff2 +0 -0
- package/web/dist/fonts/source-serif-4/source-serif-4-500-5.woff2 +0 -0
- package/web/dist/icon/1a-mark.svg +1 -0
- package/web/dist/icon.ico +0 -0
- package/web/dist/index.html +18 -0
- package/web/public/apple-touch-icon.png +0 -0
- package/web/public/brand-mark.svg +5 -0
- package/web/public/favicon-32.png +0 -0
- package/web/public/favicon.svg +5 -0
- package/web/public/fonts/WIKI-FONTS.md +5 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-600-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-400-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-500-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-600-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-sans/LICENSE +93 -0
- package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-400-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-500-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-600-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-400-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-500-normal.woff2 +0 -0
- package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-600-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-400-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-500-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-600-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-700-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-800-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-ext-500-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
- package/web/public/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
- package/web/public/fonts/jetbrains-mono/LICENSE +93 -0
- package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
- package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-500-normal.woff2 +0 -0
- package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-600-normal.woff2 +0 -0
- package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
- package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-ext-500-normal.woff2 +0 -0
- package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-ext-600-normal.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/LICENSE +94 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-0.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-1.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-10.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-100.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-11.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-12.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-13.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-14.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-15.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-16.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-17.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-18.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-19.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-2.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-20.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-21.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-22.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-23.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-24.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-25.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-26.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-27.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-28.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-29.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-3.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-30.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-31.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-32.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-33.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-34.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-35.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-36.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-37.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-38.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-39.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-4.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-40.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-41.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-42.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-43.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-44.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-45.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-46.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-47.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-48.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-49.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-5.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-50.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-51.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-52.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-53.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-54.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-55.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-56.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-57.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-58.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-59.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-6.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-60.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-61.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-62.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-63.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-64.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-65.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-66.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-67.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-68.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-69.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-7.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-70.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-71.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-72.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-73.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-74.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-75.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-76.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-77.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-78.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-79.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-8.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-80.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-81.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-82.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-83.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-84.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-85.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-86.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-87.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-88.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-89.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-9.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-90.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-91.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-92.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-93.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-94.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-95.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-96.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-97.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-98.woff2 +0 -0
- package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-99.woff2 +0 -0
- package/web/public/fonts/source-serif-4/LICENSE +93 -0
- package/web/public/fonts/source-serif-4/source-serif-4-500-0.woff2 +0 -0
- package/web/public/fonts/source-serif-4/source-serif-4-500-1.woff2 +0 -0
- package/web/public/fonts/source-serif-4/source-serif-4-500-2.woff2 +0 -0
- package/web/public/fonts/source-serif-4/source-serif-4-500-3.woff2 +0 -0
- package/web/public/fonts/source-serif-4/source-serif-4-500-4.woff2 +0 -0
- package/web/public/fonts/source-serif-4/source-serif-4-500-5.woff2 +0 -0
- package/web/public/icon/1a-mark.svg +1 -0
- package/web/public/icon.ico +0 -0
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { parseUserAttachments } from "./user-attachments.js";
|
|
2
|
+
import { recallPending } from "./prompt-delivery.js";
|
|
3
|
+
import { SessionTailValidator } from "./session-file-read.js";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { existsSync, watch } from "node:fs";
|
|
6
|
+
import { basename, dirname } from "node:path";
|
|
7
|
+
import { collectEntriesForBranchSummary } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import { projectTree, treeEntryContent, treeRevision, toUiTree } from "./session-tree.js";
|
|
9
|
+
/** Owns operation admission, native-file invalidation and derived message metadata.
|
|
10
|
+
* The native SessionManager remains the sole owner of entries and the leaf. */
|
|
11
|
+
export class SessionTreeController {
|
|
12
|
+
host;
|
|
13
|
+
watcher;
|
|
14
|
+
watchPath;
|
|
15
|
+
validator;
|
|
16
|
+
external = false;
|
|
17
|
+
operation = false;
|
|
18
|
+
disposed = false;
|
|
19
|
+
revision = "";
|
|
20
|
+
counts = { branchPoints: 0, rootCount: 0 };
|
|
21
|
+
metadata = new Map();
|
|
22
|
+
decorated = new WeakMap();
|
|
23
|
+
constructor(host) {
|
|
24
|
+
this.host = host;
|
|
25
|
+
}
|
|
26
|
+
get busy() { return this.operation; }
|
|
27
|
+
get externallyModified() { this.checkExternal(); return this.external; }
|
|
28
|
+
get session() { return this.host.runtime().session; }
|
|
29
|
+
bindFile() {
|
|
30
|
+
const path = this.session.sessionFile;
|
|
31
|
+
if (path === this.watchPath)
|
|
32
|
+
return;
|
|
33
|
+
this.watcher?.close();
|
|
34
|
+
this.watcher = undefined;
|
|
35
|
+
this.validator?.dispose();
|
|
36
|
+
this.watchPath = path;
|
|
37
|
+
this.external = false;
|
|
38
|
+
this.revision = "";
|
|
39
|
+
this.validator = path ? new SessionTailValidator(path, this.session.sessionManager, () => { this.checkExternal(); this.host.changed(); }) : undefined;
|
|
40
|
+
if (path && existsSync(dirname(path))) {
|
|
41
|
+
this.watcher = watch(dirname(path), { persistent: false }, (_event, file) => {
|
|
42
|
+
if (!file || file.toString() === basename(path))
|
|
43
|
+
this.checkExternal();
|
|
44
|
+
});
|
|
45
|
+
this.watcher.on("error", () => { this.external = true; this.host.changed(); });
|
|
46
|
+
}
|
|
47
|
+
this.checkExternal();
|
|
48
|
+
}
|
|
49
|
+
checkExternal() {
|
|
50
|
+
if (!this.watchPath || this.external)
|
|
51
|
+
return;
|
|
52
|
+
const wasBlocking = this.validator?.blocking;
|
|
53
|
+
const valid = this.validator?.check(this.session.sessionManager);
|
|
54
|
+
if (valid === undefined) {
|
|
55
|
+
if (!wasBlocking && this.validator?.blocking)
|
|
56
|
+
this.host.changed();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (valid)
|
|
60
|
+
return;
|
|
61
|
+
this.external = true;
|
|
62
|
+
if (!this.session.isIdle)
|
|
63
|
+
void this.session.abort().catch(() => { });
|
|
64
|
+
this.host.changed();
|
|
65
|
+
}
|
|
66
|
+
async waitForVerification() {
|
|
67
|
+
const validator = this.validator, session = this.session;
|
|
68
|
+
await validator?.verify(session.sessionManager);
|
|
69
|
+
if (this.disposed || !this.host.active() || this.validator !== validator || this.session !== session)
|
|
70
|
+
throw new Error("对话已切换,请重新操作。");
|
|
71
|
+
this.assertWritable();
|
|
72
|
+
}
|
|
73
|
+
assertWritable() {
|
|
74
|
+
this.checkExternal();
|
|
75
|
+
if (this.external)
|
|
76
|
+
throw new Error("会话文件已被外部修改,请重新打开后继续。");
|
|
77
|
+
if (this.validator?.blocking)
|
|
78
|
+
throw new Error("正在校验会话文件,请稍后重试。");
|
|
79
|
+
if (this.operation)
|
|
80
|
+
throw new Error("等待当前压缩或切换完成。");
|
|
81
|
+
}
|
|
82
|
+
refresh() {
|
|
83
|
+
this.bindFile();
|
|
84
|
+
this.checkExternal();
|
|
85
|
+
const sm = this.session.sessionManager;
|
|
86
|
+
const revision = treeRevision(sm);
|
|
87
|
+
if (revision !== this.revision) {
|
|
88
|
+
const tree = projectTree(sm);
|
|
89
|
+
this.counts = { branchPoints: tree.branchPoints, rootCount: tree.rootCount };
|
|
90
|
+
this.metadata.clear();
|
|
91
|
+
for (const entry of sm.getEntries())
|
|
92
|
+
this.metadata.set(entry.id, { entryId: entry.id, label: sm.getLabel(entry.id), siblings: tree.siblings(entry.id) });
|
|
93
|
+
this.revision = revision;
|
|
94
|
+
this.host.emit({ type: "tree_changed", conversationId: this.host.conversationId, revision, branchPoints: tree.branchPoints });
|
|
95
|
+
}
|
|
96
|
+
return { revision, leafId: sm.getLeafId(), ...this.counts, filterMode: this.session.settingsManager.getTreeFilterMode(), skipSummaryPrompt: this.session.settingsManager.getBranchSummarySkipPrompt(), externallyModified: this.external, verifying: this.validator?.blocking ?? false, busy: this.operation || this.session.isCompacting };
|
|
97
|
+
}
|
|
98
|
+
decorate(message, entryId) {
|
|
99
|
+
if (!entryId)
|
|
100
|
+
return message;
|
|
101
|
+
const metadata = this.metadata.get(entryId) ?? { entryId };
|
|
102
|
+
const key = JSON.stringify(metadata);
|
|
103
|
+
const cached = this.decorated.get(message);
|
|
104
|
+
if (cached?.key === key)
|
|
105
|
+
return cached.value;
|
|
106
|
+
const value = { ...message, ...metadata };
|
|
107
|
+
const entry = this.session.sessionManager.getEntry(entryId);
|
|
108
|
+
if (entry?.type === "message" && (entry.message.role === "user" || (entry.message.role === "custom" && entry.message.customType === "file"))) {
|
|
109
|
+
const content = entry.message.content;
|
|
110
|
+
const parsed = parseUserAttachments(typeof content === "string" ? content : content.filter(b => b.type === "text").map(b => b.text).join("\n"));
|
|
111
|
+
if (parsed.attachments.length) {
|
|
112
|
+
value.questionText = parsed.text;
|
|
113
|
+
value.userAttachments = parsed.attachments.map((a, index) => ({ path: a.path, mode: a.mode, preview: a.preview.slice(0, 12000), nativeRef: { entryId, index } }));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
this.decorated.set(message, { key, value });
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
async request(request, onResult) {
|
|
120
|
+
const context = { conversationId: this.host.conversationId, reqId: request.reqId };
|
|
121
|
+
let restoredQueue;
|
|
122
|
+
let ownsOperation = false;
|
|
123
|
+
const reply = (status, extra = {}) => { onResult?.(status); this.host.emit({ type: "tree_navigate_result", ...context, status, restoredQueue, ...extra }); };
|
|
124
|
+
const session = this.session;
|
|
125
|
+
const sm = session.sessionManager;
|
|
126
|
+
try {
|
|
127
|
+
if (request.conversationId !== this.host.conversationId || !this.host.active())
|
|
128
|
+
throw new Error("只能操作当前活动对话。");
|
|
129
|
+
const validate = () => {
|
|
130
|
+
if (!this.host.active() || this.session !== session)
|
|
131
|
+
throw new Error("对话已切换,请重新操作。");
|
|
132
|
+
this.checkExternal();
|
|
133
|
+
if (this.external)
|
|
134
|
+
throw new Error("会话文件已被外部修改,请重新打开后继续。");
|
|
135
|
+
if (this.validator?.blocking)
|
|
136
|
+
throw new Error("正在校验会话文件,请稍后重试。");
|
|
137
|
+
};
|
|
138
|
+
if (request.type === "tree_get") {
|
|
139
|
+
const filter = request.filter ?? session.settingsManager.getTreeFilterMode();
|
|
140
|
+
if (!["default", "no-tools", "user-only", "labeled-only", "all"].includes(filter))
|
|
141
|
+
throw new Error("Invalid tree filter");
|
|
142
|
+
const state = this.refresh();
|
|
143
|
+
this.host.emit({ type: "tree", ...context, revision: state.revision, leafId: state.leafId, ...toUiTree(sm, filter, (request.query ?? "").slice(0, 1000)) });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (request.type === "tree_content") {
|
|
147
|
+
const entry = sm.getEntry(request.entryId);
|
|
148
|
+
if (!entry)
|
|
149
|
+
throw new Error("Entry not found");
|
|
150
|
+
this.host.emit({ type: "tree_content_result", ...context, entryId: entry.id, content: treeEntryContent(entry), toolCallId: entry.type === "message" && entry.message.role === "toolResult" ? entry.message.toolCallId : undefined });
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (request.type === "tree_preview") {
|
|
154
|
+
if (!sm.getEntry(request.targetId))
|
|
155
|
+
throw new Error("Entry not found");
|
|
156
|
+
try {
|
|
157
|
+
const result = collectEntriesForBranchSummary(sm, sm.getLeafId(), request.targetId);
|
|
158
|
+
this.host.emit({ type: "tree_preview_result", ...context, entryCount: result.entries.length, commonAncestorId: result.commonAncestorId });
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
this.host.emit({ type: "tree_preview_result", ...context });
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (!this.host.admitted())
|
|
166
|
+
throw new Error("服务正在排空,请稍后重试。");
|
|
167
|
+
if (request.type === "tree_label") {
|
|
168
|
+
validate();
|
|
169
|
+
if (!sm.getEntry(request.entryId))
|
|
170
|
+
throw new Error("Entry not found");
|
|
171
|
+
if (request.label !== null && (typeof request.label !== "string" || request.label.length > 200))
|
|
172
|
+
throw new Error("Label must be at most 200 characters");
|
|
173
|
+
sm.appendLabelChange(request.entryId, request.label?.trim() || undefined);
|
|
174
|
+
reply("ok");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (this.operation || session.isCompacting) {
|
|
178
|
+
reply("busy");
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (!session.isIdle && !(request.type === "tree_navigate" && request.abortRunning)) {
|
|
182
|
+
reply("busy");
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (request.type !== "session_reopen")
|
|
186
|
+
validate();
|
|
187
|
+
this.operation = true;
|
|
188
|
+
ownsOperation = true;
|
|
189
|
+
this.host.changed();
|
|
190
|
+
if (request.type === "session_reopen") {
|
|
191
|
+
if (!session.sessionFile)
|
|
192
|
+
throw new Error("Session file is not available");
|
|
193
|
+
const result = await this.host.runtime().switchSession(session.sessionFile);
|
|
194
|
+
if (!result.cancelled) {
|
|
195
|
+
this.watcher?.close();
|
|
196
|
+
this.watchPath = undefined;
|
|
197
|
+
this.external = false;
|
|
198
|
+
await this.host.replaced();
|
|
199
|
+
this.bindFile();
|
|
200
|
+
}
|
|
201
|
+
reply(result.cancelled ? "cancelled" : "ok");
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (request.type === "tree_navigate") {
|
|
205
|
+
if (!sm.getEntry(request.targetId))
|
|
206
|
+
throw new Error("Entry not found");
|
|
207
|
+
if (!["none", "default", "custom"].includes(request.summary))
|
|
208
|
+
throw new Error("Invalid summary mode");
|
|
209
|
+
if (!session.isIdle) {
|
|
210
|
+
restoredQueue = recallPending(session);
|
|
211
|
+
await session.abort(); // SDK abort waits for idle / agent_settled, not agent_end.
|
|
212
|
+
await this.validator?.verify(sm); // Validate the final records written by our own abort.
|
|
213
|
+
validate();
|
|
214
|
+
if (!session.isIdle) {
|
|
215
|
+
reply("busy");
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
validate();
|
|
220
|
+
if (request.summary !== "none")
|
|
221
|
+
this.host.summary({ id: randomUUID() });
|
|
222
|
+
const result = await session.navigateTree(request.targetId, { summarize: request.summary !== "none", customInstructions: request.summary === "custom" ? request.customInstructions?.slice(0, 16000) : undefined, replaceInstructions: request.replaceInstructions, label: request.label?.slice(0, 200) });
|
|
223
|
+
reply(result.aborted ? "aborted" : result.cancelled ? "cancelled" : "ok", { editorText: result.editorText });
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const entryId = request.type === "session_clone" ? sm.getLeafId() : request.entryId;
|
|
227
|
+
if (!entryId || !sm.getEntry(entryId))
|
|
228
|
+
throw new Error("会话没有可派生的节点。");
|
|
229
|
+
const position = request.type === "session_clone" ? "at" : request.position;
|
|
230
|
+
if (position !== "at" && position !== "before")
|
|
231
|
+
throw new Error("Invalid fork position");
|
|
232
|
+
const result = await this.host.runtime().fork(entryId, { position });
|
|
233
|
+
if (!result.cancelled)
|
|
234
|
+
await this.host.replaced();
|
|
235
|
+
reply(result.cancelled ? "cancelled" : "ok", { editorText: result.selectedText });
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
reply("error", { error: error instanceof Error ? error.message : String(error) });
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
if (ownsOperation) {
|
|
242
|
+
this.operation = false;
|
|
243
|
+
this.host.summary(undefined);
|
|
244
|
+
}
|
|
245
|
+
this.refresh();
|
|
246
|
+
this.host.changed();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
dispose() { this.disposed = true; this.validator?.dispose(); this.watcher?.close(); this.watcher = undefined; }
|
|
250
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from "node:util";
|
|
2
|
+
const settingsTypes = new Set(["label", "context_edit", "custom", "model_change", "thinking_level_change", "session_info"]);
|
|
3
|
+
function text(content) {
|
|
4
|
+
if (typeof content === "string")
|
|
5
|
+
return content;
|
|
6
|
+
if (!Array.isArray(content))
|
|
7
|
+
return "";
|
|
8
|
+
return content.map(block => block && block.type === "text" && typeof block.text === "string" ? block.text : "").join("");
|
|
9
|
+
}
|
|
10
|
+
/** Matches the pinned CLI's filtering, including exclusions preceding its mode switch. */
|
|
11
|
+
export function treeNodeVisible(node, leafId, filter) {
|
|
12
|
+
const e = node.entry;
|
|
13
|
+
if (e.type === "usage")
|
|
14
|
+
return false;
|
|
15
|
+
if (e.type === "message" && e.message.role === "assistant" && e.id !== leafId) {
|
|
16
|
+
const m = e.message;
|
|
17
|
+
if (!text(m.content).trim() && (!m.stopReason || m.stopReason === "stop" || m.stopReason === "toolUse"))
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
switch (filter) {
|
|
21
|
+
case "user-only": return e.type === "message" && e.message.role === "user";
|
|
22
|
+
case "labeled-only": return node.label !== undefined;
|
|
23
|
+
case "no-tools": return !settingsTypes.has(e.type) && !(e.type === "message" && e.message.role === "toolResult");
|
|
24
|
+
case "all": return true;
|
|
25
|
+
default: return !settingsTypes.has(e.type);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Search intentionally follows CLI: only the first 200 content characters of messages. */
|
|
29
|
+
export function treeSearchText(node) {
|
|
30
|
+
const e = node.entry;
|
|
31
|
+
let body;
|
|
32
|
+
switch (e.type) {
|
|
33
|
+
case "message":
|
|
34
|
+
body = `${e.message.role} ${"content" in e.message ? text(e.message.content).slice(0, 200) : ""} ${e.message.role === "bashExecution" ? e.message.command : ""}`;
|
|
35
|
+
break;
|
|
36
|
+
case "custom_message":
|
|
37
|
+
body = `${e.customType} ${text(e.content).slice(0, 200)}`;
|
|
38
|
+
break;
|
|
39
|
+
case "branch_summary":
|
|
40
|
+
body = `branch summary ${e.summary}`;
|
|
41
|
+
break;
|
|
42
|
+
case "compaction":
|
|
43
|
+
body = "compaction";
|
|
44
|
+
break;
|
|
45
|
+
case "model_change":
|
|
46
|
+
body = `model ${e.modelId}`;
|
|
47
|
+
break;
|
|
48
|
+
case "thinking_level_change":
|
|
49
|
+
body = `thinking ${e.thinkingLevel}`;
|
|
50
|
+
break;
|
|
51
|
+
case "session_info":
|
|
52
|
+
body = `title ${e.name ?? ""}`;
|
|
53
|
+
break;
|
|
54
|
+
case "custom":
|
|
55
|
+
body = `custom ${e.customType}`;
|
|
56
|
+
break;
|
|
57
|
+
case "context_edit":
|
|
58
|
+
body = `context edit ${e.replacement === null ? "omit" : "replace"} ${e.targetId}`;
|
|
59
|
+
break;
|
|
60
|
+
case "label":
|
|
61
|
+
body = `label ${e.label ?? ""}`;
|
|
62
|
+
break;
|
|
63
|
+
default: body = "";
|
|
64
|
+
}
|
|
65
|
+
return `${node.label ?? ""} ${body}`.toLowerCase();
|
|
66
|
+
}
|
|
67
|
+
export function treeEntryContent(e) {
|
|
68
|
+
switch (e.type) {
|
|
69
|
+
case "message": return e.message.role === "bashExecution" ? e.message.command : "content" in e.message ? text(e.message.content) || (e.message.role === "assistant" ? e.message.errorMessage ?? "" : "") : "";
|
|
70
|
+
case "custom_message": return text(e.content);
|
|
71
|
+
case "compaction":
|
|
72
|
+
case "branch_summary": return e.summary;
|
|
73
|
+
case "model_change": return `${e.provider}/${e.modelId}`;
|
|
74
|
+
case "thinking_level_change": return e.thinkingLevel;
|
|
75
|
+
case "session_info": return e.name ?? "";
|
|
76
|
+
case "label": return e.label ?? "";
|
|
77
|
+
case "custom": return e.customType;
|
|
78
|
+
case "context_edit": return `${e.targetId}: ${e.replacement ? text(e.replacement.content) : "omit"}`;
|
|
79
|
+
case "usage": return e.kind;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function kind(e) {
|
|
83
|
+
if (e.type === "message")
|
|
84
|
+
return e.message.role === "user" ? "user" : e.message.role === "assistant" ? "assistant" : e.message.role === "toolResult" ? "tool" : "custom";
|
|
85
|
+
switch (e.type) {
|
|
86
|
+
case "compaction": return "compaction";
|
|
87
|
+
case "branch_summary": return "branchSummary";
|
|
88
|
+
case "context_edit": return "contextEdit";
|
|
89
|
+
case "model_change": return "model";
|
|
90
|
+
case "thinking_level_change": return "thinking";
|
|
91
|
+
case "label": return "label";
|
|
92
|
+
case "session_info":
|
|
93
|
+
case "usage": return "info";
|
|
94
|
+
default: return "custom";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** No persisted tree cache: derive a bounded view and linear-time navigation index. */
|
|
98
|
+
export function projectTree(sm) {
|
|
99
|
+
const roots = sm.getTree();
|
|
100
|
+
const leafId = sm.getLeafId();
|
|
101
|
+
const flat = [];
|
|
102
|
+
const byId = new Map();
|
|
103
|
+
const stack = [...roots].reverse();
|
|
104
|
+
while (stack.length) {
|
|
105
|
+
const node = stack.pop();
|
|
106
|
+
if (byId.has(node.entry.id))
|
|
107
|
+
continue;
|
|
108
|
+
flat.push(node);
|
|
109
|
+
byId.set(node.entry.id, node);
|
|
110
|
+
for (let i = node.children.length - 1; i >= 0; i--)
|
|
111
|
+
stack.push(node.children[i]);
|
|
112
|
+
}
|
|
113
|
+
const active = new Set();
|
|
114
|
+
for (let id = leafId; id && !active.has(id); id = byId.get(id)?.entry.parentId ?? null)
|
|
115
|
+
active.add(id);
|
|
116
|
+
const orderedFlat = [];
|
|
117
|
+
const order = (nodes) => [...nodes].sort((a, b) => Number(active.has(b.entry.id)) - Number(active.has(a.entry.id)));
|
|
118
|
+
const orderedStack = order(roots).reverse();
|
|
119
|
+
while (orderedStack.length) {
|
|
120
|
+
const node = orderedStack.pop();
|
|
121
|
+
orderedFlat.push(node);
|
|
122
|
+
const children = order(node.children);
|
|
123
|
+
for (let i = children.length - 1; i >= 0; i--)
|
|
124
|
+
orderedStack.push(children[i]);
|
|
125
|
+
}
|
|
126
|
+
const latest = new Map();
|
|
127
|
+
for (let i = flat.length - 1; i >= 0; i--) {
|
|
128
|
+
const node = flat[i];
|
|
129
|
+
let best = node;
|
|
130
|
+
for (const child of node.children) {
|
|
131
|
+
const candidate = latest.get(child.entry.id) ?? child;
|
|
132
|
+
if (best === node || candidate.entry.timestamp >= best.entry.timestamp)
|
|
133
|
+
best = candidate;
|
|
134
|
+
}
|
|
135
|
+
latest.set(node.entry.id, best);
|
|
136
|
+
}
|
|
137
|
+
const branchPoints = flat.filter(n => n.children.length > 1).length;
|
|
138
|
+
const siblingMap = new Map();
|
|
139
|
+
for (const group of [roots, ...flat.map(n => n.children)]) {
|
|
140
|
+
const peers = group.filter(n => treeNodeVisible(n, leafId, "default"));
|
|
141
|
+
if (peers.length < 2)
|
|
142
|
+
continue;
|
|
143
|
+
peers.forEach((node, i) => siblingMap.set(node.entry.id, { index: i + 1, count: peers.length, prevTarget: i > 0 ? latest.get(peers[i - 1].entry.id)?.entry.id : undefined, nextTarget: i + 1 < peers.length ? latest.get(peers[i + 1].entry.id)?.entry.id : undefined }));
|
|
144
|
+
}
|
|
145
|
+
const siblings = (entryId) => siblingMap.get(entryId);
|
|
146
|
+
function view(filter = "default", query = "", limit = 5000) {
|
|
147
|
+
const tokens = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
148
|
+
const visible = new Map();
|
|
149
|
+
const nodes = [];
|
|
150
|
+
let truncated = false;
|
|
151
|
+
for (const node of orderedFlat) {
|
|
152
|
+
const e = node.entry;
|
|
153
|
+
const parent = e.parentId ? visible.get(e.parentId) : undefined;
|
|
154
|
+
const rootId = parent?.root ?? e.id;
|
|
155
|
+
if (!treeNodeVisible(node, leafId, filter) || !tokens.every(token => treeSearchText(node).includes(token))) {
|
|
156
|
+
visible.set(e.id, { id: parent?.id ?? null, depth: parent?.depth ?? -1, root: rootId });
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const depth = (parent?.depth ?? -1) + 1;
|
|
160
|
+
visible.set(e.id, { id: e.id, depth, root: rootId });
|
|
161
|
+
if (nodes.length >= limit) {
|
|
162
|
+
truncated = true;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const m = e.type === "message" ? e.message : undefined;
|
|
166
|
+
nodes.push({ id: e.id, parentId: e.parentId, visibleParentId: parent?.id ?? null, depth, rootId, kind: kind(e), preview: stripVTControlCharacters(treeEntryContent(e)).replace(/\s+/g, " ").slice(0, 120), timestamp: Date.parse(e.timestamp), label: node.label, onActivePath: active.has(e.id), isLeaf: e.id === leafId, childCount: node.children.length, toolName: m?.role === "toolResult" ? m.toolName : undefined, model: m?.role === "assistant" ? m.model : e.type === "model_change" ? e.modelId : undefined, stopReason: m?.role === "assistant" && (m.stopReason === "error" || m.stopReason === "aborted") ? m.stopReason : undefined, summaryFromId: e.type === "branch_summary" ? e.fromId : undefined });
|
|
167
|
+
}
|
|
168
|
+
const childCounts = new Map();
|
|
169
|
+
for (const n of nodes)
|
|
170
|
+
childCounts.set(n.visibleParentId, (childCounts.get(n.visibleParentId) ?? 0) + 1);
|
|
171
|
+
const layout = new Map();
|
|
172
|
+
const multipleRoots = (childCounts.get(null) ?? 0) > 1;
|
|
173
|
+
for (const n of nodes) {
|
|
174
|
+
const parent = n.visibleParentId ? layout.get(n.visibleParentId) : undefined;
|
|
175
|
+
const justBranched = (childCounts.get(n.visibleParentId) ?? 0) > 1;
|
|
176
|
+
const indent = parent
|
|
177
|
+
? parent.indent + (justBranched || (parent.justBranched && parent.indent > 0) ? 1 : 0)
|
|
178
|
+
: multipleRoots ? 1 : 0;
|
|
179
|
+
layout.set(n.id, { indent, justBranched });
|
|
180
|
+
n.depth = multipleRoots ? Math.max(0, indent - 1) : indent;
|
|
181
|
+
}
|
|
182
|
+
return { nodes, truncated };
|
|
183
|
+
}
|
|
184
|
+
return { branchPoints, rootCount: roots.length, leafId, siblings, view };
|
|
185
|
+
}
|
|
186
|
+
export function treeRevision(sm) {
|
|
187
|
+
// Every label change appends an entry, including clears and replacements.
|
|
188
|
+
return `${sm.getSessionId()}:${sm.getEntryCount()}:${sm.getLeafId() ?? "root"}`;
|
|
189
|
+
}
|
|
190
|
+
export function toUiTree(sm, filter = "default", query = "") { return projectTree(sm).view(filter, query); }
|
|
191
|
+
export function siblingInfo(sm, entryId) { return projectTree(sm).siblings(entryId); }
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { extensionKey } from "./client-state.js";
|
|
2
|
+
import { extensionDisplay } from "./extension-display.js";
|
|
3
|
+
export class SettingsService {
|
|
4
|
+
host;
|
|
5
|
+
settings;
|
|
6
|
+
pendingReload = false;
|
|
7
|
+
constructor(host) {
|
|
8
|
+
this.host = host;
|
|
9
|
+
this.settings = host.stateStore.getSettings(host.clientId);
|
|
10
|
+
}
|
|
11
|
+
get current() { return this.settings; }
|
|
12
|
+
hasPendingReload() { return this.pendingReload; }
|
|
13
|
+
consumePendingReload() { const pending = this.pendingReload; this.pendingReload = false; return pending; }
|
|
14
|
+
push() {
|
|
15
|
+
let skills = [];
|
|
16
|
+
let extensions = [];
|
|
17
|
+
try {
|
|
18
|
+
const loader = this.host.getSession().resourceLoader;
|
|
19
|
+
skills = loader.getSkills().skills.map(skill => ({ name: skill.name, description: skill.description, enabled: true }));
|
|
20
|
+
extensions = loader.getExtensions().extensions.filter(extension => !extension.hidden).map(extension => {
|
|
21
|
+
const path = extension.sourceInfo?.path ?? extension.path;
|
|
22
|
+
return { id: extensionKey(extension), ...extensionDisplay(path, extension.sourceInfo?.origin === "package" ? extension.sourceInfo.source : undefined), path, enabled: true };
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch { /* The first session may still be attaching. */ }
|
|
26
|
+
this.host.emit({ type: "settings_state", settings: {
|
|
27
|
+
editResendNewSession: this.settings.editResendNewSession ?? false,
|
|
28
|
+
thinkingWrap: this.settings.thinkingWrap,
|
|
29
|
+
toolsWrap: this.settings.toolsWrap,
|
|
30
|
+
disabledPlugins: this.settings.disabledPlugins ?? [],
|
|
31
|
+
effectiveSystemPrompt: this.host.effectiveSystemPrompt(),
|
|
32
|
+
skills,
|
|
33
|
+
extensions,
|
|
34
|
+
} });
|
|
35
|
+
}
|
|
36
|
+
async set(partial) {
|
|
37
|
+
this.host.stateStore.saveSettings(this.host.clientId, partial);
|
|
38
|
+
this.settings = this.host.stateStore.getSettings(this.host.clientId);
|
|
39
|
+
this.push();
|
|
40
|
+
this.host.flushSnapshot();
|
|
41
|
+
}
|
|
42
|
+
async applyRuntime() {
|
|
43
|
+
if (this.host.isStreaming()) {
|
|
44
|
+
this.pendingReload = true;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
await this.host.reloadSession();
|
|
48
|
+
if (this.host.isDisposed())
|
|
49
|
+
return;
|
|
50
|
+
this.push();
|
|
51
|
+
this.host.flushSnapshot();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { join, relative, dirname, basename } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { DefaultPackageManager, SettingsManager, ProjectTrustStore, loadSkills } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { settingsVersion, sourceOf } from "./extensions-model.js";
|
|
6
|
+
/** Discover native resources without loading extension entry points or installing dependencies. */
|
|
7
|
+
export async function nativeSkills(cwd, agentDir, change, valid = () => true) {
|
|
8
|
+
const trusted = new ProjectTrustStore(agentDir).get(cwd) === true;
|
|
9
|
+
const settings = SettingsManager.create(cwd, agentDir, { projectTrusted: trusted });
|
|
10
|
+
const fail = () => { const errors = settings.drainErrors(); if (errors.length)
|
|
11
|
+
throw Error(errors.map(e => e.error.message).join("\n")); };
|
|
12
|
+
fail();
|
|
13
|
+
const version = settingsVersion(cwd, agentDir);
|
|
14
|
+
const manager = new DefaultPackageManager({ cwd, agentDir, settingsManager: settings });
|
|
15
|
+
const resources = (await manager.resolve(async () => "skip")).skills;
|
|
16
|
+
const entries = resources.flatMap(resource => {
|
|
17
|
+
const loaded = loadSkills({ cwd, agentDir, includeDefaults: false, skillPaths: [resource.path] }).skills;
|
|
18
|
+
return loaded.map(skill => ({ resource, skill, id: createHash("sha256").update(`${resource.metadata.scope}:${resource.metadata.source}:${resource.path}:${skill.filePath}`).digest("hex") }));
|
|
19
|
+
});
|
|
20
|
+
if (change) {
|
|
21
|
+
if (!valid())
|
|
22
|
+
throw Error("Workspace changed");
|
|
23
|
+
if (change.version !== version || version !== settingsVersion(cwd, agentDir))
|
|
24
|
+
throw Error("Pi settings changed; refresh before applying changes");
|
|
25
|
+
const target = entries.find(entry => entry.id === change.id);
|
|
26
|
+
if (!target || target.resource.metadata.scope === "temporary")
|
|
27
|
+
throw Error("Skill unavailable");
|
|
28
|
+
const { path, metadata } = target.resource;
|
|
29
|
+
const project = metadata.scope === "project";
|
|
30
|
+
if (project && !trusted)
|
|
31
|
+
throw Error("Project is not trusted");
|
|
32
|
+
// A toggle must never affect multiple skills discovered from one custom directory.
|
|
33
|
+
if (entries.filter(entry => entry.resource === target.resource).length !== 1)
|
|
34
|
+
throw Error("Manage this shared skill directory in native settings");
|
|
35
|
+
const config = project ? settings.getProjectSettings() : settings.getGlobalSettings();
|
|
36
|
+
const base = (resource) => resource.metadata.packageRoot ?? resource.metadata.baseDir ?? (project ? join(cwd, ".pi") : agentDir);
|
|
37
|
+
const matches = (pattern, resource) => {
|
|
38
|
+
const normalized = pattern.slice(1).replace(/^\.[\\/]/, "").replaceAll("\\", "/");
|
|
39
|
+
const paths = [resource.path, relative(base(resource), resource.path)];
|
|
40
|
+
if (basename(resource.path) === "SKILL.md")
|
|
41
|
+
paths.push(dirname(resource.path), relative(base(resource), dirname(resource.path)));
|
|
42
|
+
return paths.some(value => value.replaceAll("\\", "/") === normalized);
|
|
43
|
+
};
|
|
44
|
+
const override = (patterns) => {
|
|
45
|
+
const removed = patterns.filter(p => /^[+-]/.test(p) && matches(p, target.resource));
|
|
46
|
+
const retained = patterns.filter(p => !removed.includes(p));
|
|
47
|
+
for (const resource of resources) {
|
|
48
|
+
if (resource === target.resource || resource.metadata.scope !== metadata.scope || resource.metadata.origin !== metadata.origin || metadata.origin === "package" && resource.metadata.source !== metadata.source)
|
|
49
|
+
continue;
|
|
50
|
+
for (const pattern of removed)
|
|
51
|
+
if (matches(pattern, resource))
|
|
52
|
+
retained.push(`${pattern[0]}${resource.path}`);
|
|
53
|
+
}
|
|
54
|
+
return [...retained, `${change.enabled ? "+" : "-"}${path}`];
|
|
55
|
+
};
|
|
56
|
+
if (metadata.origin === "package") {
|
|
57
|
+
const packages = [...(config.packages ?? [])];
|
|
58
|
+
const index = packages.findIndex(entry => sourceOf(entry) === metadata.source);
|
|
59
|
+
if (index < 0)
|
|
60
|
+
throw Error("Package no longer configured");
|
|
61
|
+
const entry = packages[index];
|
|
62
|
+
const declaration = typeof entry === "string" ? { source: entry } : entry;
|
|
63
|
+
// [] means none, unlike an absent filter. Preserve that baseline when enabling one.
|
|
64
|
+
const patterns = declaration.skills?.length === 0 && declaration.autoload !== false ? ["!**"] : declaration.skills ?? [];
|
|
65
|
+
packages[index] = { ...declaration, skills: override(patterns) };
|
|
66
|
+
if (project)
|
|
67
|
+
settings.setProjectPackages(packages);
|
|
68
|
+
else
|
|
69
|
+
settings.setPackages(packages);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const paths = override(config.skills ?? []);
|
|
73
|
+
if (project)
|
|
74
|
+
settings.setProjectSkillPaths(paths);
|
|
75
|
+
else
|
|
76
|
+
settings.setSkillPaths(paths);
|
|
77
|
+
}
|
|
78
|
+
await settings.flush();
|
|
79
|
+
fail();
|
|
80
|
+
return nativeSkills(cwd, agentDir);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
version,
|
|
84
|
+
paths: [...new Set([join(agentDir, "skills"), join(homedir(), ".agents/skills"), join(cwd, ".pi/skills"), ...resources.map(r => r.metadata.packageRoot).filter((path) => !!path)])],
|
|
85
|
+
skills: entries.map(({ id, skill, resource }) => ({ id, name: skill.name, description: skill.description, path: skill.filePath, enabled: resource.enabled, source: resource.metadata.origin === "package" ? "package" : resource.metadata.scope, scope: resource.metadata.scope, canToggle: resource.metadata.scope !== "temporary" && entries.filter(e => e.resource === resource).length === 1, promptVisible: !skill.disableModelInvocation })),
|
|
86
|
+
};
|
|
87
|
+
}
|