@surething/cockpit 1.1.8 → 1.1.9

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 (598) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +9 -5
  3. package/.next-prod/build-manifest.json +2 -2
  4. package/.next-prod/cockpit-build.json +1 -1
  5. package/.next-prod/prerender-manifest.json +3 -3
  6. package/.next-prod/routes-manifest.json +24 -0
  7. package/.next-prod/server/app/_global-error/page.js +2 -2
  8. package/.next-prod/server/app/_global-error/page_client-reference-manifest.js +1 -1
  9. package/.next-prod/server/app/_global-error.html +1 -1
  10. package/.next-prod/server/app/_global-error.rsc +1 -1
  11. package/.next-prod/server/app/_global-error.segments/_full.segment.rsc +1 -1
  12. package/.next-prod/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  13. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next-prod/server/app/_not-found/page.js +1 -1
  15. package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
  16. package/.next-prod/server/app/api/agent/test/route.js +1 -1
  17. package/.next-prod/server/app/api/bash/route.js +1 -1
  18. package/.next-prod/server/app/api/bots/[id]/route.js +1 -1
  19. package/.next-prod/server/app/api/bots/files/route.js +1 -1
  20. package/.next-prod/server/app/api/bots/route.js +1 -1
  21. package/.next-prod/server/app/api/chat/codex/route.js +1 -1
  22. package/.next-prod/server/app/api/chat/deepseek/route.js +1 -1
  23. package/.next-prod/server/app/api/chat/glm/route.js +1 -1
  24. package/.next-prod/server/app/api/chat/grok/route.js +1 -1
  25. package/.next-prod/server/app/api/chat/kimi/route.js +1 -1
  26. package/.next-prod/server/app/api/chat/ollama/route.js +1 -1
  27. package/.next-prod/server/app/api/chat/route.js +1 -1
  28. package/.next-prod/server/app/api/chat/stop/route.js +1 -1
  29. package/.next-prod/server/app/api/claude-stats/route.js +1 -1
  30. package/.next-prod/server/app/api/commands/route.js +1 -1
  31. package/.next-prod/server/app/api/comments/route.js +1 -1
  32. package/.next-prod/server/app/api/db/columns/route.js +1 -1
  33. package/.next-prod/server/app/api/db/connect/route.js +1 -1
  34. package/.next-prod/server/app/api/db/disconnect/route.js +1 -1
  35. package/.next-prod/server/app/api/db/export/route.js +1 -1
  36. package/.next-prod/server/app/api/db/query/route.js +1 -1
  37. package/.next-prod/server/app/api/db/schemas/route.js +2 -2
  38. package/.next-prod/server/app/api/deepseek/balance/route.js +1 -1
  39. package/.next-prod/server/app/api/deepseek/credentials/route.js +1 -1
  40. package/.next-prod/server/app/api/deepseek/models/route.js +1 -1
  41. package/.next-prod/server/app/api/dev/spans/route.js +1 -1
  42. package/.next-prod/server/app/api/extension/version/route.js +1 -1
  43. package/.next-prod/server/app/api/file/route.js +1 -1
  44. package/.next-prod/server/app/api/files/blame/route.js +1 -1
  45. package/.next-prod/server/app/api/files/clipboard/route.js +1 -1
  46. package/.next-prod/server/app/api/files/copy/route.js +1 -1
  47. package/.next-prod/server/app/api/files/delete/route.js +1 -1
  48. package/.next-prod/server/app/api/files/expanded/route.js +1 -1
  49. package/.next-prod/server/app/api/files/index/route.js +1 -1
  50. package/.next-prod/server/app/api/files/init/route.js +1 -1
  51. package/.next-prod/server/app/api/files/paste/route.js +1 -1
  52. package/.next-prod/server/app/api/files/read/route.js +1 -1
  53. package/.next-prod/server/app/api/files/readdir/route.js +1 -1
  54. package/.next-prod/server/app/api/files/recent/route.js +1 -1
  55. package/.next-prod/server/app/api/files/save/route.js +1 -1
  56. package/.next-prod/server/app/api/files/search/route.js +1 -1
  57. package/.next-prod/server/app/api/files/stat/route.js +1 -1
  58. package/.next-prod/server/app/api/files/text/route.js +1 -1
  59. package/.next-prod/server/app/api/fs/dirs/route.js +1 -1
  60. package/.next-prod/server/app/api/git/blob/route.js +1 -1
  61. package/.next-prod/server/app/api/git/branch-diff/route.js +1 -1
  62. package/.next-prod/server/app/api/git/branches/route.js +1 -1
  63. package/.next-prod/server/app/api/git/commit-diff/route.js +1 -1
  64. package/.next-prod/server/app/api/git/commits/route.js +1 -1
  65. package/.next-prod/server/app/api/git/current-branch/route.js +1 -1
  66. package/.next-prod/server/app/api/git/diff/route.js +1 -1
  67. package/.next-prod/server/app/api/git/discard/route.js +1 -1
  68. package/.next-prod/server/app/api/git/stage/route.js +1 -1
  69. package/.next-prod/server/app/api/git/status/route.js +1 -1
  70. package/.next-prod/server/app/api/git/unstage/route.js +1 -1
  71. package/.next-prod/server/app/api/git/worktree/route.js +1 -1
  72. package/.next-prod/server/app/api/glm/credentials/route.js +1 -1
  73. package/.next-prod/server/app/api/glm/models/route.js +1 -1
  74. package/.next-prod/server/app/api/glm/usage/route.js +1 -1
  75. package/.next-prod/server/app/api/global-state/route.js +2 -2
  76. package/.next-prod/server/app/api/grok/models/route.js +1 -1
  77. package/.next-prod/server/app/api/health/route.js +1 -1
  78. package/.next-prod/server/app/api/html-apps/[id]/route.js +1 -1
  79. package/.next-prod/server/app/api/html-apps/files/route.js +1 -1
  80. package/.next-prod/server/app/api/html-apps/route.js +1 -1
  81. package/.next-prod/server/app/api/instructions/config/route.js +1 -1
  82. package/.next-prod/server/app/api/kimi/credentials/route.js +1 -1
  83. package/.next-prod/server/app/api/kimi/models/route.js +1 -1
  84. package/.next-prod/server/app/api/kimi/usage/route.js +1 -1
  85. package/.next-prod/server/app/api/lsp/definition/route.js +1 -1
  86. package/.next-prod/server/app/api/lsp/hover/route.js +1 -1
  87. package/.next-prod/server/app/api/lsp/references/route.js +1 -1
  88. package/.next-prod/server/app/api/lsp/status/route.js +1 -1
  89. package/.next-prod/server/app/api/lsp/warmup/route.js +1 -1
  90. package/.next-prod/server/app/api/mobile-link/route.js +1 -1
  91. package/.next-prod/server/app/api/mysql/columns/route.js +2 -2
  92. package/.next-prod/server/app/api/mysql/connect/route.js +1 -1
  93. package/.next-prod/server/app/api/mysql/disconnect/route.js +1 -1
  94. package/.next-prod/server/app/api/mysql/export/route.js +1 -1
  95. package/.next-prod/server/app/api/mysql/query/route.js +1 -1
  96. package/.next-prod/server/app/api/mysql/schemas/route.js +2 -2
  97. package/.next-prod/server/app/api/neo4j/connect/route.js +1 -1
  98. package/.next-prod/server/app/api/neo4j/disconnect/route.js +1 -1
  99. package/.next-prod/server/app/api/neo4j/query/route.js +1 -1
  100. package/.next-prod/server/app/api/neo4j/schema/route.js +1 -1
  101. package/.next-prod/server/app/api/note/list/route.js +1 -1
  102. package/.next-prod/server/app/api/note/route.js +1 -1
  103. package/.next-prod/server/app/api/ollama/config/route.js +1 -1
  104. package/.next-prod/server/app/api/ollama/default-model/route.js +1 -1
  105. package/.next-prod/server/app/api/ollama/models/route.js +1 -1
  106. package/.next-prod/server/app/api/ollama/start/route.js +1 -1
  107. package/.next-prod/server/app/api/open-cursor/route.js +1 -1
  108. package/.next-prod/server/app/api/open-vscode/route.js +1 -1
  109. package/.next-prod/server/app/api/pi/thinking/route.js +1 -1
  110. package/.next-prod/server/app/api/pinned-sessions/route.js +1 -1
  111. package/.next-prod/server/app/api/project-settings/route.js +1 -1
  112. package/.next-prod/server/app/api/project-state/route.js +2 -2
  113. package/.next-prod/server/app/api/projectGraph/affected/route.js +1 -1
  114. package/.next-prod/server/app/api/projectGraph/callees/route.js +1 -1
  115. package/.next-prod/server/app/api/projectGraph/callers/route.js +1 -1
  116. package/.next-prod/server/app/api/projectGraph/coedit/route.js +1 -1
  117. package/.next-prod/server/app/api/projectGraph/edges/route.js +1 -0
  118. package/.next-prod/server/app/api/projectGraph/edges/route.js.nft.json +1 -0
  119. package/.next-prod/server/app/api/projectGraph/edges/route_client-reference-manifest.js +1 -0
  120. package/.next-prod/server/app/api/projectGraph/file/route.js +1 -1
  121. package/.next-prod/server/app/api/projectGraph/file-functions/route.js +1 -1
  122. package/.next-prod/server/app/api/projectGraph/impact/route.js +1 -1
  123. package/.next-prod/server/app/api/projectGraph/maps/route.js +1 -0
  124. package/.next-prod/server/app/api/projectGraph/maps/route.js.nft.json +1 -0
  125. package/.next-prod/server/app/api/projectGraph/maps/route_client-reference-manifest.js +1 -0
  126. package/.next-prod/server/app/api/projectGraph/related/route.js +1 -1
  127. package/.next-prod/server/app/api/projectGraph/search/route.js +1 -1
  128. package/.next-prod/server/app/api/projectGraph/symbols/route.js +1 -1
  129. package/.next-prod/server/app/api/projects/route.js +1 -1
  130. package/.next-prod/server/app/api/push/public-key/route.js +1 -1
  131. package/.next-prod/server/app/api/push/subscribe/route.js +1 -1
  132. package/.next-prod/server/app/api/push/unsubscribe/route.js +1 -1
  133. package/.next-prod/server/app/api/redis/command/route.js +1 -1
  134. package/.next-prod/server/app/api/redis/connect/route.js +1 -1
  135. package/.next-prod/server/app/api/redis/delete/route.js +1 -1
  136. package/.next-prod/server/app/api/redis/disconnect/route.js +1 -1
  137. package/.next-prod/server/app/api/redis/get/route.js +1 -1
  138. package/.next-prod/server/app/api/redis/keys/route.js +1 -1
  139. package/.next-prod/server/app/api/redis/set/route.js +1 -1
  140. package/.next-prod/server/app/api/restart/route.js +1 -1
  141. package/.next-prod/server/app/api/scheduled-tasks/route.js +2 -2
  142. package/.next-prod/server/app/api/services/config/route.js +1 -1
  143. package/.next-prod/server/app/api/services/scripts/route.js +1 -1
  144. package/.next-prod/server/app/api/session/[sessionId]/fork/route.js +1 -1
  145. package/.next-prod/server/app/api/session/[sessionId]/history/route.js +1 -1
  146. package/.next-prod/server/app/api/session/[sessionId]/turn/route.js +2 -2
  147. package/.next-prod/server/app/api/session/image/route.js +1 -1
  148. package/.next-prod/server/app/api/session/user-messages/route.js +1 -1
  149. package/.next-prod/server/app/api/session-bots/route.js +1 -1
  150. package/.next-prod/server/app/api/session-by-path/route.js +1 -1
  151. package/.next-prod/server/app/api/session-context/route.js +2 -2
  152. package/.next-prod/server/app/api/session-title/route.js +1 -1
  153. package/.next-prod/server/app/api/session-title/suggest/route.js +1 -1
  154. package/.next-prod/server/app/api/sessions/delegate/route.js +1 -1
  155. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js +1 -1
  156. package/.next-prod/server/app/api/sessions/projects/route.js +1 -1
  157. package/.next-prod/server/app/api/sessions/search/route.js +1 -1
  158. package/.next-prod/server/app/api/sessions/status/route.js +1 -1
  159. package/.next-prod/server/app/api/settings/route.js +1 -1
  160. package/.next-prod/server/app/api/shutdown/route.js +1 -1
  161. package/.next-prod/server/app/api/skills/[id]/route.js +1 -1
  162. package/.next-prod/server/app/api/skills/builtin/route.js +1 -1
  163. package/.next-prod/server/app/api/skills/content/route.js +1 -1
  164. package/.next-prod/server/app/api/skills/files/route.js +1 -1
  165. package/.next-prod/server/app/api/skills/route.js +1 -1
  166. package/.next-prod/server/app/api/snapshots/blob/route.js +1 -1
  167. package/.next-prod/server/app/api/snapshots/diff/route.js +1 -1
  168. package/.next-prod/server/app/api/snapshots/mark/route.js +1 -0
  169. package/.next-prod/server/app/api/snapshots/mark/route.js.nft.json +1 -0
  170. package/.next-prod/server/app/api/snapshots/mark/route_client-reference-manifest.js +1 -0
  171. package/.next-prod/server/app/api/snapshots/range-diff/route.js +1 -1
  172. package/.next-prod/server/app/api/snapshots/restore/route.js +1 -0
  173. package/.next-prod/server/app/api/snapshots/restore/route.js.nft.json +1 -0
  174. package/.next-prod/server/app/api/snapshots/restore/route_client-reference-manifest.js +1 -0
  175. package/.next-prod/server/app/api/snapshots/route.js +1 -1
  176. package/.next-prod/server/app/api/terminal/aliases/route.js +1 -1
  177. package/.next-prod/server/app/api/terminal/autocomplete/route.js +1 -1
  178. package/.next-prod/server/app/api/terminal/bubble-order/route.js +1 -1
  179. package/.next-prod/server/app/api/terminal/env/route.js +1 -1
  180. package/.next-prod/server/app/api/terminal/history/route.js +1 -1
  181. package/.next-prod/server/app/api/terminal/running/route.js +1 -1
  182. package/.next-prod/server/app/api/update/route.js +1 -1
  183. package/.next-prod/server/app/api/update-state/route.js +1 -1
  184. package/.next-prod/server/app/api/version/route.js +1 -1
  185. package/.next-prod/server/app/apps/[...path]/route.js +1 -1
  186. package/.next-prod/server/app/favicon.ico/route.js +1 -1
  187. package/.next-prod/server/app/m/page.js +2 -1
  188. package/.next-prod/server/app/m/page_client-reference-manifest.js +1 -1
  189. package/.next-prod/server/app/manifest.webmanifest/route.js +1 -1
  190. package/.next-prod/server/app/page.js +1 -1
  191. package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
  192. package/.next-prod/server/app/project/page.js +1 -1
  193. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  194. package/.next-prod/server/app-paths-manifest.json +9 -5
  195. package/.next-prod/server/chunks/2493.js +13 -13
  196. package/.next-prod/server/chunks/4949.js +1 -1
  197. package/.next-prod/server/chunks/6610.js +34 -34
  198. package/.next-prod/server/chunks/7270.js +1 -1
  199. package/.next-prod/server/chunks/9830.js +2 -2
  200. package/.next-prod/server/chunks/9998.js +1 -1
  201. package/.next-prod/server/middleware-build-manifest.js +1 -1
  202. package/.next-prod/server/next-font-manifest.js +1 -1
  203. package/.next-prod/server/next-font-manifest.json +1 -1
  204. package/.next-prod/server/pages/500.html +1 -1
  205. package/.next-prod/server/server-reference-manifest.json +1 -1
  206. package/.next-prod/static/LwAYWBEgXwTIkuj7U9BpE/_buildManifest.js +1 -0
  207. package/.next-prod/static/chunks/{50189-b59a96372658a46a.js → 55541-994b26deaa23f4e6.js} +2 -2
  208. package/.next-prod/static/chunks/{731-fd4b8bcd1d40dfe9.js → 6837-78c0d1a8165d46f7.js} +21 -21
  209. package/.next-prod/static/chunks/92000-46024df89fb50e16.js +41 -0
  210. package/.next-prod/static/chunks/98596-4ca2d2544138aefd.js +733 -0
  211. package/.next-prod/static/chunks/app/_global-error/page-6af5bc188af96106.js +1 -0
  212. package/.next-prod/static/chunks/app/api/agent/test/route-6af5bc188af96106.js +1 -0
  213. package/.next-prod/static/chunks/app/api/bash/route-6af5bc188af96106.js +1 -0
  214. package/.next-prod/static/chunks/app/api/bots/[id]/route-6af5bc188af96106.js +1 -0
  215. package/.next-prod/static/chunks/app/api/bots/files/route-6af5bc188af96106.js +1 -0
  216. package/.next-prod/static/chunks/app/api/bots/route-6af5bc188af96106.js +1 -0
  217. package/.next-prod/static/chunks/app/api/chat/codex/route-6af5bc188af96106.js +1 -0
  218. package/.next-prod/static/chunks/app/api/chat/deepseek/route-6af5bc188af96106.js +1 -0
  219. package/.next-prod/static/chunks/app/api/chat/glm/route-6af5bc188af96106.js +1 -0
  220. package/.next-prod/static/chunks/app/api/chat/grok/route-6af5bc188af96106.js +1 -0
  221. package/.next-prod/static/chunks/app/api/chat/kimi/route-6af5bc188af96106.js +1 -0
  222. package/.next-prod/static/chunks/app/api/chat/ollama/route-6af5bc188af96106.js +1 -0
  223. package/.next-prod/static/chunks/app/api/chat/route-6af5bc188af96106.js +1 -0
  224. package/.next-prod/static/chunks/app/api/chat/stop/route-6af5bc188af96106.js +1 -0
  225. package/.next-prod/static/chunks/app/api/claude-stats/route-6af5bc188af96106.js +1 -0
  226. package/.next-prod/static/chunks/app/api/commands/route-6af5bc188af96106.js +1 -0
  227. package/.next-prod/static/chunks/app/api/comments/route-6af5bc188af96106.js +1 -0
  228. package/.next-prod/static/chunks/app/api/db/columns/route-6af5bc188af96106.js +1 -0
  229. package/.next-prod/static/chunks/app/api/db/connect/route-6af5bc188af96106.js +1 -0
  230. package/.next-prod/static/chunks/app/api/db/disconnect/route-6af5bc188af96106.js +1 -0
  231. package/.next-prod/static/chunks/app/api/db/export/route-6af5bc188af96106.js +1 -0
  232. package/.next-prod/static/chunks/app/api/db/query/route-6af5bc188af96106.js +1 -0
  233. package/.next-prod/static/chunks/app/api/db/schemas/route-6af5bc188af96106.js +1 -0
  234. package/.next-prod/static/chunks/app/api/deepseek/balance/route-6af5bc188af96106.js +1 -0
  235. package/.next-prod/static/chunks/app/api/deepseek/credentials/route-6af5bc188af96106.js +1 -0
  236. package/.next-prod/static/chunks/app/api/deepseek/models/route-6af5bc188af96106.js +1 -0
  237. package/.next-prod/static/chunks/app/api/dev/spans/route-6af5bc188af96106.js +1 -0
  238. package/.next-prod/static/chunks/app/api/extension/version/route-6af5bc188af96106.js +1 -0
  239. package/.next-prod/static/chunks/app/api/file/route-6af5bc188af96106.js +1 -0
  240. package/.next-prod/static/chunks/app/api/files/blame/route-6af5bc188af96106.js +1 -0
  241. package/.next-prod/static/chunks/app/api/files/clipboard/route-6af5bc188af96106.js +1 -0
  242. package/.next-prod/static/chunks/app/api/files/copy/route-6af5bc188af96106.js +1 -0
  243. package/.next-prod/static/chunks/app/api/files/delete/route-6af5bc188af96106.js +1 -0
  244. package/.next-prod/static/chunks/app/api/files/expanded/route-6af5bc188af96106.js +1 -0
  245. package/.next-prod/static/chunks/app/api/files/index/route-6af5bc188af96106.js +1 -0
  246. package/.next-prod/static/chunks/app/api/files/init/route-6af5bc188af96106.js +1 -0
  247. package/.next-prod/static/chunks/app/api/files/paste/route-6af5bc188af96106.js +1 -0
  248. package/.next-prod/static/chunks/app/api/files/read/route-6af5bc188af96106.js +1 -0
  249. package/.next-prod/static/chunks/app/api/files/readdir/route-6af5bc188af96106.js +1 -0
  250. package/.next-prod/static/chunks/app/api/files/recent/route-6af5bc188af96106.js +1 -0
  251. package/.next-prod/static/chunks/app/api/files/save/route-6af5bc188af96106.js +1 -0
  252. package/.next-prod/static/chunks/app/api/files/search/route-6af5bc188af96106.js +1 -0
  253. package/.next-prod/static/chunks/app/api/files/stat/route-6af5bc188af96106.js +1 -0
  254. package/.next-prod/static/chunks/app/api/files/text/route-6af5bc188af96106.js +1 -0
  255. package/.next-prod/static/chunks/app/api/fs/dirs/route-6af5bc188af96106.js +1 -0
  256. package/.next-prod/static/chunks/app/api/git/blob/route-6af5bc188af96106.js +1 -0
  257. package/.next-prod/static/chunks/app/api/git/branch-diff/route-6af5bc188af96106.js +1 -0
  258. package/.next-prod/static/chunks/app/api/git/branches/route-6af5bc188af96106.js +1 -0
  259. package/.next-prod/static/chunks/app/api/git/commit-diff/route-6af5bc188af96106.js +1 -0
  260. package/.next-prod/static/chunks/app/api/git/commits/route-6af5bc188af96106.js +1 -0
  261. package/.next-prod/static/chunks/app/api/git/current-branch/route-6af5bc188af96106.js +1 -0
  262. package/.next-prod/static/chunks/app/api/git/diff/route-6af5bc188af96106.js +1 -0
  263. package/.next-prod/static/chunks/app/api/git/discard/route-6af5bc188af96106.js +1 -0
  264. package/.next-prod/static/chunks/app/api/git/stage/route-6af5bc188af96106.js +1 -0
  265. package/.next-prod/static/chunks/app/api/git/status/route-6af5bc188af96106.js +1 -0
  266. package/.next-prod/static/chunks/app/api/git/unstage/route-6af5bc188af96106.js +1 -0
  267. package/.next-prod/static/chunks/app/api/git/worktree/route-6af5bc188af96106.js +1 -0
  268. package/.next-prod/static/chunks/app/api/glm/credentials/route-6af5bc188af96106.js +1 -0
  269. package/.next-prod/static/chunks/app/api/glm/models/route-6af5bc188af96106.js +1 -0
  270. package/.next-prod/static/chunks/app/api/glm/usage/route-6af5bc188af96106.js +1 -0
  271. package/.next-prod/static/chunks/app/api/global-state/route-6af5bc188af96106.js +1 -0
  272. package/.next-prod/static/chunks/app/api/grok/models/route-6af5bc188af96106.js +1 -0
  273. package/.next-prod/static/chunks/app/api/health/route-6af5bc188af96106.js +1 -0
  274. package/.next-prod/static/chunks/app/api/html-apps/[id]/route-6af5bc188af96106.js +1 -0
  275. package/.next-prod/static/chunks/app/api/html-apps/files/route-6af5bc188af96106.js +1 -0
  276. package/.next-prod/static/chunks/app/api/html-apps/route-6af5bc188af96106.js +1 -0
  277. package/.next-prod/static/chunks/app/api/instructions/config/route-6af5bc188af96106.js +1 -0
  278. package/.next-prod/static/chunks/app/api/kimi/credentials/route-6af5bc188af96106.js +1 -0
  279. package/.next-prod/static/chunks/app/api/kimi/models/route-6af5bc188af96106.js +1 -0
  280. package/.next-prod/static/chunks/app/api/kimi/usage/route-6af5bc188af96106.js +1 -0
  281. package/.next-prod/static/chunks/app/api/lsp/definition/route-6af5bc188af96106.js +1 -0
  282. package/.next-prod/static/chunks/app/api/lsp/hover/route-6af5bc188af96106.js +1 -0
  283. package/.next-prod/static/chunks/app/api/lsp/references/route-6af5bc188af96106.js +1 -0
  284. package/.next-prod/static/chunks/app/api/lsp/status/route-6af5bc188af96106.js +1 -0
  285. package/.next-prod/static/chunks/app/api/lsp/warmup/route-6af5bc188af96106.js +1 -0
  286. package/.next-prod/static/chunks/app/api/mobile-link/route-6af5bc188af96106.js +1 -0
  287. package/.next-prod/static/chunks/app/api/mysql/columns/route-6af5bc188af96106.js +1 -0
  288. package/.next-prod/static/chunks/app/api/mysql/connect/route-6af5bc188af96106.js +1 -0
  289. package/.next-prod/static/chunks/app/api/mysql/disconnect/route-6af5bc188af96106.js +1 -0
  290. package/.next-prod/static/chunks/app/api/mysql/export/route-6af5bc188af96106.js +1 -0
  291. package/.next-prod/static/chunks/app/api/mysql/query/route-6af5bc188af96106.js +1 -0
  292. package/.next-prod/static/chunks/app/api/mysql/schemas/route-6af5bc188af96106.js +1 -0
  293. package/.next-prod/static/chunks/app/api/neo4j/connect/route-6af5bc188af96106.js +1 -0
  294. package/.next-prod/static/chunks/app/api/neo4j/disconnect/route-6af5bc188af96106.js +1 -0
  295. package/.next-prod/static/chunks/app/api/neo4j/query/route-6af5bc188af96106.js +1 -0
  296. package/.next-prod/static/chunks/app/api/neo4j/schema/route-6af5bc188af96106.js +1 -0
  297. package/.next-prod/static/chunks/app/api/note/list/route-6af5bc188af96106.js +1 -0
  298. package/.next-prod/static/chunks/app/api/note/route-6af5bc188af96106.js +1 -0
  299. package/.next-prod/static/chunks/app/api/ollama/config/route-6af5bc188af96106.js +1 -0
  300. package/.next-prod/static/chunks/app/api/ollama/default-model/route-6af5bc188af96106.js +1 -0
  301. package/.next-prod/static/chunks/app/api/ollama/models/route-6af5bc188af96106.js +1 -0
  302. package/.next-prod/static/chunks/app/api/ollama/start/route-6af5bc188af96106.js +1 -0
  303. package/.next-prod/static/chunks/app/api/open-cursor/route-6af5bc188af96106.js +1 -0
  304. package/.next-prod/static/chunks/app/api/open-vscode/route-6af5bc188af96106.js +1 -0
  305. package/.next-prod/static/chunks/app/api/pi/thinking/route-6af5bc188af96106.js +1 -0
  306. package/.next-prod/static/chunks/app/api/pinned-sessions/route-6af5bc188af96106.js +1 -0
  307. package/.next-prod/static/chunks/app/api/project-settings/route-6af5bc188af96106.js +1 -0
  308. package/.next-prod/static/chunks/app/api/project-state/route-6af5bc188af96106.js +1 -0
  309. package/.next-prod/static/chunks/app/api/projectGraph/affected/route-6af5bc188af96106.js +1 -0
  310. package/.next-prod/static/chunks/app/api/projectGraph/callees/route-6af5bc188af96106.js +1 -0
  311. package/.next-prod/static/chunks/app/api/projectGraph/callers/route-6af5bc188af96106.js +1 -0
  312. package/.next-prod/static/chunks/app/api/projectGraph/coedit/route-6af5bc188af96106.js +1 -0
  313. package/.next-prod/static/chunks/app/api/projectGraph/edges/route-6af5bc188af96106.js +1 -0
  314. package/.next-prod/static/chunks/app/api/projectGraph/file/route-6af5bc188af96106.js +1 -0
  315. package/.next-prod/static/chunks/app/api/projectGraph/file-functions/route-6af5bc188af96106.js +1 -0
  316. package/.next-prod/static/chunks/app/api/projectGraph/impact/route-6af5bc188af96106.js +1 -0
  317. package/.next-prod/static/chunks/app/api/projectGraph/maps/route-6af5bc188af96106.js +1 -0
  318. package/.next-prod/static/chunks/app/api/projectGraph/related/route-6af5bc188af96106.js +1 -0
  319. package/.next-prod/static/chunks/app/api/projectGraph/search/route-6af5bc188af96106.js +1 -0
  320. package/.next-prod/static/chunks/app/api/projectGraph/symbols/route-6af5bc188af96106.js +1 -0
  321. package/.next-prod/static/chunks/app/api/projects/route-6af5bc188af96106.js +1 -0
  322. package/.next-prod/static/chunks/app/api/push/public-key/route-6af5bc188af96106.js +1 -0
  323. package/.next-prod/static/chunks/app/api/push/subscribe/route-6af5bc188af96106.js +1 -0
  324. package/.next-prod/static/chunks/app/api/push/unsubscribe/route-6af5bc188af96106.js +1 -0
  325. package/.next-prod/static/chunks/app/api/redis/command/route-6af5bc188af96106.js +1 -0
  326. package/.next-prod/static/chunks/app/api/redis/connect/route-6af5bc188af96106.js +1 -0
  327. package/.next-prod/static/chunks/app/api/redis/delete/route-6af5bc188af96106.js +1 -0
  328. package/.next-prod/static/chunks/app/api/redis/disconnect/route-6af5bc188af96106.js +1 -0
  329. package/.next-prod/static/chunks/app/api/redis/get/route-6af5bc188af96106.js +1 -0
  330. package/.next-prod/static/chunks/app/api/redis/keys/route-6af5bc188af96106.js +1 -0
  331. package/.next-prod/static/chunks/app/api/redis/set/route-6af5bc188af96106.js +1 -0
  332. package/.next-prod/static/chunks/app/api/restart/route-6af5bc188af96106.js +1 -0
  333. package/.next-prod/static/chunks/app/api/scheduled-tasks/route-6af5bc188af96106.js +1 -0
  334. package/.next-prod/static/chunks/app/api/services/config/route-6af5bc188af96106.js +1 -0
  335. package/.next-prod/static/chunks/app/api/services/scripts/route-6af5bc188af96106.js +1 -0
  336. package/.next-prod/static/chunks/app/api/session/[sessionId]/fork/route-6af5bc188af96106.js +1 -0
  337. package/.next-prod/static/chunks/app/api/session/[sessionId]/history/route-6af5bc188af96106.js +1 -0
  338. package/.next-prod/static/chunks/app/api/session/[sessionId]/turn/route-6af5bc188af96106.js +1 -0
  339. package/.next-prod/static/chunks/app/api/session/image/route-6af5bc188af96106.js +1 -0
  340. package/.next-prod/static/chunks/app/api/session/user-messages/route-6af5bc188af96106.js +1 -0
  341. package/.next-prod/static/chunks/app/api/session-bots/route-6af5bc188af96106.js +1 -0
  342. package/.next-prod/static/chunks/app/api/session-by-path/route-6af5bc188af96106.js +1 -0
  343. package/.next-prod/static/chunks/app/api/session-context/route-6af5bc188af96106.js +1 -0
  344. package/.next-prod/static/chunks/app/api/session-title/route-6af5bc188af96106.js +1 -0
  345. package/.next-prod/static/chunks/app/api/session-title/suggest/route-6af5bc188af96106.js +1 -0
  346. package/.next-prod/static/chunks/app/api/sessions/delegate/route-6af5bc188af96106.js +1 -0
  347. package/.next-prod/static/chunks/app/api/sessions/projects/[encodedPath]/route-6af5bc188af96106.js +1 -0
  348. package/.next-prod/static/chunks/app/api/sessions/projects/route-6af5bc188af96106.js +1 -0
  349. package/.next-prod/static/chunks/app/api/sessions/search/route-6af5bc188af96106.js +1 -0
  350. package/.next-prod/static/chunks/app/api/sessions/status/route-6af5bc188af96106.js +1 -0
  351. package/.next-prod/static/chunks/app/api/settings/route-6af5bc188af96106.js +1 -0
  352. package/.next-prod/static/chunks/app/api/shutdown/route-6af5bc188af96106.js +1 -0
  353. package/.next-prod/static/chunks/app/api/skills/[id]/route-6af5bc188af96106.js +1 -0
  354. package/.next-prod/static/chunks/app/api/skills/builtin/route-6af5bc188af96106.js +1 -0
  355. package/.next-prod/static/chunks/app/api/skills/content/route-6af5bc188af96106.js +1 -0
  356. package/.next-prod/static/chunks/app/api/skills/files/route-6af5bc188af96106.js +1 -0
  357. package/.next-prod/static/chunks/app/api/skills/route-6af5bc188af96106.js +1 -0
  358. package/.next-prod/static/chunks/app/api/snapshots/blob/route-6af5bc188af96106.js +1 -0
  359. package/.next-prod/static/chunks/app/api/snapshots/diff/route-6af5bc188af96106.js +1 -0
  360. package/.next-prod/static/chunks/app/api/snapshots/mark/route-6af5bc188af96106.js +1 -0
  361. package/.next-prod/static/chunks/app/api/snapshots/range-diff/route-6af5bc188af96106.js +1 -0
  362. package/.next-prod/static/chunks/app/api/snapshots/restore/route-6af5bc188af96106.js +1 -0
  363. package/.next-prod/static/chunks/app/api/snapshots/route-6af5bc188af96106.js +1 -0
  364. package/.next-prod/static/chunks/app/api/terminal/aliases/route-6af5bc188af96106.js +1 -0
  365. package/.next-prod/static/chunks/app/api/terminal/autocomplete/route-6af5bc188af96106.js +1 -0
  366. package/.next-prod/static/chunks/app/api/terminal/bubble-order/route-6af5bc188af96106.js +1 -0
  367. package/.next-prod/static/chunks/app/api/terminal/env/route-6af5bc188af96106.js +1 -0
  368. package/.next-prod/static/chunks/app/api/terminal/history/route-6af5bc188af96106.js +1 -0
  369. package/.next-prod/static/chunks/app/api/terminal/running/route-6af5bc188af96106.js +1 -0
  370. package/.next-prod/static/chunks/app/api/update/route-6af5bc188af96106.js +1 -0
  371. package/.next-prod/static/chunks/app/api/update-state/route-6af5bc188af96106.js +1 -0
  372. package/.next-prod/static/chunks/app/api/version/route-6af5bc188af96106.js +1 -0
  373. package/.next-prod/static/chunks/app/apps/[...path]/route-6af5bc188af96106.js +1 -0
  374. package/.next-prod/static/chunks/app/{layout-f0ff0ab277c84dc6.js → layout-7107ed4eeac1f693.js} +1 -1
  375. package/.next-prod/static/chunks/app/m/page-0c8e79e2f753aecb.js +2 -0
  376. package/.next-prod/static/chunks/app/manifest.webmanifest/route-6af5bc188af96106.js +1 -0
  377. package/.next-prod/static/chunks/app/{page-d2ccfc2cb47ac4af.js → page-338a2c84319778b1.js} +1 -1
  378. package/.next-prod/static/chunks/app/project/{page-d2ccfc2cb47ac4af.js → page-338a2c84319778b1.js} +1 -1
  379. package/.next-prod/static/chunks/next/dist/client/components/builtin/app-error-6af5bc188af96106.js +1 -0
  380. package/.next-prod/static/chunks/next/dist/client/components/builtin/forbidden-6af5bc188af96106.js +1 -0
  381. package/.next-prod/static/chunks/next/dist/client/components/builtin/not-found-6af5bc188af96106.js +1 -0
  382. package/.next-prod/static/chunks/next/dist/client/components/builtin/unauthorized-6af5bc188af96106.js +1 -0
  383. package/.next-prod/static/css/fa34d3b1412ca27a.css +1 -0
  384. package/.next-prod/trace +86 -15
  385. package/.next-prod/trace-build +1 -1
  386. package/.next-prod/types/app/api/projectGraph/edges/route.ts +353 -0
  387. package/.next-prod/types/app/api/projectGraph/maps/route.ts +353 -0
  388. package/.next-prod/types/app/api/snapshots/mark/route.ts +353 -0
  389. package/.next-prod/types/app/api/snapshots/restore/route.ts +353 -0
  390. package/.next-prod/types/routes.d.ts +5 -1
  391. package/.next-prod/types/validator.ts +36 -0
  392. package/README.md +6 -0
  393. package/bin/rotateLog.mjs +6 -5
  394. package/desktop-checksums.json +4 -4
  395. package/dist/{anthropicCompat-PQWSZ3O7.mjs → anthropicCompat-4HZVLIFE.mjs} +3 -2
  396. package/dist/auth.mjs +19 -3
  397. package/dist/authAudit.mjs +79 -0
  398. package/dist/{chunk-6QDJ3QAX.mjs → chunk-6QHHEA3D.mjs} +11 -9
  399. package/dist/{chunk-2PDNZOMA.mjs → chunk-HJT5ZRYY.mjs} +2 -2
  400. package/dist/{chunk-S7FDWHAF.mjs → chunk-LSFNZJMR.mjs} +26825 -29730
  401. package/dist/{chunk-3S5JGONK.mjs → chunk-N3DTLFZE.mjs} +14 -12
  402. package/dist/{chunk-AKBWZB3V.mjs → chunk-QPFJKR3B.mjs} +2 -2
  403. package/dist/{chunk-LQISLDJ5.mjs → chunk-SI632CNY.mjs} +1 -1
  404. package/dist/{chunk-G747UZSS.mjs → chunk-T4M6CNFO.mjs} +132 -34
  405. package/dist/chunk-WSSVELJX.mjs +2920 -0
  406. package/dist/{chunk-2O6IH2TF.mjs → chunk-X4R5HO25.mjs} +2 -2
  407. package/dist/deepseek-YEPNQ2GX.mjs +13 -0
  408. package/dist/glm-SGT2LTOS.mjs +15 -0
  409. package/dist/httpApi.mjs +9 -8
  410. package/dist/kimi-FDXILCYU.mjs +15 -0
  411. package/dist/scheduledTasks.mjs +41 -15
  412. package/dist/{sessionStore-FF2VHKXM.mjs → sessionStore-WJGMZM4A.mjs} +2 -1
  413. package/dist/wsServer.mjs +63 -26
  414. package/package.json +3 -3
  415. package/public/html-lib/markdown.js +1 -1
  416. package/server.mjs +6 -1
  417. package/skills/cr/SKILL.md +184 -11
  418. package/skills/dl/SKILL.md +5 -0
  419. package/skills/rf/SKILL.md +124 -0
  420. package/skills/rf/axes.md +87 -0
  421. package/skills/rf/converge.md +50 -0
  422. package/skills/rf/fix.md +138 -0
  423. package/skills/rf/lenses.md +76 -0
  424. package/skills/rf/report.md +133 -0
  425. package/skills/rf/sources.md +129 -0
  426. package/.next-prod/static/AO-RPvB4uxOb6-XZ_0YXg/_buildManifest.js +0 -1
  427. package/.next-prod/static/chunks/17220-89a26ee102272095.js +0 -732
  428. package/.next-prod/static/chunks/45590-d1a8b4e539cc8dda.js +0 -42
  429. package/.next-prod/static/chunks/app/_global-error/page-42efcb4fd08c5099.js +0 -1
  430. package/.next-prod/static/chunks/app/api/agent/test/route-42efcb4fd08c5099.js +0 -1
  431. package/.next-prod/static/chunks/app/api/bash/route-42efcb4fd08c5099.js +0 -1
  432. package/.next-prod/static/chunks/app/api/bots/[id]/route-42efcb4fd08c5099.js +0 -1
  433. package/.next-prod/static/chunks/app/api/bots/files/route-42efcb4fd08c5099.js +0 -1
  434. package/.next-prod/static/chunks/app/api/bots/route-42efcb4fd08c5099.js +0 -1
  435. package/.next-prod/static/chunks/app/api/chat/codex/route-42efcb4fd08c5099.js +0 -1
  436. package/.next-prod/static/chunks/app/api/chat/deepseek/route-42efcb4fd08c5099.js +0 -1
  437. package/.next-prod/static/chunks/app/api/chat/glm/route-42efcb4fd08c5099.js +0 -1
  438. package/.next-prod/static/chunks/app/api/chat/grok/route-42efcb4fd08c5099.js +0 -1
  439. package/.next-prod/static/chunks/app/api/chat/kimi/route-42efcb4fd08c5099.js +0 -1
  440. package/.next-prod/static/chunks/app/api/chat/ollama/route-42efcb4fd08c5099.js +0 -1
  441. package/.next-prod/static/chunks/app/api/chat/route-42efcb4fd08c5099.js +0 -1
  442. package/.next-prod/static/chunks/app/api/chat/stop/route-42efcb4fd08c5099.js +0 -1
  443. package/.next-prod/static/chunks/app/api/claude-stats/route-42efcb4fd08c5099.js +0 -1
  444. package/.next-prod/static/chunks/app/api/commands/route-42efcb4fd08c5099.js +0 -1
  445. package/.next-prod/static/chunks/app/api/comments/route-42efcb4fd08c5099.js +0 -1
  446. package/.next-prod/static/chunks/app/api/db/columns/route-42efcb4fd08c5099.js +0 -1
  447. package/.next-prod/static/chunks/app/api/db/connect/route-42efcb4fd08c5099.js +0 -1
  448. package/.next-prod/static/chunks/app/api/db/disconnect/route-42efcb4fd08c5099.js +0 -1
  449. package/.next-prod/static/chunks/app/api/db/export/route-42efcb4fd08c5099.js +0 -1
  450. package/.next-prod/static/chunks/app/api/db/query/route-42efcb4fd08c5099.js +0 -1
  451. package/.next-prod/static/chunks/app/api/db/schemas/route-42efcb4fd08c5099.js +0 -1
  452. package/.next-prod/static/chunks/app/api/deepseek/balance/route-42efcb4fd08c5099.js +0 -1
  453. package/.next-prod/static/chunks/app/api/deepseek/credentials/route-42efcb4fd08c5099.js +0 -1
  454. package/.next-prod/static/chunks/app/api/deepseek/models/route-42efcb4fd08c5099.js +0 -1
  455. package/.next-prod/static/chunks/app/api/dev/spans/route-42efcb4fd08c5099.js +0 -1
  456. package/.next-prod/static/chunks/app/api/extension/version/route-42efcb4fd08c5099.js +0 -1
  457. package/.next-prod/static/chunks/app/api/file/route-42efcb4fd08c5099.js +0 -1
  458. package/.next-prod/static/chunks/app/api/files/blame/route-42efcb4fd08c5099.js +0 -1
  459. package/.next-prod/static/chunks/app/api/files/clipboard/route-42efcb4fd08c5099.js +0 -1
  460. package/.next-prod/static/chunks/app/api/files/copy/route-42efcb4fd08c5099.js +0 -1
  461. package/.next-prod/static/chunks/app/api/files/delete/route-42efcb4fd08c5099.js +0 -1
  462. package/.next-prod/static/chunks/app/api/files/expanded/route-42efcb4fd08c5099.js +0 -1
  463. package/.next-prod/static/chunks/app/api/files/index/route-42efcb4fd08c5099.js +0 -1
  464. package/.next-prod/static/chunks/app/api/files/init/route-42efcb4fd08c5099.js +0 -1
  465. package/.next-prod/static/chunks/app/api/files/paste/route-42efcb4fd08c5099.js +0 -1
  466. package/.next-prod/static/chunks/app/api/files/read/route-42efcb4fd08c5099.js +0 -1
  467. package/.next-prod/static/chunks/app/api/files/readdir/route-42efcb4fd08c5099.js +0 -1
  468. package/.next-prod/static/chunks/app/api/files/recent/route-42efcb4fd08c5099.js +0 -1
  469. package/.next-prod/static/chunks/app/api/files/save/route-42efcb4fd08c5099.js +0 -1
  470. package/.next-prod/static/chunks/app/api/files/search/route-42efcb4fd08c5099.js +0 -1
  471. package/.next-prod/static/chunks/app/api/files/stat/route-42efcb4fd08c5099.js +0 -1
  472. package/.next-prod/static/chunks/app/api/files/text/route-42efcb4fd08c5099.js +0 -1
  473. package/.next-prod/static/chunks/app/api/fs/dirs/route-42efcb4fd08c5099.js +0 -1
  474. package/.next-prod/static/chunks/app/api/git/blob/route-42efcb4fd08c5099.js +0 -1
  475. package/.next-prod/static/chunks/app/api/git/branch-diff/route-42efcb4fd08c5099.js +0 -1
  476. package/.next-prod/static/chunks/app/api/git/branches/route-42efcb4fd08c5099.js +0 -1
  477. package/.next-prod/static/chunks/app/api/git/commit-diff/route-42efcb4fd08c5099.js +0 -1
  478. package/.next-prod/static/chunks/app/api/git/commits/route-42efcb4fd08c5099.js +0 -1
  479. package/.next-prod/static/chunks/app/api/git/current-branch/route-42efcb4fd08c5099.js +0 -1
  480. package/.next-prod/static/chunks/app/api/git/diff/route-42efcb4fd08c5099.js +0 -1
  481. package/.next-prod/static/chunks/app/api/git/discard/route-42efcb4fd08c5099.js +0 -1
  482. package/.next-prod/static/chunks/app/api/git/stage/route-42efcb4fd08c5099.js +0 -1
  483. package/.next-prod/static/chunks/app/api/git/status/route-42efcb4fd08c5099.js +0 -1
  484. package/.next-prod/static/chunks/app/api/git/unstage/route-42efcb4fd08c5099.js +0 -1
  485. package/.next-prod/static/chunks/app/api/git/worktree/route-42efcb4fd08c5099.js +0 -1
  486. package/.next-prod/static/chunks/app/api/glm/credentials/route-42efcb4fd08c5099.js +0 -1
  487. package/.next-prod/static/chunks/app/api/glm/models/route-42efcb4fd08c5099.js +0 -1
  488. package/.next-prod/static/chunks/app/api/glm/usage/route-42efcb4fd08c5099.js +0 -1
  489. package/.next-prod/static/chunks/app/api/global-state/route-42efcb4fd08c5099.js +0 -1
  490. package/.next-prod/static/chunks/app/api/grok/models/route-42efcb4fd08c5099.js +0 -1
  491. package/.next-prod/static/chunks/app/api/health/route-42efcb4fd08c5099.js +0 -1
  492. package/.next-prod/static/chunks/app/api/html-apps/[id]/route-42efcb4fd08c5099.js +0 -1
  493. package/.next-prod/static/chunks/app/api/html-apps/files/route-42efcb4fd08c5099.js +0 -1
  494. package/.next-prod/static/chunks/app/api/html-apps/route-42efcb4fd08c5099.js +0 -1
  495. package/.next-prod/static/chunks/app/api/instructions/config/route-42efcb4fd08c5099.js +0 -1
  496. package/.next-prod/static/chunks/app/api/kimi/credentials/route-42efcb4fd08c5099.js +0 -1
  497. package/.next-prod/static/chunks/app/api/kimi/models/route-42efcb4fd08c5099.js +0 -1
  498. package/.next-prod/static/chunks/app/api/kimi/usage/route-42efcb4fd08c5099.js +0 -1
  499. package/.next-prod/static/chunks/app/api/lsp/definition/route-42efcb4fd08c5099.js +0 -1
  500. package/.next-prod/static/chunks/app/api/lsp/hover/route-42efcb4fd08c5099.js +0 -1
  501. package/.next-prod/static/chunks/app/api/lsp/references/route-42efcb4fd08c5099.js +0 -1
  502. package/.next-prod/static/chunks/app/api/lsp/status/route-42efcb4fd08c5099.js +0 -1
  503. package/.next-prod/static/chunks/app/api/lsp/warmup/route-42efcb4fd08c5099.js +0 -1
  504. package/.next-prod/static/chunks/app/api/mobile-link/route-42efcb4fd08c5099.js +0 -1
  505. package/.next-prod/static/chunks/app/api/mysql/columns/route-42efcb4fd08c5099.js +0 -1
  506. package/.next-prod/static/chunks/app/api/mysql/connect/route-42efcb4fd08c5099.js +0 -1
  507. package/.next-prod/static/chunks/app/api/mysql/disconnect/route-42efcb4fd08c5099.js +0 -1
  508. package/.next-prod/static/chunks/app/api/mysql/export/route-42efcb4fd08c5099.js +0 -1
  509. package/.next-prod/static/chunks/app/api/mysql/query/route-42efcb4fd08c5099.js +0 -1
  510. package/.next-prod/static/chunks/app/api/mysql/schemas/route-42efcb4fd08c5099.js +0 -1
  511. package/.next-prod/static/chunks/app/api/neo4j/connect/route-42efcb4fd08c5099.js +0 -1
  512. package/.next-prod/static/chunks/app/api/neo4j/disconnect/route-42efcb4fd08c5099.js +0 -1
  513. package/.next-prod/static/chunks/app/api/neo4j/query/route-42efcb4fd08c5099.js +0 -1
  514. package/.next-prod/static/chunks/app/api/neo4j/schema/route-42efcb4fd08c5099.js +0 -1
  515. package/.next-prod/static/chunks/app/api/note/list/route-42efcb4fd08c5099.js +0 -1
  516. package/.next-prod/static/chunks/app/api/note/route-42efcb4fd08c5099.js +0 -1
  517. package/.next-prod/static/chunks/app/api/ollama/config/route-42efcb4fd08c5099.js +0 -1
  518. package/.next-prod/static/chunks/app/api/ollama/default-model/route-42efcb4fd08c5099.js +0 -1
  519. package/.next-prod/static/chunks/app/api/ollama/models/route-42efcb4fd08c5099.js +0 -1
  520. package/.next-prod/static/chunks/app/api/ollama/start/route-42efcb4fd08c5099.js +0 -1
  521. package/.next-prod/static/chunks/app/api/open-cursor/route-42efcb4fd08c5099.js +0 -1
  522. package/.next-prod/static/chunks/app/api/open-vscode/route-42efcb4fd08c5099.js +0 -1
  523. package/.next-prod/static/chunks/app/api/pi/thinking/route-42efcb4fd08c5099.js +0 -1
  524. package/.next-prod/static/chunks/app/api/pinned-sessions/route-42efcb4fd08c5099.js +0 -1
  525. package/.next-prod/static/chunks/app/api/project-settings/route-42efcb4fd08c5099.js +0 -1
  526. package/.next-prod/static/chunks/app/api/project-state/route-42efcb4fd08c5099.js +0 -1
  527. package/.next-prod/static/chunks/app/api/projectGraph/affected/route-42efcb4fd08c5099.js +0 -1
  528. package/.next-prod/static/chunks/app/api/projectGraph/callees/route-42efcb4fd08c5099.js +0 -1
  529. package/.next-prod/static/chunks/app/api/projectGraph/callers/route-42efcb4fd08c5099.js +0 -1
  530. package/.next-prod/static/chunks/app/api/projectGraph/coedit/route-42efcb4fd08c5099.js +0 -1
  531. package/.next-prod/static/chunks/app/api/projectGraph/file/route-42efcb4fd08c5099.js +0 -1
  532. package/.next-prod/static/chunks/app/api/projectGraph/file-functions/route-42efcb4fd08c5099.js +0 -1
  533. package/.next-prod/static/chunks/app/api/projectGraph/impact/route-42efcb4fd08c5099.js +0 -1
  534. package/.next-prod/static/chunks/app/api/projectGraph/related/route-42efcb4fd08c5099.js +0 -1
  535. package/.next-prod/static/chunks/app/api/projectGraph/search/route-42efcb4fd08c5099.js +0 -1
  536. package/.next-prod/static/chunks/app/api/projectGraph/symbols/route-42efcb4fd08c5099.js +0 -1
  537. package/.next-prod/static/chunks/app/api/projects/route-42efcb4fd08c5099.js +0 -1
  538. package/.next-prod/static/chunks/app/api/push/public-key/route-42efcb4fd08c5099.js +0 -1
  539. package/.next-prod/static/chunks/app/api/push/subscribe/route-42efcb4fd08c5099.js +0 -1
  540. package/.next-prod/static/chunks/app/api/push/unsubscribe/route-42efcb4fd08c5099.js +0 -1
  541. package/.next-prod/static/chunks/app/api/redis/command/route-42efcb4fd08c5099.js +0 -1
  542. package/.next-prod/static/chunks/app/api/redis/connect/route-42efcb4fd08c5099.js +0 -1
  543. package/.next-prod/static/chunks/app/api/redis/delete/route-42efcb4fd08c5099.js +0 -1
  544. package/.next-prod/static/chunks/app/api/redis/disconnect/route-42efcb4fd08c5099.js +0 -1
  545. package/.next-prod/static/chunks/app/api/redis/get/route-42efcb4fd08c5099.js +0 -1
  546. package/.next-prod/static/chunks/app/api/redis/keys/route-42efcb4fd08c5099.js +0 -1
  547. package/.next-prod/static/chunks/app/api/redis/set/route-42efcb4fd08c5099.js +0 -1
  548. package/.next-prod/static/chunks/app/api/restart/route-42efcb4fd08c5099.js +0 -1
  549. package/.next-prod/static/chunks/app/api/scheduled-tasks/route-42efcb4fd08c5099.js +0 -1
  550. package/.next-prod/static/chunks/app/api/services/config/route-42efcb4fd08c5099.js +0 -1
  551. package/.next-prod/static/chunks/app/api/services/scripts/route-42efcb4fd08c5099.js +0 -1
  552. package/.next-prod/static/chunks/app/api/session/[sessionId]/fork/route-42efcb4fd08c5099.js +0 -1
  553. package/.next-prod/static/chunks/app/api/session/[sessionId]/history/route-42efcb4fd08c5099.js +0 -1
  554. package/.next-prod/static/chunks/app/api/session/[sessionId]/turn/route-42efcb4fd08c5099.js +0 -1
  555. package/.next-prod/static/chunks/app/api/session/image/route-42efcb4fd08c5099.js +0 -1
  556. package/.next-prod/static/chunks/app/api/session/user-messages/route-42efcb4fd08c5099.js +0 -1
  557. package/.next-prod/static/chunks/app/api/session-bots/route-42efcb4fd08c5099.js +0 -1
  558. package/.next-prod/static/chunks/app/api/session-by-path/route-42efcb4fd08c5099.js +0 -1
  559. package/.next-prod/static/chunks/app/api/session-context/route-42efcb4fd08c5099.js +0 -1
  560. package/.next-prod/static/chunks/app/api/session-title/route-42efcb4fd08c5099.js +0 -1
  561. package/.next-prod/static/chunks/app/api/session-title/suggest/route-42efcb4fd08c5099.js +0 -1
  562. package/.next-prod/static/chunks/app/api/sessions/delegate/route-42efcb4fd08c5099.js +0 -1
  563. package/.next-prod/static/chunks/app/api/sessions/projects/[encodedPath]/route-42efcb4fd08c5099.js +0 -1
  564. package/.next-prod/static/chunks/app/api/sessions/projects/route-42efcb4fd08c5099.js +0 -1
  565. package/.next-prod/static/chunks/app/api/sessions/search/route-42efcb4fd08c5099.js +0 -1
  566. package/.next-prod/static/chunks/app/api/sessions/status/route-42efcb4fd08c5099.js +0 -1
  567. package/.next-prod/static/chunks/app/api/settings/route-42efcb4fd08c5099.js +0 -1
  568. package/.next-prod/static/chunks/app/api/shutdown/route-42efcb4fd08c5099.js +0 -1
  569. package/.next-prod/static/chunks/app/api/skills/[id]/route-42efcb4fd08c5099.js +0 -1
  570. package/.next-prod/static/chunks/app/api/skills/builtin/route-42efcb4fd08c5099.js +0 -1
  571. package/.next-prod/static/chunks/app/api/skills/content/route-42efcb4fd08c5099.js +0 -1
  572. package/.next-prod/static/chunks/app/api/skills/files/route-42efcb4fd08c5099.js +0 -1
  573. package/.next-prod/static/chunks/app/api/skills/route-42efcb4fd08c5099.js +0 -1
  574. package/.next-prod/static/chunks/app/api/snapshots/blob/route-42efcb4fd08c5099.js +0 -1
  575. package/.next-prod/static/chunks/app/api/snapshots/diff/route-42efcb4fd08c5099.js +0 -1
  576. package/.next-prod/static/chunks/app/api/snapshots/range-diff/route-42efcb4fd08c5099.js +0 -1
  577. package/.next-prod/static/chunks/app/api/snapshots/route-42efcb4fd08c5099.js +0 -1
  578. package/.next-prod/static/chunks/app/api/terminal/aliases/route-42efcb4fd08c5099.js +0 -1
  579. package/.next-prod/static/chunks/app/api/terminal/autocomplete/route-42efcb4fd08c5099.js +0 -1
  580. package/.next-prod/static/chunks/app/api/terminal/bubble-order/route-42efcb4fd08c5099.js +0 -1
  581. package/.next-prod/static/chunks/app/api/terminal/env/route-42efcb4fd08c5099.js +0 -1
  582. package/.next-prod/static/chunks/app/api/terminal/history/route-42efcb4fd08c5099.js +0 -1
  583. package/.next-prod/static/chunks/app/api/terminal/running/route-42efcb4fd08c5099.js +0 -1
  584. package/.next-prod/static/chunks/app/api/update/route-42efcb4fd08c5099.js +0 -1
  585. package/.next-prod/static/chunks/app/api/update-state/route-42efcb4fd08c5099.js +0 -1
  586. package/.next-prod/static/chunks/app/api/version/route-42efcb4fd08c5099.js +0 -1
  587. package/.next-prod/static/chunks/app/apps/[...path]/route-42efcb4fd08c5099.js +0 -1
  588. package/.next-prod/static/chunks/app/m/page-50e48b4ba0942454.js +0 -1
  589. package/.next-prod/static/chunks/app/manifest.webmanifest/route-42efcb4fd08c5099.js +0 -1
  590. package/.next-prod/static/chunks/next/dist/client/components/builtin/app-error-42efcb4fd08c5099.js +0 -1
  591. package/.next-prod/static/chunks/next/dist/client/components/builtin/forbidden-42efcb4fd08c5099.js +0 -1
  592. package/.next-prod/static/chunks/next/dist/client/components/builtin/not-found-42efcb4fd08c5099.js +0 -1
  593. package/.next-prod/static/chunks/next/dist/client/components/builtin/unauthorized-42efcb4fd08c5099.js +0 -1
  594. package/.next-prod/static/css/74144fec62c7ff43.css +0 -1
  595. package/dist/deepseek-5QJ2IWS3.mjs +0 -12
  596. package/dist/glm-SIOUQCWL.mjs +0 -14
  597. package/dist/kimi-NKL4WBNS.mjs +0 -14
  598. /package/.next-prod/static/{AO-RPvB4uxOb6-XZ_0YXg → LwAYWBEgXwTIkuj7U9BpE}/_ssgManifest.js +0 -0
@@ -0,0 +1,41 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[92e3],{1767:(e,t,r)=>{r.d(t,{BotsModal:()=>P});var n=r(95155),s=r(12115),o=r(63393),a=r(33210),l=r(96035),i=r(68459),d=r(49619),c=r(42129),u=r(79114),m=r(86957),x=r(95045),h=r(75346),f=r(23348),p=r(67415),g=r(37640),b=r(33442),v=r(34075),j=r(66109),w=r(99161),k=r(83448),y=r(20832),N=r(59461),C=r(92689),S=r(32456),M=r(7578),L=r(4768);let E=(e,t)=>e.bot===t.name||e.cwd===t.path||e.cwd.startsWith(t.path+"/");function P({isOpen:e,onClose:t,onOpenSession:r}){let{t:l}=(0,u.Bd)(),[i,d]=(0,s.useState)([]),[c,w]=(0,s.useState)(!1),[y,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(""),[M,L]=(0,s.useState)(null),[E,B]=(0,s.useState)("files"),[D,A]=(0,s.useState)(null),[W,z]=(0,s.useState)([]),[O,_]=(0,s.useState)([]),q=(0,s.useCallback)(async()=>{w(!0);let[e,t]=await Promise.all([m.t4.runPromiseExit((0,f.jm)()),m.t4.runPromiseExit((0,p.VU)())]);"Success"===e._tag?d(e.value):(0,v.oR)((0,g.oh)(e.cause,l("bots.loadFailed")),"error"),"Success"===t._tag?_(t.value):(0,v.oR)((0,g.oh)(t.cause,l("bots.loadFailed")),"error"),w(!1)},[l]);(0,s.useEffect)(()=>{if(!e){L(null),A(null);return}q(),m.t4.runPromiseExit((0,k.z2)()).then(e=>{"Success"===e._tag&&z(e.value)})},[e,q]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&(y?N(!1):t())};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[y,e,t]);let V=(0,s.useMemo)(()=>{let e=C.trim().toLowerCase();return e?i.filter(t=>{let r=t.valid?t.description:t.error;return`${t.name}
2
+ ${r}
3
+ ${t.path}`.toLowerCase().includes(e)}):i},[i,C]),U=(0,s.useMemo)(()=>{let e=(e,t)=>e.name.localeCompare(t.name);return[{key:"mine",labelKey:"bots.mine",items:V.filter(e=>!e.builtin).slice().sort(e)},{key:"builtin",labelKey:"bots.builtin",items:V.filter(e=>e.builtin).slice().sort(e)}].filter(e=>e.items.length>0)},[V]),K=(0,s.useMemo)(()=>{let e=C.trim().toLowerCase(),t=[...O].sort((e,t)=>(e.name??e.title).localeCompare(t.name??t.title));return e?t.filter(t=>`${t.title}
4
+ ${t.cwd}`.toLowerCase().includes(e)):t},[O,C]),Q=(0,s.useMemo)(()=>[...U.flatMap(e=>e.items.map(e=>e.id)),...K.map(T)],[U,K]),G=M?i.find(e=>e.id===M)??null:null,J=M?O.find(e=>T(e)===M)??null:null;(0,s.useEffect)(()=>{!e||G||J||L(Q[0]??null)},[e,G,J,Q]);let Y=(0,s.useMemo)(()=>i.filter(e=>!e.builtin).length+O.length,[i,O]),X=C.trim().length>0,Z=(0,s.useCallback)(async e=>{let t=await m.t4.runPromiseExit((0,p.i2)(e.cwd,e.sessionId));"Success"===t._tag?(_(t=>t.filter(t=>T(t)!==T(e))),(0,b._)(),(0,v.oR)(l("bots.removed"),"success")):(0,v.oR)((0,g.oh)(t.cause,l("bots.removeFailed")),"error")},[l]),ee=(0,s.useCallback)(async e=>{let t=await m.t4.runPromiseExit((0,f.Eo)(e));"Success"===t._tag?(d(t=>t.filter(t=>t.id!==e)),(0,b._)(),(0,v.oR)(l("bots.removed"),"success")):(0,v.oR)((0,g.oh)(t.cause,l("bots.removeFailed")),"error")},[l]),et=(0,s.useCallback)(e=>{(0,x.F)(h.n.OpenProject,{cwd:e,file:"BOT.md"}),t()},[t]),er=(0,s.useCallback)(()=>N(!0),[]),en=(0,s.useCallback)(()=>N(!1),[]),es=(0,s.useCallback)(async()=>{N(!1),await q()},[q]);return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:j.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:l("bots.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{value:C,onChange:e=>S(e.target.value),placeholder:l("bots.search"),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("button",{onClick:er,className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border hover:bg-hover",children:[(0,n.jsx)(o.A,{className:"w-4 h-4"}),l("bots.addExisting")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground",children:(0,n.jsx)(a.A,{className:"w-5 h-5"})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsx)("div",{className:"w-full md:w-[300px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:c&&0===i.length?(0,n.jsx)("p",{className:"text-center text-sm text-muted-foreground py-8",children:l("common.loading")}):(0,n.jsxs)("div",{className:"p-3 space-y-3",children:[U.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center",children:[(0,n.jsx)("span",{children:l(e.labelKey)}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(e=>(0,n.jsx)(I,{bot:e,selected:e.id===M,onSelect:L},e.id))})]},e.key)),K.length>0&&(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center",children:[(0,n.jsx)("span",{"data-tooltip":l("bots.sessionGroupHint"),children:l("bots.sessionGroup")}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:K.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:K.map(e=>(0,n.jsx)($,{bot:e,selected:T(e)===M,onSelect:L},T(e)))})]}),0===Q.length&&X&&(0,n.jsx)("p",{className:"text-center text-xs text-muted-foreground py-6",children:l("bots.emptyNoMatch")}),!X&&0===Y&&(0,n.jsxs)("div",{className:"text-center text-muted-foreground py-4 text-xs space-y-2",children:[(0,n.jsx)("p",{children:l("bots.emptyNoBots")}),(0,n.jsxs)("p",{children:[l("bots.emptyCreatePrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/bot"})," ",l("bots.emptyCreateSuffix")]}),(0,n.jsx)("p",{children:(0,n.jsx)("button",{type:"button",onClick:er,className:"text-brand hover:underline",children:l("bots.emptyAddExisting")})})]})]})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:G?(0,n.jsx)(F,{bot:G,tab:E,onTab:B,sessions:W,confirmingRemove:D===G.id,onAskRemove:()=>A(G.id),onCancelRemove:()=>A(null),onRemove:()=>{A(null),ee(G.id)},onOpenAsProject:()=>et(G.path),onOpenSession:(e,n)=>{r(e,n),t()},onClose:t},G.id):J?(0,n.jsx)(R,{bot:J,confirmingRemove:D===T(J),onAskRemove:()=>A(T(J)),onCancelRemove:()=>A(null),onRemove:()=>{A(null),Z(J)},onOpenSession:()=>{r(J.cwd,J.sessionId),t()}},T(J)):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:l("bots.selectHint")})})]})]}),y&&(0,n.jsx)(H,{onCancel:en,onAdded:es})]}):null}let T=e=>`session:${e.cwd}
5
+ ${e.sessionId}`,$=(0,s.memo)(function({bot:e,selected:t,onSelect:r}){let s,{t:o}=(0,u.Bd)(),a=!e.name||!e.engine;return(0,n.jsxs)("div",{onClick:()=>r(T(e)),className:`rounded-md px-2 py-2 cursor-pointer transition-colors ${t?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(l.A,{className:"w-4 h-4 text-brand flex-shrink-0"}),(0,n.jsx)("span",{className:`font-medium text-xs truncate flex-1 min-w-0 ${a?"text-muted-foreground":"text-foreground"}`,"data-tooltip":e.title,children:e.name?`@${e.name}`:e.title}),a&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:o("bots.invalid")})]}),(0,n.jsx)("p",{className:`text-xs mt-0.5 pl-6 truncate ${a?"text-destructive":"text-muted-foreground"}`,"data-tooltip":e.cwd,children:e.engine?e.name?(s=e.cwd).split(/[\\/]/).filter(Boolean).pop()??s:o("bots.sessionNameInvalid"):o("bots.sessionGone")})]})});function R({bot:e,confirmingRemove:t,onAskRemove:r,onCancelRemove:s,onRemove:o,onOpenSession:a}){let{t:l}=(0,u.Bd)();return(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:e.name?`@${e.name}`:e.title}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:e.name?l("bots.sessionUsage",{name:e.name}):l("bots.sessionNameInvalid")})]}),t?(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:o,className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:l("bots.removeSession")}),(0,n.jsx)("button",{onClick:s,className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:l("common.cancel")})]}):(0,n.jsx)("button",{onClick:r,className:"p-1.5 rounded text-muted-foreground hover:text-destructive hover:bg-red-9/10 flex-shrink-0","data-tooltip":l("bots.removeSession"),"aria-label":l("bots.removeSession"),children:(0,n.jsx)(i.A,{className:"w-4 h-4"})})]}),e.engine?(0,n.jsx)(y.p,{cwd:e.cwd,sessionId:e.sessionId,subtitle:e.title,emptyText:l("bots.noSessions"),onOpenSession:a}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:l("bots.sessionGone")})]})}let I=(0,s.memo)(function({bot:e,selected:t,onSelect:r}){let{t:s}=(0,u.Bd)(),o=e.valid?e.description:e.error;return(0,n.jsxs)("div",{onClick:()=>r(e.id),className:`rounded-md px-2 py-2 cursor-pointer transition-colors ${t?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(d.A,{className:"w-4 h-4 text-brand flex-shrink-0"}),(0,n.jsxs)("span",{className:"font-medium text-xs text-foreground truncate flex-1 min-w-0","data-tooltip":e.path,children:["@",e.name]}),!e.valid&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:s("bots.invalid")})]}),(0,n.jsx)("p",{className:`text-xs mt-0.5 pl-6 truncate ${e.valid?"text-muted-foreground":"text-destructive"}`,"data-tooltip":o||void 0,children:o})]})});function F({bot:e,tab:t,onTab:r,sessions:o,confirmingRemove:a,onAskRemove:l,onCancelRemove:d,onRemove:x,onOpenAsProject:h,onOpenSession:f,onClose:p}){let{t:g}=(0,u.Bd)(),b=function(e,t){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=!1;return m.t4.runPromiseExit((0,k.QW)((0,L.O)(e.path))).then(e=>{t||(n("Success"===e._tag?e.value:[]),a(Date.now()))}),()=>{t=!0}},[e.path]),{rows:(0,s.useMemo)(()=>{let n=new Map(t.map(e=>[B(e.cwd,e.sessionId),e])),s=new Map;for(let t of r??[]){let r=t.sessionId||(t.path.split("/").pop()||"").replace(/\.jsonl$/,""),o=B(e.path,r),a=n.get(o);s.set(o,{cwd:e.path,sessionId:r,title:t.title,time:Math.max(Date.parse(t.modifiedAt)||0,a?.lastActive??0),engine:t.engine,bot:t.bot,status:a?.status,lastMessage:a?.lastUserMessage??t.lastMessages[t.lastMessages.length-1]??t.firstMessages[0]})}for(let r of t){if(!E(r,e))continue;let t=B(r.cwd,r.sessionId);s.has(t)||s.set(t,{cwd:r.cwd,sessionId:r.sessionId,title:r.title||r.sessionId,time:r.lastActive,engine:r.engine,bot:r.bot,status:r.status,lastMessage:r.lastUserMessage})}return[...s.values()].sort((e,t)=>t.time-e.time)},[r,t,e]),loading:null===r,loadedAt:o}}(e,o),v=(e,s)=>(0,n.jsx)("button",{onClick:()=>r(e),className:`px-3 py-1 transition-colors ${t===e?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:s}),j=(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs",children:[v("files",g("bots.tabFiles")),v("sessions",`${g("bots.tabSessions")}${b.rows.length?` ${b.rows.length}`:""}`)]}),(0,n.jsx)("button",{onClick:h,className:"p-1.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover","data-tooltip":g("bots.open"),"aria-label":g("bots.open"),children:(0,n.jsx)(c.A,{className:"w-4 h-4"})}),e.builtin?null:a?(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:x,className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:g("bots.remove")}),(0,n.jsx)("button",{onClick:d,className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:g("common.cancel")})]}):(0,n.jsx)("button",{onClick:l,className:"p-1.5 rounded text-muted-foreground hover:text-destructive hover:bg-red-9/10","data-tooltip":g("bots.remove"),"aria-label":g("bots.remove"),children:(0,n.jsx)(i.A,{className:"w-4 h-4"})})]});return"files"===t?(0,n.jsx)(w.g,{endpoint:"/api/bots/files",id:e.id,entryFile:"BOT.md",title:`@${e.name}`,actions:j,onClose:p}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("h2",{className:"text-sm font-medium text-foreground truncate",children:["@",e.name]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:g("bots.sessionsScope")})]}),j]}),(0,n.jsx)(A,{data:b,onOpenSession:f})]})}let B=(e,t)=>`${e}
6
+ ${t}`,D=[{key:"today",labelKey:"sessions.dateToday"},{key:"yesterday",labelKey:"sessions.dateYesterday"},{key:"last7Days",labelKey:"sessions.dateLast7Days"},{key:"earlier",labelKey:"sessions.dateEarlier"}];function A({data:e,onOpenSession:t}){let{t:r}=(0,u.Bd)(),{rows:o,loading:a,loadedAt:l}=e,[i,d]=(0,s.useState)(null),c=o.find(e=>B(e.cwd,e.sessionId)===i)??o[0]??null,m=(0,s.useMemo)(()=>{let e=new Map;for(let t of o){let r=(0,N.j)(t.time,l),n=e.get(r);n?n.push(t):e.set(r,[t])}return D.map(t=>({...t,items:e.get(t.key)??[]})).filter(e=>e.items.length>0)},[o,l]);return a&&0===o.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:r("common.loading")}):0===o.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:r("bots.noSessions")}):(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsx)("div",{className:"w-72 flex-shrink-0 border-r border-border overflow-y-auto",children:(0,n.jsx)("div",{className:"p-2 space-y-2",children:m.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center",children:[(0,n.jsx)("span",{children:r(e.labelKey)}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(e=>{let s=B(e.cwd,e.sessionId),o=!!c&&B(c.cwd,c.sessionId)===s;return(0,n.jsxs)("div",{onClick:()=>d(s),onDoubleClick:()=>t(e.cwd,e.sessionId),className:`rounded-md px-2 py-2 cursor-pointer transition-colors ${o?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)(C.S,{engine:e.engine}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground truncate flex-1 min-w-0","data-tooltip":e.title,children:e.title}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:(0,S.fw)(r,e.time)}),(0,n.jsx)(M.l,{status:(0,M.S)(e.status),statusLabel:(0,S.Mm)(r,e.status),bot:e.bot})]}),e.lastMessage&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-[22px]","data-tooltip":e.lastMessage,children:e.lastMessage})]},s)})})]},e.key))})}),(0,n.jsx)("div",{className:"flex-1 flex min-w-0",children:c&&(0,n.jsx)(y.p,{cwd:c.cwd,sessionId:c.sessionId,subtitle:c.title,emptyText:r("sessions.noSessionMessages"),onOpenSession:()=>t(c.cwd,c.sessionId)},B(c.cwd,c.sessionId))})]})}function H({onCancel:e,onAdded:t}){let{t:r}=(0,u.Bd)(),[o,a]=(0,s.useState)(""),[l,i]=(0,s.useState)(!1),d=(0,s.useCallback)(async()=>{let e=o.trim();if(!e||l)return;i(!0);let n=await m.t4.runPromiseExit((0,f.zB)(e));if(i(!1),"Success"===n._tag){let{alreadyExists:e}=n.value;(0,v.oR)(r(e?"bots.alreadyAdded":"bots.added"),e?"info":"success"),e||(0,b._)(),t()}else(0,v.oR)((0,g.oh)(n.cause,r("bots.saveFailed")),"error")},[o,l,t,r]);return(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:()=>!l&&e()}),(0,n.jsxs)("div",{className:"relative w-full max-w-md rounded-xl border border-border bg-card p-5 shadow-xl",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-4",children:r("bots.addExisting")}),(0,n.jsx)("input",{autoFocus:!0,value:o,onChange:e=>a(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||d()},placeholder:r("bots.pathPlaceholder"),className:"w-full px-3 py-2 text-sm font-mono border border-border rounded bg-background"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-3",children:r("bots.addHint")}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-5",children:[(0,n.jsx)("button",{disabled:l,onClick:e,className:"px-3 py-1.5 text-xs rounded border border-border",children:r("common.cancel")}),(0,n.jsx)("button",{disabled:l||!o.trim(),onClick:()=>void d(),className:"px-3 py-1.5 text-xs rounded bg-brand text-white disabled:opacity-50",children:l?r("common.loading"):r("common.confirm")})]})]})]})}},2228:(e,t,r)=>{r.d(t,{ProjectItem:()=>p});var n=r(95155),s=r(12115),o=r(79114),a=r(86957),l=r(16147),i=r(68287),d=r(2111),c=r(39872),u=r(53213),m=r(49387);function x({badge:e,onSelect:t}){return(0,n.jsx)("button",{type:"button",onClick:r=>{r.stopPropagation(),t(e.sessionId)},className:"flex flex-shrink-0 items-center justify-center rounded-full transition-transform hover:scale-125",title:e.bot?`@${e.bot}`:e.label,children:(0,n.jsx)(l.w,{wash:(0,i.JQ)(e.status,!1),ring:(0,i.QV)(e.status),bot:e.bot,children:e.label})})}let h=[],f=()=>{};function p({index:e,name:t,cwd:r,isActive:l,collapsed:i,hasUnread:g,isLoading:b,hasDraft:v,sessionBadges:j,onClick:w,onSelectSession:k,onRemove:y,onOpenNote:N}){let{t:C}=(0,o.Bd)(),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),P=(0,s.useCallback)(()=>{a.t4.runPromiseExit((0,u.ue)(r)).then(e=>{"Success"===e._tag&&E(e.value.branch)})},[r]);(0,s.useEffect)(()=>{P()},[P]);let T=(0,s.useCallback)(e=>{e?.type==="watch"&&Array.isArray(e.data)&&e.data.some(e=>"git"===e.type)&&P()},[P]);(0,d.h)({url:`/ws/watch?cwd=${encodeURIComponent(r)}`,onMessage:T});let $=j??h,R=L?i?`${t} \xb7 ${L}`:L:r;return(0,n.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1 rounded-lg cursor-pointer transition-colors relative ${i?"justify-center":""} ${l?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary hover:text-foreground"}`,onClick:w,onMouseEnter:()=>M(!0),onMouseLeave:()=>M(!1),"data-tooltip":R,children:[(0,n.jsxs)("span",{className:"relative flex-shrink-0",children:[(0,n.jsx)(c.B,{number:e+1,status:i?b?"loading":g&&!l?"unread":"normal":"normal",isActive:l}),v&&(0,n.jsx)("span",{className:"absolute -right-1.5 -top-1.5 flex h-3 w-3 items-center justify-center rounded-full bg-secondary text-muted-foreground",title:C("workspace.unsentDraft"),children:(0,n.jsx)(m.A,{className:"h-2 w-2",strokeWidth:2.5})})]}),!i&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:`flex-1 truncate text-sm ${l?"text-brand":""}`,children:t}),S&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[N&&(0,n.jsx)("button",{className:"p-1 rounded hover:bg-hover text-muted-foreground hover:text-foreground transition-colors",onClick:e=>{e.stopPropagation(),N()},title:C("workspace.projectNotes"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsx)("button",{className:"p-1 rounded hover:bg-red-500/20 text-muted-foreground hover:text-red-11 transition-colors",onClick:e=>{e.stopPropagation(),y()},title:C("workspace.closeProject"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),$.length>0&&(0,n.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0",children:$.map(e=>(0,n.jsx)(x,{badge:e,onSelect:k??f},e.sessionId))})]})]})}},2349:(e,t,r)=>{r.d(t,{j:()=>m});var n=r(95155),s=r(12115),o=r(79114),a=r(2111),l=r(34075),i=r(86957),d=r(47650);function c({open:e,anchorRef:t,initialValue:r,onCancel:a,onSave:l}){let{t:i}=(0,o.Bd)(),[u,m]=(0,s.useState)(r),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(e){m(r),h(!1);let e=requestAnimationFrame(()=>{g.current?.focus(),g.current?.select()});return()=>cancelAnimationFrame(e)}p(null)},[e,r]);let v=(0,s.useCallback)(()=>{let e=t.current;if(!e)return;let r=e.getBoundingClientRect(),n=b.current?.offsetHeight??0,s=r.bottom+4;if(n&&s+n>window.innerHeight-8){let e=r.top-4-n;e>=8&&(s=e)}let o=r.left;p({top:s,left:o=Math.max(o=Math.min(o,window.innerWidth-260-8),8)})},[t]);if((0,s.useLayoutEffect)(()=>{if(e)return v(),window.addEventListener("resize",v),window.addEventListener("scroll",v,!0),()=>{window.removeEventListener("resize",v),window.removeEventListener("scroll",v,!0)}},[e,v]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&(e.preventDefault(),a())},n=e=>{let r=e.target;b.current?.contains(r)||t.current?.contains(r)||a()};return window.addEventListener("keydown",r),document.addEventListener("mousedown",n,!0),()=>{window.removeEventListener("keydown",r),document.removeEventListener("mousedown",n,!0)}},[e,a,t]),!e||"u"<typeof document)return null;let j=async()=>{if(!x){h(!0);try{await l(u.trim())}finally{h(!1)}}};return(0,d.createPortal)((0,n.jsxs)("div",{ref:b,style:{top:f?.top??0,left:f?.left??0,width:260,visibility:f?"visible":"hidden"},className:"fixed z-[100] rounded-lg border border-border bg-card p-3 shadow-lv3",children:[(0,n.jsx)("div",{className:"mb-2 text-sm font-medium text-foreground",children:i("shortIdBadge.dialogTitle")}),(0,n.jsx)("input",{ref:g,type:"text",value:u,onChange:e=>m(e.target.value.slice(0,64)),onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||229===e.keyCode||(e.preventDefault(),j())},placeholder:i("shortIdBadge.dialogPlaceholder"),maxLength:64,className:"w-full rounded border border-border bg-background px-2 py-1.5 text-sm outline-none focus:border-brand"}),(0,n.jsxs)("div",{className:"mt-3 flex justify-end gap-2 text-sm",children:[(0,n.jsx)("button",{onClick:a,className:"rounded px-3 py-1 text-muted-foreground hover:bg-hover",disabled:x,children:i("common.cancel")}),(0,n.jsx)("button",{onClick:()=>void j(),className:"rounded bg-brand px-3 py-1 text-white hover:opacity-90 disabled:opacity-50",disabled:x,children:x?"…":i("common.save")})]})]}),document.body)}var u=r(94720);let m=(0,s.memo)(function({shortId:e,type:t,onRegister:r,onUnregister:d,fullId:m,projectCwd:x,tabId:h,registered:f}){let{t:p}=(0,o.Bd)(),[g,b]=(0,s.useState)(!1),v=f??g,[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)(!1),N=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!m||!x||!h)return;let e=!1;return i.t4.runPromiseExit((0,u.MR)(x,h)).then(t=>{if(e||"Success"!==t._tag)return;let r=t.value[m];"string"==typeof r&&w(r)}),()=>{e=!0}},[m,x,h]),(0,a.h)({url:"/ws/global-state",enabled:!!m&&!!x&&!!h,onMessage:e=>{"console-delta"!==e.type||"rename"!==e.op||e.cwd!==x||e.tabId!==h||e.titles&&m&&Object.prototype.hasOwnProperty.call(e.titles,m)&&w(e.titles[m]??"")}});let C=(0,s.useCallback)(async n=>{if(n.stopPropagation(),v)await d(),b(!1),(0,l.oR)(p("toast.disconnected",{id:e}));else{await r(),b(!0);let n=`${"3456"===window.location.port?"cockpit-dev":"cockpit"} ${t} ${e}`;navigator.clipboard.writeText(n),(0,l.oR)(p("toast.copiedCommand",{command:n}))}},[v,e,t,r,d,p]),S=!!(m&&x&&h),M=(0,s.useCallback)(e=>{e.stopPropagation(),S&&y(!0)},[S]),L=(0,s.useCallback)(async e=>{m&&x&&h&&("Success"===(await i.t4.runPromiseExit((0,u.y8)(x,h,m,e)))._tag&&w(e),y(!1))},[m,x,h]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:C,onDoubleClick:e=>e.stopPropagation(),className:"inline-flex items-center gap-1 text-[10px] font-mono leading-none px-1.5 py-0.5 rounded flex-shrink-0 transition-colors bg-muted/60 hover:bg-muted text-muted-foreground",title:v?p("shortIdBadge.clickToDisconnect"):p("shortIdBadge.clickToRegister"),children:[(0,n.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${v?"bg-green-500":"bg-muted-foreground/40"}`}),e]}),S&&(j?(0,n.jsxs)("span",{className:"inline-flex items-center gap-0.5 text-[10px] leading-none flex-shrink-0 text-muted-foreground",title:p("shortIdBadge.titleSet",{title:j})||j,children:[(0,n.jsx)("span",{className:"px-1 py-0.5 rounded bg-muted/40 max-w-[120px] truncate",children:j}),(0,n.jsx)("button",{ref:N,onClick:M,className:"opacity-50 hover:opacity-100 transition-opacity","aria-label":p("shortIdBadge.editTitle"),title:p("shortIdBadge.editTitle"),children:"✎"})]}):(0,n.jsxs)("button",{ref:N,onClick:M,className:"inline-flex items-center gap-0.5 text-[10px] leading-none flex-shrink-0 text-muted-foreground/50 hover:text-muted-foreground italic transition-colors",title:p("shortIdBadge.setTitle"),children:["(",p("shortIdBadge.setTitlePlaceholder"),") ✎"]})),(0,n.jsx)(c,{open:k,anchorRef:N,initialValue:j,onCancel:()=>y(!1),onSave:L})]})})},6856:(e,t,r)=>{r.d(t,{BootstrapScripts:()=>a});var n=r(95155),s=r(12115),o=r(73321);function a({bootScript:e,buildId:t,forceUpdate:r}){let l=(0,s.useRef)(!1);return(0,o.useServerInsertedHTML)(()=>l.current?null:(l.current=!0,(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("script",{id:"cockpit-boot",dangerouslySetInnerHTML:{__html:e}}),(0,n.jsx)("script",{id:"cockpit-build",dangerouslySetInnerHTML:{__html:`window.__COCKPIT_BUILD_ID__=${JSON.stringify(t).replace(/</g,"\\u003c")};window.__COCKPIT_FORCE_UPDATE__=${JSON.stringify(r)};`}})]}))),null}},12786:(e,t,r)=>{r.d(t,{L:()=>s,Mu:()=>o});var n=r(41463);function s(){return!("u"<typeof navigator)&&(/Mac|iPhone|iPad/.test(navigator.platform||"")||navigator.userAgentData?.platform==="macOS")}function o(){return s()?"⌘":"Ctrl+"}n.platform,n.platform,n.platform},13886:(e,t,r)=>{r.d(t,{ProjectSidebar:()=>ep});var n=r(95155),s=r(12115),o=r(79114),a=r(52252),l=r(49619),i=r(2228),d=r(50538),c=r(68287),u=r(75347),m=r(8183),x=r(66109),h=r(86957),f=r(83448),p=r(92689),g=r(7578),b=r(20832),v=r(84444),j=r(32456),w=r(34075);let k=/https:\/\/github\.com\/([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)\/pull\/(\d+)/;var y=r(45720);let N=e=>{let t=e.pr.createdAt?Date.parse(e.pr.createdAt):NaN;return Number.isNaN(t)?e.session.lastActive:t};function C({sessions:e,isLoading:t,error:r,sessionNumbers:a,titleOf:l,onOpenSession:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(""),[m,x]=(0,s.useState)(""),[h,f]=(0,s.useState)(""),[p,g]=(0,s.useState)(null),[v,j]=(0,s.useState)(()=>new Set),w=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=setTimeout(()=>w.current?.focus(),0);return()=>clearTimeout(e)},[]);let y=(0,s.useMemo)(()=>(function(e,t){let r=new Map;for(let t of e)for(let e of t.pullRequests??[]){let n={key:`${e.url}
7
+ ${t.cwd}
8
+ ${t.sessionId}`,session:t,pr:e},s=r.get(e.url);s?s.push(n):r.set(e.url,[n])}let n=[];for(let[e,s]of r){s.sort((e,t)=>N(e)-N(t));let r=s[0];n.push({url:e,repo:r.pr.repo,number:r.pr.number,title:s.find(e=>e.pr.title)?.pr.title??t(r.session),createdAt:N(r),links:s})}return n.sort((e,t)=>t.createdAt-e.createdAt)})(e,l),[e,l]),E=(0,s.useMemo)(()=>[...new Set(y.map(e=>e.repo))].sort(),[y]),P=(0,s.useMemo)(()=>[...new Set(y.flatMap(e=>e.links.map(e=>e.session.engine||"claude")))].sort(),[y]),T=(0,s.useMemo)(()=>{let e=function(e){let t=e.trim();if(!t)return null;let r=function(e){let t=k.exec(e);if(!t)return null;let r=`${t[1]}/${t[2]}`,n=Number(t[3]);return{url:`https://github.com/${r}/pull/${n}`,repo:r,number:n}}(t);if(r)return{number:r.number,repo:r.repo.toLowerCase()};let n=/^(?:([A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)?)#|#)?(\d+)$/.exec(t);return n?{number:Number(n[2]),repo:n[1]?.toLowerCase()}:null}(c),t=c.trim().toLowerCase();return y.filter(r=>{if(m&&r.repo!==m||h&&!r.links.some(e=>(e.session.engine||"claude")===h))return!1;if(!t)return!0;if(e){if(r.number!==e.number)return!1;if(!e.repo)return!0;let t=r.repo.toLowerCase();return e.repo.includes("/")?t===e.repo:t.split("/")[1]===e.repo}return r.title.toLowerCase().includes(t)||r.repo.toLowerCase().includes(t)||r.links.some(e=>l(e.session).toLowerCase().includes(t))})},[y,c,m,h,l]),$=(0,s.useMemo)(()=>T.flatMap(e=>v.has(e.url)?e.links:[e.links[0]]),[T,v]),R=(0,s.useMemo)(()=>{let e=T.find(e=>e.links.some(e=>e.key===p)),t=e?.links.find(e=>e.key===p);return e&&t?{row:e,link:t}:null},[T,p]);(0,s.useEffect)(()=>{R||g($[0]?.key??null)},[R,$]);let I=(0,s.useCallback)(e=>{window.open(e,"_blank","noopener,noreferrer")},[]),F=(0,s.useCallback)(e=>{j(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border flex flex-col",children:[(0,n.jsxs)("div",{className:"p-3 flex-shrink-0 border-b border-border space-y-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:w,type:"text",placeholder:d("sessions.searchPullRequests"),value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),0===$.length)return;let t=$.findIndex(e=>e.key===p),r="ArrowDown"===e.key?Math.min($.length-1,t+1):Math.max(0,t-1);g($[r].key)}else"Enter"===e.key&&R&&!e.nativeEvent.isComposing&&(e.preventDefault(),e.metaKey||e.ctrlKey?I(R.row.url):i(R.link.session))},className:"w-full px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),c&&(0,n.jsx)("button",{onClick:()=>{u(""),w.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:d("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)(L,{className:"flex-1 min-w-0",value:m,allLabel:d("sessions.allRepos"),options:E,onChange:x}),(0,n.jsx)(L,{className:"w-28",value:h,allLabel:d("sessions.allEngines"),options:P,onChange:f})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:(0,n.jsx)("div",{className:"p-2 space-y-2",children:(()=>{if(0===e.length&&t)return(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:d("sessions.loadingSessions")});if(0===e.length&&r)return(0,n.jsx)("div",{className:"text-xs text-red-11 text-center py-6",children:r});if(0===y.length)return(0,n.jsxs)("div",{className:"text-xs text-muted-foreground text-center py-6 space-y-1",children:[(0,n.jsx)("div",{children:d("sessions.noPullRequests")}),(0,n.jsx)("div",{className:"text-foreground-subtle",children:d("sessions.noPullRequestsHint")})]});if(0===T.length)return(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:d("sessions.noMatchingPullRequests")});let s=new Date,o=[];for(let e of T){let t=function(e,t){let r=new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime();return e>=r?"dateToday":e>=r-864e5?"dateYesterday":e>=r-5184e5?"dateLast7Days":"dateEarlier"}(e.createdAt,s),r=o[o.length-1];r?.group===t?r.rows.push(e):o.push({group:t,rows:[e]})}return o.map(({group:e,rows:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"sticky top-0 z-10 bg-card px-3 py-1 text-[11px] font-medium text-muted-foreground",children:d(`sessions.${e}`)}),(0,n.jsx)("div",{className:"space-y-0.5",children:t.map(e=>{var t;let r,o,d;return(0,n.jsx)(S,{row:e,selectedKey:e.links.some(e=>e.key===p)?p:null,isExpanded:v.has(e.url),clock:(t=e.createdAt,r=new Date(t),o=e=>String(e).padStart(2,"0"),d=`${o(r.getHours())}:${o(r.getMinutes())}`,r.toDateString()===s.toDateString()?d:`${o(r.getMonth()+1)}-${o(r.getDate())} ${d}`),sessionNumbers:a,titleOf:l,onSelect:g,onOpenSession:i,onToggleExpanded:F},e.url)})})]},e))})()})})]}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0 flex-col",children:R?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(M,{row:R.row,link:R.link,onOpenSession:i,onOpenPullRequest:I}),(0,n.jsx)("div",{className:"flex-1 min-h-0 flex",children:(0,n.jsx)(b.p,{cwd:R.link.session.cwd,sessionId:R.link.session.sessionId,subtitle:l(R.link.session),emptyText:d("sessions.noSessionMessages"),onOpenSession:()=>i(R.link.session)},`${R.link.session.cwd}
9
+ ${R.link.session.sessionId}`)})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:d("sessions.selectPullRequestHint")})})]})}let S=(0,s.memo)(function({row:e,selectedKey:t,isExpanded:r,clock:s,sessionNumbers:a,titleOf:l,onSelect:i,onOpenSession:d,onToggleExpanded:c}){let u,{t:m}=(0,o.Bd)(),x=e.links[0],h=e=>a[`${e.session.cwd}
10
+ ${e.session.sessionId}`];return(0,n.jsxs)("div",{className:`rounded-md ${t?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{onClick:()=>i(x.key),onDoubleClick:()=>d(x.session),className:`px-3 py-2 rounded-md cursor-pointer transition-colors ${t?"":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground truncate","data-tooltip":e.url,children:[(u=e.repo).split("/").pop()||u,"#",e.number]}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0 tabular-nums",children:s})]}),(0,n.jsx)("div",{className:"text-xs text-foreground truncate mt-0.5","data-tooltip":e.title,children:e.title}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mt-1",children:[(0,n.jsx)(p.S,{engine:x.session.engine,size:"sm"}),(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground truncate","data-tooltip":x.session.cwd,children:(0,j.Qr)(x.session.cwd)}),(0,n.jsx)(g.l,{coordinate:h(x),bot:x.session.bot}),e.links.length>1&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),c(e.url)},className:"ml-auto text-[11px] text-muted-foreground hover:text-foreground flex-shrink-0",children:[r?"▾":"▸"," ",m("sessions.pullRequestSessions",{count:e.links.length})]})]})]}),r&&e.links.length>1&&(0,n.jsx)("div",{className:"pb-1",children:e.links.map((r,s)=>(0,n.jsxs)("div",{onClick:()=>i(r.key),onDoubleClick:()=>d(r.session),className:`flex items-center gap-1.5 ml-6 mr-2 px-2 py-1 rounded text-[11px] cursor-pointer ${r.key===t?"bg-brand/15 text-foreground":"text-muted-foreground hover:bg-hover"}`,children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:s===e.links.length-1?"└":"├"}),(0,n.jsx)("span",{className:"truncate flex-1","data-tooltip":l(r.session),children:l(r.session)}),(0,n.jsx)(g.l,{coordinate:h(r),bot:r.session.bot})]},r.key))})]})});function M({row:e,link:t,onOpenSession:r,onOpenPullRequest:s}){let{t:a}=(0,o.Bd)(),l=(0,y.X)(t.session.engine,t.session.sessionId),i="px-2.5 py-1 text-xs rounded border border-border text-foreground hover:bg-hover transition-colors";return(0,n.jsxs)("div",{className:"px-4 py-2.5 border-b border-border flex-shrink-0 space-y-1.5",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate","data-tooltip":e.title,children:e.title}),(0,n.jsx)("span",{className:"ml-auto flex-shrink-0",children:(0,n.jsx)(p.S,{engine:t.session.engine})})]}),(0,n.jsxs)("div",{className:"text-[11px] text-muted-foreground truncate","data-tooltip":e.url,children:[e.repo,"#",e.number]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:()=>r(t.session),className:i,title:"↩",children:a("scheduledTasks.openSession")}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(l).then(()=>(0,w.oR)(a("sessions.resumeCommandCopied",{command:l})),()=>(0,w.oR)(a("sessions.copyFailed")))},className:i,title:l,children:a("sessions.copyResumeCommand")}),(0,n.jsxs)("button",{onClick:()=>s(e.url),className:i,title:"⌘↩",children:[a("sessions.openPullRequest")," ↗"]})]})]})}function L({value:e,allLabel:t,options:r,onChange:o,className:a=""}){let[l,i]=(0,s.useState)(!1),d=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!l)return;let e=e=>{d.current?.contains(e.target)||i(!1)},t=e=>{"Escape"===e.key&&(e.stopPropagation(),i(!1))};return window.addEventListener("pointerdown",e),window.addEventListener("keydown",t,!0),()=>{window.removeEventListener("pointerdown",e),window.removeEventListener("keydown",t,!0)}},[l]);let c=["",...r];return(0,n.jsxs)("div",{ref:d,className:`relative ${a}`,children:[(0,n.jsxs)("button",{type:"button",onClick:()=>i(e=>!e),"aria-haspopup":"listbox","aria-expanded":l,className:`w-full flex items-center gap-1 px-2 py-1 text-xs rounded border bg-card text-left transition-colors ${l?"border-brand":"border-border hover:border-foreground-subtle"} ${e?"text-foreground":"text-muted-foreground"}`,children:[(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e||t}),(0,n.jsx)("svg",{className:`w-3 h-3 flex-shrink-0 text-foreground-subtle transition-transform ${l?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),l&&(0,n.jsx)("div",{role:"listbox",className:"absolute left-0 top-full mt-1 z-30 min-w-full max-w-[320px] max-h-64 overflow-y-auto bg-card border border-border rounded-lg shadow-lv2 py-1",children:c.map(r=>(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":r===e,onClick:()=>{o(r),i(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-xs text-left whitespace-nowrap hover:bg-hover transition-colors ${r===e?"text-brand":"text-foreground"}`,children:[(0,n.jsx)("span",{className:"w-3 flex-shrink-0",children:r===e?"✓":""}),(0,n.jsx)("span",{className:"truncate","data-tooltip":r||void 0,children:r||t})]},r||"__all__"))})]})}let E=(e,t)=>`${e}
11
+ ${t}`;function P({isOpen:e,onClose:t,onSwitchProject:r,sessionNumbers:a={},projectOrder:l,currentCwd:i,liveSessions:d}){let{t:c}=(0,o.Bd)(),w=(0,u.bc)(),[k,y]=(0,s.useState)([]),[N,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(null),[T,$]=(0,s.useState)(""),R=(0,s.useRef)(null),[I,F]=(0,s.useState)(null),[B,D]=(0,s.useState)("sessions"),A=(0,s.useCallback)(async()=>{S(!0),L(null);let e=await h.t4.runPromiseExit((0,f.z2)());"Success"===e._tag?y([...e.value]):L(c("sessions.loadSessionsFailed")),S(!1)},[c]);(0,s.useEffect)(()=>{e?(A(),setTimeout(()=>{R.current?.focus(),R.current?.select()},100)):(F(null),D("sessions"))},[e,A]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let H=(0,s.useMemo)(()=>{let e=new Map(d.map(e=>[E(e.cwd,e.sessionId),e])),t=k.map(t=>{let r=e.get(E(t.cwd,t.sessionId));return r?(e.delete(E(t.cwd,t.sessionId)),{...t,...r,searchText:r.searchText??t.searchText,pullRequests:r.pullRequests??t.pullRequests}):t});return(0,v.H)([...t,...e.values()])},[k,d]),W=(0,s.useMemo)(()=>{if(!T)return H;let e=T.toLowerCase();return H.filter(t=>!!(0,m.iM)(w,t.cwd,t.sessionId,t.title||t.sessionId,t.titleRevision).toLowerCase().includes(e)||(void 0!==t.searchText?t.searchText.includes(e):t.cwd.toLowerCase().includes(e)||(t.title?.toLowerCase().includes(e)??!1)||(t.lastUserMessage?.toLowerCase().includes(e)??!1)||(t.firstMessages?.some(t=>t.toLowerCase().includes(e))??!1)||(t.lastMessages?.some(t=>t.toLowerCase().includes(e))??!1)))},[H,T,w]),z=(0,s.useMemo)(()=>(0,j.wG)(W),[W]),O=H.filter(e=>"loading"===e.status).length,_=H.filter(e=>"unread"===e.status).length,q=I?H.find(e=>E(e.cwd,e.sessionId)===I)??null:null;(0,s.useEffect)(()=>{if(!e||"sessions"!==B||q)return;let t=W[0];F(t?E(t.cwd,t.sessionId):null)},[e,B,q,W]);let V=(0,s.useCallback)(e=>{r(e.cwd,e.sessionId),t()},[r,t]),U=(0,s.useCallback)(e=>(0,m.iM)(w,e.cwd,e.sessionId,e.title||e.sessionId,e.titleRevision),[w]),K=e=>{let t=E(e.cwd,e.sessionId),r=t===I;return(0,n.jsxs)("div",{onClick:()=>F(t),onDoubleClick:()=>V(e),className:`group/session-title rounded-md px-3 py-2 cursor-pointer transition-colors ${r?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(p.S,{engine:e.engine}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground flex items-center gap-1 flex-1 min-w-0","data-tooltip":U(e),children:(0,n.jsx)(u.dh,{cwd:e.cwd,sessionId:e.sessionId,title:e.title||e.sessionId,titleRevision:e.titleRevision})}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:(0,j.fw)(c,e.lastActive)}),(0,n.jsx)(g.l,{coordinate:a[t],status:(0,g.S)(e.status),statusLabel:(0,j.Mm)(c,e.status),bot:e.bot})]}),e.lastUserMessage&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-[22px]","data-tooltip":e.lastUserMessage,children:e.lastUserMessage})]},t)};return e?(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:x.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:c("sessions.recentSessions")}),(0,n.jsx)("div",{className:"flex items-center gap-0.5 p-0.5 rounded-md bg-muted",role:"tablist",children:["sessions","pullRequests"].map(e=>(0,n.jsx)("button",{role:"tab","aria-selected":B===e,onClick:()=>D(e),className:`px-2.5 py-0.5 text-xs rounded transition-colors ${B===e?"bg-card text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,children:c("sessions"===e?"sessions.sessionsTab":"sessions.pullRequestsTab")},e))}),O>0&&(0,n.jsx)("span",{className:"text-xs text-orange-11",children:c("sessions.runningCount",{count:O})}),_>0&&(0,n.jsx)("span",{className:"text-xs text-orange-11",children:c("sessions.unreadCount",{count:_})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 flex min-h-0",children:"pullRequests"===B?(0,n.jsx)(C,{sessions:H,isLoading:N,error:M,sessionNumbers:a,titleOf:U,onOpenSession:V}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border flex flex-col",children:[(0,n.jsx)("div",{className:"p-3 flex-shrink-0 border-b border-border",children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:R,type:"text",placeholder:c("sessions.searchSessions"),value:T,onChange:e=>$(e.target.value),className:"w-full px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),T&&(0,n.jsx)("button",{onClick:()=>{$(""),R.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:c("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:(0,n.jsx)("div",{className:"p-3 space-y-3",children:0===H.length&&N?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:c("sessions.loadingSessions")}):0===H.length&&M?(0,n.jsx)("div",{className:"text-xs text-red-11 text-center py-6",children:M}):0===W.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-6",children:T?c("sessions.noMatchingSessions"):c("sessions.noSessions")}):z.map(e=>{let t=e.items.filter(e=>"loading"===e.status).length,r=e.items.filter(e=>"unread"===e.status).length;return(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)(j.wX,{cwd:e.cwd,projectOrder:l,currentCwd:i,children:[r>0&&(0,n.jsxs)("span",{className:"text-orange-11",children:["\xb7 ",c("sessions.unreadCount",{count:r})]}),t>0&&(0,n.jsxs)("span",{className:"text-orange-11",children:["\xb7 ",c("sessions.runningCount",{count:t})]}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(K)})]},e.cwd)})})})]}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:q?(0,n.jsx)(b.p,{cwd:q.cwd,sessionId:q.sessionId,subtitle:U(q),emptyText:c("sessions.noSessionMessages"),onOpenSession:()=>V(q)},E(q.cwd,q.sessionId)):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:c("sessions.selectSessionHint")})})]})})]})]}):null}function T({projectOrder:e,currentCwd:t,onSwitchProject:r,onResolveSessionNumbers:a,collapsed:l,sessions:i}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)({}),p=(0,s.useRef)(0),g=(0,s.useCallback)(()=>{x(!0);let e=++p.current;f({}),a().then(t=>{p.current===e&&f(t)})},[a]),b=(0,s.useCallback)(()=>{x(!1),p.current+=1},[]),v=i.filter(e=>"loading"===e.status).length,j=i.filter(e=>"unread"===e.status).length;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:g,className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${l?"w-full justify-center":"w-full"}`,title:l?u("sessions.recentSessions"):void 0,children:[(0,n.jsx)(d.A,{className:"w-5 h-5 flex-shrink-0"}),!l&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:u("sessions.recentSessions")}),v>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-xs font-medium rounded-full flex items-center justify-center ${(0,c.ci)("loading",!1)} ${l?"absolute -top-1 -right-1":""}`,children:v}),j>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 bg-orange-11/15 text-orange-11 text-xs font-medium rounded-full flex items-center justify-center ${l&&!v?"absolute -top-1 -right-1":""}`,children:j})]}),(0,n.jsx)(P,{isOpen:m,onClose:b,onSwitchProject:r,sessionNumbers:h,projectOrder:e,currentCwd:t,liveSessions:i})]})}let $=(e,t)=>e<t.top+t.height/2?"before":"after";var R=r(49433);let I=(e,t)=>`${e}
12
+ ${t}`;function F({collapsed:e,pinnedSessions:t,sessionNumbers:r,projectOrder:a,currentCwd:l,onSwitchProject:i,onUnpin:d,onReorder:c}){let{t:v}=(0,o.Bd)(),w=(0,u.bc)(),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),S=N?t.find(e=>e.sessionId===N)??null:null,M=(0,s.useMemo)(()=>(0,j.wG)(t),[t]),[L,E]=(0,s.useState)(null),[P,T]=(0,s.useState)(null),[B,D]=(0,s.useState)({});(0,s.useEffect)(()=>{k&&h.t4.runPromise((0,f.z2)().pipe(R.YWq({onSuccess:e=>D(Object.fromEntries(e.map(e=>[I(e.cwd,e.sessionId),e]))),onFailure:()=>{}})))},[k]),(0,s.useEffect)(()=>{k&&!S&&C(t[0]?.sessionId??null)},[k,S,t]);let A=(0,s.useCallback)(()=>{y(!1),C(null),E(null),T(null)},[]);(0,s.useEffect)(()=>{if(!k)return;let e=e=>{"Escape"===e.key&&A()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[k,A]);let H=(0,s.useCallback)(e=>{i(e.cwd,e.sessionId),A()},[i,A]),W=(0,s.useCallback)((e,t)=>{e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.sessionId);let r=e.currentTarget.parentElement;r&&e.dataTransfer.setDragImage(r,16,r.clientHeight/2),E(t),T(null)},[]),z=(0,s.useCallback)((e,t)=>{if(!L||t.cwd!==L.cwd||(e.preventDefault(),e.dataTransfer.dropEffect="move",t.sessionId===L.sessionId))return void T(null);let r=e.currentTarget.getBoundingClientRect(),n=$(e.clientY,r);T(e=>e?.sessionId===t.sessionId&&e.cwd===t.cwd&&e.side===n?e:{cwd:t.cwd,sessionId:t.sessionId,side:n})},[L]),O=(0,s.useCallback)(()=>{E(null),T(null)},[]),_=(0,s.useCallback)((e,r)=>{if(e.preventDefault(),e.stopPropagation(),!L||r.cwd!==L.cwd||r.sessionId===L.sessionId)return void O();let n=$(e.clientY,e.currentTarget.getBoundingClientRect()),s=M.flatMap(e=>e.cwd!==r.cwd?e.items:function(e,t,r,n){let s=e.find(e=>e.sessionId===t);if(!s||t===r||!e.some(e=>e.sessionId===r))return[...e];let o=e.filter(e=>e.sessionId!==t),a=o.findIndex(e=>e.sessionId===r);return o.splice(a+ +("after"===n),0,s),o}(e.items,L.sessionId,r.sessionId,n));s.some((e,r)=>e!==t[r])&&c(s),O()},[L,M,t,c,O]),q=e=>(0,m.iM)(w,e.cwd,e.sessionId,e.title||B[I(e.cwd,e.sessionId)]?.title||e.sessionId),V=e=>{let t=B[I(e.cwd,e.sessionId)],s=e.sessionId===N,o=L?.cwd===e.cwd&&L.sessionId===e.sessionId,a=P?.cwd===e.cwd&&P.sessionId===e.sessionId?P.side:null;return(0,n.jsxs)("div",{onDragOver:t=>z(t,e),onDrop:t=>_(t,e),onDragLeave:t=>{t.relatedTarget instanceof Node&&t.currentTarget.contains(t.relatedTarget)||T(t=>t?.cwd===e.cwd&&t.sessionId===e.sessionId?null:t)},onDragEnd:O,onClick:()=>C(e.sessionId),onDoubleClick:()=>H(e),className:`group relative rounded-md px-2 py-2 cursor-pointer transition-colors flex items-start gap-1.5 ${s?"bg-brand/10":"hover:bg-hover"} ${o?"opacity-35":""}`,children:[a&&(0,n.jsx)("div",{"aria-hidden":"true",className:`pointer-events-none absolute left-1 right-1 z-10 h-0.5 rounded-full bg-brand ${"before"===a?"-top-px":"-bottom-px"}`,children:(0,n.jsx)("span",{className:"absolute -left-0.5 -top-0.5 h-1.5 w-1.5 rounded-full bg-brand"})}),(0,n.jsx)("span",{draggable:!0,onDragStart:t=>W(t,e),onClick:e=>e.stopPropagation(),title:v("sessions.dragToReorder"),className:`mt-1 text-muted-foreground/30 hover:text-foreground flex-shrink-0 select-none ${L?"cursor-grabbing":"cursor-grab"}`,children:(0,n.jsxs)("svg",{className:"w-3 h-3",viewBox:"0 0 10 16",fill:"currentColor",children:[(0,n.jsx)("circle",{cx:"3",cy:"2",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"2",r:"1.5"}),(0,n.jsx)("circle",{cx:"3",cy:"8",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"8",r:"1.5"}),(0,n.jsx)("circle",{cx:"3",cy:"14",r:"1.5"}),(0,n.jsx)("circle",{cx:"7",cy:"14",r:"1.5"})]})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)(p.S,{engine:t?.engine}),(0,n.jsx)("span",{className:"flex items-center gap-1 text-xs font-medium text-foreground flex-1 min-w-0",children:(0,n.jsx)(u.dh,{cwd:e.cwd,sessionId:e.sessionId,title:q(e),editable:!1})}),t?.lastActive?(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0 group-hover:hidden",children:(0,j.fw)(v,t.lastActive)}):null,(0,n.jsx)(g.l,{coordinate:r?.[I(e.cwd,e.sessionId)],status:(0,g.S)(t?.status),statusLabel:(0,j.Mm)(v,t?.status),bot:t?.bot}),(0,n.jsx)("div",{className:"flex-shrink-0 hidden group-hover:flex items-center gap-0.5",children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),d(e.sessionId)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:v("sessions.removeFavorite"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]}),t?.lastUserMessage&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-[22px]","data-tooltip":t.lastUserMessage,children:t.lastUserMessage})]})]},e.sessionId)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>y(!0),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${e?"w-full justify-center":"w-full"}`,title:e?v("sessions.favorites"):void 0,children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"})}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:v("sessions.favorites")}),e&&t.length>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-popover border border-border",children:t.length})]}),k&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:A}),(0,n.jsxs)("div",{className:x.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:v("sessions.favorites")}),t.length>0&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.length})]}),(0,n.jsx)("button",{onClick:A,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 flex min-h-0",children:0===t.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:v("sessions.noFavorites")})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:(0,n.jsx)("div",{className:"p-3 space-y-3",children:M.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsx)(j.wX,{cwd:e.cwd,projectOrder:a,currentCwd:l,children:(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(V)})]},e.cwd))})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:S?(0,n.jsx)(b.p,{cwd:S.cwd,sessionId:S.sessionId,subtitle:q(S),emptyText:v("sessions.noSessionMessages"),onOpenSession:()=>H(S)},I(S.cwd,S.sessionId)):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:v("sessions.selectFavoriteHint")})})]})})]})]})]})}var B=r(80860),D=r(23121),A=r(96625),H=r(20235),W=r(93777),z=r(95686);function O({task:e,onOpenSession:t}){let{t:r}=(0,o.Bd)();return(0,n.jsx)(b.p,{cwd:e.cwd,sessionId:e.sessionId,subtitle:(0,D.Q_)(e),emptyText:r("scheduledTasks.noTaskMessages"),onOpenSession:t})}var _=r(15317);function q(e){return e.engine||"claude"}function V(e){return!!e.completed&&!e.firingSince}function U(e){return e.lastFiredAt??e.createdAt}let K=e=>!!e.unread||V(e);function Q({collapsed:e,tasks:t,unreadCount:r,sessionNumbers:a,projectOrder:l,currentCwd:i,onSwitchProject:d,onPause:c,onResume:u,onTrigger:m,onDelete:b,onUpdateTask:v}){let{t:k}=(0,o.Bd)(),[y,N]=(0,s.useState)(!1),{matchLine:C}=(0,A.WB)(),[S,M]=(0,s.useState)(null),L=(0,s.useRef)(null),E=(0,s.useRef)(null),[P,T]=(0,s.useState)(null),$=(0,s.useCallback)(()=>{M(null),L.current=null,T(null)},[]),[R,I]=(0,s.useState)(null),[F,G]=(0,s.useState)(null),[J,Y]=(0,s.useState)(null),[X,Z]=(0,s.useState)(null),ee=t.filter(e=>!V(e)),et=ee.filter(e=>!e.paused).length,er=(0,s.useMemo)(()=>(0,j.wG)(function(e){let t=[],r=[],n=[];for(let s of e)s.unread||V(s)?t.push(s):s.paused?n.push(s):r.push(s);return t.sort((e,t)=>Number(!!t.unread)-Number(!!e.unread)||U(t)-U(e)),r.sort((e,t)=>(e.nextFireTime||Number.MAX_SAFE_INTEGER)-(t.nextFireTime||Number.MAX_SAFE_INTEGER)),n.sort((e,t)=>U(t)-U(e)),[...t,...r,...n]}(t)),[t]),en=J?t.find(e=>e.id===J)??null:null;(0,s.useEffect)(()=>{if(!y||en)return;let e=er[0]?.items[0];Y(e?.id??null)},[y,en,er]);let[,es]=(0,s.useState)(0);(0,s.useEffect)(()=>{if(!y)return;let e=setInterval(()=>es(e=>e+1),1e4);return()=>clearInterval(e)},[y]),(0,s.useEffect)(()=>{if(!R)return;let e=!1;return G(null),h.t4.runPromiseExit((0,f.an)(R)).then(t=>{e||("Success"===t._tag&&void 0!==t.value.content?G(t.value.content):((0,w.oR)(k("toast.readFileFailed"),"error"),I(null)))}),()=>{e=!0}},[R,k]);let eo=(0,s.useCallback)(()=>{I(null),G(null)},[]),ea=(0,s.useCallback)(async e=>{let t=!!e.taskFile;try{await navigator.clipboard.writeText(t?e.taskFile:e.message),(0,w.oR)(k(t?"common.copiedPath":"toast.copiedMessage"),"success")}catch{(0,w.oR)(k("common.copyFailed"),"error")}},[k]),el=(0,s.useCallback)(()=>{N(!1),Y(null)},[]);(0,s.useEffect)(()=>{if(!y)return;let e=e=>{if("Escape"===e.key){if(R)return void eo();if(S)return void $();el()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[y,S,R,eo,el,$]),(0,s.useLayoutEffect)(()=>{if(!S)return;let e=()=>{let e=L.current,t=E.current;if(!e||!t)return;let r=e.getBoundingClientRect();if(!r.width&&!r.height)return;let{width:n,height:s}=t.getBoundingClientRect(),o=r.right+8;if(o+n>window.innerWidth-8){let e=r.left-n-8;o=e>=8?e:Math.max(8,window.innerWidth-n-8)}let a=Math.max(8,Math.min(r.top,window.innerHeight-s-8));T(e=>e&&e.top===a&&e.left===o?e:{top:a,left:o})};e();let t=new ResizeObserver(e);return E.current&&t.observe(E.current),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{t.disconnect(),window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[S]);let ei=(0,s.useCallback)(e=>{d(e.cwd,e.sessionId),el()},[d,el]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:()=>N(!0),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${e?"w-full justify-center":"w-full"}`,title:e?k("scheduledTasks.title"):void 0,children:[(0,n.jsx)(B.A,{className:"w-5 h-5 flex-shrink-0"}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:k("scheduledTasks.title")}),r>0?(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 bg-orange-11/15 text-orange-11 text-xs font-medium rounded-full flex items-center justify-center ${e?"absolute -top-1 -right-1":""}`,children:r}):e&&t.length>0?(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-popover border border-border",children:t.length}):null]}),y&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:el}),(0,n.jsxs)("div",{className:x.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:k("scheduledTasks.title")}),ee.length>0&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[k("scheduledTasks.activeCount",{running:et}),ee.length-et>0?` \xb7 ${k("scheduledTasks.pausedCount",{paused:ee.length-et})}`:""]})]}),(0,n.jsx)("button",{onClick:el,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 flex min-h-0",children:0===t.length?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:k("scheduledTasks.noScheduledTasks")})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:(0,n.jsx)("div",{className:"p-3 space-y-3",children:er.map(e=>{let t=e.items.filter(K).length;return(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)(j.wX,{cwd:e.cwd,projectOrder:l,currentCwd:i,children:[t>0&&(0,n.jsxs)("span",{className:"text-orange-11",children:["\xb7 ",k("scheduledTasks.pendingCount",{count:t})]}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(e=>{let t,r;return t=e.id===J,(0,n.jsxs)("div",{onClick:()=>Y(e.id),onMouseLeave:()=>Z(t=>t===e.id?null:t),className:`group rounded-md px-3 py-2 cursor-pointer transition-colors ${t?"bg-brand/10":e.unread?"bg-brand/5 hover:bg-hover":"hover:bg-hover"} ${V(e)?"opacity-70":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)(p.S,{engine:q(e),tooltip:(r=q(e),e.model?`${r} \xb7 ${e.model}`:r)}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-1 min-w-0 truncate",children:e.firingSince?k("scheduledTasks.inFlight"):V(e)?k("scheduledTasks.completed"):e.paused?k("scheduledTasks.paused"):k("common.running")}),(0,n.jsx)(g.l,{coordinate:a?.[`${e.cwd}
13
+ ${e.sessionId}`]}),X===e.id?(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),Z(null),b(e.id)},className:"px-2 py-0.5 text-[10px] rounded bg-red-9 text-white hover:bg-red-10",children:k("common.confirm")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),Z(null)},className:"px-2 py-0.5 text-[10px] rounded border border-border text-muted-foreground hover:text-foreground",children:k("common.cancel")})]}):(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.taskFile&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),I(e.taskFile)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:k("common.preview"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ea(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:k(e.taskFile?"common.copyPath":"common.copy"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),m(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-brand",title:k("scheduledTasks.runNow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{d:"M8 5v14l11-7z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),L.current=t.currentTarget,M(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:k("common.edit"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),V(e)?null:e.paused?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),u(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-green-11",title:k("scheduledTasks.resume"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"})})}):(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),c(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-amber-11",title:k("scheduledTasks.pause"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 9v6m4-6v6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),Z(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:k("common.delete"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{className:"text-xs text-foreground line-clamp-3 mb-1 whitespace-pre-wrap break-words","data-tooltip":(0,D.Q_)(e),children:(0,n.jsx)(H.zl,{text:(0,D.Q_)(e),matchLine:C,variant:"chip"})}),(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"truncate",children:function(e,t){if("once"===e.type)return t("scheduledTasks.onceType",{duration:(0,_.dp)(e.delayMinutes??0,t)});if("interval"===e.type){var r;let n,s,o,a=t("scheduledTasks.everyDuration",{duration:(0,_.dp)(e.intervalMinutes??0,t)});return(e.startAt&&(a+=` \xb7 ${t("scheduledTasks.fromTime",{time:(n=new Date(r=e.startAt),s=e=>String(e).padStart(2,"0"),o=`${s(n.getHours())}:${s(n.getMinutes())}`,r>Date.now()?`${n.getMonth()+1}/${n.getDate()} ${o}`:o)})}`),e.activeFrom&&e.activeTo)?`${a} (${e.activeFrom}-${e.activeTo})`:a}return"cron"===e.type?e.cron||"cron":e.type}(e,k)}),(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsx)("span",{className:"flex-shrink-0",children:e.firingSince?k("scheduledTasks.inFlight"):V(e)?"success"===e.lastResult?k("scheduledTasks.success"):"interrupted"===e.lastResult?k("scheduledTasks.interrupted"):k("scheduledTasks.failure"):e.paused?k("scheduledTasks.paused"):function(e,t){if(!e)return"-";let r=e-Date.now();if(r<=0)return t("scheduledTasks.aboutToTrigger");if(r<6e4)return t("scheduledTasks.secondsLater",{count:Math.ceil(r/1e3)});if(r<36e5)return t("scheduledTasks.minutesLater",{count:Math.ceil(r/6e4)});if(r<864e5){let e=Math.floor(r/36e5),n=Math.ceil(r%36e5/6e4);return n>0?t("scheduledTasks.hoursMinutesLater",{h:e,m:n}):t("scheduledTasks.hoursLater",{h:e})}return new Date(e).toLocaleDateString("zh-CN",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(e.nextFireTime,k)}),!V(e)&&!e.firingSince&&e.lastFiredAt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsxs)("span",{className:"flex-shrink-0",children:[k("scheduledTasks.lastResult"),":"," ","success"===e.lastResult?"✓":"interrupted"===e.lastResult?k("scheduledTasks.interrupted"):"✗"]})]})]})]},e.id)})})]},e.cwd)})})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:en?(0,n.jsx)(O,{task:en,onOpenSession:()=>ei(en)},en.id):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:k("scheduledTasks.selectTaskHint")})})]})})]})]}),R&&null!==F&&(0,n.jsx)(z.x,{filePath:R,content:F,cwd:R.slice(0,Math.max(0,R.lastIndexOf("/"))),onClose:eo,zClassName:"z-[80]"}),S&&(0,n.jsx)("div",{ref:E,className:"fixed z-[100]",style:{top:P?.top??0,left:P?.left??0,visibility:P?"visible":"hidden"},children:(0,n.jsx)(W.E,{onClose:$,onCreate:()=>{},editTask:{id:S.id,message:S.message,taskFile:S.taskFile,type:S.type,delayMinutes:S.delayMinutes,intervalMinutes:S.intervalMinutes,activeFrom:S.activeFrom,activeTo:S.activeTo,startAt:S.startAt,cron:S.cron},onUpdate:(e,t)=>{v(e,t),$()}})})]})}var G=r(42804),J=r(997),Y=r(33210),X=r(39872),Z=r(2111),ee=r(94720),et=r(2349),er=r(96901),en=r(71077);function es({terminal:e,subtitle:t,onOpenTerminal:r}){let{t:a}=(0,o.Bd)(),{projectCwd:l,commandId:i,usePty:d}=e,c=(0,s.useRef)(null),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(void 0),f=(0,s.useRef)(d?[]:null),p=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=!0,t=(0,en.d$)({projectCwd:l,commandId:i,onAttached:e=>{let t;e?h(e):(t=f.current,f.current=null,t?.length&&c.current?.write(t.join("")))},onOutput:t=>{if(d)return void(f.current?f.current.push(t):c.current?.write(t));let r=t.replace(/\r?\n/g,"\r\n");e&&r&&!r.endsWith("\n")&&(r+="\r\n"),e=!1,c.current?.write(r)},onEnd:()=>m(!0)});return p.current=t.sendInput,()=>{p.current=null,t.close()}},[l,i,d]),(0,s.useEffect)(()=>{if(!x||!f.current)return;let e=f.current;f.current=null,e.length&&c.current?.write(e.join(""))},[x]);let g=(0,s.useCallback)(e=>p.current?.(e),[]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:`text-xs font-medium text-foreground truncate${e.title?"":" font-mono"}`,"data-tooltip":e.command,"data-tooltip-mono":!0,children:e.title||e.command.split("\n")[0]}),(0,n.jsx)("div",{className:"text-[11px] text-muted-foreground font-mono truncate","data-tooltip":e.cwd,children:t})]}),u?(0,n.jsx)("span",{className:"flex-shrink-0 text-xs text-muted-foreground",children:a("runningTerminals.ended")}):d?(0,n.jsx)("span",{className:"flex-shrink-0 text-[11px] text-foreground-subtle",children:a("runningTerminals.typeHint")}):null]}),(0,n.jsxs)("div",{className:"relative flex-1 min-h-0",children:[(0,n.jsx)("div",{className:"h-full pt-2 pb-16",children:(0,n.jsx)(er.XtermRenderer,{ref:c,output:"",isRunning:!1,directWrite:!0,fixedSize:d?x:void 0,onInput:d&&!u?g:void 0})}),(0,n.jsx)("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex justify-center pb-4",children:(0,n.jsxs)("button",{onClick:r,className:"pointer-events-auto flex items-center gap-1.5 px-5 py-2.5 rounded-full bg-brand text-white text-sm font-medium shadow-lv3 hover:bg-brand/90",children:[(0,n.jsx)("span",{children:a("runningTerminals.openTerminal")}),(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14 5l7 7-7 7M3 12h18"})})]})})]})]})}function eo(e){return e.split(/[\\/]/).filter(Boolean).pop()||e}function ea(e){var t,r;let n=(t=e.cwd,r=e.projectCwd,t&&t!==r?t.startsWith(r+"/")?t.slice(r.length+1):t:"");return[e.title?e.command.split("\n")[0]:"",n].filter(Boolean).join(" \xb7 ")}function el({collapsed:e,currentCwd:t,projectOrder:r,onFocusTerminal:a}){let{t:l}=(0,o.Bd)(),{terminals:i,refresh:d}=function(){let[e,t]=(0,s.useState)([]),r=(0,s.useRef)(null),n=(0,s.useCallback)(()=>{h.t4.runPromiseExit((0,ee.D5)()).then(e=>{"Success"===e._tag&&t(e.value)})},[]),o=(0,s.useCallback)(()=>{r.current&&clearTimeout(r.current),r.current=setTimeout(()=>{r.current=null,n()},150)},[n]);return(0,s.useEffect)(()=>(n(),()=>{r.current&&clearTimeout(r.current)}),[n]),(0,Z.h)({url:"/ws/global-state",onMessage:e=>{("running-terminals-changed"===e.type||"console-delta"===e.type&&"rename"===e.op)&&o()}}),{terminals:e,refresh:n}}(),[c,u]=(0,s.useState)(!1),[m,f]=(0,s.useState)(()=>Date.now()),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(null),[j,k]=(0,s.useState)(()=>new Set),y=(0,s.useRef)(new Map),N=(0,s.useMemo)(()=>{let e=new Map;for(let t of i){let r=e.get(t.projectCwd);r?r.push(t):e.set(t.projectCwd,[t])}let n=e=>{if(e===t)return -1;let n=r.indexOf(e);return n>=0?n:Number.MAX_SAFE_INTEGER};return[...e.entries()].sort(([e],[t])=>n(e)-n(t)||e.localeCompare(t)).map(([e,t])=>({cwd:e,number:r.indexOf(e)+1,items:[...t].sort((e,t)=>e.timestamp.localeCompare(t.timestamp))}))},[i,t,r]),C=(0,s.useMemo)(()=>N.flatMap(e=>e.items),[N]),S=(0,s.useCallback)(()=>{u(!1),v(null),g(null)},[]),M=p?C.find(e=>e.commandId===p)??null:null;(0,s.useEffect)(()=>{c&&!M&&g(C[0]?.commandId??null)},[c,M,C]);let L=(0,s.useCallback)(()=>{d(),f(Date.now()),u(!0)},[d]);(0,s.useEffect)(()=>{if(!c)return;let e=setInterval(()=>f(Date.now()),1e3);return()=>clearInterval(e)},[c]),(0,s.useEffect)(()=>{let e=new Set(i.map(e=>e.commandId));for(let[t,r]of(k(t=>{let r=new Set([...t].filter(t=>e.has(t)));return r.size===t.size?t:r}),y.current))e.has(t)||(clearTimeout(r),y.current.delete(t))},[i]),(0,s.useEffect)(()=>{let e=y.current;return()=>{for(let t of e.values())clearTimeout(t)}},[]);let E=(0,s.useCallback)(e=>{S(),a(e.projectCwd,e.commandId)},[S,a]),P=(0,s.useCallback)(e=>{v(null),k(t=>new Set(t).add(e.commandId));let t=()=>{y.current.delete(e.commandId),k(t=>{let r=new Set(t);return r.delete(e.commandId),r}),(0,w.oR)(l("runningTerminals.stopFailed"),"error")};h.t4.runPromiseExit((0,ee.px)(e.commandId)).then(r=>{"Success"!==r._tag?t():r.value.interrupted?y.current.set(e.commandId,setTimeout(t,3e3)):d()})},[d,l]);(0,s.useEffect)(()=>{if(!c)return;let e=e=>{let t=!!e.target?.closest?.(".xterm");if("Escape"===e.key&&!t){e.preventDefault(),b?v(null):S();return}if(t||0===C.length)return;let r=C.findIndex(e=>e.commandId===p);if("ArrowDown"===e.key||"ArrowUp"===e.key){e.preventDefault();let t="ArrowDown"===e.key?1:-1,n=r<0?t>0?0:C.length-1:(r+t+C.length)%C.length;g(C[n].commandId),v(null);return}let n=r>=0?C[r]:null;n&&("Enter"===e.key?(e.preventDefault(),b===n.commandId?P(n):E(n)):("Delete"===e.key||"Backspace"===e.key)&&(e.preventDefault(),j.has(n.commandId)||v(n.commandId)))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[c,C,p,b,j,S,E,P]);let T=e=>{let t,r,s,o,a=j.has(e.commandId),i=b===e.commandId,d=ea(e),c=e.title||e.command.split("\n")[0];return(0,n.jsxs)("div",{"data-running-terminal":e.commandId,onClick:()=>g(e.commandId),onDoubleClick:()=>{a||E(e)},className:`group rounded-md px-3 py-2 transition-colors cursor-pointer ${a?"opacity-50":""} ${p===e.commandId?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"flex-shrink-0 text-muted-foreground",title:l(e.usePty?"runningTerminals.modePty":"runningTerminals.modePipe"),"aria-label":l(e.usePty?"runningTerminals.modePty":"runningTerminals.modePipe"),children:e.usePty?(0,n.jsx)(G.A,{className:"w-3.5 h-3.5"}):(0,n.jsx)(J.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)(et.j,{shortId:e.shortId,type:"terminal",onRegister:()=>{h.t4.runFork((0,ee.Ok)({tabId:e.tabId,commandId:e.commandId,command:e.command,projectCwd:e.projectCwd}).pipe(R.NWQ(()=>R.rIH)))},onUnregister:()=>{h.t4.runFork((0,ee.jO)({commandId:e.commandId}).pipe(R.NWQ(()=>R.rIH)))}}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-sm text-foreground${e.title?"":" font-mono"}`,"data-tooltip":`${e.command}
14
+ pid ${e.pid}`,"data-tooltip-mono":!0,children:c}),(0,n.jsx)("span",{className:"flex-shrink-0 text-xs tabular-nums text-muted-foreground",children:(r=Math.floor((t=Math.max(0,Math.floor((m-new Date(e.timestamp).getTime())/1e3)))/86400),s=Math.floor(t%86400/3600),o=Math.floor(t%3600/60),r>0?`${r}d ${s}h`:s>0?`${s}h ${o}m`:o>0?`${o}m`:`${t}s`)}),a?(0,n.jsx)("span",{className:"flex-shrink-0 text-xs text-muted-foreground",children:l("runningTerminals.stopping")}):i?null:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),v(e.commandId)},onDoubleClick:e=>e.stopPropagation(),className:"flex-shrink-0 p-0.5 rounded text-muted-foreground hover:text-destructive hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:l("runningTerminals.stop"),"aria-label":l("runningTerminals.stop"),children:(0,n.jsx)(Y.A,{className:"w-3.5 h-3.5"})})]}),d&&!i&&(0,n.jsx)("div",{className:"mt-0.5 pl-[22px] text-xs text-muted-foreground truncate font-mono","data-tooltip":[e.title?e.command:"",e.cwd].filter(Boolean).join("\n"),"data-tooltip-mono":!0,children:d}),i&&(0,n.jsxs)("div",{className:"mt-1.5 flex items-center justify-end gap-2",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:l("runningTerminals.confirmStop")}),(0,n.jsx)("button",{onClick:()=>v(null),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:()=>P(e),className:"px-2 py-0.5 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:l("runningTerminals.stop")})]})]},e.commandId)},$=i.length;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{onClick:L,className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${e?"w-full justify-center":"w-full"}`,title:e?l("runningTerminals.title"):void 0,"data-testid":"running-terminals-entry",children:[(0,n.jsx)(G.A,{className:"w-5 h-5 flex-shrink-0"}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:l("runningTerminals.title")}),$>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-popover border border-border ${e?"absolute -top-1 -right-1":""}`,children:$})]}),c&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[70] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:S}),(0,n.jsxs)("div",{className:x.aO,"data-testid":"running-terminals-board",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("div",{className:"flex items-center gap-3 min-w-0",children:(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:l("runningTerminals.title")})}),(0,n.jsx)("button",{onClick:S,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),0===$?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:l("runningTerminals.empty")}):(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsx)("div",{className:"w-full md:w-[360px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:(0,n.jsx)("div",{className:"p-3 space-y-3",children:N.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center gap-1.5",children:[e.number>0&&(0,n.jsx)(X.B,{number:e.number,isActive:e.cwd===t}),(0,n.jsx)("span",{className:"truncate","data-tooltip":e.cwd,children:eo(e.cwd)}),e.cwd===t&&(0,n.jsxs)("span",{className:"text-foreground-subtle",children:["\xb7 ",l("runningTerminals.currentProject")]})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(T)})]},e.cwd))})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:M?(0,n.jsx)(es,{terminal:M,subtitle:[eo(M.projectCwd),ea(M)].filter(Boolean).join(" \xb7 "),onOpenTerminal:()=>E(M)},M.commandId):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:l("runningTerminals.selectHint")})})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-1.5 border-t border-border text-xs text-muted-foreground","data-testid":"running-terminals-status",children:[(0,n.jsx)("span",{className:"tabular-nums",children:l("runningTerminals.status",{count:$,projects:N.length})}),$>0&&(0,n.jsx)("span",{className:"truncate text-foreground-subtle",children:l("runningTerminals.keys")})]})]})]})]})}var ei=r(69895),ed=r(76900),ec=r(72363),eu=r(94852),em=r(60285);let ex=e=>"unread"===e?0:"loading"===e?1:2;function eh({className:e=""}){return(0,n.jsxs)("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[(0,n.jsx)("rect",{x:"4",y:"4",width:"6",height:"6",rx:"1.5"}),(0,n.jsx)("rect",{x:"4",y:"14",width:"6",height:"6",rx:"1.5"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"6",height:"6",rx:"1.5"}),(0,n.jsx)("path",{d:"M17 3v8"}),(0,n.jsx)("path",{d:"M13 7h8"})]})}function ef({collapsed:e,previews:t,activePath:r,onOpenApps:a,onShowPreview:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),u=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{u.current?.contains(e.target)||c(!1)};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[d]);let m=t.length>3,x=t.slice(0,3),h=t.slice(3),f=e=>{l(e),c(!1)},p=e=>(0,n.jsxs)("button",{type:"button",onClick:()=>f(e),className:`w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left hover:bg-hover transition-colors ${r===e.path?"text-brand":"text-muted-foreground hover:text-foreground"}`,title:e.path,children:[(0,n.jsx)("span",{className:"h-6 w-6 flex-shrink-0 rounded-md border border-border/70 flex items-center justify-center",children:e.icon?(0,n.jsx)("span",{className:"text-sm leading-none",children:e.icon}):(0,n.jsx)(eu.A,{className:"w-3.5 h-3.5"})}),(0,n.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"block text-xs font-medium truncate",children:e.title}),(0,n.jsx)("span",{className:"block text-[10px] font-mono text-muted-foreground truncate",children:e.path})]})]},e.path),g=(e,t)=>(0,n.jsx)("div",{className:"absolute left-full bottom-0 ml-2 w-64 rounded-lg border border-border bg-card shadow-lv3 z-50",children:(0,n.jsxs)("div",{className:"max-h-[19.75rem] overflow-y-auto p-1.5 space-y-1",children:[t&&(0,n.jsxs)("button",{type:"button",onClick:()=>{a(),c(!1)},className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:[(0,n.jsx)("span",{className:"h-6 w-6 flex-shrink-0 rounded-md border border-border/70 flex items-center justify-center",children:(0,n.jsx)(eh,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"text-xs font-medium truncate",children:i("workspace.apps")})]}),e.map(p)]})});return e?(0,n.jsxs)("div",{ref:u,className:"relative",children:[(0,n.jsxs)("button",{type:"button",onClick:()=>t.length?c(e=>!e):a(),className:`relative w-full flex items-center justify-center px-2 py-2 rounded-lg hover:bg-hover transition-colors ${r?"text-brand":"text-muted-foreground hover:text-foreground"}`,title:i("workspace.apps"),children:[(0,n.jsx)(eh,{className:"w-5 h-5 flex-shrink-0"}),t.length>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 text-muted-foreground text-xs font-medium rounded-full flex items-center justify-center bg-popover border border-border",children:t.length})]}),d&&g(t,!0)]}):(0,n.jsxs)("div",{ref:u,className:"relative flex items-center gap-1 rounded-lg hover:bg-hover transition-colors",children:[(0,n.jsxs)("button",{type:"button",onClick:a,className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-2 text-muted-foreground hover:text-foreground",children:[(0,n.jsx)(eh,{className:"w-5 h-5 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm",children:i("workspace.apps")})]}),t.length>0&&(0,n.jsxs)("div",{className:"flex items-center gap-1 pr-1.5 flex-shrink-0",children:[x.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>f(e),className:`h-6 w-6 rounded-md border flex items-center justify-center transition-colors ${r===e.path?"border-brand/80 text-brand":"border-border/70 text-muted-foreground hover:border-brand/70 hover:text-brand"}`,"data-tooltip":e.title,"aria-label":e.title,children:e.icon?(0,n.jsx)("span",{className:"text-sm leading-none",children:e.icon}):(0,n.jsx)(eu.A,{className:"w-3.5 h-3.5"})},e.path)),m&&(0,n.jsx)("button",{type:"button",onClick:()=>c(e=>!e),className:"h-6 w-6 rounded-md border border-border/70 text-muted-foreground hover:border-brand/70 hover:text-brand flex items-center justify-center transition-colors","data-tooltip":i("common.loadMore"),"aria-label":i("common.loadMore"),children:(0,n.jsx)(em.A,{className:"w-3.5 h-3.5"})})]}),d&&g(h,!1)]})}function ep({projects:e,activeIndex:t,collapsed:r,currentCwd:d,onSelectProject:c,onRemoveProject:u,onReorderProjects:m,onToggleCollapse:x,onOpenSessionBrowser:f,onOpenSettings:p,onOpenNote:g,onOpenSkills:b,onOpenBots:v,onOpenApps:j,htmlAppPreviews:k,activeHtmlAppPreviewPath:y,onShowHtmlAppPreview:N,onSwitchProject:C,onFocusTerminal:S,onResolveSessionNumbers:M,sessionOrders:L,draftCwds:E,sessionNumbers:P}){let $,R,{t:I,i18n:B}=(0,o.Bd)(),A=(0,s.useMemo)(()=>e.map(e=>e.cwd),[e]),{latest:H,hasUpdate:W}=function(){let[e,t]=(0,s.useState)(),[r,n]=(0,s.useState)();(0,s.useEffect)(()=>{let e=!1;h.t4.runPromiseExit((0,ed.Wr)()).then(r=>{!e&&"Success"===r._tag&&r.value.version&&t(r.value.version)});let r=new AbortController,s=setTimeout(()=>r.abort(),3e3);return fetch("https://registry.npmjs.org/@surething/cockpit/latest",{signal:r.signal}).then(e=>e.ok?e.json():null).then(t=>{if(e)return;let r=t?.version;"string"==typeof r&&n(r)}).catch(()=>{}).finally(()=>clearTimeout(s)),()=>{e=!0,r.abort(),clearTimeout(s)}},[]);let[o,a]=(0,s.useState)(!1);(0,s.useEffect)(()=>{a(!0===window.__COCKPIT_FORCE_UPDATE__)},[]);let l=!!e&&!!r&&function(e,t){let r=e=>e.replace(/^v/,"").split("-")[0].split(".").map(e=>parseInt(e,10)||0),n=r(e),s=r(t),o=Math.max(n.length,s.length);for(let e=0;e<o;e++){let t=n[e]??0,r=s[e]??0;if(t!==r)return t-r}return 0}(r,e)>0;return{current:e,latest:o?r??"999.0.0":r,hasUpdate:!!o||l}}(),[z,O]=(0,s.useState)(!1),_=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!z)return;let e=e=>{_.current?.contains(e.target)||O(!1)},t=()=>O(!1);return document.addEventListener("mousedown",e,!0),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e,!0),window.removeEventListener("blur",t)}},[z]);let q=(0,s.useCallback)(()=>{navigator.clipboard.writeText("cockpit update"),(0,w.oR)(I("workspace.upgradeCommandCopied")),O(!1)},[I]),{isUpdating:V,start:U}=($=(0,s.useSyncExternalStore)(ec.N4,ec.fX,ec.fX),R=(0,s.useCallback)(()=>{(0,ec._I)()},[]),{isUpdating:$.visible&&"done"!==$.stage&&"failed"!==$.stage,start:R}),K=(0,s.useCallback)(()=>{O(!1),U()},[U]),{pinnedSessions:G,unpinSession:J,reorder:Y}=(0,ei.P)(),{tasks:X,unreadCount:ee,reload:et,pauseTask:er,resumeTask:en,triggerTask:es,deleteTask:eo,updateTask:ea}=(0,D.nS)(),[eu,em]=(0,s.useState)(null),[eh,eg]=(0,s.useState)(null),[eb,ev]=(0,s.useState)([]),ej=(0,s.useRef)(eb);(0,s.useEffect)(()=>{ej.current=eb});let ew=(0,s.useRef)(et);(0,s.useEffect)(()=>{ew.current=et});let ek=(0,s.useCallback)(e=>{try{var t;t=ew.current,!e||"object"!=typeof e||("task-fired"===e.type?t():"global-state"===e.type&&Array.isArray(e.data?.sessions)&&ev(e.data.sessions))}catch{}},[]);(0,Z.h)({url:"/ws/global-state",onMessage:ek});let ey=new Set(eb.filter(e=>"loading"===e.status).map(e=>e.cwd)),eN=new Set(eb.filter(e=>"unread"===e.status).map(e=>e.cwd)),eC=(0,s.useMemo)(()=>{let t=new Map;for(let r of e){let e=L[r.cwd]??[],n=eb.filter(e=>e.cwd===r.cwd).map(t=>({session:t,position:e.indexOf(t.sessionId)})).filter(({session:e,position:t})=>t>=0||"loading"===e.status||"unread"===e.status).sort((e,t)=>{let r=ex(e.session.status)-ex(t.session.status);return 0!==r?r:t.session.lastActive-e.session.lastActive}),s=n.find(({session:e})=>2===ex(e.status)),o=n.filter(({session:e})=>2>ex(e.status)||e===s?.session).slice(0,3).sort((e,t)=>e.position<0?t.position<0?0:1:t.position<0?-1:e.position-t.position).map(({session:e,position:t})=>({sessionId:e.sessionId,label:t>=0?String(t+1):"\xb7",status:"loading"===e.status?"loading":"unread"===e.status?"unread":"normal",...e.bot?{bot:e.bot}:{}}));o.length>0&&t.set(r.cwd,o)}return t},[e,eb,L]),eS=(0,s.useCallback)(e=>{em(e)},[]),eM=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==eu&&eu!==t&&eg(t)},[eu]),eL=(0,s.useCallback)(t=>{if(null!==eu&&eu!==t){let r=[...e],[n]=r.splice(eu,1);r.splice(t,0,n),m(r)}em(null),eg(null)},[eu,e,m]),eE=(0,s.useCallback)(()=>{em(null),eg(null)},[]);return(0,n.jsxs)("div",{className:`h-full bg-card border-r border-border flex flex-col transition-all duration-200 ${r?"w-12":"w-56"}`,children:[(0,n.jsxs)("div",{className:"group p-2 border-b border-border relative",children:[(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${r?"justify-center":""}`,onClick:f,title:r?I("workspace.openProject"):void 0,children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M12 10v6m3-3H9m-4 7h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:I("workspace.openProject")})]}),r?(0,n.jsx)("button",{className:"absolute inset-0 m-2 flex items-center justify-center px-2 py-2 rounded-lg bg-popover shadow-lv1 text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:x,title:I("workspace.expandSidebar"),children:(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0 rotate-180",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}):(0,n.jsx)("button",{className:"absolute top-1/2 -translate-y-1/2 right-2 p-2 rounded-lg bg-popover shadow-lv1 text-foreground transition z-10 opacity-0 group-hover:opacity-100 [@media(hover:none)]:opacity-100",onClick:x,title:I("workspace.collapseSidebar"),children:(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:e.map((e,s)=>{var o;let a;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>eS(s),onDragOver:e=>eM(e,s),onDrop:()=>eL(s),onDragEnd:eE,className:`${eh===s?"border-t-2 border-brand":""} ${eu===s?"opacity-50":""}`,children:(0,n.jsx)(i.ProjectItem,{index:s,name:(a=(o=e.cwd).split("/").filter(Boolean))[a.length-1]||o,cwd:e.cwd,isActive:s===t,collapsed:r,hasUnread:eN.has(e.cwd),isLoading:ey.has(e.cwd),hasDraft:E.has(e.cwd),sessionBadges:eC.get(e.cwd),onClick:()=>c(s),onSelectSession:t=>C(e.cwd,t),onRemove:()=>u(s),onOpenNote:()=>g(e.cwd)})},e.cwd)})}),(0,n.jsxs)("div",{className:"p-2 border-t border-border space-y-1",children:[(0,n.jsx)(T,{projectOrder:A,currentCwd:d,onSwitchProject:C,onResolveSessionNumbers:M,collapsed:r,sessions:eb}),(0,n.jsx)(F,{collapsed:r,projectOrder:A,currentCwd:d,pinnedSessions:G,sessionNumbers:P,onSwitchProject:C,onUnpin:J,onReorder:Y}),(0,n.jsx)(Q,{collapsed:r,projectOrder:A,currentCwd:d,tasks:X,unreadCount:ee,sessionNumbers:P,onSwitchProject:C,onPause:er,onResume:en,onTrigger:es,onDelete:eo,onUpdateTask:ea}),(0,n.jsx)(el,{collapsed:r,currentCwd:d,projectOrder:A,onFocusTerminal:S}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${r?"justify-center":""}`,onClick:()=>g(),title:r?I("workspace.notes"):void 0,children:[(0,n.jsx)("svg",{className:"w-5 h-5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:I("workspace.notes")})]}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${r?"justify-center":""}`,onClick:b,title:r?I("workspace.skills"):void 0,children:[(0,n.jsx)(a.A,{className:"w-5 h-5 flex-shrink-0"}),!r&&(0,n.jsx)("span",{className:"text-sm",children:I("workspace.skills")})]}),(0,n.jsx)(ef,{collapsed:r,previews:k,activePath:y,onOpenApps:j,onShowPreview:N}),(0,n.jsxs)("button",{className:`w-full flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${r?"justify-center":""}`,onClick:v,title:r?I("workspace.bots"):void 0,children:[(0,n.jsx)(l.A,{className:"w-5 h-5 flex-shrink-0"}),!r&&(0,n.jsx)("span",{className:"text-sm",children:I("workspace.bots")})]}),(0,n.jsxs)("div",{className:`relative flex items-center gap-2 px-2 py-2 rounded-lg cursor-pointer text-muted-foreground hover:text-foreground hover:bg-hover transition-colors ${r?"justify-center":""}`,onClick:p,title:I("workspace.settings"),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),r&&W&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500",title:H?I("workspace.updateAvailable",{version:H}):void 0})]}),!r&&(0,n.jsx)("span",{className:"flex-1 text-sm",children:I("workspace.settings")}),!r&&W&&H&&(0,n.jsxs)("div",{ref:_,className:"relative -mr-2",children:[(0,n.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),O(e=>!e)},className:"px-1.5 py-0.5 rounded text-xs font-mono font-medium text-brand hover:bg-brand/10 transition-colors",title:I("workspace.updateAvailable",{version:H}),"aria-label":I("workspace.updateAvailable",{version:H}),children:["v",H]}),z&&(0,n.jsxs)("div",{className:"absolute left-full bottom-full ml-2 mb-1 w-56 rounded-lg border border-border bg-popover shadow-lv2 p-2 z-50",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2 px-1",children:I("workspace.updateAvailable",{version:H})}),(0,n.jsxs)("button",{type:"button",onClick:K,disabled:V,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm text-left\n hover:bg-hover transition-colors disabled:opacity-60 disabled:cursor-default",children:[V?(0,n.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:4}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),(0,n.jsx)("span",{className:"flex-1",children:V?I("workspace.updating"):I("workspace.updateNow")})]}),(0,n.jsxs)("button",{type:"button",onClick:q,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm text-left hover:bg-hover transition-colors",children:[(0,n.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}),(0,n.jsx)("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})]}),(0,n.jsx)("span",{className:"flex-1",children:I("workspace.copyUpgradeCommand")})]}),(0,n.jsxs)("a",{href:`https://opencockpit.dev/${B.language?.startsWith("zh")?"zh":"en"}/changelog/`,target:"_blank",rel:"noopener",onClick:()=>O(!1),className:"w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-hover transition-colors",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("span",{className:"flex-1",children:I("workspace.viewChangelog")}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})]})]})]}),!r&&(0,n.jsx)("a",{href:`https://opencockpit.dev/${B.language?.startsWith("zh")?"zh":"en"}/docs/get-started/quickstart/`,target:"_blank",rel:"noopener",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",onClick:e=>e.stopPropagation(),title:I("workspace.help"),"aria-label":I("workspace.help"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2})]})})]})]})]})}},15317:(e,t,r)=>{r.d(t,{LV:()=>o,dp:()=>a,wJ:()=>s});let n={minute:1,hour:60,day:1440};function s(e){return e>0&&e%n.day==0?{value:e/n.day,unit:"day"}:e>0&&e%n.hour==0?{value:e/n.hour,unit:"hour"}:{value:e,unit:"minute"}}function o(e,t){let r=parseFloat(e);return!Number.isFinite(r)||r<=0?0:Math.round(r*n[t])}function a(e,t){let{value:r,unit:n}=s(e);return t(`scheduledTasks.duration.${n}`,{count:r})}},16220:(e,t,r)=>{r.d(t,{TabManagerTopBar:()=>j});var n=r(95155),s=r(12115),o=r(63728),a=r(34075),l=r(79114),i=r(95045),d=r(75346),c=r(49433),u=r(86957),m=r(53213),x=r(45720),h=r(76900),f=r(74281);function p({cwd:e,sessionId:t}){let{t:r}=(0,l.Bd)(),[o,a]=(0,s.useState)(!1),[i,d]=(0,s.useState)(!1),[m,x]=(0,s.useState)({status:"loading"}),g=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e;a(!("localhost"===(e=window.location.hostname.replace(/^\[|\]$/g,"").toLowerCase())||e.endsWith(".localhost")||"::1"===e||"0.0.0.0"===e||/^127(?:\.\d{1,3}){3}$/.test(e)))},[]),(0,s.useEffect)(()=>{if(!i)return;let r=!1;x({status:"loading"});let n=c.JkU(function*(){var r,n;let s,o,a=yield*(0,h.O2)(),l=(r=window.location.origin,n={cwd:e,sessionId:t,token:a},s=new URLSearchParams,n.cwd&&n.sessionId&&(s.set("cwd",n.cwd),s.set("sessionId",n.sessionId)),n.token&&s.set("token",n.token),o=s.toString(),`${r}/m${o?`?${o}`:""}`);return{svg:yield*(0,h.GS)(l),hasToken:null!==a}});return u.t4.runPromiseExit(n).then(e=>{r||x("Success"===e._tag?{status:"ready",...e.value}:{status:"error"})}),()=>{r=!0}},[i,e,t]),(0,s.useEffect)(()=>{if(!i)return;let e=e=>{g.current&&!g.current.contains(e.target)&&d(!1)},t=e=>{"Escape"===e.key&&d(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[i]);let b=(0,s.useCallback)(()=>d(e=>!e),[]);return o?(0,n.jsxs)("div",{className:"relative",ref:g,children:[(0,n.jsx)("button",{onClick:b,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:r("tabManagerTopBar.openOnPhone"),children:(0,n.jsx)(f.A,{className:"w-5 h-5"})}),i&&(0,n.jsxs)("div",{className:"absolute top-full right-0 mt-1 w-60 p-3 bg-popover border border-border rounded-lg shadow-lv2 z-50",children:[(0,n.jsx)("div",{className:"w-full aspect-square rounded-md bg-white p-2 flex items-center justify-center",children:"ready"===m.status?(0,n.jsx)("div",{className:"w-full h-full [&>svg]:w-full [&>svg]:h-full",dangerouslySetInnerHTML:{__html:m.svg}}):(0,n.jsx)("span",{className:"text-xs text-neutral-500",children:r("error"===m.status?"tabManagerTopBar.phoneQrFailed":"common.loading")})}),(0,n.jsx)("p",{className:"mt-2 text-xs text-foreground text-center",children:r(e&&t?"tabManagerTopBar.phoneQrSessionHint":"tabManagerTopBar.phoneQrHint")}),"ready"===m.status&&m.hasToken&&(0,n.jsx)("p",{className:"mt-1 text-xs text-muted-foreground text-center",children:r("tabManagerTopBar.phoneQrTokenWarning")})]})]}):null}function g({className:e}){return(0,n.jsxs)("svg",{className:e,fill:"none",viewBox:"0 0 100 100","aria-hidden":"true",children:[(0,n.jsx)("path",{fill:"#0065A9",d:"M96.461 10.796 75.857.876a6.23 6.23 0 0 0-7.107 1.207l-67.451 61.5a4.167 4.167 0 0 0 .004 6.162l5.51 5.009a4.167 4.167 0 0 0 5.32.236l81.228-61.62c2.725-2.067 6.639-.124 6.639 3.297v-.24a6.25 6.25 0 0 0-3.539-5.63Z"}),(0,n.jsx)("path",{fill:"#007ACC",d:"m96.461 89.204-20.604 9.92a6.229 6.229 0 0 1-7.107-1.207l-67.451-61.5a4.167 4.167 0 0 1 .004-6.162l5.51-5.009a4.167 4.167 0 0 1 5.32-.236l81.228 61.62c2.725 2.067 6.639.124 6.639-3.297v.24a6.25 6.25 0 0 0-3.539 5.63Z"}),(0,n.jsx)("path",{fill:"#1F9CF0",d:"M75.858 99.126a6.232 6.232 0 0 1-7.108-1.21c2.306 2.307 6.25.674 6.25-2.588V4.672c0-3.262-3.944-4.895-6.25-2.589a6.232 6.232 0 0 1 7.108-1.21l20.6 9.908A6.25 6.25 0 0 1 100 16.413v67.174a6.25 6.25 0 0 1-3.541 5.633l-20.601 9.906Z"})]})}function b({className:e}){return(0,n.jsx)("svg",{className:e,viewBox:"0 0 466.73 532.09",fill:"currentColor","aria-hidden":"true",children:(0,n.jsx)("path",{d:"M457.43,125.94L244.42,2.96c-6.84-3.95-15.28-3.95-22.12,0L9.3,125.94c-5.75,3.32-9.3,9.46-9.3,16.11v247.99c0,6.65,3.55,12.79,9.3,16.11l213.01,122.98c6.84,3.95,15.28,3.95,22.12,0l213.01-122.98c5.75-3.32,9.3-9.46,9.3-16.11v-247.99c0-6.65-3.55-12.79-9.3-16.11h-.01ZM444.05,151.99l-205.63,356.16c-1.39,2.4-5.06,1.42-5.06-1.36v-233.21c0-4.66-2.49-8.97-6.53-11.31L24.87,145.67c-2.4-1.39-1.42-5.06,1.36-5.06h411.26c5.84,0,9.49,6.33,6.57,11.39h-.01Z"})})}function v({cwd:e,currentBranch:t,onSwitched:r}){let{t:o}=(0,l.Bd)(),[i,d]=(0,s.useState)(!1),[c,x]=(0,s.useState)([]),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[j,w]=(0,s.useState)(""),k=(0,s.useRef)(null),y=(0,s.useRef)(null),N=(0,s.useCallback)(async()=>{p(!0);let t=await u.t4.runPromiseExit((0,m.r4)(e));if("Success"===t._tag){let e=t.value,r=e.local??[];x([...r,...(e.remote??[]).filter(e=>!r.includes(e.replace(/^origin\//,"")))])}else(0,a.oR)(o("toast.loadBranchFailed"),"error");p(!1)},[e,o]),C=(0,s.useCallback)(()=>{d(!0),w(""),N()},[N]),S=(0,s.useCallback)(()=>{d(!1)},[]);(0,s.useEffect)(()=>{if(!i)return;let e=e=>{k.current&&!k.current.contains(e.target)&&S()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[i,S]),(0,s.useEffect)(()=>{i&&setTimeout(()=>y.current?.focus(),50)},[i]);let M=async t=>{b(!0);let n=await u.t4.runPromiseExit((0,h.Kl)({action:"checkout",cwd:e,path:e,branch:t}));if("Success"===n._tag){let e=t.replace(/^origin\//,"");(0,a.oR)(o("toast.switchedToBranch",{branch:e}),"success"),S(),r()}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:o("toast.switchBranchFailed");(0,a.oR)(r,"error")}b(!1)},L=c.filter(e=>e!==t&&e.toLowerCase().includes(j.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:k,children:[(0,n.jsx)("button",{onClick:i?S:C,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:o("git.switchBranch"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7h12m0 0l-4-4m4 4l-4 4m0 6H4m0 0l4 4m-4-4l4-4"})})}),i&&(0,n.jsxs)("div",{className:"absolute top-full left-0 mt-1 w-64 bg-popover border border-border rounded-lg shadow-lv2 z-50 overflow-hidden",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:y,type:"text",value:j,onChange:e=>w(e.target.value),placeholder:o("git.searchBranch"),className:"w-full px-2.5 py-1.5 text-sm bg-muted rounded border-none outline-none",onKeyDown:e=>{"Escape"===e.key&&S()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:f?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:o("common.loading")}):0===L.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:j?o("git.noMatchingBranches"):o("git.noBranches")}):L.map(e=>(0,n.jsx)("button",{onClick:()=>M(e),disabled:g,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-hover transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function j({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:m,onOpenAliasManager:f,onBranchSwitched:w}){let{t:k}=(0,l.Bd)(),y=t?.sessionId?(0,x.X)(t.engine,t.sessionId):null;return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6 cursor-pointer",title:k("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,a.oR)(k("toast.copiedPageUrl"),"success")})}}),e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help","data-tooltip":`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,a.oR)(k("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:k("tabManagerTopBar.copyDirPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}):(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"})]}),r&&e&&(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsxs)("button",{onClick:m,className:"flex items-center gap-1.5 px-2 py-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:"Git Worktrees",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 17h8m0 0l-4-4m4 4l-4 4M3 7v6a4 4 0 004 4h5"})}),(0,n.jsx)("span",{className:"text-sm",children:s||"main"})]}),(0,n.jsx)(v,{cwd:e,currentBranch:s,onSwitched:()=>w?.()})]})]}),(0,n.jsx)("div",{className:"absolute left-1/2 -translate-x-1/2",children:(0,n.jsx)(o.gT,{})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(p,{cwd:t?.cwd??e,sessionId:t?.sessionId}),(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.refreshProject"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&u.t4.runFork((0,h.em)(t.cwd).pipe(c.NWQ(()=>c.rIH)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)(g,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&u.t4.runFork((0,h.Q1)(t.cwd).pipe(c.NWQ(()=>c.rIH)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.openInCursor"),children:(0,n.jsx)(b,{className:"w-4 h-4"})}),y&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(y).then(()=>{(0,a.oR)(k("toast.copiedCommand",{command:y}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("chat.copyCommandTooltip",{command:y}),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:f,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.aliasesGlobal"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12h-6m-4 0a8 8 0 1116 0 8 8 0 01-16 0zm4 0h.01"})})}),(0,n.jsx)("button",{onClick:()=>(0,i.F)(d.n.OpenTokenStats,{}),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.tokenStats"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"})})}),(0,n.jsx)("button",{onClick:()=>window.open("https://surething.io?from=cockpit","_blank"),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:k("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}},21484:(e,t,r)=>{r.d(t,{SettingsModal:()=>h});var n=r(95155),s=r(12115),o=r(79114),a=r(3238),l=r(34075),i=r(12786),d=r(86957),c=r(49433),u=r(91281),m=r(80286),x=r(76900);function h({isOpen:e,onClose:t}){let{t:r,i18n:f}=(0,o.Bd)(),{theme:p,setTheme:g}=(0,a.DP)(),[b,v]=(0,s.useState)([]),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)(""),[N,C]=(0,s.useState)(null),[S,M]=(0,s.useState)("auto"),[L,E]=(0,s.useState)(!0);(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,x.M5)()).then(e=>{"Success"===e._tag&&(e.value.language&&M(e.value.language),E(!1!==e.value.codexPromptSuggestions))})},[e]);let P=(0,s.useCallback)(e=>{M(e),d.t4.runFork((0,x.DZ)({language:e}).pipe(c.NWQ(()=>c.rIH)));let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;f.changeLanguage(t)},[f]),T=(0,s.useCallback)(e=>{E(e),d.t4.runFork((0,x.DZ)({codexPromptSuggestions:e}).pipe(c.NWQ(()=>c.rIH)))},[]),$=b.length?"installed":"not-installed",R=b[0]?.version??null,I=b.map(e=>e.browser).filter(Boolean).join(", ");if((0,s.useEffect)(()=>{if(!e)return;let t=d.t4.runFork((0,x.IG)().pipe(c.Mim(e=>c.OH5(()=>v(e))),c.NWQ(()=>c.rIH),c.uxO(u.ji("3 seconds"))));return()=>{d.t4.runFork(m.G(t))}},[e]),(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,x.Wr)()).then(e=>{"Success"===e._tag&&(e.value.version&&y(e.value.version),e.value.agents&&C(e.value.agents))})},[e]),(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,x.Or)()).then(e=>{"Success"===e._tag&&e.value.path&&w(e.value.path)})},[e]),!e)return null;let F=[{value:"system",label:r("settings.themeSystem"),icon:"\uD83D\uDCBB"},{value:"light",label:r("settings.themeLight"),icon:"☀️"},{value:"dark",label:r("settings.themeDark"),icon:"\uD83C\uDF19"}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-2xl mx-4 overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:r("settings.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"p-4 space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.theme")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:F.map(e=>(0,n.jsxs)("button",{onClick:()=>g(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${p===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.language")}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:[{value:"auto",label:r("settings.languageAuto"),icon:"\uD83C\uDF10"},{value:"en",label:"English",icon:"\uD83C\uDDFA\uD83C\uDDF8"},{value:"zh",label:"中文",icon:"\uD83C\uDDE8\uD83C\uDDF3"}].map(e=>(0,n.jsxs)("button",{onClick:()=>P(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${S===e.value?"border-brand bg-brand/10 text-brand":"border-border hover:border-slate-6 text-muted-foreground hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:"text-xl",children:e.icon}),(0,n.jsx)("span",{className:"text-xs font-medium",children:e.label})]},e.value))})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.codexSection")}),(0,n.jsxs)("label",{className:"flex items-start gap-2 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:L,onChange:e=>T(e.target.checked),className:"mt-0.5 accent-brand"}),(0,n.jsxs)("span",{className:"space-y-0.5",children:[(0,n.jsx)("span",{className:"block text-xs font-medium text-foreground",children:r("settings.codexSuggestions")}),(0,n.jsx)("span",{className:"block text-xs text-muted-foreground leading-relaxed",children:r("settings.codexSuggestionsDescription")})]})]})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.browserExtension")}),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${"installed"===$?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===$&&`${r("settings.extensionInstalled")}${R?` (v${R})`:""}${I?` \xb7 ${I}`:""}`,"not-installed"===$&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==$&&(0,n.jsxs)("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-md p-2 space-y-1",children:[(0,n.jsx)("p",{className:"font-medium text-foreground",children:r("settings.installSteps")}),(0,n.jsxs)("p",{children:[r("settings.step1")," ",(0,n.jsx)("code",{className:"px-1 py-0.5 bg-muted rounded text-foreground",children:"chrome://extensions"})]}),(0,n.jsx)("p",{children:r("settings.step2")}),(0,n.jsx)("p",{children:r("settings.step3")}),(0,i.L)()&&(0,n.jsx)("p",{dangerouslySetInnerHTML:{__html:r("settings.step4mac")}})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:()=>{let e=j||"chrome-extension";navigator.clipboard.writeText(e),(0,l.oR)(r("toast.copiedName",{name:e}))},className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:r("settings.copyExtensionPath")}),"installed"===$&&(0,n.jsx)("button",{onClick:()=>{d.t4.runFork((0,x.Bt)().pipe(c.NWQ(()=>c.rIH))),(0,l.oR)(r("toast.pluginReloading"))},className:"px-3 py-1.5 text-xs border border-border text-foreground rounded-md hover:bg-muted transition-colors",children:r("settings.reloadExtension")})]}),j&&(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground font-mono truncate",children:j})]})]}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-foreground mb-2",children:r("settings.about")}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground space-y-1",children:[(0,n.jsxs)("p",{children:["Cockpit",k?` v${k}`:""]}),(N?.claude||N?.codex)&&(0,n.jsx)("p",{className:"text-muted-foreground/60",children:[N.claude&&`Claude Code ${N.claude}`,N.codex&&`Codex ${N.codex}`,r("settings.agentsBundled")].filter(Boolean).join(" \xb7 ")}),(0,n.jsx)("p",{className:"text-muted-foreground/60",children:"One seat. One AI. Everything under control."})]})]})]})]})]})}},23121:(e,t,r)=>{r.d(t,{Q_:()=>m,nS:()=>f});var n=r(12115),s=r(95045),o=r(75346),a=r(49433),l=r(69809),i=r(34075),d=r(86957),c=r(82680);let u=(e,t,r)=>a.$mh({try:async()=>{let n=await fetch(e,{method:t,headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!n.ok)throw Error(`HTTP ${n.status}`);return await n.json()},catch:r=>new c.uV({message:`${t} ${e} failed`,cause:r})});function m(e){return e.resolvedPrompt||e.message||e.taskFile||""}let x="SCHEDULED_TASKS_CHANGED";function h(){(0,s.F)(o.n.ScheduledTasksChanged,{}),document.querySelectorAll("iframe").forEach(e=>{try{e.contentWindow?.postMessage({type:x},"*")}catch{}})}function f(){let[e,t]=(0,n.useState)([]),[r,s]=(0,n.useState)(0),o=(0,n.useRef)(0),m=(0,n.useCallback)(()=>{let e,r=++o.current;d.t4.runPromise((e="/api/scheduled-tasks",a.$mh({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new c.uV({message:`fetch ${e} failed`,cause:t})})).pipe(a.YWq({onSuccess:e=>{r===o.current&&(t(e.tasks??[]),s(e.unreadCount??0))},onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{m()},[m]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type===x&&m()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[m]);let f=(0,n.useCallback)(async e=>{let t=await d.t4.runPromiseExit(u("/api/scheduled-tasks","POST",{language:l.A.language,...e}));if("Success"!==t._tag)return null;let r=t.value;return r.task?(m(),h(),r.task):null},[m]),p=(0,n.useCallback)(async e=>{await d.t4.runPromise(u("/api/scheduled-tasks","PATCH",e).pipe(a.NLW).pipe(a.NWQ(()=>a.rIH))),m(),h()},[m]),g=(0,n.useCallback)(e=>p({id:e,action:"pause"}),[p]),b=(0,n.useCallback)(e=>p({id:e,action:"resume"}),[p]),v=(0,n.useCallback)(async e=>{await d.t4.runPromise(u("/api/scheduled-tasks","DELETE",{id:e}).pipe(a.NLW).pipe(a.as(!0),a.DM4(()=>!1)))||(0,i.oR)(l.A.t("scheduledTasks.deleteFailed"),"error"),m(),h()},[m]),j=(0,n.useCallback)((e,t)=>p({id:e,action:"update",fields:{...t,language:l.A.language}}),[p]),w=(0,n.useCallback)(e=>p({id:e,action:"trigger"}),[p]),k=(0,n.useCallback)(e=>p({id:e,action:"markRead"}),[p]);return{tasks:e,unreadCount:r,reload:m,createTask:f,pauseTask:g,resumeTask:b,triggerTask:w,deleteTask:v,updateTask:j,markRead:k,markAllRead:(0,n.useCallback)(()=>p({action:"markAllRead"}),[p]),reorderTasks:(0,n.useCallback)(e=>p({action:"reorder",fields:{orderedIds:e}}),[p])}}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>k});var n=r(95155),s=r(12115),o=r(68287),a=r(16147),l=r(57125),i=r(93777),d=r(67889),c=r(75347),u=r(92689),m=r(64428),x=r(79114),h=r(51914),f=r(85942),p=r(94290),g=r(80860),b=r(50538);function v({number:e,status:t,statusLabel:r,isActive:s,pinned:l,bot:i}){let d="normal"!==t?(0,o.JQ)(t,s):l?"border-transparent bg-amber-9 text-black/80":s?"border-transparent bg-brand/25 text-brand":"border-transparent bg-muted-foreground/25 text-foreground/75";return(0,n.jsx)(a.w,{wash:d,ring:(0,o.QV)(t),bot:i,role:"normal"!==t?"status":void 0,ariaLabel:i?[r,`Bot session: @${i}`].filter(Boolean).join(" \xb7 "):r,ariaHidden:"normal"===t&&!i,children:e})}function j({onNewTab:e,onNewCodexTab:t,onNewGrokTab:r,onNewKimiTab:o,onNewGlmTab:a,onNewOllamaTab:i,onNewDeepseekTab:d}){let[c,u]=(0,s.useState)(!1),f=(0,s.useRef)(null),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({top:0,left:0}),v=(0,s.useRef)(0),w=(0,m.F2)(),{t:k}=(0,x.Bd)();return(0,s.useEffect)(()=>{if(!c)return;let e=e=>{p.current&&!p.current.contains(e.target)&&f.current&&!f.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[c]),(0,s.useLayoutEffect)(()=>{let e=p.current;if(!c||!e)return;let t=e.getBoundingClientRect();t.bottom>window.innerHeight-8&&b(e=>({...e,top:Math.max(8,v.current-t.height)}))},[c]),(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:f,onClick:()=>{if(!c&&f.current){let e=f.current.getBoundingClientRect(),t=w?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;b({top:e.bottom+4-n,left:e.left-r}),v.current=e.top-4-n}u(e=>!e)},className:"flex-shrink-0 flex items-center gap-1.5 pl-2 pr-3 py-1.5 text-sm text-foreground hover:bg-hover rounded-md transition-colors",children:[(0,n.jsx)(h.A,{className:"w-5 h-5"}),k("tabBar.newTab")]}),c&&(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{ref:p,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lv2 py-1 min-w-[140px]",style:{top:g.top,left:g.left},children:l.CX.map(s=>(0,n.jsxs)("button",{onClick:()=>{u(!1),"codex"===s?t?.():"grok"===s?r?.():"kimi"===s?o?.():"glm"===s?a?.():"ollama"===s?i?.():"deepseek"===s?d?.():e()},className:"w-full flex items-center gap-2 px-3 py-1.5 text-xs text-foreground hover:bg-brand/10 transition-colors whitespace-nowrap",children:[(0,n.jsx)(l.eV,{engine:s,className:"h-3.5 w-3.5"}),l.H[s]]},s))})})]})}function w({anchor:e,onClose:t,onCreate:r}){let o=(0,s.useRef)(null),[a,l]=(0,s.useState)(e.top);return(0,s.useLayoutEffect)(()=>{let t=o.current;if(!t)return;let r=t.getBoundingClientRect().bottom-(window.innerHeight-8);l(r>0?Math.max(8,e.top-r):e.top)},[e.top]),(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{ref:o,className:"fixed z-[9999]",style:{top:a,left:e.left},children:(0,n.jsx)(i.E,{unanchored:!0,onClose:t,onCreate:r})})})}function k({tabs:e,titlesLoading:t=!1,selectedTabId:r,visibleTabIds:o,unreadTabs:a,globalLoadingTabs:l,dragTabIndex:i,dragOverTabIndex:h,isPinned:y,onTogglePin:N,onScheduleTask:C,onSwitchTab:S,onCloseTab:M,onCloseAllTabs:L,onNewTab:E,onNewCodexTab:P,onNewGrokTab:T,onNewKimiTab:$,onNewGlmTab:R,onNewOllamaTab:I,onNewDeepseekTab:F,onOpenProjectSessions:B,onDragStart:D,onDragOver:A,onDrop:H,onDragEnd:W}){let{t:z}=(0,x.Bd)(),[O,_]=(0,s.useState)(320),q=(0,s.useRef)(null),V=(0,s.useRef)(null),U=(0,m.F2)(),[K,Q]=(0,s.useState)(null),G=(0,s.useCallback)(e=>{"mouse"===e.pointerType&&0===e.button&&(e.preventDefault(),q.current={startX:e.clientX,startWidth:O},e.currentTarget.setPointerCapture(e.pointerId))},[O]),J=(0,s.useCallback)(e=>{let t=q.current;t&&_(Math.min(480,Math.max(320,t.startWidth+(e.clientX-t.startX))))},[]),Y=(0,s.useCallback)(e=>{q.current&&(q.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},[]);return(0,n.jsxs)("div",{ref:V,className:"relative flex-shrink-0 h-full flex flex-col border-r border-border bg-card",style:{width:O},children:[(0,n.jsx)("div",{onPointerDown:G,onPointerMove:J,onPointerUp:Y,onPointerCancel:Y,className:"absolute inset-y-0 -right-[3px] w-[5px] z-10 cursor-col-resize group",children:(0,n.jsx)("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-px group-hover:bg-brand transition-colors"})}),(0,n.jsx)("div",{className:`${d.o} px-2`,children:(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex items-center gap-0.5",children:[(0,n.jsxs)("span",{className:"pl-1 text-sm font-medium text-foreground truncate",children:[z("sessions.projectSessions"),(0,n.jsx)("span",{className:"ml-1.5 text-xs font-normal text-muted-foreground tabular-nums",children:e.length})]}),L&&(0,n.jsx)(n.Fragment,{children:(0,n.jsx)("button",{onClick:L,className:"ml-auto flex-shrink-0 p-1.5 text-muted-foreground hover:text-destructive hover:bg-hover rounded transition-colors",title:z("tabBar.closeAll"),"aria-label":z("tabBar.closeAll"),children:(0,n.jsx)(f.A,{className:"w-4 h-4"})})})]})}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto p-1.5 space-y-0.5",children:[e.map((e,s)=>{let d=e.id===r,m=!d&&(o?.includes(e.id)??!1),x=y?.(e.id)??!1,f=e.isLoading||l.has(e.id)?"loading":a.has(e.id)&&!d?"unread":"normal";return(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>D(s),onDragOver:e=>A(e,s),onDrop:()=>H(s),onDragEnd:W,onClick:()=>S(e.id),className:`group group/session-title flex items-center gap-2 px-2 py-1.5 text-sm cursor-pointer rounded-md transition-colors ${d?"bg-brand/10 text-foreground font-medium":m?"bg-secondary/60 text-foreground":"text-muted-foreground hover:bg-hover hover:text-foreground"} ${i===s?"opacity-50":""} ${h===s&&i!==s?"ring-1 ring-inset ring-brand":""}`,children:[(0,n.jsx)("div",{className:"h-4 w-4 flex-shrink-0",children:(0,n.jsx)(v,{number:s+1,status:f,statusLabel:"loading"===f?z("sessions.running"):"unread"===f?z("sessions.done"):void 0,isActive:d,pinned:x,bot:e.bot})}),(0,n.jsx)("span",{className:"flex flex-1 items-center gap-1 min-w-0",children:(0,n.jsx)(c.dh,{cwd:e.cwd||"",sessionId:e.sessionId||"",title:e.title,initialTitleReady:e.titleReady||t})}),N&&e.sessionId&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),N(e.id)},className:`hidden group-hover:flex group-focus-within:flex h-5 w-5 shrink-0 items-center justify-center rounded hover:bg-muted ${x?"text-amber-9":"text-muted-foreground hover:text-amber-9"}`,"data-tooltip":z(x?"sessions.removeFavorite":"sessions.addFavorite"),"aria-label":z(x?"sessions.removeFavorite":"sessions.addFavorite"),"aria-pressed":x,children:(0,n.jsx)(p.A,{className:"h-3.5 w-3.5",fill:x?"currentColor":"none"})}),C&&e.cwd&&(0,n.jsx)("button",{onMouseDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),((e,t)=>{if(K?.tabId===e)return Q(null);let r=U?.getBoundingClientRect(),n=t.getBoundingClientRect(),s=V.current?.getBoundingClientRect().right??n.right;Q({tabId:e,top:n.top-(r?.top??0),left:s+8-(r?.left??0)})})(e.id,t.currentTarget.closest("[draggable]"))},className:`${K?.tabId===e.id?"flex text-brand bg-brand/10":"hidden group-hover:flex group-focus-within:flex text-muted-foreground hover:text-foreground hover:bg-muted"} h-5 w-5 shrink-0 items-center justify-center rounded`,"data-tooltip":z("chat.scheduledTasks"),"aria-label":z("chat.scheduledTasks"),children:(0,n.jsx)(g.A,{className:"h-3.5 w-3.5"})}),(0,n.jsxs)("span",{className:"relative h-4 w-4 shrink-0",children:[(0,n.jsx)("span",{className:"absolute inset-0 inline-flex items-center justify-center transition-opacity group-hover:opacity-0 group-focus-within:opacity-0",children:(0,n.jsx)(u.S,{engine:e.engine,size:"sm"})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),M(e.id)},className:"absolute inset-0 flex items-center justify-center rounded opacity-0 transition-opacity hover:bg-muted group-hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","data-tooltip":z("tabBar.closeTab"),"aria-label":z("tabBar.closeTab"),children:(0,n.jsx)("svg",{className:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},e.id)}),(0,n.jsxs)("div",{className:"flex items-center justify-center gap-1 pt-1",children:[(0,n.jsx)(j,{onNewTab:E,onNewCodexTab:P,onNewGrokTab:T,onNewKimiTab:$,onNewGlmTab:R,onNewOllamaTab:I,onNewDeepseekTab:F}),B&&(0,n.jsx)("button",{onClick:B,className:"flex-shrink-0 p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-md transition-colors",title:z("sessions.projectSessions"),"aria-label":z("sessions.projectSessions"),children:(0,n.jsx)(b.A,{className:"w-5 h-5"})})]})]}),K&&C&&(0,n.jsx)(w,{anchor:K,onClose:()=>Q(null),onCreate:e=>C(K.tabId,e)},K.tabId)]})}},27068:(e,t,r)=>{r.d(t,{Providers:()=>b});var n=r(95155),s=r(75347),o=r(47617),a=r(3238),l=r(34075),i=r(12115),d=r(47650);function c(e){let t=e;for(;t;){let e=t.dataset?.tooltip;if(e)return{text:e,mono:void 0!==t.dataset.tooltipMono};t=t.parentElement}return null}function u(){let[e,t]=(0,i.useState)(null),r=(0,i.useRef)(null);r.current=e;let s=(0,i.useRef)(null),o=(0,i.useRef)(null),[a,l]=(0,i.useState)({left:0,top:0}),[u,m]=(0,i.useState)(!1);return((0,i.useEffect)(()=>m(!0),[]),(0,i.useEffect)(()=>{let e=()=>{s.current&&(clearTimeout(s.current),s.current=null)},n=n=>{let o=c(n.target);if(!o){e(),r.current&&t(null);return}if(r.current&&r.current.text===o.text)return void t({...o,x:n.clientX,y:n.clientY});e();let a=n.clientX,l=n.clientY;s.current=setTimeout(()=>{t({...o,x:a,y:l}),s.current=null},300)},o=n=>{if(!r.current)return;let s=c(n.target);if(!s){e(),t(null);return}t({...s,x:n.clientX,y:n.clientY})},a=()=>{e(),r.current&&t(null)};return document.addEventListener("mouseover",n,!0),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",a),document.addEventListener("mousedown",a),()=>{document.removeEventListener("mouseover",n,!0),document.removeEventListener("mousemove",o),document.removeEventListener("mouseleave",a),document.removeEventListener("mousedown",a),e()}},[]),(0,i.useLayoutEffect)(()=>{if(!e||!o.current)return;let t=o.current.getBoundingClientRect(),r=window.innerWidth,n=window.innerHeight,s=e.x+12,a=e.y+16;s+t.width>r-8&&(s=r-t.width-8),s<8&&(s=8),a+t.height>n-8&&(a=e.y-t.height-8),l({left:s,top:a})},[e]),u&&e)?(0,d.createPortal)((0,n.jsx)("div",{ref:o,className:`fixed z-[10001] max-w-[min(80vw,64rem)] px-2 py-1 bg-tooltip text-tooltip-foreground text-xs ${e.mono?"font-mono ":""}rounded shadow-lv3 border border-line-1 whitespace-pre-wrap break-words pointer-events-none`,style:{left:a.left,top:a.top},children:e.text}),document.body):null}var m=r(79114),x=r(72363),h=r(2111);let f=new Set(["preparing","installing","repairing","rolling-back","restarting"]);function p(){return(0,n.jsxs)("svg",{className:"h-4 w-4 flex-shrink-0 animate-spin text-brand",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:4}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]})}function g(){let{t:e}=(0,m.Bd)(),t=(0,i.useSyncExternalStore)(x.N4,x.fX,x.fX),[r,s]=(0,i.useState)(()=>Date.now()),o=(0,i.useRef)(!1),{stale:a}=function(){let[e,t]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let r=window.__COCKPIT_BUILD_ID__;if(!r)return;let n=!1,s=async()=>{if(!n&&!e)try{let e=await fetch("/api/health",{cache:"no-store",signal:AbortSignal.timeout(3e3)});if(!e.ok)return;let s=await e.json();if(!s.buildId)return;n||s.buildId===r||t(!0)}catch{}},o=(0,h.D)(s);return()=>{n=!0,o()}},[e]),{stale:e}}(),[d,c]=(0,i.useState)(!1),[u,g]=(0,i.useState)(!1);(0,i.useEffect)(()=>{g(window.self===window.top)},[]),(0,i.useEffect)(()=>{u&&!o.current&&(o.current=!0,(0,x.$2)())},[u]);let b=t.visible&&f.has(t.stage);(0,i.useEffect)(()=>{if(!b)return;s(Date.now());let e=window.setInterval(()=>s(Date.now()),1e3);return()=>window.clearInterval(e)},[b]);let v=(0,i.useCallback)(()=>{navigator.clipboard.writeText(t.fixCommand),(0,l.oR)(e("workspace.updateCardFixCopied"))},[t.fixCommand,e]),j=!t.visible&&a&&!d;if(!u||!t.visible&&!j)return null;let w=t.startedAt?Math.max(0,Math.round((r-t.startedAt)/1e3)):0,k=t.baselineMs?Math.round(t.baselineMs/1e3):null,y=j||"done"===t.stage,N=j||!f.has(t.stage),C=y&&!t.upToDate,S=j?e("workspace.serverRestarted"):(()=>{switch(t.stage){case"preparing":return e("workspace.updateCardPreparing");case"installing":return e("workspace.updateCardInstalling");case"repairing":return e("workspace.updateCardRepairing");case"rolling-back":return e("workspace.updateCardRollingBack");case"restarting":return e("workspace.updateCardRestarting");case"done":if(!t.installedVersion)return e("workspace.updateComplete");return t.upToDate?e("workspace.updateCardUpToDate",{version:t.installedVersion}):e("workspace.updateCardDone",{version:t.installedVersion});case"failed":return e("workspace.updateFailed")}})();return(0,n.jsx)("div",{className:"fixed top-4 right-4 z-[110] w-80 rounded-lg border border-border\n bg-background/95 p-3 shadow-lv2 backdrop-blur",role:"status","aria-live":"polite",children:(0,n.jsxs)("div",{className:"flex items-start gap-2.5",children:[b?(0,n.jsx)(p,{}):y?(0,n.jsx)("svg",{className:"h-4 w-4 flex-shrink-0 text-brand",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"h-4 w-4 flex-shrink-0 text-destructive",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v4m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"})}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-sm text-foreground",children:S}),b&&(0,n.jsxs)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:[e("workspace.updateCardElapsed",{seconds:w}),null!==k&&(0,n.jsxs)(n.Fragment,{children:[" \xb7 ",e("workspace.updateCardBaseline",{seconds:k})]})]}),b&&!t.live&&(0,n.jsx)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground/80",children:e("workspace.updateCardNoLiveStatus")}),b&&(0,n.jsx)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:e("workspace.updateRestartNote")}),!j&&"failed"===t.stage&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"mt-1 break-words text-[11px] leading-snug text-muted-foreground",children:t.error}),t.rolledBack&&(0,n.jsx)("div",{className:"mt-1 text-[11px] leading-snug text-muted-foreground",children:e("workspace.updateCardRolledBack")}),(0,n.jsx)("div",{className:"mt-2 text-[11px] leading-snug text-muted-foreground",children:e("workspace.updateCardManualHint")}),(0,n.jsx)("code",{className:"mt-1 block break-all rounded bg-hover px-2 py-1.5 text-[11px]\n leading-snug text-foreground",children:t.fixCommand}),(0,n.jsx)("button",{type:"button",onClick:v,className:"mt-1.5 w-full rounded-md border border-border px-2.5 py-1.5 text-xs\n text-foreground transition-colors hover:bg-hover",children:e("workspace.updateCardCopyFix")}),t.logPath&&(0,n.jsx)("div",{className:"mt-1.5 break-all text-[11px] leading-snug text-muted-foreground/80",children:e("workspace.updateCardLogHint",{path:t.logPath})})]}),C&&(0,n.jsx)("button",{type:"button",onClick:()=>window.location.reload(),className:"mt-2 w-full rounded-md bg-primary px-2.5 py-1.5 text-xs\n text-primary-foreground transition-opacity hover:opacity-90",children:e("workspace.reloadNow")})]}),N&&(0,n.jsx)("button",{type:"button",onClick:()=>{c(!0),j||(0,x.fZ)()},"aria-label":e("common.close"),className:"-mr-1 -mt-1 rounded p-1 text-muted-foreground transition-colors hover:bg-hover",children:(0,n.jsx)("svg",{className:"h-3.5 w-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})})}function b({children:e,initialLanguage:t}){return(0,i.useEffect)(()=>{let e=e=>{e.preventDefault()};return document.addEventListener("contextmenu",e),()=>document.removeEventListener("contextmenu",e)},[]),(0,n.jsx)(o.I18nProvider,{initialLanguage:t,children:(0,n.jsx)(a.NP,{children:(0,n.jsxs)(l.tE,{children:[(0,n.jsx)(s.hc,{}),e,(0,n.jsx)(u,{}),(0,n.jsx)(g,{})]})})})}},41474:(e,t,r)=>{r.d(t,{F:()=>s});var n=r(12115);function s(){let[e,t]=(0,n.useState)(()=>"u"<typeof document||"visible"===document.visibilityState),[r,s]=(0,n.useState)(()=>window.parent===window);return(0,n.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{(e.data?.type==="IFRAME_VISIBILITY"||e.data?.type==="PROJECT_NUMBER")&&"boolean"==typeof e.data.visible&&s(e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e&&r}},42654:(e,t,r)=>{r.d(t,{TabManager:()=>sE});var n=r(95155),s=r(12115),o=r(79114),a=r(8601);let l=(0,s.createContext)(null);function i({value:e,children:t}){return(0,n.jsx)(l.Provider,{value:e,children:t})}var d=r(59461),c=r(47650),u=r(72312),m=r(64428),x=r(86957),h=r(60938),f=r(51145),p=r(53213),g=r(45619),b=r(24602),v=r(5135),j=r(30133),w=r(48661),k=r(88780),y=r(20080);let N=(e,t,r)=>`/api/git/blob?cwd=${encodeURIComponent(e)}&rev=${encodeURIComponent(t)}&file=${encodeURIComponent(r)}`;function C({cwd:e,filePath:t,oldRev:r,newRev:s,newNode:o}){return(0,n.jsx)(y.K,{filePath:t,oldSrc:r?N(e,r,t):null,newSrc:s?N(e,s,t):null,newNode:o})}var S=r(94287),M=r(34075);let L=(0,s.memo)(function({cwd:e,filePath:t,onLocateInTree:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate",title:t,children:t}),(0,n.jsx)(S.m,{content:s("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,M.oR)(s("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),r&&(0,n.jsx)(S.m,{content:s("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),r(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})})]})});var E=r(82292),P=r(47215),T=r(56045);function $({preview:e,onClose:t,search:r,preRef:s}){return(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-[90%] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono truncate",children:e.filePath}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)(T._,{search:r}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-secondary",children:(0,n.jsx)("pre",{ref:s,className:"whitespace-pre-wrap break-words font-mono text-foreground",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:(0,P.xb)(e.content)})})]})})}var R=r(48347),I=r(62111),F=r(61043);function B({isOpen:e,onClose:t,commit:r,cwd:a,embedded:l=!1,initialFilePath:i,onContentSearch:d,onLocateInTree:c}){let{t:u}=(0,o.Bd)(),[m,h]=(0,s.useState)([]),[f,y]=(0,s.useState)([]),[N,S]=(0,s.useState)(new Set),[M,D]=(0,s.useState)(null),[A,H]=(0,s.useState)(null),[W,z]=(0,s.useState)(!1),[O,_]=(0,s.useState)(!1),[q,V]=(0,s.useState)(null),[U,K]=(0,s.useState)(null),[Q,G]=(0,s.useState)(null),J=(0,s.useCallback)(()=>G(null),[]),Y=(0,s.useCallback)(()=>V(null),[]),[X,Z]=(0,s.useState)("compact"),[ee,et]=(0,s.useState)("unified"),er=(0,s.useRef)(null),en=(0,T.o)(er),es=(0,R.r)(),eo=r?.shortHash,ea=(0,s.useCallback)(e=>{eo&&es?.sendMessage(u("explain.commitFileMessage",{hash:eo,path:e}))},[es,u,eo]);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&q){e.preventDefault(),en.open();return}if("Escape"===e.key){if(en.isVisible)return void en.close();if(U)return void K(null);if(Q)return void G(null);if(q)return void V(null);(0,I.k)(),t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,U,Q,q,en]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{h([]),y([]),D(null),H(null),z(!0)}),x.t4.runPromiseExit((0,p.Zi)(a,r.hash)).then(e=>{if("Success"===e._tag){let t=e.value.files??[];h(t);let n=(0,k.Do)(t);if(y(n),S(new Set((0,k.Sz)(n))),i&&t.length>0){let e=t.find(e=>e.path===i);e&&setTimeout(()=>{D(e),x.t4.runPromiseExit((0,p.Zi)(a,r.hash,e.path)).then(e=>{"Success"===e._tag?H(e.value):console.error(e.cause)})},0)}}else console.error(e.cause);z(!1)}))},[e,r,a,i]);let el=(0,s.useCallback)(e=>{r&&(D(e),_(!0),x.t4.runPromiseExit((0,p.Zi)(a,r.hash,e.path)).then(e=>{"Success"===e._tag?H(e.value):console.error(e.cause),_(!1)}))},[a,r]),ei=(0,s.useCallback)(e=>{S(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ed=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,a,l;return e=new Date(r.date),t=new Date,n=e.getFullYear()===t.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),a=String(e.getHours()).padStart(2,"0"),l=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${a}:${l}`:`${e.getFullYear()}-${s}-${o} ${a}:${l}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]),ec=A?.filePath,eu=(0,s.useMemo)(()=>ec?(0,n.jsx)(L,{cwd:a,filePath:ec,onLocateInTree:c}):null,[a,ec,c]);if(!e||!r)return null;let em=!!A&&(!0===A.isImage||(0,E.u)(A.filePath)),ex=(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-2",children:r.subject}),r.body&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground whitespace-pre-wrap mb-3 max-h-32 overflow-y-auto border-l-2 border-border pl-3",children:r.body}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:u("commitDetail.hash")}),(0,n.jsx)("span",{className:"font-mono bg-accent px-1.5 py-0.5 rounded",children:r.hash})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:u("commitDetail.author")}),(0,n.jsx)("span",{children:r.author}),(0,n.jsxs)("span",{className:"text-foreground-subtle",children:["<",r.authorEmail,">"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:u("commitDetail.date")}),(0,n.jsx)("span",{children:ed}),r.relativeDate&&(0,n.jsxs)("span",{className:"text-foreground-subtle",children:["(",r.relativeDate,")"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-foreground-subtle",children:u("commitDetail.files")}),(0,n.jsx)("span",{children:u("commitDetail.nChanges",{count:m.length})})]}),!em&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[(0,n.jsx)(j.y,{value:X,onChange:Z}),(0,n.jsx)(w.q,{value:ee,onChange:et})]})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)(F.q,{children:W?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:u("commitDetail.loadingFiles")}):(0,n.jsxs)(n.Fragment,{children:[m.length>0&&(0,n.jsx)(k.WY,{files:m}),(0,n.jsx)(k.VO,{files:f,selectedPath:M?.path||null,expandedPaths:N,onSelect:e=>e.file&&el(e.file),onToggle:ei,cwd:a,showChanges:!0,showChangeClass:!0,emptyMessage:u("commitDetail.noFileChanges"),className:"py-1",onExplain:es&&eo?ea:void 0,explainDisabled:es?.isLoading})]})}),(0,n.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:O?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:u("commitDetail.loadingDiff")}):A?em?(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)("div",{className:"flex-shrink-0 px-2 py-1 border-b border-border bg-accent",children:eu}),(0,n.jsx)("div",{className:"flex-1 min-h-0",children:(0,n.jsx)(C,{cwd:a,filePath:A.filePath,oldRev:A.oldRev??(A.isNew?null:`${r.hash}^1`),newRev:A.newRev??(A.isDeleted?null:r.hash)})})]}):"unified"===ee?(0,n.jsx)(g.xU,{oldContent:A.oldContent,newContent:A.newContent,filePath:A.filePath,cwd:a,enableComments:!0,compact:"compact"===X,headerLeading:eu,onPreview:A.isDeleted?void 0:(0,P.aR)(A.filePath)?()=>K({content:A.newContent,filePath:A.filePath}):(0,P.e$)(A.filePath)?()=>G({content:A.newContent,filePath:A.filePath}):A.filePath.endsWith(".json")?()=>V({content:A.newContent,filePath:A.filePath}):void 0,previewLabel:A.filePath.endsWith(".json")?u("common.readable"):u("common.preview"),onContentSearch:d}):(0,n.jsx)(g.xZ,{oldContent:A.oldContent,newContent:A.newContent,filePath:A.filePath,isNew:A.isNew,isDeleted:A.isDeleted,cwd:a,enableComments:!0,compact:"compact"===X,headerLeading:eu,onPreview:A.isDeleted?void 0:(0,P.aR)(A.filePath)?()=>K({content:A.newContent,filePath:A.filePath}):(0,P.e$)(A.filePath)?()=>G({content:A.newContent,filePath:A.filePath}):A.filePath.endsWith(".json")?()=>V({content:A.newContent,filePath:A.filePath}):void 0,previewLabel:A.filePath.endsWith(".json")?u("common.readable"):u("common.preview"),onContentSearch:d}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:u("commitDetail.selectFileToView")})})]})]}),eh=q&&(0,n.jsx)($,{preview:q,onClose:Y,search:en,preRef:er}),ef=U&&(0,n.jsx)(b.N,{filePath:U.filePath,content:U.content,cwd:a,onClose:()=>K(null)}),ep=Q&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:J,children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(v.M,{content:Q.content,filePath:Q.filePath,cwd:a,onClose:J})})});return l?(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsx)("button",{onClick:t,className:"absolute top-2 right-2 z-10 p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",title:u("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),ex,eh,ef,ep]}):(0,n.jsx)("div",{className:"fixed inset-0 z-[60] bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card w-full h-full flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:u("commitDetail.title")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),ex,eh,ef,ep]})})}var D=r(64702),A=r(70188),H=r(14575);let W={M:{text:"text-amber-11",bg:"bg-amber-9/20"},A:{text:"text-green-11",bg:"bg-green-9/20"},D:{text:"text-red-11",bg:"bg-red-9/20"},R:{text:"text-blue-11",bg:"bg-blue-9/20"}},z=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:a,onToggle:l,onContextMenu:i,renderActions:d}){let{node:c,level:u,gitStatus:m,hasChangedChildren:x}=e,h=m?W[m]:null,f=(0,s.useCallback)(()=>{c.isDirectory?l(c.path):a(c.path)},[c.isDirectory,c.path,a,l]),p=(0,s.useCallback)(e=>{i(e,c.path,c.isDirectory)},[c.path,c.isDirectory,i]),g=!c.isDirectory&&(".env"===c.name||c.name.startsWith(".env.")),b=m?h.text:x?"text-amber-11":g?"text-yellow-600 dark:text-yellow-500":t&&!c.isDirectory?"text-brand":"text-foreground";return(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 cursor-pointer hover:bg-hover ${t?"bg-brand/10":""}`,style:{paddingLeft:`${12*u+8}px`},onClick:f,onContextMenu:p,children:[c.isDirectory?o?(0,n.jsxs)("svg",{className:"w-4 h-4 flex-shrink-0 text-muted-foreground animate-spin",viewBox:"0 0 16 16",fill:"none",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.3"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 0 0-6-6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}):(0,n.jsx)("svg",{className:`w-4 h-4 flex-shrink-0 text-muted-foreground transition-transform ${r?"rotate-90":""}`,viewBox:"0 0 16 16",fill:"none",children:(0,n.jsx)("path",{d:"M6 4 L10 8 L6 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}):(0,n.jsx)(H.o,{name:c.name,size:16,className:"flex-shrink-0 ml-4"}),(0,n.jsx)("span",{className:`text-sm truncate flex-1 ${b}`,"data-tooltip":c.isSymlink&&c.symlinkTarget?`${c.path} → ${c.symlinkTarget}`:c.path,children:c.name}),c.isSymlink&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:"→"}),m&&(0,n.jsx)("span",{className:`text-xs font-mono px-1 rounded ${h.text} ${h.bg} flex-shrink-0`,children:m}),c.isDirectory&&x&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-9 flex-shrink-0"}),d?.(c)]})});function O({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:a=null,loadingDirs:l,onSelect:i,onToggle:d,cwd:c,shouldScrollToSelected:u=!1,onScrolledToSelected:m,className:x,renderActions:h,onCreateFile:f,onDelete:p,onRefresh:g,onCopyFile:b,onPaste:v,onExplain:j,explainDisabled:w}){let k=(0,s.useRef)(null),{contextMenu:y,showContextMenu:N,hideContextMenu:C}=(0,A.Ee)(),S=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let a=[];for(let l of t){if(null!==n&&!n.has(l.path))continue;let t=s?.get(l.path),i=l.isDirectory?function(e,t){if(!t)return!1;let r=e+"/";for(let e of t.keys())if(e.startsWith(r))return!0;return!1}(l.path,s):void 0;a.push({node:l,level:o,gitStatus:t,hasChangedChildren:i}),l.isDirectory&&l.children&&r.has(l.path)&&a.push(...e(l.children,r,n,s,o+1))}return a})(e,r,o,a),[e,r,o,a]),M=(0,D.Te)({count:S.length,getScrollElement:()=>k.current,estimateSize:()=>26,overscan:10}),L=(0,s.useRef)(m);return(L.current=m,(0,s.useEffect)(()=>{if(u&&t&&S.length>0){let e=S.findIndex(e=>e.node.path===t);if(e>=0){let t=setTimeout(()=>{M.scrollToIndex(e,{align:"center"}),L.current?.()},150);return()=>clearTimeout(t)}}},[u,t,S,M]),0===S.length)?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:"No files"}):(0,n.jsxs)("div",{ref:k,className:x||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${M.getTotalSize()}px`,width:"100%",position:"relative"},children:M.getVirtualItems().map(e=>{let s=S[e.index];return(0,n.jsx)("div",{style:{position:"absolute",top:0,left:0,width:"100%",height:`${e.size}px`,transform:`translateY(${e.start}px)`},children:(0,n.jsx)(z,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:l?.has(s.node.path),onSelect:i,onToggle:d,onContextMenu:N,renderActions:h})},s.node.path)})}),y&&(0,n.jsx)(A.ft,{x:y.x,y:y.y,path:y.path,cwd:c,isDirectory:y.isDirectory,onClose:C,onCreateFile:f,onDelete:p,onRefresh:g,onCopyFile:b,onPaste:v,onExplain:j,explainDisabled:w})]})}var _=r(38408),q=r(32041),V=r(14341),U=r(42804),K=r(22164),Q=r(34582),G=r(86304),J=r(43595),Y=r(88403),X=r(85269);function Z({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),a=o>=0?e.slice(0,o+1):"",l=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],a="",l=!1;for(let s=0;s<e.length;s++){let i=t+s,d=r.has(i);d!==l&&a&&(o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-${s}`):(0,n.jsx)("span",{children:a},`${t}-${s}`)),a=""),l=d,a+=e[s]}return a&&o.push(l?(0,n.jsx)("span",{className:"text-brand font-medium",children:a},`${t}-end`):(0,n.jsx)("span",{children:a},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[a&&i(a,0,"text-muted-foreground"),i(l,a.length,"text-foreground")]})}function ee({files:e,fileIndex:t,recentFiles:r,onSelectFile:a,onClose:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(""),[u,x]=(0,s.useState)(0),h=(0,s.useRef)(null),f=(0,s.useRef)(null),p=(0,s.useMemo)(()=>{let r,n;return t??(r=[],(n=e=>{for(let t of e)t.isDirectory&&t.children?n(t.children):t.isDirectory||r.push(t.path)})(e),r)},[t,e]),g=(0,s.useMemo)(()=>{if(!d.trim()){let e=new Set(r);return[...r.map(e=>({path:e,score:0,matchedIndices:[]})),...p.filter(t=>!e.has(t)).slice(0,50).map(e=>({path:e,score:0,matchedIndices:[]}))]}let e=[];for(let t of p){let n=function(e,t){let r=e.toLowerCase(),n=t.toLowerCase(),s=[],o=0,a=0,l=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),l===i-1&&(a+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(a+=10),i>e.lastIndexOf("/")&&(a+=3),e[i]===t[o]&&(a+=1),l=i,o++);return o<n.length?null:(a-=.1*e.length,{path:e,score:a,matchedIndices:s})}(t,d.trim());n&&(r.includes(t)&&(n.score+=20),e.push(n))}return e.sort((e,t)=>t.score-e.score),e.slice(0,50)},[d,p,r]),b=(0,s.useCallback)(e=>{c(e),x(0)},[]);(0,s.useEffect)(()=>{h.current?.focus()},[]),(0,s.useEffect)(()=>{if(f.current){let e=f.current.children[u];e?.scrollIntoView({block:"nearest"})}},[u]);let v=(0,s.useCallback)(e=>{a(e),l()},[a,l]),j=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing)switch(e.key){case"ArrowDown":e.preventDefault(),x(e=>Math.min(e+1,g.length-1));break;case"ArrowUp":e.preventDefault(),x(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),g[u]&&v(g[u].path);break;case"Escape":e.preventDefault(),l()}},[g,u,v,l]);return(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-start justify-center pt-[15vh]",onClick:l,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-lv3 overflow-hidden flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),(0,n.jsx)("input",{ref:h,value:d,onChange:e=>b(e.target.value),onKeyDown:j,placeholder:i("quickFileOpen.placeholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none",autoComplete:"off",autoCorrect:"off",spellCheck:"false"}),(0,n.jsx)("kbd",{className:"text-[10px] text-muted-foreground px-1.5 py-0.5 rounded border border-border bg-secondary",children:"ESC"})]}),(0,n.jsx)("div",{ref:f,className:"flex-1 overflow-y-auto py-1",children:0===g.length?(0,n.jsx)("div",{className:"px-3 py-8 text-center text-sm text-muted-foreground",children:i("quickFileOpen.noMatch")}):g.map((e,t)=>(0,n.jsxs)("div",{className:`px-3 py-1.5 flex items-center gap-2 cursor-pointer transition-colors ${t===u?"bg-brand/15 text-foreground":"hover:bg-hover text-foreground"}`,"data-tooltip":e.path,onClick:()=>v(e.path),children:[(0,n.jsx)(H.o,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(Z,{path:e.path,matchedIndices:e.matchedIndices}),!d.trim()&&r.includes(e.path)&&(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground px-1.5 py-0.5 rounded bg-secondary flex-shrink-0",children:i("quickFileOpen.recent")})]},e.path))}),(0,n.jsxs)("div",{className:"px-3 py-1.5 border-t border-border flex items-center gap-3 text-[10px] text-muted-foreground",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"↑↓"})," ",i("quickFileOpen.selectHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Enter"})," ",i("quickFileOpen.openHint")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 rounded border border-border bg-secondary",children:"Esc"})," ",i("quickFileOpen.closeHint")]})]})]})})})}var et=r(2111),er=r(41474),en=r(61878),es=r(33210),eo=r(48368),ea=r(91958),el=r(45916),ei=r(31794),ed=r(69048),ec=r(97567),eu=r(68806),em=r(52475);function ex({kind:e,qname:t,className:r}){let s=`${(function(e,t){if("__file__"===t||"__preamble__"===t||t&&t.startsWith("__heading_"))return"text-muted-foreground/60";switch(e){case"function":case"method":return"text-violet-11";case"class":return"text-amber-11";case"interface":return"text-blue-11";default:return"text-muted-foreground/60"}})(e,t)} ${r??""}`.trim();if("__file__"===t)return(0,n.jsx)(eo.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(el.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(ei.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(ed.A,{className:s});case"class":return(0,n.jsx)(ec.A,{className:s});case"interface":return(0,n.jsx)(eu.A,{className:s});default:return(0,n.jsx)(em.A,{className:s})}}var eh=r(49433),ef=r(82680);let ep=new Map,eg=(e,t,r=!1)=>`${e}::${r?"project":"file"}::${t}`;function eb(e){if(!e)return void ep.clear();let t=`${e}::`;for(let e of ep.keys())e.startsWith(t)&&ep.delete(e)}async function ev(e,t,r=!1,n=!1){let s=eg(e,t,n);if(r)eb(e);else{let e=ep.get(s);if(e)return e}let o=eh.$mh({try:async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","1"),n&&s.set("relations","1");let o=await fetch(`/api/projectGraph/file-functions?${s}`);if(404===o.status)return"not-found";if(!o.ok)throw Error((await o.json().catch(()=>({error:`HTTP ${o.status}`}))).error||`HTTP ${o.status}`);return await o.json()},catch:e=>new ef.uV({message:"fetchFileFunctions failed",cause:e})}),a=x.t4.runPromiseExit(o).then(e=>{if("Success"===e._tag)return e.value;let t="Fail"===e.cause._tag?e.cause.error:null,r=t?.cause;if(r instanceof Error)throw r;throw Error(t?.message??"fetchFileFunctions failed")}).finally(()=>{ep.get(s)===a&&ep.delete(s)});return ep.set(s,a),a}function ej(e,t,r=!1){let[n,o]=(0,s.useState)({state:"idle"}),a=(0,s.useRef)(!0);(0,s.useEffect)(()=>(a.current=!0,()=>{a.current=!1}),[]);let l=(0,s.useRef)(""),i=(0,s.useRef)(0),d=(0,s.useCallback)((e,t,n,s=!1,d=r)=>{let c=eg(e,t,r);l.current=c;let u=++i.current;s||o({state:"loading"}),ev(e,t,n,d).then(e=>{a.current&&l.current===c&&i.current===u&&("not-found"===e?o({state:"notFound"}):o({state:"ready",data:e}))}).catch(e=>{a.current&&l.current===c&&i.current===u&&!s&&o({state:"error",message:e.message})})},[r]);(0,s.useEffect)(()=>{e&&t?d(e,t,!1):o({state:"idle"})},[e,t,d]);let c=(0,s.useCallback)(()=>{e&&t&&d(e,t,!0)},[e,t,d]),u=(0,s.useCallback)(()=>{e&&t&&d(e,t,!1,!0)},[e,t,d]),m="ready"===n.state&&!0===n.data.crossFilePending,x=(0,s.useCallback)(()=>{eb(e),t&&d(e,t,!1,!0,!1)},[e,t,d]),h=(0,s.useCallback)(t=>{t?.type==="graphProgress"&&t.data?.cwd===e&&"done"===t.data.phase&&x()},[e,x]);return(0,et.h)({url:`/ws/watch?cwd=${encodeURIComponent(e)}`,onMessage:h,onOpen:x,enabled:m}),{state:n,refresh:c,reload:u}}function ew({cwd:e}){let{t}=(0,o.Bd)(),[r,a]=(0,s.useState)(null);(0,s.useEffect)(()=>{a(null)},[e]);let l=(0,s.useCallback)(t=>{t?.type==="graphProgress"&&t.data&&t.data.cwd===e&&a(t.data)},[e]);(0,et.h)({url:`/ws/watch?cwd=${encodeURIComponent(e)}`,onMessage:l});let i=(0,s.useRef)("");if(r?.currentFile&&(i.current=r.currentFile),!r)return(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:t("blockViewer.fileMode.loading","Loading…")});let d=t(`blockViewer.buildProgress.${r.phase}`,ek[r.phase]),c=Math.max(0,Math.min(100,Math.round(r.percent)));return(0,n.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 px-8",children:(0,n.jsxs)("div",{className:"w-full max-w-md flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex items-baseline justify-between text-xs text-muted-foreground",children:[(0,n.jsx)("span",{children:d}),(0,n.jsx)("span",{className:"tabular-nums",children:"parsing"===r.phase&&r.filesTotal>0?`${r.filesDone} / ${r.filesTotal}`:`${c}%`})]}),(0,n.jsx)("div",{className:"h-1 w-full overflow-hidden rounded-full bg-muted",children:(0,n.jsx)("div",{className:"h-full rounded-full bg-primary transition-[width] duration-150 ease-linear",style:{width:`${c}%`}})}),(0,n.jsx)("div",{className:"h-4 truncate text-left font-mono text-[11px] leading-4 text-muted-foreground/70",dir:"rtl",title:"done"===r.phase?"":i.current,children:"done"===r.phase?"":i.current})]})})}let ek={listing:"Listing files…",contexts:"Reading project config…",parsing:"Parsing files",resolving:"Resolving imports…",edges:"Building call graph…",done:"Finishing up…"};var ey=r(1058),eN=r(90717),eC=r(3238),eS=r(17196);function eM({entries:e,onSelect:t,onClear:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex-1 min-h-0 bg-card flex flex-col","data-testid":"function-history-drawer",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border flex items-center justify-between gap-1",children:[(0,n.jsx)("div",{className:"flex items-center text-xs text-muted-foreground font-mono min-w-0",children:(0,n.jsx)("span",{className:"truncate",children:0===e.length?s("blockViewer.history.title"):`${s("blockViewer.history.title")} \xb7 ${e.length}/15`})}),e.length>0&&(0,n.jsx)(S.m,{content:s("blockViewer.history.clear"),children:(0,n.jsx)("button",{onClick:r,className:"flex-shrink-0 text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-secondary",children:(0,n.jsx)(es.A,{className:"w-3 h-3"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===e.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:s("blockViewer.history.empty")}):e.map((e,r)=>{var s;let o;return(0,n.jsx)(S.m,{content:`${e.qname} \xb7 ${e.filePath}`,children:(0,n.jsxs)("button",{onClick:()=>t(e),className:"w-full text-left px-2 py-1.5 border-b border-border/50 hover:transition-colors group flex items-start gap-1.5",children:[(0,n.jsx)(ex,{kind:e.kind??"unknown",qname:e.qname,className:"w-3 h-3 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-xs font-mono font-medium truncate",children:e.name}),(0,n.jsxs)("div",{className:"text-[10px] text-muted-foreground/70 truncate",children:[(o=(s=e.filePath).lastIndexOf("/"))>=0?s.slice(o+1):s,e.kind&&(0,n.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.kind]})]})]})]})},`${e.filePath}::${e.qname}::${r}`)})})]})}function eL(e,t){let r=e.filter(e=>e.filePath!==t.filePath||e.qname!==t.qname),n=[t,...r];return n.length>15?n.slice(0,15):n}let eE=new Set(["function","class","method"]);function eP(e){return eE.has(e.kind)}function eT({functions:e,counts:t,totalLines:r,currentQname:a,onSelect:l,notIndexed:i,onRebuild:d}){let{t:c}=(0,o.Bd)(),u=(0,s.useMemo)(()=>e.filter(eP),[e]);return(0,n.jsxs)("div",{className:"flex-1 min-h-0 bg-card flex flex-col","data-testid":"file-toc-section",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border text-xs text-muted-foreground tabular-nums truncate",children:[c("blockViewer.toc.title"),u.length>0&&` \xb7 ${u.length}`,null!=r&&` \xb7 ${r} ${c("common.lines")}`]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===u.length?i?(0,n.jsxs)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/80 leading-relaxed flex flex-col gap-2",children:[(0,n.jsx)("span",{className:"italic",children:c("blockViewer.toc.notIndexed")}),d&&(0,n.jsx)("button",{type:"button",onClick:d,className:"self-start px-2 py-1 rounded border border-border bg-secondary/60 hover:bg-secondary text-[10px] text-foreground transition-colors",children:c("blockViewer.refresh")})]}):(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:c("blockViewer.toc.empty")}):u.map(e=>{let r=a===e.qualifiedName,s=t?.get(e.qualifiedName),o=s?[s.in>0&&["in",s.in,"text-amber-11/80"],s.out>0&&["out",s.out,"text-green-11/80"],s.self>0&&["self",s.self,"text-muted-foreground/60"]].filter(Boolean):[];return(0,n.jsx)(S.m,{content:`${e.qualifiedName} \xb7 L${e.declLine}`,children:(0,n.jsxs)("button",{onClick:()=>l(e.qualifiedName,e.startLine),className:`w-full text-left px-2 py-1 transition-colors flex items-start gap-1.5 min-w-0 ${r?"bg-brand/15 hover:bg-brand/20":"hover:bg-secondary/60"}`,children:[(0,n.jsx)(ex,{kind:e.kind,qname:e.qualifiedName,className:"w-3 h-3 flex-shrink-0 mt-0.5"}),(0,n.jsxs)("span",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 min-w-0",children:[(0,n.jsx)("span",{className:`flex-1 min-w-0 text-xs font-mono truncate ${r?"font-semibold text-brand":""}`,children:e.name}),(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground/50 tabular-nums",children:e.endLine-e.startLine+1})]}),o.length>0&&(0,n.jsx)("span",{className:"block text-[10px] font-mono truncate",children:o.map(([e,t,r],s)=>(0,n.jsxs)("span",{className:r,children:[s>0&&(0,n.jsx)("span",{className:"text-muted-foreground/30",children:" \xb7 "}),e," ",t]},e))})]})]})},e.qualifiedName)})})]})}var e$=r(27570),eR=r(96035);function eI({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,rowOf:a,onCommentClick:l}){let i=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=i.get(n.endLine);e?e.push(n):i.set(n.endLine,[n])}return 0===i.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(i.entries()).map(([e,r])=>{let i=a?a(e):e-t,d=r[0],c=r.length-1;return(0,n.jsx)(S.m,{content:1===r.length?d.content:`${r.length} comments — click to view`,children:(0,n.jsxs)("button",{onClick:e=>l(d,e),className:"pointer-events-auto absolute right-1 w-4 h-4 rounded-full bg-amber-9/70 hover:bg-amber-11 text-white flex items-center justify-center shadow-lv1 transition-colors",style:{top:`${o+i*s+s/2-8}px`},children:[(0,n.jsx)(eR.A,{className:"w-2.5 h-2.5"}),c>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 bg-amber-11 text-white rounded-full text-[8px] leading-none w-3 h-3 flex items-center justify-center",children:c+1})]})},e)})})}function eF(e,t){for(let r=0;r<e.blocks.length;r++){let n=e.blocks[r];if(t>=n.startLine&&t<=n.endLine)return e.prefix[r]+(t-n.startLine)}return null}function eB({addedLines:e,blockRanges:t,viewportRange:r,onJumpToLine:o}){let a,l=(0,s.useRef)(null),i=(0,s.useMemo)(()=>(function(e){let t=[...e].sort((e,t)=>e.startLine-t.startLine),r=[0];for(let e of t){let t=Math.max(0,e.endLine-e.startLine+1);r.push(r[r.length-1]+t)}return{blocks:t,prefix:r,total:r[r.length-1]}})(t),[t]),d=(0,s.useMemo)(()=>{if(i.total<=0||0===e.size)return[];let t=[];for(let r of e){let e=i.blocks.find(e=>r>=e.startLine&&r<=e.endLine);e&&t.push({line:r,qname:e.qname})}t.sort((e,t)=>e.line-t.line);let r=[],n=null;for(let e of t)n&&e.line===n.end+1&&e.qname===n.qname?n.end=e.line:(n&&r.push(n),n={start:e.line,end:e.line,qname:e.qname});return n&&r.push(n),r},[e,i]);if(i.total<=0)return null;let c=(e,t)=>{let r=eF(i,e),n=eF(i,t);return null===r||null===n?null:{top:r/i.total*100,heightPct:(n-r+1)/i.total*100}};return(0,n.jsxs)("div",{ref:l,onClick:e=>{let t=l.current;if(!t)return;let r=t.getBoundingClientRect();if(r.height<=0)return;let n=function(e,t){if(e.total<=0)return null;let r=Math.max(0,Math.min(e.total-1,t));for(let t=0;t<e.blocks.length;t++){let n=e.prefix[t],s=e.prefix[t+1];if(r>=n&&r<s){let s=e.blocks[t];return{qname:s.qname,line:s.startLine+Math.round(r-n)}}}return null}(i,(e.clientY-r.top)/r.height*i.total);if(!n)return;let s=n.line,a=d.find(e=>e.qname===n.qname&&s>=e.start&&s<=e.end);if(a)return void o(a.qname,s);if(d.length>0){let e=Math.max(2,Math.round(.05*i.total)),t=eF(i,s);if(null!==t){let r=null,n=1/0;for(let e of d){let s=eF(i,e.start),o=eF(i,e.end);if(null===s||null===o)continue;let a=t<s?s-t:t>o?t-o:0;a<n&&(r=e,n=a)}if(r&&n<=e){let e=s<r.start?r.start:s>r.end?r.end:s;o(r.qname,e);return}}}let c=i.blocks.find(e=>e.qname===n.qname);c&&o(c.qname,c.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[d.map(e=>{let t=c(e.start,e.end);return t?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-green-9 pointer-events-none",style:{top:`${t.top}%`,height:`${t.heightPct}%`,minHeight:"2px"}},`run:${e.qname}:${e.start}-${e.end}`):null}),r&&r.end>=r.start&&((a=c(r.start,r.end))?(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border pointer-events-none",style:{top:`${a.top}%`,height:`${Math.max(1.2,a.heightPct)}%`}}):null)]})}var eD=r(19502),eA=r(89109),eH=r(7320),eW=r(37614);let ez={state:"loading"};function eO(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function e_(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}let eq="flex-shrink-0 h-4 leading-4 px-1.5 rounded text-[10px] text-brand hover:bg-brand/10 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-transparent";function eV({symbol:e,fileSource:t,hasChange:r,onHighlighted:a,comments:l,onCommentClick:i,addedLines:d,upstream:c,downstream:u,fold:m,onExpandGap:x}){let{resolvedTheme:h}=(0,eC.DP)(),{t:f}=(0,o.Bd)(),p=(0,R.r)(),g=(c?.length??0)+(u?.length??0)>0,b=(0,s.useMemo)(()=>(0,eS.sQ)(e.filePath),[e.filePath]),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!t)return void j(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,eS.kS)()).codeToTokens(n,{lang:b,theme:"dark"===h?"github-dark":"github-light"});r||(j(s.tokens.map(e=>(0,eS.b8)(e))),k(null))}catch(e){r||k(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,b,h]);let y=(0,s.useMemo)(()=>{if(!v)return null;let t=t=>{let r=v[t-e.startLine]??"",n=d?.has(t)?" bg-green-9/15":"";return`<div class="flex${n}" style="min-width:max-content" data-line="${t}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${t}</span><span class="whitespace-pre">${r}</span></div>`};return m?m.segments.map(e=>{if("gap"===e.kind){var r;let t,n,s;return r=e.startLine,n=e_(f("diffViewer.gap.hidden",{count:t=e.endLine-r+1})),s=e_(f("diffViewer.gap.expandAll",{count:t})),`<div class="flex items-center cursor-pointer select-none hover:bg-hover" style="min-width:max-content;height:${eQ}px" data-fold-gap="${r}" title="${s}"><span class="select-none pr-3 text-muted-foreground/40" style="min-width:3.2rem;text-align:right">⋯</span><span class="text-[10px] text-muted-foreground/60 whitespace-pre">${n}</span></div>`}let n="";for(let r=e.startLine;r<=e.endLine;r++)n+=t(r);return n}).join(""):v.map((r,n)=>t(e.startLine+n)).join("")},[v,m,d,e.startLine,f]);(0,s.useEffect)(()=>{(null!==v||null!==w)&&a(e.qualifiedName)},[v,w,e.qualifiedName,a]);let N=(0,s.useCallback)(t=>{if(!x)return;let r=t.target,n=r?.closest?.("[data-fold-gap]");if(!n)return;let s=Number(n.getAttribute("data-fold-gap"));Number.isFinite(s)&&x(e.qualifiedName,s)},[x,e.qualifiedName]);return(0,n.jsxs)("div",{className:"flex-1 min-w-0 bg-card border border-border rounded overflow-hidden relative",children:[(0,n.jsxs)("div",{"data-block-header":!0,className:"flex items-center gap-1.5 px-2 py-1.5 border-b border-border text-xs",children:[(0,n.jsx)(ex,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),!e.qualifiedName.startsWith("__code_")&&(0,n.jsxs)("span",{className:"font-mono truncate min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:e.name}),void 0!==e.params&&(0,n.jsxs)("span",{className:"text-muted-foreground/80",children:["(",e.params.join(", "),")"]})]}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground/70 flex-shrink-0",children:["unknown"!==e.kind&&`${e.kind} \xb7 `,e.endLine-e.startLine+1," ",f("common.lines")]}),p&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>p.sendMessage(f("explain.symbolMessage",{name:e.name,path:e.filePath,lines:`${e.startLine}-${e.endLine}`})),disabled:p.isLoading,title:p.isLoading?f("comments.aiResponding"):void 0,className:eq,children:f("explain.action")}),g&&(0,n.jsx)("button",{onClick:()=>p.sendMessage(f("deps.symbolMessage",{name:e.name,path:e.filePath,lines:`${e.startLine}-${e.endLine}`,...function(e,t,r){let n=e=>{switch(e.kind){case"cross":case"self":return`${e.external.name} (${e.external.filePath})`;case"method":return`${e.receiverName}.${e.methodName}()`;case"ext":return null}},s=e=>{let t=e.map(n).filter(e=>null!==e);return t.length?t.join(", "):r},o=new Map;for(let e of t){if("ext"!==e.kind)continue;let t=o.get(e.packageSpec);t?t.push(e.name):o.set(e.packageSpec,[e.name])}let a=[...o].map(([e,t])=>`${e} (${t.join(", ")})`);return{callers:s(e),callees:s(t),externals:a.length?a.join("; "):r}}(c??[],u??[],f("deps.none"))})),disabled:p.isLoading,title:p.isLoading?f("comments.aiResponding"):void 0,className:eq,children:f("deps.action")})]}),(0,n.jsx)("span",{className:"flex-1"}),r&&(0,n.jsx)("span",{className:"flex-shrink-0 w-2 h-2 rounded-full bg-amber-11","data-tooltip":"File has uncommitted change"})]}),(0,n.jsxs)("div",{"data-block-body":!0,className:"text-[11px] font-mono px-2 py-2 overflow-auto",style:{lineHeight:`${eQ}px`},onClick:N,children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),w&&(0,n.jsx)("span",{className:"text-red-11",children:w}),y&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:y}})]}),l&&l.length>0&&i&&(0,n.jsx)(eI,{comments:l,startLine:e.startLine,endLine:e.endLine,lineHeight:eQ,bodyTopOffset:eG+eJ,rowOf:m?.rowOf,onCommentClick:i})]})}function eU({side:e,pin:t,accent:r,onClick:s}){let o,a,l,i,d,c,u,m=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="ext",l="text-muted-foreground/60",i=t.name,d=t.packageSpec,c="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",a="method",l="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,d=null,c="method (unresolved)",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):"self"===t.kind?(o="bg-secondary/40 border-border hover:border-muted-foreground",a="self",l="text-muted-foreground/70",i=t.external.name,d=null,c="same-file",u=m>0?`at line${m>1?"s":""} ${t.lines.join(", ")}`:""):(o="in"===e?"bg-amber-9/15 border-amber-9/40 hover:border-amber-11":"bg-green-9/15 border-green-9/40 hover:border-green-11",a=e,l="in"===e?"text-amber-11":"text-green-11",i=t.external.name,d=eO(t.external.filePath),c="in"===e?"caller":"callee",u=t.external.filePath);let x=r&&"ext"!==t.kind&&"method"!==t.kind?" ring-1 ring-amber-9/70 ring-offset-0":"";return(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),s()},className:`${o}${x} w-full text-left border rounded px-1.5 py-0.5 text-[10px] font-mono cursor-pointer transition-colors block`,"data-tooltip":`${c} \xb7 ${i}${u?" \xb7 "+u:""}`,children:(0,n.jsxs)("span",{className:"block h-[26px] leading-[13px] overflow-hidden",children:[(0,n.jsx)("span",{className:`${l} float-left mr-1.5 text-[9px] uppercase tracking-wider font-semibold`,children:a}),(d||m>1)&&(0,n.jsxs)("span",{className:"float-right clear-both ml-1.5 max-w-[60%] truncate text-muted-foreground/70",children:[d,m>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60",children:[d?" ":"","\xb7",m,"\xd7"]})]}),(0,n.jsx)("span",{className:"font-medium break-all",children:i})]})})}let eK="w-44 @min-[900px]:w-52 @min-[1100px]:w-60 @min-[1400px]:w-72 @min-[1800px]:w-80 @min-[2400px]:w-96",eQ=18,eG=29,eJ=8;function eY(e,t){switch(t.kind){case"cross":return`${e}:x:${t.external.filePath}::${t.external.qualifiedName}`;case"self":return`${e}:s:${t.external.filePath}::${t.external.qualifiedName}`;case"ext":return`${e}:e:${t.packageSpec}::${t.name}`;case"method":return`${e}:m:${t.receiverName}::${t.methodName}`}}function eX(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function eZ(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function e0({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:a,onHighlighted:l,comments:i,onCommentClick:d,accentQnames:c,addedLines:u,fold:m,onExpandGap:x}){let h=function(e,t,r){if(0===e.length)return[];let n=e.map((e,r)=>{var n,s;return{i:r,line:(n=e.lines[0]??t.startLine,s=t.startLine,Math.max(s,Math.min(t.endLine,n)))}});n.sort((e,t)=>e.line-t.line||e.i-t.i);let s=Array(e.length).fill(0),o=-1/0;for(let{i:e,line:a}of n){let n=Math.max(eG+eJ+(r?r.rowOf(a):a-t.startLine)*eQ,o);s[e]=n,o=n+34}return s}(o,e,m);return(0,n.jsxs)("div",{"data-block-qname":e.qualifiedName,"data-start-line":e.startLine,"data-end-line":e.endLine,className:"flex gap-2 items-stretch scroll-mt-2",children:[(0,n.jsx)("div",{className:`${eK} flex-shrink-0 flex flex-col gap-1 pt-1`,children:0===s.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5",children:"no callers"}):s.map(t=>(0,n.jsx)(eU,{side:"in",pin:t,accent:eX(t,c),onClick:()=>a(t,e)},eY("in",t)))}),(0,n.jsx)(eV,{symbol:e,fileSource:t,hasChange:r,onHighlighted:l,comments:i,onCommentClick:d,addedLines:u,upstream:s,downstream:o,fold:m,onExpandGap:x}),(0,n.jsx)("div",{className:`${eK} flex-shrink-0 relative`,children:0===o.length?(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground/40 italic px-1.5 pt-1",children:"no callees"}):o.map((t,r)=>(0,n.jsx)("div",{className:"absolute left-0 right-0",style:{top:`${h[r]}px`},children:(0,n.jsx)(eU,{side:"out",pin:t,accent:eX(t,c),onClick:()=>a(t,e)})},eY("out",t)))})]})}function e1({cwd:e,onSelect:t,onClose:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(""),[d,c]=(0,s.useState)({files:[],symbols:[]}),[u,m]=(0,s.useState)(0),[h,f]=(0,s.useState)(!1),g=(0,s.useMemo)(()=>[...d.files,...d.symbols],[d]);(0,s.useEffect)(()=>{let t=l.trim();if(!t)return void c({files:[],symbols:[]});f(!0);let r=setTimeout(async()=>{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await x.t4.runPromiseExit((0,p.MB)(r));"Success"===n._tag&&(c(n.value),m(0)),f(!1)},120);return()=>clearTimeout(r)},[l,e]);let b=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==g.length){if("ArrowDown"===e.key)e.preventDefault(),m(e=>Math.min(e+1,g.length-1));else if("ArrowUp"===e.key)e.preventDefault(),m(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=g[u];r&&t(r)}}},[g,u,r,t]);return(0,n.jsx)("div",{className:"absolute inset-0 bg-background/40 z-20 flex items-start justify-center pt-24",onClick:r,children:(0,n.jsxs)("div",{className:"w-[480px] max-w-[80%] bg-card border border-border rounded shadow-lv3 overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-border",children:[(0,n.jsx)(en.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:l,onChange:e=>i(e.target.value),onKeyDown:b,placeholder:a("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),h&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"…"}),(0,n.jsx)("button",{onClick:r,className:"text-muted-foreground hover:text-foreground",children:(0,n.jsx)(es.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===g.length&&l&&!h&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:a("blockViewer.search.noResults","No matches")}),(0,n.jsx)(e2,{label:a("blockViewer.search.files","Files"),hits:d.files,startIdx:0,activeIdx:u,onSelect:t,setActive:m}),(0,n.jsx)(e2,{label:a("blockViewer.search.symbols","Symbols"),hits:d.symbols,startIdx:d.files.length,activeIdx:u,onSelect:t,setActive:m})]})]})})}function e2({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:a}){return 0===t.length?null:(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-secondary/40",children:e}),t.map((e,t)=>{let l=r+t,i=l===s;return(0,n.jsxs)("button",{onMouseEnter:()=>a(l),onClick:()=>o(e),className:`w-full text-left px-3 py-1.5 text-xs flex items-start gap-2 ${i?"bg-secondary":"hover:bg-secondary/60"}`,children:["file"===e.type?(0,n.jsx)(eo.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(ex,{kind:e.target.kind,qname:e.target.qualifiedName,className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"font-mono truncate",children:e.label}),e.hint&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground truncate",children:e.hint})]})]},`${e.type}:${e.label}:${t}`)})]})}function e5({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:a,enableComments:l=!1,onContentSearch:i,onFocalChange:d,qnameFilter:c,qnameFilterFile:u,accentQnames:m,accentFile:f,addedLines:p,addedLinesFile:g,compact:b=!1,headerExtraLeft:v,headerExtraRight:j}){let{t:w}=(0,o.Bd)(),[k,y]=(0,s.useState)("toc"),[N,C]=(0,s.useState)(null),S=N??t??null;(0,s.useEffect)(()=>{C(null)},[t]),(0,s.useEffect)(()=>{d?.(S)},[S,d]);let{state:M,refresh:L,reload:E}=ej(e,S,!0),P="ready"===M.state&&M.data.crossFilePending?ez:M,[T,$]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!S)return void $(null);let t=!1;return $(null),(async()=>{let r=new URLSearchParams({cwd:e,path:S}),n=await x.t4.runPromiseExit((0,h.eA)(r));t||("Success"===n._tag?$({content:n.value.content,mtimeMs:n.value.mtimeMs}):console.error("[BlockViewer] failed to load file source for",S,n.cause))})(),()=>{t=!0}},[e,S]);let I=(0,s.useMemo)(()=>T?T.content.split("\n").length:null,[T]),F=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!T||"ready"!==P.state)return;let e=P.data.mtimeMs;!e||T.mtimeMs<=e||F.current!==T.mtimeMs&&(F.current=T.mtimeMs,E())},[T,P,E]);let[B,D]=(0,s.useState)([]),[A,H]=(0,s.useState)(!1),[W,z]=(0,s.useState)(null),O=(0,s.useRef)(0),_=(0,s.useRef)(0),[q,V]=(0,s.useState)(()=>new Set),U="ready"===P.state?P.data.filePath:null;(0,s.useEffect)(()=>{V(new Set)},[U]);let K=(0,s.useCallback)(e=>{V(t=>{if(t.has(e))return t;let r=new Set(t);return r.add(e),r})},[]);(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),H(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let Q=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;O.current+=1,z({filePath:e,qname:"__imports__",nonce:O.current});return}let r=eZ(t),n=eZ(e.external);D(e=>eL(eL(e,r),n)),C(n.filePath),O.current+=1,z({filePath:n.filePath,qname:n.qname,nonce:O.current})},[]),G=(0,s.useCallback)(e=>{C(e.filePath),O.current+=1,z({filePath:e.filePath,qname:e.qname,nonce:O.current})},[]),J=(0,s.useCallback)(e=>{H(!1),C(e.target.filePath),"symbol"===e.type&&(O.current+=1,z({filePath:e.target.filePath,qname:e.target.qualifiedName,line:e.target.startLine,nonce:O.current}))},[]),Y=(0,s.useCallback)((e,t)=>{S&&(O.current+=1,z({filePath:S,qname:e,line:t,nonce:O.current}))},[S]),[X,Z]=(0,s.useState)(()=>new Set),ee=(0,s.useCallback)((e,t)=>{Z(r=>{let n=new Set(r);return n.add(`${S}#${e}#${t}`),n})},[S]),[et,er]=(0,s.useState)(null),[en,es]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!et)return;let e=null,t=()=>{e=null;let t=et.getBoundingClientRect();if(t.height<=0)return;let r=et.querySelectorAll("[data-block-qname]"),n=1/0,s=-1/0;r.forEach(e=>{let r=e.dataset.startLine,o=e.dataset.endLine;if(!r||!o)return;let a=Number(r),l=Number(o);if(!Number.isFinite(a)||!Number.isFinite(l))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let d=Math.max(0,t.top-i.top),c=Math.min(i.height,t.bottom-i.top),u=l-a+1,m=Math.floor(d/i.height*u),x=Math.ceil(c/i.height*u)-1,h=a+Math.max(0,m),f=a+Math.min(u-1,Math.max(0,x));h<n&&(n=h),f>s&&(s=f)}),n===1/0||s===-1/0?es(null):es(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),et.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(et);let s=new MutationObserver(r);return s.observe(et,{childList:!0,subtree:!0}),()=>{et.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[et]);let eo=(0,s.useMemo)(()=>{if("ready"!==P.state||!en)return null;let e=P.data.functions;if(0===e.length)return null;let t=(en.start+en.end)/2;for(let r of e)if(r.startLine<=t&&t<=r.endLine)return r.qualifiedName;let r=null;for(let t of e)t.startLine<=en.start&&(!r||t.startLine>r.startLine)&&(r=t);return r?.qualifiedName??null},[P,en]),ea=l&&!!e&&!!S,el=(0,R.r)(),{comments:ei,addComment:ed,updateComment:ec,deleteComment:eu,refresh:em}=(0,ey._)({cwd:e,filePath:S??""}),[ex,eh]=(0,s.useState)(null),{toolbarRef:ef,bumpRef:ep,clearToolbar:eg}=(0,e$.L)({enabled:ea,container:ex,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,r=t?.closest("[data-line]");if(!r||!ex||!ex.contains(r))return null;let n=r.getAttribute("data-line");if(!n)return null;let s=parseInt(n,10);return Number.isFinite(s)?{start:s,end:s}:null},buildLineSnapshot:({start:e,end:t})=>{let r=T?.content;return r?r.split("\n").slice(e-1,t).join("\n"):""}}),[eb,ev]=(0,s.useState)(null),[ek,eC]=(0,s.useState)(null),[eS,eE]=(0,s.useState)(null),eP=(0,s.useCallback)(()=>{let e=ef.current;e&&(ev({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),eg())},[eg,ef]),eR=(0,s.useCallback)(()=>{let e=ef.current;e&&(eC({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),eg())},[eg,ef]),eI=(0,s.useCallback)(()=>{let e=ef.current;e&&el&&S&&(eg(),(0,eN.Ff)(el.sendMessage,{filePath:S,startLine:e.range.start,endLine:e.range.end,codeContent:e.lineSnapshot},w("explain.selectionMessage")))},[el,S,eg,ef,w]),eF=(0,s.useCallback)(()=>{let e=ef.current;if(!e||!i)return;let t=e.selectedText.trim();eg(),t&&i(t)},[i,eg,ef]),e_=(0,s.useCallback)(async e=>{eb&&(await ed(eb.range.start,eb.range.end,e,eb.selectedText),ev(null))},[eb,ed]),eq=(0,s.useCallback)(async(t,r)=>{if(el&&e&&S)try{let n=(await (0,eN.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));n.push({filePath:S,startLine:t.range.start,endLine:t.range.end,codeContent:t.lineSnapshot});let s=(0,eN.Gw)(n,r);el.sendMessage(s),await (0,eN.RP)(e),em()}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[el,e,S,em]),eV=(0,s.useCallback)(e=>{ek&&eq(ek,e)},[ek,eq]),eU=(0,s.useCallback)(e=>{eb&&eq(eb,e)},[eb,eq]),eQ=(0,s.useCallback)((e,t)=>{t.stopPropagation(),eE({comment:e,x:t.clientX,y:t.clientY}),eg(),ev(null),eC(null)},[eg]);if((0,s.useEffect)(()=>{if(!W||_.current>=W.nonce||"ready"!==P.state||!T||P.data.filePath!==W.filePath)return;let e=Math.max(1,new Set((u===P.data.filePath&&c?P.data.functions.filter(e=>c.has(e.qualifiedName)):P.data.functions).map(e=>e.qualifiedName)).size);if(q.size<e)return;_.current=W.nonce;let t=null,r=requestAnimationFrame(()=>{let e=W.qname.indexOf(">"),r=e>=0?W.qname.slice(0,e):W.qname,n=document.querySelector(`[data-block-qname="${CSS.escape(r)}"]`);if(!n)return;if("number"==typeof W.line){let e=n.querySelector(`[data-line="${W.line}"]`);if(e instanceof HTMLElement){e.scrollIntoView({behavior:"instant",block:"center"}),e.classList.remove("line-flash"),e.offsetWidth,e.classList.add("line-flash"),t=window.setTimeout(()=>{e.classList.remove("line-flash")},1700);return}}n.scrollIntoView({behavior:"instant",block:"start"});let s=n.querySelector("[data-block-header]");s instanceof HTMLElement&&(s.classList.remove("block-flash"),s.offsetWidth,s.classList.add("block-flash"),t=window.setTimeout(()=>{s.classList.remove("block-flash")},1700))});return()=>{cancelAnimationFrame(r),null!==t&&window.clearTimeout(t)}},[W,P,T,q,c,u]),!S)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e3,{focalFile:null,fileCount:null,onSwitchToCode:a,onSearch:()=>H(!0),onRefresh:L,refreshDisabled:!0,extraLeft:v,extraRight:j}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-sm text-muted-foreground gap-2 px-4 text-center",children:[(0,n.jsx)("span",{children:w("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:w("blockViewer.empty.hint","or press ⌘K to search.")})]}),A&&(0,n.jsx)(e1,{cwd:e,onSelect:J,onClose:()=>H(!1)})]});if("idle"===P.state||"loading"===P.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e3,{focalFile:S,fileCount:null,onSwitchToCode:a,onSearch:()=>H(!0),onRefresh:L,refreshDisabled:!0,extraLeft:v,extraRight:j}),(0,n.jsx)(ew,{cwd:e})]});if("notFound"===P.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e3,{focalFile:S,fileCount:null,onSwitchToCode:a,onSearch:()=>H(!0),onRefresh:L,extraLeft:v,extraRight:j}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:w("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),A&&(0,n.jsx)(e1,{cwd:e,onSelect:J,onClose:()=>H(!1)})]});if("error"===P.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e3,{focalFile:S,fileCount:null,onSwitchToCode:a,onSearch:()=>H(!0),onRefresh:L,extraLeft:v,extraRight:j}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-sm",children:[(0,n.jsx)("span",{className:"text-red-11",children:P.message}),(0,n.jsx)("button",{onClick:L,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:w("blockViewer.retry","Retry")})]})]});let eG=P.data,eJ=eG.functions;if(0===eJ.length&&T){let e=Math.max(1,I??1);eJ=[{filePath:eG.filePath,qualifiedName:"__file__",name:eO(eG.filePath),kind:"unknown",startLine:1,endLine:e,declLine:1}]}let eY=u&&u===eG.filePath,eX=f&&f===eG.filePath,e2=g&&g===eG.filePath;eY&&c&&(eJ=eJ.filter(e=>c.has(e.qualifiedName)));let e6=eX?m:void 0,e8=e2?p:void 0,e9=new Map;if(b&&e8)for(let e of eJ)e9.set(e.qualifiedName,function(e,t,r,n,s=eD.aj){if(t<e)return null;let o=[];for(let n of r)n>=e&&n<=t&&o.push(n);o.sort((e,t)=>e-t);let a=[];for(let r of o){let n=Math.max(e,r-s),o=Math.min(t,r+s),l=a[a.length-1];l&&n<=l.endLine+1?o>l.endLine&&(l.endLine=o):a.push({startLine:n,endLine:o})}let l=[],i=e;for(let e of a)e.startLine>i&&l.push({startLine:i,endLine:e.startLine-1}),i=e.endLine+1;i<=t&&l.push({startLine:i,endLine:t});let d=[],c=[];for(let e of l)e.endLine-e.startLine+1<2||n(e.startLine)?c.push(e):d.push(e);if(0===d.length)return null;a=function(e){let t=[...e].sort((e,t)=>e.startLine-t.startLine),r=[];for(let e of t){let t=r[r.length-1];t&&e.startLine<=t.endLine+1?e.endLine>t.endLine&&(t.endLine=e.endLine):r.push({...e})}return r}([...a,...c]);let u=[];for(let e of[...a.map(e=>({kind:"lines",...e})),...d.map(e=>({kind:"gap",...e}))].sort((e,t)=>e.startLine-t.startLine))u.push(e);let m=[],x=0;for(let e of u)m.push(x),x+="gap"===e.kind?1:e.endLine-e.startLine+1;let h=x;return{segments:u,visibleRuns:a,hiddenCount:d.reduce((e,t)=>e+(t.endLine-t.startLine+1),0),rowOf:t=>{for(let e=0;e<u.length;e++){let r=u[e];if(t<r.startLine)break;if(t<=r.endLine)return"gap"===r.kind?m[e]:m[e]+(t-r.startLine)}return t<e?0:Math.max(0,h-1)}}}(e.startLine,e.endLine,e8,t=>X.has(`${eG.filePath}#${e.qualifiedName}#${t}`)));let e7=e4(eG.upstreamCalls),te=e4(eG.downstreamCalls),tt=new Map(eJ.map(e=>[e.qualifiedName,e])),tr=new Map,tn=new Map;for(let e of eG.intraCalls){let t=tt.get(e.to),r=tt.get(e.from);if(t){let r=tr.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):tr.set(e.from,[n])}if(r){let t=tn.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):tn.set(e.to,[n])}}let ts=new Map;for(let e of eG.externalCalls??[]){let t=ts.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):ts.set(e.focalQname,[r])}let to=new Map;for(let e of eG.methodCalls??[]){let t=to.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):to.set(e.focalQname,[r])}let ta=new Map;for(let e of eJ){let t=e.qualifiedName,r={in:e7.get(t)?.length??0,out:te.get(t)?.length??0,self:(tn.get(t)?.length??0)+(tr.get(t)?.length??0)};(r.in||r.out||r.self)&&ta.set(t,r)}let tl=r.has(eG.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(e3,{focalFile:S,fileCount:eG.fileCount,functionCount:eG.functions.length,upstreamCount:eG.upstreamCalls.length,downstreamCount:eG.downstreamCalls.length,onSwitchToCode:a,onSearch:()=>H(!0),onRefresh:L,extraLeft:v,extraRight:j}),(0,n.jsxs)("div",{ref:eh,className:"@container flex-1 relative min-h-0 flex",children:[(eG.crossFileStale||eG.indexUpdateError)&&(0,n.jsx)("div",{className:"absolute top-0 right-0 z-10 px-2 py-1 text-xs bg-background text-muted-foreground border border-border rounded",children:eG.indexUpdateError??w("blockViewer.relationsStale","Project relations need a refresh")}),(0,n.jsxs)("div",{className:`${eK} flex-shrink-0 border-r border-border flex flex-col`,children:[(0,n.jsx)("div",{className:"flex-shrink-0 flex border-b border-border",children:[["toc",w("blockViewer.tabs.toc")],["history",w("blockViewer.tabs.history")]].map(([e,t])=>(0,n.jsx)("button",{onClick:()=>y(e),className:`flex-1 px-2 py-1.5 text-xs font-medium transition-colors ${k===e?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground"}`,children:t},e))}),(0,n.jsx)("div",{className:"toc"===k?"flex-1 min-h-0 flex flex-col":"hidden",children:(0,n.jsx)(eT,{functions:eJ,counts:ta,totalLines:I,currentQname:eo,onSelect:Y,notIndexed:eG.notIndexed,onRebuild:L})}),(0,n.jsx)("div",{className:"history"===k?"flex-1 min-h-0 flex flex-col":"hidden",children:(0,n.jsx)(eM,{entries:B,onSelect:G,onClear:()=>D([])})})]}),(0,n.jsx)("div",{ref:er,className:"@container flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:eJ.map(e=>{let t,r,s,o,a,l;return(0,n.jsx)(e0,{symbol:e,fileSource:T?.content??null,hasChange:tl,upstream:(t=e7.get(e.qualifiedName),r=tn.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=te.get(e.qualifiedName),o=tr.get(e.qualifiedName),a=to.get(e.qualifiedName),l=ts.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...a??[],...l??[]]),onPinClick:Q,onHighlighted:K,comments:ea?ei:void 0,onCommentClick:ea?eQ:void 0,accentQnames:e6,addedLines:e8,fold:e9.get(e.qualifiedName),onExpandGap:ee},`${e.qualifiedName}#${e.startLine}`)})})}),ea&&ex&&(0,n.jsx)(eA.fS,{floatingToolbarRef:ef,bumpRef:ep,container:ex,onAddComment:eP,onSendToAI:eR,onSearch:i?eF:void 0,onExplain:el&&S?eI:void 0,isChatLoading:el?.isLoading}),ea&&eb&&(0,n.jsx)(eH.t,{x:eb.x,y:eb.y,range:eb.range,filePath:S??void 0,lineSnapshot:eb.lineSnapshot,container:ex,onSubmit:e_,onSendToAI:el&&S?eU:void 0,onClose:()=>ev(null),isChatLoading:el?.isLoading}),ea&&ek&&S&&(0,n.jsx)(eH.G,{x:ek.x,y:ek.y,range:ek.range,filePath:S,lineSnapshot:ek.lineSnapshot,container:ex,onSubmit:eV,onClose:()=>eC(null),isChatLoading:el?.isLoading}),ea&&eS&&(0,n.jsx)(eW.t,{x:eS.x,y:eS.y,comment:eS.comment,container:ex,onClose:()=>eE(null),onUpdateComment:ec,onDeleteComment:eu}),e8&&e8.size>0&&eJ.length>0&&(0,n.jsx)(eB,{addedLines:e8,blockRanges:eJ.flatMap(e=>{let t=e9.get(e.qualifiedName);return t?t.visibleRuns.map(t=>({qname:e.qualifiedName,startLine:t.startLine,endLine:t.endLine})):[{qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine}]}),viewportRange:en,onJumpToLine:Y}),A&&(0,n.jsx)(e1,{cwd:e,onSelect:J,onClose:()=>H(!1)})]})]})}function e4(e){let t=new Map;for(let r of e){let e=t.get(r.focalQname);if(!e){t.set(r.focalQname,[r]);continue}e.some(e=>e.external.filePath===r.external.filePath&&e.external.qualifiedName===r.external.qualifiedName)||e.push(r)}return t}function e3({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:a,onSwitchToCode:l,onSearch:i,onRefresh:d,refreshDisabled:c,extraLeft:u,extraRight:m}){let{t:x}=(0,o.Bd)(),h={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:a??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 text-xs text-muted-foreground font-mono",children:[(0,n.jsx)("span",{className:"truncate min-w-0",children:e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-foreground",children:e}),"number"==typeof r&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",r," blocks"]}),"number"==typeof s&&"number"==typeof a&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",a," out"]})]}):(0,n.jsx)("span",{children:null!==t?`${t} files`:"…"})}),u&&(0,n.jsx)("span",{className:"flex items-center gap-1 flex-shrink-0",children:u(h)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[m&&(0,n.jsx)("span",{className:"flex items-center gap-1",children:m(h)}),(0,n.jsxs)("button",{onClick:i,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground flex items-center gap-1","data-tooltip":x("blockViewer.search.tooltip","Search (⌘K)"),children:[(0,n.jsx)(en.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:d,disabled:c,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground disabled:opacity-50 disabled:hover:bg-transparent","data-tooltip":x("blockViewer.refresh","Rebuild project graph"),children:(0,n.jsx)(ea.A,{className:"w-3 h-3"})}),l&&(0,n.jsx)("button",{onClick:l,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:x("common.code","Code")})]})]})}var e6=r(22576);function e8(e){let t=0xdeadbeef,r=0x41c6ce57;for(let n=0;n<e.length;n++){let s=e.charCodeAt(n);t=Math.imul(t^s,0x9e3779b1),r=Math.imul(r^s,0x5f356495)}return t=Math.imul(t^t>>>16,0x85ebca6b)^Math.imul(r^r>>>13,0xc2b2ae35),(0x100000000*(2097151&(r=Math.imul(r^r>>>16,0x85ebca6b)^Math.imul(t^t>>>13,0xc2b2ae35)))+(t>>>0)>>>0).toString(16)}function e9(e){return e.replace(/\s+/g," ").trim()}function e7(e,t){return e?`${e}>${t}`:t}function te(e){let t=e.childForFieldName("name");if(t)return t.text;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r&&("identifier"===r.type||"type_identifier"===r.type||"property_identifier"===r.type))return r.text}return"<anonymous>"}function tt(e,t,r,n,s=[],o){return{qualifiedName:e7(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,declLine:function(e){for(let t=0;t<e.childCount;t++){let r=e.child(t);if(r&&"decorator"!==r.type&&"comment"!==r.type)return r.startPosition.row}return e.startPosition.row}(e)+1,contentHash:e8(e9(e.text)),children:s,params:o}}function tr(e){let t=e.childForFieldName("parameter");if(t)return[t.text];let r=e.childForFieldName("parameters");if(!r)return;let n=[];for(let e=0;e<r.namedChildCount;e++){let t=r.namedChild(e);t&&n.push(function e(t){switch(t.type){case"required_parameter":case"optional_parameter":{let r=t.childForFieldName("pattern");return r?e(r):t.text}case"assignment_pattern":{let r=t.childForFieldName("left");return r?e(r):t.text}case"default_parameter":case"typed_default_parameter":{let e=t.childForFieldName("name");return e?e.text:t.text}case"typed_parameter":for(let e=0;e<t.namedChildCount;e++){let r=t.namedChild(e);if(r?.type==="identifier")return r.text}return t.text;default:return t.text}}(t))}return n}let tn={theorem:"function",def:"function",abbrev:"function",example:"function",instance:"const",structure:"class",inductive:"type",axiom:"const",opaque:"const",constant:"const"};function ts(e){let t=e.split("/").pop()?.toLowerCase()??"";switch(t.includes(".")?t.split(".").pop():""){case"ts":return"typescript";case"tsx":case"jsx":return"tsx";case"js":case"mjs":case"cjs":return"javascript";case"py":case"pyi":return"python";case"go":return"go";case"rs":return"rust";case"lean":return"lean";default:return null}}var to=r(14066);let ta="/tree-sitter",tl=null,ti=new Map;async function td(e){let t,r=await (!(t=ti.get(e))&&(t=(async()=>(await (!tl&&(tl=to.iX.init({locateFile:e=>`${ta}/${e}`})),tl),to.TM.load(`${ta}/tree-sitter-${e}.wasm`)))(),ti.set(e,t)),t),n=new to.iX;return n.setLanguage(r),n}function tc(e){return e.qualifiedName.startsWith("__code_")||e.qualifiedName.startsWith("__heading_")}function tu(e){return!tc(e)&&"__file__"!==e.qualifiedName}async function tm(e,t){if(!e)return[];let r=ts(t);if(!r)return null;let n=(await td(r)).parse(e);if(!n)return null;try{return function(e,t){var r;let n,s,o=[],a=function(e){let t=[],r=-1,n=-1;for(let s=0;s<e.namedChildCount;s++){let o=e.namedChild(s);if(o){if("import_statement"===o.type||"export_statement"===o.type&&null!==o.childForFieldName("source")||"import_from_statement"===o.type||"future_import_statement"===o.type||"import"===o.type)t.push(o),r<0&&(r=o.startPosition.row+1),n=o.endPosition.row+1;else if(r>=0)break}}return r<0?null:{qualifiedName:"__imports__",name:"imports",kind:"unknown",startLine:r,endLine:n,declLine:r,contentHash:e8(e9(t.map(e=>e.text).join("\n"))),children:[]}}(e);if(a&&o.push(a),"lean"===t)o.push(...function(e){let t=[],r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s)continue;switch(s.type){case"namespace":r.push(s.childForFieldName("name")?.text??null);continue;case"section":r.push(null);continue;case"end":r.pop();continue}let o=null;if("declaration"===s.type)for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t&&t.type in tn){o=t;break}}else s.type in tn&&(o=s);if(!o)continue;let a=o.childForFieldName("name")?.text??o.type,l=r.filter(e=>null!==e);t.push({qualifiedName:[...l,a].join("."),name:a,kind:tn[o.type],startLine:s.startPosition.row+1,endLine:function(e){let t=e.endPosition.row+1,r=e.text.replace(/\s+$/,""),n=e.text.slice(r.length);if(!n)return t;let s=n.split("\n").length-1;return Math.max(e.startPosition.row+1,t-s)}(s),declLine:o.startPosition.row+1,contentHash:e8(e9(s.text)),children:[]})}return t}(e));else for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);r&&o.push(...function e(t,r,n=!1){switch(t.type){case"export_statement":case"export_default_declaration":{let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);o&&n.push(...e(o,r,!0))}return n}case"function_declaration":case"generator_function_declaration":case"function_definition":return[tt(t,te(t),"function",r,[],tr(t))];case"class_declaration":case"abstract_class_declaration":{let e=te(t),n=e7(r,e),s=function(e,t){if(!e)return[];let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(s){if("method_definition"===s.type)r.push(tt(s,te(s),"method",t,[],tr(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(tt(s,te(s),"method",t,[],tr(e)))}}}return r}(t.childForFieldName("body"),n);return[tt(t,e,"class",r,s)]}case"interface_declaration":return[tt(t,te(t),"interface",r)];case"type_alias_declaration":return[tt(t,te(t),"type",r)];case"enum_declaration":return[tt(t,te(t),"enum",r)];case"lexical_declaration":case"variable_declaration":return function(e,t){let r=[];for(let n=0;n<e.namedChildCount;n++){let s=e.namedChild(n);if(!s||"variable_declarator"!==s.type)continue;let o=s.childForFieldName("name"),a=s.childForFieldName("value");if(!o)continue;let l=o.text,i=function e(t,r=0){if(!t||r>8)return null;if("arrow_function"===t.type||"function_expression"===t.type)return t;if(["parenthesized_expression","as_expression","satisfies_expression","non_null_expression"].includes(t.type))return e(t.namedChild(0),r+1);if("call_expression"!==t.type)return null;let n=t.childForFieldName("function");if(!n)return null;let s="member_expression"===n.type?n.childForFieldName("object"):null,o=s?.type==="identifier"?s.text:"identifier"===n.type?n.text:null;if(!o)return null;let a=t;for(;a.parent;)a=a.parent;let l=(function(e){let t=[];for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);if(n)if("import_statement"===n.type){let e=n.childForFieldName("source");e?function(e,t,r){var n;let s=(n=t.text).length>=2&&('"'===n[0]||"'"===n[0])&&n[n.length-1]===n[0]?n.slice(1,-1):n,o=null;for(let t=0;t<e.namedChildCount;t++){let r=e.namedChild(t);if(r?.type==="import_clause"){o=r;break}}if(o)for(let e=0;e<o.namedChildCount;e++){let t=o.namedChild(e);if(t){if("identifier"===t.type)r.push({specifier:s,importedName:"default",localName:t.text});else if("namespace_import"===t.type){let e=function(e,t){for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);if(n?.type===t)return n}return null}(t,"identifier");e&&r.push({specifier:s,importedName:"*",localName:e.text})}else if("named_imports"===t.type)for(let e=0;e<t.namedChildCount;e++){let n=t.namedChild(e);if(!n||"import_specifier"!==n.type)continue;let o=n.childForFieldName("name"),a=n.childForFieldName("alias");o&&r.push({specifier:s,importedName:o.text,localName:a?.text??o.text})}}}}(n,e,t):function(e,t){for(let r=0;r<e.childCount;r++){let n=e.child(r);if(n&&"name"===e.fieldNameForChild(r)){if("dotted_name"===n.type){let e=n.text,r=e.split(".")[0];t.push({specifier:e,importedName:"*",localName:r})}else if("aliased_import"===n.type){let e=n.childForFieldName("name"),r=n.childForFieldName("alias");e?.type==="dotted_name"&&r&&t.push({specifier:e.text,importedName:"*",localName:r.text})}}}}(n,t)}else"import_from_statement"===n.type&&function(e,t){let r=e.childForFieldName("module_name"),n="";if(r){if("dotted_name"===r.type)n=r.text;else if("relative_import"===r.type){let e="",t="";for(let n=0;n<r.namedChildCount;n++){let s=r.namedChild(n);s&&("import_prefix"===s.type?e=s.text:"dotted_name"===s.type&&(t=s.text))}n=e+t}}if(!n)return;let s=!1;for(let r=0;r<e.childCount;r++){let o=e.child(r);if(!o)continue;let a=e.fieldNameForChild(r);if("wildcard_import"===o.type){s=!0;continue}if("name"===a){if("dotted_name"===o.type){let e=o.text;t.push({specifier:n,importedName:e,localName:e})}else if("aliased_import"===o.type){let e=o.childForFieldName("name"),r=o.childForFieldName("alias");e?.type==="dotted_name"&&r&&t.push({specifier:n,importedName:e.text,localName:r.text})}}}s&&t.push({specifier:n,importedName:"*",localName:"*"})}(n,t)}return t})(a).find(e=>e.localName===o);if(!l)return null;let i=s?n.childForFieldName("property")?.text:l.importedName,d="*"===l.importedName||"default"===l.importedName;return(!s||d)&&("@cockpit/effect-runtime/server"===l.specifier?"handler"===i||"dynamicHandler"===i:"react"===l.specifier&&["memo","forwardRef","useCallback"].includes(i??""))?e(t.childForFieldName("arguments")?.namedChild(0)??null,r+1):null}(a),d=null!==i,c=i?tr(i):void 0;if(r.push(tt(e,l,d?"function":"const",t,[],c)),a&&"object"===a.type&&!d){let e=t?`${t}>${l}`:l;for(let t=0;t<a.namedChildCount;t++){let n=a.namedChild(t);if(n){if("pair"===n.type){let t=n.childForFieldName("key"),s=n.childForFieldName("value");if(!t||!s||"property_identifier"!==t.type&&"identifier"!==t.type||"arrow_function"!==s.type&&"function_expression"!==s.type)continue;r.push(tt(n,t.text,"method",e,[],tr(s)))}else if("method_definition"===n.type){let t=te(n);t&&r.push(tt(n,t,"method",e,[],tr(n)))}}}}}return r}(t,r);case"class_definition":{let e=te(t),n=e7(r,e),s=function e(t,r){if(!t)return[];let n=[];for(let s=0;s<t.namedChildCount;s++){let o=t.namedChild(s);if(o){if("function_definition"===o.type)n.push(tt(o,te(o),"method",r,[],tr(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...tt(t,te(t),"method",r,[],tr(t)),startLine:o.startPosition.row+1,contentHash:e8(e9(o.text))});else if(t?.type==="class_definition"){let s=te(t),a=e7(r,s),l=e(t.childForFieldName("body"),a);n.push({...tt(t,s,"class",r,l),startLine:o.startPosition.row+1,contentHash:e8(e9(o.text))})}}else if("class_definition"===o.type){let t=te(o),s=e7(r,t),a=e(o.childForFieldName("body"),s);n.push(tt(o,t,"class",r,a))}}}return n}(t.childForFieldName("body"),n);return[tt(t,e,"class",r,s)]}case"decorated_definition":{let n=t.childForFieldName("definition");if(!n)return[];return e(n,r,!1).map(e=>({...e,startLine:t.startPosition.row+1,contentHash:e8(e9(t.text))}))}case"expression_statement":{let e=[];for(let n=0;n<t.namedChildCount;n++){let s=t.namedChild(n);if(s?.type==="assignment"){let n=function(e,t,r){let n=t.childForFieldName("left");if(!n||"identifier"!==n.type)return null;let s=n.text;return{qualifiedName:e7(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,declLine:e.startPosition.row+1,contentHash:e8(e9(e.text)),children:[]}}(t,s,r);n&&e.push(n)}}return e.push(...function(e,t){let r=null;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(n){if("call_expression"===n.type){r=n;break}if("await_expression"===n.type){for(let e=0;e<n.namedChildCount;e++){let t=n.namedChild(e);if(t?.type==="call_expression"){r=t;break}}break}}}if(!r)return[];let n=r.childForFieldName("function"),s=r.childForFieldName("arguments");if(!n||!s)return[];let o=null,a=[];for(let e=0;e<s.namedChildCount;e++){let t=s.namedChild(e);if(t){if(null===o&&("string"===t.type||"template_string"===t.type)){let e=t.text;o=e.length>=2&&/^["'`]/.test(e)?e.slice(1,-1):e}("arrow_function"===t.type||"function_expression"===t.type)&&a.push(t)}}if(0===a.length||!o)return[];let l=function e(t){if("identifier"===t.type)return t.text;if("member_expression"===t.type){let e=t.childForFieldName("property");return e?.text??""}if("call_expression"===t.type){let r=t.childForFieldName("function");return r?e(r):""}return""}(n),i=l?`${l} ${o}`:o;return a.map((e,r)=>tt(e,a.length>1?`${i} #${r+1}`:i,"function",t,[],tr(e)))}(t,r)),e}default:return[]}}(r,void 0,!1))}return!function(e,t){for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);if(n?.type!=="export_statement")continue;let s=n.childForFieldName("declaration");if(!s||s.startPosition.row===n.startPosition.row)continue;let o=s.startPosition.row+1;for(let e of t)"unknown"!==e.kind&&e.startLine===o&&(e.startLine=n.startPosition.row+1)}let r=new Map;for(let t=0;t<e.namedChildCount;t++){let n=e.namedChild(t);if(!n||!function(e){if("attribute_item"===e.type)return!0;if(!e.type.endsWith("comment"))return!1;for(let t=0;t<e.namedChildCount;t++)if(e.namedChild(t)?.type==="inner_doc_comment_marker")return!1;return!0}(n))continue;let s=0===n.endPosition.column&&n.endPosition.row>n.startPosition.row?n.endPosition.row-1:n.endPosition.row;r.set(s+1,n)}if(0===r.size)return;let n=new Set;for(let e of t)for(let t=e.startLine;t<=e.endLine;t++)n.add(t);for(let e of t){if("unknown"===e.kind)continue;let t=e.startLine;for(;;){let e=r.get(t-1);if(!e)break;let s=e.startPosition.row+1,o=!1;for(let e=s;e<=t-1;e++)if(n.has(e)){o=!0;break}if(o)break;t=s}if(t!==e.startLine){for(let r=t;r<e.startLine;r++)n.add(r);e.startLine=t}}}(e,o),o.push(...function(e,t){let r=e.text.split("\n"),n=r.length;if(0===n)return[];let s=new Uint8Array(n+2);for(let e of t){let t=Math.max(1,e.startLine),r=Math.min(n,e.endLine);for(let e=t;e<=r;e++)s[e]=1}let o=[],a=(e,t)=>{let n=!1;for(let s=e;s<=t;s++){let e=r[s-1];if(e&&e.trim().length>0){n=!0;break}}if(!n)return;let s=r.slice(e-1,t).join("\n");o.push({qualifiedName:`__code_${e}_${t}__`,name:"code",kind:"unknown",startLine:e,endLine:t,declLine:e,contentHash:e8(e9(s)),children:[]})},l=-1;for(let e=1;e<=n;e++)s[e]?l>=0&&(a(l,e-1),l=-1):l<0&&(l=e);return l>=0&&a(l,n),o}(e,o)),r=o,n=new Map,(s=e=>{for(let t of e){let e=(n.get(t.qualifiedName)??0)+1;n.set(t.qualifiedName,e),e>1&&(t.qualifiedName=`${t.qualifiedName}#${e}`),s(t.children)}})(r),o}(n.rootNode,r)}finally{n.delete()}}function tx(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(tu(n)){for(let e=n.startLine;e<n.declLine;e++)if(t.has(e)){r.push(n.qualifiedName);break}}return r}async function th(e,t,r,n,s){let o=new Set,a=new Set;if(e!==t)for(let r of(0,e6.X)(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum?o.add(r.newLineNum):"removed"===r.type&&void 0!==r.oldLineNum&&a.add(r.oldLineNum);if(!ts(r))return{addedLines:o};let[l,i]=await Promise.all([tm(n?"":e,r),tm(s?"":t,r)]),d=l??[],c=i??[],u=function(e,t){let r=new Map;for(let t of e)r.set(t.qualifiedName,t);let n=new Map;for(let e of t)n.set(e.qualifiedName,e);let s=[];for(let e of t){let t=r.get(e.qualifiedName);t?t.contentHash!==e.contentHash&&s.push({id:`mod:${e.qualifiedName}`,changeKind:"modified",qname:e.qualifiedName}):s.push({id:`add:${e.qualifiedName}`,changeKind:"added",qname:e.qualifiedName})}for(let t of e)n.has(t.qualifiedName)||s.push({id:`del:${t.qualifiedName}`,changeKind:"deleted",qname:t.qualifiedName});return s}(d.filter(tu),c.filter(tu)),m=new Set;for(let e of u)"deleted"!==e.changeKind&&m.add(e.qname);for(let e of function(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(tc(n)){for(let e of t)if(e>=n.startLine&&e<=n.endLine){r.push(n.qualifiedName);break}}return r}(c,o))m.add(e);for(let e of tx(c,o))m.add(e);let x=new Set(c.map(e=>e.qualifiedName));for(let e of tx(d,a))x.has(e)&&m.add(e);return{changedQnames:m,addedLines:o}}function tf({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:a=!1,isDeleted:l=!1,changedFiles:i,fileGitStatusMap:d,enableComments:c=!1,compact:u=!0,onContentSearch:m,onSwitchToCode:x,headerExtraLeft:h,headerExtraRight:f}){let[p,g]=(0,s.useState)(t);(0,s.useEffect)(()=>{g(t)},[t]);let[b,v]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return v(null),(async()=>{try{let s=await tp(p,t,r,o,a,l,i,d,e);if(n||!s)return;let c=await th(s.oldContent,s.newContent,p,s.isNew,s.isDeleted);if(n)return;v(c)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[p,t,r,o,a,l,i,d,e]),(0,n.jsx)(e5,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:c,qnameFilter:u?b?.changedQnames:void 0,qnameFilterFile:p,accentQnames:b?.changedQnames,accentFile:p,addedLines:b?.addedLines,addedLinesFile:p,compact:u,onFocalChange:e=>e&&g(e),onContentSearch:m,onSwitchToCode:x,headerExtraLeft:h,headerExtraRight:f})}async function tp(e,t,r,n,s,o,a,l,i){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!a.has(e))return null;let d=l?.get(e);if(!d)return null;let c=new URLSearchParams({cwd:i,file:e,type:d}),u=await x.t4.runPromiseExit((0,p.oh)(c));if("Success"!==u._tag)return null;let m=u.value;return{oldContent:m.oldContent,newContent:m.newContent,isNew:m.isNew??!1,isDeleted:m.isDeleted??!1}}var tg=r(50860);let tb=(e,t,r)=>`/api/git/blob?cwd=${encodeURIComponent(e)}&rev=${encodeURIComponent(t)}&file=${encodeURIComponent(r)}`;function tv({cwd:e,selected:t,diff:r,showMarkdownPreview:a,setShowMarkdownPreview:l,changedFiles:i,fileGitStatusMap:d,onContentSearch:c,locateInTree:u,setJsonPreview:m,onTokenHover:x,onTokenHoverLeave:h,onTokenHoverCancel:f}){let{t:p}=(0,o.Bd)(),k="unstaged"===t.type?{onTokenHover:x,onTokenHoverLeave:h,onTokenHoverCancel:f}:{},[N,C]=(0,s.useState)(!1),[L,T]=(0,s.useState)("file"),[$,R]=(0,s.useState)("compact"),[I,F]=(0,s.useState)("unified"),B=t.file.path,D=t.file.oldPath||B,A=(0,E.u)(B),H=B.startsWith("/")?B:e?`${e.replace(/\/$/,"")}/${B}`:B,{state:W}=ej(e,B),z=(0,s.useMemo)(()=>{if("ready"===W.state)return W.data.functions.filter(eP).map(e=>({name:e.name,startLine:e.startLine,endLine:e.endLine,params:e.params}))},[W]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[A||"map"!==L?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:B}),(0,n.jsx)(S.m,{content:p("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${B}`),(0,M.oR)(p("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(S.m,{content:p("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(B)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${"staged"===t.type?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===t.type?p("fileBrowser.staged"):p("fileBrowser.unstaged")}),(0,n.jsx)("div",{className:"flex-1"}),!A&&(0,n.jsx)(j.y,{value:$,onChange:R}),!A&&"file"===L&&(0,n.jsx)(w.q,{value:I,onChange:F}),!A&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),T(e)},className:`px-2 py-0.5 text-xs transition-colors ${L===e?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:p("file"===e?"common.file":"common.codeMap")},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:A?(0,n.jsx)(y.K,{filePath:B,oldSrc:r.isNew?null:tb(e,"staged"===t.type?"HEAD":":0","staged"===t.type?D:B),newSrc:r.isDeleted||"staged"!==t.type?null:tb(e,":0",B),newNode:r.isDeleted||"staged"===t.type?void 0:(0,n.jsx)(tg.I,{cwd:e,path:B,className:"flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:B})}):"unified"===I?(0,n.jsx)(g.xU,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,cwd:e,enableComments:!0,compact:"compact"===$,onPreview:!r.isDeleted&&(0,P.e$)(B)?()=>l(!0):!r.isDeleted&&(0,P.aR)(B)?()=>C(!0):!r.isDeleted&&B.endsWith(".json")?()=>m({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:B.endsWith(".json")?p("common.readable"):p("common.preview"),onContentSearch:c,...k}):(0,n.jsx)(g.xZ,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,compact:"compact"===$,symbols:z,onPreview:!r.isDeleted&&(0,P.e$)(B)?()=>l(!0):!r.isDeleted&&(0,P.aR)(B)?()=>C(!0):!r.isDeleted&&B.endsWith(".json")?()=>m({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:B.endsWith(".json")?p("common.readable"):p("common.preview"),onContentSearch:c,...k})})]}):(0,n.jsx)(tf,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:d,enableComments:!0,compact:"compact"===$,onContentSearch:c,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=d.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(S.m,{content:p("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,M.oR)(p("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})}),(0,n.jsx)(S.m,{content:p("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(t)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})}),r&&(0,n.jsx)("span",{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 ${"staged"===r?"bg-green-9/15 text-green-11 dark:bg-green-9/25":"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25"}`,children:"staged"===r?p("fileBrowser.staged"):p("fileBrowser.unstaged")})]})},headerExtraRight:()=>(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.y,{value:$,onChange:R}),(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["file","map"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),T(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${L===e?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:p("file"===e?"common.file":"common.codeMap")},e))})]})}),a&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:()=>l(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(v.M,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>l(!1)})})}),N&&(0,n.jsx)(b.N,{filePath:H,content:r.newContent,cwd:e,onClose:()=>C(!1)})]})}function tj({branches:e,selectedBranch:t,onSelect:r,isLoading:a,pinnedBranches:l=[]}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(!1),[u,m]=(0,s.useState)(""),x=(0,s.useRef)(null),h=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{x.current&&!x.current.contains(e.target)&&c(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{d&&h.current&&h.current.focus()},[d]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=l.filter(e=>p.has(e)&&e.toLowerCase().includes(f)),b=new Set(g),v=e?.local.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],j=e?.remote.filter(e=>!b.has(e)&&e.toLowerCase().includes(f))||[],w=e=>{r(e),c(!1),m("")};return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>c(!d),disabled:a,className:"w-full px-3 py-1.5 text-sm border border-border rounded bg-card text-foreground text-left flex items-center justify-between hover:border-slate-6 dark:hover:border-slate-6 transition-colors",children:[(0,n.jsxs)("span",{className:"truncate flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),t||i("git.selectBranch"),e?.current===t&&(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["(",i("git.currentBranch"),")"]})]}),(0,n.jsx)("svg",{className:`w-4 h-4 text-foreground-subtle transition-transform ${d?"rotate-180":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),d&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lv2 max-h-80 flex flex-col",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:h,type:"text",value:u,onChange:e=>m(e.target.value),placeholder:i("git.searchBranch"),className:"w-full px-2 py-1 text-sm border border-border rounded bg-secondary text-foreground"})}),(0,n.jsxs)("div",{className:"overflow-y-auto flex-1",children:[g.length>0&&g.map(r=>(0,n.jsxs)("div",{onClick:()=>w(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},`pinned-${r}`)),v.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-popover sticky top-0",children:i("git.localBranches")}),v.map(r=>(0,n.jsxs)("div",{onClick:()=>w(r),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${r===t?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:r}),r===e?.current&&(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:i("git.currentBranch")}),r===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},r))]}),j.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs font-medium text-muted-foreground bg-popover sticky top-0",children:i("git.remoteBranches")}),j.map(e=>(0,n.jsxs)("div",{onClick:()=>w(e),className:`px-3 py-1.5 text-sm cursor-pointer flex items-center gap-2 ${e===t?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate flex-1",children:e}),e===t&&(0,n.jsx)("svg",{className:"w-4 h-4 text-brand flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},e))]}),0===g.length&&0===v.length&&0===j.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("git.noMatchingBranches")})]})]})]})}let tw=96/72;function tk({cwd:e,path:t,refreshKey:o}){let a=(0,s.useRef)(null),[l,i]=(0,s.useState)({kind:"loading"}),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(0),[x,h]=(0,s.useState)(null),[f,p]=(0,s.useState)(0),[g,b]=(0,s.useState)({kind:"auto"}),[v,j]=(0,s.useState)(1),[w,k]=(0,s.useState)(!0);(0,s.useEffect)(()=>{let n=!1;i({kind:"loading"}),c(null),m(0),h(null),j(1);let s=null;return(async()=>{try{let a=await Promise.all([r.e(52084),r.e(49304)]).then(r.bind(r,66898));a.GlobalWorkerOptions.workerSrc="/pdfjs/pdf.worker.min.mjs";let l=`/api/files/read?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}&v=${encodeURIComponent(String(o??""))}`;s=a.getDocument({url:l});let d=await s.promise;if(n)return;let u=await Promise.all(Array.from({length:d.numPages},(e,t)=>d.getPage(t+1).then(e=>{let t=e.getViewport({scale:1});return{w:t.width,h:t.height}})));if(n)return;c(d),m(d.numPages),h(u),i({kind:"ready"})}catch(e){n||i({kind:"error",message:e instanceof Error?e.message:"Failed to load PDF"})}})(),()=>{n=!0;try{s?.destroy()}catch{}}},[e,t,o]),(0,s.useEffect)(()=>{let e=a.current;if(!e)return;let t=()=>p(Math.max(0,e.clientWidth-32));t();let r=new ResizeObserver(t);return r.observe(e),()=>r.disconnect()},[]);let y=(0,s.useMemo)(()=>x?.length?Math.max(...x.map(e=>e.w)):0,[x]),N=Math.min(y>0&&f>0?f/y:tw,tw),C="auto"===g.kind?N:g.factor*tw,S=Math.round(C/tw*100),M=(0,s.useMemo)(()=>x?x.map(e=>e.h*C+16):[],[x,C]),L=y*C,E=(0,s.useRef)(1);E.current=N/tw;let P=(0,s.useRef)(M);P.current=M;let T=(0,D.Te)({count:u,getScrollElement:()=>a.current,estimateSize:e=>P.current[e]??0,overscan:2});(0,s.useEffect)(()=>{M.length>0&&T.measure()},[M,T]);let $=(0,s.useCallback)(()=>{let e=a.current;if(!e||0===u)return;let t=e.scrollTop,r=T.getVirtualItems().find(e=>e.end>t);j((r?r.index:u-1)+1)},[T,u]),R=(0,s.useCallback)(e=>{b(t=>({kind:"fixed",factor:Math.min(4,Math.max(.25,("auto"===t.kind?E.current:t.factor)*e))}))},[]),I=(0,s.useCallback)(()=>R(1.2),[R]),F=(0,s.useCallback)(()=>R(.8333333333333334),[R]),B=(0,s.useCallback)(()=>b({kind:"auto"}),[]),A=(0,s.useCallback)(()=>k(e=>!e),[]),H=(0,s.useCallback)(e=>{T.scrollToIndex(e,{align:"start"}),j(e+1)},[T]),W=T.getVirtualItems(),z=T.getTotalSize(),O=(0,s.useMemo)(()=>(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border text-muted-foreground text-xs select-none",children:[(0,n.jsx)("button",{onClick:A,className:`px-1.5 py-0.5 rounded hover:bg-hover transition-colors ${w?"text-foreground":""}`,title:w?"Hide thumbnails":"Show thumbnails","aria-label":"Toggle thumbnails",children:(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[(0,n.jsx)("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),(0,n.jsx)("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),(0,n.jsx)("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]})}),(0,n.jsx)("span",{className:"tabular-nums",children:u>0?`${v} / ${u}`:"—"}),(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:F,className:"px-1.5 py-0.5 rounded hover:bg-hover transition-colors",title:"Zoom out","aria-label":"Zoom out",children:"−"}),(0,n.jsxs)("button",{onClick:B,className:`px-1.5 py-0.5 rounded hover:bg-hover transition-colors tabular-nums min-w-[3.5rem] ${"auto"===g.kind?"":"text-foreground"}`,title:"Reset to automatic zoom",children:[S,"%"]}),(0,n.jsx)("button",{onClick:I,className:"px-1.5 py-0.5 rounded hover:bg-hover transition-colors",title:"Zoom in","aria-label":"Zoom in",children:"+"})]})]}),[u,v,S,g.kind,I,F,B,w,A]);return"error"===l.kind?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-secondary",children:[O,(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("div",{className:"text-sm text-red-11",children:l.message})})]}):(0,n.jsxs)("div",{className:"h-full flex flex-col bg-secondary",children:[O,(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[w&&d&&x&&(0,n.jsx)(ty,{doc:d,numPages:u,sizes:x,maxPageW:y,currentPage:v,onSelect:H}),(0,n.jsx)("div",{ref:a,onScroll:$,className:"flex-1 overflow-auto px-4 py-4",children:"loading"!==l.kind&&d&&x&&!(L<=0)?(0,n.jsx)("div",{style:{height:z,width:Math.max(L,f),position:"relative"},children:W.map(e=>(0,n.jsx)("div",{"data-index":e.index,className:"absolute left-0 top-0 w-full flex justify-center",style:{transform:`translateY(${e.start}px)`,paddingBottom:16},children:(0,n.jsx)(tN,{doc:d,pageNumber:e.index+1,scale:C,width:x[e.index].w*C,height:x[e.index].h*C})},e.key))}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})})})]})]})}function ty({doc:e,numPages:t,sizes:r,maxPageW:o,currentPage:a,onSelect:l}){let i=(0,s.useRef)(null),d=o>0?100/o:0,c=(0,s.useMemo)(()=>r.map(e=>e.h*d+18+12),[r,d]),u=(0,s.useRef)(c);u.current=c;let m=(0,D.Te)({count:t,getScrollElement:()=>i.current,estimateSize:e=>u.current[e]??0,overscan:3});(0,s.useEffect)(()=>{c.length>0&&m.measure()},[c,m]),(0,s.useEffect)(()=>{t>0&&m.scrollToIndex(a-1,{align:"auto"})},[a]);let x=m.getVirtualItems();return(0,n.jsx)("div",{ref:i,className:"shrink-0 overflow-auto border-r border-border py-2",style:{width:132},children:(0,n.jsx)("div",{style:{height:m.getTotalSize(),width:"100%",position:"relative"},children:x.map(t=>{let s=a===t.index+1;return(0,n.jsxs)("div",{className:"absolute left-0 top-0 w-full flex flex-col items-center",style:{transform:`translateY(${t.start}px)`,paddingBottom:12},children:[(0,n.jsx)("button",{onClick:()=>l(t.index),className:`rounded-sm overflow-hidden transition-shadow ${s?"ring-2 ring-brand":"ring-1 ring-border hover:ring-muted-foreground"}`,title:`Page ${t.index+1}`,"aria-label":`Go to page ${t.index+1}`,children:(0,n.jsx)(tN,{doc:e,pageNumber:t.index+1,scale:d,width:r[t.index].w*d,height:r[t.index].h*d})}),(0,n.jsx)("span",{className:`mt-0.5 text-[11px] tabular-nums leading-none ${s?"text-foreground font-medium":"text-muted-foreground"}`,style:{height:18},children:t.index+1})]},t.key)})})})}function tN({doc:e,pageNumber:t,scale:r,width:o,height:a}){let l=(0,s.useRef)(null);return(0,s.useEffect)(()=>{let n=!1,s=null;return(async()=>{let o=await e.getPage(t);if(n)return;let a=l.current;if(!a)return;let i=Math.min(window.devicePixelRatio||1,2),d=o.getViewport({scale:r*i});a.width=Math.floor(d.width),a.height=Math.floor(d.height),a.style.width=`${a.width/i}px`,a.style.height=`${a.height/i}px`,s=o.render({canvas:a,viewport:d});try{await s.promise}catch{}})(),()=>{n=!0;try{s?.cancel()}catch{}}},[e,t,r]),(0,n.jsx)("div",{className:"bg-white shadow-lv2",style:{width:o,height:a},children:(0,n.jsx)("canvas",{ref:l,className:"block"})})}var tC=r(69809);function tS(e){let t=e.split(".").pop()?.toLowerCase();return t?["ts","tsx","js","jsx","mjs","cjs"].includes(t)?"typescript":["py","pyi"].includes(t)?"python":null:null}let tM=(e,t)=>eh.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()},catch:t=>new ef.uV({message:`${e} failed`,cause:t})});function tL(e){return e.replace(/^\([^)]+\)\s*/,"")}function tE(e){let t=tL(e),r=t.match(/^(?:function|const|let|var|class|interface|type|enum|async function)\s+([a-zA-Z_$][\w$]*)/);if(r)return r[1];let n=e.match(/\([^)]+\)\s+(?:[\w$]+\.)*([a-zA-Z_$][\w$]*)/);if(n)return n[1];let s=t.match(/([a-zA-Z_$][\w$]*)/);return s?s[1]:t.split(/[(\s:]/)[0]}let tP=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:a,container:l,onMouseEnter:i,onMouseLeave:d,onFindReferences:c,onSearch:u,onExplain:m,explainDisabled:x},h){let{t:f}=(0,o.Bd)(),p=(0,s.useRef)(null);(0,s.useImperativeHandle)(h,()=>p.current,[]);let g=l.getBoundingClientRect(),b=r-g.left,v=a-g.top,j=(0,s.useMemo)(()=>tL(e),[e]),w=(0,s.useMemo)(()=>(function(e){let t,r=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b/g,s=[],o=0,a=0,l=/\b(const|let|var|function|class|interface|type|enum|import|export|async|await|return|new|typeof|keyof|extends|implements|readonly|static|public|private|protected|abstract|declare|namespace|module|void|never|undefined|null|true|false|any|unknown|string|number|boolean|bigint|symbol|object)\b|"[^"]*"|'[^']*'|\b\d+\b/g;for(;null!==(t=l.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},a++));let l=t[0];/^["']/.test(l)?s.push((0,n.jsx)("span",{className:"text-green-11",children:l},a++)):/^\d+$/.test(l)?s.push((0,n.jsx)("span",{className:"text-orange-11",children:l},a++)):r.test(l)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-violet-11",children:l},a++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:l},a++)),o=t.index+l.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},a++)),s})(j),[j]);return(0,s.useEffect)(()=>{if(!p.current)return;let e=p.current,t=l.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=a-t.top;s+n.width>t.width-8&&(s=t.width-n.width-8),s<8&&(s=8),o+n.height>t.height-8&&(o=o-n.height-24),e.style.left=`${s}px`,e.style.top=`${o}px`},[r,a,l]),(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] max-w-lg bg-card border border-border rounded-lg shadow-lv3 px-3 py-2 pointer-events-none",style:{left:b,top:v},children:[(0,n.jsx)("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all leading-relaxed",children:w}),t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground whitespace-pre-wrap",children:t})]}),(c||u||m)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border my-1.5"}),(0,n.jsxs)("div",{className:"flex items-center gap-3 pointer-events-auto",onMouseEnter:i,onMouseLeave:d,children:[c&&(0,n.jsx)("button",{onClick:c,className:"text-[11px] text-brand hover:underline cursor-pointer",children:f("hoverTooltip.findReferences")}),u&&(0,n.jsx)("button",{onClick:()=>u(tE(e)),className:"text-[11px] text-brand hover:underline cursor-pointer",children:f("hoverTooltip.search")}),m&&(0,n.jsx)("button",{onClick:()=>m(tE(e)),disabled:x,title:x?f("comments.aiResponding"):void 0,className:"text-[11px] text-brand hover:underline cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed disabled:no-underline",children:f("explain.action")})]})]})]})});function tT({references:e,loading:t,onSelect:r,onClose:a}){let{t:l}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,eS.kS)();if(t!==a.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let a=(0,eS.sQ)(r.file);if("text"!==a)try{let e=n.codeToTokens(r.lineText,{lang:a,theme:s}),l=(0,eS.b8)(e.tokens[0]||[]);l&&o.set(t,l)}catch{}}t===a.current&&r(o)})()},[e,n]),t}(e),d=[],c=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=c.get(r.file);void 0===n&&(n=d.length,c.set(r.file,n),d.push({file:r.file,items:[]})),d[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-card flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground",children:[l("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-hover text-muted-foreground",children:(0,n.jsx)(es.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:l("references.notFound")}):d.map(({file:e,items:t})=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card sticky top-0",children:e}),t.map(({ref:e,idx:t})=>(0,n.jsxs)("button",{onClick:()=>r(e),className:"w-full text-left px-3 py-0.5 hover:bg-hover flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:e.line}),i.has(t)?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:i.get(t)}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:e.lineText||""})]},`${e.line}-${e.column}-${t}`))]},e))})]})}function t$({results:e,loading:t,totalMatches:r,onSelect:a,onClose:l,scope:i,onScopeChange:d,selectedPath:c}){let{t:u}=(0,o.Bd)(),m=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),a=(0,s.useRef)(0);return(0,s.useEffect)(()=>{let e=()=>o(document.documentElement.classList.contains("dark"));e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{if(0===e.length)return void queueMicrotask(()=>r(new Map));let t=++a.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,eS.kS)(),o=new Map;for(let t of e){let e=(0,eS.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let a=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),l=(0,eS.b8)(t.tokens[0]||[]);l&&o.set(a,l)}catch{}}}t===a.current&&r(o)})()},[e,n]),t}(e),x="selected"===i?e.filter(e=>e.path===c):e,h=x.reduce((e,t)=>e+t.matches.length,0);return(0,n.jsxs)("div",{className:"border-t border-border bg-card flex flex-col",style:{height:"300px"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 bg-card/50 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsxs)("span",{className:"text-xs font-medium text-foreground truncate",children:[u("searchResults.title")," ",!t&&u("searchResults.nMatches",{count:"selected"===i?h:r})]}),(0,n.jsxs)("div",{className:"flex items-center rounded border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>d("selected"),className:`px-2 py-0.5 ${"selected"===i?"bg-brand/15 text-brand":"text-muted-foreground hover:bg-hover"}`,children:u("searchResults.scopeSelected")}),(0,n.jsx)("button",{onClick:()=>d("all"),className:`px-2 py-0.5 border-l border-border ${"all"===i?"bg-brand/15 text-brand":"text-muted-foreground hover:bg-hover"}`,children:u("searchResults.scopeAll")})]})]}),(0,n.jsx)("button",{onClick:l,className:"p-0.5 rounded hover:bg-hover text-muted-foreground flex-shrink-0",children:(0,n.jsx)(es.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:t?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:u("searchResults.searching")}):0===x.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:u("searchResults.noResults")}):x.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"px-3 py-1 text-xs text-muted-foreground font-medium bg-card sticky top-0",children:e.path}),e.matches.map((t,r)=>{let s=`${e.path}:${t.lineNumber}`,o=m.get(s);return(0,n.jsxs)("button",{onClick:()=>a(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-hover flex items-baseline gap-2 group",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground font-mono font-variant-tabular flex-shrink-0 w-10 text-right",children:t.lineNumber}),o?(0,n.jsx)("span",{className:"text-sm font-mono truncate",dangerouslySetInnerHTML:{__html:o}}):(0,n.jsx)("span",{className:"text-sm font-mono text-foreground truncate",children:t.content||""})]},`${t.lineNumber}-${r}`)})]},e.path))})]})}var tR=r(63728),tI=r(79237);let tF=s.memo(function({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:a,initialSearchQuery:l,searchQueryTrigger:i,fileOpenRequest:d}){var b;let y,N,S,I,F,D,H,W,z,Z,en,es,eo,{t:ea}=(0,o.Bd)(),el=(0,R.r)(),ei=(0,s.useCallback)(e=>{el?.sendMessage(ea("explain.fileMessage",{path:e}))},[el,ea]),ed=(0,s.useCallback)(e=>{el?.sendMessage(ea("explain.stagedFileMessage",{path:e}))},[el,ea]),ec=(0,s.useCallback)(e=>{el?.sendMessage(ea("explain.unstagedFileMessage",{path:e}))},[el,ea]),eu=(0,G.P)(),em=(0,J.U)(),ex=(0,Y.Q)(),{activeView:ep,onViewChange:eg}=(0,tR.R8)(),[eb,ev]=(0,s.useState)(r),[ej,ew]=(0,s.useState)("code"),ek=(0,s.useRef)(null),ey=(0,s.useRef)(!1),[eN,eC]=(0,s.useState)(null),[eS,eM]=(0,s.useState)(null),[eL,eE]=(0,s.useState)(!1),eP=(0,s.useRef)(1),eT=(0,s.useRef)(null),[e$,eR]=(0,s.useState)(null),eI=(0,s.useRef)(null),[eF,eB]=(0,s.useState)({isDirty:!1,isSaving:!1}),[eD,eA]=(0,s.useState)(!1),[eH,eW]=(0,s.useState)(null),[ez,eO]=(0,s.useState)(null),[e_,eq]=(0,s.useState)("compact"),[eV,eU]=(0,s.useState)("unified"),[eK,eQ]=(0,s.useState)("full"),[eG,eJ]=(0,s.useState)("unified"),[eY,eX]=(0,s.useState)(320),eZ=(0,s.useRef)(null),e0=(0,s.useCallback)(e=>{"mouse"===e.pointerType&&0===e.button&&(e.preventDefault(),eZ.current={startX:e.clientX,startWidth:eY},e.currentTarget.setPointerCapture(e.pointerId))},[eY]),e1=(0,s.useCallback)(e=>{let t=eZ.current;t&&eX(Math.min(480,Math.max(320,t.startWidth+(e.clientX-t.startX))))},[]),e2=(0,s.useCallback)(e=>{eZ.current&&(eZ.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},[]),e4=(0,s.useRef)(null),e3=(0,T.o)(e4),e6=(0,s.useRef)(null),e8=(0,T.o)(e6),e9=function(e){let[t,r]=(0,s.useState)(!1);return{goToDefinition:(0,s.useCallback)(async(t,n,s)=>{r(!0);let o=await x.t4.runPromiseExit(tM("/api/lsp/definition",{cwd:e,filePath:t,line:n,column:s}));return(r(!1),"Success"===o._tag)?o.value.definitions??[]:(console.error("[useLSP] definition error:",o.cause),[])},[e]),loading:t}}(t),e7=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),a=(0,s.useRef)(0),l=(0,s.useRef)(!1),i=(0,s.useRef)(null),d=(0,s.useRef)({x:0,y:0}),c=(0,s.useCallback)(e=>{i.current=e},[]);(0,s.useEffect)(()=>{let e=e=>{d.current.x=e.clientX,d.current.y=e.clientY};return document.addEventListener("mousemove",e),()=>document.removeEventListener("mousemove",e)},[]);let u=(0,s.useRef)(!1),m=(0,s.useRef)(null),h=(0,s.useCallback)(()=>{let e=i.current;e&&u.current&&(e.style.pointerEvents="none"),u.current=!1,m.current&&(i.current?.removeEventListener("mouseleave",m.current),m.current=null)},[]),f=(0,s.useCallback)(()=>{let e=i.current;if(!e||u.current)return;u.current=!0,l.current=!0,e.style.pointerEvents="auto";let t=()=>{l.current=!1,h(),a.current++,r(null)};m.current=t,e.addEventListener("mouseleave",t)},[h]),p=(0,s.useCallback)((t,s,l,i)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let d=++a.current;n.current=setTimeout(async()=>{let n=await x.t4.runPromiseExit(tM("/api/lsp/hover",{cwd:e,filePath:t,line:s,column:l}));if(d!==a.current||"Success"!==n._tag)return;let o=n.value.hover;o&&o.displayString&&r({...o,x:i.x,y:i.y,filePath:t,line:s,column:l})},300)},[e]),g=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),a.current++,o.current=setTimeout(function(){if(l.current)return;let e=i.current;if(e){let t=e.getBoundingClientRect(),{x:r,y:n}=d.current;if(r>=t.left&&r<=t.right&&n>=t.top&&n<=t.bottom)return void f()}r(null)},150)},[f]),b=(0,s.useCallback)(()=>{l.current=!0,o.current&&clearTimeout(o.current)},[]),v=(0,s.useCallback)(()=>{l.current=!1,a.current++,r(null)},[]),j=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),l.current=!1,h(),a.current++,r(null)},[h]);return(0,s.useEffect)(()=>{t||h()},[t,h]),{hoverInfo:t,onTokenMouseEnter:p,onTokenMouseLeave:g,onCardMouseEnter:b,onCardMouseLeave:v,clearHover:j,setTooltipEl:c}}(t),te=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[a,l]=(0,s.useState)(!1);return{references:t,loading:n,visible:a,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),l(!0);let a=await x.t4.runPromiseExit(tM("/api/lsp/references",{cwd:e,filePath:t,line:n,column:s}));"Success"===a._tag?r(a.value.references??[]):(console.error("[useLSP] references error:",a.cause),r([])),o(!1)},[e]),closeReferences:(0,s.useCallback)(()=>{l(!1),r([])},[])}}(t),tt=(y=(0,s.useRef)([]),N=(0,s.useRef)([]),S=(0,s.useCallback)(e=>{y.current.push(e),y.current.length>50&&(y.current=y.current.slice(-50)),N.current=[]},[]),I=(0,s.useCallback)(e=>{if(0===y.current.length)return null;let t=y.current.pop();return N.current.push(e),N.current.length>50&&(N.current=N.current.slice(-50)),t},[]),F=(0,s.useCallback)(e=>{if(0===N.current.length)return null;let t=N.current.pop();return y.current.push(e),y.current.length>50&&(y.current=y.current.slice(-50)),t},[]),{push:S,goBack:I,goForward:F,canGoBack:(0,s.useCallback)(()=>y.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>N.current.length>0,[])}),tr=(0,er.F)(),tn=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[a,l]=(0,s.useState)(new Set),[i,d]=(0,s.useState)([]),[c,u]=(0,s.useState)(null),[m,p]=(0,s.useState)(null),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)(null),[w,k]=(0,s.useState)(""),[y,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(null),[M,L]=(0,s.useState)(!0),[P,T]=(0,s.useState)(!1),[$,R]=(0,s.useState)(null),I=(0,s.useRef)(null),[F,B]=(0,s.useState)(!1),[D,A]=(0,s.useState)(null),[H,W]=(0,s.useState)("center"),[z,O]=(0,s.useState)(null),[_,q]=(0,s.useState)(null),[V,U]=(0,s.useState)(!1),[K,Q]=(0,s.useState)([]),[G,J]=(0,s.useState)(!1),[Y,X]=(0,s.useState)(null),[Z,ee]=(0,s.useState)(null),[et,er]=(0,s.useState)(!0),[en,es]=(0,s.useState)(!1),[eo,ea]=(0,s.useState)(!1),el=(0,s.useMemo)(()=>i.map(e=>e.path).filter(Boolean),[i]),ei=(0,s.useMemo)(()=>(0,E.v3)(el),[el]),ed=(0,s.useMemo)(()=>new Set((0,E.tW)(ei)),[ei]),ec=(0,s.useMemo)(()=>w?n?(0,E.KH)(n,w,y):(0,E.q3)(t,w,y):null,[t,n,w,y]);(0,s.useEffect)(()=>{if(!ec||0===ec.size)return void j(null);let e=new Set;if(n){let t=new Set(n);for(let r of ec)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&ec.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}j(e)},[ec,t,n]);let eu=v??g,em=(0,s.useRef)(null),ex=(0,s.useCallback)(t=>{em.current&&clearTimeout(em.current),em.current=setTimeout(()=>{x.t4.runFork((0,h.Ft)(e,Array.from(t)).pipe(eh.sFT(e=>eh.OH5(()=>console.error("Error saving expanded paths:",e))),eh.NWQ(()=>eh.rIH)))},500)},[e]),ef=(0,s.useCallback)(async()=>{L(!0),R(null),await x.t4.runPromise((0,h.mP)(e).pipe(eh.YWq({onSuccess:e=>{e.error?R(e.error):(r(e.files??[]),e.expandedPaths&&Array.isArray(e.expandedPaths)&&b(new Set(e.expandedPaths)))},onFailure:e=>{console.error("Error loading files:",e),R("Failed to load files")}}))),L(!1)},[e]),ep=(0,s.useCallback)(()=>{x.t4.runPromise((0,h.DZ)(e).pipe(eh.YWq({onSuccess:e=>{e.paths&&o(e.paths)},onFailure:e=>{console.error("Error loading file index:",e)}})))},[e]),eg=(0,s.useCallback)(async t=>{l(e=>new Set([...e,t])),await x.t4.runPromise((0,h.gZ)(e,t).pipe(eh.YWq({onSuccess:e=>{e.children&&r(r=>{if(!t){let t=new Map(r.map(e=>[e.path,e]));return e.children.map(e=>{let r=t.get(e.path);return r?.children&&e.isDirectory?{...e,children:r.children}:e})}let n=structuredClone(r),s=(0,E.MB)(n,t);return s&&(s.children=e.children),n})},onFailure:e=>{console.error("Error loading directory:",e)}}))),l(e=>{let r=new Set(e);return r.delete(t),r})},[e]),eb=(0,s.useRef)(a);eb.current=a,(0,s.useEffect)(()=>{for(let e of v??g){let r=(0,E.MB)(t,e);r&&r.isDirectory&&!r.children&&!eb.current.has(e)&&eg(e)}},[t,g,v,eg]);let ev=(0,s.useCallback)(async()=>{await x.t4.runPromise((0,h.r9)(e).pipe(eh.YWq({onSuccess:e=>d(e.files??[]),onFailure:e=>console.error("Error loading recent files:",e)})))},[e]),ej=(0,s.useCallback)(async t=>{d(e=>{let r=e.filter(e=>e.path!==t);return[{path:t},...r].slice(0,15)}),await x.t4.runPromise((0,h.YW)(e,t).pipe(eh.sFT(e=>eh.OH5(()=>console.error("Error adding to recent files:",e))),eh.NWQ(()=>eh.rIH)))},[e]),ew=(0,s.useCallback)((t,r,n,s)=>{d(e=>e.map(e=>e.path===t?{...e,scrollLine:r,cursorLine:n,cursorCol:s}:e)),x.t4.runFork((0,h.YW)(e,t,{scrollLine:r,cursorLine:n,cursorCol:s}).pipe(eh.NWQ(()=>eh.rIH)))},[e]),ek=(0,s.useCallback)(e=>i.find(t=>t.path===e),[i]),ey=(0,s.useCallback)(async t=>{let r=t||c;r&&(J(!0),X(null),await x.t4.runPromise((0,h.eE)(e,r).pipe(eh.YWq({onSuccess:e=>{e.error?X(e.error):Q(e.blame??[])},onFailure:e=>{console.error("Error loading blame:",e),X("Failed to load blame info")}}))),J(!1))},[e,c]),eN=(0,s.useCallback)(async t=>{T(!0),p(null),U(!1),Q([]),X(null),ee(null);let r=eh.JkU(function*(){let r=yield*(0,h.r6)(e,t);if(!r.ok)return{type:"error",message:r.data?.error||"Failed to stat file"};let n=r.data??{};if(!n.exists)return{type:"error",message:"File not found"};if("dir"===n.kind)return{type:"error",message:"Path is a directory"};switch(n.category){case"image":return{type:"image",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}};case"pdf":return{type:"pdf",size:n.size,mtime:n.mtimeMs,...n.isSymlink?{isSymlink:!0,symlinkTarget:n.symlinkTarget}:{}};case"too-large":return{type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs};default:{let r=yield*(0,f.K)(e,t);if(409===r.status)return{type:"binary",message:r.data?.error||"Cannot preview binary file",size:n.size,mtime:n.mtimeMs};if(!r.ok)return{type:"error",message:r.data?.error||"Failed to load file"};let s=r.data??{};return{type:"text",content:s.content,size:s.size,mtime:s.mtimeMs,...s.isSymlink?{isSymlink:!0,symlinkTarget:s.symlinkTarget}:{}}}}});await x.t4.runPromise(r.pipe(eh.YWq({onSuccess:e=>p(e),onFailure:e=>{console.error("Error loading file content:",e),p({type:"error",message:"Failed to load file"})}}))),ej(t),ey(t),T(!1)},[e,ej,ey]),eC=(0,s.useCallback)(()=>{V?U(!1):(U(!0),0===K.length&&ey())},[V,K.length,ey]),eS=(0,s.useCallback)((e,t)=>{if(!e)return;if(u(e),A(t??null),null==t){let t=i.find(t=>t.path===e);t?.scrollLine?(A(t.scrollLine),W("start"),O(t.cursorLine??null),q(t.cursorCol??null)):(W("center"),O(null),q(null))}else W("center"),O(null),q(null);eN(e);let r=e.split("/");if(r.length>1){let e=[];for(let t=1;t<r.length;t++)e.push(r.slice(0,t).join("/"));b(t=>{let r=new Set(t),n=!1;for(let t of e)r.has(t)||(r.add(t),n=!0);return n&&ex(r),n?r:t})}},[eN,ex,i]),eM=(0,s.useCallback)(e=>{if(v)j(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r});else{let r=!g.has(e);if(b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),ex(r),r}),r){let r=(0,E.MB)(t,e);r&&r.isDirectory&&!r.children&&eg(e)}}},[v,ex,g,t,eg]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:a,expandedPaths:g,setExpandedPaths:b,searchTreeExpandedPaths:v,setSearchTreeExpandedPaths:j,effectiveExpandedPaths:eu,searchQuery:w,setSearchQuery:k,searchExactMatch:y,setSearchDirExact:N,matchedPaths:ec,creatingItem:C,setCreatingItem:S,isLoadingFiles:M,fileError:$,searchInputRef:I,shouldScrollToSelected:F,setShouldScrollToSelected:B,targetLineNumber:D,setTargetLineNumber:A,targetScrollAlign:H,setTargetScrollAlign:W,initialCursorLine:z,initialCursorCol:_,setInitialCursorLine:O,setInitialCursorCol:q,selectedPath:c,setSelectedPath:u,fileContent:m,setFileContent:p,isLoadingContent:P,recentFiles:i,recentFilePaths:el,setRecentFiles:d,recentFilesTree:ei,recentTreeDirPaths:ed,showBlame:V,setShowBlame:U,blameLines:K,isLoadingBlame:G,blameError:Y,blameSelectedCommit:Z,setBlameSelectedCommit:ee,previewMarkdown:et,setPreviewMarkdown:er,previewHtml:en,setPreviewHtml:es,showEditor:eo,setShowEditor:ea,saveExpandedPaths:ex,loadFiles:ef,loadFileIndex:ep,loadDirectory:eg,loadRecentFiles:ev,addToRecentFiles:ej,updateRecentFilePosition:ew,getRecentFilePosition:ek,loadFileContent:eN,loadBlame:ey,handleToggleBlame:eC,handleSelectFile:eS,handleToggle:eM}}({cwd:t});b=tn.selectedPath,D=(0,s.useRef)(null),(0,s.useEffect)(()=>{b&&b!==D.current&&tS(b)&&(D.current=b,x.t4.runFork(tM("/api/lsp/warmup",{cwd:t,filePath:b}).pipe(eh.NLW).pipe(eh.NWQ(()=>eh.rIH))))},[t,b]);let ts=(0,s.useMemo)(()=>{let e=tn.fileContent,t=tn.selectedPath;return e&&"text"===e.type&&"string"==typeof e.content&&t&&(0,P.Hz)(t)?(0,P.xb)(e.content,P.cG):null},[tn.fileContent,tn.selectedPath]),[to,ta]=(0,s.useState)({version:0,collapsed:!1});(0,s.useEffect)(()=>{ta(e=>e.collapsed?{version:e.version+1,collapsed:!1}:e)},[tn.selectedPath]);let tl=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,a]=(0,s.useState)([]),[l,i]=(0,s.useState)(!1),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(new Set),[h,f]=(0,s.useState)({caseSensitive:!1,wholeWord:!1,regex:!1,fileType:""}),[p,g]=(0,s.useState)(null),b=(0,s.useRef)(null),v=(0,s.useCallback)(async r=>{let n=r.trim();if(!n){a([]),g(null);return}if(n.length<2)return void c(tC.A.t("fileBrowser.searchMinChars"));i(!0),c(null);let s=new URLSearchParams({cwd:e,q:r,caseSensitive:String(h.caseSensitive),wholeWord:String(h.wholeWord),regex:String(h.regex),fileType:h.fileType}),o=eh.$mh({try:async()=>{let e=await fetch(`/api/files/search?${s}`),t=await e.json();if(t.error)throw Error(t.error);return t},catch:e=>new ef.uV({message:"content search failed",cause:e})});await x.t4.runPromise(o.pipe(eh.YWq({onSuccess:e=>{a(e.results),g({totalFiles:e.totalFiles,totalMatches:e.totalMatches,truncated:e.truncated}),m(new Set(e.results.map(e=>e.path))),e.results.length>0&&t?.()},onFailure:e=>{c(e.cause instanceof Error?e.cause.message:"Search failed"),a([])}}))),i(!1)},[e,h,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:l,searchError:d,searchExpandedPaths:u,searchOptions:h,setSearchOptions:f,searchStats:p,contentSearchInputRef:b,performContentSearch:v,handleSearchToggle:(0,s.useCallback)(e=>{m(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>eA(!0)}),ti=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(null),[h,f]=(0,s.useState)(!1),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)(new Set),[w,y]=(0,s.useState)([]),[N,C]=(0,s.useState)([]),S=(0,s.useMemo)(()=>{let e=new Set((0,k.Sz)(w));for(let t of g)e.delete(t);return e},[w,g]),L=(0,s.useMemo)(()=>{let e=new Set((0,k.Sz)(N));for(let t of v)e.delete(t);return e},[N,v]),[E,P]=(0,s.useState)(!1),[T,$]=(0,s.useState)(0),R=(0,s.useCallback)(async()=>{a(!0),i(null),await x.t4.runPromise((0,p.lv)(e).pipe(eh.YWq({onSuccess:e=>{n(e);let t=(0,k.Do)(e.staged),r=(0,k.Do)(e.unstaged);y(t),C(r)},onFailure:e=>{i(e.cause instanceof Error?e.cause.message:"Unknown error")}}))),a(!1)},[e]),I=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),F=(0,s.useCallback)(e=>{j(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),B=(0,s.useCallback)((e,r)=>{c({file:e,type:r}),t(e.path)},[t]),D=(0,s.useCallback)(async(e,t,r,n)=>{let s=await x.t4.runPromiseExit(e);"Success"===s._tag?(await R(),(0,M.oR)(t,"success")):(console.error(r,s.cause),(0,M.oR)(n,"error"))},[R]),A=(0,s.useCallback)(t=>D((0,p.Iz)(e,[t]),tC.A.t("toast.staged"),"Error staging file:",tC.A.t("toast.stageFailed")),[e,D]),H=(0,s.useCallback)(t=>D((0,p.X0)(e,[t]),tC.A.t("toast.unstaged"),"Error unstaging file:",tC.A.t("toast.unstageFailed")),[e,D]),W=(0,s.useCallback)(async t=>{0!==t.length&&await D((0,p.Iz)(e,t),tC.A.t("toast.stagedNFiles",{count:t.length}),"Error staging files:",tC.A.t("toast.stageFailed"))},[e,D]),z=(0,s.useCallback)(async t=>{0!==t.length&&await D((0,p.X0)(e,t),tC.A.t("toast.unstagedNFiles",{count:t.length}),"Error unstaging files:",tC.A.t("toast.unstageFailed"))},[e,D]),O=(0,s.useCallback)(async t=>{if(0===t.length)return;let r=t.filter(e=>"untracked"===e.status).map(e=>e.path),n=t.filter(e=>"untracked"!==e.status).map(e=>e.path),s=eh.JkU(function*(){r.length>0&&(yield*(0,p.Ub)(e,r,!0)),n.length>0&&(yield*(0,p.Ub)(e,n,!1))});await D(s,tC.A.t("toast.discardedNFiles",{count:t.length}),"Error discarding files:",tC.A.t("toast.discardFailed"))},[e,D]),_=(0,s.useCallback)(async()=>{r?.unstaged.length&&await D((0,p.Iz)(e,r.unstaged.map(e=>e.path)),tC.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"Error staging all files:",tC.A.t("toast.stageFailed"))},[e,r,D]),q=(0,s.useCallback)(async()=>{r?.staged.length&&await D((0,p.X0)(e,r.staged.map(e=>e.path)),tC.A.t("toast.unstagedNFiles",{count:r.staged.length}),"Error unstaging all files:",tC.A.t("toast.unstageFailed"))},[e,r,D]),V=(0,s.useCallback)(async t=>{let r="untracked"===t.status;await D((0,p.Ub)(e,[t.path],r),r?tC.A.t("toast.deletedFile"):tC.A.t("toast.discardedChanges"),"Error discarding file:",tC.A.t("toast.discardFailed"))},[e,D]),U=(0,s.useCallback)(async()=>{if(!r?.unstaged.length||!await (0,M.lJ)(tC.A.t("git.discardAllConfirm",{count:r.unstaged.length}),{danger:!0}))return;let t=r.unstaged.filter(e=>"untracked"===e.status).map(e=>e.path),n=r.unstaged.filter(e=>"untracked"!==e.status).map(e=>e.path),s=r.unstaged.length,o=eh.JkU(function*(){n.length>0&&(yield*(0,p.Ub)(e,n,!1)),t.length>0&&(yield*(0,p.Ub)(e,t,!0))});await D(o,tC.A.t("toast.discardedNFiles",{count:s}),"Error discarding all:",tC.A.t("toast.discardFailed"))},[e,r,D]);return(0,s.useEffect)(()=>{d?(f(!0),x.t4.runPromiseExit((0,p.w2)(e,d.file.path,d.type)).then(e=>{"Success"===e._tag?m(e.value):console.error("Error fetching diff:",e.cause),f(!1)})):m(null)},[d,e,T]),{status:r,setStatus:n,statusLoading:o,statusError:l,statusSelectedFile:d,statusDiff:u,statusDiffLoading:h,stagedExpandedPaths:S,unstagedExpandedPaths:L,stagedTree:w,setStagedTree:y,unstagedTree:N,setUnstagedTree:C,showStatusDiffPreview:E,setShowStatusDiffPreview:P,fetchStatus:R,handleStagedToggle:I,handleUnstagedToggle:F,handleStatusFileSelect:B,handleStage:A,handleUnstage:H,handleStageFiles:W,handleUnstageFiles:z,handleDiscardFiles:O,handleStageAll:_,handleUnstageAll:q,handleDiscardFile:V,handleDiscardAll:U,refreshDiff:(0,s.useCallback)(()=>$(e=>e+1),[])}}({cwd:t,addToRecentFiles:tn.addToRecentFiles}),td=(0,s.useMemo)(()=>{let e=new Set;if(ti.status){for(let t of ti.status.staged)e.add(t.path);for(let t of ti.status.unstaged)e.add(t.path)}return e},[ti.status]),tc=(0,s.useMemo)(()=>{let e=new Map;if(ti.status){for(let t of ti.status.staged)e.set(t.path,"staged");for(let t of ti.status.unstaged)e.set(t.path,"unstaged")}return e},[ti.status]),tu=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,a]=(0,s.useState)(""),[l,i]=(0,s.useState)([]),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)([]),[h,f]=(0,s.useState)([]),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)(null),[w,y]=(0,s.useState)(null),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(!1),[L,P]=(0,s.useState)(!1),[T,$]=(0,s.useState)(!0),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)(!1),[D,A]=(0,s.useState)(null),H=(0,s.useRef)(null),[W,z]=(0,s.useState)(null),[O,_]=(0,s.useState)(!1),[q,V]=(0,s.useState)(""),[U,K]=(0,s.useState)(""),[Q,G]=(0,s.useState)([]),[J,Y]=(0,s.useState)([]),[X,Z]=(0,s.useState)(new Set),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)(null),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)(!1),[ei,ed]=(0,s.useState)("worktree"),ec=(0,s.useRef)(O);ec.current=O;let eu=(0,s.useRef)(ei);eu.current=ei;let em=(0,s.useRef)(U);em.current=U;let ex=(0,s.useRef)(ee);ex.current=ee;let ef=(0,s.useCallback)(()=>{C(!0),A(null),x.t4.runPromise((0,p.r4)(e).pipe(eh.YWq({onSuccess:e=>{e.local&&e.current?(n(e),a(e.current),e.upstream&&V(e.upstream)):(A(tC.A.t("git.cannotGetBranches")),n(null))},onFailure:e=>{console.error(e),"NotFoundError"===e._tag?A(tC.A.t("git.notGitRepo")):A(tC.A.t("git.getBranchesFailed")),n(null)}}))).finally(()=>C(!1))},[e]),ep=(0,s.useCallback)(t=>{M(!0),c(null),m([]),f([]),j(null),y(null),$(!0),x.t4.runPromise((0,p.Bj)(e,t,E.B_).pipe(eh.YWq({onSuccess:e=>{let t=e.commits||[];i(t),$(t.length>=E.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>M(!1))},[e]),eg=(0,s.useCallback)(()=>{if(L||!T||!o)return;P(!0);let t=l.length;x.t4.runPromise((0,p.Bj)(e,o,E.B_,t).pipe(eh.YWq({onSuccess:e=>{let t=e.commits||[];t.length>0&&i(e=>[...e,...t]),$(t.length>=E.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>P(!1))},[e,o,l.length,L,T]),eb=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&eg()},[eg]),ev=(0,s.useCallback)(t=>{c(t),j(null),y(null),I(!0),x.t4.runPromise((0,p.Zi)(e,t.hash).pipe(eh.YWq({onSuccess:e=>{let t=e.files||[];m(t);let r=(0,k.Do)(t);f(r),b(new Set((0,k.Sz)(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>I(!1))},[e]),ej=(0,s.useCallback)(r=>{d&&(j(r),t(r.path),B(!0),x.t4.runPromise((0,p.Zi)(e,d.hash,r.path).pipe(eh.YWq({onSuccess:e=>y(e),onFailure:e=>{console.error(e)}}))).finally(()=>B(!1)))},[e,d,t]),ew=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ek=(0,s.useCallback)((t,r)=>{eo(!0),et(null),en(null),x.t4.runPromise((0,p.yy)(e,t,void 0,r??eu.current).pipe(eh.YWq({onSuccess:e=>{let t=e.files||[];G(t);let r=(0,k.Do)(t);Y(r),Z(new Set((0,k.Sz)(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>eo(!1))},[e]),ey=(0,s.useCallback)(r=>{et(r),t(r.path),el(!0),x.t4.runPromise((0,p.yy)(e,U,r.path,eu.current).pipe(eh.YWq({onSuccess:e=>en(e),onFailure:e=>{console.error(e)}}))).finally(()=>el(!1))},[e,U,t]),eN=(0,s.useCallback)(()=>{if(!ec.current||"worktree"!==eu.current)return;let t=em.current;if(!t)return;x.t4.runPromise((0,p.yy)(e,t,void 0,"worktree").pipe(eh.YWq({onSuccess:e=>{let t=e.files||[];G(t);let r=(0,k.Do)(t);Y(r),Z(e=>{let t=new Set(e);for(let n of(0,k.Sz)(r))e.has(n)||t.add(n);return t})},onFailure:e=>console.error(e)})));let r=ex.current;r&&x.t4.runPromise((0,p.yy)(e,t,r.path,"worktree").pipe(eh.YWq({onSuccess:e=>en(e),onFailure:e=>console.error(e)})))},[e]),eC=(0,s.useCallback)(e=>{if(eu.current===e)return;eu.current=e,ed(e);let t=em.current;ec.current&&t&&ek(t,e)},[ek]),eS=(0,s.useCallback)(e=>{Z(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eM=(0,s.useCallback)(e=>{if(_(e),e){let e="origin/main";K(e),ek(e)}else G([]),Y([]),et(null),en(null),K("")},[q,ek]);return{branches:r,selectedBranch:o,setSelectedBranch:a,commits:l,setCommits:i,selectedCommit:d,setSelectedCommit:c,historyFiles:u,historyFileTree:h,historyExpandedPaths:g,historySelectedFile:v,historyFileDiff:w,isLoadingBranches:N,isLoadingCommits:S,isLoadingMore:L,hasMoreCommits:T,setHasMoreCommits:$,isLoadingHistoryFiles:R,isLoadingHistoryDiff:F,historyError:D,commitListRef:H,tooltipPos:W,loadBranches:ef,loadCommits:ep,loadMoreCommits:eg,handleCommitListScroll:eb,handleSelectCommit:ev,handleSelectHistoryFile:ej,handleHistoryToggle:ew,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{z({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{z(null)},[]),compareMode:O,toggleCompareMode:eM,compareBaseBranch:U,setCompareBaseBranch:K,upstreamBranch:q,compareFiles:Q,compareFileTree:J,compareExpandedPaths:X,compareSelectedFile:ee,compareFileDiff:er,isLoadingCompareFiles:es,isLoadingCompareDiff:ea,handleSelectCompareFile:ey,handleCompareToggle:eS,loadCompareFiles:ek,compareDiffMode:ei,setCompareDiffMode:eC,refreshCompare:eN}}({cwd:t,addToRecentFiles:tn.addToRecentFiles}),tm=tu.compareFileDiff,tx=tm?.filePath??"",th=(0,s.useMemo)(()=>{if(!tm||tm.isDeleted)return;let e={content:tm.newContent,filePath:tm.filePath};return(0,P.e$)(tm.filePath)?()=>eO(e):tm.filePath.endsWith(".json")?()=>eW(e):void 0},[tm]),tp=(0,s.useCallback)(()=>eO(null),[]),tb=(0,s.useCallback)(()=>eW(null),[]);(0,s.useEffect)(()=>{eO(null)},[tm]);let tw=(0,s.useCallback)(e=>{el?.sendMessage(ea("worktree"===tu.compareDiffMode?"explain.compareFileWorktreeMessage":"explain.compareFileMessage",{base:tu.compareBaseBranch,path:e}))},[el,ea,tu.compareBaseBranch,tu.compareDiffMode]),ty=(0,s.useRef)(!1),tN=(0,s.useCallback)(e=>{tn.setFileContent(t=>t?.type==="text"?{...t,content:e}:t),tn.showEditor||(ty.current=!0,tn.setShowEditor(!0))},[tn]);(0,s.useEffect)(()=>{tn.showEditor&&ty.current&&(eI.current?.markDirty(),ty.current=!1)},[tn.showEditor]);let tL=(0,s.useCallback)(e=>{tn.setShowEditor(!0)},[tn]),tE=(0,s.useCallback)(async()=>{if(!tn.fileContent||"text"!==tn.fileContent.type||!tn.fileContent.content)return;let e=await x.t4.runPromiseExit((0,h.OJ)({cwd:t,path:tn.selectedPath,content:tn.fileContent.content}));try{if("Failure"===e._tag||!e.value.ok)throw Error("Failed to save file");let t=e.value.data?.mtime;t&&tn.setFileContent(e=>e?.type==="text"?{...e,mtime:t}:e),(0,M.oR)(ea("toast.savedSuccess"),"success")}catch{(0,M.oR)(ea("toast.saveFailed"),"error")}},[t,tn]),tF=(0,s.useCallback)(()=>{if(!tn.selectedPath)return;let e=eP.current,t=eT.current;e>0&&tn.updateRecentFilePosition(tn.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[tn]),tB=(0,s.useCallback)(async(e,t)=>{let r=e!==tn.selectedPath;if(r&&tn.showEditor){if(eF.isDirty&&(!await (0,M.lJ)(ea("fileBrowser.saveBeforeSwitch"),{confirmText:ea("fileBrowser.saveAndSwitch"),cancelText:ea("common.cancel")})||(await eI.current?.save(),eI.current?.isDirty)))return;tn.setShowEditor(!1)}r&&tF(),tn.handleSelectFile(e,t)},[tn,tF,eF.isDirty,ea]),tD=(0,s.useMemo)(()=>{let e=tl.contentSearchResults;if(0===e.length)return{files:[],expandDirs:new Set,matchMap:new Map};let t=new Map,r=[];for(let n of e)t.set(n.path,n),r.push(n.path);let n=(0,E.v3)(r),s=new Set((0,E.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[tl.contentSearchResults]),[tA,tH]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{tH(tD.expandDirs)},[tD.expandDirs]);let tW=(0,s.useCallback)(e=>{tH(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),tz=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=tD.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[tD.matchMap]),tO=eD&&tl.contentSearchResults.length>0,[t_,tq]=(0,s.useState)("selected");(0,s.useEffect)(()=>{tq("selected")},[tl.contentSearchResults]);let tV=!!tn.selectedPath&&null!==tS(tn.selectedPath),[tU,tK]=(0,s.useState)(!1),tQ=(0,s.useCallback)(async(e,r)=>{if(!tn.selectedPath||!tV)return;let n=await e9.goToDefinition(tn.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=(0,tI.y)(t,s.file)||s.file;tt.push({filePath:tn.selectedPath,lineNumber:eP.current}),o===tn.selectedPath?tn.setTargetLineNumber(s.line):tB(o,s.line)},[tn,t,tV,e9,tt]),tG=(0,s.useCallback)((e,t,r,n,s)=>{e&&null!==tS(e)&&(tK(t),e7.onTokenMouseEnter(e,r,n,s))},[e7]),tJ=(0,s.useCallback)((e,t,r)=>{tV&&tG(tn.selectedPath,!1,e,t,r)},[tn.selectedPath,tV,tG]),tY=(0,s.useCallback)(e=>{let r=(0,tI.y)(t,e.file)||e.file;tn.selectedPath&&tt.push({filePath:tn.selectedPath,lineNumber:eP.current}),r===tn.selectedPath?tn.setTargetLineNumber(e.line):tB(r,e.line)},[tn,t,tt]),tX=(0,s.useMemo)(()=>{if(!ti.status)return null;let e=new Map,t=e=>{switch(e){case"modified":default:return"M";case"added":case"untracked":return"A";case"deleted":return"D";case"renamed":return"R"}};for(let r of ti.status.staged)e.set(r.path,t(r.status));for(let r of ti.status.unstaged)e.set(r.path,t(r.status));return e},[ti.status]),tZ=(0,s.useMemo)(()=>{if(!ti.status)return null;let e=new Map;for(let t of ti.status.staged)"renamed"===t.status&&t.oldPath&&e.set(t.path,t.oldPath);return e},[ti.status]),t0=(0,s.useCallback)(e=>{ev("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)},[tl.setContentSearchQuery,tl.performContentSearch]),t1=function({cwd:e,selectedPath:t,gitStatusMap:r,renameOldPaths:n,isText:o,refreshKey:a}){let l=t?r?.get(t):void 0,i=o&&("M"===l||"R"===l),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(!1),[h,f]=(0,s.useState)(()=>new Set),g=(0,s.useRef)(new Set),b=i&&!!t&&h.has(t);return(0,s.useEffect)(()=>{!t||g.current.has(t)||!r||o&&(g.current.add(t),i&&f(e=>new Set(e).add(t)))},[t,r,o,i]),(0,s.useEffect)(()=>{if(!b||!t)return void c(null);let r=!1;return m(!0),x.t4.runPromiseExit((0,p.w2)(e,t,"worktree",n?.get(t)).pipe(eh.fRP("explorer.treeFileDiff"))).then(e=>{r||("Success"===e._tag?c(e.value):(console.error("Error fetching tree file diff:",e.cause),c(null)),m(!1))}),()=>{r=!0}},[b,t,e,a,n]),{canDiff:i,showDiff:b,toggleDiff:(0,s.useCallback)(()=>{t&&f(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},[t]),diff:d,isLoadingDiff:u}}({cwd:t,selectedPath:tn.selectedPath,gitStatusMap:tX,renameOldPaths:tZ,isText:tn.fileContent?.type==="text",refreshKey:tn.fileContent?.mtime}),t2="tree"===eb&&t1.showDiff;(0,s.useEffect)(()=>{eC(ek.current)},[]),(0,s.useEffect)(()=>{ev(r)},[r,a]),(0,s.useEffect)(()=>{l&&(ev("search"),tl.setContentSearchQuery(l),tl.performContentSearch(l))},[i]);let t5=(0,s.useCallback)(e=>{ev(e),tn.setBlameSelectedCommit(null),"history"===e&&tu.selectedBranch&&tu.loadCommits(tu.selectedBranch)},[tn,tu.selectedBranch,tu.loadCommits]),t4=(0,s.useCallback)(()=>{if(!tn.selectedPath)return;let e={filePath:tn.selectedPath,lineNumber:eP.current},t=tt.goBack(e);t&&(t.filePath===tn.selectedPath?tn.setTargetLineNumber(t.lineNumber):tB(t.filePath,t.lineNumber))},[tn,tt]),t3=(0,s.useCallback)(()=>{if(!tn.selectedPath)return;let e={filePath:tn.selectedPath,lineNumber:eP.current},t=tt.goForward(e);t&&(t.filePath===tn.selectedPath?tn.setTargetLineNumber(t.lineNumber):tB(t.filePath,t.lineNumber))},[tn,tt]),t6=(0,s.useCallback)(async e=>{let r=e.split("/").pop()||e;"Success"===(await x.t4.runPromiseExit((0,h.__)({cwd:t,path:e})))._tag?(0,M.oR)(ea("toast.copiedName",{name:r}),"success"):(0,M.oR)(ea("toast.copyFailed"),"error")},[t,ea]),t8=(0,s.useCallback)(async e=>{let r=await x.t4.runPromiseExit((0,h.dt)());if("Success"!==r._tag||!r.value.path)return void(0,M.oR)(ea("toast.noFileToPaste"),"info");let n=r.value.path,s=await x.t4.runPromiseExit((0,h.Nn)({cwd:t,targetDir:e,sourceAbsPath:n}));if("Success"===s._tag)(0,M.oR)(ea("toast.pastedFile",{name:s.value.newName}),"success"),tn.loadDirectory(e),tn.loadFileIndex();else{let e="Fail"===s.cause._tag?s.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:ea("toast.pasteFailed");(0,M.oR)(r,"error")}},[t,tn,ea]),t9=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===ep;if(t.ctrlKey&&!t.metaKey&&"Minus"===t.code){if(t.preventDefault(),!r)return;t.shiftKey?t3():t4();return}if((t.metaKey||t.ctrlKey)&&"p"===t.key&&!t.shiftKey&&!t.altKey){t.preventDefault(),r?eE(e=>!e):(eg("explorer"),eE(!0));return}if(r&&(t.metaKey||t.ctrlKey)&&"c"===t.key&&!t.shiftKey){let e=t.target?.tagName,r=window.getSelection()?.toString();if(("tree"===eb||"recent"===eb)&&tn.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),t6(tn.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===eb||"recent"===eb)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),t8((0,E.S7)(tn.selectedPath,tn.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(eH){t.preventDefault(),e8.open();return}if(tn.previewMarkdown&&tn.selectedPath&&(0,P.Hz)(tn.selectedPath)){t.preventDefault(),e3.open();return}}if(r&&"Escape"===t.key){if(eL)return void eE(!1);if(e8.isVisible)return void e8.close();if(e3.isVisible)return void e3.close();if(ez)return void eO(null);if(eH)return void eW(null);let t=Date.now();if(t-t9.current<3e3)return;t9.current=t,te.visible?te.closeReferences():eD?eA(!1):tn.blameSelectedCommit?tn.setBlameSelectedCommit(null):tn.showBlame?tn.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,tn.showBlame,tn.blameSelectedCommit,tn,eL,te.visible,te.closeReferences,eD,t4,t3,e3,eH,ez,e8,eb,t6,t8,ep,eg]),(0,s.useEffect)(()=>{tn.loadFiles(),tn.loadFileIndex(),tn.loadRecentFiles(),ti.fetchStatus(),tu.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{ti.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[ti.fetchStatus]);let t7=(0,s.useRef)(tr),re=(0,s.useRef)(tr);(0,s.useEffect)(()=>{tr&&!re.current?re.current=!0:tr&&!t7.current&&(tn.loadFiles(),tn.loadFileIndex(),tn.loadRecentFiles(),ti.fetchStatus(),tu.loadBranches()),t7.current=tr},[tr]),(0,s.useEffect)(()=>{tu.selectedBranch&&tu.loadCommits(tu.selectedBranch)},[tu.selectedBranch,tu.loadCommits]);let rt=(0,s.useRef)(eb),rr=(0,s.useRef)(!1);(0,s.useEffect)(()=>{let e=rt.current;if(rt.current=eb,"tree"===eb&&rr.current){rr.current=!1;return}if(("tree"===eb||"recent"===eb)&&tn.recentFiles.length>0){let t=tn.recentFiles[0].path;tn.selectedPath&&("status"!==e&&"history"!==e||tn.selectedPath===t)||(tn.setShouldScrollToSelected(!0),tB(t))}},[eb,tn.recentFiles,tn.selectedPath,tB,tn]);let rn=(0,s.useRef)(tu.selectedBranch);rn.current=tu.selectedBranch;let rs=(0,s.useRef)(tn.selectedPath);rs.current=tn.selectedPath;let ro=(0,s.useRef)(tn.fileContent?.type);ro.current=tn.fileContent?.type;let ra=(0,s.useCallback)(async e=>{try{let{data:r}=e;if(!Array.isArray(r))return;let n=r.some(e=>"git"===e.type),s=r.some(e=>"file"===e.type),o=[];if((s||n)&&(o.push(x.t4.runPromise((0,h.mP)(t)).then(e=>{e.error||tn.setFiles(t=>(0,E.HR)(e.files??[],t))}).catch(()=>{})),o.push(x.t4.runPromise((0,h.DZ)(t)).then(e=>{e.paths&&tn.setFileIndex(e.paths)}).catch(()=>{})),o.push(x.t4.runPromise((0,h.r9)(t)).then(e=>{tn.setRecentFiles(e.files??[])}).catch(()=>{}))),n||s){o.push(x.t4.runPromise((0,p.lv)(t)).then(e=>{ti.setStatus(e);let t=(0,k.Do)(e.staged),r=(0,k.Do)(e.unstaged);ti.setStagedTree(t),ti.setUnstagedTree(r)}).catch(()=>{})),ti.refreshDiff(),tu.refreshCompare(),n&&tu.loadBranches();let e=rn.current;e&&o.push(x.t4.runPromise((0,p.Bj)(t,e,E.B_)).then(e=>{let t=e.commits??[];tu.setCommits(t),tu.setHasMoreCommits(t.length>=E.B_)}).catch(()=>{}))}let a=rs.current,l=ro.current;a&&"text"===l&&o.push(x.t4.runPromise((0,f.K)(t,a)).then(e=>{let t=e.ok?e.data:null;t&&"string"==typeof t.content&&tn.setFileContent({type:"text",content:t.content,size:t.size,mtime:t.mtimeMs,...t.isSymlink?{isSymlink:!0,symlinkTarget:t.symlinkTarget}:{}})}).catch(()=>{})),await Promise.all(o)}catch(e){console.error("File watch handler error:",e)}},[t]);(0,et.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:ra,enabled:tr});let rl=(0,s.useCallback)(e=>{tB(e),tn.setShouldScrollToSelected(!0),ev("tree")},[tn,tB]),ri=(0,s.useRef)(tB);(0,s.useEffect)(()=>{ri.current=tB},[tB]);let rd=(0,s.useRef)(null),{setPreviewMarkdown:rc,setPreviewHtml:ru,setShouldScrollToSelected:rm}=tn;(0,s.useEffect)(()=>{!d||tn.isLoadingFiles||rd.current!==d.nonce&&(rd.current=d.nonce,rr.current=!0,ew("code"),ev("tree"),ru(!1),null!=d.lineNumber&&rc(!1),ri.current(d.path,d.lineNumber),rm(!0))},[d,tn.isLoadingFiles,rc,ru,rm]);let rx=(0,s.useCallback)(({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,M.oR)(ea("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:ea("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),rl(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:ea("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]}),[t,rl,ea]),rh=(0,s.useCallback)(({focalFile:e})=>"tree"===eb&&t1.canDiff&&e===tn.selectedPath?(0,n.jsxs)(n.Fragment,{children:[t1.showDiff&&(0,n.jsx)(j.y,{value:eK,onChange:eQ}),(0,n.jsx)("button",{onClick:t1.toggleDiff,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${t1.showDiff?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,title:t1.showDiff?ea("fileBrowser.exitDiff"):ea("fileBrowser.viewDiff"),children:ea("common.diff")})]}):null,[eb,t1.canDiff,t1.showDiff,t1.toggleDiff,tn.selectedPath,eK,ea]),[rf,rp]=(0,s.useState)(null),rg=(0,s.useCallback)((e,t)=>{tn.setPreviewMarkdown(!0),tn.setPreviewHtml(!1),rl(e),rp(t),t&&setTimeout(()=>rp(null),400)},[tn,rl]);return(0,n.jsxs)(A.SU,{container:eN,children:[(0,n.jsxs)("div",{ref:ek,className:"bg-card w-full h-full flex flex-col relative",children:[(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 flex flex-col overflow-hidden",style:{width:eY},children:[(0,n.jsxs)("div",{className:"flex border-b border-border",children:[(0,n.jsx)("button",{onClick:()=>t5("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===eb?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:ea("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>t5("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===eb?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:ea("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>t5("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===eb?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:ea("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>t5("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===eb?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:ea("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>t5("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===eb?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:ea("fileBrowser.historyTab")})]}),"tree"===eb&&(0,n.jsxs)("div",{className:"p-2 border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:tn.searchInputRef,type:"text",value:tn.searchQuery,onChange:e=>tn.setSearchQuery(e.target.value),placeholder:ea("fileBrowser.searchFiles"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),tn.searchQuery&&(0,n.jsx)("button",{onClick:()=>{tn.setSearchQuery(""),tn.searchInputRef.current?.focus()},className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:ea("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>tn.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${tn.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:tn.searchExactMatch?ea("fileBrowser.exactMatchOn"):ea("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>tn.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:ea("fileBrowser.refreshTree"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:()=>tn.searchTreeExpandedPaths?tn.setSearchTreeExpandedPaths(new Set):tn.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:ea("fileBrowser.collapseAll"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})]})]}),"search"===eb&&(0,n.jsxs)("div",{className:"p-2 border-b border-border space-y-2",children:[(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 relative",children:[(0,n.jsx)("input",{ref:tl.contentSearchInputRef,type:"text",value:tl.contentSearchQuery,onChange:e=>tl.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&tl.performContentSearch(tl.contentSearchQuery)},placeholder:ea("fileBrowser.searchFileContent"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),tl.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>{tl.setContentSearchQuery(""),tl.contentSearchInputRef.current?.focus()},className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:ea("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:()=>tl.performContentSearch(tl.contentSearchQuery),disabled:tl.isSearching||!tl.contentSearchQuery.trim(),className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",children:tl.isSearching?"...":ea("common.search")})]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 text-xs",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:tl.searchOptions.caseSensitive,onChange:e=>tl.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:ea("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:tl.searchOptions.wholeWord,onChange:e=>tl.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:ea("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:tl.searchOptions.regex,onChange:e=>tl.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:ea("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:tl.searchOptions.fileType,onChange:e=>tl.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:ea("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground"})]})]}),"history"===eb&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:tu.compareMode?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0 px-3 py-1.5 text-sm border border-border rounded bg-secondary text-foreground flex items-center gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:tu.branches?.current||"HEAD"}),(0,n.jsx)("div",{className:"flex flex-shrink-0 items-center rounded border border-border overflow-hidden text-xs",children:["head","worktree"].map(e=>(0,n.jsx)("button",{onClick:()=>tu.setCompareDiffMode(e),className:`px-1.5 py-0.5 transition-colors ${tu.compareDiffMode===e?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:ea("head"===e?"fileBrowser.compareScopeHeadHint":"fileBrowser.compareScopeWorktreeHint"),children:ea("head"===e?"fileBrowser.compareScopeHead":"fileBrowser.compareScopeWorktree")},e))})]}),(0,n.jsx)("button",{onClick:()=>tu.toggleCompareMode(!1),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors bg-brand text-white",title:ea("fileBrowser.compareModeOff"),children:ea("fileBrowser.compareMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0 pl-1",children:"vs"}),(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(tj,{branches:tu.branches,selectedBranch:tu.compareBaseBranch,onSelect:e=>{tu.setCompareBaseBranch(e),tu.loadCompareFiles(e)},isLoading:tu.isLoadingBranches,pinnedBranches:["origin/main",...tu.upstreamBranch&&"origin/main"!==tu.upstreamBranch?[tu.upstreamBranch]:[]]})})]})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"flex-1 min-w-0",children:(0,n.jsx)(tj,{branches:tu.branches,selectedBranch:tu.selectedBranch,onSelect:e=>{tu.setSelectedBranch(e)},isLoading:tu.isLoadingBranches,pinnedBranches:["origin/main",...tu.upstreamBranch&&"origin/main"!==tu.upstreamBranch?[tu.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>tu.toggleCompareMode(!0),className:"flex-shrink-0 px-2.5 py-1.5 text-xs font-medium rounded-lg transition-colors text-muted-foreground hover:text-foreground hover:bg-hover border border-border",title:ea("fileBrowser.compareModeOn"),children:ea("fileBrowser.compareMode")})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col",children:[(0,n.jsxs)("div",{className:`flex-1 flex flex-col min-h-0 ${"tree"===eb?"":"hidden"}`,children:[tn.creatingItem&&(0,n.jsxs)("div",{className:"px-2 py-1.5 border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:tn.creatingItem.parentPath?ea("fileBrowser.createFileIn",{path:tn.creatingItem.parentPath}):ea("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:ea("fileBrowser.fileName"),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring",onCompositionStart:()=>{ey.current=!0},onCompositionEnd:()=>{ey.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if(ey.current)return;let r=e.target.value.trim();if(!r)return;let n=tn.creatingItem.parentPath,s=n?`${n}/${r}`:r,o=await x.t4.runPromiseExit((0,h.OJ)({cwd:t,path:s,content:""}));if("Success"===o._tag&&o.value.ok)(0,M.oR)(ea("toast.createdFile",{name:r}),"success"),tn.setCreatingItem(null),tn.loadDirectory(n),tn.loadFileIndex(),n&&tn.setExpandedPaths(e=>new Set([...e,n])),tB(s);else if("Success"===o._tag){let e=o.value.data?.error;(0,M.oR)(e||ea("toast.createFailed"),"error")}else(0,M.oR)(ea("toast.createFailed"),"error")}else"Escape"===e.key&&tn.setCreatingItem(null)},onBlur:()=>tn.setCreatingItem(null)})]}),tn.isLoadingFiles&&0===tn.files.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:ea("common.loading")}):tn.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:tn.fileError}):(0,n.jsx)(O,{files:tn.files,selectedPath:tn.selectedPath,expandedPaths:tn.effectiveExpandedPaths,matchedPaths:tn.matchedPaths,gitStatusMap:tX,loadingDirs:tn.loadingDirs,onSelect:e=>{tn.setShouldScrollToSelected(!1),tB(e)},onToggle:tn.handleToggle,cwd:t,shouldScrollToSelected:tn.shouldScrollToSelected,onScrolledToSelected:()=>tn.setShouldScrollToSelected(!1),onCreateFile:e=>tn.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>eM({path:e,isDirectory:t,name:r}),onRefresh:()=>tn.loadFiles(),onCopyFile:t6,onPaste:t8,onExplain:el?ei:void 0,explainDisabled:el?.isLoading})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===eb?"":"hidden"}`,children:tl.isSearching?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):tl.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:tl.searchError}):0===tl.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:tl.contentSearchQuery?ea("fileBrowser.noContentSearchResults"):ea("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[tl.searchStats&&(0,n.jsxs)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground border-b border-border flex-shrink-0",children:[ea("fileBrowser.nFilesNMatches",{files:tl.searchStats.totalFiles,matches:tl.searchStats.totalMatches}),tl.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",ea("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(O,{files:tD.files,selectedPath:tn.selectedPath,expandedPaths:tA,onSelect:e=>{let t=tD.matchMap.get(e);tB(e,t?.matches[0]?.lineNumber),eD||eA(!0)},onToggle:tW,cwd:t,onExplain:el?ei:void 0,explainDisabled:el?.isLoading,renderActions:tz,className:"flex-1 overflow-y-auto py-1 min-w-max"})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"recent"===eb?"":"hidden"}`,children:0===tn.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:ea("fileBrowser.noRecentFiles")}):(0,n.jsx)(O,{files:tn.recentFilesTree,selectedPath:tn.selectedPath,expandedPaths:tn.recentTreeDirPaths,onSelect:tB,onToggle:E.tE,cwd:t,onExplain:el?ei:void 0,explainDisabled:el?.isLoading})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===eb?"":"hidden"}`,children:ti.statusLoading?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):ti.statusError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center p-4",children:(0,n.jsx)("span",{className:"text-red-11 text-sm",children:ti.statusError})}):(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:ea("fileBrowser.stagingArea",{count:ti.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>ti.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:ea("fileBrowser.refreshChanges"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),ti.status&&ti.status.staged.length>0&&(0,n.jsx)(k.ab,{files:ti.status.staged,className:"ml-1"})]}),(ti.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:ti.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:ea("fileBrowser.unstageAll")})]}),(0,n.jsx)(k.VO,{files:ti.stagedTree,selectedPath:ti.statusSelectedFile?.type==="staged"?ti.statusSelectedFile.file.path:null,expandedPaths:ti.stagedExpandedPaths,onSelect:e=>e.file&&ti.handleStatusFileSelect(e.file,"staged"),onToggle:ti.handleStagedToggle,cwd:t,showChanges:!0,showChangeClass:!0,hideIndicatorsOnHover:!0,emptyMessage:ea("fileBrowser.noStagedFiles"),className:"py-1",onExplain:el?ed:void 0,explainDisabled:el?.isLoading,renderActions:e=>{if(e.isDirectory){let t=(0,k.wI)(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ti.handleUnstageFiles(t.map(e=>e.path))},className:"hidden group-hover:block p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-colors",title:ea("fileBrowser.unstageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}return(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ti.handleUnstage(e.path)},className:"hidden group-hover:block p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-colors",title:ea("fileBrowser.unstageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20 12H4"})})})}})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:ea("fileBrowser.workspace",{count:ti.status?.unstaged.length||0})}),ti.status&&ti.status.unstaged.length>0&&(0,n.jsx)(k.ab,{files:ti.status.unstaged,className:"ml-1"})]}),(ti.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:ti.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:ea("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:ti.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:ea("fileBrowser.stageAll")})]})]}),(0,n.jsx)(k.VO,{files:ti.unstagedTree,selectedPath:ti.statusSelectedFile?.type==="unstaged"?ti.statusSelectedFile.file.path:null,expandedPaths:ti.unstagedExpandedPaths,onSelect:e=>e.file&&ti.handleStatusFileSelect(e.file,"unstaged"),onToggle:ti.handleUnstagedToggle,cwd:t,showChanges:!0,showChangeClass:!0,hideIndicatorsOnHover:!0,emptyMessage:ea("fileBrowser.noUnstagedChanges"),className:"py-1",onExplain:el?ec:void 0,explainDisabled:el?.isLoading,renderActions:e=>{if(e.isDirectory){let t=(0,k.wI)(e);if(0===t.length)return null;let r=t.map(e=>e.file).filter(Boolean);return(0,n.jsxs)("div",{className:"hidden group-hover:flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ti.handleDiscardFiles(r)},className:"p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-colors",title:ea("fileBrowser.discardNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ti.handleStageFiles(t.map(e=>e.path))},className:"p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-colors",title:ea("fileBrowser.stageNFiles",{count:t.length}),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]})}return e.file?(0,n.jsxs)("div",{className:"hidden group-hover:flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ti.handleDiscardFile(e.file)},className:"p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-colors",title:ea("fileBrowser.discardChanges"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ti.handleStage(e.path)},className:"p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-colors",title:ea("fileBrowser.stageFile"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})})]}):null}})]})]})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"history"===eb?"":"hidden"}`,children:tu.historyError?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-foreground-faint mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,n.jsx)("p",{className:"text-muted-foreground",children:tu.historyError})]})}):tu.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:tu.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:ea("fileBrowser.loadingDiff")}):0===tu.compareFiles.length?(0,n.jsxs)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:[(0,n.jsx)("div",{children:ea("fileBrowser.noDiffFiles")}),"head"===tu.compareDiffMode&&(0,n.jsx)("button",{onClick:()=>tu.setCompareDiffMode("worktree"),className:"mt-2 text-xs text-brand hover:underline",children:ea("fileBrowser.noDiffFilesHeadHint")})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(k.WY,{files:tu.compareFiles,label:ea("worktree"===tu.compareDiffMode?"fileBrowser.nFilesChangedWorktree":"fileBrowser.nFilesChanged",{count:tu.compareFiles.length,branch:tu.compareBaseBranch})}),(0,n.jsx)(k.VO,{files:tu.compareFileTree,expandedPaths:tu.compareExpandedPaths,onToggle:tu.handleCompareToggle,selectedPath:tu.compareSelectedFile?.path||null,onSelect:e=>{e.file&&tu.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0,showChangeClass:!0,onExplain:el?tw:void 0,explainDisabled:el?.isLoading})]})}):(0,n.jsx)("div",{ref:tu.commitListRef,className:"flex-1 overflow-y-auto",onScroll:tu.handleCommitListScroll,children:tu.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:ea("fileBrowser.loadingCommits")}):0===tu.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:ea("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[tu.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>tu.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-hover ${tu.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[e.changeClass&&(0,n.jsx)(u.N,{cls:e.changeClass}),(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-foreground-subtle","data-tooltip":e.date,children:[e.relativeDate," \xb7 ",(0,E.r6)(e.date)]})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5","data-tooltip":e.subject,children:e.subject}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e.author})]},e.hash)),tu.isLoadingMore&&(0,n.jsx)("div",{className:"p-3 text-center",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),!tu.hasMoreCommits&&tu.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-foreground-subtle",children:ea("fileBrowser.allLoaded",{count:tu.commits.length})})]})})})]})]}),(0,n.jsx)("div",{onPointerDown:e0,onPointerMove:e1,onPointerUp:e2,onPointerCancel:e2,className:"w-[5px] flex-shrink-0 relative cursor-col-resize group",children:(0,n.jsx)("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border group-hover:bg-brand transition-colors"})}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[("tree"===eb||"search"===eb||"recent"===eb)&&(tn.blameSelectedCommit?(0,n.jsx)(B,{isOpen:!0,onClose:()=>tn.setBlameSelectedCommit(null),commit:tn.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:tn.selectedPath||void 0,onLocateInTree:rl,onContentSearch:e=>{ev("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}}):"map"===ej?t2&&t1.diff?(0,n.jsx)(tf,{cwd:t,filePath:t1.diff.filePath,oldContent:t1.diff.oldContent,newContent:t1.diff.newContent,isNew:t1.diff.isNew,isDeleted:t1.diff.isDeleted,changedFiles:td,fileGitStatusMap:tc,compact:"compact"===eK,enableComments:!0,onSwitchToCode:()=>ew("code"),onContentSearch:t0,headerExtraLeft:rx,headerExtraRight:rh}):(0,n.jsx)(e5,{cwd:t,highlightedFilePath:tn.selectedPath,changedFiles:td,onSwitchToCode:()=>ew("code"),enableComments:!0,onContentSearch:t0,headerExtraLeft:rx,headerExtraRight:rh}):tn.selectedPath?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 border-b border-border flex-shrink-0 flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate",children:tn.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${tn.selectedPath}`),(0,M.oR)(ea("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:ea("common.copyAbsPath"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),rl(tn.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors flex-shrink-0",title:ea("fileBrowser.locateInTree"),children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeWidth:2,d:"M12 2v4m0 12v4M2 12h4m12 0h4"})]})})]}),(0,n.jsx)("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:tn.showEditor?(0,n.jsxs)(n.Fragment,{children:[eF.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:ea("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>eI.current?.save(),disabled:!eF.isDirty||eF.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${eF.isDirty&&!eF.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:eF.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):ea("common.save")}),(0,n.jsx)("button",{onClick:()=>eI.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:ea("fileBrowser.closeEdit"),children:ea("fileBrowser.closeBtn")})]}):t2?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.y,{value:eK,onChange:eQ}),(0,n.jsx)(w.q,{value:eG,onChange:eJ}),!(0,P.e$)(tn.selectedPath)&&!(0,P.aR)(tn.selectedPath)&&!(0,P.Hz)(tn.selectedPath)&&!(0,P.Zy)(tn.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ew("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:ea("blockViewer.viewerToggle.toBlock"),children:ea("common.codeMap")}),(0,n.jsx)("button",{onClick:t1.toggleDiff,className:"px-1.5 py-0.5 text-xs rounded transition-colors bg-brand text-white",children:ea("fileBrowser.exitDiff")})]}):(0,n.jsxs)(n.Fragment,{children:["tree"===eb&&t1.canDiff&&(0,n.jsx)("button",{onClick:t1.toggleDiff,className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:ea("fileBrowser.viewDiff"),children:ea("common.diff")}),tn.fileContent?.type==="text"&&(0,P.Hz)(tn.selectedPath)&&tn.previewMarkdown&&!tn.showBlame&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:[!0,!1].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),ta(t=>({version:t.version+1,collapsed:e}))},className:`px-2 py-0.5 text-xs transition-colors ${to.collapsed===e?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:ea(e?"fileBrowser.collapseAllJson":"fileBrowser.expandAllJson")},String(e)))}),tn.fileContent?.type==="text"&&((0,P.e$)(tn.selectedPath)||(0,P.aR)(tn.selectedPath)||(0,P.Hz)(tn.selectedPath)||(0,P.Zy)(tn.selectedPath))&&(W=(H=(0,P.aR)(tn.selectedPath))?tn.previewHtml:tn.previewMarkdown,(0,n.jsx)("button",{onClick:()=>H?tn.setPreviewHtml(e=>!e):tn.setPreviewMarkdown(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${W?"bg-brand text-white":"text-muted-foreground hover:bg-hover"}`,children:W?ea("fileBrowser.exitPreview"):ea("common.preview")})),tn.fileContent?.type==="text"&&((0,P.C_)(tn.selectedPath||"")||(0,P.OG)(tn.selectedPath||""))&&(Z=(z=tn.selectedPath||"").startsWith("/")?z:t?`${t.replace(/\/$/,"")}/${z}`:z,en=(0,P.OG)(z),(0,n.jsx)("button",{onClick:()=>void(en?ex(Z):em(Z)),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:ea(en?"bots.addTooltip":"skills.addTooltip"),children:(0,n.jsx)(V.A,{className:"w-3.5 h-3.5"})})),tn.fileContent?.type==="text"&&(0,P.aR)(tn.selectedPath)&&(eo=(es=tn.selectedPath||"").startsWith("/")?es:t?`${t.replace(/\/$/,"")}/${es}`:es,(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>eu(eo),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:ea("htmlApps.addTooltip"),children:(0,n.jsx)(V.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:eo}})),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:ea("common.openInConsole"),children:(0,n.jsx)(U.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>{let e=(0,Q.Xe)(eo);window.open((0,Q.PB)(e,window.location.origin),"_blank")},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover flex items-center",title:ea("browser.openInNewWindow"),children:(0,n.jsx)(K.A,{className:"w-3.5 h-3.5"})})]})),tn.fileContent?.type==="text"&&!(tn.previewMarkdown&&((0,P.e$)(tn.selectedPath)||(0,P.Hz)(tn.selectedPath)||(0,P.Zy)(tn.selectedPath))||tn.previewHtml&&(0,P.aR)(tn.selectedPath))&&(0,n.jsx)("button",{onClick:tn.handleToggleBlame,disabled:tn.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${tn.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-hover"} disabled:opacity-50`,title:ea("fileBrowser.viewBlame"),children:tn.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),tn.fileContent?.type==="text"&&!(tn.previewMarkdown&&((0,P.e$)(tn.selectedPath)||(0,P.Hz)(tn.selectedPath)||(0,P.Zy)(tn.selectedPath))||tn.previewHtml&&(0,P.aR)(tn.selectedPath))&&(0,n.jsx)("button",{onClick:()=>tn.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:ea("fileBrowser.editFile"),children:ea("common.edit")}),tn.fileContent?.type==="text"&&tn.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(tn.fileContent.content),(0,M.oR)(ea("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:ea("fileBrowser.copyFileContent"),children:ea("common.copy")}),tn.fileContent?.type==="text"&&!(0,P.e$)(tn.selectedPath)&&!(0,P.aR)(tn.selectedPath)&&!(0,P.Hz)(tn.selectedPath)&&!(0,P.Zy)(tn.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ew("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-hover",title:ea("blockViewer.viewerToggle.toBlock"),children:ea("common.codeMap")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:tn.isLoadingContent?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):tn.fileContent?"text"===tn.fileContent.type&&"string"==typeof tn.fileContent.content?t2?t1.isLoadingDiff&&!t1.diff?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):t1.diff?"unified"===eG?(0,n.jsx)(g.xU,{oldContent:t1.diff.oldContent,newContent:t1.diff.newContent,filePath:t1.diff.filePath,cwd:t,enableComments:!0,compact:"compact"===eK,onContentSearch:t0,onTokenHover:(e,t,r)=>tG(t1.diff?.filePath,!0,e,t,r),onTokenHoverLeave:e7.onTokenMouseLeave,onTokenHoverCancel:e7.clearHover}):(0,n.jsx)(g.xZ,{oldContent:t1.diff.oldContent,newContent:t1.diff.newContent,filePath:t1.diff.filePath,isNew:t1.diff.isNew,isDeleted:t1.diff.isDeleted,cwd:t,enableComments:!0,compact:"compact"===eK,onContentSearch:t0,onTokenHover:(e,t,r)=>tG(t1.diff?.filePath,!0,e,t,r),onTokenHoverLeave:e7.onTokenMouseLeave,onTokenHoverCancel:e7.clearHover}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{children:ea("fileBrowser.diffLoadFailed")}),(0,n.jsx)("button",{onClick:t1.toggleDiff,className:"mt-2 text-brand hover:underline text-sm",children:ea("fileBrowser.exitDiff")})]})}):tn.showBlame&&tn.blameError?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-red-11",children:tn.blameError}),(0,n.jsx)("button",{onClick:()=>tn.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:ea("fileBrowser.backToPreview")})]})}):tn.showBlame&&0===tn.blameLines.length&&tn.isLoadingBlame?(0,n.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):tn.previewMarkdown&&(0,P.Hz)(tn.selectedPath)&&!tn.showBlame?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-background text-foreground",children:[(0,n.jsx)(T._,{search:e3}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:e4,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:(0,n.jsx)(P.d9.Provider,{value:to,children:ts})})})]}):tn.previewMarkdown&&(0,P.Zy)(tn.selectedPath)&&!tn.showBlame?(0,n.jsx)(q.C0,{content:tn.fileContent.content,filePath:tn.selectedPath,className:"h-full"}):tn.previewMarkdown&&(0,P.e$)(tn.selectedPath)&&!tn.showBlame?(0,n.jsx)("div",{className:"h-full flex flex-col",children:(0,n.jsx)(v.M,{content:tn.fileContent.content,filePath:tn.selectedPath,cwd:t,embedded:!0,onLocalFileLink:rg,scrollToAnchor:rf})}):tn.previewHtml&&(0,P.aR)(tn.selectedPath)&&!tn.showBlame?(0,n.jsx)(X.O,{content:tn.fileContent.content,filePath:tn.selectedPath,cwd:t,onContentSearch:e=>{ev("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}}):(0,n.jsx)(_.Cv,{ref:eI,content:tn.fileContent.content,filePath:tn.selectedPath,cwd:t,enableComments:!0,scrollToLine:e$??tn.targetLineNumber,scrollToLineAlign:null!=e$?"start":tn.targetScrollAlign,onScrollToLineComplete:()=>{eR(null),tn.setTargetLineNumber(null)},highlightKeyword:"search"===eb?tl.contentSearchQuery:null,visibleLineRef:eP,viStateRef:eT,initialCursorLine:tn.initialCursorLine,initialCursorCol:tn.initialCursorCol,onInitialCursorSet:()=>{tn.setInitialCursorLine(null),tn.setInitialCursorCol(null)},onCmdClick:tV?tQ:void 0,onTokenHover:tV?tJ:void 0,onTokenHoverLeave:tV?e7.onTokenMouseLeave:void 0,onTokenHoverCancel:tV?e7.clearHover:void 0,blameLines:tn.showBlame&&tn.blameLines.length>0?tn.blameLines:void 0,inlineBlameLines:tn.blameLines.length>0?tn.blameLines:void 0,onSelectCommit:tn.setBlameSelectedCommit,editable:tn.showEditor,initialMtime:tn.fileContent.mtime,onEditorClose:e=>{tn.setShowEditor(!1),eR(e)},onSaved:()=>{let e=eP.current??1;tn.loadFileContent(tn.selectedPath),tn.setShowEditor(!1),eR(e)},onEditorStateChange:eB,viMode:!0,onContentMutate:tN,onEnterInsertMode:tL,onViSave:tE,onContentSearch:e=>{ev("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}}):"image"===tn.fileContent.type&&tn.selectedPath?(0,n.jsx)(tg.I,{cwd:t,path:tn.selectedPath,refreshKey:tn.fileContent.mtime,alt:tn.selectedPath}):"pdf"===tn.fileContent.type&&tn.selectedPath?(0,n.jsx)(tk,{cwd:t,path:tn.selectedPath,refreshKey:tn.fileContent.mtime}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-foreground-faint mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),(0,n.jsx)("p",{children:tn.fileContent.message||ea("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:ea("fileBrowser.selectFileToPreview")})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("svg",{className:"w-16 h-16 mx-auto text-foreground-faint mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("p",{children:ea("fileBrowser.selectFileToPreview")})]})})),"status"===eb&&(ti.statusSelectedFile&&ti.statusDiff?(0,n.jsx)(tv,{cwd:t,selected:ti.statusSelectedFile,diff:ti.statusDiff,showMarkdownPreview:ti.showStatusDiffPreview,setShowMarkdownPreview:ti.setShowStatusDiffPreview,changedFiles:td,fileGitStatusMap:tc,onContentSearch:e=>{ev("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)},locateInTree:rl,setJsonPreview:eW,onTokenHover:(e,t,r)=>tG(ti.statusDiff?.filePath,!0,e,t,r),onTokenHoverLeave:e7.onTokenMouseLeave,onTokenHoverCancel:e7.clearHover}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-foreground-subtle",children:(0,n.jsx)("span",{children:ea("fileBrowser.selectFileToViewDiff")})})),"history"===eb&&!tu.historyError&&(tu.compareMode?tu.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:ea("fileBrowser.loadingDiffContent")}):tu.compareFileDiff?(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden relative",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border flex-shrink-0",children:[(0,n.jsx)(L,{cwd:t,filePath:tu.compareFileDiff.filePath,onLocateInTree:rl}),!(0,E.u)(tu.compareFileDiff.filePath)&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[(0,n.jsx)(j.y,{value:e_,onChange:eq}),(0,n.jsx)(w.q,{value:eV,onChange:eU})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,E.u)(tu.compareFileDiff.filePath)?(0,n.jsx)(C,{cwd:t,filePath:tu.compareFileDiff.filePath,oldRev:tu.compareFileDiff.oldRev??(tu.compareFileDiff.isNew?null:tu.compareBaseBranch),newRev:"worktree"===tu.compareDiffMode?null:tu.compareFileDiff.newRev??(tu.compareFileDiff.isDeleted?null:"HEAD"),newNode:tu.compareFileDiff.newWorktree?(0,n.jsx)(tg.I,{cwd:t,path:tu.compareFileDiff.filePath}):void 0}):"unified"===eV?(0,n.jsx)(g.xU,{oldContent:tu.compareFileDiff.oldContent,newContent:tu.compareFileDiff.newContent,filePath:tu.compareFileDiff.filePath,cwd:t,enableComments:!0,compact:"compact"===e_,onPreview:th,previewLabel:tx.endsWith(".json")?ea("common.readable"):ea("common.preview"),onContentSearch:e=>{ev("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}}):(0,n.jsx)(g.xZ,{oldContent:tu.compareFileDiff.oldContent,newContent:tu.compareFileDiff.newContent,filePath:tu.compareFileDiff.filePath,isNew:tu.compareFileDiff.isNew,isDeleted:tu.compareFileDiff.isDeleted,cwd:t,enableComments:!0,compact:"compact"===e_,onPreview:th,previewLabel:tx.endsWith(".json")?ea("common.readable"):ea("common.preview"),onContentSearch:e=>{ev("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}})}),ez&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-scrim",onClick:()=>eO(null),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-lv3 w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(v.M,{content:ez.content,filePath:ez.filePath,cwd:t,onClose:tp})})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-foreground-subtle",children:(0,n.jsx)("span",{children:tu.compareFiles.length>0?ea("fileBrowser.selectFileToViewDiff"):ea("fileBrowser.clickCompareToLoad")})}):tu.selectedCommit?(0,n.jsx)(B,{isOpen:!0,onClose:()=>tu.setSelectedCommit(null),commit:tu.selectedCommit,cwd:t,embedded:!0,onLocateInTree:rl,onContentSearch:e=>{ev("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-foreground-subtle",children:(0,n.jsx)("span",{children:ea("fileBrowser.selectCommitToView")})})),eH&&(0,n.jsx)($,{preview:eH,onClose:tb,search:e8,preRef:e6})]})]}),eL&&(0,n.jsx)(ee,{files:tn.files,fileIndex:tn.fileIndex,recentFiles:tn.recentFilePaths,onSelectFile:e=>{tB(e),tn.setShouldScrollToSelected(!0),ev("tree")},onClose:()=>eE(!1)}),(tO||te.visible)&&(0,n.jsxs)("div",{className:`flex ${te.visible&&tO?"":"flex-col"}`,children:[tO&&(0,n.jsx)("div",{className:te.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(t$,{results:tl.contentSearchResults,loading:tl.isSearching,totalMatches:tl.searchStats?.totalMatches??0,onSelect:(e,t)=>{tn.selectedPath&&tt.push({filePath:tn.selectedPath,lineNumber:eP.current}),ew("code"),tB(e,t)},onClose:()=>eA(!1),scope:t_,onScopeChange:tq,selectedPath:tn.selectedPath})}),te.visible&&(0,n.jsx)("div",{className:tO?"flex-1 min-w-0":"",children:(0,n.jsx)(tT,{references:te.references,loading:te.loading,onSelect:tY,onClose:te.closeReferences})})]})]}),eS&&(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim",onClick:()=>eM(null),children:(0,n.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-lv3 p-4 max-w-sm w-full mx-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-2",children:ea("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:ea("fileBrowser.confirmDeleteMessage",{name:eS.name}).split(/<\/?file>/g).map((e,t)=>1===t?(0,n.jsx)("span",{className:"font-mono text-foreground",children:e},t):e)}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>eM(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-hover transition-colors",children:ea("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=eS;eM(null);let n=await x.t4.runPromiseExit((0,h.VK)({cwd:t,path:e}));if("Success"===n._tag){(0,M.oR)(ea("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";tn.loadDirectory(t),tn.loadFileIndex(),tn.selectedPath===e&&tB("")}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:ea("toast.deleteFailed");(0,M.oR)(r,"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:ea("common.delete")})]})]})})}),e7.hoverInfo&&eN&&(0,c.createPortal)((0,n.jsx)(tP,{ref:e7.setTooltipEl,displayString:e7.hoverInfo.displayString,documentation:e7.hoverInfo.documentation,x:e7.hoverInfo.x,y:e7.hoverInfo.y,container:eN,onMouseEnter:e7.onCardMouseEnter,onMouseLeave:e7.onCardMouseLeave,onFindReferences:tU?void 0:()=>{let{filePath:e,line:t,column:r}=e7.hoverInfo;e7.clearHover(),te.findReferences(e,t,r)},onSearch:e=>{e7.clearHover(),ev("search"),tl.setContentSearchQuery(e),tl.performContentSearch(e)},onExplain:el?e=>{let{filePath:t,line:r}=e7.hoverInfo;e7.clearHover(),el.sendMessage(ea("explain.symbolMessage",{name:e,path:t,lines:String(r)}))}:void 0,explainDisabled:el?.isLoading}),eN)]})});var tB=r(95045),tD=r(75346);function tA({isOpen:e,onClose:t,cwd:r}){let a,{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)([]),[c,u]=(0,s.useState)(null),[m,h]=(0,s.useState)(null),[f,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(""),[S,L]=(0,s.useState)(!1),[P,T]=(0,s.useState)([]),[$,R]=(0,s.useState)(""),[I,F]=(0,s.useState)(!1),B=(0,s.useCallback)((e,t)=>e?._tag==="Fail"&&e.error?.cause instanceof Error?e.error.cause.message:l(t),[l]),D=(0,s.useCallback)(async()=>{g(!0);let e=await x.t4.runPromiseExit((0,p.FK)(r));if("Success"===e._tag){let t=e.value;d(t.worktrees),u(t.nextPath),h(t.nextRandomWord),t.gitUserName&&C(t.gitUserName)}else console.error("Failed to load worktrees:",e.cause),(0,M.oR)(l("toast.worktreeLoadFailed"),"error");g(!1)},[r,l]),A=(0,s.useCallback)(e=>{let{local:t,remote:r}=e;return r.includes("origin/main")?"origin/main":r.includes("origin/master")?"origin/master":t.includes("main")?"main":t.includes("master")?"master":r.length>0?r[0]:t.length>0?t[0]:"main"},[]);(0,s.useEffect)(()=>{e&&(D(),w(null))},[e,D]);let H=async()=>{if(!c)return;let e="origin/main",t=await x.t4.runPromiseExit((0,p.r4)(r));"Success"===t._tag&&(e=A(t.value));let n=m||function(){let e="bcdfghjklmnprstvwz",t=["a","e","i","o","u","ai","au","ea","ee","ia","io","oa","oo","ou","ui"],r="";for(let n=0;n<2;n++)r+=e[Math.floor(Math.random()*e.length)],r+=t[Math.floor(Math.random()*t.length)];return r}(),s=N?`${N}/${n}`:n;v(!0);let o=await x.t4.runPromiseExit((0,p.CM)({action:"add",cwd:r,path:c,newBranch:s,baseBranch:e}));"Success"===o._tag?((0,M.oR)(l("toast.worktreeCreateSuccess",{name:s}),"success"),D()):(console.error("Failed to create worktree:",o.cause),(0,M.oR)(B(o.cause,"toast.worktreeCreateFailed"),"error")),v(!1)},W=async()=>{F(!0),R(""),L(!0);let e=await x.t4.runPromiseExit((0,p.r4)(r));if("Success"===e._tag){let t=e.value,r=t.local??[],n=t.remote??[],s=new Set(i.map(e=>e.branch).filter(Boolean));T([...r.filter(e=>!s.has(e)),...n.filter(e=>!s.has(e)&&!r.includes(e.replace(/^origin\//,"")))])}else(0,M.oR)(l("toast.loadBranchFailed"),"error");F(!1)},z=async e=>{if(!c)return;L(!1),v(!0);let t=await x.t4.runPromiseExit((0,p.CM)({action:"add",cwd:r,path:c,branch:e}));"Success"===t._tag?((0,M.oR)(l("toast.worktreeCreateSuccess",{name:e}),"success"),D()):(console.error("Failed to create worktree:",t.cause),(0,M.oR)(B(t.cause,"toast.worktreeCreateFailed"),"error")),v(!1)},O=async()=>{if(!j)return;y(!0);let e=await x.t4.runPromiseExit((0,p.CM)({action:"remove",cwd:r,path:j.path}));"Success"===e._tag?((0,M.oR)(l("toast.worktreeDeleted"),"success"),w(null),D()):(console.error("Failed to delete worktree:",e.cause),(0,M.oR)(B(e.cause,"toast.worktreeDeleteFailed"),"error")),y(!1)},_=async e=>{let t=e.isLocked?"unlock":"lock",n=await x.t4.runPromiseExit((0,p.CM)({action:t,cwd:r,path:e.path}));"Success"===n._tag?((0,M.oR)(e.isLocked?l("toast.worktreeUnlocked"):l("toast.worktreeLocked"),"success"),D()):(console.error("Failed to toggle lock:",n.cause),(0,M.oR)(B(n.cause,"toast.operationFailed"),"error"))};return e?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-lv3 w-[480px] max-h-[80vh] flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground",children:"Git Worktrees"}),(0,n.jsx)("button",{onClick:t,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:l("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:f?(0,n.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}):(0,n.jsx)("div",{className:"space-y-2",children:i.map(e=>{let s,o=e.path===r;return(0,n.jsxs)("div",{className:`group p-3 rounded-lg border transition-colors ${o?"border-brand bg-brand/5":"border-border hover:bg-hover cursor-pointer"}`,onClick:()=>{e.path!==r&&((0,tB.F)(tD.n.OpenProject,{cwd:e.path}),t())},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${o?"bg-brand":"bg-muted-foreground/30"}`}),(0,n.jsx)("span",{className:"font-medium text-foreground truncate",children:e.branch||(e.isDetached?"detached":"unknown")}),e.isLocked&&(0,n.jsx)("span",{className:"text-amber-11",title:l("git.worktree.locked"),children:"\uD83D\uDD12"}),o&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",l("common.current"),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:!o&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),_(e)},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary rounded transition-colors",title:e.isLocked?l("git.worktree.unlock"):l("git.worktree.lock"),children:e.isLocked?(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"})}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),w(e)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-secondary rounded transition-colors",title:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})})]}),(0,n.jsxs)("div",{className:"mt-1 flex items-center justify-between gap-2 pl-4",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate",children:e.path}),null!=e.createdAt&&(s=(0,E.fw)(e.createdAt/1e3),(0,n.jsx)("span",{className:`text-xs flex-shrink-0 ${"just now"===s?"text-brand":"text-muted-foreground/70"}`,"data-tooltip":new Date(e.createdAt).toLocaleString(),children:s}))]}),e.isDetached&&(0,n.jsx)("div",{className:"mt-1 text-xs text-amber-11 pl-4",children:"(detached HEAD)"})]},e.path)})})}),S&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-3 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)("input",{value:$,onChange:e=>R(e.target.value),placeholder:l("git.worktree.searchBranch"),className:"flex-1 bg-secondary text-sm text-foreground rounded px-2.5 py-1.5 outline-none",autoFocus:!0,autoComplete:"off",spellCheck:"false"}),(0,n.jsx)("button",{onClick:()=>L(!1),className:"text-xs text-muted-foreground hover:text-foreground px-2 py-1.5",children:l("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:I?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("common.loading")}):0===(a=P.filter(e=>e.toLowerCase().includes($.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:l("git.worktree.noBranches")}):a.map(e=>(0,n.jsx)("button",{onClick:()=>z(e),className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-hover transition-colors truncate",children:(0,n.jsx)("span",{className:`${e.startsWith("origin/")?"text-muted-foreground":"text-foreground"}`,children:e})},e))})]}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between flex-shrink-0",children:[(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:l("git.worktree.count",{count:i.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:W,disabled:!c||b,className:`px-3 py-1.5 text-sm rounded transition-colors ${c&&!b?"bg-secondary text-foreground hover:bg-hover":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:l("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:H,disabled:!c||b,className:`px-3 py-1.5 text-sm rounded transition-colors ${c&&!b?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:b?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):l("git.worktree.addWorktree")})]})]}),j&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-scrim rounded-lg",onClick:()=>w(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-lv3 w-[360px] p-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-3",children:l("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:l("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:l("git.worktree.path")}),(0,n.jsx)("span",{className:"text-foreground",children:j.path})]}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:l("git.worktree.branch")}),(0,n.jsx)("span",{className:"text-foreground",children:j.branch||"detached"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>w(null),className:"px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:O,disabled:k,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 transition-colors disabled:opacity-50",children:k?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):l("common.delete")})]})]})})]})}):null}function tH(e){let t=e.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")}async function tW(e,t){let r=await x.t4.runPromiseExit(((e,t,r=!1)=>{let n,s;return n="open",s={params:{url:e,tab:!0,show:r,cwd:t}},eh.$mh({try:async()=>{let e=await fetch(`/api/browser/${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}),t=await e.json();if(!e.ok||!t.ok)throw Error(t.error||`HTTP ${e.status}`);return t.data},catch:e=>new ef.uV({message:e instanceof Error?e.message:`POST /api/browser/${n} failed`,cause:e})})})(e.trim(),t,!0));if("Success"===r._tag){let{shortId:e,cli:t}=r.value;(0,M.oR)(tC.A.t("browser.openedInChrome",{command:`${t||"cockpit"} browser ${e}`}));return}window.open(e.trim(),"_blank","noopener"),(0,M.oR)(tC.A.t("browser.openInTabFallback"))}var tz=r(67635),tO=r(73300),t_=r(20986),tq=r(9921),tV=r(66088),tU=r(42790);function tK(e){let t=function(e){let t=0xffffffff;for(let r=0;r<e.length;r++){t^=e.charCodeAt(r);for(let e=0;e<8;e++)t=t>>>1^(1&t?0xedb88320:0)}return(0xffffffff^t)>>>0}(e),r="",n=t;for(let e=0;e<4;e++)r+=String.fromCharCode(97+n%26),n=Math.floor(n/26);return r}var tQ=r(2349),tG=r(12786),tJ=r(94720);let tY=(0,s.lazy)(()=>Promise.resolve().then(r.bind(r,96901)).then(e=>({default:e.XtermRenderer}))),tX={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},tZ=/\x1b\[[0-9;]*m/g;function t0({output:e,query:t,mode:r,currentIdx:o,matchListRef:a}){let l=(0,s.useRef)(null);l.current||(l.current=new tU.v,l.current.use_classes=!0);let i=e.split("\n"),d=t.toLowerCase(),c=0;return a.current=[],(0,n.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap break-words select-text",children:i.map((e,t)=>{let s=e.replace(tZ,""),i=s.toLowerCase().includes(d);if("filter"===r&&!i)return null;if(!i){let r=l.current.ansi_to_html(e);return(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:r}},t)}let u=[],m=0,x=s.toLowerCase(),h=0;for(;h<x.length;){let e=x.indexOf(d,h);if(-1===e)break;e>m&&u.push((0,n.jsx)("span",{children:s.slice(m,e)},`t${m}`));let t=c++,r=t===o;u.push((0,n.jsx)("mark",{ref:e=>{a.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+d.length)},`m${e}`)),h=m=e+d.length}return m<s.length&&u.push((0,n.jsx)("span",{children:s.slice(m)},`t${m}`)),(0,n.jsx)("div",{children:u},t)})})}let t1=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:a,output:l,exitCode:i,isRunning:d,selected:c,onSelect:u,onInterrupt:m,onStdin:h,onDelete:f,onRerun:p,timestamp:g,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,subscribePtyRefresh:w,onPtyResize:k,onToggleMaximize:y,maximized:N,expandedHeight:C,bubbleContentHeight:S,onTitleMouseDown:L}){let{t:E}=(0,o.Bd)(),P=(0,s.useRef)(null),T=(0,s.useRef)(null),$=(0,s.useRef)(!0),R=(0,s.useRef)(null),I=(0,s.useRef)(null),F=(e=>{if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`})(g),B=e&&t?tK(t+e):void 0,[D,A]=(0,s.useState)(!1),[H,W]=(0,s.useState)(""),z=(0,s.useRef)(null),O=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!v||!e)return;let t=()=>z.current?v(e,z.current.write):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[v,e]),(0,s.useEffect)(()=>{if(!j||!e)return;let t=()=>z.current?j(e,z.current.reset):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[j,e]),(0,s.useEffect)(()=>{if(!w||!e)return;let t=()=>z.current?w(e,z.current.refresh):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[w,e]);let[_,q]=(0,s.useState)(!1),[V,U]=(0,s.useState)(""),[K,Q]=(0,s.useState)("search"),[G,J]=(0,s.useState)(0),Y=(0,s.useRef)([]),X=(0,s.useRef)(null),Z=(0,s.useRef)(0);(0,s.useEffect)(()=>{X.current||(X.current=new tU.v,X.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=T.current;if(e&&X.current){if(l.length<Z.current&&(X.current=new tU.v,X.current.use_classes=!0,Z.current=0,e.innerHTML=""),l.length>Z.current){let t=l.slice(Z.current),r=X.current.ansi_to_html(t);Z.current=l.length,e.insertAdjacentHTML("beforeend",r)}if(P.current){let e=P.current.scrollHeight>P.current.clientHeight;A(e),e&&(P.current.scrollTop=P.current.scrollHeight)}}},[l]),(0,s.useEffect)(()=>(d&&$.current&&P.current&&(null!==R.current&&cancelAnimationFrame(R.current),R.current=requestAnimationFrame(()=>{P.current&&(P.current.scrollTop=P.current.scrollHeight),R.current=null})),()=>{null!==R.current&&cancelAnimationFrame(R.current)}),[l,d]),(0,s.useEffect)(()=>{if(!N)return;let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),y?.())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[N,y]);let ee=l?l.split("\n").length:0,et=(0,s.useCallback)(()=>{q(!0),requestAnimationFrame(()=>O.current?.focus())},[]),er=(0,s.useCallback)(()=>{q(!1),U(""),J(0),z.current?.clearSearch()},[]),eo=(0,s.useCallback)(e=>{e.trim()&&(b?z.current?.findNext(e):J(e=>{let t=e+1,r=Y.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(Y.current[0]?.scrollIntoView({block:"nearest"}),0)}))},[b]),ea=(0,s.useCallback)(e=>{e.trim()&&(b?z.current?.findPrevious(e):J(e=>{let t=e-1;if(t>=0)return Y.current[t]?.scrollIntoView({block:"nearest"}),t;let r=Y.current.length-1;return r>=0&&Y.current[r]?.scrollIntoView({block:"nearest"}),Math.max(r,0)}))},[b]);(0,s.useEffect)(()=>{if(!c)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key){e.preventDefault(),e.stopPropagation(),et();return}if("Escape"===e.key&&_){e.preventDefault(),e.stopPropagation(),er();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[c,_,et,er]);let el=N&&C?C-41:S??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-card text-foreground dark:text-slate-11 relative overflow-hidden border transition-colors cursor-pointer ${N?"rounded-none border-0":"rounded-2xl rounded-bl-md rounded-br-md"} ${N?"":c?"border-brand":"border-brand/30"}`,onClick:u,children:[N?(0,n.jsxs)("div",{onDoubleClick:()=>y?.(),className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41,flexShrink:0},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded bg-muted text-muted-foreground",children:">_"}),(0,n.jsx)("span",{className:"flex-1 text-xs text-muted-foreground truncate font-mono",children:a}),d&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse"}),E("console.runningText")]}),d&&m&&(0,n.jsx)("button",{onClick:m,className:"text-xs px-3 py-1 rounded-md font-medium bg-destructive text-destructive-foreground transition-all duration-150 hover:bg-destructive/80 hover:shadow-lv2 active:scale-95 active:bg-destructive/70 cursor-pointer select-none",children:"Ctrl+C"}),(0,n.jsx)("button",{onClick:()=>y?.(),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:E("console.restoreTooltip",{modKey:(0,tG.Mu)()}),children:(0,n.jsx)(es.A,{className:"w-4 h-4"})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>L?.(),onDoubleClick:e=>{e.stopPropagation(),y?.()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing ${c?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:">_"}),B&&e&&t&&(0,n.jsx)(tQ.j,{shortId:B,type:"terminal",onRegister:()=>{x.t4.runFork((0,tJ.Ok)({tabId:t,commandId:e,command:a,projectCwd:r}).pipe(eh.NWQ(()=>eh.rIH)))},onUnregister:()=>{x.t4.runFork((0,tJ.jO)({commandId:e}).pipe(eh.NWQ(()=>eh.rIH)))},fullId:e,projectCwd:r,tabId:t}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:a}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(a),(0,M.oR)(E("toast.copiedCmd"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:E("console.copyCommand"),children:(0,n.jsx)(tz.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),D&&!d&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:E("console.totalLines",{count:ee})}),l&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=l.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,M.oR)(E("toast.copiedOutput"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:E("console.copyOutput"),children:(0,n.jsx)(tO.A,{className:"w-3.5 h-3.5"})}),p&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),p()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:E("console.rerun"),children:(0,n.jsx)(t_.A,{className:"w-3.5 h-3.5"})}),f&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),f()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:E("console.deleteRecord"),children:(0,n.jsx)(es.A,{className:"w-3.5 h-3.5"})})]}),_&&(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border bg-card",style:{flexShrink:0},children:[(0,n.jsx)(en.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:O,value:V,onChange:e=>{let t=e.target.value;U(t),J(0),b&&(t.trim()?z.current?.findNext(t):z.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?ea(V):eo(V))},placeholder:E("console.searchPlaceholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none",autoComplete:"off",spellCheck:"false"}),!b&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>Q("search"),className:`px-1.5 py-0.5 rounded transition-colors ${"search"===K?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:E("console.searchMode")}),(0,n.jsx)("button",{onClick:()=>Q("filter"),className:`px-1.5 py-0.5 rounded transition-colors ${"filter"===K?"bg-brand/20 text-brand":"text-muted-foreground hover:text-foreground"}`,children:E("console.filterMode")})]}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>ea(V),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:E("console.prevShiftEnter"),children:(0,n.jsx)(tq.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>eo(V),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:E("console.nextEnter"),children:(0,n.jsx)(tV.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("button",{onClick:er,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)(es.A,{className:"w-3.5 h-3.5"})})]}),b?(0,n.jsxs)("div",{className:"relative group",style:{height:el,overflow:"hidden"},children:[(0,n.jsx)(s.Suspense,{fallback:(0,n.jsx)("div",{className:"px-4 py-2 text-xs text-muted-foreground",style:{height:el},children:E("console.loadingTerminal")}),children:(0,n.jsx)(tY,{ref:z,output:l,isRunning:d,onInput:h,onResize:k,maximized:N,height:el,directWrite:!!v})}),!d&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 pointer-events-none"}),!d&&p&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",onClick:e=>{e.stopPropagation(),p()},children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-tooltip text-tooltip-foreground text-xs",children:[(0,n.jsx)(t_.A,{className:"w-3.5 h-3.5"}),E("console.rerun")]})})]}):(0,n.jsx)("div",{ref:P,className:"overflow-auto px-4 py-2",style:{height:el},onScroll:()=>{if(P.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=P.current;$.current=t-e-r<50}},children:_&&V.trim()?(0,n.jsx)(t0,{output:l,query:V,mode:K,currentIdx:G,matchListRef:Y}):(0,n.jsx)("pre",{ref:T,className:"text-sm font-mono whitespace-pre-wrap break-words select-text"})}),d&&!N&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("span",{className:"inline-block w-2 h-2 bg-green-500 rounded-full animate-pulse flex-shrink-0"}),b?(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-1",children:E("console.clickToInput")}):h?(0,n.jsx)("input",{ref:I,value:H,onChange:e=>W(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=tX[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),h(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),h(H+"\n"),W("")),"Tab"===e.key&&(e.preventDefault(),h(" "))},placeholder:E("console.stdinPlaceholder"),className:"flex-1 min-w-0 bg-transparent text-xs font-mono text-foreground outline-none",autoComplete:"off",spellCheck:"false"}):(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:E("console.runningText")}),m&&(0,n.jsx)("button",{onClick:m,className:"flex-shrink-0 text-xs text-destructive hover:brightness-125 transition-colors cursor-pointer select-none",children:"Ctrl+C"}),F&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:F})]}),!d&&void 0!==i&&!N&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${0===i?"bg-green-500":"bg-red-500"}`}),(0,n.jsx)("span",{children:E("console.exitCode",{code:i})}),(0,n.jsx)("span",{className:"flex-1"}),F&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:F})]})]})})}),t2=new Map;function t5(e){t2.set(e.type,e)}function t4(e){return t2.get(e)}function t3(e){for(let t of t2.values())if(t.match(e))return t;return null}let t6=(e,t)=>eh.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:t=>new ef.uV({message:`POST ${e} failed`,cause:t})}),t8=(e,t)=>x.t4.runPromise(t6(`/api/${e}/disconnect`,{id:t}).pipe(eh.NWQ(()=>eh.rIH))),t9=e=>x.t4.runPromise(t6("/api/browser/unregister",{id:e}).pipe(eh.NWQ(()=>eh.rIH))),t7=e=>x.t4.runPromise(e.pipe(eh.h9N(e=>eh.OH5(()=>{if(e.cause instanceof Error)throw e.cause;throw Error(e.message)})))),re=(e,t)=>{if(e&&"object"==typeof e&&"error"in e){let t=e.error;if("string"==typeof t&&t.length>0)return t;if(t&&"object"==typeof t){let e=t.message;if("string"==typeof e&&e.length>0)return e;let r=t._tag;if("string"==typeof r&&r.length>0)return r}}return`HTTP ${t}`},rt=(e,t)=>t7(eh.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),n=await r.json();if(!r.ok)throw Error(re(n,r.status));return n},catch:t=>new ef.uV({message:`POST ${e} failed`,cause:t})})),rr=(e,t)=>t7(eh.$mh({try:async()=>{let r=new URLSearchParams(t),n=await fetch(`${e}?${r}`),s=await n.json();if(!n.ok)throw Error(re(s,n.status));return s},catch:t=>new ef.uV({message:`GET ${e} failed`,cause:t})})),rn=(e,t)=>t7(eh.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`);return r.blob()},catch:t=>new ef.uV({message:`POST blob ${e} failed`,cause:t})}));function rs(e){let t=e.trim().toLowerCase();return t.startsWith("http://")||t.startsWith("https://")}function ro({url:e,id:t,selected:r,maximized:a,expandedHeight:l,bubbleContentHeight:i,onSelect:d,onClose:c,onToggleMaximize:u,onNewTab:m,timestamp:x,onTitleMouseDown:h,initialSleeping:f,onSleep:p,onWake:g,projectCwd:b,baseCwd:v,tabId:j,autoConnect:w}){let{t:k,i18n:y}=(0,o.Bd)(),[N,C]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),E=rs(e),[P,T]=(0,s.useState)(e),[$,R]=(0,s.useState)(null),[I,F]=(0,s.useState)(f??!1),B=(0,s.useRef)(null),D=(0,s.useRef)(null),A=(0,s.useRef)(null);(0,s.useEffect)(()=>{T(e)},[e]);let H=(0,s.useRef)(!0),W=(0,s.useCallback)(()=>{I||(F(!0),R(null),p?.(t))},[I,t,p]),z=(0,s.useCallback)(()=>{B.current&&(clearTimeout(B.current),B.current=null)},[]),{shortId:O,connected:_,connect:q,disconnect:V}=function(e,t,r,n,o){let a=(0,s.useMemo)(()=>tK(e),[e]),[l,i]=(0,s.useState)(!1),d=(0,s.useRef)(null),c=(0,s.useRef)([]),u=(0,s.useRef)(null),m=(0,s.useRef)(!1),x=(0,s.useRef)(r);(0,s.useEffect)(()=>{x.current=r});let h=(0,s.useRef)([]),f=(0,s.useCallback)((e,t,r,n)=>{let s=d.current;e&&s&&s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({type:"browser:cmd-result",reqId:e,ok:t,data:r,error:n}))},[]),p=(0,s.useCallback)(e=>{let r=t.current;if(!r)return void f(e,!1,void 0,"bubble iframe not mounted (sleeping?)");let n=new URLSearchParams(window.location.search).get("cwd")||"";window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!0}})),(0,tB.F)(tD.n.ScreenshotPrepare,{cwd:n}),requestAnimationFrame(()=>requestAnimationFrame(()=>requestAnimationFrame(()=>{setTimeout(()=>{let t=r.getBoundingClientRect(),n=window.devicePixelRatio||1,s=t.x,o=t.y;try{let e=window;for(;e!==e.top;){let t=e.frameElement;if(t){let e=t.getBoundingClientRect();s+=e.x,o+=e.y}e=e.parent}}catch{}f(e,!0,{x:Math.round(s*n),y:Math.round(o*n),width:Math.round(t.width*n),height:Math.round(t.height*n),dpr:n})},150)})))},[t,f]),g=(0,s.useCallback)(e=>{"ensure-ready"===e.op?x.current?f(e.reqId,!0,{ready:!0}):e.reqId&&c.current.push(e.reqId):"prepare-screenshot"===e.op?p(e.reqId):"screenshot-done"===e.op&&(window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!1}})),(0,tB.F)(tD.n.ScreenshotDone,{}))},[p,f]);(0,s.useEffect)(()=>{if(!l)return;let t=!1;return m.current=!0,!function r(){if(t||!m.current)return;let s="https:"===window.location.protocol?"wss:":"ws:",a=new URLSearchParams({fullId:e});n&&a.set("projectCwd",n),o&&a.set("tabId",o);let l=new WebSocket(`${s}//${window.location.host}/ws/browser?${a.toString()}`);d.current=l,l.onopen=()=>{for(let e of h.current)e();h.current=[]},l.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}"browser:ui"===t.type&&g(t)},l.onclose=()=>{d.current=null,!t&&m.current&&(u.current=setTimeout(r,3e3))},l.onerror=()=>l.close()}(),()=>{t=!0,m.current=!1,u.current&&clearTimeout(u.current),d.current&&(d.current.close(),d.current=null),h.current=[]}},[l,e,g,n,o]),(0,s.useEffect)(()=>{if(r&&c.current.length>0){for(let e of c.current)f(e,!0,{ready:!0});c.current=[]}},[r,f]);let b=(0,s.useCallback)(()=>l&&d.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{h.current.push(e),l||i(!0)}),[l]);return{shortId:a,connected:l,connect:b,disconnect:(0,s.useCallback)(()=>{i(!1)},[])}}(t,A,!!$&&!I&&!N,b,j),U=(0,s.useRef)(_);U.current=_;let K=(0,s.useRef)(!1);(0,s.useEffect)(()=>{E||!w||K.current||(K.current=!0,q())},[E,w,q]),(0,s.useEffect)(()=>{let e=D.current;if(!e||I)return;let t=new IntersectionObserver(([e])=>{H.current=e.isIntersecting,e.isIntersecting||U.current?z():(B.current&&clearTimeout(B.current),B.current=setTimeout(W,3e5))});return t.observe(e),()=>t.disconnect()},[I,W,z]),(0,s.useEffect)(()=>{I?V():_?z():H.current||(B.current&&clearTimeout(B.current),B.current=setTimeout(W,3e5))},[_,I,V,z,W]),(0,s.useEffect)(()=>{f&&R(null)},[]);let G=(0,s.useCallback)(()=>{(F(!1),g?.(t),rs(e))?R(e):R((0,Q.YQ)(e,v))},[e,t,g,v]),J=(0,s.useRef)(()=>{});J.current=()=>{E||(I&&G(),q())},(0,et.h)({url:"/ws/global-state",enabled:!!O,onMessage:e=>{"browser-wake"===e.type&&e.shortId===O&&J.current()}}),(0,s.useEffect)(()=>{if(!e||I){e||R(null);return}rs(e)?R(e):R((0,Q.YQ)(e,v))},[e,I,v]);let Y=(0,s.useCallback)(()=>{C(!1);let e=A.current?.contentWindow;if(!e)return;let t=document.documentElement.classList.contains("dark");e.postMessage({type:"THEME_CHANGE",theme:t?"dark":"light"},"*"),e.postMessage({type:"cockpit:language-change",lang:y.language},"*")},[y]);(0,s.useEffect)(()=>{let e=D.current;if(!e)return;let t=null,r=e.parentElement;for(;r;){let{overflowY:e}=getComputedStyle(r);if("auto"===e||"scroll"===e){t=r;break}r=r.parentElement}if(!t)return;let n="",s=0,o=!1,a=()=>{o&&t&&(t.scrollTop=s)},l=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",a)},i=()=>{o=!1,t.removeEventListener("scroll",a),t.style.overflow=n};return e.addEventListener("mouseenter",l),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",l),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",a),o&&(t.style.overflow=n)}},[]),(0,s.useEffect)(()=>{let e=e=>{if(!e.data||"string"!=typeof e.data.type||!e.data.type.startsWith("cockpit:"))return;let r=D.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?m?.(e.data.url,t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&T(e.data.url)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,m]);let X=(0,s.useCallback)(()=>{C(!1),L(k("browser.pageLoadFailed"))},[]),Z=(0,s.useCallback)(()=>{if(I)return void G();let e=D.current?.querySelector("iframe");if(e&&$){C(!0),L(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[I,G,$]);(0,s.useEffect)(()=>{e&&!I&&(C(!0),L(null))},[e,I]);let ee=(0,s.useCallback)(()=>{if(!P)return;let e=rs(P)?P:(0,Q.YQ)(P,v);window.open((0,Q.PB)(e,window.location.origin),"_blank")},[P,v]);(0,s.useEffect)(()=>{if(!r&&!a)return;let e=e=>{"Escape"===e.key&&a&&(e.stopPropagation(),u()),"m"===e.key&&(e.metaKey||e.ctrlKey)&&r&&(e.preventDefault(),e.stopPropagation(),u())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[a,r,u]);let er=function(e){if(!e)return"";try{let t=new URL(e);return t.port?`${t.hostname}:${t.port}`:t.hostname}catch{return e.split("/").pop()||e}}(P),en=a&&l?l-41:i??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
15
+ relative transition-colors cursor-pointer
16
+ ${a?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
17
+ ${a?"":r?"border-brand":"border-brand/30"}`,onClick:a?void 0:d,children:[a?(0,n.jsxs)("div",{onDoubleClick:u,className:"flex items-center gap-2 px-3 py-2 border-b border-border bg-card",style:{height:41},children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})})}),O&&!E&&(0,n.jsx)(tQ.j,{shortId:O,type:"browser",registered:_,onRegister:()=>q(),onUnregister:async()=>{V(),await t9(O)},fullId:t,projectCwd:b,tabId:j}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate font-mono",children:P||k("browser.blankPage")}),P&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(P),(0,M.oR)(k("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.copyUrl"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("span",{className:"flex-1"}),N&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),(0,n.jsx)("button",{onClick:Z,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:ee,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.openInNewWindow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:u,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.exitMaximize",{modKey:(0,tG.Mu)()}),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})})})]}):(0,n.jsxs)("div",{"data-drag-handle":!0,onMouseDown:()=>h?.(),onDoubleClick:e=>{e.stopPropagation(),u()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing
18
+ ${r?"border-brand":"border-brand/30"}`,children:[(0,n.jsx)("span",{className:"text-[10px] font-mono leading-none px-1 py-0.5 rounded flex-shrink-0 bg-muted text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-3 h-3 inline-block",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})})}),O&&!E&&(0,n.jsx)(tQ.j,{shortId:O,type:"browser",registered:_,onRegister:()=>q(),onUnregister:async()=>{V(),await t9(O)},fullId:t,projectCwd:b,tabId:j}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:P||k("browser.blankPage")}),P&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(P),(0,M.oR)(k("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.copyUrl"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("span",{className:"flex-1"}),N&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),ee()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("browser.openInNewWindow"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),Z()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:k("common.refresh"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c()},className:"p-0.5 rounded text-destructive hover:text-destructive/80 transition-colors flex-shrink-0",title:k("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{ref:D,className:"w-full",style:{height:en},children:I?(0,n.jsxs)("div",{className:"relative overflow-hidden cursor-pointer group h-full",onClick:e=>{e.stopPropagation(),Z()},children:[(0,n.jsxs)("div",{className:"absolute inset-0 flex flex-col items-center justify-center bg-muted/30",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-2 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground/60",children:er})]}),(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-black/60 text-white text-xs",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),k("browser.clickToWake")]})})]}):e?E?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 text-muted-foreground p-6 h-full text-center",children:[(0,n.jsx)("svg",{className:"w-9 h-9 mb-1 opacity-70",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),(0,n.jsx)("p",{className:"text-sm text-foreground",children:k("browser.movedToChrome")}),(0,n.jsx)("p",{className:"text-xs break-all opacity-70",children:e}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),tW(e,b??v)},className:"mt-1 px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:k("browser.openInChrome")})]}):S?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center text-muted-foreground p-6 h-full",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-3 text-red-11",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,n.jsx)("p",{className:"text-xs",children:S}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),Z()},className:"mt-2 px-3 py-1 text-xs bg-secondary text-foreground rounded hover:bg-hover transition-colors",children:k("common.retry")})]}):(0,n.jsxs)("div",{className:"relative overflow-hidden h-full",style:{contain:"strict"},children:[N&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-card/80 z-10",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),$?(0,n.jsx)("iframe",{ref:A,src:$,className:"border-0 bg-white",allow:"clipboard-write; clipboard-read",style:a?{width:"100%",height:"100%"}:{position:"absolute",top:0,left:0,width:"200%",height:"200%",transform:"scale(0.5)",transformOrigin:"top left"},name:`cockpit-bubble-${t}`,onLoad:Y,onError:X,title:`Browser: ${er}`,"data-browser-id":t}):(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center text-muted-foreground h-full",children:[(0,n.jsx)("svg",{className:"w-10 h-10 mb-2 text-foreground-faint",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M21 12a9 9 0 01-9 9m9-9a9 9 0 00-9-9m9 9H3m9 9a9 9 0 01-9-9m9 9c1.657 0 3-4.03 3-9s-1.343-9-3-9m0 18c-1.657 0-3-4.03-3-9s1.343-9 3-9m-9 9a9 9 0 019-9"})}),(0,n.jsx)("p",{className:"text-xs",children:k("browser.blankPage")})]})}),!a&&e&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full flex-shrink-0 ${I?"bg-yellow-500":N?"bg-brand animate-pulse":S?"bg-red-500":"bg-green-500"}`}),(0,n.jsx)("span",{className:"truncate",children:I?k("browser.sleeping"):N?k("browser.loadingPage"):S?k("browser.loadFailed"):er}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:function(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}(x)})]})]})})}t5({type:"browser",idPrefix:"browser",match(e){let t=e.trim().toLowerCase();return t.endsWith(".html")||t.endsWith(".htm")||(0,Q.Kx)(t)},parse:e=>({url:e.trim(),cwd:""}),fromHistory:e=>({url:e.url,cwd:e.cwd??"",autoConnect:!!e.autoConnect}),toHistory:e=>({url:e.url,cwd:e.cwd??"",...e.autoConnect?{autoConnect:!0}:{}}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c,extra:u}){return(0,n.jsx)(ro,{id:e.id,url:e.url,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c,onNewTab:u?.addBrowserItem,initialSleeping:u?.initialSleeping,onSleep:u?.onSleep,onWake:u?.onWake,projectCwd:u?.projectCwd,baseCwd:e.cwd||u?.projectCwd,tabId:u?.tabId,autoConnect:e.autoConnect})}});let ra=[{value:"=",label:"="},{value:"!=",label:"≠"},{value:">",label:">"},{value:"<",label:"<"},{value:">=",label:"≥"},{value:"<=",label:"≤"},{value:"LIKE",label:"LIKE"},{value:"NOT LIKE",label:"NOT LIKE"},{value:"IN",label:"IN"},{value:"IS NULL",label:"IS NULL"},{value:"IS NOT NULL",label:"IS NOT NULL"}];function rl(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}function ri(e){return`"${e.replace(/"/g,'""')}"`}function rd(e){return null==e?"":"object"==typeof e?JSON.stringify(e):String(e)}function rc({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,maxW:600,maxH:300,above:!0}),l=(0,s.useRef)(null),i=(0,s.useRef)(null),d=(0,s.useRef)(!1),c=(0,m.F2)(),u=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{d.current||r(!1)},80)},[]),x=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),d.current=!1,i.current=setTimeout(()=>{let e=l.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=c?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,i=n?.width??window.innerWidth,d=n?.height??window.innerHeight,u=t.left-s,m=t.top-o,x=t.bottom-o,h=Math.min(600,i-u-8),f=m-8,p=d-x-8,g=f>p&&f>80,b=g?f-4:p-4;a({x:h<200?Math.max(8,i-600-8):u,y:g?m-4:x+4,maxW:h<200?Math.min(600,i-16):h,maxH:Math.max(60,b),above:g}),r(!0)},350)},[c]),h=(0,s.useCallback)(()=>{u()},[u]),f=(0,s.useCallback)(()=>{d.current=!0,i.current&&clearTimeout(i.current)},[]),p=(0,s.useCallback)(()=>{d.current=!1,u()},[u]);return(0,n.jsxs)("span",{ref:l,className:"block truncate",onMouseEnter:x,onMouseLeave:h,children:[e,t&&(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lv2 whitespace-pre-wrap break-all select-text cursor-text",style:{left:o.x,top:o.y,maxWidth:o.maxW,maxHeight:o.maxH,transform:o.above?"translateY(-100%)":void 0},onMouseEnter:f,onMouseLeave:p,children:function(e){try{let t=JSON.parse(e);if("object"==typeof t&&null!==t)return JSON.stringify(t,null,2)}catch{}return e}(e)})})]})}function ru({id:e,connectionString:t,displayName:r,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:d,onSelect:c,onClose:u,onToggleMaximize:m,timestamp:x,onTitleMouseDown:h}){let{t:f}=(0,o.Bd)(),{showToast:p}=(0,M.dj)(),[g,b]=(0,s.useState)("connecting"),[v,j]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)("public"),[C,S]=(0,s.useState)([]),[L,E]=(0,s.useState)(null),[P,T]=(0,s.useState)("table"),[$,R]=(0,s.useState)("data"),[I,F]=(0,s.useState)([]),[B,D]=(0,s.useState)([]),[A,H]=(0,s.useState)([]),[W,z]=(0,s.useState)([]),[O,_]=(0,s.useState)(null),[q,V]=(0,s.useState)(0),[U,K]=(0,s.useState)(!1),[Q,G]=(0,s.useState)(0),[J,Y]=(0,s.useState)(new Set),[X,Z]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)({}),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)({}),[ei,ed]=(0,s.useState)({}),[ec,eu]=(0,s.useState)(null),[em,ex]=(0,s.useState)(""),[eh,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)(!1),ej=(0,s.useRef)(null),ew=(0,s.useCallback)(async()=>{b("connecting"),j("");try{let r=await rt("/api/db/connect",{id:e,connectionString:t});k(r.schemas||[]),r.schemas?.length>0&&!r.schemas.includes("public")&&N(r.schemas[0]),b("connected")}catch(e){j(e instanceof Error?e.message:String(e)),b("error")}},[e,t]);(0,s.useEffect)(()=>{ew()},[ew]);let ek=(0,s.useCallback)(async()=>{if("connected"===g)try{let r=await rr("/api/db/schemas",{id:e,connectionString:t,schema:y});S(r.tables||[])}catch{}},[e,t,y,g]);(0,s.useEffect)(()=>{ek()},[ek]);let ey=(0,s.useCallback)(async(r,n,s,o)=>{K(!0);let a=s??ei,l=void 0!==o?o:ec;try{let s=`${ri(y)}.${ri(r)}`,{where:o,params:i}=function(e){let t=[],r=[],n=1;for(let[s,o]of Object.entries(e)){if(!o.enabled)continue;let e=ri(s);if("IS NULL"===o.op)t.push(`${e} IS NULL`);else if("IS NOT NULL"===o.op)t.push(`${e} IS NOT NULL`);else if("IN"===o.op){let s=o.value.split(",").map(e=>e.trim()).filter(Boolean);if(0===s.length)continue;let a=s.map(e=>(r.push(e),`$${n++}`));t.push(`${e}::text IN (${a.join(", ")})`)}else"LIKE"===o.op||o.op,t.push(`${e}::text ${o.op} $${n++}`),r.push(o.value)}return{where:t.length>0?` WHERE ${t.join(" AND ")}`:"",params:r}}(a),d=l?` ORDER BY ${ri(l.column)} ${l.dir}`:"",c=`SELECT * FROM ${s}${o}${d} LIMIT 50 OFFSET ${50*n}`,u=await rt("/api/db/query",{id:e,connectionString:t,sql:c,params:i});_(u);let m=`SELECT count(*)::int AS cnt FROM ${s}${o}`,x=await rt("/api/db/query",{id:e,connectionString:t,sql:m,params:i});G(x.rows?.[0]?.cnt??0)}catch{}K(!1)},[e,t,y,ei,ec]),eN=(0,s.useCallback)(async r=>{E(r),V(0),et(null),eo(!1),Y(new Set),Z(!1),ed({}),eu(null);try{let n=await rr("/api/db/columns",{id:e,connectionString:t,schema:y,table:r});F(n.columns||[]),D(n.primaryKeys||[]),H(n.foreignKeys||[]),z(n.indexes||[])}catch{}ey(r,0,{},null)},[e,t,y,ey]),eC=(0,s.useCallback)(async()=>{if(em.trim()){ev(!0),eg(""),ef(null);try{let r=await rt("/api/db/query",{id:e,connectionString:t,sql:em});ef(r)}catch(e){eg(e instanceof Error?e.message:String(e))}ev(!1)}},[e,t,em]),eS=(0,s.useCallback)(async()=>{if(null===ee||!O||!L)return;let r=O.rows[ee],n=[],s=[],o=1;for(let e of I)void 0!==er[e.name]&&er[e.name]!==rd(r[e.name]??"")&&(n.push(`${ri(e.name)} = $${o}`),s.push(""===er[e.name]&&e.nullable?null:er[e.name]),o++);if(0===n.length)return void et(null);let a=B.length>0?B:I.map(e=>e.name),l=[];for(let e of a)null===r[e]||void 0===r[e]?l.push(`${ri(e)} IS NULL`):(l.push(`${ri(e)} = $${o}`),s.push(r[e]),o++);let i=`UPDATE ${ri(y)}.${ri(L)} SET ${n.join(", ")} WHERE ${l.join(" AND ")}`;try{await rt("/api/db/query",{id:e,connectionString:t,sql:i,params:s}),et(null),ey(L,q,ei,ec)}catch(e){alert(`Update failed: ${e instanceof Error?e.message:String(e)}`)}},[ee,O,L,I,B,er,e,t,y,ey,q,ei,ec]),eM=(0,s.useCallback)(async()=>{if(!L)return;let r=[],n=[],s=[],o=1;for(let e of I)void 0!==ea[e.name]&&""!==ea[e.name]&&(r.push(ri(e.name)),n.push(ea[e.name]),s.push(`$${o}`),o++);if(0===r.length)return;let a=`INSERT INTO ${ri(y)}.${ri(L)} (${r.join(", ")}) VALUES (${s.join(", ")})`;try{await rt("/api/db/query",{id:e,connectionString:t,sql:a,params:n}),eo(!1),el({}),ey(L,q,ei,ec)}catch(e){alert(`Insert failed: ${e instanceof Error?e.message:String(e)}`)}},[L,I,ea,e,t,y,ey,q,ei,ec]),eL=(0,s.useCallback)(async()=>{if(0===J.size||!O||!L)return;let r=B.length>0?B:I.map(e=>e.name),n=0;for(let s of Array.from(J).sort((e,t)=>t-e)){let o=O.rows[s];if(!o)continue;let a=[],l=[],i=1;for(let e of r)null===o[e]||void 0===o[e]?a.push(`${ri(e)} IS NULL`):(a.push(`${ri(e)} = $${i}`),l.push(o[e]),i++);let d=`DELETE FROM ${ri(y)}.${ri(L)} WHERE ctid = (SELECT ctid FROM ${ri(y)}.${ri(L)} WHERE ${a.join(" AND ")} LIMIT 1)`;try{await rt("/api/db/query",{id:e,connectionString:t,sql:d,params:l})}catch{n++}}Y(new Set),Z(!1),ey(L,q,ei,ec),n>0&&alert(f("database.deleteRowsFailed",{count:n}))},[J,O,L,B,I,e,t,y,ey,q,ei,ec]),eE=(0,s.useCallback)(async r=>{if(!L)return;if(J.size>0&&O){let e,t=O.fields.map(e=>e.name),n=Array.from(J).sort((e,t)=>e-t).map(e=>O.rows[e]).filter(Boolean);if("json"===r)e=JSON.stringify(n,null,2);else{let r=[t.join(",")];for(let e of n)r.push(t.map(t=>{let r=e[t];if(null==r)return"";let n="object"==typeof r?JSON.stringify(r):String(r);return n.includes(",")||n.includes('"')||n.includes("\n")?`"${n.replace(/"/g,'""')}"`:n}).join(","));e=r.join("\n")}navigator.clipboard.writeText(e);return}let n=`SELECT * FROM ${ri(y)}.${ri(L)}`;try{let s=await rn("/api/db/export",{id:e,connectionString:t,sql:n,format:r}),o=URL.createObjectURL(s),a=document.createElement("a");a.href=o,a.download=`${L}.${r}`,a.click(),URL.revokeObjectURL(o)}catch(e){alert(`Export failed: ${e instanceof Error?e.message:String(e)}`)}},[L,e,t,y,J,O]),eP=(0,s.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),eC())},[eC]),eT=Math.max(1,Math.ceil(Q/50)),e$=(0,s.useCallback)(e=>{L&&(V(e),ey(L,e,ei,ec))},[L,ey,ei,ec]),eR=(0,s.useCallback)((e,t)=>{let r={...ei};t?r[e]=t:delete r[e],ed(r),V(0),Y(new Set),L&&ey(L,0,r,ec)},[ei,ec,L,ey]),eI=(0,s.useCallback)(()=>{ed({}),V(0),Y(new Set),L&&ey(L,0,{},ec)},[ec,L,ey]),eF=(0,s.useCallback)(e=>{eu(e),V(0),Y(new Set),L&&ey(L,0,ei,e)},[ei,L,ey]);return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
19
+ relative transition-colors cursor-pointer
20
+ ${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
21
+ ${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:c,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:h,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"\uD83D\uDC18"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===g&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===g&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:f("database.connectionFailed")}),"connected"===g&&(0,n.jsx)("span",{className:"text-[10px] text-green-11 flex-shrink-0",children:f("database.connected")}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rl(x)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?f("browser.exitMaximize",{modKey:(0,tG.Mu)()}):f("browser.maximize",{modKey:(0,tG.Mu)()}),children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:l&&i?i-41:d??360},className:"flex overflow-hidden",children:["connecting"===g&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),f("database.connecting")]}),"error"===g&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:v}),(0,n.jsx)("button",{onClick:ew,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:f("common.retry")})]}),"connected"===g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[w.length>1?(0,n.jsx)("select",{value:y,onChange:e=>{N(e.target.value),E(null)},className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1",children:w.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}):(0,n.jsx)("span",{className:"flex-1 min-w-0 text-xs text-muted-foreground truncate",children:y}),(0,n.jsx)("button",{onClick:ek,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-hover active:bg-active transition-colors",title:f("database.refreshTableList"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsx)("div",{className:"flex items-center border-b border-border",children:["table","view"].map(e=>(0,n.jsx)("button",{onClick:()=>T(e),className:`flex-1 py-1 text-[10px] font-medium transition-colors ${P===e?"text-brand border-b border-brand":"text-muted-foreground hover:text-foreground"}`,children:{table:f("database.filterTable"),view:f("database.filterView")}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[C.filter(e=>"table"===P?"view"!==e.type:"view"===e.type).map(e=>(0,n.jsxs)("div",{onClick:()=>eN(e.name),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer truncate transition-colors ${L===e.name?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground",children:"view"===e.type?"V":"T"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:(0,n.jsx)(rc,{text:e.name})}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.rowEstimate>0?`~${e.rowEstimate}`:""})]},e.name)),0===C.length&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:f("database.noTables")})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["structure","data","sql"].map(e=>(0,n.jsx)("button",{onClick:()=>R(e),className:`px-3 py-1.5 text-xs transition-colors ${$===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{structure:f("database.tabStructure"),data:f("database.tabData"),sql:"SQL"}[e]},e)),L&&"data"===$&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[Object.values(ei).some(e=>e.enabled)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-brand",children:f("database.filterActive",{count:Object.values(ei).filter(e=>e.enabled).length})}),(0,n.jsx)("button",{onClick:eI,className:"px-1 py-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors",title:f("database.clearAllFilters"),children:"✕"}),(0,n.jsx)("span",{className:"text-border",children:"|"})]}),J.size>0&&!X&&(0,n.jsx)("button",{onClick:()=>Z(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:f("database.deleteNRows",{count:J.size})}),X&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-destructive",children:f("database.confirmDeleteRows")}),(0,n.jsx)("button",{onClick:eL,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:f("common.confirm")}),(0,n.jsx)("button",{onClick:()=>Z(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:f("common.cancel")})]}),(0,n.jsx)("button",{onClick:()=>eE("csv"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:J.size>0?f("database.copyCsvSelected"):f("database.copyCsvAll"),children:J.size>0?f("database.copyCSV"):f("database.CSV")}),(0,n.jsx)("button",{onClick:()=>eE("json"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:J.size>0?f("database.copyJsonSelected"):f("database.copyJsonAll"),children:J.size>0?f("database.copyJSON"):f("database.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:L||"sql"===$?"structure"===$?(0,n.jsx)(rm,{columns:I,primaryKeys:B,foreignKeys:A,indexes:W}):"data"===$?(0,n.jsx)(rh,{result:O,loading:U,columns:I,page:q,totalPages:eT,totalRows:Q,onPageChange:e$,filters:ei,sort:ec,onFilterChange:eR,onSortChange:eF,selectedRows:J,onSelectedRowsChange:e=>{Y(e),Z(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!O)return;let t=O.rows[e],r={};for(let e of I)r[e.name]=null==t[e.name]?"":rd(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:ea,onStartAdd:()=>{eo(!0),el({})},onNewRowChange:(e,t)=>el(r=>({...r,[e]:t})),onSaveNewRow:eM,onCancelAdd:()=>{eo(!1),el({})},onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)(rf,{sqlInput:em,onSqlChange:ex,onExecute:eC,onKeyDown:eP,result:eh,error:ep,loading:eb,sqlRef:ej,onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:f("database.selectTable")})})]})]})]}),!l&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===g?"bg-green-500":"error"===g?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:f("common.connecting"),connected:f("common.connected"),error:f("common.connectionFailed")}[g]}),"connected"===g&&L&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:L}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rl(x)})]})]})})}function rm({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:a}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:a("database.selectTableToView")}):(0,n.jsxs)("div",{className:"p-2 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("database.columns")}),(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"text-left text-muted-foreground border-b border-border",children:[(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("database.colDefault")})]})}),(0,n.jsx)("tbody",{children:e.map(e=>(0,n.jsxs)("tr",{className:"border-b border-border/50 hover:bg-hover",children:[(0,n.jsxs)("td",{className:"px-1.5 py-1 font-mono",children:[e.isPrimaryKey&&(0,n.jsx)("span",{className:"text-amber-11 mr-1",title:a("database.primaryKey"),children:"\uD83D\uDD11"}),e.name]}),(0,n.jsxs)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono",children:[e.type,e.maxLength?`(${e.maxLength})`:""]}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground",children:e.nullable?"YES":"NO"}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono truncate max-w-[120px]",children:e.default||""})]},e.name))})]})]}),r.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("database.foreignKeys")}),(0,n.jsx)("div",{className:"space-y-0.5",children:r.map((e,t)=>(0,n.jsxs)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground",children:[e.column," → ",e.refSchema,".",e.refTable,".",e.refColumn]},t))})]}),s.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("database.indexes")}),(0,n.jsx)("div",{className:"space-y-0.5",children:s.map(e=>(0,n.jsx)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground truncate","data-tooltip":e.definition,"data-tooltip-mono":!0,children:e.name},e.name))})]})]})}function rx({filter:e,onApply:t,onClear:r,onToggle:a,onClose:l,colName:i,anchorRect:d}){let{t:c}=(0,o.Bd)(),[u,x]=(0,s.useState)(e?.op||"="),[h,f]=(0,s.useState)(e?.value||""),p=(0,s.useRef)(null),g=(0,m.F2)();(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&l()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[l]);let b="IS NULL"!==u&&"IS NOT NULL"!==u,v=()=>{(!b||h.trim())&&t({op:u,value:h.trim(),enabled:!0})},j=g?.getBoundingClientRect(),w=j?.left??0,k=j?.top??0,y=j?.width??window.innerWidth,N=d.left-w;N+220>y-8&&(N=y-220-8),N<8&&(N=8);let C=d.bottom+2-k;return(0,n.jsx)(m.ZL,{children:(0,n.jsxs)("div",{ref:p,className:"fixed z-[9998] w-[220px] bg-popover border border-border rounded-md shadow-lv2 p-2 space-y-2",style:{left:N,top:C},onClick:e=>e.stopPropagation(),children:[e&&(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:e=>a(e.target.checked),className:"w-3 h-3 accent-brand"}),c("database.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:i})]}),(0,n.jsx)("select",{value:u,onChange:e=>x(e.target.value),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 focus:outline-none focus:ring-1 focus:ring-ring",children:ra.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),b&&(0,n.jsx)("input",{type:"text",value:h,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v())},placeholder:c("IN"===u?"database.commaValues":"LIKE"===u?"database.likePattern":"database.valuePlaceholder"),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:v,disabled:b&&!h.trim(),className:"flex-1 px-2 py-1 text-[10px] bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-40 transition-colors",children:c("database.apply")}),e&&(0,n.jsx)("button",{onClick:r,className:"flex-1 px-2 py-1 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground transition-colors",children:c("database.clearFilter")})]})]})})}function rh({result:e,loading:t,columns:r,page:a,totalPages:l,totalRows:i,onPageChange:d,filters:c,sort:u,onFilterChange:m,onSortChange:x,selectedRows:h,onSelectedRowsChange:f,editingRowIdx:p,editValues:g,onStartEdit:b,onEditChange:v,onSaveEdit:j,onCancelEdit:w,isAddingRow:k,newRowValues:y,onStartAdd:N,onNewRowChange:C,onSaveNewRow:S,onCancelAdd:M,onCellCopy:L}){let{t:E}=(0,o.Bd)(),[P,T]=(0,s.useState)(null),[$,R]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==P?(e.stopPropagation(),T(null)):null!==p?(e.stopPropagation(),w()):k&&(e.stopPropagation(),M()))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[P,p,k,w,M]),!e&&!t)return(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:E("database.selectTableForData")});let I=e?.fields||[],F=e?.rows||[],B={};for(let e of r)B[e.name]=e.type+(e.maxLength?`(${e.maxLength})`:"");let D=F.length>0&&h.size===F.length,A=h.size>0&&!D;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",children:[t&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 flex items-center justify-center z-10",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[2]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-1 py-1 border-b border-border w-8 text-center",children:(0,n.jsx)("input",{type:"checkbox",checked:D,ref:e=>{e&&(e.indeterminate=A)},onChange:()=>{D?f(new Set):f(new Set(F.map((e,t)=>t)))},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(e=>{let t=u?.column===e.name?u.dir:null,r=c[e.name],s=r?.enabled;return(0,n.jsxs)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono relative",children:[(0,n.jsxs)("span",{className:"cursor-pointer select-none hover:text-foreground transition-colors",onClick:()=>{var t;return t=e.name,void(u?.column===t?"ASC"===u.dir?x({column:t,dir:"DESC"}):x(null):x({column:t,dir:"ASC"}))},children:[e.name,B[e.name]&&(0,n.jsx)("span",{className:"ml-1 text-[9px] text-muted-foreground/60 font-normal",children:B[e.name]}),"ASC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↑"}),"DESC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↓"})]}),(0,n.jsx)("button",{onClick:t=>{if(t.stopPropagation(),P===e.name)return void T(null);let r=t.currentTarget.closest("th").getBoundingClientRect();R({left:r.left,bottom:r.bottom}),T(e.name)},className:`ml-1 inline-flex items-center transition-colors ${s?"text-brand":"text-muted-foreground/40 hover:text-muted-foreground"}`,children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 16 16",fill:"currentColor",children:(0,n.jsx)("path",{d:"M1 2h14l-5.5 6.5V14l-3-2v-3.5z"})})}),P===e.name&&(0,n.jsx)(rx,{filter:r||null,onApply:t=>{m(e.name,t),T(null)},onClear:()=>{m(e.name,null),T(null)},onToggle:t=>{r&&m(e.name,{...r,enabled:t})},onClose:()=>T(null),colName:e.name,anchorRect:$})]},e.name)})]})}),(0,n.jsxs)("tbody",{children:[k&&(0,n.jsxs)("tr",{className:"bg-emerald-500/5",children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border text-center",children:(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:S,className:"text-[10px] text-green-11 hover:text-green-9",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:M,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]})}),I.map(e=>(0,n.jsx)("td",{className:"px-0.5 py-0.5 border-b border-border",children:(0,n.jsx)("input",{type:"text",value:y[e.name]??"",onChange:t=>C(e.name,t.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]",placeholder:"NULL"})},e.name))]}),F.map((e,t)=>(0,n.jsxs)("tr",{className:`hover:bg-hover ${h.has(t)?"bg-brand/5":""} ${p===t?"bg-blue-500/5":""}`,children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border/50 text-center",children:p===t?(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:j,className:"text-[10px] text-green-11 hover:text-green-9",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:w,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]}):(0,n.jsx)("input",{type:"checkbox",checked:h.has(t),onChange:()=>{let e;(e=new Set(h)).has(t)?e.delete(t):e.add(t),f(e)},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(r=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onDoubleClick:()=>{null===p&&b(t)},onContextMenu:t=>{t.preventDefault(),L(rd(e[r.name]))},children:p===t?(0,n.jsx)("input",{type:"text",value:g[r.name]??"",onChange:e=>v(r.name,e.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]"}):null===e[r.name]||void 0===e[r.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rc,{text:rd(e[r.name])})},r.name))]},t))]})]}),0===F.length&&!t&&(0,n.jsx)("div",{className:"p-4 text-xs text-muted-foreground text-center",children:E("common.noData")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-2 py-1 border-t border-border text-[10px] text-muted-foreground bg-card/30 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:N,disabled:k,className:"px-1.5 py-0.5 text-[10px] text-green-11 hover:text-green-9 disabled:opacity-30",children:E("database.addRow")}),(0,n.jsx)("span",{children:E("database.totalRows",{count:i})}),e?.duration!==void 0&&(0,n.jsxs)("span",{children:[e.duration,"ms"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>d(a-1),disabled:0===a,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[a+1," / ",l]}),(0,n.jsx)("button",{onClick:()=>d(a+1),disabled:a>=l-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function rf({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:a,error:l,loading:i,sqlRef:d,onCellCopy:c}){let{t:u}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 p-2 border-b border-border",children:[(0,n.jsx)("textarea",{ref:d,value:e,onChange:e=>t(e.target.value),onKeyDown:s,placeholder:u("database.sqlPlaceholder",{modKey:(0,tG.Mu)()}),className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("button",{onClick:r,disabled:i||!e.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:u(i?"database.executing":"database.execute")}),a?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[a.command&&!a.fields?u("database.rowsAffected",{command:a.command,count:a.rowCount,duration:a.duration}):u("database.queryRows",{count:a.rows?.length??0,duration:a.duration}),a.truncated&&` ${u("database.resultTruncated")}`]})]})]}),l&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:l}),a?.fields&&a.rows&&(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:a.fields.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e.name},e.name))})}),(0,n.jsx)("tbody",{children:a.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-hover",children:a.fields.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onContextMenu:r=>{r.preventDefault(),c(rd(e[t.name]))},children:null===e[t.name]||void 0===e[t.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rc,{text:rd(e[t.name])})},t.name))},t))})]})})]})}t5({type:"database",idPrefix:"db",match(e){let t=e.trim().toLowerCase();return t.startsWith("postgresql://")||t.startsWith("postgres://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"postgres";r=`${n}@${e.hostname}${e.port?":"+e.port:""}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(ru,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await t8("db",e.id)}});let rp=[{value:"=",label:"="},{value:"!=",label:"!="},{value:">",label:">"},{value:"<",label:"<"},{value:">=",label:">="},{value:"<=",label:"<="},{value:"LIKE",label:"LIKE"},{value:"NOT LIKE",label:"NOT LIKE"},{value:"IN",label:"IN"},{value:"IS NULL",label:"IS NULL"},{value:"IS NOT NULL",label:"IS NOT NULL"}];function rg(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}function rb(e){return`\`${e.replace(/`/g,"``")}\``}function rv(e){try{let t=e.match(/\/\/[^/]+\/([^?]+)/);if(t)return t[1]}catch{}return""}function rj(e){return null==e?"":"object"==typeof e?JSON.stringify(e):String(e)}function rw({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,maxW:600,maxH:300,above:!0}),l=(0,s.useRef)(null),i=(0,s.useRef)(null),d=(0,s.useRef)(!1),c=(0,m.F2)(),u=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{d.current||r(!1)},80)},[]),x=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),d.current=!1,i.current=setTimeout(()=>{let e=l.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=c?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,i=n?.width??window.innerWidth,d=n?.height??window.innerHeight,u=t.left-s,m=t.top-o,x=t.bottom-o,h=Math.min(600,i-u-8),f=m-8,p=d-x-8,g=f>p&&f>80,b=g?f-4:p-4;a({x:h<200?Math.max(8,i-600-8):u,y:g?m-4:x+4,maxW:h<200?Math.min(600,i-16):h,maxH:Math.max(60,b),above:g}),r(!0)},350)},[c]),h=(0,s.useCallback)(()=>{u()},[u]),f=(0,s.useCallback)(()=>{d.current=!0,i.current&&clearTimeout(i.current)},[]),p=(0,s.useCallback)(()=>{d.current=!1,u()},[u]);return(0,n.jsxs)("span",{ref:l,className:"block truncate",onMouseEnter:x,onMouseLeave:h,children:[e,t&&(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lv2 whitespace-pre-wrap break-all select-text cursor-text",style:{left:o.x,top:o.y,maxWidth:o.maxW,maxHeight:o.maxH,transform:o.above?"translateY(-100%)":void 0},onMouseEnter:f,onMouseLeave:p,children:function(e){try{let t=JSON.parse(e);if("object"==typeof t&&null!==t)return JSON.stringify(t,null,2)}catch{}return e}(e)})})]})}function rk({id:e,connectionString:t,displayName:r,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:d,onSelect:c,onClose:u,onToggleMaximize:m,timestamp:x,onTitleMouseDown:h}){let{t:f}=(0,o.Bd)(),{showToast:p}=(0,M.dj)(),[g,b]=(0,s.useState)("connecting"),[v,j]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)(()=>rv(t)),[C,S]=(0,s.useState)([]),[L,E]=(0,s.useState)(null),[P,T]=(0,s.useState)("table"),[$,R]=(0,s.useState)("data"),[I,F]=(0,s.useState)([]),[B,D]=(0,s.useState)([]),[A,H]=(0,s.useState)([]),[W,z]=(0,s.useState)([]),[O,_]=(0,s.useState)(null),[q,V]=(0,s.useState)(0),[U,K]=(0,s.useState)(!1),[Q,G]=(0,s.useState)(0),[J,Y]=(0,s.useState)(new Set),[X,Z]=(0,s.useState)(!1),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)({}),[es,eo]=(0,s.useState)(!1),[ea,el]=(0,s.useState)({}),[ei,ed]=(0,s.useState)({}),[ec,eu]=(0,s.useState)(null),[em,ex]=(0,s.useState)(""),[eh,ef]=(0,s.useState)(null),[ep,eg]=(0,s.useState)(""),[eb,ev]=(0,s.useState)(!1),ej=(0,s.useRef)(null),ew=(0,s.useCallback)(async()=>{b("connecting"),j("");try{let r=await rt("/api/mysql/connect",{id:e,connectionString:t});k(r.schemas||[]);let n=rv(t);r.schemas?.length>0&&n&&r.schemas.includes(n)?N(n):r.schemas?.length>0&&N(r.schemas[0]),b("connected")}catch(e){j(e instanceof Error?e.message:String(e)),b("error")}},[e,t]);(0,s.useEffect)(()=>{ew()},[ew]);let ek=(0,s.useCallback)(async()=>{if("connected"===g)try{let r=await rr("/api/mysql/schemas",{id:e,connectionString:t,schema:y});S(r.tables||[])}catch{}},[e,t,y,g]);(0,s.useEffect)(()=>{ek()},[ek]);let ey=(0,s.useCallback)(async(r,n,s,o)=>{K(!0);let a=s??ei,l=void 0!==o?o:ec;try{let s=`${rb(y)}.${rb(r)}`,{where:o,params:i}=function(e){let t=[],r=[];for(let[n,s]of Object.entries(e)){if(!s.enabled)continue;let e=rb(n);if("IS NULL"===s.op)t.push(`${e} IS NULL`);else if("IS NOT NULL"===s.op)t.push(`${e} IS NOT NULL`);else if("IN"===s.op){let n=s.value.split(",").map(e=>e.trim()).filter(Boolean);if(0===n.length)continue;let o=n.map(e=>(r.push(e),"?"));t.push(`${e} IN (${o.join(", ")})`)}else"LIKE"===s.op||s.op,t.push(`${e} ${s.op} ?`),r.push(s.value)}return{where:t.length>0?` WHERE ${t.join(" AND ")}`:"",params:r}}(a),d=l?` ORDER BY ${rb(l.column)} ${l.dir}`:"",c=`SELECT * FROM ${s}${o}${d} LIMIT 50 OFFSET ${50*n}`,u=await rt("/api/mysql/query",{id:e,connectionString:t,sql:c,params:i});_(u);let m=`SELECT count(*) AS cnt FROM ${s}${o}`,x=await rt("/api/mysql/query",{id:e,connectionString:t,sql:m,params:i});G(x.rows?.[0]?.cnt??0)}catch{}K(!1)},[e,t,y,ei,ec]),eN=(0,s.useCallback)(async r=>{E(r),V(0),et(null),eo(!1),Y(new Set),Z(!1),ed({}),eu(null);try{let n=await rr("/api/mysql/columns",{id:e,connectionString:t,schema:y,table:r});F(n.columns||[]),D(n.primaryKeys||[]),H(n.foreignKeys||[]),z(n.indexes||[])}catch{}ey(r,0,{},null)},[e,t,y,ey]),eC=(0,s.useCallback)(async()=>{if(em.trim()){ev(!0),eg(""),ef(null);try{let r=await rt("/api/mysql/query",{id:e,connectionString:t,sql:em});ef(r)}catch(e){eg(e instanceof Error?e.message:String(e))}ev(!1)}},[e,t,em]),eS=(0,s.useCallback)(async()=>{if(null===ee||!O||!L)return;let r=O.rows[ee],n=[],s=[];for(let e of I)void 0!==er[e.name]&&er[e.name]!==rj(r[e.name]??"")&&(n.push(`${rb(e.name)} = ?`),s.push(""===er[e.name]&&e.nullable?null:er[e.name]));if(0===n.length)return void et(null);let o=B.length>0?B:I.map(e=>e.name),a=[];for(let e of o)null===r[e]||void 0===r[e]?a.push(`${rb(e)} IS NULL`):(a.push(`${rb(e)} = ?`),s.push(r[e]));let l=`UPDATE ${rb(y)}.${rb(L)} SET ${n.join(", ")} WHERE ${a.join(" AND ")}`;try{await rt("/api/mysql/query",{id:e,connectionString:t,sql:l,params:s}),et(null),ey(L,q,ei,ec)}catch(e){alert(`Update failed: ${e instanceof Error?e.message:String(e)}`)}},[ee,O,L,I,B,er,e,t,y,ey,q,ei,ec]),eM=(0,s.useCallback)(async()=>{if(!L)return;let r=[],n=[],s=[];for(let e of I)void 0!==ea[e.name]&&""!==ea[e.name]&&(r.push(rb(e.name)),n.push(ea[e.name]),s.push("?"));if(0===r.length)return;let o=`INSERT INTO ${rb(y)}.${rb(L)} (${r.join(", ")}) VALUES (${s.join(", ")})`;try{await rt("/api/mysql/query",{id:e,connectionString:t,sql:o,params:n}),eo(!1),el({}),ey(L,q,ei,ec)}catch(e){alert(`Insert failed: ${e instanceof Error?e.message:String(e)}`)}},[L,I,ea,e,t,y,ey,q,ei,ec]),eL=(0,s.useCallback)(async()=>{if(0===J.size||!O||!L)return;let r=B.length>0?B:I.map(e=>e.name),n=0;for(let s of Array.from(J).sort((e,t)=>t-e)){let o=O.rows[s];if(!o)continue;let a=[],l=[];for(let e of r)null===o[e]||void 0===o[e]?a.push(`${rb(e)} IS NULL`):(a.push(`${rb(e)} = ?`),l.push(o[e]));let i=`DELETE FROM ${rb(y)}.${rb(L)} WHERE ${a.join(" AND ")} LIMIT 1`;try{await rt("/api/mysql/query",{id:e,connectionString:t,sql:i,params:l})}catch{n++}}Y(new Set),Z(!1),ey(L,q,ei,ec),n>0&&alert(f("mysql.deleteRowsFailed",{count:n}))},[J,O,L,B,I,e,t,y,ey,q,ei,ec]),eE=(0,s.useCallback)(async r=>{if(!L)return;if(J.size>0&&O){let e,t=O.fields.map(e=>e.name),n=Array.from(J).sort((e,t)=>e-t).map(e=>O.rows[e]).filter(Boolean);if("json"===r)e=JSON.stringify(n,null,2);else{let r=[t.join(",")];for(let e of n)r.push(t.map(t=>{let r=e[t];if(null==r)return"";let n="object"==typeof r?JSON.stringify(r):String(r);return n.includes(",")||n.includes('"')||n.includes("\n")?`"${n.replace(/"/g,'""')}"`:n}).join(","));e=r.join("\n")}navigator.clipboard.writeText(e);return}let n=`SELECT * FROM ${rb(y)}.${rb(L)}`;try{let s=await rn("/api/mysql/export",{id:e,connectionString:t,sql:n,format:r}),o=URL.createObjectURL(s),a=document.createElement("a");a.href=o,a.download=`${L}.${r}`,a.click(),URL.revokeObjectURL(o)}catch(e){alert(`Export failed: ${e instanceof Error?e.message:String(e)}`)}},[L,e,t,y,J,O]),eP=(0,s.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),eC())},[eC]),eT=Math.max(1,Math.ceil(Q/50)),e$=(0,s.useCallback)(e=>{L&&(V(e),ey(L,e,ei,ec))},[L,ey,ei,ec]),eR=(0,s.useCallback)((e,t)=>{let r={...ei};t?r[e]=t:delete r[e],ed(r),V(0),Y(new Set),L&&ey(L,0,r,ec)},[ei,ec,L,ey]),eI=(0,s.useCallback)(()=>{ed({}),V(0),Y(new Set),L&&ey(L,0,{},ec)},[ec,L,ey]),eF=(0,s.useCallback)(e=>{eu(e),V(0),Y(new Set),L&&ey(L,0,ei,e)},[ei,L,ey]);return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
22
+ relative transition-colors cursor-pointer
23
+ ${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
24
+ ${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:c,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:h,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"\uD83D\uDC2C"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===g&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===g&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:f("mysql.connectionFailed")}),"connected"===g&&(0,n.jsx)("span",{className:"text-[10px] text-green-11 flex-shrink-0",children:f("mysql.connected")}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rg(x)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?f("browser.exitMaximize",{modKey:(0,tG.Mu)()}):f("browser.maximize",{modKey:(0,tG.Mu)()}),children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:f("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:l&&i?i-41:d??360},className:"flex overflow-hidden",children:["connecting"===g&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),f("mysql.connecting")]}),"error"===g&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:v}),(0,n.jsx)("button",{onClick:ew,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:f("common.retry")})]}),"connected"===g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[w.length>1?(0,n.jsx)("select",{value:y,onChange:e=>{N(e.target.value),E(null)},className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1",children:w.map(e=>(0,n.jsx)("option",{value:e,children:e},e))}):(0,n.jsx)("span",{className:"flex-1 min-w-0 text-xs text-muted-foreground truncate",children:y}),(0,n.jsx)("button",{onClick:ek,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-hover active:bg-active transition-colors",title:f("mysql.refreshTableList"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsx)("div",{className:"flex items-center border-b border-border",children:["table","view"].map(e=>(0,n.jsx)("button",{onClick:()=>T(e),className:`flex-1 py-1 text-[10px] font-medium transition-colors ${P===e?"text-brand border-b border-brand":"text-muted-foreground hover:text-foreground"}`,children:{table:f("mysql.filterTable"),view:f("mysql.filterView")}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[C.filter(e=>"table"===P?"view"!==e.type:"view"===e.type).map(e=>(0,n.jsxs)("div",{onClick:()=>eN(e.name),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer truncate transition-colors ${L===e.name?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] text-muted-foreground",children:"view"===e.type?"V":"T"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:(0,n.jsx)(rw,{text:e.name})}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.rowEstimate>0?`~${e.rowEstimate}`:""})]},e.name)),0===C.length&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:f("mysql.noTables")})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["structure","data","sql"].map(e=>(0,n.jsx)("button",{onClick:()=>R(e),className:`px-3 py-1.5 text-xs transition-colors ${$===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{structure:f("mysql.tabStructure"),data:f("mysql.tabData"),sql:"SQL"}[e]},e)),L&&"data"===$&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[Object.values(ei).some(e=>e.enabled)&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-brand",children:f("mysql.filterActive",{count:Object.values(ei).filter(e=>e.enabled).length})}),(0,n.jsx)("button",{onClick:eI,className:"px-1 py-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors",title:f("mysql.clearAllFilters"),children:"✕"}),(0,n.jsx)("span",{className:"text-border",children:"|"})]}),J.size>0&&!X&&(0,n.jsx)("button",{onClick:()=>Z(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:f("mysql.deleteNRows",{count:J.size})}),X&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-[10px] text-destructive",children:f("mysql.confirmDeleteRows")}),(0,n.jsx)("button",{onClick:eL,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:f("common.confirm")}),(0,n.jsx)("button",{onClick:()=>Z(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:f("common.cancel")})]}),(0,n.jsx)("button",{onClick:()=>eE("csv"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:J.size>0?f("mysql.copyCsvSelected"):f("mysql.copyCsvAll"),children:J.size>0?f("mysql.copyCSV"):f("mysql.CSV")}),(0,n.jsx)("button",{onClick:()=>eE("json"),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",title:J.size>0?f("mysql.copyJsonSelected"):f("mysql.copyJsonAll"),children:J.size>0?f("mysql.copyJSON"):f("mysql.JSON")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:L||"sql"===$?"structure"===$?(0,n.jsx)(ry,{columns:I,primaryKeys:B,foreignKeys:A,indexes:W}):"data"===$?(0,n.jsx)(rC,{result:O,loading:U,columns:I,page:q,totalPages:eT,totalRows:Q,onPageChange:e$,filters:ei,sort:ec,onFilterChange:eR,onSortChange:eF,selectedRows:J,onSelectedRowsChange:e=>{Y(e),Z(!1)},editingRowIdx:ee,editValues:er,onStartEdit:e=>{if(!O)return;let t=O.rows[e],r={};for(let e of I)r[e.name]=null==t[e.name]?"":rj(t[e.name]);en(r),et(e)},onEditChange:(e,t)=>en(r=>({...r,[e]:t})),onSaveEdit:eS,onCancelEdit:()=>et(null),isAddingRow:es,newRowValues:ea,onStartAdd:()=>{eo(!0),el({})},onNewRowChange:(e,t)=>el(r=>({...r,[e]:t})),onSaveNewRow:eM,onCancelAdd:()=>{eo(!1),el({})},onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)(rS,{sqlInput:em,onSqlChange:ex,onExecute:eC,onKeyDown:eP,result:eh,error:ep,loading:eb,sqlRef:ej,onCellCopy:e=>{navigator.clipboard.writeText(e),p(f("common.copied"))}}):(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:f("mysql.selectTable")})})]})]})]}),!l&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===g?"bg-green-500":"error"===g?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:f("common.connecting"),connected:f("common.connected"),error:f("common.connectionFailed")}[g]}),"connected"===g&&L&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:L}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rg(x)})]})]})})}function ry({columns:e,primaryKeys:t,foreignKeys:r,indexes:s}){let{t:a}=(0,o.Bd)();return 0===e.length?(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:a("mysql.selectTableToView")}):(0,n.jsxs)("div",{className:"p-2 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("mysql.columns")}),(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"text-left text-muted-foreground border-b border-border",children:[(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colName")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colType")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colNullable")}),(0,n.jsx)("th",{className:"px-1.5 py-1 font-medium",children:a("mysql.colDefault")})]})}),(0,n.jsx)("tbody",{children:e.map(e=>(0,n.jsxs)("tr",{className:"border-b border-border/50 hover:bg-hover",children:[(0,n.jsxs)("td",{className:"px-1.5 py-1 font-mono",children:[e.isPrimaryKey&&(0,n.jsx)("span",{className:"text-amber-11 mr-1",title:a("mysql.primaryKey"),children:"\uD83D\uDD11"}),e.name]}),(0,n.jsxs)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono",children:[e.type,e.maxLength?`(${e.maxLength})`:""]}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground",children:e.nullable?"YES":"NO"}),(0,n.jsx)("td",{className:"px-1.5 py-1 text-muted-foreground font-mono truncate max-w-[120px]",children:e.default||""})]},e.name))})]})]}),r.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("mysql.foreignKeys")}),(0,n.jsx)("div",{className:"space-y-0.5",children:r.map((e,t)=>(0,n.jsxs)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground",children:[e.column," → ",e.refSchema,".",e.refTable,".",e.refColumn]},t))})]}),s.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1",children:a("mysql.indexes")}),(0,n.jsx)("div",{className:"space-y-0.5",children:s.map(e=>(0,n.jsx)("div",{className:"text-xs font-mono px-1.5 text-muted-foreground truncate","data-tooltip":e.definition,"data-tooltip-mono":!0,children:e.name},e.name))})]})]})}function rN({filter:e,onApply:t,onClear:r,onToggle:a,onClose:l,colName:i,anchorRect:d}){let{t:c}=(0,o.Bd)(),[u,x]=(0,s.useState)(e?.op||"="),[h,f]=(0,s.useState)(e?.value||""),p=(0,s.useRef)(null),g=(0,m.F2)();(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&l()};return document.addEventListener("mousedown",e,!0),()=>document.removeEventListener("mousedown",e,!0)},[l]);let b="IS NULL"!==u&&"IS NOT NULL"!==u,v=()=>{(!b||h.trim())&&t({op:u,value:h.trim(),enabled:!0})},j=g?.getBoundingClientRect(),w=j?.left??0,k=j?.top??0,y=j?.width??window.innerWidth,N=d.left-w;N+220>y-8&&(N=y-220-8),N<8&&(N=8);let C=d.bottom+2-k;return(0,n.jsx)(m.ZL,{children:(0,n.jsxs)("div",{ref:p,className:"fixed z-[9998] w-[220px] bg-popover border border-border rounded-md shadow-lv2 p-2 space-y-2",style:{left:N,top:C},onClick:e=>e.stopPropagation(),children:[e&&(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("label",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:e.enabled,onChange:e=>a(e.target.checked),className:"w-3 h-3 accent-brand"}),c("mysql.enable")]}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground font-mono truncate max-w-[120px]",children:i})]}),(0,n.jsx)("select",{value:u,onChange:e=>x(e.target.value),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 focus:outline-none focus:ring-1 focus:ring-ring",children:rp.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))}),b&&(0,n.jsx)("input",{type:"text",value:h,onChange:e=>f(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),v())},placeholder:c("IN"===u?"mysql.commaValues":"LIKE"===u?"mysql.likePattern":"mysql.valuePlaceholder"),className:"w-full text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring",autoFocus:!0}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:v,disabled:b&&!h.trim(),className:"flex-1 px-2 py-1 text-[10px] bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-40 transition-colors",children:c("mysql.apply")}),e&&(0,n.jsx)("button",{onClick:r,className:"flex-1 px-2 py-1 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground transition-colors",children:c("mysql.clearFilter")})]})]})})}function rC({result:e,loading:t,columns:r,page:a,totalPages:l,totalRows:i,onPageChange:d,filters:c,sort:u,onFilterChange:m,onSortChange:x,selectedRows:h,onSelectedRowsChange:f,editingRowIdx:p,editValues:g,onStartEdit:b,onEditChange:v,onSaveEdit:j,onCancelEdit:w,isAddingRow:k,newRowValues:y,onStartAdd:N,onNewRowChange:C,onSaveNewRow:S,onCancelAdd:M,onCellCopy:L}){let{t:E}=(0,o.Bd)(),[P,T]=(0,s.useState)(null),[$,R]=(0,s.useState)({left:0,bottom:0});if((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(null!==P?(e.stopPropagation(),T(null)):null!==p?(e.stopPropagation(),w()):k&&(e.stopPropagation(),M()))};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[P,p,k,w,M]),!e&&!t)return(0,n.jsx)("div",{className:"p-4 text-sm text-muted-foreground",children:E("mysql.selectTableForData")});let I=e?.fields||[],F=e?.rows||[],B={};for(let e of r)B[e.name]=e.type+(e.maxLength?`(${e.maxLength})`:"");let D=F.length>0&&h.size===F.length,A=h.size>0&&!D;return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",children:[t&&(0,n.jsx)("div",{className:"absolute inset-0 bg-background/50 flex items-center justify-center z-10",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})}),(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[2]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-1 py-1 border-b border-border w-8 text-center",children:(0,n.jsx)("input",{type:"checkbox",checked:D,ref:e=>{e&&(e.indeterminate=A)},onChange:()=>{D?f(new Set):f(new Set(F.map((e,t)=>t)))},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(e=>{let t=u?.column===e.name?u.dir:null,r=c[e.name],s=r?.enabled;return(0,n.jsxs)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono relative",children:[(0,n.jsxs)("span",{className:"cursor-pointer select-none hover:text-foreground transition-colors",onClick:()=>{var t;return t=e.name,void(u?.column===t?"ASC"===u.dir?x({column:t,dir:"DESC"}):x(null):x({column:t,dir:"ASC"}))},children:[e.name,B[e.name]&&(0,n.jsx)("span",{className:"ml-1 text-[9px] text-muted-foreground/60 font-normal",children:B[e.name]}),"ASC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↑"}),"DESC"===t&&(0,n.jsx)("span",{className:"ml-0.5 text-brand",children:"↓"})]}),(0,n.jsx)("button",{onClick:t=>{if(t.stopPropagation(),P===e.name)return void T(null);let r=t.currentTarget.closest("th").getBoundingClientRect();R({left:r.left,bottom:r.bottom}),T(e.name)},className:`ml-1 inline-flex items-center transition-colors ${s?"text-brand":"text-muted-foreground/40 hover:text-muted-foreground"}`,children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 16 16",fill:"currentColor",children:(0,n.jsx)("path",{d:"M1 2h14l-5.5 6.5V14l-3-2v-3.5z"})})}),P===e.name&&(0,n.jsx)(rN,{filter:r||null,onApply:t=>{m(e.name,t),T(null)},onClear:()=>{m(e.name,null),T(null)},onToggle:t=>{r&&m(e.name,{...r,enabled:t})},onClose:()=>T(null),colName:e.name,anchorRect:$})]},e.name)})]})}),(0,n.jsxs)("tbody",{children:[k&&(0,n.jsxs)("tr",{className:"bg-emerald-500/5",children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border text-center",children:(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:S,className:"text-[10px] text-green-11 hover:text-green-9",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:M,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]})}),I.map(e=>(0,n.jsx)("td",{className:"px-0.5 py-0.5 border-b border-border",children:(0,n.jsx)("input",{type:"text",value:y[e.name]??"",onChange:t=>C(e.name,t.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]",placeholder:"NULL"})},e.name))]}),F.map((e,t)=>(0,n.jsxs)("tr",{className:`hover:bg-hover ${h.has(t)?"bg-brand/5":""} ${p===t?"bg-blue-500/5":""}`,children:[(0,n.jsx)("td",{className:"px-1 py-0.5 border-b border-border/50 text-center",children:p===t?(0,n.jsxs)("div",{className:"flex gap-0.5 justify-center",children:[(0,n.jsx)("button",{onClick:j,className:"text-[10px] text-green-11 hover:text-green-9",title:E("common.save"),children:"✓"}),(0,n.jsx)("button",{onClick:w,className:"text-[10px] text-muted-foreground hover:text-foreground",title:E("common.cancel"),children:"✕"})]}):(0,n.jsx)("input",{type:"checkbox",checked:h.has(t),onChange:()=>{let e;(e=new Set(h)).has(t)?e.delete(t):e.add(t),f(e)},className:"w-3 h-3 accent-brand cursor-pointer"})}),I.map(r=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onDoubleClick:()=>{null===p&&b(t)},onContextMenu:t=>{t.preventDefault(),L(rj(e[r.name]))},children:p===t?(0,n.jsx)("input",{type:"text",value:g[r.name]??"",onChange:e=>v(r.name,e.target.value),className:"w-full px-1 py-0.5 text-xs bg-background border border-input rounded font-mono min-w-[60px]"}):null===e[r.name]||void 0===e[r.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rw,{text:rj(e[r.name])})},r.name))]},t))]})]}),0===F.length&&!t&&(0,n.jsx)("div",{className:"p-4 text-xs text-muted-foreground text-center",children:E("common.noData")})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-2 py-1 border-t border-border text-[10px] text-muted-foreground bg-card/30 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:N,disabled:k,className:"px-1.5 py-0.5 text-[10px] text-green-11 hover:text-green-9 disabled:opacity-30",children:E("mysql.addRow")}),(0,n.jsx)("span",{children:E("mysql.totalRows",{count:i})}),e?.duration!==void 0&&(0,n.jsxs)("span",{children:[e.duration,"ms"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>d(a-1),disabled:0===a,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"◀"}),(0,n.jsxs)("span",{children:[a+1," / ",l]}),(0,n.jsx)("button",{onClick:()=>d(a+1),disabled:a>=l-1,className:"px-1 py-0.5 hover:text-foreground disabled:opacity-30",children:"▶"})]})]})]})}function rS({sqlInput:e,onSqlChange:t,onExecute:r,onKeyDown:s,result:a,error:l,loading:i,sqlRef:d,onCellCopy:c}){let{t:u}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 p-2 border-b border-border",children:[(0,n.jsx)("textarea",{ref:d,value:e,onChange:e=>t(e.target.value),onKeyDown:s,placeholder:u("mysql.sqlPlaceholder",{modKey:(0,tG.Mu)()}),className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("button",{onClick:r,disabled:i||!e.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:u(i?"mysql.executing":"mysql.execute")}),a?.duration!==void 0&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[a.command&&!a.fields?u("mysql.rowsAffected",{command:a.command,count:a.rowCount,duration:a.duration}):u("mysql.queryRows",{count:a.rows?.length??0,duration:a.duration}),a.truncated&&` ${u("mysql.resultTruncated")}`]})]})]}),l&&(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-destructive bg-destructive/5 border-b border-border break-all",children:l}),a?.fields&&a.rows&&(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:a.fields.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e.name},e.name))})}),(0,n.jsx)("tbody",{children:a.rows.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-hover",children:a.fields.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",onContextMenu:r=>{r.preventDefault(),c(rj(e[t.name]))},children:null===e[t.name]||void 0===e[t.name]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):(0,n.jsx)(rw,{text:rj(e[t.name])})},t.name))},t))})]})})]})}t5({type:"mysql",idPrefix:"mysql",match:e=>e.trim().toLowerCase().startsWith("mysql://"),parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"mysql";r=`${n}@${e.hostname}${e.port?":"+e.port:""}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(rk,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await t8("mysql",e.id)}});let rM={string:{label:"S",color:"text-emerald-600 dark:text-emerald-400 bg-emerald-500/15"},hash:{label:"H",color:"text-blue-600 dark:text-blue-400 bg-blue-500/15"},list:{label:"L",color:"text-orange-600 dark:text-orange-400 bg-orange-500/15"},set:{label:"SET",color:"text-teal-600 dark:text-teal-400 bg-teal-500/15"},zset:{label:"Z",color:"text-purple-600 dark:text-purple-400 bg-purple-500/15"},stream:{label:"STR",color:"text-pink-600 dark:text-pink-400 bg-pink-500/15"}};function rL({type:e}){let t=rM[e]||{label:"?",color:"text-muted-foreground bg-muted"};return(0,n.jsx)("span",{className:`inline-block text-[9px] font-mono font-bold leading-none px-1 py-0.5 rounded flex-shrink-0 ${t.color}`,children:t.label})}function rE({text:e}){let[t,r]=(0,s.useState)(!1),[o,a]=(0,s.useState)({x:0,y:0,above:!0}),l=(0,s.useRef)(null),i=(0,s.useRef)(null),d=(0,m.F2)(),c=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{let e=l.current;if(!e||e.scrollWidth<=e.clientWidth)return;let t=e.getBoundingClientRect(),n=d?.getBoundingClientRect(),s=n?.left??0,o=n?.top??0,i=n?.height??window.innerHeight,c=t.top-o,u=t.bottom-o,m=c>i/2;a({x:t.left-s,y:m?c-4:u+4,above:m}),r(!0)},350)},[d]),u=(0,s.useCallback)(()=>{i.current&&clearTimeout(i.current),r(!1)},[]);return(0,n.jsxs)("span",{ref:l,className:"block truncate",onMouseEnter:c,onMouseLeave:u,children:[e,t&&(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{className:"fixed z-[9999] max-w-[500px] max-h-[200px] overflow-y-auto px-2 py-1.5 text-xs font-mono bg-popover text-popover-foreground border border-border rounded shadow-lv2 whitespace-pre-wrap break-all select-text",style:{left:o.x,top:o.y,transform:o.above?"translateY(-100%)":void 0},children:e})})]})}function rP({id:e,connectionString:t,displayName:r,selected:a,maximized:l,expandedHeight:i,bubbleContentHeight:d,onSelect:c,onClose:u,onToggleMaximize:m,timestamp:x,onTitleMouseDown:h}){var f;let{t:p}=(0,o.Bd)(),{showToast:g}=(0,M.dj)(),[b,v]=(0,s.useState)("connecting"),[j,w]=(0,s.useState)(""),[k,y]=(0,s.useState)(null),[N,C]=(0,s.useState)([]),[S,L]=(0,s.useState)("0"),[E,P]=(0,s.useState)(!1),[T,$]=(0,s.useState)("*"),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)(null),[D,A]=(0,s.useState)(null),[H,W]=(0,s.useState)(!1),[z,O]=(0,s.useState)(null),[_,q]=(0,s.useState)(!1),[V,U]=(0,s.useState)("data"),[K,Q]=(0,s.useState)(""),[G,J]=(0,s.useState)(""),[Y,X]=(0,s.useState)([]),[Z,ee]=(0,s.useState)(!1),et=(0,s.useRef)(null),er=(0,s.useRef)(null),en=(0,s.useCallback)(async()=>{v("connecting"),w("");try{let r=await rt("/api/redis/connect",{id:e,connectionString:t});y(r),v("connected")}catch(e){w(e instanceof Error?e.message:String(e)),v("error")}},[e,t]);(0,s.useEffect)(()=>{en()},[en]);let es=(0,s.useCallback)(async(r,n,s)=>{I(!0);try{let o=await rt("/api/redis/keys",{id:e,connectionString:t,pattern:r,cursor:n,count:200});C(e=>s?[...e,...o.keys]:o.keys),L(o.cursor),P(o.hasMore)}catch{}I(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===b&&es(T,"0",!1)},[b]);let eo=(0,s.useCallback)(()=>{B(null),A(null),es(T,"0",!1)},[T,es]),ea=(0,s.useCallback)(async r=>{B(r),W(!0),O(null),q(!1);try{let n=await rt("/api/redis/get",{id:e,connectionString:t,key:r});A(n)}catch(e){A(null),g(e instanceof Error?e.message:p("redis.loadFailed"))}W(!1)},[e,t,g]),el=(0,s.useCallback)(async()=>{if(F)try{await rt("/api/redis/delete",{id:e,connectionString:t,keys:[F]}),B(null),A(null),q(!1),es(T,"0",!1)}catch(e){g(e instanceof Error?e.message:p("redis.deleteFailed"))}},[F,e,t,T,es,g]),ei=(0,s.useCallback)(async()=>{if(F&&null!==z)try{await rt("/api/redis/set",{id:e,connectionString:t,key:F,value:z,type:"string"}),O(null),ea(F),g(p("common.saved"))}catch(e){g(e instanceof Error?e.message:p("redis.saveFailed"))}},[F,z,e,t,ea,g]),ed=(0,s.useCallback)(async()=>{try{let r=await rt("/api/redis/command",{id:e,connectionString:t,command:"INFO"});Q("string"==typeof r.result?r.result:String(r.result))}catch{}},[e,t]);(0,s.useEffect)(()=>{"connected"===b&&"info"===V&&ed()},[b,V,ed]);let ec=(0,s.useCallback)(async()=>{let r,n=G.trim();if(!n)return;ee(!0),J("");let s=[],o=/(?:"([^"]*)")|(?:'([^']*)')|(\S+)/g;for(;null!==(r=o.exec(n));)s.push(r[1]??r[2]??r[3]);let a=s[0]||"",l=s.slice(1);try{let r=await rt("/api/redis/command",{id:e,connectionString:t,command:a,args:l});X(e=>[...e,{command:n,result:r.result,duration:r.duration,isError:!1}])}catch(e){X(t=>[...t,{command:n,result:e instanceof Error?e.message:String(e),duration:0,isError:!0}])}ee(!1)},[G,e,t]);return(0,s.useEffect)(()=>{et.current?.scrollIntoView({behavior:"smooth"})},[Y]),(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
25
+ relative transition-colors cursor-pointer
26
+ ${l?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
27
+ ${l?"":a?"border-brand":"border-brand/30"}`,onClick:l?void 0:c,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:m,onMouseDown:h,className:`flex items-center gap-2 px-4 py-1.5 border-b border-border ${l?"bg-card":"bg-card/50"}`,style:l?{height:41}:void 0,children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"♦"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===b&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"error"===b&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:p("common.connectionFailed")}),"connected"===b&&k&&(0,n.jsxs)("span",{className:"text-[10px] text-red-11 flex-shrink-0",children:["v",k.version," \xb7 ",k.dbSize," keys \xb7 ",k.memory]}),(0,n.jsx)("span",{className:"flex-1"}),x&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:function(e){if(!e)return"";let t=new Date(e);if(isNaN(t.getTime()))return"";let r=String(t.getMonth()+1).padStart(2,"0"),n=String(t.getDate()).padStart(2,"0"),s=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${r}-${n} ${s}:${o}`}(x)}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:l?p("browser.exitMaximize",{modKey:(0,tG.Mu)()}):p("browser.maximize",{modKey:(0,tG.Mu)()}),children:l?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3m0 18v-3a2 2 0 012-2h3M3 16h3a2 2 0 012 2v3"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:p("common.close"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:l&&i?i-41:d??360},className:"flex overflow-hidden",children:["connecting"===b&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin mr-2"}),p("common.connecting"),"..."]}),"error"===b&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-3 p-4",children:[(0,n.jsx)("span",{className:"text-sm text-destructive text-center break-all",children:j}),(0,n.jsx)("button",{onClick:en,className:"px-3 py-1.5 text-xs bg-brand text-white rounded-md hover:bg-brand/90 transition-colors",children:p("common.retry")})]}),"connected"===b&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"w-52 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-1.5 border-b border-border flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:T,onChange:e=>$(e.target.value),onKeyDown:e=>{"Enter"===e.key&&eo()},placeholder:p("redis.scanPlaceholder"),className:"flex-1 min-w-0 text-xs bg-background border border-input rounded px-1.5 py-1 font-mono focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("button",{onClick:eo,className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-hover active:bg-active transition-colors",title:p("redis.scanSearch"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"6.5",cy:"6.5",r:"4.5"}),(0,n.jsx)("path",{d:"M10 10l4 4"})]})}),(0,n.jsx)("button",{onClick:()=>es(T,"0",!1),className:"flex-shrink-0 w-5 h-5 flex items-center justify-center rounded text-muted-foreground hover:text-foreground hover:bg-hover active:bg-active transition-colors",title:p("common.refresh"),children:(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M1 1v5h5"}),(0,n.jsx)("path",{d:"M15 15v-5h-5"}),(0,n.jsx)("path",{d:"M13.5 6A6 6 0 0 0 3.2 3.2L1 6"}),(0,n.jsx)("path",{d:"M2.5 10a6 6 0 0 0 10.3 2.8L15 10"})]})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[N.map(e=>(0,n.jsxs)("div",{onClick:()=>ea(e.key),className:`flex items-center gap-1.5 px-2 py-1 cursor-pointer transition-colors ${F===e.key?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)(rL,{type:e.type}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:(0,n.jsx)(rE,{text:e.key})})]},e.key)),0===N.length&&!R&&(0,n.jsx)("div",{className:"p-2 text-muted-foreground text-center",children:p("redis.noKeys")}),R&&(0,n.jsx)("div",{className:"p-2 flex items-center justify-center",children:(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"})}),E&&!R&&(0,n.jsx)("button",{onClick:()=>es(T,S,!0),className:"w-full py-1.5 text-[10px] text-brand hover:text-brand/80 transition-colors",children:p("redis.loadMore")})]}),(0,n.jsxs)("div",{className:"px-2 py-1 border-t border-border text-[10px] text-muted-foreground",children:[N.length," keys",E?"+":"",k?` / ${k.dbSize} total`:""]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:[["data","info","cli"].map(e=>(0,n.jsx)("button",{onClick:()=>U(e),className:`px-3 py-1.5 text-xs transition-colors ${V===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{data:p("redis.tabData"),info:p("redis.tabInfo"),cli:"CLI"}[e]},e)),F&&"data"===V&&(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-1 pr-2",children:[D&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:["TTL: ",function(e,t){if(-1===e)return t("redis.neverExpires");if(-2===e)return t("redis.expired");if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m${e%60>0?` ${e%60}s`:""}`;let r=Math.floor(e/3600),n=Math.floor(e%3600/60);return`${r}h${n>0?` ${n}m`:""}`}(D.ttl,p),null!==D.size?` \xb7 ${null==(f=D.size)?"":f<1024?`${f} B`:f<1048576?`${(f/1024).toFixed(1)} KB`:`${(f/1048576).toFixed(1)} MB`}`:""]}),_?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-[10px] text-destructive",children:[p("common.confirm"),"?"]}),(0,n.jsx)("button",{onClick:el,className:"px-1.5 py-0.5 text-[10px] text-white bg-destructive rounded transition-colors hover:bg-destructive/80",children:p("common.confirm")}),(0,n.jsx)("button",{onClick:()=>q(!1),className:"px-1.5 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:p("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>q(!0),className:"px-1.5 py-0.5 text-[10px] text-destructive hover:text-destructive/80 bg-destructive/10 rounded transition-colors",children:p("common.delete")})]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:"data"===V?(0,n.jsx)(rT,{selectedKey:F,keyValue:D,keyLoading:H,editingValue:z,onStartEdit:e=>O(e),onEditChange:O,onSaveEdit:ei,onCancelEdit:()=>O(null),onCellCopy:e=>{navigator.clipboard.writeText(e),g(p("common.copied"))}}):"info"===V?(0,n.jsx)(r$,{infoText:K,onRefresh:ed}):(0,n.jsx)(rR,{cliInput:G,onInputChange:J,onExecute:ec,history:Y,loading:Z,endRef:et,inputRef:er})})]})]})]})]})})}function rT({selectedKey:e,keyValue:t,keyLoading:r,editingValue:s,onStartEdit:a,onEditChange:l,onSaveEdit:i,onCancelEdit:d,onCellCopy:c}){let{t:u}=(0,o.Bd)();if(!e)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.selectKey")});if(r)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if(!t)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.keyNotExist")});let{type:m,value:x}=t;if("string"===m){let t=String(x??""),r=null!==s;return(0,n.jsxs)("div",{className:"p-3 h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,n.jsx)(rL,{type:"string"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsx)("span",{className:"flex-1"}),r?(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("button",{onClick:i,className:"px-2 py-0.5 text-[10px] text-white bg-brand rounded hover:bg-brand/90",children:u("common.save")}),(0,n.jsx)("button",{onClick:d,className:"px-2 py-0.5 text-[10px] text-muted-foreground bg-muted rounded hover:text-foreground",children:u("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>a(t),className:"px-2 py-0.5 text-[10px] text-brand hover:text-brand/80 bg-brand/10 rounded transition-colors",children:u("common.edit")})]}),r?(0,n.jsx)("textarea",{value:s,onChange:e=>l(e.target.value),className:"flex-1 w-full px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-none focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}):(0,n.jsx)("pre",{className:"flex-1 overflow-auto text-xs font-mono bg-muted/30 rounded p-2 whitespace-pre-wrap break-all select-text cursor-text",onContextMenu:e=>{e.preventDefault(),c(t)},children:t})]})}if("hash"===m){let t=Object.entries(x||{});return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rL,{type:"hash"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[t.length," fields"]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-1/3",children:"Field"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Value"})]})}),(0,n.jsx)("tbody",{children:t.map(([e,t])=>(0,n.jsxs)("tr",{className:"hover:bg-hover",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[150px]",onContextMenu:t=>{t.preventDefault(),c(e)},children:(0,n.jsx)(rE,{text:e})}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:e=>{e.preventDefault(),c(t)},children:(0,n.jsx)(rE,{text:t})})]},e))})]})})]})}if("list"===m){let t=x?.items||[],r=x?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rL,{type:"list"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nItems",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-16",children:"#"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Value"})]})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsxs)("tr",{className:"hover:bg-hover",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 text-muted-foreground",children:t}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:t=>{t.preventDefault(),c(e)},children:(0,n.jsx)(rE,{text:e})})]},t))})]})})]})}if("set"===m){let t=x?.items||[],r=x?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rL,{type:"set"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nMembers",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Member"})})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-hover",children:(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[400px]",onContextMenu:t=>{t.preventDefault(),c(e)},children:(0,n.jsx)(rE,{text:e})})},t))})]})})]})}if("zset"===m){let t=x?.items||[],r=x?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rL,{type:"zset"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nMembers",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Member"}),(0,n.jsx)("th",{className:"px-2 py-1 text-right text-muted-foreground font-medium border-b border-border w-28",children:"Score"})]})}),(0,n.jsx)("tbody",{children:t.map((e,t)=>(0,n.jsxs)("tr",{className:"hover:bg-hover",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",onContextMenu:t=>{t.preventDefault(),c(e.member)},children:(0,n.jsx)(rE,{text:e.member})}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono text-right text-muted-foreground",children:e.score})]},t))})]})})]})}if("stream"===m){let t=x?.entries||[],r=x?.total||0;return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-1.5 border-b border-border",children:[(0,n.jsx)(rL,{type:"stream"}),(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e}),(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:[u("redis.nEntries",{total:r}),t.length<r?` (${u("redis.showingN",{count:t.length})})`:""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsxs)("tr",{children:[(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border w-40",children:"ID"}),(0,n.jsx)("th",{className:"px-2 py-1 text-left text-muted-foreground font-medium border-b border-border",children:"Fields"})]})}),(0,n.jsx)("tbody",{children:t.map(([e,t])=>{let r=[];for(let e=0;e<t.length;e+=2)r.push(`${t[e]}: ${t[e+1]}`);return(0,n.jsxs)("tr",{className:"hover:bg-hover",children:[(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono text-muted-foreground",children:e}),(0,n.jsx)("td",{className:"px-2 py-0.5 border-b border-border/50 font-mono truncate max-w-[300px]",children:(0,n.jsx)(rE,{text:r.join(", ")})})]},e)})})]})})]})}return(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-sm text-muted-foreground",children:u("redis.unsupportedType",{type:m})})}function r$({infoText:e,onRefresh:t}){let{t:r}=(0,o.Bd)();if(!e)return(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-brand border-t-transparent rounded-full animate-spin"})});let s=[],a=null;for(let t of e.split("\n")){let e=t.trim();if(e){if(e.startsWith("#"))a={title:e.replace(/^#\s*/,""),items:[]},s.push(a);else if(a&&e.includes(":")){let t=e.indexOf(":");a.items.push({key:e.slice(0,t),value:e.slice(t+1)})}}}return(0,n.jsxs)("div",{className:"p-2 space-y-3 overflow-auto h-full",children:[(0,n.jsx)("div",{className:"flex justify-end",children:(0,n.jsx)("button",{onClick:t,className:"px-2 py-0.5 text-[10px] text-muted-foreground hover:text-foreground bg-muted rounded transition-colors",children:r("common.refresh")})}),s.map(e=>(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground uppercase tracking-wide px-1 mb-1 font-medium",children:e.title}),(0,n.jsx)("div",{className:"space-y-0",children:e.items.map(({key:e,value:t})=>(0,n.jsxs)("div",{className:"flex items-start gap-2 px-1.5 py-0.5 text-xs hover:bg-hover rounded",children:[(0,n.jsx)("span",{className:"text-muted-foreground font-mono flex-shrink-0 w-48 truncate",children:e}),(0,n.jsx)("span",{className:"font-mono text-foreground break-all",children:t})]},e))})]},e.title))]})}function rR({cliInput:e,onInputChange:t,onExecute:r,history:s,loading:a,endRef:l,inputRef:i}){let{t:d}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-1 overflow-auto p-2 font-mono text-xs space-y-2",onClick:()=>i.current?.focus(),children:[0===s.length&&(0,n.jsx)("div",{className:"text-muted-foreground text-center py-4",children:d("redis.cliHint")}),s.map((e,t)=>(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"text-brand",children:[(0,n.jsx)("span",{className:"text-muted-foreground mr-1",children:">"}),e.command,e.duration>0&&(0,n.jsxs)("span",{className:"text-muted-foreground/50 ml-2",children:["(",e.duration,"ms)"]})]}),(0,n.jsx)("pre",{className:`whitespace-pre-wrap break-all mt-0.5 ${e.isError?"text-destructive":"text-foreground"}`,children:e.isError?`(error) ${e.result}`:function e(t,r=0){let n=" ".repeat(r);return null===t?`${n}(nil)`:"number"==typeof t?`${n}(integer) ${t}`:"string"==typeof t?`${n}"${t}"`:Array.isArray(t)?0===t.length?`${n}(empty array)`:t.map((t,r)=>`${n}${r+1}) ${e(t,0)}`).join("\n"):`${n}${String(t)}`}(e.result)})]},t)),(0,n.jsx)("div",{ref:l})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1.5 border-t border-border bg-card/30 flex-shrink-0",children:[(0,n.jsx)("span",{className:"text-xs text-brand font-mono flex-shrink-0",children:">"}),(0,n.jsx)("input",{ref:i,type:"text",value:e,onChange:e=>t(e.target.value),onKeyDown:e=>{"Enter"!==e.key||a||r()},placeholder:d("redis.cliPlaceholder"),className:"flex-1 min-w-0 text-xs font-mono bg-transparent border-0 focus:outline-none",autoComplete:"off",spellCheck:!1,disabled:a}),a&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"})]})]})}t5({type:"redis",idPrefix:"redis",match(e){let t=e.trim().toLowerCase();return t.startsWith("redis://")||t.startsWith("rediss://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t),n=e.pathname.replace(/^\//,"")||"0";r=`db${n}@${e.hostname}${e.port?":"+e.port:":6379"}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(rP,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await t8("redis",e.id)}});let rI=/^([\d.]+)\s+([\d.]+)%\s+([\d.]+)%$/;function rF(e,t,r){if(!e)return r;let n=getComputedStyle(e).getPropertyValue(t).trim();if(!n)return r;let s=rI.exec(n);if(!s)return n;let o=Number(s[1]),a=Number(s[2])/100,l=Number(s[3])/100,i=(1-Math.abs(2*l-1))*a,d=i*(1-Math.abs(o/60%2-1)),c=l-i/2,[u,m,x]=[[i,d,0],[d,i,0],[0,i,d],[0,d,i],[d,0,i],[i,0,d]][Math.floor(o/60)%6],h=e=>Math.round((e+c)*255).toString(16).padStart(2,"0");return`#${h(u)}${h(m)}${h(x)}`}let rB=["#4C8BF5","#E74C3C","#2ECC71","#F39C12","#9B59B6","#1ABC9C","#E67E22","#3498DB","#E91E63","#00BCD4"];function rD(e,t){return rB[t.indexOf(e)%rB.length]}function rA(e){if(!e)return"";let t=new Date(e);return isNaN(t.getTime())?"":`${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function rH({nodes:e,rels:t,allLabels:r}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),l=(0,eC.Ql)()?.resolvedTheme??"dark",i=(0,s.useRef)([]),d=(0,s.useRef)(0),c=(0,s.useRef)(null),u=(0,s.useRef)({w:0,h:0}),m=(0,s.useRef)(new Map),[x,h]=(0,s.useState)(null),f=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=o.current;if(!e)return;let t=new ResizeObserver(e=>{let{width:t,height:r}=e[0].contentRect,n=u.current;if(t===n.w&&r===n.h)return;if(n.w>0&&n.h>0&&i.current.length>0){let e=t/n.w,s=r/n.h;i.current.forEach(t=>{t.x=(t.x||0)*e,t.y=(t.y||0)*s})}u.current={w:t,h:r};let s=a.current;s&&(s.width=t,s.height=r)});return t.observe(e),()=>t.disconnect()},[]),(0,s.useEffect)(()=>{let{w:t,h:r}=u.current,n=t||o.current?.clientWidth||600,s=r||o.current?.clientHeight||400;0===t&&(u.current={w:n,h:s}),i.current=e.map((t,r)=>({...t,x:t.x??n/2+Math.cos(2*r*Math.PI/e.length)*Math.min(n,s)*.3,y:t.y??s/2+Math.sin(2*r*Math.PI/e.length)*Math.min(n,s)*.3,vx:0,vy:0})),m.current=new Map(i.current.map(e=>[e.id,e]))},[e]),(0,s.useEffect)(()=>{let e=m.current,n=a.current,s=rF(n,"--foreground-faint","#666"),o=rF(n,"--foreground-subtle","#999"),l=rF(n,"--accent","#27272a"),x=rF(n,"--foreground","#fff");return d.current=requestAnimationFrame(function n(){let{w:m,h}=u.current;if(0===m||0===h){d.current=requestAnimationFrame(n);return}let p=i.current;p.forEach(e=>{e.vx=(e.vx||0)+(m/2-(e.x||0))*.001,e.vy=(e.vy||0)+(h/2-(e.y||0))*.001});for(let e=0;e<p.length;e++)for(let t=e+1;t<p.length;t++){let r=(p[e].x||0)-(p[t].x||0),n=(p[e].y||0)-(p[t].y||0),s=Math.sqrt(r*r+n*n)||1,o=2e3/(s*s),a=r/s*o,l=n/s*o;p[e].vx+=a,p[t].vx-=a,p[e].vy+=l,p[t].vy-=l}t.forEach(t=>{let r=e.get(t.startId),n=e.get(t.endId);if(!r||!n)return;let s=(n.x||0)-(r.x||0),o=(n.y||0)-(r.y||0),a=Math.sqrt(s*s+o*o)||1,l=(a-100)*.01,i=s/a*l,d=o/a*l;r.vx+=i,n.vx-=i,r.vy+=d,n.vy-=d}),p.forEach(e=>{c.current?.nodeId!==e.id&&(e.vx=.6*(e.vx||0),e.vy=.6*(e.vy||0),e.x=Math.max(20,Math.min(m-20,(e.x||0)+.1*(e.vx||0))),e.y=Math.max(20,Math.min(h-20,(e.y||0)+.1*(e.vy||0))))});let g=a.current?.getContext("2d");g&&(g.clearRect(0,0,m,h),g.lineWidth=1.5,t.forEach(t=>{let r=e.get(t.startId),n=e.get(t.endId);if(!r||!n)return;g.strokeStyle=s,g.beginPath(),g.moveTo(r.x,r.y),g.lineTo(n.x,n.y),g.stroke();let a=Math.atan2(n.y-r.y,n.x-r.x),l=n.x-24*Math.cos(a),i=n.y-24*Math.sin(a);g.fillStyle=s,g.beginPath(),g.moveTo(l,i),g.lineTo(l-8*Math.cos(a-.3),i-8*Math.sin(a-.3)),g.lineTo(l-8*Math.cos(a+.3),i-8*Math.sin(a+.3)),g.closePath(),g.fill(),g.font="9px system-ui",g.fillStyle=o,g.textAlign="center",g.fillText(t.type,(r.x+n.x)/2,(r.y+n.y)/2-4)}),p.forEach(e=>{let t=e.labels[0]||"",n=t?rD(t,r):"#6b7280";g.beginPath(),g.arc(e.x,e.y,20,0,2*Math.PI),g.fillStyle=n,g.fill();let s=f.current?.id===e.id;g.strokeStyle=s?x:l,g.lineWidth=s?2.5:1,g.stroke(),g.font="10px system-ui",g.fillStyle="#fff",g.textAlign="center",g.textBaseline="middle";let o=String(e.properties.name||e.properties.title||e.properties.id||t||e.id);g.fillText(o.length>8?o.slice(0,7)+"…":o,e.x,e.y)}),d.current=requestAnimationFrame(n))}),()=>cancelAnimationFrame(d.current)},[e,t,r,l]);let p=(0,s.useCallback)(e=>{let t=a.current?.getBoundingClientRect();if(!t)return null;let r=e.clientX-t.left,n=e.clientY-t.top;return i.current.find(e=>{let t=(e.x||0)-r,s=(e.y||0)-n;return t*t+s*s<400})||null},[]);return(0,n.jsxs)("div",{ref:o,className:"relative w-full h-full",children:[(0,n.jsx)("canvas",{ref:a,className:"cursor-grab active:cursor-grabbing absolute inset-0",onMouseDown:e=>{let t=p(e);if(t){let r=a.current.getBoundingClientRect();c.current={nodeId:t.id,offsetX:e.clientX-r.left-(t.x||0),offsetY:e.clientY-r.top-(t.y||0)}}},onMouseMove:e=>{if(c.current){let t=a.current.getBoundingClientRect(),r=i.current.find(e=>e.id===c.current.nodeId);r&&(r.x=e.clientX-t.left-c.current.offsetX,r.y=e.clientY-t.top-c.current.offsetY,r.vx=0,r.vy=0)}else{let t=p(e);f.current=t,h(t)}},onMouseUp:()=>{c.current=null},onMouseLeave:()=>{c.current=null,f.current=null,h(null)}}),x&&!c.current&&(0,n.jsxs)("div",{className:"absolute top-2 left-2 bg-popover text-popover-foreground border border-border rounded px-2 py-1 text-xs max-w-[300px] pointer-events-none",children:[(0,n.jsxs)("div",{className:"font-medium",children:[x.labels.join(", ")," #",String(x.id)]}),Object.entries(x.properties).slice(0,8).map(([e,t])=>(0,n.jsxs)("div",{className:"truncate",children:[(0,n.jsxs)("span",{className:"text-muted-foreground",children:[e,":"]})," ",String(t)]},e))]})]})}function rW({id:e,connectionString:t,displayName:r,selected:o,maximized:a,expandedHeight:l,bubbleContentHeight:i,onSelect:d,onClose:c,onToggleMaximize:u,timestamp:m,onTitleMouseDown:x}){let[h,f]=(0,s.useState)("connecting"),[p,g]=(0,s.useState)(""),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)("labels"),[S,M]=(0,s.useState)(""),[L,E]=(0,s.useState)(null),[P,T]=(0,s.useState)(!1),[$,R]=(0,s.useState)(""),I=(0,s.useRef)(null),[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)([]),[H,W]=(0,s.useState)("schema"),z=(0,s.useCallback)(async()=>{f("connecting");try{let r=await rt("/api/neo4j/connect",{id:e,connectionString:t});v(r),f("connected")}catch(e){g(e instanceof Error?e.message:String(e)),f("error")}},[e,t]);(0,s.useEffect)(()=>{z()},[z]);let O=(0,s.useCallback)(async()=>{y(!0);try{let r=await rt("/api/neo4j/schema",{id:e,connectionString:t});w(r)}catch{}y(!1)},[e,t]);(0,s.useEffect)(()=>{"connected"===h&&O()},[h,O]);let _=(0,s.useCallback)(async r=>{let n=r||S.trim();if(n){T(!0),R("");try{var s;let r,o,a=await rt("/api/neo4j/query",{id:e,connectionString:t,cypher:n});E(a);let{nodes:l,rels:i}=(s=a.records,r=new Map,o=[],s.forEach(e=>Object.values(e).forEach(function e(t){if(t&&"object"==typeof t)if("node"===t._type){let e=t._id;r.has(e)||r.set(e,{id:e,labels:t._labels||[],properties:Object.fromEntries(Object.entries(t).filter(([e])=>!e.startsWith("_")))})}else if("relationship"===t._type)o.push({id:t._id,type:t._relType,startId:t._start,endId:t._end,properties:Object.fromEntries(Object.entries(t).filter(([e])=>!e.startsWith("_")))});else if("path"===t._type){let r=t.segments;r?.forEach(t=>{e(t.start),e(t.relationship),e(t.end)})}else Array.isArray(t)&&t.forEach(e)})),{nodes:Array.from(r.values()),rels:o});l.length>0&&(B(l),A(i))}catch(e){R(e instanceof Error?e.message:String(e))}T(!1)}},[e,t,S]),q=(0,s.useCallback)(e=>{let t=`MATCH (n:\`${e}\`) RETURN n LIMIT 25`;M(t),W("cypher"),_(t)},[_]),V=(0,s.useCallback)(e=>{let t=`MATCH (a)-[r:\`${e}\`]->(b) RETURN a, r, b LIMIT 25`;M(t),W("graph"),_(t)},[_]);return(0,n.jsx)("div",{className:"flex flex-col items-start",onClick:d,children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground relative transition-colors ${o?"ring-1 ring-ring":""} rounded-lg overflow-hidden`,children:[(0,n.jsxs)("div",{"data-drag-handle":!0,onDoubleClick:u,onMouseDown:x,className:"flex items-center gap-2 px-4 py-1.5 border-b border-border cursor-grab active:cursor-grabbing select-none",children:[(0,n.jsx)("span",{className:"text-sm flex-shrink-0",children:"⬡"}),(0,n.jsx)("span",{className:"text-xs text-foreground truncate font-mono font-medium",children:r}),"connecting"===h&&(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin flex-shrink-0"}),"connected"===h&&(0,n.jsx)("span",{className:"text-[10px] text-green-11 flex-shrink-0",children:"Connected"}),"error"===h&&(0,n.jsx)("span",{className:"text-[10px] text-destructive flex-shrink-0",children:"Error"}),m&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:rA(m)}),"connected"===h&&b&&(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:["v",b.version," \xb7 ",b.nodeCount.toLocaleString(),"n \xb7 ",b.relationshipCount.toLocaleString(),"r"]}),(0,n.jsx)("span",{className:"flex-1"}),"connected"===h&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),O(),z()},disabled:k,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0 disabled:opacity-40",title:"Refresh",children:(0,n.jsx)("svg",{className:`w-3.5 h-3.5 ${k?"animate-spin":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a?(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 9V4.5M9 9H4.5M9 9L3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5l5.25 5.25"}):(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15"})})}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c()},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{style:{height:a&&l?l-41:i??360},className:"flex flex-col overflow-hidden",children:["connecting"===h&&(0,n.jsxs)("div",{className:"flex-1 flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Connecting..."]}),"error"===h&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center text-xs p-4 gap-2",children:[(0,n.jsx)("p",{className:"text-destructive",children:p}),(0,n.jsx)("button",{onClick:z,className:"px-3 py-1 rounded text-xs bg-brand text-white hover:bg-brand/90 transition-colors",children:"Retry"})]}),"connected"===h&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex items-center gap-0 border-b border-border bg-card/30 flex-shrink-0",children:["schema","cypher","graph"].map(e=>(0,n.jsx)("button",{onClick:()=>W(e),className:`px-3 py-1.5 text-xs transition-colors ${H===e?"text-brand border-b-2 border-brand font-medium":"text-muted-foreground hover:text-foreground"}`,children:{schema:"Schema",cypher:"Cypher",graph:"Graph"}[e]},e))}),(0,n.jsxs)("div",{className:"flex-1 overflow-hidden flex",children:["schema"===H&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-40 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:(0,n.jsx)("div",{className:"flex-1 overflow-y-auto text-xs",children:[{key:"labels",label:"Labels",count:j?.labels.length},{key:"relationships",label:"Relationships",count:j?.relationshipTypes.length},{key:"properties",label:"Properties",count:j?.propertyKeys.length},{key:"indexes",label:"Indexes",count:j?.indexes.length},{key:"constraints",label:"Constraints",count:j?.constraints.length}].map(e=>(0,n.jsxs)("div",{onClick:()=>C(e.key),className:`flex items-center gap-1.5 px-2 py-1.5 cursor-pointer truncate transition-colors ${N===e.key?"bg-brand/10 text-brand":"hover:bg-hover text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate min-w-0 flex-1",children:e.label}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count??0})]},e.key))})}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto text-xs",children:[k&&(0,n.jsxs)("div",{className:"flex items-center justify-center p-4 gap-2 text-muted-foreground",children:[(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"})," Loading..."]}),!k&&"labels"===N&&j?.labels.map(e=>(0,n.jsxs)("div",{onClick:()=>q(e.name),className:"flex items-center gap-1.5 px-2 py-1 cursor-pointer hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:rD(e.name,j.labels.map(e=>e.name))}}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:e.name}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count.toLocaleString()})]},e.name)),!k&&"relationships"===N&&j?.relationshipTypes.map(e=>(0,n.jsxs)("div",{onClick:()=>V(e.name),className:"flex items-center gap-1.5 px-2 py-1 cursor-pointer hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:"→"}),(0,n.jsx)("span",{className:"truncate min-w-0 flex-1 font-mono",children:e.name}),(0,n.jsx)("span",{className:"ml-auto text-[10px] text-muted-foreground flex-shrink-0",children:e.count.toLocaleString()})]},e.name)),!k&&"properties"===N&&j?.propertyKeys.map(e=>(0,n.jsx)("div",{className:"px-2 py-1 font-mono text-muted-foreground hover:bg-brand/10 transition-colors",children:e},e)),!k&&"indexes"===N&&j?.indexes.map(e=>(0,n.jsxs)("div",{className:"px-2 py-1 border-b border-border/50 hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("div",{className:"font-mono text-foreground",children:e.name}),(0,n.jsxs)("div",{className:"text-muted-foreground",children:[e.type," \xb7 ",e.labelsOrTypes?.join(", ")," \xb7 (",e.properties?.join(", "),") \xb7 ",e.state]})]},e.name)),!k&&"constraints"===N&&j?.constraints.map(e=>(0,n.jsxs)("div",{className:"px-2 py-1 border-b border-border/50 hover:bg-brand/10 transition-colors",children:[(0,n.jsx)("div",{className:"font-mono text-foreground",children:e.name}),(0,n.jsxs)("div",{className:"text-muted-foreground",children:[e.type," \xb7 ",e.labelsOrTypes?.join(", ")," \xb7 (",e.properties?.join(", "),")"]})]},e.name))]})]}),"cypher"===H&&(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("textarea",{ref:I,value:S,onChange:e=>M(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),_())},placeholder:`Enter Cypher query (${(0,tG.Mu)()}+Enter to run)`,className:"w-full h-20 px-2 py-1.5 text-xs font-mono bg-background border border-input rounded resize-y focus:outline-none focus:ring-1 focus:ring-ring",spellCheck:!1}),(0,n.jsxs)("div",{className:"flex items-center justify-between mt-1",children:[(0,n.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:[(0,tG.Mu)(),"+Enter to execute"]}),(0,n.jsx)("button",{onClick:()=>_(),disabled:P||!S.trim(),className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 transition-colors",children:P?"Running...":"Execute"})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto",children:[$&&(0,n.jsx)("div",{className:"p-2 text-xs text-destructive",children:$}),L&&!$&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-2 py-1 text-[10px] text-muted-foreground border-b border-border flex items-center gap-2",children:[(0,n.jsxs)("span",{children:[L.records.length," rows"]}),(0,n.jsxs)("span",{children:[L.duration,"ms"]}),Object.entries(L.counters).filter(([,e])=>e>0).map(([e,t])=>(0,n.jsxs)("span",{children:[e,": ",t]},e))]}),L.records.length>0&&(0,n.jsxs)("table",{className:"w-full text-xs border-collapse",children:[(0,n.jsx)("thead",{className:"sticky top-0 bg-card z-[1]",children:(0,n.jsx)("tr",{children:L.keys.map(e=>(0,n.jsx)("th",{className:"px-1.5 py-1 text-left text-muted-foreground font-medium border-b border-border whitespace-nowrap font-mono",children:e},e))})}),(0,n.jsx)("tbody",{children:L.records.map((e,t)=>(0,n.jsx)("tr",{className:"hover:bg-hover",children:L.keys.map(t=>(0,n.jsx)("td",{className:"px-1.5 py-0.5 border-b border-border/50 font-mono whitespace-nowrap max-w-[200px] truncate",children:null===e[t]?(0,n.jsx)("span",{className:"text-muted-foreground italic",children:"NULL"}):function(e){if(null==e)return"null";if("object"==typeof e){if("node"===e._type){let t=e._labels?.[0]||"",r=e.name||e.title||e.id||"";return`(${t}${r?": "+r:""})`}return"relationship"===e._type?`[${e._relType}]`:JSON.stringify(e)}return String(e)}(e[t])},t))},t))})]})]})]})]}),"graph"===H&&(0,n.jsx)("div",{className:"flex-1 relative",children:0===F.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-xs text-muted-foreground gap-2",children:[(0,n.jsx)("p",{children:"Run a Cypher query that returns nodes to visualize"}),(0,n.jsx)("button",{onClick:()=>{let e="MATCH (a)-[r]->(b) RETURN a, r, b LIMIT 50";M(e),_(e)},className:"px-3 py-1 rounded text-xs bg-brand text-white hover:bg-brand/90 transition-colors",children:"Load sample graph"})]}):(0,n.jsx)(rH,{nodes:F,rels:D,allLabels:j?.labels.map(e=>e.name)||[]})})]})]})]}),!a&&(0,n.jsxs)("div",{className:"border-t border-border px-4 py-1.5 flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:`inline-block w-2 h-2 rounded-full ${"connected"===h?"bg-green-500":"error"===h?"bg-red-500":"bg-yellow-500 animate-pulse"}`}),(0,n.jsx)("span",{children:{connecting:"Connecting",connected:"Connected",error:"Error"}[h]}),"connected"===h&&b&&(0,n.jsx)("span",{className:"text-muted-foreground/70",children:b.edition}),(0,n.jsx)("span",{className:"flex-1"}),m&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:rA(m)})]})]})})}t5({type:"neo4j",idPrefix:"neo4j",match(e){let t=e.trim().toLowerCase();return t.startsWith("neo4j://")||t.startsWith("neo4j+s://")||t.startsWith("bolt://")||t.startsWith("bolt+s://")},parse(e){let t=e.trim(),r=t;try{let e=new URL(t);r=`${e.hostname}${e.port?":"+e.port:":7687"}`}catch{}return{connectionString:t,displayName:r}},fromHistory:e=>({connectionString:e.connectionString,displayName:e.displayName||e.connectionString}),toHistory:e=>({connectionString:e.connectionString,displayName:e.displayName}),Component:function({item:e,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c}){return(0,n.jsx)(rW,{id:e.id,connectionString:e.connectionString,displayName:e.displayName,selected:t,maximized:r,expandedHeight:s,bubbleContentHeight:o,timestamp:a,onSelect:l,onClose:i,onToggleMaximize:d,onTitleMouseDown:c})},async onClose(e){await t8("neo4j",e.id)}});var rz=r(71077);let rO=(0,s.memo)(function({item:e,selected:t,maximized:r,initialSleeping:s,tabId:o,projectCwd:a,expandedHeight:l,bubbleContentHeight:i,onDragStart:d,onDragOver:c,onDragEnter:u,onDragLeave:m,onDrop:x,onDragEnd:h,onSelectId:f,onInterruptId:p,onStdin:g,onDeleteCommand:b,onRerun:v,subscribePtyOutput:j,subscribePtyReset:w,subscribePtyRefresh:k,ptySizeRef:y,resizePty:N,onToggleMaximizeId:C,onTitleMouseDown:S,onClosePlugin:M,addBrowserItem:L,onSleep:E,onWake:P}){let T={draggable:!0,onDragStart:t=>d(t,e.data.id),onDragOver:t=>c(t,e.data.id),onDragEnter:u,onDragLeave:m,onDrop:x,onDragEnd:h};if("command"===e.type){let s=e.data;return(0,n.jsx)("div",{"data-bubble-id":s.id,className:"group/cmd rounded-lg transition-shadow",...T,children:(0,n.jsx)(t1,{commandId:s.id,tabId:o,projectCwd:a,command:s.command,output:s.output,exitCode:s.exitCode,isRunning:s.isRunning,selected:t,onSelect:()=>{f(s.id)},onInterrupt:s.isRunning?()=>p(s.id):void 0,onStdin:s.isRunning?e=>g(s.id,e):void 0,onDelete:()=>{s.isRunning&&s.pid&&(0,rz.HV)(s.pid),b(s.id)},onRerun:()=>v(s.id),timestamp:s.timestamp,usePty:s.usePty,subscribePtyOutput:s.usePty?j:void 0,subscribePtyReset:s.usePty?w:void 0,subscribePtyRefresh:s.usePty?k:void 0,onPtyResize:(e,t)=>{y.current.set(s.id,{cols:e,rows:t}),N(s.id,e,t)},onToggleMaximize:()=>C(s.id),maximized:r,expandedHeight:l,bubbleContentHeight:i,onTitleMouseDown:S})})}let $=t4(e.type);if(!$)return null;let R=$.Component,I=e.data;return(0,n.jsx)("div",{"data-bubble-id":I.id,className:"rounded-lg transition-shadow",...T,children:(0,n.jsx)(R,{item:I,selected:t,maximized:r,expandedHeight:l,bubbleContentHeight:i,timestamp:I.timestamp,onSelect:()=>{f(I.id)},onClose:()=>M(I.id),onToggleMaximize:()=>C(I.id),onTitleMouseDown:S,extra:{addBrowserItem:L,initialSleeping:s,onSleep:E,onWake:P,projectCwd:a,tabId:o}})})});var r_=r(68459),rq=r(51914);function rV({cwd:e,tabId:t,onClose:r,onSave:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)({}),[c,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!0),g=(0,s.useCallback)(async()=>{p(!0);let r=await x.t4.runPromiseExit((0,tJ.QF)(e,t));"Success"===r._tag?d(r.value.env):console.error("Failed to load env:",r.cause),p(!1)},[e,t]);(0,s.useEffect)(()=>{g()},[g]);let b=()=>{c.trim()&&(d(e=>({...e,[c.trim()]:m})),u(""),h(""))},v=async()=>{let n=await x.t4.runPromiseExit((0,tJ.Vv)({cwd:e,tabId:t,env:i}));"Success"===n._tag?(a(i),r()):console.error("Failed to save env:",n.cause)};return(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-lv3 w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-lg font-semibold",children:l("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?l("envManager.tabScope"):l("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-hover transition-colors",children:(0,n.jsx)(es.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:f?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:l("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(i).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"flex-1 px-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void d(t=>({...t,[e]:r}))},placeholder:l("envManager.valuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>{d(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors",children:(0,n.jsx)(r_.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsx)("input",{type:"text",value:c,onChange:e=>u(e.target.value),placeholder:l("envManager.varNamePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),b())}}),(0,n.jsx)("input",{type:"text",value:m,onChange:e=>h(e.target.value),placeholder:l("envManager.varValuePlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),b())}}),(0,n.jsx)("button",{onClick:b,disabled:!c.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(rq.A,{className:"w-4 h-4"})})]}),0===Object.keys(i).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:l("envManager.noVars")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:r,className:"px-4 py-2 rounded-lg text-sm hover:bg-hover transition-colors",children:l("common.cancel")}),(0,n.jsx)("button",{onClick:v,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:l("common.save")})]})]})})}var rU=r(10762);function rK({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)({}),[i,d]=(0,s.useState)(""),[c,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(!0),f=(0,s.useCallback)(async()=>{h(!0);let e=await x.t4.runPromiseExit((0,tJ.Jn)());"Success"===e._tag?l(e.value):console.error("Failed to load aliases:",e.cause),h(!1)},[]);(0,s.useEffect)(()=>{f()},[f]);let p=()=>{i.trim()&&c.trim()&&(l(e=>({...e,[i.trim()]:c.trim()})),d(""),u(""))},g=async()=>{let r=await x.t4.runPromiseExit((0,tJ.cv)(a));"Success"===r._tag?(t(a),e()):console.error("Failed to save aliases:",r.cause)};return(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-lv3 w-full max-w-2xl max-h-[80vh] flex flex-col m-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[(0,n.jsx)(rU.A,{className:"w-5 h-5"}),r("aliasManager.title")]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:r("aliasManager.description")})]}),(0,n.jsx)("button",{onClick:e,className:"p-1 rounded hover:bg-hover transition-colors",children:(0,n.jsx)(es.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:m?(0,n.jsx)("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:r("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(a).map(([e,t])=>(0,n.jsxs)("div",{className:"flex items-start gap-2 group",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:e,disabled:!0,className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-muted text-sm font-mono"})]}),(0,n.jsx)("input",{type:"text",value:t,onChange:t=>{var r;return r=t.target.value,void l(t=>({...t,[e]:r}))},placeholder:r("aliasManager.fullCommandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent"})]}),(0,n.jsx)("button",{onClick:()=>{l(t=>{let r={...t};return delete r[e],r})},className:"p-2 rounded-lg text-destructive hover:bg-destructive/10 transition-colors opacity-0 group-hover:opacity-100",children:(0,n.jsx)(r_.A,{className:"w-4 h-4"})})]},e)),(0,n.jsxs)("div",{className:"flex items-start gap-2 pt-2 border-t border-border",children:[(0,n.jsxs)("div",{className:"flex-1 grid grid-cols-2 gap-2",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-sm",children:"$"}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),placeholder:r("aliasManager.aliasPlaceholder"),className:"w-full pl-7 pr-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),p())}})]}),(0,n.jsx)("input",{type:"text",value:c,onChange:e=>u(e.target.value),placeholder:r("aliasManager.commandPlaceholder"),className:"w-full px-3 py-2 rounded-lg border border-input bg-background text-sm font-mono focus:outline-none focus:ring-2 focus:ring-brand focus:border-transparent",onKeyDown:e=>{"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),p())}})]}),(0,n.jsx)("button",{onClick:p,disabled:!i.trim()||!c.trim(),className:"p-2 rounded-lg bg-brand text-brand-foreground hover:bg-brand/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:(0,n.jsx)(rq.A,{className:"w-4 h-4"})})]}),(0,n.jsxs)("div",{className:"mt-4 p-3 bg-accent rounded-lg",children:[(0,n.jsxs)("p",{className:"text-sm text-muted-foreground",children:[(0,n.jsx)("strong",{children:r("aliasManager.usage")}),r("aliasManager.usageDesc")]}),(0,n.jsxs)("div",{className:"mt-2 space-y-1 text-xs text-muted-foreground",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ ll"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"ls -la"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"$ gs"}),(0,n.jsx)("span",{children:"→"}),(0,n.jsx)("code",{className:"px-1.5 py-0.5 bg-background rounded",children:"git status"})]})]})]}),0===Object.keys(a).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:r("aliasManager.noAliases")})]})}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,n.jsx)("button",{onClick:e,className:"px-4 py-2 rounded-lg text-sm hover:bg-hover transition-colors",children:r("common.cancel")}),(0,n.jsx)("button",{onClick:g,className:"px-4 py-2 rounded-lg text-sm bg-brand text-brand-foreground hover:bg-brand/90 transition-colors",children:r("common.save")})]})]})})}var rQ=r(53961),rG=r(15813),rJ=r(37595),rY=r(49698),rX=r(49387),rZ=r(20232);let r0=/^\s*([A-Za-z0-9_-]+)\s*:\s*(.*?)\s*$/;function r1(e){let t=[];for(let[r,n]of e.split(/\r?\n/).entries()){if(!n.trim())continue;let e=n.match(r0);if(!e||!e[2])return{ok:!1,line:r+1};t.push({name:e[1],command:e[2]})}return{ok:!0,commands:t}}let r2="data-quick-command-layer";function r5({title:e,commands:t,onSave:r,onClose:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>t.map(e=>`${e.name}: ${e.command.replace(/\r?\n/g," ")}`).join("\n")),[c,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(!1),f=r1(i);(0,I.E)(a);let p=(0,s.useCallback)(async()=>{let e=r1(i);!e.ok||c||((u(!0),h(!1),await r(e.commands))?a():(u(!1),h(!0)))},[a,r,c,i]);return(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{[r2]:"",className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":e,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:e}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:l("console.quickCommandsTextHint")})]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":l("common.cancel"),children:(0,n.jsx)(es.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,wrap:"off",value:i,onChange:e=>d(e.target.value),placeholder:l("console.quickCommandsTextPlaceholder"),rows:24,spellCheck:!1,className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y overflow-x-auto whitespace-pre px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:f.ok?x?l("console.saveQuickCommandsFailed"):"":l("console.quickCommandsTextError",{line:f.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:l("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!f.ok||c,onClick:p,className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:l(c?"console.savingQuickCommands":"common.save")})]})]})]})})})}function r4({label:e,commands:t,onEdit:r,onExecute:s}){let{t:a}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),(0,n.jsx)("button",{type:"button",onClick:r,className:"p-1 text-muted-foreground hover:text-brand rounded hover:bg-hover transition-colors",title:a("common.edit"),"aria-label":a("common.edit"),children:(0,n.jsx)(rX.A,{className:"w-3.5 h-3.5"})})]}),0===t.length&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:a("console.noCustomCommands")}),t.map((e,t)=>(0,n.jsx)(S.m,{content:e.command,children:(0,n.jsxs)("button",{type:"button",onClick:()=>s(e.command),className:"w-full min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",children:[(0,n.jsx)(rZ.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:e.name})]})},t))]})}function r3({cwd:e,show:t,onClose:r,onExecute:a,onAddPluginItem:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[u,m]=(0,s.useState)([]),[h,f]=(0,s.useState)(null),p=(0,s.useRef)(null),g=(0,s.useCallback)(async()=>{let[t,r]=await Promise.all([x.t4.runPromiseExit((0,tJ.Yj)()),x.t4.runPromiseExit((0,tJ.UV)(e))]);"Success"===t._tag&&c(t.value.customCommands||[]),"Success"===r._tag&&m(r.value.customCommands||[])},[e]);(0,s.useEffect)(()=>{t?queueMicrotask(()=>g()):f(null)},[t,g]),(0,s.useEffect)(()=>{if(!t)return;let e=e=>{e.target instanceof Element&&e.target.closest(`[${r2}]`)||p.current&&!p.current.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]);let b=(0,s.useCallback)(async(t,r)=>{let n=await x.t4.runPromiseExit((0,tJ.Cb)("global"===t?{scope:"global",customCommands:r}:{cwd:e,customCommands:r}));return"Failure"===n._tag?(console.error(`Failed to save ${t} commands:`,n.cause),!1):(("global"===t?c:m)(n.value?.customCommands??r),!0)},[e]),v=(0,s.useCallback)(async e=>!!h&&b(h,e),[h,b]),j=(0,s.useCallback)(e=>{r();let t=t3(e);t?l?.(t.type,e.trim()):a(e)},[r,a,l]);return t?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:p,className:"absolute bottom-full left-0 mb-2 w-72 bg-popover border border-border rounded-lg shadow-lv2 z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(r4,{label:i("console.globalCommands"),commands:d,onEdit:()=>f("global"),onExecute:j}),(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(r4,{label:i("console.projectCommands"),commands:u,onEdit:()=>f("project"),onExecute:j})]}),h&&(0,n.jsx)(r5,{title:i("global"===h?"console.editGlobalCommands":"console.editProjectCommands"),commands:"global"===h?d:u,onSave:v,onClose:()=>f(null)})]}):null}var r6=r(63040);function r8({cwd:e,currentCwd:t,commandHistoryRef:r,gridLayout:a,onGridLayoutChange:l,onExecute:i,onAddPluginItem:d,onShowEnvManager:c,onOpenShell:u,onOpenNote:m}){let{t:h}=(0,o.Bd)(),[f,p]=(0,s.useState)(""),[g,b]=(0,s.useState)(-1),[v,j]=(0,s.useState)(""),[w,k]=(0,s.useState)([]),[y,N]=(0,s.useState)(0),[C,S]=(0,s.useState)(!1),[M,L]=(0,s.useState)(!1),[E,P]=(0,s.useState)([]),[T,$]=(0,s.useState)([]),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)(0),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)(!1),{projectCommands:W,globalCommands:z,expandCustomCommand:O,loadQuickCommands:_}=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)([]),a=(0,s.useCallback)(async()=>{let[t,n]=await Promise.all([x.t4.runPromiseExit((0,tJ.UV)(e)),x.t4.runPromiseExit((0,tJ.Yj)())]);"Success"===t._tag&&r(t.value.customCommands||[]),"Success"===n._tag&&o(n.value.customCommands||[])},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>a())},[a]);let l=[...t,...n],i=(0,s.useCallback)(e=>{let r=e.trim().split(/\s+/),s=r[0];if(!s.startsWith("/")||s.length<=1)return null;let o=s.slice(1),a=t.find(e=>e.name===o)??n.find(e=>e.name===o);return a?a.command+(r.length>1?" "+r.slice(1).join(" "):""):null},[t,n]);return{quickCustomCommands:l,projectCommands:t,globalCommands:n,expandCustomCommand:i,loadQuickCommands:a}}(e);(0,s.useEffect)(()=>{D.current?.focus()},[]),(0,s.useEffect)(()=>{let e=!1,t=()=>{x.t4.runPromiseExit((0,r6.mi)()).then(t=>{e||"Success"!==t._tag||P(t.value.filter(e=>!1!==e.valid&&e.name&&e.path).map(e=>({name:e.name,path:e.path})))})};t();let r=null;return"u">typeof BroadcastChannel&&(r=new BroadcastChannel("cockpit-html-apps")).addEventListener("message",e=>{e.data?.type==="changed"&&t()}),()=>{e=!0,r?.close()}},[]),(0,s.useEffect)(()=>{if(f.startsWith("/")){let e=f.slice(1).toLowerCase(),t=E.filter(t=>t.name.toLowerCase().startsWith(e)).map(e=>({kind:"html",name:e.name,path:e.path})),r=t=>"string"==typeof t?.name&&t.name.toLowerCase().startsWith(e),n=[...t,...[...W.filter(r).map(e=>({...e,scope:"project"})),...z.filter(r).map(e=>({...e,scope:"global"}))].map(e=>({kind:"cmd",cmd:e}))];queueMicrotask(()=>{$(n),I(n.length>0),B(0)})}else queueMicrotask(()=>I(!1))},[f,W,z,E]),(0,s.useEffect)(()=>{if(R&&A.current){let e=A.current.children[F];e?.scrollIntoView({block:"nearest"})}},[F,R]);let q=(0,s.useCallback)(e=>{if(I(!1),"html"===e.kind){d?.("browser",e.path),p("");return}let t=e.cmd.command,r=t3(t);r?d?.(r.type,t.trim()):i(t),p("")},[i,d]),V=(0,s.useCallback)(e=>{if(e.preventDefault(),H.current||!f.trim())return;if(f.startsWith("/")){let e=f.slice(1).trim(),t=E.find(t=>t.name===e);if(t){d?.("browser",t.path),p(""),b(-1),j(""),I(!1);return}}let t=O(f)??f,r=t3(t);r?d?.(r.type,t.trim()):i(t),p(""),b(-1),j("")},[f,i,d,O,E]),U=(0,s.useCallback)(async()=>{if(!D.current)return;let e=D.current.selectionStart||0,r=await x.t4.runPromiseExit((0,tJ.tp)({cwd:t,input:f,cursorPosition:e}));if("Success"===r._tag){let t=r.value,n=t.suggestions;if(n&&n.length>0&&(k(n),N(0),S(!0),1===n.length)){let r=f.substring(0,t.replaceStart??0),s=f.substring(t.replaceEnd??e);p(r+n[0]+s),S(!1),setTimeout(()=>{if(D.current){let e=(t.replaceStart??0)+n[0].length;D.current.setSelectionRange(e,e)}},0)}}else console.error("Autocomplete error:",r.cause)},[t,f]),K=(0,s.useCallback)(e=>{if(!D.current)return;let t=D.current.selectionStart||0,r=f.substring(0,t),n=f.substring(t),s=r.split(/\s+/),o=t-(s[s.length-1]||"").length;p(f.substring(0,o)+e+n),S(!1),setTimeout(()=>{if(D.current){let t=o+e.length;D.current.setSelectionRange(t,t)}},0)},[f]),Q=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing)return;if(R&&T.length>0){if("ArrowUp"===e.key){e.preventDefault(),B(e=>(e-1+T.length)%T.length);return}if("ArrowDown"===e.key){e.preventDefault(),B(e=>(e+1)%T.length);return}if("Tab"===e.key||"Enter"===e.key){e.preventDefault(),q(T[F]);return}if("Escape"===e.key){e.preventDefault(),I(!1);return}}if("Tab"===e.key){if(e.preventDefault(),C&&w.length>0){let e=(y+1)%w.length;N(e),K(w[e])}else U();return}if("Escape"===e.key&&C){e.preventDefault(),S(!1);return}let t=r.current;if(t&&0!==t.length){if("ArrowUp"===e.key){e.preventDefault(),-1===g&&j(f);let r=-1===g?t.length-1:Math.max(0,g-1);b(r),p(t[r])}else if("ArrowDown"===e.key){if(e.preventDefault(),-1===g)return;let r=g+1;r>=t.length?(b(-1),p(v)):(b(r),p(t[r]))}}},[g,f,v,C,w,y,U,K,R,T,F,q,r]);return(0,n.jsx)("div",{className:"border-t border-border p-4",children:(0,n.jsxs)("form",{onSubmit:V,className:"relative flex gap-2 items-center",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{M||_(),L(!M)},className:`p-2 rounded-lg transition-all ${M?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:h("console.quickCommands"),children:(0,n.jsx)(rQ.A,{className:"w-4 h-4"})}),(0,n.jsx)(r3,{cwd:e,show:M,onClose:()=>L(!1),onExecute:i,onAddPluginItem:d})]}),m&&(0,n.jsx)("button",{type:"button",onClick:m,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:h("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsx)("button",{type:"button",onClick:()=>l(!a),className:`p-2 rounded-lg transition-all ${a?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:a?h("console.singleColumn"):h("console.dualColumn"),children:a?(0,n.jsx)(rG.A,{className:"w-4 h-4"}):(0,n.jsx)(rJ.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{type:"button",onClick:c,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:h("console.envVars"),children:(0,n.jsx)(rY.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{type:"button",onClick:u,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:h("console.launchShell"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}),(0,n.jsx)("input",{ref:D,type:"text",value:f,onChange:e=>{p(e.target.value),-1!==g&&(b(-1),j("")),S(!1)},onKeyDown:Q,onCompositionStart:()=>{H.current=!0},onCompositionEnd:()=>{H.current=!1},placeholder:h("console.inputPlaceholder"),className:"flex-1 px-3 py-2 rounded-lg border border-input bg-background text-sm focus:outline-none focus:ring-2 focus:ring-ring font-mono"}),R&&T.length>0&&(0,n.jsx)("div",{ref:A,className:"absolute bottom-full left-0 right-0 mb-1 max-h-64 overflow-y-auto bg-popover border border-border rounded-lg shadow-lv2 z-50",children:T.map((e,t)=>(0,n.jsx)("div",{onClick:()=>q(e),className:`flex items-center gap-3 px-3 py-1.5 cursor-pointer text-sm ${t===F?"bg-brand/10":"hover:bg-hover"}`,children:"html"===e.kind?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"font-mono font-medium text-foreground",children:["/",e.name]}),(0,n.jsx)("span",{className:"flex-1 text-muted-foreground truncate",children:e.path}),(0,n.jsx)("span",{className:"text-[10px] text-brand/70 flex-shrink-0",children:"HTML"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"font-mono font-medium text-foreground",children:["/",e.cmd.name]}),(0,n.jsx)("span",{className:"flex-1 text-muted-foreground truncate",children:e.cmd.command}),(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground/60 flex-shrink-0",children:"project"===e.cmd.scope?h("console.scopeProject"):h("console.scopeGlobal")})]})},"html"===e.kind?`html-${e.name}`:`cmd-${e.cmd.scope}-${e.cmd.name}`))}),C&&w.length>1&&(0,n.jsxs)("div",{className:"absolute bottom-full left-0 mb-1 bg-popover border border-border rounded-lg shadow-lv2 max-h-48 overflow-y-auto z-50",children:[(0,n.jsx)("div",{className:"py-1",children:w.map((e,t)=>(0,n.jsx)("button",{type:"button",onClick:()=>K(e),className:`w-full px-3 py-1.5 text-left text-sm font-mono hover:bg-hover transition-colors ${t===y?"bg-accent":""}`,children:e},t))}),(0,n.jsx)("div",{className:"border-t border-border px-3 py-1 text-xs text-muted-foreground",children:h("console.tabSwitchEscClose")})]})]})})}function r9({showTop:e,showBottom:t,onScrollTop:r,onScrollBottom:s}){let{t:a}=(0,o.Bd)();return(0,n.jsxs)(n.Fragment,{children:[e&&(0,n.jsx)("button",{onClick:r,className:"absolute top-2 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-lv2 rounded-full transition-all hover:shadow-lv2 active:scale-95 z-10",title:a("chat.jumpToStart"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"})})}),t&&(0,n.jsx)("button",{onClick:s,className:"absolute bottom-20 left-1/2 -translate-x-1/2 p-2 bg-card text-muted-foreground hover:text-foreground shadow-lv2 rounded-full transition-all hover:shadow-lv2 active:scale-95 z-10",title:a("chat.jumpToLatest"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})})]})}var r7=r(50605);function ne(){return`cmd-${Date.now()}-${Math.random().toString(36).substring(2,9)}`}let nt="__cockpit_open_preferred_shell__",nr="shell",nn=new Set([nt,"zsh","bash","sh","fish","nu","python","python3","node","irb","lua","vim","nvim","vi","nano","emacs","top","htop","less","man"]),ns=[{key:"command",label:"console.bubbleCommand",triggers:["ls","git status","npm run dev"]},{key:"pty",label:"console.bubbleInteractive",triggers:["zsh","bash","vim","python"]},{key:"browser",label:"console.bubbleBrowser",triggers:["https://…","*.html"],notes:["console.bubbleBrowserNoteIframe","console.bubbleBrowserNoteCookie"]},{key:"database",label:"console.bubbleDatabase",triggers:["postgresql://","mysql://","redis://","neo4j://"]},{key:"filePreview",label:"console.bubbleFilePreview",triggers:[...Q.GV]}],no=(0,s.memo)(function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a,onOpenNote:l,focusBubble:i,isActive:d=!0}){let{t:c}=(0,o.Bd)(),{consoleItems:u,scrollRef:m,selectedCommandId:h,setSelectedCommandId:f,interruptCommand:p,sendStdin:g,deleteCommand:b,rerunCommand:v,ptySizeRef:j,resizePty:w,executeCommand:k,addPluginItem:y,closePluginItem:N,sleepingBubbles:C,handleBubbleSleep:S,handleBubbleWake:L,scrollToBottom:E,currentCwd:P,commandHistoryRef:T,setCustomEnv:$,setAliases:R,saveBubbleOrder:I,hasMoreHistory:F,loadHistory:B,currentPage:D,isLoadingHistory:A,subscribePtyOutput:H,subscribePtyReset:W,subscribePtyRefresh:z}=function({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:n}){let[o,a]=(0,s.useState)([]),[l,i]=(0,s.useState)([]),[d,c]=(0,s.useState)(new Set),[u,m]=(0,s.useState)(t||e),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(0),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)({}),N=(0,s.useRef)(""),[C,S]=(0,s.useState)({}),[M,L]=(0,s.useState)(null),E=(0,s.useRef)(null),P=(0,s.useRef)(new Map),T=(0,s.useRef)(new Map),$=(0,s.useRef)(new Set),R=(0,s.useRef)([]),I=(0,s.useRef)(new Map),F=(0,s.useRef)(new Map),B=(0,s.useRef)(new Map),D=(0,s.useRef)(null),A=(0,s.useRef)(null),H=(0,s.useRef)([]),W=(0,s.useRef)("");W.current||(W.current="u">typeof crypto&&crypto.randomUUID?crypto.randomUUID():`s_${Date.now()}_${Math.random().toString(36).slice(2)}`);let z=(0,s.useRef)(null);(0,s.useEffect)(()=>{n?.(e)},[]);let O=(0,s.useCallback)(()=>{if(P.current.size>0){let e=new Map(P.current);P.current.clear(),a(t=>t.map(t=>{let r=e.get(t.id);return void 0!==r?{...t,output:r}:t}))}E.current=null},[]),_=(0,s.useCallback)((e,t)=>{if($.current.has(e)){let r=F.current.get(e);if(r&&r.size>0)for(let e of r)e(t);else B.current.has(e)||B.current.set(e,[]),B.current.get(e).push(t);return}let r=(T.current.get(e)||"")+t;if(r.length>2097152){let t=function(e){let t=e.slice(-2097152),r=0;if(t.length>0){let e=t.charCodeAt(0);e>=56320&&e<=57343&&(r=1)}let n=Math.min(t.length,64);for(let e=r;e<n;e++){let n=t.charCodeAt(e);if(27===n){r=e;break}if((!(n>=48)||!(n<=63))&&59!==n&&63!==n&&32!==n){n>=64&&n<=126&&(r=e+1);break}}return r>0?t.slice(r):t}(r);T.current.set(e,t),P.current.set(e,t)}else T.current.set(e,r),P.current.set(e,r);null===E.current&&(E.current=requestAnimationFrame(O))},[O]),q=(0,s.useCallback)((e,t=!1)=>{T.current.delete(e),$.current.delete(e),P.current.delete(e),B.current.delete(e),t||(F.current.delete(e),U.current.delete(e))},[]),V=(0,s.useCallback)((e,t)=>{F.current.has(e)||F.current.set(e,new Set),F.current.get(e).add(t);let r=B.current.get(e);if(r&&r.length>0){for(let e of r)t(e);B.current.delete(e)}return()=>{F.current.get(e)?.delete(t)}},[]),U=(0,s.useRef)(new Map),K=(0,s.useCallback)((e,t)=>(U.current.has(e)||U.current.set(e,new Set),U.current.get(e).add(t),()=>{U.current.get(e)?.delete(t)}),[]),Q=(0,s.useRef)(new Map),G=(0,s.useCallback)((e,t)=>(Q.current.has(e)||Q.current.set(e,new Set),Q.current.get(e).add(t),()=>{Q.current.get(e)?.delete(t)}),[]);(0,s.useEffect)(()=>{if(!M)return;let e=requestAnimationFrame(()=>{for(let e of Q.current.values())for(let t of e)t()});return()=>cancelAnimationFrame(e)},[M]);let J=(0,s.useCallback)(e=>(null!==E.current&&(cancelAnimationFrame(E.current),E.current=null),O(),T.current.get(e)||""),[O]),Y=(0,s.useCallback)(()=>{z.current&&(z.current.scrollTop=z.current.scrollHeight)},[]),X=(0,s.useCallback)(async(t=0)=>{if(r){f(!0);try{let n=await x.t4.runPromise((0,tJ.uc)(e,r,t,100)).catch(e=>(console.error("Failed to load history:",e),null));if(n){let e=[],r=[],s=new Set;for(let t of n.entries){let n=t4(t.type);if(n){let e=n.fromHistory(t);r.push({id:t.id,_type:t.type,timestamp:t.timestamp,...e}),t.sleeping&&s.add(t.id)}else{if(t.running)continue;let r=t.id.includes("-")&&3===t.id.split("-").length?t.id:ne();e.push({id:r,command:t.command,output:t.output,exitCode:t.exitCode,isRunning:!1,timestamp:t.timestamp,cwd:t.cwd,usePty:t.usePty})}}0===t?(a(e),i(r),s.size>0&&c(s)):(a(t=>{let r=new Set(t.map(e=>e.id)),n=e.filter(e=>!r.has(e.id));return[...t,...n]}),i(e=>{let t=new Set(e.map(e=>e.id)),n=r.filter(e=>!t.has(e.id));return[...e,...n]})),g(n.hasMore),v(t)}}catch(e){console.error("Failed to load history:",e)}finally{f(!1)}}},[e,r]),Z=(0,s.useCallback)(async t=>{r&&await x.t4.runPromise((0,tJ.AJ)(e,r,{id:t.id,command:t.command,output:t.output,exitCode:t.exitCode,timestamp:t.timestamp,cwd:u},W.current).pipe(eh.sFT(e=>eh.OH5(()=>console.error("Failed to save cd history:",e))),eh.NWQ(()=>eh.rIH)))},[e,r,u]),ee=(0,s.useCallback)(async t=>{try{let n=await (0,rz.If)(e);if(t.current)return;for(let s of n){if(r&&s.tabId!==r)continue;if(t.current)break;let n=s.commandId;a(e=>e.find(e=>e.id===n)?e.map(e=>e.id===n?{...e,isRunning:!0,exitCode:void 0,pid:s.pid,...s.usePty?{usePty:!0}:{}}:e):[...e,{id:n,command:s.command,output:"",isRunning:!0,pid:s.pid,timestamp:s.timestamp,cwd:s.cwd,...s.usePty?{usePty:!0}:{}}]),T.current.set(n,""),s.usePty&&$.current.add(n),await (0,rz.TN)({commandId:n,projectCwd:e,onData:(e,t)=>{if("pid"===e)"string"==typeof t.command&&a(e=>e.map(e=>e.id===n?{...e,command:t.command}:e));else if("stdout"===e||"stderr"===e)_(n,t.data);else if("exit"===e){let e=J(n);q(n),a(r=>r.map(r=>r.id===n?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:()=>{a(e=>e.map(e=>e.id===n&&e.isRunning?{...e,isRunning:!1}:e))}})}}catch{}},[e,r,_,J,q]),er=(0,s.useCallback)((t,r)=>{T.current.set(t,""),r&&$.current.add(t),(0,rz.TN)({commandId:t,projectCwd:e,onData:(e,r)=>{if("pid"===e)a(e=>e.map(e=>e.id===t?{...e,pid:r.pid,..."string"==typeof r.command?{command:r.command}:{}}:e));else if("stdout"===e||"stderr"===e)_(t,r.data);else if("exit"===e){let e=J(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:()=>{a(e=>e.map(e=>e.id===t&&e.isRunning?{...e,isRunning:!1}:e))}}).catch(()=>{})},[e,_,J,q]),en=(0,s.useCallback)(e=>{let t=e?.id;if(!e||!t||H.current.some(e=>e.data.id===t))return;let r=e.type,n=r?t4(r):void 0;if(n)i(s=>s.some(e=>e.id===t)?s:[...s,{id:t,_type:r,timestamp:e.timestamp??new Date().toISOString(),...n.fromHistory(e)}]),e.sleeping&&c(e=>new Set(e).add(t));else{let r=!!e.running;a(n=>n.some(e=>e.id===t)?n:[...n,{id:t,command:e.command??"",output:e.output??"",exitCode:e.exitCode,isRunning:r,timestamp:e.timestamp??new Date().toISOString(),cwd:e.cwd,usePty:e.usePty}]),r&&er(t,!!e.usePty)}L(e=>e&&!e.includes(t)?[...e,t]:e)},[er]),es=(0,s.useCallback)(e=>{if("add"===e.op)e.entry&&en(e.entry);else if("rerun"===e.op){let t=e.entry,r=t?.id;if(!t||!r)return;if(!H.current.some(e=>e.data.id===r))return void en(t);let n=!!t.usePty;if(n){let e=U.current.get(r);if(e)for(let t of e)t()}q(r,n),a(e=>e.map(e=>e.id===r?{...e,output:"",exitCode:void 0,isRunning:!0,pid:void 0}:e)),er(r,n)}else if("update"===e.op){let t=e.id,r=e.fields;if(!t||!r)return;void 0!==r.sleeping&&c(e=>{let n=new Set(e);return r.sleeping?n.add(t):n.delete(t),n}),(void 0!==r.exitCode||void 0!==r.running)&&a(e=>e.map(e=>e.id===t?{...e,...void 0!==r.exitCode?{exitCode:r.exitCode}:{},...void 0!==r.running?{isRunning:r.running}:{}}:e))}else if("delete"===e.op){let t=e.id;if(!t)return;a(e=>e.filter(e=>e.id!==t)),i(e=>e.filter(e=>e.id!==t)),L(e=>e?e.filter(e=>e!==t):e),c(e=>{if(!e.has(t))return e;let r=new Set(e);return r.delete(t),r}),q(t)}else"clear"===e.op?(a([]),i([]),L([]),c(new Set)):"reorder"===e.op&&Array.isArray(e.order)&&L(e.order)},[en,er,q]);(0,et.h)({url:"/ws/global-state",enabled:!!e&&!!r,onMessage:t=>{"console-delta"!==t.type||t.cwd!==e||t.tabId!==r||t.sourceId&&t.sourceId===W.current||es(t)}});let eo=(0,s.useCallback)(async t=>{let s,o=t.trim().split(/\s+/),l=o[0],i=t;if(C[l]&&(i=C[l]+(o.length>1?" "+o.slice(1).join(" "):"")),tH(i)&&!/\s/.test(i.trim()))return void tW(i,e);let d=t3(i);if(d)return void A.current?.(d.type,i.trim());let c=ne(),x=new Date().toISOString(),h=(s=i.trim().split(/\s+/)[0],nn.has(s)),f={id:c,command:i===nt?nr:t,output:i!==t&&i!==nt?`→ ${i}
28
+ `:"",isRunning:!0,timestamp:x,cwd:u,...h?{usePty:!0}:{}};if(a(e=>e.some(e=>e.id===c)?e:[...e,f]),w(c),T.current.set(c,f.output),h&&$.current.add(c),setTimeout(Y,100),i.trim().startsWith("cd ")){let e=i.trim().substring(3).trim(),t=u;(0,r7.P)(e)?t=N.current?(0,r7.D)(e,N.current):u:e.startsWith("/")?t=e:".."===e?t=u.split("/").slice(0,-1).join("/")||"/":"."!==e&&(t=`${u}/${e}`.replace(/\/+/g,"/")),m(t),n?.(t),a(e=>e.map(e=>{if(e.id===c){let r={...e,output:`Changed directory to: ${t}`,exitCode:0,isRunning:!1};return Z(r),r}return e}));return}try{await (0,rz.RS)({cwd:u,command:i,commandId:c,tabId:r||"",projectCwd:e,env:k,usePty:h,sourceId:W.current,onData:(e,t)=>{if("pid"===e)a(e=>e.map(e=>e.id===c?{...e,pid:t.pid,..."string"==typeof t.command?{command:t.command}:{}}:e));else if("stdout"===e||"stderr"===e)_(c,t.data);else if("exit"===e){let e=J(c);q(c),a(r=>r.map(r=>r.id===c?{...r,output:e,exitCode:t.code,isRunning:!1,pid:void 0}:r))}},onError:e=>{let t=J(c);q(c),a(r=>r.map(r=>r.id===c?{...r,output:t+`
29
+ Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:r))}})}catch(t){let e=J(c);q(c),a(r=>r.map(r=>r.id===c?{...r,output:e+`
30
+ Error: ${t.message}`,exitCode:1,isRunning:!1,pid:void 0}:r))}},[C,u,k,r,e,_,J,q,Y,n,Z]),ea=(0,s.useCallback)(e=>{let t=o.find(t=>t.id===e);t?.isRunning&&t.pid&&(0,rz.HV)(t.pid)},[o]),el=(0,s.useCallback)(async t=>{let n=o.find(e=>e.id===t);if(!n)return;n.isRunning&&n.pid&&((0,rz.HV)(n.pid),await new Promise(e=>setTimeout(e,200)));let s=n.command.trim().split(/\s+/),l=s[0],i=n.usePty&&n.command===nr,d=i?nt:n.command;!i&&C[l]&&(d=C[l]+(s.length>1?" "+s.slice(1).join(" "):""));let c=n.usePty||!1;if(c){let e=U.current.get(t);if(e)for(let t of e)t()}q(t,c);let m=d!==n.command?`→ ${d}
31
+ `:"";c||T.current.set(t,m),c&&$.current.add(t),a(e=>e.map(e=>e.id===t?{...e,output:c?"":m,exitCode:void 0,isRunning:!0,pid:void 0}:e));let x=I.current.get(t);try{await (0,rz.RS)({cwd:n.cwd||u,command:d,commandId:t,tabId:r||"",projectCwd:e,env:k,usePty:c,sourceId:W.current,...c&&x?{cols:x.cols,rows:x.rows}:{},onData:(e,r)=>{if("pid"===e)a(e=>e.map(e=>e.id===t?{...e,pid:r.pid,..."string"==typeof r.command?{command:r.command}:{}}:e));else if("stdout"===e||"stderr"===e)_(t,r.data);else if("exit"===e){let e=J(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e,exitCode:r.code,isRunning:!1,pid:void 0}:n))}},onError:e=>{let r=J(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:r+`
32
+ Error: ${e}`,exitCode:1,isRunning:!1,pid:void 0}:n))}})}catch(r){let e=J(t);q(t),a(n=>n.map(n=>n.id===t?{...n,output:e+`
33
+ Error: ${r.message}`,exitCode:1,isRunning:!1,pid:void 0}:n))}},[o,C,u,k,r,e,_,J,q]),ei=(0,s.useCallback)(async t=>{a(e=>e.filter(e=>e.id!==t)),q(t),r&&await x.t4.runPromise((0,tJ.SN)(e,r,t,W.current).pipe(eh.sFT(e=>eh.OH5(()=>console.error("Failed to delete command:",e))),eh.NWQ(()=>eh.rIH)))},[e,r,q]),ed=(0,s.useCallback)((t,n,s)=>{var o;let a=t4(t);if(!a)return;let l=a.parse(n);"cwd"in l&&!l.cwd&&(l.cwd=u);let d={id:(o=a.idPrefix,`${o}-${Date.now()}-${Math.random().toString(36).slice(2,8)}`),_type:t,timestamp:new Date().toISOString(),...l};if(i(e=>[...e,d]),w(d.id),setTimeout(Y,100),s){let t=M&&M.length>0?[...M]:H.current.map(e=>e.data.id),n=t.indexOf(s);-1!==n?t.splice(n+1,0,d.id):t.push(d.id),L(t),r&&x.t4.runFork((0,tJ.cm)(e,r,t,W.current).pipe(eh.NWQ(()=>eh.rIH)))}if(r){let n=a.toHistory(d);x.t4.runFork((0,tJ.AJ)(e,r,{type:t,id:d.id,timestamp:d.timestamp,...n},W.current).pipe(eh.sFT(e=>eh.OH5(()=>console.error(`Failed to save ${t} item:`,e))),eh.NWQ(()=>eh.rIH)))}},[Y,e,r,M]),ec=(0,s.useCallback)(async t=>{let n=l.find(e=>e.id===t);if(i(e=>e.filter(e=>e.id!==t)),w(e=>e===t?null:e),c(e=>{let r=new Set(e);return r.delete(t),r}),n){let e=t4(n._type);e?.onClose?.(n)}r&&x.t4.runFork((0,tJ.SN)(e,r,t,W.current).pipe(eh.sFT(e=>eh.OH5(()=>console.error("Failed to delete plugin item:",e))),eh.NWQ(()=>eh.rIH)))},[l,e,r]);A.current=ed,D.current=eo;let eu=(0,s.useCallback)((t,n)=>{r&&x.t4.runFork((0,tJ.bv)(e,r,t,{sleeping:n},W.current).pipe(eh.NWQ(()=>eh.rIH)))},[e,r]),em=(0,s.useCallback)(e=>{c(t=>new Set(t).add(e)),eu(e,!0)},[eu]),ex=(0,s.useCallback)(e=>{c(t=>{let r=new Set(t);return r.delete(e),r}),eu(e,!1)},[eu]),ef=(0,s.useCallback)(async t=>{L(t),r&&await x.t4.runPromise((0,tJ.cm)(e,r,t,W.current).pipe(eh.NWQ(()=>eh.rIH)))},[e,r]),ep=(0,s.useMemo)(()=>{let e=[...o.map(e=>({type:"command",data:e})),...l.map(e=>({type:e._type,data:e}))];if(!M||0===M.length)return e.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime());let t=new Map(M.map((e,t)=>[e,t])),r=[],n=[];for(let s of e)t.has(s.data.id)?r.push(s):n.push(s);return r.sort((e,r)=>t.get(e.data.id)-t.get(r.data.id)),n.sort((e,t)=>new Date(e.data.timestamp).getTime()-new Date(t.data.timestamp).getTime()),[...r,...n]},[o,l,M]);H.current=ep,(0,s.useEffect)(()=>{R.current=o.filter(e=>!e.isRunning&&e.command.trim()).map(e=>e.command)},[o]);let eg=async()=>{let t=await x.t4.runPromise((0,tJ.QF)(e,r).pipe(eh.sFT(e=>eh.OH5(()=>console.error("Failed to load env:",e))),eh.DM4(()=>({env:{},home:""}))));y(t.env),N.current=t.home},eb=async()=>{S(await x.t4.runPromise((0,tJ.Jn)().pipe(eh.sFT(e=>eh.OH5(()=>console.error("Failed to load aliases:",e))),eh.DM4(()=>({})))))},ev=async()=>{if(!r)return;let t=await x.t4.runPromise((0,tJ.DN)(e,r).pipe(eh.DM4(()=>[])));t.length>0&&L(t)};return(0,s.useEffect)(()=>{let e={current:!1};return(async()=>{await X(0),e.current||await ee(e)})(),eg(),eb(),ev(),()=>{e.current=!0}},[X,ee]),(0,s.useEffect)(()=>()=>{null!==E.current&&cancelAnimationFrame(E.current)},[]),(0,s.useEffect)(()=>()=>{(0,rz.AS)()},[]),{commands:o,pluginItems:l,sleepingBubbles:d,consoleItems:ep,currentCwd:u,selectedCommandId:j,setSelectedCommandId:w,customEnv:k,setCustomEnv:y,aliases:C,setAliases:S,isLoadingHistory:h,hasMoreHistory:p,currentPage:b,scrollRef:z,commandHistoryRef:R,ptySizeRef:I,executeCommandRef:D,executeCommand:eo,interruptCommand:ea,rerunCommand:el,deleteCommand:ei,addPluginItem:ed,closePluginItem:ec,handleBubbleSleep:em,handleBubbleWake:ex,loadHistory:X,scrollToBottom:Y,saveBubbleOrder:ef,sendStdin:rz.tr,resizePty:rz.mO,subscribePtyOutput:V,subscribePtyReset:K,subscribePtyRefresh:G}}({cwd:e,initialShellCwd:t,tabId:r,onCwdChange:a}),[O,_]=(0,s.useState)(null),[q,V]=(0,s.useState)(0),[U,K]=(0,s.useState)(0),[Q,G]=(0,s.useState)(!0),[J,Y]=(0,s.useState)(!1),[X,Z]=(0,s.useState)(!1),[ee,er]=(0,s.useState)(!1),[en,es]=(0,s.useState)(!1),eo=(0,s.useRef)(null),ea=(0,s.useRef)(null),el=(0,s.useRef)(null),ei=(0,s.useRef)(!1),ed=(0,s.useRef)(null),ec=(0,s.useRef)(null),eu=(0,s.useRef)([]);(0,s.useEffect)(()=>{eu.current=u},[u]);let em=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollHeight-e.scrollTop-e.clientHeight<50},[m]),ex=(0,s.useCallback)(()=>{let e=m.current;return!e||e.scrollTop<50},[m]),ef=(0,s.useCallback)(()=>{er(!ex()),es(!em())},[em,ex]),ep=(0,s.useCallback)(()=>{ea.current?.scrollIntoView({behavior:"smooth"})},[]),eg=async()=>{let t=await x.t4.runPromiseExit((0,tJ.D0)(e));if("Success"===t._tag){let e=t.value.settings;e?.gridLayout!==void 0&&G(e.gridLayout)}else console.error("Failed to load project settings:",t.cause)};(0,s.useEffect)(()=>{queueMicrotask(()=>eg())},[]);let eb=(0,s.useCallback)(()=>{ei.current=!0},[]),ev=(0,s.useCallback)((e,t)=>{if(!ei.current)return void e.preventDefault();ei.current=!1,ed.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t),e.currentTarget.style.opacity="0.4";let r=e.currentTarget.querySelector("[data-drag-handle]");if(r){let t=r.cloneNode(!0);t.style.cssText="position:fixed;top:-9999px;left:-9999px;width:"+r.offsetWidth+"px;background:hsl(var(--card));color:hsl(var(--foreground));box-shadow:var(--elevation-2);border-radius:8px;padding:4px 12px;opacity:0.9;",document.body.appendChild(t),e.dataTransfer.setDragImage(t,20,16),requestAnimationFrame(()=>document.body.removeChild(t))}},[]),ej=(0,s.useCallback)((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",ec.current=t},[]),ew=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.add("ring-2","ring-brand")},[]),ek=(0,s.useCallback)(e=>{e.currentTarget.classList.remove("ring-2","ring-brand")},[]),ey=(0,s.useCallback)(e=>{e.preventDefault(),e.currentTarget.classList.remove("ring-2","ring-brand")},[]),eN=(0,s.useCallback)(e=>{e.currentTarget.style.opacity="1";let t=ed.current,r=ec.current;if(ed.current=null,ec.current=null,!t||!r||t===r)return;let n=eu.current.map(e=>e.data.id),s=n.indexOf(t),o=n.indexOf(r);if(-1===s||-1===o)return;let a=[...n];a[s]=r,a[o]=t,I(a)},[I]),eC=(0,s.useCallback)(e=>{_(t=>t===e?null:e)},[]),eS=(0,s.useCallback)((t,r)=>tH(t)?void tW(t,e):y("browser",t,r),[y,e]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"m"===e.key&&!e.shiftKey&&!e.altKey&&(e.preventDefault(),h&&eC(h))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[d,h,eC]),(0,s.useEffect)(()=>{let e=m.current;if(!e)return;let t=new ResizeObserver(([e])=>{K(e.contentRect.height)});return t.observe(e),K(e.clientHeight),()=>t.disconnect()},[m]),(0,s.useEffect)(()=>{let e=m.current;if(e)return O?V(e.clientHeight):(e.style.overflow="",V(0)),()=>{e&&(e.style.overflow="")}},[O,m]),(0,s.useEffect)(()=>{let e=m.current;if(!e||!O||!q)return;let t=requestAnimationFrame(()=>{let t=e.querySelector(`[data-bubble-id="${O}"]`);t&&t.scrollIntoView({block:"start"}),e.style.overflow="hidden"});return()=>cancelAnimationFrame(t)},[O,q,m]);let[eM,eL]=(0,s.useState)(null);(0,s.useEffect)(()=>{i&&(_(null),eL(i.commandId))},[i]),(0,s.useEffect)(()=>{if(!eM||!u.some(e=>e.data.id===eM))return;let e=requestAnimationFrame(()=>{let e=m.current,t=e?.querySelector(`[data-bubble-id="${CSS.escape(eM)}"]`);if(!e||!t)return;eL(null),f(eM);let r=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r.top-n.top-Math.max(0,(n.height-r.height)/2);e.scrollTo({top:e.scrollTop+s,behavior:"smooth"})});return()=>cancelAnimationFrame(e)},[eM,u,m,f]),(0,s.useEffect)(()=>{if(!eM)return;let e=setTimeout(()=>{eL(null),(0,M.oR)(c("runningTerminals.notFound"),"error")},3e3);return()=>clearTimeout(e)},[eM,c]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.command;t&&k(t)};return window.addEventListener("execute-terminal-command",e),()=>window.removeEventListener("execute-terminal-command",e)},[k]),(0,s.useEffect)(()=>{let e=e=>{let t=e.detail?.url;t&&y("browser",t)};return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[y]);let eE=U>0?Math.floor((U-32-12)/2-41):void 0;return(0,n.jsxs)("div",{ref:eo,className:"h-full flex flex-col bg-background relative",children:[(0,n.jsx)("div",{ref:m,onScroll:ef,className:`console-scroll-root flex-1 overflow-y-auto ${O?"":"py-4 px-4"}`,children:0===u.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"w-full max-w-md flex flex-col gap-4 text-sm",children:[(0,n.jsx)("p",{className:"text-muted-foreground",children:c("console.emptyIntro")}),(0,n.jsx)("ul",{className:"flex flex-col gap-2",children:ns.map(e=>(0,n.jsxs)("li",{className:"flex items-start gap-3",children:[(0,n.jsx)("span",{className:"w-16 flex-shrink-0 text-foreground font-medium",children:c(e.label)}),(0,n.jsxs)("span",{className:"flex-1 flex flex-col gap-1",children:[(0,n.jsx)("span",{className:"flex flex-wrap gap-1",children:e.triggers.map(e=>(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-xs font-mono text-muted-foreground",children:e},e))}),e.notes?.map(e=>(0,n.jsx)("span",{className:"text-xs leading-snug text-muted-foreground/70",children:c(e)},e))]})]},e.key))}),(0,n.jsxs)("button",{type:"button",onClick:()=>k(nt),title:c("console.launchShell"),className:"self-start flex items-center gap-2 px-4 py-2 rounded-lg border border-input bg-background text-sm text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 transition-all",children:[(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),"New PTY"]})]})}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:ea}),F&&(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("button",{onClick:()=>B(D+1),disabled:A,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors disabled:opacity-50",children:A?c("console.loadingMore"):c("console.loadMoreHistory")})}),(0,n.jsx)("div",{className:O?"flex flex-col gap-3":Q?"grid grid-cols-2 gap-3":"flex flex-col gap-3",children:u.map(t=>(0,n.jsx)(rO,{item:t,selected:d&&h===t.data.id,maximized:O===t.data.id,initialSleeping:C.has(t.data.id),tabId:r,projectCwd:e,expandedHeight:q,bubbleContentHeight:eE,onDragStart:ev,onDragOver:ej,onDragEnter:ew,onDragLeave:ek,onDrop:ey,onDragEnd:eN,onSelectId:f,onInterruptId:p,onStdin:g,onDeleteCommand:b,onRerun:v,subscribePtyOutput:H,subscribePtyReset:W,subscribePtyRefresh:z,ptySizeRef:j,resizePty:w,onToggleMaximizeId:eC,onTitleMouseDown:eb,onClosePlugin:N,addBrowserItem:eS,onSleep:S,onWake:L},t.data.id))}),(0,n.jsx)("div",{ref:el})]})}),!O&&u.length>0&&(0,n.jsx)(r9,{showTop:ee,showBottom:en,onScrollTop:ep,onScrollBottom:E}),(0,n.jsx)(r8,{cwd:e,currentCwd:P,commandHistoryRef:T,gridLayout:Q,onGridLayoutChange:t=>{G(t),x.t4.runFork((0,tJ.Yn)({cwd:e,settings:{gridLayout:t}}).pipe(eh.sFT(e=>eh.OH5(()=>console.error("Failed to save project settings:",e))),eh.NWQ(()=>eh.rIH)))},onExecute:k,onAddPluginItem:y,onShowEnvManager:()=>Y(!0),onOpenShell:()=>k(nt),onOpenNote:l}),J&&(0,n.jsx)(rV,{cwd:e,tabId:r,onClose:()=>Y(!1),onSave:e=>$(e)}),X&&(0,n.jsx)(rK,{onClose:()=>Z(!1),onSave:e=>R(e)})]})});var na=r(83897),nl=r(54271);function ni(e,t,r,n){return n&&r&&t.includes(e)}var nd=r(54356),nc=r(16220),nu=r(24058),nm=r(56058),nx=r(32880),nh=r(8183),nf=r(41948),np=r(29899),ng=r(98307),nb=r(65153),nv=r(83448),nj=r(48050),nw=r(45720);function nk({cwd:e,sessionId:t,engine:r,onOpenProjectSessions:a,onOpenSessionBrowser:l,onOpenSettings:i}){let{t:d}=(0,o.Bd)(),[c,u]=(0,s.useState)(!1),m=t?(0,nw.X)(r,t):null;return(0,n.jsx)("div",{className:"border-b border-border px-4 py-3 bg-card",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("img",{src:"/icons/icon-72x72.png",alt:"Cockpit",className:"w-6 h-6"}),(0,n.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("h1",{className:"text-lg font-semibold text-foreground",children:"Cockpit"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"One seat. One AI. Everything under control."})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e&&(0,n.jsx)("span",{className:"text-sm text-foreground max-w-md truncate cursor-help","data-tooltip":`CWD: ${e}`,children:e}),!e&&t&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground max-w-md truncate","data-tooltip":t,children:["Session: ",t]}),e&&(0,n.jsx)("button",{onClick:a,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.projectSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),(0,n.jsx)("button",{onClick:l,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("sessions.browseAllSessions"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}),m&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(m).then(()=>{u(!0),setTimeout(()=>u(!1),2e3)})},className:`p-2 rounded-lg transition-colors ${c?"text-green-11 bg-green-500/10":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,title:c?d("chat.copiedCommandTooltip"):d("chat.copyCommandTooltip",{command:m}),children:c?(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"})})}),(0,n.jsx)("button",{onClick:i,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover rounded-lg transition-colors",title:d("settings.title"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})})]})]})})}function ny(e){return e>=1e6?`${+(e/1e6).toFixed(e%1e6?1:0)}M`:e>=1e3?`${+(e/1e3).toFixed(e>=1e5?0:1)}K`:String(e)}function nN({tokenUsage:e,rateLimitInfo:t,onOpenContext:r,contextWindow:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>{if(!t?.resetsAt)return;let e=setInterval(()=>d(Date.now()),3e4);return()=>clearInterval(e)},[t?.resetsAt]);let c=t?.status==="rejected"?"text-red-11":t?.status==="allowed_warning"?"text-amber-11":"text-muted-foreground",u=t?.status==="rejected"?l("chat.rateLimitRejected","Rate Limited"):t?.status==="allowed_warning"?l("chat.rateLimitWarning","Approaching Limit"):null,m=e=>{if(!e)return"";let t=(e<1e12?1e3*e:e)-i;if(t<=0)return"";let r=Math.ceil(t/6e4);if(r<60)return`${r}m`;let n=Math.floor(r/60),s=r%60;return s>0?`${n}h${s}m`:`${n}h`},x=e=>e?e.replace(/_/g," "):"",h=e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens+e.outputTokens,f=a?h/a:null,p=[a?`${h.toLocaleString()} / ${a.toLocaleString()}`:null,r?l("contextInspector.open"):null].filter(Boolean).join(" \xb7 ")||void 0,g=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),null===f?(0,n.jsxs)("span",{children:[l("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:h.toLocaleString()})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{children:[l("chat.context"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:ny(h)})," / ",ny(a)]}),(0,n.jsx)("span",{className:"w-10 h-1 rounded-full bg-muted overflow-hidden","aria-hidden":!0,children:(0,n.jsx)("span",{className:`block h-full rounded-full ${null===f?"":f>=.9?"bg-red-9":f>=.7?"bg-amber-9":"bg-brand"}`,style:{width:`${Math.min(100,Math.max(2,100*f))}%`}})}),(0,n.jsxs)("strong",{className:`tabular-nums ${(null===f?"":f>=.9?"text-red-11":f>=.7?"text-amber-11":"")||"text-foreground"}`,children:[Math.round(100*f),"%"]})]})]});return(0,n.jsx)("div",{className:"px-4 py-1.5",children:(0,n.jsxs)("div",{className:"flex items-center justify-end gap-4 text-xs text-muted-foreground",children:[t&&u&&(0,n.jsxs)("span",{className:`flex items-center gap-1 ${c}`,"data-tooltip":[t.rateLimitType&&`Type: ${x(t.rateLimitType)}`,null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&`Resets in: ${m(t.resetsAt)}`,t.isUsingOverage&&"Using overage"].filter(Boolean).join(" \xb7 "),children:["rejected"===t.status?(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}):(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:[(0,n.jsx)("strong",{children:u}),null!=t.utilization&&` ${(100*t.utilization).toFixed(0)}%`,t.resetsAt&&` \xb7 ${m(t.resetsAt)}`]})]}),t&&!u&&t.resetsAt&&(0,n.jsxs)("span",{className:"flex items-center gap-1.5","data-tooltip":[t.rateLimitType&&x(t.rateLimitType),null!=t.utilization&&`Usage: ${(100*t.utilization).toFixed(0)}%`,`Resets in: ${m(t.resetsAt)}`].filter(Boolean).join(" \xb7 "),children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),null!=t.utilization?(0,n.jsxs)("span",{children:[(100*t.utilization).toFixed(0),"%"]}):(0,n.jsx)("span",{children:m(t.resetsAt)})]}),r?(0,n.jsx)("button",{type:"button",onClick:r,className:"flex items-center gap-1.5 rounded px-1 -mx-1 hover:bg-hover hover:text-foreground transition-colors","data-tooltip":p,children:g}):(0,n.jsx)("span",{className:"flex items-center gap-1.5","data-tooltip":p,children:g}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})}),(0,n.jsxs)("span",{children:[l("chat.output"),": ",(0,n.jsx)("strong",{className:"text-foreground",children:e.outputTokens.toLocaleString()})]})]}),(e.cacheReadInputTokens>0||e.cacheCreationInputTokens>0)&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-brand",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4"})}),(0,n.jsxs)("span",{children:["Cache: ",(e.cacheReadInputTokens/(e.inputTokens+e.cacheReadInputTokens+e.cacheCreationInputTokens)*100).toFixed(0),"%"]})]}),e.totalCostUsd>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-green-11",children:[(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),(0,n.jsxs)("span",{children:["$",e.totalCostUsd.toFixed(4)]})]})]})})}let nC=["prompt","memory","tools","skills","messages","tool_io","reasoning","other"],nS={light:["#2a78d6","#eb6834","#1baf7a","#eda100","#e87ba4","#008300","#4a3aa7","#e34948"],dark:["#3987e5","#d95926","#199e70","#c98500","#d55181","#008300","#9085e9","#e66767"]},nM={system:"prompt",instructions:"prompt",environment:"prompt",memory:"memory",tools:"tools",mcp:"tools",skills:"skills",agents:"skills",messages:"messages",summary:"messages",tool_io:"tool_io",reasoning:"reasoning",other:"other"};function nL(e){return e>=1e6?`${(e/1e6).toFixed(2)}M`:e>=1e4?`${Math.round(e/1e3)}K`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}let nE=(e,t)=>null===e?"—":`${t?"":"≈"}${nL(e)}`,nP=(0,s.memo)(function({item:e,selected:t,onSelect:r}){return(0,n.jsxs)("button",{onClick:()=>r(e.id),className:`w-full flex items-center gap-2 pl-7 pr-3 py-1 text-left text-xs transition-colors ${t?"bg-selected text-foreground":"text-muted-foreground hover:bg-hover hover:text-foreground"}`,children:[(0,n.jsx)("span",{className:`flex-1 truncate font-mono ${void 0===e.content?"opacity-60":""}`,children:e.label}),(0,n.jsx)("span",{className:"tabular-nums flex-shrink-0",children:nE(e.tokens,e.exact??!1)})]})}),nT=(0,s.memo)(function({category:e,index:t,color:r,label:a,expanded:l,selectedKey:i,onToggle:d,onSelect:c}){let{t:u}=(0,o.Bd)(),m=(0,s.useCallback)(e=>c(`${t}:${e}`),[t,c]);return(0,n.jsxs)("div",{className:"border-b border-border last:border-b-0",children:[(0,n.jsxs)("button",{onClick:()=>d(t),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-hover transition-colors",children:[(0,n.jsx)("svg",{className:`w-3 h-3 text-muted-foreground transition-transform flex-shrink-0 ${l?"rotate-90":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-sm flex-shrink-0",style:{backgroundColor:r}}),(0,n.jsx)("span",{className:"flex-1 text-sm text-foreground truncate",children:a}),(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:u("contextInspector.items",{count:e.items.length})}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground tabular-nums w-14 text-right flex-shrink-0",children:nE(e.tokens,e.exact)})]}),l&&(0,n.jsx)("div",{className:"pb-1",children:e.items.map(e=>(0,n.jsx)(nP,{item:e,selected:i===`${t}:${e.id}`,onSelect:m},e.id))})]})});function n$({isOpen:e,onClose:t,cwd:r,sessionId:a}){let{t:l,i18n:i}=(0,o.Bd)(),{resolvedTheme:d}=(0,eC.DP)(),c=nS["dark"===d?"dark":"light"],[u,m]=(0,s.useState)({status:"idle"}),[h,f]=(0,s.useState)(()=>new Set),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(0),[j,w]=(0,s.useState)(!1);(0,I.E)(t,e),(0,s.useEffect)(()=>{if(!e||!r||!a)return;let t=!1;return queueMicrotask(()=>{t||m({status:"loading"})}),x.t4.runPromiseExit((0,nv._l)(r,a)).then(e=>{t||("Success"===e._tag?m({status:"ready",data:e.value}):m({status:"error",message:l("contextInspector.loadFailed")}))}),()=>{t=!0}},[e,r,a,b,l]);let k="ready"===u.status?u.data:null,y=(0,s.useMemo)(()=>{let e=new Map;for(let t of k?.categories??[])e.set(nM[t.id],(e.get(nM[t.id])??0)+t.tokens);return nC.map((t,r)=>({group:t,color:c[r],tokens:e.get(t)??0})).filter(e=>e.tokens>0)},[k,c]),N=(0,s.useCallback)(e=>c[nC.indexOf(nM[e])],[c]),C=(0,s.useCallback)(e=>{f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),S=(0,s.useCallback)(e=>{g(e),w(!1)},[]),M=(0,s.useMemo)(()=>{if(!k||!p)return null;let e=p.indexOf(":"),t=k.categories[Number(p.slice(0,e))],r=t?.items.find(t=>t.id===p.slice(e+1));return t&&r?{category:t,item:r}:null},[k,p]),L=(0,s.useCallback)(()=>{M?.item.content&&navigator.clipboard.writeText(M.item.content).then(()=>w(!0),()=>w(!1))},[M]);if(!e)return null;let E=y.reduce((e,t)=>e+t.tokens,0),P=k?.usedTokens??null,T=Math.max(k?.contextWindow??0,P??0,E,1),$=k?.contextWindow!=null&&null!=P?Math.max(0,k.contextWindow-P):null,R=e=>e.name??l(`contextInspector.categories.${e.id}`),F=k?.capturedAt?new Date(k.capturedAt).toLocaleString(i.language):null;return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-lv3 w-full max-w-6xl mx-4 h-[85vh] flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:l("contextInspector.title")}),k&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground truncate",children:[k.engine,k.model?` \xb7 ${k.model}`:""]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>v(e=>e+1),className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:l("contextInspector.refresh")}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),a?"error"===u.status?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-red-11",children:u.message}):k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-5 py-3 border-b border-border flex-shrink-0 space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-baseline gap-4 text-xs text-muted-foreground",children:[(0,n.jsxs)("span",{children:[l("contextInspector.used"),": ",(0,n.jsx)("strong",{className:"text-foreground text-sm tabular-nums",children:null===P?"—":P.toLocaleString()})]}),(0,n.jsx)("span",{children:k.contextWindow?(0,n.jsxs)(n.Fragment,{children:[l("contextInspector.window"),": ",(0,n.jsx)("strong",{className:"text-foreground tabular-nums",children:k.contextWindow.toLocaleString()}),null!==P&&` (${Math.round(P/k.contextWindow*100)}%)`]}):l("contextInspector.unknownWindow")}),null!==$&&(0,n.jsxs)("span",{children:[l("contextInspector.free"),": ",(0,n.jsx)("span",{className:"tabular-nums",children:$.toLocaleString()})]}),(0,n.jsx)("span",{className:"flex-1"}),F&&(0,n.jsx)("span",{children:l("contextInspector.capturedAt",{time:F})})]}),(0,n.jsx)("div",{className:"flex h-3 w-full rounded bg-muted overflow-hidden gap-[2px]",children:y.map(e=>(0,n.jsx)("div",{className:"h-full first:rounded-l last:rounded-r min-w-[2px]",style:{width:`${e.tokens/T*100}%`,backgroundColor:e.color},"data-tooltip":`${l(`contextInspector.groups.${e.group}`)} \xb7 ${e.tokens.toLocaleString()}`},e.group))}),(0,n.jsx)("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-[11px] text-muted-foreground",children:y.map(e=>(0,n.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-sm",style:{backgroundColor:e.color}}),l(`contextInspector.groups.${e.group}`),(0,n.jsx)("span",{className:"text-foreground tabular-nums",children:nL(e.tokens)})]},e.group))}),k.notes.length>0&&(0,n.jsx)("ul",{className:"text-[11px] text-muted-foreground space-y-0.5 list-disc pl-4",children:k.notes.map(e=>(0,n.jsx)("li",{children:l(`contextInspector.notes.${e}`)},e))})]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsx)("div",{className:"w-[38%] min-w-[280px] border-r border-border overflow-y-auto",children:0===k.categories.length?(0,n.jsx)("div",{className:"p-6 text-sm text-muted-foreground text-center",children:l("contextInspector.empty")}):k.categories.map((e,t)=>(0,n.jsx)(nT,{category:e,index:t,color:N(e.id),label:R(e),expanded:h.has(t),selectedKey:h.has(t)?p:null,onToggle:C,onSelect:S},`${e.id}:${t}`))}),(0,n.jsx)("div",{className:"flex-1 min-w-0 flex flex-col",children:M?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-sm flex-shrink-0",style:{backgroundColor:N(M.category.id)}}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsx)("div",{className:"text-sm text-foreground font-mono truncate",children:M.item.label}),(0,n.jsxs)("div",{className:"text-[11px] text-muted-foreground truncate",children:[R(M.category),M.item.path&&` \xb7 ${M.item.path}`,null!==M.item.tokens&&` \xb7 ${nE(M.item.tokens,M.item.exact??!1)} tokens`]})]}),void 0!==M.item.content&&(0,n.jsx)("button",{onClick:L,className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors flex-shrink-0",children:j?l("contextInspector.copied"):l("contextInspector.copy")})]}),M.item.truncated&&(0,n.jsx)("div",{className:"px-4 py-1 text-[11px] text-amber-11 border-b border-border flex-shrink-0",children:l("contextInspector.truncated",{count:M.item.content?.length??0})}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:void 0===M.item.content?(0,n.jsx)("div",{className:"p-6 text-sm text-muted-foreground",children:l("contextInspector.noContent")}):(0,n.jsx)("pre",{className:"px-4 py-3 text-xs leading-relaxed font-mono text-foreground whitespace-pre-wrap break-words",children:M.item.content})})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-6 text-center",children:l("contextInspector.selectItem")})})]})]}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:l("common.loading")}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:l("contextInspector.noSession")})]})]})}var nR=r(66109);function nI({isOpen:e,onClose:t,cwd:r,sessionId:a,onSelectMessage:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(null),[u,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)(""),[g,b]=(0,s.useState)(null),v=(0,s.useRef)(0);(0,s.useEffect)(()=>()=>{++v.current},[e,r,a]);let j=(0,s.useRef)(null),w=(0,s.useRef)(null);(0,I.E)(t,e),(0,s.useEffect)(()=>{if(!e){c(null),h(!1),p(""),b(null);return}if(!r||!a)return void c([]);let t=!1;return x.t4.runPromiseExit((0,nv.nM)(r,a)).then(e=>{t||("Success"===e._tag?c(e.value.messages):(console.error("Failed to load user message index:",e.cause),h(!0),c([])))}),()=>{t=!0}},[e,r,a]);let k=(0,s.useMemo)(()=>{if(!d)return[];let e=d.map((e,t)=>({entry:e,ordinal:t+1})),t=f.trim().toLowerCase();return t?e.filter(e=>e.entry.content.toLowerCase().includes(t)):e},[d,f]),y=f.trim().length>0;(0,s.useEffect)(()=>{if(!e||y||!d)return;let t=j.current;t&&(t.scrollTop=t.scrollHeight)},[e,y,d]);let N=(0,s.useCallback)(async e=>{let r=++v.current;b(e.id);try{let n=await l(e);r===v.current&&"scrolled"===n.status&&t()}finally{r===v.current&&b(null)}},[l,t]);if(!e)return null;let C=null===d,S=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim",onClick:t,children:(0,n.jsxs)("div",{className:nR.iG,onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground",children:i("userMessages.title")}),d&&d.length>0&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:i("userMessages.count",{shown:k.length,total:d.length})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:w,type:"text",autoFocus:!0,placeholder:i("userMessages.searchPlaceholder"),value:f,onChange:e=>p(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),f&&(0,n.jsx)("button",{onClick:()=>{p(""),w.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:i("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),(0,n.jsx)("div",{ref:j,className:"flex-1 overflow-y-auto",children:C?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:i("common.loading")}):u?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground text-sm",children:i("userMessages.loadFailed")}):0===d.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:i("userMessages.noMessages")}):0===k.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:i("userMessages.noResults")}):(0,n.jsx)("div",{className:"divide-y divide-border",children:k.map(({entry:e,ordinal:t})=>{let r,s=e.timestamp?function(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return"";let r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}(e.timestamp):"";return(0,n.jsx)("button",{onClick:()=>{N(e)},className:"w-full px-4 py-3 text-left hover:bg-hover transition-colors","data-tooltip":(r=e.content.trim()).length>500?`${r.slice(0,500)}…`:r,children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsxs)("span",{className:"text-xs text-muted-foreground font-mono w-6 shrink-0 pt-0.5",children:[t,"."]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-sm text-foreground truncate",children:e.content.replace(/\s+/g," ").trim()}),g===e.id&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:i("userMessages.jumping")})]}),s&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground shrink-0 pt-0.5",children:s})]})},e.id)})})})]})});return(0,n.jsx)(m.ZL,{children:S})}function nF(e,t,r=t.id){let n=t.sourceRef;return e.find(e=>n?n.sourceId?e.sourceRef?.sourceId===n.sourceId:e.id===n.id&&e.sourceRef?.prefix===n.prefix:e.id===r)}var nB=r(97938),nD=r(20917),nA=r(74086),nH=r(38719),nW=r(36351);function nz({image:e,onClose:t}){let{t:r}=(0,o.Bd)(),s=async t=>{t.stopPropagation();try{var n;if(!navigator.clipboard?.write||"u"<typeof ClipboardItem)throw Error("Clipboard image write is unavailable");let t=await (n=e.preview,new Promise((e,t)=>{let r=new Image;r.onload=()=>{let n=document.createElement("canvas");n.width=r.naturalWidth,n.height=r.naturalHeight;let s=n.getContext("2d");s?(s.drawImage(r,0,0),n.toBlob(r=>{r?e(r):t(Error("Could not encode image"))},"image/png")):t(Error("Canvas is unavailable"))},r.onerror=()=>t(Error("Could not load image")),r.src=n}));await navigator.clipboard.write([new ClipboardItem({"image/png":t})]),(0,M.oR)(r("imagePreview.copiedImage"),"success")}catch{(0,M.oR)(r("common.copyFailed"),"error")}},a=(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:t,children:[(0,n.jsxs)("div",{className:"absolute top-4 right-4 flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:s,className:"w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",title:r("imagePreview.copyImage"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 7V5a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2M7 7h6a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2Z"})})}),(0,n.jsx)("button",{type:"button",onClick:t,className:"w-10 h-10 flex items-center justify-center text-white/80 hover:text-white bg-black/40 hover:bg-black/60 rounded-full transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("img",{src:e.preview,alt:r("imagePreview.previewImage"),className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:e=>e.stopPropagation()})]});return(0,n.jsx)(m.ZL,{children:a})}function nO({images:e,onRemove:t,disabled:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(null);return 0===e.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 p-2 border-b border-border",children:e.map(e=>(0,n.jsxs)("div",{className:"relative group w-16 h-16 rounded-lg overflow-hidden border border-border cursor-pointer",onClick:()=>i(e),children:[(0,n.jsx)("img",{src:e.preview,alt:a("imagePreview.previewImage"),className:"w-full h-full object-cover hover:opacity-90 transition-opacity"}),(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),t(e.id)},className:"absolute top-0 right-0 w-5 h-5 bg-black/60 hover:bg-black/80 text-white text-xs flex items-center justify-center rounded-bl-lg opacity-0 group-hover:opacity-100 transition-opacity",title:a("imagePreview.deleteImage"),children:"✕"})]},e.id))}),l&&(0,n.jsx)(nz,{image:l,onClose:()=>i(null)})]})}var n_=r(38798),nq=r(94514),nV=r(59883),nU=r(56204),nK=r(21362),nQ=r(63393);let nG=()=>Math.random().toString(36).slice(2,10),nJ=e=>e.replace(/\\n/g,"\n");function nY(e){let t=[],r=null;for(let[n,s]of e.split(/\r?\n/).entries()){if(!s.trim())continue;let e=s.match(/^\s*-(?:\s+(.*))?$/);if(e){let t=(e[1]??"").trim();if(!r)return{ok:!1,line:n+1};r.isGroup=!0,t&&r.children.push(nJ(t));continue}if(/^\s/.test(s))return{ok:!1,line:n+1};let o=s.trim();o&&(r={text:nJ(o),children:[],isGroup:!1},t.push(r))}return{ok:!0,nodes:t.map(e=>e.isGroup?{id:nG(),name:e.text,items:e.children.map(e=>({id:nG(),text:e}))}:{id:nG(),text:e.text})}}function nX({title:e,nodes:t,onSave:r,onClose:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>t.flatMap(e=>(0,nv._9)(e)?[e.name.replace(/\n/g,"\\n"),...e.items.length>0?e.items.map(e=>`- ${e.text.replace(/\n/g,"\\n")}`):["- "]]:[e.text.replace(/\n/g,"\\n")]).join("\n")),[c,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(!1),f=nY(i);(0,I.E)(a);let p=(0,s.useCallback)(async()=>{let e=nY(i);!e.ok||c||((u(!0),h(!1),await r(e.nodes))?a():(u(!1),h(!0)))},[a,r,c,i]);return(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{"data-quick-instruction-layer":"",className:"fixed inset-0 z-[300] flex items-center justify-center bg-scrim p-4",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:(0,n.jsxs)("div",{role:"dialog","aria-modal":"true","aria-label":e,className:"w-full max-w-4xl max-h-[90vh] bg-card border border-border rounded-xl shadow-lv3 flex flex-col",children:[(0,n.jsxs)("header",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:e}),(0,n.jsx)("p",{className:"mt-0.5 text-xs text-muted-foreground",children:l("chat.quickInstructionsMarkdownHint")})]}),(0,n.jsx)("button",{type:"button",onClick:a,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded","aria-label":l("common.cancel"),children:(0,n.jsx)(es.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 px-4 py-3",children:(0,n.jsx)("textarea",{autoFocus:!0,wrap:"off",value:i,onChange:e=>d(e.target.value),placeholder:l("chat.quickInstructionsMarkdownPlaceholder"),rows:24,spellCheck:!1,className:"w-full h-[60vh] min-h-80 max-h-[70vh] resize-y overflow-x-auto whitespace-pre px-3 py-2 text-sm font-mono leading-6 bg-background border border-border rounded-lg text-foreground focus:outline-none focus:border-brand"})}),(0,n.jsxs)("footer",{className:"flex items-center justify-between gap-3 px-4 py-3 border-t border-border",children:[(0,n.jsx)("span",{className:"text-xs text-destructive",children:f.ok?x?l("chat.saveQuickInstructionsFailed"):"":l("chat.quickInstructionsMarkdownError",{line:f.line})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{type:"button",onClick:a,className:"px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground rounded hover:bg-hover",children:l("common.cancel")}),(0,n.jsx)("button",{type:"button",disabled:!f.ok||c,onClick:p,className:"px-3 py-1.5 text-xs rounded border border-brand text-brand hover:bg-brand/10 disabled:opacity-40",children:l(c?"chat.savingQuickInstructions":"common.save")})]})]})]})})})}let nZ="data-quick-instruction-layer",n0=()=>Math.random().toString(36).slice(2,10);function n1({groups:e,value:t,onChange:r,onSubmit:a,onCancel:l}){let{t:i}=(0,o.Bd)(),[d,u]=(0,s.useState)(!1),[m,x]=(0,s.useState)(null),[h,f]=(0,s.useState)(0),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=[null,...e.map(e=>e.id)],v=null===t?i("chat.instructionGroupNone"):e.find(e=>e.id===t)?.name??i("chat.instructionGroupNone"),j=(0,s.useCallback)(()=>{let r=p.current?.getBoundingClientRect();r&&(x(((e,t,r)=>{let n=Math.min(e.width,r.width-16),s=Math.min(Math.max(8,e.left),Math.max(8,r.width-n-8)),o=r.height-e.bottom-2-8,a=e.top-2-8,l=28*t+8;if(o>=Math.min(l,96)||o>=a)return{left:s,top:e.bottom+2,width:n,maxHeight:Math.max(28,Math.min(l,o))};let i=Math.max(28,Math.min(l,a));return{left:s,top:e.top-2-i,width:n,maxHeight:i}})(r,e.length+1,{width:window.innerWidth,height:window.innerHeight})),f(Math.max(0,b.indexOf(t))),u(!0))},[e.length,b,t]),w=(0,s.useCallback)(()=>{u(!1),x(null),p.current?.focus()},[]),k=(0,s.useCallback)(e=>{r(e),w()},[r,w]);(0,s.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;g.current?.contains(t)||p.current?.contains(t)||(u(!1),x(null))};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]),(0,s.useEffect)(()=>{if(!d)return;let e=()=>{u(!1),x(null)};return window.addEventListener("resize",e),window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",e,!0)}},[d]);let y=(0,s.useCallback)(e=>{d?"Escape"===e.key?(e.preventDefault(),e.stopPropagation(),w()):"ArrowDown"===e.key?(e.preventDefault(),e.stopPropagation(),f(e=>Math.min(b.length-1,e+1))):"ArrowUp"===e.key?(e.preventDefault(),e.stopPropagation(),f(e=>Math.max(0,e-1))):"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),k(b[h]??null)):"ArrowDown"===e.key||" "===e.key?(e.preventDefault(),e.stopPropagation(),j()):"Enter"===e.key?(e.preventDefault(),e.stopPropagation(),a()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l())},[d,j,w,k,b,h,a,l]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:p,type:"button",onClick:()=>d?w():j(),onKeyDown:y,className:"w-[140px] min-w-0 flex-shrink-0 px-2 py-1 flex items-center gap-1 text-xs rounded border border-input bg-background hover:bg-hover focus:outline-none focus:ring-1 focus:ring-ring transition-colors",title:i("chat.instructionGroupLabel"),children:[(0,n.jsx)(n_.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate text-left ${null===t?"text-muted-foreground":""}`,children:v}),(0,n.jsx)(tV.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"})]}),d&&m&&(0,c.createPortal)((0,n.jsx)("div",{ref:g,[nZ]:"",role:"listbox",style:{left:m.left,top:m.top,width:m.width,maxHeight:m.maxHeight},className:"fixed z-[60] py-1 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:b.map((r,s)=>{let o=r===t;return(0,n.jsxs)("button",{type:"button",role:"option","aria-selected":o,onClick:()=>k(r),onMouseEnter:()=>f(s),className:`w-full min-w-0 px-2 py-1 flex items-center gap-1.5 text-xs text-left transition-colors ${s===h?"bg-hover":""}`,children:[(0,n.jsx)(nq.A,{className:`w-3 h-3 flex-shrink-0 ${o?"text-brand":"opacity-0"}`}),(0,n.jsx)("span",{className:`flex-1 min-w-0 truncate ${null===r?"text-muted-foreground":""}`,children:null===r?i("chat.instructionGroupNone"):e.find(e=>e.id===r)?.name})]},r??"__none__")})}),document.body)]})}function n2({initialValue:e,placeholder:t,groupChoices:r,initialGroupId:o,onCommit:a,onCancel:l}){let[i,d]=(0,s.useState)(e),[c,u]=(0,s.useState)(o??null),m=(0,s.useCallback)(()=>{let e=i.trim();e&&a(e,c)},[i,c,a]),x=(0,s.useCallback)(e=>{"Enter"!==e.key||e.nativeEvent.isComposing?"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),l()):(e.preventDefault(),e.stopPropagation(),m())},[m,l]);return(0,n.jsxs)("div",{className:"mb-1 flex items-center gap-1",children:[(0,n.jsx)("input",{type:"text",value:i,onChange:e=>d(e.target.value),onKeyDown:x,placeholder:t,autoFocus:!0,className:"flex-1 min-w-0 px-2 py-1 text-xs rounded border border-input bg-background focus:outline-none focus:ring-1 focus:ring-ring"}),r&&r.length>0&&(0,n.jsx)(n1,{groups:r,value:c,onChange:u,onSubmit:m,onCancel:l})]})}let n5=(e,t)=>`flex items-center group min-w-0 rounded transition-opacity ${e?"opacity-50":""} ${t?"border-t-2 border-brand":""}`,n4="p-1 text-muted-foreground hover:text-foreground rounded opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0",n3=(0,s.memo)(function({item:e,isDragging:t,isDragOver:r,onSelect:s,onInsert:a,onEdit:l,onDelete:i,onDragStart:d,onDragOver:c,onDrop:u,onDragEnd:m,management:x=!0}){let{t:h}=(0,o.Bd)();return(0,n.jsxs)("div",{draggable:x,onDragStart:x?()=>d(e.id):void 0,onDragOver:x?t=>c(t,e.id):void 0,onDrop:x?()=>u(e.id):void 0,onDragEnd:x?m:void 0,className:n5(t,r),children:[x&&(0,n.jsx)(nV.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsx)(S.m,{content:e.text,children:(0,n.jsxs)("button",{type:"button",onClick:()=>s(e.text),className:"flex-1 min-w-0 flex items-start gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",children:[(0,n.jsx)(nU.A,{className:"w-3 h-3 mt-1 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"min-w-0 line-clamp-2 break-words",children:e.text})]})}),(0,n.jsx)("button",{type:"button",onClick:()=>a(e.text),className:n4,title:h("chat.insertQuickInstruction"),children:(0,n.jsx)(nW.A,{className:"w-3 h-3"})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>l(e.id),className:n4,title:h("common.edit"),children:(0,n.jsx)(rX.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(e.id),className:`${n4} hover:text-destructive`,title:h("common.delete"),children:(0,n.jsx)(es.A,{className:"w-3 h-3"})})]})]})}),n6=(0,s.memo)(function({group:e,isOpen:t,isDragging:r,isDragOver:a,isDragActive:l,onHoverOpen:i,onHoverClose:d,onToggle:c,onRename:u,onDelete:m,onDragStart:x,onDragOver:h,onDrop:f,onDragEnd:p,management:g=!0}){let{t:b}=(0,o.Bd)(),v=(0,s.useRef)(null),j=(0,s.useCallback)(()=>v.current?.getBoundingClientRect(),[]);return(0,n.jsxs)("div",{ref:v,draggable:g,onDragStart:g?()=>x(e.id):void 0,onDragOver:g?t=>h(t,e.id):void 0,onDrop:g?()=>f(e.id):void 0,onDragEnd:g?p:void 0,onMouseEnter:()=>{if(l)return;let t=j();t&&i(e.id,t)},onMouseLeave:()=>{l||d()},className:`${n5(r,a)} ${t?"bg-hover":""}`,children:[g&&(0,n.jsx)(nV.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity cursor-grab"}),(0,n.jsxs)("button",{type:"button",onClick:()=>{let t=j();t&&c(e.id,t)},className:"flex-1 min-w-0 flex items-center gap-2 px-2 py-1.5 text-left text-sm rounded hover:bg-hover transition-colors",title:e.name,children:[(0,n.jsx)(n_.A,{className:"w-3 h-3 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:e.name}),(0,n.jsxs)("span",{className:"ml-auto flex items-center gap-1 flex-shrink-0 text-[10px] text-muted-foreground",children:[e.items.length>0&&e.items.length,(0,n.jsx)(nK.A,{className:"w-3 h-3"})]})]}),g&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{type:"button",onClick:()=>u(e.id),className:n4,title:b("common.edit"),children:(0,n.jsx)(rX.A,{className:"w-3 h-3"})}),(0,n.jsx)("button",{type:"button",onClick:()=>m(e.id),className:`${n4} hover:text-destructive`,title:b("common.delete"),children:(0,n.jsx)(es.A,{className:"w-3 h-3"})})]})]})});function n8({group:e,position:t,groupChoices:r,editId:s,isAdding:a,isDragActive:l,dragId:i,dragOverId:d,onMouseEnter:u,onMouseLeave:m,onSelect:x,onInsert:h,onStartEdit:f,onCommitEdit:p,onCancelEdit:g,onDelete:b,onStartAdd:v,onCommitAdd:j,onCancelAdd:w,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S=!0}){let{t:M}=(0,o.Bd)();return(0,c.createPortal)((0,n.jsxs)("div",{[nZ]:"",onMouseEnter:u,onMouseLeave:()=>{l||m()},style:{left:t.left,top:t.top,width:t.width,maxHeight:t.maxHeight},className:"fixed z-50 p-2 bg-popover border border-border rounded-lg shadow-lv2 overflow-y-auto",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1 truncate",children:e.name}),S&&(0,n.jsx)("button",{type:"button",onClick:v,className:"p-0.5 text-muted-foreground hover:text-foreground rounded flex-shrink-0",title:M("chat.addQuickInstruction"),children:(0,n.jsx)(rq.A,{className:"w-3.5 h-3.5"})})]}),S&&a&&(0,n.jsx)(n2,{initialValue:"",placeholder:M("chat.quickInstructionPlaceholder"),onCommit:e=>j(e),onCancel:w}),0===e.items.length&&!a&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:M("chat.noQuickInstructions")}),e.items.map(t=>s===t.id?(0,n.jsx)(n2,{initialValue:t.text,placeholder:M("chat.quickInstructionPlaceholder"),groupChoices:r,initialGroupId:e.id,onCommit:(e,r)=>p(t.id,e,r),onCancel:g},`edit-${t.id}`):(0,n.jsx)(n3,{item:t,isDragging:i===t.id,isDragOver:d===t.id&&i!==t.id,onSelect:x,onInsert:h,onEdit:f,onDelete:b,onDragStart:k,onDragOver:y,onDrop:N,onDragEnd:C,management:S},t.id))]}),document.body)}function n9({label:e,nodes:t,scope:r,openGroupId:a,flyoutPosition:l,onOpenFlyout:i,onCloseFlyout:d,onKeepFlyout:c,onSave:u,onSelect:m,onInsert:x,management:h=!0,onManage:f}){let{t:p}=(0,o.Bd)(),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(null),[y,N]=(0,s.useState)(null),[C,S]=(0,s.useState)(null),L=t.filter(nv._9),E=a?L.find(e=>e.id===a)??null:null,P=(0,s.useRef)(t);P.current=t;let T=(0,s.useRef)(a);T.current=a;let $=(0,s.useRef)(null);(0,s.useEffect)(()=>{j(!1)},[a]);let R=(0,s.useCallback)(e=>{k(null),u(r,e)},[u,r]),I=(0,s.useCallback)(e=>{b(null),R([...P.current,{id:n0(),text:e}])},[R]),F=(0,s.useCallback)(e=>{b(null),R([...P.current,{id:n0(),name:e,items:[]}])},[R]),B=(0,s.useCallback)((e,t,r,n)=>{let s=P.current,o={id:e,text:t};if(r===n)return void R(s.map(t=>(0,nv._9)(t)?t.id===n?{...t,items:t.items.map(t=>t.id===e?o:t)}:t:null===n&&t.id===e?o:t));let a=null===r?s.filter(t=>(0,nv._9)(t)||t.id!==e):s.map(t=>(0,nv._9)(t)&&t.id===r?{...t,items:t.items.filter(t=>t.id!==e)}:t);R(null===n?[...a,o]:a.map(e=>(0,nv._9)(e)&&e.id===n?{...e,items:[...e.items,o]}:e))},[R]),D=(0,s.useCallback)((e,t)=>{R(P.current.map(r=>(0,nv._9)(r)&&r.id===e?{...r,name:t}:r))},[R]),A=(0,s.useCallback)(async e=>{let t=P.current.find(t=>t.id===e);if(t&&(0,nv._9)(t)&&t.items.length>0){if(!await (0,M.lJ)(p("chat.deleteInstructionGroupConfirm",{name:t.name,count:t.items.length}),{danger:!0,confirmText:p("common.delete")}))return;d()}k(null),R(P.current.filter(t=>t.id!==e))},[R,p,d]),H=(0,s.useCallback)(e=>{let t=T.current;t&&R(P.current.map(r=>(0,nv._9)(r)&&r.id===t?e(r):r))},[R]),W=(0,s.useCallback)(e=>{j(!1),H(t=>({...t,items:[...t.items,{id:n0(),text:e}]}))},[H]),z=(0,s.useCallback)(e=>{k(null),H(t=>({...t,items:t.items.filter(t=>t.id!==e)}))},[H]),O=(0,s.useCallback)((e,t,r)=>{B(e,t,T.current,r)},[B]),_=(0,s.useCallback)(e=>{$.current=e,N(e)},[]),q=(0,s.useCallback)(()=>{_(null),S(null)},[_]),V=(0,s.useCallback)(e=>{_(e),d()},[_,d]),U=(0,s.useCallback)((e,t)=>{e.preventDefault(),S(t)},[]),K=(e,t,r)=>{let n=e.findIndex(e=>e.id===t),s=e.findIndex(e=>e.id===r);if(n<0||s<0)return e;let o=[...e],[a]=o.splice(n,1);return o.splice(s,0,a),o},Q=(0,s.useCallback)(e=>{let t=$.current;q(),t&&t!==e&&R(K(P.current,t,e))},[R,q]),G=(0,s.useCallback)(e=>{let t=$.current;q(),t&&t!==e&&H(r=>({...r,items:K(r.items,t,e)}))},[H,q]),J=e=>{let t=P.current.find(t=>(0,nv._9)(t)&&t.id===e);return t&&(0,nv._9)(t)?t.items.length:0},Y=(0,s.useCallback)((e,t)=>{i(r,e,t,J(e),!1)},[i,r]),X=(0,s.useCallback)((e,t)=>{T.current===e?d():i(r,e,t,J(e),!0)},[i,d,r]);return(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-muted-foreground px-1",children:e}),h?(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{type:"button",onClick:()=>{k(null),b("group")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:p("chat.addInstructionGroup"),children:(0,n.jsx)(nQ.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>{k(null),b("instruction")},className:"p-0.5 text-muted-foreground hover:text-foreground rounded",title:p("chat.addQuickInstruction"),children:(0,n.jsx)(rq.A,{className:"w-3.5 h-3.5"})})]}):f?(0,n.jsx)("button",{type:"button",onClick:f,className:"p-1 text-muted-foreground hover:text-brand rounded hover:bg-hover transition-colors",title:p("common.edit"),"aria-label":p("common.edit"),children:(0,n.jsx)(rX.A,{className:"w-3.5 h-3.5"})}):null]}),"instruction"===g&&(0,n.jsx)(n2,{initialValue:"",placeholder:p("chat.quickInstructionPlaceholder"),onCommit:e=>I(e),onCancel:()=>b(null)}),"group"===g&&(0,n.jsx)(n2,{initialValue:"",placeholder:p("chat.instructionGroupNamePlaceholder"),onCommit:e=>F(e),onCancel:()=>b(null)}),0===t.length&&!g&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground px-1 py-1",children:p("chat.noQuickInstructions")}),t.map(e=>w===e.id?(0,nv._9)(e)?(0,n.jsx)(n2,{initialValue:e.name,placeholder:p("chat.instructionGroupNamePlaceholder"),onCommit:t=>D(e.id,t),onCancel:()=>k(null)},`edit-${e.id}`):(0,n.jsx)(n2,{initialValue:e.text,placeholder:p("chat.quickInstructionPlaceholder"),groupChoices:L,initialGroupId:null,onCommit:(t,r)=>B(e.id,t,null,r),onCancel:()=>k(null)},`edit-${e.id}`):(0,nv._9)(e)?(0,n.jsx)(n6,{group:e,isOpen:a===e.id,isDragging:y===e.id,isDragOver:C===e.id&&y!==e.id,isDragActive:null!==y,onHoverOpen:Y,onHoverClose:d,onToggle:X,onRename:k,onDelete:A,onDragStart:V,onDragOver:U,onDrop:Q,onDragEnd:q,management:h},e.id):(0,n.jsx)(n3,{item:e,isDragging:y===e.id,isDragOver:C===e.id&&y!==e.id,onSelect:m,onInsert:x,onEdit:k,onDelete:A,onDragStart:V,onDragOver:U,onDrop:Q,onDragEnd:q,management:h},e.id)),E&&l&&(0,n.jsx)(n8,{group:E,position:l,groupChoices:L,editId:w,isAdding:v,isDragActive:null!==y,dragId:y,dragOverId:C,onMouseEnter:c,onMouseLeave:d,onSelect:m,onInsert:x,onStartEdit:k,onCommitEdit:O,onCancelEdit:()=>k(null),onDelete:z,onStartAdd:()=>{k(null),j(!0)},onCommitAdd:W,onCancelAdd:()=>j(!1),onDragStart:_,onDragOver:U,onDrop:G,onDragEnd:q,management:h})]})}function n7({cwd:e,anchorRef:t,onClose:r,onSelect:a,onInsert:l}){let{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)([]),[u,m]=(0,s.useState)([]),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(null),b=(0,s.useRef)(null),v=(0,s.useRef)(null),j=(0,s.useRef)(null),w=(0,s.useCallback)(()=>{v.current&&(clearTimeout(v.current),v.current=null),j.current&&(clearTimeout(j.current),j.current=null)},[]);(0,s.useEffect)(()=>w,[w]),(0,s.useEffect)(()=>{let t=!1;return(async()=>{let[r,n]=await Promise.all([x.t4.runPromiseExit((0,nv.ZQ)()),e?x.t4.runPromiseExit((0,nv.$x)(e)):null]);!t&&("Success"===r._tag?c(r.value.instructions??[]):console.error("Failed to load global instructions:",r.cause),n&&"Success"===n._tag?m(n.value.instructions??[]):n&&console.error("Failed to load project instructions:",n.cause))})(),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{let n;if((n=e.target)instanceof Element&&null!==n.closest(`[${nZ}]`))return;let s=t.current;s&&!s.contains(e.target)&&r()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,r]),(0,s.useEffect)(()=>{if(!h)return;let e=()=>{w(),f(null)},t=t=>{let r=b.current;r&&t.target instanceof Node&&t.target.contains(r)&&e()};return window.addEventListener("resize",e),window.addEventListener("scroll",t,!0),()=>{window.removeEventListener("resize",e),window.removeEventListener("scroll",t,!0)}},[h,w]);let k=(0,s.useCallback)((e,t,r,n,s)=>{w();let o=()=>{var s;let o,a,l,i,d,c,u;return f({scope:e,groupId:t,position:(a=(s={width:window.innerWidth,height:window.innerHeight}).width-r.right-4-8,l=r.left-4-8,i=288,a>=288?(i=Math.min(420,a),o=r.right+4):l>=288?(i=Math.min(420,l),o=r.left-4-i):a>=l?(i=Math.max(180,a),o=r.right+4):(i=Math.max(180,l),o=r.left-4-i),o=Math.min(Math.max(8,o),Math.max(8,s.width-i-8)),c=Math.min(d=Math.max(90,.6*s.height),30*n+40),(u=r.top-4)+c>s.height-8&&(u=s.height-8-c),{left:o,top:u=Math.max(8,u),width:i,maxHeight:d})})};s?o():v.current=setTimeout(o,150)},[w]),y=(0,s.useCallback)(()=>{w(),j.current=setTimeout(()=>f(null),300)},[w]),N=(0,s.useCallback)(()=>w(),[w]),C=(0,s.useCallback)(async(t,r)=>{let n="global"===t?c:m;n(r);let s=await x.t4.runPromiseExit((0,nv.hZ)("global"===t?{scope:"global",instructions:r}:{cwd:e,instructions:r}));return"Failure"===s._tag?(console.error(`Failed to save ${t} instructions:`,s.cause),!1):(s.value?.instructions&&n(s.value.instructions),!0)},[e]),S=(0,s.useCallback)(e=>{r(),a(e)},[r,a]),M=(0,s.useCallback)(e=>{r(),l(e)},[r,l]),L=(0,s.useCallback)(async e=>!!p&&C(p,e),[p,C]);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{ref:b,className:"absolute bottom-full left-0 mb-2 w-80 max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 max-h-[70vh] overflow-y-auto",children:[(0,n.jsx)(n9,{label:i("chat.globalInstructions"),nodes:d,scope:"global",openGroupId:h?.scope==="global"?h.groupId:null,flyoutPosition:h?.scope==="global"?h.position:null,onOpenFlyout:k,onCloseFlyout:y,onKeepFlyout:N,onSave:C,onSelect:S,onInsert:M,management:!1,onManage:()=>{w(),f(null),g("global")}}),e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"border-t border-border"}),(0,n.jsx)(n9,{label:i("chat.projectInstructions"),nodes:u,scope:"project",openGroupId:h?.scope==="project"?h.groupId:null,flyoutPosition:h?.scope==="project"?h.position:null,onOpenFlyout:k,onCloseFlyout:y,onKeepFlyout:N,onSave:C,onSelect:S,onInsert:M,management:!1,onManage:()=>{w(),f(null),g("project")}})]})]}),p&&(0,n.jsx)(nX,{title:i("global"===p?"chat.editGlobalInstructions":"chat.editProjectInstructions"),nodes:"global"===p?d:u,onSave:L,onClose:()=>g(null)})]})}var se=r(96625),st=r(20235);let sr=(0,s.memo)(function({onSend:e,disabled:t,running:r,cwd:a,engine:l,onShowGitStatus:i,onShowComments:d,hasComments:c,onOpenNote:u,draft:m,setDraft:x,draftImages:h,setDraftImages:f,suggestion:p,sessionId:g}){let{t:b}=(0,o.Bd)(),v=(0,s.useState)(""),j=(0,s.useState)([]),[w,k]=void 0!==m&&x?[m,x]:v,[y,N]=void 0!==h&&f?[h,f]:j,[C,S]=(0,s.useState)(!1),M=(0,s.useRef)(null),L=(0,s.useRef)(null),E=(0,s.useCallback)(()=>{let e=M.current;if(!e)return;e.style.height="auto";let t=Math.max(38,Math.min(e.scrollHeight,200));e.style.height=`${t}px`},[]);(0,s.useLayoutEffect)(()=>{E()},[w,E]);let P=(0,s.useMemo)(()=>l&&"claude"!==l?[]:[{name:"/plan",description:"Enable plan mode (read-only). /plan <task> to plan a task; /plan off to disable.",source:"builtin",argumentHint:"[task|off]"}],[l]),T=(0,se.nJ)({value:w,onChange:k,textareaRef:M,extraCommands:P,selfSessionId:g}),$=(0,s.useCallback)(()=>{let r=w.trim();(r||y.length>0)&&!t&&(e(r,y.length>0?y:void 0),k(""),N([]),M.current&&(M.current.style.height="auto"))},[w,y,t,e]),R=(0,s.useCallback)(r=>{t||e(r)},[t,e]),I=(0,s.useCallback)(e=>{k(t=>{let r=t.replace(/\s+$/,"");return r?`${r}
34
+ ${e}`:e}),requestAnimationFrame(()=>{let e=M.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))})},[]),F=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&!T.handleKeyDown(e)){if("Tab"===e.key&&!e.shiftKey&&p&&!w){e.preventDefault(),k(p);return}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),$())}},[T,$,p,w,k]),B=(0,s.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let r=["image/png","image/jpeg","image/webp","image/gif"];for(let n of Array.from(t)){let t=r.find(e=>n.type===e);if(t){e.preventDefault();let r=n.getAsFile();if(!r)continue;if(r.size>5242880){alert(b("chat.imageSizeLimit",{size:(r.size/1024/1024).toFixed(2)}));continue}let s=new FileReader;s.onload=e=>{let r=e.target?.result;if(!r)return;let n=r.replace(/^data:image\/\w+;base64,/,""),s={id:`img-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,data:n,preview:r,media_type:t};N(e=>[...e,s])},s.readAsDataURL(r)}}},[b]),D=(0,s.useCallback)(e=>{N(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"bg-card relative",children:[(0,n.jsx)(nO,{images:y,onRemove:D,disabled:t}),(0,n.jsx)(se.V0,{ac:T,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64"}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[i&&(0,n.jsx)("button",{onClick:i,className:"p-2 text-brand hover:text-teal-10 hover:bg-brand/10 active:bg-brand/20 active:scale-95 rounded-lg transition-all",title:b("chat.viewGitChanges"),children:(0,n.jsxs)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"6",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"2",strokeWidth:2}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 8v10M18 8v4c0 2-2 4-6 4"})]})}),d&&(0,n.jsx)("button",{onClick:d,className:`p-2 rounded-lg transition-all active:scale-95 ${c?"text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted"}`,title:b("chat.viewAllComments"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})})}),u&&(0,n.jsx)("button",{onClick:u,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95 rounded-lg transition-all",title:b("chat.projectNotes"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}),(0,n.jsxs)("div",{className:"relative",ref:L,children:[(0,n.jsx)("button",{onClick:()=>S(!C),className:`p-2 rounded-lg transition-all ${C?"text-brand bg-brand/10":"text-muted-foreground hover:text-foreground hover:bg-hover active:bg-muted active:scale-95"}`,title:b("chat.quickInstructions"),children:(0,n.jsx)(nW.A,{className:"w-5 h-5"})}),C&&(0,n.jsx)(n7,{cwd:a,anchorRef:L,onClose:()=>S(!1),onSelect:R,onInsert:I})]}),(0,n.jsx)(st.s1,{textareaRef:M,matchLine:T.matchLine,value:w,onChange:e=>{k(e.target.value),T.trackCaret(e.target)},onSelect:e=>T.trackCaret(e.currentTarget),onKeyDown:F,onPaste:B,placeholder:t?b("chat.placeholderDisabled"):r?b("chat.placeholderRunning"):p||b("chat.placeholder"),rows:1,wrapperClassName:"flex-1 min-w-0",boxClassName:"px-4 py-2 border border-border rounded-lg",colorClassName:"bg-card text-foreground",className:"resize-none focus:outline-none focus:ring-2 focus:ring-ring"})]})]})});var sn=r(30577),ss=r(73103),so=r(97488),sa=r(20073),sl=r(41066),si=r(57125);let sd={CNY:"\xa5",USD:"$"};function sc({hasKey:e}){let{t}=(0,o.Bd)(),[r,a]=(0,s.useState)(!1),[l,i]=(0,s.useState)(null),[d,c]=(0,s.useState)(null),u=(0,s.useCallback)(async()=>{a(!0),c(null);let e=await x.t4.runPromiseExit((0,nv.he)());"Failure"===e._tag?(i(null),c(t("chat.balanceFailed",{defaultValue:"Query failed — check the API key"}))):i(e.value),a(!1)},[t]),m=l?l.balances.map(e=>`${sd[e.currency]??(e.currency?`${e.currency} `:"")}${e.totalBalance}`).join(" / "):"",h=!!(l&&!l.isAvailable);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[r&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!r&&d&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:d}),!r&&!d&&l&&(0,n.jsx)("span",{className:`text-xs font-mono ${h?"text-red-11":si.pe.deepseek}`,"data-tooltip":h?t("chat.balanceUnavailable",{defaultValue:"Account is not available for requests"}):void 0,"data-testid":"deepseek-balance-value",children:m||t("chat.balanceEmpty",{defaultValue:"No balance returned"})}),(0,n.jsx)("button",{type:"button","data-testid":"deepseek-balance-button",disabled:!e||r,onClick:u,"data-tooltip":e?void 0:t("chat.balanceNeedsKey",{defaultValue:"Set a DeepSeek API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:t("chat.checkBalance",{defaultValue:"Check balance"})}),(0,n.jsx)("a",{href:"https://platform.deepseek.com/usage",target:"_blank",rel:"noopener","data-testid":"deepseek-usage-link",title:t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),"aria-label":t("chat.openUsagePage",{defaultValue:"Open DeepSeek usage console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}let su={kimi:"https://www.kimi.com/code/console",glm:"https://bigmodel.cn/coding-plan/personal/usage"};function sm(e){let t=e.remaining??"?",r=e.limit??"?";return`${e.label} ${t}/${r}`}function sx({engine:e,hasKey:t}){let{t:r}=(0,o.Bd)(),[a,l]=(0,s.useState)(!1),[i,d]=(0,s.useState)(null),[c,u]=(0,s.useState)(null),m=(0,s.useCallback)(async()=>{l(!0),u(null);let t=await x.t4.runPromiseExit((0,nv.dM)(e));"Failure"===t._tag?(d(null),u(r("chat.quotaFailed",{defaultValue:"Quota unavailable — check the API key"}))):d(t.value),l(!1)},[r,e]),h=i?.windows??[],f=[i?.tier,...h.map(sm)].filter(Boolean).join(" \xb7 "),p=function(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:`${t.getMonth()+1}/${t.getDate()} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}(h.reduce((e,t)=>t.resetTime&&(!e||t.resetTime>e)?t.resetTime:e,null)),g=h.some(e=>0===e.remaining);return(0,n.jsxs)("div",{className:"ml-auto flex items-center gap-2",children:[a&&(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),!a&&c&&(0,n.jsx)("span",{className:"text-xs text-red-11",children:c}),!a&&!c&&i&&(0,n.jsx)("span",{className:`text-xs font-mono ${g?"text-red-11":si.pe[e]}`,"data-tooltip":p?r("chat.quotaResetAt",{defaultValue:"Resets {{time}}",time:p}):void 0,"data-testid":`${e}-quota-value`,children:f||r("chat.quotaEmpty",{defaultValue:"No quota returned"})}),(0,n.jsx)("button",{type:"button","data-testid":`${e}-quota-button`,disabled:!t||a,onClick:m,"data-tooltip":t?void 0:r("chat.quotaNeedsKey",{defaultValue:"Set an API key first"}),className:"px-2 py-0.5 text-xs rounded border border-border text-muted-foreground hover:bg-hover hover:text-foreground transition-colors disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent",children:r("chat.checkQuota",{defaultValue:"Check quota"})}),(0,n.jsx)("a",{href:su[e],target:"_blank",rel:"noopener","data-testid":`${e}-console-link`,title:r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),"aria-label":r("chat.openProviderConsole",{defaultValue:"Open the provider console"}),className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})})]})}var sh=r(67889),sf=r(46456);function sp(e){if(0===e.length)return"";let t=[tC.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===eN.Un),n=e.filter(e=>e.filePath!==eN.Un);for(let e of(n.length>0&&n.forEach((e,r)=>{let n=e.startLine>0||e.endLine>0?`:${e.startLine}-${e.endLine}`:"";t.push(`[${r+1}] ${e.filePath}${n}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(tC.A.t("comments.note",{content:e.content})),t.push("")}),r)){let r=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");t.push(r),e.content&&t.push(e.content),t.push("")}return t.join("\n").trim()}function sg({isOpen:e,onClose:t,cwd:r,onNavigateToComment:a}){let{t:l}=(0,o.Bd)(),i=(0,R.r)(),[d,c]=(0,s.useState)([]),[u,h]=(0,s.useState)(!1),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),k=(0,s.useCallback)(async()=>{if(!r)return;h(!0);let e=await x.t4.runPromiseExit((0,sf.$)(r));"Success"===e._tag?c(e.value.comments??[]):console.error("Failed to load comments:",e.cause),h(!1)},[r]);(0,s.useEffect)(()=>{e&&k()},[e,k]);let y=async e=>{let t=await x.t4.runPromiseExit((0,sf.Tu)(r,e));"Success"===t._tag?(c(t=>t.filter(t=>t.id!==e)),(0,eN.Cm)()):console.error("Failed to delete comment:",t.cause)},N=async e=>{g(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await x.t4.runPromiseExit((0,f.K)(r,e.filePath));if("Success"!==n._tag||!n.value.ok)throw Error("Failed to read file");t=(n.value.data?.content||"").split("\n").slice(e.startLine-1,e.endLine).join("\n")}let n={filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,content:e.content,codeContent:t},s=sp([n]);await navigator.clipboard.writeText(s),(0,M.oR)(l("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{g(null)}},C=async()=>{if(0!==d.length){v(!0);try{let e=await (0,eN.$3)(r),t=sp(e);await navigator.clipboard.writeText(t),(0,M.oR)(l("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{v(!1)}}},S=async()=>{if(0!==d.length&&i&&!i.isLoading&&!j){w(!0);try{let e=(await (0,eN.$3)(r)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0})),n=(0,eN.Gw)(e,"");i.sendMessage(n),await (0,eN.RP)(r),c([]),t()}catch(e){console.error("Failed to send comments to AI:",e)}finally{w(!1)}}},L=d.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let E=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-scrim p-4",onClick:t,children:(0,n.jsxs)("div",{className:"w-full max-w-2xl max-h-[80vh] bg-card border border-border rounded-lg shadow-lv3 flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border ",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:l("comments.allComments")}),d.length>0&&(0,n.jsx)("button",{onClick:C,disabled:b,className:"p-1 rounded hover:bg-hover text-muted-foreground disabled:opacity-50",title:l("comments.copyAllComments"),children:b?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 rounded hover:bg-hover text-muted-foreground",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:u?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:l("common.loading")}):0===d.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[(0,n.jsx)("svg",{className:"w-12 h-12 mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"})}),(0,n.jsx)("span",{children:l("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(L).map(([e,t])=>(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border",children:[(0,n.jsx)("span",{className:`text-sm font-medium text-foreground${e===eN.Un?"":" font-mono"}`,children:e===eN.Un?l("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",l("comments.nComments",{count:t.length}),")"]})]}),(0,n.jsx)("div",{className:"divide-y divide-border",children:t.map(e=>{var t;return(0,n.jsx)("div",{className:"px-3 py-2 hover:bg-hover cursor-pointer group",onClick:()=>a?.(e),children:(0,n.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[e.startLine>0||e.endLine>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-brand tabular-nums",children:[l("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",l("comments.linesCount",{count:e.endLine-e.startLine+1}),")"]})]}):e.selectedText?(0,n.jsxs)("span",{className:"text-xs text-muted-foreground italic truncate max-w-[200px]",children:["“",e.selectedText.slice(0,50),e.selectedText.length>50?"...":"","”"]}):null,(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:(t=e.updatedAt||e.createdAt)?new Date(t).toLocaleString("zh-CN",{month:"numeric",day:"numeric",hour:"2-digit",minute:"2-digit"}):""})]}),(0,n.jsx)("p",{className:"text-sm text-foreground line-clamp-2",children:e.content||(0,n.jsx)("span",{className:"text-muted-foreground italic",children:l("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),N(e)},disabled:p===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground transition-opacity disabled:opacity-50",title:l("common.copy"),children:p===e.id?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-hover text-muted-foreground hover:text-red-9 transition-opacity",title:l("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]})},e.id)})})]},e))})}),(0,n.jsxs)("div",{className:"px-4 py-3 border-t border-border flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:l("comments.totalComments",{count:d.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[i&&(0,n.jsx)("button",{onClick:S,disabled:0===d.length||i.isLoading||j,className:"px-3 py-1.5 text-sm bg-brand text-white rounded hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed",title:i.isLoading?l("comments.aiResponding"):void 0,children:j?l("comments.submitting"):l("comments.sendToAI")}),(0,n.jsx)("button",{onClick:async()=>{0===d.length||await (0,eN.RP)(r)&&c([])},disabled:0===d.length,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 disabled:opacity-50 disabled:cursor-not-allowed",children:l("comments.clearAll")})]})]})]})});return(0,n.jsx)(m.ZL,{children:E})}var sb=r(67183),sv=r(58453);let sj=`${sh.o.replace(" border-b border-border","")} pl-3 pr-20 bg-card/50`;function sw({tabId:e,initialCwd:t,initialSessionId:r,engine:i,onEngineChange:u,ollamaModel:m,onOllamaModelChange:h,deepseekModel:f,onDeepseekModelChange:p,kimiModel:g,onKimiModelChange:b,glmModel:v,onGlmModelChange:j,claudeModel:w,onClaudeModelChange:k,claudeEffort:y,onClaudeEffortChange:N,claudeFastMode:C,onClaudeFastModeChange:S,claudeThinking:L,onClaudeThinkingChange:E,codexModel:P,onCodexModelChange:T,codexReasoningEffort:$,onCodexReasoningEffortChange:R,grokModel:I,onGrokModelChange:F,grokReasoningEffort:B,onGrokReasoningEffortChange:D,planMode:A,onPlanModeChange:H,noHistory:W,onNoHistoryChange:z,hideHeader:O,hideSidebar:_,isActive:q=!0,isVisible:V=q,isFocused:U=q,peerTabId:K,peerSide:Q,refreshSignal:G,onLoadingChange:J,onDraftPresenceChange:Y,onSessionIdChange:X,onTitleChange:Z,onBotChange:ee,onShowGitStatus:et,onOpenNote:er,onOpenSession:en,onContentSearch:es,onShowFileDiff:eo,onOpenFileLink:ea,onOpenSessionBrowser:el,onOpenSettings:ei}){let ed,{t:ec}=(0,o.Bd)(),eu=(0,s.useContext)(l),[em,ex]=(0,s.useState)(""),[eh,ef]=(0,s.useState)([]),ep=(0,na.nH)(),[eg,eb]=(0,s.useState)(null),[ev,ej]=(0,s.useState)(!1),[ew,ek]=(0,s.useState)(!1),[ey,eC]=(0,s.useState)(!1),eS=function(e){let[t,r]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{if(!e)return void r(!1);let t=!1,n=async()=>{let n=await x.t4.runPromiseExit((0,sf.lb)(e));t||"Success"!==n._tag||r((n.value.comments?.length??0)>0)};n();let s=(0,eN.zL)(n);return()=>{t=!0,s()}},[e]),t}(t),[eM,eL]=(0,s.useState)(!1),[eE,eP]=(0,s.useState)(null),[eT,e$]=(0,s.useState)(!1),eR=A??eT,eI=(0,s.useCallback)(e=>{e$(e),H?.(e)},[H]),[eF,eB]=(0,s.useState)(!1),eD=W??eF,eA=(0,s.useCallback)(e=>{eB(e),z?.(e)},[z]),[eH,eW]=(0,s.useState)(!1),ez=(0,s.useRef)(null),eO=(0,s.useRef)(null),e_=(0,s.useCallback)(async e=>{if(!t)return;let r=await x.t4.runPromiseExit((0,nj.iS)(t,e));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?("number"==typeof r.value.titleRevision&&(0,nh.X4)({...r.value,cwd:t,sessionId:e}),Z?.((0,nh.iM)((0,nh.V6)(),t,e,r.value.title,r.value.titleRevision))):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,Z]),[eq,eV]=(0,s.useState)(!1),[eU,eK]=(0,s.useState)(null),[eQ,eG]=(0,s.useState)(null),[eJ,eY]=(0,s.useState)(nD.R),eX=(0,s.useMemo)(()=>(0,nA.hC)(),[]),eZ=(0,s.useRef)(!1);(0,s.useEffect)(()=>{eZ.current=eq},[eq]);let{messages:e0,recoveryCopies:e1,onRecoveryDeleted:e2,onRecoveryDismissed:e5,setMessages:e4,onLiveSnapshotStart:e3,onWriterIdle:e6,setRunMessages:e8,onRunAccepted:e9,onSendFailure:e7,onInputRejected:te,onLiveRunEnd:tt,onSenderStart:tr,isLoadingHistory:tn,isLoadingMore:ts,hasMoreHistory:to,loadMoreHistory:ta,ensureTurnLoaded:tl,cancelTurnLoad:ti,loadHistoryByCwdAndSessionId:td,loadedSessionId:tc,loadedEngine:tu,loadedModel:tm,loadedBot:tx}=(0,nB.m)(eg,{cwd:t,initialSessionId:r,onSessionId:eb,onTitleChange:Z,onTokenUsage:eP,enabled:V,liveRunning:eq}),th=tu??i??void 0;(0,s.useEffect)(()=>{ee?.(tx)},[tx,ee]);let tf=!th||"claude"===th,tp="codex"===th,tg=w??a.BV,tb=(0,a.NR)(tg,y),tv=P??a.kn,tj=I??("grok"===tu?tm??void 0:void 0),tw=(0,a.oJ)(tv,$),tk="deepseek"===th||"kimi"===th||"glm"===th?th:null,ty="kimi"===tk?g:"glm"===tk?v:f,tN=(0,sl.X)(th,"ollama"===th?m:ty,t,eg,eH),tC="kimi"===tk?b:"glm"===tk?j:p,tS="ollama"===th||null!==tk||tf||tp||"grok"===th;(0,s.useEffect)(()=>{tu&&i!==tu&&u?.(tu)},[i,tu,u]);let tM=(0,s.useRef)({ollama:h,deepseek:p,kimi:b,glm:j});tM.current={ollama:h,deepseek:p,kimi:b,glm:j},(0,s.useEffect)(()=>{if(!tm||!tu)return;let e=tM.current;tu in e&&e[tu]?.(tm)},[tc,tm,tu]);let{drainingSubscriptions:tL,isLoading:tE,tokenUsage:tP,liveOutputTokens:tT,runningStartedAt:t$,rateLimitInfo:tR,apiRetryInfo:tI,backgroundTasks:tF,promptSuggestion:tA,handleSend:tH,handleStop:tW,injectMessage:tz}=(0,nD.e)(e0,e8,{sessionId:eg,cwd:t,engine:th,planMode:eR,noHistory:eD,ollamaModel:m,engineModel:ty,piThinkingLevel:tN.level,claudeModel:tg,claudeEffort:tb,claudeFastMode:C,claudeThinking:L,codexModel:tv,grokModel:tj,codexReasoningEffort:tw,grokReasoningEffort:B,onSessionId:eb,onFetchTitle:e_,onSendStart:tr,onRunAccepted:e9,onSendFailure:e7,onInputRejected:te,onRunEnd:tt,onRecoveryDeleted:e2,taskStore:eX}),tO=(tf||tp||"grok"===th||["ollama","deepseek","kimi","glm"].includes(th??""))&&!!(tc||eg),t_=(0,s.useCallback)((e,t,r)=>{ez.current?.pinNextUserMessage();let n=tc||eg;return tO&&n&&(tE||eZ.current)?tz(e,t,n).catch(t=>{ex(t=>t||e),(0,M.oR)(t instanceof Error?t.message:String(t),"error")}):tH(e,t,r)},[tH,tz,tO,tE,tc,eg]),tq=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(tf){let t=/^\/plan(?:\s+([\s\S]*))?$/.exec(e.trim());if(t){let e=(t[1]??"").trim();"off"===e.toLowerCase()?(eI(!1),(0,M.oR)(ec("chat.planModeOff",{defaultValue:"Plan mode off"}),"info")):""===e?(eI(!0),(0,M.oR)(ec("chat.planModeOn",{defaultValue:"Plan mode on"}),"success")):(eI(!0),t_(e,r,{permissionMode:"plan"}));return}}if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void t_(e,r);let o=e.split("\n").slice(1).join("\n").trim(),a=await x.t4.runPromiseExit((0,nv.JC)({command:s,cwd:t}));if("Success"===a._tag){let e=a.value,t=[e.stdout,e.stderr].filter(Boolean).join("\n")||"(no output)",n=ec("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
35
+
36
+ ${o}`),t_(n,r)}else t_(ec("chat.executedCommandFailed",{command:s,error:a.cause}),r);return}t_(e,r)},[t_,t,ec,tf,eI]),tV=(0,s.useCallback)(()=>{eI(!1),t_(ec("chat.approvePlanPrompt",{defaultValue:"已批准,按上述计划开始执行。"}),void 0,{permissionMode:null})},[t_,eI,ec]),tU=tc||eg,tK=V&&!tE&&!!tU;(0,nb.u)(tU,e8,tK,th,{onSnapshotStart:e3,onWriterIdle:e6,onRunEnd:tt,onRecoveryDeleted:e2,onRunningChange:e=>{eZ.current=e,eV(e)},onLiveOutputTokens:eK,onRunStartedAt:eG,onBackgroundTasks:e=>eY(e.length?e:nD.R),taskStore:eX}),(0,s.useEffect)(()=>{tK||(eV(!1),eK(null),eG(null),eY(nD.R))},[tK]);let tQ=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!G||G.nonce===tQ.current)return;tQ.current=G.nonce;let e=eg||tc;!t||!e||G.sessionId!==eg&&G.sessionId!==tc||tE||eq||td(t,e,!0,10,void 0,!0)},[G,eg,tc,t,tE,eq,td]);let[tG,tJ]=(0,s.useState)(!1),tY=(0,s.useCallback)(()=>tJ(!0),[]),tX=(0,s.useCallback)(()=>tJ(!1),[]),[tZ,t0]=(0,s.useState)(null),t1=eg||tc,t2=tE||eq;(0,s.useEffect)(()=>{if(!t||!t1||t2)return;let e=`${t}\0${t1}`,r=!1;return x.t4.runPromiseExit((0,nv.Ay)(t,t1)).then(t=>{r||"Success"!==t._tag||t0({key:e,value:t.value.contextWindow})}),()=>{r=!0}},[t,t1,t2]);let t5=tZ&&tZ.key===`${t}\0${t1}`?tZ.value:null,t4=tP||eE,t3=tE?tT:eq?eU:null,t6=tE?t$:eq?eQ:null,t8=tE?tF:eq?eJ:nD.R;(0,s.useEffect)(()=>{eg&&X?.(eg)},[eg,X]);let t9=em.trim().length>0||eh.length>0;(0,s.useEffect)(()=>{if(t9&&Y)return Y(!0),()=>Y(!1)},[t9,Y]);let t7=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(J?.(tE),t7.current&&!tE&&t&&eg){let e;for(let t=e0.length-1;t>=0;t--)if("user"===e0[t].role&&e0[t].content){e=(0,sv.e9)((0,sb.a)(e0[t].content)).slice(0,100);break}(0,tB.F)(tD.n.SessionComplete,{cwd:t,sessionId:eg,lastUserMessage:e})}t7.current=tE},[tE,J,t]),(0,s.useEffect)(()=>{if(e&&ep&&(ep.setChatLoading(e,q&&tE&&!tO),q))return()=>{ep.setChatLoading(e,!1)}},[e,tE,q,ep,tO]),(0,s.useEffect)(()=>{if(e&&ep)return ep.registerChat(e=>{eO.current?.(e)},e),()=>{ep.unregisterChat(e)}},[e,ep]),(0,s.useEffect)(()=>{e&&q&&U&&ep&&ep.setActiveTab(e)},[e,q,U,ep]),(0,s.useEffect)(()=>{eO.current=tq},[tq]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&ev&&(tE||eq)&&tW()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[ev,tE,eq,tW]);let re=(0,s.useCallback)(async(e,r)=>{let n=tc??eg;if(!t||!n)return;let s=await x.t4.runPromiseExit((0,nv.Zr)(n,{cwd:t,fromMessageUuid:e,scope:r}));if("Success"===s._tag&&s.value.newSessionId){let e=s.value.newSessionId;en?en(e,"single"===r?"Excerpt":"Fork"):(0,tB.F)(tD.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===s._tag&&(console.error("Fork failed:",s.cause),(0,M.oR)("single"===r?ec("toast.excerptFailed",{defaultValue:"Failed to excerpt this turn"}):ec("toast.forkFailed",{defaultValue:"Failed to fork session"}),"error"))},[t,tc,eg,en,ec]),rt=(0,s.useRef)(re);rt.current=re;let rr=(0,s.useRef)((e,t)=>rt.current(e,t)).current,rn=(0,s.useCallback)(async e=>{let r=tc??eg;if(!t||!r||tE||eq)return;let n=Math.max(10,(0,nf.l)(e0).length),s=await x.t4.runPromiseExit((0,nv.$N)(r,{cwd:t,messageUuid:e}));"Success"===s._tag?(s.value.recoveryDeletion&&e2(s.value.recoveryDeletion),e4(t=>(0,nf.T)(t,e)),await td(t,r,!1,n,void 0,!0),(0,M.oR)(ec("toast.turnDeleted",{defaultValue:"Turn deleted"}),"success")):(console.error("Delete turn failed:",s.cause),(0,M.oR)(ec("toast.deleteTurnFailed",{defaultValue:"Failed to delete this turn"}),"error"))},[t,tc,eg,tE,eq,e0,td,e2,ec]),rs=(0,s.useRef)(rn);rs.current=rn;let ro=(0,s.useRef)(e=>rs.current(e)).current,ra=(0,s.useCallback)(e=>{if(K&&ep){if(!ep.sendToTab(K,e))return void(0,M.oR)(ec("toast.sendToPeerFailed",{defaultValue:"Failed to send to the other pane"}),"error");(0,M.oR)(ec("toast.sentToPeer",{defaultValue:"Sent to the other pane"}),"success")}},[K,ep,ec]),rl=(0,s.useRef)(ra);rl.current=ra;let ri=(0,s.useRef)(e=>rl.current(e)).current,rd=(0,s.useCallback)(()=>{eC(!0)},[]),rc=(0,s.useCallback)(()=>{eL(!0)},[]),ru=function(e,t,r,n,o,a){let l=(0,s.useRef)(t);(0,s.useLayoutEffect)(()=>{l.current=t},[t]);let i=(0,s.useRef)(null),[d,c]=(0,s.useState)(0),u=(0,s.useCallback)(()=>{a?.(),i.current?.finish({status:"cancelled"}),i.current=null},[a]);(0,s.useLayoutEffect)(()=>u,[e,u]),(0,s.useLayoutEffect)(()=>{let e=i.current;if(!e||e.loading||!r)return;let t=requestAnimationFrame(()=>{if(i.current!==e)return;let t=nF(l.current,e.target,e.id),r=t?o(t.id)?"scrolled":"failed":e.target.sourceRef&&!e.target.sourceRef.sourceId?"stale":"missing";e.finish({status:r}),i.current=null});return()=>cancelAnimationFrame(t)},[t,r,d,o]);let m=(0,s.useCallback)(e=>(u(),new Promise(t=>{let r={id:e.id,loading:!0,target:e,finish:t};i.current=r;let s=nF(l.current,e);(s?Promise.resolve({status:"ready",messageId:s.id}):n(e.turnIndex,e.sourceRef)).then(n=>{if(i.current===r){if("ready"!==n.status){i.current=null,t(n);return}r.id=n.messageId??e.id,r.loading=!1,c(e=>e+1)}},()=>{i.current===r&&(i.current=null,t({status:"failed"}))})})),[n,u]);return(0,s.useMemo)(()=>Object.assign(m,{cancel:u}),[m,u])}(`${t}:${tc??eg}`,e0,q,tl,(0,s.useCallback)(e=>ez.current?.scrollToMessage(e)??!1,[]),ti),rm=(0,s.useCallback)(()=>{ru.cancel(),eL(!1)},[ru]),rx=(0,s.useCallback)(async e=>{let t=await ru(e);return"scrolled"!==t.status&&"cancelled"!==t.status&&(0,M.oR)(ec("chat.messageNavigationFailed",{defaultValue:"The message could not be located. Refresh the message list and try again."}),"error"),t},[ru,ec]),rh=tS?(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":ec("chat.noHistoryDesc",{defaultValue:"each prompt is independent"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"nohistory-toggle",checked:eD,onChange:e=>eA(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${eD?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(np.A,{className:"w-3.5 h-3.5"}),ec("chat.noHistory",{defaultValue:"No history context"})]})]}):null;return(0,n.jsxs)(nA.I$.Provider,{value:eX,children:[tL,(0,n.jsxs)("div",{className:`flex ${O&&_?"h-full":"h-screen"} bg-card`,children:[(0,n.jsxs)("div",{id:"chat-screen",className:"flex-1 flex flex-col min-w-0 relative",onMouseEnter:()=>ej(!0),onMouseLeave:()=>ej(!1),children:[!O&&(0,n.jsx)(nk,{cwd:t,sessionId:eg,engine:th,onOpenProjectSessions:()=>ek(!0),onOpenSessionBrowser:el,onOpenSettings:ei}),(tf||tp)&&(0,n.jsxs)("div",{className:sj,children:[(0,n.jsx)(a.Yd,{engine:tp?"codex":"claude",claudeModel:tg,onClaudeModelChange:k,claudeEffort:tb,onClaudeEffortChange:N,claudeFastMode:C,onClaudeFastModeChange:S,claudeThinking:L,onClaudeThinkingChange:E,codexModel:tv,onCodexModelChange:T,codexReasoningEffort:tw,onCodexReasoningEffortChange:R}),tf&&(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs cursor-pointer select-none","data-tooltip":ec("chat.planModeDesc",{defaultValue:"read-only \xb7 plan first, no edits"}),children:[(0,n.jsx)("input",{type:"checkbox","data-testid":"planmode-toggle",checked:eR,onChange:e=>eI(e.target.checked),className:"peer sr-only"}),(0,n.jsx)("span",{"aria-hidden":"true",className:"relative inline-flex h-4 w-7 shrink-0 items-center rounded-full bg-muted-foreground/30 transition-colors peer-checked:bg-brand peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-ring",children:(0,n.jsx)("span",{className:`h-3 w-3 rounded-full bg-white shadow-sm transition-transform ${eR?"translate-x-3.5":"translate-x-0.5"}`})}),(0,n.jsxs)("span",{className:"flex items-center gap-1.5 text-foreground",children:[(0,n.jsx)(ng.A,{className:"w-3.5 h-3.5"}),ec("chat.planMode",{defaultValue:"Plan mode"})]})]}),rh]}),"grok"===th&&(0,n.jsxs)("div",{className:sj,children:[(0,n.jsx)(ss.k,{model:tj,onModelChange:F,reasoningEffort:B,onReasoningEffortChange:D}),rh]}),"ollama"===th&&(0,n.jsxs)("div",{className:sj,children:[h&&(0,n.jsx)(sn.m,{currentModel:m,onModelChange:h}),(0,n.jsx)(sa.u,{...tN}),rh]}),tk&&(0,n.jsxs)("div",{className:sj,children:[tC&&(0,n.jsx)(so.Z,{engine:tk,currentModel:ty,onModelChange:tC,onHasKeyChange:eW}),(0,n.jsx)(sa.u,{...tN}),rh,(0,n.jsx)("div",{className:"ml-auto pl-2",children:"deepseek"===tk?(0,n.jsx)(sc,{hasKey:eH}):(0,n.jsx)(sx,{engine:tk,hasKey:eH})})]}),tn?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:ec("sessions.loadingHistory")})}):(0,n.jsx)(nH.M,{ref:ez,snapshotsEnabled:V,messages:e0,recoveryCopies:e1,onDismissRecoveryCopy:e5,isLoading:tE||eq,liveOutputTokens:t3,runningStartedAt:t6,cwd:t,sessionId:eg,engine:th,botName:tx,apiRetryInfo:tI,backgroundTasks:t8,hasMoreHistory:to,isLoadingMore:ts,onLoadMore:ta,onFork:rr,onDeleteTurn:ro,onSendToPeer:ri,peerSide:Q,isActive:q,onContentSearch:es,onShowFileDiff:eo,onOpenFileLink:ea,onApprovePlan:tV,onShowUserMessages:rc}),t4&&(0,n.jsx)(nN,{tokenUsage:t4,rateLimitInfo:tR,onOpenContext:tY,contextWindow:t5}),(0,n.jsx)(n$,{isOpen:tG,onClose:tX,cwd:t,sessionId:eg||tc}),eu&&!U?null:(ed=(0,n.jsx)(sr,{onSend:tq,disabled:(tE||eq)&&!tO,running:tE||eq,cwd:t,engine:th,onShowGitStatus:et,onShowComments:t?rd:void 0,hasComments:eS,onOpenNote:er,draft:em,setDraft:ex,draftImages:eh,setDraftImages:ef,suggestion:tA,sessionId:tc||eg||void 0}),eu?(0,c.createPortal)(ed,eu):ed)]}),!O&&t&&(0,n.jsx)(d.Q,{isOpen:ew,onClose:()=>ek(!1),cwd:t}),t&&(0,n.jsx)(sg,{isOpen:ey,onClose:()=>eC(!1),cwd:t}),(0,n.jsx)(nI,{isOpen:eM,onClose:rm,cwd:t,sessionId:tc??eg,onSelectMessage:rx})]})]})}function sk({tabId:e,cwd:t,sessionId:r,engine:o,onEngineChange:a,ollamaModel:l,onOllamaModelChange:i,deepseekModel:d,onDeepseekModelChange:c,kimiModel:u,onKimiModelChange:m,glmModel:x,onGlmModelChange:h,claudeModel:f,onClaudeModelChange:p,claudeEffort:g,onClaudeEffortChange:b,claudeFastMode:v,onClaudeFastModeChange:j,claudeThinking:w,onClaudeThinkingChange:k,codexModel:y,onCodexModelChange:N,codexReasoningEffort:C,onCodexReasoningEffortChange:S,grokModel:M,onGrokModelChange:L,grokReasoningEffort:E,onGrokReasoningEffortChange:P,planMode:T,onPlanModeChange:$,noHistory:R,onNoHistoryChange:I,isActive:F,isVisible:B,isFocused:D,peerTabId:A,peerSide:H,refreshSignal:W,onDraftChange:z,onStateChange:O,onShowGitStatus:_,onOpenNote:q,onOpenSession:V,onContentSearch:U,onShowFileDiff:K,onOpenFileLink:Q}){let G=(0,s.useCallback)(t=>{O(e,{isLoading:t})},[e,O]),J=(0,s.useCallback)(t=>{z?.(e,t)},[e,z]),Y=(0,s.useCallback)(t=>{O(e,{sessionId:t})},[e,O]),X=(0,s.useCallback)(t=>{O(e,{title:t})},[e,O]),Z=(0,s.useCallback)(t=>{O(e,{bot:t??void 0})},[e,O]),ee=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]),et=(0,s.useCallback)(t=>{i?.(e,t)},[e,i]),er=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]),en=(0,s.useCallback)(t=>{m?.(e,t)},[e,m]),es=(0,s.useCallback)(t=>{h?.(e,t)},[e,h]),eo=(0,s.useCallback)(t=>{p?.(e,t)},[e,p]),ea=(0,s.useCallback)(t=>{b?.(e,t)},[e,b]),el=(0,s.useCallback)(t=>{j?.(e,t)},[e,j]),ei=(0,s.useCallback)(t=>{k?.(e,t)},[e,k]),ed=(0,s.useCallback)(t=>{N?.(e,t)},[e,N]),ec=(0,s.useCallback)(t=>{L?.(e,t)},[e,L]),eu=(0,s.useCallback)(t=>{S?.(e,t)},[e,S]),em=(0,s.useCallback)(t=>{P?.(e,t)},[e,P]),ex=(0,s.useCallback)(t=>{$?.(e,t)},[e,$]),eh=(0,s.useCallback)(t=>{I?.(e,t)},[e,I]);return(0,n.jsx)(sw,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,onEngineChange:ee,ollamaModel:l,onOllamaModelChange:et,deepseekModel:d,onDeepseekModelChange:er,kimiModel:u,onKimiModelChange:en,glmModel:x,onGlmModelChange:es,claudeModel:f,onClaudeModelChange:eo,claudeEffort:g,onClaudeEffortChange:ea,claudeFastMode:v,onClaudeFastModeChange:el,claudeThinking:w,onClaudeThinkingChange:ei,codexModel:y,grokModel:M,onCodexModelChange:ed,onGrokModelChange:ec,codexReasoningEffort:C,grokReasoningEffort:E,onCodexReasoningEffortChange:eu,onGrokReasoningEffortChange:em,planMode:T,onPlanModeChange:ex,noHistory:R,onNoHistoryChange:eh,hideHeader:!0,hideSidebar:!0,isActive:F,isVisible:B,isFocused:D,peerTabId:A,peerSide:H,refreshSignal:W,onLoadingChange:G,onDraftPresenceChange:z?J:void 0,onSessionIdChange:Y,onTitleChange:X,onBotChange:Z,onShowGitStatus:_,onOpenNote:q,onOpenSession:V,onContentSearch:U,onShowFileDiff:K,onOpenFileLink:Q})}var sy=r(69895),sN=r(23121),sC=r(88292),sS=r(76900);function sM(e,t){if(!t.split)return{};let r=t.panes.indexOf(e);return -1===r?{}:{peerTabId:t.panes[1-r],peerSide:0===r?"right":"left"}}function sL({tabId:e,panes:t,activePane:r,row:s,maximized:a,onFocusPane:l,onClosePane:i,onToggleMaximize:d,layoutToggle:c,children:u}){let{t:m}=(0,o.Bd)(),x=t.indexOf(e),h=t.length>1;return(0,n.jsxs)("div",{onMouseDownCapture:h?()=>l(x):void 0,style:s&&-1!==x&&!a?{order:x}:void 0,className:`group/pane ${function(e,t,r,n,s){let o=t.indexOf(e);if(-1===o)return"relative hidden";if(s)return"absolute inset-0 z-30 border-y border-y-transparent";if(!n)return"relative h-full block";let a=t.length>1?` border-y ${o===r?"border-y-brand":"border-y-transparent"}`:"";return`relative h-full flex-1 min-w-0${a}${o>0?" border-l border-border":""}`}(e,t,r,s,a)}`,children:[(c||h&&-1!==x)&&(0,n.jsxs)("div",{className:"absolute top-1 right-1 z-20 flex items-center gap-0.5",children:[h&&-1!==x&&(0,n.jsxs)("div",{className:"flex items-center gap-0.5 opacity-0 pointer-events-none transition-opacity focus-within:opacity-100 focus-within:pointer-events-auto group-hover/pane:opacity-100 group-hover/pane:pointer-events-auto",children:[(0,n.jsx)("button",{type:"button",onClick:()=>d(x),title:m(a?"chat.restorePane":"chat.maximizePane"),"aria-label":m(a?"chat.restorePane":"chat.maximizePane"),"aria-pressed":a,className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:a?(0,n.jsx)(nm.A,{className:"w-3.5 h-3.5"}):(0,n.jsx)(nx.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{type:"button",onClick:()=>i(x),title:m("chat.closePane"),"aria-label":m("chat.closePane"),className:"flex items-center justify-center w-6 h-6 text-muted-foreground transition-colors hover:text-foreground",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),c]}),u]})}function sE({initialCwd:e,initialSessionId:t,initialBlank:r,initialView:l,initialFile:c,initialBubble:u}){let{t:h}=(0,o.Bd)(),[f,p]=(0,s.useState)(l??"agent"),[g,b]=(0,s.useState)(null),{tabs:v,titlesLoading:j,activeTabId:w,activeTab:k,paneTabIds:y,activePane:N,toggleSideBySide:C,focusPane:S,closePane:M,unreadTabs:L,globalLoadingTabs:E,pageVisible:P,dragTabIndex:T,dragOverTabIndex:$,closeTab:R,closeAllTabs:I,switchTab:F,handleSelectSession:B,handleNewTab:D,handleNewCodexTab:A,handleNewGrokTab:H,handleNewKimiTab:W,handleNewGlmTab:z,handleNewOllamaTab:O,handleNewDeepseekTab:_,handleOpenSession:q,updateTabState:V,updateTabEngine:U,updateTabOllamaModel:K,updateTabDeepseekModel:Q,updateTabKimiModel:G,updateTabGlmModel:J,updateTabClaudeModel:Y,updateTabClaudeEffort:X,updateTabClaudeFastMode:Z,updateTabClaudeThinking:ee,updateTabCodexModel:er,updateTabGrokModel:en,updateTabCodexReasoningEffort:es,updateTabGrokReasoningEffort:eo,updateTabPlanMode:ea,updateTabNoHistory:el,handleTabDragStart:ei,handleTabDragOver:ed,handleTabDrop:ec,handleTabDragEnd:eu}=(0,nd.useTabState)({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:f}),{isPinned:em,pinSession:ex,unpinSession:ef}=(0,sy.P)(),{createTask:ep}=(0,sN.nS)(),eg=(0,s.useCallback)(e=>{let t=v.find(t=>t.id===e);return!!t?.sessionId&&em(t.sessionId)},[v,em]),eb=(0,s.useCallback)(t=>{let r=v.find(e=>e.id===t);r?.sessionId&&(em(r.sessionId)?ef(r.sessionId):ex(r.sessionId,r.cwd||e||"",r.title))},[v,em,ex,ef,e]),ev=(0,s.useCallback)((t,r)=>{let n=v.find(e=>e.id===t),s=n?.cwd||e;if(n&&s){var o;let e,l;ep({...r,...(l="grok"===(e=(o={...n,cwd:s,tabId:t}).engine)?o.grokModel:"ollama"===e?o.ollamaModel:"kimi"===e?o.kimiModel:"glm"===e?o.glmModel:"deepseek"===e?o.deepseekModel:"codex"===e?o.codexModel??a.kn:o.claudeModel??a.BV,{cwd:o.cwd,tabId:o.tabId,sessionId:o.sessionId??crypto.randomUUID(),engine:e,...l&&{model:l}})})}},[v,e,ep]),[ej,ew]=(0,s.useState)(!1),[ek,ey]=(0,s.useState)(!1),[eN,eC]=(0,s.useState)(!1),[eS,eM]=(0,s.useState)(null),[eL,eE]=(0,s.useState)(!1),[eP,eT]=(0,s.useState)("tree"),[e$,eR]=(0,s.useState)(0),[eI,eF]=(0,s.useState)(null),[eB,eD]=(0,s.useState)(0),[eA,eH]=(0,s.useState)(c?{path:c,nonce:0}:null),[eW,ez]=(0,s.useState)(u?{commandId:u,nonce:0}:null),eO=(0,s.useRef)(()=>{}),[e_,eq]=(0,s.useState)(null),eV=null!==e_,eU=(0,s.useMemo)(()=>{let e;return{panes:e=eV?[w]:y,activePane:eV?0:N,row:e.length>1||eV,split:e.length>1,diffOrder:e.length}},[y,N,w,eV]),[eK,eQ]=(0,s.useState)(null),[eG,eJ]=(0,s.useState)();(0,s.useEffect)(()=>{window.parent.postMessage({type:"GET_PROJECT_NUMBER",cwd:e},"*")},[e]),(0,s.useEffect)(()=>{e&&!l&&x.t4.runPromiseExit((0,sS.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&p(t.activeView)}})},[e,l]);let[eY,eX]=(0,s.useState)(!1),eZ=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(eZ.current=f,p("console"),eX(!0)):(eX(!1),eZ.current&&"console"!==eZ.current&&p(eZ.current),eZ.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[f]);let e0=(0,s.useCallback)(t=>{p(t),e&&(x.t4.runFork((0,sS.Yn)({cwd:e,settings:{activeView:t}}).pipe(eh.NWQ(()=>eh.rIH))),x.t4.runFork(eh.qIB(sC.d,r=>r.publish(tD.n.ViewChange,{cwd:e,view:t}))))},[e]);(0,s.useEffect)(()=>{let e=()=>e0("console");return window.addEventListener("console-open-browser",e),()=>window.removeEventListener("console-open-browser",e)},[e0]);let e1=(0,s.useCallback)(async()=>{if(!e)return;let t=await x.t4.runPromiseExit((0,sS.b2)(e));if("Success"===t._tag){let r=t.value;if(eE(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&eM(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>e1())},[e1]);let e2=(0,s.useCallback)(e=>{let{data:t}=e;Array.isArray(t)&&t.some(e=>"git"===e.type)&&e1()},[e1]);(0,et.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:e2,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),e0("agent")):"2"===e.key?(e.preventDefault(),e0("explorer")):"3"===e.key?(e.preventDefault(),e0("console")):"s"===e.key&&e.preventDefault())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{e&&window.parent!==window&&window.parent.postMessage({type:"SESSION_NUMBERS",cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*")},[e,v]);let e5=(0,s.useRef)(new Set),[e4,e3]=(0,s.useState)(!1),e6=(0,s.useCallback)((e,t)=>{let r=e5.current;t?r.add(e):r.delete(e),e3(r.size>0)},[]);(0,s.useEffect)(()=>{e&&window.parent!==window&&window.parent.postMessage({type:"PROJECT_DRAFT",cwd:e,hasDraft:e4},"*")},[e,e4]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="PROJECT_NUMBER"&&"number"==typeof t.data?.projectNumber)return void eJ(t.data.projectNumber);if(t.data?.type==="IFRAME_VISIBILITY"&&"number"==typeof t.data?.projectNumber&&eJ(t.data.projectNumber),t.data?.type==="GET_SESSION_NUMBERS"&&t.data?.requestId&&e)return void window.parent.postMessage({type:"SESSION_NUMBERS",requestId:t.data.requestId,cwd:e,sessionIds:v.map(e=>e.sessionId??null)},"*");if(t.data?.type==="SWITCH_SESSION"){let{sessionId:e,switchToAgent:r}=t.data;e&&(B(e),r&&e0("agent"),v.find(t=>t.sessionId===e)&&eQ(t=>({sessionId:e,nonce:(t?.nonce??0)+1})))}t.data?.type==="OPEN_FILE"&&"string"==typeof t.data?.path&&eO.current({path:t.data.path}),t.data?.type==="FOCUS_CONSOLE_BUBBLE"&&"string"==typeof t.data?.commandId&&(e0("console"),ez(e=>({commandId:t.data.commandId,nonce:(e?.nonce??0)+1})))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[B,e0,e,v]);let e8=(0,s.useCallback)(()=>{eT("status"),eR(e=>e+1),e0("explorer")},[e0]),e9=(0,s.useCallback)(e=>{eF(e),eD(e=>e+1),e0("explorer")},[e0]),e7=(0,s.useCallback)(()=>e0("agent"),[e0]),[te,tt]=(0,s.useState)(!1);(0,s.useEffect)(()=>{eV||tt(!1)},[eV]);let[tr,tn]=(0,s.useState)(!1),ts=tr&&eU.split?eU.panes[eU.activePane]??null:null;(0,s.useEffect)(()=>{eU.split||tn(!1)},[eU.split]);let to=(0,s.useCallback)(e=>{tn(e=>!e),S(e)},[S]),ta=(0,s.useCallback)(()=>tt(e=>!e),[]),tl=(0,s.useCallback)(()=>eq(null),[]),ti=(0,s.useRef)(null),td=(0,s.useCallback)(e=>{let t=ti.current;if(!t)return;let r=e.offset>0&&null!==e.target&&t.contains(e.target);if("move"===e.phase){if(!r)return;let n=Math.min(.5*e.offset,t.offsetWidth);t.style.transition="none",t.style.transform=`translateX(${n}px)`;return}r&&e.triggered?(t.style.transition="transform 140ms ease-out, opacity 140ms ease-out",t.style.transform="translateX(100%)",t.style.opacity="0",window.setTimeout(tl,140)):(t.style.transition="transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1)",t.style.transform="")},[tl]);(0,s.useEffect)(()=>{let e=ti.current;e&&(e.style.transition="",e.style.transform="",e.style.opacity="")},[e_]);let tc=(0,s.useRef)(eV);(0,s.useEffect)(()=>{tc.current=eV},[eV]);let tu=(0,s.useRef)(ts);(0,s.useEffect)(()=>{tu.current=ts},[ts]);let tm=(0,s.useCallback)(()=>{tc.current?tl():null!==tu.current?tn(!1):C()},[C,tl]),tx=ts??eU.panes[eU.panes.length-1],th=(0,s.useMemo)(()=>{let e=eU.split?h("chat.singlePane"):h("chat.splitPane");return(0,n.jsx)("button",{type:"button",onClick:tm,title:e,"aria-label":e,"aria-pressed":eU.split,className:"flex items-center justify-center w-6 h-6 rounded text-muted-foreground transition-colors hover:text-foreground hover:bg-hover",children:(0,n.jsxs)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",strokeWidth:2}),!eU.split&&(0,n.jsx)("path",{strokeWidth:2,d:"M12 4v16"})]})})},[eU.split,tm,h]),tf=(0,s.useCallback)((e,t,r,n,s)=>{eq(o=>{var a;return a={messageId:e,toolCalls:t,cwd:r,sessionId:n},!0!==s?a:o?.messageId!==a.messageId?o:{...o,toolCalls:a.toolCalls}}),s||e0("agent")},[e0]),tp=(0,s.useCallback)(e=>{eH({...e,nonce:Date.now()}),e0("explorer")},[e0]);(0,s.useEffect)(()=>{eO.current=tp},[tp]);let tg=(0,s.useCallback)(()=>{e&&x.t4.runFork(eh.qIB(sC.d,t=>t.publish(tD.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(na.k_,{children:(0,n.jsx)(tR.fY,{activeView:f,onViewChange:e0,onOverscroll:td,children:(0,n.jsxs)("div",{className:"flex h-screen bg-card",children:[(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,n.jsx)(nc.TabManagerTopBar,{initialCwd:e,activeTab:k,isGitRepo:eL,currentBranch:eS,onOpenWorktree:()=>ey(!0),onOpenAliasManager:()=>eC(!0),onBranchSwitched:e1}),eY&&(0,n.jsxs)("div",{className:"flex items-center justify-center gap-2 py-1 bg-brand/15 text-brand text-xs font-medium border-b border-brand/20",children:[(0,n.jsx)("span",{className:"animate-pulse",children:"●"}),h("console.screenshotting")]}),e?(0,n.jsxs)(tR.c0,{children:[(0,n.jsx)("div",{className:"w-1/3 h-full flex flex-col overflow-hidden",children:(0,n.jsx)(m.a9,{children:(0,n.jsxs)("div",{className:"w-full h-full flex",children:[(0,n.jsx)(nu.TabBar,{tabs:v,titlesLoading:j,selectedTabId:w,visibleTabIds:y,unreadTabs:L,globalLoadingTabs:E,dragTabIndex:T,dragOverTabIndex:$,isPinned:eg,onTogglePin:eb,onScheduleTask:ev,onSwitchTab:F,onCloseTab:R,onCloseAllTabs:I,onNewTab:D,onNewCodexTab:A,onNewGrokTab:H,onNewKimiTab:W,onNewGlmTab:z,onNewOllamaTab:O,onNewDeepseekTab:_,onOpenProjectSessions:()=>ew(!0),onDragStart:ei,onDragOver:ed,onDrop:ec,onDragEnd:eu}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 h-full flex flex-col",children:[(0,n.jsx)(i,{value:eU.split?g:null,children:(0,n.jsxs)("div",{className:`flex-1 overflow-hidden relative ${eU.row?"flex":""}`,children:[v.map(e=>(0,n.jsx)(sL,{tabId:e.id,panes:eU.panes,activePane:eU.activePane,row:eU.row,maximized:ts===e.id,layoutToggle:e.id===tx?th:void 0,onFocusPane:S,onClosePane:M,onToggleMaximize:to,children:(0,n.jsx)(sk,{tabId:e.id,...sM(e.id,eU),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:U,ollamaModel:e.ollamaModel,onOllamaModelChange:K,deepseekModel:e.deepseekModel,onDeepseekModelChange:Q,kimiModel:e.kimiModel,onKimiModelChange:G,glmModel:e.glmModel,onGlmModelChange:J,claudeModel:e.claudeModel,onClaudeModelChange:Y,claudeEffort:e.claudeEffort,onClaudeEffortChange:X,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Z,claudeThinking:e.claudeThinking,onClaudeThinkingChange:ee,codexModel:e.codexModel,grokModel:e.grokModel,onCodexModelChange:er,onGrokModelChange:en,codexReasoningEffort:e.codexReasoningEffort,grokReasoningEffort:e.grokReasoningEffort,onCodexReasoningEffortChange:es,onGrokReasoningEffortChange:eo,planMode:e.planMode,onPlanModeChange:ea,noHistory:e.noHistory,onNoHistoryChange:el,isActive:ni(e.id,y,"agent"===f,P),isVisible:ni(e.id,eU.panes,"agent"===f&&!te,P)&&(!ts||ts===e.id),isFocused:e.id===w,refreshSignal:eK,onDraftChange:e6,onStateChange:V,onShowGitStatus:e8,onContentSearch:e9,onShowFileDiff:tf,onOpenFileLink:tp,onOpenNote:tg,onOpenSession:q})},e.id)),e_&&(0,n.jsx)("div",{ref:ti,"data-diff-column":"",className:te?"absolute inset-0 z-30 bg-card":"h-full flex-1 min-w-0 border-l border-border",style:te?void 0:{order:eU.diffOrder},children:(0,n.jsx)(nl.e$,{toolCalls:e_.toolCalls,cwd:e_.cwd,sessionId:e_.sessionId,onClose:tl,onContentSearch:e9,fullscreen:te,onToggleFullscreen:ta},e_.messageId)})]})}),eU.split&&(0,n.jsx)("div",{ref:b,className:"flex-shrink-0"})]})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden relative",children:(0,n.jsx)(m.a9,{children:(0,n.jsx)(tF,{onClose:e7,cwd:e,initialTab:eP,tabSwitchTrigger:e$,initialSearchQuery:eI,searchQueryTrigger:eB,fileOpenRequest:eA})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(m.a9,{children:(0,n.jsx)(no,{cwd:e,tabId:"default",onOpenNote:tg,focusBubble:eW,isActive:"console"===f})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)(nu.TabBar,{tabs:v,titlesLoading:j,selectedTabId:w,visibleTabIds:y,unreadTabs:L,globalLoadingTabs:E,dragTabIndex:T,dragOverTabIndex:$,isPinned:eg,onTogglePin:eb,onScheduleTask:ev,onSwitchTab:F,onCloseTab:R,onCloseAllTabs:I,onNewTab:D,onNewCodexTab:A,onNewGrokTab:H,onNewKimiTab:W,onNewGlmTab:z,onNewDeepseekTab:_,onDragStart:ei,onDragOver:ed,onDrop:ec,onDragEnd:eu}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 h-full flex flex-col",children:[(0,n.jsx)(i,{value:eU.split?g:null,children:(0,n.jsx)("div",{className:`flex-1 overflow-hidden relative ${eU.row?"flex":""}`,children:v.map(e=>(0,n.jsx)(sL,{tabId:e.id,panes:eU.panes,activePane:eU.activePane,row:eU.row,maximized:ts===e.id,layoutToggle:e.id===tx?th:void 0,onFocusPane:S,onClosePane:M,onToggleMaximize:to,children:(0,n.jsx)(sk,{tabId:e.id,...sM(e.id,eU),cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,onEngineChange:U,ollamaModel:e.ollamaModel,onOllamaModelChange:K,deepseekModel:e.deepseekModel,onDeepseekModelChange:Q,kimiModel:e.kimiModel,onKimiModelChange:G,glmModel:e.glmModel,onGlmModelChange:J,claudeModel:e.claudeModel,onClaudeModelChange:Y,claudeEffort:e.claudeEffort,onClaudeEffortChange:X,claudeFastMode:e.claudeFastMode,onClaudeFastModeChange:Z,claudeThinking:e.claudeThinking,onClaudeThinkingChange:ee,codexModel:e.codexModel,grokModel:e.grokModel,onCodexModelChange:er,onGrokModelChange:en,codexReasoningEffort:e.codexReasoningEffort,grokReasoningEffort:e.grokReasoningEffort,onCodexReasoningEffortChange:es,onGrokReasoningEffortChange:eo,planMode:e.planMode,onPlanModeChange:ea,noHistory:e.noHistory,onNoHistoryChange:el,isActive:ni(e.id,y,!0,P),isVisible:ni(e.id,eU.panes,!te,P)&&(!ts||ts===e.id),isFocused:e.id===w,refreshSignal:eK,onDraftChange:e6,onStateChange:V,onOpenSession:q})},e.id))})}),eU.split&&(0,n.jsx)("div",{ref:b,className:"flex-shrink-0"})]})]})]}),e&&(0,n.jsx)(d.Q,{isOpen:ej,onClose:()=>ew(!1),cwd:e,onSelectSession:B,projectNumber:eG,openSessionIds:v.map(e=>e.sessionId)}),e&&eL&&(0,n.jsx)(tA,{isOpen:ek,onClose:()=>ey(!1),cwd:e}),eN&&(0,n.jsx)(rK,{onClose:()=>eC(!1),onSave:()=>eC(!1)})]})})})}},45720:(e,t,r)=>{r.d(t,{X:()=>n});function n(e,t){switch(e){case"codex":return`codex resume ${t}`;case"grok":return`grok --resume ${t}`;case"kimi":case"glm":case"deepseek":case"ollama":return`${e} ${t}`;default:return`claude -r ${t}`}}},47617:(e,t,r)=>{r.d(t,{I18nProvider:()=>d});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(86957),i=r(76900);function d({children:e,initialLanguage:t}){return(0,s.useState)(()=>(t&&a.A.language!==t&&a.A.changeLanguage(t),null)),(0,s.useEffect)(()=>{l.t4.runPromiseExit((0,i.M5)()).then(e=>{var t;let r="auto"!==(t=("Success"===e._tag?e.value.language:"auto")||"auto")&&t?t:navigator.language.startsWith("zh")?"zh":"en";a.A.language!==r&&a.A.changeLanguage(r)})},[]),(0,s.useEffect)(()=>{let e=e=>(function(e){for(let t of document.querySelectorAll("iframe"))try{t.contentWindow?.postMessage({type:"cockpit:language-change",lang:e},"*")}catch{}})(e);return a.A.on("languageChanged",e),()=>{a.A.off("languageChanged",e)}},[]),(0,s.useEffect)(()=>{if(window===window.parent)return;let e=e=>{e.data?.type==="cockpit:language-change"&&e.data.lang&&a.A.language!==e.data.lang&&a.A.changeLanguage(e.data.lang)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,n.jsx)(o.xC,{i18n:a.A,children:e})}},52153:(e,t,r)=>{r.d(t,{SessionBrowser:()=>b});var n=r(95155),s=r(12115),o=r(79114),a=r(66109),l=r(95045),i=r(75346),d=r(86957),c=r(76900),u=r(64702);let m=(e,t)=>e.endsWith(t)?e:e+t,x=(0,s.memo)(function({entry:e,index:t,highlighted:r,top:s,onEnter:o,onPick:a,onHover:l}){return(0,n.jsxs)("div",{role:"option","aria-selected":r,onClick:()=>o(e.path),onDoubleClick:()=>a(e.path),onMouseMove:()=>l(t),style:{position:"absolute",top:s,left:0,right:0,height:30},className:`flex items-center gap-2 px-3 text-xs cursor-pointer select-none ${r?"bg-hover text-foreground":"text-foreground"} ${e.hidden?"opacity-60":""}`,children:[(0,n.jsx)("svg",{className:"w-4 h-4 shrink-0 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),(0,n.jsx)("span",{className:"flex-1 truncate",children:e.name}),e.git&&(0,n.jsx)("span",{className:"shrink-0 text-[10px] text-muted-foreground border border-border rounded px-1",children:"git"})]})});function h({onPick:e}){let t,r,a,{t:l}=(0,o.Bd)(),[i,f]=(0,s.useState)(""),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)(-1),N=(0,s.useRef)(null),C=(0,s.useRef)(null),S=(0,s.useRef)(0),M=p?.sep??"/",{base:L,prefix:E}=(t="\\"===M?Math.max(i.lastIndexOf("/"),i.lastIndexOf("\\")):i.lastIndexOf("/"),r=i.slice(0,t+1),a=i.slice(t+1),""===r&&"~"===a?{base:"~",prefix:""}:{base:r,prefix:a});(0,s.useEffect)(()=>{let e=++S.current;d.t4.runPromiseExit((0,c.fz)("")).then(t=>{"Success"===t._tag&&e===S.current&&(g(t.value),v(m(t.value.path,t.value.sep)),f(m(t.value.path,t.value.sep)))}),N.current?.focus()},[]),(0,s.useEffect)(()=>{if(null===b||L===b)return;let e=setTimeout(()=>{let e=++S.current;d.t4.runPromiseExit((0,c.fz)(L)).then(t=>{"Success"===t._tag&&e===S.current&&(g(t.value),v(L))})},60);return()=>clearTimeout(e)},[L,b]);let P=b!==L,T=(0,s.useMemo)(()=>{if(!p)return[];let e=E.toLowerCase(),t=p.dirs.filter(t=>j||!t.hidden||e.startsWith("."));return e?[...t.filter(t=>t.name.toLowerCase().startsWith(e)),...t.filter(t=>!t.name.toLowerCase().startsWith(e)&&t.name.toLowerCase().includes(e))]:t},[p,E,j]);(0,s.useEffect)(()=>{y(E&&T.length>0?0:-1)},[E,T]);let $=(0,s.useMemo)(()=>!p||p.error||P?null:E?T.find(e=>e.name.toLowerCase()===E.toLowerCase())?.path??null:p.path,[p,E,T,P]),R=(0,s.useCallback)(e=>{f(m(e,M)),N.current?.focus()},[M]),I=(0,u.Te)({count:T.length,getScrollElement:()=>C.current,estimateSize:()=>30,overscan:8});(0,s.useEffect)(()=>{k>=0&&I.scrollToIndex(k)},[k,I]);let F=p?.error&&!P?l(`folderPicker.${p.error}`):null;return(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col gap-2 p-4",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:N,type:"text",value:i,onChange:e=>f(e.target.value),onKeyDown:t=>{if("Enter"===t.key&&(t.metaKey||t.ctrlKey))t.preventDefault(),$&&e($);else if("ArrowDown"===t.key)t.preventDefault(),y(e=>Math.min(e+1,T.length-1));else if("ArrowUp"===t.key)t.preventDefault(),y(e=>Math.max(e-1,0));else if("Tab"===t.key||"Enter"===t.key){let e=T[k];e?(t.preventDefault(),R(e.path)):"Tab"===t.key&&t.preventDefault()}},placeholder:l("folderPicker.placeholder"),spellCheck:!1,autoCapitalize:"off",autoCorrect:"off",className:"flex-1 min-w-0 px-2.5 py-1.5 text-xs font-mono border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsx)("button",{onClick:()=>$&&e($),disabled:!$,"data-tooltip":$??void 0,className:"shrink-0 px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:l("folderPicker.open")})]}),(0,n.jsx)("div",{className:"flex items-center gap-0.5 min-h-6 overflow-x-auto text-xs text-muted-foreground whitespace-nowrap",children:p?.segments.map((e,t)=>(0,n.jsxs)("span",{className:"flex items-center",children:[t>1&&(0,n.jsx)("span",{className:"px-0.5 text-foreground-subtle",children:"›"}),(0,n.jsx)("button",{onClick:()=>R(e.path),className:"px-1 py-0.5 rounded hover:bg-hover hover:text-foreground transition-colors",children:e.name})]},e.path))}),(0,n.jsx)("div",{ref:C,role:"listbox",className:`flex-1 min-h-0 overflow-y-auto border border-border rounded transition-opacity ${P?"opacity-60":""}`,children:F?(0,n.jsx)("div",{className:"p-3 text-xs text-red-11",children:F}):p&&0===T.length?(0,n.jsx)("div",{className:"p-3 text-xs text-muted-foreground",children:l(E?"folderPicker.noMatch":"folderPicker.empty")}):(0,n.jsx)("div",{style:{height:I.getTotalSize(),position:"relative"},children:I.getVirtualItems().map(t=>(0,n.jsx)(x,{entry:T[t.index],index:t.index,highlighted:t.index===k,top:t.start,onEnter:R,onPick:e,onHover:y},T[t.index].path))})}),(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2 text-xs",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[p&&(0,n.jsx)("button",{onClick:()=>R(p.home),className:"px-2 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:"~"}),p?.roots.map(e=>(0,n.jsx)("button",{onClick:()=>R(e),className:"px-2 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors font-mono",children:e},e))]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 text-muted-foreground cursor-pointer select-none",children:[(0,n.jsx)("input",{type:"checkbox",checked:j,onChange:e=>w(e.target.checked)}),l("folderPicker.showHidden")]}),(0,n.jsx)("span",{className:"hidden md:inline text-foreground-subtle",children:l("folderPicker.hint")})]})]})}var f=r(7578),p=r(92689),g=r(75347);function b({isOpen:e,onClose:t,onSelectSession:r,onAddProject:u,sessionNumbers:m={},projectNumbers:x={}}){let{t:v}=(0,o.Bd)(),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)([]),[N,C]=(0,s.useState)({}),[S,M]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),[P,T]=(0,s.useState)(""),$=(0,s.useRef)(null),R=(0,s.useCallback)(async()=>{M(!0),E(null),C({});let e=await d.t4.runPromiseExit((0,c.H7)());"Success"===e._tag?y(e.value):E("Failed to load projects"),M(!1)},[]),I=(0,s.useCallback)(async e=>{C(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await d.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?C(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):C(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),F=(0,s.useCallback)(e=>{let t=N[e];t?.isExpanded?C(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?C(t=>({...t,[e]:{...t[e],isExpanded:!0}})):I(e)},[N,I]);(0,s.useEffect)(()=>{e&&(w(!1),R(),setTimeout(()=>{$.current?.focus(),$.current?.select()},100))},[e,R]);let B=(0,s.useCallback)(e=>{u?.(e),t()},[u,t]);return((0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&(j?w(!1):t())};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,j,t]),e)?(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:j?"relative w-full max-w-[min(42rem,calc((100vw_-_28rem)*0.9))] h-[min(70vh,36rem)] mx-4 bg-card rounded-lg shadow-lv3 flex flex-col overflow-hidden":a.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[j?(0,n.jsxs)("button",{onClick:()=>w(!1),className:"flex items-center gap-1 text-sm font-medium text-foreground hover:text-brand transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),v("folderPicker.title")]}):(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:v("sessions.projectList")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[!j&&(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:$,type:"text",placeholder:v("workspace.searchProjectPath"),value:P,onChange:e=>T(e.target.value),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),P&&(0,n.jsx)("button",{onClick:()=>{T(""),$.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:v("fileBrowser.clear"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),u&&!j&&(0,n.jsxs)("button",{onClick:()=>w(!0),className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m3-3H9m-4 7h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),v("sessions.openFolder")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),j?(0,n.jsx)(h,{onPick:B}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[S&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:v("workspace.loadingProjects")})]})}),L&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:L})}),!S&&!L&&0===k.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:v("workspace.projectNotFound")})}),!S&&!L&&k.filter(e=>e.fullPath.toLowerCase().includes(P.toLowerCase())).map(e=>{let t=N[e.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null},s=x[e.fullPath];return(0,n.jsxs)("div",{className:"mb-3",children:[(0,n.jsxs)("button",{onClick:()=>F(e.encodedPath),className:"w-full flex items-center gap-2 p-2 rounded hover:bg-hover transition-colors text-left",children:[(0,n.jsx)("svg",{className:`w-3 h-3 text-muted-foreground transition-transform ${t.isExpanded?"rotate-90":""}`,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})}),s&&(0,n.jsx)(f.l,{projectNumber:s}),(0,n.jsx)("span",{className:"flex-1 text-xs font-medium text-foreground truncate","data-tooltip":e.fullPath,children:e.fullPath}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",e.sessionCount,")"]})]}),t.isExpanded&&(0,n.jsxs)("div",{className:"ml-6 mt-2",children:[t.isLoading&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 text-xs text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-3 w-3",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:v("sessions.loadingSessions")})]}),t.error&&(0,n.jsx)("div",{className:"p-3 text-xs text-red-11",children:t.error}),!t.isLoading&&!t.error&&(0,n.jsx)("div",{className:a.jL,children:t.sessions.map(t=>{let s=t.path.split("/").pop()||"",o=t.sessionId||s.replace(".jsonl",""),a=m[`${e.fullPath}
37
+ ${o}`],[d,c]=a?.split(".")??[];return(0,n.jsxs)("div",{onClick:()=>{var n;let s,o;return n=e.fullPath,s=t.path.split("/").pop()||"",o=t.sessionId||s.replace(".jsonl",""),void(r?r(n,o):(0,l.F)(i.n.OpenProject,{cwd:n,sessionId:o}))},className:"group/session-title p-3 rounded border border-border hover:border-brand hover:shadow-lv2 cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,n.jsx)(p.S,{engine:t.engine}),(0,n.jsx)("h4",{className:"flex flex-1 min-w-0 items-center gap-1 text-xs font-medium text-foreground",children:(0,n.jsx)(g.dh,{cwd:e.fullPath,sessionId:t.sessionId||t.path.split("/").pop()?.replace(/\.jsonl$/,"")||"",title:t.title,titleRevision:t.titleRevision})}),a&&(0,n.jsx)(f.l,{projectNumber:d,sessionNumber:c,bot:t.bot,className:"ml-auto"})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(t.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),(0,n.jsxs)("div",{className:"space-y-0.5 text-xs",children:[t.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate","data-tooltip":e,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`first-${t}`)),t.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-foreground-subtle text-center py-0.5",children:"\xb7\xb7\xb7"}),t.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate","data-tooltip":e,children:[(0,n.jsx)("span",{className:"text-foreground-subtle mr-1",children:"•"}),e]},`last-${t}`))]})]},t.path)})})]})]},e.encodedPath)})]})]})]}):null}},53213:(e,t,r)=>{r.d(t,{Bj:()=>d,CM:()=>v,FK:()=>b,Iz:()=>x,MB:()=>j,Ub:()=>f,X0:()=>h,Zi:()=>c,lv:()=>m,oh:()=>g,r4:()=>l,ue:()=>i,w2:()=>p,yy:()=>u});var n=r(49433),s=r(82680);let o=e=>n.$mh({try:async()=>{let t=await fetch(e);if(!t.ok){let e;try{e=(await t.json()).error}catch{}throw Error(e||`HTTP ${t.status}`)}return await t.json()},catch:t=>new s.uV({message:`fetch ${e} failed`,cause:t})}),a=(e,t)=>n.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),l=e=>o(`/api/git/branches?cwd=${encodeURIComponent(e)}`).pipe(n.qIB(t=>"Failed to get branches"===t.error?n.fJG(new s.m_({resource:"git-repo",id:e})):n.PyW(t))),i=e=>o(`/api/git/current-branch?cwd=${encodeURIComponent(e)}`),d=(e,t,r,n)=>o(`/api/git/commits?cwd=${encodeURIComponent(e)}&branch=${encodeURIComponent(t)}&limit=${r}${"number"==typeof n?`&offset=${n}`:""}`),c=(e,t,r)=>o(`/api/git/commit-diff?cwd=${encodeURIComponent(e)}&hash=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),u=(e,t,r,n="worktree")=>o(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}&mode=${n}${r?`&file=${encodeURIComponent(r)}`:""}`),m=e=>o(`/api/git/status?cwd=${encodeURIComponent(e)}`),x=(e,t)=>a("/api/git/stage",{cwd:e,files:t}),h=(e,t)=>a("/api/git/unstage",{cwd:e,files:t}),f=(e,t,r)=>a("/api/git/discard",{cwd:e,files:t,isUntracked:r}),p=(e,t,r,n)=>{let s=new URLSearchParams({cwd:e,file:t,type:r});return n&&s.set("oldPath",n),o(`/api/git/diff?${s}`)},g=e=>o(`/api/git/diff?${e.toString()}`),b=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),v=e=>n.$mh({try:async()=>{let t=await fetch("/api/git/worktree",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=await t.json().catch(()=>null);if(!t.ok)throw Error(r?.error||`HTTP ${t.status}`);return r},catch:e=>new s.uV({message:"POST /api/git/worktree failed",cause:e})}),j=e=>o(`/api/projectGraph/search?${e.toString()}`)},54356:(e,t,r)=>{r.d(t,{useTabState:()=>N});var n=r(12115),s=r(41474),o=r(2111),a=r(95045),l=r(75346),i=r(49433),d=r(80286),c=r(86957),u=r(96472),m=r(82680);let x=e=>`cockpit:active-tab:${e}`;var h=r(48050),f=r(83448);function p(e){let t,r=!1,n=Promise.resolve(),s=async()=>{if(!r){r=!0;try{for(;void 0!==t;){let r=t;t=void 0;try{await e(r)}catch{}}}finally{r=!1}}};return{enqueue(e){t=e,r||(n=s())},whenIdle:()=>n}}let g=e=>`Session ${e}`;function b(e,t,r,n,s){let o=new Set(t.map(e=>e.id)),a=new Set([...e].filter(e=>o.has(e))),l=new Map;for(let e of r){if(e.cwd!==n)continue;let t="codex"===e.engine?w(e.sessionId):e.sessionId;l.set(t,e.status??"normal")}for(let e of t){if(!e.sessionId)continue;let t=l.get(e.sessionId);void 0!==t&&(t===s?a.add(e.id):a.delete(e.id))}return a}function v(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}let j=/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:\.jsonl)?$/i;function w(e){let t=e.match(j);return t?.[1]??e}function k(e,t){if(e.engine&&t.engine&&e.engine!==t.engine)return!1;if(e.sessionId===t.sessionId)return!0;let r=e.engine??t.engine;return("codex"===r||!r&&/rollout-/.test(e.sessionId+t.sessionId))&&w(e.sessionId)===w(t.sessionId)}function y(e,t,r){let n=new Set(t.map(e=>e.id)),s=new Set(e.filter(e=>n.has(e))),o=[],a=[];for(let l of e){if(n.has(l)&&!a.includes(l)){a.push(l);continue}let e=new Set([...a,...s]),i=[...t].reverse().find(t=>!e.has(t.id));if(i){a.push(i.id),s.add(i.id);continue}let d={id:`tab-${Date.now()}-pane${o.length}`,cwd:r,title:"New Chat"};o.push(d),a.push(d.id)}return{panes:a,created:o}}function N({initialCwd:e,initialSessionId:t,initialBlank:r,activeView:j}){let C=(0,n.useRef)(!1),S=(0,n.useRef)(!0),[M,L]=(0,n.useState)(!1),[E,P]=(0,n.useState)(null),[T,$]=(0,n.useState)(!!e),R=(0,n.useCallback)(()=>{S.current=!1,L(!0)},[]),I=(0,s.F)(),[F,B]=(0,n.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:t?g(t):"New Chat"}]),[D,A]=(0,n.useState)(()=>[F[0]?.id??""]),[H,W]=(0,n.useState)(0),z=(0,n.useRef)(H);(0,n.useEffect)(()=>{z.current=H},[H]);let O=(0,n.useRef)(D);(0,n.useEffect)(()=>{O.current=D},[D]);let _=D[H]??D[0]??"",q=(0,n.useCallback)(e=>{A(t=>{let r=t.indexOf(e);if(-1!==r)return r!==z.current&&W(r),t;let n=[...t];return n[z.current]=e,n})},[]),[V,U]=(0,n.useState)(new Set),[K,Q]=(0,n.useState)(new Set),G=(0,n.useRef)(F);(0,n.useEffect)(()=>{G.current=F},[F]);let J=(0,n.useRef)([]),Y=(0,n.useRef)(_);(0,n.useEffect)(()=>{Y.current=_},[_]);let X=(0,n.useRef)(null),Z=(0,n.useRef)(new Set),ee=F.find(e=>e.id===_),et=(0,n.useRef)(void 0);(0,n.useLayoutEffect)(()=>(et.current=M&&I&&(!j||"agent"===j)?ee:void 0,()=>{et.current=void 0}),[M,I,j,ee]);let er=(0,n.useMemo)(()=>p(async t=>{let r=()=>!!t.sessionId&&et.current?.id===t.id&&et.current.sessionId===t.sessionId&&et.current.engine===t.engine&&"visible"===document.visibilityState;if(!e||!t.sessionId||!r())return;let n=await c.t4.runPromise((0,u.AH)(e,t.sessionId,t.engine,r));if(null===n||!r()||et.current?.isLoading)return;let s=J.current.filter(r=>r.cwd===e&&k(r,{sessionId:t.sessionId,engine:t.engine}));if(!s.some(e=>"loading"===e.status||(e.lastActive??0)>n)){for(let e of s)e.status="normal";U(e=>{if(!e.has(t.id))return e;let r=new Set(e);return r.delete(t.id),r})}}),[e]),en=(0,n.useCallback)((e,t)=>{let r=et.current;r?.sessionId&&(!e||k({sessionId:r.sessionId,engine:r.engine},{sessionId:e,engine:t}))&&er.enqueue(r)},[er]);(0,n.useEffect)(()=>{en()},[en,M,I,j,_,ee?.sessionId,ee?.engine,ee?.isLoading]);let es=(0,n.useCallback)(t=>{e&&(Q(r=>{let n=b(r,G.current,t,e,"loading");return v(r,n)?r:n}),U(r=>{let n=b(r,G.current,t,e,"unread");return v(r,n)?r:n}))},[e]);(0,n.useEffect)(()=>{M&&es(J.current)},[M,F,es]);let[eo,ea]=(0,n.useState)(null),[el,ei]=(0,n.useState)(null);(0,n.useEffect)(()=>{!e||C.current||(C.current=!0,(async()=>{let n=c.t4.runSync(i.SvU({try:()=>{let t=window.sessionStorage.getItem(x(e));if(!t)return null;let r=JSON.parse(t);return"blank"===r.kind?{kind:"blank"}:"session"===r.kind&&"string"==typeof r.sessionId&&r.sessionId?{kind:"session",sessionId:r.sessionId}:null},catch:e=>new m.uV({message:"load active tab target failed",cause:e})}).pipe(i.h9N(()=>i.PyW(null)))),s=await c.t4.runPromise((0,u.n8)(e).pipe(i.h9N(()=>i.PyW(null))));if(s){let o=s.engines||{},a={};for(let[e,t]of Object.entries(o))a["codex"===t?w(e):e]=t;let l=[];for(let e of s.sessions||[]){let t="codex"===o[e]?w(e):e;l.includes(t)||l.push(t)}let i=s.activeSessionId&&"codex"===o[s.activeSessionId]?w(s.activeSessionId):s.activeSessionId,d=s.ollamaModels||{},c=s.deepseekModels||{},u=s.kimiModels||{},m=s.glmModels||{},x=s.claudeModels||{},h=s.claudeEfforts||{},f=s.claudeFastModes||{},p=s.claudeThinkings||{},b=s.codexModels||{},v=s.grokModels||{},j=s.codexReasoningEfforts||{},k=s.grokReasoningEfforts||{},N=s.planModes||{},C=s.noHistories||{},S=n?.kind==="session"?n.sessionId:void 0,M=[...l];t&&!M.includes(t)&&(M=[t,...M]),S&&!M.includes(S)&&(M=[S,...M]),P(M);let L=new Map((s.sessionTitles??[]).map(e=>[e.sessionId,e.title]));if(M.length>0){let l=G.current,E=M.map((t,r)=>{let n=l.find(e=>e.sessionId===t),s=L.get(t)||n?.title;return{id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:s||g(t),titleReady:!0,engine:a[t]||n?.engine||void 0,ollamaModel:d[t]||n?.ollamaModel||void 0,deepseekModel:c[t]||n?.deepseekModel||void 0,kimiModel:u[t]||n?.kimiModel||void 0,glmModel:m[t]||n?.glmModel||void 0,claudeModel:x[t]||n?.claudeModel||void 0,claudeEffort:h[t]||n?.claudeEffort||void 0,claudeFastMode:f[t]??n?.claudeFastMode,claudeThinking:p[t]??n?.claudeThinking,codexModel:b[t]||n?.codexModel||void 0,grokModel:v[t]||n?.grokModel||void 0,codexReasoningEffort:j[t]||n?.codexReasoningEffort||void 0,grokReasoningEffort:k[t]||n?.grokReasoningEffort||void 0,planMode:N[t]??n?.planMode,noHistory:C[t]??n?.noHistory}}),P=S||t||i,T=P?M.indexOf(P):-1;T<0&&(T=0);let $=n?.kind!=="blank"&&(n||t||!r&&null!==i)?void 0:{id:`tab-${Date.now()}-blank`,cwd:e,title:"New Chat"},I=$?[...E,$]:E,F=$?.id??E[T].id,D=s.paneSessionIds;if(Array.isArray(D)&&D.length>1){let{panes:t,created:r}=y(D.slice(0,2).map(e=>{let t=e&&"codex"===o[e]?w(e):e;return t&&E.find(e=>e.sessionId===t)?.id||""}),I,e),n=t.indexOf(F);-1===n&&(t[0]=F,n=0);let s=t[0]===t[1];B([...I,...r]),A(s?[t[0]]:t),W(s?0:n)}else B(I),q(F);setTimeout(R,0)}else R()}else P(t?[t]:[]),R()})())},[e,t,r,R]),(0,n.useEffect)(()=>{if(!e||null===E)return;if(0===E.length)return void $(!1);let t=!0;$(!1);let r=c.t4.runFork((0,h.S6)(e,E).pipe(i.Mim(r=>i.OH5(()=>{if(!t)return;let n=new Map(r.map(e=>[e.sessionId,e]));B(t=>t.map(t=>{if(!t.sessionId||(t.cwd||e)!==e||!E.includes(t.sessionId))return t;let r=n.get(t.sessionId);return{...t,title:r?.title??t.title,titleReady:!0}}))})),i.h9N(e=>i.FFw("Cannot load initial project titles",e)),i.yeE(i.OH5(()=>{t&&$(!1)}))));return()=>{t=!1,c.t4.runFork(d.G(r))}},[e,E]),(0,n.useEffect)(()=>{if(!M||!e)return;let t=F.map(e=>e.sessionId).filter(e=>!!e),r=F.find(e=>e.id===_),n=r?.sessionId??null,s={},o={},a={},l={},i={},d={},m={},x={},h={},f={},g={},b={},v={},j={},w={};for(let e of F)e.sessionId&&e.engine&&(s[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(o[e.sessionId]=e.ollamaModel),e.sessionId&&e.deepseekModel&&(a[e.sessionId]=e.deepseekModel),e.sessionId&&e.kimiModel&&(l[e.sessionId]=e.kimiModel),e.sessionId&&e.glmModel&&(i[e.sessionId]=e.glmModel),e.sessionId&&e.claudeModel&&(d[e.sessionId]=e.claudeModel),e.sessionId&&e.claudeEffort&&(m[e.sessionId]=e.claudeEffort),e.sessionId&&e.codexModel&&(f[e.sessionId]=e.codexModel),e.sessionId&&e.codexReasoningEffort&&(b[e.sessionId]=e.codexReasoningEffort),e.sessionId&&e.grokModel&&(g[e.sessionId]=e.grokModel),e.sessionId&&void 0!==e.grokReasoningEffort&&(v[e.sessionId]=e.grokReasoningEffort),e.sessionId&&(void 0!==e.planMode&&(j[e.sessionId]=e.planMode),void 0!==e.noHistory&&(w[e.sessionId]=e.noHistory),void 0!==e.claudeFastMode&&(x[e.sessionId]=e.claudeFastMode),void 0!==e.claudeThinking&&(h[e.sessionId]=e.claudeThinking));let k=[...Z.current],y={cwd:e,sessions:t,activeSessionId:n,paneSessionIds:D.map(e=>F.find(t=>t.id===e)?.sessionId??null),engines:s,ollamaModels:o,deepseekModels:a,kimiModels:l,glmModels:i,claudeModels:d,claudeEfforts:m,claudeFastModes:x,claudeThinkings:h,codexModels:f,grokModels:g,codexReasoningEfforts:b,grokReasoningEfforts:v,planModes:j,noHistories:w,...k.length?{closedSessionIds:k}:{}};X.current||(X.current=p(async e=>{let t=await c.t4.runPromiseExit((0,u.ej)(e));if("Success"===t._tag)for(let t of e.closedSessionIds??[])Z.current.delete(t);else console.error("Failed to save sessions:",t.cause)})),X.current.enqueue(y)},[F,_,D,e,M]),(0,n.useLayoutEffect)(()=>{if(S.current||!e)return;let t=F.find(e=>e.id===_)?.sessionId,r=t?{kind:"session",sessionId:t}:{kind:"blank"};c.t4.runSync(i.SvU({try:()=>window.sessionStorage.setItem(x(e),JSON.stringify(r)),catch:e=>new m.uV({message:"save active tab target failed",cause:e})}).pipe(i.h9N(()=>i.rIH))),(0,a.F)(l.n.SessionChange,{cwd:e,sessionId:t??null})},[_,F,e,M]);let ed=(0,n.useCallback)(t=>{e&&c.t4.runPromise((0,u.n8)(e).pipe(i.h9N(()=>i.PyW(null)))).then(r=>{if(!r)return;let n=r.engines||{},s={};for(let[e,t]of Object.entries(n))s["codex"===t?w(e):e]=t;let o=[];for(let e of r.sessions||[]){let t="codex"===n[e]?w(e):e;o.includes(t)||o.push(t)}let a=r.ollamaModels||{},l=r.deepseekModels||{},i=r.kimiModels||{},d=r.glmModels||{},c=r.claudeModels||{},u=r.claudeEfforts||{},m=r.claudeFastModes||{},x=r.claudeThinkings||{},h=r.codexModels||{},f=r.grokModels||{},p=r.codexReasoningEfforts||{},b=r.grokReasoningEfforts||{},v=r.planModes||{},j=r.noHistories||{},k=G.current,N=new Set(t),C=k.filter(e=>!e.sessionId||!N.has(e.sessionId)),S=new Set(C.map(e=>e.sessionId).filter(Boolean)),M=o.filter(e=>!S.has(e));if(C.length===k.length&&0===M.length)return;let L=[...C,...M.map((t,r)=>({id:`tab-${Date.now()}-sync-${r}`,cwd:e,sessionId:t,title:g(t),engine:s[t]||void 0,ollamaModel:a[t]||void 0,deepseekModel:l[t]||void 0,kimiModel:i[t]||void 0,glmModel:d[t]||void 0,claudeModel:c[t]||void 0,claudeEffort:u[t]||void 0,claudeFastMode:m[t]??void 0,claudeThinking:x[t]??void 0,codexModel:h[t]||void 0,grokModel:f[t]||void 0,codexReasoningEffort:p[t]||void 0,grokReasoningEffort:b[t]||void 0,planMode:v[t]||void 0,noHistory:j[t]||void 0}))];0===L.length&&(L=[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]);let{panes:E,created:P}=y(O.current,L,e);P.length&&(L=[...L,...P]),B(L),A(E)})},[e]),ec=(0,n.useCallback)(t=>{if(e){if("global-state"===t.type&&Array.isArray(t.data?.sessions)){if(J.current=t.data.sessions,!S.current)for(let r of(es(t.data.sessions),t.data.sessions))r.cwd===e&&"unread"===r.status&&en(r.sessionId,r.engine);return}"task-fired"===t.type&&t.cwd===e&&t.sessionId&&en(t.sessionId),S.current||"project-state-changed"!==t.type||t.cwd!==e||ed(t.closedSessionIds??[])}},[e,ed,es,en]);(0,o.h)({url:"/ws/global-state",enabled:!!e,onMessage:ec});let eu=(0,n.useCallback)((e,t,r,n)=>{let{engine:s,ollamaModel:o,deepseekModel:a,kimiModel:l,glmModel:i,claudeModel:d,claudeEffort:c,claudeFastMode:u,claudeThinking:m,codexModel:x,codexReasoningEffort:h,grokModel:f,grokReasoningEffort:p,planMode:b,noHistory:v,appendToEnd:j=!1}=n??{},w={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?g(t):"New Chat"),engine:s,ollamaModel:o,deepseekModel:a,kimiModel:l,glmModel:i,claudeModel:d,claudeEffort:c,claudeFastMode:u,claudeThinking:m,codexModel:x,grokModel:f,codexReasoningEffort:h,grokReasoningEffort:p,planMode:b,noHistory:v};return B(e=>{if(j)return[...e,w];let t=e.findIndex(e=>e.id===_);if(-1===t)return[...e,w];let r=[...e];return r.splice(t+1,0,w),r}),q(w.id),w.id},[_]),em=(0,n.useCallback)(t=>{let r=G.current.find(e=>e.id===t);r?.sessionId&&Z.current.add(r.sessionId);let n=G.current.filter(e=>e.id!==t),{panes:s,created:o}=y(O.current,n,e);B([...n,...o]),A(s)},[e]),ex=(0,n.useCallback)(()=>{W(0),G.current.forEach(e=>{e.sessionId&&Z.current.add(e.sessionId)});let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};q(t.id),B([t])},[e]),eh=(0,n.useCallback)((t,r)=>{let n=F.find(e=>e.sessionId===t);if(n){q(n.id),en(t);return}e?c.t4.runPromise((0,u.n8)(e).pipe(i.h9N(()=>i.PyW(null)))).then(n=>{let s=G.current.find(e=>e.sessionId===t);if(s){q(s.id),en(t);return}eu(e,t,r,{engine:n?.engines?.[t],ollamaModel:n?.ollamaModels?.[t],deepseekModel:n?.deepseekModels?.[t],kimiModel:n?.kimiModels?.[t],glmModel:n?.glmModels?.[t],claudeModel:n?.claudeModels?.[t],claudeEffort:n?.claudeEfforts?.[t],claudeFastMode:n?.claudeFastModes?.[t],claudeThinking:n?.claudeThinkings?.[t],codexModel:n?.codexModels?.[t],grokModel:n?.grokModels?.[t],codexReasoningEffort:n?.codexReasoningEfforts?.[t],grokReasoningEffort:n?.grokReasoningEfforts?.[t],planMode:n?.planModes?.[t],noHistory:n?.noHistories?.[t],appendToEnd:!0})}):eu(e,t,r,{appendToEnd:!0})},[F,e,eu,en]),ef=(0,n.useCallback)(()=>{eu(e,void 0,void 0,{appendToEnd:!0})},[e,eu]),ep=(0,n.useCallback)(()=>{eu(e,void 0,"New Codex Chat",{engine:"codex",appendToEnd:!0})},[e,eu]),eg=(0,n.useCallback)(()=>{eu(e,void 0,"New Grok Chat",{engine:"grok",appendToEnd:!0})},[e,eu]),eb=(0,n.useCallback)(()=>{eu(e,void 0,"New Kimi Chat",{engine:"kimi",kimiModel:"k3",appendToEnd:!0})},[e,eu]),ev=(0,n.useCallback)(()=>{eu(e,void 0,"New GLM Chat",{engine:"glm",glmModel:"glm-5.3",appendToEnd:!0})},[e,eu]),ej=(0,n.useRef)(void 0),ew=(0,n.useCallback)(()=>{let t=eu(e,void 0,"New Ollama Chat",{engine:"ollama",ollamaModel:ej.current,appendToEnd:!0});c.t4.runPromise((0,f.Vm)()).then(e=>{e&&(ej.current=e,B(r=>r.map(r=>r.id!==t||r.ollamaModel?r:{...r,ollamaModel:e})))})},[e,eu]),ek=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e&&r.engine!==t?{...r,engine:t}:r))},[]),ey=(0,n.useCallback)((e,t)=>{ej.current=t,B(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),eN=(0,n.useCallback)(()=>{eu(e,void 0,"New DeepSeek Chat",{engine:"deepseek",deepseekModel:"deepseek-v4-pro",appendToEnd:!0})},[e,eu]),eC=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,deepseekModel:t}:r))},[]),eS=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,kimiModel:t}:r))},[]),eM=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,glmModel:t}:r))},[]),eL=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,claudeModel:t}:r))},[]),eE=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,claudeEffort:t}:r))},[]),eP=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,claudeFastMode:t}:r))},[]),eT=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,claudeThinking:t}:r))},[]),e$=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,codexModel:t}:r))},[]),eR=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,grokModel:t}:r))},[]),eI=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,codexReasoningEffort:t}:r))},[]),eF=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,grokReasoningEffort:t}:r))},[]),eB=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,planMode:t}:r))},[]),eD=(0,n.useCallback)((e,t)=>{B(r=>r.map(r=>r.id===e?{...r,noHistory:t}:r))},[]),eA=(0,n.useCallback)((t,r)=>{let n=G.current.find(e=>e.id===Y.current);eu(e,t,r,{engine:n?.engine,ollamaModel:n?.ollamaModel,deepseekModel:n?.deepseekModel,kimiModel:n?.kimiModel,glmModel:n?.glmModel,claudeModel:n?.claudeModel,claudeEffort:n?.claudeEffort,claudeFastMode:n?.claudeFastMode,claudeThinking:n?.claudeThinking,codexModel:n?.codexModel,grokModel:n?.grokModel,codexReasoningEffort:n?.codexReasoningEffort,grokReasoningEffort:n?.grokReasoningEffort})},[e,eu]),eH=(0,n.useCallback)((e,t)=>{let r=G.current.find(t=>t.id===e);r?.isLoading&&!1===t.isLoading&&(et.current?.id===e?en(t.sessionId||r.sessionId):U(t=>new Set(t).add(e))),B(r=>r.map(r=>r.id===e?{...r,...t,titleReady:void 0!==t.sessionId&&t.sessionId!==r.sessionId?void 0:r.titleReady}:r))},[en]),eW=(0,n.useCallback)(()=>{let t=O.current;if(t.length>1){A([t[z.current]]),W(0);return}let r=G.current,n=r.findIndex(e=>e.id===t[0]),s=r[n+1]??r[n-1];if(s){A([t[0],s.id]),W(0);return}let o={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};B(e=>[...e,o]),A([t[0],o.id]),W(1)},[e]),ez=(0,n.useCallback)(e=>{let t=O.current;t.length<2||(A(t.filter((t,r)=>r!==e)),W(0))},[]),eO=(0,n.useCallback)(e=>{W(e)},[]),e_=(0,n.useCallback)(e=>{q(e);let t=G.current.find(t=>t.id===e)?.sessionId;t&&en(t)},[q,en]),eq=(0,n.useCallback)(e=>{ea(e)},[]),eV=(0,n.useCallback)((e,t)=>{e.preventDefault(),null!==eo&&eo!==t&&ei(t)},[eo]),eU=(0,n.useCallback)(e=>{null!==eo&&eo!==e&&B(t=>{let r=[...t],[n]=r.splice(eo,1);return r.splice(e,0,n),r}),ea(null),ei(null)},[eo]),eK=(0,n.useCallback)(()=>{ea(null),ei(null)},[]),eQ=F.find(e=>e.id===_);return{tabs:F,titlesLoading:T,activeTabId:_,activeTab:eQ,paneTabIds:D,activePane:H,unreadTabs:V,globalLoadingTabs:K,pageVisible:I,dragTabIndex:eo,dragOverTabIndex:el,addTab:eu,toggleSideBySide:eW,focusPane:eO,closePane:ez,closeTab:em,closeAllTabs:ex,switchTab:e_,handleSelectSession:eh,handleNewTab:ef,handleNewCodexTab:ep,handleNewGrokTab:eg,handleNewKimiTab:eb,handleNewGlmTab:ev,handleNewOllamaTab:ew,handleNewDeepseekTab:eN,handleOpenSession:eA,updateTabState:eH,updateTabEngine:ek,updateTabOllamaModel:ey,updateTabDeepseekModel:eC,updateTabKimiModel:eS,updateTabGlmModel:eM,updateTabClaudeModel:eL,updateTabClaudeEffort:eE,updateTabClaudeFastMode:eP,updateTabClaudeThinking:eT,updateTabCodexModel:e$,updateTabGrokModel:eR,updateTabCodexReasoningEffort:eI,updateTabGrokReasoningEffort:eF,updateTabPlanMode:eB,updateTabNoHistory:eD,handleTabDragStart:eq,handleTabDragOver:eV,handleTabDrop:eU,handleTabDragEnd:eK}}},60865:(e,t,r)=>{r.d(t,{NoteModal:()=>ed});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(13439),i=r(58940),d=r(43561),c=r(5989),u=r(76065),m=r(43203),x=r(6268),h=r(48434),f=r(82159),p=r(44695);let g={todo:"doing",doing:"done",done:"todo"},b={todo:"false",doing:"mixed",done:"true"},v=/^\s*(\[([ x/])?\])\s$/,j=p.L.extend({addAttributes:()=>({status:{default:"todo",keepOnSplit:!1,parseHTML:e=>(function(e){let t=e.getAttribute("data-status");if("todo"===t||"doing"===t||"done"===t)return t;let r=e.getAttribute("data-checked");return""===r||"true"===r?"done":"todo"})(e),renderHTML:e=>({"data-status":e.status,"data-checked":"done"===e.status?"true":"false"})}}),addStorage:()=>({markdown:{serialize(e,t){var r;e.write(`${"done"===(r=t.attrs.status)?"[x]":"doing"===r?"[/]":"[ ]"} `),e.renderContent(t)}}}),addInputRules(){return[(0,f.tG)({find:v,type:this.type,getAttributes:e=>{let t=e[e.length-1];return{status:"x"===t?"done":"/"===t?"doing":"todo"}}})]},renderHTML({HTMLAttributes:e}){return["li",(0,f.KV)(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},addNodeView(){return({node:e,getPos:t,editor:r})=>{let n=document.createElement("li");n.setAttribute("data-type",this.name);let s=document.createElement("label");s.classList.add("task-marker"),s.contentEditable="false";let o=document.createElement("span");o.classList.add("task-marker-box"),o.setAttribute("role","checkbox"),s.appendChild(o);let a=document.createElement("div");n.append(s,a);let l=e=>{let t=e.attrs.status??"todo";n.dataset.status=t,n.dataset.checked="done"===t?"true":"false",o.setAttribute("aria-checked",b[t])};return l(e),s.addEventListener("mousedown",e=>e.preventDefault()),s.addEventListener("click",e=>{if(e.preventDefault(),!r.isEditable||"function"!=typeof t)return;let n=t();"number"==typeof n&&r.chain().focus(void 0,{scrollIntoView:!1}).command(({tr:e})=>{let t=e.doc.nodeAt(n);if(!t)return!1;let r=t.attrs.status??"todo";return e.setNodeMarkup(n,void 0,{...t.attrs,status:g[r]}),!0}).run()}),{dom:n,contentDOM:a,update:t=>t.type===e.type&&(l(t),!0)}}}});var w=r(59265),k=r(26932),y=r(27050),N=r(52740),C=r(76865),S=r(63197);let M=new C.hs("headingFold");function L(e){let t=e.attrs.foldState;return"folded"===t||"children"===t?t:"expanded"}function E(e){let t=[],r=[];return e.forEach((e,n)=>{let s=n+e.nodeSize;if("heading"===e.type.name){let o=e.attrs.level;for(;r.length&&r[r.length-1].level>=o;)r.pop();let a=L(e),l=r.some(e=>"folded"===e.state),i=["note-heading"];"expanded"!==a&&i.push("is-collapsed"),l&&i.push("note-folded-hidden"),t.push(S.NZ.node(n,s,{class:i.join(" ")})),t.push(S.NZ.widget(n+1,(e,t)=>{let r;return(r=document.createElement("span")).className="note-fold-toggle",r.contentEditable="false",r.setAttribute("data-fold-state",a),r.addEventListener("mousedown",r=>{r.preventDefault(),r.stopPropagation();let n=t();if(null==n)return;let s=n-1,o=e.state.doc.nodeAt(s);o&&"heading"===o.type.name&&e.dispatch(e.state.tr.setNodeMarkup(s,void 0,{...o.attrs,foldState:"expanded"===L(o)?"folded":"expanded"}))}),r},{side:-1,key:`fold-${n}-${a}`})),r.push({level:o,state:a})}else r.some(e=>"folded"===e.state||"children"===e.state)&&t.push(S.NZ.node(n,s,{class:"note-folded-hidden"}))}),S.zF.create(e,t)}let P=N.A.extend({addAttributes(){return{...this.parent?.(),foldState:{default:"expanded",keepOnSplit:!1,parseHTML:e=>"true"===e.getAttribute("data-collapsed")?"folded":"expanded",renderHTML:e=>e.foldState&&"expanded"!==e.foldState?{"data-collapsed":"true"}:{}}}},addKeyboardShortcuts(){let e=this.name;return{Tab:()=>{var t;let r,n,s,{state:o}=this.editor,{$from:a}=o.selection;if(a.parent.type.name!==e)return!1;let l=a.before(a.depth),i=o.doc.nodeAt(l);if(!i||i.type.name!==e)return!1;let d=i.attrs.level,c=(t=o.doc,n=[],s=!1,t.forEach((t,r)=>{if(r===l){s=!0;return}if(s&&t.type.name===e){if(t.attrs.level<=d){s=!1;return}n.push(r)}}),n),u=c.length>0,m=L(i),x=null;return u?"expanded"===m?r="folded":(r="folded"===m?"children":"expanded",x="expanded"):r="expanded"===m?"folded":"expanded",this.editor.chain().command(({tr:t})=>{if(t.setNodeMarkup(l,void 0,{...i.attrs,foldState:r}),x)for(let r of c){let n=t.doc.nodeAt(r);n&&n.type.name===e&&t.setNodeMarkup(r,void 0,{...n.attrs,foldState:x})}return!0}).run()}}},addStorage:()=>({markdown:{serialize(e,t){e.write(e.repeat("#",t.attrs.level)+" "),e.renderInline(t,!1),"expanded"!==L(t)&&e.write(" \x3c!-- fold --\x3e"),e.closeBlock(t)},parse:{updateDOM(e){e.querySelectorAll("h1,h2,h3,h4,h5,h6").forEach(e=>{let t=e.lastChild;for(;t&&3===t.nodeType&&!(t.textContent||"").trim();){let r=t.previousSibling;e.removeChild(t),t=r}if(t&&8===t.nodeType&&/^\s*fold\s*$/.test(t.textContent||"")){let r=t.previousSibling;e.removeChild(t),r&&3===r.nodeType&&(r.textContent=(r.textContent||"").replace(/\s+$/,"")),e.setAttribute("data-collapsed","true")}})}}}}),addProseMirrorPlugins:()=>[new C.k_({key:M,state:{init:(e,{doc:t})=>E(t),apply:(e,t)=>e.docChanged?E(e.doc):t},props:{decorations:e=>M.getState(e)}})]});function T(e){let t=[];return e.forEach((e,r)=>t.push({node:e,start:r,end:r+e.nodeSize})),t}function $(e,t){return"heading"===e.type.name&&e.attrs.level<=t}function R(e){for(let t=e.depth;t>0;t--){let r=e.node(t).type.name;if("listItem"===r||"taskItem"===r)return t}return -1}function I(e,t,r,n,s){let o=t.slice(r,n),a=t.slice(n,s);e.replaceWith(r,s,a.content.append(o.content))}function F(e,t){let r=Math.max(0,Math.min(t,e.doc.content.size));e.setSelection(C.U3.near(e.doc.resolve(r)))}let B=new Set(["paragraph","bulletList","orderedList","taskList"]);function D(e,t,r){let{doc:n,selection:s}=e,o=s.$from,a=o.before(1),l=T(n),i=l.findIndex(e=>e.start===a);if(i<0)return!1;let d=i;for(;d>0&&B.has(l[d-1].node.type.name);)d--;let c=i;for(;c<l.length-1&&B.has(l[c+1].node.type.name);)c++;let u=[],m=-1,x="paragraph"===l[i].node.type.name?-1:o.index(1);for(let e=d;e<=c;e++){let t=l[e].node;if("paragraph"===t.type.name)e===i&&(m=u.length),u.push({kind:"paragraph",node:t});else{let r=t.type.name,n=0;t.forEach(t=>{e===i&&n===x&&(m=u.length),u.push({kind:r,node:t}),n++})}}if(m<0)return!1;let h=m+(r>0?1:-1);if(h<0||h>=u.length)return!1;if(t){let r,n,s,a=u[m];u[m]=u[h],u[h]=a;let i=function(e,t){let r=[],n=0;for(;n<e.length;){if("paragraph"===e[n].kind){r.push(e[n].node),n++;continue}let s=e[n].kind,o=[];for(;n<e.length&&e[n].kind===s;)o.push(e[n].node),n++;r.push(t.schema.nodes[s].create(null,o))}return y.FK.from(r)}(u,e),x=l[d].start,f=l[c].end,p=e.tr;p.replaceWith(x,f,i);let g=(r=0,n=0,s=-1,i.forEach(e=>{if(!(s>=0))if("paragraph"===e.type.name)r===h&&(s=n+1),r++,n+=e.nodeSize;else{let t=n+1;e.forEach(e=>{s>=0||(r===h&&(s=t+2),r++,t+=e.nodeSize)}),n+=e.nodeSize}}),s);F(p,g>=0?x+g+o.parentOffset:x),t(p.scrollIntoView())}return!0}function A(e,t,r){let n=e.selection.$from;if(1===n.depth&&"heading"===n.parent.type.name)return function(e,t,r){let{doc:n,selection:s}=e,o=s.$from.before(1),a=T(n),l=a.findIndex(e=>e.start===o);if(l<0)return!1;let i=a[l].node.attrs.level,d=l+1;for(;d<a.length&&!$(a[d].node,i);)d++;let c=a[l].start,u=a[d-1].end;if(r>0){if(d>=a.length)return!1;let r=a[d].node.attrs.level,o=d+1;for(;o<a.length&&!$(a[o].node,r);)o++;let l=a[o-1].end;if(t){let r=e.tr,o=n.slice(u,l).content.size;I(r,n,c,u,l),F(r,c+o+(s.from-c)),t(r.scrollIntoView())}return!0}if(0===l)return!1;let m=l-1;for(;m>=0&&!$(a[m].node,i);)m--;if(m<0||a[m].node.attrs.level<i)return!1;let x=a[m].start;if(t){let r=e.tr;I(r,n,x,c,u),F(r,x+(s.from-c)),t(r.scrollIntoView())}return!0}(e,t,r);let s=R(n);if(s>0){let o=n.node(s-1),a=n.index(s-1);return(r>0?a<o.childCount-1:a>0)?function(e,t,r,n){let{doc:s,selection:o}=e,a=o.$from,l=a.node(n),i=a.node(n-1),d=a.index(n-1),c=a.before(n),u=c+l.nodeSize;if(r>0){if(d>=i.childCount-1)return!1;let r=u+i.child(d+1).nodeSize;if(t){let n=e.tr,a=s.slice(u,r).content.size;I(n,s,c,u,r),F(n,c+a+(o.from-c)),t(n.scrollIntoView())}return!0}if(d<=0)return!1;let m=c-i.child(d-1).nodeSize;if(t){let r=e.tr;I(r,s,m,c,u),F(r,m+(o.from-c)),t(r.scrollIntoView())}return!0}(e,t,r,s):2===s&&D(e,t,r)}let o=n.depth>=1?n.node(n.depth-1).type.name:"doc";return"paragraph"===n.parent.type.name&&"doc"===o&&D(e,t,r)}function H(e,t){let{state:r}=e,n=r.selection.$from,s=n.parent.type.name;if("doc"===(n.depth>=1?n.node(n.depth-1).type.name:"doc")&&("heading"===s||"paragraph"===s)){let r=(("heading"===s?n.parent.attrs.level-1:3)+(t>0?1:-1)+4)%4;return 3===r?e.chain().setParagraph().run():e.chain().setHeading({level:r+1}).run()}let o=R(n);if(o>0){let r=n.node(o).type.name;return t<0?e.commands.liftListItem(r):e.commands.sinkListItem(r)}return!1}function W(e,t){let{state:r}=e,n=r.selection;if(!n.empty)return!1;let s=n.$from,o=t>0?1:-1;for(let t=s.depth;t>0;t--)if("taskItem"===s.node(t).type.name){let n=s.before(t),a=r.doc.nodeAt(n);if(!a)return!1;let l=a.attrs.status??"todo",i=(("doing"===l?2:"done"===l?3:1)+o+4)%4;if(0===i)return e.chain().toggleTaskList().run();let d=2===i?"doing":3===i?"done":"todo";return e.chain().command(({tr:e})=>{let t=e.doc.nodeAt(n);return!!t&&(e.setNodeMarkup(n,void 0,{...t.attrs,status:d}),!0)}).run()}if("paragraph"!==s.parent.type.name)return!1;let a=s.depth>=1?s.node(s.depth-1).type.name:"doc";return("doc"===a||"listItem"===a)&&(1==(0+o+4)%4?e.chain().toggleTaskList().run():e.chain().toggleTaskList().command(({tr:e})=>(function(e,t){let r=e.selection.$from;for(let n=r.depth;n>0;n--)if("taskItem"===r.node(n).type.name){let s=r.before(n),o=e.doc.nodeAt(s);o&&e.setNodeMarkup(s,void 0,{...o.attrs,status:t});break}return!0})(e,"done")).run())}let z=f.YY.create({name:"noteOrgKeymap",addKeyboardShortcuts(){return{"Alt-ArrowUp":()=>this.editor.commands.command(({state:e,dispatch:t})=>A(e,t,-1)),"Alt-ArrowDown":()=>this.editor.commands.command(({state:e,dispatch:t})=>A(e,t,1)),"Alt-ArrowLeft":()=>H(this.editor,-1),"Alt-ArrowRight":()=>H(this.editor,1),"Shift-ArrowRight":()=>W(this.editor,1),"Shift-ArrowLeft":()=>W(this.editor,-1)}}});function O(e){return e.storage.markdown.getMarkdown()}function _(){return[{label:a.A.t("slashCommands.heading1"),icon:"H1",description:a.A.t("slashCommands.heading1Desc"),action:e=>e.chain().focus().toggleHeading({level:1}).run()},{label:a.A.t("slashCommands.heading2"),icon:"H2",description:a.A.t("slashCommands.heading2Desc"),action:e=>e.chain().focus().toggleHeading({level:2}).run()},{label:a.A.t("slashCommands.heading3"),icon:"H3",description:a.A.t("slashCommands.heading3Desc"),action:e=>e.chain().focus().toggleHeading({level:3}).run()},{label:a.A.t("slashCommands.bulletList"),icon:"•",description:a.A.t("slashCommands.bulletListDesc"),action:e=>e.chain().focus().toggleBulletList().run()},{label:a.A.t("slashCommands.orderedList"),icon:"1.",description:a.A.t("slashCommands.orderedListDesc"),action:e=>e.chain().focus().toggleOrderedList().run()},{label:a.A.t("slashCommands.taskList"),icon:"☑",description:a.A.t("slashCommands.taskListDesc"),action:e=>e.chain().focus().toggleTaskList().run()},{label:a.A.t("slashCommands.blockquote"),icon:"❝",description:a.A.t("slashCommands.blockquoteDesc"),action:e=>e.chain().focus().toggleBlockquote().run()},{label:a.A.t("slashCommands.codeBlock"),icon:"<>",description:a.A.t("slashCommands.codeBlockDesc"),action:e=>e.chain().focus().toggleCodeBlock().run()},{label:a.A.t("slashCommands.table"),icon:"▦",description:a.A.t("slashCommands.tableDesc"),action:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{label:a.A.t("slashCommands.horizontalRule"),icon:"──",description:a.A.t("slashCommands.horizontalRuleDesc"),action:e=>e.chain().focus().setHorizontalRule().run()},{label:a.A.t("slashCommands.link"),icon:"\uD83D\uDD17",description:a.A.t("slashCommands.linkDesc"),action:e=>{window.dispatchEvent(new CustomEvent("tiptap-insert-link"))}}]}function q({editor:e,query:t,position:r,onClose:o}){let[a,l]=(0,s.useState)(0),i=(0,s.useRef)(null),d=_().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>l(0))},[t]);let c=r=>{e.chain().focus().deleteRange({from:e.state.selection.from-t.length-1,to:e.state.selection.from}).run(),r.action(e),o()};return((0,s.useEffect)(()=>{let e=e=>{"ArrowDown"===e.key?(e.preventDefault(),l(e=>(e+1)%d.length)):"ArrowUp"===e.key?(e.preventDefault(),l(e=>(e-1+d.length)%d.length)):"Enter"===e.key?(e.preventDefault(),d[a]&&c(d[a])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[d,a,o]),0===d.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lv2 py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:d.map((e,t)=>(0,n.jsxs)("button",{className:`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors ${t===a?"bg-accent text-foreground":"text-muted-foreground hover:bg-hover hover:text-foreground"}`,onClick:()=>c(e),onMouseEnter:()=>l(t),children:[(0,n.jsx)("span",{className:"w-6 text-center text-xs font-mono flex-shrink-0",children:e.icon}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium",children:e.label}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:e.description})]})]},e.label))})}_();var V=r(76043),U=r(86957),K=r(49433),Q=r(34075),G=r(66109),J=r(39872),Y=r(92451),X=r(76900);let Z=/^\s*[-*+]\s+(?:\\?\[ \\?\]|\\?\[[xX/]\\?\])\s*$/,ee=/^\s*(```|~~~)/;function et(e){return e.classList.contains("task-list-item")}let er=/^\s*\[\/\]\s?/,en=f.YY.create({name:"markdownTaskListFix",addStorage:()=>({markdown:{parse:{updateDOM(e){var t;for(let r of Array.from(e.querySelectorAll("li"))){if(et(r))continue;let e=r.parentElement;e&&"UL"===e.tagName&&(t=r.textContent||"",/^\s*\[\/\]/.test(t)&&(!function(e){let t=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=t.nextNode();for(;r&&!(r.nodeValue&&""!==r.nodeValue.trim());)r=t.nextNode();r&&r.nodeValue&&(r.nodeValue=r.nodeValue.replace(er,""))}(r),r.classList.add("task-list-item"),r.setAttribute("data-type","taskItem"),r.setAttribute("data-status","doing"),e.classList.add("contains-task-list")))}!function(e){for(let t of Array.from(e.querySelectorAll("ul.contains-task-list"))){let e=Array.from(t.children).filter(e=>"LI"===e.tagName);if(0===e.length)continue;let r=function(e){let t=[];for(let r of e){let e=t[t.length-1];e&&e.isTask===r.isTask?e.items.push(r):t.push({isTask:r.isTask,items:[r]})}return t}(e.map(e=>({isTask:et(e),el:e})));if(r.length<=1){r[0]?.isTask&&t.setAttribute("data-type","taskList");continue}let n=t.ownerDocument,s=n.createDocumentFragment();for(let e of r){let t=n.createElement("ul");for(let{el:r}of(e.isTask&&(t.setAttribute("class","contains-task-list"),t.setAttribute("data-type","taskList")),e.items))t.appendChild(r);s.appendChild(t)}t.replaceWith(s)}}(e)}}}})});var es=r(8242);let eo=new Set(["taskItem","listItem"]),ea=f.YY.create({name:"dropShellCleanup",addProseMirrorPlugins:()=>[new C.k_({key:new C.hs("dropShellCleanup"),appendTransaction(e,t,r){let n=[];if(e.forEach((t,r)=>{let s;if("drop"!==t.getMeta("uiEvent")||!t.docChanged)return;let o=(s=[],t.steps.forEach((e,r)=>{e instanceof es.Ln&&(0!==e.slice.size||e.from>=e.to||s.push(t.mapping.slice(r+1).map(e.from)))}),s);for(let t=r+1;t<e.length;t++)o=o.map(r=>e[t].mapping.map(r));n.push(...o)}),0===n.length)return null;let s=r.tr,o=!1;for(let e of n){let t=function(e,t){if(t<0||t>e.content.size)return null;let r=e.resolve(t);for(let e=r.depth;e>0;e--){var n;if(n=r.node(e),!eo.has(n.type.name)||1!==n.childCount||null===n.firstChild||!n.firstChild.isTextblock||0!==n.firstChild.content.size)continue;let t=e;for(;t>1&&1===r.node(t-1).childCount;)t--;return{from:r.before(t),to:r.after(t)}}return null}(s.doc,s.mapping.map(e));if(t)try{s.delete(t.from,t.to),o=!0}catch{}}return o?s:null}})]}),el=e=>e.split("/").filter(Boolean).pop()||e,ei=e=>e??"";function ed({isOpen:e,onClose:t,projectCwd:r,currentCwd:f,projectOrder:p}){let{t:g}=(0,o.Bd)(),[b,v]=(0,s.useState)(r??null),N=(0,s.useRef)(ei(r??null)),C=(0,s.useRef)(r??null),[S,M]=(0,s.useState)([]),[L,E]=(0,s.useState)(""),[T,$]=(0,s.useState)(!0),[R,I]=(0,s.useState)(!1),F=(0,s.useRef)(null),B=(0,s.useRef)(!1),D=(0,s.useRef)(void 0),[A,H]=(0,s.useState)(null),W=(0,s.useRef)(null),_=(0,s.useCallback)(()=>{U.t4.runPromiseExit((0,X.zv)()).then(e=>{"Success"===e._tag&&M(e.value)})},[]),et=(0,s.useCallback)(async(e,t)=>{let r=function(e){if(!e)return e;let t=e.split("\n"),r=[],n=!1;for(let e of t){if(ee.test(e)){n=!n,r.push(e);continue}if(n){r.push(e);continue}Z.test(e)||r.push(e)}let s=[],o=0,a=!1;for(let e of r){if(ee.test(e)){a=!a,s.push(e),o=0;continue}if(!a&&""===e.trim()){if((o+=1)>=2)continue;s.push(e);continue}o=0,s.push(e)}return s.join("\n")}(t);I(!0);let n=D.current,s=await U.t4.runPromiseExit((0,X.Cq)(e,r,n).pipe(K.sFT(e=>K.OH5(()=>console.error("Failed to save note:",e))))),o=N.current===ei(e);if("Success"===s._tag){let e=s.value;e.conflict&&!o?(0,Q.oR)(g("editor.conflictReloaded"),"info"):e.conflict?(eo.current?.commands.setContent(e.content,{emitUpdate:!1}),D.current=e.mtime,B.current=!1,(0,Q.oR)(g("editor.conflictReloaded"),"info")):o&&(D.current=e.mtime,B.current=!1),_()}I(!1)},[g,_]),er=(0,s.useCallback)(e=>{B.current=!0,F.current&&clearTimeout(F.current);let t=C.current;F.current=setTimeout(()=>{et(t,e)},5e3)},[et]),es=(0,l.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:!1,link:!1}),P.configure({levels:[1,2,3]}),z,d.A.configure({placeholder:()=>a.A.t("editor.placeholder")}),c.XI.configure({resizable:!0}),u.H,m.n,x.A,h._,w.Ay.configure({autolink:!0,linkOnPaste:!0,openOnClick:!1,HTMLAttributes:{class:"tiptap-link",target:"_blank",rel:"noopener noreferrer"}}),j.configure({nested:!0}),en,ea,k.o.configure({html:!0,transformCopiedText:!1,transformPastedText:!0})],editorProps:{attributes:{class:"tiptap-editor focus:outline-none min-h-[60vh] px-6 py-4"},clipboardTextSerializer:e=>e.content.textBetween(0,e.content.size,"\n").replace(/\n+$/,""),transformCopied:e=>{let t=e=>!!e&&e.isTextblock&&0===e.content.size,r=e.content,{openStart:n,openEnd:s}=e;for(;r.childCount>1&&t(r.lastChild);)r=r.cut(0,r.size-r.lastChild.nodeSize),s=0;for(;r.childCount>1&&t(r.firstChild);)r=r.cut(r.firstChild.nodeSize),n=0;return new y.Ji(r,n,s)},handleClick:(e,t,r)=>{if(r.metaKey||r.ctrlKey){let r=e.state.doc.resolve(t).marks().find(e=>"link"===e.type.name)?.attrs;if(r?.href)return window.open(r.href,"_blank","noopener,noreferrer"),!0}return!1},handleKeyDown:(e,t)=>{if("Backspace"===t.key&&eo.current){let e=eo.current;if(e.isActive("codeBlock")){let{$from:t}=e.state.selection,r=t.node(t.depth);if("codeBlock"===r.type.name&&""===r.textContent)return e.chain().focus().toggleCodeBlock().run(),!0}}return"/"!==t.key||A||setTimeout(()=>{if(!eo.current)return;let{from:e}=eo.current.state.selection;if("/"===eo.current.state.doc.textBetween(Math.max(0,e-1),e,"\n")){W.current=e;let t=eo.current.view.coordsAtPos(e);H({query:"",position:{top:t.bottom+4,left:t.left}})}},0),!1}},onUpdate:({editor:e})=>{if(er(O(e)),null!==W.current){let{from:t}=e.state.selection;if(t<W.current)H(null),W.current=null;else{let r=e.state.doc.textBetween(W.current,t,"\n");r.includes(" ")||r.includes("\n")?(H(null),W.current=null):H(e=>e?{...e,query:r}:null)}}}}),eo=(0,s.useRef)(null);(0,s.useEffect)(()=>{eo.current=es},[es]),(0,s.useEffect)(()=>{if(!e)return;let t=r??null;C.current=t,N.current=ei(t),v(t),E(""),_()},[e,r,_]),(0,s.useEffect)(()=>{if(!e||!es)return;$(!0),H(null),W.current=null;let t=!1;return U.t4.runPromiseExit((0,X.zF)(b)).then(e=>{t||("Success"===e._tag?(es.commands.setContent(e.value.content||"",{emitUpdate:!1}),D.current=e.value.mtime,F.current&&(clearTimeout(F.current),F.current=null),B.current=!1):console.error("Failed to load note:",e.cause),$(!1))}),()=>{t=!0}},[e,es,b]);let ec=(0,s.useCallback)(()=>{F.current&&(clearTimeout(F.current),F.current=null),B.current&&es&&(et(C.current,O(es)),B.current=!1)},[es,et]),eu=(0,s.useCallback)(e=>{ei(e)!==N.current&&(ec(),C.current=e,N.current=ei(e),v(e))},[ec]),em=(0,s.useCallback)(()=>{ec(),H(null),W.current=null,t()},[ec,t]);(0,s.useEffect)(()=>()=>{F.current&&clearTimeout(F.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(A?(H(null),W.current=null):em())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,em,A]);let ex=(0,s.useMemo)(()=>{let e=new Map(S.map(e=>[ei(e.cwd),e])),t=new Set([""]),n=[{cwd:null,entry:e.get("")}];for(let s of[r??null,f??null])!s||t.has(ei(s))||e.has(ei(s))||(t.add(ei(s)),n.push({cwd:s}));for(let e of[...S].sort((e,t)=>t.mtime-e.mtime))t.has(ei(e.cwd))||(t.add(ei(e.cwd)),n.push({cwd:e.cwd,entry:e}));return n},[S,r,f]),eh=(0,s.useCallback)(e=>e?el(e):g("editor.globalNote"),[g]),ef=(0,s.useMemo)(()=>{let e=L.trim().toLowerCase();return e?ex.filter(({cwd:t,entry:r})=>eh(t).toLowerCase().includes(e)||(t?.toLowerCase().includes(e)??!1)||(r?.searchText.includes(e)??!1)):ex},[ex,L,eh]);if(!e)return null;let ep=ei(b);return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:em}),(0,n.jsxs)("div",{className:G.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:b?g("editor.noteTitle",{name:el(b)}):g("editor.globalNote")}),R&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:g("editor.saving")})]}),(0,n.jsx)("button",{onClick:em,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsxs)("div",{className:"hidden md:flex w-[300px] min-h-0 flex-shrink-0 border-r border-border flex-col",children:[(0,n.jsx)("div",{className:"p-3 flex-shrink-0 border-b border-border",children:(0,n.jsx)("input",{type:"text",placeholder:g("editor.searchNotes"),value:L,onChange:e=>E(e.target.value),className:"w-full px-2 py-1 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto p-2 space-y-0.5",children:ef.map(({cwd:e,entry:t})=>{let r=e?p.indexOf(e)+1:0,s=ei(e)===ep;return(0,n.jsxs)("div",{onClick:()=>eu(e),title:e??void 0,className:`rounded-md px-3 py-2 cursor-pointer transition-colors ${s?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0",children:[null===e?(0,n.jsx)(Y.A,{className:"w-[18px] h-[18px] p-0.5 flex-shrink-0 text-muted-foreground"}):r>0?(0,n.jsx)(J.B,{number:r,isActive:e===f}):(0,n.jsx)("span",{className:"w-[18px] flex-shrink-0"}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground truncate flex-1 min-w-0",children:eh(e)}),t&&t.mtime>0&&(0,n.jsx)("span",{className:"text-[10px] text-muted-foreground flex-shrink-0",children:function(e,t){let r=Math.floor((Date.now()-t)/6e4);if(r<1)return e("common.justNow");if(r<60)return e("common.minutesAgo",{count:r});let n=Math.floor(r/60);return n<24?e("common.hoursAgo",{count:n}):e("common.daysAgo",{count:Math.floor(n/24)})}(g,t.mtime)})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-6",children:t?.firstLine||g("editor.emptyNote")})]},ei(e)||"(global)")})})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsx)(V.NoteToolbar,{editor:es}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:T?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:(0,n.jsx)("span",{children:g("common.loading")})}):(0,n.jsx)(l.$Z,{editor:es})})]})]})]}),A&&es&&(0,n.jsx)(q,{editor:es,query:A.query,position:A.position,onClose:()=>{H(null),W.current=null}})]})}},63728:(e,t,r)=>{r.d(t,{R8:()=>i,c0:()=>c,fY:()=>d,gT:()=>u});var n=r(95155),s=r(12115);let o=["agent","explorer","console"],a={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},l=(0,s.createContext)(null);function i(){let e=(0,s.useContext)(l);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function d({activeView:e,onViewChange:t,children:r,onOverscroll:a}){let i=(0,s.useRef)(null),c=(0,s.useRef)(!1),u=(0,s.useRef)(0),m=(0,s.useRef)(0),x=(0,s.useRef)(null),h=(0,s.useRef)(null),f=(0,s.useRef)(0),p=(0,s.useRef)(a);(0,s.useEffect)(()=>{p.current=a},[a]);let[g,b]=(0,s.useState)(0),[v,j]=(0,s.useState)(!1),w=o.indexOf(e),k=o.length-1;(0,s.useEffect)(()=>{u.current=0,m.current=0,h.current=null,queueMicrotask(()=>b(0))},[e]),(0,s.useEffect)(()=>{let e=e=>{if(Math.abs(e.deltaX)>Math.abs(e.deltaY)&&Math.abs(e.deltaX)>2){var r,n,s;let a=e.target;if("IFRAME"===a.tagName)return;let l=performance.now(),d=(r=f.current,n=h.current,s=()=>(function(e){for(;e;){let t=window.getComputedStyle(e).overflowX;if(("auto"===t||"scroll"===t)&&e.scrollWidth-e.clientWidth>1)return!0;e=e.parentElement}return!1})(a),null!==n&&l-r<=180?n:s()?"inner":"switcher");if(h.current=d,f.current=l,"inner"===d)return;e.preventDefault(),e.stopPropagation(),c.current&&(c.current=!1);let g=window.innerWidth,v=u.current-6*e.deltaX,y=w>0,N=w<k,C=!1;!y&&v>0&&(m.current+=v,x.current=a,v=0,C=!0),!N&&v<0&&(m.current+=v,x.current=a,v=0,C=!0),C&&p.current?.({offset:m.current,phase:"move",triggered:!1,target:a}),u.current=v=Math.max(-g,Math.min(g,v)),b(v),j(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{let e=u.current,r=m.current,n=x.current;m.current=0,x.current=null;let s=.12*g;j(!1),c.current=!0;let a=w;e<-s&&w<k?a=w+1:e>s&&w>0&&(a=w-1),u.current=0,b(0),a!==w&&t(o[a]),a===w&&0!==r&&p.current?.({offset:r,phase:"release",triggered:Math.abs(r)>.2*g,target:n}),setTimeout(()=>{c.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[w,k,t]);let[y,N]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>N(!0))},[]);let C={activeView:e,onViewChange:t,dragOffset:(()=>{if(!y)return 0;let e=window.innerWidth;return e?g/e:0})(),isDragging:y&&v};return(0,n.jsx)(l.Provider,{value:C,children:r})}function c({children:e}){let t,r,{activeView:a,dragOffset:l,isDragging:d}=i(),u=(0,s.useRef)(null),m=(0,s.useRef)(null),x=o.indexOf(a),h=o.length;return(0,s.useEffect)(()=>{let e=u.current;if(!e)return;let t=()=>{0!==e.scrollLeft&&(e.scrollLeft=0)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),(0,n.jsx)("div",{ref:u,className:"flex-1 overflow-hidden relative",style:{overscrollBehaviorX:"none"},children:(0,n.jsx)("div",{ref:m,className:d?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*o.length}%`,transform:(t=l/h*100,r=-(100/h*x)+(Number.isFinite(t)?t:0),`translateX(${r}%)`)},children:e})})}function u(){let{activeView:e,onViewChange:t,dragOffset:r,isDragging:l}=i(),d=(0,s.useRef)(null),c=(0,s.useRef)([]),[u,m]=(0,s.useState)({left:0,width:0}),x=o.indexOf(e),h=()=>{if(!d.current||0===c.current.length)return{left:0,width:0};let e=d.current.getBoundingClientRect(),t=c.current.filter(Boolean);if(t.length!==o.length)return{left:0,width:0};let n=Number.isFinite(r)?r:0,s=Math.max(0,Math.min(o.length-1,x-n)),a=Math.floor(s),l=Math.ceil(s),i=s-a,u=t[a],m=t[l];if(!u||!m)return{left:0,width:0};let h=u.getBoundingClientRect(),f=m.getBoundingClientRect();return{left:h.left+(f.left-h.left)*i-e.left,width:h.width+(f.width-h.width)*i}};(0,s.useEffect)(()=>{queueMicrotask(()=>m(h()))},[x,r]),(0,s.useEffect)(()=>{let e=()=>{m(h())};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[x,r]);let f=Number.isFinite(r)?r:0,p=Math.round(Math.max(0,Math.min(o.length-1,x-f)));return(0,n.jsxs)("div",{ref:d,className:"relative flex gap-4",children:[o.map((e,r)=>(0,n.jsx)("button",{ref:e=>{c.current[r]=e},onClick:()=>t(e),className:`px-4 py-1 text-sm font-medium transition-colors ${p===r?"text-brand":"text-muted-foreground hover:text-foreground"}`,children:a[e]},e)),(0,n.jsx)("div",{className:`absolute bottom-0 h-0.5 bg-brand ${l?"":"transition-all duration-100 ease-out"}`,style:{left:u.left,width:u.width}})]})}},71077:(e,t,r)=>{r.d(t,{AS:()=>y,HV:()=>j,If:()=>w,RS:()=>p,TN:()=>g,d$:()=>C,mO:()=>v,tr:()=>b});let n=null,s="",o=0,a=null,l=!1,i=new Map,d=null,c=null;function u(e){let t="https:"===window.location.protocol?"wss:":"ws:";return`${t}//${window.location.host}/ws/terminal?projectCwd=${encodeURIComponent(e)}`}function m(e){let t;try{t=JSON.parse(e.data)}catch{return}let r=t.type;if("ping"===r)return;if("running"===r){d&&(d(t.commands),d=null);return}let n=t.commandId;if(!n)return;let s=i.get(n);if(s){if("error"===r)s.onError(t.error);else{let{commandId:e,type:n,...o}=t;s.onData(r,o)}("exit"===r||"error"===r)&&i.delete(n)}}function x(e){n?.readyState===WebSocket.OPEN&&n.send(JSON.stringify(e))}function h(e){let t=u(e);s===t&&n||(y(),l=!1,s=t,function e(){if(l||!s)return;let t=new WebSocket(s);n=t,t.onopen=()=>{for(let e of(o=0,i.keys()))t.send(JSON.stringify({type:"attach",commandId:e}))},t.onmessage=m,t.onclose=()=>{if(n!==t||(n=null,l))return;a&&clearTimeout(a);let r=Math.min(1e3*Math.pow(1.5,o),1e4);o++,a=setTimeout(e,r)},t.onerror=()=>{}}())}function f(){return new Promise((e,t)=>{if(n?.readyState===WebSocket.OPEN)return void e();let r=setInterval(()=>{n?.readyState===WebSocket.OPEN&&(clearInterval(r),clearTimeout(s),e())},50),s=setTimeout(()=>{clearInterval(r),t(Error("WebSocket connection timeout"))},5e3)})}async function p(e){let{cwd:t,command:r,commandId:n,tabId:s,projectCwd:o,env:a,usePty:l,cols:d,rows:c,sourceId:u,onData:m,onError:p}=e;h(o);try{await f()}catch{p("WebSocket connection failed");return}i.delete(n),i.set(n,{onData:m,onError:p}),x({type:"exec",commandId:n,command:r,cwd:t,tabId:s,env:a,...l?{usePty:!0}:{},...d?{cols:d,rows:c}:{},...u?{sourceId:u}:{}})}async function g(e){let{commandId:t,projectCwd:r,onData:n,onError:s}=e;h(r);try{await f()}catch{s("WebSocket connection failed");return}i.set(t,{onData:n,onError:s}),x({type:"attach",commandId:t})}function b(e,t){x({type:"stdin",commandId:e,data:t})}function v(e,t,r){x({type:"resize",commandId:e,cols:t,rows:r})}function j(e){x({type:"interrupt",pid:e})}function w(e){return c||(c=k(e))}async function k(e){try{h(e);try{await f()}catch{return[]}return await new Promise(e=>{d=t=>{e(t)},x({type:"running"}),setTimeout(()=>{d&&(d=null,e([]))},3e3)})}finally{c=null}}function y(){if(l=!0,a&&(clearTimeout(a),a=null),n){let e=n;n=null,e.close()}i.clear(),d&&(d([]),d=null),c=null,s="",o=0}let N=/^(?:\x1b\[\??[\d;]*R|\x1b\[[?>][\d;]*c|\x1b\]\d+;[^\x07\x1b]*(?:\x07|\x1b\\))$/;function C(e){let{projectCwd:t,commandId:r,onOutput:n,onEnd:s,onAttached:o}=e,a=new WebSocket(u(t));return a.onopen=()=>a.send(JSON.stringify({type:"attach",commandId:r})),a.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.commandId===r)if("pid"===t.type){let e="number"==typeof t.cols&&"number"==typeof t.rows;o?.(e?{cols:t.cols,rows:t.rows}:void 0)}else"stdout"===t.type||"stderr"===t.type?n(String(t.data??"")):("exit"===t.type||"error"===t.type)&&s()},{close:()=>{a.onopen=null,a.onmessage=null,a.close()},sendInput:e=>{N.test(e)||a.readyState!==WebSocket.OPEN||a.send(JSON.stringify({type:"stdin",commandId:r,data:e}))}}}},72363:(e,t,r)=>{r.d(t,{$2:()=>j,N4:()=>c,_I:()=>v,fX:()=>u,fZ:()=>m});let n="cockpit update",s={visible:!1,stage:"preparing",startedAt:0,baselineMs:null,installedVersion:null,upToDate:!1,error:null,rolledBack:!1,fixCommand:n,logPath:null,live:!1},o="cockpit:update-seen-at",a=s,l=new Set,i=!1;function d(e){a={...a,...e},l.forEach(e=>e())}function c(e){return l.add(e),()=>l.delete(e)}function u(){return a}function m(){try{window.localStorage.setItem(o,String(Date.now()))}catch{}d({visible:!1})}let x=e=>new Promise(t=>setTimeout(t,e));async function h(){try{let e=await fetch("/api/health",{cache:"no-store",signal:AbortSignal.timeout(2e3)});if(!e.ok)return null;let t=await e.json();return{pid:"number"==typeof t.pid?t.pid:null,version:t.version??null}}catch{return null}}async function f(){try{let e=await fetch("/api/update-state",{cache:"no-store",signal:AbortSignal.timeout(2e3)});if(!e.ok)return{state:null,logPath:null};let t=await e.json();return{state:t.state??null,logPath:t.logPath??null}}catch{return{state:null,logPath:null}}}async function p(e){try{let t=await fetch(`http://127.0.0.1:${e}/`,{cache:"no-store",signal:AbortSignal.timeout(1500)});if(!t.ok)return null;return await t.json()}catch{return null}}function g(e){switch(e){case"installing":return"installing";case"repairing":return"repairing";case"rolling-back":return"rolling-back";case"restarting":case"done":return"restarting";default:return"preparing"}}function b(e,t={}){d({stage:"failed",error:e,...t})}async function v(){if(!i){i=!0,d({...s,visible:!0,stage:"preparing",startedAt:Date.now()});try{let e=await f();d({baselineMs:e.state?.installMs??e.state?.prevInstallMs??null,logPath:e.logPath});let t=await h(),r=t?.pid??null,s=t?.version??null,o=await fetch("/api/update",{method:"POST"});if(!o.ok){let e=await o.json().catch(()=>({}));b(e.error??`HTTP ${o.status}`);return}let l=await o.json().catch(()=>({})),i=l.statusPort??null;d({logPath:l.logPath??a.logPath});let c=0,u=null!==i,m=Date.now()+3e5;for(;Date.now()<m;){if(await x(1e3),u&&null!==i){let e=await p(i);if(e){if(c=0,d({live:!0}),"failed"===e.phase)return void b(e.error??"install failed",{rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n,live:!0});d({stage:g(e.phase),installedVersion:e.installed??a.installedVersion,baselineMs:a.baselineMs??e.prevInstallMs??null})}else++c>=3&&(u=!1,d({live:!1}))}let e=await h();if(e?.pid!=null&&(null===r||e.pid!==r)){let{state:t}=await f();if(t?.phase==="failed")return void b(t.error??"update failed",{rolledBack:!0===t.rolledBack,fixCommand:t.fixCommand??n});let r=e.version??a.installedVersion;d({stage:"done",installedVersion:r,upToDate:null!==r&&r===s});return}}b("timeout")}catch(e){b(e instanceof Error?e.message:String(e))}finally{i=!1}}}async function j(){if(i||a.visible)return;let{state:e,logPath:t}=await f();if(!e?.phase||"done"===e.phase)return;let r=e.startedAt??0,l=e.installMs??e.prevInstallMs??null;if("failed"===e.phase){let a=0;try{a=Number(window.localStorage.getItem(o))||0}catch{}if((e.finishedAt??0)<=a)return;d({...s,visible:!0,stage:"failed",startedAt:r,baselineMs:l,error:e.error??"unknown error",rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n,logPath:t});return}if(!(!r||Date.now()-r>6e5)){i=!0,d({...s,visible:!0,stage:g(e.phase),startedAt:r,baselineMs:l,logPath:t});try{let e=r+3e5;for(;Date.now()<e;){await x(1e3);let{state:e}=await f();if(e?.phase){if("failed"===e.phase)return void b(e.error??"install failed",{rolledBack:!0===e.rolledBack,fixCommand:e.fixCommand??n});if("done"===e.phase)return void d({stage:"done",installedVersion:e.installed??null,upToDate:!0===e.unchanged});d({stage:g(e.phase)})}}b("timeout")}finally{i=!1}}}},76043:(e,t,r)=>{r.d(t,{NoteToolbar:()=>l});var n=r(95155),s=r(12115),o=r(79114);function a({editor:e,onClose:t,position:r}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(()=>e.getAttributes("link").href||""),c=(0,s.useRef)(null);(0,s.useEffect)(()=>{c.current?.focus()},[]);let u=()=>{let r=i.trim();if(r){let t=r.match(/^https?:\/\//)?r:`https://${r}`;e.chain().focus().extendMarkRange("link").setLink({href:t}).run()}else e.chain().focus().extendMarkRange("link").unsetLink().run();t()},m=r?{top:r.top,left:r.left}:{};return(0,n.jsxs)("div",{className:`${r?"fixed":"absolute top-full left-0 mt-1"} z-[60] bg-popover border border-border rounded-lg shadow-lv2 p-2 flex items-center gap-2`,style:m,children:[(0,n.jsx)("input",{ref:c,type:"text",value:i,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),u()):"Escape"===e.key&&(e.preventDefault(),t())},placeholder:l("editor.linkPlaceholder"),className:"bg-background border border-border rounded px-2 py-1 text-sm w-64 outline-none focus:border-brand"}),(0,n.jsx)("button",{onClick:u,className:"p-1 rounded text-sm font-medium text-brand hover:bg-brand/10 transition-colors",title:l("editor.confirmLink"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})})}),e.isActive("link")&&(0,n.jsx)("button",{onClick:()=>{e.chain().focus().extendMarkRange("link").unsetLink().run(),t()},className:"p-1 rounded text-sm font-medium text-red-11 hover:bg-red-500/10 transition-colors",title:l("editor.removeLink"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]})}function l({editor:e}){let{t}=(0,o.Bd)(),[r,i]=(0,s.useState)(!1),d=(0,s.useRef)(null),[,c]=(0,s.useState)(0);if((0,s.useEffect)(()=>{if(!e)return;let t=()=>c(e=>e+1);return e.on("selectionUpdate",t),e.on("transaction",t),()=>{e.off("selectionUpdate",t),e.off("transaction",t)}},[e]),(0,s.useEffect)(()=>{let e=()=>i(!0);return window.addEventListener("tiptap-insert-link",e),()=>window.removeEventListener("tiptap-insert-link",e)},[]),!e)return null;let u=e=>`p-1.5 rounded text-xs font-medium transition-colors ${e?"bg-brand/15 text-brand":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,m="w-px h-5 bg-border mx-0.5",x=e.isActive("table");return(0,n.jsxs)("div",{className:"flex items-center gap-0.5 px-4 py-1.5 border-b border-border flex-shrink-0 flex-wrap",children:[(0,n.jsx)("button",{className:u(e.isActive("heading",{level:1})),onClick:()=>e.chain().focus().toggleHeading({level:1}).run(),title:t("editor.heading1"),children:"H1"}),(0,n.jsx)("button",{className:u(e.isActive("heading",{level:2})),onClick:()=>e.chain().focus().toggleHeading({level:2}).run(),title:t("editor.heading2"),children:"H2"}),(0,n.jsx)("button",{className:u(e.isActive("heading",{level:3})),onClick:()=>e.chain().focus().toggleHeading({level:3}).run(),title:t("editor.heading3"),children:"H3"}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("bold")),onClick:()=>e.chain().focus().toggleBold().run(),title:t("editor.bold"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z"})})}),(0,n.jsx)("button",{className:u(e.isActive("italic")),onClick:()=>e.chain().focus().toggleItalic().run(),title:t("editor.italic"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z"})})}),(0,n.jsx)("button",{className:u(e.isActive("strike")),onClick:()=>e.chain().focus().toggleStrike().run(),title:t("editor.strikethrough"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z"})})}),(0,n.jsx)("button",{className:u(e.isActive("code")),onClick:()=>e.chain().focus().toggleCode().run(),title:t("editor.inlineCode"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"})})}),(0,n.jsx)("div",{className:m}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{ref:d,className:u(e.isActive("link")),onClick:()=>i(!r),title:t("editor.link"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})})}),r&&(0,n.jsx)(a,{editor:e,onClose:()=>i(!1),position:null})]}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("bulletList")),onClick:()=>e.chain().focus().toggleBulletList().run(),title:t("editor.bulletList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4 10.5c-.83 0-1.5.67-1.5 1.5s.67 1.5 1.5 1.5 1.5-.67 1.5-1.5-.67-1.5-1.5-1.5zm0-6c-.83 0-1.5.67-1.5 1.5S3.17 7.5 4 7.5 5.5 6.83 5.5 6 4.83 4.5 4 4.5zm0 12c-.83 0-1.5.68-1.5 1.5s.68 1.5 1.5 1.5 1.5-.68 1.5-1.5-.67-1.5-1.5-1.5zM7 19h14v-2H7v2zm0-6h14v-2H7v2zm0-8v2h14V5H7z"})})}),(0,n.jsx)("button",{className:u(e.isActive("orderedList")),onClick:()=>e.chain().focus().toggleOrderedList().run(),title:t("editor.orderedList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M2 17h2v.5H3v1h1v.5H2v1h3v-4H2v1zm1-9h1V4H2v1h1v3zm-1 3h1.8L2 13.1v.9h3v-1H3.2L5 10.9V10H2v1zm5-6v2h14V5H7zm0 14h14v-2H7v2zm0-6h14v-2H7v2z"})})}),(0,n.jsx)("button",{className:u(e.isActive("taskList")),onClick:()=>e.chain().focus().toggleTaskList().run(),title:t("editor.taskList"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14zM17.99 9l-1.41-1.42-6.59 6.59-2.58-2.57-1.42 1.41 4 3.99z"})})}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(e.isActive("blockquote")),onClick:()=>e.chain().focus().toggleBlockquote().run(),title:t("editor.blockquote"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"})})}),(0,n.jsx)("button",{className:u(e.isActive("codeBlock")),onClick:()=>e.chain().focus().toggleCodeBlock().run(),title:t("editor.codeBlock"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20 3H4c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H4V5h16v14zm-7.5-4.5L15 12l-2.5-2.5L11 11l1.5 1.5L11 14l1.5 1.5zM9.5 14.5L7 12l2.5-2.5L11 11 9.5 12.5 11 14l-1.5.5z"})})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run(),title:t("editor.table"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M20 2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-9 15H4v-4h7v4zm0-6H4V7h7v4zm9 6h-7v-4h7v4zm0-6h-7V7h7v4z"})})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().setHorizontalRule().run(),title:t("editor.horizontalRule"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4 11h16v2H4z"})})}),x&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addRowBefore().run(),title:t("editor.insertRowAbove"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v2h20V6c0-1.1-.9-2-2-2zm0 6H2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V10zM11 17H4v-2h7v2zm0-4H4v-2h7v2zm9 4h-7v-2h7v2zm0-4h-7v-2h7v2z"}),(0,n.jsx)("path",{d:"M14 1h-4v2H8v2h2v2h4V5h2V3h-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addRowAfter().run(),title:t("editor.insertRowBelow"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v10h20V6c0-1.1-.9-2-2-2zM11 12H4v-2h7v2zm0-4H4V6h7v2zm9 4h-7v-2h7v2zm0-4h-7V6h7v2z"}),(0,n.jsx)("path",{d:"M14 19h-4v2H8v2h2v-2h4v2h2v-2h-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addColumnBefore().run(),title:t("editor.insertColumnLeft"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M6 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h2V4H6zm4 0v20h10c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H10zm7 11H10v-2h7v2zm0-4H10V9h7v2z"}),(0,n.jsx)("path",{d:"M1 14v-4h2V8h2v2h-2v4h2v2H3v-2z",opacity:".6"})]})}),(0,n.jsx)("button",{className:u(!1),onClick:()=>e.chain().focus().addColumnAfter().run(),title:t("editor.insertColumnRight"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M4 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h10V4H4zm7 11H4v-2h7v2zm0-4H4V9h7v2z"}),(0,n.jsx)("path",{d:"M18 4v20h2c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-2z"}),(0,n.jsx)("path",{d:"M21 14v-4h2V8h2v2h-2v4h2v2h-2v-2z",opacity:".6"})]})}),(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-orange-11 hover:bg-orange-500/10",onClick:()=>e.chain().focus().deleteRow().run(),title:t("editor.deleteRow"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v2h20V6c0-1.1-.9-2-2-2zm0 6H2v10c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V10zm-8 8H4v-2h8v2z"}),(0,n.jsx)("path",{d:"M15 13l-1.41 1.41L15.17 16l-1.58 1.59L15 19l1.59-1.59L18.17 19l1.42-1.41L18 16l1.59-1.59L18.17 13 16.59 14.41z",fill:"currentColor"})]})}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-orange-11 hover:bg-orange-500/10",onClick:()=>e.chain().focus().deleteColumn().run(),title:t("editor.deleteColumn"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("path",{d:"M6 4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h2V4H6zm4 0v20h10c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2H10zm7 7H10V9h7v2z"}),(0,n.jsx)("path",{d:"M13 16l-1.41 1.41L13.17 19l-1.58 1.59L13 22l1.59-1.59L16.17 22l1.42-1.41L16 19l1.59-1.59L16.17 16l-1.58 1.41z",fill:"currentColor"})]})}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-red-11 hover:bg-red-500/10",onClick:()=>e.chain().focus().deleteTable().run(),title:t("editor.deleteTable"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]}),e.isActive("codeBlock")&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:m}),(0,n.jsx)("button",{className:"p-1.5 rounded text-xs font-medium transition-colors text-red-11 hover:bg-red-500/10",onClick:()=>e.chain().focus().toggleCodeBlock().run(),title:t("editor.deleteCodeBlock"),children:(0,n.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"})})})]})]})}},76288:(e,t,r)=>{r.d(t,{EmptyState:()=>o});var n=r(95155),s=r(79114);function o({onBrowseProjects:e}){let{t}=(0,s.Bd)();return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center justify-center gap-5 bg-card",children:[(0,n.jsx)("svg",{className:"w-14 h-14 text-muted-foreground/40",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2V7z"})}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:t("workspace.selectProject")}),(0,n.jsxs)("button",{onClick:e,className:"flex items-center gap-2 px-4 py-2 text-sm rounded-lg bg-primary text-primary-foreground hover:opacity-90 transition-opacity",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m3-3H9m-4 7h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})}),t("workspace.openProject")]})]})}},76900:(e,t,r)=>{r.d(t,{Bt:()=>p,Cq:()=>j,D0:()=>y,DZ:()=>d,GS:()=>u,H7:()=>w,IG:()=>f,Kl:()=>E,M5:()=>i,O2:()=>c,Or:()=>x,Q1:()=>M,QW:()=>k,Wr:()=>m,Yn:()=>N,b2:()=>L,em:()=>S,fz:()=>C,zF:()=>b,zv:()=>v});var n=r(49433),s=r(82680),o=r(84230);let a=(e,t)=>n.$mh({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()},catch:r=>new s.uV({message:`${t?.method??"GET"} ${e} failed`,cause:r})}),l=(e,t)=>a(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),i=()=>(0,o.F)("/api/settings",a("/api/settings")),d=e=>a("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).pipe(n.yeE(n.OH5(()=>(0,o.T)("/api/settings")))),c=()=>a("/api/mobile-link",{cache:"no-store"}).pipe(n.TjK(e=>e.token??null)),u=e=>n.$mh({try:async()=>(await r.e(768).then(r.t.bind(r,768,19))).toString(e,{type:"svg",margin:1,errorCorrectionLevel:"M"}),catch:e=>new s.uV({message:"QR code generation failed",cause:e})}),m=()=>a("/api/version"),x=()=>a("/api/extension/version"),h=e=>a(e,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}"}),f=()=>h("/api/browser/extensions").pipe(n.TjK(e=>e.data??[])),p=()=>h("/api/browser/extension_reload"),g=e=>e?`/api/note?cwd=${encodeURIComponent(e)}`:"/api/note",b=e=>a(g(e)),v=()=>a("/api/note/list").pipe(n.TjK(e=>e.notes??[])),j=(e,t,r)=>n.$mh({try:async()=>{let n=g(e),s=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,baseMtime:r})});if(409===s.status){let e=await s.json();return{conflict:!0,content:e.content??"",mtime:e.mtime}}if(!s.ok)throw Error(`HTTP ${s.status}`);return{conflict:!1,mtime:(await s.json()).mtime}},catch:t=>new s.uV({message:`POST ${g(e)} failed`,cause:t})}),w=()=>a("/api/sessions/projects"),k=e=>a(`/api/sessions/projects/${encodeURIComponent(e)}`),y=e=>a(`/api/project-settings?cwd=${encodeURIComponent(e)}`),N=e=>l("/api/project-settings",e),C=e=>a(`/api/fs/dirs?path=${encodeURIComponent(e)}`),S=e=>l("/api/open-vscode",{cwd:e}),M=e=>l("/api/open-cursor",{cwd:e}),L=e=>a(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),E=e=>l("/api/git/worktree",e)},80039:(e,t,r)=>{r.d(t,{Workspace:()=>ev});var n=r(95155),s=r(12115),o=r(79114),a=r(13886),l=r(76288),i=r(52153),d=r(21484),c=r(34075),u=r(66109),m=r(61878),x=r(33210),h=r(51914),f=r(20986),p=r(24371),g=r(42804),b=r(22164),v=r(42129),j=r(68459),w=r(94852),k=r(67635),y=r(60241),N=r(95045),C=r(75346),S=r(86957),M=r(34582),L=r(85269),E=r(99161),P=r(63563),T=r(63040);function $({isOpen:e,htmlAppPreviews:t,activeHtmlAppPreviewPath:r,onShowHtmlAppPreview:a,onMinimizeHtmlAppPreview:l,onCloseHtmlAppPreview:i,onClose:d,onOpenApp:I}){let F,B,D,{t:A,i18n:H}=(0,o.Bd)(),[W,z]=(0,s.useState)([]),[O,_]=(0,s.useState)(!1),[q,V]=(0,s.useState)(""),[U,K]=(0,s.useState)(!1),[Q,G]=(0,s.useState)(""),[J,Y]=(0,s.useState)(!1),[X,Z]=(0,s.useState)({}),[ee,et]=(0,s.useState)(null),[er,en]=(0,s.useState)(0),[es,eo]=(0,s.useState)("files"),[ea,el]=(0,s.useState)(null),ei=(0,s.useRef)(null),ed=(0,s.useCallback)(async()=>{_(!0);let e=await S.t4.runPromiseExit((0,T.mi)());"Success"===e._tag?z(e.value):console.error("Failed to load html apps",e.cause),_(!1)},[]);(0,s.useEffect)(()=>{e&&(ed(),setTimeout(()=>{ei.current?.focus(),ei.current?.select()},100))},[e,ed]);let ec=(0,s.useCallback)(()=>{K(!1),et(null),el(null),d()},[d]);(0,s.useEffect)(()=>{if(!e&&!r)return;let t=e=>{if("Escape"===e.key){if(r)return void i(r);if(U){K(!1),G("");return}ec()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,r,ec,i,U]);let eu=(0,s.useMemo)(()=>{let e=q.trim().toLowerCase();return e?W.filter(t=>t.name.toLowerCase().includes(e)||t.title.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):W},[W,q]),em=(0,s.useMemo)(()=>[{key:"mine",labelKey:"htmlApps.mine",items:eu.filter(e=>!e.builtin)},{key:"builtin",labelKey:"htmlApps.builtin",items:eu.filter(e=>e.builtin)}].filter(e=>e.items.length>0),[eu]),ex=ee?W.find(e=>e.id===ee)??null:null,eh=em[0]?.items[0]?.id??null;(0,s.useEffect)(()=>{e&&!ex&&eh&&(et(eh),eo("files"))},[e,ex,eh]);let ef=(0,s.useMemo)(()=>W.filter(e=>!e.builtin).length,[W]),ep=q.trim().length>0,eg=H.resolvedLanguage?.startsWith("zh")?"https://opencockpit.dev/zh/docs/agent/html-apps/":"https://opencockpit.dev/en/docs/agent/html-apps/",eb=(0,s.useCallback)(async()=>{let e=Q.trim();if(!e)return;Y(!0);let t=await S.t4.runPromiseExit((0,T.ot)(e));if("Success"===t._tag)t.value.alreadyExists?(0,c.oR)(A("htmlApps.alreadyAdded"),"info"):((0,c.oR)(A("htmlApps.added"),"success"),(0,P.N)()),G(""),K(!1),await ed();else{let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause,n=r instanceof Error?r.message:A("htmlApps.addFailed");(0,c.oR)(n,"error")}Y(!1)},[Q,ed,A]),ev=(0,s.useCallback)(async e=>{"Success"===(await S.t4.runPromiseExit((0,T.m3)(e)))._tag?(z(t=>t.filter(t=>t.id!==e)),et(t=>t===e?null:t),(0,P.N)()):(0,c.oR)(A("common.deleteFailed"),"error")},[A]),ej=(0,s.useCallback)(e=>{I?I(e):window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:e}})),ec()},[ec,I]),ew=(0,s.useCallback)(e=>{I?I(e):window.dispatchEvent(new CustomEvent("console-open-browser",{detail:{url:e}})),l()},[l,I]),ek=(0,s.useCallback)(e=>{let t=(0,M.Xe)(e);window.open((0,M.PB)(t,window.location.origin),"_blank")},[]),ey=(0,s.useCallback)(e=>{Z(t=>({...t,[e]:(t[e]||0)+1}))},[]),eN=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,c.oR)(A("common.copiedPath"),"success")}catch{(0,c.oR)(A("common.copyFailed"),"error")}},[A]);return(0,n.jsxs)(n.Fragment,{children:[e&&(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:ec}),(0,n.jsxs)("div",{className:u.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:A("htmlApps.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(m.A,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-foreground-subtle pointer-events-none"}),(0,n.jsx)("input",{ref:ei,type:"text",value:q,onChange:e=>V(e.target.value),placeholder:A("htmlApps.searchPlaceholder"),className:"pl-7 pr-6 py-1 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),q&&(0,n.jsx)("button",{onClick:()=>{V(""),ei.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:A("fileBrowser.clear"),children:(0,n.jsx)(x.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("button",{onClick:()=>K(!0),className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",title:A("htmlApps.addHtmlApp"),children:[(0,n.jsx)(h.A,{className:"w-4 h-4"})," ",A("htmlApps.add")]}),(0,n.jsx)("button",{onClick:ec,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",title:A("common.close"),children:(0,n.jsx)(x.A,{className:"w-5 h-5"})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsx)("div",{className:"w-full md:w-[300px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:O&&0===W.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:A("common.loading")}):(0,n.jsxs)("div",{className:"p-3 space-y-3",children:[em.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center",children:[(0,n.jsx)("span",{children:A(e.labelKey)}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(e=>(0,n.jsx)(R,{app:e,selected:e.id===ee,onSelect:()=>{et(e.id),el(null),en(0),eo("files")}},e.id))})]},e.key)),0===eu.length&&ep&&(0,n.jsx)("div",{className:"text-center text-muted-foreground py-6 text-xs",children:A("htmlApps.emptyNoMatch")}),!ep&&0===ef&&(0,n.jsxs)("div",{className:"text-center text-muted-foreground py-4 text-xs space-y-2",children:[(0,n.jsx)("p",{children:A("htmlApps.emptyNoApps")}),(0,n.jsxs)("p",{children:[A("htmlApps.emptyCreatePrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/html"})," ",A("htmlApps.emptyCreateSuffix")]}),(0,n.jsxs)("p",{children:[(0,n.jsx)("button",{type:"button",onClick:()=>K(!0),className:"text-brand hover:underline",children:A("htmlApps.addExisting")})," \xb7 ",(0,n.jsx)("a",{href:eg,target:"_blank",rel:"noreferrer",className:"text-brand hover:underline",children:A("htmlApps.viewDocs")})]})]})]})}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0 flex-col",children:ex?(F=(e,t)=>(0,n.jsx)("button",{onClick:()=>eo(e),disabled:"run"===e&&!ex.valid,className:`px-3 py-1 transition-colors disabled:opacity-40 ${es===e?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:t}),B=(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs mr-1",children:[F("files",A("htmlApps.tabFiles")),F("run",A("htmlApps.tabRun"))]}),ex.valid&&(0,n.jsxs)(n.Fragment,{children:["run"===es&&(0,n.jsx)("button",{onClick:()=>en(e=>e+1),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded","data-tooltip":A("common.refresh"),"aria-label":A("common.refresh"),children:(0,n.jsx)(f.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>{a({path:ex.path,title:ex.title,icon:ex.icon}),ec()},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded","data-tooltip":A("htmlApps.openFull"),"aria-label":A("htmlApps.openFull"),children:(0,n.jsx)(p.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>ej(ex.path),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded","data-tooltip":A("common.openInConsole"),"aria-label":A("common.openInConsole"),children:(0,n.jsx)(g.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>ek(ex.path),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded","data-tooltip":A("browser.openInNewWindow"),"aria-label":A("browser.openInNewWindow"),children:(0,n.jsx)(b.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("button",{onClick:()=>{let e=ex.path.split("/");(0,N.F)(C.n.OpenProject,{cwd:e.slice(0,-1).join("/"),file:e[e.length-1]}),ec()},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded","data-tooltip":A("common.openAsProject"),"aria-label":A("common.openAsProject"),children:(0,n.jsx)(v.A,{className:"w-4 h-4"})}),ex.builtin?null:ea===ex.id?(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>{el(null),ev(ex.id)},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:A("common.confirm")}),(0,n.jsx)("button",{onClick:()=>el(null),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:A("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>el(ex.id),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded","data-tooltip":A("common.delete"),"aria-label":A("common.delete"),children:(0,n.jsx)(j.A,{className:"w-4 h-4"})})]}),D=(0,n.jsxs)("span",{className:"flex items-center gap-2 min-w-0",children:[ex.icon?(0,n.jsx)("span",{className:"text-base leading-none flex-shrink-0",children:ex.icon}):(0,n.jsx)(w.A,{className:"w-4 h-4 flex-shrink-0 text-muted-foreground"}),(0,n.jsx)("span",{className:"truncate",children:ex.title})]}),"files"===es?(0,n.jsx)(E.g,{endpoint:"/api/html-apps/files",id:ex.id,entryFile:ex.path.split("/").pop()||"index.html",title:D,actions:B},ex.id):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:D}),(0,n.jsxs)("div",{className:"flex items-center gap-1 min-w-0 mt-0.5",children:[(0,n.jsx)("span",{className:"font-mono text-xs text-muted-foreground truncate","data-tooltip":ex.path,children:ex.path}),(0,n.jsx)("button",{onClick:()=>eN(ex.path),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded flex-shrink-0",title:A("common.copyPath"),"aria-label":A("common.copyPath"),children:(0,n.jsx)(k.A,{className:"w-3.5 h-3.5"})})]})]}),B]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,n.jsx)(L.O,{filePath:ex.path,reloadKey:er},ex.id)})]})):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground px-6 text-center",children:A("htmlApps.selectHint")})})]})]})]}),e&&U&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:()=>{J||(K(!1),G(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:A("htmlApps.addHtmlApp")}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:A("htmlApps.pathLabel")}),(0,n.jsx)("input",{type:"text",value:Q,onChange:e=>G(e.target.value),onKeyDown:e=>{"Enter"!==e.key||J||eb()},placeholder:"/Users/you/.../report.html",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-4",children:[(0,n.jsx)("button",{onClick:()=>{K(!1),G("")},disabled:J,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors disabled:opacity-50",children:A("common.cancel")}),(0,n.jsx)("button",{onClick:eb,disabled:J||!Q.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 transition-colors disabled:opacity-50",children:J?A("htmlApps.adding"):A("htmlApps.add")})]})]})]}),t.map(e=>{let t=r===e.path;return(0,n.jsx)("div",{className:t?"fixed inset-0 z-[60] flex items-center justify-center bg-scrim p-0 md:p-4":"hidden",onClick:l,children:(0,n.jsxs)("div",{className:"bg-card shadow-lv3 border border-brand/30 w-full h-full md:max-w-[90%] md:h-[90vh] md:rounded-lg flex flex-col overflow-hidden",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-4 py-2 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.icon?(0,n.jsx)("span",{className:"text-base leading-none flex-shrink-0",children:e.icon}):(0,n.jsx)(w.A,{className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground truncate max-w-[35%]","data-tooltip":e.title,children:e.title}),(0,n.jsx)("span",{className:"text-sm text-muted-foreground flex-shrink-0","aria-hidden":"true",children:"-"}),(0,n.jsx)("span",{className:"font-mono text-sm text-muted-foreground truncate min-w-0","data-tooltip":e.path,children:e.path}),(0,n.jsx)("button",{onClick:()=>eN(e.path),className:"text-muted-foreground hover:text-foreground p-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:A("common.copyPath"),"aria-label":A("common.copyPath"),children:(0,n.jsx)(k.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("button",{onClick:l,className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:A("common.minimize"),children:(0,n.jsx)(y.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>ew(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:A("common.openInConsole"),children:(0,n.jsx)(g.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>ek(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:A("browser.openInNewWindow"),children:(0,n.jsx)(b.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>ey(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",title:A("common.refresh"),children:(0,n.jsx)(f.A,{className:"w-4 h-4"})}),(0,n.jsx)("button",{onClick:()=>i(e.path),className:"text-muted-foreground hover:text-foreground px-1.5 py-0.5 rounded hover:bg-hover transition-colors flex-shrink-0",children:(0,n.jsx)(x.A,{className:"w-4 h-4"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,n.jsx)(L.O,{filePath:e.path,reloadKey:X[e.path]||0})})]})},e.path)})]})}function R({app:e,selected:t,onSelect:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{onClick:r,className:`rounded-md px-2 py-2 cursor-pointer transition-colors ${t?"bg-brand/10":"hover:bg-hover"} ${e.valid?"":"opacity-60"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"w-5 h-5 flex-shrink-0 flex items-center justify-center rounded bg-brand/10 text-brand text-xs",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(0,n.jsx)(w.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"text-xs font-medium text-foreground truncate min-w-0","data-tooltip":e.title,children:e.title}),(0,n.jsxs)("span",{className:"font-mono text-[10px] text-muted-foreground truncate flex-1 min-w-0","data-tooltip":e.path,children:["/",e.name]}),!e.valid&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:s("htmlApps.invalid")})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-7","data-tooltip":e.description||void 0,children:e.description||(0,n.jsx)("span",{className:"italic opacity-60",children:s("htmlApps.noDescription")})})]})}var I=r(3238),F=r(62111),B=r(83448),D=r(53317);let A={"claude-fable-5-1":{input:10,output:50,cacheRead:.25,cacheWrite:12.5},"claude-mythos-5-1":{input:10,output:50,cacheRead:.25,cacheWrite:12.5},"claude-fable-5":{input:10,output:50,cacheRead:1,cacheWrite:12.5},"claude-mythos-5":{input:10,output:50,cacheRead:1,cacheWrite:12.5},"claude-opus-5-5":{input:4,output:20,cacheRead:.2,cacheWrite:5},"claude-opus-5":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-8":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-7":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-6":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-opus-4-5":{input:5,output:25,cacheRead:.5,cacheWrite:6.25},"claude-sonnet-5-5":{input:2,output:10,cacheRead:.2,cacheWrite:2.5},"claude-sonnet-5":{input:2,output:10,cacheRead:.2,cacheWrite:2.5},"claude-sonnet-4-6":{input:3,output:15,cacheRead:.3,cacheWrite:3.75},"claude-sonnet-4-5":{input:3,output:15,cacheRead:.3,cacheWrite:3.75},"claude-haiku-5-5":{input:.1,output:.5,cacheRead:.01,cacheWrite:.125},"claude-haiku-4-5":{input:1,output:5,cacheRead:.1,cacheWrite:1.25}},H={input:3,output:15,cacheRead:.3,cacheWrite:3.75},W={light:["#2a78d6","#eb6834","#1baf7a","#eda100","#e87ba4","#008300","#4a3aa7","#e34948"],dark:["#3987e5","#d95926","#199e70","#c98500","#d55181","#008300","#9085e9","#e66767"]},z={light:{messages:"#2a78d6",toolCalls:"#1baf7a",messagesRgb:"42, 120, 214"},dark:{messages:"#3987e5",toolCalls:"#199e70",messagesRgb:"57, 135, 229"}};function O(e){return e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function _(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function q({data:e,height:t=200,formatValue:r=O}){let o=(0,s.useRef)(null),a=(0,s.useRef)(null),[l,i]=(0,s.useState)(null),d=(0,s.useRef)([]),c=(0,s.useCallback)(()=>{let n=o.current,s=a.current;if(!n||!s)return;let l=window.devicePixelRatio||1,i=s.getBoundingClientRect().width;n.width=i*l,n.height=t*l,n.style.width=`${i}px`,n.style.height=`${t}px`;let c=n.getContext("2d");c.scale(l,l),c.clearRect(0,0,i,t);let{labels:u,datasets:m}=e;if(0===u.length)return;let x=i-50-12,h=t-8-28,f=function(e){if(e<=0)return 1;let t=Math.pow(10,Math.floor(Math.log10(e))),r=e/t;return r<=1?t:r<=2?2*t:r<=5?5*t:10*t}(Math.max(1,...u.map((e,t)=>m.reduce((e,r)=>e+r.data[t],0))));c.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",c.font="10px ui-monospace, monospace",c.textAlign="right",c.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+h-t/f*h;c.fillText(r(t),44,s),c.strokeStyle=(p="--line-2",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),c.lineWidth=.5,c.beginPath(),c.moveTo(50,s),c.lineTo(50+x,s),c.stroke()}let g=x/u.length,b=Math.max(4,Math.min(.6*g,32)),v=[];u.forEach((e,t)=>{let r=50+t*g+(g-b)/2,s=0;m.forEach(n=>{var o,a,l,i,d,u;let m=n.data[t];if(m<=0)return;let x=Math.max(1,m/f*h),p=8+h-s-x;c.fillStyle=n.color,o=c,a=r,l=p,i=b,u=2,(d=x)<1||(u=Math.min(u,d/2,i/2),o.beginPath(),o.moveTo(a+u,l),o.lineTo(a+i-u,l),o.quadraticCurveTo(a+i,l,a+i,l+u),o.lineTo(a+i,l+d-u),o.quadraticCurveTo(a+i,l+d,a+i-u,l+d),o.lineTo(a+u,l+d),o.quadraticCurveTo(a,l+d,a,l+d-u),o.lineTo(a,l+u),o.quadraticCurveTo(a,l,a+u,l),o.fill()),v.push({x:r,y:p,w:b,h:x,label:e,value:m,dataset:n.label,color:n.color}),s+=x}),c.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",c.font="9px ui-monospace, monospace",c.textAlign="center",c.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&c.fillText(e,r+b/2,8+h+6)}),d.current=v},[e,t,r]);(0,s.useEffect)(()=>{c();let e=new ResizeObserver(()=>c());return a.current&&e.observe(a.current),()=>e.disconnect()},[c]);let u=(0,s.useCallback)(e=>{let t=o.current?.getBoundingClientRect();if(!t)return;let n=e.clientX-t.left,s=e.clientY-t.top,a=d.current.find(e=>n>=e.x&&n<=e.x+e.w&&s>=e.y&&s<=e.y+e.h);a?i({x:e.clientX-t.left,y:a.y-4,content:`${a.dataset}: ${r(a.value)}`}):i(null)},[r]);return(0,n.jsxs)("div",{ref:a,className:"relative w-full text-muted-foreground",children:[(0,n.jsx)("canvas",{ref:o,className:"w-full",style:{height:t},onMouseMove:u,onMouseLeave:()=>i(null)}),l&&(0,n.jsx)("div",{className:"absolute pointer-events-none bg-popover text-popover-foreground text-[10px] px-2 py-1 rounded shadow-lv2 border border-border whitespace-nowrap z-10",style:{left:l.x,top:l.y,transform:"translate(-50%, -100%)"},children:l.content})]})}function V({hourCounts:e}){let{t}=(0,o.Bd)(),{resolvedTheme:r}=(0,I.DP)(),s=z[r],a=Math.max(1,...Object.values(e)),l=Array.from({length:24},(e,t)=>t);return(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:t("tokenStats.activeHours")}),(0,n.jsx)("div",{className:"flex gap-[2px] items-end h-16",children:l.map(r=>{let o=e[String(r)]||0,l=o/a;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:r,count:o}),children:[(0,n.jsx)("div",{className:"w-full rounded-sm transition-all",style:{height:`${Math.max(2,48*l)}px`,backgroundColor:l>0?`rgba(${s.messagesRgb}, ${.2+.8*l})`:"var(--muted)"}}),r%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:r})]},r)})})]})}function U({isOpen:e,onClose:t}){var r;let a,l,{t:i}=(0,o.Bd)(),[d,c]=(0,s.useState)(null),[u,m]=(0,s.useState)(!0),[x,h]=(0,s.useState)("day"),[f,p]=(0,s.useState)("tokens"),[g,b]=(0,s.useState)(null),{resolvedTheme:v}=(0,I.DP)();(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>m(!0)),S.t4.runPromiseExit((0,B.Cr)()).then(e=>{if("Success"===e._tag){let t=e.value;t.error||queueMicrotask(()=>c(t))}queueMicrotask(()=>m(!1))}))},[e]);let j=(0,s.useMemo)(()=>{var e;let t,r,n=Object.keys(d?.modelUsage||{}).filter(e=>!e.startsWith("<")),s=new Map;for(let e of d?.dailyModelTokens||[])for(let[t,r]of Object.entries(e.tokensByModel)){let n=s.get(t);r>0&&(!n||e.date<n)&&s.set(t,e.date)}return e=[...n].sort((e,t)=>(s.get(e)??"￿").localeCompare(s.get(t)??"￿")||e.localeCompare(t)),t=W[v],r={},e.forEach((e,n)=>{r[e]=t[n%t.length]}),r},[d,v]),w=(0,s.useMemo)(()=>d?.modelUsage?Object.entries(d.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:(0,D.J)(e),color:j[e],usage:t,cost:(r=function(e){let t=e.replace(/-\d{8}$/,""),r=A[t];if(r)return r;let n=t.toLowerCase();return n.includes("fable")||n.includes("mythos")?{input:10,output:50,cacheRead:1,cacheWrite:12.5}:n.includes("opus")?{input:5,output:25,cacheRead:.5,cacheWrite:6.25}:n.includes("haiku")?{input:1,output:5,cacheRead:.1,cacheWrite:1.25}:H}(e),t.inputTokens/1e6*r.input+t.outputTokens/1e6*r.output+t.cacheReadInputTokens/1e6*r.cacheRead+t.cacheCreationInputTokens/1e6*r.cacheWrite),totalTokens:t.inputTokens+t.outputTokens+t.cacheReadInputTokens+t.cacheCreationInputTokens}}).sort((e,t)=>t.cost-e.cost):[],[d,j]),k=(0,s.useMemo)(()=>w.reduce((e,t)=>e+t.cost,0),[w]),y=(0,s.useMemo)(()=>w.map(e=>e.id),[w]),N=(0,s.useMemo)(()=>{let e={};for(let t of w)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[w]),{activityChart:C,tokenChart:M,costChart:L}=(0,s.useMemo)(()=>{let e=d?.dailyActivity||[],t=d?.dailyModelTokens||[];if("day"===x){let r=e.slice(-60),n=t.slice(-60),s={labels:r.map(e=>e.date.slice(5)),datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messageCount),color:z[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:z[v].toolCalls}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:n.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:o,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:n.map(t=>(t.tokensByModel[e]||0)*(N[e]||0)),color:j[e]}))}}}if("week"===x){let r=function(e,t){let r=new Map;for(let t of e){let e=new Date(t.date),n=new Date(e);n.setDate(e.getDate()-e.getDay());let s=n.toISOString().slice(0,10),o=s.slice(5);r.has(s)||r.set(s,{label:o,messages:0,sessions:0,tools:0,tokensByModel:{}});let a=r.get(s);a.messages+=t.messageCount,a.sessions+=t.sessionCount,a.tools+=t.toolCallCount}for(let e of t){let t=new Date(e.date),n=new Date(t);n.setDate(t.getDate()-t.getDay());let s=n.toISOString().slice(0,10);r.has(s)||r.set(s,{label:s.slice(5),messages:0,sessions:0,tools:0,tokensByModel:{}});let o=r.get(s);for(let[t,r]of Object.entries(e.tokensByModel))o.tokensByModel[t]=(o.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:z[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:z[v].toolCalls}]};return{activityChart:s,tokenChart:{labels:n,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:r.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:n,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:r.map(t=>(t.tokensByModel[e]||0)*(N[e]||0)),color:j[e]}))}}}let r=function(e,t){let r=new Map;for(let t of e){let e=t.date.slice(0,7);r.has(e)||r.set(e,{label:e,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(e);n.messages+=t.messageCount,n.sessions+=t.sessionCount,n.tools+=t.toolCallCount}for(let e of t){let t=e.date.slice(0,7);r.has(t)||r.set(t,{label:t,messages:0,sessions:0,tools:0,tokensByModel:{}});let n=r.get(t);for(let[t,r]of Object.entries(e.tokensByModel))n.tokensByModel[t]=(n.tokensByModel[t]||0)+r}return Array.from(r.values()).sort((e,t)=>e.label.localeCompare(t.label))}(e,t),n=r.map(e=>e.label),s={labels:n,datasets:[{label:i("tokenStats.messages"),data:r.map(e=>e.messages),color:z[v].messages},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:z[v].toolCalls}]};return{activityChart:s,tokenChart:{labels:n,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:r.map(t=>t.tokensByModel[e]||0),color:j[e]}))},costChart:{labels:n,datasets:y.map(e=>({id:e,label:(0,D.J)(e),data:r.map(t=>(t.tokensByModel[e]||0)*(N[e]||0)),color:j[e]}))}}},[d,x,y,N,j,i]),E=g&&j[g]?g:null,P=(0,s.useMemo)(()=>{let e="tokens"===f?M:L;return E?{...e,datasets:e.datasets.filter(e=>e.id===E)}:e},[M,L,f,E]);if((0,F.E)(t,e),!e)return null;let T=[{key:"day",label:i("tokenStats.day")},{key:"week",label:i("tokenStats.week")},{key:"month",label:i("tokenStats.month")}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-lv3 w-full max-w-4xl mx-4 max-h-[90vh] flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:i("tokenStats.title")}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:T.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${x===e.key?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>h(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-6",children:u?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):d?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(K,{label:i("tokenStats.totalSessions"),value:String(d.totalSessions??0)}),(0,n.jsx)(K,{label:i("tokenStats.totalMessages"),value:O(d.totalMessages??0)}),(0,n.jsx)(K,{label:i("tokenStats.equivalentApiCost"),value:_(k),highlight:!0}),(0,n.jsx)(K,{label:i("tokenStats.longestSession"),value:d.longestSession?(a=Math.floor((r=d.longestSession.duration)/36e5),l=Math.floor(r%36e5/6e4),a>0?`${a}h ${l}m`:`${l}m`):"-"}),(0,n.jsx)(K,{label:i("tokenStats.firstUse"),value:d.firstSessionDate?d.firstSessionDate.slice(0,10):"-"})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.activityTrend")}),(0,n.jsxs)("div",{className:"flex items-center gap-3 text-[10px]",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:z[v].messages}}),i("tokenStats.messages")]}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:z[v].toolCalls}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(q,{data:C,height:180})})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground",children:i("tokenStats.byModel")}),(0,n.jsxs)("div",{className:"flex bg-muted rounded-md p-0.5",children:[(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"tokens"===f?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>p("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===f?"bg-background text-foreground shadow-lv1":"text-muted-foreground hover:text-foreground"}`,onClick:()=>p("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:w.map(e=>(0,n.jsxs)("button",{onClick:()=>b(E===e.id?null:e.id),className:`flex items-center gap-1 rounded-sm transition-opacity hover:opacity-100 ${E&&E!==e.id?"opacity-40":""}`,children:[(0,n.jsx)("span",{className:"inline-block w-2.5 h-2.5 rounded-sm",style:{backgroundColor:e.color}}),e.label]},e.id))})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(q,{data:P,height:180,formatValue:"tokens"===f?O:_})})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-xs font-medium text-muted-foreground mb-2",children:i("tokenStats.modelCostDetail")}),(0,n.jsx)("div",{className:"border border-border rounded-lg overflow-hidden",children:(0,n.jsxs)("table",{className:"w-full text-xs",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"bg-muted/50 text-muted-foreground",children:[(0,n.jsx)("th",{className:"text-left px-3 py-2 font-medium",children:i("tokenStats.model")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Input"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Output"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Read"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:"Cache Write"}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.share")}),(0,n.jsx)("th",{className:"text-right px-3 py-2 font-medium",children:i("tokenStats.equivalentCost")})]})}),(0,n.jsxs)("tbody",{children:[w.map(e=>(0,n.jsxs)("tr",{className:"border-t border-border",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-mono text-foreground",children:(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5",children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.label]})}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:O(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:O(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:O(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:O(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:k>0?`${(e.cost/k*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:_(e.cost)})]},e.id)),(0,n.jsxs)("tr",{className:"border-t-2 border-border bg-muted/30",children:[(0,n.jsx)("td",{className:"px-3 py-2 font-medium text-foreground",children:i("tokenStats.total")}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:O(w.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:O(w.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:O(w.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:O(w.reduce((e,t)=>e+t.usage.cacheCreationInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:"100%"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-bold text-foreground",children:_(k)})]})]})]})})]}),d.hourCounts&&Object.keys(d.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(V,{hourCounts:d.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function K({label:e,value:t,highlight:r}){return(0,n.jsxs)("div",{className:"bg-muted/30 rounded-lg px-3 py-2.5",children:[(0,n.jsx)("div",{className:"text-[10px] text-muted-foreground",children:e}),(0,n.jsx)("div",{className:`text-sm font-semibold mt-0.5 ${r?"text-brand":"text-foreground"}`,children:t})]})}var Q=r(60865),G=r(52252),J=r(48764),Y=r(58250);function X({skillId:e,name:t,actions:r,onClose:a}){let{t:l}=(0,o.Bd)(),[i,d]=(0,s.useState)(void 0);(0,s.useEffect)(()=>{if(t)return;let r=!1;return S.t4.runPromiseExit((0,J.Bz)(e)).then(e=>{r||"Success"!==e._tag||d(e.value.name)}),()=>{r=!0}},[e,t]);let c=t??i;return(0,n.jsx)(E.g,{endpoint:"/api/skills/files",id:e,entryFile:"SKILL.md",title:c?`/${c}`:l("skills.previewTitle"),actions:r,onClose:a})}let Z="builtin",ee=e=>e.split("/").slice(0,-2).join("/")||"/";function et({isOpen:e,onClose:t}){let{t:r,i18n:a}=(0,o.Bd)(),[l,i]=(0,s.useState)([]),[d,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(""),[j,w]=(0,s.useState)(!1),[k,y]=(0,s.useState)([]),[M,L]=(0,s.useState)(null),[E,P]=(0,s.useState)(null),T=(0,s.useRef)(null),$=(0,s.useCallback)(async()=>{m(!0);let e=await S.t4.runPromiseExit((0,J.Hy)());"Success"===e._tag?i(e.value):console.error("Failed to load skills",e.cause);let t=await S.t4.runPromiseExit((0,J.Wd)());"Success"===t._tag&&y(t.value),m(!1)},[]);(0,s.useEffect)(()=>{e||(L(null),P(null)),e&&($(),setTimeout(()=>{T.current?.focus(),T.current?.select()},100))},[e,$]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key){if(f){p(!1),b("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,f]);let R=(0,s.useCallback)(e=>{let t=x.trim().toLowerCase();return!t||e.name.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)||e.path.toLowerCase().includes(t)},[x]),I=(0,s.useMemo)(()=>{let e=new Map;for(let t of l){if(!R(t))continue;let r=ee(t.path),n=e.get(r);n?n.push(t):e.set(r,[t])}let t=[...e.entries()].sort(([e,t],[r,n])=>n.length-t.length||e.localeCompare(r)).map(([e,t])=>({key:e,items:[...t].sort((e,t)=>e.name.localeCompare(t.name))})),r=k.filter(R);return r.length>0&&t.push({key:Z,items:r}),t},[l,k,R]),F=(0,s.useMemo)(()=>I.flatMap(e=>e.items),[I]),B=M?[...l,...k].find(e=>e.id===M)??null:null;(0,s.useEffect)(()=>{e&&!B&&L(F[0]?.id??null)},[e,B,F]);let D=a.resolvedLanguage?.startsWith("zh")?"https://opencockpit.dev/zh/docs/agent/skills/":"https://opencockpit.dev/en/docs/agent/skills/",A=(0,s.useCallback)(async()=>{let e=g.trim();if(!e)return;w(!0);let t=await S.t4.runPromiseExit((0,J.L5)(e));if("Success"===t._tag)(0,c.oR)(t.value.alreadyExists?r("skills.alreadyAdded"):r("skills.added"),t.value.alreadyExists?"info":"success"),b(""),p(!1),await $(),t.value.alreadyExists||(0,Y.k)();else{let e="Fail"===t.cause._tag?t.cause.error:null,n=e?.cause,s=n instanceof Error?n.message:r("skills.addFailed");(0,c.oR)(s,"error")}w(!1)},[g,$,r]),H=(0,s.useCallback)(async e=>{"Success"===(await S.t4.runPromiseExit((0,J.hp)(e)))._tag?(i(t=>t.filter(t=>t.id!==e)),(0,Y.k)()):(0,c.oR)(r("common.deleteFailed"),"error")},[r]);return e?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:t}),(0,n.jsxs)("div",{className:u.aO,children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:r("skills.title")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("input",{ref:T,type:"text",value:x,onChange:e=>h(e.target.value),placeholder:r("skills.searchPlaceholder"),className:"px-2 py-1 pr-6 text-xs border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),x&&(0,n.jsx)("button",{onClick:()=>{h(""),T.current?.focus()},className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-foreground-subtle hover:text-foreground rounded-sm transition-colors",title:r("skills.clearSearch"),children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,n.jsxs)("button",{onClick:()=>p(!0),className:"flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors",children:[(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})}),r("skills.addSkill")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-foreground-subtle hover:text-foreground hover:bg-hover rounded transition-colors",title:r("common.close"),children:(0,n.jsx)("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]}),d&&0===l.length&&0===k.length?(0,n.jsx)("div",{className:"flex-1 text-center text-muted-foreground py-8 text-sm",children:r("common.loading")}):(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[(0,n.jsxs)("div",{className:"w-full md:w-[340px] min-h-0 flex-shrink-0 md:border-r border-border overflow-y-auto",children:[0===l.length&&(0,n.jsxs)("div",{className:"text-center text-muted-foreground px-4 pt-6 pb-2 text-xs space-y-2",children:[(0,n.jsx)("p",{children:r("skills.emptyNoSkills")}),(0,n.jsxs)("p",{children:[r("skills.emptyIntroPrefix")," ",(0,n.jsx)("code",{className:"px-1.5 py-0.5 rounded bg-muted text-foreground font-mono text-xs",children:"/skillify"})," ",r("skills.emptyIntroSuffix")]}),(0,n.jsxs)("p",{children:[(0,n.jsx)("button",{type:"button",onClick:()=>p(!0),className:"text-brand hover:underline",children:r("skills.addSkill")})," \xb7 ",(0,n.jsx)("a",{href:D,target:"_blank",rel:"noreferrer",className:"text-brand hover:underline",children:r("skills.viewDocs")})]})]}),(0,n.jsx)("div",{className:"p-3 space-y-3",children:0===I.length&&x?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-6 text-xs",children:r("skills.emptyNoMatch")}):I.map(e=>(0,n.jsxs)("div",{className:"rounded-lg border border-border",children:[(0,n.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-1.5 bg-card rounded-t-lg border-b border-border/60 text-[11px] font-medium text-muted-foreground flex items-center gap-1.5","data-tooltip":e.key===Z?void 0:e.key,children:[(0,n.jsx)("span",{className:`truncate${e.key===Z?"":" font-mono"}`,children:e.key===Z?r("skills.builtinGroup"):e.key.replace(/^\/(?:Users|home)\/[^/]+(?=\/|$)/,"~")}),(0,n.jsx)("span",{className:"ml-auto tabular-nums text-foreground-subtle",children:e.items.length})]}),(0,n.jsx)("div",{className:"p-1 space-y-0.5",children:e.items.map(e=>(0,n.jsx)(er,{skill:e,selected:e.id===M,onSelect:()=>{L(e.id),P(null)}},e.id))})]},e.key))})]}),(0,n.jsx)("div",{className:"hidden md:flex flex-1 min-w-0",children:B?(0,n.jsx)(X,{skillId:B.id,name:B.name,onClose:t,actions:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{let e=B.path.split("/").slice(0,-1).join("/");(0,N.F)(C.n.OpenProject,{cwd:e,file:"SKILL.md"}),t()},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors flex-shrink-0","data-tooltip":r("common.openAsProject"),"aria-label":r("common.openAsProject"),children:(0,n.jsx)(v.A,{className:"w-4 h-4"})}),B.id.startsWith("builtin:")?(0,n.jsx)("span",{className:"text-[11px] text-foreground-subtle flex-shrink-0",children:r("skills.builtinReadOnly")}):E===B.id?(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>{P(null),H(B.id)},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:r("common.confirm")}),(0,n.jsx)("button",{onClick:()=>P(null),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:r("common.cancel")})]}):(0,n.jsx)("button",{onClick:()=>P(B.id),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors flex-shrink-0",title:r("common.delete"),children:(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6M1 7h22M9 7V4a1 1 0 011-1h4a1 1 0 011 1v3"})})})]})},B.id):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-xs text-muted-foreground",children:r("skills.selectHint")})})]})]})]}),f&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-scrim",onClick:()=>{j||(p(!1),b(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-lv3 w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:r("skills.addSkill")}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:r("skills.pathLabel")}),(0,n.jsx)("input",{type:"text",value:g,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"!==e.key||j||A()},placeholder:r("skills.pathPlaceholder"),autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 mt-4",children:[(0,n.jsx)("button",{onClick:()=>{p(!1),b("")},disabled:j,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-hover transition-colors disabled:opacity-50",children:r("common.cancel")}),(0,n.jsx)("button",{onClick:A,disabled:j||!g.trim(),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 transition-colors disabled:opacity-50",children:j?r("skills.adding"):r("skills.add")})]})]})]})]}):null}function er({skill:e,selected:t,onSelect:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{onClick:r,className:`rounded-md px-2 py-2 cursor-pointer transition-colors ${t?"bg-brand/10":"hover:bg-hover"} ${e.valid?"":"opacity-60"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)("span",{className:"w-5 h-5 flex-shrink-0 flex items-center justify-center rounded bg-brand/10 text-brand text-xs",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(0,n.jsx)(G.A,{className:"w-3.5 h-3.5"})}),(0,n.jsxs)("span",{className:"font-mono text-xs font-medium text-foreground truncate flex-1 min-w-0",children:["/",e.name]}),!e.valid&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[10px] px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:s("skills.invalid")})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5 pl-7","data-tooltip":e.description||void 0,children:e.description||(0,n.jsx)("span",{className:"italic opacity-60",children:s("skills.noDescription")})})]})}var en=r(1767),es=r(25237);function eo(){let{t:e}=(0,o.Bd)(),[t,r]=(0,s.useState)(!1);return((0,s.useEffect)(()=>{let e=window.matchMedia("(max-width: 767px)"),t=()=>r(e.matches);return t(),e.addEventListener("change",t),()=>e.removeEventListener("change",t)},[]),t)?(0,n.jsxs)("button",{type:"button",onClick:()=>window.location.assign("/m"+window.location.search),className:"fixed bottom-4 right-4 z-40 flex items-center gap-1.5 rounded-full border border-border bg-popover px-3 py-2 text-sm text-foreground shadow-lv2 active:bg-active",children:[(0,n.jsx)(es.A,{className:"h-4 w-4"}),e("mobile.useMobile")]}):null}var ea=r(47650),el=r(7578);let ei=[],ed=[];function ec(){ed.forEach(e=>e())}function eu(e){ei=ei.filter(t=>t.id!==e),ec()}function em({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return ed.push(t),()=>{ed=ed.filter(e=>e!==t)}},[]),ei}();return 0===t.length?null:(0,ea.createPortal)((0,n.jsx)("div",{className:"fixed bottom-4 left-4 z-[100] flex flex-col gap-2 pointer-events-none",children:t.map(t=>(0,n.jsx)(ex,{item:t,onNavigate:e,onRemove:eu},t.id))}),document.body)}function ex({item:e,onNavigate:t,onRemove:r}){let{t:a}=(0,o.Bd)(),[l,i]=(0,s.useState)(!1),d=(0,s.useRef)(void 0),c=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(d.current=setTimeout(c,5e3),()=>clearTimeout(d.current)),[c]);let u=(0,s.useCallback)(()=>{clearTimeout(d.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),m=(0,s.useCallback)(()=>{clearTimeout(d.current)},[]),x=(0,s.useCallback)(()=>{d.current=setTimeout(c,2e3)},[c]);return(0,n.jsxs)("div",{className:`group pointer-events-auto relative bg-popover border border-border rounded-lg shadow-lv3 px-3 py-3 min-h-[84px] min-w-[260px] max-w-[340px] cursor-pointer transition-all ${l?"opacity-0 -translate-x-4":"opacity-100 translate-x-0"}`,style:{animation:l?void 0:"slideInLeft 0.3s ease-out"},onClick:u,onMouseEnter:m,onMouseLeave:x,children:[(0,n.jsx)("div",{className:"pointer-events-none absolute inset-0 rounded-lg bg-hover opacity-0 group-hover:opacity-100 transition-opacity"}),(0,n.jsxs)("div",{className:"relative flex items-start gap-2",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-green-9 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),(0,n.jsx)("span",{className:"text-sm font-medium text-foreground truncate",children:e.projectName}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:a("common.done")}),(0,n.jsx)(el.l,{projectNumber:e.projectNumber,sessionNumber:e.sessionNumber,className:"ml-auto"}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),c()},className:"p-0.5 text-muted-foreground hover:text-foreground rounded transition-colors",children:(0,n.jsx)("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.message&&(0,n.jsx)("div",{className:"relative text-xs text-muted-foreground line-clamp-2 break-words mt-1 ml-6",children:e.message})]})}var eh=r(77725),ef=r(49433),ep=r(82680);let eg=ef.$mh({try:async()=>{let e=await fetch("/api/projects");if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()},catch:e=>new ep.uV({message:"fetch /api/projects failed",cause:e})});var eb=r(96472);function ev({initialCwd:e,initialSessionId:t,initialBlank:r}){let{t:c}=(0,o.Bd)(),[u,m]=(0,s.useState)([]),[x,h]=(0,s.useState)(0),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[w,k]=(0,s.useState)(!1),[y,N]=(0,s.useState)(!1),[C,M]=(0,s.useState)(null),[L,E]=(0,s.useState)(!1),[P,T]=(0,s.useState)(!1),[R,I]=(0,s.useState)(!1),[F,B]=(0,s.useState)([]),[D,A]=(0,s.useState)(null),[H,W]=(0,s.useState)({}),[z,O]=(0,s.useState)({}),[_,q]=(0,s.useState)(()=>new Set),[V,K]=(0,s.useState)(!1),[G,J]=(0,s.useState)(new Set),Y=(0,s.useRef)(new Map),X=(0,s.useRef)(new Map),Z=(0,s.useRef)(new Map),ee=(0,s.useRef)(null),er=(0,eh.Z)(eg,[]);(0,s.useEffect)(()=>{if("success"===er.status){let e=er.data;m([...e.projects||[]]),h(e.activeIndex||0),p(e.collapsed||!1),K(!0)}else"error"===er.status&&(console.error("Failed to load projects:",er.error),K(!0))},[er]);let es=(0,s.useCallback)(async(e,t,r)=>{let n,s=await S.t4.runPromise((n={projects:e,activeIndex:t,collapsed:r},ef.$mh({try:async()=>{let e=await fetch("/api/projects",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n)});if(!e.ok)throw Error(`HTTP ${e.status}`)},catch:e=>new ep.uV({message:"save /api/projects failed",cause:e})})).pipe(ef.gPK));"Left"===s._tag&&console.error("Failed to save projects:",s.left)},[]),ea=(0,s.useCallback)((e,t)=>{var r,n;let s=u[x]?.cwd,o=(r=s?{cwd:s,sessionId:Z.current.get(s)}:void 0,n={cwd:e,sessionId:t},r?.cwd&&r.sessionId&&(r.cwd!==n.cwd||n.sessionId&&r.sessionId!==n.sessionId)?{cwd:r.cwd,sessionId:r.sessionId}:null);o&&S.t4.runFork((0,eb.T$)(o.cwd,o.sessionId).pipe(ef.h9N(()=>ef.rIH)))},[u,x]);(0,s.useEffect)(()=>{let e=u[x]?.cwd;e&&J(t=>t.has(e)?t:new Set(t).add(e))},[x,u]),(0,s.useEffect)(()=>{for(let[e,t]of Y.current.entries()){let r=u[x]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r,projectNumber:u.findIndex(t=>t.cwd===e)+1},"*")}},[x,u]);let el=(0,s.useCallback)(e=>{let t=u[x]?.cwd,r=t?Y.current.get(t):null,n=r?.contentWindow;if(!n)return;let s=n.document.createEvent("CustomEvent");s.initCustomEvent("console-open-browser",!1,!1,{url:e}),n.dispatchEvent(s)},[x,u]),ed=(0,s.useCallback)(e=>{B(t=>t.some(t=>t.path===e.path)?t:[...t,e]),A(e.path)},[]),eu=(0,s.useCallback)(()=>{A(null)},[]),ex=(0,s.useCallback)(e=>{B(t=>t.filter(t=>t.path!==e)),A(t=>t===e?null:t)},[]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type!=="SESSION_NUMBERS")return;let t=e.data.cwd;if("string"!=typeof t||!Array.isArray(e.data.sessionIds))return;let r=e.data.sessionIds.map(e=>"string"==typeof e?e:null);O(e=>{let n=e[t];return n&&n.length===r.length&&n.every((e,t)=>e===r[t])?e:{...e,[t]:r}})};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type!=="PROJECT_DRAFT")return;let{cwd:t,hasDraft:r}=e.data;"string"==typeof t&&q(e=>{if(e.has(t)===!!r)return e;let n=new Set(e);return r?n.add(t):n.delete(t),n})};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let ej=(0,s.useMemo)(()=>u.map(e=>e.cwd),[u]),ew=(0,s.useMemo)(()=>{let e={};return u.forEach((t,r)=>{(z[t.cwd]??[]).forEach((n,s)=>{n&&(e[`${t.cwd}
38
+ ${n}`]=`${r+1}.${s+1}`)})}),e},[u,z]),ek=(0,s.useCallback)(()=>{let e=crypto.randomUUID(),t=new Map(u.map((e,t)=>[e.cwd,t+1])),r=[...Y.current.values()];return 0===r.length?Promise.resolve({}):new Promise(n=>{let s={},o=new Set(r.map(e=>e.contentWindow).filter(Boolean)),a=()=>{window.removeEventListener("message",l),clearTimeout(i),W(s),n(s)},l=r=>{if(r.data?.type!=="SESSION_NUMBERS"||r.data?.requestId!==e||!o.delete(r.source))return;let n=t.get(r.data.cwd);n&&Array.isArray(r.data.sessionIds)&&r.data.sessionIds.forEach((e,t)=>{"string"==typeof e&&(s[`${r.data.cwd}
39
+ ${e}`]=`${n}.${t+1}`)}),0===o.size&&a()};window.addEventListener("message",l);let i=window.setTimeout(a,300);r.forEach(t=>t.contentWindow?.postMessage({type:"GET_SESSION_NUMBERS",requestId:e},"*"))})},[u]),ey=Object.fromEntries(u.map((e,t)=>[e.cwd,t+1]));(0,s.useEffect)(()=>{g&&ek()},[g,ek]);let eN=(0,s.useCallback)((e,t,r=!1)=>{let n=new URL(window.location.href);n.searchParams.set("cwd",e),t?n.searchParams.set("sessionId",t):n.searchParams.delete("sessionId"),r?n.searchParams.set("newChat","1"):n.searchParams.delete("newChat"),window.history.replaceState({},"",n.toString());let s=e.split("/").filter(Boolean).pop();document.title=s||"Cockpit"},[]),eC=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!V||eC.current||!e)return;eC.current=!0,t?(X.current.set(e,{sessionId:t}),Z.current.set(e,t)):r&&(X.current.set(e,{blank:!0}),Z.current.set(e,null));let n=u.findIndex(t=>t.cwd===e);if(n>=0)n!==x&&(h(n),es(u,n,f));else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),es(t,r,f)}eN(e,t,r)},[V,e,t,r,u,x,f,es,eN]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="GET_PROJECT_NUMBER"){let t=u.findIndex(t=>t.cwd===e.data.cwd);t>=0&&e.source&&"postMessage"in e.source&&e.source.postMessage({type:"PROJECT_NUMBER",projectNumber:t+1,visible:t===x},"*");return}if(e.data?.type==="SESSION_CHANGE"&&e.data?.cwd&&"sessionId"in e.data){let{cwd:t,sessionId:r}=e.data;"string"==typeof r&&r?Z.current.set(t,r):Z.current.set(t,null);let n=u[x];n?.cwd===t&&eN(t,"string"==typeof r?r:void 0,null===r)}if(e.data?.type==="SESSION_COMPLETE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:t,sessionId:r,lastUserMessage:n}=e.data,s=u[x];if(s?.cwd!==t){let e=t.split("/").pop()||t;ek().then(s=>{let o,[a,l]=s[`${t}
40
+ ${r}`]?.split(".")??[],i=u.findIndex(e=>e.cwd===t);o=`session-toast-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,ei=[...ei,{projectName:e,message:n,cwd:t,sessionId:r,projectNumber:a??(i>=0?i+1:void 0),sessionNumber:l,id:o}],ec()})}}if(e.data?.type==="OPEN_TOKEN_STATS"&&k(!0),e.data?.type==="OPEN_NOTE"&&e.data?.cwd&&(M(e.data.cwd),N(!0)),e.data?.type==="SCREENSHOT_PREPARE"&&e.data?.cwd){ee.current=x;let t=e.data.cwd,r=u.findIndex(e=>e.cwd===t);r>=0&&r!==x&&h(r);return}if(e.data?.type==="SCREENSHOT_DONE"){null!==ee.current&&ee.current!==x&&h(ee.current),ee.current=null;return}if(e.data?.type==="OPEN_PROJECT"&&e.data?.cwd){let{cwd:t,sessionId:r,switchToAgent:n,file:s}=e.data,o=r||"";ea(t,o||void 0),Z.current.set(t,o);let a=u.findIndex(e=>e.cwd===t);if(a>=0){if(o){let e=Y.current.get(t);e?.contentWindow?e.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:o,...n?{switchToAgent:!0}:{}},"*"):X.current.set(t,{sessionId:o,...n?{switchToAgent:!0}:{}})}if(s){let e=Y.current.get(t);e?.contentWindow?e.contentWindow.postMessage({type:"OPEN_FILE",path:s},"*"):X.current.set(t,{...X.current.get(t),file:s})}a!==x&&(h(a),es(u,a,f))}else{let e=[...u,{cwd:t}],r=e.length-1;m(e),h(r),es(e,r,f),(o||s)&&X.current.set(t,{...o?{sessionId:o}:{},...n?{switchToAgent:!0}:{},...s?{file:s}:{}})}eN(t,o)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[u,x,f,eN,es,ek,ea]),(0,s.useEffect)(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&!e.altKey){if(!e.shiftKey&&("p"===e.key||"f"===e.key||"s"===e.key))return void e.preventDefault();e.ctrlKey&&!e.metaKey&&"Minus"===e.code&&e.preventDefault()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let eS=(0,s.useCallback)(e=>{let t=u[e];if(t&&(e!==x&&ea(t.cwd,Z.current.get(t.cwd)),h(e),es(u,e,f),t?.cwd)){let e=Z.current.get(t.cwd);eN(t.cwd,e??void 0,null===e)}},[u,x,f,es,eN,ea]),eM=(0,s.useCallback)(e=>{let t=u.filter((t,r)=>r!==e),r=x;e<x?r=x-1:e===x&&r>=t.length&&(r=Math.max(0,t.length-1)),m(t),h(r),es(t,r,f)},[u,x,f,es]),eL=(0,s.useCallback)(e=>{let t=u[x],r=e.findIndex(e=>e.cwd===t?.cwd);m(e),h(r>=0?r:0),es(e,r>=0?r:0,f)},[u,x,f,es]),eE=(0,s.useCallback)(()=>{let e=!f;p(e),es(u,x,e)},[u,x,f,es]),eP=(0,s.useCallback)((e,t)=>{ea(e,t),Z.current.set(e,t);let r=u.findIndex(t=>t.cwd===e);if(r>=0){let n=Y.current.get(e);n?.contentWindow?n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"):X.current.set(e,{sessionId:t,switchToAgent:!0}),h(r),es(u,r,f)}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),es(r,n,f),X.current.set(e,{sessionId:t,switchToAgent:!0})}eN(e,t),b(!1)},[u,f,es,eN,ea]),eT=(0,s.useCallback)((e,t)=>{ea(e,t),Z.current.set(e,t);let r=u.findIndex(t=>t.cwd===e);if(r>=0){let n=Y.current.get(e);n?.contentWindow?n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"):X.current.set(e,{sessionId:t,switchToAgent:!0}),r!==x&&(h(r),es(u,r,f))}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),es(r,n,f),X.current.set(e,{sessionId:t,switchToAgent:!0})}eN(e,t)},[u,x,f,es,eN,ea]),e$=(0,s.useCallback)((e,t)=>{let r=Z.current.get(e)??void 0;ea(e,r);let n=u.findIndex(t=>t.cwd===e);if(n>=0){let r=Y.current.get(e);r?.contentWindow?r.contentWindow.postMessage({type:"FOCUS_CONSOLE_BUBBLE",commandId:t},"*"):X.current.set(e,{...X.current.get(e),bubble:t}),n!==x&&(h(n),es(u,n,f))}else{let r=[...u,{cwd:e}],n=r.length-1;m(r),h(n),es(r,n,f),X.current.set(e,{bubble:t})}eN(e,r)},[u,x,f,es,eN,ea]);return V?(0,n.jsxs)("div",{className:"h-screen flex bg-background overflow-hidden",children:[(0,n.jsx)(a.ProjectSidebar,{projects:u,activeIndex:x,collapsed:f,currentCwd:u[x]?.cwd,onSelectProject:eS,onRemoveProject:eM,onReorderProjects:eL,onToggleCollapse:eE,onOpenSessionBrowser:()=>b(!0),onOpenSettings:()=>j(!0),onOpenNote:e=>{M(e??null),N(!0)},onOpenSkills:()=>E(!0),onOpenBots:()=>T(!0),onOpenApps:()=>I(!0),htmlAppPreviews:F,activeHtmlAppPreviewPath:D,onShowHtmlAppPreview:ed,onSwitchProject:eT,onFocusTerminal:e$,onResolveSessionNumbers:ek,sessionOrders:z,draftCwds:_,sessionNumbers:ew}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:0===u.length?(0,n.jsx)(l.EmptyState,{onBrowseProjects:()=>b(!0)}):(0,n.jsx)("div",{className:"flex-1 relative overflow-hidden",children:u.map((e,t)=>{var r;let s,o,a;return G.has(e.cwd)&&(0,n.jsx)("iframe",{ref:t=>{t?Y.current.set(e.cwd,t):Y.current.delete(e.cwd)},src:(s=X.current.get(e.cwd),r=e.cwd,o=`/project?cwd=${encodeURIComponent(r)}`,s?.sessionId?o+=`&sessionId=${encodeURIComponent(s.sessionId)}`:s?.blank&&(o+="&newChat=1"),s?.file?o+=`&file=${encodeURIComponent(s.file)}`:s?.bubble&&(o+=`&bubble=${encodeURIComponent(s.bubble)}`),(a=s?.file?"explorer":s?.bubble?"console":s?.sessionId&&s.switchToAgent?"agent":null)&&(o+=`&view=${a}`),o),className:`absolute inset-0 w-full h-full border-0 ${t===x?"block":"hidden"}`,title:`Project: ${e.cwd}`},e.cwd)})})}),(0,n.jsx)(i.SessionBrowser,{isOpen:g,onClose:()=>b(!1),onSelectSession:eP,sessionNumbers:H,projectNumbers:ey,onAddProject:e=>{let t=u.findIndex(t=>t.cwd===e);if(ea(e,t>=0?Z.current.get(e):void 0),t>=0)h(t),es(u,t,f);else{let t=[...u,{cwd:e}],r=t.length-1;m(t),h(r),es(t,r,f)}b(!1)}}),(0,n.jsx)(d.SettingsModal,{isOpen:v,onClose:()=>j(!1)}),(0,n.jsx)(U,{isOpen:w,onClose:()=>k(!1)}),(0,n.jsx)(Q.NoteModal,{isOpen:y,onClose:()=>{N(!1),M(null)},projectCwd:C,currentCwd:u[x]?.cwd,projectOrder:ej}),(0,n.jsx)(et,{isOpen:L,onClose:()=>E(!1)}),(0,n.jsx)(en.BotsModal,{isOpen:P,onClose:()=>T(!1),onOpenSession:eT}),(0,n.jsx)($,{isOpen:R,htmlAppPreviews:F,activeHtmlAppPreviewPath:D,onShowHtmlAppPreview:ed,onMinimizeHtmlAppPreview:eu,onCloseHtmlAppPreview:ex,onClose:()=>I(!1),onOpenApp:el}),(0,n.jsx)(em,{onNavigate:eT}),(0,n.jsx)(eo,{})]}):(0,n.jsx)("div",{className:"h-screen flex items-center justify-center bg-card",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,n.jsxs)("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("span",{children:c("workspace.loadingText")})]})})}},93777:(e,t,r)=>{r.d(t,{E:()=>x});var n=r(95155),s=r(12115),o=r(79114),a=r(69809),l=r(12786),i=r(96625),d=r(20235),c=r(15317);let u={once:[{labelKey:"scheduledTasks.5minLater",value:5},{labelKey:"scheduledTasks.15minLater",value:15},{labelKey:"scheduledTasks.30minLater",value:30},{labelKey:"scheduledTasks.1hourLater",value:60},{labelKey:"scheduledTasks.3hoursLater",value:180},{labelKey:"scheduledTasks.6hoursLater",value:360},{labelKey:"scheduledTasks.1dayLater",value:1440},{labelKey:"scheduledTasks.3daysLater",value:4320}],interval:[{labelKey:"scheduledTasks.every15min",value:15},{labelKey:"scheduledTasks.every30min",value:30},{labelKey:"scheduledTasks.every1hour",value:60},{labelKey:"scheduledTasks.every2hours",value:120},{labelKey:"scheduledTasks.every6hours",value:360},{labelKey:"scheduledTasks.every12hours",value:720},{labelKey:"scheduledTasks.everyDay",value:1440}],cron:[{labelKey:"scheduledTasks.daily9am",value:"0 9 * * *"},{labelKey:"scheduledTasks.daily6pm",value:"0 18 * * *"},{labelKey:"scheduledTasks.weeklyMon9am",value:"0 9 * * 1"},{labelKey:"scheduledTasks.monthly1st9am",value:"0 9 1 * *"}]},m=["minute","hour","day"];function x({onClose:e,unanchored:t,onCreate:r,editTask:h,onUpdate:f}){let p,g,{t:b}=(0,o.Bd)(),v=!!h,[j,w]=(0,s.useState)(h?.type||"once"),[k,y]=(0,s.useState)(h?.message||""),[N,C]=(0,s.useState)(h?.taskFile?"file":"message"),[S,M]=(0,s.useState)(h?.taskFile||""),[L]=(0,s.useState)(()=>{let e=h?.delayMinutes||h?.intervalMinutes;return e?(0,c.wJ)(e):null}),[E,P]=(0,s.useState)(L?String(L.value):""),[T,$]=(0,s.useState)(L?.unit??"minute"),[R,I]=(0,s.useState)(h?.cron||""),[F,B]=(0,s.useState)(h?.activeFrom||"09:00"),[D,A]=(0,s.useState)(h?.activeTo||"18:00"),[H,W]=(0,s.useState)(h?.startAt?(p=new Date(h.startAt),g=e=>String(e).padStart(2,"0"),`${p.getFullYear()}-${g(p.getMonth()+1)}-${g(p.getDate())}T${g(p.getHours())}:${g(p.getMinutes())}`):""),[z,O]=(0,s.useState)(!!(h?.activeFrom&&h?.activeTo)),[_,q]=(0,s.useState)(null),V=(0,s.useRef)(null),U=(0,s.useRef)(null),K=(0,i.nJ)({value:k,onChange:y,textareaRef:U});(0,s.useEffect)(()=>{U.current?.focus()},[]),(0,s.useEffect)(()=>{let t=t=>{V.current&&!V.current.contains(t.target)&&e()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[e]);let Q=(0,s.useCallback)(()=>{let t="file"===N,n=t?{message:"",taskFile:S.trim()}:{message:k.trim(),taskFile:""};if(t?!n.taskFile:!n.message)return;let s=null;if("once"===j){let e=_||(0,c.LV)(E,T);if(!e||e<=0)return;s={...n,type:"once",delayMinutes:e}}else if("interval"===j){let e=_||(0,c.LV)(E,T);if(!e||e<=0)return;s={...n,type:"interval",intervalMinutes:e,startAt:H?new Date(H).getTime():null,...z?{activeFrom:F,activeTo:D}:{}}}else if("cron"===j){let e=_||R.trim();if(!e)return;s={...n,type:"cron",cron:e}}s&&(v&&h&&f?f(h.id,s):r(s),e())},[k,N,S,j,_,E,T,R,H,z,F,D,r,e,v,h,f]);return(0,n.jsxs)("div",{ref:V,className:`w-[28rem] max-w-[calc(100vw-1.5rem)] bg-popover border border-border rounded-lg shadow-lv2 z-50 ${v||t?"":"absolute bottom-full left-0 mb-2"}`,onKeyDown:t=>{"Escape"===t.key?e():"Enter"===t.key&&(t.metaKey||t.ctrlKey)&&Q()},children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:v?b("scheduledTasks.editTask"):b("scheduledTasks.createTask")})}),(0,n.jsxs)("div",{className:"p-4 space-y-4 max-h-[min(52rem,calc(100vh-3rem))] overflow-y-auto",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("div",{className:"flex gap-1 mb-1.5",children:["message","file"].map(e=>(0,n.jsx)("button",{onClick:()=>C(e),className:`px-2 py-1 text-xs rounded transition-colors ${N===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"message"===e?b("scheduledTasks.sendMessage"):b("scheduledTasks.taskFile")},e))}),"message"===N?(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(d.s1,{textareaRef:U,matchLine:K.matchLine,value:k,onChange:e=>{y(e.target.value),K.trackCaret(e.target)},onSelect:e=>K.trackCaret(e.currentTarget),onKeyDown:e=>{K.handleKeyDown(e)},placeholder:b("scheduledTasks.messagePlaceholder"),rows:5,boxClassName:"px-2 py-1.5 text-sm border border-border rounded",colorClassName:"bg-card text-foreground",className:"focus:outline-none focus:ring-1 focus:ring-ring resize-y min-h-[6rem]"}),(0,n.jsx)(i.V0,{ac:K,className:"absolute top-full left-0 right-0 mt-1 max-h-48 z-10"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:S,onChange:e=>M(e.target.value),placeholder:b("scheduledTasks.taskFilePlaceholder"),className:"w-full px-2 py-1.5 text-sm font-mono border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:b("scheduledTasks.taskFileHint")})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:b("scheduledTasks.type")}),(0,n.jsx)("div",{className:"flex gap-1",children:["once","interval","cron"].map(e=>(0,n.jsx)("button",{onClick:()=>{w(e),q(null),P(""),$("minute"),I("")},className:`flex-1 px-2 py-1 text-xs rounded transition-colors ${j===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"once"===e?b("scheduledTasks.once"):"interval"===e?b("scheduledTasks.interval"):"Cron"},e))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:b("scheduledTasks.quickSelect")}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-1",children:u[j].map(e=>(0,n.jsx)("button",{onClick:()=>{if(q(e.value),"cron"===j)I(String(e.value));else{let{value:t,unit:r}=(0,c.wJ)(e.value);P(String(t)),$(r)}},className:`px-2 py-1 text-xs rounded border transition-colors ${_===e.value?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:b(e.labelKey)},e.labelKey))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:"cron"===j?b("scheduledTasks.customCron"):b("scheduledTasks.customDuration")}),"cron"===j?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:R,onChange:e=>{I(e.target.value),q(null)},placeholder:b("scheduledTasks.cronPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring font-mono"}),R.trim()&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:function(e){let t=a.A.t,r=e.trim().split(/\s+/);if(5!==r.length)return null;let[n,s,o,l,i]=r,d={0:t("cron.dowSun"),1:t("cron.dowMon"),2:t("cron.dowTue"),3:t("cron.dowWed"),4:t("cron.dowThu"),5:t("cron.dowFri"),6:t("cron.dowSat")},c={1:`1${t("cron.monthPrefix")}`,2:`2${t("cron.monthPrefix")}`,3:`3${t("cron.monthPrefix")}`,4:`4${t("cron.monthPrefix")}`,5:`5${t("cron.monthPrefix")}`,6:`6${t("cron.monthPrefix")}`,7:`7${t("cron.monthPrefix")}`,8:`8${t("cron.monthPrefix")}`,9:`9${t("cron.monthPrefix")}`,10:`10${t("cron.monthPrefix")}`,11:`11${t("cron.monthPrefix")}`,12:`12${t("cron.monthPrefix")}`};try{let e="";if(n.includes("/")||s.includes("/")){if("*"===s&&n.includes("/"))return t("cron.everyNMinutes",{n:n.split("/")[1]});if("0"===n&&s.includes("/"))return t("cron.everyNHours",{n:s.split("/")[1]});return null}let r=parseInt(s,10),a=parseInt(n,10);if(isNaN(r)&&"*"!==s||isNaN(a)&&"*"!==n)return null;e="*"===s&&"*"===n?t("cron.everyMinute"):"*"===s?t("cron.everyHourAtMin",{m:a}):"*"===n?t("cron.hourlyEveryMin",{h:r}):`${String(r).padStart(2,"0")}:${String(a).padStart(2,"0")}`;let u=[];if("*"!==l){let e=l.split(",").map(e=>c[e]||`${e}${t("cron.monthPrefix")}`);u.push(e.join(", "))}if("*"!==o)if(o.includes("-")){let[e,r]=o.split("-");u.push(t("cron.dayRange",{a:e,b:r}))}else o.includes(",")?u.push(o.split(",").map(e=>`${e}${t("cron.dayOfMonth")}`).join(", ")):u.push(`${o}${t("cron.dayOfMonth")}`);if("*"!==i)if("1-5"===i)u.push(t("cron.weekdays"));else if("0,6"===i||"6,0"===i)u.push(t("cron.weekends"));else{let e=i.split(",").map(e=>{if(e.includes("-")){let[r,n]=e.split("-");return t("cron.weekdayRange",{a:d[r]||r,b:d[n]||n})}return`${t("cron.weekdayPrefix")}${d[e]||e}`});u.push(e.join(", "))}if(0===u.length&&"*"===o&&"*"===l&&"*"===i)return t("cron.daily",{time:e});return`${u.join(" ")} ${e}`}catch{return null}}(R.trim())||(0,n.jsx)("span",{className:"text-destructive",children:b("scheduledTasks.cronFormat")})})]}):(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("input",{type:"number",value:E,onChange:e=>{P(e.target.value),q(null)},placeholder:b("scheduledTasks.amountPlaceholder"),min:1,className:"flex-1 min-w-0 px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),m.map(e=>(0,n.jsx)("button",{onClick:()=>{$(e),q(null)},className:`px-3 text-xs rounded border transition-colors ${T===e?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:b(`scheduledTasks.unit.${e}`)},e))]})]}),"interval"===j&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:b("scheduledTasks.startAt")}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("input",{type:"datetime-local",value:H,onChange:e=>W(e.target.value),className:"flex-1 min-w-0 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),H&&(0,n.jsx)("button",{onClick:()=>W(""),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground hover:border-foreground/30 transition-colors",children:b("scheduledTasks.clear")})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-1",children:b("scheduledTasks.startAtHint")})]}),"interval"===j&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"flex items-center gap-2 text-xs text-muted-foreground mb-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:z,onChange:e=>O(e.target.checked),className:"rounded border-border"}),b("scheduledTasks.limitTimeRange")]}),z&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("input",{type:"time",value:F,onChange:e=>B(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:b("scheduledTasks.to")}),(0,n.jsx)("input",{type:"time",value:D,onChange:e=>A(e.target.value),className:"flex-1 px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]})]}),(0,n.jsx)("button",{onClick:Q,disabled:!(("file"===N?!!S.trim():!!k.trim())&&("once"===j||"interval"===j?!!(_||(0,c.LV)(E,T)>0):"cron"===j&&!!(_||R.trim()))),className:"w-full py-1.5 text-sm font-medium rounded bg-brand text-white hover:bg-brand/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:v?b("scheduledTasks.saveBtn",{modKey:(0,l.Mu)()}):b("scheduledTasks.createBtn",{modKey:(0,l.Mu)()})})]})]})}},94720:(e,t,r)=>{r.d(t,{AJ:()=>v,Cb:()=>T,D0:()=>M,D5:()=>$,DN:()=>h,Jn:()=>u,MR:()=>f,Ok:()=>N,QF:()=>c,SN:()=>j,UV:()=>P,Vv:()=>k,Yj:()=>E,Yn:()=>L,bv:()=>w,cm:()=>p,cv:()=>y,jO:()=>C,px:()=>R,tp:()=>S,uc:()=>b,y8:()=>g});var n=r(49433),s=r(82680),o=r(84230);let a=e=>n.$mh({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new s.uV({message:`fetch ${e} failed`,cause:t})}),l=(e,t)=>n.$mh({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:r=>new s.uV({message:`${t.method} ${e} failed`,cause:r})}),i=(e,t)=>l(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),d=(e,t)=>n.$mh({try:async()=>{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`);return await r.json()},catch:t=>new s.uV({message:`POST ${e} failed`,cause:t})}),c=(e,t)=>n.JkU(function*(){let r=new URLSearchParams({cwd:e});t&&r.set("tabId",t);let n=yield*a(`/api/terminal/env?${r}`);return{env:n.env||{},home:n.home||""}}),u=()=>a("/api/terminal/aliases").pipe(n.TjK(e=>e.aliases||{})),m=(e,t)=>{let r=`/api/terminal/bubble-order?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}`;return(0,o.F)(r,a(r))},x=n.OH5(()=>(0,o.T)("/api/terminal/bubble-order")),h=(e,t)=>m(e,t).pipe(n.TjK(e=>e.order||[])),f=(e,t)=>m(e,t).pipe(n.TjK(e=>e.titles||{})),p=(e,t,r,s)=>i("/api/terminal/bubble-order",{cwd:e,tabId:t,order:r,sourceId:s}).pipe(n.yeE(x)),g=(e,t,r,s)=>i("/api/terminal/bubble-order",{cwd:e,tabId:t,titles:{[r]:s}}).pipe(n.yeE(x)),b=(e,t,r,n=100)=>a(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}&page=${r}&pageSize=${n}`),v=(e,t,r,n)=>i("/api/terminal/history",{cwd:e,tabId:t,entry:r,sourceId:n}),j=(e,t,r,n)=>l(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}&commandId=${encodeURIComponent(r)}${n?`&sourceId=${encodeURIComponent(n)}`:""}`,{method:"DELETE"}),w=(e,t,r,n,s)=>l("/api/terminal/history",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,tabId:t,id:r,fields:n,sourceId:s})}),k=e=>i("/api/terminal/env",e),y=e=>i("/api/terminal/aliases",{aliases:e}),N=e=>i("/api/terminal/register",e),C=e=>i("/api/terminal/unregister",e),S=e=>n.$mh({try:async()=>{let t=await fetch("/api/terminal/autocomplete",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"POST /api/terminal/autocomplete failed",cause:e})}),M=e=>a(`/api/project-settings?cwd=${encodeURIComponent(e)}`),L=e=>i("/api/project-settings",e),E=()=>a("/api/services/config?scope=global"),P=e=>a(`/api/services/config?cwd=${encodeURIComponent(e)}`),T=e=>d("/api/services/config",e),$=()=>a("/api/terminal/running"),R=e=>d("/api/terminal/running",{commandId:e})},96472:(e,t,r)=>{r.d(t,{AH:()=>u,T$:()=>c,ej:()=>d,n8:()=>i});var n=r(49433),s=r(82680),o=r(8183),a=r(95045),l=r(75346);let i=e=>n.$mh({try:async()=>{let t=await fetch(`/api/project-state?cwd=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:e=>new s.uV({message:"loadProjectState failed",cause:e})}).pipe(n.Mim(e=>n.OH5(()=>(0,o.EF)(e.sessionTitles??[])))),d=e=>n.$mh({try:async()=>{let t=await fetch("/api/project-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"saveProjectState failed",cause:e})}),c=(e,t)=>n.$mh({try:async()=>{let r=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,action:"touch"})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"touchRecentSession failed",cause:e})}),u=(e,t,r,o)=>n.DYE(()=>{if(!o())return n.PyW(null);let i=(e,t)=>n.$mh({try:async()=>{let t=await fetch(`${e}?readBoundary=1`,{cache:"no-store"});if(!t.ok)throw Error(`HTTP ${t.status}`);let{readBefore:r}=await t.json();if("number"!=typeof r||!Number.isFinite(r))throw Error("Invalid read boundary");return r},catch:e=>new s.uV({message:"Read boundary request failed",cause:e})}).pipe(n.qIB(e=>n.DYE(()=>o()?t(e).pipe(n.as(e)):n.PyW(null))));return n.Q7R([n.gPK(i("/api/global-state",o=>{let a;return a={readBefore:o,engine:r},n.$mh({try:async()=>{let r=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:"normal",action:"status",...a})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})})})),n.gPK(i("/api/scheduled-tasks",o=>((e,t={})=>n.$mh({try:async()=>{let r=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e,...t}})});if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})}).pipe(n.Mim(()=>n.OH5(()=>(0,a.F)(l.n.ScheduledTasksChanged,{})))))(t,{cwd:e,readBefore:o,engine:r})))],{concurrency:"unbounded"}).pipe(n.qIB(([e,r])=>n.jJl([e,r],e=>"Left"===e._tag?n.FFw("Session read failed").pipe(n.swY({sessionId:t,cause:e.left})):n.rIH).pipe(n.as("Right"===e._tag?e.right:null))))})},96625:(e,t,r)=>{r.d(t,{V0:()=>p,WB:()=>h,nJ:()=>f});var n=r(95155),s=r(12115),o=r(79114),a=r(58250),l=r(23348),i=r(33442),d=r(67415),c=r(86957),u=r(83448),m=r(23970),x=r(20235);function h({extraCommands:e,selfSessionId:t}={}){let[r,n]=(0,s.useState)([]),[o,x]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)([]);(0,s.useEffect)(()=>{c.t4.runPromiseExit((0,u.M5)()).then(e=>{"Success"===e._tag?n(e.value):console.error("Failed to load commands:",e.cause)})},[]);let v=(0,s.useCallback)(async()=>{let e=await c.t4.runPromiseExit((0,u.l1)());if("Success"===e._tag){let t=e.value.skills??e.value;x((Array.isArray(t)?t:[]).filter(e=>e.valid&&!!e.name).map(e=>({name:`/${e.name}`,description:e.description||"",source:"skill",skillPath:e.path,argumentHint:e.argumentHint})))}else console.error("Failed to load skills:",e.cause)},[]);(0,s.useEffect)(()=>(v(),(0,a.U)(v)),[v]);let j=(0,s.useRef)(0),w=(0,s.useCallback)(async()=>{let e=++j.current,t=await c.t4.runPromiseExit((0,l.jm)());e===j.current&&("Success"===t._tag?p(t.value.flatMap(e=>e.valid?[{name:`@${e.name}`,description:e.description,source:"bot"}]:[])):console.error("Failed to load bots:",t.cause))},[]);(0,s.useEffect)(()=>(w(),(0,i.a)(w)),[w]);let k=(0,s.useRef)(0),y=(0,s.useCallback)(async()=>{let e=++k.current,t=await c.t4.runPromiseExit((0,d.VU)());e===k.current&&("Success"===t._tag?b(t.value.flatMap(e=>{let t;return e.name&&e.engine?[{name:`@${e.name}`,description:(t=e.cwd).split(/[\\/]/).filter(Boolean).pop()??t,source:"session",sessionKey:`${e.cwd}
41
+ ${e.sessionId}`,sessionId:e.sessionId,cwd:e.cwd}]:[]})):console.error("Failed to load session Bots:",t.cause))},[]);(0,s.useEffect)(()=>(y(),(0,i.a)(y)),[y]);let N=(0,s.useMemo)(()=>{let n=new Set([...e??[],...r,...o].map(e=>e.name.slice(1))),s=new Set(f.map(e=>e.name.slice(1))),a={isSkill:e=>n.has(e),isBot:e=>s.has(e),sessions:g.map(e=>({title:e.name.slice(1),cwd:e.cwd??"",sessionId:e.sessionId??""})),selfSessionId:t};return e=>(0,m.fp)(e,a)},[e,r,o,f,g,t]);return{commands:r,skills:o,bots:f,sessionBots:g,refreshSessionBots:y,matchLine:N}}function f({value:e,onChange:t,textareaRef:r,extraCommands:n,selfSessionId:o}){let{commands:a,skills:l,bots:i,sessionBots:d,refreshSessionBots:c,matchLine:u}=h({extraCommands:n,selfSessionId:o}),[m,x]=(0,s.useState)(e.length),[p,g]=(0,s.useState)(0),[b,v]=(0,s.useState)(()=>e.length>0),j=(0,s.useRef)(null),w=(0,s.useMemo)(()=>{let t=0===m?0:e.lastIndexOf("\n",m-1)+1,r=e.indexOf("\n",m),n=-1===r?e.length:r;return{text:e.slice(t,n),start:t,end:n}},[e,m]),k=(0,s.useMemo)(()=>{let e=w.text.match(/^\s*(\/@|\/|@)([a-zA-Z0-9-]*)$/);if(e)return{marker:e[1],verb:e[2].toLowerCase(),text:e[2]};let t=w.text.match(/^\s*@(\S.*)$/);return t?{marker:"@",verb:null,text:t[1]}:null},[w.text]),y=k?.marker==="@";(0,s.useEffect)(()=>{y&&c()},[y,c]);let N=(0,s.useMemo)(()=>{if(!k)return[];let{verb:e,text:t}=k,r=t=>null!==e&&t.name.slice(1).toLowerCase().startsWith(e);if("@"===k.marker){let e=t.toLowerCase();if(/\s$/.test(e)&&d.some(t=>t.name.slice(1).toLowerCase()===e.trimEnd()))return[];let n=d.filter(e=>e.sessionId!==o).filter(t=>t.name.slice(1).toLowerCase().includes(e)),s=n.filter(t=>t.name.slice(1).toLowerCase().startsWith(e));return[...i.filter(r),...s,...n.filter(e=>!s.includes(e))]}return[...(n??[]).filter(r),...a.filter(r),...l.filter(r)]},[k,n,a,l,i,d,o]),C=!b&&!!k&&N.length>0,S=(0,s.useRef)(e);(0,s.useLayoutEffect)(()=>{S.current!==e&&(queueMicrotask(()=>g(0)),b&&queueMicrotask(()=>v(!1)),S.current=e)},[e,b]),(0,s.useLayoutEffect)(()=>{if(C&&j.current){let e=j.current.children[p];e&&e.scrollIntoView({block:"nearest"})}},[p,C]);let M=(0,s.useCallback)(e=>{x(e.selectionStart??0)},[]),L=(0,s.useCallback)(n=>{let s=k?.marker??"/",o=`${s}${n.name.slice(1)} `,a=e.slice(0,w.start),l=e.slice(w.end),i=a.length+o.length;t(a+o+l),x(i),requestAnimationFrame(()=>{let e=r.current;e&&(e.focus(),e.setSelectionRange(i,i))})},[e,w,k,t,r]),E=(0,s.useCallback)(e=>{if(e.nativeEvent.isComposing||!C||0===N.length)return!1;let t=()=>{e.preventDefault(),e.stopPropagation()};return"ArrowDown"===e.key?(t(),g(e=>(e+1)%N.length),!0):"ArrowUp"===e.key?(t(),g(e=>(e-1+N.length)%N.length),!0):"Enter"===e.key||"Tab"===e.key?(t(),L(N[p]),!0):"Escape"===e.key&&(t(),v(!0),!0)},[C,N,p,L]);return{isOpen:C,items:N,selectedIndex:p,marker:k?.marker??"/",listRef:j,selectCommand:L,handleKeyDown:E,trackCaret:M,matchLine:u}}function p({ac:e,className:t=""}){let{t:r}=(0,o.Bd)(),{isOpen:s,items:a,selectedIndex:l,marker:i,listRef:d,selectCommand:c}=e;return s&&0!==a.length?(0,n.jsx)("div",{ref:d,className:`overflow-y-auto bg-card border border-border rounded-lg shadow-lv2 ${t}`,children:a.map((e,t)=>{let s=t>0?a[t-1]:null,o="skill"===e.source&&(!s||"skill"!==s.source),d=e=>e?.source==="bot"||e?.source==="session",u=d(e)&&!d(s),m="builtin"===e.source&&0===t;return(0,n.jsxs)("div",{children:[m&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),u&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Bots"}),(0,n.jsxs)("div",{onClick:()=>c(e),className:`px-4 py-2 cursor-pointer ${t===l?"bg-brand/10":"hover:bg-hover"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:`${x.GI} shrink-0 text-sm`,children:i+e.name.slice(1)}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:"builtin"===e.source?r(`commands.${e.name.slice(1)}`,{defaultValue:e.description}):e.description}),(0,n.jsx)("span",{className:`text-xs px-1.5 py-0.5 rounded ${(e=>{switch(e){case"builtin":return"bg-brand/15 text-brand dark:bg-brand/25 dark:text-teal-11";case"skill":return"bg-purple-9/15 text-purple-11 dark:bg-purple-9/25 dark:text-purple-11";case"bot":return"bg-teal-9/15 text-teal-11 dark:bg-teal-9/25 dark:text-teal-11";case"session":return"bg-amber-9/15 text-amber-11 dark:bg-amber-9/25 dark:text-amber-11"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return r("common.builtin");case"skill":return"Skill";case"bot":return"Bot";case"session":return r("bots.sessionBadge")}})(e.source)})]}),"skill"===e.source&&e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 pl-0 truncate",children:e.argumentHint})]})]},e.sessionKey??e.name)})}):null}},96901:(e,t,r)=>{r.r(t),r.d(t,{XtermRenderer:()=>x});var n=r(95155),s=r(12115),o=r(8422),a=r(63606),l=r(93090),i=r(3238);let d={foreground:"#d4d4d8",cursor:"#d4d4d8",cursorAccent:"#1a1a2e",selectionBackground:"#3b82f680",black:"#27272a",red:"#f87171",green:"#4ade80",yellow:"#facc15",blue:"#60a5fa",magenta:"#c084fc",cyan:"#22d3ee",white:"#e4e4e7",brightBlack:"#52525b",brightRed:"#fca5a5",brightGreen:"#86efac",brightYellow:"#fde047",brightBlue:"#93c5fd",brightMagenta:"#d8b4fe",brightCyan:"#67e8f9",brightWhite:"#fafafa"},c={foreground:"#1d2126",cursor:"#1d2126",cursorAccent:"#ffffff",selectionBackground:"#3b82f640",black:"#1d2126",red:"#ce2c31",green:"#18774c",yellow:"#a13812",blue:"#0d74ce",magenta:"#5746af",cyan:"#1c5454",white:"#60636c",brightBlack:"#787b87",brightRed:"#e5484d",brightGreen:"#2b9c67",brightYellow:"#bd4b00",brightBlue:"#0478d7",brightMagenta:"#6d54cf",brightCyan:"#3a7877",brightWhite:"#1d2126"},u={light:"#ffffff",dark:"#1b1b1d"};function m(e,t){let r=u[t];if(!e)return r;let n=getComputedStyle(e).getPropertyValue("--card").trim(),s=/^([\d.]+)\s+([\d.]+)%\s+([\d.]+)%$/.exec(n);if(!s)return r;let o=Number(s[1]),a=Number(s[2])/100,l=Number(s[3])/100,i=(1-Math.abs(2*l-1))*a,d=i*(1-Math.abs(o/60%2-1)),c=l-i/2,[m,x,h]=[[i,d,0],[d,i,0],[0,i,d],[0,d,i],[d,0,i],[i,0,d]][Math.floor(o/60)%6],f=e=>Math.round((e+c)*255).toString(16).padStart(2,"0");return`#${f(m)}${f(x)}${f(h)}`}let x=(0,s.memo)((0,s.forwardRef)(function({output:e,isRunning:t,onInput:r,onResize:u,maximized:x,height:h,directWrite:f,fixedSize:p},g){let b=(0,s.useRef)(null),v=(0,s.useRef)(null),j=(0,s.useRef)(null),w=(0,s.useRef)(null),k=(0,s.useRef)(0),y=(0,s.useRef)(r),N=(0,s.useRef)(u),C=(0,s.useRef)(p);C.current=p,(0,s.useEffect)(()=>{y.current=r},[r]),(0,s.useEffect)(()=>{N.current=u},[u]);let S=(0,i.Ql)()?.resolvedTheme??"dark",M="dark"===S?d:c,L=(0,s.useRef)(M);L.current=M;let E=(0,s.useRef)(S);E.current=S,(0,s.useEffect)(()=>{let e=v.current;e&&(e.options.theme={...M,background:m(b.current,S)})},[M,S]),(0,s.useImperativeHandle)(g,()=>({findNext:e=>w.current?.findNext(e,{caseSensitive:!1,decorations:{matchBackground:"#facc1550",matchBorder:"#facc15",matchOverviewRuler:"#facc15",activeMatchBackground:"#facc1590",activeMatchBorder:"#facc15",activeMatchColorOverviewRuler:"#facc15"}})??!1,findPrevious:e=>w.current?.findPrevious(e,{caseSensitive:!1,decorations:{matchBackground:"#facc1550",matchBorder:"#facc15",matchOverviewRuler:"#facc15",activeMatchBackground:"#facc1590",activeMatchBorder:"#facc15",activeMatchColorOverviewRuler:"#facc15"}})??!1,clearSearch:()=>{w.current?.clearDecorations()},write:e=>{v.current?.write(e)},reset:()=>{v.current?.reset()},refresh:()=>{let e=v.current;if(e){try{j.current?.fit()}catch{}try{e.refresh(0,e.rows-1)}catch{}}}}),[]),(0,s.useEffect)(()=>{if(!b.current)return;let e=new o.B({convertEol:!1,scrollback:5e3,fontSize:13,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',cursorStyle:"block",cursorBlink:!0,disableStdin:!1,allowProposedApi:!0,theme:{...L.current,background:m(b.current,E.current)}}),t=new a.Y,r=new l.n;e.loadAddon(t),e.loadAddon(r),e.open(b.current),e.parser.registerOscHandler(52,()=>!0),e.onData(e=>{y.current?.(e)});try{t.fit(),N.current&&N.current(e.cols,e.rows)}catch{}return v.current=e,j.current=t,w.current=r,k.current=0,()=>{e.dispose(),v.current=null,j.current=null,w.current=null,k.current=0}},[]),(0,s.useEffect)(()=>{let t=v.current;if(!t)return;if(f){e&&0===k.current&&(t.write(e),k.current=e.length);return}let r=!1;if(e.length<k.current&&(t.reset(),k.current=0,r=!0),e.length>k.current){let r=e.slice(k.current);t.write(r),k.current=e.length}r&&y.current&&requestAnimationFrame(()=>t.focus())},[e,f]),(0,s.useEffect)(()=>{t&&v.current&&v.current.focus()},[t]);let P=(0,s.useCallback)(()=>{let e=v.current,t=j.current;if(e&&t&&!C.current)try{t.fit(),N.current&&N.current(e.cols,e.rows)}catch{}},[]),T=p?.cols,$=p?.rows;return(0,s.useEffect)(()=>{let e=v.current;if(e&&T&&$)try{e.resize(T,$)}catch{}},[T,$]),(0,s.useEffect)(()=>{requestAnimationFrame(()=>{P(),requestAnimationFrame(P)})},[x,P]),(0,s.useEffect)(()=>{let e=b.current;if(!e)return;let t=new ResizeObserver(P);return t.observe(e),()=>t.disconnect()},[P]),(0,s.useEffect)(()=>{let e=b.current;if(!e)return;let t=t=>{let r=e.querySelector(".xterm-viewport");if(!r)return;let n=r.scrollHeight-r.clientHeight,s=t.deltaY<0&&r.scrollTop<=0,o=t.deltaY>0&&r.scrollTop>=n-1;(n<=0||s||o)&&t.preventDefault()};return e.addEventListener("wheel",t,{passive:!1}),()=>e.removeEventListener("wheel",t)},[]),(0,n.jsx)("div",{ref:b,className:"xterm-renderer px-2",style:{height:h??"100%",overflow:p?"auto":"hidden"}})}))},99161:(e,t,r)=>{r.d(t,{g:()=>b});var n=r(95155),s=r(12115),o=r(79114),a=r(5135),l=r(38408),i=r(34075),d=r(48764),c=r(86957),u=r(21362),m=r(38798),x=r(48368),h=r(78916);let f=/^(history|reports?|cache|caches|logs?|outputs?|tmp|temp|dist|build|runs?)$/i,p=(0,s.memo)(function({files:e,selected:t,onSelect:r}){let o=(0,s.useMemo)(()=>(function(e){let t={name:"",path:"",children:[]};for(let{path:r}of e){let e=r.split("/"),n=t;e.forEach((t,r)=>{let s=r===e.length-1,o=e.slice(0,r+1).join("/"),a=n.children.find(e=>e.name===t&&!!e.children==!s);a||(a=s?{name:t,path:o}:{name:t,path:o,children:[],count:0},n.children.push(a)),s||(a.count=(a.count??0)+1),n=a})}let r=e=>{e.sort((e,t)=>!!e.children!=!!t.children?e.children?-1:1:e.name.localeCompare(t.name)),e.forEach(e=>e.children&&r(e.children))};return r(t.children),t.children})(e),[e]),[a,l]=(0,s.useState)(()=>new Set),i=(e,s)=>e.map(e=>{if(e.children){let t,r=(t=!f.test(e.name),a.has(e.path)?!t:t);return(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{onClick:()=>{let t;return t=e.path,l(e=>{let r=new Set(e);return r.has(t)?r.delete(t):r.add(t),r})},style:{paddingLeft:8+12*s},"data-tooltip":e.path+"/",className:"flex items-center gap-1 pr-2 py-1 rounded cursor-pointer text-xs text-muted-foreground hover:bg-hover",children:[(0,n.jsx)(u.A,{className:`w-3 h-3 flex-shrink-0 transition-transform ${r?"rotate-90":""}`}),(0,n.jsx)(m.A,{className:"w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate",children:e.name}),(0,n.jsx)("span",{className:"ml-auto text-[10px] tabular-nums text-foreground-subtle",children:e.count})]}),r&&i(e.children,s+1)]},`d:${e.path}`)}let o=/\.(md|markdown|txt)$/i.test(e.name)?x.A:h.A;return(0,n.jsxs)("div",{onClick:()=>r(e.path),style:{paddingLeft:8+12*s+16},className:`flex items-center gap-1 pr-2 py-1 rounded cursor-pointer text-xs ${e.path===t?"bg-brand/10 text-foreground":"text-muted-foreground hover:bg-hover hover:text-foreground"}`,"data-tooltip":e.path,children:[(0,n.jsx)(o,{className:"w-3.5 h-3.5 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate font-mono",children:e.name})]},`f:${e.path}`)});return(0,n.jsx)("div",{className:"p-1 space-y-px",children:i(o,0)})}),g=()=>{};function b({endpoint:e,id:t,entryFile:r,title:u,actions:m,onClose:x=g}){let{t:h}=(0,o.Bd)(),[f,v]=(0,s.useState)("preview"),[j,w]=(0,s.useState)(null),[k,y]=(0,s.useState)(""),[N,C]=(0,s.useState)(r),[S,M]=(0,s.useState)(null),[L,E]=(0,s.useState)(224),P=(0,s.useRef)(null),T=(0,s.useCallback)(e=>{"mouse"===e.pointerType&&0===e.button&&(e.preventDefault(),P.current={startX:e.clientX,startWidth:L},e.currentTarget.setPointerCapture(e.pointerId))},[L]),$=(0,s.useCallback)(e=>{let t=P.current;t&&E(Math.min(336,Math.max(224,t.startWidth+(e.clientX-t.startX))))},[]),R=(0,s.useCallback)(e=>{P.current&&(P.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId))},[]);(0,s.useEffect)(()=>{let r=!1;return c.t4.runPromiseExit((0,d.De)(e,t)).then(e=>{r||("Success"===e._tag?(w(e.value.files),y(e.value.dir)):w(void 0))}),()=>{r=!0}},[e,t]),(0,s.useEffect)(()=>{let r=!1;return M(null),c.t4.runPromiseExit((0,d.Ek)(e,t,N)).then(e=>{r||M("Success"===e._tag?e.value:{path:N,kind:"binary",size:0})}),()=>{r=!0}},[e,t,N]);let I=k?`${k}/${N}`:"",F=/\.(md|markdown)$/i.test(N),B=!!j&&j.length>1,D=(0,s.useCallback)(async()=>{if(I)try{await navigator.clipboard.writeText(I),(0,i.oR)(h("common.copiedPath"),"success")}catch{(0,i.oR)(h("common.copyFailed"),"error")}},[I,h]),A=e=>(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:e});return(0,n.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground truncate",children:u}),(0,n.jsx)("button",{onClick:D,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-hover rounded transition-colors",title:h("skills.copyPath"),children:(0,n.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})]}),I&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5","data-tooltip":I,children:I})]}),(0,n.jsxs)("div",{className:`flex items-center rounded-md border border-border overflow-hidden text-xs flex-shrink-0 ${F?"":"invisible"}`,children:[(0,n.jsx)("button",{onClick:()=>v("preview"),className:`px-3 py-1 transition-colors ${"preview"===f?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:h("common.preview")}),(0,n.jsx)("button",{onClick:()=>v("source"),className:`px-3 py-1 transition-colors ${"source"===f?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-hover"}`,children:h("skills.source")})]}),m]}),(0,n.jsxs)("div",{className:"flex-1 flex min-h-0",children:[B&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex-shrink-0 overflow-y-auto",style:{width:L},children:(0,n.jsx)(p,{files:j,selected:N,onSelect:C})}),(0,n.jsx)("div",{onPointerDown:T,onPointerMove:$,onPointerUp:R,onPointerCancel:R,className:"w-[5px] flex-shrink-0 relative cursor-col-resize group",children:(0,n.jsx)("div",{className:"absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border group-hover:bg-brand transition-colors"})})]}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 min-h-0",children:(()=>{if(void 0===j)return A(h("skills.cannotRead"));if(!S)return A(h("common.loading"));if("text"!==S.kind)return A("tooLarge"===S.kind?h("skills.fileTooLarge"):h("skills.fileNotPreviewable"));let e=S.content??"";if(!F||"source"===f){let t;return t=I||N,(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:(0,n.jsx)(l.XO,{content:e,filePath:t,className:"min-h-full"})})}return(0,n.jsx)(a.M,{content:e,filePath:I||N,cwd:k,embedded:!0,onClose:x,tocDefaultCollapsed:!0})})()})]})]})}}}]);