@openchamber/web 1.18.3 → 1.19.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.
Files changed (215) hide show
  1. package/README.md +1 -0
  2. package/dist/assets/{CodeMirrorCommentWidgets-DbUi6I9s.js → CodeMirrorCommentWidgets-DAvopJvy.js} +1 -1
  3. package/dist/assets/{CommitSection-Jc2_hNPE.js → CommitSection-D9cV-qR9.js} +1 -1
  4. package/dist/assets/{DiagramEditor-PCrYHBko.js → DiagramEditor-B9NCadU7.js} +1 -1
  5. package/dist/assets/DiagramView-LKGBwf4G.js +1 -0
  6. package/dist/assets/{DiffView-DEGlNjMH.js → DiffView-BWNq-0ov.js} +2 -2
  7. package/dist/assets/FilesView-DB-Q0Gkz.js +14 -0
  8. package/dist/assets/{GitView-C-n17voy.js → GitView-DsWXqWx3.js} +3 -3
  9. package/dist/assets/{JsonTreeView-BYcgdTOQ.js → JsonTreeView-h4dHASlq.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +12 -0
  12. package/dist/assets/OnboardingScreen-CDjgzxEe.js +1 -0
  13. package/dist/assets/{PatchDiff-Bn7bfgUv.js → PatchDiff-jPKTJje5.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-D1fWvrUn.js → PierreDiffViewer-D_Gt4A_6.js} +1 -1
  15. package/dist/assets/PlanView-UvuxIl9-.js +4 -0
  16. package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +1 -0
  17. package/dist/assets/SettingsView-3B9VN6Ys.js +28 -0
  18. package/dist/assets/SettingsWindow-CqQNDKNd.js +1 -0
  19. package/dist/assets/{ToolOutputDialog-BtIJkFno.js → ToolOutputDialog-PmjlAxVE.js} +6 -6
  20. package/dist/assets/{ToolPartDiffPreview-i3PQo6_0.js → ToolPartDiffPreview-B34Xw9wq.js} +1 -1
  21. package/dist/assets/{VirtualizedFileDiff-DkcusvMa.js → VirtualizedFileDiff-B37yB9jZ.js} +3 -3
  22. package/dist/assets/{WalkthroughView-Cc5Hd6P5.js → WalkthroughView-Bxun3k66.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-xPena3W2.js → computeVirtualFileMetrics-DYFv_yZS.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +1 -0
  25. package/dist/assets/de-DbV6CLxv.js +9 -0
  26. package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
  27. package/dist/assets/es-CVDlyzZ4.js +15 -0
  28. package/dist/assets/fr-Czc-p0g-.js +13 -0
  29. package/dist/assets/index-1OhiMDBz.css +1 -0
  30. package/dist/assets/index-BSvmTvZl.js +1 -0
  31. package/dist/assets/index-DzriVon2.js +7 -0
  32. package/dist/assets/{isDiffPlainText-Dudf-dWx.js → isDiffPlainText-DwHKxDYc.js} +1 -1
  33. package/dist/assets/{isFilePlainText-DS4QV1dd.js → isFilePlainText-Dwq6ILxo.js} +1 -1
  34. package/dist/assets/ja-dwc9NM_S.js +15 -0
  35. package/dist/assets/ko-Ds1DZ8FX.js +15 -0
  36. package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
  37. package/dist/assets/main-BF51IOVF.js +921 -0
  38. package/dist/assets/{main-C0DyIwTb.js → main-D7UPARut.js} +2 -2
  39. package/dist/assets/markdownCore-BgeBDwD3.js +2 -0
  40. package/dist/assets/{miniChat-CGfrxKpJ.js → miniChat-BISXSGOo.js} +2 -2
  41. package/dist/assets/mobile-BnYxVuvw.js +2 -0
  42. package/dist/assets/{patchFileDiff-C5D1OPCa.js → patchFileDiff-BEDPDypx.js} +2 -2
  43. package/dist/assets/pl-CLiTO7i-.js +15 -0
  44. package/dist/assets/pt-BR-GIimJgpK.js +15 -0
  45. package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +2 -0
  46. package/dist/assets/{renderMobileApp-B5HA4qbi.js → renderMobileApp-BiMbzPq9.js} +7 -7
  47. package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +15 -0
  48. package/dist/assets/scheduledTasksApi-01zzfzqH.js +1 -0
  49. package/dist/assets/{shikiHighlight-CmanopUB.js → shikiHighlight-DXYW46vW.js} +1 -1
  50. package/dist/assets/uk-DLfgD1ki.js +15 -0
  51. package/dist/assets/{useAppFontEffects-sHmU5b8u.js → useAppFontEffects-CbzHzFop.js} +139 -142
  52. package/dist/assets/{useInlineCommentController-gt56WkxJ.js → useInlineCommentController-CegKdDXi.js} +2 -2
  53. package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-BYlZTzrw.js} +1 -1
  54. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
  55. package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
  56. package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
  60. package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
  61. package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
  62. package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
  63. package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
  67. package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
  68. package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
  77. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
  78. package/dist/assets/{vendor-codemirror-language-data-Dihw9MtL.js → vendor-codemirror-language-data-CiAYDJXN.js} +2 -2
  79. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
  80. package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
  81. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
  82. package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
  83. package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
  84. package/dist/assets/vendor-zod-adaMkgkm.js +39 -0
  85. package/dist/assets/{web-components-BL-Ur2Tb.js → web-components-DCLjCO9n.js} +1 -1
  86. package/dist/assets/zh-CN-DkeP5awK.js +15 -0
  87. package/dist/assets/zh-TW-BocaFm3d.js +15 -0
  88. package/dist/index.html +4 -4
  89. package/dist/mini-chat.html +3 -3
  90. package/dist/mobile.html +3 -3
  91. package/package.json +1 -1
  92. package/server/index.js +116 -3
  93. package/server/lib/agent-memory/actions.js +243 -0
  94. package/server/lib/agent-memory/actions.test.js +343 -0
  95. package/server/lib/agent-memory/feature-flag.js +19 -0
  96. package/server/lib/agent-memory/feature-flag.test.js +38 -0
  97. package/server/lib/agent-memory/project-resolution.js +56 -0
  98. package/server/lib/agent-memory/project-resolution.test.js +85 -0
  99. package/server/lib/agent-memory/routes.http.test.js +270 -0
  100. package/server/lib/agent-memory/routes.js +169 -0
  101. package/server/lib/agent-memory/runtime.js +427 -0
  102. package/server/lib/agent-memory/runtime.test.js +344 -0
  103. package/server/lib/agent-memory/threat-patterns.js +61 -0
  104. package/server/lib/agent-memory/threat-patterns.test.js +61 -0
  105. package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
  106. package/server/lib/agent-tool/runtime.js +63 -13
  107. package/server/lib/agent-tool/runtime.test.js +85 -2
  108. package/server/lib/context-obligatory/runtime.js +34 -3
  109. package/server/lib/context-obligatory/runtime.test.js +114 -0
  110. package/server/lib/dev-tunnel/client.js +20 -1
  111. package/server/lib/dev-tunnel/tunnel.test.js +9 -0
  112. package/server/lib/fs/DOCUMENTATION.md +3 -0
  113. package/server/lib/fs/routes.js +149 -32
  114. package/server/lib/fs/routes.test.js +225 -0
  115. package/server/lib/git/DOCUMENTATION.md +8 -0
  116. package/server/lib/git/service.js +121 -67
  117. package/server/lib/git/service.test.js +129 -0
  118. package/server/lib/github/DOCUMENTATION.md +14 -3
  119. package/server/lib/github/pr-status.js +188 -83
  120. package/server/lib/github/pr-status.test.js +182 -0
  121. package/server/lib/github/routes.js +36 -30
  122. package/server/lib/markdown-image-grants/DOCUMENTATION.md +36 -0
  123. package/server/lib/markdown-image-grants/routes.js +340 -0
  124. package/server/lib/markdown-image-grants/routes.test.js +221 -0
  125. package/server/lib/notifications/template-runtime.js +2 -3
  126. package/server/lib/openchamber-control/action-resolution.test.js +65 -0
  127. package/server/lib/openchamber-control/actions.js +78 -0
  128. package/server/lib/openchamber-control/service.js +7 -0
  129. package/server/lib/openchamber-sessions/routes.js +14 -0
  130. package/server/lib/opencode/DOCUMENTATION.md +6 -4
  131. package/server/lib/opencode/claude-cli-auth.js +60 -0
  132. package/server/lib/opencode/claude-cli-auth.test.js +54 -0
  133. package/server/lib/opencode/feature-routes-runtime.js +22 -0
  134. package/server/lib/opencode/plugins.js +12 -3
  135. package/server/lib/opencode/plugins.test.js +18 -0
  136. package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
  137. package/server/lib/opencode/proxy.js +116 -6
  138. package/server/lib/opencode/proxy.test.js +158 -1
  139. package/server/lib/opencode/routes.js +4 -1
  140. package/server/lib/opencode/server-startup-runtime.js +22 -1
  141. package/server/lib/opencode/server-startup-runtime.test.js +44 -0
  142. package/server/lib/opencode/settings-helpers.js +11 -0
  143. package/server/lib/opencode/settings-helpers.test.js +35 -0
  144. package/server/lib/opencode/settings-runtime.js +51 -0
  145. package/server/lib/opencode/shared.js +120 -16
  146. package/server/lib/opencode/shared.test.js +185 -1
  147. package/server/lib/project-context/DOCUMENTATION.md +158 -0
  148. package/server/lib/project-context/routes.http.test.js +264 -0
  149. package/server/lib/project-context/routes.js +237 -0
  150. package/server/lib/project-context/runtime.js +667 -0
  151. package/server/lib/project-context/runtime.test.js +498 -0
  152. package/server/lib/quota/DOCUMENTATION.md +16 -1
  153. package/server/lib/quota/providers/claude/auth.js +113 -0
  154. package/server/lib/quota/providers/claude/auth.test.js +117 -0
  155. package/server/lib/quota/providers/claude/index.js +151 -0
  156. package/server/lib/quota/providers/claude/index.test.js +147 -0
  157. package/server/lib/quota/providers/claude/transforms.js +127 -0
  158. package/server/lib/quota/providers/claude/transforms.test.js +82 -0
  159. package/server/lib/quota/providers/command-code.js +90 -0
  160. package/server/lib/quota/providers/command-code.test.js +72 -0
  161. package/server/lib/quota/providers/index.js +22 -2
  162. package/server/lib/quota/providers/index.test.js +10 -1
  163. package/server/lib/quota/utils/formatters.js +2 -1
  164. package/server/lib/scheduled-tasks/runtime.js +21 -2
  165. package/server/lib/session-knowledge/DOCUMENTATION.md +87 -0
  166. package/server/lib/session-knowledge/routes.js +107 -0
  167. package/server/lib/session-knowledge/runtime.js +331 -0
  168. package/server/lib/session-knowledge/runtime.test.js +275 -0
  169. package/server/lib/skills-catalog/DOCUMENTATION.md +22 -22
  170. package/server/lib/skills-catalog/curated-sources.js +1 -1
  171. package/server/lib/skills-catalog/curated-sources.test.js +10 -0
  172. package/server/lib/small-model/index.js +8 -0
  173. package/server/lib/small-model/index.test.js +31 -1
  174. package/server/lib/small-model/routes.js +3 -1
  175. package/dist/assets/DiagramView-CndEcZNu.js +0 -1
  176. package/dist/assets/FilesView-CzUgIvUm.js +0 -14
  177. package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +0 -1
  178. package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +0 -12
  179. package/dist/assets/OnboardingScreen-BmN0lhk4.js +0 -1
  180. package/dist/assets/PlanView-CWM0iyFk.js +0 -4
  181. package/dist/assets/SessionSwitcherDropdown-Cez-9xRh.js +0 -1
  182. package/dist/assets/SettingsView-Bl1drwPw.js +0 -28
  183. package/dist/assets/SettingsWindow-DL5axjDZ.js +0 -1
  184. package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +0 -1
  185. package/dist/assets/de-u7gSnqWs.js +0 -9
  186. package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
  187. package/dist/assets/es-T9O7aAOr.js +0 -15
  188. package/dist/assets/fr-Oor7ewbE.js +0 -13
  189. package/dist/assets/index-CVNuER6G.css +0 -1
  190. package/dist/assets/index-Crz1YOFl.js +0 -1
  191. package/dist/assets/index-iFY_N5aO.js +0 -7
  192. package/dist/assets/ja-DHpqbVmr.js +0 -15
  193. package/dist/assets/ko-CwLkS3nx.js +0 -15
  194. package/dist/assets/main-CAxX6DAN.js +0 -915
  195. package/dist/assets/markdownCore-DhfzuGXu.js +0 -2
  196. package/dist/assets/markdownImageAssets-BTNlRyjd.js +0 -1
  197. package/dist/assets/mobile-DEmhwNcV.js +0 -2
  198. package/dist/assets/pl-CcZILN8q.js +0 -15
  199. package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
  200. package/dist/assets/renderElectronMiniChatApp-Dpbswpom.js +0 -2
  201. package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +0 -13
  202. package/dist/assets/scheduledTasksApi-BxgGWTL8.js +0 -1
  203. package/dist/assets/uk-BA2kZR38.js +0 -15
  204. package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
  205. package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
  206. package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
  207. package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
  208. package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
  209. package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
  210. package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
  211. package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
  212. package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
  213. package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
  214. package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
  215. package/server/lib/quota/providers/claude.js +0 -107
@@ -1,21 +1,21 @@
1
1
  # Skills Catalog Module Documentation
2
2
 
3
3
  ## Purpose
4
- This module provides skill discovery, scanning, and installation capabilities for OpenCode. It supports multiple skill sources including git repositories and the ClawdHub registry, with caching and conflict resolution for skill installation.
4
+ This module provides skill discovery, scanning, and installation capabilities for OpenCode. It supports multiple skill sources including git repositories and the ClawHub registry, with caching and conflict resolution for skill installation.
5
5
 
6
6
  ## Entrypoints and structure
7
7
  - `packages/web/server/lib/skills-catalog/`: Skills catalog module directory containing all skill-related functionality.
8
8
  - `cache.js`: In-memory cache for scan results with TTL support.
9
- - `curated-sources.js`: Predefined skill sources (Anthropic, ClawdHub).
9
+ - `curated-sources.js`: Predefined skill sources (Anthropic, ClawHub).
10
10
  - `git.js`: Git operations helpers for cloning and auth error detection.
11
11
  - `install.js`: Skills installation from git repositories.
12
12
  - `scan.js`: Skills scanning from git repositories.
13
13
  - `source.js`: Source string parsing for git repositories.
14
- - `clawdhub/`: ClawdHub registry integration.
15
- - `index.js`: Public API exports for ClawdHub.
16
- - `scan.js`: Scanning ClawdHub registry with pagination.
17
- - `install.js`: Installation from ClawdHub (ZIP download).
18
- - `api.js`: ClawdHub API client with rate limiting.
14
+ - `clawdhub/`: ClawHub registry integration.
15
+ - `index.js`: Public API exports for ClawHub.
16
+ - `scan.js`: Scanning ClawHub registry with pagination.
17
+ - `install.js`: Installation from ClawHub (ZIP download).
18
+ - `api.js`: ClawHub API client with rate limiting.
19
19
 
20
20
  ## Public API
21
21
 
@@ -28,7 +28,7 @@ The following functions are exported and used by the web server:
28
28
  - `clearCache()`: Clear all cached scan results.
29
29
 
30
30
  ### Curated Sources (`curated-sources.js`)
31
- - `getCuratedSkillsSources()`: Return list of curated skill sources (Anthropic, ClawdHub).
31
+ - `getCuratedSkillsSources()`: Return list of curated skill sources (Anthropic, ClawHub).
32
32
  - `CURATED_SKILLS_SOURCES`: Constant array of predefined sources.
33
33
 
34
34
  ### Source Parsing (`source.js`)
@@ -40,17 +40,17 @@ The following functions are exported and used by the web server:
40
40
  ### Git Repository Installation (`install.js`)
41
41
  - `installSkillsFromRepository({ source, subpath, defaultSubpath, identity, scope, targetSource, workingDirectory, userSkillDir, selections, conflictPolicy, conflictDecisions })`: Install skills from git repository. Supports user/project scopes, opencode/agents targets, conflict resolution (prompt/skipAll/overwriteAll), and sparse checkout for efficiency.
42
42
 
43
- ### ClawdHub Integration (`clawdhub/index.js`)
44
- - `isClawdHubSource(source)`: Check if source string refers to ClawdHub.
45
- - `scanClawdHub()`: Scan entire ClawdHub registry for all skills (paginated, max 20 pages).
46
- - `scanClawdHubPage({ cursor })`: Scan a single page of ClawdHub results with cursor-based pagination.
47
- - `installSkillsFromClawdHub({ scope, targetSource, workingDirectory, userSkillDir, selections, conflictPolicy, conflictDecisions })`: Install skills from ClawdHub by downloading ZIP files.
48
- - `fetchClawdHubSkills({ cursor })`: Fetch paginated skills list from ClawdHub API.
43
+ ### ClawHub Integration (`clawdhub/index.js`)
44
+ - `isClawdHubSource(source)`: Check if source string refers to ClawHub.
45
+ - `scanClawdHub()`: Scan entire ClawHub registry for all skills (paginated, max 20 pages).
46
+ - `scanClawdHubPage({ cursor })`: Scan a single page of ClawHub results with cursor-based pagination.
47
+ - `installSkillsFromClawdHub({ scope, targetSource, workingDirectory, userSkillDir, selections, conflictPolicy, conflictDecisions })`: Install skills from ClawHub by downloading ZIP files.
48
+ - `fetchClawdHubSkills({ cursor })`: Fetch paginated skills list from ClawHub API.
49
49
  - `fetchClawdHubSkillVersion(slug, version)`: Fetch specific skill version details.
50
50
  - `fetchClawdHubSkillInfo(slug)`: Fetch skill metadata without version details.
51
51
  - `downloadClawdHubSkill(slug, version)`: Download skill package as ZIP buffer.
52
52
 
53
- ### ClawdHub Constants (`clawdhub/index.js`)
53
+ ### ClawHub Constants (`clawdhub/index.js`)
54
54
  - `CLAWDHUB_SOURCE_ID`: Source identifier for curated sources.
55
55
  - `CLAWDHUB_SOURCE_STRING`: Source string format.
56
56
 
@@ -82,9 +82,9 @@ The following functions are internal helpers used by exported functions:
82
82
  - `toFsPath(repoDir, repoRelPosixPath)`: Convert POSIX path to filesystem path.
83
83
  - `getTargetSkillDir({ scope, targetSource, workingDirectory, userSkillDir, skillName })`: Determine target installation directory based on scope (user/project), targetSource (opencode/agents), and skill name.
84
84
 
85
- ### ClawdHub API Helpers (`clawdhub/api.js`)
85
+ ### ClawHub API Helpers (`clawdhub/api.js`)
86
86
  - `rateLimitedFetch(url, options)`: Fetch with rate limiting (120 req/min limit, 100ms delay between requests, exponential backoff on 429/500 errors).
87
- - `mapClawdHubItem(item)`: Transform ClawdHub API response to SkillsCatalogItem format.
87
+ - `mapClawdHubItem(item)`: Transform ClawHub API response to SkillsCatalogItem format.
88
88
 
89
89
  ## Response Contracts
90
90
 
@@ -101,9 +101,9 @@ The following functions are internal helpers used by exported functions:
101
101
  - `skipped`: Array of skipped skills with `{ skillName, reason }`.
102
102
  - `error`: Error object with `{ kind, message, conflicts? }` on failure. Kinds: `authRequired`, `networkError`, `conflicts`, `invalidSource`, `unknown`.
103
103
 
104
- ### ClawdHub Scan Response
104
+ ### ClawHub Scan Response
105
105
  - `ok`: Boolean indicating success.
106
- - `items`: Array of skill items with ClawdHub-specific metadata in `clawdhub` property.
106
+ - `items`: Array of skill items with ClawHub-specific metadata in `clawdhub` property.
107
107
  - `nextCursor`: Pagination cursor for next page (only for `scanClawdHubPage`).
108
108
  - `error`: Error object with `{ kind, message }` on failure.
109
109
 
@@ -129,7 +129,7 @@ The following functions are internal helpers used by exported functions:
129
129
 
130
130
  ### Skill Name Validation
131
131
  - All skill names must match `/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/` (1-64 chars).
132
- - Skill names are derived from directory basenames for git repos and slugs for ClawdHub.
132
+ - Skill names are derived from directory basenames for git repos and slugs for ClawHub.
133
133
  - Invalid names result in non-installable skills with appropriate warnings.
134
134
 
135
135
  ### Git Cloning Strategy
@@ -144,8 +144,8 @@ The following functions are internal helpers used by exported functions:
144
144
  - Per-skill decisions override global policy via `conflictDecisions` map.
145
145
  - Conflict response includes `{ skillName, scope, source }` for each conflict.
146
146
 
147
- ### ClawdHub Integration
148
- - ClawdHub API base URL: `https://clawdhub.com/api/v1`.
147
+ ### ClawHub Integration
148
+ - ClawHub API base URL: `https://clawdhub.com/api/v1`.
149
149
  - Pagination uses cursor-based approach with `MAX_PAGES=20` safety limit.
150
150
  - Rate limiting: 120 req/min with 100ms delay between requests.
151
151
  - Downloaded skills are extracted from ZIP files using `adm-zip`.
@@ -9,7 +9,7 @@ const CURATED_SKILLS_SOURCES = [
9
9
  },
10
10
  {
11
11
  id: 'clawdhub',
12
- label: 'ClawdHub',
12
+ label: 'ClawHub',
13
13
  description: 'Community skill registry with vector search',
14
14
  source: 'clawdhub:registry',
15
15
  sourceType: 'clawdhub',
@@ -0,0 +1,10 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { getCuratedSkillsSources } from './curated-sources.js';
3
+
4
+ describe('getCuratedSkillsSources', () => {
5
+ it('labels the ClawHub curated source as ClawHub', () => {
6
+ const clawhub = getCuratedSkillsSources().find((source) => source.id === 'clawdhub');
7
+ expect(clawhub).toBeDefined();
8
+ expect(clawhub.label).toBe('ClawHub');
9
+ });
10
+ });
@@ -120,6 +120,13 @@ export async function generateSmallModelText({ prompt, system, maxOutputTokens,
120
120
  );
121
121
  }
122
122
 
123
+ if (resolved.providerID === 'claude-code') {
124
+ throw Object.assign(
125
+ new Error('Claude Code cannot be used for background small-model actions. Choose another Small Model in Settings → Sessions.'),
126
+ { statusCode: 422, code: 'small-model-provider-unsupported' },
127
+ );
128
+ }
129
+
123
130
  // Callers with a session context can forbid silently switching providers:
124
131
  // an explicit user choice (settings override, opencode config, request
125
132
  // model) is always allowed, anything else must stay on the session's
@@ -183,6 +190,7 @@ export function listAuthenticatedProviders() {
183
190
  const ids = new Set(
184
191
  Object.keys(auth || {}).filter((providerID) => isUsableAuthEntry(auth[providerID])),
185
192
  );
193
+ ids.delete('claude-code');
186
194
  // The catalog id is github-copilot while legacy auth entries may sit
187
195
  // under the copilot alias.
188
196
  if (isUsableAuthEntry(getAuthEntryForProvider(auth, 'github-copilot'))) {
@@ -26,12 +26,42 @@ vi.mock('./call.js', () => ({
26
26
  }),
27
27
  }));
28
28
 
29
- const { generateSmallModelText, describeSmallModel } = await import('./index.js');
29
+ const { generateSmallModelText, describeSmallModel, listAuthenticatedProviders } = await import('./index.js');
30
30
  const { readAuthFile } = await import('../opencode/auth.js');
31
31
  const { readConfigLayers } = await import('../opencode/shared.js');
32
32
  const { getModelCatalog } = await import('./catalog.js');
33
33
  const { callSmallModel } = await import('./call.js');
34
34
 
35
+ describe('unsupported small-model providers', () => {
36
+ beforeEach(() => {
37
+ readAuthFile.mockReturnValue({
38
+ 'claude-code': {
39
+ type: 'oauth',
40
+ access: 'claude-cli-managed',
41
+ refresh: 'claude-cli-managed',
42
+ },
43
+ });
44
+ readConfigLayers.mockReturnValue({ mergedConfig: {} });
45
+ getModelCatalog.mockResolvedValue({});
46
+ callSmallModel.mockReset();
47
+ });
48
+
49
+ it('rejects Claude Code with an actionable error before transport dispatch', async () => {
50
+ await expect(generateSmallModelText({
51
+ prompt: 'summarize this',
52
+ model: 'claude-code/haiku',
53
+ })).rejects.toMatchObject({
54
+ statusCode: 422,
55
+ code: 'small-model-provider-unsupported',
56
+ });
57
+ expect(callSmallModel).not.toHaveBeenCalled();
58
+ });
59
+
60
+ it('does not offer Claude Code in the Small Model picker', () => {
61
+ expect(listAuthenticatedProviders()).not.toContain('claude-code');
62
+ });
63
+ });
64
+
35
65
  // 8k context leaves 4k input tokens after the output reserve → 16k chars.
36
66
  const CATALOG = {
37
67
  anthropic: {
@@ -39,7 +39,9 @@ export function registerSmallModelRoutes(app, { getSmallModelService }) {
39
39
  console.error('Small model generation failed:', error);
40
40
  }
41
41
  res.status(statusCode).json({
42
- error: error.message || 'Small model generation failed',
42
+ error: statusCode === 404
43
+ ? (error.message || 'No small model is available')
44
+ : 'The selected Small Model could not complete this action. Choose another model in Settings → Sessions → Small Model and try again.',
43
45
  ...(error?.code ? { code: error.code } : {}),
44
46
  });
45
47
  }
@@ -1 +0,0 @@
1
- import{R as r,j as i}from"./vendor-react-BUCujlKS.js";import{u as n}from"./index-iFY_N5aO.js";import{f as j,V as b,I as m}from"./useAppFontEffects-sHmU5b8u.js";import{D as y}from"./DiagramEditor-PCrYHBko.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-tQekJUAF.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dihw9MtL.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-react-drawio-Ct3Q0DsD.js";function Wi(){const{t:s}=j(),{files:o}=b(),[e,g]=r.useState(null),[p,a]=r.useState(""),[x,l]=r.useState(!0),c=r.useRef(null),u=n(t=>t.pendingDiagramFile),f=r.useCallback(async t=>{l(!0),g(t);try{const d=await o?.readFile?.(t);d&&a(d.content)}catch{a("")}finally{l(!1)}},[o]);r.useEffect(()=>{if(!u)return;const t=n.getState().consumePendingDiagramFile();t&&f(t)},[f,u]);const h=r.useCallback(async()=>{const t=c.current?.getXml();e&&o?.writeFile&&t&&t!==p&&(await o.writeFile(e,t),a(t))},[e,o,p]),v=e?e.split("/").pop()||e:"";return e?x?i.jsx("div",{className:"flex h-full items-center justify-center p-3",children:i.jsx(m,{name:"loader-4",className:"size-4 animate-spin"})}):i.jsxs("div",{className:"flex h-full flex-col",children:[i.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[i.jsx(m,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),i.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:v}),i.jsx("button",{type:"button",onClick:()=>{h()},className:"size-6 flex items-center justify-center rounded-md text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:s("filesView.diagram.saveDiagram"),children:i.jsx(m,{name:"save-3",className:"size-4"})}),i.jsx("button",{type:"button",onClick:()=>n.getState().setActiveMainTab("chat"),className:"size-6 flex items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:s("filesView.diagram.closeDiagramView"),children:i.jsx(m,{name:"close",className:"size-4"})})]}),i.jsx("div",{className:"flex-1 min-h-0",children:i.jsx(y,{ref:c,xml:p,className:"h-full"})})]}):i.jsx("div",{className:"flex h-full items-center justify-center p-3",children:i.jsx("div",{className:"typography-ui text-muted-foreground",children:s("filesView.editor.pickFileFromTree")})})}export{Wi as DiagramView};
@@ -1,14 +0,0 @@
1
- import{R as n,j as s,f as Ut}from"./vendor-react-BUCujlKS.js";import{P as Un,Q as Gn,R as Kn,S as Hn,ag as xi,m as ze,u as he,cQ as qn,A as vi,t as _n,r as wi,T as bi,e as Qn,cR as Jn,aG as Xn,cS as Yn}from"./index-iFY_N5aO.js";import{f as Vs,S as ks,B as S,h as O,V as Zn,L as ea,aV as ta,a0 as sa,a1 as ra,b_ as ia,gO as yi,gm as na,t as I,l as ji,aa as er,bV as js,cq as aa,b as oa,gP as tr,ab as Fi,gQ as Ni,bW as Ci,bX as la,fI as ca,gR as da,br as ua,gS as fa,bs as Ai,bt as Ii,bu as Oi,bv as Bi,bw as $i,bx as Wi,I as g,aU as or,aR as lr,ad as Ns,aT as cr,aQ as Cs,aX as ht,aY as pt,aZ as gt,bU as sr,ac as rr,bQ as Si,by as ma,bz as ha,gk as ir,g as Ts,aS as pa,a_ as ga}from"./useAppFontEffects-sHmU5b8u.js";import{w as xa,x as va,y as wa,z as ba,A as ya}from"./runtimeEndpointReset-cbahJ3hD.js";import{c as ki,s as ja,C as Ti,P as nr}from"./shikiHighlight-CmanopUB.js";import{a as Fa}from"./vendor-codemirror-state-CNWM3Q8V.js";import{E as kt}from"./vendor-codemirror-view-DSzLbZiS.js";import{F as Na,J as Ca}from"./JsonTreeView-BYcgdTOQ.js";import{ensurePierreThemeRegistered as Vi,getResolvedShikiTheme as Sa}from"./appThemeRegistry-BK0dHKa6.js";import{D as ka}from"./DiagramEditor-PCrYHBko.js";import{u as Ta,n as Va}from"./useInlineCommentController-gt56WkxJ.js";import{b as Da}from"./CodeMirrorCommentWidgets-DbUi6I9s.js";import{u as Fs,c as Ea}from"./scheduledTasksApi-BxgGWTL8.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-tQekJUAF.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dihw9MtL.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-codemirror-search-8kyQdB3f.js";import"./vendor-replit-codemirror-vim-B0Ecqnlh.js";import"./web-components-BL-Ur2Tb.js";import"./computeVirtualFileMetrics-xPena3W2.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./Virtualizer-X_7XPoTH.js";import"./isFilePlainText-DS4QV1dd.js";import"./registerCustomTheme-BBXUCRnG.js";import"./vendor-react-drawio-Ct3Q0DsD.js";const Pa=(d,e)=>{if(!e)return null;const r=Number.parseInt(d.trim(),10);return!Number.isFinite(r)||r<1?null:Math.min(r,e.state.doc.lines)},Di=(d,e)=>{const r=d.state.doc.lineAt(e.main.head);return{lineNumber:r.number,character:e.main.head-r.from+1,selection:e}},Ei=(d,e,r)=>{const m=d.state.doc.line(e),x=Math.max(1,Math.min(r,m.length+1)),v=m.from+x-1;d.dispatch({selection:Fa.cursor(v),effects:kt.scrollIntoView(v,{y:"center"})})};function Ra({open:d,onOpenChange:e,view:r,variant:m="overlay"}){const{t:x}=Vs(),[v,y]=n.useState(""),b=n.useRef(null),h=n.useRef(!1),j=n.useRef(null),p=n.useRef(null),F=n.useMemo(()=>Pa(v,r),[v,r]);n.useEffect(()=>{!d||!r||(h.current=!1,b.current=Di(r,r.state.selection),y(""))},[d,r]),n.useEffect(()=>{d&&window.requestAnimationFrame(()=>{p.current?.focus(),p.current?.select()})},[d]),n.useEffect(()=>{if(!(!d||!r||!b.current)){if(F===null){const{selection:a}=b.current;r.dispatch({selection:a,effects:kt.scrollIntoView(a.main.from,{y:"center"})});return}Ei(r,F,b.current.character)}},[F,d,r]);const M=n.useCallback(()=>{if(!r||h.current||!b.current)return;const{selection:a}=b.current;r.dispatch({selection:a,effects:kt.scrollIntoView(a.main.from,{y:"center"})})},[r]),E=n.useCallback(a=>{a||M(),e(a)},[e,M]),N=n.useCallback(()=>{!r||F===null||!b.current||(h.current=!0,Ei(r,F,b.current.character),e(!1),r.focus())},[F,e,r]);n.useEffect(()=>{if(!d)return;const a=W=>{const _=j.current,L=W.target;!_||!(L instanceof Node)||_.contains(L)||E(!1)},q=W=>{W.key==="Escape"&&(W.preventDefault(),E(!1))};return document.addEventListener("pointerdown",a,!0),document.addEventListener("keydown",q,!0),()=>{document.removeEventListener("pointerdown",a,!0),document.removeEventListener("keydown",q,!0)}},[E,d,m]);const P=n.useMemo(()=>{if(!r)return x("goToLineDialog.helper.editorUnavailable");if(F===null){const a=b.current??Di(r,r.state.selection);return x("goToLineDialog.helper.currentLineRange",{current:a.lineNumber,max:r.state.doc.lines})}return x("goToLineDialog.helper.goToLine",{line:F})},[F,x,r]);return m==="inline"?d?s.jsxs("div",{ref:j,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(ks,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:v,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),N())},placeholder:x("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(S,{variant:"outline",size:"xs",onClick:N,disabled:!r||F===null,className:"h-6 px-2",children:x("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:j,className:O("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",d?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(ks,{ref:p,type:"number",min:1,step:1,inputMode:"numeric",value:v,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&(a.preventDefault(),N())},placeholder:x("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:P})]})})}function Ma(d){return!(!d.autoSaveEnabled||!d.isDirty||!d.canWrite||d.isSaving||d.fileLoading||d.isNonEditableBinary||!d.selectedFilePath||d.loadedFilePath!==d.selectedFilePath)}function za(d){return d.selectedFilePath?d.isDirty?!(d.fileLoading||d.loadedFilePath!==d.selectedFilePath||d.isNonEditableBinary||d.draftContent===""&&d.fileContent!==""&&d.loadedFilePath!==d.selectedFilePath):!0:!1}const La=d=>{const e=z(d);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const r=e.lastIndexOf("/");if(r<0)return e;if(r===0)return"/";const m=e.slice(0,r);return/^[A-Za-z]:$/.test(m)?`${m}/`:m},Aa=d=>{const e=Ut.c(8),{label:r,iconDataUrl:m}=d,[x,v]=n.useState(!1);let y;e[0]!==r?(y=r.trim().slice(0,1).toUpperCase()||"?",e[0]=r,e[1]=y):y=e[1];const b=y;if(m&&!x){let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>v(!0),e[2]=p):p=e[2];let F;return e[3]!==m?(F=s.jsx("img",{src:m,alt:"",className:"size-4 rounded-sm",onError:p}),e[3]=m,e[4]=F):F=e[4],F}let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=O("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=h):h=e[5];let j;return e[6]!==b?(j=s.jsx("span",{className:h,children:b}),e[6]=b,e[7]=j):j=e[7],j},Ia=d=>d.slice().sort((e,r)=>e.type!==r.type?e.type==="directory"?-1:1:e.name.localeCompare(r.name)),z=d=>{if(!d)return"";const e=d.replace(/\\/g,"/"),r=e.startsWith("//");let m=e.replace(/\/+/g,"/");r&&!m.startsWith("//")&&(m=`/${m}`);const x=m==="/",v=/^[A-Za-z]:\/$/.test(m);return!x&&!v&&(m=m.replace(/\/+$/,"")),m},Oa=d=>d.startsWith("/")||d.startsWith("//")||/^[A-Za-z]:\//.test(d),Wt=d=>/^[A-Za-z]:\//.test(d)?d.toLowerCase():d,rs=(d,e)=>{const r=z(e),m=z(d);if(!r||!m)return!1;const x=Wt(r),v=Wt(m);return v===x||v.startsWith(`${x}/`)},Pi=(d,e)=>{const r=z(e),m=z(d);if(!rs(m,r))return[];const v=m.slice(r.length).replace(/^\//,"").split("/"),y=[];let b=r;for(let h=0;h<v.length-1;h++)b=b?`${b}/${v[h]}`:v[h],y.push(b);return y},Ss=(d,e)=>{if(!e)return"";const r=z(e);if(!d||!rs(r,d))return r;const m=r.slice(d.length);return m.startsWith("/")?m.slice(1):m},Ba=new Set(["node_modules"]),$a=d=>{const e=Ut.c(3),{status:r}=d;let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=m):m=e[0];const x=m[r];let v;return e[1]!==x?(v=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:x}}),e[1]=x,e[2]=v):v=e[2],v},Ri=d=>{const e=Ut.c(11),{name:r}=d,m=n.useRef(null),x=n.useRef(null),[v,y]=n.useState(!1);let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const M=m.current,E=x.current;if(!M||!E)return;const N=()=>{y(E.scrollWidth>M.clientWidth+1)};N();const P=new ResizeObserver(N);return P.observe(M),P.observe(E),()=>{P.disconnect()}},e[0]=b):b=e[0];let h;e[1]!==r?(h=[r],e[1]=r,e[2]=h):h=e[2],n.useLayoutEffect(b,h);let j;e[3]!==r?(j=s.jsx("span",{ref:x,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:r}),e[3]=r,e[4]=j):j=e[4];let p;e[5]!==r||e[6]!==v?(p=v?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:r}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:r})]}):s.jsx("span",{className:"block min-w-0 truncate",children:r}),e[5]=r,e[6]=v,e[7]=p):p=e[7];let F;return e[8]!==j||e[9]!==p?(F=s.jsxs("span",{ref:m,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[j,p]}),e[8]=j,e[9]=p,e[10]=F):F=e[10],F},Wa=d=>Ba.has(d),Ua=d=>{const e=z(d);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ga=d=>{const r=(d instanceof Error?d.message:String(d??"")).toLowerCase();return r.includes("is a directory")||r.includes("eisdir")},Mi=d=>{const r=(d instanceof Error?d.message:String(d??"")).toLowerCase();return r.includes("file not found")||r.includes("enoent")||r.includes("no such file")||r.includes("does not exist")},ss=2e5,Ka=d=>{let e=0,r=0;for(let m=0;m<d.length;m+=1)d.charCodeAt(m)===10&&(m>0&&d.charCodeAt(m-1)===13?e+=1:r+=1);return e>r?`\r
2
- `:`
3
- `},Ui=d=>d.replace(/\r\n/g,`
4
- `).replace(/\r/g,`
5
- `),Ha=(d,e)=>{const r=Ui(d);return e===`\r
6
- `?r.replace(/\n/g,`\r
7
- `):r},Gi=(d,e)=>s.jsx(Ns,{filePath:d,extension:e}),zi=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},qa=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},ar=d=>{if(!d)return!1;const e=d.toLowerCase().split(".").pop();return e==="html"||e==="htm"},_a=d=>{const e=Ut.c(76),{node:r,root:m,isExpanded:x,isActive:v,isMobile:y,isBrowserClient:b,alwaysShowActions:h,status:j,badge:p,permissions:F,downloadFile:M,contextMenuPath:E,setContextMenuPath:N,rightClickMenuPath:P,setRightClickMenuPath:a,onSelect:q,onToggle:W,onRevealPath:_,onOpenDialog:L}=d,{t:T}=Vs(),V=r.type==="directory",{canRename:le,canCreateFile:X,canCreateFolder:Y,canDelete:A,canReveal:ce}=F,Le=!V&&!!M,U=ce&&!b,Q=le||X||Y||A||Le||U;let Z;e[0]!==Q||e[1]!==r.path||e[2]!==a?(Z=fe=>{Q&&(fe?.preventDefault(),a(r.path))},e[0]=Q,e[1]=r.path,e[2]=a,e[3]=Z):Z=e[3];const pe=Z;let ee;e[4]!==V||e[5]!==r||e[6]!==q||e[7]!==W?(ee=()=>{V?W(r.path):q(r)},e[4]=V,e[5]=r,e[6]=q,e[7]=W,e[8]=ee):ee=e[8];const ge=ee;let de;e[9]!==r.path||e[10]!==N||e[11]!==a?(de=fe=>{fe.stopPropagation(),a(null),N(r.path)},e[9]=r.path,e[10]=N,e[11]=a,e[12]=de):de=e[12];const rt=de;let Tt;e[13]!==X||e[14]!==Y||e[15]!==A||e[16]!==le||e[17]!==U||e[18]!==M||e[19]!==b||e[20]!==V||e[21]!==r||e[22]!==L||e[23]!==_||e[24]!==m||e[25]!==T?(Tt=fe=>{const{Item:ve,Separator:wt}=fe;return s.jsxs(s.Fragment,{children:[le&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("rename",r)},children:[s.jsx(g,{name:"edit",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.rename")]}),s.jsxs(ve,{onClick:C=>{C.stopPropagation(),Ts(r.path).then(we=>{if(we.ok){I.success(T("sidebarFilesTree.toast.pathCopied"));return}I.error(T("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.copyPath")]}),s.jsxs(ve,{onClick:C=>{C.stopPropagation();const we=Ss(m,r.path)||r.path;Ts(we).then(Qe=>{if(Qe.ok){I.success(T("filesView.toast.relativePathCopied"));return}I.error(T("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(g,{name:"file-copy-2",className:"mr-2 size-4"})," ",T("filesView.tree.menu.copyRelativePath")]}),!V&&M&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),M(r.path).catch(we=>{console.error("Download failed:",we),I.error(T("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"})," ",T(b?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),U&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),_(r.path)},children:[s.jsx(g,{name:"folder-received",className:"mr-2 size-4"})," ",T(ga())]}),V&&(X||Y)&&s.jsxs(s.Fragment,{children:[s.jsx(wt,{}),X&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("createFile",r)},children:[s.jsx(g,{name:"file-add",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.newFile")]}),Y&&s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("createFolder",r)},children:[s.jsx(g,{name:"folder-add",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.newFolder")]})]}),A&&s.jsxs(s.Fragment,{children:[s.jsx(wt,{}),s.jsxs(ve,{onClick:C=>{C.stopPropagation(),L("delete",r)},className:"text-destructive focus:text-destructive",children:[s.jsx(g,{name:"delete-bin",className:"mr-2 size-4"})," ",T("sidebarFilesTree.menu.delete")]})]})]})},e[13]=X,e[14]=Y,e[15]=A,e[16]=le,e[17]=U,e[18]=M,e[19]=b,e[20]=V,e[21]=r,e[22]=L,e[23]=_,e[24]=m,e[25]=T,e[26]=Tt):Tt=e[26];const _e=Tt,G=P===r.path;let Fe;e[27]!==r.path||e[28]!==a?(Fe=fe=>a(fe?r.path:null),e[27]=r.path,e[28]=a,e[29]=Fe):Fe=e[29];const xt=y?void 0:pe;let Ae;e[30]!==xt?(Ae=s.jsx("div",{className:"group relative flex items-center",onContextMenu:xt}),e[30]=xt,e[31]=Ae):Ae=e[31];const Ie=y?void 0:pe,vt=v?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let xe;e[32]!==vt?(xe=O("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",vt),e[32]=vt,e[33]=xe):xe=e[33];let Oe;e[34]!==V||e[35]!==x||e[36]!==r.extension||e[37]!==r.path?(Oe=V?x?s.jsx(g,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(g,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):Gi(r.path,r.extension),e[34]=V,e[35]=x,e[36]=r.extension,e[37]=r.path,e[38]=Oe):Oe=e[38];let ue;e[39]!==r.name||e[40]!==r.path?(ue=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:r.path,children:r.name}),e[39]=r.name,e[40]=r.path,e[41]=ue):ue=e[41];let Ne;e[42]!==V||e[43]!==j?(Ne=!V&&j&&s.jsx($a,{status:j}),e[42]=V,e[43]=j,e[44]=Ne):Ne=e[44];let it;e[45]!==p||e[46]!==V?(it=V&&p&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[p.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",p.modified]}),p.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",p.added]})]}),e[45]=p,e[46]=V,e[47]=it):it=e[47];let nt;e[48]!==ge||e[49]!==xe||e[50]!==Oe||e[51]!==ue||e[52]!==Ne||e[53]!==it||e[54]!==Ie?(nt=s.jsxs("button",{type:"button",onClick:ge,onContextMenu:Ie,className:xe,children:[Oe,ue,Ne,it]}),e[48]=ge,e[49]=xe,e[50]=Oe,e[51]=ue,e[52]=Ne,e[53]=it,e[54]=Ie,e[55]=nt):nt=e[55];let Be;e[56]!==h||e[57]!==E||e[58]!==rt||e[59]!==Q||e[60]!==y||e[61]!==r.path||e[62]!==_e||e[63]!==N?(Be=Q&&s.jsx("div",{className:O("absolute right-1 top-1/2 -translate-y-1/2",h?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(or,{open:E===r.path,onOpenChange:fe=>N(fe?r.path:null),children:[s.jsx(lr,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"icon",className:"size-6",onClick:rt,children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})}),s.jsx(cr,{align:"end",side:"bottom",onCloseAutoFocus:()=>N(null),children:_e({Item:Cs,Separator:pa})})]})}),e[56]=h,e[57]=E,e[58]=rt,e[59]=Q,e[60]=y,e[61]=r.path,e[62]=_e,e[63]=N,e[64]=Be):Be=e[64];let $e;e[65]!==nt||e[66]!==Be||e[67]!==Ae?($e=s.jsxs(ba,{render:Ae,children:[nt,Be]}),e[65]=nt,e[66]=Be,e[67]=Ae,e[68]=$e):$e=e[68];let We;e[69]!==_e?(We=s.jsx(xa,{className:"min-w-[180px]",children:_e({Item:wa,Separator:va})}),e[69]=_e,e[70]=We):We=e[70];let at;return e[71]!==$e||e[72]!==We||e[73]!==G||e[74]!==Fe?(at=s.jsxs(ya,{open:G,onOpenChange:Fe,children:[$e,We]}),e[71]=$e,e[72]=We,e[73]=G,e[74]=Fe,e[75]=at):at=e[75],at},Qa=d=>{const e=Ut.c(83),{activeDialog:r,dialogData:m,dialogInputValue:x,onDialogInputChange:v,isDialogSubmitting:y,onDialogSubmit:b,onClose:h,inputRef:j}=d,{t:p}=Vs(),F=!!r;let M;e[0]!==h?(M=de=>!de&&h(),e[0]=h,e[1]=M):M=e[1];let E;e[2]!==r||e[3]!==p?(E=r==="createFile"&&p("filesView.dialog.createFile.title"),e[2]=r,e[3]=p,e[4]=E):E=e[4];let N;e[5]!==r||e[6]!==p?(N=r==="createFolder"&&p("filesView.dialog.createFolder.title"),e[5]=r,e[6]=p,e[7]=N):N=e[7];let P;e[8]!==r||e[9]!==p?(P=r==="rename"&&p("filesView.dialog.rename.title"),e[8]=r,e[9]=p,e[10]=P):P=e[10];let a;e[11]!==r||e[12]!==p?(a=r==="delete"&&p("filesView.dialog.delete.title"),e[11]=r,e[12]=p,e[13]=a):a=e[13];let q;e[14]!==E||e[15]!==N||e[16]!==P||e[17]!==a?(q=s.jsxs(Bi,{children:[E,N,P,a]}),e[14]=E,e[15]=N,e[16]=P,e[17]=a,e[18]=q):q=e[18];let W;e[19]!==r||e[20]!==m?.path||e[21]!==p?(W=r==="createFile"&&p("filesView.dialog.createFile.description",{path:m?.path??p("filesView.dialog.rootFallback")}),e[19]=r,e[20]=m?.path,e[21]=p,e[22]=W):W=e[22];let _;e[23]!==r||e[24]!==m?.path||e[25]!==p?(_=r==="createFolder"&&p("filesView.dialog.createFolder.description",{path:m?.path??p("filesView.dialog.rootFallback")}),e[23]=r,e[24]=m?.path,e[25]=p,e[26]=_):_=e[26];let L;e[27]!==r||e[28]!==m?.name||e[29]!==p?(L=r==="rename"&&p("filesView.dialog.rename.description",{name:m?.name??""}),e[27]=r,e[28]=m?.name,e[29]=p,e[30]=L):L=e[30];let T;e[31]!==r||e[32]!==m?.name||e[33]!==p?(T=r==="delete"&&p("filesView.dialog.delete.description",{name:m?.name??""}),e[31]=r,e[32]=m?.name,e[33]=p,e[34]=T):T=e[34];let V;e[35]!==L||e[36]!==T||e[37]!==W||e[38]!==_?(V=s.jsxs($i,{children:[W,_,L,T]}),e[35]=L,e[36]=T,e[37]=W,e[38]=_,e[39]=V):V=e[39];let le;e[40]!==V||e[41]!==q?(le=s.jsxs(Oi,{children:[q,V]}),e[40]=V,e[41]=q,e[42]=le):le=e[42];let X;e[43]!==r||e[44]!==x||e[45]!==j||e[46]!==v||e[47]!==b||e[48]!==p?(X=r!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(ks,{value:x,onChange:de=>v(de.target.value),placeholder:p(r==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:de=>{de.key==="Enter"&&b()},ref:j})}),e[43]=r,e[44]=x,e[45]=j,e[46]=v,e[47]=b,e[48]=p,e[49]=X):X=e[49];let Y;e[50]!==p?(Y=p("filesView.dialog.cancel"),e[50]=p,e[51]=Y):Y=e[51];let A;e[52]!==y||e[53]!==h||e[54]!==Y?(A=s.jsx(S,{variant:"outline",onClick:h,disabled:y,children:Y}),e[52]=y,e[53]=h,e[54]=Y,e[55]=A):A=e[55];const ce=r==="delete"?"destructive":"default";let Le;e[56]!==b?(Le=()=>{b()},e[56]=b,e[57]=Le):Le=e[57];let U;e[58]!==r||e[59]!==x||e[60]!==y?(U=y||r!=="delete"&&!x.trim(),e[58]=r,e[59]=x,e[60]=y,e[61]=U):U=e[61];let Q;e[62]!==r||e[63]!==y||e[64]!==p?(Q=y?s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}):p(r==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=r,e[63]=y,e[64]=p,e[65]=Q):Q=e[65];let Z;e[66]!==ce||e[67]!==Le||e[68]!==U||e[69]!==Q?(Z=s.jsx(S,{variant:ce,onClick:Le,disabled:U,children:Q}),e[66]=ce,e[67]=Le,e[68]=U,e[69]=Q,e[70]=Z):Z=e[70];let pe;e[71]!==A||e[72]!==Z?(pe=s.jsxs(Wi,{children:[A,Z]}),e[71]=A,e[72]=Z,e[73]=pe):pe=e[73];let ee;e[74]!==j||e[75]!==le||e[76]!==X||e[77]!==pe?(ee=s.jsxs(Ii,{initialFocus:j,children:[le,X,pe]}),e[74]=j,e[75]=le,e[76]=X,e[77]=pe,e[78]=ee):ee=e[78];let ge;return e[79]!==F||e[80]!==M||e[81]!==ee?(ge=s.jsx(Ai,{open:F,onOpenChange:M,children:ee}),e[79]=F,e[80]=M,e[81]=ee,e[82]=ge):ge=e[82],ge},Li=(d,e,r)=>{const m=Ut.c(8),[x,v]=n.useState(""),[y,b]=n.useState(0);let h,j;m[0]!==d||m[1]!==r||m[2]!==e?(h=()=>{if(!d){v("");return}let F=!1;v("");const M=Qn(),E=Jn(M);Xn(M).then(P=>{F||!P||(v(d),e(null))}).catch(P=>{F||(e(P instanceof Error?P.message:r),v(d))});const N=Yn(()=>{F||(v(d),b(Ja),e(null))});return()=>{F=!0,E(),N()}},j=[d,e,r],m[0]=d,m[1]=r,m[2]=e,m[3]=h,m[4]=j):(h=m[3],j=m[4]),n.useEffect(h,j);let p;return m[5]!==y||m[6]!==x?(p={readyKey:x,nonce:y},m[5]=y,m[6]=x,m[7]=p):p=m[7],p},mc=({mode:d="full"})=>{const{t:e}=Vs(),{files:r,runtime:m}=Zn(),{currentTheme:x,availableThemes:v,lightThemeId:y,darkThemeId:b}=ea(),{isMobile:h,isTablet:j,screenWidth:p}=ta(),F=Un(m.platform),M=h||j,E=Gn(),N=Kn(),P=sa()??"",a=z(P.trim()),q=d!=="editor-only",W=d==="editor-only"&&!h,_=Hn(t=>t.searchFiles),L=ra(P),[T,V]=n.useState(""),le=ia(T,200),X=n.useRef(null),[Y,A]=n.useState(!1),[ce,Le]=n.useState(!0),[U,Q]=n.useState(!1),[Z,pe]=n.useState(!1),[ee,ge]=n.useState(!1),de=n.useRef(null),rt=n.useRef(0),Tt=n.useCallback(t=>{rt.current=Math.max(0,rt.current+(t?1:-1))},[]),_e=n.useCallback(t=>t instanceof Element?t.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);n.useEffect(()=>{if(!ee)return;const t=i=>{rt.current>0||_e(i.target)||de.current&&!de.current.contains(i.target)&&ge(!1)};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[_e,ee]);const[G,Fe]=n.useState("edit"),[xt,Ae]=n.useState("edit"),[Ie,vt]=n.useState("tree"),[xe,Oe]=n.useState("edit"),[ue,Ne]=n.useState("preview"),[it,nt]=n.useState(0),Be=n.useRef({}),$e=n.useRef({}),We=n.useRef({}),at=n.useRef({}),fe=n.useMemo(()=>v.find(t=>t.metadata.id===y)??xi(!1),[v,y]),ve=n.useMemo(()=>v.find(t=>t.metadata.id===b)??xi(!0),[v,b]);n.useEffect(()=>{Vi(fe),Vi(ve)},[fe,ve]);const wt=n.useMemo(()=>[],[]),C=ze(t=>a?t.byRoot[a]?.openPaths??wt:wt),we=ze(t=>a?t.byRoot[a]?.selectedPath??null:null),Qe=ze(t=>a?t.byRoot[a]?.expandedPaths??wt:wt),Vt=ze(t=>t.removeOpenPath),ot=ze(t=>t.removeOpenPathsByPrefix),dr=ze(t=>t.removeExpandedPathsByPrefix),te=ze(t=>t.setSelectedPath),ur=ze(t=>t.toggleExpandedPath),is=ze(t=>t.expandPaths),Dt=n.useCallback(t=>{const i=z(t),o=i.split("/"),c=o[o.length-1]||i,u=c.includes(".")?c.split(".").pop()?.toLowerCase():void 0;return{name:c,path:i,type:"file",extension:u}},[]),Et=n.useMemo(()=>C.map(Dt),[C,Dt]),Ds=n.useMemo(()=>{if(we){const t=Wt(we);if(C.some(i=>Wt(i)===t))return we}return C[0]??null},[C,we]),l=n.useMemo(()=>Ds?Dt(Ds):null,[Ds,Dt]),Ue=l?.path??"";n.useEffect(()=>{if(!a||!we)return;const t=Wt(we);C.some(o=>Wt(o)===t)||te(a,C[0]??null)},[C,a,we,te]);const ns=!!(a&&Ue&&!rs(Ue,a)),fr=ns?yi(Ue):void 0,Ce=n.useMemo(()=>({allowOutsideWorkspace:d==="editor-only"&&ns,outsideFileGrant:fr,directory:a||void 0}),[d,ns,fr,a]),Es=n.useRef(null),[mr,Ki]=n.useState({left:!1,right:!1}),hr=n.useCallback(()=>{const t=Es.current;t&&Ki({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),pr=n.useRef(hr);pr.current=hr,n.useEffect(()=>{const t=Es.current;if(!t)return;const i=()=>pr.current();i(),t.addEventListener("scroll",i,{passive:!0});const o=new ResizeObserver(i);return o.observe(t),()=>{t.removeEventListener("scroll",i),o.disconnect()}},[Et.length]);const[gr,Ps]=n.useState({}),[as,Gt]=n.useState({}),Se=n.useRef(new Set),ke=n.useRef(new Set),Je=n.useRef(new Map),xr=n.useRef(0),[vr,os]=n.useState([]),[Hi,ls]=n.useState(!1),[k,K]=n.useState(""),{isPlaying:cs,play:qi,stop:_i}=na(),[Ee,Xe]=n.useState(!1),[Ye,se]=n.useState(null),[Qi,Pe]=n.useState(""),[be,H]=n.useState(null),[B,J]=n.useState(""),[Pt,Rs]=n.useState(!1),[wr,Ji]=n.useState(`
8
- `),Xi=n.useRef(null),Ge=n.useRef(null),ye=n.useRef(null),lt=n.useRef(""),Kt=n.useRef(""),Ze=n.useRef(null),br=n.useRef(null),et=n.useRef(null),ds=n.useRef(0),Ht=n.useRef(null),[Yi,Rt]=n.useState("idle"),[Zi,us]=n.useState(!1),[qt,yr]=n.useState(!1),re=he(t=>t.autoSaveEnabled),en=he(t=>t.setAutoSaveEnabled),[Ms,Mt]=n.useState(!1),zt=n.useRef(null),_t=n.useRef(null),Qt=n.useRef(null),bt=n.useRef(!1),Jt=n.useRef(null),Xt=n.useRef(null),Re=n.useRef(null),tn=n.useRef(null),[sn,zs]=n.useState(0),Lt=n.useRef(null),yt=n.useRef({key:"",attempts:0});n.useEffect(()=>()=>{Lt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Lt.current),Lt.current=null)},[]);const[jt,Ls]=n.useState(null),[Ft,rn]=n.useState(null),[ct,jr]=n.useState(""),[nn,As]=n.useState(!1),[an,on]=n.useState(null),[ln,cn]=n.useState(null),[dn,Fr]=n.useState(!1),[un,Nr]=n.useState(!1),[fn,Is]=n.useState(!1),Cr=!!r.writeFile,Sr=!!r.createDirectory,kr=!!r.rename,Tr=!!r.delete,Vr=!!r.revealPath,mn=Fs(t=>t.availableApps),hn=Fs(t=>t.isCacheStale),Dr=Fs(t=>t.initialize),pn=Fs(t=>t.loadInstalledApps);n.useEffect(()=>{Dr()},[Dr]);const gn=n.useCallback(t=>{r.revealPath&&r.revealPath(t).catch(()=>{I.error(e("sidebarFilesTree.toast.revealFailed"))})},[r,e]),xn=n.useCallback(async t=>{if(!l?.path||await qn(l.path,t.id,t.appName)||await vi(l.path,t.appName))return;const c=La(l.path)||a;c&&await vi(c,t.appName)||I.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[a,l?.path,e]),Os=n.useCallback((t,i)=>{Ls(t),rn(i),jr(t==="rename"&&i.name||""),As(!1)},[]),[R,Me]=n.useState(null),At=n.useRef(!1),dt=n.useRef(null),[Er,It]=n.useState(!1),Ke=he(t=>t.setMainTabGuard),He=he(t=>t.pendingFileNavigation),fs=he(t=>t.setPendingFileNavigation),Bs=he(t=>t.pendingFileFocusPath),$s=he(t=>t.setPendingFileFocusPath),Pr=he(t=>t.shortcutOverrides),Rr=he(t=>t.fileEditorKeymap),Yt=ji(t=>t.settingsDefaultFileViewerPreview),vn=ji(t=>t.showMessageTTSButtons),Mr=he(t=>t.expandedEditorToolbar);n.useEffect(()=>{const t=()=>{At.current=!1,dt.current=null,It(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),n.useEffect(()=>()=>{Jt.current!==null&&window.clearTimeout(Jt.current),Xt.current!==null&&window.clearTimeout(Xt.current)},[]);const wn=n.useCallback((t,i)=>{const o=t.split(`
9
- `),c=Math.max(1,i.start),u=Math.min(o.length,i.end);return c>u?"":o.slice(c-1,u).join(`
10
- `)},[]),bn=Ta({source:"file",fileLabel:l?.path??null,language:l?.path&&er(l.path)||"text",getCodeForRange:t=>wn(k,Va(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:zr,commentText:ms,setCommentText:Lr,editingDraftId:hs,setSelection:Ar,saveComment:Ir,cancel:Zt,reset:Or,startEdit:Br,deleteDraft:$r}=bn;n.useEffect(()=>{Me(null),Or(),Ke(null),J(""),Rs(!1)},[l?.path,Or,Ke]),n.useEffect(()=>{Ar(R)},[R,Ar]),n.useEffect(()=>{if(!R&&!hs)return;const t=o=>{const c=o.target;c.closest('[data-comment-input="true"]')||c.closest('[data-comment-card="true"]')||c.closest(".cm-gutterElement")||c.closest("[data-sonner-toast]")||c.closest("[data-sonner-toaster]")||ms.trim()||(Me(null),Zt())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[Zt,ms,hs,R]);const Wr=n.useCallback((t,i)=>{const o=i??R??void 0;i&&Me(i),Ir(t,o),Me(null)},[R,Ir]),Ur=n.useCallback((t,i)=>{const o=[];for(const c of i){if(!(c&&typeof c.name=="string"&&c.name.length>0)||!E&&c.name.startsWith(".")||!N&&Wa(c.name))continue;const u=c.name,f=z(c.path||""),w=f?Oa(f)?f:z(`${t}/${f}`):z(`${t}/${u}`),D=c.isDirectory?"directory":"file",$=D==="file"&&u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;o.push({name:u,path:w,type:D,extension:$})}return Ia(o)},[N,E]),Te=n.useCallback(async t=>{const i=z(t.trim());if(!i||Se.current.has(i)||ke.current.has(i))return;ke.current=new Set(ke.current),ke.current.add(i);const o=xr.current+1;xr.current=o,Je.current=new Map(Je.current),Je.current.set(i,o);const c=()=>Je.current.get(i)===o;await(r.listDirectory?r.listDirectory(i).then(f=>f.entries.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory}))):_n.listLocalDirectory(i).then(f=>f.map(w=>({name:w.name,path:w.path,isDirectory:w.isDirectory})))).then(f=>{if(!c())return;const w=Ur(i,f);Se.current=new Set(Se.current),Se.current.add(i),Gt(D=>{if(!D[i])return D;const $={...D};return delete $[i],$}),Ps(D=>({...D,[i]:w}))}).catch(f=>{if(!c())return;const w=f instanceof Error?f.message:String(f??"");if(w==="Directory not found"&&a&&i!==a){dr(a,i),Gt(D=>{if(!D[i])return D;const $={...D};return delete $[i],$});return}console.error("Failed to load files directory:",f),Gt(D=>({...D,[i]:w}))}).finally(()=>{c()&&(Je.current=new Map(Je.current),Je.current.delete(i),ke.current=new Set(ke.current),ke.current.delete(i))})},[r,Ur,dr,a]),ps=n.useCallback(async()=>{a&&(Se.current=new Set,ke.current=new Set,Je.current=new Map,Gt({}),Ps(t=>Object.keys(t).length===0?t:{}),await Te(a))},[Te,a]),qe=n.useCallback(async t=>{if(!t){await ps();return}const i=z(t);Se.current=new Set(Se.current),Se.current.delete(i),ke.current=new Set(ke.current),ke.current.delete(i),await Te(i)},[Te,ps]),Gr=n.useRef(""),Kr=n.useRef("");n.useEffect(()=>{if(!a)return;const t=`${a}|h${E?"1":"0"}|g${N?"1":"0"}`,i=Gr.current!==a,o=Kr.current!==t;!i&&!o||(i&&(Gr.current=a,K(""),se(null),Pe(""),H(null),A(!1)),o&&(Kr.current=t,Se.current=new Set,ke.current=new Set,Je.current=new Map,Gt({}),Ps(c=>Object.keys(c).length===0?c:{}),Te(a)))},[Te,a,N,E]),n.useEffect(()=>{if(!r.listDirectory)return;const t=()=>{if(!document.hidden&&Qe.length>0)for(const i of Qe)qe(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[Qe,r.listDirectory,qe]),n.useEffect(()=>{if(!r.listDirectory||Qe.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of Qe)qe(i)},8e3);return()=>clearInterval(t)},[Qe,r.listDirectory,qe]);const yn=n.useCallback(async t=>{if(t?.preventDefault(),!Ft||!jt)return;As(!0);const i=()=>{Ls(null)},o=u=>{I.error(u)},c=()=>{As(!1)};if(jt==="createFile"){if(!ct.trim()){o(e("sidebarFilesTree.toast.filenameRequired")),c();return}if(!r.writeFile){o(e("sidebarFilesTree.toast.writeNotSupported")),c();return}const u=Ft.path,f=u?`${u}/`:"",w=z(`${f}${ct.trim()}`);await r.writeFile(w,"").then(async D=>{D.success&&(I.success(e("sidebarFilesTree.toast.fileCreated")),await qe(u)),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}if(jt==="createFolder"){if(!ct.trim()){o(e("sidebarFilesTree.toast.folderNameRequired")),c();return}const u=Ft.path,f=u?`${u}/`:"",w=z(`${f}${ct.trim()}`);await r.createDirectory(w).then(async D=>{D.success&&(I.success(e("sidebarFilesTree.toast.folderCreated")),await qe(u)),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}if(jt==="rename"){if(!ct.trim()){o(e("sidebarFilesTree.toast.nameRequired")),c();return}if(!r.rename){o(e("sidebarFilesTree.toast.renameNotSupported")),c();return}const u=Ft.path,f=u.split("/").slice(0,-1).join("/"),w=f?`${f}/`:"",D=z(`${w}${ct.trim()}`);await r.rename(u,D).then(async $=>{$.success&&(I.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await qe(f),a&&ot(a,u),(l?.path===u||l?.path.startsWith(`${u}/`))&&(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1))),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}if(jt==="delete"){if(!r.delete){o(e("sidebarFilesTree.toast.deleteNotSupported")),c();return}const u=Ft.path,f=u.split("/").slice(0,-1).join("/");await r.delete(u).then(async w=>{w.success&&(I.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await qe(f),a&&ot(a,u),(l?.path===u||l?.path.startsWith(`${u}/`))&&(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1))),i()}).catch(()=>o(e("sidebarFilesTree.toast.operationFailed"))).finally(c);return}c()},[jt,Ft,ct,r,qe,h,ot,a,l?.path,te,e]);n.useEffect(()=>{if(!P){os([]),ls(!1);return}const t=le.trim();if(!t){os([]),ls(!1);return}let i=!1;return ls(!0),_(P,t,150,{includeHidden:E,respectGitignore:!N,type:"file"}).then(o=>{if(i)return;const u=o.filter(f=>N||!Ua(f.path)).map(f=>({name:f.name,path:z(f.path),type:"file",extension:f.extension,relativePath:f.relativePath}));os(u)}).catch(()=>{i||os([])}).finally(()=>{i||ls(!1)}),()=>{i=!0}},[P,le,_,E,N]);const Hr=n.useCallback(async(t,i)=>{if(r.readFile)return(await r.readFile(t,{...i??{},directory:a||void 0})).content??"";const o=new URLSearchParams({path:t});i?.allowOutsideWorkspace&&o.set("allowOutsideWorkspace","true"),i?.outsideFileGrant&&o.set("outsideFileGrant",i.outsideFileGrant),i?.optional&&o.set("optional","true"),a&&o.set("directory",a);const c=await wi(`/api/fs/read?${o.toString()}`,{cache:i?.optional?"no-store":"default"});if(!c.ok){const u=await c.json().catch(()=>({error:c.statusText}));throw new Error(u.error||e("filesView.error.readFileFailed"))}return c.text()},[r,a,e]),ut=n.useCallback(async(t,i)=>{if(r.statFile){const o=await r.statFile(t,{...i??{},directory:a||void 0});return{path:o.path,size:o.size,mtimeMs:o.mtimeMs}}return null},[r,a]);n.useEffect(()=>{if(!a||!r.statFile||C.length===0)return;let t=!1;const i=[...C];return Promise.all(i.map(async o=>{try{const c=await r.statFile?.(o,{directory:a||void 0});!t&&c&&!c.isFile&&ot(a,o)}catch(c){!t&&Mi(c)&&ot(a,o)}})),()=>{t=!0}},[r,C,ot,a]);const Ws=n.useMemo(()=>k.length>ss?`${k.slice(0,ss)}
11
-
12
- … truncated …`:k,[k]),ie=B!==Ws,Nt=n.useCallback(async()=>{if(!l||!r.writeFile)return I.error(e("filesView.toast.savingNotSupported")),!1;const t=js(l.path)||qt;if(!za({selectedFilePath:l.path,loadedFilePath:be,fileLoading:Ee,isDirty:ie,draftContent:B,fileContent:k,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${l.path}".`):B===""&&k!==""&&be!==l.path&&console.warn(`[saveDraft] refusing to save empty draft for "${l.path}" (${k.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!ie)return!0;Rs(!0);try{const i=Ha(B,wr);if(!(await r.writeFile(l.path,i))?.success)return I.error(e("filesView.toast.writeFileFailed")),!1;if(K(B),a&&rs(l.path,a)){const c=Ss(a,l.path);c&&aa.requestGitRefresh({directory:a,paths:[c]})}if(a&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(z(l.path))){const c=oa.getState().projects.find(u=>z(u.path)===z(a));if(c)try{await Ea(c.id)}catch{I.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return l?.path&&tr(l.path)&&(lt.current=B,Kt.current=B),ut(l.path).then(c=>{c&&(et.current=c)}).catch(()=>{}),!0}catch(i){return I.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{Rs(!1)}},[qt,B,k,Ee,r,ie,wr,be,ut,a,l,e]);n.useEffect(()=>{if(!ie){Ke(null);return}const t=i=>bt.current?(bt.current=!1,!0):(Mt(!0),_t.current=i,!1);return Ke(t),()=>{he.getState().mainTabGuard===t&&Ke(null)}},[ie,Ke]),n.useEffect(()=>{re||(Rt("idle"),Ge.current&&(clearTimeout(Ge.current),Ge.current=null))},[re]);const qr=1500;n.useEffect(()=>{const t=!!(l&&r.writeFile),i=!!(l?.path&&(js(l.path)||qt));if(Ma({autoSaveEnabled:re,isDirty:ie,canWrite:t,isSaving:Pt,fileLoading:Ee,selectedFilePath:l?.path,loadedFilePath:be,isNonEditableBinary:i}))return Ge.current=setTimeout(()=>{Nt().then(o=>{o&&(Rt("saved"),setTimeout(()=>Rt("idle"),2e3))})},qr),()=>{Ge.current&&(clearTimeout(Ge.current),Ge.current=null)}},[re,qt,B,Ee,ie,be,l,r.writeFile,Pt,Nt]),n.useEffect(()=>{Rt("idle")},[l?.path]),n.useEffect(()=>{const t=i=>{ma(i)&&(i.key.toLowerCase()==="s"?(i.preventDefault(),Ge.current&&(clearTimeout(Ge.current),Ge.current=null),Pt||Nt().then(o=>{o&&(Rt("saved"),setTimeout(()=>Rt("idle"),2e3))})):i.key.toLowerCase()==="f"&&(i.preventDefault(),pe(!0)))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[Pt,Nt]);const _r=n.useCallback(async t=>{const i=ds.current+1;ds.current=i;const o=()=>{if(!a)return!1;const je=ze.getState().byRoot[a],oe=je?.selectedPath??je?.openPaths[0]??null;return ds.current===i&&oe===t.path};se(null),Pe(""),H(null),yr(!1);const c=Fi(t.path),u=Ni(t.path),f=Ci(t.path),w=js(t.path);if(h&&A(!0),m.isDesktop&&c&&!u){K(""),J(""),Xe(!0);return}if(!m.isDesktop&&c&&!u){K(""),J(""),H(t.path),Xe(!1);return}if(f){K(""),J(""),H(t.path),Xe(!1);return}if(w){K(""),J(""),H(t.path),Xe(!1);return}Xe(!0);const D=yi(t.path),$={allowOutsideWorkspace:d==="editor-only"&&!!a&&!rs(t.path,a),outsideFileGrant:D};await Hr(t.path,$).then(je=>{if(!o())return;if(la(je)){yr(!0),K(""),J(""),H(t.path);return}const oe=Ui(je);Ji(Ka(je)),K(oe),lt.current=oe,Kt.current=oe,J(oe.length>ss?`${oe.slice(0,ss)}
13
-
14
- … truncated …`:oe),H(t.path),ut(t.path,$).then(Ct=>{Ct&&o()&&(et.current=Ct)}).catch(()=>{})}).catch(je=>{if(o()){if(Ga(je)){if(Xe(!1),a&&te(a,null),se(null),K(""),J(""),H(null),et.current=null,T.trim().length>0&&V(""),h&&A(!1),a){const Ct=[...Pi(t.path,a),t.path];Ct.length>0&&is(a,Ct);for(const Ys of Ct)Se.current.has(Ys)||Te(Ys)}return}if(Mi(je)){a&&ot(a,t.path),K(""),J(""),se(null),et.current=null,h&&A(!1);return}K(""),J(""),se(je instanceof Error?je.message:e("filesView.error.readFileFailed")),et.current=null}}).finally(()=>{o()&&Xe(!1)})},[is,h,Te,d,Hr,ut,ot,a,m.isDesktop,T,te,e]),gs=n.useCallback(async(t,i)=>{if(!a)return;const o=Pi(t,a),c=i?[...o,t]:o;c.length>0&&is(a,c);const u=c.map(f=>{if(!Se.current.has(f))return Te(f)}).filter(Boolean);await Promise.all(u)},[is,Te,a]),Qr=n.useCallback((t,i)=>{const o=i.findIndex(c=>c.path===t);return o===-1||i.length<=1?null:i[o+1]??i[o-1]??null},[]),me=n.useCallback(async t=>{if(bt.current)bt.current=!1;else if(ie){Mt(!0),zt.current=t;return}a&&(te(a,t.path),gs(t.path,!1)),se(null),Pe(""),K(""),lt.current="",Kt.current="",J(""),H(null),h&&A(!0)},[gs,ie,h,a,te]);n.useEffect(()=>{l?.path&&gs(l.path,!1)},[gs,l?.path]),n.useEffect(()=>{if(!l){ds.current+=1,Ht.current=null,Xe(!1);return}if(be===l.path||Ht.current===l.path)return;const t=l.path;Ht.current=t,_r(l).finally(()=>{Ht.current===t&&(Ht.current=null)})},[_r,be,l]);const Jr=n.useRef(ie);Jr.current=ie,n.useEffect(()=>{if(!l?.path||be!==l.path)return;let t=!1;const i=window.setInterval(()=>{document.hidden||ut(l.path,Ce).then(o=>{if(t||!o)return;const c=et.current;if(!c||c.path!==l.path){et.current=o;return}const u=o.mtimeMs!==void 0&&c.mtimeMs!==void 0&&o.mtimeMs!==c.mtimeMs,f=o.size!==c.size;!u&&!f||Jr.current||(et.current=o,H(null))}).catch(()=>{})},2e3);return()=>{t=!0,window.clearInterval(i)}},[be,ut,l?.path,Ce]);const jn=n.useCallback(()=>{const t=zt.current,i=_t.current,o=Qt.current;if(zt.current=null,_t.current=null,Qt.current=null,bt.current=!0,Mt(!1),J(Ws),o){a&&Vt(a,o),l?.path===o&&(t?me(t):(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1)));return}if(t){me(t);return}i&&(Ke(null),he.getState().setActiveMainTab(i))},[Ws,me,h,Vt,a,l?.path,Ke,te]),Fn=n.useCallback(async()=>{const t=zt.current,i=_t.current,o=Qt.current;if(!await Nt()){bt.current=!1;return}if(zt.current=null,_t.current=null,Qt.current=null,bt.current=!0,Mt(!1),o){a&&Vt(a,o),l?.path===o&&(t?await me(t):(a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1)));return}if(t){await me(t);return}i&&(Ke(null),he.getState().setActiveMainTab(i))},[me,h,Vt,a,Nt,l?.path,Ke,te]),Xr=n.useCallback(t=>{const i=l?.path===t,o=Qr(t,Et);if(i&&ie){Mt(!0),zt.current=o,Qt.current=t;return}if(a&&Vt(a,t),!!i){if(o){me(o);return}a&&te(a,null),K(""),se(null),Pe(""),H(null),h&&A(!1)}},[Qr,me,ie,h,Et,Vt,a,l?.path,te]),Nn=n.useCallback(t=>{if(C.includes(t))return"open";if(L?.files){const i=t.startsWith(a+"/")?t.slice(a.length+1):t,o=L.files.find(c=>c.path===i);if(o){if(o.index==="A"||o.working_dir==="?")return"git-added";if(o.index==="D")return"git-deleted";if(o.index==="M"||o.working_dir==="M")return"git-modified"}}return null},[C,L,a]),Cn=n.useCallback(t=>{if(!L?.files)return null;const i=t.startsWith(a+"/")?t.slice(a.length+1):t,o=i?`${i}/`:"";let c=0,u=0;for(const f of L.files)f.path.startsWith(o)&&((f.index==="M"||f.working_dir==="M")&&c++,(f.index==="A"||f.working_dir==="?")&&u++);return c+u>0?{modified:c,added:u}:null},[L,a]),Sn=n.useCallback(async t=>{const i=z(t);a&&(ur(a,i),Se.current.has(i)||await Te(i))},[Te,a,ur]),kn=n.useMemo(()=>({canRename:kr,canCreateFile:Cr,canCreateFolder:Sr,canDelete:Tr,canReveal:Vr}),[kr,Cr,Sr,Tr,Vr]);function Yr(t,i){const o=gr[t]??[];return o.map((c,u)=>{const f=c.type==="directory",w=f&&Qe.includes(c.path),D=l?.path===c.path,$=u===o.length-1;return s.jsxs("li",{className:"relative",children:[i>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),$&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx(_a,{node:c,root:a,isExpanded:w,isActive:D,isMobile:h,isBrowserClient:F,alwaysShowActions:M,status:f?void 0:Nn(c.path),badge:f?Cn(c.path):void 0,permissions:kn,downloadFile:r.downloadFile,contextMenuPath:an,setContextMenuPath:on,rightClickMenuPath:ln,setRightClickMenuPath:cn,onSelect:me,onToggle:Sn,onRevealPath:gn,onOpenDialog:Os}),f&&w&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[as[c.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:as[c.path],children:as[c.path]}),s.jsxs(S,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{qe(c.path)},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,Yr(c.path,i+1)]})]},c.path)})}const ne=!!(l?.path&&Fi(l.path)),xs=!!(l?.path&&Ni(l.path)),Ve=!!(l?.path&&Ci(l.path)),Us=!!(l?.path&&(js(l.path)||qt)),tt=Us&&!ne&&!Ve,Zr=n.useMemo(()=>z(He?.path??""),[He?.path]),Ot=!!(He&&Zr&&Ue&&Ue===Zr&&!Ee&&!Ye&&!ne&&!Ve&&!tt),ft=n.useMemo(()=>Ss(a,Ue),[Ue,a]),Tn=!!(l&&(!ne||xs)&&!Ve&&!tt&&k.length>0),Vn=!!(l&&ft.length>0),De=!!(l&&!ns&&!Us&&!ne&&r.writeFile&&k.length<=ss),mt=!!(l?.path&&zi(l.path)),es=!!(l?.path&&qa(l.path)),Bt=!!(l?.path&&ar(l.path)),ts=!!(l?.path&&tr(l.path)),Gs=!!(l&&!Us&&!ne)&&!mt&&!ts&&!(Bt&&xe==="preview"),Dn=mt&&xt==="edit"||Bt&&xe==="edit"||es&&Ie==="text"||!mt&&!Bt&&!es&&G==="edit",vs=n.useMemo(()=>Ue?ca(Ue):null,[Ue]),[ei,Ks]=n.useState(null);n.useEffect(()=>{let t=!1;const i=l?.path;if(!i||vs){Ks(null);return}return Ks(null),da(i).then(o=>{t||Ks(o)}),()=>{t=!0}},[l?.path,vs]),n.useEffect(()=>{!De&&G==="edit"&&Fe("view")},[De,G]);const Hs="openchamber:files:md-viewer-mode",qs="openchamber:files:html-viewer-mode",_s="openchamber:files:json-viewer-mode";n.useEffect(()=>{const t=l?.path;if(!t)return;Fe(Be.current[t]??"edit");let i=Yt?"preview":"edit";try{const u=localStorage.getItem(Hs);(u==="preview"||u==="edit")&&(i=u)}catch{}Ae($e.current[t]??i);let o=Yt?"preview":"edit";try{const u=localStorage.getItem(qs);(u==="preview"||u==="edit")&&(o=u)}catch{}Oe(We.current[t]??o),Ne(at.current[t]??(Yt?"preview":"edit"));let c=Yt?"tree":"text";try{const u=localStorage.getItem(_s);(u==="tree"||u==="text")&&(c=u)}catch{}vt(c)},[l?.path,Yt]);const En=n.useCallback(t=>{const i=l?.path;i&&(Be.current[i]=t),Fe(t)},[l?.path]),ti=n.useCallback(t=>{const i=l?.path;i&&($e.current[i]=t),Ae(t);try{localStorage.setItem(Hs,t)}catch{}},[l?.path]),ae=n.useCallback(()=>xt,[xt]),Pn=n.useCallback(t=>{vt(t);try{localStorage.setItem(_s,t)}catch{}},[]),Rn=n.useCallback(t=>{const i=l?.path;i&&(We.current[i]=t),Oe(t);try{localStorage.setItem(qs,t)}catch{}},[l?.path]),Mn=n.useCallback(t=>{const i=l?.path;if(i&&(at.current[i]=t),ye.current&&(clearTimeout(ye.current),ye.current=null),Ze.current!==null&&(cancelAnimationFrame(Ze.current),Ze.current=null),t==="edit")J(lt.current||k),Ne(t);else{lt.current=B;const o=i;Ne("edit"),Ze.current=requestAnimationFrame(()=>{Ze.current=requestAnimationFrame(()=>{Ze.current=null,!(a&&o&&ze.getState().byRoot[a]?.selectedPath!==o)&&(nt(c=>c+1),Ne("preview"))})});return}},[B,k,a,l?.path]),Qs=n.useCallback(async(t,i)=>{if(!r.writeFile||i===Kt.current)return!1;if(!(await r.writeFile(t,i))?.success)return I.error(e("filesView.toast.writeFileFailed")),!1;lt.current=i,Kt.current=i,J(i);const c=await ut(t,Ce).catch(()=>null);return c&&(et.current=c),!0},[r,ut,Ce,e]);n.useEffect(()=>()=>{ye.current&&(clearTimeout(ye.current),ye.current=null),Ze.current!==null&&(cancelAnimationFrame(Ze.current),Ze.current=null)},[ue,l?.path]);const zn=n.useCallback(t=>{if(lt.current=t,!re||!l?.path||ue!=="preview"||!r.writeFile)return;ye.current&&clearTimeout(ye.current);const i=l.path;ye.current=setTimeout(()=>{ye.current=null,Qs(i,t).then(o=>{o&&(us(!0),setTimeout(()=>us(!1),1500))}).catch(o=>{I.error(o instanceof Error?o.message:e("filesView.toast.saveFailed"))})},qr)},[re,ue,r.writeFile,Qs,l?.path,e]),Ln=n.useMemo(()=>ts&&(lt.current||B)||k,[B,k,ts]),si=n.useCallback(()=>xe,[xe]);n.useEffect(()=>{const t=o=>{const c=o?"preview":"edit",u=o?"tree":"text";for(const f of C)Be.current[f]="edit",zi(f)&&($e.current[f]=c),ar(f)&&(We.current[f]=c),tr(f)&&(at.current[f]=c);Fe("edit"),Ae(c),Oe(c),Ne(c),vt(u);try{localStorage.setItem(Hs,c),localStorage.setItem(qs,c),localStorage.setItem(_s,u)}catch{}},i=o=>{const c=!!o.detail?.enabled;t(c)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",i),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",i)}},[C]),n.useEffect(()=>{if(!He||!a)return;const t=()=>{typeof window>"u"||Lt.current===null&&(Lt.current=window.requestAnimationFrame(()=>{Lt.current=null,zs(st=>st+1)}))},i=(st,St)=>{if(st.state.doc.length!==St.length)return!1;if(St.length===0)return!0;const Zs=Math.min(128,St.length);if(st.state.sliceDoc(0,Zs)!==St.slice(0,Zs))return!1;const gi=Math.max(0,St.length-Zs);return st.state.sliceDoc(gi,St.length)===St.slice(gi)},o=z(He.path);if(!o){fs(null),yt.current={key:"",attempts:0};return}const c=`${o}:${He.line}:${He.column??1}`;if(yt.current.key!==c&&(yt.current={key:c,attempts:0}),l?.path!==o){if(Ms)return;me(Dt(o));return}if(Ee||be!==o)return;if(Ye||ne||Ve||tt){fs(null),yt.current={key:"",attempts:0};return}if(!De)return;if(G!=="edit"){Fe("edit");return}const u=Re.current;if(!u){t();return}if(!i(u,B)){t();return}const f=Math.max(1,Math.min(He.line,u.state.doc.lines)),w=u.state.doc.line(f),D=Math.max(1,He.column||1),$=Math.max(0,w.to-w.from),je=Math.min($,D-1),oe=w.from+je;if(!(u.state.selection.main.head===oe)||yt.current.attempts===0){yt.current.attempts+=1,u.dispatch({selection:{anchor:oe},effects:kt.scrollIntoView(oe,{y:"center"})}),u.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const st=Re.current;st&&(st.dispatch({selection:{anchor:oe},effects:kt.scrollIntoView(oe,{y:"center"})}),st.focus())}),fs(null),yt.current={key:"",attempts:0}},[De,Ms,B,sn,Ye,Ee,ne,Ve,tt,be,me,He,a,l?.path,fs,G,Dt]),n.useEffect(()=>{if(!Bs||!a)return;const t=z(Bs);if(!t){$s(null);return}l?.path===t&&(Ee||be!==t||(!Ye&&!ne&&!Ve&&!tt&&De&&G==="edit"&&Re.current?.focus(),$s(null)))},[De,Ye,Ee,ne,Ve,tt,be,Bs,a,l?.path,$s,G]);const $t=n.useCallback(t=>{if(!h||!t||!t.hasFocus||typeof window>"u")return;const i=window.visualViewport;if(!i)return;const o=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,o-(i.offsetTop+i.height))<=0)return;const u=t.state.selection.main.head,f=t.coordsAtPos(u);if(!f)return;const w=Math.round(i.offsetTop+i.height),$=f.bottom+20-w;$<=0||(t.scrollDOM.scrollTop+=$)},[h]);n.useEffect(()=>{if(!h||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{$t(Re.current)})},i=window.visualViewport;return i?.addEventListener("resize",t),i?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{i?.removeEventListener("resize",t),i?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[h,$t]),n.useEffect(()=>{if(!De||G!=="edit"||h)return;const t=ua("open_go_to_line",Pr),i=o=>{const c=o.target;if(c?.closest('[role="dialog"]'))return;const u=!!c?.closest(".cm-editor");c?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!u||!document.activeElement?.closest(".cm-editor")||ha(o,t)&&(o.preventDefault(),Is(!0))};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[De,h,Pr,G]);const ws=he(t=>t.editorFontSize),ri=n.useMemo(()=>{if(!l?.path)return[ki(x,{fontSize:ws})];const t=er(l.path),i=[ki(x,t?{syntaxColors:!1,fontSize:ws}:{fontSize:ws})],o=vs??ei;return o&&i.push(o),t&&i.push(ja({language:t,themeName:x.metadata.id,theme:Sa(x)})),ce&&i.push(kt.lineWrapping),h&&i.push(kt.updateListener.of(c=>{c.view.hasFocus&&(c.selectionSet||c.focusChanged||c.viewportChanged||c.geometryChanged)&&window.requestAnimationFrame(()=>{$t(c.view)})})),i},[x,l?.path,vs,ei,ce,h,$t,ws]),ii=n.useMemo(()=>({light:fe.metadata.id,dark:ve.metadata.id}),[fe.metadata.id,ve.metadata.id]),bs=l?.path&&Ve?`${l.path}|${Ce.allowOutsideWorkspace?"outside":"workspace"}|${Ce.outsideFileGrant??""}`:"",ys=l?.path&&Bt&&xe==="preview"&&!m.isVSCode?l.path:"",ni=e("filesView.error.readFileFailed"),{readyKey:ai,nonce:An}=Li(ys,se,ni),{readyKey:oi,nonce:li}=Li(bs,se,ni),In=!!(ys&&ai!==ys),ci=!!(bs&&oi!==bs),di=l?.path&&ne?xs?`data:${fa(l.path)};utf8,${encodeURIComponent(k)}`:Qi:"",ui=l?.path&&Ve&&oi===bs?bi().authenticatedAsset("/api/fs/raw",{path:l.path,allowOutsideWorkspace:Ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:Ce.outsideFileGrant,directory:a||void 0}):"",fi=n.useCallback(t=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:ui,className:"h-full w-full border-0",title:t.name},li)}),[ui,li]);n.useEffect(()=>{let t=!1,i="";return(async()=>{if(!l?.path||!ne||xs){Pe("");return}se(null),await(r.readFileBinary?r.readFileBinary(l.path,Ce).then(u=>u.dataUrl):(async()=>{const u=await wi("/api/fs/raw",{query:{path:l.path,allowOutsideWorkspace:Ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:Ce.outsideFileGrant,directory:a||void 0}});if(!u.ok)throw new Error(e("filesView.error.readFileFailed"));const f=await u.blob();return i=URL.createObjectURL(f),t?(URL.revokeObjectURL(i),i="",""):i})()).then(u=>{t||(Pe(u),H(l.path))}).catch(u=>{t||(Pe(""),se(u instanceof Error?u.message:e("filesView.error.readFileFailed")),H(null))}).finally(()=>{t||Xe(!1)})})(),()=>{t=!0,i&&URL.revokeObjectURL(i)}},[r,ne,xs,a,l?.path,Ce,e]);const On=n.useCallback(()=>Ls(null),[]),Bn=n.useMemo(()=>Da({drafts:zr,editingDraftId:hs,commentText:ms,onTextChange:Lr,selection:R,isDragging:Er,fileLabel:l?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Wr,onCancel:()=>{Me(null),Zt()},onEdit:t=>{Br(t),Me({start:t.startLine,end:t.endLine})},onDelete:$r}),[Zt,ms,$r,hs,zr,Wr,Er,R,l?.path,Lr,Br]),mi=n.useCallback((t,i)=>s.jsx("div",{className:"h-full",children:s.jsx(Na,{file:{name:t.name,contents:i,lang:er(t.path)||void 0},options:{disableFileHeader:!0,overflow:ce?"wrap":"scroll",theme:ii,themeType:x.metadata.variant==="dark"?"dark":"light"},className:"block h-full w-full",style:{height:"100%"}})}),[x.metadata.variant,ii,ce]),Js=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!l)return null;const c=i==="docked"?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",u=(f,w)=>s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:w})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:f})]});return s.jsxs("div",{className:c,children:[De&&Dn&&s.jsxs(s.Fragment,{children:[Pt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(g,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):re&&Yi==="saved"&&!ie?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(g,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):ie?u(e(re?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ir()}+S`}),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{Nt()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(re?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:`${ir()}+S`}),"aria-label":e("filesView.editor.saveAria",{shortcut:`${ir()}+S`}),children:s.jsx(g,{name:"save-3",className:"size-4"})})):null,u(e(re?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>en(!re),className:O("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",re?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(re?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(re?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:re?s.jsx(g,{name:"file-check-fill",className:"size-4"}):s.jsx(g,{name:"file-check",className:"size-4"})}))]}),s.jsxs(or,{onOpenChange:Tt,children:[s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(lr,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(g,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(cr,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[mn.map(f=>s.jsxs(Cs,{className:"flex items-center gap-2",onClick:()=>{xn(f)},children:[s.jsx(Aa,{label:f.label,iconDataUrl:f.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:f.label})]},f.id)),hn?s.jsxs(Cs,{className:"flex items-center gap-2",onClick:()=>{pn(!0)},children:[s.jsx(g,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!ne&&!Ve&&!tt&&s.jsxs(s.Fragment,{children:[u(e(ce?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Le(!ce),className:O("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",ce?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(ce?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(g,{name:"text-wrap",className:"size-4"})})),G==="edit"&&s.jsxs(s.Fragment,{children:[u(e("filesView.editor.findInFile"),s.jsx(S,{variant:"ghost",size:"sm",onClick:f=>{pe(!Z),f.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(g,{name:"search",className:"size-4"})})),u(e("filesView.editor.goToLine"),s.jsx(S,{variant:"ghost",size:"sm",onClick:f=>{Is(w=>!w),f.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(g,{name:"menu-fold-2",className:"size-4"})})),s.jsx(Ra,{open:fn,onOpenChange:Is,view:Re.current,variant:"inline"})]})]}),Gs&&De&&!es&&!Bt&&s.jsx(nr,{currentMode:G==="view"?"preview":"edit",onToggle:()=>{En(G==="view"?"edit":"view")}}),mt&&u(e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ti(ae()==="preview"?"edit":"preview"),className:O("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",ae()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:ae()==="preview"?"eye":"eye-off",className:"size-4"})})),ar(l?.path??"")&&s.jsx(nr,{currentMode:si(),onToggle:()=>{Rn(si()==="preview"?"edit":"preview")}}),mt&&ae()==="preview"&&vn&&s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx(S,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(cs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{cs?_i():k.trim()&&qi(k)},children:cs?s.jsx(g,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"volume-up",className:"size-4"})})}),s.jsx(gt,{sideOffset:8,children:e(cs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),ts&&s.jsxs(s.Fragment,{children:[s.jsx(nr,{currentMode:ue,onToggle:()=>Mn(ue==="preview"?"edit":"preview")}),ue==="preview"&&s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{const f=br.current?.getXml();if(ye.current&&(clearTimeout(ye.current),ye.current=null),l?.path&&f){if(!await Qs(l.path,f))return;us(!0),setTimeout(()=>us(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:Zi?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"save-3",className:"size-4"})})]}),es&&u(e(Ie==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Pn(Ie==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(Ie==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:Ie==="tree"?s.jsx(g,{name:"code-sslash",className:"size-4"}):s.jsx(g,{name:"node-tree",className:"size-4"})})),Tn&&u(e("filesView.editor.copyFileContents"),s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{(await Ts(k)).ok?(Fr(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.current=window.setTimeout(()=>{Fr(!1)},1200)):I.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:dn?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"clipboard",className:"size-4"})})),Vn&&u(e("filesView.editor.copyFilePathTitle",{path:ft}),s.jsx(S,{variant:"ghost",size:"sm",onClick:async()=>{(await Ts(ft)).ok?(Nr(!0),Xt.current!==null&&window.clearTimeout(Xt.current),Xt.current=window.setTimeout(()=>{Nr(!1)},1200)):I.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:ft}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:ft}),children:un?s.jsx(g,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(g,{name:"file-copy-2",className:"size-4"})})),r.downloadFile&&u(e("filesView.editor.saveFile"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{const f=r.downloadFile;f&&f(l.path).catch(w=>{console.error("Download failed:",w),I.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(g,{name:"download",className:"size-4"})})),t?u(e("filesView.editor.exitFullscreen"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Q(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(g,{name:"fullscreen-exit",className:"size-4"})})):!h&&d==="full"&&u(e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Q(!U),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(U?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:U?s.jsx(g,{name:"fullscreen-exit",className:"size-4"}):s.jsx(g,{name:"fullscreen",className:"size-4"})}))]})},Xs=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Ai,{open:Ms,onOpenChange:t=>{t||Mt(!0)},children:s.jsxs(Ii,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Oi,{children:[s.jsx(Bi,{children:e("filesView.unsaved.title")}),s.jsx($i,{children:e("filesView.unsaved.description")})]}),s.jsxs(Wi,{children:[s.jsx(S,{variant:"outline",onClick:()=>{Fn()},disabled:Pt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(S,{variant:"destructive",onClick:jn,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:O("flex flex-col flex-shrink-0",q&&"border-b border-border/40"),children:[q?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[h&&Y&&s.jsx("button",{type:"button",onClick:()=>A(!1),"aria-label":e("filesView.editor.back"),className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:s.jsx(g,{name:"arrow-left-s",className:"size-5"})}),h?l?s.jsxs(or,{children:[s.jsx(lr,{asChild:!0,children:s.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":e("filesView.editor.openFilesAria"),children:[s.jsx(Ns,{filePath:l.path,extension:l.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Ri,{name:l.name}),s.jsx(g,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(cr,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Et.map(t=>{const i=l?.path===t.path;return s.jsxs(Cs,{onSelect:o=>{if(o.target.closest("[data-close-open-file]")){o.preventDefault();return}i||me(t)},className:O("flex min-w-0 items-center justify-between gap-2 overflow-hidden",i&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(Ns,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Ri,{name:t.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:o=>{o.preventDefault(),o.stopPropagation()},onClick:o=>{o.preventDefault(),o.stopPropagation(),Xr(t.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Et.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[mr.left&&s.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),mr.right&&s.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),s.jsx("div",{ref:Es,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Et.map(t=>{const i=l?.path===t.path;return s.jsxs("div",{title:Ss(a,t.path),className:O("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",i?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[s.jsx(Ns,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{i||me(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),s.jsx("button",{type:"button",onClick:o=>{o.stopPropagation(),Xr(t.path)},className:O("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!M&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(g,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,(Mr||h)&&l?s.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[ft&&!h?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:ft,children:ft}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Js({layout:"docked"})})]}):null]}),s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[l&&!Z&&!(Mr||h)&&s.jsx("div",{ref:de,className:"absolute right-3 top-3 z-30",onMouseLeave:()=>{rt.current>0||ge(!1)},children:ee?Js():s.jsxs("div",{className:"flex items-center gap-1",children:[mt?s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ti(ae()==="preview"?"edit":"preview"),className:O("size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors",ae()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]":"text-muted-foreground hover:text-foreground"),"aria-label":e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),title:e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(g,{name:ae()==="preview"?"eye":"eye-off",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e(ae()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode")})]}):null,s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",onMouseEnter:()=>ge(!0),children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>ge(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":e("filesView.editor.showControlsAria"),title:e("filesView.editor.controlsTitle"),children:s.jsx(g,{name:"more-2-fill",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.editor.controlsTitle")})]})]})}),s.jsx(sr,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:l?Ee||ci?W?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):Ye?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Ye}):ne?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:di,alt:l?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},l.path)}):Ve?fi(l):tt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!l||t(l.path).catch(i=>{console.error("Download failed:",i),I.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):l&&ts&&ue==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(ka,{ref:br,xml:Ln,onChange:zn},`${l.path}:${it}`)}):l&&es&&Ie==="tree"?s.jsx(rr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Ca,{jsonString:k,maxHeight:"100%",initiallyExpandedDepth:2})})}):l&&mt&&ae()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-3",children:[k.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(k.length/1024)})}),s.jsx(rr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Si,{content:k,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):l&&Bt&&xe==="preview"?In?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!m.isVSCode&&ai===ys?(()=>{const t=l.path.split("/").map(i=>encodeURIComponent(i)).join("/");return bi().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:m.isVSCode?(()=>{const t=l.path.substring(0,l.path.lastIndexOf("/")+1);return t?k.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):k})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},An)}):l&&Gs&&G==="view"?mi(l,B):s.jsxs("div",{className:O("relative h-full",Ot&&"overflow-hidden"),ref:tn,children:[s.jsx("div",{className:O("h-full",Ot&&"invisible"),children:s.jsx(Ti,{value:B,onChange:J,readOnly:!De,vimMode:Rr==="vim",extensions:ri,className:"h-full",blockWidgets:Bn,onViewReady:t=>{Re.current=t,zs(i=>i+1),window.requestAnimationFrame(()=>{$t(t)})},onViewDestroy:()=>{Re.current&&(Re.current=null),zs(t=>t+1)},enableSearch:!0,searchOpen:Z,onSearchOpenChange:pe,highlightLines:R?{start:Math.min(R.start,R.end),end:Math.max(R.start,R.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,i,o)=>{if(!(o instanceof MouseEvent)||o.button!==0)return!1;o.preventDefault();const c=t.state.doc.lineAt(i.from).number;if(R&&!o.shiftKey&&Math.min(R.start,R.end)===c&&Math.max(R.start,R.end)===c)return Me(null),Zt(),At.current=!1,dt.current=null,It(!1),!0;if(h&&R&&!o.shiftKey){const u=Math.min(R.start,R.end,c),f=Math.max(R.start,R.end,c);return Me({start:u,end:f}),At.current=!1,dt.current=null,It(!1),!0}if(At.current=!0,dt.current=c,It(!0),R&&o.shiftKey){const u=Math.min(R.start,c),f=Math.max(R.end,c);Me({start:u,end:f})}else Me({start:c,end:c});return!0},mouseover:(t,i,o)=>{if(!(o instanceof MouseEvent)||o.buttons!==1||!At.current||dt.current===null)return!1;const c=t.state.doc.lineAt(i.from).number,u=Math.min(dt.current,c),f=Math.max(dt.current,c);return Me({start:u,end:f}),It(!0),!1},mouseup:()=>(At.current=!1,dt.current=null,It(!1),!1)}}})}),Ot&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})]})]}),$n=!!(a&&gr[a]),hi=a?as[a]:null,pi=s.jsxs("section",{className:O("flex min-h-0 flex-col overflow-hidden",h?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:O("flex flex-col gap-2 py-2",h?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(g,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(ks,{ref:X,value:T,onChange:t=>V(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),T.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{V(""),X.current?.focus()},children:s.jsx(g,{name:"close",className:"size-4"})})]}),s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Os("createFile",{path:P,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(g,{name:"file-add",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>Os("createFolder",{path:P,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(g,{name:"folder-add",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(ht,{children:[s.jsx(pt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{ps()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(g,{name:"refresh",className:"size-4"})})})}),s.jsx(gt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(sr,{outerClassName:"flex-1 min-h-0",className:O("py-2",h?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:Hi?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):vr.length>0?vr.map(t=>{const i=l?.path===t.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{me(t)},className:O("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[Gi(t.path,t.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):hi?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:hi}),s.jsxs(S,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{ps()},children:[s.jsx(g,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):$n?Yr(a,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),Wn=d==="full"&&U&&l&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:Js({exitFullscreenOnly:!0})}),s.jsx(sr,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:Ee||ci?W?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):Ye?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Ye}):ne?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:di,alt:l.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},l.path)}):Ve?fi(l):tt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(S,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!l||t(l.path).catch(i=>{console.error("Download failed:",i),I.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(g,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):mt&&ae()==="preview"?s.jsxs("div",{className:"h-full overflow-auto p-4",children:[k.length>500*1024&&s.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(k.length/1024)})}),s.jsx(rr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(Si,{content:k,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):Gs&&G==="view"?mi(l,B):s.jsxs("div",{className:O("relative h-full",Ot&&"overflow-hidden"),children:[s.jsx("div",{className:O("h-full",Ot&&"invisible"),children:s.jsx(Ti,{value:B,onChange:J,readOnly:!De,vimMode:Rr==="vim",extensions:ri,className:"h-full",onViewReady:t=>{Re.current=t,window.requestAnimationFrame(()=>{$t(t)})},onViewDestroy:()=>{Re.current&&(Re.current=null)}})}),Ot&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(g,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(Qa,{activeDialog:jt,dialogData:Ft,dialogInputValue:ct,onDialogInputChange:jr,isDialogSubmitting:nn,onDialogSubmit:yn,onClose:On,inputRef:Xi}),Wn,h?Y?Xs:pi:d==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:Xs})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[p>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:pi}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Xs})]})]})};function Ja(d){return d+1}export{mc as FilesView};
@@ -1 +0,0 @@
1
- import{f as S,j as s,R as h}from"./vendor-react-BUCujlKS.js";import{a0 as R,I as M}from"./useAppFontEffects-sHmU5b8u.js";import{extractMarkdownImageCandidates as A,MAX_MARKDOWN_IMAGE_COUNT as C}from"./markdownCore-DhfzuGXu.js";import{r as O}from"./markdownImageAssets-BTNlRyjd.js";import"./vendor-scheduler-7OC5HNn7.js";import"./index-iFY_N5aO.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-D_V6hAcE.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-tQekJUAF.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-DUOssd4j.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Bbw3D7r0.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-BjbBRsUA.js";import"./vendor-codemirror-lang-json-ryCw7nab.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-VgNqFSH-.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-B3Qe3OpS.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-FGQydhTc.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-Dihw9MtL.js";import"./vendor-codemirror-lang-python-N414WYK-.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-ARAOgp1x.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-marked-CX41MkDF.js";import"./vendor-remend-BWYYytN3.js";import"./vendor-katex-k3Ppq1Ha.js";import"./vendor-dompurify-r8glNMJW.js";const P=p=>{const e=S.c(31),{candidate:t,directory:i,onShowPopup:m}=p,c=h.useRef(null),[o,a]=h.useState(!1);let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={url:"",status:"loading"},e[0]=n):n=e[0];const[r,l]=h.useState(n);let w,x;e[1]!==o?(w=()=>{const u=c.current;if(!u||o)return;if(typeof IntersectionObserver>"u"){a(!0);return}const b=new IntersectionObserver(E=>{E.some(L)&&(a(!0),b.disconnect())},{rootMargin:"200px"});return b.observe(u),()=>b.disconnect()},x=[o],e[1]=o,e[2]=w,e[3]=x):(w=e[2],x=e[3]),h.useEffect(w,x);let y,k;e[4]!==t.source||e[5]!==i||e[6]!==o?(y=()=>{if(!o)return;const u=new AbortController;return l({url:"",status:"loading"}),O(t.source,i,u.signal).then(b=>{u.signal.aborted||l({url:b,status:"loading"})}).catch(()=>{u.signal.aborted||l({url:"",status:"error"})}),()=>u.abort()},k=[t.source,i,o],e[4]=t.source,e[5]=i,e[6]=o,e[7]=y,e[8]=k):(y=e[7],k=e[8]),h.useEffect(y,k);let v;e[9]!==t.filename||e[10]!==r.status||e[11]!==r.url||e[12]!==m?(v=()=>{r.status!=="ready"||!m||m({open:!0,title:t.filename,content:"",metadata:{tool:"markdown-image-preview",filename:t.filename},image:{url:r.url,filename:t.filename}})},e[9]=t.filename,e[10]=r.status,e[11]=r.url,e[12]=m,e[13]=v):v=e[13];const N=v,_=r.status!=="ready";let f;e[14]!==t.filename||e[15]!==r.status||e[16]!==r.url?(f=s.jsx("span",{className:"flex h-[72px] w-[100px] items-center justify-center overflow-hidden rounded-lg border border-border/40 bg-muted/10",children:r.url&&r.status!=="error"?s.jsx("img",{src:r.url,alt:t.filename,className:"h-full w-full object-contain",loading:"lazy",decoding:"async",referrerPolicy:"no-referrer",onLoad:()=>l(D),onError:()=>l({url:"",status:"error"}),"data-openchamber-markdown-image":"true","data-openchamber-markdown-image-thumbnail":"true","data-openchamber-markdown-image-state":r.status}):s.jsx(M,{name:"file-image",className:"h-5 w-5 text-muted-foreground"})}),e[14]=t.filename,e[15]=r.status,e[16]=r.url,e[17]=f):f=e[17];let j;e[18]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(M,{name:"file-image",className:"h-3 w-3 shrink-0"}),e[18]=j):j=e[18];let d;e[19]!==t.filename?(d=s.jsx("span",{className:"min-w-0 truncate typography-meta",children:t.filename}),e[19]=t.filename,e[20]=d):d=e[20];let g;e[21]!==t.filename||e[22]!==d?(g=s.jsxs("span",{className:"mt-1 flex w-[100px] items-center justify-center gap-1 text-muted-foreground",title:t.filename,"data-openchamber-markdown-image-caption":"true",children:[j,d]}),e[21]=t.filename,e[22]=d,e[23]=g):g=e[23];let I;return e[24]!==t.filename||e[25]!==t.source||e[26]!==N||e[27]!==g||e[28]!==_||e[29]!==f?(I=s.jsxs("button",{ref:c,type:"button",className:"w-[100px] shrink-0 text-left outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":t.filename,disabled:_,onClick:N,"data-openchamber-markdown-image-action":"true","data-openchamber-markdown-image-source":t.source,"data-openchamber-markdown-image-filename":t.filename,children:[f,g]}),e[24]=t.filename,e[25]=t.source,e[26]=N,e[27]=g,e[28]=_,e[29]=f,e[30]=I):I=e[30],I},dt=p=>{const e=S.c(11),{contents:t,onShowPopup:i}=p,m=R()??"";let c;e[0]!==t?(c=A(t,C),e[0]=t,e[1]=c):c=e[1];const o=c;if(o.length===0)return null;let a;if(e[2]!==o||e[3]!==m||e[4]!==i){let r;e[6]!==m||e[7]!==i?(r=l=>s.jsx(P,{candidate:l,directory:m,onShowPopup:i},l.source),e[6]=m,e[7]=i,e[8]=r):r=e[8],a=o.map(r),e[2]=o,e[3]=m,e[4]=i,e[5]=a}else a=e[5];let n;return e[9]!==a?(n=s.jsx("div",{className:"mt-3 flex max-w-full gap-2 overflow-x-auto pb-1","data-openchamber-markdown-image-gallery":"true",children:a}),e[9]=a,e[10]=n):n=e[10],n};function L(p){return p.isIntersecting}function D(p){return{...p,status:"ready"}}export{dt as MarkdownImageGallery};