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,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件浏览与只读预览(M4)——服务端。
|
|
3
|
+
*
|
|
4
|
+
* 三条硬约束:
|
|
5
|
+
* 1. **只能看当前项目内**(ADR-0006):所有路径 `realpath` 后必须落在工作区根内;
|
|
6
|
+
* 2. **懒加载**:列目录只列一层(91 个会话那种大目录也不卡);
|
|
7
|
+
* 3. **有上限**:预览只读前 N 字节,二进制给「不可预览」而不是塞满界面。
|
|
8
|
+
*/
|
|
9
|
+
import { realpathSync } from "node:fs";
|
|
10
|
+
import { open, readFile, readdir, stat } from "node:fs/promises";
|
|
11
|
+
import { isAbsolute, join } from "node:path";
|
|
12
|
+
import { resolveInsideRoot, toPosixPath } from "../util/paths.js";
|
|
13
|
+
const MAX_PREVIEW_BYTES = 512 * 1024;
|
|
14
|
+
/**
|
|
15
|
+
* 默认不列的目录/文件(依赖与构建产物不该占满文件树)。
|
|
16
|
+
*
|
|
17
|
+
* **全部存小写**:Windows 文件系统不区分大小写,`Node_Modules` 与 `node_modules` 是同一个目录,
|
|
18
|
+
* 用原大小写去 `has()` 会让这些目录在 Windows 上照常出现(树被撑大、搜索变慢)。
|
|
19
|
+
* 后半段是 Windows 的目录噪音:资源管理器默认隐藏,我们不隐藏就会看到一片 `$RECYCLE.BIN` 之类。
|
|
20
|
+
*/
|
|
21
|
+
export const IGNORED_ENTRIES = new Set([
|
|
22
|
+
"node_modules",
|
|
23
|
+
".git",
|
|
24
|
+
"dist",
|
|
25
|
+
"coverage",
|
|
26
|
+
".next",
|
|
27
|
+
"target",
|
|
28
|
+
// Windows:系统/隐藏噪聲(dotfile 那套约定在那边不适用)
|
|
29
|
+
"desktop.ini",
|
|
30
|
+
"thumbs.db",
|
|
31
|
+
"$recycle.bin",
|
|
32
|
+
"system volume information",
|
|
33
|
+
"pagefile.sys",
|
|
34
|
+
"hiberfil.sys",
|
|
35
|
+
"swapfile.sys",
|
|
36
|
+
"dumpstack.log.tmp",
|
|
37
|
+
"$winreagent",
|
|
38
|
+
"recovery",
|
|
39
|
+
]);
|
|
40
|
+
/** 纯函数:这个条目名是否该被忽略(大小写无关) */
|
|
41
|
+
export function isIgnoredEntry(name) {
|
|
42
|
+
return IGNORED_ENTRIES.has(name.toLowerCase());
|
|
43
|
+
}
|
|
44
|
+
/** 目录里最多列多少项(防止某个目录把界面撑爆) */
|
|
45
|
+
const MAX_DIR_ENTRIES = 500;
|
|
46
|
+
/** 纯函数:按「目录优先、同类按名字」排序(与常见文件树一致) */
|
|
47
|
+
function sortEntries(entries) {
|
|
48
|
+
return [...entries].sort((a, b) => (a.isDir === b.isDir ? a.name.localeCompare(b.name) : a.isDir ? -1 : 1));
|
|
49
|
+
}
|
|
50
|
+
/** 纯函数:看起来像文本吗(NUL 字节 = 二进制;常见图片扩展名直接判二进制) */
|
|
51
|
+
function looksBinary(bytes, name) {
|
|
52
|
+
if (/\.(png|jpe?g|gif|webp|ico|pdf|zip|gz|tar|exe|dylib|so|woff2?|ttf|mp4|mp3|wav)$/i.test(name))
|
|
53
|
+
return true;
|
|
54
|
+
const sample = bytes.subarray(0, 4096);
|
|
55
|
+
for (const byte of sample)
|
|
56
|
+
if (byte === 0)
|
|
57
|
+
return true;
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 列一层目录。
|
|
62
|
+
*
|
|
63
|
+
* `showHidden` 控制**点开头的隐藏文件**(.env / .github 之类):默认只放行 .gitignore 与 .env.example
|
|
64
|
+
* (它们是项目说明的一部分),需要时由界面的「眼睛」按钮显式打开。
|
|
65
|
+
* `node_modules` / `dist` 这类永远不列(ADR:依赖与构建产物不该占满文件树)。
|
|
66
|
+
*/
|
|
67
|
+
export async function listDirectory(root, relPath, options = {}) {
|
|
68
|
+
const target = relPath === "" ? root : join(root, relPath);
|
|
69
|
+
const safe = resolveInsideRoot(root, target, realpathSync);
|
|
70
|
+
if (!safe.ok)
|
|
71
|
+
return { ok: false, error: safe.reason };
|
|
72
|
+
try {
|
|
73
|
+
const items = await readdir(safe.path, { withFileTypes: true });
|
|
74
|
+
const entries = items
|
|
75
|
+
.filter((item) => !isIgnoredEntry(item.name))
|
|
76
|
+
.filter((item) => options.showHidden === true ||
|
|
77
|
+
!item.name.startsWith(".") ||
|
|
78
|
+
item.name === ".gitignore" ||
|
|
79
|
+
item.name === ".env.example")
|
|
80
|
+
.map((item) => ({ name: item.name, path: toPosixPath(join(relPath, item.name)), isDir: item.isDirectory() }));
|
|
81
|
+
return {
|
|
82
|
+
ok: true,
|
|
83
|
+
root,
|
|
84
|
+
path: toPosixPath(relPath),
|
|
85
|
+
entries: sortEntries(entries).slice(0, MAX_DIR_ENTRIES),
|
|
86
|
+
truncated: entries.length > MAX_DIR_ENTRIES,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export async function readPreview(root, relPath, limit = MAX_PREVIEW_BYTES) {
|
|
94
|
+
/**
|
|
95
|
+
* 绝对路径:模型/工具给出的**真实地址**(正文里常只写文件名,点开时已经换回绝对路径),
|
|
96
|
+
* 直接按它读。相对路径仍必须落在工作区内(ADR-0006:realpath 之后在根内)。
|
|
97
|
+
* 工作区外的绝对路径放行与 `readRaw` 对 `/tmp` 截图的放行同口径 —— 单用户工作台的边界是**只读**,
|
|
98
|
+
* 而「点了模型刚读过的那个文件」本身就已经是用户的明确意图。
|
|
99
|
+
*/
|
|
100
|
+
let filePath;
|
|
101
|
+
if (isAbsolute(relPath)) {
|
|
102
|
+
try {
|
|
103
|
+
filePath = realpathSync(relPath);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return { ok: false, error: `路径不存在或无法解析:${relPath}` };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const safe = resolveInsideRoot(root, join(root, relPath), realpathSync);
|
|
111
|
+
if (!safe.ok)
|
|
112
|
+
return { ok: false, error: safe.reason };
|
|
113
|
+
filePath = safe.path;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
const info = await stat(filePath);
|
|
117
|
+
if (info.isDirectory())
|
|
118
|
+
return { ok: false, error: "这是一个目录" };
|
|
119
|
+
// 只读前 limit 字节:以前是 readFile 全读进来再截断(工作区里一个几 GB 的日志
|
|
120
|
+
// 就能把进程内存打爆),512KB 的上限等于没设。
|
|
121
|
+
const size = info.size;
|
|
122
|
+
const take = Math.min(size, limit);
|
|
123
|
+
const handle = await open(filePath, "r");
|
|
124
|
+
let bytes;
|
|
125
|
+
try {
|
|
126
|
+
bytes = Buffer.alloc(take);
|
|
127
|
+
if (take > 0)
|
|
128
|
+
await handle.read(bytes, 0, take, 0);
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
await handle.close();
|
|
132
|
+
}
|
|
133
|
+
const binary = looksBinary(bytes, filePath);
|
|
134
|
+
return {
|
|
135
|
+
ok: true,
|
|
136
|
+
path: relPath,
|
|
137
|
+
text: binary ? "" : bytes.toString("utf8"),
|
|
138
|
+
bytes: size,
|
|
139
|
+
truncated: size > limit,
|
|
140
|
+
binary,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** 允许直接当图片/文档发给浏览器的扩展名(其余一律拒绝,避免变成任意文件下载器) */
|
|
148
|
+
const RAW_MIME = {
|
|
149
|
+
png: "image/png",
|
|
150
|
+
jpg: "image/jpeg",
|
|
151
|
+
jpeg: "image/jpeg",
|
|
152
|
+
gif: "image/gif",
|
|
153
|
+
webp: "image/webp",
|
|
154
|
+
avif: "image/avif",
|
|
155
|
+
svg: "image/svg+xml",
|
|
156
|
+
ico: "image/x-icon",
|
|
157
|
+
bmp: "image/bmp",
|
|
158
|
+
pdf: "application/pdf",
|
|
159
|
+
// html 报告(agent 生成的「报告」多是单文件 html):预览面板要能把**页面**渲染出来。
|
|
160
|
+
// 只放行 html/htm:JS/CSS 不额外开口子,报告自己内联;外链走网络。
|
|
161
|
+
html: "text/html; charset=utf-8",
|
|
162
|
+
htm: "text/html; charset=utf-8",
|
|
163
|
+
};
|
|
164
|
+
/** 图片原始大小上限(超过就拒绝,别让浏览器卡死) */
|
|
165
|
+
const MAX_RAW_BYTES = 20 * 1024 * 1024;
|
|
166
|
+
/** 纯函数:按扩展名给 Content-Type(不在白名单里返回空串 = 拒绝) */
|
|
167
|
+
function mimeOf(path) {
|
|
168
|
+
const extension = path.split(".").pop()?.toLowerCase() ?? "";
|
|
169
|
+
return RAW_MIME[extension] ?? "";
|
|
170
|
+
}
|
|
171
|
+
/** 读取图片原始字节(markdown 里 \`\` 能直接显示的关键一环) */
|
|
172
|
+
export async function readRaw(root, relPath) {
|
|
173
|
+
const mime = mimeOf(relPath);
|
|
174
|
+
if (mime === "")
|
|
175
|
+
return { ok: false, error: `不支持的文件类型:${relPath.split(".").pop() ?? "无扩展名"}` };
|
|
176
|
+
// 绝对路径(agent 把截图写到 /tmp/x.png 这种):只做「存在 + 是文件 + 类型白名单」,
|
|
177
|
+
// 不做工作区包含 —— 否则模型刚生成的图在对话里就看不见。相对路径仍限制在工作区内。
|
|
178
|
+
let safe;
|
|
179
|
+
try {
|
|
180
|
+
safe = isAbsolute(relPath)
|
|
181
|
+
? { ok: true, path: realpathSync(relPath) }
|
|
182
|
+
: resolveInsideRoot(root, join(root, relPath), realpathSync);
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
186
|
+
}
|
|
187
|
+
if (!safe.ok)
|
|
188
|
+
return { ok: false, error: safe.reason };
|
|
189
|
+
try {
|
|
190
|
+
const info = await stat(safe.path);
|
|
191
|
+
if (info.isDirectory())
|
|
192
|
+
return { ok: false, error: "这是一个目录" };
|
|
193
|
+
if (info.size > MAX_RAW_BYTES)
|
|
194
|
+
return { ok: false, error: "文件太大(上限 20MB)", tooLarge: true };
|
|
195
|
+
return { ok: true, bytes: await readFile(safe.path), mime };
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// ---------------------------------------------------------------------------
|
|
202
|
+
// 视频 / 音频:走「流 + Range」,不整块读进内存(大文件也能拖动进度条)
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
/** 允许内联播放的媒体类型(白名单之外的扩展名一律拒绝) */
|
|
205
|
+
const MEDIA_MIME = {
|
|
206
|
+
mp4: "video/mp4",
|
|
207
|
+
m4v: "video/mp4",
|
|
208
|
+
webm: "video/webm",
|
|
209
|
+
ogv: "video/ogg",
|
|
210
|
+
mov: "video/quicktime",
|
|
211
|
+
mkv: "video/x-matroska",
|
|
212
|
+
mp3: "audio/mpeg",
|
|
213
|
+
m4a: "audio/mp4",
|
|
214
|
+
aac: "audio/aac",
|
|
215
|
+
wav: "audio/wav",
|
|
216
|
+
ogg: "audio/ogg",
|
|
217
|
+
opus: "audio/opus",
|
|
218
|
+
flac: "audio/flac",
|
|
219
|
+
};
|
|
220
|
+
/** 纯函数:媒体扩展名 → Content-Type(不是媒体返回空串) */
|
|
221
|
+
function mediaMimeOf(path) {
|
|
222
|
+
const extension = path.split(".").pop()?.toLowerCase() ?? "";
|
|
223
|
+
return MEDIA_MIME[extension] ?? "";
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 解析一个可播放的媒体文件:校验路径(与 readRaw 同规矩)、类型白名单、大小上限。
|
|
227
|
+
* 只 stat,不读内容 —— 真正的字节由路由用 createReadStream + Range 流出去。
|
|
228
|
+
*/
|
|
229
|
+
export async function resolveMediaFile(root, relPath) {
|
|
230
|
+
const mime = mediaMimeOf(relPath);
|
|
231
|
+
if (mime === "")
|
|
232
|
+
return { ok: false, error: `不支持的媒体类型:${relPath.split(".").pop() ?? "无扩展名"}` };
|
|
233
|
+
let safePath;
|
|
234
|
+
try {
|
|
235
|
+
safePath = isAbsolute(relPath) ? realpathSync(relPath) : "";
|
|
236
|
+
if (safePath === "") {
|
|
237
|
+
const safe = resolveInsideRoot(root, join(root, relPath), realpathSync);
|
|
238
|
+
if (!safe.ok)
|
|
239
|
+
return { ok: false, error: safe.reason };
|
|
240
|
+
safePath = safe.path;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const info = await stat(safePath);
|
|
248
|
+
if (info.isDirectory())
|
|
249
|
+
return { ok: false, error: "这是一个目录" };
|
|
250
|
+
if (info.size > MAX_MEDIA_BYTES)
|
|
251
|
+
return { ok: false, error: "文件太大(上限 4GB)", tooLarge: true };
|
|
252
|
+
return { ok: true, path: safePath, size: info.size, mime };
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/** 媒体文件大小上限:4GB(流式发送,不会占内存;只是别把「伪装的巨型文件」当视频播) */
|
|
259
|
+
const MAX_MEDIA_BYTES = 4 * 1024 * 1024 * 1024;
|
|
260
|
+
/** 纯函数:解析 Range 头(只认单段 `bytes=a-b`),返回闭区间;无效返回 null(按整文件发) */
|
|
261
|
+
export function parseRange(header, size) {
|
|
262
|
+
if (!header)
|
|
263
|
+
return null;
|
|
264
|
+
// 空文件:下面两个分支都会算出 `end: -1`,传给 createReadStream 会同步抛 ERR_OUT_OF_RANGE
|
|
265
|
+
// (那时响应头已发出,连接直接被掐断)—— 直接当作「没范围」按整文件发
|
|
266
|
+
if (size <= 0)
|
|
267
|
+
return null;
|
|
268
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
269
|
+
if (!match)
|
|
270
|
+
return null;
|
|
271
|
+
const [, rawStart, rawEnd] = match;
|
|
272
|
+
if (rawStart === "" && rawEnd === "")
|
|
273
|
+
return null;
|
|
274
|
+
if (rawStart === "") {
|
|
275
|
+
// 后缀写法:bytes=-N → 最后 N 字节
|
|
276
|
+
const length = Number(rawEnd);
|
|
277
|
+
if (!Number.isFinite(length) || length <= 0)
|
|
278
|
+
return null;
|
|
279
|
+
return { start: Math.max(0, size - length), end: size - 1 };
|
|
280
|
+
}
|
|
281
|
+
const start = Number(rawStart);
|
|
282
|
+
const end = rawEnd === "" ? size - 1 : Number(rawEnd);
|
|
283
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start > end)
|
|
284
|
+
return null;
|
|
285
|
+
return { start: Math.min(start, size - 1), end: Math.min(end, size - 1) };
|
|
286
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件浏览的 HTTP 路由(M4)——从 index.ts 抽出(400 行护栏)。
|
|
3
|
+
*
|
|
4
|
+
* `GET /api/files/list?path=<相对路径>` → 列一层目录(懒惰展开)
|
|
5
|
+
* `GET /api/files/read?path=<相对路径>` → 只读预览(≤512KB,二进制给标记)
|
|
6
|
+
*
|
|
7
|
+
* `workspaceOf()` 返回**当前会话**的工作区(多项目:文件树跟着当前会话走,ADR-0021 §3)。
|
|
8
|
+
*/
|
|
9
|
+
import { createReadStream, realpathSync, statSync } from "node:fs";
|
|
10
|
+
import { isAbsolute } from "node:path";
|
|
11
|
+
import { listDirectory, parseRange, readPreview, readRaw, resolveMediaFile } from "./file-service.js";
|
|
12
|
+
import { resolveTarget } from "./path-resolve.js";
|
|
13
|
+
import { applyFileResponseHeaders, filenameOf } from "../http/file-headers.js";
|
|
14
|
+
import { searchFiles } from "./file-search.js";
|
|
15
|
+
import { searchFileContents } from "./content-search.js";
|
|
16
|
+
import { checkoutBranch, readFileDiff, readFileStatuses, readGitBranches } from "./git-info.js";
|
|
17
|
+
export function registerFileRoutes(app, options) {
|
|
18
|
+
app.get("/api/files/list", async (request, response) => {
|
|
19
|
+
const root = rootOf(request.query.root, options.workspaceOf());
|
|
20
|
+
if (!root) {
|
|
21
|
+
response
|
|
22
|
+
.status(409)
|
|
23
|
+
.json({ error: { code: "files.no_workspace", message: "还没有打开会话(不知道是哪个项目)" } });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const relPath = typeof request.query.path === "string" ? request.query.path : "";
|
|
27
|
+
// 隐藏文件由界面的「眼睛」按钮显式打开(?hidden=1)
|
|
28
|
+
const result = await listDirectory(root, relPath, { showHidden: request.query.hidden === "1" });
|
|
29
|
+
if (!result.ok) {
|
|
30
|
+
response.status(400).json({ error: { code: "files.list_failed", message: result.error } });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
response.json(result);
|
|
34
|
+
});
|
|
35
|
+
// markdown 图片用:直接回字节(只放行图片/PDF 白名单,仍受工作区约束)
|
|
36
|
+
app.get("/api/files/raw", async (request, response) => {
|
|
37
|
+
const root = rootOf(request.query.root, options.workspaceOf());
|
|
38
|
+
if (!root) {
|
|
39
|
+
response
|
|
40
|
+
.status(409)
|
|
41
|
+
.json({ error: { code: "files.no_workspace", message: "还没有打开会话(不知道是哪个项目)" } });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const relPath = typeof request.query.path === "string" ? request.query.path : "";
|
|
45
|
+
const rawPath = await resolveMediaPath(root, relPath);
|
|
46
|
+
const result = await readRaw(root, rawPath);
|
|
47
|
+
if (!result.ok) {
|
|
48
|
+
response.status(result.tooLarge ? 413 : 400).json({ error: { code: "files.raw_failed", message: result.error } });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
response.setHeader("Content-Type", result.mime);
|
|
52
|
+
response.setHeader("Cache-Control", "private, max-age=60");
|
|
53
|
+
// ADR-0042:nosniff 始终加;html/svg 在**顶层导航**时转成下载(页面内嵌的 iframe 照旧)
|
|
54
|
+
applyFileResponseHeaders(request.headers, response, { mime: result.mime, filename: filenameOf(rawPath) });
|
|
55
|
+
response.send(result.bytes);
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* 视频 / 音频:**流式 + Range**(拖动进度条、边下边播都靠它)。
|
|
59
|
+
* 只让白名单里的媒体类型通过;大小上限 4GB;路径同样受工作区约束。
|
|
60
|
+
*/
|
|
61
|
+
app.get("/api/files/media", async (request, response) => {
|
|
62
|
+
const root = rootOf(request.query.root, options.workspaceOf());
|
|
63
|
+
if (!root) {
|
|
64
|
+
response
|
|
65
|
+
.status(409)
|
|
66
|
+
.json({ error: { code: "files.no_workspace", message: "还没有打开会话(不知道是哪个项目)" } });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const relPath = typeof request.query.path === "string" ? request.query.path : "";
|
|
70
|
+
const resolvedMediaPath = await resolveMediaPath(root, relPath);
|
|
71
|
+
const file = await resolveMediaFile(root, resolvedMediaPath);
|
|
72
|
+
if (!file.ok) {
|
|
73
|
+
response.status(file.tooLarge ? 413 : 400).json({ error: { code: "files.media_failed", message: file.error } });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const range = parseRange(request.headers.range, file.size);
|
|
77
|
+
response.setHeader("Content-Type", file.mime);
|
|
78
|
+
response.setHeader("Accept-Ranges", "bytes");
|
|
79
|
+
response.setHeader("Cache-Control", "private, max-age=600");
|
|
80
|
+
// 媒体类型不是主动内容,这行只会加 nosniff(ADR-0042)
|
|
81
|
+
applyFileResponseHeaders(request.headers, response, { mime: file.mime, filename: filenameOf(resolvedMediaPath) });
|
|
82
|
+
if (range) {
|
|
83
|
+
response.status(206);
|
|
84
|
+
response.setHeader("Content-Range", `bytes ${range.start}-${range.end}/${file.size}`);
|
|
85
|
+
response.setHeader("Content-Length", String(range.end - range.start + 1));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
response.setHeader("Content-Length", String(file.size));
|
|
89
|
+
}
|
|
90
|
+
if (request.method === "HEAD") {
|
|
91
|
+
response.end();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
createReadStream(file.path, range ? { start: range.start, end: range.end } : undefined)
|
|
95
|
+
.on("error", () => response.destroy())
|
|
96
|
+
.pipe(response);
|
|
97
|
+
});
|
|
98
|
+
/** 文件名搜索(放大镜):只匹配名字,不做内容搜索 */
|
|
99
|
+
app.get("/api/files/search", async (request, response) => {
|
|
100
|
+
const root = rootOf(request.query.root, options.workspaceOf());
|
|
101
|
+
if (!root) {
|
|
102
|
+
response
|
|
103
|
+
.status(409)
|
|
104
|
+
.json({ error: { code: "files.no_workspace", message: "还没有打开会话(不知道是哪个项目)" } });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const query = typeof request.query.q === "string" ? request.query.q : "";
|
|
108
|
+
const result = await searchFiles(root, query);
|
|
109
|
+
if (!result.ok) {
|
|
110
|
+
response.status(400).json({ error: { code: "files.search_failed", message: result.error } });
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
response.json(result);
|
|
114
|
+
});
|
|
115
|
+
/**
|
|
116
|
+
* 全文搜索(**文件内容**):`{ root, q, glob? }` → 命中行清单。
|
|
117
|
+
* 同名行数就是界面左侧那一排结果(行文本 + 路径:行号)。
|
|
118
|
+
* 与 `/api/files/search`(只看文件名)分两个口:一个要读字节、一个有上限,混在一起两边都不好调。
|
|
119
|
+
*/
|
|
120
|
+
app.get("/api/files/grep", async (request, response) => {
|
|
121
|
+
const root = rootOf(request.query.root, options.workspaceOf());
|
|
122
|
+
if (!root) {
|
|
123
|
+
response
|
|
124
|
+
.status(409)
|
|
125
|
+
.json({ error: { code: "files.no_workspace", message: "还没有打开会话(不知道是哪个项目)" } });
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const query = typeof request.query.q === "string" ? request.query.q : "";
|
|
129
|
+
const glob = typeof request.query.glob === "string" ? request.query.glob : "";
|
|
130
|
+
const result = await searchFileContents(root, query, { glob });
|
|
131
|
+
if (!result.ok) {
|
|
132
|
+
response.status(400).json({ error: { code: "files.grep_failed", message: result.error } });
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
response.json(result);
|
|
136
|
+
});
|
|
137
|
+
/** 当前项目的 git 信息(分支名 + 本地分支清单;不是仓库就 isRepo=false) */
|
|
138
|
+
app.get("/api/files/git", async (request, response) => {
|
|
139
|
+
const root = rootOf(request.query.root, options.workspaceOf());
|
|
140
|
+
if (!root) {
|
|
141
|
+
response.json({ isRepo: false, branch: null, branches: [] });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
response.json(await readGitBranches(root));
|
|
145
|
+
});
|
|
146
|
+
/**
|
|
147
|
+
* 切分支:`{ root, branch, force? }` → `git checkout <branch>`。
|
|
148
|
+
* 只接受**本地已有分支**;工作区有未提交改动时先 409 回一份改动清单(`files.dirty_worktree`),
|
|
149
|
+
* 界面确认后带 `force: true` 再发一次。冲突时 git 会拒绝,报错原样回给界面。
|
|
150
|
+
*/
|
|
151
|
+
app.post("/api/files/git/checkout", async (request, response) => {
|
|
152
|
+
const body = request.body;
|
|
153
|
+
const root = rootOf(body?.root, options.workspaceOf());
|
|
154
|
+
if (!root) {
|
|
155
|
+
response
|
|
156
|
+
.status(409)
|
|
157
|
+
.json({ error: { code: "files.no_workspace", message: "还没有打开会话(不知道是哪个项目)" } });
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (typeof body?.branch !== "string" || body.branch.trim() === "") {
|
|
161
|
+
response.status(400).json({ error: { code: "files.no_branch", message: "没有指定要切换的分支" } });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const result = await checkoutBranch(root, body.branch, { force: body.force === true });
|
|
165
|
+
if (!result.ok) {
|
|
166
|
+
if (result.dirty) {
|
|
167
|
+
response.status(409).json({
|
|
168
|
+
error: {
|
|
169
|
+
code: "files.dirty_worktree",
|
|
170
|
+
message: `工作区有 ${result.dirty.total} 个未提交改动`,
|
|
171
|
+
files: result.dirty.files,
|
|
172
|
+
total: result.dirty.total,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
response.status(400).json({ error: { code: "files.checkout_failed", message: result.message } });
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
response.json({ ...(await readGitBranches(root)), branch: result.branch });
|
|
181
|
+
});
|
|
182
|
+
app.get("/api/files/read", async (request, response) => {
|
|
183
|
+
const root = rootOf(request.query.root, options.workspaceOf());
|
|
184
|
+
if (!root) {
|
|
185
|
+
response
|
|
186
|
+
.status(409)
|
|
187
|
+
.json({ error: { code: "files.no_workspace", message: "还没有打开会话(不知道是哪个项目)" } });
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const relPath = typeof request.query.path === "string" ? request.query.path : "";
|
|
191
|
+
const target = await resolveTarget(root, relPath);
|
|
192
|
+
if (!target.ok) {
|
|
193
|
+
response.status(400).json({
|
|
194
|
+
error: {
|
|
195
|
+
code: "files.resolve_failed",
|
|
196
|
+
message: target.error,
|
|
197
|
+
...(target.candidates ? { candidates: target.candidates } : {}),
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const result = await readPreview(root, target.relPath);
|
|
203
|
+
if (!result.ok) {
|
|
204
|
+
response.status(400).json({ error: { code: "files.read_failed", message: result.error } });
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
// `matchedBy: "suffix"`:这条路径是「按文件名/后缀找回的」,界面得告诉用户开的是哪个文件
|
|
208
|
+
response.json(target.matchedBy ? { ...result, matchedBy: target.matchedBy } : result);
|
|
209
|
+
});
|
|
210
|
+
/** 文件树上的改动标记:每个文件的 M / A / U + 增删行数(不是仓库就 isRepo:false) */
|
|
211
|
+
app.get("/api/files/git/status", async (request, response) => {
|
|
212
|
+
const root = rootOf(request.query.root, options.workspaceOf());
|
|
213
|
+
if (!root) {
|
|
214
|
+
response.json({ isRepo: false, entries: {} });
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
response.json(await readFileStatuses(root));
|
|
218
|
+
});
|
|
219
|
+
/**
|
|
220
|
+
* 一个文件「改了什么」:工作区 vs HEAD 的 unified diff。
|
|
221
|
+
* 不是 git 仓库 / 文件没改动 → `diff: ""`,界面就不摆那个页签。
|
|
222
|
+
*/
|
|
223
|
+
app.get("/api/files/diff", async (request, response) => {
|
|
224
|
+
const root = rootOf(request.query.root, options.workspaceOf());
|
|
225
|
+
if (!root) {
|
|
226
|
+
response
|
|
227
|
+
.status(409)
|
|
228
|
+
.json({ error: { code: "files.no_workspace", message: "还没有打开会话(不知道是哪个项目)" } });
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const relPath = typeof request.query.path === "string" ? request.query.path : "";
|
|
232
|
+
if (relPath === "") {
|
|
233
|
+
response.status(400).json({ error: { code: "files.no_path", message: "没有指定文件" } });
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const target = await resolveTarget(root, relPath);
|
|
237
|
+
if (!target.ok) {
|
|
238
|
+
response.status(400).json({
|
|
239
|
+
error: {
|
|
240
|
+
code: "files.resolve_failed",
|
|
241
|
+
message: target.error,
|
|
242
|
+
...(target.candidates ? { candidates: target.candidates } : {}),
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
response.json(await readFileDiff(root, target.relPath));
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* 图片 / 视频 / 音频也吃「点开的路径」那一套:对话里点 `shot.png`、或者贴的是绝对路径。
|
|
252
|
+
*
|
|
253
|
+
* 绝对路径**不在工作区里**的照旧放行(agent 把截图写到 `/tmp` 是常态,见 `readRaw` 的注释),
|
|
254
|
+
* 所以只在「相对路径」时才走解析;解析不出来就原样交给下层 —— 错误文案与以前一致。
|
|
255
|
+
*/
|
|
256
|
+
async function resolveMediaPath(root, relPath) {
|
|
257
|
+
if (relPath.trim() === "" || isAbsolute(relPath))
|
|
258
|
+
return relPath;
|
|
259
|
+
const target = await resolveTarget(root, relPath);
|
|
260
|
+
return target.ok ? target.relPath : relPath;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* 文件根目录:默认是当前会话的工作区;「在文件中打开」某个项目时传 root 覆盖。
|
|
264
|
+
* 校验:必须是存在的目录(realpath)。不做工作区包含检查 —— 因为根目录本身就是工作区,
|
|
265
|
+
* 一旦允许换根,"包含于工作区"就退化成"包含于自己",没有意义;真正的边界是**只读**。
|
|
266
|
+
*/
|
|
267
|
+
function rootOf(raw, fallback) {
|
|
268
|
+
// isAbsolute 而不是 startsWith("/"):Windows 的 `C:\proj`、`\\server\share` 也得过
|
|
269
|
+
if (typeof raw !== "string" || !isAbsolute(raw))
|
|
270
|
+
return fallback;
|
|
271
|
+
try {
|
|
272
|
+
const real = realpathSync(raw);
|
|
273
|
+
return statSync(real).isDirectory() ? real : fallback;
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
return fallback;
|
|
277
|
+
}
|
|
278
|
+
}
|