@jingyi0605/codingns 0.5.0 → 0.5.1

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 (76) hide show
  1. package/dist/public/assets/AdaptiveButlerPage-SffCV4Vb.js +3 -0
  2. package/dist/public/assets/App-WOLwMld_.js +30 -0
  3. package/dist/public/assets/{BootstrapPage-Vu5oEJ8z.js → BootstrapPage--zExdgfM.js} +1 -1
  4. package/dist/public/assets/{ConversationPage-Cjpg6g0J.js → ConversationPage-D9pzRmOg.js} +2 -2
  5. package/dist/public/assets/{DesktopDetachPreviewPage-BgeEqbc5.js → DesktopDetachPreviewPage-DvI9CIKi.js} +1 -1
  6. package/dist/public/assets/{DesktopWindowPage-1WelvxdH.js → DesktopWindowPage-D8FpOSLE.js} +1 -1
  7. package/dist/public/assets/FileContextPanel-C8T7oqRN.js +1 -0
  8. package/dist/public/assets/GitSidebar-Bze7DNnc.js +6 -0
  9. package/dist/public/assets/{MobileCreateSessionSheet-DLq5qPkx.js → MobileCreateSessionSheet-CXSKMnYn.js} +1 -1
  10. package/dist/public/assets/MobileSheet-Gzc14EpR.js +1 -0
  11. package/dist/public/assets/{MobileTopHeaderFrame-DArgZI7L.js → MobileTopHeaderFrame-BWorAJ1C.js} +1 -1
  12. package/dist/public/assets/{MobileWorkspaceSwitcherHeader-0ywJKfBQ.js → MobileWorkspaceSwitcherHeader-DOr4pTUq.js} +1 -1
  13. package/dist/public/assets/{ServerSettingsModal-izoYMx9U.js → ServerSettingsModal-BYB0GvTl.js} +1 -1
  14. package/dist/public/assets/{SessionIndexPage-C5aG8FIv.js → SessionIndexPage-CR3IARXX.js} +1 -1
  15. package/dist/public/assets/SettingsPage-B_BQtnwE.js +1 -0
  16. package/dist/public/assets/TerminalManagerPanel-PQ-EM64j.js +1 -0
  17. package/dist/public/assets/{TerminalPage-CtKXIU0h.js → TerminalPage-CvnHXBhw.js} +12 -12
  18. package/dist/public/assets/{TerminalRuntimeFallbackModal-CRhOQOsT.js → TerminalRuntimeFallbackModal-D7Aq186N.js} +1 -1
  19. package/dist/public/assets/{ToolFilesPage-DcYPsS-e.js → ToolFilesPage-Qzkc6K2I.js} +1 -1
  20. package/dist/public/assets/{ToolGitPage-CsPl89ty.js → ToolGitPage-BdNDN-cV.js} +1 -1
  21. package/dist/public/assets/{ToolProcessesPage-D0dvR8xK.js → ToolProcessesPage-EXJ9DHWI.js} +1 -1
  22. package/dist/public/assets/{ToolsHomePage-4fP-KRiv.js → ToolsHomePage-CjF3CWzR.js} +1 -1
  23. package/dist/public/assets/{WorkbenchLandingPage-kvlfyxRo.js → WorkbenchLandingPage-DZPk4SmX.js} +1 -1
  24. package/dist/public/assets/WorkbenchLayout-rwQib5In.js +3 -0
  25. package/dist/public/assets/{WorkbenchModal-Ctob14VR.js → WorkbenchModal-B09hC9b5.js} +1 -1
  26. package/dist/public/assets/WorkbenchShellRoute-Cerk5uK7.js +1 -0
  27. package/dist/public/assets/WorkbenchShellRoute-DsW4mBTX.css +1 -0
  28. package/dist/public/assets/{WorkspaceDebugDetailPage-Com5kEXJ.js → WorkspaceDebugDetailPage-Bcq8s-Ma.js} +1 -1
  29. package/dist/public/assets/WorkspaceDetailPage-DNAa8pKr.js +1 -0
  30. package/dist/public/assets/WorkspaceHomePage-BoiLuACV.js +1 -0
  31. package/dist/public/assets/client-runtime-manager-CRQ-F5d2.js +1 -0
  32. package/dist/public/assets/{default-session-permission-mode-CcGwR4Kk.js → default-session-permission-mode-D0wZ9Jek.js} +1 -1
  33. package/dist/public/assets/{file-tree-icon-UFVoVzhM.js → file-tree-icon-Dp_xhVfD.js} +14 -14
  34. package/dist/public/assets/index-C2G8Gmf1.js +42 -0
  35. package/dist/public/assets/{index-_52jxu4a.css → index-CpPTUeA3.css} +1 -1
  36. package/dist/public/assets/{preferences-service-KIYeE2gk.js → preferences-service-gOt2ZjKZ.js} +1 -1
  37. package/dist/public/assets/{session-runtime-machine-0KNSSPp5.js → session-runtime-machine-Dq3pW-UF.js} +8 -8
  38. package/dist/public/assets/{terminal-runtime-meta-AWXJpN4r.js → terminal-runtime-meta-BMT-rSEe.js} +1 -1
  39. package/dist/public/assets/{useRegisteredDebugTemplates-DBDRdptr.js → useRegisteredDebugTemplates-zMcEOGca.js} +1 -1
  40. package/dist/public/index.html +2 -2
  41. package/dist/server/modules/client/client-controller.js +1 -1
  42. package/dist/server/modules/client/client-controller.js.map +1 -1
  43. package/dist/server/modules/client/client-service.d.ts +16 -2
  44. package/dist/server/modules/client/client-service.js +21 -3
  45. package/dist/server/modules/client/client-service.js.map +1 -1
  46. package/dist/server/modules/relay-tunnel/relay-tunnel-service.d.ts +2 -1
  47. package/dist/server/modules/relay-tunnel/relay-tunnel-service.js +203 -8
  48. package/dist/server/modules/relay-tunnel/relay-tunnel-service.js.map +1 -1
  49. package/dist/server/modules/workbench/snapshot-revision.d.ts +4 -0
  50. package/dist/server/modules/workbench/snapshot-revision.js +13 -0
  51. package/dist/server/modules/workbench/snapshot-revision.js.map +1 -0
  52. package/dist/server/modules/workbench/workbench-service.d.ts +1 -0
  53. package/dist/server/modules/workbench/workbench-service.js +3 -2
  54. package/dist/server/modules/workbench/workbench-service.js.map +1 -1
  55. package/dist/server/modules/workbench/workspace-panel-snapshot-service.d.ts +6 -1
  56. package/dist/server/modules/workbench/workspace-panel-snapshot-service.js +10 -8
  57. package/dist/server/modules/workbench/workspace-panel-snapshot-service.js.map +1 -1
  58. package/dist/server/server/create-server.js +1 -1
  59. package/dist/server/server/create-server.js.map +1 -1
  60. package/dist/server/types/domain.d.ts +9 -0
  61. package/dist/server/ws/workbench-ws-hub.js +135 -33
  62. package/dist/server/ws/workbench-ws-hub.js.map +1 -1
  63. package/package.json +1 -1
  64. package/dist/public/assets/AdaptiveButlerPage-R-XZw7pd.js +0 -3
  65. package/dist/public/assets/App-DkvE5EyM.js +0 -30
  66. package/dist/public/assets/FileContextPanel-D_ghXJuW.js +0 -1
  67. package/dist/public/assets/GitSidebar-D9f9Jxwr.js +0 -6
  68. package/dist/public/assets/MobileSheet-DLg-gX1t.js +0 -1
  69. package/dist/public/assets/SettingsPage-HJIC-P-4.js +0 -1
  70. package/dist/public/assets/TerminalManagerPanel-DpyUTo9k.js +0 -1
  71. package/dist/public/assets/WorkbenchLayout-ByFw4eeu.js +0 -3
  72. package/dist/public/assets/WorkbenchShellRoute-BUITtdAg.css +0 -1
  73. package/dist/public/assets/WorkbenchShellRoute-Kw7JEZI3.js +0 -1
  74. package/dist/public/assets/WorkspaceDetailPage-D0Lrx4Uz.js +0 -1
  75. package/dist/public/assets/WorkspaceHomePage-wR8d3aP9.js +0 -1
  76. package/dist/public/assets/index-Byp9hJ0c.js +0 -42
@@ -0,0 +1,3 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/FileContextPanel-C8T7oqRN.js","assets/index-C2G8Gmf1.js","assets/index-CpPTUeA3.css","assets/App-WOLwMld_.js","assets/App-DUAg5urj.css","assets/MobileSheet-Gzc14EpR.js","assets/WorkbenchModal-B09hC9b5.js","assets/file-tree-icon-Dp_xhVfD.js","assets/window-BWqRixxq.js","assets/event-DvH9tcej.js","assets/GitSidebar-Bze7DNnc.js","assets/default-session-permission-mode-D0wZ9Jek.js","assets/TerminalManagerPanel-PQ-EM64j.js","assets/terminal-runtime-meta-BMT-rSEe.js","assets/TerminalRuntimeFallbackModal-D7Aq186N.js"])))=>i.map(i=>d[i]);
2
+ var Zl=Object.defineProperty;var Ql=(e,n,s)=>n in e?Zl(e,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[n]=s;var ye=(e,n,s)=>Ql(e,typeof n!="symbol"?n+"":n,s);import{B as Z,t as r,b as l,j as t,e as nn,l as Zs,E as Pa,F as ec,C as tc,G as nc,v as Wa,A as Aa,o as Zr,H as sc,J as rc,K as Ba,i as La,L as Ri,f as Oi,h as Da,M as ic,k as _a,x as oc,n as ac,y as lc,_ as Hi}from"./index-C2G8Gmf1.js";import{m as Se,d as Tn,g as Qr,u as er,f as tr,e as Xn,h as cc,i as dc,O as mo}from"./App-WOLwMld_.js";import{e as Ui,l as uc,m as hc,$ as Fa,a0 as fc,M as mc,i as pc,j as bc,a1 as kc,a2 as gc,u as Er,g as wc,a3 as xc,a4 as vc,a5 as yc,a6 as Oa,a7 as Sc,a8 as Ha,a9 as jc,aa as Nc,ab as Ua,H as Cc,a as Tc,o as Ic,S as Rc,n as $a,P as Mc,r as Ec,ac as Pc}from"./MobileSheet-Gzc14EpR.js";import{t as gs,P as Xr,g as qa}from"./window-BWqRixxq.js";import{R as Wc,_ as po,a as bo,C as Ga,i as ie}from"./event-DvH9tcej.js";import{W as $e}from"./WorkbenchModal-B09hC9b5.js";const Gs=new Map;function za(){return typeof window<"u"&&typeof window.sessionStorage<"u"}function ko(e,n){return!Number.isFinite(e)||Date.now()-e>n}function Yr(e,n){const s=Gs.get(e);if(s&&!ko(s.savedAt,n))return s.value;if(!za())return null;const i=window.sessionStorage.getItem(e);if(!i)return null;try{const o=JSON.parse(i);return!o||ko(o.savedAt,n)?(window.sessionStorage.removeItem(e),Gs.delete(e),null):(Gs.set(e,o),o.value)}catch{return window.sessionStorage.removeItem(e),Gs.delete(e),null}}function Ys(e,n){const s={savedAt:Date.now(),value:n};if(Gs.set(e,s),!!za())try{window.sessionStorage.setItem(e,JSON.stringify(s))}catch{}}const Ac="codingns.debug.perf";function Bc(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(Ac)==="1"}catch{return!1}}function gt(e,n){if(!Bc()||typeof performance>"u")return;const s=Math.round(performance.now());if(n&&Object.keys(n).length>0){console.info(`[perf-ui] ${e} ${s}ms`,n);return}console.info(`[perf-ui] ${e} ${s}ms`)}function em(e,n,s,i){return Z.request("/api/files/content",{method:"PUT",body:JSON.stringify({workspaceId:e,path:n,content:s,expectedVersion:i??void 0})})}function tm(e){return Z.request("/api/files/ops",{method:"POST",body:JSON.stringify(e)})}function nm(e){return Z.request("/api/files/upload",{method:"POST",body:JSON.stringify(e)})}function sm(e,n){const s=new URLSearchParams({workspaceId:e,path:n});return Z.request(`/api/files/download?${s.toString()}`)}function Lc(e,n,s=1,i=20){const o=new URLSearchParams({workspaceId:e,keyword:n,page:String(s),pageSize:String(i)});return Z.request(`/api/files/search?${o.toString()}`)}function rm(e,n){const s=new URLSearchParams({workspaceId:e,path:n});return Z.request(`/api/files/preview?${s.toString()}`)}function im(e){return Z.request(`/api/git/status?workspaceId=${encodeURIComponent(e)}`)}function om(e,n,s){const i=new URLSearchParams({workspaceId:e,path:n,staged:String(s)});return Z.request(`/api/git/diff?${i.toString()}`)}function am(e,n){return Z.request("/api/git/stage",{method:"POST",body:JSON.stringify({workspaceId:e,targets:n})})}function lm(e,n){return Z.request("/api/git/unstage",{method:"POST",body:JSON.stringify({workspaceId:e,targets:n})})}function cm(e,n){return Z.request("/api/git/discard",{method:"POST",body:JSON.stringify({workspaceId:e,targets:n})})}function dm(e,n){return Z.request("/api/git/commit/draft",{method:"POST",body:JSON.stringify({workspaceId:e,mode:n})})}function um(e,n){return Z.request("/api/git/commit",{method:"POST",body:JSON.stringify({workspaceId:e,draft:n})})}function hm(e){return Z.request("/api/git/commit/undo",{method:"POST",body:JSON.stringify({workspaceId:e})})}function fm(e,n=5,s=null){const i=new URLSearchParams({workspaceId:e,limit:String(n)});return s&&i.set("cursor",s),Z.request(`/api/git/history?${i.toString()}`)}function mm(e,n){const s=new URLSearchParams({workspaceId:e,commitHash:n});return Z.request(`/api/git/commit-detail?${s.toString()}`)}function Dc(e){return Z.request(`/api/git/branches?workspaceId=${encodeURIComponent(e)}`)}function _c(e){return Z.request(`/api/git/tags?workspaceId=${encodeURIComponent(e)}`)}function pm(e,n,s){return Z.request("/api/git/branches/switch",{method:"POST",body:JSON.stringify({workspaceId:e,branchName:n,create:s})})}function bm(e,n,s,i,o){return Z.request("/api/git/remote/sync",{method:"POST",body:JSON.stringify({workspaceId:e,action:n,...s?{remote:s}:{},...i?{auth:i}:{},...o?{remember:o}:{}})})}function km(e){return Z.request(`/api/git/remotes?workspaceId=${encodeURIComponent(e)}`)}var zr,Kr;function Ka(e){var n;if("items"in e)e.items=(n=e.items)===null||n===void 0?void 0:n.map(s=>"rid"in s?s:Ka(s));else if("action"in e&&e.action){const s=new Ga;return s.onmessage=e.action,delete e.action,{...e,handler:s}}return e}async function ys(e,n){const s=new Ga;if(n&&typeof n=="object"&&("action"in n&&n.action&&(s.onmessage=n.action,delete n.action),"item"in n&&n.item&&typeof n.item=="object"&&"About"in n.item&&n.item.About&&typeof n.item.About=="object"&&"icon"in n.item.About&&n.item.About.icon&&(n.item.About.icon=gs(n.item.About.icon)),"icon"in n&&n.icon&&(n.icon=gs(n.icon)),"items"in n&&n.items)){let i=function(o){var c;return"rid"in o?[o.rid,o.kind]:("item"in o&&typeof o.item=="object"&&(!((c=o.item.About)===null||c===void 0)&&c.icon)&&(o.item.About.icon=gs(o.item.About.icon)),"icon"in o&&o.icon&&(o.icon=gs(o.icon)),"items"in o&&o.items&&(o.items=o.items.map(i)),Ka(o))};n.items=n.items.map(i)}return ie("plugin:menu|new",{kind:e,options:n,handler:s})}class Ss extends Wc{get id(){return po(this,zr,"f")}get kind(){return po(this,Kr,"f")}constructor(n,s,i){super(n),zr.set(this,void 0),Kr.set(this,void 0),bo(this,zr,s),bo(this,Kr,i)}}zr=new WeakMap,Kr=new WeakMap;class $i extends Ss{constructor(n,s){super(n,s,"MenuItem")}static async new(n){return ys("MenuItem",n).then(([s,i])=>new $i(s,i))}async text(){return ie("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(n){return ie("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:n})}async isEnabled(){return ie("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(n){return ie("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:n})}async setAccelerator(n){return ie("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:n})}}class qi extends Ss{constructor(n,s){super(n,s,"Check")}static async new(n){return ys("Check",n).then(([s,i])=>new qi(s,i))}async text(){return ie("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(n){return ie("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:n})}async isEnabled(){return ie("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(n){return ie("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:n})}async setAccelerator(n){return ie("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:n})}async isChecked(){return ie("plugin:menu|is_checked",{rid:this.rid})}async setChecked(n){return ie("plugin:menu|set_checked",{rid:this.rid,checked:n})}}var go;(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"})(go||(go={}));class Gi extends Ss{constructor(n,s){super(n,s,"Icon")}static async new(n){return ys("Icon",n).then(([s,i])=>new Gi(s,i))}async text(){return ie("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(n){return ie("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:n})}async isEnabled(){return ie("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(n){return ie("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:n})}async setAccelerator(n){return ie("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:n})}async setIcon(n){return ie("plugin:menu|set_icon",{rid:this.rid,kind:this.kind,icon:gs(n)})}}class zi extends Ss{constructor(n,s){super(n,s,"Predefined")}static async new(n){return ys("Predefined",n).then(([s,i])=>new zi(s,i))}async text(){return ie("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(n){return ie("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:n})}}function vs([e,n,s]){switch(s){case"Submenu":return new Ki(e,n);case"Predefined":return new zi(e,n);case"Check":return new qi(e,n);case"Icon":return new Gi(e,n);case"MenuItem":default:return new $i(e,n)}}class Ki extends Ss{constructor(n,s){super(n,s,"Submenu")}static async new(n){return ys("Submenu",n).then(([s,i])=>new Ki(s,i))}async text(){return ie("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(n){return ie("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:n})}async isEnabled(){return ie("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(n){return ie("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:n})}async append(n){return ie("plugin:menu|append",{rid:this.rid,kind:this.kind,items:(Array.isArray(n)?n:[n]).map(s=>"rid"in s?[s.rid,s.kind]:s)})}async prepend(n){return ie("plugin:menu|prepend",{rid:this.rid,kind:this.kind,items:(Array.isArray(n)?n:[n]).map(s=>"rid"in s?[s.rid,s.kind]:s)})}async insert(n,s){return ie("plugin:menu|insert",{rid:this.rid,kind:this.kind,items:(Array.isArray(n)?n:[n]).map(i=>"rid"in i?[i.rid,i.kind]:i),position:s})}async remove(n){return ie("plugin:menu|remove",{rid:this.rid,kind:this.kind,item:[n.rid,n.kind]})}async removeAt(n){return ie("plugin:menu|remove_at",{rid:this.rid,kind:this.kind,position:n}).then(vs)}async items(){return ie("plugin:menu|items",{rid:this.rid,kind:this.kind}).then(n=>n.map(vs))}async get(n){return ie("plugin:menu|get",{rid:this.rid,kind:this.kind,id:n}).then(s=>s?vs(s):null)}async popup(n,s){var i;return ie("plugin:menu|popup",{rid:this.rid,kind:this.kind,window:(i=s==null?void 0:s.label)!==null&&i!==void 0?i:null,at:n instanceof Xr?n:n?new Xr(n):null})}async setAsWindowsMenuForNSApp(){return ie("plugin:menu|set_as_windows_menu_for_nsapp",{rid:this.rid})}async setAsHelpMenuForNSApp(){return ie("plugin:menu|set_as_help_menu_for_nsapp",{rid:this.rid})}async setIcon(n){return ie("plugin:menu|set_icon",{rid:this.rid,kind:this.kind,icon:gs(n)})}}class ws extends Ss{constructor(n,s){super(n,s,"Menu")}static async new(n){return ys("Menu",n).then(([s,i])=>new ws(s,i))}static async default(){return ie("plugin:menu|create_default").then(([n,s])=>new ws(n,s))}async append(n){return ie("plugin:menu|append",{rid:this.rid,kind:this.kind,items:(Array.isArray(n)?n:[n]).map(s=>"rid"in s?[s.rid,s.kind]:s)})}async prepend(n){return ie("plugin:menu|prepend",{rid:this.rid,kind:this.kind,items:(Array.isArray(n)?n:[n]).map(s=>"rid"in s?[s.rid,s.kind]:s)})}async insert(n,s){return ie("plugin:menu|insert",{rid:this.rid,kind:this.kind,items:(Array.isArray(n)?n:[n]).map(i=>"rid"in i?[i.rid,i.kind]:i),position:s})}async remove(n){return ie("plugin:menu|remove",{rid:this.rid,kind:this.kind,item:[n.rid,n.kind]})}async removeAt(n){return ie("plugin:menu|remove_at",{rid:this.rid,kind:this.kind,position:n}).then(vs)}async items(){return ie("plugin:menu|items",{rid:this.rid,kind:this.kind}).then(n=>n.map(vs))}async get(n){return ie("plugin:menu|get",{rid:this.rid,kind:this.kind,id:n}).then(s=>s?vs(s):null)}async popup(n,s){var i;return ie("plugin:menu|popup",{rid:this.rid,kind:this.kind,window:(i=s==null?void 0:s.label)!==null&&i!==void 0?i:null,at:n instanceof Xr?n:n?new Xr(n):null})}async setAsAppMenu(){return ie("plugin:menu|set_as_app_menu",{rid:this.rid}).then(n=>n?new ws(n[0],n[1]):null)}async setAsWindowMenu(n){var s;return ie("plugin:menu|set_as_window_menu",{rid:this.rid,window:(s=n==null?void 0:n.label)!==null&&s!==void 0?s:null}).then(i=>i?new ws(i[0],i[1]):null)}}async function Fc(e){if(e.length===0)return;await(await ws.new({items:e.map(s=>({id:s.id,text:s.label,enabled:!s.disabled,accelerator:s.accelerator,action:()=>{s.onSelect()}}))})).popup(void 0,qa())}function Va(e,n){const s=new Map(e.map(c=>[n.getId(c),c])),i=new Map,o=[];for(const c of e){const h=Oc(c,s,n);if(!h){o.push(c);continue}const f=i.get(h)??[];i.set(h,[...f,c])}return[...o].sort(n.compare).map(c=>Ja(c,0,i,n,new Set))}function js(e){return Array.isArray(e==null?void 0:e.children)?e.children:[]}function Xa(e){return e.flatMap(n=>[n.item,...Xa(js(n))])}function Sn(e){return e.flatMap(n=>[n,...Sn(js(n))])}function Vi(e,n){return e.some(s=>n(s.item)||Vi(js(s),n))}function Ya(e,n,s){return e?s(e.item)===n?!0:js(e).some(i=>Ya(i,n,s)):!1}function ks(e,n,s){for(const i of e){const o=s(i.item);if(o===n)return[];const c=ks(js(i),n,s);if(Ya(i,n,s)&&c.length>=0)return[o,...c]}return[]}function Ja(e,n,s,i,o){const c=i.getId(e),h=new Set(o);h.add(c);const f=[...s.get(c)??[]].filter(k=>!h.has(i.getId(k))).sort(i.compare).map(k=>Ja(k,n+1,s,i,h));return{item:e,depth:n,children:f}}function Oc(e,n,s){const i=wo(s.getParentId(e));if(!i)return null;const o=n.get(i);if(!o)return null;const c=new Set([s.getId(e)]);let h=o;for(;h;){const f=s.getId(h);if(c.has(f))return null;c.add(f);const k=wo(s.getParentId(h));if(!k||(h=n.get(k),!h))return i}return i}function wo(e){const n=e==null?void 0:e.trim();return n||null}function at(){return"/workspaces"}function Gt(e){return`/workspaces/${encodeURIComponent(e)}`}function Za(e){return`${Gt(e)}/debug`}function Qs(e){return`${Gt(e)}/sessions`}function $t(e,n){return`${Qs(e)}/${encodeURIComponent(n)}`}function Qa(e,n){const s=`${Gt(e)}/tools`;if(!n)return s;const i=new URLSearchParams({tab:n});return`${s}?${i.toString()}`}function el(e){return`${Gt(e)}/tools/files`}function tl(e){return`${Gt(e)}/tools/git`}function nl(e){return`${Gt(e)}/tools/processes`}function xs(e){return`${Gt(e)}/terminals`}function Vn(e,n){const s=`${Gt(e)}/butler`;if(!n)return s;const i=new URLSearchParams({tab:n});return`${s}?${i.toString()}`}function Hc(e){return e.flatMap(n=>[...n.sessions.map(s=>({session:s,workspace:n.workspace})),...rl(n.childWorktrees??[])]).sort((n,s)=>(s.session.lastMessageAt??s.session.updatedAt).localeCompare(n.session.lastMessageAt??n.session.updatedAt))}function gm(e){return Va(e,{getId:n=>n.session.sessionId,getParentId:n=>{var s;return((s=n.session.parentSessionId)==null?void 0:s.trim())||null},compare:$c})}function sl(e,n){const s=Uc(),i=new URLSearchParams({provider:n});return`${$t(e,s)}?${i.toString()}`}function Uc(){const e=globalThis.crypto;return e&&typeof e.randomUUID=="function"?`draft-${e.randomUUID()}`:`draft-${Date.now()}-${Math.random().toString(16).slice(2)}`}function $c(e,n){return(n.session.lastMessageAt??n.session.updatedAt).localeCompare(e.session.lastMessageAt??e.session.updatedAt)}function rl(e){return e.flatMap(n=>[...n.sessions.map(s=>({session:s,workspace:n.workspace})),...rl(n.children)])}const qc="mobile.tools.last-primary-tool";function il(){if(typeof window>"u")return"files";try{return window.localStorage.getItem(qc)==="git"?"git":"files"}catch{return"files"}}function Xi(e){var i;const n=[{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 o of n){const c=Se(o.pattern,e),h=((i=c==null?void 0:c.params.workspaceId)==null?void 0:i.trim())??null;if(h)return{workspaceId:h,routeKind:o.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 o of s)if(Se(o.pattern,e))return{workspaceId:null,routeKind:o.routeKind,legacy:!0};return null}function Gc(e,n){const s=Xi(e);if((s==null?void 0:s.routeKind)==="git")return"git";if((s==null?void 0:s.routeKind)==="files")return"files";const i=new URLSearchParams(n).get("tab");return i==="git"?"git":i==="files"?"files":il()}function Yi(e,n){const s=Xi(e);return(s==null?void 0:s.routeKind)==="processes"&&s.workspaceId?xs(s.workspaceId):s!=null&&s.workspaceId?Qa(s.workspaceId,Gc(e,n)):s!=null&&s.legacy?il()==="git"?"/tools?tab=git":"/tools?tab=files":null}function Ji({activeEntry:e,presentation:n,pathname:s,search:i,moreButtonLabel:o}){if(n==="conversation-focus"||e!=="butler")return null;const c=Xi(s);return c?c.routeKind==="processes"?{title:r("shell.terminalManagerEntry"),showBackButton:!0,showMoreButton:!1,moreButtonLabel:o}:(c.routeKind==="home"||c.routeKind==="files"||c.routeKind==="git",null):null}const ol=l.createContext({composerPortalTarget:null});function Zi({composerPortalTarget:e,children:n}){return t.jsx(ol.Provider,{value:{composerPortalTarget:e},children:n})}function wm(){return l.useContext(ol)}function Qi(e,n,s){const[i,o]=l.useState(void 0);return l.useEffect(()=>{const c=e.current,h=n.current;if(!s||!c||!h){o(void 0),c&&c.style.removeProperty("--mobile-conversation-tabbar-height");return}const f=c,k=h;function p(){if(!e.current||!k.isConnected)return;const N=`${Math.round(k.getBoundingClientRect().height)}px`;f.style.setProperty("--mobile-conversation-tabbar-height",N),o(N)}p();const w=typeof ResizeObserver<"u"?new ResizeObserver(p):null;return w==null||w.observe(k),window.addEventListener("resize",p),()=>{w==null||w.disconnect(),window.removeEventListener("resize",p),f.style.removeProperty("--mobile-conversation-tabbar-height")}},[s,e,n]),i}const zc=3e3,Pr=10,xo=84,vo=.36;function eo({enabled:e,rootRef:n,suspended:s=!1,resetKey:i}){const o=l.useRef(null),c=l.useRef(null),h=l.useRef("visible"),f=l.useRef(1),[k,p]=l.useState("visible"),[w,N]=l.useState(1);l.useEffect(()=>{h.current=k},[k]),l.useEffect(()=>{f.current=w},[w]);function C(){zn(o),o.current=window.setTimeout(()=>{R()},zc)}function R(){p("hidden"),N(0)}function O(){p("visible"),N(1),C()}l.useEffect(()=>{if(zn(o),!e){zn(o),p("visible"),N(1);return}if(s){p("hidden"),N(0);return}return O(),()=>{zn(o)}},[e,i,s]),l.useEffect(()=>()=>{zn(o)},[]),l.useEffect(()=>{if(!e||s){c.current=null;return}const W=n.current;if(!W)return;function x(q){if(q.touches.length!==1){c.current=null;return}const j=q.touches[0],J=jo(q.target);if(!j||!J){c.current=null;return}c.current={surface:J,startX:j.clientX,startY:j.clientY,pointerType:"touch",initialState:h.current==="visible"?"visible":"hidden",touchId:j.identifier,dragging:!1,latestProgress:f.current},h.current==="visible"&&zn(o)}function A(q){const j=c.current;if(!j||j.pointerType!=="touch")return;const J=pi(q.touches,j.touchId);if(!J)return;const Q=J.clientX-j.startX,E=J.clientY-j.startY;if(j.surface==="conversation"){if(Math.abs(E)<=Pr||Math.abs(E)<=Math.abs(Q))return;c.current=null,j.initialState==="visible"&&R();return}const ue=j.initialState==="hidden"?-E:E;ue<=Pr&&!j.dragging||(Co(q),j.dragging=!0,j.latestProgress=yo(j.initialState,ue),p("dragging"),N(j.latestProgress))}function I(q){const j=c.current;if(!(!j||j.pointerType!=="touch"||!pi(q.changedTouches,j.touchId))){if(c.current=null,!j.dragging){j.initialState==="visible"&&C();return}So(j.initialState,j.latestProgress,O,p,N)}}function G(q){const j=c.current;if(!(!j||j.pointerType!=="touch"||!pi(q.changedTouches,j.touchId))){if(c.current=null,!j.dragging){j.initialState==="visible"&&C();return}if(j.initialState==="visible"){O();return}p("hidden"),N(0)}}function K(q){if(q.pointerType!=="touch")return;const j=jo(q.target);if(!j){c.current=null;return}if(c.current={surface:j,startX:q.clientX,startY:q.clientY,pointerType:"pointer",initialState:h.current==="visible"?"visible":"hidden",pointerId:q.pointerId,captureTarget:q.target instanceof Element?q.target:null,dragging:!1,latestProgress:f.current},q.target instanceof Element)try{q.target.setPointerCapture(q.pointerId)}catch{}h.current==="visible"&&zn(o)}function Y(q){const j=c.current;if(!j||j.pointerType!=="pointer")return;const J=q.clientX-j.startX,Q=q.clientY-j.startY;if(j.surface==="conversation"){if(Math.abs(Q)<=Pr||Math.abs(Q)<=Math.abs(J))return;c.current=null,j.initialState==="visible"&&R();return}const E=j.initialState==="hidden"?-Q:Q;E<=Pr&&!j.dragging||(Co(q),j.dragging=!0,j.latestProgress=yo(j.initialState,E),p("dragging"),N(j.latestProgress))}function z(q){const j=c.current;if(!(!j||j.pointerType!=="pointer"||j.pointerId!==q.pointerId)){if(c.current=null,Kc(j),!j.dragging){j.initialState==="visible"&&C();return}So(j.initialState,j.latestProgress,O,p,N)}}return W.addEventListener("touchstart",x,{passive:!0}),W.addEventListener("pointerdown",K,{passive:!0}),window.addEventListener("touchmove",A,{passive:!1}),window.addEventListener("touchend",I),window.addEventListener("touchcancel",G),window.addEventListener("pointermove",Y,{passive:!1}),window.addEventListener("pointerup",z),window.addEventListener("pointercancel",z),()=>{W.removeEventListener("touchstart",x),W.removeEventListener("pointerdown",K),window.removeEventListener("touchmove",A),window.removeEventListener("touchend",I),window.removeEventListener("touchcancel",G),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",z),window.removeEventListener("pointercancel",z)}},[e,n,s]);const H=e&&!s?w:e?0:1;return{state:s&&e?"hidden":k,progress:H,isOpen:H>.01}}function zn(e){e.current!==null&&(window.clearTimeout(e.current),e.current=null)}function yo(e,n){return No(e==="hidden"?n/xo:1-n/xo,0,1)}function So(e,n,s,i,o){if(e==="hidden"){if(n>=vo){s();return}i("hidden"),o(0);return}if(n<=1-vo){i("hidden"),o(0);return}s()}function Kc(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 pi(e,n){if(typeof n!="number")return e[0]??null;for(let s=0;s<e.length;s+=1){const i=e[s];if((i==null?void 0:i.identifier)===n)return i}return null}function jo(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 No(e,n,s){return Math.min(Math.max(e,n),s)}function Co(e){e.cancelable&&e.preventDefault()}function nr({viewportClass:e,activeEntry:n,hasNavigationPanel:s,hasAuxiliaryPanel:i,preferCompactLayout:o=!1}){return o||e==="compact"?"compact":e==="expanded"&&s&&i?"expanded":n==="butler"&&i?"medium-auxiliary":s?"medium-navigation":i?"medium-auxiliary":"compact"}function ei(e){return!e.isNativeMobile||e.viewportClass==="expanded"||typeof window>"u"?!1:window.innerHeight>window.innerWidth}function al(e){return e==="medium-navigation"||e==="expanded"}function ll(e){return e==="medium-auxiliary"||e==="expanded"}function to({viewportClass:e,activeEntry:n,hasNavigationPanel:s,hasAuxiliaryPanel:i,preferCompactLayout:o=!1,children:c,navigationPanel:h,auxiliaryPanel:f}){const k=nr({viewportClass:e,activeEntry:n,hasNavigationPanel:s,hasAuxiliaryPanel:i,preferCompactLayout:o}),p=al(k)&&h,w=ll(k)&&f;return t.jsxs("div",{className:"mobile-adaptive-pane-layout","data-pane-layout":k,children:[p?t.jsx("aside",{className:"workbench-nav surface-card mobile-adaptive-pane-panel mobile-adaptive-pane-panel-navigation",children:h}):null,t.jsx("div",{className:"mobile-adaptive-pane-main",children:c}),w?t.jsx("aside",{className:"workbench-auxiliary surface-card mobile-adaptive-pane-panel mobile-adaptive-pane-panel-auxiliary",children:f}):null]})}function Vc({activeEntry:e,presentation:n="default",children:s,navigationPanel:i,auxiliaryPanel:o,onNavigateWorkspaces:c,onNavigateTerminals:h,onNavigateSessions:f,onNavigateButler:k,onNavigateToolProcesses:p,onNavigateSettings:w}){const N=Tn(),C=Ui(),R=Qr(),O=er(),H=l.useRef(null),W=l.useRef(null),[x,A]=l.useState(null),I=n==="conversation-focus",G=ei({isNativeMobile:N.isNativeMobile,viewportClass:N.viewportClass}),K=eo({enabled:I,rootRef:H,resetKey:`${R.pathname}${R.search}`}),Y=nr({viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!i,hasAuxiliaryPanel:!!o,preferCompactLayout:G}),z=Ji({activeEntry:e,presentation:n,pathname:R.pathname,search:R.search,moreButtonLabel:r("shell.androidMoreAction")}),q=[{key:"workspaces",label:r("shell.mobileWorkspacesEntry"),icon:t.jsx(Jc,{}),onClick:c},{key:"sessions",label:r("shell.mobileSessionsEntry"),icon:t.jsx(Zc,{}),onClick:f},{key:"terminals",label:r("shell.mobileButlerEntry"),icon:t.jsx(ed,{}),onClick:k},{key:"butler",label:r("shell.mobileTerminalsEntry"),icon:t.jsx(Qc,{}),onClick:h},{key:"settings",label:r("shell.mobileSettingsEntry"),icon:t.jsx(td,{}),onClick:w}],j=I?{"--mobile-conversation-tabbar-progress":K.progress.toFixed(4)}:void 0;Qi(H,W,I);function J(){const E=Yi(R.pathname,R.search);if(!E){h();return}O(E,{replace:!0})}const Q=t.jsx("nav",{ref:W,className:"android-workbench-bottom-nav","aria-label":r("shell.title"),children:q.map(E=>t.jsxs("button",{type:"button",className:"android-workbench-bottom-nav-item","data-active":E.key===e,"aria-current":E.key===e?"page":void 0,onClick:()=>{E.key!==e&&C.trigger("selection"),E.onClick()},children:[t.jsx("span",{className:"android-workbench-bottom-nav-icon","aria-hidden":"true",children:E.icon}),t.jsx("span",{className:"android-workbench-bottom-nav-label",children:E.label})]},E.key))});return t.jsx(Zi,{composerPortalTarget:I?x:null,children:t.jsxs("div",{ref:H,className:"android-workbench-shell","data-active-entry":e,"data-mobile-presentation":n,"data-pane-layout":Y,"data-tabbar-open":I?K.isOpen:!0,"data-conversation-tabbar-state":I?K.state:"default",style:j,children:[z?t.jsxs("header",{className:"android-workbench-topbar","data-header-kind":"tools",children:[t.jsxs("div",{className:"android-workbench-topbar-leading",children:[z.showBackButton?t.jsx("button",{type:"button",className:"android-workbench-icon-button","aria-label":r("common.back"),onClick:J,children:t.jsx(Xc,{})}):null,t.jsx("div",{className:"android-workbench-topbar-copy",children:t.jsx("h1",{children:z.title})})]}),t.jsx("div",{className:"android-workbench-topbar-actions",children:z.showMoreButton?t.jsx("button",{type:"button",className:"android-workbench-icon-button","aria-label":z.moreButtonLabel,onClick:p,children:t.jsx(Yc,{})}):null})]}):null,t.jsx("div",{className:"android-workbench-content",children:t.jsx(to,{viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!i,hasAuxiliaryPanel:!!o,preferCompactLayout:G,navigationPanel:i,auxiliaryPanel:o,children:s})}),I?t.jsxs("div",{className:"mobile-conversation-bottom-layer",children:[t.jsx("div",{ref:A,className:"mobile-conversation-bottom-layer-composer-slot"}),t.jsx("div",{className:"mobile-conversation-bottom-layer-tabbar-shell",children:Q})]}):Q]})})}function Xc(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("path",{d:"m15 18-6-6 6-6"}),t.jsx("path",{d:"M21 12H9"})]})}function Yc(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[t.jsx("circle",{cx:"12",cy:"5",r:"1.8"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.8"}),t.jsx("circle",{cx:"12",cy:"19",r:"1.8"})]})}function Jc(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.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"}),t.jsx("path",{d:"M8 13h8"})]})}function Zc(){return t.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t.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 Qc(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),t.jsx("path",{d:"m7.5 9 3 3-3 3"}),t.jsx("path",{d:"M12.5 15H17"})]})}function ed(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("rect",{x:"5",y:"7",width:"14",height:"10",rx:"3"}),t.jsx("path",{d:"M9 7V5a3 3 0 0 1 6 0v2"}),t.jsx("circle",{cx:"10",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),t.jsx("circle",{cx:"14",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),t.jsx("path",{d:"M10 15c.6.5 1.2.8 2 .8s1.4-.3 2-.8"})]})}function td(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.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 nd=120,zs={viewportHeight:null,keyboardInset:0,keyboardOpen:!1};function Mi(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function sd(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 n=(e.type||"text").toLowerCase();return!["button","checkbox","color","file","hidden","image","radio","range","reset","submit"].includes(n)}return!1}function rd(){var n;if(typeof window>"u")return 0;const e=[window.innerHeight,typeof document<"u"?(n=document.documentElement)==null?void 0:n.clientHeight:0].filter(Mi);return e.length>0?Math.max(...e):0}function To(){if(typeof window>"u")return zs;const e=window.visualViewport,n=rd(),s=(e==null?void 0:e.height)??n,i=Mi(s)?Math.round(s):null,o=Mi(e==null?void 0:e.offsetTop)?(e==null?void 0:e.offsetTop)??0:0,c=i===null?0:Math.max(0,Math.round(n-i-o));return{viewportHeight:i,keyboardInset:c,keyboardOpen:sd(typeof document<"u"?document.activeElement:null)&&c>=nd}}function bi(e,n){if(typeof document>"u")return;[document.documentElement,document.body].filter(i=>i instanceof HTMLElement).forEach(i=>{if(!e){delete i.dataset.mobileKeyboardOpen,delete i.dataset.mobileViewportBound,i.style.removeProperty("--mobile-shell-viewport-height"),i.style.removeProperty("--mobile-shell-keyboard-inset");return}i.dataset.mobileKeyboardOpen=String(n.keyboardOpen),i.dataset.mobileViewportBound="true",n.viewportHeight===null?i.style.removeProperty("--mobile-shell-viewport-height"):i.style.setProperty("--mobile-shell-viewport-height",`${n.viewportHeight}px`),i.style.setProperty("--mobile-shell-keyboard-inset",`${n.keyboardInset}px`)})}function id(e){const[n,s]=l.useState(()=>e?To():zs),i=l.useRef(null);return l.useEffect(()=>{if(!e){s(zs),bi(!1,zs);return}function o(){s(To())}function c(){i.current!==null&&window.clearTimeout(i.current),i.current=window.setTimeout(()=>{i.current=null,o()},0)}o();const h=window.visualViewport;return window.addEventListener("resize",o),window.addEventListener("orientationchange",o),h==null||h.addEventListener("resize",o),h==null||h.addEventListener("scroll",o),document.addEventListener("focusin",o),document.addEventListener("focusout",c),()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null),window.removeEventListener("resize",o),window.removeEventListener("orientationchange",o),h==null||h.removeEventListener("resize",o),h==null||h.removeEventListener("scroll",o),document.removeEventListener("focusin",o),document.removeEventListener("focusout",c),bi(!1,zs)}},[e]),l.useEffect(()=>{bi(e,n)},[e,n]),n}function od({activeEntry:e,presentation:n="default",children:s,navigationPanel:i,auxiliaryPanel:o,onNavigateWorkspaces:c,onNavigateTerminals:h,onNavigateSessions:f,onNavigateButler:k,onNavigateToolProcesses:p,onNavigateSettings:w}){const N=Tn(),C=Ui(),R=Qr(),O=er(),H=l.useRef(null),W=l.useRef(null),[x,A]=l.useState(null),I=n==="conversation-focus",G=ei({isNativeMobile:N.isNativeMobile,viewportClass:N.viewportClass}),K=eo({enabled:I,rootRef:H,resetKey:`${R.pathname}${R.search}`}),Y=nr({viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!i,hasAuxiliaryPanel:!!o,preferCompactLayout:G}),z=Ji({activeEntry:e,presentation:n,pathname:R.pathname,search:R.search,moreButtonLabel:r("shell.iosMoreAction")}),q=[{key:"workspaces",label:r("shell.mobileWorkspacesEntry"),icon:t.jsx(cd,{}),onClick:c},{key:"sessions",label:r("shell.mobileSessionsEntry"),icon:t.jsx(dd,{}),onClick:f},{key:"terminals",label:r("shell.mobileButlerEntry"),icon:t.jsx(hd,{}),onClick:k},{key:"butler",label:r("shell.mobileTerminalsEntry"),icon:t.jsx(ud,{}),onClick:h},{key:"settings",label:r("shell.mobileSettingsEntry"),icon:t.jsx(fd,{}),onClick:w}],j=I?{"--mobile-conversation-tabbar-progress":K.progress.toFixed(4)}:void 0;Qi(H,W,I);function J(){const E=Yi(R.pathname,R.search);if(!E){h();return}O(E,{replace:!0})}const Q=t.jsx("nav",{ref:W,className:"ios-workbench-tabbar","aria-label":r("shell.title"),children:q.map(E=>t.jsxs("button",{type:"button",className:"ios-workbench-tabbar-item","data-active":E.key===e,"aria-current":E.key===e?"page":void 0,onClick:()=>{E.key!==e&&C.trigger("selection"),E.onClick()},children:[t.jsx("span",{className:"ios-workbench-tabbar-icon","aria-hidden":"true",children:E.icon}),t.jsx("span",{className:"ios-workbench-tabbar-label",children:E.label})]},E.key))});return t.jsx(Zi,{composerPortalTarget:I?x:null,children:t.jsxs("div",{ref:H,className:"ios-workbench-shell","data-active-entry":e,"data-mobile-presentation":n,"data-pane-layout":Y,"data-tabbar-open":I?K.isOpen:!0,"data-conversation-tabbar-state":I?K.state:"default",style:j,children:[z?t.jsxs("header",{className:"ios-workbench-nav","data-header-kind":"tools",children:[t.jsx("div",{className:"ios-workbench-nav-leading",children:z.showBackButton?t.jsxs("button",{type:"button",className:"ios-workbench-back-button","aria-label":r("common.back"),onClick:J,children:[t.jsx(ad,{}),t.jsx("span",{children:r("common.back")})]}):null}),t.jsx("div",{className:"ios-workbench-nav-copy",children:t.jsx("h1",{children:z.title})}),t.jsx("div",{className:"ios-workbench-nav-actions",children:z.showMoreButton?t.jsx("button",{type:"button",className:"ios-workbench-icon-button","aria-label":z.moreButtonLabel,onClick:p,children:t.jsx(ld,{})}):null})]}):null,t.jsx("div",{className:"ios-workbench-content",children:t.jsx(to,{viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!i,hasAuxiliaryPanel:!!o,preferCompactLayout:G,navigationPanel:i,auxiliaryPanel:o,children:s})}),I?t.jsxs("div",{className:"mobile-conversation-bottom-layer",children:[t.jsx("div",{ref:A,className:"mobile-conversation-bottom-layer-composer-slot"}),t.jsx("div",{className:"mobile-conversation-bottom-layer-tabbar-shell",children:Q})]}):Q]})})}function ad(){return t.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.85",children:t.jsx("path",{d:"m15 18-6-6 6-6"})})}function ld(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[t.jsx("circle",{cx:"12",cy:"5",r:"1.8"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.8"}),t.jsx("circle",{cx:"12",cy:"19",r:"1.8"})]})}function cd(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.85",children:[t.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"}),t.jsx("path",{d:"M8 13h8"})]})}function dd(){return t.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.85",children:t.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 ud(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.85",children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),t.jsx("path",{d:"m7.5 9 3 3-3 3"}),t.jsx("path",{d:"M12.5 15H17"})]})}function hd(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.85",children:[t.jsx("rect",{x:"5",y:"7",width:"14",height:"10",rx:"3"}),t.jsx("path",{d:"M9 7V5a3 3 0 0 1 6 0v2"}),t.jsx("circle",{cx:"10",cy:"12",r:".95",fill:"currentColor",stroke:"none"}),t.jsx("circle",{cx:"14",cy:"12",r:".95",fill:"currentColor",stroke:"none"}),t.jsx("path",{d:"M10 15c.6.5 1.2.8 2 .8s1.4-.3 2-.8"})]})}function fd(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.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 md(e){const n=Tn();return n.platform==="ios"?t.jsx(od,{...e}):n.platform==="android"?t.jsx(Vc,{...e}):t.jsx(pd,{...e})}function pd({activeEntry:e,presentation:n="default",children:s,navigationPanel:i,auxiliaryPanel:o,onNavigateWorkspaces:c,onNavigateTerminals:h,onNavigateSessions:f,onNavigateButler:k,onNavigateToolProcesses:p,onNavigateSettings:w}){const N=Tn(),C=Ui(),R=Qr(),O=er(),H=l.useRef(null),W=l.useRef(null),[x,A]=l.useState(null),I=id(N.platform==="web"),G=N.platform==="web"&&I.keyboardOpen,K=n==="conversation-focus",Y=ei({isNativeMobile:N.isNativeMobile,viewportClass:N.viewportClass}),z=eo({enabled:K,rootRef:H,suspended:G,resetKey:`${R.pathname}${R.search}`}),q=nr({viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!i,hasAuxiliaryPanel:!!o,preferCompactLayout:Y}),j=Ji({activeEntry:e,presentation:n,pathname:R.pathname,search:R.search,moreButtonLabel:r("shell.iosMoreAction")}),J=[{key:"workspaces",label:r("shell.mobileWorkspacesEntry"),icon:t.jsx(gd,{}),onClick:c},{key:"sessions",label:r("shell.mobileSessionsEntry"),icon:t.jsx(wd,{}),onClick:f},{key:"terminals",label:r("shell.mobileButlerEntry"),icon:t.jsx(vd,{}),onClick:k},{key:"butler",label:r("shell.mobileTerminalsEntry"),icon:t.jsx(xd,{}),onClick:h},{key:"settings",label:r("shell.mobileSettingsEntry"),icon:t.jsx(yd,{}),onClick:w}],Q=K?{"--mobile-conversation-tabbar-progress":z.progress.toFixed(4)}:void 0;Qi(H,W,K);function E(){const U=Yi(R.pathname,R.search);if(!U){h();return}O(U,{replace:!0})}const ue=t.jsx("nav",{ref:W,className:"mobile-workbench-tabbar","aria-label":r("shell.title"),hidden:G,children:J.map(U=>t.jsxs("button",{type:"button",className:"mobile-workbench-tabbar-item","data-active":U.key===e,"aria-current":U.key===e?"page":void 0,onClick:()=>{U.key!==e&&C.trigger("selection"),U.onClick()},children:[t.jsx("span",{className:"mobile-workbench-tabbar-icon","aria-hidden":"true",children:U.icon}),t.jsx("span",{className:"mobile-workbench-tabbar-label",children:U.label})]},U.key))});return t.jsx(Zi,{composerPortalTarget:K?x:null,children:t.jsxs("div",{ref:H,className:"mobile-workbench-shell","data-active-entry":e,"data-mobile-presentation":n,"data-mobile-runtime":N.platform,"data-mobile-keyboard-open":G,"data-pane-layout":q,"data-tabbar-open":G?!1:K?z.isOpen:!0,"data-conversation-tabbar-state":K?z.state:"default",style:Q,children:[j?t.jsxs("header",{className:"mobile-workbench-header","data-header-kind":"tools",children:[t.jsxs("div",{className:"mobile-workbench-header-leading",children:[j.showBackButton?t.jsx("button",{type:"button",className:"mobile-workbench-header-button","aria-label":r("common.back"),onClick:E,children:t.jsx(bd,{})}):null,t.jsx("div",{className:"mobile-workbench-header-copy",children:t.jsx("h1",{children:j.title})})]}),t.jsx("div",{className:"mobile-workbench-header-actions",children:j.showMoreButton?t.jsx("button",{type:"button",className:"mobile-workbench-header-button mobile-tools-more-button","aria-label":j.moreButtonLabel,onClick:p,children:t.jsx(kd,{})}):null})]}):null,t.jsx("div",{className:"mobile-workbench-content",children:t.jsx(to,{viewportClass:N.viewportClass,activeEntry:e,hasNavigationPanel:!!i,hasAuxiliaryPanel:!!o,preferCompactLayout:Y,navigationPanel:i,auxiliaryPanel:o,children:s})}),K?t.jsxs("div",{className:"mobile-conversation-bottom-layer",children:[t.jsx("div",{ref:A,className:"mobile-conversation-bottom-layer-composer-slot"}),t.jsx("div",{className:"mobile-conversation-bottom-layer-tabbar-shell",children:ue})]}):ue]})})}function bd(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[t.jsx("path",{d:"m15 18-6-6 6-6"}),t.jsx("path",{d:"M21 12H9"})]})}function kd(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[t.jsx("circle",{cx:"12",cy:"5",r:"1.8"}),t.jsx("circle",{cx:"12",cy:"12",r:"1.8"}),t.jsx("circle",{cx:"12",cy:"19",r:"1.8"})]})}function gd(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[t.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"}),t.jsx("path",{d:"M8 13h8"})]})}function wd(){return t.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:t.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 xd(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2.5"}),t.jsx("path",{d:"m7.5 9 3 3-3 3"}),t.jsx("path",{d:"M12.5 15H17"})]})}function vd(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[t.jsx("rect",{x:"5",y:"7",width:"14",height:"10",rx:"3"}),t.jsx("path",{d:"M9 7V5a3 3 0 0 1 6 0v2"}),t.jsx("circle",{cx:"10",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),t.jsx("circle",{cx:"14",cy:"12",r:"1",fill:"currentColor",stroke:"none"}),t.jsx("path",{d:"M10 15c.6.5 1.2.8 2 .8s1.4-.3 2-.8"})]})}function yd(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.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 Sd{constructor(n){ye(this,"maxAttempts");ye(this,"baseDelayMs");ye(this,"reconnectAttempts",0);ye(this,"reconnectTimer",null);ye(this,"disposed",!1);this.options=n,this.maxAttempts=n.maxAttempts??4,this.baseDelayMs=n.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(!nn.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 n=this.baseDelayMs*this.reconnectAttempts;this.reconnectTimer=window.setTimeout(()=>{this.options.onReconnect(!0)},n)}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 jd{constructor(n){ye(this,"socket",null);ye(this,"disposed",!1);ye(this,"authRecoveryInFlight",!1);ye(this,"pendingRefresh",!1);ye(this,"workbenchKnownRevision");ye(this,"fileTreeSubscription",null);ye(this,"gitSubscription",null);ye(this,"terminalManagerSubscription",null);ye(this,"workspaceManagementSubscription",null);ye(this,"pendingFileTreeRefresh",null);ye(this,"pendingGitRefresh",null);ye(this,"pendingTerminalManagerRefresh",null);ye(this,"pendingWorkspaceManagementRefresh",null);ye(this,"fileTreeRevisionByPath",new Map);ye(this,"gitRevisionByWorkspaceId",new Map);ye(this,"terminalManagerRevisionByWorkspaceId",new Map);ye(this,"workspaceManagementRevisionByWorkspaceId",new Map);ye(this,"fileTreeListeners",new Set);ye(this,"gitListeners",new Set);ye(this,"terminalManagerListeners",new Set);ye(this,"workspaceManagementListeners",new Set);ye(this,"connectionManager");this.options=n,this.workbenchKnownRevision=null,this.connectionManager=new Sd({onReconnect:s=>{this.connect(s)},onStateChange:n.onConnectionChange})}start(){this.connectionManager.start()}requestRefresh(){const n=this.socket;if(!Io(n)){this.pendingRefresh=!0;return}n.send(JSON.stringify({type:"workbench.refresh",knownRevision:this.workbenchKnownRevision??void 0})),this.pendingRefresh=!1}setWorkbenchKnownRevision(n){this.workbenchKnownRevision=Et(n)}subscribeFileTree(n,s,i){this.fileTreeSubscription={workspaceId:n,paths:Ro(s),knownRevisionByPath:ki(i==null?void 0:i.knownRevisionByPath)},this.sendWhenReady({type:"fileTree.subscribe",workspaceId:n,paths:this.fileTreeSubscription.paths,knownRevisions:gi(n,this.fileTreeSubscription.paths,this.fileTreeSubscription.knownRevisionByPath,this.fileTreeRevisionByPath)})}requestFileTreeRefresh(n,s,i){const o=Ro(s),c={type:"fileTree.refresh",workspaceId:n,paths:o,knownRevisions:gi(n,o,ki(i==null?void 0:i.knownRevisionByPath),this.fileTreeRevisionByPath)};this.sendWhenReady(c)?this.pendingFileTreeRefresh=null:this.pendingFileTreeRefresh={workspaceId:n,paths:o,knownRevisionByPath:ki(i==null?void 0:i.knownRevisionByPath)}}subscribeGit(n,s){this.gitSubscription={workspaceId:n,knownRevision:Et(s==null?void 0:s.knownRevision)},this.sendWhenReady({type:"git.subscribe",workspaceId:n,knownRevision:this.gitSubscription.knownRevision??this.gitRevisionByWorkspaceId.get(n)})}requestGitRefresh(n,s){const i={type:"git.refresh",workspaceId:n,knownRevision:Et(s==null?void 0:s.knownRevision)??this.gitRevisionByWorkspaceId.get(n)};this.sendWhenReady(i)?this.pendingGitRefresh=null:this.pendingGitRefresh={workspaceId:n,knownRevision:Et(s==null?void 0:s.knownRevision)}}subscribeTerminalManager(n,s){this.terminalManagerSubscription={workspaceId:n,knownRevision:Et(s==null?void 0:s.knownRevision)},this.sendWhenReady({type:"terminalManager.subscribe",workspaceId:n,knownRevision:this.terminalManagerSubscription.knownRevision??this.terminalManagerRevisionByWorkspaceId.get(n)})}requestTerminalManagerRefresh(n,s){const i={type:"terminalManager.refresh",workspaceId:n,knownRevision:Et(s==null?void 0:s.knownRevision)??this.terminalManagerRevisionByWorkspaceId.get(n)};this.sendWhenReady(i)?this.pendingTerminalManagerRefresh=null:this.pendingTerminalManagerRefresh={workspaceId:n,knownRevision:Et(s==null?void 0:s.knownRevision)}}subscribeWorkspaceManagement(n,s){this.workspaceManagementSubscription={workspaceId:n,knownRevision:Et(s==null?void 0:s.knownRevision)},this.sendWhenReady({type:"workspaceManagement.subscribe",workspaceId:n,knownRevision:this.workspaceManagementSubscription.knownRevision??this.workspaceManagementRevisionByWorkspaceId.get(n)})}requestWorkspaceManagementRefresh(n,s){const i={type:"workspaceManagement.refresh",workspaceId:n,knownRevision:Et(s==null?void 0:s.knownRevision)??this.workspaceManagementRevisionByWorkspaceId.get(n)};this.sendWhenReady(i)?this.pendingWorkspaceManagementRefresh=null:this.pendingWorkspaceManagementRefresh={workspaceId:n,knownRevision:Et(s==null?void 0:s.knownRevision)}}addFileTreeSnapshotListener(n){return this.fileTreeListeners.add(n),()=>{this.fileTreeListeners.delete(n)}}addGitSnapshotListener(n){return this.gitListeners.add(n),()=>{this.gitListeners.delete(n)}}addTerminalManagerSnapshotListener(n){return this.terminalManagerListeners.add(n),()=>{this.terminalManagerListeners.delete(n)}}addWorkspaceManagementSnapshotListener(n){return this.workspaceManagementListeners.add(n),()=>{this.workspaceManagementListeners.delete(n)}}close(){var n;this.disposed=!0,this.connectionManager.close(),(n=this.socket)==null||n.close(),this.socket=null}connect(n){var k;if(this.disposed)return;n&&this.socket&&(this.socket.close(),this.socket=null);const s=(k=Zs.getState().session)==null?void 0:k.accessToken;if(!s){this.options.onUnauthorized();return}const i=Pa(),o=ec(i),c=o.baseUrl,h=`${tc("/ws",c)}?access_token=${encodeURIComponent(s)}`,f=o.transport.createWebSocket({path:"/ws",baseUrl:c,url:h});this.socket=f,f.addEventListener("open",()=>{f.send(JSON.stringify({type:"workbench.subscribe",knownRevision:this.workbenchKnownRevision??void 0})),this.pendingRefresh&&this.requestRefresh(),this.fileTreeSubscription&&f.send(JSON.stringify({type:"fileTree.subscribe",workspaceId:this.fileTreeSubscription.workspaceId,paths:this.fileTreeSubscription.paths,knownRevisions:gi(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&&f.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&&f.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&&f.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})}),f.addEventListener("message",p=>{var N,C,R,O,H,W,x,A;if(!(p instanceof MessageEvent)||typeof p.data!="string")return;const w=JSON.parse(p.data);if(w.type==="system.connected"){this.connectionManager.markConnected();return}if(w.type==="session.error"){w.error_code==="UNAUTHORIZED"&&this.handleUnauthorized();return}if(w.type==="fileTree.snapshot"){const I=w.snapshot;if(I)I.revision=w.revision,this.fileTreeRevisionByPath.set(Ei(I.workspaceId,I.path),w.revision);else if(w.unchanged&&this.fileTreeSubscription)for(const G of this.fileTreeSubscription.paths)this.fileTreeRevisionByPath.set(Ei(this.fileTreeSubscription.workspaceId,G),w.revision);if(!I)return;(C=(N=this.options).onFileTreeSnapshot)==null||C.call(N,I),this.fileTreeListeners.forEach(G=>G(I));return}if(w.type==="git.snapshot"){const I=w.snapshot;if(I?(I.revision=w.revision,this.gitRevisionByWorkspaceId.set(I.workspaceId,w.revision)):w.unchanged&&this.gitSubscription&&this.gitRevisionByWorkspaceId.set(this.gitSubscription.workspaceId,w.revision),!I)return;(O=(R=this.options).onGitSnapshot)==null||O.call(R,I),this.gitListeners.forEach(G=>G(I));return}if(w.type==="terminalManager.snapshot"){const I=w.snapshot;if(I?(I.revision=w.revision,this.terminalManagerRevisionByWorkspaceId.set(I.workspaceId,w.revision)):w.unchanged&&this.terminalManagerSubscription&&this.terminalManagerRevisionByWorkspaceId.set(this.terminalManagerSubscription.workspaceId,w.revision),!I)return;(W=(H=this.options).onTerminalManagerSnapshot)==null||W.call(H,I),this.terminalManagerListeners.forEach(G=>G(I));return}if(w.type==="workspaceManagement.snapshot"){const I=w.snapshot;if(I?(I.revision=w.revision,this.workspaceManagementRevisionByWorkspaceId.set(I.workspaceId,w.revision)):w.unchanged&&this.workspaceManagementSubscription&&this.workspaceManagementRevisionByWorkspaceId.set(this.workspaceManagementSubscription.workspaceId,w.revision),!I)return;(A=(x=this.options).onWorkspaceManagementSnapshot)==null||A.call(x,I),this.workspaceManagementListeners.forEach(G=>G(I));return}w.type==="workbench.snapshot"&&w.snapshot&&Nd(w.snapshot)?(w.snapshot.revision=w.revision,this.workbenchKnownRevision=w.revision,this.options.onSnapshot(w.snapshot)):w.type==="workbench.snapshot"&&w.unchanged&&(this.workbenchKnownRevision=w.revision)}),f.addEventListener("close",()=>{this.disposed||this.socket!==f||this.connectionManager.markDisconnected()}),f.addEventListener("error",()=>{this.disposed||this.socket!==f||this.connectionManager.markTransientFailure()})}handleUnauthorized(){if(this.authRecoveryInFlight||this.disposed)return;this.authRecoveryInFlight=!0;const n=this.socket;this.socket=null,n==null||n.close(),Zs.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(n){const s=this.socket;return Io(s)?(s.send(JSON.stringify(n)),!0):!1}}function Io(e){return e!==null&&e.readyState===1}function Nd(e){return typeof e!="object"||e===null?!1:Array.isArray(e.items)}function Ro(e){const n=new Set;for(const s of e??[""])n.add(s.trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,""));return[...n]}function Et(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function ki(e){return e?Object.fromEntries(Object.entries(e).map(([n,s])=>[n.trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,""),Et(s)]).filter(n=>n[1]!==null)):{}}function gi(e,n,s,i){const o=n.map(c=>{const h=c.trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,"");return[h,s[h]??i.get(Ei(e,h))??null]}).filter(c=>!!c[1]);if(o.length!==0)return Object.fromEntries(o)}function Ei(e,n){return`${e}::${n}`}const Mo=6,Cd=["button","a","input","textarea","select","summary","[role='button']","[role='link']","[role='tab']","[role='menuitem']","[contenteditable='true']","[data-window-drag='ignore']"].join(", ");function Td(e){return e instanceof HTMLElement?!e.closest(Cd):!0}function Pi(e,n,s){return e.isDesktop&&e.ui.osFamily==="macos"&&n===0&&Td(s)}function cl(e){return e.isDesktop&&e.ui.osFamily==="macos"&&e.ui.prefersOverlayTitlebar}function dl(e){return cl(e)?"":void 0}function Id(e){if(!Pi(e.platform,e.button,e.target)||typeof window>"u")return;const n=e.clientX,s=e.clientY;let i=!0;const o=()=>{i&&(i=!1,window.removeEventListener("mousemove",c),window.removeEventListener("mouseup",h),window.removeEventListener("blur",f))},c=k=>{Math.abs(k.clientX-n)<Mo&&Math.abs(k.clientY-s)<Mo||(o(),Rd())},h=()=>{o()},f=()=>{o()};window.addEventListener("mousemove",c),window.addEventListener("mouseup",h),window.addEventListener("blur",f)}async function Rd(){typeof window>"u"||typeof window.__TAURI_INTERNALS__>"u"||await qa().startDragging()}const Jr=.78,Md=1;function Ed(){return typeof window<"u"&&typeof window.__TAURI_INTERNALS__<"u"}function ul(e,n,s,i){const o=Math.hypot(s-e,i-n),c=Math.min(1,o/120);return Jr+(Md-Jr)*c}function jn(e){return Math.round(Number.isFinite(e)?e:0)}function Pd(e){if(!Ed())return null;const n=jn(e.x),s=jn(e.y);let i=!1,o=Promise.resolve();const c=(f,k)=>(o=o.then(async()=>{await window.__TAURI_INTERNALS__.invoke(f,k)}).catch(()=>{}),o),h=async()=>{i||(i=!0,await c("close_detach_preview"))};return c("show_detach_preview",{title:e.title,x:n,y:s,scale:Jr}),{updatePosition(f,k){if(i)return;const p=jn(f),w=jn(k);c("update_detach_preview_position",{x:p,y:w,scale:ul(n,s,p,w)})},complete(){return h()},cancel(){return h()}}}function Wd(e){if(typeof document>"u")return null;const n=jn(e.x),s=jn(e.y),i=document.createElement("div");i.className="desktop-window-detach-animation",i.setAttribute("aria-hidden","true"),i.dataset.state="preview",i.style.left=`${n}px`,i.style.top=`${s}px`,i.style.setProperty("--detach-preview-scale",Jr.toFixed(3));const o=document.createElement("div");o.className="desktop-window-detach-animation-bar";const c=document.createElement("strong");c.className="desktop-window-detach-animation-title",c.textContent=e.title;const h=document.createElement("div");h.className="desktop-window-detach-animation-body",o.append(c),i.append(o,h),document.body.append(i);let f=!1;const k=()=>{f||(f=!0,i.remove())};return{updatePosition(p,w){if(f)return;const N=jn(p),C=jn(w),R=ul(n,s,N,C);i.style.left=`${N}px`,i.style.top=`${C}px`,i.style.setProperty("--detach-preview-scale",R.toFixed(3))},async complete(){k()},async cancel(){k()}}}function Eo(e){return Pd(e)??Wd(e)}const Ad={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 Bd(e){return{...e,bounds:{...e.bounds}}}function Ld(e,n,s){n&&(e.windows.registerDescriptor(n),s?e.windows.markWindowOpen(n.windowId):e.windows.markWindowClosed(n.windowId))}function Dd(e){return Ad[e]}function _d(e,n){return`${e}-${n}`}async function ti(e,n,s){const i=s.workspaceId.trim(),o=Dd(n);if(!e.isDesktop||!e.bridge.supported)return{ok:!1,errorCode:"PLATFORM_NOT_SUPPORTED",detail:"当前运行环境不支持桌面外部窗口。"};if(!i)return{ok:!1,errorCode:"WINDOW_WORKSPACE_REQUIRED",detail:`${o.label}外部窗口必须绑定工作区。`};const c=_d(n,i),h=e.windows.getDescriptor(c),f=h?Bd(h):null,k=e.windows.isWindowOpen(c),p=nc({windowId:c,kind:n,workspaceId:i,sessionId:s.sessionId??(f==null?void 0:f.sessionId)??null,mode:"external",bounds:f==null?void 0:f.bounds,focusOwner:s.focusOwner??o.defaultFocusOwner});e.windows.registerDescriptor(p);const w=await e.bridge.createWindow(p);return w.ok?(e.windows.markWindowOpen(c),{ok:!0,value:p}):(f?Ld(e,f,k):e.windows.removeWindow(c),{ok:!1,errorCode:w.errorCode,detail:w.detail})}function Fd(e,n){return ti(e,"files",n)}function Od(e,n){return ti(e,"git",n)}function Hd(e,n){return ti(e,"processes",n)}function xm(e,n){return ti(e,"terminals",n)}async function Po(){return await Z.request("/api/skills/overview")}async function Ud(e){await Z.request("/api/skills",{method:"POST",body:JSON.stringify(e)})}async function $d(e){await Z.request("/api/skills/import",{method:"POST",body:JSON.stringify(e)})}async function qd(e){await Z.request("/api/skills/sync",{method:"POST",body:JSON.stringify(e)})}function Gd({triggerClassName:e="secondary-button",triggerLabel:n,triggerLeading:s}){const i=Wa(y=>{var $;return(($=y.session)==null?void 0:$.accessToken)??null}),o=l.useRef(null),[c,h]=l.useState(null),[f,k]=l.useState(!1),[p,w]=l.useState(null),[N,C]=l.useState(null),[R,O]=l.useState(null),[H,W]=l.useState(!1),[x,A]=l.useState(!1),[I,G]=l.useState(null),[K,Y]=l.useState("file"),[z,q]=l.useState("workspace"),[j,J]=l.useState(""),[Q,E]=l.useState(()=>$s("workspace"));l.useEffect(()=>{let y=!0;if(!H)return;if(!i){h(null),C(null),O(null),k(!1);return}return(async()=>{k(!0);try{const le=await Po();if(!y)return;h(le),C(null)}catch(le){if(!y)return;C(ps(le))}finally{y&&k(!1)}})(),()=>{y=!1}},[i,H]);async function ue(){const y=await Po();h(y),C(null)}async function U(){if(i){w("refresh"),C(null),O(null);try{await ue(),O(r("settings.skillRefreshSuccess"))}catch(y){C(ps(y))}finally{w(null)}}}async function ce(y){if(i){w(Wo(y)),C(null),O(null);try{await $d({targetCli:y.targetCli,directoryPath:y.directoryPath,expectedContentHash:y.contentHash}),await ue(),O(r("settings.skillImportSuccess",{name:y.name,target:Nn(y.targetCli)}))}catch($){C(ps($))}finally{w(null)}}}async function D(y){if(!i)return;const $=y.bindings.filter(le=>le.enabled).map(le=>le.targetCli);if($.length===0){C(r("settings.skillSyncTargetMissing"));return}w(Ao(y.skill.id)),C(null),O(null);try{await qd({skillId:y.skill.id,targetCli:$}),await ue(),O(r("settings.skillSyncSuccess",{name:y.skill.name}))}catch(le){C(ps(le))}finally{w(null)}}async function v(y){var le;const $=((le=y.target.files)==null?void 0:le[0])??null;if(y.target.value="",!!$){C(null),O(null);try{const F=await au($),Pe=ml($.name,F);G(Pe),E($s(z))}catch(F){C(ps(F))}}}async function S(){const y=Bo({sourceMode:K,fileDraft:I,pastedMarkdown:j});if(!i)return;if(!y){C(K==="paste"?r("settings.skillPasteEmpty"):r("settings.skillUploadEmpty"));return}const $=y.directoryName;if(!$){C(r("settings.skillUploadDirectoryInvalid"));return}const le=Wi(z).filter(F=>Q[F]).map(F=>F);if(le.length===0){C(r("settings.skillUploadTargetRequired"));return}w("upload"),C(null),O(null);try{await Ud({markdownContent:y.rawContent,scope:z,fileName:y.fileName,directoryName:$,targetCli:le}),await ue(),O(r("settings.skillUploadSuccess",{name:$})),ae(z),A(!1)}catch(F){C(ps(F))}finally{w(null)}}function X(y){q(y),E($s(y))}function ke(y){Y(y),G(null),J(""),E($s(z)),C(null)}function we(y){E($=>({...$,[y]:!$[y]}))}function ne(){A(!0),C(null)}function oe(){A(!1),C(null),ae(z)}function ae(y){G(null),J(""),Y("file"),E($s(y))}const he=(c==null?void 0:c.summary)??{managedSkillCount:0,managedEntryCount:0},be=ru((c==null?void 0:c.assistantRuntimeSkills)??[],(c==null?void 0:c.conflictedEntries)??[],(c==null?void 0:c.diagnostics)??[]),me=((c==null?void 0:c.conflictedEntries)??[]).filter(y=>!fl(y,(c==null?void 0:c.diagnostics)??[])),Ge=((c==null?void 0:c.diagnostics)??[]).filter(y=>!sr(y)),Ee=Bo({sourceMode:K,fileDraft:I,pastedMarkdown:j}),_=n??r("settings.skillManageAction");return t.jsxs(t.Fragment,{children:[t.jsxs("button",{className:e,type:"button","data-open":H?"true":"false","aria-haspopup":"dialog","aria-expanded":H,onClick:()=>{W(!0)},children:[s,t.jsx("span",{children:_})]}),t.jsxs($e,{open:H,title:r("settings.skillConfigModalTitle"),description:r("settings.skillConfigModalDescription"),className:"settings-skill-modal",headerActions:t.jsxs("div",{className:"settings-skill-modal-actions",children:[t.jsx("button",{className:"secondary-button",type:"button",disabled:!i||f||p!==null,onClick:ne,children:r("settings.skillCreateAction")}),t.jsx("button",{className:"secondary-button",type:"button",disabled:!i||f||p!==null,onClick:()=>{U()},children:p==="refresh"?r("common.loading"):r("settings.skillRefresh")})]}),onClose:()=>W(!1),children:[t.jsxs("section",{className:"settings-skill-summary-block",children:[t.jsxs("div",{className:"settings-skill-summary-grid",children:[t.jsx(Wr,{label:r("settings.skillSummaryManagedSkills"),value:String(he.managedSkillCount)}),t.jsx(Wr,{label:r("settings.skillSummaryManagedEntries"),value:String(he.managedEntryCount)}),t.jsx(Wr,{label:r("settings.skillSummaryConflictedEntries"),value:String(me.length)}),t.jsx(Wr,{label:r("settings.skillSummaryDiagnostics"),value:String(Ge.length)})]}),t.jsx("div",{className:"settings-release-meta",children:t.jsxs("span",{children:[r("settings.skillScannedAt"),": ",f?r("common.loading"):su(c==null?void 0:c.scannedAt)]})}),R?t.jsx("p",{className:"settings-release-status",children:R}):null,N?t.jsx("p",{className:"settings-release-status",children:N}):null]}),t.jsx(Us,{title:r("settings.skillManagedListTitle"),emptyText:r("settings.skillManagedEmpty"),items:(c==null?void 0:c.managedSkills)??[],renderItem:y=>{const $=Ao(y.skill.id);return t.jsxs("div",{className:"settings-skill-entry",children:[t.jsxs("div",{className:"settings-skill-entry-main",children:[t.jsx("strong",{className:"settings-skill-entry-title",children:y.skill.name}),t.jsx("p",{className:"settings-skill-entry-meta",children:Qd(y.bindings)}),t.jsx("div",{className:"settings-skill-tags",children:y.bindings.map(le=>t.jsxs("span",{className:"settings-skill-tag","data-status":le.syncStatus,children:[Nn(le.targetCli)," · ",Zd(le.syncStatus)]},`${y.skill.id}-${le.targetCli}`))})]}),t.jsx("div",{className:"settings-skill-entry-actions",children:t.jsx("button",{className:"secondary-button",type:"button",disabled:f||p!==null,onClick:()=>{D(y)},children:p===$?r("common.loading"):r("settings.skillSyncAction")})})]},y.skill.id)}}),t.jsx(Us,{title:r("settings.skillUnmanagedListTitle"),emptyText:r("settings.skillUnmanagedEmpty"),items:(c==null?void 0:c.unmanagedEntries)??[],renderItem:y=>{const $=Wo(y);return t.jsxs("div",{className:"settings-skill-entry",children:[t.jsxs("div",{className:"settings-skill-entry-main",children:[t.jsx("strong",{className:"settings-skill-entry-title",children:y.name}),t.jsx("p",{className:"settings-skill-entry-meta",children:eu(y)})]}),t.jsx("div",{className:"settings-skill-entry-actions",children:t.jsx("button",{className:"secondary-button",type:"button",disabled:f||p!==null,onClick:()=>{ce(y)},children:p===$?r("common.loading"):r("settings.skillImportAction")})})]},`${y.targetCli}:${y.directoryPath}`)}}),t.jsx(Us,{title:r("settings.skillAssistantRuntimeListTitle"),description:r("settings.skillAssistantRuntimeListDescription"),emptyText:r("settings.skillAssistantRuntimeEmpty"),items:be,renderItem:y=>t.jsx("div",{className:"settings-skill-entry",children:t.jsxs("div",{className:"settings-skill-entry-main",children:[t.jsx("strong",{className:"settings-skill-entry-title",children:y.name}),t.jsx("p",{className:"settings-skill-entry-meta",children:r("settings.skillAssistantRuntimeItemDescription")}),t.jsxs("p",{className:"settings-skill-entry-meta",children:[r("settings.skillAssistantRuntimeUsedBy"),": ",hl(y.usedByTargetCli)]}),t.jsxs("div",{className:"settings-skill-tags",children:[t.jsx("span",{className:"settings-skill-tag","data-status":"assistant-runtime",children:r("settings.skillTagAssistantOnly")}),y.usedByTargetCli.map($=>t.jsx("span",{className:"settings-skill-tag","data-status":"synced",children:Nn($)},`${y.directoryName}:${$}`))]})]})},`${y.directoryName}:${y.sourcePath}`)}),t.jsx(Us,{title:r("settings.skillConflictedListTitle"),emptyText:r("settings.skillConflictedEmpty"),items:me,renderItem:y=>{const $=iu(y,(c==null?void 0:c.diagnostics)??[]);return t.jsx("div",{className:"settings-skill-entry",children:t.jsxs("div",{className:"settings-skill-entry-main",children:[t.jsx("strong",{className:"settings-skill-entry-title",children:y.name}),t.jsx("p",{className:"settings-skill-entry-meta",children:tu(y)}),$.length>0?t.jsx("div",{className:"settings-skill-tags",children:$.map(le=>t.jsx("span",{className:"settings-skill-tag","data-status":le.status,children:le.label},le.key))}):null]})},`${y.targetCli}:${y.directoryPath}`)}}),t.jsx(Us,{title:r("settings.skillDiagnosticsTitle"),emptyText:r("settings.skillDiagnosticsEmpty"),items:Ge,renderItem:y=>{const $=ou(y),le=nu(y);return t.jsx("div",{className:"settings-skill-entry",children:t.jsxs("div",{className:"settings-skill-entry-main",children:[t.jsx("strong",{className:"settings-skill-entry-title",children:le.title}),t.jsx("p",{className:"settings-skill-entry-meta",children:le.detail}),$.length>0?t.jsx("div",{className:"settings-skill-tags",children:$.map(F=>t.jsx("span",{className:"settings-skill-tag","data-status":F.status,children:F.label},F.key))}):null]})},`${y.targetCli}:${y.code}:${y.directoryPath??y.rootDir}`)}})]}),t.jsx($e,{open:x,title:r("settings.skillCreateModalTitle"),description:r("settings.skillCreateModalDescription"),className:"settings-skill-create-modal",onClose:oe,children:t.jsxs("section",{className:"settings-skill-section",children:[t.jsx("h3",{className:"settings-skill-section-title",children:r("settings.skillUploadSectionTitle")}),t.jsx("p",{className:"settings-skill-section-description",children:r("settings.skillUploadSectionDescription")}),t.jsxs("div",{className:"settings-skill-create-panel",children:[t.jsx("input",{ref:o,type:"file",accept:".md,text/markdown,text/plain",className:"settings-skill-upload-input",onChange:y=>{v(y)}}),t.jsx("div",{className:"settings-model-tabs",role:"tablist","aria-label":r("settings.skillCreateSourceTabsLabel"),children:Xd.map(y=>{const $=K===y;return t.jsx("button",{type:"button",role:"tab",className:"settings-model-tab","aria-selected":$,"data-active":$?"true":"false",onClick:()=>ke(y),children:Jd(y)},y)})}),t.jsx("div",{className:"settings-skill-upload-targets",role:"radiogroup","aria-label":r("settings.skillUploadScopeLabel"),children:Vd.map(y=>t.jsxs("label",{className:"settings-skill-upload-target","data-selected":z===y?"true":"false",children:[t.jsx("input",{type:"radio",name:"skill-upload-scope",checked:z===y,onChange:()=>X(y)}),t.jsx("span",{children:Yd(y)})]},y))}),K==="file"?t.jsx("div",{className:"settings-skill-create-toolbar",children:t.jsx("button",{className:"secondary-button",type:"button",disabled:f||p!==null,onClick:()=>{var y;(y=o.current)==null||y.click()},children:r("settings.skillUploadPickAction")})}):t.jsxs("label",{className:"settings-skill-upload-field",children:[t.jsx("span",{children:r("settings.skillPasteLabel")}),t.jsx("textarea",{className:"settings-skill-create-textarea",value:j,onChange:y=>J(y.target.value),placeholder:r("settings.skillPastePlaceholder")})]}),Ee?t.jsx("div",{className:"settings-skill-entry",children:t.jsxs("div",{className:"settings-skill-entry-main",children:[t.jsx("strong",{className:"settings-skill-entry-title",children:Ee.previewTitle}),t.jsxs("p",{className:"settings-skill-entry-meta",children:[r("settings.skillUploadPickedFile"),": ",Ee.fileName]})]})}):t.jsx("div",{className:"settings-skill-empty",children:K==="paste"?r("settings.skillPasteEmpty"):r("settings.skillUploadEmpty")}),t.jsxs("div",{className:"settings-skill-upload-field",children:[t.jsx("span",{children:r("settings.skillUploadTargetsLabel")}),t.jsx("div",{className:"settings-skill-upload-targets",children:Wi(z).map(y=>t.jsxs("label",{className:"settings-skill-upload-target","data-selected":Q[y]?"true":"false",children:[t.jsx("input",{type:"checkbox",checked:Q[y],onChange:()=>we(y)}),t.jsx("span",{children:Nn(y)})]},y))})]}),Ee!=null&&Ee.notes.length?t.jsx("div",{className:"settings-skill-tags",children:Ee.notes.map((y,$)=>t.jsx("span",{className:"settings-skill-tag","data-status":"pending",children:y},`${Ee.fileName}:${$}`))}):null,N?t.jsx("p",{className:"settings-release-status",children:N}):null,t.jsx("div",{className:"settings-skill-create-actions",children:t.jsx("button",{className:"primary-button",type:"button",disabled:f||p!==null,onClick:()=>{S()},children:p==="upload"?r("common.loading"):r("settings.skillCreateSubmitAction")})})]})]})})]})}function Us({title:e,description:n,emptyText:s,items:i,renderItem:o}){return t.jsxs("section",{className:"settings-skill-section",children:[t.jsx("h3",{className:"settings-skill-section-title",children:e}),n?t.jsx("p",{className:"settings-skill-section-description",children:n}):null,i.length>0?t.jsx("div",{className:"settings-skill-entry-list",children:i.map(c=>o(c))}):t.jsx("div",{className:"settings-skill-empty",children:s})]})}function Wr({label:e,value:n}){return t.jsxs("div",{className:"settings-skill-summary-card",children:[t.jsx("span",{children:e}),t.jsx("strong",{children:n})]})}function Wo(e){return`import:${e.targetCli}:${e.directoryPath}`}function Ao(e){return`sync:${e}`}const zd=["codex","claude-code","gemini","opencode"],Kd=["codex","claude-code"],Vd=["workspace","assistant"],Xd=["file","paste"];function ps(e){return e instanceof Aa?e.message||r("settings.skillLoadFailed"):e instanceof Error?e.message:r("settings.skillLoadFailed")}function Nn(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 Yd(e){return e==="assistant"?r("settings.skillUploadScopeAssistant"):r("settings.skillUploadScopeWorkspace")}function Jd(e){return e==="paste"?r("settings.skillCreateSourcePaste"):r("settings.skillCreateSourceFile")}function $s(e){return{codex:new Set(Wi(e)).has("codex"),"claude-code":!1,gemini:!1,opencode:!1}}function Wi(e){return e==="assistant"?Kd:zd}function Bo({sourceMode:e,fileDraft:n,pastedMarkdown:s}){return e==="file"?n:s.trim()?ml(lu(s),s):null}function Zd(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 hl(e){return e.map(Nn).join(" / ")}function Qd(e){const n=e.filter(s=>s.enabled);return n.length===0?r("settings.skillManagedItemNoTarget"):r("settings.skillManagedItemDescription",{targets:hl(n.map(s=>s.targetCli))})}function eu(e){return r("settings.skillUnmanagedItemDescription",{target:Nn(e.targetCli)})}function tu(e){return r("settings.skillConflictedItemDescription",{target:Nn(e.targetCli)})}function nu(e){const n=Nn(e.targetCli);switch(e.code){case"SKILL_TARGET_ROOT_MISSING":return{title:r("settings.skillDiagnosticTargetMissingTitle",{target:n}),detail:r("settings.skillDiagnosticTargetMissingDetail",{target:n})};case"SKILL_TARGET_ROOT_INVALID":case"SKILL_TARGET_STAT_FAILED":case"SKILL_TARGET_READ_FAILED":return{title:r("settings.skillDiagnosticReadFailedTitle",{target:n}),detail:r("settings.skillDiagnosticReadFailedDetail",{target:n})};case"SKILL_TARGET_SKILL_MISSING":return{title:r("settings.skillDiagnosticSyncMissingTitle",{target:n}),detail:r("settings.skillDiagnosticSyncMissingDetail",{target:n})};default:return{title:r("settings.skillDiagnosticGenericTitle",{target:n}),detail:r("settings.skillDiagnosticGenericDetail",{target:n})}}}function su(e){if(!e)return"-";const n=Date.parse(e);return Number.isNaN(n)?e:new Date(n).toLocaleString()}function ru(e,n,s){if(e.length>0)return e.map(o=>({name:o.name,directoryName:o.directoryName,sourcePath:o.sourcePath,usedByTargetCli:o.usedByTargetCli}));const i=new Map;for(const o of n)fl(o,s)&&i.set(Lo(o.targetCli,o.directoryPath),{name:o.name,directoryName:o.directoryName,sourcePath:o.directoryPath,usedByTargetCli:[o.targetCli]});for(const o of s){if(!sr(o))continue;const c=o.directoryPath??o.rootDir,h=Lo(o.targetCli,c);i.has(h)||i.set(h,{name:o.directoryName??"codingns-assistant",directoryName:o.directoryName??"codingns-assistant",sourcePath:c,usedByTargetCli:[o.targetCli]})}return[...i.values()]}function Lo(e,n){return`${e}:${n}`}function fl(e,n){return n.some(s=>sr(s)&&s.targetCli===e.targetCli&&s.directoryPath===e.directoryPath&&s.directoryName===e.directoryName)}function sr(e){return e.code==="SKILL_RESERVED_FOR_ASSISTANT_RUNTIME"}function iu(e,n){return n.find(i=>sr(i)&&i.targetCli===e.targetCli&&i.directoryName===e.directoryName&&i.directoryPath===e.directoryPath)?[{key:`assistant-runtime:${e.targetCli}:${e.directoryPath}`,label:r("settings.skillTagAssistantOnly"),status:"assistant-runtime"}]:[]}function ou(e){return sr(e)?[{key:`assistant-runtime:${e.targetCli}:${e.directoryPath??e.rootDir}`,label:r("settings.skillTagAssistantOnly"),status:"assistant-runtime"}]:[]}function ml(e,n){const s=[],i=n.replace(/^\uFEFF/,"").replace(/\r\n?/g,`
3
+ `).trim();if(!i)throw new Error(r("settings.skillUploadContentEmpty"));i!==n.trim()&&s.push(r("settings.skillUploadNormalizedNote"));const o=pl(i),c=Ai(e)??Ai(o)??"";return c||s.push(r("settings.skillUploadDirectoryRequiredNote")),o||s.push(r("settings.skillUploadHeadingNote")),{fileName:e,rawContent:i,directoryName:c,previewTitle:o||cu(c||"skill"),notes:s}}async function au(e){if(typeof e.text=="function")return await e.text();if(typeof FileReader>"u")throw new Error(r("settings.skillUploadReadFailed"));return await new Promise((n,s)=>{const i=new FileReader;i.onerror=()=>{s(i.error??new Error(r("settings.skillUploadReadFailed")))},i.onload=()=>{if(typeof i.result=="string"){n(i.result);return}s(new Error(r("settings.skillUploadReadFailed")))},i.readAsText(e)})}function Ai(e){const i=(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 i.length>0?i:null}function lu(e){const n=Ai(pl(e));return n?`${n}.md`:"pasted-skill.md"}function pl(e){var n,s;return((s=(n=e.match(/^#\s+(.+)$/m))==null?void 0:n[1])==null?void 0:s.trim())??""}function cu(e){return e.split(/[._-]+/).filter(Boolean).map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")||e}function no(e){var n,s;return e.runningState==="failed"||!!((n=e.lastErrorCode)!=null&&n.trim())||!!((s=e.lastErrorDetail)!=null&&s.trim())}function du(e,n,s){return`${e} is-${bl(n,s)}`}function bl(e,n){n==null||n.isActive;const s=fu(e);return n!=null&&n.hasSubagents?s==="error"?"error":s==="unread"?"subagent-unread":s==="running"||s==="running_inferred"?"subagent-running":"subagent":s==="running_inferred"?"running-inferred":s.replace("_","-")}function uu(e){return e.runningState==="stale"?r("conversation.runtimeStale"):e.runningState==="unknown"?r("conversation.runtimeUnknown"):null}function hu(e,n){return n.runningState==="stale"?`${e} is-stale`:n.runningState==="unknown"?`${e} is-unknown`:null}function fu(e){return no(e)?"error":e.runningState==="stale"?"stale":e.runningState==="unknown"?"unknown":e.activityState==="running"?mu(e)?"running_inferred":"running":e.activityState==="completed_unread"?"unread":"idle"}function mu(e){return e.activityResolutionSource==="inferred_log"||e.activitySource==="inferred"}function pu(e){return so(e)!==null}function bu(e){return e.isSubagent===!0&&!pu(e)}function so(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 ku(e){const n=so(e);return n==="reconstructed"?r("shell.sessionForkReconstructed"):n==="message"?r("shell.sessionForkMessage"):n==="session"?r("shell.sessionForkSession"):null}function gu(e){return e.sessionKind==="annotation"?"annotation":null}function vm(e){return gu(e)==="annotation"?r("conversation.actionSessionBadge"):null}const Do=48;function wu(e){return typeof e=="string"?e.replace(/\s+/g," ").trim():""}function ro(e,n){const s=wu(e)||n,i=s.length>Do?s.slice(0,Do).trimEnd():s;return{fullTitle:s,displayTitle:i}}function Ar(e,n){return(n??"").localeCompare(e??"")}function _o(e,n){return e.localeCompare(n,void 0,{numeric:!0,sensitivity:"base"})}function Br(e){return(e==null?void 0:e.trim())??""}function io(e,n,s){if(s==="updatedAt"){const h=Ar(e.updatedAt,n.updatedAt);if(h!==0)return h}if(s==="title"){const h=_o(Br(e.title),Br(n.title));if(h!==0)return h}else{const h=Ar(e.createdAt,n.createdAt);if(h!==0)return h}const i=Ar(e.updatedAt,n.updatedAt);if(i!==0)return i;const o=Ar(e.createdAt,n.createdAt);if(o!==0)return o;const c=_o(Br(e.title),Br(n.title));return c!==0?c:e.sessionId.localeCompare(n.sessionId)}function rr(e,n){return[...e].sort((s,i)=>io(s,i,n))}function oo(e,n){return Array.isArray(e)?e.map(s=>({...s,sessions:rr(s.sessions,n),children:oo(s.children,n)})):[]}const wi=5,xi=["#2563eb","#0891b2","#16a34a","#d97706","#dc2626","#64748b"];function xu(e){const n=Math.round(e.ratio*1e3)/10;return`${n.toFixed(n%1===0?0:1)}%`}function vu(e,n){const s=e.reduce((f,k)=>f+k.count,0);if(s<=0)return[];const o=e.slice(0,wi).map((f,k)=>({...f,key:f.type,ratio:f.count/s,color:xi[k]??xi[0]})),c=e.slice(wi);if(c.length===0)return o;const h=c.reduce((f,k)=>f+k.count,0);return o.push({key:"other",type:n,count:h,ratio:h/s,color:xi[wi]}),o}function yu(e){if(e.length===0)return"conic-gradient(color-mix(in srgb, var(--border-primary) 78%, transparent) 0% 100%)";let n=0;return`conic-gradient(${e.map((i,o)=>{const c=n,h=o===e.length-1?1:Math.min(1,n+i.ratio);return n=h,`${i.color} ${Fo(c)} ${Fo(h)}`}).join(", ")})`}function Su(e){return{"--workbench-manage-chart-background":yu(e)}}function Fo(e){const n=Math.round(e*1e3)/10;return`${n.toFixed(n%1===0?0:1)}%`}const ju=8,Nu=12,Cu=160,Oo=96;function Tu(e,n,s,i={}){const o=i.gapPx??ju,c=i.viewportMarginPx??Nu,h=i.defaultWidthPx??Cu,f=i.estimatedHeightPx??Oo,k=i.minHeightPx??Oo,p=Math.max(0,s.width),w=Math.max(0,s.height),N=Math.max(0,w-c*2),C=Math.max(0,p-c*2),R=Lr(Math.max(n.width||h,h),0,C),O=Math.max(n.height||f,f),H=Math.max(0,p-e.x-c),W=Math.max(0,e.x-c),x=H<R&&W>H,A=Math.max(0,w-e.y-o-c),I=Math.max(0,e.y-o-c),G=A<O&&I>A,Y=Lr(Math.max(G?I:A,k),0,N),z=Math.min(O,Y),q=x?e.x-R:e.x,j=Math.max(c,p-c-R),J=G?e.y-o-z:e.y+o,Q=Math.max(c,w-c-z),E=Lr(q,c,j),ue=Lr(J,c,Q),U=x||E<e.x?"right":"left";return{top:ue,left:E,width:R,maxHeight:Math.max(0,Y),transformOrigin:`${G?"bottom":"top"} ${U}`}}function Lr(e,n,s){return!Number.isFinite(e)||s<n?n:Math.min(Math.max(e,n),s)}const kl="workbench.navigation.snapshot",gl=1800*1e3,Iu="workbench.navigation.snapshot.host.";function wl(e){return`${Iu}${e}`}function Ru(e=gl,n=Zr(nn.getState())){if(n){const s=Yr(wl(n),e);if(s)return s}return Yr(kl,e)}function Dr(e,n=Zr(nn.getState())){Ys(kl,e),n&&Ys(wl(n),e)}function Ho(e,n="createdAt"){return!e||!Array.isArray(e.items)?[]:e.items.map(s=>({workspace:s.workspace,sessions:rr(s.sessions,n),childWorktrees:Mu(s.childWorktrees,n)}))}function Mu(e,n){return oo(e,n)}function ao(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 Eu(e){const n=new Map;for(const s of e)n.set(s.workspace.id,ao(s.workspace)),xl(n,s.childWorktrees??[],s.workspace,s.workspace);return Object.fromEntries(n)}function tn(e){if(e!=null&&e.backgroundColor)return{"--workspace-tone-color":e.backgroundColor}}function xl(e,n,s,i,o=i.name){var c;for(const h of n){const f=((c=h.meta.displayName)==null?void 0:c.trim())||h.workspace.name;e.set(h.workspace.id,{workspaceId:h.workspace.id,tone:"worktree",backgroundColor:h.workspace.backgroundColor??null,displayName:f,workspaceName:h.workspace.name,branchName:h.meta.branchName||null,depth:h.meta.depth,rootWorkspaceId:s.id,rootDisplayName:s.name,parentWorkspaceId:h.meta.parentWorkspaceId||i.id,parentDisplayName:o}),xl(e,h.children,s,h.workspace,f)}}const Pu="X-CodingNS-Assistant-Source",Wu="butler-ui",vi=new Map;async function sn(e,n={},s={}){const i=new Headers(n.headers);i.set(Pu,Wu);const o=Au();if(vi.get(o)===!1){if(s.unsupportedFallback!==void 0)return Uo(s.unsupportedFallback);throw $o()}try{const h=await Z.request(e,{...n,headers:i});return vi.set(o,!0),h}catch(h){if(!Bu(h))throw h;if(vi.set(o,!1),s.unsupportedFallback!==void 0)return Uo(s.unsupportedFallback);throw $o()}}function Au(){return Pa()}function Uo(e){return typeof e=="function"?e():e}function Bu(e){return e instanceof Aa&&(e.status===404||e.status===405||e.status===501)}function $o(){return new Error("当前 Host 版本不支持新版助手接口,请先升级 Host。")}function Lu(){return Z.request("/api/butler/profile")}function ym(e){return Z.request("/api/butler/profile/init",{method:"POST",body:JSON.stringify(e)})}function Sm(e){return Z.request("/api/butler/profile",{method:"PATCH",body:JSON.stringify(e)})}function jm(){return Z.request("/api/butler/control-session")}function Nm(){return Z.request("/api/butler/control-sessions")}function Cm(e){return Z.request(`/api/butler/control-sessions/${encodeURIComponent(e)}`)}function Tm(e={}){var o;const n=new URLSearchParams;e.status&&n.set("status",e.status),(o=e.controlSessionId)!=null&&o.trim()&&n.set("controlSessionId",e.controlSessionId.trim()),e.limit&&e.limit>0&&n.set("limit",String(e.limit));const s=n.toString(),i=s?`/api/butler/control-timers?${s}`:"/api/butler/control-timers";return Z.request(i)}function Im(){return Z.request("/api/butler/control-session/reset",{method:"POST"})}function Rm(e={}){return Z.request("/api/butler/control-session/start",{method:"POST",body:JSON.stringify(e)})}function Mm(e){return Z.request("/api/butler/control-session/messages",{method:"POST",body:JSON.stringify(e)})}function Em(e={}){var o;const n=new URLSearchParams;e.status&&n.set("status",e.status),(o=e.controlSessionId)!=null&&o.trim()&&n.set("controlSessionId",e.controlSessionId.trim()),e.limit&&e.limit>0&&n.set("limit",String(e.limit));const s=n.toString(),i=s?`/api/assistant/automations?${s}`:"/api/assistant/automations";return sn(i,{},{unsupportedFallback:()=>({payload:{items:[]}})})}function Pm(e={}){var o;const n=new URLSearchParams;(o=e.controlSessionId)!=null&&o.trim()&&n.set("controlSessionId",e.controlSessionId.trim()),e.limit&&e.limit>0&&n.set("limit",String(e.limit));const s=n.toString(),i=s?`/api/assistant/automations/runs/recent?${s}`:"/api/assistant/automations/runs/recent";return sn(i,{},{unsupportedFallback:()=>({payload:{items:[]}})})}function Wm(e){return sn(`/api/assistant/automations/${encodeURIComponent(e)}/cancel`,{method:"POST",body:JSON.stringify({})})}function Am(e,n){return sn(`/api/assistant/automations/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify(n)})}function Bm(e){return sn(`/api/assistant/automations/${encodeURIComponent(e)}/skip-wait`,{method:"POST",body:JSON.stringify({})})}function Lm(e={}){var o;const n=new URLSearchParams;e.status&&n.set("status",e.status),(o=e.controlSessionId)!=null&&o.trim()&&n.set("controlSessionId",e.controlSessionId.trim());const s=n.toString(),i=s?`/api/assistant/sandboxes?${s}`:"/api/assistant/sandboxes";return sn(i,{},{unsupportedFallback:()=>({payload:{items:[]}})})}function Dm(e){return sn(`/api/assistant/sandboxes/${encodeURIComponent(e.sandboxId)}/promote`,{method:"POST",body:JSON.stringify({mode:e.mode,projectName:e.projectName,defaultProvider:e.defaultProvider})})}function _m(e){return sn(`/api/assistant/sandboxes/${encodeURIComponent(e)}/expire`,{method:"POST",body:JSON.stringify({})})}function Fm(e){return sn(`/api/assistant/sandboxes/${encodeURIComponent(e)}`,{method:"DELETE"})}function Om(e){return Z.request(`/api/butler/control-timers/${encodeURIComponent(e)}/cancel`,{method:"POST",body:JSON.stringify({})})}function Hm(){return Z.request("/api/butler/control-session/events")}function Du(){return Z.request("/api/butler/overview")}function _u(e={}){var o;const n=new URLSearchParams;(o=e.workspaceId)!=null&&o.trim()&&n.set("workspaceId",e.workspaceId.trim()),e.status&&n.set("status",e.status),e.riskLevel&&n.set("riskLevel",e.riskLevel);const s=n.toString(),i=s?`/api/butler/projects?${s}`:"/api/butler/projects";return Z.request(i)}function Um(e,n={}){const s=new URLSearchParams;n.enabled!==null&&n.enabled!==void 0&&s.set("enabled",String(n.enabled)),n.executionMode&&s.set("executionMode",n.executionMode);const i=s.toString(),o=i?`/api/butler/projects/${encodeURIComponent(e)}/patrol-plans?${i}`:`/api/butler/projects/${encodeURIComponent(e)}/patrol-plans`;return Z.request(o)}function vl(e={}){var o,c;const n=new URLSearchParams;(o=e.workspaceId)!=null&&o.trim()&&n.set("workspaceId",e.workspaceId.trim()),(c=e.projectId)!=null&&c.trim()&&n.set("projectId",e.projectId.trim()),e.status&&n.set("status",e.status),e.itemType&&n.set("itemType",e.itemType);const s=n.toString(),i=s?`/api/butler/inbox?${s}`:"/api/butler/inbox";return Z.request(i)}function Fu(e){return Z.request("/api/butler/inbox",{method:"POST",body:JSON.stringify(e)})}function Ou(e={}){var o,c;const n=new URLSearchParams;e.status&&n.set("status",e.status),(o=e.projectId)!=null&&o.trim()&&n.set("projectId",e.projectId.trim()),(c=e.sessionId)!=null&&c.trim()&&n.set("sessionId",e.sessionId.trim());const s=n.toString(),i=s?`/api/butler/follow-up-tasks?${s}`:"/api/butler/follow-up-tasks";return Z.request(i)}function $m(e){return Z.request("/api/butler/follow-up-tasks",{method:"POST",body:JSON.stringify(e)})}function qm(e){return Z.request(`/api/butler/follow-up-tasks/${encodeURIComponent(e)}`)}function Gm(e){return Z.request(`/api/butler/follow-up-tasks/${encodeURIComponent(e)}/cancel`,{method:"POST"})}function zm(e,n){return Z.request(`/api/butler/projects/${encodeURIComponent(e)}/verifications/${encodeURIComponent(n)}/cancel`,{method:"POST"})}function qo(e,n){return Z.request(`/api/butler/inbox/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify({projectId:n.projectId,itemType:n.itemType,title:n.title,content:n.content,priority:n.priority,status:n.status})})}function Km(e){return Z.request(`/api/butler/inbox/${encodeURIComponent(e)}/analyze`,{method:"POST",body:JSON.stringify({})})}function Vm(e){return Z.request(`/api/butler/inbox/${encodeURIComponent(e)}/start-session`,{method:"POST",body:JSON.stringify({})})}function Hu(e){return Z.request(`/api/butler/inbox/${encodeURIComponent(e)}`,{method:"DELETE"})}function Uu(){return Z.request("/api/butler/notifications/archives")}function $u(e,n){return Z.request(`/api/butler/notifications/archives/${encodeURIComponent(e)}`,{method:"PATCH",body:JSON.stringify({archived:n})})}function qu(e){const n=new URLSearchParams;return n.set("sessionId",e),Z.request(`/api/butler/session-target?${n.toString()}`)}function Xm(e){const n=new URLSearchParams;return n.set("sessionId",e),Z.request(`/api/butler/session-action-context?${n.toString()}`)}function Ym(e){return Z.request("/api/butler/actions/start-verification",{method:"POST",body:JSON.stringify(e)})}class Bi extends Error{constructor(n,s){super(s),this.code=n,this.name="HostSwitchError"}}class Gu{constructor(){ye(this,"inFlight",null)}async switchHost(n){this.inFlight&&await this.inFlight;const s=this.performSwitch(n).finally(()=>{this.inFlight===s&&(this.inFlight=null)});this.inFlight=s,await s}async performSwitch(n){const s=nn.getState();if(Zr(s)===n)return;const i=sc(s,n);if(!i)throw new Bi("HOST_NOT_FOUND",`找不到 HOST:${n}`);if(!(await rc(i.baseUrl)).reachable)throw new Bi("HOST_UNREACHABLE",`目标 HOST 不可达:${i.baseUrl}`);const c=Ba(i.id);if(c)try{await Zs.loginForHost(i,{username:c.username,password:c.password})}catch{}const h=nn.getState(),f=new Date().toISOString();if(La(i)){nn.updateRuntime({discoveredHosts:h.discoveredHosts.map(k=>k.id===n?{...k,lastConnectedAt:f,updatedAt:f}:k),activeDiscoveredHostId:n});return}Ri.setActiveDiscoveredHost(null),await nn.update({hosts:h.hosts.map(k=>k.id===n?{...k,lastConnectedAt:f,updatedAt:f}:k),activeHostId:n})}}const zu=new Gu;function Ku({open:e,id:n,role:s="dialog",labelledBy:i,className:o,anchorRef:c,popoverRef:h,children:f,maxWidth:k=360,gap:p=10,viewportPadding:w=16}){const[N,C]=l.useState(null);if(l.useEffect(()=>{if(!e||typeof window>"u"||typeof document>"u"){C(null);return}let O=0;const H=()=>{const x=c.current;if(!x)return;const A=x.getBoundingClientRect(),I=Math.max(180,Math.min(k,window.innerWidth-w*2)),G=Math.min(Math.max(w,A.right-I),Math.max(w,window.innerWidth-w-I)),K=A.top>=Math.min(240,window.innerHeight*.42),Y=Math.round(K?A.top-p:A.bottom+p);C({top:Y,left:Math.round(G),width:I,placeAbove:K})},W=()=>{window.cancelAnimationFrame(O),O=window.requestAnimationFrame(H)};return H(),window.addEventListener("resize",W),window.addEventListener("scroll",W,!0),()=>{window.cancelAnimationFrame(O),window.removeEventListener("resize",W),window.removeEventListener("scroll",W,!0)}},[c,p,k,e,w]),!e||!N||typeof document>"u")return null;const R={position:"fixed",top:N.top,left:N.left,width:N.width,maxWidth:`calc(100vw - ${w*2}px)`,zIndex:9999,transform:N.placeAbove?"translateY(-100%)":void 0};return tr.createPortal(t.jsx("div",{id:n,ref:h,role:s,"aria-labelledby":i,className:o,"data-placement":N.placeAbove?"top":"bottom",style:R,children:f}),document.body)}const yi={status:"idle",latencyMs:null};function yl({collapsed:e=!1}){const[n,s]=l.useState(!1),[i,o]=l.useState(!1),[c,h]=l.useState(""),[f,k]=l.useState(""),[p,w]=l.useState(""),[N,C]=l.useState(""),[R,O]=l.useState(null),[H,W]=l.useState(null),[x,A]=l.useState(null),[I,G]=l.useState(!1),[K,Y]=l.useState(yi),[z,q]=l.useState(null),j=l.useRef(null),J=l.useRef(null),Q=l.useRef(null),E=l.useRef(null),ue=Oi(_=>_),U=Wa(_=>_.session),{showToast:ce}=Xn(),D=Da(ue),v=Zr(ue),S=uc(),X=ic(v),ke=l.useMemo(()=>Go(ue.hosts,v),[v,ue.hosts]),we=l.useMemo(()=>Go(_a(ue),v),[v,ue]),ne=l.useCallback(()=>{if(typeof window>"u")return;const _=j.current;if(!_)return;const y=_.getBoundingClientRect(),$=window.innerWidth,le=window.innerHeight,F=16,Pe=8,_e=Math.min(320,Math.max(240,$-F*2)),Wt=Math.min(e?Math.max(F,y.right+Pe):Math.max(F,y.left),Math.max(F,$-_e-F)),Je=i?440:240,wt=e?y.top:y.bottom+Pe,Fe=Math.min(Math.max(F,wt),Math.max(F,le-Je-F));q({position:"fixed",top:Fe,left:Wt,width:_e,maxWidth:$-F*2})},[e,i]);l.useEffect(()=>{if(!n){q(null),G(!1),Y(yi);return}Ri.refresh();function _($){var le,F,Pe;$.target instanceof Node&&!((le=j.current)!=null&&le.contains($.target))&&!((F=J.current)!=null&&F.contains($.target))&&!((Pe=E.current)!=null&&Pe.contains($.target))&&(s(!1),o(!1),G(!1),A(null))}function y($){$.key==="Escape"&&(s(!1),o(!1),G(!1),A(null))}return window.addEventListener("pointerdown",_),window.addEventListener("keydown",y),window.addEventListener("resize",ne),window.addEventListener("scroll",ne,!0),ne(),()=>{window.removeEventListener("pointerdown",_),window.removeEventListener("keydown",y),window.removeEventListener("resize",ne),window.removeEventListener("scroll",ne,!0)}},[n,ne]),l.useEffect(()=>{if(!I||!n||(S==null?void 0:S.kind)!=="relay"){Y(yi);return}let _=!1;const y=performance.now();return Y({status:"probing",latencyMs:null}),Z.request("/api/client/runtime-config").then(()=>{_||Y({status:"ready",latencyMs:performance.now()-y})}).catch(()=>{_||Y({status:"error",latencyMs:null})}),()=>{_=!0}},[S==null?void 0:S.kind,I,n]);async function oe(_){if(R||H||_.id===v){s(!1);return}O(_.id);try{await zu.switchHost(_.id),s(!1),o(!1),G(!1),A(null)}catch(y){ce({title:Ju(y,_.name),tone:"error"})}finally{O(null)}}async function ae(_){if(!(_.id===v||R||H)){if(x!==_.id){A(_.id);return}W(_.id);try{await nn.update({hosts:ue.hosts.filter(y=>y.id!==_.id)}),oc(_.id),Zs.clearHostSession(_.id),A(null),ce({title:r("shell.hostDeleteSuccess",{name:_.name})})}catch{ce({title:r("shell.hostDeleteFailed",{name:_.name}),tone:"error"})}finally{W(null)}}}async function he(){const _=p.trim();if((_.length>0||N.length>0)&&(!_||!N)){ce({title:r("shell.hostAddIncompleteCredentials"),tone:"error"});return}let $;try{$=ac(f)}catch{ce({title:r("shell.hostAddInvalidUrl"),tone:"error"});return}if(ue.hosts.some(Pe=>Pe.baseUrl===$)){ce({title:r("shell.hostAddDuplicate"),tone:"error"});return}const le=new Date().toISOString(),F={id:Yu(),name:c.trim()||Vu($),baseUrl:$,kind:Xu($),createdAt:le,updatedAt:le,lastConnectedAt:null,lastUserId:null,lastUsername:null};try{const Pe=La(D)&&D.baseUrl===$;Pe&&Ri.setActiveDiscoveredHost(null),await nn.update({hosts:[...ue.hosts,F],activeHostId:Pe?F.id:ue.activeHostId}),_&&N&&lc({hostId:F.id,username:_,password:N}),be(),o(!1),A(null),ce({title:r("shell.hostAddSuccess",{name:F.name})})}catch{ce({title:r("shell.hostAddFailed"),tone:"error"})}}function be(){h(""),k(""),w(""),C("")}if(!D)return null;const me=U!=null&&U.user.username?`${D.baseUrl} · ${U.user.username}`:D.baseUrl,Ge=(S==null?void 0:S.kind)==="relay"?r("shell.hostSwitcherDetailStatusRelay"):r("shell.hostSwitcherDetailStatusDirect"),Ee=S?r(hc(S.kind)):r("common.unknown");return t.jsxs("div",{ref:j,className:"workbench-host-switcher-anchor","data-collapsed":e,children:[t.jsx("button",{type:"button",className:e?"workbench-nav-toolbar-button workbench-collapsed-button":"workbench-nav-toolbar-button","aria-label":r("shell.hostSwitcherAriaLabel"),title:me,"aria-expanded":n,onClick:()=>{s(_=>!_),o(!1)},children:t.jsx(eh,{})}),n&&z&&typeof document<"u"?tr.createPortal(t.jsxs("div",{ref:J,className:"workbench-host-switcher-menu",style:z,role:"menu","aria-label":r("shell.hostSwitcherTitle"),children:[t.jsx("div",{className:"workbench-host-switcher-menu-header",children:t.jsx("strong",{children:r("shell.hostSwitcherTitle")})}),t.jsxs("div",{className:"workbench-host-switcher-list",children:[t.jsx("div",{className:"workbench-host-switcher-section-label",children:r("shell.hostSwitcherSavedSection")}),ke.map(_=>{const y=_.id===v,$=y?(U==null?void 0:U.user.username)??_.lastUsername??_.baseUrl:_.lastUsername??_.baseUrl;return t.jsxs("div",{className:"workbench-host-switcher-item","data-active":y,children:[t.jsxs("button",{type:"button",className:"workbench-host-switcher-item-main",disabled:R!==null||H!==null,onClick:()=>{oe(_)},children:[t.jsxs("span",{className:"workbench-host-switcher-item-copy",children:[t.jsxs("span",{className:"workbench-host-switcher-item-title",children:[_.name,y?t.jsx("span",{className:"workbench-host-switcher-item-badge",children:r("shell.hostSwitcherCurrentBadge")}):null]}),t.jsx("span",{className:"workbench-host-switcher-item-meta",children:$})]}),t.jsx("span",{className:"workbench-host-switcher-item-trailing",children:R===_.id?r("shell.hostSwitcherSwitching"):y?t.jsx(Ko,{}):t.jsx(zo,{})})]}),y?t.jsx("button",{ref:Q,type:"button",className:"workbench-host-switcher-item-action","aria-label":r("shell.hostSwitcherDetailAriaLabel",{name:_.name}),"aria-expanded":I,"aria-haspopup":"dialog","data-tone":"detail",onClick:()=>{G(le=>!le),A(null)},children:r("shell.hostSwitcherDetailAction")}):t.jsx("button",{type:"button",className:"workbench-host-switcher-item-action","aria-label":r("shell.hostDeleteAriaLabel",{name:_.name}),title:x===_.id?r("shell.hostDeleteConfirmAction"):r("shell.hostDeleteAction"),"data-confirming":x===_.id,disabled:R!==null||H!==null,onClick:()=>{ae(_)},children:H===_.id?r("shell.hostDeleteBusy"):x===_.id?r("shell.hostDeleteConfirmAction"):t.jsx(nh,{})})]},_.id)}),we.length>0?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"workbench-host-switcher-section-label",children:r("shell.hostSwitcherDiscoveredSection")}),we.map(_=>{const y=_.id===v,$=Ba(_.id),le=y?(U==null?void 0:U.user.username)??($==null?void 0:$.username)??_.baseUrl:($==null?void 0:$.username)??_.baseUrl;return t.jsxs("div",{className:"workbench-host-switcher-item","data-active":y,"data-discovered":"true",children:[t.jsxs("button",{type:"button",className:"workbench-host-switcher-item-main",disabled:R!==null||H!==null,onClick:()=>{oe(_)},children:[t.jsxs("span",{className:"workbench-host-switcher-item-copy",children:[t.jsxs("span",{className:"workbench-host-switcher-item-title",children:[_.name,t.jsx("span",{className:"workbench-host-switcher-item-badge","data-tone":"discovered",children:r("shell.hostSwitcherDiscoveredBadge")}),y?t.jsx("span",{className:"workbench-host-switcher-item-badge",children:r("shell.hostSwitcherCurrentBadge")}):null]}),t.jsx("span",{className:"workbench-host-switcher-item-meta",children:le})]}),t.jsx("span",{className:"workbench-host-switcher-item-trailing",children:R===_.id?r("shell.hostSwitcherSwitching"):y?t.jsx(Ko,{}):t.jsx(zo,{})})]}),y?t.jsx("button",{ref:Q,type:"button",className:"workbench-host-switcher-item-action","aria-label":r("shell.hostSwitcherDetailAriaLabel",{name:_.name}),"aria-expanded":I,"aria-haspopup":"dialog","data-tone":"detail",onClick:()=>{G(F=>!F),A(null)},children:r("shell.hostSwitcherDetailAction")}):null]},_.id)})]}):null,ue.localHostDiscovery.status==="refreshing"?t.jsx("div",{className:"workbench-host-switcher-state-row",children:r("shell.hostDiscoveryRefreshing")}):null,ue.localHostDiscovery.status==="failed"?t.jsx("div",{className:"workbench-host-switcher-state-row","data-tone":"error",children:r("shell.hostDiscoveryFailed")}):null]}),i?t.jsxs("div",{className:"workbench-host-switcher-form",children:[t.jsxs("label",{className:"workbench-host-switcher-field",children:[t.jsx("span",{children:r("shell.hostSwitcherNameLabel")}),t.jsx("input",{value:c,onChange:_=>h(_.target.value),placeholder:r("shell.hostSwitcherNamePlaceholder")})]}),t.jsxs("label",{className:"workbench-host-switcher-field",children:[t.jsx("span",{children:r("shell.hostSwitcherUrlLabel")}),t.jsx("input",{value:f,onChange:_=>k(_.target.value),placeholder:r("shell.hostSwitcherUrlPlaceholder")})]}),t.jsxs("label",{className:"workbench-host-switcher-field",children:[t.jsx("span",{children:r("auth.username")}),t.jsx("input",{value:p,onChange:_=>w(_.target.value),autoComplete:"username"})]}),t.jsxs("label",{className:"workbench-host-switcher-field",children:[t.jsx("span",{children:r("auth.password")}),t.jsx("input",{type:"password",value:N,onChange:_=>C(_.target.value),autoComplete:"current-password"})]}),t.jsxs("div",{className:"workbench-host-switcher-form-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",onClick:()=>{o(!1),be()},children:r("common.cancel")}),t.jsx("button",{type:"button",className:"primary-button",onClick:()=>{he()},children:r("shell.hostSwitcherSaveAction")})]})]}):t.jsxs("button",{type:"button",className:"workbench-host-switcher-add",onClick:()=>{o(!0),A(null)},children:[t.jsx(th,{}),r("shell.hostSwitcherAddAction")]}),t.jsxs(Ku,{open:I&&S!==null&&Q.current!==null,className:"workbench-host-switcher-detail-popover",anchorRef:Q,popoverRef:E,labelledBy:"workbench-host-switcher-detail-title",children:[t.jsx("div",{className:"workbench-host-switcher-detail-header",children:t.jsx("strong",{id:"workbench-host-switcher-detail-title",children:r("shell.hostSwitcherDetailTitle")})}),t.jsxs("div",{className:"workbench-host-switcher-detail-grid",children:[t.jsxs("div",{className:"workbench-host-switcher-detail-row",children:[t.jsx("span",{className:"workbench-host-switcher-detail-label",children:r("shell.hostSwitcherDetailStatusLabel")}),t.jsx("span",{className:"workbench-host-switcher-detail-value",children:Ge})]}),t.jsxs("div",{className:"workbench-host-switcher-detail-row",children:[t.jsx("span",{className:"workbench-host-switcher-detail-label",children:r("shell.hostSwitcherDetailRouteLabel")}),t.jsx("span",{className:"workbench-host-switcher-detail-value",children:Ee})]}),t.jsxs("div",{className:"workbench-host-switcher-detail-row",children:[t.jsx("span",{className:"workbench-host-switcher-detail-label",children:r("shell.hostSwitcherDetailAddressLabel")}),t.jsx("span",{className:"workbench-host-switcher-detail-value","data-multiline":"true",children:(S==null?void 0:S.url)??D.baseUrl})]}),(S==null?void 0:S.kind)==="relay"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"workbench-host-switcher-detail-row",children:[t.jsx("span",{className:"workbench-host-switcher-detail-label",children:r("shell.hostSwitcherDetailLatencyLabel")}),t.jsx("span",{className:"workbench-host-switcher-detail-value",children:Zu(K)})]}),t.jsxs("div",{className:"workbench-host-switcher-detail-row",children:[t.jsx("span",{className:"workbench-host-switcher-detail-label",children:r("shell.hostSwitcherDetailTrafficLabel")}),t.jsx("span",{className:"workbench-host-switcher-detail-value",children:Qu(X.totalBytes)})]})]}):null]})]})]}),document.body):null]})}function Go(e,n){return[...e].sort((s,i)=>{if(s.id===n)return-1;if(i.id===n)return 1;const o=s.lastConnectedAt??s.updatedAt??s.createdAt;return(i.lastConnectedAt??i.updatedAt??i.createdAt).localeCompare(o)})}function Vu(e){try{const n=new URL(e),s=n.pathname==="/"?"":n.pathname.replace(/\/+$/,"");return`${n.host}${s}`}catch{return e}}function Xu(e){try{const n=new URL(e).hostname.toLowerCase();return n==="localhost"||n==="127.0.0.1"||n==="::1"||n==="[::1]"?"local":/^10\./.test(n)||/^192\.168\./.test(n)||/^172\.(1[6-9]|2\d|3[0-1])\./.test(n)?"lan":"remote"}catch{return"custom"}}function Yu(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`host-${crypto.randomUUID()}`:`host-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function Ju(e,n){return e instanceof Bi?e.code==="HOST_UNREACHABLE"?r("shell.hostSwitchUnreachable",{name:n}):r("shell.hostSwitchMissing"):r("shell.hostSwitchFailed")}function Zu(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 Qu(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 eh(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[t.jsx("rect",{x:"4",y:"4.5",width:"16",height:"6.5",rx:"2.2",stroke:"currentColor",strokeWidth:"1.8"}),t.jsx("rect",{x:"4",y:"13",width:"16",height:"6.5",rx:"2.2",stroke:"currentColor",strokeWidth:"1.8"}),t.jsx("path",{d:"M11 7.75h5.5",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"}),t.jsx("path",{d:"M11 16.25h5.5",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"}),t.jsx("circle",{cx:"7.5",cy:"7.75",r:"1",fill:"currentColor",stroke:"none"}),t.jsx("circle",{cx:"7.5",cy:"16.25",r:"1",fill:"currentColor",stroke:"none"})]})}function zo(){return t.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:t.jsx("path",{d:"M6 3.5L10.5 8 6 12.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function Ko(){return t.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:t.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 th(){return t.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:t.jsx("path",{d:"M8 3.5v9M3.5 8h9",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function nh(){return t.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:t.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 _r={repositoryUrl:"",parentPath:"",directoryName:"",name:"",authMode:"none",username:"",password:"",token:""};function sh({open:e,onClose:n,onCloned:s}){const{showToast:i}=Xn(),[o,c]=l.useState(!1),[h,f]=l.useState(_r),[k,p]=l.useState(!1),[w,N]=l.useState(!1),[C,R]=l.useState(null),[O,H]=l.useState(""),[W,x]=l.useState(""),[A,I]=l.useState(null),[G,K]=l.useState([]),[Y,z]=l.useState([]),q=o||w;l.useEffect(()=>{!e&&!o&&(f(_r),p(!1),R(null))},[o,e]);const j=l.useCallback(async D=>{N(!0),R(null);try{const v=await Fa(D);H(v.currentPath),x(v.currentPath),I(v.parentPath),K(v.roots),z(v.items),f(S=>({...S,parentPath:v.currentPath}))}catch(v){H(""),I(null),z([]),R(v instanceof Error?v.message:r("shell.importBrowserBrowseFailed"))}finally{N(!1)}},[]);function J(){o||(p(!1),R(null),f(_r),n())}function Q(){p(!0),j(h.parentPath||void 0)}function E(){o||(p(!1),R(null))}async function ue(D){D.preventDefault(),await j(W)}function U(){f(D=>({...D,parentPath:O})),p(!1),R(null)}async function ce(D){D.preventDefault();const v=h.repositoryUrl.trim(),S=h.parentPath.trim();if(!v){i({title:r("shell.cloneRepoRequired"),tone:"error"});return}if(!S){i({title:r("shell.clonePathRequired"),tone:"error"});return}c(!0);try{const X=await fc({repositoryUrl:v,parentPath:S,directoryName:h.directoryName.trim()||void 0,name:h.name.trim()||void 0,auth:h.authMode==="none"?{mode:"none"}:h.authMode==="basic"?{mode:"basic",username:h.username.trim(),password:h.password}:{mode:"token",username:h.username.trim()||void 0,token:h.token}});await(s==null?void 0:s(X)),f(_r),p(!1),i({title:r("shell.cloneSuccess"),description:X.path,tone:"success"}),n()}catch(X){i({title:X instanceof Error?X.message:r("shell.cloneFailed"),tone:"error"})}finally{c(!1)}}return t.jsxs(t.Fragment,{children:[t.jsx($e,{open:e,title:r("shell.cloneWorkspaceTitle"),description:r("shell.cloneWorkspaceHint"),onClose:J,children:t.jsxs("form",{className:"workbench-clone-form",onSubmit:D=>void ce(D),children:[t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.cloneRepositoryLabel")}),t.jsx("input",{type:"text",value:h.repositoryUrl,placeholder:r("shell.cloneRepositoryPlaceholder"),onChange:D=>f(v=>({...v,repositoryUrl:D.target.value}))})]}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.cloneParentPathLabel")}),t.jsxs("div",{className:"workbench-modal-inline-field",children:[t.jsx("input",{type:"text",value:h.parentPath,placeholder:r("shell.cloneParentPathPlaceholder"),onChange:D=>f(v=>({...v,parentPath:D.target.value}))}),t.jsx("button",{type:"button",className:"secondary-button",disabled:o,onClick:Q,children:r("shell.clonePickDirectory")})]})]}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.cloneDirectoryNameLabel")}),t.jsx("input",{type:"text",value:h.directoryName,placeholder:r("shell.cloneDirectoryNamePlaceholder"),onChange:D=>f(v=>({...v,directoryName:D.target.value}))})]}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.importNameLabel")}),t.jsx("input",{type:"text",value:h.name,placeholder:r("shell.importNamePlaceholder"),onChange:D=>f(v=>({...v,name:D.target.value}))})]}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.cloneAuthModeLabel")}),t.jsxs("select",{value:h.authMode,onChange:D=>f(v=>({...v,authMode:D.target.value})),children:[t.jsx("option",{value:"none",children:r("shell.cloneAuthModeNone")}),t.jsx("option",{value:"basic",children:r("shell.cloneAuthModeBasic")}),t.jsx("option",{value:"token",children:r("shell.cloneAuthModeToken")})]})]}),h.authMode==="basic"?t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.cloneUsernameLabel")}),t.jsx("input",{type:"text",value:h.username,placeholder:r("shell.cloneUsernamePlaceholder"),autoComplete:"username",onChange:D=>f(v=>({...v,username:D.target.value}))})]}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.clonePasswordLabel")}),t.jsx("input",{type:"password",value:h.password,placeholder:r("shell.clonePasswordPlaceholder"),autoComplete:"current-password",onChange:D=>f(v=>({...v,password:D.target.value}))})]})]}):null,h.authMode==="token"?t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.cloneUsernameLabel")}),t.jsx("input",{type:"text",value:h.username,placeholder:r("shell.cloneTokenUsernamePlaceholder"),onChange:D=>f(v=>({...v,username:D.target.value}))})]}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.cloneTokenLabel")}),t.jsx("input",{type:"password",value:h.token,placeholder:r("shell.cloneTokenPlaceholder"),onChange:D=>f(v=>({...v,token:D.target.value}))})]})]}):null,t.jsx("p",{className:"workbench-import-hint",children:r("shell.cloneHint")}),t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:o,onClick:J,children:r("common.cancel")}),t.jsx("button",{type:"submit",className:"primary-button",disabled:o,children:o?r("shell.cloneSubmitting"):r("shell.cloneSubmit")})]})]})}),t.jsxs($e,{open:e&&k,title:r("shell.cloneBrowserTitle"),description:r("shell.cloneBrowserDescription"),onClose:E,children:[t.jsxs("form",{className:"workbench-directory-browser-form",onSubmit:ue,children:[t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.importBrowserCurrentPath")}),t.jsx("input",{type:"text",value:W,placeholder:r("shell.importPathPlaceholder"),onChange:D=>x(D.target.value)})]}),t.jsxs("div",{className:"workbench-directory-browser-toolbar",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:q||!A,onClick:()=>{A&&j(A)},children:r("shell.importBrowserOpenParent")}),t.jsx("button",{type:"submit",className:"secondary-button",disabled:q,children:r("shell.importBrowserOpenPath")})]})]}),t.jsxs("section",{className:"workbench-directory-browser-panel",children:[t.jsxs("div",{className:"workbench-directory-browser-section",children:[t.jsx("span",{className:"workbench-directory-browser-section-title",children:r("shell.importBrowserRoots")}),t.jsx("div",{className:"workbench-directory-browser-root-list",children:G.map(D=>t.jsx("button",{type:"button",className:"workbench-directory-browser-chip",disabled:q,onClick:()=>{j(D.path)},children:D.name},D.path))})]}),t.jsx("div",{className:"workbench-directory-browser-current-path",children:O}),C?t.jsx("p",{className:"workbench-directory-browser-status status-text","data-tone":"error",children:C}):null,w?t.jsx("p",{className:"workbench-directory-browser-status status-text",children:r("common.loading")}):Y.length>0?t.jsx("div",{className:"workbench-directory-browser-list",children:Y.map(D=>t.jsxs("button",{type:"button",className:"workbench-directory-browser-item",disabled:q,onClick:()=>{j(D.path)},children:[t.jsx("span",{className:"workbench-directory-browser-item-name",children:D.name}),t.jsx("span",{className:"workbench-directory-browser-item-path",children:D.path})]},D.path))}):t.jsx("p",{className:"workbench-directory-browser-status status-text",children:r("shell.importBrowserEmpty")})]}),t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:o,onClick:E,children:r("common.cancel")}),t.jsx("button",{type:"button",className:"primary-button",disabled:q||!O,onClick:U,children:r("shell.cloneBrowserSubmit")})]})]})]})}const rh="butler:inbox-updated";function Si(){typeof window>"u"||window.dispatchEvent(new Event(rh))}const Vo={projectId:"",itemType:"task",title:"",content:"",status:"pending"};function Sl({active:e,preferredWorkspaceId:n,preferredSessionId:s,creationRequestId:i=0,initialDraft:o=null,compactComposer:c=!1,composerOpen:h=!0,onComposerOpenChange:f}){const{showToast:k}=Xn(),[p,w]=l.useState(!1),[N,C]=l.useState(!1),[R,O]=l.useState([]),[H,W]=l.useState([]),[x,A]=l.useState(null),[I,G]=l.useState(null),[K,Y]=l.useState(Vo),[z,q]=l.useState(!1),j=l.useMemo(()=>Yo(R,n,I),[I,n,R]),J=l.useMemo(()=>z?H:H.filter(v=>v.status!=="closed"),[H,z]);l.useEffect(()=>{e&&Q()},[e,s]),l.useEffect(()=>{!e||x||Y(v=>{const S=Zo({projects:j,currentProjectId:v.projectId,preferredProjectId:I,preferredWorkspaceId:n});return S===v.projectId?v:{...v,projectId:S}})},[e,x,I,n,j]),l.useEffect(()=>{!e||i<=0||(E(void 0,n,o,I),f==null||f(!0))},[e,i,o,f,I,n]);async function Q(){w(!0);try{const[v,S,X]=await Promise.all([_u(),vl(),s?qu(s).catch(()=>null):Promise.resolve(null)]),ke=(X==null?void 0:X.target.project.id)??null;G(ke),O(v.items),W(S.items),x||E(v.items,n,i>0?o:null,ke)}catch(v){k({title:r("shell.butlerInboxLoadFailed"),description:v instanceof Error?v.message:void 0,tone:"error"})}finally{w(!1)}}function E(v=R,S=n,X=o,ke=I){var ne,oe;const we=Yo(v,S,ke);A(null),Y({...Vo,projectId:Zo({projects:we,preferredProjectId:ke,preferredWorkspaceId:S}),title:((ne=X==null?void 0:X.title)==null?void 0:ne.trim())??"",content:((oe=X==null?void 0:X.content)==null?void 0:oe.trim())??""})}function ue(v){A(v.id),Y({projectId:v.projectId,itemType:v.itemType,title:v.title,content:v.content,status:v.status}),c&&(f==null||f(!0))}async function U(v){v.preventDefault(),C(!0);try{x?(await qo(x,{projectId:K.projectId,itemType:K.itemType,title:K.title,content:K.content,status:K.status,priority:"medium"}),k({title:r("shell.butlerInboxUpdated"),tone:"success"})):(await Fu({projectId:K.projectId,itemType:K.itemType,title:K.title,content:K.content,status:K.status,priority:"medium"}),k({title:r("shell.butlerInboxCreated"),tone:"success"})),Si(),await Q(),E(),c&&(f==null||f(!1))}catch(S){k({title:r("shell.butlerInboxSaveFailed"),description:S instanceof Error?S.message:void 0,tone:"error"})}finally{C(!1)}}async function ce(v){C(!0);try{await Hu(v),k({title:r("shell.butlerInboxDeleted"),tone:"success"}),Si(),await Q(),x===v&&E()}catch(S){k({title:r("shell.butlerInboxDeleteFailed"),description:S instanceof Error?S.message:void 0,tone:"error"})}finally{C(!1)}}async function D(v,S){if(v.status!==S){C(!0);try{await qo(v.id,{status:S}),k({title:r("shell.butlerInboxUpdated"),tone:"success"}),Si(),await Q(),x===v.id&&Y(X=>({...X,status:S}))}catch(X){k({title:r("shell.butlerInboxSaveFailed"),description:X instanceof Error?X.message:void 0,tone:"error"})}finally{C(!1)}}}return t.jsxs("div",{className:"workspace-inbox-modal",children:[c?null:t.jsx("section",{className:"workspace-inbox-panel",children:t.jsx(Xo,{selectableProjects:j,formState:K,saving:N,editingItemId:x,useMobilePicker:!1,onProjectChange:v=>{Y(S=>({...S,projectId:v}))},onItemTypeChange:v=>{Y(S=>({...S,itemType:v}))},onStatusChange:v=>{Y(S=>({...S,status:v}))},onTitleChange:v=>{Y(S=>({...S,title:v}))},onContentChange:v=>{Y(S=>({...S,content:v}))},onCancel:()=>E(),onSubmit:U})}),t.jsxs("section",{className:"workspace-inbox-panel",children:[t.jsxs("header",{className:"workspace-inbox-panel-header",children:[t.jsxs("div",{children:[t.jsx("h3",{children:r("shell.butlerInboxListTitle")}),t.jsx("p",{children:r("shell.butlerInboxListDescription")})]}),t.jsxs("label",{className:"workspace-inbox-closed-toggle",children:[t.jsx("input",{type:"checkbox",checked:z,onChange:v=>q(v.target.checked)}),t.jsx("span",{children:r("shell.butlerInboxShowClosedAction")})]})]}),p?t.jsx("p",{className:"workspace-inbox-status",children:r("shell.butlerInboxLoading")}):null,!p&&J.length===0?t.jsx("p",{className:"workspace-inbox-status",children:r("shell.butlerInboxEmpty")}):null,!p&&J.length>0?t.jsx("div",{className:"workspace-inbox-list",children:J.map(v=>t.jsxs("article",{className:"workspace-inbox-item",children:[t.jsxs("div",{className:"workspace-inbox-item-header",children:[t.jsxs("div",{children:[t.jsx("strong",{children:v.title}),t.jsx("p",{children:v.projectName})]}),t.jsxs("div",{className:"workspace-inbox-item-badges",children:[t.jsx("span",{className:"workspace-inbox-badge",children:Qo(v.status)}),t.jsx("span",{className:"workspace-inbox-badge",children:ch(v.itemType)})]})]}),t.jsx("p",{className:"workspace-inbox-item-content",children:v.content}),t.jsxs("div",{className:"workspace-inbox-item-footer",children:[t.jsx("span",{children:dh(v.updatedAt)}),t.jsxs("div",{className:"workspace-inbox-item-actions",children:[t.jsx("div",{className:"workspace-inbox-status-quick-actions",role:"group","aria-label":r("shell.butlerInboxQuickStatusLabel"),children:["pending","in_progress","closed"].map(S=>{const X=v.status===S;return t.jsx("button",{type:"button",className:"secondary-button","data-active":X,disabled:N,onClick:()=>{D(v,S)},children:Qo(S)},`${v.id}:${S}`)})}),t.jsx("button",{type:"button",className:"secondary-button",disabled:N,onClick:()=>ue(v),children:r("shell.butlerInboxEditAction")}),t.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:N,onClick:()=>{ce(v.id)},children:r("shell.butlerInboxDeleteAction")})]})]})]},v.id))}):null]}),c?t.jsx($e,{open:e&&h,title:x?r("shell.butlerInboxEditingTitle"):r("shell.butlerInboxCreateTitle"),description:r("shell.butlerInboxFormDescription"),className:"workspace-inbox-modal-card workspace-inbox-composer-modal-card",onClose:()=>{f==null||f(!1),E()},children:t.jsx("div",{className:"workspace-inbox-composer-modal-body",children:t.jsx(Xo,{selectableProjects:j,formState:K,saving:N,editingItemId:x,useMobilePicker:!0,onProjectChange:v=>{Y(S=>({...S,projectId:v}))},onItemTypeChange:v=>{Y(S=>({...S,itemType:v}))},onStatusChange:v=>{Y(S=>({...S,status:v}))},onTitleChange:v=>{Y(S=>({...S,title:v}))},onContentChange:v=>{Y(S=>({...S,content:v}))},onCancel:()=>{f==null||f(!1),E()},onSubmit:U})})}):null]})}function Xo(e){const n=e.selectableProjects.map(o=>({value:o.id,label:o.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")}],i=[{value:"pending",label:r("shell.butlerInboxStatusPending")},{value:"in_progress",label:r("shell.butlerInboxStatusInProgress")},{value:"closed",label:r("shell.butlerInboxStatusClosed")}];return t.jsxs(t.Fragment,{children:[t.jsxs("header",{className:"workspace-inbox-panel-header",children:[t.jsx("h3",{children:e.editingItemId?r("shell.butlerInboxEditingTitle"):r("shell.butlerInboxCreateTitle")}),t.jsx("p",{children:r("shell.butlerInboxFormDescription")})]}),e.selectableProjects.length===0?t.jsx("p",{className:"workspace-inbox-status",children:r("shell.butlerInboxProjectsEmpty")}):t.jsxs("form",{className:"workspace-inbox-form",onSubmit:e.onSubmit,children:[t.jsx("div",{className:"workspace-inbox-form-grid",children:e.useMobilePicker?t.jsxs(t.Fragment,{children:[t.jsx(ji,{label:r("shell.butlerInboxProjectLabel"),value:e.formState.projectId,options:n,disabled:e.saving,onChange:e.onProjectChange}),t.jsx(ji,{label:r("shell.butlerInboxTypeLabel"),value:e.formState.itemType,options:s,disabled:e.saving,onChange:e.onItemTypeChange}),t.jsx(ji,{label:r("shell.butlerInboxStatusLabel"),value:e.formState.status,options:i,disabled:e.saving,onChange:e.onStatusChange})]}):t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.butlerInboxProjectLabel")}),t.jsx("select",{value:e.formState.projectId,disabled:e.saving,onChange:o=>e.onProjectChange(o.target.value),children:e.selectableProjects.map(o=>t.jsx("option",{value:o.id,children:o.name},o.id))})]}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.butlerInboxTypeLabel")}),t.jsxs("select",{value:e.formState.itemType,disabled:e.saving,onChange:o=>e.onItemTypeChange(o.target.value),children:[t.jsx("option",{value:"task",children:r("shell.butlerInboxTypeTask")}),t.jsx("option",{value:"bug",children:r("shell.butlerInboxTypeBug")}),t.jsx("option",{value:"feature",children:r("shell.butlerInboxTypeFeature")}),t.jsx("option",{value:"change",children:r("shell.butlerInboxTypeChange")})]})]}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.butlerInboxStatusLabel")}),t.jsxs("select",{value:e.formState.status,disabled:e.saving,onChange:o=>e.onStatusChange(o.target.value),children:[t.jsx("option",{value:"pending",children:r("shell.butlerInboxStatusPending")}),t.jsx("option",{value:"in_progress",children:r("shell.butlerInboxStatusInProgress")}),t.jsx("option",{value:"closed",children:r("shell.butlerInboxStatusClosed")})]})]})]})}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.butlerInboxTitleLabel")}),t.jsx("input",{value:e.formState.title,placeholder:r("shell.butlerInboxTitlePlaceholder"),disabled:e.saving,onChange:o=>e.onTitleChange(o.target.value)})]}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.butlerInboxContentLabel")}),t.jsx("textarea",{rows:4,value:e.formState.content,placeholder:r("shell.butlerInboxContentPlaceholder"),disabled:e.saving,onChange:o=>e.onContentChange(o.target.value)})]}),t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:e.saving,onClick:e.onCancel,children:e.editingItemId?r("shell.butlerInboxCancelEditAction"):r("common.cancel")}),t.jsx("button",{type:"submit",className:"primary-button",disabled:e.saving||!e.formState.projectId,children:e.editingItemId?r("shell.butlerInboxUpdateAction"):r("shell.butlerInboxCreateAction")})]})]})]})}function ji({label:e,value:n,options:s,disabled:i,onChange:o}){const[c,h]=l.useState(!1),f=s.find(k=>k.value===n)??s[0]??null;return l.useEffect(()=>{if(!c)return;function k(p){p.key==="Escape"&&h(!1)}return window.addEventListener("keydown",k),()=>{window.removeEventListener("keydown",k)}},[c]),t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"workbench-modal-field workspace-inbox-mobile-picker",children:[t.jsx("span",{children:e}),t.jsxs("button",{type:"button",className:"workspace-inbox-mobile-picker-trigger","aria-label":e,"aria-haspopup":"dialog","aria-expanded":c,disabled:i||s.length===0,onClick:()=>h(!0),children:[t.jsx("span",{className:"workspace-inbox-mobile-picker-trigger-value",children:(f==null?void 0:f.label)??""}),t.jsx("span",{className:"workspace-inbox-mobile-picker-trigger-icon",children:t.jsx(ah,{expanded:c})})]})]}),t.jsx(ih,{open:c,title:e,options:s,selectedValue:n,onClose:()=>h(!1),onSelect:k=>{o(k),h(!1)}})]})}function ih({open:e,title:n,options:s,selectedValue:i,onClose:o,onSelect:c}){return e?t.jsx(mc,{open:e,title:n,kind:"picker",height:"half",className:"workspace-inbox-picker-sheet",cardClassName:"workspace-inbox-picker-sheet-card",bodyClassName:"workspace-inbox-picker-sheet-body",showHandle:!0,onClose:o,children:t.jsx(pc,{className:"workspace-inbox-picker-sheet-options",role:"listbox","aria-label":n,children:s.map(h=>{const f=h.value===i;return t.jsx(bc,{as:"button",className:"workspace-inbox-picker-option",role:"option","aria-selected":f,selected:f,trailing:t.jsx("span",{className:"workspace-inbox-picker-option-indicator","aria-hidden":"true",children:f?t.jsx(lh,{}):null}),onClick:()=>c(h.value),children:t.jsxs("span",{className:"workspace-inbox-picker-option-copy",children:[t.jsx("strong",{children:h.label}),h.description?t.jsx("span",{children:h.description}):null]})},h.value)})})}):null}function Jm({open:e,preferredWorkspaceId:n,preferredSessionId:s,creationRequestId:i=0,initialDraft:o=null,onClose:c,compactComposer:h=!1}){const[f,k]=l.useState(0),[p,w]=l.useState(!h);return l.useEffect(()=>{e||w(!h)},[h,e]),t.jsx($e,{open:e,title:r("shell.butlerInboxModalTitle"),description:r("shell.butlerInboxModalDescription"),className:"workspace-inbox-modal-card",showCloseButton:!h,headerActions:h?t.jsx("button",{type:"button",className:"workspace-inbox-modal-create-button","aria-label":r("shell.butlerInboxCreateAction"),title:r("shell.butlerInboxCreateAction"),onClick:()=>{k(N=>N+1),w(!0)},children:t.jsx(oh,{})}):void 0,onClose:c,children:t.jsx(Sl,{active:e,preferredWorkspaceId:n,preferredSessionId:s,creationRequestId:Math.max(i,f),initialDraft:o,compactComposer:h,composerOpen:p,onComposerOpenChange:w})})}function Yo(e,n,s){return[...e].filter(i=>i.lifecycleStatus!=="archived").sort((i,o)=>{const c=Jo(i,n,s),h=Jo(o,n,s);return c!==h?h-c:i.name.localeCompare(o.name,"zh-Hans-CN")})}function Jo(e,n,s){return s&&e.id===s?2:n&&e.workspaceId===n?1:0}function Zo({projects:e,currentProjectId:n,preferredProjectId:s,preferredWorkspaceId:i}){var c;if(n&&e.some(h=>h.id===n))return n;if(s&&e.some(h=>h.id===s))return s;const o=i?e.find(h=>h.workspaceId===i):null;return(o==null?void 0:o.id)||((c=e[0])==null?void 0:c.id)||""}function oh(){return t.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8","aria-hidden":"true",children:[t.jsx("path",{d:"M12 5v14"}),t.jsx("path",{d:"M5 12h14"})]})}function ah({expanded:e}){return t.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true","data-expanded":e?"true":void 0,children:t.jsx("path",{d:"M3.5 6 8 10l4.5-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function lh(){return t.jsx("svg",{viewBox:"0 0 16 16","aria-hidden":"true",children:t.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 ch(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 dh(e){return new Date(e).toLocaleString()}function uh({open:e,onClose:n,onImported:s}){const{showToast:i}=Xn(),[o,c]=l.useState(!1),[h,f]=l.useState(!1),[k,p]=l.useState(!1),[w,N]=l.useState(null),[C,R]=l.useState(""),[O,H]=l.useState(""),[W,x]=l.useState(null),[A,I]=l.useState([]),[G,K]=l.useState([]),[Y,z]=l.useState(!1),[q,j]=l.useState(""),J=o||h||k,Q=l.useCallback(async S=>{c(!0),N(null);try{const X=await Fa(S);R(X.currentPath),H(X.currentPath),x(X.parentPath),I(X.roots),K(X.items)}catch(X){R(""),x(null),K([]),N(X instanceof Error?X.message:r("shell.importBrowserBrowseFailed"))}finally{c(!1)}},[]);l.useEffect(()=>{if(!e){z(!1),j(""),N(null);return}Q(C||void 0)},[Q,e]);function E(){J||(z(!1),j(""),n())}async function ue(S){S.preventDefault(),await Q(O)}function U(){!C||J||(j(""),z(!0))}function ce(){h||(z(!1),j(""))}async function D(S){S==null||S.preventDefault();const X=q.trim();if(!(!C||!X||J)){f(!0),N(null);try{const ke=await gc({parentPath:C,directoryName:X});i({title:r("shell.importBrowserCreateDirectorySuccess"),description:ke.path,tone:"success"}),z(!1),j(""),await Q(ke.path)}catch(ke){const we=ke instanceof Error?ke.message:r("shell.importBrowserCreateDirectoryFailed");N(we),i({title:we,tone:"error"})}finally{f(!1)}}}async function v(){const S=C.trim();if(!(!S||J)){p(!0),N(null);try{const X=await kc({path:S});i({title:r("shell.importSuccess"),description:X.path,tone:"success"}),n(),Promise.resolve().then(()=>s==null?void 0:s(X)).catch(ke=>{i({title:ke instanceof Error?ke.message:r("shell.navigationLoadFailed"),tone:"error"})})}catch(X){i({title:X instanceof Error?X.message:r("shell.importFailed"),tone:"error"})}finally{p(!1)}}}return t.jsxs(t.Fragment,{children:[t.jsxs($e,{open:e,title:r("shell.importBrowserTitle"),description:r("shell.importBrowserDescription"),onClose:E,children:[t.jsxs("form",{className:"workbench-directory-browser-form",onSubmit:ue,children:[t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.importBrowserCurrentPath")}),t.jsx("input",{type:"text",value:O,placeholder:r("shell.importPathPlaceholder"),onChange:S=>H(S.target.value)})]}),t.jsxs("div",{className:"workbench-directory-browser-toolbar",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:J||!W,onClick:()=>{W&&Q(W)},children:r("shell.importBrowserOpenParent")}),t.jsx("button",{type:"submit",className:"secondary-button",disabled:J,children:r("shell.importBrowserOpenPath")}),t.jsx("button",{type:"button",className:"secondary-button",disabled:J||!C,onClick:U,children:r("shell.importBrowserCreateDirectory")})]})]}),t.jsxs("section",{className:"workbench-directory-browser-panel",children:[t.jsxs("div",{className:"workbench-directory-browser-section",children:[t.jsx("span",{className:"workbench-directory-browser-section-title",children:r("shell.importBrowserRoots")}),t.jsx("div",{className:"workbench-directory-browser-root-list",children:A.map(S=>t.jsx("button",{type:"button",className:"workbench-directory-browser-chip",disabled:J,onClick:()=>{Q(S.path)},children:S.name},S.path))})]}),t.jsx("div",{className:"workbench-directory-browser-current-path",children:C}),w?t.jsx("p",{className:"workbench-directory-browser-status status-text","data-tone":"error",children:w}):null,o?t.jsx("p",{className:"workbench-directory-browser-status status-text",children:r("common.loading")}):G.length>0?t.jsx("div",{className:"workbench-directory-browser-list",children:G.map(S=>t.jsxs("button",{type:"button",className:"workbench-directory-browser-item",disabled:J,onClick:()=>{Q(S.path)},children:[t.jsx("span",{className:"workbench-directory-browser-item-name",children:S.name}),t.jsx("span",{className:"workbench-directory-browser-item-path",children:S.path})]},S.path))}):t.jsx("p",{className:"workbench-directory-browser-status status-text",children:r("shell.importBrowserEmpty")})]}),t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:J,onClick:E,children:r("common.cancel")}),t.jsx("button",{type:"button",className:"primary-button",disabled:J||!C,onClick:()=>{v()},children:k?r("shell.importSubmitting"):r("shell.importBrowserSubmit")})]})]}),t.jsx($e,{open:e&&Y,title:r("shell.importBrowserCreateDirectoryTitle"),description:r("shell.importBrowserCreateDirectoryDescription"),onClose:ce,children:t.jsxs("form",{className:"workbench-rename-form",onSubmit:S=>void D(S),children:[t.jsx("div",{className:"workbench-directory-browser-current-path",children:C}),t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.importBrowserCreateDirectoryLabel")}),t.jsx("input",{type:"text",value:q,placeholder:r("shell.importBrowserCreateDirectoryPlaceholder"),autoFocus:!0,onChange:S=>j(S.target.value)})]}),t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:h,onClick:ce,children:r("common.cancel")}),t.jsx("button",{type:"submit",className:"primary-button",disabled:h||!q.trim(),children:h?r("shell.importBrowserCreatingDirectory"):r("shell.importBrowserCreateDirectorySubmit")})]})]})})]})}function hh({onOpenSoftwareUpdate:e}){var i;const n=Oi(o=>o.platform),s=cc(o=>o.latestState);return n!=="desktop"||!(s!=null&&s.hasUpdate)?null:t.jsx("button",{className:"workbench-nav-update-badge",type:"button",title:((i=s.manifest)==null?void 0:i.version)??r("settings.releaseUpdateReady"),onClick:e,children:t.jsx("span",{className:"workbench-nav-update-badge-label",children:r("settings.releaseUpdateBadge")})})}const ea="workbench.left.width",ta="workbench.right.width",na="workbench.left.collapsed",sa="workbench.right.collapsed",Fr="workbench.last.session.path",Ni="workbench.workspace.selected.id",ra="workbench.notifications.seen_at",fh=280,mh=320,ia=240,oa=280,aa=520,la=560,ph=200,Ci=20,qs=40,Or=5,bh=3e4,kh=12,ca=60*1e3,gh=4e3,da=220,ua=18,wh=6,bs="data-workbench-panel-resizing",Hr="data-workbench-window-resizing",xh=180,vh="workbench:focus-composer",yh=new Set(["starting","running","reconnecting","stale","unknown"]),Sh=["#34C759","#22C55E","#14B8A6","#06B6D4","#0EA5E9","#3B82F6","#6366F1","#8B5CF6","#A855F7","#D946EF","#EC4899","#F43F5E","#EF4444","#F97316","#F59E0B","#EAB308","#84CC16","#10B981"],jh=["--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"],Me={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 jl(e,n){const s=e.getPropertyValue(n).trim();if(!s)return null;const i=Number.parseFloat(s);return Number.isFinite(i)?i:null}function Nh(e){return Math.round(e*100)/100}function Ch(e,n){const s=n.getBoundingClientRect();if(s.width<=0||s.height<=0)return null;const i=window.getComputedStyle(n);return i.display==="none"||i.visibility==="hidden"?null:s.top-e.top+s.height/2}function yn(e,n){const s=e.getBoundingClientRect(),o=Array.from(e.querySelectorAll(n)).map(c=>Ch(s,c)).filter(c=>c!==null);return o.length===0?null:o.reduce((c,h)=>c+h,0)/o.length}function Ht(e,n,s){const i=e.style.getPropertyValue(n).trim();if(s===null||!Number.isFinite(s)){i&&e.style.removeProperty(n);return}const o=`${Nh(s)}px`;i!==o&&e.style.setProperty(n,o)}function Ut(e,n,s,i){return i===null?null:(jl(e,n)??0)+(s-i)}function ha(e){if(e)for(const n of jh)e.style.removeProperty(n)}function Th(e){return yh.has(e.runningState??"idle")||e.activityState==="running"}function Ih(e,n){const s=[];for(const i of[...n].sort()){const o=e.get(i);!o||o.size===0||s.push(`${i}:${[...o].sort().join(",")}`)}return s.join("|")}function Rh(e){var o,c;const n=((o=e.lastErrorCode)==null?void 0:o.trim())??"",s=((c=e.lastErrorDetail)==null?void 0:c.trim())??"",i=[n,s].filter(h=>h.length>0).join(" · ");return i?i.length<=da?i:`${i.slice(0,da-3)}...`:null}function Mh(e,n,s){var c,h,f,k,p,w,N,C,R,O,H,W;const i=new Map(e.projects.map(x=>[x.id,x.workspaceId])),o=[];for(const x of s){const A=x.title.trim()||x.projectName;if(x.assistantState.lifecycleStage==="analyzed"&&!((c=x.assistantState.linkedSessionId)!=null&&c.trim())&&x.assistantState.lastAnalyzedAt){o.push({id:`todo-analysis-completed:${x.id}:${x.assistantState.lastAnalyzedAt}`,kind:"todo_analyzed",title:r("shell.globalNotificationTodoAnalyzedTitle",{title:A}),body:((h=x.assistantState.analysisSummary)==null?void 0:h.trim())||((f=x.assistantState.generatedPrompt)==null?void 0:f.trim())||x.content,routePath:Vn(x.workspaceId),workspaceId:x.workspaceId,createdAt:x.assistantState.lastAnalyzedAt});continue}x.assistantState.lifecycleStage==="failed"&&o.push({id:`todo-analysis-failed:${x.id}:${x.updatedAt}`,kind:"todo_analyze_failed",title:r("shell.globalNotificationTodoAnalyzeFailedTitle",{title:A}),body:((k=x.assistantState.lastError)==null?void 0:k.trim())||x.content,routePath:Vn(x.workspaceId),workspaceId:x.workspaceId,createdAt:x.updatedAt})}for(const x of n){const A=((p=x.sessionTitle)==null?void 0:p.trim())||x.projectName,I=x.updatedAt||x.lastAutomationAt||x.createdAt;if(x.status==="waiting_user"){o.push({id:`follow-up-waiting:${x.id}`,kind:"follow_up_waiting_user",title:r("shell.globalNotificationFollowUpWaitingTitle",{title:A}),body:((w=x.waitingReason)==null?void 0:w.trim())||((N=x.lastAutomationSummary)==null?void 0:N.trim())||x.objective,routePath:$t(x.workspaceId,x.sessionId),workspaceId:x.workspaceId,createdAt:I});continue}if(x.status==="completed"){o.push({id:`follow-up-completed:${x.id}`,kind:"follow_up_completed",title:r("shell.globalNotificationFollowUpCompletedTitle",{title:A}),body:((C=x.lastAutomationSummary)==null?void 0:C.trim())||x.objective,routePath:$t(x.workspaceId,x.sessionId),workspaceId:x.workspaceId,createdAt:I});continue}x.status==="failed"&&o.push({id:`follow-up-failed:${x.id}`,kind:"follow_up_failed",title:r("shell.globalNotificationFollowUpFailedTitle",{title:A}),body:((R=x.lastAutomationSummary)==null?void 0:R.trim())||((O=x.waitingReason)==null?void 0:O.trim())||x.objective,routePath:$t(x.workspaceId,x.sessionId),workspaceId:x.workspaceId,createdAt:I})}for(const x of e.verifications){if(x.status!=="failed")continue;const A=x.projectId?i.get(x.projectId)??null:null,I=((H=x.targetRef)==null?void 0:H.trim())||x.verificationType;o.push({id:`verification-failed:${x.id}`,kind:"verification_failed",title:r("shell.globalNotificationVerificationFailedTitle",{title:I}),body:((W=x.summary)==null?void 0:W.trim())||r("shell.globalNotificationVerificationFailedFallback"),routePath:A?Vn(A):null,workspaceId:A,createdAt:x.finishedAt||x.startedAt||x.createdAt})}return o.sort((x,A)=>{const I=fa(x.kind)-fa(A.kind);return I!==0?I:Cn(A.createdAt)-Cn(x.createdAt)}).slice(0,kh)}function fa(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 Eh(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 Cn(e){if(!e)return 0;const n=new Date(e).getTime();return Number.isNaN(n)?0:n}function Ph(e){return/^(?:[A-Za-z0-9_-]+)(?:\/[A-Za-z0-9_-]+)*$/.test(e)}function Wh(e){return/^(?:[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*\/?)?$/.test(e)}function Ah(e,n){const s=new Set,i=(e==null?void 0:e.currentBranch)??"",o=((e==null?void 0:e.local)??[]).slice().sort((f,k)=>Number(k.current)-Number(f.current)||f.name.localeCompare(k.name)).map(f=>({value:f.name,current:f.current,recommended:f.name===i})).filter(f=>!f.value||s.has(f.value)?!1:(s.add(f.value),!0)),c=((e==null?void 0:e.remote)??[]).map(f=>({value:f.name})).filter(f=>!f.value||s.has(f.value)?!1:(s.add(f.value),!0)),h=n.map(f=>({value:f.name})).filter(f=>!f.value||s.has(f.value)?!1:(s.add(f.value),!0));return{localBranches:o,remoteBranches:c,tags:h}}function Bh(e){return e.getBoundingClientRect()}function Lh(e,n){return n?Cn(e.createdAt)>Cn(n):!0}function Dh(e){const n=new Date(e);return Number.isNaN(n.getTime())?e:new Intl.DateTimeFormat(void 0,{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(n)}function ma(e,n){var h,f;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 p=Se(k,e),w=(h=p==null?void 0:p.params.workspaceId)==null?void 0:h.trim();if(w)return w}const i=Js(e),o=(i==null?void 0:i.sessionId)??null;return!o||!Yl(o)?null:((f=new URLSearchParams(n).get("workspaceId"))==null?void 0:f.trim())||null}function _h(e){return e.startsWith("/sessions")||e.startsWith("/terminals")||e.startsWith("/tools")}function Ti(e){return e==="mobile"?at():"/landing"}function Js(e){var c,h,f;const n=Se("/workspaces/:workspaceId/sessions/:sessionId",e),s=(c=n==null?void 0:n.params.sessionId)==null?void 0:c.trim();if(s)return{sessionId:s,workspaceId:((h=n==null?void 0:n.params.workspaceId)==null?void 0:h.trim())??null};const i=Se("/sessions/:sessionId",e),o=(f=i==null?void 0:i.params.sessionId)==null?void 0:f.trim();return o?{sessionId:o,workspaceId:null}:null}function Fh(e){return!!(Se("/sessions",e)||Se("/workspaces/:workspaceId/sessions",e))}function pa(e){return!!Js(e)}function Oh(e){return!!(Se("/tools",e)||Se("/tools/files",e)||Se("/tools/git",e)||Se("/tools/processes",e)||Se("/workspaces/:workspaceId/tools",e)||Se("/workspaces/:workspaceId/tools/files",e)||Se("/workspaces/:workspaceId/tools/git",e)||Se("/workspaces/:workspaceId/tools/processes",e))}function Li(e){return!!(Se("/terminals",e)||Se("/workspaces/:workspaceId/terminals",e))}function Vr(e){return!!Se("/workspaces/:workspaceId/butler",e)}function Hh(e,n){return Se("/workspaces/:workspaceId/debug",e)?Za(n):Se("/workspaces/:workspaceId",e)?Gt(n):Se("/workspaces/:workspaceId/tools/files",e)||Se("/tools/files",e)?el(n):Se("/workspaces/:workspaceId/tools/git",e)||Se("/tools/git",e)?tl(n):Se("/workspaces/:workspaceId/tools/processes",e)||Se("/tools/processes",e)?nl(n):Se("/workspaces/:workspaceId/tools",e)||Se("/tools",e)?Qa(n):Li(e)?xs(n):Vr(e)?Vn(n):Qs(n)}function Uh(e){return e.trim().replace(/\\/g,"/").replace(/^(?:\.\/)+/,"").replace(/^\/+/,"")}const $h=l.lazy(async()=>({default:(await Hi(()=>import("./FileContextPanel-C8T7oqRN.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]))).FileContextPanel})),qh=l.lazy(async()=>({default:(await Hi(()=>import("./GitSidebar-Bze7DNnc.js"),__vite__mapDeps([10,1,2,3,4,11,5,7,6,8,9]))).GitSidebar})),Gh=l.lazy(async()=>({default:(await Hi(()=>import("./TerminalManagerPanel-PQ-EM64j.js"),__vite__mapDeps([12,1,2,6,3,4,5,13,14,8,9]))).TerminalManagerPanel}));function zh(e){return!!((e==null?void 0:e.item)??(e==null?void 0:e.session))}function Pt(e){return js(e)}function Kh(e){return e&&"item"in e?e.item:(e==null?void 0:e.session)??null}function Ks(e){return Array.isArray(e==null?void 0:e.visibleSessionTree)?e.visibleSessionTree.filter(zh):[]}async function Nl(e,n){const s=await Ic(n,e);if(s.canStartSession===!1)throw new Error(s.limitations[0]??r("conversation.capabilityDenied"))}const Cl=l.createContext(null);function Di(e){return bu(e)}function qt(e){return e.isArchived===!0}function ni(e){var n;return((n=e.parentSessionId)==null?void 0:n.trim())||null}function lo(e,n){return Va(e,{getId:s=>s.sessionId,getParentId:ni,compare:(s,i)=>io(s,i,n)})}function Tl(e){return e.filter(n=>{if(qt(n))return!1;const s=ni(n);if(!s)return!0;const i=e.find(o=>o.sessionId===s);return!i||!qt(i)})}function Vh(e){return e.flatMap(n=>{const s=Kh(n);return s?[s,...Xa(Pt(n))]:[]})}function Xh(e,n,s){const i=new Set(Sn(Pt(e)).sort((o,c)=>io(o.item,c.item,s)).slice(0,n).map(o=>o.item.sessionId));return{...e,children:Il(Pt(e),i)}}function Il(e,n){return e.flatMap(s=>{const i=Il(Pt(s),n);return!n.has(s.item.sessionId)&&i.length===0?[]:[{...s,children:i}]})}function Ur(e,n,s,i=-1){if(e<=0)return 0;const o=i>=0?Math.max(n,i+1):n;return Math.min(e,Math.max(s??0,o))}function ba(e,n){const s=Object.keys(e),i=Object.keys(n);return s.length!==i.length?!1:s.every(o=>e[o]===n[o])}function Yh(e){const n=e.lastMessageAt??e.updatedAt;return n?new Date(n).toLocaleDateString():""}function Jh(e){return no(e)||e.syncStatus==="error"}function Zh(e){var i,o;if(!Jh(e))return null;const n=((i=e.lastErrorCode)==null?void 0:i.trim())??"",s=((o=e.lastErrorDetail)==null?void 0:o.replace(/\s+/g," ").trim())??"";return n&&s&&!s.includes(n)?`${n} · ${s}`:s||n||(e.syncStatus==="error"&&!no(e)?r("conversation.syncStatusError"):r("conversation.runtimeErrorTitle"))}function Qh(e,n=110){return e.length<=n?e:`${e.slice(0,Math.max(0,n-1)).trimEnd()}…`}function si(e,n="compact"){return Tc(e,n)}const ef={position:"relative",zIndex:0},tf={zIndex:1};function Rl(e,n,s,i){const o=[],c=(i==null?void 0:i.trim())||n.name;s&&o.push(c);const h=Yh(e);return h&&o.push(h),o.join(" · ")||c}function ka(e,n){return du("session-state-indicator",e,n)}function nf(e,n){return bl(e,n)}function ga(e,n){try{const s=window.localStorage.getItem(e),i=s?Number(s):Number.NaN;return Number.isFinite(i)?i:n}catch{return n}}function wa(e,n){try{const s=window.localStorage.getItem(e);return s===null?n:s==="true"}catch{return n}}function xa(e){var n;try{const s=(n=window.localStorage.getItem(e))==null?void 0:n.trim();return s||null}catch{return null}}function Kn(e,n){try{window.localStorage.setItem(e,n)}catch{}}function sf(e){try{window.localStorage.removeItem(e)}catch{}}function $r(e,n,s){return Math.max(n,Math.min(s,e))}function qr(e){const n=Number.parseFloat(e);return Number.isFinite(n)?n:0}function rf(e){const n=window.getComputedStyle(e),s=qr(n.getPropertyValue("--desktop-macos-titlebar-height")),i=qr(n.getPropertyValue("--workbench-header-min-height")),o=qr(n.getPropertyValue("--workbench-macos-titlebar-padding-top")),c=qr(n.getPropertyValue("--workbench-macos-titlebar-padding-bottom"));return Math.max(s,i,40)+o+c+8}function va(e,n){const s=n.getBoundingClientRect();return e>=s.top&&e<=s.top+rf(n)}function of(e){return e instanceof HTMLElement?e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement||!!e.closest("[contenteditable='true']"):!1}function af(){typeof window>"u"||window.dispatchEvent(new CustomEvent(vh))}function Ml(e,n){const s=n==null?void 0:n.trim();if(!s)return null;for(const i of e){if(i.workspace.id===s)return i;const o=Ml(i.children,s);if(o)return o}return null}function lf(e,n){const s=n==null?void 0:n.trim();if(!s)return null;for(const i of e){const o=Ml(i.childWorktrees,s);if(o)return o}return null}function ya(e){return!e||!Array.isArray(e.items)?[]:e.items.filter(n=>{var s;return n.collapsed===!0&&((s=n.workspace)==null?void 0:s.id)}).map(n=>n.workspace.id)}function Ii(e,n){const s=new Set(n);return{items:e.map(i=>({workspace:i.workspace,sessions:i.sessions,childWorktrees:i.childWorktrees,collapsed:s.has(i.workspace.id)}))}}function El(e,n,s){return e.map(i=>{const o=Tl(i.sessions);return{workspace:i.workspace,meta:i.meta,visibleSessions:o,archivedSessions:i.sessions.filter(c=>qt(c)&&!ni(c)),visibleSessionTree:lo(o,s).filter(c=>!n.has(c.item.sessionId)&&!Vi(Pt(c),h=>n.has(h.sessionId))),children:El(i.children,n,s)}})}function _i(e){return e.flatMap(n=>[n.workspace.id,..._i(n.children)])}function Vs(e){return e.flatMap(n=>[...n.visibleSessionTree,...Vs(n.children)])}function cf(e,n){if(!n)return null;for(const s of e){if(s.workspace.id===n)return{workspace:s.workspace,visibleSessionTree:Ks(s)};const i=Wl(s.childWorktrees,n);if(i)return i}return null}function Pl(e,n){for(const s of e){const i=Sn(s.visibleSessionTree).find(c=>c.item.sessionId===n);if(i)return i;const o=Pl(s.children,n);if(o)return o}return null}function Wl(e,n){for(const s of e){if(s.workspace.id===n)return{workspace:s.workspace,visibleSessionTree:s.visibleSessionTree};const i=Wl(s.children,n);if(i)return i}return null}function df(e,n){if(!n)return null;for(const s of e){if(s.workspace.id===n)return{workspace:s.workspace,archivedSessions:s.archivedSessions};const i=Al(s.childWorktrees,n);if(i)return i}return null}function Sa(e,n){if(!n)return null;for(const s of e){if(s.workspace.id===n)return s.workspace;const i=Bl(s.childWorktrees,n);if(i)return i}return null}function Al(e,n){for(const s of e){if(s.workspace.id===n)return{workspace:s.workspace,archivedSessions:s.archivedSessions};const i=Al(s.children,n);if(i)return i}return null}function Bl(e,n){for(const s of e){if(s.workspace.id===n)return s.workspace;const i=Bl(s.children,n);if(i)return i}return null}function Ll(e,n){for(const s of e){if(s.workspace.id===n)return[s.workspace.id];const i=Ll(s.children,n);if(i.length>0)return[s.workspace.id,...i]}return[]}function ja(e){return e.flatMap(n=>[n.workspace.id,...Dl(n.childWorktrees)])}function Dl(e){return e.flatMap(n=>[n.workspace.id,...Dl(n.children)])}function uf(e,n=[]){if(e.tone!=="worktree")return e.rootDisplayName;if(n.length>0)return n.join(" / ");const s=[e.rootDisplayName];return e.parentDisplayName&&e.parentDisplayName!==e.rootDisplayName&&s.push(e.parentDisplayName),s.join(" / ")}function hf(e,n,s,i){if(n===s)return e;const o=e.findIndex(p=>p.workspace.id===n),c=e.findIndex(p=>p.workspace.id===s);if(o<0||c<0)return e;const h=[...e],[f]=h.splice(o,1);if(!f)return e;const k=h.findIndex(p=>p.workspace.id===s);return k<0?e:(h.splice(i==="before"?k:k+1,0,f),h.every((p,w)=>{var N;return p.workspace.id===((N=e[w])==null?void 0:N.workspace.id)})?e:h)}function ff(e,n){if(!Array.isArray(e.items)||n.size===0)return e;let s=!1;const i=e.items.map(o=>{let c=!1;const h=o.sessions.map(k=>{const p=n.get(k.sessionId);return p===void 0||qt(k)===p?k:(s=!0,c=!0,{...k,isArchived:p})}),f=Fl(o.childWorktrees??[],n,k=>{k&&(s=!0,c=!0)});return c?{...o,sessions:h,childWorktrees:f}:o});return s?{...e,items:i}:e}function mf(e,n){if(!(!Array.isArray(n.items)||e.size===0))for(const s of n.items){for(const i of s.sessions){const o=e.get(i.sessionId);o!==void 0&&qt(i)===o&&e.delete(i.sessionId)}Ol(e,s.childWorktrees??[])}}function pf(e,n,s){let i=!1;const o=e.map(c=>{if(c.workspace.id!==n.workspaceId){const{nodes:k,changed:p}=Hl(c.childWorktrees,n,s);return p?(i=!0,{...c,childWorktrees:k}):c}const h=c.sessions.findIndex(k=>k.sessionId===n.sessionId),f=h>=0?c.sessions.map((k,p)=>p===h?n:k):[n,...c.sessions];return i=!0,{...c,sessions:rr(f,s)}});return i?o:e}function bf(e,n,s){let i=!1;const o=e.map(c=>{let h=!1;const f=c.sessions.map(p=>p.sessionId!==n?p:(i=!0,h=!0,{...p,lastSeenAt:p.lastSeenAt&&p.lastSeenAt>s?p.lastSeenAt:s,activityState:p.activityState==="completed_unread"?"idle":p.activityState})),k=ri(c.childWorktrees,p=>p.sessionId!==n?p:(i=!0,h=!0,{...p,lastSeenAt:p.lastSeenAt&&p.lastSeenAt>s?p.lastSeenAt:s,activityState:p.activityState==="completed_unread"?"idle":p.activityState}));return h?{...c,sessions:f,childWorktrees:k}:c});return i?o:e}function Na(e,n,s){let i=!1;const o=e.map(c=>{let h=!1;const f=c.sessions.map(p=>p.sessionId!==n||p.isArchived===s?p:(i=!0,h=!0,{...p,isArchived:s})),k=ri(c.childWorktrees,p=>p.sessionId!==n||p.isArchived===s?p:(i=!0,h=!0,{...p,isArchived:s}));return h?{...c,sessions:f,childWorktrees:k}:c});return i?o:e}function Ca(e,n,s){let i=!1;const o=e.map(c=>{let h=!1;const f=c.sessions.map(p=>p.sessionId!==n||p.isFavorite===!0===s?p:(i=!0,h=!0,{...p,isFavorite:s})),k=ri(c.childWorktrees,p=>p.sessionId!==n||p.isFavorite===!0===s?p:(i=!0,h=!0,{...p,isFavorite:s}));return h?{...c,sessions:f,childWorktrees:k}:c});return i?o:e}function kf(e,n){return e.includes(n)?e.filter(s=>s!==n):[...e,n]}function gf(e){return e?e.slice(0,8):"--"}function Ta(e,n,s){return s?e.includes(n)?e:[...e,n]:e.includes(n)?e.filter(i=>i!==n):e}function _l(e,n){const s=e.filter(i=>n.has(i));return s.length===e.length?e:s}function Fl(e,n,s){return e.map(i=>{let o=!1;const c=i.sessions.map(f=>{const k=n.get(f.sessionId);return k===void 0||qt(f)===k?f:(o=!0,{...f,isArchived:k})}),h=Fl(i.children,n,f=>{f&&(o=!0)});return s(o),o?{...i,sessions:c,children:h}:i})}function Ol(e,n){for(const s of n){for(const i of s.sessions){const o=e.get(i.sessionId);o!==void 0&&qt(i)===o&&e.delete(i.sessionId)}Ol(e,s.children)}}function Hl(e,n,s){let i=!1;const o=e.map(c=>{if(c.workspace.id===n.workspaceId){const f=c.sessions.findIndex(p=>p.sessionId===n.sessionId),k=f>=0?c.sessions.map((p,w)=>w===f?n:p):[n,...c.sessions];return i=!0,{...c,sessions:rr(k,s)}}const h=Hl(c.children,n,s);return h.changed?(i=!0,{...c,children:h.nodes}):c});return{nodes:i?o:[...e],changed:i}}function wf(e,n){return e.map(s=>({...s,sessions:rr(s.sessions,n),childWorktrees:oo(s.childWorktrees,n)}))}function ri(e,n){let s=!1;const i=e.map(o=>{let c=!1;const h=o.sessions.map(k=>{const p=n(k);return p!==k&&(c=!0,s=!0),p}),f=ri(o.children,n);return f!==o.children&&(c=!0,s=!0),c?{...o,sessions:h,children:f}:o});return s?i:[...e]}function Fi(e){return`workspace-management.summary.${e}`}function Ul(e){return`git-sidebar.snapshot.${e}`}function $l(e,n){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 ql(e,n){const s=e.git.repoRoot??n.repoRoot??null;return{...e,workspaceId:n.id,name:n.name,path:n.path,git:{...e.git,isRepository:e.git.isRepository||!!s,repoRoot:s}}}function Gl(e,n){var o,c,h;const s=((o=n.status)==null?void 0:o.snapshot.repoRoot)??e.git.repoRoot,i=((c=n.status)==null?void 0:c.snapshot.branch)??((h=n.branches)==null?void 0:h.currentBranch)??e.git.currentBranch??null;return{...e,git:{...e.git,isRepository:e.git.isRepository||!!s,repoRoot:s,currentBranch:i,error:null}}}function zl({count:e,className:n="workbench-skeleton-lines"}){return t.jsx("div",{className:n,"aria-hidden":"true",children:Array.from({length:e},(s,i)=>t.jsx("span",{className:"skeleton-line"},i))})}function xf(){return t.jsx("div",{className:"workbench-nav-loading","aria-hidden":"true",children:Array.from({length:3},(e,n)=>t.jsxs("section",{className:"workbench-skeleton-card",children:[t.jsxs("div",{className:"workbench-skeleton-heading",children:[t.jsx("span",{className:"skeleton-line short"}),t.jsx("span",{className:"skeleton-line tiny"})]}),t.jsx("div",{className:"workbench-skeleton-list",children:Array.from({length:3},(s,i)=>t.jsxs("div",{className:"workbench-skeleton-session",children:[t.jsx("span",{className:"workbench-skeleton-dot"}),t.jsx(zl,{count:2,className:"workbench-skeleton-lines compact"})]},i))})]},n))})}function Gr(){return t.jsx("section",{className:"workbench-info-skeleton","aria-hidden":"true",children:Array.from({length:4},(e,n)=>t.jsxs("article",{className:"workbench-info-skeleton-card",children:[t.jsx("span",{className:"skeleton-line short"}),t.jsx(zl,{count:3})]},n))})}function vf({side:e,collapsed:n}){const s=e==="left"?8.5:15.5,i=e==="left"?n?"12 9 15 12 12 15":"15 9 12 12 15 15":n?"12 9 9 12 12 15":"9 9 12 12 9 15";return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),t.jsx("line",{x1:s,y1:"4",x2:s,y2:"20"}),t.jsx("polyline",{points:i})]})}function Ia({ariaLabel:e,side:n,collapsed:s,className:i="panel-icon-button",onClick:o}){return t.jsx("button",{className:i,type:"button","aria-label":e,title:e,onClick:o,children:t.jsx(vf,{side:n,collapsed:s})})}function Xs({expanded:e}){return t.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:t.jsx("polyline",{points:"6 9 12 15 18 9"})})}function yf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),t.jsx("polyline",{points:"7 10 12 15 17 10"}),t.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}function Sf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.jsx("rect",{x:"4",y:"5",width:"16",height:"14",rx:"2"}),t.jsx("line",{x1:"8",y1:"10",x2:"16",y2:"10"}),t.jsx("line",{x1:"8",y1:"14",x2:"12",y2:"14"}),t.jsx("circle",{cx:"17.5",cy:"15.5",r:"2.5"})]})}function jf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.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"}),t.jsx("path",{d:"M10 18.5a2 2 0 0 0 4 0",strokeLinecap:"round"})]})}function Kl(e){return t.jsx("div",{className:"workbench-notification-anchor",children:t.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:[t.jsx(jf,{}),e.unreadCount>0?t.jsx("span",{className:"workbench-notification-badge","aria-label":r("shell.globalNotificationsUnreadAria",{count:String(e.unreadCount)}),children:e.unreadCount>99?"99+":e.unreadCount}):null]})})}function Nf(e){const[n,s]=l.useState("notifications");l.useEffect(()=>{e.open&&s("notifications")},[e.open]);const i=l.useMemo(()=>e.notifications.filter(o=>e.showArchivedNotifications||!e.archivedNotificationIds.has(o.id)),[e.archivedNotificationIds,e.notifications,e.showArchivedNotifications]);return t.jsxs($e,{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:[t.jsxs("div",{className:"workbench-notification-tabs",role:"tablist","aria-label":r("shell.globalNotificationsPanelTitle"),children:[t.jsx("button",{type:"button",className:n==="notifications"?"workbench-notification-tab active":"workbench-notification-tab",role:"tab","aria-selected":n==="notifications",onClick:()=>s("notifications"),children:r("shell.globalNotificationsAction")}),t.jsx("button",{type:"button",className:n==="inbox"?"workbench-notification-tab active":"workbench-notification-tab",role:"tab","aria-selected":n==="inbox",onClick:()=>s("inbox"),children:r("shell.butlerInboxAction")})]}),t.jsx("div",{className:"workbench-notification-content","data-tab":n,children:n==="notifications"?t.jsxs("div",{className:"workbench-notification-pane",role:"tabpanel","aria-label":r("shell.globalNotificationsAction"),children:[t.jsx("div",{className:"workbench-notification-toolbar",children:t.jsxs("label",{className:"workbench-notification-filter",children:[t.jsx("input",{type:"checkbox",checked:e.showArchivedNotifications,onChange:o=>e.onToggleShowArchivedNotifications(o.target.checked)}),t.jsx("span",{children:r("shell.globalNotificationsShowArchived")})]})}),i.length>0?t.jsx("div",{className:"workbench-notification-list",children:i.map(o=>{const c=e.archivedNotificationIds.has(o.id);return t.jsxs("article",{className:"workbench-notification-item","data-archived":c,children:[t.jsxs("button",{type:"button",className:"workbench-notification-item-content",onClick:()=>{e.onSelectNotification(o)},children:[t.jsx("span",{className:"workbench-notification-item-kind",children:Eh(o.kind)}),t.jsx("strong",{children:o.title}),t.jsx("p",{children:o.body})]}),t.jsxs("div",{className:"workbench-notification-item-side",children:[t.jsx("time",{children:Dh(o.createdAt)}),t.jsx("button",{type:"button",className:"secondary-button workbench-notification-item-action-button",onClick:()=>{if(c){e.onUnarchiveNotification(o.id);return}e.onArchiveNotification(o.id)},children:c?r("shell.globalNotificationsRemoveArchiveAction"):r("shell.globalNotificationsArchiveAction")})]})]},o.id)})}):t.jsx("p",{className:"workbench-notification-empty",children:r("shell.globalNotificationsEmpty")})]}):t.jsx("div",{className:"workbench-notification-pane",role:"tabpanel","aria-label":r("shell.butlerInboxAction"),children:t.jsx(Sl,{active:e.open&&n==="inbox",preferredWorkspaceId:e.preferredWorkspaceId,preferredSessionId:e.preferredSessionId})})}),t.jsx("div",{className:"workbench-modal-actions workbench-notification-footer-actions",children:t.jsx("button",{type:"button",className:"secondary-button",onClick:e.onClose,children:r("common.close")})})]})}function Cf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),t.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Tf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("circle",{cx:"11",cy:"11",r:"7"}),t.jsx("line",{x1:"20",y1:"20",x2:"16.65",y2:"16.65"})]})}function If(){return t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:t.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 Rf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),t.jsx("path",{d:"M7 9l3 3-3 3"}),t.jsx("path",{d:"M13 15h4"})]})}function Mf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[t.jsx("rect",{x:"4",y:"5",width:"16",height:"14",rx:"3"}),t.jsx("circle",{cx:"9",cy:"11",r:"1"}),t.jsx("circle",{cx:"15",cy:"11",r:"1"}),t.jsx("path",{d:"M8 15h8"}),t.jsx("path",{d:"M12 5V3"})]})}function Ef(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[t.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"}),t.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 Vl(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),t.jsx("line",{x1:"9",y1:"4",x2:"9",y2:"20"}),t.jsx("polyline",{points:"14 9 11 12 14 15"})]})}function Pf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.jsx("circle",{cx:"18",cy:"6",r:"3"}),t.jsx("circle",{cx:"6",cy:"6",r:"3"}),t.jsx("circle",{cx:"18",cy:"18",r:"3"}),t.jsx("path",{d:"M6 9v6a3 3 0 0 0 3 3h3"}),t.jsx("line",{x1:"18",y1:"9",x2:"18",y2:"15"})]})}function Wf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.jsx("circle",{cx:"12",cy:"12",r:"3"}),t.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 Af(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.jsx("rect",{x:"4",y:"5",width:"6",height:"6",rx:"1.5"}),t.jsx("rect",{x:"14",y:"5",width:"6",height:"6",rx:"1.5"}),t.jsx("rect",{x:"4",y:"13",width:"6",height:"6",rx:"1.5"}),t.jsx("path",{d:"M14 16l2 2 4-4"})]})}function Bf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.jsx("rect",{x:"4",y:"6",width:"10",height:"12",rx:"2"}),t.jsx("path",{d:"M10 12h8"}),t.jsx("path",{d:"M15 8l4 4-4 4"})]})}function Lf({selected:e}){return e?t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[t.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"4"}),t.jsx("path",{d:"M8 12.5l2.8 2.8L16.5 9.5"})]}):t.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:t.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"4"})})}function Xl({active:e,className:n}){return e?t.jsx("svg",{className:n,width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"1.5",children:t.jsx("polygon",{points:"12 3 15 9 22 10 17 15 18 22 12 18 6 22 7 15 2 10 9 9"})}):t.jsx("svg",{className:n,width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:t.jsx("polygon",{points:"12 3 15 9 22 10 17 15 18 22 12 18 6 22 7 15 2 10 9 9"})})}function Df(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.jsx("path",{d:"M3 7h18"}),t.jsx("path",{d:"M5 7l1 12h12l1-12"}),t.jsx("path",{d:"M9 11h6"}),t.jsx("path",{d:"M8 4h8l1 3H7l1-3z"})]})}function _f(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.jsx("path",{d:"M12 20h9"}),t.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 Ff(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.jsx("path",{d:"M3 6h18"}),t.jsx("path",{d:"M8 6V4h8v2"}),t.jsx("path",{d:"M6 6l1 14h10l1-14"}),t.jsx("path",{d:"M10 11v5"}),t.jsx("path",{d:"M14 11v5"})]})}function Of(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",children:[t.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"}),t.jsx("path",{d:"M9 13h6"})]})}function Hf(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.9",children:[t.jsx("circle",{cx:"12",cy:"12",r:"9"}),t.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"}),t.jsx("circle",{cx:"12",cy:"17.2",r:"1",fill:"currentColor",stroke:"none"})]})}function Uf({open:e,mode:n,keyword:s,codeWorkspaceId:i,codeResults:o,codeLoading:c,codeError:h,workspaceOptions:f,sessionResults:k,onClose:p,onModeChange:w,onKeywordChange:N,onCodeWorkspaceChange:C,onCodeSearch:R,onOpenSession:O}){const H=s.trim().length>0&&i.trim().length>0;return t.jsx($e,{open:e,title:r("shell.searchModalTitle"),description:r("shell.searchModalDescription"),onClose:p,children:t.jsxs("div",{className:"workbench-search-modal",children:[t.jsxs("div",{className:"workbench-search-mode-switch",role:"tablist","aria-label":r("shell.searchModeLabel"),children:[t.jsx("button",{type:"button",className:n==="sessions"?"workbench-search-mode-button active":"workbench-search-mode-button",role:"tab","aria-selected":n==="sessions",onClick:()=>w("sessions"),children:r("shell.searchModeSessions")}),t.jsx("button",{type:"button",className:n==="code"?"workbench-search-mode-button active":"workbench-search-mode-button",role:"tab","aria-selected":n==="code",onClick:()=>w("code"),children:r("shell.searchModeCode")})]}),n==="sessions"?t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.searchKeywordLabel")}),t.jsx("input",{type:"text",value:s,placeholder:r("shell.searchSessionPlaceholder"),autoFocus:!0,onChange:W=>N(W.target.value)})]}),t.jsx("div",{className:"workbench-search-results",children:s.trim().length===0?t.jsx("p",{className:"workbench-search-empty",children:r("shell.searchSessionHint")}):k.length>0?k.map(W=>{const x=ro(W.session.title,r("common.unknown"));return t.jsxs("button",{type:"button",className:"workbench-search-result-item",onClick:()=>O(W.session.sessionId),children:[t.jsx("span",{className:"workbench-search-result-title",title:x.fullTitle,children:x.displayTitle}),t.jsxs("span",{className:"workbench-search-result-meta",children:[W.workspace.name," · ",si(W.session.provider,"full")]})]},W.session.sessionId)}):t.jsx("p",{className:"workbench-search-empty",children:r("shell.searchSessionEmpty")})})]}):t.jsxs(t.Fragment,{children:[t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.searchWorkspaceLabel")}),t.jsx("select",{value:i,onChange:W=>C(W.target.value),children:f.map(W=>t.jsx("option",{value:W.id,children:W.name},W.id))})]}),t.jsxs("form",{className:"workbench-search-code-form",onSubmit:W=>{W.preventDefault(),R()},children:[t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.searchKeywordLabel")}),t.jsx("input",{type:"text",value:s,placeholder:r("shell.searchCodePlaceholder"),autoFocus:!0,onChange:W=>N(W.target.value)})]}),t.jsx("button",{type:"submit",className:"primary-button",disabled:!H||c,children:c?r("common.loading"):r("shell.searchSubmit")})]}),t.jsxs("div",{className:"workbench-search-results",children:[h?t.jsx("p",{className:"status-text","data-tone":"error",children:h}):null,!h&&s.trim().length===0?t.jsx("p",{className:"workbench-search-empty",children:r("shell.searchCodeHint")}):null,!h&&s.trim().length>0&&!c&&o.length===0?t.jsx("p",{className:"workbench-search-empty",children:r("shell.searchCodeEmpty")}):null,o.map(W=>t.jsxs("div",{className:"workbench-search-result-item static",children:[t.jsx("span",{className:"workbench-search-result-title",children:W.name}),t.jsx("span",{className:"workbench-search-result-meta",children:W.path})]},`${W.path}-${W.kind}`))]})]})]})})}function $f({menuKey:e,session:n,workspace:s,workspaceContext:i,isActive:o,isFavorite:c,menuOpen:h,menuAnchorPoint:f,showWorkspaceName:k,depth:p=0,showActions:w=!0,hasSubagents:N=!1,subagentListExpanded:C=!1,selectionMode:R=!1,selected:O=!1,onToggleSelect:H,onToggleSubagents:W,onOpen:x,onRename:A,onOpenContextMenu:I,onToggleFavorite:G,onArchive:K,onDelete:Y,onCloseMenu:z}){var oe;const q=Tn(),j=$a(n.provider).supportsSessionDelete===!0,J=Di(n)?((oe=n.subagentLabel)==null?void 0:oe.trim())||r("shell.subagentBadge"):null,Q=ro(n.title,r("common.unknown")),E=Zh(n),ue=E?Qh(E):null,U=uu(n),ce=U?hu("session-activity-badge",n):null,D=so(n),v=ku(n),S=l.useRef(null),[X,ke]=l.useState(null);l.useLayoutEffect(()=>{if(q.isDesktop||!h||!f||typeof window>"u"){ke(null);return}const ae=()=>{var be,me;const he=Tu(f,{width:((be=S.current)==null?void 0:be.offsetWidth)??0,height:((me=S.current)==null?void 0:me.offsetHeight)??0},{width:window.innerWidth,height:window.innerHeight},{estimatedHeightPx:j&&Y?216:168});ke({position:"fixed",top:`${Math.round(he.top)}px`,left:`${Math.round(he.left)}px`,width:`${Math.round(he.width)}px`,maxWidth:"calc(100vw - 24px)",maxHeight:`${Math.round(he.maxHeight)}px`,transformOrigin:he.transformOrigin})};return ae(),window.addEventListener("resize",ae),window.addEventListener("scroll",ae,!0),()=>{window.removeEventListener("resize",ae),window.removeEventListener("scroll",ae,!0)}},[f,h,q.isDesktop]);async function we(){await Fc([{id:`rename:${n.sessionId}`,label:r("shell.renameAction"),onSelect:A},{id:`favorite:${n.sessionId}`,label:c?r("shell.unfavoriteAction"):r("shell.favoriteAction"),onSelect:G},{id:`archive:${n.sessionId}`,label:r("shell.archiveAction"),onSelect:K},...j&&Y?[{id:`delete:${n.sessionId}`,label:r("shell.deleteSessionAction"),onSelect:Y}]:[]])}const ne=!q.isDesktop&&h&&typeof document<"u"?tr.createPortal(t.jsxs("div",{ref:S,className:"workbench-session-menu","data-menu-key":e,role:"menu","aria-label":r("shell.sessionMoreAction"),onClick:ae=>ae.stopPropagation(),style:X??{position:"fixed",top:0,left:0,visibility:"hidden"},children:[t.jsxs("button",{type:"button",className:"workbench-session-menu-item",onClick:()=>{A(),z()},children:[t.jsx(_f,{}),t.jsx("span",{children:r("shell.renameAction")})]}),t.jsxs("button",{type:"button",className:"workbench-session-menu-item",onClick:()=>{G(),z()},children:[t.jsx(Xl,{active:c}),t.jsx("span",{children:c?r("shell.unfavoriteAction"):r("shell.favoriteAction")})]}),t.jsxs("button",{type:"button",className:"workbench-session-menu-item",onClick:()=>{K(),z()},children:[t.jsx(Df,{}),t.jsx("span",{children:r("shell.archiveAction")})]}),j&&Y?t.jsxs("button",{type:"button",className:"workbench-session-menu-item",onClick:()=>{Y(),z()},children:[t.jsx(Ff,{}),t.jsx("span",{children:r("shell.deleteSessionAction")})]}):null]}),document.body):null;return t.jsxs("article",{className:"workbench-session-card","data-active":o,"data-depth":p,"data-subagent":Di(n),"data-workspace-tone":i.tone,"data-worktree-depth":i.depth,"data-has-subagents":N,"data-selecting":R,"data-selected":O,style:tn(i),onContextMenu:ae=>{if(!(R||!w||!I)){if(ae.preventDefault(),ae.stopPropagation(),q.isDesktop){we();return}I({x:ae.clientX,y:ae.clientY})}},children:[t.jsxs("div",{className:"workbench-session-main",children:[R?t.jsx("span",{className:"workbench-session-selection-indicator","data-selected":O,"aria-hidden":"true",children:t.jsx(Lf,{selected:O})}):N?t.jsxs("button",{type:"button",className:"workbench-session-subagent-toggle",style:tf,"data-indicator-variant":nf(n,{hasSubagents:!0,isActive:o}),"aria-label":C?r("shell.subagentCollapse"):r("shell.subagentExpand"),title:C?r("shell.subagentCollapse"):r("shell.subagentExpand"),"aria-expanded":C,onClick:ae=>{ae.stopPropagation(),W==null||W()},children:[t.jsx("span",{className:ka(n,{hasSubagents:!0,isActive:o}),"data-activity-source":n.activitySource,"aria-hidden":"true"}),t.jsx("span",{className:"workbench-session-subagent-toggle-icon","aria-hidden":"true",children:t.jsx(Xs,{expanded:C})})]}):t.jsx("span",{className:ka(n,{isActive:o}),"data-activity-source":n.activitySource,"aria-hidden":"true"}),t.jsx("button",{type:"button",className:"workbench-session-link",style:N?ef:void 0,"data-active":o,"aria-pressed":R?O:void 0,onClick:R?H:x,onKeyDown:ae=>{if(R||!w||!I||ae.key!=="ContextMenu"&&!(ae.shiftKey&&ae.key==="F10"))return;if(ae.preventDefault(),ae.stopPropagation(),q.isDesktop){we();return}const he=ae.currentTarget.getBoundingClientRect();I({x:he.right,y:he.bottom})},children:t.jsxs("div",{className:"workbench-session-link-copy",children:[t.jsxs("div",{className:"session-title-row",children:[t.jsx("span",{className:"session-title",title:Q.fullTitle,children:Q.displayTitle}),J?t.jsx("span",{className:"session-subagent-badge",children:J}):null,v&&D?t.jsx("span",{className:`session-fork-badge ${D}`,children:v}):null]}),t.jsxs("div",{className:"session-meta-row",children:[t.jsx("span",{className:"session-meta",children:Rl(n,s,k,i.displayName)}),U&&ce?t.jsx("span",{className:ce,children:U}):null,t.jsx("span",{className:`session-provider-badge ${n.provider}`,children:si(n.provider)})]}),ue?t.jsx("div",{className:"session-error-row",title:E??void 0,children:t.jsx("span",{className:"session-error-text",children:ue})}):null]})})]}),ne]})}function Ra({workspaceGroups:e,workspaceVisualContextMap:n,sessionDisplaySortMode:s,favoriteSessions:i,favoriteSessionIds:o,activeWorkspaceId:c,isConversationActive:h,isTerminalActive:f,isButlerActive:k,isSearchOpen:p,navigationLoading:w,navigationError:N,activeSessionId:C,onRefreshNavigation:R,onSessionUpdated:O,onNavigateConversation:H,onNavigateTerminals:W,onNavigateButler:x,onOpenSearch:A,onOpenSettings:I,onSelectWorkspace:G,onToggleWorkspaceCollapse:K,onStartWorkspaceReorder:Y,onPreviewWorkspaceReorder:z,onCommitWorkspaceReorder:q,allowWorkspaceReorder:j,subscribeGitSnapshot:J,requestGitRefresh:Q,subscribeWorkspaceManagementSnapshot:E,requestWorkspaceManagementRefresh:ue,onToggleFavoriteSession:U,onArchiveSession:ce,onUnarchiveSession:D,workspaceManagementStateById:v,setWorkspaceManagementStateById:S,unreadNotificationCount:X,notificationPanelOpen:ke,onToggleNotificationPanel:we,onClose:ne,onToggleCollapse:oe}){var Gn;const ae=er(),he=Tn(),be=dl(he),{showToast:me}=Xn(),Ge=Oi(d=>d),Ee=((Gn=Da(Ge))==null?void 0:Gn.name)??"",_=Ge.hosts.length+_a(Ge).length>1&&Ee.length>0,[y,$]=l.useState(!1),[le,F]=l.useState(!1),[Pe,ut]=l.useState(!1),[_e,Wt]=l.useState([]),[Je,wt]=l.useState(null),[Fe,ir]=l.useState(null),[lt,or]=l.useState(null),[He,Yn]=l.useState(null),[Te,zt]=l.useState(null),[ct,Ns]=l.useState(null),[At,Kt]=l.useState(!1),[Ze,In]=l.useState(!1),[xt,Rn]=l.useState(""),[Cs,rn]=l.useState(""),[Jn,xe]=l.useState(""),[Vt,Ae]=l.useState({localBranches:[],remoteBranches:[],tags:[]}),[Qe,ze]=l.useState(!1),[Ts,et]=l.useState(-1),[Mn,En]=l.useState(!1),[Zn,Pn]=l.useState(!1),[Bt,Wn]=l.useState(null),[vt,Is]=l.useState(null),[ii,An]=l.useState(null),[oi,Xt]=l.useState(null),[Bn,yt]=l.useState(null),[on,ar]=l.useState(null),[Yt,an]=l.useState(null),[Qn,lr]=l.useState(null),[ai,tt]=l.useState(Ci),[St,je]=l.useState({}),[es,ln]=l.useState({}),[Ln,cn]=l.useState([]),[dn,Jt]=l.useState({expandedWorkspaceIds:[],collapsedWorkspaceIds:[]}),[nt,jt]=l.useState(null),[Nt,Zt]=l.useState(""),[un,cr]=l.useState(null),[it,Lt]=l.useState(null),[Ct,st]=l.useState([]),[Dn,ts]=l.useState(!1),[Rs,ns]=l.useState({}),[Ke,ot]=l.useState(null),Ve=l.useRef(null),Tt=l.useRef(null),Dt=l.useRef(null),ss=l.useRef(new Map),hn=l.useRef(null),fn=l.useRef(null),ht=l.useRef(null),dr=l.useMemo(()=>new Set(dn.expandedWorkspaceIds),[dn.expandedWorkspaceIds]),rs=l.useMemo(()=>new Set(dn.collapsedWorkspaceIds),[dn.collapsedWorkspaceIds]),_n=Ke!==null,It=j&&he.isDesktop&&he.ui.osFamily==="macos",Xe=l.useCallback(()=>{an(null),lr(null)},[]),ur=l.useCallback((d,m)=>{an(d),lr(m)},[]),Ie=Sa(e,Te)??((ct==null?void 0:ct.id)===Te?ct:null),Ms=Jn.trim().toLowerCase(),mn=l.useMemo(()=>[{key:"localBranches",label:r("shell.createWorktreeBaseRefLocalGroup"),items:Vt.localBranches},{key:"remoteBranches",label:r("shell.createWorktreeBaseRefRemoteGroup"),items:Vt.remoteBranches},{key:"tags",label:r("shell.createWorktreeBaseRefTagGroup"),items:Vt.tags}].map(m=>({...m,items:m.items.filter(g=>Ms?g.value.toLowerCase().includes(Ms):!0)})).filter(m=>m.items.length>0),[Ms,Vt]),dt=l.useMemo(()=>mn.flatMap(d=>d.items),[mn]),Es=Ie?`create-worktree-base-ref-listbox-${Ie.id}`:"create-worktree-base-ref-listbox",ft=df(e,oi),Ye=ft?gn(ft.workspace):null,pn=l.useMemo(()=>cf(e,it),[it,e]),is=l.useMemo(()=>pn?Vh(pn.visibleSessionTree):[],[pn]),pe=l.useMemo(()=>is.map(d=>d.sessionId),[is]),rt=l.useMemo(()=>new Set(pe),[pe]),Re=l.useMemo(()=>new Set(Ct),[Ct]),hr=pe.length>0&&Ct.length===pe.length;l.useEffect(()=>{S(d=>{const m=ja(e),g=new Set(m),M={};Object.entries(d).forEach(([V,ve])=>{g.has(V)&&(M[V]=ve)}),m.forEach(V=>{const ve=Sa(e,V);if(!ve)return;const Ue=Yr(Fi(V),ca),We=Yr(Ul(V),ca),qe=M[V];let Mt=ql((qe==null?void 0:qe.detail)??Ue??$l(ve),ve);(We!=null&&We.status||We!=null&&We.branches)&&(Mt=Gl(Mt,{status:We.status??null,branches:We.branches??null})),M[V]={detail:Mt,loading:!1,error:null}});const P=Object.keys(d),te=Object.keys(M);return P.length===te.length&&te.every(V=>d[V]===M[V])?d:M})},[e]);const os=l.useCallback(async d=>{await R(),await he.bridge.showNotification(r("shell.importSuccess"),d.path)},[R,he.bridge]),as=l.useCallback(async d=>{await R(),await he.bridge.showNotification(r("shell.cloneSuccess"),d.path)},[R,he.bridge]);function _t(d){if(_e.includes(d)){Wt(g=>g.filter(M=>M!==d));return}Wt(g=>[...g,d]),J(d),Q(d),E(d),ue(d)}async function Fn(d,m){if(Rs[d])return;const g=(m==null?void 0:m.trim().toUpperCase())??null;ns(M=>({...M,[d]:!0}));try{await Ha(d,{backgroundColor:g}),await R()}catch(M){me({title:M instanceof Error?M.message:r("shell.manageWorkspaceColorSaveFailed"),tone:"error"})}finally{ns(M=>({...M,[d]:!1}))}}async function fr(){if(!(!Je||Fe)){ir(Je.id);try{await Ec(Je.id),Wt(d=>d.filter(m=>m!==Je.id)),S(d=>{const m={...d};return delete m[Je.id],m}),wt(null),await R(),me({title:r("shell.manageWorkspaceRemoveSuccess"),tone:"success"})}catch(d){me({title:d instanceof Error?d.message:r("shell.manageWorkspaceRemoveFailed"),tone:"error"})}finally{ir(null)}}}l.useEffect(()=>{if(!Yt)return;function d(m){const g=m.target;g instanceof HTMLElement&&g.closest(".workbench-session-menu")||Xe()}return window.addEventListener("pointerdown",d),()=>{window.removeEventListener("pointerdown",d)}},[Xe,Yt]),l.useEffect(()=>{if(!it){Ct.length>0&&st([]);return}if(!pn){Lt(null),st([]);return}st(d=>_l(d,rt))},[pn,rt,it,Ct.length]),l.useEffect(()=>{it&&pe.length===0&&(Lt(null),st([]))},[pe.length,it]),l.useEffect(()=>{const d=new Set(ja(e)),m=new Set(e.flatMap(g=>_i(g.childWorktrees)));Wt(g=>g.filter(M=>d.has(M))),Jt(g=>({expandedWorkspaceIds:g.expandedWorkspaceIds.filter(M=>m.has(M)),collapsedWorkspaceIds:g.collapsedWorkspaceIds.filter(M=>m.has(M))})),wt(g=>g&&d.has(g.id)?g:null),ns(g=>Object.fromEntries(Object.entries(g).filter(([M,P])=>P&&d.has(M))))},[e]),l.useEffect(()=>{const d=i.findIndex(m=>m.session.sessionId===C);tt(m=>{const g=Ur(i.length,Ci,m,d);return g===m?m:g})},[C,i]),l.useEffect(()=>{je(d=>{const m={};for(const g of e){const M=Ks(g),P=M.findIndex(te=>te.item.sessionId===C||ks([te],C??"",V=>V.sessionId).length>0);m[g.workspace.id]=Ur(M.length,qs,d[g.workspace.id],P);for(const te of Vs(g.childWorktrees)){te.item.sessionId===C||ks([te],C??"",We=>We.sessionId).length>0;const V=te.item.workspaceId;if(m[V]!==void 0)continue;const ve=Vs(g.childWorktrees).filter(We=>We.item.workspaceId===V&&We.depth===0),Ue=ve.findIndex(We=>We.item.sessionId===C||ks([We],C??"",qe=>qe.sessionId).length>0);m[V]=Ur(ve.length,qs,d[V],Ue)}}return ba(d,m)?d:m})},[C,e]),l.useEffect(()=>{ln(d=>{const m={};for(const g of e)for(const M of[...Ks(g),...Vs(g.childWorktrees)])for(const P of Sn(Pt(M))){const te=Pt(P);if(te.length===0)continue;const V=Sn(te),ve=V.findIndex(Ue=>Ue.item.sessionId===C);m[P.item.sessionId]=Ur(V.length,Or,d[P.item.sessionId],ve)}return ba(d,m)?d:m})},[C,e]),l.useEffect(()=>{if(!C)return;const d=e.flatMap(m=>[...ks(Ks(m),C,g=>g.sessionId),...Vs(m.childWorktrees).flatMap(g=>ks([g],C,M=>M.sessionId))]);d.length!==0&&cn(m=>{const g=new Set(m);let M=!1;for(const P of d)g.has(P)||(g.add(P),M=!0);return M?Array.from(g):m})},[C,e]),l.useEffect(()=>{if(!c)return;const d=[];for(const m of e){const g=Ll(m.childWorktrees,c);g.length!==0&&d.push(...g)}d.length>0&&Jt(m=>{const g=new Set(m.expandedWorkspaceIds);let M=!1;for(const P of d)g.has(P)||(g.add(P),M=!0);return M?{expandedWorkspaceIds:Array.from(g),collapsedWorkspaceIds:m.collapsedWorkspaceIds}:m})},[c,e]),l.useEffect(()=>{if(!Te){Ns(null),Kt(!1),In(!1),Rn(""),rn(""),xe(""),ze(!1),et(-1),En(!1),Ae({localBranches:[],remoteBranches:[],tags:[]}),Pn(!1),Wn(null);return}Kt(!1),Rn(""),rn(""),xe(""),ze(!1),et(-1),En(!1),Ae({localBranches:[],remoteBranches:[],tags:[]}),Pn(!1),Wn(null)},[Te]),l.useEffect(()=>{const d=Ie;if(!At||!d)return;let m=!1;const g=d.id;return Pn(!0),Wn(null),Promise.all([Dc(g),_c(g)]).then(([M,P])=>{m||Ae(Ah(M,P))}).catch(()=>{m||(Ae({localBranches:[],remoteBranches:[],tags:[]}),Wn(r("shell.createWorktreeBaseRefLoadFailed")))}).finally(()=>{m||Pn(!1)}),()=>{m=!0}},[Ie==null?void 0:Ie.id,At]),l.useLayoutEffect(()=>{if(!Qe||!Ve.current){Is(null),An(null);return}const d=()=>{const g=Ve.current;if(!g)return;const M=Bh(g);Is({top:M.bottom+8,left:M.left,width:M.width})};d();const m=g=>{var P,te;const M=g.target;M instanceof Node&&((P=Ve.current)!=null&&P.contains(M)||(te=Tt.current)!=null&&te.contains(M)||(ze(!1),et(-1)))};return window.addEventListener("resize",d),window.addEventListener("scroll",d,!0),window.addEventListener("pointerdown",m),()=>{window.removeEventListener("resize",d),window.removeEventListener("scroll",d,!0),window.removeEventListener("pointerdown",m)}},[dt.length,Qe]),l.useLayoutEffect(()=>{if(!Qe||!Tt.current){An(null);return}const d=Tt.current,m=()=>{const M=Math.ceil(d.getBoundingClientRect().height);An(P=>P===M?P:M)};if(m(),typeof ResizeObserver>"u")return;const g=new ResizeObserver(()=>{m()});return g.observe(d),()=>{g.disconnect()}},[Qe,mn,Zn,Bt]);function Ps(){$(!0)}function Ws(){F(!0)}function ls(){Kt(!1),Rn(""),rn(""),xe(""),ze(!1),et(-1),En(!1)}function bn(d,m){const g=d.getBoundingClientRect();return m<=g.top+g.height/2?"before":"after"}function Le(){Dt.current!==null&&(cancelAnimationFrame(Dt.current),Dt.current=null),ot(null)}function mt(d){const m=(d==null?void 0:d.commit)??!1,g=(d==null?void 0:d.preserveClickSuppression)??!1,M=hn.current,P=fn.current;hn.current=null,fn.current=null,P==null||P(),M!=null&&M.dragging&&(Le(),m&&q(),!g&&ht.current===M.workspaceId&&(ht.current=null))}function cs(d){if(ht.current===d){ht.current=null;return}K(d)}function As(d,m){if(m){ss.current.set(d,m);return}ss.current.delete(d)}function Bs(d,m){for(const[g,M]of ss.current){const P=M.getBoundingClientRect();if(d>=P.left&&d<=P.right&&m>=P.top&&m<=P.bottom)return{workspaceId:g,element:M}}return null}function se(d,m){var ve;if(!It||d.button!==0)return;mt();const g=d.currentTarget,M={pointerId:d.pointerId,workspaceId:m,startX:d.clientX,startY:d.clientY,pointerTarget:g,dragging:!1};hn.current=M,(ve=g.setPointerCapture)==null||ve.call(g,d.pointerId);const P=Ue=>{Ls(Ue)},te=Ue=>{kn(Ue.pointerId,{commit:!0,preserveClickSuppression:!0})},V=Ue=>{kn(Ue.pointerId,{commit:!1,preserveClickSuppression:!1})};fn.current=()=>{g.removeEventListener("pointermove",P),g.removeEventListener("pointerup",te),g.removeEventListener("pointercancel",V),window.removeEventListener("pointermove",P),window.removeEventListener("pointerup",te),window.removeEventListener("pointercancel",V)},g.addEventListener("pointermove",P),g.addEventListener("pointerup",te),g.addEventListener("pointercancel",V),window.addEventListener("pointermove",P,{passive:!1}),window.addEventListener("pointerup",te),window.addEventListener("pointercancel",V)}function Ls(d){const m=hn.current;if(!m||m.pointerId!==d.pointerId)return;if(!m.dragging){if(Math.hypot(d.clientX-m.startX,d.clientY-m.startY)<wh)return;m.dragging=!0,ht.current=m.workspaceId,Y(),ot(m.workspaceId)}d.preventDefault();const g=Bs(d.clientX,d.clientY);!g||g.workspaceId===m.workspaceId||z(m.workspaceId,g.workspaceId,bn(g.element,d.clientY))}function kn(d,m){var M,P;const g=hn.current;!g||g.pointerId!==d||((P=(M=g.pointerTarget).releasePointerCapture)==null||P.call(M,d),mt(m))}function ds(d){Ls(d)}function On(d){kn(d.pointerId,{commit:!0,preserveClickSuppression:!0})}function li(d){kn(d.pointerId,{commit:!1,preserveClickSuppression:!1})}function Hn(d,m){d.dataTransfer.effectAllowed="move",d.dataTransfer.setData("text/plain",m),Y(),Dt.current!==null&&cancelAnimationFrame(Dt.current),Dt.current=requestAnimationFrame(()=>{Dt.current=null,ot(m)})}function pt(d,m){const g=Ke||d.dataTransfer.getData("text/plain");!g||g===m||(d.preventDefault(),d.dataTransfer.dropEffect="move",z(g,m,bn(d.currentTarget,d.clientY)))}function Be(d){d.preventDefault()}function Un(){Le(),q()}l.useEffect(()=>()=>{mt()},[]);function mr(d){return es[d]??Or}function Ds(d){return Ln.includes(d)}function bt(d){return St[d]??qs}function pr(){tt(d=>Math.min(i.length,d+Ci))}function $n(d,m){je(g=>({...g,[d]:Math.min(m,(g[d]??qs)+qs)}))}function Rt(d){ln(m=>({...m,[d]:(m[d]??Or)+Or}))}function br(d){cn(m=>m.includes(d)?m.filter(g=>g!==d):[...m,d])}function qn(d,m){return rs.has(d)?!1:m||dr.has(d)}function _s(d,m){const g=!qn(d,m);Jt(M=>{const P=M.expandedWorkspaceIds.filter(V=>V!==d),te=M.collapsedWorkspaceIds.filter(V=>V!==d);return g?{expandedWorkspaceIds:[...P,d],collapsedWorkspaceIds:te}:{expandedWorkspaceIds:P,collapsedWorkspaceIds:[...te,d]}})}function ci(d){for(const m of e){const g=Sn(lo(m.visibleSessions,s)).find(M=>M.item.sessionId===d)??Pl(m.childWorktrees,d);if(g)return Pt(g)}return[]}function kr(d,m){const g=gn(d);return t.jsxs("button",{type:"button",className:"workbench-archive-folder","data-workspace-tone":g.tone,style:tn(g),onClick:()=>Xt(d.id),children:[t.jsxs("span",{className:"workbench-archive-folder-main",children:[t.jsx(Of,{}),t.jsx("span",{children:r("shell.archiveFolderLabel")})]}),t.jsx("span",{className:"workbench-section-counter",children:m.length})]})}function Fs(){return t.jsxs("div",{className:"workbench-workspace-batch-toolbar",children:[t.jsx("span",{className:"workbench-workspace-batch-label",children:r("shell.batchSelectionMode")}),t.jsxs("span",{className:"workbench-workspace-batch-counter",children:[Ct.length,"/",pe.length]}),t.jsx("button",{type:"button",className:"workbench-workspace-batch-action",onClick:fi,children:hr?r("shell.clearSelectedSessions"):r("shell.selectAllSessions")}),t.jsx("button",{type:"button",className:"workbench-workspace-batch-action primary",disabled:Ct.length===0||Dn,onClick:()=>{vr()},children:Dn?r("shell.batchArchiving"):r("shell.batchArchiveAction")}),t.jsx("button",{type:"button",className:"workbench-workspace-batch-action",onClick:ui,children:r("common.cancel")})]})}function gr(d,m="workbench-workspace-actions"){return t.jsxs("div",{className:m,children:[t.jsx("button",{type:"button",className:"workbench-workspace-icon-button","aria-label":r("shell.switchWorkspace"),title:r("shell.switchWorkspace"),"aria-pressed":c===d,onClick:()=>{G(d),ne==null||ne()},children:t.jsx(Bf,{})}),t.jsx("button",{type:"button",className:"workbench-workspace-icon-button","aria-label":r("shell.batchSelectSessions"),title:r("shell.batchSelectSessions"),onClick:()=>di(d),children:t.jsx(Af,{})}),t.jsx("button",{type:"button",className:"workbench-workspace-icon-button workbench-workspace-create","aria-label":r("shell.createSession"),title:r("shell.createSession"),onClick:()=>zt(d),children:t.jsx(Cf,{})})]})}function wr(d){const m=d.visibleSessionTree,M=new Set(_i(d.children)).has(c??""),P=d.workspace.id===c||M,te=_n||!qn(d.workspace.id,P),V=gn(d.workspace);return t.jsxs("section",{className:"workbench-workspace-group","data-worktree-node":"true","data-batch-active":it===d.workspace.id,"data-worktree-depth":d.meta.depth,"data-workspace-tone":"worktree",style:tn(V),children:[t.jsxs("div",{className:"workbench-workspace-header minimal",children:[t.jsxs("button",{type:"button",className:"workbench-workspace-toggle","aria-label":te?r("shell.worktreeExpand"):r("shell.worktreeCollapse"),onClick:()=>_s(d.workspace.id,P),children:[t.jsx("span",{className:"workbench-workspace-toggle-icon","aria-hidden":"true",children:t.jsx(Xs,{expanded:!te})}),t.jsxs("span",{children:[t.jsx("strong",{children:d.meta.displayName||d.workspace.name}),t.jsx("span",{className:"session-meta",children:d.meta.branchName})]})]}),it===d.workspace.id?Fs():gr(d.workspace.id)]}),te?null:t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"workbench-session-list","data-workspace-tone":V.tone,style:tn(V),children:[m.length===0?t.jsx("p",{className:"workbench-session-empty",children:r("shell.emptyWorkspaceSessions")}):m.slice(0,bt(d.workspace.id)).map(ve=>us({node:ve,workspace:d.workspace,workspaceContext:V,menuKeyPrefix:`worktree:${d.workspace.id}`,showWorkspaceName:!1,selectionMode:it===d.workspace.id,favoriteEnabled:!0})),m.length>bt(d.workspace.id)?t.jsx("button",{type:"button",className:"workbench-subsession-expand ghost-button",onClick:()=>$n(d.workspace.id,m.length),children:r("shell.sessionExpandMore")}):null]}),d.children.length>0?t.jsx("div",{className:"workbench-session-list workbench-worktree-child-list",children:d.children.map(ve=>wr(ve))}):null,kr(d.workspace,d.archivedSessions)]})]},d.workspace.id)}function us(d){const{node:m,workspace:g,workspaceContext:M,menuKeyPrefix:P,showWorkspaceName:te,selectionMode:V,favoriteEnabled:ve,ancestorExpanded:Ue=!1,allowToggle:We=m.depth===0,ancestorHasNextSiblings:qe=[],hasNextSibling:Mt=!1,isFirstSibling:Ft=!1}=d,Ne=m.item,wn=Pt(m),Ot=Ue||Ds(Ne.sessionId),Ce=Ot&&We,Cr=Ce?Xh(m,mr(Ne.sessionId),s):m,ms=Ot?Pt(Cr):[],Tr=Sn(wn).length,Ir=Sn(ms).length,Rr=Ce&&Ir<Tr,Mr=m.depth>0?[...qe,Mt]:[...qe];return t.jsxs("div",{className:"workbench-session-tree-node",children:[t.jsxs("div",{className:"workbench-session-tree-row",style:{"--workbench-session-tree-depth":m.depth},children:[m.depth>0?t.jsxs("div",{className:"workbench-session-tree-guides","aria-hidden":"true",children:[qe.map((xn,vn)=>xn?t.jsx("span",{className:"workbench-session-tree-guide-column",style:{"--workbench-session-tree-level":vn+1}},`${Ne.sessionId}:ancestor:${vn}`):null),t.jsx("span",{className:"workbench-session-tree-guide-branch","data-continue":Mt,"data-first":Ft,style:{"--workbench-session-tree-level":m.depth},children:t.jsx("span",{className:"workbench-session-tree-guide-branch-horizontal"})})]}):null,t.jsx($f,{menuKey:`${P}:${Ne.sessionId}`,session:Ne,workspace:g,workspaceContext:M,isActive:Ne.sessionId===C,isFavorite:ve&&o.has(Ne.sessionId),menuOpen:Yt===`${P}:${Ne.sessionId}`,showWorkspaceName:te,depth:m.depth,showActions:ve,hasSubagents:We&&wn.length>0,subagentListExpanded:Ot,selectionMode:V,selected:Re.has(Ne.sessionId),onToggleSelect:()=>hi(Ne.sessionId),onToggleSubagents:()=>br(Ne.sessionId),onOpen:()=>{ae($t(g.id,Ne.sessionId)),ne==null||ne()},onRename:()=>Os(Ne,g),menuAnchorPoint:Yt===`${P}:${Ne.sessionId}`?Qn:null,onOpenContextMenu:xn=>ur(`${P}:${Ne.sessionId}`,xn),onToggleFavorite:()=>hs(Ne.sessionId),onArchive:()=>fs(Ne.sessionId),onDelete:$a(Ne.provider).supportsSessionDelete===!0?()=>{Xe(),yt({session:Ne,workspace:g})}:void 0,onCloseMenu:Xe})]}),wn.length>0&&Ot?t.jsxs("div",{className:"workbench-subsession-list",children:[ms.map((xn,vn)=>us({node:xn,workspace:g,workspaceContext:M,menuKeyPrefix:P,showWorkspaceName:te,selectionMode:V,favoriteEnabled:ve,ancestorExpanded:!0,allowToggle:!1,ancestorHasNextSiblings:Mr,hasNextSibling:vn<ms.length-1,isFirstSibling:vn===0})),Rr?t.jsx("button",{type:"button",className:"workbench-subsession-expand ghost-button",onClick:()=>Rt(Ne.sessionId),children:r("shell.subagentExpandMore")}):null]}):null]},Ne.sessionId)}function di(d){Xe(),Lt(d),st([])}function ui(){Lt(null),st([])}function hi(d){st(m=>kf(m,d))}function fi(){st(d=>d.length===pe.length?[]:pe)}async function mi(d,m){or(d),Yn(m);try{await Nl(d,m),zt(null),ae(sl(d,m)),ne==null||ne()}catch(g){me({title:g instanceof Error?g.message:r("shell.startSessionFailed"),tone:"error"})}finally{or(null),Yn(null)}}async function Qt(d){if(d.preventDefault(),!Ie||Ze)return;const m=xt.trim(),g=Cs.trim(),M=Jn.trim();if(!m){me({title:r("shell.createWorktreeBranchRequired"),tone:"error"});return}if(!Ph(m)){me({title:r("shell.createWorktreeBranchInvalid"),tone:"error"});return}In(!0);try{const P=await Pc({sourceWorkspaceId:Ie.id,branchName:m,displayName:g||void 0,baseRef:M||void 0});Ns(P.workspace),G(P.workspace.id),await R(),zt(P.workspace.id),ls(),me({title:r("shell.createWorktreeSucceeded",{name:P.meta.displayName||P.workspace.name}),tone:"success"})}catch(P){me({title:P instanceof Error?P.message:r("shell.createWorktreeFailed"),tone:"error"})}finally{In(!1)}}async function hs(d){const m=o.has(d);Xe();try{await U(d),me({title:m?r("shell.favoriteRemoved"):r("shell.favoriteAdded"),tone:"success"})}catch(g){me({title:g instanceof Error?g.message:r("shell.favoriteToggleFailed"),tone:"error"})}}async function fs(d){Xe();try{await ce(d),me({title:r("shell.archiveAdded"),tone:"success"})}catch(m){me({title:m instanceof Error?m.message:r("shell.navigationLoadFailed"),tone:"error"})}}async function xr(){if(!Bn||on)return;const{session:d,workspace:m}=Bn;ar(d.sessionId),Xe();try{await Mc(d.sessionId),st(g=>g.filter(M=>M!==d.sessionId)),yt(null),C===d.sessionId&&ae(m.id?Qs(m.id):at()),await R(),me({title:r("shell.deleteSessionSuccess"),tone:"success"})}catch(g){me({title:g instanceof Error?g.message:r("shell.deleteSessionFailed"),tone:"error"})}finally{ar(null)}}async function vr(){if(!(Ct.length===0||Dn)){Xe(),ts(!0);try{const d=[...Ct],m=await Promise.allSettled(d.map(async P=>({sessionId:P,session:await Oa(P,!0)}))),g=[];let M=0;for(const P of m){if(P.status==="fulfilled"){g.push(P.value.sessionId),O(P.value.session);continue}M+=1}g.length>0&&(await R(),st(P=>P.filter(te=>!g.includes(te)))),M>0?me({title:g.length>0?r("shell.batchArchivePartialFailed"):r("shell.batchArchiveFailed"),tone:"error"}):me({title:r("shell.batchArchiveSuccess"),tone:"success"})}catch(d){me({title:d instanceof Error?d.message:r("shell.batchArchiveFailed"),tone:"error"})}finally{ts(!1)}}}async function yr(d){Xe();try{await D(d),me({title:r("shell.archiveRestored"),tone:"success"})}catch(m){me({title:m instanceof Error?m.message:r("shell.navigationLoadFailed"),tone:"error"})}}function Os(d,m){Xe(),jt({session:d,workspace:m}),Zt(d.title)}async function Sr(d){if(d.preventDefault(),!nt)return;const m=Nt.trim();if(m){cr(nt.session.sessionId);try{const g=await Ua(nt.session.sessionId,m);O(g),jt(null),Zt(""),me({title:r("shell.renameSuccess"),tone:"success"})}catch(g){me({title:g instanceof Error?g.message:r("shell.renameFailed"),tone:"error"})}finally{cr(null)}}}const jr=i.slice(0,ai),Nr=jr.length<i.length;function gn(d){return n[d.id]??ao(d)}function Hs(d,m,g,M,P=[]){var Ot;const te=_e.includes(d.id),V=v[d.id]??{detail:null,loading:!1,error:null},ve=Fe===d.id,Ue=Rs[d.id]===!0,We=(Ot=V.detail)!=null&&Ot.git.remotes.length?V.detail.git.remotes.map(Ce=>`${Ce.name}: ${Ce.url}`).join(" · "):r("shell.manageWorkspaceNoRemote"),qe=V.detail?vu(V.detail.codeComposition.items,r("shell.manageWorkspaceCodeCompositionOther")):[],Mt=qe.length>0?Su(qe):void 0,Ft=gn(d),Ne=uf(Ft,P),wn=[...P,Ft.displayName];return t.jsxs("article",{className:"workbench-manage-item","data-workspace-tone":Ft.tone,"data-worktree-node":M,style:tn(Ft),children:[t.jsxs("button",{type:"button",className:"workbench-manage-item-toggle","aria-expanded":te,onClick:()=>_t(d.id),children:[t.jsxs("span",{className:"workbench-manage-item-heading",children:[t.jsx(Xs,{expanded:te}),t.jsxs("span",{className:"workbench-manage-item-heading-copy",children:[t.jsx("strong",{children:Ft.displayName}),t.jsx("span",{className:"workbench-manage-item-tree-path",children:Ne})]})]}),t.jsx("span",{className:"workbench-section-counter",children:m})]}),te?t.jsxs("div",{className:"workbench-manage-item-body",children:[t.jsxs("div",{className:"workbench-manage-detail-block",children:[t.jsx("span",{className:"workbench-manage-detail-label",children:r("shell.manageWorkspacePathLabel")}),t.jsx("p",{className:"workbench-manage-detail-value",children:d.path})]}),M?t.jsxs("div",{className:"workbench-manage-detail-block",children:[t.jsxs("div",{className:"workbench-manage-detail-header",children:[t.jsx("span",{className:"workbench-manage-detail-label",children:r("shell.manageWorkspaceColorLabel")}),t.jsxs("div",{className:"workbench-manage-color-actions",children:[t.jsx("div",{className:"workbench-manage-color-palette","aria-label":r("shell.manageWorkspaceColorLabel"),children:Sh.map(Ce=>t.jsx("button",{type:"button",className:"workbench-manage-color-swatch","aria-label":r("shell.manageWorkspaceColorSelectSwatch",{color:Ce}),"aria-pressed":d.backgroundColor===Ce,disabled:Ue,"data-selected":d.backgroundColor===Ce,style:{backgroundColor:Ce},onClick:()=>{Fn(d.id,Ce)}},Ce))}),t.jsx("button",{type:"button",className:"ghost-button",disabled:Ue||!d.backgroundColor,onClick:()=>{Fn(d.id,null)},children:r("shell.manageWorkspaceColorClearAction")})]})]}),t.jsx("p",{className:"workbench-manage-hint",children:d.backgroundColor??r("shell.manageWorkspaceColorUnset")})]}):null,V.loading&&V.detail===null?t.jsx("p",{className:"workbench-manage-status status-text",children:r("shell.manageWorkspaceLoading")}):null,V.error?t.jsx("p",{className:"workbench-manage-status status-text","data-tone":"error",children:V.error}):null,V.detail?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"workbench-manage-detail-block",children:t.jsxs("div",{className:"workbench-manage-detail-header",children:[t.jsx("span",{className:"workbench-manage-detail-label",children:r("shell.manageWorkspaceGitCommitCount")}),t.jsx("strong",{className:"workbench-manage-detail-accent",children:V.detail.git.commitCount??"--"})]})}),t.jsxs("div",{className:"workbench-manage-detail-block",children:[t.jsx("span",{className:"workbench-manage-detail-label",children:r("shell.manageWorkspaceGitInfoLabel")}),V.detail.git.isRepository?t.jsxs("div",{className:"workbench-manage-kv-list",children:[t.jsxs("div",{className:"workbench-manage-kv-item",children:[t.jsx("span",{children:r("shell.manageWorkspaceRepoRoot")}),t.jsx("span",{children:V.detail.git.repoRoot??"--"})]}),t.jsxs("div",{className:"workbench-manage-kv-item",children:[t.jsx("span",{children:r("shell.manageWorkspaceCurrentBranch")}),t.jsx("span",{children:V.detail.git.currentBranch??"--"})]}),t.jsxs("div",{className:"workbench-manage-kv-item",children:[t.jsx("span",{children:r("shell.manageWorkspaceRemoteLabel")}),t.jsx("span",{children:We})]})]}):t.jsx("p",{className:"workbench-section-empty",children:V.detail.git.error??r("shell.manageWorkspaceNotGit")})]}),t.jsxs("div",{className:"workbench-manage-detail-block",children:[t.jsx("span",{className:"workbench-manage-detail-label",children:r("shell.manageWorkspaceCodeCompositionLabel")}),qe.length>0?t.jsxs("div",{className:"workbench-manage-type-chart",children:[t.jsxs("div",{className:"workbench-manage-type-chart-ring",style:Mt,"aria-hidden":"true",children:[t.jsx("strong",{className:"workbench-manage-type-chart-total",children:V.detail.codeComposition.scannedFileCount}),t.jsx("span",{className:"workbench-manage-type-chart-caption",children:r("shell.manageWorkspaceCodeCompositionFiles")})]}),t.jsx("div",{className:"workbench-manage-type-list",children:qe.map(Ce=>t.jsxs("div",{className:"workbench-manage-type-item",children:[t.jsxs("span",{className:"workbench-manage-type-meta",children:[t.jsx("span",{className:"workbench-manage-type-swatch",style:{backgroundColor:Ce.color},"aria-hidden":"true"}),t.jsx("span",{className:"workbench-manage-type-name",children:Ce.type})]}),t.jsxs("span",{children:[Ce.count," · ",xu(Ce)]})]},Ce.key))})]}):t.jsx("p",{className:"workbench-section-empty",children:V.detail.codeComposition.error??r("shell.manageWorkspaceNoCodeComposition")}),V.detail.codeComposition.truncated?t.jsx("p",{className:"workbench-manage-hint",children:r("shell.manageWorkspaceCodeTruncated",{count:V.detail.codeComposition.scannedFileCount})}):null]})]}):null,t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",onClick:()=>{ut(!1),ae(Za(d.id))},children:r("shell.workspaceDetailDebugOpenPageAction")}),t.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:!!Fe,onClick:()=>wt(d),children:ve?r("shell.manageWorkspaceRemoving"):r("shell.manageWorkspaceRemoveAction")})]})]}):null,g.length>0?t.jsx("div",{className:"workbench-manage-children",children:g.map(Ce=>Hs(Ce.workspace,Ce.visibleSessions.length+Ce.archivedSessions.length,Ce.children,!0,wn))}):null]},d.id)}return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"workbench-nav-header","data-window-drag-handle":"workbench-nav-header","data-tauri-drag-region":be,children:t.jsxs("div",{className:"workbench-nav-toolbar","data-tauri-drag-region":be,children:[oe?t.jsx("button",{type:"button",className:"workbench-nav-toolbar-button","aria-label":r("shell.hideSessionSidebar"),title:r("shell.hideSessionSidebar"),onClick:oe,children:t.jsx(Vl,{})}):null,t.jsx(yl,{}),t.jsx(Kl,{unreadCount:X,open:ke,onToggle:we})]})}),t.jsxs("div",{className:"workbench-nav-body",children:[t.jsxs("div",{className:"workbench-nav-segment",children:[t.jsxs("div",{className:"workbench-nav-segment-tabs",role:"tablist","aria-label":r("shell.centerTabsLabel"),children:[t.jsxs("div",{className:"workbench-nav-segment-pair",children:[t.jsxs("button",{type:"button",className:h?"workbench-nav-segment-button active":"workbench-nav-segment-button","data-layout":"paired",role:"tab","aria-selected":h,onClick:H,children:[t.jsx(If,{}),t.jsx("span",{children:r("shell.conversationEntry")})]}),t.jsxs("button",{type:"button",className:k?"workbench-nav-segment-button active":"workbench-nav-segment-button","data-layout":"paired",role:"tab","aria-selected":k,onClick:x,children:[t.jsx(Mf,{}),t.jsx("span",{children:r("shell.butlerEntry")})]})]}),t.jsxs("button",{type:"button",className:f?"workbench-nav-segment-button active":"workbench-nav-segment-button",role:"tab","aria-selected":f,onClick:W,children:[t.jsx(Rf,{}),t.jsx("span",{children:r("shell.terminalsEntry")})]})]}),t.jsx(Gd,{triggerClassName:"workbench-nav-segment-button",triggerLabel:r("shell.skillsEntry"),triggerLeading:t.jsx(Ef,{})}),t.jsxs("button",{type:"button",className:"workbench-nav-segment-button","data-open":p,"aria-haspopup":"dialog","aria-expanded":p,onClick:A,children:[t.jsx(Tf,{}),t.jsx("span",{children:r("shell.searchEntry")})]})]}),N?t.jsx("div",{className:"workbench-status-row",children:t.jsx("p",{className:"status-text","data-tone":"error",children:N})}):null,i.length>0?t.jsxs("section",{className:"workbench-section-block workbench-favorite-section",children:[t.jsxs("div",{className:"workbench-section-heading",children:[t.jsxs("div",{className:"workbench-section-heading-main",children:[t.jsx(Xl,{active:!0,className:"workbench-favorite-heading-icon"}),t.jsx("span",{children:r("shell.favoriteSectionTitle")})]}),t.jsx("span",{className:"workbench-section-counter",children:i.length})]}),t.jsxs("div",{className:"workbench-session-list",children:[jr.map(d=>{const m=ci(d.session.sessionId);return t.jsx("div",{children:us({node:{item:d.session,depth:0,children:m},workspace:d.workspace,workspaceContext:gn(d.workspace),menuKeyPrefix:"favorite",showWorkspaceName:!0,selectionMode:!1,favoriteEnabled:!0})},d.session.sessionId)}),Nr?t.jsx("button",{type:"button",className:"workbench-subsession-expand ghost-button",onClick:pr,children:r("shell.favoriteExpandMore")}):null]})]}):null,w&&e.length===0?t.jsx(xf,{}):null,!w&&!N&&e.length===0?t.jsx("div",{className:"workbench-empty-state minimal",children:t.jsx("p",{children:r("shell.emptyNavigationBody")})}):null,t.jsxs("section",{className:"workbench-section-block workbench-workspace-section",children:[t.jsxs("div",{className:"workbench-section-heading",children:[t.jsx("div",{className:"workbench-section-heading-main",children:t.jsx("span",{children:r("shell.workspaceSectionTitle")})}),t.jsxs("div",{className:"workbench-section-actions",children:[t.jsx("button",{type:"button",className:"workbench-workspace-icon-button","aria-label":r("shell.manageWorkspaceAction"),title:r("shell.manageWorkspaceAction"),onClick:()=>ut(!0),children:t.jsx(Sf,{})}),t.jsx("button",{type:"button",className:"workbench-workspace-icon-button","aria-label":r("shell.importWorkspaceTitle"),title:r("shell.importWorkspaceTitle"),onClick:Ps,children:t.jsx(yf,{})}),t.jsx("button",{type:"button",className:"workbench-workspace-icon-button","aria-label":r("shell.cloneWorkspaceTitle"),title:r("shell.cloneWorkspaceTitle"),onClick:Ws,children:t.jsx(Pf,{})})]})]}),e.map(d=>{const m=Ks(d),g=Ke===d.workspace.id,M=d.isCollapsed||_n;return t.jsxs("section",{className:"workbench-workspace-group",ref:P=>As(d.workspace.id,P),"data-workspace-group-id":d.workspace.id,"data-batch-active":it===d.workspace.id,"data-dragging":g,onDragOver:P=>pt(P,d.workspace.id),onDrop:Be,children:[t.jsxs("div",{className:"workbench-workspace-header minimal",children:[t.jsxs("button",{type:"button",className:"workbench-workspace-toggle","aria-label":M?r("shell.workspaceExpand"):r("shell.workspaceCollapse"),draggable:j&&!It,onClick:()=>cs(d.workspace.id),onPointerDown:It?P=>se(P,d.workspace.id):void 0,onPointerMove:It?ds:void 0,onPointerUp:It?On:void 0,onPointerCancel:It?li:void 0,onDragStart:j&&!It?P=>Hn(P,d.workspace.id):void 0,onDragEnd:j&&!It?Un:void 0,"data-reorder-enabled":j?"true":void 0,children:[t.jsx("span",{className:"workbench-workspace-toggle-icon","aria-hidden":"true",children:t.jsx(Xs,{expanded:!M})}),t.jsx("strong",{children:d.workspace.name})]}),it===d.workspace.id?Fs():gr(d.workspace.id)]}),M?null:t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"workbench-session-list",children:[m.length===0?t.jsx("p",{className:"workbench-session-empty",children:r("shell.emptyWorkspaceSessions")}):m.slice(0,bt(d.workspace.id)).map(P=>us({node:P,workspace:d.workspace,workspaceContext:gn(d.workspace),menuKeyPrefix:`workspace:${d.workspace.id}`,showWorkspaceName:!1,selectionMode:it===d.workspace.id,favoriteEnabled:!0})),m.length>bt(d.workspace.id)?t.jsx("button",{type:"button",className:"workbench-subsession-expand ghost-button",onClick:()=>$n(d.workspace.id,m.length),children:r("shell.sessionExpandMore")}):null]}),d.childWorktrees.length>0?t.jsx("div",{className:"workbench-session-list workbench-worktree-child-list",children:d.childWorktrees.map(P=>wr(P))}):null,kr(d.workspace,d.archivedSessions)]})]},d.workspace.id)})]})]}),t.jsx("div",{className:"workbench-nav-footer minimal",children:t.jsxs("div",{className:"workbench-nav-footer-actions",children:[t.jsxs("button",{className:"settings-entry-button workbench-nav-settings-button",type:"button",onClick:I,title:_?`${r("settings.title")} · ${Ee}`:r("settings.title"),children:[t.jsx(Wf,{}),t.jsx("span",{className:"settings-entry-label",children:r("settings.title")}),_?t.jsx("span",{className:"workbench-nav-settings-host-badge",title:Ee,children:Ee}):null]}),t.jsx(hh,{onOpenSoftwareUpdate:()=>ae("/settings/software-update")})]})}),t.jsx($e,{open:Pe,title:r("shell.manageWorkspaceTitle"),className:"workbench-manage-workspaces-modal",description:r("shell.manageWorkspaceDescription"),headerActions:t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",className:"secondary-button workbench-manage-modal-action",onClick:Ps,children:r("shell.manageWorkspaceImportAction")}),t.jsx("button",{type:"button",className:"secondary-button workbench-manage-modal-action",onClick:Ws,children:r("shell.manageWorkspaceCloneAction")})]}),onClose:()=>{Fe||ut(!1)},children:e.length>0?t.jsx("div",{className:"workbench-manage-list",children:e.map(d=>Hs(d.workspace,d.visibleSessions.length+d.archivedSessions.length,d.childWorktrees,!1))}):t.jsx("p",{className:"workbench-section-empty",children:r("shell.manageWorkspaceEmpty")})}),t.jsxs($e,{open:Bn!==null,title:r("shell.deleteSessionConfirmTitle"),description:r("shell.deleteSessionConfirmDescription"),onClose:()=>{on||yt(null)},children:[t.jsx("p",{className:"workbench-section-empty",children:Bn?Bn.session.title:""}),t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:!!on,onClick:()=>yt(null),children:r("common.cancel")}),t.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:!!on,onClick:()=>{xr()},children:on?r("common.loading"):r("shell.deleteSessionAction")})]})]}),t.jsxs($e,{open:Je!==null,title:r("shell.manageWorkspaceRemoveConfirmTitle"),description:r("shell.manageWorkspaceRemoveConfirmDescription"),onClose:()=>{Fe||wt(null)},children:[t.jsx("p",{className:"workbench-section-empty",children:Je?r("shell.manageWorkspaceRemoveConfirmTarget",{name:Je.name}):""}),t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:!!Fe,onClick:()=>wt(null),children:r("common.cancel")}),t.jsx("button",{type:"button",className:"secondary-button workbench-danger-button",disabled:!!Fe,onClick:()=>{fr()},children:Fe?r("shell.manageWorkspaceRemoving"):r("shell.manageWorkspaceRemoveConfirmAction")})]})]}),t.jsx(sh,{open:le,onClose:()=>F(!1),onCloned:as}),t.jsx(uh,{open:y,onClose:()=>$(!1),onImported:os}),t.jsx($e,{open:Ie!==null,title:r("shell.createSessionModalTitle"),className:"workbench-create-session-modal",description:Ie?`${r("shell.createSessionTarget")} · ${Ie.name}`:r("shell.createSessionModalDescription"),headerActions:t.jsx("button",{type:"button",className:"secondary-button create-session-worktree-trigger",disabled:Ze||!!lt,onClick:()=>Kt(!0),children:r("shell.createWorktreeAction")}),onClose:()=>zt(null),children:t.jsxs("section",{className:"create-session-modal-section",children:[t.jsxs("div",{className:"create-session-modal-section-header",children:[t.jsx("strong",{children:r("shell.createSessionProviderLabel")}),t.jsx("span",{children:r("shell.providerOptionHint")})]}),t.jsx(Rc,{disabled:!!lt||Ze,workspaceId:(Ie==null?void 0:Ie.id)??null,pendingProvider:lt===(Ie==null?void 0:Ie.id)?He??null:null,onSelect:d=>{Ie&&mi(Ie.id,d)}})]})}),t.jsx($e,{open:Ie!==null&&At,title:r("shell.createWorktreeAction"),className:"workbench-create-worktree-modal",headerActions:t.jsx("button",{type:"button",className:Mn?"workbench-modal-help-button active":"workbench-modal-help-button","aria-label":r("shell.createWorktreeHelpAction"),title:r("shell.createWorktreeHelpAction"),"aria-pressed":Mn,onClick:()=>En(d=>!d),children:t.jsx(Hf,{})}),description:Ie?`${r("shell.createWorktreeSectionDescription")} ${r("shell.createSessionTarget")} · ${Ie.name}`:r("shell.createWorktreeSectionDescription"),onClose:ls,children:t.jsxs("form",{className:"create-session-worktree-form",onSubmit:Qt,children:[Mn?t.jsxs("section",{className:"create-session-worktree-help-card","aria-label":r("shell.createWorktreeHelpTitle"),children:[t.jsx("strong",{children:r("shell.createWorktreeHelpTitle")}),t.jsxs("div",{className:"create-session-worktree-help-grid",children:[t.jsxs("article",{children:[t.jsx("h3",{children:r("shell.createWorktreeHelpBranchTitle")}),t.jsx("p",{children:r("shell.createWorktreeHelpBranchBody")})]}),t.jsxs("article",{children:[t.jsx("h3",{children:r("shell.createWorktreeHelpDisplayNameTitle")}),t.jsx("p",{children:r("shell.createWorktreeHelpDisplayNameBody")})]}),t.jsxs("article",{children:[t.jsx("h3",{children:r("shell.createWorktreeHelpBaseRefTitle")}),t.jsx("p",{children:r("shell.createWorktreeHelpBaseRefBody")})]})]})]}):null,t.jsxs("label",{className:"create-session-worktree-field",children:[t.jsx("span",{children:r("shell.createWorktreeBranchLabel")}),t.jsx("input",{className:"settings-text-input",value:xt,placeholder:r("shell.createWorktreeBranchPlaceholder"),onChange:d=>{const m=d.target.value;Wh(m)&&Rn(m)}})]}),t.jsxs("label",{className:"create-session-worktree-field",children:[t.jsx("span",{children:r("shell.createWorktreeDisplayNameLabel")}),t.jsx("input",{className:"settings-text-input",value:Cs,placeholder:r("shell.createWorktreeDisplayNamePlaceholder"),onChange:d=>rn(d.target.value)})]}),t.jsxs("label",{className:"create-session-worktree-field",children:[t.jsx("span",{children:r("shell.createWorktreeBaseRefLabel")}),t.jsx("div",{className:"create-session-worktree-combobox",ref:Ve,onBlurCapture:d=>{var g,M;const m=d.relatedTarget;m instanceof Node&&((g=Ve.current)!=null&&g.contains(m)||(M=Tt.current)!=null&&M.contains(m))||(ze(!1),et(-1))},children:t.jsxs("div",{className:"create-session-worktree-combobox-input-wrap",children:[t.jsx("input",{className:"settings-text-input create-session-worktree-combobox-input",role:"combobox","aria-autocomplete":"list","aria-expanded":Qe,"aria-controls":Es,value:Jn,placeholder:r("shell.createWorktreeBaseRefPlaceholder"),onFocus:()=>{ze(!0),et(dt.length>0?0:-1)},onChange:d=>{xe(d.target.value),ze(!0),et(dt.length>0?0:-1)},onKeyDown:d=>{if(d.key==="ArrowDown"){if(d.preventDefault(),!Qe){ze(!0);return}dt.length>0&&et(m=>m>=dt.length-1?0:m+1);return}if(d.key==="ArrowUp"){if(d.preventDefault(),!Qe){ze(!0);return}dt.length>0&&et(m=>m<=0?dt.length-1:m-1);return}if(d.key==="Enter"&&Qe&&Ts>=0){d.preventDefault();const m=dt[Ts];m&&(xe(m.value),ze(!1),et(-1));return}d.key==="Escape"&&ze(!1)}}),t.jsx("button",{type:"button",className:"create-session-worktree-combobox-toggle","aria-label":r("shell.createWorktreeBaseRefToggle"),"aria-expanded":Qe,onClick:()=>{ze(d=>!d),et(!Qe&&dt.length>0?0:-1)},children:t.jsx(Xs,{expanded:Qe})})]})}),t.jsx("span",{className:"create-session-worktree-field-hint",children:Zn?r("shell.createWorktreeBaseRefLoading"):Bt||r("shell.createWorktreeBaseRefHint",{localCount:Vt.localBranches.length,remoteCount:Vt.remoteBranches.length,tagCount:Vt.tags.length})})]}),Qe&&vt&&typeof document<"u"?tr.createPortal(t.jsxs("div",{className:"create-session-worktree-combobox-floating-layer",children:[t.jsx("div",{className:"create-session-worktree-combobox-floating-backdrop",style:{"--create-worktree-combobox-top":`${vt.top}px`,"--create-worktree-combobox-left":`${vt.left}px`,"--create-worktree-combobox-width":`${vt.width}px`,"--create-worktree-combobox-height":`${ii??0}px`}}),t.jsx("div",{ref:Tt,className:"create-session-worktree-combobox-popover floating",style:{"--create-worktree-combobox-top":`${vt.top}px`,"--create-worktree-combobox-left":`${vt.left}px`,"--create-worktree-combobox-width":`${vt.width}px`},children:Zn?t.jsx("p",{className:"create-session-worktree-combobox-empty",children:r("shell.createWorktreeBaseRefLoading")}):Bt?t.jsx("p",{className:"create-session-worktree-combobox-empty",children:Bt}):mn.length>0?t.jsx("div",{id:Es,className:"create-session-worktree-combobox-list",role:"listbox",children:mn.map(d=>t.jsxs("section",{className:"create-session-worktree-combobox-group","aria-label":d.label,children:[t.jsx("header",{className:"create-session-worktree-combobox-group-title",children:d.label}),t.jsx("div",{className:"create-session-worktree-combobox-group-options",children:d.items.map(m=>{const g=dt.findIndex(te=>te.value===m.value),M=Jn===m.value,P=Ts===g;return t.jsxs("button",{type:"button",role:"option",className:"create-session-worktree-combobox-option","aria-selected":M,"data-highlighted":P,onMouseDown:te=>te.preventDefault(),onMouseEnter:()=>et(g),onClick:()=>{xe(m.value),ze(!1),et(-1)},children:[t.jsx("span",{className:"create-session-worktree-combobox-option-label",children:m.value}),t.jsxs("span",{className:"create-session-worktree-combobox-option-badges",children:[m.current?t.jsx("span",{className:"create-session-worktree-combobox-badge",children:r("shell.createWorktreeBaseRefCurrentBadge")}):null,m.recommended?t.jsx("span",{className:"create-session-worktree-combobox-badge recommended",children:r("shell.createWorktreeBaseRefRecommendedBadge")}):null]})]},`${d.key}:${m.value}`)})})]},d.key))}):t.jsx("p",{className:"create-session-worktree-combobox-empty",children:r("shell.createWorktreeBaseRefEmpty")})})]}),document.body):null,t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:Ze,onClick:ls,children:r("common.cancel")}),t.jsx("button",{type:"submit",className:"primary-button",disabled:Ze,children:Ze?r("shell.createWorktreeSubmitting"):r("shell.createWorktreeSubmit")})]})]})}),t.jsx($e,{open:ft!==null,title:r("shell.archiveModalTitle"),description:ft?`${ft.workspace.name} · ${r("shell.archiveModalDescription")}`:r("shell.archiveModalDescription"),onClose:()=>Xt(null),children:ft&&ft.archivedSessions.length>0?t.jsx("div",{className:"workbench-archive-list","data-workspace-tone":(Ye==null?void 0:Ye.tone)??"root",style:tn(Ye),children:ft.archivedSessions.map(d=>{const m=ro(d.title,r("common.unknown"));return t.jsxs("article",{className:"workbench-archive-item","data-workspace-tone":(Ye==null?void 0:Ye.tone)??"root",style:tn(Ye),children:[t.jsxs("div",{className:"workbench-archive-item-main",children:[t.jsx("strong",{title:m.fullTitle,children:m.displayTitle}),t.jsxs("p",{children:[Rl(d,ft.workspace,!1)," ·"," ",si(d.provider)]})]}),t.jsx("button",{type:"button",className:"secondary-button",onClick:()=>yr(d.sessionId),children:r("shell.unarchiveAction")})]},d.sessionId)})}):t.jsx("p",{className:"workbench-section-empty",children:r("shell.archiveEmpty")})}),t.jsx($e,{open:nt!==null,title:r("shell.renameModalTitle"),description:r("shell.renameModalDescription"),onClose:()=>{un||(jt(null),Zt(""))},children:t.jsxs("form",{className:"workbench-rename-form",onSubmit:Sr,children:[t.jsxs("label",{className:"workbench-modal-field",children:[t.jsx("span",{children:r("shell.renameInputLabel")}),t.jsx("input",{type:"text",value:Nt,placeholder:r("shell.renameInputPlaceholder"),maxLength:120,autoFocus:!0,onChange:d=>Zt(d.target.value)})]}),t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:!!un,onClick:()=>{jt(null),Zt("")},children:r("common.cancel")}),t.jsx("button",{type:"submit",className:"primary-button",disabled:!Nt.trim()||un===(nt==null?void 0:nt.session.sessionId),children:un===(nt==null?void 0:nt.session.sessionId)?r("shell.renamingSession"):r("common.save")})]})]})})]})}function Ma({panelReady:e,activeTab:n,fileRevealRequest:s,onTabChange:i,onToggleCollapse:o,currentSessionId:c,activeWorkspaceId:h,navigationGroups:f,workspaceContext:k,worktreeMeta:p,worktreeMergeState:w,onRefreshWorktreeMergePreview:N,onApplyWorktreeMerge:C,onCleanupWorktree:R}){var ue;const O=h??((ue=f[0])==null?void 0:ue.workspace.id)??null,H=Tn(),W=dl(H),{showToast:x}=Xn(),A=l.useRef(null),I=l.useRef(null),G=H.isDesktop&&H.bridge.supported,K=G&&!!h,Y=G&&!!O,z=G&&!!O,q=typeof globalThis<"u"&&"PointerEvent"in globalThis,j=l.useCallback(async(U,ce,D)=>{if(U==="files"){const S=await Fd(H,{workspaceId:ce,sessionId:D,focusOwner:"file-context-panel"});S.ok||x({title:S.detail??r("conversation.filePanelOpenExternalFailed"),tone:"error"});return}if(U==="git"){const S=await Od(H,{workspaceId:ce,focusOwner:"git-sidebar"});S.ok||x({title:S.detail??r("git.openExternalFailed"),tone:"error"});return}const v=await Hd(H,{workspaceId:ce,focusOwner:"terminal-manager-panel"});v.ok||x({title:v.detail??r("terminalManager.openExternalFailed"),tone:"error"})},[H,x]),J=l.useCallback((U,ce)=>{if(U.button!==0||!G)return;const D=ce==="files"?h:ce==="git"||ce==="terminals"?O:null;if(!D)return;const v=ce==="files"?c:null;A.current={tab:ce,startX:U.clientX,startY:U.clientY,workspaceId:D,sessionId:v,detached:!1,preview:null};const S=ne=>{var be;const oe=A.current;if(!oe)return;const ae=Math.abs(ne.clientX-oe.startX),he=Math.abs(ne.clientY-oe.startY);!oe.detached&&Math.max(ae,he)<ua||(oe.detached||(oe.detached=!0,I.current=oe.tab,oe.preview=Eo({title:oe.tab==="files"?r("shell.filesEntry"):oe.tab==="git"?r("shell.gitEntry"):r("shell.terminalManagerEntry"),x:ne.clientX,y:ne.clientY})),(be=oe.preview)==null||be.updatePosition(ne.clientX,ne.clientY))},X=ne=>{var ae;const oe=(ae=A.current)==null?void 0:ae.preview;ne&&(oe==null||oe.cancel()),window.removeEventListener("mousemove",S),window.removeEventListener("mouseup",ke),window.removeEventListener("blur",we),A.current=null},ke=async()=>{var oe;const ne=A.current;X(!1),ne!=null&&ne.detached&&(await((oe=ne.preview)==null?void 0:oe.complete()),await j(ne.tab,ne.workspaceId,ne.sessionId))},we=()=>{X(!0)};window.addEventListener("mousemove",S),window.addEventListener("mouseup",ke),window.addEventListener("blur",we)},[h,G,c,O,j]),Q=l.useCallback((U,ce)=>{if(U.button!==0||!G)return;const D=ce==="files"?h:ce==="git"||ce==="terminals"?O:null;if(!D)return;const v=U.currentTarget,S=U.pointerId;v.setPointerCapture(S);const X=ce==="files"?c:null;A.current={tab:ce,startX:U.clientX,startY:U.clientY,workspaceId:D,sessionId:X,detached:!1,preview:null};const ke=he=>{var Ee;if(he.pointerId!==S)return;const be=A.current;if(!be)return;const me=Math.abs(he.clientX-be.startX),Ge=Math.abs(he.clientY-be.startY);!be.detached&&Math.max(me,Ge)<ua||(be.detached||(be.detached=!0,I.current=be.tab,be.preview=Eo({title:be.tab==="files"?r("shell.filesEntry"):be.tab==="git"?r("shell.gitEntry"):r("shell.terminalManagerEntry"),x:he.clientX,y:he.clientY})),(Ee=be.preview)==null||Ee.updatePosition(he.clientX,he.clientY))},we=he=>{var me;const be=(me=A.current)==null?void 0:me.preview;he&&(be==null||be.cancel()),v.removeEventListener("pointermove",ke),v.removeEventListener("pointerup",ne),v.removeEventListener("pointercancel",oe),v.removeEventListener("lostpointercapture",oe),window.removeEventListener("blur",ae),A.current=null,v.hasPointerCapture(S)&&v.releasePointerCapture(S)},ne=async he=>{var me;if(he.pointerId!==S)return;const be=A.current;we(!1),be!=null&&be.detached&&(await((me=be.preview)==null?void 0:me.complete()),await j(be.tab,be.workspaceId,be.sessionId))},oe=he=>{he.pointerId===S&&we(!0)},ae=()=>{we(!0)};v.addEventListener("pointermove",ke),v.addEventListener("pointerup",ne),v.addEventListener("pointercancel",oe),v.addEventListener("lostpointercapture",oe),window.addEventListener("blur",ae)},[h,G,c,O,j]),E=l.useCallback(U=>{if(I.current===U){I.current=null;return}i(U)},[i]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"workbench-auxiliary-header","data-workspace-tone":(k==null?void 0:k.tone)??"root",style:tn(k),"data-window-drag-handle":"workbench-auxiliary-header","data-tauri-drag-region":W,children:[o?t.jsx("button",{type:"button",className:"workbench-nav-toolbar-button","aria-label":r("shell.hideInfoSidebar"),title:r("shell.hideInfoSidebar"),onClick:o,children:t.jsx(Vl,{})}):null,t.jsxs("div",{className:"workbench-info-tabs",role:"tablist","aria-label":r("shell.infoTabsLabel"),"data-tauri-drag-region":W,children:[t.jsx("button",{className:n==="files"?"workbench-info-tab active":"workbench-info-tab",type:"button",role:"tab","aria-selected":n==="files",title:K?"拖拽标签到独立窗口":void 0,onPointerDown:U=>Q(U,"files"),onMouseDown:q?void 0:U=>J(U,"files"),onClick:()=>E("files"),children:r("shell.filesEntry")}),t.jsx("button",{className:n==="git"?"workbench-info-tab active":"workbench-info-tab",type:"button",role:"tab","aria-selected":n==="git",title:Y?"拖拽标签到独立窗口":void 0,onPointerDown:U=>Q(U,"git"),onMouseDown:q?void 0:U=>J(U,"git"),onClick:()=>E("git"),children:r("shell.gitEntry")}),t.jsx("button",{className:n==="terminals"?"workbench-info-tab active":"workbench-info-tab",type:"button",role:"tab","aria-selected":n==="terminals",title:z?"拖拽标签到独立窗口":void 0,onPointerDown:U=>Q(U,"terminals"),onMouseDown:q?void 0:U=>J(U,"terminals"),onClick:()=>E("terminals"),children:r("shell.terminalManagerEntry")})]})]}),t.jsxs("div",{className:"workbench-auxiliary-body",children:[e?null:t.jsx(Gr,{}),e&&n==="git"&&p?t.jsx(qf,{meta:p,state:w,onRefresh:()=>N(p.workspaceId,!0),onApply:()=>C(p.workspaceId),onCleanup:()=>R(p)}):null,e&&n==="files"?h?t.jsx(l.Suspense,{fallback:t.jsx(Gr,{}),children:t.jsx($h,{sessionId:c,workspaceId:h,externalRevealRequest:s})}):t.jsx("section",{className:"workbench-empty-state minimal",children:t.jsx("p",{children:r("shell.filesPanelEmpty")})}):null,e&&n==="git"?O?t.jsx(l.Suspense,{fallback:t.jsx(Gr,{}),children:t.jsx(qh,{workspaceId:O})}):t.jsx("section",{className:"workbench-empty-state minimal",children:t.jsx("p",{children:r("shell.gitPanelEmpty")})}):null,e&&n==="terminals"?t.jsx(l.Suspense,{fallback:t.jsx(Gr,{}),children:t.jsx(Gh,{currentWorkspaceId:h,navigationGroups:f})}):null]})]})}function qf({meta:e,state:n,onRefresh:s,onApply:i,onCleanup:o}){const[c,h]=l.useState(!1),f=(n==null?void 0:n.preview)??null,k=(n==null?void 0:n.loading)??!1,p=(n==null?void 0:n.applying)??!1,w=(n==null?void 0:n.cleaning)??!1,N=f!==null,C=(f==null?void 0:f.alreadyMerged)===!0,R=new Set((f==null?void 0:f.blockers.map(E=>E.code))??[]),O=R.size>0||!!(n!=null&&n.error),H=C&&!O,W=(f==null?void 0:f.canMerge)===!0&&!k&&!p&&!w&&!H,x=H&&!k&&!p&&!w&&!R.has("SOURCE_DIRTY")&&!R.has("HAS_ACTIVE_CHILDREN"),A=k||p||w?"loading":O?"blocked":H?"merged":f!=null&&f.canMerge?"ready":N?"blocked":"idle",I=(f==null?void 0:f.targetWorkspace.name)??r("common.unknown"),G=(f==null?void 0:f.sourceBranchName)??e.branchName,K=(f==null?void 0:f.targetBranchName)??e.baseRef??r("common.unknown"),Y=zf({t:r,hasPreview:N,showMergedState:H,isMerged:C,canMerge:(f==null?void 0:f.canMerge)===!0,ahead:(f==null?void 0:f.ahead)??0,blockerCodeSet:R}),z=k?r("shell.worktreeMergePreviewLoading"):p?r("shell.worktreeMergeApplying"):w?r("shell.worktreeCleanupRunning"):H?r("shell.worktreeMergeAlreadyMerged"):f!=null&&f.canMerge?r("shell.worktreeMergeReady"):N?r("shell.worktreeMergeBlocked"):r("shell.worktreeMergePreviewIdle"),q=[r("shell.worktreeMergeCurrentBranch",{branch:G}),r("shell.worktreeMergeParentBranch",{branch:K}),r("shell.worktreeMergeTargetWorkspace",{name:I}),f?r("shell.worktreeMergeAheadBehind",{ahead:f.ahead,behind:f.behind}):r("shell.worktreeMergeAheadBehindPending"),f!=null&&f.mergeBaseCommit?r("shell.worktreeMergeBaseCommit",{commit:gf(f.mergeBaseCommit)}):null].filter(E=>!!E),j=`worktree-merge-panel-details-${e.workspaceId}`,J=c?r("shell.worktreeMergeCollapseDetails"):r("shell.worktreeMergeExpandDetails"),Q=Gf({t:r,loading:k,applying:p,cleaning:w,hasPreview:N,canMerge:(f==null?void 0:f.canMerge)===!0,showMergedState:H,blockerCodeSet:R});return l.useEffect(()=>{h(!1)},[e.workspaceId]),t.jsxs("section",{className:"worktree-merge-panel","data-state":A,children:[t.jsxs("button",{type:"button",className:"worktree-merge-panel-summary","aria-label":J,"aria-expanded":c,"aria-controls":j,onClick:()=>{h(E=>!E)},children:[t.jsx("span",{className:"worktree-merge-panel-summary-label",children:r("shell.worktreeMergePanelLabel")}),t.jsx("span",{className:"worktree-merge-panel-summary-main",children:t.jsx("span",{className:"worktree-merge-panel-summary-tags",children:Q.map(E=>t.jsx("span",{className:"worktree-merge-panel-summary-tag","data-state":A,children:E},E))})}),t.jsx("span",{className:"worktree-merge-panel-summary-toggle",children:J})]}),c?t.jsxs("div",{id:j,className:"worktree-merge-panel-details",children:[t.jsx("div",{className:"worktree-merge-panel-detail-head",children:t.jsx("span",{className:"worktree-merge-panel-status","data-state":A,children:z})}),t.jsx("div",{className:"worktree-merge-panel-meta",children:q.map(E=>t.jsx("span",{children:E},E))}),N?t.jsx("div",{className:"worktree-merge-panel-checklist","aria-label":r("shell.worktreeMergeChecklistTitle"),children:Y.map(E=>t.jsxs("div",{className:"worktree-merge-panel-checklist-item","data-state":E.state,children:[t.jsx("span",{className:"worktree-merge-panel-checklist-marker","aria-hidden":"true",children:E.state==="done"?"✓":E.state==="blocked"?"!":"·"}),t.jsxs("span",{className:"worktree-merge-panel-checklist-copy",children:[t.jsx("strong",{children:E.label}),E.detail?t.jsx("span",{children:E.detail}):null]})]},E.key))}):null,n!=null&&n.error?t.jsx("p",{className:"worktree-merge-panel-error status-text","data-tone":"error",children:n.error}):null,f!=null&&f.conflictPaths.length?t.jsxs("div",{className:"worktree-merge-panel-conflicts",children:[t.jsx("span",{className:"worktree-merge-panel-conflicts-label",children:r("shell.worktreeMergeConflictLabel")}),t.jsx("div",{className:"worktree-merge-panel-conflict-list",children:f.conflictPaths.map(E=>t.jsx("code",{children:E},E))})]}):null,t.jsxs("div",{className:"worktree-merge-panel-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:k||p||w,onClick:s,children:N?r("shell.worktreeMergePreviewRefresh"):r("shell.worktreeMergePreviewAction")}),t.jsx("button",{type:"button",className:"primary-button",disabled:!W,onClick:i,children:p?r("shell.worktreeMergeApplying"):r("shell.worktreeMergeApplyAction")}),t.jsx("button",{type:"button",className:"secondary-button worktree-merge-panel-cleanup-button",disabled:!x,onClick:o,children:w?r("shell.worktreeCleanupRunning"):r("shell.worktreeCleanupAction")})]})]}):null]})}function Gf(e){const{t:n,loading:s,applying:i,cleaning:o,hasPreview:c,canMerge:h,showMergedState:f,blockerCodeSet:k}=e;if(s)return[n("shell.worktreeMergeCompactChecking")];if(i)return[n("shell.worktreeMergeCompactMerging")];if(o)return[n("shell.worktreeMergeCompactCleaning")];const p=[];return k.has("SOURCE_NOT_ACTIVE")&&p.push(n("shell.worktreeMergeCompactInactive")),k.has("SOURCE_DIRTY")&&p.push(n("shell.worktreeMergeCompactDirty")),k.has("TARGET_DIRTY")&&p.push(n("shell.worktreeMergeCompactTargetDirty")),k.has("HAS_CONFLICTS")&&p.push(n("shell.worktreeMergeCompactConflict")),k.has("HAS_ACTIVE_CHILDREN")&&p.push(n("shell.worktreeMergeCompactChildren")),p.length>0?p:h?[n("shell.worktreeMergeCompactReady")]:f?[n("shell.worktreeMergeCompactMerged")]:c?k.has("NO_COMMITS_TO_MERGE")?[n("shell.worktreeMergeCompactNoCommits")]:[n("shell.worktreeMergeCompactBlocked")]:[n("shell.worktreeMergeCompactPending")]}function zf(e){const{t:n,hasPreview:s,showMergedState:i,isMerged:o,canMerge:c,ahead:h,blockerCodeSet:f}=e,k=f.has("SOURCE_NOT_ACTIVE"),p=f.has("SOURCE_DIRTY"),w=f.has("TARGET_DIRTY"),N=f.has("HAS_ACTIVE_CHILDREN"),C=f.has("HAS_CONFLICTS"),R=s&&!o&&(f.has("NO_COMMITS_TO_MERGE")||h<=0),O=i?{key:"merge-result",label:n("shell.worktreeMergeChecklistResultMerged"),detail:n("shell.worktreeMergeMergedHint"),state:"done"}:c?{key:"merge-result",label:n("shell.worktreeMergeChecklistResultReady"),detail:n("shell.worktreeMergeChecklistResultReadyDetail"),state:"done"}:s?{key:"merge-result",label:n("shell.worktreeMergeChecklistResultBlocked"),detail:n("shell.worktreeMergeChecklistResultBlockedDetail"),state:"blocked"}:{key:"merge-result",label:n("shell.worktreeMergeChecklistResultPending"),detail:null,state:"pending"};return[{key:"source-state",label:n("shell.worktreeMergeChecklistSourceState"),detail:s&&k?n("shell.worktreeMergeChecklistSourceStateBlocked"):null,state:s?k?"blocked":"done":"pending"},{key:"clean-source",label:n("shell.worktreeMergeChecklistSourceClean"),detail:s&&p?n("shell.worktreeMergeChecklistSourceCleanBlocked"):null,state:s?p?"blocked":"done":"pending"},{key:"clean-target",label:n("shell.worktreeMergeChecklistTargetClean"),detail:s&&w?n("shell.worktreeMergeChecklistTargetCleanBlocked"):null,state:s?w?"blocked":"done":"pending"},{key:"children",label:n("shell.worktreeMergeChecklistChildren"),detail:s&&N?n("shell.worktreeMergeChecklistChildrenBlocked"):null,state:s?N?"blocked":"done":"pending"},{key:"commits",label:n("shell.worktreeMergeChecklistCommits"),detail:R?n(o?"shell.worktreeMergeMergedDirtyHint":"shell.worktreeMergeChecklistCommitsBlocked"):null,state:R?o?"done":"blocked":s?"done":"pending"},{key:"conflicts",label:n("shell.worktreeMergeChecklistConflicts"),detail:C?n("shell.worktreeMergeChecklistConflictsBlocked"):null,state:C?"blocked":s?"done":"pending"},O]}function Zm({shellMode:e="desktop"}){var Ne,wn,Ot,Ce,Cr,ms,Tr,Ir,Rr,Mr,xn,vn,co,uo,ho;const n=Qr(),s=er(),i=Tn(),{showToast:o}=Xn(),c=Er(a=>a.sessionDisplaySortMode),h=Er(a=>a.notificationPreferences.notifyOnPermissionRequest),f=Er(a=>a.notificationPreferences.notifyOnSessionCompleted),k=Er(a=>a.notificationPreferences.notifyOnSessionFailed),p=l.useRef(Ru(gl)),w=l.useRef(0),N=l.useRef((((wn=(Ne=p.current)==null?void 0:Ne.items)==null?void 0:wn.length)??0)>0),C=l.useRef(new Map),R=l.useRef(!1),O=l.useRef(null),H=l.useRef(0),W=l.useRef(null),x=l.useRef(null),A=l.useRef(new Set),I=l.useRef(new Set),G=l.useRef(new Set),K=l.useRef(new Set),Y=l.useRef(null),z=l.useRef(null),q=l.useRef(null),j=l.useRef(null),J=l.useRef(null),Q=l.useRef(null),E=l.useRef(null),ue=l.useRef(null),U=l.useRef(0),ce=l.useRef(0),D=l.useRef(o),v=l.useRef(i.bridge),S=l.useRef(null),X=l.useRef(0),ke=l.useRef(0),we=l.useRef(null),ne=l.useRef(null),oe=l.useRef(null),ae=l.useRef(!1),he=l.useRef(!1),be=l.useRef(!1),me=l.useRef(new Map),Ge=l.useRef(!1),Ee=l.useRef(new Map),_=l.useRef(""),y=l.useRef([]),$=l.useRef(c),le=l.useRef(null),[F,Pe]=l.useState(()=>Ho(p.current,c)),ut=l.useRef(F),[_e,Wt]=l.useState(()=>{var a,u;return(((u=(a=p.current)==null?void 0:a.items)==null?void 0:u.length)??0)===0}),[Je,wt]=l.useState(null),[Fe,ir]=l.useState(()=>$r(ga(ea,fh),ia,aa)),[lt,or]=l.useState(()=>$r(ga(ta,mh),oa,la)),[He,Yn]=l.useState(()=>wa(na,!1)),[Te,zt]=l.useState(()=>wa(sa,!1)),[ct,Ns]=l.useState(null),[At,Kt]=l.useState(()=>ya(p.current)),[Ze,In]=l.useState(()=>xa(Ni)),[xt,Rn]=l.useState(!1),[Cs,rn]=l.useState("files"),[Jn,xe]=l.useState(!1),[Vt,Ae]=l.useState(!1),[Qe,ze]=l.useState(null),[Ts,et]=l.useState({}),[Mn,En]=l.useState(!1),[Zn,Pn]=l.useState("sessions"),[Bt,Wn]=l.useState(""),[vt,Is]=l.useState(""),[ii,An]=l.useState(!1),[oi,Xt]=l.useState(null),[Bn,yt]=l.useState([]),[on,ar]=l.useState(null),[Yt,an]=l.useState({}),Qn=cl(i),lr=l.useCallback(a=>{if(Qn)return;const u=S.current;u&&(!Pi(i,a.button,a.target)||!va(a.clientY,u)||Id({platform:i,button:a.button,target:a.target,clientX:a.clientX,clientY:a.clientY}))},[i,Qn]),ai=l.useCallback(a=>{if(Qn)return;const u=S.current;u&&(!Pi(i,a.button,a.target)||!va(a.clientY,u)||i.bridge.setWindowState("toggle-zoom"))},[i,Qn]),[tt,St]=l.useState({}),[je,es]=l.useState(null),[ln,Ln]=l.useState(!1),[cn,dn]=l.useState([]),[Jt,nt]=l.useState(()=>new Set),[jt,Nt]=l.useState(!1),[Zt,un]=l.useState(!1),[cr,it]=l.useState(0),[Lt,Ct]=l.useState(()=>xa(ra)),st=e==="desktop"&&i.isDesktop&&i.ui.osFamily==="macos"&&i.ui.prefersOverlayTitlebar,{theme:Dn}=dc();l.useEffect(()=>{D.current=o},[o]),l.useEffect(()=>{if(typeof document>"u")return;const{documentElement:a,body:u}=document,b=document.getElementById("root");if(!st){a.removeAttribute("data-workbench-macos-vibrancy"),u==null||u.removeAttribute("data-workbench-macos-vibrancy");return}const T=a.style.background,B=(u==null?void 0:u.style.background)??"",L=(b==null?void 0:b.style.background)??"";return a.setAttribute("data-workbench-macos-vibrancy","true"),u==null||u.setAttribute("data-workbench-macos-vibrancy","true"),a.style.background="transparent",u==null||u.style.setProperty("background","transparent"),b==null||b.style.setProperty("background","transparent"),()=>{a.removeAttribute("data-workbench-macos-vibrancy"),u==null||u.removeAttribute("data-workbench-macos-vibrancy"),a.style.background=T,u&&(u.style.background=B),b instanceof HTMLElement&&(b.style.background=L)}},[st]),l.useEffect(()=>()=>{oe.current!==null&&window.clearTimeout(oe.current)},[]),l.useEffect(()=>{var B;if(typeof document>"u")return;const{documentElement:a,body:u}=document;if(!ct){a.removeAttribute(bs),u==null||u.removeAttribute(bs);return}const b=a.style.cursor,T=(u==null?void 0:u.style.cursor)??"";return a.setAttribute(bs,ct),u==null||u.setAttribute(bs,ct),a.style.cursor="col-resize",u==null||u.style.setProperty("cursor","col-resize"),(B=window.getSelection())==null||B.removeAllRanges(),()=>{a.removeAttribute(bs),u==null||u.removeAttribute(bs),a.style.cursor=b,u&&(u.style.cursor=T)}},[ct]),l.useEffect(()=>{$.current=c,Pe(a=>wf(a,c))},[c]),l.useEffect(()=>{ut.current=F},[F]),l.useEffect(()=>{v.current=i.bridge},[i.bridge]),l.useEffect(()=>{X.current=Fe},[Fe]),l.useEffect(()=>{ke.current=lt},[lt]),l.useEffect(()=>()=>{we.current!==null&&window.cancelAnimationFrame(we.current)},[]);const ts=l.useCallback(async()=>{const a=U.current+1;U.current=a;try{const u=await Lu();if(a!==U.current)return;if(!u.initialized){dn([]),nt(new Set);return}const[b,T,B,L]=await Promise.all([Du(),Ou(),vl(),Uu()]);if(a!==U.current)return;dn(Mh(b.overview,T.items,B.items)),nt(new Set(L.items.map(ee=>ee.notificationId)))}catch{if(a!==U.current)return;dn([]),nt(new Set)}},[]),Rs=l.useCallback(a=>{const u=a.map(b=>b.createdAt).sort((b,T)=>Cn(T)-Cn(b))[0]??null;u&&Ct(b=>b&&Cn(b)>=Cn(u)?b:u)},[]);l.useEffect(()=>{Lt&&Kn(ra,Lt)},[Lt]),l.useEffect(()=>{ts();const a=window.setInterval(()=>{ts()},bh);return()=>{window.clearInterval(a)}},[ts]),l.useEffect(()=>{gt("workbench.layout_mounted",{path:n.pathname,search:n.search})},[n.pathname,n.search]),l.useEffect(()=>{var a,u;gt("workbench.cached_snapshot_loaded",{cached:!!p.current,workspaceCount:((a=p.current)==null?void 0:a.items.length)??0,sessionCount:((u=p.current)==null?void 0:u.items.reduce((b,T)=>b+T.sessions.length,0))??0})},[]);function ns(a){var T;if(!a||!Array.isArray(a.items))return;mf(C.current,a);const u=ff(a,C.current);gt("workbench.apply_snapshot",{workspaceCount:u.items.length,sessionCount:u.items.reduce((B,L)=>B+L.sessions.length,0),currentSessionId:((T=Js(n.pathname))==null?void 0:T.sessionId)??null});const b=Ho(u,$.current);p.current=u,Dr(u),ut.current=b,Pe(b),Kt(ya(u)),wt(null)}const Ke=l.useCallback(async()=>{const a=w.current+1;w.current=a,Wt(u=>u||!N.current),gt("workbench.refresh_navigation.start",{requestId:a,hasNavigationData:N.current});try{const u=await wc();if(a!==w.current){gt("workbench.refresh_navigation.stale",{requestId:a});return}ns(u)}catch(u){if(a!==w.current)return;wt(u instanceof Error?u.message:r("shell.navigationLoadFailed")),D.current({title:u instanceof Error?u.message:r("shell.navigationLoadFailed"),tone:"error"})}finally{gt("workbench.refresh_navigation.end",{requestId:a,success:a===w.current}),a===w.current&&Wt(!1)}},[]),ot=l.useCallback(a=>{Pe(u=>{const b=pf(u,a,$.current);return ut.current=b,b})},[]),Ve=l.useCallback(()=>{var a;(a=x.current)==null||a.requestRefresh()},[]),Tt=l.useCallback((a,u)=>{s($t(a,u))},[s]),Dt=l.useCallback((a,u,b)=>{var T;Y.current={workspaceId:a,paths:u,knownRevisionByPath:b==null?void 0:b.knownRevisionByPath},(T=x.current)==null||T.subscribeFileTree(a,u,b)},[]),ss=l.useCallback((a,u,b)=>{var T;z.current={workspaceId:a,paths:u,knownRevisionByPath:b==null?void 0:b.knownRevisionByPath},(T=x.current)==null||T.requestFileTreeRefresh(a,u,b)},[]),hn=l.useCallback(a=>(A.current.add(a),()=>{A.current.delete(a)}),[]),fn=l.useCallback((a,u)=>{var b;q.current={workspaceId:a,knownRevision:u==null?void 0:u.knownRevision},(b=x.current)==null||b.subscribeGit(a,u)},[]),ht=l.useCallback((a,u)=>{var b;j.current={workspaceId:a,knownRevision:u==null?void 0:u.knownRevision},(b=x.current)==null||b.requestGitRefresh(a,u)},[]),dr=l.useCallback(a=>(I.current.add(a),()=>{I.current.delete(a)}),[]),rs=l.useCallback((a,u)=>{var b;J.current={workspaceId:a,knownRevision:u==null?void 0:u.knownRevision},(b=x.current)==null||b.subscribeWorkspaceManagement(a,u)},[]),_n=l.useCallback((a,u)=>{var b;Q.current={workspaceId:a,knownRevision:u==null?void 0:u.knownRevision},an(T=>{var B;return{...T,[a]:{detail:((B=T[a])==null?void 0:B.detail)??null,loading:!0,error:null}}}),(b=x.current)==null||b.requestWorkspaceManagementRefresh(a,u)},[]),It=l.useCallback(a=>(G.current.add(a),()=>{G.current.delete(a)}),[]),Xe=l.useCallback(async(a,u=!1)=>{const b=a.trim();if(!b)return;let T=!0;if(St(B=>{const L=B[b];return!u&&(L!=null&&L.loading)?(T=!1,B):{...B,[b]:{preview:(L==null?void 0:L.preview)??null,loading:!0,applying:(L==null?void 0:L.applying)??!1,cleaning:(L==null?void 0:L.cleaning)??!1,error:null}}}),!!T)try{const B=await xc(b);St(L=>{var ee,fe;return{...L,[b]:{preview:B,loading:!1,applying:((ee=L[b])==null?void 0:ee.applying)??!1,cleaning:((fe=L[b])==null?void 0:fe.cleaning)??!1,error:null}}})}catch(B){St(L=>{var ee,fe,de;return{...L,[b]:{preview:((ee=L[b])==null?void 0:ee.preview)??null,loading:!1,applying:((fe=L[b])==null?void 0:fe.applying)??!1,cleaning:((de=L[b])==null?void 0:de.cleaning)??!1,error:B instanceof Error?B.message:r("shell.worktreeMergePreviewFailed")}}})}},[]),ur=l.useCallback(async a=>{const u=a.trim();if(u){St(b=>{var T,B;return{...b,[u]:{preview:((T=b[u])==null?void 0:T.preview)??null,loading:!1,applying:!0,cleaning:((B=b[u])==null?void 0:B.cleaning)??!1,error:null}}});try{const b=await vc(u);St(T=>{var B;return{...T,[u]:{preview:b.preview,loading:!1,applying:!1,cleaning:((B=T[u])==null?void 0:B.cleaning)??!1,error:null}}}),Ve(),Ke(),Xe(u,!0),ht(b.preview.targetWorkspace.id),D.current({title:b.applied?r("shell.worktreeMergeApplySuccess"):r("shell.worktreeMergeAlreadyMerged"),tone:"success"})}catch(b){St(T=>{var B,L;return{...T,[u]:{preview:((B=T[u])==null?void 0:B.preview)??null,loading:!1,applying:!1,cleaning:((L=T[u])==null?void 0:L.cleaning)??!1,error:b instanceof Error?b.message:r("shell.worktreeMergeApplyFailed")}}}),D.current({title:b instanceof Error?b.message:r("shell.worktreeMergeApplyFailed"),tone:"error"})}}},[Xe,Ke,ht,Ve]),Ie=l.useCallback(async a=>{var T,B;const u=a.workspaceId,b=ln&&((B=(T=tt[u])==null?void 0:T.preview)==null?void 0:B.alreadyMerged)===!0;St(L=>{var ee;return{...L,[u]:{preview:((ee=L[u])==null?void 0:ee.preview)??null,loading:!1,applying:!1,cleaning:!0,error:null}}});try{const L=await yc(u,{deleteBranch:b});if(St(ee=>{var fe;return{...ee,[u]:{preview:((fe=ee[u])==null?void 0:fe.preview)??null,loading:!1,applying:!1,cleaning:!1,error:null}}}),Ln(!1),es(ee=>(ee==null?void 0:ee.workspaceId)===u?null:ee),Ve(),await Ke(),s(Gt(a.parentWorkspaceId),{replace:!0}),L.branchDeleted){D.current({title:r("shell.worktreeCleanupDeleteBranchSuccess",{branch:L.deletedBranchName||a.branchName}),tone:"success"});return}if(L.branchDeleteRequested){D.current({title:r("shell.worktreeCleanupDeleteBranchPartialFailed",{branch:a.branchName}),description:L.branchDeleteError||void 0,tone:"warning"});return}D.current({title:r("shell.worktreeCleanupSuccess"),tone:"success"})}catch(L){St(ee=>{var fe;return{...ee,[u]:{preview:((fe=ee[u])==null?void 0:fe.preview)??null,loading:!1,applying:!1,cleaning:!1,error:L instanceof Error?L.message:r("shell.worktreeCleanupFailed")}}}),D.current({title:L instanceof Error?L.message:r("shell.worktreeCleanupFailed"),tone:"error"})}},[ln,s,Ke,Ve,tt]),Ms=l.useCallback(a=>{Ln(!1),es(a)},[]),mn=l.useCallback((a,u)=>{var b;E.current={workspaceId:a,knownRevision:u==null?void 0:u.knownRevision},(b=x.current)==null||b.subscribeTerminalManager(a,u)},[]),dt=l.useCallback((a,u)=>{var b;ue.current={workspaceId:a,knownRevision:u==null?void 0:u.knownRevision},(b=x.current)==null||b.requestTerminalManagerRefresh(a,u)},[]),Es=l.useCallback(a=>(K.current.add(a),()=>{K.current.delete(a)}),[]),ft=l.useCallback((a,u)=>{Pe(b=>bf(b,a,u??new Date().toISOString()))},[]),Ye=l.useCallback(async(a,u)=>{C.current.set(a,u),Pe(b=>Na(b,a,u));try{const b=await Oa(a,u),T=qt(b);T===u?C.current.set(a,T):C.current.delete(a),ot(b),Ve(),Ke()}catch(b){throw C.current.delete(a),Pe(T=>Na(T,a,!u)),b}},[Ke,Ve,ot]),pn=l.useCallback((a,u)=>{gt("workbench.set_session_workspace",{sessionId:a,workspaceId:u}),et(b=>{if(!u){if(!(a in b))return b;const T={...b};return delete T[a],T}return b[a]===u?b:{...b,[a]:u}})},[]);l.useEffect(()=>{N.current=F.length>0},[F]),l.useEffect(()=>{gt("workbench.navigation_state",{navigationLoading:_e,workspaceCount:F.length,sessionCount:F.reduce((a,u)=>a+u.sessions.length,0)})},[F,_e]),l.useEffect(()=>{var ge;W.current!==null&&window.clearTimeout(W.current),W.current=window.setTimeout(()=>{var re;W.current=null,!(R.current||N.current)&&(gt("workbench.refresh_navigation.ws_fallback_triggered"),(re=x.current)==null||re.requestRefresh())},1200);const a=new jd({onConnectionChange:re=>{re==="connected"&&Sc(),re==="reconnect_failed"&&!N.current&&(wt(r("shell.navigationLoadFailed")),D.current({id:"workbench-navigation-connection",title:r("shell.navigationLoadFailed"),tone:"warning",durationMs:3600}))},onSnapshot:re=>{R.current=!0,gt("workbench.ws_snapshot_received",{workspaceCount:re.items.length,sessionCount:re.items.reduce((De,kt)=>De+kt.sessions.length,0)}),W.current!==null&&(window.clearTimeout(W.current),W.current=null),ns(re),Wt(!1)},onFileTreeSnapshot:re=>{A.current.forEach(De=>De(re))},onGitSnapshot:re=>{Ys(Ul(re.workspaceId),{revision:re.revision??null,status:re.status,history:re.history,historyTotalCount:re.historyTotalCount,historyNextCursor:re.historyNextCursor,branches:re.branches}),an(De=>{var fo;const kt=((fo=F.find(Jl=>Jl.workspace.id===re.workspaceId))==null?void 0:fo.workspace)??null;if(!kt)return De;const Oe=De[re.workspaceId],en=Gl(ql((Oe==null?void 0:Oe.detail)??$l(kt),kt),re);return Ys(Fi(re.workspaceId),en),{...De,[re.workspaceId]:{detail:en,loading:!1,error:null}}}),I.current.forEach(De=>De(re))},onWorkspaceManagementSnapshot:re=>{Ys(Fi(re.workspaceId),re),an(De=>({...De,[re.workspaceId]:{detail:re,loading:!1,error:null}})),G.current.forEach(De=>De(re))},onTerminalManagerSnapshot:re=>{K.current.forEach(De=>De(re))},onUnauthorized:()=>{Zs.clear(),s("/login",{replace:!0})}});a.setWorkbenchKnownRevision(((ge=p.current)==null?void 0:ge.revision)??null),x.current=a;const u=Y.current,b=z.current,T=q.current,B=j.current,L=J.current,ee=Q.current,fe=E.current,de=ue.current;return u&&a.subscribeFileTree(u.workspaceId,u.paths,{knownRevisionByPath:u.knownRevisionByPath}),T&&a.subscribeGit(T.workspaceId,{knownRevision:T.knownRevision}),L&&a.subscribeWorkspaceManagement(L.workspaceId,{knownRevision:L.knownRevision}),fe&&a.subscribeTerminalManager(fe.workspaceId,{knownRevision:fe.knownRevision}),b&&a.requestFileTreeRefresh(b.workspaceId,b.paths,{knownRevisionByPath:b.knownRevisionByPath}),B&&a.requestGitRefresh(B.workspaceId,{knownRevision:B.knownRevision}),ee&&a.requestWorkspaceManagementRefresh(ee.workspaceId,{knownRevision:ee.knownRevision}),de&&a.requestTerminalManagerRefresh(de.workspaceId,{knownRevision:de.knownRevision}),a.start(),()=>{W.current!==null&&(window.clearTimeout(W.current),W.current=null),x.current===a&&(x.current=null),a.close()}},[s]),l.useEffect(()=>{Kn(ea,String(Fe))},[Fe]),l.useEffect(()=>{Kn(ta,String(lt))},[lt]),l.useEffect(()=>{Kn(na,String(He))},[He]),l.useEffect(()=>{Kn(sa,String(Te))},[Te]),l.useEffect(()=>{if(!Ze){sf(Ni);return}Kn(Ni,Ze)},[Ze]),l.useEffect(()=>{if(xt||Te)return;const a=window.setTimeout(()=>{Rn(!0)},ph);return()=>{window.clearTimeout(a)}},[xt,Te]);const is=Js(n.pathname),pe=(is==null?void 0:is.sessionId)??null,rt=pe?Yl(pe):!1,Re=l.useMemo(()=>Hc(F),[F]),hr=l.useMemo(()=>new Set(F.map(a=>a.workspace.id)),[F]),os=l.useMemo(()=>new Set(At),[At]),as=l.useMemo(()=>Re.filter(a=>a.session.isFavorite===!0).map(a=>a.session.sessionId),[Re]),_t=l.useMemo(()=>new Set(as),[as]),Fn=l.useCallback(a=>{const u=Ii(a,At);p.current=u,Dr(u),ut.current=a,Pe(a)},[At]),fr=l.useCallback(a=>{const u=!os.has(a),b=Ta(At,a,u),T=Ii(F,b);p.current=T,Dr(T),Kt(b),Ha(a,{collapsed:u}).catch(B=>{const L=Ta(b,a,!u),ee=Ii(F,L);p.current=ee,Dr(ee),Kt(L),D.current({title:B instanceof Error?B.message:r("shell.workspaceCollapseStateSaveFailed"),tone:"error"})})},[os,At,F]),Ps=l.useCallback(()=>{le.current={originalGroups:ut.current}},[]),Ws=l.useCallback((a,u,b)=>{const T=ut.current,B=hf(T,a,u,b);B!==T&&Fn(B)},[Fn]),ls=l.useCallback(()=>{const a=le.current;le.current=null;const u=ut.current;a&&(a.originalGroups.length===u.length&&a.originalGroups.every((b,T)=>{var B;return b.workspace.id===((B=u[T])==null?void 0:B.workspace.id)})||jc({workspaceIds:u.map(b=>b.workspace.id)}).catch(b=>{Fn(a.originalGroups),D.current({title:b instanceof Error?b.message:r("shell.workspaceReorderFailed"),tone:"error"})}))},[Fn]);l.useEffect(()=>{const a=new Map;if(Re.forEach(({session:u})=>{a.set(u.sessionId,{activityState:u.activityState,completedAt:u.completedAt??null,runningState:u.runningState??null})}),!be.current){be.current=!0,me.current=a;return}Re.forEach(({session:u})=>{var ee;if(u.sessionId===pe)return;const b=me.current.get(u.sessionId);if(!b)return;const T=b.activityState!=="completed_unread"&&u.activityState==="completed_unread",B=((ee=u.title)==null?void 0:ee.trim())||r("common.unknown");if(f&&T){const fe=r("conversation.backgroundCompletionToastDescription",{title:B});D.current({id:`workbench-session-completed-${u.sessionId}-${u.completedAt??"unknown"}`,title:r("conversation.backgroundCompletionToastTitle"),description:fe,tone:"success",durationMs:8e3,action:{label:r("shell.contextOpenSession"),onClick:()=>Tt(u.workspaceId,u.sessionId)}}),v.current.showNotification(r("conversation.backgroundCompletionToastTitle"),fe)}const L=b.runningState!=="failed"&&(u.runningState??null)==="failed";if(k&&L){const fe=Rh(u)??r("conversation.runtimeFailed"),de=r("conversation.backgroundFailureToastDescription",{title:B,detail:fe});D.current({id:`workbench-session-failed-${u.sessionId}-${u.updatedAt}`,title:r("conversation.backgroundFailureToastTitle"),description:de,tone:"error",durationMs:8e3,action:{label:r("shell.contextOpenSession"),onClick:()=>Tt(u.workspaceId,u.sessionId)}}),v.current.showNotification(r("conversation.backgroundFailureToastTitle"),de)}}),me.current=a},[pe,Re,f,k,Tt]),l.useEffect(()=>{y.current=Re.map(a=>a.session).filter(a=>a.sessionId!==pe&&Th(a)).map(a=>{var u;return{sessionId:a.sessionId,workspaceId:a.workspaceId,title:((u=a.title)==null?void 0:u.trim())||r("common.unknown")}})},[pe,Re]),l.useEffect(()=>{let a=!1,u=null;const b=()=>{u=window.setTimeout(()=>{T().finally(()=>{a||b()})},gh)},T=async()=>{var de;const B=y.current;if(B.length===0){Ge.current||(Ge.current=!0),_.current="";return}const L=new Set(B.map(ge=>ge.sessionId)),ee=await Promise.all(B.map(async ge=>{try{const re=await Cc(ge.sessionId);return{session:ge,items:re.items}}catch{return{session:ge,items:null}}}));if(a)return;for(const ge of ee){if(!ge.items)continue;const re=ge.items.filter(Oe=>Oe.status==="pending"),De=new Set(re.map(Oe=>Oe.id)),kt=Ee.current.get(ge.session.sessionId)??new Set;Ge.current&&re.forEach(Oe=>{if(kt.has(Oe.id)||!h)return;const en=r("conversation.backgroundPermissionToastDescription",{title:ge.session.title,requestTitle:Oe.title});D.current({id:`workbench-permission-request-${Oe.id}`,title:r("conversation.permissionRequestToastTitle"),description:en,tone:"warning",durationMs:8e3,action:{label:r("shell.contextOpenSession"),onClick:()=>Tt(ge.session.workspaceId,ge.session.sessionId)}}),v.current.showNotification(r("conversation.permissionRequestToastTitle"),en)}),Ee.current.set(ge.session.sessionId,De)}for(const[ge,re]of Ee.current.entries())!L.has(ge)&&re.size===0&&Ee.current.delete(ge);const fe=Ih(Ee.current,L);Ge.current&&fe!==_.current&&((de=x.current)==null||de.requestRefresh()),_.current=fe,Ge.current=!0};return T().finally(()=>{a||b()}),()=>{a=!0,u!==null&&window.clearTimeout(u)}},[h,Tt]),l.useEffect(()=>{if(_e&&F.length===0)return;const a=new Set(F.map(u=>u.workspace.id));Kt(u=>_l(u,a)),In(u=>u&&a.has(u)?u:null)},[F,_e]);const bn=Re.find(a=>a.session.sessionId===pe)??null,Le=(bn==null?void 0:bn.workspace.id)??(pe?Ts[pe]??null:null),mt=ma(n.pathname,n.search),cs=mt&&hr.has(mt)?mt:null,As=Ze&&hr.has(Ze)?Ze:null,Bs=Le??cs??As??null,se=Bs??((Ot=F[0])==null?void 0:Ot.workspace.id)??null,Ls=l.useCallback(a=>{if(a){const u=Re.find(b=>b.workspace.id===a)??null;if(u)return u}return Re[0]??null},[Re]),kn=l.useCallback(a=>{const u=typeof window>"u"?null:window.localStorage.getItem(Fr);if(!u)return null;const b=u.split("?")[0]??u,T=Js(b);if(!T)return window.localStorage.removeItem(Fr),null;const B=T.sessionId,L=Re.find(fe=>fe.session.sessionId===B)??null,ee=T.workspaceId??(L==null?void 0:L.workspace.id)??null;return L&&(!a||ee===a)?$t(L.workspace.id,L.session.sessionId):(window.localStorage.removeItem(Fr),null)},[Re]),ds=l.useMemo(()=>cn.filter(a=>!Jt.has(a.id)),[Jt,cn]),On=l.useMemo(()=>ds.filter(a=>Lh(a,Lt)).length,[ds,Lt]);l.useEffect(()=>{jt&&Rs(ds)},[ds,Rs,jt]);const li=l.useCallback(a=>{Nt(!1),a.routePath&&s(a.routePath)},[s]),Hn=l.useCallback(async(a,u)=>{const b=ce.current+1;ce.current=b;try{const T=await $u(a,u);if(b!==ce.current)return;nt(B=>{const L=new Set(B);return T.item?L.add(T.item.notificationId):L.delete(a),L})}catch(T){if(b!==ce.current)return;D.current({title:r("shell.globalNotificationsArchiveFailed"),description:T instanceof Error?T.message:void 0,tone:"error"})}},[]);l.useEffect(()=>{Le&&In(a=>a===Le?a:Le)},[Le]),l.useEffect(()=>{var L;if(_e)return;const a=((L=F[0])==null?void 0:L.workspace.id)??null,u=cs??a??As,b=pe&&!rt?Ls(u):null,T=pe&&!rt?kn(u):null,B=b?$t(b.workspace.id,b.session.sessionId):null;if(mt&&!cs){s(T??B??(a?Hh(n.pathname,a):Ti(e)),{replace:!0});return}if(pe&&!rt&&!Le){s(T??B??(a?Qs(a):Ti(e)),{replace:!0});return}},[pe,Ls,rt,n.pathname,s,F,_e,kn,mt,Le,e,As,cs]),l.useEffect(()=>{gt("workbench.current_workspace_resolved",{currentSessionId:pe,sessionWorkspaceId:Le,routeWorkspaceId:mt,currentWorkspaceId:se,source:Le?bn?"navigation":"sessionWorkspaceMap":mt?"route":Ze?"workspaceSelection":"navigationFallback"})},[bn,pe,se,mt,Ze,Le]),l.useEffect(()=>{gt("workbench.info_panel_state",{infoPanelReady:xt,rightCollapsed:Te,currentWorkspaceId:se,sessionWorkspaceId:Le,currentSessionId:pe})},[pe,se,xt,Te,Le]);const pt=Li(n.pathname)?"terminals":Vr(n.pathname)?"butler":"conversation",Be=e==="mobile",Un=Ti(e),mr=l.useMemo(()=>F.map(a=>{const u=Tl(a.sessions);return{workspace:a.workspace,visibleSessions:u,archivedSessions:a.sessions.filter(b=>qt(b)&&!ni(b)),visibleSessionTree:lo(u,c).filter(b=>!_t.has(b.item.sessionId)&&!Vi(Pt(b),T=>_t.has(T.sessionId))),childWorktrees:El(a.childWorktrees,_t,c),isCollapsed:os.has(a.workspace.id)}}),[os,_t,F,c]),Ds=l.useMemo(()=>Eu(F),[F]),bt=l.useMemo(()=>lf(F,se),[se,F]),pr=l.useMemo(()=>se?(bt==null?void 0:bt.workspace)??F.map(a=>a.workspace).find(a=>a.id===se)??null:null,[se,bt,F]),$n=(bt==null?void 0:bt.meta)??null,Rt=(se?Ds[se]??null:null)??(pr?ao(pr):null),br=$n?tt[$n.workspaceId]??null:null,qn=l.useMemo(()=>Re.filter(a=>_t.has(a.session.sessionId)&&!qt(a.session)&&!Di(a.session)),[_t,Re]),_s=n.pathname.startsWith("/settings")?"settings":Vr(n.pathname)?"terminals":Li(n.pathname)?"butler":Oh(n.pathname)?n.pathname.endsWith("/tools/processes")||n.pathname==="/tools/processes"?"butler":"sessions":Fh(n.pathname)||pa(n.pathname)?"sessions":"workspaces",ci=Be&&(_s==="sessions"&&pa(n.pathname)||Vr(n.pathname)),kr=ei({isNativeMobile:i.isNativeMobile,viewportClass:i.viewportClass}),Fs=nr({viewportClass:i.viewportClass,activeEntry:_s,hasNavigationPanel:Be,hasAuxiliaryPanel:Be,preferCompactLayout:kr}),gr=Be&&al(Fs),wr=Be&&ll(Fs),us=l.useMemo(()=>F.map(a=>a.workspace),[F]),di=l.useMemo(()=>{const a=Bt.trim().toLowerCase();return a?Re.filter(u=>{const b=(u.session.title||"").toLowerCase(),T=u.workspace.name.toLowerCase(),B=si(u.session.provider,"full").toLowerCase();return b.includes(a)||T.includes(a)||B.includes(a)}):[]},[Re,Bt]);l.useEffect(()=>{var u;const a=se??((u=F[0])==null?void 0:u.workspace.id)??"";a&&Is(b=>b&&F.some(B=>B.workspace.id===b)?b:a)},[se,F]),l.useEffect(()=>{pe&&!rt&&Le&&Kn(Fr,`${n.pathname}${n.search}`)},[pe,rt,n.pathname,n.search,Le]),l.useEffect(()=>{if(pe&&rt){O.current=`${n.pathname}${n.search}`;return}pe&&!rt&&(O.current=null)},[pe,rt,n.pathname,n.search]),l.useEffect(()=>{Be||(xe(!1),Ae(!1))},[Be]),l.useEffect(()=>{!Be||_e||!_h(n.pathname)||Bs||(xe(!1),Ae(!1),s(Un,{replace:!0}))},[Bs,Be,n.pathname,s,_e,Un]);function ui(){if(Be){xe(!0);return}Yn(!1)}function hi(){if(Qt(),Be){Ae(!0);return}zt(!1)}function fi(){if(Be){xe(a=>!a);return}Yn(a=>!a)}function mi(){if(Qt(),Be){Ae(a=>!a);return}zt(a=>!a)}function Qt(){Rn(!0)}function hs(a){In(a),Qt(),pe&&Le!==a&&s(Un)}const fs=l.useCallback(async a=>{var T;const u=((T=Re.find(B=>B.session.sessionId===a))==null?void 0:T.session)??null,b=(u==null?void 0:u.isFavorite)!==!0;Pe(B=>Ca(B,a,b));try{const B=await Nc(a,b);ot(B),Ve()}catch(B){throw Pe(L=>Ca(L,a,!b)),B}},[Re,Ve,ot]),xr=l.useCallback((a,u)=>{Nl(a,u).then(()=>{s(sl(a,u))}).catch(b=>{o({title:b instanceof Error?b.message:r("shell.startSessionFailed"),tone:"error"})})},[s,o]),vr=l.useCallback(a=>{var T;const u=((T=a.workspaceId)==null?void 0:T.trim())||se,b=Uh(a.filePath);return!u||!b?!1:(Qt(),rn("files"),Be?(xe(!1),Ae(!0)):zt(!1),ar({requestId:H.current+1,workspaceId:u,filePath:b,openViewer:a.openViewer===!0}),H.current+=1,!0)},[se,Be]),yr=l.useCallback(async(a,u)=>{const b=await Ua(a,u.trim());return ot(b),b},[ot]);function Os(a){En(!0)}function Sr(){En(!1),Pn("sessions"),Wn(""),Xt(null),yt([]),An(!1)}async function jr(){const a=Bt.trim();if(!a||!vt.trim()){yt([]),Xt(null);return}An(!0),Xt(null);try{const u=await Lc(vt,a);yt(u.items)}catch(u){yt([]),Xt(u instanceof Error?u.message:r("shell.searchCodeFailed"))}finally{An(!1)}}function Nr(a,u){const b=S.current;b&&(b.style.setProperty("--workbench-left-width",`${a}px`),b.style.setProperty("--workbench-left-current-width",He?"0px":`${a}px`),b.style.setProperty("--workbench-right-width",`${u}px`),b.style.setProperty("--workbench-right-current-width",Te?"0px":`${u}px`))}function gn(a={}){return{leftWidth:a.leftWidth??(He?0:X.current),rightWidth:a.rightWidth??(te&&!Te?ke.current:0),leftCollapsed:a.leftCollapsed??He,rightCollapsed:a.rightCollapsed??(!te||Te),prefersDarkAppearance:a.prefersDarkAppearance??Dn!=="light",isResizing:a.isResizing??ct!==null}}function Hs(a,u){var fe;u.preventDefault(),u.stopPropagation(),(fe=window.getSelection())==null||fe.removeAllRanges();const b=u.clientX,T=a==="left"?Fe:lt;Ns(a);const B=()=>{const de=ne.current;if(ne.current=null,de!==null){if(a==="left"){X.current=de,ir(ge=>ge===de?ge:de),Nr(de,ke.current);return}ke.current=de,or(ge=>ge===de?ge:de),Nr(X.current,de)}};function L(de){var kt;de.preventDefault(),(kt=window.getSelection())==null||kt.removeAllRanges();const ge=de.clientX-b,re=a==="left"?$r(T+ge,ia,aa):$r(T-ge,oa,la),De=a==="left"?X.current:ke.current;re===De&&ne.current===null||(ne.current=re,we.current===null&&(we.current=window.requestAnimationFrame(()=>{we.current=null,B()})))}function ee(){document.removeEventListener("mousemove",L),document.removeEventListener("mouseup",ee),we.current!==null&&(window.cancelAnimationFrame(we.current),we.current=null),B(),Ns(ge=>ge===a?null:ge);const de=gn({isResizing:!1});qe.current=de,i.bridge.syncNativeSidebarLayout(de)}document.addEventListener("mousemove",L,{passive:!1}),document.addEventListener("mouseup",ee)}function Gn(){if(m())return;if(Re.length===0){s(Un);return}const a=$t(Re[0].workspace.id,Re[0].session.sessionId);s(a)}function d(){if(!m(se)){if(se){s(Qs(se));return}s(Un)}}function m(a){if(pe&&Le)return a&&Le&&Le!==a?!1:(s(`${n.pathname}${n.search}`),!0);if(O.current){if(a){const[b,T=""]=O.current.split("?"),B=ma(b??O.current,T?`?${T}`:"");if(B&&B!==a)return!1}return s(O.current),!0}const u=kn(a);return u?(s(u),!0):!1}l.useEffect(()=>{if(typeof window>"u")return;function a(u){if(!(u.metaKey||u.ctrlKey)){u.key==="Escape"&&(xe(!1),Ae(!1));return}if(of(u.target))return;const T=u.key.toLowerCase();if(!u.shiftKey&&T==="b"){u.preventDefault(),fi();return}if(u.shiftKey&&T==="i"){u.preventDefault(),mi();return}if(!u.shiftKey&&T===","){u.preventDefault(),s("/settings");return}if(!u.shiftKey&&T==="1"){u.preventDefault(),Gn();return}if(!u.shiftKey&&T==="2"){u.preventDefault(),s(se?xs(se):at());return}if(!u.shiftKey&&T==="k"){u.preventDefault(),af();return}u.shiftKey&&T==="r"&&(u.preventDefault(),Ke())}return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[s,Ke,Be,Gn]);const g=l.useMemo(()=>({shellMode:e,navigationGroups:F,navigationLoading:_e,navigationError:Je,currentWorkspaceId:se,currentSessionId:pe,favoriteSessionIds:as,favoriteSessions:qn,globalNotifications:cn,archivedNotificationIds:Array.from(Jt),showArchivedNotifications:Zt,unreadNotificationCount:On,refreshNavigation:Ke,requestNavigationRefresh:Ve,openNotificationPanel:()=>{Nt(!0)},closeNotificationPanel:()=>{Nt(!1)},setShowArchivedNotifications:un,archiveNotification:a=>{Hn(a,!0)},unarchiveNotification:a=>{Hn(a,!1)},setAuxiliaryPanel:ze,subscribeFileTree:Dt,requestFileTreeRefresh:ss,addFileTreeSnapshotListener:hn,subscribeGitSnapshot:fn,requestGitRefresh:ht,addGitSnapshotListener:dr,subscribeWorkspaceManagementSnapshot:rs,requestWorkspaceManagementRefresh:_n,addWorkspaceManagementSnapshotListener:It,workspaceManagementStateById:Yt,subscribeTerminalManagerSnapshot:mn,requestTerminalManagerRefresh:dt,addTerminalManagerSnapshotListener:Es,selectWorkspace:hs,toggleFavoriteSession:fs,archiveSession:a=>Ye(a,!0),unarchiveSession:a=>Ye(a,!1),renameSession:yr,startDraftSession:xr,markNavigationSessionSeen:ft,upsertNavigationSession:ot,setSessionWorkspace:pn,revealWorkspaceFile:vr}),[hn,dr,It,Es,Ye,pe,se,cn,as,qn,hs,Jt,ft,Je,F,_e,On,ss,ht,_n,Ke,Ve,un,ze,dt,yr,Zt,Yt,e,xr,pn,Dt,fn,rs,mn,Hn,fs,ot,vr]),M={"--workbench-left-width":`${Fe}px`,"--workbench-left-current-width":He?"0px":`${Fe}px`,"--workbench-right-width":`${lt}px`,"--workbench-right-current-width":Te?"0px":`${lt}px`},P=pt==="butler"?Qe:t.jsx(Ma,{panelReady:xt,activeTab:Cs,fileRevealRequest:on,onTabChange:a=>{Qt(),rn(a)},currentSessionId:rt?null:pe,activeWorkspaceId:se,navigationGroups:F,workspaceContext:Rt,worktreeMeta:$n,worktreeMergeState:br,onRefreshWorktreeMergePreview:Xe,onApplyWorktreeMerge:ur,onCleanupWorktree:Ie}),te=P!==null,V=i.isDesktop&&i.ui.osFamily==="macos"&&i.ui.prefersOverlayTitlebar;l.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const{documentElement:a,body:u}=document,b=()=>{oe.current!==null&&(window.clearTimeout(oe.current),oe.current=null);const B=ae.current;ae.current=!1,a.removeAttribute(Hr),u==null||u.removeAttribute(Hr),B&&he.current&&(he.current=!1,it(L=>L+1))};if(!V){b();return}const T=()=>{ae.current=!0,a.setAttribute(Hr,"true"),u==null||u.setAttribute(Hr,"true"),oe.current!==null&&window.clearTimeout(oe.current),oe.current=window.setTimeout(()=>{b()},xh)};return window.addEventListener("resize",T),()=>{window.removeEventListener("resize",T),b()}},[V]);const ve=l.useMemo(()=>({leftWidth:He?0:Fe,rightWidth:te&&!Te?lt:0,leftCollapsed:He,rightCollapsed:!te||Te,prefersDarkAppearance:Dn!=="light",isResizing:ct!==null}),[ct,He,Fe,Te,lt,te,Dn]),Ue=l.useDeferredValue(ve),We=ct===null?Ue:ve,qe=l.useRef(ve);l.useEffect(()=>{qe.current=ve},[ve]),l.useEffect(()=>{if(typeof window>"u")return;let a=null;const u=()=>{a=null,i.bridge.syncNativeSidebarLayout(We)},b=()=>{a!==null&&window.cancelAnimationFrame(a),a=window.requestAnimationFrame(u)};return st?(b(),()=>{a!==null&&window.cancelAnimationFrame(a)}):(i.bridge.syncNativeSidebarLayout({leftWidth:0,rightWidth:0,leftCollapsed:!0,rightCollapsed:!0,prefersDarkAppearance:!1,isResizing:!1}),()=>{a!==null&&window.cancelAnimationFrame(a)})},[We,i.bridge,st]),l.useLayoutEffect(()=>{const a=S.current;if(!a||!V||typeof window>"u"){ha(a);return}let u=null,b=null;const T=new Set([a]),B=()=>{he.current=!1;const ee=window.getComputedStyle(a),fe=jl(ee,"--desktop-macos-traffic-light-center-y");if(fe===null){ha(a);return}const de={navToolbar:yn(a,Me.navToolbar.selector),infoTabs:yn(a,Me.infoTabs.selector),auxiliaryToolbarButton:yn(a,Me.auxiliaryToolbarButton.selector),conversationHeaderMain:yn(a,Me.conversationHeaderMain.selector),conversationHeaderActions:yn(a,Me.conversationHeaderActions.selector),terminalTabbarMain:yn(a,Me.terminalTabbarMain.selector),collapsedLeftControls:yn(a,Me.collapsedLeftControls.selector),collapsedRightControls:yn(a,Me.collapsedRightControls.selector)},ge=[de.infoTabs,de.conversationHeaderMain,de.conversationHeaderActions,de.terminalTabbarMain].filter(Oe=>Oe!==null),re=[de.collapsedLeftControls,de.collapsedRightControls].filter(Oe=>Oe!==null),De=re.length>0?Ut(ee,"--workbench-collapsed-controls-live-shift-y",fe,re.reduce((Oe,en)=>Oe+en,0)/re.length):null,kt=ge.length>0?Ut(ee,"--workbench-titlebar-live-content-shift-y",fe,ge.reduce((Oe,en)=>Oe+en,0)/ge.length):null;Ht(a,"--workbench-titlebar-live-content-shift-y",kt),Ht(a,"--workbench-collapsed-controls-live-shift-y",De),Ht(a,Me.navToolbar.variableName,Ut(ee,Me.navToolbar.variableName,fe,de.navToolbar)),Ht(a,Me.infoTabs.variableName,Ut(ee,Me.infoTabs.variableName,fe,de.infoTabs)),Ht(a,Me.auxiliaryToolbarButton.variableName,Ut(ee,Me.auxiliaryToolbarButton.variableName,fe,de.auxiliaryToolbarButton)),Ht(a,Me.conversationHeaderMain.variableName,Ut(ee,Me.conversationHeaderMain.variableName,fe,de.conversationHeaderMain)),Ht(a,Me.conversationHeaderActions.variableName,Ut(ee,Me.conversationHeaderActions.variableName,fe,de.conversationHeaderActions)),Ht(a,Me.terminalTabbarMain.variableName,Ut(ee,Me.terminalTabbarMain.variableName,fe,de.terminalTabbarMain)),Ht(a,Me.collapsedLeftControls.variableName,Ut(ee,Me.collapsedLeftControls.variableName,fe,de.collapsedLeftControls)),Ht(a,Me.collapsedRightControls.variableName,Ut(ee,Me.collapsedRightControls.variableName,fe,de.collapsedRightControls))},L=()=>{if(ae.current){he.current=!0;return}u!==null&&window.cancelAnimationFrame(u),u=window.requestAnimationFrame(()=>{u=null,B()})};if(L(),typeof ResizeObserver<"u"){b=new ResizeObserver(()=>{L()});for(const ee of Object.values(Me))for(const fe of a.querySelectorAll(ee.selector))T.add(fe);for(const ee of T)b.observe(ee)}return window.addEventListener("resize",L),()=>{u!==null&&window.cancelAnimationFrame(u),window.removeEventListener("resize",L),b==null||b.disconnect()}},[pt,xt,He,n.pathname,n.search,Te,te,V,cr]);const Mt=Be?t.jsx(Ra,{workspaceGroups:mr,workspaceVisualContextMap:Ds,sessionDisplaySortMode:c,favoriteSessions:qn,favoriteSessionIds:_t,activeWorkspaceId:se,isConversationActive:pt==="conversation",isTerminalActive:pt==="terminals",isButlerActive:pt==="butler",isSearchOpen:Mn,navigationLoading:_e,navigationError:Je,activeSessionId:pe,onRefreshNavigation:Ke,onSessionUpdated:ot,onNavigateConversation:Gn,onNavigateTerminals:()=>{xe(!1),s(se?xs(se):at())},onNavigateButler:()=>{xe(!1),s(se?Vn(se):at())},onOpenSearch:()=>{xe(!1),Os()},onOpenSettings:()=>{xe(!1),s("/settings")},onSelectWorkspace:hs,onToggleWorkspaceCollapse:fr,onStartWorkspaceReorder:Ps,onPreviewWorkspaceReorder:Ws,onCommitWorkspaceReorder:ls,allowWorkspaceReorder:!1,subscribeGitSnapshot:fn,requestGitRefresh:ht,subscribeWorkspaceManagementSnapshot:rs,requestWorkspaceManagementRefresh:_n,onToggleFavoriteSession:fs,onArchiveSession:a=>Ye(a,!0),onUnarchiveSession:a=>Ye(a,!1),workspaceManagementStateById:Yt,setWorkspaceManagementStateById:an,unreadNotificationCount:On,notificationPanelOpen:jt,onToggleNotificationPanel:()=>{Nt(a=>!a)},onClose:()=>xe(!1)}):null,Ft=Be&&te?P:null;return t.jsxs(Cl.Provider,{value:g,children:[Be?t.jsx(t.Fragment,{children:t.jsx(md,{activeEntry:_s,presentation:ci?"conversation-focus":"default",navigationPanel:Mt,auxiliaryPanel:Ft,onOpenNavigation:()=>{Ae(!1),xe(!0)},onOpenSearch:()=>{xe(!1),Ae(!1),Os()},onOpenAuxiliary:()=>{te&&(Qt(),xe(!1),Ae(!0))},onNavigateWorkspaces:()=>{xe(!1),Ae(!1),s(at())},onNavigateTerminals:()=>{xe(!1),Ae(!1),s(se?xs(se):at())},onNavigateButler:()=>{xe(!1),Ae(!1),s(se?Vn(se):at())},onNavigateSessions:()=>{xe(!1),Ae(!1),d()},onNavigateToolFiles:()=>{xe(!1),Ae(!1),s(se?el(se):at())},onNavigateToolGit:()=>{xe(!1),Ae(!1),s(se?tl(se):at())},onNavigateToolProcesses:()=>{xe(!1),Ae(!1),s(se?nl(se):at())},onNavigateSettings:()=>{xe(!1),Ae(!1),s("/settings")},children:t.jsx(mo,{})})}):t.jsx("div",{className:"workbench-shell",ref:S,style:M,onMouseDownCapture:lr,onDoubleClickCapture:ai,"data-nav-loading":_e,"data-left-collapsed":He,"data-right-collapsed":Te,"data-info-ready":xt,"data-runtime-platform":i.platform,"data-os-family":i.ui.osFamily,"data-overlay-titlebar":i.ui.prefersOverlayTitlebar,children:t.jsxs("div",{className:"workbench-body-shell",children:[t.jsx("aside",{className:"workbench-nav surface-card","data-collapsed":He,children:t.jsx(Ra,{workspaceGroups:mr,workspaceVisualContextMap:Ds,sessionDisplaySortMode:c,favoriteSessions:qn,favoriteSessionIds:_t,activeWorkspaceId:se,isConversationActive:pt==="conversation",isTerminalActive:pt==="terminals",isButlerActive:pt==="butler",isSearchOpen:Mn,navigationLoading:_e,navigationError:Je,activeSessionId:pe,onRefreshNavigation:Ke,onSessionUpdated:ot,onNavigateConversation:Gn,onNavigateTerminals:()=>s(se?xs(se):at()),onNavigateButler:()=>s(se?Vn(se):at()),onOpenSearch:()=>Os(),onOpenSettings:()=>s("/settings"),onSelectWorkspace:hs,onToggleWorkspaceCollapse:fr,onStartWorkspaceReorder:Ps,onPreviewWorkspaceReorder:Ws,onCommitWorkspaceReorder:ls,allowWorkspaceReorder:!0,subscribeGitSnapshot:fn,requestGitRefresh:ht,subscribeWorkspaceManagementSnapshot:rs,requestWorkspaceManagementRefresh:_n,onToggleFavoriteSession:fs,onArchiveSession:a=>Ye(a,!0),onUnarchiveSession:a=>Ye(a,!1),workspaceManagementStateById:Yt,setWorkspaceManagementStateById:an,unreadNotificationCount:On,notificationPanelOpen:jt,onToggleNotificationPanel:()=>{Nt(a=>!a)},onToggleCollapse:()=>Yn(!0)})}),t.jsx("div",{className:"workbench-side-resizer","data-side":"left","data-collapsed":He,role:"separator","aria-label":r("shell.leftResizerLabel"),onMouseDown:He?void 0:a=>Hs("left",a)}),t.jsxs("div",{className:"workbench-main-shell",children:[t.jsxs("div",{className:"workbench-collapsed-rail","aria-hidden":!He&&!Te,children:[t.jsxs("div",{className:"workbench-collapsed-controls left","data-visible":He,children:[t.jsx(Ia,{className:"workbench-nav-toolbar-button workbench-collapsed-button",ariaLabel:r("shell.showSessionSidebar"),side:"left",collapsed:!0,onClick:ui}),t.jsx(yl,{collapsed:!0}),t.jsx(Kl,{unreadCount:On,open:jt,onToggle:()=>{Nt(a=>!a)},collapsed:!0})]}),te?t.jsx("div",{className:"workbench-collapsed-controls right","data-visible":Te,children:t.jsx(Ia,{className:"workbench-nav-toolbar-button workbench-collapsed-button",ariaLabel:r("shell.showInfoSidebar"),side:"right",collapsed:!0,onClick:hi})}):null]}),t.jsx(mo,{})]}),te?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"workbench-side-resizer","data-side":"right","data-collapsed":Te,role:"separator","aria-label":r("shell.rightResizerLabel"),onMouseDown:Te?void 0:a=>Hs("right",a)}),t.jsx("aside",{className:"workbench-auxiliary surface-card","data-workspace-tone":(Rt==null?void 0:Rt.tone)??"root","data-worktree-depth":(Rt==null?void 0:Rt.depth)??0,"data-collapsed":Te,"data-custom-panel":pt==="butler",style:tn(Rt),children:pt==="butler"?t.jsx("div",{className:"workbench-auxiliary-custom-panel",children:Qe}):t.jsx(Ma,{panelReady:xt,activeTab:Cs,fileRevealRequest:on,onTabChange:a=>{Qt(),rn(a)},onToggleCollapse:()=>zt(!0),currentSessionId:rt?null:pe,activeWorkspaceId:se,navigationGroups:F,workspaceContext:Rt,worktreeMeta:$n,worktreeMergeState:br,onRefreshWorktreeMergePreview:Xe,onApplyWorktreeMerge:ur,onCleanupWorktree:Ms})})]}):null]})}),t.jsx(Nf,{open:jt,notifications:cn,archivedNotificationIds:Jt,showArchivedNotifications:Zt,onClose:()=>Nt(!1),onToggleShowArchivedNotifications:un,onArchiveNotification:a=>{Hn(a,!0)},onUnarchiveNotification:a=>{Hn(a,!1)},onSelectNotification:li,preferredWorkspaceId:se,preferredSessionId:rt?null:pe}),t.jsx(Uf,{open:Mn,mode:Zn,keyword:Bt,codeWorkspaceId:vt,codeResults:Bn,codeLoading:ii,codeError:oi,workspaceOptions:us,sessionResults:di,onClose:Sr,onModeChange:a=>{Pn(a),Xt(null),yt([])},onKeywordChange:a=>{Wn(a),Zn==="code"&&!a.trim()&&(yt([]),Xt(null))},onCodeWorkspaceChange:a=>Is(a),onCodeSearch:()=>{jr()},onOpenSession:a=>{Sr();const u=Re.find(b=>b.session.sessionId===a)??null;s(u?$t(u.workspace.id,a):at())}}),t.jsxs($e,{open:je!==null,title:r("shell.worktreeCleanupModalTitle"),description:r("shell.worktreeCleanupModalDescription"),onClose:()=>{var a;je&&((a=tt[je.workspaceId])!=null&&a.cleaning)||(Ln(!1),es(null))},children:[t.jsx("p",{className:"workbench-section-empty",children:je?r("shell.worktreeCleanupConfirm",{name:je.displayName||je.branchName}):""}),je?t.jsxs("div",{className:"worktree-cleanup-modal-options",children:[t.jsxs("label",{className:"conversation-selection-checkbox worktree-cleanup-modal-option",children:[t.jsx("input",{type:"checkbox",checked:ln,disabled:!!((Ce=tt[je.workspaceId])!=null&&Ce.cleaning)||((ms=(Cr=tt[je.workspaceId])==null?void 0:Cr.preview)==null?void 0:ms.alreadyMerged)!==!0,onChange:a=>Ln(a.target.checked)}),t.jsx("span",{children:r("shell.worktreeCleanupDeleteBranchLabel",{branch:je.branchName})})]}),((Ir=(Tr=tt[je.workspaceId])==null?void 0:Tr.preview)==null?void 0:Ir.alreadyMerged)!==!0?t.jsx("p",{className:"conversation-selection-hint worktree-cleanup-modal-hint",children:r("shell.worktreeCleanupDeleteBranchHint")}):null]}):null,t.jsxs("div",{className:"workbench-modal-actions",children:[t.jsx("button",{type:"button",className:"secondary-button",disabled:!!(je&&((Rr=tt[je.workspaceId])!=null&&Rr.cleaning)),onClick:()=>{Ln(!1),es(null)},children:r("common.cancel")}),t.jsx("button",{type:"button",className:ln&&je&&((xn=(Mr=tt[je.workspaceId])==null?void 0:Mr.preview)==null?void 0:xn.alreadyMerged)===!0?"secondary-button workbench-danger-button":"primary-button",disabled:!je||!!(je&&((vn=tt[je.workspaceId])!=null&&vn.cleaning)),onClick:()=>{je&&Ie(je)},children:je&&((co=tt[je.workspaceId])!=null&&co.cleaning)?r("shell.worktreeCleanupRunning"):ln&&je&&((ho=(uo=tt[je.workspaceId])==null?void 0:uo.preview)==null?void 0:ho.alreadyMerged)===!0?r("shell.worktreeCleanupDeleteBranchAction"):r("shell.worktreeCleanupAction")})]})]}),Be?t.jsxs(t.Fragment,{children:[gr?null:t.jsx(Ea,{isOpen:Jn,side:"left",onClose:()=>xe(!1),children:Mt}),wr?null:t.jsx(Ea,{isOpen:Vt,side:"right",onClose:()=>Ae(!1),children:Ft})]}):null]})}function Ea({isOpen:e,side:n,onClose:s,children:i,className:o,overlayClassName:c}){if(!e)return null;const h=t.jsxs(t.Fragment,{children:[t.jsx("div",{className:["mobile-nav-overlay","open",c].filter(Boolean).join(" "),onClick:s,role:"button",tabIndex:0,"aria-label":r("common.back"),onKeyDown:f=>{f.key==="Escape"&&s()}}),t.jsx("div",{className:["mobile-nav-drawer",n,"open",o].filter(Boolean).join(" "),children:i})]});return typeof document>"u"?h:tr.createPortal(h,document.body)}function Qm(){return l.useContext(Cl)??{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 Yl(e){return e.startsWith("draft-")}export{at as $,uu as A,rh as B,hu as C,no as D,Tu as E,du as F,Eu as G,gm as H,Sn as I,js as J,ks as K,Xm as L,Gm as M,zm as N,Ym as O,$m as P,so as Q,ku as R,gu as S,vm as T,dl as U,tn as V,jd as W,gt as X,Hc as Y,ao as Z,wm as _,Zm as a,Vi as a0,Sd as a1,xm as a2,ym as a3,Sm as a4,Rm as a5,Mm as a6,Im as a7,Cm as a8,jm as a9,nm as aA,sm as aB,Fc as aC,dm as aD,fm as aE,Dc as aF,km as aG,um as aH,lm as aI,hm as aJ,cm as aK,bm as aL,pm as aM,mm as aN,rm as aO,em as aP,Za as aQ,Hm as aa,Nm as ab,Lm as ac,qm as ad,Km as ae,Vm as af,Om as ag,Wm as ah,Am as ai,Bm as aj,Dm as ak,_m as al,Fm as am,Ku as an,Tm as ao,Em as ap,Pm as aq,Um as ar,Ru as as,zu as at,Bi as au,im as av,am as aw,om as ax,tm as ay,Lc as az,$t as b,uh as c,sh as d,Jm as e,Du as f,Lu as g,vl as h,bu as i,Qs as j,xs as k,Ou as l,Ho as m,Qa as n,Vn as o,nl as p,Gt as q,Yr as r,vu as s,Su as t,Qm as u,el as v,Ys as w,tl as x,xu as y,ro as z};