pop-agent 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +620 -2
- package/README.zh.md +622 -0
- package/dist/server/approval/read-only.js +107 -0
- package/dist/server/approval/rules.js +73 -0
- package/dist/server/approval/scope.js +164 -0
- package/dist/server/approval/unattended.js +25 -0
- package/dist/server/asr/bridge.js +244 -0
- package/dist/server/asr/install.js +188 -0
- package/dist/server/asr/paths.js +101 -0
- package/dist/server/asr/routes.js +62 -0
- package/dist/server/brand.js +2 -0
- package/dist/server/cli-config.js +65 -0
- package/dist/server/cli-info.js +169 -0
- package/dist/server/cli.js +602 -0
- package/dist/server/computer/apps.js +152 -0
- package/dist/server/computer/cli.js +322 -0
- package/dist/server/computer/framing.js +36 -0
- package/dist/server/computer/helper-client.js +268 -0
- package/dist/server/computer/paths.js +114 -0
- package/dist/server/computer/routes.js +118 -0
- package/dist/server/computer/settings.js +169 -0
- package/dist/server/computer/skill.js +131 -0
- package/dist/server/computer/status.js +134 -0
- package/dist/server/cron/agent-run.js +121 -0
- package/dist/server/cron/index.js +539 -0
- package/dist/server/cron/tool.js +155 -0
- package/dist/server/engine/builtin.js +180 -0
- package/dist/server/engine/catalog-probe.js +34 -0
- package/dist/server/engine/catalog.js +8 -0
- package/dist/server/engine/claude-map.js +297 -0
- package/dist/server/engine/claude-sessions.js +581 -0
- package/dist/server/engine/claude-transport.js +75 -0
- package/dist/server/engine/claude.js +414 -0
- package/dist/server/engine/cli-version.js +119 -0
- package/dist/server/engine/codex-approvals.js +45 -0
- package/dist/server/engine/codex-map.js +298 -0
- package/dist/server/engine/codex-sessions.js +159 -0
- package/dist/server/engine/codex-subagents.js +349 -0
- package/dist/server/engine/codex-transport.js +49 -0
- package/dist/server/engine/codex.js +530 -0
- package/dist/server/engine/dsh-history.js +195 -0
- package/dist/server/engine/dsh-log.js +256 -0
- package/dist/server/engine/dsh-map.js +223 -0
- package/dist/server/engine/dsh-prompt-patch.js +48 -0
- package/dist/server/engine/dsh-sessions.js +206 -0
- package/dist/server/engine/dsh-transport.js +37 -0
- package/dist/server/engine/dsh.js +329 -0
- package/dist/server/engine/engine-install.js +182 -0
- package/dist/server/engine/engine-routes.js +54 -0
- package/dist/server/engine/engine-specs.js +65 -0
- package/dist/server/engine/engine-versions.js +41 -0
- package/dist/server/engine/export-html-tree-patch.js +89 -0
- package/dist/server/engine/fake.js +263 -0
- package/dist/server/engine/jsonrpc-stdio.js +275 -0
- package/dist/server/engine/model-registry-reload.js +115 -0
- package/dist/server/engine/narrate-guidance.js +25 -0
- package/dist/server/engine/opencode-map.js +500 -0
- package/dist/server/engine/opencode-projects.js +61 -0
- package/dist/server/engine/opencode-sessions.js +201 -0
- package/dist/server/engine/opencode-transport.js +48 -0
- package/dist/server/engine/opencode.js +434 -0
- package/dist/server/engine/pi-appearance-tool.js +101 -0
- package/dist/server/engine/pi-canvas-tool.js +181 -0
- package/dist/server/engine/pi-cron-tool.js +196 -0
- package/dist/server/engine/pi-events.js +153 -0
- package/dist/server/engine/pi-plugins.js +312 -0
- package/dist/server/engine/pi-rename.js +14 -0
- package/dist/server/engine/pi-retry.js +124 -0
- package/dist/server/engine/pi-sdk.js +1272 -0
- package/dist/server/engine/pi-session-model.js +23 -0
- package/dist/server/engine/pi-stop.js +28 -0
- package/dist/server/engine/pi-subagent-tool.js +188 -0
- package/dist/server/engine/pi-subagents.js +445 -0
- package/dist/server/engine/pi-thinking.js +34 -0
- package/dist/server/engine/pi-transcript.js +247 -0
- package/dist/server/engine/pi-turn-outcome.js +25 -0
- package/dist/server/engine/pi-version.js +11 -0
- package/dist/server/engine/port.js +1 -0
- package/dist/server/engine/registry.js +61 -0
- package/dist/server/engine/resource-signature.js +55 -0
- package/dist/server/engine/scratch.js +13 -0
- package/dist/server/engine/subagent-guidance.js +22 -0
- package/dist/server/engine/suggestion-guidance.js +24 -0
- package/dist/server/engine/switchable.js +22 -0
- package/dist/server/engine/wiring.js +225 -0
- package/dist/server/files/content-search.js +187 -0
- package/dist/server/files/dir-routes.js +104 -0
- package/dist/server/files/file-search.js +64 -0
- package/dist/server/files/file-service.js +286 -0
- package/dist/server/files/files-routes.js +278 -0
- package/dist/server/files/git-info.js +428 -0
- package/dist/server/files/path-resolve.js +176 -0
- package/dist/server/files/pick-path-routes.js +162 -0
- package/dist/server/http/auth-routes.js +454 -0
- package/dist/server/http/auth.js +306 -0
- package/dist/server/http/aux-routes.js +98 -0
- package/dist/server/http/client-log-routes.js +49 -0
- package/dist/server/http/compress.js +102 -0
- package/dist/server/http/file-headers.js +75 -0
- package/dist/server/http/health-and-static.js +46 -0
- package/dist/server/http/live-routes.js +116 -0
- package/dist/server/http/login-activity.js +76 -0
- package/dist/server/http/login-guard.js +185 -0
- package/dist/server/http/login-page.js +347 -0
- package/dist/server/http/password-store.js +88 -0
- package/dist/server/http/voice-settings-routes.js +30 -0
- package/dist/server/http/ws-routes.js +141 -0
- package/dist/server/index.js +1085 -0
- package/dist/server/markers/actions.js +281 -0
- package/dist/server/mcp/codex-mcp-store.js +190 -0
- package/dist/server/mcp/json-mcp-store.js +276 -0
- package/dist/server/mcp/mcp-auth.js +194 -0
- package/dist/server/mcp/mcp-command.js +137 -0
- package/dist/server/mcp/mcp-engine-shared.js +112 -0
- package/dist/server/mcp/mcp-import.js +289 -0
- package/dist/server/mcp/mcp-market-sources.js +192 -0
- package/dist/server/mcp/mcp-market-types.js +5 -0
- package/dist/server/mcp/mcp-market.js +174 -0
- package/dist/server/mcp/mcp-probe.js +170 -0
- package/dist/server/mcp/mcp-routes.js +71 -0
- package/dist/server/mcp/mcp-store.js +286 -0
- package/dist/server/mcp/none-mcp-store.js +27 -0
- package/dist/server/mcp/pi-mcp-config.js +308 -0
- package/dist/server/pi-gate.js +106 -0
- package/dist/server/plugins/engine-plugin-stores.js +265 -0
- package/dist/server/plugins/plugin-routes.js +22 -0
- package/dist/server/protocol-parse.js +533 -0
- package/dist/server/protocol-settings.js +1 -0
- package/dist/server/protocol.js +8 -0
- package/dist/server/providers/catalog-store.js +89 -0
- package/dist/server/providers/catalog-writes.js +199 -0
- package/dist/server/providers/catalog.js +77 -0
- package/dist/server/providers/codex-models.js +96 -0
- package/dist/server/providers/codex-test.js +124 -0
- package/dist/server/providers/enabled-models.js +110 -0
- package/dist/server/providers/import-models.js +69 -0
- package/dist/server/providers/import-routes.js +266 -0
- package/dist/server/providers/model-kind.js +35 -0
- package/dist/server/providers/model-test.js +113 -0
- package/dist/server/providers/one-shot.js +218 -0
- package/dist/server/providers/probe-routes.js +26 -0
- package/dist/server/providers/probe.js +84 -0
- package/dist/server/providers/provider-handlers.js +240 -0
- package/dist/server/providers/provider-pool.js +63 -0
- package/dist/server/providers/provider-store.js +502 -0
- package/dist/server/providers/request-headers.js +7 -0
- package/dist/server/providers/subscription-routes.js +183 -0
- package/dist/server/providers/validate.js +249 -0
- package/dist/server/push/push-routes.js +171 -0
- package/dist/server/push/push.js +239 -0
- package/dist/server/push/vapid-config.js +179 -0
- package/dist/server/session/appearance.js +79 -0
- package/dist/server/session/approval-bridge.js +119 -0
- package/dist/server/session/attachment-resolve.js +21 -0
- package/dist/server/session/canvas-artifacts.js +108 -0
- package/dist/server/session/canvas-store.js +137 -0
- package/dist/server/session/canvas-suggest.js +70 -0
- package/dist/server/session/canvas.js +323 -0
- package/dist/server/session/client-view.js +82 -0
- package/dist/server/session/close-ephemeral.js +23 -0
- package/dist/server/session/conversation-create.js +87 -0
- package/dist/server/session/cron-prompt-routes.js +25 -0
- package/dist/server/session/cron-prompt.js +59 -0
- package/dist/server/session/delete-session.js +125 -0
- package/dist/server/session/engine-switch.js +118 -0
- package/dist/server/session/fork-session.js +38 -0
- package/dist/server/session/lock.js +82 -0
- package/dist/server/session/model-controller.js +149 -0
- package/dist/server/session/move-session.js +40 -0
- package/dist/server/session/notices.js +33 -0
- package/dist/server/session/one-shot.js +95 -0
- package/dist/server/session/persist-ephemeral.js +48 -0
- package/dist/server/session/pi-opener.js +163 -0
- package/dist/server/session/pi-refresh.js +51 -0
- package/dist/server/session/pi-sessions-provider.js +41 -0
- package/dist/server/session/pi-sessions.js +431 -0
- package/dist/server/session/refresh-actions.js +58 -0
- package/dist/server/session/rename-session.js +23 -0
- package/dist/server/session/runtime-services.js +37 -0
- package/dist/server/session/runtime-types.js +1 -0
- package/dist/server/session/runtime.js +844 -0
- package/dist/server/session/session-stats.js +91 -0
- package/dist/server/session/settings.js +526 -0
- package/dist/server/session/snapshot-for.js +9 -0
- package/dist/server/session/stats-refresher.js +55 -0
- package/dist/server/session/subagents.js +119 -0
- package/dist/server/session/suggest-title.js +33 -0
- package/dist/server/session/switch-conversation.js +111 -0
- package/dist/server/session/template-prompt-routes.js +26 -0
- package/dist/server/session/template-prompt.js +110 -0
- package/dist/server/session/throttle.js +14 -0
- package/dist/server/session/title-prompt.js +128 -0
- package/dist/server/session/turn-events.js +198 -0
- package/dist/server/session/turn-finish.js +97 -0
- package/dist/server/session/turn-markers.js +31 -0
- package/dist/server/session/turn-queue.js +264 -0
- package/dist/server/session/turn-send.js +138 -0
- package/dist/server/session/turn-watchdog.js +77 -0
- package/dist/server/session/voice-settings.js +39 -0
- package/dist/server/sessions/session-routes.js +97 -0
- package/dist/server/skills/skill-install.js +184 -0
- package/dist/server/skills/skill-routes.js +134 -0
- package/dist/server/skills/skill-store.js +163 -0
- package/dist/server/skills/skillhub.js +213 -0
- package/dist/server/skills/zip.js +121 -0
- package/dist/server/snapshot/fan-out.js +12 -0
- package/dist/server/snapshot/messages.js +117 -0
- package/dist/server/snapshot/sender.js +53 -0
- package/dist/server/snapshot/state.js +274 -0
- package/dist/server/subagents/profile-store.js +305 -0
- package/dist/server/terminal/terminal-routes.js +223 -0
- package/dist/server/terminal/terminal-session.js +197 -0
- package/dist/server/tts/edge-worker-source.js +48 -0
- package/dist/server/tts/edge.js +143 -0
- package/dist/server/tts/local-voices.js +35 -0
- package/dist/server/tts/local.js +192 -0
- package/dist/server/tts/routes.js +56 -0
- package/dist/server/tts/service.js +97 -0
- package/dist/server/tts/types.js +7 -0
- package/dist/server/tts/voices.js +21 -0
- package/dist/server/update-check.js +147 -0
- package/dist/server/update-prompt.js +131 -0
- package/dist/server/uploads/upload-routes.js +67 -0
- package/dist/server/uploads/upload-store.js +113 -0
- package/dist/server/util/atomic-write.js +18 -0
- package/dist/server/util/data-dir.js +36 -0
- package/dist/server/util/desktop.js +216 -0
- package/dist/server/util/env.js +202 -0
- package/dist/server/util/file-mode.js +57 -0
- package/dist/server/util/ids.js +28 -0
- package/dist/server/util/json-file.js +38 -0
- package/dist/server/util/log-file.js +67 -0
- package/dist/server/util/log.js +52 -0
- package/dist/server/util/origin.js +117 -0
- package/dist/server/util/paths.js +187 -0
- package/dist/server/util/pricing-index.js +117 -0
- package/dist/server/util/pricing.js +214 -0
- package/dist/server/util/prune-pty.js +72 -0
- package/dist/server/util/spawn-cli.js +147 -0
- package/dist/server/util/startup.js +34 -0
- package/dist/server/util/upstream-version.js +177 -0
- package/dist/server/util/usage.js +19 -0
- package/dist/server/util/version.js +59 -0
- package/dist/server/web-proxy/picker-script.js +495 -0
- package/dist/server/web-proxy/proxy-routes.js +205 -0
- package/dist/server/web-proxy/proxy-url.js +76 -0
- package/dist/server/web-proxy/rewrite.js +98 -0
- package/dist/server/web-proxy/wrapper.js +92 -0
- package/dist/server/ws/handle-message.js +182 -0
- package/dist/server/ws/reply-frame.js +5 -0
- package/helper/asr/Info.plist +24 -0
- package/helper/asr/build.sh +59 -0
- package/helper/asr/main.swift +279 -0
- package/helper/asr/release/ASRBridge.zip +0 -0
- package/package.json +120 -5
- package/web/dist/apple-touch-icon-precomposed.png +0 -0
- package/web/dist/apple-touch-icon.png +0 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_abnfDiagram-WEYOIA3C-Cxf7yoVn.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_architectureDiagram-ZHVYKT53-BtmjGlGq.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_c4Diagram-XDPPPE54-CMVGVtIk.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_cynefinDiagram-WF24UDRP-7i0BPrM8.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_diagram-CBK3MWTC-G70wUrpC.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_diagram-ODIL2UCW-DG5xxpj4.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_diagram-PFBEJUXE-TVSrX2lz.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_diagram-TYUNFSNR-B5kj_W4w.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_ebnfDiagram-V4P3TTPT-CYDlMnIy.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_ishikawaDiagram-HPEHV2GE-Bwle1LQ4.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_mindmap-definition-6OY57UG3-Dp_r4po3.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_pegDiagram-ECIUJNBX-D0XH8M0y.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_railroadDiagram-Y72NRBL7-BYBIBrHp.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_swimlanes-B3ENRKFQ-Bj4-4hK8.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_swimlanesDiagram-AYQRV4AK-Cr0JbDyV.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_usecaseDiagram-WPOLBNNX-BN92OiEn.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_vennDiagram-Q3Y3IDCW--PhbzdU_.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_chunk_wardleyDiagram-IVAIDKWA-nObiqZ0S.js +1 -0
- package/web/dist/assets/_pop-agent-mermaid-pruned_katex_katex-Zojedrce.js +1 -0
- package/web/dist/assets/approval.en-BFhMPNWP.mp3 +0 -0
- package/web/dist/assets/approval.zh-DWqP6Pcu.mp3 +0 -0
- package/web/dist/assets/arc-Dn7mfTUL.js +1 -0
- package/web/dist/assets/architecture-WOLXFQ4H-DwHKr8GA.js +1 -0
- package/web/dist/assets/array-BifhSqXX.js +1 -0
- package/web/dist/assets/blockDiagram-RJAE7QA3-CA2AOM6-.js +140 -0
- package/web/dist/assets/channel-PVcvMEH-.js +1 -0
- package/web/dist/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
- package/web/dist/assets/chunk-55XCU76K-DlITu1ZH.js +1 -0
- package/web/dist/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
- package/web/dist/assets/chunk-7S6XSTFO-DzX1XF3_.js +2 -0
- package/web/dist/assets/chunk-AQDTSKZB-BdEDejS-.js +72 -0
- package/web/dist/assets/chunk-DSNLSHJZ-Chj2PD0m.js +129 -0
- package/web/dist/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
- package/web/dist/assets/chunk-HNE4Q36P-V3jylrEv.js +1 -0
- package/web/dist/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
- package/web/dist/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
- package/web/dist/assets/chunk-NGNAAXSQ-DuHRe0y2.js +136 -0
- package/web/dist/assets/chunk-VQ5W62QI-BiWZxVe5.js +1 -0
- package/web/dist/assets/chunk-WQQL4CDK-BtyaHLI7.js +10 -0
- package/web/dist/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
- package/web/dist/assets/chunk-ZAUX2LTX-DS3wpSTy.js +62 -0
- package/web/dist/assets/chunk-ZCHMQSOR-at82jgqF.js +2 -0
- package/web/dist/assets/classDiagram-v2-4MYWR3UA-CTgR1e3M.js +217 -0
- package/web/dist/assets/cose-bilkent-JH36ORCC-DW-hnOsq.js +1 -0
- package/web/dist/assets/cynefin-EF2NZ3EQ-Pg-c-yVE.js +1 -0
- package/web/dist/assets/dagre-NK4GIZVX-B0Ivt5Pn.js +4 -0
- package/web/dist/assets/diagram-I5XIIV2D-jE6SNlbX.js +24 -0
- package/web/dist/assets/diagram-RJA3I4VV-DQJNgW0u.js +41 -0
- package/web/dist/assets/done.en-s1tZOg6A.mp3 +0 -0
- package/web/dist/assets/done.zh-Dq-Os4NS.mp3 +0 -0
- package/web/dist/assets/elk-QONTBCTQ-KOJVoDyP.js +27 -0
- package/web/dist/assets/erDiagram-KYQIGQAA-DNUqfe2J.js +99 -0
- package/web/dist/assets/error.en-BGPHdZVi.mp3 +0 -0
- package/web/dist/assets/error.zh-DdFp64-u.mp3 +0 -0
- package/web/dist/assets/eventmodeling-K75KTNOO-DnxXCUaf.js +1 -0
- package/web/dist/assets/flowDiagram-IUGLLWBU-CRLc8ozS.js +213 -0
- package/web/dist/assets/ganttDiagram-R7GPNTJY-DDLhSPGT.js +292 -0
- package/web/dist/assets/gitGraph-VSP46ZUC-BjfoZeXP.js +1 -0
- package/web/dist/assets/gitGraphDiagram-PDYL7XHY-6uZGw3lU.js +106 -0
- package/web/dist/assets/graphlib-DS17s2tU.js +1 -0
- package/web/dist/assets/highlight-DMv0JmTA.js +5 -0
- package/web/dist/assets/i18n-en-H5OrSHR5.js +1 -0
- package/web/dist/assets/index-CQ1VhLwx.js +79 -0
- package/web/dist/assets/index-DB6jJFLf.css +1 -0
- package/web/dist/assets/info-OHQRW6UA-BMDHcIvy.js +1 -0
- package/web/dist/assets/infoDiagram-MVDRKAX5-C2d1Uwhn.js +2 -0
- package/web/dist/assets/init-C-OQMol4.js +1 -0
- package/web/dist/assets/journeyDiagram-BOSHW7O7-BAE_nPCd.js +139 -0
- package/web/dist/assets/kanban-definition-FNSA4HC5-C2Z3ejvx.js +89 -0
- package/web/dist/assets/line-DHlXL-f4.js +1 -0
- package/web/dist/assets/linear-B363vzIx.js +1 -0
- package/web/dist/assets/markdown-Bcx45PNe.js +31 -0
- package/web/dist/assets/math-Dh0H2mym.js +1 -0
- package/web/dist/assets/mermaid-parser.core-CxD9DMnU.js +7 -0
- package/web/dist/assets/mermaid.core-CdVzG6_M.js +44 -0
- package/web/dist/assets/ordinal-BDEzSJ7C.js +1 -0
- package/web/dist/assets/packet-JDAUHWVQ-Cx23kBS5.js +1 -0
- package/web/dist/assets/path-fybaL0A-.js +1 -0
- package/web/dist/assets/pie-XZMESJXO-BDdtcaza.js +1 -0
- package/web/dist/assets/pieDiagram-GNMPY74T-DRqt_o8d.js +39 -0
- package/web/dist/assets/quadrantDiagram-D57K4MC3-Cq3-_E3T.js +7 -0
- package/web/dist/assets/radar-ABXABTNO-yJ_gp7Uq.js +1 -0
- package/web/dist/assets/railroad-I3PHUGI6-BFVVDyfL.js +1 -0
- package/web/dist/assets/railroad-abnf-LNEFI6M7-BhhpD6rl.js +1 -0
- package/web/dist/assets/railroad-ebnf-DWYD2UWJ-os_iV6TA.js +1 -0
- package/web/dist/assets/railroad-peg-JR7BVNR7-kex9mDBE.js +1 -0
- package/web/dist/assets/react-TO3cgmuO.js +9 -0
- package/web/dist/assets/requirementDiagram-EQYSW5RA-BnDM54-F.js +84 -0
- package/web/dist/assets/rolldown-runtime-COiEfhsA.js +1 -0
- package/web/dist/assets/sankeyDiagram-SY24JHO5-CMQmL2Tu.js +40 -0
- package/web/dist/assets/sequenceDiagram-BLEHNHQU-Dqhxl46T.js +169 -0
- package/web/dist/assets/sizeCapture-INFHLROL-3uHXrFqA.js +1 -0
- package/web/dist/assets/src-BWF7jMDv.js +1 -0
- package/web/dist/assets/stateDiagram-v2-A6IESKWZ-D1u1qdD7.js +291 -0
- package/web/dist/assets/steer.en-1RIP4K_0.mp3 +0 -0
- package/web/dist/assets/steer.zh-BCINYQs7.mp3 +0 -0
- package/web/dist/assets/stopped.en-CFPMi6oy.mp3 +0 -0
- package/web/dist/assets/stopped.zh-D2CUs-KZ.mp3 +0 -0
- package/web/dist/assets/timeline-definition-JXYKGLGB-DEjsSeWV.js +120 -0
- package/web/dist/assets/treeView-D4JQ5SDB-BXYISxgj.js +1 -0
- package/web/dist/assets/treemap-SAJKECNS-B6BJK2c0.js +1 -0
- package/web/dist/assets/wardley-7MLQ67FV-DsjBYeKs.js +1 -0
- package/web/dist/assets/xterm-BrP-ENHg.css +1 -0
- package/web/dist/assets/xterm-C3-Bm0Yw.js +16 -0
- package/web/dist/assets/xychartDiagram-4URNHDU4-CBbRqTE2.js +7 -0
- package/web/dist/favicon-32.png +0 -0
- package/web/dist/favicon.ico +0 -0
- package/web/dist/favicon.svg +25 -0
- package/web/dist/icons/apple-touch-icon-180.png +0 -0
- package/web/dist/icons/icon-1024.png +0 -0
- package/web/dist/icons/icon-192.png +0 -0
- package/web/dist/icons/icon-512.png +0 -0
- package/web/dist/icons/icon-maskable-512.png +0 -0
- package/web/dist/index.html +62 -0
- package/web/dist/manifest.webmanifest +17 -0
- package/web/dist/maskable.svg +25 -0
- package/web/dist/sw.js +40 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 引擎接线(index.ts 的 400 行护栏 + 一处装配)。
|
|
3
|
+
*
|
|
4
|
+
* 把三件事绑在一起,因为它们必须指向**同一批实例**:
|
|
5
|
+
* 1. 注册表(有哪些引擎、怎么造);
|
|
6
|
+
* 2. codex 的 app-server 客户端(引擎与会话清单共用一个子进程);
|
|
7
|
+
* 3. 目录(每个引擎的历史会话从哪来)。
|
|
8
|
+
*
|
|
9
|
+
* codex 客户端构造时不 spawn:机器上没装 codex 也能正常启动,只有在切到它时才报错。
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { createBuiltinEngineRegistry } from "./builtin.js";
|
|
15
|
+
import { enabledSubagentSpecs, readSubagentSettings } from "../subagents/profile-store.js";
|
|
16
|
+
import { createEngineCatalog } from "./catalog.js";
|
|
17
|
+
import { createClaudeSessionsProvider } from "./claude-sessions.js";
|
|
18
|
+
import { createClaudeClient } from "./claude-transport.js";
|
|
19
|
+
import { createCodexSessionsProvider } from "./codex-sessions.js";
|
|
20
|
+
import { createCodexClient } from "./codex-transport.js";
|
|
21
|
+
import { createDshClient } from "./dsh-transport.js";
|
|
22
|
+
import { writeDshSuggestionPatch } from "./dsh-prompt-patch.js";
|
|
23
|
+
import { suggestionGuidance } from "./suggestion-guidance.js";
|
|
24
|
+
import { NARRATE_GUIDANCE } from "./narrate-guidance.js";
|
|
25
|
+
import { createDshSessionsProvider } from "./dsh-sessions.js";
|
|
26
|
+
import { createOpencodeSessionsProvider } from "./opencode-sessions.js";
|
|
27
|
+
import { readOpencodeSessionDirs } from "./opencode-projects.js";
|
|
28
|
+
import { createOpencodeClient } from "./opencode-transport.js";
|
|
29
|
+
/** opencode 目录清单的缓存时长:它是「要逐个点名多少个目录」的依据,不必每次刷新都开一次库 */
|
|
30
|
+
const OPENCODE_DIRS_TTL_MS = 30_000;
|
|
31
|
+
/**
|
|
32
|
+
* 读 `<patchDir>/default-model.json`(`{"provider":"…","model":"…"}` 或 `{"id":"provider/model"}`)。
|
|
33
|
+
*
|
|
34
|
+
* 为什么要有它:把自定义 provider 通过 `--patch` 带给 acp 之后,ACP 的 `session/new`
|
|
35
|
+
* 仍然按它自己的默认路由给 `currentValue`(实测 `agent-default-model` 不生效),
|
|
36
|
+
* 于是「新会话默认用哪个模型」必须由我们自己指定。
|
|
37
|
+
*/
|
|
38
|
+
function readDshDefaultModel(dir) {
|
|
39
|
+
const file = join(dir, "default-model.json");
|
|
40
|
+
if (!existsSync(file))
|
|
41
|
+
return null;
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
44
|
+
if (typeof parsed.id === "string" && parsed.id.trim() !== "")
|
|
45
|
+
return parsed.id.trim();
|
|
46
|
+
if (typeof parsed.provider === "string" && typeof parsed.model === "string") {
|
|
47
|
+
return `${parsed.provider}/${parsed.model}`;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function createEngineWiring(options) {
|
|
56
|
+
const codexClient = createCodexClient({
|
|
57
|
+
bin: options.codexBin,
|
|
58
|
+
home: options.codexHome ?? undefined,
|
|
59
|
+
log: (text) => options.onLog(text, { engine: "codex" }),
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* dsh 的 patch 叠加层:把「自定义 provider / 默认模型」带给 acp profile。
|
|
63
|
+
* 顺序 = 环境变量里显式给的 → 用户目录里的 `*.yml`(按文件名)。
|
|
64
|
+
*/
|
|
65
|
+
const patchDir = options.dshPatchDir;
|
|
66
|
+
/**
|
|
67
|
+
* 「下一步建议」+「动手前先说话」:dsh 只能靠 patch 叠加层带进去
|
|
68
|
+
* (ACP 的 session/new 没有系统提示字段)。写在工作台自己的临时目录,
|
|
69
|
+
* **不**混进用户的 `dsh-patches`;排在最前面,用户自己写的 patch 仍有最终决定权。
|
|
70
|
+
*/
|
|
71
|
+
const suggestionPatchFile = writeDshSuggestionPatch(join(tmpdir(), "pop-agent"), [suggestionGuidance(options.thinkCount?.() ?? null), NARRATE_GUIDANCE].join("\n\n"));
|
|
72
|
+
const patchFiles = [
|
|
73
|
+
suggestionPatchFile,
|
|
74
|
+
...(options.dshPatches ?? []),
|
|
75
|
+
...(patchDir && existsSync(patchDir)
|
|
76
|
+
? readdirSync(patchDir)
|
|
77
|
+
.filter((name) => name.endsWith(".yml") || name.endsWith(".yaml"))
|
|
78
|
+
.sort()
|
|
79
|
+
.map((name) => join(patchDir, name))
|
|
80
|
+
: []),
|
|
81
|
+
].filter((file) => existsSync(file));
|
|
82
|
+
if (patchFiles.length > 0)
|
|
83
|
+
options.onLog(`dsh:加载 ${patchFiles.length} 个 patch 叠加层`, { files: patchFiles });
|
|
84
|
+
// 自定义 provider 的「默认模型」:patch 里的 agent-default-model 不会被 ACP 带到
|
|
85
|
+
// session/new 的 configOptions(实测),所以这里用一个伴随文件显式指定。
|
|
86
|
+
const defaultModel = options.dshModel ?? (patchDir ? readDshDefaultModel(patchDir) : null);
|
|
87
|
+
const dshClient = createDshClient({
|
|
88
|
+
bin: options.dshBin,
|
|
89
|
+
home: options.dshHome ?? undefined,
|
|
90
|
+
patches: patchFiles,
|
|
91
|
+
log: (text) => options.onLog(text, { engine: "dsh" }),
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* opencode 的 ACP 客户端(懒启动:机器上没装 opencode 也能正常起工作台,切到它才拉起)。
|
|
95
|
+
* 会话清单与引擎共用同一个子进程。
|
|
96
|
+
*/
|
|
97
|
+
const opencodeClient = createOpencodeClient({
|
|
98
|
+
bin: options.opencodeBin,
|
|
99
|
+
args: options.opencodeArgs,
|
|
100
|
+
// 别让它继承宿主进程的目录:opencode 的项目上下文跟着 cwd 走
|
|
101
|
+
cwd: options.workspace,
|
|
102
|
+
log: (text) => options.onLog(text, { engine: "opencode" }),
|
|
103
|
+
});
|
|
104
|
+
/**
|
|
105
|
+
* opencode 的候选目录:`session/list` 是**目录作用域**的,且带 `{cwd}` 只匹配 `directory` 完全相等的会话
|
|
106
|
+
* (不是整棵项目树,见 opencode-sessions.ts 文件头)。所以「全部历史」= 把「有过会话的目录」逐个点名。
|
|
107
|
+
* 三个来源取并集:
|
|
108
|
+
* 1. 当前工作区;
|
|
109
|
+
* 2. opencode 自己的 `session.directory`(全量答案,只读;见 opencode-projects.ts);
|
|
110
|
+
* 3. pi 的历史会话项目(缓存过,热态 ~7ms)。
|
|
111
|
+
*
|
|
112
|
+
* 目录清单缓存 30s:它是「有多少个目录要点名」的依据,没必要每次刷新都开一次库;
|
|
113
|
+
* 会话本身不缓存(删了要立刻消失)。
|
|
114
|
+
*/
|
|
115
|
+
let opencodeDirsCache = null;
|
|
116
|
+
const opencodeWorkspaces = async () => {
|
|
117
|
+
const dirs = [options.workspace];
|
|
118
|
+
if (!opencodeDirsCache || Date.now() - opencodeDirsCache.at > OPENCODE_DIRS_TTL_MS) {
|
|
119
|
+
const found = await readOpencodeSessionDirs({ log: (text) => options.onLog(text, { engine: "opencode" }) });
|
|
120
|
+
opencodeDirsCache = { at: Date.now(), dirs: found };
|
|
121
|
+
}
|
|
122
|
+
dirs.push(...opencodeDirsCache.dirs);
|
|
123
|
+
try {
|
|
124
|
+
for (const project of await options.piSessions())
|
|
125
|
+
dirs.push(project.cwd);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
options.onLog(`opencode:枚举候选项目目录失败(只用工作区):${error instanceof Error ? error.message : String(error)}`, {
|
|
129
|
+
engine: "opencode",
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return dirs;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Claude Code 的 ACP 客户端(同样懒启动:没装适配器也能正常起工作台)。
|
|
136
|
+
* 历史会话清单不走它(直接读 `~/.claude/projects`),所以这里只给引擎用。
|
|
137
|
+
*
|
|
138
|
+
* `claudeBin` 空串 = 自动探测(老包 `claude-code-acp` / 新包 `claude-agent-acp`)。
|
|
139
|
+
*/
|
|
140
|
+
const claudeClient = createClaudeClient({
|
|
141
|
+
bin: options.claudeBin || undefined,
|
|
142
|
+
args: options.claudeArgs,
|
|
143
|
+
cwd: options.workspace,
|
|
144
|
+
log: (text) => options.onLog(text, { engine: "claude" }),
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
* codex 的子代理策略:**每次建会话现读**模板库(面板改完,下一条新会话就生效)。
|
|
148
|
+
*
|
|
149
|
+
* 读不到模板目录(精简部署)= 关掉:宁可不给 spawn 工具,也不要让模型
|
|
150
|
+
* 拿着一堆它看不见的「类型」乱派活。
|
|
151
|
+
*/
|
|
152
|
+
const codexSubagentPolicy = () => {
|
|
153
|
+
const dir = options.subagentAgentDir;
|
|
154
|
+
if (!dir)
|
|
155
|
+
return { enabled: false, concurrency: 4, profiles: [] };
|
|
156
|
+
const settings = readSubagentSettings(dir);
|
|
157
|
+
const profiles = enabledSubagentSpecs(dir).map((profile) => ({
|
|
158
|
+
id: profile.id,
|
|
159
|
+
label: profile.label,
|
|
160
|
+
description: profile.description,
|
|
161
|
+
}));
|
|
162
|
+
return { enabled: settings.enabled, concurrency: settings.concurrency, profiles };
|
|
163
|
+
};
|
|
164
|
+
const registry = createBuiltinEngineRegistry({
|
|
165
|
+
onNotice: options.onNotice,
|
|
166
|
+
...(options.skillPaths ? { skillPaths: options.skillPaths } : {}),
|
|
167
|
+
onLog: (text) => options.onLog(text),
|
|
168
|
+
...(options.thinkCount ? { thinkCount: options.thinkCount } : {}),
|
|
169
|
+
...(options.cron ? { cron: options.cron } : {}),
|
|
170
|
+
...(options.appearance ? { appearance: options.appearance } : {}),
|
|
171
|
+
...(options.canvas ? { canvas: options.canvas } : {}),
|
|
172
|
+
codex: { client: codexClient, bin: options.codexBin, subagentPolicy: codexSubagentPolicy },
|
|
173
|
+
dsh: { client: dshClient, bin: options.dshBin, model: defaultModel },
|
|
174
|
+
opencode: {
|
|
175
|
+
client: opencodeClient,
|
|
176
|
+
bin: options.opencodeBin,
|
|
177
|
+
args: options.opencodeArgs,
|
|
178
|
+
model: options.opencodeModel ?? null,
|
|
179
|
+
},
|
|
180
|
+
claude: {
|
|
181
|
+
client: claudeClient,
|
|
182
|
+
bin: options.claudeBin || undefined,
|
|
183
|
+
args: options.claudeArgs,
|
|
184
|
+
model: options.claudeModel ?? null,
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
const catalog = createEngineCatalog({
|
|
188
|
+
registry,
|
|
189
|
+
sessions: {
|
|
190
|
+
pi: options.piSessions,
|
|
191
|
+
// fake 是「剧本回放」引擎:历史沿用 pi 的存储(本地演练 / 冒烟时侧栏不至于全空)
|
|
192
|
+
fake: options.piSessions,
|
|
193
|
+
codex: createCodexSessionsProvider({ client: codexClient, log: (text) => options.onLog(text) }),
|
|
194
|
+
// dsh 的历史会话清单:读 ~/.dsh 的 workspace.json + 会话投影缓存(只读)
|
|
195
|
+
dsh: createDshSessionsProvider({ home: options.dshHome ?? undefined, log: (text) => options.onLog(text) }),
|
|
196
|
+
// opencode 的历史会话清单:按项目 cwd 逐个 `session/list`(接口是项目作用域的)
|
|
197
|
+
opencode: createOpencodeSessionsProvider({
|
|
198
|
+
client: opencodeClient,
|
|
199
|
+
workspaces: opencodeWorkspaces,
|
|
200
|
+
log: (text) => options.onLog(text),
|
|
201
|
+
}),
|
|
202
|
+
// claude 的历史会话清单:直接读 `~/.claude/projects/*/*.jsonl`(标题/时间/模型都在文件里)
|
|
203
|
+
claude: createClaudeSessionsProvider({ log: (text) => options.onLog(text) }),
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
const resolved = registry.resolve(options.engineName);
|
|
207
|
+
if (resolved.fallbackFrom) {
|
|
208
|
+
options.onLog(`POP_AGENT_ENGINE 未注册,回落到 pi(可选:${registry.names().join(" / ")})`, {
|
|
209
|
+
requested: resolved.fallbackFrom,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
registry,
|
|
214
|
+
catalog,
|
|
215
|
+
resolved,
|
|
216
|
+
codexClient,
|
|
217
|
+
// 收掉外部引擎的子进程;pi 是进程内 SDK,不需要额外收
|
|
218
|
+
close: () => {
|
|
219
|
+
codexClient.close();
|
|
220
|
+
dshClient.close();
|
|
221
|
+
opencodeClient.close();
|
|
222
|
+
claudeClient.close();
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 全文搜索(**文件内容** grep)—— 文件名搜索是 file-search.ts 的活,这里是「这行字出现在哪」。
|
|
3
|
+
*
|
|
4
|
+
* 为什么自己走一遍目录、不直接 `rg`:这个工作台要能在没装 ripgrep 的机器上开箱就用,
|
|
5
|
+
* 也不想为一次搜索多进程一个不稳定的外部依赖。代价是自己得把「别扫的东西」列清楚:
|
|
6
|
+
* - 跳过 node_modules / .git / dist 之类的重目录(复用 file-service 的 IGNORED_ENTRIES);
|
|
7
|
+
* - 跳过符号链接(可能成环)、跳过二进制(含 NUL 字节)、跳过超过 512KB 的文件;
|
|
8
|
+
* - 文件数 / 结果数都有上限,超了就 `truncated: true` —— 界面明确说「只显示前 N 条」,
|
|
9
|
+
* 比让人等到怀疑卡死强。
|
|
10
|
+
*
|
|
11
|
+
* 匹配大小写不敏感(跟文件名搜索一个口径):找代码时记得住字、记不住大小写。
|
|
12
|
+
* 每行最多回一条命中:一屏里同一行出现五次同一个词,列五条只会把别的结果挤下去。
|
|
13
|
+
*/
|
|
14
|
+
import { readFile, readdir, stat } from "node:fs/promises";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { toPosixPath } from "../util/paths.js";
|
|
17
|
+
import { isIgnoredEntry } from "./file-service.js";
|
|
18
|
+
const GREP_MAX_RESULTS = 200;
|
|
19
|
+
const GREP_MAX_FILES = 20000;
|
|
20
|
+
const GREP_MAX_FILE_BYTES = 512 * 1024;
|
|
21
|
+
/** 单行最多回多少字(长的压缩行 / 生成的 JSON 别把整屏撑爆) */
|
|
22
|
+
export const GREP_LINE_CHARS = 400;
|
|
23
|
+
const GREP_MAX_DEPTH = 12;
|
|
24
|
+
/** 正则里的特殊字符(逐个转义;glob 只认 `*` `**` `?`,其余按字面) */
|
|
25
|
+
const REGEX_SPECIAL = /[.+^${}()|[\]\\]/g;
|
|
26
|
+
/**
|
|
27
|
+
* 简易 glob → 正则:`*` 不跨目录、`**` 跨目录、`?` 一个字符。
|
|
28
|
+
* 空模式回 null(= 不筛)。
|
|
29
|
+
*/
|
|
30
|
+
export function globToRegExp(glob) {
|
|
31
|
+
const pattern = glob.trim();
|
|
32
|
+
if (pattern === "")
|
|
33
|
+
return null;
|
|
34
|
+
let out = "";
|
|
35
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
36
|
+
const char = pattern[index];
|
|
37
|
+
if (char === "*") {
|
|
38
|
+
if (pattern[index + 1] === "*") {
|
|
39
|
+
index += 1;
|
|
40
|
+
// `**/` = 任意层目录(含零层);尾部的 `**` = 任意字符
|
|
41
|
+
if (pattern[index + 1] === "/") {
|
|
42
|
+
index += 1;
|
|
43
|
+
out += "(?:[^/]+/)*";
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
out += ".*";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
out += "[^/]*";
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (char === "?") {
|
|
55
|
+
out += "[^/]";
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
out += char.replace(REGEX_SPECIAL, "\\$&");
|
|
59
|
+
}
|
|
60
|
+
return new RegExp(`^${out}$`);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 路径要不要搜:
|
|
64
|
+
* - 带 `/` 的模式匹配整条相对路径(`src/**\/*.ts`);
|
|
65
|
+
* - 不带的只看文件名(`*.ts` = 所有 ts),这是最常用的一种;
|
|
66
|
+
* - 一个通配符都没有的纯词按「包含」处理(`ts` → `*ts*`),省得人人先学 glob。
|
|
67
|
+
*/
|
|
68
|
+
export function matchesGlob(path, glob) {
|
|
69
|
+
const pattern = glob.trim();
|
|
70
|
+
if (pattern === "")
|
|
71
|
+
return true;
|
|
72
|
+
const effective = /[*?]/.test(pattern) ? pattern : `*${pattern}*`;
|
|
73
|
+
const regex = globToRegExp(effective);
|
|
74
|
+
if (!regex)
|
|
75
|
+
return true;
|
|
76
|
+
const target = effective.includes("/") ? path : path.slice(path.lastIndexOf("/") + 1);
|
|
77
|
+
return regex.test(target);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 把一行文本裁成「看得见命中」的一段。
|
|
81
|
+
* 长行(压缩过的 JSON 之类)从命中前留 40 字开始截 —— 只留开头的话,命中在 3000 列就白截了。
|
|
82
|
+
*/
|
|
83
|
+
export function lineWindow(raw, at) {
|
|
84
|
+
const trimmed = raw.replace(/\s+$/, "");
|
|
85
|
+
// 行首缩进也算「有效内容」:从行首开始截时保持原样(缩进很有信息量),但命中离行首太远就平移窗口
|
|
86
|
+
const lead = trimmed.length - trimmed.trimStart().length;
|
|
87
|
+
let start = 0;
|
|
88
|
+
if (trimmed.length - lead > GREP_LINE_CHARS)
|
|
89
|
+
start = Math.max(lead, Math.min(at - 40, trimmed.length - GREP_LINE_CHARS));
|
|
90
|
+
return { text: trimmed.slice(start, start + GREP_LINE_CHARS), column: Math.max(0, at - start) };
|
|
91
|
+
}
|
|
92
|
+
/** 扫一个文件:返回它里面所有命中的行(每行一条) */
|
|
93
|
+
async function scanFile(absPath, relPath, needleLower, maxResults) {
|
|
94
|
+
try {
|
|
95
|
+
const info = await stat(absPath);
|
|
96
|
+
if (!info.isFile() || info.size === 0 || info.size > GREP_MAX_FILE_BYTES)
|
|
97
|
+
return [];
|
|
98
|
+
const buffer = await readFile(absPath);
|
|
99
|
+
// 二进制(含 NUL 字节)直接跳过:图片 / 压缩包 / 编译产物
|
|
100
|
+
if (buffer.includes(0))
|
|
101
|
+
return [];
|
|
102
|
+
const lines = buffer.toString("utf8").split(/\r?\n/);
|
|
103
|
+
const found = [];
|
|
104
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
105
|
+
if (found.length >= maxResults)
|
|
106
|
+
break;
|
|
107
|
+
const raw = lines[index];
|
|
108
|
+
const at = raw.toLowerCase().indexOf(needleLower);
|
|
109
|
+
if (at < 0)
|
|
110
|
+
continue;
|
|
111
|
+
const { text, column } = lineWindow(raw, at);
|
|
112
|
+
found.push({ path: relPath, line: index + 1, text, column });
|
|
113
|
+
}
|
|
114
|
+
return found;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return []; // 没权限 / 刚被删:跳过,不因为一个文件中断整次搜索
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export async function searchFileContents(root, query, options = {}) {
|
|
121
|
+
const needle = query.trim();
|
|
122
|
+
if (needle === "")
|
|
123
|
+
return { ok: true, matches: [], files: 0, truncated: false };
|
|
124
|
+
const needleLower = needle.toLowerCase();
|
|
125
|
+
const glob = options.glob ?? "";
|
|
126
|
+
const maxResults = options.maxResults ?? GREP_MAX_RESULTS;
|
|
127
|
+
const maxFiles = options.maxFiles ?? GREP_MAX_FILES;
|
|
128
|
+
const matches = [];
|
|
129
|
+
let files = 0;
|
|
130
|
+
let truncated = false;
|
|
131
|
+
/** 广度优先:浅层的文件先出结果,界面看起来「立刻就动了」 */
|
|
132
|
+
const walk = async (dir, relPath, depth) => {
|
|
133
|
+
if (depth > GREP_MAX_DEPTH || matches.length >= maxResults)
|
|
134
|
+
return;
|
|
135
|
+
let items;
|
|
136
|
+
try {
|
|
137
|
+
items = await readdir(dir, { withFileTypes: true });
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const dirs = [];
|
|
143
|
+
for (const item of items) {
|
|
144
|
+
if (isIgnoredEntry(item.name))
|
|
145
|
+
continue;
|
|
146
|
+
// 符号链接不跟:可能指回上层成环,也可能指到工作区外面去
|
|
147
|
+
if (item.isSymbolicLink())
|
|
148
|
+
continue;
|
|
149
|
+
const childRel = toPosixPath(relPath === "" ? item.name : `${relPath}/${item.name}`);
|
|
150
|
+
if (item.isDirectory()) {
|
|
151
|
+
dirs.push({ path: join(dir, item.name), rel: childRel });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (!item.isFile())
|
|
155
|
+
continue;
|
|
156
|
+
if (!matchesGlob(childRel, glob))
|
|
157
|
+
continue;
|
|
158
|
+
if (files >= maxFiles) {
|
|
159
|
+
truncated = true;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
files += 1;
|
|
163
|
+
const found = await scanFile(join(dir, item.name), childRel, needleLower, maxResults - matches.length);
|
|
164
|
+
matches.push(...found);
|
|
165
|
+
if (matches.length >= maxResults) {
|
|
166
|
+
truncated = true;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const child of dirs) {
|
|
171
|
+
await walk(child.path, child.rel, depth + 1);
|
|
172
|
+
if (matches.length >= maxResults) {
|
|
173
|
+
truncated = true;
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
try {
|
|
179
|
+
await walk(root, "", 0);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
183
|
+
}
|
|
184
|
+
// 排序:先按路径(跟文件树一个方向),再按行号 —— 同一文件的结果聚在一起才好读
|
|
185
|
+
matches.sort((a, b) => (a.path === b.path ? a.line - b.line : a.path < b.path ? -1 : 1));
|
|
186
|
+
return { ok: true, matches: matches.slice(0, maxResults), files, truncated };
|
|
187
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 目录浏览(「新建项目」用):**只读列目录**,不创建、不删除任何东西。
|
|
3
|
+
*
|
|
4
|
+
* 与文件面板的区别:这里要能走出当前工作区(新建项目就是要在别处选目录),
|
|
5
|
+
* 所以只做「绝对路径 + 存在 + 是目录」的校验,且只返回**目录名**(不返回文件、不返回内容)。
|
|
6
|
+
*/
|
|
7
|
+
import { realpathSync, statSync } from "node:fs";
|
|
8
|
+
import { readdir, stat } from "node:fs/promises";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
11
|
+
import { isIgnoredEntry } from "./file-service.js";
|
|
12
|
+
import { normalizePathInput } from "../util/paths.js";
|
|
13
|
+
/**
|
|
14
|
+
* Windows 上的盘符列表(`C:` → `C:\`)。
|
|
15
|
+
*
|
|
16
|
+
* 为什么必须有:Windows 没有 `/` 这种唯一的树根 —— 到了 `C:\` 就**上不去了**,
|
|
17
|
+
* 用户想选 `D:\code` 时界面里根本没有入口(`/api/fs/dirs` 的「上级目录」在盘根是 null)。
|
|
18
|
+
* 其它平台返回空数组,前端只在非空时显示这一行。
|
|
19
|
+
*/
|
|
20
|
+
function windowsDrives() {
|
|
21
|
+
if (process.platform !== "win32")
|
|
22
|
+
return [];
|
|
23
|
+
const drives = [];
|
|
24
|
+
for (let code = "A".charCodeAt(0); code <= "Z".charCodeAt(0); code += 1) {
|
|
25
|
+
const name = `${String.fromCharCode(code)}:`;
|
|
26
|
+
try {
|
|
27
|
+
// 没插盘的 A:/B:、断开映射的网络盘会抛错 —— 跳过,不要让一个坏盘拖垮整个列表
|
|
28
|
+
if (statSync(`${name}\\`).isDirectory())
|
|
29
|
+
drives.push({ name, path: `${name}\\` });
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
/* 没有这个盘 */
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return drives;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 这一个条目是不是「能进去的目录」。
|
|
39
|
+
*
|
|
40
|
+
* Windows 上的 junction(`C:\Users\x\Application Data`、`Documents and Settings`)
|
|
41
|
+
* 和目录符号链接在 `Dirent` 里是 **symlink 而不是 directory** —— 只看 `isDirectory()`
|
|
42
|
+
* 会把它们从列表里吞掉;而这类目录恰好是用户目录下最常见的跳转点。
|
|
43
|
+
* 只有遇到 symlink 才多一次 `stat`,普通目录零成本。
|
|
44
|
+
*/
|
|
45
|
+
async function isDirectoryEntry(parent, item) {
|
|
46
|
+
if (item.isDirectory())
|
|
47
|
+
return true;
|
|
48
|
+
if (!item.isSymbolicLink())
|
|
49
|
+
return false;
|
|
50
|
+
try {
|
|
51
|
+
return (await stat(join(parent, item.name))).isDirectory();
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// 断链 / 没权限:当作不可进入
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function registerDirRoutes(app, options) {
|
|
59
|
+
app.get("/api/fs/dirs", async (request, response) => {
|
|
60
|
+
// 用户可能是「复制文件地址」粘贴进来的(带引号)、或只写了 `C:` —— 先归一化再判断。
|
|
61
|
+
const asked = typeof request.query.path === "string" ? normalizePathInput(request.query.path) : "";
|
|
62
|
+
// 显式给了路径但不是绝对路径:**说清楚**,不要静默回落成当前工作区
|
|
63
|
+
// (以前的表现就是「跳转按了没反应」,用户以为坏了)
|
|
64
|
+
if (asked !== "" && !isAbsolute(asked)) {
|
|
65
|
+
response.status(400).json({
|
|
66
|
+
error: { code: "fs.not_absolute", message: `请输入绝对路径(例如 C:\\Users\\你的用户名):${asked}` },
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const raw = asked !== "" ? asked : (options.workspaceOf() ?? homedir());
|
|
71
|
+
let real;
|
|
72
|
+
try {
|
|
73
|
+
real = realpathSync(raw);
|
|
74
|
+
if (!statSync(real).isDirectory())
|
|
75
|
+
throw new Error("not a directory");
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
response.status(400).json({ error: { code: "fs.bad_path", message: "不是可用的目录" } });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let entries = [];
|
|
82
|
+
try {
|
|
83
|
+
const items = await readdir(real, { withFileTypes: true });
|
|
84
|
+
const visible = items.filter((item) => !item.name.startsWith(".") && !isIgnoredEntry(item.name));
|
|
85
|
+
const checks = await Promise.all(visible.map((item) => isDirectoryEntry(real, item)));
|
|
86
|
+
entries = visible
|
|
87
|
+
.filter((_item, index) => checks[index] === true)
|
|
88
|
+
.map((item) => ({ name: item.name, path: join(real, item.name) }))
|
|
89
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
90
|
+
.slice(0, 500);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
response.status(403).json({ error: { code: "fs.unreadable", message: "这个目录读不了(权限)" } });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
response.json({
|
|
97
|
+
path: real,
|
|
98
|
+
parent: real === dirname(real) ? null : dirname(real),
|
|
99
|
+
entries,
|
|
100
|
+
// 盘根处「上级目录」是 null,切盘只能靠这一行(非 Windows 平台上是空数组)
|
|
101
|
+
drives: windowsDrives(),
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件名搜索(文件管理标题栏的放大镜)。
|
|
3
|
+
*
|
|
4
|
+
* 只按**文件名**匹配(不做内容搜索:那是 grep 的活,也不该把大仓库全读一遍)。
|
|
5
|
+
* 约束:只在工作区根内、跳过 node_modules/.git 等重目录、深度与结果数都有上限 ——
|
|
6
|
+
* 单用户工作台里「点了没反应」比「慢一点」更难受,所以宁可少返回也要快。
|
|
7
|
+
*/
|
|
8
|
+
import { readdir } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { toPosixPath } from "../util/paths.js";
|
|
11
|
+
import { isIgnoredEntry } from "./file-service.js";
|
|
12
|
+
const SEARCH_MAX_RESULTS = 200;
|
|
13
|
+
const SEARCH_MAX_DEPTH = 8;
|
|
14
|
+
/** 纯函数:名字是否命中(大小写不敏感的包含匹配) */
|
|
15
|
+
function matchesQuery(name, query) {
|
|
16
|
+
return name.toLowerCase().includes(query.toLowerCase());
|
|
17
|
+
}
|
|
18
|
+
export async function searchFiles(root, query, options = {}) {
|
|
19
|
+
const needle = query.trim();
|
|
20
|
+
if (needle === "")
|
|
21
|
+
return { ok: true, entries: [], truncated: false };
|
|
22
|
+
const maxResults = options.maxResults ?? SEARCH_MAX_RESULTS;
|
|
23
|
+
const maxDepth = options.maxDepth ?? SEARCH_MAX_DEPTH;
|
|
24
|
+
const found = [];
|
|
25
|
+
let truncated = false;
|
|
26
|
+
/** 广度优先一层层扫:先命中的是浅层文件,视觉上更符合预期 */
|
|
27
|
+
const walk = async (dir, relPath, depth) => {
|
|
28
|
+
if (depth > maxDepth || found.length >= maxResults) {
|
|
29
|
+
truncated ||= found.length >= maxResults;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
let items;
|
|
33
|
+
try {
|
|
34
|
+
items = await readdir(dir, { withFileTypes: true });
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return; // 没权限 / 刚被删:跳过
|
|
38
|
+
}
|
|
39
|
+
const dirs = [];
|
|
40
|
+
for (const item of items) {
|
|
41
|
+
if (isIgnoredEntry(item.name))
|
|
42
|
+
continue;
|
|
43
|
+
if (found.length >= maxResults) {
|
|
44
|
+
truncated = true;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const childPath = join(dir, item.name);
|
|
48
|
+
const childRel = toPosixPath(join(relPath, item.name));
|
|
49
|
+
if (item.isDirectory())
|
|
50
|
+
dirs.push({ path: childPath, rel: childRel });
|
|
51
|
+
if (matchesQuery(item.name, needle))
|
|
52
|
+
found.push({ name: item.name, path: childRel, isDir: item.isDirectory() });
|
|
53
|
+
}
|
|
54
|
+
for (const dir2 of dirs)
|
|
55
|
+
await walk(dir2.path, dir2.rel, depth + 1);
|
|
56
|
+
};
|
|
57
|
+
try {
|
|
58
|
+
await walk(root, "", 0);
|
|
59
|
+
return { ok: true, entries: found, truncated };
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
63
|
+
}
|
|
64
|
+
}
|