@jingyi0605/codingns 0.6.1 → 0.6.5

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 (162) hide show
  1. package/bin/codingns.mjs +225 -0
  2. package/dist/public/assets/AdaptiveButlerPage-CfsUVZKl.js +3 -0
  3. package/dist/public/assets/{App-Dsf3ooXU.js → App-B9HcTkMT.js} +3 -3
  4. package/dist/public/assets/{BootstrapPage-CE0m1qSR.js → BootstrapPage-BgLdZEKQ.js} +1 -1
  5. package/dist/public/assets/ConversationPage-Cj8go7L0.js +4 -0
  6. package/dist/public/assets/{DesktopDetachPreviewPage-Dxarr_Wf.js → DesktopDetachPreviewPage-YCBnyC58.js} +1 -1
  7. package/dist/public/assets/{DesktopWindowPage-VytPwJ4c.js → DesktopWindowPage-CrvndE23.js} +1 -1
  8. package/dist/public/assets/{FileContextPanel-DwFzLsOp.js → FileContextPanel-CdC7GGw5.js} +1 -1
  9. package/dist/public/assets/{GitSidebar-CH6WqTrM.js → GitSidebar-z2SBinQh.js} +1 -1
  10. package/dist/public/assets/{MobileCreateSessionSheet-DcxKM00P.js → MobileCreateSessionSheet-Cb2HM-y3.js} +1 -1
  11. package/dist/public/assets/{MobileTopHeaderFrame-C5rIKQT6.js → MobileTopHeaderFrame-etF2HKlm.js} +1 -1
  12. package/dist/public/assets/{MobileWorkspaceSwitcherHeader-CfUnHgv_.js → MobileWorkspaceSwitcherHeader-CuGJ31kb.js} +1 -1
  13. package/dist/public/assets/{RelayConnectEntryPage-CgMvVZwa.js → RelayConnectEntryPage-BB6DbGtP.js} +1 -1
  14. package/dist/public/assets/{ServerSettingsModal-CFul__z1.js → ServerSettingsModal-Bl1sacZg.js} +1 -1
  15. package/dist/public/assets/{SessionIndexPage-B-tRhBXC.js → SessionIndexPage-NbF9gJnp.js} +1 -1
  16. package/dist/public/assets/SettingsPage-DGsmQpLv.js +1 -0
  17. package/dist/public/assets/{TerminalManagerPanel-BbORd-ee.js → TerminalManagerPanel-BOm8Hi_v.js} +1 -1
  18. package/dist/public/assets/{TerminalPage-DWHv6mlu.js → TerminalPage-B5JNFU6w.js} +19 -19
  19. package/dist/public/assets/{TerminalRuntimeFallbackModal-B29YxbQe.js → TerminalRuntimeFallbackModal-CM3LRKOJ.js} +1 -1
  20. package/dist/public/assets/{ToolFilesPage-Dx9cv9hu.js → ToolFilesPage-GSqKQsj_.js} +1 -1
  21. package/dist/public/assets/{ToolGitPage-D7H3vAia.js → ToolGitPage-BVFWMMQp.js} +1 -1
  22. package/dist/public/assets/{ToolProcessesPage-PqQWxsy-.js → ToolProcessesPage-DZ456fYz.js} +1 -1
  23. package/dist/public/assets/{ToolsHomePage-CX05Pe_4.js → ToolsHomePage-DsJp0y8A.js} +1 -1
  24. package/dist/public/assets/{WorkbenchLandingPage-CchkAC75.js → WorkbenchLandingPage-DyPei0e-.js} +1 -1
  25. package/dist/public/assets/WorkbenchLayout-DlbgBT3n.js +4 -0
  26. package/dist/public/assets/WorkbenchModal-LNfB69qx.js +1 -0
  27. package/dist/public/assets/WorkbenchShellRoute-BsxumYx5.js +1 -0
  28. package/dist/public/assets/{WorkbenchShellRoute-RGZpA0_J.css → WorkbenchShellRoute-DhQo_0vu.css} +1 -1
  29. package/dist/public/assets/{WorkspaceDebugDetailPage-Deqy2_pO.js → WorkspaceDebugDetailPage-CaXj5zVI.js} +1 -1
  30. package/dist/public/assets/{WorkspaceDetailPage-Cvf-ZdlB.js → WorkspaceDetailPage-DOexuuaw.js} +1 -1
  31. package/dist/public/assets/{WorkspaceHomePage-Dsyvqyk1.js → WorkspaceHomePage-DkCHNjKD.js} +1 -1
  32. package/dist/public/assets/{client-runtime-manager-DROQJ9v3.js → client-runtime-manager-6OoYHXGd.js} +1 -1
  33. package/dist/public/assets/{file-tree-icon-Bp3Ntt7u.js → file-tree-icon-9pt1OStn.js} +1 -1
  34. package/dist/public/assets/index-BwlbvwaA.css +1 -0
  35. package/dist/public/assets/index-DSw-TkQL.js +42 -0
  36. package/dist/public/assets/{login-direct-candidate-resolver-DotM530R.js → login-direct-candidate-resolver-CLlYtBRq.js} +1 -1
  37. package/dist/public/assets/model-switch-api-C-l8-E1S.js +1 -0
  38. package/dist/public/assets/{preferences-service-BG6GKG29.js → preferences-service-BCcfYP_d.js} +1 -1
  39. package/dist/public/assets/{relay-entry-pmr-c42O.js → relay-entry-BmLkMKuq.js} +1 -1
  40. package/dist/public/assets/session-runtime-machine-DgtvREca.js +21 -0
  41. package/dist/public/assets/{terminal-runtime-meta-8_uRZf7h.js → terminal-runtime-meta-0h-75uRy.js} +1 -1
  42. package/dist/public/assets/{useRegisteredDebugTemplates-DWX7LXQu.js → useRegisteredDebugTemplates-rBVmAqh3.js} +1 -1
  43. package/dist/public/index.html +2 -2
  44. package/dist/server/modules/assistant-capability/assistant-capability-service.d.ts +4 -1
  45. package/dist/server/modules/assistant-capability/assistant-capability-service.js +12 -1
  46. package/dist/server/modules/assistant-capability/assistant-capability-service.js.map +1 -1
  47. package/dist/server/modules/butler/butler-control-session-service.d.ts +4 -1
  48. package/dist/server/modules/butler/butler-control-session-service.js +17 -1
  49. package/dist/server/modules/butler/butler-control-session-service.js.map +1 -1
  50. package/dist/server/modules/butler/butler-profile-service.d.ts +3 -1
  51. package/dist/server/modules/butler/butler-profile-service.js +16 -4
  52. package/dist/server/modules/butler/butler-profile-service.js.map +1 -1
  53. package/dist/server/modules/opencli/opencli-bridge-skill-service.d.ts +12 -0
  54. package/dist/server/modules/opencli/opencli-bridge-skill-service.js +124 -0
  55. package/dist/server/modules/opencli/opencli-bridge-skill-service.js.map +1 -0
  56. package/dist/server/modules/opencli/opencli-catalog-service.d.ts +50 -0
  57. package/dist/server/modules/opencli/opencli-catalog-service.js +345 -0
  58. package/dist/server/modules/opencli/opencli-catalog-service.js.map +1 -0
  59. package/dist/server/modules/opencli/opencli-controller.d.ts +13 -0
  60. package/dist/server/modules/opencli/opencli-controller.js +30 -0
  61. package/dist/server/modules/opencli/opencli-controller.js.map +1 -0
  62. package/dist/server/modules/opencli/opencli-health-service.d.ts +28 -0
  63. package/dist/server/modules/opencli/opencli-health-service.js +106 -0
  64. package/dist/server/modules/opencli/opencli-health-service.js.map +1 -0
  65. package/dist/server/modules/opencli/opencli-install-discovery.d.ts +23 -0
  66. package/dist/server/modules/opencli/opencli-install-discovery.js +130 -0
  67. package/dist/server/modules/opencli/opencli-install-discovery.js.map +1 -0
  68. package/dist/server/modules/opencli/opencli-management-service.d.ts +59 -0
  69. package/dist/server/modules/opencli/opencli-management-service.js +152 -0
  70. package/dist/server/modules/opencli/opencli-management-service.js.map +1 -0
  71. package/dist/server/modules/opencli/opencli-runtime-builder.d.ts +11 -0
  72. package/dist/server/modules/opencli/opencli-runtime-builder.js +214 -0
  73. package/dist/server/modules/opencli/opencli-runtime-builder.js.map +1 -0
  74. package/dist/server/modules/opencli/opencli-runtime-layout.d.ts +3 -0
  75. package/dist/server/modules/opencli/opencli-runtime-layout.js +11 -0
  76. package/dist/server/modules/opencli/opencli-runtime-layout.js.map +1 -0
  77. package/dist/server/modules/opencli/opencli-runtime-profile-service.d.ts +29 -0
  78. package/dist/server/modules/opencli/opencli-runtime-profile-service.js +104 -0
  79. package/dist/server/modules/opencli/opencli-runtime-profile-service.js.map +1 -0
  80. package/dist/server/modules/opencli/opencli-runtime-resolver.d.ts +29 -0
  81. package/dist/server/modules/opencli/opencli-runtime-resolver.js +110 -0
  82. package/dist/server/modules/opencli/opencli-runtime-resolver.js.map +1 -0
  83. package/dist/server/modules/opencli/opencli-session-prompt-service.d.ts +11 -0
  84. package/dist/server/modules/opencli/opencli-session-prompt-service.js +66 -0
  85. package/dist/server/modules/opencli/opencli-session-prompt-service.js.map +1 -0
  86. package/dist/server/modules/provider/provider-catalog-service.d.ts +46 -0
  87. package/dist/server/modules/provider/provider-catalog-service.js +249 -0
  88. package/dist/server/modules/provider/provider-catalog-service.js.map +1 -0
  89. package/dist/server/modules/provider/provider-controller.d.ts +15 -2
  90. package/dist/server/modules/provider/provider-controller.js +44 -6
  91. package/dist/server/modules/provider/provider-controller.js.map +1 -1
  92. package/dist/server/modules/provider/provider-disabled.d.ts +8 -0
  93. package/dist/server/modules/provider/provider-disabled.js +45 -0
  94. package/dist/server/modules/provider/provider-disabled.js.map +1 -0
  95. package/dist/server/modules/provider/provider-discovery-helper-client.d.ts +1 -0
  96. package/dist/server/modules/provider/provider-discovery-helper-client.js.map +1 -1
  97. package/dist/server/modules/provider/provider-discovery-helper-process.js +3 -3
  98. package/dist/server/modules/provider/provider-discovery-helper-process.js.map +1 -1
  99. package/dist/server/modules/provider/provider-discovery-runtime.d.ts +1 -1
  100. package/dist/server/modules/provider/provider-discovery-runtime.js +12 -8
  101. package/dist/server/modules/provider/provider-discovery-runtime.js.map +1 -1
  102. package/dist/server/modules/sessions/claude-compatible-provider-registry.d.ts +16 -0
  103. package/dist/server/modules/sessions/claude-compatible-provider-registry.js +91 -0
  104. package/dist/server/modules/sessions/claude-compatible-provider-registry.js.map +1 -0
  105. package/dist/server/modules/sessions/session-history-service.d.ts +7 -1
  106. package/dist/server/modules/sessions/session-history-service.js +49 -16
  107. package/dist/server/modules/sessions/session-history-service.js.map +1 -1
  108. package/dist/server/modules/sessions/session-live-runtime-router-service.js +9 -4
  109. package/dist/server/modules/sessions/session-live-runtime-router-service.js.map +1 -1
  110. package/dist/server/modules/sessions/session-live-runtime-service.d.ts +8 -4
  111. package/dist/server/modules/sessions/session-live-runtime-service.js +100 -87
  112. package/dist/server/modules/sessions/session-live-runtime-service.js.map +1 -1
  113. package/dist/server/modules/sessions/session-permission-request-service.d.ts +5 -2
  114. package/dist/server/modules/sessions/session-permission-request-service.js +26 -27
  115. package/dist/server/modules/sessions/session-permission-request-service.js.map +1 -1
  116. package/dist/server/modules/sessions/session-provider-config-service.d.ts +17 -1
  117. package/dist/server/modules/sessions/session-provider-config-service.js +121 -17
  118. package/dist/server/modules/sessions/session-provider-config-service.js.map +1 -1
  119. package/dist/server/modules/skills/skill-manager-service.d.ts +5 -0
  120. package/dist/server/modules/skills/skill-manager-service.js +26 -0
  121. package/dist/server/modules/skills/skill-manager-service.js.map +1 -1
  122. package/dist/server/modules/tasks/task-helper-process-handlers.d.ts +1 -0
  123. package/dist/server/modules/tasks/task-helper-process-handlers.js +1 -1
  124. package/dist/server/modules/tasks/task-helper-process-handlers.js.map +1 -1
  125. package/dist/server/routes/opencli.d.ts +3 -0
  126. package/dist/server/routes/opencli.js +7 -0
  127. package/dist/server/routes/opencli.js.map +1 -0
  128. package/dist/server/routes/providers.js +4 -2
  129. package/dist/server/routes/providers.js.map +1 -1
  130. package/dist/server/server/create-server.d.ts +8 -0
  131. package/dist/server/server/create-server.js +44 -11
  132. package/dist/server/server/create-server.js.map +1 -1
  133. package/dist/server/storage/repositories/opencli-catalog-entry-repository.d.ts +9 -0
  134. package/dist/server/storage/repositories/opencli-catalog-entry-repository.js +85 -0
  135. package/dist/server/storage/repositories/opencli-catalog-entry-repository.js.map +1 -0
  136. package/dist/server/storage/repositories/opencli-provider-repository.d.ts +8 -0
  137. package/dist/server/storage/repositories/opencli-provider-repository.js +88 -0
  138. package/dist/server/storage/repositories/opencli-provider-repository.js.map +1 -0
  139. package/dist/server/storage/repositories/opencli-runtime-profile-repository.d.ts +11 -0
  140. package/dist/server/storage/repositories/opencli-runtime-profile-repository.js +127 -0
  141. package/dist/server/storage/repositories/opencli-runtime-profile-repository.js.map +1 -0
  142. package/dist/server/storage/repositories/provider-control-repository.d.ts +9 -0
  143. package/dist/server/storage/repositories/provider-control-repository.js +51 -0
  144. package/dist/server/storage/repositories/provider-control-repository.js.map +1 -0
  145. package/dist/server/storage/sqlite/client.js +53 -0
  146. package/dist/server/storage/sqlite/client.js.map +1 -1
  147. package/dist/server/storage/sqlite/schema.sql +66 -0
  148. package/dist/server/types/domain.d.ts +50 -0
  149. package/node_modules/@codingns/session-sync-core/dist/runtime/legna-runtime.d.ts +5 -0
  150. package/node_modules/@codingns/session-sync-core/dist/runtime/legna-runtime.js +1 -1
  151. package/node_modules/@codingns/session-sync-core/dist/runtime/legna-runtime.js.map +1 -1
  152. package/package.json +1 -1
  153. package/dist/public/assets/AdaptiveButlerPage-Dw72U3hG.js +0 -3
  154. package/dist/public/assets/ConversationPage-8wOY7SX-.js +0 -4
  155. package/dist/public/assets/SettingsPage-C9LGxSQZ.js +0 -1
  156. package/dist/public/assets/WorkbenchLayout-pOZvEqp7.js +0 -3
  157. package/dist/public/assets/WorkbenchModal-ColqvV6a.js +0 -1
  158. package/dist/public/assets/WorkbenchShellRoute-C0_h4lP6.js +0 -1
  159. package/dist/public/assets/index-B84Po2NA.css +0 -1
  160. package/dist/public/assets/index-C-0oeG_5.js +0 -42
  161. package/dist/public/assets/model-switch-api-Bh9nYslz.js +0 -1
  162. package/dist/public/assets/session-runtime-machine-YN84QBlr.js +0 -21
@@ -0,0 +1,4 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FileContextPanel-CdC7GGw5.js","assets/index-DSw-TkQL.js","assets/index-BwlbvwaA.css","assets/App-B9HcTkMT.js","assets/App-CcDXqFl1.css","assets/model-switch-api-C-l8-E1S.js","assets/WorkbenchModal-LNfB69qx.js","assets/file-tree-icon-9pt1OStn.js","assets/window-BVUB8gMK.js","assets/event-DvH9tcej.js","assets/relay-entry-BmLkMKuq.js","assets/GitSidebar-z2SBinQh.js","assets/TerminalManagerPanel-BOm8Hi_v.js","assets/terminal-runtime-meta-0h-75uRy.js","assets/TerminalRuntimeFallbackModal-CM3LRKOJ.js"])))=>i.map(i=>d[i]);
2
+ var Sd=Object.defineProperty;var jd=(e,t,s)=>t in e?Sd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var Pe=(e,t,s)=>jd(e,typeof t!="symbol"?t+"":t,s);import{C as oe,t as r,b as o,j as n,e as tn,m as xr,H as Fl,J as Cd,F as Nd,K as Id,w as Ri,A as Ei,p as Ea,L as Td,M as Md,N as $l,i as Hl,O as ki,f as Pi,h as wi,P as Rd,l as Ul,y as Ed,n as Pd,z as Ad,d as Wd,_ as Ai}from"./index-DSw-TkQL.js";import{m as Oe,e as Vn,h as Pa,u as Sr,g as ws,f as vs,i as Ld,j as Dd,O as no}from"./App-B9HcTkMT.js";import{e as Wi,f as Gs,i as Li,j as Pt,k as Zr,V as Gl,A as so,l as Bd,m as _d,a4 as zl,a5 as Od,M as Fd,a6 as $d,a7 as Hd,n as Ud,t as Gd,q as zd,s as Kl,h as $s,a as vi,v as Kd,o as qd,p as ja,a8 as Vd,a9 as Xd,aa as Yd,H as Jd,u as Qr,g as Zd,ab as Qd,ac as eu,ad as tu,ae as ql,af as nu,ag as Vl,ah as su,ai as ru,aj as Xl,K as au,S as iu,R as ro,r as ou,ak as lu}from"./model-switch-api-C-l8-E1S.js";import{t as zs,P as Ca,g as Yl}from"./window-BVUB8gMK.js";import{R as cu,_ as ao,a as io,C as Jl,i as ke}from"./event-DvH9tcej.js";import{W as et,M as du,D as uu}from"./WorkbenchModal-LNfB69qx.js";import{r as hu,b as pu}from"./relay-entry-BmLkMKuq.js";const Ks=new Map,Zl=48;function xs(){return typeof window<"u"&&typeof window.sessionStorage<"u"}function oo(e,t){return!Number.isFinite(e)||Date.now()-e>t}function mu(e){return!e||typeof e!="object"||!("savedAt"in e)||!("value"in e)?!1:Number.isFinite(e.savedAt)}function Ql(e){try{const t=JSON.parse(e);return mu(t)?t:null}catch{return null}}function fu(){if(!xs())return[];try{return Array.from({length:window.sessionStorage.length},(e,t)=>window.sessionStorage.key(t)).filter(e=>typeof e=="string"&&e.length>0)}catch{return[]}}function ec(){if(!xs())return[];const e=[];for(const t of fu()){let s=null;try{s=window.sessionStorage.getItem(t)}catch{continue}if(!s)continue;const a=Ql(s);a&&e.push({key:t,savedAt:a.savedAt})}return e.sort((t,s)=>t.savedAt-s.savedAt)}function yr(e){if(xs())try{window.sessionStorage.removeItem(e)}catch{}}function ea(e){const t=new Set((e==null?void 0:e.preserveKeys)??[]),s=(e==null?void 0:e.maxCount)??Zl,a=ec().filter(c=>!t.has(c.key)),i=Math.max(0,t.size+a.length-s);for(let c=0;c<i;c+=1){const u=a[c];if(!u)break;yr(u.key)}}function bu(e){return e instanceof DOMException&&(e.name==="QuotaExceededError"||e.name==="NS_ERROR_DOM_QUOTA_REACHED"||e.code===22||e.code===1014)}function Za(e,t){if(!xs())return"failed";try{return window.sessionStorage.setItem(e,t),"success"}catch(s){return bu(s)?"quota_exceeded":"failed"}}function gu(e,t){const s=Za(e,t);if(s==="success"){ea({preserveKeys:[e]});return}if(s==="quota_exceeded"){if(yr(e),ea({maxCount:Math.max(0,Zl-1)}),Za(e,t)==="success"){ea({preserveKeys:[e]});return}for(const a of ec())if(a.key!==e&&(yr(a.key),Za(e,t)==="success")){ea({preserveKeys:[e]});return}}}function Na(e,t){const s=Ks.get(e);if(s){if(!oo(s.savedAt,t))return s.value;Ks.delete(e)}if(!xs())return null;let a=null;try{a=window.sessionStorage.getItem(e)}catch{return null}if(!a)return null;const i=Ql(a);return!i||oo(i.savedAt,t)?(yr(e),Ks.delete(e),null):(Ks.set(e,i),i.value)}function wr(e,t){const s={savedAt:Date.now(),value:t};if(Ks.set(e,s),!!xs())try{gu(e,JSON.stringify(s))}catch{}}function eg(e){Ks.delete(e),xs()&&yr(e)}const ku="codingns.debug.perf",wu="codingns.debug.sessionMessageDedup",vu="codingns.debug.opencodeOrder",xu="codingns.debug.timelineScroll";function yu(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(ku)==="1"}catch{return!1}}function mt(e,t){if(!yu()||typeof performance>"u")return;const s=Math.round(performance.now());if(t&&Object.keys(t).length>0){console.info(`[perf-ui] ${e} ${s}ms`,t);return}console.info(`[perf-ui] ${e} ${s}ms`)}function Su(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(wu)==="1"}catch{return!1}}function tg(e,t){if(!Su()||typeof performance>"u")return;const s=Math.round(performance.now());if(t&&Object.keys(t).length>0){console.info(`[session-dedup] ${e} ${s}ms`,t);return}console.info(`[session-dedup] ${e} ${s}ms`)}function ju(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(vu)==="1"}catch{return!1}}function ng(e,t){if(!ju()||typeof performance>"u")return;const s=Math.round(performance.now()),a={scope:e,timestampMs:s,...t??{}};try{const i=window,c=i.__CODINGNS_OPENCODE_ORDER_DEBUG__??[];c.push(a),c.length>500&&c.splice(0,c.length-500),i.__CODINGNS_OPENCODE_ORDER_DEBUG__=c}catch{}if(t&&Object.keys(t).length>0){console.info(`[opencode-order-ui] ${e} ${s}ms`,t);return}console.info(`[opencode-order-ui] ${e} ${s}ms`)}function Cu(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(xu)==="1"}catch{return!1}}function sg(e,t){if(!Cu()||typeof performance>"u")return;const s=Math.round(performance.now()),a={scope:e,timestampMs:s,...t??{}};try{const i=window,c=i.__CODINGNS_TIMELINE_SCROLL_DEBUG__??[];c.push(a),c.length>300&&c.splice(0,c.length-300),i.__CODINGNS_TIMELINE_SCROLL_DEBUG__=c}catch{}if(t&&Object.keys(t).length>0){console.info(`[timeline-scroll] ${e} ${s}ms`,t);return}console.info(`[timeline-scroll] ${e} ${s}ms`)}function rg(e,t,s,a){return oe.request("/api/files/content",{method:"PUT",body:JSON.stringify({workspaceId:e,path:t,content:s,expectedVersion:a??void 0})})}function ag(e){return oe.request("/api/files/ops",{method:"POST",body:JSON.stringify(e)})}function ig(e){return oe.request("/api/files/upload",{method:"POST",body:JSON.stringify(e)})}function og(e,t){const s=new URLSearchParams({workspaceId:e,path:t});return oe.request(`/api/files/download?${s.toString()}`)}function Nu(e,t,s=1,a=20){const i=new URLSearchParams({workspaceId:e,keyword:t,page:String(s),pageSize:String(a)});return oe.request(`/api/files/search?${i.toString()}`)}function lg(e,t){const s=new URLSearchParams({workspaceId:e,path:t});return oe.request(`/api/files/preview?${s.toString()}`)}function cg(e){return oe.request(`/api/git/status?workspaceId=${encodeURIComponent(e)}`)}function dg(e){return oe.request("/api/git/init",{method:"POST",body:JSON.stringify({workspaceId:e})})}function ug(e,t,s){const a=new URLSearchParams({workspaceId:e,path:t,staged:String(s)});return oe.request(`/api/git/diff?${a.toString()}`)}function hg(e,t){return oe.request("/api/git/stage",{method:"POST",body:JSON.stringify({workspaceId:e,targets:t})})}function pg(e,t){return oe.request("/api/git/unstage",{method:"POST",body:JSON.stringify({workspaceId:e,targets:t})})}function mg(e,t){return oe.request("/api/git/discard",{method:"POST",body:JSON.stringify({workspaceId:e,targets:t})})}function fg(e,t){return oe.request("/api/git/commit/draft",{method:"POST",body:JSON.stringify({workspaceId:e,mode:t})})}function bg(e,t){return oe.request("/api/git/commit",{method:"POST",body:JSON.stringify({workspaceId:e,draft:t})})}function gg(e){return oe.request("/api/git/commit/undo",{method:"POST",body:JSON.stringify({workspaceId:e})})}function kg(e,t=5,s=null){const a=new URLSearchParams({workspaceId:e,limit:String(t)});return s&&a.set("cursor",s),oe.request(`/api/git/history?${a.toString()}`)}function wg(e,t){const s=new URLSearchParams({workspaceId:e,commitHash:t});return oe.request(`/api/git/commit-detail?${s.toString()}`)}function Iu(e){return oe.request(`/api/git/branches?workspaceId=${encodeURIComponent(e)}`)}function Tu(e){return oe.request(`/api/git/tags?workspaceId=${encodeURIComponent(e)}`)}function vg(e,t,s){return oe.request("/api/git/branches/switch",{method:"POST",body:JSON.stringify({workspaceId:e,branchName:t,create:s})})}function xg(e,t,s,a,i){return oe.request("/api/git/remote/sync",{method:"POST",body:JSON.stringify({workspaceId:e,action:t,...s?{remote:s}:{},...a?{auth:a}:{},...i?{remember:i}:{}})})}function yg(e){return oe.request(`/api/git/remotes?workspaceId=${encodeURIComponent(e)}`)}var wa,va;function tc(e){var t;if("items"in e)e.items=(t=e.items)===null||t===void 0?void 0:t.map(s=>"rid"in s?s:tc(s));else if("action"in e&&e.action){const s=new Jl;return s.onmessage=e.action,delete e.action,{...e,handler:s}}return e}async function Ys(e,t){const s=new Jl;if(t&&typeof t=="object"&&("action"in t&&t.action&&(s.onmessage=t.action,delete t.action),"item"in t&&t.item&&typeof t.item=="object"&&"About"in t.item&&t.item.About&&typeof t.item.About=="object"&&"icon"in t.item.About&&t.item.About.icon&&(t.item.About.icon=zs(t.item.About.icon)),"icon"in t&&t.icon&&(t.icon=zs(t.icon)),"items"in t&&t.items)){let a=function(i){var c;return"rid"in i?[i.rid,i.kind]:("item"in i&&typeof i.item=="object"&&(!((c=i.item.About)===null||c===void 0)&&c.icon)&&(i.item.About.icon=zs(i.item.About.icon)),"icon"in i&&i.icon&&(i.icon=zs(i.icon)),"items"in i&&i.items&&(i.items=i.items.map(a)),tc(i))};t.items=t.items.map(a)}return ke("plugin:menu|new",{kind:e,options:t,handler:s})}class Js extends cu{get id(){return ao(this,wa,"f")}get kind(){return ao(this,va,"f")}constructor(t,s,a){super(t),wa.set(this,void 0),va.set(this,void 0),io(this,wa,s),io(this,va,a)}}wa=new WeakMap,va=new WeakMap;class Di extends Js{constructor(t,s){super(t,s,"MenuItem")}static async new(t){return Ys("MenuItem",t).then(([s,a])=>new Di(s,a))}async text(){return ke("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(t){return ke("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:t})}async isEnabled(){return ke("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(t){return ke("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:t})}async setAccelerator(t){return ke("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:t})}}class Bi extends Js{constructor(t,s){super(t,s,"Check")}static async new(t){return Ys("Check",t).then(([s,a])=>new Bi(s,a))}async text(){return ke("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(t){return ke("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:t})}async isEnabled(){return ke("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(t){return ke("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:t})}async setAccelerator(t){return ke("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:t})}async isChecked(){return ke("plugin:menu|is_checked",{rid:this.rid})}async setChecked(t){return ke("plugin:menu|set_checked",{rid:this.rid,checked:t})}}var lo;(function(e){e.Add="Add",e.Advanced="Advanced",e.Bluetooth="Bluetooth",e.Bookmarks="Bookmarks",e.Caution="Caution",e.ColorPanel="ColorPanel",e.ColumnView="ColumnView",e.Computer="Computer",e.EnterFullScreen="EnterFullScreen",e.Everyone="Everyone",e.ExitFullScreen="ExitFullScreen",e.FlowView="FlowView",e.Folder="Folder",e.FolderBurnable="FolderBurnable",e.FolderSmart="FolderSmart",e.FollowLinkFreestanding="FollowLinkFreestanding",e.FontPanel="FontPanel",e.GoLeft="GoLeft",e.GoRight="GoRight",e.Home="Home",e.IChatTheater="IChatTheater",e.IconView="IconView",e.Info="Info",e.InvalidDataFreestanding="InvalidDataFreestanding",e.LeftFacingTriangle="LeftFacingTriangle",e.ListView="ListView",e.LockLocked="LockLocked",e.LockUnlocked="LockUnlocked",e.MenuMixedState="MenuMixedState",e.MenuOnState="MenuOnState",e.MobileMe="MobileMe",e.MultipleDocuments="MultipleDocuments",e.Network="Network",e.Path="Path",e.PreferencesGeneral="PreferencesGeneral",e.QuickLook="QuickLook",e.RefreshFreestanding="RefreshFreestanding",e.Refresh="Refresh",e.Remove="Remove",e.RevealFreestanding="RevealFreestanding",e.RightFacingTriangle="RightFacingTriangle",e.Share="Share",e.Slideshow="Slideshow",e.SmartBadge="SmartBadge",e.StatusAvailable="StatusAvailable",e.StatusNone="StatusNone",e.StatusPartiallyAvailable="StatusPartiallyAvailable",e.StatusUnavailable="StatusUnavailable",e.StopProgressFreestanding="StopProgressFreestanding",e.StopProgress="StopProgress",e.TrashEmpty="TrashEmpty",e.TrashFull="TrashFull",e.User="User",e.UserAccounts="UserAccounts",e.UserGroup="UserGroup",e.UserGuest="UserGuest"})(lo||(lo={}));class _i extends Js{constructor(t,s){super(t,s,"Icon")}static async new(t){return Ys("Icon",t).then(([s,a])=>new _i(s,a))}async text(){return ke("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(t){return ke("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:t})}async isEnabled(){return ke("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(t){return ke("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:t})}async setAccelerator(t){return ke("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:t})}async setIcon(t){return ke("plugin:menu|set_icon",{rid:this.rid,kind:this.kind,icon:zs(t)})}}class Oi extends Js{constructor(t,s){super(t,s,"Predefined")}static async new(t){return Ys("Predefined",t).then(([s,a])=>new Oi(s,a))}async text(){return ke("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(t){return ke("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:t})}}function Vs([e,t,s]){switch(s){case"Submenu":return new Fi(e,t);case"Predefined":return new Oi(e,t);case"Check":return new Bi(e,t);case"Icon":return new _i(e,t);case"MenuItem":default:return new Di(e,t)}}class Fi extends Js{constructor(t,s){super(t,s,"Submenu")}static async new(t){return Ys("Submenu",t).then(([s,a])=>new Fi(s,a))}async text(){return ke("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(t){return ke("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:t})}async isEnabled(){return ke("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(t){return ke("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:t})}async append(t){return ke("plugin:menu|append",{rid:this.rid,kind:this.kind,items:(Array.isArray(t)?t:[t]).map(s=>"rid"in s?[s.rid,s.kind]:s)})}async prepend(t){return ke("plugin:menu|prepend",{rid:this.rid,kind:this.kind,items:(Array.isArray(t)?t:[t]).map(s=>"rid"in s?[s.rid,s.kind]:s)})}async insert(t,s){return ke("plugin:menu|insert",{rid:this.rid,kind:this.kind,items:(Array.isArray(t)?t:[t]).map(a=>"rid"in a?[a.rid,a.kind]:a),position:s})}async remove(t){return ke("plugin:menu|remove",{rid:this.rid,kind:this.kind,item:[t.rid,t.kind]})}async removeAt(t){return ke("plugin:menu|remove_at",{rid:this.rid,kind:this.kind,position:t}).then(Vs)}async items(){return ke("plugin:menu|items",{rid:this.rid,kind:this.kind}).then(t=>t.map(Vs))}async get(t){return ke("plugin:menu|get",{rid:this.rid,kind:this.kind,id:t}).then(s=>s?Vs(s):null)}async popup(t,s){var a;return ke("plugin:menu|popup",{rid:this.rid,kind:this.kind,window:(a=s==null?void 0:s.label)!==null&&a!==void 0?a:null,at:t instanceof Ca?t:t?new Ca(t):null})}async setAsWindowsMenuForNSApp(){return ke("plugin:menu|set_as_windows_menu_for_nsapp",{rid:this.rid})}async setAsHelpMenuForNSApp(){return ke("plugin:menu|set_as_help_menu_for_nsapp",{rid:this.rid})}async setIcon(t){return ke("plugin:menu|set_icon",{rid:this.rid,kind:this.kind,icon:zs(t)})}}class qs extends Js{constructor(t,s){super(t,s,"Menu")}static async new(t){return Ys("Menu",t).then(([s,a])=>new qs(s,a))}static async default(){return ke("plugin:menu|create_default").then(([t,s])=>new qs(t,s))}async append(t){return ke("plugin:menu|append",{rid:this.rid,kind:this.kind,items:(Array.isArray(t)?t:[t]).map(s=>"rid"in s?[s.rid,s.kind]:s)})}async prepend(t){return ke("plugin:menu|prepend",{rid:this.rid,kind:this.kind,items:(Array.isArray(t)?t:[t]).map(s=>"rid"in s?[s.rid,s.kind]:s)})}async insert(t,s){return ke("plugin:menu|insert",{rid:this.rid,kind:this.kind,items:(Array.isArray(t)?t:[t]).map(a=>"rid"in a?[a.rid,a.kind]:a),position:s})}async remove(t){return ke("plugin:menu|remove",{rid:this.rid,kind:this.kind,item:[t.rid,t.kind]})}async removeAt(t){return ke("plugin:menu|remove_at",{rid:this.rid,kind:this.kind,position:t}).then(Vs)}async items(){return ke("plugin:menu|items",{rid:this.rid,kind:this.kind}).then(t=>t.map(Vs))}async get(t){return ke("plugin:menu|get",{rid:this.rid,kind:this.kind,id:t}).then(s=>s?Vs(s):null)}async popup(t,s){var a;return ke("plugin:menu|popup",{rid:this.rid,kind:this.kind,window:(a=s==null?void 0:s.label)!==null&&a!==void 0?a:null,at:t instanceof Ca?t:t?new Ca(t):null})}async setAsAppMenu(){return ke("plugin:menu|set_as_app_menu",{rid:this.rid}).then(t=>t?new qs(t[0],t[1]):null)}async setAsWindowMenu(t){var s;return ke("plugin:menu|set_as_window_menu",{rid:this.rid,window:(s=t==null?void 0:t.label)!==null&&s!==void 0?s:null}).then(a=>a?new qs(a[0],a[1]):null)}}async function Mu(e){if(e.length===0)return;await(await qs.new({items:e.map(s=>({id:s.id,text:s.label,enabled:!s.disabled,accelerator:s.accelerator,action:()=>{s.onSelect()}}))})).popup(void 0,Yl())}const co={"parallel-group-1":{accent:"#0ea5e9",soft:"rgba(14, 165, 233, 0.16)",surface:"rgba(14, 165, 233, 0.08)"},"parallel-group-2":{accent:"#10b981",soft:"rgba(16, 185, 129, 0.16)",surface:"rgba(16, 185, 129, 0.08)"},"parallel-group-3":{accent:"#f59e0b",soft:"rgba(245, 158, 11, 0.16)",surface:"rgba(245, 158, 11, 0.08)"},"parallel-group-4":{accent:"#ec4899",soft:"rgba(236, 72, 153, 0.16)",surface:"rgba(236, 72, 153, 0.08)"},"parallel-group-5":{accent:"#8b5cf6",soft:"rgba(139, 92, 246, 0.16)",surface:"rgba(139, 92, 246, 0.08)"},"parallel-group-6":{accent:"#f97316",soft:"rgba(249, 115, 22, 0.16)",surface:"rgba(249, 115, 22, 0.08)"}},Ru=2600,nc="workbench.parallel.pane.palette";let Hs=null;const uo=["#34C759","#22C55E","#14B8A6","#06B6D4","#0EA5E9","#3B82F6","#6366F1","#8B5CF6","#A855F7","#D946EF","#EC4899","#F43F5E","#EF4444","#F97316","#F59E0B","#EAB308","#84CC16","#10B981"];function Eu(e="create"){return e==="append"?{totalDurationMs:1200,sidebarCollapseDurationMs:0,paneEnterDelayMs:0,paneEnterDurationMs:1e3,gridRevealDelayMs:0,gridRevealDurationMs:920,shellExpandDurationMs:0,paneStaggerMs:80}:{totalDurationMs:2e3,sidebarCollapseDurationMs:720,paneEnterDelayMs:520,paneEnterDurationMs:1480,gridRevealDelayMs:420,gridRevealDurationMs:1360,shellExpandDurationMs:720,paneStaggerMs:96}}function sc(e){var s,a;const t=(s=e.displayParentSessionId)==null?void 0:s.trim();return t||((a=e.parentSessionId)==null?void 0:a.trim())||null}function Pu(e){var a;const t=(a=e==null?void 0:e.colorToken)==null?void 0:a.trim();if(!t)return;const s=co[t]??co["parallel-group-1"];return{"--parallel-group-accent":s.accent,"--parallel-group-soft":s.soft,"--parallel-group-surface":s.surface}}function Sg(e){const t=Ia(e.overrideColor)??Au(e.groupId,e.ordinal);return{"--parallel-group-accent":t,"--parallel-group-soft":ho(t,.08),"--parallel-group-surface":ho(t,.03)}}function jg(e){if(typeof window>"u")return null;const t=e.trim();if(!t)return null;const s=rc();return Ia(s[t]??null)}function Cg(e,t){if(typeof window>"u")return Ia(t);const s=e.trim();if(!s)return null;const a=rc(),i=Ia(t);return i?a[s]=i:delete a[s],window.localStorage.setItem(nc,JSON.stringify(a)),i}function Au(e,t){const s=uo.length,a=Math.abs(Fu(e))%s;return uo[(a+t*5)%s]}function Ng(e){return e?e.role==="anchor"?r("shell.parallelGroupAnchorBadge"):r("shell.parallelGroupMemberBadge"):null}function Wu(e){return e?r("shell.parallelGroupBadge",{count:e.memberCount}):null}function Ig(e){var s;return((s=e==null?void 0:e.branchName)==null?void 0:s.trim())||null}function Lu(e){var s,a,i;return((a=(s=e==null?void 0:e.parallelGroup)==null?void 0:s.groupId)==null?void 0:a.trim())?((i=e==null?void 0:e.sessionIsolatedWorkspace)==null?void 0:i.lifecycleStatus)!=="promoted":!1}function Du(e,t){return t&&(t.lifecycleStatus==="active"||t.lifecycleStatus==="removing")?t.sourceWorkspaceId:e.workspaceId}function Bu(e,t){return t&&(t.lifecycleStatus==="active"||t.lifecycleStatus==="promoted")?t.workspaceId:e.workspaceId}function _u(e,t="create"){Hs={groupId:e,createdAt:Date.now(),...Eu(t)}}function Ou(e){return!Hs||Hs.groupId!==e?null:Date.now()-Hs.createdAt>Ru?(Hs=null,null):Hs}function rc(){if(typeof window>"u")return{};const e=window.localStorage.getItem(nc);if(!e)return{};try{const t=JSON.parse(e);return!t||typeof t!="object"?{}:t}catch{return{}}}function Fu(e){let t=0;for(const s of e)t=t*31+s.charCodeAt(0)|0;return t}function Ia(e){const t=(e==null?void 0:e.trim().toUpperCase())??"";return/^#[0-9A-F]{6}$/.test(t)?t:null}function ho(e,t){const s=Math.max(0,Math.min(t,1)),a=Number.parseInt(e.slice(1,3),16),i=Number.parseInt(e.slice(3,5),16),c=Number.parseInt(e.slice(5,7),16);return`rgba(${a}, ${i}, ${c}, ${s})`}function ac(e,t){const s=new Map(e.map(c=>[t.getId(c),c])),a=new Map,i=[];for(const c of e){const u=$u(c,s,t);if(!u){i.push(c);continue}const h=a.get(u)??[];a.set(u,[...h,c])}return[...i].sort(t.compare).map(c=>lc(c,0,a,t,new Set))}function Zs(e){return Array.isArray(e==null?void 0:e.children)?e.children:[]}function ic(e){return e.flatMap(t=>[t.item,...ic(Zs(t))])}function zn(e){return e.flatMap(t=>[t,...zn(Zs(t))])}function $i(e,t){return e.some(s=>t(s.item)||$i(Zs(s),t))}function oc(e,t,s){return e?s(e.item)===t?!0:Zs(e).some(a=>oc(a,t,s)):!1}function Us(e,t,s){for(const a of e){const i=s(a.item);if(i===t)return[];const c=Us(Zs(a),t,s);if(oc(a,t,s)&&c.length>=0)return[i,...c]}return[]}function lc(e,t,s,a,i){const c=a.getId(e),u=new Set(i);u.add(c);const h=[...s.get(c)??[]].filter(k=>!u.has(a.getId(k))).sort(a.compare).map(k=>lc(k,t+1,s,a,u));return{item:e,depth:t,children:h}}function $u(e,t,s){const a=po(s.getParentId(e));if(!a)return null;const i=t.get(a);if(!i)return null;const c=new Set([s.getId(e)]);let u=i;for(;u;){const h=s.getId(u);if(c.has(h))return null;c.add(h);const k=po(s.getParentId(u));if(!k||(u=t.get(k),!u))return a}return a}function po(e){const t=e==null?void 0:e.trim();return t||null}function Ct(){return"/workspaces"}function kn(e){return`/workspaces/${encodeURIComponent(e)}`}function cc(e){return`${kn(e)}/debug`}function Xs(e){return`${kn(e)}/sessions`}function Ut(e,t){return`${Xs(e)}/${encodeURIComponent(t)}`}function dc(e,t){const s=`${kn(e)}/tools`;if(!t)return s;const a=new URLSearchParams({tab:t});return`${s}?${a.toString()}`}function uc(e){return`${kn(e)}/tools/files`}function hc(e){return`${kn(e)}/tools/git`}function pc(e){return`${kn(e)}/tools/processes`}function gs(e){return`${kn(e)}/terminals`}function ks(e,t){const s=`${kn(e)}/butler`;if(!t)return s;const a=new URLSearchParams({tab:t});return`${s}?${a.toString()}`}function Hu(e){return e.flatMap(t=>[...t.sessions.map(s=>({session:s,workspace:t.workspace})),...fc(t.childWorktrees??[])]).sort((t,s)=>(s.session.lastMessageAt??s.session.updatedAt).localeCompare(t.session.lastMessageAt??t.session.updatedAt))}function Tg(e,t){return ac(e,{getId:s=>s.session.sessionId,getParentId:s=>Uu(s.session,t),compare:zu})}function Uu(e,t){var s;return(t==null?void 0:t.mode)==="mobile"?((s=e.parentSessionId)==null?void 0:s.trim())||null:sc(e)}function mc(e,t){const s=Gu(),a=new URLSearchParams({provider:t});return`${Ut(e,s)}?${a.toString()}`}function Gu(){const e=globalThis.crypto;return e&&typeof e.randomUUID=="function"?`draft-${e.randomUUID()}`:`draft-${Date.now()}-${Math.random().toString(16).slice(2)}`}function zu(e,t){return(t.session.lastMessageAt??t.session.updatedAt).localeCompare(e.session.lastMessageAt??e.session.updatedAt)}function fc(e){return e.flatMap(t=>[...t.sessions.map(s=>({session:s,workspace:t.workspace})),...fc(t.children)])}const Ku="mobile.tools.last-primary-tool";function bc(){if(typeof window>"u")return"files";try{return window.localStorage.getItem(Ku)==="git"?"git":"files"}catch{return"files"}}function Hi(e){var a;const t=[{pattern:"/workspaces/:workspaceId/tools/processes",routeKind:"processes"},{pattern:"/workspaces/:workspaceId/tools/files",routeKind:"files"},{pattern:"/workspaces/:workspaceId/tools/git",routeKind:"git"},{pattern:"/workspaces/:workspaceId/tools",routeKind:"home"}];for(const i of t){const c=Oe(i.pattern,e),u=((a=c==null?void 0:c.params.workspaceId)==null?void 0:a.trim())??null;if(u)return{workspaceId:u,routeKind:i.routeKind,legacy:!1}}const s=[{pattern:"/tools/processes",routeKind:"processes"},{pattern:"/tools/files",routeKind:"files"},{pattern:"/tools/git",routeKind:"git"},{pattern:"/tools",routeKind:"home"}];for(const i of s)if(Oe(i.pattern,e))return{workspaceId:null,routeKind:i.routeKind,legacy:!0};return null}function qu(e,t){const s=Hi(e);if((s==null?void 0:s.routeKind)==="git")return"git";if((s==null?void 0:s.routeKind)==="files")return"files";const a=new URLSearchParams(t).get("tab");return a==="git"?"git":a==="files"?"files":bc()}function Ui(e,t){const s=Hi(e);return(s==null?void 0:s.routeKind)==="processes"&&s.workspaceId?gs(s.workspaceId):s!=null&&s.workspaceId?dc(s.workspaceId,qu(e,t)):s!=null&&s.legacy?bc()==="git"?"/tools?tab=git":"/tools?tab=files":null}function Gi({activeEntry:e,presentation:t,pathname:s,search:a,moreButtonLabel:i}){if(t==="conversation-focus"||e!=="butler")return null;const c=Hi(s);return c?c.routeKind==="processes"?{title:r("shell.terminalManagerEntry"),showBackButton:!0,showMoreButton:!1,moreButtonLabel:i}:(c.routeKind==="home"||c.routeKind==="files"||c.routeKind==="git",null):null}const gc=o.createContext({composerPortalTarget:null});function zi({composerPortalTarget:e,children:t}){return n.jsx(gc.Provider,{value:{composerPortalTarget:e},children:t})}function Mg(){return o.useContext(gc)}function Ki(e,t,s){const[a,i]=o.useState(void 0);return o.useEffect(()=>{const c=e.current,u=t.current;if(!s||!c||!u){i(void 0),c&&c.style.removeProperty("--mobile-conversation-tabbar-height");return}const h=c,k=u;function b(){if(!e.current||!k.isConnected)return;const N=`${Math.round(k.getBoundingClientRect().height)}px`;h.style.setProperty("--mobile-conversation-tabbar-height",N),i(N)}b();const y=typeof ResizeObserver<"u"?new ResizeObserver(b):null;return y==null||y.observe(k),window.addEventListener("resize",b),()=>{y==null||y.disconnect(),window.removeEventListener("resize",b),h.style.removeProperty("--mobile-conversation-tabbar-height")}},[s,e,t]),a}const Vu=3e3,ta=10,mo=84,fo=.36;function qi({enabled:e,rootRef:t,suspended:s=!1,resetKey:a}){const i=o.useRef(null),c=o.useRef(null),u=o.useRef("visible"),h=o.useRef(1),[k,b]=o.useState("visible"),[y,N]=o.useState(1);o.useEffect(()=>{u.current=k},[k]),o.useEffect(()=>{h.current=y},[y]);function A(){fs(i),i.current=window.setTimeout(()=>{M()},Vu)}function M(){b("hidden"),N(0)}function L(){b("visible"),N(1),A()}o.useEffect(()=>{if(fs(i),!e){fs(i),b("visible"),N(1);return}if(s){b("hidden"),N(0);return}return L(),()=>{fs(i)}},[e,a,s]),o.useEffect(()=>()=>{fs(i)},[]),o.useEffect(()=>{if(!e||s){c.current=null;return}const I=t.current;if(!I)return;function w(D){if(D.touches.length!==1){c.current=null;return}const j=D.touches[0],J=ko(D.target);if(!j||!J){c.current=null;return}c.current={surface:J,startX:j.clientX,startY:j.clientY,pointerType:"touch",initialState:u.current==="visible"?"visible":"hidden",touchId:j.identifier,dragging:!1,latestProgress:h.current},u.current==="visible"&&fs(i)}function O(D){const j=c.current;if(!j||j.pointerType!=="touch")return;const J=Qa(D.touches,j.touchId);if(!J)return;const Q=J.clientX-j.startX,B=J.clientY-j.startY;if(j.surface==="conversation"){if(Math.abs(B)<=ta||Math.abs(B)<=Math.abs(Q))return;c.current=null,j.initialState==="visible"&&M();return}const le=j.initialState==="hidden"?-B:B;le<=ta&&!j.dragging||(vo(D),j.dragging=!0,j.latestProgress=bo(j.initialState,le),b("dragging"),N(j.latestProgress))}function E(D){const j=c.current;if(!(!j||j.pointerType!=="touch"||!Qa(D.changedTouches,j.touchId))){if(c.current=null,!j.dragging){j.initialState==="visible"&&A();return}go(j.initialState,j.latestProgress,L,b,N)}}function K(D){const j=c.current;if(!(!j||j.pointerType!=="touch"||!Qa(D.changedTouches,j.touchId))){if(c.current=null,!j.dragging){j.initialState==="visible"&&A();return}if(j.initialState==="visible"){L();return}b("hidden"),N(0)}}function T(D){if(D.pointerType!=="touch")return;const j=ko(D.target);if(!j){c.current=null;return}if(c.current={surface:j,startX:D.clientX,startY:D.clientY,pointerType:"pointer",initialState:u.current==="visible"?"visible":"hidden",pointerId:D.pointerId,captureTarget:D.target instanceof Element?D.target:null,dragging:!1,latestProgress:h.current},D.target instanceof Element)try{D.target.setPointerCapture(D.pointerId)}catch{}u.current==="visible"&&fs(i)}function H(D){const j=c.current;if(!j||j.pointerType!=="pointer")return;const J=D.clientX-j.startX,Q=D.clientY-j.startY;if(j.surface==="conversation"){if(Math.abs(Q)<=ta||Math.abs(Q)<=Math.abs(J))return;c.current=null,j.initialState==="visible"&&M();return}const B=j.initialState==="hidden"?-Q:Q;B<=ta&&!j.dragging||(vo(D),j.dragging=!0,j.latestProgress=bo(j.initialState,B),b("dragging"),N(j.latestProgress))}function X(D){const j=c.current;if(!(!j||j.pointerType!=="pointer"||j.pointerId!==D.pointerId)){if(c.current=null,Xu(j),!j.dragging){j.initialState==="visible"&&A();return}go(j.initialState,j.latestProgress,L,b,N)}}return I.addEventListener("touchstart",w,{passive:!0}),I.addEventListener("pointerdown",T,{passive:!0}),window.addEventListener("touchmove",O,{passive:!1}),window.addEventListener("touchend",E),window.addEventListener("touchcancel",K),window.addEventListener("pointermove",H,{passive:!1}),window.addEventListener("pointerup",X),window.addEventListener("pointercancel",X),()=>{I.removeEventListener("touchstart",w),I.removeEventListener("pointerdown",T),window.removeEventListener("touchmove",O),window.removeEventListener("touchend",E),window.removeEventListener("touchcancel",K),window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",X),window.removeEventListener("pointercancel",X)}},[e,t,s]);const z=e&&!s?y:e?0:1;return{state:s&&e?"hidden":k,progress:z,isOpen:z>.01}}function fs(e){e.current!==null&&(window.clearTimeout(e.current),e.current=null)}function bo(e,t){return wo(e==="hidden"?t/mo:1-t/mo,0,1)}function go(e,t,s,a,i){if(e==="hidden"){if(t>=fo){s();return}a("hidden"),i(0);return}if(t<=1-fo){a("hidden"),i(0);return}s()}function Xu(e){if(!(e.pointerType!=="pointer"||typeof e.pointerId!="number"||!(e.captureTarget instanceof Element)))try{e.captureTarget.hasPointerCapture(e.pointerId)&&e.captureTarget.releasePointerCapture(e.pointerId)}catch{}}function Qa(e,t){if(typeof t!="number")return e[0]??null;for(let s=0;s<e.length;s+=1){const a=e[s];if((a==null?void 0:a.identifier)===t)return a}return null}function ko(e){return e instanceof Element?e.closest(".composer-panel")?"composer":e.closest(".message-list, .message-timeline, .mobile-conversation-main, .conversation-page-shell, .mobile-butler-main-stage, .mobile-butler-chat-body, .mobile-butler-page-shell")?"conversation":null:null}function wo(e,t,s){return Math.min(Math.max(e,t),s)}function vo(e){e.cancelable&&e.preventDefault()}function jr({viewportClass:e,activeEntry:t,hasNavigationPanel:s,hasAuxiliaryPanel:a,preferCompactLayout:i=!1}){return i||e==="compact"?"compact":e==="expanded"&&s&&a?"expanded":t==="butler"&&a?"medium-auxiliary":s?"medium-navigation":a?"medium-auxiliary":"compact"}function Aa(e){return!e.isNativeMobile||e.viewportClass==="expanded"||typeof window>"u"?!1:window.innerHeight>window.innerWidth}function kc(e){return e==="medium-navigation"||e==="expanded"}function wc(e){return e==="medium-auxiliary"||e==="expanded"}function Vi({viewportClass:e,activeEntry:t,hasNavigationPanel:s,hasAuxiliaryPanel:a,preferCompactLayout:i=!1,children:c,navigationPanel:u,auxiliaryPanel:h}){const k=jr({viewportClass:e,activeEntry:t,hasNavigationPanel:s,hasAuxiliaryPanel:a,preferCompactLayout:i}),b=kc(k)&&u,y=wc(k)&&h;return n.jsxs("div",{className:"mobile-adaptive-pane-layout","data-pane-layout":k,children:[b?n.jsx("aside",{className:"workbench-nav surface-card mobile-adaptive-pane-panel mobile-adaptive-pane-panel-navigation",children:u}):null,n.jsx("div",{className:"mobile-adaptive-pane-main",children:c}),y?n.jsx("aside",{className:"workbench-auxiliary surface-card mobile-adaptive-pane-panel mobile-adaptive-pane-panel-auxiliary",children:h}):null]})}function Yu({activeEntry:e,presentation:t="default",children:s,navigationPanel:a,auxiliaryPanel:i,onNavigateWorkspaces:c,onNavigateTerminals:u,onNavigateSessions:h,onNavigateButler:k,onNavigateToolProcesses:b,onNavigateSettings:y}){const N=Vn(),A=Wi(),M=Pa(),L=Sr(),z=o.useRef(null),I=o.useRef(null),[w,O]=o.useState(null),E=t==="conversation-focus",K=Aa({isNativeMobile:N.isNativeMobile,viewportClass:N.viewportClass}),T=qi({enabled:E,rootRef:z,resetKey:`${M.pathname}${M.search}`}),H=jr({viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!a,hasAuxiliaryPanel:!!i,preferCompactLayout:K}),X=Gi({activeEntry:e,presentation:t,pathname:M.pathname,search:M.search,moreButtonLabel:r("shell.androidMoreAction")}),D=[{key:"workspaces",label:r("shell.mobileWorkspacesEntry"),icon:n.jsx(Qu,{}),onClick:c},{key:"sessions",label:r("shell.mobileSessionsEntry"),icon:n.jsx(eh,{}),onClick:h},{key:"terminals",label:r("shell.mobileButlerEntry"),icon:n.jsx(nh,{}),onClick:k},{key:"butler",label:r("shell.mobileTerminalsEntry"),icon:n.jsx(th,{}),onClick:u},{key:"settings",label:r("shell.mobileSettingsEntry"),icon:n.jsx(sh,{}),onClick:y}],j=E?{"--mobile-conversation-tabbar-progress":T.progress.toFixed(4)}:void 0;Ki(z,I,E);function J(){const B=Ui(M.pathname,M.search);if(!B){u();return}L(B,{replace:!0})}const Q=n.jsx("nav",{ref:I,className:"android-workbench-bottom-nav","aria-label":r("shell.title"),children:D.map(B=>n.jsxs("button",{type:"button",className:"android-workbench-bottom-nav-item","data-active":B.key===e,"aria-current":B.key===e?"page":void 0,onClick:()=>{B.key!==e&&A.trigger("selection"),B.onClick()},children:[n.jsx("span",{className:"android-workbench-bottom-nav-icon","aria-hidden":"true",children:B.icon}),n.jsx("span",{className:"android-workbench-bottom-nav-label",children:B.label})]},B.key))});return n.jsx(zi,{composerPortalTarget:E?w:null,children:n.jsxs("div",{ref:z,className:"android-workbench-shell","data-active-entry":e,"data-mobile-presentation":t,"data-pane-layout":H,"data-tabbar-open":E?T.isOpen:!0,"data-conversation-tabbar-state":E?T.state:"default",style:j,children:[X?n.jsxs("header",{className:"android-workbench-topbar","data-header-kind":"tools",children:[n.jsxs("div",{className:"android-workbench-topbar-leading",children:[X.showBackButton?n.jsx("button",{type:"button",className:"android-workbench-icon-button","aria-label":r("common.back"),onClick:J,children:n.jsx(Ju,{})}):null,n.jsx("div",{className:"android-workbench-topbar-copy",children:n.jsx("h1",{children:X.title})})]}),n.jsx("div",{className:"android-workbench-topbar-actions",children:X.showMoreButton?n.jsx("button",{type:"button",className:"android-workbench-icon-button","aria-label":X.moreButtonLabel,onClick:b,children:n.jsx(Zu,{})}):null})]}):null,n.jsx("div",{className:"android-workbench-content",children:n.jsx(Vi,{viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!a,hasAuxiliaryPanel:!!i,preferCompactLayout:K,navigationPanel:a,auxiliaryPanel:i,children:s})}),E?n.jsxs("div",{className:"mobile-conversation-bottom-layer",children:[n.jsx("div",{ref:O,className:"mobile-conversation-bottom-layer-composer-slot"}),n.jsx("div",{className:"mobile-conversation-bottom-layer-tabbar-shell",children:Q})]}):Q]})})}function Ju(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"m15 18-6-6 6-6"}),n.jsx("path",{d:"M21 12H9"})]})}function Zu(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[n.jsx("circle",{cx:"12",cy:"5",r:"1.8"}),n.jsx("circle",{cx:"12",cy:"12",r:"1.8"}),n.jsx("circle",{cx:"12",cy:"19",r:"1.8"})]})}function Qu(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"}),n.jsx("path",{d:"M8 13h8"})]})}function eh(){return n.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H8l-5 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function th(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),n.jsx("path",{d:"m7.5 9 3 3-3 3"}),n.jsx("path",{d:"M12.5 15H17"})]})}function nh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("rect",{x:"5",y:"7",width:"14",height:"10",rx:"3"}),n.jsx("path",{d:"M9 7V5a3 3 0 0 1 6 0v2"}),n.jsx("circle",{cx:"10",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),n.jsx("circle",{cx:"14",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),n.jsx("path",{d:"M10 15c.6.5 1.2.8 2 .8s1.4-.3 2-.8"})]})}function sh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("circle",{cx:"12",cy:"12",r:"3"}),n.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06A1.65 1.65 0 0 0 4.6 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82L4.21 7.1a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 8.92 4a1.65 1.65 0 0 0 1-1.51V2.4a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9c0 .66.39 1.25 1 1.51h.09a2 2 0 0 1 0 4h-.09c-.61.26-1 .85-1 1.49z"})]})}const rh=120,mr={viewportHeight:null,keyboardInset:0,keyboardOpen:!1};function xi(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function ah(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable||e.closest("[contenteditable='true']"))return!0;if(e instanceof HTMLTextAreaElement)return!e.readOnly&&!e.disabled;if(e instanceof HTMLInputElement){if(e.readOnly||e.disabled)return!1;const t=(e.type||"text").toLowerCase();return!["button","checkbox","color","file","hidden","image","radio","range","reset","submit"].includes(t)}return!1}function ih(){var t;if(typeof window>"u")return 0;const e=[window.innerHeight,typeof document<"u"?(t=document.documentElement)==null?void 0:t.clientHeight:0].filter(xi);return e.length>0?Math.max(...e):0}function xo(){if(typeof window>"u")return mr;const e=window.visualViewport,t=ih(),s=(e==null?void 0:e.height)??t,a=xi(s)?Math.round(s):null,i=xi(e==null?void 0:e.offsetTop)?(e==null?void 0:e.offsetTop)??0:0,c=a===null?0:Math.max(0,Math.round(t-a-i));return{viewportHeight:a,keyboardInset:c,keyboardOpen:ah(typeof document<"u"?document.activeElement:null)&&c>=rh}}function ei(e,t){if(typeof document>"u")return;[document.documentElement,document.body].filter(a=>a instanceof HTMLElement).forEach(a=>{if(!e){delete a.dataset.mobileKeyboardOpen,delete a.dataset.mobileViewportBound,a.style.removeProperty("--mobile-shell-viewport-height"),a.style.removeProperty("--mobile-shell-keyboard-inset");return}a.dataset.mobileKeyboardOpen=String(t.keyboardOpen),a.dataset.mobileViewportBound="true",t.viewportHeight===null?a.style.removeProperty("--mobile-shell-viewport-height"):a.style.setProperty("--mobile-shell-viewport-height",`${t.viewportHeight}px`),a.style.setProperty("--mobile-shell-keyboard-inset",`${t.keyboardInset}px`)})}function oh(e){const[t,s]=o.useState(()=>e?xo():mr),a=o.useRef(null);return o.useEffect(()=>{if(!e){s(mr),ei(!1,mr);return}function i(){s(xo())}function c(){a.current!==null&&window.clearTimeout(a.current),a.current=window.setTimeout(()=>{a.current=null,i()},0)}i();const u=window.visualViewport;return window.addEventListener("resize",i),window.addEventListener("orientationchange",i),u==null||u.addEventListener("resize",i),u==null||u.addEventListener("scroll",i),document.addEventListener("focusin",i),document.addEventListener("focusout",c),()=>{a.current!==null&&(window.clearTimeout(a.current),a.current=null),window.removeEventListener("resize",i),window.removeEventListener("orientationchange",i),u==null||u.removeEventListener("resize",i),u==null||u.removeEventListener("scroll",i),document.removeEventListener("focusin",i),document.removeEventListener("focusout",c),ei(!1,mr)}},[e]),o.useEffect(()=>{ei(e,t)},[e,t]),t}function lh({activeEntry:e,presentation:t="default",children:s,navigationPanel:a,auxiliaryPanel:i,onNavigateWorkspaces:c,onNavigateTerminals:u,onNavigateSessions:h,onNavigateButler:k,onNavigateToolProcesses:b,onNavigateSettings:y}){const N=Vn(),A=Wi(),M=Pa(),L=Sr(),z=o.useRef(null),I=o.useRef(null),[w,O]=o.useState(null),E=t==="conversation-focus",K=Aa({isNativeMobile:N.isNativeMobile,viewportClass:N.viewportClass}),T=qi({enabled:E,rootRef:z,resetKey:`${M.pathname}${M.search}`}),H=jr({viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!a,hasAuxiliaryPanel:!!i,preferCompactLayout:K}),X=Gi({activeEntry:e,presentation:t,pathname:M.pathname,search:M.search,moreButtonLabel:r("shell.iosMoreAction")}),D=[{key:"workspaces",label:r("shell.mobileWorkspacesEntry"),icon:n.jsx(uh,{}),onClick:c},{key:"sessions",label:r("shell.mobileSessionsEntry"),icon:n.jsx(hh,{}),onClick:h},{key:"terminals",label:r("shell.mobileButlerEntry"),icon:n.jsx(mh,{}),onClick:k},{key:"butler",label:r("shell.mobileTerminalsEntry"),icon:n.jsx(ph,{}),onClick:u},{key:"settings",label:r("shell.mobileSettingsEntry"),icon:n.jsx(fh,{}),onClick:y}],j=E?{"--mobile-conversation-tabbar-progress":T.progress.toFixed(4)}:void 0;Ki(z,I,E);function J(){const B=Ui(M.pathname,M.search);if(!B){u();return}L(B,{replace:!0})}const Q=n.jsx("nav",{ref:I,className:"ios-workbench-tabbar","aria-label":r("shell.title"),children:D.map(B=>n.jsxs("button",{type:"button",className:"ios-workbench-tabbar-item","data-active":B.key===e,"aria-current":B.key===e?"page":void 0,onClick:()=>{B.key!==e&&A.trigger("selection"),B.onClick()},children:[n.jsx("span",{className:"ios-workbench-tabbar-icon","aria-hidden":"true",children:B.icon}),n.jsx("span",{className:"ios-workbench-tabbar-label",children:B.label})]},B.key))});return n.jsx(zi,{composerPortalTarget:E?w:null,children:n.jsxs("div",{ref:z,className:"ios-workbench-shell","data-active-entry":e,"data-mobile-presentation":t,"data-pane-layout":H,"data-tabbar-open":E?T.isOpen:!0,"data-conversation-tabbar-state":E?T.state:"default",style:j,children:[X?n.jsxs("header",{className:"ios-workbench-nav","data-header-kind":"tools",children:[n.jsx("div",{className:"ios-workbench-nav-leading",children:X.showBackButton?n.jsxs("button",{type:"button",className:"ios-workbench-back-button","aria-label":r("common.back"),onClick:J,children:[n.jsx(ch,{}),n.jsx("span",{children:r("common.back")})]}):null}),n.jsx("div",{className:"ios-workbench-nav-copy",children:n.jsx("h1",{children:X.title})}),n.jsx("div",{className:"ios-workbench-nav-actions",children:X.showMoreButton?n.jsx("button",{type:"button",className:"ios-workbench-icon-button","aria-label":X.moreButtonLabel,onClick:b,children:n.jsx(dh,{})}):null})]}):null,n.jsx("div",{className:"ios-workbench-content",children:n.jsx(Vi,{viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!a,hasAuxiliaryPanel:!!i,preferCompactLayout:K,navigationPanel:a,auxiliaryPanel:i,children:s})}),E?n.jsxs("div",{className:"mobile-conversation-bottom-layer",children:[n.jsx("div",{ref:O,className:"mobile-conversation-bottom-layer-composer-slot"}),n.jsx("div",{className:"mobile-conversation-bottom-layer-tabbar-shell",children:Q})]}):Q]})})}function ch(){return n.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.85",children:n.jsx("path",{d:"m15 18-6-6 6-6"})})}function dh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[n.jsx("circle",{cx:"12",cy:"5",r:"1.8"}),n.jsx("circle",{cx:"12",cy:"12",r:"1.8"}),n.jsx("circle",{cx:"12",cy:"19",r:"1.8"})]})}function uh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.85",children:[n.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"}),n.jsx("path",{d:"M8 13h8"})]})}function hh(){return n.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.85",children:n.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H8l-5 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function ph(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.85",children:[n.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),n.jsx("path",{d:"m7.5 9 3 3-3 3"}),n.jsx("path",{d:"M12.5 15H17"})]})}function mh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.85",children:[n.jsx("rect",{x:"5",y:"7",width:"14",height:"10",rx:"3"}),n.jsx("path",{d:"M9 7V5a3 3 0 0 1 6 0v2"}),n.jsx("circle",{cx:"10",cy:"12",r:".95",fill:"currentColor",stroke:"none"}),n.jsx("circle",{cx:"14",cy:"12",r:".95",fill:"currentColor",stroke:"none"}),n.jsx("path",{d:"M10 15c.6.5 1.2.8 2 .8s1.4-.3 2-.8"})]})}function fh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",children:[n.jsx("circle",{cx:"12",cy:"12",r:"3"}),n.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06A1.65 1.65 0 0 0 4.6 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82L4.21 7.1a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 8.92 4a1.65 1.65 0 0 0 1-1.51V2.4a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9c0 .66.39 1.25 1 1.51h.09a2 2 0 0 1 0 4h-.09c-.61.26-1 .85-1 1.49z"})]})}function bh(e){const t=Vn();return t.platform==="ios"?n.jsx(lh,{...e}):t.platform==="android"?n.jsx(Yu,{...e}):n.jsx(gh,{...e})}function gh({activeEntry:e,presentation:t="default",children:s,navigationPanel:a,auxiliaryPanel:i,onNavigateWorkspaces:c,onNavigateTerminals:u,onNavigateSessions:h,onNavigateButler:k,onNavigateToolProcesses:b,onNavigateSettings:y}){const N=Vn(),A=Wi(),M=Pa(),L=Sr(),z=o.useRef(null),I=o.useRef(null),[w,O]=o.useState(null),E=oh(N.platform==="web"),K=N.platform==="web"&&E.keyboardOpen,T=t==="conversation-focus",H=Aa({isNativeMobile:N.isNativeMobile,viewportClass:N.viewportClass}),X=qi({enabled:T,rootRef:z,suspended:K,resetKey:`${M.pathname}${M.search}`}),D=jr({viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!a,hasAuxiliaryPanel:!!i,preferCompactLayout:H}),j=Gi({activeEntry:e,presentation:t,pathname:M.pathname,search:M.search,moreButtonLabel:r("shell.iosMoreAction")}),J=[{key:"workspaces",label:r("shell.mobileWorkspacesEntry"),icon:n.jsx(vh,{}),onClick:c},{key:"sessions",label:r("shell.mobileSessionsEntry"),icon:n.jsx(xh,{}),onClick:h},{key:"terminals",label:r("shell.mobileButlerEntry"),icon:n.jsx(Sh,{}),onClick:k},{key:"butler",label:r("shell.mobileTerminalsEntry"),icon:n.jsx(yh,{}),onClick:u},{key:"settings",label:r("shell.mobileSettingsEntry"),icon:n.jsx(jh,{}),onClick:y}],Q=T?{"--mobile-conversation-tabbar-progress":X.progress.toFixed(4)}:void 0;Ki(z,I,T);function B(){const ae=Ui(M.pathname,M.search);if(!ae){u();return}L(ae,{replace:!0})}const le=n.jsx("nav",{ref:I,className:"mobile-workbench-tabbar","aria-label":r("shell.title"),hidden:K,children:J.map(ae=>n.jsxs("button",{type:"button",className:"mobile-workbench-tabbar-item","data-active":ae.key===e,"aria-current":ae.key===e?"page":void 0,onClick:()=>{ae.key!==e&&A.trigger("selection"),ae.onClick()},children:[n.jsx("span",{className:"mobile-workbench-tabbar-icon","aria-hidden":"true",children:ae.icon}),n.jsx("span",{className:"mobile-workbench-tabbar-label",children:ae.label})]},ae.key))});return n.jsx(zi,{composerPortalTarget:T?w:null,children:n.jsxs("div",{ref:z,className:"mobile-workbench-shell","data-active-entry":e,"data-mobile-presentation":t,"data-mobile-runtime":N.platform,"data-mobile-keyboard-open":K,"data-pane-layout":D,"data-tabbar-open":K?!1:T?X.isOpen:!0,"data-conversation-tabbar-state":T?X.state:"default",style:Q,children:[j?n.jsxs("header",{className:"mobile-workbench-header","data-header-kind":"tools",children:[n.jsxs("div",{className:"mobile-workbench-header-leading",children:[j.showBackButton?n.jsx("button",{type:"button",className:"mobile-workbench-header-button","aria-label":r("common.back"),onClick:B,children:n.jsx(kh,{})}):null,n.jsx("div",{className:"mobile-workbench-header-copy",children:n.jsx("h1",{children:j.title})})]}),n.jsx("div",{className:"mobile-workbench-header-actions",children:j.showMoreButton?n.jsx("button",{type:"button",className:"mobile-workbench-header-button mobile-tools-more-button","aria-label":j.moreButtonLabel,onClick:b,children:n.jsx(wh,{})}):null})]}):null,n.jsx("div",{className:"mobile-workbench-content",children:n.jsx(Vi,{viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!a,hasAuxiliaryPanel:!!i,preferCompactLayout:H,navigationPanel:a,auxiliaryPanel:i,children:s})}),T?n.jsxs("div",{className:"mobile-conversation-bottom-layer",children:[n.jsx("div",{ref:O,className:"mobile-conversation-bottom-layer-composer-slot"}),n.jsx("div",{className:"mobile-conversation-bottom-layer-tabbar-shell",children:le})]}):le]})})}function kh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[n.jsx("path",{d:"m15 18-6-6 6-6"}),n.jsx("path",{d:"M21 12H9"})]})}function wh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[n.jsx("circle",{cx:"12",cy:"5",r:"1.8"}),n.jsx("circle",{cx:"12",cy:"12",r:"1.8"}),n.jsx("circle",{cx:"12",cy:"19",r:"1.8"})]})}function vh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[n.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"}),n.jsx("path",{d:"M8 13h8"})]})}function xh(){return n.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:n.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H8l-5 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function yh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[n.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),n.jsx("path",{d:"m7.5 9 3 3-3 3"}),n.jsx("path",{d:"M12.5 15H17"})]})}function Sh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[n.jsx("rect",{x:"5",y:"7",width:"14",height:"10",rx:"3"}),n.jsx("path",{d:"M9 7V5a3 3 0 0 1 6 0v2"}),n.jsx("circle",{cx:"10",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),n.jsx("circle",{cx:"14",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),n.jsx("path",{d:"M10 15c.6.5 1.2.8 2 .8s1.4-.3 2-.8"})]})}function jh(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("circle",{cx:"12",cy:"12",r:"3"}),n.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06A1.65 1.65 0 0 0 4.6 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82L4.21 7.1a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 8.92 4a1.65 1.65 0 0 0 1-1.51V2.4a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9c0 .66.39 1.25 1 1.51h.09a2 2 0 0 1 0 4h-.09c-.61.26-1 .85-1 1.49z"})]})}class Ch{constructor(t){Pe(this,"maxAttempts");Pe(this,"baseDelayMs");Pe(this,"reconnectAttempts",0);Pe(this,"reconnectTimer",null);Pe(this,"disposed",!1);this.options=t,this.maxAttempts=t.maxAttempts??4,this.baseDelayMs=t.baseDelayMs??300}start(){this.options.onReconnect(!1)}markConnected(){this.reconnectAttempts=0,this.options.onStateChange("connected")}markTransientFailure(){this.disposed||this.reconnectAttempts>0||this.options.onStateChange("reconnecting")}markDisconnected(){if(this.disposed)return;if(!tn.getState().autoReconnect){this.options.onStateChange("reconnect_failed");return}if(this.reconnectAttempts+=1,this.reconnectAttempts>this.maxAttempts){this.options.onStateChange("reconnect_failed");return}this.options.onStateChange("reconnecting");const t=this.baseDelayMs*this.reconnectAttempts;this.reconnectTimer=window.setTimeout(()=>{this.options.onReconnect(!0)},t)}reconnectNow(){this.reconnectAttempts=0,this.reconnectTimer!==null&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.options.onReconnect(!0)}close(){this.disposed=!0,this.reconnectTimer!==null&&(window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.options.onStateChange("closed")}}class Nh{constructor(t){Pe(this,"socket",null);Pe(this,"disposed",!1);Pe(this,"authRecoveryInFlight",!1);Pe(this,"pendingRefresh",!1);Pe(this,"workbenchKnownRevision");Pe(this,"lastWorkbenchSnapshot",null);Pe(this,"fileTreeSubscription",null);Pe(this,"gitSubscription",null);Pe(this,"terminalManagerSubscription",null);Pe(this,"workspaceManagementSubscription",null);Pe(this,"pendingFileTreeRefresh",null);Pe(this,"pendingGitRefresh",null);Pe(this,"pendingTerminalManagerRefresh",null);Pe(this,"pendingWorkspaceManagementRefresh",null);Pe(this,"fileTreeRevisionByPath",new Map);Pe(this,"gitRevisionByWorkspaceId",new Map);Pe(this,"terminalManagerRevisionByWorkspaceId",new Map);Pe(this,"workspaceManagementRevisionByWorkspaceId",new Map);Pe(this,"fileTreeListeners",new Set);Pe(this,"gitListeners",new Set);Pe(this,"terminalManagerListeners",new Set);Pe(this,"workspaceManagementListeners",new Set);Pe(this,"workbenchSubscribeStartedAtMs",null);Pe(this,"workbenchRefreshStartedAtMs",null);Pe(this,"connectionManager");this.options=t,this.workbenchKnownRevision=null,this.connectionManager=new Ch({onReconnect:s=>{this.connect(s)},onStateChange:t.onConnectionChange})}start(){this.connectionManager.start()}requestRefresh(){const t=this.socket;if(!yo(t)){this.pendingRefresh=!0;return}this.workbenchRefreshStartedAtMs=performance.now(),t.send(JSON.stringify({type:"workbench.refresh",knownRevision:this.workbenchKnownRevision??void 0})),mt("workbench.refresh.sent",{knownRevision:this.workbenchKnownRevision}),this.pendingRefresh=!1}setWorkbenchKnownRevision(t){this.workbenchKnownRevision=Ht(t)}primeWorkbenchSnapshot(t){if(!t||!Array.isArray(t.items)){this.lastWorkbenchSnapshot=null,this.workbenchKnownRevision=null;return}this.lastWorkbenchSnapshot=t,this.workbenchKnownRevision=Ht(t.revision)??null}subscribeFileTree(t,s,a){this.fileTreeSubscription={workspaceId:t,paths:So(s),knownRevisionByPath:ti(a==null?void 0:a.knownRevisionByPath)},this.sendWhenReady({type:"fileTree.subscribe",workspaceId:t,paths:this.fileTreeSubscription.paths,knownRevisions:ni(t,this.fileTreeSubscription.paths,this.fileTreeSubscription.knownRevisionByPath,this.fileTreeRevisionByPath)})}requestFileTreeRefresh(t,s,a){const i=So(s),c={type:"fileTree.refresh",workspaceId:t,paths:i,knownRevisions:ni(t,i,ti(a==null?void 0:a.knownRevisionByPath),this.fileTreeRevisionByPath)};this.sendWhenReady(c)?this.pendingFileTreeRefresh=null:this.pendingFileTreeRefresh={workspaceId:t,paths:i,knownRevisionByPath:ti(a==null?void 0:a.knownRevisionByPath)}}subscribeGit(t,s){this.gitSubscription={workspaceId:t,knownRevision:Ht(s==null?void 0:s.knownRevision)},this.sendWhenReady({type:"git.subscribe",workspaceId:t,knownRevision:this.gitSubscription.knownRevision??this.gitRevisionByWorkspaceId.get(t)})}requestGitRefresh(t,s){const a={type:"git.refresh",workspaceId:t,knownRevision:Ht(s==null?void 0:s.knownRevision)??this.gitRevisionByWorkspaceId.get(t)};this.sendWhenReady(a)?this.pendingGitRefresh=null:this.pendingGitRefresh={workspaceId:t,knownRevision:Ht(s==null?void 0:s.knownRevision)}}subscribeTerminalManager(t,s){this.terminalManagerSubscription={workspaceId:t,knownRevision:Ht(s==null?void 0:s.knownRevision)},this.sendWhenReady({type:"terminalManager.subscribe",workspaceId:t,knownRevision:this.terminalManagerSubscription.knownRevision??this.terminalManagerRevisionByWorkspaceId.get(t)})}requestTerminalManagerRefresh(t,s){const a={type:"terminalManager.refresh",workspaceId:t,knownRevision:Ht(s==null?void 0:s.knownRevision)??this.terminalManagerRevisionByWorkspaceId.get(t)};this.sendWhenReady(a)?this.pendingTerminalManagerRefresh=null:this.pendingTerminalManagerRefresh={workspaceId:t,knownRevision:Ht(s==null?void 0:s.knownRevision)}}subscribeWorkspaceManagement(t,s){this.workspaceManagementSubscription={workspaceId:t,knownRevision:Ht(s==null?void 0:s.knownRevision)},this.sendWhenReady({type:"workspaceManagement.subscribe",workspaceId:t,knownRevision:this.workspaceManagementSubscription.knownRevision??this.workspaceManagementRevisionByWorkspaceId.get(t)})}requestWorkspaceManagementRefresh(t,s){const a={type:"workspaceManagement.refresh",workspaceId:t,knownRevision:Ht(s==null?void 0:s.knownRevision)??this.workspaceManagementRevisionByWorkspaceId.get(t)};this.sendWhenReady(a)?this.pendingWorkspaceManagementRefresh=null:this.pendingWorkspaceManagementRefresh={workspaceId:t,knownRevision:Ht(s==null?void 0:s.knownRevision)}}addFileTreeSnapshotListener(t){return this.fileTreeListeners.add(t),()=>{this.fileTreeListeners.delete(t)}}addGitSnapshotListener(t){return this.gitListeners.add(t),()=>{this.gitListeners.delete(t)}}addTerminalManagerSnapshotListener(t){return this.terminalManagerListeners.add(t),()=>{this.terminalManagerListeners.delete(t)}}addWorkspaceManagementSnapshotListener(t){return this.workspaceManagementListeners.add(t),()=>{this.workspaceManagementListeners.delete(t)}}close(){var t;this.disposed=!0,this.connectionManager.close(),(t=this.socket)==null||t.close(),this.socket=null}connect(t){var k;if(this.disposed)return;t&&this.socket&&(this.socket.close(),this.socket=null);const s=(k=xr.getState().session)==null?void 0:k.accessToken;if(!s){this.options.onUnauthorized();return}const a=Fl(),i=Cd(a),c=i.baseUrl,u=`${Nd("/ws",c)}?access_token=${encodeURIComponent(s)}`,h=i.transport.createWebSocket({path:"/ws",baseUrl:c,url:u});this.socket=h,h.addEventListener("open",()=>{this.workbenchSubscribeStartedAtMs=performance.now(),h.send(JSON.stringify({type:"workbench.subscribe",knownRevision:this.workbenchKnownRevision??void 0})),mt("workbench.subscribe.sent",{knownRevision:this.workbenchKnownRevision,baseUrl:c}),this.pendingRefresh&&this.requestRefresh(),this.fileTreeSubscription&&h.send(JSON.stringify({type:"fileTree.subscribe",workspaceId:this.fileTreeSubscription.workspaceId,paths:this.fileTreeSubscription.paths,knownRevisions:ni(this.fileTreeSubscription.workspaceId,this.fileTreeSubscription.paths,this.fileTreeSubscription.knownRevisionByPath,this.fileTreeRevisionByPath)})),this.pendingFileTreeRefresh&&this.requestFileTreeRefresh(this.pendingFileTreeRefresh.workspaceId,this.pendingFileTreeRefresh.paths,{knownRevisionByPath:this.pendingFileTreeRefresh.knownRevisionByPath}),this.gitSubscription&&h.send(JSON.stringify({type:"git.subscribe",workspaceId:this.gitSubscription.workspaceId,knownRevision:this.gitSubscription.knownRevision??this.gitRevisionByWorkspaceId.get(this.gitSubscription.workspaceId)})),this.pendingGitRefresh&&this.requestGitRefresh(this.pendingGitRefresh.workspaceId,{knownRevision:this.pendingGitRefresh.knownRevision}),this.terminalManagerSubscription&&h.send(JSON.stringify({type:"terminalManager.subscribe",workspaceId:this.terminalManagerSubscription.workspaceId,knownRevision:this.terminalManagerSubscription.knownRevision??this.terminalManagerRevisionByWorkspaceId.get(this.terminalManagerSubscription.workspaceId)})),this.pendingTerminalManagerRefresh&&this.requestTerminalManagerRefresh(this.pendingTerminalManagerRefresh.workspaceId,{knownRevision:this.pendingTerminalManagerRefresh.knownRevision}),this.workspaceManagementSubscription&&h.send(JSON.stringify({type:"workspaceManagement.subscribe",workspaceId:this.workspaceManagementSubscription.workspaceId,knownRevision:this.workspaceManagementSubscription.knownRevision??this.workspaceManagementRevisionByWorkspaceId.get(this.workspaceManagementSubscription.workspaceId)})),this.pendingWorkspaceManagementRefresh&&this.requestWorkspaceManagementRefresh(this.pendingWorkspaceManagementRefresh.workspaceId,{knownRevision:this.pendingWorkspaceManagementRefresh.knownRevision})}),h.addEventListener("message",b=>{var N,A,M,L,z,I,w,O,E,K;if(!(b instanceof MessageEvent)||typeof b.data!="string")return;const y=JSON.parse(b.data);if(y.type==="system.connected"){this.connectionManager.markConnected();return}if(y.type==="session.error"){y.error_code==="UNAUTHORIZED"&&this.handleUnauthorized();return}if(y.type==="workbench.snapshot"&&(mt("workbench.snapshot.received",{unchanged:y.unchanged,revision:y.revision,workspaceCount:((N=y.snapshot)==null?void 0:N.items.length)??0,sessionCount:y.snapshot?Mh(y.snapshot):0,subscribeDurationMs:na(this.workbenchSubscribeStartedAtMs),refreshDurationMs:na(this.workbenchRefreshStartedAtMs)}),this.workbenchRefreshStartedAtMs=null),y.type==="workbench.delta"){mt("workbench.delta.received",{baseRevision:y.baseRevision,revision:y.revision,changedWorkspaceCount:y.changedItems.length,removedWorkspaceCount:y.removedWorkspaceIds.length,subscribeDurationMs:na(this.workbenchSubscribeStartedAtMs),refreshDurationMs:na(this.workbenchRefreshStartedAtMs)}),this.workbenchRefreshStartedAtMs=null;const T=Th(this.lastWorkbenchSnapshot,y);if(!T){mt("workbench.delta.mismatch",{currentRevision:((A=this.lastWorkbenchSnapshot)==null?void 0:A.revision)??null,baseRevision:y.baseRevision,revision:y.revision}),this.workbenchKnownRevision=null,this.lastWorkbenchSnapshot=null,this.connectionManager.reconnectNow();return}this.lastWorkbenchSnapshot=T,this.workbenchKnownRevision=y.revision,this.options.onSnapshot(T);return}if(y.type==="fileTree.snapshot"){const T=y.snapshot;if(T)T.revision=y.revision,this.fileTreeRevisionByPath.set(yi(T.workspaceId,T.path),y.revision);else if(y.unchanged&&this.fileTreeSubscription)for(const H of this.fileTreeSubscription.paths)this.fileTreeRevisionByPath.set(yi(this.fileTreeSubscription.workspaceId,H),y.revision);if(!T)return;(L=(M=this.options).onFileTreeSnapshot)==null||L.call(M,T),this.fileTreeListeners.forEach(H=>H(T));return}if(y.type==="git.snapshot"){const T=y.snapshot;if(T?(T.revision=y.revision,this.gitRevisionByWorkspaceId.set(T.workspaceId,y.revision)):y.unchanged&&this.gitSubscription&&this.gitRevisionByWorkspaceId.set(this.gitSubscription.workspaceId,y.revision),!T)return;(I=(z=this.options).onGitSnapshot)==null||I.call(z,T),this.gitListeners.forEach(H=>H(T));return}if(y.type==="terminalManager.snapshot"){const T=y.snapshot;if(T?(T.revision=y.revision,this.terminalManagerRevisionByWorkspaceId.set(T.workspaceId,y.revision)):y.unchanged&&this.terminalManagerSubscription&&this.terminalManagerRevisionByWorkspaceId.set(this.terminalManagerSubscription.workspaceId,y.revision),!T)return;(O=(w=this.options).onTerminalManagerSnapshot)==null||O.call(w,T),this.terminalManagerListeners.forEach(H=>H(T));return}if(y.type==="workspaceManagement.snapshot"){const T=y.snapshot;if(T?(T.revision=y.revision,this.workspaceManagementRevisionByWorkspaceId.set(T.workspaceId,y.revision)):y.unchanged&&this.workspaceManagementSubscription&&this.workspaceManagementRevisionByWorkspaceId.set(this.workspaceManagementSubscription.workspaceId,y.revision),!T)return;(K=(E=this.options).onWorkspaceManagementSnapshot)==null||K.call(E,T),this.workspaceManagementListeners.forEach(H=>H(T));return}y.type==="workbench.snapshot"&&y.snapshot&&Ih(y.snapshot)?(y.snapshot.revision=y.revision,this.lastWorkbenchSnapshot=y.snapshot,this.workbenchKnownRevision=y.revision,this.options.onSnapshot(y.snapshot)):y.type==="workbench.snapshot"&&y.unchanged&&(this.workbenchKnownRevision=y.revision,this.lastWorkbenchSnapshot&&(this.lastWorkbenchSnapshot={...this.lastWorkbenchSnapshot,revision:y.revision}))}),h.addEventListener("close",()=>{this.disposed||this.socket!==h||this.connectionManager.markDisconnected()}),h.addEventListener("error",()=>{this.disposed||this.socket!==h||this.connectionManager.markTransientFailure()})}handleUnauthorized(){if(this.authRecoveryInFlight||this.disposed)return;this.authRecoveryInFlight=!0;const t=this.socket;this.socket=null,t==null||t.close(),xr.refresh().then(s=>{if(this.authRecoveryInFlight=!1,!this.disposed){if(s.status==="refreshed"){this.connectionManager.reconnectNow();return}if(s.status==="deferred"){this.connectionManager.markDisconnected();return}this.options.onUnauthorized()}})}sendWhenReady(t){const s=this.socket;return yo(s)?(s.send(JSON.stringify(t)),!0):!1}}function yo(e){return e!==null&&e.readyState===1}function Ih(e){return typeof e!="object"||e===null?!1:Array.isArray(e.items)}function So(e){const t=new Set;for(const s of e??[""])t.add(s.trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,""));return[...t]}function Ht(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function Th(e,t){if(!e||e.revision!==t.baseRevision)return null;const s=new Map(e.items.map(i=>[i.workspace.id,i]));for(const i of t.removedWorkspaceIds)s.delete(i);for(const i of t.changedItems)s.set(i.workspace.id,i);const a=[];for(const i of t.orderedWorkspaceIds){const c=s.get(i);if(!c)return null;a.push(c)}return{revision:t.revision,items:a}}function ti(e){return e?Object.fromEntries(Object.entries(e).map(([t,s])=>[t.trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,""),Ht(s)]).filter(t=>t[1]!==null)):{}}function ni(e,t,s,a){const i=t.map(c=>{const u=c.trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,"");return[u,s[u]??a.get(yi(e,u))??null]}).filter(c=>!!c[1]);if(i.length!==0)return Object.fromEntries(i)}function yi(e,t){return`${e}::${t}`}function Mh(e){return e.items.reduce((t,s)=>t+s.sessions.length+vc(s.childWorktrees??[]),0)}function vc(e){return e.reduce((t,s)=>{if(typeof s!="object"||s===null)return t;const a=s,i=Array.isArray(a.sessions)?a.sessions.length:0,c=Array.isArray(a.children)?vc(a.children):0;return t+i+c},0)}function na(e){return e===null||typeof performance>"u"?null:Math.round(performance.now()-e)}const jo=6,Rh=["button","a","input","textarea","select","summary","[role='button']","[role='link']","[role='tab']","[role='menuitem']","[contenteditable='true']","[data-window-drag='ignore']"].join(", ");function Eh(e){return e instanceof HTMLElement?!e.closest(Rh):!0}function Si(e,t,s){return e.isDesktop&&e.ui.osFamily==="macos"&&t===0&&Eh(s)}function xc(e){return e.isDesktop&&e.ui.osFamily==="macos"&&e.ui.prefersOverlayTitlebar}function yc(e){return xc(e)?"":void 0}function Ph(e){if(!Si(e.platform,e.button,e.target)||typeof window>"u")return;const t=e.clientX,s=e.clientY;let a=!0;const i=()=>{a&&(a=!1,window.removeEventListener("mousemove",c),window.removeEventListener("mouseup",u),window.removeEventListener("blur",h))},c=k=>{Math.abs(k.clientX-t)<jo&&Math.abs(k.clientY-s)<jo||(i(),Ah())},u=()=>{i()},h=()=>{i()};window.addEventListener("mousemove",c),window.addEventListener("mouseup",u),window.addEventListener("blur",h)}async function Ah(){typeof window>"u"||typeof window.__TAURI_INTERNALS__>"u"||await Yl().startDragging()}const Ta=.78,Wh=1;function Lh(){return typeof window<"u"&&typeof window.__TAURI_INTERNALS__<"u"}function Sc(e,t,s,a){const i=Math.hypot(s-e,a-t),c=Math.min(1,i/120);return Ta+(Wh-Ta)*c}function Kn(e){return Math.round(Number.isFinite(e)?e:0)}function Dh(e){if(!Lh())return null;const t=Kn(e.x),s=Kn(e.y);let a=!1,i=Promise.resolve();const c=(h,k)=>(i=i.then(async()=>{await window.__TAURI_INTERNALS__.invoke(h,k)}).catch(()=>{}),i),u=async()=>{a||(a=!0,await c("close_detach_preview"))};return c("show_detach_preview",{title:e.title,x:t,y:s,scale:Ta}),{updatePosition(h,k){if(a)return;const b=Kn(h),y=Kn(k);c("update_detach_preview_position",{x:b,y,scale:Sc(t,s,b,y)})},complete(){return u()},cancel(){return u()}}}function Bh(e){if(typeof document>"u")return null;const t=Kn(e.x),s=Kn(e.y),a=document.createElement("div");a.className="desktop-window-detach-animation",a.setAttribute("aria-hidden","true"),a.dataset.state="preview",a.style.left=`${t}px`,a.style.top=`${s}px`,a.style.setProperty("--detach-preview-scale",Ta.toFixed(3));const i=document.createElement("div");i.className="desktop-window-detach-animation-bar";const c=document.createElement("strong");c.className="desktop-window-detach-animation-title",c.textContent=e.title;const u=document.createElement("div");u.className="desktop-window-detach-animation-body",i.append(c),a.append(i,u),document.body.append(a);let h=!1;const k=()=>{h||(h=!0,a.remove())};return{updatePosition(b,y){if(h)return;const N=Kn(b),A=Kn(y),M=Sc(t,s,N,A);a.style.left=`${N}px`,a.style.top=`${A}px`,a.style.setProperty("--detach-preview-scale",M.toFixed(3))},async complete(){k()},async cancel(){k()}}}function Co(e){return Dh(e)??Bh(e)}const _h={files:{kind:"files",label:"文件",defaultFocusOwner:"file-context-panel"},git:{kind:"git",label:"Git",defaultFocusOwner:"git-sidebar"},processes:{kind:"processes",label:"调试",defaultFocusOwner:"terminal-manager-panel"},terminals:{kind:"terminals",label:"终端",defaultFocusOwner:"terminal-page"}};function Oh(e){return{...e,bounds:{...e.bounds}}}function Fh(e,t,s){t&&(e.windows.registerDescriptor(t),s?e.windows.markWindowOpen(t.windowId):e.windows.markWindowClosed(t.windowId))}function $h(e){return _h[e]}function jc(e,t){return`${e}-${t}`}async function Wa(e,t,s){const a=s.workspaceId.trim(),i=$h(t);if(!e.isDesktop||!e.bridge.supported)return{ok:!1,errorCode:"PLATFORM_NOT_SUPPORTED",detail:"当前运行环境不支持桌面外部窗口。"};if(!a)return{ok:!1,errorCode:"WINDOW_WORKSPACE_REQUIRED",detail:`${i.label}外部窗口必须绑定工作区。`};const c=jc(t,a),u=e.windows.getDescriptor(c),h=u?Oh(u):null,k=e.windows.isWindowOpen(c),b=Id({windowId:c,kind:t,workspaceId:a,workspaceName:s.workspaceName??(h==null?void 0:h.workspaceName)??null,sessionId:s.sessionId??(h==null?void 0:h.sessionId)??null,mode:"external",bounds:h==null?void 0:h.bounds,focusOwner:s.focusOwner??i.defaultFocusOwner});e.windows.registerDescriptor(b);const y=await e.bridge.createWindow(b);return y.ok?(e.windows.markWindowOpen(c),{ok:!0,value:b}):(h?Fh(e,h,k):e.windows.removeWindow(c),{ok:!1,errorCode:y.errorCode,detail:y.detail})}function Rg(e){return jc("terminals",e)}function Hh(e,t){return Wa(e,"files",t)}function Uh(e,t){return Wa(e,"git",t)}function Gh(e,t){return Wa(e,"processes",t)}function Eg(e,t){return Wa(e,"terminals",t)}async function No(){return await oe.request("/api/skills/overview")}async function zh(e){await oe.request("/api/skills",{method:"POST",body:JSON.stringify(e)})}async function Kh(e){await oe.request("/api/skills/import",{method:"POST",body:JSON.stringify(e)})}async function qh(e){await oe.request("/api/skills/sync",{method:"POST",body:JSON.stringify(e)})}async function Vh(){return await oe.request("/api/opencli/catalog")}async function Xh(){return await oe.request("/api/opencli/check",{method:"POST"})}async function Yh(e){return await oe.request("/api/opencli/config",{method:"POST",body:JSON.stringify(e)})}const si="all",ri="status";function Jh({toolbarMode:e="internal",onToolbarStateChange:t}={}){var me,We,Ve,ct;const s=Ri(S=>{var te;return((te=S.session)==null?void 0:te.accessToken)??null}),[a,i]=o.useState(null),[c,u]=o.useState(!1),[h,k]=o.useState(!1),[b,y]=o.useState(!1),[N,A]=o.useState(!1),[M,L]=o.useState([]),[z,I]=o.useState(null),[w,O]=o.useState(null),[E,K]=o.useState(si),[T,H]=o.useState(null),[X,D]=o.useState(!1),[j,J]=o.useState(""),[Q,B]=o.useState(ri);o.useEffect(()=>{let S=!0;if(!s){i(null),A(!1),L([]),O(null),I(null),u(!1),K(si),H(null),D(!1),J(""),B(ri);return}return(async()=>{u(!0);try{const q=await Vh();if(!S)return;de(q)}catch(q){if(!S)return;O(ai(q))}finally{S&&u(!1)}})(),()=>{S=!1}},[s]);const le=o.useMemo(()=>new Set(M),[M]),ae=o.useMemo(()=>ep((a==null?void 0:a.entries)??[]),[a==null?void 0:a.entries]),ee=o.useMemo(()=>rp(),[]);o.useEffect(()=>{ae.some(S=>S.id===E)||K(si)},[E,ae]);const _=o.useMemo(()=>((a==null?void 0:a.siteGroups)??[]).filter(S=>S.commands.some(te=>Io(te,E,le))),[E,a==null?void 0:a.siteGroups,le]),x=o.useMemo(()=>T?_.find(S=>S.site===T)??null:null,[T,_]);o.useEffect(()=>{T&&!x&&H(null)},[T,x]),o.useEffect(()=>{J(""),B(ri)},[T]);const R=o.useMemo(()=>{if(!x)return[];const S=j.trim().toLowerCase();return x.commands.filter(te=>Io(te,E,le)&&np(te,S)).sort((te,q)=>sp(te,q,{sortId:Q,selectedCommandIdSet:le}))},[E,x,j,Q,le]),$=!!(a&&(a.provider.enabled!==N||a.entries.some(S=>S.enabled!==le.has(S.commandId)))),Y=o.useMemo(()=>({draftEnabled:N,enableDisabled:c||h||b,refreshDisabled:!s||c||h||b,detailDisabled:!a||c,saveDisabled:!s||c||h||b||!a||!$,refreshing:h,saving:b,onEnabledChange:ie,onRefresh:()=>{Ce()},onShowDetails:()=>D(!0),onSave:()=>{ye()}}),[s,a,M,N,$,c,h,b]);o.useEffect(()=>{t==null||t(Y)},[t,Y]),o.useEffect(()=>()=>{t==null||t(null)},[t]);async function Ce(){if(s){k(!0),O(null),I(null);try{const S=await Xh();de(S),I(hp(S.refreshState,S.runtimeAvailability))}catch(S){O(ai(S))}finally{k(!1)}}}async function ye(){if(s){y(!0),O(null),I(null);try{const S=await Yh({enabled:N,enabledCommandIds:M});de(S),I(pp(S))}catch(S){O(ai(S))}finally{y(!1)}}}function de(S){i(S),A(S.provider.enabled),L(S.entries.filter(te=>te.enabled).map(te=>te.commandId).sort((te,q)=>te.localeCompare(q))),O(null)}function ie(S){A(S)}function Ne(S,te){const q=S.commands.map(fe=>fe.commandId);L(fe=>{const we=new Set(fe);for(const ue of q)te?we.add(ue):we.delete(ue);return[...we].sort((ue,st)=>ue.localeCompare(st))})}function pe(S,te){L(q=>{const fe=new Set(q);return te?fe.add(S):fe.delete(S),[...fe].sort((we,ue)=>we.localeCompare(ue))})}const ne=(a==null?void 0:a.summary)??{catalogCount:0,browserDependentCount:0,installState:"not_installed"};return n.jsxs("section",{className:"settings-opencli-panel settings-skill-section",children:[e==="internal"?n.jsx(Zh,{state:Y,className:"settings-opencli-inline-toolbar"}):null,n.jsxs("div",{className:"settings-skill-summary-grid",children:[n.jsx(sa,{label:r("settings.opencliSummaryInstallState"),value:Ro(ne.installState)}),n.jsx(sa,{label:r("settings.opencliSummaryCatalogCount"),value:String(ne.catalogCount)}),n.jsx(sa,{label:r("settings.opencliSummaryEnabledCount"),value:String(M.length)}),n.jsx(sa,{label:r("settings.opencliSummaryBrowserCount"),value:String(ne.browserDependentCount)})]}),z?n.jsx("p",{className:"settings-release-status",children:z}):null,w?n.jsx("p",{className:"settings-release-status",children:w}):null,c?n.jsx("div",{className:"settings-skill-empty",children:r("settings.opencliLoading")}):a!=null&&a.siteGroups.length?n.jsxs("section",{className:"settings-opencli-catalog-section settings-skill-section",children:[n.jsx("div",{className:"settings-model-tabs settings-opencli-filter-tabs",role:"tablist","aria-label":r("settings.opencliFilterTabsLabel"),children:ae.map(S=>{const te=E===S.id;return n.jsx("button",{type:"button",role:"tab",className:"settings-model-tab","aria-selected":te,"data-active":te?"true":"false",onClick:()=>K(S.id),children:S.label},S.id)})}),_.length>0?n.jsx("div",{className:"settings-opencli-site-grid",children:_.map(S=>{const te=tp(S,le),q=ap(S.commands),fe=Mo(S,{maxDescriptions:2}),we=Mo(S),ue=Nc(S.site),st=T===S.site;return n.jsxs("div",{className:"settings-opencli-site-card","data-selected":st?"true":"false",children:[n.jsxs("div",{className:"settings-opencli-site-card-head",children:[n.jsx("div",{className:"settings-opencli-site-card-visual",style:ue.style,children:n.jsx("span",{children:ue.label})}),n.jsxs("div",{className:"settings-opencli-site-card-body",children:[n.jsxs("div",{className:"settings-opencli-site-card-topline",children:[n.jsx("strong",{className:"settings-skill-entry-title",children:S.site}),n.jsxs("div",{className:"settings-opencli-site-card-actions",children:[n.jsx("button",{className:"ghost-button settings-opencli-site-detail-button",type:"button",onClick:()=>H(S.site),children:r("settings.opencliSiteViewAction")}),n.jsxs("label",{className:"settings-opencli-checkbox settings-opencli-site-toggle",children:[n.jsx("input",{"aria-label":r("settings.opencliSiteToggleLabel",{site:S.site}),type:"checkbox",checked:te.allSelected,disabled:h||b,ref:De=>{De&&(De.indeterminate=te.partialSelected)},onChange:De=>Ne(S,De.target.checked)}),n.jsx("span",{children:r("settings.opencliSiteEnableAction")})]})]})]}),n.jsx("p",{className:"settings-opencli-site-card-description",title:we,children:fe})]})]}),n.jsx("div",{className:"settings-opencli-site-card-summary",children:n.jsx("div",{className:"settings-opencli-site-card-tag-rows",children:n.jsx("div",{className:"settings-skill-tags settings-opencli-site-card-tag-row settings-opencli-site-card-type-row",children:(q.length>0?q:["unknown"]).slice(0,2).map(De=>n.jsx("span",{className:"settings-skill-tag settings-opencli-strategy-tag","data-strategy":Mc(De),children:Ic(De)},`${S.site}:${De}`))})})})]},S.site)})}):n.jsx("div",{className:"settings-skill-empty",children:r("settings.opencliFilteredEmpty")})]}):n.jsx("div",{className:"settings-skill-empty",children:mp(a)}),n.jsx(et,{open:X,title:r("settings.opencliDetailTitle"),className:"settings-opencli-detail-modal",onClose:()=>D(!1),children:a?n.jsxs(n.Fragment,{children:[n.jsx(Gs,{heading:r("settings.opencliDetailStatusHeading"),actions:n.jsxs("div",{className:"settings-opencli-detail-tags",children:[n.jsx(Zr,{children:Ro(a.provider.installState)}),n.jsx(Zr,{children:lp(a.provider.healthState)}),n.jsx(Zr,{children:dp(((me=a.activeRuntimeProfile)==null?void 0:me.status)??null)})]}),children:n.jsxs(Li,{compact:!0,className:"settings-opencli-detail-list",children:[n.jsx(Pt,{label:r("settings.opencliEnabledStateLabel"),trailing:n.jsx("span",{className:"settings-opencli-detail-value",children:N?r("settings.opencliEnabledStateOn"):r("settings.opencliEnabledStateOff")})}),n.jsx(Pt,{label:r("settings.opencliSummaryCatalogCount"),trailing:n.jsx("span",{className:"settings-opencli-detail-value",children:String(ne.catalogCount)})}),n.jsx(Pt,{label:r("settings.opencliSummaryEnabledCount"),trailing:n.jsx("span",{className:"settings-opencli-detail-value",children:String(M.length)})}),n.jsx(Pt,{label:r("settings.opencliSummaryBrowserCount"),trailing:n.jsx("span",{className:"settings-opencli-detail-value",children:String(ne.browserDependentCount)})}),n.jsx(Pt,{label:r("settings.opencliVersionLabel"),trailing:n.jsx("span",{className:"settings-opencli-detail-value",children:a.provider.version??"-"})}),n.jsx(Pt,{label:r("settings.opencliCatalogSourceLabel"),trailing:n.jsx("span",{className:"settings-opencli-detail-value",children:cp(a.effectiveCatalogSource??null)})}),n.jsx(Pt,{label:r("settings.opencliLastCheckedLabel"),trailing:n.jsx("span",{className:"settings-opencli-detail-value",children:Eo(a.provider.lastCheckedAt)})}),n.jsx(Pt,{label:r("settings.opencliCatalogRefreshedLabel"),trailing:n.jsx("span",{className:"settings-opencli-detail-value",children:Eo(a.provider.catalogRefreshedAt)})}),n.jsx(Pt,{label:r("settings.opencliInstallPathLabel"),description:a.provider.installPath??"-"}),n.jsx(Pt,{label:r("settings.opencliDetailRuntimeIdLabel"),description:a.provider.activeRuntimeId??"-"}),n.jsx(Pt,{label:r("settings.opencliDetailRuntimeRootLabel"),description:((We=a.activeRuntimeProfile)==null?void 0:We.runtimeRootPath)??"-"})]})}),a.provider.lastErrorDetail||(Ve=a.activeRuntimeProfile)!=null&&Ve.lastErrorDetail?n.jsx(Gs,{tone:"danger",heading:r("settings.opencliDetailErrorHeading"),children:n.jsxs("div",{className:"settings-opencli-detail-errors",children:[a.provider.lastErrorDetail?n.jsx("p",{className:"settings-skill-entry-meta",children:a.provider.lastErrorDetail}):null,(ct=a.activeRuntimeProfile)!=null&&ct.lastErrorDetail?n.jsx("p",{className:"settings-skill-entry-meta",children:a.activeRuntimeProfile.lastErrorDetail}):null]})}):null]}):null}),n.jsx(et,{open:x!==null,title:x?r("settings.opencliSiteDetailTitle",{site:x.site}):r("settings.opencliCommandModalFallbackTitle"),description:x?r("settings.opencliSiteDetailDescription",{count:R.length,total:x.totalCount}):void 0,className:"settings-opencli-command-modal",onClose:()=>H(null),children:x?n.jsxs("section",{className:"settings-skill-section",children:[n.jsx(Gs,{heading:r("settings.opencliSiteDescriptionHeading"),children:n.jsx("div",{className:"settings-opencli-site-detail-copy",children:Cc(x.commands).map(S=>n.jsx("p",{className:"settings-opencli-site-detail-description",children:S},S))})}),n.jsx(Gs,{heading:r("settings.opencliCommandSearchLabel"),actions:n.jsx(Zr,{children:r("settings.opencliCommandResultCount",{count:R.length})}),children:n.jsxs("div",{className:"settings-opencli-command-tools",children:[n.jsxs("label",{className:"settings-opencli-command-search",htmlFor:"opencli-command-search",children:[n.jsx("span",{className:"settings-opencli-command-search-label",children:r("settings.opencliCommandSearchLabel")}),n.jsx("input",{id:"opencli-command-search",className:"settings-text-input",type:"search",value:j,placeholder:r("settings.opencliCommandSearchPlaceholder"),onChange:S=>J(S.target.value)})]}),n.jsxs("div",{className:"settings-opencli-command-sort",children:[n.jsx("span",{className:"settings-opencli-command-search-label",children:r("settings.opencliCommandSortLabel")}),n.jsx("div",{className:"settings-opencli-command-sort-tabs",role:"tablist","aria-label":r("settings.opencliCommandSortLabel"),children:ee.map(S=>{const te=Q===S.id;return n.jsx("button",{type:"button",role:"tab",className:"settings-model-tab settings-opencli-command-sort-button","aria-selected":te,"data-active":te?"true":"false",onClick:()=>B(S.id),children:S.label},S.id)})})]})]})}),R.length>0?n.jsx("div",{className:"settings-opencli-command-grid",children:R.map(S=>n.jsx(Qh,{command:S,checked:le.has(S.commandId),disabled:h||b,onToggle:pe},S.commandId))}):n.jsx(Gl,{compact:!0,title:r("settings.opencliCommandModalEmpty")})]}):null})]})}function Zh({state:e,className:t}){return n.jsxs("div",{className:`settings-opencli-toolbar${t?` ${t}`:""}`,children:[n.jsxs("label",{className:"settings-opencli-checkbox settings-opencli-toolbar-toggle",children:[n.jsx("input",{"aria-label":r("settings.opencliProviderToggleLabel"),type:"checkbox",checked:e.draftEnabled,disabled:e.enableDisabled,onChange:s=>e.onEnabledChange(s.target.checked)}),n.jsx("span",{children:r("settings.opencliEnableAction")})]}),n.jsx("button",{className:"secondary-button",type:"button",disabled:e.refreshDisabled,onClick:e.onRefresh,children:e.refreshing?r("common.loading"):r("settings.opencliRefreshAction")}),n.jsx("button",{className:"secondary-button",type:"button",disabled:e.detailDisabled,onClick:e.onShowDetails,children:r("settings.opencliDetailAction")}),n.jsx("button",{className:"primary-button",type:"button",disabled:e.saveDisabled,onClick:e.onSave,children:e.saving?r("common.loading"):r("settings.opencliSaveAction")})]})}function Qh({command:e,checked:t,disabled:s,onToggle:a}){const i=Nc(e.commandId);return n.jsxs("div",{className:"settings-opencli-command-card",children:[n.jsxs("div",{className:"settings-opencli-command-card-head",children:[n.jsx("div",{className:"settings-opencli-command-badge",style:i.style,children:n.jsx("span",{children:e.name.slice(0,1).toUpperCase()})}),n.jsxs("div",{className:"settings-opencli-command-card-main",children:[n.jsxs("label",{className:"settings-opencli-checkbox",children:[n.jsx("input",{"aria-label":r("settings.opencliCommandToggleLabel",{commandId:e.commandId}),type:"checkbox",checked:t,disabled:s,onChange:c=>a(e.commandId,c.target.checked)}),n.jsx("span",{children:e.commandId})]}),n.jsx("p",{className:"settings-skill-entry-meta",children:e.description||r("settings.opencliCommandDescriptionEmpty")})]})]}),n.jsxs("div",{className:"settings-skill-tags",children:[n.jsx("span",{className:"settings-skill-tag settings-opencli-strategy-tag","data-strategy":Mc(e.strategy),children:up(e.strategy)}),e.browser?n.jsx("span",{className:"settings-skill-tag","data-status":"failed",children:r("settings.opencliBrowserTag")}):n.jsx("span",{className:"settings-skill-tag","data-status":"synced",children:r("settings.opencliHttpTag")})]})]})}function sa({label:e,value:t}){return n.jsxs("div",{className:"settings-skill-summary-card",children:[n.jsx("span",{children:e}),n.jsx("strong",{children:t})]})}function ep(e){const t=Array.from(new Set(e.map(s=>s.strategy.trim()).filter(s=>s.length>0&&s!=="unknown"))).sort((s,a)=>s.localeCompare(a));return[{id:"all",label:r("settings.opencliFilterAll")},{id:"enabled",label:r("settings.opencliFilterEnabled")},{id:"browser",label:r("settings.opencliFilterBrowser")},{id:"direct",label:r("settings.opencliFilterDirect")},...t.map(s=>({id:`strategy:${s}`,label:r("settings.opencliFilterStrategy",{strategy:Ic(s)})}))]}function Io(e,t,s){switch(t){case"all":return!0;case"enabled":return s.has(e.commandId);case"browser":return e.browser;case"direct":return!e.browser;default:return t.startsWith("strategy:")?e.strategy===t.slice(9):!0}}function tp(e,t){const s=e.commands.filter(a=>t.has(a.commandId)).length;return{selectedCount:s,allSelected:s>0&&s===e.commands.length,partialSelected:s>0&&s<e.commands.length}}function np(e,t){return t?[e.commandId,e.name,e.description,e.strategy].join(`
3
+ `).toLowerCase().includes(t):!0}function sp(e,t,s){const a=To(e,s)-To(t,s);if(a!==0)return a;const i=e.name.localeCompare(t.name);return i!==0?i:e.commandId.localeCompare(t.commandId)}function To(e,t){const s=t.selectedCommandIdSet.has(e.commandId)?0:1,a=e.browser?1:0;switch(t.sortId){case"browser":return(e.browser?0:2)+s;case"name":return 0;case"status":default:return s*2+a}}function rp(){return[{id:"status",label:r("settings.opencliCommandSortStatus")},{id:"browser",label:r("settings.opencliCommandSortBrowser")},{id:"name",label:r("settings.opencliCommandSortName")}]}function Cc(e){return Array.from(new Set(e.map(t=>t.description.trim()).filter(t=>t.length>0)))}function Mo(e,t={}){const s=Cc(e.commands);if(s.length===0)return r("settings.opencliSiteDescriptionEmpty");const a=t.maxDescriptions??s.length;return s.slice(0,a).join(" · ")}function ap(e){return Array.from(new Set(e.map(t=>t.strategy.trim()).filter(t=>t.length>0&&t!=="unknown"))).sort((t,s)=>t.localeCompare(s))}function Nc(e){const t=fp[e.toLowerCase()];if(t)return{label:t.label,style:{background:t.background}};const s=Po[Math.abs(op(e))%Po.length];return{label:ip(e),style:{background:`linear-gradient(135deg, ${s[0]} 0%, ${s[1]} 100%)`}}}function ip(e){const t=e.split(/[^a-z0-9]+/i).map(a=>a.trim()).filter(a=>a.length>0);if(t.length>=2)return`${t[0][0]??""}${t[1][0]??""}`.toUpperCase();const s=t[0]??e;return s.slice(0,Math.min(2,s.length)).toUpperCase()}function op(e){let t=0;for(const s of e)t=(t<<5)-t+s.charCodeAt(0),t|=0;return t}function ai(e){return e instanceof Ei?e.message||r("settings.opencliLoadFailed"):e instanceof Error?e.message:r("settings.opencliLoadFailed")}function Ro(e){switch(e){case"installed":return r("settings.opencliInstallInstalled");case"broken":return r("settings.opencliInstallBroken");default:return r("settings.opencliInstallMissing")}}function lp(e){switch(e){case"ready":return r("settings.opencliHealthReady");case"bridge_missing":return r("settings.opencliHealthBridgeMissing");case"binary_ready":return r("settings.opencliHealthBinaryReady");case"runtime_build_failed":return r("settings.opencliHealthRuntimeBuildFailed");default:return r("settings.opencliHealthUnknown")}}function cp(e){switch(e){case"manifest":return r("settings.opencliCatalogSourceManifest");case"cli_list":return r("settings.opencliCatalogSourceCliList");case"local_manifest":return r("settings.opencliCatalogSourceLocalManifest");case"cache":return r("settings.opencliCatalogSourceCache");default:return"-"}}function dp(e){switch(e){case"ready":return r("settings.opencliRuntimeReady");case"failed":return r("settings.opencliRuntimeFailed");case"pending":return r("settings.opencliRuntimePending");case"stale":return r("settings.opencliRuntimeStale");default:return r("settings.opencliRuntimeIdle")}}function up(e){return r("settings.opencliStrategyLabel",{strategy:Tc(e)})}function Ic(e){return r("settings.opencliStrategyShortLabel",{strategy:Tc(e)})}function Tc(e){switch(Rc(e)){case"cookie":return r("settings.opencliStrategyCookie");case"header":return r("settings.opencliStrategyHeader");case"intercept":return r("settings.opencliStrategyIntercept");case"local":return r("settings.opencliStrategyLocal");case"public":return r("settings.opencliStrategyPublic");case"ui":return r("settings.opencliStrategyUi");default:return r("settings.opencliStrategyUnknown")}}function Mc(e){return Rc(e)}function Rc(e){const t=e.trim().toLowerCase();return t.length>0?t:"unknown"}function hp(e,t){return e==="cache_retained"?r("settings.opencliRefreshCacheRetained"):e==="unavailable"?r("settings.opencliRefreshUnavailable"):t==="ready"?r("settings.opencliRefreshReady"):r("settings.opencliRefreshDone")}function pp(e){return e.runtimeAvailability==="ready"?r("settings.opencliSaveReady"):e.provider.enabled?r("settings.opencliSaveEnabled"):r("settings.opencliSaveDisabled")}function mp(e){return e?e.provider.installState!=="installed"?r("settings.opencliEmptyNotInstalled"):r("settings.opencliEmpty"):r("settings.opencliEmpty")}function Eo(e){if(!e)return"-";const t=Date.parse(e);return Number.isNaN(t)?e:new Date(t).toLocaleString()}const Po=[["#2563eb","#0ea5e9"],["#0f766e","#14b8a6"],["#7c3aed","#6366f1"],["#ea580c","#f59e0b"],["#be123c","#f43f5e"],["#1d4ed8","#38bdf8"]],fp={github:{label:"GH",background:"linear-gradient(135deg, #111827 0%, #374151 100%)"},hackernews:{label:"HN",background:"linear-gradient(135deg, #f97316 0%, #fb923c 100%)"},twitter:{label:"TW",background:"linear-gradient(135deg, #2563eb 0%, #38bdf8 100%)"},x:{label:"X",background:"linear-gradient(135deg, #111827 0%, #6b7280 100%)"},reddit:{label:"RD",background:"linear-gradient(135deg, #f97316 0%, #ef4444 100%)"}},bp=[{id:"skills"},{id:"opencli"}];function gp({triggerClassName:e="secondary-button",triggerLabel:t,triggerLeading:s}){const a=Ri(m=>{var C;return((C=m.session)==null?void 0:C.accessToken)??null}),i=o.useRef(null),[c,u]=o.useState(null),[h,k]=o.useState([]),[b,y]=o.useState(!1),[N,A]=o.useState(null),[M,L]=o.useState(null),[z,I]=o.useState(null),[w,O]=o.useState(!1),[E,K]=o.useState(!1),[T,H]=o.useState(null),[X,D]=o.useState("file"),[j,J]=o.useState("workspace"),[Q,B]=o.useState(""),[le,ae]=o.useState(()=>hr("workspace")),[ee,_]=o.useState("skills"),[x,R]=o.useState(null),$=o.useId(),Y=Cp(h);o.useEffect(()=>{let m=!0;if(!w)return;if(!a){u(null),k([]),L(null),I(null),y(!1);return}return(async()=>{y(!0);try{const[G,se]=await Promise.all([No(),so()]);if(!m)return;u(G),k(se),L(null)}catch(G){if(!m)return;L(_s(G))}finally{m&&y(!1)}})(),()=>{m=!1}},[a,w]);async function Ce(){const[m,C]=await Promise.all([No(),so()]);u(m),k(C),L(null)}async function ye(){if(a){A("refresh"),L(null),I(null);try{await Ce(),I(r("settings.skillRefreshSuccess"))}catch(m){L(_s(m))}finally{A(null)}}}async function de(m){if(a){A(Ao(m)),L(null),I(null);try{await Kh({targetCli:m.targetCli,directoryPath:m.directoryPath,expectedContentHash:m.contentHash}),await Ce(),I(r("settings.skillImportSuccess",{name:m.name,target:At(m.targetCli)}))}catch(C){L(_s(C))}finally{A(null)}}}async function ie(m){if(!a)return;const C=m.bindings.filter(G=>G.enabled).map(G=>G.targetCli).filter(G=>xt(G,Y));if(C.length===0){L(Ap(m.bindings));return}A(Wo(m.skill.id)),L(null),I(null);try{await qh({skillId:m.skill.id,targetCli:C}),await Ce(),I(r("settings.skillSyncSuccess",{name:m.skill.name}))}catch(G){L(_s(G))}finally{A(null)}}async function Ne(m){var G;const C=((G=m.target.files)==null?void 0:G[0])??null;if(m.target.value="",!!C){L(null),I(null);try{const se=await Fp(C),he=Ac(C.name,se);H(he),ae(hr(j,Y))}catch(se){L(_s(se))}}}async function pe(){const m=Lo({sourceMode:X,fileDraft:T,pastedMarkdown:Q});if(!a)return;if(!m){L(X==="paste"?r("settings.skillPasteEmpty"):r("settings.skillUploadEmpty"));return}const C=m.directoryName;if(!C){L(r("settings.skillUploadDirectoryInvalid"));return}const G=Ma(j).filter(se=>le[se]).filter(se=>xt(se,Y)).map(se=>se);if(G.length===0){L(Wp(j,Y));return}A("upload"),L(null),I(null);try{await zh({markdownContent:m.rawContent,scope:j,fileName:m.fileName,directoryName:C,targetCli:G}),await Ce(),I(r("settings.skillUploadSuccess",{name:C})),S(j),K(!1)}catch(se){L(_s(se))}finally{A(null)}}function ne(m){J(m),ae(hr(m,Y))}function me(m){D(m),H(null),B(""),ae(hr(j,Y)),L(null)}function We(m){xt(m,Y)&&ae(C=>({...C,[m]:!C[m]}))}function Ve(){K(!0),L(null),S(j)}function ct(){K(!1),L(null),S(j)}function S(m){H(null),B(""),D("file"),ae(hr(m,Y))}const te=(c==null?void 0:c.summary)??{managedSkillCount:0,managedEntryCount:0},q=Bp((c==null?void 0:c.assistantRuntimeSkills)??[],(c==null?void 0:c.conflictedEntries)??[],(c==null?void 0:c.diagnostics)??[]),fe=((c==null?void 0:c.conflictedEntries)??[]).filter(m=>!Pc(m,(c==null?void 0:c.diagnostics)??[])),we=((c==null?void 0:c.diagnostics)??[]).filter(m=>!Cr(m)),ue=Lo({sourceMode:X,fileDraft:T,pastedMarkdown:Q}),st=t??r("settings.skillManageAction"),De=ee==="skills",Xe=ee==="opencli";return n.jsxs(n.Fragment,{children:[n.jsxs("button",{className:e,type:"button","data-open":w?"true":"false","aria-haspopup":"dialog","aria-expanded":w,onClick:()=>{_("skills"),O(!0)},children:[s,n.jsx("span",{children:st})]}),n.jsxs(et,{open:w,title:r("settings.skillConfigModalTitle"),hideHeader:!0,className:"settings-skill-modal",onClose:()=>{_("skills"),O(!1)},children:[n.jsxs("div",{className:"settings-skill-modal-topbar",children:[n.jsxs("div",{className:"settings-skill-modal-topbar-main",children:[n.jsx("div",{className:"settings-model-tabs settings-skill-tabs",role:"tablist","aria-label":r("settings.skillConfigTabsLabel"),children:bp.map(m=>{const C=ee===m.id,G=`${$}-${m.id}-tab`,se=`${$}-${m.id}-panel`;return n.jsx("button",{id:G,type:"button",role:"tab",className:"settings-model-tab","aria-selected":C,"aria-controls":se,"data-active":C?"true":"false",onClick:()=>_(m.id),children:Up(m.id)},m.id)})}),De?n.jsxs("div",{className:"settings-skill-modal-actions settings-skill-page-toolbar",children:[n.jsx("button",{className:"secondary-button",type:"button",disabled:!a||b||N!==null,onClick:Ve,children:r("settings.skillCreateAction")}),n.jsx("button",{className:"secondary-button",type:"button",disabled:!a||b||N!==null,onClick:()=>{ye()},children:N==="refresh"?r("common.loading"):r("settings.skillRefresh")})]}):null,Xe&&x?n.jsxs("div",{className:"settings-skill-modal-actions settings-skill-page-toolbar settings-opencli-toolbar",children:[n.jsxs("label",{className:"settings-opencli-checkbox settings-opencli-toolbar-toggle",children:[n.jsx("input",{"aria-label":r("settings.opencliProviderToggleLabel"),type:"checkbox",checked:x.draftEnabled,disabled:x.enableDisabled,onChange:m=>x.onEnabledChange(m.target.checked)}),n.jsx("span",{children:r("settings.opencliEnableAction")})]}),n.jsx("button",{className:"secondary-button",type:"button",disabled:x.refreshDisabled,onClick:x.onRefresh,children:x.refreshing?r("common.loading"):r("settings.opencliRefreshAction")}),n.jsx("button",{className:"secondary-button",type:"button",disabled:x.detailDisabled,onClick:x.onShowDetails,children:r("settings.opencliDetailAction")}),n.jsx("button",{className:"primary-button",type:"button",disabled:x.saveDisabled,onClick:x.onSave,children:x.saving?r("common.loading"):r("settings.opencliSaveAction")})]}):null]}),n.jsx(du,{onClick:()=>{_("skills"),O(!1)}})]}),De?n.jsxs("div",{id:`${$}-skills-panel`,role:"tabpanel","aria-labelledby":`${$}-skills-tab`,className:"settings-skill-panel",children:[n.jsxs("section",{className:"settings-skill-summary-block",children:[n.jsxs("div",{className:"settings-skill-summary-grid",children:[n.jsx(ra,{label:r("settings.skillSummaryManagedSkills"),value:String(te.managedSkillCount)}),n.jsx(ra,{label:r("settings.skillSummaryManagedEntries"),value:String(te.managedEntryCount)}),n.jsx(ra,{label:r("settings.skillSummaryConflictedEntries"),value:String(fe.length)}),n.jsx(ra,{label:r("settings.skillSummaryDiagnostics"),value:String(we.length)})]}),n.jsx("div",{className:"settings-release-meta",children:n.jsxs("span",{children:[r("settings.skillScannedAt"),": ",b?r("common.loading"):Dp(c==null?void 0:c.scannedAt)]})}),z?n.jsx("p",{className:"settings-release-status",children:z}):null,M?n.jsx("p",{className:"settings-release-status",children:M}):null]}),n.jsx(ur,{title:r("settings.skillManagedListTitle"),emptyText:r("settings.skillManagedEmpty"),items:(c==null?void 0:c.managedSkills)??[],renderItem:m=>{const C=Wo(m.skill.id);return n.jsxs("div",{className:"settings-skill-entry",children:[n.jsxs("div",{className:"settings-skill-entry-main",children:[n.jsx("strong",{className:"settings-skill-entry-title",children:m.skill.name}),n.jsx("p",{className:"settings-skill-entry-meta",children:Rp(m.bindings)}),n.jsx("div",{className:"settings-skill-tags",children:m.bindings.map(G=>n.jsx("span",{className:"settings-skill-tag","data-status":Tp(G,Y),children:Mp(G,Y)},`${m.skill.id}-${G.targetCli}`))})]}),n.jsx("div",{className:"settings-skill-entry-actions",children:n.jsx("button",{className:"secondary-button",type:"button",disabled:b||N!==null||!Ip(m.bindings,Y),onClick:()=>{ie(m)},children:N===C?r("common.loading"):r("settings.skillSyncAction")})})]},m.skill.id)}}),n.jsx(ur,{title:r("settings.skillUnmanagedListTitle"),emptyText:r("settings.skillUnmanagedEmpty"),items:(c==null?void 0:c.unmanagedEntries)??[],renderItem:m=>{const C=Ao(m);return n.jsxs("div",{className:"settings-skill-entry",children:[n.jsxs("div",{className:"settings-skill-entry-main",children:[n.jsx("strong",{className:"settings-skill-entry-title",children:m.name}),n.jsx("p",{className:"settings-skill-entry-meta",children:Ep(m,Y)}),xt(m.targetCli,Y)?null:n.jsx("div",{className:"settings-skill-tags",children:n.jsx("span",{className:"settings-skill-tag","data-status":"failed",children:r("settings.skillTargetDisabledTag")})})]}),n.jsx("div",{className:"settings-skill-entry-actions",children:n.jsx("button",{className:"secondary-button",type:"button",disabled:b||N!==null||!xt(m.targetCli,Y),onClick:()=>{de(m)},children:N===C?r("common.loading"):r("settings.skillImportAction")})})]},`${m.targetCli}:${m.directoryPath}`)}}),n.jsx(ur,{title:r("settings.skillAssistantRuntimeListTitle"),description:r("settings.skillAssistantRuntimeListDescription"),emptyText:r("settings.skillAssistantRuntimeEmpty"),items:q,renderItem:m=>n.jsx("div",{className:"settings-skill-entry",children:n.jsxs("div",{className:"settings-skill-entry-main",children:[n.jsx("strong",{className:"settings-skill-entry-title",children:m.name}),n.jsx("p",{className:"settings-skill-entry-meta",children:r("settings.skillAssistantRuntimeItemDescription")}),n.jsxs("p",{className:"settings-skill-entry-meta",children:[r("settings.skillAssistantRuntimeUsedBy"),": ",Ec(m.usedByTargetCli)]}),n.jsxs("div",{className:"settings-skill-tags",children:[n.jsx("span",{className:"settings-skill-tag","data-status":"assistant-runtime",children:r("settings.skillTagAssistantOnly")}),m.usedByTargetCli.map(C=>n.jsx("span",{className:"settings-skill-tag","data-status":xt(C,Y)?"synced":"failed",children:xt(C,Y)?At(C):`${At(C)} · ${r("settings.skillTargetDisabledTag")}`},`${m.directoryName}:${C}`))]})]})},`${m.directoryName}:${m.sourcePath}`)}),n.jsx(ur,{title:r("settings.skillConflictedListTitle"),emptyText:r("settings.skillConflictedEmpty"),items:fe,renderItem:m=>{const C=_p(m,(c==null?void 0:c.diagnostics)??[]);return n.jsx("div",{className:"settings-skill-entry",children:n.jsxs("div",{className:"settings-skill-entry-main",children:[n.jsx("strong",{className:"settings-skill-entry-title",children:m.name}),n.jsx("p",{className:"settings-skill-entry-meta",children:Pp(m,Y)}),C.length>0?n.jsx("div",{className:"settings-skill-tags",children:C.map(G=>n.jsx("span",{className:"settings-skill-tag","data-status":G.status,children:G.label},G.key))}):null]})},`${m.targetCli}:${m.directoryPath}`)}}),n.jsx(ur,{title:r("settings.skillDiagnosticsTitle"),emptyText:r("settings.skillDiagnosticsEmpty"),items:we,renderItem:m=>{const C=Op(m),G=Lp(m);return n.jsx("div",{className:"settings-skill-entry",children:n.jsxs("div",{className:"settings-skill-entry-main",children:[n.jsx("strong",{className:"settings-skill-entry-title",children:G.title}),n.jsx("p",{className:"settings-skill-entry-meta",children:G.detail}),C.length>0?n.jsx("div",{className:"settings-skill-tags",children:C.map(se=>n.jsx("span",{className:"settings-skill-tag","data-status":se.status,children:se.label},se.key))}):null]})},`${m.targetCli}:${m.code}:${m.directoryPath??m.rootDir}`)}})]}):n.jsx("div",{id:`${$}-opencli-panel`,role:"tabpanel","aria-labelledby":`${$}-opencli-tab`,className:"settings-skill-panel",children:n.jsx(Jh,{toolbarMode:"external",onToolbarStateChange:R})})]}),n.jsx(et,{open:E,title:r("settings.skillCreateModalTitle"),description:r("settings.skillCreateModalDescription"),className:"settings-skill-create-modal",onClose:ct,children:n.jsxs("section",{className:"settings-skill-section",children:[n.jsx("h3",{className:"settings-skill-section-title",children:r("settings.skillUploadSectionTitle")}),n.jsx("p",{className:"settings-skill-section-description",children:r("settings.skillUploadSectionDescription")}),n.jsxs("div",{className:"settings-skill-create-panel",children:[n.jsx("input",{ref:i,type:"file",accept:".md,text/markdown,text/plain",className:"settings-skill-upload-input",onChange:m=>{Ne(m)}}),n.jsx("div",{className:"settings-model-tabs",role:"tablist","aria-label":r("settings.skillCreateSourceTabsLabel"),children:xp.map(m=>{const C=X===m;return n.jsx("button",{type:"button",role:"tab",className:"settings-model-tab","aria-selected":C,"data-active":C?"true":"false",onClick:()=>me(m),children:Sp(m)},m)})}),n.jsx("div",{className:"settings-skill-upload-targets",role:"radiogroup","aria-label":r("settings.skillUploadScopeLabel"),children:vp.map(m=>n.jsxs("label",{className:"settings-skill-upload-target","data-selected":j===m?"true":"false",children:[n.jsx("input",{type:"radio",name:"skill-upload-scope",checked:j===m,onChange:()=>ne(m)}),n.jsx("span",{children:yp(m)})]},m))}),X==="file"?n.jsx("div",{className:"settings-skill-create-toolbar",children:n.jsx("button",{className:"secondary-button",type:"button",disabled:b||N!==null,onClick:()=>{var m;(m=i.current)==null||m.click()},children:r("settings.skillUploadPickAction")})}):n.jsxs("label",{className:"settings-skill-upload-field",children:[n.jsx("span",{children:r("settings.skillPasteLabel")}),n.jsx("textarea",{className:"settings-skill-create-textarea",value:Q,onChange:m=>B(m.target.value),placeholder:r("settings.skillPastePlaceholder")})]}),ue?n.jsx("div",{className:"settings-skill-entry",children:n.jsxs("div",{className:"settings-skill-entry-main",children:[n.jsx("strong",{className:"settings-skill-entry-title",children:ue.previewTitle}),n.jsxs("p",{className:"settings-skill-entry-meta",children:[r("settings.skillUploadPickedFile"),": ",ue.fileName]})]})}):n.jsx("div",{className:"settings-skill-empty",children:X==="paste"?r("settings.skillPasteEmpty"):r("settings.skillUploadEmpty")}),n.jsxs("div",{className:"settings-skill-upload-field",children:[n.jsx("span",{children:r("settings.skillUploadTargetsLabel")}),n.jsx("div",{className:"settings-skill-upload-targets",children:Ma(j).map(m=>n.jsxs("label",{className:"settings-skill-upload-target","data-selected":le[m]?"true":"false",children:[n.jsx("input",{type:"checkbox",checked:le[m],disabled:!xt(m,Y),onChange:()=>We(m)}),n.jsx("span",{children:xt(m,Y)?At(m):`${At(m)} · ${r("settings.skillTargetDisabledTag")}`})]},m))})]}),ue!=null&&ue.notes.length?n.jsx("div",{className:"settings-skill-tags",children:ue.notes.map((m,C)=>n.jsx("span",{className:"settings-skill-tag","data-status":"pending",children:m},`${ue.fileName}:${C}`))}):null,M?n.jsx("p",{className:"settings-release-status",children:M}):null,n.jsx("div",{className:"settings-skill-create-actions",children:n.jsx("button",{className:"primary-button",type:"button",disabled:b||N!==null,onClick:()=>{pe()},children:N==="upload"?r("common.loading"):r("settings.skillCreateSubmitAction")})})]})]})})]})}function ur({title:e,description:t,emptyText:s,items:a,renderItem:i}){return n.jsxs("section",{className:"settings-skill-section",children:[n.jsx("h3",{className:"settings-skill-section-title",children:e}),t?n.jsx("p",{className:"settings-skill-section-description",children:t}):null,a.length>0?n.jsx("div",{className:"settings-skill-entry-list",children:a.map(c=>i(c))}):n.jsx("div",{className:"settings-skill-empty",children:s})]})}function ra({label:e,value:t}){return n.jsxs("div",{className:"settings-skill-summary-card",children:[n.jsx("span",{children:e}),n.jsx("strong",{children:t})]})}function Ao(e){return`import:${e.targetCli}:${e.directoryPath}`}function Wo(e){return`sync:${e}`}const kp=["codex","claude-code","gemini","opencode"],wp=["codex","claude-code"],vp=["workspace","assistant"],xp=["file","paste"];function _s(e){return e instanceof Ei?e.message||r("settings.skillLoadFailed"):e instanceof Error?e.message:r("settings.skillLoadFailed")}function At(e){switch(e){case"claude-code":return r("settings.skillTargetClaudeCode");case"gemini":return r("settings.skillTargetGemini");case"opencode":return r("settings.skillTargetOpenCode");default:return r("settings.skillTargetCodex")}}function yp(e){return e==="assistant"?r("settings.skillUploadScopeAssistant"):r("settings.skillUploadScopeWorkspace")}function Sp(e){return e==="paste"?r("settings.skillCreateSourcePaste"):r("settings.skillCreateSourceFile")}function hr(e,t={}){const a=Ma(e).filter(i=>xt(i,t))[0]??null;return{codex:a==="codex","claude-code":a==="claude-code",gemini:a==="gemini",opencode:a==="opencode"}}function Ma(e){return e==="assistant"?wp:kp}function Lo({sourceMode:e,fileDraft:t,pastedMarkdown:s}){return e==="file"?t:s.trim()?Ac($p(s),s):null}function jp(e){switch(e){case"conflicted":return r("settings.skillBindingConflicted");case"failed":return r("settings.skillBindingFailed");case"pending":return r("settings.skillBindingPending");default:return r("settings.skillBindingSynced")}}function Cp(e){const t={};for(const s of e){const a=Np(s.provider);a&&(t[a]=s)}return t}function Np(e){switch(e){case"claude-code":return"claude-code";case"codex":return"codex";case"gemini":return"gemini";case"opencode":return"opencode";default:return null}}function xt(e,t){var s;return((s=t[e])==null?void 0:s.enabled)!==!1}function Ip(e,t){return e.some(s=>s.enabled&&xt(s.targetCli,t))}function Tp(e,t){return xt(e.targetCli,t)?e.syncStatus:"failed"}function Mp(e,t){return xt(e.targetCli,t)?`${At(e.targetCli)} · ${jp(e.syncStatus)}`:`${At(e.targetCli)} · ${r("settings.skillTargetDisabledTag")}`}function Ec(e){return e.map(At).join(" / ")}function Rp(e){const t=e.filter(s=>s.enabled);return t.length===0?r("settings.skillManagedItemNoTarget"):r("settings.skillManagedItemDescription",{targets:Ec(t.map(s=>s.targetCli))})}function Ep(e,t){return xt(e.targetCli,t)?r("settings.skillUnmanagedItemDescription",{target:At(e.targetCli)}):r("settings.skillUnmanagedItemDisabledDescription",{target:At(e.targetCli)})}function Pp(e,t){return xt(e.targetCli,t)?r("settings.skillConflictedItemDescription",{target:At(e.targetCli)}):r("settings.skillConflictedItemDisabledDescription",{target:At(e.targetCli)})}function Ap(e,t){return e.some(a=>a.enabled)?r("settings.skillSyncTargetDisabled"):r("settings.skillSyncTargetMissing")}function Wp(e,t){return Ma(e).some(a=>xt(a,t))?r("settings.skillUploadTargetRequired"):r("settings.skillUploadTargetDisabled")}function Lp(e){const t=At(e.targetCli);switch(e.code){case"SKILL_TARGET_ROOT_MISSING":return{title:r("settings.skillDiagnosticTargetMissingTitle",{target:t}),detail:r("settings.skillDiagnosticTargetMissingDetail",{target:t})};case"SKILL_TARGET_ROOT_INVALID":case"SKILL_TARGET_STAT_FAILED":case"SKILL_TARGET_READ_FAILED":return{title:r("settings.skillDiagnosticReadFailedTitle",{target:t}),detail:r("settings.skillDiagnosticReadFailedDetail",{target:t})};case"SKILL_TARGET_SKILL_MISSING":return{title:r("settings.skillDiagnosticSyncMissingTitle",{target:t}),detail:r("settings.skillDiagnosticSyncMissingDetail",{target:t})};default:return{title:r("settings.skillDiagnosticGenericTitle",{target:t}),detail:r("settings.skillDiagnosticGenericDetail",{target:t})}}}function Dp(e){if(!e)return"-";const t=Date.parse(e);return Number.isNaN(t)?e:new Date(t).toLocaleString()}function Bp(e,t,s){if(e.length>0)return e.map(i=>({name:i.name,directoryName:i.directoryName,sourcePath:i.sourcePath,usedByTargetCli:i.usedByTargetCli}));const a=new Map;for(const i of t)Pc(i,s)&&a.set(Do(i.targetCli,i.directoryPath),{name:i.name,directoryName:i.directoryName,sourcePath:i.directoryPath,usedByTargetCli:[i.targetCli]});for(const i of s){if(!Cr(i))continue;const c=i.directoryPath??i.rootDir,u=Do(i.targetCli,c);a.has(u)||a.set(u,{name:i.directoryName??"codingns-assistant",directoryName:i.directoryName??"codingns-assistant",sourcePath:c,usedByTargetCli:[i.targetCli]})}return[...a.values()]}function Do(e,t){return`${e}:${t}`}function Pc(e,t){return t.some(s=>Cr(s)&&s.targetCli===e.targetCli&&s.directoryPath===e.directoryPath&&s.directoryName===e.directoryName)}function Cr(e){return e.code==="SKILL_RESERVED_FOR_ASSISTANT_RUNTIME"}function _p(e,t){return t.find(a=>Cr(a)&&a.targetCli===e.targetCli&&a.directoryName===e.directoryName&&a.directoryPath===e.directoryPath)?[{key:`assistant-runtime:${e.targetCli}:${e.directoryPath}`,label:r("settings.skillTagAssistantOnly"),status:"assistant-runtime"}]:[]}function Op(e){return Cr(e)?[{key:`assistant-runtime:${e.targetCli}:${e.directoryPath??e.rootDir}`,label:r("settings.skillTagAssistantOnly"),status:"assistant-runtime"}]:[]}function Ac(e,t){const s=[],a=t.replace(/^\uFEFF/,"").replace(/\r\n?/g,`
4
+ `).trim();if(!a)throw new Error(r("settings.skillUploadContentEmpty"));a!==t.trim()&&s.push(r("settings.skillUploadNormalizedNote"));const i=Wc(a),c=ji(e)??ji(i)??"";return c||s.push(r("settings.skillUploadDirectoryRequiredNote")),i||s.push(r("settings.skillUploadHeadingNote")),{fileName:e,rawContent:a,directoryName:c,previewTitle:i||Hp(c||"skill"),notes:s}}async function Fp(e){if(typeof e.text=="function")return await e.text();if(typeof FileReader>"u")throw new Error(r("settings.skillUploadReadFailed"));return await new Promise((t,s)=>{const a=new FileReader;a.onerror=()=>{s(a.error??new Error(r("settings.skillUploadReadFailed")))},a.onload=()=>{if(typeof a.result=="string"){t(a.result);return}s(new Error(r("settings.skillUploadReadFailed")))},a.readAsText(e)})}function ji(e){const a=(e.replace(/\\/g,"/").split("/").pop()??e).replace(/\.[A-Za-z0-9]+$/,"").trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/-+/g,"-").replace(/^[-._]+|[-._]+$/g,"").toLowerCase();return a.length>0?a:null}function $p(e){const t=ji(Wc(e));return t?`${t}.md`:"pasted-skill.md"}function Wc(e){var t,s;return((s=(t=e.match(/^#\s+(.+)$/m))==null?void 0:t[1])==null?void 0:s.trim())??""}function Hp(e){return e.split(/[._-]+/).filter(Boolean).map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")||e}function Up(e){switch(e){case"opencli":return r("settings.skillConfigTabOpenCli");default:return r("settings.skillConfigTabSkills")}}function Xi(e){var t,s;return e.runningState==="failed"||!!((t=e.lastErrorCode)!=null&&t.trim())||!!((s=e.lastErrorDetail)!=null&&s.trim())}function Gp(e,t,s){return`${e} is-${Lc(t,s)}`}function Lc(e,t){t==null||t.isActive;const s=qp(e);return t!=null&&t.hasSubagents?s==="error"?"error":s==="unread"?"subagent-unread":s==="running"||s==="running_inferred"?"subagent-running":"subagent":s==="running_inferred"?"running-inferred":s.replace("_","-")}function zp(e){return e.runningState==="stale"?r("conversation.runtimeStale"):e.runningState==="unknown"?r("conversation.runtimeUnknown"):null}function Kp(e,t){return t.runningState==="stale"?`${e} is-stale`:t.runningState==="unknown"?`${e} is-unknown`:null}function Pg(e){return e?e.activityState==="running"?!0:e.runningState==="starting"||e.runningState==="running"||e.runningState==="reconnecting":!1}function qp(e){return Xi(e)?"error":e.runningState==="stale"?"stale":e.runningState==="unknown"?"unknown":e.activityState==="running"?Vp(e)?"running_inferred":"running":e.activityState==="completed_unread"?"unread":"idle"}function Vp(e){return e.activityResolutionSource==="inferred_log"||e.activitySource==="inferred"}function Xp(e){return Yi(e)!==null}function Yp(e){return e.isSubagent===!0&&!Xp(e)}function Yi(e){return e.forkMethod==="reconstructed_message_fork"||e.forkMethod==="reconstructed_session_fork"?"reconstructed":e.forkMethod==="native_message_fork"||e.forkSourceType==="message"?"message":e.forkMethod==="native_session_fork"||e.forkSourceType==="session"?"session":null}function Jp(e){const t=Yi(e);return t==="reconstructed"?r("shell.sessionForkReconstructed"):t==="message"?r("shell.sessionForkMessage"):t==="session"?r("shell.sessionForkSession"):null}function Zp(e){return e.sessionKind==="annotation"?"annotation":null}function Ag(e){return Zp(e)==="annotation"?r("conversation.actionSessionBadge"):null}const Bo=48;function Qp(e){return typeof e=="string"?e.replace(/\s+/g," ").trim():""}function Ji(e,t){const s=Qp(e)||t,a=s.length>Bo?s.slice(0,Bo).trimEnd():s;return{fullTitle:s,displayTitle:a}}function aa(e,t){return(t??"").localeCompare(e??"")}function _o(e,t){return e.localeCompare(t,void 0,{numeric:!0,sensitivity:"base"})}function ia(e){return(e==null?void 0:e.trim())??""}function Zi(e,t,s){if(s==="updatedAt"){const u=aa(e.updatedAt,t.updatedAt);if(u!==0)return u}if(s==="title"){const u=_o(ia(e.title),ia(t.title));if(u!==0)return u}else{const u=aa(e.createdAt,t.createdAt);if(u!==0)return u}const a=aa(e.updatedAt,t.updatedAt);if(a!==0)return a;const i=aa(e.createdAt,t.createdAt);if(i!==0)return i;const c=_o(ia(e.title),ia(t.title));return c!==0?c:e.sessionId.localeCompare(t.sessionId)}function Nr(e,t){return[...e].sort((s,a)=>Zi(s,a,t))}function Qi(e,t){return Array.isArray(e)?e.map(s=>({...s,sessions:Nr(s.sessions,t),children:Qi(s.children,t)})):[]}const ii=5,oi=["#2563eb","#0891b2","#16a34a","#d97706","#dc2626","#64748b"];function em(e){const t=Math.round(e.ratio*1e3)/10;return`${t.toFixed(t%1===0?0:1)}%`}function tm(e,t){const s=e.reduce((h,k)=>h+k.count,0);if(s<=0)return[];const i=e.slice(0,ii).map((h,k)=>({...h,key:h.type,ratio:h.count/s,color:oi[k]??oi[0]})),c=e.slice(ii);if(c.length===0)return i;const u=c.reduce((h,k)=>h+k.count,0);return i.push({key:"other",type:t,count:u,ratio:u/s,color:oi[ii]}),i}function nm(e){if(e.length===0)return"conic-gradient(color-mix(in srgb, var(--border-primary) 78%, transparent) 0% 100%)";let t=0;return`conic-gradient(${e.map((a,i)=>{const c=t,u=i===e.length-1?1:Math.min(1,t+a.ratio);return t=u,`${a.color} ${Oo(c)} ${Oo(u)}`}).join(", ")})`}function sm(e){return{"--workbench-manage-chart-background":nm(e)}}function Oo(e){const t=Math.round(e*1e3)/10;return`${t.toFixed(t%1===0?0:1)}%`}const rm=8,am=12,im=160,Fo=96;function om(e,t,s,a={}){const i=a.gapPx??rm,c=a.viewportMarginPx??am,u=a.defaultWidthPx??im,h=a.estimatedHeightPx??Fo,k=a.minHeightPx??Fo,b=Math.max(0,s.width),y=Math.max(0,s.height),N=Math.max(0,y-c*2),A=Math.max(0,b-c*2),M=oa(Math.max(t.width||u,u),0,A),L=Math.max(t.height||h,h),z=Math.max(0,b-e.x-c),I=Math.max(0,e.x-c),w=z<M&&I>z,O=Math.max(0,y-e.y-i-c),E=Math.max(0,e.y-i-c),K=O<L&&E>O,H=oa(Math.max(K?E:O,k),0,N),X=Math.min(L,H),D=w?e.x-M:e.x,j=Math.max(c,b-c-M),J=K?e.y-i-X:e.y+i,Q=Math.max(c,y-c-X),B=oa(D,c,j),le=oa(J,c,Q),ae=w||B<e.x?"right":"left";return{top:le,left:B,width:M,maxHeight:Math.max(0,H),transformOrigin:`${K?"bottom":"top"} ${ae}`}}function oa(e,t,s){return!Number.isFinite(e)||s<t?t:Math.min(Math.max(e,t),s)}const Dc="workbench.navigation.snapshot",Bc=1800*1e3,lm="workbench.navigation.snapshot.host.";function _c(e){return`${lm}${e}`}function cm(e=Bc,t=Ea(tn.getState())){if(t){const s=Na(_c(t),e);if(s)return s}return Na(Dc,e)}function la(e,t=Ea(tn.getState())){wr(Dc,e),t&&wr(_c(t),e)}function $o(e,t="createdAt"){return!e||!Array.isArray(e.items)?[]:e.items.map(s=>({workspace:s.workspace,sessions:Nr(s.sessions,t),childWorktrees:dm(s.childWorktrees,t)}))}function dm(e,t){return Qi(e,t)}function Ra(e){return{workspaceId:e.id,tone:"root",backgroundColor:e.backgroundColor??null,displayName:e.name,workspaceName:e.name,branchName:null,depth:0,rootWorkspaceId:e.id,rootDisplayName:e.name,parentWorkspaceId:null,parentDisplayName:null}}function um(e){const t=new Map;for(const s of e)t.set(s.workspace.id,Ra(s.workspace)),Oc(t,s.childWorktrees??[],s.workspace,s.workspace);return Object.fromEntries(t)}function In(e){if(e!=null&&e.backgroundColor)return{"--workspace-tone-color":e.backgroundColor}}function Oc(e,t,s,a,i=a.name){var c;for(const u of t){const h=((c=u.meta.displayName)==null?void 0:c.trim())||u.workspace.name;e.set(u.workspace.id,{workspaceId:u.workspace.id,tone:"worktree",backgroundColor:u.workspace.backgroundColor??null,displayName:h,workspaceName:u.workspace.name,branchName:u.meta.branchName||null,depth:u.meta.depth,rootWorkspaceId:s.id,rootDisplayName:s.name,parentWorkspaceId:u.meta.parentWorkspaceId||a.id,parentDisplayName:i}),Oc(e,u.children,s,u.workspace,h)}}const hm="X-CodingNS-Assistant-Source",pm="butler-ui",li=new Map;async function Tn(e,t={},s={}){const a=new Headers(t.headers);a.set(hm,pm);const i=mm();if(li.get(i)===!1){if(s.unsupportedFallback!==void 0)return Ho(s.unsupportedFallback);throw Uo()}try{const u=await oe.request(e,{...t,headers:a});return li.set(i,!0),u}catch(u){if(!fm(u))throw u;if(li.set(i,!1),s.unsupportedFallback!==void 0)return Ho(s.unsupportedFallback);throw Uo()}}function mm(){return Fl()}function Ho(e){return typeof e=="function"?e():e}function fm(e){return e instanceof Ei&&(e.status===404||e.status===405||e.status===501)}function Uo(){return new Error("当前 Host 版本不支持新版助手接口,请先升级 Host。")}function bm(){return oe.request("/api/butler/profile")}function Wg(e){return oe.request("/api/butler/profile/init",{method:"POST",body:JSON.stringify(e)})}function Lg(e){return oe.request("/api/butler/profile",{method:"PATCH",body:JSON.stringify(e)})}function Dg(){return oe.request("/api/butler/control-session")}function Bg(){return oe.request("/api/butler/control-sessions")}function _g(e){return oe.request(`/api/butler/control-sessions/${encodeURIComponent(e)}`)}function Og(e={}){var i;const t=new URLSearchParams;e.status&&t.set("status",e.status),(i=e.controlSessionId)!=null&&i.trim()&&t.set("controlSessionId",e.controlSessionId.trim()),e.limit&&e.limit>0&&t.set("limit",String(e.limit));const s=t.toString(),a=s?`/api/butler/control-timers?${s}`:"/api/butler/control-timers";return oe.request(a)}function Fg(){return oe.request("/api/butler/control-session/reset",{method:"POST"})}function $g(e={}){return oe.request("/api/butler/control-session/start",{method:"POST",body:JSON.stringify(e)})}function Hg(e){return oe.request("/api/butler/control-session/messages",{method:"POST",body:JSON.stringify(e)})}function Ug(e={}){var i;const t=new URLSearchParams;e.status&&t.set("status",e.status),(i=e.controlSessionId)!=null&&i.trim()&&t.set("controlSessionId",e.controlSessionId.trim()),e.limit&&e.limit>0&&t.set("limit",String(e.limit));const s=t.toString(),a=s?`/api/assistant/automations?${s}`:"/api/assistant/automations";return Tn(a,{},{unsupportedFallback:()=>({payload:{items:[]}})})}function Gg(e={}){var i;const t=new URLSearchParams;(i=e.controlSessionId)!=null&&i.trim()&&t.set("controlSessionId",e.controlSessionId.trim()),e.limit&&e.limit>0&&t.set("limit",String(e.limit));const s=t.toString(),a=s?`/api/assistant/automations/runs/recent?${s}`:"/api/assistant/automations/runs/recent";return Tn(a,{},{unsupportedFallback:()=>({payload:{items:[]}})})}function zg(e){return Tn(`/api/assistant/automations/${encodeURIComponent(e)}/cancel`,{method:"POST",body:JSON.stringify({})})}function Kg(e,t){return Tn(`/api/assistant/automations/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify(t)})}function qg(e){return Tn(`/api/assistant/automations/${encodeURIComponent(e)}/skip-wait`,{method:"POST",body:JSON.stringify({})})}function Vg(e={}){var i;const t=new URLSearchParams;e.status&&t.set("status",e.status),(i=e.controlSessionId)!=null&&i.trim()&&t.set("controlSessionId",e.controlSessionId.trim());const s=t.toString(),a=s?`/api/assistant/sandboxes?${s}`:"/api/assistant/sandboxes";return Tn(a,{},{unsupportedFallback:()=>({payload:{items:[]}})})}function Xg(e){return Tn(`/api/assistant/sandboxes/${encodeURIComponent(e.sandboxId)}/promote`,{method:"POST",body:JSON.stringify({mode:e.mode,projectName:e.projectName,defaultProvider:e.defaultProvider})})}function Yg(e){return Tn(`/api/assistant/sandboxes/${encodeURIComponent(e)}/expire`,{method:"POST",body:JSON.stringify({})})}function Jg(e){return Tn(`/api/assistant/sandboxes/${encodeURIComponent(e)}`,{method:"DELETE"})}function Zg(e){return oe.request(`/api/butler/control-timers/${encodeURIComponent(e)}/cancel`,{method:"POST",body:JSON.stringify({})})}function Qg(){return oe.request("/api/butler/control-session/events")}function gm(){return oe.request("/api/butler/overview")}function km(e={}){var i;const t=new URLSearchParams;(i=e.workspaceId)!=null&&i.trim()&&t.set("workspaceId",e.workspaceId.trim()),e.status&&t.set("status",e.status),e.riskLevel&&t.set("riskLevel",e.riskLevel);const s=t.toString(),a=s?`/api/butler/projects?${s}`:"/api/butler/projects";return oe.request(a)}function ek(e,t={}){const s=new URLSearchParams;t.enabled!==null&&t.enabled!==void 0&&s.set("enabled",String(t.enabled)),t.executionMode&&s.set("executionMode",t.executionMode);const a=s.toString(),i=a?`/api/butler/projects/${encodeURIComponent(e)}/patrol-plans?${a}`:`/api/butler/projects/${encodeURIComponent(e)}/patrol-plans`;return oe.request(i)}function Fc(e={}){var i,c;const t=new URLSearchParams;(i=e.workspaceId)!=null&&i.trim()&&t.set("workspaceId",e.workspaceId.trim()),(c=e.projectId)!=null&&c.trim()&&t.set("projectId",e.projectId.trim()),e.status&&t.set("status",e.status),e.itemType&&t.set("itemType",e.itemType);const s=t.toString(),a=s?`/api/butler/inbox?${s}`:"/api/butler/inbox";return oe.request(a)}function wm(e){return oe.request("/api/butler/inbox",{method:"POST",body:JSON.stringify(e)})}function vm(e={}){var i,c;const t=new URLSearchParams;e.status&&t.set("status",e.status),(i=e.projectId)!=null&&i.trim()&&t.set("projectId",e.projectId.trim()),(c=e.sessionId)!=null&&c.trim()&&t.set("sessionId",e.sessionId.trim());const s=t.toString(),a=s?`/api/butler/follow-up-tasks?${s}`:"/api/butler/follow-up-tasks";return oe.request(a)}function tk(e){return oe.request("/api/butler/follow-up-tasks",{method:"POST",body:JSON.stringify(e)})}function nk(e){return oe.request(`/api/butler/follow-up-tasks/${encodeURIComponent(e)}`)}function sk(e){return oe.request(`/api/butler/follow-up-tasks/${encodeURIComponent(e)}/cancel`,{method:"POST"})}function rk(e,t){return oe.request(`/api/butler/projects/${encodeURIComponent(e)}/verifications/${encodeURIComponent(t)}/cancel`,{method:"POST"})}function Go(e,t){return oe.request(`/api/butler/inbox/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify({projectId:t.projectId,itemType:t.itemType,title:t.title,content:t.content,priority:t.priority,status:t.status})})}function ak(e){return oe.request(`/api/butler/inbox/${encodeURIComponent(e)}/analyze`,{method:"POST",body:JSON.stringify({})})}function ik(e){return oe.request(`/api/butler/inbox/${encodeURIComponent(e)}/start-session`,{method:"POST",body:JSON.stringify({})})}function xm(e){return oe.request(`/api/butler/inbox/${encodeURIComponent(e)}`,{method:"DELETE"})}function ym(){return oe.request("/api/butler/notifications/archives")}function Sm(e,t){return oe.request(`/api/butler/notifications/archives/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify({archived:t})})}function jm(e){const t=new URLSearchParams;return t.set("sessionId",e),oe.request(`/api/butler/session-target?${t.toString()}`)}function ok(e){const t=new URLSearchParams;return t.set("sessionId",e),oe.request(`/api/butler/session-action-context?${t.toString()}`)}function lk(e){return oe.request("/api/butler/actions/start-verification",{method:"POST",body:JSON.stringify(e)})}class Ci extends Error{constructor(t,s){super(s),this.code=t,this.name="HostSwitchError"}}class Cm{constructor(){Pe(this,"inFlight",null)}async switchHost(t){this.inFlight&&await this.inFlight;const s=this.performSwitch(t).finally(()=>{this.inFlight===s&&(this.inFlight=null)});this.inFlight=s,await s}async performSwitch(t){const s=tn.getState();if(Ea(s)===t)return;const a=Td(s,t);if(!a)throw new Ci("HOST_NOT_FOUND",`找不到 HOST:${t}`);if(!(await Md(a.baseUrl)).reachable)throw new Ci("HOST_UNREACHABLE",`目标 HOST 不可达:${a.baseUrl}`);const c=$l(a.id);if(c)try{await xr.loginForHost(a,{username:c.username,password:c.password})}catch{}const u=tn.getState(),h=new Date().toISOString();if(Hl(a)){tn.updateRuntime({discoveredHosts:u.discoveredHosts.map(k=>k.id===t?{...k,lastConnectedAt:h,updatedAt:h}:k),activeDiscoveredHostId:t});return}ki.setActiveDiscoveredHost(null),await tn.update({hosts:u.hosts.map(k=>k.id===t?{...k,lastConnectedAt:h,updatedAt:h}:k),activeHostId:t})}}const Nm=new Cm;function Im({open:e,id:t,role:s="dialog",labelledBy:a,className:i,anchorRef:c,popoverRef:u,children:h,maxWidth:k=360,gap:b=10,viewportPadding:y=16}){const[N,A]=o.useState(null);if(o.useEffect(()=>{if(!e||typeof window>"u"||typeof document>"u"){A(null);return}let L=0;const z=()=>{const w=c.current;if(!w)return;const O=w.getBoundingClientRect(),E=Math.max(180,Math.min(k,window.innerWidth-y*2)),K=Math.min(Math.max(y,O.right-E),Math.max(y,window.innerWidth-y-E)),T=O.top>=Math.min(240,window.innerHeight*.42),H=Math.round(T?O.top-b:O.bottom+b);A({top:H,left:Math.round(K),width:E,placeAbove:T})},I=()=>{window.cancelAnimationFrame(L),L=window.requestAnimationFrame(z)};return z(),window.addEventListener("resize",I),window.addEventListener("scroll",I,!0),()=>{window.cancelAnimationFrame(L),window.removeEventListener("resize",I),window.removeEventListener("scroll",I,!0)}},[c,b,k,e,y]),!e||!N||typeof document>"u")return null;const M={position:"fixed",top:N.top,left:N.left,width:N.width,maxWidth:`calc(100vw - ${y*2}px)`,zIndex:9999,transform:N.placeAbove?"translateY(-100%)":void 0};return ws.createPortal(n.jsx("div",{id:t,ref:u,role:s,"aria-labelledby":a,className:i,"data-placement":N.placeAbove?"top":"bottom",style:M,children:h}),document.body)}const ci={status:"idle",latencyMs:null};function $c({collapsed:e=!1}){const[t,s]=o.useState(!1),[a,i]=o.useState(!1),[c,u]=o.useState(""),[h,k]=o.useState(""),[b,y]=o.useState(""),[N,A]=o.useState(""),[M,L]=o.useState(null),[z,I]=o.useState(null),[w,O]=o.useState(null),[E,K]=o.useState(!1),[T,H]=o.useState(!1),[X,D]=o.useState(ci),[j,J]=o.useState(null),Q=o.useRef(null),B=o.useRef(null),le=o.useRef(null),ae=o.useRef(null),ee=Pi(S=>S),_=Ri(S=>S.session),{showToast:x}=vs(),R=wi(ee),$=Ea(ee),Y=Bd(),Ce=Rd($),ye=o.useMemo(()=>zo(ee.hosts,$),[$,ee.hosts]),de=o.useMemo(()=>zo(Ul(ee),$),[$,ee]),ie=o.useCallback(()=>{if(typeof window>"u")return;const S=Q.current;if(!S)return;const te=S.getBoundingClientRect(),q=window.innerWidth,fe=window.innerHeight,we=16,ue=8,De=Math.min(320,Math.max(240,q-we*2)),Xe=Math.min(e?Math.max(we,te.right+ue):Math.max(we,te.left),Math.max(we,q-De-we)),m=a?440:240,C=e?te.top:te.bottom+ue,G=Math.min(Math.max(we,C),Math.max(we,fe-m-we));J({position:"fixed",top:G,left:Xe,width:De,maxWidth:q-we*2})},[e,a]);o.useEffect(()=>{if(!t){J(null),K(!1),D(ci);return}ki.refresh();function S(q){var fe,we,ue;q.target instanceof Node&&!((fe=Q.current)!=null&&fe.contains(q.target))&&!((we=B.current)!=null&&we.contains(q.target))&&!((ue=ae.current)!=null&&ue.contains(q.target))&&(s(!1),i(!1),K(!1),O(null))}function te(q){q.key==="Escape"&&(s(!1),i(!1),K(!1),O(null))}return window.addEventListener("pointerdown",S),window.addEventListener("keydown",te),window.addEventListener("resize",ie),window.addEventListener("scroll",ie,!0),ie(),()=>{window.removeEventListener("pointerdown",S),window.removeEventListener("keydown",te),window.removeEventListener("resize",ie),window.removeEventListener("scroll",ie,!0)}},[t,ie]),o.useEffect(()=>{if(!E||!t||(Y==null?void 0:Y.kind)!=="relay"){D(ci);return}let S=!1;const te=performance.now();return D({status:"probing",latencyMs:null}),oe.request("/api/client/runtime-config").then(()=>{S||D({status:"ready",latencyMs:performance.now()-te})}).catch(()=>{S||D({status:"error",latencyMs:null})}),()=>{S=!0}},[Y==null?void 0:Y.kind,E,t]);async function Ne(S){if(M||z||S.id===$){s(!1);return}L(S.id);try{await Nm.switchHost(S.id),s(!1),i(!1),K(!1),O(null)}catch(te){x({title:Pm(te,S.name),tone:"error"})}finally{L(null)}}async function pe(S){if(!(S.id===$||M||z)){if(w!==S.id){O(S.id);return}I(S.id);try{await tn.update({hosts:ee.hosts.filter(te=>te.id!==S.id)}),Ed(S.id),xr.clearHostSession(S.id),O(null),x({title:r("shell.hostDeleteSuccess",{name:S.name})})}catch{x({title:r("shell.hostDeleteFailed",{name:S.name}),tone:"error"})}finally{I(null)}}}async function ne(){if(T)return;const S=c.trim(),te=b.trim();if((te.length>0||N.length>0)&&(!te||!N)){x({title:r("shell.hostAddIncompleteCredentials"),tone:"error"});return}let fe;try{fe=Pd(h)}catch{x({title:r("shell.hostAddInvalidUrl"),tone:"error"});return}H(!0);try{const we=await hu(fe),ue=tn.getState(),st=wi(ue);if(we?ue.hosts.find(G=>{var se;return G.baseUrl===fe||!!we.bindingId&&((se=G.relayTunnel)==null?void 0:se.bindingId)===we.bindingId}):ue.hosts.find(G=>G.baseUrl===fe)){x({title:r("shell.hostAddDuplicate"),tone:"error"});return}const Xe=Hl(st)&&st.baseUrl===fe;Xe&&ki.setActiveDiscoveredHost(null);let m,C;if(we){const se=(await tn.update(pu(ue,we,{activate:Xe,displayName:S}))).hosts.find(he=>Rm(he,fe,we.bindingId??null));if(!se)throw new Error("relay entry host missing after save");m=se.id,C=se.name}else{const G=new Date().toISOString(),se={id:Em(),name:S||Tm(fe),baseUrl:fe,kind:Mm(fe),createdAt:G,updatedAt:G,lastConnectedAt:null,lastUserId:null,lastUsername:null};await tn.update({hosts:[...ue.hosts,se],activeHostId:Xe?se.id:ue.activeHostId}),m=se.id,C=se.name}te&&N&&Ad({hostId:m,username:te,password:N}),me(),i(!1),O(null),x({title:r("shell.hostAddSuccess",{name:C})})}catch{x({title:r("shell.hostAddFailed"),tone:"error"})}finally{H(!1)}}function me(){u(""),k(""),y(""),A("")}if(!R)return null;const We=_!=null&&_.user.username?`${R.baseUrl} · ${_.user.username}`:R.baseUrl,Ve=(Y==null?void 0:Y.kind)==="relay"?r("shell.hostSwitcherDetailStatusRelay"):r("shell.hostSwitcherDetailStatusDirect"),ct=Y?r(_d(Y.kind)):r("common.unknown");return n.jsxs("div",{ref:Q,className:"workbench-host-switcher-anchor","data-collapsed":e,children:[n.jsx("button",{type:"button",className:e?"workbench-nav-toolbar-button workbench-collapsed-button":"workbench-nav-toolbar-button","aria-label":r("shell.hostSwitcherAriaLabel"),title:We,"aria-expanded":t,onClick:()=>{s(S=>!S),i(!1)},children:n.jsx(Lm,{})}),t&&j&&typeof document<"u"?ws.createPortal(n.jsxs("div",{ref:B,className:"workbench-host-switcher-menu",style:j,role:"menu","aria-label":r("shell.hostSwitcherTitle"),children:[n.jsx("div",{className:"workbench-host-switcher-menu-header",children:n.jsx("strong",{children:r("shell.hostSwitcherTitle")})}),n.jsxs("div",{className:"workbench-host-switcher-list",children:[n.jsx("div",{className:"workbench-host-switcher-section-label",children:r("shell.hostSwitcherSavedSection")}),ye.map(S=>{const te=S.id===$,q=te?(_==null?void 0:_.user.username)??S.lastUsername??S.baseUrl:S.lastUsername??S.baseUrl;return n.jsxs("div",{className:"workbench-host-switcher-item","data-active":te,children:[n.jsxs("button",{type:"button",className:"workbench-host-switcher-item-main",disabled:M!==null||z!==null,onClick:()=>{Ne(S)},children:[n.jsxs("span",{className:"workbench-host-switcher-item-copy",children:[n.jsxs("span",{className:"workbench-host-switcher-item-title",children:[S.name,te?n.jsx("span",{className:"workbench-host-switcher-item-badge",children:r("shell.hostSwitcherCurrentBadge")}):null]}),n.jsx("span",{className:"workbench-host-switcher-item-meta",children:q})]}),n.jsx("span",{className:"workbench-host-switcher-item-trailing",children:M===S.id?r("shell.hostSwitcherSwitching"):te?n.jsx(qo,{}):n.jsx(Ko,{})})]}),te?n.jsx("button",{ref:le,type:"button",className:"workbench-host-switcher-item-action","aria-label":r("shell.hostSwitcherDetailAriaLabel",{name:S.name}),"aria-expanded":E,"aria-haspopup":"dialog","data-tone":"detail",onClick:()=>{K(fe=>!fe),O(null)},children:r("shell.hostSwitcherDetailAction")}):n.jsx("button",{type:"button",className:"workbench-host-switcher-item-action","aria-label":r("shell.hostDeleteAriaLabel",{name:S.name}),title:w===S.id?r("shell.hostDeleteConfirmAction"):r("shell.hostDeleteAction"),"data-confirming":w===S.id,disabled:M!==null||z!==null,onClick:()=>{pe(S)},children:z===S.id?r("shell.hostDeleteBusy"):w===S.id?r("shell.hostDeleteConfirmAction"):n.jsx(Bm,{})})]},S.id)}),de.length>0?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"workbench-host-switcher-section-label",children:r("shell.hostSwitcherDiscoveredSection")}),de.map(S=>{const te=S.id===$,q=$l(S.id),fe=te?(_==null?void 0:_.user.username)??(q==null?void 0:q.username)??S.baseUrl:(q==null?void 0:q.username)??S.baseUrl;return n.jsxs("div",{className:"workbench-host-switcher-item","data-active":te,"data-discovered":"true",children:[n.jsxs("button",{type:"button",className:"workbench-host-switcher-item-main",disabled:M!==null||z!==null,onClick:()=>{Ne(S)},children:[n.jsxs("span",{className:"workbench-host-switcher-item-copy",children:[n.jsxs("span",{className:"workbench-host-switcher-item-title",children:[S.name,n.jsx("span",{className:"workbench-host-switcher-item-badge","data-tone":"discovered",children:r("shell.hostSwitcherDiscoveredBadge")}),te?n.jsx("span",{className:"workbench-host-switcher-item-badge",children:r("shell.hostSwitcherCurrentBadge")}):null]}),n.jsx("span",{className:"workbench-host-switcher-item-meta",children:fe})]}),n.jsx("span",{className:"workbench-host-switcher-item-trailing",children:M===S.id?r("shell.hostSwitcherSwitching"):te?n.jsx(qo,{}):n.jsx(Ko,{})})]}),te?n.jsx("button",{ref:le,type:"button",className:"workbench-host-switcher-item-action","aria-label":r("shell.hostSwitcherDetailAriaLabel",{name:S.name}),"aria-expanded":E,"aria-haspopup":"dialog","data-tone":"detail",onClick:()=>{K(we=>!we),O(null)},children:r("shell.hostSwitcherDetailAction")}):null]},S.id)})]}):null,ee.localHostDiscovery.status==="refreshing"?n.jsx("div",{className:"workbench-host-switcher-state-row",children:r("shell.hostDiscoveryRefreshing")}):null,ee.localHostDiscovery.status==="failed"?n.jsx("div",{className:"workbench-host-switcher-state-row","data-tone":"error",children:r("shell.hostDiscoveryFailed")}):null]}),a?n.jsxs("div",{className:"workbench-host-switcher-form",children:[n.jsxs("label",{className:"workbench-host-switcher-field",children:[n.jsx("span",{children:r("shell.hostSwitcherNameLabel")}),n.jsx("input",{value:c,disabled:T,onChange:S=>u(S.target.value),placeholder:r("shell.hostSwitcherNamePlaceholder")})]}),n.jsxs("label",{className:"workbench-host-switcher-field",children:[n.jsx("span",{children:r("shell.hostSwitcherUrlLabel")}),n.jsx("input",{value:h,disabled:T,onChange:S=>k(S.target.value),placeholder:r("shell.hostSwitcherUrlPlaceholder")})]}),n.jsxs("label",{className:"workbench-host-switcher-field",children:[n.jsx("span",{children:r("auth.username")}),n.jsx("input",{value:b,disabled:T,onChange:S=>y(S.target.value),autoComplete:"username"})]}),n.jsxs("label",{className:"workbench-host-switcher-field",children:[n.jsx("span",{children:r("auth.password")}),n.jsx("input",{type:"password",value:N,disabled:T,onChange:S=>A(S.target.value),autoComplete:"current-password"})]}),n.jsxs("div",{className:"workbench-host-switcher-form-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:T,onClick:()=>{i(!1),me()},children:r("common.cancel")}),n.jsx("button",{type:"button",className:"primary-button",disabled:T,onClick:()=>{ne()},children:T?r("common.loading"):r("shell.hostSwitcherSaveAction")})]})]}):n.jsxs("button",{type:"button",className:"workbench-host-switcher-add",onClick:()=>{i(!0),O(null)},children:[n.jsx(Dm,{}),r("shell.hostSwitcherAddAction")]}),n.jsxs(Im,{open:E&&Y!==null&&le.current!==null,className:"workbench-host-switcher-detail-popover",anchorRef:le,popoverRef:ae,labelledBy:"workbench-host-switcher-detail-title",children:[n.jsx("div",{className:"workbench-host-switcher-detail-header",children:n.jsx("strong",{id:"workbench-host-switcher-detail-title",children:r("shell.hostSwitcherDetailTitle")})}),n.jsxs("div",{className:"workbench-host-switcher-detail-grid",children:[n.jsxs("div",{className:"workbench-host-switcher-detail-row",children:[n.jsx("span",{className:"workbench-host-switcher-detail-label",children:r("shell.hostSwitcherDetailStatusLabel")}),n.jsx("span",{className:"workbench-host-switcher-detail-value",children:Ve})]}),n.jsxs("div",{className:"workbench-host-switcher-detail-row",children:[n.jsx("span",{className:"workbench-host-switcher-detail-label",children:r("shell.hostSwitcherDetailRouteLabel")}),n.jsx("span",{className:"workbench-host-switcher-detail-value",children:ct})]}),n.jsxs("div",{className:"workbench-host-switcher-detail-row",children:[n.jsx("span",{className:"workbench-host-switcher-detail-label",children:r("shell.hostSwitcherDetailAddressLabel")}),n.jsx("span",{className:"workbench-host-switcher-detail-value","data-multiline":"true",children:(Y==null?void 0:Y.url)??R.baseUrl})]}),(Y==null?void 0:Y.kind)==="relay"?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"workbench-host-switcher-detail-row",children:[n.jsx("span",{className:"workbench-host-switcher-detail-label",children:r("shell.hostSwitcherDetailLatencyLabel")}),n.jsx("span",{className:"workbench-host-switcher-detail-value",children:Am(X)})]}),n.jsxs("div",{className:"workbench-host-switcher-detail-row",children:[n.jsx("span",{className:"workbench-host-switcher-detail-label",children:r("shell.hostSwitcherDetailTrafficLabel")}),n.jsx("span",{className:"workbench-host-switcher-detail-value",children:Wm(Ce.totalBytes)})]})]}):null]})]})]}),document.body):null]})}function zo(e,t){return[...e].sort((s,a)=>{if(s.id===t)return-1;if(a.id===t)return 1;const i=s.lastConnectedAt??s.updatedAt??s.createdAt;return(a.lastConnectedAt??a.updatedAt??a.createdAt).localeCompare(i)})}function Tm(e){try{const t=new URL(e),s=t.pathname==="/"?"":t.pathname.replace(/\/+$/,"");return`${t.host}${s}`}catch{return e}}function Mm(e){try{const t=new URL(e).hostname.toLowerCase();return t==="localhost"||t==="127.0.0.1"||t==="::1"||t==="[::1]"?"local":/^10\./.test(t)||/^192\.168\./.test(t)||/^172\.(1[6-9]|2\d|3[0-1])\./.test(t)?"lan":"remote"}catch{return"custom"}}function Rm(e,t,s){var a;return!!(e.baseUrl===t||s&&((a=e.relayTunnel)==null?void 0:a.bindingId)===s)}function Em(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`host-${crypto.randomUUID()}`:`host-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function Pm(e,t){return e instanceof Ci?e.code==="HOST_UNREACHABLE"?r("shell.hostSwitchUnreachable",{name:t}):r("shell.hostSwitchMissing"):r("shell.hostSwitchFailed")}function Am(e){return e.status==="probing"?r("shell.hostSwitcherDetailLatencyLoading"):e.status==="error"?r("shell.hostSwitcherDetailUnavailable"):e.status==="ready"?`${Math.max(1,Math.round(e.latencyMs))} ms`:r("shell.hostSwitcherDetailUnavailable")}function Wm(e){return!Number.isFinite(e)||e<1024?`${Math.max(0,Math.round(e))} B`:e<1024**2?`${(e/1024).toFixed(1)} KB`:e<1024**3?`${(e/1024**2).toFixed(1)} MB`:`${(e/1024**3).toFixed(2)} GB`}function Lm(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[n.jsx("rect",{x:"4",y:"4.5",width:"16",height:"6.5",rx:"2.2",stroke:"currentColor",strokeWidth:"1.8"}),n.jsx("rect",{x:"4",y:"13",width:"16",height:"6.5",rx:"2.2",stroke:"currentColor",strokeWidth:"1.8"}),n.jsx("path",{d:"M11 7.75h5.5",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"}),n.jsx("path",{d:"M11 16.25h5.5",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"}),n.jsx("circle",{cx:"7.5",cy:"7.75",r:"1",fill:"currentColor",stroke:"none"}),n.jsx("circle",{cx:"7.5",cy:"16.25",r:"1",fill:"currentColor",stroke:"none"})]})}function Ko(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M6 3.5L10.5 8 6 12.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function qo(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M3.5 8.5L6.5 11.5L12.5 5.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.8"})})}function Dm(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M8 3.5v9M3.5 8h9",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function Bm(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M3.5 4.5h9M6.5 2.75h3M5 4.5v7.25a1 1 0 0 0 1 1h4a1 1 0 0 0 1-1V4.5M6.75 6.5v4M9.25 6.5v4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.35"})})}const ca={repositoryUrl:"",parentPath:"",directoryName:"",name:"",authMode:"none",username:"",password:"",token:""};function _m({open:e,onClose:t,onCloned:s}){const{showToast:a}=vs(),[i,c]=o.useState(!1),[u,h]=o.useState(ca),[k,b]=o.useState(!1),[y,N]=o.useState(!1),[A,M]=o.useState(null),[L,z]=o.useState(""),[I,w]=o.useState(""),[O,E]=o.useState(null),[K,T]=o.useState([]),[H,X]=o.useState([]),D=i||y;o.useEffect(()=>{!e&&!i&&(h(ca),b(!1),M(null))},[i,e]);const j=o.useCallback(async _=>{N(!0),M(null);try{const x=await zl(_);z(x.currentPath),w(x.currentPath),E(x.parentPath),T(x.roots),X(x.items),h(R=>({...R,parentPath:x.currentPath}))}catch(x){z(""),E(null),X([]),M(x instanceof Error?x.message:r("shell.importBrowserBrowseFailed"))}finally{N(!1)}},[]);function J(){i||(b(!1),M(null),h(ca),t())}function Q(){b(!0),j(u.parentPath||void 0)}function B(){i||(b(!1),M(null))}async function le(_){_.preventDefault(),await j(I)}function ae(){h(_=>({..._,parentPath:L})),b(!1),M(null)}async function ee(_){_.preventDefault();const x=u.repositoryUrl.trim(),R=u.parentPath.trim();if(!x){a({title:r("shell.cloneRepoRequired"),tone:"error"});return}if(!R){a({title:r("shell.clonePathRequired"),tone:"error"});return}c(!0);try{const $=await Od({repositoryUrl:x,parentPath:R,directoryName:u.directoryName.trim()||void 0,name:u.name.trim()||void 0,auth:u.authMode==="none"?{mode:"none"}:u.authMode==="basic"?{mode:"basic",username:u.username.trim(),password:u.password}:{mode:"token",username:u.username.trim()||void 0,token:u.token}});await(s==null?void 0:s($)),h(ca),b(!1),a({title:r("shell.cloneSuccess"),description:$.path,tone:"success"}),t()}catch($){a({title:$ instanceof Error?$.message:r("shell.cloneFailed"),tone:"error"})}finally{c(!1)}}return n.jsxs(n.Fragment,{children:[n.jsx(et,{open:e,title:r("shell.cloneWorkspaceTitle"),description:r("shell.cloneWorkspaceHint"),onClose:J,children:n.jsxs("form",{className:"workbench-clone-form",onSubmit:_=>void ee(_),children:[n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.cloneRepositoryLabel")}),n.jsx("input",{type:"text",value:u.repositoryUrl,placeholder:r("shell.cloneRepositoryPlaceholder"),onChange:_=>h(x=>({...x,repositoryUrl:_.target.value}))})]}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.cloneParentPathLabel")}),n.jsxs("div",{className:"workbench-modal-inline-field",children:[n.jsx("input",{type:"text",value:u.parentPath,placeholder:r("shell.cloneParentPathPlaceholder"),onChange:_=>h(x=>({...x,parentPath:_.target.value}))}),n.jsx("button",{type:"button",className:"secondary-button",disabled:i,onClick:Q,children:r("shell.clonePickDirectory")})]})]}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.cloneDirectoryNameLabel")}),n.jsx("input",{type:"text",value:u.directoryName,placeholder:r("shell.cloneDirectoryNamePlaceholder"),onChange:_=>h(x=>({...x,directoryName:_.target.value}))})]}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.importNameLabel")}),n.jsx("input",{type:"text",value:u.name,placeholder:r("shell.importNamePlaceholder"),onChange:_=>h(x=>({...x,name:_.target.value}))})]}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.cloneAuthModeLabel")}),n.jsxs("select",{value:u.authMode,onChange:_=>h(x=>({...x,authMode:_.target.value})),children:[n.jsx("option",{value:"none",children:r("shell.cloneAuthModeNone")}),n.jsx("option",{value:"basic",children:r("shell.cloneAuthModeBasic")}),n.jsx("option",{value:"token",children:r("shell.cloneAuthModeToken")})]})]}),u.authMode==="basic"?n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.cloneUsernameLabel")}),n.jsx("input",{type:"text",value:u.username,placeholder:r("shell.cloneUsernamePlaceholder"),autoComplete:"username",onChange:_=>h(x=>({...x,username:_.target.value}))})]}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.clonePasswordLabel")}),n.jsx("input",{type:"password",value:u.password,placeholder:r("shell.clonePasswordPlaceholder"),autoComplete:"current-password",onChange:_=>h(x=>({...x,password:_.target.value}))})]})]}):null,u.authMode==="token"?n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.cloneUsernameLabel")}),n.jsx("input",{type:"text",value:u.username,placeholder:r("shell.cloneTokenUsernamePlaceholder"),onChange:_=>h(x=>({...x,username:_.target.value}))})]}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.cloneTokenLabel")}),n.jsx("input",{type:"password",value:u.token,placeholder:r("shell.cloneTokenPlaceholder"),onChange:_=>h(x=>({...x,token:_.target.value}))})]})]}):null,n.jsx("p",{className:"workbench-import-hint",children:r("shell.cloneHint")}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:i,onClick:J,children:r("common.cancel")}),n.jsx("button",{type:"submit",className:"primary-button",disabled:i,children:i?r("shell.cloneSubmitting"):r("shell.cloneSubmit")})]})]})}),n.jsxs(et,{open:e&&k,title:r("shell.cloneBrowserTitle"),description:r("shell.cloneBrowserDescription"),onClose:B,children:[n.jsxs("form",{className:"workbench-directory-browser-form",onSubmit:le,children:[n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.importBrowserCurrentPath")}),n.jsx("input",{type:"text",value:I,placeholder:r("shell.importPathPlaceholder"),onChange:_=>w(_.target.value)})]}),n.jsxs("div",{className:"workbench-directory-browser-toolbar",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:D||!O,onClick:()=>{O&&j(O)},children:r("shell.importBrowserOpenParent")}),n.jsx("button",{type:"submit",className:"secondary-button",disabled:D,children:r("shell.importBrowserOpenPath")})]})]}),n.jsxs("section",{className:"workbench-directory-browser-panel",children:[n.jsxs("div",{className:"workbench-directory-browser-section",children:[n.jsx("span",{className:"workbench-directory-browser-section-title",children:r("shell.importBrowserRoots")}),n.jsx("div",{className:"workbench-directory-browser-root-list",children:K.map(_=>n.jsx("button",{type:"button",className:"workbench-directory-browser-chip",disabled:D,onClick:()=>{j(_.path)},children:_.name},_.path))})]}),n.jsx("div",{className:"workbench-directory-browser-current-path",children:L}),A?n.jsx("p",{className:"workbench-directory-browser-status status-text","data-tone":"error",children:A}):null,y?n.jsx("p",{className:"workbench-directory-browser-status status-text",children:r("common.loading")}):H.length>0?n.jsx("div",{className:"workbench-directory-browser-list",children:H.map(_=>n.jsxs("button",{type:"button",className:"workbench-directory-browser-item",disabled:D,onClick:()=>{j(_.path)},children:[n.jsx("span",{className:"workbench-directory-browser-item-name",children:_.name}),n.jsx("span",{className:"workbench-directory-browser-item-path",children:_.path})]},_.path))}):n.jsx("p",{className:"workbench-directory-browser-status status-text",children:r("shell.importBrowserEmpty")})]}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:i,onClick:B,children:r("common.cancel")}),n.jsx("button",{type:"button",className:"primary-button",disabled:D||!L,onClick:ae,children:r("shell.cloneBrowserSubmit")})]})]})]})}const Om="butler:inbox-updated";function di(){typeof window>"u"||window.dispatchEvent(new Event(Om))}const Vo={projectId:"",itemType:"task",title:"",content:"",status:"pending"};function Hc({active:e,preferredWorkspaceId:t,preferredSessionId:s,creationRequestId:a=0,initialDraft:i=null,compactComposer:c=!1,composerOpen:u=!0,onComposerOpenChange:h}){const{showToast:k}=vs(),[b,y]=o.useState(!1),[N,A]=o.useState(!1),[M,L]=o.useState([]),[z,I]=o.useState([]),[w,O]=o.useState(null),[E,K]=o.useState(null),[T,H]=o.useState(Vo),[X,D]=o.useState(!1),j=o.useMemo(()=>Yo(M,t,E),[E,t,M]),J=o.useMemo(()=>X?z:z.filter(x=>x.status!=="closed"),[z,X]);o.useEffect(()=>{e&&Q()},[e,s]),o.useEffect(()=>{!e||w||H(x=>{const R=Zo({projects:j,currentProjectId:x.projectId,preferredProjectId:E,preferredWorkspaceId:t});return R===x.projectId?x:{...x,projectId:R}})},[e,w,E,t,j]),o.useEffect(()=>{!e||a<=0||(B(void 0,t,i,E),h==null||h(!0))},[e,a,i,h,E,t]);async function Q(){y(!0);try{const[x,R,$]=await Promise.all([km(),Fc(),s?jm(s).catch(()=>null):Promise.resolve(null)]),Y=($==null?void 0:$.target.project.id)??null;K(Y),L(x.items),I(R.items),w||B(x.items,t,a>0?i:null,Y)}catch(x){k({title:r("shell.butlerInboxLoadFailed"),description:x instanceof Error?x.message:void 0,tone:"error"})}finally{y(!1)}}function B(x=M,R=t,$=i,Y=E){var ye,de;const Ce=Yo(x,R,Y);O(null),H({...Vo,projectId:Zo({projects:Ce,preferredProjectId:Y,preferredWorkspaceId:R}),title:((ye=$==null?void 0:$.title)==null?void 0:ye.trim())??"",content:((de=$==null?void 0:$.content)==null?void 0:de.trim())??""})}function le(x){O(x.id),H({projectId:x.projectId,itemType:x.itemType,title:x.title,content:x.content,status:x.status}),c&&(h==null||h(!0))}async function ae(x){x.preventDefault(),A(!0);try{w?(await Go(w,{projectId:T.projectId,itemType:T.itemType,title:T.title,content:T.content,status:T.status,priority:"medium"}),k({title:r("shell.butlerInboxUpdated"),tone:"success"})):(await wm({projectId:T.projectId,itemType:T.itemType,title:T.title,content:T.content,status:T.status,priority:"medium"}),k({title:r("shell.butlerInboxCreated"),tone:"success"})),di(),await Q(),B(),c&&(h==null||h(!1))}catch(R){k({title:r("shell.butlerInboxSaveFailed"),description:R instanceof Error?R.message:void 0,tone:"error"})}finally{A(!1)}}async function ee(x){A(!0);try{await xm(x),k({title:r("shell.butlerInboxDeleted"),tone:"success"}),di(),await Q(),w===x&&B()}catch(R){k({title:r("shell.butlerInboxDeleteFailed"),description:R instanceof Error?R.message:void 0,tone:"error"})}finally{A(!1)}}async function _(x,R){if(x.status!==R){A(!0);try{await Go(x.id,{status:R}),k({title:r("shell.butlerInboxUpdated"),tone:"success"}),di(),await Q(),w===x.id&&H($=>({...$,status:R}))}catch($){k({title:r("shell.butlerInboxSaveFailed"),description:$ instanceof Error?$.message:void 0,tone:"error"})}finally{A(!1)}}}return n.jsxs("div",{className:"workspace-inbox-modal",children:[c?null:n.jsx("section",{className:"workspace-inbox-panel",children:n.jsx(Xo,{selectableProjects:j,formState:T,saving:N,editingItemId:w,useMobilePicker:!1,onProjectChange:x=>{H(R=>({...R,projectId:x}))},onItemTypeChange:x=>{H(R=>({...R,itemType:x}))},onStatusChange:x=>{H(R=>({...R,status:x}))},onTitleChange:x=>{H(R=>({...R,title:x}))},onContentChange:x=>{H(R=>({...R,content:x}))},onCancel:()=>B(),onSubmit:ae})}),n.jsxs("section",{className:"workspace-inbox-panel",children:[n.jsxs("header",{className:"workspace-inbox-panel-header",children:[n.jsxs("div",{children:[n.jsx("h3",{children:r("shell.butlerInboxListTitle")}),n.jsx("p",{children:r("shell.butlerInboxListDescription")})]}),n.jsxs("label",{className:"workspace-inbox-closed-toggle",children:[n.jsx("input",{type:"checkbox",checked:X,onChange:x=>D(x.target.checked)}),n.jsx("span",{children:r("shell.butlerInboxShowClosedAction")})]})]}),b?n.jsx("p",{className:"workspace-inbox-status",children:r("shell.butlerInboxLoading")}):null,!b&&J.length===0?n.jsx("p",{className:"workspace-inbox-status",children:r("shell.butlerInboxEmpty")}):null,!b&&J.length>0?n.jsx("div",{className:"workspace-inbox-list",children:J.map(x=>n.jsxs("article",{className:"workspace-inbox-item",children:[n.jsxs("div",{className:"workspace-inbox-item-header",children:[n.jsxs("div",{children:[n.jsx("strong",{children:x.title}),n.jsx("p",{children:x.projectName})]}),n.jsxs("div",{className:"workspace-inbox-item-badges",children:[n.jsx("span",{className:"workspace-inbox-badge",children:Qo(x.status)}),n.jsx("span",{className:"workspace-inbox-badge",children:Gm(x.itemType)})]})]}),n.jsx("p",{className:"workspace-inbox-item-content",children:x.content}),n.jsxs("div",{className:"workspace-inbox-item-footer",children:[n.jsx("span",{children:zm(x.updatedAt)}),n.jsxs("div",{className:"workspace-inbox-item-actions",children:[n.jsx("div",{className:"workspace-inbox-status-quick-actions",role:"group","aria-label":r("shell.butlerInboxQuickStatusLabel"),children:["pending","in_progress","closed"].map(R=>{const $=x.status===R;return n.jsx("button",{type:"button",className:"secondary-button","data-active":$,disabled:N,onClick:()=>{_(x,R)},children:Qo(R)},`${x.id}:${R}`)})}),n.jsx("button",{type:"button",className:"secondary-button",disabled:N,onClick:()=>le(x),children:r("shell.butlerInboxEditAction")}),n.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:N,onClick:()=>{ee(x.id)},children:r("shell.butlerInboxDeleteAction")})]})]})]},x.id))}):null]}),c?n.jsx(et,{open:e&&u,title:w?r("shell.butlerInboxEditingTitle"):r("shell.butlerInboxCreateTitle"),description:r("shell.butlerInboxFormDescription"),className:"workspace-inbox-modal-card workspace-inbox-composer-modal-card",onClose:()=>{h==null||h(!1),B()},children:n.jsx("div",{className:"workspace-inbox-composer-modal-body",children:n.jsx(Xo,{selectableProjects:j,formState:T,saving:N,editingItemId:w,useMobilePicker:!0,onProjectChange:x=>{H(R=>({...R,projectId:x}))},onItemTypeChange:x=>{H(R=>({...R,itemType:x}))},onStatusChange:x=>{H(R=>({...R,status:x}))},onTitleChange:x=>{H(R=>({...R,title:x}))},onContentChange:x=>{H(R=>({...R,content:x}))},onCancel:()=>{h==null||h(!1),B()},onSubmit:ae})})}):null]})}function Xo(e){const t=e.selectableProjects.map(i=>({value:i.id,label:i.name})),s=[{value:"task",label:r("shell.butlerInboxTypeTask")},{value:"bug",label:r("shell.butlerInboxTypeBug")},{value:"feature",label:r("shell.butlerInboxTypeFeature")},{value:"change",label:r("shell.butlerInboxTypeChange")}],a=[{value:"pending",label:r("shell.butlerInboxStatusPending")},{value:"in_progress",label:r("shell.butlerInboxStatusInProgress")},{value:"closed",label:r("shell.butlerInboxStatusClosed")}];return n.jsxs(n.Fragment,{children:[n.jsxs("header",{className:"workspace-inbox-panel-header",children:[n.jsx("h3",{children:e.editingItemId?r("shell.butlerInboxEditingTitle"):r("shell.butlerInboxCreateTitle")}),n.jsx("p",{children:r("shell.butlerInboxFormDescription")})]}),e.selectableProjects.length===0?n.jsx("p",{className:"workspace-inbox-status",children:r("shell.butlerInboxProjectsEmpty")}):n.jsxs("form",{className:"workspace-inbox-form",onSubmit:e.onSubmit,children:[n.jsx("div",{className:"workspace-inbox-form-grid",children:e.useMobilePicker?n.jsxs(n.Fragment,{children:[n.jsx(ui,{label:r("shell.butlerInboxProjectLabel"),value:e.formState.projectId,options:t,disabled:e.saving,onChange:e.onProjectChange}),n.jsx(ui,{label:r("shell.butlerInboxTypeLabel"),value:e.formState.itemType,options:s,disabled:e.saving,onChange:e.onItemTypeChange}),n.jsx(ui,{label:r("shell.butlerInboxStatusLabel"),value:e.formState.status,options:a,disabled:e.saving,onChange:e.onStatusChange})]}):n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.butlerInboxProjectLabel")}),n.jsx("select",{value:e.formState.projectId,disabled:e.saving,onChange:i=>e.onProjectChange(i.target.value),children:e.selectableProjects.map(i=>n.jsx("option",{value:i.id,children:i.name},i.id))})]}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.butlerInboxTypeLabel")}),n.jsxs("select",{value:e.formState.itemType,disabled:e.saving,onChange:i=>e.onItemTypeChange(i.target.value),children:[n.jsx("option",{value:"task",children:r("shell.butlerInboxTypeTask")}),n.jsx("option",{value:"bug",children:r("shell.butlerInboxTypeBug")}),n.jsx("option",{value:"feature",children:r("shell.butlerInboxTypeFeature")}),n.jsx("option",{value:"change",children:r("shell.butlerInboxTypeChange")})]})]}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.butlerInboxStatusLabel")}),n.jsxs("select",{value:e.formState.status,disabled:e.saving,onChange:i=>e.onStatusChange(i.target.value),children:[n.jsx("option",{value:"pending",children:r("shell.butlerInboxStatusPending")}),n.jsx("option",{value:"in_progress",children:r("shell.butlerInboxStatusInProgress")}),n.jsx("option",{value:"closed",children:r("shell.butlerInboxStatusClosed")})]})]})]})}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.butlerInboxTitleLabel")}),n.jsx("input",{value:e.formState.title,placeholder:r("shell.butlerInboxTitlePlaceholder"),disabled:e.saving,onChange:i=>e.onTitleChange(i.target.value)})]}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.butlerInboxContentLabel")}),n.jsx("textarea",{rows:4,value:e.formState.content,placeholder:r("shell.butlerInboxContentPlaceholder"),disabled:e.saving,onChange:i=>e.onContentChange(i.target.value)})]}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:e.saving,onClick:e.onCancel,children:e.editingItemId?r("shell.butlerInboxCancelEditAction"):r("common.cancel")}),n.jsx("button",{type:"submit",className:"primary-button",disabled:e.saving||!e.formState.projectId,children:e.editingItemId?r("shell.butlerInboxUpdateAction"):r("shell.butlerInboxCreateAction")})]})]})]})}function ui({label:e,value:t,options:s,disabled:a,onChange:i}){const[c,u]=o.useState(!1),h=s.find(k=>k.value===t)??s[0]??null;return o.useEffect(()=>{if(!c)return;function k(b){b.key==="Escape"&&u(!1)}return window.addEventListener("keydown",k),()=>{window.removeEventListener("keydown",k)}},[c]),n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"workbench-modal-field workspace-inbox-mobile-picker",children:[n.jsx("span",{children:e}),n.jsxs("button",{type:"button",className:"workspace-inbox-mobile-picker-trigger","aria-label":e,"aria-haspopup":"dialog","aria-expanded":c,disabled:a||s.length===0,onClick:()=>u(!0),children:[n.jsx("span",{className:"workspace-inbox-mobile-picker-trigger-value",children:(h==null?void 0:h.label)??""}),n.jsx("span",{className:"workspace-inbox-mobile-picker-trigger-icon",children:n.jsx(Hm,{expanded:c})})]})]}),n.jsx(Fm,{open:c,title:e,options:s,selectedValue:t,onClose:()=>u(!1),onSelect:k=>{i(k),u(!1)}})]})}function Fm({open:e,title:t,options:s,selectedValue:a,onClose:i,onSelect:c}){return e?n.jsx(Fd,{open:e,title:t,kind:"picker",height:"half",className:"workspace-inbox-picker-sheet",cardClassName:"workspace-inbox-picker-sheet-card",bodyClassName:"workspace-inbox-picker-sheet-body",showHandle:!0,onClose:i,children:n.jsx(Li,{className:"workspace-inbox-picker-sheet-options",role:"listbox","aria-label":t,children:s.map(u=>{const h=u.value===a;return n.jsx(Pt,{as:"button",className:"workspace-inbox-picker-option",role:"option","aria-selected":h,selected:h,trailing:n.jsx("span",{className:"workspace-inbox-picker-option-indicator","aria-hidden":"true",children:h?n.jsx(Um,{}):null}),onClick:()=>c(u.value),children:n.jsxs("span",{className:"workspace-inbox-picker-option-copy",children:[n.jsx("strong",{children:u.label}),u.description?n.jsx("span",{children:u.description}):null]})},u.value)})})}):null}function ck({open:e,preferredWorkspaceId:t,preferredSessionId:s,creationRequestId:a=0,initialDraft:i=null,onClose:c,compactComposer:u=!1}){const[h,k]=o.useState(0),[b,y]=o.useState(!u);return o.useEffect(()=>{e||y(!u)},[u,e]),n.jsx(et,{open:e,title:r("shell.butlerInboxModalTitle"),description:r("shell.butlerInboxModalDescription"),className:"workspace-inbox-modal-card",showCloseButton:!u,headerActions:u?n.jsx("button",{type:"button",className:"workspace-inbox-modal-create-button","aria-label":r("shell.butlerInboxCreateAction"),title:r("shell.butlerInboxCreateAction"),onClick:()=>{k(N=>N+1),y(!0)},children:n.jsx($m,{})}):void 0,onClose:c,children:n.jsx(Hc,{active:e,preferredWorkspaceId:t,preferredSessionId:s,creationRequestId:Math.max(a,h),initialDraft:i,compactComposer:u,composerOpen:b,onComposerOpenChange:y})})}function Yo(e,t,s){return[...e].filter(a=>a.lifecycleStatus!=="archived").sort((a,i)=>{const c=Jo(a,t,s),u=Jo(i,t,s);return c!==u?u-c:a.name.localeCompare(i.name,"zh-Hans-CN")})}function Jo(e,t,s){return s&&e.id===s?2:t&&e.workspaceId===t?1:0}function Zo({projects:e,currentProjectId:t,preferredProjectId:s,preferredWorkspaceId:a}){var c;if(t&&e.some(u=>u.id===t))return t;if(s&&e.some(u=>u.id===s))return s;const i=a?e.find(u=>u.workspaceId===a):null;return(i==null?void 0:i.id)||((c=e[0])==null?void 0:c.id)||""}function $m(){return n.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":"true",children:[n.jsx("path",{d:"M12 5v14"}),n.jsx("path",{d:"M5 12h14"})]})}function Hm({expanded:e}){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true","data-expanded":e?"true":void 0,children:n.jsx("path",{d:"M3.5 6 8 10l4.5-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function Um(){return n.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:n.jsx("path",{d:"M3.5 8.4 6.6 11.5 12.5 5.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.8"})})}function Gm(e){switch(e){case"bug":return r("shell.butlerInboxTypeBug");case"feature":return r("shell.butlerInboxTypeFeature");case"change":return r("shell.butlerInboxTypeChange");case"task":default:return r("shell.butlerInboxTypeTask")}}function Qo(e){switch(e){case"in_progress":return r("shell.butlerInboxStatusInProgress");case"closed":return r("shell.butlerInboxStatusClosed");case"pending":default:return r("shell.butlerInboxStatusPending")}}function zm(e){return new Date(e).toLocaleString()}function Km({open:e,onClose:t,onImported:s}){const{showToast:a}=vs(),[i,c]=o.useState(!1),[u,h]=o.useState(!1),[k,b]=o.useState(!1),[y,N]=o.useState(null),[A,M]=o.useState(""),[L,z]=o.useState(""),[I,w]=o.useState(null),[O,E]=o.useState([]),[K,T]=o.useState([]),[H,X]=o.useState(!1),[D,j]=o.useState(""),J=i||u||k,Q=o.useCallback(async R=>{c(!0),N(null);try{const $=await zl(R);M($.currentPath),z($.currentPath),w($.parentPath),E($.roots),T($.items)}catch($){M(""),w(null),T([]),N($ instanceof Error?$.message:r("shell.importBrowserBrowseFailed"))}finally{c(!1)}},[]);o.useEffect(()=>{if(!e){X(!1),j(""),N(null);return}Q(A||void 0)},[Q,e]);function B(){J||(X(!1),j(""),t())}async function le(R){R.preventDefault(),await Q(L)}function ae(){!A||J||(j(""),X(!0))}function ee(){u||(X(!1),j(""))}async function _(R){R==null||R.preventDefault();const $=D.trim();if(!(!A||!$||J)){h(!0),N(null);try{const Y=await Hd({parentPath:A,directoryName:$});a({title:r("shell.importBrowserCreateDirectorySuccess"),description:Y.path,tone:"success"}),X(!1),j(""),await Q(Y.path)}catch(Y){const Ce=Y instanceof Error?Y.message:r("shell.importBrowserCreateDirectoryFailed");N(Ce),a({title:Ce,tone:"error"})}finally{h(!1)}}}async function x(){const R=A.trim();if(!(!R||J)){b(!0),N(null);try{const $=await $d({path:R});a({title:r("shell.importSuccess"),description:$.path,tone:"success"}),t(),Promise.resolve().then(()=>s==null?void 0:s($)).catch(Y=>{a({title:Y instanceof Error?Y.message:r("shell.navigationLoadFailed"),tone:"error"})})}catch($){a({title:$ instanceof Error?$.message:r("shell.importFailed"),tone:"error"})}finally{b(!1)}}}return n.jsxs(n.Fragment,{children:[n.jsxs(et,{open:e,title:r("shell.importBrowserTitle"),description:r("shell.importBrowserDescription"),onClose:B,children:[n.jsxs("form",{className:"workbench-directory-browser-form",onSubmit:le,children:[n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.importBrowserCurrentPath")}),n.jsx("input",{type:"text",value:L,placeholder:r("shell.importPathPlaceholder"),onChange:R=>z(R.target.value)})]}),n.jsxs("div",{className:"workbench-directory-browser-toolbar",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:J||!I,onClick:()=>{I&&Q(I)},children:r("shell.importBrowserOpenParent")}),n.jsx("button",{type:"submit",className:"secondary-button",disabled:J,children:r("shell.importBrowserOpenPath")}),n.jsx("button",{type:"button",className:"secondary-button",disabled:J||!A,onClick:ae,children:r("shell.importBrowserCreateDirectory")})]})]}),n.jsxs("section",{className:"workbench-directory-browser-panel",children:[n.jsxs("div",{className:"workbench-directory-browser-section",children:[n.jsx("span",{className:"workbench-directory-browser-section-title",children:r("shell.importBrowserRoots")}),n.jsx("div",{className:"workbench-directory-browser-root-list",children:O.map(R=>n.jsx("button",{type:"button",className:"workbench-directory-browser-chip",disabled:J,onClick:()=>{Q(R.path)},children:R.name},R.path))})]}),n.jsx("div",{className:"workbench-directory-browser-current-path",children:A}),y?n.jsx("p",{className:"workbench-directory-browser-status status-text","data-tone":"error",children:y}):null,i?n.jsx("p",{className:"workbench-directory-browser-status status-text",children:r("common.loading")}):K.length>0?n.jsx("div",{className:"workbench-directory-browser-list",children:K.map(R=>n.jsxs("button",{type:"button",className:"workbench-directory-browser-item",disabled:J,onClick:()=>{Q(R.path)},children:[n.jsx("span",{className:"workbench-directory-browser-item-name",children:R.name}),n.jsx("span",{className:"workbench-directory-browser-item-path",children:R.path})]},R.path))}):n.jsx("p",{className:"workbench-directory-browser-status status-text",children:r("shell.importBrowserEmpty")})]}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:J,onClick:B,children:r("common.cancel")}),n.jsx("button",{type:"button",className:"primary-button",disabled:J||!A,onClick:()=>{x()},children:k?r("shell.importSubmitting"):r("shell.importBrowserSubmit")})]})]}),n.jsx(et,{open:e&&H,title:r("shell.importBrowserCreateDirectoryTitle"),description:r("shell.importBrowserCreateDirectoryDescription"),onClose:ee,children:n.jsxs("form",{className:"workbench-rename-form",onSubmit:R=>void _(R),children:[n.jsx("div",{className:"workbench-directory-browser-current-path",children:A}),n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.importBrowserCreateDirectoryLabel")}),n.jsx("input",{type:"text",value:D,placeholder:r("shell.importBrowserCreateDirectoryPlaceholder"),autoFocus:!0,onChange:R=>j(R.target.value)})]}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:u,onClick:ee,children:r("common.cancel")}),n.jsx("button",{type:"submit",className:"primary-button",disabled:u||!D.trim(),children:u?r("shell.importBrowserCreatingDirectory"):r("shell.importBrowserCreateDirectorySubmit")})]})]})})]})}function qm({onOpenSoftwareUpdate:e}){var a;const t=Pi(i=>i.platform),s=Ld(i=>i.latestState);return t!=="desktop"||!(s!=null&&s.hasUpdate)?null:n.jsx("button",{className:"workbench-nav-update-badge",type:"button",title:((a=s.manifest)==null?void 0:a.version)??r("settings.releaseUpdateReady"),onClick:e,children:n.jsx("span",{className:"workbench-nav-update-badge-label",children:r("settings.releaseUpdateBadge")})})}function Vm(){const e=Wd.getState().profile.defaultPermissionMode;return e==="default"?null:e}const fr="provider-default",xa="__global_default__";function Xm(e){switch(e){case"claude-code":case"codex":case"gemini":return e;default:return null}}function da(e,t){const s=(t==null?void 0:t.trim())||null;return e==="cc-switch-preset"&&s?{providerConfigMode:"cc-switch-preset",providerPresetId:s}:{providerConfigMode:"global-default",providerPresetId:null}}function Ym(e){const t=e!=null&&e.currentPresetName?e.currentModel?`${e.currentPresetName} · ${e.currentModel}`:e.currentPresetName:null;return[{value:xa,label:r("conversation.deploymentDefaultPreset"),summary:t},...((e==null?void 0:e.options)??[]).map(s=>({value:s.id,label:s.name,summary:s.model??s.summary??null}))]}function Jm(e){return e.usesProviderDefault===!0||e.id===fr}function Zm(e){return e?e.cliAvailable===!0&&e.status!=="unavailable"&&e.options.length>1:!0}function Qm({triggerId:e,ariaLabel:t,triggerLabel:s,presetOptions:a,selectedPresetValue:i,selectedPresetSummary:c,onSelectPreset:u,modelOptions:h,selectedModelValue:k,onSelectModel:b,loadingPresets:y=!1,loadingModels:N=!1,modelColumnDisabled:A=!1,showPresetColumn:M=!0,modelEmptyText:L}){const[z,I]=o.useState(!1),w=o.useRef(null),O=o.useRef(null),E=o.useRef(null),[K,T]=o.useState(null),H=o.useId(),X=o.useCallback(()=>{const D=O.current;if(!D||typeof window>"u")return;const j=D.getBoundingClientRect(),J=D.closest(".workbench-modal-card"),Q=J instanceof HTMLElement?J.getBoundingClientRect():null,B=window.innerWidth,le=window.innerHeight,ae=12,ee=8,_=320,x=Math.min(560,Math.max(320,B-ae*2)),R=Math.min(x,420),$=Math.max(Math.min(x,Math.max(R,Math.round(j.width*1.9))),Math.min(320,x)),Y=Math.min(Math.max(ae,j.left),Math.max(ae,B-$-ae)),Ce=Q?Math.max(ae,Q.top+8):ae,ye=Q?Math.min(le-ae,Q.bottom-8):le-ae,de=Math.max(0,j.top-Ce-ee),ie=Math.max(0,ye-j.bottom-ee),Ne=Q?!(ie>=_||ie>de+40):de>=240||de>=ie;T({position:"fixed",left:Y,width:$,maxWidth:x,zIndex:1905,top:Ne?void 0:j.bottom+ee,bottom:Ne?le-j.top+ee:void 0})},[]);return o.useEffect(()=>{if(!z)return;function D(J){var B,le;const Q=J.target;!((B=w.current)!=null&&B.contains(Q))&&!((le=E.current)!=null&&le.contains(Q))&&I(!1)}function j(J){J.key==="Escape"&&I(!1)}return window.addEventListener("pointerdown",D),window.addEventListener("keydown",j),window.addEventListener("resize",X),window.addEventListener("scroll",X,!0),X(),()=>{window.removeEventListener("pointerdown",D),window.removeEventListener("keydown",j),window.removeEventListener("resize",X),window.removeEventListener("scroll",X,!0)}},[z,X]),n.jsxs("div",{ref:w,className:"composer-mac-select composer-deployment-select","data-open":z?"true":"false",children:[n.jsxs("button",{id:e,ref:O,type:"button",className:"composer-mac-select-trigger composer-deployment-select-trigger","aria-label":t,"aria-haspopup":"dialog","aria-expanded":z,"aria-controls":H,onClick:()=>I(D=>!D),children:[n.jsx("span",{className:"composer-mac-select-label composer-deployment-select-label",children:s}),n.jsx("svg",{className:"composer-mac-select-chevron",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("polyline",{points:"6 14 12 8 18 14"})})]}),z&&K&&typeof document<"u"?ws.createPortal(n.jsx("div",{ref:E,className:"composer-mac-select-popover composer-deployment-select-popover",style:K,role:"presentation",children:n.jsxs("div",{id:H,className:`composer-deployment-select-panel${M?"":" is-model-only"}`,role:"dialog","aria-label":t,children:[M?n.jsxs("div",{className:"composer-deployment-select-column",children:[n.jsx("div",{className:"composer-deployment-select-column-header",children:r("conversation.deploymentConfigColumn")}),n.jsxs("div",{className:"composer-deployment-select-list",role:"listbox","aria-label":r("conversation.deploymentConfigColumn"),children:[a.map(D=>{const j=D.value===i;return n.jsxs("button",{type:"button",role:"option","aria-selected":j,className:`composer-deployment-select-option ${j?"is-selected":""}`,onClick:()=>u(D.value),children:[n.jsx("span",{className:"composer-deployment-select-option-check","aria-hidden":"true",children:j?"✓":""}),n.jsxs("span",{className:"composer-deployment-select-option-copy",children:[n.jsx("span",{className:"composer-deployment-select-option-label",children:D.label}),D.summary?n.jsx("span",{className:"composer-deployment-select-option-summary",children:D.summary}):null]})]},D.value)}),y?n.jsx("div",{className:"composer-deployment-select-state",children:r("conversation.deploymentLoading")}):null]})]}):null,n.jsxs("div",{className:"composer-deployment-select-column","data-disabled":A?"true":"false",children:[n.jsx("div",{className:"composer-deployment-select-column-header",children:r("conversation.deploymentModelColumn")}),M&&c?n.jsx("div",{className:"composer-deployment-select-column-hint",children:c}):null,n.jsx("div",{className:"composer-deployment-select-list",role:"listbox","aria-label":r("conversation.deploymentModelColumn"),children:N&&A?n.jsx("div",{className:"composer-deployment-select-state",children:r("conversation.deploymentModelLoading")}):h.length>0?h.map(D=>{const j=D.value===k;return n.jsxs("button",{type:"button",role:"option","aria-selected":j,className:`composer-deployment-select-option ${j?"is-selected":""}`,disabled:A,onClick:()=>{b(D.value),I(!1)},children:[n.jsx("span",{className:"composer-deployment-select-option-check","aria-hidden":"true",children:j?"✓":""}),n.jsx("span",{className:"composer-deployment-select-option-copy",children:n.jsx("span",{className:"composer-deployment-select-option-label",children:D.label})})]},D.value)}):n.jsx("div",{className:"composer-deployment-select-state",children:L})})]})]})}),document.body):null]})}const Uc=144,ef=196,tf=124,nf=72;let el=null;function sf(e,t){if(typeof document>"u")return t.length*8;el??(el=document.createElement("canvas"));const s=el.getContext("2d");if(!s)return t.length*8;const a=window.getComputedStyle(e),i=a.fontStyle||"normal",c=a.fontWeight||"600",u=a.fontSize||"13px",h=a.fontFamily||"system-ui";return s.font=`${i} ${c} ${u} ${h}`,s.measureText(t).width}function rf({labels:e,triggerWidth:t,maxWidth:s,preferredWidth:a,measureText:i}){const c=e.reduce((u,h)=>Math.max(u,Math.ceil(i(h)+nf)),0);return Math.min(s,Math.max(t,Uc,a,c))}function tl({triggerId:e,ariaLabel:t,value:s,options:a,onChange:i,disabled:c=!1,compact:u=!1,className:h}){const[k,b]=o.useState(!1),y=o.useRef(null),N=o.useRef(null),A=o.useRef(null),[M,L]=o.useState(null),z=o.useId(),I=a.find(E=>E.value===s)??a[0]??null,w=o.useMemo(()=>a.map(E=>E.label),[a]),O=o.useCallback(()=>{const E=N.current;if(!E||typeof window>"u")return;const K=E.getBoundingClientRect(),T=window.innerWidth,H=window.innerHeight,X=12,D=10,j=Math.max(Uc,T-X*2),J=u?tf:ef,Q=rf({labels:w,triggerWidth:K.width,maxWidth:j,preferredWidth:J,measureText:_=>sf(E,_)}),B=Math.min(Math.max(X,K.left),Math.max(X,T-Q-X)),le=K.top-X,ae=H-K.bottom-X,ee=le>=180||le>=ae;L({position:"fixed",left:B,width:Q,maxWidth:j,zIndex:1905,top:ee?void 0:K.bottom+D,bottom:ee?H-K.top+D:void 0})},[u,w]);return o.useEffect(()=>{if(!k)return;function E(T){var X,D;const H=T.target;!((X=y.current)!=null&&X.contains(H))&&!((D=A.current)!=null&&D.contains(H))&&b(!1)}function K(T){T.key==="Escape"&&b(!1)}return window.addEventListener("pointerdown",E),window.addEventListener("keydown",K),window.addEventListener("resize",O),window.addEventListener("scroll",O,!0),O(),()=>{window.removeEventListener("pointerdown",E),window.removeEventListener("keydown",K),window.removeEventListener("resize",O),window.removeEventListener("scroll",O,!0)}},[k,O]),I?n.jsxs("div",{ref:y,className:`composer-mac-select ${u?"is-compact":""}${h?` ${h}`:""}`,"data-open":k?"true":"false",children:[n.jsxs("button",{id:e,ref:N,type:"button",className:"composer-mac-select-trigger","aria-label":t,"aria-haspopup":"listbox","aria-expanded":k,"aria-controls":z,disabled:c,onClick:()=>b(E=>!E),children:[n.jsx("span",{className:"composer-mac-select-label",children:I.label}),n.jsx("svg",{className:"composer-mac-select-chevron",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("polyline",{points:"6 14 12 8 18 14"})})]}),k&&M&&typeof document<"u"?ws.createPortal(n.jsx("div",{ref:A,className:"composer-mac-select-popover",style:M,role:"presentation",children:n.jsx("div",{id:z,className:"composer-mac-select-list",role:"listbox","aria-label":t,children:a.map(E=>{const K=E.value===s;return n.jsxs("button",{type:"button",role:"option","aria-selected":K,className:`composer-mac-select-option ${K?"is-selected":""}`,onClick:()=>{i(E.value),b(!1)},children:[n.jsx("span",{className:"composer-mac-select-option-check","aria-hidden":"true",children:K?"✓":""}),n.jsx("span",{className:"composer-mac-select-option-label",children:E.label})]},E.value)})})}),document.body):null]}):null}const ua=["codex","claude-code","gemini"];function Gc(e){return{provider:e,model:"",providerConfigMode:"global-default",providerPresetId:null,memberPrompt:"",workspaceIsolationMode:"none"}}function nl(e,t){return Array.from({length:t},()=>Gc(e))}function hi(e,t){var s;return(s=e==null?void 0:e.modelOptions)!=null&&s.length?e.modelOptions:ja(t).modelOptions??[]}function sl(e,t,s){return t!=="cc-switch-preset"||!s?null:`${e}::${s}`}function rl(e,t){return Math.max(0,e-t.length)}function af({open:e,source:t,onClose:s,onCreated:a}){const i=o.useId(),c=(t==null?void 0:t.defaultProvider)??"codex",u=(t==null?void 0:t.kind)==="group",h=(t==null?void 0:t.kind)==="group"?Math.max(0,4-t.currentMemberCount):4,k=o.useMemo(()=>(t==null?void 0:t.kind)==="group"?Array.from({length:h},(m,C)=>C+1):[2,3,4],[h,t==null?void 0:t.kind]),b=(t==null?void 0:t.kind)==="group"?1:2,y=(t==null?void 0:t.kind)==="group"?t.sharedPrompt:"",{visibleProviders:N}=Ud(qd,e),[A,M]=o.useState(y),[L,z]=o.useState(b),[I,w]=o.useState(()=>nl(c,b)),[O,E]=o.useState({}),[K,T]=o.useState({}),[H,X]=o.useState({}),[D,j]=o.useState({}),[J,Q]=o.useState({}),[B,le]=o.useState(!1),[ae,ee]=o.useState(!1),[_,x]=o.useState(null),[R,$]=o.useState(null),[Y,Ce]=o.useState({}),ye=o.useRef(!1),de=o.useRef({});o.useEffect(()=>{if(!e)return;const m=(t==null?void 0:t.defaultProvider)??"codex",C=(t==null?void 0:t.kind)==="group"?1:2;M((t==null?void 0:t.kind)==="group"?t.sharedPrompt:""),z(C),w(nl(m,C)),E({}),T({}),X({}),j({}),Q({}),le(!1),ee(!1),x(null),$(null),Ce({}),ye.current=!1,Object.keys(de.current).forEach(G=>{delete de.current[G]})},[e,t==null?void 0:t.defaultProvider,t==null?void 0:t.kind,t==null?void 0:t.workspaceId,(t==null?void 0:t.kind)==="session"?t.sessionId:null,(t==null?void 0:t.kind)==="group"?t.groupId:null,(t==null?void 0:t.kind)==="group"?t.sharedPrompt:null]),o.useEffect(()=>{w(m=>{var se;if(m.length===L)return m;if(m.length>L)return m.slice(0,L);const C=m.slice(),G=((se=m[0])==null?void 0:se.provider)??c;for(;C.length<L;)C.push(Gc(G));return C})},[c,L]),o.useEffect(()=>{k.length!==0&&z(m=>k.includes(m)?m:k[0]??m)},[k]),o.useEffect(()=>{if(!e||!t)return;let m=!1;return le(!0),Gd(N,t.workspaceId).then(C=>{m||E(C)}).finally(()=>{m||le(!1)}),()=>{m=!0}},[e,t==null?void 0:t.workspaceId,N]),o.useEffect(()=>{e&&(ye.current||(ye.current=!0,X(m=>({...m,...Object.fromEntries(ua.map(C=>[C,!0]))})),zd().then(m=>{const C=Object.fromEntries(m.items.map(G=>[G.app,G]));T(Object.fromEntries(ua.map(G=>[G,C[G]??null])))}).catch(()=>{T(Object.fromEntries(ua.map(m=>[m,null])))}).finally(()=>{X(m=>({...m,...Object.fromEntries(ua.map(C=>[C,!1]))}))})))},[e]),o.useEffect(()=>{if(!e||!t)return;const m=Array.from(new Set(I.map(C=>{const G=da(C.providerConfigMode,C.providerPresetId);return sl(C.provider,G.providerConfigMode,G.providerPresetId)}).filter(C=>C!==null))).filter(C=>D[C]===void 0&&!de.current[C]);if(m.length!==0)for(const C of m){const[G,se]=C.split("::");de.current[C]=!0,Q(he=>({...he,[C]:!0})),Kl(G,t.workspaceId,{providerConfigMode:"cc-switch-preset",providerPresetId:se}).then(he=>{j(Be=>({...Be,[C]:he}))}).catch(()=>{j(he=>({...he,[C]:null}))}).finally(()=>{delete de.current[C],Q(he=>({...he,[C]:!1}))})}},[D,I,e,t]);const ie=o.useMemo(()=>N.filter(m=>{const C=O[m];return C?C.canStartSession!==!1:!1}),[O,N]);o.useEffect(()=>{if(!ie.length)return;const m=ie.includes(c)?c:ie[0];w(C=>{let G=!1;const se=C.map(he=>ie.includes(he.provider)?he:(G=!0,{...he,provider:m,providerConfigMode:"global-default",providerPresetId:null,model:""}));return G?se:C})},[ie,c]);const Ne=o.useMemo(()=>I.map((m,C)=>{var Me;const G=da(m.providerConfigMode,m.providerPresetId),se=Xm(m.provider),he=se?K[se]??null:null,Be=Ym(he),Ie=G.providerConfigMode==="cc-switch-preset"?G.providerPresetId??xa:xa,tt=Be.find(Ge=>Ge.value===Ie)??Be[0]??null,Ze=sl(m.provider,G.providerConfigMode,G.providerPresetId),Nt=O[m.provider]??null,Ye=Ze?D[Ze]??null:null,It=(G.providerConfigMode==="cc-switch-preset"?Ye?hi(Ye,m.provider):[{id:fr,name:r("conversation.modelUseCliDefault"),usesProviderDefault:!0}]:hi(Nt,m.provider)).map(Ge=>({value:Ge.id,label:Jm(Ge)?r("conversation.modelUseCliDefault"):Ge.name})),dt=m.model.trim()||fr,it=((Me=It.find(Ge=>Ge.value===dt))==null?void 0:Me.label)??r("conversation.modelUseCliDefault"),ft=Zm(he),rt=se!==null,sn=Ze?J[Ze]===!0:!1,Wt=!!(Ze&&sn&&Ye===null);return{index:C,draft:m,supportsDeploymentPicker:rt,showPresetColumn:ft,deploymentPresetOptions:Be,selectedPresetValue:Ie,selectedPresetOption:tt,triggerLabel:ft?`${(tt==null?void 0:tt.label)??r("conversation.deploymentDefaultPreset")} · ${it}`:it,selectedModelValue:dt,modelOptions:It,loadingPresets:se?H[se]===!0:!1,loadingModels:sn,modelColumnDisabled:Wt}}),[D,K,H,J,I,O]);if(o.useEffect(()=>{e&&w(m=>{let C=!1;const G=m.map((se,he)=>{const Be=Ne[he];if(!Be)return se;let Ie=se;const tt=da(se.providerConfigMode,se.providerPresetId);tt.providerConfigMode==="cc-switch-preset"&&tt.providerPresetId&&!Be.loadingPresets&&!Be.deploymentPresetOptions.some(Ye=>Ye.value===tt.providerPresetId)&&(Ie={...Ie,providerConfigMode:"global-default",providerPresetId:null,model:""},C=!0);const Ze=new Set(Be.modelOptions.map(Ye=>Ye.value)),Nt=Ie.model.trim()||fr;return Ze.has(Nt)||(Ie={...Ie,model:""},C=!0),Ie});return C?G:m})},[Ne,e]),!e||!t)return null;const pe=t,ne=R?rl(I.length,R.memberFailures):0,me=new Set(R?I.map((m,C)=>C).filter(m=>!(m in Y)):[]),We=pe.kind==="group"?r("shell.parallelAppendModalTitle"):r("shell.parallelCreateModalTitle"),Ve=pe.kind==="session"?`${pe.workspaceName} · ${pe.sessionTitle}`:pe.workspaceName,ct=pe.kind==="group"?r("shell.parallelAppendSharedPromptLabel"):r("shell.parallelCreateSharedPromptLabel"),S=pe.kind==="group"?r("shell.parallelAppendCountLabel"):r("shell.parallelCreateCountLabel"),te=pe.kind==="group"?r("shell.parallelAppendSubmit"):r("shell.parallelCreateSubmit"),q=pe.kind==="group"?r("shell.parallelAppendSubmitting"):r("shell.parallelCreateSubmitting"),fe=_??(pe.kind==="group"&&h===0?r("shell.parallelAppendNoRemainingSlots"):null)??(!B&&ie.length===0?r("shell.parallelCreateNoAvailableProviders"):null),we={"--parallel-member-columns":String(Math.max(1,Math.min(L,4)))};function ue(m){x(null),$(null),Ce(C=>{if(!(m in C))return C;const G={...C};return delete G[m],G})}function st(){x(null),$(null),Ce({})}function De(m,C){ue(m);const G=C?"temporary_worktree":"none";w(se=>se.map((he,Be)=>Be===m?{...he,workspaceIsolationMode:G}:he))}async function Xe(){const m=A.trim();if(!u&&!m){x(r("shell.parallelCreatePromptRequired"));return}if(pe.kind==="group"&&h===0){x(r("shell.parallelAppendNoRemainingSlots"));return}if(!ie.length){x(r("shell.parallelCreateNoAvailableProviders"));return}ee(!0),x(null),$(null),Ce({});try{const C=Vm(),G=I.map(he=>{const Be=da(he.providerConfigMode,he.providerPresetId);return{provider:he.provider,model:he.model.trim()||null,providerConfigMode:Be.providerConfigMode,providerPresetId:Be.providerConfigMode==="cc-switch-preset"?Be.providerPresetId:null,memberPrompt:he.memberPrompt.trim()||null,workspaceIsolationMode:he.workspaceIsolationMode}}),se=pe.kind==="group"?await Vd(pe.groupId,{permissionMode:C,members:G}):pe.kind==="session"?await Xd(pe.sessionId,{sharedPrompt:m,permissionMode:C,members:G}):await Yd(pe.workspaceId,{sharedPrompt:m,permissionMode:C,members:G});if(se.memberFailures.length>0){const he=rl(I.length,se.memberFailures);$(se),Ce(Object.fromEntries(se.memberFailures.map(Be=>[Be.ordinal,Be]))),x(he>0?r("shell.parallelCreatePartialFailure",{successCount:he,failureCount:se.memberFailures.length}):r("shell.parallelCreateAllFailed",{failureCount:se.memberFailures.length}));return}await a(se)}catch(C){x(C instanceof Error?C.message:r("shell.parallelGroupLoadFailed"))}finally{ee(!1)}}return n.jsx(uu,{open:e,title:We,description:Ve,size:"xwide",layout:"form",className:"parallel-create-modal",bodyClassName:"parallel-create-modal-body",dismissible:!ae,onClose:s,footer:n.jsxs(Kd,{align:"between",className:"parallel-create-modal-footer",children:[n.jsx("div",{className:"parallel-create-modal-status",role:"status","aria-live":"polite",children:fe?n.jsx("span",{className:"parallel-create-modal-error",children:fe}):null}),n.jsxs("div",{className:"parallel-create-modal-footer-actions",children:[R&&ne>0?n.jsx("button",{type:"button",className:"secondary-button",disabled:ae,onClick:()=>{a(R)},children:r("shell.parallelCreateContinuePartial")}):null,n.jsx("button",{type:"button",className:"secondary-button",disabled:ae,onClick:s,children:r("common.cancel")}),n.jsx("button",{type:"button",className:"primary-button",disabled:ae||B||ie.length===0||pe.kind==="group"&&h===0,onClick:()=>{Xe()},children:ae?q:te})]})]}),children:n.jsxs("div",{className:"parallel-create-layout",children:[n.jsx(Gs,{className:"parallel-create-shared-section",tone:"accent",children:n.jsxs("div",{className:"parallel-create-target-row",children:[n.jsx($s,{className:"parallel-create-target-field",label:ct,htmlFor:`${i}-shared-prompt`,children:n.jsx("textarea",{id:`${i}-shared-prompt`,className:"parallel-create-textarea parallel-create-textarea-target",rows:2,value:A,readOnly:u,"aria-readonly":u,"data-readonly":u?"true":void 0,onChange:m=>{u||(st(),M(m.target.value))}})}),n.jsx($s,{className:"parallel-create-count-field",label:S,children:n.jsx("div",{className:"parallel-create-count-group",role:"group","aria-label":S,children:k.map(m=>n.jsx("button",{type:"button",className:"parallel-create-count-button","data-active":L===m,onClick:()=>{st(),z(m)},children:m},m))})})]})}),n.jsx(Gs,{className:"parallel-create-members-section",heading:r("shell.parallelCreateMembersTitle"),children:n.jsx("div",{className:"parallel-create-member-list",style:we,children:Ne.map(({draft:m,index:C,supportsDeploymentPicker:G,showPresetColumn:se,deploymentPresetOptions:he,selectedPresetValue:Be,selectedPresetOption:Ie,triggerLabel:tt,selectedModelValue:Ze,modelOptions:Nt,loadingPresets:Ye,loadingModels:nn,modelColumnDisabled:It})=>{var Wt;const dt=ie,it=dt.includes(m.provider)?m.provider:"",ft=dt.length>0?dt.map(Me=>({value:Me,label:vi(Me,"full")})):[{value:"",label:B?r("shell.parallelCreateProvidersLoading"):r("shell.parallelCreateNoAvailableProviders")}],rt=hi(O[m.provider]??null,m.provider),sn=rt.length>0?[{value:"",label:((Wt=rt.find(Me=>Me.usesProviderDefault===!0))==null?void 0:Wt.name)??r("shell.parallelPaneModelFallback")},...rt.filter(Me=>Me.usesProviderDefault!==!0).map(Me=>({value:Me.id,label:Me.name}))]:[{value:"",label:r("shell.parallelCreateNoModelsAvailable")}];return n.jsxs("article",{className:"parallel-create-member-card","data-state":Y[C]?"error":me.has(C)?"success":void 0,children:[n.jsxs("header",{className:"parallel-create-member-header",children:[n.jsxs("div",{className:"parallel-create-member-title-block",children:[n.jsx("strong",{children:r("shell.parallelCreateMemberTitle",{index:C+1})}),n.jsx("span",{className:"parallel-create-member-provider",children:vi(m.provider,"full")}),n.jsxs("label",{className:"parallel-create-isolation-toggle",children:[n.jsx("input",{type:"checkbox",checked:m.workspaceIsolationMode==="temporary_worktree",onChange:Me=>{De(C,Me.target.checked)}}),n.jsx("span",{className:"parallel-create-isolation-copy",children:r("shell.parallelCreateIsolationLabel")})]})]}),Y[C]?n.jsx("span",{className:"parallel-create-member-status error",children:r("shell.parallelCreateMemberFailed")}):me.has(C)?n.jsx("span",{className:"parallel-create-member-status success",children:r("shell.parallelCreateMemberSucceeded")}):null]}),n.jsxs("div",{className:"parallel-create-member-grid",children:[n.jsx($s,{label:r("shell.createSessionProviderLabel"),htmlFor:`${i}-member-${C}-provider`,children:n.jsx(tl,{triggerId:`${i}-member-${C}-provider`,className:"parallel-create-provider-select",ariaLabel:r("shell.createSessionProviderLabel"),value:it,options:ft,disabled:!dt.length,onChange:Me=>{ue(C);const Ge=Me;w(Se=>Se.map((nt,Ae)=>Ae===C?{...nt,provider:Ge,providerConfigMode:"global-default",providerPresetId:null,model:""}:nt))}})}),n.jsx($s,{label:r("shell.parallelCreateModelLabel"),htmlFor:G?void 0:`${i}-member-${C}-model`,children:G?n.jsx("div",{className:"parallel-create-deployment-select",children:n.jsx(Qm,{triggerId:`${i}-member-${C}-model`,ariaLabel:r("shell.parallelCreateModelLabel"),triggerLabel:tt,presetOptions:he,selectedPresetValue:Be,selectedPresetSummary:(Ie==null?void 0:Ie.summary)??null,onSelectPreset:Me=>{ue(C),w(Ge=>Ge.map((Se,nt)=>nt!==C?Se:Me===xa?{...Se,providerConfigMode:"global-default",providerPresetId:null,model:""}:{...Se,providerConfigMode:"cc-switch-preset",providerPresetId:Me,model:""}))},modelOptions:Nt,selectedModelValue:Ze,onSelectModel:Me=>{ue(C),w(Ge=>Ge.map((Se,nt)=>nt===C?{...Se,model:Me===fr?"":Me}:Se))},loadingPresets:Ye,loadingModels:nn,modelColumnDisabled:It,showPresetColumn:se,modelEmptyText:r("conversation.deploymentModelEmpty")})}):n.jsx(tl,{triggerId:`${i}-member-${C}-model`,className:"parallel-create-provider-select",ariaLabel:r("shell.parallelCreateModelLabel"),value:m.model,options:sn,disabled:!dt.length||rt.length===0,onChange:Me=>{ue(C),w(Ge=>Ge.map((Se,nt)=>nt===C?{...Se,model:Me}:Se))}})})]}),n.jsx($s,{label:r("shell.parallelCreateMemberPromptLabel"),htmlFor:`${i}-member-${C}-prompt`,children:n.jsx("textarea",{id:`${i}-member-${C}-prompt`,className:"parallel-create-textarea member",rows:2,value:m.memberPrompt,onChange:Me=>{ue(C);const Ge=Me.target.value;w(Se=>Se.map((nt,Ae)=>Ae===C?{...nt,memberPrompt:Ge}:nt))}})}),Y[C]?n.jsxs("div",{className:"parallel-create-member-error",role:"alert",children:[n.jsx("strong",{children:r("shell.parallelCreateMemberErrorTitle")}),n.jsx("p",{children:Y[C].detail})]}):null]},`parallel-member-${C}`)})})})]})})}const of=12,lf=180,al=72;function cf(e,t){const[s,a]=o.useState(!1),[i,c]=o.useState(""),[u,h]=o.useState({}),[k,b]=o.useState({}),[y,N]=o.useState(!1),[A,M]=o.useState(null);o.useEffect(()=>{e||(a(!1),c(""),M(null))},[e]),o.useEffect(()=>{if(!e||!s)return;const I=t.filter(O=>k[O.sessionId]!==!0);if(I.length===0)return;let w=!1;return N(!0),M(null),Promise.allSettled(I.map(async O=>{const E=await Jd(O.sessionId,null,of,"backward");return{sessionId:O.sessionId,summary:df(E.messages)}})).then(O=>{if(w)return;const E={},K={};let T=0;I.forEach(H=>{E[H.sessionId]=!0});for(const H of O){if(H.status==="fulfilled"){K[H.value.sessionId]=H.value.summary;continue}T+=1}b(H=>({...H,...E})),Object.keys(K).length>0&&h(H=>({...H,...K})),M(T>0?r("shell.archiveSearchSummaryFailed"):null)}).finally(()=>{w||N(!1)}),()=>{w=!0}},[k,e,s,t]);const L=o.useMemo(()=>{const I=pi(i);return I?t.filter(w=>pi(w.title).includes(I)?!0:pi(u[w.sessionId]??"").includes(I)):t},[i,t,u]);function z(){a(I=>{const w=!I;return w||(c(""),M(null)),w})}return{searchOpen:s,searchKeyword:i,filteredSessions:L,summaryLoading:y,summaryError:A,summaryBySessionId:u,setSearchKeyword:c,toggleSearch:z}}function df(e){const t=[...e].sort((a,i)=>a.sequence-i.sequence).map(uf).filter(a=>a.length>0);if(t.length===0)return"";const s=t.slice(-3).join(" · ");return Ni(s,lf)}function uf(e){var s,a;const t=zc(e.content);return t.length>0?Ni(t,al):(a=(s=e.toolCall)==null?void 0:s.name)!=null&&a.trim()?Ni(e.toolCall.name.trim(),al):""}function pi(e){return zc(e).toLocaleLowerCase()}function zc(e){return e.replace(/\s+/g," ").trim()}function Ni(e,t){return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}const hf=5e3;let Os=null;function pf(){var t;if(Os!==null)return Os;if(typeof document>"u")return Os=0,Os;const e=document.createElement("div");return e.dataset.scrollbarProbe="true",e.style.position="absolute",e.style.top="-9999px",e.style.width="120px",e.style.height="120px",e.style.overflow="scroll",e.style.visibility="hidden",e.style.pointerEvents="none",(t=document.body)==null||t.appendChild(e),Os=Math.max(0,e.offsetWidth-e.clientWidth),e.remove(),Os}function mf(e){if(pf()>0){e.dataset.scrollbarLayout="stable";return}e.removeAttribute("data-scrollbar-layout")}function Kc(e){const t=o.useRef(null),s=e??t;return o.useEffect(()=>{const a=s.current;if(!a||typeof globalThis.window>"u")return;mf(a);let i=null;const c=()=>{i!==null&&(window.clearTimeout(i),i=null)},u=()=>{c(),a.removeAttribute("data-scrolling")},h=()=>{a.setAttribute("data-scrolling","true"),c(),i=window.setTimeout(()=>{a.removeAttribute("data-scrolling"),i=null},hf)},k=()=>{h()};return a.addEventListener("scroll",k,{passive:!0}),()=>{a.removeEventListener("scroll",k),u()}},[s]),s}const il="workbench.left.width",ol="workbench.right.width",ll="workbench.left.collapsed",cl="workbench.right.collapsed",ha="workbench.last.session.path",mi="workbench.workspace.selected.id",dl="workbench.notifications.seen_at",ff=280,bf=320,ul=240,hl=280,pl=520,ml=560,gf=200,fi=20,pr=40,pa=5,kf=3e4,wf=12,fl=60*1e3,vf=4e3,bl=220,gl=18,xf=6,Fs="data-workbench-panel-resizing",ma="data-workbench-window-resizing",yf=180,Sf="workbench:focus-composer",jf=new Set(["starting","running","reconnecting","stale","unknown"]),Cf=["#34C759","#22C55E","#14B8A6","#06B6D4","#0EA5E9","#3B82F6","#6366F1","#8B5CF6","#A855F7","#D946EF","#EC4899","#F43F5E","#EF4444","#F97316","#F59E0B","#EAB308","#84CC16","#10B981"],Nf=["--workbench-titlebar-live-content-shift-y","--workbench-nav-toolbar-live-shift-y","--workbench-info-tabs-live-shift-y","--workbench-auxiliary-toolbar-button-live-shift-y","--workbench-conversation-header-main-live-shift-y","--workbench-conversation-header-actions-live-shift-y","--workbench-terminal-tabbar-live-shift-y","--workbench-collapsed-controls-live-shift-y","--workbench-collapsed-left-controls-live-shift-y","--workbench-collapsed-right-controls-live-shift-y"],Ue={navToolbar:{selector:".workbench-nav-toolbar",variableName:"--workbench-nav-toolbar-live-shift-y"},infoTabs:{selector:".workbench-info-tabs",variableName:"--workbench-info-tabs-live-shift-y"},auxiliaryToolbarButton:{selector:".workbench-auxiliary-header > .workbench-nav-toolbar-button",variableName:"--workbench-auxiliary-toolbar-button-live-shift-y"},conversationHeaderMain:{selector:".conversation-header-main",variableName:"--workbench-conversation-header-main-live-shift-y"},conversationHeaderActions:{selector:".conversation-header-actions",variableName:"--workbench-conversation-header-actions-live-shift-y"},terminalTabbarMain:{selector:".terminal-tabbar-main",variableName:"--workbench-terminal-tabbar-live-shift-y"},collapsedLeftControls:{selector:'.workbench-collapsed-controls.left[data-visible="true"] .workbench-nav-toolbar-button',variableName:"--workbench-collapsed-left-controls-live-shift-y"},collapsedRightControls:{selector:'.workbench-collapsed-controls.right[data-visible="true"] .workbench-nav-toolbar-button',variableName:"--workbench-collapsed-right-controls-live-shift-y"}};function qc(e,t){const s=e.getPropertyValue(t).trim();if(!s)return null;const a=Number.parseFloat(s);return Number.isFinite(a)?a:null}function If(e){return Math.round(e*100)/100}function Tf(e,t){const s=t.getBoundingClientRect();if(s.width<=0||s.height<=0)return null;const a=window.getComputedStyle(t);return a.display==="none"||a.visibility==="hidden"?null:s.top-e.top+s.height/2}function Gn(e,t){const s=e.getBoundingClientRect(),i=Array.from(e.querySelectorAll(t)).map(c=>Tf(s,c)).filter(c=>c!==null);return i.length===0?null:i.reduce((c,u)=>c+u,0)/i.length}function fn(e,t,s){const a=e.style.getPropertyValue(t).trim();if(s===null||!Number.isFinite(s)){a&&e.style.removeProperty(t);return}const i=`${If(s)}px`;a!==i&&e.style.setProperty(t,i)}function bn(e,t,s,a){return a===null?null:(qc(e,t)??0)+(s-a)}function kl(e){if(e)for(const t of Nf)e.style.removeProperty(t)}function Mf(e){return jf.has(e.runningState??"idle")||e.activityState==="running"}function Rf(e,t){const s=[];for(const a of[...t].sort()){const i=e.get(a);!i||i.size===0||s.push(`${a}:${[...i].sort().join(",")}`)}return s.join("|")}function Ef(e){var i,c;const t=((i=e.lastErrorCode)==null?void 0:i.trim())??"",s=((c=e.lastErrorDetail)==null?void 0:c.trim())??"",a=[t,s].filter(u=>u.length>0).join(" · ");return a?a.length<=bl?a:`${a.slice(0,bl-3)}...`:null}function Pf(e,t,s){var c,u,h,k,b,y,N,A,M,L,z,I;const a=new Map(e.projects.map(w=>[w.id,w.workspaceId])),i=[];for(const w of s){const O=w.title.trim()||w.projectName;if(w.assistantState.lifecycleStage==="analyzed"&&!((c=w.assistantState.linkedSessionId)!=null&&c.trim())&&w.assistantState.lastAnalyzedAt){i.push({id:`todo-analysis-completed:${w.id}:${w.assistantState.lastAnalyzedAt}`,kind:"todo_analyzed",title:r("shell.globalNotificationTodoAnalyzedTitle",{title:O}),body:((u=w.assistantState.analysisSummary)==null?void 0:u.trim())||((h=w.assistantState.generatedPrompt)==null?void 0:h.trim())||w.content,routePath:ks(w.workspaceId),workspaceId:w.workspaceId,createdAt:w.assistantState.lastAnalyzedAt});continue}w.assistantState.lifecycleStage==="failed"&&i.push({id:`todo-analysis-failed:${w.id}:${w.updatedAt}`,kind:"todo_analyze_failed",title:r("shell.globalNotificationTodoAnalyzeFailedTitle",{title:O}),body:((k=w.assistantState.lastError)==null?void 0:k.trim())||w.content,routePath:ks(w.workspaceId),workspaceId:w.workspaceId,createdAt:w.updatedAt})}for(const w of t){const O=((b=w.sessionTitle)==null?void 0:b.trim())||w.projectName,E=w.updatedAt||w.lastAutomationAt||w.createdAt;if(w.status==="waiting_user"){i.push({id:`follow-up-waiting:${w.id}`,kind:"follow_up_waiting_user",title:r("shell.globalNotificationFollowUpWaitingTitle",{title:O}),body:((y=w.waitingReason)==null?void 0:y.trim())||((N=w.lastAutomationSummary)==null?void 0:N.trim())||w.objective,routePath:Ut(w.workspaceId,w.sessionId),workspaceId:w.workspaceId,createdAt:E});continue}if(w.status==="completed"){i.push({id:`follow-up-completed:${w.id}`,kind:"follow_up_completed",title:r("shell.globalNotificationFollowUpCompletedTitle",{title:O}),body:((A=w.lastAutomationSummary)==null?void 0:A.trim())||w.objective,routePath:Ut(w.workspaceId,w.sessionId),workspaceId:w.workspaceId,createdAt:E});continue}w.status==="failed"&&i.push({id:`follow-up-failed:${w.id}`,kind:"follow_up_failed",title:r("shell.globalNotificationFollowUpFailedTitle",{title:O}),body:((M=w.lastAutomationSummary)==null?void 0:M.trim())||((L=w.waitingReason)==null?void 0:L.trim())||w.objective,routePath:Ut(w.workspaceId,w.sessionId),workspaceId:w.workspaceId,createdAt:E})}for(const w of e.verifications){if(w.status!=="failed")continue;const O=w.projectId?a.get(w.projectId)??null:null,E=((z=w.targetRef)==null?void 0:z.trim())||w.verificationType;i.push({id:`verification-failed:${w.id}`,kind:"verification_failed",title:r("shell.globalNotificationVerificationFailedTitle",{title:E}),body:((I=w.summary)==null?void 0:I.trim())||r("shell.globalNotificationVerificationFailedFallback"),routePath:O?ks(O):null,workspaceId:O,createdAt:w.finishedAt||w.startedAt||w.createdAt})}return i.sort((w,O)=>{const E=wl(w.kind)-wl(O.kind);return E!==0?E:qn(O.createdAt)-qn(w.createdAt)}).slice(0,wf)}function wl(e){switch(e){case"follow_up_waiting_user":return 0;case"todo_analyze_failed":return 1;case"follow_up_failed":return 2;case"verification_failed":return 3;case"todo_analyzed":return 4;case"follow_up_completed":return 5;default:return 9}}function Af(e){switch(e){case"follow_up_waiting_user":return r("shell.globalNotificationKindWaitingUser");case"todo_analyzed":return r("shell.globalNotificationKindTodoAnalyzed");case"todo_analyze_failed":return r("shell.globalNotificationKindTodoAnalyzeFailed");case"follow_up_completed":return r("shell.globalNotificationKindFollowUpCompleted");case"follow_up_failed":return r("shell.globalNotificationKindFollowUpFailed");case"verification_failed":return r("shell.globalNotificationKindVerificationFailed");default:return r("shell.globalNotificationsPanelTitle")}}function qn(e){if(!e)return 0;const t=new Date(e).getTime();return Number.isNaN(t)?0:t}function Wf(e){return/^(?:[A-Za-z0-9_-]+)(?:\/[A-Za-z0-9_-]+)*$/.test(e)}function Lf(e){return/^(?:[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*\/?)?$/.test(e)}function Df(e,t){const s=new Set,a=(e==null?void 0:e.currentBranch)??"",i=((e==null?void 0:e.local)??[]).slice().sort((h,k)=>Number(k.current)-Number(h.current)||h.name.localeCompare(k.name)).map(h=>({value:h.name,current:h.current,recommended:h.name===a})).filter(h=>!h.value||s.has(h.value)?!1:(s.add(h.value),!0)),c=((e==null?void 0:e.remote)??[]).map(h=>({value:h.name})).filter(h=>!h.value||s.has(h.value)?!1:(s.add(h.value),!0)),u=t.map(h=>({value:h.name})).filter(h=>!h.value||s.has(h.value)?!1:(s.add(h.value),!0));return{localBranches:i,remoteBranches:c,tags:u}}function Bf(e){return e.getBoundingClientRect()}function _f(e,t){return t?qn(e.createdAt)>qn(t):!0}function Of(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat(void 0,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(t)}function vl(e,t){var u,h;const s=["/workspaces/:workspaceId","/workspaces/:workspaceId/sessions","/workspaces/:workspaceId/sessions/:sessionId","/workspaces/:workspaceId/tools","/workspaces/:workspaceId/tools/files","/workspaces/:workspaceId/tools/git","/workspaces/:workspaceId/tools/processes","/workspaces/:workspaceId/terminals","/workspaces/:workspaceId/butler"];for(const k of s){const b=Oe(k,e),y=(u=b==null?void 0:b.params.workspaceId)==null?void 0:u.trim();if(y)return y}const a=vr(e),i=(a==null?void 0:a.sessionId)??null;return!i||!xd(i)?null:((h=new URLSearchParams(t).get("workspaceId"))==null?void 0:h.trim())||null}function Ff(e){return e.startsWith("/sessions")||e.startsWith("/terminals")||e.startsWith("/tools")}function bi(e){return e==="mobile"?Ct():"/landing"}function vr(e){var c,u,h;const t=Oe("/workspaces/:workspaceId/sessions/:sessionId",e),s=(c=t==null?void 0:t.params.sessionId)==null?void 0:c.trim();if(s)return{sessionId:s,workspaceId:((u=t==null?void 0:t.params.workspaceId)==null?void 0:u.trim())??null};const a=Oe("/sessions/:sessionId",e),i=(h=a==null?void 0:a.params.sessionId)==null?void 0:h.trim();return i?{sessionId:i,workspaceId:null}:null}function $f(e){return!!(Oe("/sessions",e)||Oe("/workspaces/:workspaceId/sessions",e))}function xl(e){return!!vr(e)}function Hf(e){return!!(Oe("/tools",e)||Oe("/tools/files",e)||Oe("/tools/git",e)||Oe("/tools/processes",e)||Oe("/workspaces/:workspaceId/tools",e)||Oe("/workspaces/:workspaceId/tools/files",e)||Oe("/workspaces/:workspaceId/tools/git",e)||Oe("/workspaces/:workspaceId/tools/processes",e))}function ya(e){return!!(Oe("/terminals",e)||Oe("/workspaces/:workspaceId/terminals",e))}function Sa(e){return!!Oe("/workspaces/:workspaceId/butler",e)}function Uf(e,t){return Oe("/workspaces/:workspaceId/debug",e)?cc(t):Oe("/workspaces/:workspaceId",e)?kn(t):Oe("/workspaces/:workspaceId/tools/files",e)||Oe("/tools/files",e)?uc(t):Oe("/workspaces/:workspaceId/tools/git",e)||Oe("/tools/git",e)?hc(t):Oe("/workspaces/:workspaceId/tools/processes",e)||Oe("/tools/processes",e)?pc(t):Oe("/workspaces/:workspaceId/tools",e)||Oe("/tools",e)?dc(t):ya(e)?gs(t):Sa(e)?ks(t):Xs(t)}function Gf(e){return e.trim().replace(/\\/g,"/").replace(/^(?:\.\/)+/,"").replace(/^\/+/,"")}const zf=o.lazy(async()=>({default:(await Ai(()=>import("./FileContextPanel-CdC7GGw5.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]))).FileContextPanel})),Kf=o.lazy(async()=>({default:(await Ai(()=>import("./GitSidebar-z2SBinQh.js"),__vite__mapDeps([11,1,2,3,4,5,7,6,8,9,10]))).GitSidebar})),qf=o.lazy(async()=>({default:(await Ai(()=>import("./TerminalManagerPanel-BOm8Hi_v.js"),__vite__mapDeps([12,1,2,6,3,4,5,13,14,8,9,10]))).TerminalManagerPanel}));function Vf(e){return!!((e==null?void 0:e.item)??(e==null?void 0:e.session))}function en(e){return Zs(e)}function Vc(e){return e&&"item"in e?e.item:(e==null?void 0:e.session)??null}function br(e){return Array.isArray(e==null?void 0:e.visibleSessionTree)?e.visibleSessionTree.filter(Vf):[]}async function Xc(e,t){const s=await Kl(t,e);if(s.canStartSession===!1)throw new Error(s.limitations[0]??r("conversation.capabilityDenied"))}const Yc=o.createContext(null);function Ii(e){return Yp(e)}function gn(e){return e.isArchived===!0}function La(e){return sc(e)}function eo(e,t){return ac(e,{getId:s=>s.sessionId,getParentId:La,compare:(s,a)=>Zi(s,a,t)})}function Jc(e){return e.filter(t=>{if(gn(t))return!1;const s=La(t);if(!s)return!0;const a=e.find(i=>i.sessionId===s);return!a||!gn(a)})}function Xf(e){return e.flatMap(t=>{const s=Vc(t);return s?[s,...ic(en(t))]:[]})}function Yf(e,t,s){const a=new Set(zn(en(e)).sort((i,c)=>Zi(i.item,c.item,s)).slice(0,t).map(i=>i.item.sessionId));return{...e,children:Zc(en(e),a)}}function Zc(e,t){return e.flatMap(s=>{const a=Zc(en(s),t);return!t.has(s.item.sessionId)&&a.length===0?[]:[{...s,children:a}]})}function fa(e,t,s,a=-1){if(e<=0)return 0;const i=a>=0?Math.max(t,a+1):t;return Math.min(e,Math.max(s??0,i))}function yl(e,t){const s=Object.keys(e),a=Object.keys(t);return s.length!==a.length?!1:s.every(i=>e[i]===t[i])}function Jf(e){const t=e.lastMessageAt??e.updatedAt;return t?new Date(t).toLocaleDateString():""}function Zf(e){return Xi(e)||e.syncStatus==="error"}function Qf(e){var a,i;if(!Zf(e))return null;const t=((a=e.lastErrorCode)==null?void 0:a.trim())??"",s=((i=e.lastErrorDetail)==null?void 0:i.replace(/\s+/g," ").trim())??"";return t&&s&&!s.includes(t)?`${t} · ${s}`:s||t||(e.syncStatus==="error"&&!Xi(e)?r("conversation.syncStatusError"):r("conversation.runtimeErrorTitle"))}function eb(e,t=110){return e.length<=t?e:`${e.slice(0,Math.max(0,t-1)).trimEnd()}…`}function Da(e,t="compact"){return vi(e,t)}const tb={position:"relative",zIndex:0},nb={zIndex:1};function Qc(e,t,s,a){const i=[],c=(a==null?void 0:a.trim())||t.name;s&&i.push(c);const u=Jf(e);return u&&i.push(u),i.join(" · ")||c}function Sl(e,t){return Gp("session-state-indicator",e,t)}function sb(e,t){return Lc(e,t)}function jl(e,t){try{const s=window.localStorage.getItem(e),a=s?Number(s):Number.NaN;return Number.isFinite(a)?a:t}catch{return t}}function Cl(e,t){try{const s=window.localStorage.getItem(e);return s===null?t:s==="true"}catch{return t}}function Nl(e){var t;try{const s=(t=window.localStorage.getItem(e))==null?void 0:t.trim();return s||null}catch{return null}}function bs(e,t){try{window.localStorage.setItem(e,t)}catch{}}function rb(e){try{window.localStorage.removeItem(e)}catch{}}function ba(e,t,s){return Math.max(t,Math.min(s,e))}function ga(e){const t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function ab(e){const t=window.getComputedStyle(e),s=ga(t.getPropertyValue("--desktop-macos-titlebar-height")),a=ga(t.getPropertyValue("--workbench-header-min-height")),i=ga(t.getPropertyValue("--workbench-macos-titlebar-padding-top")),c=ga(t.getPropertyValue("--workbench-macos-titlebar-padding-bottom"));return Math.max(s,a,40)+i+c+8}function Il(e,t){const s=t.getBoundingClientRect();return e>=s.top&&e<=s.top+ab(t)}function ib(e){return e instanceof HTMLElement?e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement||!!e.closest("[contenteditable='true']"):!1}function ob(){typeof window>"u"||window.dispatchEvent(new CustomEvent(Sf))}function ed(e,t){const s=t==null?void 0:t.trim();if(!s)return null;for(const a of e){if(a.workspace.id===s)return a;const i=ed(a.children,s);if(i)return i}return null}function Tl(e,t){const s=t==null?void 0:t.trim();if(!s)return null;for(const a of e){const i=ed(a.childWorktrees,s);if(i)return i}return null}function td(e){return e.flatMap(t=>[t.workspace.id,...td(t.children)])}function lb(e){return new Set(e.flatMap(t=>[t.workspace.id,...td(t.childWorktrees)]))}function Ml(e){return!e||!Array.isArray(e.items)?[]:e.items.filter(t=>{var s;return t.collapsed===!0&&((s=t.workspace)==null?void 0:s.id)}).map(t=>t.workspace.id)}function gi(e,t){const s=new Set(t);return{items:e.map(a=>({workspace:a.workspace,sessions:a.sessions,childWorktrees:a.childWorktrees,collapsed:s.has(a.workspace.id)}))}}function nd(e,t,s){return e.map(a=>{const i=Jc(a.sessions);return{workspace:a.workspace,meta:a.meta,visibleSessions:i,archivedSessions:a.sessions.filter(c=>gn(c)&&!La(c)),visibleSessionTree:eo(i,s).filter(c=>!t.has(c.item.sessionId)&&!$i(en(c),u=>t.has(u.sessionId))),children:nd(a.children,t,s)}})}function Ti(e){return e.flatMap(t=>[t.workspace.id,...Ti(t.children)])}function gr(e){return e.flatMap(t=>[...t.visibleSessionTree,...gr(t.children)])}function cb(e,t){if(!t)return null;for(const s of e){if(s.workspace.id===t)return{workspace:s.workspace,visibleSessionTree:br(s)};const a=rd(s.childWorktrees,t);if(a)return a}return null}function sd(e,t){for(const s of e){const a=zn(s.visibleSessionTree).find(c=>c.item.sessionId===t);if(a)return a;const i=sd(s.children,t);if(i)return i}return null}function rd(e,t){for(const s of e){if(s.workspace.id===t)return{workspace:s.workspace,visibleSessionTree:s.visibleSessionTree};const a=rd(s.children,t);if(a)return a}return null}function db(e,t){if(!t)return null;for(const s of e){if(s.workspace.id===t)return{workspace:s.workspace,archivedSessions:s.archivedSessions};const a=ad(s.childWorktrees,t);if(a)return a}return null}function Rl(e,t){if(!t)return null;for(const s of e){if(s.workspace.id===t)return s.workspace;const a=id(s.childWorktrees,t);if(a)return a}return null}function ad(e,t){for(const s of e){if(s.workspace.id===t)return{workspace:s.workspace,archivedSessions:s.archivedSessions};const a=ad(s.children,t);if(a)return a}return null}function id(e,t){for(const s of e){if(s.workspace.id===t)return s.workspace;const a=id(s.children,t);if(a)return a}return null}function od(e,t){for(const s of e){if(s.workspace.id===t)return[s.workspace.id];const a=od(s.children,t);if(a.length>0)return[s.workspace.id,...a]}return[]}function El(e){return e.flatMap(t=>[t.workspace.id,...ld(t.childWorktrees)])}function ld(e){return e.flatMap(t=>[t.workspace.id,...ld(t.children)])}function ub(e,t=[]){if(e.tone!=="worktree")return e.rootDisplayName;if(t.length>0)return t.join(" / ");const s=[e.rootDisplayName];return e.parentDisplayName&&e.parentDisplayName!==e.rootDisplayName&&s.push(e.parentDisplayName),s.join(" / ")}function hb(e,t,s,a){if(t===s)return e;const i=e.findIndex(b=>b.workspace.id===t),c=e.findIndex(b=>b.workspace.id===s);if(i<0||c<0)return e;const u=[...e],[h]=u.splice(i,1);if(!h)return e;const k=u.findIndex(b=>b.workspace.id===s);return k<0?e:(u.splice(a==="before"?k:k+1,0,h),u.every((b,y)=>{var N;return b.workspace.id===((N=e[y])==null?void 0:N.workspace.id)})?e:u)}function pb(e,t){if(!Array.isArray(e.items)||t.size===0)return e;let s=!1;const a=e.items.map(i=>{let c=!1;const u=i.sessions.map(k=>{const b=t.get(k.sessionId);return b===void 0||gn(k)===b?k:(s=!0,c=!0,{...k,isArchived:b})}),h=dd(i.childWorktrees??[],t,k=>{k&&(s=!0,c=!0)});return c?{...i,sessions:u,childWorktrees:h}:i});return s?{...e,items:a}:e}function mb(e,t){if(!(!Array.isArray(t.items)||e.size===0))for(const s of t.items){for(const a of s.sessions){const i=e.get(a.sessionId);i!==void 0&&gn(a)===i&&e.delete(a.sessionId)}ud(e,s.childWorktrees??[])}}function fb(e,t,s){let a=!1;const i=e.map(c=>{if(c.workspace.id!==t.workspaceId){const{nodes:k,changed:b}=hd(c.childWorktrees,t,s);return b?(a=!0,{...c,childWorktrees:k}):c}const u=c.sessions.findIndex(k=>k.sessionId===t.sessionId),h=u>=0?c.sessions.map((k,b)=>b===u?t:k):[t,...c.sessions];return a=!0,{...c,sessions:Nr(h,s)}});return a?i:e}function bb(e,t,s){let a=!1;const i=e.map(c=>{let u=!1;const h=c.sessions.map(b=>b.sessionId!==t?b:(a=!0,u=!0,{...b,lastSeenAt:b.lastSeenAt&&b.lastSeenAt>s?b.lastSeenAt:s,activityState:b.activityState==="completed_unread"?"idle":b.activityState})),k=Ba(c.childWorktrees,b=>b.sessionId!==t?b:(a=!0,u=!0,{...b,lastSeenAt:b.lastSeenAt&&b.lastSeenAt>s?b.lastSeenAt:s,activityState:b.activityState==="completed_unread"?"idle":b.activityState}));return u?{...c,sessions:h,childWorktrees:k}:c});return a?i:e}function Pl(e,t,s){let a=!1;const i=e.map(c=>{let u=!1;const h=c.sessions.map(b=>b.sessionId!==t||b.isArchived===s?b:(a=!0,u=!0,{...b,isArchived:s})),k=Ba(c.childWorktrees,b=>b.sessionId!==t||b.isArchived===s?b:(a=!0,u=!0,{...b,isArchived:s}));return u?{...c,sessions:h,childWorktrees:k}:c});return a?i:e}function Al(e,t,s){let a=!1;const i=e.map(c=>{let u=!1;const h=c.sessions.map(b=>b.sessionId!==t||b.isFavorite===!0===s?b:(a=!0,u=!0,{...b,isFavorite:s})),k=Ba(c.childWorktrees,b=>b.sessionId!==t||b.isFavorite===!0===s?b:(a=!0,u=!0,{...b,isFavorite:s}));return u?{...c,sessions:h,childWorktrees:k}:c});return a?i:e}function gb(e,t){return e.includes(t)?e.filter(s=>s!==t):[...e,t]}function kb(e){return e?e.slice(0,8):"--"}function Wl(e,t,s){return s?e.includes(t)?e:[...e,t]:e.includes(t)?e.filter(a=>a!==t):e}function cd(e,t){const s=e.filter(a=>t.has(a));return s.length===e.length?e:s}function dd(e,t,s){return e.map(a=>{let i=!1;const c=a.sessions.map(h=>{const k=t.get(h.sessionId);return k===void 0||gn(h)===k?h:(i=!0,{...h,isArchived:k})}),u=dd(a.children,t,h=>{h&&(i=!0)});return s(i),i?{...a,sessions:c,children:u}:a})}function ud(e,t){for(const s of t){for(const a of s.sessions){const i=e.get(a.sessionId);i!==void 0&&gn(a)===i&&e.delete(a.sessionId)}ud(e,s.children)}}function hd(e,t,s){let a=!1;const i=e.map(c=>{if(c.workspace.id===t.workspaceId){const h=c.sessions.findIndex(b=>b.sessionId===t.sessionId),k=h>=0?c.sessions.map((b,y)=>y===h?t:b):[t,...c.sessions];return a=!0,{...c,sessions:Nr(k,s)}}const u=hd(c.children,t,s);return u.changed?(a=!0,{...c,children:u.nodes}):c});return{nodes:a?i:[...e],changed:a}}function wb(e,t){return e.map(s=>({...s,sessions:Nr(s.sessions,t),childWorktrees:Qi(s.childWorktrees,t)}))}function Ba(e,t){let s=!1;const a=e.map(i=>{let c=!1;const u=i.sessions.map(k=>{const b=t(k);return b!==k&&(c=!0,s=!0),b}),h=Ba(i.children,t);return h!==i.children&&(c=!0,s=!0),c?{...i,sessions:u,children:h}:i});return s?a:[...e]}function Mi(e){return`workspace-management.summary.${e}`}function pd(e){return`git-sidebar.snapshot.${e}`}function md(e,t){const s=e.repoRoot??null;return{workspaceId:e.id,name:e.name,path:e.path,git:{isRepository:!!s,repoRoot:s,currentBranch:null,commitCount:null,remotes:[],error:null},codeComposition:{scannedFileCount:0,truncated:!1,items:[],error:null}}}function fd(e,t){const s=e.git.repoRoot??t.repoRoot??null;return{...e,workspaceId:t.id,name:t.name,path:t.path,git:{...e.git,isRepository:e.git.isRepository||!!s,repoRoot:s}}}function bd(e,t){var c,u,h,k;const s=((c=t.status)==null?void 0:c.snapshot.enabled)!==!1,a=s?((u=t.status)==null?void 0:u.snapshot.repoRoot)??e.git.repoRoot:e.git.repoRoot,i=s?((h=t.status)==null?void 0:h.snapshot.branch)??((k=t.branches)==null?void 0:k.currentBranch)??e.git.currentBranch??null:e.git.currentBranch??null;return{...e,git:{...e.git,isRepository:s&&(e.git.isRepository||!!a),repoRoot:a,currentBranch:i,error:null}}}function gd({count:e,className:t="workbench-skeleton-lines"}){return n.jsx("div",{className:t,"aria-hidden":"true",children:Array.from({length:e},(s,a)=>n.jsx("span",{className:"skeleton-line"},a))})}function vb(){return n.jsx("div",{className:"workbench-nav-loading","aria-hidden":"true",children:Array.from({length:3},(e,t)=>n.jsxs("section",{className:"workbench-skeleton-card",children:[n.jsxs("div",{className:"workbench-skeleton-heading",children:[n.jsx("span",{className:"skeleton-line short"}),n.jsx("span",{className:"skeleton-line tiny"})]}),n.jsx("div",{className:"workbench-skeleton-list",children:Array.from({length:3},(s,a)=>n.jsxs("div",{className:"workbench-skeleton-session",children:[n.jsx("span",{className:"workbench-skeleton-dot"}),n.jsx(gd,{count:2,className:"workbench-skeleton-lines compact"})]},a))})]},t))})}function ka(){return n.jsx("section",{className:"workbench-info-skeleton","aria-hidden":"true",children:Array.from({length:4},(e,t)=>n.jsxs("article",{className:"workbench-info-skeleton-card",children:[n.jsx("span",{className:"skeleton-line short"}),n.jsx(gd,{count:3})]},t))})}function xb({side:e,collapsed:t}){const s=e==="left"?8.5:15.5,a=e==="left"?t?"12 9 15 12 12 15":"15 9 12 12 15 15":t?"12 9 9 12 12 15":"9 9 12 12 9 15";return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),n.jsx("line",{x1:s,y1:"4",x2:s,y2:"20"}),n.jsx("polyline",{points:a})]})}function Ll({ariaLabel:e,side:t,collapsed:s,className:a="panel-icon-button",onClick:i}){return n.jsx("button",{className:a,type:"button","aria-label":e,title:e,onClick:i,children:n.jsx(xb,{side:t,collapsed:s})})}function kr({expanded:e}){return n.jsx("svg",{className:e?"workbench-chevron":"workbench-chevron collapsed",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("polyline",{points:"6 9 12 15 18 9"})})}function yb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),n.jsx("polyline",{points:"7 10 12 15 17 10"}),n.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}function Sb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("rect",{x:"4",y:"5",width:"16",height:"14",rx:"2"}),n.jsx("line",{x1:"8",y1:"10",x2:"16",y2:"10"}),n.jsx("line",{x1:"8",y1:"14",x2:"12",y2:"14"}),n.jsx("circle",{cx:"17.5",cy:"15.5",r:"2.5"})]})}function jb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("path",{d:"M7.5 10.2a4.5 4.5 0 1 1 9 0v3.1c0 .8.3 1.6.9 2.2l.8.8H5.8l.8-.8c.6-.6.9-1.4.9-2.2z",strokeLinecap:"round",strokeLinejoin:"round"}),n.jsx("path",{d:"M10 18.5a2 2 0 0 0 4 0",strokeLinecap:"round"})]})}function kd(e){return n.jsx("div",{className:"workbench-notification-anchor",children:n.jsxs("button",{type:"button",className:e.collapsed?"workbench-nav-toolbar-button workbench-collapsed-button":"workbench-nav-toolbar-button","aria-label":r("shell.globalNotificationsAction"),title:r("shell.globalNotificationsAction"),"aria-expanded":e.open,onClick:e.onToggle,children:[n.jsx(jb,{}),e.unreadCount>0?n.jsx("span",{className:"workbench-notification-badge","aria-label":r("shell.globalNotificationsUnreadAria",{count:String(e.unreadCount)}),children:e.unreadCount>99?"99+":e.unreadCount}):null]})})}function Cb(e){const[t,s]=o.useState("notifications");o.useEffect(()=>{e.open&&s("notifications")},[e.open]);const a=o.useMemo(()=>e.notifications.filter(i=>e.showArchivedNotifications||!e.archivedNotificationIds.has(i.id)),[e.archivedNotificationIds,e.notifications,e.showArchivedNotifications]);return n.jsxs(et,{open:e.open,title:r("shell.globalNotificationsPanelTitle"),description:r("shell.globalNotificationsPanelDescription"),className:"workbench-notification-modal-card workspace-inbox-modal-card",showCloseButton:!1,onClose:e.onClose,children:[n.jsxs("div",{className:"workbench-notification-tabs",role:"tablist","aria-label":r("shell.globalNotificationsPanelTitle"),children:[n.jsx("button",{type:"button",className:t==="notifications"?"workbench-notification-tab active":"workbench-notification-tab",role:"tab","aria-selected":t==="notifications",onClick:()=>s("notifications"),children:r("shell.globalNotificationsAction")}),n.jsx("button",{type:"button",className:t==="inbox"?"workbench-notification-tab active":"workbench-notification-tab",role:"tab","aria-selected":t==="inbox",onClick:()=>s("inbox"),children:r("shell.butlerInboxAction")})]}),n.jsx("div",{className:"workbench-notification-content","data-tab":t,children:t==="notifications"?n.jsxs("div",{className:"workbench-notification-pane",role:"tabpanel","aria-label":r("shell.globalNotificationsAction"),children:[n.jsx("div",{className:"workbench-notification-toolbar",children:n.jsxs("label",{className:"workbench-notification-filter",children:[n.jsx("input",{type:"checkbox",checked:e.showArchivedNotifications,onChange:i=>e.onToggleShowArchivedNotifications(i.target.checked)}),n.jsx("span",{children:r("shell.globalNotificationsShowArchived")})]})}),a.length>0?n.jsx("div",{className:"workbench-notification-list",children:a.map(i=>{const c=e.archivedNotificationIds.has(i.id);return n.jsxs("article",{className:"workbench-notification-item","data-archived":c,children:[n.jsxs("button",{type:"button",className:"workbench-notification-item-content",onClick:()=>{e.onSelectNotification(i)},children:[n.jsx("span",{className:"workbench-notification-item-kind",children:Af(i.kind)}),n.jsx("strong",{children:i.title}),n.jsx("p",{children:i.body})]}),n.jsxs("div",{className:"workbench-notification-item-side",children:[n.jsx("time",{children:Of(i.createdAt)}),n.jsx("button",{type:"button",className:"secondary-button workbench-notification-item-action-button",onClick:()=>{if(c){e.onUnarchiveNotification(i.id);return}e.onArchiveNotification(i.id)},children:c?r("shell.globalNotificationsRemoveArchiveAction"):r("shell.globalNotificationsArchiveAction")})]})]},i.id)})}):n.jsx("p",{className:"workbench-notification-empty",children:r("shell.globalNotificationsEmpty")})]}):n.jsx("div",{className:"workbench-notification-pane",role:"tabpanel","aria-label":r("shell.butlerInboxAction"),children:n.jsx(Hc,{active:e.open&&t==="inbox",preferredWorkspaceId:e.preferredWorkspaceId,preferredSessionId:e.preferredSessionId})})}),n.jsx("div",{className:"workbench-modal-actions workbench-notification-footer-actions",children:n.jsx("button",{type:"button",className:"secondary-button",onClick:e.onClose,children:r("common.close")})})]})}function Nb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),n.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Ib(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("circle",{cx:"11",cy:"11",r:"7"}),n.jsx("line",{x1:"20",y1:"20",x2:"16.65",y2:"16.65"})]})}function Tb(){return n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:n.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H8l-5 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function Mb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[n.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),n.jsx("path",{d:"M7 9l3 3-3 3"}),n.jsx("path",{d:"M13 15h4"})]})}function Rb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[n.jsx("rect",{x:"4",y:"5",width:"16",height:"14",rx:"3"}),n.jsx("circle",{cx:"9",cy:"11",r:"1"}),n.jsx("circle",{cx:"15",cy:"11",r:"1"}),n.jsx("path",{d:"M8 15h8"}),n.jsx("path",{d:"M12 5V3"})]})}function Eb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[n.jsx("path",{d:"M12 4.5 13.6 8l3.9.4-2.9 2.7.8 3.9L12 13.2 8.6 15l.8-3.9-2.9-2.7L10.4 8 12 4.5Z"}),n.jsx("path",{d:"m18.5 4.5.5 1.3 1.3.5-1.3.5-.5 1.3-.5-1.3-1.3-.5 1.3-.5.5-1.3Z"})]})}function wd(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),n.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),n.jsx("polyline",{points:"14 9 11 12 14 15"})]})}function Pb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("circle",{cx:"18",cy:"6",r:"3"}),n.jsx("circle",{cx:"6",cy:"6",r:"3"}),n.jsx("circle",{cx:"18",cy:"18",r:"3"}),n.jsx("path",{d:"M6 9v6a3 3 0 0 0 3 3h3"}),n.jsx("line",{x1:"18",y1:"9",x2:"18",y2:"15"})]})}function Ab(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("circle",{cx:"12",cy:"12",r:"3"}),n.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09a1.65 1.65 0 0 0-1-1.51 1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06A1.65 1.65 0 0 0 4.6 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09a1.65 1.65 0 0 0 1.51-1 1.65 1.65 0 0 0-.33-1.82L4.21 7.1a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06A1.65 1.65 0 0 0 8.92 4a1.65 1.65 0 0 0 1-1.51V2.4a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9c0 .66.39 1.25 1 1.51h.09a2 2 0 0 1 0 4h-.09c-.61.26-1 .85-1 1.49z"})]})}function Wb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("rect",{x:"4",y:"5",width:"6",height:"6",rx:"1.5"}),n.jsx("rect",{x:"14",y:"5",width:"6",height:"6",rx:"1.5"}),n.jsx("rect",{x:"4",y:"13",width:"6",height:"6",rx:"1.5"}),n.jsx("path",{d:"M14 16l2 2 4-4"})]})}function Lb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("rect",{x:"4",y:"6",width:"10",height:"12",rx:"2"}),n.jsx("path",{d:"M10 12h8"}),n.jsx("path",{d:"M15 8l4 4-4 4"})]})}function Db({selected:e}){return e?n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"4"}),n.jsx("path",{d:"M8 12.5l2.8 2.8L16.5 9.5"})]}):n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"4"})})}function vd({active:e,className:t}){return e?n.jsx("svg",{className:t,width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.5",children:n.jsx("polygon",{points:"12 3 15 9 22 10 17 15 18 22 12 18 6 22 7 15 2 10 9 9"})}):n.jsx("svg",{className:t,width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:n.jsx("polygon",{points:"12 3 15 9 22 10 17 15 18 22 12 18 6 22 7 15 2 10 9 9"})})}function Bb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("path",{d:"M3 7h18"}),n.jsx("path",{d:"M5 7l1 12h12l1-12"}),n.jsx("path",{d:"M9 11h6"}),n.jsx("path",{d:"M8 4h8l1 3H7l1-3z"})]})}function _b(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("path",{d:"M12 20h9"}),n.jsx("path",{d:"M16.5 3.5a2.12 2.12 0 1 1 3 3L7 19l-4 1 1-4 12.5-12.5z"})]})}function Ob(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("path",{d:"M3 6h18"}),n.jsx("path",{d:"M8 6V4h8v2"}),n.jsx("path",{d:"M6 6l1 14h10l1-14"}),n.jsx("path",{d:"M10 11v5"}),n.jsx("path",{d:"M14 11v5"})]})}function Fb(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[n.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"}),n.jsx("path",{d:"M9 13h6"})]})}function $b(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[n.jsx("circle",{cx:"12",cy:"12",r:"9"}),n.jsx("path",{d:"M9.7 9.4a2.5 2.5 0 1 1 4.1 2c-.8.7-1.8 1.2-1.8 2.6",strokeLinecap:"round"}),n.jsx("circle",{cx:"12",cy:"17.2",r:"1",fill:"currentColor",stroke:"none"})]})}function Hb({open:e,mode:t,keyword:s,codeWorkspaceId:a,codeResults:i,codeLoading:c,codeError:u,workspaceOptions:h,sessionResults:k,onClose:b,onModeChange:y,onKeywordChange:N,onCodeWorkspaceChange:A,onCodeSearch:M,onOpenSession:L}){const z=s.trim().length>0&&a.trim().length>0;return n.jsx(et,{open:e,title:r("shell.searchModalTitle"),description:r("shell.searchModalDescription"),onClose:b,children:n.jsxs("div",{className:"workbench-search-modal",children:[n.jsxs("div",{className:"workbench-search-mode-switch",role:"tablist","aria-label":r("shell.searchModeLabel"),children:[n.jsx("button",{type:"button",className:t==="sessions"?"workbench-search-mode-button active":"workbench-search-mode-button",role:"tab","aria-selected":t==="sessions",onClick:()=>y("sessions"),children:r("shell.searchModeSessions")}),n.jsx("button",{type:"button",className:t==="code"?"workbench-search-mode-button active":"workbench-search-mode-button",role:"tab","aria-selected":t==="code",onClick:()=>y("code"),children:r("shell.searchModeCode")})]}),t==="sessions"?n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.searchKeywordLabel")}),n.jsx("input",{type:"text",value:s,placeholder:r("shell.searchSessionPlaceholder"),autoFocus:!0,onChange:I=>N(I.target.value)})]}),n.jsx("div",{className:"workbench-search-results",children:s.trim().length===0?n.jsx("p",{className:"workbench-search-empty",children:r("shell.searchSessionHint")}):k.length>0?k.map(I=>{const w=Ji(I.session.title,r("common.unknown"));return n.jsxs("button",{type:"button",className:"workbench-search-result-item",onClick:()=>L(I.session.sessionId),children:[n.jsx("span",{className:"workbench-search-result-title",title:w.fullTitle,children:w.displayTitle}),n.jsxs("span",{className:"workbench-search-result-meta",children:[I.workspace.name," · ",Da(I.session.provider,"full")]})]},I.session.sessionId)}):n.jsx("p",{className:"workbench-search-empty",children:r("shell.searchSessionEmpty")})})]}):n.jsxs(n.Fragment,{children:[n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.searchWorkspaceLabel")}),n.jsx("select",{value:a,onChange:I=>A(I.target.value),children:h.map(I=>n.jsx("option",{value:I.id,children:I.name},I.id))})]}),n.jsxs("form",{className:"workbench-search-code-form",onSubmit:I=>{I.preventDefault(),M()},children:[n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.searchKeywordLabel")}),n.jsx("input",{type:"text",value:s,placeholder:r("shell.searchCodePlaceholder"),autoFocus:!0,onChange:I=>N(I.target.value)})]}),n.jsx("button",{type:"submit",className:"primary-button",disabled:!z||c,children:c?r("common.loading"):r("shell.searchSubmit")})]}),n.jsxs("div",{className:"workbench-search-results",children:[u?n.jsx("p",{className:"status-text","data-tone":"error",children:u}):null,!u&&s.trim().length===0?n.jsx("p",{className:"workbench-search-empty",children:r("shell.searchCodeHint")}):null,!u&&s.trim().length>0&&!c&&i.length===0?n.jsx("p",{className:"workbench-search-empty",children:r("shell.searchCodeEmpty")}):null,i.map(I=>n.jsxs("div",{className:"workbench-search-result-item static",children:[n.jsx("span",{className:"workbench-search-result-title",children:I.name}),n.jsx("span",{className:"workbench-search-result-meta",children:I.path})]},`${I.path}-${I.kind}`))]})]})]})})}function Dl({menuKey:e,session:t,workspace:s,workspaceContext:a,isActive:i,isFavorite:c,menuOpen:u,menuAnchorPoint:h,showWorkspaceName:k,depth:b=0,showActions:y=!0,hasSubagents:N=!1,subagentListExpanded:A=!1,selectionMode:M=!1,selected:L=!1,onToggleSelect:z,onToggleSubagents:I,onOpen:w,onRename:O,onOpenContextMenu:E,onToggleFavorite:K,onArchive:T,onDelete:H,onCloseMenu:X}){var Ne,pe,ne;const D=Vn(),j=ja(t.provider).supportsSessionDelete===!0,J=Ii(t)?((Ne=t.subagentLabel)==null?void 0:Ne.trim())||r("shell.subagentBadge"):null,Q=Ji(t.title,r("common.unknown")),B=Qf(t),le=B?eb(B):null,ae=zp(t),ee=ae?Kp("session-activity-badge",t):null,_=Yi(t),x=Jp(t),R=Wu(t.parallelGroup),$=Pu(t.parallelGroup),Y=o.useRef(null),[Ce,ye]=o.useState(null);o.useLayoutEffect(()=>{if(D.isDesktop||!u||!h||typeof window>"u"){ye(null);return}const me=()=>{var Ve,ct;const We=om(h,{width:((Ve=Y.current)==null?void 0:Ve.offsetWidth)??0,height:((ct=Y.current)==null?void 0:ct.offsetHeight)??0},{width:window.innerWidth,height:window.innerHeight},{estimatedHeightPx:j&&H?216:168});ye({position:"fixed",top:`${Math.round(We.top)}px`,left:`${Math.round(We.left)}px`,width:`${Math.round(We.width)}px`,maxWidth:"calc(100vw - 24px)",maxHeight:`${Math.round(We.maxHeight)}px`,transformOrigin:We.transformOrigin})};return me(),window.addEventListener("resize",me),window.addEventListener("scroll",me,!0),()=>{window.removeEventListener("resize",me),window.removeEventListener("scroll",me,!0)}},[h,u,D.isDesktop]);async function de(){await Mu([{id:`rename:${t.sessionId}`,label:r("shell.renameAction"),onSelect:O},{id:`favorite:${t.sessionId}`,label:c?r("shell.unfavoriteAction"):r("shell.favoriteAction"),onSelect:K},{id:`archive:${t.sessionId}`,label:r("shell.archiveAction"),onSelect:T},...j&&H?[{id:`delete:${t.sessionId}`,label:r("shell.deleteSessionAction"),onSelect:H}]:[]])}const ie=!D.isDesktop&&u&&typeof document<"u"?ws.createPortal(n.jsxs("div",{ref:Y,className:"workbench-session-menu","data-menu-key":e,role:"menu","aria-label":r("shell.sessionMoreAction"),onClick:me=>me.stopPropagation(),style:Ce??{position:"fixed",top:0,left:0,visibility:"hidden"},children:[n.jsxs("button",{type:"button",className:"workbench-session-menu-item",onClick:()=>{O(),X()},children:[n.jsx(_b,{}),n.jsx("span",{children:r("shell.renameAction")})]}),n.jsxs("button",{type:"button",className:"workbench-session-menu-item",onClick:()=>{K(),X()},children:[n.jsx(vd,{active:c}),n.jsx("span",{children:c?r("shell.unfavoriteAction"):r("shell.favoriteAction")})]}),n.jsxs("button",{type:"button",className:"workbench-session-menu-item",onClick:()=>{T(),X()},children:[n.jsx(Bb,{}),n.jsx("span",{children:r("shell.archiveAction")})]}),j&&H?n.jsxs("button",{type:"button",className:"workbench-session-menu-item",onClick:()=>{H(),X()},children:[n.jsx(Ob,{}),n.jsx("span",{children:r("shell.deleteSessionAction")})]}):null]}),document.body):null;return n.jsxs("article",{className:"workbench-session-card","data-active":i,"data-depth":b,"data-subagent":Ii(t),"data-workspace-tone":a.tone,"data-worktree-depth":a.depth,"data-has-subagents":N,"data-selecting":M,"data-selected":L,"data-parallel-group":t.parallelGroup?"true":void 0,"data-parallel-role":((pe=t.parallelGroup)==null?void 0:pe.role)??void 0,"data-parallel-color-token":((ne=t.parallelGroup)==null?void 0:ne.colorToken)??void 0,style:{...In(a)??{},...$??{}},onContextMenu:me=>{if(!(M||!y||!E)){if(me.preventDefault(),me.stopPropagation(),D.isDesktop){de();return}E({x:me.clientX,y:me.clientY})}},children:[n.jsxs("div",{className:"workbench-session-main",children:[M?n.jsx("span",{className:"workbench-session-selection-indicator","data-selected":L,"aria-hidden":"true",children:n.jsx(Db,{selected:L})}):N?n.jsxs("button",{type:"button",className:"workbench-session-subagent-toggle",style:nb,"data-indicator-variant":sb(t,{hasSubagents:!0,isActive:i}),"aria-label":A?r("shell.subagentCollapse"):r("shell.subagentExpand"),title:A?r("shell.subagentCollapse"):r("shell.subagentExpand"),"aria-expanded":A,onClick:me=>{me.stopPropagation(),I==null||I()},children:[n.jsx("span",{className:Sl(t,{hasSubagents:!0,isActive:i}),"data-activity-source":t.activitySource,"aria-hidden":"true"}),n.jsx("span",{className:"workbench-session-subagent-toggle-icon","aria-hidden":"true",children:n.jsx(kr,{expanded:A})})]}):n.jsx("span",{className:Sl(t,{isActive:i}),"data-activity-source":t.activitySource,"aria-hidden":"true"}),n.jsx("button",{type:"button",className:"workbench-session-link",style:N?tb:void 0,"data-active":i,"aria-pressed":M?L:void 0,onClick:M?z:w,onKeyDown:me=>{if(M||!y||!E||me.key!=="ContextMenu"&&!(me.shiftKey&&me.key==="F10"))return;if(me.preventDefault(),me.stopPropagation(),D.isDesktop){de();return}const We=me.currentTarget.getBoundingClientRect();E({x:We.right,y:We.bottom})},children:n.jsxs("div",{className:"workbench-session-link-copy",children:[n.jsxs("div",{className:"session-title-row",children:[n.jsx("span",{className:"session-title",title:Q.fullTitle,children:Q.displayTitle}),J?n.jsx("span",{className:"session-subagent-badge",children:J}):null,R?n.jsx("span",{className:"session-parallel-badge",children:R}):null,!R&&x&&_?n.jsx("span",{className:`session-fork-badge ${_}`,children:x}):null]}),n.jsxs("div",{className:"session-meta-row",children:[n.jsx("span",{className:"session-meta",children:Qc(t,s,k,a.displayName)}),ae&&ee?n.jsx("span",{className:ee,children:ae}):null,n.jsx("span",{className:`session-provider-badge ${t.provider}`,children:Da(t.provider)})]}),le?n.jsx("div",{className:"session-error-row",title:B??void 0,children:n.jsx("span",{className:"session-error-text",children:le})}):null]})})]}),ie]})}function Bl({workspaceGroups:e,workspaceVisualContextMap:t,sessionDisplaySortMode:s,favoriteSessions:a,favoriteSessionIds:i,activeWorkspaceId:c,isConversationActive:u,isTerminalActive:h,isButlerActive:k,isSearchOpen:b,navigationLoading:y,navigationError:N,activeSessionId:A,onRefreshNavigation:M,onSessionUpdated:L,onNavigateConversation:z,onNavigateTerminals:I,onNavigateButler:w,onOpenSearch:O,onOpenSettings:E,onSelectWorkspace:K,onToggleWorkspaceCollapse:T,onStartWorkspaceReorder:H,onPreviewWorkspaceReorder:X,onCommitWorkspaceReorder:D,allowWorkspaceReorder:j,subscribeGitSnapshot:J,requestGitRefresh:Q,subscribeWorkspaceManagementSnapshot:B,requestWorkspaceManagementRefresh:le,onToggleFavoriteSession:ae,onArchiveSession:ee,onUnarchiveSession:_,workspaceManagementStateById:x,setWorkspaceManagementStateById:R,unreadNotificationCount:$,notificationPanelOpen:Y,onToggleNotificationPanel:Ce,onClose:ye,onToggleCollapse:de}){var qr;const ie=Sr(),Ne=Vn(),pe=yc(Ne),{showToast:ne}=vs(),me=Kc(),We=Pi(d=>d),Ve=((qr=wi(We))==null?void 0:qr.name)??"",ct=We.hosts.length+Ul(We).length>1&&Ve.length>0,[S,te]=o.useState(!1),[q,fe]=o.useState(!1),[we,ue]=o.useState(!1),[st,De]=o.useState([]),[Xe,m]=o.useState(null),[C,G]=o.useState(null),[se,he]=o.useState(null),[Be,Ie]=o.useState(null),[tt,Ze]=o.useState(null),[Nt,Ye]=o.useState(null),[nn,It]=o.useState(null),[dt,it]=o.useState(!1),[ft,rt]=o.useState(!1),[sn,Wt]=o.useState(""),[Me,Ge]=o.useState(""),[Se,nt]=o.useState(""),[Ae,Xn]=o.useState({localBranches:[],remoteBranches:[],tags:[]}),[yt,St]=o.useState(!1),[Qs,ut]=o.useState(-1),[ys,Yn]=o.useState(!1),[Ss,wn]=o.useState(!1),[Mn,Rn]=o.useState(null),[rn,Ir]=o.useState(null),[er,tr]=o.useState(null),[En,Tr]=o.useState(null),[Lt,Pn]=o.useState(null),[Jn,Zn]=o.useState(null),[bt,gt]=o.useState(null),[Dt,Mr]=o.useState(!1),[at,Bt]=o.useState(null),[Fe,Qn]=o.useState(null),[es,An]=o.useState(fi),[ts,js]=o.useState({}),[ns,ss]=o.useState({}),[Wn,an]=o.useState([]),[Ln,rs]=o.useState({expandedWorkspaceIds:[],collapsedWorkspaceIds:[]}),[_t,Cs]=o.useState(null),[vn,as]=o.useState(""),[xn,Ns]=o.useState(null),[kt,is]=o.useState(null),[jt,ze]=o.useState([]),[wt,Et]=o.useState(!1),[Dn,Is]=o.useState({}),[Ts,Ms]=o.useState(null),on=o.useRef(null),Ot=o.useRef(null),ln=o.useRef(null),Bn=o.useRef(new Map),cn=o.useRef(null),Rs=o.useRef(null),dn=o.useRef(null),Rr=o.useMemo(()=>new Set(Ln.expandedWorkspaceIds),[Ln.expandedWorkspaceIds]),Er=o.useMemo(()=>new Set(Ln.collapsedWorkspaceIds),[Ln.collapsedWorkspaceIds]),Pr=Ts!==null,Gt=j&&Ne.isDesktop&&Ne.ui.osFamily==="macos",ot=o.useCallback(()=>{Bt(null),Qn(null)},[]),nr=o.useCallback((d,f)=>{Bt(d),Qn(f)},[]),_e=Rl(e,tt)??((nn==null?void 0:nn.id)===tt?nn:null),zt=Se.trim().toLowerCase(),_n=o.useMemo(()=>[{key:"localBranches",label:r("shell.createWorktreeBaseRefLocalGroup"),items:Ae.localBranches},{key:"remoteBranches",label:r("shell.createWorktreeBaseRefRemoteGroup"),items:Ae.remoteBranches},{key:"tags",label:r("shell.createWorktreeBaseRefTagGroup"),items:Ae.tags}].map(f=>({...f,items:f.items.filter(v=>zt?v.value.toLowerCase().includes(zt):!0)})).filter(f=>f.items.length>0),[zt,Ae]),Tt=o.useMemo(()=>_n.flatMap(d=>d.items),[_n]),Te=_e?`create-worktree-base-ref-listbox-${_e.id}`:"create-worktree-base-ref-listbox",Ke=db(e,En),Ee=Ke?Yt(Ke.workspace):null,yn=(Ke==null?void 0:Ke.archivedSessions)??[],{searchOpen:On,searchKeyword:os,filteredSessions:Kt,summaryLoading:Es,summaryError:sr,summaryBySessionId:Ar,setSearchKeyword:Wr,toggleSearch:Lr}=cf(Ke!==null,yn),ht=o.useId(),$e=o.useMemo(()=>cb(e,kt),[kt,e]),Ft=o.useMemo(()=>$e?Xf($e.visibleSessionTree):[],[$e]),Mt=o.useMemo(()=>Ft.map(d=>d.sessionId),[Ft]),Ps=o.useMemo(()=>new Set(Mt),[Mt]),As=o.useMemo(()=>new Set(jt),[jt]),be=Mt.length>0&&jt.length===Mt.length;o.useEffect(()=>{R(d=>{const f=El(e),v=new Set(f),W={};Object.entries(d).forEach(([Z,Re])=>{v.has(Z)&&(W[Z]=Re)}),f.forEach(Z=>{const Re=Rl(e,Z);if(!Re)return;const Qe=Na(Mi(Z),fl),qe=Na(pd(Z),fl),pt=W[Z];let Jt=fd((pt==null?void 0:pt.detail)??Qe??md(Re),Re);(qe!=null&&qe.status||qe!=null&&qe.branches)&&(Jt=bd(Jt,{status:qe.status??null,branches:qe.branches??null})),W[Z]={detail:Jt,loading:!1,error:null}});const F=Object.keys(d),ge=Object.keys(W);return F.length===ge.length&&ge.every(Z=>d[Z]===W[Z])?d:W})},[e]);const Dr=o.useCallback(async d=>{await M(),await Ne.bridge.showNotification(r("shell.importSuccess"),d.path)},[M,Ne.bridge]),rr=o.useCallback(async d=>{await M(),await Ne.bridge.showNotification(r("shell.cloneSuccess"),d.path)},[M,Ne.bridge]);function Ws(d){if(st.includes(d)){De(v=>v.filter(W=>W!==d));return}De(v=>[...v,d]),J(d),Q(d),B(d),le(d)}async function Fn(d,f){if(Dn[d])return;const v=(f==null?void 0:f.trim().toUpperCase())??null;Is(W=>({...W,[d]:!0}));try{await Vl(d,{backgroundColor:v}),await M()}catch(W){ne({title:W instanceof Error?W.message:r("shell.manageWorkspaceColorSaveFailed"),tone:"error"})}finally{Is(W=>({...W,[d]:!1}))}}async function _a(){if(!(!Xe||C)){G(Xe.id);try{await ou(Xe.id),De(d=>d.filter(f=>f!==Xe.id)),R(d=>{const f={...d};return delete f[Xe.id],f}),m(null),await M(),ne({title:r("shell.manageWorkspaceRemoveSuccess"),tone:"success"})}catch(d){ne({title:d instanceof Error?d.message:r("shell.manageWorkspaceRemoveFailed"),tone:"error"})}finally{G(null)}}}o.useEffect(()=>{if(!at)return;function d(f){const v=f.target;v instanceof HTMLElement&&v.closest(".workbench-session-menu")||ot()}return window.addEventListener("pointerdown",d),()=>{window.removeEventListener("pointerdown",d)}},[ot,at]),o.useEffect(()=>{if(!kt){jt.length>0&&ze([]),bt&&gt(null);return}if(!$e){is(null),ze([]),gt(null);return}ze(d=>cd(d,Ps))},[$e,bt,Ps,kt,jt.length]),o.useEffect(()=>{kt&&Mt.length===0&&(is(null),ze([]),gt(null))},[Mt.length,kt]),o.useEffect(()=>{const d=new Set(El(e)),f=new Set(e.flatMap(v=>Ti(v.childWorktrees)));De(v=>v.filter(W=>d.has(W))),rs(v=>({expandedWorkspaceIds:v.expandedWorkspaceIds.filter(W=>f.has(W)),collapsedWorkspaceIds:v.collapsedWorkspaceIds.filter(W=>f.has(W))})),m(v=>v&&d.has(v.id)?v:null),Is(v=>Object.fromEntries(Object.entries(v).filter(([W,F])=>F&&d.has(W))))},[e]),o.useEffect(()=>{const d=a.findIndex(f=>f.session.sessionId===A);An(f=>{const v=fa(a.length,fi,f,d);return v===f?f:v})},[A,a]),o.useEffect(()=>{js(d=>{const f={};for(const v of e){const W=br(v),F=W.findIndex(ge=>ge.item.sessionId===A||Us([ge],A??"",Z=>Z.sessionId).length>0);f[v.workspace.id]=fa(W.length,pr,d[v.workspace.id],F);for(const ge of gr(v.childWorktrees)){ge.item.sessionId===A||Us([ge],A??"",qe=>qe.sessionId).length>0;const Z=ge.item.workspaceId;if(f[Z]!==void 0)continue;const Re=gr(v.childWorktrees).filter(qe=>qe.item.workspaceId===Z&&qe.depth===0),Qe=Re.findIndex(qe=>qe.item.sessionId===A||Us([qe],A??"",pt=>pt.sessionId).length>0);f[Z]=fa(Re.length,pr,d[Z],Qe)}}return yl(d,f)?d:f})},[A,e]),o.useEffect(()=>{ss(d=>{const f={};for(const v of e)for(const W of[...br(v),...gr(v.childWorktrees)])for(const F of zn(en(W))){const ge=en(F);if(ge.length===0)continue;const Z=zn(ge),Re=Z.findIndex(Qe=>Qe.item.sessionId===A);f[F.item.sessionId]=fa(Z.length,pa,d[F.item.sessionId],Re)}return yl(d,f)?d:f})},[A,e]),o.useEffect(()=>{if(!A)return;const d=e.flatMap(f=>[...Us(br(f),A,v=>v.sessionId),...gr(f.childWorktrees).flatMap(v=>Us([v],A,W=>W.sessionId))]);d.length!==0&&an(f=>{const v=new Set(f);let W=!1;for(const F of d)v.has(F)||(v.add(F),W=!0);return W?Array.from(v):f})},[A,e]),o.useEffect(()=>{if(!c)return;const d=[];for(const f of e){const v=od(f.childWorktrees,c);v.length!==0&&d.push(...v)}d.length>0&&rs(f=>{const v=new Set(f.expandedWorkspaceIds);let W=!1;for(const F of d)v.has(F)||(v.add(F),W=!0);return W?{expandedWorkspaceIds:Array.from(v),collapsedWorkspaceIds:f.collapsedWorkspaceIds}:f})},[c,e]),o.useEffect(()=>{if(!tt){It(null),it(!1),rt(!1),Wt(""),Ge(""),nt(""),St(!1),ut(-1),Yn(!1),Xn({localBranches:[],remoteBranches:[],tags:[]}),wn(!1),Rn(null);return}it(!1),Wt(""),Ge(""),nt(""),St(!1),ut(-1),Yn(!1),Xn({localBranches:[],remoteBranches:[],tags:[]}),wn(!1),Rn(null)},[tt]),o.useEffect(()=>{const d=_e;if(!dt||!d)return;let f=!1;const v=d.id;return wn(!0),Rn(null),Promise.all([Iu(v),Tu(v)]).then(([W,F])=>{f||Xn(Df(W,F))}).catch(()=>{f||(Xn({localBranches:[],remoteBranches:[],tags:[]}),Rn(r("shell.createWorktreeBaseRefLoadFailed")))}).finally(()=>{f||wn(!1)}),()=>{f=!0}},[_e==null?void 0:_e.id,dt]),o.useLayoutEffect(()=>{if(!yt||!on.current){Ir(null),tr(null);return}const d=()=>{const v=on.current;if(!v)return;const W=Bf(v);Ir({top:W.bottom+8,left:W.left,width:W.width})};d();const f=v=>{var F,ge;const W=v.target;W instanceof Node&&((F=on.current)!=null&&F.contains(W)||(ge=Ot.current)!=null&&ge.contains(W)||(St(!1),ut(-1)))};return window.addEventListener("resize",d),window.addEventListener("scroll",d,!0),window.addEventListener("pointerdown",f),()=>{window.removeEventListener("resize",d),window.removeEventListener("scroll",d,!0),window.removeEventListener("pointerdown",f)}},[Tt.length,yt]),o.useLayoutEffect(()=>{if(!yt||!Ot.current){tr(null);return}const d=Ot.current,f=()=>{const W=Math.ceil(d.getBoundingClientRect().height);tr(F=>F===W?F:W)};if(f(),typeof ResizeObserver>"u")return;const v=new ResizeObserver(()=>{f()});return v.observe(d),()=>{v.disconnect()}},[yt,_n,Ss,Mn]);function $n(){te(!0)}function Rt(){fe(!0)}function Je(d){un(),Ze(null),Ye({kind:"workspace",workspaceId:d.id,workspaceName:d.name})}function un(){it(!1),Wt(""),Ge(""),nt(""),St(!1),ut(-1),Yn(!1)}function ar(d,f){const v=d.getBoundingClientRect();return f<=v.top+v.height/2?"before":"after"}function ls(){ln.current!==null&&(cancelAnimationFrame(ln.current),ln.current=null),Ms(null)}function Hn(d){const f=(d==null?void 0:d.commit)??!1,v=(d==null?void 0:d.preserveClickSuppression)??!1,W=cn.current,F=Rs.current;cn.current=null,Rs.current=null,F==null||F(),W!=null&&W.dragging&&(ls(),f&&D(),!v&&dn.current===W.workspaceId&&(dn.current=null))}function to(d){if(dn.current===d){dn.current=null;return}T(d)}function qt(d,f){if(f){Bn.current.set(d,f);return}Bn.current.delete(d)}function Sn(d,f){for(const[v,W]of Bn.current){const F=W.getBoundingClientRect();if(d>=F.left&&d<=F.right&&f>=F.top&&f<=F.bottom)return{workspaceId:v,element:W}}return null}function Br(d,f){var Re;if(!Gt||d.button!==0)return;Hn();const v=d.currentTarget,W={pointerId:d.pointerId,workspaceId:f,startX:d.clientX,startY:d.clientY,pointerTarget:v,dragging:!1};cn.current=W,(Re=v.setPointerCapture)==null||Re.call(v,d.pointerId);const F=Qe=>{ir(Qe)},ge=Qe=>{jn(Qe.pointerId,{commit:!0,preserveClickSuppression:!0})},Z=Qe=>{jn(Qe.pointerId,{commit:!1,preserveClickSuppression:!1})};Rs.current=()=>{v.removeEventListener("pointermove",F),v.removeEventListener("pointerup",ge),v.removeEventListener("pointercancel",Z),window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",ge),window.removeEventListener("pointercancel",Z)},v.addEventListener("pointermove",F),v.addEventListener("pointerup",ge),v.addEventListener("pointercancel",Z),window.addEventListener("pointermove",F,{passive:!1}),window.addEventListener("pointerup",ge),window.addEventListener("pointercancel",Z)}function ir(d){const f=cn.current;if(!f||f.pointerId!==d.pointerId)return;if(!f.dragging){if(Math.hypot(d.clientX-f.startX,d.clientY-f.startY)<xf)return;f.dragging=!0,dn.current=f.workspaceId,H(),Ms(f.workspaceId)}d.preventDefault();const v=Sn(d.clientX,d.clientY);!v||v.workspaceId===f.workspaceId||X(f.workspaceId,v.workspaceId,ar(v.element,d.clientY))}function jn(d,f){var W,F;const v=cn.current;!v||v.pointerId!==d||((F=(W=v.pointerTarget).releasePointerCapture)==null||F.call(W,d),Hn(f))}function Oa(d){ir(d)}function Vt(d){jn(d.pointerId,{commit:!0,preserveClickSuppression:!0})}function _r(d){jn(d.pointerId,{commit:!1,preserveClickSuppression:!1})}function or(d,f){d.dataTransfer.effectAllowed="move",d.dataTransfer.setData("text/plain",f),H(),ln.current!==null&&cancelAnimationFrame(ln.current),ln.current=requestAnimationFrame(()=>{ln.current=null,Ms(f)})}function vt(d,f){const v=Ts||d.dataTransfer.getData("text/plain");!v||v===f||(d.preventDefault(),d.dataTransfer.dropEffect="move",X(v,f,ar(d.currentTarget,d.clientY)))}function Ls(d){d.preventDefault()}function lr(){ls(),D()}o.useEffect(()=>()=>{Hn()},[]);function Fa(d){return ns[d]??pa}function $a(d){return Wn.includes(d)}function cs(d){return ts[d]??pr}function Ha(){An(d=>Math.min(a.length,d+fi))}function Or(d,f){js(v=>({...v,[d]:Math.min(f,(v[d]??pr)+pr)}))}function Ua(d){ss(f=>({...f,[d]:(f[d]??pa)+pa}))}function Ga(d){an(f=>f.includes(d)?f.filter(v=>v!==d):[...f,d])}function Fr(d,f){return Er.has(d)?!1:f||Rr.has(d)}function za(d,f){const v=!Fr(d,f);rs(W=>{const F=W.expandedWorkspaceIds.filter(Z=>Z!==d),ge=W.collapsedWorkspaceIds.filter(Z=>Z!==d);return v?{expandedWorkspaceIds:[...F,d],collapsedWorkspaceIds:ge}:{expandedWorkspaceIds:F,collapsedWorkspaceIds:[...ge,d]}})}function Ka(d){for(const f of e){const v=zn(eo(f.visibleSessions,s)).find(W=>W.item.sessionId===d)??sd(f.childWorktrees,d);if(v)return en(v)}return[]}function $r(d,f){const v=Yt(d);return n.jsxs("button",{type:"button",className:"workbench-archive-folder","data-workspace-tone":v.tone,style:In(v),onClick:()=>Tr(d.id),children:[n.jsxs("span",{className:"workbench-archive-folder-main",children:[n.jsx(Fb,{}),n.jsx("span",{children:r("shell.archiveFolderLabel")})]}),n.jsx("span",{className:"workbench-section-counter",children:f.length})]})}function hn(){return n.jsxs("div",{className:"workbench-workspace-batch-toolbar",children:[n.jsx("span",{className:"workbench-workspace-batch-label",children:r("shell.batchSelectionMode")}),n.jsxs("span",{className:"workbench-workspace-batch-counter",children:[jt.length,"/",Mt.length]}),n.jsx("button",{type:"button",className:"workbench-workspace-batch-action",onClick:Gr,children:be?r("shell.clearSelectedSessions"):r("shell.selectAllSessions")}),n.jsx("button",{type:"button",className:"workbench-workspace-batch-action primary",disabled:jt.length===0||wt||Dt,onClick:()=>{Kr()},children:wt?r("shell.batchArchiving"):r("shell.batchArchiveAction")}),n.jsx("button",{type:"button",className:"workbench-workspace-batch-action danger",disabled:jt.length===0||wt||Dt,onClick:qa,children:Dt?r("shell.batchDeleting"):r("shell.batchDeleteAction")}),n.jsx("button",{type:"button",className:"workbench-workspace-batch-action",onClick:Ur,children:r("common.cancel")})]})}function ds(d,f="workbench-workspace-actions"){return n.jsxs("div",{className:f,children:[n.jsx("button",{type:"button",className:"workbench-workspace-icon-button","aria-label":r("shell.switchWorkspace"),title:r("shell.switchWorkspace"),"aria-pressed":c===d,onClick:()=>{K(d),ye==null||ye()},children:n.jsx(Lb,{})}),n.jsx("button",{type:"button",className:"workbench-workspace-icon-button","aria-label":r("shell.batchSelectSessions"),title:r("shell.batchSelectSessions"),onClick:()=>Hr(d),children:n.jsx(Wb,{})}),n.jsx("button",{type:"button",className:"workbench-workspace-icon-button workbench-workspace-create","aria-label":r("shell.createSession"),title:r("shell.createSession"),onClick:()=>Ze(d),children:n.jsx(Nb,{})})]})}function us(d){const f=d.visibleSessionTree,W=new Set(Ti(d.children)).has(c??""),F=d.workspace.id===c||W,ge=Pr||!Fr(d.workspace.id,F),Z=Yt(d.workspace);return n.jsxs("section",{className:"workbench-workspace-group","data-worktree-node":"true","data-batch-active":kt===d.workspace.id,"data-worktree-depth":d.meta.depth,"data-workspace-tone":"worktree",style:In(Z),children:[n.jsxs("div",{className:"workbench-workspace-header minimal",children:[n.jsxs("button",{type:"button",className:"workbench-workspace-toggle","aria-label":ge?r("shell.worktreeExpand"):r("shell.worktreeCollapse"),onClick:()=>za(d.workspace.id,F),children:[n.jsx("span",{className:"workbench-workspace-toggle-icon","aria-hidden":"true",children:n.jsx(kr,{expanded:!ge})}),n.jsxs("span",{children:[n.jsx("strong",{children:d.meta.displayName||d.workspace.name}),n.jsx("span",{className:"session-meta",children:d.meta.branchName})]})]}),kt===d.workspace.id?hn():ds(d.workspace.id)]}),ge?null:n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"workbench-session-list","data-workspace-tone":Z.tone,style:In(Z),children:[f.length===0?n.jsx("p",{className:"workbench-session-empty",children:r("shell.emptyWorkspaceSessions")}):f.slice(0,cs(d.workspace.id)).map(Re=>hs({node:Re,workspace:d.workspace,workspaceContext:Z,menuKeyPrefix:`worktree:${d.workspace.id}`,showWorkspaceName:!1,selectionMode:kt===d.workspace.id,favoriteEnabled:!0})),f.length>cs(d.workspace.id)?n.jsx("button",{type:"button",className:"workbench-subsession-expand ghost-button",onClick:()=>Or(d.workspace.id,f.length),children:r("shell.sessionExpandMore")}):null]}),d.children.length>0?n.jsx("div",{className:"workbench-session-list workbench-worktree-child-list",children:d.children.map(Re=>us(Re))}):null,$r(d.workspace,d.archivedSessions)]})]},d.workspace.id)}function hs(d){var g;const{node:f,workspace:v,workspaceContext:W,menuKeyPrefix:F,showWorkspaceName:ge,selectionMode:Z,favoriteEnabled:Re,ancestorExpanded:Qe=!1,allowToggle:qe=f.depth===0,ancestorHasNextSiblings:pt=[],hasNextSibling:Jt=!1,isFirstSibling:pn=!1}=d,ve=f.item,Cn=en(f),Zt=Qe||$a(ve.sessionId),He=Zt&&qe,Vr=He?Yf(f,Fa(ve.sessionId),s):f,ms=Zt?en(Vr):[],Xr=zn(Cn).length,Yr=zn(ms).length,Jr=He&&Yr<Xr,l=f.depth>0?[...pt,Jt]:[...pt],p=Zt&&((g=ve.parallelGroup)==null?void 0:g.role)==="anchor"&&Cn.some(P=>{var U,V,ce;return((V=(U=Vc(P))==null?void 0:U.parallelGroup)==null?void 0:V.groupId)===((ce=ve.parallelGroup)==null?void 0:ce.groupId)});return n.jsxs("div",{className:"workbench-session-tree-node",children:[n.jsxs("div",{className:"workbench-session-tree-row",style:{"--workbench-session-tree-depth":f.depth},children:[f.depth>0?n.jsxs("div",{className:"workbench-session-tree-guides","aria-hidden":"true",children:[pt.map((P,U)=>P?n.jsx("span",{className:"workbench-session-tree-guide-column",style:{"--workbench-session-tree-level":U+1}},`${ve.sessionId}:ancestor:${U}`):null),n.jsx("span",{className:"workbench-session-tree-guide-branch","data-continue":Jt,"data-first":pn,style:{"--workbench-session-tree-level":f.depth},children:n.jsx("span",{className:"workbench-session-tree-guide-branch-horizontal"})})]}):null,n.jsx(Dl,{menuKey:`${F}:${ve.sessionId}`,session:ve,workspace:v,workspaceContext:W,isActive:ve.sessionId===A,isFavorite:Re&&i.has(ve.sessionId),menuOpen:at===`${F}:${ve.sessionId}`,showWorkspaceName:ge,depth:f.depth,showActions:Re,hasSubagents:qe&&Cn.length>0,subagentListExpanded:Zt,selectionMode:Z,selected:As.has(ve.sessionId),onToggleSelect:()=>Ds(ve.sessionId),onToggleSubagents:()=>Ga(ve.sessionId),onOpen:()=>{ie(Ut(v.id,ve.sessionId)),ye==null||ye()},onRename:()=>dr(ve,v),menuAnchorPoint:at===`${F}:${ve.sessionId}`?Fe:null,onOpenContextMenu:P=>nr(`${F}:${ve.sessionId}`,P),onToggleFavorite:()=>cr(ve.sessionId),onArchive:()=>ps(ve.sessionId),onDelete:ja(ve.provider).supportsSessionDelete===!0?()=>{ot(),Pn({session:ve,workspace:v})}:void 0,onCloseMenu:ot})]}),Cn.length>0&&Zt?n.jsxs("div",{className:"workbench-subsession-list",children:[p?n.jsx("div",{className:"workbench-session-tree-node",children:n.jsxs("div",{className:"workbench-session-tree-row",style:{"--workbench-session-tree-depth":f.depth+1},children:[n.jsxs("div",{className:"workbench-session-tree-guides","aria-hidden":"true",children:[l.map((P,U)=>P?n.jsx("span",{className:"workbench-session-tree-guide-column",style:{"--workbench-session-tree-level":U+1}},`parallel-anchor-replica:${ve.sessionId}:ancestor:${U}`):null),n.jsx("span",{className:"workbench-session-tree-guide-branch","data-continue":ms.length>0,"data-first":"true",style:{"--workbench-session-tree-level":f.depth+1},children:n.jsx("span",{className:"workbench-session-tree-guide-branch-horizontal"})})]}),n.jsx(Dl,{menuKey:`${F}:parallel-anchor-replica:${ve.sessionId}`,session:ve,workspace:v,workspaceContext:W,isActive:!1,isFavorite:Re&&i.has(ve.sessionId),menuOpen:at===`${F}:parallel-anchor-replica:${ve.sessionId}`,showWorkspaceName:ge,depth:f.depth+1,showActions:Re,hasSubagents:!1,subagentListExpanded:!1,selectionMode:Z,selected:As.has(ve.sessionId),onToggleSelect:()=>Ds(ve.sessionId),onOpen:()=>{ie(Ut(v.id,ve.sessionId)),ye==null||ye()},onRename:()=>dr(ve,v),menuAnchorPoint:at===`${F}:parallel-anchor-replica:${ve.sessionId}`?Fe:null,onOpenContextMenu:P=>nr(`${F}:parallel-anchor-replica:${ve.sessionId}`,P),onToggleFavorite:()=>cr(ve.sessionId),onArchive:()=>ps(ve.sessionId),onDelete:ja(ve.provider).supportsSessionDelete===!0?()=>{ot(),Pn({session:ve,workspace:v})}:void 0,onCloseMenu:ot})]})},`parallel-anchor-replica:${ve.sessionId}`):null,ms.map((P,U)=>hs({node:P,workspace:v,workspaceContext:W,menuKeyPrefix:F,showWorkspaceName:ge,selectionMode:Z,favoriteEnabled:Re,ancestorExpanded:!0,allowToggle:!1,ancestorHasNextSiblings:l,hasNextSibling:U<ms.length-1,isFirstSibling:!p&&U===0})),Jr?n.jsx("button",{type:"button",className:"workbench-subsession-expand ghost-button",onClick:()=>Ua(ve.sessionId),children:r("shell.subagentExpandMore")}):null]}):null]},ve.sessionId)}function Hr(d){ot(),is(d),ze([]),gt(null)}function Ur(){is(null),ze([]),gt(null)}function Ds(d){ze(f=>gb(f,d))}function Gr(){ze(d=>d.length===Mt.length?[]:Mt)}function qa(){if(!$e||jt.length===0||wt||Dt)return;const d=new Map(Ft.map(v=>[v.sessionId,v])),f=jt.flatMap(v=>{const W=d.get(v);return W?[W]:[]});f.length!==0&&(ot(),gt({workspace:$e.workspace,sessions:f}))}async function zr(d,f){he(d),Ie(f);try{await Xc(d,f),Ze(null),ie(mc(d,f)),ye==null||ye()}catch(v){ne({title:v instanceof Error?v.message:r("shell.startSessionFailed"),tone:"error"})}finally{he(null),Ie(null)}}async function Va(d){if(d.preventDefault(),!_e||ft)return;const f=sn.trim(),v=Me.trim(),W=Se.trim();if(!f){ne({title:r("shell.createWorktreeBranchRequired"),tone:"error"});return}if(!Wf(f)){ne({title:r("shell.createWorktreeBranchInvalid"),tone:"error"});return}rt(!0);try{const F=await lu({sourceWorkspaceId:_e.id,branchName:f,displayName:v||void 0,baseRef:W||void 0});It(F.workspace),K(F.workspace.id),await M(),Ze(F.workspace.id),un(),ne({title:r("shell.createWorktreeSucceeded",{name:F.meta.displayName||F.workspace.name}),tone:"success"})}catch(F){ne({title:F instanceof Error?F.message:r("shell.createWorktreeFailed"),tone:"error"})}finally{rt(!1)}}async function cr(d){const f=i.has(d);ot();try{await ae(d),ne({title:f?r("shell.favoriteRemoved"):r("shell.favoriteAdded"),tone:"success"})}catch(v){ne({title:v instanceof Error?v.message:r("shell.favoriteToggleFailed"),tone:"error"})}}async function ps(d){ot();try{await ee(d),ne({title:r("shell.archiveAdded"),tone:"success"})}catch(f){ne({title:f instanceof Error?f.message:r("shell.navigationLoadFailed"),tone:"error"})}}async function Xa(){if(!Lt||Jn)return;const{session:d,workspace:f}=Lt;Zn(d.sessionId),ot();try{await ro(d.sessionId),ze(v=>v.filter(W=>W!==d.sessionId)),Pn(null),A===d.sessionId&&ie(f.id?Xs(f.id):Ct()),await M(),ne({title:r("shell.deleteSessionSuccess"),tone:"success"})}catch(v){ne({title:v instanceof Error?v.message:r("shell.deleteSessionFailed"),tone:"error"})}finally{Zn(null)}}async function Kr(){if(!(jt.length===0||wt||Dt)){ot(),Et(!0);try{const d=[...jt],f=await Promise.allSettled(d.map(async F=>({sessionId:F,session:await ql(F,!0)}))),v=[];let W=0;for(const F of f){if(F.status==="fulfilled"){v.push(F.value.sessionId),L(F.value.session);continue}W+=1}v.length>0&&(await M(),ze(F=>F.filter(ge=>!v.includes(ge)))),W>0?ne({title:v.length>0?r("shell.batchArchivePartialFailed"):r("shell.batchArchiveFailed"),tone:"error"}):ne({title:r("shell.batchArchiveSuccess"),tone:"success"})}catch(d){ne({title:d instanceof Error?d.message:r("shell.batchArchiveFailed"),tone:"error"})}finally{Et(!1)}}}async function Ya(){if(!bt||Dt)return;const{workspace:d,sessions:f}=bt,v=f.map(W=>W.sessionId);if(v.length===0){gt(null);return}Mr(!0),ot();try{const W=await Promise.allSettled(v.map(async Z=>(await ro(Z),Z))),F=[];let ge=0;for(const Z of W){if(Z.status==="fulfilled"){F.push(Z.value);continue}ge+=1}if(F.length>0&&(A&&F.includes(A)&&ie(d.id?Xs(d.id):Ct()),ze(Z=>Z.filter(Re=>!F.includes(Re))),await M()),ge>0){gt(Z=>{if(!Z)return Z;const Re=Z.sessions.filter(Qe=>!F.includes(Qe.sessionId));return Re.length>0?{...Z,sessions:Re}:null}),ne({title:F.length>0?r("shell.batchDeletePartialFailed"):r("shell.batchDeleteFailed"),tone:"error"});return}gt(null),ne({title:r("shell.batchDeleteSuccess"),tone:"success"})}catch(W){ne({title:W instanceof Error?W.message:r("shell.batchDeleteFailed"),tone:"error"})}finally{Mr(!1)}}async function Ja(d){ot();try{await _(d),ne({title:r("shell.archiveRestored"),tone:"success"})}catch(f){ne({title:f instanceof Error?f.message:r("shell.navigationLoadFailed"),tone:"error"})}}function dr(d,f){ot(),Cs({session:d,workspace:f}),as(d.title)}async function $t(d){if(d.preventDefault(),!_t)return;const f=vn.trim();if(f){Ns(_t.session.sessionId);try{const v=await Xl(_t.session.sessionId,f);L(v),Cs(null),as(""),ne({title:r("shell.renameSuccess"),tone:"success"})}catch(v){ne({title:v instanceof Error?v.message:r("shell.renameFailed"),tone:"error"})}finally{Ns(null)}}}const Xt=a.slice(0,es),Bs=Xt.length<a.length;function Yt(d){return t[d.id]??Ra(d)}function Un(d,f,v,W,F=[]){var Zt;const ge=st.includes(d.id),Z=x[d.id]??{detail:null,loading:!1,error:null},Re=C===d.id,Qe=Dn[d.id]===!0,qe=(Zt=Z.detail)!=null&&Zt.git.remotes.length?Z.detail.git.remotes.map(He=>`${He.name}: ${He.url}`).join(" · "):r("shell.manageWorkspaceNoRemote"),pt=Z.detail?tm(Z.detail.codeComposition.items,r("shell.manageWorkspaceCodeCompositionOther")):[],Jt=pt.length>0?sm(pt):void 0,pn=Yt(d),ve=ub(pn,F),Cn=[...F,pn.displayName];return n.jsxs("article",{className:"workbench-manage-item","data-workspace-tone":pn.tone,"data-worktree-node":W,style:In(pn),children:[n.jsxs("button",{type:"button",className:"workbench-manage-item-toggle","aria-expanded":ge,onClick:()=>Ws(d.id),children:[n.jsxs("span",{className:"workbench-manage-item-heading",children:[n.jsx(kr,{expanded:ge}),n.jsxs("span",{className:"workbench-manage-item-heading-copy",children:[n.jsx("strong",{children:pn.displayName}),n.jsx("span",{className:"workbench-manage-item-tree-path",children:ve})]})]}),n.jsx("span",{className:"workbench-section-counter",children:f})]}),ge?n.jsxs("div",{className:"workbench-manage-item-body",children:[n.jsxs("div",{className:"workbench-manage-detail-block",children:[n.jsx("span",{className:"workbench-manage-detail-label",children:r("shell.manageWorkspacePathLabel")}),n.jsx("p",{className:"workbench-manage-detail-value",children:d.path})]}),W?n.jsxs("div",{className:"workbench-manage-detail-block",children:[n.jsxs("div",{className:"workbench-manage-detail-header",children:[n.jsx("span",{className:"workbench-manage-detail-label",children:r("shell.manageWorkspaceColorLabel")}),n.jsxs("div",{className:"workbench-manage-color-actions",children:[n.jsx("div",{className:"workbench-manage-color-palette","aria-label":r("shell.manageWorkspaceColorLabel"),children:Cf.map(He=>n.jsx("button",{type:"button",className:"workbench-manage-color-swatch","aria-label":r("shell.manageWorkspaceColorSelectSwatch",{color:He}),"aria-pressed":d.backgroundColor===He,disabled:Qe,"data-selected":d.backgroundColor===He,style:{backgroundColor:He},onClick:()=>{Fn(d.id,He)}},He))}),n.jsx("button",{type:"button",className:"ghost-button",disabled:Qe||!d.backgroundColor,onClick:()=>{Fn(d.id,null)},children:r("shell.manageWorkspaceColorClearAction")})]})]}),n.jsx("p",{className:"workbench-manage-hint",children:d.backgroundColor??r("shell.manageWorkspaceColorUnset")})]}):null,Z.loading&&Z.detail===null?n.jsx("p",{className:"workbench-manage-status status-text",children:r("shell.manageWorkspaceLoading")}):null,Z.error?n.jsx("p",{className:"workbench-manage-status status-text","data-tone":"error",children:Z.error}):null,Z.detail?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"workbench-manage-detail-block",children:n.jsxs("div",{className:"workbench-manage-detail-header",children:[n.jsx("span",{className:"workbench-manage-detail-label",children:r("shell.manageWorkspaceGitCommitCount")}),n.jsx("strong",{className:"workbench-manage-detail-accent",children:Z.detail.git.commitCount??"--"})]})}),n.jsxs("div",{className:"workbench-manage-detail-block",children:[n.jsx("span",{className:"workbench-manage-detail-label",children:r("shell.manageWorkspaceGitInfoLabel")}),Z.detail.git.isRepository?n.jsxs("div",{className:"workbench-manage-kv-list",children:[n.jsxs("div",{className:"workbench-manage-kv-item",children:[n.jsx("span",{children:r("shell.manageWorkspaceRepoRoot")}),n.jsx("span",{children:Z.detail.git.repoRoot??"--"})]}),n.jsxs("div",{className:"workbench-manage-kv-item",children:[n.jsx("span",{children:r("shell.manageWorkspaceCurrentBranch")}),n.jsx("span",{children:Z.detail.git.currentBranch??"--"})]}),n.jsxs("div",{className:"workbench-manage-kv-item",children:[n.jsx("span",{children:r("shell.manageWorkspaceRemoteLabel")}),n.jsx("span",{children:qe})]})]}):n.jsx("p",{className:"workbench-section-empty",children:Z.detail.git.error??r("shell.manageWorkspaceNotGit")})]}),n.jsxs("div",{className:"workbench-manage-detail-block",children:[n.jsx("span",{className:"workbench-manage-detail-label",children:r("shell.manageWorkspaceCodeCompositionLabel")}),pt.length>0?n.jsxs("div",{className:"workbench-manage-type-chart",children:[n.jsxs("div",{className:"workbench-manage-type-chart-ring",style:Jt,"aria-hidden":"true",children:[n.jsx("strong",{className:"workbench-manage-type-chart-total",children:Z.detail.codeComposition.scannedFileCount}),n.jsx("span",{className:"workbench-manage-type-chart-caption",children:r("shell.manageWorkspaceCodeCompositionFiles")})]}),n.jsx("div",{className:"workbench-manage-type-list",children:pt.map(He=>n.jsxs("div",{className:"workbench-manage-type-item",children:[n.jsxs("span",{className:"workbench-manage-type-meta",children:[n.jsx("span",{className:"workbench-manage-type-swatch",style:{backgroundColor:He.color},"aria-hidden":"true"}),n.jsx("span",{className:"workbench-manage-type-name",children:He.type})]}),n.jsxs("span",{children:[He.count," · ",em(He)]})]},He.key))})]}):n.jsx("p",{className:"workbench-section-empty",children:Z.detail.codeComposition.error??r("shell.manageWorkspaceNoCodeComposition")}),Z.detail.codeComposition.truncated?n.jsx("p",{className:"workbench-manage-hint",children:r("shell.manageWorkspaceCodeTruncated",{count:Z.detail.codeComposition.scannedFileCount})}):null]})]}):null,n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",onClick:()=>{ue(!1),ie(cc(d.id))},children:r("shell.workspaceDetailDebugOpenPageAction")}),n.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:!!C,onClick:()=>m(d),children:Re?r("shell.manageWorkspaceRemoving"):r("shell.manageWorkspaceRemoveAction")})]})]}):null,v.length>0?n.jsx("div",{className:"workbench-manage-children",children:v.map(He=>Un(He.workspace,He.visibleSessions.length+He.archivedSessions.length,He.children,!0,Cn))}):null]},d.id)}return n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"workbench-nav-header","data-window-drag-handle":"workbench-nav-header","data-tauri-drag-region":pe,children:n.jsxs("div",{className:"workbench-nav-toolbar","data-tauri-drag-region":pe,children:[de?n.jsx("button",{type:"button",className:"workbench-nav-toolbar-button","aria-label":r("shell.hideSessionSidebar"),title:r("shell.hideSessionSidebar"),onClick:de,children:n.jsx(wd,{})}):null,n.jsx($c,{}),n.jsx(kd,{unreadCount:$,open:Y,onToggle:Ce})]})}),n.jsxs("div",{ref:me,className:"workbench-nav-body","data-scrollbar-autohide":"true",children:[n.jsxs("div",{className:"workbench-nav-segment",children:[n.jsxs("div",{className:"workbench-nav-segment-tabs",role:"tablist","aria-label":r("shell.centerTabsLabel"),children:[n.jsxs("div",{className:"workbench-nav-segment-pair",children:[n.jsxs("button",{type:"button",className:u?"workbench-nav-segment-button active":"workbench-nav-segment-button","data-layout":"paired",role:"tab","aria-selected":u,onClick:z,children:[n.jsx(Tb,{}),n.jsx("span",{children:r("shell.conversationEntry")})]}),n.jsxs("button",{type:"button",className:k?"workbench-nav-segment-button active":"workbench-nav-segment-button","data-layout":"paired",role:"tab","aria-selected":k,onClick:w,children:[n.jsx(Rb,{}),n.jsx("span",{children:r("shell.butlerEntry")})]})]}),n.jsxs("button",{type:"button",className:h?"workbench-nav-segment-button active":"workbench-nav-segment-button",role:"tab","aria-selected":h,onClick:I,children:[n.jsx(Mb,{}),n.jsx("span",{children:r("shell.terminalsEntry")})]})]}),n.jsx(gp,{triggerClassName:"workbench-nav-segment-button",triggerLabel:r("shell.skillsEntry"),triggerLeading:n.jsx(Eb,{})}),n.jsxs("button",{type:"button",className:"workbench-nav-segment-button","data-open":b,"aria-haspopup":"dialog","aria-expanded":b,onClick:O,children:[n.jsx(Ib,{}),n.jsx("span",{children:r("shell.searchEntry")})]})]}),N?n.jsx("div",{className:"workbench-status-row",children:n.jsx("p",{className:"status-text","data-tone":"error",children:N})}):null,a.length>0?n.jsxs("section",{className:"workbench-section-block workbench-favorite-section",children:[n.jsxs("div",{className:"workbench-section-heading",children:[n.jsxs("div",{className:"workbench-section-heading-main",children:[n.jsx(vd,{active:!0,className:"workbench-favorite-heading-icon"}),n.jsx("span",{children:r("shell.favoriteSectionTitle")})]}),n.jsx("span",{className:"workbench-section-counter",children:a.length})]}),n.jsxs("div",{className:"workbench-session-list",children:[Xt.map(d=>{const f=Ka(d.session.sessionId);return n.jsx("div",{children:hs({node:{item:d.session,depth:0,children:f},workspace:d.workspace,workspaceContext:Yt(d.workspace),menuKeyPrefix:"favorite",showWorkspaceName:!0,selectionMode:!1,favoriteEnabled:!0})},d.session.sessionId)}),Bs?n.jsx("button",{type:"button",className:"workbench-subsession-expand ghost-button",onClick:Ha,children:r("shell.favoriteExpandMore")}):null]})]}):null,y&&e.length===0?n.jsx(vb,{}):null,!y&&!N&&e.length===0?n.jsx("div",{className:"workbench-empty-state minimal",children:n.jsx("p",{children:r("shell.emptyNavigationBody")})}):null,n.jsxs("section",{className:"workbench-section-block workbench-workspace-section",children:[n.jsxs("div",{className:"workbench-section-heading",children:[n.jsx("div",{className:"workbench-section-heading-main",children:n.jsx("span",{children:r("shell.workspaceSectionTitle")})}),n.jsxs("div",{className:"workbench-section-actions",children:[n.jsx("button",{type:"button",className:"workbench-workspace-icon-button","aria-label":r("shell.manageWorkspaceAction"),title:r("shell.manageWorkspaceAction"),onClick:()=>ue(!0),children:n.jsx(Sb,{})}),n.jsx("button",{type:"button",className:"workbench-workspace-icon-button","aria-label":r("shell.importWorkspaceTitle"),title:r("shell.importWorkspaceTitle"),onClick:$n,children:n.jsx(yb,{})}),n.jsx("button",{type:"button",className:"workbench-workspace-icon-button","aria-label":r("shell.cloneWorkspaceTitle"),title:r("shell.cloneWorkspaceTitle"),onClick:Rt,children:n.jsx(Pb,{})})]})]}),e.map(d=>{const f=br(d),v=Ts===d.workspace.id,W=d.isCollapsed||Pr;return n.jsxs("section",{className:"workbench-workspace-group",ref:F=>qt(d.workspace.id,F),"data-workspace-group-id":d.workspace.id,"data-batch-active":kt===d.workspace.id,"data-dragging":v,onDragOver:F=>vt(F,d.workspace.id),onDrop:Ls,children:[n.jsxs("div",{className:"workbench-workspace-header minimal",children:[n.jsxs("button",{type:"button",className:"workbench-workspace-toggle","aria-label":W?r("shell.workspaceExpand"):r("shell.workspaceCollapse"),draggable:j&&!Gt,onClick:()=>to(d.workspace.id),onPointerDown:Gt?F=>Br(F,d.workspace.id):void 0,onPointerMove:Gt?Oa:void 0,onPointerUp:Gt?Vt:void 0,onPointerCancel:Gt?_r:void 0,onDragStart:j&&!Gt?F=>or(F,d.workspace.id):void 0,onDragEnd:j&&!Gt?lr:void 0,"data-reorder-enabled":j?"true":void 0,children:[n.jsx("span",{className:"workbench-workspace-toggle-icon","aria-hidden":"true",children:n.jsx(kr,{expanded:!W})}),n.jsx("strong",{children:d.workspace.name})]}),kt===d.workspace.id?hn():ds(d.workspace.id)]}),W?null:n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"workbench-session-list",children:[f.length===0?n.jsx("p",{className:"workbench-session-empty",children:r("shell.emptyWorkspaceSessions")}):f.slice(0,cs(d.workspace.id)).map(F=>hs({node:F,workspace:d.workspace,workspaceContext:Yt(d.workspace),menuKeyPrefix:`workspace:${d.workspace.id}`,showWorkspaceName:!1,selectionMode:kt===d.workspace.id,favoriteEnabled:!0})),f.length>cs(d.workspace.id)?n.jsx("button",{type:"button",className:"workbench-subsession-expand ghost-button",onClick:()=>Or(d.workspace.id,f.length),children:r("shell.sessionExpandMore")}):null]}),d.childWorktrees.length>0?n.jsx("div",{className:"workbench-session-list workbench-worktree-child-list",children:d.childWorktrees.map(F=>us(F))}):null,$r(d.workspace,d.archivedSessions)]})]},d.workspace.id)})]})]}),n.jsx("div",{className:"workbench-nav-footer minimal",children:n.jsxs("div",{className:"workbench-nav-footer-actions",children:[n.jsxs("button",{className:"settings-entry-button workbench-nav-settings-button",type:"button",onClick:E,title:ct?`${r("settings.title")} · ${Ve}`:r("settings.title"),children:[n.jsx(Ab,{}),n.jsx("span",{className:"settings-entry-label",children:r("settings.title")}),ct?n.jsx("span",{className:"workbench-nav-settings-host-badge",title:Ve,children:Ve}):null]}),n.jsx(qm,{onOpenSoftwareUpdate:()=>ie("/settings/software-update")})]})}),n.jsx(et,{open:we,title:r("shell.manageWorkspaceTitle"),className:"workbench-manage-workspaces-modal",description:r("shell.manageWorkspaceDescription"),headerActions:n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"secondary-button workbench-manage-modal-action",onClick:$n,children:r("shell.manageWorkspaceImportAction")}),n.jsx("button",{type:"button",className:"secondary-button workbench-manage-modal-action",onClick:Rt,children:r("shell.manageWorkspaceCloneAction")})]}),onClose:()=>{C||ue(!1)},children:e.length>0?n.jsx("div",{className:"workbench-manage-list",children:e.map(d=>Un(d.workspace,d.visibleSessions.length+d.archivedSessions.length,d.childWorktrees,!1))}):n.jsx("p",{className:"workbench-section-empty",children:r("shell.manageWorkspaceEmpty")})}),n.jsxs(et,{open:Lt!==null,title:r("shell.deleteSessionConfirmTitle"),description:r("shell.deleteSessionConfirmDescription"),onClose:()=>{Jn||Pn(null)},children:[n.jsx("p",{className:"workbench-section-empty",children:Lt?Lt.session.title:""}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:!!Jn,onClick:()=>Pn(null),children:r("common.cancel")}),n.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:!!Jn,onClick:()=>{Xa()},children:Jn?r("common.loading"):r("shell.deleteSessionAction")})]})]}),n.jsxs(et,{open:bt!==null,title:r("shell.batchDeleteConfirmTitle"),description:r("shell.batchDeleteConfirmDescription",{count:`${(bt==null?void 0:bt.sessions.length)??0}`}),onClose:()=>{Dt||gt(null)},children:[n.jsx("p",{className:"workbench-section-empty",children:bt?r("shell.batchDeleteSelectionSummary",{count:`${bt.sessions.length}`}):""}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:Dt,onClick:()=>gt(null),children:r("common.cancel")}),n.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:Dt,onClick:()=>{Ya()},children:Dt?r("shell.batchDeleting"):r("shell.batchDeleteAction")})]})]}),n.jsxs(et,{open:Xe!==null,title:r("shell.manageWorkspaceRemoveConfirmTitle"),description:r("shell.manageWorkspaceRemoveConfirmDescription"),onClose:()=>{C||m(null)},children:[n.jsx("p",{className:"workbench-section-empty",children:Xe?r("shell.manageWorkspaceRemoveConfirmTarget",{name:Xe.name}):""}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:!!C,onClick:()=>m(null),children:r("common.cancel")}),n.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:!!C,onClick:()=>{_a()},children:C?r("shell.manageWorkspaceRemoving"):r("shell.manageWorkspaceRemoveConfirmAction")})]})]}),n.jsx(_m,{open:q,onClose:()=>fe(!1),onCloned:rr}),n.jsx(Km,{open:S,onClose:()=>te(!1),onImported:Dr}),n.jsx(af,{open:Nt!==null,source:Nt,onClose:()=>Ye(null),onCreated:async d=>{d.members.forEach(v=>{L(v.session)}),_u(d.group.id),await M();const f=d.members.find(v=>v.session.sessionId===d.group.anchorSessionId)??d.members[0]??null;f&&ie(Ut(Du(f.session,f.sessionIsolatedWorkspace),f.session.sessionId)),Ye(null),ne({title:r("shell.parallelCreateSucceeded"),tone:"success"})}}),n.jsx(et,{open:_e!==null,title:r("shell.createSessionModalTitle"),className:"workbench-create-session-modal",description:_e?`${r("shell.createSessionTarget")} · ${_e.name}`:r("shell.createSessionModalDescription"),headerActions:n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button",className:"primary-button create-session-parallel-trigger",disabled:ft||!!se||!_e,onClick:()=>{_e&&Je(_e)},children:r("shell.parallelCreateAction")}),n.jsx("button",{type:"button",className:"primary-button create-session-worktree-trigger",disabled:ft||!!se,onClick:()=>it(!0),children:r("shell.createWorktreeAction")})]}),onClose:()=>Ze(null),children:n.jsxs("section",{className:"create-session-modal-section",children:[n.jsx("div",{className:"create-session-modal-section-header",children:n.jsx("strong",{children:r("shell.createSessionProviderLabel")})}),n.jsx(iu,{disabled:!!se||ft,workspaceId:(_e==null?void 0:_e.id)??null,pendingProvider:se===(_e==null?void 0:_e.id)?Be??null:null,onSelect:d=>{_e&&zr(_e.id,d)}})]})}),n.jsx(et,{open:_e!==null&&dt,title:r("shell.createWorktreeAction"),className:"workbench-create-worktree-modal",headerActions:n.jsx("button",{type:"button",className:ys?"workbench-modal-help-button active":"workbench-modal-help-button","aria-label":r("shell.createWorktreeHelpAction"),title:r("shell.createWorktreeHelpAction"),"aria-pressed":ys,onClick:()=>Yn(d=>!d),children:n.jsx($b,{})}),description:_e?`${r("shell.createWorktreeSectionDescription")} ${r("shell.createSessionTarget")} · ${_e.name}`:r("shell.createWorktreeSectionDescription"),onClose:un,children:n.jsxs("form",{className:"create-session-worktree-form",onSubmit:Va,children:[ys?n.jsxs("section",{className:"create-session-worktree-help-card","aria-label":r("shell.createWorktreeHelpTitle"),children:[n.jsx("strong",{children:r("shell.createWorktreeHelpTitle")}),n.jsxs("div",{className:"create-session-worktree-help-grid",children:[n.jsxs("article",{children:[n.jsx("h3",{children:r("shell.createWorktreeHelpBranchTitle")}),n.jsx("p",{children:r("shell.createWorktreeHelpBranchBody")})]}),n.jsxs("article",{children:[n.jsx("h3",{children:r("shell.createWorktreeHelpDisplayNameTitle")}),n.jsx("p",{children:r("shell.createWorktreeHelpDisplayNameBody")})]}),n.jsxs("article",{children:[n.jsx("h3",{children:r("shell.createWorktreeHelpBaseRefTitle")}),n.jsx("p",{children:r("shell.createWorktreeHelpBaseRefBody")})]})]})]}):null,n.jsxs("label",{className:"create-session-worktree-field",children:[n.jsx("span",{children:r("shell.createWorktreeBranchLabel")}),n.jsx("input",{className:"settings-text-input",value:sn,placeholder:r("shell.createWorktreeBranchPlaceholder"),onChange:d=>{const f=d.target.value;Lf(f)&&Wt(f)}})]}),n.jsxs("label",{className:"create-session-worktree-field",children:[n.jsx("span",{children:r("shell.createWorktreeDisplayNameLabel")}),n.jsx("input",{className:"settings-text-input",value:Me,placeholder:r("shell.createWorktreeDisplayNamePlaceholder"),onChange:d=>Ge(d.target.value)})]}),n.jsxs("label",{className:"create-session-worktree-field",children:[n.jsx("span",{children:r("shell.createWorktreeBaseRefLabel")}),n.jsx("div",{className:"create-session-worktree-combobox",ref:on,onBlurCapture:d=>{var v,W;const f=d.relatedTarget;f instanceof Node&&((v=on.current)!=null&&v.contains(f)||(W=Ot.current)!=null&&W.contains(f))||(St(!1),ut(-1))},children:n.jsxs("div",{className:"create-session-worktree-combobox-input-wrap",children:[n.jsx("input",{className:"settings-text-input create-session-worktree-combobox-input",role:"combobox","aria-autocomplete":"list","aria-expanded":yt,"aria-controls":Te,value:Se,placeholder:r("shell.createWorktreeBaseRefPlaceholder"),onFocus:()=>{St(!0),ut(Tt.length>0?0:-1)},onChange:d=>{nt(d.target.value),St(!0),ut(Tt.length>0?0:-1)},onKeyDown:d=>{if(d.key==="ArrowDown"){if(d.preventDefault(),!yt){St(!0);return}Tt.length>0&&ut(f=>f>=Tt.length-1?0:f+1);return}if(d.key==="ArrowUp"){if(d.preventDefault(),!yt){St(!0);return}Tt.length>0&&ut(f=>f<=0?Tt.length-1:f-1);return}if(d.key==="Enter"&&yt&&Qs>=0){d.preventDefault();const f=Tt[Qs];f&&(nt(f.value),St(!1),ut(-1));return}d.key==="Escape"&&St(!1)}}),n.jsx("button",{type:"button",className:"create-session-worktree-combobox-toggle","aria-label":r("shell.createWorktreeBaseRefToggle"),"aria-expanded":yt,onClick:()=>{St(d=>!d),ut(!yt&&Tt.length>0?0:-1)},children:n.jsx(kr,{expanded:yt})})]})}),n.jsx("span",{className:"create-session-worktree-field-hint",children:Ss?r("shell.createWorktreeBaseRefLoading"):Mn||r("shell.createWorktreeBaseRefHint",{localCount:Ae.localBranches.length,remoteCount:Ae.remoteBranches.length,tagCount:Ae.tags.length})})]}),yt&&rn&&typeof document<"u"?ws.createPortal(n.jsxs("div",{className:"create-session-worktree-combobox-floating-layer",children:[n.jsx("div",{className:"create-session-worktree-combobox-floating-backdrop",style:{"--create-worktree-combobox-top":`${rn.top}px`,"--create-worktree-combobox-left":`${rn.left}px`,"--create-worktree-combobox-width":`${rn.width}px`,"--create-worktree-combobox-height":`${er??0}px`}}),n.jsx("div",{ref:Ot,className:"create-session-worktree-combobox-popover floating",style:{"--create-worktree-combobox-top":`${rn.top}px`,"--create-worktree-combobox-left":`${rn.left}px`,"--create-worktree-combobox-width":`${rn.width}px`},children:Ss?n.jsx("p",{className:"create-session-worktree-combobox-empty",children:r("shell.createWorktreeBaseRefLoading")}):Mn?n.jsx("p",{className:"create-session-worktree-combobox-empty",children:Mn}):_n.length>0?n.jsx("div",{id:Te,className:"create-session-worktree-combobox-list",role:"listbox",children:_n.map(d=>n.jsxs("section",{className:"create-session-worktree-combobox-group","aria-label":d.label,children:[n.jsx("header",{className:"create-session-worktree-combobox-group-title",children:d.label}),n.jsx("div",{className:"create-session-worktree-combobox-group-options",children:d.items.map(f=>{const v=Tt.findIndex(ge=>ge.value===f.value),W=Se===f.value,F=Qs===v;return n.jsxs("button",{type:"button",role:"option",className:"create-session-worktree-combobox-option","aria-selected":W,"data-highlighted":F,onMouseDown:ge=>ge.preventDefault(),onMouseEnter:()=>ut(v),onClick:()=>{nt(f.value),St(!1),ut(-1)},children:[n.jsx("span",{className:"create-session-worktree-combobox-option-label",children:f.value}),n.jsxs("span",{className:"create-session-worktree-combobox-option-badges",children:[f.current?n.jsx("span",{className:"create-session-worktree-combobox-badge",children:r("shell.createWorktreeBaseRefCurrentBadge")}):null,f.recommended?n.jsx("span",{className:"create-session-worktree-combobox-badge recommended",children:r("shell.createWorktreeBaseRefRecommendedBadge")}):null]})]},`${d.key}:${f.value}`)})})]},d.key))}):n.jsx("p",{className:"create-session-worktree-combobox-empty",children:r("shell.createWorktreeBaseRefEmpty")})})]}),document.body):null,n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:ft,onClick:un,children:r("common.cancel")}),n.jsx("button",{type:"submit",className:"primary-button",disabled:ft,children:ft?r("shell.createWorktreeSubmitting"):r("shell.createWorktreeSubmit")})]})]})}),n.jsxs(et,{open:Ke!==null,title:r("shell.archiveModalTitle"),description:Ke?`${Ke.workspace.name} · ${r("shell.archiveModalDescription")}`:r("shell.archiveModalDescription"),headerActions:yn.length>0?n.jsx("button",{type:"button",className:"secondary-button","aria-pressed":On,onClick:Lr,children:r("shell.archiveSearchAction")}):void 0,onClose:()=>Tr(null),children:[On?n.jsxs("div",{className:"workbench-archive-search-panel",children:[n.jsx($s,{label:r("shell.archiveSearchLabel"),htmlFor:ht,children:n.jsx("input",{id:ht,type:"text",value:os,placeholder:r("shell.archiveSearchPlaceholder"),autoFocus:!0,onChange:d=>Wr(d.target.value)})}),Es?n.jsx("p",{className:"workbench-archive-search-status",children:r("shell.archiveSearchSummaryLoading")}):null,sr?n.jsx("p",{className:"workbench-archive-search-status status-text","data-tone":"warning",children:sr}):null]}):null,Ke&&Kt.length>0?n.jsx(Li,{className:"workbench-archive-list","data-workspace-tone":(Ee==null?void 0:Ee.tone)??"root",style:In(Ee),children:Kt.map(d=>{var W;const f=Ji(d.title,r("common.unknown")),v=((W=Ar[d.sessionId])==null?void 0:W.trim())??"";return n.jsx(Pt,{className:"workbench-archive-item","data-workspace-tone":(Ee==null?void 0:Ee.tone)??"root",style:In(Ee),trailing:n.jsx("button",{type:"button",className:"secondary-button",onClick:()=>Ja(d.sessionId),children:r("shell.unarchiveAction")}),children:n.jsxs("div",{className:"workbench-archive-item-main",children:[n.jsx("strong",{title:f.fullTitle,children:f.displayTitle}),n.jsxs("p",{children:[Qc(d,Ke.workspace,!1)," ·"," ",Da(d.provider)]}),On&&v?n.jsx("p",{className:"workbench-archive-item-summary",children:v}):null]})},d.sessionId)})}):n.jsx(Gl,{title:yn.length>0&&os.trim().length>0?r("shell.archiveSearchEmpty"):r("shell.archiveEmpty"),compact:!0,className:"workbench-section-empty"})]}),n.jsx(et,{open:_t!==null,title:r("shell.renameModalTitle"),description:r("shell.renameModalDescription"),onClose:()=>{xn||(Cs(null),as(""))},children:n.jsxs("form",{className:"workbench-rename-form",onSubmit:$t,children:[n.jsxs("label",{className:"workbench-modal-field",children:[n.jsx("span",{children:r("shell.renameInputLabel")}),n.jsx("input",{type:"text",value:vn,placeholder:r("shell.renameInputPlaceholder"),maxLength:120,autoFocus:!0,onChange:d=>as(d.target.value)})]}),n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:!!xn,onClick:()=>{Cs(null),as("")},children:r("common.cancel")}),n.jsx("button",{type:"submit",className:"primary-button",disabled:!vn.trim()||xn===(_t==null?void 0:_t.session.sessionId),children:xn===(_t==null?void 0:_t.session.sessionId)?r("shell.renamingSession"):r("common.save")})]})]})})]})}function _l({panelReady:e,activeTab:t,fileRevealRequest:s,onTabChange:a,onToggleCollapse:i,currentSessionId:c,activeWorkspaceId:u,navigationGroups:h,workspaceContext:k,worktreeMeta:b,worktreeMergeState:y,onRefreshWorktreeMergePreview:N,onApplyWorktreeMerge:A,onCleanupWorktree:M}){var ae;const L=u??((ae=h[0])==null?void 0:ae.workspace.id)??null,z=Vn(),I=yc(z),{showToast:w}=vs(),O=Kc(),E=o.useRef(null),K=o.useRef(null),T=z.isDesktop&&z.bridge.supported,H=T&&!!u,X=T&&!!L,D=T&&!!L,j=typeof globalThis<"u"&&"PointerEvent"in globalThis,J=o.useCallback(async(ee,_,x)=>{if(ee==="files"){const $=await Hh(z,{workspaceId:_,sessionId:x,focusOwner:"file-context-panel"});$.ok||w({title:$.detail??r("conversation.filePanelOpenExternalFailed"),tone:"error"});return}if(ee==="git"){const $=await Uh(z,{workspaceId:_,focusOwner:"git-sidebar"});$.ok||w({title:$.detail??r("git.openExternalFailed"),tone:"error"});return}const R=await Gh(z,{workspaceId:_,focusOwner:"terminal-manager-panel"});R.ok||w({title:R.detail??r("terminalManager.openExternalFailed"),tone:"error"})},[z,w]),Q=o.useCallback((ee,_)=>{if(ee.button!==0||!T)return;const x=_==="files"?u:_==="git"||_==="terminals"?L:null;if(!x)return;const R=_==="files"?c:null;E.current={tab:_,startX:ee.clientX,startY:ee.clientY,workspaceId:x,sessionId:R,detached:!1,preview:null};const $=de=>{var ne;const ie=E.current;if(!ie)return;const Ne=Math.abs(de.clientX-ie.startX),pe=Math.abs(de.clientY-ie.startY);!ie.detached&&Math.max(Ne,pe)<gl||(ie.detached||(ie.detached=!0,K.current=ie.tab,ie.preview=Co({title:ie.tab==="files"?r("shell.filesEntry"):ie.tab==="git"?r("shell.gitEntry"):r("shell.terminalManagerEntry"),x:de.clientX,y:de.clientY})),(ne=ie.preview)==null||ne.updatePosition(de.clientX,de.clientY))},Y=de=>{var Ne;const ie=(Ne=E.current)==null?void 0:Ne.preview;de&&(ie==null||ie.cancel()),window.removeEventListener("mousemove",$),window.removeEventListener("mouseup",Ce),window.removeEventListener("blur",ye),E.current=null},Ce=async()=>{var ie;const de=E.current;Y(!1),de!=null&&de.detached&&(await((ie=de.preview)==null?void 0:ie.complete()),await J(de.tab,de.workspaceId,de.sessionId))},ye=()=>{Y(!0)};window.addEventListener("mousemove",$),window.addEventListener("mouseup",Ce),window.addEventListener("blur",ye)},[u,T,c,L,J]),B=o.useCallback((ee,_)=>{if(ee.button!==0||!T)return;const x=_==="files"?u:_==="git"||_==="terminals"?L:null;if(!x)return;const R=ee.currentTarget,$=ee.pointerId;R.setPointerCapture($);const Y=_==="files"?c:null;E.current={tab:_,startX:ee.clientX,startY:ee.clientY,workspaceId:x,sessionId:Y,detached:!1,preview:null};const Ce=pe=>{var Ve;if(pe.pointerId!==$)return;const ne=E.current;if(!ne)return;const me=Math.abs(pe.clientX-ne.startX),We=Math.abs(pe.clientY-ne.startY);!ne.detached&&Math.max(me,We)<gl||(ne.detached||(ne.detached=!0,K.current=ne.tab,ne.preview=Co({title:ne.tab==="files"?r("shell.filesEntry"):ne.tab==="git"?r("shell.gitEntry"):r("shell.terminalManagerEntry"),x:pe.clientX,y:pe.clientY})),(Ve=ne.preview)==null||Ve.updatePosition(pe.clientX,pe.clientY))},ye=pe=>{var me;const ne=(me=E.current)==null?void 0:me.preview;pe&&(ne==null||ne.cancel()),R.removeEventListener("pointermove",Ce),R.removeEventListener("pointerup",de),R.removeEventListener("pointercancel",ie),R.removeEventListener("lostpointercapture",ie),window.removeEventListener("blur",Ne),E.current=null,R.hasPointerCapture($)&&R.releasePointerCapture($)},de=async pe=>{var me;if(pe.pointerId!==$)return;const ne=E.current;ye(!1),ne!=null&&ne.detached&&(await((me=ne.preview)==null?void 0:me.complete()),await J(ne.tab,ne.workspaceId,ne.sessionId))},ie=pe=>{pe.pointerId===$&&ye(!0)},Ne=()=>{ye(!0)};R.addEventListener("pointermove",Ce),R.addEventListener("pointerup",de),R.addEventListener("pointercancel",ie),R.addEventListener("lostpointercapture",ie),window.addEventListener("blur",Ne)},[u,T,c,L,J]),le=o.useCallback(ee=>{if(K.current===ee){K.current=null;return}a(ee)},[a]);return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"workbench-auxiliary-header","data-workspace-tone":(k==null?void 0:k.tone)??"root",style:In(k),"data-window-drag-handle":"workbench-auxiliary-header","data-tauri-drag-region":I,children:[i?n.jsx("button",{type:"button",className:"workbench-nav-toolbar-button","aria-label":r("shell.hideInfoSidebar"),title:r("shell.hideInfoSidebar"),onClick:i,children:n.jsx(wd,{})}):null,n.jsxs("div",{className:"workbench-info-tabs",role:"tablist","aria-label":r("shell.infoTabsLabel"),"data-tauri-drag-region":I,children:[n.jsx("button",{className:t==="files"?"workbench-info-tab active":"workbench-info-tab",type:"button",role:"tab","aria-selected":t==="files",title:H?"拖拽标签到独立窗口":void 0,onPointerDown:ee=>B(ee,"files"),onMouseDown:j?void 0:ee=>Q(ee,"files"),onClick:()=>le("files"),children:r("shell.filesEntry")}),n.jsx("button",{className:t==="git"?"workbench-info-tab active":"workbench-info-tab",type:"button",role:"tab","aria-selected":t==="git",title:X?"拖拽标签到独立窗口":void 0,onPointerDown:ee=>B(ee,"git"),onMouseDown:j?void 0:ee=>Q(ee,"git"),onClick:()=>le("git"),children:r("shell.gitEntry")}),n.jsx("button",{className:t==="terminals"?"workbench-info-tab active":"workbench-info-tab",type:"button",role:"tab","aria-selected":t==="terminals",title:D?"拖拽标签到独立窗口":void 0,onPointerDown:ee=>B(ee,"terminals"),onMouseDown:j?void 0:ee=>Q(ee,"terminals"),onClick:()=>le("terminals"),children:r("shell.terminalManagerEntry")})]})]}),n.jsxs("div",{ref:O,className:"workbench-auxiliary-body","data-scrollbar-autohide":"true",children:[e?null:n.jsx(ka,{}),e&&t==="git"&&b?n.jsx(Ub,{meta:b,state:y,onRefresh:()=>N(b.workspaceId,!0),onApply:()=>A(b.workspaceId),onCleanup:()=>M(b)}):null,e&&t==="files"?u?n.jsx(o.Suspense,{fallback:n.jsx(ka,{}),children:n.jsx(zf,{sessionId:c,workspaceId:u,externalRevealRequest:s})}):n.jsx("section",{className:"workbench-empty-state minimal",children:n.jsx("p",{children:r("shell.filesPanelEmpty")})}):null,e&&t==="git"?L?n.jsx(o.Suspense,{fallback:n.jsx(ka,{}),children:n.jsx(Kf,{workspaceId:L})}):n.jsx("section",{className:"workbench-empty-state minimal",children:n.jsx("p",{children:r("shell.gitPanelEmpty")})}):null,e&&t==="terminals"?n.jsx(o.Suspense,{fallback:n.jsx(ka,{}),children:n.jsx(qf,{currentWorkspaceId:u,navigationGroups:h})}):null]})]})}function Ub({meta:e,state:t,onRefresh:s,onApply:a,onCleanup:i}){const[c,u]=o.useState(!1),h=(t==null?void 0:t.preview)??null,k=(t==null?void 0:t.loading)??!1,b=(t==null?void 0:t.applying)??!1,y=(t==null?void 0:t.cleaning)??!1,N=h!==null,A=(h==null?void 0:h.alreadyMerged)===!0,M=new Set((h==null?void 0:h.blockers.map(B=>B.code))??[]),L=M.size>0||!!(t!=null&&t.error),z=A&&!L,I=(h==null?void 0:h.canMerge)===!0&&!k&&!b&&!y&&!z,w=z&&!k&&!b&&!y&&!M.has("SOURCE_DIRTY")&&!M.has("HAS_ACTIVE_CHILDREN"),O=k||b||y?"loading":L?"blocked":z?"merged":h!=null&&h.canMerge?"ready":N?"blocked":"idle",E=(h==null?void 0:h.targetWorkspace.name)??r("common.unknown"),K=(h==null?void 0:h.sourceBranchName)??e.branchName,T=(h==null?void 0:h.targetBranchName)??e.baseRef??r("common.unknown"),H=zb({t:r,hasPreview:N,showMergedState:z,isMerged:A,canMerge:(h==null?void 0:h.canMerge)===!0,ahead:(h==null?void 0:h.ahead)??0,blockerCodeSet:M}),X=k?r("shell.worktreeMergePreviewLoading"):b?r("shell.worktreeMergeApplying"):y?r("shell.worktreeCleanupRunning"):z?r("shell.worktreeMergeAlreadyMerged"):h!=null&&h.canMerge?r("shell.worktreeMergeReady"):N?r("shell.worktreeMergeBlocked"):r("shell.worktreeMergePreviewIdle"),D=[r("shell.worktreeMergeCurrentBranch",{branch:K}),r("shell.worktreeMergeParentBranch",{branch:T}),r("shell.worktreeMergeTargetWorkspace",{name:E}),h?r("shell.worktreeMergeAheadBehind",{ahead:h.ahead,behind:h.behind}):r("shell.worktreeMergeAheadBehindPending"),h!=null&&h.mergeBaseCommit?r("shell.worktreeMergeBaseCommit",{commit:kb(h.mergeBaseCommit)}):null].filter(B=>!!B),j=`worktree-merge-panel-details-${e.workspaceId}`,J=c?r("shell.worktreeMergeCollapseDetails"):r("shell.worktreeMergeExpandDetails"),Q=Gb({t:r,loading:k,applying:b,cleaning:y,hasPreview:N,canMerge:(h==null?void 0:h.canMerge)===!0,showMergedState:z,blockerCodeSet:M});return o.useEffect(()=>{u(!1)},[e.workspaceId]),n.jsxs("section",{className:"worktree-merge-panel","data-state":O,children:[n.jsxs("button",{type:"button",className:"worktree-merge-panel-summary","aria-label":J,"aria-expanded":c,"aria-controls":j,onClick:()=>{u(B=>!B)},children:[n.jsx("span",{className:"worktree-merge-panel-summary-label",children:r("shell.worktreeMergePanelLabel")}),n.jsx("span",{className:"worktree-merge-panel-summary-main",children:n.jsx("span",{className:"worktree-merge-panel-summary-tags",children:Q.map(B=>n.jsx("span",{className:"worktree-merge-panel-summary-tag","data-state":O,children:B},B))})}),n.jsx("span",{className:"worktree-merge-panel-summary-toggle",children:J})]}),c?n.jsxs("div",{id:j,className:"worktree-merge-panel-details",children:[n.jsx("div",{className:"worktree-merge-panel-detail-head",children:n.jsx("span",{className:"worktree-merge-panel-status","data-state":O,children:X})}),n.jsx("div",{className:"worktree-merge-panel-meta",children:D.map(B=>n.jsx("span",{children:B},B))}),N?n.jsx("div",{className:"worktree-merge-panel-checklist","aria-label":r("shell.worktreeMergeChecklistTitle"),children:H.map(B=>n.jsxs("div",{className:"worktree-merge-panel-checklist-item","data-state":B.state,children:[n.jsx("span",{className:"worktree-merge-panel-checklist-marker","aria-hidden":"true",children:B.state==="done"?"✓":B.state==="blocked"?"!":"·"}),n.jsxs("span",{className:"worktree-merge-panel-checklist-copy",children:[n.jsx("strong",{children:B.label}),B.detail?n.jsx("span",{children:B.detail}):null]})]},B.key))}):null,t!=null&&t.error?n.jsx("p",{className:"worktree-merge-panel-error status-text","data-tone":"error",children:t.error}):null,h!=null&&h.conflictPaths.length?n.jsxs("div",{className:"worktree-merge-panel-conflicts",children:[n.jsx("span",{className:"worktree-merge-panel-conflicts-label",children:r("shell.worktreeMergeConflictLabel")}),n.jsx("div",{className:"worktree-merge-panel-conflict-list",children:h.conflictPaths.map(B=>n.jsx("code",{children:B},B))})]}):null,n.jsxs("div",{className:"worktree-merge-panel-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:k||b||y,onClick:s,children:N?r("shell.worktreeMergePreviewRefresh"):r("shell.worktreeMergePreviewAction")}),n.jsx("button",{type:"button",className:"primary-button",disabled:!I,onClick:a,children:b?r("shell.worktreeMergeApplying"):r("shell.worktreeMergeApplyAction")}),n.jsx("button",{type:"button",className:"secondary-button worktree-merge-panel-cleanup-button",disabled:!w,onClick:i,children:y?r("shell.worktreeCleanupRunning"):r("shell.worktreeCleanupAction")})]})]}):null]})}function Gb(e){const{t,loading:s,applying:a,cleaning:i,hasPreview:c,canMerge:u,showMergedState:h,blockerCodeSet:k}=e;if(s)return[t("shell.worktreeMergeCompactChecking")];if(a)return[t("shell.worktreeMergeCompactMerging")];if(i)return[t("shell.worktreeMergeCompactCleaning")];const b=[];return k.has("SOURCE_NOT_ACTIVE")&&b.push(t("shell.worktreeMergeCompactInactive")),k.has("SOURCE_DIRTY")&&b.push(t("shell.worktreeMergeCompactDirty")),k.has("TARGET_DIRTY")&&b.push(t("shell.worktreeMergeCompactTargetDirty")),k.has("HAS_CONFLICTS")&&b.push(t("shell.worktreeMergeCompactConflict")),k.has("HAS_ACTIVE_CHILDREN")&&b.push(t("shell.worktreeMergeCompactChildren")),b.length>0?b:u?[t("shell.worktreeMergeCompactReady")]:h?[t("shell.worktreeMergeCompactMerged")]:c?k.has("NO_COMMITS_TO_MERGE")?[t("shell.worktreeMergeCompactNoCommits")]:[t("shell.worktreeMergeCompactBlocked")]:[t("shell.worktreeMergeCompactPending")]}function zb(e){const{t,hasPreview:s,showMergedState:a,isMerged:i,canMerge:c,ahead:u,blockerCodeSet:h}=e,k=h.has("SOURCE_NOT_ACTIVE"),b=h.has("SOURCE_DIRTY"),y=h.has("TARGET_DIRTY"),N=h.has("HAS_ACTIVE_CHILDREN"),A=h.has("HAS_CONFLICTS"),M=s&&!i&&(h.has("NO_COMMITS_TO_MERGE")||u<=0),L=a?{key:"merge-result",label:t("shell.worktreeMergeChecklistResultMerged"),detail:t("shell.worktreeMergeMergedHint"),state:"done"}:c?{key:"merge-result",label:t("shell.worktreeMergeChecklistResultReady"),detail:t("shell.worktreeMergeChecklistResultReadyDetail"),state:"done"}:s?{key:"merge-result",label:t("shell.worktreeMergeChecklistResultBlocked"),detail:t("shell.worktreeMergeChecklistResultBlockedDetail"),state:"blocked"}:{key:"merge-result",label:t("shell.worktreeMergeChecklistResultPending"),detail:null,state:"pending"};return[{key:"source-state",label:t("shell.worktreeMergeChecklistSourceState"),detail:s&&k?t("shell.worktreeMergeChecklistSourceStateBlocked"):null,state:s?k?"blocked":"done":"pending"},{key:"clean-source",label:t("shell.worktreeMergeChecklistSourceClean"),detail:s&&b?t("shell.worktreeMergeChecklistSourceCleanBlocked"):null,state:s?b?"blocked":"done":"pending"},{key:"clean-target",label:t("shell.worktreeMergeChecklistTargetClean"),detail:s&&y?t("shell.worktreeMergeChecklistTargetCleanBlocked"):null,state:s?y?"blocked":"done":"pending"},{key:"children",label:t("shell.worktreeMergeChecklistChildren"),detail:s&&N?t("shell.worktreeMergeChecklistChildrenBlocked"):null,state:s?N?"blocked":"done":"pending"},{key:"commits",label:t("shell.worktreeMergeChecklistCommits"),detail:M?t(i?"shell.worktreeMergeMergedDirtyHint":"shell.worktreeMergeChecklistCommitsBlocked"):null,state:M?i?"done":"blocked":s?"done":"pending"},{key:"conflicts",label:t("shell.worktreeMergeChecklistConflicts"),detail:A?t("shell.worktreeMergeChecklistConflictsBlocked"):null,state:A?"blocked":s?"done":"pending"},L]}function dk({shellMode:e="desktop"}){var F,ge,Z,Re,Qe,qe,pt,Jt,pn,ve,Cn,Zt,He,Vr,ms,Xr,Yr,Jr;const t=Pa(),s=Sr(),a=Vn(),{showToast:i}=vs(),c=Qr(l=>l.sessionDisplaySortMode),u=Qr(l=>l.notificationPreferences.notifyOnPermissionRequest),h=Qr(l=>l.notificationPreferences.notifyOnSessionCompleted),k=Qr(l=>l.notificationPreferences.notifyOnSessionFailed),b=o.useRef(cm(Bc)),y=o.useRef(0),N=o.useRef((((ge=(F=b.current)==null?void 0:F.items)==null?void 0:ge.length)??0)>0),A=o.useRef(new Map),M=o.useRef(!1),L=o.useRef(null),z=o.useRef(0),I=o.useRef(null),w=o.useRef(null),O=o.useRef(new Set),E=o.useRef(new Set),K=o.useRef(new Set),T=o.useRef(new Set),H=o.useRef(null),X=o.useRef(null),D=o.useRef(null),j=o.useRef(null),J=o.useRef(null),Q=o.useRef(null),B=o.useRef(null),le=o.useRef(null),ae=o.useRef(0),ee=o.useRef(0),_=o.useRef(i),x=o.useRef(a.bridge),R=o.useRef(null),$=o.useRef(0),Y=o.useRef(0),Ce=o.useRef(null),ye=o.useRef(null),de=o.useRef(null),ie=o.useRef(!1),Ne=o.useRef(!1),pe=o.useRef(!1),ne=o.useRef(new Map),me=o.useRef(!1),We=o.useRef(new Map),Ve=o.useRef(""),ct=o.useRef([]),S=o.useRef(c),te=o.useRef(null),[q,fe]=o.useState(()=>$o(b.current,c)),we=o.useRef(q),[ue,st]=o.useState(()=>{var l,p;return(((p=(l=b.current)==null?void 0:l.items)==null?void 0:p.length)??0)===0}),[De,Xe]=o.useState(null),[m,C]=o.useState(()=>ba(jl(il,ff),ul,pl)),[G,se]=o.useState(()=>ba(jl(ol,bf),hl,ml)),[he,Be]=o.useState(()=>Cl(ll,!1)),[Ie,tt]=o.useState(()=>Cl(cl,!1)),[Ze,Nt]=o.useState(null),[Ye,nn]=o.useState(null),[It,dt]=o.useState(()=>Ml(b.current)),[it,ft]=o.useState(()=>Nl(mi)),[rt,sn]=o.useState(!1),[Wt,Me]=o.useState("files"),[Ge,Se]=o.useState(!1),[nt,Ae]=o.useState(!1),[Xn,yt]=o.useState(null),[St,Qs]=o.useState({}),[ut,ys]=o.useState(!1),[Yn,Ss]=o.useState("sessions"),[wn,Mn]=o.useState(""),[Rn,rn]=o.useState(""),[Ir,er]=o.useState(!1),[tr,En]=o.useState(null),[Tr,Lt]=o.useState([]),[Pn,Jn]=o.useState(null),[Zn,bt]=o.useState({}),gt=xc(a),Dt=o.useCallback(l=>{if(gt)return;const p=R.current;p&&(!Si(a,l.button,l.target)||!Il(l.clientY,p)||Ph({platform:a,button:l.button,target:l.target,clientX:l.clientX,clientY:l.clientY}))},[a,gt]),Mr=o.useCallback(l=>{if(gt)return;const p=R.current;p&&(!Si(a,l.button,l.target)||!Il(l.clientY,p)||a.bridge.setWindowState("toggle-zoom"))},[a,gt]),[at,Bt]=o.useState({}),[Fe,Qn]=o.useState(null),[es,An]=o.useState(!1),[ts,js]=o.useState([]),[ns,ss]=o.useState(()=>new Set),[Wn,an]=o.useState(!1),[Ln,rs]=o.useState(!1),[_t,Cs]=o.useState(0),[vn,as]=o.useState(()=>Nl(dl)),xn=e==="desktop"&&a.isDesktop&&a.ui.osFamily==="macos"&&a.ui.prefersOverlayTitlebar,{theme:Ns}=Dd();o.useEffect(()=>{_.current=i},[i]),o.useEffect(()=>{if(typeof document>"u")return;const{documentElement:l,body:p}=document,g=document.getElementById("root");if(!xn){l.removeAttribute("data-workbench-macos-vibrancy"),p==null||p.removeAttribute("data-workbench-macos-vibrancy");return}const P=l.style.background,U=(p==null?void 0:p.style.background)??"",V=(g==null?void 0:g.style.background)??"";return l.setAttribute("data-workbench-macos-vibrancy","true"),p==null||p.setAttribute("data-workbench-macos-vibrancy","true"),l.style.background="transparent",p==null||p.style.setProperty("background","transparent"),g==null||g.style.setProperty("background","transparent"),()=>{l.removeAttribute("data-workbench-macos-vibrancy"),p==null||p.removeAttribute("data-workbench-macos-vibrancy"),l.style.background=P,p&&(p.style.background=U),g instanceof HTMLElement&&(g.style.background=V)}},[xn]),o.useEffect(()=>()=>{de.current!==null&&window.clearTimeout(de.current)},[]),o.useEffect(()=>{var U;if(typeof document>"u")return;const{documentElement:l,body:p}=document;if(!Ye){l.removeAttribute(Fs),p==null||p.removeAttribute(Fs);return}const g=l.style.cursor,P=(p==null?void 0:p.style.cursor)??"";return l.setAttribute(Fs,Ye),p==null||p.setAttribute(Fs,Ye),l.style.cursor="col-resize",p==null||p.style.setProperty("cursor","col-resize"),(U=window.getSelection())==null||U.removeAllRanges(),()=>{l.removeAttribute(Fs),p==null||p.removeAttribute(Fs),l.style.cursor=g,p&&(p.style.cursor=P)}},[Ye]),o.useEffect(()=>{S.current=c,fe(l=>wb(l,c))},[c]),o.useEffect(()=>{we.current=q},[q]),o.useEffect(()=>{x.current=a.bridge},[a.bridge]),o.useEffect(()=>{$.current=m},[m]),o.useEffect(()=>{Y.current=G},[G]),o.useEffect(()=>()=>{Ce.current!==null&&window.cancelAnimationFrame(Ce.current)},[]);const kt=o.useCallback(async()=>{const l=ae.current+1;ae.current=l;try{const p=await bm();if(l!==ae.current)return;if(!p.initialized){js([]),ss(new Set);return}const[g,P,U,V]=await Promise.all([gm(),vm(),Fc(),ym()]);if(l!==ae.current)return;js(Pf(g.overview,P.items,U.items)),ss(new Set(V.items.map(ce=>ce.notificationId)))}catch{if(l!==ae.current)return;js([]),ss(new Set)}},[]),is=o.useCallback(l=>{const p=l.map(g=>g.createdAt).sort((g,P)=>qn(P)-qn(g))[0]??null;p&&as(g=>g&&qn(g)>=qn(p)?g:p)},[]);o.useEffect(()=>{vn&&bs(dl,vn)},[vn]),o.useEffect(()=>{kt();const l=window.setInterval(()=>{kt()},kf);return()=>{window.clearInterval(l)}},[kt]),o.useEffect(()=>{mt("workbench.layout_mounted",{path:t.pathname,search:t.search})},[t.pathname,t.search]),o.useEffect(()=>{var l,p;mt("workbench.cached_snapshot_loaded",{cached:!!b.current,workspaceCount:((l=b.current)==null?void 0:l.items.length)??0,sessionCount:((p=b.current)==null?void 0:p.items.reduce((g,P)=>g+P.sessions.length,0))??0})},[]);function jt(l){var P;if(!l||!Array.isArray(l.items))return;mb(A.current,l);const p=pb(l,A.current);mt("workbench.apply_snapshot",{workspaceCount:p.items.length,sessionCount:p.items.reduce((U,V)=>U+V.sessions.length,0),currentSessionId:((P=vr(t.pathname))==null?void 0:P.sessionId)??null});const g=$o(p,S.current);b.current=p,la(p),we.current=g,fe(g),dt(Ml(p)),Xe(null)}const ze=o.useCallback(async()=>{const l=y.current+1;y.current=l,st(p=>p||!N.current),mt("workbench.refresh_navigation.start",{requestId:l,hasNavigationData:N.current});try{const p=await Zd();if(l!==y.current){mt("workbench.refresh_navigation.stale",{requestId:l});return}jt(p)}catch(p){if(l!==y.current)return;Xe(p instanceof Error?p.message:r("shell.navigationLoadFailed")),_.current({title:p instanceof Error?p.message:r("shell.navigationLoadFailed"),tone:"error"})}finally{mt("workbench.refresh_navigation.end",{requestId:l,success:l===y.current}),l===y.current&&st(!1)}},[]),wt=o.useCallback(l=>{fe(p=>{const g=fb(p,l,S.current);return we.current=g,g})},[]),Et=o.useCallback(()=>{var l;(l=w.current)==null||l.requestRefresh()},[]),Dn=o.useCallback((l,p)=>{s(Ut(l,p))},[s]),Is=o.useCallback((l,p,g)=>{var P;H.current={workspaceId:l,paths:p,knownRevisionByPath:g==null?void 0:g.knownRevisionByPath},(P=w.current)==null||P.subscribeFileTree(l,p,g)},[]),Ts=o.useCallback((l,p,g)=>{var P;X.current={workspaceId:l,paths:p,knownRevisionByPath:g==null?void 0:g.knownRevisionByPath},(P=w.current)==null||P.requestFileTreeRefresh(l,p,g)},[]),Ms=o.useCallback(l=>(O.current.add(l),()=>{O.current.delete(l)}),[]),on=o.useCallback((l,p)=>{var g;D.current={workspaceId:l,knownRevision:p==null?void 0:p.knownRevision},(g=w.current)==null||g.subscribeGit(l,p)},[]),Ot=o.useCallback((l,p)=>{var g;j.current={workspaceId:l,knownRevision:p==null?void 0:p.knownRevision},(g=w.current)==null||g.requestGitRefresh(l,p)},[]),ln=o.useCallback(l=>(E.current.add(l),()=>{E.current.delete(l)}),[]),Bn=o.useCallback((l,p)=>{var g;J.current={workspaceId:l,knownRevision:p==null?void 0:p.knownRevision},(g=w.current)==null||g.subscribeWorkspaceManagement(l,p)},[]),cn=o.useCallback((l,p)=>{var g;Q.current={workspaceId:l,knownRevision:p==null?void 0:p.knownRevision},bt(P=>{var U;return{...P,[l]:{detail:((U=P[l])==null?void 0:U.detail)??null,loading:!0,error:null}}}),(g=w.current)==null||g.requestWorkspaceManagementRefresh(l,p)},[]),Rs=o.useCallback(l=>(K.current.add(l),()=>{K.current.delete(l)}),[]),dn=o.useCallback(async(l,p=!1)=>{const g=l.trim();if(!g)return;let P=!0;if(Bt(U=>{const V=U[g];return!p&&(V!=null&&V.loading)?(P=!1,U):{...U,[g]:{preview:(V==null?void 0:V.preview)??null,loading:!0,applying:(V==null?void 0:V.applying)??!1,cleaning:(V==null?void 0:V.cleaning)??!1,error:null}}}),!!P)try{const U=await Qd(g);Bt(V=>{var ce,je;return{...V,[g]:{preview:U,loading:!1,applying:((ce=V[g])==null?void 0:ce.applying)??!1,cleaning:((je=V[g])==null?void 0:je.cleaning)??!1,error:null}}})}catch(U){Bt(V=>{var ce,je,xe;return{...V,[g]:{preview:((ce=V[g])==null?void 0:ce.preview)??null,loading:!1,applying:((je=V[g])==null?void 0:je.applying)??!1,cleaning:((xe=V[g])==null?void 0:xe.cleaning)??!1,error:U instanceof Error?U.message:r("shell.worktreeMergePreviewFailed")}}})}},[]),Rr=o.useCallback(async l=>{const p=l.trim();if(p){Bt(g=>{var P,U;return{...g,[p]:{preview:((P=g[p])==null?void 0:P.preview)??null,loading:!1,applying:!0,cleaning:((U=g[p])==null?void 0:U.cleaning)??!1,error:null}}});try{const g=await eu(p);Bt(P=>{var U;return{...P,[p]:{preview:g.preview,loading:!1,applying:!1,cleaning:((U=P[p])==null?void 0:U.cleaning)??!1,error:null}}}),Et(),ze(),dn(p,!0),Ot(g.preview.targetWorkspace.id),_.current({title:g.applied?r("shell.worktreeMergeApplySuccess"):r("shell.worktreeMergeAlreadyMerged"),tone:"success"})}catch(g){Bt(P=>{var U,V;return{...P,[p]:{preview:((U=P[p])==null?void 0:U.preview)??null,loading:!1,applying:!1,cleaning:((V=P[p])==null?void 0:V.cleaning)??!1,error:g instanceof Error?g.message:r("shell.worktreeMergeApplyFailed")}}}),_.current({title:g instanceof Error?g.message:r("shell.worktreeMergeApplyFailed"),tone:"error"})}}},[dn,ze,Ot,Et]),Er=o.useCallback(async l=>{var P,U;const p=l.workspaceId,g=es&&((U=(P=at[p])==null?void 0:P.preview)==null?void 0:U.alreadyMerged)===!0;Bt(V=>{var ce;return{...V,[p]:{preview:((ce=V[p])==null?void 0:ce.preview)??null,loading:!1,applying:!1,cleaning:!0,error:null}}});try{const V=await tu(p,{deleteBranch:g});if(Bt(ce=>{var je;return{...ce,[p]:{preview:((je=ce[p])==null?void 0:je.preview)??null,loading:!1,applying:!1,cleaning:!1,error:null}}}),An(!1),Qn(ce=>(ce==null?void 0:ce.workspaceId)===p?null:ce),Et(),await ze(),s(kn(l.parentWorkspaceId),{replace:!0}),V.branchDeleted){_.current({title:r("shell.worktreeCleanupDeleteBranchSuccess",{branch:V.deletedBranchName||l.branchName}),tone:"success"});return}if(V.branchDeleteRequested){_.current({title:r("shell.worktreeCleanupDeleteBranchPartialFailed",{branch:l.branchName}),description:V.branchDeleteError||void 0,tone:"warning"});return}_.current({title:r("shell.worktreeCleanupSuccess"),tone:"success"})}catch(V){Bt(ce=>{var je;return{...ce,[p]:{preview:((je=ce[p])==null?void 0:je.preview)??null,loading:!1,applying:!1,cleaning:!1,error:V instanceof Error?V.message:r("shell.worktreeCleanupFailed")}}}),_.current({title:V instanceof Error?V.message:r("shell.worktreeCleanupFailed"),tone:"error"})}},[es,s,ze,Et,at]),Pr=o.useCallback(l=>{An(!1),Qn(l)},[]),Gt=o.useCallback((l,p)=>{var g;B.current={workspaceId:l,knownRevision:p==null?void 0:p.knownRevision},(g=w.current)==null||g.subscribeTerminalManager(l,p)},[]),ot=o.useCallback((l,p)=>{var g;le.current={workspaceId:l,knownRevision:p==null?void 0:p.knownRevision},(g=w.current)==null||g.requestTerminalManagerRefresh(l,p)},[]),nr=o.useCallback(l=>(T.current.add(l),()=>{T.current.delete(l)}),[]),_e=o.useCallback((l,p)=>{fe(g=>bb(g,l,p??new Date().toISOString()))},[]),zt=o.useCallback(async(l,p)=>{A.current.set(l,p),fe(g=>Pl(g,l,p));try{const g=await ql(l,p),P=gn(g);P===p?A.current.set(l,P):A.current.delete(l),wt(g),Et(),ze()}catch(g){throw A.current.delete(l),fe(P=>Pl(P,l,!p)),g}},[ze,Et,wt]),_n=o.useCallback((l,p)=>{mt("workbench.set_session_workspace",{sessionId:l,workspaceId:p}),Qs(g=>{if(!p){if(!(l in g))return g;const P={...g};return delete P[l],P}return g[l]===p?g:{...g,[l]:p}})},[]);o.useEffect(()=>{N.current=q.length>0},[q]),o.useEffect(()=>{mt("workbench.navigation_state",{navigationLoading:ue,workspaceCount:q.length,sessionCount:q.reduce((l,p)=>l+p.sessions.length,0)})},[q,ue]),o.useEffect(()=>{I.current!==null&&window.clearTimeout(I.current),I.current=window.setTimeout(()=>{var re;I.current=null,!(M.current||N.current)&&(mt("workbench.refresh_navigation.ws_fallback_triggered"),(re=w.current)==null||re.requestRefresh())},1200);const l=new Nh({onConnectionChange:re=>{re==="connected"&&nu(),re==="reconnect_failed"&&!N.current&&(Xe(r("shell.navigationLoadFailed")),_.current({id:"workbench-navigation-connection",title:r("shell.navigationLoadFailed"),tone:"warning",durationMs:3600}))},onSnapshot:re=>{M.current=!0,mt("workbench.ws_snapshot_received",{workspaceCount:re.items.length,sessionCount:re.items.reduce((Le,Qt)=>Le+Qt.sessions.length,0)}),I.current!==null&&(window.clearTimeout(I.current),I.current=null),jt(re),st(!1)},onFileTreeSnapshot:re=>{O.current.forEach(Le=>Le(re))},onGitSnapshot:re=>{wr(pd(re.workspaceId),{revision:re.revision??null,status:re.status,history:re.history,historyTotalCount:re.historyTotalCount,historyNextCursor:re.historyNextCursor,branches:re.branches}),bt(Le=>{var Nn;const Qt=((Nn=q.find(yd=>yd.workspace.id===re.workspaceId))==null?void 0:Nn.workspace)??null;if(!Qt)return Le;const mn=Le[re.workspaceId],lt=bd(fd((mn==null?void 0:mn.detail)??md(Qt),Qt),re);return wr(Mi(re.workspaceId),lt),{...Le,[re.workspaceId]:{detail:lt,loading:!1,error:null}}}),E.current.forEach(Le=>Le(re))},onWorkspaceManagementSnapshot:re=>{wr(Mi(re.workspaceId),re),bt(Le=>({...Le,[re.workspaceId]:{detail:re,loading:!1,error:null}})),K.current.forEach(Le=>Le(re))},onTerminalManagerSnapshot:re=>{T.current.forEach(Le=>Le(re))},onUnauthorized:()=>{xr.clear(),s("/login",{replace:!0})}});l.primeWorkbenchSnapshot(b.current),w.current=l;const p=H.current,g=X.current,P=D.current,U=j.current,V=J.current,ce=Q.current,je=B.current,xe=le.current;return p&&l.subscribeFileTree(p.workspaceId,p.paths,{knownRevisionByPath:p.knownRevisionByPath}),P&&l.subscribeGit(P.workspaceId,{knownRevision:P.knownRevision}),V&&l.subscribeWorkspaceManagement(V.workspaceId,{knownRevision:V.knownRevision}),je&&l.subscribeTerminalManager(je.workspaceId,{knownRevision:je.knownRevision}),g&&l.requestFileTreeRefresh(g.workspaceId,g.paths,{knownRevisionByPath:g.knownRevisionByPath}),U&&l.requestGitRefresh(U.workspaceId,{knownRevision:U.knownRevision}),ce&&l.requestWorkspaceManagementRefresh(ce.workspaceId,{knownRevision:ce.knownRevision}),xe&&l.requestTerminalManagerRefresh(xe.workspaceId,{knownRevision:xe.knownRevision}),l.start(),()=>{I.current!==null&&(window.clearTimeout(I.current),I.current=null),w.current===l&&(w.current=null),l.close()}},[s]),o.useEffect(()=>{bs(il,String(m))},[m]),o.useEffect(()=>{bs(ol,String(G))},[G]),o.useEffect(()=>{bs(ll,String(he))},[he]),o.useEffect(()=>{bs(cl,String(Ie))},[Ie]),o.useEffect(()=>{if(!it){rb(mi);return}bs(mi,it)},[it]),o.useEffect(()=>{if(rt||Ie)return;const l=window.setTimeout(()=>{sn(!0)},gf);return()=>{window.clearTimeout(l)}},[rt,Ie]);const Tt=vr(t.pathname),Te=(Tt==null?void 0:Tt.sessionId)??null,Ke=Te?xd(Te):!1,Ee=o.useMemo(()=>Hu(q),[q]),yn=o.useMemo(()=>lb(q),[q]),On=o.useMemo(()=>new Set(It),[It]),os=o.useMemo(()=>Ee.filter(l=>l.session.isFavorite===!0).map(l=>l.session.sessionId),[Ee]),Kt=o.useMemo(()=>new Set(os),[os]),Es=o.useCallback(l=>{const p=gi(l,It);b.current=p,la(p),we.current=l,fe(l)},[It]),sr=o.useCallback(l=>{const p=!On.has(l),g=Wl(It,l,p),P=gi(q,g);b.current=P,la(P),dt(g),Vl(l,{collapsed:p}).catch(U=>{const V=Wl(g,l,!p),ce=gi(q,V);b.current=ce,la(ce),dt(V),_.current({title:U instanceof Error?U.message:r("shell.workspaceCollapseStateSaveFailed"),tone:"error"})})},[On,It,q]),Ar=o.useCallback(()=>{te.current={originalGroups:we.current}},[]),Wr=o.useCallback((l,p,g)=>{const P=we.current,U=hb(P,l,p,g);U!==P&&Es(U)},[Es]),Lr=o.useCallback(()=>{const l=te.current;te.current=null;const p=we.current;l&&(l.originalGroups.length===p.length&&l.originalGroups.every((g,P)=>{var U;return g.workspace.id===((U=p[P])==null?void 0:U.workspace.id)})||su({workspaceIds:p.map(g=>g.workspace.id)}).catch(g=>{Es(l.originalGroups),_.current({title:g instanceof Error?g.message:r("shell.workspaceReorderFailed"),tone:"error"})}))},[Es]);o.useEffect(()=>{const l=new Map;if(Ee.forEach(({session:p})=>{l.set(p.sessionId,{activityState:p.activityState,completedAt:p.completedAt??null,runningState:p.runningState??null})}),!pe.current){pe.current=!0,ne.current=l;return}Ee.forEach(({session:p})=>{var ce;if(p.sessionId===Te)return;const g=ne.current.get(p.sessionId);if(!g)return;const P=g.activityState!=="completed_unread"&&p.activityState==="completed_unread",U=((ce=p.title)==null?void 0:ce.trim())||r("common.unknown");if(h&&P){const je=r("conversation.backgroundCompletionToastDescription",{title:U});_.current({id:`workbench-session-completed-${p.sessionId}-${p.completedAt??"unknown"}`,title:r("conversation.backgroundCompletionToastTitle"),description:je,tone:"success",durationMs:8e3,action:{label:r("shell.contextOpenSession"),onClick:()=>Dn(p.workspaceId,p.sessionId)}}),x.current.showNotification(r("conversation.backgroundCompletionToastTitle"),je)}const V=g.runningState!=="failed"&&(p.runningState??null)==="failed";if(k&&V){const je=Ef(p)??r("conversation.runtimeFailed"),xe=r("conversation.backgroundFailureToastDescription",{title:U,detail:je});_.current({id:`workbench-session-failed-${p.sessionId}-${p.updatedAt}`,title:r("conversation.backgroundFailureToastTitle"),description:xe,tone:"error",durationMs:8e3,action:{label:r("shell.contextOpenSession"),onClick:()=>Dn(p.workspaceId,p.sessionId)}}),x.current.showNotification(r("conversation.backgroundFailureToastTitle"),xe)}}),ne.current=l},[Te,Ee,h,k,Dn]),o.useEffect(()=>{ct.current=Ee.map(l=>l.session).filter(l=>l.sessionId!==Te&&Mf(l)).map(l=>{var p;return{sessionId:l.sessionId,workspaceId:l.workspaceId,title:((p=l.title)==null?void 0:p.trim())||r("common.unknown")}})},[Te,Ee]),o.useEffect(()=>{let l=!1,p=null;const g=()=>{p=window.setTimeout(()=>{P().finally(()=>{l||g()})},vf)},P=async()=>{var xe;const U=ct.current;if(U.length===0){me.current||(me.current=!0),Ve.current="";return}const V=new Set(U.map(re=>re.sessionId)),ce=await Promise.all(U.map(async re=>{try{const Le=await au(re.sessionId);return{session:re,items:Le.items}}catch{return{session:re,items:null}}}));if(l)return;for(const re of ce){if(!re.items)continue;const Le=re.items.filter(lt=>lt.status==="pending"),Qt=new Set(Le.map(lt=>lt.id)),mn=We.current.get(re.session.sessionId)??new Set;me.current&&Le.forEach(lt=>{if(mn.has(lt.id)||!u)return;const Nn=r("conversation.backgroundPermissionToastDescription",{title:re.session.title,requestTitle:lt.title});_.current({id:`workbench-permission-request-${lt.id}`,title:r("conversation.permissionRequestToastTitle"),description:Nn,tone:"warning",durationMs:8e3,action:{label:r("shell.contextOpenSession"),onClick:()=>Dn(re.session.workspaceId,re.session.sessionId)}}),x.current.showNotification(r("conversation.permissionRequestToastTitle"),Nn)}),We.current.set(re.session.sessionId,Qt)}for(const[re,Le]of We.current.entries())!V.has(re)&&Le.size===0&&We.current.delete(re);const je=Rf(We.current,V);me.current&&je!==Ve.current&&((xe=w.current)==null||xe.requestRefresh()),Ve.current=je,me.current=!0};return P().finally(()=>{l||g()}),()=>{l=!0,p!==null&&window.clearTimeout(p)}},[u,Dn]),o.useEffect(()=>{ue&&q.length===0||(dt(l=>cd(l,yn)),ft(l=>l&&yn.has(l)?l:null))},[yn,ue]);const ht=Ee.find(l=>l.session.sessionId===Te)??null,$e=(ht==null?void 0:ht.workspace.id)??(Te?St[Te]??null:null),Ft=vl(t.pathname,t.search),Mt=Ft&&yn.has(Ft)?Ft:null,Ps=it&&yn.has(it)?it:null,As=$e??Mt??Ps??null,be=As??((Z=q[0])==null?void 0:Z.workspace.id)??null,Dr=o.useCallback(l=>{if(l){const p=Ee.find(g=>g.workspace.id===l)??null;if(p)return p}return Ee[0]??null},[Ee]),rr=o.useCallback(l=>{const p=typeof window>"u"?null:window.localStorage.getItem(ha);if(!p)return null;const g=p.split("?")[0]??p,P=vr(g);if(!P)return window.localStorage.removeItem(ha),null;const U=P.sessionId,V=Ee.find(je=>je.session.sessionId===U)??null,ce=P.workspaceId??(V==null?void 0:V.workspace.id)??null;return V&&(!l||ce===l)?Ut(V.workspace.id,V.session.sessionId):(window.localStorage.removeItem(ha),null)},[Ee]),Ws=o.useMemo(()=>ts.filter(l=>!ns.has(l.id)),[ns,ts]),Fn=o.useMemo(()=>Ws.filter(l=>_f(l,vn)).length,[Ws,vn]);o.useEffect(()=>{Wn&&is(Ws)},[Ws,is,Wn]);const _a=o.useCallback(l=>{an(!1),l.routePath&&s(l.routePath)},[s]),$n=o.useCallback(async(l,p)=>{const g=ee.current+1;ee.current=g;try{const P=await Sm(l,p);if(g!==ee.current)return;ss(U=>{const V=new Set(U);return P.item?V.add(P.item.notificationId):V.delete(l),V})}catch(P){if(g!==ee.current)return;_.current({title:r("shell.globalNotificationsArchiveFailed"),description:P instanceof Error?P.message:void 0,tone:"error"})}},[]);o.useEffect(()=>{$e&&ft(l=>l===$e?l:$e)},[$e]),o.useEffect(()=>{var V;if(ue)return;const l=((V=q[0])==null?void 0:V.workspace.id)??null,p=Mt??l??Ps,g=Te&&!Ke?Dr(p):null,P=Te&&!Ke?rr(p):null,U=g?Ut(g.workspace.id,g.session.sessionId):null;if(Ft&&!Mt){s(P??U??(l?Uf(t.pathname,l):bi(e)),{replace:!0});return}if(Te&&!Ke&&!$e){s(P??U??(l?Xs(l):bi(e)),{replace:!0});return}},[Te,Dr,Ke,t.pathname,s,q,ue,rr,Ft,$e,e,Ps,Mt]),o.useEffect(()=>{mt("workbench.current_workspace_resolved",{currentSessionId:Te,sessionWorkspaceId:$e,routeWorkspaceId:Ft,currentWorkspaceId:be,source:$e?ht?"navigation":"sessionWorkspaceMap":Ft?"route":it?"workspaceSelection":"navigationFallback"})},[ht,Te,be,Ft,it,$e]);const Rt=ya(t.pathname)?"terminals":Sa(t.pathname)?"butler":"conversation",Je=e==="mobile",un=bi(e),ar=o.useMemo(()=>q.map(l=>{const p=Jc(l.sessions);return{workspace:l.workspace,visibleSessions:p,archivedSessions:l.sessions.filter(g=>gn(g)&&!La(g)),visibleSessionTree:eo(p,c).filter(g=>!Kt.has(g.item.sessionId)&&!$i(en(g),P=>Kt.has(P.sessionId))),childWorktrees:nd(l.childWorktrees,Kt,c),isCollapsed:On.has(l.workspace.id)}}),[On,Kt,q,c]),ls=o.useMemo(()=>um(q),[q]),Hn=o.useMemo(()=>Tl(q,be),[be,q]),qt=(ht?Bu(ht.session,ht.session.sessionIsolatedWorkspace):be)??be,Sn=o.useMemo(()=>Tl(q,qt),[qt,q]),Br=o.useMemo(()=>be?(Hn==null?void 0:Hn.workspace)??q.map(l=>l.workspace).find(l=>l.id===be)??null:null,[be,Hn,q]),ir=o.useMemo(()=>qt?(Sn==null?void 0:Sn.workspace)??q.map(l=>l.workspace).find(l=>l.id===qt)??null:null,[qt,Sn,q]),jn=(Sn==null?void 0:Sn.meta)??null,Oa=(be?ls[be]??null:null)??(Br?Ra(Br):null),Vt=(qt?ls[qt]??null:null)??(ir?Ra(ir):Oa),_r=jn?at[jn.workspaceId]??null:null,or=((qe=(Qe=(Re=ht==null?void 0:ht.session)==null?void 0:Re.parallelGroup)==null?void 0:Qe.groupId)==null?void 0:qe.trim())||null,vt=Rt==="conversation"&&Lu((ht==null?void 0:ht.session)??null);o.useEffect(()=>{if(typeof window>"u"||!vt||!or){Nt(null);return}const l=Ou(or);if(!l||l.sidebarCollapseDurationMs<=0){Nt(null);return}Nt(l);const p=Date.now()-l.createdAt,g=l.totalDurationMs-p;if(g<=0){Nt(null);return}const P=window.setTimeout(()=>{Nt(null)},g);return()=>{window.clearTimeout(P)}},[or,vt]),o.useEffect(()=>{mt("workbench.info_panel_state",{infoPanelReady:rt,rightCollapsed:Ie||vt,currentWorkspaceId:be,sessionWorkspaceId:$e,currentSessionId:Te})},[Te,be,rt,vt,Ie,$e]);const Ls=o.useMemo(()=>Ee.filter(l=>Kt.has(l.session.sessionId)&&!gn(l.session)&&!Ii(l.session)),[Kt,Ee]),lr=t.pathname.startsWith("/settings")?"settings":Sa(t.pathname)?"terminals":ya(t.pathname)?"butler":Hf(t.pathname)?t.pathname.endsWith("/tools/processes")||t.pathname==="/tools/processes"?"butler":"sessions":$f(t.pathname)||xl(t.pathname)?"sessions":"workspaces",Fa=Je&&(lr==="sessions"&&xl(t.pathname)||Sa(t.pathname)),$a=Aa({isNativeMobile:a.isNativeMobile,viewportClass:a.viewportClass}),cs=jr({viewportClass:a.viewportClass,activeEntry:lr,hasNavigationPanel:Je,hasAuxiliaryPanel:Je,preferCompactLayout:$a}),Ha=Je&&kc(cs),Or=Je&&wc(cs),Ua=o.useMemo(()=>q.map(l=>l.workspace),[q]),Ga=o.useMemo(()=>{const l=wn.trim().toLowerCase();return l?Ee.filter(p=>{const g=(p.session.title||"").toLowerCase(),P=p.workspace.name.toLowerCase(),U=Da(p.session.provider,"full").toLowerCase();return g.includes(l)||P.includes(l)||U.includes(l)}):[]},[Ee,wn]);o.useEffect(()=>{var p;const l=be??((p=q[0])==null?void 0:p.workspace.id)??"";l&&rn(g=>g&&q.some(U=>U.workspace.id===g)?g:l)},[be,q]),o.useEffect(()=>{Te&&!Ke&&$e&&bs(ha,`${t.pathname}${t.search}`)},[Te,Ke,t.pathname,t.search,$e]),o.useEffect(()=>{if(Te&&Ke){L.current=`${t.pathname}${t.search}`;return}Te&&!Ke&&(L.current=null)},[Te,Ke,t.pathname,t.search]),o.useEffect(()=>{Je||(Se(!1),Ae(!1))},[Je]),o.useEffect(()=>{!Je||ue||!Ff(t.pathname)||As||(Se(!1),Ae(!1),s(un,{replace:!0}))},[As,Je,t.pathname,s,ue,un]);function Fr(){if(Je){Se(!0);return}Be(!1)}function za(){if(!vt){if(hn(),Je){Ae(!0);return}tt(!1)}}function Ka(){if(Je){Se(l=>!l);return}Be(l=>!l)}function $r(){if(!vt){if(hn(),Je){Ae(l=>!l);return}tt(l=>!l)}}function hn(){sn(!0)}function ds(l){if(ft(l),hn(),ya(t.pathname)){const p=gs(l);t.pathname!==p&&s(p);return}Te&&$e!==l&&s(un)}const us=o.useCallback(async l=>{var P;const p=((P=Ee.find(U=>U.session.sessionId===l))==null?void 0:P.session)??null,g=(p==null?void 0:p.isFavorite)!==!0;fe(U=>Al(U,l,g));try{const U=await ru(l,g);wt(U),Et()}catch(U){throw fe(V=>Al(V,l,!g)),U}},[Ee,Et,wt]),hs=o.useCallback((l,p)=>{Xc(l,p).then(()=>{s(mc(l,p))}).catch(g=>{i({title:g instanceof Error?g.message:r("shell.startSessionFailed"),tone:"error"})})},[s,i]),Hr=o.useCallback(l=>{var P;const p=((P=l.workspaceId)==null?void 0:P.trim())||be,g=Gf(l.filePath);return!p||!g?!1:(hn(),Me("files"),Je?(Se(!1),Ae(!0)):tt(!1),Jn({requestId:z.current+1,workspaceId:p,filePath:g,openViewer:l.openViewer===!0}),z.current+=1,!0)},[be,Je]),Ur=o.useCallback(async(l,p)=>{const g=await Xl(l,p.trim());return wt(g),g},[wt]);function Ds(l){ys(!0)}function Gr(){ys(!1),Ss("sessions"),Mn(""),En(null),Lt([]),er(!1)}async function qa(){const l=wn.trim();if(!l||!Rn.trim()){Lt([]),En(null);return}er(!0),En(null);try{const p=await Nu(Rn,l);Lt(p.items)}catch(p){Lt([]),En(p instanceof Error?p.message:r("shell.searchCodeFailed"))}finally{er(!1)}}function zr(l,p){const g=R.current;g&&(g.style.setProperty("--workbench-left-width",`${l}px`),g.style.setProperty("--workbench-left-current-width",he?"0px":`${l}px`),g.style.setProperty("--workbench-right-width",`${p}px`),g.style.setProperty("--workbench-right-current-width",Ie?"0px":`${p}px`))}function Va(l={}){return{leftWidth:l.leftWidth??(he?0:$.current),rightWidth:l.rightWidth??($t&&!Ie?Y.current:0),leftCollapsed:l.leftCollapsed??he,rightCollapsed:l.rightCollapsed??(!$t||Ie),prefersDarkAppearance:l.prefersDarkAppearance??Ns!=="light",isResizing:l.isResizing??Ye!==null}}function cr(l,p){var je;p.preventDefault(),p.stopPropagation(),(je=window.getSelection())==null||je.removeAllRanges();const g=p.clientX,P=l==="left"?m:G;nn(l);const U=()=>{const xe=ye.current;if(ye.current=null,xe!==null){if(l==="left"){$.current=xe,C(re=>re===xe?re:xe),zr(xe,Y.current);return}Y.current=xe,se(re=>re===xe?re:xe),zr($.current,xe)}};function V(xe){var mn;xe.preventDefault(),(mn=window.getSelection())==null||mn.removeAllRanges();const re=xe.clientX-g,Le=l==="left"?ba(P+re,ul,pl):ba(P-re,hl,ml),Qt=l==="left"?$.current:Y.current;Le===Qt&&ye.current===null||(ye.current=Le,Ce.current===null&&(Ce.current=window.requestAnimationFrame(()=>{Ce.current=null,U()})))}function ce(){document.removeEventListener("mousemove",V),document.removeEventListener("mouseup",ce),Ce.current!==null&&(window.cancelAnimationFrame(Ce.current),Ce.current=null),U(),nn(re=>re===l?null:re);const xe=Va({isResizing:!1});f.current=xe,a.bridge.syncNativeSidebarLayout(xe)}document.addEventListener("mousemove",V,{passive:!1}),document.addEventListener("mouseup",ce)}function ps(){if(Kr())return;if(Ee.length===0){s(un);return}const l=Ut(Ee[0].workspace.id,Ee[0].session.sessionId);s(l)}function Xa(){if(!Kr(be)){if(be){s(Xs(be));return}s(un)}}function Kr(l){if(Te&&$e)return l&&$e&&$e!==l?!1:(s(`${t.pathname}${t.search}`),!0);if(L.current){if(l){const[g,P=""]=L.current.split("?"),U=vl(g??L.current,P?`?${P}`:"");if(U&&U!==l)return!1}return s(L.current),!0}const p=rr(l);return p?(s(p),!0):!1}o.useEffect(()=>{if(typeof window>"u")return;function l(p){if(!(p.metaKey||p.ctrlKey)){p.key==="Escape"&&(Se(!1),Ae(!1));return}if(ib(p.target))return;const P=p.key.toLowerCase();if(!p.shiftKey&&P==="b"){p.preventDefault(),Ka();return}if(p.shiftKey&&P==="i"){p.preventDefault(),$r();return}if(!p.shiftKey&&P===","){p.preventDefault(),s("/settings");return}if(!p.shiftKey&&P==="1"){p.preventDefault(),ps();return}if(!p.shiftKey&&P==="2"){p.preventDefault(),s(be?gs(be):Ct());return}if(!p.shiftKey&&P==="k"){p.preventDefault(),ob();return}p.shiftKey&&P==="r"&&(p.preventDefault(),ze())}return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l)}},[s,ze,Je,ps]);const Ya=o.useMemo(()=>({shellMode:e,navigationGroups:q,navigationLoading:ue,navigationError:De,currentWorkspaceId:be,currentSessionId:Te,favoriteSessionIds:os,favoriteSessions:Ls,globalNotifications:ts,archivedNotificationIds:Array.from(ns),showArchivedNotifications:Ln,unreadNotificationCount:Fn,refreshNavigation:ze,requestNavigationRefresh:Et,openNotificationPanel:()=>{an(!0)},closeNotificationPanel:()=>{an(!1)},setShowArchivedNotifications:rs,archiveNotification:l=>{$n(l,!0)},unarchiveNotification:l=>{$n(l,!1)},setAuxiliaryPanel:yt,subscribeFileTree:Is,requestFileTreeRefresh:Ts,addFileTreeSnapshotListener:Ms,subscribeGitSnapshot:on,requestGitRefresh:Ot,addGitSnapshotListener:ln,subscribeWorkspaceManagementSnapshot:Bn,requestWorkspaceManagementRefresh:cn,addWorkspaceManagementSnapshotListener:Rs,workspaceManagementStateById:Zn,subscribeTerminalManagerSnapshot:Gt,requestTerminalManagerRefresh:ot,addTerminalManagerSnapshotListener:nr,selectWorkspace:ds,toggleFavoriteSession:us,archiveSession:l=>zt(l,!0),unarchiveSession:l=>zt(l,!1),renameSession:Ur,startDraftSession:hs,markNavigationSessionSeen:_e,upsertNavigationSession:wt,setSessionWorkspace:_n,revealWorkspaceFile:Hr}),[Ms,ln,Rs,nr,zt,Te,be,ts,os,Ls,ds,ns,_e,De,q,ue,Fn,Ts,Ot,cn,ze,Et,rs,yt,ot,Ur,Ln,Zn,e,hs,_n,Is,on,Bn,Gt,$n,us,wt,Hr]),Ja={"--workbench-left-width":`${m}px`,"--workbench-left-current-width":he?"0px":`${m}px`,"--workbench-right-width":`${G}px`,"--workbench-right-current-width":Ie||vt?"0px":`${G}px`,"--workbench-right-sidebar-duration":Ze&&!Ie?`${Ze.sidebarCollapseDurationMs}ms`:void 0,"--workbench-right-sidebar-content-duration":Ze&&!Ie?`${Math.max(320,Ze.sidebarCollapseDurationMs-120)}ms`:void 0},dr=Rt==="butler"?Xn:n.jsx(_l,{panelReady:rt,activeTab:Wt,fileRevealRequest:Pn,onTabChange:l=>{hn(),Me(l)},currentSessionId:Ke?null:Te,activeWorkspaceId:qt,navigationGroups:q,workspaceContext:Vt,worktreeMeta:jn,worktreeMergeState:_r,onRefreshWorktreeMergePreview:dn,onApplyWorktreeMerge:Rr,onCleanupWorktree:Er}),$t=dr!==null,Xt=Ie||vt,Bs=vt&&Ze!==null&&!Ie,Yt=a.isDesktop&&a.ui.osFamily==="macos"&&a.ui.prefersOverlayTitlebar;o.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const{documentElement:l,body:p}=document,g=()=>{de.current!==null&&(window.clearTimeout(de.current),de.current=null);const U=ie.current;ie.current=!1,l.removeAttribute(ma),p==null||p.removeAttribute(ma),U&&Ne.current&&(Ne.current=!1,Cs(V=>V+1))};if(!Yt){g();return}const P=()=>{ie.current=!0,l.setAttribute(ma,"true"),p==null||p.setAttribute(ma,"true"),de.current!==null&&window.clearTimeout(de.current),de.current=window.setTimeout(()=>{g()},yf)};return window.addEventListener("resize",P),()=>{window.removeEventListener("resize",P),g()}},[Yt]);const Un=o.useMemo(()=>({leftWidth:he?0:m,rightWidth:$t&&!Xt?G:0,leftCollapsed:he,rightCollapsed:!$t||Xt,prefersDarkAppearance:Ns!=="light",isResizing:Ye!==null}),[Ye,Xt,he,m,G,$t,Ns]),qr=o.useDeferredValue(Un),d=Ye===null?qr:Un,f=o.useRef(Un);o.useEffect(()=>{f.current=Un},[Un]),o.useEffect(()=>{if(typeof window>"u")return;let l=null;const p=()=>{l=null,a.bridge.syncNativeSidebarLayout(d)},g=()=>{l!==null&&window.cancelAnimationFrame(l),l=window.requestAnimationFrame(p)};return xn?(g(),()=>{l!==null&&window.cancelAnimationFrame(l)}):(a.bridge.syncNativeSidebarLayout({leftWidth:0,rightWidth:0,leftCollapsed:!0,rightCollapsed:!0,prefersDarkAppearance:!1,isResizing:!1}),()=>{l!==null&&window.cancelAnimationFrame(l)})},[d,a.bridge,xn]),o.useLayoutEffect(()=>{const l=R.current;if(!l||!Yt||typeof window>"u"){kl(l);return}let p=null,g=null;const P=new Set([l]),U=()=>{Ne.current=!1;const ce=window.getComputedStyle(l),je=qc(ce,"--desktop-macos-traffic-light-center-y");if(je===null){kl(l);return}const xe={navToolbar:Gn(l,Ue.navToolbar.selector),infoTabs:Gn(l,Ue.infoTabs.selector),auxiliaryToolbarButton:Gn(l,Ue.auxiliaryToolbarButton.selector),conversationHeaderMain:Gn(l,Ue.conversationHeaderMain.selector),conversationHeaderActions:Gn(l,Ue.conversationHeaderActions.selector),terminalTabbarMain:Gn(l,Ue.terminalTabbarMain.selector),collapsedLeftControls:Gn(l,Ue.collapsedLeftControls.selector),collapsedRightControls:Gn(l,Ue.collapsedRightControls.selector)},re=[xe.infoTabs,xe.conversationHeaderMain,xe.conversationHeaderActions,xe.terminalTabbarMain].filter(lt=>lt!==null),Le=[xe.collapsedLeftControls,xe.collapsedRightControls].filter(lt=>lt!==null),Qt=Le.length>0?bn(ce,"--workbench-collapsed-controls-live-shift-y",je,Le.reduce((lt,Nn)=>lt+Nn,0)/Le.length):null,mn=re.length>0?bn(ce,"--workbench-titlebar-live-content-shift-y",je,re.reduce((lt,Nn)=>lt+Nn,0)/re.length):null;fn(l,"--workbench-titlebar-live-content-shift-y",mn),fn(l,"--workbench-collapsed-controls-live-shift-y",Qt),fn(l,Ue.navToolbar.variableName,bn(ce,Ue.navToolbar.variableName,je,xe.navToolbar)),fn(l,Ue.infoTabs.variableName,bn(ce,Ue.infoTabs.variableName,je,xe.infoTabs)),fn(l,Ue.auxiliaryToolbarButton.variableName,bn(ce,Ue.auxiliaryToolbarButton.variableName,je,xe.auxiliaryToolbarButton)),fn(l,Ue.conversationHeaderMain.variableName,bn(ce,Ue.conversationHeaderMain.variableName,je,xe.conversationHeaderMain)),fn(l,Ue.conversationHeaderActions.variableName,bn(ce,Ue.conversationHeaderActions.variableName,je,xe.conversationHeaderActions)),fn(l,Ue.terminalTabbarMain.variableName,bn(ce,Ue.terminalTabbarMain.variableName,je,xe.terminalTabbarMain)),fn(l,Ue.collapsedLeftControls.variableName,bn(ce,Ue.collapsedLeftControls.variableName,je,xe.collapsedLeftControls)),fn(l,Ue.collapsedRightControls.variableName,bn(ce,Ue.collapsedRightControls.variableName,je,xe.collapsedRightControls))},V=()=>{if(ie.current){Ne.current=!0;return}p!==null&&window.cancelAnimationFrame(p),p=window.requestAnimationFrame(()=>{p=null,U()})};if(V(),typeof ResizeObserver<"u"){g=new ResizeObserver(()=>{V()});for(const ce of Object.values(Ue))for(const je of l.querySelectorAll(ce.selector))P.add(je);for(const ce of P)g.observe(ce)}return window.addEventListener("resize",V),()=>{p!==null&&window.cancelAnimationFrame(p),window.removeEventListener("resize",V),g==null||g.disconnect()}},[Rt,rt,he,t.pathname,t.search,Ie,$t,Yt,_t]);const v=Je?n.jsx(Bl,{workspaceGroups:ar,workspaceVisualContextMap:ls,sessionDisplaySortMode:c,favoriteSessions:Ls,favoriteSessionIds:Kt,activeWorkspaceId:be,isConversationActive:Rt==="conversation",isTerminalActive:Rt==="terminals",isButlerActive:Rt==="butler",isSearchOpen:ut,navigationLoading:ue,navigationError:De,activeSessionId:Te,onRefreshNavigation:ze,onSessionUpdated:wt,onNavigateConversation:ps,onNavigateTerminals:()=>{Se(!1),s(be?gs(be):Ct())},onNavigateButler:()=>{Se(!1),s(be?ks(be):Ct())},onOpenSearch:()=>{Se(!1),Ds()},onOpenSettings:()=>{Se(!1),s("/settings")},onSelectWorkspace:ds,onToggleWorkspaceCollapse:sr,onStartWorkspaceReorder:Ar,onPreviewWorkspaceReorder:Wr,onCommitWorkspaceReorder:Lr,allowWorkspaceReorder:!1,subscribeGitSnapshot:on,requestGitRefresh:Ot,subscribeWorkspaceManagementSnapshot:Bn,requestWorkspaceManagementRefresh:cn,onToggleFavoriteSession:us,onArchiveSession:l=>zt(l,!0),onUnarchiveSession:l=>zt(l,!1),workspaceManagementStateById:Zn,setWorkspaceManagementStateById:bt,unreadNotificationCount:Fn,notificationPanelOpen:Wn,onToggleNotificationPanel:()=>{an(l=>!l)},onClose:()=>Se(!1)}):null,W=Je&&$t?dr:null;return n.jsxs(Yc.Provider,{value:Ya,children:[Je?n.jsx(n.Fragment,{children:n.jsx(bh,{activeEntry:lr,presentation:Fa?"conversation-focus":"default",navigationPanel:v,auxiliaryPanel:W,onOpenNavigation:()=>{Ae(!1),Se(!0)},onOpenSearch:()=>{Se(!1),Ae(!1),Ds()},onOpenAuxiliary:()=>{$t&&(hn(),Se(!1),Ae(!0))},onNavigateWorkspaces:()=>{Se(!1),Ae(!1),s(Ct())},onNavigateTerminals:()=>{Se(!1),Ae(!1),s(be?gs(be):Ct())},onNavigateButler:()=>{Se(!1),Ae(!1),s(be?ks(be):Ct())},onNavigateSessions:()=>{Se(!1),Ae(!1),Xa()},onNavigateToolFiles:()=>{Se(!1),Ae(!1),s(be?uc(be):Ct())},onNavigateToolGit:()=>{Se(!1),Ae(!1),s(be?hc(be):Ct())},onNavigateToolProcesses:()=>{Se(!1),Ae(!1),s(be?pc(be):Ct())},onNavigateSettings:()=>{Se(!1),Ae(!1),s("/settings")},children:n.jsx(no,{})})}):n.jsx("div",{className:"workbench-shell",ref:R,style:Ja,onMouseDownCapture:Dt,onDoubleClickCapture:Mr,"data-nav-loading":ue,"data-left-collapsed":he,"data-right-collapsed":Xt,"data-info-ready":rt,"data-parallel-conversation-active":vt?"true":void 0,"data-parallel-sidebar-transition":Bs?"true":void 0,"data-runtime-platform":a.platform,"data-os-family":a.ui.osFamily,"data-overlay-titlebar":a.ui.prefersOverlayTitlebar,children:n.jsxs("div",{className:"workbench-body-shell",children:[n.jsx("aside",{className:"workbench-nav surface-card","data-collapsed":he,children:n.jsx(Bl,{workspaceGroups:ar,workspaceVisualContextMap:ls,sessionDisplaySortMode:c,favoriteSessions:Ls,favoriteSessionIds:Kt,activeWorkspaceId:be,isConversationActive:Rt==="conversation",isTerminalActive:Rt==="terminals",isButlerActive:Rt==="butler",isSearchOpen:ut,navigationLoading:ue,navigationError:De,activeSessionId:Te,onRefreshNavigation:ze,onSessionUpdated:wt,onNavigateConversation:ps,onNavigateTerminals:()=>s(be?gs(be):Ct()),onNavigateButler:()=>s(be?ks(be):Ct()),onOpenSearch:()=>Ds(),onOpenSettings:()=>s("/settings"),onSelectWorkspace:ds,onToggleWorkspaceCollapse:sr,onStartWorkspaceReorder:Ar,onPreviewWorkspaceReorder:Wr,onCommitWorkspaceReorder:Lr,allowWorkspaceReorder:!0,subscribeGitSnapshot:on,requestGitRefresh:Ot,subscribeWorkspaceManagementSnapshot:Bn,requestWorkspaceManagementRefresh:cn,onToggleFavoriteSession:us,onArchiveSession:l=>zt(l,!0),onUnarchiveSession:l=>zt(l,!1),workspaceManagementStateById:Zn,setWorkspaceManagementStateById:bt,unreadNotificationCount:Fn,notificationPanelOpen:Wn,onToggleNotificationPanel:()=>{an(l=>!l)},onToggleCollapse:()=>Be(!0)})}),n.jsx("div",{className:"workbench-side-resizer","data-side":"left","data-collapsed":he,role:"separator","aria-label":r("shell.leftResizerLabel"),onMouseDown:he?void 0:l=>cr("left",l)}),n.jsxs("div",{className:"workbench-main-shell",children:[n.jsxs("div",{className:"workbench-collapsed-rail","aria-hidden":!he&&!Ie,children:[n.jsxs("div",{className:"workbench-collapsed-controls left","data-visible":he,children:[n.jsx(Ll,{className:"workbench-nav-toolbar-button workbench-collapsed-button",ariaLabel:r("shell.showSessionSidebar"),side:"left",collapsed:!0,onClick:Fr}),n.jsx($c,{collapsed:!0}),n.jsx(kd,{unreadCount:Fn,open:Wn,onToggle:()=>{an(l=>!l)},collapsed:!0})]}),$t&&!vt?n.jsx("div",{className:"workbench-collapsed-controls right","data-visible":Ie,children:n.jsx(Ll,{className:"workbench-nav-toolbar-button workbench-collapsed-button",ariaLabel:r("shell.showInfoSidebar"),side:"right",collapsed:!0,onClick:za})}):null]}),n.jsx(no,{})]}),$t?n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"workbench-side-resizer","data-side":"right","data-collapsed":Xt,"data-auto-hidden":vt?"true":void 0,role:"separator","aria-label":r("shell.rightResizerLabel"),onMouseDown:Xt?void 0:l=>cr("right",l)}),n.jsx("aside",{className:"workbench-auxiliary surface-card","data-workspace-tone":(Vt==null?void 0:Vt.tone)??"root","data-worktree-depth":(Vt==null?void 0:Vt.depth)??0,"data-collapsed":Xt,"data-auto-hidden":vt?"true":void 0,"data-custom-panel":Rt==="butler","data-parallel-transition":Bs?"true":void 0,"aria-hidden":Xt&&!Bs,style:In(Vt),children:vt&&!Bs?null:Rt==="butler"?n.jsx("div",{className:"workbench-auxiliary-custom-panel",children:Xn}):n.jsx(_l,{panelReady:rt,activeTab:Wt,fileRevealRequest:Pn,onTabChange:l=>{hn(),Me(l)},onToggleCollapse:()=>tt(!0),currentSessionId:Ke?null:Te,activeWorkspaceId:qt,navigationGroups:q,workspaceContext:Vt,worktreeMeta:jn,worktreeMergeState:_r,onRefreshWorktreeMergePreview:dn,onApplyWorktreeMerge:Rr,onCleanupWorktree:Pr})})]}):null]})}),n.jsx(Cb,{open:Wn,notifications:ts,archivedNotificationIds:ns,showArchivedNotifications:Ln,onClose:()=>an(!1),onToggleShowArchivedNotifications:rs,onArchiveNotification:l=>{$n(l,!0)},onUnarchiveNotification:l=>{$n(l,!1)},onSelectNotification:_a,preferredWorkspaceId:be,preferredSessionId:Ke?null:Te}),n.jsx(Hb,{open:ut,mode:Yn,keyword:wn,codeWorkspaceId:Rn,codeResults:Tr,codeLoading:Ir,codeError:tr,workspaceOptions:Ua,sessionResults:Ga,onClose:Gr,onModeChange:l=>{Ss(l),En(null),Lt([])},onKeywordChange:l=>{Mn(l),Yn==="code"&&!l.trim()&&(Lt([]),En(null))},onCodeWorkspaceChange:l=>rn(l),onCodeSearch:()=>{qa()},onOpenSession:l=>{Gr();const p=Ee.find(g=>g.session.sessionId===l)??null;s(p?Ut(p.workspace.id,l):Ct())}}),n.jsxs(et,{open:Fe!==null,title:r("shell.worktreeCleanupModalTitle"),description:r("shell.worktreeCleanupModalDescription"),onClose:()=>{var l;Fe&&((l=at[Fe.workspaceId])!=null&&l.cleaning)||(An(!1),Qn(null))},children:[n.jsx("p",{className:"workbench-section-empty",children:Fe?r("shell.worktreeCleanupConfirm",{name:Fe.displayName||Fe.branchName}):""}),Fe?n.jsxs("div",{className:"worktree-cleanup-modal-options",children:[n.jsxs("label",{className:"conversation-selection-checkbox worktree-cleanup-modal-option",children:[n.jsx("input",{type:"checkbox",checked:es,disabled:!!((pt=at[Fe.workspaceId])!=null&&pt.cleaning)||((pn=(Jt=at[Fe.workspaceId])==null?void 0:Jt.preview)==null?void 0:pn.alreadyMerged)!==!0,onChange:l=>An(l.target.checked)}),n.jsx("span",{children:r("shell.worktreeCleanupDeleteBranchLabel",{branch:Fe.branchName})})]}),((Cn=(ve=at[Fe.workspaceId])==null?void 0:ve.preview)==null?void 0:Cn.alreadyMerged)!==!0?n.jsx("p",{className:"conversation-selection-hint worktree-cleanup-modal-hint",children:r("shell.worktreeCleanupDeleteBranchHint")}):null]}):null,n.jsxs("div",{className:"workbench-modal-actions",children:[n.jsx("button",{type:"button",className:"secondary-button",disabled:!!(Fe&&((Zt=at[Fe.workspaceId])!=null&&Zt.cleaning)),onClick:()=>{An(!1),Qn(null)},children:r("common.cancel")}),n.jsx("button",{type:"button",className:es&&Fe&&((Vr=(He=at[Fe.workspaceId])==null?void 0:He.preview)==null?void 0:Vr.alreadyMerged)===!0?"secondary-button workbench-danger-button":"primary-button",disabled:!Fe||!!(Fe&&((ms=at[Fe.workspaceId])!=null&&ms.cleaning)),onClick:()=>{Fe&&Er(Fe)},children:Fe&&((Xr=at[Fe.workspaceId])!=null&&Xr.cleaning)?r("shell.worktreeCleanupRunning"):es&&Fe&&((Jr=(Yr=at[Fe.workspaceId])==null?void 0:Yr.preview)==null?void 0:Jr.alreadyMerged)===!0?r("shell.worktreeCleanupDeleteBranchAction"):r("shell.worktreeCleanupAction")})]})]}),Je?n.jsxs(n.Fragment,{children:[Ha?null:n.jsx(Ol,{isOpen:Ge,side:"left",onClose:()=>Se(!1),children:v}),Or?null:n.jsx(Ol,{isOpen:nt,side:"right",onClose:()=>Ae(!1),children:W})]}):null]})}function Ol({isOpen:e,side:t,onClose:s,children:a,className:i,overlayClassName:c}){if(!e)return null;const u=n.jsxs(n.Fragment,{children:[n.jsx("div",{className:["mobile-nav-overlay","open",c].filter(Boolean).join(" "),onClick:s,role:"button",tabIndex:0,"aria-label":r("common.back"),onKeyDown:h=>{h.key==="Escape"&&s()}}),n.jsx("div",{className:["mobile-nav-drawer",t,"open",i].filter(Boolean).join(" "),children:a})]});return typeof document>"u"?u:ws.createPortal(u,document.body)}function uk(){return o.useContext(Yc)??{navigationGroups:[],navigationLoading:!1,navigationError:null,shellMode:"desktop",currentWorkspaceId:null,currentSessionId:null,favoriteSessionIds:[],favoriteSessions:[],globalNotifications:[],archivedNotificationIds:[],showArchivedNotifications:!1,unreadNotificationCount:0,refreshNavigation:async()=>{},requestNavigationRefresh:()=>{},openNotificationPanel:()=>{},closeNotificationPanel:()=>{},setShowArchivedNotifications:()=>{},archiveNotification:()=>{},unarchiveNotification:()=>{},setAuxiliaryPanel:()=>{},subscribeFileTree:()=>{},requestFileTreeRefresh:()=>{},addFileTreeSnapshotListener:()=>()=>{},subscribeGitSnapshot:()=>{},requestGitRefresh:()=>{},addGitSnapshotListener:()=>()=>{},subscribeWorkspaceManagementSnapshot:()=>{},requestWorkspaceManagementRefresh:()=>{},addWorkspaceManagementSnapshotListener:()=>()=>{},workspaceManagementStateById:{},subscribeTerminalManagerSnapshot:()=>{},requestTerminalManagerRefresh:()=>{},addTerminalManagerSnapshotListener:()=>()=>{},selectWorkspace:()=>{},toggleFavoriteSession:async()=>{},archiveSession:async()=>{},unarchiveSession:async()=>{},renameSession:async()=>{throw new Error("workbench shell unavailable")},startDraftSession:()=>{},setSessionWorkspace:()=>{},upsertNavigationSession:()=>{},markNavigationSessionSeen:()=>{},revealWorkspaceFile:()=>!1}}function xd(e){return e.startsWith("draft-")}export{ok as $,em as A,Om as B,Ji as C,zp as D,Kp as E,Wu as F,Ng as G,Pu as H,Xi as I,om as J,Gp as K,um as L,Uu as M,Tg as N,zn as O,Zs as P,Us as Q,da as R,fr as S,Xm as T,Zm as U,Ym as V,Nh as W,xa as X,Jm as Y,Qm as Z,Vm as _,dk as a,Cu as a$,sk as a0,rk as a1,lk as a2,tk as a3,ng as a4,mt as a5,tg as a6,Hu as a7,Du as a8,Ra as a9,Wg as aA,Lg as aB,$g as aC,Hg as aD,Fg as aE,_g as aF,Dg as aG,Qg as aH,Bg as aI,Vg as aJ,nk as aK,ak as aL,ik as aM,Zg as aN,zg as aO,Kg as aP,qg as aQ,Xg as aR,Yg as aS,Jg as aT,Im as aU,Og as aV,Ug as aW,Gg as aX,ek as aY,tl as aZ,Kc as a_,af as aa,Eu as ab,Ou as ac,jg as ad,Sg as ae,Ig as af,Bu as ag,In as ah,uo as ai,Cg as aj,Hh as ak,Uh as al,Gh as am,Eg as an,Yi as ao,Jp as ap,Zp as aq,Ag as ar,Mg as as,Lu as at,_u as au,$i as av,cf as aw,Ct as ax,Ch as ay,Rg as az,Na as b,sg as b0,cm as b1,Nm as b2,Ci as b3,cg as b4,hg as b5,ug as b6,ag as b7,Nu as b8,ig as b9,og as ba,Mu as bb,eg as bc,dg as bd,fg as be,kg as bf,Iu as bg,yg as bh,bg as bi,pg as bj,gg as bk,mg as bl,xg as bm,vg as bn,wg as bo,lg as bp,rg as bq,cc as br,Ut as c,Km as d,_m as e,ck as f,Yp as g,bm as h,Pg as i,gm as j,Fc as k,vm as l,$o as m,Xs as n,gs as o,dc as p,ks as q,yc as r,pc as s,kn as t,uk as u,tm as v,wr as w,sm as x,uc as y,hc as z};