wind-agent-cli 1.37.2 → 1.37.3
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 +718 -718
- package/README.md +1 -1
- package/dist/api-docs.html +901 -901
- package/dist/assets/{CodeEditor-B2Wf7Fg0.js → CodeEditor-BqmxpZ_D.js} +1 -1
- package/dist/assets/{FileTree-N2IkkHlv.js → FileTree-DLE7Ioai.js} +1 -1
- package/dist/assets/{GitPanel-DZCeuFZ2.js → GitPanel-f8RMRa8D.js} +1 -1
- package/dist/assets/{MarkdownPreview-C0tqYnVu.js → MarkdownPreview-93h_1tJa.js} +1 -1
- package/dist/assets/{PluginTabContent-Bnuf-fb8.js → PluginTabContent-DU1jjkXP.js} +1 -1
- package/dist/assets/{Shell-BfFnMZ-f.js → Shell-CN_2MRIM.js} +1 -1
- package/dist/assets/{StandaloneShell-QmyYwNAl.js → StandaloneShell-D0avS8UE.js} +1 -1
- package/dist/assets/{TaskMasterPanel-fMsmvN9L.js → TaskMasterPanel-Cpf1Q5Ph.js} +3 -3
- package/dist/assets/{abnfDiagram-N423BO3Z-DjPU7HLs.js → abnfDiagram-N423BO3Z-p3aJIm4T.js} +1 -1
- package/dist/assets/{arc-Pdq6Tvr3.js → arc-CTeud6Fl.js} +1 -1
- package/dist/assets/{architectureDiagram-T3A2C74G-D0JnT0Vh.js → architectureDiagram-T3A2C74G-CG7kRCJU.js} +1 -1
- package/dist/assets/{blockDiagram-VBNYF7ZC-DpaEf3mv.js → blockDiagram-VBNYF7ZC-oSjQ1SgE.js} +1 -1
- package/dist/assets/{c4Diagram-5PPSVZJV-MpqlPGFi.js → c4Diagram-5PPSVZJV-RkzF0DJV.js} +1 -1
- package/dist/assets/channel-BfQbarn9.js +1 -0
- package/dist/assets/{chunk-2GRJ4B5K-DoSdNo8u.js → chunk-2GRJ4B5K-B07uZ07O.js} +1 -1
- package/dist/assets/{chunk-2Q5K7J3B-CE7I3uMn.js → chunk-2Q5K7J3B-DNSfO7xS.js} +1 -1
- package/dist/assets/{chunk-5RXB4S5H-B4UQ8snD.js → chunk-5RXB4S5H-BTeYcgyb.js} +1 -1
- package/dist/assets/{chunk-5VM5RSS4-B55XgqHZ.js → chunk-5VM5RSS4-B7vZV0zC.js} +1 -1
- package/dist/assets/{chunk-6Q2QTUOP-BS1KpefW.js → chunk-6Q2QTUOP-DuS_xUGG.js} +1 -1
- package/dist/assets/{chunk-GF5L2VYU-DkEPedJP.js → chunk-GF5L2VYU-CKLZ3iVD.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-DOtkNhMm.js → chunk-JWPE2WC7-DD2hcXvs.js} +1 -1
- package/dist/assets/{chunk-KBJHAD2P-BXLjviqM.js → chunk-KBJHAD2P-Cz-l38qp.js} +1 -1
- package/dist/assets/{chunk-RYQCIY6F-C50fjNNz.js → chunk-RYQCIY6F-DGFIU1YM.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-QBYqCkb7.js → chunk-XXDRQBXY-CmfzoYFl.js} +1 -1
- package/dist/assets/classDiagram-JCYQIIEL-Bpfe3kq7.js +1 -0
- package/dist/assets/classDiagram-v2-OCEON4UE-Bpfe3kq7.js +1 -0
- package/dist/assets/{code-xml-VK1YfShP.js → code-xml-CLpHzEOP.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-DrVTo1Nh.js → cose-bilkent-JH36ORCC-DlFcLXCB.js} +1 -1
- package/dist/assets/{cynefin-VYW2F7L2-DnJa_OlQ.js → cynefin-VYW2F7L2-P1HecReO.js} +1 -1
- package/dist/assets/{cynefinDiagram-MW4NZA55-CCxBjw9E.js → cynefinDiagram-MW4NZA55-COgduz5P.js} +1 -1
- package/dist/assets/{dagre-VZM6K2ZE-C_GvE4lu.js → dagre-VZM6K2ZE-Bbb-siGp.js} +1 -1
- package/dist/assets/{diagram-7IWD3JNH-pFzs9HEu.js → diagram-7IWD3JNH-9CWGFMYR.js} +1 -1
- package/dist/assets/{diagram-B4RE2ZJO-CcehQC7x.js → diagram-B4RE2ZJO-TWK59T6V.js} +1 -1
- package/dist/assets/{diagram-LBJQPF4R-hfKcrrxe.js → diagram-LBJQPF4R-ErMC9yaa.js} +1 -1
- package/dist/assets/{diagram-Q27KOJAE-C1semJfK.js → diagram-Q27KOJAE-Dt_-C7hV.js} +1 -1
- package/dist/assets/{diagram-UB23O5K3-57hvXQXO.js → diagram-UB23O5K3-BJ1DnRAF.js} +1 -1
- package/dist/assets/{ebnfDiagram-BXEA7PRR-9KIAlAVw.js → ebnfDiagram-BXEA7PRR-CE1YaQ9s.js} +1 -1
- package/dist/assets/{erDiagram-JOGREHBK-B7OzJ767.js → erDiagram-JOGREHBK-Bqk7N9aY.js} +1 -1
- package/dist/assets/{flowDiagram-UKHOOZJN-CJV8fQPR.js → flowDiagram-UKHOOZJN-DEr2II5V.js} +1 -1
- package/dist/assets/{ganttDiagram-PKOTCBZU-CbMNWWQu.js → ganttDiagram-PKOTCBZU-CWYAUeYN.js} +1 -1
- package/dist/assets/{gitGraphDiagram-DS77QQ5N-I_vZ5waO.js → gitGraphDiagram-DS77QQ5N-tdEcEIM6.js} +1 -1
- package/dist/assets/{index-ZHwIojzi.js → index-B-sTfSZq.js} +1 -1
- package/dist/assets/{index-GFhXZyl2.js → index-BSe3UiFA.js} +1 -1
- package/dist/assets/{index-DFnVoqpx.js → index-B_FDMWar.js} +5 -5
- package/dist/assets/{index-DlSeAkw_.js → index-CWJtg2pR.js} +1 -1
- package/dist/assets/{infoDiagram-6WML65LV-Dh20Tsbq.js → infoDiagram-6WML65LV-A3IqRUnO.js} +1 -1
- package/dist/assets/{ishikawaDiagram-WSZJBQD7-DH2Sm3ko.js → ishikawaDiagram-WSZJBQD7-B2uL6bkK.js} +1 -1
- package/dist/assets/{journeyDiagram-NVQOT4AX-BNFQqlVu.js → journeyDiagram-NVQOT4AX-D9JB-hRW.js} +1 -1
- package/dist/assets/{kanban-definition-27J2QSJJ-B3iL0ztJ.js → kanban-definition-27J2QSJJ-DmlgiV7K.js} +1 -1
- package/dist/assets/{linear-Cwe9dEKA.js → linear-Ct_eoJQk.js} +1 -1
- package/dist/assets/{mermaid.core-BYRQSshi.js → mermaid.core-CQ698HNn.js} +5 -5
- package/dist/assets/{mindmap-definition-FAOFIHXS-BgfBYMzr.js → mindmap-definition-FAOFIHXS-DGtMgQhf.js} +1 -1
- package/dist/assets/{pegDiagram-VL7TDLO6-CNYpECr8.js → pegDiagram-VL7TDLO6-CO6vP4n9.js} +1 -1
- package/dist/assets/{pieDiagram-7S7Q4E2Y-DeSrxc4I.js → pieDiagram-7S7Q4E2Y-DMkt_Zfr.js} +1 -1
- package/dist/assets/{quadrantDiagram-CIZ2JOQS-BXVVQsa6.js → quadrantDiagram-CIZ2JOQS-DgNxRz6t.js} +1 -1
- package/dist/assets/{railroadDiagram-AXF67PYL-JTroIW8F.js → railroadDiagram-AXF67PYL-DKz9UqA9.js} +1 -1
- package/dist/assets/{requirementDiagram-LRYGKXZP-C1Z_inLz.js → requirementDiagram-LRYGKXZP-L84XyGgV.js} +1 -1
- package/dist/assets/{sankeyDiagram-W5VNT64P-DCJgKFUk.js → sankeyDiagram-W5VNT64P-CQqWbJ3j.js} +1 -1
- package/dist/assets/{sequenceDiagram-SI44F4Z6-D8Wrx5Vc.js → sequenceDiagram-SI44F4Z6--tnzS2tb.js} +1 -1
- package/dist/assets/{sizeCapture-X5ZJPWSS-CXqD68vD.js → sizeCapture-X5ZJPWSS-DujwEOtm.js} +1 -1
- package/dist/assets/{stateDiagram-OKZ733FA-CF0Ekqjo.js → stateDiagram-OKZ733FA-BK3TcZY2.js} +1 -1
- package/dist/assets/stateDiagram-v2-UEYNNEHI-_medyomK.js +1 -0
- package/dist/assets/{swimlanes-SLNWSIFB-DVIax_k4.js → swimlanes-SLNWSIFB-naX-Uv1B.js} +2 -2
- package/dist/assets/swimlanesDiagram-ULZ7WXOC-DstIv3TC.js +8 -0
- package/dist/assets/{timeline-definition-Z64GVDOM-DSqk3ApG.js → timeline-definition-Z64GVDOM-C-vP_ddU.js} +1 -1
- package/dist/assets/{vennDiagram-T6HMQDX7-DNbTqyG5.js → vennDiagram-T6HMQDX7-DN-I7o-7.js} +1 -1
- package/dist/assets/{wardleyDiagram-T6FBY63Y-BNCpsFZV.js → wardleyDiagram-T6FBY63Y-Db9dsaXv.js} +1 -1
- package/dist/assets/{xychartDiagram-ELKLHX3M-XsVZphHr.js → xychartDiagram-ELKLHX3M-DE6OxW_p.js} +1 -1
- package/dist/clear-cache.html +85 -85
- package/dist/convert-icons.md +52 -52
- package/dist/favicon.svg +8 -8
- package/dist/generate-icons.js +48 -48
- package/dist/icons/codex-white.svg +3 -3
- package/dist/icons/codex.svg +3 -3
- package/dist/icons/cursor-white.svg +11 -11
- package/dist/icons/icon-128x128.svg +11 -11
- package/dist/icons/icon-144x144.svg +11 -11
- package/dist/icons/icon-152x152.svg +11 -11
- package/dist/icons/icon-192x192.svg +11 -11
- package/dist/icons/icon-384x384.svg +11 -11
- package/dist/icons/icon-512x512.svg +11 -11
- package/dist/icons/icon-72x72.svg +11 -11
- package/dist/icons/icon-96x96.svg +11 -11
- package/dist/icons/icon-template.svg +11 -11
- package/dist/index.html +56 -56
- package/dist/logo.svg +17 -17
- package/dist/manifest.json +60 -60
- package/dist/sw.js +124 -124
- package/dist-server/server/modules/cli/cli.service.js +36 -36
- package/dist-server/server/modules/cli/sandbox.service.js +38 -38
- package/dist-server/server/modules/cli/tests/cli-environment-bootstrap.test.js +74 -74
- package/dist-server/server/modules/commands/commands.routes.js +24 -24
- package/dist-server/server/modules/database/migrations.js +190 -190
- package/dist-server/server/modules/database/repositories/api-keys.js +3 -3
- package/dist-server/server/modules/database/repositories/github-tokens.js +2 -2
- package/dist-server/server/modules/database/repositories/notification-channel-endpoints.js +28 -28
- package/dist-server/server/modules/database/repositories/notification-preferences.js +4 -4
- package/dist-server/server/modules/database/repositories/projects.db.js +61 -61
- package/dist-server/server/modules/database/repositories/provider-models.js +35 -35
- package/dist-server/server/modules/database/repositories/push-subscriptions.js +5 -5
- package/dist-server/server/modules/database/repositories/scan-state.db.js +5 -5
- package/dist-server/server/modules/database/repositories/sessions.db.js +92 -92
- package/dist-server/server/modules/database/schema.js +177 -177
- package/dist-server/server/modules/database/tests/provider-models.db.integration.test.js +6 -6
- package/dist-server/server/modules/git/git.routes.js +17 -17
- package/dist-server/server/modules/providers/list/opencode/opencode-models.provider.js +12 -12
- package/dist-server/server/modules/providers/list/opencode/opencode-runtime.provider.js +9 -9
- package/dist-server/server/modules/providers/list/opencode/opencode-runtime.provider.test.js +17 -17
- package/dist-server/server/modules/providers/list/opencode/opencode-session-synchronizer.provider.js +25 -25
- package/dist-server/server/modules/providers/list/opencode/opencode-sessions.provider.js +27 -27
- package/dist-server/server/modules/providers/services/provider-token-usage.service.js +9 -9
- package/dist-server/server/modules/providers/tests/mcp.test.js +3 -3
- package/dist-server/server/modules/providers/tests/opencode-sessions.test.js +96 -96
- package/dist-server/server/modules/providers/tests/provider-token-usage.service.test.js +18 -18
- package/dist-server/server/modules/taskmaster/taskmaster.routes.js +419 -419
- package/electron/cloud.js +260 -260
- package/electron/desktopNotifications.js +378 -378
- package/electron/desktopWindow.js +766 -766
- package/electron/launcher/index.html +14 -14
- package/electron/launcher/launcher.css +801 -801
- package/electron/launcher/launcher.js +687 -687
- package/electron/localServer.js +549 -549
- package/electron/main.js +944 -944
- package/electron/preload.cjs +60 -60
- package/electron/scripts/generate-macos-icon.js +62 -62
- package/electron/serverInstaller.js +277 -277
- package/electron/tabs.js +87 -87
- package/electron/viewHost.js +331 -331
- package/package.json +250 -247
- package/public/api-docs.html +901 -901
- package/scripts/fix-node-pty.js +67 -67
- package/scripts/promote-dist-server.mjs +50 -50
- package/scripts/release/build-server-bundle.js +176 -176
- package/scripts/release/prepare-desktop-app.js +152 -152
- package/server/index.ts +399 -399
- package/server/load-env.ts +47 -47
- package/server/modules/agent/agent.module.ts +52 -52
- package/server/modules/agent/agent.routes.ts +1287 -1287
- package/server/modules/agent/index.ts +2 -2
- package/server/modules/agent/tests/agent.routes.test.ts +205 -205
- package/server/modules/assets/assets.routes.ts +150 -150
- package/server/modules/assets/index.ts +3 -3
- package/server/modules/assets/services/image-assets.service.ts +127 -127
- package/server/modules/assets/tests/image-assets.service.test.ts +74 -74
- package/server/modules/auth/auth.middleware.ts +163 -163
- package/server/modules/auth/auth.module.ts +38 -38
- package/server/modules/auth/auth.routes.ts +57 -57
- package/server/modules/auth/auth.service.ts +155 -155
- package/server/modules/auth/index.ts +9 -9
- package/server/modules/auth/tests/auth.service.test.ts +95 -95
- package/server/modules/browser-use/browser-use-mcp.routes.ts +120 -120
- package/server/modules/browser-use/browser-use-mcp.ts +386 -386
- package/server/modules/browser-use/browser-use-runtime.ts +10 -10
- package/server/modules/browser-use/browser-use.routes.ts +96 -96
- package/server/modules/browser-use/browser-use.service.ts +836 -836
- package/server/modules/browser-use/index.ts +11 -11
- package/server/modules/browser-use/tests/browser-use.service.test.ts +10 -10
- package/server/modules/cli/cli.module.ts +93 -93
- package/server/modules/cli/cli.service.ts +248 -248
- package/server/modules/cli/cli.ts +19 -19
- package/server/modules/cli/index.ts +2 -2
- package/server/modules/cli/sandbox.service.ts +398 -398
- package/server/modules/cli/tests/cli-environment-bootstrap.test.ts +186 -186
- package/server/modules/cli/tests/cli.service.test.ts +86 -86
- package/server/modules/cli/tests/sandbox.service.test.ts +58 -58
- package/server/modules/commands/commands.module.ts +22 -22
- package/server/modules/commands/commands.routes.ts +586 -586
- package/server/modules/commands/index.ts +2 -2
- package/server/modules/commands/tests/commands.test.ts +109 -109
- package/server/modules/database/connection.ts +143 -143
- package/server/modules/database/index.ts +17 -17
- package/server/modules/database/init-db.ts +17 -17
- package/server/modules/database/migrations.ts +515 -515
- package/server/modules/database/repositories/api-keys.ts +119 -119
- package/server/modules/database/repositories/app-config.ts +53 -53
- package/server/modules/database/repositories/credentials.ts +106 -106
- package/server/modules/database/repositories/github-tokens.ts +100 -100
- package/server/modules/database/repositories/notification-channel-endpoints.ts +153 -153
- package/server/modules/database/repositories/notification-preferences.ts +117 -117
- package/server/modules/database/repositories/projects.db.ts +196 -196
- package/server/modules/database/repositories/provider-models.ts +168 -168
- package/server/modules/database/repositories/push-subscriptions.ts +80 -80
- package/server/modules/database/repositories/scan-state.db.ts +42 -42
- package/server/modules/database/repositories/sessions.db.ts +524 -524
- package/server/modules/database/repositories/users.ts +140 -140
- package/server/modules/database/repositories/vapid-keys.ts +57 -57
- package/server/modules/database/schema.ts +210 -210
- package/server/modules/database/tests/projects.db.integration.test.ts +72 -72
- package/server/modules/database/tests/provider-models.db.integration.test.ts +125 -125
- package/server/modules/database/tests/sessions-provider-mapping.test.ts +109 -109
- package/server/modules/database/tests/sessions.db.integration.test.ts +116 -116
- package/server/modules/file-tree/file-tree.module.ts +116 -116
- package/server/modules/file-tree/file-tree.routes.ts +258 -258
- package/server/modules/file-tree/file-tree.service.ts +675 -675
- package/server/modules/file-tree/index.ts +2 -2
- package/server/modules/file-tree/tests/file-tree.routes.test.ts +157 -157
- package/server/modules/file-tree/tests/file-tree.service.test.ts +371 -371
- package/server/modules/git/git-branch.service.ts +43 -43
- package/server/modules/git/git-parsing.service.ts +66 -66
- package/server/modules/git/git.module.ts +22 -22
- package/server/modules/git/git.routes.ts +1596 -1596
- package/server/modules/git/index.ts +2 -2
- package/server/modules/git/tests/git-branch.service.test.ts +60 -60
- package/server/modules/git/tests/git-init.routes.test.ts +132 -132
- package/server/modules/git/tests/git.test.ts +106 -106
- package/server/modules/notifications/index.ts +24 -24
- package/server/modules/notifications/notifications.routes.ts +127 -127
- package/server/modules/notifications/services/desktop-notification-clients.service.ts +124 -124
- package/server/modules/notifications/services/notification-orchestrator.service.js +310 -310
- package/server/modules/notifications/tests/notification-orchestrator.integration.test.ts +55 -55
- package/server/modules/notifications/vapid-keys.service.ts +38 -38
- package/server/modules/notifications/websocket/desktop-notifications-websocket.service.ts +109 -109
- package/server/modules/plugins/index.ts +9 -9
- package/server/modules/plugins/plugin-process.service.ts +217 -217
- package/server/modules/plugins/plugin-registry.service.ts +459 -459
- package/server/modules/plugins/plugins.module.ts +33 -33
- package/server/modules/plugins/plugins.routes.ts +66 -66
- package/server/modules/plugins/plugins.service.ts +147 -147
- package/server/modules/plugins/tests/plugins.service.test.ts +32 -32
- package/server/modules/projects/index.ts +11 -11
- package/server/modules/projects/projects.routes.ts +273 -273
- package/server/modules/projects/services/project-clone.service.ts +323 -323
- package/server/modules/projects/services/project-delete.service.ts +90 -90
- package/server/modules/projects/services/project-management.service.ts +144 -144
- package/server/modules/projects/services/project-star.service.ts +78 -78
- package/server/modules/projects/services/projects-has-taskmaster.service.ts +248 -248
- package/server/modules/projects/services/projects-with-sessions-fetch.service.ts +314 -314
- package/server/modules/projects/tests/project-clone.service.test.ts +183 -183
- package/server/modules/projects/tests/project-management.service.test.ts +117 -117
- package/server/modules/projects/tests/project-star.service.test.ts +123 -123
- package/server/modules/projects/tests/projects-has-taskmaster.service.test.ts +105 -105
- package/server/modules/providers/README.md +380 -380
- package/server/modules/providers/index.ts +10 -10
- package/server/modules/providers/list/claude/claude-auth.provider.ts +160 -160
- package/server/modules/providers/list/claude/claude-mcp.provider.ts +135 -135
- package/server/modules/providers/list/claude/claude-models.provider.ts +294 -294
- package/server/modules/providers/list/claude/claude-runtime.provider.js +1068 -1068
- package/server/modules/providers/list/claude/claude-session-synchronizer.provider.ts +203 -203
- package/server/modules/providers/list/claude/claude-sessions.provider.ts +684 -684
- package/server/modules/providers/list/claude/claude-skills.provider.ts +265 -265
- package/server/modules/providers/list/claude/claude.provider.ts +30 -30
- package/server/modules/providers/list/codex/codex-auth.provider.ts +100 -100
- package/server/modules/providers/list/codex/codex-mcp.provider.ts +135 -135
- package/server/modules/providers/list/codex/codex-models.provider.ts +123 -123
- package/server/modules/providers/list/codex/codex-runtime.provider.js +533 -533
- package/server/modules/providers/list/codex/codex-session-synchronizer.provider.ts +203 -203
- package/server/modules/providers/list/codex/codex-sessions.provider.ts +938 -938
- package/server/modules/providers/list/codex/codex-skills.provider.ts +73 -73
- package/server/modules/providers/list/codex/codex.provider.ts +28 -28
- package/server/modules/providers/list/cursor/cursor-auth.provider.ts +143 -143
- package/server/modules/providers/list/cursor/cursor-mcp.provider.ts +108 -108
- package/server/modules/providers/list/cursor/cursor-models.provider.ts +119 -119
- package/server/modules/providers/list/cursor/cursor-runtime.provider.js +385 -385
- package/server/modules/providers/list/cursor/cursor-session-synchronizer.provider.ts +159 -159
- package/server/modules/providers/list/cursor/cursor-sessions.provider.ts +654 -654
- package/server/modules/providers/list/cursor/cursor-skills.provider.ts +39 -39
- package/server/modules/providers/list/cursor/cursor.provider.ts +30 -30
- package/server/modules/providers/list/opencode/opencode-auth.provider.ts +110 -110
- package/server/modules/providers/list/opencode/opencode-mcp.provider.ts +228 -228
- package/server/modules/providers/list/opencode/opencode-models.provider.ts +203 -203
- package/server/modules/providers/list/opencode/opencode-runtime.provider.js +434 -434
- package/server/modules/providers/list/opencode/opencode-runtime.provider.test.js +261 -261
- package/server/modules/providers/list/opencode/opencode-session-synchronizer.provider.ts +179 -179
- package/server/modules/providers/list/opencode/opencode-sessions.provider.ts +500 -500
- package/server/modules/providers/list/opencode/opencode-skills.provider.ts +78 -78
- package/server/modules/providers/list/opencode/opencode.provider.ts +30 -30
- package/server/modules/providers/provider.registry.ts +36 -36
- package/server/modules/providers/provider.routes.ts +877 -877
- package/server/modules/providers/services/mcp.service.ts +109 -109
- package/server/modules/providers/services/provider-auth.service.ts +26 -26
- package/server/modules/providers/services/provider-capabilities.service.ts +97 -97
- package/server/modules/providers/services/provider-models.service.ts +401 -401
- package/server/modules/providers/services/provider-runtime.service.ts +108 -108
- package/server/modules/providers/services/provider-token-usage.service.ts +357 -357
- package/server/modules/providers/services/session-conversations-search.service.ts +1321 -1321
- package/server/modules/providers/services/session-synchronizer.service.ts +74 -74
- package/server/modules/providers/services/sessions-watcher.service.ts +247 -247
- package/server/modules/providers/services/sessions.service.ts +471 -471
- package/server/modules/providers/services/skills.service.ts +39 -39
- package/server/modules/providers/shared/base/abstract.provider.ts +32 -32
- package/server/modules/providers/shared/mcp/mcp.provider.ts +151 -151
- package/server/modules/providers/shared/skills/skills.provider.ts +287 -287
- package/server/modules/providers/tests/claude-auth.test.ts +150 -150
- package/server/modules/providers/tests/claude-sessions.test.ts +61 -61
- package/server/modules/providers/tests/codex-sessions.test.ts +231 -231
- package/server/modules/providers/tests/mcp.test.ts +349 -349
- package/server/modules/providers/tests/opencode-models.test.ts +41 -41
- package/server/modules/providers/tests/opencode-sessions.test.ts +522 -522
- package/server/modules/providers/tests/provider-attachment-history.test.ts +247 -247
- package/server/modules/providers/tests/provider-models.service.test.ts +353 -353
- package/server/modules/providers/tests/provider-runtime.service.test.ts +138 -138
- package/server/modules/providers/tests/provider-token-usage.service.test.ts +186 -186
- package/server/modules/providers/tests/provider.routes.test.ts +244 -244
- package/server/modules/providers/tests/sessions-details.test.ts +73 -73
- package/server/modules/providers/tests/sessions.service.test.ts +127 -127
- package/server/modules/providers/tests/skills.test.ts +692 -692
- package/server/modules/settings/index.ts +2 -2
- package/server/modules/settings/settings.module.ts +50 -50
- package/server/modules/settings/settings.routes.ts +51 -51
- package/server/modules/settings/settings.service.ts +186 -186
- package/server/modules/settings/tests/settings.service.test.ts +54 -54
- package/server/modules/system/index.ts +2 -2
- package/server/modules/system/system.module.ts +62 -62
- package/server/modules/system/system.routes.ts +21 -21
- package/server/modules/system/system.service.ts +76 -76
- package/server/modules/system/tests/system.service.test.ts +118 -118
- package/server/modules/taskmaster/index.ts +2 -2
- package/server/modules/taskmaster/taskmaster.module.ts +24 -24
- package/server/modules/taskmaster/taskmaster.routes.ts +1482 -1482
- package/server/modules/taskmaster/taskmaster.service.ts +132 -132
- package/server/modules/taskmaster/tests/taskmaster.routes.test.ts +144 -144
- package/server/modules/taskmaster/tests/taskmaster.service.test.ts +97 -97
- package/server/modules/user/index.ts +2 -2
- package/server/modules/user/tests/user.service.test.ts +61 -61
- package/server/modules/user/user.module.ts +58 -58
- package/server/modules/user/user.routes.ts +50 -50
- package/server/modules/user/user.service.ts +85 -85
- package/server/modules/voice/index.ts +2 -2
- package/server/modules/voice/tests/voice.service.test.ts +98 -98
- package/server/modules/voice/voice.module.ts +47 -47
- package/server/modules/voice/voice.routes.ts +113 -113
- package/server/modules/voice/voice.service.ts +192 -192
- package/server/modules/websocket/README.md +273 -273
- package/server/modules/websocket/index.ts +3 -3
- package/server/modules/websocket/services/chat-run-registry.service.ts +343 -343
- package/server/modules/websocket/services/chat-session-writer.service.ts +145 -145
- package/server/modules/websocket/services/chat-websocket.service.ts +425 -425
- package/server/modules/websocket/services/plugin-websocket-proxy.service.ts +65 -65
- package/server/modules/websocket/services/shell-websocket.service.ts +502 -502
- package/server/modules/websocket/services/websocket-auth.service.ts +59 -59
- package/server/modules/websocket/services/websocket-server.service.ts +124 -124
- package/server/modules/websocket/services/websocket-state.service.ts +16 -16
- package/server/modules/websocket/services/websocket-writer.service.ts +38 -38
- package/server/modules/websocket/tests/chat-attachment-filter.test.ts +59 -59
- package/server/modules/websocket/tests/chat-run-registry.test.ts +282 -282
- package/server/modules/websocket/tests/shell-websocket.service.test.ts +100 -100
- package/server/modules/websocket/tests/websocket-heartbeat.service.test.ts +78 -78
- package/server/modules/worktrees/index.ts +2 -2
- package/server/modules/worktrees/services/worktree-create-and-open.service.ts +53 -53
- package/server/modules/worktrees/services/worktree-create.service.ts +104 -104
- package/server/modules/worktrees/services/worktree-git.service.ts +207 -207
- package/server/modules/worktrees/services/worktree-list.service.ts +143 -143
- package/server/modules/worktrees/services/worktree-merge.service.ts +157 -157
- package/server/modules/worktrees/services/worktree-open.service.ts +85 -85
- package/server/modules/worktrees/services/worktree-remove.service.ts +88 -88
- package/server/modules/worktrees/tests/worktree-create-and-open.service.test.ts +68 -68
- package/server/modules/worktrees/tests/worktree-create.service.test.ts +142 -142
- package/server/modules/worktrees/tests/worktree-git.service.test.ts +84 -84
- package/server/modules/worktrees/tests/worktree-list.service.test.ts +45 -45
- package/server/modules/worktrees/tests/worktree-merge.service.test.ts +213 -213
- package/server/modules/worktrees/tests/worktree-open.service.test.ts +122 -122
- package/server/modules/worktrees/tests/worktree-remove.service.test.ts +227 -227
- package/server/modules/worktrees/tests/worktrees.routes.test.ts +199 -199
- package/server/modules/worktrees/worktrees.module.ts +113 -113
- package/server/modules/worktrees/worktrees.routes.ts +116 -116
- package/server/shared/claude-cli-path.ts +139 -139
- package/server/shared/frontmatter.ts +18 -18
- package/server/shared/image-attachments.ts +435 -435
- package/server/shared/interfaces.ts +179 -179
- package/server/shared/tests/claude-cli-path.test.ts +61 -61
- package/server/shared/tests/image-attachments.test.ts +353 -353
- package/server/shared/tests/slice-tail-page.test.ts +42 -42
- package/server/shared/types.ts +1226 -1226
- package/server/shared/utils.ts +1161 -1161
- package/server/tsconfig.json +40 -40
- package/shared/networkHosts.js +22 -22
- package/dist/assets/channel-Bm0ZLE4z.js +0 -1
- package/dist/assets/classDiagram-JCYQIIEL-DqEOcNxw.js +0 -1
- package/dist/assets/classDiagram-v2-OCEON4UE-DqEOcNxw.js +0 -1
- package/dist/assets/stateDiagram-v2-UEYNNEHI-DARLpEFJ.js +0 -1
- package/dist/assets/swimlanesDiagram-ULZ7WXOC-CrgDgaY8.js +0 -8
|
@@ -1,675 +1,675 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import ignore from 'ignore';
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
FileTreeDirectoryEntry,
|
|
7
|
-
FileTreeNode,
|
|
8
|
-
FileTreeServiceDependencies,
|
|
9
|
-
FileTreeServices,
|
|
10
|
-
FileTreeUploadedFile,
|
|
11
|
-
} from '@/shared/types.js';
|
|
12
|
-
import { AppError, FORBIDDEN_WORKSPACE_PATHS, normalizeProjectPath } from '@/shared/utils.js';
|
|
13
|
-
|
|
14
|
-
const HARD_EXCLUDED_DIRECTORY_NAMES = new Set([
|
|
15
|
-
'node_modules', '.git', '.svn', '.hg',
|
|
16
|
-
]);
|
|
17
|
-
|
|
18
|
-
const IGNORED_DIRECTORY_NAMES = new Set([
|
|
19
|
-
...HARD_EXCLUDED_DIRECTORY_NAMES,
|
|
20
|
-
'dist', 'build', '.next', '.nuxt', '.cache', '.parcel-cache',
|
|
21
|
-
'__pycache__', '.pytest_cache', '.mypy_cache', '.tox', 'venv', '.venv',
|
|
22
|
-
'target', 'vendor',
|
|
23
|
-
'.gradle', '.idea', 'coverage', '.nyc_output',
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
const COMMON_WORKSPACE_DIRECTORY_NAMES = [
|
|
27
|
-
'Desktop',
|
|
28
|
-
'Documents',
|
|
29
|
-
'Projects',
|
|
30
|
-
'Development',
|
|
31
|
-
'Dev',
|
|
32
|
-
'Code',
|
|
33
|
-
'workspace',
|
|
34
|
-
];
|
|
35
|
-
|
|
36
|
-
// File Tree consumes this guard when recursively listing a project so a very
|
|
37
|
-
// broad workspace (for example, a user's home directory) cannot exhaust the
|
|
38
|
-
// server heap before the browser has a chance to switch to a narrower project.
|
|
39
|
-
const MAXIMUM_FILE_TREE_ENTRIES = 10_000;
|
|
40
|
-
|
|
41
|
-
type FileTreeEntryFilter = (entryPath: string, isDirectory: boolean) => boolean;
|
|
42
|
-
|
|
43
|
-
function includeEntryByHardExclusions(entryPath: string, isDirectory: boolean): boolean {
|
|
44
|
-
return !isDirectory || !HARD_EXCLUDED_DIRECTORY_NAMES.has(path.basename(entryPath));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function includeEntryByFallbackDirectoryNames(entryPath: string, isDirectory: boolean): boolean {
|
|
48
|
-
return includeEntryByHardExclusions(entryPath, isDirectory)
|
|
49
|
-
&& (!isDirectory || !IGNORED_DIRECTORY_NAMES.has(path.basename(entryPath)));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function createFileTreeError(message: string, statusCode: number, code: string): AppError {
|
|
53
|
-
return new AppError(message, { statusCode, code });
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function readErrorCode(error: unknown): string | null {
|
|
57
|
-
return typeof error === 'object' && error !== null && 'code' in error
|
|
58
|
-
? String(error.code)
|
|
59
|
-
: null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function readErrorMessage(error: unknown): string {
|
|
63
|
-
return error instanceof Error ? error.message : String(error);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function permissionBitsToRwx(permissionBits: number): string {
|
|
67
|
-
const read = permissionBits & 4 ? 'r' : '-';
|
|
68
|
-
const write = permissionBits & 2 ? 'w' : '-';
|
|
69
|
-
const execute = permissionBits & 1 ? 'x' : '-';
|
|
70
|
-
return read + write + execute;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function validateFilename(name: string): void {
|
|
74
|
-
if (!name.trim()) {
|
|
75
|
-
throw createFileTreeError('Filename cannot be empty', 400, 'INVALID_FILENAME');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (/[<>:"/\\|?*\x00-\x1f]/.test(name)) {
|
|
79
|
-
throw createFileTreeError('Filename contains invalid characters', 400, 'INVALID_FILENAME');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i.test(name)) {
|
|
83
|
-
throw createFileTreeError('Filename is a reserved name', 400, 'INVALID_FILENAME');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (/^\.+$/.test(name)) {
|
|
87
|
-
throw createFileTreeError('Filename cannot be only dots', 400, 'INVALID_FILENAME');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function resolvePathInsideProject(projectRoot: string, targetPath: string): string {
|
|
92
|
-
const resolvedPath = path.isAbsolute(targetPath)
|
|
93
|
-
? path.resolve(targetPath)
|
|
94
|
-
: path.resolve(projectRoot, targetPath);
|
|
95
|
-
const normalizedProjectRoot = path.resolve(projectRoot) + path.sep;
|
|
96
|
-
|
|
97
|
-
if (!resolvedPath.startsWith(normalizedProjectRoot)) {
|
|
98
|
-
throw createFileTreeError('Path must be under project root', 403, 'PATH_OUTSIDE_PROJECT');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return resolvedPath;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function expandWorkspacePath(workspaceRoot: string, inputPath: string): string {
|
|
105
|
-
if (inputPath === '~') {
|
|
106
|
-
return workspaceRoot;
|
|
107
|
-
}
|
|
108
|
-
if (inputPath.startsWith('~/') || inputPath.startsWith('~\\')) {
|
|
109
|
-
return path.join(workspaceRoot, inputPath.slice(2));
|
|
110
|
-
}
|
|
111
|
-
return inputPath;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function createConcurrencyLimiter(maximumConcurrency: number) {
|
|
115
|
-
let activeOperations = 0;
|
|
116
|
-
const pendingOperations: Array<() => void> = [];
|
|
117
|
-
|
|
118
|
-
async function acquire(): Promise<void> {
|
|
119
|
-
if (activeOperations < maximumConcurrency) {
|
|
120
|
-
activeOperations += 1;
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
await new Promise<void>((resolve) => {
|
|
125
|
-
pendingOperations.push(resolve);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function release(): void {
|
|
130
|
-
const nextOperation = pendingOperations.shift();
|
|
131
|
-
if (nextOperation) {
|
|
132
|
-
nextOperation();
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
activeOperations = Math.max(0, activeOperations - 1);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return { acquire, release };
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function mapFileSystemError(
|
|
143
|
-
error: unknown,
|
|
144
|
-
messages: Partial<Record<string, { message: string; statusCode: number }>>,
|
|
145
|
-
): never {
|
|
146
|
-
const errorCode = readErrorCode(error);
|
|
147
|
-
const mappedError = errorCode ? messages[errorCode] : undefined;
|
|
148
|
-
if (mappedError) {
|
|
149
|
-
throw createFileTreeError(mappedError.message, mappedError.statusCode, errorCode ?? 'FILE_TREE_ERROR');
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
throw error;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function createGitignoreEntryFilter(
|
|
156
|
-
projectRoot: string,
|
|
157
|
-
gitignoreContent: string,
|
|
158
|
-
): FileTreeEntryFilter {
|
|
159
|
-
const gitignore = ignore().add(gitignoreContent);
|
|
160
|
-
|
|
161
|
-
return (entryPath, isDirectory) => {
|
|
162
|
-
if (!includeEntryByHardExclusions(entryPath, isDirectory)) return false;
|
|
163
|
-
|
|
164
|
-
const relativePath = path.relative(projectRoot, entryPath).split(path.sep).join('/');
|
|
165
|
-
const matchPath = isDirectory ? `${relativePath}/` : relativePath;
|
|
166
|
-
return !gitignore.ignores(matchPath);
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Creates File Tree workflows for the module composition root and route tests.
|
|
172
|
-
* Every filesystem, project, workspace, environment, and logging dependency is
|
|
173
|
-
* required explicitly so this service has no machine-wide production defaults.
|
|
174
|
-
*/
|
|
175
|
-
export function createFileTreeService(dependencies: FileTreeServiceDependencies): FileTreeServices {
|
|
176
|
-
const fileSystem = dependencies.fileSystem;
|
|
177
|
-
const concurrencyLimit = Number.isFinite(dependencies.fileSystemConcurrency)
|
|
178
|
-
&& dependencies.fileSystemConcurrency > 0
|
|
179
|
-
? Math.floor(dependencies.fileSystemConcurrency)
|
|
180
|
-
: 1;
|
|
181
|
-
const { acquire, release } = createConcurrencyLimiter(concurrencyLimit);
|
|
182
|
-
|
|
183
|
-
async function resolveProjectRoot(projectId: string): Promise<string> {
|
|
184
|
-
const projectRoot = await dependencies.projects.getProjectPathById(projectId);
|
|
185
|
-
if (!projectRoot) {
|
|
186
|
-
throw createFileTreeError('Project not found', 404, 'PROJECT_NOT_FOUND');
|
|
187
|
-
}
|
|
188
|
-
return projectRoot;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Streams one directory and keeps only the entries the tree will show.
|
|
193
|
-
*
|
|
194
|
-
* Entries are filtered and charged against the shared budget one at a time,
|
|
195
|
-
* so a pathologically large directory stops the walk at the cap instead of
|
|
196
|
-
* being read into memory in full first.
|
|
197
|
-
*/
|
|
198
|
-
async function collectVisibleEntries(
|
|
199
|
-
directoryPath: string,
|
|
200
|
-
includeEntry: FileTreeEntryFilter,
|
|
201
|
-
remainingEntries: { value: number },
|
|
202
|
-
): Promise<FileTreeDirectoryEntry[]> {
|
|
203
|
-
const visibleEntries: FileTreeDirectoryEntry[] = [];
|
|
204
|
-
|
|
205
|
-
await acquire();
|
|
206
|
-
try {
|
|
207
|
-
for await (const entry of fileSystem.openDirectory(directoryPath)) {
|
|
208
|
-
const isDirectory = entry.isDirectory();
|
|
209
|
-
if (!includeEntry(path.join(directoryPath, entry.name), isDirectory)) {
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Charged after visibility filtering so ignored entries never consume
|
|
214
|
-
// the budget. Every recursive branch shares one counter, so the cap
|
|
215
|
-
// applies to the whole tree rather than per directory.
|
|
216
|
-
if (remainingEntries.value <= 0) {
|
|
217
|
-
throw createFileTreeError(
|
|
218
|
-
`Project file tree exceeds the ${MAXIMUM_FILE_TREE_ENTRIES.toLocaleString()} entry limit. Choose a narrower project directory or add ignore rules.`,
|
|
219
|
-
413,
|
|
220
|
-
'FILE_TREE_TOO_LARGE',
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
remainingEntries.value -= 1;
|
|
224
|
-
visibleEntries.push(entry);
|
|
225
|
-
}
|
|
226
|
-
} catch (error) {
|
|
227
|
-
// The entry cap is a caller-visible outcome, not an unreadable directory.
|
|
228
|
-
if (error instanceof AppError) {
|
|
229
|
-
throw error;
|
|
230
|
-
}
|
|
231
|
-
const errorCode = readErrorCode(error);
|
|
232
|
-
if (errorCode !== 'EACCES' && errorCode !== 'EPERM') {
|
|
233
|
-
dependencies.logger.error(`Error reading directory "${directoryPath}"`, error);
|
|
234
|
-
}
|
|
235
|
-
return [];
|
|
236
|
-
} finally {
|
|
237
|
-
release();
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return visibleEntries;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
async function buildFileTree(
|
|
244
|
-
directoryPath: string,
|
|
245
|
-
maximumDepth: number,
|
|
246
|
-
currentDepth = 0,
|
|
247
|
-
includeEntry: FileTreeEntryFilter = includeEntryByFallbackDirectoryNames,
|
|
248
|
-
remainingEntries = { value: MAXIMUM_FILE_TREE_ENTRIES },
|
|
249
|
-
): Promise<FileTreeNode[]> {
|
|
250
|
-
const visibleEntries = await collectVisibleEntries(directoryPath, includeEntry, remainingEntries);
|
|
251
|
-
|
|
252
|
-
const items = await Promise.all(visibleEntries.map(async (entry): Promise<FileTreeNode> => {
|
|
253
|
-
const itemPath = path.join(directoryPath, entry.name);
|
|
254
|
-
const item: FileTreeNode = {
|
|
255
|
-
name: entry.name,
|
|
256
|
-
path: itemPath,
|
|
257
|
-
type: entry.isDirectory() ? 'directory' : 'file',
|
|
258
|
-
size: 0,
|
|
259
|
-
modified: null,
|
|
260
|
-
permissions: '000',
|
|
261
|
-
permissionsRwx: '---------',
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
await acquire();
|
|
266
|
-
try {
|
|
267
|
-
const stats = await fileSystem.lstat(itemPath);
|
|
268
|
-
const ownerPermissions = (stats.mode >> 6) & 7;
|
|
269
|
-
const groupPermissions = (stats.mode >> 3) & 7;
|
|
270
|
-
const otherPermissions = stats.mode & 7;
|
|
271
|
-
|
|
272
|
-
item.size = stats.size;
|
|
273
|
-
item.modified = stats.mtime.toISOString();
|
|
274
|
-
item.permissions = `${ownerPermissions}${groupPermissions}${otherPermissions}`;
|
|
275
|
-
item.permissionsRwx = permissionBitsToRwx(ownerPermissions)
|
|
276
|
-
+ permissionBitsToRwx(groupPermissions)
|
|
277
|
-
+ permissionBitsToRwx(otherPermissions);
|
|
278
|
-
if (stats.isSymbolicLink()) {
|
|
279
|
-
item.isSymlink = true;
|
|
280
|
-
}
|
|
281
|
-
} finally {
|
|
282
|
-
release();
|
|
283
|
-
}
|
|
284
|
-
} catch {
|
|
285
|
-
// Metadata failures should not hide an otherwise readable tree entry.
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Skip recursing into pseudo-filesystems and other system-critical
|
|
289
|
-
// directories (e.g. /proc, /sys) — they're never valid project roots,
|
|
290
|
-
// and /proc in particular can contain thousands of virtual entries
|
|
291
|
-
// that make traversal from a broad root (e.g. "/") pathologically slow.
|
|
292
|
-
const isForbiddenSystemDir = FORBIDDEN_WORKSPACE_PATHS.includes(normalizeProjectPath(itemPath));
|
|
293
|
-
|
|
294
|
-
if (entry.isDirectory() && currentDepth < maximumDepth && !isForbiddenSystemDir) {
|
|
295
|
-
item.children = await buildFileTree(
|
|
296
|
-
itemPath,
|
|
297
|
-
maximumDepth,
|
|
298
|
-
currentDepth + 1,
|
|
299
|
-
includeEntry,
|
|
300
|
-
remainingEntries,
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return item;
|
|
305
|
-
}));
|
|
306
|
-
|
|
307
|
-
return items.sort((left, right) => {
|
|
308
|
-
if (left.type !== right.type) {
|
|
309
|
-
return left.type === 'directory' ? -1 : 1;
|
|
310
|
-
}
|
|
311
|
-
return left.name.localeCompare(right.name);
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
async function cleanupTemporaryFiles(files: FileTreeUploadedFile[]): Promise<void> {
|
|
316
|
-
await Promise.all(files.map(async (file) => {
|
|
317
|
-
try {
|
|
318
|
-
await fileSystem.unlink(file.temporaryPath);
|
|
319
|
-
} catch {
|
|
320
|
-
// A successfully moved file no longer has a temporary source to clean.
|
|
321
|
-
}
|
|
322
|
-
}));
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return {
|
|
326
|
-
async browseWorkspace(inputPath) {
|
|
327
|
-
const requestedPath = inputPath
|
|
328
|
-
? expandWorkspacePath(dependencies.workspace.rootPath, inputPath)
|
|
329
|
-
: dependencies.workspace.rootPath;
|
|
330
|
-
const targetPath = path.resolve(requestedPath);
|
|
331
|
-
const validation = await dependencies.workspace.validatePath(targetPath);
|
|
332
|
-
if (!validation.valid) {
|
|
333
|
-
throw createFileTreeError(validation.error ?? 'Path is outside the workspace root', 403, 'INVALID_WORKSPACE_PATH');
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const resolvedPath = validation.resolvedPath || targetPath;
|
|
337
|
-
try {
|
|
338
|
-
await fileSystem.access(resolvedPath);
|
|
339
|
-
const stats = await fileSystem.stat(resolvedPath);
|
|
340
|
-
if (!stats.isDirectory()) {
|
|
341
|
-
throw createFileTreeError('Path is not a directory', 400, 'NOT_A_DIRECTORY');
|
|
342
|
-
}
|
|
343
|
-
} catch (error) {
|
|
344
|
-
if (error instanceof AppError) throw error;
|
|
345
|
-
throw createFileTreeError('Directory not accessible', 404, 'DIRECTORY_NOT_ACCESSIBLE');
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
const fileTree = await buildFileTree(resolvedPath, 1);
|
|
349
|
-
const directories = fileTree
|
|
350
|
-
.filter((item) => item.type === 'directory')
|
|
351
|
-
.map((item) => ({ path: item.path, name: item.name, type: 'directory' as const }))
|
|
352
|
-
.sort((left, right) => {
|
|
353
|
-
const leftHidden = left.name.startsWith('.');
|
|
354
|
-
const rightHidden = right.name.startsWith('.');
|
|
355
|
-
if (leftHidden && !rightHidden) return 1;
|
|
356
|
-
if (!leftHidden && rightHidden) return -1;
|
|
357
|
-
return left.name.localeCompare(right.name);
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
let resolvedWorkspaceRoot = dependencies.workspace.rootPath;
|
|
361
|
-
try {
|
|
362
|
-
resolvedWorkspaceRoot = await fileSystem.realpath(dependencies.workspace.rootPath);
|
|
363
|
-
} catch {
|
|
364
|
-
// The configured workspace root remains the comparison fallback.
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
const suggestions = resolvedPath === resolvedWorkspaceRoot
|
|
368
|
-
? [
|
|
369
|
-
...directories.filter((directory) => COMMON_WORKSPACE_DIRECTORY_NAMES.includes(directory.name)),
|
|
370
|
-
...directories.filter((directory) => !COMMON_WORKSPACE_DIRECTORY_NAMES.includes(directory.name)),
|
|
371
|
-
]
|
|
372
|
-
: directories;
|
|
373
|
-
|
|
374
|
-
return { path: resolvedPath, suggestions };
|
|
375
|
-
},
|
|
376
|
-
|
|
377
|
-
async createWorkspaceFolder(folderPath) {
|
|
378
|
-
const expandedPath = expandWorkspacePath(dependencies.workspace.rootPath, folderPath);
|
|
379
|
-
const resolvedInput = path.resolve(expandedPath);
|
|
380
|
-
const validation = await dependencies.workspace.validatePath(resolvedInput);
|
|
381
|
-
if (!validation.valid) {
|
|
382
|
-
throw createFileTreeError(validation.error ?? 'Path is outside the workspace root', 403, 'INVALID_WORKSPACE_PATH');
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const targetPath = validation.resolvedPath || resolvedInput;
|
|
386
|
-
try {
|
|
387
|
-
await fileSystem.access(path.dirname(targetPath));
|
|
388
|
-
} catch {
|
|
389
|
-
throw createFileTreeError('Parent directory does not exist', 404, 'PARENT_DIRECTORY_NOT_FOUND');
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
try {
|
|
393
|
-
await fileSystem.access(targetPath);
|
|
394
|
-
throw createFileTreeError('Folder already exists', 409, 'FOLDER_ALREADY_EXISTS');
|
|
395
|
-
} catch (error) {
|
|
396
|
-
if (error instanceof AppError) throw error;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
try {
|
|
400
|
-
await fileSystem.makeDirectory(targetPath, false);
|
|
401
|
-
} catch (error) {
|
|
402
|
-
mapFileSystemError(error, {
|
|
403
|
-
EEXIST: { message: 'Folder already exists', statusCode: 409 },
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
return { success: true, path: targetPath };
|
|
408
|
-
},
|
|
409
|
-
|
|
410
|
-
async readTextFile(projectId, filePath) {
|
|
411
|
-
const projectRoot = await resolveProjectRoot(projectId);
|
|
412
|
-
const resolvedPath = resolvePathInsideProject(projectRoot, filePath);
|
|
413
|
-
try {
|
|
414
|
-
const content = await fileSystem.readTextFile(resolvedPath);
|
|
415
|
-
return { content, path: resolvedPath };
|
|
416
|
-
} catch (error) {
|
|
417
|
-
mapFileSystemError(error, {
|
|
418
|
-
ENOENT: { message: 'File not found', statusCode: 404 },
|
|
419
|
-
EACCES: { message: 'Permission denied', statusCode: 403 },
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
},
|
|
423
|
-
|
|
424
|
-
async openFile(projectId, filePath) {
|
|
425
|
-
const projectRoot = await resolveProjectRoot(projectId);
|
|
426
|
-
const resolvedPath = resolvePathInsideProject(projectRoot, filePath);
|
|
427
|
-
try {
|
|
428
|
-
await fileSystem.access(resolvedPath);
|
|
429
|
-
} catch {
|
|
430
|
-
throw createFileTreeError('File not found', 404, 'FILE_NOT_FOUND');
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
return {
|
|
434
|
-
contentType: dependencies.resolveMimeType(resolvedPath),
|
|
435
|
-
stream: fileSystem.createReadStream(resolvedPath),
|
|
436
|
-
};
|
|
437
|
-
},
|
|
438
|
-
|
|
439
|
-
async saveTextFile(projectId, filePath, content) {
|
|
440
|
-
const projectRoot = await resolveProjectRoot(projectId);
|
|
441
|
-
const resolvedPath = resolvePathInsideProject(projectRoot, filePath);
|
|
442
|
-
try {
|
|
443
|
-
await fileSystem.writeTextFile(resolvedPath, content);
|
|
444
|
-
} catch (error) {
|
|
445
|
-
mapFileSystemError(error, {
|
|
446
|
-
ENOENT: { message: 'File or directory not found', statusCode: 404 },
|
|
447
|
-
EACCES: { message: 'Permission denied', statusCode: 403 },
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
return { success: true, path: resolvedPath, message: 'File saved successfully' };
|
|
452
|
-
},
|
|
453
|
-
|
|
454
|
-
async listProjectFiles(projectId, options) {
|
|
455
|
-
const projectRoot = await resolveProjectRoot(projectId);
|
|
456
|
-
try {
|
|
457
|
-
await fileSystem.access(projectRoot);
|
|
458
|
-
} catch {
|
|
459
|
-
throw createFileTreeError(`Project path not found: ${projectRoot}`, 404, 'PROJECT_PATH_NOT_FOUND');
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
let includeEntry: FileTreeEntryFilter | undefined;
|
|
463
|
-
if (options?.respectGitignore) {
|
|
464
|
-
try {
|
|
465
|
-
const gitignoreContent = await fileSystem.readTextFile(path.join(projectRoot, '.gitignore'));
|
|
466
|
-
includeEntry = createGitignoreEntryFilter(projectRoot, gitignoreContent);
|
|
467
|
-
} catch (error) {
|
|
468
|
-
if (readErrorCode(error) !== 'ENOENT') {
|
|
469
|
-
dependencies.logger.error(`Error reading .gitignore in "${projectRoot}"`, error);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
return buildFileTree(projectRoot, 10, 0, includeEntry);
|
|
475
|
-
},
|
|
476
|
-
|
|
477
|
-
async createEntry(input) {
|
|
478
|
-
validateFilename(input.name);
|
|
479
|
-
const projectRoot = await resolveProjectRoot(input.projectId);
|
|
480
|
-
const targetPath = input.parentPath
|
|
481
|
-
? path.join(input.parentPath, input.name)
|
|
482
|
-
: input.name;
|
|
483
|
-
const resolvedPath = resolvePathInsideProject(projectRoot, targetPath);
|
|
484
|
-
|
|
485
|
-
try {
|
|
486
|
-
await fileSystem.access(resolvedPath);
|
|
487
|
-
throw createFileTreeError(
|
|
488
|
-
`${input.type === 'file' ? 'File' : 'Directory'} already exists`,
|
|
489
|
-
409,
|
|
490
|
-
'FILE_TREE_ENTRY_EXISTS',
|
|
491
|
-
);
|
|
492
|
-
} catch (error) {
|
|
493
|
-
if (error instanceof AppError) throw error;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
try {
|
|
497
|
-
if (input.type === 'directory') {
|
|
498
|
-
await fileSystem.makeDirectory(resolvedPath, false);
|
|
499
|
-
} else {
|
|
500
|
-
const parentDirectory = path.dirname(resolvedPath);
|
|
501
|
-
try {
|
|
502
|
-
await fileSystem.access(parentDirectory);
|
|
503
|
-
} catch {
|
|
504
|
-
await fileSystem.makeDirectory(parentDirectory, true);
|
|
505
|
-
}
|
|
506
|
-
await fileSystem.writeTextFile(resolvedPath, '');
|
|
507
|
-
}
|
|
508
|
-
} catch (error) {
|
|
509
|
-
mapFileSystemError(error, {
|
|
510
|
-
EACCES: { message: 'Permission denied', statusCode: 403 },
|
|
511
|
-
ENOENT: { message: 'Parent directory not found', statusCode: 404 },
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
return {
|
|
516
|
-
success: true,
|
|
517
|
-
path: resolvedPath,
|
|
518
|
-
name: input.name,
|
|
519
|
-
type: input.type,
|
|
520
|
-
message: `${input.type === 'file' ? 'File' : 'Directory'} created successfully`,
|
|
521
|
-
};
|
|
522
|
-
},
|
|
523
|
-
|
|
524
|
-
async renameEntry(input) {
|
|
525
|
-
validateFilename(input.newName);
|
|
526
|
-
const projectRoot = await resolveProjectRoot(input.projectId);
|
|
527
|
-
const resolvedOldPath = resolvePathInsideProject(projectRoot, input.oldPath);
|
|
528
|
-
|
|
529
|
-
try {
|
|
530
|
-
await fileSystem.access(resolvedOldPath);
|
|
531
|
-
} catch {
|
|
532
|
-
throw createFileTreeError('File or directory not found', 404, 'FILE_TREE_ENTRY_NOT_FOUND');
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
const resolvedNewPath = path.join(path.dirname(resolvedOldPath), input.newName);
|
|
536
|
-
resolvePathInsideProject(projectRoot, resolvedNewPath);
|
|
537
|
-
try {
|
|
538
|
-
await fileSystem.access(resolvedNewPath);
|
|
539
|
-
throw createFileTreeError(
|
|
540
|
-
'A file or directory with this name already exists',
|
|
541
|
-
409,
|
|
542
|
-
'FILE_TREE_ENTRY_EXISTS',
|
|
543
|
-
);
|
|
544
|
-
} catch (error) {
|
|
545
|
-
if (error instanceof AppError) throw error;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
try {
|
|
549
|
-
await fileSystem.rename(resolvedOldPath, resolvedNewPath);
|
|
550
|
-
} catch (error) {
|
|
551
|
-
mapFileSystemError(error, {
|
|
552
|
-
EACCES: { message: 'Permission denied', statusCode: 403 },
|
|
553
|
-
ENOENT: { message: 'File or directory not found', statusCode: 404 },
|
|
554
|
-
EXDEV: { message: 'Cannot move across different filesystems', statusCode: 400 },
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return {
|
|
559
|
-
success: true,
|
|
560
|
-
oldPath: resolvedOldPath,
|
|
561
|
-
newPath: resolvedNewPath,
|
|
562
|
-
newName: input.newName,
|
|
563
|
-
message: 'Renamed successfully',
|
|
564
|
-
};
|
|
565
|
-
},
|
|
566
|
-
|
|
567
|
-
async deleteEntry(input) {
|
|
568
|
-
const projectRoot = await resolveProjectRoot(input.projectId);
|
|
569
|
-
const resolvedPath = resolvePathInsideProject(projectRoot, input.targetPath);
|
|
570
|
-
let stats;
|
|
571
|
-
try {
|
|
572
|
-
stats = await fileSystem.stat(resolvedPath);
|
|
573
|
-
} catch {
|
|
574
|
-
throw createFileTreeError('File or directory not found', 404, 'FILE_TREE_ENTRY_NOT_FOUND');
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
if (resolvedPath === path.resolve(projectRoot)) {
|
|
578
|
-
throw createFileTreeError('Cannot delete project root directory', 403, 'PROJECT_ROOT_DELETE_FORBIDDEN');
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
try {
|
|
582
|
-
if (stats.isDirectory()) {
|
|
583
|
-
await fileSystem.removeDirectory(resolvedPath);
|
|
584
|
-
} else {
|
|
585
|
-
await fileSystem.unlink(resolvedPath);
|
|
586
|
-
}
|
|
587
|
-
} catch (error) {
|
|
588
|
-
mapFileSystemError(error, {
|
|
589
|
-
EACCES: { message: 'Permission denied', statusCode: 403 },
|
|
590
|
-
ENOENT: { message: 'File or directory not found', statusCode: 404 },
|
|
591
|
-
ENOTEMPTY: { message: 'Directory is not empty', statusCode: 400 },
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
const entryType = stats.isDirectory() ? 'directory' as const : 'file' as const;
|
|
596
|
-
return {
|
|
597
|
-
success: true,
|
|
598
|
-
path: resolvedPath,
|
|
599
|
-
type: entryType,
|
|
600
|
-
message: 'Deleted successfully',
|
|
601
|
-
};
|
|
602
|
-
},
|
|
603
|
-
|
|
604
|
-
async storeUploadedFiles(input) {
|
|
605
|
-
if (input.files.length === 0) {
|
|
606
|
-
throw createFileTreeError('No files provided', 400, 'UPLOAD_FILES_REQUIRED');
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
try {
|
|
610
|
-
const projectRoot = await resolveProjectRoot(input.projectId);
|
|
611
|
-
const resolvedTargetDirectory = !input.targetPath
|
|
612
|
-
|| input.targetPath === '.'
|
|
613
|
-
|| input.targetPath === './'
|
|
614
|
-
? path.resolve(projectRoot)
|
|
615
|
-
: resolvePathInsideProject(projectRoot, input.targetPath);
|
|
616
|
-
|
|
617
|
-
try {
|
|
618
|
-
await fileSystem.access(resolvedTargetDirectory);
|
|
619
|
-
} catch {
|
|
620
|
-
await fileSystem.makeDirectory(resolvedTargetDirectory, true);
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
const uploadedFiles: Array<{ name: string; path: string; size: number; mimeType: string }> = [];
|
|
624
|
-
for (let fileIndex = 0; fileIndex < input.files.length; fileIndex += 1) {
|
|
625
|
-
const file = input.files[fileIndex];
|
|
626
|
-
const fileName = input.relativePaths[fileIndex] || file.originalName;
|
|
627
|
-
const destinationPath = path.join(resolvedTargetDirectory, fileName);
|
|
628
|
-
|
|
629
|
-
try {
|
|
630
|
-
resolvePathInsideProject(projectRoot, destinationPath);
|
|
631
|
-
} catch (error) {
|
|
632
|
-
if (error instanceof AppError && error.statusCode === 403) {
|
|
633
|
-
await cleanupTemporaryFiles([file]);
|
|
634
|
-
continue;
|
|
635
|
-
}
|
|
636
|
-
throw error;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
const parentDirectory = path.dirname(destinationPath);
|
|
640
|
-
try {
|
|
641
|
-
await fileSystem.access(parentDirectory);
|
|
642
|
-
} catch {
|
|
643
|
-
await fileSystem.makeDirectory(parentDirectory, true);
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
await fileSystem.copyFile(file.temporaryPath, destinationPath);
|
|
647
|
-
await fileSystem.unlink(file.temporaryPath);
|
|
648
|
-
uploadedFiles.push({
|
|
649
|
-
name: fileName,
|
|
650
|
-
path: destinationPath,
|
|
651
|
-
size: file.size,
|
|
652
|
-
mimeType: file.mimeType,
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
return {
|
|
657
|
-
success: true,
|
|
658
|
-
files: uploadedFiles,
|
|
659
|
-
uploadedCount: uploadedFiles.length,
|
|
660
|
-
requestedFileCount: input.requestedFileCount,
|
|
661
|
-
targetPath: resolvedTargetDirectory,
|
|
662
|
-
message: `Uploaded ${uploadedFiles.length} ${uploadedFiles.length === 1 ? 'file' : 'files'} successfully`,
|
|
663
|
-
};
|
|
664
|
-
} catch (error) {
|
|
665
|
-
await cleanupTemporaryFiles(input.files);
|
|
666
|
-
if (readErrorCode(error) === 'EACCES') {
|
|
667
|
-
throw createFileTreeError('Permission denied', 403, 'EACCES');
|
|
668
|
-
}
|
|
669
|
-
if (error instanceof AppError) throw error;
|
|
670
|
-
dependencies.logger.error(`Error uploading files: ${readErrorMessage(error)}`, error);
|
|
671
|
-
throw error;
|
|
672
|
-
}
|
|
673
|
-
},
|
|
674
|
-
};
|
|
675
|
-
}
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
|
|
3
|
+
import ignore from 'ignore';
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
FileTreeDirectoryEntry,
|
|
7
|
+
FileTreeNode,
|
|
8
|
+
FileTreeServiceDependencies,
|
|
9
|
+
FileTreeServices,
|
|
10
|
+
FileTreeUploadedFile,
|
|
11
|
+
} from '@/shared/types.js';
|
|
12
|
+
import { AppError, FORBIDDEN_WORKSPACE_PATHS, normalizeProjectPath } from '@/shared/utils.js';
|
|
13
|
+
|
|
14
|
+
const HARD_EXCLUDED_DIRECTORY_NAMES = new Set([
|
|
15
|
+
'node_modules', '.git', '.svn', '.hg',
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const IGNORED_DIRECTORY_NAMES = new Set([
|
|
19
|
+
...HARD_EXCLUDED_DIRECTORY_NAMES,
|
|
20
|
+
'dist', 'build', '.next', '.nuxt', '.cache', '.parcel-cache',
|
|
21
|
+
'__pycache__', '.pytest_cache', '.mypy_cache', '.tox', 'venv', '.venv',
|
|
22
|
+
'target', 'vendor',
|
|
23
|
+
'.gradle', '.idea', 'coverage', '.nyc_output',
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
const COMMON_WORKSPACE_DIRECTORY_NAMES = [
|
|
27
|
+
'Desktop',
|
|
28
|
+
'Documents',
|
|
29
|
+
'Projects',
|
|
30
|
+
'Development',
|
|
31
|
+
'Dev',
|
|
32
|
+
'Code',
|
|
33
|
+
'workspace',
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
// File Tree consumes this guard when recursively listing a project so a very
|
|
37
|
+
// broad workspace (for example, a user's home directory) cannot exhaust the
|
|
38
|
+
// server heap before the browser has a chance to switch to a narrower project.
|
|
39
|
+
const MAXIMUM_FILE_TREE_ENTRIES = 10_000;
|
|
40
|
+
|
|
41
|
+
type FileTreeEntryFilter = (entryPath: string, isDirectory: boolean) => boolean;
|
|
42
|
+
|
|
43
|
+
function includeEntryByHardExclusions(entryPath: string, isDirectory: boolean): boolean {
|
|
44
|
+
return !isDirectory || !HARD_EXCLUDED_DIRECTORY_NAMES.has(path.basename(entryPath));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function includeEntryByFallbackDirectoryNames(entryPath: string, isDirectory: boolean): boolean {
|
|
48
|
+
return includeEntryByHardExclusions(entryPath, isDirectory)
|
|
49
|
+
&& (!isDirectory || !IGNORED_DIRECTORY_NAMES.has(path.basename(entryPath)));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function createFileTreeError(message: string, statusCode: number, code: string): AppError {
|
|
53
|
+
return new AppError(message, { statusCode, code });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function readErrorCode(error: unknown): string | null {
|
|
57
|
+
return typeof error === 'object' && error !== null && 'code' in error
|
|
58
|
+
? String(error.code)
|
|
59
|
+
: null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function readErrorMessage(error: unknown): string {
|
|
63
|
+
return error instanceof Error ? error.message : String(error);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function permissionBitsToRwx(permissionBits: number): string {
|
|
67
|
+
const read = permissionBits & 4 ? 'r' : '-';
|
|
68
|
+
const write = permissionBits & 2 ? 'w' : '-';
|
|
69
|
+
const execute = permissionBits & 1 ? 'x' : '-';
|
|
70
|
+
return read + write + execute;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function validateFilename(name: string): void {
|
|
74
|
+
if (!name.trim()) {
|
|
75
|
+
throw createFileTreeError('Filename cannot be empty', 400, 'INVALID_FILENAME');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (/[<>:"/\\|?*\x00-\x1f]/.test(name)) {
|
|
79
|
+
throw createFileTreeError('Filename contains invalid characters', 400, 'INVALID_FILENAME');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (/^(CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])$/i.test(name)) {
|
|
83
|
+
throw createFileTreeError('Filename is a reserved name', 400, 'INVALID_FILENAME');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (/^\.+$/.test(name)) {
|
|
87
|
+
throw createFileTreeError('Filename cannot be only dots', 400, 'INVALID_FILENAME');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function resolvePathInsideProject(projectRoot: string, targetPath: string): string {
|
|
92
|
+
const resolvedPath = path.isAbsolute(targetPath)
|
|
93
|
+
? path.resolve(targetPath)
|
|
94
|
+
: path.resolve(projectRoot, targetPath);
|
|
95
|
+
const normalizedProjectRoot = path.resolve(projectRoot) + path.sep;
|
|
96
|
+
|
|
97
|
+
if (!resolvedPath.startsWith(normalizedProjectRoot)) {
|
|
98
|
+
throw createFileTreeError('Path must be under project root', 403, 'PATH_OUTSIDE_PROJECT');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return resolvedPath;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function expandWorkspacePath(workspaceRoot: string, inputPath: string): string {
|
|
105
|
+
if (inputPath === '~') {
|
|
106
|
+
return workspaceRoot;
|
|
107
|
+
}
|
|
108
|
+
if (inputPath.startsWith('~/') || inputPath.startsWith('~\\')) {
|
|
109
|
+
return path.join(workspaceRoot, inputPath.slice(2));
|
|
110
|
+
}
|
|
111
|
+
return inputPath;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function createConcurrencyLimiter(maximumConcurrency: number) {
|
|
115
|
+
let activeOperations = 0;
|
|
116
|
+
const pendingOperations: Array<() => void> = [];
|
|
117
|
+
|
|
118
|
+
async function acquire(): Promise<void> {
|
|
119
|
+
if (activeOperations < maximumConcurrency) {
|
|
120
|
+
activeOperations += 1;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
await new Promise<void>((resolve) => {
|
|
125
|
+
pendingOperations.push(resolve);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function release(): void {
|
|
130
|
+
const nextOperation = pendingOperations.shift();
|
|
131
|
+
if (nextOperation) {
|
|
132
|
+
nextOperation();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
activeOperations = Math.max(0, activeOperations - 1);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return { acquire, release };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function mapFileSystemError(
|
|
143
|
+
error: unknown,
|
|
144
|
+
messages: Partial<Record<string, { message: string; statusCode: number }>>,
|
|
145
|
+
): never {
|
|
146
|
+
const errorCode = readErrorCode(error);
|
|
147
|
+
const mappedError = errorCode ? messages[errorCode] : undefined;
|
|
148
|
+
if (mappedError) {
|
|
149
|
+
throw createFileTreeError(mappedError.message, mappedError.statusCode, errorCode ?? 'FILE_TREE_ERROR');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function createGitignoreEntryFilter(
|
|
156
|
+
projectRoot: string,
|
|
157
|
+
gitignoreContent: string,
|
|
158
|
+
): FileTreeEntryFilter {
|
|
159
|
+
const gitignore = ignore().add(gitignoreContent);
|
|
160
|
+
|
|
161
|
+
return (entryPath, isDirectory) => {
|
|
162
|
+
if (!includeEntryByHardExclusions(entryPath, isDirectory)) return false;
|
|
163
|
+
|
|
164
|
+
const relativePath = path.relative(projectRoot, entryPath).split(path.sep).join('/');
|
|
165
|
+
const matchPath = isDirectory ? `${relativePath}/` : relativePath;
|
|
166
|
+
return !gitignore.ignores(matchPath);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Creates File Tree workflows for the module composition root and route tests.
|
|
172
|
+
* Every filesystem, project, workspace, environment, and logging dependency is
|
|
173
|
+
* required explicitly so this service has no machine-wide production defaults.
|
|
174
|
+
*/
|
|
175
|
+
export function createFileTreeService(dependencies: FileTreeServiceDependencies): FileTreeServices {
|
|
176
|
+
const fileSystem = dependencies.fileSystem;
|
|
177
|
+
const concurrencyLimit = Number.isFinite(dependencies.fileSystemConcurrency)
|
|
178
|
+
&& dependencies.fileSystemConcurrency > 0
|
|
179
|
+
? Math.floor(dependencies.fileSystemConcurrency)
|
|
180
|
+
: 1;
|
|
181
|
+
const { acquire, release } = createConcurrencyLimiter(concurrencyLimit);
|
|
182
|
+
|
|
183
|
+
async function resolveProjectRoot(projectId: string): Promise<string> {
|
|
184
|
+
const projectRoot = await dependencies.projects.getProjectPathById(projectId);
|
|
185
|
+
if (!projectRoot) {
|
|
186
|
+
throw createFileTreeError('Project not found', 404, 'PROJECT_NOT_FOUND');
|
|
187
|
+
}
|
|
188
|
+
return projectRoot;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Streams one directory and keeps only the entries the tree will show.
|
|
193
|
+
*
|
|
194
|
+
* Entries are filtered and charged against the shared budget one at a time,
|
|
195
|
+
* so a pathologically large directory stops the walk at the cap instead of
|
|
196
|
+
* being read into memory in full first.
|
|
197
|
+
*/
|
|
198
|
+
async function collectVisibleEntries(
|
|
199
|
+
directoryPath: string,
|
|
200
|
+
includeEntry: FileTreeEntryFilter,
|
|
201
|
+
remainingEntries: { value: number },
|
|
202
|
+
): Promise<FileTreeDirectoryEntry[]> {
|
|
203
|
+
const visibleEntries: FileTreeDirectoryEntry[] = [];
|
|
204
|
+
|
|
205
|
+
await acquire();
|
|
206
|
+
try {
|
|
207
|
+
for await (const entry of fileSystem.openDirectory(directoryPath)) {
|
|
208
|
+
const isDirectory = entry.isDirectory();
|
|
209
|
+
if (!includeEntry(path.join(directoryPath, entry.name), isDirectory)) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Charged after visibility filtering so ignored entries never consume
|
|
214
|
+
// the budget. Every recursive branch shares one counter, so the cap
|
|
215
|
+
// applies to the whole tree rather than per directory.
|
|
216
|
+
if (remainingEntries.value <= 0) {
|
|
217
|
+
throw createFileTreeError(
|
|
218
|
+
`Project file tree exceeds the ${MAXIMUM_FILE_TREE_ENTRIES.toLocaleString()} entry limit. Choose a narrower project directory or add ignore rules.`,
|
|
219
|
+
413,
|
|
220
|
+
'FILE_TREE_TOO_LARGE',
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
remainingEntries.value -= 1;
|
|
224
|
+
visibleEntries.push(entry);
|
|
225
|
+
}
|
|
226
|
+
} catch (error) {
|
|
227
|
+
// The entry cap is a caller-visible outcome, not an unreadable directory.
|
|
228
|
+
if (error instanceof AppError) {
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
const errorCode = readErrorCode(error);
|
|
232
|
+
if (errorCode !== 'EACCES' && errorCode !== 'EPERM') {
|
|
233
|
+
dependencies.logger.error(`Error reading directory "${directoryPath}"`, error);
|
|
234
|
+
}
|
|
235
|
+
return [];
|
|
236
|
+
} finally {
|
|
237
|
+
release();
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return visibleEntries;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async function buildFileTree(
|
|
244
|
+
directoryPath: string,
|
|
245
|
+
maximumDepth: number,
|
|
246
|
+
currentDepth = 0,
|
|
247
|
+
includeEntry: FileTreeEntryFilter = includeEntryByFallbackDirectoryNames,
|
|
248
|
+
remainingEntries = { value: MAXIMUM_FILE_TREE_ENTRIES },
|
|
249
|
+
): Promise<FileTreeNode[]> {
|
|
250
|
+
const visibleEntries = await collectVisibleEntries(directoryPath, includeEntry, remainingEntries);
|
|
251
|
+
|
|
252
|
+
const items = await Promise.all(visibleEntries.map(async (entry): Promise<FileTreeNode> => {
|
|
253
|
+
const itemPath = path.join(directoryPath, entry.name);
|
|
254
|
+
const item: FileTreeNode = {
|
|
255
|
+
name: entry.name,
|
|
256
|
+
path: itemPath,
|
|
257
|
+
type: entry.isDirectory() ? 'directory' : 'file',
|
|
258
|
+
size: 0,
|
|
259
|
+
modified: null,
|
|
260
|
+
permissions: '000',
|
|
261
|
+
permissionsRwx: '---------',
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
await acquire();
|
|
266
|
+
try {
|
|
267
|
+
const stats = await fileSystem.lstat(itemPath);
|
|
268
|
+
const ownerPermissions = (stats.mode >> 6) & 7;
|
|
269
|
+
const groupPermissions = (stats.mode >> 3) & 7;
|
|
270
|
+
const otherPermissions = stats.mode & 7;
|
|
271
|
+
|
|
272
|
+
item.size = stats.size;
|
|
273
|
+
item.modified = stats.mtime.toISOString();
|
|
274
|
+
item.permissions = `${ownerPermissions}${groupPermissions}${otherPermissions}`;
|
|
275
|
+
item.permissionsRwx = permissionBitsToRwx(ownerPermissions)
|
|
276
|
+
+ permissionBitsToRwx(groupPermissions)
|
|
277
|
+
+ permissionBitsToRwx(otherPermissions);
|
|
278
|
+
if (stats.isSymbolicLink()) {
|
|
279
|
+
item.isSymlink = true;
|
|
280
|
+
}
|
|
281
|
+
} finally {
|
|
282
|
+
release();
|
|
283
|
+
}
|
|
284
|
+
} catch {
|
|
285
|
+
// Metadata failures should not hide an otherwise readable tree entry.
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Skip recursing into pseudo-filesystems and other system-critical
|
|
289
|
+
// directories (e.g. /proc, /sys) — they're never valid project roots,
|
|
290
|
+
// and /proc in particular can contain thousands of virtual entries
|
|
291
|
+
// that make traversal from a broad root (e.g. "/") pathologically slow.
|
|
292
|
+
const isForbiddenSystemDir = FORBIDDEN_WORKSPACE_PATHS.includes(normalizeProjectPath(itemPath));
|
|
293
|
+
|
|
294
|
+
if (entry.isDirectory() && currentDepth < maximumDepth && !isForbiddenSystemDir) {
|
|
295
|
+
item.children = await buildFileTree(
|
|
296
|
+
itemPath,
|
|
297
|
+
maximumDepth,
|
|
298
|
+
currentDepth + 1,
|
|
299
|
+
includeEntry,
|
|
300
|
+
remainingEntries,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return item;
|
|
305
|
+
}));
|
|
306
|
+
|
|
307
|
+
return items.sort((left, right) => {
|
|
308
|
+
if (left.type !== right.type) {
|
|
309
|
+
return left.type === 'directory' ? -1 : 1;
|
|
310
|
+
}
|
|
311
|
+
return left.name.localeCompare(right.name);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async function cleanupTemporaryFiles(files: FileTreeUploadedFile[]): Promise<void> {
|
|
316
|
+
await Promise.all(files.map(async (file) => {
|
|
317
|
+
try {
|
|
318
|
+
await fileSystem.unlink(file.temporaryPath);
|
|
319
|
+
} catch {
|
|
320
|
+
// A successfully moved file no longer has a temporary source to clean.
|
|
321
|
+
}
|
|
322
|
+
}));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return {
|
|
326
|
+
async browseWorkspace(inputPath) {
|
|
327
|
+
const requestedPath = inputPath
|
|
328
|
+
? expandWorkspacePath(dependencies.workspace.rootPath, inputPath)
|
|
329
|
+
: dependencies.workspace.rootPath;
|
|
330
|
+
const targetPath = path.resolve(requestedPath);
|
|
331
|
+
const validation = await dependencies.workspace.validatePath(targetPath);
|
|
332
|
+
if (!validation.valid) {
|
|
333
|
+
throw createFileTreeError(validation.error ?? 'Path is outside the workspace root', 403, 'INVALID_WORKSPACE_PATH');
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const resolvedPath = validation.resolvedPath || targetPath;
|
|
337
|
+
try {
|
|
338
|
+
await fileSystem.access(resolvedPath);
|
|
339
|
+
const stats = await fileSystem.stat(resolvedPath);
|
|
340
|
+
if (!stats.isDirectory()) {
|
|
341
|
+
throw createFileTreeError('Path is not a directory', 400, 'NOT_A_DIRECTORY');
|
|
342
|
+
}
|
|
343
|
+
} catch (error) {
|
|
344
|
+
if (error instanceof AppError) throw error;
|
|
345
|
+
throw createFileTreeError('Directory not accessible', 404, 'DIRECTORY_NOT_ACCESSIBLE');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const fileTree = await buildFileTree(resolvedPath, 1);
|
|
349
|
+
const directories = fileTree
|
|
350
|
+
.filter((item) => item.type === 'directory')
|
|
351
|
+
.map((item) => ({ path: item.path, name: item.name, type: 'directory' as const }))
|
|
352
|
+
.sort((left, right) => {
|
|
353
|
+
const leftHidden = left.name.startsWith('.');
|
|
354
|
+
const rightHidden = right.name.startsWith('.');
|
|
355
|
+
if (leftHidden && !rightHidden) return 1;
|
|
356
|
+
if (!leftHidden && rightHidden) return -1;
|
|
357
|
+
return left.name.localeCompare(right.name);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
let resolvedWorkspaceRoot = dependencies.workspace.rootPath;
|
|
361
|
+
try {
|
|
362
|
+
resolvedWorkspaceRoot = await fileSystem.realpath(dependencies.workspace.rootPath);
|
|
363
|
+
} catch {
|
|
364
|
+
// The configured workspace root remains the comparison fallback.
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const suggestions = resolvedPath === resolvedWorkspaceRoot
|
|
368
|
+
? [
|
|
369
|
+
...directories.filter((directory) => COMMON_WORKSPACE_DIRECTORY_NAMES.includes(directory.name)),
|
|
370
|
+
...directories.filter((directory) => !COMMON_WORKSPACE_DIRECTORY_NAMES.includes(directory.name)),
|
|
371
|
+
]
|
|
372
|
+
: directories;
|
|
373
|
+
|
|
374
|
+
return { path: resolvedPath, suggestions };
|
|
375
|
+
},
|
|
376
|
+
|
|
377
|
+
async createWorkspaceFolder(folderPath) {
|
|
378
|
+
const expandedPath = expandWorkspacePath(dependencies.workspace.rootPath, folderPath);
|
|
379
|
+
const resolvedInput = path.resolve(expandedPath);
|
|
380
|
+
const validation = await dependencies.workspace.validatePath(resolvedInput);
|
|
381
|
+
if (!validation.valid) {
|
|
382
|
+
throw createFileTreeError(validation.error ?? 'Path is outside the workspace root', 403, 'INVALID_WORKSPACE_PATH');
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const targetPath = validation.resolvedPath || resolvedInput;
|
|
386
|
+
try {
|
|
387
|
+
await fileSystem.access(path.dirname(targetPath));
|
|
388
|
+
} catch {
|
|
389
|
+
throw createFileTreeError('Parent directory does not exist', 404, 'PARENT_DIRECTORY_NOT_FOUND');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
try {
|
|
393
|
+
await fileSystem.access(targetPath);
|
|
394
|
+
throw createFileTreeError('Folder already exists', 409, 'FOLDER_ALREADY_EXISTS');
|
|
395
|
+
} catch (error) {
|
|
396
|
+
if (error instanceof AppError) throw error;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
try {
|
|
400
|
+
await fileSystem.makeDirectory(targetPath, false);
|
|
401
|
+
} catch (error) {
|
|
402
|
+
mapFileSystemError(error, {
|
|
403
|
+
EEXIST: { message: 'Folder already exists', statusCode: 409 },
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return { success: true, path: targetPath };
|
|
408
|
+
},
|
|
409
|
+
|
|
410
|
+
async readTextFile(projectId, filePath) {
|
|
411
|
+
const projectRoot = await resolveProjectRoot(projectId);
|
|
412
|
+
const resolvedPath = resolvePathInsideProject(projectRoot, filePath);
|
|
413
|
+
try {
|
|
414
|
+
const content = await fileSystem.readTextFile(resolvedPath);
|
|
415
|
+
return { content, path: resolvedPath };
|
|
416
|
+
} catch (error) {
|
|
417
|
+
mapFileSystemError(error, {
|
|
418
|
+
ENOENT: { message: 'File not found', statusCode: 404 },
|
|
419
|
+
EACCES: { message: 'Permission denied', statusCode: 403 },
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
|
|
424
|
+
async openFile(projectId, filePath) {
|
|
425
|
+
const projectRoot = await resolveProjectRoot(projectId);
|
|
426
|
+
const resolvedPath = resolvePathInsideProject(projectRoot, filePath);
|
|
427
|
+
try {
|
|
428
|
+
await fileSystem.access(resolvedPath);
|
|
429
|
+
} catch {
|
|
430
|
+
throw createFileTreeError('File not found', 404, 'FILE_NOT_FOUND');
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return {
|
|
434
|
+
contentType: dependencies.resolveMimeType(resolvedPath),
|
|
435
|
+
stream: fileSystem.createReadStream(resolvedPath),
|
|
436
|
+
};
|
|
437
|
+
},
|
|
438
|
+
|
|
439
|
+
async saveTextFile(projectId, filePath, content) {
|
|
440
|
+
const projectRoot = await resolveProjectRoot(projectId);
|
|
441
|
+
const resolvedPath = resolvePathInsideProject(projectRoot, filePath);
|
|
442
|
+
try {
|
|
443
|
+
await fileSystem.writeTextFile(resolvedPath, content);
|
|
444
|
+
} catch (error) {
|
|
445
|
+
mapFileSystemError(error, {
|
|
446
|
+
ENOENT: { message: 'File or directory not found', statusCode: 404 },
|
|
447
|
+
EACCES: { message: 'Permission denied', statusCode: 403 },
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return { success: true, path: resolvedPath, message: 'File saved successfully' };
|
|
452
|
+
},
|
|
453
|
+
|
|
454
|
+
async listProjectFiles(projectId, options) {
|
|
455
|
+
const projectRoot = await resolveProjectRoot(projectId);
|
|
456
|
+
try {
|
|
457
|
+
await fileSystem.access(projectRoot);
|
|
458
|
+
} catch {
|
|
459
|
+
throw createFileTreeError(`Project path not found: ${projectRoot}`, 404, 'PROJECT_PATH_NOT_FOUND');
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
let includeEntry: FileTreeEntryFilter | undefined;
|
|
463
|
+
if (options?.respectGitignore) {
|
|
464
|
+
try {
|
|
465
|
+
const gitignoreContent = await fileSystem.readTextFile(path.join(projectRoot, '.gitignore'));
|
|
466
|
+
includeEntry = createGitignoreEntryFilter(projectRoot, gitignoreContent);
|
|
467
|
+
} catch (error) {
|
|
468
|
+
if (readErrorCode(error) !== 'ENOENT') {
|
|
469
|
+
dependencies.logger.error(`Error reading .gitignore in "${projectRoot}"`, error);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
return buildFileTree(projectRoot, 10, 0, includeEntry);
|
|
475
|
+
},
|
|
476
|
+
|
|
477
|
+
async createEntry(input) {
|
|
478
|
+
validateFilename(input.name);
|
|
479
|
+
const projectRoot = await resolveProjectRoot(input.projectId);
|
|
480
|
+
const targetPath = input.parentPath
|
|
481
|
+
? path.join(input.parentPath, input.name)
|
|
482
|
+
: input.name;
|
|
483
|
+
const resolvedPath = resolvePathInsideProject(projectRoot, targetPath);
|
|
484
|
+
|
|
485
|
+
try {
|
|
486
|
+
await fileSystem.access(resolvedPath);
|
|
487
|
+
throw createFileTreeError(
|
|
488
|
+
`${input.type === 'file' ? 'File' : 'Directory'} already exists`,
|
|
489
|
+
409,
|
|
490
|
+
'FILE_TREE_ENTRY_EXISTS',
|
|
491
|
+
);
|
|
492
|
+
} catch (error) {
|
|
493
|
+
if (error instanceof AppError) throw error;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
try {
|
|
497
|
+
if (input.type === 'directory') {
|
|
498
|
+
await fileSystem.makeDirectory(resolvedPath, false);
|
|
499
|
+
} else {
|
|
500
|
+
const parentDirectory = path.dirname(resolvedPath);
|
|
501
|
+
try {
|
|
502
|
+
await fileSystem.access(parentDirectory);
|
|
503
|
+
} catch {
|
|
504
|
+
await fileSystem.makeDirectory(parentDirectory, true);
|
|
505
|
+
}
|
|
506
|
+
await fileSystem.writeTextFile(resolvedPath, '');
|
|
507
|
+
}
|
|
508
|
+
} catch (error) {
|
|
509
|
+
mapFileSystemError(error, {
|
|
510
|
+
EACCES: { message: 'Permission denied', statusCode: 403 },
|
|
511
|
+
ENOENT: { message: 'Parent directory not found', statusCode: 404 },
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
return {
|
|
516
|
+
success: true,
|
|
517
|
+
path: resolvedPath,
|
|
518
|
+
name: input.name,
|
|
519
|
+
type: input.type,
|
|
520
|
+
message: `${input.type === 'file' ? 'File' : 'Directory'} created successfully`,
|
|
521
|
+
};
|
|
522
|
+
},
|
|
523
|
+
|
|
524
|
+
async renameEntry(input) {
|
|
525
|
+
validateFilename(input.newName);
|
|
526
|
+
const projectRoot = await resolveProjectRoot(input.projectId);
|
|
527
|
+
const resolvedOldPath = resolvePathInsideProject(projectRoot, input.oldPath);
|
|
528
|
+
|
|
529
|
+
try {
|
|
530
|
+
await fileSystem.access(resolvedOldPath);
|
|
531
|
+
} catch {
|
|
532
|
+
throw createFileTreeError('File or directory not found', 404, 'FILE_TREE_ENTRY_NOT_FOUND');
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
const resolvedNewPath = path.join(path.dirname(resolvedOldPath), input.newName);
|
|
536
|
+
resolvePathInsideProject(projectRoot, resolvedNewPath);
|
|
537
|
+
try {
|
|
538
|
+
await fileSystem.access(resolvedNewPath);
|
|
539
|
+
throw createFileTreeError(
|
|
540
|
+
'A file or directory with this name already exists',
|
|
541
|
+
409,
|
|
542
|
+
'FILE_TREE_ENTRY_EXISTS',
|
|
543
|
+
);
|
|
544
|
+
} catch (error) {
|
|
545
|
+
if (error instanceof AppError) throw error;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
try {
|
|
549
|
+
await fileSystem.rename(resolvedOldPath, resolvedNewPath);
|
|
550
|
+
} catch (error) {
|
|
551
|
+
mapFileSystemError(error, {
|
|
552
|
+
EACCES: { message: 'Permission denied', statusCode: 403 },
|
|
553
|
+
ENOENT: { message: 'File or directory not found', statusCode: 404 },
|
|
554
|
+
EXDEV: { message: 'Cannot move across different filesystems', statusCode: 400 },
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return {
|
|
559
|
+
success: true,
|
|
560
|
+
oldPath: resolvedOldPath,
|
|
561
|
+
newPath: resolvedNewPath,
|
|
562
|
+
newName: input.newName,
|
|
563
|
+
message: 'Renamed successfully',
|
|
564
|
+
};
|
|
565
|
+
},
|
|
566
|
+
|
|
567
|
+
async deleteEntry(input) {
|
|
568
|
+
const projectRoot = await resolveProjectRoot(input.projectId);
|
|
569
|
+
const resolvedPath = resolvePathInsideProject(projectRoot, input.targetPath);
|
|
570
|
+
let stats;
|
|
571
|
+
try {
|
|
572
|
+
stats = await fileSystem.stat(resolvedPath);
|
|
573
|
+
} catch {
|
|
574
|
+
throw createFileTreeError('File or directory not found', 404, 'FILE_TREE_ENTRY_NOT_FOUND');
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (resolvedPath === path.resolve(projectRoot)) {
|
|
578
|
+
throw createFileTreeError('Cannot delete project root directory', 403, 'PROJECT_ROOT_DELETE_FORBIDDEN');
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
try {
|
|
582
|
+
if (stats.isDirectory()) {
|
|
583
|
+
await fileSystem.removeDirectory(resolvedPath);
|
|
584
|
+
} else {
|
|
585
|
+
await fileSystem.unlink(resolvedPath);
|
|
586
|
+
}
|
|
587
|
+
} catch (error) {
|
|
588
|
+
mapFileSystemError(error, {
|
|
589
|
+
EACCES: { message: 'Permission denied', statusCode: 403 },
|
|
590
|
+
ENOENT: { message: 'File or directory not found', statusCode: 404 },
|
|
591
|
+
ENOTEMPTY: { message: 'Directory is not empty', statusCode: 400 },
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
const entryType = stats.isDirectory() ? 'directory' as const : 'file' as const;
|
|
596
|
+
return {
|
|
597
|
+
success: true,
|
|
598
|
+
path: resolvedPath,
|
|
599
|
+
type: entryType,
|
|
600
|
+
message: 'Deleted successfully',
|
|
601
|
+
};
|
|
602
|
+
},
|
|
603
|
+
|
|
604
|
+
async storeUploadedFiles(input) {
|
|
605
|
+
if (input.files.length === 0) {
|
|
606
|
+
throw createFileTreeError('No files provided', 400, 'UPLOAD_FILES_REQUIRED');
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
try {
|
|
610
|
+
const projectRoot = await resolveProjectRoot(input.projectId);
|
|
611
|
+
const resolvedTargetDirectory = !input.targetPath
|
|
612
|
+
|| input.targetPath === '.'
|
|
613
|
+
|| input.targetPath === './'
|
|
614
|
+
? path.resolve(projectRoot)
|
|
615
|
+
: resolvePathInsideProject(projectRoot, input.targetPath);
|
|
616
|
+
|
|
617
|
+
try {
|
|
618
|
+
await fileSystem.access(resolvedTargetDirectory);
|
|
619
|
+
} catch {
|
|
620
|
+
await fileSystem.makeDirectory(resolvedTargetDirectory, true);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const uploadedFiles: Array<{ name: string; path: string; size: number; mimeType: string }> = [];
|
|
624
|
+
for (let fileIndex = 0; fileIndex < input.files.length; fileIndex += 1) {
|
|
625
|
+
const file = input.files[fileIndex];
|
|
626
|
+
const fileName = input.relativePaths[fileIndex] || file.originalName;
|
|
627
|
+
const destinationPath = path.join(resolvedTargetDirectory, fileName);
|
|
628
|
+
|
|
629
|
+
try {
|
|
630
|
+
resolvePathInsideProject(projectRoot, destinationPath);
|
|
631
|
+
} catch (error) {
|
|
632
|
+
if (error instanceof AppError && error.statusCode === 403) {
|
|
633
|
+
await cleanupTemporaryFiles([file]);
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
throw error;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const parentDirectory = path.dirname(destinationPath);
|
|
640
|
+
try {
|
|
641
|
+
await fileSystem.access(parentDirectory);
|
|
642
|
+
} catch {
|
|
643
|
+
await fileSystem.makeDirectory(parentDirectory, true);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
await fileSystem.copyFile(file.temporaryPath, destinationPath);
|
|
647
|
+
await fileSystem.unlink(file.temporaryPath);
|
|
648
|
+
uploadedFiles.push({
|
|
649
|
+
name: fileName,
|
|
650
|
+
path: destinationPath,
|
|
651
|
+
size: file.size,
|
|
652
|
+
mimeType: file.mimeType,
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
return {
|
|
657
|
+
success: true,
|
|
658
|
+
files: uploadedFiles,
|
|
659
|
+
uploadedCount: uploadedFiles.length,
|
|
660
|
+
requestedFileCount: input.requestedFileCount,
|
|
661
|
+
targetPath: resolvedTargetDirectory,
|
|
662
|
+
message: `Uploaded ${uploadedFiles.length} ${uploadedFiles.length === 1 ? 'file' : 'files'} successfully`,
|
|
663
|
+
};
|
|
664
|
+
} catch (error) {
|
|
665
|
+
await cleanupTemporaryFiles(input.files);
|
|
666
|
+
if (readErrorCode(error) === 'EACCES') {
|
|
667
|
+
throw createFileTreeError('Permission denied', 403, 'EACCES');
|
|
668
|
+
}
|
|
669
|
+
if (error instanceof AppError) throw error;
|
|
670
|
+
dependencies.logger.error(`Error uploading files: ${readErrorMessage(error)}`, error);
|
|
671
|
+
throw error;
|
|
672
|
+
}
|
|
673
|
+
},
|
|
674
|
+
};
|
|
675
|
+
}
|