@researai/deepscientist 1.5.16 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (896) hide show
  1. package/AGENTS.md +309 -130
  2. package/AISB/catalog/aisb.b1.agentic_coding.yaml +244 -0
  3. package/AISB/catalog/aisb.b10.climate_earth.yaml +235 -0
  4. package/AISB/catalog/aisb.b11.model_efficiency.yaml +231 -0
  5. package/AISB/catalog/aisb.b12.embodied_ai.yaml +238 -0
  6. package/AISB/catalog/aisb.b2.agent_systems.yaml +229 -0
  7. package/AISB/catalog/aisb.b3.self_evolving_rl.yaml +237 -0
  8. package/AISB/catalog/aisb.b4.lm_reasoning.yaml +240 -0
  9. package/AISB/catalog/aisb.b5.math_proof.yaml +235 -0
  10. package/AISB/catalog/aisb.b6.research_process.yaml +243 -0
  11. package/AISB/catalog/aisb.b7.multimodal_fusion.yaml +232 -0
  12. package/AISB/catalog/aisb.b8.lifesci_drug.yaml +275 -0
  13. package/AISB/catalog/aisb.b9.material_science.yaml +237 -0
  14. package/AISB/catalog/aisb.t3.001_savvy.yaml +159 -0
  15. package/AISB/catalog/aisb.t3.001_savvy.zh.yaml +121 -0
  16. package/AISB/catalog/aisb.t3.002_pinet.yaml +189 -0
  17. package/AISB/catalog/aisb.t3.002_pinet.zh.yaml +130 -0
  18. package/AISB/catalog/aisb.t3.004_decentralattn.yaml +184 -0
  19. package/AISB/catalog/aisb.t3.004_decentralattn.zh.yaml +153 -0
  20. package/AISB/catalog/aisb.t3.005_tsae.yaml +193 -0
  21. package/AISB/catalog/aisb.t3.005_tsae.zh.yaml +139 -0
  22. package/AISB/catalog/aisb.t3.006_physense.yaml +194 -0
  23. package/AISB/catalog/aisb.t3.006_physense.zh.yaml +118 -0
  24. package/AISB/catalog/aisb.t3.007_reasoningiqa.yaml +169 -0
  25. package/AISB/catalog/aisb.t3.007_reasoningiqa.zh.yaml +133 -0
  26. package/AISB/catalog/aisb.t3.008_meanflows.yaml +188 -0
  27. package/AISB/catalog/aisb.t3.008_meanflows.zh.yaml +140 -0
  28. package/AISB/catalog/aisb.t3.009_scoremissing.yaml +179 -0
  29. package/AISB/catalog/aisb.t3.009_scoremissing.zh.yaml +119 -0
  30. package/AISB/catalog/aisb.t3.010_suitabilityfilter.yaml +221 -0
  31. package/AISB/catalog/aisb.t3.010_suitabilityfilter.zh.yaml +141 -0
  32. package/AISB/catalog/aisb.t3.011_osd.yaml +206 -0
  33. package/AISB/catalog/aisb.t3.011_osd.zh.yaml +163 -0
  34. package/AISB/catalog/aisb.t3.012_efficientqat.yaml +206 -0
  35. package/AISB/catalog/aisb.t3.012_efficientqat.zh.yaml +159 -0
  36. package/AISB/catalog/aisb.t3.013_appl.yaml +152 -0
  37. package/AISB/catalog/aisb.t3.013_appl.zh.yaml +126 -0
  38. package/AISB/catalog/aisb.t3.014_piguard.yaml +207 -0
  39. package/AISB/catalog/aisb.t3.014_piguard.zh.yaml +164 -0
  40. package/AISB/catalog/aisb.t3.015_frspec.yaml +209 -0
  41. package/AISB/catalog/aisb.t3.015_frspec.zh.yaml +163 -0
  42. package/AISB/catalog/aisb.t3.016_mathfusion.yaml +166 -0
  43. package/AISB/catalog/aisb.t3.016_mathfusion.zh.yaml +145 -0
  44. package/AISB/catalog/aisb.t3.017_multimodalglp.yaml +171 -0
  45. package/AISB/catalog/aisb.t3.017_multimodalglp.zh.yaml +122 -0
  46. package/AISB/catalog/aisb.t3.018_cotsynth.yaml +206 -0
  47. package/AISB/catalog/aisb.t3.018_cotsynth.zh.yaml +162 -0
  48. package/AISB/catalog/aisb.t3.019_dyscaleut.yaml +211 -0
  49. package/AISB/catalog/aisb.t3.019_dyscaleut.zh.yaml +148 -0
  50. package/AISB/catalog/aisb.t3.020_aristotle.yaml +173 -0
  51. package/AISB/catalog/aisb.t3.020_aristotle.zh.yaml +119 -0
  52. package/AISB/catalog/aisb.t3.021_tokenrecycling.yaml +160 -0
  53. package/AISB/catalog/aisb.t3.021_tokenrecycling.zh.yaml +129 -0
  54. package/AISB/catalog/aisb.t3.022_chainofreasoning.yaml +204 -0
  55. package/AISB/catalog/aisb.t3.022_chainofreasoning.zh.yaml +161 -0
  56. package/AISB/catalog/aisb.t3.023_guidedembed.yaml +211 -0
  57. package/AISB/catalog/aisb.t3.023_guidedembed.zh.yaml +189 -0
  58. package/AISB/catalog/aisb.t3.024_outputcentric.yaml +148 -0
  59. package/AISB/catalog/aisb.t3.024_outputcentric.zh.yaml +131 -0
  60. package/AISB/catalog/aisb.t3.025_deeper.yaml +143 -0
  61. package/AISB/catalog/aisb.t3.025_deeper.zh.yaml +116 -0
  62. package/AISB/catalog/aisb.t3.026_gartkg.yaml +195 -0
  63. package/AISB/catalog/aisb.t3.026_gartkg.zh.yaml +127 -0
  64. package/AISB/catalog/aisb.t3.027_citeeval.yaml +182 -0
  65. package/AISB/catalog/aisb.t3.027_citeeval.zh.yaml +135 -0
  66. package/AISB/catalog/aisb.t3.028_sbam.yaml +206 -0
  67. package/AISB/catalog/aisb.t3.028_sbam.zh.yaml +166 -0
  68. package/AISB/catalog/aisb.t3.029_cdqgeoembed.yaml +224 -0
  69. package/AISB/catalog/aisb.t3.029_cdqgeoembed.zh.yaml +142 -0
  70. package/AISB/catalog/aisb.t3.030_processrm.yaml +211 -0
  71. package/AISB/catalog/aisb.t3.030_processrm.zh.yaml +166 -0
  72. package/AISB/catalog/aisb.t3.031_circuitstability.yaml +172 -0
  73. package/AISB/catalog/aisb.t3.031_circuitstability.zh.yaml +134 -0
  74. package/AISB/catalog/aisb.t3.032_ptsolver.yaml +169 -0
  75. package/AISB/catalog/aisb.t3.032_ptsolver.zh.yaml +135 -0
  76. package/AISB/catalog/aisb.t3.033_gcse.yaml +144 -0
  77. package/AISB/catalog/aisb.t3.033_gcse.zh.yaml +126 -0
  78. package/AISB/catalog/aisb.t3.034_ensemblewm.yaml +183 -0
  79. package/AISB/catalog/aisb.t3.034_ensemblewm.zh.yaml +146 -0
  80. package/AISB/catalog/aisb.t3.035_moralvalueswa.yaml +207 -0
  81. package/AISB/catalog/aisb.t3.035_moralvalueswa.zh.yaml +165 -0
  82. package/AISB/catalog/aisb.t3.036_weakstrongpref.yaml +210 -0
  83. package/AISB/catalog/aisb.t3.036_weakstrongpref.zh.yaml +194 -0
  84. package/AISB/catalog/aisb.t3.037_dementiamask.yaml +172 -0
  85. package/AISB/catalog/aisb.t3.037_dementiamask.zh.yaml +132 -0
  86. package/AISB/catalog/aisb.t3.038_tinysam.yaml +284 -0
  87. package/AISB/catalog/aisb.t3.038_tinysam.zh.yaml +240 -0
  88. package/AISB/catalog/aisb.t3.039_calf.yaml +224 -0
  89. package/AISB/catalog/aisb.t3.039_calf.zh.yaml +194 -0
  90. package/AISB/catalog/aisb.t3.040_graniteguardian.yaml +199 -0
  91. package/AISB/catalog/aisb.t3.040_graniteguardian.zh.yaml +174 -0
  92. package/AISB/catalog/aisb.t3.041_amdm.yaml +149 -0
  93. package/AISB/catalog/aisb.t3.041_amdm.zh.yaml +137 -0
  94. package/AISB/catalog/aisb.t3.042_xpatch.yaml +216 -0
  95. package/AISB/catalog/aisb.t3.042_xpatch.zh.yaml +182 -0
  96. package/AISB/catalog/aisb.t3.043_vhm.yaml +268 -0
  97. package/AISB/catalog/aisb.t3.043_vhm.zh.yaml +193 -0
  98. package/AISB/catalog/aisb.t3.044_rgvi.yaml +224 -0
  99. package/AISB/catalog/aisb.t3.044_rgvi.zh.yaml +176 -0
  100. package/AISB/catalog/aisb.t3.045_pslstm.yaml +203 -0
  101. package/AISB/catalog/aisb.t3.045_pslstm.zh.yaml +179 -0
  102. package/AISB/catalog/aisb.t3.046_nonstatts.yaml +208 -0
  103. package/AISB/catalog/aisb.t3.046_nonstatts.zh.yaml +194 -0
  104. package/AISB/catalog/aisb.t3.047_timepfn.yaml +156 -0
  105. package/AISB/catalog/aisb.t3.047_timepfn.zh.yaml +124 -0
  106. package/AISB/catalog/aisb.t3.048_proxyspex.yaml +148 -0
  107. package/AISB/catalog/aisb.t3.048_proxyspex.zh.yaml +125 -0
  108. package/AISB/catalog/aisb.t3.049_hogwildinference.yaml +183 -0
  109. package/AISB/catalog/aisb.t3.049_hogwildinference.zh.yaml +138 -0
  110. package/AISB/catalog/aisb.t3.050_causalpfn.yaml +214 -0
  111. package/AISB/catalog/aisb.t3.050_causalpfn.zh.yaml +190 -0
  112. package/AISB/catalog/aisb.t3.051_flashtp.yaml +169 -0
  113. package/AISB/catalog/aisb.t3.051_flashtp.zh.yaml +124 -0
  114. package/AISB/catalog/aisb.t3.052_nsdiff.yaml +155 -0
  115. package/AISB/catalog/aisb.t3.052_nsdiff.zh.yaml +138 -0
  116. package/AISB/catalog/aisb.t3.053_k2vae.yaml +158 -0
  117. package/AISB/catalog/aisb.t3.053_k2vae.zh.yaml +132 -0
  118. package/AISB/catalog/aisb.t3.054_timebase.yaml +178 -0
  119. package/AISB/catalog/aisb.t3.054_timebase.zh.yaml +158 -0
  120. package/AISB/catalog/aisb.t3.055_csbrain.yaml +238 -0
  121. package/AISB/catalog/aisb.t3.055_csbrain.zh.yaml +184 -0
  122. package/AISB/catalog/aisb.t3.056_infosam.yaml +224 -0
  123. package/AISB/catalog/aisb.t3.056_infosam.zh.yaml +189 -0
  124. package/AISB/catalog/aisb.t3.057_mdreid.yaml +129 -0
  125. package/AISB/catalog/aisb.t3.057_mdreid.zh.yaml +117 -0
  126. package/AISB/catalog/aisb.t3.058_mindglitch.yaml +171 -0
  127. package/AISB/catalog/aisb.t3.058_mindglitch.zh.yaml +145 -0
  128. package/AISB/catalog/aisb.t3.059_selfsupervised.yaml +154 -0
  129. package/AISB/catalog/aisb.t3.059_selfsupervised.zh.yaml +125 -0
  130. package/AISB/catalog/aisb.t3.060_iaggad.yaml +121 -0
  131. package/AISB/catalog/aisb.t3.060_iaggad.zh.yaml +100 -0
  132. package/AISB/catalog/aisb.t3.061_hsgkn.yaml +136 -0
  133. package/AISB/catalog/aisb.t3.061_hsgkn.zh.yaml +113 -0
  134. package/AISB/catalog/aisb.t3.062_visionts.yaml +237 -0
  135. package/AISB/catalog/aisb.t3.062_visionts.zh.yaml +216 -0
  136. package/AISB/catalog/aisb.t3.063_tsrag.yaml +162 -0
  137. package/AISB/catalog/aisb.t3.063_tsrag.zh.yaml +138 -0
  138. package/AISB/catalog/aisb.t3.064_pir.yaml +221 -0
  139. package/AISB/catalog/aisb.t3.064_pir.zh.yaml +197 -0
  140. package/AISB/catalog/aisb.t3.065_proteinbinding.yaml +234 -0
  141. package/AISB/catalog/aisb.t3.065_proteinbinding.zh.yaml +167 -0
  142. package/AISB/catalog/aisb.t3.066_tropicalattention.yaml +267 -0
  143. package/AISB/catalog/aisb.t3.066_tropicalattention.zh.yaml +229 -0
  144. package/AISB/catalog/aisb.t3.067_kanad.yaml +193 -0
  145. package/AISB/catalog/aisb.t3.067_kanad.zh.yaml +167 -0
  146. package/AISB/catalog/aisb.t3.068_sempo.yaml +187 -0
  147. package/AISB/catalog/aisb.t3.068_sempo.zh.yaml +148 -0
  148. package/AISB/catalog/aisb.t3.069_treehfd.yaml +129 -0
  149. package/AISB/catalog/aisb.t3.069_treehfd.zh.yaml +111 -0
  150. package/AISB/catalog/aisb.t3.070_certifiedunlearning.yaml +224 -0
  151. package/AISB/catalog/aisb.t3.070_certifiedunlearning.zh.yaml +171 -0
  152. package/AISB/catalog/aisb.t3.071_neuralmjd.yaml +142 -0
  153. package/AISB/catalog/aisb.t3.071_neuralmjd.zh.yaml +120 -0
  154. package/AISB/catalog/aisb.t3.072_fedgmt.yaml +181 -0
  155. package/AISB/catalog/aisb.t3.072_fedgmt.zh.yaml +158 -0
  156. package/AISB/catalog/aisb.t3.073_rld.yaml +161 -0
  157. package/AISB/catalog/aisb.t3.073_rld.zh.yaml +129 -0
  158. package/AISB/catalog/aisb.t3.074_lsvi.yaml +163 -0
  159. package/AISB/catalog/aisb.t3.074_lsvi.zh.yaml +129 -0
  160. package/AISB/catalog/aisb.t3.075_treeslicedentropy.yaml +201 -0
  161. package/AISB/catalog/aisb.t3.075_treeslicedentropy.zh.yaml +148 -0
  162. package/AISB/catalog/aisb.t3.076_aanet.yaml +169 -0
  163. package/AISB/catalog/aisb.t3.076_aanet.zh.yaml +129 -0
  164. package/AISB/catalog/aisb.t3.077_cmnn.yaml +199 -0
  165. package/AISB/catalog/aisb.t3.077_cmnn.zh.yaml +165 -0
  166. package/AISB/catalog/aisb.t3.078_conformalanomaly.yaml +146 -0
  167. package/AISB/catalog/aisb.t3.078_conformalanomaly.zh.yaml +117 -0
  168. package/AISB/catalog/aisb.t3.079_dpfkmeans.yaml +131 -0
  169. package/AISB/catalog/aisb.t3.079_dpfkmeans.zh.yaml +104 -0
  170. package/AISB/catalog/aisb.t3.080_latentscorereweight.yaml +169 -0
  171. package/AISB/catalog/aisb.t3.080_latentscorereweight.zh.yaml +123 -0
  172. package/AISB/catalog/aisb.t3.081_qmamba.yaml +150 -0
  173. package/AISB/catalog/aisb.t3.081_qmamba.zh.yaml +117 -0
  174. package/AISB/catalog/aisb.t3.082_onlinellmrouting.yaml +160 -0
  175. package/AISB/catalog/aisb.t3.082_onlinellmrouting.zh.yaml +133 -0
  176. package/AISB/catalog/aisb.t3.083_starformer.yaml +178 -0
  177. package/AISB/catalog/aisb.t3.083_starformer.zh.yaml +140 -0
  178. package/AISB/catalog/aisb.t3.084_ift.yaml +139 -0
  179. package/AISB/catalog/aisb.t3.084_ift.zh.yaml +111 -0
  180. package/AISB/catalog/aisb.t3.085_neuralsurv.yaml +183 -0
  181. package/AISB/catalog/aisb.t3.085_neuralsurv.zh.yaml +143 -0
  182. package/AISB/catalog/aisb.t3.086_stella.yaml +197 -0
  183. package/AISB/catalog/aisb.t3.086_stella.zh.yaml +142 -0
  184. package/AISB/catalog/aisb.t3.087_moses.yaml +167 -0
  185. package/AISB/catalog/aisb.t3.087_moses.zh.yaml +132 -0
  186. package/AISB/catalog/aisb.t3.088_channelnorm.yaml +140 -0
  187. package/AISB/catalog/aisb.t3.088_channelnorm.zh.yaml +109 -0
  188. package/AISB/catalog/aisb.t3.089_causalvelocity.yaml +730 -0
  189. package/AISB/catalog/aisb.t3.089_causalvelocity.zh.yaml +668 -0
  190. package/AISB/catalog/aisb.t3.090_rstib.yaml +144 -0
  191. package/AISB/catalog/aisb.t3.090_rstib.zh.yaml +109 -0
  192. package/AISB/catalog/aisb.t3.091_timeawarecausal.yaml +132 -0
  193. package/AISB/catalog/aisb.t3.091_timeawarecausal.zh.yaml +107 -0
  194. package/AISB/catalog/aisb.t3.092_kmeanslocalopt.yaml +138 -0
  195. package/AISB/catalog/aisb.t3.092_kmeanslocalopt.zh.yaml +110 -0
  196. package/AISB/catalog/aisb.t3.093_fedwmsam.yaml +134 -0
  197. package/AISB/catalog/aisb.t3.093_fedwmsam.zh.yaml +106 -0
  198. package/AISB/catalog/aisb.t3.094_boundre.yaml +147 -0
  199. package/AISB/catalog/aisb.t3.094_boundre.zh.yaml +114 -0
  200. package/AISB/catalog/aisb.t3.095_fastfeaturecp.yaml +153 -0
  201. package/AISB/catalog/aisb.t3.095_fastfeaturecp.zh.yaml +118 -0
  202. package/AISB/catalog/aisb.t3.096_m3svm.yaml +189 -0
  203. package/AISB/catalog/aisb.t3.096_m3svm.zh.yaml +149 -0
  204. package/AISB/catalog/aisb.t3.097_wassersteintl.yaml +212 -0
  205. package/AISB/catalog/aisb.t3.097_wassersteintl.zh.yaml +169 -0
  206. package/AISB/catalog/aisb.t3.098_xmahalanobis.yaml +171 -0
  207. package/AISB/catalog/aisb.t3.098_xmahalanobis.zh.yaml +127 -0
  208. package/AISB/catalog/aisb.t3.099_ollalanding.yaml +248 -0
  209. package/AISB/catalog/aisb.t3.099_ollalanding.zh.yaml +182 -0
  210. package/AISB/catalog/aisb.t3.100_invmissingdata.yaml +179 -0
  211. package/AISB/catalog/aisb.t3.100_invmissingdata.zh.yaml +150 -0
  212. package/AISB/catalog/aisb.t3.101_acia.yaml +164 -0
  213. package/AISB/catalog/aisb.t3.101_acia.zh.yaml +109 -0
  214. package/AISB/catalog/aisb.t3.102_stochasticff.yaml +178 -0
  215. package/AISB/catalog/aisb.t3.102_stochasticff.zh.yaml +130 -0
  216. package/AISB/catalog/aisb.t3.103_qdcp.yaml +150 -0
  217. package/AISB/catalog/aisb.t3.103_qdcp.zh.yaml +116 -0
  218. package/AISB/catalog/aisb.t3.104_balancedactiveinf.yaml +137 -0
  219. package/AISB/catalog/aisb.t3.104_balancedactiveinf.zh.yaml +104 -0
  220. package/AISB/catalog/aisb.t3.105_binaryclasseval.yaml +161 -0
  221. package/AISB/catalog/aisb.t3.105_binaryclasseval.zh.yaml +130 -0
  222. package/AISB/image/001_aisb.t3.001_savvy.jpg +0 -0
  223. package/AISB/image/002_aisb.t3.002_pinet.jpg +0 -0
  224. package/AISB/image/003_aisb.t3.003_dmsqd.jpg +0 -0
  225. package/AISB/image/004_aisb.t3.004_decentralattn.jpg +0 -0
  226. package/AISB/image/005_aisb.t3.005_tsae.jpg +0 -0
  227. package/AISB/image/006_aisb.t3.006_physense.jpg +0 -0
  228. package/AISB/image/007_aisb.t3.007_reasoningiqa.jpg +0 -0
  229. package/AISB/image/008_aisb.t3.008_meanflows.jpg +0 -0
  230. package/AISB/image/009_aisb.t3.009_scoremissing.jpg +0 -0
  231. package/AISB/image/010_aisb.t3.010_suitabilityfilter.jpg +0 -0
  232. package/AISB/image/011_aisb.t3.011_osd.jpg +0 -0
  233. package/AISB/image/012_aisb.t3.012_efficientqat.jpg +0 -0
  234. package/AISB/image/013_aisb.t3.013_appl.jpg +0 -0
  235. package/AISB/image/014_aisb.t3.014_piguard.jpg +0 -0
  236. package/AISB/image/015_aisb.t3.015_frspec.jpg +0 -0
  237. package/AISB/image/016_aisb.t3.016_mathfusion.jpg +0 -0
  238. package/AISB/image/017_aisb.t3.017_multimodalglp.jpg +0 -0
  239. package/AISB/image/018_aisb.t3.018_cotsynth.jpg +0 -0
  240. package/AISB/image/019_aisb.t3.019_dyscaleut.jpg +0 -0
  241. package/AISB/image/020_aisb.t3.020_aristotle.jpg +0 -0
  242. package/AISB/image/021_aisb.t3.021_tokenrecycling.jpg +0 -0
  243. package/AISB/image/022_aisb.t3.022_chainofreasoning.jpg +0 -0
  244. package/AISB/image/023_aisb.t3.023_guidedembed.jpg +0 -0
  245. package/AISB/image/024_aisb.t3.024_outputcentric.jpg +0 -0
  246. package/AISB/image/025_aisb.t3.025_deeper.jpg +0 -0
  247. package/AISB/image/026_aisb.t3.026_gartkg.jpg +0 -0
  248. package/AISB/image/027_aisb.t3.027_citeeval.jpg +0 -0
  249. package/AISB/image/028_aisb.t3.028_sbam.jpg +0 -0
  250. package/AISB/image/029_aisb.t3.029_cdqgeoembed.jpg +0 -0
  251. package/AISB/image/030_aisb.t3.030_processrm.jpg +0 -0
  252. package/AISB/image/031_aisb.t3.031_circuitstability.jpg +0 -0
  253. package/AISB/image/032_aisb.t3.032_ptsolver.jpg +0 -0
  254. package/AISB/image/033_aisb.t3.033_gcse.jpg +0 -0
  255. package/AISB/image/034_aisb.t3.034_ensemblewm.jpg +0 -0
  256. package/AISB/image/035_aisb.t3.035_moralvalueswa.jpg +0 -0
  257. package/AISB/image/036_aisb.t3.036_weakstrongpref.jpg +0 -0
  258. package/AISB/image/037_aisb.t3.037_dementiamask.jpg +0 -0
  259. package/AISB/image/038_aisb.t3.038_tinysam.jpg +0 -0
  260. package/AISB/image/039_aisb.t3.039_calf.jpg +0 -0
  261. package/AISB/image/040_aisb.t3.040_graniteguardian.jpg +0 -0
  262. package/AISB/image/041_aisb.t3.041_amdm.jpg +0 -0
  263. package/AISB/image/042_aisb.t3.042_xpatch.jpg +0 -0
  264. package/AISB/image/043_aisb.t3.043_vhm.jpg +0 -0
  265. package/AISB/image/044_aisb.t3.044_rgvi.jpg +0 -0
  266. package/AISB/image/045_aisb.t3.045_pslstm.jpg +0 -0
  267. package/AISB/image/046_aisb.t3.046_nonstatts.jpg +0 -0
  268. package/AISB/image/047_aisb.t3.047_timepfn.jpg +0 -0
  269. package/AISB/image/048_aisb.t3.048_proxyspex.jpg +0 -0
  270. package/AISB/image/049_aisb.t3.049_hogwildinference.jpg +0 -0
  271. package/AISB/image/050_aisb.t3.050_causalpfn.jpg +0 -0
  272. package/AISB/image/051_aisb.t3.051_flashtp.jpg +0 -0
  273. package/AISB/image/052_aisb.t3.052_nsdiff.jpg +0 -0
  274. package/AISB/image/053_aisb.t3.053_k2vae.jpg +0 -0
  275. package/AISB/image/054_aisb.t3.054_timebase.jpg +0 -0
  276. package/AISB/image/055_aisb.t3.055_csbrain.jpg +0 -0
  277. package/AISB/image/056_aisb.t3.056_infosam.jpg +0 -0
  278. package/AISB/image/057_aisb.t3.057_mdreid.jpg +0 -0
  279. package/AISB/image/058_aisb.t3.058_mindglitch.jpg +0 -0
  280. package/AISB/image/059_aisb.t3.059_selfsupervised.jpg +0 -0
  281. package/AISB/image/060_aisb.t3.060_iaggad.jpg +0 -0
  282. package/AISB/image/061_aisb.t3.061_hsgkn.jpg +0 -0
  283. package/AISB/image/062_aisb.t3.062_visionts.jpg +0 -0
  284. package/AISB/image/063_aisb.t3.063_tsrag.jpg +0 -0
  285. package/AISB/image/064_aisb.t3.064_pir.jpg +0 -0
  286. package/AISB/image/065_aisb.t3.065_proteinbinding.jpg +0 -0
  287. package/AISB/image/066_aisb.t3.066_tropicalattention.jpg +0 -0
  288. package/AISB/image/067_aisb.t3.067_kanad.jpg +0 -0
  289. package/AISB/image/068_aisb.t3.068_sempo.jpg +0 -0
  290. package/AISB/image/069_aisb.t3.069_treehfd.jpg +0 -0
  291. package/AISB/image/070_aisb.t3.070_certifiedunlearning.jpg +0 -0
  292. package/AISB/image/071_aisb.t3.071_neuralmjd.jpg +0 -0
  293. package/AISB/image/072_aisb.t3.072_fedgmt.jpg +0 -0
  294. package/AISB/image/073_aisb.t3.073_rld.jpg +0 -0
  295. package/AISB/image/074_aisb.t3.074_lsvi.jpg +0 -0
  296. package/AISB/image/075_aisb.t3.075_treeslicedentropy.jpg +0 -0
  297. package/AISB/image/076_aisb.t3.076_aanet.jpg +0 -0
  298. package/AISB/image/077_aisb.t3.077_cmnn.jpg +0 -0
  299. package/AISB/image/078_aisb.t3.078_conformalanomaly.jpg +0 -0
  300. package/AISB/image/079_aisb.t3.079_dpfkmeans.jpg +0 -0
  301. package/AISB/image/080_aisb.t3.080_latentscorereweight.jpg +0 -0
  302. package/AISB/image/081_aisb.t3.081_qmamba.jpg +0 -0
  303. package/AISB/image/082_aisb.t3.082_onlinellmrouting.jpg +0 -0
  304. package/AISB/image/083_aisb.t3.083_starformer.jpg +0 -0
  305. package/AISB/image/084_aisb.t3.084_ift.jpg +0 -0
  306. package/AISB/image/085_aisb.t3.085_neuralsurv.jpg +0 -0
  307. package/AISB/image/086_aisb.t3.086_stella.jpg +0 -0
  308. package/AISB/image/087_aisb.t3.087_moses.jpg +0 -0
  309. package/AISB/image/088_aisb.t3.088_channelnorm.jpg +0 -0
  310. package/AISB/image/089_aisb.t3.089_causalvelocity.jpg +0 -0
  311. package/AISB/image/090_aisb.t3.090_rstib.jpg +0 -0
  312. package/AISB/image/091_aisb.t3.091_timeawarecausal.jpg +0 -0
  313. package/AISB/image/092_aisb.t3.092_kmeanslocalopt.jpg +0 -0
  314. package/AISB/image/093_aisb.t3.093_fedwmsam.jpg +0 -0
  315. package/AISB/image/094_aisb.t3.094_boundre.jpg +0 -0
  316. package/AISB/image/095_aisb.t3.095_fastfeaturecp.jpg +0 -0
  317. package/AISB/image/096_aisb.t3.096_m3svm.jpg +0 -0
  318. package/AISB/image/097_aisb.t3.097_wassersteintl.jpg +0 -0
  319. package/AISB/image/098_aisb.t3.098_xmahalanobis.jpg +0 -0
  320. package/AISB/image/099_aisb.t3.099_ollalanding.jpg +0 -0
  321. package/AISB/image/100_aisb.t3.100_invmissingdata.jpg +0 -0
  322. package/AISB/image/101_aisb.t3.101_acia.jpg +0 -0
  323. package/AISB/image/102_aisb.t3.102_stochasticff.jpg +0 -0
  324. package/AISB/image/103_aisb.t3.103_qdcp.jpg +0 -0
  325. package/AISB/image/104_aisb.t3.104_balancedactiveinf.jpg +0 -0
  326. package/AISB/image/105_aisb.t3.105_binaryclasseval.jpg +0 -0
  327. package/AISB/image/106_aisb.t1.reasoning_lite.jpg +0 -0
  328. package/AISB/image/107_aisb.t2.paper_audit.jpg +0 -0
  329. package/AISB/image/108_aisb.t3.multi_gpu_search.jpg +0 -0
  330. package/AISB/image/109_aisb.t3.tdc_admet.jpg +0 -0
  331. package/AISB/image/aisb.b1.agentic_coding.svg +16 -0
  332. package/AISB/image/aisb.b10.climate_earth.svg +16 -0
  333. package/AISB/image/aisb.b11.model_efficiency.svg +16 -0
  334. package/AISB/image/aisb.b12.embodied_ai.svg +16 -0
  335. package/AISB/image/aisb.b2.agent_systems.svg +16 -0
  336. package/AISB/image/aisb.b3.self_evolving_rl.svg +16 -0
  337. package/AISB/image/aisb.b4.lm_reasoning.svg +16 -0
  338. package/AISB/image/aisb.b5.math_proof.svg +16 -0
  339. package/AISB/image/aisb.b6.research_process.svg +16 -0
  340. package/AISB/image/aisb.b7.multimodal_fusion.svg +16 -0
  341. package/AISB/image/aisb.b8.lifesci_drug.svg +16 -0
  342. package/AISB/image/aisb.b9.material_science.svg +16 -0
  343. package/README.md +196 -32
  344. package/bin/ds.js +924 -66
  345. package/docs/en/00_QUICK_START.md +195 -18
  346. package/docs/en/01_SETTINGS_REFERENCE.md +468 -96
  347. package/docs/en/02_START_RESEARCH_GUIDE.md +26 -5
  348. package/docs/en/03_QQ_CONNECTOR_GUIDE.md +14 -3
  349. package/docs/en/04_LINGZHU_CONNECTOR_GUIDE.md +2 -0
  350. package/docs/en/05_TUI_GUIDE.md +171 -2
  351. package/docs/en/07_MEMORY_AND_MCP.md +38 -2
  352. package/docs/en/09_DOCTOR.md +78 -7
  353. package/docs/en/10_WEIXIN_CONNECTOR_GUIDE.md +38 -1
  354. package/docs/en/11_LICENSE_AND_RISK.md +4 -0
  355. package/docs/en/12_GUIDED_WORKFLOW_TOUR.md +15 -0
  356. package/docs/en/14_PROMPT_SKILLS_AND_MCP_GUIDE.md +9 -0
  357. package/docs/en/15_CODEX_PROVIDER_SETUP.md +624 -180
  358. package/docs/en/16_TELEGRAM_CONNECTOR_GUIDE.md +14 -0
  359. package/docs/en/17_WHATSAPP_CONNECTOR_GUIDE.md +14 -0
  360. package/docs/en/18_FEISHU_CONNECTOR_GUIDE.md +14 -0
  361. package/docs/en/21_LOCAL_MODEL_BACKENDS_GUIDE.md +386 -0
  362. package/docs/en/22_BENCHSTORE_YAML_REFERENCE.md +469 -0
  363. package/docs/en/23_BENCHSTORE_GITHUB_RELEASES_SPEC.md +316 -0
  364. package/docs/en/24_CLAUDE_CODE_PROVIDER_SETUP.md +469 -0
  365. package/docs/en/25_OPENCODE_PROVIDER_SETUP.md +653 -0
  366. package/docs/en/26_CITATION_AND_ATTRIBUTION.md +119 -0
  367. package/docs/en/27_KIMI_CODE_PROVIDER_SETUP.md +180 -0
  368. package/docs/en/28_DISCORD_CONNECTOR_GUIDE.md +61 -0
  369. package/docs/en/29_SLACK_CONNECTOR_GUIDE.md +60 -0
  370. package/docs/en/30_SETTINGS_CONTROL_CENTER_GUIDE.md +371 -0
  371. package/docs/en/{19_LOCAL_BROWSER_AUTH.md → 31_LOCAL_BROWSER_AUTH.md} +1 -1
  372. package/docs/en/32_WINDOWS_WSL2_DEPLOYMENT_GUIDE.md +273 -0
  373. package/docs/en/33_WORKSPACE_EXPLORER_QA.md +121 -0
  374. package/docs/en/91_DEVELOPMENT.md +266 -0
  375. package/docs/en/99_ACKNOWLEDGEMENTS.md +24 -19
  376. package/docs/en/README.md +48 -7
  377. package/docs/images/admin/admin-connectors-health-en.png +0 -0
  378. package/docs/images/admin/admin-controllers-en.png +0 -0
  379. package/docs/images/admin/admin-diagnostics-en.png +0 -0
  380. package/docs/images/admin/admin-errors-en.png +0 -0
  381. package/docs/images/admin/admin-issues-en.png +0 -0
  382. package/docs/images/admin/admin-logs-en.png +0 -0
  383. package/docs/images/admin/admin-quest-detail-en.png +0 -0
  384. package/docs/images/admin/admin-quests-en.png +0 -0
  385. package/docs/images/admin/admin-repairs-en.png +0 -0
  386. package/docs/images/admin/admin-runtime-en.png +0 -0
  387. package/docs/images/admin/admin-search-en.png +0 -0
  388. package/docs/images/admin/admin-stats-en.png +0 -0
  389. package/docs/images/admin/admin-summary-en.png +0 -0
  390. package/docs/images/connectors/connector-discord-en.png +0 -0
  391. package/docs/images/connectors/connector-feishu-en.png +0 -0
  392. package/docs/images/connectors/connector-lingzhu-en.png +0 -0
  393. package/docs/images/connectors/connector-qq-en.png +0 -0
  394. package/docs/images/connectors/connector-slack-en.png +0 -0
  395. package/docs/images/connectors/connector-telegram-en.png +0 -0
  396. package/docs/images/connectors/connector-weixin-en.png +0 -0
  397. package/docs/images/connectors/connector-whatsapp-en.png +0 -0
  398. package/docs/images/settings/settings-baselines-en.png +0 -0
  399. package/docs/images/settings/settings-config-en.png +0 -0
  400. package/docs/images/settings/settings-connectors-overview-en.png +0 -0
  401. package/docs/images/settings/settings-deepxiv-en.png +0 -0
  402. package/docs/images/settings/settings-mcp-servers-en.png +0 -0
  403. package/docs/images/settings/settings-plugins-en.png +0 -0
  404. package/docs/images/settings/settings-runners-en.png +0 -0
  405. package/docs/zh/00_QUICK_START.md +142 -18
  406. package/docs/zh/01_SETTINGS_REFERENCE.md +219 -98
  407. package/docs/zh/02_START_RESEARCH_GUIDE.md +26 -5
  408. package/docs/zh/05_TUI_GUIDE.md +171 -2
  409. package/docs/zh/07_MEMORY_AND_MCP.md +29 -2
  410. package/docs/zh/09_DOCTOR.md +54 -8
  411. package/docs/zh/10_WEIXIN_CONNECTOR_GUIDE.md +24 -1
  412. package/docs/zh/11_LICENSE_AND_RISK.md +4 -0
  413. package/docs/zh/12_GUIDED_WORKFLOW_TOUR.md +15 -0
  414. package/docs/zh/14_PROMPT_SKILLS_AND_MCP_GUIDE.md +9 -0
  415. package/docs/zh/15_CODEX_PROVIDER_SETUP.md +552 -181
  416. package/docs/zh/21_LOCAL_MODEL_BACKENDS_GUIDE.md +384 -0
  417. package/docs/zh/22_BENCHSTORE_YAML_REFERENCE.md +459 -0
  418. package/docs/zh/23_BENCHSTORE_GITHUB_RELEASES_SPEC.md +287 -0
  419. package/docs/zh/23_CLAUDE_RUNNER_GUIDE.md +103 -0
  420. package/docs/zh/24_CLAUDE_CODE_PROVIDER_SETUP.md +460 -0
  421. package/docs/zh/25_OPENCODE_PROVIDER_SETUP.md +660 -0
  422. package/docs/zh/26_CITATION_AND_ATTRIBUTION.md +102 -0
  423. package/docs/zh/27_KIMI_CODE_PROVIDER_SETUP.md +51 -0
  424. package/docs/zh/{19_LOCAL_BROWSER_AUTH.md → 31_LOCAL_BROWSER_AUTH.md} +1 -1
  425. package/docs/zh/32_WINDOWS_WSL2_DEPLOYMENT_GUIDE.md +264 -0
  426. package/docs/zh/33_WORKSPACE_EXPLORER_QA.md +127 -0
  427. package/docs/zh/99_ACKNOWLEDGEMENTS.md +23 -19
  428. package/docs/zh/README.md +33 -7
  429. package/install.sh +168 -20
  430. package/package.json +5 -1
  431. package/pyproject.toml +2 -1
  432. package/src/deepscientist/__init__.py +1 -1
  433. package/src/deepscientist/acp/envelope.py +13 -0
  434. package/src/deepscientist/admin/__init__.py +3 -0
  435. package/src/deepscientist/admin/charts.py +681 -0
  436. package/src/deepscientist/admin/logs.py +119 -0
  437. package/src/deepscientist/admin/repairs.py +217 -0
  438. package/src/deepscientist/admin/service.py +1310 -0
  439. package/src/deepscientist/admin/system_info.py +700 -0
  440. package/src/deepscientist/admin/tasks.py +465 -0
  441. package/src/deepscientist/admin/tool_metrics.py +600 -0
  442. package/src/deepscientist/artifact/guidance.py +8 -4
  443. package/src/deepscientist/artifact/schemas.py +115 -0
  444. package/src/deepscientist/artifact/service.py +4268 -260
  445. package/src/deepscientist/bash_exec/monitor.py +30 -3
  446. package/src/deepscientist/bash_exec/service.py +134 -1
  447. package/src/deepscientist/benchstore/__init__.py +4 -0
  448. package/src/deepscientist/benchstore/prompt_builder.py +224 -0
  449. package/src/deepscientist/benchstore/service.py +1716 -0
  450. package/src/deepscientist/bridges/connectors.py +8 -2
  451. package/src/deepscientist/channels/weixin_ilink.py +8 -1
  452. package/src/deepscientist/cli.py +92 -17
  453. package/src/deepscientist/codex_cli_compat.py +187 -74
  454. package/src/deepscientist/config/models.py +82 -11
  455. package/src/deepscientist/config/service.py +1077 -93
  456. package/src/deepscientist/connector/weixin_support.py +48 -17
  457. package/src/deepscientist/daemon/api/handlers.py +827 -235
  458. package/src/deepscientist/daemon/api/router.py +81 -1
  459. package/src/deepscientist/daemon/app.py +1512 -85
  460. package/src/deepscientist/diagnostics/__init__.py +6 -0
  461. package/src/deepscientist/diagnostics/runner_failures.py +277 -0
  462. package/src/deepscientist/doctor.py +407 -56
  463. package/src/deepscientist/evidence_packets.py +590 -0
  464. package/src/deepscientist/home.py +52 -4
  465. package/src/deepscientist/kimi_cli_compat.py +50 -0
  466. package/src/deepscientist/latex_runtime.py +2 -2
  467. package/src/deepscientist/mcp/context.py +2 -0
  468. package/src/deepscientist/mcp/schemas.py +114 -0
  469. package/src/deepscientist/mcp/server.py +1566 -126
  470. package/src/deepscientist/memory/service.py +203 -16
  471. package/src/deepscientist/process_control.py +8 -1
  472. package/src/deepscientist/prompts/builder.py +850 -88
  473. package/src/deepscientist/quest/__init__.py +2 -2
  474. package/src/deepscientist/quest/layout.py +12 -1
  475. package/src/deepscientist/quest/node_traces.py +10 -0
  476. package/src/deepscientist/quest/service.py +1852 -161
  477. package/src/deepscientist/quest/stage_views.py +1 -1
  478. package/src/deepscientist/runners/__init__.py +18 -0
  479. package/src/deepscientist/runners/base.py +89 -1
  480. package/src/deepscientist/runners/builtins.py +13 -1
  481. package/src/deepscientist/runners/claude.py +391 -0
  482. package/src/deepscientist/runners/codex.py +480 -35
  483. package/src/deepscientist/runners/codex_telemetry.py +127 -0
  484. package/src/deepscientist/runners/kimi.py +334 -0
  485. package/src/deepscientist/runners/metadata.py +68 -0
  486. package/src/deepscientist/runners/opencode.py +414 -0
  487. package/src/deepscientist/runners/runtime_overrides.py +100 -0
  488. package/src/deepscientist/runners/simple_cli.py +538 -0
  489. package/src/deepscientist/runtime_storage.py +303 -0
  490. package/src/deepscientist/shared.py +80 -16
  491. package/src/deepscientist/skills/installer.py +37 -0
  492. package/src/deepscientist/skills/registry.py +2 -0
  493. package/src/deepscientist/tinytex.py +2 -2
  494. package/src/deepscientist/tui.py +10 -3
  495. package/src/prompts/benchstore/system.md +77 -0
  496. package/src/prompts/connectors/qq.md +33 -2
  497. package/src/prompts/connectors/weixin.md +208 -23
  498. package/src/prompts/contracts/admin_ops.md +74 -0
  499. package/src/prompts/contracts/admin_ops_knowledge.md +138 -0
  500. package/src/prompts/contracts/shared_interaction.md +5 -10
  501. package/src/prompts/start_setup/system.md +422 -0
  502. package/src/prompts/system.md +411 -304
  503. package/src/prompts/system_copilot.md +89 -0
  504. package/src/skills/analysis-campaign/SKILL.md +239 -578
  505. package/src/skills/analysis-campaign/references/artifact-flow-examples.md +102 -0
  506. package/src/skills/analysis-campaign/references/boundary-cases.md +98 -0
  507. package/src/skills/analysis-campaign/references/campaign-checklist-template.md +39 -24
  508. package/src/skills/analysis-campaign/references/campaign-design.md +26 -10
  509. package/src/skills/analysis-campaign/references/campaign-plan-template.md +53 -54
  510. package/src/skills/analysis-campaign/references/operational-guidance.md +97 -0
  511. package/src/skills/analysis-campaign/references/writing-facing-slice-examples.md +10 -20
  512. package/src/skills/baseline/SKILL.md +183 -461
  513. package/src/skills/baseline/references/artifact-flow-examples.md +106 -0
  514. package/src/skills/baseline/references/artifact-payload-examples.md +1 -1
  515. package/src/skills/baseline/references/baseline-checklist-template.md +27 -35
  516. package/src/skills/baseline/references/baseline-plan-template.md +37 -76
  517. package/src/skills/baseline/references/boundary-cases.md +86 -0
  518. package/src/skills/baseline/references/codebase-audit-checklist.md +2 -6
  519. package/src/skills/baseline/references/comparability-contract.md +7 -12
  520. package/src/skills/baseline/references/operational-guidance.md +56 -0
  521. package/src/skills/baseline/references/route-selection.md +5 -25
  522. package/src/skills/decision/SKILL.md +113 -306
  523. package/src/skills/decision/references/checkpoint-memory-template.md +47 -0
  524. package/src/skills/decision/references/operational-guidance.md +94 -0
  525. package/src/skills/decision/references/research-route-criteria.md +7 -8
  526. package/src/skills/decision/references/strategic-decision-template.md +13 -26
  527. package/src/skills/experiment/SKILL.md +132 -670
  528. package/src/skills/experiment/references/execution-playbook.md +374 -0
  529. package/src/skills/experiment/references/main-experiment-checklist-template.md +26 -2
  530. package/src/skills/experiment/references/main-experiment-plan-template.md +28 -17
  531. package/src/skills/experiment/references/operational-guidance.md +108 -0
  532. package/src/skills/finalize/SKILL.md +62 -0
  533. package/src/skills/finalize/references/checkpoint-memory-template.md +49 -0
  534. package/src/skills/finalize/references/resume-packet-template.md +7 -0
  535. package/src/skills/idea/SKILL.md +228 -15
  536. package/src/skills/idea/references/controlled-brainstorming-playbook.md +78 -0
  537. package/src/skills/idea/references/current-board-packet-template.md +61 -0
  538. package/src/skills/idea/references/high-value-idea-sourcing.md +119 -0
  539. package/src/skills/idea/references/idea-generation-playbook.md +21 -0
  540. package/src/skills/idea/references/idea-thinking-flow.md +6 -0
  541. package/src/skills/idea/references/literature-survey-template.md +3 -0
  542. package/src/skills/idea/references/objective-contract-template.md +54 -0
  543. package/src/skills/idea/references/outline-seeding-example.md +56 -0
  544. package/src/skills/idea/references/pre-idea-draft-template.md +105 -0
  545. package/src/skills/idea/references/related-work-playbook.md +75 -2
  546. package/src/skills/idea/references/research-history-playbook.md +114 -0
  547. package/src/skills/idea/references/selection-gate.md +58 -6
  548. package/src/skills/intake-audit/SKILL.md +43 -2
  549. package/src/skills/intake-audit/references/state-audit-template.md +10 -0
  550. package/src/skills/nature-data/SKILL.md +128 -0
  551. package/src/skills/nature-data/UPSTREAM_LICENSE.txt +21 -0
  552. package/src/skills/nature-data/agents/openai.yaml +4 -0
  553. package/src/skills/nature-data/references/chinese-author-alignment.md +84 -0
  554. package/src/skills/nature-data/references/fair-metadata-checklist.md +105 -0
  555. package/src/skills/nature-data/references/policy-principles.md +103 -0
  556. package/src/skills/nature-data/references/repository-and-identifiers.md +96 -0
  557. package/src/skills/nature-data/references/source-basis.md +54 -0
  558. package/src/skills/nature-data/references/statement-patterns.md +153 -0
  559. package/src/skills/nature-figure/SKILL.md +197 -0
  560. package/src/skills/nature-figure/UPSTREAM_LICENSE.txt +21 -0
  561. package/src/skills/nature-figure/agents/openai.yaml +4 -0
  562. package/src/skills/nature-figure/evals/evals.json +37 -0
  563. package/src/skills/nature-figure/references/api.md +428 -0
  564. package/src/skills/nature-figure/references/backend-selection.md +100 -0
  565. package/src/skills/nature-figure/references/chart-types.md +281 -0
  566. package/src/skills/nature-figure/references/common-patterns.md +349 -0
  567. package/src/skills/nature-figure/references/design-theory.md +436 -0
  568. package/src/skills/nature-figure/references/figure-contract.md +93 -0
  569. package/src/skills/nature-figure/references/nature-2026-observations.md +112 -0
  570. package/src/skills/nature-figure/references/qa-contract.md +119 -0
  571. package/src/skills/nature-figure/references/r-template-index.md +66 -0
  572. package/src/skills/nature-figure/references/r-workflow.md +161 -0
  573. package/src/skills/nature-figure/references/tutorials.md +250 -0
  574. package/src/skills/nature-paper2ppt/SKILL.md +507 -0
  575. package/src/skills/nature-paper2ppt/UPSTREAM_LICENSE.txt +21 -0
  576. package/src/skills/nature-paper2ppt/agents/openai.yaml +4 -0
  577. package/src/skills/nature-polishing/SKILL.md +385 -0
  578. package/src/skills/nature-polishing/UPSTREAM_LICENSE.txt +21 -0
  579. package/src/skills/nature-polishing/agents/openai.yaml +4 -0
  580. package/src/skills/nature-polishing/references/phrasebank-playbook.md +162 -0
  581. package/src/skills/nature-polishing/references/section-moves.md +240 -0
  582. package/src/skills/nature-polishing/references/style-guardrails.md +94 -0
  583. package/src/skills/nature-polishing/references/writing-strategy.md +148 -0
  584. package/src/skills/optimize/SKILL.md +177 -1568
  585. package/src/skills/optimize/references/brief-shaping-playbook.md +95 -0
  586. package/src/skills/optimize/references/candidate-board-template.md +13 -0
  587. package/src/skills/optimize/references/candidate-ranking-template.md +51 -0
  588. package/src/skills/optimize/references/codegen-route-playbook.md +50 -0
  589. package/src/skills/optimize/references/debug-response-template.md +29 -0
  590. package/src/skills/optimize/references/frontier-review-template.md +32 -0
  591. package/src/skills/optimize/references/fusion-playbook.md +36 -0
  592. package/src/skills/optimize/references/method-brief-template.md +73 -0
  593. package/src/skills/optimize/references/operational-guidance.md +621 -0
  594. package/src/skills/optimize/references/optimization-memory-template.md +30 -0
  595. package/src/skills/optimize/references/optimize-checklist-template.md +18 -0
  596. package/src/skills/optimize/references/plateau-response-playbook.md +28 -0
  597. package/src/skills/optimize/references/prompt-patterns.md +49 -0
  598. package/src/skills/paper-outline/SKILL.md +227 -0
  599. package/src/skills/paper-outline/references/outline-patterns.md +87 -0
  600. package/src/skills/paper-plot/SKILL.md +79 -0
  601. package/src/skills/paper-plot/agents/openai.yaml +4 -0
  602. package/src/skills/paper-plot/references/bar_grouped_hatch.md +96 -0
  603. package/src/skills/paper-plot/references/bar_paired_delta.md +72 -0
  604. package/src/skills/paper-plot/references/line_confidence_band.md +75 -0
  605. package/src/skills/paper-plot/references/line_loss_with_inset.md +65 -0
  606. package/src/skills/paper-plot/references/line_training_curve.md +44 -0
  607. package/src/skills/paper-plot/references/radar_dual_series.md +59 -0
  608. package/src/skills/paper-plot/references/scatter_broken_axis.md +59 -0
  609. package/src/skills/paper-plot/references/scatter_tsne_cluster.md +72 -0
  610. package/src/skills/paper-plot/scripts/bar_memevolve.py +109 -0
  611. package/src/skills/paper-plot/scripts/bar_spice.py +166 -0
  612. package/src/skills/paper-plot/scripts/line_aime.py +94 -0
  613. package/src/skills/paper-plot/scripts/line_loss_inset.py +157 -0
  614. package/src/skills/paper-plot/scripts/line_selfdistill.py +168 -0
  615. package/src/skills/paper-plot/scripts/radar_dora.py +151 -0
  616. package/src/skills/paper-plot/scripts/scatter_break.py +169 -0
  617. package/src/skills/paper-plot/scripts/scatter_tsne.py +133 -0
  618. package/src/skills/rebuttal/SKILL.md +9 -0
  619. package/src/skills/references/tool-usage-by-stage.md +438 -0
  620. package/src/skills/review/SKILL.md +105 -7
  621. package/src/skills/science/PROVENANCE.md +44 -0
  622. package/src/skills/science/SKILL.md +137 -0
  623. package/src/skills/science/references/artifact-science-tool.md +110 -0
  624. package/src/skills/science/references/claim-type-discipline.md +56 -0
  625. package/src/skills/science/references/domain-index.md +422 -0
  626. package/src/skills/science/references/hpc-via-bash-exec.md +42 -0
  627. package/src/skills/science/references/package-check-playbook.md +64 -0
  628. package/src/skills/science/references/package-index.min.json +3616 -0
  629. package/src/skills/science/references/packages/abinit.md +80 -0
  630. package/src/skills/science/references/packages/acts.md +73 -0
  631. package/src/skills/science/references/packages/aiida-core.md +80 -0
  632. package/src/skills/science/references/packages/alamode.md +80 -0
  633. package/src/skills/science/references/packages/amuse.md +88 -0
  634. package/src/skills/science/references/packages/anndata.md +88 -0
  635. package/src/skills/science/references/packages/arbor.md +80 -0
  636. package/src/skills/science/references/packages/arc.md +73 -0
  637. package/src/skills/science/references/packages/astropy.md +88 -0
  638. package/src/skills/science/references/packages/astroquery.md +88 -0
  639. package/src/skills/science/references/packages/atomate2.md +80 -0
  640. package/src/skills/science/references/packages/atomsmltr.md +73 -0
  641. package/src/skills/science/references/packages/awkward.md +73 -0
  642. package/src/skills/science/references/packages/batman.md +88 -0
  643. package/src/skills/science/references/packages/biopython.md +88 -0
  644. package/src/skills/science/references/packages/bloqade.md +73 -0
  645. package/src/skills/science/references/packages/brian2.md +73 -0
  646. package/src/skills/science/references/packages/bullet3.md +73 -0
  647. package/src/skills/science/references/packages/calculix.md +80 -0
  648. package/src/skills/science/references/packages/cantera.md +73 -0
  649. package/src/skills/science/references/packages/cavity-md-ipi.md +80 -0
  650. package/src/skills/science/references/packages/ccdproc.md +88 -0
  651. package/src/skills/science/references/packages/celerite2.md +88 -0
  652. package/src/skills/science/references/packages/cellrank.md +73 -0
  653. package/src/skills/science/references/packages/cesm.md +80 -0
  654. package/src/skills/science/references/packages/chemicals.md +73 -0
  655. package/src/skills/science/references/packages/chempy.md +73 -0
  656. package/src/skills/science/references/packages/cirq.md +73 -0
  657. package/src/skills/science/references/packages/coffea.md +73 -0
  658. package/src/skills/science/references/packages/cp2k.md +88 -0
  659. package/src/skills/science/references/packages/custodian.md +80 -0
  660. package/src/skills/science/references/packages/dart.md +73 -0
  661. package/src/skills/science/references/packages/datamol.md +88 -0
  662. package/src/skills/science/references/packages/dd4hep.md +73 -0
  663. package/src/skills/science/references/packages/dealii.md +80 -0
  664. package/src/skills/science/references/packages/deepchem.md +88 -0
  665. package/src/skills/science/references/packages/delphes.md +73 -0
  666. package/src/skills/science/references/packages/devito.md +80 -0
  667. package/src/skills/science/references/packages/dftb.md +88 -0
  668. package/src/skills/science/references/packages/dftd4.md +88 -0
  669. package/src/skills/science/references/packages/dftk-jl.md +80 -0
  670. package/src/skills/science/references/packages/dolfinx.md +80 -0
  671. package/src/skills/science/references/packages/drake.md +73 -0
  672. package/src/skills/science/references/packages/dumux.md +73 -0
  673. package/src/skills/science/references/packages/elk.md +80 -0
  674. package/src/skills/science/references/packages/elmerfem.md +80 -0
  675. package/src/skills/science/references/packages/enzo-e.md +88 -0
  676. package/src/skills/science/references/packages/espresso.md +80 -0
  677. package/src/skills/science/references/packages/exoplanet.md +88 -0
  678. package/src/skills/science/references/packages/fairroot.md +73 -0
  679. package/src/skills/science/references/packages/fbpic.md +80 -0
  680. package/src/skills/science/references/packages/fdtdbath-meep.md +80 -0
  681. package/src/skills/science/references/packages/geant4.md +73 -0
  682. package/src/skills/science/references/packages/geosx.md +80 -0
  683. package/src/skills/science/references/packages/gprmax.md +80 -0
  684. package/src/skills/science/references/packages/gromacs.md +80 -0
  685. package/src/skills/science/references/packages/gwaslab.md +73 -0
  686. package/src/skills/science/references/packages/gz-sim.md +73 -0
  687. package/src/skills/science/references/packages/hail.md +88 -0
  688. package/src/skills/science/references/packages/hiphive.md +80 -0
  689. package/src/skills/science/references/packages/hoomd-blue.md +80 -0
  690. package/src/skills/science/references/packages/itensor.md +73 -0
  691. package/src/skills/science/references/packages/itensors-jl.md +73 -0
  692. package/src/skills/science/references/packages/jdftx.md +73 -0
  693. package/src/skills/science/references/packages/jobflow.md +80 -0
  694. package/src/skills/science/references/packages/kadanoffbaym-jl.md +73 -0
  695. package/src/skills/science/references/packages/kite.md +80 -0
  696. package/src/skills/science/references/packages/kratos.md +80 -0
  697. package/src/skills/science/references/packages/kwant.md +73 -0
  698. package/src/skills/science/references/packages/lammps.md +80 -0
  699. package/src/skills/science/references/packages/lightkurve.md +88 -0
  700. package/src/skills/science/references/packages/limix.md +73 -0
  701. package/src/skills/science/references/packages/maxwelllink.md +80 -0
  702. package/src/skills/science/references/packages/mcdc.md +73 -0
  703. package/src/skills/science/references/packages/meep.md +80 -0
  704. package/src/skills/science/references/packages/mfem.md +80 -0
  705. package/src/skills/science/references/packages/mitgcm.md +73 -0
  706. package/src/skills/science/references/packages/modflow6.md +73 -0
  707. package/src/skills/science/references/packages/molecool.md +73 -0
  708. package/src/skills/science/references/packages/mom6.md +73 -0
  709. package/src/skills/science/references/packages/moose.md +80 -0
  710. package/src/skills/science/references/packages/mpas-model.md +73 -0
  711. package/src/skills/science/references/packages/mujoco.md +73 -0
  712. package/src/skills/science/references/packages/mumax3.md +73 -0
  713. package/src/skills/science/references/packages/nekrs.md +80 -0
  714. package/src/skills/science/references/packages/nessi.md +73 -0
  715. package/src/skills/science/references/packages/nest-simulator.md +73 -0
  716. package/src/skills/science/references/packages/netket.md +73 -0
  717. package/src/skills/science/references/packages/neuron.md +73 -0
  718. package/src/skills/science/references/packages/nextflow.md +88 -0
  719. package/src/skills/science/references/packages/nwchem.md +88 -0
  720. package/src/skills/science/references/packages/openbabel.md +88 -0
  721. package/src/skills/science/references/packages/openems.md +80 -0
  722. package/src/skills/science/references/packages/openff-toolkit.md +88 -0
  723. package/src/skills/science/references/packages/openfoam-dev.md +80 -0
  724. package/src/skills/science/references/packages/openmc.md +73 -0
  725. package/src/skills/science/references/packages/openmm.md +80 -0
  726. package/src/skills/science/references/packages/openmoc.md +73 -0
  727. package/src/skills/science/references/packages/openmx.md +80 -0
  728. package/src/skills/science/references/packages/opensees.md +80 -0
  729. package/src/skills/science/references/packages/opensn.md +80 -0
  730. package/src/skills/science/references/packages/opm-simulators.md +73 -0
  731. package/src/skills/science/references/packages/oqupy.md +73 -0
  732. package/src/skills/science/references/packages/packmol.md +80 -0
  733. package/src/skills/science/references/packages/palabos.md +80 -0
  734. package/src/skills/science/references/packages/parflow.md +80 -0
  735. package/src/skills/science/references/packages/pennylane.md +88 -0
  736. package/src/skills/science/references/packages/perceval.md +73 -0
  737. package/src/skills/science/references/packages/phono3py.md +73 -0
  738. package/src/skills/science/references/packages/phonopy.md +73 -0
  739. package/src/skills/science/references/packages/photutils.md +88 -0
  740. package/src/skills/science/references/packages/picongpu.md +80 -0
  741. package/src/skills/science/references/packages/plink-ng.md +88 -0
  742. package/src/skills/science/references/packages/precice.md +73 -0
  743. package/src/skills/science/references/packages/psc.md +80 -0
  744. package/src/skills/science/references/packages/psi4.md +88 -0
  745. package/src/skills/science/references/packages/pybinding.md +73 -0
  746. package/src/skills/science/references/packages/pyfr.md +80 -0
  747. package/src/skills/science/references/packages/pyhf.md +73 -0
  748. package/src/skills/science/references/packages/pyiron_base.md +80 -0
  749. package/src/skills/science/references/packages/pylcp.md +73 -0
  750. package/src/skills/science/references/packages/pylith.md +80 -0
  751. package/src/skills/science/references/packages/pynbody.md +88 -0
  752. package/src/skills/science/references/packages/pysam.md +88 -0
  753. package/src/skills/science/references/packages/pyscf.md +88 -0
  754. package/src/skills/science/references/packages/q-e.md +73 -0
  755. package/src/skills/science/references/packages/qibo.md +73 -0
  756. package/src/skills/science/references/packages/qiskit.md +73 -0
  757. package/src/skills/science/references/packages/quantica-jl.md +73 -0
  758. package/src/skills/science/references/packages/quantumoptics-jl.md +73 -0
  759. package/src/skills/science/references/packages/quimb.md +73 -0
  760. package/src/skills/science/references/packages/qulacs.md +73 -0
  761. package/src/skills/science/references/packages/qutip.md +73 -0
  762. package/src/skills/science/references/packages/rdkit.md +88 -0
  763. package/src/skills/science/references/packages/rmg-py.md +73 -0
  764. package/src/skills/science/references/packages/root.md +73 -0
  765. package/src/skills/science/references/packages/scanpy.md +88 -0
  766. package/src/skills/science/references/packages/scikit-allel.md +88 -0
  767. package/src/skills/science/references/packages/scikit-bio.md +88 -0
  768. package/src/skills/science/references/packages/scqubits.md +73 -0
  769. package/src/skills/science/references/packages/scuff-em.md +80 -0
  770. package/src/skills/science/references/packages/scvi-tools.md +73 -0
  771. package/src/skills/science/references/packages/seissol.md +73 -0
  772. package/src/skills/science/references/packages/sfepy.md +80 -0
  773. package/src/skills/science/references/packages/sisl.md +73 -0
  774. package/src/skills/science/references/packages/smilei.md +80 -0
  775. package/src/skills/science/references/packages/snakemake.md +88 -0
  776. package/src/skills/science/references/packages/specfem3d-globe.md +80 -0
  777. package/src/skills/science/references/packages/specutils.md +88 -0
  778. package/src/skills/science/references/packages/spglib.md +80 -0
  779. package/src/skills/science/references/packages/squidpy.md +88 -0
  780. package/src/skills/science/references/packages/starry.md +88 -0
  781. package/src/skills/science/references/packages/strawberryfields.md +73 -0
  782. package/src/skills/science/references/packages/su2.md +80 -0
  783. package/src/skills/science/references/packages/sunny-jl.md +73 -0
  784. package/src/skills/science/references/packages/sw4.md +73 -0
  785. package/src/skills/science/references/packages/swift.md +88 -0
  786. package/src/skills/science/references/packages/tdnegf.md +73 -0
  787. package/src/skills/science/references/packages/tenpy.md +73 -0
  788. package/src/skills/science/references/packages/thermo.md +73 -0
  789. package/src/skills/science/references/packages/tkwant.md +73 -0
  790. package/src/skills/science/references/packages/tvb-root.md +73 -0
  791. package/src/skills/science/references/packages/uproot5.md +73 -0
  792. package/src/skills/science/references/packages/vampire.md +80 -0
  793. package/src/skills/science/references/packages/wannier_tools.md +73 -0
  794. package/src/skills/science/references/packages/warpx.md +80 -0
  795. package/src/skills/science/references/packages/wrf.md +73 -0
  796. package/src/skills/science/references/packages/xtb.md +88 -0
  797. package/src/skills/science/references/packages/yt.md +73 -0
  798. package/src/skills/science/references/science-task-brief-template.md +71 -0
  799. package/src/skills/scout/SKILL.md +83 -425
  800. package/src/skills/scout/references/literature-scout-template.md +5 -24
  801. package/src/skills/scout/references/operational-guidance.md +191 -0
  802. package/src/skills/scout/references/paper-triage-playbook.md +11 -35
  803. package/src/skills/write/SKILL.md +744 -1246
  804. package/src/skills/write/references/experiments_analysis_patterns.md +129 -0
  805. package/src/skills/write/references/oral_package_patterns.md +252 -0
  806. package/src/skills/write/references/oral_writing_principles.md +291 -0
  807. package/src/skills/write/references/section_rewrite_checklist.md +234 -0
  808. package/src/tui/dist/app/AppContainer.js +1314 -27
  809. package/src/tui/dist/components/Composer.js +26 -1
  810. package/src/tui/dist/components/ConfigScreen.js +2 -1
  811. package/src/tui/dist/components/InputPrompt.js +25 -9
  812. package/src/tui/dist/components/MainContent.js +18 -3
  813. package/src/tui/dist/components/QuestScreen.js +3 -2
  814. package/src/tui/dist/components/UtilityScreen.js +37 -0
  815. package/src/tui/dist/hooks/useSafeInput.js +10 -0
  816. package/src/tui/dist/index.js +13 -1
  817. package/src/tui/dist/layouts/DefaultAppLayout.js +11 -8
  818. package/src/tui/dist/lib/api.js +89 -1
  819. package/src/tui/package.json +1 -1
  820. package/src/ui/dist/assets/{AnalysisPlugin-DnSm0GZn.js → AnalysisPlugin-CA94NGmI.js} +1 -1
  821. package/src/ui/dist/assets/CliPlugin-DHBzphZU.js +79 -0
  822. package/src/ui/dist/assets/CodeEditorPlugin-BOFwD2rn.js +2 -0
  823. package/src/ui/dist/assets/{CodeViewerPlugin-itb0tltR.js → CodeViewerPlugin-CqDpgjik.js} +4 -4
  824. package/src/ui/dist/assets/{DocViewerPlugin-DqKkiCI6.js → DocViewerPlugin-UDBgt8-4.js} +3 -3
  825. package/src/ui/dist/assets/GitCommitViewerPlugin-BmHtZ0bZ.js +6 -0
  826. package/src/ui/dist/assets/{GitDiffViewerPlugin-DxL2ezFG.js → GitDiffViewerPlugin-CAxjNorQ.js} +2 -2
  827. package/src/ui/dist/assets/{GitSnapshotViewer-B_RQm1YZ.js → GitSnapshotViewer-CweA6VON.js} +2 -2
  828. package/src/ui/dist/assets/{ImageViewerPlugin-tHqlXY3n.js → ImageViewerPlugin-C8wHGvGN.js} +5 -5
  829. package/src/ui/dist/assets/LabPlugin-COyyLUol.js +32 -0
  830. package/src/ui/dist/assets/{LatexPlugin-B495DTXC.js → LatexPlugin-BQjAaA5J.js} +4 -4
  831. package/src/ui/dist/assets/{MarkdownViewerPlugin-DG28-61B.js → MarkdownViewerPlugin-Dy1NE2dI.js} +3 -3
  832. package/src/ui/dist/assets/{MarketplacePlugin-BiOGT-Kj.js → MarketplacePlugin-DMIZtEJ2.js} +2 -2
  833. package/src/ui/dist/assets/NotebookEditor-CFHMq_Qt.js +91 -0
  834. package/src/ui/dist/assets/{NotebookEditor-CVsj8h_T.js → NotebookEditor-WFyd8Ybt.js} +23 -23
  835. package/src/ui/dist/assets/{PdfLoader-CASDQmxJ.js → PdfLoader-CLE5u5TS.js} +3 -3
  836. package/src/ui/dist/assets/{PdfMarkdownPlugin-BFhwoKsY.js → PdfMarkdownPlugin-_iNK_H83.js} +1 -1
  837. package/src/ui/dist/assets/PdfViewerPlugin-DgWsbInT.js +22 -0
  838. package/src/ui/dist/assets/SearchPlugin-DrZmn5iw.js +11 -0
  839. package/src/ui/dist/assets/{TextViewerPlugin-CB4DYfWO.js → TextViewerPlugin-D1-T3aC7.js} +4 -4
  840. package/src/ui/dist/assets/branding/runner-claude.svg +107 -0
  841. package/src/ui/dist/assets/branding/runner-codex.svg +10 -0
  842. package/src/ui/dist/assets/branding/runner-kimi.svg +14 -0
  843. package/src/ui/dist/assets/branding/runner-opencode.svg +7 -0
  844. package/src/ui/dist/assets/cli-store-CoZ-x5Ip.js +1 -0
  845. package/src/ui/dist/assets/{code-DLC6G24T.js → code-DbsmSd3Y.js} +1 -1
  846. package/src/ui/dist/assets/file-diff-panel-DsvyRz47.js +1 -0
  847. package/src/ui/dist/assets/{wrap-text-CwMn-iqb.js → file-jump-queue-DeQBikaw.js} +3 -3
  848. package/src/ui/dist/assets/{file-socket-Cu4Qln7Y.js → file-socket-DA5XIx88.js} +1 -1
  849. package/src/ui/dist/assets/fonts/ds-fonts.css +50 -4
  850. package/src/ui/dist/assets/images/deepxiv/register-guide.png +0 -0
  851. package/src/ui/dist/assets/index-39vY9LmZ.js +1 -0
  852. package/src/ui/dist/assets/{index-wQ7RIIRd.js → index-BsO46tJA.js} +1 -1
  853. package/src/ui/dist/assets/index-CHzJ2xtB.js +3530 -0
  854. package/src/ui/dist/assets/index-DH-zxoZ3.css +33 -0
  855. package/src/ui/dist/assets/{plugin-notebook-HbW2K-1c.js → plugin-notebook-JRhysCqj.js} +2 -2
  856. package/src/ui/dist/assets/{project-sync-CsX08Qno.js → project-sync-DPmWKmKD.js} +1 -1
  857. package/src/ui/dist/assets/{zoom-out-R-GWEhzS.js → zoom-out-DAukFWen.js} +3 -3
  858. package/src/ui/dist/index.html +3 -3
  859. package/src/skills/analysis-campaign/references/artifact-orchestration.md +0 -58
  860. package/src/skills/baseline/references/memory-playbook.md +0 -40
  861. package/src/skills/baseline/references/publishable-baseline-package.md +0 -30
  862. package/src/skills/write/references/outline-evidence-contract-example.md +0 -107
  863. package/src/skills/write/references/paper-experiment-matrix-template.md +0 -131
  864. package/src/skills/write/references/paper-section-playbook.md +0 -64
  865. package/src/skills/write/references/reviewer-first-writing.md +0 -64
  866. package/src/skills/write/references/revision-checklist.md +0 -70
  867. package/src/skills/write/references/section-contracts.md +0 -82
  868. package/src/skills/write/references/sentence-level-proofing.md +0 -49
  869. package/src/ui/dist/assets/AiManusChatView-COFACy7V.js +0 -204
  870. package/src/ui/dist/assets/CliPlugin-CvwCmDQ5.js +0 -109
  871. package/src/ui/dist/assets/CodeEditorPlugin-cOqSa0xq.js +0 -2
  872. package/src/ui/dist/assets/GitCommitViewerPlugin-DVgNHBCS.js +0 -1
  873. package/src/ui/dist/assets/LabCopilotPanel-ClMbq5Yu.js +0 -14
  874. package/src/ui/dist/assets/LabPlugin-L_SuE8ow.js +0 -22
  875. package/src/ui/dist/assets/NotebookEditor-C-4Kt1p9.js +0 -81
  876. package/src/ui/dist/assets/PdfViewerPlugin-DcOzU9vd.js +0 -17
  877. package/src/ui/dist/assets/SearchPlugin-CHj7M58O.js +0 -16
  878. package/src/ui/dist/assets/VNCViewer-CjlbyCB3.js +0 -11
  879. package/src/ui/dist/assets/bot-CFkZY-JP.js +0 -6
  880. package/src/ui/dist/assets/chevron-up-Dq5ofbht.js +0 -6
  881. package/src/ui/dist/assets/file-content-Dv4LoZec.js +0 -1
  882. package/src/ui/dist/assets/file-diff-panel-Denq-lC3.js +0 -1
  883. package/src/ui/dist/assets/file-jump-queue-DA-SdG__.js +0 -1
  884. package/src/ui/dist/assets/git-commit-horizontal-BUh6G52n.js +0 -6
  885. package/src/ui/dist/assets/image-B9HUUddG.js +0 -6
  886. package/src/ui/dist/assets/index-B2B1sg-M.js +0 -1
  887. package/src/ui/dist/assets/index-Cgla8biy.css +0 -33
  888. package/src/ui/dist/assets/index-DRyx7vAc.js +0 -1
  889. package/src/ui/dist/assets/index-Gbl53BNp.js +0 -2496
  890. package/src/ui/dist/assets/pdf-effect-queue-ZtnHFCAi.js +0 -6
  891. package/src/ui/dist/assets/popover-DL6h35vr.js +0 -1
  892. package/src/ui/dist/assets/select-DvmXt1yY.js +0 -11
  893. package/src/ui/dist/assets/sigma-7jpXazui.js +0 -6
  894. package/src/ui/dist/assets/trash-xA7kFt8i.js +0 -11
  895. package/src/ui/dist/assets/useCliAccess-DsMwDjOp.js +0 -1
  896. package/src/ui/dist/assets/useFileDiffOverlay-FuhcnKiw.js +0 -1
