@surething/cockpit 1.0.213 → 1.0.215

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 (572) hide show
  1. package/.next-prod/BUILD_ID +1 -1
  2. package/.next-prod/app-path-routes-manifest.json +6 -2
  3. package/.next-prod/build-manifest.json +2 -2
  4. package/.next-prod/prerender-manifest.json +3 -3
  5. package/.next-prod/routes-manifest.json +24 -0
  6. package/.next-prod/server/app/_global-error/page.js +3 -3
  7. package/.next-prod/server/app/_global-error/page.js.nft.json +1 -1
  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/_global-error.segment.rsc +1 -1
  14. package/.next-prod/server/app/_global-error.segments/_head.segment.rsc +1 -1
  15. package/.next-prod/server/app/_global-error.segments/_index.segment.rsc +1 -1
  16. package/.next-prod/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  17. package/.next-prod/server/app/_not-found/page.js +2 -2
  18. package/.next-prod/server/app/_not-found/page.js.nft.json +1 -1
  19. package/.next-prod/server/app/_not-found/page_client-reference-manifest.js +1 -1
  20. package/.next-prod/server/app/_not-found.html +1 -1
  21. package/.next-prod/server/app/_not-found.rsc +3 -3
  22. package/.next-prod/server/app/_not-found.segments/_full.segment.rsc +3 -3
  23. package/.next-prod/server/app/_not-found.segments/_head.segment.rsc +1 -1
  24. package/.next-prod/server/app/_not-found.segments/_index.segment.rsc +3 -3
  25. package/.next-prod/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  26. package/.next-prod/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  27. package/.next-prod/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  28. package/.next-prod/server/app/api/agent/test/route.js +1 -1
  29. package/.next-prod/server/app/api/agent/test/route.js.nft.json +1 -1
  30. package/.next-prod/server/app/api/bash/route.js +1 -1
  31. package/.next-prod/server/app/api/bash/route.js.nft.json +1 -1
  32. package/.next-prod/server/app/api/chat/codex/route.js +2 -2
  33. package/.next-prod/server/app/api/chat/codex/route.js.nft.json +1 -1
  34. package/.next-prod/server/app/api/chat/deepseek/route.js +2 -2
  35. package/.next-prod/server/app/api/chat/deepseek/route.js.nft.json +1 -1
  36. package/.next-prod/server/app/api/chat/kimi/route.js +2 -2
  37. package/.next-prod/server/app/api/chat/kimi/route.js.nft.json +1 -1
  38. package/.next-prod/server/app/api/chat/ollama/route.js +4 -4
  39. package/.next-prod/server/app/api/chat/ollama/route.js.nft.json +1 -1
  40. package/.next-prod/server/app/api/chat/route.js +2 -2
  41. package/.next-prod/server/app/api/chat/route.js.nft.json +1 -1
  42. package/.next-prod/server/app/api/claude-stats/route.js +1 -1
  43. package/.next-prod/server/app/api/claude-stats/route.js.nft.json +1 -1
  44. package/.next-prod/server/app/api/commands/route.js +1 -1
  45. package/.next-prod/server/app/api/commands/route.js.nft.json +1 -1
  46. package/.next-prod/server/app/api/comments/route.js +1 -1
  47. package/.next-prod/server/app/api/comments/route.js.nft.json +1 -1
  48. package/.next-prod/server/app/api/db/columns/route.js +2 -2
  49. package/.next-prod/server/app/api/db/columns/route.js.nft.json +1 -1
  50. package/.next-prod/server/app/api/db/connect/route.js +1 -1
  51. package/.next-prod/server/app/api/db/connect/route.js.nft.json +1 -1
  52. package/.next-prod/server/app/api/db/disconnect/route.js +1 -1
  53. package/.next-prod/server/app/api/db/disconnect/route.js.nft.json +1 -1
  54. package/.next-prod/server/app/api/db/export/route.js +1 -1
  55. package/.next-prod/server/app/api/db/export/route.js.nft.json +1 -1
  56. package/.next-prod/server/app/api/db/query/route.js +1 -1
  57. package/.next-prod/server/app/api/db/query/route.js.nft.json +1 -1
  58. package/.next-prod/server/app/api/db/schemas/route.js +1 -1
  59. package/.next-prod/server/app/api/db/schemas/route.js.nft.json +1 -1
  60. package/.next-prod/server/app/api/dev/spans/route.js +1 -1
  61. package/.next-prod/server/app/api/dev/spans/route.js.nft.json +1 -1
  62. package/.next-prod/server/app/api/extension/version/route.js +1 -1
  63. package/.next-prod/server/app/api/extension/version/route.js.nft.json +1 -1
  64. package/.next-prod/server/app/api/file/route.js +1 -1
  65. package/.next-prod/server/app/api/file/route.js.nft.json +1 -1
  66. package/.next-prod/server/app/api/files/blame/route.js +1 -1
  67. package/.next-prod/server/app/api/files/blame/route.js.nft.json +1 -1
  68. package/.next-prod/server/app/api/files/clipboard/route.js +1 -1
  69. package/.next-prod/server/app/api/files/clipboard/route.js.nft.json +1 -1
  70. package/.next-prod/server/app/api/files/copy/route.js +1 -1
  71. package/.next-prod/server/app/api/files/copy/route.js.nft.json +1 -1
  72. package/.next-prod/server/app/api/files/delete/route.js +1 -1
  73. package/.next-prod/server/app/api/files/delete/route.js.nft.json +1 -1
  74. package/.next-prod/server/app/api/files/expanded/route.js +1 -1
  75. package/.next-prod/server/app/api/files/expanded/route.js.nft.json +1 -1
  76. package/.next-prod/server/app/api/files/index/route.js +1 -1
  77. package/.next-prod/server/app/api/files/index/route.js.nft.json +1 -1
  78. package/.next-prod/server/app/api/files/init/route.js +1 -1
  79. package/.next-prod/server/app/api/files/init/route.js.nft.json +1 -1
  80. package/.next-prod/server/app/api/files/paste/route.js +1 -1
  81. package/.next-prod/server/app/api/files/paste/route.js.nft.json +1 -1
  82. package/.next-prod/server/app/api/files/read/route.js +1 -1
  83. package/.next-prod/server/app/api/files/read/route.js.nft.json +1 -1
  84. package/.next-prod/server/app/api/files/readdir/route.js +1 -1
  85. package/.next-prod/server/app/api/files/readdir/route.js.nft.json +1 -1
  86. package/.next-prod/server/app/api/files/recent/route.js +1 -1
  87. package/.next-prod/server/app/api/files/recent/route.js.nft.json +1 -1
  88. package/.next-prod/server/app/api/files/save/route.js +1 -1
  89. package/.next-prod/server/app/api/files/save/route.js.nft.json +1 -1
  90. package/.next-prod/server/app/api/files/search/route.js +1 -1
  91. package/.next-prod/server/app/api/files/search/route.js.nft.json +1 -1
  92. package/.next-prod/server/app/api/files/stat/route.js +1 -1
  93. package/.next-prod/server/app/api/files/stat/route.js.nft.json +1 -1
  94. package/.next-prod/server/app/api/files/text/route.js +1 -1
  95. package/.next-prod/server/app/api/files/text/route.js.nft.json +1 -1
  96. package/.next-prod/server/app/api/git/branch-diff/route.js +1 -1
  97. package/.next-prod/server/app/api/git/branch-diff/route.js.nft.json +1 -1
  98. package/.next-prod/server/app/api/git/branches/route.js +1 -1
  99. package/.next-prod/server/app/api/git/branches/route.js.nft.json +1 -1
  100. package/.next-prod/server/app/api/git/commit-diff/route.js +1 -1
  101. package/.next-prod/server/app/api/git/commit-diff/route.js.nft.json +1 -1
  102. package/.next-prod/server/app/api/git/commits/route.js +1 -1
  103. package/.next-prod/server/app/api/git/commits/route.js.nft.json +1 -1
  104. package/.next-prod/server/app/api/git/diff/route.js +1 -1
  105. package/.next-prod/server/app/api/git/diff/route.js.nft.json +1 -1
  106. package/.next-prod/server/app/api/git/discard/route.js +1 -1
  107. package/.next-prod/server/app/api/git/discard/route.js.nft.json +1 -1
  108. package/.next-prod/server/app/api/git/stage/route.js +1 -1
  109. package/.next-prod/server/app/api/git/stage/route.js.nft.json +1 -1
  110. package/.next-prod/server/app/api/git/status/route.js +1 -1
  111. package/.next-prod/server/app/api/git/status/route.js.nft.json +1 -1
  112. package/.next-prod/server/app/api/git/unstage/route.js +1 -1
  113. package/.next-prod/server/app/api/git/unstage/route.js.nft.json +1 -1
  114. package/.next-prod/server/app/api/git/worktree/route.js +1 -1
  115. package/.next-prod/server/app/api/git/worktree/route.js.nft.json +1 -1
  116. package/.next-prod/server/app/api/global-state/route.js +1 -1
  117. package/.next-prod/server/app/api/global-state/route.js.nft.json +1 -1
  118. package/.next-prod/server/app/api/jupyter/load/route.js +1 -1
  119. package/.next-prod/server/app/api/jupyter/load/route.js.nft.json +1 -1
  120. package/.next-prod/server/app/api/jupyter/save/route.js +1 -1
  121. package/.next-prod/server/app/api/jupyter/save/route.js.nft.json +1 -1
  122. package/.next-prod/server/app/api/jupyter/shutdown/route.js +1 -1
  123. package/.next-prod/server/app/api/jupyter/shutdown/route.js.nft.json +1 -1
  124. package/.next-prod/server/app/api/lsp/definition/route.js +1 -1
  125. package/.next-prod/server/app/api/lsp/definition/route.js.nft.json +1 -1
  126. package/.next-prod/server/app/api/lsp/hover/route.js +1 -1
  127. package/.next-prod/server/app/api/lsp/hover/route.js.nft.json +1 -1
  128. package/.next-prod/server/app/api/lsp/references/route.js +1 -1
  129. package/.next-prod/server/app/api/lsp/references/route.js.nft.json +1 -1
  130. package/.next-prod/server/app/api/lsp/status/route.js +1 -1
  131. package/.next-prod/server/app/api/lsp/status/route.js.nft.json +1 -1
  132. package/.next-prod/server/app/api/lsp/warmup/route.js +1 -1
  133. package/.next-prod/server/app/api/lsp/warmup/route.js.nft.json +1 -1
  134. package/.next-prod/server/app/api/mysql/columns/route.js +1 -1
  135. package/.next-prod/server/app/api/mysql/columns/route.js.nft.json +1 -1
  136. package/.next-prod/server/app/api/mysql/connect/route.js +1 -1
  137. package/.next-prod/server/app/api/mysql/connect/route.js.nft.json +1 -1
  138. package/.next-prod/server/app/api/mysql/disconnect/route.js +1 -1
  139. package/.next-prod/server/app/api/mysql/disconnect/route.js.nft.json +1 -1
  140. package/.next-prod/server/app/api/mysql/export/route.js +1 -1
  141. package/.next-prod/server/app/api/mysql/export/route.js.nft.json +1 -1
  142. package/.next-prod/server/app/api/mysql/query/route.js +1 -1
  143. package/.next-prod/server/app/api/mysql/query/route.js.nft.json +1 -1
  144. package/.next-prod/server/app/api/mysql/schemas/route.js +1 -1
  145. package/.next-prod/server/app/api/mysql/schemas/route.js.nft.json +1 -1
  146. package/.next-prod/server/app/api/neo4j/connect/route.js +1 -1
  147. package/.next-prod/server/app/api/neo4j/connect/route.js.nft.json +1 -1
  148. package/.next-prod/server/app/api/neo4j/disconnect/route.js +1 -1
  149. package/.next-prod/server/app/api/neo4j/disconnect/route.js.nft.json +1 -1
  150. package/.next-prod/server/app/api/neo4j/query/route.js +1 -1
  151. package/.next-prod/server/app/api/neo4j/query/route.js.nft.json +1 -1
  152. package/.next-prod/server/app/api/neo4j/schema/route.js +1 -1
  153. package/.next-prod/server/app/api/neo4j/schema/route.js.nft.json +1 -1
  154. package/.next-prod/server/app/api/note/route.js +1 -1
  155. package/.next-prod/server/app/api/note/route.js.nft.json +1 -1
  156. package/.next-prod/server/app/api/ollama/models/route.js +1 -1
  157. package/.next-prod/server/app/api/ollama/models/route.js.nft.json +1 -1
  158. package/.next-prod/server/app/api/ollama/start/route.js +1 -1
  159. package/.next-prod/server/app/api/ollama/start/route.js.nft.json +1 -1
  160. package/.next-prod/server/app/api/open-cursor/route.js +1 -1
  161. package/.next-prod/server/app/api/open-cursor/route.js.nft.json +1 -1
  162. package/.next-prod/server/app/api/open-vscode/route.js +1 -1
  163. package/.next-prod/server/app/api/open-vscode/route.js.nft.json +1 -1
  164. package/.next-prod/server/app/api/pick-folder/route.js +1 -1
  165. package/.next-prod/server/app/api/pick-folder/route.js.nft.json +1 -1
  166. package/.next-prod/server/app/api/pinned-sessions/route.js +1 -1
  167. package/.next-prod/server/app/api/pinned-sessions/route.js.nft.json +1 -1
  168. package/.next-prod/server/app/api/project-settings/route.js +1 -1
  169. package/.next-prod/server/app/api/project-settings/route.js.nft.json +1 -1
  170. package/.next-prod/server/app/api/project-state/route.js +1 -1
  171. package/.next-prod/server/app/api/project-state/route.js.nft.json +1 -1
  172. package/.next-prod/server/app/api/projectGraph/affected/route.js +1 -0
  173. package/.next-prod/server/app/api/projectGraph/affected/route.js.nft.json +1 -0
  174. package/.next-prod/server/app/api/projectGraph/affected/route_client-reference-manifest.js +1 -0
  175. package/.next-prod/server/app/api/projectGraph/callees/route.js +1 -1
  176. package/.next-prod/server/app/api/projectGraph/callees/route.js.nft.json +1 -1
  177. package/.next-prod/server/app/api/projectGraph/callers/route.js +1 -1
  178. package/.next-prod/server/app/api/projectGraph/callers/route.js.nft.json +1 -1
  179. package/.next-prod/server/app/api/projectGraph/coedit/route.js +1 -1
  180. package/.next-prod/server/app/api/projectGraph/coedit/route.js.nft.json +1 -1
  181. package/.next-prod/server/app/api/projectGraph/context/route.js +1 -0
  182. package/.next-prod/server/app/api/projectGraph/context/route.js.nft.json +1 -0
  183. package/.next-prod/server/app/api/projectGraph/context/route_client-reference-manifest.js +1 -0
  184. package/.next-prod/server/app/api/projectGraph/file/route.js +1 -1
  185. package/.next-prod/server/app/api/projectGraph/file/route.js.nft.json +1 -1
  186. package/.next-prod/server/app/api/projectGraph/file-functions/route.js +1 -1
  187. package/.next-prod/server/app/api/projectGraph/file-functions/route.js.nft.json +1 -1
  188. package/.next-prod/server/app/api/projectGraph/impact/route.js +1 -1
  189. package/.next-prod/server/app/api/projectGraph/impact/route.js.nft.json +1 -1
  190. package/.next-prod/server/app/api/projectGraph/related/route.js +1 -0
  191. package/.next-prod/server/app/api/projectGraph/related/route.js.nft.json +1 -0
  192. package/.next-prod/server/app/api/projectGraph/related/route_client-reference-manifest.js +1 -0
  193. package/.next-prod/server/app/api/projectGraph/risk/route.js +1 -0
  194. package/.next-prod/server/app/api/projectGraph/risk/route.js.nft.json +1 -0
  195. package/.next-prod/server/app/api/projectGraph/risk/route_client-reference-manifest.js +1 -0
  196. package/.next-prod/server/app/api/projectGraph/search/route.js +1 -1
  197. package/.next-prod/server/app/api/projectGraph/search/route.js.nft.json +1 -1
  198. package/.next-prod/server/app/api/projects/route.js +1 -1
  199. package/.next-prod/server/app/api/projects/route.js.nft.json +1 -1
  200. package/.next-prod/server/app/api/redis/command/route.js +1 -1
  201. package/.next-prod/server/app/api/redis/command/route.js.nft.json +1 -1
  202. package/.next-prod/server/app/api/redis/connect/route.js +1 -1
  203. package/.next-prod/server/app/api/redis/connect/route.js.nft.json +1 -1
  204. package/.next-prod/server/app/api/redis/delete/route.js +1 -1
  205. package/.next-prod/server/app/api/redis/delete/route.js.nft.json +1 -1
  206. package/.next-prod/server/app/api/redis/disconnect/route.js +1 -1
  207. package/.next-prod/server/app/api/redis/disconnect/route.js.nft.json +1 -1
  208. package/.next-prod/server/app/api/redis/get/route.js +1 -1
  209. package/.next-prod/server/app/api/redis/get/route.js.nft.json +1 -1
  210. package/.next-prod/server/app/api/redis/keys/route.js +1 -1
  211. package/.next-prod/server/app/api/redis/keys/route.js.nft.json +1 -1
  212. package/.next-prod/server/app/api/redis/set/route.js +1 -1
  213. package/.next-prod/server/app/api/redis/set/route.js.nft.json +1 -1
  214. package/.next-prod/server/app/api/review/[id]/comments/route.js +1 -1
  215. package/.next-prod/server/app/api/review/[id]/comments/route.js.nft.json +1 -1
  216. package/.next-prod/server/app/api/review/[id]/replies/route.js +1 -1
  217. package/.next-prod/server/app/api/review/[id]/replies/route.js.nft.json +1 -1
  218. package/.next-prod/server/app/api/review/[id]/route.js +1 -1
  219. package/.next-prod/server/app/api/review/[id]/route.js.nft.json +1 -1
  220. package/.next-prod/server/app/api/review/identify/route.js +1 -1
  221. package/.next-prod/server/app/api/review/identify/route.js.nft.json +1 -1
  222. package/.next-prod/server/app/api/review/order/route.js +1 -1
  223. package/.next-prod/server/app/api/review/order/route.js.nft.json +1 -1
  224. package/.next-prod/server/app/api/review/route.js +1 -1
  225. package/.next-prod/server/app/api/review/route.js.nft.json +1 -1
  226. package/.next-prod/server/app/api/review/share-info/route.js +1 -1
  227. package/.next-prod/server/app/api/review/share-info/route.js.nft.json +1 -1
  228. package/.next-prod/server/app/api/review/users/route.js +1 -1
  229. package/.next-prod/server/app/api/review/users/route.js.nft.json +1 -1
  230. package/.next-prod/server/app/api/scheduled-tasks/route.js +1 -1
  231. package/.next-prod/server/app/api/scheduled-tasks/route.js.nft.json +1 -1
  232. package/.next-prod/server/app/api/services/config/route.js +1 -1
  233. package/.next-prod/server/app/api/services/config/route.js.nft.json +1 -1
  234. package/.next-prod/server/app/api/services/scripts/route.js +1 -1
  235. package/.next-prod/server/app/api/services/scripts/route.js.nft.json +1 -1
  236. package/.next-prod/server/app/api/session/[sessionId]/fork/route.js +1 -1
  237. package/.next-prod/server/app/api/session/[sessionId]/fork/route.js.nft.json +1 -1
  238. package/.next-prod/server/app/api/session/[sessionId]/history/route.js +1 -1
  239. package/.next-prod/server/app/api/session/[sessionId]/history/route.js.nft.json +1 -1
  240. package/.next-prod/server/app/api/session-by-path/route.js +1 -1
  241. package/.next-prod/server/app/api/session-by-path/route.js.nft.json +1 -1
  242. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js +1 -1
  243. package/.next-prod/server/app/api/sessions/projects/[encodedPath]/route.js.nft.json +1 -1
  244. package/.next-prod/server/app/api/sessions/projects/route.js +1 -1
  245. package/.next-prod/server/app/api/sessions/projects/route.js.nft.json +1 -1
  246. package/.next-prod/server/app/api/sessions/route.js +1 -1
  247. package/.next-prod/server/app/api/sessions/route.js.nft.json +1 -1
  248. package/.next-prod/server/app/api/settings/route.js +1 -1
  249. package/.next-prod/server/app/api/settings/route.js.nft.json +1 -1
  250. package/.next-prod/server/app/api/skills/[id]/route.js +1 -1
  251. package/.next-prod/server/app/api/skills/[id]/route.js.nft.json +1 -1
  252. package/.next-prod/server/app/api/skills/content/route.js +1 -1
  253. package/.next-prod/server/app/api/skills/content/route.js.nft.json +1 -1
  254. package/.next-prod/server/app/api/skills/route.js +1 -1
  255. package/.next-prod/server/app/api/skills/route.js.nft.json +1 -1
  256. package/.next-prod/server/app/api/terminal/aliases/route.js +1 -1
  257. package/.next-prod/server/app/api/terminal/aliases/route.js.nft.json +1 -1
  258. package/.next-prod/server/app/api/terminal/autocomplete/route.js +1 -1
  259. package/.next-prod/server/app/api/terminal/autocomplete/route.js.nft.json +1 -1
  260. package/.next-prod/server/app/api/terminal/bubble-order/route.js +1 -1
  261. package/.next-prod/server/app/api/terminal/bubble-order/route.js.nft.json +1 -1
  262. package/.next-prod/server/app/api/terminal/env/route.js +1 -1
  263. package/.next-prod/server/app/api/terminal/env/route.js.nft.json +1 -1
  264. package/.next-prod/server/app/api/terminal/history/route.js +1 -1
  265. package/.next-prod/server/app/api/terminal/history/route.js.nft.json +1 -1
  266. package/.next-prod/server/app/api/version/route.js +1 -1
  267. package/.next-prod/server/app/api/version/route.js.nft.json +1 -1
  268. package/.next-prod/server/app/favicon.ico/route.js +1 -1
  269. package/.next-prod/server/app/favicon.ico/route.js.nft.json +1 -1
  270. package/.next-prod/server/app/manifest.webmanifest/route.js +2 -2
  271. package/.next-prod/server/app/manifest.webmanifest/route.js.nft.json +1 -1
  272. package/.next-prod/server/app/page.js +2 -2
  273. package/.next-prod/server/app/page.js.nft.json +1 -1
  274. package/.next-prod/server/app/page_client-reference-manifest.js +1 -1
  275. package/.next-prod/server/app/project/page.js +2 -2
  276. package/.next-prod/server/app/project/page.js.nft.json +1 -1
  277. package/.next-prod/server/app/project/page_client-reference-manifest.js +1 -1
  278. package/.next-prod/server/app/review/[id]/page.js +2 -2
  279. package/.next-prod/server/app/review/[id]/page.js.nft.json +1 -1
  280. package/.next-prod/server/app/review/[id]/page_client-reference-manifest.js +1 -1
  281. package/.next-prod/server/app-paths-manifest.json +6 -2
  282. package/.next-prod/server/chunks/2540.js +1 -0
  283. package/.next-prod/server/chunks/2939.js +1 -1
  284. package/.next-prod/server/chunks/4008.js +1 -0
  285. package/.next-prod/server/chunks/8916.js +1 -1
  286. package/.next-prod/server/chunks/9658.js +4 -4
  287. package/.next-prod/server/chunks/{7828.js → 9877.js} +80 -3
  288. package/.next-prod/server/middleware-build-manifest.js +1 -1
  289. package/.next-prod/server/pages/404.html +1 -1
  290. package/.next-prod/server/pages/500.html +1 -1
  291. package/.next-prod/server/server-reference-manifest.json +1 -1
  292. package/.next-prod/static/chunks/2171-1d5aa2a301006dfb.js +1 -0
  293. package/.next-prod/static/chunks/{5188-3337a5d88efc5fc1.js → 5188-415582403ef0e29c.js} +2 -2
  294. package/.next-prod/static/chunks/6345-e5ceeb2aeb698eb6.js +14 -0
  295. package/.next-prod/static/chunks/{aaea2bcf-be8b39a8f32280f3.js → aaea2bcf-56770c8875ee56c9.js} +1 -1
  296. package/.next-prod/static/chunks/app/_global-error/page-8ae56b9359db0996.js +1 -0
  297. package/.next-prod/static/chunks/app/api/agent/test/route-8ae56b9359db0996.js +1 -0
  298. package/.next-prod/static/chunks/app/api/bash/route-8ae56b9359db0996.js +1 -0
  299. package/.next-prod/static/chunks/app/api/chat/codex/route-8ae56b9359db0996.js +1 -0
  300. package/.next-prod/static/chunks/app/api/chat/deepseek/route-8ae56b9359db0996.js +1 -0
  301. package/.next-prod/static/chunks/app/api/chat/kimi/route-8ae56b9359db0996.js +1 -0
  302. package/.next-prod/static/chunks/app/api/chat/ollama/route-8ae56b9359db0996.js +1 -0
  303. package/.next-prod/static/chunks/app/api/chat/route-8ae56b9359db0996.js +1 -0
  304. package/.next-prod/static/chunks/app/api/claude-stats/route-8ae56b9359db0996.js +1 -0
  305. package/.next-prod/static/chunks/app/api/commands/route-8ae56b9359db0996.js +1 -0
  306. package/.next-prod/static/chunks/app/api/comments/route-8ae56b9359db0996.js +1 -0
  307. package/.next-prod/static/chunks/app/api/db/columns/route-8ae56b9359db0996.js +1 -0
  308. package/.next-prod/static/chunks/app/api/db/connect/route-8ae56b9359db0996.js +1 -0
  309. package/.next-prod/static/chunks/app/api/db/disconnect/route-8ae56b9359db0996.js +1 -0
  310. package/.next-prod/static/chunks/app/api/db/export/route-8ae56b9359db0996.js +1 -0
  311. package/.next-prod/static/chunks/app/api/db/query/route-8ae56b9359db0996.js +1 -0
  312. package/.next-prod/static/chunks/app/api/db/schemas/route-8ae56b9359db0996.js +1 -0
  313. package/.next-prod/static/chunks/app/api/dev/spans/route-8ae56b9359db0996.js +1 -0
  314. package/.next-prod/static/chunks/app/api/extension/version/route-8ae56b9359db0996.js +1 -0
  315. package/.next-prod/static/chunks/app/api/file/route-8ae56b9359db0996.js +1 -0
  316. package/.next-prod/static/chunks/app/api/files/blame/route-8ae56b9359db0996.js +1 -0
  317. package/.next-prod/static/chunks/app/api/files/clipboard/route-8ae56b9359db0996.js +1 -0
  318. package/.next-prod/static/chunks/app/api/files/copy/route-8ae56b9359db0996.js +1 -0
  319. package/.next-prod/static/chunks/app/api/files/delete/route-8ae56b9359db0996.js +1 -0
  320. package/.next-prod/static/chunks/app/api/files/expanded/route-8ae56b9359db0996.js +1 -0
  321. package/.next-prod/static/chunks/app/api/files/index/route-8ae56b9359db0996.js +1 -0
  322. package/.next-prod/static/chunks/app/api/files/init/route-8ae56b9359db0996.js +1 -0
  323. package/.next-prod/static/chunks/app/api/files/paste/route-8ae56b9359db0996.js +1 -0
  324. package/.next-prod/static/chunks/app/api/files/read/route-8ae56b9359db0996.js +1 -0
  325. package/.next-prod/static/chunks/app/api/files/readdir/route-8ae56b9359db0996.js +1 -0
  326. package/.next-prod/static/chunks/app/api/files/recent/route-8ae56b9359db0996.js +1 -0
  327. package/.next-prod/static/chunks/app/api/files/save/route-8ae56b9359db0996.js +1 -0
  328. package/.next-prod/static/chunks/app/api/files/search/route-8ae56b9359db0996.js +1 -0
  329. package/.next-prod/static/chunks/app/api/files/stat/route-8ae56b9359db0996.js +1 -0
  330. package/.next-prod/static/chunks/app/api/files/text/route-8ae56b9359db0996.js +1 -0
  331. package/.next-prod/static/chunks/app/api/git/branch-diff/route-8ae56b9359db0996.js +1 -0
  332. package/.next-prod/static/chunks/app/api/git/branches/route-8ae56b9359db0996.js +1 -0
  333. package/.next-prod/static/chunks/app/api/git/commit-diff/route-8ae56b9359db0996.js +1 -0
  334. package/.next-prod/static/chunks/app/api/git/commits/route-8ae56b9359db0996.js +1 -0
  335. package/.next-prod/static/chunks/app/api/git/diff/route-8ae56b9359db0996.js +1 -0
  336. package/.next-prod/static/chunks/app/api/git/discard/route-8ae56b9359db0996.js +1 -0
  337. package/.next-prod/static/chunks/app/api/git/stage/route-8ae56b9359db0996.js +1 -0
  338. package/.next-prod/static/chunks/app/api/git/status/route-8ae56b9359db0996.js +1 -0
  339. package/.next-prod/static/chunks/app/api/git/unstage/route-8ae56b9359db0996.js +1 -0
  340. package/.next-prod/static/chunks/app/api/git/worktree/route-8ae56b9359db0996.js +1 -0
  341. package/.next-prod/static/chunks/app/api/global-state/route-8ae56b9359db0996.js +1 -0
  342. package/.next-prod/static/chunks/app/api/jupyter/load/route-8ae56b9359db0996.js +1 -0
  343. package/.next-prod/static/chunks/app/api/jupyter/save/route-8ae56b9359db0996.js +1 -0
  344. package/.next-prod/static/chunks/app/api/jupyter/shutdown/route-8ae56b9359db0996.js +1 -0
  345. package/.next-prod/static/chunks/app/api/lsp/definition/route-8ae56b9359db0996.js +1 -0
  346. package/.next-prod/static/chunks/app/api/lsp/hover/route-8ae56b9359db0996.js +1 -0
  347. package/.next-prod/static/chunks/app/api/lsp/references/route-8ae56b9359db0996.js +1 -0
  348. package/.next-prod/static/chunks/app/api/lsp/status/route-8ae56b9359db0996.js +1 -0
  349. package/.next-prod/static/chunks/app/api/lsp/warmup/route-8ae56b9359db0996.js +1 -0
  350. package/.next-prod/static/chunks/app/api/mysql/columns/route-8ae56b9359db0996.js +1 -0
  351. package/.next-prod/static/chunks/app/api/mysql/connect/route-8ae56b9359db0996.js +1 -0
  352. package/.next-prod/static/chunks/app/api/mysql/disconnect/route-8ae56b9359db0996.js +1 -0
  353. package/.next-prod/static/chunks/app/api/mysql/export/route-8ae56b9359db0996.js +1 -0
  354. package/.next-prod/static/chunks/app/api/mysql/query/route-8ae56b9359db0996.js +1 -0
  355. package/.next-prod/static/chunks/app/api/mysql/schemas/route-8ae56b9359db0996.js +1 -0
  356. package/.next-prod/static/chunks/app/api/neo4j/connect/route-8ae56b9359db0996.js +1 -0
  357. package/.next-prod/static/chunks/app/api/neo4j/disconnect/route-8ae56b9359db0996.js +1 -0
  358. package/.next-prod/static/chunks/app/api/neo4j/query/route-8ae56b9359db0996.js +1 -0
  359. package/.next-prod/static/chunks/app/api/neo4j/schema/route-8ae56b9359db0996.js +1 -0
  360. package/.next-prod/static/chunks/app/api/note/route-8ae56b9359db0996.js +1 -0
  361. package/.next-prod/static/chunks/app/api/ollama/models/route-8ae56b9359db0996.js +1 -0
  362. package/.next-prod/static/chunks/app/api/ollama/start/route-8ae56b9359db0996.js +1 -0
  363. package/.next-prod/static/chunks/app/api/open-cursor/route-8ae56b9359db0996.js +1 -0
  364. package/.next-prod/static/chunks/app/api/open-vscode/route-8ae56b9359db0996.js +1 -0
  365. package/.next-prod/static/chunks/app/api/pick-folder/route-8ae56b9359db0996.js +1 -0
  366. package/.next-prod/static/chunks/app/api/pinned-sessions/route-8ae56b9359db0996.js +1 -0
  367. package/.next-prod/static/chunks/app/api/project-settings/route-8ae56b9359db0996.js +1 -0
  368. package/.next-prod/static/chunks/app/api/project-state/route-8ae56b9359db0996.js +1 -0
  369. package/.next-prod/static/chunks/app/api/projectGraph/affected/route-8ae56b9359db0996.js +1 -0
  370. package/.next-prod/static/chunks/app/api/projectGraph/callees/route-8ae56b9359db0996.js +1 -0
  371. package/.next-prod/static/chunks/app/api/projectGraph/callers/route-8ae56b9359db0996.js +1 -0
  372. package/.next-prod/static/chunks/app/api/projectGraph/coedit/route-8ae56b9359db0996.js +1 -0
  373. package/.next-prod/static/chunks/app/api/projectGraph/context/route-8ae56b9359db0996.js +1 -0
  374. package/.next-prod/static/chunks/app/api/projectGraph/file/route-8ae56b9359db0996.js +1 -0
  375. package/.next-prod/static/chunks/app/api/projectGraph/file-functions/route-8ae56b9359db0996.js +1 -0
  376. package/.next-prod/static/chunks/app/api/projectGraph/impact/route-8ae56b9359db0996.js +1 -0
  377. package/.next-prod/static/chunks/app/api/projectGraph/related/route-8ae56b9359db0996.js +1 -0
  378. package/.next-prod/static/chunks/app/api/projectGraph/risk/route-8ae56b9359db0996.js +1 -0
  379. package/.next-prod/static/chunks/app/api/projectGraph/search/route-8ae56b9359db0996.js +1 -0
  380. package/.next-prod/static/chunks/app/api/projects/route-8ae56b9359db0996.js +1 -0
  381. package/.next-prod/static/chunks/app/api/redis/command/route-8ae56b9359db0996.js +1 -0
  382. package/.next-prod/static/chunks/app/api/redis/connect/route-8ae56b9359db0996.js +1 -0
  383. package/.next-prod/static/chunks/app/api/redis/delete/route-8ae56b9359db0996.js +1 -0
  384. package/.next-prod/static/chunks/app/api/redis/disconnect/route-8ae56b9359db0996.js +1 -0
  385. package/.next-prod/static/chunks/app/api/redis/get/route-8ae56b9359db0996.js +1 -0
  386. package/.next-prod/static/chunks/app/api/redis/keys/route-8ae56b9359db0996.js +1 -0
  387. package/.next-prod/static/chunks/app/api/redis/set/route-8ae56b9359db0996.js +1 -0
  388. package/.next-prod/static/chunks/app/api/review/[id]/comments/route-8ae56b9359db0996.js +1 -0
  389. package/.next-prod/static/chunks/app/api/review/[id]/replies/route-8ae56b9359db0996.js +1 -0
  390. package/.next-prod/static/chunks/app/api/review/[id]/route-8ae56b9359db0996.js +1 -0
  391. package/.next-prod/static/chunks/app/api/review/identify/route-8ae56b9359db0996.js +1 -0
  392. package/.next-prod/static/chunks/app/api/review/order/route-8ae56b9359db0996.js +1 -0
  393. package/.next-prod/static/chunks/app/api/review/route-8ae56b9359db0996.js +1 -0
  394. package/.next-prod/static/chunks/app/api/review/share-info/route-8ae56b9359db0996.js +1 -0
  395. package/.next-prod/static/chunks/app/api/review/users/route-8ae56b9359db0996.js +1 -0
  396. package/.next-prod/static/chunks/app/api/scheduled-tasks/route-8ae56b9359db0996.js +1 -0
  397. package/.next-prod/static/chunks/app/api/services/config/route-8ae56b9359db0996.js +1 -0
  398. package/.next-prod/static/chunks/app/api/services/scripts/route-8ae56b9359db0996.js +1 -0
  399. package/.next-prod/static/chunks/app/api/session/[sessionId]/fork/route-8ae56b9359db0996.js +1 -0
  400. package/.next-prod/static/chunks/app/api/session/[sessionId]/history/route-8ae56b9359db0996.js +1 -0
  401. package/.next-prod/static/chunks/app/api/session-by-path/route-8ae56b9359db0996.js +1 -0
  402. package/.next-prod/static/chunks/app/api/sessions/projects/[encodedPath]/route-8ae56b9359db0996.js +1 -0
  403. package/.next-prod/static/chunks/app/api/sessions/projects/route-8ae56b9359db0996.js +1 -0
  404. package/.next-prod/static/chunks/app/api/sessions/route-8ae56b9359db0996.js +1 -0
  405. package/.next-prod/static/chunks/app/api/settings/route-8ae56b9359db0996.js +1 -0
  406. package/.next-prod/static/chunks/app/api/skills/[id]/route-8ae56b9359db0996.js +1 -0
  407. package/.next-prod/static/chunks/app/api/skills/content/route-8ae56b9359db0996.js +1 -0
  408. package/.next-prod/static/chunks/app/api/skills/route-8ae56b9359db0996.js +1 -0
  409. package/.next-prod/static/chunks/app/api/terminal/aliases/route-8ae56b9359db0996.js +1 -0
  410. package/.next-prod/static/chunks/app/api/terminal/autocomplete/route-8ae56b9359db0996.js +1 -0
  411. package/.next-prod/static/chunks/app/api/terminal/bubble-order/route-8ae56b9359db0996.js +1 -0
  412. package/.next-prod/static/chunks/app/api/terminal/env/route-8ae56b9359db0996.js +1 -0
  413. package/.next-prod/static/chunks/app/api/terminal/history/route-8ae56b9359db0996.js +1 -0
  414. package/.next-prod/static/chunks/app/api/version/route-8ae56b9359db0996.js +1 -0
  415. package/.next-prod/static/chunks/app/manifest.webmanifest/route-8ae56b9359db0996.js +1 -0
  416. package/.next-prod/static/chunks/next/dist/client/components/builtin/app-error-8ae56b9359db0996.js +1 -0
  417. package/.next-prod/static/chunks/next/dist/client/components/builtin/forbidden-8ae56b9359db0996.js +1 -0
  418. package/.next-prod/static/chunks/next/dist/client/components/builtin/not-found-8ae56b9359db0996.js +1 -0
  419. package/.next-prod/static/chunks/next/dist/client/components/builtin/unauthorized-8ae56b9359db0996.js +1 -0
  420. package/.next-prod/static/css/{f016b445331fc5a2.css → cc6d733cdf607b30.css} +1 -1
  421. package/.next-prod/static/dtH6UmANw3cgn-jbRuVu4/_buildManifest.js +1 -0
  422. package/.next-prod/trace +13 -12
  423. package/.next-prod/trace-build +1 -1
  424. package/.next-prod/types/app/api/projectGraph/affected/route.ts +351 -0
  425. package/.next-prod/types/app/api/projectGraph/context/route.ts +351 -0
  426. package/.next-prod/types/app/api/projectGraph/related/route.ts +351 -0
  427. package/.next-prod/types/app/api/projectGraph/risk/route.ts +351 -0
  428. package/.next-prod/types/routes.d.ts +5 -1
  429. package/.next-prod/types/validator.ts +36 -0
  430. package/README.md +8 -8
  431. package/README.zh.md +8 -8
  432. package/bin/cock-browser.mjs +93 -3
  433. package/bin/cock-codegraph.mjs +907 -0
  434. package/bin/cock-terminal.mjs +476 -159
  435. package/bin/cock.mjs +9 -1
  436. package/bin/cockpit-dev.mjs +9 -0
  437. package/bin/setup-dev.mjs +92 -0
  438. package/dist/cache-GIQJA4HL.mjs +502 -0
  439. package/dist/chunk-7P6ASYW6.mjs +9 -0
  440. package/dist/{chunk-OWUW2O3D.mjs → chunk-CZWJPTRO.mjs} +4 -2
  441. package/dist/{chunk-FBR4KJI5.mjs → chunk-KRTISG5I.mjs} +213 -2
  442. package/dist/{chunk-TXBVUZVH.mjs → chunk-ZJ6CC3MH.mjs} +0 -7
  443. package/dist/httpApi.mjs +203 -17
  444. package/dist/scheduledTasks.mjs +3 -2
  445. package/dist/{server-E7G55DY7.mjs → server-OSOMFNXR.mjs} +27 -4
  446. package/dist/wsServer.mjs +8 -34
  447. package/package.json +5 -2
  448. package/.next-prod/static/-BWPF5YtAsgnego1UPtt9/_buildManifest.js +0 -1
  449. package/.next-prod/static/chunks/2171-5163d946ec03ce80.js +0 -1
  450. package/.next-prod/static/chunks/6345-4299a3385983e28c.js +0 -14
  451. package/.next-prod/static/chunks/app/_global-error/page-994734ef0d317687.js +0 -1
  452. package/.next-prod/static/chunks/app/api/agent/test/route-994734ef0d317687.js +0 -1
  453. package/.next-prod/static/chunks/app/api/bash/route-994734ef0d317687.js +0 -1
  454. package/.next-prod/static/chunks/app/api/chat/codex/route-994734ef0d317687.js +0 -1
  455. package/.next-prod/static/chunks/app/api/chat/deepseek/route-994734ef0d317687.js +0 -1
  456. package/.next-prod/static/chunks/app/api/chat/kimi/route-994734ef0d317687.js +0 -1
  457. package/.next-prod/static/chunks/app/api/chat/ollama/route-994734ef0d317687.js +0 -1
  458. package/.next-prod/static/chunks/app/api/chat/route-994734ef0d317687.js +0 -1
  459. package/.next-prod/static/chunks/app/api/claude-stats/route-994734ef0d317687.js +0 -1
  460. package/.next-prod/static/chunks/app/api/commands/route-994734ef0d317687.js +0 -1
  461. package/.next-prod/static/chunks/app/api/comments/route-994734ef0d317687.js +0 -1
  462. package/.next-prod/static/chunks/app/api/db/columns/route-994734ef0d317687.js +0 -1
  463. package/.next-prod/static/chunks/app/api/db/connect/route-994734ef0d317687.js +0 -1
  464. package/.next-prod/static/chunks/app/api/db/disconnect/route-994734ef0d317687.js +0 -1
  465. package/.next-prod/static/chunks/app/api/db/export/route-994734ef0d317687.js +0 -1
  466. package/.next-prod/static/chunks/app/api/db/query/route-994734ef0d317687.js +0 -1
  467. package/.next-prod/static/chunks/app/api/db/schemas/route-994734ef0d317687.js +0 -1
  468. package/.next-prod/static/chunks/app/api/dev/spans/route-994734ef0d317687.js +0 -1
  469. package/.next-prod/static/chunks/app/api/extension/version/route-994734ef0d317687.js +0 -1
  470. package/.next-prod/static/chunks/app/api/file/route-994734ef0d317687.js +0 -1
  471. package/.next-prod/static/chunks/app/api/files/blame/route-994734ef0d317687.js +0 -1
  472. package/.next-prod/static/chunks/app/api/files/clipboard/route-994734ef0d317687.js +0 -1
  473. package/.next-prod/static/chunks/app/api/files/copy/route-994734ef0d317687.js +0 -1
  474. package/.next-prod/static/chunks/app/api/files/delete/route-994734ef0d317687.js +0 -1
  475. package/.next-prod/static/chunks/app/api/files/expanded/route-994734ef0d317687.js +0 -1
  476. package/.next-prod/static/chunks/app/api/files/index/route-994734ef0d317687.js +0 -1
  477. package/.next-prod/static/chunks/app/api/files/init/route-994734ef0d317687.js +0 -1
  478. package/.next-prod/static/chunks/app/api/files/paste/route-994734ef0d317687.js +0 -1
  479. package/.next-prod/static/chunks/app/api/files/read/route-994734ef0d317687.js +0 -1
  480. package/.next-prod/static/chunks/app/api/files/readdir/route-994734ef0d317687.js +0 -1
  481. package/.next-prod/static/chunks/app/api/files/recent/route-994734ef0d317687.js +0 -1
  482. package/.next-prod/static/chunks/app/api/files/save/route-994734ef0d317687.js +0 -1
  483. package/.next-prod/static/chunks/app/api/files/search/route-994734ef0d317687.js +0 -1
  484. package/.next-prod/static/chunks/app/api/files/stat/route-994734ef0d317687.js +0 -1
  485. package/.next-prod/static/chunks/app/api/files/text/route-994734ef0d317687.js +0 -1
  486. package/.next-prod/static/chunks/app/api/git/branch-diff/route-994734ef0d317687.js +0 -1
  487. package/.next-prod/static/chunks/app/api/git/branches/route-994734ef0d317687.js +0 -1
  488. package/.next-prod/static/chunks/app/api/git/commit-diff/route-994734ef0d317687.js +0 -1
  489. package/.next-prod/static/chunks/app/api/git/commits/route-994734ef0d317687.js +0 -1
  490. package/.next-prod/static/chunks/app/api/git/diff/route-994734ef0d317687.js +0 -1
  491. package/.next-prod/static/chunks/app/api/git/discard/route-994734ef0d317687.js +0 -1
  492. package/.next-prod/static/chunks/app/api/git/stage/route-994734ef0d317687.js +0 -1
  493. package/.next-prod/static/chunks/app/api/git/status/route-994734ef0d317687.js +0 -1
  494. package/.next-prod/static/chunks/app/api/git/unstage/route-994734ef0d317687.js +0 -1
  495. package/.next-prod/static/chunks/app/api/git/worktree/route-994734ef0d317687.js +0 -1
  496. package/.next-prod/static/chunks/app/api/global-state/route-994734ef0d317687.js +0 -1
  497. package/.next-prod/static/chunks/app/api/jupyter/load/route-994734ef0d317687.js +0 -1
  498. package/.next-prod/static/chunks/app/api/jupyter/save/route-994734ef0d317687.js +0 -1
  499. package/.next-prod/static/chunks/app/api/jupyter/shutdown/route-994734ef0d317687.js +0 -1
  500. package/.next-prod/static/chunks/app/api/lsp/definition/route-994734ef0d317687.js +0 -1
  501. package/.next-prod/static/chunks/app/api/lsp/hover/route-994734ef0d317687.js +0 -1
  502. package/.next-prod/static/chunks/app/api/lsp/references/route-994734ef0d317687.js +0 -1
  503. package/.next-prod/static/chunks/app/api/lsp/status/route-994734ef0d317687.js +0 -1
  504. package/.next-prod/static/chunks/app/api/lsp/warmup/route-994734ef0d317687.js +0 -1
  505. package/.next-prod/static/chunks/app/api/mysql/columns/route-994734ef0d317687.js +0 -1
  506. package/.next-prod/static/chunks/app/api/mysql/connect/route-994734ef0d317687.js +0 -1
  507. package/.next-prod/static/chunks/app/api/mysql/disconnect/route-994734ef0d317687.js +0 -1
  508. package/.next-prod/static/chunks/app/api/mysql/export/route-994734ef0d317687.js +0 -1
  509. package/.next-prod/static/chunks/app/api/mysql/query/route-994734ef0d317687.js +0 -1
  510. package/.next-prod/static/chunks/app/api/mysql/schemas/route-994734ef0d317687.js +0 -1
  511. package/.next-prod/static/chunks/app/api/neo4j/connect/route-994734ef0d317687.js +0 -1
  512. package/.next-prod/static/chunks/app/api/neo4j/disconnect/route-994734ef0d317687.js +0 -1
  513. package/.next-prod/static/chunks/app/api/neo4j/query/route-994734ef0d317687.js +0 -1
  514. package/.next-prod/static/chunks/app/api/neo4j/schema/route-994734ef0d317687.js +0 -1
  515. package/.next-prod/static/chunks/app/api/note/route-994734ef0d317687.js +0 -1
  516. package/.next-prod/static/chunks/app/api/ollama/models/route-994734ef0d317687.js +0 -1
  517. package/.next-prod/static/chunks/app/api/ollama/start/route-994734ef0d317687.js +0 -1
  518. package/.next-prod/static/chunks/app/api/open-cursor/route-994734ef0d317687.js +0 -1
  519. package/.next-prod/static/chunks/app/api/open-vscode/route-994734ef0d317687.js +0 -1
  520. package/.next-prod/static/chunks/app/api/pick-folder/route-994734ef0d317687.js +0 -1
  521. package/.next-prod/static/chunks/app/api/pinned-sessions/route-994734ef0d317687.js +0 -1
  522. package/.next-prod/static/chunks/app/api/project-settings/route-994734ef0d317687.js +0 -1
  523. package/.next-prod/static/chunks/app/api/project-state/route-994734ef0d317687.js +0 -1
  524. package/.next-prod/static/chunks/app/api/projectGraph/callees/route-994734ef0d317687.js +0 -1
  525. package/.next-prod/static/chunks/app/api/projectGraph/callers/route-994734ef0d317687.js +0 -1
  526. package/.next-prod/static/chunks/app/api/projectGraph/coedit/route-994734ef0d317687.js +0 -1
  527. package/.next-prod/static/chunks/app/api/projectGraph/file/route-994734ef0d317687.js +0 -1
  528. package/.next-prod/static/chunks/app/api/projectGraph/file-functions/route-994734ef0d317687.js +0 -1
  529. package/.next-prod/static/chunks/app/api/projectGraph/impact/route-994734ef0d317687.js +0 -1
  530. package/.next-prod/static/chunks/app/api/projectGraph/search/route-994734ef0d317687.js +0 -1
  531. package/.next-prod/static/chunks/app/api/projects/route-994734ef0d317687.js +0 -1
  532. package/.next-prod/static/chunks/app/api/redis/command/route-994734ef0d317687.js +0 -1
  533. package/.next-prod/static/chunks/app/api/redis/connect/route-994734ef0d317687.js +0 -1
  534. package/.next-prod/static/chunks/app/api/redis/delete/route-994734ef0d317687.js +0 -1
  535. package/.next-prod/static/chunks/app/api/redis/disconnect/route-994734ef0d317687.js +0 -1
  536. package/.next-prod/static/chunks/app/api/redis/get/route-994734ef0d317687.js +0 -1
  537. package/.next-prod/static/chunks/app/api/redis/keys/route-994734ef0d317687.js +0 -1
  538. package/.next-prod/static/chunks/app/api/redis/set/route-994734ef0d317687.js +0 -1
  539. package/.next-prod/static/chunks/app/api/review/[id]/comments/route-994734ef0d317687.js +0 -1
  540. package/.next-prod/static/chunks/app/api/review/[id]/replies/route-994734ef0d317687.js +0 -1
  541. package/.next-prod/static/chunks/app/api/review/[id]/route-994734ef0d317687.js +0 -1
  542. package/.next-prod/static/chunks/app/api/review/identify/route-994734ef0d317687.js +0 -1
  543. package/.next-prod/static/chunks/app/api/review/order/route-994734ef0d317687.js +0 -1
  544. package/.next-prod/static/chunks/app/api/review/route-994734ef0d317687.js +0 -1
  545. package/.next-prod/static/chunks/app/api/review/share-info/route-994734ef0d317687.js +0 -1
  546. package/.next-prod/static/chunks/app/api/review/users/route-994734ef0d317687.js +0 -1
  547. package/.next-prod/static/chunks/app/api/scheduled-tasks/route-994734ef0d317687.js +0 -1
  548. package/.next-prod/static/chunks/app/api/services/config/route-994734ef0d317687.js +0 -1
  549. package/.next-prod/static/chunks/app/api/services/scripts/route-994734ef0d317687.js +0 -1
  550. package/.next-prod/static/chunks/app/api/session/[sessionId]/fork/route-994734ef0d317687.js +0 -1
  551. package/.next-prod/static/chunks/app/api/session/[sessionId]/history/route-994734ef0d317687.js +0 -1
  552. package/.next-prod/static/chunks/app/api/session-by-path/route-994734ef0d317687.js +0 -1
  553. package/.next-prod/static/chunks/app/api/sessions/projects/[encodedPath]/route-994734ef0d317687.js +0 -1
  554. package/.next-prod/static/chunks/app/api/sessions/projects/route-994734ef0d317687.js +0 -1
  555. package/.next-prod/static/chunks/app/api/sessions/route-994734ef0d317687.js +0 -1
  556. package/.next-prod/static/chunks/app/api/settings/route-994734ef0d317687.js +0 -1
  557. package/.next-prod/static/chunks/app/api/skills/[id]/route-994734ef0d317687.js +0 -1
  558. package/.next-prod/static/chunks/app/api/skills/content/route-994734ef0d317687.js +0 -1
  559. package/.next-prod/static/chunks/app/api/skills/route-994734ef0d317687.js +0 -1
  560. package/.next-prod/static/chunks/app/api/terminal/aliases/route-994734ef0d317687.js +0 -1
  561. package/.next-prod/static/chunks/app/api/terminal/autocomplete/route-994734ef0d317687.js +0 -1
  562. package/.next-prod/static/chunks/app/api/terminal/bubble-order/route-994734ef0d317687.js +0 -1
  563. package/.next-prod/static/chunks/app/api/terminal/env/route-994734ef0d317687.js +0 -1
  564. package/.next-prod/static/chunks/app/api/terminal/history/route-994734ef0d317687.js +0 -1
  565. package/.next-prod/static/chunks/app/api/version/route-994734ef0d317687.js +0 -1
  566. package/.next-prod/static/chunks/app/manifest.webmanifest/route-994734ef0d317687.js +0 -1
  567. package/.next-prod/static/chunks/next/dist/client/components/builtin/app-error-994734ef0d317687.js +0 -1
  568. package/.next-prod/static/chunks/next/dist/client/components/builtin/forbidden-994734ef0d317687.js +0 -1
  569. package/.next-prod/static/chunks/next/dist/client/components/builtin/not-found-994734ef0d317687.js +0 -1
  570. package/.next-prod/static/chunks/next/dist/client/components/builtin/unauthorized-994734ef0d317687.js +0 -1
  571. package/bin/cock-dev.mjs +0 -6
  572. /package/.next-prod/static/{-BWPF5YtAsgnego1UPtt9 → dtH6UmANw3cgn-jbRuVu4}/_ssgManifest.js +0 -0
@@ -1,4 +1,4 @@
1
- "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5188],{1058:(e,t,r)=>{r.d(t,{_:()=>a});var n=r(12115),s=r(90717),o=r(86957),l=r(46456);function a({cwd:e,filePath:t}){let[r,i]=(0,n.useState)([]),[c,d]=(0,n.useState)(!1),[u,m]=(0,n.useState)(null),x=(0,n.useCallback)(async()=>{if(!e||!t)return;d(!0),m(null);let r=await o.t4.runPromiseExit((0,l.lb)(e,t));if("Success"===r._tag)i(r.value.comments??[]);else{let e="Fail"===r.cause._tag?r.cause.error:null,t=e?.cause;m(t instanceof Error?t.message:"Failed to load comments")}d(!1)},[e,t]);(0,n.useEffect)(()=>{x()},[x]),(0,n.useEffect)(()=>(0,s.zL)(()=>{x()}),[x]);let h=(0,n.useCallback)(async(r,n,s,a)=>{let c=await o.t4.runPromiseExit((0,l.BC)({cwd:e,filePath:t,startLine:r,endLine:n,content:s,...a?{selectedText:a}:{}}));if("Success"===c._tag&&c.value.comment){let e=c.value.comment;return i(t=>[...t,e]),e}return"Failure"===c._tag&&console.error("Failed to add comment:",c.cause),null},[e,t]),f=(0,n.useCallback)(async(t,r)=>{let n=await o.t4.runPromiseExit((0,l.vv)(e,t,r));if("Success"===n._tag&&n.value.comment){let e=n.value.comment;return i(r=>r.map(r=>r.id===t?e:r)),!0}return"Failure"===n._tag&&console.error("Failed to update comment:",n.cause),!1},[e]),p=(0,n.useCallback)(async t=>{let r=await o.t4.runPromiseExit((0,l.Tu)(e,t));return"Success"===r._tag?(i(e=>e.filter(e=>e.id!==t)),!0):(console.error("Failed to delete comment:",r.cause),!1)},[e]),g=(0,n.useCallback)(e=>r.filter(t=>e>=t.startLine&&e<=t.endLine),[r]);return{comments:r,isLoading:c,error:u,addComment:h,updateComment:f,deleteComment:p,refresh:x,getCommentsForLine:g}}},2228:(e,t,r)=>{r.d(t,{ProjectItem:()=>a});var n=r(95155),s=r(12115),o=r(79114);function l({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-6 h-6 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"4"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function a({index:e,name:t,cwd:r,isActive:i,collapsed:c,hasUnread:d,isLoading:u,onClick:m,onRemove:x,onOpenNote:h}){let{t:f}=(0,o.Bd)(),[p,g]=(0,s.useState)(!1);return(0,n.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1 rounded-lg cursor-pointer transition-colors relative ${c?"justify-center":""} ${i?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary hover:text-foreground"}`,onClick:m,onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),title:r,children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(l,{number:e+1,isActive:i}),d&&!i&&!u&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),u&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"})]}),!c&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"flex-1 truncate text-sm",children:t}),!u&&i?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}):null]}),p&&!c&&(0,n.jsxs)("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-0.5",children:[h&&(0,n.jsx)("button",{className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",onClick:e=>{e.stopPropagation(),h()},title:f("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-500 transition-colors",onClick:e=>{e.stopPropagation(),x()},title:f("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"})})})]})]})}},3292:(e,t,r)=>{r.d(t,{P:()=>c});var n=r(12115),s=r(95045),o=r(75346),l=r(49433),a=r(86957),i=r(82680);function c(){let[e,t]=(0,n.useState)([]),r=(0,n.useCallback)(()=>{let e=l.tryPromise({try:async()=>{let e=await fetch("/api/pinned-sessions");return await e.json()},catch:e=>new i.uV({message:"loadPinnedSessions failed",cause:e})});a.t4.runPromise(e.pipe(l.match({onSuccess:e=>t(e.sessions||[]),onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{r()},[r]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type==="PINNED_SESSIONS_CHANGED"&&r()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[r]);let c=(0,n.useCallback)(e=>{t(e);let r=l.tryPromise({try:async()=>{await fetch("/api/pinned-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessions:e})})},catch:e=>new i.uV({message:"savePinnedSessions failed",cause:e})});a.t4.runFork(r.pipe(l.orElse(()=>l.void))),(0,s.F)(o.n.PinnedSessionsChanged,{})},[]),d=(0,n.useCallback)(t=>e.some(e=>e.sessionId===t),[e]),u=(0,n.useCallback)((t,r,n)=>{e.some(e=>e.sessionId===t)||c([...e,{sessionId:t,cwd:r,customTitle:n}])},[e,c]),m=(0,n.useCallback)(t=>{c(e.filter(e=>e.sessionId!==t))},[e,c]),x=(0,n.useCallback)((t,r)=>{c(e.map(e=>e.sessionId===t?{...e,customTitle:r}:e))},[e,c]);return{pinnedSessions:e,isPinned:d,pinSession:u,unpinSession:m,updateTitle:x,reorder:(0,n.useCallback)(e=>{c(e)},[c]),reload:r}}},7320:(e,t,r)=>{r.d(t,{G:()=>a,t:()=>l});var n=r(95155),s=r(12115),o=r(79114);function l({x:e,y:t,range:r,lineSnapshot:a,container:i,onSubmit:c,onClose:d}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)(""),[h,f]=(0,s.useState)(!1),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0}),j=a?.split("\n").slice(0,5).join("\n"),w=!!a&&a.split("\n").length>5;return(0,s.useEffect)(()=>{if(p.current&&i){let r=i.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>v({x:s,y:o}))}},[e,t,i]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{h||!p.current||p.current.contains(e.target)||d()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d,h]),(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,n.jsx)("div",{className:"px-3 py-2 bg-amber-9/10 border-b border-border",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-amber-11",children:u("comments.addComment")}),(r.start>0||r.end>0)&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("comments.lineRange",{start:r.start,end:r.end})})]})}),a&&(0,n.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,n.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[j,w&&(0,n.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("textarea",{ref:g,value:m,onChange:e=>x(e.target.value),placeholder:u("comments.inputPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:h,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!h&&m.trim()&&(f(!0),c(m.trim()))),"Escape"!==e.key||h||d()}}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:u(h?"comments.submitting":"comments.enterSubmit")})]})]})}function a({x:e,y:t,range:r,filePath:l,lineSnapshot:i,container:c,onSubmit:d,onClose:u,isChatLoading:m}){let{t:x}=(0,o.Bd)(),[h,f]=(0,s.useState)(""),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&c){let r=c.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>v({x:s,y:o}))}},[e,t,c]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&u()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[u]);let j=i?.split("\n").slice(0,5).join("\n"),w=!!i&&i.split("\n").length>5;return(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,n.jsxs)("div",{className:"px-3 py-2 bg-brand/10 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-brand",children:x("comments.askAI")}),(r.start>0||r.end>0)&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:x("comments.lineRange",{start:r.start,end:r.end})})]}),l&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:l})]}),i&&(0,n.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,n.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[j,w&&(0,n.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("textarea",{ref:g,value:h,onChange:e=>f(e.target.value),placeholder:x("comments.inputQuestion"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:m,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!m&&h.trim()&&(d(h.trim()),u())),"Escape"===e.key&&u()}}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:x(m?"comments.aiGenerating":"comments.enterSend")})]})]})}},8648:(e,t,r)=>{r.d(t,{NoteModal:()=>C});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(13439),i=r(37795),c=r(43561),d=r(5989),u=r(76065),m=r(43203),x=r(6268),h=r(48434),f=r(44695),p=r(59265),g=r(26932);function b(e){return e.storage.markdown.getMarkdown()}function v(){return[{label:l.A.t("slashCommands.heading1"),icon:"H1",description:l.A.t("slashCommands.heading1Desc"),action:e=>e.chain().focus().toggleHeading({level:1}).run()},{label:l.A.t("slashCommands.heading2"),icon:"H2",description:l.A.t("slashCommands.heading2Desc"),action:e=>e.chain().focus().toggleHeading({level:2}).run()},{label:l.A.t("slashCommands.heading3"),icon:"H3",description:l.A.t("slashCommands.heading3Desc"),action:e=>e.chain().focus().toggleHeading({level:3}).run()},{label:l.A.t("slashCommands.bulletList"),icon:"•",description:l.A.t("slashCommands.bulletListDesc"),action:e=>e.chain().focus().toggleBulletList().run()},{label:l.A.t("slashCommands.orderedList"),icon:"1.",description:l.A.t("slashCommands.orderedListDesc"),action:e=>e.chain().focus().toggleOrderedList().run()},{label:l.A.t("slashCommands.taskList"),icon:"☑",description:l.A.t("slashCommands.taskListDesc"),action:e=>e.chain().focus().toggleTaskList().run()},{label:l.A.t("slashCommands.blockquote"),icon:"❝",description:l.A.t("slashCommands.blockquoteDesc"),action:e=>e.chain().focus().toggleBlockquote().run()},{label:l.A.t("slashCommands.codeBlock"),icon:"<>",description:l.A.t("slashCommands.codeBlockDesc"),action:e=>e.chain().focus().toggleCodeBlock().run()},{label:l.A.t("slashCommands.table"),icon:"▦",description:l.A.t("slashCommands.tableDesc"),action:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{label:l.A.t("slashCommands.horizontalRule"),icon:"──",description:l.A.t("slashCommands.horizontalRuleDesc"),action:e=>e.chain().focus().setHorizontalRule().run()},{label:l.A.t("slashCommands.link"),icon:"\uD83D\uDD17",description:l.A.t("slashCommands.linkDesc"),action:e=>{window.dispatchEvent(new CustomEvent("tiptap-insert-link"))}}]}function j({editor:e,query:t,position:r,onClose:o}){let[l,a]=(0,s.useState)(0),i=(0,s.useRef)(null),c=v().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>a(0))},[t]);let d=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(),a(e=>(e+1)%c.length)):"ArrowUp"===e.key?(e.preventDefault(),a(e=>(e-1+c.length)%c.length)):"Enter"===e.key?(e.preventDefault(),c[l]&&d(c[l])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[c,l,o]),0===c.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lg py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:c.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===l?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"}`,onClick:()=>d(e),onMouseEnter:()=>a(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))})}v();var w=r(76043),y=r(86957),k=r(49433),N=r(76900);function C({isOpen:e,onClose:t,projectCwd:r,projectName:v}){let{t:S}=(0,o.Bd)(),[L,E]=(0,s.useState)(!0),[M,T]=(0,s.useState)(!1),$=(0,s.useRef)(null),P=(0,s.useRef)(!1),[R,B]=(0,s.useState)(null),F=(0,s.useRef)(null),I=(0,s.useCallback)(async e=>{T(!0),"Success"===(await y.t4.runPromiseExit((0,N.Cq)(r,e).pipe(k.tapError(e=>k.sync(()=>console.error("Failed to save note:",e))))))._tag&&(P.current=!1),T(!1)},[r]),D=(0,s.useCallback)(e=>{P.current=!0,$.current&&clearTimeout($.current),$.current=setTimeout(()=>{I(e)},5e3)},[I]),A=(0,a.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:{levels:[1,2,3]}}),c.A.configure({placeholder:()=>l.A.t("editor.placeholder")}),d.XI.configure({resizable:!0}),u.H,m.n,x.A,h._,p.Ay.configure({autolink:!0,linkOnPaste:!0,openOnClick:!1,HTMLAttributes:{class:"tiptap-link",target:"_blank",rel:"noopener noreferrer"}}),f.L.configure({nested:!0}),g.o.configure({html:!0,transformCopiedText:!0,transformPastedText:!0})],editorProps:{attributes:{class:"tiptap-editor focus:outline-none min-h-[60vh] px-6 py-4"},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&&_.current){let e=_.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||R||setTimeout(()=>{if(!_.current)return;let{from:e}=_.current.state.selection;if("/"===_.current.state.doc.textBetween(Math.max(0,e-1),e,"\n")){F.current=e;let t=_.current.view.coordsAtPos(e);B({query:"",position:{top:t.bottom+4,left:t.left}})}},0),!1}},onUpdate:({editor:e})=>{if(D(b(e)),null!==F.current){let{from:t}=e.state.selection;if(t<F.current)B(null),F.current=null;else{let r=e.state.doc.textBetween(F.current,t,"\n");r.includes(" ")||r.includes("\n")?(B(null),F.current=null):B(e=>e?{...e,query:r}:null)}}}}),_=(0,s.useRef)(A);(0,s.useEffect)(()=>{_.current=A},[A]),(0,s.useEffect)(()=>{e&&A&&(E(!0),B(null),F.current=null,y.t4.runPromiseExit((0,N.zF)(r)).then(e=>{"Success"===e._tag?(A.commands.setContent(e.value.content||""),P.current=!1):console.error("Failed to load note:",e.cause),E(!1)}))},[e,A,r]);let W=(0,s.useCallback)(()=>{$.current&&(clearTimeout($.current),$.current=null),P.current&&A&&I(b(A)),B(null),F.current=null,t()},[A,I,t]);return((0,s.useEffect)(()=>()=>{$.current&&clearTimeout($.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(R?(B(null),F.current=null):W())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,W,R]),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-black/50",onClick:W}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] mx-4 flex flex-col overflow-hidden",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",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:v?S("editor.noteTitle",{name:v}):S("editor.noteUntitled")}),M&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:S("editor.saving")})]}),(0,n.jsx)("button",{onClick:W,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent 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)(w.NoteToolbar,{editor:A}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:L?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:(0,n.jsx)("span",{children:S("common.loading")})}):(0,n.jsx)(a.$Z,{editor:A})})]}),R&&A&&(0,n.jsx)(j,{editor:A,query:R.query,position:R.position,onClose:()=>{B(null),F.current=null}})]}):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},17196:(e,t,r)=>{r.d(t,{Np:()=>d,ZD:()=>i,b8:()=>c,kS:()=>l,sQ:()=>a});var n=r(67014);let s=null,o=["typescript","tsx","javascript","jsx","html","css","scss","json","yaml","python","go","rust","java","ruby","php","bash","shell","markdown","sql","c","cpp","swift","kotlin","dart","lua","graphql","xml"];function l(){return s||(s=(0,n.O_)({themes:["github-dark","github-light"],langs:[...o]})),s}function a(e){let t=e.split("/").pop()?.toLowerCase()||"",r=t.split(".").pop()?.toLowerCase();if(".env"===t||t.startsWith(".env.")||"dockerfile"===t||t.startsWith("dockerfile.")||"makefile"===t)return"bash";let n={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",html:"html",htm:"html",css:"css",scss:"scss",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",py:"python",go:"go",rs:"rust",java:"java",kt:"kotlin",rb:"ruby",php:"php",cs:"cpp",cpp:"cpp",c:"c",h:"c",sh:"bash",bash:"bash",zsh:"bash",md:"markdown",mdx:"markdown",sql:"sql",swift:"swift",dart:"dart",lua:"lua",graphql:"graphql",gql:"graphql",toml:"yaml",sass:"scss",less:"css",scala:"java",r:"python",vim:"bash",env:"bash"}[r||""]||"text";return o.includes(n)?n:"text"}function i(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function c(e){return e.map(e=>e.color?`<span style="color:${e.color}">${i(e.content)}</span>`:i(e.content)).join("")}function d(e,t,r,n){if(!t)return[];let s=[],o=r?t:t.toLowerCase();for(let t=0;t<e.length;t++){let l=r?e[t]:e[t].toLowerCase(),a=0;for(;;){let e=l.indexOf(o,a);if(-1===e)break;let r=e+o.length;if(n){let n=e>0?l[e-1]:" ",o=r<l.length?l[r]:" ",a=!/\w/.test(n),i=!/\w/.test(o);a&&i&&s.push({lineIndex:t,startCol:e,endCol:r})}else s.push({lineIndex:t,startCol:e,endCol:r});a=e+1}}return s}},21484:(e,t,r)=>{r.d(t,{SettingsModal:()=>x});var n=r(95155),s=r(12115),o=r(79114),l=r(3238),a=r(34075),i=r(12786),c=r(53853),d=r(86957),u=r(49433),m=r(76900);function x({isOpen:e,onClose:t}){let{t:r,i18n:h}=(0,o.Bd)(),{theme:f,setTheme:p}=(0,l.D)(),g=(0,c.G)(),[b,v]=(0,s.useState)(""),[j,w]=(0,s.useState)(""),[y,k]=(0,s.useState)("auto");(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.M5)()).then(e=>{"Success"===e._tag&&e.value.language&&k(e.value.language)})},[e]);let N=(0,s.useCallback)(e=>{k(e),d.t4.runFork((0,m.DZ)({language:e}).pipe(u.orElse(()=>u.void)));let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;h.changeLanguage(t)},[h]),C=g?"installed":"not-installed",S=g?.version??null;if((0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.Wr)()).then(e=>{"Success"===e._tag&&e.value.version&&w(e.value.version)})},[e]),(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.Or)()).then(e=>{"Success"===e._tag&&e.value.path&&v(e.value.path)})},[e]),!e)return null;let L=[{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-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-md 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-accent 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:L.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 ${f===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:()=>N(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${y===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.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"===C?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===C&&`${r("settings.extensionInstalled")}${S?` (v${S})`:""}`,"not-installed"===C&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==C&&(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=b||"chrome-extension";navigator.clipboard.writeText(e),(0,a.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"===C&&(0,n.jsx)("button",{onClick:()=>{g?.id&&window.chrome?.runtime?.sendMessage&&(window.chrome.runtime.sendMessage(g.id,{type:"reload"}),(0,a.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")})]}),b&&(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground font-mono truncate",children:b})]})]}),(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",j?` v${j}`:""]}),(0,n.jsx)("p",{className:"text-muted-foreground/60",children:"One seat. One AI. Everything under control."})]})]})]})]})]})}},23121:(e,t,r)=>{r.d(t,{n:()=>m});var n=r(12115),s=r(95045),o=r(75346),l=r(49433),a=r(86957),i=r(82680);let c=(e,t,r)=>l.tryPromise({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 i.uV({message:`${t} ${e} failed`,cause:r})}),d="SCHEDULED_TASKS_CHANGED";function u(){(0,s.F)(o.n.ScheduledTasksChanged,{}),document.querySelectorAll("iframe").forEach(e=>{try{e.contentWindow?.postMessage({type:d},"*")}catch{}})}function m(){let[e,t]=(0,n.useState)([]),[r,s]=(0,n.useState)(0),o=(0,n.useCallback)(()=>{let e;a.t4.runPromise((e="/api/scheduled-tasks",l.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new i.uV({message:`fetch ${e} failed`,cause:t})})).pipe(l.match({onSuccess:e=>{t(e.tasks??[]),s(e.unreadCount??0)},onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{o()},[o]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type===d&&o()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[o]);let m=(0,n.useCallback)(async e=>{let t=await a.t4.runPromiseExit(c("/api/scheduled-tasks","POST",e));if("Success"!==t._tag)return null;let r=t.value;return r.task?(o(),u(),r.task):null},[o]),x=(0,n.useCallback)(async(e,t,r)=>{await a.t4.runPromise(c("/api/scheduled-tasks","PATCH",{id:e,action:t,fields:r}).pipe(l.asVoid).pipe(l.orElse(()=>l.void))),o(),u()},[o]),h=(0,n.useCallback)(e=>x(e,"pause"),[x]),f=(0,n.useCallback)(e=>x(e,"resume"),[x]),p=(0,n.useCallback)(async e=>{await a.t4.runPromise(c("/api/scheduled-tasks","DELETE",{id:e}).pipe(l.asVoid).pipe(l.orElse(()=>l.void))),o(),u()},[o]),g=(0,n.useCallback)((e,t)=>x(e,"update",t),[x]),b=(0,n.useCallback)(e=>x(e,"trigger"),[x]),v=(0,n.useCallback)(e=>x(e,"markRead"),[x]);return{tasks:e,unreadCount:r,reload:o,createTask:m,pauseTask:h,resumeTask:f,triggerTask:b,deleteTask:p,updateTask:g,markRead:v,markAllRead:(0,n.useCallback)(()=>x("_","markAllRead"),[x]),reorderTasks:(0,n.useCallback)(e=>x("_","reorder",{orderedIds:e}),[x])}}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>d});var n=r(95155),s=r(12115),o=r(94287),l=r(64428),a=r(79114);function i({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-5 h-5 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function c({onNewTab:e,onNewClaude2Tab:t,onNewCodexTab:r,onNewKimiTab:o,onNewOllamaTab:a,onNewDeepseekTab:i}){let[d,u]=(0,s.useState)(!1),m=(0,s.useRef)(null),x=(0,s.useRef)(null),[h,f]=(0,s.useState)({top:0,right:0}),p=(0,l.F2)();(0,s.useEffect)(()=>{if(!d)return;let e=e=>{x.current&&!x.current.contains(e.target)&&m.current&&!m.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let g=n=>{u(!1),"claude2"===n?t?.():"codex"===n?r?.():"kimi"===n?o?.():"ollama"===n?a?.():"deepseek"===n?i?.():e()};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:m,onClick:()=>{if(!d&&m.current){let e=m.current.getBoundingClientRect(),t=p?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0,s=t?.width??window.innerWidth;f({top:e.bottom+4-n,right:s-(e.right-r)})}u(e=>!e)},className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"New tab",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"})})}),d&&(0,n.jsx)(l.ZL,{children:(0,n.jsxs)("div",{ref:x,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[140px]",style:{top:h.top,right:h.right},children:[(0,n.jsxs)("button",{onClick:()=>g("claude"),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)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}),"Claude Code"]}),(0,n.jsxs)("button",{onClick:()=>g("claude2"),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)("span",{className:"w-2 h-2 rounded-full bg-orange-500 flex-shrink-0"}),"Claude 2"]}),(0,n.jsxs)("button",{onClick:()=>g("codex"),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)("span",{className:"w-2 h-2 rounded-full bg-emerald-500 flex-shrink-0"}),"OpenAI Codex"]}),(0,n.jsxs)("button",{onClick:()=>g("deepseek"),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)("span",{className:"w-2 h-2 rounded-full bg-sky-500 flex-shrink-0"}),"DeepSeek"]}),(0,n.jsxs)("button",{onClick:()=>g("kimi"),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)("span",{className:"w-2 h-2 rounded-full bg-blue-500 flex-shrink-0"}),"Kimi"]}),(0,n.jsxs)("button",{onClick:()=>g("ollama"),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)("span",{className:"w-2 h-2 rounded-full bg-violet-500 flex-shrink-0"}),"Ollama"]})]})})]})}function d({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:l,isPinned:u,onTogglePin:m,onSwitchTab:x,onCloseTab:h,onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j,onDragStart:w,onDragOver:y,onDrop:k,onDragEnd:N}){let{t:C}=(0,a.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((a,c)=>(0,n.jsx)(o.m,{content:a.title,delay:200,className:"flex-1 min-w-16 max-w-32",children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>w(c),onDragOver:e=>y(e,c),onDrop:()=>k(c),onDragEnd:N,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg transition-colors ${a.id===t?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary"} ${s===c?"opacity-50":""} ${l===c?"border-l-2 border-brand":""}`,onClick:()=>x(a.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(i,{number:c+1,isActive:a.id===t}),a.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!a.isLoading&&r.has(a.id)&&a.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),m&&u?.(a.id)&&!a.isLoading&&!(r.has(a.id)&&a.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m(a.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-amber-500 hover:text-destructive transition-colors",title:C("tabBar.unpin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})}),m&&!u?.(a.id)&&!a.isLoading&&!(r.has(a.id)&&a.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m(a.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-muted-foreground opacity-0 group-hover:opacity-60 hover:!opacity-100 hover:!text-brand transition-all",title:C("tabBar.pin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})})]}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:a.title}),"claude2"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-orange-500/15 text-orange-400 font-medium leading-relaxed",children:"C2"}),"codex"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-emerald-500/15 text-emerald-400 font-medium leading-relaxed",children:"CX"}),"kimi"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-blue-500/15 text-blue-400 font-medium leading-relaxed",children:"KM"}),"ollama"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-violet-500/15 text-violet-400 font-medium leading-relaxed",children:"OL"}),"deepseek"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-sky-500/15 text-sky-400 font-medium leading-relaxed",children:"DS"}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h(a.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:C("tabBar.closeTab"),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:"M6 18L18 6M6 6l12 12"})})})]})},a.id)),(0,n.jsx)(c,{onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j})]})})}},27570:(e,t,r)=>{r.d(t,{L:()=>s});var n=r(12115);function s({enabled:e,container:t,resolveLineRange:r,buildLineSnapshot:o,dragThresholdPx:l=5}){let a=(0,n.useRef)(null),i=(0,n.useRef)(()=>{}),c=(0,n.useRef)(r),d=(0,n.useRef)(o),u=(0,n.useRef)(l);return c.current=r,d.current=o,u.current=l,(0,n.useEffect)(()=>{if(!e||!t)return;let r=!1,n=0,s=0,o=()=>{a.current&&(a.current=null,i.current())},l=e=>{r=!0,n=e.clientX,s=e.clientY;let t=e.target;t?.closest?.(".floating-toolbar")||o()},m=e=>{r=!1;let l=e.target;if(l?.closest?.(".floating-toolbar"))return;let m=u.current,x=Math.abs(e.clientX-n)>m||Math.abs(e.clientY-s)>m,h=window.getSelection();if(!h||h.isCollapsed||!h.toString().trim()||!x)return void o();let f=h.getRangeAt(0);if(!t.contains(f.commonAncestorContainer))return void o();let p=c.current(f.startContainer),g=c.current(f.endContainer);if(!p||!g)return void o();let b=Math.min(p.start,g.start),v=Math.max(p.end,g.end),j=h.toString(),w=d.current({start:b,end:v});a.current={x:e.clientX,y:e.clientY,range:{start:b,end:v},selectedText:j,lineSnapshot:w},i.current()},x=()=>{if(r||!a.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||o()};return t.addEventListener("mousedown",l),document.addEventListener("mouseup",m),document.addEventListener("selectionchange",x),()=>{t.removeEventListener("mousedown",l),document.removeEventListener("mouseup",m),document.removeEventListener("selectionchange",x)}},[e,t]),{toolbarRef:a,bumpRef:i,clearToolbar:()=>{a.current&&(a.current=null,i.current())}}}},33408:(e,t,r)=>{r.d(t,{TabManager:()=>sd});var n=r(95155),s=r(12115),o=r(79114),l=r(95045),a=r(75346),i=r(86957),c=r(83448);function d({isOpen:e,onClose:t,cwd:r,onSelectSession:u}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(""),w=(0,s.useRef)(null),y=(0,s.useCallback)(async()=>{if(!r)return;p(!0),b(null);let e=r.replace(/\//g,"-"),t=await i.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?h(t.value):b("Failed to load sessions"),p(!1)},[r]);(0,s.useEffect)(()=>{e&&(y(),setTimeout(()=>{w.current?.focus()},100))},[e,y]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let k=x.filter(e=>{if(!v)return!0;let t=v.toLowerCase();return e.title.toLowerCase().includes(t)||e.firstMessages.some(e=>e.toLowerCase().includes(t))||e.lastMessages.some(e=>e.toLowerCase().includes(t))});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-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-6xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",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-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:m("sessions.sessionList")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:r,children:r})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsx)("input",{ref:w,type:"text",placeholder:m("sessions.searchSessions"),value:v,onChange:e=>j(e.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent 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 overflow-y-auto p-4",children:[f&&(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:m("sessions.loadingSessions")})]})}),g&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:g})}),!f&&!g&&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:m(v?"sessions.noMatchingSessions":"sessions.noSessionsYet")})}),!f&&!g&&k.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:k.map(e=>(0,n.jsxs)("div",{onClick:()=>{let n;return n=(e.path.split("/").pop()||"").replace(".jsonl",""),void(u?(u(n,e.title),t()):(0,l.F)(a.n.OpenProject,{cwd:r,sessionId:n}))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[e.engine&&"claude"!==e.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===e.engine?"bg-orange-500/15 text-orange-11":"ollama"===e.engine?"bg-blue-500/15 text-blue-11":"codex"===e.engine?"bg-green-500/15 text-green-11":"kimi"===e.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:e.title,children:e.title})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.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:[e.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),e.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),e.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},e.path))})]})]})]}):null}var u=r(47650),m=r(64428),x=r(60938),h=r(53213),f=r(64702),p=r(1058),g=r(90717),b=r(70188),v=r(48347),j=r(89109),w=r(7320);function y(e,t){let r=e.split("\n"),n=t.split("\n"),s=[],o=r.length,l=n.length,a=Array(o+1).fill(null).map(()=>Array(l+1).fill(0));for(let e=1;e<=o;e++)for(let t=1;t<=l;t++)r[e-1]===n[t-1]?a[e][t]=a[e-1][t-1]+1:a[e][t]=Math.max(a[e-1][t],a[e][t-1]);let i=o,c=l,d=[];for(;i>0||c>0;)i>0&&c>0&&r[i-1]===n[c-1]?(d.push({type:"unchanged",content:r[i-1],oldLineNum:i,newLineNum:c}),i--,c--):c>0&&(0===i||a[i][c-1]>=a[i-1][c])?(d.push({type:"added",content:n[c-1],newLineNum:c}),c--):(d.push({type:"removed",content:r[i-1],oldLineNum:i}),i--);for(;d.length>0;)s.push(d.pop());return s}var k=r(34075),N=r(56978),C=r(17196);function S({lines:e,containerRef:t}){let r=(0,s.useRef)(null),[o,l]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{let{scrollTop:t,scrollHeight:n,clientHeight:s}=e,o=r.current?.clientHeight||0;if(n<=s)l({top:0,height:o});else{let e=o/n;l({top:t*e,height:s*e})}};return n(),e.addEventListener("scroll",n),window.addEventListener("resize",n),()=>{e.removeEventListener("scroll",n),window.removeEventListener("resize",n)}},[t]),0===e.length)return null;let a=100/e.length;return(0,n.jsxs)("div",{ref:r,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let n=t.current,s=r.current;if(!n||!s)return;let o=s.getBoundingClientRect(),l=(e.clientY-o.top)/o.height*n.scrollHeight-n.clientHeight/2;n.scrollTo({top:Math.max(0,l),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,n.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*a}%`,height:`${Math.max(a,.5)}%`,minHeight:"2px"}},t)),(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${o.top}px`,height:`${Math.max(o.height,10)}px`}})]})}var L=r(37614),E=r(27570);function M(e){return e.params?`${e.name}(${e.params.join(", ")})`:e.name}function T({oldContent:e,newContent:t,filePath:r,isNew:l=!1,isDeleted:a=!1,cwd:i,enableComments:c=!1,onPreview:d,previewLabel:m,onContentSearch:x,targetLine:h,compact:$=!1,symbols:P}){let{t:R}=(0,o.Bd)(),B=m??R("common.preview"),F=(0,s.useMemo)(()=>y(e,t),[e,t]),I=(0,s.useRef)(null),D=(0,s.useRef)(null),A=(0,s.useRef)(null),_=(0,s.useRef)(!1),[W,z]=(0,s.useState)(!1),H=(0,b.iN)(),O=(0,v.r)(),q=c&&!!i,{comments:V,addComment:K,updateComment:U,deleteComment:J,refresh:Q}=(0,p._)({cwd:i||"",filePath:r}),[X,Y]=(0,s.useState)(null),[Z,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{A.current!==Z&&G(A.current)});let{toolbarRef:ee,bumpRef:et,clearToolbar:er}=(0,E.L)({enabled:q,container:Z,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,r=t?.closest("[data-new-line]");if(!r)return null;let n=parseInt(r.getAttribute("data-new-line")||"0",10);return!Number.isFinite(n)||n<=0?null:{start:n,end:n}},buildLineSnapshot:({start:e,end:t})=>{let r=[],n=0;for(let s of F)("unchanged"===s.type||"added"===s.type)&&++n>=e&&n<=t&&r.push(s.content);return r.join("\n")}}),[en,es]=(0,s.useState)(null),[eo,el]=(0,s.useState)(null);(0,s.useEffect)(()=>{z(!0)},[]);let ea=(0,s.useMemo)(()=>{let e=new Set;for(let t of V)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[V]),ei=(0,s.useMemo)(()=>{let e=new Map;for(let t of V){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[V]),ec=(0,s.useCallback)((e,t)=>{t.stopPropagation(),Y({comment:e,x:t.clientX,y:t.clientY}),er(),es(null),el(null)},[er]),ed=(0,s.useCallback)(()=>{let e=ee.current;e&&(es({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),er())},[er,ee]),eu=(0,s.useCallback)(()=>{let e=ee.current;e&&(el({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),er())},[er,ee]),em=(0,s.useCallback)(()=>{let e=ee.current;if(!e||!x)return;let t=e.selectedText.trim();er(),t&&x(t)},[x,er,ee]),ex=(0,s.useCallback)(async e=>{if(eo&&O&&i)try{let t=await (0,g.$3)(i),n=[];for(let e of t)n.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});n.push({filePath:r,startLine:eo.range.start,endLine:eo.range.end,codeContent:eo.lineSnapshot});let s=(0,g.Gw)(n,e);O.sendMessage(s),await (0,g.RP)(i),Q(),el(null)}catch(e){console.error("Failed to send to AI:",e)}},[eo,O,r,i,Q]),eh=(0,s.useCallback)(async e=>{en&&(await K(en.range.start,en.range.end,e,en.selectedText),es(null))},[en,K]);(0,s.useEffect)(()=>{let e=D.current,t=A.current;if(!e||!t)return;let r=(e,t)=>{_.current||(_.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{_.current=!1}))},n=()=>r(e,t),s=()=>r(t,e);return e.addEventListener("scroll",n),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",n),t.removeEventListener("scroll",s)}},[]);let{leftLines:ef,rightLines:ep}=(0,s.useMemo)(()=>{let e=[],t=[],r=0,n=0;for(let s=0;s<F.length;s++){let o=F[s];if("unchanged"===o.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});r++,n++,e.push({lineNum:r,content:o.content,type:"unchanged",originalIdx:s}),t.push({lineNum:n,content:o.content,type:"unchanged",originalIdx:s})}else"removed"===o.type?(r++,e.push({lineNum:r,content:o.content,type:"removed",originalIdx:s})):"added"===o.type&&(n++,t.push({lineNum:n,content:o.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[F]),eg=(0,s.useMemo)(()=>F.map(e=>e.content),[F]),eb=(0,N.C)(eg,r),[ev,ej]=(0,s.useState)(()=>new Map);(0,s.useLayoutEffect)(()=>{ej(new Map),eE.measure()},[ef,ep]);let ew=(0,s.useMemo)(()=>P??[],[P]),{rows:ey,gaps:ek}=(0,s.useMemo)(()=>$?function(e,t,r,n=[]){let s=e.length,o=r=>"unchanged"!==e[r].type||"unchanged"!==t[r].type,l=new Set;for(let e=0;e<s;e++){if(!o(e))continue;let t=Math.max(0,e-3),r=Math.min(s-1,e+3);for(let e=t;e<=r;e++)l.add(e)}let a=[];for(let e=0;e<s;e++){if(l.has(e))continue;let t=e;for(;e<s&&!l.has(e);)e++;a.push({id:a.length,startIdx:t,endIdx:e-1}),e--}for(let e of a){let t=r.get(e.id)??{topRevealed:0,bottomRevealed:0},n=e.endIdx-e.startIdx+1,s=Math.max(0,Math.min(t.topRevealed,n)),o=Math.max(0,Math.min(t.bottomRevealed,n-s));for(let t=e.startIdx;t<e.startIdx+s;t++)l.add(t);for(let t=e.endIdx-o+1;t<=e.endIdx;t++)l.add(t)}let i=[];for(let e=0;e<s;e++){let r;if(l.has(e)){i.push({kind:"diff",idx:e});continue}let o=e;for(;e<s&&!l.has(e);)e++;let c=e-1;e--;let d=a.find(e=>e.startIdx<=o&&c<=e.endIdx);if(!d)continue;let u=c-o+1,m=Math.min(20,u);if(n.length>0&&c+1<s)for(let e=c+1;e<s;e++){let s=t[e].lineNum;if(!(s<=0)){r=function(e,t){let r=null;for(let n of e)n.startLine<=t&&t<=n.endLine&&(!r||n.endLine-n.startLine<r.endLine-r.startLine)&&(r=n);return r}(n,s)??void 0;break}}i.push({kind:"gap-expand",gapId:d.id,direction:"up",revealCount:m}),i.push({kind:"gap-label",gapId:d.id,hiddenCount:u,enclosingFn:r}),i.push({kind:"gap-expand",gapId:d.id,direction:"down",revealCount:m})}return{rows:i,gaps:a}}(ef,ep,ev,ew):{rows:ef.map((e,t)=>({kind:"diff",idx:t})),gaps:[]},[$,ef,ef,ep,ev,ew]),eN=(0,s.useCallback)((e,t)=>{let r=ek.find(t=>t.id===e);r&&ej(n=>{let s=n.get(e)??{topRevealed:0,bottomRevealed:0},o=r.endIdx-r.startIdx+1-s.topRevealed-s.bottomRevealed;if(o<=0)return n;let l=Math.min(20,o),a="up"===t?{...s,topRevealed:s.topRevealed+l}:{...s,bottomRevealed:s.bottomRevealed+l};return new Map(n).set(e,a)})},[ek]),eC=(0,s.useCallback)(e=>{for(let t of ek)if(e>=t.startIdx&&e<=t.endIdx)return t.id;return null},[ek]),eS=(0,s.useCallback)(e=>ey[e]?.kind==="gap-label"?28:20,[ey]),eL=(0,s.useCallback)(e=>{let t=ey[e];if(!t)return e;if("gap-label"===t.kind)return`gl:${t.gapId}`;if("gap-expand"===t.kind)return`ge:${t.gapId}:${t.direction}`;let r=ef[t.idx],n=ep[t.idx];return`d:${r?.lineNum??"x"}:${r?.type??"x"}:${n?.lineNum??"x"}:${n?.type??"x"}`},[ey,ef,ep]),eE=(0,f.Te)({count:ey.length,getScrollElement:()=>I.current,estimateSize:eS,getItemKey:eL,overscan:20}),eM=l?"w-1/4":a?"w-3/4":"w-1/2",eT=l?"w-3/4":a?"w-1/4":"w-1/2",e$=(0,s.useMemo)(()=>ey.map(e=>{if("diff"!==e.kind)return{type:"unchanged"};let t=ef[e.idx],r=ep[e.idx];return"removed"===t.type?{type:"removed"}:r?.type==="added"?{type:"added"}:{type:"unchanged"}}),[ey,ef,ep]),eP=eE.getTotalSize(),eR=eE.getVirtualItems();return(0,s.useEffect)(()=>{if(!h)return;let e=("after"===h.side?ep:ef).findIndex(e=>e.lineNum===h.line);if(-1===e)return;let t=ey.findIndex(t=>"diff"===t.kind&&t.idx===e);if(-1===t){let t=eC(e);if(null!==t){let e=ek.find(e=>e.id===t);if(!e)return;let r=e.endIdx-e.startIdx+1;ej(e=>{let n=e.get(t)??{topRevealed:0,bottomRevealed:0};if(n.topRevealed+n.bottomRevealed>=r)return e;let s=new Map(e);return s.set(t,{topRevealed:r,bottomRevealed:0}),s})}return}let r=requestAnimationFrame(()=>{eE.scrollToIndex(t,{align:"start"})});return()=>cancelAnimationFrame(r)},[h,ef,ep,ey]),(0,n.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,n.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,n.jsx)("div",{className:`${eM} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:l?"(New File)":a?"Deleted":"Old"}),(0,n.jsxs)("div",{className:`${eT} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,n.jsx)("span",{className:"block text-center",children:a?"(Deleted)":"New"}),(0,n.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[d&&(0,n.jsx)("button",{onClick:d,className:"text-muted-foreground hover:text-foreground transition-colors",children:B}),!a&&t&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,k.oR)(R("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:R("common.copy")})]})]}),(0,n.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,n.jsx)("div",{ref:I,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,n.jsxs)("div",{className:"flex",style:{height:`${eP}px`},children:[(0,n.jsx)("div",{ref:D,className:`${eM} overflow-x-auto border-r border-border`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eR.map(e=>{let t=ey[e.index];if("gap-expand"===t.kind||"gap-label"===t.kind){let r="gap-label"===t.kind;return(0,n.jsx)("div",{ref:eE.measureElement,"data-index":e.index,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:r?"bg-accent border-y border-border":""},e.key)}let r=ef[t.idx];return(0,n.jsxs)("div",{ref:eE.measureElement,"data-index":e.index,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===r.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:r.lineNum||""}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:r.originalIdx>=0&&eb[r.originalIdx]||(0,C.ZD)(r.content||" ")}})]},e.key)})})}),(0,n.jsx)("div",{ref:A,className:`${eT} overflow-x-auto`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eR.map(e=>{let t=ey[e.index];if("gap-expand"===t.kind)return(0,n.jsx)("button",{ref:eE.measureElement,"data-index":e.index,type:"button",onClick:()=>eN(t.gapId,t.direction),style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center text-[11px] text-foreground/50 hover:bg-accent hover:text-brand active:bg-brand/15 transition-colors duration-100 cursor-pointer focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-brand/60",title:R("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),"aria-label":R("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),children:(0,n.jsx)("span",{className:"select-none",children:R("diffViewer.gap.more",{count:t.revealCount})})},e.key);if("gap-label"===t.kind)return(0,n.jsxs)("div",{ref:eE.measureElement,"data-index":e.index,"data-gap-id":t.gapId,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center gap-2 px-3 text-[11px] text-foreground/80 bg-accent border-y border-border min-w-0 select-none",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:R("diffViewer.gap.hidden",{count:t.hiddenCount})}),t.enclosingFn&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"opacity-50 flex-shrink-0",children:"\xb7"}),(0,n.jsx)("span",{className:"truncate min-w-0 font-medium",title:M(t.enclosingFn),children:M(t.enclosingFn)})]})]},e.key);let r=ep[t.idx],s=r?.lineNum||0,o=s>0&&ea.has(s),l=ei.get(s),a=l?.[0],i=en&&s>=en.range.start&&s<=en.range.end,c=eo&&s>=eo.range.start&&s<=eo.range.end,d=i||c;return(0,n.jsxs)("div",{ref:eE.measureElement,"data-index":e.index,"data-new-line":s||void 0,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${d?"bg-blue-9/20":o?"bg-amber-9/10":r?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${d?"bg-blue-9/30":""}`,style:{width:q?"52px":"40px"},children:[q&&s>0&&o&&a&&(0,n.jsx)("button",{onClick:e=>ec(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:R("codeViewer.nComments",{count:l?.length}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),q&&s>0&&!o&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"flex-1 text-right pr-1",children:s||""})]}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:r?.originalIdx>=0&&eb[r.originalIdx]||(0,C.ZD)(r?.content||" ")}})]},e.key)})})})]})}),(0,n.jsx)(S,{lines:e$,containerRef:I})]}),W&&H&&(0,u.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.f,{floatingToolbarRef:ee,bumpRef:et,container:H,onAddComment:ed,onSendToAI:eu,onSearch:x?em:void 0,isChatLoading:O?.isLoading??!1}),en&&(0,n.jsx)(w.t,{x:en.x,y:en.y,range:en.range,lineSnapshot:en.lineSnapshot,container:H,onSubmit:eh,onClose:()=>es(null)}),eo&&(0,n.jsx)(w.G,{x:eo.x,y:eo.y,range:eo.range,filePath:r,lineSnapshot:eo.lineSnapshot,container:H,onSubmit:ex,onClose:()=>el(null),isChatLoading:O?.isLoading}),X&&(0,n.jsx)(L.t,{x:X.x,y:X.y,comment:X.comment,container:H,onClose:()=>Y(null),onUpdateComment:U,onDeleteComment:J})]}),H)]})}function $({oldContent:e,newContent:t,filePath:r}){let o=(0,s.useMemo)(()=>y(e,t),[e,t]),l=(0,s.useRef)(null),a=(0,s.useMemo)(()=>o.map(e=>e.content),[o]),i=(0,N.C)(a,r),c=(0,s.useCallback)(e=>{let t=o[e];return t?`${t.type}:${t.oldLineNum??"x"}:${t.newLineNum??"x"}`:e},[o]),d=(0,f.Te)({count:o.length,getScrollElement:()=>l.current,estimateSize:()=>20,getItemKey:c,overscan:20});return(0,n.jsx)("div",{ref:l,className:"font-mono text-sm overflow-auto h-full",children:(0,n.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.getVirtualItems().map(e=>{let t=o[e.index];return(0,n.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":"added"===t.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==t.type?t.oldLineNum:""}),(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==t.type?t.newLineNum:""}),(0,n.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===t.type?"text-red-11":"added"===t.type?"text-green-11":"text-slate-9"}`,children:"removed"===t.type?"-":"added"===t.type?"+":" "}),(0,n.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:i[e.index]||(0,C.ZD)(t.content||" ")}})]},e.key)})})})}let P={ts:"#3178c6",tsx:"#3178c6",js:"#f1e05a",jsx:"#61dafb",mjs:"#f1e05a",cjs:"#f1e05a",html:"#e44d26",css:"#563d7c",scss:"#cd6799",sass:"#cd6799",less:"#1d365d",vue:"#41b883",svelte:"#ff3e00",json:"#cbcb41",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4121",xml:"#e37933",env:"#ecd53f",md:"#519aba",mdx:"#519aba",txt:"#89898a",py:"#3572a5",go:"#00add8",rs:"#dea584",java:"#b07219",kt:"#a97bff",kts:"#a97bff",c:"#555555",h:"#555555",cpp:"#f34b7d",hpp:"#f34b7d",rb:"#701516",php:"#4f5d95",sh:"#89e051",bash:"#89e051",zsh:"#89e051",png:"#a074c4",jpg:"#a074c4",jpeg:"#a074c4",gif:"#a074c4",svg:"#ffb13b",webp:"#a074c4",ico:"#a074c4",lock:"#89898a",gitignore:"#f14e32",dockerfile:"#2496ed",sql:"#e38c00",graphql:"#e535ab",gql:"#e535ab",default:"#8a8a8a"},R={"package.json":"#cb3837","package-lock.json":"#cb3837","tsconfig.json":"#3178c6","jsconfig.json":"#f1e05a",".gitignore":"#f14e32",".eslintrc":"#4b32c3",".eslintrc.js":"#4b32c3",".eslintrc.json":"#4b32c3",".prettierrc":"#56b3b4",dockerfile:"#2496ed",".env":"#ecd53f",".env.local":"#ecd53f",".env.development":"#ecd53f",".env.production":"#ecd53f","readme.md":"#519aba",license:"#d4af37",makefile:"#6d8086","cargo.toml":"#dea584","go.mod":"#00add8","go.sum":"#00add8","requirements.txt":"#3572a5","yarn.lock":"#2c8ebb","pnpm-lock.yaml":"#f9ad00","vite.config.ts":"#646cff","vite.config.js":"#646cff","next.config.js":"#000000","next.config.mjs":"#000000","tailwind.config.js":"#38bdf8","tailwind.config.ts":"#38bdf8"};function B({name:e,className:t="",size:r=16}){let s,o=R[s=e.toLowerCase()]?R[s]:P[e.split(".").pop()?.toLowerCase()||""]||P.default,l=e.split(".").pop()?.toLowerCase()||"";return["ts","tsx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M7 10h10M12 10v8",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):["js","jsx","mjs","cjs"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M10 10v6c0 1-1 2-2 2M14 10v4c0 2 4 2 4 0v-4",stroke:"#323330",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):"jsx"===l||"tsx"===l&&e.includes("component")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(60 12 12)"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(120 12 12)"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2",fill:"#61dafb"})]}):"json"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 4C4 4 4 6 4 8v2c0 1-1 2-2 2 1 0 2 1 2 2v2c0 2 0 4 2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M18 4c2 0 2 2 2 4v2c0 1 1 2 2 2-1 0-2 1-2 2v2c0 2 0 4-2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5",fill:o})]}):["md","mdx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M5 15V9l3 4 3-4v6M17 12l-2-3v6M17 12l2-3v6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["py","pyi","pyx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M12 4c-4 0-4 2-4 3v2h5v1H6c-2 0-3 2-3 4s1 4 3 4h2v-2c0-2 1-3 3-3h4c1 0 2-1 2-2V7c0-2-2-3-5-3z",fill:"#3572a5"}),(0,n.jsx)("path",{d:"M12 20c4 0 4-2 4-3v-2h-5v-1h7c2 0 3-2 3-4s-1-4-3-4h-2v2c0 2-1 3-3 3h-4c-1 0-2 1-2 2v4c0 2 2 3 5 3z",fill:"#ffd43b"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"1",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"17",r:"1",fill:"white"})]}):"go"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6",fill:o}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"0.7",fill:"#333"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"0.7",fill:"#333"})]}):"rs"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:o,strokeWidth:"2",fill:"none"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:o}),(0,n.jsx)("path",{d:"M12 3v3M12 18v3M3 12h3M18 12h3",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):["png","jpg","jpeg","gif","webp","ico","bmp"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"9",r:"2",fill:o}),(0,n.jsx)("path",{d:"M3 16l5-5 3 3 4-4 6 6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"svg"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 12 Q12 6 17 12 Q12 18 7 12",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"html"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M8 7h8l-.5 6-3.5 1-3.5-1-.2-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["css","scss","sass","less"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M15 8H9l.3 3h5.2l-.4 4-2.1.7-2.1-.7-.1-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["yaml","yml"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 8l3 4v5M17 8l-3 4v5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["sh","bash","zsh","fish"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",fill:"#1e1e1e",stroke:"#555",strokeWidth:"1"}),(0,n.jsx)("path",{d:"M6 9l3 3-3 3M12 15h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"gitignore"===l||".gitignore"===e.toLowerCase()?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",fill:o}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:"white"}),(0,n.jsx)("path",{d:"M12 6v3M12 15v3M6 12h3M15 12h3",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):"dockerfile"===l||"dockerfile"===e.toLowerCase()||e.toLowerCase().startsWith("dockerfile")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M3 12h3v3H3zM7 12h3v3H7zM11 12h3v3h-3zM7 8h3v3H7zM11 8h3v3h-3zM11 4h3v3h-3zM15 12h3v3h-3z",fill:o}),(0,n.jsx)("path",{d:"M21 13c-1-2-3-2-4-2h-1c0-1 0-2-2-3h-1v1c0 1-1 2-2 2H3c-1 3 0 6 2 8s5 3 9 3c5 0 8-2 10-6",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"env"===l||e.startsWith(".env")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"8",r:"2",fill:o}),(0,n.jsx)("path",{d:"M12 8h6M8 12h8M8 16h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round"})]}):"sql"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"7",rx:"8",ry:"3",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 7v10c0 1.7 3.6 3 8 3s8-1.3 8-3V7",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"vue"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M2 4h4l6 10 6-10h4L12 22 2 4z",fill:o}),(0,n.jsx)("path",{d:"M6 4h4l2 4 2-4h4l-6 10L6 4z",fill:"#35495e"})]}):(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 3h8l5 5v13H6V3z",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M14 3v5h5",stroke:o,strokeWidth:"1.5",fill:"none"})]})}function F({status:e}){let{label:t,className:r}={added:{label:"A",className:"text-green-11"},untracked:{label:"A",className:"text-green-11"},modified:{label:"M",className:"text-amber-11"},deleted:{label:"D",className:"text-red-11"},renamed:{label:"R",className:"text-brand"}}[e]||{label:"?",className:"text-muted-foreground"};return(0,n.jsx)("span",{className:`text-xs font-bold ${r}`,children:t})}let I=s.memo(function e({node:t,level:r,selectedPath:o,expandedPaths:l,onSelect:a,onToggle:i,onContextMenu:c,showChanges:d=!1,renderActions:u}){let m=o===t.path,x=l.has(t.path),h=(0,s.useCallback)(()=>{t.isDirectory?i(t.path):a(t)},[t,a,i]),f=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),c(e,t.path,t.isDirectory)},[t.path,t.isDirectory,c]);return t.isDirectory?(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*r+8}px`},onClick:h,onContextMenu:f,children:[(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:x?"▼":"▶"}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1 truncate","data-tooltip":t.path,children:t.name}),u&&u(t)]}),x&&t.children.map(t=>(0,n.jsx)(e,{node:t,level:r+1,selectedPath:o,expandedPaths:l,onSelect:a,onToggle:i,onContextMenu:c,showChanges:d,renderActions:u},t.path))]}):(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${m?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*r+8}px`},onClick:h,onContextMenu:f,children:[(0,n.jsx)(B,{name:t.name,size:16,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:`text-sm flex-1 truncate ${m?"text-brand":"text-foreground"}`,"data-tooltip":t.path,children:t.name}),t.status&&(0,n.jsx)(F,{status:t.status}),d&&void 0!==t.additions&&void 0!==t.deletions&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["+",t.additions]}),(0,n.jsxs)("span",{className:"text-xs text-red-11",children:["-",t.deletions]})]}),u&&u(t)]})});function D({files:e,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:l,cwd:a,showChanges:i=!1,renderActions:c,emptyMessage:d,className:u}){let{t:m}=(0,o.Bd)(),x=d??m("gitFileTree.noFiles"),{contextMenu:h,showContextMenu:f,hideContextMenu:p}=(0,b.Ee)();return 0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:x}):(0,n.jsxs)("div",{className:u||"py-1",children:[e.map(e=>(0,n.jsx)(I,{node:e,level:0,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:l,onContextMenu:f,showChanges:i,renderActions:c},e.path)),h&&(0,n.jsx)(b.ft,{x:h.x,y:h.y,path:h.path,cwd:a,isDirectory:h.isDirectory,onClose:p})]})}function A(e){let t=[];for(let r of e){let e=r.path.split("/"),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,l=e.slice(0,t+1).join("/"),a=n.find(e=>e.name===s);a||(a={name:s,path:l,isDirectory:!o,children:[],...o&&{status:r.status,additions:r.additions,deletions:r.deletions,oldPath:r.oldPath,file:r}},n.push(a)),o||(n=a.children)}}let r=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>r(e.children))};return r(t),t}function _(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),r(n.children))};return r(e),t}function W(e){let t=[],r=e=>{if(e.isDirectory)for(let t of e.children)r(t);else t.push(e)};return r(e),t}var z=r(69809);function H(e){try{let t=JSON.parse(e);return Q(t,0)}catch{return e}}let O="#79c0ff",q="#a5d6ff",V="#ff7b72",K="#8b949e",U=(e,t)=>s.createElement("span",{style:{color:e}},t);function J({label:e,labelColor:t,value:r,indent:n}){let[o,l]=s.useState(!1),[a,i]=s.useState({x:0,y:0}),c="string"==typeof r&&r.replace(/\\n/g,"\n").split("\n").length>3,d={onMouseDown:e=>{i({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-a.x,r=e.clientY-a.y;t*t+r*r>25||(e.stopPropagation(),l(e=>!e))},style:{cursor:"pointer"}};if(c&&o&&"string"==typeof r){let n=r.replace(/\\n/g,"\n").split("\n")[0],o=r.replace(/\\n/g,"\n").split("\n").length;return s.createElement("span",d,U(t,e),U(K,": "),U(q,n),U("#6e7681",` ${z.A.t("toolCall.foldedLines",{count:o})}`))}let u=s.createElement(s.Fragment,null,U(t,e),U(K,": "),Q(r,n));return c?s.createElement("span",d,u):u}function Q(e,t){let r=" ".repeat(t);if(null===e)return U(V,"null");if(void 0===e)return U(V,"undefined");if("string"==typeof e)return U(q,e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+r));if("number"==typeof e)return U("#79c0ff",String(e));if("boolean"==typeof e)return U(V,String(e));if(Array.isArray(e))return 0===e.length?U(K,"[]"):s.createElement(s.Fragment,null,U(K,"["),"\n",...e.map((n,o)=>s.createElement("span",{key:o},r+" ",s.createElement(J,{label:`[${o}]`,labelColor:O,value:n,indent:t+1}),o<e.length-1?s.createElement(s.Fragment,null,U(K,","),"\n"):"\n")),r,U(K,"]"));if("object"==typeof e){let n=Object.entries(e);return 0===n.length?U(K,"{}"):s.createElement(s.Fragment,null,U(K,"{"),"\n",...n.map(([e,o],l)=>s.createElement("span",{key:e},r+" ",s.createElement(J,{label:e,labelColor:O,value:o,indent:t+1}),l<n.length-1?s.createElement(s.Fragment,null,U(K,","),"\n"):"\n")),r,U(K,"}"))}return String(e)}let X=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function Y(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return X.has(t)}function Z(e){return e.toLowerCase().endsWith(".md")}let G="json-search-highlight-style";function ee(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[l,a]=(0,s.useState)(!1),[i,c]=(0,s.useState)(0),[d,u]=(0,s.useState)(0),m=(0,s.useRef)(null),x=(0,s.useRef)([]),h=(0,s.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),x.current=[];let r=e.current;if(!r||!n){c(0),u(0);return}!function(){if(document.getElementById(G))return;let e=document.createElement("style");e.id=G,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let s=r.textContent||"",o=l?n:n.toLowerCase(),a=l?s:s.toLowerCase(),i=[],d=0;for(;d<a.length;){let e=a.indexOf(o,d);if(-1===e)break;i.push([e,e+o.length]),d=e+1}if(0===i.length){c(0),u(0);return}let m=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),h=0,f=0,p=[],g=null,b=0;for(;(t=m.nextNode())&&f<i.length;){let e=t.textContent?.length||0,r=h,n=h+e;for(;f<i.length;){let[e,s]=i[f];if(e>=n)break;if(!g)if(e>=r)(g=document.createRange()).setStart(t,e-r),b=s;else break;if(b<=n)g.setEnd(t,b-r),p.push(g),g=null,f++;else break}h=n}x.current=p,c(p.length),u(e=>p.length>0?Math.min(e,p.length-1):0),CSS.highlights&&p.length>0&&CSS.highlights.set("json-search",new Highlight(...p))},[e,n,l]),f=(0,s.useCallback)((e,t)=>{let r=e.getBoundingClientRect();(t.top<r.top||t.bottom>r.bottom)&&(e.scrollTop+=t.top-r.top-r.height/2+t.height/2)},[]),p=(0,s.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let r=x.current[t];if(!r||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(r));let n=r.getBoundingClientRect(),s=e.current?.parentElement;s&&f(s,n)},[e,f]);(0,s.useEffect)(()=>{queueMicrotask(()=>h())},[h]),(0,s.useEffect)(()=>{p(d)},[d,i,p]),(0,s.useEffect)(()=>{let t=e.current;if(!t||!n)return;let r=new MutationObserver(()=>h());return r.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>r.disconnect()},[e,n,h]),(0,s.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),x.current=[])},[t]),(0,s.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let g=(0,s.useCallback)(()=>{0!==i&&u(e=>(e+1)%i)},[i]),b=(0,s.useCallback)(()=>{0!==i&&u(e=>(e-1+i)%i)},[i]),v=(0,s.useCallback)(()=>{r(!0),setTimeout(()=>m.current?.focus(),0)},[]),j=(0,s.useCallback)(()=>{r(!1),o(""),u(0)},[]),w=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?b():g()),"Escape"===e.key&&(e.preventDefault(),j())},[g,b,j]);return{isVisible:t,query:n,setQuery:o,caseSensitive:l,setCaseSensitive:a,matchCount:i,currentIndex:d,searchInputRef:m,open:v,close:j,goToNext:g,goToPrev:b,handleKeyDown:w}}function et({search:e}){return e.isVisible?s.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},s.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:z.A.t("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),s.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:z.A.t("codeViewer.caseSensitive")},"Aa"),s.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:z.A.t("common.noMatch")),s.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:z.A.t("common.previous")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),s.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:z.A.t("common.next")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),s.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:z.A.t("common.close")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}function er({isOpen:e,onClose:t,commit:r,cwd:l,embedded:a=!1,initialFilePath:c,onContentSearch:d}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)(null),[w,y]=(0,s.useState)(null),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),M=(0,s.useRef)(null),$=ee(M);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&L){e.preventDefault(),$.open();return}if("Escape"===e.key){if($.isVisible)return void $.close();if(L)return void E(null);t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,L,$]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{x([]),p([]),j(null),y(null),N(!0)}),i.t4.runPromiseExit((0,h.Zi)(l,r.hash)).then(e=>{if("Success"===e._tag){let t=e.value.files??[];x(t);let n=A(t);if(p(n),b(new Set(_(n))),c&&t.length>0){let e=t.find(e=>e.path===c);e&&setTimeout(()=>{j(e),i.t4.runPromiseExit((0,h.Zi)(l,r.hash,e.path)).then(e=>{"Success"===e._tag?y(e.value):console.error(e.cause)})},0)}}else console.error(e.cause);N(!1)}))},[e,r,l,c]);let P=(0,s.useCallback)(e=>{r&&(j(e),S(!0),i.t4.runPromiseExit((0,h.Zi)(l,r.hash,e.path)).then(e=>{"Success"===e._tag?y(e.value):console.error(e.cause),S(!1)}))},[l,r]),R=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),B=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,l,a;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"),l=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${l}:${a}`:`${e.getFullYear()}-${s}-${o} ${l}:${a}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]);if(!e||!r)return null;let F=(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 bg-secondary 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-slate-9",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-slate-9",children:u("commitDetail.author")}),(0,n.jsx)("span",{children:r.author}),(0,n.jsxs)("span",{className:"text-slate-9",children:["<",r.authorEmail,">"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:u("commitDetail.date")}),(0,n.jsx)("span",{children:B}),r.relativeDate&&(0,n.jsxs)("span",{className:"text-slate-9",children:["(",r.relativeDate,")"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:u("commitDetail.files")}),(0,n.jsx)("span",{children:u("commitDetail.nChanges",{count:m.length})})]})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{className:"w-72 flex-shrink-0 border-r border-border overflow-y-auto overflow-x-hidden",children:k?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:u("commitDetail.loadingFiles")}):(0,n.jsx)(D,{files:f,selectedPath:v?.path||null,expandedPaths:g,onSelect:e=>e.file&&P(e.file),onToggle:R,cwd:l,showChanges:!0,emptyMessage:u("commitDetail.noFileChanges"),className:"py-1"})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:C?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:u("commitDetail.loadingDiff")}):w?(0,n.jsx)(T,{oldContent:w.oldContent,newContent:w.newContent,filePath:w.filePath,isNew:w.isNew,isDeleted:w.isDeleted,cwd:l,enableComments:!0,onPreview:!w.isDeleted&&w.filePath.endsWith(".json")?()=>E({content:w.newContent,filePath:w.filePath}):void 0,previewLabel:u("common.readable"),onContentSearch:d}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:u("commitDetail.selectFileToView")})})]})]}),I=L&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>E(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl 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:L.filePath}),(0,n.jsx)("button",{onClick:()=>E(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent 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)(et,{search:$}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:M,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:H(L.content)})})]})});return a?(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-slate-9 hover:text-foreground hover:bg-accent 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"})})}),F,I]}):(0,n.jsx)("div",{className:"fixed inset-0 z-[60] bg-black/50",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-slate-9 hover:text-foreground hover:bg-accent 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"})})})]}),F,I]})})}let en={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"},"?":{text:"text-slate-9",bg:"bg-slate-9/20"},R:{text:"text-blue-11",bg:"bg-blue-9/20"}},es=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:l,onToggle:a,onContextMenu:i,renderActions:c}){let{node:d,level:u,gitStatus:m,hasChangedChildren:x}=e,h=m?en[m]:null,f=(0,s.useCallback)(()=>{d.isDirectory?a(d.path):l(d.path)},[d.isDirectory,d.path,l,a]),p=(0,s.useCallback)(e=>{i(e,d.path,d.isDirectory)},[d.path,d.isDirectory,i]),g=!d.isDirectory&&(".env"===d.name||d.name.startsWith(".env.")),b=m?h.text:x?"text-amber-11":g?"text-yellow-600 dark:text-yellow-500":t&&!d.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-accent ${t?"bg-brand/10":""}`,style:{paddingLeft:`${12*u+8}px`},onClick:f,onContextMenu:p,children:[d.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)(B,{name:d.name,size:16,className:"flex-shrink-0 ml-4"}),(0,n.jsx)("span",{className:`text-sm truncate flex-1 ${b}`,"data-tooltip":d.isSymlink&&d.symlinkTarget?`${d.path} → ${d.symlinkTarget}`:d.path,children:d.name}),d.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}),d.isDirectory&&x&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-9 flex-shrink-0"}),c?.(d)]})});function eo({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:l=null,loadingDirs:a,onSelect:i,onToggle:c,cwd:d,shouldScrollToSelected:u=!1,onScrolledToSelected:m,className:x,renderActions:h,onCreateFile:p,onDelete:g,onRefresh:v,onCopyFile:j,onPaste:w}){let y=(0,s.useRef)(null),{contextMenu:k,showContextMenu:N,hideContextMenu:C}=(0,b.Ee)(),S=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let l=[];for(let a of t){if(null!==n&&!n.has(a.path))continue;let t=s?.get(a.path),i=a.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}(a.path,s):void 0;l.push({node:a,level:o,gitStatus:t,hasChangedChildren:i}),a.isDirectory&&a.children&&r.has(a.path)&&l.push(...e(a.children,r,n,s,o+1))}return l})(e,r,o,l),[e,r,o,l]),L=(0,f.Te)({count:S.length,getScrollElement:()=>y.current,estimateSize:()=>26,overscan:10}),E=(0,s.useRef)(m);return(E.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(()=>{L.scrollToIndex(e,{align:"center"}),E.current?.()},150);return()=>clearTimeout(t)}}},[u,t,S,L]),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:y,className:x||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${L.getTotalSize()}px`,width:"100%",position:"relative"},children:L.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)(es,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:a?.has(s.node.path),onSelect:i,onToggle:c,onContextMenu:N,renderActions:h})},s.node.path)})}),k&&(0,n.jsx)(b.ft,{x:k.x,y:k.y,path:k.path,cwd:d,isDirectory:k.isDirectory,onClose:C,onCreateFile:p,onDelete:g,onRefresh:v,onCopyFile:j,onPaste:w})]})}var el=r(38408),ea=r(82292),ei=r(45048),ec=r(97251),ed=r(47176),eu=r(79968);let em=[ec.W];function ex({content:e,filePath:t,cwd:r,onClose:l,sourceFile:a}){let i=a||(r&&t.startsWith(r)?t.slice(r.endsWith("/")?r.length:r.length+1):t),{t:c}=(0,o.Bd)(),d=(0,b.iN)(),m=(0,v.r)(),{comments:x,addComment:h,updateComment:f,deleteComment:y,refresh:k}=(0,p._)({cwd:r,filePath:t}),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(null),[T,$]=(0,s.useState)(null),[P,R]=(0,s.useState)(null),B=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>C(!0))},[]);let[F,I]=(0,s.useState)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>{D.current!==F&&I(D.current)});let{toolbarRef:A,bumpRef:_,clearToolbar:W}=(0,E.L)({enabled:!0,container:F,resolveLineRange:e=>{let t=function(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let r=t.closest("[data-source-start]");if(!r)return null;let n=r.getAttribute("data-source-start"),s=r.getAttribute("data-source-end");return n&&s?{start:parseInt(n,10),end:parseInt(s,10)}:null}(e);return t?{start:t.start,end:t.end}:null},buildLineSnapshot:({start:e,end:t})=>{let r=Math.max(0,e-1),n=Math.min(B.length,t);return B.slice(r,n).join("\n")}}),z=(0,s.useCallback)(()=>{let e=A.current;e&&(M({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),W())},[W,A]),H=(0,s.useCallback)(()=>{let e=A.current;e&&($({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),W())},[W,A]),O=(0,s.useCallback)(async e=>{S&&(await h(S.range.start,S.range.end,e,S.selectedText),M(null))},[S,h]),q=(0,s.useCallback)(async e=>{if(T&&m)try{let n=await (0,g.$3)(r),s=[];for(let e of n)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:T.range.start,endLine:T.range.end,codeContent:T.lineSnapshot});let o=(0,g.Gw)(s,e);m.sendMessage(o),await (0,g.RP)(r),k(),$(null)}catch(e){console.error("Failed to send to AI:",e)}},[T,m,t,r,k]),V=(0,s.useMemo)(()=>{if(0===x.length)return[];let e=new Map;for(let t of x){let r=`${t.startLine}-${t.endLine}`;e.has(r)||e.set(r,[]),e.get(r).push(t)}return Array.from(e.entries()).map(([e,t])=>({key:e,startLine:t[0].startLine,endLine:t[0].endLine,comments:t}))},[x]),[K,U]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===V.length||!D.current)return void queueMicrotask(()=>U([]));let e=setTimeout(()=>{let e=D.current;if(!e)return;let t=[],r=e.querySelectorAll("[data-source-start]");for(let n of V){let s=null,o=1/0;for(let e of r){let t=parseInt(e.getAttribute("data-source-start"),10),r=parseInt(e.getAttribute("data-source-end"),10);if(t<=n.startLine&&r>=n.endLine){let n=r-t;n<o&&(o=n,s=e)}}if(s){let r=e.getBoundingClientRect(),o=s.getBoundingClientRect();t.push({key:n.key,top:o.top-r.top+e.scrollTop,comments:n.comments})}}U(t)},100);return()=>clearTimeout(e)},[V,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(T){$(null),e.stopPropagation();return}if(S){M(null),e.stopPropagation();return}if(A.current){A.current=null,_.current(),e.stopPropagation();return}if(P){R(null),e.stopPropagation();return}l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[T,S,P,l]),(0,n.jsxs)(n.Fragment,{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 truncate",children:t}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(eu.ShareReviewToggle,{content:e,sourceFile:i}),(0,n.jsx)("button",{onClick:l,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:c("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.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)(ed.l,{content:e,containerRef:D}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:D,children:[(0,n.jsx)("div",{className:"p-6",children:(0,n.jsx)(ei.T,{content:e,rehypePlugins:em})}),K.map(({key:e,top:t,comments:r})=>(0,n.jsx)("div",{className:"absolute right-3 cursor-pointer z-10",style:{top:t},onClick:e=>{e.stopPropagation(),R({comment:r[0],x:e.clientX,y:e.clientY})},children:(0,n.jsx)("div",{className:"w-5 h-5 rounded-full bg-amber-500/80 text-white text-xs flex items-center justify-center shadow-sm hover:bg-amber-500 transition-colors",children:r.length})},e))]})]}),N&&d&&(0,u.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.f,{floatingToolbarRef:A,bumpRef:_,container:d,onAddComment:z,onSendToAI:H,isChatLoading:m?.isLoading}),S&&(0,n.jsx)(w.t,{x:S.x,y:S.y,range:S.range,lineSnapshot:S.lineSnapshot,container:d,onSubmit:O,onClose:()=>M(null)}),T&&(0,n.jsx)(w.G,{x:T.x,y:T.y,range:T.range,filePath:t,lineSnapshot:T.lineSnapshot,container:d,onSubmit:q,onClose:()=>$(null),isChatLoading:m?.isLoading}),P&&(0,n.jsx)(L.t,{x:P.x,y:P.y,comment:P.comment,container:d,onClose:()=>R(null),onUpdateComment:f,onDeleteComment:y})]}),d)]})}function eh({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),l=o>=0?e.slice(0,o+1):"",a=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],l="",a=!1;for(let s=0;s<e.length;s++){let i=t+s,c=r.has(i);c!==a&&l&&(o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-${s}`):(0,n.jsx)("span",{children:l},`${t}-${s}`)),l=""),a=c,l+=e[s]}return l&&o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-end`):(0,n.jsx)("span",{children:l},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[l&&i(l,0,"text-muted-foreground"),i(a,l.length,"text-foreground")]})}function ef({files:e,fileIndex:t,recentFiles:r,onSelectFile:l,onClose:a}){let{t:i}=(0,o.Bd)(),[c,d]=(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(!c.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,l=0,a=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),a===i-1&&(l+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(l+=10),i>e.lastIndexOf("/")&&(l+=3),e[i]===t[o]&&(l+=1),a=i,o++);return o<n.length?null:(l-=.1*e.length,{path:e,score:l,matchedIndices:s})}(t,c.trim());n&&(r.includes(t)&&(n.score+=20),e.push(n))}return e.sort((e,t)=>t.score-e.score),e.slice(0,50)},[c,p,r]),b=(0,s.useCallback)(e=>{d(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=>{l(e),a()},[l,a]),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(),a()}},[g,u,v,a]);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:a,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-2xl 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:c,onChange:e=>b(e.target.value),onKeyDown:j,placeholder:i("quickFileOpen.placeholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",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-accent text-foreground"}`,"data-tooltip":e.path,onClick:()=>v(e.path),children:[(0,n.jsx)(B,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(eh,{path:e.path,matchedIndices:e.matchedIndices}),!c.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 ep=r(2111),eg=r(41474),eb=r(61878),ev=r(33210),ej=r(48368),ew=r(91958),ey=r(45916),ek=r(31794),eN=r(69048),eC=r(97567),eS=r(68806),eL=r(52475);function eE({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)(ej.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(ey.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(ek.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(eN.A,{className:s});case"class":return(0,n.jsx)(eC.A,{className:s});case"interface":return(0,n.jsx)(eS.A,{className:s});default:return(0,n.jsx)(eL.A,{className:s})}}var eM=r(49433),eT=r(82680);let e$=new Map,eP=new Map;async function eR(e,t,r=!1){let n=`${e}::${t}`;if(r)!function(e){if(!e){e$.clear(),eP.clear();return}let t=`${e}::`;for(let e of e$.keys())e.startsWith(t)&&e$.delete(e);for(let e of eP.keys())e.startsWith(t)&&eP.delete(e)}(e);else{let e=e$.get(n);if(e)return e;let t=eP.get(n);if(t)return t}let s=eM.tryPromise({try:async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","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}`);let l=await o.json();return e$.set(n,l),l},catch:e=>new eT.uV({message:"fetchFileFunctions failed",cause:e})}),o=i.t4.runPromiseExit(s).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.delete(n));return eP.set(n,o),o}function eB(e,t){let[r,n]=(0,s.useState)({state:"idle"}),o=(0,s.useRef)(!0);(0,s.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let l=(0,s.useCallback)((e,t,r)=>{n({state:"loading"}),eR(e,t,r).then(e=>{o.current&&("not-found"===e?n({state:"notFound"}):n({state:"ready",data:e}))}).catch(e=>{o.current&&n({state:"error",message:e.message})})},[]);return(0,s.useEffect)(()=>{e&&t?l(e,t,!1):n({state:"idle"})},[e,t,l]),{state:r,refresh:(0,s.useCallback)(()=>{e&&t&&l(e,t,!0)},[e,t,l])}}var eF=r(3238),eI=r(50538),eD=r(94287);function eA({entries:e,onSelect:t,onClear:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-l border-border 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.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground font-mono min-w-0",children:[(0,n.jsx)(eI.A,{className:"w-3 h-3 flex-shrink-0"}),(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)(eD.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)(ev.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)(eD.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:bg-secondary/60 transition-colors group flex items-start gap-1.5",children:[(0,n.jsx)(eE,{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 e_(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 eW=new Set(["function","class","method"]);function ez(e){return eW.has(e.kind)}function eH({functions:e,currentQname:t,onSelect:r}){let{t:l}=(0,o.Bd)(),a=(0,s.useMemo)(()=>e.filter(ez),[e]);return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-r border-border flex flex-col","data-testid":"file-toc-section",children:[(0,n.jsx)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border text-xs text-muted-foreground font-mono truncate",children:0===a.length?l("blockViewer.toc.title"):`${l("blockViewer.toc.title")} \xb7 ${a.length}`}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===a.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:l("blockViewer.toc.empty")}):a.map(e=>{let s=t===e.qualifiedName;return(0,n.jsx)(eD.m,{content:`${e.qualifiedName} \xb7 L${e.startLine}`,children:(0,n.jsxs)("button",{onClick:()=>r(e.qualifiedName,e.startLine),className:`w-full text-left px-2 py-1 transition-colors flex items-center gap-1.5 min-w-0 ${s?"bg-brand/15 hover:bg-brand/20":"hover:bg-secondary/60"}`,children:[(0,n.jsx)(eE,{kind:e.kind,qname:e.qualifiedName,className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:`text-xs font-mono truncate ${s?"font-semibold text-brand":""}`,children:e.name})]})},e.qualifiedName)})})]})}var eO=r(96035);function eq({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,onCommentClick:l}){let a=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=a.get(n.endLine);e?e.push(n):a.set(n.endLine,[n])}return 0===a.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(a.entries()).map(([e,r])=>{let a=o+(e-t)*s,i=r[0],c=r.length-1;return(0,n.jsx)(eD.m,{content:1===r.length?i.content:`${r.length} comments — click to view`,children:(0,n.jsxs)("button",{onClick:e=>l(i,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-sm transition-colors",style:{top:`${a+s/2-8}px`},children:[(0,n.jsx)(eO.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 eV(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 eK({addedLines:e,blockRanges:t,viewportRange:r,onJumpToLine:o}){let l,a=(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]),c=(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 d=(e,t)=>{let r=eV(i,e),n=eV(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:a,onClick:e=>{let t=a.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,l=c.find(e=>e.qname===n.qname&&s>=e.start&&s<=e.end);if(l)return void o(l.qname,s);if(c.length>0){let e=Math.max(2,Math.round(.05*i.total)),t=eV(i,s);if(null!==t){let r=null,n=1/0;for(let e of c){let s=eV(i,e.start),o=eV(i,e.end);if(null===s||null===o)continue;let l=t<s?s-t:t>o?t-o:0;l<n&&(r=e,n=l)}if(r&&n<=e){let e=s<r.start?r.start:s>r.end?r.end:s;o(r.qname,e);return}}}let d=i.blocks.find(e=>e.qname===n.qname);d&&o(d.qname,d.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[c.map(e=>{let t=d(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&&((l=d(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:`${l.top}%`,height:`${Math.max(1.2,l.heightPct)}%`}}):null)]})}function eU(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function eJ({symbol:e,fileSource:t,hasChange:r,onHighlighted:o,comments:l,onCommentClick:a,addedLines:i}){let{resolvedTheme:c}=(0,eF.D)(),d=(0,s.useMemo)(()=>(0,C.sQ)(e.filePath),[e.filePath]),[u,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!t)return void m(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,C.kS)()).codeToTokens(n,{lang:d,theme:"dark"===c?"github-dark":"github-light"}).tokens.map((t,r)=>{let n=e.startLine+r,s=i?.has(n)??!1;return`<div class="flex${s?" bg-green-9/15":""}" style="min-width:max-content" data-line="${n}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${n}</span><span class="whitespace-pre">${(0,C.b8)(t)}</span></div>`}).join("");r||(m(s),h(null))}catch(e){r||h(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,d,c,e.filePath,i]),(0,s.useEffect)(()=>{(null!==u||null!==x)&&o(e.qualifiedName)},[u,x,e.qualifiedName,o]),(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 bg-secondary/40 text-xs",children:[(0,n.jsx)(eE,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),(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:[e.kind," \xb7 L",e.startLine,"-",e.endLine]}),(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:`${eX}px`},children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),x&&(0,n.jsx)("span",{className:"text-red-11",children:x}),u&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:u}})]}),l&&l.length>0&&a&&(0,n.jsx)(eq,{comments:l,startLine:e.startLine,endLine:e.endLine,lineHeight:eX,bodyTopOffset:eY+eZ,onCommentClick:a})]})}function eQ({side:e,pin:t,accent:r,onClick:s}){let o,l,a,i,c,d,u,m=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",l="ext",a="text-muted-foreground/60",i=t.name,c=t.packageSpec,d="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",l="method",a="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,c=null,d="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",l="self",a="text-muted-foreground/70",i=t.external.name,c=null,d="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",l=e,a="in"===e?"text-amber-11":"text-green-11",i=t.external.name,c=eU(t.external.filePath),d="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.jsxs)("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 flex items-center gap-1.5`,"data-tooltip":`${d}${u?" \xb7 "+u:""}`,children:[(0,n.jsx)("span",{className:`${a} text-[9px] uppercase tracking-wider font-semibold flex-shrink-0`,children:l}),(0,n.jsxs)("span",{className:"truncate flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:i}),c&&(0,n.jsx)("span",{className:"text-muted-foreground/70 ml-1",children:c}),m>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60 ml-1",children:["\xb7",m,"\xd7"]})]})]})}let eX=18,eY=29,eZ=8;function eG(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 e0(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function e1(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function e2({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:l,onHighlighted:a,comments:i,onCommentClick:c,accentQnames:d,addedLines:u}){let m=function(e,t){if(0===e.length)return[];let r=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)))}});r.sort((e,t)=>e.line-t.line||e.i-t.i);let n=Array(e.length).fill(0),s=-1/0;for(let{i:e,line:o}of r){let r=Math.max(eY+eZ+(o-t.startLine)*eX,s);n[e]=r,s=r+22}return n}(o,e);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:"w-44 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)(eQ,{side:"in",pin:t,accent:e0(t,d),onClick:()=>l(t,e)},eG("in",t)))}),(0,n.jsx)(eJ,{symbol:e,fileSource:t,hasChange:r,onHighlighted:a,comments:i,onCommentClick:c,addedLines:u}),(0,n.jsx)("div",{className:"w-44 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:`${m[r]}px`},children:(0,n.jsx)(eQ,{side:"out",pin:t,accent:e0(t,d),onClick:()=>l(t,e)})},eG("out",t)))})]})}function e5({cwd:e,onSelect:t,onClose:r}){let{t:l}=(0,o.Bd)(),[a,c]=(0,s.useState)(""),[d,u]=(0,s.useState)({files:[],symbols:[]}),[m,x]=(0,s.useState)(0),[f,p]=(0,s.useState)(!1),g=(0,s.useMemo)(()=>[...d.files,...d.symbols],[d]);(0,s.useEffect)(()=>{let t=a.trim();if(!t)return void u({files:[],symbols:[]});p(!0);let r=setTimeout(async()=>{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await i.t4.runPromiseExit((0,h.MB)(r));"Success"===n._tag&&(u(n.value),x(0)),p(!1)},120);return()=>clearTimeout(r)},[a,e]);let b=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==g.length){if("ArrowDown"===e.key)e.preventDefault(),x(e=>Math.min(e+1,g.length-1));else if("ArrowUp"===e.key)e.preventDefault(),x(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=g[m];r&&t(r)}}},[g,m,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-2xl 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)(eb.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:a,onChange:e=>c(e.target.value),onKeyDown:b,placeholder:l("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),f&&(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)(ev.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===g.length&&a&&!f&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:l("blockViewer.search.noResults","No matches")}),(0,n.jsx)(e4,{label:l("blockViewer.search.files","Files"),hits:d.files,startIdx:0,activeIdx:m,onSelect:t,setActive:x}),(0,n.jsx)(e4,{label:l("blockViewer.search.symbols","Symbols"),hits:d.symbols,startIdx:d.files.length,activeIdx:m,onSelect:t,setActive:x})]})]})})}function e4({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:l}){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 a=r+t,i=a===s;return(0,n.jsxs)("button",{onMouseEnter:()=>l(a),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.target.kind?(0,n.jsx)(ej.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(eE,{kind:e.target.symbolKind,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 e3({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:l,enableComments:a=!1,onContentSearch:c,onFocalChange:d,qnameFilter:u,qnameFilterFile:m,accentQnames:h,accentFile:f,addedLines:b,addedLinesFile:y,headerExtraLeft:k,headerExtraRight:N}){let{t:C}=(0,o.Bd)(),[S,M]=(0,s.useState)(null),T=S??t??null;(0,s.useEffect)(()=>{M(null)},[t]),(0,s.useEffect)(()=>{d?.(T)},[T,d]);let{state:$,refresh:P}=eB(e,T),[R,B]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!T)return void B(null);let t=!1;return B(null),(async()=>{let r=new URLSearchParams({cwd:e,path:T}),n=await i.t4.runPromiseExit((0,x.eA)(r));t||("Success"===n._tag?B({content:n.value.content,mtimeMs:n.value.mtimeMs}):console.error("[BlockViewer] failed to load file source for",T,n.cause))})(),()=>{t=!0}},[e,T]);let F=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!R||"ready"!==$.state)return;let e=$.data.mtimeMs;!e||R.mtimeMs<=e||F.current!==R.mtimeMs&&(F.current=R.mtimeMs,P())},[R,$,P]);let[I,D]=(0,s.useState)([]),[A,_]=(0,s.useState)(!1),[W,z]=(0,s.useState)(null),H=(0,s.useRef)(0),O=(0,s.useRef)(0),[q,V]=(0,s.useState)(()=>new Set),K="ready"===$.state?$.data.filePath:null;(0,s.useEffect)(()=>{V(new Set)},[K]);let U=(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(),_(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let J=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;H.current+=1,z({filePath:e,qname:"__imports__",nonce:H.current});return}let r=e1(t),n=e1(e.external);D(e=>e_(e_(e,r),n)),M(n.filePath),H.current+=1,z({filePath:n.filePath,qname:n.qname,nonce:H.current})},[]),Q=(0,s.useCallback)(e=>{M(e.filePath),H.current+=1,z({filePath:e.filePath,qname:e.qname,nonce:H.current})},[]),X=(0,s.useCallback)(e=>{_(!1),M(e.target.filePath),"symbol"===e.target.kind&&(H.current+=1,z({filePath:e.target.filePath,qname:e.target.qualifiedName,line:e.target.line,nonce:H.current}))},[]),Y=(0,s.useCallback)((e,t)=>{T&&(H.current+=1,z({filePath:T,qname:e,line:t,nonce:H.current}))},[T]),[Z,G]=(0,s.useState)(null),[ee,et]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!Z)return;let e=null,t=()=>{e=null;let t=Z.getBoundingClientRect();if(t.height<=0)return;let r=Z.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 l=Number(r),a=Number(o);if(!Number.isFinite(l)||!Number.isFinite(a))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let c=Math.max(0,t.top-i.top),d=Math.min(i.height,t.bottom-i.top),u=a-l+1,m=Math.floor(c/i.height*u),x=Math.ceil(d/i.height*u)-1,h=l+Math.max(0,m),f=l+Math.min(u-1,Math.max(0,x));h<n&&(n=h),f>s&&(s=f)}),n===1/0||s===-1/0?et(null):et(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),Z.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(Z);let s=new MutationObserver(r);return s.observe(Z,{childList:!0,subtree:!0}),()=>{Z.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[Z]);let er=(0,s.useMemo)(()=>{if("ready"!==$.state||!ee)return null;let e=$.data.functions;if(0===e.length)return null;let t=(ee.start+ee.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<=ee.start&&(!r||t.startLine>r.startLine)&&(r=t);return r?.qualifiedName??null},[$,ee]),en=a&&!!e&&!!T,es=(0,v.r)(),{comments:eo,addComment:el,updateComment:ea,deleteComment:ei,refresh:ec}=(0,p._)({cwd:e,filePath:T??""}),[ed,eu]=(0,s.useState)(null),{toolbarRef:em,bumpRef:ex,clearToolbar:eh}=(0,E.L)({enabled:en,container:ed,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||!ed||!ed.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=R?.content;return r?r.split("\n").slice(e-1,t).join("\n"):""}}),[ef,ep]=(0,s.useState)(null),[eg,eb]=(0,s.useState)(null),[ev,ej]=(0,s.useState)(null),ew=(0,s.useCallback)(()=>{let e=em.current;e&&(ep({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),eh())},[eh,em]),ey=(0,s.useCallback)(()=>{let e=em.current;e&&(eb({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),eh())},[eh,em]),ek=(0,s.useCallback)(()=>{let e=em.current;if(!e||!c)return;let t=e.selectedText.trim();eh(),t&&c(t)},[c,eh,em]),eN=(0,s.useCallback)(async e=>{ef&&(await el(ef.range.start,ef.range.end,e,ef.selectedText),ep(null))},[ef,el]),eC=(0,s.useCallback)(async t=>{if(eg&&es&&e&&T)try{let r=(await (0,g.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:T,startLine:eg.range.start,endLine:eg.range.end,codeContent:eg.lineSnapshot});let n=(0,g.Gw)(r,t);es.sendMessage(n),await (0,g.RP)(e),ec(),eb(null)}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[eg,es,e,T,ec]),eS=(0,s.useCallback)((e,t)=>{t.stopPropagation(),ej({comment:e,x:t.clientX,y:t.clientY}),eh(),ep(null),eb(null)},[eh]);if((0,s.useEffect)(()=>{let e;if(!W||O.current>=W.nonce||"ready"!==$.state||!R||$.data.filePath!==W.filePath)return;if(m&&m===$.data.filePath&&u){let t=0;for(let e of $.data.functions)u.has(e.qualifiedName)&&t++;e=Math.max(1,t)}else e=Math.max(1,$.data.functions.length);if(q.size<e)return;O.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,$,R,q,u,m]),!T)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e8,{focalFile:null,fileCount:null,onSwitchToCode:l,onSearch:()=>_(!0),onRefresh:P,refreshDisabled:!0,extraLeft:k,extraRight:N}),(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:C("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:C("blockViewer.empty.hint","or press ⌘K to search.")})]}),A&&(0,n.jsx)(e5,{cwd:e,onSelect:X,onClose:()=>_(!1)})]});if("idle"===$.state||"loading"===$.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e8,{focalFile:T,fileCount:null,onSwitchToCode:l,onSearch:()=>_(!0),onRefresh:P,refreshDisabled:!0,extraLeft:k,extraRight:N}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:C("blockViewer.fileMode.loading","Loading…")})]});if("notFound"===$.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e8,{focalFile:T,fileCount:null,onSwitchToCode:l,onSearch:()=>_(!0),onRefresh:P,extraLeft:k,extraRight:N}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:C("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),A&&(0,n.jsx)(e5,{cwd:e,onSelect:X,onClose:()=>_(!1)})]});if("error"===$.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e8,{focalFile:T,fileCount:null,onSwitchToCode:l,onSearch:()=>_(!0),onRefresh:P,extraLeft:k,extraRight:N}),(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:$.message}),(0,n.jsx)("button",{onClick:P,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:C("blockViewer.retry","Retry")})]})]});let eL=$.data,eE=eL.functions;if(0===eE.length&&R){let e=Math.max(1,R.content.split("\n").length);eE=[{filePath:eL.filePath,qualifiedName:"__file__",name:eU(eL.filePath),kind:"unknown",startLine:1,endLine:e}]}let eM=m&&m===eL.filePath,eT=f&&f===eL.filePath,e$=y&&y===eL.filePath;eM&&u&&(eE=eE.filter(e=>u.has(e.qualifiedName)));let eP=eT?h:void 0,eR=e$?b:void 0,eF=e6(eL.upstreamCalls),eI=e6(eL.downstreamCalls),eD=new Map(eE.map(e=>[e.qualifiedName,e])),eW=new Map,ez=new Map;for(let e of eL.intraCalls){let t=eD.get(e.to),r=eD.get(e.from);if(t){let r=eW.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):eW.set(e.from,[n])}if(r){let t=ez.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):ez.set(e.to,[n])}}let eO=new Map;for(let e of eL.externalCalls??[]){let t=eO.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):eO.set(e.focalQname,[r])}let eq=new Map;for(let e of eL.methodCalls??[]){let t=eq.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):eq.set(e.focalQname,[r])}let eV=r.has(eL.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(e8,{focalFile:T,fileCount:eL.fileCount,functionCount:eL.functions.length,upstreamCount:eL.upstreamCalls.length,downstreamCount:eL.downstreamCalls.length,onSwitchToCode:l,onSearch:()=>_(!0),onRefresh:P,extraLeft:k,extraRight:N}),(0,n.jsxs)("div",{ref:eu,className:"flex-1 relative min-h-0 flex",children:[(0,n.jsx)(eH,{functions:eE,currentQname:er,onSelect:Y}),(0,n.jsx)("div",{ref:G,className:"flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:eE.map(e=>{let t,r,s,o,l,a;return(0,n.jsx)(e2,{symbol:e,fileSource:R?.content??null,hasChange:eV,upstream:(t=eF.get(e.qualifiedName),r=ez.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=eI.get(e.qualifiedName),o=eW.get(e.qualifiedName),l=eq.get(e.qualifiedName),a=eO.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...l??[],...a??[]]),onPinClick:J,onHighlighted:U,comments:en?eo:void 0,onCommentClick:en?eS:void 0,accentQnames:eP,addedLines:eR},e.qualifiedName)})})}),en&&ed&&(0,n.jsx)(j.f,{floatingToolbarRef:em,bumpRef:ex,container:ed,onAddComment:ew,onSendToAI:ey,onSearch:c?ek:void 0,isChatLoading:es?.isLoading}),en&&ef&&(0,n.jsx)(w.t,{x:ef.x,y:ef.y,range:ef.range,lineSnapshot:ef.lineSnapshot,container:ed,onSubmit:eN,onClose:()=>ep(null)}),en&&eg&&T&&(0,n.jsx)(w.G,{x:eg.x,y:eg.y,range:eg.range,filePath:T,lineSnapshot:eg.lineSnapshot,container:ed,onSubmit:eC,onClose:()=>eb(null),isChatLoading:es?.isLoading}),en&&ev&&(0,n.jsx)(L.t,{x:ev.x,y:ev.y,comment:ev.comment,container:ed,onClose:()=>ej(null),onUpdateComment:ea,onDeleteComment:ei}),eR&&eR.size>0&&eE.length>0&&(0,n.jsx)(eK,{addedLines:eR,blockRanges:eE.map(e=>({qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine})),viewportRange:ee,onJumpToLine:Y}),(0,n.jsx)(eA,{entries:I,onSelect:Q,onClear:()=>D([])}),A&&(0,n.jsx)(e5,{cwd:e,onSelect:X,onClose:()=>_(!1)})]})]})}function e6(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 e8({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:l,onSwitchToCode:a,onSearch:i,onRefresh:c,refreshDisabled:d,extraLeft:u,extraRight:m}){let{t:x}=(0,o.Bd)(),h={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:l??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between bg-secondary/30 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 l&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",l," 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)(eb.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:c,disabled:d,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)(ew.A,{className:"w-3 h-3"})}),a&&(0,n.jsx)("button",{onClick:a,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:"Code"})]})]})}function e9(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 e7(e){return e.replace(/\s+/g," ").trim()}function te(e,t){return e?`${e}>${t}`:t}function tt(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 tr(e,t,r,n,s=[],o){return{qualifiedName:te(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:e9(e7(e.text)),children:s,params:o}}function tn(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}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";default:return null}}var to=r(14066);let tl="/tree-sitter",ta=null,ti=new Map;async function tc(e){let t,r=await (!(t=ti.get(e))&&(t=(async()=>(await (!ta&&(ta=to.iX.init({locateFile:e=>`${tl}/${e}`})),ta),to.TM.load(`${tl}/tree-sitter-${e}.wasm`)))(),ti.set(e,t)),t),n=new to.iX;return n.setLanguage(r),n}function td(e){return e.qualifiedName.startsWith("__code_")||e.qualifiedName.startsWith("__heading_")}function tu(e){return!td(e)&&"__file__"!==e.qualifiedName}async function tm(e,t){if(!e)return[];let r=ts(t);if(!r)return null;let n=(await tc(r)).parse(e);if(!n)return null;try{return function(e){let t=[],r=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)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,contentHash:e9(e7(t.map(e=>e.text).join("\n"))),children:[]}}(e);r&&t.push(r);for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);n&&t.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[tr(t,tt(t),"function",r,[],tn(t))];case"class_declaration":case"abstract_class_declaration":{let e=tt(t),n=te(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(tr(s,tt(s),"method",t,[],tn(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(tr(s,tt(s),"method",t,[],tn(e)))}}}return r}(t.childForFieldName("body"),n);return[tr(t,e,"class",r,s)]}case"interface_declaration":return[tr(t,tt(t),"interface",r)];case"type_alias_declaration":return[tr(t,tt(t),"type",r)];case"enum_declaration":return[tr(t,tt(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"),l=s.childForFieldName("value");if(!o)continue;let a=o.text,i=l&&("arrow_function"===l.type||"function_expression"===l.type),c=i&&l?tn(l):void 0;if(r.push(tr(e,a,i?"function":"const",t,[],c)),l&&"object"===l.type&&!i){let e=t?`${t}>${a}`:a;for(let t=0;t<l.namedChildCount;t++){let n=l.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(tr(n,t.text,"method",e,[],tn(s)))}else if("method_definition"===n.type){let t=tt(n);t&&r.push(tr(n,t,"method",e,[],tn(n)))}}}}}return r}(t,r);case"class_definition":{let e=tt(t),n=te(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(tr(o,tt(o),"method",r,[],tn(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...tr(t,tt(t),"method",r,[],tn(t)),startLine:o.startPosition.row+1,contentHash:e9(e7(o.text))});else if(t?.type==="class_definition"){let s=tt(t),l=te(r,s),a=e(t.childForFieldName("body"),l);n.push({...tr(t,s,"class",r,a),startLine:o.startPosition.row+1,contentHash:e9(e7(o.text))})}}else if("class_definition"===o.type){let t=tt(o),s=te(r,t),l=e(o.childForFieldName("body"),s);n.push(tr(o,t,"class",r,l))}}}return n}(t.childForFieldName("body"),n);return[tr(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:e9(e7(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:te(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:e9(e7(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,l=[];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)&&l.push(t)}}if(0===l.length||!o)return[];let a=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=a?`${a} ${o}`:o;return l.map((e,r)=>tr(e,l.length>1?`${i} #${r+1}`:i,"function",t,[],tn(e)))}(t,r)),e}default:return[]}}(n,void 0,!1))}return t.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=[],l=(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,contentHash:e9(e7(s)),children:[]})},a=-1;for(let e=1;e<=n;e++)s[e]?a>=0&&(l(a,e-1),a=-1):a<0&&(a=e);return a>=0&&l(a,n),o}(e,t)),t}(n.rootNode)}finally{n.delete()}}async function tx(e,t,r,n,s){let o=new Set;if(e!==t)for(let r of y(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum&&o.add(r.newLineNum);if(!ts(r))return{addedLines:o};let[l,a]=await Promise.all([tm(n?"":e,r),tm(s?"":t,r)]),i=a??[],c=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}((l??[]).filter(tu),i.filter(tu)),d=new Set;for(let e of c)"deleted"!==e.changeKind&&d.add(e.qname);for(let e of function(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(td(n)){for(let e of t)if(e>=n.startLine&&e<=n.endLine){r.push(n.qualifiedName);break}}return r}(i,o))d.add(e);return{changedQnames:d,addedLines:o}}function th({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:l=!1,isDeleted:a=!1,changedFiles:i,fileGitStatusMap:c,enableComments:d=!1,onContentSearch:u,headerExtraLeft:m,headerExtraRight:x}){let[h,f]=(0,s.useState)(t);(0,s.useEffect)(()=>{f(t)},[t]);let[p,g]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return g(null),(async()=>{try{let s=await tf(h,t,r,o,l,a,i,c,e);if(n||!s)return;let d=await tx(s.oldContent,s.newContent,h,s.isNew,s.isDeleted);if(n)return;g(d)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[h,t,r,o,l,a,i,c,e]),(0,n.jsx)(e3,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:d,qnameFilter:p?.changedQnames,qnameFilterFile:h,accentQnames:p?.changedQnames,accentFile:h,addedLines:p?.addedLines,addedLinesFile:h,onFocalChange:e=>e&&f(e),onContentSearch:u,headerExtraLeft:m,headerExtraRight:x})}async function tf(e,t,r,n,s,o,l,a,c){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!l.has(e))return null;let d=a?.get(e);if(!d)return null;let u=new URLSearchParams({cwd:c,file:e,type:d}),m=await i.t4.runPromiseExit((0,h.oh)(u));if("Success"!==m._tag)return null;let x=m.value;return{oldContent:x.oldContent,newContent:x.newContent,isNew:x.isNew??!1,isDeleted:x.isDeleted??!1}}function tp(e){let{refreshKey:t,className:r="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:l}=e,a="absPath"in e&&"string"==typeof e.absPath,c=a?void 0:e.cwd,d=a?void 0:e.path,u=a?e.absPath:void 0,[m,h]=(0,s.useState)({kind:"loading"}),f=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++f.current;return h({kind:"loading"}),(async()=>{if(a){if(e!==f.current)return;h({kind:"ready",etag:null,size:0});return}let t=await i.t4.runPromiseExit((0,x.r6)(c,d));if(e!==f.current)return;if("Failure"===t._tag){let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause;h({kind:"error",message:r instanceof Error?r.message:"Unknown error"});return}let r=t.value;if(!r.ok)return h({kind:"error",message:`stat failed (${r.status})`});let n=r.data;n&&n.exists?"too-large"===n.category?h({kind:"too-large",size:n.size??0}):"image"!==n.category?h({kind:"error",message:`Not an image (${n.category})`}):h({kind:"ready",etag:n.etag||`t-${n.mtimeMs??Date.now()}`,size:n.size??0}):h({kind:"missing"})})(),()=>{f.current++}},[a,c,d,u,t]),"loading"===m.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===m.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===m.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(m.size/1024/1024)," MB)"]})});if("error"===m.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-red-11",children:m.message})});let p=a?`/api/file?path=${encodeURIComponent(u)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(c)}&path=${encodeURIComponent(d)}&v=${encodeURIComponent(m.etag)}`;return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("img",{src:p,alt:l??(d||u),className:o})})}function tg({cwd:e,selected:t,diff:r,showMarkdownPreview:l,setShowMarkdownPreview:a,changedFiles:i,fileGitStatusMap:c,onContentSearch:d,locateInTree:u,jsonPreview:m,setJsonPreview:x,jsonPreviewSearch:h,jsonPreviewPreRef:f}){let{t:p}=(0,o.Bd)(),[g,b]=(0,s.useState)("file"),[v,j]=(0,s.useState)("compact"),w=t.file.path,y=(0,ea.u)(w),{state:N}=eB(e,w),C=(0,s.useMemo)(()=>{if("ready"===N.state)return N.data.functions.filter(ez).map(e=>({name:e.name,startLine:e.startLine,endLine:e.endLine,params:e.params}))},[N]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[y||"map"!==g?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:w}),(0,n.jsx)(eD.m,{content:p("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${w}`),(0,k.oR)(p("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent 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)(eD.m,{content:p("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(w)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent 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"}),!y&&"file"===g&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["compact","full"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),j(e)},className:`px-2 py-0.5 text-xs transition-colors ${v===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:p("compact"===e?"diffViewer.compact":"diffViewer.full")},e))}),!y&&(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(),b(e)},className:`px-2 py-0.5 text-xs transition-colors ${g===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:p("file"===e?"common.file":"common.codeMap")},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:y?(0,n.jsx)(tp,{cwd:e,path:w,className:"p-4 flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:w}):(0,n.jsx)(T,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,compact:"compact"===v,symbols:C,onPreview:!r.isDeleted&&Z(w)?()=>a(!0):!r.isDeleted&&w.endsWith(".json")?()=>x({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:w.endsWith(".json")?p("common.readable"):p("common.preview"),onContentSearch:d})})]}):(0,n.jsx)(th,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:c,enableComments:!0,onContentSearch:d,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=c.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(eD.m,{content:p("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,k.oR)(p("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent 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)(eD.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-accent 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.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(),b(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${g===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:p("file"===e?"common.file":"common.codeMap")},e))})}),l&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>a(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(ex,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>a(!1)})})}),m&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>x(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl 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:m.filePath}),(0,n.jsx)("button",{onClick:()=>x(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent 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)(et,{search:h}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:f,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:H(m.content)})})]})})]})}function tb({branches:e,selectedBranch:t,onSelect:r,isLoading:l,pinnedBranches:a=[]}){let{t:i}=(0,o.Bd)(),[c,d]=(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)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{c&&h.current&&h.current.focus()},[c]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=a.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),d(!1),m("")};return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>d(!c),disabled:l,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-slate-9 transition-transform ${c?"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"})})]}),c&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lg 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 placeholder-slate-9"})}),(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-accent 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-secondary 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-accent 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-secondary 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-accent 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")})]})]})]})}function tv(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 tj=(e,t)=>eM.tryPromise({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 eT.uV({message:`${e} failed`,cause:t})});function tw(e){return e.replace(/^\([^)]+\)\s*/,"")}let ty=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:l,container:a,onMouseEnter:i,onMouseLeave:c,onFindReferences:d,onSearch:u},m){let{t:x}=(0,o.Bd)(),h=(0,s.useRef)(null);(0,s.useImperativeHandle)(m,()=>h.current,[]);let f=a.getBoundingClientRect(),p=r-f.left,g=l-f.top,b=(0,s.useMemo)(()=>tw(e),[e]),v=(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,l=0,a=/\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=a.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},l++));let a=t[0];/^["']/.test(a)?s.push((0,n.jsx)("span",{className:"text-green-400",children:a},l++)):/^\d+$/.test(a)?s.push((0,n.jsx)("span",{className:"text-orange-300",children:a},l++)):r.test(a)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-pink-400",children:a},l++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:a},l++)),o=t.index+a.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},l++)),s})(b),[b]);return(0,s.useEffect)(()=>{if(!h.current)return;let e=h.current,t=a.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=l-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,l,a]),(0,n.jsxs)("div",{ref:h,className:"absolute z-[200] max-w-lg bg-card border border-border rounded-lg shadow-xl px-3 py-2 pointer-events-none",style:{left:p,top:g},children:[(0,n.jsx)("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all leading-relaxed",children:v}),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})]}),(d||u)&&(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:c,children:[d&&(0,n.jsx)("button",{onClick:d,className:"text-[11px] text-brand hover:underline cursor-pointer",children:x("hoverTooltip.findReferences")}),u&&(0,n.jsx)("button",{onClick:()=>u(function(e){let t=tw(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]}(e)),className:"text-[11px] text-brand hover:underline cursor-pointer",children:x("hoverTooltip.search")})]})]})]})});function tk({references:e,loading:t,onSelect:r,onClose:l}){let{t:a}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(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=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,C.kS)();if(t!==l.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let l=(0,C.sQ)(r.file);if("text"!==l)try{let e=n.codeToTokens(r.lineText,{lang:l,theme:s}),a=(0,C.b8)(e.tokens[0]||[]);a&&o.set(t,a)}catch{}}t===l.current&&r(o)})()},[e,n]),t}(e),c=[],d=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=d.get(r.file);void 0===n&&(n=c.length,d.set(r.file,n),c.push({file:r.file,items:[]})),c[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary 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:[a("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:l,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(ev.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:a("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:a("references.notFound")}):c.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/30 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-accent/50 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 tN({results:e,loading:t,totalMatches:r,onSelect:l,onClose:a}){let{t:i}=(0,o.Bd)(),c=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(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=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,C.kS)(),o=new Map;for(let t of e){let e=(0,C.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let l=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),a=(0,C.b8)(t.tokens[0]||[]);a&&o.set(l,a)}catch{}}}t===l.current&&r(o)})()},[e,n]),t}(e);return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary 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:[i("searchResults.title")," ",!t&&i("searchResults.nMatches",{count:r})]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(ev.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:i("searchResults.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:i("searchResults.noResults")}):e.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/30 sticky top-0",children:e.path}),e.matches.map((t,r)=>{let s=`${e.path}:${t.lineNumber}`,o=c.get(s);return(0,n.jsxs)("button",{onClick:()=>l(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 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 tC=r(63728);function tS({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:l,initialSearchQuery:a,searchQueryTrigger:c}){var d;let f,p,g,v,j,w,{t:y}=(0,o.Bd)(),{activeView:N}=(0,tC.R8)(),[C,S]=(0,s.useState)(r),[L,E]=(0,s.useState)("code"),M=(0,s.useRef)(null),$=(0,s.useRef)(!1),[P,R]=(0,s.useState)(null),[B,F]=(0,s.useState)(null),[I,O]=(0,s.useState)(!1),q=(0,s.useRef)(1),V=(0,s.useRef)(null),[K,U]=(0,s.useState)(null),J=(0,s.useRef)(null),[Q,X]=(0,s.useState)({isDirty:!1,isSaving:!1}),[Y,G]=(0,s.useState)(!1),[en,es]=(0,s.useState)(!1),[ei,ec]=(0,s.useState)(null),ed=(0,s.useRef)(null),eu=ee(ed),em=(0,s.useRef)(null),eh=ee(em),eb=function(e){let[t,r]=(0,s.useState)(!1);return{goToDefinition:(0,s.useCallback)(async(t,n,s)=>{r(!0);let o=await i.t4.runPromiseExit(tj("/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),ev=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),l=(0,s.useRef)(0),a=(0,s.useRef)(!1),c=(0,s.useRef)(null),d=(0,s.useRef)({x:0,y:0}),u=(0,s.useCallback)(e=>{c.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 m=(0,s.useRef)(!1),x=(0,s.useRef)(null),h=(0,s.useCallback)(()=>{let e=c.current;e&&m.current&&(e.style.pointerEvents="none"),m.current=!1,x.current&&(c.current?.removeEventListener("mouseleave",x.current),x.current=null)},[]),f=(0,s.useCallback)(()=>{let e=c.current;if(!e||m.current)return;m.current=!0,a.current=!0,e.style.pointerEvents="auto";let t=()=>{a.current=!1,h(),l.current++,r(null)};x.current=t,e.addEventListener("mouseleave",t)},[h]),p=(0,s.useCallback)((t,s,a,c)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let d=++l.current;n.current=setTimeout(async()=>{let n=await i.t4.runPromiseExit(tj("/api/lsp/hover",{cwd:e,filePath:t,line:s,column:a}));if(d!==l.current||"Success"!==n._tag)return;let o=n.value.hover;o&&o.displayString&&r({...o,x:c.x,y:c.y,filePath:t,line:s,column:a})},300)},[e]),g=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),l.current++,o.current=setTimeout(function(){if(a.current)return;let e=c.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)(()=>{a.current=!0,o.current&&clearTimeout(o.current)},[]),v=(0,s.useCallback)(()=>{a.current=!1,l.current++,r(null)},[]),j=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),a.current=!1,h(),l.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:u}}(t),ej=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[l,a]=(0,s.useState)(!1);return{references:t,loading:n,visible:l,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),a(!0);let l=await i.t4.runPromiseExit(tj("/api/lsp/references",{cwd:e,filePath:t,line:n,column:s}));"Success"===l._tag?r(l.value.references??[]):(console.error("[useLSP] references error:",l.cause),r([])),o(!1)},[e]),closeReferences:(0,s.useCallback)(()=>{a(!1),r([])},[])}}(t),ew=(f=(0,s.useRef)([]),p=(0,s.useRef)([]),g=(0,s.useCallback)(e=>{f.current.push(e),f.current.length>50&&(f.current=f.current.slice(-50)),p.current=[]},[]),v=(0,s.useCallback)(e=>{if(0===f.current.length)return null;let t=f.current.pop();return p.current.push(e),p.current.length>50&&(p.current=p.current.slice(-50)),t},[]),j=(0,s.useCallback)(e=>{if(0===p.current.length)return null;let t=p.current.pop();return f.current.push(e),f.current.length>50&&(f.current=f.current.slice(-50)),t},[]),{push:g,goBack:v,goForward:j,canGoBack:(0,s.useCallback)(()=>f.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>p.current.length>0,[])}),ey=(0,eg.F)(),ek=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[l,a]=(0,s.useState)(new Set),[c,d]=(0,s.useState)([]),[u,m]=(0,s.useState)(null),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(""),[y,k]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[S,L]=(0,s.useState)(!1),[E,M]=(0,s.useState)(!1),[T,$]=(0,s.useState)(null),P=(0,s.useRef)(null),[R,B]=(0,s.useState)(!1),[F,I]=(0,s.useState)(null),[D,A]=(0,s.useState)("center"),[_,W]=(0,s.useState)(null),[z,H]=(0,s.useState)(null),[O,q]=(0,s.useState)(!1),[V,K]=(0,s.useState)([]),[U,J]=(0,s.useState)(!1),[Q,X]=(0,s.useState)(null),[Y,Z]=(0,s.useState)(null),[G,ee]=(0,s.useState)(!1),[et,er]=(0,s.useState)(!1),en=(0,s.useMemo)(()=>c.map(e=>e.path).filter(Boolean),[c]),es=(0,s.useMemo)(()=>(0,ea.v3)(en),[en]),eo=(0,s.useMemo)(()=>new Set((0,ea.tW)(es)),[es]),el=(0,s.useMemo)(()=>j?n?(0,ea.KH)(n,j,y):(0,ea.q3)(t,j,y):null,[t,n,j,y]);(0,s.useEffect)(()=>{if(!el||0===el.size)return void v(null);let e=new Set;if(n){let t=new Set(n);for(let r of el)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&el.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}v(e)},[el,t,n]);let ei=b??p,ec=(0,s.useRef)(null),ed=(0,s.useCallback)(t=>{ec.current&&clearTimeout(ec.current),ec.current=setTimeout(()=>{i.t4.runFork((0,x.Ft)(e,Array.from(t)).pipe(eM.tapError(e=>eM.sync(()=>console.error("Error saving expanded paths:",e))),eM.orElse(()=>eM.void)))},500)},[e]),eu=(0,s.useCallback)(async()=>{L(!0),$(null),await i.t4.runPromise((0,x.mP)(e).pipe(eM.match({onSuccess:e=>{e.error?$(e.error):(r(e.files??[]),e.expandedPaths&&Array.isArray(e.expandedPaths)&&g(new Set(e.expandedPaths)))},onFailure:e=>{console.error("Error loading files:",e),$("Failed to load files")}}))),L(!1)},[e]),em=(0,s.useCallback)(()=>{i.t4.runPromise((0,x.DZ)(e).pipe(eM.match({onSuccess:e=>{e.paths&&o(e.paths)},onFailure:e=>{console.error("Error loading file index:",e)}})))},[e]),ex=(0,s.useCallback)(async t=>{a(e=>new Set([...e,t])),await i.t4.runPromise((0,x.gZ)(e,t).pipe(eM.match({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,ea.MB)(n,t);return s&&(s.children=e.children),n})},onFailure:e=>{console.error("Error loading directory:",e)}}))),a(e=>{let r=new Set(e);return r.delete(t),r})},[e]),eh=(0,s.useRef)(l);eh.current=l,(0,s.useEffect)(()=>{for(let e of b??p){let r=(0,ea.MB)(t,e);r&&r.isDirectory&&!r.children&&!eh.current.has(e)&&ex(e)}},[t,p,b,ex]);let ef=(0,s.useCallback)(async()=>{await i.t4.runPromise((0,x.r9)(e).pipe(eM.match({onSuccess:e=>d(e.files??[]),onFailure:e=>console.error("Error loading recent files:",e)})))},[e]),ep=(0,s.useCallback)(async t=>{d(e=>{let r=e.filter(e=>e.path!==t);return[{path:t},...r].slice(0,15)}),await i.t4.runPromise((0,x.YW)(e,t).pipe(eM.tapError(e=>eM.sync(()=>console.error("Error adding to recent files:",e))),eM.orElse(()=>eM.void)))},[e]),eg=(0,s.useCallback)((t,r,n,s)=>{d(e=>e.map(e=>e.path===t?{...e,scrollLine:r,cursorLine:n,cursorCol:s}:e)),i.t4.runFork((0,x.YW)(e,t,{scrollLine:r,cursorLine:n,cursorCol:s}).pipe(eM.orElse(()=>eM.void)))},[e]),eb=(0,s.useCallback)(e=>c.find(t=>t.path===e),[c]),ev=(0,s.useCallback)(async t=>{let r=t||u;r&&(J(!0),X(null),await i.t4.runPromise((0,x.eE)(e,r).pipe(eM.match({onSuccess:e=>{e.error?X(e.error):K(e.blame??[])},onFailure:e=>{console.error("Error loading blame:",e),X("Failed to load blame info")}}))),J(!1))},[e,u]),ej=(0,s.useCallback)(async t=>{M(!0),f(null),q(!1),K([]),X(null),Z(null);let r=eM.gen(function*(){let r=yield*(0,x.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"binary":return{type:"binary",message:"Cannot preview binary file",size:n.size,mtime:n.mtimeMs};case"too-large":return{type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs};default:{let r=yield*(0,x.K9)(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 i.t4.runPromise(r.pipe(eM.match({onSuccess:e=>f(e),onFailure:e=>{console.error("Error loading file content:",e),f({type:"error",message:"Failed to load file"})}}))),ep(t),ev(t),M(!1)},[e,ep,ev]),ew=(0,s.useCallback)(()=>{O?q(!1):(q(!0),0===V.length&&ev())},[O,V.length,ev]),ey=(0,s.useCallback)((e,t)=>{if(!e)return;if(m(e),I(t??null),null==t){let t=c.find(t=>t.path===e);t?.scrollLine?(I(t.scrollLine),A("start"),W(t.cursorLine??null),H(t.cursorCol??null)):(A("center"),W(null),H(null))}else A("center"),W(null),H(null);ej(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("/"));g(t=>{let r=new Set(t),n=!1;for(let t of e)r.has(t)||(r.add(t),n=!0);return n&&ed(r),n?r:t})}},[ej,ed,c]),ek=(0,s.useCallback)(e=>{if(b)v(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r});else{let r=!p.has(e);if(g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),ed(r),r}),r){let r=(0,ea.MB)(t,e);r&&r.isDirectory&&!r.children&&ex(e)}}},[b,ed,p,t,ex]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:l,expandedPaths:p,setExpandedPaths:g,searchTreeExpandedPaths:b,setSearchTreeExpandedPaths:v,effectiveExpandedPaths:ei,searchQuery:j,setSearchQuery:w,searchExactMatch:y,setSearchDirExact:k,matchedPaths:el,creatingItem:N,setCreatingItem:C,isLoadingFiles:S,fileError:T,searchInputRef:P,shouldScrollToSelected:R,setShouldScrollToSelected:B,targetLineNumber:F,setTargetLineNumber:I,targetScrollAlign:D,setTargetScrollAlign:A,initialCursorLine:_,initialCursorCol:z,setInitialCursorLine:W,setInitialCursorCol:H,selectedPath:u,setSelectedPath:m,fileContent:h,setFileContent:f,isLoadingContent:E,recentFiles:c,recentFilePaths:en,setRecentFiles:d,recentFilesTree:es,recentTreeDirPaths:eo,showBlame:O,setShowBlame:q,blameLines:V,isLoadingBlame:U,blameError:Q,blameSelectedCommit:Y,setBlameSelectedCommit:Z,showMarkdownPreview:G,setShowMarkdownPreview:ee,showEditor:et,setShowEditor:er,saveExpandedPaths:ed,loadFiles:eu,loadFileIndex:em,loadDirectory:ex,loadRecentFiles:ef,addToRecentFiles:ep,updateRecentFilePosition:eg,getRecentFilePosition:eb,loadFileContent:ej,loadBlame:ev,handleToggleBlame:ew,handleSelectFile:ey,handleToggle:ek}}({cwd:t});d=ek.selectedPath,w=(0,s.useRef)(null),(0,s.useEffect)(()=>{d&&d!==w.current&&tv(d)&&(w.current=d,i.t4.runFork(tj("/api/lsp/warmup",{cwd:t,filePath:d}).pipe(eM.asVoid).pipe(eM.orElse(()=>eM.void))))},[t,d]);let eN=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,l]=(0,s.useState)([]),[a,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)(null),[m,x]=(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){l([]),g(null);return}if(n.length<2)return void u(z.A.t("fileBrowser.searchMinChars"));c(!0),u(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=eM.tryPromise({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 eT.uV({message:"content search failed",cause:e})});await i.t4.runPromise(o.pipe(eM.match({onSuccess:e=>{l(e.results),g({totalFiles:e.totalFiles,totalMatches:e.totalMatches,truncated:e.truncated}),x(new Set(e.results.map(e=>e.path))),e.results.length>0&&t?.()},onFailure:e=>{u(e.cause instanceof Error?e.cause.message:"Search failed"),l([])}}))),c(!1)},[e,h,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:a,searchError:d,searchExpandedPaths:m,searchOptions:h,setSearchOptions:f,searchStats:p,contentSearchInputRef:b,performContentSearch:v,handleSearchToggle:(0,s.useCallback)(e=>{x(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>G(!0)}),eC=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(!1),[a,c]=(0,s.useState)(null),[d,u]=(0,s.useState)(null),[m,x]=(0,s.useState)(null),[f,p]=(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(_(w));for(let t of g)e.delete(t);return e},[w,g]),L=(0,s.useMemo)(()=>{let e=new Set(_(N));for(let t of v)e.delete(t);return e},[N,v]),[E,M]=(0,s.useState)(!1),[T,$]=(0,s.useState)(0),P=(0,s.useCallback)(async()=>{l(!0),c(null),await i.t4.runPromise((0,h.lv)(e).pipe(eM.match({onSuccess:e=>{n(e);let t=A(e.staged),r=A(e.unstaged);y(t),C(r)},onFailure:e=>{c(e.cause instanceof Error?e.cause.message:"Unknown error")}}))),l(!1)},[e]),R=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),B=(0,s.useCallback)(e=>{j(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),F=(0,s.useCallback)((e,r)=>{u({file:e,type:r}),t(e.path)},[t]),I=(0,s.useCallback)(async(e,t,r,n)=>{let s=await i.t4.runPromiseExit(e);"Success"===s._tag?(await P(),(0,k.oR)(t,"success")):(console.error(r,s.cause),(0,k.oR)(n,"error"))},[P]),D=(0,s.useCallback)(t=>I((0,h.Iz)(e,[t]),z.A.t("toast.staged"),"Error staging file:",z.A.t("toast.stageFailed")),[e,I]),W=(0,s.useCallback)(t=>I((0,h.X0)(e,[t]),z.A.t("toast.unstaged"),"Error unstaging file:",z.A.t("toast.unstageFailed")),[e,I]),H=(0,s.useCallback)(async t=>{0!==t.length&&await I((0,h.Iz)(e,t),z.A.t("toast.stagedNFiles",{count:t.length}),"Error staging files:",z.A.t("toast.stageFailed"))},[e,I]),O=(0,s.useCallback)(async t=>{0!==t.length&&await I((0,h.X0)(e,t),z.A.t("toast.unstagedNFiles",{count:t.length}),"Error unstaging files:",z.A.t("toast.unstageFailed"))},[e,I]),q=(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=eM.gen(function*(){r.length>0&&(yield*(0,h.Ub)(e,r,!0)),n.length>0&&(yield*(0,h.Ub)(e,n,!1))});await I(s,z.A.t("toast.discardedNFiles",{count:t.length}),"Error discarding files:",z.A.t("toast.discardFailed"))},[e,I]),V=(0,s.useCallback)(async()=>{r?.unstaged.length&&await I((0,h.Iz)(e,r.unstaged.map(e=>e.path)),z.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"Error staging all files:",z.A.t("toast.stageFailed"))},[e,r,I]),K=(0,s.useCallback)(async()=>{r?.staged.length&&await I((0,h.X0)(e,r.staged.map(e=>e.path)),z.A.t("toast.unstagedNFiles",{count:r.staged.length}),"Error unstaging all files:",z.A.t("toast.unstageFailed"))},[e,r,I]),U=(0,s.useCallback)(async t=>{let r="untracked"===t.status;await I((0,h.Ub)(e,[t.path],r),r?z.A.t("toast.deletedFile"):z.A.t("toast.discardedChanges"),"Error discarding file:",z.A.t("toast.discardFailed"))},[e,I]),J=(0,s.useCallback)(async()=>{if(!r?.unstaged.length||!await (0,k.lJ)(z.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=eM.gen(function*(){n.length>0&&(yield*(0,h.Ub)(e,n,!1)),t.length>0&&(yield*(0,h.Ub)(e,t,!0))});await I(o,z.A.t("toast.discardedNFiles",{count:s}),"Error discarding all:",z.A.t("toast.discardFailed"))},[e,r,I]);return(0,s.useEffect)(()=>{d?(p(!0),i.t4.runPromiseExit((0,h.w2)(e,d.file.path,d.type)).then(e=>{"Success"===e._tag?x(e.value):console.error("Error fetching diff:",e.cause),p(!1)})):x(null)},[d,e,T]),{status:r,setStatus:n,statusLoading:o,statusError:a,statusSelectedFile:d,statusDiff:m,statusDiffLoading:f,stagedExpandedPaths:S,unstagedExpandedPaths:L,stagedTree:w,setStagedTree:y,unstagedTree:N,setUnstagedTree:C,showStatusDiffPreview:E,setShowStatusDiffPreview:M,fetchStatus:P,handleStagedToggle:R,handleUnstagedToggle:B,handleStatusFileSelect:F,handleStage:D,handleUnstage:W,handleStageFiles:H,handleUnstageFiles:O,handleDiscardFiles:q,handleStageAll:V,handleUnstageAll:K,handleDiscardFile:U,handleDiscardAll:J,refreshDiff:(0,s.useCallback)(()=>$(e=>e+1),[])}}({cwd:t,addToRecentFiles:ek.addToRecentFiles}),eS=(0,s.useMemo)(()=>{let e=new Set;if(eC.status){for(let t of eC.status.staged)e.add(t.path);for(let t of eC.status.unstaged)e.add(t.path)}return e},[eC.status]),eL=(0,s.useMemo)(()=>{let e=new Map;if(eC.status){for(let t of eC.status.staged)e.set(t.path,"staged");for(let t of eC.status.unstaged)e.set(t.path,"unstaged")}return e},[eC.status]),eE=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(""),[a,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[m,x]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)(null),[w,y]=(0,s.useState)(null),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,E]=(0,s.useState)(!1),[M,T]=(0,s.useState)(!0),[$,P]=(0,s.useState)(!1),[R,B]=(0,s.useState)(!1),[F,I]=(0,s.useState)(null),D=(0,s.useRef)(null),[W,H]=(0,s.useState)(null),[O,q]=(0,s.useState)(!1),[V,K]=(0,s.useState)(""),[U,J]=(0,s.useState)(""),[Q,X]=(0,s.useState)([]),[Y,Z]=(0,s.useState)([]),[G,ee]=(0,s.useState)(new Set),[et,er]=(0,s.useState)(null),[en,es]=(0,s.useState)(null),[eo,el]=(0,s.useState)(!1),[ei,ec]=(0,s.useState)(!1),ed=(0,s.useCallback)(()=>{N(!0),I(null),i.t4.runPromise((0,h.r4)(e).pipe(eM.match({onSuccess:e=>{e.local&&e.current?(n(e),l(e.current),e.upstream&&K(e.upstream)):(I(z.A.t("git.cannotGetBranches")),n(null))},onFailure:e=>{console.error(e),"NotFoundError"===e._tag?I(z.A.t("git.notGitRepo")):I(z.A.t("git.getBranchesFailed")),n(null)}}))).finally(()=>N(!1))},[e]),eu=(0,s.useCallback)(t=>{S(!0),u(null),x([]),p([]),j(null),y(null),T(!0),i.t4.runPromise((0,h.Bj)(e,t,ea.B_).pipe(eM.match({onSuccess:e=>{let t=e.commits||[];c(t),T(t.length>=ea.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>S(!1))},[e]),em=(0,s.useCallback)(()=>{if(L||!M||!o)return;E(!0);let t=a.length;i.t4.runPromise((0,h.Bj)(e,o,ea.B_,t).pipe(eM.match({onSuccess:e=>{let t=e.commits||[];t.length>0&&c(e=>[...e,...t]),T(t.length>=ea.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>E(!1))},[e,o,a.length,L,M]),ex=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&em()},[em]),eh=(0,s.useCallback)(t=>{u(t),j(null),y(null),P(!0),i.t4.runPromise((0,h.Zi)(e,t.hash).pipe(eM.match({onSuccess:e=>{let t=e.files||[];x(t);let r=A(t);p(r),b(new Set(_(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>P(!1))},[e]),ef=(0,s.useCallback)(r=>{d&&(j(r),t(r.path),B(!0),i.t4.runPromise((0,h.Zi)(e,d.hash,r.path).pipe(eM.match({onSuccess:e=>y(e),onFailure:e=>{console.error(e)}}))).finally(()=>B(!1)))},[e,d,t]),ep=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eg=(0,s.useCallback)(t=>{el(!0),er(null),es(null),i.t4.runPromise((0,h.yy)(e,t).pipe(eM.match({onSuccess:e=>{let t=e.files||[];X(t);let r=A(t);Z(r),ee(new Set(_(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>el(!1))},[e]),eb=(0,s.useCallback)(r=>{er(r),t(r.path),ec(!0),i.t4.runPromise((0,h.yy)(e,U,r.path).pipe(eM.match({onSuccess:e=>es(e),onFailure:e=>{console.error(e)}}))).finally(()=>ec(!1))},[e,U,t]),ev=(0,s.useCallback)(e=>{ee(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ej=(0,s.useCallback)(e=>{if(q(e),e){let e="origin/main";J(e),eg(e)}else X([]),Z([]),er(null),es(null),J("")},[V,eg]);return{branches:r,selectedBranch:o,setSelectedBranch:l,commits:a,setCommits:c,selectedCommit:d,setSelectedCommit:u,historyFiles:m,historyFileTree:f,historyExpandedPaths:g,historySelectedFile:v,historyFileDiff:w,isLoadingBranches:k,isLoadingCommits:C,isLoadingMore:L,hasMoreCommits:M,setHasMoreCommits:T,isLoadingHistoryFiles:$,isLoadingHistoryDiff:R,historyError:F,commitListRef:D,tooltipPos:W,loadBranches:ed,loadCommits:eu,loadMoreCommits:em,handleCommitListScroll:ex,handleSelectCommit:eh,handleSelectHistoryFile:ef,handleHistoryToggle:ep,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{H({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{H(null)},[]),compareMode:O,toggleCompareMode:ej,compareBaseBranch:U,setCompareBaseBranch:J,upstreamBranch:V,compareFiles:Q,compareFileTree:Y,compareExpandedPaths:G,compareSelectedFile:et,compareFileDiff:en,isLoadingCompareFiles:eo,isLoadingCompareDiff:ei,handleSelectCompareFile:eb,handleCompareToggle:ev,loadCompareFiles:eg}}({cwd:t,addToRecentFiles:ek.addToRecentFiles}),e$=(0,s.useRef)(!1),eP=(0,s.useCallback)(e=>{ek.setFileContent(t=>t?.type==="text"?{...t,content:e}:t),ek.showEditor||(e$.current=!0,ek.setShowEditor(!0))},[ek]);(0,s.useEffect)(()=>{ek.showEditor&&e$.current&&(J.current?.markDirty(),e$.current=!1)},[ek.showEditor]);let eR=(0,s.useCallback)(e=>{ek.setShowEditor(!0)},[ek]),eB=(0,s.useCallback)(async()=>{if(!ek.fileContent||"text"!==ek.fileContent.type||!ek.fileContent.content)return;let e=await i.t4.runPromiseExit((0,x.OJ)({cwd:t,path:ek.selectedPath,content:ek.fileContent.content}));try{if("Failure"===e._tag||!e.value.ok)throw Error("Failed to save file");let t=e.value.data?.mtime;t&&ek.setFileContent(e=>e?.type==="text"?{...e,mtime:t}:e),(0,k.oR)(y("toast.savedSuccess"),"success")}catch{(0,k.oR)(y("toast.saveFailed"),"error")}},[t,ek]),eF=(0,s.useCallback)(()=>{if(!ek.selectedPath)return;let e=q.current,t=V.current;e>0&&ek.updateRecentFilePosition(ek.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[ek]),eI=(0,s.useCallback)(async(e,t)=>{let r=e!==ek.selectedPath;if(r&&ek.showEditor){if(Q.isDirty&&(!await (0,k.lJ)(y("fileBrowser.saveBeforeSwitch"),{confirmText:y("fileBrowser.saveAndSwitch"),cancelText:y("common.cancel")})||(await J.current?.save(),J.current?.isDirty)))return;ek.setShowEditor(!1)}r&&eF(),ek.handleSelectFile(e,t)},[ek,eF,Q.isDirty,y]),eD=(0,s.useMemo)(()=>{let e=eN.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,ea.v3)(r),s=new Set((0,ea.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[eN.contentSearchResults]),[eA,e_]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{e_(eD.expandDirs)},[eD.expandDirs]);let eW=(0,s.useCallback)(e=>{e_(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ez=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=eD.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[eD.matchMap]),eH=Y&&eN.contentSearchResults.length>0,eO=!!ek.selectedPath&&null!==tv(ek.selectedPath),eq=(0,s.useCallback)(async(e,r)=>{if(!ek.selectedPath||!eO)return;let n=await eb.goToDefinition(ek.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=t.endsWith("/")?t:t+"/",l=s.file.startsWith(o)?s.file.slice(o.length):s.file;ew.push({filePath:ek.selectedPath,lineNumber:q.current}),l===ek.selectedPath?ek.setTargetLineNumber(s.line):eI(l,s.line)},[ek,t,eO,eb,ew]),eV=(0,s.useCallback)((e,t,r)=>{ek.selectedPath&&eO&&ev.onTokenMouseEnter(ek.selectedPath,e,t,r)},[ek.selectedPath,eO,ev]),eK=(0,s.useCallback)(e=>{let r=t.endsWith("/")?t:t+"/",n=e.file.startsWith(r)?e.file.slice(r.length):e.file;ek.selectedPath&&ew.push({filePath:ek.selectedPath,lineNumber:q.current}),n===ek.selectedPath?ek.setTargetLineNumber(e.line):eI(n,e.line)},[ek,t,ew]),eU=(0,s.useMemo)(()=>{if(!eC.status)return null;let e=new Map,t=e=>{switch(e){case"modified":default:return"M";case"added":return"A";case"deleted":return"D";case"renamed":return"R";case"untracked":return"?"}};for(let r of eC.status.staged)e.set(r.path,t(r.status));for(let r of eC.status.unstaged)e.set(r.path,t(r.status));return e},[eC.status]);(0,s.useEffect)(()=>{R(M.current)},[]),(0,s.useEffect)(()=>{S(r)},[r,l]),(0,s.useEffect)(()=>{a&&(S("search"),eN.setContentSearchQuery(a),eN.performContentSearch(a))},[c]);let eJ=(0,s.useCallback)(e=>{S(e),ek.setBlameSelectedCommit(null),"history"===e&&eE.selectedBranch&&eE.loadCommits(eE.selectedBranch)},[ek,eE.selectedBranch,eE.loadCommits]),eQ=(0,s.useCallback)(()=>{if(!ek.selectedPath)return;let e={filePath:ek.selectedPath,lineNumber:q.current},t=ew.goBack(e);t&&(t.filePath===ek.selectedPath?ek.setTargetLineNumber(t.lineNumber):eI(t.filePath,t.lineNumber))},[ek,ew]),eX=(0,s.useCallback)(()=>{if(!ek.selectedPath)return;let e={filePath:ek.selectedPath,lineNumber:q.current},t=ew.goForward(e);t&&(t.filePath===ek.selectedPath?ek.setTargetLineNumber(t.lineNumber):eI(t.filePath,t.lineNumber))},[ek,ew]),eY=(0,s.useCallback)(async e=>{let r=e.split("/").pop()||e;"Success"===(await i.t4.runPromiseExit((0,x.__)({cwd:t,paths:[e],op:"copy"})))._tag?(0,k.oR)(y("toast.copiedName",{name:r}),"success"):(0,k.oR)(y("toast.copyFailed"),"error")},[t,y]),eZ=(0,s.useCallback)(async e=>{let r=await i.t4.runPromiseExit((0,x.dt)());if("Success"!==r._tag||!r.value.path)return void(0,k.oR)(y("toast.noFileToPaste"),"info");let n=r.value.path,s=await i.t4.runPromiseExit((0,x.Nn)({cwd:t,targetDir:e,sourceAbsPath:n}));if("Success"===s._tag)(0,k.oR)(y("toast.pastedFile",{name:s.value.newName}),"success"),ek.loadDirectory(e),ek.loadFileIndex();else{let e="Fail"===s.cause._tag?s.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:y("toast.pasteFailed");(0,k.oR)(r,"error")}},[t,ek,y]),eG=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===N;if(r&&t.ctrlKey&&!t.metaKey&&"Minus"===t.code){t.preventDefault(),t.shiftKey?eX():eQ();return}if(r&&(t.metaKey||t.ctrlKey)&&"p"===t.key){t.preventDefault(),O(e=>!e);return}if(r&&(t.metaKey||t.ctrlKey)&&"c"===t.key&&!t.shiftKey){let e=t.target?.tagName,r=window.getSelection()?.toString();if(("tree"===C||"recent"===C)&&ek.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),eY(ek.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===C||"recent"===C)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),eZ((0,ea.S7)(ek.selectedPath,ek.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(ei){t.preventDefault(),eh.open();return}if(en&&ek.selectedPath?.endsWith(".json")){t.preventDefault(),eu.open();return}}if(r&&"Escape"===t.key){if(I)return void O(!1);if(eh.isVisible)return void eh.close();if(eu.isVisible)return void eu.close();if(ei)return void ec(null);let t=Date.now();if(t-eG.current<3e3)return;eG.current=t,ej.visible?ej.closeReferences():Y?G(!1):ek.blameSelectedCommit?ek.setBlameSelectedCommit(null):ek.showBlame?ek.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,ek.showBlame,ek.blameSelectedCommit,ek,I,ej.visible,ej.closeReferences,Y,eQ,eX,en,eu,ei,eh,C,eY,eZ,N]),(0,s.useEffect)(()=>{ek.loadFiles(),ek.loadFileIndex(),ek.loadRecentFiles(),eC.fetchStatus(),eE.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{eC.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[eC.fetchStatus]);let e0=(0,s.useRef)(ey);(0,s.useEffect)(()=>{ey&&!e0.current&&(ek.loadFiles(),ek.loadFileIndex(),ek.loadRecentFiles(),eC.fetchStatus(),eE.loadBranches()),e0.current=ey},[ey]),(0,s.useEffect)(()=>{eE.selectedBranch&&eE.loadCommits(eE.selectedBranch)},[eE.selectedBranch,eE.loadCommits]);let e1=(0,s.useRef)(C);(0,s.useEffect)(()=>{let e=e1.current;if(e1.current=C,("tree"===C||"recent"===C)&&ek.recentFiles.length>0){let t=ek.recentFiles[0].path;ek.selectedPath&&("status"!==e&&"history"!==e||ek.selectedPath===t)||(ek.setShouldScrollToSelected(!0),eI(t))}},[C,ek.recentFiles,ek.selectedPath,eI,ek]);let e2=(0,s.useRef)(eE.selectedBranch);e2.current=eE.selectedBranch;let e5=(0,s.useRef)(ek.selectedPath);e5.current=ek.selectedPath;let e4=(0,s.useRef)(ek.fileContent?.type);e4.current=ek.fileContent?.type;let e6=(0,s.useCallback)(async e=>{try{let{data:r}=e;if(!r)return;let n=r.some(e=>"git"===e.type),s=r.some(e=>"file"===e.type),o=[];if((s||n)&&(o.push(i.t4.runPromise((0,x.mP)(t)).then(e=>{e.error||ek.setFiles(t=>(0,ea.HR)(e.files??[],t))}).catch(()=>{})),o.push(i.t4.runPromise((0,x.DZ)(t)).then(e=>{e.paths&&ek.setFileIndex(e.paths)}).catch(()=>{})),o.push(i.t4.runPromise((0,x.r9)(t)).then(e=>{ek.setRecentFiles(e.files??[])}).catch(()=>{}))),n||s){o.push(i.t4.runPromise((0,h.lv)(t)).then(e=>{eC.setStatus(e);let t=A(e.staged),r=A(e.unstaged);eC.setStagedTree(t),eC.setUnstagedTree(r)}).catch(()=>{})),eC.refreshDiff(),n&&eE.loadBranches();let e=e2.current;e&&o.push(i.t4.runPromise((0,h.Bj)(t,e,ea.B_)).then(e=>{let t=e.commits??[];eE.setCommits(t),eE.setHasMoreCommits(t.length>=ea.B_)}).catch(()=>{}))}let l=e5.current,a=e4.current;l&&"text"===a&&o.push(i.t4.runPromise((0,x.K9)(t,l)).then(e=>{let t=e.ok?e.data:null;t&&"string"==typeof t.content&&ek.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,ep.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:e6,enabled:ey});let e8=(0,s.useCallback)(e=>{let t=e.split("/");if(t.length>1){let e=[];for(let r=1;r<t.length;r++)e.push(t.slice(0,r).join("/"));ek.setExpandedPaths(t=>{let r=new Set(t);for(let t of e)r.add(t);return ek.saveExpandedPaths(r),r})}ek.setSelectedPath(e),ek.setShouldScrollToSelected(!0),S("tree")},[ek]);return(0,n.jsxs)(b.SU,{container:P,children:[(0,n.jsxs)("div",{ref:M,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:"w-80 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex border-b border-border",children:[(0,n.jsx)("button",{onClick:()=>eJ("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===C?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:y("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>eJ("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===C?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:y("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>eJ("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===C?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:y("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>eJ("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===C?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:y("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>eJ("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===C?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:y("fileBrowser.historyTab")})]}),"tree"===C&&(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:ek.searchInputRef,type:"text",value:ek.searchQuery,onChange:e=>ek.setSearchQuery(e.target.value),placeholder:y("fileBrowser.searchFiles"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),ek.searchQuery&&(0,n.jsx)("button",{onClick:()=>ek.setSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:y("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:()=>ek.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${ek.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:ek.searchExactMatch?y("fileBrowser.exactMatchOn"):y("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>ek.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:y("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:()=>ek.searchTreeExpandedPaths?ek.setSearchTreeExpandedPaths(new Set):ek.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:y("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"===C&&(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:eN.contentSearchInputRef,type:"text",value:eN.contentSearchQuery,onChange:e=>eN.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&eN.performContentSearch(eN.contentSearchQuery)},placeholder:y("fileBrowser.searchFileContent"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),eN.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>eN.setContentSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:y("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:()=>eN.performContentSearch(eN.contentSearchQuery),disabled:eN.isSearching||!eN.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:eN.isSearching?"...":y("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:eN.searchOptions.caseSensitive,onChange:e=>eN.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:y("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eN.searchOptions.wholeWord,onChange:e=>eN.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:y("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eN.searchOptions.regex,onChange:e=>eN.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:y("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:eN.searchOptions.fileType,onChange:e=>eN.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:y("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9"})]})]}),"history"===C&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:eE.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:"truncate",children:eE.branches?.current||"HEAD"}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:"HEAD"})]}),(0,n.jsx)("button",{onClick:()=>eE.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:y("fileBrowser.compareModeOff"),children:y("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)(tb,{branches:eE.branches,selectedBranch:eE.compareBaseBranch,onSelect:e=>{eE.setCompareBaseBranch(e),eE.loadCompareFiles(e)},isLoading:eE.isLoadingBranches,pinnedBranches:["origin/main",...eE.upstreamBranch&&"origin/main"!==eE.upstreamBranch?[eE.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)(tb,{branches:eE.branches,selectedBranch:eE.selectedBranch,onSelect:e=>{eE.setSelectedBranch(e)},isLoading:eE.isLoadingBranches,pinnedBranches:["origin/main",...eE.upstreamBranch&&"origin/main"!==eE.upstreamBranch?[eE.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>eE.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-accent border border-border",title:y("fileBrowser.compareModeOn"),children:y("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"===C?"":"hidden"}`,children:[ek.creatingItem&&(0,n.jsxs)("div",{className:"px-2 py-1.5 border-b border-border bg-secondary flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:ek.creatingItem.parentPath?y("fileBrowser.createFileIn",{path:ek.creatingItem.parentPath}):y("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:y("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:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if($.current)return;let r=e.target.value.trim();if(!r)return;let n=ek.creatingItem.parentPath,s=n?`${n}/${r}`:r,o=await i.t4.runPromiseExit((0,x.OJ)({cwd:t,path:s,content:""}));if("Success"===o._tag&&o.value.ok)(0,k.oR)(y("toast.createdFile",{name:r}),"success"),ek.setCreatingItem(null),ek.loadDirectory(n),ek.loadFileIndex(),n&&ek.setExpandedPaths(e=>new Set([...e,n])),eI(s);else if("Success"===o._tag){let e=o.value.data?.error;(0,k.oR)(e||y("toast.createFailed"),"error")}else(0,k.oR)(y("toast.createFailed"),"error")}else"Escape"===e.key&&ek.setCreatingItem(null)},onBlur:()=>ek.setCreatingItem(null)})]}),ek.isLoadingFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("common.loading")}):ek.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ek.fileError}):(0,n.jsx)(eo,{files:ek.files,selectedPath:ek.selectedPath,expandedPaths:ek.effectiveExpandedPaths,matchedPaths:ek.matchedPaths,gitStatusMap:eU,loadingDirs:ek.loadingDirs,onSelect:e=>{ek.setShouldScrollToSelected(!1),eI(e)},onToggle:ek.handleToggle,cwd:t,shouldScrollToSelected:ek.shouldScrollToSelected,onScrolledToSelected:()=>ek.setShouldScrollToSelected(!1),onCreateFile:e=>ek.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>F({path:e,isDirectory:t,name:r}),onRefresh:()=>ek.loadFiles(),onCopyFile:eY,onPaste:eZ})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===C?"":"hidden"}`,children:eN.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"})}):eN.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:eN.searchError}):0===eN.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:eN.contentSearchQuery?y("fileBrowser.noContentSearchResults"):y("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[eN.searchStats&&(0,n.jsxs)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-secondary border-b border-border flex-shrink-0",children:[y("fileBrowser.nFilesNMatches",{files:eN.searchStats.totalFiles,matches:eN.searchStats.totalMatches}),eN.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",y("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(eo,{files:eD.files,selectedPath:ek.selectedPath,expandedPaths:eA,onSelect:e=>{let t=eD.matchMap.get(e);eI(e,t?.matches[0]?.lineNumber),Y||G(!0)},onToggle:eW,cwd:t,renderActions:ez,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"===C?"":"hidden"}`,children:0===ek.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("fileBrowser.noRecentFiles")}):(0,n.jsx)(eo,{files:ek.recentFilesTree,selectedPath:ek.selectedPath,expandedPaths:ek.recentTreeDirPaths,onSelect:eI,onToggle:ea.tE,cwd:t})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===C?"":"hidden"}`,children:eC.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"})}):eC.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:eC.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:y("fileBrowser.stagingArea",{count:eC.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>eC.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:y("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"})})})]}),(eC.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:eC.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:y("fileBrowser.unstageAll")})]}),(0,n.jsx)(D,{files:eC.stagedTree,selectedPath:eC.statusSelectedFile?.type==="staged"?eC.statusSelectedFile.file.path:null,expandedPaths:eC.stagedExpandedPaths,onSelect:e=>e.file&&eC.handleStatusFileSelect(e.file,"staged"),onToggle:eC.handleStagedToggle,cwd:t,emptyMessage:y("fileBrowser.noStagedFiles"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=W(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),eC.handleUnstageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:y("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(),eC.handleUnstage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:y("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.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:y("fileBrowser.workspace",{count:eC.status?.unstaged.length||0})}),(eC.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:eC.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:y("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:eC.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:y("fileBrowser.stageAll")})]})]}),(0,n.jsx)(D,{files:eC.unstagedTree,selectedPath:eC.statusSelectedFile?.type==="unstaged"?eC.statusSelectedFile.file.path:null,expandedPaths:eC.unstagedExpandedPaths,onSelect:e=>e.file&&eC.handleStatusFileSelect(e.file,"unstaged"),onToggle:eC.handleUnstagedToggle,cwd:t,emptyMessage:y("fileBrowser.noUnstagedChanges"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=W(e);if(0===t.length)return null;let r=t.map(e=>e.file).filter(Boolean);return(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),eC.handleDiscardFiles(r)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:y("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(),eC.handleStageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:y("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:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),eC.handleDiscardFile(e.file)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:y("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(),eC.handleStage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:y("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"===C?"":"hidden"}`,children:eE.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-slate-7 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:eE.historyError})]})}):eE.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:eE.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("fileBrowser.loadingDiff")}):0===eE.compareFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("fileBrowser.noDiffFiles")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:y("fileBrowser.nFilesChanged",{count:eE.compareFiles.length,branch:eE.compareBaseBranch})})}),(0,n.jsx)(D,{files:eE.compareFileTree,expandedPaths:eE.compareExpandedPaths,onToggle:eE.handleCompareToggle,selectedPath:eE.compareSelectedFile?.path||null,onSelect:e=>{e.file&&eE.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0})]})}):(0,n.jsx)("div",{ref:eE.commitListRef,className:"flex-1 overflow-y-auto",onScroll:eE.handleCommitListScroll,children:eE.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("fileBrowser.loadingCommits")}):0===eE.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[eE.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>eE.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-accent ${eE.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-slate-9",title:e.date,children:[e.relativeDate," \xb7 ",(0,ea.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)),eE.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"})}),!eE.hasMoreCommits&&eE.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-slate-9",children:y("fileBrowser.allLoaded",{count:eE.commits.length})})]})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[("tree"===C||"search"===C||"recent"===C)&&(ek.blameSelectedCommit?(0,n.jsx)(er,{isOpen:!0,onClose:()=>ek.setBlameSelectedCommit(null),commit:ek.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:ek.selectedPath||void 0,onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)}}):"map"===L?(0,n.jsx)(e3,{cwd:t,highlightedFilePath:ek.selectedPath,changedFiles:eS,onSwitchToCode:()=>E("code"),enableComments:!0,onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)},headerExtraLeft:({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,k.oR)(y("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:y("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(),e8(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:y("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"})]})})]})}):ek.selectedPath?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary 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:ek.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${ek.selectedPath}`),(0,k.oR)(y("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:y("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(),e8(ek.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:y("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:ek.showEditor?(0,n.jsxs)(n.Fragment,{children:[Q.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:y("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>J.current?.save(),disabled:!Q.isDirty||Q.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${Q.isDirty&&!Q.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:Q.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):y("common.save")}),(0,n.jsx)("button",{onClick:()=>J.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:y("fileBrowser.closeEdit"),children:y("fileBrowser.closeBtn")})]}):(0,n.jsxs)(n.Fragment,{children:[ek.fileContent?.type==="text"&&ek.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(ek.fileContent.content),(0,k.oR)(y("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:y("fileBrowser.copyFileContent"),children:y("common.copy")}),ek.selectedPath?.endsWith(".json")&&ek.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>es(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${en?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,title:y("fileBrowser.toggleJsonReadable"),children:y("common.readable")}),ek.fileContent?.type==="text"&&Z(ek.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ek.setShowMarkdownPreview(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:y("fileBrowser.previewMarkdown"),children:y("common.preview")}),ek.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:ek.handleToggleBlame,disabled:ek.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${ek.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-accent"} disabled:opacity-50`,title:y("fileBrowser.viewBlame"),children:ek.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),ek.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>E("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:y("blockViewer.viewerToggle.toBlock"),children:y("common.codeMap")}),ek.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>ek.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:y("fileBrowser.editFile"),children:y("common.edit")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:ek.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"})}):ek.fileContent?"text"===ek.fileContent.type&&"string"==typeof ek.fileContent.content?ek.showBlame&&ek.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:ek.blameError}),(0,n.jsx)("button",{onClick:()=>ek.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:y("fileBrowser.backToPreview")})]})}):ek.showBlame&&0===ek.blameLines.length&&ek.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"})}):en&&ek.selectedPath?.endsWith(".json")?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-[#0d1117]",children:[(0,n.jsx)(et,{search:eu}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:ed,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:H(ek.fileContent.content)})})]}):(0,n.jsx)(el.Cv,{ref:J,content:ek.fileContent.content,filePath:ek.selectedPath,cwd:t,enableComments:!0,scrollToLine:K??ek.targetLineNumber,scrollToLineAlign:null!=K?"start":ek.targetScrollAlign,onScrollToLineComplete:()=>{U(null),ek.setTargetLineNumber(null)},highlightKeyword:"search"===C?eN.contentSearchQuery:null,visibleLineRef:q,viStateRef:V,initialCursorLine:ek.initialCursorLine,initialCursorCol:ek.initialCursorCol,onInitialCursorSet:()=>{ek.setInitialCursorLine(null),ek.setInitialCursorCol(null)},onCmdClick:eO?eq:void 0,onTokenHover:eO?eV:void 0,onTokenHoverLeave:eO?ev.onTokenMouseLeave:void 0,onTokenHoverCancel:eO?ev.clearHover:void 0,blameLines:ek.showBlame&&ek.blameLines.length>0?ek.blameLines:void 0,inlineBlameLines:ek.blameLines.length>0?ek.blameLines:void 0,onSelectCommit:ek.setBlameSelectedCommit,editable:ek.showEditor,initialMtime:ek.fileContent.mtime,onEditorClose:e=>{ek.setShowEditor(!1),U(e)},onSaved:()=>{let e=q.current??1;ek.loadFileContent(ek.selectedPath),ek.setShowEditor(!1),U(e)},onEditorStateChange:X,viMode:!0,onContentMutate:eP,onEnterInsertMode:eR,onViSave:eB,onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)}}):"image"===ek.fileContent.type&&ek.selectedPath?(0,n.jsx)(tp,{cwd:t,path:ek.selectedPath,refreshKey:ek.fileContent.mtime,alt:ek.selectedPath}):(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-slate-7 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:ek.fileContent.message||y("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:y("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-slate-7 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:y("fileBrowser.selectFileToPreview")})]})})),"status"===C&&(eC.statusSelectedFile&&eC.statusDiff?(0,n.jsx)(tg,{cwd:t,selected:eC.statusSelectedFile,diff:eC.statusDiff,showMarkdownPreview:eC.showStatusDiffPreview,setShowMarkdownPreview:eC.setShowStatusDiffPreview,changedFiles:eS,fileGitStatusMap:eL,onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)},locateInTree:e8,jsonPreview:ei,setJsonPreview:ec,jsonPreviewSearch:eh,jsonPreviewPreRef:em}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:y("fileBrowser.selectFileToViewDiff")})})),"history"===C&&!eE.historyError&&(eE.compareMode?eE.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:y("fileBrowser.loadingDiffContent")}):eE.compareFileDiff?(0,n.jsx)(T,{oldContent:eE.compareFileDiff.oldContent,newContent:eE.compareFileDiff.newContent,filePath:eE.compareFileDiff.filePath,isNew:eE.compareFileDiff.isNew,isDeleted:eE.compareFileDiff.isDeleted,cwd:t,enableComments:!0,onPreview:!eE.compareFileDiff.isDeleted&&eE.compareFileDiff.filePath.endsWith(".json")?()=>ec({content:eE.compareFileDiff.newContent,filePath:eE.compareFileDiff.filePath}):void 0,previewLabel:y("common.readable"),onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:eE.compareFiles.length>0?y("fileBrowser.selectFileToViewDiff"):y("fileBrowser.clickCompareToLoad")})}):eE.selectedCommit?(0,n.jsx)(er,{isOpen:!0,onClose:()=>eE.setSelectedCommit(null),commit:eE.selectedCommit,cwd:t,embedded:!0,onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:y("fileBrowser.selectCommitToView")})}))]})]}),ek.showMarkdownPreview&&ek.fileContent?.type==="text"&&ek.selectedPath&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>ek.setShowMarkdownPreview(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(ex,{content:ek.fileContent.content||"",filePath:ek.selectedPath,cwd:t,onClose:()=>ek.setShowMarkdownPreview(!1)})})}),I&&(0,n.jsx)(ef,{files:ek.files,fileIndex:ek.fileIndex,recentFiles:ek.recentFilePaths,onSelectFile:e=>{eI(e),ek.setShouldScrollToSelected(!0),S("tree")},onClose:()=>O(!1)}),(eH||ej.visible)&&(0,n.jsxs)("div",{className:`flex ${ej.visible&&eH?"":"flex-col"}`,children:[eH&&(0,n.jsx)("div",{className:ej.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(tN,{results:eN.contentSearchResults,loading:eN.isSearching,totalMatches:eN.searchStats?.totalMatches??0,onSelect:(e,t)=>{ek.selectedPath&&ew.push({filePath:ek.selectedPath,lineNumber:q.current}),eI(e,t)},onClose:()=>G(!1)})}),ej.visible&&(0,n.jsx)("div",{className:eH?"flex-1 min-w-0":"",children:(0,n.jsx)(tk,{references:ej.references,loading:ej.loading,onSelect:eK,onClose:ej.closeReferences})})]})]}),B&&(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50",onClick:()=>F(null),children:(0,n.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-xl 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:y("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:y("fileBrowser.confirmDeleteMessage",{name:B.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:()=>F(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-accent transition-colors",children:y("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=B;F(null);let n=await i.t4.runPromiseExit((0,x.VK)({cwd:t,path:e}));if("Success"===n._tag){(0,k.oR)(y("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";ek.loadDirectory(t),ek.loadFileIndex(),ek.selectedPath===e&&eI("")}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:y("toast.deleteFailed");(0,k.oR)(r,"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:y("common.delete")})]})]})})}),ev.hoverInfo&&P&&(0,u.createPortal)((0,n.jsx)(ty,{ref:ev.setTooltipEl,displayString:ev.hoverInfo.displayString,documentation:ev.hoverInfo.documentation,x:ev.hoverInfo.x,y:ev.hoverInfo.y,container:P,onMouseEnter:ev.onCardMouseEnter,onMouseLeave:ev.onCardMouseLeave,onFindReferences:()=>{let{filePath:e,line:t,column:r}=ev.hoverInfo;ev.clearHover(),ej.findReferences(e,t,r)},onSearch:e=>{ev.clearHover(),S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)}}),P)]})}function tL({isOpen:e,onClose:t,cwd:r}){let c,{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)([]),[x,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),[y,N]=(0,s.useState)(null),[C,S]=(0,s.useState)(!1),[L,E]=(0,s.useState)(""),[M,T]=(0,s.useState)(!1),[$,P]=(0,s.useState)([]),[R,B]=(0,s.useState)(""),[F,I]=(0,s.useState)(!1),D=(0,s.useCallback)((e,t)=>e?._tag==="Fail"&&e.error?.cause instanceof Error?e.error.cause.message:d(t),[d]),A=(0,s.useCallback)(async()=>{v(!0);let e=await i.t4.runPromiseExit((0,h.FK)(r));if("Success"===e._tag){let t=e.value;m(t.worktrees),f(t.nextPath),g(t.nextRandomWord),t.gitUserName&&E(t.gitUserName)}else console.error("Failed to load worktrees:",e.cause),(0,k.oR)(d("toast.worktreeLoadFailed"),"error");v(!1)},[r,d]),_=(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&&(A(),N(null))},[e,A]);let W=async()=>{if(!x)return;let e="origin/main",t=await i.t4.runPromiseExit((0,h.r4)(r));"Success"===t._tag&&(e=_(t.value));let n=p||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=L?`${L}/${n}`:n;w(!0);let o=await i.t4.runPromiseExit((0,h.CM)({action:"add",cwd:r,path:x,newBranch:s,baseBranch:e}));"Success"===o._tag?((0,k.oR)(d("toast.worktreeCreateSuccess",{name:s}),"success"),A()):(console.error("Failed to create worktree:",o.cause),(0,k.oR)(D(o.cause,"toast.worktreeCreateFailed"),"error")),w(!1)},z=async()=>{I(!0),B(""),T(!0);let e=await i.t4.runPromiseExit((0,h.r4)(r));if("Success"===e._tag){let t=e.value,r=t.local??[],n=t.remote??[],s=new Set(u.map(e=>e.branch).filter(Boolean));P([...r.filter(e=>!s.has(e)),...n.filter(e=>!s.has(e)&&!r.includes(e.replace(/^origin\//,"")))])}else(0,k.oR)(d("toast.loadBranchFailed"),"error");I(!1)},H=async e=>{if(!x)return;T(!1),w(!0);let t=await i.t4.runPromiseExit((0,h.CM)({action:"add",cwd:r,path:x,branch:e}));"Success"===t._tag?((0,k.oR)(d("toast.worktreeCreateSuccess",{name:e}),"success"),A()):(console.error("Failed to create worktree:",t.cause),(0,k.oR)(D(t.cause,"toast.worktreeCreateFailed"),"error")),w(!1)},O=async()=>{if(!y)return;S(!0);let e=await i.t4.runPromiseExit((0,h.CM)({action:"remove",cwd:r,path:y.path}));"Success"===e._tag?((0,k.oR)(d("toast.worktreeDeleted"),"success"),N(null),A()):(console.error("Failed to delete worktree:",e.cause),(0,k.oR)(D(e.cause,"toast.worktreeDeleteFailed"),"error")),S(!1)},q=async e=>{let t=e.isLocked?"unlock":"lock",n=await i.t4.runPromiseExit((0,h.CM)({action:t,cwd:r,path:e.path}));"Success"===n._tag?((0,k.oR)(e.isLocked?d("toast.worktreeUnlocked"):d("toast.worktreeLocked"),"success"),A()):(console.error("Failed to toggle lock:",n.cause),(0,k.oR)(D(n.cause,"toast.operationFailed"),"error"))};return e?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl 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-accent rounded transition-colors",title:d("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:b?(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:u.map(e=>{let s=e.path===r;return(0,n.jsxs)("div",{className:`group p-3 rounded-lg border transition-colors ${s?"border-brand bg-brand/5":"border-border hover:bg-accent cursor-pointer"}`,onClick:()=>{e.path!==r&&((0,l.F)(a.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 ${s?"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:d("git.worktree.locked"),children:"\uD83D\uDD12"}),s&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",d("common.current"),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:!s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),q(e)},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary rounded transition-colors",title:e.isLocked?d("git.worktree.unlock"):d("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(),N(e)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-secondary rounded transition-colors",title:d("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.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate pl-4",children:e.path}),e.isDetached&&(0,n.jsx)("div",{className:"mt-1 text-xs text-amber-11 pl-4",children:"(detached HEAD)"})]},e.path)})})}),M&&(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:R,onChange:e=>B(e.target.value),placeholder:d("git.worktree.searchBranch"),className:"flex-1 bg-secondary text-sm text-foreground rounded px-2.5 py-1.5 outline-none placeholder:text-muted-foreground",autoFocus:!0,autoComplete:"off",spellCheck:"false"}),(0,n.jsx)("button",{onClick:()=>T(!1),className:"text-xs text-muted-foreground hover:text-foreground px-2 py-1.5",children:d("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:F?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:d("common.loading")}):0===(c=$.filter(e=>e.toLowerCase().includes(R.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:d("git.worktree.noBranches")}):c.map(e=>(0,n.jsx)("button",{onClick:()=>H(e),className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent 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:d("git.worktree.count",{count:u.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:z,disabled:!x||j,className:`px-3 py-1.5 text-sm rounded transition-colors ${x&&!j?"bg-secondary text-foreground hover:bg-accent":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:d("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:W,disabled:!x||j,className:`px-3 py-1.5 text-sm rounded transition-colors ${x&&!j?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:j?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):d("git.worktree.addWorktree")})]})]}),y&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-black/50 rounded-lg",onClick:()=>N(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-[360px] p-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-3",children:d("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:d("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:d("git.worktree.path")}),(0,n.jsx)("span",{className:"text-foreground",children:y.path})]}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:d("git.worktree.branch")}),(0,n.jsx)("span",{className:"text-foreground",children:y.branch||"detached"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>N(null),className:"px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:d("common.cancel")}),(0,n.jsx)("button",{onClick:O,disabled:C,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 transition-colors disabled:opacity-50",children:C?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):d("common.delete")})]})]})})]})}):null}var tE=r(67635),tM=r(73300),tT=r(20986),t$=r(9921),tP=r(66088),tR=r(42790);function tB(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}let tF=(0,s.memo)(function({shortId:e,type:t,onRegister:r,onUnregister:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)(async n=>{if(n.stopPropagation(),i)await l(),c(!1),(0,k.oR)(a("toast.disconnected",{id:e}));else{await r(),c(!0);let n=`${"3456"===window.location.port?"cock-dev":"cock"} ${t} ${e}`;navigator.clipboard.writeText(n),(0,k.oR)(a("toast.copiedCommand",{command:n}))}},[i,e,t,r,l,a]);return(0,n.jsxs)("button",{onClick:d,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:i?a("shortIdBadge.clickToDisconnect"):a("shortIdBadge.clickToRegister"),children:[(0,n.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${i?"bg-green-500":"bg-muted-foreground/40"}`}),e]})});var tI=r(12786);let tD=e=>eM.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new eT.uV({message:`fetch ${e} failed`,cause:t})}),tA=(e,t)=>eM.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:r=>new eT.uV({message:`${t.method} ${e} failed`,cause:r})}),t_=(e,t)=>tA(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),tW=(e,t)=>eM.gen(function*(){let r=new URLSearchParams({cwd:e});return t&&r.set("tabId",t),(yield*tD(`/api/terminal/env?${r}`)).env||{}}),tz=()=>tD("/api/terminal/aliases").pipe(eM.map(e=>e.aliases||{})),tH=(e,t,r)=>t_("/api/terminal/bubble-order",{cwd:e,tabId:t,order:r}),tO=(e,t,r)=>t_("/api/terminal/history",{cwd:e,tabId:t,entry:r}),tq=(e,t,r)=>tA(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}&commandId=${encodeURIComponent(r)}`,{method:"DELETE"}),tV=e=>tD(`/api/services/config?cwd=${encodeURIComponent(e)}`),tK=(0,s.lazy)(()=>Promise.all([r.e(3888),r.e(1959)]).then(r.bind(r,71959)).then(e=>({default:e.XtermRenderer}))),tU={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},tJ=/\x1b\[[0-9;]*m/g;function tQ({output:e,query:t,mode:r,currentIdx:o,matchListRef:l}){let a=(0,s.useRef)(null);a.current||(a.current=new tR.v,a.current.use_classes=!0);let i=e.split("\n"),c=t.toLowerCase(),d=0;return l.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(tJ,""),i=s.toLowerCase().includes(c);if("filter"===r&&!i)return null;if(!i){let r=a.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(c,h);if(-1===e)break;e>m&&u.push((0,n.jsx)("span",{children:s.slice(m,e)},`t${m}`));let t=d++,r=t===o;u.push((0,n.jsx)("mark",{ref:e=>{l.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+c.length)},`m${e}`)),h=m=e+c.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 tX=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:l,output:a,exitCode:c,isRunning:d,selected:u,onSelect:m,onInterrupt:x,onStdin:h,onDelete:f,onRerun:p,timestamp:g,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,onPtyResize:w,onToggleMaximize:y,maximized:N,expandedHeight:C,bubbleContentHeight:S,onTitleMouseDown:L}){let{t:E}=(0,o.Bd)(),M=(0,s.useRef)(null),T=(0,s.useRef)(null),$=(0,s.useRef)(!0),P=(0,s.useRef)(null),R=(0,s.useRef)(null),B=(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),F=e&&t?tB(t+e):void 0,[I,D]=(0,s.useState)(!1),[A,_]=(0,s.useState)(""),W=(0,s.useRef)(null),z=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!v||!e)return;let t=()=>W.current?v(e,W.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=()=>W.current?j(e,W.current.reset):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[j,e]);let[H,O]=(0,s.useState)(!1),[q,V]=(0,s.useState)(""),[K,U]=(0,s.useState)("search"),[J,Q]=(0,s.useState)(0),X=(0,s.useRef)([]),Y=(0,s.useRef)(null),Z=(0,s.useRef)(0);(0,s.useEffect)(()=>{Y.current||(Y.current=new tR.v,Y.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=T.current;if(e&&Y.current){if(a.length<Z.current&&(Y.current=new tR.v,Y.current.use_classes=!0,Z.current=0,e.innerHTML=""),a.length>Z.current){let t=a.slice(Z.current),r=Y.current.ansi_to_html(t);Z.current=a.length,e.insertAdjacentHTML("beforeend",r)}if(M.current){let e=M.current.scrollHeight>M.current.clientHeight;D(e),e&&(M.current.scrollTop=M.current.scrollHeight)}}},[a]),(0,s.useEffect)(()=>(d&&$.current&&M.current&&(null!==P.current&&cancelAnimationFrame(P.current),P.current=requestAnimationFrame(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight),P.current=null})),()=>{null!==P.current&&cancelAnimationFrame(P.current)}),[a,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 G=a?a.split("\n").length:0,ee=(0,s.useCallback)(()=>{O(!0),requestAnimationFrame(()=>z.current?.focus())},[]),et=(0,s.useCallback)(()=>{O(!1),V(""),Q(0),W.current?.clearSearch()},[]),er=(0,s.useCallback)(e=>{e.trim()&&(b?W.current?.findNext(e):Q(e=>{let t=e+1,r=X.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(X.current[0]?.scrollIntoView({block:"nearest"}),0)}))},[b]),en=(0,s.useCallback)(e=>{e.trim()&&(b?W.current?.findPrevious(e):Q(e=>{let t=e-1;if(t>=0)return X.current[t]?.scrollIntoView({block:"nearest"}),t;let r=X.current.length-1;return r>=0&&X.current[r]?.scrollIntoView({block:"nearest"}),Math.max(r,0)}))},[b]);(0,s.useEffect)(()=>{if(!u)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key){e.preventDefault(),e.stopPropagation(),ee();return}if("Escape"===e.key&&H){e.preventDefault(),e.stopPropagation(),et();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[u,H,ee,et]);let es=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-accent 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?"":u?"border-brand":"border-brand/30"}`,onClick:m,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:l}),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&&x&&(0,n.jsx)("button",{onClick:x,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-md 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-accent transition-colors",title:E("console.restoreTooltip",{modKey:(0,tI.Mu)()}),children:(0,n.jsx)(ev.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 ${u?"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:">_"}),F&&e&&t&&(0,n.jsx)(tF,{shortId:F,type:"terminal",onRegister:()=>{i.t4.runFork(t_("/api/terminal/register",{tabId:t,commandId:e,command:l,projectCwd:r}).pipe(eM.orElse(()=>eM.void)))},onUnregister:()=>{i.t4.runFork(t_("/api/terminal/unregister",{commandId:e}).pipe(eM.orElse(()=>eM.void)))}}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:l}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(l),(0,k.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)(tE.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),I&&!d&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:E("console.totalLines",{count:G})}),a&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=a.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,k.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)(tM.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)(tT.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)(ev.A,{className:"w-3.5 h-3.5"})})]}),H&&(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)(eb.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:z,value:q,onChange:e=>{let t=e.target.value;V(t),Q(0),b&&(t.trim()?W.current?.findNext(t):W.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?en(q):er(q))},placeholder:E("console.searchPlaceholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",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:()=>U("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:()=>U("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:()=>en(q),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:E("console.prevShiftEnter"),children:(0,n.jsx)(t$.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>er(q),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:E("console.nextEnter"),children:(0,n.jsx)(tP.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("button",{onClick:et,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",children:(0,n.jsx)(ev.A,{className:"w-3.5 h-3.5"})})]}),b?(0,n.jsxs)("div",{className:"relative group",style:{height:es,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:es},children:E("console.loadingTerminal")}),children:(0,n.jsx)(tK,{ref:W,output:a,isRunning:d,onInput:h,onResize:w,maximized:N,height:es,directWrite:!!v})}),!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()},title:E("console.rerun"),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)(tT.A,{className:"w-3.5 h-3.5"}),E("console.rerun")]})})]}):(0,n.jsx)("div",{ref:M,className:"overflow-auto px-4 py-2",style:{height:es},onScroll:()=>{if(M.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=M.current;$.current=t-e-r<50}},children:H&&q.trim()?(0,n.jsx)(tQ,{output:a,query:q,mode:K,currentIdx:J,matchListRef:X}):(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:R,value:A,onChange:e=>_(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=tU[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),h(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),h(A+"\n"),_("")),"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 placeholder:text-muted-foreground",autoComplete:"off",spellCheck:"false"}):(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:E("console.runningText")}),x&&(0,n.jsx)("button",{onClick:x,className:"flex-shrink-0 text-xs text-destructive hover:brightness-125 transition-colors cursor-pointer select-none",children:"Ctrl+C"}),B&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:B})]}),!d&&void 0!==c&&!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===c?"bg-green-500":"bg-red-500"}`}),(0,n.jsx)("span",{children:E("console.exitCode",{code:c})}),(0,n.jsx)("span",{className:"flex-1"}),B&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:B})]})]})})});var tY=r(68459),tZ=r(51914);function tG({cwd:e,tabId:t,onClose:r,onSave:l}){let{t:a}=(0,o.Bd)(),[c,d]=(0,s.useState)({}),[u,m]=(0,s.useState)(""),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!0),g=(0,s.useCallback)(async()=>{p(!0);let r=await i.t4.runPromiseExit(tW(e,t));"Success"===r._tag?d(r.value):console.error("Failed to load env:",r.cause),p(!1)},[e,t]);(0,s.useEffect)(()=>{g()},[g]);let b=()=>{u.trim()&&(d(e=>({...e,[u.trim()]:x})),m(""),h(""))},v=async()=>{let n=await i.t4.runPromiseExit(t_("/api/terminal/env",{cwd:e,tabId:t,env:c}));"Success"===n._tag?(l(c),r()):console.error("Failed to save env:",n.cause)};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl 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:a("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?a("envManager.tabScope"):a("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(ev.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:a("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(c).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:a("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)(tY.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:u,onChange:e=>m(e.target.value),placeholder:a("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:x,onChange:e=>h(e.target.value),placeholder:a("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:!u.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)(tZ.A,{className:"w-4 h-4"})})]}),0===Object.keys(c).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:a("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-accent transition-colors",children:a("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:a("common.save")})]})]})})}var t0=r(10762);function t1({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[l,a]=(0,s.useState)({}),[c,d]=(0,s.useState)(""),[u,m]=(0,s.useState)(""),[x,h]=(0,s.useState)(!0),f=(0,s.useCallback)(async()=>{h(!0);let e=await i.t4.runPromiseExit(tz());"Success"===e._tag?a(e.value):console.error("Failed to load aliases:",e.cause),h(!1)},[]);(0,s.useEffect)(()=>{f()},[f]);let p=()=>{c.trim()&&u.trim()&&(a(e=>({...e,[c.trim()]:u.trim()})),d(""),m(""))},g=async()=>{let r=await i.t4.runPromiseExit(t_("/api/terminal/aliases",{aliases:l}));"Success"===r._tag?(t(l),e()):console.error("Failed to save aliases:",r.cause)};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl 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)(t0.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-accent transition-colors",children:(0,n.jsx)(ev.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:x?(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(l).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 a(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:()=>{a(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)(tY.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:c,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:u,onChange:e=>m(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:!c.trim()||!u.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)(tZ.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(l).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-accent 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 t2=r(53961),t5=r(15813),t4=r(37595),t3=r(49698),t6=r(20232);let t8=new Map;function t9(e){t8.set(e.type,e)}function t7(e){return t8.get(e)}function re(e){for(let t of t8.values())if(t.match(e))return t;return null}let rt=(e,t)=>eM.tryPromise({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 eT.uV({message:`POST ${e} failed`,cause:t})}),rr=(e,t)=>i.t4.runPromise(rt(`/api/${e}/disconnect`,{id:t}).pipe(eM.orElse(()=>eM.void))),rn=e=>i.t4.runPromise(rt("/api/browser/unregister",{id:e}).pipe(eM.orElse(()=>eM.void))),rs=e=>i.t4.runPromise(e.pipe(eM.catchAll(e=>eM.sync(()=>{if(e.cause instanceof Error)throw e.cause;throw Error(e.message)})))),ro=(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}`},rl=(e,t)=>rs(eM.tryPromise({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(ro(n,r.status));return n},catch:t=>new eT.uV({message:`POST ${e} failed`,cause:t})})),ra=(e,t)=>rs(eM.tryPromise({try:async()=>{let r=new URLSearchParams(t),n=await fetch(`${e}?${r}`),s=await n.json();if(!n.ok)throw Error(ro(s,n.status));return s},catch:t=>new eT.uV({message:`GET ${e} failed`,cause:t})})),ri=(e,t)=>rs(eM.tryPromise({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 eT.uV({message:`POST blob ${e} failed`,cause:t})}));var rc=r(53853);function rd(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.set("_cockpit","1"),t.toString()}catch{let t=e.includes("?")?"&":"?";return`${e}${t}_cockpit=1`}}function ru(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.delete("_cockpit"),t.toString()}catch{return e.replace(/[?&]_cockpit=1/,"")}}async function rm(e){let t=(0,rc.f)()?.id??null;return!!t&&new Promise(r=>{try{let n=globalThis.chrome?.runtime;if(!n?.sendMessage)return void r(!1);let s=setTimeout(()=>r(!1),2e3);n.sendMessage(t,{type:"prepare-iframe",url:e},e=>{clearTimeout(s),r(e?.ok??!1)})}catch{r(!1)}})}function rx(e){try{let t=new URL(e).hostname;return"localhost"===t||"127.0.0.1"===t}catch{return!1}}function rh({url:e,id:t,selected:r,maximized:i,expandedHeight:c,bubbleContentHeight:d,onSelect:u,onClose:m,onToggleMaximize:x,onNewTab:h,timestamp:f,onTitleMouseDown:p,initialSleeping:g,onSleep:b,onWake:v}){let{t:j}=(0,o.Bd)(),[w,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[S,L]=(0,s.useState)(e),[E,M]=(0,s.useState)(null),[T,$]=(0,s.useState)(g??!1),P=(0,s.useRef)(null),R=(0,s.useRef)(null),B=(0,s.useRef)(null);(0,s.useEffect)(()=>{L(e)},[e]);let F=(0,s.useRef)(!0),I=(0,s.useCallback)(()=>{T||($(!0),M(null),b?.(t))},[T,t,b]),D=(0,s.useCallback)(()=>{P.current&&(clearTimeout(P.current),P.current=null)},[]),{shortId:A,connected:_,connect:W,disconnect:z}=function(e,t,r){let n=(0,s.useMemo)(()=>tB(e),[e]),[o,i]=(0,s.useState)(!1),c=(0,s.useRef)(null),d=(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)([]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="cockpit:cmd-result"){let{reqId:t,ok:r,data:n,error:s}=e.data,o=c.current;o&&o.readyState===WebSocket.OPEN&&o.send(JSON.stringify({type:"browser:cmd-result",reqId:t,ok:r,data:n,error:s}));return}if(e.data?.type==="cockpit:prepare-screenshot"){let r=t.current;if(!r?.contentWindow)return;let n=new URLSearchParams(window.location.search).get("cwd")||"";window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!0}})),(0,l.F)(a.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{}r.contentWindow?.postMessage({type:"cockpit:screenshot-bounds",reqId:e.data.reqId,bounds:{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)})));return}if(e.data?.type==="cockpit:screenshot-done"){window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!1}})),(0,l.F)(a.n.ScreenshotDone,{});return}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let f=(0,s.useCallback)(e=>{let r=t.current;if(!r?.contentWindow){let t=c.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"browser:cmd-result",reqId:e.reqId,ok:!1,error:"iframe not available (page may be sleeping)"}));return}r.contentWindow.postMessage({type:"cockpit:cmd",reqId:e.reqId,action:e.action,params:e.params},"*")},[t]);(0,s.useEffect)(()=>{if(!o)return;let r=!1;return m.current=!0,!function n(){if(r||!m.current)return;let s="https:"===window.location.protocol?"wss:":"ws:",o=new WebSocket(`${s}//${window.location.host}/ws/browser?fullId=${encodeURIComponent(e)}`);c.current=o,o.onopen=()=>{for(let e of h.current)e();if(h.current=[],d.current.length>0){for(let e of d.current)f(e);d.current=[]}},o.onmessage=e=>{let r;try{r=JSON.parse(e.data)}catch{return}if("browser:cmd"===r.type){let e=r;t.current?.contentWindow&&x.current?f(e):d.current.push(e)}},o.onclose=()=>{c.current=null,!r&&m.current&&(u.current=setTimeout(n,3e3))},o.onerror=()=>o.close()}(),()=>{r=!0,m.current=!1,u.current&&clearTimeout(u.current),c.current&&(c.current.close(),c.current=null),h.current=[]}},[o,e,t,f]),(0,s.useEffect)(()=>{if(r&&d.current.length>0){for(let e of d.current)f(e);d.current=[]}},[r,f]);let p=(0,s.useCallback)(()=>o&&c.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{h.current.push(e),o||i(!0)}),[o]);return{shortId:n,connected:o,connect:p,disconnect:(0,s.useCallback)(()=>{i(!1)},[])}}(t,B,!!E&&!T&&!w),H=(0,s.useRef)(_);H.current=_,(0,s.useEffect)(()=>{let e=R.current;if(!e||T)return;let t=new IntersectionObserver(([e])=>{F.current=e.isIntersecting,e.isIntersecting||H.current?D():(P.current&&clearTimeout(P.current),P.current=setTimeout(I,3e5))});return t.observe(e),()=>t.disconnect()},[T,I,D]),(0,s.useEffect)(()=>{T?z():_?D():F.current||(P.current&&clearTimeout(P.current),P.current=setTimeout(I,3e5))},[_,T,z,D,I]),(0,s.useEffect)(()=>{g&&M(null)},[]);let O=(0,s.useCallback)(()=>{$(!1),v?.(t);let r=rd(e);rx(e)?M(r):rm(e).then(()=>M(r))},[e,t,v]);(0,s.useEffect)(()=>{if(!e||T){e||M(null);return}let t=rd(e);if(rx(e))return void M(t);let r=!1;return rm(e).then(()=>{r||M(t)}),()=>{r=!0}},[e,T]);let q=(0,s.useCallback)(()=>y(!1),[]);(0,s.useEffect)(()=>{let e=R.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,l=()=>{o&&t&&(t.scrollTop=s)},a=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",l)},i=()=>{o=!1,t.removeEventListener("scroll",l),t.style.overflow=n};return e.addEventListener("mouseenter",a),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",a),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",l),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=R.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?h?.(ru(e.data.url),t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&L(ru(e.data.url))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,h]);let V=(0,s.useCallback)(()=>{y(!1),C(j("browser.pageLoadFailed"))},[]),K=(0,s.useCallback)(()=>{if(T)return void O();let e=R.current?.querySelector("iframe");if(e&&E){y(!0),C(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[T,O,E]);(0,s.useEffect)(()=>{e&&!T&&(y(!0),C(null))},[e,T]);let U=(0,s.useCallback)(()=>{S&&window.open(S,"_blank")},[S]);(0,s.useEffect)(()=>{if(!r&&!i)return;let e=e=>{"Escape"===e.key&&i&&(e.stopPropagation(),x()),"m"===e.key&&(e.metaKey||e.ctrlKey)&&r&&(e.preventDefault(),e.stopPropagation(),x())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[i,r,x]);let J=function(e){if(!e)return"";try{let t=new URL(e);return t.port?`${t.hostname}:${t.port}`:t.hostname}catch{return e}}(S),Q=i&&c?c-41:d??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5188],{1058:(e,t,r)=>{r.d(t,{_:()=>a});var n=r(12115),s=r(90717),o=r(86957),l=r(46456);function a({cwd:e,filePath:t}){let[r,i]=(0,n.useState)([]),[c,d]=(0,n.useState)(!1),[u,m]=(0,n.useState)(null),x=(0,n.useCallback)(async()=>{if(!e||!t)return;d(!0),m(null);let r=await o.t4.runPromiseExit((0,l.lb)(e,t));if("Success"===r._tag)i(r.value.comments??[]);else{let e="Fail"===r.cause._tag?r.cause.error:null,t=e?.cause;m(t instanceof Error?t.message:"Failed to load comments")}d(!1)},[e,t]);(0,n.useEffect)(()=>{x()},[x]),(0,n.useEffect)(()=>(0,s.zL)(()=>{x()}),[x]);let h=(0,n.useCallback)(async(r,n,s,a)=>{let c=await o.t4.runPromiseExit((0,l.BC)({cwd:e,filePath:t,startLine:r,endLine:n,content:s,...a?{selectedText:a}:{}}));if("Success"===c._tag&&c.value.comment){let e=c.value.comment;return i(t=>[...t,e]),e}return"Failure"===c._tag&&console.error("Failed to add comment:",c.cause),null},[e,t]),f=(0,n.useCallback)(async(t,r)=>{let n=await o.t4.runPromiseExit((0,l.vv)(e,t,r));if("Success"===n._tag&&n.value.comment){let e=n.value.comment;return i(r=>r.map(r=>r.id===t?e:r)),!0}return"Failure"===n._tag&&console.error("Failed to update comment:",n.cause),!1},[e]),p=(0,n.useCallback)(async t=>{let r=await o.t4.runPromiseExit((0,l.Tu)(e,t));return"Success"===r._tag?(i(e=>e.filter(e=>e.id!==t)),!0):(console.error("Failed to delete comment:",r.cause),!1)},[e]),g=(0,n.useCallback)(e=>r.filter(t=>e>=t.startLine&&e<=t.endLine),[r]);return{comments:r,isLoading:c,error:u,addComment:h,updateComment:f,deleteComment:p,refresh:x,getCommentsForLine:g}}},2228:(e,t,r)=>{r.d(t,{ProjectItem:()=>a});var n=r(95155),s=r(12115),o=r(79114);function l({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-6 h-6 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"4"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function a({index:e,name:t,cwd:r,isActive:i,collapsed:c,hasUnread:d,isLoading:u,onClick:m,onRemove:x,onOpenNote:h}){let{t:f}=(0,o.Bd)(),[p,g]=(0,s.useState)(!1);return(0,n.jsxs)("div",{className:`flex items-center gap-2 px-2 py-1 rounded-lg cursor-pointer transition-colors relative ${c?"justify-center":""} ${i?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary hover:text-foreground"}`,onClick:m,onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),title:r,children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(l,{number:e+1,isActive:i}),d&&!i&&!u&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),u&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"})]}),!c&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"flex-1 truncate text-sm",children:t}),!u&&i?(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}):null]}),p&&!c&&(0,n.jsxs)("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 flex items-center gap-0.5",children:[h&&(0,n.jsx)("button",{className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground transition-colors",onClick:e=>{e.stopPropagation(),h()},title:f("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-500 transition-colors",onClick:e=>{e.stopPropagation(),x()},title:f("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"})})})]})]})}},3292:(e,t,r)=>{r.d(t,{P:()=>c});var n=r(12115),s=r(95045),o=r(75346),l=r(49433),a=r(86957),i=r(82680);function c(){let[e,t]=(0,n.useState)([]),r=(0,n.useCallback)(()=>{let e=l.tryPromise({try:async()=>{let e=await fetch("/api/pinned-sessions");return await e.json()},catch:e=>new i.uV({message:"loadPinnedSessions failed",cause:e})});a.t4.runPromise(e.pipe(l.match({onSuccess:e=>t(e.sessions||[]),onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{r()},[r]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type==="PINNED_SESSIONS_CHANGED"&&r()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[r]);let c=(0,n.useCallback)(e=>{t(e);let r=l.tryPromise({try:async()=>{await fetch("/api/pinned-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessions:e})})},catch:e=>new i.uV({message:"savePinnedSessions failed",cause:e})});a.t4.runFork(r.pipe(l.orElse(()=>l.void))),(0,s.F)(o.n.PinnedSessionsChanged,{})},[]),d=(0,n.useCallback)(t=>e.some(e=>e.sessionId===t),[e]),u=(0,n.useCallback)((t,r,n)=>{e.some(e=>e.sessionId===t)||c([...e,{sessionId:t,cwd:r,customTitle:n}])},[e,c]),m=(0,n.useCallback)(t=>{c(e.filter(e=>e.sessionId!==t))},[e,c]),x=(0,n.useCallback)((t,r)=>{c(e.map(e=>e.sessionId===t?{...e,customTitle:r}:e))},[e,c]);return{pinnedSessions:e,isPinned:d,pinSession:u,unpinSession:m,updateTitle:x,reorder:(0,n.useCallback)(e=>{c(e)},[c]),reload:r}}},7320:(e,t,r)=>{r.d(t,{G:()=>a,t:()=>l});var n=r(95155),s=r(12115),o=r(79114);function l({x:e,y:t,range:r,lineSnapshot:a,container:i,onSubmit:c,onClose:d}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)(""),[h,f]=(0,s.useState)(!1),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0}),j=a?.split("\n").slice(0,5).join("\n"),w=!!a&&a.split("\n").length>5;return(0,s.useEffect)(()=>{if(p.current&&i){let r=i.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>v({x:s,y:o}))}},[e,t,i]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{h||!p.current||p.current.contains(e.target)||d()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d,h]),(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,n.jsx)("div",{className:"px-3 py-2 bg-amber-9/10 border-b border-border",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-amber-11",children:u("comments.addComment")}),(r.start>0||r.end>0)&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("comments.lineRange",{start:r.start,end:r.end})})]})}),a&&(0,n.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,n.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[j,w&&(0,n.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("textarea",{ref:g,value:m,onChange:e=>x(e.target.value),placeholder:u("comments.inputPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:h,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!h&&m.trim()&&(f(!0),c(m.trim()))),"Escape"!==e.key||h||d()}}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:u(h?"comments.submitting":"comments.enterSubmit")})]})]})}function a({x:e,y:t,range:r,filePath:l,lineSnapshot:i,container:c,onSubmit:d,onClose:u,isChatLoading:m}){let{t:x}=(0,o.Bd)(),[h,f]=(0,s.useState)(""),p=(0,s.useRef)(null),g=(0,s.useRef)(null),[b,v]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&c){let r=c.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>v({x:s,y:o}))}},[e,t,c]),(0,s.useEffect)(()=>{g.current?.focus()},[]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&u()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[u]);let j=i?.split("\n").slice(0,5).join("\n"),w=!!i&&i.split("\n").length>5;return(0,n.jsxs)("div",{ref:p,className:"absolute z-[200] w-[640px] bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:b.x,top:b.y},children:[(0,n.jsxs)("div",{className:"px-3 py-2 bg-brand/10 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-brand",children:x("comments.askAI")}),(r.start>0||r.end>0)&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:x("comments.lineRange",{start:r.start,end:r.end})})]}),l&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:l})]}),i&&(0,n.jsx)("div",{className:"px-3 py-2 bg-secondary/50 border-b border-border max-h-24 overflow-hidden",children:(0,n.jsxs)("pre",{className:"text-xs font-mono text-muted-foreground whitespace-pre-wrap break-all",children:[j,w&&(0,n.jsx)("span",{className:"text-muted-foreground/50",children:"..."})]})}),(0,n.jsxs)("div",{className:"p-2",children:[(0,n.jsx)("textarea",{ref:g,value:h,onChange:e=>f(e.target.value),placeholder:x("comments.inputQuestion"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50 disabled:cursor-not-allowed",rows:2,disabled:m,onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),!m&&h.trim()&&(d(h.trim()),u())),"Escape"===e.key&&u()}}),(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:x(m?"comments.aiGenerating":"comments.enterSend")})]})]})}},8648:(e,t,r)=>{r.d(t,{NoteModal:()=>C});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(13439),i=r(37795),c=r(43561),d=r(5989),u=r(76065),m=r(43203),x=r(6268),h=r(48434),f=r(44695),p=r(59265),g=r(26932);function b(e){return e.storage.markdown.getMarkdown()}function v(){return[{label:l.A.t("slashCommands.heading1"),icon:"H1",description:l.A.t("slashCommands.heading1Desc"),action:e=>e.chain().focus().toggleHeading({level:1}).run()},{label:l.A.t("slashCommands.heading2"),icon:"H2",description:l.A.t("slashCommands.heading2Desc"),action:e=>e.chain().focus().toggleHeading({level:2}).run()},{label:l.A.t("slashCommands.heading3"),icon:"H3",description:l.A.t("slashCommands.heading3Desc"),action:e=>e.chain().focus().toggleHeading({level:3}).run()},{label:l.A.t("slashCommands.bulletList"),icon:"•",description:l.A.t("slashCommands.bulletListDesc"),action:e=>e.chain().focus().toggleBulletList().run()},{label:l.A.t("slashCommands.orderedList"),icon:"1.",description:l.A.t("slashCommands.orderedListDesc"),action:e=>e.chain().focus().toggleOrderedList().run()},{label:l.A.t("slashCommands.taskList"),icon:"☑",description:l.A.t("slashCommands.taskListDesc"),action:e=>e.chain().focus().toggleTaskList().run()},{label:l.A.t("slashCommands.blockquote"),icon:"❝",description:l.A.t("slashCommands.blockquoteDesc"),action:e=>e.chain().focus().toggleBlockquote().run()},{label:l.A.t("slashCommands.codeBlock"),icon:"<>",description:l.A.t("slashCommands.codeBlockDesc"),action:e=>e.chain().focus().toggleCodeBlock().run()},{label:l.A.t("slashCommands.table"),icon:"▦",description:l.A.t("slashCommands.tableDesc"),action:e=>e.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()},{label:l.A.t("slashCommands.horizontalRule"),icon:"──",description:l.A.t("slashCommands.horizontalRuleDesc"),action:e=>e.chain().focus().setHorizontalRule().run()},{label:l.A.t("slashCommands.link"),icon:"\uD83D\uDD17",description:l.A.t("slashCommands.linkDesc"),action:e=>{window.dispatchEvent(new CustomEvent("tiptap-insert-link"))}}]}function j({editor:e,query:t,position:r,onClose:o}){let[l,a]=(0,s.useState)(0),i=(0,s.useRef)(null),c=v().filter(e=>e.label.toLowerCase().includes(t.toLowerCase())||e.description.toLowerCase().includes(t.toLowerCase()));(0,s.useEffect)(()=>{queueMicrotask(()=>a(0))},[t]);let d=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(),a(e=>(e+1)%c.length)):"ArrowUp"===e.key?(e.preventDefault(),a(e=>(e-1+c.length)%c.length)):"Enter"===e.key?(e.preventDefault(),c[l]&&d(c[l])):"Escape"===e.key&&(e.preventDefault(),o())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[c,l,o]),0===c.length)?null:(0,n.jsx)("div",{ref:i,className:"slash-command-menu fixed z-[60] bg-popover border border-border rounded-lg shadow-lg py-1 w-56 max-h-64 overflow-y-auto",style:{top:r.top,left:r.left},children:c.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===l?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"}`,onClick:()=>d(e),onMouseEnter:()=>a(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))})}v();var w=r(76043),y=r(86957),k=r(49433),N=r(76900);function C({isOpen:e,onClose:t,projectCwd:r,projectName:v}){let{t:S}=(0,o.Bd)(),[L,E]=(0,s.useState)(!0),[M,T]=(0,s.useState)(!1),$=(0,s.useRef)(null),P=(0,s.useRef)(!1),[R,B]=(0,s.useState)(null),F=(0,s.useRef)(null),I=(0,s.useCallback)(async e=>{T(!0),"Success"===(await y.t4.runPromiseExit((0,N.Cq)(r,e).pipe(k.tapError(e=>k.sync(()=>console.error("Failed to save note:",e))))))._tag&&(P.current=!1),T(!1)},[r]),D=(0,s.useCallback)(e=>{P.current=!0,$.current&&clearTimeout($.current),$.current=setTimeout(()=>{I(e)},5e3)},[I]),A=(0,a.hG)({immediatelyRender:!1,extensions:[i.A.configure({heading:{levels:[1,2,3]}}),c.A.configure({placeholder:()=>l.A.t("editor.placeholder")}),d.XI.configure({resizable:!0}),u.H,m.n,x.A,h._,p.Ay.configure({autolink:!0,linkOnPaste:!0,openOnClick:!1,HTMLAttributes:{class:"tiptap-link",target:"_blank",rel:"noopener noreferrer"}}),f.L.configure({nested:!0}),g.o.configure({html:!0,transformCopiedText:!0,transformPastedText:!0})],editorProps:{attributes:{class:"tiptap-editor focus:outline-none min-h-[60vh] px-6 py-4"},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&&_.current){let e=_.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||R||setTimeout(()=>{if(!_.current)return;let{from:e}=_.current.state.selection;if("/"===_.current.state.doc.textBetween(Math.max(0,e-1),e,"\n")){F.current=e;let t=_.current.view.coordsAtPos(e);B({query:"",position:{top:t.bottom+4,left:t.left}})}},0),!1}},onUpdate:({editor:e})=>{if(D(b(e)),null!==F.current){let{from:t}=e.state.selection;if(t<F.current)B(null),F.current=null;else{let r=e.state.doc.textBetween(F.current,t,"\n");r.includes(" ")||r.includes("\n")?(B(null),F.current=null):B(e=>e?{...e,query:r}:null)}}}}),_=(0,s.useRef)(A);(0,s.useEffect)(()=>{_.current=A},[A]),(0,s.useEffect)(()=>{e&&A&&(E(!0),B(null),F.current=null,y.t4.runPromiseExit((0,N.zF)(r)).then(e=>{"Success"===e._tag?(A.commands.setContent(e.value.content||""),P.current=!1):console.error("Failed to load note:",e.cause),E(!1)}))},[e,A,r]);let W=(0,s.useCallback)(()=>{$.current&&(clearTimeout($.current),$.current=null),P.current&&A&&I(b(A)),B(null),F.current=null,t()},[A,I,t]);return((0,s.useEffect)(()=>()=>{$.current&&clearTimeout($.current)},[]),(0,s.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"===e.key&&(R?(B(null),F.current=null):W())};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,W,R]),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-black/50",onClick:W}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-6xl h-[90vh] mx-4 flex flex-col overflow-hidden",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",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:v?S("editor.noteTitle",{name:v}):S("editor.noteUntitled")}),M&&(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:S("editor.saving")})]}),(0,n.jsx)("button",{onClick:W,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent 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)(w.NoteToolbar,{editor:A}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:L?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:(0,n.jsx)("span",{children:S("common.loading")})}):(0,n.jsx)(a.$Z,{editor:A})})]}),R&&A&&(0,n.jsx)(j,{editor:A,query:R.query,position:R.position,onClose:()=>{B(null),F.current=null}})]}):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},17196:(e,t,r)=>{r.d(t,{Np:()=>d,ZD:()=>i,b8:()=>c,kS:()=>l,sQ:()=>a});var n=r(67014);let s=null,o=["typescript","tsx","javascript","jsx","html","css","scss","json","yaml","python","go","rust","java","ruby","php","bash","shell","markdown","sql","c","cpp","swift","kotlin","dart","lua","graphql","xml"];function l(){return s||(s=(0,n.O_)({themes:["github-dark","github-light"],langs:[...o]})),s}function a(e){let t=e.split("/").pop()?.toLowerCase()||"",r=t.split(".").pop()?.toLowerCase();if(".env"===t||t.startsWith(".env.")||"dockerfile"===t||t.startsWith("dockerfile.")||"makefile"===t)return"bash";let n={ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",html:"html",htm:"html",css:"css",scss:"scss",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",py:"python",go:"go",rs:"rust",java:"java",kt:"kotlin",rb:"ruby",php:"php",cs:"cpp",cpp:"cpp",c:"c",h:"c",sh:"bash",bash:"bash",zsh:"bash",md:"markdown",mdx:"markdown",sql:"sql",swift:"swift",dart:"dart",lua:"lua",graphql:"graphql",gql:"graphql",toml:"yaml",sass:"scss",less:"css",scala:"java",r:"python",vim:"bash",env:"bash"}[r||""]||"text";return o.includes(n)?n:"text"}function i(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function c(e){return e.map(e=>e.color?`<span style="color:${e.color}">${i(e.content)}</span>`:i(e.content)).join("")}function d(e,t,r,n){if(!t)return[];let s=[],o=r?t:t.toLowerCase();for(let t=0;t<e.length;t++){let l=r?e[t]:e[t].toLowerCase(),a=0;for(;;){let e=l.indexOf(o,a);if(-1===e)break;let r=e+o.length;if(n){let n=e>0?l[e-1]:" ",o=r<l.length?l[r]:" ",a=!/\w/.test(n),i=!/\w/.test(o);a&&i&&s.push({lineIndex:t,startCol:e,endCol:r})}else s.push({lineIndex:t,startCol:e,endCol:r});a=e+1}}return s}},21484:(e,t,r)=>{r.d(t,{SettingsModal:()=>x});var n=r(95155),s=r(12115),o=r(79114),l=r(3238),a=r(34075),i=r(12786),c=r(53853),d=r(86957),u=r(49433),m=r(76900);function x({isOpen:e,onClose:t}){let{t:r,i18n:h}=(0,o.Bd)(),{theme:f,setTheme:p}=(0,l.D)(),g=(0,c.G)(),[b,v]=(0,s.useState)(""),[j,w]=(0,s.useState)(""),[y,k]=(0,s.useState)("auto");(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.M5)()).then(e=>{"Success"===e._tag&&e.value.language&&k(e.value.language)})},[e]);let N=(0,s.useCallback)(e=>{k(e),d.t4.runFork((0,m.DZ)({language:e}).pipe(u.orElse(()=>u.void)));let t="auto"===e?navigator.language.startsWith("zh")?"zh":"en":e;h.changeLanguage(t)},[h]),C=g?"installed":"not-installed",S=g?.version??null;if((0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.Wr)()).then(e=>{"Success"===e._tag&&e.value.version&&w(e.value.version)})},[e]),(0,s.useEffect)(()=>{e&&d.t4.runPromiseExit((0,m.Or)()).then(e=>{"Success"===e._tag&&e.value.path&&v(e.value.path)})},[e]),!e)return null;let L=[{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-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-md 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-accent 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:L.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 ${f===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:()=>N(e.value),className:`flex flex-col items-center gap-1 p-3 rounded-lg border transition-colors ${y===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.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"===C?"bg-green-500":"bg-slate-400"}`}),(0,n.jsxs)("span",{children:["installed"===C&&`${r("settings.extensionInstalled")}${S?` (v${S})`:""}`,"not-installed"===C&&r("settings.extensionNotInstalled")]})]}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground leading-relaxed",children:r("settings.extensionDescription")}),"installed"!==C&&(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=b||"chrome-extension";navigator.clipboard.writeText(e),(0,a.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"===C&&(0,n.jsx)("button",{onClick:()=>{g?.id&&window.chrome?.runtime?.sendMessage&&(window.chrome.runtime.sendMessage(g.id,{type:"reload"}),(0,a.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")})]}),b&&(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground font-mono truncate",children:b})]})]}),(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",j?` v${j}`:""]}),(0,n.jsx)("p",{className:"text-muted-foreground/60",children:"One seat. One AI. Everything under control."})]})]})]})]})]})}},23121:(e,t,r)=>{r.d(t,{n:()=>m});var n=r(12115),s=r(95045),o=r(75346),l=r(49433),a=r(86957),i=r(82680);let c=(e,t,r)=>l.tryPromise({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 i.uV({message:`${t} ${e} failed`,cause:r})}),d="SCHEDULED_TASKS_CHANGED";function u(){(0,s.F)(o.n.ScheduledTasksChanged,{}),document.querySelectorAll("iframe").forEach(e=>{try{e.contentWindow?.postMessage({type:d},"*")}catch{}})}function m(){let[e,t]=(0,n.useState)([]),[r,s]=(0,n.useState)(0),o=(0,n.useCallback)(()=>{let e;a.t4.runPromise((e="/api/scheduled-tasks",l.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new i.uV({message:`fetch ${e} failed`,cause:t})})).pipe(l.match({onSuccess:e=>{t(e.tasks??[]),s(e.unreadCount??0)},onFailure:()=>{}})))},[]);(0,n.useEffect)(()=>{o()},[o]),(0,n.useEffect)(()=>{let e=e=>{e.data?.type===d&&o()};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[o]);let m=(0,n.useCallback)(async e=>{let t=await a.t4.runPromiseExit(c("/api/scheduled-tasks","POST",e));if("Success"!==t._tag)return null;let r=t.value;return r.task?(o(),u(),r.task):null},[o]),x=(0,n.useCallback)(async(e,t,r)=>{await a.t4.runPromise(c("/api/scheduled-tasks","PATCH",{id:e,action:t,fields:r}).pipe(l.asVoid).pipe(l.orElse(()=>l.void))),o(),u()},[o]),h=(0,n.useCallback)(e=>x(e,"pause"),[x]),f=(0,n.useCallback)(e=>x(e,"resume"),[x]),p=(0,n.useCallback)(async e=>{await a.t4.runPromise(c("/api/scheduled-tasks","DELETE",{id:e}).pipe(l.asVoid).pipe(l.orElse(()=>l.void))),o(),u()},[o]),g=(0,n.useCallback)((e,t)=>x(e,"update",t),[x]),b=(0,n.useCallback)(e=>x(e,"trigger"),[x]),v=(0,n.useCallback)(e=>x(e,"markRead"),[x]);return{tasks:e,unreadCount:r,reload:o,createTask:m,pauseTask:h,resumeTask:f,triggerTask:b,deleteTask:p,updateTask:g,markRead:v,markAllRead:(0,n.useCallback)(()=>x("_","markAllRead"),[x]),reorderTasks:(0,n.useCallback)(e=>x("_","reorder",{orderedIds:e}),[x])}}},24058:(e,t,r)=>{r.d(t,{TabBar:()=>d});var n=r(95155),s=r(12115),o=r(94287),l=r(64428),a=r(79114);function i({number:e,isActive:t}){return(0,n.jsxs)("svg",{className:`w-5 h-5 flex-shrink-0 ${t?"text-brand":"text-muted-foreground"}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9"}),(0,n.jsx)("text",{x:"12",y:"16",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"12",fontWeight:"500",children:e})]})}function c({onNewTab:e,onNewClaude2Tab:t,onNewCodexTab:r,onNewKimiTab:o,onNewOllamaTab:a,onNewDeepseekTab:i}){let[d,u]=(0,s.useState)(!1),m=(0,s.useRef)(null),x=(0,s.useRef)(null),[h,f]=(0,s.useState)({top:0,right:0}),p=(0,l.F2)();(0,s.useEffect)(()=>{if(!d)return;let e=e=>{x.current&&!x.current.contains(e.target)&&m.current&&!m.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let g=n=>{u(!1),"claude2"===n?t?.():"codex"===n?r?.():"kimi"===n?o?.():"ollama"===n?a?.():"deepseek"===n?i?.():e()};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{ref:m,onClick:()=>{if(!d&&m.current){let e=m.current.getBoundingClientRect(),t=p?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0,s=t?.width??window.innerWidth;f({top:e.bottom+4-n,right:s-(e.right-r)})}u(e=>!e)},className:"flex-shrink-0 p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"New tab",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"})})}),d&&(0,n.jsx)(l.ZL,{children:(0,n.jsxs)("div",{ref:x,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[140px]",style:{top:h.top,right:h.right},children:[(0,n.jsxs)("button",{onClick:()=>g("claude"),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)("span",{className:"w-2 h-2 rounded-full bg-brand flex-shrink-0"}),"Claude Code"]}),(0,n.jsxs)("button",{onClick:()=>g("claude2"),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)("span",{className:"w-2 h-2 rounded-full bg-orange-500 flex-shrink-0"}),"Claude 2"]}),(0,n.jsxs)("button",{onClick:()=>g("codex"),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)("span",{className:"w-2 h-2 rounded-full bg-emerald-500 flex-shrink-0"}),"OpenAI Codex"]}),(0,n.jsxs)("button",{onClick:()=>g("deepseek"),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)("span",{className:"w-2 h-2 rounded-full bg-sky-500 flex-shrink-0"}),"DeepSeek"]}),(0,n.jsxs)("button",{onClick:()=>g("kimi"),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)("span",{className:"w-2 h-2 rounded-full bg-blue-500 flex-shrink-0"}),"Kimi"]}),(0,n.jsxs)("button",{onClick:()=>g("ollama"),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)("span",{className:"w-2 h-2 rounded-full bg-violet-500 flex-shrink-0"}),"Ollama"]})]})})]})}function d({tabs:e,activeTabId:t,unreadTabs:r,dragTabIndex:s,dragOverTabIndex:l,isPinned:u,onTogglePin:m,onSwitchTab:x,onCloseTab:h,onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j,onDragStart:w,onDragOver:y,onDrop:k,onDragEnd:N}){let{t:C}=(0,a.Bd)();return(0,n.jsx)("div",{className:"border-b border-border bg-card shrink-0",children:(0,n.jsxs)("div",{className:"flex items-center px-2 gap-1 overflow-x-auto",children:[e.map((a,c)=>(0,n.jsx)(o.m,{content:a.title,delay:200,className:"flex-1 min-w-16 max-w-32",children:(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>w(c),onDragOver:e=>y(e,c),onDrop:()=>k(c),onDragEnd:N,className:`group flex items-center gap-1 px-3 py-1.5 text-sm cursor-pointer rounded-t-lg transition-colors ${a.id===t?"bg-accent text-foreground":"text-muted-foreground hover:bg-secondary"} ${s===c?"opacity-50":""} ${l===c?"border-l-2 border-brand":""}`,onClick:()=>x(a.id),children:[(0,n.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,n.jsx)(i,{number:c+1,isActive:a.id===t}),a.isLoading&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-orange-9 animate-pulse"}),!a.isLoading&&r.has(a.id)&&a.id!==t&&(0,n.jsx)("span",{className:"absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-red-500"}),m&&u?.(a.id)&&!a.isLoading&&!(r.has(a.id)&&a.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m(a.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-amber-500 hover:text-destructive transition-colors",title:C("tabBar.unpin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})}),m&&!u?.(a.id)&&!a.isLoading&&!(r.has(a.id)&&a.id!==t)&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),m(a.id)},className:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center rounded-full bg-card text-muted-foreground opacity-0 group-hover:opacity-60 hover:!opacity-100 hover:!text-brand transition-all",title:C("tabBar.pin"),children:(0,n.jsx)("svg",{className:"w-2.5 h-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2.5,children:(0,n.jsx)("path",{d:"M16 4h-2V2h-4v2H8c-.55 0-1 .45-1 1v4l-2 3v2h5.97v7l1 1 1-1v-7H19v-2l-2-3V5c0-.55-.45-1-1-1z"})})})]}),(0,n.jsx)("span",{className:"flex-1 min-w-0 truncate",children:a.title}),"claude2"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-orange-500/15 text-orange-400 font-medium leading-relaxed",children:"C2"}),"codex"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-emerald-500/15 text-emerald-400 font-medium leading-relaxed",children:"CX"}),"kimi"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-blue-500/15 text-blue-400 font-medium leading-relaxed",children:"KM"}),"ollama"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-violet-500/15 text-violet-400 font-medium leading-relaxed",children:"OL"}),"deepseek"===a.engine&&(0,n.jsx)("span",{className:"flex-shrink-0 text-[9px] px-1 py-0 rounded bg-sky-500/15 text-sky-400 font-medium leading-relaxed",children:"DS"}),e.length>1&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),h(a.id)},className:"ml-1 p-0.5 rounded hover:bg-muted opacity-0 group-hover:opacity-100 transition-opacity",title:C("tabBar.closeTab"),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:"M6 18L18 6M6 6l12 12"})})})]})},a.id)),(0,n.jsx)(c,{onNewTab:f,onNewClaude2Tab:p,onNewCodexTab:g,onNewKimiTab:b,onNewOllamaTab:v,onNewDeepseekTab:j})]})})}},27570:(e,t,r)=>{r.d(t,{L:()=>s});var n=r(12115);function s({enabled:e,container:t,resolveLineRange:r,buildLineSnapshot:o,dragThresholdPx:l=5}){let a=(0,n.useRef)(null),i=(0,n.useRef)(()=>{}),c=(0,n.useRef)(r),d=(0,n.useRef)(o),u=(0,n.useRef)(l);return c.current=r,d.current=o,u.current=l,(0,n.useEffect)(()=>{if(!e||!t)return;let r=!1,n=0,s=0,o=()=>{a.current&&(a.current=null,i.current())},l=e=>{r=!0,n=e.clientX,s=e.clientY;let t=e.target;t?.closest?.(".floating-toolbar")||o()},m=e=>{r=!1;let l=e.target;if(l?.closest?.(".floating-toolbar"))return;let m=u.current,x=Math.abs(e.clientX-n)>m||Math.abs(e.clientY-s)>m,h=window.getSelection();if(!h||h.isCollapsed||!h.toString().trim()||!x)return void o();let f=h.getRangeAt(0);if(!t.contains(f.commonAncestorContainer))return void o();let p=c.current(f.startContainer),g=c.current(f.endContainer);if(!p||!g)return void o();let b=Math.min(p.start,g.start),v=Math.max(p.end,g.end),j=h.toString(),w=d.current({start:b,end:v});a.current={x:e.clientX,y:e.clientY,range:{start:b,end:v},selectedText:j,lineSnapshot:w},i.current()},x=()=>{if(r||!a.current)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||o()};return t.addEventListener("mousedown",l),document.addEventListener("mouseup",m),document.addEventListener("selectionchange",x),()=>{t.removeEventListener("mousedown",l),document.removeEventListener("mouseup",m),document.removeEventListener("selectionchange",x)}},[e,t]),{toolbarRef:a,bumpRef:i,clearToolbar:()=>{a.current&&(a.current=null,i.current())}}}},33408:(e,t,r)=>{r.d(t,{TabManager:()=>sd});var n=r(95155),s=r(12115),o=r(79114),l=r(95045),a=r(75346),i=r(86957),c=r(83448);function d({isOpen:e,onClose:t,cwd:r,onSelectSession:u}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)([]),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(""),w=(0,s.useRef)(null),y=(0,s.useCallback)(async()=>{if(!r)return;p(!0),b(null);let e=r.replace(/\//g,"-"),t=await i.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?h(t.value):b("Failed to load sessions"),p(!1)},[r]);(0,s.useEffect)(()=>{e&&(y(),setTimeout(()=>{w.current?.focus()},100))},[e,y]),(0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]);let k=x.filter(e=>{if(!v)return!0;let t=v.toLowerCase();return e.title.toLowerCase().includes(t)||e.firstMessages.some(e=>e.toLowerCase().includes(t))||e.lastMessages.some(e=>e.toLowerCase().includes(t))});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-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-6xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col overflow-hidden",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-1 min-w-0",children:[(0,n.jsx)("h2",{className:"text-sm font-medium text-foreground",children:m("sessions.sessionList")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground truncate",title:r,children:r})]}),(0,n.jsxs)("div",{className:"flex items-center gap-3 ml-4",children:[(0,n.jsx)("input",{ref:w,type:"text",placeholder:m("sessions.searchSessions"),value:v,onChange:e=>j(e.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent 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 overflow-y-auto p-4",children:[f&&(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:m("sessions.loadingSessions")})]})}),g&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:g})}),!f&&!g&&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:m(v?"sessions.noMatchingSessions":"sessions.noSessionsYet")})}),!f&&!g&&k.length>0&&(0,n.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:k.map(e=>(0,n.jsxs)("div",{onClick:()=>{let n;return n=(e.path.split("/").pop()||"").replace(".jsonl",""),void(u?(u(n,e.title),t()):(0,l.F)(a.n.OpenProject,{cwd:r,sessionId:n}))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[e.engine&&"claude"!==e.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===e.engine?"bg-orange-500/15 text-orange-11":"ollama"===e.engine?"bg-blue-500/15 text-blue-11":"codex"===e.engine?"bg-green-500/15 text-green-11":"kimi"===e.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:e.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:e.title,children:e.title})]}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:new Date(e.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:[e.firstMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),e.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),e.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},e.path))})]})]})]}):null}var u=r(47650),m=r(64428),x=r(60938),h=r(53213),f=r(64702),p=r(1058),g=r(90717),b=r(70188),v=r(48347),j=r(89109),w=r(7320);function y(e,t){let r=e.split("\n"),n=t.split("\n"),s=[],o=r.length,l=n.length,a=Array(o+1).fill(null).map(()=>Array(l+1).fill(0));for(let e=1;e<=o;e++)for(let t=1;t<=l;t++)r[e-1]===n[t-1]?a[e][t]=a[e-1][t-1]+1:a[e][t]=Math.max(a[e-1][t],a[e][t-1]);let i=o,c=l,d=[];for(;i>0||c>0;)i>0&&c>0&&r[i-1]===n[c-1]?(d.push({type:"unchanged",content:r[i-1],oldLineNum:i,newLineNum:c}),i--,c--):c>0&&(0===i||a[i][c-1]>=a[i-1][c])?(d.push({type:"added",content:n[c-1],newLineNum:c}),c--):(d.push({type:"removed",content:r[i-1],oldLineNum:i}),i--);for(;d.length>0;)s.push(d.pop());return s}var k=r(34075),N=r(56978),C=r(17196);function S({lines:e,containerRef:t}){let r=(0,s.useRef)(null),[o,l]=(0,s.useState)({top:0,height:0});if((0,s.useEffect)(()=>{let e=t.current;if(!e)return;let n=()=>{let{scrollTop:t,scrollHeight:n,clientHeight:s}=e,o=r.current?.clientHeight||0;if(n<=s)l({top:0,height:o});else{let e=o/n;l({top:t*e,height:s*e})}};return n(),e.addEventListener("scroll",n),window.addEventListener("resize",n),()=>{e.removeEventListener("scroll",n),window.removeEventListener("resize",n)}},[t]),0===e.length)return null;let a=100/e.length;return(0,n.jsxs)("div",{ref:r,className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",onClick:e=>{let n=t.current,s=r.current;if(!n||!s)return;let o=s.getBoundingClientRect(),l=(e.clientY-o.top)/o.height*n.scrollHeight-n.clientHeight/2;n.scrollTo({top:Math.max(0,l),behavior:"smooth"})},children:[e.map((e,t)=>"unchanged"!==e.type&&(0,n.jsx)("div",{className:`absolute left-0 right-0 ${"removed"===e.type?"bg-red-9":"bg-green-9"}`,style:{top:`${t*a}%`,height:`${Math.max(a,.5)}%`,minHeight:"2px"}},t)),(0,n.jsx)("div",{className:"absolute left-0 right-0 bg-muted/60 border-y border-border",style:{top:`${o.top}px`,height:`${Math.max(o.height,10)}px`}})]})}var L=r(37614),E=r(27570);function M(e){return e.params?`${e.name}(${e.params.join(", ")})`:e.name}function T({oldContent:e,newContent:t,filePath:r,isNew:l=!1,isDeleted:a=!1,cwd:i,enableComments:c=!1,onPreview:d,previewLabel:m,onContentSearch:x,targetLine:h,compact:$=!1,symbols:P}){let{t:R}=(0,o.Bd)(),B=m??R("common.preview"),F=(0,s.useMemo)(()=>y(e,t),[e,t]),I=(0,s.useRef)(null),D=(0,s.useRef)(null),A=(0,s.useRef)(null),_=(0,s.useRef)(!1),[W,z]=(0,s.useState)(!1),H=(0,b.iN)(),O=(0,v.r)(),q=c&&!!i,{comments:V,addComment:K,updateComment:U,deleteComment:J,refresh:Q}=(0,p._)({cwd:i||"",filePath:r}),[X,Y]=(0,s.useState)(null),[Z,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{A.current!==Z&&G(A.current)});let{toolbarRef:ee,bumpRef:et,clearToolbar:er}=(0,E.L)({enabled:q,container:Z,resolveLineRange:e=>{if(!document.contains(e))return null;let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e,r=t?.closest("[data-new-line]");if(!r)return null;let n=parseInt(r.getAttribute("data-new-line")||"0",10);return!Number.isFinite(n)||n<=0?null:{start:n,end:n}},buildLineSnapshot:({start:e,end:t})=>{let r=[],n=0;for(let s of F)("unchanged"===s.type||"added"===s.type)&&++n>=e&&n<=t&&r.push(s.content);return r.join("\n")}}),[en,es]=(0,s.useState)(null),[eo,el]=(0,s.useState)(null);(0,s.useEffect)(()=>{z(!0)},[]);let ea=(0,s.useMemo)(()=>{let e=new Set;for(let t of V)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[V]),ei=(0,s.useMemo)(()=>{let e=new Map;for(let t of V){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[V]),ec=(0,s.useCallback)((e,t)=>{t.stopPropagation(),Y({comment:e,x:t.clientX,y:t.clientY}),er(),es(null),el(null)},[er]),ed=(0,s.useCallback)(()=>{let e=ee.current;e&&(es({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),er())},[er,ee]),eu=(0,s.useCallback)(()=>{let e=ee.current;e&&(el({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),er())},[er,ee]),em=(0,s.useCallback)(()=>{let e=ee.current;if(!e||!x)return;let t=e.selectedText.trim();er(),t&&x(t)},[x,er,ee]),ex=(0,s.useCallback)(async e=>{if(eo&&O&&i)try{let t=await (0,g.$3)(i),n=[];for(let e of t)n.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});n.push({filePath:r,startLine:eo.range.start,endLine:eo.range.end,codeContent:eo.lineSnapshot});let s=(0,g.Gw)(n,e);O.sendMessage(s),await (0,g.RP)(i),Q(),el(null)}catch(e){console.error("Failed to send to AI:",e)}},[eo,O,r,i,Q]),eh=(0,s.useCallback)(async e=>{en&&(await K(en.range.start,en.range.end,e,en.selectedText),es(null))},[en,K]);(0,s.useEffect)(()=>{let e=D.current,t=A.current;if(!e||!t)return;let r=(e,t)=>{_.current||(_.current=!0,t.scrollLeft=e.scrollLeft,requestAnimationFrame(()=>{_.current=!1}))},n=()=>r(e,t),s=()=>r(t,e);return e.addEventListener("scroll",n),t.addEventListener("scroll",s),()=>{e.removeEventListener("scroll",n),t.removeEventListener("scroll",s)}},[]);let{leftLines:ef,rightLines:ep}=(0,s.useMemo)(()=>{let e=[],t=[],r=0,n=0;for(let s=0;s<F.length;s++){let o=F[s];if("unchanged"===o.type){for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});r++,n++,e.push({lineNum:r,content:o.content,type:"unchanged",originalIdx:s}),t.push({lineNum:n,content:o.content,type:"unchanged",originalIdx:s})}else"removed"===o.type?(r++,e.push({lineNum:r,content:o.content,type:"removed",originalIdx:s})):"added"===o.type&&(n++,t.push({lineNum:n,content:o.content,type:"added",originalIdx:s}))}for(;e.length<t.length;)e.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});for(;t.length<e.length;)t.push({lineNum:0,content:"",type:"unchanged",originalIdx:-1});return{leftLines:e,rightLines:t}},[F]),eg=(0,s.useMemo)(()=>F.map(e=>e.content),[F]),eb=(0,N.C)(eg,r),[ev,ej]=(0,s.useState)(()=>new Map);(0,s.useLayoutEffect)(()=>{ej(new Map),eE.measure()},[ef,ep]);let ew=(0,s.useMemo)(()=>P??[],[P]),{rows:ey,gaps:ek}=(0,s.useMemo)(()=>$?function(e,t,r,n=[]){let s=e.length,o=r=>"unchanged"!==e[r].type||"unchanged"!==t[r].type,l=new Set;for(let e=0;e<s;e++){if(!o(e))continue;let t=Math.max(0,e-3),r=Math.min(s-1,e+3);for(let e=t;e<=r;e++)l.add(e)}let a=[];for(let e=0;e<s;e++){if(l.has(e))continue;let t=e;for(;e<s&&!l.has(e);)e++;a.push({id:a.length,startIdx:t,endIdx:e-1}),e--}for(let e of a){let t=r.get(e.id)??{topRevealed:0,bottomRevealed:0},n=e.endIdx-e.startIdx+1,s=Math.max(0,Math.min(t.topRevealed,n)),o=Math.max(0,Math.min(t.bottomRevealed,n-s));for(let t=e.startIdx;t<e.startIdx+s;t++)l.add(t);for(let t=e.endIdx-o+1;t<=e.endIdx;t++)l.add(t)}let i=[];for(let e=0;e<s;e++){let r;if(l.has(e)){i.push({kind:"diff",idx:e});continue}let o=e;for(;e<s&&!l.has(e);)e++;let c=e-1;e--;let d=a.find(e=>e.startIdx<=o&&c<=e.endIdx);if(!d)continue;let u=c-o+1,m=Math.min(20,u);if(n.length>0&&c+1<s)for(let e=c+1;e<s;e++){let s=t[e].lineNum;if(!(s<=0)){r=function(e,t){let r=null;for(let n of e)n.startLine<=t&&t<=n.endLine&&(!r||n.endLine-n.startLine<r.endLine-r.startLine)&&(r=n);return r}(n,s)??void 0;break}}i.push({kind:"gap-expand",gapId:d.id,direction:"up",revealCount:m}),i.push({kind:"gap-label",gapId:d.id,hiddenCount:u,enclosingFn:r}),i.push({kind:"gap-expand",gapId:d.id,direction:"down",revealCount:m})}return{rows:i,gaps:a}}(ef,ep,ev,ew):{rows:ef.map((e,t)=>({kind:"diff",idx:t})),gaps:[]},[$,ef,ef,ep,ev,ew]),eN=(0,s.useCallback)((e,t)=>{let r=ek.find(t=>t.id===e);r&&ej(n=>{let s=n.get(e)??{topRevealed:0,bottomRevealed:0},o=r.endIdx-r.startIdx+1-s.topRevealed-s.bottomRevealed;if(o<=0)return n;let l=Math.min(20,o),a="up"===t?{...s,topRevealed:s.topRevealed+l}:{...s,bottomRevealed:s.bottomRevealed+l};return new Map(n).set(e,a)})},[ek]),eC=(0,s.useCallback)(e=>{for(let t of ek)if(e>=t.startIdx&&e<=t.endIdx)return t.id;return null},[ek]),eS=(0,s.useCallback)(e=>ey[e]?.kind==="gap-label"?28:20,[ey]),eL=(0,s.useCallback)(e=>{let t=ey[e];if(!t)return e;if("gap-label"===t.kind)return`gl:${t.gapId}`;if("gap-expand"===t.kind)return`ge:${t.gapId}:${t.direction}`;let r=ef[t.idx],n=ep[t.idx];return`d:${r?.lineNum??"x"}:${r?.type??"x"}:${n?.lineNum??"x"}:${n?.type??"x"}`},[ey,ef,ep]),eE=(0,f.Te)({count:ey.length,getScrollElement:()=>I.current,estimateSize:eS,getItemKey:eL,overscan:20}),eM=l?"w-1/4":a?"w-3/4":"w-1/2",eT=l?"w-3/4":a?"w-1/4":"w-1/2",e$=(0,s.useMemo)(()=>ey.map(e=>{if("diff"!==e.kind)return{type:"unchanged"};let t=ef[e.idx],r=ep[e.idx];return"removed"===t.type?{type:"removed"}:r?.type==="added"?{type:"added"}:{type:"unchanged"}}),[ey,ef,ep]),eP=eE.getTotalSize(),eR=eE.getVirtualItems();return(0,s.useEffect)(()=>{if(!h)return;let e=("after"===h.side?ep:ef).findIndex(e=>e.lineNum===h.line);if(-1===e)return;let t=ey.findIndex(t=>"diff"===t.kind&&t.idx===e);if(-1===t){let t=eC(e);if(null!==t){let e=ek.find(e=>e.id===t);if(!e)return;let r=e.endIdx-e.startIdx+1;ej(e=>{let n=e.get(t)??{topRevealed:0,bottomRevealed:0};if(n.topRevealed+n.bottomRevealed>=r)return e;let s=new Map(e);return s.set(t,{topRevealed:r,bottomRevealed:0}),s})}return}let r=requestAnimationFrame(()=>{eE.scrollToIndex(t,{align:"start"})});return()=>cancelAnimationFrame(r)},[h,ef,ep,ey]),(0,n.jsxs)("div",{className:"font-mono flex flex-col h-full text-sm",children:[(0,n.jsxs)("div",{className:"flex flex-shrink-0 border-b border-border",children:[(0,n.jsx)("div",{className:`${eM} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-center text-xs font-medium border-r border-border`,children:l?"(New File)":a?"Deleted":"Old"}),(0,n.jsxs)("div",{className:`${eT} min-w-0 px-2 py-1 bg-accent text-muted-foreground text-xs font-medium relative`,children:[(0,n.jsx)("span",{className:"block text-center",children:a?"(Deleted)":"New"}),(0,n.jsxs)("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2",children:[d&&(0,n.jsx)("button",{onClick:d,className:"text-muted-foreground hover:text-foreground transition-colors",children:B}),!a&&t&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(t),(0,k.oR)(R("diffViewer.copiedAll"))},className:"text-muted-foreground hover:text-foreground transition-colors",children:R("common.copy")})]})]}),(0,n.jsx)("div",{className:"w-4 flex-shrink-0 bg-accent"})]}),(0,n.jsxs)("div",{className:"flex-1 min-h-0 flex",children:[(0,n.jsx)("div",{ref:I,className:"flex-1 overflow-y-auto overflow-x-hidden",children:(0,n.jsxs)("div",{className:"flex",style:{height:`${eP}px`},children:[(0,n.jsx)("div",{ref:D,className:`${eM} overflow-x-auto border-r border-border`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eR.map(e=>{let t=ey[e.index];if("gap-expand"===t.kind||"gap-label"===t.kind){let r="gap-label"===t.kind;return(0,n.jsx)("div",{ref:eE.measureElement,"data-index":e.index,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:r?"bg-accent border-y border-border":""},e.key)}let r=ef[t.idx];return(0,n.jsxs)("div",{ref:eE.measureElement,"data-index":e.index,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===r.type?"bg-red-9/15 dark:bg-red-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:r.lineNum||""}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:r.originalIdx>=0&&eb[r.originalIdx]||(0,C.ZD)(r.content||" ")}})]},e.key)})})}),(0,n.jsx)("div",{ref:A,className:`${eT} overflow-x-auto`,children:(0,n.jsx)("div",{className:"min-w-max h-full",style:{position:"relative"},children:eR.map(e=>{let t=ey[e.index];if("gap-expand"===t.kind)return(0,n.jsx)("button",{ref:eE.measureElement,"data-index":e.index,type:"button",onClick:()=>eN(t.gapId,t.direction),style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center text-[11px] text-foreground/50 hover:bg-accent hover:text-brand active:bg-brand/15 transition-colors duration-100 cursor-pointer focus:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-brand/60",title:R("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),"aria-label":R("up"===t.direction?"diffViewer.gap.expandUp":"diffViewer.gap.expandDown",{count:t.revealCount}),children:(0,n.jsx)("span",{className:"select-none",children:R("diffViewer.gap.more",{count:t.revealCount})})},e.key);if("gap-label"===t.kind)return(0,n.jsxs)("div",{ref:eE.measureElement,"data-index":e.index,"data-gap-id":t.gapId,style:{position:"absolute",top:0,left:0,width:"100%",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:"flex items-center justify-center gap-2 px-3 text-[11px] text-foreground/80 bg-accent border-y border-border min-w-0 select-none",children:[(0,n.jsx)("span",{className:"flex-shrink-0",children:R("diffViewer.gap.hidden",{count:t.hiddenCount})}),t.enclosingFn&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"opacity-50 flex-shrink-0",children:"\xb7"}),(0,n.jsx)("span",{className:"truncate min-w-0 font-medium",title:M(t.enclosingFn),children:M(t.enclosingFn)})]})]},e.key);let r=ep[t.idx],s=r?.lineNum||0,o=s>0&&ea.has(s),l=ei.get(s),a=l?.[0],i=en&&s>=en.range.start&&s<=en.range.end,c=eo&&s>=eo.range.start&&s<=eo.range.end,d=i||c;return(0,n.jsxs)("div",{ref:eE.measureElement,"data-index":e.index,"data-new-line":s||void 0,"data-row-idx":t.idx,style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${Math.max(e.size,eS(e.index))}px`,transform:`translateY(${e.start}px)`},className:`flex ${d?"bg-blue-9/20":o?"bg-amber-9/10":r?.type==="added"?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center gap-0.5 pr-1 text-slate-9 select-none border-r border-border ${d?"bg-blue-9/30":""}`,style:{width:q?"52px":"40px"},children:[q&&s>0&&o&&a&&(0,n.jsx)("button",{onClick:e=>ec(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:R("codeViewer.nComments",{count:l?.length}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),q&&s>0&&!o&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"flex-1 text-right pr-1",children:s||""})]}),(0,n.jsx)("span",{className:"whitespace-pre pl-2",dangerouslySetInnerHTML:{__html:r?.originalIdx>=0&&eb[r.originalIdx]||(0,C.ZD)(r?.content||" ")}})]},e.key)})})})]})}),(0,n.jsx)(S,{lines:e$,containerRef:I})]}),W&&H&&(0,u.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.f,{floatingToolbarRef:ee,bumpRef:et,container:H,onAddComment:ed,onSendToAI:eu,onSearch:x?em:void 0,isChatLoading:O?.isLoading??!1}),en&&(0,n.jsx)(w.t,{x:en.x,y:en.y,range:en.range,lineSnapshot:en.lineSnapshot,container:H,onSubmit:eh,onClose:()=>es(null)}),eo&&(0,n.jsx)(w.G,{x:eo.x,y:eo.y,range:eo.range,filePath:r,lineSnapshot:eo.lineSnapshot,container:H,onSubmit:ex,onClose:()=>el(null),isChatLoading:O?.isLoading}),X&&(0,n.jsx)(L.t,{x:X.x,y:X.y,comment:X.comment,container:H,onClose:()=>Y(null),onUpdateComment:U,onDeleteComment:J})]}),H)]})}function $({oldContent:e,newContent:t,filePath:r}){let o=(0,s.useMemo)(()=>y(e,t),[e,t]),l=(0,s.useRef)(null),a=(0,s.useMemo)(()=>o.map(e=>e.content),[o]),i=(0,N.C)(a,r),c=(0,s.useCallback)(e=>{let t=o[e];return t?`${t.type}:${t.oldLineNum??"x"}:${t.newLineNum??"x"}`:e},[o]),d=(0,f.Te)({count:o.length,getScrollElement:()=>l.current,estimateSize:()=>20,getItemKey:c,overscan:20});return(0,n.jsx)("div",{ref:l,className:"font-mono text-sm overflow-auto h-full",children:(0,n.jsx)("div",{style:{height:`${d.getTotalSize()}px`,position:"relative"},children:d.getVirtualItems().map(e=>{let t=o[e.index];return(0,n.jsxs)("div",{style:{position:"absolute",top:0,left:0,minWidth:"100%",width:"max-content",height:`${e.size}px`,transform:`translateY(${e.start}px)`},className:`flex ${"removed"===t.type?"bg-red-9/15 dark:bg-red-9/25":"added"===t.type?"bg-green-9/15 dark:bg-green-9/25":""}`,children:[(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"added"!==t.type?t.oldLineNum:""}),(0,n.jsx)("span",{className:"w-10 flex-shrink-0 text-right pr-2 text-slate-9 select-none border-r border-border",children:"removed"!==t.type?t.newLineNum:""}),(0,n.jsx)("span",{className:`w-6 flex-shrink-0 text-center select-none ${"removed"===t.type?"text-red-11":"added"===t.type?"text-green-11":"text-slate-9"}`,children:"removed"===t.type?"-":"added"===t.type?"+":" "}),(0,n.jsx)("span",{className:"flex-1 whitespace-pre pl-1",dangerouslySetInnerHTML:{__html:i[e.index]||(0,C.ZD)(t.content||" ")}})]},e.key)})})})}let P={ts:"#3178c6",tsx:"#3178c6",js:"#f1e05a",jsx:"#61dafb",mjs:"#f1e05a",cjs:"#f1e05a",html:"#e44d26",css:"#563d7c",scss:"#cd6799",sass:"#cd6799",less:"#1d365d",vue:"#41b883",svelte:"#ff3e00",json:"#cbcb41",yaml:"#cb171e",yml:"#cb171e",toml:"#9c4121",xml:"#e37933",env:"#ecd53f",md:"#519aba",mdx:"#519aba",txt:"#89898a",py:"#3572a5",go:"#00add8",rs:"#dea584",java:"#b07219",kt:"#a97bff",kts:"#a97bff",c:"#555555",h:"#555555",cpp:"#f34b7d",hpp:"#f34b7d",rb:"#701516",php:"#4f5d95",sh:"#89e051",bash:"#89e051",zsh:"#89e051",png:"#a074c4",jpg:"#a074c4",jpeg:"#a074c4",gif:"#a074c4",svg:"#ffb13b",webp:"#a074c4",ico:"#a074c4",lock:"#89898a",gitignore:"#f14e32",dockerfile:"#2496ed",sql:"#e38c00",graphql:"#e535ab",gql:"#e535ab",default:"#8a8a8a"},R={"package.json":"#cb3837","package-lock.json":"#cb3837","tsconfig.json":"#3178c6","jsconfig.json":"#f1e05a",".gitignore":"#f14e32",".eslintrc":"#4b32c3",".eslintrc.js":"#4b32c3",".eslintrc.json":"#4b32c3",".prettierrc":"#56b3b4",dockerfile:"#2496ed",".env":"#ecd53f",".env.local":"#ecd53f",".env.development":"#ecd53f",".env.production":"#ecd53f","readme.md":"#519aba",license:"#d4af37",makefile:"#6d8086","cargo.toml":"#dea584","go.mod":"#00add8","go.sum":"#00add8","requirements.txt":"#3572a5","yarn.lock":"#2c8ebb","pnpm-lock.yaml":"#f9ad00","vite.config.ts":"#646cff","vite.config.js":"#646cff","next.config.js":"#000000","next.config.mjs":"#000000","tailwind.config.js":"#38bdf8","tailwind.config.ts":"#38bdf8"};function B({name:e,className:t="",size:r=16}){let s,o=R[s=e.toLowerCase()]?R[s]:P[e.split(".").pop()?.toLowerCase()||""]||P.default,l=e.split(".").pop()?.toLowerCase()||"";return["ts","tsx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M7 10h10M12 10v8",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):["js","jsx","mjs","cjs"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"20",rx:"2",fill:o}),(0,n.jsx)("path",{d:"M10 10v6c0 1-1 2-2 2M14 10v4c0 2 4 2 4 0v-4",stroke:"#323330",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):"jsx"===l||"tsx"===l&&e.includes("component")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(60 12 12)"}),(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",stroke:"#61dafb",strokeWidth:"1.5",fill:"none",transform:"rotate(120 12 12)"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2",fill:"#61dafb"})]}):"json"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 4C4 4 4 6 4 8v2c0 1-1 2-2 2 1 0 2 1 2 2v2c0 2 0 4 2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M18 4c2 0 2 2 2 4v2c0 1 1 2 2 2-1 0-2 1-2 2v2c0 2 0 4-2 4",stroke:o,strokeWidth:"2",fill:"none",strokeLinecap:"round"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1.5",fill:o})]}):["md","mdx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M5 15V9l3 4 3-4v6M17 12l-2-3v6M17 12l2-3v6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["py","pyi","pyx"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M12 4c-4 0-4 2-4 3v2h5v1H6c-2 0-3 2-3 4s1 4 3 4h2v-2c0-2 1-3 3-3h4c1 0 2-1 2-2V7c0-2-2-3-5-3z",fill:"#3572a5"}),(0,n.jsx)("path",{d:"M12 20c4 0 4-2 4-3v-2h-5v-1h7c2 0 3-2 3-4s-1-4-3-4h-2v2c0 2-1 3-3 3h-4c-1 0-2 1-2 2v4c0 2 2 3 5 3z",fill:"#ffd43b"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"1",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"17",r:"1",fill:"white"})]}):"go"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"12",rx:"8",ry:"6",fill:o}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"1.5",fill:"white"}),(0,n.jsx)("circle",{cx:"9",cy:"11",r:"0.7",fill:"#333"}),(0,n.jsx)("circle",{cx:"15",cy:"11",r:"0.7",fill:"#333"})]}):"rs"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:o,strokeWidth:"2",fill:"none"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:o}),(0,n.jsx)("path",{d:"M12 3v3M12 18v3M3 12h3M18 12h3",stroke:o,strokeWidth:"2",strokeLinecap:"round"})]}):["png","jpg","jpeg","gif","webp","ico","bmp"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"9",r:"2",fill:o}),(0,n.jsx)("path",{d:"M3 16l5-5 3 3 4-4 6 6",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"svg"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 12 Q12 6 17 12 Q12 18 7 12",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"html"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M8 7h8l-.5 6-3.5 1-3.5-1-.2-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["css","scss","sass","less"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M4 3l1.5 17L12 22l6.5-2L20 3H4z",fill:o}),(0,n.jsx)("path",{d:"M15 8H9l.3 3h5.2l-.4 4-2.1.7-2.1-.7-.1-2",stroke:"white",strokeWidth:"1.2",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):["yaml","yml"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M7 8l3 4v5M17 8l-3 4v5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):["sh","bash","zsh","fish"].includes(l)?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",fill:"#1e1e1e",stroke:"#555",strokeWidth:"1"}),(0,n.jsx)("path",{d:"M6 9l3 3-3 3M12 15h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}):"gitignore"===l||".gitignore"===e.toLowerCase()?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"9",fill:o}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3",fill:"white"}),(0,n.jsx)("path",{d:"M12 6v3M12 15v3M6 12h3M15 12h3",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):"dockerfile"===l||"dockerfile"===e.toLowerCase()||e.toLowerCase().startsWith("dockerfile")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M3 12h3v3H3zM7 12h3v3H7zM11 12h3v3h-3zM7 8h3v3H7zM11 8h3v3h-3zM11 4h3v3h-3zM15 12h3v3h-3z",fill:o}),(0,n.jsx)("path",{d:"M21 13c-1-2-3-2-4-2h-1c0-1 0-2-2-3h-1v1c0 1-1 2-2 2H3c-1 3 0 6 2 8s5 3 9 3c5 0 8-2 10-6",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"env"===l||e.startsWith(".env")?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("circle",{cx:"8",cy:"8",r:"2",fill:o}),(0,n.jsx)("path",{d:"M12 8h6M8 12h8M8 16h5",stroke:o,strokeWidth:"1.5",strokeLinecap:"round"})]}):"sql"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("ellipse",{cx:"12",cy:"7",rx:"8",ry:"3",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 7v10c0 1.7 3.6 3 8 3s8-1.3 8-3V7",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M4 12c0 1.7 3.6 3 8 3s8-1.3 8-3",stroke:o,strokeWidth:"1.5",fill:"none"})]}):"vue"===l?(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M2 4h4l6 10 6-10h4L12 22 2 4z",fill:o}),(0,n.jsx)("path",{d:"M6 4h4l2 4 2-4h4l-6 10L6 4z",fill:"#35495e"})]}):(0,n.jsxs)("svg",{width:r,height:r,viewBox:"0 0 24 24",fill:"none",className:t,children:[(0,n.jsx)("path",{d:"M6 3h8l5 5v13H6V3z",stroke:o,strokeWidth:"1.5",fill:"none"}),(0,n.jsx)("path",{d:"M14 3v5h5",stroke:o,strokeWidth:"1.5",fill:"none"})]})}function F({status:e}){let{label:t,className:r}={added:{label:"A",className:"text-green-11"},untracked:{label:"A",className:"text-green-11"},modified:{label:"M",className:"text-amber-11"},deleted:{label:"D",className:"text-red-11"},renamed:{label:"R",className:"text-brand"}}[e]||{label:"?",className:"text-muted-foreground"};return(0,n.jsx)("span",{className:`text-xs font-bold ${r}`,children:t})}let I=s.memo(function e({node:t,level:r,selectedPath:o,expandedPaths:l,onSelect:a,onToggle:i,onContextMenu:c,showChanges:d=!1,renderActions:u}){let m=o===t.path,x=l.has(t.path),h=(0,s.useCallback)(()=>{t.isDirectory?i(t.path):a(t)},[t,a,i]),f=(0,s.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),c(e,t.path,t.isDirectory)},[t.path,t.isDirectory,c]);return t.isDirectory?(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"flex items-center gap-1 py-0.5 px-2 pr-3 hover:bg-accent cursor-pointer whitespace-nowrap group",style:{paddingLeft:`${12*r+8}px`},onClick:h,onContextMenu:f,children:[(0,n.jsx)("span",{className:"text-slate-9 text-xs",children:x?"▼":"▶"}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1 truncate","data-tooltip":t.path,children:t.name}),u&&u(t)]}),x&&t.children.map(t=>(0,n.jsx)(e,{node:t,level:r+1,selectedPath:o,expandedPaths:l,onSelect:a,onToggle:i,onContextMenu:c,showChanges:d,renderActions:u},t.path))]}):(0,n.jsxs)("div",{className:`flex items-center gap-1.5 py-0.5 px-2 pr-3 cursor-pointer whitespace-nowrap group ${m?"bg-brand/10":"hover:bg-accent"}`,style:{paddingLeft:`${12*r+8}px`},onClick:h,onContextMenu:f,children:[(0,n.jsx)(B,{name:t.name,size:16,className:"flex-shrink-0"}),(0,n.jsx)("span",{className:`text-sm flex-1 truncate ${m?"text-brand":"text-foreground"}`,"data-tooltip":t.path,children:t.name}),t.status&&(0,n.jsx)(F,{status:t.status}),d&&void 0!==t.additions&&void 0!==t.deletions&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{className:"text-xs text-green-11",children:["+",t.additions]}),(0,n.jsxs)("span",{className:"text-xs text-red-11",children:["-",t.deletions]})]}),u&&u(t)]})});function D({files:e,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:l,cwd:a,showChanges:i=!1,renderActions:c,emptyMessage:d,className:u}){let{t:m}=(0,o.Bd)(),x=d??m("gitFileTree.noFiles"),{contextMenu:h,showContextMenu:f,hideContextMenu:p}=(0,b.Ee)();return 0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-slate-9",children:x}):(0,n.jsxs)("div",{className:u||"py-1",children:[e.map(e=>(0,n.jsx)(I,{node:e,level:0,selectedPath:t,expandedPaths:r,onSelect:s,onToggle:l,onContextMenu:f,showChanges:i,renderActions:c},e.path)),h&&(0,n.jsx)(b.ft,{x:h.x,y:h.y,path:h.path,cwd:a,isDirectory:h.isDirectory,onClose:p})]})}function A(e){let t=[];for(let r of e){let e=r.path.split("/"),n=t;for(let t=0;t<e.length;t++){let s=e[t],o=t===e.length-1,l=e.slice(0,t+1).join("/"),a=n.find(e=>e.name===s);a||(a={name:s,path:l,isDirectory:!o,children:[],...o&&{status:r.status,additions:r.additions,deletions:r.deletions,oldPath:r.oldPath,file:r}},n.push(a)),o||(n=a.children)}}let r=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>r(e.children))};return r(t),t}function _(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),r(n.children))};return r(e),t}function W(e){let t=[],r=e=>{if(e.isDirectory)for(let t of e.children)r(t);else t.push(e)};return r(e),t}var z=r(69809);function H(e){try{let t=JSON.parse(e);return Q(t,0)}catch{return e}}let O="#79c0ff",q="#a5d6ff",V="#ff7b72",K="#8b949e",U=(e,t)=>s.createElement("span",{style:{color:e}},t);function J({label:e,labelColor:t,value:r,indent:n}){let[o,l]=s.useState(!1),[a,i]=s.useState({x:0,y:0}),c="string"==typeof r&&r.replace(/\\n/g,"\n").split("\n").length>3,d={onMouseDown:e=>{i({x:e.clientX,y:e.clientY})},onClick:e=>{let t=e.clientX-a.x,r=e.clientY-a.y;t*t+r*r>25||(e.stopPropagation(),l(e=>!e))},style:{cursor:"pointer"}};if(c&&o&&"string"==typeof r){let n=r.replace(/\\n/g,"\n").split("\n")[0],o=r.replace(/\\n/g,"\n").split("\n").length;return s.createElement("span",d,U(t,e),U(K,": "),U(q,n),U("#6e7681",` ${z.A.t("toolCall.foldedLines",{count:o})}`))}let u=s.createElement(s.Fragment,null,U(t,e),U(K,": "),Q(r,n));return c?s.createElement("span",d,u):u}function Q(e,t){let r=" ".repeat(t);if(null===e)return U(V,"null");if(void 0===e)return U(V,"undefined");if("string"==typeof e)return U(q,e.replace(/\\n/g,"\n").replace(/\n/g,"\n"+r));if("number"==typeof e)return U("#79c0ff",String(e));if("boolean"==typeof e)return U(V,String(e));if(Array.isArray(e))return 0===e.length?U(K,"[]"):s.createElement(s.Fragment,null,U(K,"["),"\n",...e.map((n,o)=>s.createElement("span",{key:o},r+" ",s.createElement(J,{label:`[${o}]`,labelColor:O,value:n,indent:t+1}),o<e.length-1?s.createElement(s.Fragment,null,U(K,","),"\n"):"\n")),r,U(K,"]"));if("object"==typeof e){let n=Object.entries(e);return 0===n.length?U(K,"{}"):s.createElement(s.Fragment,null,U(K,"{"),"\n",...n.map(([e,o],l)=>s.createElement("span",{key:e},r+" ",s.createElement(J,{label:e,labelColor:O,value:o,indent:t+1}),l<n.length-1?s.createElement(s.Fragment,null,U(K,","),"\n"):"\n")),r,U(K,"}"))}return String(e)}let X=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg",".bmp",".ico",".avif"]);function Y(e){let t=e.slice(e.lastIndexOf(".")).toLowerCase();return X.has(t)}function Z(e){return e.toLowerCase().endsWith(".md")}let G="json-search-highlight-style";function ee(e){let[t,r]=(0,s.useState)(!1),[n,o]=(0,s.useState)(""),[l,a]=(0,s.useState)(!1),[i,c]=(0,s.useState)(0),[d,u]=(0,s.useState)(0),m=(0,s.useRef)(null),x=(0,s.useRef)([]),h=(0,s.useCallback)(()=>{let t;CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),x.current=[];let r=e.current;if(!r||!n){c(0),u(0);return}!function(){if(document.getElementById(G))return;let e=document.createElement("style");e.id=G,e.textContent="::highlight(json-search){background:rgba(217,119,6,.3)}::highlight(json-search-current){background:rgba(217,119,6,.5)}",document.head.appendChild(e)}();let s=r.textContent||"",o=l?n:n.toLowerCase(),a=l?s:s.toLowerCase(),i=[],d=0;for(;d<a.length;){let e=a.indexOf(o,d);if(-1===e)break;i.push([e,e+o.length]),d=e+1}if(0===i.length){c(0),u(0);return}let m=document.createTreeWalker(r,NodeFilter.SHOW_TEXT),h=0,f=0,p=[],g=null,b=0;for(;(t=m.nextNode())&&f<i.length;){let e=t.textContent?.length||0,r=h,n=h+e;for(;f<i.length;){let[e,s]=i[f];if(e>=n)break;if(!g)if(e>=r)(g=document.createRange()).setStart(t,e-r),b=s;else break;if(b<=n)g.setEnd(t,b-r),p.push(g),g=null,f++;else break}h=n}x.current=p,c(p.length),u(e=>p.length>0?Math.min(e,p.length-1):0),CSS.highlights&&p.length>0&&CSS.highlights.set("json-search",new Highlight(...p))},[e,n,l]),f=(0,s.useCallback)((e,t)=>{let r=e.getBoundingClientRect();(t.top<r.top||t.bottom>r.bottom)&&(e.scrollTop+=t.top-r.top-r.height/2+t.height/2)},[]),p=(0,s.useCallback)(t=>{CSS.highlights?.delete("json-search-current");let r=x.current[t];if(!r||!CSS.highlights)return;CSS.highlights.set("json-search-current",new Highlight(r));let n=r.getBoundingClientRect(),s=e.current?.parentElement;s&&f(s,n)},[e,f]);(0,s.useEffect)(()=>{queueMicrotask(()=>h())},[h]),(0,s.useEffect)(()=>{p(d)},[d,i,p]),(0,s.useEffect)(()=>{let t=e.current;if(!t||!n)return;let r=new MutationObserver(()=>h());return r.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>r.disconnect()},[e,n,h]),(0,s.useEffect)(()=>{t||(CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current"),x.current=[])},[t]),(0,s.useEffect)(()=>()=>{CSS.highlights?.delete("json-search"),CSS.highlights?.delete("json-search-current")},[]);let g=(0,s.useCallback)(()=>{0!==i&&u(e=>(e+1)%i)},[i]),b=(0,s.useCallback)(()=>{0!==i&&u(e=>(e-1+i)%i)},[i]),v=(0,s.useCallback)(()=>{r(!0),setTimeout(()=>m.current?.focus(),0)},[]),j=(0,s.useCallback)(()=>{r(!1),o(""),u(0)},[]),w=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?b():g()),"Escape"===e.key&&(e.preventDefault(),j())},[g,b,j]);return{isVisible:t,query:n,setQuery:o,caseSensitive:l,setCaseSensitive:a,matchCount:i,currentIndex:d,searchInputRef:m,open:v,close:j,goToNext:g,goToPrev:b,handleKeyDown:w}}function et({search:e}){return e.isVisible?s.createElement("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border"},s.createElement("input",{ref:e.searchInputRef,type:"text",value:e.query,onChange:t=>e.setQuery(t.target.value),onKeyDown:e.handleKeyDown,placeholder:z.A.t("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),s.createElement("button",{onClick:()=>e.setCaseSensitive(e=>!e),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e.caseSensitive?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:z.A.t("codeViewer.caseSensitive")},"Aa"),s.createElement("span",{className:"text-xs text-muted-foreground"},e.matchCount>0?`${e.currentIndex+1}/${e.matchCount}`:z.A.t("common.noMatch")),s.createElement("button",{onClick:e.goToPrev,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:z.A.t("common.previous")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}))),s.createElement("button",{onClick:e.goToNext,disabled:0===e.matchCount,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:z.A.t("common.next")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"}))),s.createElement("button",{onClick:e.close,className:"p-1 rounded hover:bg-accent",title:z.A.t("common.close")},s.createElement("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},s.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))):null}function er({isOpen:e,onClose:t,commit:r,cwd:l,embedded:a=!1,initialFilePath:c,onContentSearch:d}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)(null),[w,y]=(0,s.useState)(null),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),M=(0,s.useRef)(null),$=ee(M);(0,s.useEffect)(()=>{let r=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key&&L){e.preventDefault(),$.open();return}if("Escape"===e.key){if($.isVisible)return void $.close();if(L)return void E(null);t()}};if(e)return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,L,$]),(0,s.useEffect)(()=>{e&&r&&(queueMicrotask(()=>{x([]),p([]),j(null),y(null),N(!0)}),i.t4.runPromiseExit((0,h.Zi)(l,r.hash)).then(e=>{if("Success"===e._tag){let t=e.value.files??[];x(t);let n=A(t);if(p(n),b(new Set(_(n))),c&&t.length>0){let e=t.find(e=>e.path===c);e&&setTimeout(()=>{j(e),i.t4.runPromiseExit((0,h.Zi)(l,r.hash,e.path)).then(e=>{"Success"===e._tag?y(e.value):console.error(e.cause)})},0)}}else console.error(e.cause);N(!1)}))},[e,r,l,c]);let P=(0,s.useCallback)(e=>{r&&(j(e),S(!0),i.t4.runPromiseExit((0,h.Zi)(l,r.hash,e.path)).then(e=>{"Success"===e._tag?y(e.value):console.error(e.cause),S(!1)}))},[l,r]),R=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),B=(0,s.useMemo)(()=>{if(!r)return"";if(r.date){let e,t,n,s,o,l,a;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"),l=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0"),n?`${s}-${o} ${l}:${a}`:`${e.getFullYear()}-${s}-${o} ${l}:${a}`}return r.time?new Date(1e3*r.time).toLocaleString():""},[r]);if(!e||!r)return null;let F=(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 bg-secondary 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-slate-9",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-slate-9",children:u("commitDetail.author")}),(0,n.jsx)("span",{children:r.author}),(0,n.jsxs)("span",{className:"text-slate-9",children:["<",r.authorEmail,">"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:u("commitDetail.date")}),(0,n.jsx)("span",{children:B}),r.relativeDate&&(0,n.jsxs)("span",{className:"text-slate-9",children:["(",r.relativeDate,")"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("span",{className:"text-slate-9",children:u("commitDetail.files")}),(0,n.jsx)("span",{children:u("commitDetail.nChanges",{count:m.length})})]})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)("div",{className:"w-72 flex-shrink-0 border-r border-border overflow-y-auto overflow-x-hidden",children:k?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:u("commitDetail.loadingFiles")}):(0,n.jsx)(D,{files:f,selectedPath:v?.path||null,expandedPaths:g,onSelect:e=>e.file&&P(e.file),onToggle:R,cwd:l,showChanges:!0,emptyMessage:u("commitDetail.noFileChanges"),className:"py-1"})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:C?(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:u("commitDetail.loadingDiff")}):w?(0,n.jsx)(T,{oldContent:w.oldContent,newContent:w.newContent,filePath:w.filePath,isNew:w.isNew,isDeleted:w.isDeleted,cwd:l,enableComments:!0,onPreview:!w.isDeleted&&w.filePath.endsWith(".json")?()=>E({content:w.newContent,filePath:w.filePath}):void 0,previewLabel:u("common.readable"),onContentSearch:d}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground text-sm",children:u("commitDetail.selectFileToView")})})]})]}),I=L&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>E(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl 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:L.filePath}),(0,n.jsx)("button",{onClick:()=>E(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent 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)(et,{search:$}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:M,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:H(L.content)})})]})});return a?(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-slate-9 hover:text-foreground hover:bg-accent 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"})})}),F,I]}):(0,n.jsx)("div",{className:"fixed inset-0 z-[60] bg-black/50",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-slate-9 hover:text-foreground hover:bg-accent 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"})})})]}),F,I]})})}let en={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"},"?":{text:"text-slate-9",bg:"bg-slate-9/20"},R:{text:"text-blue-11",bg:"bg-blue-9/20"}},es=s.memo(function({item:e,isSelected:t,isExpanded:r,isLoading:o,onSelect:l,onToggle:a,onContextMenu:i,renderActions:c}){let{node:d,level:u,gitStatus:m,hasChangedChildren:x}=e,h=m?en[m]:null,f=(0,s.useCallback)(()=>{d.isDirectory?a(d.path):l(d.path)},[d.isDirectory,d.path,l,a]),p=(0,s.useCallback)(e=>{i(e,d.path,d.isDirectory)},[d.path,d.isDirectory,i]),g=!d.isDirectory&&(".env"===d.name||d.name.startsWith(".env.")),b=m?h.text:x?"text-amber-11":g?"text-yellow-600 dark:text-yellow-500":t&&!d.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-accent ${t?"bg-brand/10":""}`,style:{paddingLeft:`${12*u+8}px`},onClick:f,onContextMenu:p,children:[d.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)(B,{name:d.name,size:16,className:"flex-shrink-0 ml-4"}),(0,n.jsx)("span",{className:`text-sm truncate flex-1 ${b}`,"data-tooltip":d.isSymlink&&d.symlinkTarget?`${d.path} → ${d.symlinkTarget}`:d.path,children:d.name}),d.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}),d.isDirectory&&x&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-9 flex-shrink-0"}),c?.(d)]})});function eo({files:e,selectedPath:t,expandedPaths:r,matchedPaths:o=null,gitStatusMap:l=null,loadingDirs:a,onSelect:i,onToggle:c,cwd:d,shouldScrollToSelected:u=!1,onScrolledToSelected:m,className:x,renderActions:h,onCreateFile:p,onDelete:g,onRefresh:v,onCopyFile:j,onPaste:w}){let y=(0,s.useRef)(null),{contextMenu:k,showContextMenu:N,hideContextMenu:C}=(0,b.Ee)(),S=(0,s.useMemo)(()=>(function e(t,r,n,s=null,o=0){let l=[];for(let a of t){if(null!==n&&!n.has(a.path))continue;let t=s?.get(a.path),i=a.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}(a.path,s):void 0;l.push({node:a,level:o,gitStatus:t,hasChangedChildren:i}),a.isDirectory&&a.children&&r.has(a.path)&&l.push(...e(a.children,r,n,s,o+1))}return l})(e,r,o,l),[e,r,o,l]),L=(0,f.Te)({count:S.length,getScrollElement:()=>y.current,estimateSize:()=>26,overscan:10}),E=(0,s.useRef)(m);return(E.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(()=>{L.scrollToIndex(e,{align:"center"}),E.current?.()},150);return()=>clearTimeout(t)}}},[u,t,S,L]),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:y,className:x||"h-full overflow-y-auto",style:{willChange:"transform"},children:[(0,n.jsx)("div",{style:{height:`${L.getTotalSize()}px`,width:"100%",position:"relative"},children:L.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)(es,{item:s,isSelected:t===s.node.path,isExpanded:r.has(s.node.path),isLoading:a?.has(s.node.path),onSelect:i,onToggle:c,onContextMenu:N,renderActions:h})},s.node.path)})}),k&&(0,n.jsx)(b.ft,{x:k.x,y:k.y,path:k.path,cwd:d,isDirectory:k.isDirectory,onClose:C,onCreateFile:p,onDelete:g,onRefresh:v,onCopyFile:j,onPaste:w})]})}var el=r(38408),ea=r(82292),ei=r(45048),ec=r(97251),ed=r(47176),eu=r(79968);let em=[ec.W];function ex({content:e,filePath:t,cwd:r,onClose:l,sourceFile:a}){let i=a||(r&&t.startsWith(r)?t.slice(r.endsWith("/")?r.length:r.length+1):t),{t:c}=(0,o.Bd)(),d=(0,b.iN)(),m=(0,v.r)(),{comments:x,addComment:h,updateComment:f,deleteComment:y,refresh:k}=(0,p._)({cwd:r,filePath:t}),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(null),[T,$]=(0,s.useState)(null),[P,R]=(0,s.useState)(null),B=(0,s.useMemo)(()=>e.split("\n"),[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>C(!0))},[]);let[F,I]=(0,s.useState)(null),D=(0,s.useRef)(null);(0,s.useEffect)(()=>{D.current!==F&&I(D.current)});let{toolbarRef:A,bumpRef:_,clearToolbar:W}=(0,E.L)({enabled:!0,container:F,resolveLineRange:e=>{let t=function(e){let t=e.nodeType===Node.TEXT_NODE?e.parentElement:e;if(!t||!("closest"in t))return null;let r=t.closest("[data-source-start]");if(!r)return null;let n=r.getAttribute("data-source-start"),s=r.getAttribute("data-source-end");return n&&s?{start:parseInt(n,10),end:parseInt(s,10)}:null}(e);return t?{start:t.start,end:t.end}:null},buildLineSnapshot:({start:e,end:t})=>{let r=Math.max(0,e-1),n=Math.min(B.length,t);return B.slice(r,n).join("\n")}}),z=(0,s.useCallback)(()=>{let e=A.current;e&&(M({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),W())},[W,A]),H=(0,s.useCallback)(()=>{let e=A.current;e&&($({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),W())},[W,A]),O=(0,s.useCallback)(async e=>{S&&(await h(S.range.start,S.range.end,e,S.selectedText),M(null))},[S,h]),q=(0,s.useCallback)(async e=>{if(T&&m)try{let n=await (0,g.$3)(r),s=[];for(let e of n)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:T.range.start,endLine:T.range.end,codeContent:T.lineSnapshot});let o=(0,g.Gw)(s,e);m.sendMessage(o),await (0,g.RP)(r),k(),$(null)}catch(e){console.error("Failed to send to AI:",e)}},[T,m,t,r,k]),V=(0,s.useMemo)(()=>{if(0===x.length)return[];let e=new Map;for(let t of x){let r=`${t.startLine}-${t.endLine}`;e.has(r)||e.set(r,[]),e.get(r).push(t)}return Array.from(e.entries()).map(([e,t])=>({key:e,startLine:t[0].startLine,endLine:t[0].endLine,comments:t}))},[x]),[K,U]=(0,s.useState)([]);return(0,s.useEffect)(()=>{if(0===V.length||!D.current)return void queueMicrotask(()=>U([]));let e=setTimeout(()=>{let e=D.current;if(!e)return;let t=[],r=e.querySelectorAll("[data-source-start]");for(let n of V){let s=null,o=1/0;for(let e of r){let t=parseInt(e.getAttribute("data-source-start"),10),r=parseInt(e.getAttribute("data-source-end"),10);if(t<=n.startLine&&r>=n.endLine){let n=r-t;n<o&&(o=n,s=e)}}if(s){let r=e.getBoundingClientRect(),o=s.getBoundingClientRect();t.push({key:n.key,top:o.top-r.top+e.scrollTop,comments:n.comments})}}U(t)},100);return()=>clearTimeout(e)},[V,e]),(0,s.useEffect)(()=>{let e=e=>{if("Escape"===e.key){if(T){$(null),e.stopPropagation();return}if(S){M(null),e.stopPropagation();return}if(A.current){A.current=null,_.current(),e.stopPropagation();return}if(P){R(null),e.stopPropagation();return}l()}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[T,S,P,l]),(0,n.jsxs)(n.Fragment,{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 truncate",children:t}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(eu.ShareReviewToggle,{content:e,sourceFile:i}),(0,n.jsx)("button",{onClick:l,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:c("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.jsxs)("div",{className:"flex-1 flex overflow-hidden",children:[(0,n.jsx)(ed.l,{content:e,containerRef:D}),(0,n.jsxs)("div",{className:"flex-1 overflow-auto relative",ref:D,children:[(0,n.jsx)("div",{className:"p-6",children:(0,n.jsx)(ei.T,{content:e,rehypePlugins:em})}),K.map(({key:e,top:t,comments:r})=>(0,n.jsx)("div",{className:"absolute right-3 cursor-pointer z-10",style:{top:t},onClick:e=>{e.stopPropagation(),R({comment:r[0],x:e.clientX,y:e.clientY})},children:(0,n.jsx)("div",{className:"w-5 h-5 rounded-full bg-amber-500/80 text-white text-xs flex items-center justify-center shadow-sm hover:bg-amber-500 transition-colors",children:r.length})},e))]})]}),N&&d&&(0,u.createPortal)((0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(j.f,{floatingToolbarRef:A,bumpRef:_,container:d,onAddComment:z,onSendToAI:H,isChatLoading:m?.isLoading}),S&&(0,n.jsx)(w.t,{x:S.x,y:S.y,range:S.range,lineSnapshot:S.lineSnapshot,container:d,onSubmit:O,onClose:()=>M(null)}),T&&(0,n.jsx)(w.G,{x:T.x,y:T.y,range:T.range,filePath:t,lineSnapshot:T.lineSnapshot,container:d,onSubmit:q,onClose:()=>$(null),isChatLoading:m?.isLoading}),P&&(0,n.jsx)(L.t,{x:P.x,y:P.y,comment:P.comment,container:d,onClose:()=>R(null),onUpdateComment:f,onDeleteComment:y})]}),d)]})}function eh({path:e,matchedIndices:t}){let r=(0,s.useMemo)(()=>new Set(t),[t]),o=e.lastIndexOf("/"),l=o>=0?e.slice(0,o+1):"",a=o>=0?e.slice(o+1):e,i=(e,t,s)=>{let o=[],l="",a=!1;for(let s=0;s<e.length;s++){let i=t+s,c=r.has(i);c!==a&&l&&(o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-${s}`):(0,n.jsx)("span",{children:l},`${t}-${s}`)),l=""),a=c,l+=e[s]}return l&&o.push(a?(0,n.jsx)("span",{className:"text-brand font-medium",children:l},`${t}-end`):(0,n.jsx)("span",{children:l},`${t}-end`)),(0,n.jsx)("span",{className:s,children:o})};return(0,n.jsxs)("span",{className:"truncate",children:[l&&i(l,0,"text-muted-foreground"),i(a,l.length,"text-foreground")]})}function ef({files:e,fileIndex:t,recentFiles:r,onSelectFile:l,onClose:a}){let{t:i}=(0,o.Bd)(),[c,d]=(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(!c.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,l=0,a=-1;for(let i=0;i<r.length&&o<n.length;i++)r[i]===n[o]&&(s.push(i),a===i-1&&(l+=5),(0===i||"/"===e[i-1]||"."===e[i-1]||"-"===e[i-1]||"_"===e[i-1])&&(l+=10),i>e.lastIndexOf("/")&&(l+=3),e[i]===t[o]&&(l+=1),a=i,o++);return o<n.length?null:(l-=.1*e.length,{path:e,score:l,matchedIndices:s})}(t,c.trim());n&&(r.includes(t)&&(n.score+=20),e.push(n))}return e.sort((e,t)=>t.score-e.score),e.slice(0,50)},[c,p,r]),b=(0,s.useCallback)(e=>{d(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=>{l(e),a()},[l,a]),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(),a()}},[g,u,v,a]);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:a,children:(0,n.jsxs)("div",{className:"w-[680px] max-h-[60vh] bg-card border border-border rounded-lg shadow-2xl 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:c,onChange:e=>b(e.target.value),onKeyDown:j,placeholder:i("quickFileOpen.placeholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",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-accent text-foreground"}`,"data-tooltip":e.path,onClick:()=>v(e.path),children:[(0,n.jsx)(B,{name:e.path.split("/").pop()||"",className:"w-4 h-4 flex-shrink-0"}),(0,n.jsx)(eh,{path:e.path,matchedIndices:e.matchedIndices}),!c.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 ep=r(2111),eg=r(41474),eb=r(61878),ev=r(33210),ej=r(48368),ew=r(91958),ey=r(45916),ek=r(31794),eN=r(69048),eC=r(97567),eS=r(68806),eL=r(52475);function eE({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)(ej.A,{className:s});if("__preamble__"===t)return(0,n.jsx)(ey.A,{className:s});if(t&&t.startsWith("__heading_"))return(0,n.jsx)(ek.A,{className:s});switch(e){case"function":case"method":return(0,n.jsx)(eN.A,{className:s});case"class":return(0,n.jsx)(eC.A,{className:s});case"interface":return(0,n.jsx)(eS.A,{className:s});default:return(0,n.jsx)(eL.A,{className:s})}}var eM=r(49433),eT=r(82680);let e$=new Map,eP=new Map;async function eR(e,t,r=!1){let n=`${e}::${t}`;if(r)!function(e){if(!e){e$.clear(),eP.clear();return}let t=`${e}::`;for(let e of e$.keys())e.startsWith(t)&&e$.delete(e);for(let e of eP.keys())e.startsWith(t)&&eP.delete(e)}(e);else{let e=e$.get(n);if(e)return e;let t=eP.get(n);if(t)return t}let s=eM.tryPromise({try:async()=>{let s=new URLSearchParams({cwd:e,path:t});r&&s.set("refresh","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}`);let l=await o.json();return e$.set(n,l),l},catch:e=>new eT.uV({message:"fetchFileFunctions failed",cause:e})}),o=i.t4.runPromiseExit(s).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.delete(n));return eP.set(n,o),o}function eB(e,t){let[r,n]=(0,s.useState)({state:"idle"}),o=(0,s.useRef)(!0);(0,s.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let l=(0,s.useCallback)((e,t,r)=>{n({state:"loading"}),eR(e,t,r).then(e=>{o.current&&("not-found"===e?n({state:"notFound"}):n({state:"ready",data:e}))}).catch(e=>{o.current&&n({state:"error",message:e.message})})},[]);return(0,s.useEffect)(()=>{e&&t?l(e,t,!1):n({state:"idle"})},[e,t,l]),{state:r,refresh:(0,s.useCallback)(()=>{e&&t&&l(e,t,!0)},[e,t,l])}}var eF=r(3238),eI=r(50538),eD=r(94287);function eA({entries:e,onSelect:t,onClear:r}){let{t:s}=(0,o.Bd)();return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-l border-border 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.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground font-mono min-w-0",children:[(0,n.jsx)(eI.A,{className:"w-3 h-3 flex-shrink-0"}),(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)(eD.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)(ev.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)(eD.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:bg-secondary/60 transition-colors group flex items-start gap-1.5",children:[(0,n.jsx)(eE,{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 e_(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 eW=new Set(["function","class","method"]);function ez(e){return eW.has(e.kind)}function eH({functions:e,currentQname:t,onSelect:r}){let{t:l}=(0,o.Bd)(),a=(0,s.useMemo)(()=>e.filter(ez),[e]);return(0,n.jsxs)("div",{className:"w-56 flex-shrink-0 bg-card border-r border-border flex flex-col","data-testid":"file-toc-section",children:[(0,n.jsx)("div",{className:"flex-shrink-0 px-2 py-1.5 border-b border-border text-xs text-muted-foreground font-mono truncate",children:0===a.length?l("blockViewer.toc.title"):`${l("blockViewer.toc.title")} \xb7 ${a.length}`}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===a.length?(0,n.jsx)("div",{className:"px-3 py-4 text-[10px] text-muted-foreground/60 italic leading-relaxed",children:l("blockViewer.toc.empty")}):a.map(e=>{let s=t===e.qualifiedName;return(0,n.jsx)(eD.m,{content:`${e.qualifiedName} \xb7 L${e.startLine}`,children:(0,n.jsxs)("button",{onClick:()=>r(e.qualifiedName,e.startLine),className:`w-full text-left px-2 py-1 transition-colors flex items-center gap-1.5 min-w-0 ${s?"bg-brand/15 hover:bg-brand/20":"hover:bg-secondary/60"}`,children:[(0,n.jsx)(eE,{kind:e.kind,qname:e.qualifiedName,className:"w-3 h-3 flex-shrink-0"}),(0,n.jsx)("span",{className:`text-xs font-mono truncate ${s?"font-semibold text-brand":""}`,children:e.name})]})},e.qualifiedName)})})]})}var eO=r(96035);function eq({comments:e,startLine:t,endLine:r,lineHeight:s,bodyTopOffset:o,onCommentClick:l}){let a=new Map;for(let n of e){if(n.endLine<t||n.endLine>r)continue;let e=a.get(n.endLine);e?e.push(n):a.set(n.endLine,[n])}return 0===a.size?null:(0,n.jsx)("div",{className:"absolute top-0 right-0 bottom-0 w-6 pointer-events-none",children:Array.from(a.entries()).map(([e,r])=>{let a=o+(e-t)*s,i=r[0],c=r.length-1;return(0,n.jsx)(eD.m,{content:1===r.length?i.content:`${r.length} comments — click to view`,children:(0,n.jsxs)("button",{onClick:e=>l(i,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-sm transition-colors",style:{top:`${a+s/2-8}px`},children:[(0,n.jsx)(eO.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 eV(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 eK({addedLines:e,blockRanges:t,viewportRange:r,onJumpToLine:o}){let l,a=(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]),c=(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 d=(e,t)=>{let r=eV(i,e),n=eV(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:a,onClick:e=>{let t=a.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,l=c.find(e=>e.qname===n.qname&&s>=e.start&&s<=e.end);if(l)return void o(l.qname,s);if(c.length>0){let e=Math.max(2,Math.round(.05*i.total)),t=eV(i,s);if(null!==t){let r=null,n=1/0;for(let e of c){let s=eV(i,e.start),o=eV(i,e.end);if(null===s||null===o)continue;let l=t<s?s-t:t>o?t-o:0;l<n&&(r=e,n=l)}if(r&&n<=e){let e=s<r.start?r.start:s>r.end?r.end:s;o(r.qname,e);return}}}let d=i.blocks.find(e=>e.qname===n.qname);d&&o(d.qname,d.startLine)},className:"w-4 flex-shrink-0 bg-secondary border-l border-border relative cursor-pointer",title:"Diff minimap — click to jump",children:[c.map(e=>{let t=d(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&&((l=d(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:`${l.top}%`,height:`${Math.max(1.2,l.heightPct)}%`}}):null)]})}function eU(e){let t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function eJ({symbol:e,fileSource:t,hasChange:r,onHighlighted:o,comments:l,onCommentClick:a,addedLines:i}){let{resolvedTheme:c}=(0,eF.D)(),d=(0,s.useMemo)(()=>(0,C.sQ)(e.filePath),[e.filePath]),[u,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(null);return(0,s.useEffect)(()=>{if(!t)return void m(null);let r=!1;return(async()=>{try{let n=t.split("\n").slice(e.startLine-1,e.endLine).join("\n"),s=(await (0,C.kS)()).codeToTokens(n,{lang:d,theme:"dark"===c?"github-dark":"github-light"}).tokens.map((t,r)=>{let n=e.startLine+r,s=i?.has(n)??!1;return`<div class="flex${s?" bg-green-9/15":""}" style="min-width:max-content" data-line="${n}"><span class="select-none pr-3 text-muted-foreground/60 tabular-nums" style="min-width:3.2rem;text-align:right">${n}</span><span class="whitespace-pre">${(0,C.b8)(t)}</span></div>`}).join("");r||(m(s),h(null))}catch(e){r||h(e instanceof Error?e.message:"highlight failed")}})(),()=>{r=!0}},[t,e.startLine,e.endLine,d,c,e.filePath,i]),(0,s.useEffect)(()=>{(null!==u||null!==x)&&o(e.qualifiedName)},[u,x,e.qualifiedName,o]),(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 bg-secondary/40 text-xs",children:[(0,n.jsx)(eE,{kind:e.kind,qname:e.qualifiedName,className:"w-3.5 h-3.5 flex-shrink-0"}),(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:[e.kind," \xb7 L",e.startLine,"-",e.endLine]}),(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:`${eX}px`},children:[!t&&(0,n.jsx)("span",{className:"text-muted-foreground",children:"Loading…"}),x&&(0,n.jsx)("span",{className:"text-red-11",children:x}),u&&(0,n.jsx)("div",{dangerouslySetInnerHTML:{__html:u}})]}),l&&l.length>0&&a&&(0,n.jsx)(eq,{comments:l,startLine:e.startLine,endLine:e.endLine,lineHeight:eX,bodyTopOffset:eY+eZ,onCommentClick:a})]})}function eQ({side:e,pin:t,accent:r,onClick:s}){let o,l,a,i,c,d,u,m=t.lines.length;"ext"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",l="ext",a="text-muted-foreground/60",i=t.name,c=t.packageSpec,d="external",u=t.packageSpec):"method"===t.kind?(o="bg-secondary/30 border-border/50 hover:border-muted-foreground/60",l="method",a="text-muted-foreground/60",i=`${t.receiverName}.${t.methodName}`,c=null,d="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",l="self",a="text-muted-foreground/70",i=t.external.name,c=null,d="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",l=e,a="in"===e?"text-amber-11":"text-green-11",i=t.external.name,c=eU(t.external.filePath),d="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.jsxs)("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 flex items-center gap-1.5`,"data-tooltip":`${d}${u?" \xb7 "+u:""}`,children:[(0,n.jsx)("span",{className:`${a} text-[9px] uppercase tracking-wider font-semibold flex-shrink-0`,children:l}),(0,n.jsxs)("span",{className:"truncate flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:i}),c&&(0,n.jsx)("span",{className:"text-muted-foreground/70 ml-1",children:c}),m>1&&(0,n.jsxs)("span",{className:"text-muted-foreground/60 ml-1",children:["\xb7",m,"\xd7"]})]})]})}let eX=18,eY=29,eZ=8;function eG(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 e0(e,t){return"ext"!==e.kind&&"method"!==e.kind&&(t?.has(e.external.qualifiedName)??!1)}function e1(e){return{filePath:e.filePath,qname:e.qualifiedName,name:e.name,kind:e.kind}}function e2({symbol:e,fileSource:t,hasChange:r,upstream:s,downstream:o,onPinClick:l,onHighlighted:a,comments:i,onCommentClick:c,accentQnames:d,addedLines:u}){let m=function(e,t){if(0===e.length)return[];let r=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)))}});r.sort((e,t)=>e.line-t.line||e.i-t.i);let n=Array(e.length).fill(0),s=-1/0;for(let{i:e,line:o}of r){let r=Math.max(eY+eZ+(o-t.startLine)*eX,s);n[e]=r,s=r+22}return n}(o,e);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:"w-44 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)(eQ,{side:"in",pin:t,accent:e0(t,d),onClick:()=>l(t,e)},eG("in",t)))}),(0,n.jsx)(eJ,{symbol:e,fileSource:t,hasChange:r,onHighlighted:a,comments:i,onCommentClick:c,addedLines:u}),(0,n.jsx)("div",{className:"w-44 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:`${m[r]}px`},children:(0,n.jsx)(eQ,{side:"out",pin:t,accent:e0(t,d),onClick:()=>l(t,e)})},eG("out",t)))})]})}function e5({cwd:e,onSelect:t,onClose:r}){let{t:l}=(0,o.Bd)(),[a,c]=(0,s.useState)(""),[d,u]=(0,s.useState)({files:[],symbols:[]}),[m,x]=(0,s.useState)(0),[f,p]=(0,s.useState)(!1),g=(0,s.useMemo)(()=>[...d.files,...d.symbols],[d]);(0,s.useEffect)(()=>{let t=a.trim();if(!t)return void u({files:[],symbols:[]});p(!0);let r=setTimeout(async()=>{let r=new URLSearchParams({cwd:e,q:t,limit:"12"}),n=await i.t4.runPromiseExit((0,h.MB)(r));"Success"===n._tag&&(u(n.value),x(0)),p(!1)},120);return()=>clearTimeout(r)},[a,e]);let b=(0,s.useCallback)(e=>{if("Escape"===e.key)return void r();if(0!==g.length){if("ArrowDown"===e.key)e.preventDefault(),x(e=>Math.min(e+1,g.length-1));else if("ArrowUp"===e.key)e.preventDefault(),x(e=>Math.max(e-1,0));else if("Enter"===e.key){e.preventDefault();let r=g[m];r&&t(r)}}},[g,m,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-2xl 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)(eb.A,{className:"w-4 h-4 text-muted-foreground"}),(0,n.jsx)("input",{autoFocus:!0,value:a,onChange:e=>c(e.target.value),onKeyDown:b,placeholder:l("blockViewer.search.hint","Start typing to search"),className:"flex-1 bg-transparent border-0 outline-none text-sm"}),f&&(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)(ev.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsxs)("div",{className:"max-h-96 overflow-y-auto",children:[0===g.length&&a&&!f&&(0,n.jsx)("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:l("blockViewer.search.noResults","No matches")}),(0,n.jsx)(e4,{label:l("blockViewer.search.files","Files"),hits:d.files,startIdx:0,activeIdx:m,onSelect:t,setActive:x}),(0,n.jsx)(e4,{label:l("blockViewer.search.symbols","Symbols"),hits:d.symbols,startIdx:d.files.length,activeIdx:m,onSelect:t,setActive:x})]})]})})}function e4({label:e,hits:t,startIdx:r,activeIdx:s,onSelect:o,setActive:l}){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 a=r+t,i=a===s;return(0,n.jsxs)("button",{onMouseEnter:()=>l(a),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.target.kind?(0,n.jsx)(ej.A,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0 text-muted-foreground"}):(0,n.jsx)(eE,{kind:e.target.symbolKind,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 e3({cwd:e,highlightedFilePath:t,changedFiles:r,onSwitchToCode:l,enableComments:a=!1,onContentSearch:c,onFocalChange:d,qnameFilter:u,qnameFilterFile:m,accentQnames:h,accentFile:f,addedLines:b,addedLinesFile:y,headerExtraLeft:k,headerExtraRight:N}){let{t:C}=(0,o.Bd)(),[S,M]=(0,s.useState)(null),T=S??t??null;(0,s.useEffect)(()=>{M(null)},[t]),(0,s.useEffect)(()=>{d?.(T)},[T,d]);let{state:$,refresh:P}=eB(e,T),[R,B]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!T)return void B(null);let t=!1;return B(null),(async()=>{let r=new URLSearchParams({cwd:e,path:T}),n=await i.t4.runPromiseExit((0,x.eA)(r));t||("Success"===n._tag?B({content:n.value.content,mtimeMs:n.value.mtimeMs}):console.error("[BlockViewer] failed to load file source for",T,n.cause))})(),()=>{t=!0}},[e,T]);let F=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!R||"ready"!==$.state)return;let e=$.data.mtimeMs;!e||R.mtimeMs<=e||F.current!==R.mtimeMs&&(F.current=R.mtimeMs,P())},[R,$,P]);let[I,D]=(0,s.useState)([]),[A,_]=(0,s.useState)(!1),[W,z]=(0,s.useState)(null),H=(0,s.useRef)(0),O=(0,s.useRef)(0),[q,V]=(0,s.useState)(()=>new Set),K="ready"===$.state?$.data.filePath:null;(0,s.useEffect)(()=>{V(new Set)},[K]);let U=(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(),_(!0))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]);let J=(0,s.useCallback)((e,t)=>{if("ext"===e.kind||"method"===e.kind){let e=t.filePath;if(!e)return;H.current+=1,z({filePath:e,qname:"__imports__",nonce:H.current});return}let r=e1(t),n=e1(e.external);D(e=>e_(e_(e,r),n)),M(n.filePath),H.current+=1,z({filePath:n.filePath,qname:n.qname,nonce:H.current})},[]),Q=(0,s.useCallback)(e=>{M(e.filePath),H.current+=1,z({filePath:e.filePath,qname:e.qname,nonce:H.current})},[]),X=(0,s.useCallback)(e=>{_(!1),M(e.target.filePath),"symbol"===e.target.kind&&(H.current+=1,z({filePath:e.target.filePath,qname:e.target.qualifiedName,line:e.target.line,nonce:H.current}))},[]),Y=(0,s.useCallback)((e,t)=>{T&&(H.current+=1,z({filePath:T,qname:e,line:t,nonce:H.current}))},[T]),[Z,G]=(0,s.useState)(null),[ee,et]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!Z)return;let e=null,t=()=>{e=null;let t=Z.getBoundingClientRect();if(t.height<=0)return;let r=Z.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 l=Number(r),a=Number(o);if(!Number.isFinite(l)||!Number.isFinite(a))return;let i=e.getBoundingClientRect();if(i.height<=0||i.bottom<=t.top||i.top>=t.bottom)return;let c=Math.max(0,t.top-i.top),d=Math.min(i.height,t.bottom-i.top),u=a-l+1,m=Math.floor(c/i.height*u),x=Math.ceil(d/i.height*u)-1,h=l+Math.max(0,m),f=l+Math.min(u-1,Math.max(0,x));h<n&&(n=h),f>s&&(s=f)}),n===1/0||s===-1/0?et(null):et(e=>e&&e.start===n&&e.end===s?e:{start:n,end:s})},r=()=>{null===e&&(e=requestAnimationFrame(t))};r(),Z.addEventListener("scroll",r,{passive:!0});let n=new ResizeObserver(r);n.observe(Z);let s=new MutationObserver(r);return s.observe(Z,{childList:!0,subtree:!0}),()=>{Z.removeEventListener("scroll",r),n.disconnect(),s.disconnect(),null!==e&&cancelAnimationFrame(e)}},[Z]);let er=(0,s.useMemo)(()=>{if("ready"!==$.state||!ee)return null;let e=$.data.functions;if(0===e.length)return null;let t=(ee.start+ee.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<=ee.start&&(!r||t.startLine>r.startLine)&&(r=t);return r?.qualifiedName??null},[$,ee]),en=a&&!!e&&!!T,es=(0,v.r)(),{comments:eo,addComment:el,updateComment:ea,deleteComment:ei,refresh:ec}=(0,p._)({cwd:e,filePath:T??""}),[ed,eu]=(0,s.useState)(null),{toolbarRef:em,bumpRef:ex,clearToolbar:eh}=(0,E.L)({enabled:en,container:ed,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||!ed||!ed.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=R?.content;return r?r.split("\n").slice(e-1,t).join("\n"):""}}),[ef,ep]=(0,s.useState)(null),[eg,eb]=(0,s.useState)(null),[ev,ej]=(0,s.useState)(null),ew=(0,s.useCallback)(()=>{let e=em.current;e&&(ep({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),eh())},[eh,em]),ey=(0,s.useCallback)(()=>{let e=em.current;e&&(eb({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),eh())},[eh,em]),ek=(0,s.useCallback)(()=>{let e=em.current;if(!e||!c)return;let t=e.selectedText.trim();eh(),t&&c(t)},[c,eh,em]),eN=(0,s.useCallback)(async e=>{ef&&(await el(ef.range.start,ef.range.end,e,ef.selectedText),ep(null))},[ef,el]),eC=(0,s.useCallback)(async t=>{if(eg&&es&&e&&T)try{let r=(await (0,g.$3)(e)).map(e=>({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0}));r.push({filePath:T,startLine:eg.range.start,endLine:eg.range.end,codeContent:eg.lineSnapshot});let n=(0,g.Gw)(r,t);es.sendMessage(n),await (0,g.RP)(e),ec(),eb(null)}catch(e){console.error("[BlockViewer] send to AI failed:",e)}},[eg,es,e,T,ec]),eS=(0,s.useCallback)((e,t)=>{t.stopPropagation(),ej({comment:e,x:t.clientX,y:t.clientY}),eh(),ep(null),eb(null)},[eh]);if((0,s.useEffect)(()=>{let e;if(!W||O.current>=W.nonce||"ready"!==$.state||!R||$.data.filePath!==W.filePath)return;if(m&&m===$.data.filePath&&u){let t=0;for(let e of $.data.functions)u.has(e.qualifiedName)&&t++;e=Math.max(1,t)}else e=Math.max(1,$.data.functions.length);if(q.size<e)return;O.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,$,R,q,u,m]),!T)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e8,{focalFile:null,fileCount:null,onSwitchToCode:l,onSearch:()=>_(!0),onRefresh:P,refreshDisabled:!0,extraLeft:k,extraRight:N}),(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:C("blockViewer.empty.body","Select a file in the left tree to see its function call graph.")}),(0,n.jsx)("span",{className:"text-xs",children:C("blockViewer.empty.hint","or press ⌘K to search.")})]}),A&&(0,n.jsx)(e5,{cwd:e,onSelect:X,onClose:()=>_(!1)})]});if("idle"===$.state||"loading"===$.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e8,{focalFile:T,fileCount:null,onSwitchToCode:l,onSearch:()=>_(!0),onRefresh:P,refreshDisabled:!0,extraLeft:k,extraRight:N}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:C("blockViewer.fileMode.loading","Loading…")})]});if("notFound"===$.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e8,{focalFile:T,fileCount:null,onSwitchToCode:l,onSearch:()=>_(!0),onRefresh:P,extraLeft:k,extraRight:N}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground px-4 text-center",children:C("blockViewer.fileMode.notFound","This file is not indexed (unsupported language or beyond the file cap).")}),A&&(0,n.jsx)(e5,{cwd:e,onSelect:X,onClose:()=>_(!1)})]});if("error"===$.state)return(0,n.jsxs)("div",{className:"h-full flex flex-col",children:[(0,n.jsx)(e8,{focalFile:T,fileCount:null,onSwitchToCode:l,onSearch:()=>_(!0),onRefresh:P,extraLeft:k,extraRight:N}),(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:$.message}),(0,n.jsx)("button",{onClick:P,className:"px-3 py-1 rounded bg-secondary hover:bg-secondary/80",children:C("blockViewer.retry","Retry")})]})]});let eL=$.data,eE=eL.functions;if(0===eE.length&&R){let e=Math.max(1,R.content.split("\n").length);eE=[{filePath:eL.filePath,qualifiedName:"__file__",name:eU(eL.filePath),kind:"unknown",startLine:1,endLine:e}]}let eM=m&&m===eL.filePath,eT=f&&f===eL.filePath,e$=y&&y===eL.filePath;eM&&u&&(eE=eE.filter(e=>u.has(e.qualifiedName)));let eP=eT?h:void 0,eR=e$?b:void 0,eF=e6(eL.upstreamCalls),eI=e6(eL.downstreamCalls),eD=new Map(eE.map(e=>[e.qualifiedName,e])),eW=new Map,ez=new Map;for(let e of eL.intraCalls){let t=eD.get(e.to),r=eD.get(e.from);if(t){let r=eW.get(e.from),n={kind:"self",external:t,lines:e.lines};r?r.push(n):eW.set(e.from,[n])}if(r){let t=ez.get(e.to),n={kind:"self",external:r,lines:e.lines};t?t.push(n):ez.set(e.to,[n])}}let eO=new Map;for(let e of eL.externalCalls??[]){let t=eO.get(e.focalQname),r={kind:"ext",name:e.external.name,packageSpec:e.external.packageSpec,lines:e.lines};t?t.push(r):eO.set(e.focalQname,[r])}let eq=new Map;for(let e of eL.methodCalls??[]){let t=eq.get(e.focalQname),r={kind:"method",receiverName:e.receiverName,methodName:e.methodName,lines:e.lines};t?t.push(r):eq.set(e.focalQname,[r])}let eV=r.has(eL.filePath);return(0,n.jsxs)("div",{className:"h-full flex flex-col relative",children:[(0,n.jsx)(e8,{focalFile:T,fileCount:eL.fileCount,functionCount:eL.functions.length,upstreamCount:eL.upstreamCalls.length,downstreamCount:eL.downstreamCalls.length,onSwitchToCode:l,onSearch:()=>_(!0),onRefresh:P,extraLeft:k,extraRight:N}),(0,n.jsxs)("div",{ref:eu,className:"flex-1 relative min-h-0 flex",children:[(0,n.jsx)(eH,{functions:eE,currentQname:er,onSelect:Y}),(0,n.jsx)("div",{ref:G,className:"flex-1 min-w-0 overflow-auto",children:(0,n.jsx)("div",{className:"flex flex-col gap-3 p-3",children:eE.map(e=>{let t,r,s,o,l,a;return(0,n.jsx)(e2,{symbol:e,fileSource:R?.content??null,hasChange:eV,upstream:(t=eF.get(e.qualifiedName),r=ez.get(e.qualifiedName),[...(t??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...r??[]]),downstream:(s=eI.get(e.qualifiedName),o=eW.get(e.qualifiedName),l=eq.get(e.qualifiedName),a=eO.get(e.qualifiedName),[...(s??[]).map(e=>({kind:"cross",external:e.external,lines:e.lines})),...o??[],...l??[],...a??[]]),onPinClick:J,onHighlighted:U,comments:en?eo:void 0,onCommentClick:en?eS:void 0,accentQnames:eP,addedLines:eR},e.qualifiedName)})})}),en&&ed&&(0,n.jsx)(j.f,{floatingToolbarRef:em,bumpRef:ex,container:ed,onAddComment:ew,onSendToAI:ey,onSearch:c?ek:void 0,isChatLoading:es?.isLoading}),en&&ef&&(0,n.jsx)(w.t,{x:ef.x,y:ef.y,range:ef.range,lineSnapshot:ef.lineSnapshot,container:ed,onSubmit:eN,onClose:()=>ep(null)}),en&&eg&&T&&(0,n.jsx)(w.G,{x:eg.x,y:eg.y,range:eg.range,filePath:T,lineSnapshot:eg.lineSnapshot,container:ed,onSubmit:eC,onClose:()=>eb(null),isChatLoading:es?.isLoading}),en&&ev&&(0,n.jsx)(L.t,{x:ev.x,y:ev.y,comment:ev.comment,container:ed,onClose:()=>ej(null),onUpdateComment:ea,onDeleteComment:ei}),eR&&eR.size>0&&eE.length>0&&(0,n.jsx)(eK,{addedLines:eR,blockRanges:eE.map(e=>({qname:e.qualifiedName,startLine:e.startLine,endLine:e.endLine})),viewportRange:ee,onJumpToLine:Y}),(0,n.jsx)(eA,{entries:I,onSelect:Q,onClear:()=>D([])}),A&&(0,n.jsx)(e5,{cwd:e,onSelect:X,onClose:()=>_(!1)})]})]})}function e6(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 e8({focalFile:e,fileCount:t,functionCount:r,upstreamCount:s,downstreamCount:l,onSwitchToCode:a,onSearch:i,onRefresh:c,refreshDisabled:d,extraLeft:u,extraRight:m}){let{t:x}=(0,o.Bd)(),h={focalFile:e,blockCount:r??0,upstreamCount:s??0,downstreamCount:l??0};return(0,n.jsxs)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-border flex items-center justify-between bg-secondary/30 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 l&&(0,n.jsxs)("span",{className:"ml-2",children:["\xb7 ",s," in \xb7 ",l," 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)(eb.A,{className:"w-3 h-3"})," ⌘K"]}),(0,n.jsx)("button",{onClick:c,disabled:d,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)(ew.A,{className:"w-3 h-3"})}),a&&(0,n.jsx)("button",{onClick:a,className:"text-xs px-2 py-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground",children:"Code"})]})]})}function e9(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 e7(e){return e.replace(/\s+/g," ").trim()}function te(e,t){return e?`${e}>${t}`:t}function tt(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 tr(e,t,r,n,s=[],o){return{qualifiedName:te(n,t),name:t,kind:r,startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:e9(e7(e.text)),children:s,params:o}}function tn(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}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";default:return null}}var to=r(14066);let tl="/tree-sitter",ta=null,ti=new Map;async function tc(e){let t,r=await (!(t=ti.get(e))&&(t=(async()=>(await (!ta&&(ta=to.iX.init({locateFile:e=>`${tl}/${e}`})),ta),to.TM.load(`${tl}/tree-sitter-${e}.wasm`)))(),ti.set(e,t)),t),n=new to.iX;return n.setLanguage(r),n}function td(e){return e.qualifiedName.startsWith("__code_")||e.qualifiedName.startsWith("__heading_")}function tu(e){return!td(e)&&"__file__"!==e.qualifiedName}async function tm(e,t){if(!e)return[];let r=ts(t);if(!r)return null;let n=(await tc(r)).parse(e);if(!n)return null;try{return function(e){let t=[],r=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)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,contentHash:e9(e7(t.map(e=>e.text).join("\n"))),children:[]}}(e);r&&t.push(r);for(let r=0;r<e.namedChildCount;r++){let n=e.namedChild(r);n&&t.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[tr(t,tt(t),"function",r,[],tn(t))];case"class_declaration":case"abstract_class_declaration":{let e=tt(t),n=te(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(tr(s,tt(s),"method",t,[],tn(s)));else if("public_field_definition"===s.type){let e=s.childForFieldName("value");e&&("arrow_function"===e.type||"function_expression"===e.type)&&r.push(tr(s,tt(s),"method",t,[],tn(e)))}}}return r}(t.childForFieldName("body"),n);return[tr(t,e,"class",r,s)]}case"interface_declaration":return[tr(t,tt(t),"interface",r)];case"type_alias_declaration":return[tr(t,tt(t),"type",r)];case"enum_declaration":return[tr(t,tt(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"),l=s.childForFieldName("value");if(!o)continue;let a=o.text,i=l&&("arrow_function"===l.type||"function_expression"===l.type),c=i&&l?tn(l):void 0;if(r.push(tr(e,a,i?"function":"const",t,[],c)),l&&"object"===l.type&&!i){let e=t?`${t}>${a}`:a;for(let t=0;t<l.namedChildCount;t++){let n=l.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(tr(n,t.text,"method",e,[],tn(s)))}else if("method_definition"===n.type){let t=tt(n);t&&r.push(tr(n,t,"method",e,[],tn(n)))}}}}}return r}(t,r);case"class_definition":{let e=tt(t),n=te(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(tr(o,tt(o),"method",r,[],tn(o)));else if("decorated_definition"===o.type){let t=o.childForFieldName("definition");if(t?.type==="function_definition")n.push({...tr(t,tt(t),"method",r,[],tn(t)),startLine:o.startPosition.row+1,contentHash:e9(e7(o.text))});else if(t?.type==="class_definition"){let s=tt(t),l=te(r,s),a=e(t.childForFieldName("body"),l);n.push({...tr(t,s,"class",r,a),startLine:o.startPosition.row+1,contentHash:e9(e7(o.text))})}}else if("class_definition"===o.type){let t=tt(o),s=te(r,t),l=e(o.childForFieldName("body"),s);n.push(tr(o,t,"class",r,l))}}}return n}(t.childForFieldName("body"),n);return[tr(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:e9(e7(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:te(r,s),name:s,kind:"const",startLine:e.startPosition.row+1,endLine:e.endPosition.row+1,contentHash:e9(e7(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,l=[];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)&&l.push(t)}}if(0===l.length||!o)return[];let a=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=a?`${a} ${o}`:o;return l.map((e,r)=>tr(e,l.length>1?`${i} #${r+1}`:i,"function",t,[],tn(e)))}(t,r)),e}default:return[]}}(n,void 0,!1))}return t.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=[],l=(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,contentHash:e9(e7(s)),children:[]})},a=-1;for(let e=1;e<=n;e++)s[e]?a>=0&&(l(a,e-1),a=-1):a<0&&(a=e);return a>=0&&l(a,n),o}(e,t)),t}(n.rootNode)}finally{n.delete()}}async function tx(e,t,r,n,s){let o=new Set;if(e!==t)for(let r of y(n?"":e,s?"":t))"added"===r.type&&void 0!==r.newLineNum&&o.add(r.newLineNum);if(!ts(r))return{addedLines:o};let[l,a]=await Promise.all([tm(n?"":e,r),tm(s?"":t,r)]),i=a??[],c=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}((l??[]).filter(tu),i.filter(tu)),d=new Set;for(let e of c)"deleted"!==e.changeKind&&d.add(e.qname);for(let e of function(e,t){if(0===t.size)return[];let r=[];for(let n of e)if(td(n)){for(let e of t)if(e>=n.startLine&&e<=n.endLine){r.push(n.qualifiedName);break}}return r}(i,o))d.add(e);return{changedQnames:d,addedLines:o}}function th({cwd:e,filePath:t,oldContent:r,newContent:o,isNew:l=!1,isDeleted:a=!1,changedFiles:i,fileGitStatusMap:c,enableComments:d=!1,onContentSearch:u,headerExtraLeft:m,headerExtraRight:x}){let[h,f]=(0,s.useState)(t);(0,s.useEffect)(()=>{f(t)},[t]);let[p,g]=(0,s.useState)(null);return(0,s.useEffect)(()=>{let n=!1;return g(null),(async()=>{try{let s=await tf(h,t,r,o,l,a,i,c,e);if(n||!s)return;let d=await tx(s.oldContent,s.newContent,h,s.isNew,s.isDeleted);if(n)return;g(d)}catch(e){n||console.error("[BlockDiffViewer] projection failed:",e)}})(),()=>{n=!0}},[h,t,r,o,l,a,i,c,e]),(0,n.jsx)(e3,{cwd:e,highlightedFilePath:t,changedFiles:i,enableComments:d,qnameFilter:p?.changedQnames,qnameFilterFile:h,accentQnames:p?.changedQnames,accentFile:h,addedLines:p?.addedLines,addedLinesFile:h,onFocalChange:e=>e&&f(e),onContentSearch:u,headerExtraLeft:m,headerExtraRight:x})}async function tf(e,t,r,n,s,o,l,a,c){if(e===t)return{oldContent:r,newContent:n,isNew:s,isDeleted:o};if(!l.has(e))return null;let d=a?.get(e);if(!d)return null;let u=new URLSearchParams({cwd:c,file:e,type:d}),m=await i.t4.runPromiseExit((0,h.oh)(u));if("Success"!==m._tag)return null;let x=m.value;return{oldContent:x.oldContent,newContent:x.newContent,isNew:x.isNew??!1,isDeleted:x.isDeleted??!1}}function tp(e){let{refreshKey:t,className:r="h-full flex items-center justify-center p-4 bg-secondary",imgClassName:o="max-w-full max-h-full object-contain",alt:l}=e,a="absPath"in e&&"string"==typeof e.absPath,c=a?void 0:e.cwd,d=a?void 0:e.path,u=a?e.absPath:void 0,[m,h]=(0,s.useState)({kind:"loading"}),f=(0,s.useRef)(0);if((0,s.useEffect)(()=>{let e=++f.current;return h({kind:"loading"}),(async()=>{if(a){if(e!==f.current)return;h({kind:"ready",etag:null,size:0});return}let t=await i.t4.runPromiseExit((0,x.r6)(c,d));if(e!==f.current)return;if("Failure"===t._tag){let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause;h({kind:"error",message:r instanceof Error?r.message:"Unknown error"});return}let r=t.value;if(!r.ok)return h({kind:"error",message:`stat failed (${r.status})`});let n=r.data;n&&n.exists?"too-large"===n.category?h({kind:"too-large",size:n.size??0}):"image"!==n.category?h({kind:"error",message:`Not an image (${n.category})`}):h({kind:"ready",etag:n.etag||`t-${n.mtimeMs??Date.now()}`,size:n.size??0}):h({kind:"missing"})})(),()=>{f.current++}},[a,c,d,u,t]),"loading"===m.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("span",{className:"inline-block w-6 h-6 border-2 border-brand border-t-transparent rounded-full animate-spin"})});if("missing"===m.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:"File not found"})});if("too-large"===m.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Image too large to preview (",Math.round(m.size/1024/1024)," MB)"]})});if("error"===m.kind)return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("div",{className:"text-sm text-red-11",children:m.message})});let p=a?`/api/file?path=${encodeURIComponent(u)}&raw=true`:`/api/files/read?cwd=${encodeURIComponent(c)}&path=${encodeURIComponent(d)}&v=${encodeURIComponent(m.etag)}`;return(0,n.jsx)("div",{className:r,children:(0,n.jsx)("img",{src:p,alt:l??(d||u),className:o})})}function tg({cwd:e,selected:t,diff:r,showMarkdownPreview:l,setShowMarkdownPreview:a,changedFiles:i,fileGitStatusMap:c,onContentSearch:d,locateInTree:u,jsonPreview:m,setJsonPreview:x,jsonPreviewSearch:h,jsonPreviewPreRef:f}){let{t:p}=(0,o.Bd)(),[g,b]=(0,s.useState)("file"),[v,j]=(0,s.useState)("compact"),w=t.file.path,y=(0,ea.u)(w),{state:N}=eB(e,w),C=(0,s.useMemo)(()=>{if("ready"===N.state)return N.data.functions.filter(ez).map(e=>({name:e.name,startLine:e.startLine,endLine:e.endLine,params:e.params}))},[N]);return(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[y||"map"!==g?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary border-b border-border flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs font-mono text-muted-foreground",children:w}),(0,n.jsx)(eD.m,{content:p("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(`${e}/${w}`),(0,k.oR)(p("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent 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)(eD.m,{content:p("fileBrowser.locateInTree"),children:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),u(w)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent 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"}),!y&&"file"===g&&(0,n.jsx)("div",{className:"flex items-center gap-0.5 rounded border border-border overflow-hidden",children:["compact","full"].map(e=>(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),j(e)},className:`px-2 py-0.5 text-xs transition-colors ${v===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:p("compact"===e?"diffViewer.compact":"diffViewer.full")},e))}),!y&&(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(),b(e)},className:`px-2 py-0.5 text-xs transition-colors ${g===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:p("file"===e?"common.file":"common.codeMap")},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-auto",children:y?(0,n.jsx)(tp,{cwd:e,path:w,className:"p-4 flex items-center justify-center",imgClassName:"max-w-full max-h-[60vh] object-contain",alt:w}):(0,n.jsx)(T,{oldContent:r.oldContent,newContent:r.newContent,filePath:r.filePath,isNew:r.isNew,isDeleted:r.isDeleted,cwd:e,enableComments:!0,compact:"compact"===v,symbols:C,onPreview:!r.isDeleted&&Z(w)?()=>a(!0):!r.isDeleted&&w.endsWith(".json")?()=>x({content:r.newContent,filePath:r.filePath}):void 0,previewLabel:w.endsWith(".json")?p("common.readable"):p("common.preview"),onContentSearch:d})})]}):(0,n.jsx)(th,{cwd:e,filePath:r.filePath,oldContent:r.oldContent,newContent:r.newContent,isNew:r.isNew,isDeleted:r.isDeleted,changedFiles:i,fileGitStatusMap:c,enableComments:!0,onContentSearch:d,headerExtraLeft:({focalFile:t})=>{if(!t)return null;let r=c.get(t);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(eD.m,{content:p("common.copyAbsPath"),children:(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${e}/${t}`),(0,k.oR)(p("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent 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)(eD.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-accent 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.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(),b(e)},className:`px-2 py-0.5 text-[11px] transition-colors ${g===e?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,children:p("file"===e?"common.file":"common.codeMap")},e))})}),l&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>a(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(ex,{content:r.newContent,filePath:r.filePath,cwd:e,onClose:()=>a(!1)})})}),m&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>x(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl 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:m.filePath}),(0,n.jsx)("button",{onClick:()=>x(null),className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent 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)(et,{search:h}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4 bg-[#0d1117]",children:(0,n.jsx)("pre",{ref:f,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:H(m.content)})})]})})]})}function tb({branches:e,selectedBranch:t,onSelect:r,isLoading:l,pinnedBranches:a=[]}){let{t:i}=(0,o.Bd)(),[c,d]=(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)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{c&&h.current&&h.current.focus()},[c]);let f=u.toLowerCase(),p=new Set([...e?.local||[],...e?.remote||[]]),g=a.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),d(!1),m("")};return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>d(!c),disabled:l,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-slate-9 transition-transform ${c?"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"})})]}),c&&(0,n.jsxs)("div",{className:"absolute z-50 mt-1 w-full bg-card border border-border rounded-lg shadow-lg 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 placeholder-slate-9"})}),(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-accent 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-secondary 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-accent 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-secondary 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-accent 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")})]})]})]})}function tv(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 tj=(e,t)=>eM.tryPromise({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 eT.uV({message:`${e} failed`,cause:t})});function tw(e){return e.replace(/^\([^)]+\)\s*/,"")}let ty=(0,s.forwardRef)(function({displayString:e,documentation:t,x:r,y:l,container:a,onMouseEnter:i,onMouseLeave:c,onFindReferences:d,onSearch:u},m){let{t:x}=(0,o.Bd)(),h=(0,s.useRef)(null);(0,s.useImperativeHandle)(m,()=>h.current,[]);let f=a.getBoundingClientRect(),p=r-f.left,g=l-f.top,b=(0,s.useMemo)(()=>tw(e),[e]),v=(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,l=0,a=/\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=a.exec(e));){t.index>o&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o,t.index)},l++));let a=t[0];/^["']/.test(a)?s.push((0,n.jsx)("span",{className:"text-green-400",children:a},l++)):/^\d+$/.test(a)?s.push((0,n.jsx)("span",{className:"text-orange-300",children:a},l++)):r.test(a)?(r.lastIndex=0,s.push((0,n.jsx)("span",{className:"text-pink-400",children:a},l++))):s.push((0,n.jsx)("span",{className:"text-foreground",children:a},l++)),o=t.index+a.length}return o<e.length&&s.push((0,n.jsx)("span",{className:"text-foreground",children:e.slice(o)},l++)),s})(b),[b]);return(0,s.useEffect)(()=>{if(!h.current)return;let e=h.current,t=a.getBoundingClientRect(),n=e.getBoundingClientRect(),s=r-t.left,o=l-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,l,a]),(0,n.jsxs)("div",{ref:h,className:"absolute z-[200] max-w-lg bg-card border border-border rounded-lg shadow-xl px-3 py-2 pointer-events-none",style:{left:p,top:g},children:[(0,n.jsx)("pre",{className:"font-mono text-xs whitespace-pre-wrap break-all leading-relaxed",children:v}),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})]}),(d||u)&&(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:c,children:[d&&(0,n.jsx)("button",{onClick:d,className:"text-[11px] text-brand hover:underline cursor-pointer",children:x("hoverTooltip.findReferences")}),u&&(0,n.jsx)("button",{onClick:()=>u(function(e){let t=tw(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]}(e)),className:"text-[11px] text-brand hover:underline cursor-pointer",children:x("hoverTooltip.search")})]})]})]})});function tk({references:e,loading:t,onSelect:r,onClose:l}){let{t:a}=(0,o.Bd)(),i=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(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=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,C.kS)();if(t!==l.current)return;let o=new Map;for(let t=0;t<e.length;t++){let r=e[t];if(!r.lineText)continue;let l=(0,C.sQ)(r.file);if("text"!==l)try{let e=n.codeToTokens(r.lineText,{lang:l,theme:s}),a=(0,C.b8)(e.tokens[0]||[]);a&&o.set(t,a)}catch{}}t===l.current&&r(o)})()},[e,n]),t}(e),c=[],d=new Map;for(let t=0;t<e.length;t++){let r=e[t],n=d.get(r.file);void 0===n&&(n=c.length,d.set(r.file,n),c.push({file:r.file,items:[]})),c[n].items.push({ref:r,idx:t})}return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary 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:[a("references.title")," ",!t&&`(${e.length})`]}),(0,n.jsx)("button",{onClick:l,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(ev.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:a("references.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:a("references.notFound")}):c.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/30 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-accent/50 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 tN({results:e,loading:t,totalMatches:r,onSelect:l,onClose:a}){let{t:i}=(0,o.Bd)(),c=function(e){let[t,r]=(0,s.useState)(new Map),[n,o]=(0,s.useState)(!1),l=(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=++l.current,s=n?"github-dark":"github-light";(async()=>{let n=await (0,C.kS)(),o=new Map;for(let t of e){let e=(0,C.sQ)(t.path);if("text"!==e)for(let r of t.matches){if(!r.content)continue;let l=`${t.path}:${r.lineNumber}`;try{let t=n.codeToTokens(r.content,{lang:e,theme:s}),a=(0,C.b8)(t.tokens[0]||[]);a&&o.set(l,a)}catch{}}}t===l.current&&r(o)})()},[e,n]),t}(e);return(0,n.jsxs)("div",{className:"border-t border-border bg-secondary 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:[i("searchResults.title")," ",!t&&i("searchResults.nMatches",{count:r})]}),(0,n.jsx)("button",{onClick:a,className:"p-0.5 rounded hover:bg-accent text-muted-foreground",children:(0,n.jsx)(ev.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:i("searchResults.searching")}):0===e.length?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:i("searchResults.noResults")}):e.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/30 sticky top-0",children:e.path}),e.matches.map((t,r)=>{let s=`${e.path}:${t.lineNumber}`,o=c.get(s);return(0,n.jsxs)("button",{onClick:()=>l(e.path,t.lineNumber),className:"w-full text-left px-3 py-0.5 hover:bg-accent/50 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 tC=r(63728);function tS({onClose:e,cwd:t,initialTab:r="tree",tabSwitchTrigger:l,initialSearchQuery:a,searchQueryTrigger:c}){var d;let f,p,g,v,j,w,{t:y}=(0,o.Bd)(),{activeView:N}=(0,tC.R8)(),[C,S]=(0,s.useState)(r),[L,E]=(0,s.useState)("code"),M=(0,s.useRef)(null),$=(0,s.useRef)(!1),[P,R]=(0,s.useState)(null),[B,F]=(0,s.useState)(null),[I,O]=(0,s.useState)(!1),q=(0,s.useRef)(1),V=(0,s.useRef)(null),[K,U]=(0,s.useState)(null),J=(0,s.useRef)(null),[Q,X]=(0,s.useState)({isDirty:!1,isSaving:!1}),[Y,G]=(0,s.useState)(!1),[en,es]=(0,s.useState)(!1),[ei,ec]=(0,s.useState)(null),ed=(0,s.useRef)(null),eu=ee(ed),em=(0,s.useRef)(null),eh=ee(em),eb=function(e){let[t,r]=(0,s.useState)(!1);return{goToDefinition:(0,s.useCallback)(async(t,n,s)=>{r(!0);let o=await i.t4.runPromiseExit(tj("/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),ev=function(e){let[t,r]=(0,s.useState)(null),n=(0,s.useRef)(null),o=(0,s.useRef)(null),l=(0,s.useRef)(0),a=(0,s.useRef)(!1),c=(0,s.useRef)(null),d=(0,s.useRef)({x:0,y:0}),u=(0,s.useCallback)(e=>{c.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 m=(0,s.useRef)(!1),x=(0,s.useRef)(null),h=(0,s.useCallback)(()=>{let e=c.current;e&&m.current&&(e.style.pointerEvents="none"),m.current=!1,x.current&&(c.current?.removeEventListener("mouseleave",x.current),x.current=null)},[]),f=(0,s.useCallback)(()=>{let e=c.current;if(!e||m.current)return;m.current=!0,a.current=!0,e.style.pointerEvents="auto";let t=()=>{a.current=!1,h(),l.current++,r(null)};x.current=t,e.addEventListener("mouseleave",t)},[h]),p=(0,s.useCallback)((t,s,a,c)=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current);let d=++l.current;n.current=setTimeout(async()=>{let n=await i.t4.runPromiseExit(tj("/api/lsp/hover",{cwd:e,filePath:t,line:s,column:a}));if(d!==l.current||"Success"!==n._tag)return;let o=n.value.hover;o&&o.displayString&&r({...o,x:c.x,y:c.y,filePath:t,line:s,column:a})},300)},[e]),g=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),l.current++,o.current=setTimeout(function(){if(a.current)return;let e=c.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)(()=>{a.current=!0,o.current&&clearTimeout(o.current)},[]),v=(0,s.useCallback)(()=>{a.current=!1,l.current++,r(null)},[]),j=(0,s.useCallback)(()=>{n.current&&clearTimeout(n.current),o.current&&clearTimeout(o.current),a.current=!1,h(),l.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:u}}(t),ej=function(e){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(!1),[l,a]=(0,s.useState)(!1);return{references:t,loading:n,visible:l,findReferences:(0,s.useCallback)(async(t,n,s)=>{o(!0),a(!0);let l=await i.t4.runPromiseExit(tj("/api/lsp/references",{cwd:e,filePath:t,line:n,column:s}));"Success"===l._tag?r(l.value.references??[]):(console.error("[useLSP] references error:",l.cause),r([])),o(!1)},[e]),closeReferences:(0,s.useCallback)(()=>{a(!1),r([])},[])}}(t),ew=(f=(0,s.useRef)([]),p=(0,s.useRef)([]),g=(0,s.useCallback)(e=>{f.current.push(e),f.current.length>50&&(f.current=f.current.slice(-50)),p.current=[]},[]),v=(0,s.useCallback)(e=>{if(0===f.current.length)return null;let t=f.current.pop();return p.current.push(e),p.current.length>50&&(p.current=p.current.slice(-50)),t},[]),j=(0,s.useCallback)(e=>{if(0===p.current.length)return null;let t=p.current.pop();return f.current.push(e),f.current.length>50&&(f.current=f.current.slice(-50)),t},[]),{push:g,goBack:v,goForward:j,canGoBack:(0,s.useCallback)(()=>f.current.length>0,[]),canGoForward:(0,s.useCallback)(()=>p.current.length>0,[])}),ey=(0,eg.F)(),ek=function({cwd:e}){let[t,r]=(0,s.useState)([]),[n,o]=(0,s.useState)(null),[l,a]=(0,s.useState)(new Set),[c,d]=(0,s.useState)([]),[u,m]=(0,s.useState)(null),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(new Set),[b,v]=(0,s.useState)(null),[j,w]=(0,s.useState)(""),[y,k]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[S,L]=(0,s.useState)(!1),[E,M]=(0,s.useState)(!1),[T,$]=(0,s.useState)(null),P=(0,s.useRef)(null),[R,B]=(0,s.useState)(!1),[F,I]=(0,s.useState)(null),[D,A]=(0,s.useState)("center"),[_,W]=(0,s.useState)(null),[z,H]=(0,s.useState)(null),[O,q]=(0,s.useState)(!1),[V,K]=(0,s.useState)([]),[U,J]=(0,s.useState)(!1),[Q,X]=(0,s.useState)(null),[Y,Z]=(0,s.useState)(null),[G,ee]=(0,s.useState)(!1),[et,er]=(0,s.useState)(!1),en=(0,s.useMemo)(()=>c.map(e=>e.path).filter(Boolean),[c]),es=(0,s.useMemo)(()=>(0,ea.v3)(en),[en]),eo=(0,s.useMemo)(()=>new Set((0,ea.tW)(es)),[es]),el=(0,s.useMemo)(()=>j?n?(0,ea.KH)(n,j,y):(0,ea.q3)(t,j,y):null,[t,n,j,y]);(0,s.useEffect)(()=>{if(!el||0===el.size)return void v(null);let e=new Set;if(n){let t=new Set(n);for(let r of el)t.has(r)||e.add(r)}else{let r=t=>{for(let n of t)n.isDirectory&&n.children&&el.has(n.path)&&(e.add(n.path),r(n.children))};r(t)}v(e)},[el,t,n]);let ei=b??p,ec=(0,s.useRef)(null),ed=(0,s.useCallback)(t=>{ec.current&&clearTimeout(ec.current),ec.current=setTimeout(()=>{i.t4.runFork((0,x.Ft)(e,Array.from(t)).pipe(eM.tapError(e=>eM.sync(()=>console.error("Error saving expanded paths:",e))),eM.orElse(()=>eM.void)))},500)},[e]),eu=(0,s.useCallback)(async()=>{L(!0),$(null),await i.t4.runPromise((0,x.mP)(e).pipe(eM.match({onSuccess:e=>{e.error?$(e.error):(r(e.files??[]),e.expandedPaths&&Array.isArray(e.expandedPaths)&&g(new Set(e.expandedPaths)))},onFailure:e=>{console.error("Error loading files:",e),$("Failed to load files")}}))),L(!1)},[e]),em=(0,s.useCallback)(()=>{i.t4.runPromise((0,x.DZ)(e).pipe(eM.match({onSuccess:e=>{e.paths&&o(e.paths)},onFailure:e=>{console.error("Error loading file index:",e)}})))},[e]),ex=(0,s.useCallback)(async t=>{a(e=>new Set([...e,t])),await i.t4.runPromise((0,x.gZ)(e,t).pipe(eM.match({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,ea.MB)(n,t);return s&&(s.children=e.children),n})},onFailure:e=>{console.error("Error loading directory:",e)}}))),a(e=>{let r=new Set(e);return r.delete(t),r})},[e]),eh=(0,s.useRef)(l);eh.current=l,(0,s.useEffect)(()=>{for(let e of b??p){let r=(0,ea.MB)(t,e);r&&r.isDirectory&&!r.children&&!eh.current.has(e)&&ex(e)}},[t,p,b,ex]);let ef=(0,s.useCallback)(async()=>{await i.t4.runPromise((0,x.r9)(e).pipe(eM.match({onSuccess:e=>d(e.files??[]),onFailure:e=>console.error("Error loading recent files:",e)})))},[e]),ep=(0,s.useCallback)(async t=>{d(e=>{let r=e.filter(e=>e.path!==t);return[{path:t},...r].slice(0,15)}),await i.t4.runPromise((0,x.YW)(e,t).pipe(eM.tapError(e=>eM.sync(()=>console.error("Error adding to recent files:",e))),eM.orElse(()=>eM.void)))},[e]),eg=(0,s.useCallback)((t,r,n,s)=>{d(e=>e.map(e=>e.path===t?{...e,scrollLine:r,cursorLine:n,cursorCol:s}:e)),i.t4.runFork((0,x.YW)(e,t,{scrollLine:r,cursorLine:n,cursorCol:s}).pipe(eM.orElse(()=>eM.void)))},[e]),eb=(0,s.useCallback)(e=>c.find(t=>t.path===e),[c]),ev=(0,s.useCallback)(async t=>{let r=t||u;r&&(J(!0),X(null),await i.t4.runPromise((0,x.eE)(e,r).pipe(eM.match({onSuccess:e=>{e.error?X(e.error):K(e.blame??[])},onFailure:e=>{console.error("Error loading blame:",e),X("Failed to load blame info")}}))),J(!1))},[e,u]),ej=(0,s.useCallback)(async t=>{M(!0),f(null),q(!1),K([]),X(null),Z(null);let r=eM.gen(function*(){let r=yield*(0,x.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"binary":return{type:"binary",message:"Cannot preview binary file",size:n.size,mtime:n.mtimeMs};case"too-large":return{type:"error",message:"File too large to preview",size:n.size,mtime:n.mtimeMs};default:{let r=yield*(0,x.K9)(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 i.t4.runPromise(r.pipe(eM.match({onSuccess:e=>f(e),onFailure:e=>{console.error("Error loading file content:",e),f({type:"error",message:"Failed to load file"})}}))),ep(t),ev(t),M(!1)},[e,ep,ev]),ew=(0,s.useCallback)(()=>{O?q(!1):(q(!0),0===V.length&&ev())},[O,V.length,ev]),ey=(0,s.useCallback)((e,t)=>{if(!e)return;if(m(e),I(t??null),null==t){let t=c.find(t=>t.path===e);t?.scrollLine?(I(t.scrollLine),A("start"),W(t.cursorLine??null),H(t.cursorCol??null)):(A("center"),W(null),H(null))}else A("center"),W(null),H(null);ej(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("/"));g(t=>{let r=new Set(t),n=!1;for(let t of e)r.has(t)||(r.add(t),n=!0);return n&&ed(r),n?r:t})}},[ej,ed,c]),ek=(0,s.useCallback)(e=>{if(b)v(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r});else{let r=!p.has(e);if(g(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),ed(r),r}),r){let r=(0,ea.MB)(t,e);r&&r.isDirectory&&!r.children&&ex(e)}}},[b,ed,p,t,ex]);return{files:t,setFiles:r,fileIndex:n,setFileIndex:o,loadingDirs:l,expandedPaths:p,setExpandedPaths:g,searchTreeExpandedPaths:b,setSearchTreeExpandedPaths:v,effectiveExpandedPaths:ei,searchQuery:j,setSearchQuery:w,searchExactMatch:y,setSearchDirExact:k,matchedPaths:el,creatingItem:N,setCreatingItem:C,isLoadingFiles:S,fileError:T,searchInputRef:P,shouldScrollToSelected:R,setShouldScrollToSelected:B,targetLineNumber:F,setTargetLineNumber:I,targetScrollAlign:D,setTargetScrollAlign:A,initialCursorLine:_,initialCursorCol:z,setInitialCursorLine:W,setInitialCursorCol:H,selectedPath:u,setSelectedPath:m,fileContent:h,setFileContent:f,isLoadingContent:E,recentFiles:c,recentFilePaths:en,setRecentFiles:d,recentFilesTree:es,recentTreeDirPaths:eo,showBlame:O,setShowBlame:q,blameLines:V,isLoadingBlame:U,blameError:Q,blameSelectedCommit:Y,setBlameSelectedCommit:Z,showMarkdownPreview:G,setShowMarkdownPreview:ee,showEditor:et,setShowEditor:er,saveExpandedPaths:ed,loadFiles:eu,loadFileIndex:em,loadDirectory:ex,loadRecentFiles:ef,addToRecentFiles:ep,updateRecentFilePosition:eg,getRecentFilePosition:eb,loadFileContent:ej,loadBlame:ev,handleToggleBlame:ew,handleSelectFile:ey,handleToggle:ek}}({cwd:t});d=ek.selectedPath,w=(0,s.useRef)(null),(0,s.useEffect)(()=>{d&&d!==w.current&&tv(d)&&(w.current=d,i.t4.runFork(tj("/api/lsp/warmup",{cwd:t,filePath:d}).pipe(eM.asVoid).pipe(eM.orElse(()=>eM.void))))},[t,d]);let eN=function({cwd:e,onSearchComplete:t}){let[r,n]=(0,s.useState)(""),[o,l]=(0,s.useState)([]),[a,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)(null),[m,x]=(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){l([]),g(null);return}if(n.length<2)return void u(z.A.t("fileBrowser.searchMinChars"));c(!0),u(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=eM.tryPromise({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 eT.uV({message:"content search failed",cause:e})});await i.t4.runPromise(o.pipe(eM.match({onSuccess:e=>{l(e.results),g({totalFiles:e.totalFiles,totalMatches:e.totalMatches,truncated:e.truncated}),x(new Set(e.results.map(e=>e.path))),e.results.length>0&&t?.()},onFailure:e=>{u(e.cause instanceof Error?e.cause.message:"Search failed"),l([])}}))),c(!1)},[e,h,t]);return{contentSearchQuery:r,setContentSearchQuery:n,contentSearchResults:o,isSearching:a,searchError:d,searchExpandedPaths:m,searchOptions:h,setSearchOptions:f,searchStats:p,contentSearchInputRef:b,performContentSearch:v,handleSearchToggle:(0,s.useCallback)(e=>{x(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[])}}({cwd:t,onSearchComplete:()=>G(!0)}),eC=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(!1),[a,c]=(0,s.useState)(null),[d,u]=(0,s.useState)(null),[m,x]=(0,s.useState)(null),[f,p]=(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(_(w));for(let t of g)e.delete(t);return e},[w,g]),L=(0,s.useMemo)(()=>{let e=new Set(_(N));for(let t of v)e.delete(t);return e},[N,v]),[E,M]=(0,s.useState)(!1),[T,$]=(0,s.useState)(0),P=(0,s.useCallback)(async()=>{l(!0),c(null),await i.t4.runPromise((0,h.lv)(e).pipe(eM.match({onSuccess:e=>{n(e);let t=A(e.staged),r=A(e.unstaged);y(t),C(r)},onFailure:e=>{c(e.cause instanceof Error?e.cause.message:"Unknown error")}}))),l(!1)},[e]),R=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),B=(0,s.useCallback)(e=>{j(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),F=(0,s.useCallback)((e,r)=>{u({file:e,type:r}),t(e.path)},[t]),I=(0,s.useCallback)(async(e,t,r,n)=>{let s=await i.t4.runPromiseExit(e);"Success"===s._tag?(await P(),(0,k.oR)(t,"success")):(console.error(r,s.cause),(0,k.oR)(n,"error"))},[P]),D=(0,s.useCallback)(t=>I((0,h.Iz)(e,[t]),z.A.t("toast.staged"),"Error staging file:",z.A.t("toast.stageFailed")),[e,I]),W=(0,s.useCallback)(t=>I((0,h.X0)(e,[t]),z.A.t("toast.unstaged"),"Error unstaging file:",z.A.t("toast.unstageFailed")),[e,I]),H=(0,s.useCallback)(async t=>{0!==t.length&&await I((0,h.Iz)(e,t),z.A.t("toast.stagedNFiles",{count:t.length}),"Error staging files:",z.A.t("toast.stageFailed"))},[e,I]),O=(0,s.useCallback)(async t=>{0!==t.length&&await I((0,h.X0)(e,t),z.A.t("toast.unstagedNFiles",{count:t.length}),"Error unstaging files:",z.A.t("toast.unstageFailed"))},[e,I]),q=(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=eM.gen(function*(){r.length>0&&(yield*(0,h.Ub)(e,r,!0)),n.length>0&&(yield*(0,h.Ub)(e,n,!1))});await I(s,z.A.t("toast.discardedNFiles",{count:t.length}),"Error discarding files:",z.A.t("toast.discardFailed"))},[e,I]),V=(0,s.useCallback)(async()=>{r?.unstaged.length&&await I((0,h.Iz)(e,r.unstaged.map(e=>e.path)),z.A.t("toast.stagedNFiles",{count:r.unstaged.length}),"Error staging all files:",z.A.t("toast.stageFailed"))},[e,r,I]),K=(0,s.useCallback)(async()=>{r?.staged.length&&await I((0,h.X0)(e,r.staged.map(e=>e.path)),z.A.t("toast.unstagedNFiles",{count:r.staged.length}),"Error unstaging all files:",z.A.t("toast.unstageFailed"))},[e,r,I]),U=(0,s.useCallback)(async t=>{let r="untracked"===t.status;await I((0,h.Ub)(e,[t.path],r),r?z.A.t("toast.deletedFile"):z.A.t("toast.discardedChanges"),"Error discarding file:",z.A.t("toast.discardFailed"))},[e,I]),J=(0,s.useCallback)(async()=>{if(!r?.unstaged.length||!await (0,k.lJ)(z.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=eM.gen(function*(){n.length>0&&(yield*(0,h.Ub)(e,n,!1)),t.length>0&&(yield*(0,h.Ub)(e,t,!0))});await I(o,z.A.t("toast.discardedNFiles",{count:s}),"Error discarding all:",z.A.t("toast.discardFailed"))},[e,r,I]);return(0,s.useEffect)(()=>{d?(p(!0),i.t4.runPromiseExit((0,h.w2)(e,d.file.path,d.type)).then(e=>{"Success"===e._tag?x(e.value):console.error("Error fetching diff:",e.cause),p(!1)})):x(null)},[d,e,T]),{status:r,setStatus:n,statusLoading:o,statusError:a,statusSelectedFile:d,statusDiff:m,statusDiffLoading:f,stagedExpandedPaths:S,unstagedExpandedPaths:L,stagedTree:w,setStagedTree:y,unstagedTree:N,setUnstagedTree:C,showStatusDiffPreview:E,setShowStatusDiffPreview:M,fetchStatus:P,handleStagedToggle:R,handleUnstagedToggle:B,handleStatusFileSelect:F,handleStage:D,handleUnstage:W,handleStageFiles:H,handleUnstageFiles:O,handleDiscardFiles:q,handleStageAll:V,handleUnstageAll:K,handleDiscardFile:U,handleDiscardAll:J,refreshDiff:(0,s.useCallback)(()=>$(e=>e+1),[])}}({cwd:t,addToRecentFiles:ek.addToRecentFiles}),eS=(0,s.useMemo)(()=>{let e=new Set;if(eC.status){for(let t of eC.status.staged)e.add(t.path);for(let t of eC.status.unstaged)e.add(t.path)}return e},[eC.status]),eL=(0,s.useMemo)(()=>{let e=new Map;if(eC.status){for(let t of eC.status.staged)e.set(t.path,"staged");for(let t of eC.status.unstaged)e.set(t.path,"unstaged")}return e},[eC.status]),eE=function({cwd:e,addToRecentFiles:t}){let[r,n]=(0,s.useState)(null),[o,l]=(0,s.useState)(""),[a,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(null),[m,x]=(0,s.useState)([]),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)(new Set),[v,j]=(0,s.useState)(null),[w,y]=(0,s.useState)(null),[k,N]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,E]=(0,s.useState)(!1),[M,T]=(0,s.useState)(!0),[$,P]=(0,s.useState)(!1),[R,B]=(0,s.useState)(!1),[F,I]=(0,s.useState)(null),D=(0,s.useRef)(null),[W,H]=(0,s.useState)(null),[O,q]=(0,s.useState)(!1),[V,K]=(0,s.useState)(""),[U,J]=(0,s.useState)(""),[Q,X]=(0,s.useState)([]),[Y,Z]=(0,s.useState)([]),[G,ee]=(0,s.useState)(new Set),[et,er]=(0,s.useState)(null),[en,es]=(0,s.useState)(null),[eo,el]=(0,s.useState)(!1),[ei,ec]=(0,s.useState)(!1),ed=(0,s.useCallback)(()=>{N(!0),I(null),i.t4.runPromise((0,h.r4)(e).pipe(eM.match({onSuccess:e=>{e.local&&e.current?(n(e),l(e.current),e.upstream&&K(e.upstream)):(I(z.A.t("git.cannotGetBranches")),n(null))},onFailure:e=>{console.error(e),"NotFoundError"===e._tag?I(z.A.t("git.notGitRepo")):I(z.A.t("git.getBranchesFailed")),n(null)}}))).finally(()=>N(!1))},[e]),eu=(0,s.useCallback)(t=>{S(!0),u(null),x([]),p([]),j(null),y(null),T(!0),i.t4.runPromise((0,h.Bj)(e,t,ea.B_).pipe(eM.match({onSuccess:e=>{let t=e.commits||[];c(t),T(t.length>=ea.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>S(!1))},[e]),em=(0,s.useCallback)(()=>{if(L||!M||!o)return;E(!0);let t=a.length;i.t4.runPromise((0,h.Bj)(e,o,ea.B_,t).pipe(eM.match({onSuccess:e=>{let t=e.commits||[];t.length>0&&c(e=>[...e,...t]),T(t.length>=ea.B_)},onFailure:e=>{console.error(e)}}))).finally(()=>E(!1))},[e,o,a.length,L,M]),ex=(0,s.useCallback)(e=>{let{scrollTop:t,scrollHeight:r,clientHeight:n}=e.target;r-t-n<100&&em()},[em]),eh=(0,s.useCallback)(t=>{u(t),j(null),y(null),P(!0),i.t4.runPromise((0,h.Zi)(e,t.hash).pipe(eM.match({onSuccess:e=>{let t=e.files||[];x(t);let r=A(t);p(r),b(new Set(_(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>P(!1))},[e]),ef=(0,s.useCallback)(r=>{d&&(j(r),t(r.path),B(!0),i.t4.runPromise((0,h.Zi)(e,d.hash,r.path).pipe(eM.match({onSuccess:e=>y(e),onFailure:e=>{console.error(e)}}))).finally(()=>B(!1)))},[e,d,t]),ep=(0,s.useCallback)(e=>{b(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),eg=(0,s.useCallback)(t=>{el(!0),er(null),es(null),i.t4.runPromise((0,h.yy)(e,t).pipe(eM.match({onSuccess:e=>{let t=e.files||[];X(t);let r=A(t);Z(r),ee(new Set(_(r)))},onFailure:e=>{console.error(e)}}))).finally(()=>el(!1))},[e]),eb=(0,s.useCallback)(r=>{er(r),t(r.path),ec(!0),i.t4.runPromise((0,h.yy)(e,U,r.path).pipe(eM.match({onSuccess:e=>es(e),onFailure:e=>{console.error(e)}}))).finally(()=>ec(!1))},[e,U,t]),ev=(0,s.useCallback)(e=>{ee(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ej=(0,s.useCallback)(e=>{if(q(e),e){let e="origin/main";J(e),eg(e)}else X([]),Z([]),er(null),es(null),J("")},[V,eg]);return{branches:r,selectedBranch:o,setSelectedBranch:l,commits:a,setCommits:c,selectedCommit:d,setSelectedCommit:u,historyFiles:m,historyFileTree:f,historyExpandedPaths:g,historySelectedFile:v,historyFileDiff:w,isLoadingBranches:k,isLoadingCommits:C,isLoadingMore:L,hasMoreCommits:M,setHasMoreCommits:T,isLoadingHistoryFiles:$,isLoadingHistoryDiff:R,historyError:F,commitListRef:D,tooltipPos:W,loadBranches:ed,loadCommits:eu,loadMoreCommits:em,handleCommitListScroll:ex,handleSelectCommit:eh,handleSelectHistoryFile:ef,handleHistoryToggle:ep,handleCommitInfoMouseMove:(0,s.useCallback)(e=>{H({x:e.clientX,y:e.clientY})},[]),handleCommitInfoMouseLeave:(0,s.useCallback)(()=>{H(null)},[]),compareMode:O,toggleCompareMode:ej,compareBaseBranch:U,setCompareBaseBranch:J,upstreamBranch:V,compareFiles:Q,compareFileTree:Y,compareExpandedPaths:G,compareSelectedFile:et,compareFileDiff:en,isLoadingCompareFiles:eo,isLoadingCompareDiff:ei,handleSelectCompareFile:eb,handleCompareToggle:ev,loadCompareFiles:eg}}({cwd:t,addToRecentFiles:ek.addToRecentFiles}),e$=(0,s.useRef)(!1),eP=(0,s.useCallback)(e=>{ek.setFileContent(t=>t?.type==="text"?{...t,content:e}:t),ek.showEditor||(e$.current=!0,ek.setShowEditor(!0))},[ek]);(0,s.useEffect)(()=>{ek.showEditor&&e$.current&&(J.current?.markDirty(),e$.current=!1)},[ek.showEditor]);let eR=(0,s.useCallback)(e=>{ek.setShowEditor(!0)},[ek]),eB=(0,s.useCallback)(async()=>{if(!ek.fileContent||"text"!==ek.fileContent.type||!ek.fileContent.content)return;let e=await i.t4.runPromiseExit((0,x.OJ)({cwd:t,path:ek.selectedPath,content:ek.fileContent.content}));try{if("Failure"===e._tag||!e.value.ok)throw Error("Failed to save file");let t=e.value.data?.mtime;t&&ek.setFileContent(e=>e?.type==="text"?{...e,mtime:t}:e),(0,k.oR)(y("toast.savedSuccess"),"success")}catch{(0,k.oR)(y("toast.saveFailed"),"error")}},[t,ek]),eF=(0,s.useCallback)(()=>{if(!ek.selectedPath)return;let e=q.current,t=V.current;e>0&&ek.updateRecentFilePosition(ek.selectedPath,e,t?t.cursorLine+1:e,t?t.cursorCol+1:1)},[ek]),eI=(0,s.useCallback)(async(e,t)=>{let r=e!==ek.selectedPath;if(r&&ek.showEditor){if(Q.isDirty&&(!await (0,k.lJ)(y("fileBrowser.saveBeforeSwitch"),{confirmText:y("fileBrowser.saveAndSwitch"),cancelText:y("common.cancel")})||(await J.current?.save(),J.current?.isDirty)))return;ek.setShowEditor(!1)}r&&eF(),ek.handleSelectFile(e,t)},[ek,eF,Q.isDirty,y]),eD=(0,s.useMemo)(()=>{let e=eN.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,ea.v3)(r),s=new Set((0,ea.tW)(n));return{files:n,expandDirs:s,matchMap:t}},[eN.contentSearchResults]),[eA,e_]=(0,s.useState)(new Set);(0,s.useEffect)(()=>{e_(eD.expandDirs)},[eD.expandDirs]);let eW=(0,s.useCallback)(e=>{e_(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),ez=(0,s.useCallback)(e=>{if(e.isDirectory)return null;let t=eD.matchMap.get(e.path);return t?(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:t.matches.length}):null},[eD.matchMap]),eH=Y&&eN.contentSearchResults.length>0,eO=!!ek.selectedPath&&null!==tv(ek.selectedPath),eq=(0,s.useCallback)(async(e,r)=>{if(!ek.selectedPath||!eO)return;let n=await eb.goToDefinition(ek.selectedPath,e,r);if(0===n.length)return;let s=n[0],o=t.endsWith("/")?t:t+"/",l=s.file.startsWith(o)?s.file.slice(o.length):s.file;ew.push({filePath:ek.selectedPath,lineNumber:q.current}),l===ek.selectedPath?ek.setTargetLineNumber(s.line):eI(l,s.line)},[ek,t,eO,eb,ew]),eV=(0,s.useCallback)((e,t,r)=>{ek.selectedPath&&eO&&ev.onTokenMouseEnter(ek.selectedPath,e,t,r)},[ek.selectedPath,eO,ev]),eK=(0,s.useCallback)(e=>{let r=t.endsWith("/")?t:t+"/",n=e.file.startsWith(r)?e.file.slice(r.length):e.file;ek.selectedPath&&ew.push({filePath:ek.selectedPath,lineNumber:q.current}),n===ek.selectedPath?ek.setTargetLineNumber(e.line):eI(n,e.line)},[ek,t,ew]),eU=(0,s.useMemo)(()=>{if(!eC.status)return null;let e=new Map,t=e=>{switch(e){case"modified":default:return"M";case"added":return"A";case"deleted":return"D";case"renamed":return"R";case"untracked":return"?"}};for(let r of eC.status.staged)e.set(r.path,t(r.status));for(let r of eC.status.unstaged)e.set(r.path,t(r.status));return e},[eC.status]);(0,s.useEffect)(()=>{R(M.current)},[]),(0,s.useEffect)(()=>{S(r)},[r,l]),(0,s.useEffect)(()=>{a&&(S("search"),eN.setContentSearchQuery(a),eN.performContentSearch(a))},[c]);let eJ=(0,s.useCallback)(e=>{S(e),ek.setBlameSelectedCommit(null),"history"===e&&eE.selectedBranch&&eE.loadCommits(eE.selectedBranch)},[ek,eE.selectedBranch,eE.loadCommits]),eQ=(0,s.useCallback)(()=>{if(!ek.selectedPath)return;let e={filePath:ek.selectedPath,lineNumber:q.current},t=ew.goBack(e);t&&(t.filePath===ek.selectedPath?ek.setTargetLineNumber(t.lineNumber):eI(t.filePath,t.lineNumber))},[ek,ew]),eX=(0,s.useCallback)(()=>{if(!ek.selectedPath)return;let e={filePath:ek.selectedPath,lineNumber:q.current},t=ew.goForward(e);t&&(t.filePath===ek.selectedPath?ek.setTargetLineNumber(t.lineNumber):eI(t.filePath,t.lineNumber))},[ek,ew]),eY=(0,s.useCallback)(async e=>{let r=e.split("/").pop()||e;"Success"===(await i.t4.runPromiseExit((0,x.__)({cwd:t,paths:[e],op:"copy"})))._tag?(0,k.oR)(y("toast.copiedName",{name:r}),"success"):(0,k.oR)(y("toast.copyFailed"),"error")},[t,y]),eZ=(0,s.useCallback)(async e=>{let r=await i.t4.runPromiseExit((0,x.dt)());if("Success"!==r._tag||!r.value.path)return void(0,k.oR)(y("toast.noFileToPaste"),"info");let n=r.value.path,s=await i.t4.runPromiseExit((0,x.Nn)({cwd:t,targetDir:e,sourceAbsPath:n}));if("Success"===s._tag)(0,k.oR)(y("toast.pastedFile",{name:s.value.newName}),"success"),ek.loadDirectory(e),ek.loadFileIndex();else{let e="Fail"===s.cause._tag?s.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:y("toast.pasteFailed");(0,k.oR)(r,"error")}},[t,ek,y]),eG=(0,s.useRef)(0);(0,s.useEffect)(()=>{let t=t=>{let r="explorer"===N;if(r&&t.ctrlKey&&!t.metaKey&&"Minus"===t.code){t.preventDefault(),t.shiftKey?eX():eQ();return}if(r&&(t.metaKey||t.ctrlKey)&&"p"===t.key){t.preventDefault(),O(e=>!e);return}if(r&&(t.metaKey||t.ctrlKey)&&"c"===t.key&&!t.shiftKey){let e=t.target?.tagName,r=window.getSelection()?.toString();if(("tree"===C||"recent"===C)&&ek.selectedPath&&!r&&"INPUT"!==e&&"TEXTAREA"!==e){t.preventDefault(),eY(ek.selectedPath);return}}if(r&&(t.metaKey||t.ctrlKey)&&"v"===t.key){let e=t.target?.tagName;if(("tree"===C||"recent"===C)&&"INPUT"!==e&&"TEXTAREA"!==e&&!t.target?.isContentEditable){t.preventDefault(),eZ((0,ea.S7)(ek.selectedPath,ek.files));return}}if(r&&(t.metaKey||t.ctrlKey)&&"f"===t.key){if(ei){t.preventDefault(),eh.open();return}if(en&&ek.selectedPath?.endsWith(".json")){t.preventDefault(),eu.open();return}}if(r&&"Escape"===t.key){if(I)return void O(!1);if(eh.isVisible)return void eh.close();if(eu.isVisible)return void eu.close();if(ei)return void ec(null);let t=Date.now();if(t-eG.current<3e3)return;eG.current=t,ej.visible?ej.closeReferences():Y?G(!1):ek.blameSelectedCommit?ek.setBlameSelectedCommit(null):ek.showBlame?ek.setShowBlame(!1):e()}};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,ek.showBlame,ek.blameSelectedCommit,ek,I,ej.visible,ej.closeReferences,Y,eQ,eX,en,eu,ei,eh,C,eY,eZ,N]),(0,s.useEffect)(()=>{ek.loadFiles(),ek.loadFileIndex(),ek.loadRecentFiles(),eC.fetchStatus(),eE.loadBranches()},[]),(0,s.useEffect)(()=>{let e=()=>{eC.fetchStatus()};return window.addEventListener("git-status-changed",e),()=>window.removeEventListener("git-status-changed",e)},[eC.fetchStatus]);let e0=(0,s.useRef)(ey);(0,s.useEffect)(()=>{ey&&!e0.current&&(ek.loadFiles(),ek.loadFileIndex(),ek.loadRecentFiles(),eC.fetchStatus(),eE.loadBranches()),e0.current=ey},[ey]),(0,s.useEffect)(()=>{eE.selectedBranch&&eE.loadCommits(eE.selectedBranch)},[eE.selectedBranch,eE.loadCommits]);let e1=(0,s.useRef)(C);(0,s.useEffect)(()=>{let e=e1.current;if(e1.current=C,("tree"===C||"recent"===C)&&ek.recentFiles.length>0){let t=ek.recentFiles[0].path;ek.selectedPath&&("status"!==e&&"history"!==e||ek.selectedPath===t)||(ek.setShouldScrollToSelected(!0),eI(t))}},[C,ek.recentFiles,ek.selectedPath,eI,ek]);let e2=(0,s.useRef)(eE.selectedBranch);e2.current=eE.selectedBranch;let e5=(0,s.useRef)(ek.selectedPath);e5.current=ek.selectedPath;let e4=(0,s.useRef)(ek.fileContent?.type);e4.current=ek.fileContent?.type;let e6=(0,s.useCallback)(async e=>{try{let{data:r}=e;if(!r)return;let n=r.some(e=>"git"===e.type),s=r.some(e=>"file"===e.type),o=[];if((s||n)&&(o.push(i.t4.runPromise((0,x.mP)(t)).then(e=>{e.error||ek.setFiles(t=>(0,ea.HR)(e.files??[],t))}).catch(()=>{})),o.push(i.t4.runPromise((0,x.DZ)(t)).then(e=>{e.paths&&ek.setFileIndex(e.paths)}).catch(()=>{})),o.push(i.t4.runPromise((0,x.r9)(t)).then(e=>{ek.setRecentFiles(e.files??[])}).catch(()=>{}))),n||s){o.push(i.t4.runPromise((0,h.lv)(t)).then(e=>{eC.setStatus(e);let t=A(e.staged),r=A(e.unstaged);eC.setStagedTree(t),eC.setUnstagedTree(r)}).catch(()=>{})),eC.refreshDiff(),n&&eE.loadBranches();let e=e2.current;e&&o.push(i.t4.runPromise((0,h.Bj)(t,e,ea.B_)).then(e=>{let t=e.commits??[];eE.setCommits(t),eE.setHasMoreCommits(t.length>=ea.B_)}).catch(()=>{}))}let l=e5.current,a=e4.current;l&&"text"===a&&o.push(i.t4.runPromise((0,x.K9)(t,l)).then(e=>{let t=e.ok?e.data:null;t&&"string"==typeof t.content&&ek.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,ep.h)({url:`/ws/watch?cwd=${encodeURIComponent(t)}`,onMessage:e6,enabled:ey});let e8=(0,s.useCallback)(e=>{let t=e.split("/");if(t.length>1){let e=[];for(let r=1;r<t.length;r++)e.push(t.slice(0,r).join("/"));ek.setExpandedPaths(t=>{let r=new Set(t);for(let t of e)r.add(t);return ek.saveExpandedPaths(r),r})}ek.setSelectedPath(e),ek.setShouldScrollToSelected(!0),S("tree")},[ek]);return(0,n.jsxs)(b.SU,{container:P,children:[(0,n.jsxs)("div",{ref:M,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:"w-80 flex-shrink-0 border-r border-border flex flex-col overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex border-b border-border",children:[(0,n.jsx)("button",{onClick:()=>eJ("tree"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"tree"===C?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:y("fileBrowser.directoryTree")}),(0,n.jsx)("button",{onClick:()=>eJ("search"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"search"===C?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:y("fileBrowser.searchTab")}),(0,n.jsx)("button",{onClick:()=>eJ("recent"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"recent"===C?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:y("fileBrowser.recentTab")}),(0,n.jsx)("button",{onClick:()=>eJ("status"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"status"===C?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:y("fileBrowser.changesTab")}),(0,n.jsx)("button",{onClick:()=>eJ("history"),className:`flex-1 px-2 py-2 text-sm font-medium transition-colors ${"history"===C?"text-brand border-b-2 border-brand":"text-muted-foreground hover:text-foreground dark:hover:text-foreground"}`,children:y("fileBrowser.historyTab")})]}),"tree"===C&&(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:ek.searchInputRef,type:"text",value:ek.searchQuery,onChange:e=>ek.setSearchQuery(e.target.value),placeholder:y("fileBrowser.searchFiles"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),ek.searchQuery&&(0,n.jsx)("button",{onClick:()=>ek.setSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:y("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:()=>ek.setSearchDirExact(e=>!e),className:`px-1 py-0.5 rounded transition-colors text-xs font-mono font-bold border ${ek.searchExactMatch?"border-brand text-brand bg-brand/10":"border-transparent text-muted-foreground hover:text-foreground hover:bg-accent"}`,title:ek.searchExactMatch?y("fileBrowser.exactMatchOn"):y("fileBrowser.exactMatchOff"),children:"ab"}),(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:()=>ek.loadFiles(),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:y("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:()=>ek.searchTreeExpandedPaths?ek.setSearchTreeExpandedPaths(new Set):ek.setExpandedPaths(new Set),className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:y("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"===C&&(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:eN.contentSearchInputRef,type:"text",value:eN.contentSearchQuery,onChange:e=>eN.setContentSearchQuery(e.target.value),onKeyDown:e=>{"Enter"===e.key&&eN.performContentSearch(eN.contentSearchQuery)},placeholder:y("fileBrowser.searchFileContent"),className:"w-full px-3 py-1.5 pr-7 text-sm border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"}),eN.contentSearchQuery&&(0,n.jsx)("button",{onClick:()=>eN.setContentSearchQuery(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 text-slate-9 hover:text-foreground rounded-sm transition-colors",title:y("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:()=>eN.performContentSearch(eN.contentSearchQuery),disabled:eN.isSearching||!eN.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:eN.isSearching?"...":y("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:eN.searchOptions.caseSensitive,onChange:e=>eN.setSearchOptions(t=>({...t,caseSensitive:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:y("fileBrowser.caseSensitive")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eN.searchOptions.wholeWord,onChange:e=>eN.setSearchOptions(t=>({...t,wholeWord:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:y("fileBrowser.wholeWord")})]}),(0,n.jsxs)("label",{className:"flex items-center gap-1 cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:eN.searchOptions.regex,onChange:e=>eN.setSearchOptions(t=>({...t,regex:e.target.checked})),className:"w-3 h-3"}),(0,n.jsx)("span",{className:"text-muted-foreground",children:y("fileBrowser.regex")})]}),(0,n.jsx)("input",{type:"text",value:eN.searchOptions.fileType,onChange:e=>eN.setSearchOptions(t=>({...t,fileType:e.target.value})),placeholder:y("fileBrowser.fileTypes"),className:"w-24 px-2 py-0.5 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9"})]})]}),"history"===C&&(0,n.jsx)("div",{className:"p-3 border-b border-border",children:eE.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:"truncate",children:eE.branches?.current||"HEAD"}),(0,n.jsx)("span",{className:"text-xs text-green-11 flex-shrink-0",children:"HEAD"})]}),(0,n.jsx)("button",{onClick:()=>eE.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:y("fileBrowser.compareModeOff"),children:y("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)(tb,{branches:eE.branches,selectedBranch:eE.compareBaseBranch,onSelect:e=>{eE.setCompareBaseBranch(e),eE.loadCompareFiles(e)},isLoading:eE.isLoadingBranches,pinnedBranches:["origin/main",...eE.upstreamBranch&&"origin/main"!==eE.upstreamBranch?[eE.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)(tb,{branches:eE.branches,selectedBranch:eE.selectedBranch,onSelect:e=>{eE.setSelectedBranch(e)},isLoading:eE.isLoadingBranches,pinnedBranches:["origin/main",...eE.upstreamBranch&&"origin/main"!==eE.upstreamBranch?[eE.upstreamBranch]:[]]})}),(0,n.jsx)("button",{onClick:()=>eE.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-accent border border-border",title:y("fileBrowser.compareModeOn"),children:y("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"===C?"":"hidden"}`,children:[ek.creatingItem&&(0,n.jsxs)("div",{className:"px-2 py-1.5 border-b border-border bg-secondary flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:ek.creatingItem.parentPath?y("fileBrowser.createFileIn",{path:ek.creatingItem.parentPath}):y("fileBrowser.createFile")}),(0,n.jsx)("input",{type:"text",autoFocus:!0,placeholder:y("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:()=>{$.current=!0},onCompositionEnd:()=>{$.current=!1},onKeyDown:async e=>{if("Enter"===e.key){if($.current)return;let r=e.target.value.trim();if(!r)return;let n=ek.creatingItem.parentPath,s=n?`${n}/${r}`:r,o=await i.t4.runPromiseExit((0,x.OJ)({cwd:t,path:s,content:""}));if("Success"===o._tag&&o.value.ok)(0,k.oR)(y("toast.createdFile",{name:r}),"success"),ek.setCreatingItem(null),ek.loadDirectory(n),ek.loadFileIndex(),n&&ek.setExpandedPaths(e=>new Set([...e,n])),eI(s);else if("Success"===o._tag){let e=o.value.data?.error;(0,k.oR)(e||y("toast.createFailed"),"error")}else(0,k.oR)(y("toast.createFailed"),"error")}else"Escape"===e.key&&ek.setCreatingItem(null)},onBlur:()=>ek.setCreatingItem(null)})]}),ek.isLoadingFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("common.loading")}):ek.fileError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:ek.fileError}):(0,n.jsx)(eo,{files:ek.files,selectedPath:ek.selectedPath,expandedPaths:ek.effectiveExpandedPaths,matchedPaths:ek.matchedPaths,gitStatusMap:eU,loadingDirs:ek.loadingDirs,onSelect:e=>{ek.setShouldScrollToSelected(!1),eI(e)},onToggle:ek.handleToggle,cwd:t,shouldScrollToSelected:ek.shouldScrollToSelected,onScrolledToSelected:()=>ek.setShouldScrollToSelected(!1),onCreateFile:e=>ek.setCreatingItem({type:"file",parentPath:e}),onDelete:(e,t,r)=>F({path:e,isDirectory:t,name:r}),onRefresh:()=>ek.loadFiles(),onCopyFile:eY,onPaste:eZ})]}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"search"===C?"":"hidden"}`,children:eN.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"})}):eN.searchError?(0,n.jsx)("div",{className:"p-4 text-center text-red-11 text-sm",children:eN.searchError}):0===eN.contentSearchResults.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:eN.contentSearchQuery?y("fileBrowser.noContentSearchResults"):y("fileBrowser.enterKeywordToSearch")}):(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto flex flex-col min-h-0",children:[eN.searchStats&&(0,n.jsxs)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-secondary border-b border-border flex-shrink-0",children:[y("fileBrowser.nFilesNMatches",{files:eN.searchStats.totalFiles,matches:eN.searchStats.totalMatches}),eN.searchStats.truncated&&(0,n.jsxs)("span",{className:"text-amber-11 ml-1",children:["(",y("fileBrowser.resultsTruncated"),")"]})]}),(0,n.jsx)(eo,{files:eD.files,selectedPath:ek.selectedPath,expandedPaths:eA,onSelect:e=>{let t=eD.matchMap.get(e);eI(e,t?.matches[0]?.lineNumber),Y||G(!0)},onToggle:eW,cwd:t,renderActions:ez,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"===C?"":"hidden"}`,children:0===ek.recentFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("fileBrowser.noRecentFiles")}):(0,n.jsx)(eo,{files:ek.recentFilesTree,selectedPath:ek.selectedPath,expandedPaths:ek.recentTreeDirPaths,onSelect:eI,onToggle:ea.tE,cwd:t})}),(0,n.jsx)("div",{className:`flex-1 flex flex-col min-h-0 ${"status"===C?"":"hidden"}`,children:eC.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"})}):eC.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:eC.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:y("fileBrowser.stagingArea",{count:eC.status?.staged.length||0})}),(0,n.jsx)("button",{onClick:()=>eC.fetchStatus(),className:"p-0.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:y("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"})})})]}),(eC.status?.staged.length||0)>0&&(0,n.jsx)("button",{onClick:eC.handleUnstageAll,className:"text-sm text-amber-11 hover:text-amber-10 hover:underline",children:y("fileBrowser.unstageAll")})]}),(0,n.jsx)(D,{files:eC.stagedTree,selectedPath:eC.statusSelectedFile?.type==="staged"?eC.statusSelectedFile.file.path:null,expandedPaths:eC.stagedExpandedPaths,onSelect:e=>e.file&&eC.handleStatusFileSelect(e.file,"staged"),onToggle:eC.handleStagedToggle,cwd:t,emptyMessage:y("fileBrowser.noStagedFiles"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=W(e);return 0===t.length?null:(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),eC.handleUnstageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:y("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(),eC.handleUnstage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 dark:hover:bg-amber-9/20 rounded transition-all",title:y("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.jsx)("span",{className:"text-sm font-medium text-muted-foreground",children:y("fileBrowser.workspace",{count:eC.status?.unstaged.length||0})}),(eC.status?.unstaged.length||0)>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:eC.handleDiscardAll,className:"text-sm text-red-11 hover:text-red-10 hover:underline",children:y("fileBrowser.discardAll")}),(0,n.jsx)("button",{onClick:eC.handleStageAll,className:"text-sm text-green-11 hover:text-green-10 hover:underline",children:y("fileBrowser.stageAll")})]})]}),(0,n.jsx)(D,{files:eC.unstagedTree,selectedPath:eC.statusSelectedFile?.type==="unstaged"?eC.statusSelectedFile.file.path:null,expandedPaths:eC.unstagedExpandedPaths,onSelect:e=>e.file&&eC.handleStatusFileSelect(e.file,"unstaged"),onToggle:eC.handleUnstagedToggle,cwd:t,emptyMessage:y("fileBrowser.noUnstagedChanges"),className:"py-1",renderActions:e=>{if(e.isDirectory){let t=W(e);if(0===t.length)return null;let r=t.map(e=>e.file).filter(Boolean);return(0,n.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),eC.handleDiscardFiles(r)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:y("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(),eC.handleStageFiles(t.map(e=>e.path))},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:y("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:"flex items-center gap-0.5",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),eC.handleDiscardFile(e.file)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-red-11 hover:text-red-10 hover:bg-red-9/10 dark:hover:bg-red-9/20 rounded transition-all",title:y("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(),eC.handleStage(e.path)},className:"opacity-0 group-hover:opacity-100 p-0.5 text-green-11 hover:text-green-10 hover:bg-green-9/10 dark:hover:bg-green-9/20 rounded transition-all",title:y("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"===C?"":"hidden"}`,children:eE.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-slate-7 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:eE.historyError})]})}):eE.compareMode?(0,n.jsx)("div",{className:"flex-1 overflow-y-auto overflow-x-hidden",children:eE.isLoadingCompareFiles?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("fileBrowser.loadingDiff")}):0===eE.compareFiles.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("fileBrowser.noDiffFiles")}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border",children:(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:y("fileBrowser.nFilesChanged",{count:eE.compareFiles.length,branch:eE.compareBaseBranch})})}),(0,n.jsx)(D,{files:eE.compareFileTree,expandedPaths:eE.compareExpandedPaths,onToggle:eE.handleCompareToggle,selectedPath:eE.compareSelectedFile?.path||null,onSelect:e=>{e.file&&eE.handleSelectCompareFile(e.file)},cwd:t,showChanges:!0})]})}):(0,n.jsx)("div",{ref:eE.commitListRef,className:"flex-1 overflow-y-auto",onScroll:eE.handleCommitListScroll,children:eE.isLoadingCommits?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("fileBrowser.loadingCommits")}):0===eE.commits.length?(0,n.jsx)("div",{className:"p-4 text-center text-muted-foreground text-sm",children:y("fileBrowser.noCommits")}):(0,n.jsxs)(n.Fragment,{children:[eE.commits.map(e=>(0,n.jsxs)("div",{onClick:()=>eE.handleSelectCommit(e),className:`px-3 py-2 border-b border-border cursor-pointer hover:bg-accent ${eE.selectedCommit?.hash===e.hash?"bg-brand/10":""}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-mono text-xs text-brand",children:e.shortHash}),(0,n.jsxs)("span",{className:"text-xs text-slate-9",title:e.date,children:[e.relativeDate," \xb7 ",(0,ea.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)),eE.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"})}),!eE.hasMoreCommits&&eE.commits.length>0&&(0,n.jsx)("div",{className:"p-3 text-center text-xs text-slate-9",children:y("fileBrowser.allLoaded",{count:eE.commits.length})})]})})})]})]}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[("tree"===C||"search"===C||"recent"===C)&&(ek.blameSelectedCommit?(0,n.jsx)(er,{isOpen:!0,onClose:()=>ek.setBlameSelectedCommit(null),commit:ek.blameSelectedCommit,cwd:t,embedded:!0,initialFilePath:ek.selectedPath||void 0,onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)}}):"map"===L?(0,n.jsx)(e3,{cwd:t,highlightedFilePath:ek.selectedPath,changedFiles:eS,onSwitchToCode:()=>E("code"),enableComments:!0,onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)},headerExtraLeft:({focalFile:e})=>e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(`${t}/${e}`),(0,k.oR)(y("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:y("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(),e8(e)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:y("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"})]})})]})}):ek.selectedPath?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-4 py-2 bg-secondary 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:ek.selectedPath}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(`${t}/${ek.selectedPath}`),(0,k.oR)(y("common.copiedPath"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:y("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(),e8(ek.selectedPath)},className:"p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors flex-shrink-0",title:y("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:ek.showEditor?(0,n.jsxs)(n.Fragment,{children:[Q.isDirty&&(0,n.jsx)("span",{className:"text-xs text-amber-11",children:y("fileBrowser.unsaved")}),(0,n.jsx)("button",{onClick:()=>J.current?.save(),disabled:!Q.isDirty||Q.isSaving,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${Q.isDirty&&!Q.isSaving?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:Q.isSaving?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border-2 border-current border-t-transparent rounded-full animate-spin"}):y("common.save")}),(0,n.jsx)("button",{onClick:()=>J.current?.close(),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:y("fileBrowser.closeEdit"),children:y("fileBrowser.closeBtn")})]}):(0,n.jsxs)(n.Fragment,{children:[ek.fileContent?.type==="text"&&ek.fileContent.content&&(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(ek.fileContent.content),(0,k.oR)(y("toast.copiedFileContent"))},className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:y("fileBrowser.copyFileContent"),children:y("common.copy")}),ek.selectedPath?.endsWith(".json")&&ek.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>es(e=>!e),className:`px-1.5 py-0.5 text-xs rounded transition-colors ${en?"bg-brand text-white":"text-muted-foreground hover:bg-accent"}`,title:y("fileBrowser.toggleJsonReadable"),children:y("common.readable")}),ek.fileContent?.type==="text"&&Z(ek.selectedPath)&&(0,n.jsx)("button",{onClick:()=>ek.setShowMarkdownPreview(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:y("fileBrowser.previewMarkdown"),children:y("common.preview")}),ek.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:ek.handleToggleBlame,disabled:ek.isLoadingBlame,className:`px-1.5 py-0.5 text-xs rounded transition-colors ${ek.showBlame?"bg-brand text-white":"text-muted-foreground hover:bg-accent"} disabled:opacity-50`,title:y("fileBrowser.viewBlame"),children:ek.isLoadingBlame?(0,n.jsx)("span",{className:"inline-block w-3 h-3 border border-current border-t-transparent rounded-full animate-spin"}):"Blame"}),ek.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>E("map"),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:y("blockViewer.viewerToggle.toBlock"),children:y("common.codeMap")}),ek.fileContent?.type==="text"&&(0,n.jsx)("button",{onClick:()=>ek.setShowEditor(!0),className:"px-1.5 py-0.5 text-xs rounded transition-colors text-muted-foreground hover:bg-accent",title:y("fileBrowser.editFile"),children:y("common.edit")})]})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:ek.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"})}):ek.fileContent?"text"===ek.fileContent.type&&"string"==typeof ek.fileContent.content?ek.showBlame&&ek.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:ek.blameError}),(0,n.jsx)("button",{onClick:()=>ek.setShowBlame(!1),className:"mt-2 text-brand hover:underline text-sm",children:y("fileBrowser.backToPreview")})]})}):ek.showBlame&&0===ek.blameLines.length&&ek.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"})}):en&&ek.selectedPath?.endsWith(".json")?(0,n.jsxs)("div",{className:"h-full flex flex-col bg-[#0d1117]",children:[(0,n.jsx)(et,{search:eu}),(0,n.jsx)("div",{className:"flex-1 overflow-auto px-6 py-4",children:(0,n.jsx)("pre",{ref:ed,className:"whitespace-pre-wrap break-words font-mono",style:{fontSize:"0.8125rem",lineHeight:"1.5"},children:H(ek.fileContent.content)})})]}):(0,n.jsx)(el.Cv,{ref:J,content:ek.fileContent.content,filePath:ek.selectedPath,cwd:t,enableComments:!0,scrollToLine:K??ek.targetLineNumber,scrollToLineAlign:null!=K?"start":ek.targetScrollAlign,onScrollToLineComplete:()=>{U(null),ek.setTargetLineNumber(null)},highlightKeyword:"search"===C?eN.contentSearchQuery:null,visibleLineRef:q,viStateRef:V,initialCursorLine:ek.initialCursorLine,initialCursorCol:ek.initialCursorCol,onInitialCursorSet:()=>{ek.setInitialCursorLine(null),ek.setInitialCursorCol(null)},onCmdClick:eO?eq:void 0,onTokenHover:eO?eV:void 0,onTokenHoverLeave:eO?ev.onTokenMouseLeave:void 0,onTokenHoverCancel:eO?ev.clearHover:void 0,blameLines:ek.showBlame&&ek.blameLines.length>0?ek.blameLines:void 0,inlineBlameLines:ek.blameLines.length>0?ek.blameLines:void 0,onSelectCommit:ek.setBlameSelectedCommit,editable:ek.showEditor,initialMtime:ek.fileContent.mtime,onEditorClose:e=>{ek.setShowEditor(!1),U(e)},onSaved:()=>{let e=q.current??1;ek.loadFileContent(ek.selectedPath),ek.setShowEditor(!1),U(e)},onEditorStateChange:X,viMode:!0,onContentMutate:eP,onEnterInsertMode:eR,onViSave:eB,onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)}}):"image"===ek.fileContent.type&&ek.selectedPath?(0,n.jsx)(tp,{cwd:t,path:ek.selectedPath,refreshKey:ek.fileContent.mtime,alt:ek.selectedPath}):(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-slate-7 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:ek.fileContent.message||y("fileBrowser.cannotPreview")})]})}):(0,n.jsx)("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:y("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-slate-7 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:y("fileBrowser.selectFileToPreview")})]})})),"status"===C&&(eC.statusSelectedFile&&eC.statusDiff?(0,n.jsx)(tg,{cwd:t,selected:eC.statusSelectedFile,diff:eC.statusDiff,showMarkdownPreview:eC.showStatusDiffPreview,setShowMarkdownPreview:eC.setShowStatusDiffPreview,changedFiles:eS,fileGitStatusMap:eL,onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)},locateInTree:e8,jsonPreview:ei,setJsonPreview:ec,jsonPreviewSearch:eh,jsonPreviewPreRef:em}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:y("fileBrowser.selectFileToViewDiff")})})),"history"===C&&!eE.historyError&&(eE.compareMode?eE.isLoadingCompareDiff?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:y("fileBrowser.loadingDiffContent")}):eE.compareFileDiff?(0,n.jsx)(T,{oldContent:eE.compareFileDiff.oldContent,newContent:eE.compareFileDiff.newContent,filePath:eE.compareFileDiff.filePath,isNew:eE.compareFileDiff.isNew,isDeleted:eE.compareFileDiff.isDeleted,cwd:t,enableComments:!0,onPreview:!eE.compareFileDiff.isDeleted&&eE.compareFileDiff.filePath.endsWith(".json")?()=>ec({content:eE.compareFileDiff.newContent,filePath:eE.compareFileDiff.filePath}):void 0,previewLabel:y("common.readable"),onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:eE.compareFiles.length>0?y("fileBrowser.selectFileToViewDiff"):y("fileBrowser.clickCompareToLoad")})}):eE.selectedCommit?(0,n.jsx)(er,{isOpen:!0,onClose:()=>eE.setSelectedCommit(null),commit:eE.selectedCommit,cwd:t,embedded:!0,onContentSearch:e=>{S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)}}):(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-slate-9",children:(0,n.jsx)("span",{children:y("fileBrowser.selectCommitToView")})}))]})]}),ek.showMarkdownPreview&&ek.fileContent?.type==="text"&&ek.selectedPath&&(0,n.jsx)("div",{className:"absolute inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>ek.setShowMarkdownPreview(!1),children:(0,n.jsx)("div",{className:"bg-card rounded-lg shadow-xl w-full max-w-[90%] h-full flex flex-col",onClick:e=>e.stopPropagation(),children:(0,n.jsx)(ex,{content:ek.fileContent.content||"",filePath:ek.selectedPath,cwd:t,onClose:()=>ek.setShowMarkdownPreview(!1)})})}),I&&(0,n.jsx)(ef,{files:ek.files,fileIndex:ek.fileIndex,recentFiles:ek.recentFilePaths,onSelectFile:e=>{eI(e),ek.setShouldScrollToSelected(!0),S("tree")},onClose:()=>O(!1)}),(eH||ej.visible)&&(0,n.jsxs)("div",{className:`flex ${ej.visible&&eH?"":"flex-col"}`,children:[eH&&(0,n.jsx)("div",{className:ej.visible?"flex-1 min-w-0 border-r border-border":"",children:(0,n.jsx)(tN,{results:eN.contentSearchResults,loading:eN.isSearching,totalMatches:eN.searchStats?.totalMatches??0,onSelect:(e,t)=>{ek.selectedPath&&ew.push({filePath:ek.selectedPath,lineNumber:q.current}),eI(e,t)},onClose:()=>G(!1)})}),ej.visible&&(0,n.jsx)("div",{className:eH?"flex-1 min-w-0":"",children:(0,n.jsx)(tk,{references:ej.references,loading:ej.loading,onSelect:eK,onClose:ej.closeReferences})})]})]}),B&&(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{className:"fixed inset-0 z-[300] flex items-center justify-center bg-black/50",onClick:()=>F(null),children:(0,n.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-xl 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:y("fileBrowser.confirmDelete")}),(0,n.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:y("fileBrowser.confirmDeleteMessage",{name:B.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:()=>F(null),className:"px-3 py-1.5 text-sm rounded border border-border hover:bg-accent transition-colors",children:y("common.cancel")}),(0,n.jsx)("button",{onClick:async()=>{let{path:e,name:r}=B;F(null);let n=await i.t4.runPromiseExit((0,x.VK)({cwd:t,path:e}));if("Success"===n._tag){(0,k.oR)(y("toast.movedToTrash",{name:r}),"success");let t=e.includes("/")?e.substring(0,e.lastIndexOf("/")):"";ek.loadDirectory(t),ek.loadFileIndex(),ek.selectedPath===e&&eI("")}else{let e="Fail"===n.cause._tag?n.cause.error:null,t=e?.cause,r=t instanceof Error?t.message:y("toast.deleteFailed");(0,k.oR)(r,"error")}},className:"px-3 py-1.5 text-sm rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 transition-colors",children:y("common.delete")})]})]})})}),ev.hoverInfo&&P&&(0,u.createPortal)((0,n.jsx)(ty,{ref:ev.setTooltipEl,displayString:ev.hoverInfo.displayString,documentation:ev.hoverInfo.documentation,x:ev.hoverInfo.x,y:ev.hoverInfo.y,container:P,onMouseEnter:ev.onCardMouseEnter,onMouseLeave:ev.onCardMouseLeave,onFindReferences:()=>{let{filePath:e,line:t,column:r}=ev.hoverInfo;ev.clearHover(),ej.findReferences(e,t,r)},onSearch:e=>{ev.clearHover(),S("search"),eN.setContentSearchQuery(e),eN.performContentSearch(e)}}),P)]})}function tL({isOpen:e,onClose:t,cwd:r}){let c,{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)([]),[x,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(null),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),[y,N]=(0,s.useState)(null),[C,S]=(0,s.useState)(!1),[L,E]=(0,s.useState)(""),[M,T]=(0,s.useState)(!1),[$,P]=(0,s.useState)([]),[R,B]=(0,s.useState)(""),[F,I]=(0,s.useState)(!1),D=(0,s.useCallback)((e,t)=>e?._tag==="Fail"&&e.error?.cause instanceof Error?e.error.cause.message:d(t),[d]),A=(0,s.useCallback)(async()=>{v(!0);let e=await i.t4.runPromiseExit((0,h.FK)(r));if("Success"===e._tag){let t=e.value;m(t.worktrees),f(t.nextPath),g(t.nextRandomWord),t.gitUserName&&E(t.gitUserName)}else console.error("Failed to load worktrees:",e.cause),(0,k.oR)(d("toast.worktreeLoadFailed"),"error");v(!1)},[r,d]),_=(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&&(A(),N(null))},[e,A]);let W=async()=>{if(!x)return;let e="origin/main",t=await i.t4.runPromiseExit((0,h.r4)(r));"Success"===t._tag&&(e=_(t.value));let n=p||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=L?`${L}/${n}`:n;w(!0);let o=await i.t4.runPromiseExit((0,h.CM)({action:"add",cwd:r,path:x,newBranch:s,baseBranch:e}));"Success"===o._tag?((0,k.oR)(d("toast.worktreeCreateSuccess",{name:s}),"success"),A()):(console.error("Failed to create worktree:",o.cause),(0,k.oR)(D(o.cause,"toast.worktreeCreateFailed"),"error")),w(!1)},z=async()=>{I(!0),B(""),T(!0);let e=await i.t4.runPromiseExit((0,h.r4)(r));if("Success"===e._tag){let t=e.value,r=t.local??[],n=t.remote??[],s=new Set(u.map(e=>e.branch).filter(Boolean));P([...r.filter(e=>!s.has(e)),...n.filter(e=>!s.has(e)&&!r.includes(e.replace(/^origin\//,"")))])}else(0,k.oR)(d("toast.loadBranchFailed"),"error");I(!1)},H=async e=>{if(!x)return;T(!1),w(!0);let t=await i.t4.runPromiseExit((0,h.CM)({action:"add",cwd:r,path:x,branch:e}));"Success"===t._tag?((0,k.oR)(d("toast.worktreeCreateSuccess",{name:e}),"success"),A()):(console.error("Failed to create worktree:",t.cause),(0,k.oR)(D(t.cause,"toast.worktreeCreateFailed"),"error")),w(!1)},O=async()=>{if(!y)return;S(!0);let e=await i.t4.runPromiseExit((0,h.CM)({action:"remove",cwd:r,path:y.path}));"Success"===e._tag?((0,k.oR)(d("toast.worktreeDeleted"),"success"),N(null),A()):(console.error("Failed to delete worktree:",e.cause),(0,k.oR)(D(e.cause,"toast.worktreeDeleteFailed"),"error")),S(!1)},q=async e=>{let t=e.isLocked?"unlock":"lock",n=await i.t4.runPromiseExit((0,h.CM)({action:t,cwd:r,path:e.path}));"Success"===n._tag?((0,k.oR)(e.isLocked?d("toast.worktreeUnlocked"):d("toast.worktreeLocked"),"success"),A()):(console.error("Failed to toggle lock:",n.cause),(0,k.oR)(D(n.cause,"toast.operationFailed"),"error"))};return e?(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl 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-accent rounded transition-colors",title:d("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:b?(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:u.map(e=>{let s=e.path===r;return(0,n.jsxs)("div",{className:`group p-3 rounded-lg border transition-colors ${s?"border-brand bg-brand/5":"border-border hover:bg-accent cursor-pointer"}`,onClick:()=>{e.path!==r&&((0,l.F)(a.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 ${s?"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:d("git.worktree.locked"),children:"\uD83D\uDD12"}),s&&(0,n.jsxs)("span",{className:"text-xs text-brand",children:["(",d("common.current"),")"]})]}),(0,n.jsx)("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:!s&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),q(e)},className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-secondary rounded transition-colors",title:e.isLocked?d("git.worktree.unlock"):d("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(),N(e)},className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-secondary rounded transition-colors",title:d("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.jsx)("div",{className:"mt-1 text-xs text-muted-foreground truncate pl-4",children:e.path}),e.isDetached&&(0,n.jsx)("div",{className:"mt-1 text-xs text-amber-11 pl-4",children:"(detached HEAD)"})]},e.path)})})}),M&&(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:R,onChange:e=>B(e.target.value),placeholder:d("git.worktree.searchBranch"),className:"flex-1 bg-secondary text-sm text-foreground rounded px-2.5 py-1.5 outline-none placeholder:text-muted-foreground",autoFocus:!0,autoComplete:"off",spellCheck:"false"}),(0,n.jsx)("button",{onClick:()=>T(!1),className:"text-xs text-muted-foreground hover:text-foreground px-2 py-1.5",children:d("common.cancel")})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto space-y-0.5",children:F?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:d("common.loading")}):0===(c=$.filter(e=>e.toLowerCase().includes(R.toLowerCase()))).length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:d("git.worktree.noBranches")}):c.map(e=>(0,n.jsx)("button",{onClick:()=>H(e),className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent 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:d("git.worktree.count",{count:u.length})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:z,disabled:!x||j,className:`px-3 py-1.5 text-sm rounded transition-colors ${x&&!j?"bg-secondary text-foreground hover:bg-accent":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:d("git.worktree.selectBranch")}),(0,n.jsx)("button",{onClick:W,disabled:!x||j,className:`px-3 py-1.5 text-sm rounded transition-colors ${x&&!j?"bg-brand text-white hover:bg-brand/90":"bg-secondary text-muted-foreground cursor-not-allowed"}`,children:j?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):d("git.worktree.addWorktree")})]})]}),y&&(0,n.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-black/50 rounded-lg",onClick:()=>N(null),children:(0,n.jsxs)("div",{className:"bg-card rounded-lg shadow-xl w-[360px] p-4",onClick:e=>e.stopPropagation(),children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground mb-3",children:d("git.worktree.confirmDelete")}),(0,n.jsxs)("div",{className:"text-sm text-muted-foreground mb-4",children:[(0,n.jsx)("p",{className:"mb-2",children:d("git.worktree.confirmDeleteMsg")}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:d("git.worktree.path")}),(0,n.jsx)("span",{className:"text-foreground",children:y.path})]}),(0,n.jsxs)("p",{className:"text-xs",children:[(0,n.jsx)("span",{className:"text-muted-foreground",children:d("git.worktree.branch")}),(0,n.jsx)("span",{className:"text-foreground",children:y.branch||"detached"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>N(null),className:"px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors",children:d("common.cancel")}),(0,n.jsx)("button",{onClick:O,disabled:C,className:"px-3 py-1.5 text-sm bg-red-9 text-white rounded hover:bg-red-10 transition-colors disabled:opacity-50",children:C?(0,n.jsx)("span",{className:"inline-block w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin"}):d("common.delete")})]})]})})]})}):null}var tE=r(67635),tM=r(73300),tT=r(20986),t$=r(9921),tP=r(66088),tR=r(42790);function tB(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}let tF=(0,s.memo)(function({shortId:e,type:t,onRegister:r,onUnregister:l}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)(!1),d=(0,s.useCallback)(async n=>{if(n.stopPropagation(),i)await l(),c(!1),(0,k.oR)(a("toast.disconnected",{id:e}));else{await r(),c(!0);let n=`${"3456"===window.location.port?"cockpit-dev":"cockpit"} ${t} ${e}`;navigator.clipboard.writeText(n),(0,k.oR)(a("toast.copiedCommand",{command:n}))}},[i,e,t,r,l,a]);return(0,n.jsxs)("button",{onClick:d,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:i?a("shortIdBadge.clickToDisconnect"):a("shortIdBadge.clickToRegister"),children:[(0,n.jsx)("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${i?"bg-green-500":"bg-muted-foreground/40"}`}),e]})});var tI=r(12786);let tD=e=>eM.tryPromise({try:async()=>{let t=await fetch(e);if(!t.ok)throw Error(`HTTP ${t.status}`);return await t.json()},catch:t=>new eT.uV({message:`fetch ${e} failed`,cause:t})}),tA=(e,t)=>eM.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok)throw Error(`HTTP ${r.status}`)},catch:r=>new eT.uV({message:`${t.method} ${e} failed`,cause:r})}),t_=(e,t)=>tA(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),tW=(e,t)=>eM.gen(function*(){let r=new URLSearchParams({cwd:e});return t&&r.set("tabId",t),(yield*tD(`/api/terminal/env?${r}`)).env||{}}),tz=()=>tD("/api/terminal/aliases").pipe(eM.map(e=>e.aliases||{})),tH=(e,t,r)=>t_("/api/terminal/bubble-order",{cwd:e,tabId:t,order:r}),tO=(e,t,r)=>t_("/api/terminal/history",{cwd:e,tabId:t,entry:r}),tq=(e,t,r)=>tA(`/api/terminal/history?cwd=${encodeURIComponent(e)}&tabId=${encodeURIComponent(t)}&commandId=${encodeURIComponent(r)}`,{method:"DELETE"}),tV=e=>tD(`/api/services/config?cwd=${encodeURIComponent(e)}`),tK=(0,s.lazy)(()=>Promise.all([r.e(3888),r.e(1959)]).then(r.bind(r,71959)).then(e=>({default:e.XtermRenderer}))),tU={c:"\x03",d:"\x04",z:"\x1a",l:"\f",a:"\x01",e:"\x05",u:"\x15",w:"\x17"},tJ=/\x1b\[[0-9;]*m/g;function tQ({output:e,query:t,mode:r,currentIdx:o,matchListRef:l}){let a=(0,s.useRef)(null);a.current||(a.current=new tR.v,a.current.use_classes=!0);let i=e.split("\n"),c=t.toLowerCase(),d=0;return l.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(tJ,""),i=s.toLowerCase().includes(c);if("filter"===r&&!i)return null;if(!i){let r=a.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(c,h);if(-1===e)break;e>m&&u.push((0,n.jsx)("span",{children:s.slice(m,e)},`t${m}`));let t=d++,r=t===o;u.push((0,n.jsx)("mark",{ref:e=>{l.current[t]=e},className:r?"bg-brand/40 text-foreground":"bg-yellow-300/40 text-foreground",children:s.slice(e,e+c.length)},`m${e}`)),h=m=e+c.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 tX=(0,s.memo)(function({commandId:e,tabId:t,projectCwd:r,command:l,output:a,exitCode:c,isRunning:d,selected:u,onSelect:m,onInterrupt:x,onStdin:h,onDelete:f,onRerun:p,timestamp:g,usePty:b,subscribePtyOutput:v,subscribePtyReset:j,onPtyResize:w,onToggleMaximize:y,maximized:N,expandedHeight:C,bubbleContentHeight:S,onTitleMouseDown:L}){let{t:E}=(0,o.Bd)(),M=(0,s.useRef)(null),T=(0,s.useRef)(null),$=(0,s.useRef)(!0),P=(0,s.useRef)(null),R=(0,s.useRef)(null),B=(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),F=e&&t?tB(t+e):void 0,[I,D]=(0,s.useState)(!1),[A,_]=(0,s.useState)(""),W=(0,s.useRef)(null),z=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!v||!e)return;let t=()=>W.current?v(e,W.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=()=>W.current?j(e,W.current.reset):null,r=t();if(r)return r;let n=setInterval(()=>{(r=t())&&clearInterval(n)},50);return()=>{clearInterval(n),r?.()}},[j,e]);let[H,O]=(0,s.useState)(!1),[q,V]=(0,s.useState)(""),[K,U]=(0,s.useState)("search"),[J,Q]=(0,s.useState)(0),X=(0,s.useRef)([]),Y=(0,s.useRef)(null),Z=(0,s.useRef)(0);(0,s.useEffect)(()=>{Y.current||(Y.current=new tR.v,Y.current.use_classes=!0)},[]),(0,s.useLayoutEffect)(()=>{let e=T.current;if(e&&Y.current){if(a.length<Z.current&&(Y.current=new tR.v,Y.current.use_classes=!0,Z.current=0,e.innerHTML=""),a.length>Z.current){let t=a.slice(Z.current),r=Y.current.ansi_to_html(t);Z.current=a.length,e.insertAdjacentHTML("beforeend",r)}if(M.current){let e=M.current.scrollHeight>M.current.clientHeight;D(e),e&&(M.current.scrollTop=M.current.scrollHeight)}}},[a]),(0,s.useEffect)(()=>(d&&$.current&&M.current&&(null!==P.current&&cancelAnimationFrame(P.current),P.current=requestAnimationFrame(()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight),P.current=null})),()=>{null!==P.current&&cancelAnimationFrame(P.current)}),[a,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 G=a?a.split("\n").length:0,ee=(0,s.useCallback)(()=>{O(!0),requestAnimationFrame(()=>z.current?.focus())},[]),et=(0,s.useCallback)(()=>{O(!1),V(""),Q(0),W.current?.clearSearch()},[]),er=(0,s.useCallback)(e=>{e.trim()&&(b?W.current?.findNext(e):Q(e=>{let t=e+1,r=X.current[t];return r?(r.scrollIntoView({block:"nearest"}),t):(X.current[0]?.scrollIntoView({block:"nearest"}),0)}))},[b]),en=(0,s.useCallback)(e=>{e.trim()&&(b?W.current?.findPrevious(e):Q(e=>{let t=e-1;if(t>=0)return X.current[t]?.scrollIntoView({block:"nearest"}),t;let r=X.current.length-1;return r>=0&&X.current[r]?.scrollIntoView({block:"nearest"}),Math.max(r,0)}))},[b]);(0,s.useEffect)(()=>{if(!u)return;let e=e=>{if((e.metaKey||e.ctrlKey)&&"f"===e.key){e.preventDefault(),e.stopPropagation(),ee();return}if("Escape"===e.key&&H){e.preventDefault(),e.stopPropagation(),et();return}};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[u,H,ee,et]);let es=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-accent 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?"":u?"border-brand":"border-brand/30"}`,onClick:m,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:l}),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&&x&&(0,n.jsx)("button",{onClick:x,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-md 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-accent transition-colors",title:E("console.restoreTooltip",{modKey:(0,tI.Mu)()}),children:(0,n.jsx)(ev.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 ${u?"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:">_"}),F&&e&&t&&(0,n.jsx)(tF,{shortId:F,type:"terminal",onRegister:()=>{i.t4.runFork(t_("/api/terminal/register",{tabId:t,commandId:e,command:l,projectCwd:r}).pipe(eM.orElse(()=>eM.void)))},onUnregister:()=>{i.t4.runFork(t_("/api/terminal/unregister",{commandId:e}).pipe(eM.orElse(()=>eM.void)))}}),(0,n.jsx)("span",{className:"font-mono text-foreground truncate",children:l}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(l),(0,k.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)(tE.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("span",{className:"flex-1"}),I&&!d&&(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:E("console.totalLines",{count:G})}),a&&(0,n.jsx)("button",{onClick:e=>{let t;e.stopPropagation(),t=a.replace(/\x1b\[[0-9;]*m/g,""),navigator.clipboard.writeText(t),(0,k.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)(tM.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)(tT.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)(ev.A,{className:"w-3.5 h-3.5"})})]}),H&&(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)(eb.A,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"}),(0,n.jsx)("input",{ref:z,value:q,onChange:e=>{let t=e.target.value;V(t),Q(0),b&&(t.trim()?W.current?.findNext(t):W.current?.clearSearch())},onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?en(q):er(q))},placeholder:E("console.searchPlaceholder"),className:"flex-1 bg-transparent text-sm text-foreground outline-none placeholder:text-muted-foreground",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:()=>U("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:()=>U("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:()=>en(q),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:E("console.prevShiftEnter"),children:(0,n.jsx)(t$.A,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>er(q),className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",title:E("console.nextEnter"),children:(0,n.jsx)(tP.A,{className:"w-3.5 h-3.5"})})]}),(0,n.jsx)("button",{onClick:et,className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors",children:(0,n.jsx)(ev.A,{className:"w-3.5 h-3.5"})})]}),b?(0,n.jsxs)("div",{className:"relative group",style:{height:es,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:es},children:E("console.loadingTerminal")}),children:(0,n.jsx)(tK,{ref:W,output:a,isRunning:d,onInput:h,onResize:w,maximized:N,height:es,directWrite:!!v})}),!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()},title:E("console.rerun"),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)(tT.A,{className:"w-3.5 h-3.5"}),E("console.rerun")]})})]}):(0,n.jsx)("div",{ref:M,className:"overflow-auto px-4 py-2",style:{height:es},onScroll:()=>{if(M.current){let{scrollTop:e,scrollHeight:t,clientHeight:r}=M.current;$.current=t-e-r<50}},children:H&&q.trim()?(0,n.jsx)(tQ,{output:a,query:q,mode:K,currentIdx:J,matchListRef:X}):(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:R,value:A,onChange:e=>_(e.target.value),onKeyDown:e=>{if(e.ctrlKey&&!e.metaKey&&!e.altKey){let t=tU[e.key.toLowerCase()];if(t){e.preventDefault(),e.stopPropagation(),h(t);return}}"Enter"!==e.key||e.nativeEvent.isComposing||(e.preventDefault(),h(A+"\n"),_("")),"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 placeholder:text-muted-foreground",autoComplete:"off",spellCheck:"false"}):(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:E("console.runningText")}),x&&(0,n.jsx)("button",{onClick:x,className:"flex-shrink-0 text-xs text-destructive hover:brightness-125 transition-colors cursor-pointer select-none",children:"Ctrl+C"}),B&&(0,n.jsx)("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:B})]}),!d&&void 0!==c&&!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===c?"bg-green-500":"bg-red-500"}`}),(0,n.jsx)("span",{children:E("console.exitCode",{code:c})}),(0,n.jsx)("span",{className:"flex-1"}),B&&(0,n.jsx)("span",{className:"text-[11px] flex-shrink-0",children:B})]})]})})});var tY=r(68459),tZ=r(51914);function tG({cwd:e,tabId:t,onClose:r,onSave:l}){let{t:a}=(0,o.Bd)(),[c,d]=(0,s.useState)({}),[u,m]=(0,s.useState)(""),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!0),g=(0,s.useCallback)(async()=>{p(!0);let r=await i.t4.runPromiseExit(tW(e,t));"Success"===r._tag?d(r.value):console.error("Failed to load env:",r.cause),p(!1)},[e,t]);(0,s.useEffect)(()=>{g()},[g]);let b=()=>{u.trim()&&(d(e=>({...e,[u.trim()]:x})),m(""),h(""))},v=async()=>{let n=await i.t4.runPromiseExit(t_("/api/terminal/env",{cwd:e,tabId:t,env:c}));"Success"===n._tag?(l(c),r()):console.error("Failed to save env:",n.cause)};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl 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:a("envManager.title")}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:t?a("envManager.tabScope"):a("envManager.globalScope")})]}),(0,n.jsx)("button",{onClick:r,className:"p-1 rounded hover:bg-accent transition-colors",children:(0,n.jsx)(ev.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:a("common.loading")}):(0,n.jsxs)("div",{className:"space-y-3",children:[Object.entries(c).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:a("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)(tY.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:u,onChange:e=>m(e.target.value),placeholder:a("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:x,onChange:e=>h(e.target.value),placeholder:a("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:!u.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)(tZ.A,{className:"w-4 h-4"})})]}),0===Object.keys(c).length&&(0,n.jsx)("div",{className:"text-center py-8 text-muted-foreground text-sm",children:a("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-accent transition-colors",children:a("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:a("common.save")})]})]})})}var t0=r(10762);function t1({onClose:e,onSave:t}){let{t:r}=(0,o.Bd)(),[l,a]=(0,s.useState)({}),[c,d]=(0,s.useState)(""),[u,m]=(0,s.useState)(""),[x,h]=(0,s.useState)(!0),f=(0,s.useCallback)(async()=>{h(!0);let e=await i.t4.runPromiseExit(tz());"Success"===e._tag?a(e.value):console.error("Failed to load aliases:",e.cause),h(!1)},[]);(0,s.useEffect)(()=>{f()},[f]);let p=()=>{c.trim()&&u.trim()&&(a(e=>({...e,[c.trim()]:u.trim()})),d(""),m(""))},g=async()=>{let r=await i.t4.runPromiseExit(t_("/api/terminal/aliases",{aliases:l}));"Success"===r._tag?(t(l),e()):console.error("Failed to save aliases:",r.cause)};return(0,n.jsx)("div",{className:"absolute inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,n.jsxs)("div",{className:"bg-background border border-border rounded-lg shadow-xl 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)(t0.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-accent transition-colors",children:(0,n.jsx)(ev.A,{className:"w-5 h-5"})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:x?(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(l).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 a(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:()=>{a(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)(tY.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:c,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:u,onChange:e=>m(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:!c.trim()||!u.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)(tZ.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(l).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-accent 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 t2=r(53961),t5=r(15813),t4=r(37595),t3=r(49698),t6=r(20232);let t8=new Map;function t9(e){t8.set(e.type,e)}function t7(e){return t8.get(e)}function re(e){for(let t of t8.values())if(t.match(e))return t;return null}let rt=(e,t)=>eM.tryPromise({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 eT.uV({message:`POST ${e} failed`,cause:t})}),rr=(e,t)=>i.t4.runPromise(rt(`/api/${e}/disconnect`,{id:t}).pipe(eM.orElse(()=>eM.void))),rn=e=>i.t4.runPromise(rt("/api/browser/unregister",{id:e}).pipe(eM.orElse(()=>eM.void))),rs=e=>i.t4.runPromise(e.pipe(eM.catchAll(e=>eM.sync(()=>{if(e.cause instanceof Error)throw e.cause;throw Error(e.message)})))),ro=(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}`},rl=(e,t)=>rs(eM.tryPromise({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(ro(n,r.status));return n},catch:t=>new eT.uV({message:`POST ${e} failed`,cause:t})})),ra=(e,t)=>rs(eM.tryPromise({try:async()=>{let r=new URLSearchParams(t),n=await fetch(`${e}?${r}`),s=await n.json();if(!n.ok)throw Error(ro(s,n.status));return s},catch:t=>new eT.uV({message:`GET ${e} failed`,cause:t})})),ri=(e,t)=>rs(eM.tryPromise({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 eT.uV({message:`POST blob ${e} failed`,cause:t})}));var rc=r(53853);function rd(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.set("_cockpit","1"),t.toString()}catch{let t=e.includes("?")?"&":"?";return`${e}${t}_cockpit=1`}}function ru(e){if(!e)return e;try{let t=new URL(e);return t.searchParams.delete("_cockpit"),t.toString()}catch{return e.replace(/[?&]_cockpit=1/,"")}}async function rm(e){let t=(0,rc.f)()?.id??null;return!!t&&new Promise(r=>{try{let n=globalThis.chrome?.runtime;if(!n?.sendMessage)return void r(!1);let s=setTimeout(()=>r(!1),2e3);n.sendMessage(t,{type:"prepare-iframe",url:e},e=>{clearTimeout(s),r(e?.ok??!1)})}catch{r(!1)}})}function rx(e){try{let t=new URL(e).hostname;return"localhost"===t||"127.0.0.1"===t}catch{return!1}}function rh({url:e,id:t,selected:r,maximized:i,expandedHeight:c,bubbleContentHeight:d,onSelect:u,onClose:m,onToggleMaximize:x,onNewTab:h,timestamp:f,onTitleMouseDown:p,initialSleeping:g,onSleep:b,onWake:v}){let{t:j}=(0,o.Bd)(),[w,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(null),[S,L]=(0,s.useState)(e),[E,M]=(0,s.useState)(null),[T,$]=(0,s.useState)(g??!1),P=(0,s.useRef)(null),R=(0,s.useRef)(null),B=(0,s.useRef)(null);(0,s.useEffect)(()=>{L(e)},[e]);let F=(0,s.useRef)(!0),I=(0,s.useCallback)(()=>{T||($(!0),M(null),b?.(t))},[T,t,b]),D=(0,s.useCallback)(()=>{P.current&&(clearTimeout(P.current),P.current=null)},[]),{shortId:A,connected:_,connect:W,disconnect:z}=function(e,t,r){let n=(0,s.useMemo)(()=>tB(e),[e]),[o,i]=(0,s.useState)(!1),c=(0,s.useRef)(null),d=(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)([]);(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="cockpit:cmd-result"){let{reqId:t,ok:r,data:n,error:s}=e.data,o=c.current;o&&o.readyState===WebSocket.OPEN&&o.send(JSON.stringify({type:"browser:cmd-result",reqId:t,ok:r,data:n,error:s}));return}if(e.data?.type==="cockpit:prepare-screenshot"){let r=t.current;if(!r?.contentWindow)return;let n=new URLSearchParams(window.location.search).get("cwd")||"";window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!0}})),(0,l.F)(a.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{}r.contentWindow?.postMessage({type:"cockpit:screenshot-bounds",reqId:e.data.reqId,bounds:{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)})));return}if(e.data?.type==="cockpit:screenshot-done"){window.dispatchEvent(new CustomEvent("cockpit-screenshot-state",{detail:{active:!1}})),(0,l.F)(a.n.ScreenshotDone,{});return}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]);let f=(0,s.useCallback)(e=>{let r=t.current;if(!r?.contentWindow){let t=c.current;t&&t.readyState===WebSocket.OPEN&&t.send(JSON.stringify({type:"browser:cmd-result",reqId:e.reqId,ok:!1,error:"iframe not available (page may be sleeping)"}));return}r.contentWindow.postMessage({type:"cockpit:cmd",reqId:e.reqId,action:e.action,params:e.params},"*")},[t]);(0,s.useEffect)(()=>{if(!o)return;let r=!1;return m.current=!0,!function n(){if(r||!m.current)return;let s="https:"===window.location.protocol?"wss:":"ws:",o=new WebSocket(`${s}//${window.location.host}/ws/browser?fullId=${encodeURIComponent(e)}`);c.current=o,o.onopen=()=>{for(let e of h.current)e();if(h.current=[],d.current.length>0){for(let e of d.current)f(e);d.current=[]}},o.onmessage=e=>{let r;try{r=JSON.parse(e.data)}catch{return}if("browser:cmd"===r.type){let e=r;t.current?.contentWindow&&x.current?f(e):d.current.push(e)}},o.onclose=()=>{c.current=null,!r&&m.current&&(u.current=setTimeout(n,3e3))},o.onerror=()=>o.close()}(),()=>{r=!0,m.current=!1,u.current&&clearTimeout(u.current),c.current&&(c.current.close(),c.current=null),h.current=[]}},[o,e,t,f]),(0,s.useEffect)(()=>{if(r&&d.current.length>0){for(let e of d.current)f(e);d.current=[]}},[r,f]);let p=(0,s.useCallback)(()=>o&&c.current?.readyState===WebSocket.OPEN?Promise.resolve():new Promise(e=>{h.current.push(e),o||i(!0)}),[o]);return{shortId:n,connected:o,connect:p,disconnect:(0,s.useCallback)(()=>{i(!1)},[])}}(t,B,!!E&&!T&&!w),H=(0,s.useRef)(_);H.current=_,(0,s.useEffect)(()=>{let e=R.current;if(!e||T)return;let t=new IntersectionObserver(([e])=>{F.current=e.isIntersecting,e.isIntersecting||H.current?D():(P.current&&clearTimeout(P.current),P.current=setTimeout(I,3e5))});return t.observe(e),()=>t.disconnect()},[T,I,D]),(0,s.useEffect)(()=>{T?z():_?D():F.current||(P.current&&clearTimeout(P.current),P.current=setTimeout(I,3e5))},[_,T,z,D,I]),(0,s.useEffect)(()=>{g&&M(null)},[]);let O=(0,s.useCallback)(()=>{$(!1),v?.(t);let r=rd(e);rx(e)?M(r):rm(e).then(()=>M(r))},[e,t,v]);(0,s.useEffect)(()=>{if(!e||T){e||M(null);return}let t=rd(e);if(rx(e))return void M(t);let r=!1;return rm(e).then(()=>{r||M(t)}),()=>{r=!0}},[e,T]);let q=(0,s.useCallback)(()=>y(!1),[]);(0,s.useEffect)(()=>{let e=R.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,l=()=>{o&&t&&(t.scrollTop=s)},a=()=>{n=t.style.overflow,s=t.scrollTop,o=!0,t.style.overflow="hidden",t.addEventListener("scroll",l)},i=()=>{o=!1,t.removeEventListener("scroll",l),t.style.overflow=n};return e.addEventListener("mouseenter",a),e.addEventListener("mouseleave",i),()=>{e.removeEventListener("mouseenter",a),e.removeEventListener("mouseleave",i),t.removeEventListener("scroll",l),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=R.current?.querySelector("iframe");if(!r||e.source!==r.contentWindow)return;let n=e.data.type;"cockpit:new-tab"===n&&e.data.url?h?.(ru(e.data.url),t):("cockpit:navigate"===n||"cockpit:loaded"===n)&&e.data.url&&L(ru(e.data.url))};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[t,h]);let V=(0,s.useCallback)(()=>{y(!1),C(j("browser.pageLoadFailed"))},[]),K=(0,s.useCallback)(()=>{if(T)return void O();let e=R.current?.querySelector("iframe");if(e&&E){y(!0),C(null);let t=e.src;e.src="",setTimeout(()=>{e.src=t},0)}},[T,O,E]);(0,s.useEffect)(()=>{e&&!T&&(y(!0),C(null))},[e,T]);let U=(0,s.useCallback)(()=>{S&&window.open(S,"_blank")},[S]);(0,s.useEffect)(()=>{if(!r&&!i)return;let e=e=>{"Escape"===e.key&&i&&(e.stopPropagation(),x()),"m"===e.key&&(e.metaKey||e.ctrlKey)&&r&&(e.preventDefault(),e.stopPropagation(),x())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[i,r,x]);let J=function(e){if(!e)return"";try{let t=new URL(e);return t.port?`${t.hostname}:${t.port}`:t.hostname}catch{return e}}(S),Q=i&&c?c-41:d??360;return(0,n.jsx)("div",{className:"flex flex-col items-start",children:(0,n.jsxs)("div",{className:`w-full bg-accent text-foreground
2
2
  relative transition-colors cursor-pointer
3
3
  ${i?"rounded-none overflow-visible border-0":"border overflow-hidden rounded-2xl rounded-bl-md rounded-br-md"}
4
4
  ${i?"":r?"border-brand":"border-brand/30"}`,onClick:i?void 0:u,children:[i?(0,n.jsxs)("div",{onDoubleClick:x,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"})})}),A&&(0,n.jsx)(tF,{shortId:A,type:"browser",onRegister:()=>W(),onUnregister:async()=>{z(),await rn(A)}}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground truncate font-mono",children:S||j("browser.blankPage")}),S&&(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(S),(0,k.oR)(j("toast.copiedUrl"))},className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:j("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"}),w&&(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:K,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:j("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:U,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:j("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:x,className:"p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors flex-shrink-0",title:j("browser.exitMaximize",{modKey:(0,tI.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:()=>p?.(),onDoubleClick:e=>{e.stopPropagation(),x()},className:`flex items-center gap-2 px-4 py-1.5 border-b text-xs transition-colors cursor-grab active:cursor-grabbing
@@ -26,4 +26,4 @@ ${e.skillPath}
26
26
 
27
27
  ${s}`;break}}e(t,b.length>0?b:void 0),g(""),v([]),$.current&&($.current.style.height="auto")}},[p,b,t,e,y,f]),_=(0,s.useCallback)(e=>{g(e.name+" "),$.current?.focus()},[]),W=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing){if(I&&F.length>0){if("ArrowDown"===e.key){e.preventDefault(),E(e=>(e+1)%F.length);return}if("ArrowUp"===e.key){e.preventDefault(),E(e=>(e-1+F.length)%F.length);return}if("Enter"===e.key){e.preventDefault(),_(F[L]);return}if("Escape"===e.key){e.preventDefault(),T(!0);return}if("Tab"===e.key){e.preventDefault(),_(F[L]);return}}"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),A())}},[I,F,L,_,A]),z=(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(f("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};v(e=>[...e,s])},s.readAsDataURL(r)}}},[f]),H=(0,s.useCallback)(e=>{v(t=>t.filter(t=>t.id!==e))},[]);return(0,n.jsxs)("div",{className:"border-t border-border bg-card relative",children:[(0,n.jsx)(n5,{images:b,onRemove:H,disabled:t}),I&&F.length>0&&(0,n.jsx)("div",{ref:P,className:"absolute bottom-full left-0 right-0 mx-4 mb-2 max-h-64 overflow-y-auto bg-card border border-border rounded-lg shadow-lg",children:F.map((e,t)=>{let r=t>0?F[t-1]:null,s="skill"===e.source&&(!r||"skill"!==r.source),o="skill"!==e.source&&0===t;return(0,n.jsxs)("div",{children:[o&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Commands"}),s&&(0,n.jsx)("div",{className:"px-4 py-1 text-[10px] uppercase tracking-wider text-muted-foreground bg-muted/40",children:"Skills"}),(0,n.jsxs)("div",{onClick:()=>_(e),className:`px-4 py-2 cursor-pointer ${t===L?"bg-brand/10":"hover:bg-accent"}`,children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("span",{className:"font-mono text-sm font-medium text-foreground",children:e.name}),(0,n.jsx)("span",{className:"flex-1 text-sm text-muted-foreground truncate",children:"builtin"===e.source?f(`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"}})(e.source)}`,children:(e=>{switch(e){case"builtin":return f("common.builtin");case"skill":return"Skill"}})(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.name)})}),(0,n.jsxs)("div",{className:"flex gap-2 items-end p-4",children:[(0,n.jsx)("button",{onClick:async()=>{if(!r)return;let e=await i.t4.runPromiseExit((0,h.Iz)(r,["."]));"Success"===e._tag?((0,k.oR)(f("toast.stagedAllFiles"),"success"),window.dispatchEvent(new CustomEvent("git-status-changed"))):(console.error("Error staging files:",e.cause),(0,k.oR)(f("toast.stageFailed"),"error"))},className:"p-2 text-green-11 hover:text-green-10 hover:bg-green-9/10 active:bg-green-9/20 active:scale-95 rounded-lg transition-all",title:f("chat.stageAll"),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:"M12 4v16m8-8H4"})})}),a&&(0,n.jsx)("button",{onClick:a,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:f("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 text-amber-11 hover:text-amber-10 hover:bg-amber-9/10 active:bg-amber-9/20 active:scale-95 rounded-lg transition-all",title:f("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-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:f("chat.userMessages"),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 6h16M4 12h16M4 18h16"})})}),m&&(0,n.jsx)("button",{onClick:m,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent active:bg-muted active:scale-95 rounded-lg transition-all",title:f("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"})})}),x&&(0,n.jsxs)("div",{className:"relative",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-accent active:bg-muted active:scale-95"}`,title:f("chat.scheduledTasks"),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:"12",cy:"12",r:"10",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]})}),C&&(0,n.jsx)(n4.E,{onClose:()=>S(!1),onCreate:x})]}),(0,n.jsx)("textarea",{ref:$,value:p,onChange:e=>g(e.target.value),onKeyDown:W,onPaste:z,placeholder:t?f("chat.placeholderDisabled"):f("chat.placeholder"),rows:1,className:"flex-1 resize-none px-4 py-2 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-ring bg-card text-foreground placeholder-slate-9"})]})]})});function n8({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[l,a]=(0,s.useState)([]),[d,u]=(0,s.useState)(!1),[x,h]=(0,s.useState)(null),[f,p]=(0,s.useState)(!1),g=(0,s.useRef)(null),b=(0,s.useRef)(null),[v,j]=(0,s.useState)({top:0,left:0}),w=(0,m.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{b.current&&!b.current.contains(e.target)&&g.current&&!g.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let y=(0,s.useCallback)(async()=>{u(!0),h(null);let e=await i.t4.runPromiseExit((0,c.qD)(()=>p(!0)));if(p(!1),"Failure"===e._tag)h("Connection error");else{let t=e.value;switch(t._tag){case"ok":a(t.models);break;case"not-installed":case"error":h(t.message);break;case"not-running":h("Ollama is not running")}}u(!1)},[]),k=e?e.replace(/:latest$/,""):"Select model",N=r?(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{ref:b,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-1 min-w-[200px] max-h-[300px] overflow-y-auto",style:{top:v.top,left:v.left},children:d||f?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),f?"Starting Ollama...":"Loading models..."]}):x?(0,n.jsx)("div",{className:"px-3 py-2 text-xs text-red-400",children:x}):0===l.length?(0,n.jsxs)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:["No models found. Run ",(0,n.jsx)("code",{className:"bg-secondary px-1 rounded",children:"ollama pull <model>"})]}):l.map(r=>{var s;return(0,n.jsxs)("button",{onClick:()=>{t(r.name),o(!1)},className:`w-full flex items-center justify-between gap-2 px-3 py-1.5 text-xs hover:bg-brand/10 transition-colors ${r.name===e?"text-brand":"text-foreground"}`,children:[(0,n.jsx)("span",{className:"truncate",children:r.name.replace(/:latest$/,"")}),(0,n.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:r.parameter_size||((s=r.size)<1e9?`${(s/1e6).toFixed(0)}M`:`${(s/1e9).toFixed(1)}G`)})]},r.name)})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:g,onClick:()=>{if(!r){if(g.current){let e=g.current.getBoundingClientRect(),t=w?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;j({top:e.bottom+4-n,left:e.left-r})}y()}o(e=>!e)},className:"flex items-center gap-1 px-2 py-0.5 text-[11px] rounded bg-violet-500/15 text-violet-400 hover:bg-violet-500/25 transition-colors",title:"Switch Ollama model",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-violet-500 flex-shrink-0"}),(0,n.jsx)("span",{className:"truncate max-w-[120px]",children:k}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0",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"})})]}),N]})}let n9=[{value:"deepseek-v4-flash",label:"deepseek-v4-flash"},{value:"deepseek-v4-pro",label:"deepseek-v4-pro"}];function n7({currentModel:e,onModelChange:t}){let[r,o]=(0,s.useState)(!1),[l,a]=(0,s.useState)(""),[d,u]=(0,s.useState)(""),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(null),w=(0,s.useRef)(null),y=(0,s.useRef)(null),k=(0,s.useRef)(null),[N,C]=(0,s.useState)({top:0,left:0}),S=(0,m.F2)();(0,s.useEffect)(()=>{if(!r)return;let e=e=>{y.current&&!y.current.contains(e.target)&&w.current&&!w.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);let L=(0,s.useCallback)(async()=>{p(!0),j(null);let r=await i.t4.runPromiseExit((0,c.td)());if("Failure"===r._tag){j("Failed to load settings"),p(!1);return}let n=r.value;a(n?.engines?.deepseek?.apiKey||""),u(""),h(!1);let s=n?.engines?.deepseek?.model;!e&&s&&n9.some(e=>e.value===s)&&t(s),p(!1)},[e,t]),E=(0,s.useCallback)(async e=>{let t=await i.t4.runPromiseExit((0,c.td)()),r=("Success"===t._tag?t.value:{}).engines||{},n={...r,deepseek:{...r.deepseek||{},...e}};if("Failure"===(await i.t4.runPromiseExit((0,c.em)({engines:n})))._tag)throw Error("Failed to save settings")},[]),M=async()=>{let e=d.trim();if(e){b(!0),j(null);try{await E({apiKey:e}),a(e),u(""),h(!1)}catch(e){j(e instanceof Error?e.message:"Save failed")}finally{b(!1)}}},T=async()=>{b(!0),j(null);try{await E({apiKey:""}),a(""),u(""),h(!1)}catch(e){j(e instanceof Error?e.message:"Clear failed")}finally{b(!1)}},$=async e=>{t(e);try{await E({model:e})}catch{}},P=!!l,R=P?e||"deepseek-v4-flash":"Set API key",B=P?"text-sky-400":"text-amber-400",F=r?(0,n.jsx)(m.ZL,{children:(0,n.jsx)("div",{ref:y,className:"fixed z-[9999] bg-popover border border-border rounded-lg shadow-lg py-2 min-w-[280px]",style:{top:N.top,left:N.left},children:f?(0,n.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{className:"w-3 h-3 border border-brand border-t-transparent rounded-full animate-spin"}),"Loading..."]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"API Key"}),P&&!x?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("code",{className:"flex-1 min-w-0 truncate text-xs px-2 py-1 rounded bg-secondary text-foreground font-mono",children:l?l.length<=8?l.replace(/./g,"•"):`${l.slice(0,3)}${"•".repeat(Math.max(4,l.length-7))}${l.slice(-4)}`:""}),(0,n.jsx)("button",{onClick:()=>{h(!0),u(""),setTimeout(()=>k.current?.focus(),0)},className:"text-[11px] px-2 py-1 rounded bg-secondary hover:bg-accent text-foreground transition-colors",disabled:g,children:"Edit"}),(0,n.jsx)("button",{onClick:T,className:"text-[11px] px-2 py-1 rounded text-red-400 hover:bg-red-500/10 transition-colors",disabled:g,children:"Clear"})]}):(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("input",{ref:k,type:"password",value:d,onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&M()},placeholder:"sk-...",className:"flex-1 min-w-0 text-xs px-2 py-1 rounded bg-secondary text-foreground border border-border focus:border-sky-500 focus:outline-none font-mono",autoFocus:!0}),(0,n.jsx)("button",{onClick:M,disabled:g||!d.trim(),className:"text-[11px] px-2 py-1 rounded bg-sky-500/20 hover:bg-sky-500/30 text-sky-300 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:g?"Saving...":"Save"}),P&&(0,n.jsx)("button",{onClick:()=>{h(!1),u("")},className:"text-[11px] px-2 py-1 rounded text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"})]}),v&&(0,n.jsx)("div",{className:"mt-1 text-[11px] text-red-400",children:v})]}),(0,n.jsx)("div",{className:"my-1 border-t border-border"}),(0,n.jsxs)("div",{className:"px-3 py-1.5",children:[(0,n.jsx)("div",{className:"text-[11px] font-medium text-muted-foreground mb-1.5",children:"Model"}),(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:n9.map(t=>{let r=(e||"deepseek-v4-flash")===t.value;return(0,n.jsxs)("button",{onClick:()=>$(t.value),className:`flex items-center gap-2 px-2 py-1 text-xs rounded transition-colors ${r?"bg-sky-500/15 text-sky-300":"text-foreground hover:bg-accent"}`,children:[(0,n.jsx)("span",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${r?"border-sky-400":"border-muted-foreground"}`,children:r&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-sky-400"})}),(0,n.jsx)("span",{children:t.label})]},t.value)})})]})]})})}):null;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("button",{ref:w,onClick:()=>{if(!r){if(w.current){let e=w.current.getBoundingClientRect(),t=S?.getBoundingClientRect(),r=t?.left??0,n=t?.top??0;C({top:e.bottom+4-n,left:e.left-r})}L()}o(e=>!e)},className:"flex items-center gap-1 px-2 py-0.5 text-[11px] rounded bg-sky-500/15 hover:bg-sky-500/25 transition-colors",title:"Configure DeepSeek",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-sky-500 flex-shrink-0"}),(0,n.jsx)("span",{className:`truncate max-w-[160px] ${B}`,children:R}),(0,n.jsx)("svg",{className:"w-3 h-3 flex-shrink-0 text-sky-400",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"})})]}),F]})}var se=r(46456);function st(e){if(0===e.length)return"";let t=[z.A.t("comments.codeRef"),""],r=e.filter(e=>e.filePath===g.Un),n=e.filter(e=>e.filePath!==g.Un);for(let e of(n.length>0&&n.forEach((e,r)=>{t.push(`[${r+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),t.push("```"),t.push(e.codeContent),t.push("```"),e.content&&t.push(z.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 sr({isOpen:e,onClose:t,cwd:r,onNavigateToComment:l}){let{t:a}=(0,o.Bd)(),[c,d]=(0,s.useState)([]),[u,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)(null),[b,v]=(0,s.useState)(!1),j=(0,s.useCallback)(async()=>{if(!r)return;h(!0);let e=await i.t4.runPromiseExit((0,se.$)(r));"Success"===e._tag?d(e.value.comments??[]):console.error("Failed to load comments:",e.cause),h(!1)},[r]);(0,s.useEffect)(()=>{e&&j()},[e,j]);let w=async e=>{let t=await i.t4.runPromiseExit((0,se.Tu)(r,e));"Success"===t._tag?(d(t=>t.filter(t=>t.id!==e)),(0,g.Cm)()):console.error("Failed to delete comment:",t.cause)},y=async e=>{p(e.id);try{let t="";if(e.selectedText)t=e.selectedText;else{let n=await i.t4.runPromiseExit((0,x.K9)(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=st([n]);await navigator.clipboard.writeText(s),(0,k.oR)(a("toast.copiedComment"))}catch(e){console.error("Failed to copy comment:",e)}finally{p(null)}},N=async()=>{if(0!==c.length){v(!0);try{let e=await (0,g.$3)(r),t=st(e);await navigator.clipboard.writeText(t),(0,k.oR)(a("toast.copiedAllComments"))}catch(e){console.error("Failed to copy all comments:",e)}finally{v(!1)}}},C=c.reduce((e,t)=>(e[t.filePath]||(e[t.filePath]=[]),e[t.filePath].push(t),e),{});if(!e)return null;let S=(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 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-xl 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 bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-foreground",children:a("comments.allComments")}),c.length>0&&(0,n.jsx)("button",{onClick:N,disabled:b,className:"p-1 rounded hover:bg-accent text-muted-foreground disabled:opacity-50",title:a("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-accent 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:a("common.loading")}):0===c.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:a("comments.noComments")})]}):(0,n.jsx)("div",{className:"space-y-4",children:Object.entries(C).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 bg-secondary border-b border-border",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-foreground font-mono",children:e===g.Un?a("comments.aiReply"):e}),(0,n.jsxs)("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",a("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-accent/50 cursor-pointer group",onClick:()=>l?.(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 font-mono",children:[a("common.line")," ",e.startLine===e.endLine?e.startLine:`${e.startLine}-${e.endLine}`]}),(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",a("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:a("comments.noContent")})})]}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),y(e)},disabled:f===e.id,className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground transition-opacity disabled:opacity-50",title:a("common.copy"),children:f===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(),w(e.id)},className:"p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-accent text-muted-foreground hover:text-red-9 transition-opacity",title:a("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 bg-secondary flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm text-muted-foreground",children:a("comments.totalComments",{count:c.length})}),(0,n.jsx)("button",{onClick:async()=>{0===c.length||await (0,g.RP)(r)&&d([])},disabled:0===c.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:a("comments.clearAll")})]})]})});return(0,n.jsx)(m.ZL,{children:S})}function sn({tabId:e,initialCwd:t,initialSessionId:r,engine:u,ollamaModel:m,onOllamaModelChange:x,deepseekModel:h,onDeepseekModelChange:f,hideHeader:p,hideSidebar:g,isActive:b=!0,onLoadingChange:v,onSessionIdChange:j,onTitleChange:w,onShowGitStatus:y,onOpenNote:k,onCreateScheduledTask:N,onOpenSession:C,onContentSearch:S,onOpenSessionBrowser:L,onOpenSettings:E}){let{t:M}=(0,o.Bd)(),T=ny(),[$,P]=(0,s.useState)([]),[R,B]=(0,s.useState)(null),[F,I]=(0,s.useState)(!1),[D,A]=(0,s.useState)(!1),[_,W]=(0,s.useState)(!1),[H,O]=(0,s.useState)(!1),[q,V]=(0,s.useState)(null),K=(0,s.useRef)(null),U=(0,s.useRef)(null),J=(0,s.useCallback)(async e=>{if(!t)return;let r=await i.t4.runPromiseExit((0,c.n_)({cwd:t,sessionId:e}));"Success"===r._tag&&r.value&&"string"==typeof r.value.title?w?.(r.value.title):"Failure"===r._tag&&console.error("Failed to fetch session title:",r.cause)},[t,w]),{isLoading:Q,tokenUsage:X,rateLimitInfo:Y,apiRetryInfo:Z,handleSend:G,handleStop:ee}=function(e,{sessionId:t,cwd:r,engine:n,ollamaModel:o,deepseekModel:l,onSessionId:a,onFetchTitle:i}){let[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(null),[x,h]=(0,s.useState)(null),[f,p]=(0,s.useState)(null),g=(0,s.useRef)(null),b=(0,s.useRef)(t);b.current=t;let v=(0,s.useRef)(null),j=(0,s.useRef)(null),w=(0,s.useCallback)(()=>{let t=v.current;if(t&&t.text){let{messageId:r,text:n}=t;e(e=>e.map(e=>e.id===r?{...e,content:(e.content||"")+n}:e)),v.current={messageId:r,text:""}}j.current=null},[e]),y=(0,s.useCallback)(()=>{g.current&&(g.current.abort(),g.current=null)},[]),k=(0,s.useCallback)((t,s)=>{let o=t.type;if("system"===o&&"init"===t.subtype){let e=t.session_id;a(e),b.current=e,p(null);return}if("system"===o&&"api_retry"===t.subtype)return void p({attempt:t.attempt??0,maxRetries:t.max_retries??0,delayMs:t.retry_delay_ms??0,errorStatus:t.error_status,error:t.error});if("rate_limit_event"===o){let e=t.rate_limit_info;e&&h({status:e.status||"allowed",resetsAt:e.resetsAt,rateLimitType:e.rateLimitType,utilization:e.utilization,overageStatus:e.overageStatus,overageDisabledReason:e.overageDisabledReason,isUsingOverage:e.isUsingOverage,surpassedThreshold:e.surpassedThreshold});return}if("stream_event"===o){p(e=>e?null:e);let e=t.event;if(e?.type==="content_block_delta"&&e.delta?.type==="text_delta"){let t=e.delta.text||"";v.current&&v.current.messageId===s?v.current.text+=t:v.current={messageId:s,text:t},j.current||(j.current=setTimeout(w,50))}return}if("assistant"===o){let r=t.message;if(r?.content){if("codex"===n||"kimi"===n||"ollama"===n){let t=r.content.filter(e=>"text"===e.type&&e.text).map(e=>e.text);if(t.length>0){let r=t.join("");e(e=>e.map(e=>e.id===s?{...e,content:(e.content||"")+r}:e))}}for(let t of r.content)if("name"in t&&t.name){let r={id:t.id||`tool-${Date.now()}`,name:t.name,input:t.input||{},isLoading:!0};e(e=>e.map(e=>e.id!==s||e.toolCalls?.some(e=>e.id===r.id)?e:{...e,toolCalls:[...e.toolCalls||[],r]}))}}}if("user"===o){let r=t.message;if(r?.content){for(let t of r.content)if("tool_use_id"in t&&t.tool_use_id){let r=t.tool_use_id,n="string"==typeof t.content?t.content:JSON.stringify(t.content);e(e=>e.map(e=>e.id===s?{...e,toolCalls:e.toolCalls?.map(e=>e.id===r?{...e,result:n,isLoading:!1}:e)}:e))}}}if("result"===o){p(null),j.current&&(clearTimeout(j.current),j.current=null),w();let n=b.current;n&&r&&e(e=>(2===e.length&&i(n),e));let o=t.usage,l=t.total_cost_usd;o&&m({inputTokens:o.input_tokens||0,outputTokens:o.output_tokens||0,cacheCreationInputTokens:o.cache_creation_input_tokens||0,cacheReadInputTokens:o.cache_read_input_tokens||0,totalCostUsd:l||0}),e(e=>e.map(e=>e.id===s?{...e,isStreaming:!1,toolCalls:e.toolCalls?.map(e=>({...e,isLoading:!1}))}:e))}},[e,w,a,i,r,n]),N=(0,s.useCallback)(async(t,s)=>{let a=s?.map(e=>({type:"base64",media_type:e.media_type,data:e.data})),i={id:`user-${Date.now()}`,role:"user",content:t,images:a};e(e=>[...e,i]),d(!0),p(null);let c=`assistant-${Date.now()}`,u={id:c,role:"assistant",content:"",toolCalls:[],isStreaming:!0};e(e=>[...e,u]),g.current=new AbortController;try{if("ollama"===n&&!o)throw Error("Please select an Ollama model first (click the model picker above)");let e="codex"===n?"/api/chat/codex":"kimi"===n?"/api/chat/kimi":"ollama"===n?"/api/chat/ollama":"deepseek"===n?"/api/chat/deepseek":"/api/chat",s=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt:t,sessionId:b.current,images:a,cwd:r,language:z.A.language,..."ollama"===n&&o&&{model:o},..."deepseek"===n&&l&&{model:l},..."claude2"===n&&{engine:"claude2"}}),signal:g.current.signal});if(400===s.status&&"deepseek"===n){let e=await s.json().catch(()=>null);throw Error(e?.error||"DeepSeek request failed")}if(!s.ok)throw Error(z.A.t("chat.requestFailed",{defaultValue:"Request failed"}));let i=s.body?.getReader();if(!i)throw Error(z.A.t("chat.cannotReadStream",{defaultValue:"Cannot read stream"}));let d=new TextDecoder,u="";for(;;){let{done:e,value:t}=await i.read();if(e)break;let r=(u+=d.decode(t,{stream:!0})).split("\n");for(let e of(u=r.pop()||"",r))if(e.startsWith("data: ")){let t=e.slice(6);if("[DONE]"===t)continue;try{let e=JSON.parse(t);k(e,c)}catch{}}}}catch(t){if(t instanceof Error&&"AbortError"===t.name);else{console.error("Chat error:",t);let r=t instanceof Error?t.message:z.A.t("chat.errorRetry",{defaultValue:"An error occurred. Please try again."});e(e=>e.map(e=>e.id===c?{...e,content:r,isStreaming:!1}:e))}}finally{g.current=null,d(!1),e(e=>e.map(e=>e.id===c?{...e,isStreaming:!1}:e))}},[r,n,o,l,e,k]);return{isLoading:c,tokenUsage:u,rateLimitInfo:x,apiRetryInfo:f,handleSend:N,handleStop:y,abortControllerRef:g}}(P,{sessionId:R,cwd:t,engine:u,ollamaModel:m,deepseekModel:h,onSessionId:B,onFetchTitle:J}),et=(0,s.useCallback)(async(e,r)=>{let n=e.split("\n")[0];if(n.startsWith("!")&&n.length>1){let s=n.slice(1).trim();if(!s)return void G(e,r);let o=e.split("\n").slice(1).join("\n").trim(),l=await i.t4.runPromiseExit((0,c.JC)({command:s,cwd:t}));if("Success"===l._tag){let e=l.value,t=[e.stdout,e.stderr].filter(Boolean).join("\n")||"(no output)",n=M("chat.executedCommand",{command:s,exitInfo:e.exitCode?` (exit code: ${e.exitCode})`:"",output:t});o&&(n+=`
28
28
 
29
- ${o}`),G(n,r)}else G(M("chat.executedCommandFailed",{command:s,error:l.cause}),r);return}G(e,r)},[G,t,M]),{isLoadingHistory:er,isLoadingMore:en,hasMoreHistory:es,loadMoreHistory:eo,loadHistoryByCwdAndSessionId:el}=function(e,t,r,{cwd:n,initialSessionId:o,onSessionId:l,onTitleChange:a,onTokenUsage:c}){let[d,u]=(0,s.useState)(!1),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(void 0),[b,v]=(0,s.useState)(0),j=(0,s.useRef)(a);j.current=a;let w=(0,s.useRef)(c);w.current=c;let y=(0,s.useRef)(void 0),k=(0,s.useRef)(0),N=(0,s.useCallback)(async(e,r,n=!1,s,o)=>{if(n){let e=Date.now();if(e-k.current<5e3)return;k.current=e}n||u(!0);try{let a={cwd:e,sessionId:r,limit:s,beforeTurnIndex:o};n&&y.current&&(a.ifFingerprint=y.current);let c=await i.t4.runPromiseExit(nM(a));if("Success"===c._tag&&c.value){let e=c.value;if(e.notModified)return;e.fingerprint&&(y.current=e.fingerprint),void 0!==e.totalTurns&&v(e.totalTurns),void 0!==e.hasMore&&f(e.hasMore),e.messages&&e.messages.length>0&&(n?t(t=>{let r=e.messages;if(t.length===r.length&&t.length>0&&t[t.length-1].content===r[r.length-1].content)return t;let n=0;for(let e=0;e<Math.min(t.length,r.length)&&t[e].id===r[e].id&&t[e].content===r[e].content;e++)n=e+1;return n===t.length&&n<r.length?[...t,...r.slice(n)]:r}):t(e.messages)),e.sessionId&&l(e.sessionId),e.title&&j.current?.(e.title),e.usage&&w.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{n||u(!1)}},[t,l]),C=(0,s.useCallback)(async()=>{if(n&&r&&!m&&h){x(!0);try{let s=void 0!==p?p:b-Math.ceil(e.filter(e=>"user"===e.role).length),o=await i.t4.runPromiseExit(nM({cwd:n,sessionId:r,limit:10,beforeTurnIndex:s>0?s:void 0}));if("Success"===o._tag&&o.value){let e=o.value;if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let r=e.messages.filter(e=>"user"===e.role).length;g(s-r)}void 0!==e.hasMore&&f(e.hasMore),e.fingerprint&&(y.current=e.fingerprint)}else"Failure"===o._tag&&console.error("Failed to load more history:",o.cause)}finally{x(!1)}}},[n,r,m,h,p,b,e,t]),S=(0,s.useCallback)(async e=>{u(!0);let r=eM.tryPromise({try:async()=>{let t=await fetch(`/api/session/${e}/history`);return t.ok?await t.json():null},catch:e=>new eT.uV({message:"load session history failed",cause:e})}),n=await i.t4.runPromiseExit(r);"Success"===n._tag&&n.value?.messages&&n.value.messages.length>0?t(n.value.messages):"Failure"===n._tag&&console.error("Failed to load history:",n.cause),u(!1)},[t]);return(0,s.useEffect)(()=>{n&&o&&N(n,o,!1,10)},[]),{isLoadingHistory:d,isLoadingMore:m,hasMoreHistory:h,loadMoreHistory:C,loadHistory:S,loadHistoryByCwdAndSessionId:N}}($,P,R,{cwd:t,initialSessionId:r,onSessionId:B,onTitleChange:w,onTokenUsage:V}),ea=(0,s.useRef)(b);(0,s.useEffect)(()=>{b&&!ea.current&&R&&t&&!Q&&el(t,R,!0,10),ea.current=b},[b,R,t,Q,el]);let ei=X||q;(0,s.useEffect)(()=>{R&&j?.(R)},[R,j]);let ec=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(v?.(Q),ec.current&&!Q&&t&&R){let e;for(let t=$.length-1;t>=0;t--)if("user"===$[t].role&&$[t].content){e=$[t].content.slice(0,100);break}(0,l.F)(a.n.SessionComplete,{cwd:t,sessionId:R,lastUserMessage:e})}ec.current=Q},[Q,v,t]),(0,s.useEffect)(()=>{b&&T?.setIsLoading(Q)},[Q,b,T]),(0,s.useEffect)(()=>{if(e&&T)return T.registerChat(e=>{U.current?.(e)},e),()=>{T.unregisterChat(e)}},[e,T]),(0,s.useEffect)(()=>{e&&b&&T&&T.setActiveTab(e)},[e,b,T]),(0,s.useEffect)(()=>{U.current=et},[et]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&F&&Q&&ee()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[F,Q,ee]);let ed=(0,s.useCallback)(async e=>{if(!t||!R)return;let r=await i.t4.runPromiseExit((0,c.Zr)(R,{cwd:t,fromMessageUuid:e}));if("Success"===r._tag&&r.value.newSessionId){let e=r.value.newSessionId;C?C(e,"Fork"):(0,l.F)(a.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===r._tag&&console.error("Fork failed:",r.cause)},[t,R,C]),eu=(0,s.useCallback)(()=>{W(!0)},[]),em=(0,s.useCallback)(()=>{O(!0)},[]),ex=(0,s.useMemo)(()=>{if(N&&t&&e&&R)return r=>{N({...r,cwd:t,tabId:e,sessionId:R})}},[N,t,e,R]);return(0,n.jsxs)("div",{className:`flex ${p&&g?"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:()=>I(!0),onMouseLeave:()=>I(!1),children:[!p&&(0,n.jsx)(nS,{cwd:t,sessionId:R,onOpenProjectSessions:()=>A(!0),onOpenSessionBrowser:L,onOpenSettings:E}),"ollama"===u&&x&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(n8,{currentModel:m,onModelChange:x})}),"deepseek"===u&&f&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(n7,{currentModel:h,onModelChange:f})}),er?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:M("sessions.loadingHistory")})}):(0,n.jsx)(n1,{ref:K,messages:$,isLoading:Q,cwd:t,sessionId:R,engine:u,apiRetryInfo:Z,hasMoreHistory:es,isLoadingMore:en,onLoadMore:eo,onFork:ed,isActive:b,onContentSearch:S}),ei&&(0,n.jsx)(nL,{tokenUsage:ei,rateLimitInfo:Y}),(0,n.jsx)(n6,{onSend:et,disabled:Q,cwd:t,engine:u,onShowGitStatus:y,onShowComments:t?eu:void 0,onShowUserMessages:em,onOpenNote:k,onCreateScheduledTask:ex})]}),!p&&t&&(0,n.jsx)(d,{isOpen:D,onClose:()=>A(!1),cwd:t}),t&&(0,n.jsx)(sr,{isOpen:_,onClose:()=>W(!1),cwd:t}),(0,n.jsx)(nE,{isOpen:H,onClose:()=>O(!1),messages:$,onSelectMessage:e=>{K.current?.scrollToMessage(e)}})]})}function ss({tabId:e,cwd:t,sessionId:r,engine:o,ollamaModel:l,onOllamaModelChange:a,deepseekModel:i,onDeepseekModelChange:c,isActive:d,onStateChange:u,onShowGitStatus:m,onOpenNote:x,onCreateScheduledTask:h,onOpenSession:f,onContentSearch:p}){let g=(0,s.useCallback)(t=>{u(e,{isLoading:t})},[e,u]),b=(0,s.useCallback)(t=>{u(e,{sessionId:t})},[e,u]),v=(0,s.useCallback)(t=>{u(e,{title:t})},[e,u]),j=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]),w=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]);return(0,n.jsx)(sn,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,ollamaModel:l,onOllamaModelChange:j,deepseekModel:i,onDeepseekModelChange:w,hideHeader:!0,hideSidebar:!0,isActive:d,onLoadingChange:g,onSessionIdChange:b,onTitleChange:v,onShowGitStatus:m,onOpenNote:x,onCreateScheduledTask:h,onOpenSession:f,onContentSearch:p})}var so=r(3292),sl=r(23121),sa=r(88292),si=r(76900),sc=r(96472);function sd({initialCwd:e,initialSessionId:t}){let{t:r}=(0,o.Bd)(),[l,c]=(0,s.useState)("agent"),{tabs:u,activeTabId:x,activeTab:h,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,closeTab:b,switchTab:v,handleSelectSession:j,handleNewTab:w,handleNewClaude2Tab:y,handleNewCodexTab:k,handleNewKimiTab:N,handleNewOllamaTab:C,handleNewDeepseekTab:S,handleOpenSession:L,updateTabState:E,updateTabOllamaModel:M,updateTabDeepseekModel:T,handleTabDragStart:$,handleTabDragOver:P,handleTabDrop:R,handleTabDragEnd:B}=(0,nk.useTabState)({initialCwd:e,initialSessionId:t,activeView:l}),{isPinned:F,pinSession:I,unpinSession:D}=(0,so.P)(),{createTask:A}=(0,sl.n)(),_=(0,s.useCallback)(e=>{let t=u.find(t=>t.id===e);return!!t?.sessionId&&F(t.sessionId)},[u,F]),W=(0,s.useCallback)(t=>{let r=u.find(e=>e.id===t);r?.sessionId&&(F(r.sessionId)?D(r.sessionId):I(r.sessionId,r.cwd||e||"",r.title))},[u,F,I,D,e]),[z,H]=(0,s.useState)(!1),[O,q]=(0,s.useState)(!1),[V,K]=(0,s.useState)(!1),[U,J]=(0,s.useState)(null),[Q,X]=(0,s.useState)(!1),[Y,Z]=(0,s.useState)("tree"),[G,ee]=(0,s.useState)(0),[et,er]=(0,s.useState)(null),[en,es]=(0,s.useState)(0);(0,s.useEffect)(()=>{e&&i.t4.runPromiseExit((0,si.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&c(t.activeView)}})},[e]);let[eo,el]=(0,s.useState)(!1),ea=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(ea.current=l,c("console"),el(!0)):(el(!1),ea.current&&"console"!==ea.current&&c(ea.current),ea.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[l]);let ei=(0,s.useCallback)(t=>{c(t),e&&(i.t4.runFork((0,si.Yn)({cwd:e,settings:{activeView:t}}).pipe(eM.orElse(()=>eM.void))),i.t4.runFork(eM.flatMap(sa.d,r=>r.publish(a.n.ViewChange,{cwd:e,view:t}))))},[e]),ec=(0,s.useCallback)(async()=>{if(!e)return;let t=await i.t4.runPromiseExit((0,si.b2)(e));if("Success"===t._tag){let r=t.value;if(X(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&J(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>ec())},[ec]);let ed=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"git"===e.type)&&ec()},[ec]);(0,ep.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:ed,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),ei("agent")):"2"===e.key?(e.preventDefault(),ei("explorer")):"3"===e.key&&(e.preventDefault(),ei("console")))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){j(r),n&&ei("agent");let t=u.find(e=>e.sessionId===r);e&&!t?.isLoading&&i.t4.runFork((0,sc.KJ)(e,r,"normal").pipe(eM.orElse(()=>eM.void)))}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[j,ei,e,u]);let eu=(0,s.useCallback)(()=>{Z("status"),ee(e=>e+1),ei("explorer")},[ei]),em=(0,s.useCallback)(e=>{er(e),es(e=>e+1),ei("explorer")},[ei]),ex=(0,s.useCallback)(()=>{e&&i.t4.runFork(eM.flatMap(sa.d,t=>t.publish(a.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(nw,{children:(0,n.jsx)(tC.fY,{activeView:l,onViewChange:ei,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)(nN.TabManagerTopBar,{initialCwd:e,activeTab:h,isGitRepo:Q,currentBranch:U,onOpenWorktree:()=>q(!0),onOpenProjectSessions:()=>H(!0),onOpenAliasManager:()=>K(!0),onBranchSwitched:ec}),eo&&(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:"●"}),r("console.screenshotting")]}),e?(0,n.jsxs)(tC.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 flex-col",children:[(0,n.jsx)(nC.TabBar,{tabs:u,activeTabId:x,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,isPinned:_,onTogglePin:W,onSwitchTab:v,onCloseTab:b,onNewTab:w,onNewClaude2Tab:y,onNewCodexTab:k,onNewKimiTab:N,onNewOllamaTab:C,onNewDeepseekTab:S,onDragStart:$,onDragOver:P,onDrop:R,onDragEnd:B}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===x?"block":"hidden"}`,children:(0,n.jsx)(ss,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:M,deepseekModel:e.deepseekModel,onDeepseekModelChange:T,isActive:e.id===x&&"agent"===l,onStateChange:E,onShowGitStatus:eu,onContentSearch:em,onOpenNote:ex,onCreateScheduledTask:A,onOpenSession:L})},e.id))})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(m.a9,{children:(0,n.jsx)(tS,{onClose:()=>ei("agent"),cwd:e,initialTab:Y,tabSwitchTrigger:G,initialSearchQuery:et,searchQueryTrigger:en})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(m.a9,{children:(0,n.jsx)(nv,{cwd:e,tabId:"default",onOpenNote:ex})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(nC.TabBar,{tabs:u,activeTabId:x,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,isPinned:_,onTogglePin:W,onSwitchTab:v,onCloseTab:b,onNewTab:w,onNewClaude2Tab:y,onNewCodexTab:k,onNewKimiTab:N,onNewDeepseekTab:S,onDragStart:$,onDragOver:P,onDrop:R,onDragEnd:B}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===x?"block":"hidden"}`,children:(0,n.jsx)(ss,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:M,deepseekModel:e.deepseekModel,onDeepseekModelChange:T,isActive:e.id===x,onStateChange:E,onCreateScheduledTask:A,onOpenSession:L})},e.id))})]})]}),e&&(0,n.jsx)(d,{isOpen:z,onClose:()=>H(!1),cwd:e,onSelectSession:j}),e&&Q&&(0,n.jsx)(tL,{isOpen:O,onClose:()=>q(!1),cwd:e}),V&&(0,n.jsx)(t1,{onClose:()=>K(!1),onSave:()=>K(!1)})]})})})}},37614:(e,t,r)=>{r.d(t,{t:()=>l});var n=r(95155),s=r(12115),o=r(79114);function l({x:e,y:t,comment:r,container:a,onClose:i,onUpdateComment:c,onDeleteComment:d}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(r.content),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&a){let r=a.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>b({x:s,y:o}))}},[e,t,a]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[i]);let v=async()=>{h.trim()&&(await c(r.id,h.trim()),x(!1))},j=async()=>{await d(r.id),i()};return(0,n.jsx)("div",{ref:p,className:"absolute z-[200] w-96 bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:g.x,top:g.y},children:(0,n.jsx)("div",{className:"p-3",children:m?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("textarea",{value:h,onChange:e=>f(e.target.value),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:3,autoFocus:!0,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),v()),"Escape"===e.key&&(x(!1),f(r.content))}}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>{x(!1),f(r.content)},className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground",children:u("common.cancel")}),(0,n.jsx)("button",{onClick:v,className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90",children:u("common.save")})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:r.content}),(0,n.jsxs)("div",{className:"mt-2 flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("comments.lineRange",{start:r.startLine,end:r.endLine})}),(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("button",{onClick:()=>x(!0),className:"p-1 rounded hover:bg-accent text-muted-foreground",title:u("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"})})}),(0,n.jsx)("button",{onClick:j,className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-red-9",title:u("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:"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"})})})]})]})]})})})}},38408:(e,t,r)=>{r.d(t,{Cv:()=>B,XO:()=>F});var n=r(95155),s=r(12115),o=r(79114),l=r(47650),a=r(86957),i=r(60938),c=r(70188),d=r(7320),u=r(56978),m=r(17196),x=r(89109),h=r(37614),f=r(69809),p=r(64428);function g({blame:e,onClick:t}){let{t:r}=(0,o.Bd)(),l=(0,s.useRef)(null),a=(0,s.useRef)(null),i=(0,p.F2)(),c=(0,s.useRef)(!1),d=(0,s.useRef)(!1),u=(0,s.useRef)(null),m=(0,s.useRef)(null),x=(0,s.useRef)(null),h=(0,s.useRef)(e);(0,s.useEffect)(()=>{h.current=e},[e]);let b=(0,s.useRef)(t);(0,s.useEffect)(()=>{b.current=t},[t]);let v=(0,s.useCallback)(()=>{let e,t=a.current,r=l.current;if(!t||!r)return;let n=r.getBoundingClientRect(),s=t.getBoundingClientRect(),o=i?.getBoundingClientRect(),c=o?.left??0,d=o?.top??0,u=o?.width??window.innerWidth,m=o?.height??window.innerHeight,x=n.left-c;x+s.width>u-8&&(x=u-s.width-8),x<8&&(x=8);let h=n.top-d,f=n.bottom-d;(e=h-s.height-4<0?f+4:h-s.height-4)+s.height>m-8&&(e=m-s.height-8),t.style.left=`${x}px`,t.style.top=`${e}px`},[i]),j=(0,s.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null),m.current&&(clearTimeout(m.current),m.current=null),c.current=!1,d.current=!1,a.current&&(a.current.style.display="none"),x.current&&(document.removeEventListener("mousedown",x.current.down),document.removeEventListener("mouseup",x.current.up),x.current=null)},[]),w=(0,s.useCallback)(()=>{let e=a.current;if(!e||c.current)return;c.current=!0,e.style.left="-9999px",e.style.top="-9999px",e.style.display="block",requestAnimationFrame(()=>requestAnimationFrame(v));let t=0,r=0,n=e=>{t=e.clientX,r=e.clientY},s=e=>{if(!(Math.abs(e.clientX-t)>5||Math.abs(e.clientY-r)>5)){let t;t=e.target,a.current?.contains(t)||l.current?.contains(t)||j()}};document.addEventListener("mousedown",n),document.addEventListener("mouseup",s),x.current={down:n,up:s}},[v,j]),y=(0,s.useCallback)(()=>{if(u.current&&clearTimeout(u.current),m.current&&(clearTimeout(m.current),m.current=null),c.current)return;let e=window.getSelection();(!e||e.isCollapsed)&&(u.current=setTimeout(w,500))},[w]),k=(0,s.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null),c.current&&(m.current=setTimeout(()=>{d.current||j()},200))},[j]),N=(0,s.useCallback)(()=>{d.current=!0,m.current&&(clearTimeout(m.current),m.current=null)},[]),C=(0,s.useCallback)(()=>{d.current=!1,j()},[j]),S=(0,s.useCallback)(e=>{e.stopPropagation();let t=window.getSelection();t&&t.toString().length>0&&a.current?.contains(t.anchorNode)||(b.current?.(h.current),j())},[j]);(0,s.useEffect)(()=>()=>j(),[j]);let L=e.message.split("\n")[0]||"",E=e.message.split("\n").slice(1).join("\n").trim();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{ref:l,className:"select-none text-xs text-muted-foreground/50 ml-6 cursor-default hover:text-muted-foreground/80",onMouseEnter:y,onMouseLeave:k,children:[e.author.split(" ")[0],", ",function(e){let t=f.A.t,r=Math.floor((Date.now()-1e3*e)/1e3);if(r<60)return t("common.justNow");let n=Math.floor(r/60);if(n<60)return t("common.minutesAgo",{count:n});let s=Math.floor(n/60);if(s<24)return t("common.hoursAgo",{count:s});let o=Math.floor(s/24);if(o<30)return t("common.daysAgo",{count:o});let l=Math.floor(o/30);return l<12?t("common.monthsAgo",{count:l}):t("common.yearsAgo",{count:Math.floor(l/12)})}(e.time)," \xb7 ",L]}),(0,n.jsx)(p.ZL,{children:(0,n.jsxs)("div",{ref:a,className:"fixed z-[9999] bg-card border border-border rounded-lg shadow-xl p-3 text-xs text-foreground whitespace-pre-wrap max-w-md select-text",style:{display:"none",minWidth:280,cursor:"text"},"data-inline-blame-tip":"",onMouseEnter:N,onMouseLeave:C,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,n.jsx)("span",{className:"font-mono text-brand",children:e.hash}),(0,n.jsx)("span",{className:"text-muted-foreground",children:e.author}),(0,n.jsx)("span",{className:"text-muted-foreground/60",children:new Date(1e3*e.time).toLocaleString()})]}),(0,n.jsx)("div",{className:"font-medium",children:L}),E&&(0,n.jsx)("div",{className:"mt-1 text-muted-foreground",children:E}),(0,n.jsx)("div",{className:"mt-2 text-[11px] text-brand border-t border-border pt-2 cursor-pointer hover:underline",onClick:S,children:r("codeViewer.clickToViewDetails")})]})})]})}let b=[{bg:"rgba(59, 130, 246, 0.15)",border:"rgb(59, 130, 246)"},{bg:"rgba(16, 185, 129, 0.15)",border:"rgb(16, 185, 129)"},{bg:"rgba(245, 158, 11, 0.15)",border:"rgb(245, 158, 11)"},{bg:"rgba(239, 68, 68, 0.15)",border:"rgb(239, 68, 68)"},{bg:"rgba(168, 85, 247, 0.15)",border:"rgb(168, 85, 247)"},{bg:"rgba(236, 72, 153, 0.15)",border:"rgb(236, 72, 153)"},{bg:"rgba(20, 184, 166, 0.15)",border:"rgb(20, 184, 166)"},{bg:"rgba(249, 115, 22, 0.15)",border:"rgb(249, 115, 22)"}];function v(e,t){let r,n=document.caretRangeFromPoint(e.clientX,e.clientY);if(!n||!t.contains(n.startContainer))return 1;let s=n.startContainer,o=n.startOffset,l=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),a=1;for(;r=l.nextNode();){if(r===s){a+=o;break}a+=r.textContent?.length||0}return a}let j=(0,s.memo)(function({virtualKey:e,lineNum:t,highlightedHtml:r,hasComments:l,firstComment:a,lineCommentsCount:i,isInRange:c,showLineNumbers:d,lineNumChars:u,commentsEnabled:m,virtualItemSize:x,virtualItemStart:h,onCommentBubbleClick:f,onCmdClick:p,onTokenHover:b,onTokenHoverLeave:j,flashLine:w,blameLine:y,showBlameInfo:k,blameAuthorColor:N,isBlameHovered:C,onBlameClick:S,onBlameMouseEnter:L,onBlameMouseLeave:E,inlineBlameData:M,onInlineBlameClick:T,isCursorLine:$,cursorCol:P}){let{t:R}=(0,o.Bd)(),B=(0,s.useMemo)(()=>$&&null!=P?function(e,t){let r=0,n=0;for(;n<e.length;){if("<"===e[n]){let t=e.indexOf(">",n);if(-1!==t){n=t+1;continue}}if(r===t){let t;if("&"===e[n]){let r=e.indexOf(";",n);t=-1!==r&&r-n<10?r+1:n+1}else t=n+1;let r=e.substring(n,t);return e.substring(0,n)+'<span class="vi-char-cursor">'+r+"</span>"+e.substring(t)}if("&"===e[n]){let t=e.indexOf(";",n);n=-1!==t&&t-n<10?t+1:n+1}else n++;r++}return e+'<span class="vi-char-cursor"> </span>'}(r,P):r,[r,$,P]),F=(0,s.useCallback)(e=>{if(!e.metaKey||!p)return;e.preventDefault(),e.stopPropagation();let r=e.currentTarget,n=v(e,r);window.getSelection()?.removeAllRanges(),p(t,n)},[t,p]),I=(0,s.useCallback)(e=>{if(!b||0!==e.buttons)return;let r=window.getSelection();if(r&&!r.isCollapsed)return;let n=e.target;if("SPAN"!==n.tagName||!n.style.color)return;let s=e.currentTarget,o=v(e,s),l=n.getBoundingClientRect();b(t,o,{x:l.left,y:l.bottom+4})},[t,b]),D=(0,s.useCallback)(()=>{y&&S&&S(y)},[y,S]),A=(0,s.useCallback)(e=>{y&&L&&L(y,e)},[y,L]);return(0,n.jsxs)("div",{"data-line":t,style:{position:"absolute",top:0,left:0,width:"100%",height:`${x}px`,transform:`translateY(${h}px)`,backgroundColor:C&&N?N.bg:void 0},className:`flex ${w===t?"flash-line":""} ${$?"vi-cursor-line":""} ${c?"bg-blue-9/20":l?"bg-amber-9/10":"hover:bg-accent/50"}`,children:[(0,n.jsxs)("div",{className:"flex shrink-0 sticky left-0 z-[2] bg-secondary",style:{backgroundColor:C&&N?N.bg:void 0},children:[y&&N&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-1 flex-shrink-0",style:{backgroundColor:N.border}}),(0,n.jsx)("div",{className:"w-48 flex-shrink-0 px-2 flex items-center gap-2 border-r border-border text-muted-foreground cursor-pointer hover:bg-accent/50",onMouseEnter:A,onMouseLeave:E,onClick:D,title:R("codeViewer.clickToViewCommit"),children:k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"font-medium",style:{color:N.border},children:y.hash}),(0,n.jsx)("span",{className:"truncate flex-1",children:y.author.split(" ")[0]})]}):null})]}),d&&(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center justify-end gap-0.5 pr-2 select-none border-r border-border font-variant-tabular ${c?"bg-blue-9/30 text-blue-11":"bg-card/50 text-slate-9"}`,children:[m&&l&&a&&(0,n.jsx)("button",{onClick:e=>f(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:R("codeViewer.nComments",{count:i}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),m&&!l&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"text-right",style:{minWidth:`${u}ch`},children:t})]})]}),(0,n.jsxs)("span",{className:"flex-1 px-3 whitespace-pre select-text",onClick:F,onMouseOver:I,onMouseLeave:j,"data-code-content":!0,children:[(0,n.jsx)("span",{dangerouslySetInnerHTML:{__html:B}}),M&&(0,n.jsx)(g,{blame:M,onClick:T})]})]},e)});var w=r(64702),y=r(1058),k=r(90717),N=r(48347),C=r(27570);function S(e,t,r){let n,s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),o=0;for(;(n=s.nextNode())&&n!==t;)o+=n.textContent.length;return o+r}function L(e,t){let r,n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),s=t,o=null;for(;r=n.nextNode();){o=r;let e=r.textContent.length;if(s<=e)return{node:r,offset:s};s-=e}return o?{node:o,offset:o.textContent.length}:null}var E=r(82292),M=r(34075);let T="white-space:pre;padding:0 12px;min-height:20px;line-height:20px";function $(e){let t=window.getSelection();if(!t?.rangeCount)return null;let r=t.getRangeAt(0),n=r.startContainer;for(;n&&n.parentElement!==e;)n=n.parentElement;if(!n)return null;let s=Array.from(e.children).indexOf(n);if(s<0)return null;let o=document.createRange();return o.selectNodeContents(n),o.setEnd(r.startContainer,r.startOffset),{line:s,offset:o.toString().length}}function P(e,t){let r,n=e.children[t.line];if(!n)return;let s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=t.offset;for(;r=s.nextNode();){let e=r.textContent?.length||0;if(o<=e){let e=window.getSelection(),t=document.createRange();t.setStart(r,o),t.collapse(!0),e?.removeAllRanges(),e?.addRange(t);return}o-=e}let l=window.getSelection(),a=document.createRange();a.selectNodeContents(n),a.collapse(!1),l?.removeAllRanges(),l?.addRange(a)}function R(e){return e.map(e=>`<div style="${T}">${e}</div>`).join("")}let B=(0,s.forwardRef)(function({content:e,filePath:t,showLineNumbers:r=!0,showSearch:f=!0,className:p="",cwd:g,enableComments:v=!1,scrollToLine:B=null,scrollToLineAlign:F="center",onScrollToLineComplete:I,highlightKeyword:D=null,visibleLineRef:A,onCmdClick:_,onTokenHover:W,onTokenHoverLeave:z,onTokenHoverCancel:H,blameLines:O,inlineBlameLines:q,onSelectCommit:V,editable:K=!1,initialMtime:U,onEditorClose:J,onSaved:Q,onEditorStateChange:X,viMode:Y=!1,onContentMutate:Z,onEnterInsertMode:G,onViSave:ee,viStateRef:et,initialCursorLine:er,initialCursorCol:en,onInitialCursorSet:es,onContentSearch:eo},el){let{t:ea}=(0,o.Bd)(),ei=(0,s.useRef)(e),ec=(0,s.useRef)(!1),[ed,eu]=(0,s.useState)(!1),[em,ex]=(0,s.useState)(!1),[eh,ef]=(0,s.useState)(()=>e.split("\n").length),ep=(0,s.useRef)(e.split("\n").length),[eg,eb]=(0,s.useState)({show:!1}),ev=(0,s.useRef)(null),ej=(0,s.useRef)(null),ew=(0,s.useRef)(U),ey=(0,s.useRef)(null),ek=(0,s.useRef)(!1),eN=(0,s.useRef)(!1),{parentRef:eC,containerRef:eS,searchInputRef:eL,floatingToolbarRef:eE,suppressHoverRef:eM,bumpToolbarRef:eT,savedSelectionRef:e$,highlightedLines:eP,isMounted:eR,cmdHeld:eB,flashLine:eF,isSearchVisible:eI,searchQuery:eD,caseSensitive:eA,wholeWord:e_,currentMatchIndex:eW,viewingComment:ez,addCommentInput:eH,sendToAIInput:eO,aiBridge:eq,commentsEnabled:eV,updateComment:eK,deleteComment:eU,lines:eJ,matches:eQ,rowData:eX,virtualizer:eY,commentsByEndLine:eZ,linesWithComments:eG,setIsSearchVisible:e0,setSearchQuery:e1,setCaseSensitive:e2,setWholeWord:e5,setViewingComment:e4,setAddCommentInput:e3,setSendToAIInput:e6,goToNextMatch:e8,goToPrevMatch:e9,handleSearchKeyDown:e7,handleCommentBubbleClick:te,handleToolbarAddComment:tt,handleToolbarSendToAI:tr,handleToolbarSearch:tn,handleCommentSubmit:ts,handleSendToAISubmit:to,getHighlightedLineHtml:tl,suppressMatchScrollRef:ta,inlineBlameLineRef:ti,inlineBlameVersion:tc}=function({content:e,filePath:t,showSearch:r=!0,cwd:n,enableComments:o=!1,scrollToLine:l=null,scrollToLineAlign:a="center",onScrollToLineComplete:i,visibleLineRef:c,onContentSearch:d}){let[x,h]=(0,s.useState)(!1),f=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,N.r)();(0,s.useEffect)(()=>{h(!0)},[]);let[v,j]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),M=(0,s.useRef)(null),[T,$]=(0,s.useState)(!1),[P,R]=(0,s.useState)(""),[B,F]=(0,s.useState)(!1),[I,D]=(0,s.useState)(!1),[A,_]=(0,s.useState)(0),[W,z]=(0,s.useState)(0),H=(0,s.useRef)(!1),[O,q]=(0,s.useState)(null),V=(0,s.useRef)(!1),K=(0,s.useRef)(null),[U,J]=(0,s.useState)(null),[Q,X]=(0,s.useState)(null),Y=(0,s.useMemo)(()=>e.split("\n"),[e]),[Z,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{f.current!==Z&&G(f.current)});let ee=o&&!!n,{toolbarRef:et,bumpRef:er,clearToolbar:en}=(0,C.L)({enabled:ee,container:Z,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)return null;let n=parseInt(r.getAttribute("data-line")||"0",10);return!Number.isFinite(n)||n<=0?null:{start:n,end:n}},buildLineSnapshot:({start:e,end:t})=>Y.slice(e-1,t).join("\n")}),es=(0,s.useRef)(null),[eo,el]=(0,s.useState)(0),{comments:ea,addComment:ei,updateComment:ec,deleteComment:ed,refresh:eu}=(0,y._)({cwd:n||"",filePath:t}),em=(0,u.C)(Y,t),ex=(0,s.useMemo)(()=>{let e=new Map;for(let t of ea){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[ea]),eh=(0,s.useMemo)(()=>{let e=new Set;for(let t of ea)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[ea]),ef=(0,s.useMemo)(()=>(0,m.Np)(Y,P,B,I),[Y,P,B,I]);(0,s.useEffect)(()=>{ef.length>0&&_(0)},[ef.length,P,B,I]);let ep=(0,s.useMemo)(()=>{let e=[];for(let t=0;t<Y.length;t++)e.push({type:"code",lineIndex:t});return e},[Y.length]),eg=(0,w.Te)({count:ep.length,getScrollElement:()=>f.current,estimateSize:()=>20,overscan:10});(0,s.useEffect)(()=>{if(!c)return;let e=f.current;if(!e)return;let t=()=>{if(!eg.range)return;let t=e.scrollTop;for(let e of eg.getVirtualItems())if(e.start>=t){let t=ep[e.index];t?.type==="code"&&(c.current=t.lineIndex+1);return}};return e.addEventListener("scroll",t,{passive:!0}),t(),()=>e.removeEventListener("scroll",t)},[c,ep]),(0,s.useEffect)(()=>{let e=e=>{"Meta"===e.key&&j(!0)},t=e=>{"Meta"===e.key&&j(!1)},r=()=>j(!1);return window.addEventListener("keydown",e),window.addEventListener("keyup",t),window.addEventListener("blur",r),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t),window.removeEventListener("blur",r)}},[]),(0,s.useEffect)(()=>{if(!r)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),$(!0),setTimeout(()=>g.current?.focus(),0)),"Escape"===e.key&&(T?($(!1),R("")):Q?X(null):U?J(null):et.current?en():O&&q(null))},t=p.current;if(t)return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[r,T,Q,U,O]),(0,s.useEffect)(()=>{if(H.current){H.current=!1;return}if(ef.length>0&&A>=0&&A<ef.length){let e=ef[A],t=ep.findIndex(t=>"code"===t.type&&t.lineIndex===e.lineIndex);t>=0&&eg.scrollToIndex(t,{align:"center"})}},[A,ef,eg,ep,W]);let eb=(0,s.useCallback)(()=>{0!==ef.length&&(_(e=>(e+1)%ef.length),z(e=>e+1))},[ef.length]),ev=(0,s.useCallback)(()=>{0!==ef.length&&(_(e=>(e-1+ef.length)%ef.length),z(e=>e+1))},[ef.length]),ej=(0,s.useRef)(l);ej.current=l,(0,s.useEffect)(()=>{if(null!==ej.current&&ej.current>0&&ep.length>0){let e=ej.current,t=e-1,r=ep.findIndex(e=>"code"===e.type&&e.lineIndex===t);if(r>=0){let t=()=>{eg.scrollToIndex(r,{align:a}),"center"===a&&(M.current&&clearTimeout(M.current),E(e),M.current=setTimeout(()=>E(null),500)),i?.()};"start"===a?requestAnimationFrame(t):setTimeout(t,150)}}},[l,a,ep.length,eg,i]);let ew=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?ev():eb()),"Escape"===e.key&&($(!1),R(""))},[eb,ev]),ey=(0,s.useCallback)((e,t)=>{ee&&(t.stopPropagation(),q({comment:e,x:t.clientX,y:t.clientY}),en(),J(null),X(null))},[ee,en]);(0,s.useEffect)(()=>{if(!ee)return;let e=f.current,t=!1,r=()=>{t=!0,K.current=null,V.current=!0},n=()=>{t=!1;let e=window.getSelection();if(!e||e.isCollapsed||!e.toString().trim()){V.current=!1;return}let r=e.getRangeAt(0),n=f.current;if(!n||!n.contains(r.commonAncestorContainer))return;let s=r.startContainer,o=r.endContainer,l=(s.nodeType===Node.TEXT_NODE?s.parentElement:s)?.closest("[data-line]"),a=(o.nodeType===Node.TEXT_NODE?o.parentElement:o)?.closest("[data-line]");if(!l||!a)return;let i=parseInt(l.getAttribute("data-line")||"0",10),c=parseInt(a.getAttribute("data-line")||"0",10);i&&c&&(V.current=!0,K.current={startLine:i,startOffset:S(l,r.startContainer,r.startOffset),endLine:c,endOffset:S(a,r.endContainer,r.endOffset)})},s=()=>{if(t)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(K.current=null,V.current=!1)};return e?.addEventListener("mousedown",r),document.addEventListener("mouseup",n),document.addEventListener("selectionchange",s),()=>{e?.removeEventListener("mousedown",r),document.removeEventListener("mouseup",n),document.removeEventListener("selectionchange",s)}},[ee]),(0,s.useEffect)(()=>{let e=f.current;if(!e)return;let t=t=>{let r,n;if(!e.contains(t.target)){if(t.target.closest?.("[data-inline-blame-tip]"))return;null!==es.current&&(es.current=null,el(e=>e+1));return}let s=window.getSelection();if(s&&!s.isCollapsed&&s.toString().trim())return;let o=(r=t.target,(n=r.closest?.("[data-line]"))?parseInt(n.getAttribute("data-line")||"0",10):null);o!==es.current&&(es.current=o,requestAnimationFrame(()=>el(e=>e+1)))};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]);let ek=(0,s.useCallback)(()=>{let e=et.current;e&&(J({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,et]),eN=(0,s.useCallback)(()=>{let e=et.current;e&&(X({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,et]),eC=(0,s.useCallback)(()=>{let e=et.current;if(!e||!d)return;let t=e.selectedText.trim();en(),t&&d(t)},[d,en,et]),eS=(0,s.useCallback)(async e=>{U&&(await ei(U.range.start,U.range.end,e,U.selectedText),J(null))},[U,ei]),eL=(0,s.useCallback)(async e=>{if(Q&&b&&n)try{let r=await (0,k.$3)(n),s=[];for(let e of r)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:Q.range.start,endLine:Q.range.end,codeContent:Q.lineSnapshot});let o=(0,k.Gw)(s,e);b.sendMessage(o),await (0,k.RP)(n),eu(),X(null)}catch(e){console.error("Failed to send to AI:",e)}},[Q,b,t,n,eu]),eE=(0,s.useCallback)((e,t,r)=>{let n=Y[e];if(!n)return t;let s=[];if(P&&ef.length>0)for(let t of ef.filter(t=>t.lineIndex===e)){let r=ef[A]?.lineIndex===e&&ef[A]?.startCol===t.startCol;s.push({start:t.startCol,end:t.endCol,cls:r?"hl-cur":"hl-m"})}if(r&&!P&&r.length>=1){let e=r.toLowerCase(),t=n.toLowerCase(),o=0;for(;-1!==(o=t.indexOf(e,o));)s.push({start:o,end:o+r.length,cls:"hl-kw"}),o+=1}if(0===s.length)return t;s.sort((e,t)=>e.start-t.start||e.end-t.end);let o=[],l=0;for(let e of s){if(e.start<l)continue;e.start>l&&o.push((0,m.ZD)(n.substring(l,e.start)));let t=(0,m.ZD)(n.substring(e.start,e.end));o.push(`<span class="${e.cls}">${t}</span>`),l=e.end}if(l<n.length&&o.push((0,m.ZD)(n.substring(l))),t!==(0,m.ZD)(n)){let e=t;for(let t of s){let r=n.substring(t.start,t.end),s=(0,m.ZD)(r),o=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=RegExp(`(?<=>)([^<]*?)(${o})`,""),a=`$1<span class="${t.cls}">${s}</span>`,i=e.replace(l,a);i.length>e.length+200||(e=i)}return e}return o.join("")},[P,ef,A,Y]);return{parentRef:f,containerRef:p,searchInputRef:g,floatingToolbarRef:et,suppressHoverRef:V,savedSelectionRef:K,highlightedLines:em,isMounted:x,cmdHeld:v,flashLine:L,isSearchVisible:T,searchQuery:P,caseSensitive:B,wholeWord:I,currentMatchIndex:A,viewingComment:O,bumpToolbarRef:er,addCommentInput:U,sendToAIInput:Q,aiBridge:b,commentsEnabled:ee,comments:ea,updateComment:ec,deleteComment:ed,lines:Y,matches:ef,rowData:ep,virtualizer:eg,commentsByEndLine:ex,linesWithComments:eh,setIsSearchVisible:$,setSearchQuery:R,suppressMatchScrollRef:H,setCaseSensitive:F,setWholeWord:D,setViewingComment:q,setAddCommentInput:J,setSendToAIInput:X,goToNextMatch:eb,goToPrevMatch:ev,handleSearchKeyDown:ew,handleCommentBubbleClick:ey,handleToolbarAddComment:ek,handleToolbarSendToAI:eN,handleToolbarSearch:eC,handleCommentSubmit:eS,handleSendToAISubmit:eL,getHighlightedLineHtml:eE,inlineBlameLineRef:es,inlineBlameVersion:eo}}({content:e,filePath:t,showSearch:f,cwd:g,enableComments:!K&&v,scrollToLine:K?null:B,scrollToLineAlign:K?"center":F,onScrollToLineComplete:K?void 0:I,visibleLineRef:K?void 0:A,onContentSearch:eo}),td=(0,c.iN)(),tu=(0,s.useRef)(null),tm=(0,s.useRef)(null),tx=(0,s.useRef)({line:0,col:0}),th=(0,s.useRef)({line:0,col:0}),tf=function({lines:e,enabled:t,onContentChange:r,onEnterInsert:n,onSave:o,getVisibleLineCount:l,scrollToLine:a,onSearchExecute:i,onSearchNext:c,onSearchPrev:d,onSearchClear:u}){let[m,x]=(0,s.useState)("normal"),[h,f]=(0,s.useState)(-1),[p,g]=(0,s.useState)(0),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(""),[y,k]=(0,s.useState)(""),[N,C]=(0,s.useState)(""),[S,L]=(0,s.useState)(""),E=(0,s.useRef)([]),M=(0,s.useRef)([]),T=(0,s.useRef)([]),$=(0,s.useRef)(null),P=(0,s.useRef)(e);(0,s.useEffect)(()=>{P.current=e}),(0,s.useEffect)(()=>{0!==e.length&&queueMicrotask(()=>f(t=>Math.min(t,e.length-1)))},[e.length]);let R=(0,s.useCallback)((e,t)=>Math.max(0,Math.min(t,Math.max(0,(P.current[e]??"").length-1))),[]),B=(0,s.useRef)(e.length);(0,s.useEffect)(()=>{let t=Math.abs(e.length-B.current);B.current=e.length,t>10&&(queueMicrotask(()=>{f(-1),g(0),v(!1)}),E.current=[],M.current=[],T.current=[])},[e]);let F=(0,s.useCallback)(()=>{$.current&&(clearTimeout($.current),$.current=null),w("")},[]),I=(0,s.useCallback)(()=>{$.current&&clearTimeout($.current),$.current=setTimeout(()=>{w(""),$.current=null},500)},[]),D=(0,s.useCallback)((e,t)=>{E.current.push(t),M.current=[],v(!0),r(e.join("\n"))},[r]),A=(0,s.useCallback)((e,t)=>{let r=Math.max(0,Math.min(e,P.current.length-1));f(r),g(R(r,t??0)),a(r,"auto")},[a,R]),_=(0,s.useCallback)(e=>{f(t=>{let r=Math.max(0,Math.min(t+e,P.current.length-1));return a(r,"auto"),g(e=>Math.max(0,Math.min(e,Math.max(0,(P.current[r]??"").length-1)))),r})},[a]),W=(0,s.useCallback)(()=>{let e=P.current,t=Math.min(h,e.length-1);if(0===e.length)return;let r=e[t];T.current=[r];let n=[...e];n.splice(t,1),0===n.length&&n.push("");let s=Math.min(t,n.length-1);D(n,{lineIndex:t,oldLines:[r],newLines:[],cursorLine:t}),f(s),g(0)},[h,D]),z=(0,s.useCallback)(()=>{let e=P.current,t=Math.min(h,e.length-1);e.length>0&&(T.current=[e[t]])},[h]),H=(0,s.useCallback)(()=>{let e=T.current;if(0===e.length)return;let t=P.current,r=Math.min(h,t.length-1)+1,n=[...t];n.splice(r,0,...e),D(n,{lineIndex:r,oldLines:[],newLines:[...e],cursorLine:h}),f(r),g(0),a(r,"auto")},[h,D,a]),O=(0,s.useCallback)(()=>{let e=P.current,t=Math.min(h,e.length-1),r=e[t];if(!r||0===r.length)return;let n=r.substring(1),s=[...e];s[t]=n,D(s,{lineIndex:t,oldLines:[r],newLines:[n],cursorLine:h})},[h,D]),q=(0,s.useCallback)(()=>{let e=E.current;if(0===e.length)return;let t=e.pop(),n=[...P.current];0===t.newLines.length&&t.oldLines.length>0?n.splice(t.lineIndex,0,...t.oldLines):0===t.oldLines.length&&t.newLines.length>0?(n.splice(t.lineIndex,t.newLines.length),0===n.length&&n.push("")):n.splice(t.lineIndex,t.newLines.length,...t.oldLines),M.current.push(t),r(n.join("\n")),f(Math.min(t.cursorLine,n.length-1)),a(Math.min(t.cursorLine,n.length-1),"auto"),0===e.length&&v(!1)},[r,a]),V=(0,s.useCallback)(()=>{let e=M.current;if(0===e.length)return;let t=e.pop(),n=[...P.current];0===t.newLines.length&&t.oldLines.length>0?(n.splice(t.lineIndex,t.oldLines.length),0===n.length&&n.push("")):0===t.oldLines.length&&t.newLines.length>0?n.splice(t.lineIndex,0,...t.newLines):n.splice(t.lineIndex,t.oldLines.length,...t.newLines),E.current.push(t),v(!0),r(n.join("\n"));let s=t.lineIndex+Math.max(0,t.newLines.length-1);f(Math.min(s,n.length-1)),a(Math.min(s,n.length-1),"auto")},[r,a]),K=(0,s.useCallback)(e=>{let t=P.current,r=Math.min(h,t.length-1);if("o"===e||"O"===e){let n="o"===e?r+1:r,s=[...t];s.splice(n,0,""),D(s,{lineIndex:n,oldLines:[],newLines:[""],cursorLine:h}),r=n,f(n)}x("insert"),n(r,p,e)},[h,p,D,n]),U=(0,s.useCallback)(()=>{x("normal"),F()},[F]),J=(0,s.useCallback)(()=>{x("command"),k("")},[]),Q=(0,s.useCallback)(()=>{x("normal"),k("")},[]),X=(0,s.useCallback)(()=>{x("search"),C("")},[]),Y=(0,s.useCallback)(()=>{x("normal"),C("")},[]),Z=(0,s.useCallback)(e=>{let t=e.trim();if("w"===t){o?.(),x("normal"),k("");return}if("q"===t){x("normal"),k("");return}if("wq"===t){o?.(),x("normal"),k("");return}if("noh"===t||"nohlsearch"===t){u?.(),x("normal"),k("");return}let r=parseInt(t,10);if(!isNaN(r)&&r>0){let e=Math.min(r-1,P.current.length-1);f(e),a(e,"center"),x("normal"),k("");return}x("normal"),k("")},[o,u,a]),G=(0,s.useCallback)(e=>{if(!e){x("normal"),C("");return}L(e),i?.(e),x("normal"),C("")},[i]),ee=(0,s.useCallback)(e=>{if(!t)return!1;let r=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;if("insert"===m)return("Escape"===e.key||!!r)&&(U(),!0);if("command"===m)return!e.isComposing&&("Escape"===e.key||r?Q():"Enter"===e.key?Z(y):"Backspace"===e.key?0===y.length?Q():k(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||k(t=>t+e.key),!0);if("search"===m)return!e.isComposing&&("Escape"===e.key||r?Y():"Enter"===e.key?G(N):"Backspace"===e.key?0===N.length?Y():C(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||C(t=>t+e.key),!0);if(h<0&&(f(0),g(0)),e.metaKey)return!1;if(e.ctrlKey)return"d"===e.key?(_(Math.max(1,Math.floor(l()/2))),F(),!0):"u"===e.key?(_(-Math.max(1,Math.floor(l()/2))),F(),!0):"r"===e.key&&(V(),F(),!0);let n=e.key,s=j+n;if("g"===s)return w("g"),I(),!0;if("gg"===s)return A(0),F(),!0;if("d"===s)return w("d"),I(),!0;if("dd"===s)return W(),F(),!0;if("y"===s)return w("y"),I(),!0;if("yy"===s)return z(),F(),!0;if(j&&s!==n&&F(),"j"===n||"ArrowDown"===n)return _(1),!0;if("k"===n||"ArrowUp"===n)return _(-1),!0;if("h"===n||"ArrowLeft"===n)return g(e=>Math.max(0,e-1)),!0;if("l"===n||"ArrowRight"===n){let e=Math.max(0,(P.current[h]??"").length-1);return g(t=>Math.min(e,t+1)),!0}if("0"===n)return g(0),!0;if("$"===n)return g(Math.max(0,(P.current[h]??"").length-1)),!0;if("^"===n){let e=(P.current[h]??"").search(/\S/);return g(e>=0?e:0),!0}return"G"===n?(A(P.current.length-1),!0):"x"===n?(O(),!0):"p"===n?(H(),!0):"u"===n?(q(),!0):"i"===n||"a"===n||"I"===n||"A"===n||"o"===n||"O"===n?(K(n),!0):"/"===n?(X(),!0):"n"===n?(c?.(),!0):"N"===n?(d?.(),!0):":"===n?(J(),!0):"Escape"!==n&&1===n.length},[t,m,j,y,N,h,U,K,J,Q,X,Y,Z,G,_,A,l,W,z,H,O,q,V,F,I,c,d]);return{state:{mode:m,cursorLine:h,cursorCol:p,isDirty:b,keyBuffer:j,commandInput:y,searchInput:N,lastSearch:S},handleKeyDown:ee,enterNormal:U,enterInsert:K,setCursorLine:f,setCursorCol:g,setCommandInput:k,setSearchInput:C,setIsDirty:v,clearUndoHistory:(0,s.useCallback)(()=>{E.current=[],M.current=[]},[])}}({lines:eJ,enabled:Y&&!K,onContentChange:e=>{tx.current={line:th.current.line,col:th.current.col},Z?.(e)},onEnterInsert:(e,t,r)=>{let n=t;if("a"===r)n=t+1;else if("A"===r)n=(eJ[e]??"").length;else if("I"===r){let t=(eJ[e]??"").search(/\S/);n=t>=0?t:0}else("o"===r||"O"===r)&&(n=0);tx.current={line:e,col:n},G?.(e)},onSave:ee,getVisibleLineCount:()=>{let e=eC.current;return e?Math.floor(e.clientHeight/20):20},scrollToLine:(e,t)=>{let r=eX.findIndex(t=>"code"===t.type&&t.lineIndex===e);r>=0&&eY.scrollToIndex(r,{align:t||"auto"})},onSearchExecute:e=>{e1(e),e0(!1)},onSearchNext:e8,onSearchPrev:e9,onSearchClear:()=>{e1("")}});(0,s.useEffect)(()=>{et&&(et.current={cursorLine:tf.state.cursorLine,cursorCol:tf.state.cursorCol}),th.current={line:tf.state.cursorLine,col:tf.state.cursorCol}},[et,tf.state.cursorLine,tf.state.cursorCol]);let tp=(0,s.useRef)(null);(0,s.useEffect)(()=>{Y&&!K&&null!=er&&t&&tp.current!==t&&(tp.current=t,tf.setCursorLine(er-1),null!=en&&tf.setCursorCol(en-1),es?.())},[Y,K,er,en,t]),(0,s.useEffect)(()=>{if(!Y||K)return;let e=eS.current;if(!e)return;let t=e=>{let t=e.target;"TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable||tf.handleKeyDown(e)&&(e.preventDefault(),e.stopPropagation())};return e.addEventListener("keydown",t,!0),()=>e.removeEventListener("keydown",t,!0)},[Y,K,tf.handleKeyDown]),(0,s.useEffect)(()=>{if(!Y||K)return;let e=eS.current;e&&"normal"===tf.state.mode&&requestAnimationFrame(()=>{let t=document.activeElement;t&&("TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable)||e.focus()})},[Y,K,tf.state.mode,e]);let tg=(0,s.useCallback)(e=>{if(!Y||K)return;let t=e.target.closest("[data-line]");if(t){let r=parseInt(t.getAttribute("data-line"),10);if(!isNaN(r)){tf.setCursorLine(r-1);let n=t.querySelector("[data-code-content]");if(n){let t=document.caretRangeFromPoint(e.clientX,e.clientY);if(t&&n.contains(t.startContainer)){let e,s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=0;for(;e=s.nextNode();){if(e===t.startContainer){o+=t.startOffset;break}o+=e.textContent?.length||0}let l=eJ[r-1]??"";tf.setCursorCol(Math.max(0,Math.min(o,Math.max(0,l.length-1))))}}}}let r=e.target;if("TEXTAREA"===r.tagName||"INPUT"===r.tagName||r.isContentEditable)return;let n=eS.current;n&&n.focus()},[Y,K,tf.setCursorLine,tf.setCursorCol,eJ]),tb=(0,s.useCallback)(e=>{Y&&!K&&requestAnimationFrame(()=>{let e=window.getSelection(),t=e?.toString().trim();t&&/^\S+$/.test(t)&&(ta.current=!0,e1(t))})},[Y,K,e1,ta]);(0,s.useEffect)(()=>{"command"===tf.state.mode?setTimeout(()=>tu.current?.focus(),0):"search"===tf.state.mode&&setTimeout(()=>tm.current?.focus(),0)},[tf.state.mode]),(0,s.useEffect)(()=>{let e=eC.current;if(!e)return;let t=()=>{(H??z)?.()};return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t)},[H,z]),(0,s.useEffect)(()=>{eH||eO?(eM.current=!0,z?.()):eE.current||(eM.current=!1)},[eH,eO,z]),(0,s.useLayoutEffect)(()=>{let e=e$.current;if(!e)return;let t=window.getSelection();if(t&&!t.isCollapsed)return;let r=eC.current;if(!r)return;let n=r.querySelector(`[data-line="${e.startLine}"]`),s=r.querySelector(`[data-line="${e.endLine}"]`);if(!n||!s)return;let o=L(n,e.startOffset),l=L(s,e.endOffset);if(o&&l)try{let e=document.createRange();e.setStart(o.node,o.offset),e.setEnd(l.node,l.offset),t?.removeAllRanges(),t?.addRange(e)}catch{}});let tv=(0,s.useCallback)((e,t,r)=>{eM.current||W?.(e,t,r)},[W]),tj=(0,s.useCallback)((e,t)=>{eM.current||_?.(e,t)},[_]),tw=Math.max(4,String(K?eh:eJ.length).length),ty=(0,s.useMemo)(()=>{let e=0;for(let t of eJ){let r=0;for(let e=0;e<t.length;e++)" "===t[e]?r+=2-r%2:r+=1;r>e&&(e=r)}return e},[eJ]);(0,s.useEffect)(()=>{if(K){ei.current=e;let t=e.split("\n").length;ep.current=t,ef(t),ec.current=!1,eu(!1),eb({show:!1}),ew.current=U}},[K,e,U]),(0,s.useEffect)(()=>{if(!K)return;let t=ev.current;if(!t)return;let r=e.split("\n");t.innerHTML=R(r.map((e,t)=>eP[t]||(0,m.ZD)(e||" "))),requestAnimationFrame(()=>{let e,n;Y?(e=Math.max(0,Math.min(tx.current.line,r.length-1)),n=tx.current.col):(e=Math.max(0,Math.min((A?.current??1)-1,r.length-1)),n=0),t.focus(),P(t,{line:e,offset:n});let s=A?.current??1;ej.current&&(ej.current.scrollTop=(s-1)*20)})},[K]),(0,s.useEffect)(()=>{K&&X?.({isDirty:ed,isSaving:em})},[K,ed,em,X]);let tk=(0,s.useCallback)(()=>{let e=ev.current;if(!e)return ei.current;let t=[];for(let r of e.childNodes){let e=r.textContent||"";t.push(" "===e?"":e)}return t.join("\n")},[]),tN=(0,s.useCallback)(()=>{ey.current&&clearTimeout(ey.current),ey.current=setTimeout(async()=>{let e=ev.current;if(e&&!eN.current){ei.current=tk();try{let r=await (0,m.kS)(),n=(0,m.sQ)(t),s=document.documentElement.classList.contains("dark"),o=ei.current.split("\n"),l=r.codeToTokens(o.join("\n"),{lang:n,theme:s?"github-dark":"github-light"}).tokens.map(e=>(0,m.b8)(e)),a=$(e);ek.current=!0,e.innerHTML=R(l),ek.current=!1,a&&P(e,a)}catch{}}},300)},[t,tk]);(0,s.useEffect)(()=>{if(K)return()=>{ey.current&&clearTimeout(ey.current)}},[K]);let tC=(0,s.useCallback)(()=>{let e=ev.current;if(!e)return;ec.current||(ec.current=!0,eu(!0));let t=e.children.length;t!==ep.current&&(ep.current=t,ef(t))},[]),tS=(0,s.useCallback)(()=>{ek.current||eN.current||(tC(),tN())},[tC,tN]),tL=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&("Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," ")),"Enter"===e.key)){e.preventDefault();let t=ev.current;if(!t)return;let r=window.getSelection();if(!r?.rangeCount)return;let n=r.getRangeAt(0);n.deleteContents();let s=n.startContainer;for(;s&&s.parentElement!==t;)s=s.parentElement;if(!s||!(s instanceof HTMLElement))return;let o=$(t),l=Array.from(t.children).indexOf(s),a=s.textContent||"",i=o?.offset??a.length,c=a.substring(0,i),d=a.substring(i);s.innerHTML=(0,m.ZD)(c||" ");let u=document.createElement("div");u.setAttribute("style",T),u.innerHTML=(0,m.ZD)(d||" "),s.after(u),P(t,{line:l+1,offset:0}),tC(),tN()}},[tC,tN]),tE=(0,s.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData("text/plain");document.execCommand("insertText",!1,t)},[]),tM=(0,s.useCallback)(async(e=!1)=>{if(!g)return;ei.current=tk(),ex(!0);let r=await a.t4.runPromiseExit((0,i.OJ)({cwd:g,path:t,content:ei.current,expectedMtime:e?void 0:ew.current}));if("Failure"===r._tag){console.error("Error saving file:",r.cause),(0,M.oR)(ea("toast.saveFailed"),"error"),ex(!1);return}let n=r.value,s=n.data;if(409===n.status&&s?.conflict){let e=await a.t4.runPromiseExit((0,i.K9)(g,t));"Success"===e._tag&&e.value.ok&&"string"==typeof e.value.data?.content?eb({show:!0,diskContent:e.value.data.content}):eb({show:!0}),ex(!1);return}if(!n.ok){console.error("Error saving file: status",n.status),(0,M.oR)(ea("toast.saveFailed"),"error"),ex(!1);return}let o=s?.mtime;o&&(ew.current=o),ec.current=!1,eu(!1),eb({show:!1}),(0,M.oR)(ea("toast.savedSuccess"),"success"),Q?.(),ex(!1)},[g,t,tk,Q,ea]),tT=(0,s.useCallback)(async()=>{ed&&!em&&await tM(!1)},[ed,em,tM]),t$=(0,s.useCallback)(async()=>{eb({show:!1}),await tM(!0)},[tM]),tP=(0,s.useCallback)(()=>{if(void 0!==eg.diskContent){ei.current=eg.diskContent;let t=eg.diskContent.split("\n").length;ep.current=t,ef(t);let r=eg.diskContent!==e;ec.current=r,eu(r);let n=ev.current;n&&(n.innerHTML=R(eg.diskContent.split("\n").map(e=>(0,m.ZD)(e||" "))),tN())}eb({show:!1}),Q?.()},[eg.diskContent,e,Q,tN]),tR=(0,s.useCallback)(()=>{let e=ej.current;return e?Math.floor(e.scrollTop/20)+1:A?.current??1},[A]),tB=(0,s.useCallback)(async()=>{(!ed||await (0,M.lJ)(ea("codeViewer.unsavedConfirm"),{danger:!0,confirmText:ea("codeViewer.discardChanges"),cancelText:ea("codeViewer.continueEditing")}))&&J?.(tR())},[ed,J,tR]);(0,s.useEffect)(()=>{if(!K)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),tT())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[K,tT]);let tF=(0,s.useCallback)(()=>{let e=tk();Z?.(e);let t=ev.current,r=t?$(t):null,n=tR();if(tf.enterNormal(),r){tf.setCursorLine(r.line);let t=e.split("\n")[r.line]??"";tf.setCursorCol(Math.max(0,Math.min(r.offset,Math.max(0,t.length-1))))}else tf.setCursorLine(Math.max(0,n-1));J?.(n)},[tk,Z,tR,J,tf]);(0,s.useEffect)(()=>{if(!K)return;let e=e=>{let t="Escape"===e.key,r=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;(t||Y&&r)&&(e.preventDefault(),e.stopPropagation(),Y?ec.current?(0,M.lJ)(ea("codeViewer.unsavedExitConfirm"),{danger:!0,confirmText:ea("codeViewer.discardChanges"),cancelText:ea("codeViewer.continueEditing")}).then(e=>{e&&tF()}):tF():tB())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[K,Y,tB,tF]);let tI=(0,s.useCallback)(()=>{ec.current||(ec.current=!0,eu(!0))},[]);(0,s.useImperativeHandle)(el,()=>({save:tT,close:tB,markDirty:tI,get isDirty(){return ec.current},get isSaving(){return em}}),[tT,tB,tI,em]);let tD=!!(O&&O.length>0),tA=(0,s.useMemo)(()=>{if(!O)return new Map;let e=[...new Set(O.map(e=>e.author))],t=new Map;return e.forEach((e,r)=>{t.set(e,b[r%b.length])}),t},[O]),[t_,tW]=(0,s.useState)(null),[tz,tH]=(0,s.useState)(null);(0,s.useEffect)(()=>{tW(null),tH(null)},[O]);let tO=(0,s.useCallback)((e,t)=>{tW(e.author);let r=t.currentTarget.getBoundingClientRect();tH({line:e,x:r.right+8,y:r.top})},[]),tq=(0,s.useCallback)(()=>{tW(null),tH(null)},[]),tV=(0,s.useCallback)(e=>{V&&(V({hash:e.hashFull,shortHash:e.hash,author:e.author,authorEmail:e.authorEmail,date:new Date(1e3*e.time).toISOString(),subject:e.message.split("\n")[0]||"",body:e.message.split("\n").slice(1).join("\n").trim(),time:e.time}),tH(null))},[V]),tK=`${tw+2}ch`;return(0,n.jsxs)("div",{ref:eS,className:`h-full flex flex-col outline-none ${p}`,tabIndex:0,onClick:tg,onDoubleClick:tb,children:[K&&eg.show&&(0,n.jsxs)("div",{className:"px-4 py-2 bg-amber-500/15 border-b border-amber-500/30 flex items-center gap-3 flex-shrink-0",children:[(0,n.jsx)("svg",{className:"w-5 h-5 text-amber-500 flex-shrink-0",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-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1",children:ea("codeViewer.fileModifiedExternally")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:tP,className:"px-3 py-1 text-sm rounded border border-border hover:bg-accent transition-colors",children:ea("codeViewer.useDiskVersion")}),(0,n.jsx)("button",{onClick:t$,className:"px-3 py-1 text-sm rounded bg-amber-500 text-white hover:bg-amber-600 transition-colors",children:ea("codeViewer.forceOverwrite")})]})]}),!K&&f&&eI&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("input",{ref:eL,type:"text",value:eD,onChange:e=>e1(e.target.value),onKeyDown:e7,placeholder:ea("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsx)("button",{onClick:()=>e2(!eA),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eA?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:ea("codeViewer.caseSensitive"),children:"Aa"}),(0,n.jsx)("button",{onClick:()=>e5(!e_),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e_?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:ea("codeViewer.wholeWordMatch"),children:"[ab]"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:eQ.length>0?`${eW+1}/${eQ.length}`:ea("common.noMatch")}),(0,n.jsx)("button",{onClick:e9,disabled:0===eQ.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:ea("common.previous"),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"})})}),(0,n.jsx)("button",{onClick:e8,disabled:0===eQ.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:ea("common.next"),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"})})}),(0,n.jsx)("button",{onClick:()=>{e0(!1),e1("")},className:"p-1 rounded hover:bg-accent",title:ea("common.close"),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"})})})]}),K?(0,n.jsx)("div",{ref:ej,className:"flex-1 overflow-auto bg-secondary",children:(0,n.jsxs)("div",{className:"flex",style:{minHeight:"100%"},children:[(0,n.jsx)("div",{className:"flex-shrink-0 font-mono text-sm select-none sticky left-0 z-[2] bg-secondary",style:{width:tK},children:Array.from({length:eh},(e,t)=>(0,n.jsx)("div",{className:"text-right text-muted-foreground/50 pr-3",style:{height:20,lineHeight:"20px"},children:t+1},t))}),(0,n.jsx)("div",{ref:ev,contentEditable:!0,suppressContentEditableWarning:!0,onInput:tS,onKeyDown:tL,onPaste:tE,onCompositionStart:()=>{eN.current=!0},onCompositionEnd:()=>{eN.current=!1,tS()},spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",className:"flex-1 font-mono text-sm outline-none",style:{caretColor:"var(--foreground)",tabSize:2}})]})}):(0,n.jsx)("div",{ref:eC,className:`flex-1 overflow-auto font-mono text-sm bg-secondary${eB?" cmd-held-container":""}`,children:(0,n.jsx)("div",{style:{height:`${eY.getTotalSize()}px`,minWidth:"100%",width:tD?`calc(${tw+ty+10}ch + 13rem)`:`${tw+ty+10}ch`,position:"relative"},children:eY.getVirtualItems().map(e=>{let t=eX[e.index];if("code"!==t.type)return null;let s=t.lineIndex,o=s+1,l=eP[s]||(0,m.ZD)(eJ[s]||""),a=tl(s,l,D),i=eG.has(o),c=eZ.get(o),d=c?.[0],u=!!(eH&&o>=eH.range.start&&o<=eH.range.end),x=tc>=0?ti.current:null,h=!K&&q&&x===o?q[s]??null:null,f=tD?O[s]:void 0,p=tD&&s>0?O[s-1]:void 0,g=!!f&&(!p||p.hash!==f.hash),b=f?tA.get(f.author):void 0;return(0,n.jsx)(j,{virtualKey:e.key,lineNum:o,highlightedHtml:a,hasComments:i,firstComment:d,lineCommentsCount:c?.length,isInRange:u,showLineNumbers:r,lineNumChars:tw,commentsEnabled:eV,virtualItemSize:e.size,virtualItemStart:e.start,onCommentBubbleClick:te,onCmdClick:tj,onTokenHover:tv,onTokenHoverLeave:z,flashLine:eF,blameLine:f,showBlameInfo:g,blameAuthorColor:b,isBlameHovered:!!(f&&t_===f.author),onBlameClick:tV,onBlameMouseEnter:tO,onBlameMouseLeave:tq,inlineBlameData:h,onInlineBlameClick:tV,isCursorLine:Y&&!K&&tf.state.cursorLine===s,cursorCol:Y&&!K&&tf.state.cursorLine===s?tf.state.cursorCol:void 0},e.key)})})}),Y&&(0,n.jsxs)("div",{className:"vi-status-bar flex-shrink-0 h-6 bg-card border-t border-border flex items-center px-3 text-xs font-mono select-none",children:["normal"===tf.state.mode&&(0,n.jsx)("span",{className:"text-green-11 font-medium",children:"NORMAL"}),"insert"===tf.state.mode&&(0,n.jsx)("span",{className:"text-blue-11 font-medium",children:"INSERT"}),"command"===tf.state.mode&&(0,n.jsxs)("div",{className:"flex items-center flex-1",children:[(0,n.jsx)("span",{className:"text-foreground",children:":"}),(0,n.jsx)("input",{ref:tu,value:tf.state.commandInput,onChange:e=>tf.setCommandInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tf.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),"search"===tf.state.mode&&(0,n.jsxs)("div",{className:"flex items-center flex-1",children:[(0,n.jsx)("span",{className:"text-foreground",children:"/"}),(0,n.jsx)("input",{ref:tm,value:tf.state.searchInput,onChange:e=>tf.setSearchInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tf.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),tf.state.keyBuffer&&"normal"===tf.state.mode&&(0,n.jsx)("span",{className:"ml-2 text-muted-foreground",children:tf.state.keyBuffer}),tf.state.isDirty&&("normal"===tf.state.mode||"command"===tf.state.mode)&&(0,n.jsx)("span",{className:"ml-2 text-amber-11",children:"[+]"}),(0,n.jsxs)("span",{className:"ml-auto text-muted-foreground",children:[tf.state.cursorLine+1,":",tf.state.cursorCol+1]})]}),eR&&td&&(0,l.createPortal)((0,n.jsxs)(n.Fragment,{children:[!K&&(0,n.jsx)(x.f,{floatingToolbarRef:eE,bumpRef:eT,container:td,onAddComment:tt,onSendToAI:tr,onSearch:eo?tn:void 0,isChatLoading:eq?.isLoading}),!K&&eH&&(0,n.jsx)(d.t,{x:eH.x,y:eH.y,range:eH.range,lineSnapshot:eH.lineSnapshot,container:td,onSubmit:ts,onClose:()=>e3(null)}),!K&&eO&&(0,n.jsx)(d.G,{x:eO.x,y:eO.y,range:eO.range,filePath:t,lineSnapshot:eO.lineSnapshot,container:td,onSubmit:to,onClose:()=>e6(null),isChatLoading:eq?.isLoading}),!K&&ez&&(0,n.jsx)(h.t,{x:ez.x,y:ez.y,comment:ez.comment,container:td,onClose:()=>e4(null),onUpdateComment:eK,onDeleteComment:eU}),tz&&(0,n.jsxs)("div",{className:"fixed z-50 bg-card border border-border rounded-lg shadow-lg p-3 max-w-lg",style:{left:Math.min(tz.x,window.innerWidth-450),top:Math.max(8,Math.min(tz.y,window.innerHeight-200))},children:[(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 rounded text-xs font-mono font-medium text-white flex-shrink-0",style:{backgroundColor:tA.get(tz.line.author)?.border||"#666"},children:tz.line.hash}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground",children:tz.line.author}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:tz.line.authorEmail})]})]}),(0,n.jsx)("div",{className:"mt-2 text-sm text-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:tz.line.message}),(0,n.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground border-t border-border pt-2",children:[(0,E.fw)(tz.line.time)," \xb7 ",new Date(1e3*tz.line.time).toLocaleString(),(0,n.jsx)("span",{className:"ml-2 text-brand",children:ea("codeViewer.clickToViewDetails")})]})]})]}),td)]})});function F({content:e,filePath:t,className:r=""}){let o=(0,s.useMemo)(()=>e.split("\n"),[e]),l=(0,u.C)(o,t),a=Math.max(4,String(o.length).length);return(0,n.jsx)("pre",{className:`overflow-auto text-sm font-mono bg-secondary p-2 ${r}`,children:o.map((e,t)=>(0,n.jsxs)("div",{className:"flex",children:[(0,n.jsx)("span",{className:"text-slate-9 select-none pr-4 text-right",style:{minWidth:`${a+2}ch`},children:t+1}),(0,n.jsx)("span",{className:"flex-1",dangerouslySetInnerHTML:{__html:l[t]||(0,m.ZD)(e||" ")}})]},t))})}},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);return(0,n.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{e.data?.type==="IFRAME_VISIBILITY"&&t(!!e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e}},46456:(e,t,r)=>{r.d(t,{$:()=>i,BC:()=>c,Tu:()=>u,lb:()=>a,tj:()=>m,vv:()=>d});var n=r(49433),s=r(82680);let o=(e,t)=>n.tryPromise({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)=>n.tryPromise({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})}),a=(e,t)=>o(`/api/comments?cwd=${encodeURIComponent(e)}${t?`&filePath=${encodeURIComponent(t)}`:""}`),i=e=>o(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`),c=e=>o("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),d=(e,t,r)=>o("/api/comments",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,id:t,content:r})}),u=(e,t)=>l(`/api/comments?cwd=${encodeURIComponent(e)}&id=${encodeURIComponent(t)}`,{method:"DELETE"}),m=e=>l(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`,{method:"DELETE"})},47617:(e,t,r)=>{r.d(t,{I18nProvider:()=>c});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(86957),i=r(76900);function c({children:e}){return(0,s.useEffect)(()=>{a.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";l.A.language!==r&&l.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 l.A.on("languageChanged",e),()=>{l.A.off("languageChanged",e)}},[]),(0,s.useEffect)(()=>{if(window===window.parent)return;let e=e=>{e.data?.type==="cockpit:language-change"&&e.data.lang&&l.A.language!==e.data.lang&&l.A.changeLanguage(e.data.lang)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,n.jsx)(o.xC,{i18n:l.A,children:e})}},48347:(e,t,r)=>{r.d(t,{H:()=>l,r:()=>a});var n=r(95155),s=r(12115);let o=(0,s.createContext)(null);function l({value:e,children:t}){return(0,n.jsx)(o.Provider,{value:e,children:t})}function a(){return(0,s.useContext)(o)}},53213:(e,t,r)=>{r.d(t,{Bj:()=>i,CM:()=>b,FK:()=>g,Iz:()=>m,MB:()=>v,Ub:()=>h,X0:()=>x,Zi:()=>c,lv:()=>u,oh:()=>p,r4:()=>a,w2:()=>f,yy:()=>d});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({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})}),l=(e,t)=>n.tryPromise({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})}),a=e=>o(`/api/git/branches?cwd=${encodeURIComponent(e)}`).pipe(n.flatMap(t=>"Failed to get branches"===t.error?n.fail(new s.m_({resource:"git-repo",id:e})):n.succeed(t))),i=(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)}`:""}`),d=(e,t,r)=>o(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),u=e=>o(`/api/git/status?cwd=${encodeURIComponent(e)}`),m=(e,t)=>l("/api/git/stage",{cwd:e,files:t}),x=(e,t)=>l("/api/git/unstage",{cwd:e,files:t}),h=(e,t,r)=>l("/api/git/discard",{cwd:e,files:t,isUntracked:r}),f=(e,t,r)=>{let n=new URLSearchParams({cwd:e,file:t,type:r});return o(`/api/git/diff?${n}`)},p=e=>o(`/api/git/diff?${e.toString()}`),g=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),b=e=>n.tryPromise({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})}),v=e=>o(`/api/projectGraph/search?${e.toString()}`)},53853:(e,t,r)=>{r.d(t,{G:()=>u,f:()=>m});var n=r(12115);function s(){if("u"<typeof document)return null;let e=document.querySelector('meta[name="cockpit-bridge"]');if(!e)return null;let t=e.dataset.id,r=e.dataset.version;return t?{id:t,version:r||"unknown"}:null}let o=null,l=new Set;function a(){l.forEach(e=>e())}function i(e){l.add(e);let t=s();return t&&!o&&(o=t,Promise.resolve().then(a)),()=>{l.delete(e)}}function c(){return o}function d(){return null}if("u">typeof document&&(o=s()),"u">typeof MutationObserver&&"u">typeof document){let e=new MutationObserver(()=>{let e=s();e&&(!o||e.id!==o.id||e.version!==o.version)&&(o=e,a())}),t=document.head||document.documentElement;t&&e.observe(t,{childList:!0})}function u(){return(0,n.useSyncExternalStore)(i,c,d)}function m(){return o??s()}},56978:(e,t,r)=>{r.d(t,{C:()=>o});var n=r(12115),s=r(17196);function o(e,t){let[r,o]=(0,n.useState)(null),[l,a]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=()=>{a(document.documentElement.classList.contains("dark"))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let i=(0,n.useMemo)(()=>e.join("\n"),[e]),c=`${i}:${t}:${l}`,d=(0,n.useMemo)(()=>r&&r.key===c?r.html:e.map(e=>(0,s.ZD)(e||" ")),[e,c,r]);return(0,n.useEffect)(()=>{if(0===e.length)return;let r=!1;return(async()=>{try{let n=await (0,s.kS)();if(r)return;let a=(0,s.sQ)(t),i=e.join("\n"),d=n.codeToTokens(i,{lang:a,theme:l?"github-dark":"github-light"}),u=[];for(let e=0;e<d.tokens.length;e++)if(u[e]=(0,s.b8)(d.tokens[e]),e%500==0&&e>0&&(await new Promise(e=>setTimeout(e,0)),r))return;o({key:c,html:u})}catch(e){console.error("Line highlight error:",e)}})(),()=>{r=!0}},[i,t,l]),d}},60938:(e,t,r)=>{r.d(t,{DZ:()=>c,Ft:()=>x,K9:()=>p,Nn:()=>w,OJ:()=>b,VK:()=>y,YW:()=>m,__:()=>j,dt:()=>v,eA:()=>g,eE:()=>h,gZ:()=>d,mP:()=>i,nM:()=>k,r6:()=>f,r9:()=>u});var n=r(49433),s=r(82680);let o=(e,t={})=>n.tryPromise({try:async()=>{let r=await fetch(e,t.init);if(t.passThroughStatuses&&t.passThroughStatuses.includes(r.status))return await r.json().catch(()=>({}));if(!r.ok){let e;try{e=(await r.json()).error}catch{}throw Error(e||`HTTP ${r.status}`)}return await r.json()},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),l=(e,t)=>n.tryPromise({try:async()=>{let r=await fetch(e,t),n=null;try{n=await r.json()}catch{}return{status:r.status,ok:r.ok,data:n}},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),a=(e,t)=>n.tryPromise({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})}),i=e=>o(`/api/files/init?cwd=${encodeURIComponent(e)}`),c=e=>o(`/api/files/index?cwd=${encodeURIComponent(e)}`),d=(e,t)=>o(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),u=e=>o(`/api/files/recent?cwd=${encodeURIComponent(e)}`),m=(e,t,r)=>a("/api/files/recent",{cwd:e,file:t,...r??{}}),x=(e,t)=>a("/api/files/expanded",{cwd:e,paths:t}),h=(e,t)=>o(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),f=(e,t)=>l(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),p=(e,t)=>l(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),g=e=>o(`/api/files/text?${e.toString()}`),b=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=null;try{r=await t.json()}catch{}return{status:t.status,ok:t.ok,data:r}},catch:e=>new s.uV({message:"POST /api/files/save failed",cause:e})}),v=()=>o("/api/files/clipboard"),j=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/files/clipboard",{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:"POST /api/files/clipboard failed",cause:e})}),w=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/files/paste",{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/files/paste failed",cause:e})}),y=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/files/delete",{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/files/delete failed",cause:e})}),k=e=>o(`/api/file?path=${encodeURIComponent(e)}`)},63048:(e,t,r)=>{r.d(t,{Workspace:()=>K});var n=r(95155),s=r(12115),o=r(79114),l=r(69958),a=r(76288),i=r(83678),c=r(21484),d=r(86957),u=r(83448);let m={"claude-opus-4-6":{label:"Opus 4.6",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"},"claude-opus-4-5-20251101":{label:"Opus 4.5",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#fb923c"},"claude-sonnet-4-6":{label:"Sonnet 4.6",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#3b82f6"},"claude-sonnet-4-5-20250929":{label:"Sonnet 4.5",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#60a5fa"},"claude-haiku-4-5-20251001":{label:"Haiku 4.5",input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}},x={label:"",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#94a3b8"};function h(e){if(m[e])return m[e];let t=e.toLowerCase();return t.includes("opus")?{...x,input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"}:t.includes("haiku")?{...x,input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}:x}function f(e){let t=m[e];return t?t.label:e.replace(/^claude-/,"").replace(/-\d{8}$/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function p(e){return(m[e]??h(e)).color}function g(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 b(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function v({data:e,height:t=200,formatValue:r=g}){let o=(0,s.useRef)(null),l=(0,s.useRef)(null),[a,i]=(0,s.useState)(null),c=(0,s.useRef)([]),d=(0,s.useCallback)(()=>{let n=o.current,s=l.current;if(!n||!s)return;let a=window.devicePixelRatio||1,i=s.getBoundingClientRect().width;n.width=i*a,n.height=t*a,n.style.width=`${i}px`,n.style.height=`${t}px`;let d=n.getContext("2d");d.scale(a,a),d.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))));d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="10px ui-monospace, monospace",d.textAlign="right",d.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+h-t/f*h;d.fillText(r(t),44,s),d.strokeStyle=(p="--border",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),d.lineWidth=.5,d.beginPath(),d.moveTo(50,s),d.lineTo(50+x,s),d.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,l,a,i,c,u;let m=n.data[t];if(m<=0)return;let x=m/f*h,p=8+h-s-x;d.fillStyle=n.color,o=d,l=r,a=p,i=b,u=2,(c=x)<1||(u=Math.min(u,c/2,i/2),o.beginPath(),o.moveTo(l+u,a),o.lineTo(l+i-u,a),o.quadraticCurveTo(l+i,a,l+i,a+u),o.lineTo(l+i,a+c-u),o.quadraticCurveTo(l+i,a+c,l+i-u,a+c),o.lineTo(l+u,a+c),o.quadraticCurveTo(l,a+c,l,a+c-u),o.lineTo(l,a+u),o.quadraticCurveTo(l,a,l+u,a),o.fill()),v.push({x:r,y:p,w:b,h:x,label:e,value:m,dataset:n.label,color:n.color}),s+=x}),d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="9px ui-monospace, monospace",d.textAlign="center",d.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&d.fillText(e,r+b/2,8+h+6)}),c.current=v},[e,t,r]);(0,s.useEffect)(()=>{d();let e=new ResizeObserver(()=>d());return l.current&&e.observe(l.current),()=>e.disconnect()},[d]);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,l=c.current.find(e=>n>=e.x&&n<=e.x+e.w&&s>=e.y&&s<=e.y+e.h);l?i({x:e.clientX-t.left,y:l.y-4,content:`${l.dataset}: ${r(l.value)}`}):i(null)},[r]);return(0,n.jsxs)("div",{ref:l,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)}),a&&(0,n.jsx)("div",{className:"absolute pointer-events-none bg-popover text-popover-foreground text-[10px] px-2 py-1 rounded shadow-lg border border-border whitespace-nowrap z-10",style:{left:a.x,top:a.y,transform:"translate(-50%, -100%)"},children:a.content})]})}function j({hourCounts:e}){let{t}=(0,o.Bd)(),r=Math.max(1,...Object.values(e)),s=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:s.map(s=>{let o=e[String(s)]||0,l=o/r;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:s,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(59, 130, 246, ${.2+.8*l})`:"var(--muted)"}}),s%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:s})]},s)})})]})}function w({isOpen:e,onClose:t}){var r;let l,a,{t:i}=(0,o.Bd)(),[c,m]=(0,s.useState)(null),[x,k]=(0,s.useState)(!0),[N,C]=(0,s.useState)("day"),[S,L]=(0,s.useState)("tokens"),[E,M]=(0,s.useState)("claude");(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>k(!0)),d.t4.runPromiseExit((0,u.Cr)(E)).then(e=>{if("Success"===e._tag){let t=e.value;t.error||queueMicrotask(()=>m(t))}queueMicrotask(()=>k(!1))}))},[e,E]);let T=(0,s.useMemo)(()=>c?.modelUsage?Object.entries(c.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:f(e),color:p(e),usage:t,cost:(r=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):[],[c]),$=(0,s.useMemo)(()=>T.reduce((e,t)=>e+t.cost,0),[T]),P=(0,s.useMemo)(()=>T.map(e=>e.id),[T]),R=(0,s.useMemo)(()=>{let e={};for(let t of T)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[T]),{activityChart:B,tokenChart:F,costChart:I}=(0,s.useMemo)(()=>{let e=c?.dailyActivity||[],t=c?.dailyModelTokens||[];if("day"===N){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:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:"#22c55e"}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:P.map(e=>({label:f(e),data:n.map(t=>t.tokensByModel[e]||0),color:p(e)}))},costChart:{labels:o,datasets:P.map(e=>({label:f(e),data:n.map(t=>(t.tokensByModel[e]||0)*(R[e]||0)),color:p(e)}))}}}if("week"===N){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 l=r.get(s);l.messages+=t.messageCount,l.sessions+=t.sessionCount,l.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:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:P.map(e=>({label:f(e),data:r.map(t=>t.tokensByModel[e]||0),color:p(e)}))},costChart:{labels:n,datasets:P.map(e=>({label:f(e),data:r.map(t=>(t.tokensByModel[e]||0)*(R[e]||0)),color:p(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:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:P.map(e=>({label:f(e),data:r.map(t=>t.tokensByModel[e]||0),color:p(e)}))},costChart:{labels:n,datasets:P.map(e=>({label:f(e),data:r.map(t=>(t.tokensByModel[e]||0)*(R[e]||0)),color:p(e)}))}}},[c,N,P,R,i]);if((0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]),!e)return null;let D=[{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-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-xl 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:["claude","claude2"].map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${E===e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{m(null),M(e)},children:"claude"===e?"Claude":"Claude 2"},e))}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:D.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${N===e.key?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>C(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent 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:x?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(y,{label:i("tokenStats.totalSessions"),value:String(c.totalSessions??0)}),(0,n.jsx)(y,{label:i("tokenStats.totalMessages"),value:g(c.totalMessages??0)}),(0,n.jsx)(y,{label:i("tokenStats.equivalentApiCost"),value:b($),highlight:!0}),(0,n.jsx)(y,{label:i("tokenStats.longestSession"),value:c.longestSession?(l=Math.floor((r=c.longestSession.duration)/36e5),a=Math.floor(r%36e5/6e4),l>0?`${l}h ${a}m`:`${a}m`):"-"}),(0,n.jsx)(y,{label:i("tokenStats.firstUse"),value:c.firstSessionDate?c.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:"#3b82f6"}}),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:"#22c55e"}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(v,{data:B,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"===S?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>L("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===S?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>L("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:T.map(e=>(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: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)(v,{data:"tokens"===S?F:I,height:180,formatValue:"tokens"===S?g:b})})]}),(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:[T.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:g(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:$>0?`${(e.cost/$*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:b(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:g(T.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(T.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(T.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(T.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:b($)})]})]})]})})]}),c.hourCounts&&Object.keys(c.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(j,{hourCounts:c.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function y({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 k=r(8648),N=r(34075),C=r(45048),S=r(38408),L=r(49433),E=r(82680);let M=(e,t)=>L.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok){let e;try{e=(await r.json()).error}catch{}throw Error(e||`HTTP ${r.status}`)}return await r.json()},catch:r=>new E.uV({message:`${t?.method??"GET"} ${e} failed`,cause:r})});function T({skillId:e,onClose:t}){let[r,o]=(0,s.useState)(null),[l,a]=(0,s.useState)(!0),[i,c]=(0,s.useState)("preview");(0,s.useEffect)(()=>{let t=!1;return a(!0),d.t4.runPromiseExit(M(`/api/skills/content?id=${encodeURIComponent(e)}`)).then(e=>{t||("Success"===e._tag?o(e.value):console.error("Failed to load skill content",e.cause),a(!1))}),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),t())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let u=(0,s.useCallback)(async()=>{if(r?.path)try{await navigator.clipboard.writeText(r.path),(0,N.oR)("Path copied","success")}catch{(0,N.oR)("Failed to copy","error")}},[r]);return(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-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-4xl h-[85vh] mx-4 flex flex-col overflow-hidden",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:r?.name?`/${r.name}`:"Skill Preview"}),(0,n.jsx)("button",{onClick:u,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"Copy path",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"})]})})]}),r?.path&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5",children:r.path})]}),(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>c("preview"),className:`px-3 py-1 transition-colors ${"preview"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Preview"}),(0,n.jsx)("button",{onClick:()=>c("source"),className:`px-3 py-1 transition-colors ${"source"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Source"})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors flex-shrink-0",title:"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 overflow-auto",children:l?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"Loading..."}):r&&r.valid?"preview"===i?(0,n.jsx)("div",{className:"px-6 py-4",children:(0,n.jsx)(C.T,{content:r.content})}):(0,n.jsx)(S.XO,{content:r.content,filePath:r.path,className:"min-h-full"}):(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"File cannot be read."})})]})]})}var $=r(88371);function P({isOpen:e,onClose:t}){let[r,o]=(0,s.useState)([]),[l,a]=(0,s.useState)(!1),[i,c]=(0,s.useState)(""),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(null),v=(0,s.useCallback)(async()=>{a(!0);let e=await d.t4.runPromiseExit(M("/api/skills"));"Success"===e._tag?o(e.value):console.error("Failed to load skills",e.cause),a(!1)},[]);(0,s.useEffect)(()=>{e&&v()},[e,v]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key&&!g){if(u){m(!1),h("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,u,g]);let j=(0,s.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):r},[r,i]),w=(0,s.useCallback)(async()=>{let e=x.trim();if(!e)return;p(!0);let t=await d.t4.runPromiseExit(M("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}));if("Success"===t._tag)(0,N.oR)("Skill added","success"),h(""),m(!1),await v(),(0,$.k)();else{let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause,n=r instanceof Error?r.message:"Failed to add skill";(0,N.oR)(n,"error")}p(!1)},[x,v]),y=(0,s.useCallback)(async e=>{"Success"===(await d.t4.runPromiseExit(M(`/api/skills/${encodeURIComponent(e)}`,{method:"DELETE"})))._tag?(o(t=>t.filter(t=>t.id!==e)),(0,$.k)()):(0,N.oR)("Failed to delete","error")},[]),k=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,N.oR)("Path copied","success")}catch{(0,N.oR)("Failed to copy","error")}},[]);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-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-3xl h-[80vh] mx-4 flex flex-col overflow-hidden",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:"Skills"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"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.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsxs)("svg",{className:"w-4 h-4 absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"7",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-4.35-4.35"})]}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"Search skills...",className:"w-full pl-8 pr-3 py-1.5 text-sm border border-border rounded-md bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"})]}),(0,n.jsx)("button",{onClick:()=>m(!0),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 active:scale-95 transition-all",children:"+ Add Skill"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-3 space-y-2",children:l?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:"Loading..."}):0===j.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:0===r.length?'No skills yet. Click "Add Skill" to add one.':"No skills match your search."}):j.map(e=>(0,n.jsx)(R,{skill:e,onPreview:()=>b(e.id),onDelete:()=>y(e.id),onCopyPath:()=>k(e.path)},e.id))})]})]}),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-black/50",onClick:()=>{f||(m(!1),h(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:"Add Skill"}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:"Absolute path to SKILL.md"}),(0,n.jsx)("input",{type:"text",value:x,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"!==e.key||f||w()},placeholder:"/Users/you/.../skills/foo/SKILL.md",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground placeholder-slate-9 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:()=>{m(!1),h("")},disabled:f,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50",children:"Cancel"}),(0,n.jsx)("button",{onClick:w,disabled:f||!x.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:f?"Adding...":"Add"})]})]})]}),g&&(0,n.jsx)(T,{skillId:g,onClose:()=>b(null)})]}):null}function R({skill:e,onPreview:t,onDelete:r,onCopyPath:o}){let[l,a]=(0,s.useState)(!1);return(0,n.jsx)("div",{className:`border border-border rounded-lg p-3 bg-card hover:bg-accent/30 transition-colors ${e.valid?"":"opacity-60"}`,children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"w-9 h-9 flex-shrink-0 flex items-center justify-center rounded-md bg-brand/10 text-brand text-lg",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(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:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,n.jsxs)("span",{className:"font-mono text-sm font-medium text-foreground",children:["/",e.name]}),e.description&&(0,n.jsx)("span",{className:"text-sm text-muted-foreground line-clamp-2",children:e.description}),!e.valid&&(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:"Invalid"})]}),e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 truncate",children:e.argumentHint}),(0,n.jsx)("div",{className:"flex items-center gap-1 mt-1",children:(0,n.jsx)("button",{onClick:o,className:"text-xs text-muted-foreground hover:text-foreground font-mono truncate text-left",title:"Copy path",children:e.path})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:t,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:"Preview",children:(0,n.jsxs)("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 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"})]})}),l?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{a(!1),r()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:"Confirm"}),(0,n.jsx)("button",{onClick:()=>a(!1),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:"Cancel"})]}):(0,n.jsx)("button",{onClick:()=>a(!0),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",title:"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"})})})]})]})})}var B=r(47650);let F=[],I=[];function D(){I.forEach(e=>e())}function A(e){F=F.filter(t=>t.id!==e),D()}function _({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return I.push(t),()=>{I=I.filter(e=>e!==t)}},[]),F}();return 0===t.length?null:(0,B.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)(W,{item:t,onNavigate:e,onRemove:A},t.id))}),document.body)}function W({item:e,onNavigate:t,onRemove:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),c=(0,s.useRef)(void 0),d=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(c.current=setTimeout(d,5e3),()=>clearTimeout(c.current)),[d]);let u=(0,s.useCallback)(()=>{clearTimeout(c.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),m=(0,s.useCallback)(()=>{clearTimeout(c.current)},[]),x=(0,s.useCallback)(()=>{c.current=setTimeout(d,2e3)},[d]);return(0,n.jsxs)("div",{className:`pointer-events-auto bg-card border border-border rounded-lg shadow-lg px-3 py-2.5 min-w-[260px] max-w-[340px] cursor-pointer hover:bg-accent transition-all ${a?"opacity-0 -translate-x-4":"opacity-100 translate-x-0"}`,style:{animation:a?void 0:"slideInLeft 0.3s ease-out"},onClick:u,onMouseEnter:m,onMouseLeave:x,children:[(0,n.jsxs)("div",{className:"flex items-center 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:l("common.done")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},className:"ml-auto 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:"text-xs text-muted-foreground truncate mt-1 ml-6",children:e.message})]})}var z=r(10592),H=r(86359),O=r(80905),q=r(80286);let V=L.tryPromise({try:async()=>{let e=await fetch("/api/projects");if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()},catch:e=>new E.uV({message:"fetch /api/projects failed",cause:e})});function K({initialCwd:e,initialSessionId:t}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)([]),[h,f]=(0,s.useState)(0),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[j,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(!1),[T,$]=(0,s.useState)(null),[R,B]=(0,s.useState)(!1),[I,A]=(0,s.useState)(!1),[W,U]=(0,s.useState)(new Set),J=(0,s.useRef)(new Map),Q=(0,s.useRef)(new Map),X=(0,s.useRef)(new Map),Y=(0,s.useRef)(null),Z=function(e,t){let[r,n]=(0,s.useState)({status:"loading"});return(0,s.useEffect)(()=>{n({status:"loading"});let t=d.t4.runFork(e);return t.addObserver(e=>{z.YW(e,{onSuccess:e=>n({status:"success",data:e}),onFailure:e=>{let t=H.od(e);n({status:"error",error:O.Ru(t)?t.value:e})}})}),()=>{L.runFork(q.G(t))}},t),r}(V,[]);(0,s.useEffect)(()=>{if("success"===Z.status){let e=Z.data;x([...e.projects||[]]),f(e.activeIndex||0),g(e.collapsed||!1),A(!0)}else"error"===Z.status&&(console.error("Failed to load projects:",Z.error),A(!0))},[Z]);let G=(0,s.useCallback)(async(e,t,n)=>{let s,{Effect:o}=await r.e(9012).then(r.bind(r,49012)),{BrowserRuntime:l}=await r.e(7562).then(r.bind(r,47562)),a=await l.runPromise((s={projects:e,activeIndex:t,collapsed:n},L.tryPromise({try:async()=>{let e=await fetch("/api/projects",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(s)});if(!e.ok)throw Error(`HTTP ${e.status}`)},catch:e=>new E.uV({message:"save /api/projects failed",cause:e})})).pipe(o.either));"Left"===a._tag&&console.error("Failed to save projects:",a.left)},[]);(0,s.useEffect)(()=>{let e=m[h]?.cwd;e&&U(t=>t.has(e)?t:new Set(t).add(e))},[h,m]),(0,s.useEffect)(()=>{for(let[e,t]of J.current.entries()){let r=m[h]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r},"*")}},[h,m]);let ee=(0,s.useCallback)((e,t)=>{let r=new URL(window.location.href);r.searchParams.set("cwd",e),t?r.searchParams.set("sessionId",t):r.searchParams.delete("sessionId"),window.history.replaceState({},"",r.toString());let n=e.split("/").filter(Boolean).pop();document.title=n?`Cockpit - ${n}`:"Cockpit"},[]),et=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!I||et.current||!e)return;et.current=!0,t&&(Q.current.set(e,{sessionId:t}),X.current.set(e,t));let r=m.findIndex(t=>t.cwd===e);if(r>=0)r!==h&&(f(r),G(m,r,p));else{let t=[...m,{cwd:e}],r=t.length-1;x(t),f(r),G(t,r,p)}ee(e,t)},[I,e,t,m,h,p,G,ee]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="SESSION_CHANGE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:t,sessionId:r}=e.data;X.current.set(t,r);let n=m[h];n?.cwd===t&&ee(t,r)}if(e.data?.type==="SESSION_COMPLETE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:r,sessionId:n,lastUserMessage:s}=e.data,o=m[h];if(o?.cwd!==r){var t;let e;t={projectName:r.split("/").pop()||r,message:s,cwd:r,sessionId:n},e=`session-toast-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,F=[...F,{...t,id:e}],D()}}if(e.data?.type==="OPEN_TOKEN_STATS"&&C(!0),e.data?.type==="OPEN_NOTE"&&e.data?.cwd&&($(e.data.cwd),M(!0)),e.data?.type==="SCREENSHOT_PREPARE"&&e.data?.cwd){Y.current=h;let t=e.data.cwd,r=m.findIndex(e=>e.cwd===t);r>=0&&r!==h&&f(r);return}if(e.data?.type==="SCREENSHOT_DONE"){null!==Y.current&&Y.current!==h&&f(Y.current),Y.current=null;return}if(e.data?.type==="OPEN_PROJECT"&&e.data?.cwd){let{cwd:t,sessionId:r}=e.data,n=r||"";X.current.set(t,n);let s=m.findIndex(e=>e.cwd===t);if(s>=0){if(n){let e=J.current.get(t);e?.contentWindow&&e.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:n},"*")}s!==h&&(f(s),G(m,s,p))}else{let e=[...m,{cwd:t}],r=e.length-1;x(e),f(r),G(e,r,p),n&&Q.current.set(t,{sessionId:n})}ee(t,n)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[m,h,p,ee,G]);let er=(0,s.useCallback)(e=>{f(e),G(m,e,p);let t=m[e];if(t?.cwd){let e=X.current.get(t.cwd);ee(t.cwd,e)}},[m,p,G,ee]),en=(0,s.useCallback)(e=>{let t=m.filter((t,r)=>r!==e),r=h;e<h?r=h-1:e===h&&r>=t.length&&(r=Math.max(0,t.length-1)),x(t),f(r),G(t,r,p)},[m,h,p,G]),es=(0,s.useCallback)(e=>{let t=m[h],r=e.findIndex(e=>e.cwd===t?.cwd);x(e),f(r>=0?r:0),G(e,r>=0?r:0,p)},[m,h,p,G]),eo=(0,s.useCallback)(()=>{let e=!p;g(e),G(m,h,e)},[m,h,p,G]),el=(0,s.useCallback)((e,t)=>{X.current.set(e,t);let r=m.findIndex(t=>t.cwd===e);if(r>=0){let n=J.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),f(r),G(m,r,p)}else{let r=[...m,{cwd:e}],n=r.length-1;x(r),f(n),G(r,n,p),Q.current.set(e,{sessionId:t,switchToAgent:!0})}ee(e,t),v(!1)},[m,p,G,ee]),ea=(0,s.useCallback)((e,t)=>{X.current.set(e,t);let r=m.findIndex(t=>t.cwd===e);if(r>=0){let n=J.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),r!==h&&(f(r),G(m,r,p))}else{let r=[...m,{cwd:e}],n=r.length-1;x(r),f(n),G(r,n,p),Q.current.set(e,{sessionId:t,switchToAgent:!0})}ee(e,t)},[m,h,p,G,ee]),ei=(0,s.useCallback)(e=>{let t=Q.current.get(e);if(t){let r=J.current.get(e);r?.contentWindow&&r.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t.sessionId,switchToAgent:t.switchToAgent},"*"),Q.current.delete(e)}},[]);return I?(0,n.jsxs)("div",{className:"h-screen flex bg-background overflow-hidden",children:[(0,n.jsx)(l.ProjectSidebar,{projects:m,activeIndex:h,collapsed:p,currentCwd:m[h]?.cwd,onSelectProject:er,onRemoveProject:en,onReorderProjects:es,onToggleCollapse:eo,onOpenSessionBrowser:()=>v(!0),onOpenSettings:()=>y(!0),onOpenNote:e=>{$(e??null),M(!0)},onOpenSkills:()=>B(!0),onSwitchProject:ea,onAddProject:e=>{let t=m.findIndex(t=>t.cwd===e);if(t>=0)f(t),G(m,t,p);else{let t=[...m,{cwd:e}],r=t.length-1;x(t),f(r),G(t,r,p)}}}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:0===m.length?(0,n.jsx)(a.EmptyState,{onSelectSession:el}):(0,n.jsx)("div",{className:"flex-1 relative overflow-hidden",children:m.map((e,t)=>W.has(e.cwd)&&(0,n.jsx)("iframe",{ref:t=>{t?J.current.set(e.cwd,t):J.current.delete(e.cwd)},src:`/project?cwd=${encodeURIComponent(e.cwd)}`,onLoad:()=>ei(e.cwd),className:`absolute inset-0 w-full h-full border-0 ${t===h?"block":"hidden"}`,title:`Project: ${e.cwd}`},e.cwd))})}),(0,n.jsx)(i.SessionBrowser,{isOpen:b,onClose:()=>v(!1),onSelectSession:el,onAddProject:e=>{let t=m.findIndex(t=>t.cwd===e);if(t>=0)f(t),G(m,t,p);else{let t=[...m,{cwd:e}],r=t.length-1;x(t),f(r),G(t,r,p)}v(!1)}}),(0,n.jsx)(c.SettingsModal,{isOpen:j,onClose:()=>y(!1)}),(0,n.jsx)(w,{isOpen:N,onClose:()=>C(!1)}),(0,n.jsx)(k.NoteModal,{isOpen:S,onClose:()=>{M(!1),$(null)},projectCwd:T,projectName:T?T.split("/").pop():null}),(0,n.jsx)(P,{isOpen:R,onClose:()=>B(!1)}),(0,n.jsx)(_,{onNavigate:ea})]}):(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:u("workspace.loadingText")})]})})}},63728:(e,t,r)=>{r.d(t,{R8:()=>i,c0:()=>d,fY:()=>c,gT:()=>u});var n=r(95155),s=r(12115);let o=["agent","explorer","console"],l={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},a=(0,s.createContext)(null);function i(){let e=(0,s.useContext)(a);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function c({activeView:e,onViewChange:t,children:r}){let l=(0,s.useRef)(null),i=(0,s.useRef)(!1),d=(0,s.useRef)(0),[u,m]=(0,s.useState)(0),[x,h]=(0,s.useState)(!1),f=o.indexOf(e),p=o.length-1;(0,s.useEffect)(()=>{d.current=0,queueMicrotask(()=>m(0))},[e]),(0,s.useEffect)(()=>{let e=e=>{if(Math.abs(e.deltaX)>Math.abs(e.deltaY)&&Math.abs(e.deltaX)>2){let r=e.target;if("IFRAME"===r.tagName||function(e){for(;e;){let t=window.getComputedStyle(e).overflowX;if(("auto"===t||"scroll"===t)&&e.scrollWidth>e.clientWidth)return!0;e=e.parentElement}return!1}(r))return;e.preventDefault(),e.stopPropagation(),i.current&&(i.current=!1);let n=window.innerWidth,s=d.current-6*e.deltaX;!(f>0)&&s>0&&(s=0),!(f<p)&&s<0&&(s=0),d.current=s=Math.max(-n,Math.min(n,s)),m(s),h(!0),l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{let e=d.current,r=.12*n;h(!1),i.current=!0;let s=f;e<-r&&f<p?s=f+1:e>r&&f>0&&(s=f-1),d.current=0,m(0),s!==f&&t(o[s]),setTimeout(()=>{i.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[f,p,t]);let[g,b]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>b(!0))},[]);let v={activeView:e,onViewChange:t,dragOffset:(()=>{if(!g)return 0;let e=window.innerWidth;return e?u/e:0})(),isDragging:g&&x};return(0,n.jsx)(a.Provider,{value:v,children:r})}function d({children:e}){let t,r,{activeView:l,dragOffset:a,isDragging:c}=i(),u=(0,s.useRef)(null),m=(0,s.useRef)(null),x=o.indexOf(l),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:c?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*o.length}%`,transform:(t=a/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:a}=i(),c=(0,s.useRef)(null),d=(0,s.useRef)([]),[u,m]=(0,s.useState)({left:0,width:0}),x=o.indexOf(e),h=()=>{if(!c.current||0===d.current.length)return{left:0,width:0};let e=c.current.getBoundingClientRect(),t=d.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)),l=Math.floor(s),a=Math.ceil(s),i=s-l,u=t[l],m=t[a];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:c,className:"relative flex gap-4",children:[o.map((e,r)=>(0,n.jsx)("button",{ref:e=>{d.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:l[e]},e)),(0,n.jsx)("div",{className:`absolute bottom-0 h-0.5 bg-brand ${a?"":"transition-all duration-100 ease-out"}`,style:{left:u.left,width:u.width}})]})}},69958:(e,t,r)=>{r.d(t,{ProjectSidebar:()=>p});var n=r(95155),s=r(12115),o=r(79114),l=r(2228);function a({currentCwd:e,onSwitchProject:t,collapsed:r,sessions:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(0),x=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!c)return;let e=e=>{x.current&&!x.current.contains(e.target)&&d(!1)},t=()=>{d(!1)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[c]);let h=(0,s.useCallback)(e=>{t(e.cwd,e.sessionId),d(!1)},[t]),f=l.filter(e=>"loading"===e.status).length,p=l.filter(e=>"unread"===e.status).length,g=(0,s.useCallback)(e=>{let t=Math.floor((u-e)/6e4);if(t<1)return i("common.justNow");if(t<60)return i("common.minutesAgo",{count:t});let r=Math.floor(t/60);return r<24?i("common.hoursAgo",{count:r}):i("common.daysAgo",{count:Math.floor(r/24)})},[i,u]);return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>{m(Date.now()),d(!c)},className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"w-full justify-center":"w-full"}`,title:i("sessions.recentSessions"),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:"M13 10V3L4 14h7v7l9-11h-7z"})}),!r&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:i("sessions.recentSessions")}),f>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-orange-9 animate-pulse ${r?"absolute -top-1 -right-1":""}`,children:f}),p>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-red-500 ${r&&!f?"absolute -top-1 -right-1":""}`,children:p})]}),c&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 h-[450px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:i("sessions.recentSessions")}),f>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-orange-11",children:["(",i("sessions.runningCount",{count:f}),")"]}),p>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-red-500",children:["(",i("sessions.unreadCount",{count:p}),")"]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===l.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("sessions.noSessions")}):l.map((t,r)=>{let s;return(0,n.jsxs)("button",{onClick:()=>h(t),className:`w-full px-3 py-2 text-left hover:bg-accent transition-colors flex items-start gap-2 ${r!==l.length-1?"border-b border-border/50":""} ${e===t.cwd?"bg-accent/50":""}`,children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${"loading"===t.status?"bg-orange-9 animate-pulse":"unread"===t.status?"bg-red-500":"bg-muted-foreground/30"}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",title:t.cwd,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:(s=t.cwd).split("/").pop()||s}),"loading"===t.status&&(0,n.jsx)("span",{className:"text-xs text-orange-11 flex-shrink-0",children:i("sessions.running")}),"unread"===t.status&&(0,n.jsx)("span",{className:"text-xs text-red-500 flex-shrink-0",children:i("sessions.done")}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:g(t.lastActive)})]}),(t.lastUserMessage||t.title)&&(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:t.lastUserMessage||t.title})]})]},`${t.cwd}-${t.sessionId}`)})})]})]})}function i({collapsed:e,pinnedSessions:t,onSwitchProject:r,onUnpin:l,onUpdateTitle:a,onReorder:c}){let{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)(!1),x=(0,s.useRef)(null),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null),[w,y]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!u)return;let e=e=>{x.current&&!x.current.contains(e.target)&&(m(!1),f(null))},t=()=>{m(!1),f(null)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[u]),(0,s.useEffect)(()=>{h&&(b.current?.focus(),b.current?.select())},[h]);let k=(0,s.useCallback)(e=>{h||(r(e.cwd,e.sessionId),m(!1))},[r,h]),N=(0,s.useCallback)((e,t)=>{t.stopPropagation(),f(e.sessionId),g(e.customTitle||"")},[]),C=(0,s.useCallback)(()=>{h&&p.trim()&&a(h,p.trim()),f(null)},[h,p,a]),S=(0,s.useCallback)(e=>{j(e)},[]),L=(0,s.useCallback)((e,t)=>{e.preventDefault(),y(t)},[]),E=(0,s.useCallback)(e=>{if(null===v||v===e){j(null),y(null);return}let r=[...t],[n]=r.splice(v,1);r.splice(e,0,n),c(r),j(null),y(null)},[v,t,c]),M=(0,s.useCallback)(()=>{j(null),y(null)},[]);return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>m(!u),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${e?"w-full justify-center":"w-full"}`,title:d("sessions.pinnedSessions"),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:d("sessions.pinnedSessions")}),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-accent",children:t.length})]}),u&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 max-h-[450px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:d("sessions.pinnedSessions")})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:d("sessions.noPinnedSessions")}):t.map((e,r)=>{let s;return(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>S(r),onDragOver:e=>L(e,r),onDrop:()=>E(r),onDragEnd:M,onClick:()=>k(e),className:`group w-full px-3 py-2 text-left hover:bg-accent transition-colors flex items-start gap-2 cursor-pointer ${r!==t.length-1?"border-b border-border/50":""} ${v===r?"opacity-50":""} ${w===r?"border-t-2 border-brand":""}`,children:[(0,n.jsx)("span",{className:"mt-1.5 text-muted-foreground/30 flex-shrink-0 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",title:e.cwd,children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:(s=e.cwd).split("/").pop()||s})}),h===e.sessionId?(0,n.jsx)("input",{ref:b,type:"text",value:p,onChange:e=>g(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||("Enter"===e.key&&C(),"Escape"===e.key&&f(null))},onBlur:C,onClick:e=>e.stopPropagation(),className:"w-full text-xs px-1 py-0.5 border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring mt-0.5"}):(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:e.customTitle||e.sessionId.slice(0,8)})]}),h!==e.sessionId&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity mt-0.5",children:[(0,n.jsx)("button",{onClick:t=>N(e,t),className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:d("sessions.editTitle"),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:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),l(e.sessionId)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:d("sessions.remove"),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.sessionId)})})]})]})}var c=r(93777);function d(e,t){if("once"===e.type)return t("scheduledTasks.onceType",{minutes:e.delayMinutes});if("interval"===e.type){let r=t("scheduledTasks.everyNMinutes",{minutes:e.intervalMinutes});return e.activeFrom&&e.activeTo?`${r} (${e.activeFrom}-${e.activeTo})`:r}return"cron"===e.type?e.cron||"cron":e.type}function u(e){return e.unread?"bg-red-500":e.completed?"bg-muted-foreground":e.paused?"bg-yellow-500":"error"===e.lastResult?"bg-red-500":"bg-green-500"}function m({collapsed:e,tasks:t,unreadCount:r,onSwitchProject:l,onPause:a,onResume:i,onTrigger:x,onDelete:h,onMarkRead:f,onUpdateTask:p,onReorder:g}){let{t:b}=(0,o.Bd)(),[v,j]=(0,s.useState)(!1),[w,y]=(0,s.useState)(null),k=(0,s.useRef)(null),N=t.filter(e=>!e.completed),C=N.filter(e=>!e.paused).length,S=t.filter(e=>e.completed),[L,E]=(0,s.useState)(null),[M,T]=(0,s.useState)(null),$=(0,s.useCallback)(e=>{E(e)},[]),P=(0,s.useCallback)((e,t)=>{e.preventDefault(),T(t)},[]),R=(0,s.useCallback)(e=>{if(null===L||L===e){E(null),T(null);return}let t=[...N],[r]=t.splice(L,1);t.splice(e,0,r),g([...t,...S].map(e=>e.id)),E(null),T(null)},[L,N,S,g]),B=(0,s.useCallback)(()=>{E(null),T(null)},[]),[,F]=(0,s.useState)(0);return(0,s.useEffect)(()=>{if(!v)return;let e=setInterval(()=>F(e=>e+1),1e4);return()=>clearInterval(e)},[v]),(0,s.useEffect)(()=>{if(!v)return;let e=e=>{k.current&&!k.current.contains(e.target)&&j(!1)},t=()=>j(!1);return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[v]),(0,n.jsxs)("div",{className:"relative",ref:k,children:[(0,n.jsxs)("button",{onClick:()=>j(!v),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${e?"w-full justify-center":"w-full"}`,title:b("scheduledTasks.title"),children:[(0,n.jsxs)("svg",{className:"w-5 h-5 flex-shrink-0",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)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:b("scheduledTasks.title")}),r>0?(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-red-500 ${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-accent",children:t.length}):null]}),v&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-96 max-h-[500px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:b("scheduledTasks.title")}),N.length>0&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[b("scheduledTasks.activeCount",{running:C}),N.length-C>0?` \xb7 ${b("scheduledTasks.pausedCount",{paused:N.length-C})}`:""]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:b("scheduledTasks.noScheduledTasks")}):(0,n.jsxs)(n.Fragment,{children:[N.map((e,t)=>{var r;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>$(t),onDragOver:e=>P(e,t),onDrop:()=>R(t),onDragEnd:B,className:`group px-3 py-2 hover:bg-accent transition-colors border-b border-border/50 cursor-pointer ${e.unread?"bg-brand/5":""} ${L===t?"opacity-50":""} ${M===t?"border-t-2 border-brand":""}`,onClick:()=>{l(e.cwd,e.sessionId),e.unread&&f(e.id),j(!1)},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${u(e)}`}),(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)("span",{className:"text-xs text-muted-foreground font-mono",children:(r=e.cwd).split("/").pop()||r}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"\xb7"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:e.completed?b("scheduledTasks.completed"):e.paused?b("scheduledTasks.paused"):b("common.running")})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5",title:e.message,children:e.message}),(0,n.jsxs)("div",{className:"flex items-center gap-3 mt-1 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{children:d(e,b)}),(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsx)("span",{children:e.paused?b("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,b)}),e.lastFiredAt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsxs)("span",{children:[b("scheduledTasks.lastResult"),": ","success"===e.lastResult?"✓":"✗"]})]})]})]}),(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),x(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-brand",title:b("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(),y(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:b("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"})})}),e.paused?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-green-500",title:b("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(),a(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-yellow-500",title:b("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(),h(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:b("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"})})})]})]})},e.id)}),S.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-muted/30 border-b border-border/50",children:b("scheduledTasks.completedCount",{count:S.length})}),S.map(e=>(0,n.jsx)("div",{className:"group px-3 py-2 hover:bg-accent transition-colors border-b border-border/50 opacity-60 cursor-pointer",onClick:()=>{l(e.cwd,e.sessionId),j(!1)},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${u(e)}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-foreground truncate",children:e.message}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground mt-0.5",children:[d(e,b)," \xb7 ","success"===e.lastResult?b("scheduledTasks.success"):b("scheduledTasks.failure")]})]}),(0,n.jsx)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),h(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:b("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"})})})})]})},e.id))]})]})})]}),w&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/30",onClick:()=>y(null)}),(0,n.jsx)("div",{className:"relative",children:(0,n.jsx)(c.E,{onClose:()=>y(null),onCreate:()=>{},editTask:{id:w.id,message:w.message,type:w.type,delayMinutes:w.delayMinutes,intervalMinutes:w.intervalMinutes,activeFrom:w.activeFrom,activeTo:w.activeTo,cron:w.cron},onUpdate:(e,t)=>{p(e,t),y(null)}})})]})]})}var x=r(3292),h=r(23121),f=r(2111);function p({projects:e,activeIndex:t,collapsed:r,currentCwd:c,onSelectProject:d,onRemoveProject:u,onReorderProjects:g,onToggleCollapse:b,onOpenSessionBrowser:v,onOpenSettings:j,onOpenNote:w,onOpenSkills:y,onSwitchProject:k,onAddProject:N}){let{t:C}=(0,o.Bd)(),{pinnedSessions:S,unpinSession:L,updateTitle:E,reorder:M}=(0,x.P)(),{tasks:T,unreadCount:$,reload:P,pauseTask:R,resumeTask:B,triggerTask:F,deleteTask:I,updateTask:D,markRead:A,reorderTasks:_}=(0,h.n)(),[W,z]=(0,s.useState)(!1),[H,O]=(0,s.useState)(null),[q,V]=(0,s.useState)(null),[K,U]=(0,s.useState)([]),J=(0,s.useRef)(K);(0,s.useEffect)(()=>{J.current=K});let Q=(0,s.useRef)(P);(0,s.useEffect)(()=>{Q.current=P});let X=(0,s.useCallback)(e=>{try{if("task-fired"===e.type)return void Q.current();let{data:t}=e;if(!t)return;U(t.sessions||[])}catch{}},[]);(0,f.h)({url:"/ws/global-state",onMessage:X});let Y=new Set(K.filter(e=>"loading"===e.status).map(e=>e.cwd)),Z=new Set(K.filter(e=>"unread"===e.status).map(e=>e.cwd)),G=(0,s.useCallback)(e=>{O(e)},[]),ee=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==H&&H!==t&&V(t)},[H]),et=(0,s.useCallback)(t=>{if(null!==H&&H!==t){let r=[...e],[n]=r.splice(H,1);r.splice(t,0,n),g(r)}O(null),V(null)},[H,e,g]),er=(0,s.useCallback)(()=>{O(null),V(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:"p-2 border-b border-border relative",onMouseEnter:()=>z(!0),onMouseLeave:()=>z(!1),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-accent transition-colors ${r?"justify-center":""}`,onClick:v,title:C("workspace.openProject"),children:[(0,n.jsxs)("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)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]}),!r&&(0,n.jsx)("span",{className:"text-sm",children:C("workspace.openProject")})]}),W&&(r?(0,n.jsx)("button",{className:"absolute inset-0 m-2 flex items-center justify-center px-2 py-2 rounded-lg bg-accent text-foreground transition-colors z-10",onClick:b,title:C("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-accent text-foreground transition-colors z-10",onClick:b,title:C("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:()=>G(s),onDragOver:e=>ee(e,s),onDrop:()=>et(s),onDragEnd:er,className:`${q===s?"border-t-2 border-brand":""} ${H===s?"opacity-50":""}`,children:(0,n.jsx)(l.ProjectItem,{index:s,name:(a=(o=e.cwd).split("/").filter(Boolean))[a.length-1]||o,cwd:e.cwd,isActive:s===t,collapsed:r,hasUnread:Z.has(e.cwd),isLoading:Y.has(e.cwd),onClick:()=>d(s),onRemove:()=>u(s),onOpenNote:()=>w(e.cwd)})},e.cwd)})}),(0,n.jsxs)("div",{className:"p-2 border-t border-border space-y-1",children:[(0,n.jsx)(a,{currentCwd:c,onSwitchProject:k,collapsed:r,sessions:K}),(0,n.jsx)(i,{collapsed:r,pinnedSessions:S,onSwitchProject:k,onUnpin:L,onUpdateTitle:E,onReorder:M}),(0,n.jsx)(m,{collapsed:r,tasks:T,unreadCount:$,onSwitchProject:k,onPause:R,onResume:B,onTrigger:F,onDelete:I,onMarkRead:A,onUpdateTask:D,onReorder:_}),(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-accent transition-colors ${r?"justify-center":""}`,onClick:()=>w(),title:C("workspace.notes"),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:C("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-accent transition-colors ${r?"justify-center":""}`,onClick:y,title:C("workspace.skills"),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:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:C("workspace.skills")})]}),(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-accent transition-colors ${r?"justify-center":""}`,onClick:j,title:C("workspace.settings"),children:[(0,n.jsxs)("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:"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&&(0,n.jsx)("span",{className:"text-sm",children:C("workspace.settings")})]})]})]})}},70188:(e,t,r)=>{r.d(t,{Ee:()=>m,SU:()=>c,ft:()=>u,iN:()=>d});var n=r(95155),s=r(12115),o=r(79114),l=r(47650),a=r(34075);let i=(0,s.createContext)(null);function c({container:e,children:t}){return(0,n.jsx)(i.Provider,{value:e,children:t})}function d(){return(0,s.useContext)(i)}function u({x:e,y:t,path:r,cwd:c,isDirectory:d,onClose:m,onCreateFile:x,onDelete:h,onRefresh:f,onCopyFile:p,onPaste:g}){let{t:b}=(0,o.Bd)(),v=(0,s.useRef)(null),j=(0,s.useContext)(i),w=r.split("/").pop()||r,y=`${c}/${r}`,k=r.includes("/")?r.substring(0,r.lastIndexOf("/")):"",N=k?`${c}/${k}`:c,C=d?r:k,S=d?y:N;(0,s.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&m()},t=e=>{"Escape"===e.key&&m()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[m]);let[L,E]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(v.current&&j){let r=j.getBoundingClientRect(),n=v.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s=Math.min(s,r.width-n.width-8),o=Math.min(o,r.height-n.height-8),E({x:s=Math.max(8,s),y:o=Math.max(8,o)})}else if(v.current){let r=v.current.getBoundingClientRect();E({x:Math.max(8,Math.min(e,window.innerWidth-r.width-8)),y:Math.max(8,Math.min(t,window.innerHeight-r.height-8))})}},[e,t,j]);let M=(0,s.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),(0,a.oR)(b("toast.copiedName",{name:t}),"success")}catch{(0,a.oR)(b("toast.copyFailed"),"error")}m()},[m,b]),T=d?r:k,$=[{label:b("fileContextMenu.copyRelativePath"),value:r},{label:b("fileContextMenu.copyAbsolutePath"),value:y},{label:b("fileContextMenu.copyRelativeDirPath"),value:C||"."},{label:b("fileContextMenu.copyAbsoluteDirPath"),value:S},{label:d?b("fileContextMenu.copyFolderName"):b("fileContextMenu.copyFileName"),value:w}],P=(0,n.jsxs)("div",{ref:v,className:"absolute z-[200] bg-card border border-border rounded-lg shadow-lg py-1 w-fit whitespace-nowrap",style:{left:L.x,top:L.y},children:[x&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),x(T)},children:b("fileContextMenu.createFile")}),p&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),p(r)},children:d?b("fileContextMenu.copyFolder"):b("fileContextMenu.copyFile")}),g&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),g(T)},children:b("fileContextMenu.pasteHere")}),h&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-destructive hover:bg-accent transition-colors",onClick:()=>{m(),h(r,d,w)},children:d?b("fileContextMenu.deleteFolder"):b("fileContextMenu.deleteFile")}),(x||h||p||g)&&(0,n.jsx)("div",{className:"my-1 border-t border-border"}),$.map((e,t)=>(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>M(e.value,e.label),children:e.label},t))]});return j?(0,l.createPortal)(P,j):P}function m(){let[e,t]=(0,s.useState)(null);return{contextMenu:e,showContextMenu:(0,s.useCallback)((e,r,n)=>{e.preventDefault(),e.stopPropagation(),t({x:e.clientX,y:e.clientY,path:r,isDirectory:n})},[]),hideContextMenu:(0,s.useCallback)(()=>{t(null)},[])}}},75346:(e,t,r)=>{r.d(t,{n:()=>s});var n=r(88292);let s={SessionChange:(0,n.R)("session-change"),ViewChange:(0,n.R)("view-change"),OpenNote:(0,n.R)("open-note"),LangChange:(0,n.R)("lang-change"),TabAdd:(0,n.R)("tab-add"),TabClose:(0,n.R)("tab-close"),SwitchSession:(0,n.R)("switch-session"),ProjectChange:(0,n.R)("project-change"),OpenProject:(0,n.R)("open-project"),SessionComplete:(0,n.R)("session-complete"),OpenTokenStats:(0,n.R)("open-token-stats"),PinnedSessionsChanged:(0,n.R)("pinned-sessions-changed"),ScheduledTasksChanged:(0,n.R)("scheduled-tasks-changed"),ScreenshotPrepare:(0,n.R)("screenshot-prepare"),ScreenshotDone:(0,n.R)("screenshot-done")}},76043:(e,t,r)=>{r.d(t,{NoteToolbar:()=>a});var n=r(95155),s=r(12115),o=r(79114);function l({editor:e,onClose:t,position:r}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)(()=>e.getAttributes("link").href||""),d=(0,s.useRef)(null);(0,s.useEffect)(()=>{d.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-lg p-2 flex items-center gap-2`,style:m,children:[(0,n.jsx)("input",{ref:d,type:"text",value:i,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),u()):"Escape"===e.key&&(e.preventDefault(),t())},placeholder:a("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:a("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-500 hover:bg-red-500/10 transition-colors",title:a("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 a({editor:e}){let{t}=(0,o.Bd)(),[r,i]=(0,s.useState)(!1),c=(0,s.useRef)(null),[,d]=(0,s.useState)(0);if((0,s.useEffect)(()=>{if(!e)return;let t=()=>d(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-accent"}`,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:c,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)(l,{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-500 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-500 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-500 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-500 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:()=>i});var n=r(95155),s=r(12115),o=r(79114),l=r(86957),a=r(76900);function i({onSelectSession:e}){let{t}=(0,o.Bd)(),[r,c]=(0,s.useState)([]),[d,u]=(0,s.useState)({}),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useCallback)(async()=>{x(!0),f(null),u({});let e=await l.t4.runPromiseExit((0,a.H7)());"Success"===e._tag?c(e.value):f("Failed to load projects"),x(!1)},[]),j=(0,s.useCallback)(async e=>{u(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await l.t4.runPromiseExit((0,a.QW)(e));"Success"===t._tag?u(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):u(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),w=(0,s.useCallback)(e=>{let t=d[e];t?.isExpanded?u(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?u(t=>({...t,[e]:{...t[e],isExpanded:!0}})):j(e)},[d,j]);return(0,s.useEffect)(()=>{v(),setTimeout(()=>{b.current?.focus()},100)},[v]),(0,n.jsxs)("div",{className:"flex-1 flex flex-col bg-card",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-lg font-medium text-foreground",children:t("workspace.selectProject")}),(0,n.jsx)("input",{ref:b,type:"text",placeholder:t("workspace.searchProjectPath"),value:p,onChange:e=>g(e.target.value),className:"px-3 py-1.5 text-sm border border-border rounded-lg bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[m&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm 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:t("workspace.loadingProjects")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)("div",{className:"text-sm text-red-500",children:h})}),!m&&!h&&0===r.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:t("workspace.projectNotFound")})}),!m&&!h&&(0,n.jsx)("div",{className:"space-y-2",children:r.filter(e=>e.fullPath.toLowerCase().includes(p.toLowerCase())).map(r=>{let s=d[r.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null};return(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>w(r.encodedPath),className:"w-full flex items-center gap-3 p-3 hover:bg-accent transition-colors text-left",children:[(0,n.jsx)("svg",{className:`w-4 h-4 text-muted-foreground transition-transform ${s.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-5 h-5 text-brand",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.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground truncate",children:r.name}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:r.fullPath})]}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground bg-secondary px-2 py-0.5 rounded",children:t("workspace.sessions",{count:r.sessionCount})})]}),s.isExpanded&&(0,n.jsxs)("div",{className:"border-t border-border bg-secondary/30",children:[s.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-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:t("workspace.loadingSessions")})]}),s.error&&(0,n.jsx)("div",{className:"p-3 text-xs text-red-500",children:s.error}),!s.isLoading&&!s.error&&0===s.sessions.length&&(0,n.jsx)("div",{className:"p-3 text-xs text-muted-foreground",children:t("workspace.noSessions")}),!s.isLoading&&!s.error&&s.sessions.map(t=>(0,n.jsxs)("button",{onClick:()=>{e(r.fullPath,(t.path.split("/").pop()||"").replace(".jsonl",""))},className:"w-full flex items-start gap-3 p-3 hover:bg-accent transition-colors text-left border-t border-border first:border-t-0",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground mt-0.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:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-foreground truncate",children:t.title}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:new Date(t.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),t.firstMessages.length>0&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-1 truncate",children:t.firstMessages[0]})]})]},t.path))]})]},r.encodedPath)})})]})]})}},76412:(e,t,r)=>{r.d(t,{TabManagerTopBar:()=>p});var n=r(95155),s=r(12115),o=r(63728),l=r(82032),a=r(34075),i=r(79114),c=r(95045),d=r(75346),u=r(49433),m=r(86957),x=r(53213),h=r(76900);function f({cwd:e,currentBranch:t,onSwitched:r}){let{t:o}=(0,i.Bd)(),[l,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)([]),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(""),y=(0,s.useRef)(null),k=(0,s.useRef)(null),N=(0,s.useCallback)(async()=>{g(!0);let t=await m.t4.runPromiseExit((0,x.r4)(e));if("Success"===t._tag){let e=t.value,r=e.local??[];u([...r,...(e.remote??[]).filter(e=>!r.includes(e.replace(/^origin\//,"")))])}else(0,a.oR)(o("toast.loadBranchFailed"),"error");g(!1)},[e,o]),C=(0,s.useCallback)(()=>{c(!0),w(""),N()},[N]),S=(0,s.useCallback)(()=>{c(!1)},[]);(0,s.useEffect)(()=>{if(!l)return;let e=e=>{y.current&&!y.current.contains(e.target)&&S()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l,S]),(0,s.useEffect)(()=>{l&&setTimeout(()=>k.current?.focus(),50)},[l]);let L=async t=>{v(!0);let n=await m.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")}v(!1)},E=d.filter(e=>e!==t&&e.toLowerCase().includes(j.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:y,children:[(0,n.jsx)("button",{onClick:l?S:C,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent 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"})})}),l&&(0,n.jsxs)("div",{className:"absolute top-full left-0 mt-1 w-64 bg-popover border border-border rounded-lg shadow-lg z-50 overflow-hidden",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:k,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 placeholder:text-muted-foreground",onKeyDown:e=>{"Escape"===e.key&&S()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:p?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:o("common.loading")}):0===E.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:j?o("git.noMatchingBranches"):o("git.noBranches")}):E.map(e=>(0,n.jsx)("button",{onClick:()=>L(e),disabled:b,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function p({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:x,onOpenProjectSessions:g,onOpenAliasManager:b,onBranchSwitched:v}){let{t:j}=(0,i.Bd)();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:j("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,a.oR)(j("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",title:`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,a.oR)(j("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("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:x,className:"flex items-center gap-1.5 px-2 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent 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)(f,{cwd:e,currentBranch:s,onSwitched:()=>v?.()})]})]}),(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)(l.ReviewDropdown,{cwd:e}),(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("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"})})}),e&&(0,n.jsx)("button",{onClick:g,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("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:()=>{t?.cwd&&m.t4.runFork((0,h.em)(t.cwd).pipe(u.orElse(()=>u.void)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M17.583 2.213L12 7.393 6.417 2.213 1 6.17v11.66l5.417 3.957L12 16.607l5.583 5.18L23 17.83V6.17l-5.417-3.957zM6.417 17.83L3 15.33V8.67l3.417-2.5v11.66zm11.166 0V6.17L21 8.67v6.66l-3.417 2.5z"})})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&m.t4.runFork((0,h.Q1)(t.cwd).pipe(u.orElse(()=>u.void)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("tabManagerTopBar.openInCursor"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4.5 2L20.5 12L4.5 22V2Z"})})}),t?.sessionId&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t.sessionId}`;navigator.clipboard.writeText(e).then(()=>{(0,a.oR)(j("toast.copiedCommand",{command:e}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("chat.copyCommandTooltip",{sessionId:t.sessionId}),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:b,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("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,c.F)(d.n.OpenTokenStats,{}),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("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-accent rounded-lg transition-colors",title:j("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}},76900:(e,t,r)=>{r.d(t,{Cq:()=>x,D0:()=>p,DZ:()=>i,H7:()=>h,It:()=>b,Kl:()=>y,M5:()=>a,Or:()=>d,Q1:()=>j,QW:()=>f,Wr:()=>c,Yn:()=>g,b2:()=>w,em:()=>v,zF:()=>m});var n=r(49433),s=r(82680);let o=(e,t)=>n.tryPromise({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)=>o(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=()=>o("/api/settings"),i=e=>o("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>o("/api/version"),d=()=>o("/api/extension/version"),u=e=>e?`/api/note?cwd=${encodeURIComponent(e)}`:"/api/note",m=e=>o(u(e)),x=(e,t)=>l(u(e),{content:t}),h=()=>o("/api/sessions/projects"),f=e=>o(`/api/sessions/projects/${encodeURIComponent(e)}`),p=e=>o(`/api/project-settings?cwd=${encodeURIComponent(e)}`),g=e=>l("/api/project-settings",e),b=()=>o("/api/pick-folder"),v=e=>l("/api/open-vscode",{cwd:e}),j=e=>l("/api/open-cursor",{cwd:e}),w=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),y=e=>l("/api/git/worktree",e)},82292:(e,t,r)=>{function n(e,t){for(let r of e){if(r.path===t)return r;if(r.children){let e=n(r.children,t);if(e)return e}}return null}function s(e,t){if(!e)return"";let r=n(t,e);if(r?.isDirectory)return e;let s=e.split("/");return s.pop(),s.join("/")}function o(e){let t=[];for(let r of e){let e=r.split("/"),n=t;for(let t=0;t<e.length;t++){let r=e[t],s=t===e.length-1,o=e.slice(0,t+1).join("/"),l=n.find(e=>e.name===r);l||(l={name:r,path:o,isDirectory:!s,children:s?void 0:[]},n.push(l)),!s&&l.children&&(n=l.children)}}let r=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>{e.children&&r(e.children)})};return r(t),t}function l(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),n.children&&r(n.children))};return r(e),t}r.d(t,{B_:()=>h,HR:()=>function e(t,r){if(0===r.length)return t;let n=new Map(r.map(e=>[e.path,e]));return t.map(t=>{let r=n.get(t.path);return r&&t.isDirectory?void 0===t.children&&void 0!==r.children?{...t,children:r.children}:void 0!==t.children&&void 0!==r.children?{...t,children:e(t.children,r.children)}:t:t})},KH:()=>d,MB:()=>n,S7:()=>s,fw:()=>u,q3:()=>c,r6:()=>m,tE:()=>x,tW:()=>l,u:()=>i,v3:()=>o});let a=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function i(e){let t=e.split(".").pop()?.toLowerCase();return a.has(t||"")}function c(e,t,r=!1){let n=new Set;if(!t)return n;let s=t.toLowerCase(),o=e=>{if(n.add(e.path),e.children)for(let t of e.children)o(t)},l=(e,t)=>{let a=e.name.toLowerCase(),i=r?a===s:a.includes(s);if(i&&e.children)return o(e),t.forEach(e=>n.add(e)),!0;let c=!1;if(e.children)for(let r of e.children)l(r,[...t,e.path])&&(c=!0);return(!!i||!!c)&&(n.add(e.path),t.forEach(e=>n.add(e)),!0)};for(let t of e)l(t,[]);return n}function d(e,t,r=!1){let n=new Set;if(!t)return n;let s=t.toLowerCase();for(let t of e){let e=t.split("/");for(let t=0;t<e.length;t++){let o=e[t].toLowerCase();if(r?o===s:o.includes(s)){for(let t=0;t<=e.length-1;t++)n.add(e.slice(0,t+1).join("/"));break}}}return n}function u(e){let t=Math.floor(Math.floor((Date.now()-1e3*e)/1e3)/60),r=Math.floor(t/60),n=Math.floor(r/24),s=Math.floor(n/30),o=Math.floor(n/365);return o>0?`${o}y ago`:s>0?`${s}mo ago`:n>0?`${n}d ago`:r>0?`${r}h ago`:t>0?`${t}m ago`:"just now"}function m(e){let t=new Date(e),r=new Date,n=t.getFullYear()===r.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0"),l=String(t.getHours()).padStart(2,"0"),a=String(t.getMinutes()).padStart(2,"0");return n?`${s}-${o} ${l}:${a}`:`${t.getFullYear()}-${s}-${o} ${l}:${a}`}let x=()=>{},h=50},83448:(e,t,r)=>{r.d(t,{Cr:()=>b,JC:()=>u,M5:()=>c,QW:()=>h,Zr:()=>x,an:()=>g,em:()=>i,l1:()=>d,n_:()=>m,qD:()=>p,td:()=>a});var n=r(49433),s=r(82680);let o=(e,t)=>n.tryPromise({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)=>o(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=()=>o("/api/settings"),i=e=>o("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>o("/api/commands"),d=()=>o("/api/skills"),u=e=>l("/api/bash",e),m=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new s.uV({message:"POST /api/session-by-path failed",cause:e})}),x=(e,t)=>l(`/api/session/${encodeURIComponent(e)}/fork`,t),h=e=>o(`/api/sessions/projects/${encodeURIComponent(e)}`),f=()=>n.tryPromise({try:async()=>{let e=await fetch("/api/ollama/models");return 503===e.status?{_tag:"not-running"}:e.ok?{_tag:"ok",models:(await e.json()).models??[]}:{_tag:"error",message:"Failed to fetch models"}},catch:e=>new s.uV({message:"fetch ollama models failed",cause:e})}),p=e=>n.gen(function*(){let t=yield*f();if("not-running"!==t._tag)return t;e&&(yield*n.sync(e));let r=yield*n.tryPromise({try:async()=>{let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json().catch(()=>({}));return 404===e.status?{_tag:"not-installed",message:t.message||"Ollama is not installed"}:e.ok?{_tag:"started"}:{_tag:"error",message:"Failed to start Ollama"}},catch:e=>new s.uV({message:"start ollama failed",cause:e})});if("not-installed"===r._tag)return{_tag:"not-installed",message:r.message};if("error"===r._tag)return{_tag:"error",message:r.message};let o=yield*f();return"not-running"===o._tag?{_tag:"error",message:"Ollama started but cannot fetch models"}:o}),g=e=>o(`/api/file?path=${encodeURIComponent(e)}`),b=e=>o(`/api/claude-stats?engine=${encodeURIComponent(e)}`)},83678:(e,t,r)=>{r.d(t,{SessionBrowser:()=>d});var n=r(95155),s=r(12115),o=r(79114),l=r(95045),a=r(75346),i=r(86957),c=r(76900);function d({isOpen:e,onClose:t,onSelectSession:r,onAddProject:u}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)({}),[v,j]=(0,s.useState)(!1),[w,y]=(0,s.useState)(null),[k,N]=(0,s.useState)(""),C=(0,s.useRef)(null),S=(0,s.useCallback)(async()=>{j(!0),y(null),b({});let e=await i.t4.runPromiseExit((0,c.H7)());"Success"===e._tag?p(e.value):y("Failed to load projects"),j(!1)},[]),L=(0,s.useCallback)(async e=>{b(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await i.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?b(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):b(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),E=(0,s.useCallback)(e=>{let t=g[e];t?.isExpanded?b(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?b(t=>({...t,[e]:{...t[e],isExpanded:!0}})):L(e)},[g,L]);(0,s.useEffect)(()=>{e&&(S(),setTimeout(()=>{C.current?.focus()},100))},[e,S]);let M=(0,s.useCallback)(async()=>{if(x)return;h(!0);let e=await i.t4.runPromiseExit((0,c.It)());"Success"===e._tag&&e.value.folder&&u&&(u(e.value.folder),t()),h(!1)},[x,u,t]);return((0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,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-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-6xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col 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:m("sessions.projectList")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("input",{ref:C,type:"text",placeholder:m("workspace.searchProjectPath"),value:k,onChange:e=>N(e.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),u&&(0,n.jsxs)("button",{onClick:M,disabled:x,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-accent transition-colors disabled:opacity-50",title:m("sessions.openFolder"),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"})}),x?m("sessions.selectingFolder"):m("sessions.openFolder")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent 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 overflow-y-auto p-4",children:[v&&(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:m("workspace.loadingProjects")})]})}),w&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:w})}),!v&&!w&&0===f.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:m("workspace.projectNotFound")})}),!v&&!w&&f.filter(e=>e.fullPath.toLowerCase().includes(k.toLowerCase())).map(e=>{let t=g[e.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null};return(0,n.jsxs)("div",{className:"mb-3",children:[(0,n.jsxs)("button",{onClick:()=>E(e.encodedPath),className:"w-full flex items-center gap-2 p-2 rounded hover:bg-accent 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"})}),(0,n.jsx)("span",{className:"flex-1 text-xs font-medium text-foreground truncate",title: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:m("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:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:t.sessions.map(t=>(0,n.jsxs)("div",{onClick:()=>{var n;let s;return n=e.fullPath,s=(t.path.split("/").pop()||"").replace(".jsonl",""),void(r?r(n,s):(0,l.F)(a.n.OpenProject,{cwd:n,sessionId:s}))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[t.engine&&"claude"!==t.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===t.engine?"bg-orange-500/15 text-orange-11":"ollama"===t.engine?"bg-blue-500/15 text-blue-11":"codex"===t.engine?"bg-green-500/15 text-green-11":"kimi"===t.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:t.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:t.title,children:t.title})]}),(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",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),t.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),t.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},t.path))})]})]},e.encodedPath)})]})]})]}):null}},84310:(e,t,r)=>{r.d(t,{Providers:()=>u});var n=r(95155),s=r(47617),o=r(3238),l=r(34075),a=r(12115),i=r(47650);function c(e){let t=e;for(;t;){let e=t.dataset?.tooltip;if(e)return e;t=t.parentElement}return null}function d(){let[e,t]=(0,a.useState)(null),r=(0,a.useRef)(null);r.current=e;let s=(0,a.useRef)(null),o=(0,a.useRef)(null),[l,d]=(0,a.useState)({left:0,top:0}),[u,m]=(0,a.useState)(!1);return((0,a.useEffect)(()=>m(!0),[]),(0,a.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)return void t({text:o,x:n.clientX,y:n.clientY});e();let l=n.clientX,a=n.clientY;s.current=setTimeout(()=>{t({text:o,x:l,y:a}),s.current=null},300)},o=n=>{if(!r.current)return;let s=c(n.target);if(!s){e(),t(null);return}t({text:s,x:n.clientX,y:n.clientY})},l=()=>{e(),r.current&&t(null)};return document.addEventListener("mouseover",n,!0),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",l),document.addEventListener("mousedown",l),()=>{document.removeEventListener("mouseover",n,!0),document.removeEventListener("mousemove",o),document.removeEventListener("mouseleave",l),document.removeEventListener("mousedown",l),e()}},[]),(0,a.useLayoutEffect)(()=>{if(!e||!o.current)return;let t=o.current.getBoundingClientRect(),r=window.innerWidth,n=window.innerHeight,s=e.x+12,l=e.y+16;s+t.width>r-8&&(s=r-t.width-8),s<8&&(s=8),l+t.height>n-8&&(l=e.y-t.height-8),d({left:s,top:l})},[e]),u&&e)?(0,i.createPortal)((0,n.jsx)("div",{ref:o,className:"fixed z-[9999] px-2 py-1 bg-popover text-popover-foreground text-xs font-mono rounded shadow-lg border border-brand whitespace-nowrap pointer-events-none max-w-[80vw] overflow-hidden text-ellipsis",style:{left:l.left,top:l.top},children:e.text}),document.body):null}function u({children:e}){return(0,n.jsx)(s.I18nProvider,{children:(0,n.jsx)(o.N,{children:(0,n.jsxs)(l.tE,{children:[e,(0,n.jsx)(d,{})]})})})}},88371:(e,t,r)=>{r.d(t,{U:()=>o,k:()=>s});let n="cockpit-skills";function s(){let e="u"<typeof BroadcastChannel?null:new BroadcastChannel(n);if(e)try{e.postMessage({type:"changed"})}finally{e.close()}}function o(e){if("u"<typeof BroadcastChannel)return()=>{};let t=new BroadcastChannel(n),r=t=>{t.data?.type==="changed"&&e()};return t.addEventListener("message",r),()=>{t.removeEventListener("message",r),t.close()}}},89039:(e,t,r)=>{r.d(t,{useTabState:()=>d});var n=r(12115),s=r(41474),o=r(95045),l=r(75346),a=r(49433),i=r(86957),c=r(96472);function d({initialCwd:e,initialSessionId:t,activeView:r}){let u=(0,n.useRef)(!1),m=(0,n.useRef)(!0),x=(0,n.useRef)(r);(0,n.useEffect)(()=>{x.current=r},[r]);let h=(0,s.F)(),f=(0,n.useRef)(h);(0,n.useEffect)(()=>{f.current=h},[h]);let[p,g]=(0,n.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]),[b,v]=(0,n.useState)(p[0].id),[j,w]=(0,n.useState)(new Set),y=(0,n.useRef)(p);(0,n.useEffect)(()=>{y.current=p},[p]);let k=(0,n.useCallback)((t,r)=>{e&&t&&i.t4.runFork((0,c.KJ)(e,t,r).pipe(a.catchAll(()=>a.void)))},[e]),[N,C]=(0,n.useState)(null),[S,L]=(0,n.useState)(null);(0,n.useEffect)(()=>{!e||u.current||(u.current=!0,(async()=>{let r=await i.t4.runPromise((0,c.n8)(e).pipe(a.catchAll(()=>a.succeed(null))));if(r){let n=r.sessions||[],s=r.activeSessionId,o=r.engines||{},l=r.ollamaModels||{},a=r.deepseekModels||{},i=[...n];if(t&&!i.includes(t)&&(i=[t,...i]),i.length>0){let r=i.map((t,r)=>({id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:o[t]||void 0,ollamaModel:l[t]||void 0,deepseekModel:a[t]||void 0})),n=t||s,c=n?i.indexOf(n):-1;c<0&&(c=0);let d=r[c].id;g(r),v(d),setTimeout(()=>{m.current=!1},0)}else m.current=!1}else m.current=!1})())},[e,t]),(0,n.useEffect)(()=>{if(m.current||!e)return;let t=p.map(e=>e.sessionId).filter(e=>!!e),r=p.find(e=>e.id===b),n=r?.sessionId,s={},o={},l={};for(let e of p)e.sessionId&&e.engine&&(s[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(o[e.sessionId]=e.ollamaModel),e.sessionId&&e.deepseekModel&&(l[e.sessionId]=e.deepseekModel);i.t4.runFork((0,c.ej)({cwd:e,sessions:t,activeSessionId:n,engines:s,ollamaModels:o,deepseekModels:l}).pipe(a.tapError(e=>a.sync(()=>console.error("Failed to save sessions:",e))),a.catchAll(()=>a.void)))},[p,b,e]),(0,n.useEffect)(()=>{if(m.current||!e)return;let t=p.find(e=>e.id===b);t?.sessionId&&(0,o.F)(l.n.SessionChange,{cwd:e,sessionId:t.sessionId})},[b,p,e]);let E=(0,n.useCallback)((e,t,r,n,s,o,l=!1)=>{let a={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?`Session ${t.slice(0,6)}...`:"New Chat"),engine:n,ollamaModel:s,deepseekModel:o};g(e=>{if(l)return[...e,a];let t=e.findIndex(e=>e.id===b);if(-1===t)return[...e,a];let r=[...e];return r.splice(t+1,0,a),r}),v(a.id)},[b]),M=(0,n.useCallback)(t=>{g(r=>{let n=r.filter(e=>e.id!==t);if(t===b&&n.length>0&&v(n[n.length-1].id),0===n.length){let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};return v(t.id),[t]}return n})},[b,e]),T=(0,n.useCallback)((t,r)=>{let n=p.find(e=>e.sessionId===t);n?v(n.id):E(e,t,r,void 0,void 0,void 0,!0)},[p,e,E]),$=(0,n.useCallback)(()=>{E(e,void 0,void 0,void 0,void 0,void 0,!0)},[e,E]),P=(0,n.useCallback)(()=>{E(e,void 0,"New Claude 2 Chat","claude2",void 0,void 0,!0)},[e,E]),R=(0,n.useCallback)(()=>{E(e,void 0,"New Codex Chat","codex",void 0,void 0,!0)},[e,E]),B=(0,n.useCallback)(()=>{E(e,void 0,"New Kimi Chat","kimi",void 0,void 0,!0)},[e,E]),F=(0,n.useCallback)(t=>{E(e,void 0,t?`New Ollama (${t})`:"New Ollama Chat","ollama",t,void 0,!0)},[e,E]),I=(0,n.useCallback)((e,t)=>{g(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),D=(0,n.useCallback)(()=>{E(e,void 0,"New DeepSeek Chat","deepseek",void 0,"deepseek-v4-flash",!0)},[e,E]),A=(0,n.useCallback)((e,t)=>{g(r=>r.map(r=>r.id===e?{...r,deepseekModel:t}:r))},[]),_=(0,n.useCallback)((t,r)=>{E(e,t,r)},[e,E]),W=(0,n.useCallback)((e,t)=>{g(r=>{let n=r.find(t=>t.id===e);if(n?.isLoading&&!1===t.isLoading){let r=!x.current||"agent"===x.current;if(e===b&&r&&f.current){let e=n.sessionId||t.sessionId;e&&k(e,"normal")}else w(t=>new Set(t).add(e))}return r.map(r=>r.id===e?{...r,...t}:r)})},[b,k]);(0,n.useEffect)(()=>{(!r||"agent"===r)&&h&&w(e=>{if(!e.has(b))return e;let t=new Set(e);t.delete(b);let r=y.current.find(e=>e.id===b);return r?.sessionId&&(k(r.sessionId,"normal"),i.t4.runFork((0,c.M2)(r.sessionId).pipe(a.catchAll(()=>a.void)))),t})},[r,b,h,k]);let z=(0,n.useCallback)(e=>{v(e),w(t=>{if(!t.has(e))return t;let r=new Set(t);r.delete(e);let n=y.current.find(t=>t.id===e);return n?.sessionId&&(k(n.sessionId,"normal"),i.t4.runFork((0,c.M2)(n.sessionId).pipe(a.catchAll(()=>a.void)))),r})},[k]),H=(0,n.useCallback)(e=>{C(e)},[]),O=(0,n.useCallback)((e,t)=>{e.preventDefault(),null!==N&&N!==t&&L(t)},[N]),q=(0,n.useCallback)(e=>{null!==N&&N!==e&&g(t=>{let r=[...t],[n]=r.splice(N,1);return r.splice(e,0,n),r}),C(null),L(null)},[N]),V=(0,n.useCallback)(()=>{C(null),L(null)},[]),K=p.find(e=>e.id===b);return{tabs:p,activeTabId:b,activeTab:K,unreadTabs:j,dragTabIndex:N,dragOverTabIndex:S,addTab:E,closeTab:M,switchTab:z,handleSelectSession:T,handleNewTab:$,handleNewClaude2Tab:P,handleNewCodexTab:R,handleNewKimiTab:B,handleNewOllamaTab:F,handleNewDeepseekTab:D,handleOpenSession:_,updateTabState:W,updateTabOllamaModel:I,updateTabDeepseekModel:A,handleTabDragStart:H,handleTabDragOver:O,handleTabDrop:q,handleTabDragEnd:V}}},89109:(e,t,r)=>{r.d(t,{f:()=>a});var n=r(95155),s=r(12115),o=r(79114);function l({x:e,y:t,visible:r,container:s,onAddComment:a,onSendToAI:i,onSearch:c,isChatLoading:d}){let{t:u}=(0,o.Bd)(),m=s.getBoundingClientRect(),x=e-m.left,h=Math.max(0,t-m.top-40);return(0,n.jsxs)("div",{className:"floating-toolbar absolute z-[200] flex items-center gap-1.5 bg-card border border-border rounded-lg shadow-xl p-1.5",style:{left:x+8,top:h,visibility:r?"visible":"hidden",pointerEvents:r?"auto":"none"},children:[(0,n.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:a,children:u("floatingToolbar.addComment")}),(0,n.jsx)("button",{className:"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",onClick:i,disabled:d,title:u(d?"comments.aiResponding":"floatingToolbar.sendToAI"),children:u("floatingToolbar.sendToAI")}),c&&(0,n.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:c,children:u("floatingToolbar.search")})]})}let a=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:r,onAddComment:o,onSendToAI:a,onSearch:i,isChatLoading:c}){let[d,u]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>u(e=>e+1)},[t]);let m=(0,s.useMemo)(()=>e.current,[d]);return(0,n.jsx)(l,{x:m?.x??0,y:m?.y??0,visible:!!m,container:r,onAddComment:o,onSendToAI:a,onSearch:i,isChatLoading:c})})},90717:(e,t,r)=>{r.d(t,{$3:()=>u,Cm:()=>d,Gw:()=>h,RP:()=>m,Un:()=>x,zL:()=>c});var n=r(69809),s=r(49433),o=r(86957),l=r(82680),a=r(46456);let i=new Set;function c(e){return i.add(e),()=>i.delete(e)}function d(){i.forEach(e=>e())}async function u(e){let t=await o.t4.runPromiseExit((0,a.lb)(e));if("Success"!==t._tag)throw Error("Failed to fetch comments");let r=t.value.comments??[];if(0===r.length)return[];let n=new Map;for(let e of r)e.selectedText||(n.has(e.filePath)||n.set(e.filePath,[]),n.get(e.filePath).push(e));let i=new Map;await Promise.all(Array.from(n.keys()).map(async t=>{let r=await o.t4.runPromiseExit(s.tryPromise({try:async()=>{let r=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`);return r.ok?await r.json():null},catch:e=>new l.uV({message:`read file text ${t} failed`,cause:e})}));"Success"===r._tag&&r.value&&"string"==typeof r.value.content?i.set(t,r.value.content.split("\n")):"Failure"===r._tag&&console.error(`Failed to read file ${t}:`,r.cause)}));let c=[];for(let e of r){if(e.selectedText){c.push({...e,codeContent:e.selectedText});continue}let t=i.get(e.filePath),r="";if(t){let n=Math.max(0,e.startLine-1),s=Math.min(t.length,e.endLine);r=t.slice(n,s).join("\n")}c.push({...e,codeContent:r})}return c}async function m(e){let t=await o.t4.runPromiseExit((0,a.tj)(e));return"Success"===t._tag?(d(),!0):(console.error("Failed to clear comments:",t.cause),!1)}let x="__chat__";function h(e,t){let r=e.filter(e=>e.filePath===x),s=e.filter(e=>e.filePath!==x),o=[];for(let e of(s.length>0&&(o.push(`${n.A.t("comments.codeRef")}`,""),s.forEach((e,t)=>{o.push(`[${t+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),o.push("```"),o.push(e.codeContent),o.push("```"),e.note&&o.push(n.A.t("comments.note",{content:e.note})),o.push("")})),r)){let t=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");o.push(t),e.note&&o.push(e.note),o.push("")}return o.push(n.A.t("comments.question",{question:t})),o.join("\n")}},93777:(e,t,r)=>{r.d(t,{E:()=>c});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(12786);let i={once:[{labelKey:"scheduledTasks.5minLater",value:5},{labelKey:"scheduledTasks.15minLater",value:15},{labelKey:"scheduledTasks.30minLater",value:30},{labelKey:"scheduledTasks.1hourLater",value:60}],interval:[{labelKey:"scheduledTasks.every15min",value:15},{labelKey:"scheduledTasks.every30min",value:30},{labelKey:"scheduledTasks.every1hour",value:60},{labelKey:"scheduledTasks.every2hours",value:120}],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 * *"}]};function c({onClose:e,onCreate:t,editTask:r,onUpdate:d}){let{t:u}=(0,o.Bd)(),m=!!r,[x,h]=(0,s.useState)(r?.type||"once"),[f,p]=(0,s.useState)(r?.message||""),[g,b]=(0,s.useState)(r?String(r.delayMinutes||r.intervalMinutes||""):""),[v,j]=(0,s.useState)(r?.cron||""),[w,y]=(0,s.useState)(r?.activeFrom||"09:00"),[k,N]=(0,s.useState)(r?.activeTo||"18:00"),[C,S]=(0,s.useState)(!!(r?.activeFrom&&r?.activeTo)),[L,E]=(0,s.useState)(null),M=(0,s.useRef)(null),T=(0,s.useRef)(null);(0,s.useEffect)(()=>{T.current?.focus()},[]),(0,s.useEffect)(()=>{let t=t=>{M.current&&!M.current.contains(t.target)&&e()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[e]);let $=(0,s.useCallback)(()=>{if(!f.trim())return;let n=null;if("once"===x){let e=L||parseInt(g,10);if(!e||e<=0)return;n={message:f.trim(),type:"once",delayMinutes:e}}else if("interval"===x){let e=L||parseInt(g,10);if(!e||e<=0)return;n={message:f.trim(),type:"interval",intervalMinutes:e,...C?{activeFrom:w,activeTo:k}:{}}}else if("cron"===x){let e=L||v.trim();if(!e)return;n={message:f.trim(),type:"cron",cron:e}}n&&(m&&r&&d?d(r.id,n):t(n),e())},[f,x,L,g,v,C,w,k,t,e,m,r,d]);return(0,n.jsxs)("div",{ref:M,className:`w-80 bg-popover border border-border rounded-lg shadow-lg z-50 ${m?"":"absolute bottom-full left-0 mb-2"}`,onKeyDown:t=>{"Escape"===t.key?e():"Enter"===t.key&&(t.metaKey||t.ctrlKey)&&$()},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:m?u("scheduledTasks.editTask"):u("scheduledTasks.createTask")})}),(0,n.jsxs)("div",{className:"p-3 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.sendMessage")}),(0,n.jsx)("textarea",{ref:T,value:f,onChange:e=>p(e.target.value),placeholder:u("scheduledTasks.messagePlaceholder"),rows:2,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring resize-none"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.type")}),(0,n.jsx)("div",{className:"flex gap-1",children:["once","interval","cron"].map(e=>(0,n.jsx)("button",{onClick:()=>{h(e),E(null),b(""),j("")},className:`flex-1 px-2 py-1 text-xs rounded transition-colors ${x===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"once"===e?u("scheduledTasks.once"):"interval"===e?u("scheduledTasks.interval"):"Cron"},e))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.quickSelect")}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-1",children:i[x].map(e=>(0,n.jsx)("button",{onClick:()=>{E(e.value),"cron"===x?j(String(e.value)):b(String(e.value))},className:`px-2 py-1 text-xs rounded border transition-colors ${L===e.value?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:u(e.labelKey)},e.labelKey))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:"cron"===x?u("scheduledTasks.customCron"):u("scheduledTasks.customMinutes")}),"cron"===x?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:v,onChange:e=>{j(e.target.value),E(null)},placeholder:u("scheduledTasks.cronPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring font-mono"}),v.trim()&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:function(e){let t=l.A.t,r=e.trim().split(/\s+/);if(5!==r.length)return null;let[n,s,o,a,i]=r,c={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")},d={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),l=parseInt(n,10);if(isNaN(r)&&"*"!==s||isNaN(l)&&"*"!==n)return null;e="*"===s&&"*"===n?t("cron.everyMinute"):"*"===s?t("cron.everyHourAtMin",{m:l}):"*"===n?t("cron.hourlyEveryMin",{h:r}):`${String(r).padStart(2,"0")}:${String(l).padStart(2,"0")}`;let u=[];if("*"!==a){let e=a.split(",").map(e=>d[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:c[r]||r,b:c[n]||n})}return`${t("cron.weekdayPrefix")}${c[e]||e}`});u.push(e.join(", "))}if(0===u.length&&"*"===o&&"*"===a&&"*"===i)return t("cron.daily",{time:e});return`${u.join(" ")} ${e}`}catch{return null}}(v.trim())||(0,n.jsx)("span",{className:"text-destructive",children:u("scheduledTasks.cronFormat")})})]}):(0,n.jsx)("input",{type:"number",value:g,onChange:e=>{b(e.target.value),E(null)},placeholder:u("scheduledTasks.minutesPlaceholder"),min:1,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]}),"interval"===x&&(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:C,onChange:e=>S(e.target.checked),className:"rounded border-border"}),u("scheduledTasks.limitTimeRange")]}),C&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("input",{type:"time",value:w,onChange:e=>y(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:u("scheduledTasks.to")}),(0,n.jsx)("input",{type:"time",value:k,onChange:e=>N(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:$,disabled:!(f.trim()&&("once"===x||"interval"===x?!!(L||g&&parseInt(g,10)>0):"cron"===x&&!!(L||v.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:m?u("scheduledTasks.saveBtn",{modKey:(0,a.Mu)()}):u("scheduledTasks.createBtn",{modKey:(0,a.Mu)()})})]})]})}},95045:(e,t,r)=>{r.d(t,{F:()=>l});var n=r(49433),s=r(88292),o=r(86957);let l=(e,t)=>{o.t4.runFork(n.flatMap(s.d,r=>r.publish(e,t)))}},96472:(e,t,r)=>{r.d(t,{KJ:()=>a,M2:()=>i,ej:()=>l,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({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})}),l=e=>n.tryPromise({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})}),a=(e,t,r)=>n.tryPromise({try:async()=>{let n=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e}})});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})})}}]);
29
+ ${o}`),G(n,r)}else G(M("chat.executedCommandFailed",{command:s,error:l.cause}),r);return}G(e,r)},[G,t,M]),{isLoadingHistory:er,isLoadingMore:en,hasMoreHistory:es,loadMoreHistory:eo,loadHistoryByCwdAndSessionId:el,loadedSessionId:ea}=function(e,t,r,{cwd:n,initialSessionId:o,onSessionId:l,onTitleChange:a,onTokenUsage:c}){let[d,u]=(0,s.useState)(!1),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(!1),[p,g]=(0,s.useState)(void 0),[b,v]=(0,s.useState)(0),[j,w]=(0,s.useState)(null),y=(0,s.useRef)(a);y.current=a;let k=(0,s.useRef)(c);k.current=c;let N=(0,s.useRef)(void 0),C=(0,s.useRef)(0),S=(0,s.useCallback)(async(e,r,n=!1,s,o)=>{if(n){let e=Date.now();if(e-C.current<5e3)return;C.current=e}n||u(!0);try{let a={cwd:e,sessionId:r,limit:s,beforeTurnIndex:o};n&&N.current&&(a.ifFingerprint=N.current);let c=await i.t4.runPromiseExit(nM(a));if("Success"===c._tag&&c.value){let e=c.value;if(e.notModified)return;e.fingerprint&&(N.current=e.fingerprint),void 0!==e.totalTurns&&v(e.totalTurns),void 0!==e.hasMore&&f(e.hasMore),e.messages&&e.messages.length>0&&(n?t(t=>{let r=e.messages;if(t.length===r.length&&t.length>0&&t[t.length-1].content===r[r.length-1].content)return t;let n=0;for(let e=0;e<Math.min(t.length,r.length)&&t[e].id===r[e].id&&t[e].content===r[e].content;e++)n=e+1;return n===t.length&&n<r.length?[...t,...r.slice(n)]:r}):t(e.messages),w(r)),e.sessionId&&l(e.sessionId),e.title&&y.current?.(e.title),e.usage&&k.current?.({inputTokens:e.usage.input_tokens||0,outputTokens:e.usage.output_tokens||0,cacheCreationInputTokens:e.usage.cache_creation_input_tokens||0,cacheReadInputTokens:e.usage.cache_read_input_tokens||0,totalCostUsd:0})}}catch(e){console.error("Failed to load history by cwd and sessionId:",e)}finally{n||u(!1)}},[t,l]),L=(0,s.useCallback)(async()=>{if(n&&r&&!m&&h){x(!0);try{let s=void 0!==p?p:b-Math.ceil(e.filter(e=>"user"===e.role).length),o=await i.t4.runPromiseExit(nM({cwd:n,sessionId:r,limit:10,beforeTurnIndex:s>0?s:void 0}));if("Success"===o._tag&&o.value){let e=o.value;if(e.messages&&e.messages.length>0){t(t=>[...e.messages,...t]);let n=e.messages.filter(e=>"user"===e.role).length;g(s-n),w(r)}void 0!==e.hasMore&&f(e.hasMore),e.fingerprint&&(N.current=e.fingerprint)}else"Failure"===o._tag&&console.error("Failed to load more history:",o.cause)}finally{x(!1)}}},[n,r,m,h,p,b,e,t]),E=(0,s.useCallback)(async e=>{u(!0);let r=eM.tryPromise({try:async()=>{let t=await fetch(`/api/session/${e}/history`);return t.ok?await t.json():null},catch:e=>new eT.uV({message:"load session history failed",cause:e})}),n=await i.t4.runPromiseExit(r);"Success"===n._tag&&n.value?.messages&&n.value.messages.length>0?(t(n.value.messages),w(e)):"Failure"===n._tag&&console.error("Failed to load history:",n.cause),u(!1)},[t]);return(0,s.useEffect)(()=>{n&&o&&S(n,o,!1,10)},[]),{isLoadingHistory:d,isLoadingMore:m,hasMoreHistory:h,loadMoreHistory:L,loadHistory:E,loadHistoryByCwdAndSessionId:S,loadedSessionId:j}}($,P,R,{cwd:t,initialSessionId:r,onSessionId:B,onTitleChange:w,onTokenUsage:V}),ei=(0,s.useRef)(b);(0,s.useEffect)(()=>{b&&!ei.current&&R&&t&&!Q&&el(t,R,!0,10),ei.current=b},[b,R,t,Q,el]);let ec=X||q;(0,s.useEffect)(()=>{R&&j?.(R)},[R,j]);let ed=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(v?.(Q),ed.current&&!Q&&t&&R){let e;for(let t=$.length-1;t>=0;t--)if("user"===$[t].role&&$[t].content){e=$[t].content.slice(0,100);break}(0,l.F)(a.n.SessionComplete,{cwd:t,sessionId:R,lastUserMessage:e})}ed.current=Q},[Q,v,t]),(0,s.useEffect)(()=>{b&&T?.setIsLoading(Q)},[Q,b,T]),(0,s.useEffect)(()=>{if(e&&T)return T.registerChat(e=>{U.current?.(e)},e),()=>{T.unregisterChat(e)}},[e,T]),(0,s.useEffect)(()=>{e&&b&&T&&T.setActiveTab(e)},[e,b,T]),(0,s.useEffect)(()=>{U.current=et},[et]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&F&&Q&&ee()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[F,Q,ee]);let eu=(0,s.useCallback)(async e=>{let r=ea??R;if(!t||!r)return;let n=await i.t4.runPromiseExit((0,c.Zr)(r,{cwd:t,fromMessageUuid:e}));if("Success"===n._tag&&n.value.newSessionId){let e=n.value.newSessionId;C?C(e,"Fork"):(0,l.F)(a.n.OpenProject,{cwd:t,sessionId:e})}else"Failure"===n._tag&&console.error("Fork failed:",n.cause)},[t,ea,R,C]),em=(0,s.useCallback)(()=>{W(!0)},[]),ex=(0,s.useCallback)(()=>{O(!0)},[]),eh=(0,s.useMemo)(()=>{if(N&&t&&e&&R)return r=>{N({...r,cwd:t,tabId:e,sessionId:R})}},[N,t,e,R]);return(0,n.jsxs)("div",{className:`flex ${p&&g?"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:()=>I(!0),onMouseLeave:()=>I(!1),children:[!p&&(0,n.jsx)(nS,{cwd:t,sessionId:R,onOpenProjectSessions:()=>A(!0),onOpenSessionBrowser:L,onOpenSettings:E}),"ollama"===u&&x&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(n8,{currentModel:m,onModelChange:x})}),"deepseek"===u&&f&&(0,n.jsx)("div",{className:"flex items-center px-3 py-1.5 border-b border-border bg-card/50",children:(0,n.jsx)(n7,{currentModel:h,onModelChange:f})}),er?(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,n.jsx)("span",{className:"text-muted-foreground",children:M("sessions.loadingHistory")})}):(0,n.jsx)(n1,{ref:K,messages:$,isLoading:Q,cwd:t,sessionId:R,engine:u,apiRetryInfo:Z,hasMoreHistory:es,isLoadingMore:en,onLoadMore:eo,onFork:eu,isActive:b,onContentSearch:S}),ec&&(0,n.jsx)(nL,{tokenUsage:ec,rateLimitInfo:Y}),(0,n.jsx)(n6,{onSend:et,disabled:Q,cwd:t,engine:u,onShowGitStatus:y,onShowComments:t?em:void 0,onShowUserMessages:ex,onOpenNote:k,onCreateScheduledTask:eh})]}),!p&&t&&(0,n.jsx)(d,{isOpen:D,onClose:()=>A(!1),cwd:t}),t&&(0,n.jsx)(sr,{isOpen:_,onClose:()=>W(!1),cwd:t}),(0,n.jsx)(nE,{isOpen:H,onClose:()=>O(!1),messages:$,onSelectMessage:e=>{K.current?.scrollToMessage(e)}})]})}function ss({tabId:e,cwd:t,sessionId:r,engine:o,ollamaModel:l,onOllamaModelChange:a,deepseekModel:i,onDeepseekModelChange:c,isActive:d,onStateChange:u,onShowGitStatus:m,onOpenNote:x,onCreateScheduledTask:h,onOpenSession:f,onContentSearch:p}){let g=(0,s.useCallback)(t=>{u(e,{isLoading:t})},[e,u]),b=(0,s.useCallback)(t=>{u(e,{sessionId:t})},[e,u]),v=(0,s.useCallback)(t=>{u(e,{title:t})},[e,u]),j=(0,s.useCallback)(t=>{a?.(e,t)},[e,a]),w=(0,s.useCallback)(t=>{c?.(e,t)},[e,c]);return(0,n.jsx)(sn,{tabId:e,initialCwd:t,initialSessionId:r,engine:o,ollamaModel:l,onOllamaModelChange:j,deepseekModel:i,onDeepseekModelChange:w,hideHeader:!0,hideSidebar:!0,isActive:d,onLoadingChange:g,onSessionIdChange:b,onTitleChange:v,onShowGitStatus:m,onOpenNote:x,onCreateScheduledTask:h,onOpenSession:f,onContentSearch:p})}var so=r(3292),sl=r(23121),sa=r(88292),si=r(76900),sc=r(96472);function sd({initialCwd:e,initialSessionId:t}){let{t:r}=(0,o.Bd)(),[l,c]=(0,s.useState)("agent"),{tabs:u,activeTabId:x,activeTab:h,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,closeTab:b,switchTab:v,handleSelectSession:j,handleNewTab:w,handleNewClaude2Tab:y,handleNewCodexTab:k,handleNewKimiTab:N,handleNewOllamaTab:C,handleNewDeepseekTab:S,handleOpenSession:L,updateTabState:E,updateTabOllamaModel:M,updateTabDeepseekModel:T,handleTabDragStart:$,handleTabDragOver:P,handleTabDrop:R,handleTabDragEnd:B}=(0,nk.useTabState)({initialCwd:e,initialSessionId:t,activeView:l}),{isPinned:F,pinSession:I,unpinSession:D}=(0,so.P)(),{createTask:A}=(0,sl.n)(),_=(0,s.useCallback)(e=>{let t=u.find(t=>t.id===e);return!!t?.sessionId&&F(t.sessionId)},[u,F]),W=(0,s.useCallback)(t=>{let r=u.find(e=>e.id===t);r?.sessionId&&(F(r.sessionId)?D(r.sessionId):I(r.sessionId,r.cwd||e||"",r.title))},[u,F,I,D,e]),[z,H]=(0,s.useState)(!1),[O,q]=(0,s.useState)(!1),[V,K]=(0,s.useState)(!1),[U,J]=(0,s.useState)(null),[Q,X]=(0,s.useState)(!1),[Y,Z]=(0,s.useState)("tree"),[G,ee]=(0,s.useState)(0),[et,er]=(0,s.useState)(null),[en,es]=(0,s.useState)(0);(0,s.useEffect)(()=>{e&&i.t4.runPromiseExit((0,si.D0)(e)).then(e=>{if("Success"===e._tag){let t=e.value.settings;t?.activeView&&c(t.activeView)}})},[e]);let[eo,el]=(0,s.useState)(!1),ea=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{let{active:t}=e.detail;t?(ea.current=l,c("console"),el(!0)):(el(!1),ea.current&&"console"!==ea.current&&c(ea.current),ea.current=null)};return window.addEventListener("cockpit-screenshot-state",e),()=>window.removeEventListener("cockpit-screenshot-state",e)},[l]);let ei=(0,s.useCallback)(t=>{c(t),e&&(i.t4.runFork((0,si.Yn)({cwd:e,settings:{activeView:t}}).pipe(eM.orElse(()=>eM.void))),i.t4.runFork(eM.flatMap(sa.d,r=>r.publish(a.n.ViewChange,{cwd:e,view:t}))))},[e]),ec=(0,s.useCallback)(async()=>{if(!e)return;let t=await i.t4.runPromiseExit((0,si.b2)(e));if("Success"===t._tag){let r=t.value;if(X(!!r.isGitRepo),r.isGitRepo&&r.worktrees&&r.worktrees.length>0){let t=r.worktrees.find(t=>t.path===e);t&&J(t.branch)}}else console.error("Failed to load git info:",t.cause)},[e]);(0,s.useEffect)(()=>{queueMicrotask(()=>ec())},[ec]);let ed=(0,s.useCallback)(e=>{let{data:t}=e;t?.some(e=>"git"===e.type)&&ec()},[ec]);(0,ep.h)({url:`/ws/watch?cwd=${encodeURIComponent(e||"")}`,onMessage:ed,enabled:!!e}),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&!e.shiftKey&&!e.altKey&&("1"===e.key?(e.preventDefault(),ei("agent")):"2"===e.key?(e.preventDefault(),ei("explorer")):"3"===e.key&&(e.preventDefault(),ei("console")))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,s.useEffect)(()=>{let t=t=>{if(t.data?.type==="SWITCH_SESSION"){let{sessionId:r,switchToAgent:n}=t.data;if(r){j(r),n&&ei("agent");let t=u.find(e=>e.sessionId===r);e&&!t?.isLoading&&i.t4.runFork((0,sc.KJ)(e,r,"normal").pipe(eM.orElse(()=>eM.void)))}}};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[j,ei,e,u]);let eu=(0,s.useCallback)(()=>{Z("status"),ee(e=>e+1),ei("explorer")},[ei]),em=(0,s.useCallback)(e=>{er(e),es(e=>e+1),ei("explorer")},[ei]),ex=(0,s.useCallback)(()=>{e&&i.t4.runFork(eM.flatMap(sa.d,t=>t.publish(a.n.OpenNote,{cwd:e})))},[e]);return(0,n.jsx)(nw,{children:(0,n.jsx)(tC.fY,{activeView:l,onViewChange:ei,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)(nN.TabManagerTopBar,{initialCwd:e,activeTab:h,isGitRepo:Q,currentBranch:U,onOpenWorktree:()=>q(!0),onOpenProjectSessions:()=>H(!0),onOpenAliasManager:()=>K(!0),onBranchSwitched:ec}),eo&&(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:"●"}),r("console.screenshotting")]}),e?(0,n.jsxs)(tC.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 flex-col",children:[(0,n.jsx)(nC.TabBar,{tabs:u,activeTabId:x,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,isPinned:_,onTogglePin:W,onSwitchTab:v,onCloseTab:b,onNewTab:w,onNewClaude2Tab:y,onNewCodexTab:k,onNewKimiTab:N,onNewOllamaTab:C,onNewDeepseekTab:S,onDragStart:$,onDragOver:P,onDrop:R,onDragEnd:B}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===x?"block":"hidden"}`,children:(0,n.jsx)(ss,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:M,deepseekModel:e.deepseekModel,onDeepseekModelChange:T,isActive:e.id===x&&"agent"===l,onStateChange:E,onShowGitStatus:eu,onContentSearch:em,onOpenNote:ex,onCreateScheduledTask:A,onOpenSession:L})},e.id))})]})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(m.a9,{children:(0,n.jsx)(tS,{onClose:()=>ei("agent"),cwd:e,initialTab:Y,tabSwitchTrigger:G,initialSearchQuery:et,searchQueryTrigger:en})})}),(0,n.jsx)("div",{className:"w-1/3 h-full overflow-hidden",children:(0,n.jsx)(m.a9,{children:(0,n.jsx)(nv,{cwd:e,tabId:"default",onOpenNote:ex})})})]}):(0,n.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)(nC.TabBar,{tabs:u,activeTabId:x,unreadTabs:f,dragTabIndex:p,dragOverTabIndex:g,isPinned:_,onTogglePin:W,onSwitchTab:v,onCloseTab:b,onNewTab:w,onNewClaude2Tab:y,onNewCodexTab:k,onNewKimiTab:N,onNewDeepseekTab:S,onDragStart:$,onDragOver:P,onDrop:R,onDragEnd:B}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden relative",children:u.map(e=>(0,n.jsx)("div",{className:`h-full ${e.id===x?"block":"hidden"}`,children:(0,n.jsx)(ss,{tabId:e.id,cwd:e.cwd,sessionId:e.sessionId,engine:e.engine,ollamaModel:e.ollamaModel,onOllamaModelChange:M,deepseekModel:e.deepseekModel,onDeepseekModelChange:T,isActive:e.id===x,onStateChange:E,onCreateScheduledTask:A,onOpenSession:L})},e.id))})]})]}),e&&(0,n.jsx)(d,{isOpen:z,onClose:()=>H(!1),cwd:e,onSelectSession:j}),e&&Q&&(0,n.jsx)(tL,{isOpen:O,onClose:()=>q(!1),cwd:e}),V&&(0,n.jsx)(t1,{onClose:()=>K(!1),onSave:()=>K(!1)})]})})})}},37614:(e,t,r)=>{r.d(t,{t:()=>l});var n=r(95155),s=r(12115),o=r(79114);function l({x:e,y:t,comment:r,container:a,onClose:i,onUpdateComment:c,onDeleteComment:d}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(r.content),p=(0,s.useRef)(null),[g,b]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(p.current&&a){let r=a.getBoundingClientRect(),n=p.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s+n.width>r.width-16&&(s=r.width-n.width-16),s<16&&(s=16),o+n.height>r.height-16&&(o=o-n.height-8),o<16&&(o=16),queueMicrotask(()=>b({x:s,y:o}))}},[e,t,a]),(0,s.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&i()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[i]);let v=async()=>{h.trim()&&(await c(r.id,h.trim()),x(!1))},j=async()=>{await d(r.id),i()};return(0,n.jsx)("div",{ref:p,className:"absolute z-[200] w-96 bg-card border border-border rounded-lg shadow-lg overflow-hidden",style:{left:g.x,top:g.y},children:(0,n.jsx)("div",{className:"p-3",children:m?(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("textarea",{value:h,onChange:e=>f(e.target.value),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card resize-none focus:outline-none focus:ring-1 focus:ring-ring",rows:3,autoFocus:!0,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||e.nativeEvent.isComposing||(e.preventDefault(),v()),"Escape"===e.key&&(x(!1),f(r.content))}}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{onClick:()=>{x(!1),f(r.content)},className:"px-2 py-1 text-xs text-muted-foreground hover:text-foreground",children:u("common.cancel")}),(0,n.jsx)("button",{onClick:v,className:"px-2 py-1 text-xs bg-brand text-white rounded hover:bg-brand/90",children:u("common.save")})]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:r.content}),(0,n.jsxs)("div",{className:"mt-2 flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:u("comments.lineRange",{start:r.startLine,end:r.endLine})}),(0,n.jsxs)("div",{className:"flex gap-1",children:[(0,n.jsx)("button",{onClick:()=>x(!0),className:"p-1 rounded hover:bg-accent text-muted-foreground",title:u("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"})})}),(0,n.jsx)("button",{onClick:j,className:"p-1 rounded hover:bg-accent text-muted-foreground hover:text-red-9",title:u("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:"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"})})})]})]})]})})})}},38408:(e,t,r)=>{r.d(t,{Cv:()=>B,XO:()=>F});var n=r(95155),s=r(12115),o=r(79114),l=r(47650),a=r(86957),i=r(60938),c=r(70188),d=r(7320),u=r(56978),m=r(17196),x=r(89109),h=r(37614),f=r(69809),p=r(64428);function g({blame:e,onClick:t}){let{t:r}=(0,o.Bd)(),l=(0,s.useRef)(null),a=(0,s.useRef)(null),i=(0,p.F2)(),c=(0,s.useRef)(!1),d=(0,s.useRef)(!1),u=(0,s.useRef)(null),m=(0,s.useRef)(null),x=(0,s.useRef)(null),h=(0,s.useRef)(e);(0,s.useEffect)(()=>{h.current=e},[e]);let b=(0,s.useRef)(t);(0,s.useEffect)(()=>{b.current=t},[t]);let v=(0,s.useCallback)(()=>{let e,t=a.current,r=l.current;if(!t||!r)return;let n=r.getBoundingClientRect(),s=t.getBoundingClientRect(),o=i?.getBoundingClientRect(),c=o?.left??0,d=o?.top??0,u=o?.width??window.innerWidth,m=o?.height??window.innerHeight,x=n.left-c;x+s.width>u-8&&(x=u-s.width-8),x<8&&(x=8);let h=n.top-d,f=n.bottom-d;(e=h-s.height-4<0?f+4:h-s.height-4)+s.height>m-8&&(e=m-s.height-8),t.style.left=`${x}px`,t.style.top=`${e}px`},[i]),j=(0,s.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null),m.current&&(clearTimeout(m.current),m.current=null),c.current=!1,d.current=!1,a.current&&(a.current.style.display="none"),x.current&&(document.removeEventListener("mousedown",x.current.down),document.removeEventListener("mouseup",x.current.up),x.current=null)},[]),w=(0,s.useCallback)(()=>{let e=a.current;if(!e||c.current)return;c.current=!0,e.style.left="-9999px",e.style.top="-9999px",e.style.display="block",requestAnimationFrame(()=>requestAnimationFrame(v));let t=0,r=0,n=e=>{t=e.clientX,r=e.clientY},s=e=>{if(!(Math.abs(e.clientX-t)>5||Math.abs(e.clientY-r)>5)){let t;t=e.target,a.current?.contains(t)||l.current?.contains(t)||j()}};document.addEventListener("mousedown",n),document.addEventListener("mouseup",s),x.current={down:n,up:s}},[v,j]),y=(0,s.useCallback)(()=>{if(u.current&&clearTimeout(u.current),m.current&&(clearTimeout(m.current),m.current=null),c.current)return;let e=window.getSelection();(!e||e.isCollapsed)&&(u.current=setTimeout(w,500))},[w]),k=(0,s.useCallback)(()=>{u.current&&(clearTimeout(u.current),u.current=null),c.current&&(m.current=setTimeout(()=>{d.current||j()},200))},[j]),N=(0,s.useCallback)(()=>{d.current=!0,m.current&&(clearTimeout(m.current),m.current=null)},[]),C=(0,s.useCallback)(()=>{d.current=!1,j()},[j]),S=(0,s.useCallback)(e=>{e.stopPropagation();let t=window.getSelection();t&&t.toString().length>0&&a.current?.contains(t.anchorNode)||(b.current?.(h.current),j())},[j]);(0,s.useEffect)(()=>()=>j(),[j]);let L=e.message.split("\n")[0]||"",E=e.message.split("\n").slice(1).join("\n").trim();return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("span",{ref:l,className:"select-none text-xs text-muted-foreground/50 ml-6 cursor-default hover:text-muted-foreground/80",onMouseEnter:y,onMouseLeave:k,children:[e.author.split(" ")[0],", ",function(e){let t=f.A.t,r=Math.floor((Date.now()-1e3*e)/1e3);if(r<60)return t("common.justNow");let n=Math.floor(r/60);if(n<60)return t("common.minutesAgo",{count:n});let s=Math.floor(n/60);if(s<24)return t("common.hoursAgo",{count:s});let o=Math.floor(s/24);if(o<30)return t("common.daysAgo",{count:o});let l=Math.floor(o/30);return l<12?t("common.monthsAgo",{count:l}):t("common.yearsAgo",{count:Math.floor(l/12)})}(e.time)," \xb7 ",L]}),(0,n.jsx)(p.ZL,{children:(0,n.jsxs)("div",{ref:a,className:"fixed z-[9999] bg-card border border-border rounded-lg shadow-xl p-3 text-xs text-foreground whitespace-pre-wrap max-w-md select-text",style:{display:"none",minWidth:280,cursor:"text"},"data-inline-blame-tip":"",onMouseEnter:N,onMouseLeave:C,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1.5",children:[(0,n.jsx)("span",{className:"font-mono text-brand",children:e.hash}),(0,n.jsx)("span",{className:"text-muted-foreground",children:e.author}),(0,n.jsx)("span",{className:"text-muted-foreground/60",children:new Date(1e3*e.time).toLocaleString()})]}),(0,n.jsx)("div",{className:"font-medium",children:L}),E&&(0,n.jsx)("div",{className:"mt-1 text-muted-foreground",children:E}),(0,n.jsx)("div",{className:"mt-2 text-[11px] text-brand border-t border-border pt-2 cursor-pointer hover:underline",onClick:S,children:r("codeViewer.clickToViewDetails")})]})})]})}let b=[{bg:"rgba(59, 130, 246, 0.15)",border:"rgb(59, 130, 246)"},{bg:"rgba(16, 185, 129, 0.15)",border:"rgb(16, 185, 129)"},{bg:"rgba(245, 158, 11, 0.15)",border:"rgb(245, 158, 11)"},{bg:"rgba(239, 68, 68, 0.15)",border:"rgb(239, 68, 68)"},{bg:"rgba(168, 85, 247, 0.15)",border:"rgb(168, 85, 247)"},{bg:"rgba(236, 72, 153, 0.15)",border:"rgb(236, 72, 153)"},{bg:"rgba(20, 184, 166, 0.15)",border:"rgb(20, 184, 166)"},{bg:"rgba(249, 115, 22, 0.15)",border:"rgb(249, 115, 22)"}];function v(e,t){let r,n=document.caretRangeFromPoint(e.clientX,e.clientY);if(!n||!t.contains(n.startContainer))return 1;let s=n.startContainer,o=n.startOffset,l=document.createTreeWalker(t,NodeFilter.SHOW_TEXT),a=1;for(;r=l.nextNode();){if(r===s){a+=o;break}a+=r.textContent?.length||0}return a}let j=(0,s.memo)(function({virtualKey:e,lineNum:t,highlightedHtml:r,hasComments:l,firstComment:a,lineCommentsCount:i,isInRange:c,showLineNumbers:d,lineNumChars:u,commentsEnabled:m,virtualItemSize:x,virtualItemStart:h,onCommentBubbleClick:f,onCmdClick:p,onTokenHover:b,onTokenHoverLeave:j,flashLine:w,blameLine:y,showBlameInfo:k,blameAuthorColor:N,isBlameHovered:C,onBlameClick:S,onBlameMouseEnter:L,onBlameMouseLeave:E,inlineBlameData:M,onInlineBlameClick:T,isCursorLine:$,cursorCol:P}){let{t:R}=(0,o.Bd)(),B=(0,s.useMemo)(()=>$&&null!=P?function(e,t){let r=0,n=0;for(;n<e.length;){if("<"===e[n]){let t=e.indexOf(">",n);if(-1!==t){n=t+1;continue}}if(r===t){let t;if("&"===e[n]){let r=e.indexOf(";",n);t=-1!==r&&r-n<10?r+1:n+1}else t=n+1;let r=e.substring(n,t);return e.substring(0,n)+'<span class="vi-char-cursor">'+r+"</span>"+e.substring(t)}if("&"===e[n]){let t=e.indexOf(";",n);n=-1!==t&&t-n<10?t+1:n+1}else n++;r++}return e+'<span class="vi-char-cursor"> </span>'}(r,P):r,[r,$,P]),F=(0,s.useCallback)(e=>{if(!e.metaKey||!p)return;e.preventDefault(),e.stopPropagation();let r=e.currentTarget,n=v(e,r);window.getSelection()?.removeAllRanges(),p(t,n)},[t,p]),I=(0,s.useCallback)(e=>{if(!b||0!==e.buttons)return;let r=window.getSelection();if(r&&!r.isCollapsed)return;let n=e.target;if("SPAN"!==n.tagName||!n.style.color)return;let s=e.currentTarget,o=v(e,s),l=n.getBoundingClientRect();b(t,o,{x:l.left,y:l.bottom+4})},[t,b]),D=(0,s.useCallback)(()=>{y&&S&&S(y)},[y,S]),A=(0,s.useCallback)(e=>{y&&L&&L(y,e)},[y,L]);return(0,n.jsxs)("div",{"data-line":t,style:{position:"absolute",top:0,left:0,width:"100%",height:`${x}px`,transform:`translateY(${h}px)`,backgroundColor:C&&N?N.bg:void 0},className:`flex ${w===t?"flash-line":""} ${$?"vi-cursor-line":""} ${c?"bg-blue-9/20":l?"bg-amber-9/10":"hover:bg-accent/50"}`,children:[(0,n.jsxs)("div",{className:"flex shrink-0 sticky left-0 z-[2] bg-secondary",style:{backgroundColor:C&&N?N.bg:void 0},children:[y&&N&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-1 flex-shrink-0",style:{backgroundColor:N.border}}),(0,n.jsx)("div",{className:"w-48 flex-shrink-0 px-2 flex items-center gap-2 border-r border-border text-muted-foreground cursor-pointer hover:bg-accent/50",onMouseEnter:A,onMouseLeave:E,onClick:D,title:R("codeViewer.clickToViewCommit"),children:k?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"font-medium",style:{color:N.border},children:y.hash}),(0,n.jsx)("span",{className:"truncate flex-1",children:y.author.split(" ")[0]})]}):null})]}),d&&(0,n.jsxs)("span",{className:`flex-shrink-0 flex items-center justify-end gap-0.5 pr-2 select-none border-r border-border font-variant-tabular ${c?"bg-blue-9/30 text-blue-11":"bg-card/50 text-slate-9"}`,children:[m&&l&&a&&(0,n.jsx)("button",{onClick:e=>f(a,e),className:"w-4 h-4 flex items-center justify-center rounded hover:bg-accent text-amber-9",title:R("codeViewer.nComments",{count:i}),children:(0,n.jsx)("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:(0,n.jsx)("path",{fillRule:"evenodd",d:"M18 10c0 3.866-3.582 7-8 7a8.841 8.841 0 01-4.083-.98L2 17l1.338-3.123C2.493 12.767 2 11.434 2 10c0-3.866 3.582-7 8-7s8 3.134 8 7zM7 9H5v2h2V9zm8 0h-2v2h2V9zM9 9h2v2H9V9z",clipRule:"evenodd"})})}),m&&!l&&(0,n.jsx)("span",{className:"w-4"}),(0,n.jsx)("span",{className:"text-right",style:{minWidth:`${u}ch`},children:t})]})]}),(0,n.jsxs)("span",{className:"flex-1 px-3 whitespace-pre select-text",onClick:F,onMouseOver:I,onMouseLeave:j,"data-code-content":!0,children:[(0,n.jsx)("span",{dangerouslySetInnerHTML:{__html:B}}),M&&(0,n.jsx)(g,{blame:M,onClick:T})]})]},e)});var w=r(64702),y=r(1058),k=r(90717),N=r(48347),C=r(27570);function S(e,t,r){let n,s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),o=0;for(;(n=s.nextNode())&&n!==t;)o+=n.textContent.length;return o+r}function L(e,t){let r,n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),s=t,o=null;for(;r=n.nextNode();){o=r;let e=r.textContent.length;if(s<=e)return{node:r,offset:s};s-=e}return o?{node:o,offset:o.textContent.length}:null}var E=r(82292),M=r(34075);let T="white-space:pre;padding:0 12px;min-height:20px;line-height:20px";function $(e){let t=window.getSelection();if(!t?.rangeCount)return null;let r=t.getRangeAt(0),n=r.startContainer;for(;n&&n.parentElement!==e;)n=n.parentElement;if(!n)return null;let s=Array.from(e.children).indexOf(n);if(s<0)return null;let o=document.createRange();return o.selectNodeContents(n),o.setEnd(r.startContainer,r.startOffset),{line:s,offset:o.toString().length}}function P(e,t){let r,n=e.children[t.line];if(!n)return;let s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=t.offset;for(;r=s.nextNode();){let e=r.textContent?.length||0;if(o<=e){let e=window.getSelection(),t=document.createRange();t.setStart(r,o),t.collapse(!0),e?.removeAllRanges(),e?.addRange(t);return}o-=e}let l=window.getSelection(),a=document.createRange();a.selectNodeContents(n),a.collapse(!1),l?.removeAllRanges(),l?.addRange(a)}function R(e){return e.map(e=>`<div style="${T}">${e}</div>`).join("")}let B=(0,s.forwardRef)(function({content:e,filePath:t,showLineNumbers:r=!0,showSearch:f=!0,className:p="",cwd:g,enableComments:v=!1,scrollToLine:B=null,scrollToLineAlign:F="center",onScrollToLineComplete:I,highlightKeyword:D=null,visibleLineRef:A,onCmdClick:_,onTokenHover:W,onTokenHoverLeave:z,onTokenHoverCancel:H,blameLines:O,inlineBlameLines:q,onSelectCommit:V,editable:K=!1,initialMtime:U,onEditorClose:J,onSaved:Q,onEditorStateChange:X,viMode:Y=!1,onContentMutate:Z,onEnterInsertMode:G,onViSave:ee,viStateRef:et,initialCursorLine:er,initialCursorCol:en,onInitialCursorSet:es,onContentSearch:eo},el){let{t:ea}=(0,o.Bd)(),ei=(0,s.useRef)(e),ec=(0,s.useRef)(!1),[ed,eu]=(0,s.useState)(!1),[em,ex]=(0,s.useState)(!1),[eh,ef]=(0,s.useState)(()=>e.split("\n").length),ep=(0,s.useRef)(e.split("\n").length),[eg,eb]=(0,s.useState)({show:!1}),ev=(0,s.useRef)(null),ej=(0,s.useRef)(null),ew=(0,s.useRef)(U),ey=(0,s.useRef)(null),ek=(0,s.useRef)(!1),eN=(0,s.useRef)(!1),{parentRef:eC,containerRef:eS,searchInputRef:eL,floatingToolbarRef:eE,suppressHoverRef:eM,bumpToolbarRef:eT,savedSelectionRef:e$,highlightedLines:eP,isMounted:eR,cmdHeld:eB,flashLine:eF,isSearchVisible:eI,searchQuery:eD,caseSensitive:eA,wholeWord:e_,currentMatchIndex:eW,viewingComment:ez,addCommentInput:eH,sendToAIInput:eO,aiBridge:eq,commentsEnabled:eV,updateComment:eK,deleteComment:eU,lines:eJ,matches:eQ,rowData:eX,virtualizer:eY,commentsByEndLine:eZ,linesWithComments:eG,setIsSearchVisible:e0,setSearchQuery:e1,setCaseSensitive:e2,setWholeWord:e5,setViewingComment:e4,setAddCommentInput:e3,setSendToAIInput:e6,goToNextMatch:e8,goToPrevMatch:e9,handleSearchKeyDown:e7,handleCommentBubbleClick:te,handleToolbarAddComment:tt,handleToolbarSendToAI:tr,handleToolbarSearch:tn,handleCommentSubmit:ts,handleSendToAISubmit:to,getHighlightedLineHtml:tl,suppressMatchScrollRef:ta,inlineBlameLineRef:ti,inlineBlameVersion:tc}=function({content:e,filePath:t,showSearch:r=!0,cwd:n,enableComments:o=!1,scrollToLine:l=null,scrollToLineAlign:a="center",onScrollToLineComplete:i,visibleLineRef:c,onContentSearch:d}){let[x,h]=(0,s.useState)(!1),f=(0,s.useRef)(null),p=(0,s.useRef)(null),g=(0,s.useRef)(null),b=(0,N.r)();(0,s.useEffect)(()=>{h(!0)},[]);let[v,j]=(0,s.useState)(!1),[L,E]=(0,s.useState)(null),M=(0,s.useRef)(null),[T,$]=(0,s.useState)(!1),[P,R]=(0,s.useState)(""),[B,F]=(0,s.useState)(!1),[I,D]=(0,s.useState)(!1),[A,_]=(0,s.useState)(0),[W,z]=(0,s.useState)(0),H=(0,s.useRef)(!1),[O,q]=(0,s.useState)(null),V=(0,s.useRef)(!1),K=(0,s.useRef)(null),[U,J]=(0,s.useState)(null),[Q,X]=(0,s.useState)(null),Y=(0,s.useMemo)(()=>e.split("\n"),[e]),[Z,G]=(0,s.useState)(null);(0,s.useEffect)(()=>{f.current!==Z&&G(f.current)});let ee=o&&!!n,{toolbarRef:et,bumpRef:er,clearToolbar:en}=(0,C.L)({enabled:ee,container:Z,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)return null;let n=parseInt(r.getAttribute("data-line")||"0",10);return!Number.isFinite(n)||n<=0?null:{start:n,end:n}},buildLineSnapshot:({start:e,end:t})=>Y.slice(e-1,t).join("\n")}),es=(0,s.useRef)(null),[eo,el]=(0,s.useState)(0),{comments:ea,addComment:ei,updateComment:ec,deleteComment:ed,refresh:eu}=(0,y._)({cwd:n||"",filePath:t}),em=(0,u.C)(Y,t),ex=(0,s.useMemo)(()=>{let e=new Map;for(let t of ea){let r=t.endLine;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e},[ea]),eh=(0,s.useMemo)(()=>{let e=new Set;for(let t of ea)for(let r=t.startLine;r<=t.endLine;r++)e.add(r);return e},[ea]),ef=(0,s.useMemo)(()=>(0,m.Np)(Y,P,B,I),[Y,P,B,I]);(0,s.useEffect)(()=>{ef.length>0&&_(0)},[ef.length,P,B,I]);let ep=(0,s.useMemo)(()=>{let e=[];for(let t=0;t<Y.length;t++)e.push({type:"code",lineIndex:t});return e},[Y.length]),eg=(0,w.Te)({count:ep.length,getScrollElement:()=>f.current,estimateSize:()=>20,overscan:10});(0,s.useEffect)(()=>{if(!c)return;let e=f.current;if(!e)return;let t=()=>{if(!eg.range)return;let t=e.scrollTop;for(let e of eg.getVirtualItems())if(e.start>=t){let t=ep[e.index];t?.type==="code"&&(c.current=t.lineIndex+1);return}};return e.addEventListener("scroll",t,{passive:!0}),t(),()=>e.removeEventListener("scroll",t)},[c,ep]),(0,s.useEffect)(()=>{let e=e=>{"Meta"===e.key&&j(!0)},t=e=>{"Meta"===e.key&&j(!1)},r=()=>j(!1);return window.addEventListener("keydown",e),window.addEventListener("keyup",t),window.addEventListener("blur",r),()=>{window.removeEventListener("keydown",e),window.removeEventListener("keyup",t),window.removeEventListener("blur",r)}},[]),(0,s.useEffect)(()=>{if(!r)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),$(!0),setTimeout(()=>g.current?.focus(),0)),"Escape"===e.key&&(T?($(!1),R("")):Q?X(null):U?J(null):et.current?en():O&&q(null))},t=p.current;if(t)return t.addEventListener("keydown",e),()=>t.removeEventListener("keydown",e)},[r,T,Q,U,O]),(0,s.useEffect)(()=>{if(H.current){H.current=!1;return}if(ef.length>0&&A>=0&&A<ef.length){let e=ef[A],t=ep.findIndex(t=>"code"===t.type&&t.lineIndex===e.lineIndex);t>=0&&eg.scrollToIndex(t,{align:"center"})}},[A,ef,eg,ep,W]);let eb=(0,s.useCallback)(()=>{0!==ef.length&&(_(e=>(e+1)%ef.length),z(e=>e+1))},[ef.length]),ev=(0,s.useCallback)(()=>{0!==ef.length&&(_(e=>(e-1+ef.length)%ef.length),z(e=>e+1))},[ef.length]),ej=(0,s.useRef)(l);ej.current=l,(0,s.useEffect)(()=>{if(null!==ej.current&&ej.current>0&&ep.length>0){let e=ej.current,t=e-1,r=ep.findIndex(e=>"code"===e.type&&e.lineIndex===t);if(r>=0){let t=()=>{eg.scrollToIndex(r,{align:a}),"center"===a&&(M.current&&clearTimeout(M.current),E(e),M.current=setTimeout(()=>E(null),500)),i?.()};"start"===a?requestAnimationFrame(t):setTimeout(t,150)}}},[l,a,ep.length,eg,i]);let ew=(0,s.useCallback)(e=>{"Enter"===e.key&&(e.preventDefault(),e.shiftKey?ev():eb()),"Escape"===e.key&&($(!1),R(""))},[eb,ev]),ey=(0,s.useCallback)((e,t)=>{ee&&(t.stopPropagation(),q({comment:e,x:t.clientX,y:t.clientY}),en(),J(null),X(null))},[ee,en]);(0,s.useEffect)(()=>{if(!ee)return;let e=f.current,t=!1,r=()=>{t=!0,K.current=null,V.current=!0},n=()=>{t=!1;let e=window.getSelection();if(!e||e.isCollapsed||!e.toString().trim()){V.current=!1;return}let r=e.getRangeAt(0),n=f.current;if(!n||!n.contains(r.commonAncestorContainer))return;let s=r.startContainer,o=r.endContainer,l=(s.nodeType===Node.TEXT_NODE?s.parentElement:s)?.closest("[data-line]"),a=(o.nodeType===Node.TEXT_NODE?o.parentElement:o)?.closest("[data-line]");if(!l||!a)return;let i=parseInt(l.getAttribute("data-line")||"0",10),c=parseInt(a.getAttribute("data-line")||"0",10);i&&c&&(V.current=!0,K.current={startLine:i,startOffset:S(l,r.startContainer,r.startOffset),endLine:c,endOffset:S(a,r.endContainer,r.endOffset)})},s=()=>{if(t)return;let e=window.getSelection();e&&!e.isCollapsed&&e.toString().trim()||(K.current=null,V.current=!1)};return e?.addEventListener("mousedown",r),document.addEventListener("mouseup",n),document.addEventListener("selectionchange",s),()=>{e?.removeEventListener("mousedown",r),document.removeEventListener("mouseup",n),document.removeEventListener("selectionchange",s)}},[ee]),(0,s.useEffect)(()=>{let e=f.current;if(!e)return;let t=t=>{let r,n;if(!e.contains(t.target)){if(t.target.closest?.("[data-inline-blame-tip]"))return;null!==es.current&&(es.current=null,el(e=>e+1));return}let s=window.getSelection();if(s&&!s.isCollapsed&&s.toString().trim())return;let o=(r=t.target,(n=r.closest?.("[data-line]"))?parseInt(n.getAttribute("data-line")||"0",10):null);o!==es.current&&(es.current=o,requestAnimationFrame(()=>el(e=>e+1)))};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]);let ek=(0,s.useCallback)(()=>{let e=et.current;e&&(J({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,et]),eN=(0,s.useCallback)(()=>{let e=et.current;e&&(X({x:e.x,y:e.y,range:e.range,selectedText:e.selectedText,lineSnapshot:e.lineSnapshot}),en())},[en,et]),eC=(0,s.useCallback)(()=>{let e=et.current;if(!e||!d)return;let t=e.selectedText.trim();en(),t&&d(t)},[d,en,et]),eS=(0,s.useCallback)(async e=>{U&&(await ei(U.range.start,U.range.end,e,U.selectedText),J(null))},[U,ei]),eL=(0,s.useCallback)(async e=>{if(Q&&b&&n)try{let r=await (0,k.$3)(n),s=[];for(let e of r)s.push({filePath:e.filePath,startLine:e.startLine,endLine:e.endLine,codeContent:e.codeContent,note:e.content||void 0});s.push({filePath:t,startLine:Q.range.start,endLine:Q.range.end,codeContent:Q.lineSnapshot});let o=(0,k.Gw)(s,e);b.sendMessage(o),await (0,k.RP)(n),eu(),X(null)}catch(e){console.error("Failed to send to AI:",e)}},[Q,b,t,n,eu]),eE=(0,s.useCallback)((e,t,r)=>{let n=Y[e];if(!n)return t;let s=[];if(P&&ef.length>0)for(let t of ef.filter(t=>t.lineIndex===e)){let r=ef[A]?.lineIndex===e&&ef[A]?.startCol===t.startCol;s.push({start:t.startCol,end:t.endCol,cls:r?"hl-cur":"hl-m"})}if(r&&!P&&r.length>=1){let e=r.toLowerCase(),t=n.toLowerCase(),o=0;for(;-1!==(o=t.indexOf(e,o));)s.push({start:o,end:o+r.length,cls:"hl-kw"}),o+=1}if(0===s.length)return t;s.sort((e,t)=>e.start-t.start||e.end-t.end);let o=[],l=0;for(let e of s){if(e.start<l)continue;e.start>l&&o.push((0,m.ZD)(n.substring(l,e.start)));let t=(0,m.ZD)(n.substring(e.start,e.end));o.push(`<span class="${e.cls}">${t}</span>`),l=e.end}if(l<n.length&&o.push((0,m.ZD)(n.substring(l))),t!==(0,m.ZD)(n)){let e=t;for(let t of s){let r=n.substring(t.start,t.end),s=(0,m.ZD)(r),o=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),l=RegExp(`(?<=>)([^<]*?)(${o})`,""),a=`$1<span class="${t.cls}">${s}</span>`,i=e.replace(l,a);i.length>e.length+200||(e=i)}return e}return o.join("")},[P,ef,A,Y]);return{parentRef:f,containerRef:p,searchInputRef:g,floatingToolbarRef:et,suppressHoverRef:V,savedSelectionRef:K,highlightedLines:em,isMounted:x,cmdHeld:v,flashLine:L,isSearchVisible:T,searchQuery:P,caseSensitive:B,wholeWord:I,currentMatchIndex:A,viewingComment:O,bumpToolbarRef:er,addCommentInput:U,sendToAIInput:Q,aiBridge:b,commentsEnabled:ee,comments:ea,updateComment:ec,deleteComment:ed,lines:Y,matches:ef,rowData:ep,virtualizer:eg,commentsByEndLine:ex,linesWithComments:eh,setIsSearchVisible:$,setSearchQuery:R,suppressMatchScrollRef:H,setCaseSensitive:F,setWholeWord:D,setViewingComment:q,setAddCommentInput:J,setSendToAIInput:X,goToNextMatch:eb,goToPrevMatch:ev,handleSearchKeyDown:ew,handleCommentBubbleClick:ey,handleToolbarAddComment:ek,handleToolbarSendToAI:eN,handleToolbarSearch:eC,handleCommentSubmit:eS,handleSendToAISubmit:eL,getHighlightedLineHtml:eE,inlineBlameLineRef:es,inlineBlameVersion:eo}}({content:e,filePath:t,showSearch:f,cwd:g,enableComments:!K&&v,scrollToLine:K?null:B,scrollToLineAlign:K?"center":F,onScrollToLineComplete:K?void 0:I,visibleLineRef:K?void 0:A,onContentSearch:eo}),td=(0,c.iN)(),tu=(0,s.useRef)(null),tm=(0,s.useRef)(null),tx=(0,s.useRef)({line:0,col:0}),th=(0,s.useRef)({line:0,col:0}),tf=function({lines:e,enabled:t,onContentChange:r,onEnterInsert:n,onSave:o,getVisibleLineCount:l,scrollToLine:a,onSearchExecute:i,onSearchNext:c,onSearchPrev:d,onSearchClear:u}){let[m,x]=(0,s.useState)("normal"),[h,f]=(0,s.useState)(-1),[p,g]=(0,s.useState)(0),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(""),[y,k]=(0,s.useState)(""),[N,C]=(0,s.useState)(""),[S,L]=(0,s.useState)(""),E=(0,s.useRef)([]),M=(0,s.useRef)([]),T=(0,s.useRef)([]),$=(0,s.useRef)(null),P=(0,s.useRef)(e);(0,s.useEffect)(()=>{P.current=e}),(0,s.useEffect)(()=>{0!==e.length&&queueMicrotask(()=>f(t=>Math.min(t,e.length-1)))},[e.length]);let R=(0,s.useCallback)((e,t)=>Math.max(0,Math.min(t,Math.max(0,(P.current[e]??"").length-1))),[]),B=(0,s.useRef)(e.length);(0,s.useEffect)(()=>{let t=Math.abs(e.length-B.current);B.current=e.length,t>10&&(queueMicrotask(()=>{f(-1),g(0),v(!1)}),E.current=[],M.current=[],T.current=[])},[e]);let F=(0,s.useCallback)(()=>{$.current&&(clearTimeout($.current),$.current=null),w("")},[]),I=(0,s.useCallback)(()=>{$.current&&clearTimeout($.current),$.current=setTimeout(()=>{w(""),$.current=null},500)},[]),D=(0,s.useCallback)((e,t)=>{E.current.push(t),M.current=[],v(!0),r(e.join("\n"))},[r]),A=(0,s.useCallback)((e,t)=>{let r=Math.max(0,Math.min(e,P.current.length-1));f(r),g(R(r,t??0)),a(r,"auto")},[a,R]),_=(0,s.useCallback)(e=>{f(t=>{let r=Math.max(0,Math.min(t+e,P.current.length-1));return a(r,"auto"),g(e=>Math.max(0,Math.min(e,Math.max(0,(P.current[r]??"").length-1)))),r})},[a]),W=(0,s.useCallback)(()=>{let e=P.current,t=Math.min(h,e.length-1);if(0===e.length)return;let r=e[t];T.current=[r];let n=[...e];n.splice(t,1),0===n.length&&n.push("");let s=Math.min(t,n.length-1);D(n,{lineIndex:t,oldLines:[r],newLines:[],cursorLine:t}),f(s),g(0)},[h,D]),z=(0,s.useCallback)(()=>{let e=P.current,t=Math.min(h,e.length-1);e.length>0&&(T.current=[e[t]])},[h]),H=(0,s.useCallback)(()=>{let e=T.current;if(0===e.length)return;let t=P.current,r=Math.min(h,t.length-1)+1,n=[...t];n.splice(r,0,...e),D(n,{lineIndex:r,oldLines:[],newLines:[...e],cursorLine:h}),f(r),g(0),a(r,"auto")},[h,D,a]),O=(0,s.useCallback)(()=>{let e=P.current,t=Math.min(h,e.length-1),r=e[t];if(!r||0===r.length)return;let n=r.substring(1),s=[...e];s[t]=n,D(s,{lineIndex:t,oldLines:[r],newLines:[n],cursorLine:h})},[h,D]),q=(0,s.useCallback)(()=>{let e=E.current;if(0===e.length)return;let t=e.pop(),n=[...P.current];0===t.newLines.length&&t.oldLines.length>0?n.splice(t.lineIndex,0,...t.oldLines):0===t.oldLines.length&&t.newLines.length>0?(n.splice(t.lineIndex,t.newLines.length),0===n.length&&n.push("")):n.splice(t.lineIndex,t.newLines.length,...t.oldLines),M.current.push(t),r(n.join("\n")),f(Math.min(t.cursorLine,n.length-1)),a(Math.min(t.cursorLine,n.length-1),"auto"),0===e.length&&v(!1)},[r,a]),V=(0,s.useCallback)(()=>{let e=M.current;if(0===e.length)return;let t=e.pop(),n=[...P.current];0===t.newLines.length&&t.oldLines.length>0?(n.splice(t.lineIndex,t.oldLines.length),0===n.length&&n.push("")):0===t.oldLines.length&&t.newLines.length>0?n.splice(t.lineIndex,0,...t.newLines):n.splice(t.lineIndex,t.oldLines.length,...t.newLines),E.current.push(t),v(!0),r(n.join("\n"));let s=t.lineIndex+Math.max(0,t.newLines.length-1);f(Math.min(s,n.length-1)),a(Math.min(s,n.length-1),"auto")},[r,a]),K=(0,s.useCallback)(e=>{let t=P.current,r=Math.min(h,t.length-1);if("o"===e||"O"===e){let n="o"===e?r+1:r,s=[...t];s.splice(n,0,""),D(s,{lineIndex:n,oldLines:[],newLines:[""],cursorLine:h}),r=n,f(n)}x("insert"),n(r,p,e)},[h,p,D,n]),U=(0,s.useCallback)(()=>{x("normal"),F()},[F]),J=(0,s.useCallback)(()=>{x("command"),k("")},[]),Q=(0,s.useCallback)(()=>{x("normal"),k("")},[]),X=(0,s.useCallback)(()=>{x("search"),C("")},[]),Y=(0,s.useCallback)(()=>{x("normal"),C("")},[]),Z=(0,s.useCallback)(e=>{let t=e.trim();if("w"===t){o?.(),x("normal"),k("");return}if("q"===t){x("normal"),k("");return}if("wq"===t){o?.(),x("normal"),k("");return}if("noh"===t||"nohlsearch"===t){u?.(),x("normal"),k("");return}let r=parseInt(t,10);if(!isNaN(r)&&r>0){let e=Math.min(r-1,P.current.length-1);f(e),a(e,"center"),x("normal"),k("");return}x("normal"),k("")},[o,u,a]),G=(0,s.useCallback)(e=>{if(!e){x("normal"),C("");return}L(e),i?.(e),x("normal"),C("")},[i]),ee=(0,s.useCallback)(e=>{if(!t)return!1;let r=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;if("insert"===m)return("Escape"===e.key||!!r)&&(U(),!0);if("command"===m)return!e.isComposing&&("Escape"===e.key||r?Q():"Enter"===e.key?Z(y):"Backspace"===e.key?0===y.length?Q():k(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||k(t=>t+e.key),!0);if("search"===m)return!e.isComposing&&("Escape"===e.key||r?Y():"Enter"===e.key?G(N):"Backspace"===e.key?0===N.length?Y():C(e=>e.slice(0,-1)):1!==e.key.length||e.metaKey||e.ctrlKey||C(t=>t+e.key),!0);if(h<0&&(f(0),g(0)),e.metaKey)return!1;if(e.ctrlKey)return"d"===e.key?(_(Math.max(1,Math.floor(l()/2))),F(),!0):"u"===e.key?(_(-Math.max(1,Math.floor(l()/2))),F(),!0):"r"===e.key&&(V(),F(),!0);let n=e.key,s=j+n;if("g"===s)return w("g"),I(),!0;if("gg"===s)return A(0),F(),!0;if("d"===s)return w("d"),I(),!0;if("dd"===s)return W(),F(),!0;if("y"===s)return w("y"),I(),!0;if("yy"===s)return z(),F(),!0;if(j&&s!==n&&F(),"j"===n||"ArrowDown"===n)return _(1),!0;if("k"===n||"ArrowUp"===n)return _(-1),!0;if("h"===n||"ArrowLeft"===n)return g(e=>Math.max(0,e-1)),!0;if("l"===n||"ArrowRight"===n){let e=Math.max(0,(P.current[h]??"").length-1);return g(t=>Math.min(e,t+1)),!0}if("0"===n)return g(0),!0;if("$"===n)return g(Math.max(0,(P.current[h]??"").length-1)),!0;if("^"===n){let e=(P.current[h]??"").search(/\S/);return g(e>=0?e:0),!0}return"G"===n?(A(P.current.length-1),!0):"x"===n?(O(),!0):"p"===n?(H(),!0):"u"===n?(q(),!0):"i"===n||"a"===n||"I"===n||"A"===n||"o"===n||"O"===n?(K(n),!0):"/"===n?(X(),!0):"n"===n?(c?.(),!0):"N"===n?(d?.(),!0):":"===n?(J(),!0):"Escape"!==n&&1===n.length},[t,m,j,y,N,h,U,K,J,Q,X,Y,Z,G,_,A,l,W,z,H,O,q,V,F,I,c,d]);return{state:{mode:m,cursorLine:h,cursorCol:p,isDirty:b,keyBuffer:j,commandInput:y,searchInput:N,lastSearch:S},handleKeyDown:ee,enterNormal:U,enterInsert:K,setCursorLine:f,setCursorCol:g,setCommandInput:k,setSearchInput:C,setIsDirty:v,clearUndoHistory:(0,s.useCallback)(()=>{E.current=[],M.current=[]},[])}}({lines:eJ,enabled:Y&&!K,onContentChange:e=>{tx.current={line:th.current.line,col:th.current.col},Z?.(e)},onEnterInsert:(e,t,r)=>{let n=t;if("a"===r)n=t+1;else if("A"===r)n=(eJ[e]??"").length;else if("I"===r){let t=(eJ[e]??"").search(/\S/);n=t>=0?t:0}else("o"===r||"O"===r)&&(n=0);tx.current={line:e,col:n},G?.(e)},onSave:ee,getVisibleLineCount:()=>{let e=eC.current;return e?Math.floor(e.clientHeight/20):20},scrollToLine:(e,t)=>{let r=eX.findIndex(t=>"code"===t.type&&t.lineIndex===e);r>=0&&eY.scrollToIndex(r,{align:t||"auto"})},onSearchExecute:e=>{e1(e),e0(!1)},onSearchNext:e8,onSearchPrev:e9,onSearchClear:()=>{e1("")}});(0,s.useEffect)(()=>{et&&(et.current={cursorLine:tf.state.cursorLine,cursorCol:tf.state.cursorCol}),th.current={line:tf.state.cursorLine,col:tf.state.cursorCol}},[et,tf.state.cursorLine,tf.state.cursorCol]);let tp=(0,s.useRef)(null);(0,s.useEffect)(()=>{Y&&!K&&null!=er&&t&&tp.current!==t&&(tp.current=t,tf.setCursorLine(er-1),null!=en&&tf.setCursorCol(en-1),es?.())},[Y,K,er,en,t]),(0,s.useEffect)(()=>{if(!Y||K)return;let e=eS.current;if(!e)return;let t=e=>{let t=e.target;"TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable||tf.handleKeyDown(e)&&(e.preventDefault(),e.stopPropagation())};return e.addEventListener("keydown",t,!0),()=>e.removeEventListener("keydown",t,!0)},[Y,K,tf.handleKeyDown]),(0,s.useEffect)(()=>{if(!Y||K)return;let e=eS.current;e&&"normal"===tf.state.mode&&requestAnimationFrame(()=>{let t=document.activeElement;t&&("TEXTAREA"===t.tagName||"INPUT"===t.tagName||t.isContentEditable)||e.focus()})},[Y,K,tf.state.mode,e]);let tg=(0,s.useCallback)(e=>{if(!Y||K)return;let t=e.target.closest("[data-line]");if(t){let r=parseInt(t.getAttribute("data-line"),10);if(!isNaN(r)){tf.setCursorLine(r-1);let n=t.querySelector("[data-code-content]");if(n){let t=document.caretRangeFromPoint(e.clientX,e.clientY);if(t&&n.contains(t.startContainer)){let e,s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT),o=0;for(;e=s.nextNode();){if(e===t.startContainer){o+=t.startOffset;break}o+=e.textContent?.length||0}let l=eJ[r-1]??"";tf.setCursorCol(Math.max(0,Math.min(o,Math.max(0,l.length-1))))}}}}let r=e.target;if("TEXTAREA"===r.tagName||"INPUT"===r.tagName||r.isContentEditable)return;let n=eS.current;n&&n.focus()},[Y,K,tf.setCursorLine,tf.setCursorCol,eJ]),tb=(0,s.useCallback)(e=>{Y&&!K&&requestAnimationFrame(()=>{let e=window.getSelection(),t=e?.toString().trim();t&&/^\S+$/.test(t)&&(ta.current=!0,e1(t))})},[Y,K,e1,ta]);(0,s.useEffect)(()=>{"command"===tf.state.mode?setTimeout(()=>tu.current?.focus(),0):"search"===tf.state.mode&&setTimeout(()=>tm.current?.focus(),0)},[tf.state.mode]),(0,s.useEffect)(()=>{let e=eC.current;if(!e)return;let t=()=>{(H??z)?.()};return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t)},[H,z]),(0,s.useEffect)(()=>{eH||eO?(eM.current=!0,z?.()):eE.current||(eM.current=!1)},[eH,eO,z]),(0,s.useLayoutEffect)(()=>{let e=e$.current;if(!e)return;let t=window.getSelection();if(t&&!t.isCollapsed)return;let r=eC.current;if(!r)return;let n=r.querySelector(`[data-line="${e.startLine}"]`),s=r.querySelector(`[data-line="${e.endLine}"]`);if(!n||!s)return;let o=L(n,e.startOffset),l=L(s,e.endOffset);if(o&&l)try{let e=document.createRange();e.setStart(o.node,o.offset),e.setEnd(l.node,l.offset),t?.removeAllRanges(),t?.addRange(e)}catch{}});let tv=(0,s.useCallback)((e,t,r)=>{eM.current||W?.(e,t,r)},[W]),tj=(0,s.useCallback)((e,t)=>{eM.current||_?.(e,t)},[_]),tw=Math.max(4,String(K?eh:eJ.length).length),ty=(0,s.useMemo)(()=>{let e=0;for(let t of eJ){let r=0;for(let e=0;e<t.length;e++)" "===t[e]?r+=2-r%2:r+=1;r>e&&(e=r)}return e},[eJ]);(0,s.useEffect)(()=>{if(K){ei.current=e;let t=e.split("\n").length;ep.current=t,ef(t),ec.current=!1,eu(!1),eb({show:!1}),ew.current=U}},[K,e,U]),(0,s.useEffect)(()=>{if(!K)return;let t=ev.current;if(!t)return;let r=e.split("\n");t.innerHTML=R(r.map((e,t)=>eP[t]||(0,m.ZD)(e||" "))),requestAnimationFrame(()=>{let e,n;Y?(e=Math.max(0,Math.min(tx.current.line,r.length-1)),n=tx.current.col):(e=Math.max(0,Math.min((A?.current??1)-1,r.length-1)),n=0),t.focus(),P(t,{line:e,offset:n});let s=A?.current??1;ej.current&&(ej.current.scrollTop=(s-1)*20)})},[K]),(0,s.useEffect)(()=>{K&&X?.({isDirty:ed,isSaving:em})},[K,ed,em,X]);let tk=(0,s.useCallback)(()=>{let e=ev.current;if(!e)return ei.current;let t=[];for(let r of e.childNodes){let e=r.textContent||"";t.push(" "===e?"":e)}return t.join("\n")},[]),tN=(0,s.useCallback)(()=>{ey.current&&clearTimeout(ey.current),ey.current=setTimeout(async()=>{let e=ev.current;if(e&&!eN.current){ei.current=tk();try{let r=await (0,m.kS)(),n=(0,m.sQ)(t),s=document.documentElement.classList.contains("dark"),o=ei.current.split("\n"),l=r.codeToTokens(o.join("\n"),{lang:n,theme:s?"github-dark":"github-light"}).tokens.map(e=>(0,m.b8)(e)),a=$(e);ek.current=!0,e.innerHTML=R(l),ek.current=!1,a&&P(e,a)}catch{}}},300)},[t,tk]);(0,s.useEffect)(()=>{if(K)return()=>{ey.current&&clearTimeout(ey.current)}},[K]);let tC=(0,s.useCallback)(()=>{let e=ev.current;if(!e)return;ec.current||(ec.current=!0,eu(!0));let t=e.children.length;t!==ep.current&&(ep.current=t,ef(t))},[]),tS=(0,s.useCallback)(()=>{ek.current||eN.current||(tC(),tN())},[tC,tN]),tL=(0,s.useCallback)(e=>{if(!e.nativeEvent.isComposing&&("Tab"===e.key&&(e.preventDefault(),document.execCommand("insertText",!1," ")),"Enter"===e.key)){e.preventDefault();let t=ev.current;if(!t)return;let r=window.getSelection();if(!r?.rangeCount)return;let n=r.getRangeAt(0);n.deleteContents();let s=n.startContainer;for(;s&&s.parentElement!==t;)s=s.parentElement;if(!s||!(s instanceof HTMLElement))return;let o=$(t),l=Array.from(t.children).indexOf(s),a=s.textContent||"",i=o?.offset??a.length,c=a.substring(0,i),d=a.substring(i);s.innerHTML=(0,m.ZD)(c||" ");let u=document.createElement("div");u.setAttribute("style",T),u.innerHTML=(0,m.ZD)(d||" "),s.after(u),P(t,{line:l+1,offset:0}),tC(),tN()}},[tC,tN]),tE=(0,s.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData("text/plain");document.execCommand("insertText",!1,t)},[]),tM=(0,s.useCallback)(async(e=!1)=>{if(!g)return;ei.current=tk(),ex(!0);let r=await a.t4.runPromiseExit((0,i.OJ)({cwd:g,path:t,content:ei.current,expectedMtime:e?void 0:ew.current}));if("Failure"===r._tag){console.error("Error saving file:",r.cause),(0,M.oR)(ea("toast.saveFailed"),"error"),ex(!1);return}let n=r.value,s=n.data;if(409===n.status&&s?.conflict){let e=await a.t4.runPromiseExit((0,i.K9)(g,t));"Success"===e._tag&&e.value.ok&&"string"==typeof e.value.data?.content?eb({show:!0,diskContent:e.value.data.content}):eb({show:!0}),ex(!1);return}if(!n.ok){console.error("Error saving file: status",n.status),(0,M.oR)(ea("toast.saveFailed"),"error"),ex(!1);return}let o=s?.mtime;o&&(ew.current=o),ec.current=!1,eu(!1),eb({show:!1}),(0,M.oR)(ea("toast.savedSuccess"),"success"),Q?.(),ex(!1)},[g,t,tk,Q,ea]),tT=(0,s.useCallback)(async()=>{ed&&!em&&await tM(!1)},[ed,em,tM]),t$=(0,s.useCallback)(async()=>{eb({show:!1}),await tM(!0)},[tM]),tP=(0,s.useCallback)(()=>{if(void 0!==eg.diskContent){ei.current=eg.diskContent;let t=eg.diskContent.split("\n").length;ep.current=t,ef(t);let r=eg.diskContent!==e;ec.current=r,eu(r);let n=ev.current;n&&(n.innerHTML=R(eg.diskContent.split("\n").map(e=>(0,m.ZD)(e||" "))),tN())}eb({show:!1}),Q?.()},[eg.diskContent,e,Q,tN]),tR=(0,s.useCallback)(()=>{let e=ej.current;return e?Math.floor(e.scrollTop/20)+1:A?.current??1},[A]),tB=(0,s.useCallback)(async()=>{(!ed||await (0,M.lJ)(ea("codeViewer.unsavedConfirm"),{danger:!0,confirmText:ea("codeViewer.discardChanges"),cancelText:ea("codeViewer.continueEditing")}))&&J?.(tR())},[ed,J,tR]);(0,s.useEffect)(()=>{if(!K)return;let e=e=>{(e.metaKey||e.ctrlKey)&&"s"===e.key&&(e.preventDefault(),tT())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[K,tT]);let tF=(0,s.useCallback)(()=>{let e=tk();Z?.(e);let t=ev.current,r=t?$(t):null,n=tR();if(tf.enterNormal(),r){tf.setCursorLine(r.line);let t=e.split("\n")[r.line]??"";tf.setCursorCol(Math.max(0,Math.min(r.offset,Math.max(0,t.length-1))))}else tf.setCursorLine(Math.max(0,n-1));J?.(n)},[tk,Z,tR,J,tf]);(0,s.useEffect)(()=>{if(!K)return;let e=e=>{let t="Escape"===e.key,r=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;(t||Y&&r)&&(e.preventDefault(),e.stopPropagation(),Y?ec.current?(0,M.lJ)(ea("codeViewer.unsavedExitConfirm"),{danger:!0,confirmText:ea("codeViewer.discardChanges"),cancelText:ea("codeViewer.continueEditing")}).then(e=>{e&&tF()}):tF():tB())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[K,Y,tB,tF]);let tI=(0,s.useCallback)(()=>{ec.current||(ec.current=!0,eu(!0))},[]);(0,s.useImperativeHandle)(el,()=>({save:tT,close:tB,markDirty:tI,get isDirty(){return ec.current},get isSaving(){return em}}),[tT,tB,tI,em]);let tD=!!(O&&O.length>0),tA=(0,s.useMemo)(()=>{if(!O)return new Map;let e=[...new Set(O.map(e=>e.author))],t=new Map;return e.forEach((e,r)=>{t.set(e,b[r%b.length])}),t},[O]),[t_,tW]=(0,s.useState)(null),[tz,tH]=(0,s.useState)(null);(0,s.useEffect)(()=>{tW(null),tH(null)},[O]);let tO=(0,s.useCallback)((e,t)=>{tW(e.author);let r=t.currentTarget.getBoundingClientRect();tH({line:e,x:r.right+8,y:r.top})},[]),tq=(0,s.useCallback)(()=>{tW(null),tH(null)},[]),tV=(0,s.useCallback)(e=>{V&&(V({hash:e.hashFull,shortHash:e.hash,author:e.author,authorEmail:e.authorEmail,date:new Date(1e3*e.time).toISOString(),subject:e.message.split("\n")[0]||"",body:e.message.split("\n").slice(1).join("\n").trim(),time:e.time}),tH(null))},[V]),tK=`${tw+2}ch`;return(0,n.jsxs)("div",{ref:eS,className:`h-full flex flex-col outline-none ${p}`,tabIndex:0,onClick:tg,onDoubleClick:tb,children:[K&&eg.show&&(0,n.jsxs)("div",{className:"px-4 py-2 bg-amber-500/15 border-b border-amber-500/30 flex items-center gap-3 flex-shrink-0",children:[(0,n.jsx)("svg",{className:"w-5 h-5 text-amber-500 flex-shrink-0",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-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})}),(0,n.jsx)("span",{className:"text-sm text-foreground flex-1",children:ea("codeViewer.fileModifiedExternally")}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("button",{onClick:tP,className:"px-3 py-1 text-sm rounded border border-border hover:bg-accent transition-colors",children:ea("codeViewer.useDiskVersion")}),(0,n.jsx)("button",{onClick:t$,className:"px-3 py-1 text-sm rounded bg-amber-500 text-white hover:bg-amber-600 transition-colors",children:ea("codeViewer.forceOverwrite")})]})]}),!K&&f&&eI&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-2 px-3 py-2 bg-secondary border-b border-border",children:[(0,n.jsx)("input",{ref:eL,type:"text",value:eD,onChange:e=>e1(e.target.value),onKeyDown:e7,placeholder:ea("codeViewer.searchPlaceholder"),className:"flex-1 max-w-xs px-2 py-1 text-sm border border-border rounded bg-card text-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),(0,n.jsx)("button",{onClick:()=>e2(!eA),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${eA?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:ea("codeViewer.caseSensitive"),children:"Aa"}),(0,n.jsx)("button",{onClick:()=>e5(!e_),className:`px-2 py-1 text-xs font-mono rounded border transition-colors ${e_?"bg-brand text-white border-brand":"border-border text-muted-foreground hover:bg-accent"}`,title:ea("codeViewer.wholeWordMatch"),children:"[ab]"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:eQ.length>0?`${eW+1}/${eQ.length}`:ea("common.noMatch")}),(0,n.jsx)("button",{onClick:e9,disabled:0===eQ.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:ea("common.previous"),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"})})}),(0,n.jsx)("button",{onClick:e8,disabled:0===eQ.length,className:"p-1 rounded hover:bg-accent disabled:opacity-50",title:ea("common.next"),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"})})}),(0,n.jsx)("button",{onClick:()=>{e0(!1),e1("")},className:"p-1 rounded hover:bg-accent",title:ea("common.close"),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"})})})]}),K?(0,n.jsx)("div",{ref:ej,className:"flex-1 overflow-auto bg-secondary",children:(0,n.jsxs)("div",{className:"flex",style:{minHeight:"100%"},children:[(0,n.jsx)("div",{className:"flex-shrink-0 font-mono text-sm select-none sticky left-0 z-[2] bg-secondary",style:{width:tK},children:Array.from({length:eh},(e,t)=>(0,n.jsx)("div",{className:"text-right text-muted-foreground/50 pr-3",style:{height:20,lineHeight:"20px"},children:t+1},t))}),(0,n.jsx)("div",{ref:ev,contentEditable:!0,suppressContentEditableWarning:!0,onInput:tS,onKeyDown:tL,onPaste:tE,onCompositionStart:()=>{eN.current=!0},onCompositionEnd:()=>{eN.current=!1,tS()},spellCheck:!1,autoCorrect:"off",autoCapitalize:"off",className:"flex-1 font-mono text-sm outline-none",style:{caretColor:"var(--foreground)",tabSize:2}})]})}):(0,n.jsx)("div",{ref:eC,className:`flex-1 overflow-auto font-mono text-sm bg-secondary${eB?" cmd-held-container":""}`,children:(0,n.jsx)("div",{style:{height:`${eY.getTotalSize()}px`,minWidth:"100%",width:tD?`calc(${tw+ty+10}ch + 13rem)`:`${tw+ty+10}ch`,position:"relative"},children:eY.getVirtualItems().map(e=>{let t=eX[e.index];if("code"!==t.type)return null;let s=t.lineIndex,o=s+1,l=eP[s]||(0,m.ZD)(eJ[s]||""),a=tl(s,l,D),i=eG.has(o),c=eZ.get(o),d=c?.[0],u=!!(eH&&o>=eH.range.start&&o<=eH.range.end),x=tc>=0?ti.current:null,h=!K&&q&&x===o?q[s]??null:null,f=tD?O[s]:void 0,p=tD&&s>0?O[s-1]:void 0,g=!!f&&(!p||p.hash!==f.hash),b=f?tA.get(f.author):void 0;return(0,n.jsx)(j,{virtualKey:e.key,lineNum:o,highlightedHtml:a,hasComments:i,firstComment:d,lineCommentsCount:c?.length,isInRange:u,showLineNumbers:r,lineNumChars:tw,commentsEnabled:eV,virtualItemSize:e.size,virtualItemStart:e.start,onCommentBubbleClick:te,onCmdClick:tj,onTokenHover:tv,onTokenHoverLeave:z,flashLine:eF,blameLine:f,showBlameInfo:g,blameAuthorColor:b,isBlameHovered:!!(f&&t_===f.author),onBlameClick:tV,onBlameMouseEnter:tO,onBlameMouseLeave:tq,inlineBlameData:h,onInlineBlameClick:tV,isCursorLine:Y&&!K&&tf.state.cursorLine===s,cursorCol:Y&&!K&&tf.state.cursorLine===s?tf.state.cursorCol:void 0},e.key)})})}),Y&&(0,n.jsxs)("div",{className:"vi-status-bar flex-shrink-0 h-6 bg-card border-t border-border flex items-center px-3 text-xs font-mono select-none",children:["normal"===tf.state.mode&&(0,n.jsx)("span",{className:"text-green-11 font-medium",children:"NORMAL"}),"insert"===tf.state.mode&&(0,n.jsx)("span",{className:"text-blue-11 font-medium",children:"INSERT"}),"command"===tf.state.mode&&(0,n.jsxs)("div",{className:"flex items-center flex-1",children:[(0,n.jsx)("span",{className:"text-foreground",children:":"}),(0,n.jsx)("input",{ref:tu,value:tf.state.commandInput,onChange:e=>tf.setCommandInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tf.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),"search"===tf.state.mode&&(0,n.jsxs)("div",{className:"flex items-center flex-1",children:[(0,n.jsx)("span",{className:"text-foreground",children:"/"}),(0,n.jsx)("input",{ref:tm,value:tf.state.searchInput,onChange:e=>tf.setSearchInput(e.target.value),onKeyDown:e=>{if(e.nativeEvent.isComposing)return;let t=e.ctrlKey&&"c"===e.key&&!e.metaKey&&!e.shiftKey;("Enter"===e.key||"Escape"===e.key||t)&&(e.preventDefault(),e.stopPropagation(),tf.handleKeyDown(e.nativeEvent))},className:"flex-1 bg-transparent outline-none text-foreground ml-0.5",spellCheck:!1,autoComplete:"off"})]}),tf.state.keyBuffer&&"normal"===tf.state.mode&&(0,n.jsx)("span",{className:"ml-2 text-muted-foreground",children:tf.state.keyBuffer}),tf.state.isDirty&&("normal"===tf.state.mode||"command"===tf.state.mode)&&(0,n.jsx)("span",{className:"ml-2 text-amber-11",children:"[+]"}),(0,n.jsxs)("span",{className:"ml-auto text-muted-foreground",children:[tf.state.cursorLine+1,":",tf.state.cursorCol+1]})]}),eR&&td&&(0,l.createPortal)((0,n.jsxs)(n.Fragment,{children:[!K&&(0,n.jsx)(x.f,{floatingToolbarRef:eE,bumpRef:eT,container:td,onAddComment:tt,onSendToAI:tr,onSearch:eo?tn:void 0,isChatLoading:eq?.isLoading}),!K&&eH&&(0,n.jsx)(d.t,{x:eH.x,y:eH.y,range:eH.range,lineSnapshot:eH.lineSnapshot,container:td,onSubmit:ts,onClose:()=>e3(null)}),!K&&eO&&(0,n.jsx)(d.G,{x:eO.x,y:eO.y,range:eO.range,filePath:t,lineSnapshot:eO.lineSnapshot,container:td,onSubmit:to,onClose:()=>e6(null),isChatLoading:eq?.isLoading}),!K&&ez&&(0,n.jsx)(h.t,{x:ez.x,y:ez.y,comment:ez.comment,container:td,onClose:()=>e4(null),onUpdateComment:eK,onDeleteComment:eU}),tz&&(0,n.jsxs)("div",{className:"fixed z-50 bg-card border border-border rounded-lg shadow-lg p-3 max-w-lg",style:{left:Math.min(tz.x,window.innerWidth-450),top:Math.max(8,Math.min(tz.y,window.innerHeight-200))},children:[(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"px-2 py-0.5 rounded text-xs font-mono font-medium text-white flex-shrink-0",style:{backgroundColor:tA.get(tz.line.author)?.border||"#666"},children:tz.line.hash}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground",children:tz.line.author}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground",children:tz.line.authorEmail})]})]}),(0,n.jsx)("div",{className:"mt-2 text-sm text-foreground whitespace-pre-wrap max-h-48 overflow-y-auto",children:tz.line.message}),(0,n.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground border-t border-border pt-2",children:[(0,E.fw)(tz.line.time)," \xb7 ",new Date(1e3*tz.line.time).toLocaleString(),(0,n.jsx)("span",{className:"ml-2 text-brand",children:ea("codeViewer.clickToViewDetails")})]})]})]}),td)]})});function F({content:e,filePath:t,className:r=""}){let o=(0,s.useMemo)(()=>e.split("\n"),[e]),l=(0,u.C)(o,t),a=Math.max(4,String(o.length).length);return(0,n.jsx)("pre",{className:`overflow-auto text-sm font-mono bg-secondary p-2 ${r}`,children:o.map((e,t)=>(0,n.jsxs)("div",{className:"flex",children:[(0,n.jsx)("span",{className:"text-slate-9 select-none pr-4 text-right",style:{minWidth:`${a+2}ch`},children:t+1}),(0,n.jsx)("span",{className:"flex-1",dangerouslySetInnerHTML:{__html:l[t]||(0,m.ZD)(e||" ")}})]},t))})}},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);return(0,n.useEffect)(()=>{let e=()=>{t("visible"===document.visibilityState)};document.addEventListener("visibilitychange",e);let r=e=>{e.data?.type==="IFRAME_VISIBILITY"&&t(!!e.data.visible)};return window.addEventListener("message",r),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("message",r)}},[]),e}},46456:(e,t,r)=>{r.d(t,{$:()=>i,BC:()=>c,Tu:()=>u,lb:()=>a,tj:()=>m,vv:()=>d});var n=r(49433),s=r(82680);let o=(e,t)=>n.tryPromise({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)=>n.tryPromise({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})}),a=(e,t)=>o(`/api/comments?cwd=${encodeURIComponent(e)}${t?`&filePath=${encodeURIComponent(t)}`:""}`),i=e=>o(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`),c=e=>o("/api/comments",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),d=(e,t,r)=>o("/api/comments",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,id:t,content:r})}),u=(e,t)=>l(`/api/comments?cwd=${encodeURIComponent(e)}&id=${encodeURIComponent(t)}`,{method:"DELETE"}),m=e=>l(`/api/comments?cwd=${encodeURIComponent(e)}&all=true`,{method:"DELETE"})},47617:(e,t,r)=>{r.d(t,{I18nProvider:()=>c});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(86957),i=r(76900);function c({children:e}){return(0,s.useEffect)(()=>{a.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";l.A.language!==r&&l.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 l.A.on("languageChanged",e),()=>{l.A.off("languageChanged",e)}},[]),(0,s.useEffect)(()=>{if(window===window.parent)return;let e=e=>{e.data?.type==="cockpit:language-change"&&e.data.lang&&l.A.language!==e.data.lang&&l.A.changeLanguage(e.data.lang)};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[]),(0,n.jsx)(o.xC,{i18n:l.A,children:e})}},48347:(e,t,r)=>{r.d(t,{H:()=>l,r:()=>a});var n=r(95155),s=r(12115);let o=(0,s.createContext)(null);function l({value:e,children:t}){return(0,n.jsx)(o.Provider,{value:e,children:t})}function a(){return(0,s.useContext)(o)}},53213:(e,t,r)=>{r.d(t,{Bj:()=>i,CM:()=>b,FK:()=>g,Iz:()=>m,MB:()=>v,Ub:()=>h,X0:()=>x,Zi:()=>c,lv:()=>u,oh:()=>p,r4:()=>a,w2:()=>f,yy:()=>d});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({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})}),l=(e,t)=>n.tryPromise({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})}),a=e=>o(`/api/git/branches?cwd=${encodeURIComponent(e)}`).pipe(n.flatMap(t=>"Failed to get branches"===t.error?n.fail(new s.m_({resource:"git-repo",id:e})):n.succeed(t))),i=(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)}`:""}`),d=(e,t,r)=>o(`/api/git/branch-diff?cwd=${encodeURIComponent(e)}&base=${encodeURIComponent(t)}${r?`&file=${encodeURIComponent(r)}`:""}`),u=e=>o(`/api/git/status?cwd=${encodeURIComponent(e)}`),m=(e,t)=>l("/api/git/stage",{cwd:e,files:t}),x=(e,t)=>l("/api/git/unstage",{cwd:e,files:t}),h=(e,t,r)=>l("/api/git/discard",{cwd:e,files:t,isUntracked:r}),f=(e,t,r)=>{let n=new URLSearchParams({cwd:e,file:t,type:r});return o(`/api/git/diff?${n}`)},p=e=>o(`/api/git/diff?${e.toString()}`),g=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),b=e=>n.tryPromise({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})}),v=e=>o(`/api/projectGraph/search?${e.toString()}`)},53853:(e,t,r)=>{r.d(t,{G:()=>u,f:()=>m});var n=r(12115);function s(){if("u"<typeof document)return null;let e=document.querySelector('meta[name="cockpit-bridge"]');if(!e)return null;let t=e.dataset.id,r=e.dataset.version;return t?{id:t,version:r||"unknown"}:null}let o=null,l=new Set;function a(){l.forEach(e=>e())}function i(e){l.add(e);let t=s();return t&&!o&&(o=t,Promise.resolve().then(a)),()=>{l.delete(e)}}function c(){return o}function d(){return null}if("u">typeof document&&(o=s()),"u">typeof MutationObserver&&"u">typeof document){let e=new MutationObserver(()=>{let e=s();e&&(!o||e.id!==o.id||e.version!==o.version)&&(o=e,a())}),t=document.head||document.documentElement;t&&e.observe(t,{childList:!0})}function u(){return(0,n.useSyncExternalStore)(i,c,d)}function m(){return o??s()}},56978:(e,t,r)=>{r.d(t,{C:()=>o});var n=r(12115),s=r(17196);function o(e,t){let[r,o]=(0,n.useState)(null),[l,a]=(0,n.useState)(!1);(0,n.useEffect)(()=>{let e=()=>{a(document.documentElement.classList.contains("dark"))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>t.disconnect()},[]);let i=(0,n.useMemo)(()=>e.join("\n"),[e]),c=`${i}:${t}:${l}`,d=(0,n.useMemo)(()=>r&&r.key===c?r.html:e.map(e=>(0,s.ZD)(e||" ")),[e,c,r]);return(0,n.useEffect)(()=>{if(0===e.length)return;let r=!1;return(async()=>{try{let n=await (0,s.kS)();if(r)return;let a=(0,s.sQ)(t),i=e.join("\n"),d=n.codeToTokens(i,{lang:a,theme:l?"github-dark":"github-light"}),u=[];for(let e=0;e<d.tokens.length;e++)if(u[e]=(0,s.b8)(d.tokens[e]),e%500==0&&e>0&&(await new Promise(e=>setTimeout(e,0)),r))return;o({key:c,html:u})}catch(e){console.error("Line highlight error:",e)}})(),()=>{r=!0}},[i,t,l]),d}},60938:(e,t,r)=>{r.d(t,{DZ:()=>c,Ft:()=>x,K9:()=>p,Nn:()=>w,OJ:()=>b,VK:()=>y,YW:()=>m,__:()=>j,dt:()=>v,eA:()=>g,eE:()=>h,gZ:()=>d,mP:()=>i,nM:()=>k,r6:()=>f,r9:()=>u});var n=r(49433),s=r(82680);let o=(e,t={})=>n.tryPromise({try:async()=>{let r=await fetch(e,t.init);if(t.passThroughStatuses&&t.passThroughStatuses.includes(r.status))return await r.json().catch(()=>({}));if(!r.ok){let e;try{e=(await r.json()).error}catch{}throw Error(e||`HTTP ${r.status}`)}return await r.json()},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),l=(e,t)=>n.tryPromise({try:async()=>{let r=await fetch(e,t),n=null;try{n=await r.json()}catch{}return{status:r.status,ok:r.ok,data:n}},catch:t=>new s.uV({message:`GET ${e} failed`,cause:t})}),a=(e,t)=>n.tryPromise({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})}),i=e=>o(`/api/files/init?cwd=${encodeURIComponent(e)}`),c=e=>o(`/api/files/index?cwd=${encodeURIComponent(e)}`),d=(e,t)=>o(`/api/files/readdir?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),u=e=>o(`/api/files/recent?cwd=${encodeURIComponent(e)}`),m=(e,t,r)=>a("/api/files/recent",{cwd:e,file:t,...r??{}}),x=(e,t)=>a("/api/files/expanded",{cwd:e,paths:t}),h=(e,t)=>o(`/api/files/blame?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`),f=(e,t)=>l(`/api/files/stat?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),p=(e,t)=>l(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`,{cache:"no-store"}),g=e=>o(`/api/files/text?${e.toString()}`),b=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/files/save",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),r=null;try{r=await t.json()}catch{}return{status:t.status,ok:t.ok,data:r}},catch:e=>new s.uV({message:"POST /api/files/save failed",cause:e})}),v=()=>o("/api/files/clipboard"),j=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/files/clipboard",{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:"POST /api/files/clipboard failed",cause:e})}),w=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/files/paste",{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/files/paste failed",cause:e})}),y=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/files/delete",{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/files/delete failed",cause:e})}),k=e=>o(`/api/file?path=${encodeURIComponent(e)}`)},63048:(e,t,r)=>{r.d(t,{Workspace:()=>K});var n=r(95155),s=r(12115),o=r(79114),l=r(69958),a=r(76288),i=r(83678),c=r(21484),d=r(86957),u=r(83448);let m={"claude-opus-4-6":{label:"Opus 4.6",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"},"claude-opus-4-5-20251101":{label:"Opus 4.5",input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#fb923c"},"claude-sonnet-4-6":{label:"Sonnet 4.6",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#3b82f6"},"claude-sonnet-4-5-20250929":{label:"Sonnet 4.5",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#60a5fa"},"claude-haiku-4-5-20251001":{label:"Haiku 4.5",input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}},x={label:"",input:3,output:15,cacheRead:.3,cacheWrite:3.75,color:"#94a3b8"};function h(e){if(m[e])return m[e];let t=e.toLowerCase();return t.includes("opus")?{...x,input:5,output:25,cacheRead:.5,cacheWrite:6.25,color:"#f97316"}:t.includes("haiku")?{...x,input:1,output:5,cacheRead:.1,cacheWrite:1.25,color:"#22c55e"}:x}function f(e){let t=m[e];return t?t.label:e.replace(/^claude-/,"").replace(/-\d{8}$/,"").replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function p(e){return(m[e]??h(e)).color}function g(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 b(e){return e>=1e3?`$${e.toFixed(0)}`:e>=100?`$${e.toFixed(1)}`:`$${e.toFixed(2)}`}function v({data:e,height:t=200,formatValue:r=g}){let o=(0,s.useRef)(null),l=(0,s.useRef)(null),[a,i]=(0,s.useState)(null),c=(0,s.useRef)([]),d=(0,s.useCallback)(()=>{let n=o.current,s=l.current;if(!n||!s)return;let a=window.devicePixelRatio||1,i=s.getBoundingClientRect().width;n.width=i*a,n.height=t*a,n.style.width=`${i}px`,n.style.height=`${t}px`;let d=n.getContext("2d");d.scale(a,a),d.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))));d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="10px ui-monospace, monospace",d.textAlign="right",d.textBaseline="middle";for(let e=0;e<=4;e++){var p;let t=f/4*e,s=8+h-t/f*h;d.fillText(r(t),44,s),d.strokeStyle=(p="--border",getComputedStyle(n).getPropertyValue(p).trim()||"#333"),d.lineWidth=.5,d.beginPath(),d.moveTo(50,s),d.lineTo(50+x,s),d.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,l,a,i,c,u;let m=n.data[t];if(m<=0)return;let x=m/f*h,p=8+h-s-x;d.fillStyle=n.color,o=d,l=r,a=p,i=b,u=2,(c=x)<1||(u=Math.min(u,c/2,i/2),o.beginPath(),o.moveTo(l+u,a),o.lineTo(l+i-u,a),o.quadraticCurveTo(l+i,a,l+i,a+u),o.lineTo(l+i,a+c-u),o.quadraticCurveTo(l+i,a+c,l+i-u,a+c),o.lineTo(l+u,a+c),o.quadraticCurveTo(l,a+c,l,a+c-u),o.lineTo(l,a+u),o.quadraticCurveTo(l,a,l+u,a),o.fill()),v.push({x:r,y:p,w:b,h:x,label:e,value:m,dataset:n.label,color:n.color}),s+=x}),d.fillStyle=getComputedStyle(n).getPropertyValue("color")||"#888",d.font="9px ui-monospace, monospace",d.textAlign="center",d.textBaseline="top",t%(u.length>20?Math.ceil(u.length/15):1)==0&&d.fillText(e,r+b/2,8+h+6)}),c.current=v},[e,t,r]);(0,s.useEffect)(()=>{d();let e=new ResizeObserver(()=>d());return l.current&&e.observe(l.current),()=>e.disconnect()},[d]);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,l=c.current.find(e=>n>=e.x&&n<=e.x+e.w&&s>=e.y&&s<=e.y+e.h);l?i({x:e.clientX-t.left,y:l.y-4,content:`${l.dataset}: ${r(l.value)}`}):i(null)},[r]);return(0,n.jsxs)("div",{ref:l,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)}),a&&(0,n.jsx)("div",{className:"absolute pointer-events-none bg-popover text-popover-foreground text-[10px] px-2 py-1 rounded shadow-lg border border-border whitespace-nowrap z-10",style:{left:a.x,top:a.y,transform:"translate(-50%, -100%)"},children:a.content})]})}function j({hourCounts:e}){let{t}=(0,o.Bd)(),r=Math.max(1,...Object.values(e)),s=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:s.map(s=>{let o=e[String(s)]||0,l=o/r;return(0,n.jsxs)("div",{className:"flex-1 flex flex-col items-center gap-0.5",title:t("tokenStats.hourSessions",{h:s,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(59, 130, 246, ${.2+.8*l})`:"var(--muted)"}}),s%3==0&&(0,n.jsx)("span",{className:"text-[8px] text-muted-foreground",children:s})]},s)})})]})}function w({isOpen:e,onClose:t}){var r;let l,a,{t:i}=(0,o.Bd)(),[c,m]=(0,s.useState)(null),[x,k]=(0,s.useState)(!0),[N,C]=(0,s.useState)("day"),[S,L]=(0,s.useState)("tokens"),[E,M]=(0,s.useState)("claude");(0,s.useEffect)(()=>{e&&(queueMicrotask(()=>k(!0)),d.t4.runPromiseExit((0,u.Cr)(E)).then(e=>{if("Success"===e._tag){let t=e.value;t.error||queueMicrotask(()=>m(t))}queueMicrotask(()=>k(!1))}))},[e,E]);let T=(0,s.useMemo)(()=>c?.modelUsage?Object.entries(c.modelUsage).filter(([e])=>!e.startsWith("<")).map(([e,t])=>{let r;return{id:e,label:f(e),color:p(e),usage:t,cost:(r=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):[],[c]),$=(0,s.useMemo)(()=>T.reduce((e,t)=>e+t.cost,0),[T]),P=(0,s.useMemo)(()=>T.map(e=>e.id),[T]),R=(0,s.useMemo)(()=>{let e={};for(let t of T)e[t.id]=t.totalTokens>0?t.cost/t.totalTokens:0;return e},[T]),{activityChart:B,tokenChart:F,costChart:I}=(0,s.useMemo)(()=>{let e=c?.dailyActivity||[],t=c?.dailyModelTokens||[];if("day"===N){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:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.toolCallCount),color:"#22c55e"}]},o=n.map(e=>e.date.slice(5));return{activityChart:s,tokenChart:{labels:o,datasets:P.map(e=>({label:f(e),data:n.map(t=>t.tokensByModel[e]||0),color:p(e)}))},costChart:{labels:o,datasets:P.map(e=>({label:f(e),data:n.map(t=>(t.tokensByModel[e]||0)*(R[e]||0)),color:p(e)}))}}}if("week"===N){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 l=r.get(s);l.messages+=t.messageCount,l.sessions+=t.sessionCount,l.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:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:P.map(e=>({label:f(e),data:r.map(t=>t.tokensByModel[e]||0),color:p(e)}))},costChart:{labels:n,datasets:P.map(e=>({label:f(e),data:r.map(t=>(t.tokensByModel[e]||0)*(R[e]||0)),color:p(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:"#3b82f6"},{label:i("tokenStats.toolCalls"),data:r.map(e=>e.tools),color:"#22c55e"}]};return{activityChart:s,tokenChart:{labels:n,datasets:P.map(e=>({label:f(e),data:r.map(t=>t.tokensByModel[e]||0),color:p(e)}))},costChart:{labels:n,datasets:P.map(e=>({label:f(e),data:r.map(t=>(t.tokensByModel[e]||0)*(R[e]||0)),color:p(e)}))}}},[c,N,P,R,i]);if((0,s.useEffect)(()=>{if(!e)return;let r=e=>{"Escape"===e.key&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,t]),!e)return null;let D=[{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-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-xl shadow-xl 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:["claude","claude2"].map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${E===e?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>{m(null),M(e)},children:"claude"===e?"Claude":"Claude 2"},e))}),(0,n.jsx)("div",{className:"flex bg-muted rounded-md p-0.5",children:D.map(e=>(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${N===e.key?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>C(e.key),children:e.label},e.key))})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent 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:x?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("common.loading")}):c?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"grid grid-cols-5 gap-3",children:[(0,n.jsx)(y,{label:i("tokenStats.totalSessions"),value:String(c.totalSessions??0)}),(0,n.jsx)(y,{label:i("tokenStats.totalMessages"),value:g(c.totalMessages??0)}),(0,n.jsx)(y,{label:i("tokenStats.equivalentApiCost"),value:b($),highlight:!0}),(0,n.jsx)(y,{label:i("tokenStats.longestSession"),value:c.longestSession?(l=Math.floor((r=c.longestSession.duration)/36e5),a=Math.floor(r%36e5/6e4),l>0?`${l}h ${a}m`:`${a}m`):"-"}),(0,n.jsx)(y,{label:i("tokenStats.firstUse"),value:c.firstSessionDate?c.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:"#3b82f6"}}),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:"#22c55e"}}),i("tokenStats.toolCalls")]})]})]}),(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(v,{data:B,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"===S?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>L("tokens"),children:i("tokenStats.tokenUsage")}),(0,n.jsx)("button",{className:`px-2.5 py-0.5 text-[11px] rounded transition-colors ${"cost"===S?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,onClick:()=>L("cost"),children:i("tokenStats.equivalentCost")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-3 text-[10px] flex-wrap",children:T.map(e=>(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: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)(v,{data:"tokens"===S?F:I,height:180,formatValue:"tokens"===S?g:b})})]}),(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:[T.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:g(e.usage.inputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(e.usage.outputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(e.usage.cacheReadInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(e.usage.cacheCreationInputTokens)}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:$>0?`${(e.cost/$*100).toFixed(1)}%`:"-"}),(0,n.jsx)("td",{className:"px-3 py-2 text-right font-medium text-foreground",children:b(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:g(T.reduce((e,t)=>e+t.usage.inputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(T.reduce((e,t)=>e+t.usage.outputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(T.reduce((e,t)=>e+t.usage.cacheReadInputTokens,0))}),(0,n.jsx)("td",{className:"px-3 py-2 text-right text-muted-foreground",children:g(T.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:b($)})]})]})]})})]}),c.hourCounts&&Object.keys(c.hourCounts).length>0&&(0,n.jsx)("div",{className:"border border-border rounded-lg p-3 bg-muted/20",children:(0,n.jsx)(j,{hourCounts:c.hourCounts})})]}):(0,n.jsx)("div",{className:"text-center text-muted-foreground py-12",children:i("tokenStats.notFound")})})]})]})}function y({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 k=r(8648),N=r(34075),C=r(45048),S=r(38408),L=r(49433),E=r(82680);let M=(e,t)=>L.tryPromise({try:async()=>{let r=await fetch(e,t);if(!r.ok){let e;try{e=(await r.json()).error}catch{}throw Error(e||`HTTP ${r.status}`)}return await r.json()},catch:r=>new E.uV({message:`${t?.method??"GET"} ${e} failed`,cause:r})});function T({skillId:e,onClose:t}){let[r,o]=(0,s.useState)(null),[l,a]=(0,s.useState)(!0),[i,c]=(0,s.useState)("preview");(0,s.useEffect)(()=>{let t=!1;return a(!0),d.t4.runPromiseExit(M(`/api/skills/content?id=${encodeURIComponent(e)}`)).then(e=>{t||("Success"===e._tag?o(e.value):console.error("Failed to load skill content",e.cause),a(!1))}),()=>{t=!0}},[e]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.stopPropagation(),t())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t]);let u=(0,s.useCallback)(async()=>{if(r?.path)try{await navigator.clipboard.writeText(r.path),(0,N.oR)("Path copied","success")}catch{(0,N.oR)("Failed to copy","error")}},[r]);return(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-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-4xl h-[85vh] mx-4 flex flex-col overflow-hidden",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:r?.name?`/${r.name}`:"Skill Preview"}),(0,n.jsx)("button",{onClick:u,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"Copy path",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"})]})})]}),r?.path&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground font-mono truncate mt-0.5",children:r.path})]}),(0,n.jsxs)("div",{className:"flex items-center rounded-md border border-border overflow-hidden text-xs flex-shrink-0",children:[(0,n.jsx)("button",{onClick:()=>c("preview"),className:`px-3 py-1 transition-colors ${"preview"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Preview"}),(0,n.jsx)("button",{onClick:()=>c("source"),className:`px-3 py-1 transition-colors ${"source"===i?"bg-brand text-white":"text-muted-foreground hover:text-foreground hover:bg-accent"}`,children:"Source"})]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors flex-shrink-0",title:"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 overflow-auto",children:l?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"Loading..."}):r&&r.valid?"preview"===i?(0,n.jsx)("div",{className:"px-6 py-4",children:(0,n.jsx)(C.T,{content:r.content})}):(0,n.jsx)(S.XO,{content:r.content,filePath:r.path,className:"min-h-full"}):(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-muted-foreground text-sm",children:"File cannot be read."})})]})]})}var $=r(88371);function P({isOpen:e,onClose:t}){let[r,o]=(0,s.useState)([]),[l,a]=(0,s.useState)(!1),[i,c]=(0,s.useState)(""),[u,m]=(0,s.useState)(!1),[x,h]=(0,s.useState)(""),[f,p]=(0,s.useState)(!1),[g,b]=(0,s.useState)(null),v=(0,s.useCallback)(async()=>{a(!0);let e=await d.t4.runPromiseExit(M("/api/skills"));"Success"===e._tag?o(e.value):console.error("Failed to load skills",e.cause),a(!1)},[]);(0,s.useEffect)(()=>{e&&v()},[e,v]),(0,s.useEffect)(()=>{if(!e)return;let r=e=>{if("Escape"===e.key&&!g){if(u){m(!1),h("");return}t()}};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e,t,u,g]);let j=(0,s.useMemo)(()=>{let e=i.trim().toLowerCase();return e?r.filter(t=>t.name.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)):r},[r,i]),w=(0,s.useCallback)(async()=>{let e=x.trim();if(!e)return;p(!0);let t=await d.t4.runPromiseExit(M("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e})}));if("Success"===t._tag)(0,N.oR)("Skill added","success"),h(""),m(!1),await v(),(0,$.k)();else{let e="Fail"===t.cause._tag?t.cause.error:null,r=e?.cause,n=r instanceof Error?r.message:"Failed to add skill";(0,N.oR)(n,"error")}p(!1)},[x,v]),y=(0,s.useCallback)(async e=>{"Success"===(await d.t4.runPromiseExit(M(`/api/skills/${encodeURIComponent(e)}`,{method:"DELETE"})))._tag?(o(t=>t.filter(t=>t.id!==e)),(0,$.k)()):(0,N.oR)("Failed to delete","error")},[]),k=(0,s.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),(0,N.oR)("Path copied","success")}catch{(0,N.oR)("Failed to copy","error")}},[]);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-black/50",onClick:t}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-3xl h-[80vh] mx-4 flex flex-col overflow-hidden",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:"Skills"}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:"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.jsxs)("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border flex-shrink-0",children:[(0,n.jsxs)("div",{className:"relative flex-1",children:[(0,n.jsxs)("svg",{className:"w-4 h-4 absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"7",strokeWidth:2}),(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-4.35-4.35"})]}),(0,n.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"Search skills...",className:"w-full pl-8 pr-3 py-1.5 text-sm border border-border rounded-md bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring"})]}),(0,n.jsx)("button",{onClick:()=>m(!0),className:"px-3 py-1.5 text-sm rounded-md bg-brand text-white hover:bg-teal-10 active:scale-95 transition-all",children:"+ Add Skill"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-3 space-y-2",children:l?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:"Loading..."}):0===j.length?(0,n.jsx)("div",{className:"text-center text-muted-foreground py-8 text-sm",children:0===r.length?'No skills yet. Click "Add Skill" to add one.':"No skills match your search."}):j.map(e=>(0,n.jsx)(R,{skill:e,onPreview:()=>b(e.id),onDelete:()=>y(e.id),onCopyPath:()=>k(e.path)},e.id))})]})]}),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-black/50",onClick:()=>{f||(m(!1),h(""))}}),(0,n.jsxs)("div",{className:"relative bg-card rounded-lg shadow-xl w-full max-w-lg mx-4 p-5",children:[(0,n.jsx)("h3",{className:"text-sm font-medium text-foreground mb-3",children:"Add Skill"}),(0,n.jsx)("label",{className:"block text-xs text-muted-foreground mb-1",children:"Absolute path to SKILL.md"}),(0,n.jsx)("input",{type:"text",value:x,onChange:e=>h(e.target.value),onKeyDown:e=>{"Enter"!==e.key||f||w()},placeholder:"/Users/you/.../skills/foo/SKILL.md",autoFocus:!0,className:"w-full px-3 py-2 text-sm font-mono border border-border rounded-md bg-card text-foreground placeholder-slate-9 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:()=>{m(!1),h("")},disabled:f,className:"px-3 py-1.5 text-sm rounded-md border border-border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-50",children:"Cancel"}),(0,n.jsx)("button",{onClick:w,disabled:f||!x.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:f?"Adding...":"Add"})]})]})]}),g&&(0,n.jsx)(T,{skillId:g,onClose:()=>b(null)})]}):null}function R({skill:e,onPreview:t,onDelete:r,onCopyPath:o}){let[l,a]=(0,s.useState)(!1);return(0,n.jsx)("div",{className:`border border-border rounded-lg p-3 bg-card hover:bg-accent/30 transition-colors ${e.valid?"":"opacity-60"}`,children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"w-9 h-9 flex-shrink-0 flex items-center justify-center rounded-md bg-brand/10 text-brand text-lg",children:e.icon?(0,n.jsx)("span",{children:e.icon}):(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:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,n.jsxs)("span",{className:"font-mono text-sm font-medium text-foreground",children:["/",e.name]}),e.description&&(0,n.jsx)("span",{className:"text-sm text-muted-foreground line-clamp-2",children:e.description}),!e.valid&&(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded bg-red-9/15 text-red-11",children:"Invalid"})]}),e.argumentHint&&(0,n.jsx)("div",{className:"font-mono text-xs text-muted-foreground mt-0.5 truncate",children:e.argumentHint}),(0,n.jsx)("div",{className:"flex items-center gap-1 mt-1",children:(0,n.jsx)("button",{onClick:o,className:"text-xs text-muted-foreground hover:text-foreground font-mono truncate text-left",title:"Copy path",children:e.path})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[(0,n.jsx)("button",{onClick:t,disabled:!e.valid,className:"p-1.5 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors disabled:opacity-40 disabled:cursor-not-allowed",title:"Preview",children:(0,n.jsxs)("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 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"})]})}),l?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("button",{onClick:()=>{a(!1),r()},className:"px-2 py-1 text-xs rounded bg-red-9 text-white hover:bg-red-10",children:"Confirm"}),(0,n.jsx)("button",{onClick:()=>a(!1),className:"px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground",children:"Cancel"})]}):(0,n.jsx)("button",{onClick:()=>a(!0),className:"p-1.5 text-muted-foreground hover:text-red-11 hover:bg-red-9/10 rounded transition-colors",title:"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"})})})]})]})})}var B=r(47650);let F=[],I=[];function D(){I.forEach(e=>e())}function A(e){F=F.filter(t=>t.id!==e),D()}function _({onNavigate:e}){let t=function(){let[,e]=(0,s.useState)(0);return(0,s.useEffect)(()=>{let t=()=>e(e=>e+1);return I.push(t),()=>{I=I.filter(e=>e!==t)}},[]),F}();return 0===t.length?null:(0,B.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)(W,{item:t,onNavigate:e,onRemove:A},t.id))}),document.body)}function W({item:e,onNavigate:t,onRemove:r}){let{t:l}=(0,o.Bd)(),[a,i]=(0,s.useState)(!1),c=(0,s.useRef)(void 0),d=(0,s.useCallback)(()=>{i(!0),setTimeout(()=>r(e.id),300)},[e.id,r]);(0,s.useEffect)(()=>(c.current=setTimeout(d,5e3),()=>clearTimeout(c.current)),[d]);let u=(0,s.useCallback)(()=>{clearTimeout(c.current),t(e.cwd,e.sessionId),r(e.id)},[e,t,r]),m=(0,s.useCallback)(()=>{clearTimeout(c.current)},[]),x=(0,s.useCallback)(()=>{c.current=setTimeout(d,2e3)},[d]);return(0,n.jsxs)("div",{className:`pointer-events-auto bg-card border border-border rounded-lg shadow-lg px-3 py-2.5 min-w-[260px] max-w-[340px] cursor-pointer hover:bg-accent transition-all ${a?"opacity-0 -translate-x-4":"opacity-100 translate-x-0"}`,style:{animation:a?void 0:"slideInLeft 0.3s ease-out"},onClick:u,onMouseEnter:m,onMouseLeave:x,children:[(0,n.jsxs)("div",{className:"flex items-center 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:l("common.done")}),(0,n.jsx)("button",{onClick:e=>{e.stopPropagation(),d()},className:"ml-auto 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:"text-xs text-muted-foreground truncate mt-1 ml-6",children:e.message})]})}var z=r(10592),H=r(86359),O=r(80905),q=r(80286);let V=L.tryPromise({try:async()=>{let e=await fetch("/api/projects");if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()},catch:e=>new E.uV({message:"fetch /api/projects failed",cause:e})});function K({initialCwd:e,initialSessionId:t}){let{t:u}=(0,o.Bd)(),[m,x]=(0,s.useState)([]),[h,f]=(0,s.useState)(0),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[j,y]=(0,s.useState)(!1),[N,C]=(0,s.useState)(!1),[S,M]=(0,s.useState)(!1),[T,$]=(0,s.useState)(null),[R,B]=(0,s.useState)(!1),[I,A]=(0,s.useState)(!1),[W,U]=(0,s.useState)(new Set),J=(0,s.useRef)(new Map),Q=(0,s.useRef)(new Map),X=(0,s.useRef)(new Map),Y=(0,s.useRef)(null),Z=function(e,t){let[r,n]=(0,s.useState)({status:"loading"});return(0,s.useEffect)(()=>{n({status:"loading"});let t=d.t4.runFork(e);return t.addObserver(e=>{z.YW(e,{onSuccess:e=>n({status:"success",data:e}),onFailure:e=>{let t=H.od(e);n({status:"error",error:O.Ru(t)?t.value:e})}})}),()=>{L.runFork(q.G(t))}},t),r}(V,[]);(0,s.useEffect)(()=>{if("success"===Z.status){let e=Z.data;x([...e.projects||[]]),f(e.activeIndex||0),g(e.collapsed||!1),A(!0)}else"error"===Z.status&&(console.error("Failed to load projects:",Z.error),A(!0))},[Z]);let G=(0,s.useCallback)(async(e,t,n)=>{let s,{Effect:o}=await r.e(9012).then(r.bind(r,49012)),{BrowserRuntime:l}=await r.e(7562).then(r.bind(r,47562)),a=await l.runPromise((s={projects:e,activeIndex:t,collapsed:n},L.tryPromise({try:async()=>{let e=await fetch("/api/projects",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(s)});if(!e.ok)throw Error(`HTTP ${e.status}`)},catch:e=>new E.uV({message:"save /api/projects failed",cause:e})})).pipe(o.either));"Left"===a._tag&&console.error("Failed to save projects:",a.left)},[]);(0,s.useEffect)(()=>{let e=m[h]?.cwd;e&&U(t=>t.has(e)?t:new Set(t).add(e))},[h,m]),(0,s.useEffect)(()=>{for(let[e,t]of J.current.entries()){let r=m[h]?.cwd===e;t.contentWindow?.postMessage({type:"IFRAME_VISIBILITY",visible:r},"*")}},[h,m]);let ee=(0,s.useCallback)((e,t)=>{let r=new URL(window.location.href);r.searchParams.set("cwd",e),t?r.searchParams.set("sessionId",t):r.searchParams.delete("sessionId"),window.history.replaceState({},"",r.toString());let n=e.split("/").filter(Boolean).pop();document.title=n?`Cockpit - ${n}`:"Cockpit"},[]),et=(0,s.useRef)(!1);(0,s.useEffect)(()=>{if(!I||et.current||!e)return;et.current=!0,t&&(Q.current.set(e,{sessionId:t}),X.current.set(e,t));let r=m.findIndex(t=>t.cwd===e);if(r>=0)r!==h&&(f(r),G(m,r,p));else{let t=[...m,{cwd:e}],r=t.length-1;x(t),f(r),G(t,r,p)}ee(e,t)},[I,e,t,m,h,p,G,ee]),(0,s.useEffect)(()=>{let e=e=>{if(e.data?.type==="SESSION_CHANGE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:t,sessionId:r}=e.data;X.current.set(t,r);let n=m[h];n?.cwd===t&&ee(t,r)}if(e.data?.type==="SESSION_COMPLETE"&&e.data?.cwd&&e.data?.sessionId){let{cwd:r,sessionId:n,lastUserMessage:s}=e.data,o=m[h];if(o?.cwd!==r){var t;let e;t={projectName:r.split("/").pop()||r,message:s,cwd:r,sessionId:n},e=`session-toast-${Date.now()}-${Math.random().toString(36).slice(2,6)}`,F=[...F,{...t,id:e}],D()}}if(e.data?.type==="OPEN_TOKEN_STATS"&&C(!0),e.data?.type==="OPEN_NOTE"&&e.data?.cwd&&($(e.data.cwd),M(!0)),e.data?.type==="SCREENSHOT_PREPARE"&&e.data?.cwd){Y.current=h;let t=e.data.cwd,r=m.findIndex(e=>e.cwd===t);r>=0&&r!==h&&f(r);return}if(e.data?.type==="SCREENSHOT_DONE"){null!==Y.current&&Y.current!==h&&f(Y.current),Y.current=null;return}if(e.data?.type==="OPEN_PROJECT"&&e.data?.cwd){let{cwd:t,sessionId:r}=e.data,n=r||"";X.current.set(t,n);let s=m.findIndex(e=>e.cwd===t);if(s>=0){if(n){let e=J.current.get(t);e?.contentWindow&&e.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:n},"*")}s!==h&&(f(s),G(m,s,p))}else{let e=[...m,{cwd:t}],r=e.length-1;x(e),f(r),G(e,r,p),n&&Q.current.set(t,{sessionId:n})}ee(t,n)}};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)},[m,h,p,ee,G]);let er=(0,s.useCallback)(e=>{f(e),G(m,e,p);let t=m[e];if(t?.cwd){let e=X.current.get(t.cwd);ee(t.cwd,e)}},[m,p,G,ee]),en=(0,s.useCallback)(e=>{let t=m.filter((t,r)=>r!==e),r=h;e<h?r=h-1:e===h&&r>=t.length&&(r=Math.max(0,t.length-1)),x(t),f(r),G(t,r,p)},[m,h,p,G]),es=(0,s.useCallback)(e=>{let t=m[h],r=e.findIndex(e=>e.cwd===t?.cwd);x(e),f(r>=0?r:0),G(e,r>=0?r:0,p)},[m,h,p,G]),eo=(0,s.useCallback)(()=>{let e=!p;g(e),G(m,h,e)},[m,h,p,G]),el=(0,s.useCallback)((e,t)=>{X.current.set(e,t);let r=m.findIndex(t=>t.cwd===e);if(r>=0){let n=J.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),f(r),G(m,r,p)}else{let r=[...m,{cwd:e}],n=r.length-1;x(r),f(n),G(r,n,p),Q.current.set(e,{sessionId:t,switchToAgent:!0})}ee(e,t),v(!1)},[m,p,G,ee]),ea=(0,s.useCallback)((e,t)=>{X.current.set(e,t);let r=m.findIndex(t=>t.cwd===e);if(r>=0){let n=J.current.get(e);n?.contentWindow&&n.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t,switchToAgent:!0},"*"),r!==h&&(f(r),G(m,r,p))}else{let r=[...m,{cwd:e}],n=r.length-1;x(r),f(n),G(r,n,p),Q.current.set(e,{sessionId:t,switchToAgent:!0})}ee(e,t)},[m,h,p,G,ee]),ei=(0,s.useCallback)(e=>{let t=Q.current.get(e);if(t){let r=J.current.get(e);r?.contentWindow&&r.contentWindow.postMessage({type:"SWITCH_SESSION",sessionId:t.sessionId,switchToAgent:t.switchToAgent},"*"),Q.current.delete(e)}},[]);return I?(0,n.jsxs)("div",{className:"h-screen flex bg-background overflow-hidden",children:[(0,n.jsx)(l.ProjectSidebar,{projects:m,activeIndex:h,collapsed:p,currentCwd:m[h]?.cwd,onSelectProject:er,onRemoveProject:en,onReorderProjects:es,onToggleCollapse:eo,onOpenSessionBrowser:()=>v(!0),onOpenSettings:()=>y(!0),onOpenNote:e=>{$(e??null),M(!0)},onOpenSkills:()=>B(!0),onSwitchProject:ea,onAddProject:e=>{let t=m.findIndex(t=>t.cwd===e);if(t>=0)f(t),G(m,t,p);else{let t=[...m,{cwd:e}],r=t.length-1;x(t),f(r),G(t,r,p)}}}),(0,n.jsx)("div",{className:"flex-1 flex flex-col min-w-0 overflow-hidden",children:0===m.length?(0,n.jsx)(a.EmptyState,{onSelectSession:el}):(0,n.jsx)("div",{className:"flex-1 relative overflow-hidden",children:m.map((e,t)=>W.has(e.cwd)&&(0,n.jsx)("iframe",{ref:t=>{t?J.current.set(e.cwd,t):J.current.delete(e.cwd)},src:`/project?cwd=${encodeURIComponent(e.cwd)}`,onLoad:()=>ei(e.cwd),className:`absolute inset-0 w-full h-full border-0 ${t===h?"block":"hidden"}`,title:`Project: ${e.cwd}`},e.cwd))})}),(0,n.jsx)(i.SessionBrowser,{isOpen:b,onClose:()=>v(!1),onSelectSession:el,onAddProject:e=>{let t=m.findIndex(t=>t.cwd===e);if(t>=0)f(t),G(m,t,p);else{let t=[...m,{cwd:e}],r=t.length-1;x(t),f(r),G(t,r,p)}v(!1)}}),(0,n.jsx)(c.SettingsModal,{isOpen:j,onClose:()=>y(!1)}),(0,n.jsx)(w,{isOpen:N,onClose:()=>C(!1)}),(0,n.jsx)(k.NoteModal,{isOpen:S,onClose:()=>{M(!1),$(null)},projectCwd:T,projectName:T?T.split("/").pop():null}),(0,n.jsx)(P,{isOpen:R,onClose:()=>B(!1)}),(0,n.jsx)(_,{onNavigate:ea})]}):(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:u("workspace.loadingText")})]})})}},63728:(e,t,r)=>{r.d(t,{R8:()=>i,c0:()=>d,fY:()=>c,gT:()=>u});var n=r(95155),s=r(12115);let o=["agent","explorer","console"],l={agent:"AGENT",explorer:"EXPLORER",console:"CONSOLE"},a=(0,s.createContext)(null);function i(){let e=(0,s.useContext)(a);if(!e)throw Error("useSwipeContext must be used within SwipeableViewContainer");return e}function c({activeView:e,onViewChange:t,children:r}){let l=(0,s.useRef)(null),i=(0,s.useRef)(!1),d=(0,s.useRef)(0),[u,m]=(0,s.useState)(0),[x,h]=(0,s.useState)(!1),f=o.indexOf(e),p=o.length-1;(0,s.useEffect)(()=>{d.current=0,queueMicrotask(()=>m(0))},[e]),(0,s.useEffect)(()=>{let e=e=>{if(Math.abs(e.deltaX)>Math.abs(e.deltaY)&&Math.abs(e.deltaX)>2){let r=e.target;if("IFRAME"===r.tagName||function(e){for(;e;){let t=window.getComputedStyle(e).overflowX;if(("auto"===t||"scroll"===t)&&e.scrollWidth>e.clientWidth)return!0;e=e.parentElement}return!1}(r))return;e.preventDefault(),e.stopPropagation(),i.current&&(i.current=!1);let n=window.innerWidth,s=d.current-6*e.deltaX;!(f>0)&&s>0&&(s=0),!(f<p)&&s<0&&(s=0),d.current=s=Math.max(-n,Math.min(n,s)),m(s),h(!0),l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{let e=d.current,r=.12*n;h(!1),i.current=!0;let s=f;e<-r&&f<p?s=f+1:e>r&&f>0&&(s=f-1),d.current=0,m(0),s!==f&&t(o[s]),setTimeout(()=>{i.current=!1},80)},60)}};return document.addEventListener("wheel",e,{passive:!1,capture:!0}),()=>document.removeEventListener("wheel",e,{capture:!0})},[f,p,t]);let[g,b]=(0,s.useState)(!1);(0,s.useEffect)(()=>{queueMicrotask(()=>b(!0))},[]);let v={activeView:e,onViewChange:t,dragOffset:(()=>{if(!g)return 0;let e=window.innerWidth;return e?u/e:0})(),isDragging:g&&x};return(0,n.jsx)(a.Provider,{value:v,children:r})}function d({children:e}){let t,r,{activeView:l,dragOffset:a,isDragging:c}=i(),u=(0,s.useRef)(null),m=(0,s.useRef)(null),x=o.indexOf(l),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:c?"flex":"flex transition-transform duration-100 ease-out",style:{position:"absolute",top:"0px",bottom:"0px",left:"0px",width:`${100*o.length}%`,transform:(t=a/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:a}=i(),c=(0,s.useRef)(null),d=(0,s.useRef)([]),[u,m]=(0,s.useState)({left:0,width:0}),x=o.indexOf(e),h=()=>{if(!c.current||0===d.current.length)return{left:0,width:0};let e=c.current.getBoundingClientRect(),t=d.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)),l=Math.floor(s),a=Math.ceil(s),i=s-l,u=t[l],m=t[a];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:c,className:"relative flex gap-4",children:[o.map((e,r)=>(0,n.jsx)("button",{ref:e=>{d.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:l[e]},e)),(0,n.jsx)("div",{className:`absolute bottom-0 h-0.5 bg-brand ${a?"":"transition-all duration-100 ease-out"}`,style:{left:u.left,width:u.width}})]})}},69958:(e,t,r)=>{r.d(t,{ProjectSidebar:()=>p});var n=r(95155),s=r(12115),o=r(79114),l=r(2228);function a({currentCwd:e,onSwitchProject:t,collapsed:r,sessions:l}){let{t:i}=(0,o.Bd)(),[c,d]=(0,s.useState)(!1),[u,m]=(0,s.useState)(0),x=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!c)return;let e=e=>{x.current&&!x.current.contains(e.target)&&d(!1)},t=()=>{d(!1)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[c]);let h=(0,s.useCallback)(e=>{t(e.cwd,e.sessionId),d(!1)},[t]),f=l.filter(e=>"loading"===e.status).length,p=l.filter(e=>"unread"===e.status).length,g=(0,s.useCallback)(e=>{let t=Math.floor((u-e)/6e4);if(t<1)return i("common.justNow");if(t<60)return i("common.minutesAgo",{count:t});let r=Math.floor(t/60);return r<24?i("common.hoursAgo",{count:r}):i("common.daysAgo",{count:Math.floor(r/24)})},[i,u]);return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>{m(Date.now()),d(!c)},className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${r?"w-full justify-center":"w-full"}`,title:i("sessions.recentSessions"),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:"M13 10V3L4 14h7v7l9-11h-7z"})}),!r&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:i("sessions.recentSessions")}),f>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-orange-9 animate-pulse ${r?"absolute -top-1 -right-1":""}`,children:f}),p>0&&(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-red-500 ${r&&!f?"absolute -top-1 -right-1":""}`,children:p})]}),c&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 h-[450px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:i("sessions.recentSessions")}),f>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-orange-11",children:["(",i("sessions.runningCount",{count:f}),")"]}),p>0&&(0,n.jsxs)("span",{className:"ml-2 text-xs text-red-500",children:["(",i("sessions.unreadCount",{count:p}),")"]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===l.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:i("sessions.noSessions")}):l.map((t,r)=>{let s;return(0,n.jsxs)("button",{onClick:()=>h(t),className:`w-full px-3 py-2 text-left hover:bg-accent transition-colors flex items-start gap-2 ${r!==l.length-1?"border-b border-border/50":""} ${e===t.cwd?"bg-accent/50":""}`,children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${"loading"===t.status?"bg-orange-9 animate-pulse":"unread"===t.status?"bg-red-500":"bg-muted-foreground/30"}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",title:t.cwd,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:(s=t.cwd).split("/").pop()||s}),"loading"===t.status&&(0,n.jsx)("span",{className:"text-xs text-orange-11 flex-shrink-0",children:i("sessions.running")}),"unread"===t.status&&(0,n.jsx)("span",{className:"text-xs text-red-500 flex-shrink-0",children:i("sessions.done")}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:g(t.lastActive)})]}),(t.lastUserMessage||t.title)&&(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:t.lastUserMessage||t.title})]})]},`${t.cwd}-${t.sessionId}`)})})]})]})}function i({collapsed:e,pinnedSessions:t,onSwitchProject:r,onUnpin:l,onUpdateTitle:a,onReorder:c}){let{t:d}=(0,o.Bd)(),[u,m]=(0,s.useState)(!1),x=(0,s.useRef)(null),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),[v,j]=(0,s.useState)(null),[w,y]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!u)return;let e=e=>{x.current&&!x.current.contains(e.target)&&(m(!1),f(null))},t=()=>{m(!1),f(null)};return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[u]),(0,s.useEffect)(()=>{h&&(b.current?.focus(),b.current?.select())},[h]);let k=(0,s.useCallback)(e=>{h||(r(e.cwd,e.sessionId),m(!1))},[r,h]),N=(0,s.useCallback)((e,t)=>{t.stopPropagation(),f(e.sessionId),g(e.customTitle||"")},[]),C=(0,s.useCallback)(()=>{h&&p.trim()&&a(h,p.trim()),f(null)},[h,p,a]),S=(0,s.useCallback)(e=>{j(e)},[]),L=(0,s.useCallback)((e,t)=>{e.preventDefault(),y(t)},[]),E=(0,s.useCallback)(e=>{if(null===v||v===e){j(null),y(null);return}let r=[...t],[n]=r.splice(v,1);r.splice(e,0,n),c(r),j(null),y(null)},[v,t,c]),M=(0,s.useCallback)(()=>{j(null),y(null)},[]);return(0,n.jsxs)("div",{className:"relative",ref:x,children:[(0,n.jsxs)("button",{onClick:()=>m(!u),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${e?"w-full justify-center":"w-full"}`,title:d("sessions.pinnedSessions"),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:d("sessions.pinnedSessions")}),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-accent",children:t.length})]}),u&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-80 max-h-[450px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg",children:(0,n.jsx)("span",{className:"text-sm font-medium",children:d("sessions.pinnedSessions")})}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:d("sessions.noPinnedSessions")}):t.map((e,r)=>{let s;return(0,n.jsxs)("div",{draggable:!0,onDragStart:()=>S(r),onDragOver:e=>L(e,r),onDrop:()=>E(r),onDragEnd:M,onClick:()=>k(e),className:`group w-full px-3 py-2 text-left hover:bg-accent transition-colors flex items-start gap-2 cursor-pointer ${r!==t.length-1?"border-b border-border/50":""} ${v===r?"opacity-50":""} ${w===r?"border-t-2 border-brand":""}`,children:[(0,n.jsx)("span",{className:"mt-1.5 text-muted-foreground/30 flex-shrink-0 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",title:e.cwd,children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsx)("span",{className:"font-medium text-sm truncate",children:(s=e.cwd).split("/").pop()||s})}),h===e.sessionId?(0,n.jsx)("input",{ref:b,type:"text",value:p,onChange:e=>g(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||("Enter"===e.key&&C(),"Escape"===e.key&&f(null))},onBlur:C,onClick:e=>e.stopPropagation(),className:"w-full text-xs px-1 py-0.5 border border-border rounded bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring mt-0.5"}):(0,n.jsx)("div",{className:"text-xs text-foreground/80 truncate",children:e.customTitle||e.sessionId.slice(0,8)})]}),h!==e.sessionId&&(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity mt-0.5",children:[(0,n.jsx)("button",{onClick:t=>N(e,t),className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:d("sessions.editTitle"),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:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})})}),(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),l(e.sessionId)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:d("sessions.remove"),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.sessionId)})})]})]})}var c=r(93777);function d(e,t){if("once"===e.type)return t("scheduledTasks.onceType",{minutes:e.delayMinutes});if("interval"===e.type){let r=t("scheduledTasks.everyNMinutes",{minutes:e.intervalMinutes});return e.activeFrom&&e.activeTo?`${r} (${e.activeFrom}-${e.activeTo})`:r}return"cron"===e.type?e.cron||"cron":e.type}function u(e){return e.unread?"bg-red-500":e.completed?"bg-muted-foreground":e.paused?"bg-yellow-500":"error"===e.lastResult?"bg-red-500":"bg-green-500"}function m({collapsed:e,tasks:t,unreadCount:r,onSwitchProject:l,onPause:a,onResume:i,onTrigger:x,onDelete:h,onMarkRead:f,onUpdateTask:p,onReorder:g}){let{t:b}=(0,o.Bd)(),[v,j]=(0,s.useState)(!1),[w,y]=(0,s.useState)(null),k=(0,s.useRef)(null),N=t.filter(e=>!e.completed),C=N.filter(e=>!e.paused).length,S=t.filter(e=>e.completed),[L,E]=(0,s.useState)(null),[M,T]=(0,s.useState)(null),$=(0,s.useCallback)(e=>{E(e)},[]),P=(0,s.useCallback)((e,t)=>{e.preventDefault(),T(t)},[]),R=(0,s.useCallback)(e=>{if(null===L||L===e){E(null),T(null);return}let t=[...N],[r]=t.splice(L,1);t.splice(e,0,r),g([...t,...S].map(e=>e.id)),E(null),T(null)},[L,N,S,g]),B=(0,s.useCallback)(()=>{E(null),T(null)},[]),[,F]=(0,s.useState)(0);return(0,s.useEffect)(()=>{if(!v)return;let e=setInterval(()=>F(e=>e+1),1e4);return()=>clearInterval(e)},[v]),(0,s.useEffect)(()=>{if(!v)return;let e=e=>{k.current&&!k.current.contains(e.target)&&j(!1)},t=()=>j(!1);return document.addEventListener("mousedown",e),window.addEventListener("blur",t),()=>{document.removeEventListener("mousedown",e),window.removeEventListener("blur",t)}},[v]),(0,n.jsxs)("div",{className:"relative",ref:k,children:[(0,n.jsxs)("button",{onClick:()=>j(!v),className:`relative flex items-center gap-2 px-2 py-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors ${e?"w-full justify-center":"w-full"}`,title:b("scheduledTasks.title"),children:[(0,n.jsxs)("svg",{className:"w-5 h-5 flex-shrink-0",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)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6l4 2"})]}),!e&&(0,n.jsx)("span",{className:"text-sm flex-1 text-left",children:b("scheduledTasks.title")}),r>0?(0,n.jsx)("span",{className:`min-w-[18px] h-[18px] px-1 text-white text-xs font-medium rounded-full flex items-center justify-center bg-red-500 ${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-accent",children:t.length}):null]}),v&&(0,n.jsxs)("div",{className:"absolute left-full bottom-0 ml-2 w-96 max-h-[500px] bg-popover border border-border rounded-lg shadow-lg z-50 flex flex-col",children:[(0,n.jsxs)("div",{className:"px-3 py-2 border-b border-border bg-muted/50 flex-shrink-0 rounded-t-lg flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-sm font-medium",children:b("scheduledTasks.title")}),N.length>0&&(0,n.jsxs)("span",{className:"text-xs text-muted-foreground",children:[b("scheduledTasks.activeCount",{running:C}),N.length-C>0?` \xb7 ${b("scheduledTasks.pausedCount",{paused:N.length-C})}`:""]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:0===t.length?(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-muted-foreground text-center",children:b("scheduledTasks.noScheduledTasks")}):(0,n.jsxs)(n.Fragment,{children:[N.map((e,t)=>{var r;return(0,n.jsx)("div",{draggable:!0,onDragStart:()=>$(t),onDragOver:e=>P(e,t),onDrop:()=>R(t),onDragEnd:B,className:`group px-3 py-2 hover:bg-accent transition-colors border-b border-border/50 cursor-pointer ${e.unread?"bg-brand/5":""} ${L===t?"opacity-50":""} ${M===t?"border-t-2 border-brand":""}`,onClick:()=>{l(e.cwd,e.sessionId),e.unread&&f(e.id),j(!1)},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${u(e)}`}),(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)("span",{className:"text-xs text-muted-foreground font-mono",children:(r=e.cwd).split("/").pop()||r}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:"\xb7"}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground",children:e.completed?b("scheduledTasks.completed"):e.paused?b("scheduledTasks.paused"):b("common.running")})]}),(0,n.jsx)("div",{className:"text-sm text-foreground truncate mt-0.5",title:e.message,children:e.message}),(0,n.jsxs)("div",{className:"flex items-center gap-3 mt-1 text-xs text-muted-foreground",children:[(0,n.jsx)("span",{children:d(e,b)}),(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsx)("span",{children:e.paused?b("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,b)}),e.lastFiredAt&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{children:"\xb7"}),(0,n.jsxs)("span",{children:[b("scheduledTasks.lastResult"),": ","success"===e.lastResult?"✓":"✗"]})]})]})]}),(0,n.jsxs)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),x(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-brand",title:b("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(),y(e)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground",title:b("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"})})}),e.paused?(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),i(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-green-500",title:b("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(),a(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-yellow-500",title:b("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(),h(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:b("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"})})})]})]})},e.id)}),S.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-1.5 text-xs text-muted-foreground bg-muted/30 border-b border-border/50",children:b("scheduledTasks.completedCount",{count:S.length})}),S.map(e=>(0,n.jsx)("div",{className:"group px-3 py-2 hover:bg-accent transition-colors border-b border-border/50 opacity-60 cursor-pointer",onClick:()=>{l(e.cwd,e.sessionId),j(!1)},children:(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:`mt-1.5 w-2 h-2 rounded-full flex-shrink-0 ${u(e)}`}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-foreground truncate",children:e.message}),(0,n.jsxs)("div",{className:"text-xs text-muted-foreground mt-0.5",children:[d(e,b)," \xb7 ","success"===e.lastResult?b("scheduledTasks.success"):b("scheduledTasks.failure")]})]}),(0,n.jsx)("div",{className:"flex-shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),h(e.id)},className:"p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-destructive",title:b("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"})})})})]})},e.id))]})]})})]}),w&&(0,n.jsxs)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-black/30",onClick:()=>y(null)}),(0,n.jsx)("div",{className:"relative",children:(0,n.jsx)(c.E,{onClose:()=>y(null),onCreate:()=>{},editTask:{id:w.id,message:w.message,type:w.type,delayMinutes:w.delayMinutes,intervalMinutes:w.intervalMinutes,activeFrom:w.activeFrom,activeTo:w.activeTo,cron:w.cron},onUpdate:(e,t)=>{p(e,t),y(null)}})})]})]})}var x=r(3292),h=r(23121),f=r(2111);function p({projects:e,activeIndex:t,collapsed:r,currentCwd:c,onSelectProject:d,onRemoveProject:u,onReorderProjects:g,onToggleCollapse:b,onOpenSessionBrowser:v,onOpenSettings:j,onOpenNote:w,onOpenSkills:y,onSwitchProject:k,onAddProject:N}){let{t:C}=(0,o.Bd)(),{pinnedSessions:S,unpinSession:L,updateTitle:E,reorder:M}=(0,x.P)(),{tasks:T,unreadCount:$,reload:P,pauseTask:R,resumeTask:B,triggerTask:F,deleteTask:I,updateTask:D,markRead:A,reorderTasks:_}=(0,h.n)(),[W,z]=(0,s.useState)(!1),[H,O]=(0,s.useState)(null),[q,V]=(0,s.useState)(null),[K,U]=(0,s.useState)([]),J=(0,s.useRef)(K);(0,s.useEffect)(()=>{J.current=K});let Q=(0,s.useRef)(P);(0,s.useEffect)(()=>{Q.current=P});let X=(0,s.useCallback)(e=>{try{if("task-fired"===e.type)return void Q.current();let{data:t}=e;if(!t)return;U(t.sessions||[])}catch{}},[]);(0,f.h)({url:"/ws/global-state",onMessage:X});let Y=new Set(K.filter(e=>"loading"===e.status).map(e=>e.cwd)),Z=new Set(K.filter(e=>"unread"===e.status).map(e=>e.cwd)),G=(0,s.useCallback)(e=>{O(e)},[]),ee=(0,s.useCallback)((e,t)=>{e.preventDefault(),null!==H&&H!==t&&V(t)},[H]),et=(0,s.useCallback)(t=>{if(null!==H&&H!==t){let r=[...e],[n]=r.splice(H,1);r.splice(t,0,n),g(r)}O(null),V(null)},[H,e,g]),er=(0,s.useCallback)(()=>{O(null),V(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:"p-2 border-b border-border relative",onMouseEnter:()=>z(!0),onMouseLeave:()=>z(!1),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-accent transition-colors ${r?"justify-center":""}`,onClick:v,title:C("workspace.openProject"),children:[(0,n.jsxs)("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)("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]}),!r&&(0,n.jsx)("span",{className:"text-sm",children:C("workspace.openProject")})]}),W&&(r?(0,n.jsx)("button",{className:"absolute inset-0 m-2 flex items-center justify-center px-2 py-2 rounded-lg bg-accent text-foreground transition-colors z-10",onClick:b,title:C("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-accent text-foreground transition-colors z-10",onClick:b,title:C("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:()=>G(s),onDragOver:e=>ee(e,s),onDrop:()=>et(s),onDragEnd:er,className:`${q===s?"border-t-2 border-brand":""} ${H===s?"opacity-50":""}`,children:(0,n.jsx)(l.ProjectItem,{index:s,name:(a=(o=e.cwd).split("/").filter(Boolean))[a.length-1]||o,cwd:e.cwd,isActive:s===t,collapsed:r,hasUnread:Z.has(e.cwd),isLoading:Y.has(e.cwd),onClick:()=>d(s),onRemove:()=>u(s),onOpenNote:()=>w(e.cwd)})},e.cwd)})}),(0,n.jsxs)("div",{className:"p-2 border-t border-border space-y-1",children:[(0,n.jsx)(a,{currentCwd:c,onSwitchProject:k,collapsed:r,sessions:K}),(0,n.jsx)(i,{collapsed:r,pinnedSessions:S,onSwitchProject:k,onUnpin:L,onUpdateTitle:E,onReorder:M}),(0,n.jsx)(m,{collapsed:r,tasks:T,unreadCount:$,onSwitchProject:k,onPause:R,onResume:B,onTrigger:F,onDelete:I,onMarkRead:A,onUpdateTask:D,onReorder:_}),(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-accent transition-colors ${r?"justify-center":""}`,onClick:()=>w(),title:C("workspace.notes"),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:C("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-accent transition-colors ${r?"justify-center":""}`,onClick:y,title:C("workspace.skills"),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:"M12 3l1.9 4.8L19 9l-4.1 3.1L16 18l-4-2.8L8 18l1.1-5.9L5 9l5.1-1.2L12 3z"})}),!r&&(0,n.jsx)("span",{className:"text-sm",children:C("workspace.skills")})]}),(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-accent transition-colors ${r?"justify-center":""}`,onClick:j,title:C("workspace.settings"),children:[(0,n.jsxs)("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:"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&&(0,n.jsx)("span",{className:"text-sm",children:C("workspace.settings")})]})]})]})}},70188:(e,t,r)=>{r.d(t,{Ee:()=>m,SU:()=>c,ft:()=>u,iN:()=>d});var n=r(95155),s=r(12115),o=r(79114),l=r(47650),a=r(34075);let i=(0,s.createContext)(null);function c({container:e,children:t}){return(0,n.jsx)(i.Provider,{value:e,children:t})}function d(){return(0,s.useContext)(i)}function u({x:e,y:t,path:r,cwd:c,isDirectory:d,onClose:m,onCreateFile:x,onDelete:h,onRefresh:f,onCopyFile:p,onPaste:g}){let{t:b}=(0,o.Bd)(),v=(0,s.useRef)(null),j=(0,s.useContext)(i),w=r.split("/").pop()||r,y=`${c}/${r}`,k=r.includes("/")?r.substring(0,r.lastIndexOf("/")):"",N=k?`${c}/${k}`:c,C=d?r:k,S=d?y:N;(0,s.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&m()},t=e=>{"Escape"===e.key&&m()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[m]);let[L,E]=(0,s.useState)({x:0,y:0});(0,s.useEffect)(()=>{if(v.current&&j){let r=j.getBoundingClientRect(),n=v.current.getBoundingClientRect(),s=e-r.left,o=t-r.top;s=Math.min(s,r.width-n.width-8),o=Math.min(o,r.height-n.height-8),E({x:s=Math.max(8,s),y:o=Math.max(8,o)})}else if(v.current){let r=v.current.getBoundingClientRect();E({x:Math.max(8,Math.min(e,window.innerWidth-r.width-8)),y:Math.max(8,Math.min(t,window.innerHeight-r.height-8))})}},[e,t,j]);let M=(0,s.useCallback)(async(e,t)=>{try{await navigator.clipboard.writeText(e),(0,a.oR)(b("toast.copiedName",{name:t}),"success")}catch{(0,a.oR)(b("toast.copyFailed"),"error")}m()},[m,b]),T=d?r:k,$=[{label:b("fileContextMenu.copyRelativePath"),value:r},{label:b("fileContextMenu.copyAbsolutePath"),value:y},{label:b("fileContextMenu.copyRelativeDirPath"),value:C||"."},{label:b("fileContextMenu.copyAbsoluteDirPath"),value:S},{label:d?b("fileContextMenu.copyFolderName"):b("fileContextMenu.copyFileName"),value:w}],P=(0,n.jsxs)("div",{ref:v,className:"absolute z-[200] bg-card border border-border rounded-lg shadow-lg py-1 w-fit whitespace-nowrap",style:{left:L.x,top:L.y},children:[x&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),x(T)},children:b("fileContextMenu.createFile")}),p&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),p(r)},children:d?b("fileContextMenu.copyFolder"):b("fileContextMenu.copyFile")}),g&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>{m(),g(T)},children:b("fileContextMenu.pasteHere")}),h&&(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-destructive hover:bg-accent transition-colors",onClick:()=>{m(),h(r,d,w)},children:d?b("fileContextMenu.deleteFolder"):b("fileContextMenu.deleteFile")}),(x||h||p||g)&&(0,n.jsx)("div",{className:"my-1 border-t border-border"}),$.map((e,t)=>(0,n.jsx)("button",{className:"block w-full px-3 py-1.5 text-left text-sm text-foreground hover:bg-accent transition-colors",onClick:()=>M(e.value,e.label),children:e.label},t))]});return j?(0,l.createPortal)(P,j):P}function m(){let[e,t]=(0,s.useState)(null);return{contextMenu:e,showContextMenu:(0,s.useCallback)((e,r,n)=>{e.preventDefault(),e.stopPropagation(),t({x:e.clientX,y:e.clientY,path:r,isDirectory:n})},[]),hideContextMenu:(0,s.useCallback)(()=>{t(null)},[])}}},75346:(e,t,r)=>{r.d(t,{n:()=>s});var n=r(88292);let s={SessionChange:(0,n.R)("session-change"),ViewChange:(0,n.R)("view-change"),OpenNote:(0,n.R)("open-note"),LangChange:(0,n.R)("lang-change"),TabAdd:(0,n.R)("tab-add"),TabClose:(0,n.R)("tab-close"),SwitchSession:(0,n.R)("switch-session"),ProjectChange:(0,n.R)("project-change"),OpenProject:(0,n.R)("open-project"),SessionComplete:(0,n.R)("session-complete"),OpenTokenStats:(0,n.R)("open-token-stats"),PinnedSessionsChanged:(0,n.R)("pinned-sessions-changed"),ScheduledTasksChanged:(0,n.R)("scheduled-tasks-changed"),ScreenshotPrepare:(0,n.R)("screenshot-prepare"),ScreenshotDone:(0,n.R)("screenshot-done")}},76043:(e,t,r)=>{r.d(t,{NoteToolbar:()=>a});var n=r(95155),s=r(12115),o=r(79114);function l({editor:e,onClose:t,position:r}){let{t:a}=(0,o.Bd)(),[i,c]=(0,s.useState)(()=>e.getAttributes("link").href||""),d=(0,s.useRef)(null);(0,s.useEffect)(()=>{d.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-lg p-2 flex items-center gap-2`,style:m,children:[(0,n.jsx)("input",{ref:d,type:"text",value:i,onChange:e=>c(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),u()):"Escape"===e.key&&(e.preventDefault(),t())},placeholder:a("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:a("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-500 hover:bg-red-500/10 transition-colors",title:a("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 a({editor:e}){let{t}=(0,o.Bd)(),[r,i]=(0,s.useState)(!1),c=(0,s.useRef)(null),[,d]=(0,s.useState)(0);if((0,s.useEffect)(()=>{if(!e)return;let t=()=>d(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-accent"}`,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:c,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)(l,{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-500 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-500 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-500 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-500 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:()=>i});var n=r(95155),s=r(12115),o=r(79114),l=r(86957),a=r(76900);function i({onSelectSession:e}){let{t}=(0,o.Bd)(),[r,c]=(0,s.useState)([]),[d,u]=(0,s.useState)({}),[m,x]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null),[p,g]=(0,s.useState)(""),b=(0,s.useRef)(null),v=(0,s.useCallback)(async()=>{x(!0),f(null),u({});let e=await l.t4.runPromiseExit((0,a.H7)());"Success"===e._tag?c(e.value):f("Failed to load projects"),x(!1)},[]),j=(0,s.useCallback)(async e=>{u(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await l.t4.runPromiseExit((0,a.QW)(e));"Success"===t._tag?u(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):u(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),w=(0,s.useCallback)(e=>{let t=d[e];t?.isExpanded?u(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?u(t=>({...t,[e]:{...t[e],isExpanded:!0}})):j(e)},[d,j]);return(0,s.useEffect)(()=>{v(),setTimeout(()=>{b.current?.focus()},100)},[v]),(0,n.jsxs)("div",{className:"flex-1 flex flex-col bg-card",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border",children:[(0,n.jsx)("h2",{className:"text-lg font-medium text-foreground",children:t("workspace.selectProject")}),(0,n.jsx)("input",{ref:b,type:"text",placeholder:t("workspace.searchProjectPath"),value:p,onChange:e=>g(e.target.value),className:"px-3 py-1.5 text-sm border border-border rounded-lg bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[m&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm 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:t("workspace.loadingProjects")})]})}),h&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)("div",{className:"text-sm text-red-500",children:h})}),!m&&!h&&0===r.length&&(0,n.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,n.jsx)("div",{className:"text-sm text-muted-foreground",children:t("workspace.projectNotFound")})}),!m&&!h&&(0,n.jsx)("div",{className:"space-y-2",children:r.filter(e=>e.fullPath.toLowerCase().includes(p.toLowerCase())).map(r=>{let s=d[r.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null};return(0,n.jsxs)("div",{className:"border border-border rounded-lg overflow-hidden",children:[(0,n.jsxs)("button",{onClick:()=>w(r.encodedPath),className:"w-full flex items-center gap-3 p-3 hover:bg-accent transition-colors text-left",children:[(0,n.jsx)("svg",{className:`w-4 h-4 text-muted-foreground transition-transform ${s.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-5 h-5 text-brand",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.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-foreground truncate",children:r.name}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground truncate",children:r.fullPath})]}),(0,n.jsx)("span",{className:"text-xs text-muted-foreground bg-secondary px-2 py-0.5 rounded",children:t("workspace.sessions",{count:r.sessionCount})})]}),s.isExpanded&&(0,n.jsxs)("div",{className:"border-t border-border bg-secondary/30",children:[s.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-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:t("workspace.loadingSessions")})]}),s.error&&(0,n.jsx)("div",{className:"p-3 text-xs text-red-500",children:s.error}),!s.isLoading&&!s.error&&0===s.sessions.length&&(0,n.jsx)("div",{className:"p-3 text-xs text-muted-foreground",children:t("workspace.noSessions")}),!s.isLoading&&!s.error&&s.sessions.map(t=>(0,n.jsxs)("button",{onClick:()=>{e(r.fullPath,(t.path.split("/").pop()||"").replace(".jsonl",""))},className:"w-full flex items-start gap-3 p-3 hover:bg-accent transition-colors text-left border-t border-border first:border-t-0",children:[(0,n.jsx)("svg",{className:"w-4 h-4 text-muted-foreground mt-0.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:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-foreground truncate",children:t.title}),(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:new Date(t.modifiedAt).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}),t.firstMessages.length>0&&(0,n.jsx)("div",{className:"text-xs text-muted-foreground mt-1 truncate",children:t.firstMessages[0]})]})]},t.path))]})]},r.encodedPath)})})]})]})}},76412:(e,t,r)=>{r.d(t,{TabManagerTopBar:()=>p});var n=r(95155),s=r(12115),o=r(63728),l=r(82032),a=r(34075),i=r(79114),c=r(95045),d=r(75346),u=r(49433),m=r(86957),x=r(53213),h=r(76900);function f({cwd:e,currentBranch:t,onSwitched:r}){let{t:o}=(0,i.Bd)(),[l,c]=(0,s.useState)(!1),[d,u]=(0,s.useState)([]),[p,g]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[j,w]=(0,s.useState)(""),y=(0,s.useRef)(null),k=(0,s.useRef)(null),N=(0,s.useCallback)(async()=>{g(!0);let t=await m.t4.runPromiseExit((0,x.r4)(e));if("Success"===t._tag){let e=t.value,r=e.local??[];u([...r,...(e.remote??[]).filter(e=>!r.includes(e.replace(/^origin\//,"")))])}else(0,a.oR)(o("toast.loadBranchFailed"),"error");g(!1)},[e,o]),C=(0,s.useCallback)(()=>{c(!0),w(""),N()},[N]),S=(0,s.useCallback)(()=>{c(!1)},[]);(0,s.useEffect)(()=>{if(!l)return;let e=e=>{y.current&&!y.current.contains(e.target)&&S()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l,S]),(0,s.useEffect)(()=>{l&&setTimeout(()=>k.current?.focus(),50)},[l]);let L=async t=>{v(!0);let n=await m.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")}v(!1)},E=d.filter(e=>e!==t&&e.toLowerCase().includes(j.toLowerCase()));return(0,n.jsxs)("div",{className:"relative",ref:y,children:[(0,n.jsx)("button",{onClick:l?S:C,className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent 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"})})}),l&&(0,n.jsxs)("div",{className:"absolute top-full left-0 mt-1 w-64 bg-popover border border-border rounded-lg shadow-lg z-50 overflow-hidden",children:[(0,n.jsx)("div",{className:"p-2 border-b border-border",children:(0,n.jsx)("input",{ref:k,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 placeholder:text-muted-foreground",onKeyDown:e=>{"Escape"===e.key&&S()}})}),(0,n.jsx)("div",{className:"max-h-60 overflow-y-auto p-1",children:p?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:o("common.loading")}):0===E.length?(0,n.jsx)("div",{className:"text-xs text-muted-foreground text-center py-4",children:j?o("git.noMatchingBranches"):o("git.noBranches")}):E.map(e=>(0,n.jsx)("button",{onClick:()=>L(e),disabled:b,className:"w-full text-left px-2.5 py-1.5 text-sm rounded hover:bg-accent transition-colors truncate disabled:opacity-50",children:(0,n.jsx)("span",{className:e.startsWith("origin/")?"text-muted-foreground":"text-foreground",children:e})},e))})]})]})}function p({initialCwd:e,activeTab:t,isGitRepo:r,currentBranch:s,onOpenWorktree:x,onOpenProjectSessions:g,onOpenAliasManager:b,onBranchSwitched:v}){let{t:j}=(0,i.Bd)();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:j("tabManagerTopBar.copyPageUrl"),onClick:()=>{navigator.clipboard.writeText(window.location.href).then(()=>{(0,a.oR)(j("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",title:`CWD: ${e}`,children:e}),(0,n.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(e),(0,a.oR)(j("toast.copiedDirPath"))},className:"p-1 text-muted-foreground hover:text-foreground hover:bg-accent rounded transition-colors",title:j("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:x,className:"flex items-center gap-1.5 px-2 py-1.5 text-muted-foreground hover:text-foreground hover:bg-accent 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)(f,{cwd:e,currentBranch:s,onSwitched:()=>v?.()})]})]}),(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)(l.ReviewDropdown,{cwd:e}),(0,n.jsx)("button",{onClick:()=>window.location.reload(),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("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"})})}),e&&(0,n.jsx)("button",{onClick:g,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("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:()=>{t?.cwd&&m.t4.runFork((0,h.em)(t.cwd).pipe(u.orElse(()=>u.void)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("tabManagerTopBar.openInVSCode"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M17.583 2.213L12 7.393 6.417 2.213 1 6.17v11.66l5.417 3.957L12 16.607l5.583 5.18L23 17.83V6.17l-5.417-3.957zM6.417 17.83L3 15.33V8.67l3.417-2.5v11.66zm11.166 0V6.17L21 8.67v6.66l-3.417 2.5z"})})}),(0,n.jsx)("button",{onClick:()=>{t?.cwd&&m.t4.runFork((0,h.Q1)(t.cwd).pipe(u.orElse(()=>u.void)))},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("tabManagerTopBar.openInCursor"),children:(0,n.jsx)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M4.5 2L20.5 12L4.5 22V2Z"})})}),t?.sessionId&&(0,n.jsx)("button",{onClick:()=>{let e=`claude -r ${t.sessionId}`;navigator.clipboard.writeText(e).then(()=>{(0,a.oR)(j("toast.copiedCommand",{command:e}),"success")})},className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("chat.copyCommandTooltip",{sessionId:t.sessionId}),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:b,className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("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,c.F)(d.n.OpenTokenStats,{}),className:"p-2 text-muted-foreground hover:text-foreground hover:bg-accent rounded-lg transition-colors",title:j("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-accent rounded-lg transition-colors",title:j("tabManagerTopBar.openSurething"),children:(0,n.jsx)("img",{src:"https://surething.io/logo.png?from=cockpit",alt:"Surething",className:"w-5 h-5 rounded-sm"})})]})]})})}},76900:(e,t,r)=>{r.d(t,{Cq:()=>x,D0:()=>p,DZ:()=>i,H7:()=>h,It:()=>b,Kl:()=>y,M5:()=>a,Or:()=>d,Q1:()=>j,QW:()=>f,Wr:()=>c,Yn:()=>g,b2:()=>w,em:()=>v,zF:()=>m});var n=r(49433),s=r(82680);let o=(e,t)=>n.tryPromise({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)=>o(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=()=>o("/api/settings"),i=e=>o("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>o("/api/version"),d=()=>o("/api/extension/version"),u=e=>e?`/api/note?cwd=${encodeURIComponent(e)}`:"/api/note",m=e=>o(u(e)),x=(e,t)=>l(u(e),{content:t}),h=()=>o("/api/sessions/projects"),f=e=>o(`/api/sessions/projects/${encodeURIComponent(e)}`),p=e=>o(`/api/project-settings?cwd=${encodeURIComponent(e)}`),g=e=>l("/api/project-settings",e),b=()=>o("/api/pick-folder"),v=e=>l("/api/open-vscode",{cwd:e}),j=e=>l("/api/open-cursor",{cwd:e}),w=e=>o(`/api/git/worktree?cwd=${encodeURIComponent(e)}`),y=e=>l("/api/git/worktree",e)},82292:(e,t,r)=>{function n(e,t){for(let r of e){if(r.path===t)return r;if(r.children){let e=n(r.children,t);if(e)return e}}return null}function s(e,t){if(!e)return"";let r=n(t,e);if(r?.isDirectory)return e;let s=e.split("/");return s.pop(),s.join("/")}function o(e){let t=[];for(let r of e){let e=r.split("/"),n=t;for(let t=0;t<e.length;t++){let r=e[t],s=t===e.length-1,o=e.slice(0,t+1).join("/"),l=n.find(e=>e.name===r);l||(l={name:r,path:o,isDirectory:!s,children:s?void 0:[]},n.push(l)),!s&&l.children&&(n=l.children)}}let r=e=>{e.sort((e,t)=>e.isDirectory&&!t.isDirectory?-1:!e.isDirectory&&t.isDirectory?1:e.name.localeCompare(t.name)),e.forEach(e=>{e.children&&r(e.children)})};return r(t),t}function l(e){let t=[],r=e=>{for(let n of e)n.isDirectory&&(t.push(n.path),n.children&&r(n.children))};return r(e),t}r.d(t,{B_:()=>h,HR:()=>function e(t,r){if(0===r.length)return t;let n=new Map(r.map(e=>[e.path,e]));return t.map(t=>{let r=n.get(t.path);return r&&t.isDirectory?void 0===t.children&&void 0!==r.children?{...t,children:r.children}:void 0!==t.children&&void 0!==r.children?{...t,children:e(t.children,r.children)}:t:t})},KH:()=>d,MB:()=>n,S7:()=>s,fw:()=>u,q3:()=>c,r6:()=>m,tE:()=>x,tW:()=>l,u:()=>i,v3:()=>o});let a=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp"]);function i(e){let t=e.split(".").pop()?.toLowerCase();return a.has(t||"")}function c(e,t,r=!1){let n=new Set;if(!t)return n;let s=t.toLowerCase(),o=e=>{if(n.add(e.path),e.children)for(let t of e.children)o(t)},l=(e,t)=>{let a=e.name.toLowerCase(),i=r?a===s:a.includes(s);if(i&&e.children)return o(e),t.forEach(e=>n.add(e)),!0;let c=!1;if(e.children)for(let r of e.children)l(r,[...t,e.path])&&(c=!0);return(!!i||!!c)&&(n.add(e.path),t.forEach(e=>n.add(e)),!0)};for(let t of e)l(t,[]);return n}function d(e,t,r=!1){let n=new Set;if(!t)return n;let s=t.toLowerCase();for(let t of e){let e=t.split("/");for(let t=0;t<e.length;t++){let o=e[t].toLowerCase();if(r?o===s:o.includes(s)){for(let t=0;t<=e.length-1;t++)n.add(e.slice(0,t+1).join("/"));break}}}return n}function u(e){let t=Math.floor(Math.floor((Date.now()-1e3*e)/1e3)/60),r=Math.floor(t/60),n=Math.floor(r/24),s=Math.floor(n/30),o=Math.floor(n/365);return o>0?`${o}y ago`:s>0?`${s}mo ago`:n>0?`${n}d ago`:r>0?`${r}h ago`:t>0?`${t}m ago`:"just now"}function m(e){let t=new Date(e),r=new Date,n=t.getFullYear()===r.getFullYear(),s=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0"),l=String(t.getHours()).padStart(2,"0"),a=String(t.getMinutes()).padStart(2,"0");return n?`${s}-${o} ${l}:${a}`:`${t.getFullYear()}-${s}-${o} ${l}:${a}`}let x=()=>{},h=50},83448:(e,t,r)=>{r.d(t,{Cr:()=>b,JC:()=>u,M5:()=>c,QW:()=>h,Zr:()=>x,an:()=>g,em:()=>i,l1:()=>d,n_:()=>m,qD:()=>p,td:()=>a});var n=r(49433),s=r(82680);let o=(e,t)=>n.tryPromise({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)=>o(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),a=()=>o("/api/settings"),i=e=>o("/api/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),c=()=>o("/api/commands"),d=()=>o("/api/skills"),u=e=>l("/api/bash",e),m=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/session-by-path",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});return t.ok?await t.json():null},catch:e=>new s.uV({message:"POST /api/session-by-path failed",cause:e})}),x=(e,t)=>l(`/api/session/${encodeURIComponent(e)}/fork`,t),h=e=>o(`/api/sessions/projects/${encodeURIComponent(e)}`),f=()=>n.tryPromise({try:async()=>{let e=await fetch("/api/ollama/models");return 503===e.status?{_tag:"not-running"}:e.ok?{_tag:"ok",models:(await e.json()).models??[]}:{_tag:"error",message:"Failed to fetch models"}},catch:e=>new s.uV({message:"fetch ollama models failed",cause:e})}),p=e=>n.gen(function*(){let t=yield*f();if("not-running"!==t._tag)return t;e&&(yield*n.sync(e));let r=yield*n.tryPromise({try:async()=>{let e=await fetch("/api/ollama/start",{method:"POST"}),t=await e.json().catch(()=>({}));return 404===e.status?{_tag:"not-installed",message:t.message||"Ollama is not installed"}:e.ok?{_tag:"started"}:{_tag:"error",message:"Failed to start Ollama"}},catch:e=>new s.uV({message:"start ollama failed",cause:e})});if("not-installed"===r._tag)return{_tag:"not-installed",message:r.message};if("error"===r._tag)return{_tag:"error",message:r.message};let o=yield*f();return"not-running"===o._tag?{_tag:"error",message:"Ollama started but cannot fetch models"}:o}),g=e=>o(`/api/file?path=${encodeURIComponent(e)}`),b=e=>o(`/api/claude-stats?engine=${encodeURIComponent(e)}`)},83678:(e,t,r)=>{r.d(t,{SessionBrowser:()=>d});var n=r(95155),s=r(12115),o=r(79114),l=r(95045),a=r(75346),i=r(86957),c=r(76900);function d({isOpen:e,onClose:t,onSelectSession:r,onAddProject:u}){let{t:m}=(0,o.Bd)(),[x,h]=(0,s.useState)(!1),[f,p]=(0,s.useState)([]),[g,b]=(0,s.useState)({}),[v,j]=(0,s.useState)(!1),[w,y]=(0,s.useState)(null),[k,N]=(0,s.useState)(""),C=(0,s.useRef)(null),S=(0,s.useCallback)(async()=>{j(!0),y(null),b({});let e=await i.t4.runPromiseExit((0,c.H7)());"Success"===e._tag?p(e.value):y("Failed to load projects"),j(!1)},[]),L=(0,s.useCallback)(async e=>{b(t=>({...t,[e]:{...t[e],isExpanded:!0,isLoading:!0,sessions:[],error:null}}));let t=await i.t4.runPromiseExit((0,c.QW)(e));"Success"===t._tag?b(r=>({...r,[e]:{...r[e],isLoading:!1,sessions:t.value}})):b(t=>({...t,[e]:{...t[e],isLoading:!1,error:"Failed to load sessions"}}))},[]),E=(0,s.useCallback)(e=>{let t=g[e];t?.isExpanded?b(t=>({...t,[e]:{...t[e],isExpanded:!1}})):t?.sessions?.length?b(t=>({...t,[e]:{...t[e],isExpanded:!0}})):L(e)},[g,L]);(0,s.useEffect)(()=>{e&&(S(),setTimeout(()=>{C.current?.focus()},100))},[e,S]);let M=(0,s.useCallback)(async()=>{if(x)return;h(!0);let e=await i.t4.runPromiseExit((0,c.It)());"Success"===e._tag&&e.value.folder&&u&&(u(e.value.folder),t()),h(!1)},[x,u,t]);return((0,s.useEffect)(()=>{let r=r=>{"Escape"===r.key&&e&&t()};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[e,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-black/50 backdrop-blur-sm",onClick:t}),(0,n.jsxs)("div",{className:"relative w-full max-w-6xl h-[90vh] mx-4 bg-card rounded-lg shadow-xl flex flex-col 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:m("sessions.projectList")}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("input",{ref:C,type:"text",placeholder:m("workspace.searchProjectPath"),value:k,onChange:e=>N(e.target.value),className:"px-2 py-1 text-xs border border-border rounded bg-card text-foreground placeholder-slate-9 focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent"}),u&&(0,n.jsxs)("button",{onClick:M,disabled:x,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-accent transition-colors disabled:opacity-50",title:m("sessions.openFolder"),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"})}),x?m("sessions.selectingFolder"):m("sessions.openFolder")]}),(0,n.jsx)("button",{onClick:t,className:"p-1 text-slate-9 hover:text-foreground hover:bg-accent 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 overflow-y-auto p-4",children:[v&&(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:m("workspace.loadingProjects")})]})}),w&&(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)("div",{className:"text-xs text-red-11",children:w})}),!v&&!w&&0===f.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:m("workspace.projectNotFound")})}),!v&&!w&&f.filter(e=>e.fullPath.toLowerCase().includes(k.toLowerCase())).map(e=>{let t=g[e.encodedPath]||{isExpanded:!1,isLoading:!1,sessions:[],error:null};return(0,n.jsxs)("div",{className:"mb-3",children:[(0,n.jsxs)("button",{onClick:()=>E(e.encodedPath),className:"w-full flex items-center gap-2 p-2 rounded hover:bg-accent 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"})}),(0,n.jsx)("span",{className:"flex-1 text-xs font-medium text-foreground truncate",title: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:m("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:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3",children:t.sessions.map(t=>(0,n.jsxs)("div",{onClick:()=>{var n;let s;return n=e.fullPath,s=(t.path.split("/").pop()||"").replace(".jsonl",""),void(r?r(n,s):(0,l.F)(a.n.OpenProject,{cwd:n,sessionId:s}))},className:"p-3 bg-secondary rounded border border-border hover:border-brand hover:shadow-md cursor-pointer transition-all",children:[(0,n.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[t.engine&&"claude"!==t.engine&&(0,n.jsx)("span",{className:`shrink-0 px-1 py-0.5 text-[10px] leading-none font-medium rounded ${"claude2"===t.engine?"bg-orange-500/15 text-orange-11":"ollama"===t.engine?"bg-blue-500/15 text-blue-11":"codex"===t.engine?"bg-green-500/15 text-green-11":"kimi"===t.engine?"bg-purple-500/15 text-purple-11":"bg-muted text-muted-foreground"}`,children:t.engine}),(0,n.jsx)("h4",{className:"text-xs font-medium text-foreground truncate",title:t.title,children:t.title})]}),(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",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`first-${t}`)),t.lastMessages.length>0&&(0,n.jsx)("div",{className:"text-slate-9 text-center py-0.5",children:"\xb7\xb7\xb7"}),t.lastMessages.map((e,t)=>(0,n.jsxs)("div",{className:"text-foreground truncate",title:e,children:[(0,n.jsx)("span",{className:"text-slate-9 mr-1",children:"•"}),e]},`last-${t}`))]})]},t.path))})]})]},e.encodedPath)})]})]})]}):null}},84310:(e,t,r)=>{r.d(t,{Providers:()=>u});var n=r(95155),s=r(47617),o=r(3238),l=r(34075),a=r(12115),i=r(47650);function c(e){let t=e;for(;t;){let e=t.dataset?.tooltip;if(e)return e;t=t.parentElement}return null}function d(){let[e,t]=(0,a.useState)(null),r=(0,a.useRef)(null);r.current=e;let s=(0,a.useRef)(null),o=(0,a.useRef)(null),[l,d]=(0,a.useState)({left:0,top:0}),[u,m]=(0,a.useState)(!1);return((0,a.useEffect)(()=>m(!0),[]),(0,a.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)return void t({text:o,x:n.clientX,y:n.clientY});e();let l=n.clientX,a=n.clientY;s.current=setTimeout(()=>{t({text:o,x:l,y:a}),s.current=null},300)},o=n=>{if(!r.current)return;let s=c(n.target);if(!s){e(),t(null);return}t({text:s,x:n.clientX,y:n.clientY})},l=()=>{e(),r.current&&t(null)};return document.addEventListener("mouseover",n,!0),document.addEventListener("mousemove",o),document.addEventListener("mouseleave",l),document.addEventListener("mousedown",l),()=>{document.removeEventListener("mouseover",n,!0),document.removeEventListener("mousemove",o),document.removeEventListener("mouseleave",l),document.removeEventListener("mousedown",l),e()}},[]),(0,a.useLayoutEffect)(()=>{if(!e||!o.current)return;let t=o.current.getBoundingClientRect(),r=window.innerWidth,n=window.innerHeight,s=e.x+12,l=e.y+16;s+t.width>r-8&&(s=r-t.width-8),s<8&&(s=8),l+t.height>n-8&&(l=e.y-t.height-8),d({left:s,top:l})},[e]),u&&e)?(0,i.createPortal)((0,n.jsx)("div",{ref:o,className:"fixed z-[9999] px-2 py-1 bg-popover text-popover-foreground text-xs font-mono rounded shadow-lg border border-brand whitespace-nowrap pointer-events-none max-w-[80vw] overflow-hidden text-ellipsis",style:{left:l.left,top:l.top},children:e.text}),document.body):null}function u({children:e}){return(0,n.jsx)(s.I18nProvider,{children:(0,n.jsx)(o.N,{children:(0,n.jsxs)(l.tE,{children:[e,(0,n.jsx)(d,{})]})})})}},88371:(e,t,r)=>{r.d(t,{U:()=>o,k:()=>s});let n="cockpit-skills";function s(){let e="u"<typeof BroadcastChannel?null:new BroadcastChannel(n);if(e)try{e.postMessage({type:"changed"})}finally{e.close()}}function o(e){if("u"<typeof BroadcastChannel)return()=>{};let t=new BroadcastChannel(n),r=t=>{t.data?.type==="changed"&&e()};return t.addEventListener("message",r),()=>{t.removeEventListener("message",r),t.close()}}},89039:(e,t,r)=>{r.d(t,{useTabState:()=>d});var n=r(12115),s=r(41474),o=r(95045),l=r(75346),a=r(49433),i=r(86957),c=r(96472);function d({initialCwd:e,initialSessionId:t,activeView:r}){let u=(0,n.useRef)(!1),m=(0,n.useRef)(!0),x=(0,n.useRef)(r);(0,n.useEffect)(()=>{x.current=r},[r]);let h=(0,s.F)(),f=(0,n.useRef)(h);(0,n.useEffect)(()=>{f.current=h},[h]);let[p,g]=(0,n.useState)(()=>[{id:`tab-${Date.now()}`,cwd:e,title:"New Chat"}]),[b,v]=(0,n.useState)(p[0].id),[j,w]=(0,n.useState)(new Set),y=(0,n.useRef)(p);(0,n.useEffect)(()=>{y.current=p},[p]);let k=(0,n.useCallback)((t,r)=>{e&&t&&i.t4.runFork((0,c.KJ)(e,t,r).pipe(a.catchAll(()=>a.void)))},[e]),[N,C]=(0,n.useState)(null),[S,L]=(0,n.useState)(null);(0,n.useEffect)(()=>{!e||u.current||(u.current=!0,(async()=>{let r=await i.t4.runPromise((0,c.n8)(e).pipe(a.catchAll(()=>a.succeed(null))));if(r){let n=r.sessions||[],s=r.activeSessionId,o=r.engines||{},l=r.ollamaModels||{},a=r.deepseekModels||{},i=[...n];if(t&&!i.includes(t)&&(i=[t,...i]),i.length>0){let r=i.map((t,r)=>({id:`tab-${Date.now()}-${r}`,cwd:e,sessionId:t,title:`Session ${t.slice(0,6)}...`,engine:o[t]||void 0,ollamaModel:l[t]||void 0,deepseekModel:a[t]||void 0})),n=t||s,c=n?i.indexOf(n):-1;c<0&&(c=0);let d=r[c].id;g(r),v(d),setTimeout(()=>{m.current=!1},0)}else m.current=!1}else m.current=!1})())},[e,t]),(0,n.useEffect)(()=>{if(m.current||!e)return;let t=p.map(e=>e.sessionId).filter(e=>!!e),r=p.find(e=>e.id===b),n=r?.sessionId,s={},o={},l={};for(let e of p)e.sessionId&&e.engine&&(s[e.sessionId]=e.engine),e.sessionId&&e.ollamaModel&&(o[e.sessionId]=e.ollamaModel),e.sessionId&&e.deepseekModel&&(l[e.sessionId]=e.deepseekModel);i.t4.runFork((0,c.ej)({cwd:e,sessions:t,activeSessionId:n,engines:s,ollamaModels:o,deepseekModels:l}).pipe(a.tapError(e=>a.sync(()=>console.error("Failed to save sessions:",e))),a.catchAll(()=>a.void)))},[p,b,e]),(0,n.useEffect)(()=>{if(m.current||!e)return;let t=p.find(e=>e.id===b);t?.sessionId&&(0,o.F)(l.n.SessionChange,{cwd:e,sessionId:t.sessionId})},[b,p,e]);let E=(0,n.useCallback)((e,t,r,n,s,o,l=!1)=>{let a={id:`tab-${Date.now()}`,cwd:e,sessionId:t,title:r||(t?`Session ${t.slice(0,6)}...`:"New Chat"),engine:n,ollamaModel:s,deepseekModel:o};g(e=>{if(l)return[...e,a];let t=e.findIndex(e=>e.id===b);if(-1===t)return[...e,a];let r=[...e];return r.splice(t+1,0,a),r}),v(a.id)},[b]),M=(0,n.useCallback)(t=>{g(r=>{let n=r.filter(e=>e.id!==t);if(t===b&&n.length>0&&v(n[n.length-1].id),0===n.length){let t={id:`tab-${Date.now()}`,cwd:e,title:"New Chat"};return v(t.id),[t]}return n})},[b,e]),T=(0,n.useCallback)((t,r)=>{let n=p.find(e=>e.sessionId===t);n?v(n.id):E(e,t,r,void 0,void 0,void 0,!0)},[p,e,E]),$=(0,n.useCallback)(()=>{E(e,void 0,void 0,void 0,void 0,void 0,!0)},[e,E]),P=(0,n.useCallback)(()=>{E(e,void 0,"New Claude 2 Chat","claude2",void 0,void 0,!0)},[e,E]),R=(0,n.useCallback)(()=>{E(e,void 0,"New Codex Chat","codex",void 0,void 0,!0)},[e,E]),B=(0,n.useCallback)(()=>{E(e,void 0,"New Kimi Chat","kimi",void 0,void 0,!0)},[e,E]),F=(0,n.useCallback)(t=>{E(e,void 0,t?`New Ollama (${t})`:"New Ollama Chat","ollama",t,void 0,!0)},[e,E]),I=(0,n.useCallback)((e,t)=>{g(r=>r.map(r=>r.id===e?{...r,ollamaModel:t}:r))},[]),D=(0,n.useCallback)(()=>{E(e,void 0,"New DeepSeek Chat","deepseek",void 0,"deepseek-v4-flash",!0)},[e,E]),A=(0,n.useCallback)((e,t)=>{g(r=>r.map(r=>r.id===e?{...r,deepseekModel:t}:r))},[]),_=(0,n.useCallback)((t,r)=>{E(e,t,r)},[e,E]),W=(0,n.useCallback)((e,t)=>{g(r=>{let n=r.find(t=>t.id===e);if(n?.isLoading&&!1===t.isLoading){let r=!x.current||"agent"===x.current;if(e===b&&r&&f.current){let e=n.sessionId||t.sessionId;e&&k(e,"normal")}else w(t=>new Set(t).add(e))}return r.map(r=>r.id===e?{...r,...t}:r)})},[b,k]);(0,n.useEffect)(()=>{(!r||"agent"===r)&&h&&w(e=>{if(!e.has(b))return e;let t=new Set(e);t.delete(b);let r=y.current.find(e=>e.id===b);return r?.sessionId&&(k(r.sessionId,"normal"),i.t4.runFork((0,c.M2)(r.sessionId).pipe(a.catchAll(()=>a.void)))),t})},[r,b,h,k]);let z=(0,n.useCallback)(e=>{v(e),w(t=>{if(!t.has(e))return t;let r=new Set(t);r.delete(e);let n=y.current.find(t=>t.id===e);return n?.sessionId&&(k(n.sessionId,"normal"),i.t4.runFork((0,c.M2)(n.sessionId).pipe(a.catchAll(()=>a.void)))),r})},[k]),H=(0,n.useCallback)(e=>{C(e)},[]),O=(0,n.useCallback)((e,t)=>{e.preventDefault(),null!==N&&N!==t&&L(t)},[N]),q=(0,n.useCallback)(e=>{null!==N&&N!==e&&g(t=>{let r=[...t],[n]=r.splice(N,1);return r.splice(e,0,n),r}),C(null),L(null)},[N]),V=(0,n.useCallback)(()=>{C(null),L(null)},[]),K=p.find(e=>e.id===b);return{tabs:p,activeTabId:b,activeTab:K,unreadTabs:j,dragTabIndex:N,dragOverTabIndex:S,addTab:E,closeTab:M,switchTab:z,handleSelectSession:T,handleNewTab:$,handleNewClaude2Tab:P,handleNewCodexTab:R,handleNewKimiTab:B,handleNewOllamaTab:F,handleNewDeepseekTab:D,handleOpenSession:_,updateTabState:W,updateTabOllamaModel:I,updateTabDeepseekModel:A,handleTabDragStart:H,handleTabDragOver:O,handleTabDrop:q,handleTabDragEnd:V}}},89109:(e,t,r)=>{r.d(t,{f:()=>a});var n=r(95155),s=r(12115),o=r(79114);function l({x:e,y:t,visible:r,container:s,onAddComment:a,onSendToAI:i,onSearch:c,isChatLoading:d}){let{t:u}=(0,o.Bd)(),m=s.getBoundingClientRect(),x=e-m.left,h=Math.max(0,t-m.top-40);return(0,n.jsxs)("div",{className:"floating-toolbar absolute z-[200] flex items-center gap-1.5 bg-card border border-border rounded-lg shadow-xl p-1.5",style:{left:x+8,top:h,visibility:r?"visible":"hidden",pointerEvents:r?"auto":"none"},children:[(0,n.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:a,children:u("floatingToolbar.addComment")}),(0,n.jsx)("button",{className:"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",onClick:i,disabled:d,title:u(d?"comments.aiResponding":"floatingToolbar.sendToAI"),children:u("floatingToolbar.sendToAI")}),c&&(0,n.jsx)("button",{className:"px-3 py-1.5 text-xs font-medium border border-brand text-brand rounded-md hover:bg-brand/10 transition-colors",onClick:c,children:u("floatingToolbar.search")})]})}let a=(0,s.memo)(function({floatingToolbarRef:e,bumpRef:t,container:r,onAddComment:o,onSendToAI:a,onSearch:i,isChatLoading:c}){let[d,u]=(0,s.useState)(0);(0,s.useEffect)(()=>{t.current=()=>u(e=>e+1)},[t]);let m=(0,s.useMemo)(()=>e.current,[d]);return(0,n.jsx)(l,{x:m?.x??0,y:m?.y??0,visible:!!m,container:r,onAddComment:o,onSendToAI:a,onSearch:i,isChatLoading:c})})},90717:(e,t,r)=>{r.d(t,{$3:()=>u,Cm:()=>d,Gw:()=>h,RP:()=>m,Un:()=>x,zL:()=>c});var n=r(69809),s=r(49433),o=r(86957),l=r(82680),a=r(46456);let i=new Set;function c(e){return i.add(e),()=>i.delete(e)}function d(){i.forEach(e=>e())}async function u(e){let t=await o.t4.runPromiseExit((0,a.lb)(e));if("Success"!==t._tag)throw Error("Failed to fetch comments");let r=t.value.comments??[];if(0===r.length)return[];let n=new Map;for(let e of r)e.selectedText||(n.has(e.filePath)||n.set(e.filePath,[]),n.get(e.filePath).push(e));let i=new Map;await Promise.all(Array.from(n.keys()).map(async t=>{let r=await o.t4.runPromiseExit(s.tryPromise({try:async()=>{let r=await fetch(`/api/files/text?cwd=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`);return r.ok?await r.json():null},catch:e=>new l.uV({message:`read file text ${t} failed`,cause:e})}));"Success"===r._tag&&r.value&&"string"==typeof r.value.content?i.set(t,r.value.content.split("\n")):"Failure"===r._tag&&console.error(`Failed to read file ${t}:`,r.cause)}));let c=[];for(let e of r){if(e.selectedText){c.push({...e,codeContent:e.selectedText});continue}let t=i.get(e.filePath),r="";if(t){let n=Math.max(0,e.startLine-1),s=Math.min(t.length,e.endLine);r=t.slice(n,s).join("\n")}c.push({...e,codeContent:r})}return c}async function m(e){let t=await o.t4.runPromiseExit((0,a.tj)(e));return"Success"===t._tag?(d(),!0):(console.error("Failed to clear comments:",t.cause),!1)}let x="__chat__";function h(e,t){let r=e.filter(e=>e.filePath===x),s=e.filter(e=>e.filePath!==x),o=[];for(let e of(s.length>0&&(o.push(`${n.A.t("comments.codeRef")}`,""),s.forEach((e,t)=>{o.push(`[${t+1}] ${e.filePath}:${e.startLine}-${e.endLine}`),o.push("```"),o.push(e.codeContent),o.push("```"),e.note&&o.push(n.A.t("comments.note",{content:e.note})),o.push("")})),r)){let t=e.codeContent.split("\n").map(e=>`> ${e}`).join("\n");o.push(t),e.note&&o.push(e.note),o.push("")}return o.push(n.A.t("comments.question",{question:t})),o.join("\n")}},93777:(e,t,r)=>{r.d(t,{E:()=>c});var n=r(95155),s=r(12115),o=r(79114),l=r(69809),a=r(12786);let i={once:[{labelKey:"scheduledTasks.5minLater",value:5},{labelKey:"scheduledTasks.15minLater",value:15},{labelKey:"scheduledTasks.30minLater",value:30},{labelKey:"scheduledTasks.1hourLater",value:60}],interval:[{labelKey:"scheduledTasks.every15min",value:15},{labelKey:"scheduledTasks.every30min",value:30},{labelKey:"scheduledTasks.every1hour",value:60},{labelKey:"scheduledTasks.every2hours",value:120}],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 * *"}]};function c({onClose:e,onCreate:t,editTask:r,onUpdate:d}){let{t:u}=(0,o.Bd)(),m=!!r,[x,h]=(0,s.useState)(r?.type||"once"),[f,p]=(0,s.useState)(r?.message||""),[g,b]=(0,s.useState)(r?String(r.delayMinutes||r.intervalMinutes||""):""),[v,j]=(0,s.useState)(r?.cron||""),[w,y]=(0,s.useState)(r?.activeFrom||"09:00"),[k,N]=(0,s.useState)(r?.activeTo||"18:00"),[C,S]=(0,s.useState)(!!(r?.activeFrom&&r?.activeTo)),[L,E]=(0,s.useState)(null),M=(0,s.useRef)(null),T=(0,s.useRef)(null);(0,s.useEffect)(()=>{T.current?.focus()},[]),(0,s.useEffect)(()=>{let t=t=>{M.current&&!M.current.contains(t.target)&&e()};return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[e]);let $=(0,s.useCallback)(()=>{if(!f.trim())return;let n=null;if("once"===x){let e=L||parseInt(g,10);if(!e||e<=0)return;n={message:f.trim(),type:"once",delayMinutes:e}}else if("interval"===x){let e=L||parseInt(g,10);if(!e||e<=0)return;n={message:f.trim(),type:"interval",intervalMinutes:e,...C?{activeFrom:w,activeTo:k}:{}}}else if("cron"===x){let e=L||v.trim();if(!e)return;n={message:f.trim(),type:"cron",cron:e}}n&&(m&&r&&d?d(r.id,n):t(n),e())},[f,x,L,g,v,C,w,k,t,e,m,r,d]);return(0,n.jsxs)("div",{ref:M,className:`w-80 bg-popover border border-border rounded-lg shadow-lg z-50 ${m?"":"absolute bottom-full left-0 mb-2"}`,onKeyDown:t=>{"Escape"===t.key?e():"Enter"===t.key&&(t.metaKey||t.ctrlKey)&&$()},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:m?u("scheduledTasks.editTask"):u("scheduledTasks.createTask")})}),(0,n.jsxs)("div",{className:"p-3 space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.sendMessage")}),(0,n.jsx)("textarea",{ref:T,value:f,onChange:e=>p(e.target.value),placeholder:u("scheduledTasks.messagePlaceholder"),rows:2,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring resize-none"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.type")}),(0,n.jsx)("div",{className:"flex gap-1",children:["once","interval","cron"].map(e=>(0,n.jsx)("button",{onClick:()=>{h(e),E(null),b(""),j("")},className:`flex-1 px-2 py-1 text-xs rounded transition-colors ${x===e?"bg-brand text-white":"bg-muted text-muted-foreground hover:text-foreground"}`,children:"once"===e?u("scheduledTasks.once"):"interval"===e?u("scheduledTasks.interval"):"Cron"},e))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:u("scheduledTasks.quickSelect")}),(0,n.jsx)("div",{className:"grid grid-cols-2 gap-1",children:i[x].map(e=>(0,n.jsx)("button",{onClick:()=>{E(e.value),"cron"===x?j(String(e.value)):b(String(e.value))},className:`px-2 py-1 text-xs rounded border transition-colors ${L===e.value?"border-brand bg-brand/10 text-brand":"border-border text-muted-foreground hover:text-foreground hover:border-foreground/30"}`,children:u(e.labelKey)},e.labelKey))})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-muted-foreground mb-1 block",children:"cron"===x?u("scheduledTasks.customCron"):u("scheduledTasks.customMinutes")}),"cron"===x?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("input",{type:"text",value:v,onChange:e=>{j(e.target.value),E(null)},placeholder:u("scheduledTasks.cronPlaceholder"),className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring font-mono"}),v.trim()&&(0,n.jsx)("div",{className:"mt-1 text-xs text-muted-foreground",children:function(e){let t=l.A.t,r=e.trim().split(/\s+/);if(5!==r.length)return null;let[n,s,o,a,i]=r,c={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")},d={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),l=parseInt(n,10);if(isNaN(r)&&"*"!==s||isNaN(l)&&"*"!==n)return null;e="*"===s&&"*"===n?t("cron.everyMinute"):"*"===s?t("cron.everyHourAtMin",{m:l}):"*"===n?t("cron.hourlyEveryMin",{h:r}):`${String(r).padStart(2,"0")}:${String(l).padStart(2,"0")}`;let u=[];if("*"!==a){let e=a.split(",").map(e=>d[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:c[r]||r,b:c[n]||n})}return`${t("cron.weekdayPrefix")}${c[e]||e}`});u.push(e.join(", "))}if(0===u.length&&"*"===o&&"*"===a&&"*"===i)return t("cron.daily",{time:e});return`${u.join(" ")} ${e}`}catch{return null}}(v.trim())||(0,n.jsx)("span",{className:"text-destructive",children:u("scheduledTasks.cronFormat")})})]}):(0,n.jsx)("input",{type:"number",value:g,onChange:e=>{b(e.target.value),E(null)},placeholder:u("scheduledTasks.minutesPlaceholder"),min:1,className:"w-full px-2 py-1.5 text-sm border border-border rounded bg-card text-foreground placeholder-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"})]}),"interval"===x&&(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:C,onChange:e=>S(e.target.checked),className:"rounded border-border"}),u("scheduledTasks.limitTimeRange")]}),C&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("input",{type:"time",value:w,onChange:e=>y(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:u("scheduledTasks.to")}),(0,n.jsx)("input",{type:"time",value:k,onChange:e=>N(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:$,disabled:!(f.trim()&&("once"===x||"interval"===x?!!(L||g&&parseInt(g,10)>0):"cron"===x&&!!(L||v.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:m?u("scheduledTasks.saveBtn",{modKey:(0,a.Mu)()}):u("scheduledTasks.createBtn",{modKey:(0,a.Mu)()})})]})]})}},95045:(e,t,r)=>{r.d(t,{F:()=>l});var n=r(49433),s=r(88292),o=r(86957);let l=(e,t)=>{o.t4.runFork(n.flatMap(s.d,r=>r.publish(e,t)))}},96472:(e,t,r)=>{r.d(t,{KJ:()=>a,M2:()=>i,ej:()=>l,n8:()=>o});var n=r(49433),s=r(82680);let o=e=>n.tryPromise({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})}),l=e=>n.tryPromise({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})}),a=(e,t,r)=>n.tryPromise({try:async()=>{let n=await fetch("/api/global-state",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:e,sessionId:t,status:r})});if(!n.ok)throw Error(`HTTP ${n.status}`)},catch:e=>new s.uV({message:"updateSessionStatus failed",cause:e})}),i=e=>n.tryPromise({try:async()=>{let t=await fetch("/api/scheduled-tasks",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"markReadBySessionId",fields:{sessionId:e}})});if(!t.ok)throw Error(`HTTP ${t.status}`)},catch:e=>new s.uV({message:"markScheduledTasksReadBySession failed",cause:e})})}}]);