@@ -0,0 +1,79 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BsO46tJA.js","assets/index-CHzJ2xtB.js","assets/plugin-monaco-C8UgLomw.js","assets/plugin-terminal-MXFIPun8.js","assets/plugin-notebook-JRhysCqj.js","assets/index-DH-zxoZ3.css"])))=>i.map(i=>d[i]);
2
+ import{t as je,bU as Bt,bV as or,bW as lr,bX as cr,bY as Tt,bZ as dr,b_ as ur,b$ as mr,c0 as fr,c1 as hr,c2 as xr,j as e,d as zt,b as ne,a6 as X,u as Ie,_ as Ht,c3 as Ls,R as ke,c4 as gt,a$ as Ze,c5 as Ds,c6 as pr,c7 as Ps,S as Dt,f as vt,c8 as Os,af as $s,z as gr,s as vr,r as br,p as wr,q as yr,c9 as Qe,ca as et,cb as tt,cc as st,cd as Us,ce as Vt,bv as Fs,cf as Nr,bw as ls,bx as Sr,by as qt,bz as Ee,cg as Me,bC as Bs,ch as jr,bB as Cr,bA as pe,bE as _r,ci as kr,bF as Er,bH as Tr,bG as Rr,bI as Ir,bJ as Ar,bK as Mr,bL as Lr,h as zs,g as Dr,cj as Pr,ck as Hs,bm as Or,cl as Vs,D as $r,cm as Ur,k as nt,cn as qs,co as Fr,cp as te,bg as cs,bh as ds,bi as us,bk as We,$ as ms,cq as fs,X as Rt,cr as Br,cs as zr,ct as Hr,cu as ge,o as Vr,cv as qr,c as Gr,cw as Wr,bP as Gs,cx as Kr,cy as Ws,cz as Yr,cA as Xr,cB as Jr,cC as Zr,cD as Qr,cE as It,cF as ei,cG as ti,cH as si,cI as ni,cJ as ri,cK as ii,cL as Ks,a0 as Gt,i as ai,ao as oi,B as hs,an as li,cM as ci,cN as di,cO as ui,cP as mi,L as Ye,cQ as fi,cR as hi,cS as xi,T as ft,cT as pi,cU as gi,cV as vi,N as bi,bd as wi,cW as yi}from"./index-CHzJ2xtB.js";import{r}from"./plugin-monaco-C8UgLomw.js";import{u as ce,C as ee}from"./cli-store-CoZ-x5Ip.js";import{S as Ni}from"./index-BsO46tJA.js";import{r as Ys}from"./plugin-notebook-JRhysCqj.js";import"./plugin-terminal-MXFIPun8.js";/**
3
+ * @license lucide-react v0.511.0 - ISC
4
+ *
5
+ * This source code is licensed under the ISC license.
6
+ * See the LICENSE file in the root directory of this source tree.
7
+ */const Si=[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]],ji=je("cloud-upload",Si);/**
8
+ * @license lucide-react v0.511.0 - ISC
9
+ *
10
+ * This source code is licensed under the ISC license.
11
+ * See the LICENSE file in the root directory of this source tree.
12
+ */const Ci=[["path",{d:"m7 21-4.3-4.3c-1-1-1-2.5 0-3.4l9.6-9.6c1-1 2.5-1 3.4 0l5.6 5.6c1 1 1 2.5 0 3.4L13 21",key:"182aya"}],["path",{d:"M22 21H7",key:"t4ddhn"}],["path",{d:"m5 11 9 9",key:"1mo9qw"}]],xs=je("eraser",Ci);/**
13
+ * @license lucide-react v0.511.0 - ISC
14
+ *
15
+ * This source code is licensed under the ISC license.
16
+ * See the LICENSE file in the root directory of this source tree.
17
+ */const _i=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]],ki=je("file-down",_i);/**
18
+ * @license lucide-react v0.511.0 - ISC
19
+ *
20
+ * This source code is licensed under the ISC license.
21
+ * See the LICENSE file in the root directory of this source tree.
22
+ */const Ei=[["line",{x1:"22",x2:"2",y1:"12",y2:"12",key:"1y58io"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}],["line",{x1:"6",x2:"6.01",y1:"16",y2:"16",key:"sgf278"}],["line",{x1:"10",x2:"10.01",y1:"16",y2:"16",key:"1l4acy"}]],Ti=je("hard-drive",Ei);/**
23
+ * @license lucide-react v0.511.0 - ISC
24
+ *
25
+ * This source code is licensed under the ISC license.
26
+ * See the LICENSE file in the root directory of this source tree.
27
+ */const Ri=[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-5.999a2 2 0 0 1 2.582 0l7 5.999A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"1d0kgt"}]],Ii=je("house",Ri);/**
28
+ * @license lucide-react v0.511.0 - ISC
29
+ *
30
+ * This source code is licensed under the ISC license.
31
+ * See the LICENSE file in the root directory of this source tree.
32
+ */const Ai=[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]],ht=je("layers",Ai);/**
33
+ * @license lucide-react v0.511.0 - ISC
34
+ *
35
+ * This source code is licensed under the ISC license.
36
+ * See the LICENSE file in the root directory of this source tree.
37
+ */const Mi=[["rect",{x:"3",y:"5",width:"6",height:"6",rx:"1",key:"1defrl"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"M13 6h8",key:"15sg57"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 18h8",key:"oe0vm4"}]],Li=je("list-todo",Mi);/**
38
+ * @license lucide-react v0.511.0 - ISC
39
+ *
40
+ * This source code is licensed under the ISC license.
41
+ * See the LICENSE file in the root directory of this source tree.
42
+ */const Di=[["path",{d:"M6 19v-3",key:"1nvgqn"}],["path",{d:"M10 19v-3",key:"iu8nkm"}],["path",{d:"M14 19v-3",key:"kcehxu"}],["path",{d:"M18 19v-3",key:"1vh91z"}],["path",{d:"M8 11V9",key:"63erz4"}],["path",{d:"M16 11V9",key:"fru6f3"}],["path",{d:"M12 11V9",key:"ha00sb"}],["path",{d:"M2 15h20",key:"16ne18"}],["path",{d:"M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z",key:"lhddv3"}]],Pi=je("memory-stick",Di);/**
43
+ * @license lucide-react v0.511.0 - ISC
44
+ *
45
+ * This source code is licensed under the ISC license.
46
+ * See the LICENSE file in the root directory of this source tree.
47
+ */const Oi=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],Xs=je("server",Oi);/**
48
+ * @license lucide-react v0.511.0 - ISC
49
+ *
50
+ * This source code is licensed under the ISC license.
51
+ * See the LICENSE file in the root directory of this source tree.
52
+ */const $i=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],Ui=je("shield",$i);/**
53
+ * @license lucide-react v0.511.0 - ISC
54
+ *
55
+ * This source code is licensed under the ISC license.
56
+ * See the LICENSE file in the root directory of this source tree.
57
+ */const Fi=[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]],Bi=je("timer",Fi);/**
58
+ * @license lucide-react v0.511.0 - ISC
59
+ *
60
+ * This source code is licensed under the ISC license.
61
+ * See the LICENSE file in the root directory of this source tree.
62
+ */const zi=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],Hi=je("wifi",zi);function Js(s,t){const n=Bt(t()),i=()=>n.set(t());return i(),or(()=>{const a=()=>cr.preRender(i,!1,!0),l=s.map(d=>d.on("change",a));return()=>{l.forEach(d=>d()),lr(i)}}),n}function Vi(s){Tt.current=[],s();const t=Js(Tt.current,s);return Tt.current=void 0,t}function qi(s,t,n,i){if(typeof s=="function")return Vi(s);const l=dr(t,n,i),d=Array.isArray(s)?ps(s,l):ps([s],([c])=>l(c)),o=Array.isArray(s)?void 0:s.accelerate;return o&&!o.isTransformed&&typeof t!="function"&&Array.isArray(n)&&i?.clamp!==!1&&(d.accelerate={...o,times:t,keyframes:n,isTransformed:!0}),d}function ps(s,t){const n=ur(()=>[]);return Js(s,()=>{n.length=0;const i=s.length;for(let a=0;a<i;a++)n[a]=s[a].get();return t(n)})}function Gi(s,t={}){const{isStatic:n}=r.useContext(mr),i=()=>hr(s)?s.get():s;if(n)return qi(i);const a=Bt(i());return r.useInsertionEffect(()=>fr(a,s,t),[a,JSON.stringify(t)]),a}function Wi(s,t={}){return Gi(s,{type:"spring",...t})}function Ki({to:s,from:t=0,direction:n="up",delay:i=0,duration:a=2,className:l="",startWhen:d=!0,separator:o="",onStart:c,onEnd:h}){const g=r.useRef(null),x=Bt(n==="down"?s:t),j=20+40*(1/a),C=100*(1/a),k=Wi(x,{damping:j,stiffness:C}),v=xr(g,{once:!0,margin:"0px"}),f=p=>{const y=p.toString();if(y.includes(".")){const _=y.split(".")[1];if(parseInt(_)!==0)return _.length}return 0},b=Math.max(f(t),f(s)),N=r.useCallback(p=>{const y=b>0,_={useGrouping:!!o,minimumFractionDigits:y?b:0,maximumFractionDigits:y?b:0},F=Intl.NumberFormat("en-US",_).format(p);return o?F.replace(/,/g,o):F},[b,o]);return r.useEffect(()=>{g.current&&(g.current.textContent=N(n==="down"?s:t))},[t,s,n,N]),r.useEffect(()=>{if(v&&d){typeof c=="function"&&c();const p=setTimeout(()=>{x.set(n==="down"?t:s)},i*1e3),y=setTimeout(()=>{typeof h=="function"&&h()},i*1e3+a*1e3);return()=>{clearTimeout(p),clearTimeout(y)}}},[v,d,x,n,t,s,i,c,h,a]),r.useEffect(()=>{const p=k.on("change",y=>{g.current&&(g.current.textContent=N(y))});return()=>p()},[k,N]),e.jsx("span",{className:l,ref:g})}function lt({children:s}){return e.jsx(e.Fragment,{children:s})}const ct=(s,t)=>t<=0?1:Math.min(Math.max(s,1),t);function Yi({initialStep:s=1,onStepChange:t,onFinalStepCompleted:n,backButtonText:i="Previous",nextButtonText:a="Next",nextDisabled:l,backDisabled:d,contentAnimation:o=!1,className:c,children:h}){const g=r.useMemo(()=>r.Children.toArray(h).filter(K=>r.isValidElement(K)),[h]),x=g.length,[j,C]=r.useState(()=>ct(s,x)),k=r.useRef(j);r.useEffect(()=>{C(ct(s,x))},[s,x]),r.useEffect(()=>{t?.(j)},[j,t]),r.useEffect(()=>{k.current=j},[j]);const v=(K,R,q)=>typeof K=="function"?K(R,q):!!K,f=j>=x,b=v(l,j,x),N=v(d,j,x),p=j>1&&!N,y=typeof a=="function"?a(j,x):a,_=()=>{if(f){b||n?.();return}b||C(K=>ct(K+1,x))},F=()=>{p&&C(K=>ct(K-1,x))};if(x===0)return null;const P=g[j-1],V=P?.props?.title??`Step ${j}`,G=P?.props?.description,z=j>=k.current?"forward":"back";return e.jsxs("div",{className:ne("stepper-root flex flex-col gap-5",c),children:[e.jsxs("div",{className:"stepper-header flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-3",children:g.map((K,R)=>{const q=R+1,U=q<j,$=q===j,O=K.props.title??`Step ${q}`;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:ne("stepper-dot flex h-8 w-8 items-center justify-center rounded-full border text-xs font-semibold transition",U&&"border-transparent bg-[var(--cli-accent-olive)] text-[var(--cli-ink-0)]",$&&"border-[var(--cli-accent-olive)] bg-white/90 text-[var(--cli-ink-1)]",!U&&!$&&"border-white/60 bg-white/60 text-[var(--cli-muted-1)]"),"data-state":U?"complete":$?"active":"upcoming",children:U?e.jsx(zt,{className:"h-4 w-4"}):q}),e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("span",{className:"text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:["Step ",q]}),e.jsx("span",{className:ne("text-xs font-semibold",$?"text-[var(--cli-ink-1)]":"text-[var(--cli-muted-1)]"),children:O})]}),R<x-1?e.jsx("div",{className:"h-px w-8 bg-white/60","aria-hidden":"true"}):null]},`${O}-${q}`)})}),e.jsxs("div",{className:"rounded-full border border-white/50 bg-white/80 px-3 py-1 text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:[j," / ",x]})]}),e.jsxs("div",{className:"stepper-content rounded-xl border border-white/40 bg-white/80 p-4","data-step":j,"data-direction":z,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:V}),G?e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:G}):null]}),e.jsxs("span",{className:"rounded-full border border-white/60 bg-white/70 px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:["Step ",j]})]}),e.jsx("div",{className:"mt-4",children:P})]},o?`step-${j}`:"step-static"),e.jsxs("div",{className:"stepper-actions flex flex-wrap items-center justify-between gap-3",children:[e.jsx(X,{variant:"secondary",onClick:F,disabled:!p,children:i}),e.jsx(X,{onClick:_,disabled:b,children:y})]})]})}function Xi(s){if(s==null||Number.isNaN(s))return"n/a";if(s<1024)return`${s} B`;const t=s/1024;if(t<1024)return`${t.toFixed(1)} KB`;const n=t/1024;return n<1024?`${n.toFixed(1)} MB`:`${(n/1024).toFixed(1)} GB`}function ye(s){if(!s)return"/";const t=s.replace(/\\/g,"/");let n=t.startsWith("/")?t:`/${t}`;return n=n.replace(/\/{2,}/g,"/"),n.length>1&&n.endsWith("/")&&(n=n.replace(/\/+$/,"")),n}function Ji(s){const t=ye(s);return t==="/"?[]:t.split("/").filter(Boolean)}function Zi(s){return s.length===0?"/":`/${s.join("/")}`}const Qi=1024*1024,ea=50*1024*1024,ta=["/.env","/.env.","/.ssh/","/credentials.json","/secrets.yaml","/secrets.yml","/id_rsa","/id_ed25519","/.aws/credentials","/.docker/config.json","/etc/passwd","/etc/shadow","/etc/gshadow","/proc/","/sys/kernel/","/dev/mem","/dev/kmem"];function At(s){const t=ye(s).toLowerCase();for(const n of ta)if(t.includes(n))return n;return null}const gs={online:"bg-[var(--cli-status-online)]",offline:"bg-[var(--cli-status-offline)]",standalone:"bg-[var(--cli-status-idle)]",error:"bg-[var(--cli-status-error)]",idle:"bg-[var(--cli-status-idle)]",busy:"bg-[var(--cli-status-busy)]"};function sa(s){if(!s)return"n/a";const t=new Date(s);return Number.isNaN(t.getTime())?"n/a":t.toLocaleString()}function na(s){if(!s)return"n/a";const t=new Date(s);if(Number.isNaN(t.getTime()))return"n/a";const n=Date.now()-t.getTime();return n<6e4?"just now":n<36e5?`${Math.round(n/6e4)}m ago`:n<864e5?`${Math.round(n/36e5)}h ago`:`${Math.round(n/864e5)}d ago`}function ra({server:s,isActive:t,onSelect:n}){const i=gs[s.status]||gs.offline;return e.jsxs("button",{"data-cli-server-card":!0,type:"button",onClick:n,"aria-pressed":t,className:ne("cli-console-row group w-full rounded-lg border border-white/30 bg-white/50 px-3 py-2 text-left transition","hover:border-white/60 hover:bg-white/70",t&&"ring-2 ring-[var(--cli-accent-olive)]"),children:[e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--cli-ink-1)]",children:[e.jsx("span",{className:ne("h-2 w-2 rounded-full",i)}),e.jsx(Xs,{className:"h-4 w-4 text-[var(--cli-muted-1)]"}),e.jsx("span",{className:"truncate max-w-[170px]",children:s.name||s.hostname})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-[11px] text-[var(--cli-muted-1)]",children:[e.jsx("span",{className:"truncate max-w-[190px]",children:s.hostname}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-[var(--cli-muted-2)]"}),e.jsx("span",{children:s.ip_address||"n/a"}),e.jsx("span",{className:"h-1 w-1 rounded-full bg-[var(--cli-muted-2)]"}),e.jsxs("span",{children:["Last heartbeat ",na(s.last_seen_at)]})]})]})}),e.jsxs("div",{className:"mt-2 text-[10px] text-[var(--cli-muted-1)]",children:[s.status," · Last heartbeat ",sa(s.last_seen_at)]})]})}function ia({readOnly:s,onBind:t,collapsed:n,onToggleCollapse:i,tabs:a=[],activeTab:l,onTabChange:d}){const{t:o}=Ie("cli"),c=ce(y=>y.servers),h=ce(y=>y.activeServerId),g=ce(y=>y.setActiveServer),x=ce(y=>y.refreshServers),j=r.useRef(null),[C,k]=r.useState(""),v=r.useMemo(()=>({total:c.length,online:c.filter(_=>_.status==="online").length,busy:c.filter(_=>_.status==="busy").length,offline:c.filter(_=>_.status==="offline").length}),[c]),f=r.useMemo(()=>{const y=C.trim().toLowerCase();return y?c.filter(_=>[_.name,_.hostname,_.ip_address].filter(Boolean).join(" ").toLowerCase().includes(y)):c},[C,c]),b=n?c:f,N=r.useMemo(()=>({online:"bg-[var(--cli-status-online)]",offline:"bg-[var(--cli-status-offline)]",error:"bg-[var(--cli-status-error)]",busy:"bg-[var(--cli-status-busy)]",idle:"bg-[var(--cli-status-idle)]",standalone:"bg-[var(--cli-status-idle)]"}),[]),p=y=>{if(a.length===0)return null;const _=y==="collapsed",F={overview:Ii,methods:gr,terminal:$s,files:Os,logs:vt,tasks:Ni,findings:Dt,admin:Ui};return e.jsx("div",{className:_?"mt-2 grid gap-2 px-2":"mt-3 grid grid-cols-4 gap-2",children:a.map(P=>{const V=P.value===l,G=F[P.value]??vt,z=P.label;return e.jsxs("button",{type:"button",onClick:()=>d?.(P.value),"aria-pressed":V,title:P.label,className:`cli-focus-ring group relative flex items-center justify-center rounded-lg border px-2 py-1 text-[10px] font-semibold transition ${V?"border-[var(--cli-accent-amber)] bg-white/90 text-[var(--cli-ink-1)]":"border-white/60 bg-white/70 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]"}`,children:[_?e.jsx(G,{className:"h-4 w-4"}):z,_?e.jsx("span",{className:"pointer-events-none absolute left-full top-1/2 ml-3 -translate-y-1/2 whitespace-nowrap rounded-lg border border-white/70 bg-white/90 px-2 py-1 text-[10px] text-[var(--cli-ink-1)] opacity-0 shadow-sm transition group-hover:opacity-100",children:z}):null]},P.value)})})};return r.useEffect(()=>{if(!j.current||b.length===0||typeof window>"u"||window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;let _=!1;const P=j.current.querySelectorAll("[data-cli-server-card]");if(P.length!==0)return Ht(async()=>{const{default:V}=await import("./index-BsO46tJA.js").then(G=>G.i);return{default:V}},__vite__mapDeps([0,1,2,3,4,5])).then(({default:V})=>{_||V({targets:P,opacity:[0,1],translateY:[10,0],delay:V.stagger(60),duration:520,easing:"easeOutCubic"})}).catch(()=>{}),()=>{_=!0}},[b]),n?e.jsxs("div",{className:"flex h-full flex-col items-center py-3",children:[e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/60 bg-white/70 p-2 text-[var(--cli-muted-1)] transition hover:text-[var(--cli-ink-1)]",onClick:()=>i?.(),title:o("expand"),"aria-label":o("expand_cli_console"),children:e.jsx(Ls,{className:"h-4 w-4"})}),e.jsxs("div",{className:"mt-3 flex flex-col items-center gap-2",children:[e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/60 bg-white/70 p-2 text-[var(--cli-muted-1)] transition hover:text-[var(--cli-ink-1)]",onClick:()=>x(),title:o("refresh"),"aria-label":o("refresh_server_list"),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/60 bg-white/70 p-2 text-[var(--cli-muted-1)] transition hover:text-[var(--cli-ink-1)] disabled:opacity-50",onClick:()=>t?.(),title:o("bind_server"),"aria-label":o("bind_server"),disabled:s||!t,children:e.jsx(gt,{className:"h-3.5 w-3.5"})})]}),e.jsx(Ze,{className:"mt-3 flex-1 w-full px-2",children:e.jsxs("div",{ref:j,className:"flex flex-col items-center gap-2 pb-4",children:[b.map(y=>{const _=(y.name||y.hostname||"S").slice(0,2).toUpperCase();return e.jsxs("button",{type:"button","data-cli-server-card":!0,onClick:()=>g(y.id),"aria-pressed":y.id===h,title:y.name||y.hostname,className:`cli-focus-ring flex h-10 w-10 flex-col items-center justify-center gap-1 rounded-xl border border-white/50 text-[10px] font-semibold transition ${y.id===h?"bg-[var(--cli-accent-olive)] text-[var(--cli-ink-0)]":"bg-white/60 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]"}`,children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${N[y.status]||"bg-[var(--cli-status-idle)]"}`}),e.jsx("span",{children:_})]},y.id)}),b.length===0?e.jsx("div",{className:"text-center text-[10px] text-[var(--cli-muted-1)]",children:o("no_servers")}):null]})}),a.length>0?e.jsxs("div",{className:"w-full pb-2",children:[e.jsx("div",{className:"text-center text-[10px] text-[var(--cli-muted-1)]",children:"---"}),p("collapsed")]}):null]}):e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsxs("div",{className:"px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:o("cli_console")}),e.jsx("p",{className:"text-xs text-[var(--cli-muted-1)]",children:o("remote_hosts_live_agents")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/60 bg-white/70 p-2 text-[var(--cli-muted-1)] transition hover:text-[var(--cli-ink-1)]",onClick:()=>i?.(),title:o("collapse"),"aria-label":o("collapse_cli_console"),children:e.jsx(Ds,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/60 bg-white/70 p-2 text-[var(--cli-muted-1)] transition hover:text-[var(--cli-ink-1)]",onClick:()=>x(),title:o("refresh"),"aria-label":o("refresh_server_list"),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),e.jsx(pr,{className:"rounded-full",children:e.jsxs(X,{size:"sm",className:"rounded-full",onClick:()=>t?.(),disabled:s||!t,children:[e.jsx(gt,{className:"mr-1 h-4 w-4"}),o("bind")]})})]})]}),e.jsx("div",{className:"mt-3",children:e.jsx(Ps,{value:C,onChange:y=>k(y.target.value),placeholder:o("search_cli_servers_placeholder"),className:"h-9 text-xs","aria-label":o("search_cli_servers")})}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-[10px] text-[var(--cli-muted-1)]",children:[e.jsx("span",{className:"rounded-full border border-white/40 bg-white/70 px-2 py-0.5",children:o("total",{count:v.total})}),e.jsx("span",{className:"rounded-full border border-white/40 bg-white/70 px-2 py-0.5",children:o("online",{count:v.online})}),v.busy>0?e.jsx("span",{className:"rounded-full border border-white/40 bg-white/70 px-2 py-0.5",children:o("busy_count",{count:v.busy})}):null,e.jsx("span",{className:"rounded-full border border-white/40 bg-white/70 px-2 py-0.5",children:o("offline_count",{count:v.offline})})]})]}),e.jsx(Ze,{className:"flex-1 px-4",children:e.jsxs("div",{ref:j,className:"space-y-3 pb-6",children:[b.map(y=>e.jsx(ra,{server:y,isActive:y.id===h,onSelect:()=>g(y.id)},y.id)),b.length===0?e.jsx("div",{className:"rounded-xl border border-dashed border-white/50 bg-white/40 p-4 text-center text-xs text-[var(--cli-muted-1)]",children:C.trim()?o("no_servers_match_search"):o(s?"no_servers_available_project":"no_servers_yet_bind")}):null]})}),a.length>0?e.jsxs("div",{className:"px-4 pb-4",children:[e.jsx("div",{className:"text-center text-[10px] text-[var(--cli-muted-1)]",children:"---"}),p("expanded")]}):null]})}const dt=new Map,vs="ds_cli_client_id";let Mt=null;function aa(){const s={connected:!1,connect:()=>s,disconnect:()=>s,on:()=>s,off:()=>s,emit:()=>!0};return s}function Wt(){if(Mt)return Mt;let s="";if(typeof window<"u")try{s=window.localStorage.getItem(vs)||""}catch{s=""}if(!s){try{s=crypto.randomUUID()}catch{s=`cli-${Date.now()}-${Math.random().toString(16).slice(2,10)}`}if(typeof window<"u")try{window.localStorage.setItem(vs,s)}catch{}}return Mt=s,s}function Zs(s={}){if(!vr())return{socket:aa(),release:()=>{}};const t=br(),n=`${t}::user`;let i=dt.get(n);return i||(i={socket:wr(`${t}/cli`,{path:"/ws/socket.io",autoConnect:!1,transports:["websocket","polling"],auth:l=>{const d=Wt(),o="cli.v1",c=yr.getState().accessToken||(typeof window<"u"?window.localStorage.getItem("ds_access_token"):null);l({token:c||null,client_id:d,protocol_version:o})}}),refCount:0},dt.set(n,i)),i.refCount+=1,i.socket.connected||i.socket.connect(),{socket:i.socket,release:()=>{const a=dt.get(n);a&&(a.refCount-=1,a.refCount<=0&&(a.socket.disconnect(),dt.delete(n)))}}}function Ae(s){return s&&typeof s=="object"&&"payload"in s?s.payload:s}let bs=0;function bt(){return bs+=1,bs}function wt(s,t={}){return{protocol_version:"cli.v1",ts:new Date().toISOString(),payload:s,...t}}const ws={[ee.DISCONNECTED]:{CONNECT:ee.CONNECTING},[ee.CONNECTING]:{AUTH_SUCCESS:ee.AUTHENTICATING,DISCONNECT:ee.DISCONNECTED,CONNECTION_LOST:ee.RECONNECTING},[ee.AUTHENTICATING]:{AUTH_SUCCESS:ee.CONNECTED,AUTH_FAILURE:ee.FAILED,CONNECTION_LOST:ee.RECONNECTING},[ee.CONNECTED]:{DISCONNECT:ee.DISCONNECTED,CONNECTION_LOST:ee.RECONNECTING,SUSPEND:ee.SUSPENDED},[ee.RECONNECTING]:{RECONNECT_SUCCESS:ee.CONNECTED,MAX_RETRIES_EXCEEDED:ee.FAILED,DISCONNECT:ee.DISCONNECTED},[ee.SUSPENDED]:{RESUME:ee.CONNECTING,DISCONNECT:ee.DISCONNECTED},[ee.FAILED]:{CONNECT:ee.CONNECTING,DISCONNECT:ee.DISCONNECTED}};class oa{state=ee.DISCONNECTED;listeners=new Set;getState(){return this.state}sendEvent(t){const n=ws[this.state]?.[t.type];if(!n)return console.warn(`Invalid connection transition: ${this.state} -> ${t.type}`),!1;const i=this.state;return this.state=n,this.notifyListeners(n,t),i!==n&&console.debug(`[CLI] Connection state: ${i} -> ${n} (${t.type})`),!0}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}canSendEvent(t){return!!ws[this.state]?.[t]}reset(){this.state=ee.DISCONNECTED}notifyListeners(t,n){this.listeners.forEach(i=>i(t,n))}}class la{metrics={totalConnections:0,successfulConnections:0,failedConnections:0,reconnectionAttempts:0,averageReconnectTime:0,messagesBuffered:0,messagesDropped:0};recordConnection(){this.metrics.totalConnections+=1}recordConnectionSuccess(){this.metrics.successfulConnections+=1}recordConnectionFailure(){this.metrics.failedConnections+=1}recordReconnectionAttempt(t){this.metrics.reconnectionAttempts+=1;const n=this.metrics.reconnectionAttempts;this.metrics.averageReconnectTime=(this.metrics.averageReconnectTime*(n-1)+t)/n}recordMessageBuffered(t=1){this.metrics.messagesBuffered+=t}recordMessageDropped(t=1){this.metrics.messagesDropped+=t}getMetrics(){return{...this.metrics}}}class ca{buffer=[];maxSize;onOverflow;constructor(t={}){this.maxSize=t.maxSize??1e3,this.onOverflow=t.onOverflow??"drop_oldest"}enqueue(t){if(this.pruneExpired(),this.buffer.length>=this.maxSize)switch(this.onOverflow){case"drop_oldest":{this.buffer.sort((i,a)=>{const l={high:0,normal:1,low:2};return l[a.priority]-l[i.priority]||i.timestamp-a.timestamp}),this.buffer.pop();break}case"drop_newest":return!1;case"reject":throw new Error("Message buffer overflow")}const n={...t,id:crypto.randomUUID(),timestamp:Date.now()};return this.buffer.push(n),!0}flush(){this.pruneExpired();const t=[...this.buffer].sort((n,i)=>{const a={high:0,normal:1,low:2},l=a[n.priority]-a[i.priority];return l!==0?l:n.timestamp-i.timestamp});return this.buffer=[],t}getStatus(){return{size:this.buffer.length,maxSize:this.maxSize,oldestTimestamp:this.buffer.length>0?Math.min(...this.buffer.map(t=>t.timestamp)):null}}clear(){this.buffer=[]}countByPriority(t){return this.buffer.filter(n=>n.priority===t).length}pruneExpired(){const t=Date.now();this.buffer=this.buffer.filter(n=>n.maxAge?t-n.timestamp<n.maxAge:!0)}}const da={initialDelay:1e3,maxDelay:3e5,maxRetries:30,backoffMultiplier:1.5,jitterFactor:.2};class ua{config;retryCount=0;currentTimeout=null;listeners=new Set;constructor(t={}){this.config={...da,...t}}calculateDelay(){const t=Math.min(this.config.initialDelay*Math.pow(this.config.backoffMultiplier,this.retryCount),this.config.maxDelay),n=t*this.config.jitterFactor*(Math.random()*2-1);return Math.max(0,Math.floor(t+n))}scheduleReconnect(t){if(this.retryCount>=this.config.maxRetries){this.notifyListeners({status:"failed",message:`Max retries reached (${this.config.maxRetries})`});return}const n=this.calculateDelay();this.retryCount+=1,this.notifyListeners({status:"waiting",retryCount:this.retryCount,maxRetries:this.config.maxRetries,nextRetryIn:n}),this.currentTimeout=setTimeout(async()=>{this.notifyListeners({status:"reconnecting",retryCount:this.retryCount});try{if(await t()){this.reset(),this.notifyListeners({status:"connected"});return}}catch(i){console.error("[CLI] Reconnect failed:",i)}this.scheduleReconnect(t)},n)}reset(){this.retryCount=0,this.currentTimeout&&(clearTimeout(this.currentTimeout),this.currentTimeout=null)}cancel(){this.reset(),this.notifyListeners({status:"cancelled"})}retryNow(t){this.cancel(),this.retryCount=0,this.scheduleReconnect(t)}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}getRetryCount(){return this.retryCount}notifyListeners(t){this.listeners.forEach(n=>n(t))}}const ma="CLI server offline. Please ensure the CLI is running.",fa=s=>{const t=s.toLowerCase();return t.includes("cli server")&&(t.includes("not connected")||t.includes("offline"))||t.includes("cli_server_not_connected")||t.includes("cli_server_offline")?ma:s};function Qs(s){const{projectId:t,serverId:n,handlers:i}=s,a=r.useRef(Wt()),l=r.useRef(new ua),d=r.useRef(!1),o=r.useRef(new ca),c=r.useRef(new oa),h=r.useRef(new la),g=r.useRef(null),x=r.useRef(!1),j=r.useRef(null),C=r.useRef(()=>{}),[k,v]=r.useState(()=>({state:c.current.getState(),bufferedMessages:0,metrics:h.current.getMetrics()})),{socket:f,release:b}=r.useMemo(()=>Zs(),[]),N=r.useCallback(()=>{v(R=>({...R,metrics:h.current.getMetrics()}))},[]),p=r.useCallback(()=>{const R=o.current.getStatus();v(q=>({...q,bufferedMessages:R.size,metrics:h.current.getMetrics()}))},[]),y=r.useCallback((R,q,U={},$)=>{if(!t||!n)return;const O=wt(q,{project_id:t,server_id:n,client_id:a.current,...U});if(!f.connected){try{o.current.enqueue({type:R,payload:O,priority:$?.priority??"normal",maxAge:$?.maxAge})?h.current.recordMessageBuffered():(h.current.recordMessageDropped(),N(),i?.onError?.("Message buffer full; dropping newest message"))}catch(J){h.current.recordMessageDropped(),N(),i?.onError?.(J instanceof Error?J.message:"Message buffer error")}p();return}f.emit(R,O)},[t,n,f,i,p,N]),_=r.useCallback(()=>{if(!f.connected)return;o.current.flush().forEach(q=>f.emit(q.type,q.payload)),p()},[f,p]),F=r.useCallback(async()=>{if(!t||!n)return!1;if(j.current)return j.current;const R=Date.now(),q=wt({},{project_id:t,server_id:n,client_id:a.current});h.current.recordConnection(),N();const U=new Promise($=>{f.timeout(3e3).emit("cli:subscribe",q,O=>{if(j.current=null,O){x.current=!1,h.current.recordConnectionFailure(),N();const Q=c.current.getState();Q===ee.AUTHENTICATING&&c.current.canSendEvent("AUTH_FAILURE")&&c.current.sendEvent({type:"AUTH_FAILURE",error:O.message}),Q===ee.RECONNECTING&&C.current(),v(re=>({...re,lastError:O.message})),$(!1);return}const J=Date.now()-R,Y=c.current.getState();Y===ee.RECONNECTING?c.current.sendEvent({type:"RECONNECT_SUCCESS"}):Y===ee.AUTHENTICATING&&c.current.sendEvent({type:"AUTH_SUCCESS"}),x.current=!0,h.current.recordConnectionSuccess(),N(),l.current.reset(),d.current=!1,v(Q=>({...Q,latencyMs:J,lastConnectedAt:Date.now()})),$(!0)})});return j.current=U,U},[t,n,f,N]),P=r.useCallback(async()=>{if(f.connected&&x.current)return!0;if(!f.connected&&!await new Promise(U=>{let $=!1;const O=window.setTimeout(()=>{$||($=!0,Q(),U(!1))},4e3),J=()=>{$||($=!0,Q(),U(!0))},Y=()=>{$||($=!0,Q(),U(!1))},Q=()=>{window.clearTimeout(O),f.off("connect",J),f.off("connect_error",Y)};f.once("connect",J),f.once("connect_error",Y),f.connect()}))return!1;const R=await F();return R&&_(),R},[f,F,_]),V=r.useCallback(()=>{d.current||(d.current=!0,l.current.scheduleReconnect(P))},[P]);C.current=V,r.useEffect(()=>{const R=c.current,q=R.subscribe(($,O)=>{v(J=>({...J,state:$,lastError:O.type==="AUTH_FAILURE"?O.error:J.lastError}))}),U=l.current.subscribe($=>{if($.status==="waiting"){g.current=null,v(O=>({...O,reconnectAttempts:$.retryCount,nextRetryIn:$.nextRetryIn}));return}if($.status==="reconnecting"){g.current||(g.current=Date.now()),v(O=>({...O,reconnectAttempts:$.retryCount,nextRetryIn:void 0}));return}if($.status==="failed"){d.current=!1,h.current.recordConnectionFailure(),N(),R.canSendEvent("MAX_RETRIES_EXCEEDED")&&R.sendEvent({type:"MAX_RETRIES_EXCEEDED"}),v(O=>({...O,lastError:$.message}));return}if($.status==="connected"){d.current=!1,g.current&&(h.current.recordReconnectionAttempt(Date.now()-g.current),N(),g.current=null),v(O=>({...O,reconnectAttempts:0,nextRetryIn:void 0}));return}$.status==="cancelled"&&(d.current=!1,g.current=null,v(O=>({...O,reconnectAttempts:0,nextRetryIn:void 0})))});return()=>{q(),U()}},[N]),r.useEffect(()=>{if(!t||!n)return;const R=c.current;R.canSendEvent("CONNECT")&&R.sendEvent({type:"CONNECT"});const q=async()=>{const E=R.getState();E===ee.CONNECTING&&R.canSendEvent("AUTH_SUCCESS")&&R.sendEvent({type:"AUTH_SUCCESS"}),E!==ee.RECONNECTING&&await F()&&_()},U=E=>{x.current=!1,R.canSendEvent("CONNECTION_LOST")&&R.sendEvent({type:"CONNECTION_LOST"}),E&&v(Z=>({...Z,lastError:`Disconnected: ${E}`})),V()},$=E=>{x.current=!1;const Z=E instanceof Error?E.message:"Connection error";v(ie=>({...ie,lastError:Z})),i?.onError?.(Z),h.current.recordConnectionFailure(),N(),R.canSendEvent("CONNECTION_LOST")&&R.sendEvent({type:"CONNECTION_LOST"}),V()},O=E=>{i?.onTerminalOutput?.(E)},J=E=>{i?.onStatusUpdate?.(E)},Y=E=>{i?.onFileResponse?.(E)},Q=E=>{i?.onConfirmRequired?.(E)},re=E=>{i?.onBlocked?.(E)},oe=E=>{i?.onSessionCreated?.(E)},ue=E=>{i?.onSessionAttached?.(E)},le=E=>{i?.onSessionDetached?.(E)},T=E=>{i?.onSessionClosed?.(E)},B=E=>{i?.onSessionError?.(E)},S=E=>{i?.onMethodStatus?.(E)},u=E=>{i?.onMethodDone?.(E)},w=E=>{i?.onMethodError?.(E)},A=E=>{i?.onMethodListResponse?.(E)},M=E=>{i?.onMethodGetResponse?.(E)},W=E=>{const Z=typeof E?.message=="string"&&E.message?E.message:"CLI server error",ie=typeof E?.event=="string"&&E.event?` (${E.event})`:"",fe=fa(Z);i?.onError?.(`${fe}${ie}`)};return f.on("connect",q),f.on("disconnect",U),f.on("connect_error",$),f.on("cli:terminal:output",O),f.on("cli:status:update",J),f.on("cli:file:list:response",Y),f.on("cli:file:content:response",Y),f.on("cli:file:download:response",Y),f.on("cli:file:write:response",Y),f.on("cli:file:delete:response",Y),f.on("cli:terminal:confirm_required",Q),f.on("cli:terminal:blocked",re),f.on("cli:session:created",oe),f.on("cli:session:attached",ue),f.on("cli:session:detached",le),f.on("cli:session:closed",T),f.on("cli:session:error",B),f.on("cli:method:status",S),f.on("cli:method:done",u),f.on("cli:method:error",w),f.on("cli:method:list:response",A),f.on("cli:method:get:response",M),f.on("cli:error",W),f.connected||f.connect(),()=>{f.off("connect",q),f.off("disconnect",U),f.off("connect_error",$),f.off("cli:terminal:output",O),f.off("cli:status:update",J),f.off("cli:file:list:response",Y),f.off("cli:file:content:response",Y),f.off("cli:file:download:response",Y),f.off("cli:file:write:response",Y),f.off("cli:file:delete:response",Y),f.off("cli:terminal:confirm_required",Q),f.off("cli:terminal:blocked",re),f.off("cli:session:created",oe),f.off("cli:session:attached",ue),f.off("cli:session:detached",le),f.off("cli:session:closed",T),f.off("cli:session:error",B),f.off("cli:method:status",S),f.off("cli:method:done",u),f.off("cli:method:error",w),f.off("cli:method:list:response",A),f.off("cli:method:get:response",M),f.off("cli:error",W),l.current.cancel(),b()}},[t,n,f,b,F,_,i,V,N]);const G=r.useCallback(R=>{const q={data:R.data,confirmed:R.confirmed};R.mode&&(q.mode=R.mode),y("cli:terminal:input",q,{session_id:R.sessionId,seq:R.seq,operation_id:R.operationId},{priority:"high"})},[y]),z=r.useCallback(R=>{y("cli:terminal:resize",{cols:R.cols,rows:R.rows},{session_id:R.sessionId},{priority:"low",maxAge:2e3})},[y]),K=r.useCallback((R,q,U)=>{y(R,q,U)},[y]);return{socket:f,status:k,emitEnvelope:y,sendTerminalInput:G,sendTerminalResize:z,sendFileRequest:K,unwrapPayload:Ae}}class ha{state;maxScrollbackLines=1e4;maxSessionsPerServer=10;listeners=new Set;constructor(){this.state={sessions:new Map,activeSessionId:null}}createSession(t,n={}){const i=this.getSessionsByServer(t),a=n.id??crypto.randomUUID(),l=this.state.sessions.get(a);if(!l&&i.length>=this.maxSessionsPerServer)throw new Error(`Reached max sessions per server (${this.maxSessionsPerServer})`);const d=Date.now();if(l)return l.state="active",l.lastActiveAt=d,n.name&&(l.name=n.name),n.mode&&(l.mode=n.mode),n.cols&&(l.cols=n.cols),n.rows&&(l.rows=n.rows),n.cwd&&(l.cwd=n.cwd),n.cwdRel&&(l.cwdRel=n.cwdRel),n.condaEnv!==void 0&&(l.condaEnv=n.condaEnv),n.shell&&(l.shell=n.shell),this.state.activeSessionId=a,this.notifyListeners(),l;const o=i.length+1,c=pa(o),h={id:a,serverId:t,name:n.name??`${c} Session`,createdAt:d,state:"active",scrollback:[],lineBuffer:"",lastActiveAt:d,cols:n.cols??120,rows:n.rows??40,mode:n.mode??"terminal",cwd:n.cwd,cwdRel:n.cwdRel,condaEnv:n.condaEnv,shell:n.shell,env:n.env,serialized:n.serialized};return this.state.sessions.set(a,h),this.state.activeSessionId=a,this.notifyListeners(),h}restoreSession(t){const n=t.createdAt||Date.now(),i=t.lastActiveAt||n;this.state.sessions.set(t.id,{...t,createdAt:n,lastActiveAt:i,lineBuffer:"",mode:t.mode??"terminal"}),this.state.activeSessionId||(this.state.activeSessionId=t.id),this.notifyListeners()}getSessionsByServer(t,n){return Array.from(this.state.sessions.values()).filter(i=>i.serverId===t&&(n?.includeClosed||i.state!=="closed"))}getActiveSession(){return this.state.activeSessionId?this.state.sessions.get(this.state.activeSessionId)??null:null}getSession(t){return this.state.sessions.get(t)??null}switchSession(t,n){const i=this.state.sessions.get(t);return i&&(n?.allowClosed||i.state!=="closed")?(this.state.activeSessionId=t,i.state!=="closed"&&(i.lastActiveAt=Date.now()),this.notifyListeners(),i):null}detachSession(t){const n=this.state.sessions.get(t);return!n||n.state!=="active"?!1:(n.state="detached",this.notifyListeners(),!0)}attachSession(t){const n=this.state.sessions.get(t);return!n||n.state!=="detached"?null:(n.state="active",n.lastActiveAt=Date.now(),this.state.activeSessionId=t,this.notifyListeners(),n)}closeSession(t){const n=this.state.sessions.get(t);if(!n)return!1;if(n.state="closed",this.state.activeSessionId===t){const i=Array.from(this.state.sessions.values()).find(a=>a.state!=="closed");this.state.activeSessionId=i?i.id:null}return this.notifyListeners(),!0}removeSession(t){if(!this.state.sessions.get(t))return!1;if(this.state.sessions.delete(t),this.state.activeSessionId===t){const i=Array.from(this.state.sessions.values()),a=i.find(l=>l.state!=="closed")??i[0];this.state.activeSessionId=a?a.id:null}return this.notifyListeners(),!0}renameSession(t,n){const i=this.state.sessions.get(t);return i?(i.name=n,this.notifyListeners(),!0):!1}updateScrollback(t,n){const i=this.state.sessions.get(t);if(!i||!n)return;const a=`${i.lineBuffer??""}${n}`.replace(/\r\n/g,`
63
+ `).replace(/\r/g,`
64
+ `),l=a.split(`
65
+ `);let d="";a.endsWith(`
66
+ `)?l.length&&l[l.length-1]===""&&l.pop():d=l.pop()??"",l.length&&(i.scrollback=i.scrollback.concat(l).slice(-this.maxScrollbackLines)),i.lineBuffer=d,i.lastActiveAt=Date.now(),this.notifyListeners()}setScrollback(t,n){const i=this.state.sessions.get(t);i&&(i.scrollback=n.slice(-this.maxScrollbackLines),i.lineBuffer="",i.lastActiveAt=Date.now(),this.notifyListeners())}setSerialized(t,n){const i=this.state.sessions.get(t);i&&(i.serialized=n,i.lastActiveAt=Date.now(),this.notifyListeners())}getState(){return this.state}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}notifyListeners(){this.listeners.forEach(t=>t(this.state))}}const xa="ABCDEFGHIJKLMNOPQRSTUVWXYZ";function pa(s){if(s<=0)return"A";let t=s,n="";for(;t>0;)t-=1,n=xa[t%26]+n,t=Math.floor(t/26);return n.length>2?"ZZ":n}function ga({open:s,command:t,level:n,description:i,matchedPattern:a,onConfirm:l,onCancel:d}){const{t:o}=Ie("cli"),[c,h]=r.useState("");r.useEffect(()=>{s||h("")},[s]);const g=c.trim().toUpperCase()==="RUN";return e.jsx(Qe,{open:s,onOpenChange:x=>x?null:d(),children:e.jsxs(et,{className:"cli-root max-w-lg",children:[e.jsxs(tt,{children:[e.jsx(st,{children:o("danger_confirm_title")}),e.jsx(Us,{children:i||o("danger_default_desc")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-[var(--cli-muted-1)]",children:[n?e.jsx("span",{className:"rounded-full border border-white/40 bg-white/70 px-2 py-0.5 text-[10px] text-[var(--cli-ink-1)]",children:o("danger_risk",{level:n.toUpperCase()})}):null,a?e.jsx("span",{className:"rounded-full border border-white/40 bg-white/70 px-2 py-0.5 text-[10px] text-[var(--cli-ink-1)]",children:o("danger_pattern",{pattern:a})}):null]}),e.jsx("div",{className:"rounded-xl border border-black/5 bg-black/90 p-3 font-mono text-xs text-white",children:t}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs text-[var(--cli-muted-1)]",children:o("danger_type_run")}),e.jsx("input",{value:c,onChange:x=>h(x.target.value),placeholder:"RUN",className:"w-full rounded-lg border border-white/40 bg-white/70 px-3 py-2 text-xs text-[var(--cli-ink-1)] outline-none"})]}),e.jsxs(Vt,{className:"gap-2",children:[e.jsx(X,{variant:"secondary",onClick:d,children:o("cancel")}),e.jsx(X,{onClick:l,disabled:!g,children:o("run_command")})]})]})})}function va(s){r.useEffect(()=>{const t=n=>{const i=n.key.toLowerCase();(n.ctrlKey||n.metaKey)&&i==="f"&&(n.preventDefault(),s.onSearch?.()),(n.ctrlKey||n.metaKey)&&i==="l"&&(n.preventDefault(),s.onClear?.()),n.ctrlKey&&n.shiftKey&&i==="t"&&(n.preventDefault(),s.onNewSession?.()),n.ctrlKey&&n.shiftKey&&i==="w"&&(n.preventDefault(),s.onCloseSession?.())};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[s])}const en="cli_terminal_sessions",ba=24;function ys(s){if(typeof window>"u"||typeof localStorage>"u")return;const t=s.filter(n=>n.state!=="closed").map(n=>({sessionId:n.id,serverId:n.serverId,name:n.name,lastActiveAt:n.lastActiveAt,scrollbackHash:tn(n.scrollback),cols:n.cols,rows:n.rows,mode:n.mode,cwd:n.cwd,cwdRel:n.cwdRel,shell:n.shell,condaEnv:n.condaEnv,serialized:n.serialized&&n.serialized.length<=2e5?n.serialized:void 0}));localStorage.setItem(en,JSON.stringify(t))}function Ns(){if(typeof window>"u"||typeof localStorage>"u")return[];try{const s=localStorage.getItem(en);if(!s)return[];const t=JSON.parse(s),n=Date.now(),i=ba*60*60*1e3;return t.filter(a=>n-a.lastActiveAt<i)}catch(s){return console.error("Failed to load persisted sessions:",s),[]}}async function Ss(s,t,n){const i=t.scrollbackHash??"",a=n?.timeoutMs??5e3;return new Promise(l=>{let d=!1;const o=g=>{d||(d=!0,s.off("cli:session:recover:response",c),clearTimeout(h),l(g))},c=g=>{const x=g?.session_id||g?.sessionId;if(!(x&&x!==t.sessionId)){if(g?.success){o({recovered:!0,scrollback:g.scrollback});return}o({recovered:!1})}},h=setTimeout(()=>{o({recovered:!1})},a);s.on("cli:session:recover:response",c),s.emit("cli:session:recover",wt({scrollback_hash:i},{session_id:t.sessionId,server_id:t.serverId,client_id:Wt()}))})}function tn(s){const t=s.slice(-100).join(`
67
+ `);try{return btoa(t).slice(0,32)}catch{return btoa(unescape(encodeURIComponent(t))).slice(0,32)}}const sn="cli_terminal_recordings",wa=12,ya=24;function nn(){if(typeof window>"u"||typeof localStorage>"u")return[];try{const s=localStorage.getItem(sn);if(!s)return[];const t=JSON.parse(s),n=ya*60*60*1e3,i=Date.now();return t.filter(a=>i-a.updatedAt<n)}catch{return[]}}function Na(s){if(!(typeof window>"u"||typeof localStorage>"u"))try{localStorage.setItem(sn,JSON.stringify(s))}catch{}}function Sa(s){return nn().find(i=>i.sessionId===s)||null}function ja(s,t,n,i){const a=nn().filter(o=>o.sessionId!==s),l={sessionId:s,serverId:t,title:n,entries:i,updatedAt:Date.now()};a.unshift(l),a.sort((o,c)=>c.updatedAt-o.updatedAt);const d=a.slice(0,wa);Na(d)}async function Ca(){return typeof window>"u"||!("Notification"in window)?"denied":Notification.permission==="granted"?"granted":Notification.requestPermission()}function rn(s,t){typeof window>"u"||!("Notification"in window)||Notification.permission==="granted"&&new Notification(s,{body:t})}const _a="6f07d9a4-0e31-4f69-9ad4-b6295b6e4d2e";function ka(s){const t=s.replace(/-/g,""),n=new Uint8Array(16);for(let i=0;i<16;i+=1)n[i]=Number.parseInt(t.slice(i*2,i*2+2),16);return n}function Ea(s){const t=Array.from(s).map(n=>n.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20,32)}`}function ut(s,t){let n=2166136261^t;for(let i=0;i<s.length;i+=1)n^=s.charCodeAt(i),n=Math.imul(n,16777619);return n>>>0}function Ta(s){const t=ut(s,1).toString(16).padStart(8,"0"),n=ut(s,2).toString(16).padStart(8,"0"),i=ut(s,3).toString(16).padStart(8,"0"),a=ut(s,4).toString(16).padStart(8,"0"),l=`${t}${n}${i}${a}`.slice(0,32);return`${l.slice(0,8)}-${l.slice(8,12)}-5${l.slice(13,16)}-a${l.slice(17,20)}-${l.slice(20,32)}`}async function an(s,t=_a){const n=ka(t),i=new TextEncoder().encode(s),a=new Uint8Array(n.length+i.length);if(a.set(n,0),a.set(i,n.length),typeof crypto<"u"&&crypto.subtle?.digest){const d=new Uint8Array(await crypto.subtle.digest("SHA-1",a)).slice(0,16);return d[6]=d[6]&15|80,d[8]=d[8]&63|128,Ea(d)}return Ta(`${t}:${s}`)}async function Ra(s,t){return an(`${s}:${t}:default`)}async function Ia(s,t,n){return an(`${s}:${t}:${n}`)}function js(s,[t,n]){return Math.min(n,Math.max(t,s))}function Aa(s,t=[]){let n=[];function i(l,d){const o=r.createContext(d),c=n.length;n=[...n,d];const h=x=>{const{scope:j,children:C,...k}=x,v=j?.[s]?.[c]||o,f=r.useMemo(()=>k,Object.values(k));return e.jsx(v.Provider,{value:f,children:C})};h.displayName=l+"Provider";function g(x,j){const C=j?.[s]?.[c]||o,k=r.useContext(C);if(k)return k;if(d!==void 0)return d;throw new Error(`\`${x}\` must be used within \`${l}\``)}return[h,g]}const a=()=>{const l=n.map(d=>r.createContext(d));return function(o){const c=o?.[s]||l;return r.useMemo(()=>({[`__scope${s}`]:{...o,[s]:c}}),[o,c])}};return a.scopeName=s,[i,Ma(a,...t)]}function Ma(...s){const t=s[0];if(s.length===1)return t;const n=()=>{const i=s.map(a=>({useScope:a(),scopeName:a.scopeName}));return function(l){const d=i.reduce((o,{useScope:c,scopeName:h})=>{const x=c(l)[`__scope${h}`];return{...o,...x}},{});return r.useMemo(()=>({[`__scope${t.scopeName}`]:d}),[d])}};return n.scopeName=t.scopeName,n}function on(s){const t=La(s),n=r.forwardRef((i,a)=>{const{children:l,...d}=i,o=r.Children.toArray(l),c=o.find(Pa);if(c){const h=c.props.children,g=o.map(x=>x===c?r.Children.count(h)>1?r.Children.only(null):r.isValidElement(h)?h.props.children:null:x);return e.jsx(t,{...d,ref:a,children:r.isValidElement(h)?r.cloneElement(h,void 0,g):null})}return e.jsx(t,{...d,ref:a,children:l})});return n.displayName=`${s}.Slot`,n}function La(s){const t=r.forwardRef((n,i)=>{const{children:a,...l}=n;if(r.isValidElement(a)){const d=$a(a),o=Oa(l,a.props);return a.type!==r.Fragment&&(o.ref=i?Fs(i,d):d),r.cloneElement(a,o)}return r.Children.count(a)>1?r.Children.only(null):null});return t.displayName=`${s}.SlotClone`,t}var Da=Symbol("radix.slottable");function Pa(s){return r.isValidElement(s)&&typeof s.type=="function"&&"__radixId"in s.type&&s.type.__radixId===Da}function Oa(s,t){const n={...t};for(const i in t){const a=s[i],l=t[i];/^on[A-Z]/.test(i)?a&&l?n[i]=(...o)=>{const c=l(...o);return a(...o),c}:a&&(n[i]=a):i==="style"?n[i]={...a,...l}:i==="className"&&(n[i]=[a,l].filter(Boolean).join(" "))}return{...s,...n}}function $a(s){let t=Object.getOwnPropertyDescriptor(s.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?s.ref:(t=Object.getOwnPropertyDescriptor(s,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?s.props.ref:s.props.ref||s.ref)}var Ua=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Se=Ua.reduce((s,t)=>{const n=on(`Primitive.${t}`),i=r.forwardRef((a,l)=>{const{asChild:d,...o}=a,c=d?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(c,{...o,ref:l})});return i.displayName=`Primitive.${t}`,{...s,[t]:i}},{});function Fa(s){const t=r.useRef({value:s,previous:s});return r.useMemo(()=>(t.current.value!==s&&(t.current.previous=t.current.value,t.current.value=s),t.current.previous),[s])}function Ba(s){const t=za(s),n=r.forwardRef((i,a)=>{const{children:l,...d}=i,o=r.Children.toArray(l),c=o.find(Va);if(c){const h=c.props.children,g=o.map(x=>x===c?r.Children.count(h)>1?r.Children.only(null):r.isValidElement(h)?h.props.children:null:x);return e.jsx(t,{...d,ref:a,children:r.isValidElement(h)?r.cloneElement(h,void 0,g):null})}return e.jsx(t,{...d,ref:a,children:l})});return n.displayName=`${s}.Slot`,n}function za(s){const t=r.forwardRef((n,i)=>{const{children:a,...l}=n;if(r.isValidElement(a)){const d=Ga(a),o=qa(l,a.props);return a.type!==r.Fragment&&(o.ref=i?Fs(i,d):d),r.cloneElement(a,o)}return r.Children.count(a)>1?r.Children.only(null):null});return t.displayName=`${s}.SlotClone`,t}var Ha=Symbol("radix.slottable");function Va(s){return r.isValidElement(s)&&typeof s.type=="function"&&"__radixId"in s.type&&s.type.__radixId===Ha}function qa(s,t){const n={...t};for(const i in t){const a=s[i],l=t[i];/^on[A-Z]/.test(i)?a&&l?n[i]=(...o)=>{const c=l(...o);return a(...o),c}:a&&(n[i]=a):i==="style"?n[i]={...a,...l}:i==="className"&&(n[i]=[a,l].filter(Boolean).join(" "))}return{...s,...n}}function Ga(s){let t=Object.getOwnPropertyDescriptor(s.props,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?s.ref:(t=Object.getOwnPropertyDescriptor(s,"ref")?.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?s.props.ref:s.props.ref||s.ref)}var Wa=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ka=Wa.reduce((s,t)=>{const n=Ba(`Primitive.${t}`),i=r.forwardRef((a,l)=>{const{asChild:d,...o}=a,c=d?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(c,{...o,ref:l})});return i.displayName=`Primitive.${t}`,{...s,[t]:i}},{}),ln=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),Ya="VisuallyHidden",Xa=r.forwardRef((s,t)=>e.jsx(Ka.span,{...s,ref:t,style:{...ln,...s.style}}));Xa.displayName=Ya;var Ja=[" ","Enter","ArrowUp","ArrowDown"],Za=[" ","Enter"],ze="Select",[Nt,St,Qa]=jr(ze),[Xe]=Aa(ze,[Qa,Bs]),jt=Bs(),[eo,Le]=Xe(ze),[to,so]=Xe(ze),cn=s=>{const{__scopeSelect:t,children:n,open:i,defaultOpen:a,onOpenChange:l,value:d,defaultValue:o,onValueChange:c,dir:h,name:g,autoComplete:x,disabled:j,required:C,form:k}=s,v=jt(t),[f,b]=r.useState(null),[N,p]=r.useState(null),[y,_]=r.useState(!1),F=Nr(h),[P,V]=ls({prop:i,defaultProp:a??!1,onChange:l,caller:ze}),[G,z]=ls({prop:d,defaultProp:o,onChange:c,caller:ze}),K=r.useRef(null),R=f?k||!!f.closest("form"):!0,[q,U]=r.useState(new Set),$=Array.from(q).map(O=>O.props.value).join(";");return e.jsx(Sr,{...v,children:e.jsxs(eo,{required:C,scope:t,trigger:f,onTriggerChange:b,valueNode:N,onValueNodeChange:p,valueNodeHasChildren:y,onValueNodeHasChildrenChange:_,contentId:qt(),value:G,onValueChange:z,open:P,onOpenChange:V,dir:F,triggerPointerDownPosRef:K,disabled:j,children:[e.jsx(Nt.Provider,{scope:t,children:e.jsx(to,{scope:s.__scopeSelect,onNativeOptionAdd:r.useCallback(O=>{U(J=>new Set(J).add(O))},[]),onNativeOptionRemove:r.useCallback(O=>{U(J=>{const Y=new Set(J);return Y.delete(O),Y})},[]),children:n})}),R?e.jsxs(Mn,{"aria-hidden":!0,required:C,tabIndex:-1,name:g,autoComplete:x,value:G,onChange:O=>z(O.target.value),disabled:j,form:k,children:[G===void 0?e.jsx("option",{value:""}):null,Array.from(q)]},$):null]})})};cn.displayName=ze;var dn="SelectTrigger",un=r.forwardRef((s,t)=>{const{__scopeSelect:n,disabled:i=!1,...a}=s,l=jt(n),d=Le(dn,n),o=d.disabled||i,c=Ee(t,d.onTriggerChange),h=St(n),g=r.useRef("touch"),[x,j,C]=Dn(v=>{const f=h().filter(p=>!p.disabled),b=f.find(p=>p.value===d.value),N=Pn(f,v,b);N!==void 0&&d.onValueChange(N.value)}),k=v=>{o||(d.onOpenChange(!0),C()),v&&(d.triggerPointerDownPosRef.current={x:Math.round(v.pageX),y:Math.round(v.pageY)})};return e.jsx(Cr,{asChild:!0,...l,children:e.jsx(Se.button,{type:"button",role:"combobox","aria-controls":d.contentId,"aria-expanded":d.open,"aria-required":d.required,"aria-autocomplete":"none",dir:d.dir,"data-state":d.open?"open":"closed",disabled:o,"data-disabled":o?"":void 0,"data-placeholder":Ln(d.value)?"":void 0,...a,ref:c,onClick:pe(a.onClick,v=>{v.currentTarget.focus(),g.current!=="mouse"&&k(v)}),onPointerDown:pe(a.onPointerDown,v=>{g.current=v.pointerType;const f=v.target;f.hasPointerCapture(v.pointerId)&&f.releasePointerCapture(v.pointerId),v.button===0&&v.ctrlKey===!1&&v.pointerType==="mouse"&&(k(v),v.preventDefault())}),onKeyDown:pe(a.onKeyDown,v=>{const f=x.current!=="";!(v.ctrlKey||v.altKey||v.metaKey)&&v.key.length===1&&j(v.key),!(f&&v.key===" ")&&Ja.includes(v.key)&&(k(),v.preventDefault())})})})});un.displayName=dn;var mn="SelectValue",fn=r.forwardRef((s,t)=>{const{__scopeSelect:n,className:i,style:a,children:l,placeholder:d="",...o}=s,c=Le(mn,n),{onValueNodeHasChildrenChange:h}=c,g=l!==void 0,x=Ee(t,c.onValueNodeChange);return Me(()=>{h(g)},[h,g]),e.jsx(Se.span,{...o,ref:x,style:{pointerEvents:"none"},children:Ln(c.value)?e.jsx(e.Fragment,{children:d}):l})});fn.displayName=mn;var no="SelectIcon",hn=r.forwardRef((s,t)=>{const{__scopeSelect:n,children:i,...a}=s;return e.jsx(Se.span,{"aria-hidden":!0,...a,ref:t,children:i||"▼"})});hn.displayName=no;var ro="SelectPortal",xn=s=>e.jsx(_r,{asChild:!0,...s});xn.displayName=ro;var He="SelectContent",pn=r.forwardRef((s,t)=>{const n=Le(He,s.__scopeSelect),[i,a]=r.useState();if(Me(()=>{a(new DocumentFragment)},[]),!n.open){const l=i;return l?Ys.createPortal(e.jsx(gn,{scope:s.__scopeSelect,children:e.jsx(Nt.Slot,{scope:s.__scopeSelect,children:e.jsx("div",{children:s.children})})}),l):null}return e.jsx(vn,{...s,ref:t})});pn.displayName=He;var Ce=10,[gn,De]=Xe(He),io="SelectContentImpl",ao=on("SelectContent.RemoveScroll"),vn=r.forwardRef((s,t)=>{const{__scopeSelect:n,position:i="item-aligned",onCloseAutoFocus:a,onEscapeKeyDown:l,onPointerDownOutside:d,side:o,sideOffset:c,align:h,alignOffset:g,arrowPadding:x,collisionBoundary:j,collisionPadding:C,sticky:k,hideWhenDetached:v,avoidCollisions:f,...b}=s,N=Le(He,n),[p,y]=r.useState(null),[_,F]=r.useState(null),P=Ee(t,u=>y(u)),[V,G]=r.useState(null),[z,K]=r.useState(null),R=St(n),[q,U]=r.useState(!1),$=r.useRef(!1);r.useEffect(()=>{if(p)return Er(p)},[p]),Tr();const O=r.useCallback(u=>{const[w,...A]=R().map(E=>E.ref.current),[M]=A.slice(-1),W=document.activeElement;for(const E of u)if(E===W||(E?.scrollIntoView({block:"nearest"}),E===w&&_&&(_.scrollTop=0),E===M&&_&&(_.scrollTop=_.scrollHeight),E?.focus(),document.activeElement!==W))return},[R,_]),J=r.useCallback(()=>O([V,p]),[O,V,p]);r.useEffect(()=>{q&&J()},[q,J]);const{onOpenChange:Y,triggerPointerDownPosRef:Q}=N;r.useEffect(()=>{if(p){let u={x:0,y:0};const w=M=>{u={x:Math.abs(Math.round(M.pageX)-(Q.current?.x??0)),y:Math.abs(Math.round(M.pageY)-(Q.current?.y??0))}},A=M=>{u.x<=10&&u.y<=10?M.preventDefault():p.contains(M.target)||Y(!1),document.removeEventListener("pointermove",w),Q.current=null};return Q.current!==null&&(document.addEventListener("pointermove",w),document.addEventListener("pointerup",A,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",w),document.removeEventListener("pointerup",A,{capture:!0})}}},[p,Y,Q]),r.useEffect(()=>{const u=()=>Y(!1);return window.addEventListener("blur",u),window.addEventListener("resize",u),()=>{window.removeEventListener("blur",u),window.removeEventListener("resize",u)}},[Y]);const[re,oe]=Dn(u=>{const w=R().filter(W=>!W.disabled),A=w.find(W=>W.ref.current===document.activeElement),M=Pn(w,u,A);M&&setTimeout(()=>M.ref.current.focus())}),ue=r.useCallback((u,w,A)=>{const M=!$.current&&!A;(N.value!==void 0&&N.value===w||M)&&(G(u),M&&($.current=!0))},[N.value]),le=r.useCallback(()=>p?.focus(),[p]),T=r.useCallback((u,w,A)=>{const M=!$.current&&!A;(N.value!==void 0&&N.value===w||M)&&K(u)},[N.value]),B=i==="popper"?Pt:bn,S=B===Pt?{side:o,sideOffset:c,align:h,alignOffset:g,arrowPadding:x,collisionBoundary:j,collisionPadding:C,sticky:k,hideWhenDetached:v,avoidCollisions:f}:{};return e.jsx(gn,{scope:n,content:p,viewport:_,onViewportChange:F,itemRefCallback:ue,selectedItem:V,onItemLeave:le,itemTextRefCallback:T,focusSelectedItem:J,selectedItemText:z,position:i,isPositioned:q,searchRef:re,children:e.jsx(Rr,{as:ao,allowPinchZoom:!0,children:e.jsx(Ir,{asChild:!0,trapped:N.open,onMountAutoFocus:u=>{u.preventDefault()},onUnmountAutoFocus:pe(a,u=>{N.trigger?.focus({preventScroll:!0}),u.preventDefault()}),children:e.jsx(Ar,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:l,onPointerDownOutside:d,onFocusOutside:u=>u.preventDefault(),onDismiss:()=>N.onOpenChange(!1),children:e.jsx(B,{role:"listbox",id:N.contentId,"data-state":N.open?"open":"closed",dir:N.dir,onContextMenu:u=>u.preventDefault(),...b,...S,onPlaced:()=>U(!0),ref:P,style:{display:"flex",flexDirection:"column",outline:"none",...b.style},onKeyDown:pe(b.onKeyDown,u=>{const w=u.ctrlKey||u.altKey||u.metaKey;if(u.key==="Tab"&&u.preventDefault(),!w&&u.key.length===1&&oe(u.key),["ArrowUp","ArrowDown","Home","End"].includes(u.key)){let M=R().filter(W=>!W.disabled).map(W=>W.ref.current);if(["ArrowUp","End"].includes(u.key)&&(M=M.slice().reverse()),["ArrowUp","ArrowDown"].includes(u.key)){const W=u.target,E=M.indexOf(W);M=M.slice(E+1)}setTimeout(()=>O(M)),u.preventDefault()}})})})})})})});vn.displayName=io;var oo="SelectItemAlignedPosition",bn=r.forwardRef((s,t)=>{const{__scopeSelect:n,onPlaced:i,...a}=s,l=Le(He,n),d=De(He,n),[o,c]=r.useState(null),[h,g]=r.useState(null),x=Ee(t,P=>g(P)),j=St(n),C=r.useRef(!1),k=r.useRef(!0),{viewport:v,selectedItem:f,selectedItemText:b,focusSelectedItem:N}=d,p=r.useCallback(()=>{if(l.trigger&&l.valueNode&&o&&h&&v&&f&&b){const P=l.trigger.getBoundingClientRect(),V=h.getBoundingClientRect(),G=l.valueNode.getBoundingClientRect(),z=b.getBoundingClientRect();if(l.dir!=="rtl"){const W=z.left-V.left,E=G.left-W,Z=P.left-E,ie=P.width+Z,fe=Math.max(ie,V.width),be=window.innerWidth-Ce,me=js(E,[Ce,Math.max(Ce,be-fe)]);o.style.minWidth=ie+"px",o.style.left=me+"px"}else{const W=V.right-z.right,E=window.innerWidth-G.right-W,Z=window.innerWidth-P.right-E,ie=P.width+Z,fe=Math.max(ie,V.width),be=window.innerWidth-Ce,me=js(E,[Ce,Math.max(Ce,be-fe)]);o.style.minWidth=ie+"px",o.style.right=me+"px"}const K=j(),R=window.innerHeight-Ce*2,q=v.scrollHeight,U=window.getComputedStyle(h),$=parseInt(U.borderTopWidth,10),O=parseInt(U.paddingTop,10),J=parseInt(U.borderBottomWidth,10),Y=parseInt(U.paddingBottom,10),Q=$+O+q+Y+J,re=Math.min(f.offsetHeight*5,Q),oe=window.getComputedStyle(v),ue=parseInt(oe.paddingTop,10),le=parseInt(oe.paddingBottom,10),T=P.top+P.height/2-Ce,B=R-T,S=f.offsetHeight/2,u=f.offsetTop+S,w=$+O+u,A=Q-w;if(w<=T){const W=K.length>0&&f===K[K.length-1].ref.current;o.style.bottom="0px";const E=h.clientHeight-v.offsetTop-v.offsetHeight,Z=Math.max(B,S+(W?le:0)+E+J),ie=w+Z;o.style.height=ie+"px"}else{const W=K.length>0&&f===K[0].ref.current;o.style.top="0px";const Z=Math.max(T,$+v.offsetTop+(W?ue:0)+S)+A;o.style.height=Z+"px",v.scrollTop=w-T+v.offsetTop}o.style.margin=`${Ce}px 0`,o.style.minHeight=re+"px",o.style.maxHeight=R+"px",i?.(),requestAnimationFrame(()=>C.current=!0)}},[j,l.trigger,l.valueNode,o,h,v,f,b,l.dir,i]);Me(()=>p(),[p]);const[y,_]=r.useState();Me(()=>{h&&_(window.getComputedStyle(h).zIndex)},[h]);const F=r.useCallback(P=>{P&&k.current===!0&&(p(),N?.(),k.current=!1)},[p,N]);return e.jsx(co,{scope:n,contentWrapper:o,shouldExpandOnScrollRef:C,onScrollButtonChange:F,children:e.jsx("div",{ref:c,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:y},children:e.jsx(Se.div,{...a,ref:x,style:{boxSizing:"border-box",maxHeight:"100%",...a.style}})})})});bn.displayName=oo;var lo="SelectPopperPosition",Pt=r.forwardRef((s,t)=>{const{__scopeSelect:n,align:i="start",collisionPadding:a=Ce,...l}=s,d=jt(n);return e.jsx(Mr,{...d,...l,ref:t,align:i,collisionPadding:a,style:{boxSizing:"border-box",...l.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});Pt.displayName=lo;var[co,Kt]=Xe(He,{}),Ot="SelectViewport",wn=r.forwardRef((s,t)=>{const{__scopeSelect:n,nonce:i,...a}=s,l=De(Ot,n),d=Kt(Ot,n),o=Ee(t,l.onViewportChange),c=r.useRef(0);return e.jsxs(e.Fragment,{children:[e.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:i}),e.jsx(Nt.Slot,{scope:n,children:e.jsx(Se.div,{"data-radix-select-viewport":"",role:"presentation",...a,ref:o,style:{position:"relative",flex:1,overflow:"hidden auto",...a.style},onScroll:pe(a.onScroll,h=>{const g=h.currentTarget,{contentWrapper:x,shouldExpandOnScrollRef:j}=d;if(j?.current&&x){const C=Math.abs(c.current-g.scrollTop);if(C>0){const k=window.innerHeight-Ce*2,v=parseFloat(x.style.minHeight),f=parseFloat(x.style.height),b=Math.max(v,f);if(b<k){const N=b+C,p=Math.min(k,N),y=N-p;x.style.height=p+"px",x.style.bottom==="0px"&&(g.scrollTop=y>0?y:0,x.style.justifyContent="flex-end")}}}c.current=g.scrollTop})})})]})});wn.displayName=Ot;var yn="SelectGroup",[uo,mo]=Xe(yn),fo=r.forwardRef((s,t)=>{const{__scopeSelect:n,...i}=s,a=qt();return e.jsx(uo,{scope:n,id:a,children:e.jsx(Se.div,{role:"group","aria-labelledby":a,...i,ref:t})})});fo.displayName=yn;var Nn="SelectLabel",Sn=r.forwardRef((s,t)=>{const{__scopeSelect:n,...i}=s,a=mo(Nn,n);return e.jsx(Se.div,{id:a.id,...i,ref:t})});Sn.displayName=Nn;var yt="SelectItem",[ho,jn]=Xe(yt),Cn=r.forwardRef((s,t)=>{const{__scopeSelect:n,value:i,disabled:a=!1,textValue:l,...d}=s,o=Le(yt,n),c=De(yt,n),h=o.value===i,[g,x]=r.useState(l??""),[j,C]=r.useState(!1),k=Ee(t,N=>c.itemRefCallback?.(N,i,a)),v=qt(),f=r.useRef("touch"),b=()=>{a||(o.onValueChange(i),o.onOpenChange(!1))};if(i==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return e.jsx(ho,{scope:n,value:i,disabled:a,textId:v,isSelected:h,onItemTextChange:r.useCallback(N=>{x(p=>p||(N?.textContent??"").trim())},[]),children:e.jsx(Nt.ItemSlot,{scope:n,value:i,disabled:a,textValue:g,children:e.jsx(Se.div,{role:"option","aria-labelledby":v,"data-highlighted":j?"":void 0,"aria-selected":h&&j,"data-state":h?"checked":"unchecked","aria-disabled":a||void 0,"data-disabled":a?"":void 0,tabIndex:a?void 0:-1,...d,ref:k,onFocus:pe(d.onFocus,()=>C(!0)),onBlur:pe(d.onBlur,()=>C(!1)),onClick:pe(d.onClick,()=>{f.current!=="mouse"&&b()}),onPointerUp:pe(d.onPointerUp,()=>{f.current==="mouse"&&b()}),onPointerDown:pe(d.onPointerDown,N=>{f.current=N.pointerType}),onPointerMove:pe(d.onPointerMove,N=>{f.current=N.pointerType,a?c.onItemLeave?.():f.current==="mouse"&&N.currentTarget.focus({preventScroll:!0})}),onPointerLeave:pe(d.onPointerLeave,N=>{N.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:pe(d.onKeyDown,N=>{c.searchRef?.current!==""&&N.key===" "||(Za.includes(N.key)&&b(),N.key===" "&&N.preventDefault())})})})})});Cn.displayName=yt;var Je="SelectItemText",_n=r.forwardRef((s,t)=>{const{__scopeSelect:n,className:i,style:a,...l}=s,d=Le(Je,n),o=De(Je,n),c=jn(Je,n),h=so(Je,n),[g,x]=r.useState(null),j=Ee(t,b=>x(b),c.onItemTextChange,b=>o.itemTextRefCallback?.(b,c.value,c.disabled)),C=g?.textContent,k=r.useMemo(()=>e.jsx("option",{value:c.value,disabled:c.disabled,children:C},c.value),[c.disabled,c.value,C]),{onNativeOptionAdd:v,onNativeOptionRemove:f}=h;return Me(()=>(v(k),()=>f(k)),[v,f,k]),e.jsxs(e.Fragment,{children:[e.jsx(Se.span,{id:c.textId,...l,ref:j}),c.isSelected&&d.valueNode&&!d.valueNodeHasChildren?Ys.createPortal(l.children,d.valueNode):null]})});_n.displayName=Je;var kn="SelectItemIndicator",En=r.forwardRef((s,t)=>{const{__scopeSelect:n,...i}=s;return jn(kn,n).isSelected?e.jsx(Se.span,{"aria-hidden":!0,...i,ref:t}):null});En.displayName=kn;var $t="SelectScrollUpButton",Tn=r.forwardRef((s,t)=>{const n=De($t,s.__scopeSelect),i=Kt($t,s.__scopeSelect),[a,l]=r.useState(!1),d=Ee(t,i.onScrollButtonChange);return Me(()=>{if(n.viewport&&n.isPositioned){let o=function(){const h=c.scrollTop>0;l(h)};const c=n.viewport;return o(),c.addEventListener("scroll",o),()=>c.removeEventListener("scroll",o)}},[n.viewport,n.isPositioned]),a?e.jsx(In,{...s,ref:d,onAutoScroll:()=>{const{viewport:o,selectedItem:c}=n;o&&c&&(o.scrollTop=o.scrollTop-c.offsetHeight)}}):null});Tn.displayName=$t;var Ut="SelectScrollDownButton",Rn=r.forwardRef((s,t)=>{const n=De(Ut,s.__scopeSelect),i=Kt(Ut,s.__scopeSelect),[a,l]=r.useState(!1),d=Ee(t,i.onScrollButtonChange);return Me(()=>{if(n.viewport&&n.isPositioned){let o=function(){const h=c.scrollHeight-c.clientHeight,g=Math.ceil(c.scrollTop)<h;l(g)};const c=n.viewport;return o(),c.addEventListener("scroll",o),()=>c.removeEventListener("scroll",o)}},[n.viewport,n.isPositioned]),a?e.jsx(In,{...s,ref:d,onAutoScroll:()=>{const{viewport:o,selectedItem:c}=n;o&&c&&(o.scrollTop=o.scrollTop+c.offsetHeight)}}):null});Rn.displayName=Ut;var In=r.forwardRef((s,t)=>{const{__scopeSelect:n,onAutoScroll:i,...a}=s,l=De("SelectScrollButton",n),d=r.useRef(null),o=St(n),c=r.useCallback(()=>{d.current!==null&&(window.clearInterval(d.current),d.current=null)},[]);return r.useEffect(()=>()=>c(),[c]),Me(()=>{o().find(g=>g.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[o]),e.jsx(Se.div,{"aria-hidden":!0,...a,ref:t,style:{flexShrink:0,...a.style},onPointerDown:pe(a.onPointerDown,()=>{d.current===null&&(d.current=window.setInterval(i,50))}),onPointerMove:pe(a.onPointerMove,()=>{l.onItemLeave?.(),d.current===null&&(d.current=window.setInterval(i,50))}),onPointerLeave:pe(a.onPointerLeave,()=>{c()})})}),xo="SelectSeparator",An=r.forwardRef((s,t)=>{const{__scopeSelect:n,...i}=s;return e.jsx(Se.div,{"aria-hidden":!0,...i,ref:t})});An.displayName=xo;var Ft="SelectArrow",po=r.forwardRef((s,t)=>{const{__scopeSelect:n,...i}=s,a=jt(n),l=Le(Ft,n),d=De(Ft,n);return l.open&&d.position==="popper"?e.jsx(Lr,{...a,...i,ref:t}):null});po.displayName=Ft;var go="SelectBubbleInput",Mn=r.forwardRef(({__scopeSelect:s,value:t,...n},i)=>{const a=r.useRef(null),l=Ee(i,a),d=Fa(t);return r.useEffect(()=>{const o=a.current;if(!o)return;const c=window.HTMLSelectElement.prototype,g=Object.getOwnPropertyDescriptor(c,"value").set;if(d!==t&&g){const x=new Event("change",{bubbles:!0});g.call(o,t),o.dispatchEvent(x)}},[d,t]),e.jsx(Se.select,{...n,style:{...ln,...n.style},ref:l,defaultValue:t})});Mn.displayName=go;function Ln(s){return s===""||s===void 0}function Dn(s){const t=kr(s),n=r.useRef(""),i=r.useRef(0),a=r.useCallback(d=>{const o=n.current+d;t(o),function c(h){n.current=h,window.clearTimeout(i.current),h!==""&&(i.current=window.setTimeout(()=>c(""),1e3))}(o)},[t]),l=r.useCallback(()=>{n.current="",window.clearTimeout(i.current)},[]);return r.useEffect(()=>()=>window.clearTimeout(i.current),[]),[n,a,l]}function Pn(s,t,n){const a=t.length>1&&Array.from(t).every(h=>h===t[0])?t[0]:t,l=n?s.indexOf(n):-1;let d=vo(s,Math.max(l,0));a.length===1&&(d=d.filter(h=>h!==n));const c=d.find(h=>h.textValue.toLowerCase().startsWith(a.toLowerCase()));return c!==n?c:void 0}function vo(s,t){return s.map((n,i)=>s[(t+i)%s.length])}var bo=cn,On=un,wo=fn,yo=hn,No=xn,$n=pn,So=wn,Un=Sn,Fn=Cn,jo=_n,Co=En,Bn=Tn,zn=Rn,Hn=An;const _o=bo,ko=wo,Vn=r.forwardRef(({className:s,children:t,...n},i)=>e.jsxs(On,{ref:i,className:ne("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background","placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",s),...n,children:[t,e.jsx(yo,{asChild:!0,children:e.jsx(zs,{className:"h-4 w-4 opacity-50"})})]}));Vn.displayName=On.displayName;const qn=r.forwardRef(({className:s,...t},n)=>e.jsx(Bn,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(Dr,{className:"h-4 w-4"})}));qn.displayName=Bn.displayName;const Gn=r.forwardRef(({className:s,...t},n)=>e.jsx(zn,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",s),...t,children:e.jsx(zs,{className:"h-4 w-4"})}));Gn.displayName=zn.displayName;const Wn=r.forwardRef(({className:s,children:t,position:n="popper",...i},a)=>e.jsx(No,{children:e.jsxs($n,{ref:a,className:ne("relative z-[10002] max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out","data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0","data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95","data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2","data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",s),position:n,...i,children:[e.jsx(qn,{}),e.jsx(So,{className:ne("p-1",n==="popper"&&"w-full min-w-[var(--radix-select-trigger-width)] max-h-[var(--radix-select-content-available-height)]"),children:t}),e.jsx(Gn,{})]})}));Wn.displayName=$n.displayName;const Eo=r.forwardRef(({className:s,...t},n)=>e.jsx(Un,{ref:n,className:ne("py-1.5 pl-8 pr-2 text-sm font-semibold",s),...t}));Eo.displayName=Un.displayName;const Kn=r.forwardRef(({className:s,children:t,...n},i)=>e.jsxs(Fn,{ref:i,className:ne("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none","focus:bg-accent focus:text-accent-foreground","data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),...n,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Co,{children:e.jsx(zt,{className:"h-4 w-4"})})}),e.jsx(jo,{children:t})]}));Kn.displayName=Fn.displayName;const To=r.forwardRef(({className:s,...t},n)=>e.jsx(Hn,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",s),...t}));To.displayName=Hn.displayName;const Ro=[.5,1,2,4];function Io({open:s,onOpenChange:t,entries:n,title:i}){const{t:a}=Ie("cli"),[l,d]=r.useState(0),[o,c]=r.useState(!1),[h,g]=r.useState(1),x=r.useRef(null),[j,C]=r.useState(!1),{containerRef:k,terminalRef:v,write:f,clear:b}=Pr({enabled:s,autoFocus:!1,onReady:G=>{G.options.disableStdin=!0,C(!0)}}),N=n.length>0,p=r.useCallback(()=>{const G=v.current;if(!G){b();return}try{G.reset()}catch{G.clear()}G.options.disableStdin=!0},[b]),y=r.useCallback(()=>{d(0),c(!1),p()},[p]),_=r.useMemo(()=>n.map(G=>G.data).join(""),[n]);r.useEffect(()=>{if(!s){c(!1),C(!1),y();return}y()},[s,y,n]),r.useEffect(()=>{if(!s||!o||!j)return;if(l>=n.length){c(!1);return}const G=l>0?n[l-1]?.ts??n[l].ts:n[l].ts,z=Math.max(0,n[l].ts-G),K=Math.min(2e3,Math.max(20,z/h));return x.current=window.setTimeout(()=>{f(n[l].data),d(R=>R+1)},K),()=>{x.current&&window.clearTimeout(x.current)}},[s,o,l,n,h]);const F=()=>{N&&j&&(l>=n.length&&y(),c(!0))},P=()=>{c(!1),x.current&&window.clearTimeout(x.current)},V=()=>{c(!1),j&&(d(n.length),p(),f(_))};return e.jsx(Qe,{open:s,onOpenChange:t,children:e.jsxs(et,{className:"cli-root max-w-4xl",children:[e.jsx(tt,{children:e.jsx(st,{children:a("replay_title",{title:i})})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs text-[var(--cli-muted-1)]",children:[e.jsx("div",{className:"rounded-full border border-white/40 bg-white/70 px-3 py-1",children:a("entries_count",{count:n.length})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:a("speed")}),e.jsxs(_o,{value:String(h),onValueChange:G=>g(Number(G)),children:[e.jsx(Vn,{className:"h-8 w-24",children:e.jsx(ko,{})}),e.jsx(Wn,{children:Ro.map(G=>e.jsxs(Kn,{value:String(G),children:[G,"x"]},G))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{size:"sm",onClick:F,disabled:!N,children:a("play")}),e.jsx(X,{variant:"secondary",size:"sm",onClick:P,disabled:!o,children:a("pause")}),e.jsx(X,{variant:"ghost",size:"sm",onClick:y,disabled:!N,children:a("restart")}),e.jsx(X,{variant:"ghost",size:"sm",onClick:V,disabled:!N,children:a("show_full")})]})]}),e.jsxs("div",{className:"relative h-[360px] rounded-2xl border border-white/40 bg-white/70 p-2",children:[e.jsx("div",{ref:k,className:"cli-terminal h-full"}),N?null:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-xs text-[var(--cli-muted-1)]",children:a("no_recording_available")})]})]})]})})}const Ao=120,Mo=40,Lo={sent:"bg-[var(--cli-status-idle)] text-[var(--cli-ink-0)]",streaming:"bg-[var(--cli-status-busy)] text-[var(--cli-ink-0)]",confirm:"bg-[var(--cli-status-warning)] text-[var(--cli-ink-0)]",blocked:"bg-[var(--cli-status-offline)] text-[var(--cli-ink-0)]",error:"bg-[var(--cli-status-error)] text-[var(--cli-ink-0)]"},Do={success:"bg-[var(--cli-status-online)] text-[var(--cli-ink-0)]",error:"bg-[var(--cli-status-error)] text-[var(--cli-ink-0)]"};function Po({open:s,onOpenChange:t,projectId:n,activeServerId:i}){const{t:a}=Ie("cli"),l=ce(T=>T.servers),[d,o]=r.useState(new Set),[c,h]=r.useState(""),[g,x]=r.useState({}),[j,C]=r.useState("~/"),[k,v]=r.useState([]),[f,b]=r.useState({}),[N,p]=r.useState(!1),[y,_]=r.useState(!1),F=r.useRef(null),P=r.useRef(new Map),V=r.useRef(new Map),G=r.useRef(crypto.randomUUID()),{socket:z,release:K}=r.useMemo(()=>Zs({}),[]),R=r.useCallback((T,B,S,u={})=>{const w=wt(S,{project_id:n,server_id:B,client_id:G.current,...u});z.emit(T,w)},[n,z]);r.useEffect(()=>{i&&o(T=>T.size>0?T:new Set([i]))},[i]);const q=r.useCallback(T=>{const B=V.current.get(T);B&&(window.clearTimeout(B),V.current.delete(T))},[]),U=r.useCallback((T,B,S=2e4)=>{q(T);const u=window.setTimeout(()=>{R("cli:session:close",T,{session_id:B},{session_id:B}),P.current.delete(T),V.current.delete(T)},S);V.current.set(T,u)},[q,R]),$=r.useCallback(()=>{P.current.forEach((T,B)=>{R("cli:session:close",B,{session_id:T},{session_id:T})}),P.current.clear(),V.current.forEach(T=>window.clearTimeout(T)),V.current.clear()},[R]);r.useEffect(()=>{s||($(),h(""),x({}),v([]),b({}))},[s,$]),r.useEffect(()=>()=>{$(),K()},[$,K]);const O=r.useMemo(()=>Array.from(d),[d]);r.useEffect(()=>{const T=u=>{const w=u.session_id||u.payload?.session_id,A=u.server_id||u.payload?.server_id,M=typeof w=="string"?w:String(w||""),W=typeof A=="string"?A:String(A||"");if(!M||!W)return;const E=P.current.get(W);if(!E||E!==M)return;const Z=String(u.payload?.data||"");Z&&(x(ie=>{const fe=ie[W];if(!fe)return ie;const be=(fe.output+Z).slice(-8e3);return{...ie,[W]:{...fe,status:"streaming",output:be}}}),U(W,M))},B=u=>{const w=u.payload,A=u.session_id||w?.session_id,M=u.server_id||w?.server_id,W=typeof A=="string"?A:String(A||""),E=typeof M=="string"?M:String(M||"");if(!W||!E)return;const Z=P.current.get(E);if(!Z||Z!==W)return;const ie=w?.danger||{},fe=ie?.description?String(ie.description):"Confirmation required",be=w?.command?String(w.command):void 0;q(E),x(me=>{const Pe=me[String(E)];return Pe?{...me,[String(E)]:{...Pe,status:"confirm",detail:fe,command:be||Pe.command,operationId:u.operation_id||Pe.operationId}}:me})},S=u=>{const w=u.payload,A=u.session_id||w?.session_id,M=u.server_id||w?.server_id,W=typeof A=="string"?A:String(A||""),E=typeof M=="string"?M:String(M||"");if(!W||!E)return;const Z=P.current.get(E);if(!Z||Z!==W)return;const ie=w?.danger||{},fe=ie?.description?String(ie.description):"Command blocked for safety.";x(be=>{const me=be[String(E)];return me?{...be,[String(E)]:{...me,status:"blocked",detail:fe}}:be}),U(E,W,8e3)};return z.on("cli:terminal:output",T),z.on("cli:terminal:confirm_required",B),z.on("cli:terminal:blocked",S),()=>{z.off("cli:terminal:output",T),z.off("cli:terminal:confirm_required",B),z.off("cli:terminal:blocked",S)}},[z,q,U]);const J=r.useCallback(T=>{o(B=>{const S=new Set(B);return S.has(T)?S.delete(T):S.add(T),S})},[]),Y=r.useCallback(()=>{o(new Set(l.map(T=>T.id)))},[l]),Q=r.useCallback(()=>{o(new Set)},[]),re=r.useCallback(async()=>{const T=c.trim();if(!(!T||O.length===0)){p(!0);try{const B=await Promise.all(O.map(async()=>crypto.randomUUID())),S={};O.forEach((u,w)=>{const A=P.current.get(u);A&&R("cli:session:close",u,{session_id:A},{session_id:A});const M=B[w],W=crypto.randomUUID();P.current.set(u,M),S[u]={status:"sent",output:"",operationId:W,command:T},R("cli:session:create",u,{session_id:M,cols:Ao,rows:Mo,project_id:n},{session_id:M}),R("cli:terminal:input",u,{data:T.endsWith(`
68
+ `)?T:`${T}
69
+ `},{session_id:M,operation_id:W,seq:bt()}),U(u,M)}),x(S)}catch(B){console.error("[CLI] Batch command failed:",B)}finally{p(!1)}}},[c,R,n,U,O]),oe=r.useCallback(T=>{const B=g[T],S=P.current.get(T);!B||!S||(R("cli:terminal:input",T,{data:B.command.endsWith(`
70
+ `)?B.command:`${B.command}
71
+ `,confirmed:!0},{session_id:S,operation_id:B.operationId,seq:bt()}),U(T,S),x(u=>({...u,[T]:{...B,status:"sent",detail:void 0}})))},[g,R,U]),ue=r.useCallback(T=>{const B=T.target.files?Array.from(T.target.files):[];v(B)},[]),le=r.useCallback(async()=>{if(!k.length||O.length===0)return;_(!0);const T={};await Promise.all(O.map(async B=>{try{for(const S of k)await Hs(n,B,S,j);T[B]={status:"success",detail:`${k.length} file(s) uploaded`}}catch(S){T[B]={status:"error",detail:S instanceof Error?S.message:"Upload failed"}}})),b(T),_(!1)},[n,O,k,j]);return e.jsx(Qe,{open:s,onOpenChange:t,children:e.jsxs(et,{className:"cli-root max-w-5xl",children:[e.jsx(tt,{children:e.jsxs(st,{className:"flex items-center gap-2",children:[e.jsx(ht,{className:"h-4 w-4"}),a("batch_operations")]})}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-[1fr_1.2fr]",children:[e.jsxs("div",{className:"rounded-2xl border border-white/40 bg-white/70 p-4 text-sm text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:a("batch_target_servers")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{variant:"secondary",size:"sm",onClick:Y,children:a("select_all")}),e.jsx(X,{variant:"ghost",size:"sm",onClick:Q,children:a("clear")})]})]}),e.jsx(Ze,{className:"mt-3 h-60 pr-2",children:e.jsxs("div",{className:"space-y-2",children:[l.map(T=>e.jsxs("label",{className:"flex items-center justify-between gap-2 rounded-lg border border-white/40 bg-white/60 px-3 py-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:d.has(T.id),onChange:()=>J(T.id),className:"cli-focus-ring h-3.5 w-3.5 accent-[var(--cli-accent-olive)]","aria-label":`${a("select_all")} ${T.name||T.hostname}`}),e.jsx("span",{className:"text-[var(--cli-ink-1)]",children:T.name||T.hostname})]}),e.jsx("span",{className:"rounded-full px-2 py-0.5 text-[10px] font-medium text-[var(--cli-muted-1)]",children:T.status})]},T.id)),l.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-white/40 bg-white/50 p-3 text-center text-xs text-[var(--cli-muted-1)]",children:a("no_servers_available")}):null]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-2xl border border-white/40 bg-white/70 p-4",children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:a("batch_run_command")}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsx(Or,{value:c,onChange:T=>h(T.target.value),placeholder:a("batch_command_placeholder"),className:"min-h-[80px]","aria-label":a("batch_command_input")}),e.jsx(X,{size:"sm",onClick:re,disabled:N||!c.trim()||O.length===0,children:a("run_on_selected")}),Object.keys(g).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(g).map(([T,B])=>{const S=l.find(u=>u.id===T)?.name||l.find(u=>u.id===T)?.hostname||T;return e.jsxs("div",{className:"rounded-xl border border-white/40 bg-white/60 px-3 py-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[var(--cli-ink-1)]",children:S}),e.jsx("span",{className:ne("rounded-full px-2 py-0.5 text-[10px] font-medium",Lo[B.status]),children:B.status})]}),B.detail?e.jsx("div",{className:"mt-1 text-[11px] text-[var(--cli-muted-1)]",children:B.detail}):null,B.status==="confirm"?e.jsx("div",{className:"mt-2",children:e.jsx(X,{size:"sm",onClick:()=>oe(T),children:a("confirm_and_run")})}):null,B.output?e.jsx("pre",{className:"mt-2 max-h-32 overflow-auto rounded-lg border border-white/40 bg-white/70 p-2 text-[11px] text-[var(--cli-ink-1)]",children:B.output}):null]},T)})}):null]})]}),e.jsxs("div",{className:"rounded-2xl border border-white/40 bg-white/70 p-4",children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:a("batch_upload")}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ps,{value:j,onChange:T=>C(T.target.value),placeholder:a("batch_upload_target_placeholder"),className:"flex-1","aria-label":a("upload_target_path")}),e.jsxs(X,{variant:"secondary",size:"sm",onClick:()=>F.current?.click(),children:[e.jsx(ji,{className:"mr-1 h-4 w-4"}),a("select_files")]}),e.jsx("input",{ref:F,type:"file",multiple:!0,className:"hidden",onChange:ue,"aria-label":a("select_files_to_upload")})]}),k.length>0?e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:a("files_selected_count",{count:k.length})}):e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:a("no_files_selected")}),e.jsx(X,{size:"sm",onClick:le,disabled:y||k.length===0||O.length===0,children:a("upload_to_selected")}),Object.keys(f).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(f).map(([T,B])=>{const S=l.find(u=>u.id===T)?.name||l.find(u=>u.id===T)?.hostname||T;return e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-white/40 bg-white/60 px-3 py-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[B.status==="success"?e.jsx(Vs,{className:"h-4 w-4 text-[var(--cli-status-online)]"}):null,e.jsx("span",{className:"text-[var(--cli-ink-1)]",children:S})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[B.detail?e.jsx("span",{children:B.detail}):null,e.jsx("span",{className:ne("rounded-full px-2 py-0.5 text-[10px] font-medium",Do[B.status]),children:B.status})]})]},T)})}):null]})]})]})]})]})})}function Oo(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,s=>{const t=Math.random()*16|0;return(s==="x"?t:t&3|8).toString(16)})}const Yt=$r()(Ur((s,t)=>({conversations:[],activeConversationId:null,createConversation:n=>{const i=Oo(),a=new Date,l={id:i,projectId:n,title:"New Conversation",createdAt:a,updatedAt:a};return s(d=>({conversations:[...d.conversations,l],activeConversationId:i})),i},setActiveConversation:n=>{s({activeConversationId:n})},updateConversationTitle:(n,i)=>{s(a=>({conversations:a.conversations.map(l=>l.id===n?{...l,title:i,updatedAt:new Date}:l)}))},deleteConversation:n=>{s(i=>{const a=i.conversations.filter(d=>d.id!==n);let l=i.activeConversationId;if(i.activeConversationId===n){const d=i.conversations.find(o=>o.id===n);if(d){const o=a.filter(c=>c.projectId===d.projectId);l=o.length>0?o[0].id:null}else l=null}return{conversations:a,activeConversationId:l}})},clearHistory:n=>{s(i=>{const a=i.conversations.filter(o=>o.projectId!==n),d=i.conversations.find(o=>o.id===i.activeConversationId)?.projectId===n?null:i.activeConversationId;return{conversations:a,activeConversationId:d}})},getConversationsForProject:n=>t().conversations.filter(i=>i.projectId===n).sort((i,a)=>new Date(a.updatedAt).getTime()-new Date(i.updatedAt).getTime()),getActiveConversation:()=>{const{conversations:n,activeConversationId:i}=t();return n.find(a=>a.id===i)},ensureConversation:n=>{const i=t(),a=i.getActiveConversation();if(a&&a.projectId===n)return a.id;const l=i.getConversationsForProject(n);if(l.length>0){const d=l[0];return s({activeConversationId:d.id}),d.id}return i.createConversation(n)}}),{name:"ds-chat-store",storage:{getItem:s=>{const t=localStorage.getItem(s);if(!t)return null;const n=JSON.parse(t);return n.state?.conversations&&(n.state.conversations=n.state.conversations.map(i=>({...i,createdAt:new Date(i.createdAt),updatedAt:new Date(i.updatedAt)}))),n},setItem:(s,t)=>{const n={...t,state:{...t.state,conversations:t.state.conversations.map(i=>({...i,createdAt:i.createdAt.toISOString(),updatedAt:i.updatedAt.toISOString()}))}};localStorage.setItem(s,JSON.stringify(n))},removeItem:s=>localStorage.removeItem(s)},partialize:s=>({conversations:s.conversations,activeConversationId:s.activeConversationId})})),$o=()=>Yt(s=>s.conversations.find(t=>t.id===s.activeConversationId)),Uo=s=>Yt(t=>t.conversations.filter(n=>n.projectId===s).sort((n,i)=>new Date(i.updatedAt).getTime()-new Date(n.updatedAt).getTime())),Fo=()=>Yt(s=>({createConversation:s.createConversation,setActiveConversation:s.setActiveConversation,updateConversationTitle:s.updateConversationTitle,deleteConversation:s.deleteConversation,clearHistory:s.clearHistory,ensureConversation:s.ensureConversation})),Cs=4e3;function Bo({projectId:s,server:t,readOnly:n,canUnbind:i}){const a=r.useRef(new ha),[l,d]=r.useState([]),[o,c]=r.useState(null),h=r.useRef(()=>{}),g=r.useRef(()=>{}),x=r.useRef(()=>{}),j=r.useRef(()=>{}),C=r.useRef(null),[k,v]=r.useState(!1),[f,b]=r.useState(null),[N,p]=r.useState(!1),[y,_]=r.useState(null),[F,P]=r.useState(null),[V,G]=r.useState(!1),[z,K]=r.useState([]),[R,q]=r.useState("Terminal session"),[U,$]=r.useState(!1),[O,J]=r.useState(!1),[Y,Q]=r.useState(!1),[re,oe]=r.useState(null),[ue,le]=r.useState(""),T=r.useRef(!1),B=r.useRef(null),S=r.useRef(new Map),u=r.useRef(t.status),w=r.useRef(!1),A=r.useRef(new Map),M=r.useRef(()=>""),W=r.useRef(()=>{}),E=r.useRef(new Set),Z=r.useRef(new Map),ie=r.useRef(null),fe=$o(),be=Uo(s),me=r.useMemo(()=>fe?.projectId===s?fe.id:be[0]?.id??null,[fe,be,s]),Pe=ce(m=>m.setConnectionStatus),Xt=ce(m=>m.updateServerStatus),ve=ce(m=>m.setSessions),Yn=ce(m=>m.addNotification),Xn=ce(m=>m.pushTelemetryPoint),Jt=ce(m=>m.refreshServers),{addToast:Oe}=nt(),_e=r.useRef({}),Ct=r.useRef(typeof TextDecoder<"u"?new TextDecoder("utf-8"):null),Ve=r.useCallback((m,I)=>{h.current?.(m,I)},[]),Ne=r.useCallback(()=>{g.current?.()},[]),Zt=r.useCallback(async()=>{if(!(!i||O||!window.confirm("Unbind this server? The CLI agent will disconnect and can be reconnected by logging in again."))){J(!0);try{await qs(s,t.id),await Jt(),Oe({type:"success",title:"Server unbound",description:"The CLI agent has been disconnected. Re-login to bind again."})}catch{Oe({type:"error",title:"Unbind failed",description:"Unable to unbind this server."})}finally{J(!1)}}},[Oe,i,s,Jt,t.id,O]),rt=r.useCallback(()=>{const m=a.current.getSessionsByServer(t.id);return d(m),ve(t.id,m),m},[t.id,ve]),$e=r.useCallback(m=>{if(!m)return;const I=M.current?.()??"";I&&(I.length>2e5||a.current.setSerialized(m,I))},[]),Ue=r.useCallback(m=>{const I=A.current.get(m);if(!I||I.length===0)return;const L=a.current.getSession(m);ja(m,t.id,L?.name??"Terminal session",I)},[t.id]),_t=r.useCallback(m=>{const I=S.current.get(m);I&&window.clearTimeout(I);const L=window.setTimeout(()=>{Ue(m),S.current.delete(m)},1200);S.current.set(m,L)},[Ue]),Jn=r.useCallback((m,I)=>{const L=Date.now(),D=A.current.get(m);if(!D){A.current.set(m,[{ts:L,data:I}]),_t(m);return}D.push({ts:L,data:I}),D.length>Cs&&D.splice(0,D.length-Cs),_t(m)},[_t]),Zn=r.useMemo(()=>({onTerminalOutput:m=>_e.current.onTerminalOutput?.(m),onStatusUpdate:m=>_e.current.onStatusUpdate?.(m),onConfirmRequired:m=>_e.current.onConfirmRequired?.(m),onBlocked:m=>_e.current.onBlocked?.(m),onSessionAttached:m=>_e.current.onSessionAttached?.(m),onSessionDetached:m=>_e.current.onSessionDetached?.(m),onSessionClosed:m=>_e.current.onSessionClosed?.(m),onSessionError:m=>_e.current.onSessionError?.(m),onError:m=>_e.current.onError?.(m)}),[]);_e.current={onTerminalOutput:m=>{const I=m.session_id||m.payload?.session_id,L=typeof I=="string"?I:String(I||"");if(!L)return;const D=m.payload?.data;let H="";if(typeof D=="string")H=D;else if(D instanceof ArrayBuffer)H=Ct.current?.decode(new Uint8Array(D))??"";else if(ArrayBuffer.isView(D)){const we=D;H=Ct.current?.decode(new Uint8Array(we.buffer,we.byteOffset,we.byteLength))??""}else if(Array.isArray(D))try{H=Ct.current?.decode(new Uint8Array(D))??""}catch{H=String(D)}else D!=null&&(H=String(D));let de=a.current.getSession(L);de||(a.current.restoreSession({id:L,serverId:t.id,name:`Terminal ${a.current.getSessionsByServer(t.id).length+1}`,createdAt:Date.now(),lastActiveAt:Date.now(),state:"active",scrollback:[],cols:C.current?.cols??120,rows:C.current?.rows??40,mode:"terminal"}),de=a.current.getSession(L),o||c(L)),a.current.updateScrollback(L,H),Jn(L,H),L===o&&Ve(H,()=>{x.current?.()});const se=a.current.getSessionsByServer(t.id);d(se),ve(t.id,se)},onStatusUpdate:m=>{const I=m.payload,L=I?.status,D=I?.last_seen_at,H=typeof D=="string"&&D?D:typeof m.ts=="string"&&m.ts?m.ts:void 0;if(L){const se=L,we=u.current;if(se!==we){const Ge=se==="online"?"CLI server online":"CLI server offline";Yn({id:crypto.randomUUID(),title:Ge,body:`${t.name||t.hostname} is now ${se}`,level:se==="online"?"success":"warning",createdAt:Date.now()}),rn(Ge,`${t.name||t.hostname} is now ${se}`),u.current=se}Xt(t.id,se,H??null)}else H&&Xt(t.id,u.current,H);const de=I?.metrics;if(de&&typeof de=="object"){const se=de,we=se.timestamp,Ge=typeof we=="string"&&we?we:new Date().toISOString(),he=xe=>{if(typeof xe=="number"&&Number.isFinite(xe))return xe;if(typeof xe=="string"){const ot=Number.parseFloat(xe);return Number.isFinite(ot)?ot:null}return null},ae={timestamp:Ge,cpu_percent:he(se.cpu_percent),mem_used_mb:he(se.mem_used_mb),mem_total_mb:he(se.mem_total_mb),mem_percent:he(se.mem_percent),disk_used_gb:he(se.disk_used_gb),disk_total_gb:he(se.disk_total_gb),disk_percent:he(se.disk_percent),gpu:Array.isArray(se.gpu)?se.gpu.map(xe=>({index:Number.parseInt(String(xe?.index??0),10),name:xe?.name,uuid:xe?.uuid,utilization_gpu:he(xe?.utilization_gpu),utilization_memory:he(xe?.utilization_memory),memory_total_mb:he(xe?.memory_total_mb),memory_used_mb:he(xe?.memory_used_mb),memory_free_mb:he(xe?.memory_free_mb)})):null};Xn(t.id,ae)}},onConfirmRequired:m=>{const I=m.payload,L=String(I?.command||""),D=I?.danger||{},H=m.session_id||String(I?.session_id||"");!H||a.current.getSession(String(H))?.mode==="ui"||_({command:L,sessionId:String(H),operationId:m.operation_id||crypto.randomUUID(),level:D?.level?String(D.level):void 0,description:D?.description?String(D.description):void 0,matchedPattern:D?.matched_pattern?String(D.matched_pattern):void 0})},onBlocked:m=>{const I=m.payload,L=String(I?.command||""),D=I?.danger||{},H=m.session_id||String(I?.session_id||"");a.current.getSession(String(H))?.mode!=="ui"&&(P(D?.description?String(D.description):"Command was blocked for safety."),Oe({type:"warning",title:"Command blocked",description:L?`${L} was blocked.`:"Command was blocked."}))},onSessionAttached:m=>{const I=Ae(m),L=String(I?.sessionId||I?.session_id||""),D=I?.scrollback;if(!L)return;Array.isArray(D)&&a.current.setScrollback(L,D);const H=a.current.getSessionsByServer(t.id);d(H),ve(t.id,H)},onSessionDetached:m=>{const I=Ae(m),L=String(I?.sessionId||I?.session_id||"");if(!L)return;a.current.detachSession(L);const D=a.current.getSessionsByServer(t.id);d(D),ve(t.id,D)},onSessionClosed:m=>{const I=Ae(m),L=String(I?.sessionId||I?.session_id||"");if(!L)return;a.current.closeSession(L),Ue(L),A.current.delete(L);const D=a.current.getSessionsByServer(t.id);d(D),ve(t.id,D),o===L&&c(a.current.getState().activeSessionId)},onSessionError:m=>{const I=Ae(m);console.warn("[CLI] Session error:",I)},onError:m=>{Oe({type:"error",title:"CLI server error",description:m||"CLI server error"})}};const{socket:it,status:Te,sendTerminalInput:kt,sendTerminalResize:Qt,emitEnvelope:Fe}=Qs({projectId:s,serverId:t.id,handlers:Zn}),es=r.useCallback(async(m,I)=>{if(Te.state!==ee.CONNECTED||E.current.has(m))return;const L=a.current.getSession(m);if(!L||!I?.force&&(L.scrollback.length>0||L.serialized))return;const D=Date.now(),H=Z.current.get(m)??0;if(!(!I?.force&&D-H<3e3)){Z.current.set(m,D),E.current.add(m);try{const de=L.scrollback.length>0?tn(L.scrollback):"",se=await Ss(it,{sessionId:m,serverId:t.id,scrollbackHash:de},{timeoutMs:5e3});if(se.recovered&&se.scrollback){a.current.setScrollback(m,se.scrollback);const we=a.current.getSessionsByServer(t.id);d(we),ve(t.id,we),m===o&&N&&(Ne(),Ve(se.scrollback.join(`
72
+ `)+`
73
+ `,()=>{x.current?.(),j.current?.()}))}}finally{E.current.delete(m)}}},[o,Ne,t.id,ve,it,Te.state,N,Ve]);r.useEffect(()=>{Pe(Te)},[Te,Pe]),r.useEffect(()=>{ie.current=o},[o]),r.useEffect(()=>{T.current=!1,w.current=!1;const m=a.current.getSessionsByServer(t.id);d(m),c(m[0]?.id??null),u.current=t.status},[t.id]),r.useEffect(()=>(B.current&&window.clearTimeout(B.current),B.current=window.setTimeout(()=>{ys(a.current.getSessionsByServer(t.id))},1e3),()=>{B.current&&window.clearTimeout(B.current)}),[l,t.id]),r.useEffect(()=>()=>{S.current.forEach(m=>window.clearTimeout(m)),S.current.clear()},[t.id]),r.useEffect(()=>()=>{const m=ie.current;m&&($e(m),Ue(m)),ys(a.current.getSessionsByServer(t.id))},[$e,Ue,t.id]);const Re=r.useMemo(()=>o?a.current.getSession(o):null,[o]),Qn=Re?.mode==="ui"?"ui":"terminal",ts=r.useCallback(()=>{if(!o)return;const m=a.current.getSession(o),I=A.current.get(o)??[],L=I.length===0?Sa(o):null,D=I.length>0?I:L?.entries??[];K([...D]),q(m?.name??L?.title??"Terminal session"),G(!0)},[o]),Be=r.useCallback(m=>{try{o&&$e(o),Ne();const I=C.current,L=a.current.createSession(t.id,{id:m?.id,name:m?.name,mode:m?.mode,cols:m?.cols??I?.cols,rows:m?.rows??I?.rows}),D=a.current.getSessionsByServer(t.id);d(D),ve(t.id,D),c(L.id);const H={session_id:L.id,cols:L.cols,rows:L.rows};return s&&(H.project_id=s),L.name&&(H.name=L.name),L.mode==="ui"&&(H.mode="ui"),Fe("cli:session:create",H,{session_id:L.id}),L}catch(I){return console.error("[CLI] Failed to create session:",I),null}},[o,$e,Ne,Fe,t.id,ve]),qe=r.useCallback(async()=>{if(!s)return null;const m=await Ra(s,t.id),I=a.current.getSession(m);return I&&I.state!=="closed"?(c(I.id),I):Be({id:m})},[Be,s,t.id]),at=r.useCallback(async()=>{if(!s||!me)return null;const m=await Ia(s,t.id,me),I=a.current.getSession(m);return I&&I.state!=="closed"?(c(I.id),I):Be({id:m,name:"Conversation session"})},[me,Be,s,t.id]);r.useEffect(()=>{if(Te.state!==ee.CONNECTED||T.current)return;T.current=!0,(async()=>{const I=H=>{if(!H)return Date.now();const de=Date.parse(H);return Number.isFinite(de)?de:Date.now()};try{const H=await Hr(s,t.id);if(H.length>0){const de=Ns().filter(ae=>ae.serverId===t.id),se=new Map(de.map(ae=>[ae.sessionId,ae])),we=a.current.getSessionsByServer(t.id),Ge=new Set(H.map(ae=>ae.id));we.forEach(ae=>{Ge.has(ae.id)||a.current.closeSession(ae.id)}),H.forEach(ae=>{const xe=Array.isArray(ae.scrollback)?ae.scrollback:[],ot=se.get(ae.id),ar=xe.length===0?ot?.serialized:void 0;a.current.restoreSession({id:ae.id,serverId:t.id,name:ae.name||"Terminal",createdAt:I(ae.connected_at),lastActiveAt:I(ae.last_active_at||ae.connected_at),state:ae.state||"active",scrollback:xe,cols:ae.cols??C.current?.cols??120,rows:ae.rows??C.current?.rows??40,mode:ae.session_type==="ui"?"ui":"terminal",cwd:ae.cwd??void 0,shell:ae.shell??void 0,serialized:ar})});const he=a.current.getSessionsByServer(t.id);if(he.length===0){await qe();return}d(he),ve(t.id,he),c(he[0]?.id??null);return}}catch(H){console.warn("[CLI] Failed to load sessions from API:",H)}const L=Ns().filter(H=>H.serverId===t.id);if(L.length===0){a.current.getSessionsByServer(t.id).length===0&&await qe();return}for(const H of L){const de=await Ss(it,{sessionId:H.sessionId,serverId:H.serverId,scrollbackHash:H.serialized?H.scrollbackHash:""});de.recovered&&a.current.restoreSession({id:H.sessionId,serverId:H.serverId,name:H.name,createdAt:Date.now(),lastActiveAt:Date.now(),state:"active",scrollback:de.scrollback||[],cols:H.cols,rows:H.rows,mode:H.mode,cwd:H.cwd,shell:H.shell,serialized:H.serialized})}const D=a.current.getSessionsByServer(t.id);if(D.length===0){await qe();return}d(D),ve(t.id,D),c(D[0]?.id??null)})()},[s,Te.state,t.id,it,Be,qe,ve]),r.useEffect(()=>{w.current||l.length>0||o||(w.current=!0,me?at():qe())},[o,me,at,qe,l.length]);const ss=r.useCallback(()=>{if(!Re||!N)return;Ne();const m=Re.serialized,I=Re.scrollback;m?Ve(m,()=>{x.current?.(),j.current?.()}):I.length>0?Ve(I.join(`
74
+ `)+`
75
+ `,()=>{x.current?.(),j.current?.()}):(x.current?.(),j.current?.()),b(null),W.current?.()},[Re,Ne,N,Ve]);r.useEffect(()=>{ss()},[ss]),r.useEffect(()=>{!N||!o||es(o)},[o,es,N]);const ns=r.useCallback(m=>{if(m===o||re===m)return;$e(o),Ne(),o&&a.current.getSession(o)?.state==="active"&&(a.current.detachSession(o),Fe("cli:session:detach",{session_id:o},{session_id:o})),a.current.attachSession(m)||a.current.switchSession(m),Fe("cli:session:attach",{session_id:m},{session_id:m});const L=a.current.getSessionsByServer(t.id);d(L),ve(t.id,L),c(m)},[o,re,Fe,t.id,ve]),rs=r.useCallback(m=>{if(!a.current.getSession(m))return;$e(m),m===o&&Ne(),a.current.closeSession(m),Fe("cli:session:close",{session_id:m},{session_id:m}),Ue(m),A.current.delete(m);const L=rt(),D=a.current.getState().activeSessionId;c(D),!D&&L.length===0&&Ne(),re===m&&(oe(null),le(""))},[$e,Ne,Fe,re,Ue,rt]),is=r.useCallback((m,I)=>{oe(m),le(I)},[]),as=r.useCallback((m,I)=>{const L=a.current.getSession(m);if(!L){oe(null),le("");return}const H=I.trim()||L.name||"Terminal";H!==L.name&&(a.current.renameSession(m,H),rt(),n||Fr(s,t.id,m,{name:H}).catch(()=>{Oe({type:"warning",title:"Session rename failed",description:"Unable to persist the session name. Changes are local only."})})),oe(null),le("")},[Oe,s,n,t.id,rt]),er=r.useCallback(()=>{oe(null),le("")},[]),Et=r.useCallback(()=>{if(me){at();return}Be()},[me,Be,at]);va({onClear:Ne,onNewSession:Et,onCloseSession:()=>{o&&rs(o)},onSearch:()=>v(!0)});const tr=r.useCallback(m=>{if(n||!o)return;const I=crypto.randomUUID(),L=Re?.mode;kt({data:m,sessionId:o,seq:bt(),operationId:I,mode:L})},[n,o,kt,Re]),sr=r.useCallback((m,I)=>{C.current={cols:m,rows:I},o&&Qt({cols:m,rows:I,sessionId:o})},[o,Qt]),nr=r.useCallback(m=>{if(m.state===0){b(null);return}b(m)},[]),os=r.useMemo(()=>f?f.state===3?"Running…":`${Math.round(f.value)}%`:null,[f]),rr=r.useMemo(()=>f?f.state===2?"bg-[var(--cli-status-error)] text-[var(--cli-ink-0)]":f.state===4||f.state===3?"bg-[var(--cli-status-warning)] text-[var(--cli-ink-0)]":"bg-[var(--cli-accent-emerald)] text-[var(--cli-ink-0)]":"",[f]),ir=Y?"w-14":"w-56";return e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[n?e.jsx(te,{className:"mb-3 rounded-xl border border-white/40 bg-white/70 px-4 py-2 text-xs text-[var(--cli-muted-1)]",children:"Read-only access. Terminal input is disabled."}):null,F?e.jsx(te,{className:"mb-3 rounded-xl border border-white/40 bg-white/70 px-4 py-2 text-xs text-[var(--cli-muted-1)]",children:F}):null,e.jsxs("div",{className:"flex min-h-0 flex-1 gap-3",children:[e.jsx("div",{className:`flex ${ir} shrink-0 flex-col gap-3`,children:Y?e.jsxs(te,{className:"cli-card flex min-h-0 flex-1 flex-col items-center rounded-2xl border border-white/40 bg-white/70 px-2 py-3",children:[e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/60 bg-white/80 p-2 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",onClick:()=>Q(!1),title:"Expand sessions panel","aria-label":"Expand sessions panel",children:e.jsx(Ls,{className:"h-4 w-4"})}),e.jsx("div",{className:"mt-3 flex flex-1 flex-col items-center gap-2 overflow-auto",children:l.map(m=>{const I=m.id===o,L=(m.name||"Terminal").slice(0,2).toUpperCase();return e.jsx("button",{type:"button",onClick:()=>ns(m.id),"aria-pressed":I,title:m.name||"Terminal",className:`cli-focus-ring flex h-9 w-9 items-center justify-center rounded-xl text-[10px] font-semibold transition ${I?"bg-[var(--cli-accent-olive)] text-[var(--cli-ink-0)]":"bg-white/70 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]"}`,children:L},m.id)})}),e.jsx("button",{type:"button",className:"cli-focus-ring mt-3 flex h-9 w-9 items-center justify-center rounded-xl border border-white/40 bg-white/60 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",onClick:Et,title:"New session","aria-label":"Create new session",children:e.jsx(gt,{className:"h-4 w-4"})}),e.jsxs("div",{className:"mt-3 flex flex-col items-center gap-2",children:[e.jsxs(cs,{children:[e.jsx(ds,{asChild:!0,children:e.jsx("button",{type:"button",className:"cli-focus-ring flex h-9 w-9 items-center justify-center rounded-xl border border-white/40 bg-white/70 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",title:"Actions","aria-label":"Actions",children:e.jsx(ht,{className:"h-4 w-4"})})}),e.jsxs(us,{align:"end",children:[e.jsxs(We,{onClick:ts,disabled:!Re?.scrollback.length,children:[e.jsx(ms,{className:"mr-2 h-3.5 w-3.5"}),"Replay session"]}),e.jsxs(We,{onClick:()=>$(!0),disabled:n,children:[e.jsx(ht,{className:"mr-2 h-3.5 w-3.5"}),"Batch operations"]}),i?e.jsxs(e.Fragment,{children:[e.jsx(fs,{}),e.jsxs(We,{onClick:()=>void Zt(),disabled:O,children:[e.jsx(Rt,{className:"mr-2 h-3.5 w-3.5"}),"Unbind server"]})]}):null]})]}),e.jsx("button",{type:"button",className:"cli-focus-ring flex h-9 w-9 items-center justify-center rounded-xl border border-white/40 bg-white/70 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",onClick:()=>v(m=>!m),title:"Search output","aria-label":"Search output",children:e.jsx(Dt,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",className:"cli-focus-ring flex h-9 w-9 items-center justify-center rounded-xl border border-white/40 bg-white/70 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",onClick:Ne,title:"Clear output","aria-label":"Clear output",children:e.jsx(xs,{className:"h-4 w-4"})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(te,{className:"cli-card flex min-h-0 flex-1 flex-col rounded-2xl border border-white/40 bg-white/70 px-3 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-xs font-semibold text-[var(--cli-ink-1)]",children:"Sessions"}),e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/60 bg-white/80 p-1.5 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",onClick:()=>Q(!0),title:"Collapse sessions panel","aria-label":"Collapse sessions panel",children:e.jsx(Ds,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"mt-3 flex flex-1 flex-col gap-2 overflow-auto pr-1",children:l.map(m=>{const I=m.id===o,L=m.id===re;return e.jsxs("div",{className:"group relative",children:[e.jsx("button",{type:"button",onClick:()=>ns(m.id),onDoubleClick:()=>is(m.id,m.name),"aria-pressed":I,className:`cli-focus-ring w-full rounded-xl px-3 py-2 pr-10 text-left text-xs font-medium transition ${I?"bg-[var(--cli-accent-olive)] text-[var(--cli-ink-0)]":"bg-white/60 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]"}`,children:L?e.jsx("input",{className:"w-full rounded-lg border border-white/50 bg-white/80 px-2 py-1 text-xs text-[var(--cli-ink-1)] outline-none focus:ring-2 focus:ring-[var(--cli-accent-olive)]",value:ue,onChange:D=>le(D.target.value),onKeyDown:D=>{D.key==="Enter"&&(D.preventDefault(),as(m.id,ue)),D.key==="Escape"&&(D.preventDefault(),er())},onBlur:()=>as(m.id,ue),onClick:D=>D.stopPropagation(),autoFocus:!0}):m.name}),L?null:e.jsxs("div",{className:"absolute right-2 top-2 flex items-center gap-1 opacity-0 transition group-hover:opacity-100",children:[e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/40 bg-white/80 p-1 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",onClick:D=>{D.stopPropagation(),is(m.id,m.name)},"aria-label":"Rename session",title:"Rename session",children:e.jsx(Br,{className:"h-3 w-3"})}),e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/40 bg-white/80 p-1 text-[var(--cli-status-error)] hover:text-[var(--cli-status-error)]",onClick:D=>{D.stopPropagation(),rs(m.id)},"aria-label":"Close session",title:"Close session",children:e.jsx(Rt,{className:"h-3 w-3"})})]})]},m.id)})}),e.jsxs("button",{type:"button",className:"cli-focus-ring mt-3 flex w-full items-center justify-center gap-2 rounded-xl border border-white/40 bg-white/60 px-3 py-2 text-xs text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",onClick:Et,title:"New session","aria-label":"Create new session",children:[e.jsx(gt,{className:"h-3.5 w-3.5"}),"New session"]})]}),e.jsxs(te,{className:"cli-card shrink-0 rounded-2xl border border-white/40 bg-white/70 px-3 py-3",children:[e.jsx("div",{className:"text-xs font-semibold text-[var(--cli-ink-1)]",children:"Controls"}),e.jsx("div",{className:"mt-3 flex flex-col gap-2",children:e.jsxs(cs,{children:[e.jsx(ds,{asChild:!0,children:e.jsx(X,{size:"sm",variant:"secondary",className:"h-8 w-full justify-start rounded-xl px-3 text-[11px]",children:"Actions"})}),e.jsxs(us,{align:"start",children:[e.jsxs(We,{onClick:ts,disabled:!Re?.scrollback.length,children:[e.jsx(ms,{className:"mr-2 h-3.5 w-3.5"}),"Replay session"]}),e.jsxs(We,{onClick:()=>$(!0),disabled:n,children:[e.jsx(ht,{className:"mr-2 h-3.5 w-3.5"}),"Batch operations"]}),i?e.jsxs(e.Fragment,{children:[e.jsx(fs,{}),e.jsxs(We,{onClick:()=>void Zt(),disabled:O,children:[e.jsx(Rt,{className:"mr-2 h-3.5 w-3.5"}),"Unbind server"]})]}):null]})]})}),e.jsxs("div",{className:"mt-3 space-y-2 text-[11px] text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"rounded-full border border-white/40 bg-white/70 px-2 py-0.5 text-center",children:[Te.state," · ",Te.latencyMs?`${Te.latencyMs} ms`:"–"]}),os?e.jsxs("div",{className:`rounded-full px-2 py-0.5 text-center text-[10px] font-medium ${rr}`,children:["Progress: ",os]}):null]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/40 bg-white/80 p-2 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",onClick:()=>v(m=>!m),title:"Search output","aria-label":"Search output",children:e.jsx(Dt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",className:"cli-focus-ring rounded-full border border-white/40 bg-white/80 p-2 text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",onClick:Ne,title:"Clear output","aria-label":"Clear output",children:e.jsx(xs,{className:"h-3.5 w-3.5"})})]})]})]})}),e.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(zr,{onInput:tr,onResize:sr,onProgress:nr,appearance:Qn,searchOpen:k,onSearchOpenChange:v,onReady:({write:m,clear:I,serialize:L,resetProgress:D,scrollToBottom:H,focus:de})=>{h.current=m,g.current=I,M.current=L,W.current=D,x.current=H,j.current=de,p(!0)}})})})]}),e.jsx(Io,{open:V,onOpenChange:G,entries:z,title:R}),e.jsx(Po,{open:U,onOpenChange:$,projectId:s,activeServerId:t.id}),e.jsx(ga,{open:!!y,command:y?.command||"",level:y?.level,description:y?.description,matchedPattern:y?.matchedPattern,onCancel:()=>_(null),onConfirm:()=>{y&&(kt({data:y.command,sessionId:y.sessionId,seq:bt(),operationId:y.operationId,confirmed:!0}),_(null))}})]})}function zo({onBind:s}){const{t}=Ie("cli");return e.jsx(ge,{duration:.45,y:12,children:e.jsxs(te,{className:"flex h-full w-full flex-col items-center justify-center gap-4 rounded-2xl border border-white/40 bg-white/60 p-8 text-center shadow-[0_8px_30px_rgba(32,32,32,0.08)] transition-all duration-300 motion-safe:hover:-translate-y-0.5",spotlightColor:"rgba(143, 163, 184, 0.18)",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-[var(--cli-bg-2)] text-[var(--cli-ink-1)]",children:e.jsx($s,{className:"h-6 w-6"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-[var(--cli-ink-1)]",children:t("empty_title")}),e.jsx("p",{className:"mt-1 text-sm text-[var(--cli-muted-1)]",children:t("empty_desc")})]}),e.jsxs("div",{className:"w-full max-w-md space-y-2 rounded-xl border border-white/40 bg-white/70 px-4 py-3 text-left text-xs text-[var(--cli-muted-1)]",children:[e.jsx("div",{className:"font-semibold text-[var(--cli-ink-1)]",children:t("quick_start")}),e.jsx("div",{children:t("quick_step_1")}),e.jsx("div",{children:t("quick_step_2")}),e.jsx("div",{children:t("quick_step_3")})]}),s?e.jsx(X,{onClick:s,className:"rounded-full px-5",children:t("bind_server")}):null]})})}function Ho({open:s,onOpenChange:t}){const{t:n}=Ie("cli"),[i,a]=r.useState(null),[l,d]=r.useState(!1),[o,c]=r.useState(null),[h,g]=r.useState(null),j=(Vr.defaults.baseURL||"").replace(/\/$/,"")||"http://deepscientist.cc:8080";r.useEffect(()=>{if(!s)return;let f=!1;return d(!0),c(null),a(null),g(null),qr().then(b=>{f||a(b.api_token)}).catch(()=>{f||c(n("token_load_error"))}).finally(()=>{f||d(!1)}),()=>{f=!0}},[s,n]);const C=async(f,b)=>{i&&(await Gr(b),g(f),window.setTimeout(()=>g(null),1500))},k=i?`bash install.sh --token ${i} --server ${j}`:"",v=i?`ds-cli login --token ${i} --server ${j}
76
+ ds-cli start --ws-url ${j}`:"";return e.jsx(Qe,{open:s,onOpenChange:t,children:e.jsxs(et,{className:"cli-root max-w-2xl",children:[e.jsxs(tt,{children:[e.jsx(st,{children:n("bind_remote_server_title")}),e.jsx(Us,{children:n("bind_remote_server_desc")})]}),e.jsxs("div",{className:"space-y-3",children:[o?e.jsx("div",{className:"rounded-xl border border-black/5 bg-[var(--cli-bg-1)] p-3 text-sm text-[var(--cli-ink-1)]",children:o}):null,e.jsxs("div",{className:"rounded-xl border border-black/5 bg-white/70 p-3 text-sm text-[var(--cli-ink-1)]",children:[e.jsx("div",{className:"font-semibold",children:n("bind_option_install_title")}),e.jsx("code",{className:"mt-2 block rounded-lg bg-black/90 px-3 py-2 text-xs text-white break-all",children:l?n("loading_token"):k||n("token_unavailable")}),e.jsx("p",{className:"mt-2 text-xs text-[var(--cli-muted-1)]",children:n("bind_option_install_desc")}),e.jsx("p",{className:"mt-2 text-xs text-[var(--cli-muted-1)]",children:n("bind_option_custom_dir",{example:"bash install.sh --dir ~/.deepscientist --token ..."})}),e.jsx("p",{className:"mt-2 text-xs text-[var(--cli-muted-1)]",children:n("bind_option_local_codeagent")}),e.jsx(X,{className:"mt-3",size:"sm",variant:"secondary",onClick:()=>C("install",k),disabled:!i,children:n(h==="install"?"copied":"copy_install_command")})]}),e.jsxs("div",{className:"rounded-xl border border-black/5 bg-white/70 p-3 text-sm text-[var(--cli-ink-1)]",children:[e.jsx("div",{className:"font-semibold",children:n("bind_option_login_title")}),e.jsx("code",{className:"mt-2 block rounded-lg bg-black/90 px-3 py-2 text-xs text-white whitespace-pre-line break-all",children:l?n("loading_token"):v||n("token_unavailable")}),e.jsx("p",{className:"mt-2 text-xs text-[var(--cli-muted-1)]",children:n("bind_option_login_desc")}),e.jsx(X,{className:"mt-3",size:"sm",variant:"secondary",onClick:()=>C("login",v),disabled:!i,children:n(h==="login"?"copied":"copy_login_command")})]})]}),e.jsx(Vt,{className:"gap-2",children:e.jsx(X,{onClick:()=>t(!1),children:n("done")})})]})})}function Vo(){const{t:s}=Ie("cli"),t=ce(c=>c.notifications),n=ce(c=>c.markNotificationRead),i=ce(c=>c.clearNotifications),[a,l]=r.useState(null),d=r.useMemo(()=>t.filter(c=>!c.read).length,[t]),o=async()=>{const c=await Ca();l(c)};return e.jsxs("div",{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-4 text-sm text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--cli-ink-1)]",children:[e.jsx(Wr,{className:"h-4 w-4"}),s("notifications")]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[var(--cli-muted-1)]",children:s("unread_count",{count:d})}),t.length>0?e.jsxs(X,{variant:"ghost",size:"sm",onClick:i,children:[e.jsx(Gs,{className:"mr-1 h-3.5 w-3.5"}),s("clear")]}):null]})]}),e.jsxs("div",{className:"mt-3 space-y-2",children:[t.map(c=>e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-xl border border-white/40 bg-white/70 px-3 py-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-[var(--cli-ink-1)]",children:c.title}),c.body?e.jsx("div",{className:"mt-1 text-xs text-[var(--cli-muted-1)]",children:c.body}):null]}),c.read?null:e.jsx("button",{type:"button",className:"cli-focus-ring text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]",onClick:()=>n(c.id),title:s("mark_as_read"),"aria-label":s("mark_as_read"),children:e.jsx(zt,{className:"h-3.5 w-3.5"})})]},c.id)),t.length===0?e.jsx("div",{className:"rounded-xl border border-dashed border-white/50 bg-white/40 p-4 text-center text-xs text-[var(--cli-muted-1)]",children:s("no_notifications_yet")}):null]}),e.jsxs("div",{className:"mt-4 flex items-center justify-between rounded-xl border border-white/40 bg-white/70 px-3 py-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsx("span",{children:s("browser_notifications",{permission:a??Notification.permission})}),e.jsx(X,{variant:"secondary",size:"sm",onClick:o,children:s("enable")})]})]})}const _s=[{value:"15m",label:"15m",bucket:30},{value:"1h",label:"1h",bucket:60},{value:"6h",label:"6h",bucket:300},{value:"24h",label:"24h",bucket:900},{value:"7d",label:"7d",bucket:3600}];function qo(s){const t=s.gpu?.length?s.gpu.reduce((n,i)=>n+(i.utilization_gpu??0),0)/s.gpu.length:null;return{timestamp:s.timestamp,cpu:s.cpu_percent??null,memory:s.mem_percent??null,gpu:t}}function Go(s){const t=new Date(s);return Number.isNaN(t.getTime())?s:`${t.getHours().toString().padStart(2,"0")}:${t.getMinutes().toString().padStart(2,"0")}`}function ks(s){if(typeof s=="number"&&Number.isFinite(s))return s;if(typeof s=="string"){const t=s.replace(/[^\d]/g,"");return t?Number.parseInt(t,10):null}return null}function Wo(s,t,n){if(!s||s<=0)return n("n_a");const i=t!=null?Math.max(0,t):0,l=(Math.max(0,s-i)/1024).toFixed(1),d=(s/1024).toFixed(1);return n("gpu_memory_used",{used:l,total:d})}function Ko({projectId:s,server:t,showRefreshButton:n=!1}){const{t:i}=Ie("cli"),[a,l]=r.useState("1h"),[d,o]=r.useState(!1),[c,h]=r.useState(null),[g,x]=r.useState(!1),{addToast:j}=nt(),C=ce(p=>p.telemetryByServer),k=ce(p=>p.setTelemetrySeries),v=r.useCallback(async()=>{o(!0),h(null);try{const p=_s.find(_=>_.value===a),y=await Kr(s,t.id,{range:a,bucket:p?.bucket});k(t.id,y.points)}catch{h("Unable to load telemetry.")}finally{o(!1)}},[s,t.id,k,a]),f=r.useCallback(async()=>{if(!g){x(!0);try{await Ws(s,t.id),j({type:"success",title:"Refresh requested",description:"Waiting for the CLI agent to report new hardware info."})}catch{j({type:"error",title:i("refresh_failed_title"),description:i("refresh_failed_desc")})}finally{x(!1)}}},[j,g,s,t.id,i]);r.useEffect(()=>{v()},[v]);const b=r.useMemo(()=>(C[t.id]??[]).slice(-300).map(qo),[t.id,C]),N=t.gpu_info??[];return e.jsxs("div",{className:"space-y-4",children:[e.jsx(ge,{delay:.1,duration:.45,y:12,children:e.jsxs(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:i("gpu_details")}),n?e.jsxs(X,{variant:"secondary",size:"sm",onClick:f,disabled:g,children:[e.jsx(ke,{className:ne("mr-2 h-3.5 w-3.5",g?"animate-spin":"")}),i("refresh_gpu")]}):null]}),e.jsx("div",{className:"mt-3 space-y-2 text-xs text-[var(--cli-muted-1)]",children:t.gpu_count===0?e.jsx("div",{children:i("no_gpus")}):N.length>0?N.map(p=>{const y=ks(p.memory_total_mb??p.memory_total),_=ks(p.memory_free_mb??p.memory_free);return e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("span",{children:["GPU ",p.index,": ",p.name]}),e.jsx("span",{children:Wo(y,_,i)})]},p.uuid??`${p.index}`)}):e.jsx("div",{children:i("gpu_telemetry_unavailable")})})]})}),e.jsx(ge,{delay:.12,duration:.45,y:12,children:e.jsxs(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:i("realtime_telemetry")}),e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:i("realtime_telemetry_desc")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-full border border-white/40 bg-white/60 px-1 py-1",children:_s.map(p=>{const y=a===p.value;return e.jsx("button",{type:"button",className:ne("rounded-full px-3 py-1 text-[11px] font-medium transition",y?"bg-[var(--cli-accent-emerald)] text-[var(--cli-ink-0)]":"text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)]"),onClick:()=>l(p.value),children:p.label},p.value)})}),e.jsxs(X,{variant:"secondary",size:"sm",onClick:()=>void v(),disabled:d,children:[e.jsx(ke,{className:ne("mr-2 h-3.5 w-3.5",d?"animate-spin":"")}),i("refresh")]})]})]}),e.jsx("div",{className:"mt-4 h-[240px]",children:d?e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:i("loading_telemetry")}):c?e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:c}):b.length===0?e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:i("no_telemetry")}):e.jsx(Yr,{width:"100%",height:"100%",children:e.jsxs(Xr,{data:b,children:[e.jsx(Jr,{dataKey:"timestamp",tickFormatter:Go,tick:{fontSize:10,fill:"var(--cli-muted-1)"},axisLine:{stroke:"rgba(0,0,0,0.1)"},tickLine:!1}),e.jsx(Zr,{domain:[0,100],tick:{fontSize:10,fill:"var(--cli-muted-1)"},axisLine:!1,tickLine:!1,tickFormatter:p=>`${p}%`}),e.jsx(Qr,{formatter:(p,y)=>{const _=String(y??"");if(p==null||Array.isArray(p))return[i("n_a"),_];const F=typeof p=="number"?p:Number(p);return Number.isFinite(F)?[`${Math.round(F)}%`,_]:[i("n_a"),_]},labelFormatter:p=>{const y=new Date(p);return Number.isNaN(y.getTime())?String(p):y.toLocaleString()}}),e.jsx(It,{type:"monotone",dataKey:"cpu",stroke:"var(--cli-accent-rose)",strokeWidth:2,dot:!1,name:i("cpu")}),e.jsx(It,{type:"monotone",dataKey:"memory",stroke:"var(--cli-accent-steel)",strokeWidth:2,dot:!1,name:i("memory")}),e.jsx(It,{type:"monotone",dataKey:"gpu",stroke:"var(--cli-accent-amber)",strokeWidth:2,dot:!1,name:i("gpu")})]})})})]})})]})}const Es={online:"bg-[var(--cli-status-online)] text-[var(--cli-ink-0)]",offline:"bg-[var(--cli-status-offline)] text-[var(--cli-ink-0)]",standalone:"bg-[var(--cli-status-idle)] text-[var(--cli-ink-0)]",error:"bg-[var(--cli-status-error)] text-[var(--cli-ink-0)]",idle:"bg-[var(--cli-status-idle)] text-[var(--cli-ink-0)]",busy:"bg-[var(--cli-status-busy)] text-[var(--cli-ink-0)]"};function Ts(s){if(!s)return"n/a";const t=new Date(s);return Number.isNaN(t.getTime())?"n/a":t.toLocaleString()}function Lt({label:s,value:t,suffix:n,icon:i}){const a=typeof t=="number"&&Number.isFinite(t);return e.jsxs(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-4 shadow-[0_8px_20px_rgba(20,20,20,0.08)]",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-[var(--cli-muted-1)]",children:[i?e.jsx("span",{className:"text-[var(--cli-muted-1)]",children:i}):null,e.jsx("span",{children:s})]}),e.jsxs("div",{className:"mt-2 flex items-baseline gap-1 text-lg font-semibold text-[var(--cli-ink-1)]",children:[a?e.jsx(Ki,{to:t??0,duration:.6,className:"tabular-nums"}):e.jsx("span",{children:"n/a"}),n?e.jsx("span",{className:"text-sm text-[var(--cli-muted-1)]",children:n}):null]})]})}const Yo={healthy:"bg-[var(--cli-accent-emerald)] text-[var(--cli-ink-0)]",degraded:"bg-[var(--cli-status-warning)] text-[var(--cli-ink-0)]",unhealthy:"bg-[var(--cli-status-offline)] text-[var(--cli-ink-0)]",ready:"bg-[var(--cli-accent-emerald)] text-[var(--cli-ink-0)]",not_ready:"bg-[var(--cli-status-warning)] text-[var(--cli-ink-0)]"},Xo={database:"Database",redis:"Redis",websocket:"WebSocket",cli_servers:"CLI servers"};function Jo(s){return s?s.error?s.error:typeof s.latency_ms=="number"?`${Math.round(s.latency_ms)} ms`:typeof s.active_connections=="number"?`${s.active_connections} connections`:typeof s.online_count=="number"?`${s.online_count} online`:"":""}function Zo({projectId:s,server:t,connectionStatus:n,accessLabel:i,canUnbind:a}){const l=Es[t.status]||Es.offline,d=n?.state??"disconnected",o=n?.latencyMs!=null?`${Math.round(n.latencyMs)} ms`:"n/a",c=n?.metrics,h=c?.averageReconnectTime!=null&&c.averageReconnectTime>0?`${Math.round(c.averageReconnectTime)} ms`:"n/a",[g,x]=r.useState(null),[j,C]=r.useState(!1),[k,v]=r.useState(null),[f,b]=r.useState(!1),[N,p]=r.useState(!1),{addToast:y}=nt(),_=ce(z=>z.refreshServers),F=r.useCallback(async()=>{C(!0),v(null);try{const z=await ei();x(z)}catch{v("Unable to load system health.")}finally{C(!1)}},[]),P=r.useCallback(async()=>{if(!f){b(!0);try{await Ws(s,t.id),y({type:"success",title:"Refresh requested",description:"Waiting for the CLI agent to report new hardware info."})}catch{y({type:"error",title:"Refresh failed",description:"CLI server is offline or unavailable."})}finally{b(!1)}}},[y,f,s,t.id]),V=r.useCallback(async()=>{if(!(!a||N||!window.confirm("Unbind this server? The CLI agent will disconnect and can be reconnected by logging in again."))){p(!0);try{await qs(s,t.id),await _(),y({type:"success",title:"Server unbound",description:"The CLI agent has been disconnected. Re-login to bind again."})}catch{y({type:"error",title:"Unbind failed",description:"Unable to unbind this server."})}finally{p(!1)}}},[y,a,s,_,t.id,N]);r.useEffect(()=>{F()},[F,t.id]);const G=r.useMemo(()=>g?.checks?Object.entries(g.checks).map(([z,K])=>({key:z,label:Xo[z]??z,status:K.status,detail:Jo(K)})):[],[g]);return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ge,{duration:.4,y:10,children:e.jsx(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:"Overview"}),e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:"System health, hardware, and connection telemetry."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(X,{variant:"secondary",size:"sm",onClick:()=>void F(),disabled:j,children:[e.jsx(ke,{className:ne("mr-2 h-3.5 w-3.5",j?"animate-spin":"")}),"Refresh health"]}),e.jsxs(X,{variant:"secondary",size:"sm",onClick:P,disabled:f,children:[e.jsx(ke,{className:ne("mr-2 h-3.5 w-3.5",f?"animate-spin":"")}),"Refresh GPU"]}),a?e.jsx(X,{variant:"destructive",size:"sm",onClick:()=>void V(),disabled:N,children:"Unbind server"}):null]})]})})}),e.jsx(ge,{duration:.45,y:12,children:e.jsx(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-5 shadow-[0_8px_24px_rgba(20,20,20,0.08)]",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--cli-ink-1)]",children:[e.jsx(Xs,{className:"h-4 w-4"}),e.jsx("span",{children:t.name||t.hostname}),e.jsx("span",{className:ne("rounded-full px-2 py-0.5 text-[10px] font-medium",l),children:t.status})]}),e.jsx("div",{className:"mt-1 text-xs text-[var(--cli-muted-1)]",children:t.hostname}),e.jsxs("div",{className:"mt-3 grid gap-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{children:["OS: ",t.os_info||"n/a"]}),e.jsxs("div",{children:["IP: ",t.ip_address||"n/a"]}),e.jsxs("div",{children:["Last heartbeat: ",Ts(t.last_seen_at)]})]})]}),e.jsxs("div",{className:"rounded-xl border border-white/40 bg-white/70 px-4 py-3 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Hi,{className:"h-3.5 w-3.5"}),e.jsxs("span",{children:["Socket: ",d]})]}),e.jsxs("div",{className:"mt-1",children:["Latency: ",o]}),e.jsxs("div",{className:"mt-1",children:["Buffered queue: ",n?.bufferedMessages??0]}),e.jsxs("div",{className:"mt-1",children:["Access: ",i||"n/a"]})]})]})})}),e.jsx(ge,{delay:.05,duration:.45,y:12,children:e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsx(Lt,{label:"GPU",value:t.gpu_count,suffix:"available",icon:e.jsx(ti,{className:"h-3.5 w-3.5"})}),e.jsx(Lt,{label:"Memory",value:t.memory_gb,suffix:"GB",icon:e.jsx(Pi,{className:"h-3.5 w-3.5"})}),e.jsx(Lt,{label:"Disk",value:t.disk_gb,suffix:"GB",icon:e.jsx(Ti,{className:"h-3.5 w-3.5"})})]})}),e.jsx(Ko,{projectId:s,server:t}),e.jsx(ge,{delay:.15,duration:.45,y:12,children:e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:"System health"})}),j?e.jsx("div",{className:"mt-3 text-xs text-[var(--cli-muted-1)]",children:"Checking health…"}):k?e.jsx("div",{className:"mt-3 text-xs text-[var(--cli-muted-1)]",children:k}):e.jsxs("div",{className:"mt-3 space-y-2 text-xs text-[var(--cli-muted-1)]",children:[G.map(z=>e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{children:z.label}),e.jsxs("div",{className:"flex items-center gap-2",children:[z.detail?e.jsx("span",{children:z.detail}):null,e.jsx("span",{className:ne("rounded-full px-2 py-0.5 text-[10px] font-medium",Yo[z.status]||"bg-[var(--cli-status-idle)] text-[var(--cli-ink-0)]"),children:z.status})]})]},z.key)),G.length===0?e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:"No health data available."}):null]}),e.jsxs("div",{className:"mt-3 text-[11px] text-[var(--cli-muted-1)]",children:["Last checked: ",Ts(g?.timestamp)]})]}),e.jsxs(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-4",children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:"Connection metrics"}),e.jsxs("div",{className:"mt-3 grid gap-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{children:["Reconnect attempts: ",c?.reconnectionAttempts??0]}),e.jsxs("div",{children:["Average reconnect time: ",h]}),e.jsxs("div",{children:["Messages buffered: ",c?.messagesBuffered??0]}),e.jsxs("div",{children:["Messages dropped: ",c?.messagesDropped??0]}),e.jsxs("div",{children:["Total connections: ",c?.totalConnections??0]}),e.jsxs("div",{children:["Failed connections: ",c?.failedConnections??0]})]}),n?.lastError?e.jsxs("div",{className:"mt-3 rounded-lg border border-white/40 bg-white/60 px-3 py-2 text-[11px] text-[var(--cli-muted-1)]",children:["Last error: ",n.lastError]}):null]})]})}),e.jsx(Vo,{})]})}const Rs="CLI server offline. Please ensure the CLI is running.",Qo=(s,t)=>{if(Ks.isAxiosError(s)){const n=s.response?.data?.detail??s.response?.data?.message;if(n){const i=String(n),a=i.toLowerCase();return a.includes("not connected")||a.includes("offline")?Rs:i}if(s.response?.status===503)return Rs}return s instanceof Error&&s.message?s.message:t};function el(s,t,n){const[i,a]=r.useState("/"),[l,d]=r.useState([]),[o,c]=r.useState(!1),[h,g]=r.useState(null),x=ye(n||"/"),j=r.useCallback(async(b,N=!1)=>{if(!s||!t)return;const p=ye(b);c(!0),g(null);try{const y=await si(s,t,p,N),_=y.items.map(F=>({...F,path:ye(F.path)}));d(_),a(ye(y.path||p))}catch(y){console.error("[CLI] Failed to load files:",y),g(Qo(y,"Failed to load files"))}finally{c(!1)}},[s,t]),C=r.useCallback(async(b,N)=>{if(!s||!t)return null;try{return await ni(s,t,b,N)}catch(p){return console.error("[CLI] Failed to read file:",p),null}},[s,t]),k=r.useCallback(async(b,N)=>{!s||!t||(await ri(s,t,{path:b,content:N,operation:"write"}),await j(i,!0))},[s,t,j,i]),v=r.useCallback(async(b,N=!1)=>{!s||!t||(await ii(s,t,b,N),await j(i,!0))},[s,t,j,i]),f=r.useCallback(async(b,N)=>{!s||!t||(await Hs(s,t,b,N),await j(i,!0))},[s,t,j,i]);return r.useEffect(()=>{!s||!t||j(x,!0)},[s,t,x,j]),{path:i,items:l,isLoading:o,error:h,load:j,readFile:C,writeFile:k,removeFile:v,uploadFile:f,setPath:a}}function tl({item:s,isSelected:t,isChecked:n,onToggle:i,onOpen:a,onDownload:l,onDelete:d,readOnly:o,canDownload:c,canDelete:h}){const g=s.type==="directory";return e.jsxs("div",{className:ne("flex w-full items-center justify-between rounded-lg border border-transparent px-3 py-2 text-left text-sm transition","hover:bg-white/60",t&&"border-white/70 bg-white/70"),children:[e.jsxs("button",{type:"button",onClick:()=>a(s),className:"flex flex-1 items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:!!n,onChange:()=>i?.(s),onClick:x=>x.stopPropagation(),"aria-label":`Select ${s.name}`,className:"cli-focus-ring h-3.5 w-3.5 accent-[var(--cli-accent-olive)]"}),g?e.jsx(Os,{className:"h-4 w-4"}):e.jsx(vt,{className:"h-4 w-4"}),e.jsx("span",{className:"text-[var(--cli-ink-1)]",children:s.name})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsx("span",{children:g?"Folder":Xi(s.size)}),l&&!g?e.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),c&&l(s)},disabled:!c,className:"cli-focus-ring text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)] disabled:opacity-50",title:c?"Download":"Download not allowed","aria-label":c?`Download ${s.name}`:"Download not allowed",children:e.jsx(Gt,{className:"h-3.5 w-3.5"})}):null,d?e.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),!(o||!h)&&d(s)},disabled:o||!h,className:"cli-focus-ring text-[var(--cli-muted-1)] hover:text-[var(--cli-ink-1)] disabled:opacity-50",title:o||!h?"Delete not allowed":"Delete","aria-label":o||!h?"Delete not allowed":`Delete ${s.name}`,children:e.jsx(Gs,{className:"h-3.5 w-3.5"})}):null]})]})}const Is="CLI server offline. Please ensure the CLI is running.",As=(s,t)=>{if(Ks.isAxiosError(s)){const n=s.response?.data?.detail??s.response?.data?.message;if(n){const i=String(n),a=i.toLowerCase();return a.includes("not connected")||a.includes("offline")?Is:i}if(s.response?.status===503)return Is}return s instanceof Error&&s.message?s.message:t},sl=s=>{if(!s)return"n/a";const t=new Date(s);if(Number.isNaN(t.getTime()))return"n/a";const n=Date.now()-t.getTime();return n<6e4?"just now":n<36e5?`${Math.round(n/6e4)}m ago`:n<864e5?`${Math.round(n/36e5)}h ago`:`${Math.round(n/864e5)}d ago`},nl=s=>{if(!s)return"n/a";const t=new Date(s);return Number.isNaN(t.getTime())?"n/a":t.toLocaleString()};function rl({projectId:s,serverId:t,serverRoot:n,serverStatus:i,serverLastSeenAt:a,readOnly:l,canDelete:d,canUpload:o,canDownload:c}){const{path:h,items:g,isLoading:x,error:j,load:C,uploadFile:k,removeFile:v}=el(s,t,n),f=r.useRef(null),{addToast:b}=nt(),N=ai(S=>S.openTab),[p,y]=r.useState(null),[_,F]=r.useState(null),[P,V]=r.useState(new Set),G=i==="offline"||i==="error",z=r.useMemo(()=>{const S=g.filter(w=>w.type==="file").length,u=g.filter(w=>w.type==="directory").length;return{fileCount:S,folderCount:u}},[g]),K=r.useMemo(()=>[...g].sort((S,u)=>S.type===u.type?S.name.localeCompare(u.name):S.type==="directory"?-1:1),[g]),R=r.useMemo(()=>ye(n||"/"),[n]),q=r.useMemo(()=>{if(!R||R==="/")return ye(h);if(h.startsWith(R)){const S=h.slice(R.length);return ye(S||"/")}return ye(h)},[h,R]),U=r.useCallback(S=>{if(!R||R==="/")return ye(S);const u=ye(S);return u==="/"?R:ye(`${R}/${u.replace(/^\//,"")}`)},[R]),$=r.useMemo(()=>{const S=Ji(q),w=[{label:n||`/CLI/${t}`,path:"/"}];return S.forEach((A,M)=>{w.push({label:A,path:Zi(S.slice(0,M+1))})}),w},[q,t,n]),O=r.useMemo(()=>g.filter(S=>P.has(S.path)),[g,P]),J=r.useCallback(S=>{V(u=>{const w=new Set(u);return w.has(S.path)?w.delete(S.path):w.add(S.path),w})},[]),Y=r.useCallback(S=>{const u=oi(S.name);if(u===hs.NOTEBOOK){const w=S.name.toLowerCase();if(w.endsWith(".md")||w.endsWith(".markdown")||w.endsWith(".mdx"))return u}if(S.mime_type){const w=li(S.mime_type);if(w)return w===hs.TEXT_VIEWER&&u?u:w}return u},[]),Q=r.useCallback(async S=>{if(!c)return;const u=At(S.path);if(u){b({type:"warning",title:"Download blocked",description:`Sensitive file access blocked (${u}).`});return}if(S.size&&S.size>ea){b({type:"warning",title:"Download too large",description:"This file exceeds the download limit. Use a CLI tool to fetch it."});return}try{const w=await ci(s,t,S.path),A=URL.createObjectURL(w),M=document.createElement("a");M.href=A,M.download=S.name,M.click(),URL.revokeObjectURL(A)}catch{b({type:"error",title:"Download failed",description:"Unable to download this file."})}},[b,c,s,t]),re=r.useCallback(async S=>{if(S.type==="directory"){y(null),await C(S.path,!1);return}const u=At(S.path);if(u){b({type:"warning",title:"Access blocked",description:`Sensitive file access blocked (${u}).`});return}const w=Y(S);if(!w){b({type:"warning",title:"No viewer available",description:"Download the file to view it locally."}),c&&await Q(S);return}y(S);const A=di({projectId:s,serverId:t,path:S.path}),M={updatedAt:S.modified_at??void 0,sizeBytes:S.size??void 0,mimeType:S.mime_type??void 0};N({pluginId:w,context:{type:"file",resourceId:A,resourcePath:ui({serverId:t,path:S.path,serverRoot:n??void 0}),resourceName:S.name,mimeType:S.mime_type??void 0,customData:{projectId:s,fileSource:"cli",cliServerId:t,cliPath:S.path,cliRoot:n??void 0,fileMeta:M,readOnly:l??!1,readonly:l??!1}},title:S.name})},[b,c,Q,C,N,s,l,Y,t,n]),oe=r.useCallback(()=>{C(h,!0)},[C,h]),ue=r.useCallback(()=>{l||!o||f.current?.click()},[l,o]),le=r.useCallback(async S=>{if(l||!o)return;const u=Array.from(S.target.files||[]);if(u.length===0)return;const w=ye(h);for(const A of u){if(A.size>Qi){b({type:"warning",title:"Upload too large",description:`${A.name} exceeds 1 MB and cannot be uploaded.`});continue}try{await k(A,w)}catch(M){b({type:"error",title:"Upload failed",description:As(M,"Unable to upload this file.")})}}S.target.value=""},[b,h,l,o,k]),T=r.useCallback(S=>{l||!d||F(S)},[l,d]),B=r.useCallback(async()=>{if(_){for(const S of _){const u=At(S.path);if(u){b({type:"warning",title:"Delete blocked",description:`Sensitive file access blocked (${u}).`});continue}try{await v(S.path,S.type==="directory")}catch(w){b({type:"error",title:"Delete failed",description:As(w,"Unable to delete this file.")})}}F(null),V(new Set)}},[b,_,v]);return e.jsxs("div",{className:"flex h-full flex-col gap-4",children:[e.jsx(ge,{duration:.4,y:10,children:e.jsx(te,{className:"rounded-2xl border border-white/40 bg-white/70 px-4 py-3",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:"Files"}),e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:"Browse and manage CLI server files."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(X,{variant:"secondary",size:"sm",onClick:oe,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"}),"Refresh"]}),l?null:e.jsxs(e.Fragment,{children:[e.jsxs(X,{size:"sm",onClick:ue,disabled:!o,children:[e.jsx(mi,{className:"mr-2 h-3.5 w-3.5"}),"Upload"]}),e.jsx("input",{ref:f,type:"file",multiple:!0,className:"hidden",onChange:le,"aria-label":"Upload files"})]})]})]})})}),e.jsx(ge,{duration:.4,y:10,children:e.jsx("div",{className:"flex flex-wrap items-center justify-between gap-3",children:e.jsxs(te,{className:"flex flex-wrap items-center gap-2 rounded-2xl border border-white/40 bg-white/70 px-3 py-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:"Path"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:$.map((S,u)=>e.jsxs("button",{type:"button",onClick:()=>C(U(S.path),!1),className:"cli-focus-ring rounded-full border border-white/40 bg-white/60 px-3 py-1 text-[var(--cli-ink-1)] hover:bg-white/80","aria-label":`Navigate to ${S.label}`,children:[S.label,u<$.length-1?" /":""]},S.path))}),e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-[var(--cli-muted-1)]",children:[e.jsx("span",{className:"h-1 w-1 rounded-full bg-[var(--cli-muted-2)]"}),z.folderCount," folders · ",z.fileCount," files",O.length>0?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"h-1 w-1 rounded-full bg-[var(--cli-muted-2)]"}),O.length," selected"]}):null,l?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"h-1 w-1 rounded-full bg-[var(--cli-muted-2)]"}),"Read-only"]}):null]})]})})}),G?e.jsxs("div",{className:"rounded-xl border border-white/40 bg-white/70 p-4 text-sm text-[var(--cli-muted-1)]",children:[e.jsx("div",{children:"CLI server is offline. Please ensure the CLI is running and connected."}),e.jsxs("div",{className:"mt-1 text-[11px] text-[var(--cli-muted-2)]",children:["Last heartbeat ",sl(a)," (",nl(a),")"]})]}):null,j?e.jsx("div",{className:"rounded-xl border border-white/40 bg-white/70 p-4 text-sm text-[var(--cli-muted-1)]",children:j}):null,e.jsx("div",{className:"h-full min-h-0",children:e.jsx(te,{className:"h-full rounded-2xl border border-white/40 bg-white/60 p-3",children:e.jsx(Ze,{className:"h-full",children:x?e.jsxs("div",{className:"flex items-center justify-center py-6 text-sm text-[var(--cli-muted-1)]",children:[e.jsx(Ye,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading files..."]}):e.jsxs("div",{className:"space-y-1",children:[K.map(S=>e.jsx(tl,{item:S,isSelected:p?.path===S.path,isChecked:P.has(S.path),onToggle:J,onOpen:re,onDownload:Q,onDelete:u=>T([u]),readOnly:l,canDownload:c,canDelete:d},S.path)),K.length===0?e.jsx("div",{className:"py-6 text-center text-sm text-[var(--cli-muted-1)]",children:"No files in this folder."}):null]})})})}),O.length>0?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-xl border border-white/40 bg-white/70 px-4 py-3 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("span",{children:[O.length," selected"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c?e.jsx(X,{variant:"secondary",size:"sm",onClick:()=>O.forEach(Q),children:"Download selected"}):null,d?e.jsx(X,{variant:"secondary",size:"sm",onClick:()=>T(O),children:"Delete selected"}):null,e.jsx(X,{variant:"ghost",size:"sm",onClick:()=>V(new Set),children:"Clear selection"})]})]}):null,e.jsx(Qe,{open:!!_,onOpenChange:()=>F(null),children:e.jsxs(et,{className:"cli-root max-w-md",children:[e.jsx(tt,{children:e.jsx(st,{children:"Confirm delete"})}),e.jsxs("div",{className:"space-y-2 text-sm text-[var(--cli-muted-1)]",children:[_?.map(S=>e.jsx("div",{className:"rounded-lg border border-white/40 bg-white/70 px-3 py-2",children:S.path},S.path)),e.jsx("div",{children:"This action cannot be undone."})]}),e.jsxs(Vt,{className:"gap-2",children:[e.jsx(X,{variant:"secondary",onClick:()=>F(null),children:"Cancel"}),e.jsx(X,{onClick:B,children:"Delete"})]})]})})]})}function il(s,t){const[i,a]=r.useState([]),[l,d]=r.useState(!1),[o,c]=r.useState(null),[h,g]=r.useState(0),[x,j]=r.useState(20),[C,k]=r.useState(0),v=r.useRef({}),f=r.useRef({limit:20,offset:0}),b=r.useCallback(async(y,_)=>{if(!(!s||!t)){d(!0),c(null);try{y&&(v.current=y);const F=_?.append?f.current.offset+f.current.limit:0,P=await fi(s,t,{...v.current,limit:f.current.limit,offset:F});f.current={limit:P.limit,offset:P.offset},g(P.total),j(P.limit),k(P.offset),a(V=>_?.append?[...V,...P.items]:P.items)}catch(F){console.error("[CLI] Failed to load logs:",F),c("Failed to load logs")}finally{d(!1)}}},[s,t]),N=r.useCallback(async(y,_)=>!s||!t?null:hi(s,t,y,_),[s,t]);r.useEffect(()=>{!s||!t||b()},[s,t,b]);const p=r.useCallback(async()=>{l||i.length>=h||await b(void 0,{append:!0})},[l,i.length,b,h]);return{items:i,isLoading:l,error:o,load:b,loadMore:p,total:h,limit:x,offset:C,downloadLog:N}}function Ms(s){if(!s)return"n/a";const t=new Date(s);return Number.isNaN(t.getTime())?"n/a":t.toLocaleString()}function al({log:s,onDownload:t}){return e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-xl border border-white/40 bg-white/70 px-4 py-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"text-sm font-medium text-[var(--cli-ink-1)]",children:[Ms(s.time_start)," - ",Ms(s.time_end)]}),e.jsxs("div",{className:"mt-1 text-xs text-[var(--cli-muted-1)]",children:[s.entry_count," entries · ",s.format]})]}),t?e.jsxs(X,{variant:"secondary",size:"sm",onClick:()=>t(s.id),children:[e.jsx(Gt,{className:"mr-2 h-3.5 w-3.5"}),"Download"]}):null]})}function mt(s){if(!s)return;const t=new Date(s);if(!Number.isNaN(t.getTime()))return t.toISOString()}function ol(s){if(!s)return"n/a";const t=new Date(s);return Number.isNaN(t.getTime())?"n/a":t.toLocaleString()}async function ll(s){return s?s instanceof Blob?(await s.text()).split(`
77
+ `).map(n=>n.trim()).filter(Boolean).map(n=>{try{return JSON.parse(n)}catch{return{message:n}}}):Array.isArray(s)?s:typeof s=="string"?s.split(`
78
+ `).map(t=>t.trim()).filter(Boolean).map(t=>{try{return JSON.parse(t)}catch{return{message:t}}}):typeof s=="object"&&s?[s]:[]:[]}function Ke(s){return`"${s.replace(/"/g,'""')}"`}function cl(s){const t=["timestamp","event_type","actor_user_id","level","message","payload"],n=s.map(i=>{const a=String(i.timestamp||i.ts||""),l=String(i.event_type||i.eventType||""),d=String(i.actor_user_id||i.user_id||""),o=String(i.level||i.severity||""),c=String(i.message||""),h=i.payload?JSON.stringify(i.payload):"";return[Ke(a),Ke(l),Ke(d),Ke(o),Ke(c),Ke(h)].join(",")});return[t.join(","),...n].join(`
79
+ `)}function dl({projectId:s,serverId:t,canViewAll:n}){const{items:i,isLoading:a,error:l,downloadLog:d,load:o,loadMore:c,total:h}=il(s,t),{addToast:g}=nt(),[x,j]=r.useState(""),[C,k]=r.useState(""),[v,f]=r.useState(""),[b,N]=r.useState(""),[p,y]=r.useState(""),[_,F]=r.useState([]),[P,V]=r.useState(!1),[G,z]=r.useState(null),[K,R]=r.useState(0),q=r.useRef(null),U=r.useCallback(async u=>{const w=await d(u,{download:!0});if(!w||!(w instanceof Blob))return;const A=URL.createObjectURL(w),M=document.createElement("a");M.href=A,M.download=`${u}.jsonl.gz`,M.click(),URL.revokeObjectURL(A)},[d]),$=r.useCallback(()=>{const u={},w=mt(x),A=mt(C);w&&(u.start_time=w),A&&(u.end_time=A),F([]),o(u)},[x,C,o]),O=r.useCallback(()=>{j(""),k(""),f(""),N(""),y(""),F([]),o({})},[o]),J=r.useCallback(async()=>{if(i.length!==0){V(!0),z(null);try{const u=[];for(const w of i){const A=await d(w.id,{decompress:!0}),M=await ll(A);u.push(...M)}F(u)}catch(u){console.error("[CLI] Failed to load log entries:",u),z("Failed to load log entries")}finally{V(!1)}}},[d,i]),Y=r.useMemo(()=>{const u=v.trim().toLowerCase(),w=b.trim().toLowerCase(),A=p.trim().toLowerCase(),M=mt(x),W=mt(C);return _.filter(E=>{if(u&&!String(E.event_type||E.eventType||"").toLowerCase().includes(u)||w&&!String(E.actor_user_id||E.user_id||"").toLowerCase().includes(w)||A&&!String(E.level||E.severity||"").toLowerCase().includes(A))return!1;if(M||W){const Z=E.timestamp||E.ts;if(Z){const ie=new Date(String(Z)).toISOString();if(M&&ie<M||W&&ie>W)return!1}}return!0})},[_,v,b,p,x,C]),Q=r.useCallback(u=>{if(Y.length!==0)try{const w=u==="json"?new Blob([JSON.stringify(Y,null,2)],{type:"application/json"}):new Blob([cl(Y)],{type:"text/csv"}),A=URL.createObjectURL(w),M=document.createElement("a");M.href=A,M.download=`cli-logs-${t}.${u}`,M.click(),URL.revokeObjectURL(A)}catch{g({type:"error",title:"Export failed",description:"Unable to export log entries."})}},[g,Y,t]),re=44,oe=q.current?.clientHeight??360,ue=Y.length*re,le=Math.max(0,Math.floor(K/re)-6),T=Math.min(Y.length,Math.ceil((K+oe)/re)+6),B=Y.slice(le,T),S=le*re;return a?e.jsxs("div",{className:"flex items-center justify-center py-8 text-sm text-[var(--cli-muted-1)]",children:[e.jsx(Ye,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading logs..."]}):l?e.jsx("div",{className:"rounded-xl border border-white/40 bg-white/70 p-4 text-sm text-[var(--cli-muted-1)]",children:l}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(ge,{duration:.45,y:12,children:e.jsx(te,{className:"rounded-2xl border border-white/40 bg-white/70 p-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:"Logs"}),e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:"Audit terminal, file, and system operations."})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(X,{variant:"secondary",size:"sm",onClick:()=>o(),disabled:a,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"}),"Refresh list"]})})]})})}),e.jsx(ge,{duration:.45,y:12,children:e.jsxs(te,{className:"rounded-2xl border border-white/40 bg-white/70 p-4 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:"Filters"}),e.jsxs("div",{className:"mt-1 text-[10px] text-[var(--cli-muted-1)]",children:[i.length," log objects loaded · ",h," total"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(X,{size:"sm",onClick:$,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"}),"Apply"]}),e.jsx(X,{variant:"secondary",size:"sm",onClick:O,children:"Clear"})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{htmlFor:"cli-logs-start",children:"Start"}),e.jsx("input",{id:"cli-logs-start",type:"datetime-local",value:x,onChange:u=>j(u.target.value),className:"cli-focus-ring rounded-lg border border-white/50 bg-white/70 px-2 py-1 text-xs text-[var(--cli-ink-1)]"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{htmlFor:"cli-logs-end",children:"End"}),e.jsx("input",{id:"cli-logs-end",type:"datetime-local",value:C,onChange:u=>k(u.target.value),className:"cli-focus-ring rounded-lg border border-white/50 bg-white/70 px-2 py-1 text-xs text-[var(--cli-ink-1)]"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{htmlFor:"cli-logs-event",children:"Event"}),e.jsx("input",{id:"cli-logs-event",value:v,onChange:u=>f(u.target.value),placeholder:"terminal_input",className:"cli-focus-ring rounded-lg border border-white/50 bg-white/70 px-2 py-1 text-xs text-[var(--cli-ink-1)]"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{htmlFor:"cli-logs-actor",children:"Actor"}),e.jsx("input",{id:"cli-logs-actor",value:b,onChange:u=>N(u.target.value),placeholder:n?"user id":"Admin only",disabled:!n,className:"cli-focus-ring rounded-lg border border-white/50 bg-white/70 px-2 py-1 text-xs text-[var(--cli-ink-1)] disabled:opacity-60"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{htmlFor:"cli-logs-level",children:"Level"}),e.jsx("input",{id:"cli-logs-level",value:p,onChange:u=>y(u.target.value),placeholder:"warn",className:"cli-focus-ring rounded-lg border border-white/50 bg-white/70 px-2 py-1 text-xs text-[var(--cli-ink-1)]"})]})]})]})}),e.jsx(ge,{delay:.05,duration:.45,y:12,children:e.jsxs("div",{className:"space-y-3",children:[i.map(u=>e.jsx(al,{log:u,onDownload:U},u.id)),i.length===0?e.jsx("div",{className:"rounded-xl border border-white/40 bg-white/70 p-4 text-sm text-[var(--cli-muted-1)]",children:"No logs available yet."}):null,i.length>0&&i.length<h?e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-white/40 bg-white/70 px-4 py-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("span",{children:["Showing ",i.length," of ",h," log objects"]}),e.jsx(X,{variant:"secondary",size:"sm",onClick:c,disabled:a,children:"Load more"})]}):null]})}),e.jsxs(te,{className:"rounded-2xl border border-white/40 bg-white/70 p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:"Entries"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(X,{variant:"secondary",size:"sm",onClick:J,disabled:P,children:[e.jsx(Gt,{className:"mr-2 h-3.5 w-3.5"}),"Load entries"]}),e.jsxs(X,{variant:"secondary",size:"sm",onClick:()=>Q("json"),disabled:Y.length===0,children:[e.jsx(ki,{className:"mr-2 h-3.5 w-3.5"}),"Export JSON"]}),e.jsx(X,{variant:"secondary",size:"sm",onClick:()=>Q("csv"),disabled:Y.length===0,children:"Export CSV"})]})]}),P?e.jsxs("div",{className:"mt-4 flex items-center text-sm text-[var(--cli-muted-1)]",children:[e.jsx(Ye,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading log entries..."]}):null,G?e.jsx("div",{className:"mt-4 text-sm text-[var(--cli-muted-1)]",children:G}):null,Y.length===0&&!P?e.jsx("div",{className:"mt-4 text-sm text-[var(--cli-muted-1)]",children:"Load entries to filter and export."}):null,Y.length>0?e.jsx("div",{ref:q,className:"mt-4 h-80 overflow-auto rounded-xl border border-white/40 bg-white/60",onScroll:u=>R(u.currentTarget.scrollTop),children:e.jsx("div",{style:{height:ue},className:"relative",children:e.jsx("div",{style:{transform:`translateY(${S}px)`},children:B.map((u,w)=>{const A=String(u.timestamp||u.ts||""),M=String(u.event_type||u.eventType||""),W=String(u.actor_user_id||u.user_id||""),E=String(u.level||u.severity||""),Z=u.payload?JSON.stringify(u.payload):"";return e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-white/30 px-3 py-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsx("div",{className:"min-w-[160px] text-[var(--cli-ink-1)]",children:ol(A)}),e.jsx("div",{className:"min-w-[120px] text-[var(--cli-ink-1)]",children:M||"event"}),e.jsx("div",{className:"min-w-[120px]",children:W||"n/a"}),e.jsx("div",{className:"min-w-[80px]",children:E||"n/a"}),e.jsx("div",{className:"flex-1 truncate text-[10px] text-[var(--cli-muted-1)]",children:Z||u.message||""})]},`${le+w}-${A}-${M}`)})})})}):null]})]})}function ul(s){if(!s)return"n/a";const t=new Date(s);return Number.isNaN(t.getTime())?"n/a":t.toLocaleString()}function xt(s){const t=s.toLowerCase();return t.includes("completed")||t.includes("complete")||t.includes("done")||t.includes("success")||t.includes("failed")||t.includes("error")||t.includes("cancelled")||t.includes("canceled")}function pt(s){const t=s.toLowerCase();return t.includes("failed")||t.includes("error")||t.includes("cancelled")||t.includes("canceled")}function ml(s){const t=xt(s);return pt(s)?"bg-[var(--cli-status-offline)] text-[var(--cli-ink-0)]":t?"bg-[var(--cli-accent-emerald)] text-[var(--cli-ink-0)]":"bg-[var(--cli-status-warning)] text-[var(--cli-ink-0)]"}function fl({projectId:s,serverId:t}){const[n,i]=r.useState([]),[a,l]=r.useState(!1),[d,o]=r.useState(null),c=ce(k=>k.addNotification),h=ce(k=>k.servers),g=r.useRef(new Map),x=r.useRef(!1),j=r.useRef(null),C=r.useMemo(()=>{const k=n.filter(b=>!xt(b.status)).length,v=n.filter(b=>pt(b.status)).length,f=n.filter(b=>xt(b.status)&&!pt(b.status)).length;return{running:k,failed:v,completed:f}},[n]);return r.useEffect(()=>{let k=!0;const v=async()=>{l(!0),o(null);try{const b=await xi(s,t);if(k){if(i(b),x.current){const N=h.find(p=>p.id===t)?.name||h.find(p=>p.id===t)?.hostname||"CLI server";b.forEach(p=>{const y=g.current.get(p.id);if(y&&y!==p.status&&xt(p.status)){const _=pt(p.status),F=_?"Task failed":"Task completed";c({id:crypto.randomUUID(),title:F,body:`${N}: ${p.title}`,level:_?"error":"success",createdAt:Date.now()}),rn(F,`${N}: ${p.title}`)}})}g.current=new Map(b.map(N=>[N.id,N.status])),x.current=!0}}catch{k&&o("Failed to load tasks.")}finally{k&&l(!1)}},f=window.setInterval(()=>{v()},15e3);return v(),()=>{k=!1,window.clearInterval(f)}},[s,t,h,c]),r.useEffect(()=>{if(!j.current||n.length===0||typeof window>"u"||window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;let v=!1;const f=j.current.querySelectorAll("[data-cli-task-item]");if(f.length!==0)return Ht(async()=>{const{default:b}=await import("./index-BsO46tJA.js").then(N=>N.i);return{default:b}},__vite__mapDeps([0,1,2,3,4,5])).then(({default:b})=>{v||b({targets:f,opacity:[0,1],translateY:[8,0],delay:b.stagger(50),duration:420,easing:"easeOutCubic"})}).catch(()=>{}),()=>{v=!0}},[n]),e.jsxs("div",{className:"space-y-4",children:[e.jsx(ge,{duration:.4,y:10,children:e.jsxs(te,{className:"rounded-2xl border border-white/40 bg-white/70 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--cli-ink-1)]",children:[e.jsx(Li,{className:"h-4 w-4"}),"Task overview"]}),e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-3 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"rounded-lg border border-white/40 bg-white/60 px-3 py-2",children:["Running: ",e.jsx("span",{className:"font-semibold text-[var(--cli-ink-1)]",children:C.running})]}),e.jsxs("div",{className:"rounded-lg border border-white/40 bg-white/60 px-3 py-2",children:["Completed: ",e.jsx("span",{className:"font-semibold text-[var(--cli-ink-1)]",children:C.completed})]}),e.jsxs("div",{className:"rounded-lg border border-white/40 bg-white/60 px-3 py-2",children:["Failed: ",e.jsx("span",{className:"font-semibold text-[var(--cli-ink-1)]",children:C.failed})]})]})]})}),a?e.jsxs("div",{className:"flex items-center justify-center py-8 text-sm text-[var(--cli-muted-1)]",children:[e.jsx(Ye,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading tasks..."]}):d?e.jsx(te,{className:"rounded-xl border border-white/40 bg-white/70 p-4 text-sm text-[var(--cli-muted-1)]",children:d}):n.length===0?e.jsx(te,{className:"rounded-xl border border-white/40 bg-white/70 p-4 text-sm text-[var(--cli-muted-1)]",children:"No tasks yet. Task activity will appear here once the CLI agent starts running jobs."}):e.jsx(ge,{delay:.05,duration:.4,y:10,children:e.jsx("div",{ref:j,className:"space-y-3",children:n.map(k=>e.jsxs("div",{"data-cli-task-item":!0,className:"rounded-xl border border-white/40 bg-white/70 px-4 py-3 text-sm text-[var(--cli-ink-1)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-medium",children:k.title}),e.jsx("span",{className:ne("rounded-full px-2 py-0.5 text-[10px] font-medium",ml(k.status)),children:k.status})]}),e.jsxs("div",{className:"mt-1 text-xs text-[var(--cli-muted-1)]",children:["Updated: ",ul(k.updated_at)]})]},k.id))})})]})}function hl(s){if(!s)return"n/a";const t=new Date(s);return Number.isNaN(t.getTime())?"n/a":t.toLocaleString()}function xl(s){const t=s.toLowerCase();return t.includes("high")||t.includes("critical")?"bg-[var(--cli-status-offline)] text-[var(--cli-ink-0)]":t.includes("medium")||t.includes("warn")?"bg-[var(--cli-status-warning)] text-[var(--cli-ink-0)]":"bg-[var(--cli-accent-emerald)] text-[var(--cli-ink-0)]"}function pl({projectId:s,serverId:t}){const[n,i]=r.useState([]),[a,l]=r.useState(!1),[d,o]=r.useState(null),c=r.useRef(null),h=r.useMemo(()=>{const g=n.filter(C=>{const k=C.severity.toLowerCase();return k.includes("high")||k.includes("critical")}).length,x=n.filter(C=>C.severity.toLowerCase().includes("medium")).length,j=n.length-g-x;return{high:g,medium:x,low:j}},[n]);return r.useEffect(()=>{let g=!0;return(async()=>{l(!0),o(null);try{const j=await pi(s,t);g&&i(j)}catch{g&&o("Failed to load findings.")}finally{g&&l(!1)}})(),()=>{g=!1}},[s,t]),r.useEffect(()=>{if(!c.current||n.length===0||typeof window>"u"||window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;let x=!1;const j=c.current.querySelectorAll("[data-cli-finding-item]");if(j.length!==0)return Ht(async()=>{const{default:C}=await import("./index-BsO46tJA.js").then(k=>k.i);return{default:C}},__vite__mapDeps([0,1,2,3,4,5])).then(({default:C})=>{x||C({targets:j,opacity:[0,1],translateY:[8,0],delay:C.stagger(50),duration:420,easing:"easeOutCubic"})}).catch(()=>{}),()=>{x=!0}},[n]),e.jsxs("div",{className:"space-y-4",children:[e.jsx(ge,{duration:.4,y:10,children:e.jsxs(te,{className:"rounded-2xl border border-white/40 bg-white/70 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--cli-ink-1)]",children:[e.jsx(ft,{className:"h-4 w-4"}),"Findings overview"]}),e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-3 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"rounded-lg border border-white/40 bg-white/60 px-3 py-2",children:["High: ",e.jsx("span",{className:"font-semibold text-[var(--cli-ink-1)]",children:h.high})]}),e.jsxs("div",{className:"rounded-lg border border-white/40 bg-white/60 px-3 py-2",children:["Medium: ",e.jsx("span",{className:"font-semibold text-[var(--cli-ink-1)]",children:h.medium})]}),e.jsxs("div",{className:"rounded-lg border border-white/40 bg-white/60 px-3 py-2",children:["Low: ",e.jsx("span",{className:"font-semibold text-[var(--cli-ink-1)]",children:h.low})]})]})]})}),a?e.jsxs("div",{className:"flex items-center justify-center py-8 text-sm text-[var(--cli-muted-1)]",children:[e.jsx(Ye,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading findings..."]}):d?e.jsx(te,{className:"rounded-xl border border-white/40 bg-white/70 p-4 text-sm text-[var(--cli-muted-1)]",children:d}):n.length===0?e.jsx(te,{className:"rounded-xl border border-white/40 bg-white/70 p-4 text-sm text-[var(--cli-muted-1)]",children:"No findings yet. Any detected anomalies or insights will appear here."}):e.jsx(ge,{delay:.05,duration:.4,y:10,children:e.jsx("div",{ref:c,className:"space-y-3",children:n.map(g=>e.jsxs("div",{"data-cli-finding-item":!0,className:"rounded-xl border border-white/40 bg-white/70 px-4 py-3 text-sm text-[var(--cli-ink-1)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-medium",children:g.title}),e.jsx("span",{className:ne("rounded-full px-2 py-0.5 text-[10px] font-medium",xl(g.severity)),children:g.severity})]}),e.jsxs("div",{className:"mt-1 text-xs text-[var(--cli-muted-1)]",children:["Updated: ",hl(g.updated_at)]})]},g.id))})})]})}const gl=()=>{try{return crypto.randomUUID()}catch{return`method-${Date.now()}-${Math.random().toString(16).slice(2)}`}},vl=s=>{if(!s)return"n/a";const t=new Date(s);return Number.isNaN(t.getTime())?String(s):t.toLocaleString()};function bl({projectId:s,serverId:t,canCreate:n}){const[i,a]=r.useState([]),[l,d]=r.useState(!1),[o,c]=r.useState(null),[h,g]=r.useState(""),[x,j]=r.useState(""),[C,k]=r.useState(""),[v,f]=r.useState(""),[b,N]=r.useState(!0),[p,y]=r.useState(!0),[_,F]=r.useState(null),[P,V]=r.useState(!1),[G,z]=r.useState(null),[K,R]=r.useState(null),[q,U]=r.useState(1),$=r.useRef(null),O=h.trim().length>0,J=O&&n&&!P,re=J&&p&&q===4,oe=r.useCallback(async()=>{d(!0),c(null);try{const u=await gi(s,t);a(u.methods||[])}catch{c("Unable to load methods.")}finally{d(!1)}},[s,t]),ue=r.useMemo(()=>({onMethodStatus:u=>{const w=Ae(u),A=w?.request_id;if(!$.current||A&&A!==$.current)return;const M={step:typeof w?.step=="number"?w.step:void 0,message:typeof w?.message=="string"?w.message:void 0,percent:typeof w?.percent=="number"?w.percent:void 0};R(M)},onMethodDone:u=>{const A=Ae(u)?.request_id;$.current&&(A&&A!==$.current||($.current=null,V(!1),F(null),R({step:6,message:"Method created",percent:100}),y(!1),oe()))},onMethodError:u=>{const w=Ae(u),A=w?.request_id;if(!$.current||A&&A!==$.current)return;$.current=null,V(!1),F(null);const M=typeof w?.error=="string"?w.error:"Method creation failed.";z(M),y(!1)}}),[oe]);Qs({projectId:s,serverId:t,handlers:ue}),r.useEffect(()=>{oe(),F(null),V(!1),z(null),R(null),$.current=null},[oe]),r.useEffect(()=>{if(!re){F(null);return}F(4)},[re,h,x,C,v]);const le=r.useCallback(async()=>{if(!J)return;V(!0),z(null),R({step:0,message:"Queued for creation",percent:0});const u=gl();try{const w=await vi(s,t,{session_id:u,method_name:b?void 0:x.trim()||void 0,paper_source:h.trim(),topic:C.trim()||void 0,code_source:v.trim()||void 0,auto_name:b});$.current=w.request_id||u}catch{V(!1),z("Failed to queue method creation.")}},[b,J,v,x,h,s,t,C]);r.useEffect(()=>{if(_===null)return;if(_<=0){F(null),le();return}const u=window.setTimeout(()=>{F(w=>w!=null?w-1:w)},1e3);return()=>window.clearTimeout(u)},[_,le]);const T=()=>{g(""),j(""),k(""),f(""),N(!0),y(!0),F(null),z(null),R(null),U(1)},B=r.useMemo(()=>[{label:"Paper source",ready:h.trim().length>0},{label:"Method name",ready:b||x.trim().length>0,optional:!0},{label:"Topic",ready:C.trim().length>0,optional:!0},{label:"Code repo",ready:v.trim().length>0,optional:!0}],[b,v,x,h,C]),S=Math.min(100,Math.max(0,K?.percent??0));return e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1.1fr)_minmax(0,0.9fr)]",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-6 shadow-[0_10px_24px_rgba(20,20,20,0.08)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"cli-h2 text-[var(--cli-ink-1)]",children:"Method report"}),e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:"Provide core inputs. Creation runs automatically when required fields are ready."})]}),e.jsx("div",{className:"rounded-full border border-white/50 bg-white/80 px-3 py-1 text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:"Session anchored"})]}),e.jsxs("div",{className:"mt-5 grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-xl border border-white/40 bg-white/80 px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:"Project"}),e.jsx("div",{className:"mt-1 text-sm font-semibold text-[var(--cli-ink-1)]",children:s})]}),e.jsxs("div",{className:"rounded-xl border border-white/40 bg-white/80 px-4 py-3",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:"Server"}),e.jsx("div",{className:"mt-1 text-sm font-semibold text-[var(--cli-ink-1)]",children:t})]})]})]}),e.jsx(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-6 shadow-[0_10px_24px_rgba(20,20,20,0.08)]",children:e.jsxs(Yi,{initialStep:q,onStepChange:U,onFinalStepCompleted:()=>void le(),backButtonText:"Previous",nextButtonText:(u,w)=>u>=w?P?"Creating...":"Create method":"Next",nextDisabled:(u,w)=>u===1?!O:u>=w?!J:!1,backDisabled:()=>P,children:[e.jsx(lt,{title:"Paper source",description:"Provide a PDF/MD path or a URL.",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-[var(--cli-muted-1)]",children:[e.jsx("span",{children:"Required input"}),e.jsx("span",{className:"rounded-full border border-white/60 bg-white/70 px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--cli-status-busy)]",children:"Required"})]}),e.jsx("input",{value:h,onChange:u=>g(u.target.value),placeholder:"https://arxiv.org/abs/0000.00000 or /path/to/paper.pdf",className:"cli-focus-ring w-full rounded-lg border border-white/40 bg-white/80 px-3 py-2 text-sm text-[var(--cli-ink-1)] outline-none"}),e.jsx("p",{className:"text-xs text-[var(--cli-muted-1)]",children:"Links to arxiv/openreview are parsed automatically."})]})}),e.jsx(lt,{title:"Method identity",description:"Supply a name or let the model derive one.",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-[var(--cli-muted-1)]",children:[e.jsx("span",{children:"Optional input"}),e.jsx("span",{className:"rounded-full border border-white/60 bg-white/70 px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:"Optional"})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_auto]",children:[e.jsx("input",{value:x,onChange:u=>{const w=u.target.value;j(w),w.trim()&&N(!1)},placeholder:"Contrastive Ablation Method",disabled:b,className:ne("cli-focus-ring w-full rounded-lg border border-white/40 bg-white/80 px-3 py-2 text-sm text-[var(--cli-ink-1)] outline-none",b&&"opacity-60")}),e.jsxs("label",{className:"flex items-center gap-2 rounded-lg border border-white/40 bg-white/80 px-3 py-2 text-xs text-[var(--cli-muted-1)]",children:[e.jsx("input",{type:"checkbox",checked:b,onChange:u=>{const w=u.target.checked;N(w),w&&j("")},className:"h-4 w-4 accent-[var(--cli-accent-olive)]"}),"Auto-name"]})]})]})}),e.jsx(lt,{title:"Focus and code",description:"Optionally narrow scope or point to code.",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:"Topic"}),e.jsx("input",{value:C,onChange:u=>k(u.target.value),placeholder:"Transformer pruning / Diffusion speedup",className:"cli-focus-ring mt-2 w-full rounded-lg border border-white/40 bg-white/80 px-3 py-2 text-sm text-[var(--cli-ink-1)] outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:"Code repo or path"}),e.jsx("input",{value:v,onChange:u=>f(u.target.value),placeholder:"https://github.com/org/repo or /path/to/code",className:"cli-focus-ring mt-2 w-full rounded-lg border border-white/40 bg-white/80 px-3 py-2 text-sm text-[var(--cli-ink-1)] outline-none"})]})]})}),e.jsx(lt,{title:"Run controls",description:"Review the report and submit.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 text-xs text-[var(--cli-muted-1)]",children:[e.jsx("span",{children:"Auto-run begins on the final step."}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:p,onChange:u=>y(u.target.checked),className:"h-4 w-4 accent-[var(--cli-accent-olive)]"}),"Auto-run enabled"]})]}),_!==null&&re?e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-white/40 bg-white/80 px-4 py-3 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Bi,{className:"h-4 w-4 text-[var(--cli-muted-1)]"}),"Auto-creating in ",_,"s"]}),e.jsx(X,{variant:"secondary",size:"sm",onClick:()=>F(null),children:"Cancel"})]}):null,e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(X,{variant:"secondary",onClick:T,disabled:P,children:"Reset"}),n?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--cli-status-error)]",children:[e.jsx(ft,{className:"h-4 w-4"}),"You do not have permission to create methods."]})]}),G?e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--cli-status-error)]",children:[e.jsx(ft,{className:"h-4 w-4"}),G]}):null]})})]})})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-6 shadow-[0_10px_24px_rgba(20,20,20,0.08)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:"Checklist"}),e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:"Required vs optional inputs"})]}),e.jsx("span",{className:"rounded-full border border-white/50 bg-white/80 px-3 py-1 text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:"Report status"})]}),e.jsx("div",{className:"mt-4 space-y-2 text-xs",children:B.map(u=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-white/40 bg-white/80 px-3 py-2",children:[e.jsx("span",{className:"text-[var(--cli-ink-1)]",children:u.label}),e.jsxs("span",{className:ne("flex items-center gap-1 text-[10px] uppercase tracking-wide",u.ready?"text-[var(--cli-status-online)]":"text-[var(--cli-muted-1)]"),children:[u.ready?e.jsx(Vs,{className:"h-3 w-3"}):null,u.optional?"Optional":"Required"]})]},u.label))})]}),e.jsxs(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-6 shadow-[0_10px_24px_rgba(20,20,20,0.08)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:"Creation status"}),e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:"Live progress from the CLI agent"})]}),e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:P?"Running":"Idle"})]}),e.jsxs("div",{className:"mt-4 rounded-xl border border-white/40 bg-white/80 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs text-[var(--cli-muted-1)]",children:[e.jsx("span",{children:K?.message||"Awaiting input"}),e.jsx("span",{children:K?.percent?`${K?.percent}%`:"0%"})]}),e.jsx("div",{className:"mt-3 h-2 w-full rounded-full bg-white/60",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--cli-accent-olive)] transition-all",style:{width:`${S}%`}})}),K?.step?e.jsxs("div",{className:"mt-2 text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:["Step ",K.step]}):null]})]}),e.jsxs(te,{className:"cli-card rounded-2xl border border-white/40 bg-white/70 p-6 shadow-[0_10px_24px_rgba(20,20,20,0.08)]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:"Methods"}),e.jsx("div",{className:"text-xs text-[var(--cli-muted-1)]",children:"Registered methods for this project"})]}),e.jsxs(X,{variant:"secondary",size:"sm",onClick:oe,disabled:l,children:[e.jsx(ke,{className:ne("mr-2 h-4 w-4",l&&"animate-spin")}),"Refresh"]})]}),l?e.jsx("div",{className:"mt-6 flex items-center justify-center text-xs text-[var(--cli-muted-1)]",children:"Loading methods..."}):o?e.jsxs("div",{className:"mt-6 flex items-center gap-2 text-xs text-[var(--cli-status-error)]",children:[e.jsx(ft,{className:"h-4 w-4"}),o]}):i.length===0?e.jsxs("div",{className:"mt-6 flex flex-col items-center gap-2 rounded-xl border border-dashed border-white/40 bg-white/60 px-4 py-6 text-xs text-[var(--cli-muted-1)]",children:[e.jsx(vt,{className:"h-5 w-5"}),"No methods recorded yet."]}):e.jsx("div",{className:"mt-4 space-y-3",children:i.map(u=>{const w=u.method_name||u.method_slug||u.method_id||"Method",A=u.status||"created";return e.jsxs("div",{className:"rounded-xl border border-white/40 bg-white/80 px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:w}),e.jsx("div",{className:"text-[11px] text-[var(--cli-muted-1)]",children:u.method_id||"unknown id"})]}),e.jsx("span",{className:"rounded-full border border-white/50 bg-white/90 px-2 py-1 text-[10px] uppercase tracking-wide text-[var(--cli-muted-1)]",children:A})]}),e.jsxs("div",{className:"mt-2 grid gap-1 text-xs text-[var(--cli-muted-1)]",children:[e.jsxs("div",{children:["Paper: ",u.paper?.source||"n/a"]}),e.jsxs("div",{children:["Code: ",u.code?.source||"n/a"]}),e.jsxs("div",{children:["Created: ",vl(u.created_at)]})]})]},u.method_id||u.method_slug||w)})})]})]})]})}function wl(s){return s?s==="owner"?"owner":s==="admin"?"admin":s==="editor"?"edit":s==="viewer"?"view":"none":"none"}function yl(s,t){const n=t?.allowTerminalInput??!0,i=t?.allowFileEdit??!0;return{...{view_server_status:s!=="none",view_terminal_output:s!=="none",view_operation_logs:s!=="none",view_files:s!=="none",view_tasks:s!=="none",view_findings:s!=="none"},...{terminal_input:s!=="none"&&s!=="view"&&n,file_upload:s!=="none"&&s!=="view"&&i,file_download:s==="admin"||s==="owner"||s==="edit"&&i,file_edit:s!=="none"&&s!=="view"&&i,file_delete:s!=="none"&&s!=="view"&&i},...{manage_sessions:s==="admin"||s==="owner",manage_permissions:s==="admin"||s==="owner",disconnect_server:s==="admin"||s==="owner",view_all_user_logs:s==="admin"||s==="owner",delete_server:s==="owner"}}}function Nl(s){const{projectId:t,serverId:n,readOnly:i}=s,[a,l]=r.useState("none"),[d,o]=r.useState(null),[c,h]=r.useState(!1),[g,x]=r.useState(null);r.useEffect(()=>{if(!t||!n){l("none"),o(null);return}if(i){l("view"),o(null);return}let C=!1;return h(!0),x(null),(async()=>{try{const v=await bi(t);if(C)return;const f=wl(v?.role);l(f),o(null)}catch{if(C)return;l("none"),o(null),x("Failed to resolve CLI permissions")}finally{C||h(!1)}})(),()=>{C=!0}},[t,i,n]);const j=r.useMemo(()=>yl(a,d),[a,d]);return{permission:a,granularity:d,capabilities:j,isLoading:c,error:g}}const Sl=s=>s==="offline"||s==="error",jl=s=>{if(!s)return"n/a";const t=new Date(s);if(Number.isNaN(t.getTime()))return"n/a";const n=Date.now()-t.getTime();return n<6e4?"just now":n<36e5?`${Math.round(n/6e4)}m ago`:n<864e5?`${Math.round(n/36e5)}h ago`:`${Math.round(n/864e5)}d ago`},Cl=s=>{if(!s)return"n/a";const t=new Date(s);return Number.isNaN(t.getTime())?"n/a":t.toLocaleString()};function Al({context:s,setTitle:t}){const{t:n}=Ie("cli"),i=wi("cli.connect"),a=s.customData,l=typeof a?.projectId=="string"?a.projectId:void 0,d=!!(a?.readOnly||a?.readonly),[o,c]=r.useState(!1),[h,g]=r.useState("overview"),[x,j]=r.useState(!0),C=ce(U=>U.servers),k=ce(U=>U.activeServerId),v=ce(U=>U.isLoading),f=ce(U=>U.loadServers),b=ce(U=>U.connectionStatus),{ensureConversation:N}=Fo();r.useEffect(()=>{t("CLI")},[t]),r.useEffect(()=>{l&&f(l)},[l,f]),r.useEffect(()=>{l&&N(l)},[l,N]);const p=r.useMemo(()=>C.find(U=>U.id===k),[C,k]),y=p?Sl(p.status):!1,_=Nl({projectId:l,serverId:p?.id??null,readOnly:d}),F=_.permission==="admin"||_.permission==="owner",P=_.capabilities.terminal_input,V=_.capabilities.file_edit,G=_.capabilities.file_delete,z=_.capabilities.file_upload,K=_.capabilities.file_download,R=_.capabilities.disconnect_server,q=r.useMemo(()=>{const U=[{value:"methods",label:n("tab_methods")},{value:"terminal",label:n("tab_terminal")},{value:"files",label:n("tab_files")},{value:"logs",label:n("tab_logs")},{value:"tasks",label:n("tab_tasks")},{value:"findings",label:n("tab_findings")}];return U.push({value:"overview",label:n("tab_overview")}),U},[n]);return l?!i.isEntitlementLoading&&!i.isMaxEntitled?e.jsx("div",{className:"cli-root flex h-full items-center justify-center",children:e.jsxs("div",{className:"rounded-2xl border border-white/40 bg-white/70 px-4 py-3 text-center",children:[e.jsx("div",{className:"text-sm font-semibold text-[var(--cli-ink-1)]",children:n("plan_access_required")}),e.jsx("div",{className:"mt-1 text-xs text-[var(--cli-muted-1)]",children:n("max_only_desc")})]})}):v?e.jsx("div",{className:"cli-root flex h-full items-center justify-center",children:e.jsx(Ye,{className:"h-6 w-6 animate-spin text-[var(--cli-muted-1)]"})}):e.jsxs("div",{className:"cli-root relative flex h-full overflow-hidden",children:[e.jsx(yi,{animated:!1}),e.jsx("div",{className:`shrink-0 border-r border-white/40 bg-[var(--cli-bg-1)] transition-all ${x?"w-16":"w-72"}`,children:e.jsx(ia,{readOnly:!F,onBind:()=>c(!0),collapsed:x,onToggleCollapse:()=>j(U=>!U),tabs:q,activeTab:h,onTabChange:U=>g(U)})}),e.jsx("div",{className:"relative flex flex-1 flex-col bg-[var(--cli-bg-0)]",children:p?e.jsx(e.Fragment,{children:e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden px-6 pb-4 pt-6",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[y?e.jsxs("div",{className:"mb-3 rounded-xl border border-white/40 bg-white/70 px-4 py-3 text-sm text-[var(--cli-muted-1)]",children:[e.jsx("div",{className:"font-semibold text-[var(--cli-ink-1)]",children:n("cli_server_disconnected")}),e.jsx("div",{className:"mt-1 text-[11px] text-[var(--cli-muted-2)]",children:n("last_heartbeat",{relative:jl(p.last_seen_at),timestamp:Cl(p.last_seen_at)})})]}):null,h==="terminal"?e.jsx("div",{className:"flex-1 min-h-0 cli-tab-enter",children:e.jsx(Bo,{projectId:l,server:p,readOnly:!P,canUnbind:R})},h):e.jsx(Ze,{className:"flex-1 min-h-0 pr-2",children:e.jsxs("div",{className:"h-full min-h-0 cli-tab-enter",children:[h==="overview"?e.jsx(Zo,{projectId:l,server:p,connectionStatus:b,accessLabel:_.permission,canUnbind:R}):null,h==="methods"?e.jsx(bl,{projectId:l,serverId:p.id,canCreate:V}):null,h==="files"?e.jsx(rl,{projectId:l,serverId:p.id,serverRoot:p.server_root,serverStatus:p.status,serverLastSeenAt:p.last_seen_at,readOnly:!V,canDelete:G,canUpload:z,canDownload:K}):null,h==="logs"?e.jsx(dl,{projectId:l,serverId:p.id,canViewAll:_.capabilities.view_all_user_logs}):null,h==="tasks"?e.jsx(fl,{projectId:l,serverId:p.id}):null,h==="findings"?e.jsx(pl,{projectId:l,serverId:p.id}):null]},h)})]})})}):e.jsx("div",{className:"flex h-full items-center justify-center p-6",children:C.length===0?e.jsx(zo,{onBind:()=>c(!0)}):e.jsx("p",{className:"text-[var(--cli-muted-1)]",children:n("select_server_from_list")})})}),e.jsx(Ho,{open:o,onOpenChange:c})]}):e.jsx("div",{className:"cli-root flex h-full items-center justify-center",children:e.jsx("p",{className:"text-[var(--cli-muted-1)]",children:n("no_project_selected")})})}export{Al as default};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/plugin-monaco-C8UgLomw.js","assets/plugin-terminal-MXFIPun8.js"])))=>i.map(i=>d[i]);
2
+ import{D as se,U as ne,Q as J,aa as re,J as Y,j as m,b as L,L as H,Z as ie,ab as ae,R as oe,a4 as ce,_ as de}from"./index-CHzJ2xtB.js";import{R as b}from"./plugin-monaco-C8UgLomw.js";import{a as le}from"./file-socket-DA5XIx88.js";import{c as ue}from"./monaco-CiHMMNH_.js";import{u as ye,F as fe}from"./file-diff-panel-DsvyRz47.js";import"./plugin-notebook-JRhysCqj.js";import"./plugin-terminal-MXFIPun8.js";function me({dbName:r,version:n,storeName:i}){return new Promise((a,e)=>{const s=indexedDB.open(r,n);s.onupgradeneeded=()=>{const t=s.result;t.objectStoreNames.contains(i)||t.createObjectStore(i)},s.onsuccess=()=>a(s.result),s.onerror=()=>e(s.error??new Error("Failed to open IndexedDB"))})}function X(r){return new Promise((n,i)=>{r.onsuccess=()=>n(r.result),r.onerror=()=>i(r.error??new Error("IndexedDB request failed"))})}function pe(r){let n=null;const i=()=>(n||(n=me(r)),n),a=async(e,s)=>{const t=await i();return await new Promise((o,d)=>{const u=t.transaction(r.storeName,e),h=u.objectStore(r.storeName);Promise.resolve(s(h)).then(l=>{l instanceof IDBRequest?X(l).then(o).catch(d):o(l)}).catch(d),u.onabort=()=>d(u.error??new Error("IndexedDB transaction aborted"))})};return{async get(e){return await a("readonly",s=>s.get(e))},async set(e,s){await a("readwrite",t=>t.put(s,e))},async del(e){await a("readwrite",s=>s.delete(e))},async keys(){const t=(await i()).transaction(r.storeName,"readonly").objectStore(r.storeName);return(await X(t.getAllKeys())).map(String)}}}const ve=1*1024*1024,$=20*1024*1024;function D(r,n){return`${r}:${n}`}function x(r){try{return new TextEncoder().encode(r).byteLength}catch{return r.length}}function M(r){return(r.sizeBytes??x(r.content))<=ve}const j=pe({dbName:"ds-file-cache",version:1,storeName:"files"}),S=se((r,n)=>({entries:{},totalBytes:0,loadingKeys:{},getKey:D,getEntry:(i,a)=>n().entries[D(i,a)],ensureLoaded:async({projectId:i,fileId:a,updatedAt:e,mimeType:s,sizeBytes:t})=>{const o=D(i,a),d=n().entries[o],u=l=>r(f=>({loadingKeys:{...f.loadingKeys,[o]:l}})),h=l=>(r(f=>{const v=f.entries[o],A=v?v.sizeBytes??x(v.content):0,g=l.sizeBytes??x(l.content);return{entries:{...f.entries,[o]:{...l,key:o}},totalBytes:Math.max(0,f.totalBytes-A+g)}}),n().evictIfNeeded(),n().entries[o]);if(d){if(d.isDirty)return n().touch({projectId:i,fileId:a}),d;if(!(d.updatedAt&&e&&d.updatedAt!==e))return n().touch({projectId:i,fileId:a}),d}u(!0);try{const l=await j.get(o);if(l){const g={key:o,projectId:l.projectId,fileId:l.fileId,mimeType:l.mimeType,sizeBytes:l.sizeBytes??x(l.content),updatedAt:l.updatedAt,content:l.content,isDirty:l.isDirty,saveState:"idle",conflict:void 0,lastAccessedAt:Date.now(),lastSavedAt:l.lastSavedAt,saveError:void 0};if(!(e&&g.updatedAt&&g.updatedAt!==e&&!g.isDirty))return h(g)}const f=await J(a),v=t??x(f),A=h({projectId:i,fileId:a,mimeType:s,sizeBytes:v,updatedAt:e,content:f,isDirty:!1,saveState:"idle",saveError:void 0,conflict:void 0,lastAccessedAt:Date.now(),lastSavedAt:void 0});if(M(A)){const g={v:1,projectId:i,fileId:a,mimeType:s,sizeBytes:A.sizeBytes,updatedAt:A.updatedAt,content:A.content,isDirty:A.isDirty,lastAccessedAt:A.lastAccessedAt,lastSavedAt:A.lastSavedAt,conflict:A.conflict};await j.set(o,g)}return A}finally{u(!1)}},reload:async({projectId:i,fileId:a,updatedAt:e,mimeType:s,sizeBytes:t,ignoreDirty:o})=>{const d=D(i,a),u=n().entries[d];if(u?.isDirty&&!o)return n().touch({projectId:i,fileId:a}),u;const h=l=>r(f=>({loadingKeys:{...f.loadingKeys,[d]:l}}));h(!0);try{const l=await J(a),f=t??x(l);return n().applyServerSnapshot({projectId:i,fileId:a,content:l,updatedAt:e,sizeBytes:f,mimeType:s}),n().entries[d]}finally{h(!1)}},setContent:({projectId:i,fileId:a,content:e})=>{const s=D(i,a),t=Date.now();r(d=>{const u=d.entries[s],h=x(e),l=u?u.sizeBytes??x(u.content):0,f={key:s,projectId:i,fileId:a,mimeType:u?.mimeType,sizeBytes:h,updatedAt:u?.updatedAt,content:e,isDirty:!0,saveState:u?.saveState??"idle",saveError:void 0,conflict:u?.conflict,lastAccessedAt:t,lastSavedAt:u?.lastSavedAt};return{entries:{...d.entries,[s]:f},totalBytes:Math.max(0,d.totalBytes-l+h)}});const o=n().entries[s];if(o&&M(o)){const d={v:1,projectId:i,fileId:a,mimeType:o.mimeType,sizeBytes:o.sizeBytes,updatedAt:o.updatedAt,content:o.content,isDirty:o.isDirty,lastAccessedAt:o.lastAccessedAt,lastSavedAt:o.lastSavedAt,conflict:o.conflict};j.set(s,d).catch(()=>{})}},touch:({projectId:i,fileId:a})=>{const e=D(i,a);r(s=>{const t=s.entries[e];return t?{entries:{...s.entries,[e]:{...t,lastAccessedAt:Date.now()}}}:s})},save:async({projectId:i,fileId:a})=>{const e=D(i,a),s=n().entries[e];if(!s)return await n().ensureLoaded({projectId:i,fileId:a});r(t=>({entries:{...t.entries,[e]:{...t.entries[e],saveState:"saving",saveError:void 0}}}));try{const o=(await ne(a,s.content)).updated_at,d={...n().entries[e],isDirty:!1,saveState:"idle",updatedAt:o,lastSavedAt:Date.now(),saveError:void 0,conflict:void 0};if(r(u=>({entries:{...u.entries,[e]:d}})),M(d)){const u={v:1,projectId:i,fileId:a,mimeType:d.mimeType,sizeBytes:d.sizeBytes,updatedAt:d.updatedAt,content:d.content,isDirty:d.isDirty,lastAccessedAt:d.lastAccessedAt,lastSavedAt:d.lastSavedAt,conflict:d.conflict};await j.set(e,u)}return d}catch(t){const o=t instanceof Error?t.message:"Save failed";return r(d=>({entries:{...d.entries,[e]:{...d.entries[e],saveState:"error",saveError:o}}})),n().entries[e]}},applyServerSnapshot:({projectId:i,fileId:a,content:e,updatedAt:s,sizeBytes:t,mimeType:o,keepDirty:d})=>{const u=D(i,a),h=Date.now();r(f=>{const v=f.entries[u],A=v?v.sizeBytes??x(v.content):0,g=t??x(e),C={key:u,projectId:i,fileId:a,mimeType:o??v?.mimeType,sizeBytes:g,updatedAt:s??v?.updatedAt,content:e,isDirty:d?!!v?.isDirty:!1,saveState:"idle",saveError:void 0,conflict:void 0,lastAccessedAt:h,lastSavedAt:d?v?.lastSavedAt:h};return{entries:{...f.entries,[u]:C},totalBytes:Math.max(0,f.totalBytes-A+g)}});const l=n().entries[u];if(l&&M(l)){const f={v:1,projectId:i,fileId:a,mimeType:l.mimeType,sizeBytes:l.sizeBytes,updatedAt:l.updatedAt,content:l.content,isDirty:l.isDirty,lastAccessedAt:l.lastAccessedAt,lastSavedAt:l.lastSavedAt,conflict:void 0};j.set(u,f).catch(()=>{})}},evictIfNeeded:()=>{const{totalBytes:i,entries:a}=n();if(i<=$)return;const e=Object.values(a).slice().sort((o,d)=>o.lastAccessedAt-d.lastAccessedAt);let s=i;const t={...a};for(const o of e){if(s<=$)break;if(o.isDirty)continue;const d=o.sizeBytes??x(o.content);delete t[o.key],s-=d}s!==i&&r({entries:t,totalBytes:Math.max(0,s)})}}));function he(r,n){const i=r&&n?D(r,n):null;return S(a=>i?!!a.loadingKeys[i]:!1)}const be=ce(()=>de(()=>import("./plugin-monaco-C8UgLomw.js").then(r=>r.i),__vite__mapDeps([0,1])),{});ue();function Ae(r){const n=r.toLowerCase();return n.endsWith(".py")||n.endsWith(".pyw")||n.endsWith(".pyi")?"python":n.endsWith(".json")||n.endsWith(".jsonc")||n.endsWith(".json5")?"json":n.endsWith(".ts")||n.endsWith(".tsx")||n.endsWith(".mts")?"typescript":n.endsWith(".js")||n.endsWith(".jsx")||n.endsWith(".mjs")?"javascript":n.endsWith(".md")||n.endsWith(".markdown")?"markdown":n.endsWith(".yaml")||n.endsWith(".yml")?"yaml":n.endsWith(".html")||n.endsWith(".htm")?"html":n.endsWith(".css")||n.endsWith(".scss")||n.endsWith(".sass")?"css":"plaintext"}function we(){const[r,n]=b.useState(()=>typeof document>"u"?!1:document.documentElement.classList.contains("dark"));return b.useEffect(()=>{const i=document.documentElement,a=new MutationObserver(()=>{n(i.classList.contains("dark"))});return a.observe(i,{attributes:!0,attributeFilter:["class"]}),()=>a.disconnect()},[]),r}function ge(r,n,i){b.useEffect(()=>{const a=window.setTimeout(r,i);return()=>window.clearTimeout(a)},[...n,i])}function Te({context:r,tabId:n,setDirty:i,setTitle:a}){const e=r.customData?.projectId??void 0,s=r.customData?.fileMeta??void 0,t=r.resourceId,o=re(t),d=r.resourcePath??void 0,u=r.resourceName||r.resourcePath||"Untitled",h=b.useMemo(()=>Ae(u),[u]),l=we(),f=S(c=>c.ensureLoaded),v=S(c=>c.reload),A=S(c=>c.save),g=S(c=>c.setContent),C=S(c=>c.applyServerSnapshot),P=e&&t?S.getState().getKey(e,t):null,y=S(c=>P?c.entries[P]:void 0),K=he(e,t??void 0),N=Y(c=>c.updateFileMeta),{diffEvent:z,clearDiff:Q}=ye({fileId:t,filePath:d,projectId:e}),_=b.useRef(null),R=b.useRef(null),T=b.useRef(!1),[Z,F]=b.useState(!1);b.useEffect(()=>{a(u)},[u,a]),b.useEffect(()=>{!e||!t||f({projectId:e,fileId:t,updatedAt:s?.updatedAt,mimeType:r.mimeType??s?.mimeType,sizeBytes:s?.sizeBytes}).catch(c=>{console.error("[CodeEditorPlugin] Failed to load file:",c)})},[e,t,f,s?.updatedAt,s?.mimeType,s?.sizeBytes,r.mimeType]),b.useEffect(()=>{if(!e||!t||o)return;const{socket:c,release:w}=le();R.current={socket:c,release:w};const p=async()=>{if(!T.current&&c.connected)try{T.current=!0,await c.emitWithAck("file:join",{projectId:e,fileId:t,clientVersion:"1.0.0"}),F(!0)}catch(k){console.warn("[CodeEditorPlugin] file:join failed:",k)}},B=()=>{F(!0),p()},E=()=>{F(!1),T.current=!1},O=k=>{if(k?.fileId!==t)return;const te=S.getState().getKey(e,t),U=S.getState().entries[te];U?.isDirty||(C({projectId:e,fileId:t,content:String(k?.content??""),updatedAt:String(k?.updatedAt??""),sizeBytes:typeof k?.size=="number"?k.size:void 0,mimeType:U?.mimeType}),N(t,{updatedAt:String(k?.updatedAt??""),size:typeof k?.size=="number"?k.size:void 0}))};return c.on("connect",B),c.on("disconnect",E),c.on("file:content-updated",O),c.connected&&p(),()=>{try{c.off("connect",B),c.off("disconnect",E),c.off("file:content-updated",O),T.current&&c.emit("file:leave",{projectId:e,fileId:t})}finally{T.current=!1,F(!1),R.current=null,w()}}},[e,t,o]),b.useEffect(()=>{i(!!y?.isDirty)},[y?.isDirty,i]);const W=b.useCallback(async()=>{if(!e||!t||!y)return;try{const p=S.getState().getKey(e,t);S.setState(B=>{const E=B.entries[p];return E?{entries:{...B.entries,[p]:{...E,saveState:"saving",saveError:void 0}}}:B})}catch{}const c=R.current?.socket;if(!o&&c&&c.connected&&T.current)try{const p=await c.emitWithAck("file:update-content",{projectId:e,fileId:t,content:y.content});if("error"in p)throw new Error(p.error.message);C({projectId:e,fileId:t,content:y.content,updatedAt:p.data.updatedAt,sizeBytes:typeof p.data.size=="number"?p.data.size:y.sizeBytes,mimeType:y.mimeType}),o||N(t,{updatedAt:p.data.updatedAt,size:typeof p.data.size=="number"?p.data.size:void 0,mimeType:y.mimeType});return}catch(p){console.warn("[CodeEditorPlugin] realtime save failed, fallback to HTTP:",p)}const w=await A({projectId:e,fileId:t});!o&&w.updatedAt&&N(t,{updatedAt:w.updatedAt,size:w.sizeBytes,mimeType:w.mimeType})},[C,y,t,o,e,A,N]);ge(()=>{!e||!t||!y?.isDirty||y.saveState!=="saving"&&W()},[e,t,y?.content,y?.isDirty],650),b.useEffect(()=>{if(!e||!t)return;const c=w=>{(w.ctrlKey||w.metaKey)&&w.key.toLowerCase()==="s"&&(w.preventDefault(),W())};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[e,t,W]);const q=b.useMemo(()=>y?y.saveState==="saving"?"Saving…":y.saveState==="error"?y.saveError||"Save failed":y.isDirty?"Unsaved":"Saved":"",[y]),G=!!e&&!!t&&!!y&&!K,V=h==="json",I=async()=>{const c=_.current;if(c)try{await c.getAction("editor.action.formatDocument").run()}catch(w){console.warn("[CodeEditorPlugin] Format failed:",w)}},ee=b.useCallback(async()=>{if(!e||!t||y?.isDirty&&!window.confirm("Discard unsaved changes and reload from server?"))return;const c=Y.getState().findNode(t),w=c?.updatedAt??s?.updatedAt,p=c?.size??s?.sizeBytes,B=c?.mimeType??r.mimeType??s?.mimeType;try{await v({projectId:e,fileId:t,updatedAt:w,sizeBytes:p,mimeType:B,ignoreDirty:!0})}catch(E){console.warn("[CodeEditorPlugin] Reload failed:",E)}},[e,t,y?.isDirty,s?.updatedAt,s?.sizeBytes,s?.mimeType,r.mimeType,v]);return b.useEffect(()=>{z?.diff&&(!e||!t||z.changeType!=="delete"&&(y?.isDirty||v({projectId:e,fileId:t,mimeType:r.mimeType??s?.mimeType,sizeBytes:s?.sizeBytes,updatedAt:s?.updatedAt,ignoreDirty:!0})))},[z,y?.isDirty,e,t,r.mimeType,s?.mimeType,s?.sizeBytes,s?.updatedAt,v]),!e||!t?m.jsx("div",{className:"h-full flex items-center justify-center text-sm text-muted-foreground",children:"No file selected."}):m.jsxs("div",{className:"flex flex-col h-full bg-background",children:[m.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/60 bg-white/60 backdrop-blur dark:bg-black/30",children:[m.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[m.jsx("div",{className:"truncate text-sm font-medium",children:u}),m.jsx("span",{className:"text-[11px] px-2 py-0.5 rounded bg-black/[0.06] dark:bg-white/[0.08] text-muted-foreground uppercase",children:h})]}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsxs("span",{className:L("text-xs",y?.saveState==="error"?"text-red-600":"text-muted-foreground"),title:y?.saveError,children:[q,!o&&!Z?" (offline)":""]}),m.jsxs("button",{type:"button",className:L("inline-flex items-center gap-1.5 text-xs px-2.5 py-1.5 rounded-md","border border-black/10 bg-white hover:bg-black/[0.03]","dark:border-white/10 dark:bg-white/[0.04] dark:hover:bg-white/[0.07]",!G&&"opacity-60 pointer-events-none"),onClick:()=>void W(),title:"Save (Ctrl/Cmd+S)",children:[y?.saveState==="saving"?m.jsx(H,{className:"h-3.5 w-3.5 animate-spin"}):m.jsx(ie,{className:"h-3.5 w-3.5"}),"Save"]}),V?m.jsxs("button",{type:"button",className:L("inline-flex items-center gap-1.5 text-xs px-2.5 py-1.5 rounded-md","border border-black/10 bg-white hover:bg-black/[0.03]","dark:border-white/10 dark:bg-white/[0.04] dark:hover:bg-white/[0.07]"),onClick:I,title:"Format JSON",children:[m.jsx(ae,{className:"h-3.5 w-3.5"}),"Format"]}):null,m.jsxs("button",{type:"button",className:L("inline-flex items-center gap-1.5 text-xs px-2.5 py-1.5 rounded-md","border border-black/10 bg-white hover:bg-black/[0.03]","dark:border-white/10 dark:bg-white/[0.04] dark:hover:bg-white/[0.07]"),onClick:()=>void ee(),title:"Reload from cache/server",children:[m.jsx(oe,{className:"h-3.5 w-3.5"}),"Reload"]})]})]}),m.jsxs("div",{className:"relative flex-1 min-h-0",children:[z?.diff?m.jsx(fe,{diff:z.diff,changeType:z.changeType,title:"AI change",subtitle:u,onClose:Q,className:"absolute right-4 top-4 z-10 w-[min(420px,46vw)]"}):null,K&&!y?m.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:m.jsx(H,{className:"h-6 w-6 animate-spin"})}):m.jsx(be,{height:"100%",language:h,theme:l?"vs-dark":"vs",value:y?.content??"",beforeMount:c=>{try{c.languages.json.jsonDefaults.setDiagnosticsOptions({validate:!0,allowComments:!0,trailingCommas:"ignore"})}catch{}},onMount:c=>{_.current=c},onChange:c=>{g({projectId:e,fileId:t,content:c??""})},options:{automaticLayout:!0,minimap:{enabled:!1},fontFamily:'"Fira Code", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',fontSize:13,wordWrap:"off",scrollBeyondLastLine:!1,renderWhitespace:"selection",tabSize:2,insertSpaces:!0}})]})]})}export{Te as default};