@yuriai/web 0.3.1 → 0.3.2-beta.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 (87) hide show
  1. package/dist/assets/{AgentAvatar-BwB9S5gR.js → AgentAvatar-B4_d0rQt.js} +1 -1
  2. package/dist/assets/{AssistantConversationSurface-BQJZ0RY8.js → AssistantConversationSurface-BlrOfc3x.js} +3 -3
  3. package/dist/assets/{AssistantSessionCard-CSpwjbEO.js → AssistantSessionCard-B7cmrLAe.js} +2 -2
  4. package/dist/assets/{AssistantUnreadBadge-DJQUBf7P.js → AssistantUnreadBadge-DzxFnL8M.js} +1 -1
  5. package/dist/assets/{AssistantView-BNYeCdPt.js → AssistantView-TODFoL2I.js} +1 -1
  6. package/dist/assets/{DiagramView-4xy78PeY.js → DiagramView-x3sdXc97.js} +1 -1
  7. package/dist/assets/{FadeInOnReveal-BSm_Y5N-.js → FadeInOnReveal-C5qpH3TY.js} +1 -1
  8. package/dist/assets/{GuiPluginPage-Zn-NJGcV.js → GuiPluginPage-D5ajS2AA.js} +1 -1
  9. package/dist/assets/{GuiPluginSurface-BzbqxS7y.js → GuiPluginSurface-bwXAUscV.js} +1 -1
  10. package/dist/assets/{GuiPluginWindow-DACvDqJe.js → GuiPluginWindow-SsWHnc4g.js} +1 -1
  11. package/dist/assets/{Icon-CbRhi6Fu.js → Icon-DBOSvb4U.js} +1 -1
  12. package/dist/assets/{ImageLoadingPlaceholder-DoSf5jCj.js → ImageLoadingPlaceholder-CrJp1f5y.js} +1 -1
  13. package/dist/assets/{LoadingImage-2mWVVnaP.js → LoadingImage-zXRrm9H9.js} +1 -1
  14. package/dist/assets/MarkdownRenderer-eeOXke_U.js +2 -0
  15. package/dist/assets/{MarkdownRendererImpl-Bs4elVH3.js → MarkdownRendererImpl-BeJCqK7P.js} +1 -1
  16. package/dist/assets/{MarkstreamRendererImpl-rHAAvqOj.js → MarkstreamRendererImpl-DOYwdhQ_.js} +1 -1
  17. package/dist/assets/{MobileDetailNavigation-l_n1taf1.js → MobileDetailNavigation-DVbLG15P.js} +1 -1
  18. package/dist/assets/{MobileResizableSheet-eCQDQAYS.js → MobileResizableSheet-WTfrQdK8.js} +1 -1
  19. package/dist/assets/{MobileShareBridge-DGb2HExd.js → MobileShareBridge-CgVEGvAL.js} +1 -1
  20. package/dist/assets/{MobileSurface-lAYRO5L7.js → MobileSurface-BL4nGTY5.js} +1 -1
  21. package/dist/assets/{MultiRunWindow-BzkslOOz.js → MultiRunWindow-CMBcfCOh.js} +1 -1
  22. package/dist/assets/{OnboardingScreen-YNlP1MQe.js → OnboardingScreen-DLMYQLFn.js} +1 -1
  23. package/dist/assets/{OverlayScrollbar-CTdoPf6E.js → OverlayScrollbar-CwmXL6W2.js} +1 -1
  24. package/dist/assets/{RemoteAssistantSessionCard-B1Pavyxf.js → RemoteAssistantSessionCard-vCSOg3_8.js} +1 -1
  25. package/dist/assets/{SettingsView-Bl2kgume.js → SettingsView-DeS2ph7b.js} +1 -1
  26. package/dist/assets/{SettingsWindow-IUQlRvAB.js → SettingsWindow-CBh8oudq.js} +1 -1
  27. package/dist/assets/{SetupTourDialog-CPBnXSzq.js → SetupTourDialog-C6SfskP3.js} +1 -1
  28. package/dist/assets/{TerminalView-9qSzxiHi.js → TerminalView-CJDYSJWP.js} +1 -1
  29. package/dist/assets/{ToolOutputDialog-CmhQV6kW.js → ToolOutputDialog-DF8dWVTm.js} +1 -1
  30. package/dist/assets/{VoiceSettings-CfYrDKgr.js → VoiceSettings-C-W8KWvQ.js} +1 -1
  31. package/dist/assets/{capgoAdapter-BEKE5h5I.js → capgoAdapter-vPx0i-Ad.js} +1 -1
  32. package/dist/assets/{checkbox-gVpQUiVY.js → checkbox-QxG9Mpbu.js} +1 -1
  33. package/dist/assets/{collapsible-DCBnoRLL.js → collapsible-BvteRbPh.js} +1 -1
  34. package/dist/assets/{context-menu-w28HFXdm.js → context-menu-BYPUMFAX.js} +1 -1
  35. package/dist/assets/{diagram-DGTlsED0.js → diagram-D6B_k7M5.js} +1 -1
  36. package/dist/assets/{dialog-wyG1j1ZY.js → dialog-BfjbsTOP.js} +1 -1
  37. package/dist/assets/{fileMentionTouchSelection-YTaXrwGt.js → fileMentionTouchSelection-DiKjZQEm.js} +1 -1
  38. package/dist/assets/{gitApi-Bxuv7iZR.js → gitApi-CtJXK0WM.js} +1 -1
  39. package/dist/assets/host-Bx9gj-ju.js +1 -0
  40. package/dist/assets/{input-Bv6SbhDB.js → input-C16jIASm.js} +1 -1
  41. package/dist/assets/{insertionBoundaries-CIvMb0MT.js → insertionBoundaries-62IwW9Ka.js} +1 -1
  42. package/dist/assets/{main-DrYyJLms.js → main-CAyhodbD.js} +4 -4
  43. package/dist/assets/{main-wQ79inDK.js → main-DZedJhQx.js} +2 -2
  44. package/dist/assets/{markdownHeightCache-D2mAXH8W.js → markdownHeightCache-CDcoG7oI.js} +1 -1
  45. package/dist/assets/{mcpQueries-CUIUymwN.js → mcpQueries-CQjcxaDQ.js} +1 -1
  46. package/dist/assets/{miniChat-BTPvGmaS.js → miniChat-DFXcicxI.js} +2 -2
  47. package/dist/assets/{mobile-DtTmIm4s.js → mobile-CKNvVIUj.js} +2 -2
  48. package/dist/assets/{mobileBackNavigation-DwKmPsU6.js → mobileBackNavigation-BPncsZvR.js} +1 -1
  49. package/dist/assets/{mobileConnections-BaVOE5PX.js → mobileConnections-BBNhczt8.js} +2 -2
  50. package/dist/assets/{multirun-Di_vmRR_.js → multirun-B5DvrZRF.js} +1 -1
  51. package/dist/assets/{native-config-B3D9Nv0p.js → native-config-1ijMxxRj.js} +1 -1
  52. package/dist/assets/{navigation-lAkZZJTN.js → navigation-guYHqUd5.js} +1 -1
  53. package/dist/assets/{openRemoteProjectSession-APe4n1gm.js → openRemoteProjectSession-Dvg3pCz-.js} +1 -1
  54. package/dist/assets/{projectMeta--OgVpG4Z.js → projectMeta-BOcz1XpN.js} +1 -1
  55. package/dist/assets/{pwa-B6o6xxPS.js → pwa-D4vcI8VD.js} +1 -1
  56. package/dist/assets/{queue-abort-optimistic-DYFaJQrY.js → queue-abort-optimistic-BuYzwR0N.js} +1 -1
  57. package/dist/assets/{react-DVXKhubI.js → react-DEouUmkV.js} +1 -1
  58. package/dist/assets/{readiness-Di6b1RDu.js → readiness-CzHlOvNr.js} +2 -2
  59. package/dist/assets/{reference-history-DO4BO4M5.js → reference-history-Dyzfrmw-.js} +1 -1
  60. package/dist/assets/{remoteSessionReference-CabFQNo2.js → remoteSessionReference-CqNXv4Qg.js} +1 -1
  61. package/dist/assets/{renderElectronMiniChatApp-BkHYTNcZ.js → renderElectronMiniChatApp-S8GzGGR7.js} +2 -2
  62. package/dist/assets/{renderMobileApp-tKRbh1UN.js → renderMobileApp-Bbs497wM.js} +4 -4
  63. package/dist/assets/{runtimeConfig-Ez0YVcLS.js → runtimeConfig-oElsA8Cz.js} +1 -1
  64. package/dist/assets/runtimeEndpointReset-DT9dHdmQ.js +151 -0
  65. package/dist/assets/{select-CrwouN4e.js → select-DpKqX1V6.js} +1 -1
  66. package/dist/assets/{sessionLookup-BpilZd_w.js → sessionLookup-BHJgGHf0.js} +1 -1
  67. package/dist/assets/{sortable-tabs-strip-Ijc1-z3K.js → sortable-tabs-strip-a2sshnFf.js} +1 -1
  68. package/dist/assets/{speechSettingsQueries-cV1mK7RB.js → speechSettingsQueries-DKesZuQ3.js} +1 -1
  69. package/dist/assets/{textarea-BPhvk5Vd.js → textarea-DPrUh2E_.js} +1 -1
  70. package/dist/assets/{tooltip-BQ1xVNC6.js → tooltip-JO7-ziD9.js} +1 -1
  71. package/dist/assets/types-CxdhW05G.js +2 -0
  72. package/dist/assets/{useAppFontEffects-PZ3Y-JIL.js → useAppFontEffects-DhmTAaeq.js} +5 -5
  73. package/dist/assets/{useDesktopWindowControlsLayout-Z6PBzcuL.js → useDesktopWindowControlsLayout-C3Bhl4tF.js} +1 -1
  74. package/dist/assets/{useEffectiveDirectory-DWiz5-Xa.js → useEffectiveDirectory-DsQiUzq0.js} +1 -1
  75. package/dist/assets/{useMobileNavigationStore-D2FLOd1l.js → useMobileNavigationStore-2N3dS8vX.js} +4 -4
  76. package/dist/assets/{usePluginsStore-pd_Lgl6m.js → usePluginsStore-nTVPoJCl.js} +1 -1
  77. package/dist/assets/{useProjectRuntimeAPIs-Me0Uy2tM.js → useProjectRuntimeAPIs-CHhK626l.js} +1 -1
  78. package/dist/assets/{useStreamingTextThrottle-eJaQ-Vpw.js → useStreamingTextThrottle-CNJGj-_8.js} +1 -1
  79. package/dist/index.html +5 -5
  80. package/dist/mini-chat.html +5 -5
  81. package/dist/mobile.html +1 -1
  82. package/package.json +1 -1
  83. package/server/lib/gui-customization/skill/references/work-status.md +4 -2
  84. package/dist/assets/MarkdownRenderer-BHK_Ba71.js +0 -2
  85. package/dist/assets/host-D9EDWNmx.js +0 -1
  86. package/dist/assets/runtimeEndpointReset-C105_37x.js +0 -151
  87. package/dist/assets/types-CO7YCNVq.js +0 -2
@@ -1,4 +1,4 @@
1
- import{n as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n}from"./runtime-switch-BMjl5Y5W.js";import{n as r}from"./runtime-fetch-DKZOpfzo.js";import{t as i}from"./runtimeAPIRegistry-C2VogTny.js";import{$ as a,A as o,B as s,D as c,E as l,F as u,G as d,H as f,I as p,J as m,K as ee,L as te,M as ne,N as re,O as ie,P as ae,Q as oe,R as se,S as ce,T as le,U as ue,V as de,W as h,X as fe,Y as pe,Z as me,_ as he,_t as ge,a as _e,at as ve,b as ye,bt as be,c as xe,ct as Se,d as Ce,dt as we,et as Te,f as Ee,ft as De,g as Oe,gt as ke,h as Ae,ht as je,i as Me,it as Ne,j as g,k as Pe,l as Fe,lt as Ie,m as Le,mt as Re,n as ze,nt as Be,o as Ve,ot as He,p as Ue,pt as We,q as Ge,r as Ke,rt as qe,s as Je,st as Ye,t as Xe,tt as Ze,u as Qe,ut as $e,v as et,vt as tt,x as nt,y as rt,yt as it,z as at}from"./gitApiHttp-B0FJaIhU.js";import{n as ot}from"./client-1Fk5IbQR.js";import{Xi as _,p as v,u as st}from"./useMobileNavigationStore-D2FLOd1l.js";var y=`/api/magic-prompts`,ct=new Map([{id:`git.commit.generate.visible`,title:`Commit Generation Visible Prompt`,group:`Git`,description:`Visible user message for commit message generation.`,template:`You are generating a Conventional Commits subject line from the diffs of the selected files.`},{id:`git.commit.generate.instructions`,title:`Commit Generation Instructions`,group:`Git`,description:`Hidden instructions for commit message generation.`,placeholders:[{key:`selected_files`,description:`Bullet list of currently selected file paths.`}],template:`Return exactly one JSON object and nothing else. Do not include prose, markdown, explanations, or code fences.
1
+ import{n as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n}from"./runtime-switch-BMjl5Y5W.js";import{n as r}from"./runtime-fetch-DKZOpfzo.js";import{t as i}from"./runtimeAPIRegistry-C2VogTny.js";import{$ as a,A as o,B as s,D as c,E as l,F as u,G as d,H as f,I as p,J as m,K as ee,L as te,M as ne,N as re,O as ie,P as ae,Q as oe,R as se,S as ce,T as le,U as ue,V as de,W as h,X as fe,Y as pe,Z as me,_ as he,_t as ge,a as _e,at as ve,b as ye,bt as be,c as xe,ct as Se,d as Ce,dt as we,et as Te,f as Ee,ft as De,g as Oe,gt as ke,h as Ae,ht as je,i as Me,it as Ne,j as g,k as Pe,l as Fe,lt as Ie,m as Le,mt as Re,n as ze,nt as Be,o as Ve,ot as He,p as Ue,pt as We,q as Ge,r as Ke,rt as qe,s as Je,st as Ye,t as Xe,tt as Ze,u as Qe,ut as $e,v as et,vt as tt,x as nt,y as rt,yt as it,z as at}from"./gitApiHttp-B0FJaIhU.js";import{n as ot}from"./client-1Fk5IbQR.js";import{Xi as _,p as v,u as st}from"./useMobileNavigationStore-2N3dS8vX.js";var y=`/api/magic-prompts`,ct=new Map([{id:`git.commit.generate.visible`,title:`Commit Generation Visible Prompt`,group:`Git`,description:`Visible user message for commit message generation.`,template:`You are generating a Conventional Commits subject line from the diffs of the selected files.`},{id:`git.commit.generate.instructions`,title:`Commit Generation Instructions`,group:`Git`,description:`Hidden instructions for commit message generation.`,placeholders:[{key:`selected_files`,description:`Bullet list of currently selected file paths.`}],template:`Return exactly one JSON object and nothing else. Do not include prose, markdown, explanations, or code fences.
2
2
 
3
3
  The JSON object must have exactly this shape:
4
4
  {"subject": string, "highlights": string[]}
@@ -0,0 +1 @@
1
+ import{f as e,n as t}from"./platform-wF65ZFgV.js";import{C as n,D as r,I as i,L as a,M as o,O as s,P as c,S as l,T as u,_ as d,a as f,b as p,c as m,j as h,n as g,o as _,r as v,s as y,t as ee,v as b,w as x,y as S}from"./vendor-opencode-client-BM2r1f0o.js";import{a as te}from"./vendor-tanstack-query-core-BSjXNgF_.js";import{b as ne,v as C}from"./runtime-file-resource-CuLP3xp7.js";import{o as w}from"./path-utils-jGozTg9d.js";import{a as T,n as re}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{Dt as ie,ht as ae,mt as oe,y as se}from"./vendor-effect-X1Hqc7ba.js";import{t as E}from"./native-errors-06if6eu-.js";import{a as ce,i as le,n as ue,o as de,r as fe,s as D}from"./appearance-DFsI3pnP.js";import{i as pe,o as me}from"./fileReferenceParser-1HHDBUum.js";import{a as he,r as O}from"./pages-CYkE04ml.js";import{n as ge,t as _e}from"./vendor-solid-js-BBVUd3Hw.js";import{a as ve,c as ye,d as be,f as k,g as A,h as j,i as M,l as N,m as xe,n as Se,o as P,p as F,r as Ce,s as we,t as Te,u as Ee}from"./vendor-opencode-plugin-ZhpPgHCL.js";var I={"@opencode/plugin/gui":P,"@opencode/plugin/gui/main":P,"@opencode/plugin/gui/file":ve,"@opencode/plugin/gui/review":M,"@opencode/plugin/gui/browser":Ce,"@opencode/plugin/rpc":Te,"@opencode/schema/rpc":Se,"@opencode/client":v,"@opencode/client/effect":g,"@opencode/client/solid":ee,effect:se,"solid-js":c,"solid-js/web":ge,"solid-js/store":y},De=new Set(`assert assert/strict async_hooks buffer child_process cluster console constants crypto dgram diagnostics_channel dns dns/promises domain events fs fs/promises http http2 https inspector inspector/promises module net os path path/posix path/win32 perf_hooks process punycode querystring readline readline/promises repl stream stream/consumers stream/promises stream/web string_decoder sys timers timers/promises tls trace_events tty url util util/types v8 vm wasi worker_threads zlib`.split(` `));function Oe(){let e=new Proxy(function(){},{get:(t,n)=>n===`then`?void 0:n===Symbol.hasInstance?()=>!1:n===Symbol.toPrimitive||n===`toString`?()=>`[main-only module]`:e,apply:()=>e,construct:()=>e,set:()=>!0});return e}function ke(e,t){if(e.length>16777216)throw Error(`GUI bundle exceeds 16 MiB`);let n={exports:{}};Function(`require`,`module`,`exports`,e)(e=>{if(Object.hasOwn(I,e))return I[e];if(e===`electron`||e.startsWith(`node:`)||De.has(e))return Oe();throw Error(`Unsupported GUI shared module: ${e}`)},n,n.exports);let r=n.exports,i=r&&typeof r==`object`&&`default`in r?r.default:r;if(!i||typeof i!=`object`)throw Error(`GUI bundle must default-export Plugin.define`);if((!(`setup`in i)||typeof i.setup!=`function`)&&!(t&&`main`in i&&typeof i.main==`function`))throw new E(`GUI_PLUGIN_UNSUPPORTED`,`This host requires a window setup; main-only plugins are unsupported`);if(`os`in i&&i.os!==void 0){if(!t)throw new E(`GUI_PLUGIN_UNSUPPORTED`,`OS-restricted plugins require the native GUI host`);if(!Array.isArray(i.os)||!i.os.includes(t))throw new E(`GUI_PLUGIN_UNSUPPORTED`,`GUI plugin is unavailable on this OS`)}if(`main`in i&&i.main!==void 0&&typeof i.main!=`function`)throw Error(`Invalid GUI main entry`);if(`stores`in i&&i.stores!==void 0){if(!i.stores||typeof i.stores!=`object`||Array.isArray(i.stores))throw Error(`Invalid GUI stores`);for(let e of Object.values(i.stores))if(!e||typeof e!=`object`||!(`schema`in e)||!ie(e.schema)||!(`scope`in e)||![`global`,`session`].includes(String(e.scope))||!(`initial`in e))throw Error(`Invalid GUI store declaration`)}if(`i18n`in i&&i.i18n!==void 0){if(!i.i18n||typeof i.i18n!=`object`||Array.isArray(i.i18n))throw Error(`Invalid GUI locale catalog`);for(let e of Object.values(i.i18n))if(!e||typeof e!=`object`||Array.isArray(e)||Object.values(e).some(e=>typeof e!=`string`))throw Error(`GUI locales must be inline string dictionaries`)}return i}function L(t){let n=t;if(/^file:/i.test(n)){let e=new URL(n);n=`${e.hostname&&e.hostname!==`localhost`?`//${e.hostname}`:``}${decodeURIComponent(e.pathname)}`,/^\/[a-z]:\//i.test(n)&&(n=n.slice(1))}let r=e(n)??``;return r===`.`?``:r}var R=e=>/^(?:\/|[a-z]:\/)/i.test(e),z=()=>{throw Error(`Unsupported GUI file API: tree`)},B=class extends Error{},V=e=>new TextEncoder().encode(e).byteLength,Ae=class{files;query;transport;root;api;ended=!1;states=new Map;inflight=new Map;watches=new Map;apiLeases=new Map;registeredOwners=new WeakSet;endedOwners=new WeakSet;leaseCount=0;rerun=new Set;selections=new Map;scrolls=new Map;subscriptions=new Map;constructor(e,t,n,r){this.files=e,this.query=t,this.transport=n,this.root=r,this.root=L(r),this.api={root:this.root,ready:()=>!this.ended,resolve:e=>this.resolve(e),absolute:R,get:e=>{let t=this.track(e,`file`);return this.states.get(t)},missing:e=>{let t=this.track(e,`missing`);return this.states.get(t)?.notFound===!0},sync:(e,t)=>{let n=s();return this.ended||n&&this.endedOwners.has(n)?Promise.resolve():(this.acquireApiLease(e),this.sync(e,t?.force))},unwatch:e=>this.releaseApiLease(s(),this.resolve(e)),exists:async e=>{try{if(this.files.statFile)return(await this.query.fetchQuery(this.statOptions(e))).isFile;let t=this.full(e);return(await this.files.listDirectory(t.slice(0,t.lastIndexOf(`/`)))).entries.some(e=>!e.isDirectory&&L(e.path)===t)}catch{return!1}},search:async(e,t)=>{if(t?.kind===`any`)throw Error(`Unsupported GUI file search: directories`);t?.signal?.throwIfAborted();let r=await this.query.fetchQuery({queryKey:[`gui-plugin-files`,n,this.root,`search`,e,t?.limit],gcTime:3e4,queryFn:async({signal:n})=>(n.throwIfAborted(),this.files.search({directory:this.root,query:e,maxResults:t?.limit??100}))});if(t?.signal?.throwIfAborted(),this.ended)throw new DOMException(`GUI file model was disposed`,`AbortError`);return r.map(e=>this.resolve(e.path))},selection:{get:e=>this.selections.get(this.track(e,`selection`)),set:(e,t)=>{let n=this.resolve(e),r=this.selections.get(n);r===t||r&&t&&r.start===t.start&&r.end===t.end&&r.side===t.side&&r.endSide===t.endSide||(this.selections.set(n,t),this.trim(this.selections,`selection`),this.changed(n,`selection`))}},scroll:{get:e=>this.scrolls.get(this.track(e,`scroll`))??{},set:(e,t)=>{let n=this.resolve(e),r=this.scrolls.get(n),i={...r,...t};(r?.top!==i.top||r?.left!==i.left)&&(this.scrolls.set(n,i),this.trim(this.scrolls,`scroll`),this.changed(n,`scroll`))}},tree:{list:z,state:z,sync:z,expand:z,collapse:z}}}resolve(e){let t=L(e);if(!R(t))return t;if(t===this.root)return``;let n=this.root.endsWith(`/`)?this.root:`${this.root}/`;return t.startsWith(n)?t.slice(n.length):t}full(e){let t=this.resolve(e);return R(t)?t:L(`${this.root}/${t}`)}input(e){return{scopeDirectory:this.root,path:this.full(e),options:{directory:this.root}}}statOptions(e){return{...ne(this.files,this.input(e),this.transport),gcTime:3e4}}track(e,t){let n=this.resolve(e),i=r();if(!i||this.ended)return n;let a=`${t}:${n}`,s=this.subscriptions.get(a);s||(s={revision:u(0),listeners:new Set},this.subscriptions.set(a,s));let c=s;return c.listeners.has(i)||(c.listeners.add(i),o(i,()=>h(()=>{c.listeners.delete(i),!c.listeners.size&&this.subscriptions.get(a)===c&&this.subscriptions.delete(a)}))),c.revision[0](),n}changed(e,t){this.ended||this.subscriptions.get(`${t}:${e}`)?.revision[1](e=>e+1)}trim(e,t){for(;e.size>64;){let n=e.keys().next().value;e.delete(n),this.changed(n,t)}}setState(e,t){let n=this.states.get(e);n?.content?.content===t.content?.content&&n?.content?.type===t.content?.type&&(t.content=n?.content),!(n&&n.loaded===t.loaded&&n.loading===t.loading&&n.error===t.error&&n.notFound===t.notFound&&n.content===t.content)&&(this.states.set(e,t),d(()=>{this.changed(e,`file`),n?.notFound===!0!=(t.notFound===!0)&&this.changed(e,`missing`)}))}acquireApiLease(e){let t=s();if(this.ended||t&&this.endedOwners.has(t)||!this.files.statFile)return;let n=this.resolve(e),r=this.apiLeases.get(t);if(r?.has(n))return;if(this.leaseCount>=256)throw Error(`GUI file consumer limit exceeded`);let i=this.watch(n);r||(r=new Map,this.apiLeases.set(t,r)),r.set(n,i),this.leaseCount++,t&&!this.registeredOwners.has(t)&&(this.registeredOwners.add(t),h(()=>{`fn`in t||this.endedOwners.add(t),this.registeredOwners.delete(t);for(let e of[...this.apiLeases.get(t)?.keys()??[]])this.releaseApiLease(t,e)}))}releaseApiLease(e,t){let n=this.apiLeases.get(e),r=n?.get(t);r&&(n.delete(t),this.leaseCount--,n.size||this.apiLeases.delete(e),r())}reserve(e){if(!this.states.has(e)){if(this.states.size>=64){let e=[...this.states.keys()].find(e=>!this.watches.has(e)&&!this.inflight.has(e));if(!e)throw Error(`GUI file cache limit exceeded`);let t=this.states.get(e)?.notFound===!0;this.states.delete(e),d(()=>{this.changed(e,`file`),t&&this.changed(e,`missing`)})}this.states.set(e,{path:e,name:e.split(`/`).at(-1)??e})}}async sync(e,t=!1){if(this.ended)return;let n=this.resolve(e);if(this.inflight.has(n))return t&&this.rerun.add(n),this.inflight.get(n);if(!t&&this.states.get(n)?.loaded&&!this.states.get(n)?.error)return;this.reserve(n);let r=this.states.get(n);this.setState(n,{...r,path:n,name:n.split(`/`).at(-1)??n,loading:!r?.loaded&&!this.watches.get(n)?.failed});let i=(async()=>{try{do{this.rerun.delete(n);let e=this.watches.get(n),r=e?.epoch;try{let i=C(this.files,this.input(n),this.transport),a=await this.query.fetchQuery({...i,gcTime:3e4,staleTime:t?0:3e4,queryFn:async()=>{if(!this.files.readFile)throw Error(`File content reads are unavailable in this runtime`);let e=await this.files.readFile(this.full(n),{directory:this.root});if(e.exists===!1)throw new B(`File does not exist`);let t=e.content;if(V(t)>131072)throw Error(`GUI file preview exceeds 128 KiB`);return t}});if(this.ended)return;if(V(a)>131072)throw Error(`GUI file preview exceeds 128 KiB`);(!e||e.epoch===r&&!e.failed)&&this.setState(n,{path:n,name:n.split(`/`).at(-1)??n,loaded:!0,loading:!1,content:{type:`text`,content:a}})}catch(t){if(this.ended)return;if((!e||e.epoch===r&&!e.failed)&&this.setState(n,{...this.states.get(n),loading:!1,...t instanceof B?{notFound:!0}:{},error:String(t)}),!this.rerun.has(n))throw t}t=!0}while(!this.ended&&this.rerun.has(n))}finally{this.inflight.delete(n),this.rerun.delete(n)}})();return this.inflight.set(n,i),i}watch(e){if(this.ended||!this.files.statFile)return()=>{};let t=this.resolve(e),n=this.watches.get(t);if(!n){if(this.watches.size>=64)throw Error(`GUI file watch limit exceeded`);this.reserve(t),n={count:0,epoch:0,failed:!1,stop:()=>{}};let e=n;this.watches.set(t,e);let r,i=new te(this.query,{...this.statOptions(t),refetchInterval:2e3,refetchIntervalInBackground:!1}),a=i.subscribe(n=>{if(this.ended||this.watches.get(t)!==e||n.isFetching)return;if(n.isError||n.isSuccess&&!n.data.isFile){e.failed=!0,e.epoch++,this.setState(t,{...this.states.get(t),loading:!1,notFound:n.isSuccess?!0:this.states.get(t)?.notFound,error:n.isError?String(n.error):`File does not exist`});return}if(!n.data||!n.isSuccess)return;let i=`${n.data.size}:${n.data.mtimeMs??``}`,a=e.failed||r!==void 0&&i!==r;e.failed=!1,r=i,a&&(e.epoch++,this.sync(t,!0).catch(()=>{}))});e.stop=()=>{a(),i.destroy()},this.states.get(t)?.loaded&&this.sync(t,!0).catch(()=>{})}n.count++;let r=!0;return()=>{r&&(r=!1,--n.count===0&&this.watches.get(t)===n&&this.stopWatch(t))}}stopWatch(e){this.watches.get(e)?.stop(),this.watches.delete(e)}dispose(){this.ended=!0;for(let e of this.watches.values())e.stop();this.watches.clear(),this.apiLeases.clear(),this.leaseCount=0,this.rerun.clear(),this.states.clear(),this.inflight.clear(),this.selections.clear(),this.scrolls.clear(),this.subscriptions.clear()}},H=256,U=2097152,W=e=>structuredClone(m(e)),je=class{backend;transport;memory=new Map;resets=new Map;constructor(e,t){this.backend=e,this.transport=t}forPlugin(e,t){let n=(t,n=`global`)=>{if(typeof n==`object`&&`session`in n&&!n.session.location)throw Error(`Unsupported GUI storage: session location is unknown`);let r=n===`global`?n:`session`in n?[n.session.server.id,n.session.id,n.session.location]:[n.server,n.directory];return`yuri.gui-plugin.${JSON.stringify([this.transport,e,r,t])}`},r=e=>{if(t.aborted)throw Error(`GUI plugin has been disposed`);if(e!==void 0)throw Error(`Unsupported GUI storage migration: from`)},i=new Map;return{store:(e,a)=>{r(a.from);let o=n(e,a.scope),s=i.get(o);if(s)return s;if(i.size>=H)throw Error(`GUI plugin store limit exceeded`);let c=oe(a.schema),l=ae(a.schema),d=c(l(W(a.initial)));if(JSON.stringify(l(d)).length>U)throw Error(`GUI plugin store exceeds 2 MiB`);let f=d,p=this.backend.getItem(o);if(p!==null&&p.length<=U)try{f=c(JSON.parse(p))}catch{f=d}let[m,h]=u(f),g=e=>{r();let t=JSON.stringify(l(W(e)));if(t.length>U)throw Error(`GUI plugin store exceeds 2 MiB`);let n=c(JSON.parse(t));this.backend.setItem(o,t),h(()=>n)},_={get value(){return m()},ready:()=>!0,set:g,update:e=>{let t=W(m());if(e(t)!==void 0)throw Error(`Store update must not return a replacement`);g(t)}},v=()=>h(()=>W(d)),y=this.resets.get(o)??new Set;return y.add(v),this.resets.set(o,y),t.addEventListener(`abort`,()=>{y.delete(v),y.size||this.resets.delete(o),i.clear()},{once:!0}),i.set(o,_),_},memory:(e,t)=>{r();let i=n(e),a=this.memory.get(i);if(a)return[a[0],e=>{r(),a[1](e)}];if(this.memory.size>=H)throw Error(`GUI plugin memory store limit exceeded`);if(JSON.stringify(t.initial).length>U)throw Error(`GUI plugin memory exceeds 2 MiB`);let[o,s]=f(W(t.initial)),c=[o,e=>{r();let t=W(m(o));if(e(t)!==void 0)throw Error(`Memory update must not return a replacement`);if(JSON.stringify(t).length>U)throw Error(`GUI plugin memory exceeds 2 MiB`);s(_(t))}];return this.memory.set(i,[o,e=>{let t=W(m(o));if(e(t)!==void 0)throw Error(`Memory update must not return a replacement`);if(JSON.stringify(t).length>U)throw Error(`GUI plugin memory exceeds 2 MiB`);s(_(t))}]),c},remove:(e,t)=>{r(t?.from);let i=n(e,t?.scope);this.backend.removeItem(i);for(let e of this.resets.get(i)??[])e()}}}dispose(){this.memory.clear(),this.resets.clear()}};function Me(e){if(typeof e!=`string`||e.length>2097152)return;let t=e.trim();if(t)try{if(t.startsWith(`<`))return D(t);if(!/^data:/i.test(t))return t;let e=/^data:image\/(svg\+xml|png|jpeg|gif|webp|avif|x-icon|vnd\.microsoft\.icon)(?:;charset=utf-8)?(;base64)?,([\s\S]+)$/i.exec(t);if(!e)return;let[,n,r,i]=e;if(r&&!/^[A-Za-z0-9+/]+={0,2}$/.test(i))return;if(n.toLowerCase()===`svg+xml`){let e=r?new TextDecoder(`utf-8`,{fatal:!0}).decode(Uint8Array.from(atob(i),e=>e.charCodeAt(0))):decodeURIComponent(i);return D(e)}return!r||!atob(i).length?void 0:`data:image/${n.toLowerCase()};base64,${i}`}catch{return}}var G=e=>e===`yuri.exportPDF`||e===`yuri.exportLongImage`,Ne=class{api;probe;clients=new Map;ended=!1;constructor(e){this.api=e}use(e,t){let n=this.clients.get(t),r=n?.get(e);if(r)return r.live;let[i,a]=u(this.api&&!t.aborted&&!this.ended?{status:`pending`}:{status:`inactive`,reason:`disabled`}),o=()=>{a({status:`inactive`,reason:`disabled`}),t.removeEventListener(`abort`,o),this.clients.delete(t)},s={live:A(i),stop:o};if(this.ended||t.aborted||(n||(n=new Map,this.clients.set(t,n)),n.set(e,s),t.addEventListener(`abort`,o,{once:!0}),!this.api))return s.live;let c=this.api;return this.probe??=Promise.resolve().then(()=>c.capabilities()),this.probe.then(n=>{if(this.ended||t.aborted)return;let r=e===`yuri.exportPDF`?`exportPDF`:`exportLongImage`;if(n.version!==1||!n[r]){a({status:`inactive`,reason:`disabled`});return}let o=async(e,n={})=>{if(this.ended||t.aborted||i().status!==`active`)return{status:`cancelled`};let o=AbortSignal.any([t,...n.signal?[n.signal]:[]]);try{return await c[r](e,{...n,signal:o})}catch(e){throw e&&typeof e==`object`&&`code`in e&&e.code===`EXPORT_UNSUPPORTED`&&a({status:`inactive`,reason:`failed`}),e}},s=Object.freeze(e===`yuri.exportPDF`?{version:1,limits:n.limits,exportPDF:o}:{version:1,limits:n.limits,exportLongImage:o});a({status:`active`,generation:1,value:s})}).catch(()=>{!this.ended&&!t.aborted&&a({status:`inactive`,reason:`failed`})}),s.live}dispose(){this.ended=!0;for(let e of this.clients.values())for(let t of e.values())t.stop();this.clients.clear()}};function Pe(e,t){let n=new Map,r=Object.freeze({dismiss(){}});return e.addEventListener(`abort`,()=>{for(let e of[...n.values()])e.handle.dismiss()},{once:!0}),Object.freeze({show(i){if(e.aborted)return r;if(!t)throw new E(`GUI_PLUGIN_UNSUPPORTED`,`GUI toast is unavailable`);if(!i||typeof i!=`object`)throw new E(`GUI_PLUGIN_INVALID_INPUT`,`Expected toast options`);let{title:a,description:o,variant:s=`default`,duration:c=5e3,persistent:l=!1,icon:u,actions:d}=i;if(typeof a!=`string`||o!==void 0&&typeof o!=`string`||![`default`,`success`,`error`,`loading`].includes(s)||typeof l!=`boolean`||typeof c!=`number`||!Number.isFinite(c)||c<0)throw new E(`GUI_PLUGIN_INVALID_INPUT`,`Invalid toast options`);if(u!==void 0||d!==void 0)throw new E(`GUI_PLUGIN_UNSUPPORTED`,`GUI toast icon/actions are unsupported`);if(e.aborted)return r;let f=JSON.stringify([a,o??null,s,c,l]),p=n.get(f),m=()=>{let e=n.get(f);!e||e.id!==h||(clearTimeout(e.timer),n.delete(f))},h=(s==="default"?t:t[s])(a,{id:p?.id,description:o,duration:l?1/0:c,onDismiss:m,onAutoClose:m}),g=p?.handle??Object.freeze({dismiss(){m(),t.dismiss(h)}});clearTimeout(p?.timer);let _=s===`loading`&&!l?setTimeout(()=>g.dismiss(),c):void 0;return n.set(f,{id:h,handle:g,timer:_}),g}})}var Fe=T(`YuriMedia`);async function Ie(e){let n=/\.html?$/i.test(e.name)?`text/html`:`text/plain`,r=new Blob([e.content],{type:n});if(t()){if(!re.isPluginAvailable(`YuriMedia`))throw new E(`GUI_PLUGIN_UNSUPPORTED`,`Native file saving is unavailable`);if(r.size>33554432)throw new E(`GUI_PLUGIN_INVALID_INPUT`,`File exceeds maximum size`);let t=await new Promise((e,t)=>{let n=new FileReader;n.onload=()=>{if(typeof n.result!=`string`){t(Error(`Failed to encode file`));return}e(n.result.slice(n.result.indexOf(`,`)+1))},n.onerror=()=>t(n.error??Error(`Failed to encode file`)),n.readAsDataURL(r)});return!(await Fe.saveFile({dataBase64:t,mimeType:n,filename:e.name})).cancelled}let i=URL.createObjectURL(r),a=document.createElement(`a`);try{return a.href=i,a.download=e.name,document.body.append(a),a.click(),!0}finally{a.remove(),setTimeout(()=>URL.revokeObjectURL(i),1e3)}}var K=p();function Le(e){return{version:1,register(t){let n=a(K);if(!n||n.plugin!==e||n.signal.aborted||e.aborted)throw Error(`Preview actions require the owning mounted panel`);let r=new AbortController,i=AbortSignal.any([e,n.signal,r.signal]),o,s=()=>{i.removeEventListener(`abort`,s),r.abort(),o?.remove()};h(s),i.addEventListener(`abort`,s,{once:!0});try{o=t.render({element:t.element,signal:i,async snapshot(e={}){let r=AbortSignal.any([i,...e.signal?[e.signal]:[]]);if(r.throwIfAborted(),!n.content.contains(t.element)||n.target.contains(t.element))throw Error(`Preview capture region is no longer in its owning panel`);let a=await t.capture({...e,signal:r});if(r.throwIfAborted(),!n.content.contains(t.element))throw Error(`Preview capture region was replaced`);return a}}),i.throwIfAborted(),n.target.append(o)}catch(e){throw s(),e}return s}}}var Re=`yuri.work-status`;function q(e,t){return e===t||!!(e&&t&&Object.keys(e).length===Object.keys(t).length&&Object.keys(e).every(n=>e[n]===t[n]))}var J=e=>e&&Object.freeze({...e});function Y(e,t,n){let r=new AbortController,[i,a]=u(!0),[o,s]=u(J(e.project),{equals:q}),[c,l]=u(J(e.worktree),{equals:q}),[f,p]=u(Object.freeze({...e.git}),{equals:q}),[m,h]=u(e.placement);return{props:Object.freeze({session:t,directory:e.directory,runtimeId:n,signal:r.signal,get active(){return i()},get project(){return o()},get worktree(){return c()},get git(){return f()},get placement(){return m()}}),matches:t=>t.sessionId===e.sessionId&&t.directory===e.directory&&t.scope===e.scope,update(e){r.signal.aborted||d(()=>{s(J(e.project)),l(J(e.worktree)),p(Object.freeze({...e.git})),h(e.placement)})},dispose(){r.signal.aborted||(a(!1),r.abort())}}}var ze=class{plugins=new Map;order=new Map;snapshot=Object.freeze([]);generation=0;listeners=new Set;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.snapshot;setOrder(e){e.length===this.order.size&&e.every((e,t)=>this.order.get(e)===t)||(this.order=new Map(e.map((e,t)=>[e,t])),this.publish())}replace(e,t,n){let r=this.plugins.get(e)??[],i=new Set,a=n.map(n=>{if(!n||typeof n!=`object`||!(`id`in n)||typeof n.id!=`string`||!n.id.trim()||n.id.length>128||i.has(n.id)||!(`render`in n)||typeof n.render!=`function`||`order`in n&&n.order!==void 0&&(typeof n.order!=`number`||!Number.isFinite(n.order)))throw Error(`Invalid or duplicate yuri.work-status contribution`);i.add(n.id);let a=JSON.stringify([e,n.id]),o=`order`in n&&typeof n.order==`number`?n.order:0,s=n.render,c=r.find(e=>e.key===a),l=c&&c.revision===t&&c.render===s?c.generation:++this.generation;return c&&c.revision===t&&c.render===s&&c.order===o?c:Object.freeze({key:a,pluginId:e,revision:t,generation:l,order:o,render:s})});a.length?this.plugins.set(e,a):this.plugins.delete(e),this.publish()}contains(e){return this.plugins.get(e.pluginId)?.some(t=>t.key===e.key&&t.generation===e.generation)??!1}remove(e){this.plugins.delete(e)&&this.publish()}dispose(){this.plugins.clear(),this.publish(),this.listeners.clear()}publish(){let e=[...this.plugins.values()].flat().sort((e,t)=>e.order-t.order||(this.order.get(e.pluginId)??2**53-1)-(this.order.get(t.pluginId)??2**53-1));if(!(e.length===this.snapshot.length&&e.every((e,t)=>e===this.snapshot[t]))){this.snapshot=Object.freeze(e);for(let e of this.listeners)i(e)}}},X=e=>{throw new E(`GUI_PLUGIN_UNSUPPORTED`,`Unsupported GUI host API: ${e}`)};function Z(e,t){return new Proxy(t,{get:(t,n)=>n in t?Reflect.get(t,n):X(`${e}.${String(n)}`)})}var Q=e=>Object.freeze(e.map(e=>Object.freeze(e)));function Be(e,t){if(!e.fields||!t.fields)return!1;let n=Reflect.ownKeys(e.fields);return n.length===Reflect.ownKeys(t.fields).length&&n.every(n=>{let r=e.fields[n],i=t.fields[n];return i!==void 0&&`value`in r&&`value`in i&&Object.is(r.value,i.value)&&r.enumerable===i.enumerable&&r.configurable===i.configurable&&r.writable===i.writable})}function $(e,t){if(e){for(let n of e.owned??[])$(n,t);e.cleanups&&=e.cleanups.map(e=>()=>{try{Promise.resolve(e()).catch(t)}catch(e){t(e)}})}}var Ve=class{options;fileIcons=new de;appearanceCatalog=new le;workStatus=new ze;instances=new Map;listeners=new Set;panelMounts=new Set;fileViews=new Map;changes=u(0);views=u(0);session=u();currentPage=u();mobilePageNetworkReady=u(!1);appearance;layouts=new Map;files;storage;ended=!1;contracts=new Map;snapshot=Object.freeze({plugins:Object.freeze([]),commands:Object.freeze([]),titlebarItems:Object.freeze([]),panels:Object.freeze([]),pages:Object.freeze([]),settings:Object.freeze([]),menuItems:Object.freeze([]),activePanel:null});#e;viewExports;constructor(e){this.options=e,this.viewExports=new Ne(e.viewExport),this.appearance=u({locale:e.locale,mode:e.mode,narrow:e.narrow}),this.storage=new je(e.storage,e.transport);let t=()=>(this.session[0](),this.files?.api??X(`screen.file without a session`));this.#e=Z(`screen`,{get file(){return t()}})}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.snapshot;changed(e=!1){let t=this.snapshot;this.changes[1](e=>e+1),e&&t===this.snapshot&&this.publish()}setSession(e){if(this.ended)return;let t=this.session[0]();if(t?.id===e?.id&&t?.directory===e?.directory)return;if(!e)for(let e of[...this.panelMounts])e();this.files?.dispose(),this.files=e?new Ae(this.options.files,this.options.queryClient,this.options.transport,e.directory):void 0;let n=e?this.sessionReference(e):void 0,r=this.snapshot;this.session[1](n),r===this.snapshot&&this.publish()}sessionReference(e,t){let n=t?JSON.stringify(t.queryScope):this.options.transport,r=Z(`session.server`,{id:n,name:t?.location.hostId??this.options.transport,...t?{}:{client:this.options.client}});return Object.freeze(Z(`session`,{id:e.id,directory:e.directory,key:t?JSON.stringify([n,e.id]):`${this.options.transport}\n${e.id}`,tab:e.id,server:r,pending:!1,visit:{},location:t?Object.freeze({...t.location}):{directory:e.directory}}))}setAppearance(e){if(this.ended)return;let t=this.appearance[0]();(t.locale!==e.locale||t.mode!==e.mode||t.narrow!==e.narrow)&&this.appearance[1]({...e})}setPage(e){this.ended||this.currentPage[1](e)}setMobilePageNetworkReady(e){this.mobilePageNetworkReady[1](!this.ended&&e)}install(e,t,r){if(this.options.mobileNetworkRequired&&!this.mobilePageNetworkReady[0]()&&!this.ended)throw new E(`GUI_PLUGIN_UNAVAILABLE`,`Mobile plugin Relay is not ready`);let a=this.instances.get(e);if(this.ended||a?.status===`active`&&a.revision===t.revision&&a.native?.active!==!1){r?.dispose();return}a&&(this.instances.delete(e),this.release(a));let c={id:e,native:r,revision:t.revision,controller:new AbortController,status:`active`,cleanups:new Set,contributions:new Set,iconChanges:u(0),appearanceChanges:u(0),workStatusChanges:u(0),commands:[],titlebarItems:[],panels:[],pages:[],settings:[],menus:[]};this.instances.set(e,c);try{if(e===`yuri`||e.startsWith(`yuri.`))throw Error(`The yuri namespace is reserved to the host`);let a=ke(t.code,r?.activation.os);x(e=>{c.dispose=e,c.root=s(),b(()=>S(j.Provider,{value:c.context=this.context(c,a,t.options),get children(){c.owner=s();let e=i(()=>a.setup?.(c.context));if(typeof e==`function`)c.cleanups.add(()=>{Promise.resolve(e()).catch(e=>{c.error=String(e)})});else if(e!==void 0)throw e&&typeof e==`object`&&`then`in e&&Promise.resolve(e).catch(()=>{}),Error(`GUI setup must be synchronous and return only cleanup`);return null}}),e=>this.fail(c,e)),c.controller.signal.aborted||o(c.owner,()=>n(()=>{if(c.iconChanges[0](),!c.controller.signal.aborted)try{let e=[...c.contributions].filter(e=>e.registry===ce).map(e=>e.read()).filter(e=>e!==void 0);this.fileIcons.replace(c.id,e),c.iconError!==void 0&&i(()=>{c.iconError=void 0,this.publish()})}catch(e){i(()=>{this.fileIcons.remove(c.id),c.iconError=e instanceof Error?e.message:String(e),this.publish()})}})),c.controller.signal.aborted||o(c.owner,()=>n(()=>{if(c.appearanceChanges[0](),!c.controller.signal.aborted)try{let e=e=>[...c.contributions].filter(t=>t.registry===e).map(e=>e.read()).filter(e=>e!==void 0);this.appearanceCatalog.replace(c.id,e(fe),e(ue),c.native?.activation.capabilities?.dockIcon===!0)}catch(e){i(()=>this.fail(c,e))}})),c.controller.signal.aborted||o(c.owner,()=>n(()=>{if(c.workStatusChanges[0](),!c.controller.signal.aborted)try{let e=[...c.contributions].filter(e=>e.registry===Re).map(e=>e.read()).filter(e=>e!==void 0);this.workStatus.replace(c.id,c.revision,e)}catch(e){i(()=>this.fail(c,e))}})),c.controller.signal.aborted||o(c.owner,()=>n(()=>{this.changes[0](),this.session[0](),this.appearance[0]();try{this.derive(c)}catch(e){i(()=>this.fail(c,e))}i(()=>this.publish())}))})}catch(e){this.fail(c,e)}this.changed(!0)}release(e){e.controller.abort(),e.native?.dispose();for(let t of[...e.cleanups])try{t()}catch(t){e.error??=String(t)}e.cleanups.clear(),$(e.root,t=>{e.error??=String(t)});try{e.dispose?.()}catch(t){e.error??=String(t)}e.contributions.clear(),e.commands=[],e.titlebarItems=[],e.panels=[],e.pages=[],e.settings=[],e.menus=[],this.fileIcons.remove(e.id),this.appearanceCatalog.remove(e.id),this.workStatus.remove(e.id);for(let t of this.contracts.values())t.provider===e&&(t.provider=void 0,t.live[1]({status:`inactive`,reason:e.status===`failed`?`failed`:`disabled`}))}fail(e,t){e.status!==`failed`&&this.instances.get(e.id)===e&&(e.status=`failed`,e.error=t instanceof Error?t.message:String(t),t instanceof E&&(e.errorCode=t.code),this.release(e),this.publish())}uninstall(e){let t=this.instances.get(e);if(t){this.instances.delete(e),this.release(t);for(let t of this.layouts.values())t.open=t.open.filter(t=>!t.startsWith(`${e}:`)),t.active?.startsWith(`${e}:`)&&(t.active=null);this.changed(!0)}}dispose(){this.ended||(this.ended=!0,d(()=>{for(let e of[...this.instances.keys()])this.uninstall(e)}),this.viewExports.dispose(),this.files?.dispose(),this.fileIcons.dispose(),this.appearanceCatalog.dispose(),this.workStatus.dispose(),this.storage.dispose(),this.layouts.clear(),this.fileViews.clear(),this.contracts.clear(),this.listeners.clear())}async setDockIcon(e,t){let n=this.instances.get(e),r=n?.native;if(!r?.active||!r.activation.capabilities?.dockIcon)return X(`Dock icon`);try{await r.setDockIcon(t)}catch(e){throw t!==null&&n&&this.fail(n,e),e}}own(e,t){let n=!0,r=()=>{n&&(n=!1,e.cleanups.delete(r),t())};return e.controller.signal.aborted||a(F)?.ended?(r(),r):(e.cleanups.add(r),s()&&h(r),r)}list(e){this.changes[0]();let t=[];for(let n of this.instances.values())if(n.status===`active`){for(let r of n.contributions)if(r.registry===e.id){let e=r.read();e!==void 0&&t.push(e)}}return t}context(e,t,r){let o=this.storage.forPlugin(e.id,e.controller.signal),c=Object.fromEntries(Object.entries(t.stores??{}).map(([e,t])=>[e,t.scope===`global`?o.store(e,{...t,scope:`global`}):n=>o.store(e,{...t,scope:{session:n}})])),u=(e,n)=>{let r=this.appearance[0]().locale;return(t.i18n?.[r]?.[e]??t.i18n?.[r.split(`-`)[0]]?.[e]??t.i18n?.en?.[e]??e).replace(/\{\{(\w+)\}\}/g,(e,t)=>String(n?.[t]??e))},d=Z(`layout`,{narrow:()=>this.appearance[0]().narrow,ready:()=>!!this.session[0](),open:(t,n,r)=>{e.controller.signal.aborted||this.openPanel(t,n,r)},close:(t,n)=>{e.controller.signal.aborted||this.closeFor(t,n)},toggle:(e,t)=>d.state(e,t)===`visible`?d.close(e,t):d.open(e,t),hide:(t,n)=>{if(e.controller.signal.aborted)return;let r=this.layout(n);r.active===t&&r.shown&&(r.shown=!1,this.changed())},state:(e,t)=>{this.changes[0]();let n=this.layout(t);return n.active===e?n.shown?`visible`:`active`:n.open.includes(e)?`open`:`closed`},stored:t=>(this.changes[0](),this.layout(t).open.filter(t=>t.startsWith(`${e.id}:`)).map(t=>t.slice(e.id.length+1))),side:{opened:e=>(this.changes[0](),this.layout(e).shown),toggle:t=>{if(e.controller.signal.aborted)return;let n=this.layout(t);n.shown=!n.shown,this.changed()},menu:()=>this.list(N).filter(e=>e.menu===`session.panel`).sort((e,t)=>(e.order??0)-(t.order??0))},scroll:{get:(e,t)=>(this.changes[0](),this.layout(e).scroll.get(t)),set:(t,n,r)=>{if(e.controller.signal.aborted)return;let i=this.layout(t).scroll;if(!i.has(n)&&i.size>=128)throw Error(`GUI layout scroll limit exceeded`);i.set(n,{...r}),this.changed()}}}),f=Le(e.controller.signal),p=A(()=>e.controller.signal.aborted?{status:`inactive`,reason:`disabled`}:{status:`active`,generation:1,value:f}),m={open:t=>e.controller.signal.aborted||this.appearance[0]().narrow&&!this.mobilePageNetworkReady[0]()||!e.pages.some(e=>e.id===t)?!1:this.options.openPage?.(O(e.id,t))??!1,current:()=>{let t=this.currentPage[0]();return e.pages.find(n=>O(e.id,n.id)===t)?.id}},g=A(()=>e.controller.signal.aborted||!this.options.openPage||this.appearance[0]().narrow&&!this.mobilePageNetworkReady[0]()?{status:`inactive`,reason:`disabled`}:{status:`active`,generation:1,value:m});return Z(`ctx`,{id:e.id,options:r,signal:e.controller.signal,client:this.options.client,storage:o,stores:c,toast:Pe(e.controller.signal,this.options.toast),app:{name:`yuri`,version:e.native?.activation.app.version??``,channel:e.native?.activation.app.packaged?`prod`:`local`,platform:e.native?`desktop`:`web`,packaged:e.native?.activation.app.packaged??!1},desktop:e.native?Z(`desktop`,{os:e.native.activation.os}):void 0,t:u,plural:(e,t,n)=>{let r=`${e}.${new Intl.PluralRules(this.appearance[0]().locale).select(t)}`;return u(r,{...n,count:t})===r?u(`${e}.other`,{...n,count:t}):u(r,{...n,count:t})},add:(t,r)=>{if(e.controller.signal.aborted||a(F)?.ended)return()=>{};if([`server`,`composer-pill`,`slot`,`file.viewer`,`menubar-item`].includes(t.id)&&X(`registry.${t.id}`),e.contributions.size>=256)throw Error(`GUI contribution limit exceeded`);let o=()=>{},c,u=x(i=>{o=i,c=s();let a=()=>typeof r==`function`?r():r,u;if(t.id===`yuri.file-icon`){let e=l(()=>{try{return{ok:!0,value:a()}}catch(e){return{ok:!1,error:e}}});u=()=>{let t=e();if(!t.ok)throw t.error;return t.value}}else u=l(a);if(t.id===`style`){let t=document.createElement(`style`);t.dataset.yuriPluginStyle=e.id,document.head.append(t),h(()=>t.remove()),n(()=>{let e=u();t.textContent=e===void 0?``:String(e)})}return{registry:t.id,read:u}},s()??e.owner);e.contributions.add(u);let d=()=>{t.id===`yuri.file-icon`&&e.iconChanges[1](e=>e+1)},f=()=>{(t.id===`yuri.theme`||t.id===`yuri.branding`)&&e.appearanceChanges[1](e=>e+1)},p=()=>{t.id===`yuri.work-status`&&e.workStatusChanges[1](e=>e+1)};return i(d),i(f),i(p),i(()=>this.changed()),this.own(e,()=>{$(c,t=>{e.error??=String(t)}),o(),e.contributions.delete(u),i(d),i(f),i(p),i(()=>this.changed())})},list:e=>this.list(e),provide:(t,n)=>{if(e.controller.signal.aborted||a(F)?.ended)return()=>{};if(G(t.id)||t.id===`yuri.previewActions`||t.id===`yuri.pages`)throw Error(`Preview/export/page contracts are provided only by the Yuri host`);if(t.kind!==`contract`||!(t.id===e.id||t.id.startsWith(`${e.id}.`)))throw Error(`Contract must belong to the providing plugin`);let r=this.contract(t.id);if(r.provider)throw Error(`Contract already provided: ${t.id}`);return r.provider=e,r.live[1]({status:`active`,value:n,generation:++r.generation}),this.own(e,()=>{r.provider===e&&(r.provider=void 0,r.live[1]({status:`inactive`,reason:e.status===`failed`?`failed`:`disabled`}))})},use:t=>t.id===`yuri.pages`?t.kind===`contract`?g:X(`pages token must be a Contract`):t.id===`yuri.previewActions`?t.kind===`contract`?p:X(`preview actions token must be a Contract`):G(t.id)?t.kind===`contract`?this.viewExports.use(t.id,e.controller.signal):X(`export token must be a Contract`):t.kind===`ipc`&&e.native?e.native.token(t).live:this.contract(t.id,t.kind===`ipc`).live[0],main:t=>{if(!(t.id===e.id||t.id.startsWith(`${e.id}.`)))throw new E(`GUI_PLUGIN_FORBIDDEN`,`IPC must belong to the plugin`);return e.native?e.native.token(t).value:new Proxy({state:()=>void 0},{get:(e,t)=>t===`state`?e.state:t===`on`?()=>{throw new E(`GUI_PLUGIN_UNSUPPORTED`)}:()=>Promise.reject(new E(`GUI_PLUGIN_UNSUPPORTED`))})},sessions:{current:this.session[0],list:()=>{let e=this.session[0]();return e?[e]:[]}},screen:{current:()=>this.session[0]()?this.#e:void 0},layout:d,appearance:{mode:()=>this.appearance[0]().mode,font:()=>getComputedStyle(document.documentElement).getPropertyValue(`--font-mono`).trim()||`monospace`},locale:{locale:()=>this.appearance[0]().locale,direction:()=>/^(ar|fa|he|ur)(-|$)/i.test(this.appearance[0]().locale)?`rtl`:`ltr`},system:{copy:e=>navigator.clipboard.writeText(e),openExternal:e=>{let t=new URL(e);[`https:`,`http:`,`mailto:`].includes(t.protocol)||X(`system.openExternal protocol`),window.open(e,`_blank`,`noopener,noreferrer`)},save:Ie},commands:{run:t=>e.controller.signal.aborted||!this.command(t)?!1:(this.runCommand(t),!0)},links:{open:t=>!e.controller.signal.aborted&&this.navigateLink(e,t),exists:t=>i(()=>{if(e.controller.signal.aborted)return!1;let n=this.linkHandler(t);try{return Promise.resolve(n?.value.exists?.(t)??!1).catch(()=>!1)}catch{return!1}})}})}contract(e,t=!1){let n=this.contracts.get(e);if(!n){if(this.contracts.size>=256)throw Error(`GUI contract limit exceeded`);let t=u({status:`inactive`,reason:`disabled`});n={live:[A(t[0]),t[1]],generation:0},this.contracts.set(e,n)}return t&&n.provider&&X(`IPC contract collision`),n}derive(e){if(e.status!==`active`)return;let t=[],n=[],r=[],a=[],o=[],s=[],c=this.session[0]();for(let i of e.contributions){if([`yuri.file-icon`,`yuri.theme`,`yuri.branding`,`yuri.work-status`].includes(i.registry))continue;let l=i.read();if(l!==void 0){if(i.registry===`yuri.page`){let e=he(l);if(s.some(t=>t.id===e.id))throw Error(`Duplicate yuri.page id`);s.push(e)}else if(i.registry===we.id){let n=l;n.enabled!==!1&&t.push({key:`${e.id}.${n.id}`,pluginId:e.id,title:n.title,description:n.description,bind:n.bind,hidden:n.hidden,run:()=>this.invoke(e,()=>n.run())})}else if(i.registry===k.id){let t=l;o.push({key:JSON.stringify([e.id,t.id]),pluginId:e.id,label:t.label,title:t.title,icon:Me(t.icon),busy:t.busy,pressed:t.pressed,actionable:!!t.run,run:t.run})}else if(i.registry===Ee.id&&c){let t=l,r=`${e.id}:`,i=this.layout(c).open.filter(e=>e.startsWith(r)).map(e=>e.slice(r.length));for(let r of t.list({session:c,screen:this.#e,open:i}))n.push({plugin:e,panel:t,tab:r})}else if(i.registry===be.id){let e=l;(e.page||e.section)&&X(`SettingsPage host sections`),e.title,r.push(e)}else if(i.registry===N.id){let e=l;e.menu===`session.panel`?(e.title,a.push(e)):X(`MenuItem.${e.menu}`)}}}for(let e of n)e.tab.title;e.commands=t,e.titlebarItems=o,e.panels=n,e.pages=s,e.settings=r,e.menus=a,i(()=>this.views[1](e=>e+1))}publish(){let e=i(this.session[0]),t=e?this.layouts.get(e.key):void 0,n=[...this.instances.values()],r=n.filter(e=>e.status===`active`),a=r.flatMap(e=>e.panels.map(({tab:n})=>{let r=n.file?this.filePath(n.file):void 0;return{key:`${e.id}:${n.id}`,pluginId:e.id,title:n.title,file:r,inline:!!(r&&this.fileViews.has(r)),active:t?.shown===!0&&t.active===`${e.id}:${n.id}`}}));this.snapshot=Object.freeze({plugins:Q(n.map(({id:e,revision:t,status:n,error:r,errorCode:i,iconError:a})=>({id:e,revision:t,status:n,error:r??a,...i?{errorCode:i}:{}}))),commands:Q(r.flatMap(e=>e.commands.filter(e=>!e.hidden))),panels:Q(a),titlebarItems:Q(r.flatMap(e=>e.titlebarItems.map(({run:e,...t})=>t))),pages:Q(r.flatMap(e=>e.pages.map(t=>({key:O(e.id,t.id),pluginId:e.id,title:t.title,icon:t.icon})))),settings:Q(r.flatMap(e=>e.settings.map(t=>({key:`${e.id}:${t.id}`,pluginId:e.id,title:t.title})))),menuItems:Q(r.flatMap(e=>e.menus.map(t=>({key:`${e.id}:${t.id}`,pluginId:e.id,title:t.title,description:t.description,run:()=>{this.invoke(e,()=>t.run())}})))),activePanel:t?.shown&&a.some(e=>e.key===t.active)?t.active:null,sessionKey:e?.key});for(let e of this.listeners)e()}invoke(e,t){if(!e.controller.signal.aborted)try{let n=o(e.owner??null,t);if(n instanceof Promise)return n.catch(t=>this.fail(e,t))}catch(t){this.fail(e,t)}}command(e){return[...this.instances.values()].flatMap(e=>e.commands).find(t=>t.key===e)}runCommand(e){return this.command(e)?.run()}runTitlebarItem(e){for(let t of this.instances.values()){let n=t.titlebarItems.find(t=>t.key===e);if(n?.run&&!n.busy)return this.invoke(t,n.run)}}linkHandler(e){let t=[];for(let e of this.instances.values())for(let n of e.contributions)if(n.registry===ye.id){let r=n.read();r&&t.push({instance:e,value:r})}for(let n of t.sort((e,t)=>(t.value.priority??0)-(e.value.priority??0)))try{if(n.value.match(e))return n}catch(e){this.fail(n.instance,e)}}navigateLink(e,t){if(this.ended)return!1;let n=me(t.href);if(!n||!pe(n.path))return this.openLink(t);let r=this.session[0]();if(!r||t.session&&(t.session.key!==r.key||t.session.server.id!==r.server.id))return!1;if(!this.options.focusFile)return this.openLink(t);let i=w(t.base??r.directory,n.path),a=n.line===void 0?``:`:${n.line}${n.column===void 0?``:`:${n.column}`}`;return this.invoke(e,()=>this.options.focusFile(i+a,r.directory)),!0}openLink(e){if(this.ended)return!1;let t={...e,session:e.session??this.session[0]()},n=this.linkHandler(t);return n?(this.invoke(n.instance,()=>n.value.open(t)),!0):!1}filePath(e,t=this.session[0]()?.directory){let n=L(e);return/^(?:\/|[a-z]:\/)/i.test(n)||!t?n:L(`${t}/${n}`)}registerFileView(e,t){if(this.ended)return()=>{};let n=this.filePath(e,t),r=this.fileViews.get(n)??0;this.fileViews.set(n,r+1),r===0&&this.changed(!0);let i=!1;return()=>{if(i||this.ended)return;i=!0;let e=(this.fileViews.get(n)??1)-1;if(e){this.fileViews.set(n,e);return}{let e=this.session[0](),t=e&&this.layouts.get(e.key);t?.active&&this.snapshot.panels.some(e=>e.key===t.active&&e.file===n)&&(t.shown=!1),this.fileViews.delete(n)}this.changed(!0)}}filePanel(e,t){let n=this.filePath(e,t);return this.snapshot.panels.find(e=>e.file===n&&e.inline)}panelVisible(e){let t=this.session[0]();if(!t)return!1;let n=this.panel(e)?.tab.file;if(n&&this.fileViews.has(this.filePath(n)))return!0;let r=this.layouts.get(t.key);return!!(r?.shown&&r.active===e)}layout(e){let t=this.layouts.get(e.key);if(!t){if(this.layouts.size>=128)throw Error(`GUI session layout limit exceeded`);t={open:[],active:null,shown:!1,scroll:new Map},this.layouts.set(e.key,t)}return t}openPanel(e,t,n){if(this.ended)return;let r=this.layout(t),i=r.active,a=r.shown,o=r.open.length;if(!r.open.includes(e)){if(r.open.length>=64)throw Error(`GUI panel tab limit exceeded`);r.open=[...r.open,e]}n?.tab!==`append`&&(r.active=e,r.shown=!(this.appearance[0]().narrow&&n?.background)),(i!==r.active||a!==r.shown||o!==r.open.length)&&this.changed(!0);let s=this.panel(e);t.key===this.session[0]()?.key&&s&&n?.tab!==`append`&&this.invoke(s.plugin,()=>s.panel.focus?.({...this.props(e),restored:!1}))}selectPanel(e){let t=this.session[0]();t&&this.openPanel(e,t)}closeFor(e,t){let n=this.layout(t),r=t.key===this.session[0]()?.key?this.panel(e):void 0;if(!n.open.includes(e)||r?.tab.pinned||r?.tab.closable===!1)return;let i=this.session[0](),a=r&&i?{tab:r.tab,session:i,screen:this.#e}:void 0;n.open=n.open.filter(t=>t!==e),n.active===e&&(n.active=n.open.at(-1)??null),this.changed(!0),r&&a&&this.invoke(r.plugin,()=>r.panel.close?.(a))}closePanel(e){let t=this.session[0]();t&&this.closeFor(e,t)}hidePanel(){let e=this.session[0]();if(!e)return;let t=this.layout(e);t.shown&&(t.shown=!1,this.changed(!0))}panel(e){return[...this.instances.values()].flatMap(e=>e.panels).find(t=>`${t.plugin.id}:${t.tab.id}`===e)}props(e,t=!1){let n=this.panel(e)?.tab,r=()=>(this.views[0](),this.panel(e)?.tab??n??X(`panel no longer listed`)),i=t?l(()=>{let e=r();return{tab:e,fields:Object.getPrototypeOf(e)===Object.prototype?Object.getOwnPropertyDescriptors(e):void 0}},void 0,{equals:Be}):void 0,a=i?()=>i().tab:r,o=()=>this.session[0]()??X(`panel without session`);return{get tab(){return a()},get session(){return o()},screen:this.#e}}mountPanel(e,t,r){let a=this.panel(e);if(!a)return()=>{};let o=new AbortController,s=()=>{let s=l(()=>{this.session[0](),this.changes[0](),this.views[0]();let t=this.panel(e)?.tab.file;return t&&this.files&&this.panelVisible(e)?{model:this.files,file:t}:void 0},void 0,{equals:(e,t)=>e?.model===t?.model&&e?.file===t?.file});n(()=>{let e=s();e&&(h(e.model.watch(e.file)),e.model.sync(e.file).catch(()=>{}))});let c=()=>i(()=>a.panel.render(this.props(e,!0)));return S(K.Provider,{value:r?{plugin:a.plugin.controller.signal,signal:o.signal,content:t,target:r}:void 0,get children(){return c()}})},c=this.mount(a.plugin,t,()=>S(xe.Provider,{value:{visible:()=>(this.changes[0](),this.panelVisible(e)),present:()=>(this.changes[0](),this.panelVisible(e)),placement:()=>this.appearance[0]().narrow?`mobile`:`side`,reserve:()=>!1,animate:()=>!1,sidebar:Z(`panel.sidebar`,{}),open:()=>{let e=this.session[0]();return e?a.plugin.context.layout.stored(e):[]}},get children(){return s()}})),u=()=>{this.panelMounts.delete(u),o.abort(),c()};return this.panelMounts.add(u),this.own(a.plugin,u)}mountSettings(e,t){for(let n of this.instances.values()){let r=n.settings.find(t=>`${n.id}:${t.id}`===e);if(r)return this.mount(n,t,()=>r.render({}))}return()=>{}}mountPage(e,t){if(this.appearance[0]().narrow&&!this.mobilePageNetworkReady[0]())throw new E(`GUI_PLUGIN_UNAVAILABLE`,`Mobile page Relay is not ready`);for(let n of this.instances.values()){let r=n.pages.find(t=>O(n.id,t.id)===e);if(r)return this.mount(n,t,()=>r.render())}return()=>{}}mountWorkStatus(e,t,n){let r=this.instances.get(e.pluginId);if(!r||!this.workStatus.contains(e)||this.ended)return{update(){},dispose(){}};let i=Y(n,n.sessionId&&n.directory?this.sessionReference({id:n.sessionId,directory:n.directory},n.scope):void 0,n.scope?JSON.stringify(n.scope.queryScope):this.options.transport),a=()=>{},o=()=>{},s=this.own(r,()=>{i.dispose(),o(),a()});return o=this.workStatus.subscribe(()=>{this.workStatus.contains(e)||s()}),a=this.mount(r,t,()=>e.render(i.props)),i.props.signal.aborted&&(o(),a()),{update:e=>{if(!i.matches(e)){s();return}i.update(e)},dispose:s}}mount(e,t,n){if(e.controller.signal.aborted)return()=>{};let r=()=>{},a,o=t=>{queueMicrotask(()=>this.fail(e,t))};try{r=_e(()=>S(j.Provider,{value:e.context,get children(){return a=s(),b(()=>i(n),o)}}),t)}catch(t){this.fail(e,t)}return this.own(e,()=>{$(a,t=>{e.error??=String(t)}),r(),t.replaceChildren()})}};export{Ve as GuiPluginHost};
@@ -1 +1 @@
1
- import"./rolldown-runtime-hePW80VL.js";import{ot as e,st as t}from"./vendor-base-ui-z2M4boRm.js";import{n}from"./vendor-react-P8wFrkcT.js";import{Rn as r}from"./useMobileNavigationStore-D2FLOd1l.js";var i=n();t();var a=e();function o(e){let t=(0,i.c)(23),n,o,s,c,l,u;t[0]===e?(n=t[1],o=t[2],s=t[3],c=t[4],l=t[5],u=t[6]):({className:o,type:u,bordered:n,placeholder:c,endAdornment:s,...l}=e,t[0]=e,t[1]=n,t[2]=o,t[3]=s,t[4]=c,t[5]=l,t[6]=u);let d=c||` `,f=n!==void 0&&`border border-transparent ring-0 focus:ring-0 aria-invalid:ring-1 aria-invalid:focus:ring-1`,p=n&&`border-[var(--form-surface-border)]`,m=s&&`pe-11`,h;t[7]!==o||t[8]!==f||t[9]!==p||t[10]!==m?(h=r(`text-foreground file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground bg-[var(--surface-elevated)] appearance-none flex h-9 w-full min-w-0 rounded-lg px-3 py-1 typography-markdown outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:typography-ui-label file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:typography-ui-label`,`ring-1 ring-inset ring-border/60 transition duration-200 ease-out`,`hover:[&:not(:focus)]:bg-[var(--surface-subtle)] hover:[&:not(:focus)]:ring-transparent`,`focus:ring-2 focus:ring-[var(--interactive-focus-ring)] focus-visible:outline-none`,`aria-invalid:ring-[var(--status-error)] aria-invalid:focus:ring-[var(--status-error)]`,f,p,o,m),t[7]=o,t[8]=f,t[9]=p,t[10]=m,t[11]=h):h=t[11];let g;t[12]!==n||t[13]!==l||t[14]!==d||t[15]!==h||t[16]!==u?(g=(0,a.jsx)(`input`,{type:u,"data-slot":`input`,"data-bordered":n,placeholder:d,className:h,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,...l}),t[12]=n,t[13]=l,t[14]=d,t[15]=h,t[16]=u,t[17]=g):g=t[17];let _=g;if(!s)return _;let v;t[18]===s?v=t[19]:(v=(0,a.jsx)(`div`,{"data-slot":`input-end-adornment`,className:`absolute inset-y-0 end-0 flex items-center`,children:s}),t[18]=s,t[19]=v);let y;return t[20]!==_||t[21]!==v?(y=(0,a.jsxs)(`div`,{"data-slot":`input-wrapper`,className:`relative min-w-0 w-full flex-1`,children:[_,v]}),t[20]=_,t[21]=v,t[22]=y):y=t[22],y}export{o as t};
1
+ import"./rolldown-runtime-hePW80VL.js";import{ot as e,st as t}from"./vendor-base-ui-z2M4boRm.js";import{n}from"./vendor-react-P8wFrkcT.js";import{Rn as r}from"./useMobileNavigationStore-2N3dS8vX.js";var i=n();t();var a=e();function o(e){let t=(0,i.c)(23),n,o,s,c,l,u;t[0]===e?(n=t[1],o=t[2],s=t[3],c=t[4],l=t[5],u=t[6]):({className:o,type:u,bordered:n,placeholder:c,endAdornment:s,...l}=e,t[0]=e,t[1]=n,t[2]=o,t[3]=s,t[4]=c,t[5]=l,t[6]=u);let d=c||` `,f=n!==void 0&&`border border-transparent ring-0 focus:ring-0 aria-invalid:ring-1 aria-invalid:focus:ring-1`,p=n&&`border-[var(--form-surface-border)]`,m=s&&`pe-11`,h;t[7]!==o||t[8]!==f||t[9]!==p||t[10]!==m?(h=r(`text-foreground file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground bg-[var(--surface-elevated)] appearance-none flex h-9 w-full min-w-0 rounded-lg px-3 py-1 typography-markdown outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:typography-ui-label file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:typography-ui-label`,`ring-1 ring-inset ring-border/60 transition duration-200 ease-out`,`hover:[&:not(:focus)]:bg-[var(--surface-subtle)] hover:[&:not(:focus)]:ring-transparent`,`focus:ring-2 focus:ring-[var(--interactive-focus-ring)] focus-visible:outline-none`,`aria-invalid:ring-[var(--status-error)] aria-invalid:focus:ring-[var(--status-error)]`,f,p,o,m),t[7]=o,t[8]=f,t[9]=p,t[10]=m,t[11]=h):h=t[11];let g;t[12]!==n||t[13]!==l||t[14]!==d||t[15]!==h||t[16]!==u?(g=(0,a.jsx)(`input`,{type:u,"data-slot":`input`,"data-bordered":n,placeholder:d,className:h,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,...l}),t[12]=n,t[13]=l,t[14]=d,t[15]=h,t[16]=u,t[17]=g):g=t[17];let _=g;if(!s)return _;let v;t[18]===s?v=t[19]:(v=(0,a.jsx)(`div`,{"data-slot":`input-end-adornment`,className:`absolute inset-y-0 end-0 flex items-center`,children:s}),t[18]=s,t[19]=v);let y;return t[20]!==_||t[21]!==v?(y=(0,a.jsxs)(`div`,{"data-slot":`input-wrapper`,className:`relative min-w-0 w-full flex-1`,children:[_,v]}),t[20]=_,t[21]=v,t[22]=y):y=t[22],y}export{o as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n}from"./runtime-switch-BMjl5Y5W.js";import{R as r,l as i,u as a}from"./platform-wF65ZFgV.js";import{a as o,i as s,r as c}from"./vendor-zustand-Cwko4FG1.js";import{ot as l,st as u}from"./vendor-base-ui-z2M4boRm.js";import{St as d,an as f,jt as p,on as m}from"./gitApiHttp-B0FJaIhU.js";import{t as h}from"./safeStorage-DTOhKN0V.js";import{i as g,t as _}from"./vendor-pathe-vBmvQE8f.js";import{n as v}from"./vendor-react-P8wFrkcT.js";import{s as y,u as b}from"./vendor-tanstack-react-query-B-KblYBV.js";import{E as x}from"./runtime-file-resource-CuLP3xp7.js";import{o as S}from"./path-utils-jGozTg9d.js";import{r as C}from"./vendor-reactuses-core-Dyjw5sZR.js";import{r as w}from"./useUIStore-Cfmg-aDQ.js";import{t as T}from"./i18n-qHllte6P.js";import{Ba as E,Fa as ee,Gn as D,Jn as O,R as k,Rn as A,Sa as te,Va as j,Xi as M,Xn as N,da as ne,di as P,lt as re,p as F,v as I,vi as L,x as ie,yt as ae}from"./useMobileNavigationStore-D2FLOd1l.js";import{s as oe}from"./remoteProjectQueries-Dfms-cCx.js";import{a as se,g as ce,o as le,p as ue,s as de}from"./fileMentionAutocompleteState-BZJqfgae.js";import{t as fe}from"./AgentAvatar-BwB9S5gR.js";import{n as R}from"./Icon-CbRhi6Fu.js";import{l as pe,s as me}from"./gitApi-Bxuv7iZR.js";import{c as he,d as ge,l as _e,n as ve,r as ye,t as be}from"./fileMentionTouchSelection-YTaXrwGt.js";import{n as xe}from"./textarea-BPhvk5Vd.js";import{f as Se,o as Ce}from"./projectMeta--OgVpG4Z.js";var z=(e,t)=>{let n=t.trim();if(!n)return[...e].sort((e,t)=>e.isBuiltIn===t.isBuiltIn?e.name.localeCompare(t.name):e.isBuiltIn?-1:1);let r=ce([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.isBuiltIn===t.item.isBuiltIn?e.item.name.localeCompare(t.item.name):e.item.isBuiltIn?-1:1:e.score-t.score),r.map(e=>e.item)},B=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>{let r=t[n];return r!=null&&e.id===r.id&&e.title===r.title&&(e.subtitle??``)===(r.subtitle??``)&&(e.badge??``)===(r.badge??``)&&e.iconName===r.iconName&&e.agentName===r.agentName}),V=(e,t)=>e.highlightedIndex===t.highlightedIndex&&B(e.rows,t.rows),we=(e,t)=>B(e,t)?e:t.slice(),Te=(e,t,n)=>{e&&(t.current&&V(t.current,n)||(t.current=n,e(n)))},Ee=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},H=e(u(),1),U=v(),De=e=>e.directories.flatMap(e=>e.sessions),Oe=(e,t)=>({...oe(e,t.location.hostId),select:De}),ke=async(e,t,n)=>{n.sdk();let r=await e.fetchQuery(Oe(t,n));return n.sdk(),De(r)},Ae=(e,t,n,r)=>{n.sdk();let i=e.getQueryData(Oe(t,n).queryKey);for(let e of i?.directories??[]){let t=e.sessions.find(e=>e.id===r);if(t)return t.title||r}return r},je=(e,t,n,r={})=>({queryKey:[...e.queryScope,`composer-files`,t,n,r],staleTime:3e4,gcTime:3e4,queryFn:async({signal:i})=>{let a=await e.sdk().file.find({query:t,location:{directory:e.location.directory},limit:n,type:r.type},{signal:i});if(e.sdk(),i.throwIfAborted(),!Array.isArray(a.data))throw Error(`File search returned no data`);return a.data.map(t=>{let n=g(t.path),r=_(n);return{name:r,path:S(e.location.directory,n),relativePath:n,extension:r.includes(`.`)?r.split(`.`).pop()?.toLowerCase():void 0,isDirectory:t.type===`directory`}})}}),W=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+/g,`/`);n&&!r.startsWith(`//`)&&(r=`/${r}`);let i=r===`/`,a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,``)),r},G=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,K=e=>e.startsWith(`yuri-remote-location:`)?i(e):W(e),q=(e,t)=>{let n=W(a(t,`local`).directory),r=W(e);if(!n||!r)return!1;let i=G(n),o=G(r);return o===i||o.startsWith(i.endsWith(`/`)?i:`${i}/`)},Me=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t;try{t=K(e)}catch{continue}if(!t||!r||typeof r!=`object`)continue;let i=r,a=Array.isArray(i.openPaths)?Array.from(new Set(i.openPaths.filter(e=>typeof e==`string`).map(e=>W(e)).filter(e=>q(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>W(e)).filter(e=>q(e,t)))):[],s=typeof i.selectedPath==`string`?W(i.selectedPath):null,c=s&&q(s,t)?s:a[0]??null,l=typeof i.touchedAt==`number`&&Number.isFinite(i.touchedAt)?i.touchedAt:Date.now(),u=n[t];if(u){let e=Array.from(new Set([...u.openPaths,...a])),r=Array.from(new Set([...u.expandedPaths,...o])),i=u.selectedPath??c??e[0]??null;n[t]={openPaths:e,selectedPath:i,expandedPaths:r,touchedAt:Math.max(u.touchedAt,l)};continue}n[t]={openPaths:a,selectedPath:c,expandedPaths:o,touchedAt:l}}return n},J=(e,t)=>{let n=Object.entries(e);if(n.length<=t)return e;n.sort((e,t)=>(t[1]?.touchedAt??0)-(e[1]?.touchedAt??0));let r={};for(let[e,i]of n.slice(0,t))r[e]=i;return r},Y=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},Ne=o()(c(s((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=K((t||``).trim()),a=W((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!q(a,i)||e(e=>{let t=e.byRoot[i],n=Y(t),r=n.openPaths.includes(a),o=r?n.openPaths:[...n.openPaths,a],s=n.selectedPath??a;return t&&r&&t.selectedPath===s?e:{byRoot:J({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=K((t||``).trim()),i=W((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=G(i),a=e=>G(e)===n,o=t.selectedPath?a(t.selectedPath):!1;if(!t.openPaths.some(a)&&!o)return e;let s=t.openPaths.filter(e=>!a(e)),c=o?s[0]??null:t.selectedPath;return{byRoot:J({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=K((t||``).trim()),i=W((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=G(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=G(e);return t===n||t.startsWith(a)},s=t.openPaths.filter(e=>!o(e));if(s.length===t.openPaths.length)return e;let c=t.selectedPath&&o(t.selectedPath)?s[0]??null:t.selectedPath;return{byRoot:J({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=K((t||``).trim()),i=W((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=G(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=G(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:J({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=K((t||``).trim()),a=n?W(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!q(a,i)||e(e=>{let t=e.byRoot[i],n=Y(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:J({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=K((e||``).trim());if(!n)return;let r=t().byRoot[n];if(!r||r.selectedPath)return;let i=r.openPaths[0]??null;i&&t().setSelectedPath(n,i)},toggleExpandedPath:(t,n)=>{let r=K((t||``).trim()),i=W((n||``).trim());!r||!i||!q(i,r)||e(e=>{let t=e.byRoot[r],n=Y(t),a=n.expandedPaths.includes(i)?n.expandedPaths.filter(e=>e!==i):[...n.expandedPaths,i];return t&&t.expandedPaths===a&&t.selectedPath===n.selectedPath&&t.openPaths===n.openPaths?e:{byRoot:J({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=K((t||``).trim()),i=W((n||``).trim());!r||!i||!q(i,r)||e(e=>{let t=e.byRoot[r],n=Y(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:J({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=K((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>W((e||``).trim())).filter(e=>e&&q(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=Y(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:J({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:h(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:Me(t)}},merge:(e,t)=>({...t,byRoot:Me(e&&typeof e==`object`?e.byRoot:void 0)}),partialize:e=>({byRoot:Me(e.byRoot)})}),{name:`files-view-tabs-store`})),Pe=(e,t)=>{let n=(0,U.c)(4),r=t===void 0?200:t,[i,a]=H.useState(e),o,s;return n[0]!==r||n[1]!==e?(o=()=>{let t=window.setTimeout(()=>{a(e)},r);return()=>{window.clearTimeout(t)}},s=[e,r],n[0]=r,n[1]=e,n[2]=o,n[3]=s):(o=n[2],s=n[3]),H.useEffect(o,s),i},Fe=()=>{let e=(0,U.c)(17),t=F(Ie),n=ae(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=ie(r),a=F(Le),o=F(Re),s=j(ze),c=j(Be),l=d(Ve);if(t){let r;e[2]===i?r=e[3]:(r=I(i),e[2]=i,e[3]=r);let o=r;if(o)return o;let s;e[4]!==t||e[5]!==a?(s=a.get(t),e[4]=t,e[5]=a,e[6]=s):s=e[6];let c=s;if(c?.path)return c.path;let l;if(e[7]!==t||e[8]!==n){let r;e[10]===t?r=e[11]:(r=e=>e.id===t,e[10]=t,e[11]=r),l=n.find(r),e[7]=t,e[8]=n,e[9]=l}else l=e[9];let u=l;if(u?.directory)return u.directory}if(o?.open&&(o.bootstrapPendingDirectory||o.directoryOverride))return(o.bootstrapPendingDirectory||o.directoryOverride)??void 0;if(s){let t;if(e[12]!==s||e[13]!==c){let n;e[15]===s?n=e[16]:(n=e=>e.id===s,e[15]=s,e[16]=n),t=c.find(n),e[12]=s,e[13]=c,e[14]=t}else t=e[14];let n=t;if(n?.path)return n.path}return l??void 0};function Ie(e){return e.currentSessionId}function Le(e){return e.worktreeMetadata}function Re(e){return e.newSessionDraft}function ze(e){return e.activeProjectId}function Be(e){return e.projects}function Ve(e){return e.currentDirectory}var X=l(),He=`bg-transparent font-[inherit] text-[var(--primary-base)]`,Ue=(e,t)=>{let n=t.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase();if(!r.includes(n))return e;let i=[],a=0,o=r.indexOf(n);for(;o!==-1;)o>a&&i.push(e.slice(a,o)),i.push((0,X.jsx)(`mark`,{className:He,children:e.slice(o,o+n.length)},`${o}-${n}`)),a=o+n.length,o=r.indexOf(n,a);return a<e.length&&i.push(e.slice(a)),i},We=H.forwardRef((e,t)=>{let n=(0,U.c)(4),r=x(),i;return n[0]!==r||n[1]!==e||n[2]!==t?(i=r?.entry.location.hostId?(0,X.jsx)(Je,{...e,ref:t,entry:r.entry,registry:r.registry},JSON.stringify(r.entry.queryScope)):(0,X.jsx)(Ge,{...e,ref:t}),n[0]=r,n[1]=e,n[2]=t,n[3]=i):i=n[3],i}),Ge=H.forwardRef((e,t)=>{let n=(0,U.c)(22),r=Fe()??``,i=F(Xe),a=L(Ze),o=!!e.onSessionSelect,s;n[0]===o?s=n[1]:(s={enabled:o},n[0]=o,n[1]=s);let c=k(s),l=j(Qe),u=j($e),d;if(n[2]!==l||n[3]!==r||n[4]!==u){let e=u.find(e=>e.id===l)?.path||r;d=e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null,n[2]=l,n[3]=r,n[4]=u,n[5]=d}else d=n[5];let f=d,m;n[6]===f?m=n[7]:(m=e=>f?e.byRoot[f]:void 0,n[6]=f,n[7]=m);let h=Ne(m),g=M(et),_=p(tt),v;n[8]!==a||n[9]!==c||n[10]!==e.onSessionSelect?(v=e.onSessionSelect?P(a,c):[],n[8]=a,n[9]=c,n[10]=e.onSessionSelect,n[11]=v):v=n[11];let y=v,b=e.currentSessionId??i,x;return n[12]!==g||n[13]!==r||n[14]!==f||n[15]!==h||n[16]!==e||n[17]!==t||n[18]!==_||n[19]!==y||n[20]!==b?(x=(0,X.jsx)(Ye,{...e,ref:t,currentDirectory:r,currentSessionId:b,projectRoot:f,projectTabs:h,agentCatalog:g,sessions:y,searchFiles:_}),n[12]=g,n[13]=r,n[14]=f,n[15]=h,n[16]=e,n[17]=t,n[18]=_,n[19]=y,n[20]=b,n[21]=x):x=n[21],x}),Ke=[],qe=[],Je=H.forwardRef((e,t)=>{let n=(0,U.c)(32),{entry:r,registry:i}=e,a=b(),o;n[0]===r?o=n[1]:(o=ee(r.location.directory,void 0,r),n[0]=r,n[1]=o);let s=!!e.onAgentSelect,c;n[2]!==o||n[3]!==s?(c={...o,enabled:s},n[2]=o,n[3]=s,n[4]=c):c=n[4];let l=y(c),u;n[5]!==r||n[6]!==i?(u=Oe(i,r),n[5]=r,n[6]=i,n[7]=u):u=n[7];let d=!!e.onSessionSelect,f;n[8]!==u||n[9]!==d?(f={...u,enabled:d},n[8]=u,n[9]=d,n[10]=f):f=n[10];let p=y(f),m;n[11]===r.key?m=n[12]:(m=e=>e.byRoot[r.key],n[11]=r.key,n[12]=m);let h=Ne(m),g;n[13]!==a||n[14]!==r?(g=(e,t,n,i)=>{let o=n===void 0?60:n;return a.fetchQuery(je(r,t,o,i))},n[13]=a,n[14]=r,n[15]=g):g=n[15];let _=C(g),v=r.location.directory,x;if(n[16]!==r.location.directory){let e;n[18]===Symbol.for(`react.memo_cache_sentinel`)?(e=/\/+$/,n[18]=e):e=n[18],x=r.location.directory.replace(/\\/g,`/`).replace(e,``),n[16]=r.location.directory,n[17]=x}else x=n[17];let S=l.data??qe,w=p.data??Ke,T=l.error??p.error,E;n[19]===r?E=n[20]:(E=()=>{r.sdk()},n[19]=r,n[20]=E);let D;return n[21]!==r.location.directory||n[22]!==h||n[23]!==e||n[24]!==t||n[25]!==_||n[26]!==S||n[27]!==w||n[28]!==T||n[29]!==E||n[30]!==x?(D=(0,X.jsx)(Ye,{...e,ref:t,currentDirectory:v,projectRoot:x,projectTabs:h,agentCatalog:S,sessions:w,searchFiles:_,catalogError:T,assertCurrent:E}),n[21]=r.location.directory,n[22]=h,n[23]=e,n[24]=t,n[25]=_,n[26]=S,n[27]=w,n[28]=T,n[29]=E,n[30]=x,n[31]=D):D=n[31],D}),Ye=H.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:i,onClose:a,style:o,onRowsChange:s,currentDirectory:c,currentSessionId:l,projectRoot:u,projectTabs:d,agentCatalog:p,sessions:h,searchFiles:g,catalogError:_,assertCurrent:v},y)=>{let{t:b}=T(),x=Pe(e,180),S=m(),E=f(),[ee,O]=H.useState([]),[k,j]=H.useState(!1),[M,N]=H.useState(null),[P,re]=H.useState(0),F=H.useRef(0),I=H.useRef({query:e,directory:c,ids:[]}),[L,ie]=H.useState(360),[ae,oe]=H.useState({}),[ce,pe]=H.useState({}),me=H.useRef([]),ge=H.useRef([]),_e=H.useRef([]),Se=H.useRef(null),Ce=H.useRef(null),z=H.useRef(null);z.current||=be();let B=w(e=>e.isMobile),V=(e??``).trim(),we=te({directory:c||null}),U=H.useMemo(()=>r?we.data??[]:[],[r,we.data]),De=H.useMemo(()=>{if(!u||!d)return[];let e=[d.selectedPath,...d.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=[];for(let r of e){if(t.has(r))continue;t.add(r);let e=r.replace(/\\/g,`/`),i=e.split(`/`).filter(Boolean).pop()||e,a=e.startsWith(`${u}/`)?e.slice(u.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return de(n,V,{limit:6})},[V,u,d]),Oe=H.useMemo(()=>n?ne(p).filter(e=>e.mode!==`primary`):[],[p,n]),ke=H.useMemo(()=>i?se({sessions:h,currentSessionId:l??null,searchQuery:V}):[],[h,l,V,i]),Ae=De,je=ee,W=H.useMemo(()=>he({skills:U,agents:Oe,sessions:ke,recentFiles:Ae,pathHits:je,searchQuery:V,untitledSession:b(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:b(`chat.fileMentionAutocomplete.sessionType`),skillBadge:b(`chat.commandAutocomplete.badge.skill`)}),[U,Oe,ke,Ae,je,V,b]);H.useEffect(()=>{let e=e=>{let t=e.target;!t||!Se.current||Se.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),H.useEffect(()=>{if(!c){O([]),j(!1),N(null);return}let e=(x??``).trim(),t=ue(e);if(!t){O([]),j(!1),N(null);return}let n=!1;j(!0),N(null);let r={includeHidden:S,respectGitignore:!E};return Promise.all([g(c,t,80,{...r,type:`file`}),g(c,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(De.map(e=>e.path));O(le({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(e=>{n||N(e instanceof Error?e:Error(String(e)))}).finally(()=>{n||j(!1)}),()=>{n=!0}},[c,x,De,g,S,E]),H.useLayoutEffect(()=>{let t=I.current,n=t.ids[F.current],r=t.query===e&&t.directory===c?Math.max(0,W.findIndex(e=>e.id===n)):0;I.current={query:e,directory:c,ids:W.map(e=>e.id)},F.current=r,re(r)},[W,e,c]),H.useEffect(()=>{oe({}),pe({})},[W]),H.useEffect(()=>{me.current[P]?.scrollIntoView({block:`nearest`})},[P]),H.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};ge.current.forEach((n,r)=>{if(!n)return;let i=_e.current[r]?.offsetWidth??n.scrollWidth,a=Math.max(0,i-n.clientWidth),o=a>8;if(e[r]=o,o){let e=Math.max(.6,a/110);t[r]=e}}),oe(e),pe(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[W]),H.useEffect(()=>{let e=ge.current[P];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&ie(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[P]);let G=C(e=>{t(e)}),K=C(e=>{n?.(e)}),q=C(e=>{i?.(e)}),Me=C(e=>{r?.(e)}),J=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&z.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&z.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(z.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>z.current?.pointerCancel(),onClick:()=>{z.current?.click(t)},onMouseMove:()=>{F.current=e,re(e)}}),Y=e=>{try{v?.()}catch(e){N(e instanceof Error?e:Error(String(e)));return}let t=W.length;if(t===0)return;let n=(e%t+t)%t,r=W[n];if(r.agentName!==void 0){K(r.agentName);return}if(r.id.startsWith(`skill:`)){let e=U.find(e=>r.id===`skill:${e.name}-${e.scope}`);e&&Me(e);return}if(r.id.startsWith(`session:`)){let e=ke.find(e=>r.id===`session:${e.id}`);e&&q(e);return}let i=r.id.startsWith(`recent:`)?Ae.find(e=>r.id===`recent:${e.path}`):je.find(e=>r.id===`file:${e.path}`);i&&G(i)};H.useEffect(()=>{Te(s,Ce,{rows:W,highlightedIndex:P})},[s,P,W]);let Ne=H.useRef(s);return Ne.current=s,H.useEffect(()=>()=>{Ee(Ne.current,Ce)},[]),H.useImperativeHandle(y,()=>({acceptIndex:e=>{Y(e)},handleKeyDown:e=>{if(e===`Escape`){a();return}let t=W.length;if(t!==0){if(e===`ArrowDown`){F.current=(F.current+1)%t,re(F.current);return}if(e===`ArrowUp`){F.current=(F.current-1+t)%t,re(F.current);return}(e===`Enter`||e===`Tab`)&&Y(F.current)}}})),(0,X.jsxs)(ve,{ref:Se,isMobile:B,className:`max-w-[640px] max-h-64`,style:o,children:[(0,X.jsx)(xe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,X.jsxs)(`div`,{className:`py-1`,children:[_||we.error||M?(0,X.jsx)(`div`,{role:`alert`,className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:(_??we.error??M)?.message}):null,W.map((e,t)=>{let n=e.id.startsWith(`file:`)||e.id.startsWith(`recent:`),r=n?D(e.title,{maxLength:60}):e.title,i=P===t,a=ae[t]??!1,o=ce[t]??2.6;return(0,X.jsxs)(`div`,{"data-mention-id":e.id,ref:e=>{me.current[t]=e},className:A(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,B&&`min-h-11`,ye(B,i),!B&&i&&`text-interactive-selection-foreground`),...J(t,()=>Y(t)),children:[(0,X.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center`,children:e.agentName===void 0?(0,X.jsx)(R,{name:e.iconName,className:`size-3.5 text-current`}):(0,X.jsx)(fe,{name:e.agentName,size:20})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,X.jsxs)(`span`,{ref:e=>{ge.current[t]=e},className:A(`relative block min-w-0 overflow-hidden`,n&&a&&i&&`file-mention-marquee-container`),style:i?{"--file-mention-marquee-width":`${L}px`,"--file-mention-marquee-duration":`${o}s`}:void 0,title:e.title,children:[(0,X.jsx)(`span`,{ref:e=>{_e.current[t]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:e.title}),n&&a&&i?(0,X.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Ue(e.title,V)}):(0,X.jsx)(`span`,{className:`block truncate`,children:Ue(r,V)})]}),e.trailingLabel?(0,X.jsx)(`span`,{className:A(`max-w-[40%] shrink-0 truncate text-muted-foreground`,B?`typography-micro`:`typography-meta`),children:e.trailingLabel}):null]}),e.subtitle?(0,X.jsx)(`div`,{className:A(`truncate text-muted-foreground`,B?`typography-micro`:`typography-meta`),children:Ue(e.subtitle,V)}):null]})]},e.id)}),k&&je.length===0?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,X.jsx)(R,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!k&&W.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:b(`chat.fileMentionAutocomplete.empty`)})]})}),!B&&(0,X.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:b(`chat.autocomplete.keyboardHint`)})]})});function Xe(e){return e.currentSessionId}function Ze(e){return e.activeSessions}function Qe(e){return e.activeProjectId}function $e(e){return e.projects}function et(e){return e.agents}function tt(e){return e.searchFiles}var nt=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`btw`]),rt=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&nt.has(n))},it=(e,t)=>!e||t({name:e}),at=` `,ot=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=n;for(;r>0&&!/\s/.test(e[r-1]);)--r;return r>=2&&e[r-1]===at&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},st=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,ct=A(st,`bg-[color-mix(in_srgb,var(--primary-base)_12%,transparent)] text-[color-mix(in_srgb,var(--primary-base)_70%,transparent)] border-[color-mix(in_srgb,var(--primary-base)_24%,transparent)]`),lt=A(st,`bg-[color-mix(in_srgb,var(--status-success)_12%,transparent)] text-[color-mix(in_srgb,var(--status-success)_70%,transparent)] border-[color-mix(in_srgb,var(--status-success)_24%,transparent)]`),ut=A(st,`bg-[color-mix(in_srgb,var(--status-info)_12%,transparent)] text-[color-mix(in_srgb,var(--status-info)_70%,transparent)] border-[color-mix(in_srgb,var(--status-info)_24%,transparent)]`),dt=A(st,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),ft=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),pt=e=>{let t=!!e.sessionID;return{hasSession:t,canStartSessionCommand:t||e.hasNewDraft}},mt=H.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:i,style:a,commandPolicy:o,commandContext:s,onRowsChange:c},l)=>{let{t:u}=T(),d=w(e=>e.isMobile),f=F(e=>e.currentSessionId),p=F(e=>!!e.newSessionDraft?.open),m=F(H.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=re(f??``,m??void 0),g=H.useMemo(()=>s??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[s,f,h.length,p]),{hasSession:_,canStartSessionCommand:v}=H.useMemo(()=>pt(g),[g]),y=g.hasMessages,[b,x]=H.useState([]),[S,C]=H.useState(!1),ee=E({directory:i}),D=H.useMemo(()=>ee.data??[],[ee.data]),O=ee.isFetching,[k,te]=H.useState(0),j=H.useRef(0),M=H.useRef(!1),N=H.useRef([]),ne=H.useRef(null),P=H.useRef(!1),I=H.useRef(null),L=H.useRef(!1),ie=H.useRef(null);H.useEffect(()=>{let e=e=>{let t=e.target;!t||!ne.current||ne.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),H.useEffect(()=>{(async()=>{C(O);try{let t=D.flatMap((e,t)=>e.source===`skill`?[]:[{id:`opencode:${e.scope??`global`}:${e.name}:${e.agent??``}:${e.model??``}:${t}`,name:e.name,source:`opencode`,description:e.description,agent:e.agent??void 0,model:e.model??void 0,isBuiltIn:e.isBuiltIn,scope:e.scope,reference:e.reference}]),n=[{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!y?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:btw`,name:`btw`,source:`yuri`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`yuri:undo`,name:`undo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`yuri:redo`,name:`redo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`yuri:fork`,name:`fork`,source:`yuri`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`yuri:timeline`,name:`timeline`,source:`yuri`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`yuri:model`,name:`model`,source:`yuri`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`yuri:compact`,name:`compact`,source:`yuri`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...r()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...v?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...v?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...v?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...v?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...v?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[],...t],i=!y,a=z(n.filter(e=>(i||e.name!==`init`)&&(o?.(e)??!0)),e);x(e=>ft(e,a)?e:a)}catch{let t=!y,n=z([{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!y?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:btw`,name:`btw`,source:`yuri`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`yuri:undo`,name:`undo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`yuri:redo`,name:`redo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`yuri:fork`,name:`fork`,source:`yuri`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`yuri:timeline`,name:`timeline`,source:`yuri`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`yuri:model`,name:`model`,source:`yuri`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`yuri:compact`,name:`compact`,source:`yuri`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...r()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...v?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...v?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...v?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...v?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...v?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(o?.(e)??!0)),e);x(e=>ft(e,n)?e:n)}finally{C(!1)}})()},[e,y,_,v,D,O,u,o]),H.useEffect(()=>{te(0)},[b]),H.useEffect(()=>{j.current=k},[k]),H.useEffect(()=>{N.current[k]?.scrollIntoView({block:`nearest`})},[k]),H.useEffect(()=>{Te(c,ie,{rows:_e(b,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:k})},[b,c,k,u]);let ae=H.useRef(c);ae.current=c,H.useEffect(()=>()=>{Ee(ae.current,ie)},[]),H.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=b[e];r&&t(r,rt(r,n))},handleKeyDown:e=>{let r=b.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){M.current=!0,te(e=>(e+1)%r);return}if(e===`ArrowUp`){M.current=!0,te(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(j.current%r+r)%r,i=b[n];i&&t(i,rt(i,e===`Enter`))}}}}),[b,n,t]);let oe=e=>{let t=ge(e);switch(e.name){case`new`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,X.jsxs)(ve,{ref:ne,isMobile:d,className:`max-w-[450px] max-h-64`,style:a,children:[(0,X.jsx)(xe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:S?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,X.jsx)(R,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,X.jsxs)(`div`,{children:[b.map((n,r)=>{let i=n.isBuiltIn,a=n.isYuri;return(0,X.jsxs)(`div`,{ref:e=>{N.current[r]=e},className:A(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,ye(d,r===k),!d&&r===k&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(I.current={x:e.clientX,y:e.clientY},L.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!I.current)return;let t=e.clientX-I.current.x,n=e.clientY-I.current.y;Math.hypot(t,n)>6&&(L.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=L.current;I.current=null,L.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),P.current=!0,t(n,rt(n,d)))},onPointerCancel:()=>{I.current=null,L.current=!1},onClick:()=>{if(P.current){P.current=!1;return}t(n,rt(n,d))},onMouseMove:()=>{M.current=!1,te(r)},children:[(0,X.jsx)(`div`,{className:A(!d&&`mt-0.5`),children:oe(n)}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,Ue(n.name,e)]}),n.isSkill?(0,X.jsx)(`span`,{className:ct,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,X.jsx)(`span`,{className:ct,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,X.jsx)(`span`,{className:dt,children:`Yuri`}):i?(0,X.jsx)(`span`,{className:dt,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,X.jsx)(`span`,{className:n.scope===`project`?ut:lt,children:n.scope}):null,n.agent&&(0,X.jsx)(`span`,{className:dt,children:n.agent})]}),n.description&&!d&&(0,X.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Ue(n.description,e)})]})]},n.id)}),b.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,X.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});mt.displayName=`CommandAutocomplete`;var ht=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,gt=1e4,_t=6e4,vt=5e3,yt=3e4,bt=6e4,xt=25,St=40,Ct=2,wt=15e3,Tt=500,Et=30,Dt=20971520,Ot=new Map,kt=new Map,At=new Map,jt=new Map,Mt=new Map,Nt=new Map,Pt=new WeakMap,Ft=e=>{let t=Pt.get(e);return t||(t=new Set(e.files.map(e=>e.path)),Pt.set(e,t)),t},It=(e,t)=>`${t}:${e}`,Lt=e=>kt.get(e)??0,Rt=e=>{let t=Lt(e)+1;return kt.set(e,t),t},zt=e=>{let t=(At.get(e)??0)+1;return At.set(e,t),t},Bt=e=>{let t=Ot.get(e);if(t)return t;let n=new Set;return Ot.set(e,n),n},Z=()=>({isGitRepo:null,status:null,branches:null,branchesTransportIdentity:null,log:null,identity:null,diffCache:new Map,indexRevision:0,lastRepoCheckAt:0,lastStatusFetch:0,lastStatusChange:0,lastLogFetch:0,lastBranchesFetch:0,lastIdentityFetch:0,logMaxCount:25,isLoadingStatus:!1,isLoadingLog:!1,isLoadingBranches:!1,isLoadingIdentity:!1}),Vt=(e,t=Et,n=Dt)=>{let r=0;for(let t of e.values())r+=(t.original?.length??0)+(t.modified?.length??0);if(e.size<=t&&r<=n)return e;let i=Array.from(e.entries()).sort((e,t)=>e[1].fetchedAt-t[1].fetchedAt),a=new Map,o=0;for(let e=i.length-1;e>=0;e--){let[r,s]=i[e],c=(s.original?.length??0)+(s.modified?.length??0);if(a.size>=t)break;o+c>n&&a.size>0||(a.set(r,s),o+=c)}return a},Ht=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,Ut=e=>{let t=e?.trim()??``;return t===`?`?``:t},Wt=(e,t)=>{let n=new Set,r=!1,i=!e;e&&(i=e.ahead!==t.ahead||e.behind!==t.behind||e.current!==t.current||e.tracking!==t.tracking||e.isClean!==t.isClean||t.upstreamComparison!==void 0&&Ht(e.upstreamComparison,t.upstreamComparison)||t.diffStats!==void 0&&e.diffStats===void 0);let a=new Map;for(let t of e?.files??[])a.set(t.path,t);for(let e of t.files??[]){let t=a.get(e.path);if(!t){n.add(e.path),Ut(e.index)&&(r=!0);continue}a.delete(e.path),(t.index!==e.index||t.working_dir!==e.working_dir)&&n.add(e.path),!r&&Ut(t.index)!==Ut(e.index)&&(r=!0)}for(let[e,t]of a)n.add(e),Ut(t.index)&&(r=!0);let o=t.diffStats,s=e?.diffStats;if(o!==void 0&&o!==s){let e=s??{};for(let t in o){let r=o[t],i=e[t];(!i||i.insertions!==r.insertions||i.deletions!==r.deletions)&&n.add(t)}for(let t in e)t in o||n.add(t)}return{changed:i||n.size>0,changedPaths:n,indexChanged:r}},Gt=e=>!e||e.trim().length===0,Kt=e=>(e||``).trim()===`U`,qt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Kt(t)||Kt(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},Jt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Kt(t)||Kt(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},Yt=e=>Gt(e.index)&&Gt(e.working_dir),Q=o()(c((e,t)=>({directories:new Map,activeDirectory:null,setActiveDirectory:n=>{let{activeDirectory:r,directories:i}=t();if(r!==n)if(r&&Rt(r),n&&Rt(n),n&&!i.has(n)){let t=new Map(i);t.set(n,Z()),e({activeDirectory:n,directories:t})}else e({activeDirectory:n})},getDirectoryState:e=>t().directories.get(e)??null,fetchStatus:async(n,r,i={})=>{let a=i.mode??`full`,o=It(n,a),s=jt.get(o)??(a===`light`?jt.get(It(n,`full`)):void 0);if(s)return s;let c=(async()=>{let{silent:a=!1}=i,{directories:o}=t(),s=o.get(n);if(s||=Z(),!a){let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingStatus:!0}),e({directories:r})}let c=!1;try{let a=Date.now(),o=s.isGitRepo!==!0||a-(s.lastRepoCheckAt||0)>_t,l=s.isGitRepo===!0;if(o&&(l=await r.checkIsGitRepository(n)),!l){let r=new Map(t().directories),i=r.get(n)??s;return r.set(n,{...i,isGitRepo:!1,status:null,isLoadingStatus:!1,lastRepoCheckAt:a,lastStatusFetch:a}),e({directories:r}),!1}let u=await r.getGitStatus(n,i.mode?{mode:i.mode}:void 0),d=t().directories.get(n)??Z(),f=Nt.get(n),p=f?.received===u&&f.stored===d.status?null:Wt(d.status,u);if(p?.changed){c=!0;let r=new Map(t().directories),i=r.get(n)??Z(),{changedPaths:s,indexChanged:l}=p,d=new Map(i.diffCache);for(let e of s)d.delete(e);let f=s.size>0;f&&Rt(n);let m={...u,diffStats:u.diffStats===void 0&&i.status?.diffStats!==void 0?i.status.diffStats:u.diffStats,upstreamComparison:u.upstreamComparison===void 0?i.status?.upstreamComparison:u.upstreamComparison};r.set(n,{...i,isGitRepo:!0,status:m,diffCache:d,indexRevision:l?i.indexRevision+1:i.indexRevision,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:f?Date.now():i.lastStatusChange}),e({directories:r}),Nt.set(n,{received:u,stored:m})}else{Nt.set(n,{received:u,stored:d.status});let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isGitRepo:!0,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:i.lastStatusChange}),e({directories:r})}}catch(e){console.error(`Failed to fetch git status:`,e)}finally{if(!a){let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingStatus:!1}),e({directories:r})}}return c})();jt.set(o,c);try{return await c}finally{jt.get(o)===c&&jt.delete(o)}},moveStatusPathsOptimistically:(n,r,i)=>{let a=new Set(r.map(e=>e.trim()).filter(Boolean));if(a.size===0)return null;let{directories:o}=t(),s=o.get(n),c=s?.status??null;if(!s||!c)return c;let l=!1,u=[];for(let e of c.files){if(!a.has(e.path)){u.push(e);continue}let t=i===`stage`?qt(e):Jt(e);t!==e&&(l=!0),Yt(t)?l=!0:u.push(t)}if(!l)return c;let d=new Map(o);return d.set(n,{...s,status:{...c,files:u,isClean:u.length===0},indexRevision:s.indexRevision+1,lastStatusChange:Date.now()}),e({directories:d}),c},restoreStatus:(n,r)=>{let{directories:i}=t(),a=i.get(n);if(!a)return;let o=new Map(i);o.set(n,{...a,status:r,indexRevision:a.indexRevision+1,lastStatusChange:Date.now()}),e({directories:o})},bumpIndexRevision:n=>{let{directories:r}=t(),i=r.get(n);if(!i)return;let a=new Map(r);a.set(n,{...i,indexRevision:i.indexRevision+1}),e({directories:a})},fetchBranches:async(r,i,a={})=>{let o=n(),s=zt(r);{let n=new Map(t().directories),i=n.get(r)??Z();n.set(r,{...i,isLoadingBranches:!0}),e({directories:n})}try{let c=a.force?await N(r,i,void 0,o):await O(r,i,void 0,o);if(s!==At.get(r)||o!==n())return;let l=new Map(t().directories),u=l.get(r)??Z();l.set(r,{...u,branches:c,branchesTransportIdentity:o,isLoadingBranches:!1,lastBranchesFetch:Date.now()}),e({directories:l})}catch(i){if(ht(i)||console.error(`Failed to fetch git branches:`,i),s!==At.get(r)||o!==n())return;let a=new Map(t().directories),c=a.get(r)??Z();a.set(r,{...c,isLoadingBranches:!1}),e({directories:a})}},fetchLog:async(n,r,i)=>{let{directories:a}=t(),o=a.get(n),s=i??o?.logMaxCount??25;{let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingLog:!0}),e({directories:r})}try{let i=await r.getGitLog(n,{maxCount:s}),a=new Map(t().directories),o=a.get(n)??Z();a.set(n,{...o,log:i,isLoadingLog:!1,lastLogFetch:Date.now(),logMaxCount:s}),e({directories:a})}catch(r){console.error(`Failed to fetch git log:`,r);let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,isLoadingLog:!1}),e({directories:i})}},fetchIdentity:async(n,r)=>{{let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingIdentity:!0}),e({directories:r})}try{let i=await r.getCurrentGitIdentity(n),a=new Map(t().directories),o=a.get(n)??Z();a.set(n,{...o,identity:i,isLoadingIdentity:!1,lastIdentityFetch:Date.now()}),e({directories:a})}catch(r){console.error(`Failed to fetch git identity:`,r);let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,isLoadingIdentity:!1}),e({directories:i})}},fetchAll:async(n,r,i={})=>{let{directories:a}=t(),o=a.get(n);if(!o){o=Z();let t=new Map(a);t.set(n,o),e({directories:t})}let{force:s=!1,silentIfCached:c=!1}=i,l=Date.now();await t().fetchStatus(n,r,{silent:c&&!!o?.status});let u=t().directories.get(n);if(!u?.isGitRepo)return;await t().fetchBranches(n,r,{force:s});let d=l-(u.lastLogFetch||0);(s||d>gt||!u.log)&&await t().fetchLog(n,r),await t().fetchIdentity(n,r)},getDiff:(e,n)=>t().directories.get(e)?.diffCache.get(n)??null,setDiff:(n,r,i)=>{let a=new Map(t().directories),o=a.get(n)??Z(),s=new Map(o.diffCache);s.set(r,{...i,fetchedAt:Date.now()});let c=Vt(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{Rt(n);let r=new Map(t().directories),i=r.get(n);i&&(r.set(n,{...i,diffCache:new Map}),e({directories:r}))},fetchAllDiffs:async(e,n)=>{let r=t().directories.get(e);if(!r?.status?.files||r.status.files.length===0)return;let i=r.status.files.map(e=>e.path).slice(0,xt);await t().prefetchDiffs(e,n,i,{maxFiles:xt})},prefetchDiffs:async(n,r,i,a={})=>{let o=t().directories.get(n);if(!o?.status?.files||o.status.files.length===0||i.length===0)return;let{maxFiles:s=St}=a,c=Math.min(Math.max(1,s),Et),l=Ft(o.status),u=o.status.diffStats,d=Bt(n),f=[],p=new Set;for(let e of i){if(p.size>=c)break;if(!e||p.has(e)||!l.has(e))continue;let t=u?.[e];t&&t.insertions+t.deletions>Tt||(p.add(e),!o.diffCache.has(e)&&(d.has(e)||f.push(e)))}let m=f;if(m.length===0)return;let h=Lt(n);if(typeof document<`u`&&document.hidden)return;m.forEach(e=>d.add(e));let g=0,_=[],v=()=>{let e=g;return g+=1,e<m.length?m[e]:null},y=async e=>{let t=r.getGitFileDiff(n,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${wt}ms`)),wt)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},b=async()=>{for(;;){if(h!==Lt(n))return;let e=v();if(!e)return;try{_.push(await y(e))}catch{}finally{d.delete(e)}}},x=Math.min(Ct,m.length);if(await Promise.allSettled(Array.from({length:x},()=>b())),m.forEach(e=>d.delete(e)),h!==Lt(n))return;let S=new Map(t().directories),C=S.get(n);if(!C)return;let w=new Map(C.diffCache),T=Date.now();_.forEach(e=>{!e.diff.isBinary&&e.diff.original===``&&e.diff.modified===``||w.set(e.path,{...e.diff,fetchedAt:T})});let E=Vt(w);S.set(n,{...C,diffCache:E}),e({directories:S})},setLogMaxCount:(n,r)=>{let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,logMaxCount:r}),e({directories:i})},ensureStatus:async(e,n)=>{let r=t().directories.get(e),i=Date.now();r?.status&&i-r.lastStatusFetch<vt||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=Mt.get(e);if(r)return r;let i=(async()=>{let r=t().directories.get(e),i=Date.now();(!r?.status||r.status.diffStats===void 0||i-(r?.lastStatusFetch??0)>=vt)&&await t().fetchStatus(e,n,{silent:!!r?.status});let a=t().directories.get(e);if(!a?.isGitRepo)return;let o=[];(!a.branches||i-a.lastBranchesFetch>=yt)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=gt)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=bt)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return Mt.set(e,i),i.finally(()=>{Mt.get(e)===i&&Mt.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),Xt=e=>{let t=(0,U.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status??null:null,t[0]=e,t[1]=n),Q(n)},Zt=e=>{let r=(0,U.c)(3),i=H.useSyncExternalStore(t,n,n),a;return r[0]!==e||r[1]!==i?(a=t=>{if(!e)return null;let n=t.directories.get(e);return n?.branchesTransportIdentity===i?n.branches:null},r[0]=e,r[1]=i,r[2]=a):a=r[2],Q(a)},Qt=e=>{let t=(0,U.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isGitRepo??null:null,t[0]=e,t[1]=n),Q(n)},$t=e=>{let t=(0,U.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status?.current?.trim()??null:null,t[0]=e,t[1]=n),Q(n)},en=e=>{let t=(0,U.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=H.useRef(n),i;return t[1]===e?i=t[2]:(i=t=>{let n=r.current,i=n.size===e.length;if(i)for(let r of e){let e=t.directories.get(r),a=n.get(r);if(!a||(e?.isGitRepo??null)!==a.isGitRepo||(e?.status?.current??null)!==a.branch){i=!1;break}}if(i)return n;let a=new Map;for(let n of e){let e=t.directories.get(n);a.set(n,{isGitRepo:e?.isGitRepo??null,branch:e?.status?.current??null})}return r.current=a,a},t[1]=e,t[2]=i),Q(i)},tn=e=>{let t=(0,U.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingStatus??!1:!1,t[0]=e,t[1]=n),Q(n)},nn=e=>{let t=(0,U.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingBranches??!1:!1,t[0]=e,t[1]=n),Q(n)},rn=e=>{let t=String(e||``).trim().replace(/^remotes\//,``);if(!t)return null;let n=t.indexOf(`/`);return n<=0||n>=t.length-1?null:{remote:t.slice(0,n),branch:t.slice(n+1)}},$=e=>String(e||``).trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/^remotes\//,``),an=e=>e.branchName?$(e.branchName):e.mode===`existing`?$(e.existingBranch||e.preferredName||``):$(e.preferredName||``),on=async e=>{let t=await Se(e);try{let n=rn((await me(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=rn((await pe(e)).tracking);if(t?.remote)return t.remote}catch{}return null},sn=async(e,t)=>{let n=await on(e),r=$(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},cn=async(e,t,n)=>{let r=an(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await sn(e,r):i&&$(r)?{setUpstream:!0,upstreamRemote:i,upstreamBranch:$(r)}:null;return a?{...t,setUpstream:t.setUpstream??a.setUpstream,upstreamRemote:t.upstreamRemote||a.upstreamRemote,upstreamBranch:t.upstreamBranch||a.upstreamBranch}:t},ln=async(e,t,n)=>{let r=await cn(e.path,t,n);return Ce(e,r)},un=`yuri:lastWorktreeSourceBranch`,dn=({mode:e,sourceBranch:t,linkedPr:n,selectedBranch:r})=>e===`existing-branch`?r||null:n?null:t||null,fn=({branches:e,savedSourceBranch:t,rootBranch:n})=>t&&e.includes(t)&&t?{sourceBranch:t,shouldClearSavedSourceBranch:!1}:{sourceBranch:n&&e.includes(n)?n:e.includes(`main`)?`main`:e.includes(`master`)?`master`:e[0]??``,shouldClearSavedSourceBranch:!!t},pn=(e,t,n)=>{if(!e)return e;let r=t.length>0&&!/\s$/.test(t)&&!/^\s/.test(e)&&!/[([{]$/.test(t),i=n.length>0&&!/\s$/.test(e)&&!/^\s/.test(n)&&!/^[\])}.,;:!?]/.test(n);return`${r?` `:``}${e}${i?` `:``}`},mn=(e,t,n)=>{let r=pn(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},hn=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=mn(r,i,a),s=Math.max(0,o.indexOf(r)),c=i.length+s;return{text:`${i}${o}${a}`,caret:i.length+o.length,start:c,end:c+r.length}},gn=(e,t)=>{let n=e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`;return new Set(e.map(n)).has(n(t))||e.some(e=>e.range.start<t.range.end&&t.range.start<e.range.end)?[...e]:[...e,t]},_n=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{Fe as C,Ae as D,ke as E,we as O,We as S,Ne as T,Q as _,un as a,ot as b,ln as c,$t as d,Zt as f,Xt as g,en as h,mn as i,on as l,tn as m,gn as n,fn as o,nn as p,hn as r,dn as s,_n as t,cn as u,Qt as v,Pe as w,it as x,mt as y};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n}from"./runtime-switch-BMjl5Y5W.js";import{R as r,l as i,u as a}from"./platform-wF65ZFgV.js";import{a as o,i as s,r as c}from"./vendor-zustand-Cwko4FG1.js";import{ot as l,st as u}from"./vendor-base-ui-z2M4boRm.js";import{St as d,an as f,jt as p,on as m}from"./gitApiHttp-B0FJaIhU.js";import{t as h}from"./safeStorage-DTOhKN0V.js";import{i as g,t as _}from"./vendor-pathe-vBmvQE8f.js";import{n as v}from"./vendor-react-P8wFrkcT.js";import{s as y,u as b}from"./vendor-tanstack-react-query-B-KblYBV.js";import{E as x}from"./runtime-file-resource-CuLP3xp7.js";import{o as S}from"./path-utils-jGozTg9d.js";import{r as C}from"./vendor-reactuses-core-Dyjw5sZR.js";import{r as w}from"./useUIStore-Cfmg-aDQ.js";import{t as T}from"./i18n-qHllte6P.js";import{Ba as E,Fa as ee,Gn as D,Jn as O,R as k,Rn as A,Sa as te,Va as j,Xi as M,Xn as N,da as ne,di as P,lt as re,p as F,v as I,vi as L,x as ie,yt as ae}from"./useMobileNavigationStore-2N3dS8vX.js";import{s as oe}from"./remoteProjectQueries-Dfms-cCx.js";import{a as se,g as ce,o as le,p as ue,s as de}from"./fileMentionAutocompleteState-BZJqfgae.js";import{t as fe}from"./AgentAvatar-B4_d0rQt.js";import{n as R}from"./Icon-DBOSvb4U.js";import{l as pe,s as me}from"./gitApi-CtJXK0WM.js";import{c as he,d as ge,l as _e,n as ve,r as ye,t as be}from"./fileMentionTouchSelection-DiKjZQEm.js";import{n as xe}from"./textarea-DPrUh2E_.js";import{f as Se,o as Ce}from"./projectMeta-BOcz1XpN.js";var z=(e,t)=>{let n=t.trim();if(!n)return[...e].sort((e,t)=>e.isBuiltIn===t.isBuiltIn?e.name.localeCompare(t.name):e.isBuiltIn?-1:1);let r=ce([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.isBuiltIn===t.item.isBuiltIn?e.item.name.localeCompare(t.item.name):e.item.isBuiltIn?-1:1:e.score-t.score),r.map(e=>e.item)},B=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>{let r=t[n];return r!=null&&e.id===r.id&&e.title===r.title&&(e.subtitle??``)===(r.subtitle??``)&&(e.badge??``)===(r.badge??``)&&e.iconName===r.iconName&&e.agentName===r.agentName}),V=(e,t)=>e.highlightedIndex===t.highlightedIndex&&B(e.rows,t.rows),we=(e,t)=>B(e,t)?e:t.slice(),Te=(e,t,n)=>{e&&(t.current&&V(t.current,n)||(t.current=n,e(n)))},Ee=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},H=e(u(),1),U=v(),De=e=>e.directories.flatMap(e=>e.sessions),Oe=(e,t)=>({...oe(e,t.location.hostId),select:De}),ke=async(e,t,n)=>{n.sdk();let r=await e.fetchQuery(Oe(t,n));return n.sdk(),De(r)},Ae=(e,t,n,r)=>{n.sdk();let i=e.getQueryData(Oe(t,n).queryKey);for(let e of i?.directories??[]){let t=e.sessions.find(e=>e.id===r);if(t)return t.title||r}return r},je=(e,t,n,r={})=>({queryKey:[...e.queryScope,`composer-files`,t,n,r],staleTime:3e4,gcTime:3e4,queryFn:async({signal:i})=>{let a=await e.sdk().file.find({query:t,location:{directory:e.location.directory},limit:n,type:r.type},{signal:i});if(e.sdk(),i.throwIfAborted(),!Array.isArray(a.data))throw Error(`File search returned no data`);return a.data.map(t=>{let n=g(t.path),r=_(n);return{name:r,path:S(e.location.directory,n),relativePath:n,extension:r.includes(`.`)?r.split(`.`).pop()?.toLowerCase():void 0,isDirectory:t.type===`directory`}})}}),W=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+/g,`/`);n&&!r.startsWith(`//`)&&(r=`/${r}`);let i=r===`/`,a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,``)),r},G=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,K=e=>e.startsWith(`yuri-remote-location:`)?i(e):W(e),q=(e,t)=>{let n=W(a(t,`local`).directory),r=W(e);if(!n||!r)return!1;let i=G(n),o=G(r);return o===i||o.startsWith(i.endsWith(`/`)?i:`${i}/`)},Me=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t;try{t=K(e)}catch{continue}if(!t||!r||typeof r!=`object`)continue;let i=r,a=Array.isArray(i.openPaths)?Array.from(new Set(i.openPaths.filter(e=>typeof e==`string`).map(e=>W(e)).filter(e=>q(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>W(e)).filter(e=>q(e,t)))):[],s=typeof i.selectedPath==`string`?W(i.selectedPath):null,c=s&&q(s,t)?s:a[0]??null,l=typeof i.touchedAt==`number`&&Number.isFinite(i.touchedAt)?i.touchedAt:Date.now(),u=n[t];if(u){let e=Array.from(new Set([...u.openPaths,...a])),r=Array.from(new Set([...u.expandedPaths,...o])),i=u.selectedPath??c??e[0]??null;n[t]={openPaths:e,selectedPath:i,expandedPaths:r,touchedAt:Math.max(u.touchedAt,l)};continue}n[t]={openPaths:a,selectedPath:c,expandedPaths:o,touchedAt:l}}return n},J=(e,t)=>{let n=Object.entries(e);if(n.length<=t)return e;n.sort((e,t)=>(t[1]?.touchedAt??0)-(e[1]?.touchedAt??0));let r={};for(let[e,i]of n.slice(0,t))r[e]=i;return r},Y=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},Ne=o()(c(s((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=K((t||``).trim()),a=W((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!q(a,i)||e(e=>{let t=e.byRoot[i],n=Y(t),r=n.openPaths.includes(a),o=r?n.openPaths:[...n.openPaths,a],s=n.selectedPath??a;return t&&r&&t.selectedPath===s?e:{byRoot:J({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=K((t||``).trim()),i=W((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=G(i),a=e=>G(e)===n,o=t.selectedPath?a(t.selectedPath):!1;if(!t.openPaths.some(a)&&!o)return e;let s=t.openPaths.filter(e=>!a(e)),c=o?s[0]??null:t.selectedPath;return{byRoot:J({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=K((t||``).trim()),i=W((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=G(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=G(e);return t===n||t.startsWith(a)},s=t.openPaths.filter(e=>!o(e));if(s.length===t.openPaths.length)return e;let c=t.selectedPath&&o(t.selectedPath)?s[0]??null:t.selectedPath;return{byRoot:J({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=K((t||``).trim()),i=W((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=G(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=G(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:J({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=K((t||``).trim()),a=n?W(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!q(a,i)||e(e=>{let t=e.byRoot[i],n=Y(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:J({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=K((e||``).trim());if(!n)return;let r=t().byRoot[n];if(!r||r.selectedPath)return;let i=r.openPaths[0]??null;i&&t().setSelectedPath(n,i)},toggleExpandedPath:(t,n)=>{let r=K((t||``).trim()),i=W((n||``).trim());!r||!i||!q(i,r)||e(e=>{let t=e.byRoot[r],n=Y(t),a=n.expandedPaths.includes(i)?n.expandedPaths.filter(e=>e!==i):[...n.expandedPaths,i];return t&&t.expandedPaths===a&&t.selectedPath===n.selectedPath&&t.openPaths===n.openPaths?e:{byRoot:J({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=K((t||``).trim()),i=W((n||``).trim());!r||!i||!q(i,r)||e(e=>{let t=e.byRoot[r],n=Y(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:J({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=K((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>W((e||``).trim())).filter(e=>e&&q(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=Y(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:J({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:h(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:Me(t)}},merge:(e,t)=>({...t,byRoot:Me(e&&typeof e==`object`?e.byRoot:void 0)}),partialize:e=>({byRoot:Me(e.byRoot)})}),{name:`files-view-tabs-store`})),Pe=(e,t)=>{let n=(0,U.c)(4),r=t===void 0?200:t,[i,a]=H.useState(e),o,s;return n[0]!==r||n[1]!==e?(o=()=>{let t=window.setTimeout(()=>{a(e)},r);return()=>{window.clearTimeout(t)}},s=[e,r],n[0]=r,n[1]=e,n[2]=o,n[3]=s):(o=n[2],s=n[3]),H.useEffect(o,s),i},Fe=()=>{let e=(0,U.c)(17),t=F(Ie),n=ae(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=ie(r),a=F(Le),o=F(Re),s=j(ze),c=j(Be),l=d(Ve);if(t){let r;e[2]===i?r=e[3]:(r=I(i),e[2]=i,e[3]=r);let o=r;if(o)return o;let s;e[4]!==t||e[5]!==a?(s=a.get(t),e[4]=t,e[5]=a,e[6]=s):s=e[6];let c=s;if(c?.path)return c.path;let l;if(e[7]!==t||e[8]!==n){let r;e[10]===t?r=e[11]:(r=e=>e.id===t,e[10]=t,e[11]=r),l=n.find(r),e[7]=t,e[8]=n,e[9]=l}else l=e[9];let u=l;if(u?.directory)return u.directory}if(o?.open&&(o.bootstrapPendingDirectory||o.directoryOverride))return(o.bootstrapPendingDirectory||o.directoryOverride)??void 0;if(s){let t;if(e[12]!==s||e[13]!==c){let n;e[15]===s?n=e[16]:(n=e=>e.id===s,e[15]=s,e[16]=n),t=c.find(n),e[12]=s,e[13]=c,e[14]=t}else t=e[14];let n=t;if(n?.path)return n.path}return l??void 0};function Ie(e){return e.currentSessionId}function Le(e){return e.worktreeMetadata}function Re(e){return e.newSessionDraft}function ze(e){return e.activeProjectId}function Be(e){return e.projects}function Ve(e){return e.currentDirectory}var X=l(),He=`bg-transparent font-[inherit] text-[var(--primary-base)]`,Ue=(e,t)=>{let n=t.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase();if(!r.includes(n))return e;let i=[],a=0,o=r.indexOf(n);for(;o!==-1;)o>a&&i.push(e.slice(a,o)),i.push((0,X.jsx)(`mark`,{className:He,children:e.slice(o,o+n.length)},`${o}-${n}`)),a=o+n.length,o=r.indexOf(n,a);return a<e.length&&i.push(e.slice(a)),i},We=H.forwardRef((e,t)=>{let n=(0,U.c)(4),r=x(),i;return n[0]!==r||n[1]!==e||n[2]!==t?(i=r?.entry.location.hostId?(0,X.jsx)(Je,{...e,ref:t,entry:r.entry,registry:r.registry},JSON.stringify(r.entry.queryScope)):(0,X.jsx)(Ge,{...e,ref:t}),n[0]=r,n[1]=e,n[2]=t,n[3]=i):i=n[3],i}),Ge=H.forwardRef((e,t)=>{let n=(0,U.c)(22),r=Fe()??``,i=F(Xe),a=L(Ze),o=!!e.onSessionSelect,s;n[0]===o?s=n[1]:(s={enabled:o},n[0]=o,n[1]=s);let c=k(s),l=j(Qe),u=j($e),d;if(n[2]!==l||n[3]!==r||n[4]!==u){let e=u.find(e=>e.id===l)?.path||r;d=e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null,n[2]=l,n[3]=r,n[4]=u,n[5]=d}else d=n[5];let f=d,m;n[6]===f?m=n[7]:(m=e=>f?e.byRoot[f]:void 0,n[6]=f,n[7]=m);let h=Ne(m),g=M(et),_=p(tt),v;n[8]!==a||n[9]!==c||n[10]!==e.onSessionSelect?(v=e.onSessionSelect?P(a,c):[],n[8]=a,n[9]=c,n[10]=e.onSessionSelect,n[11]=v):v=n[11];let y=v,b=e.currentSessionId??i,x;return n[12]!==g||n[13]!==r||n[14]!==f||n[15]!==h||n[16]!==e||n[17]!==t||n[18]!==_||n[19]!==y||n[20]!==b?(x=(0,X.jsx)(Ye,{...e,ref:t,currentDirectory:r,currentSessionId:b,projectRoot:f,projectTabs:h,agentCatalog:g,sessions:y,searchFiles:_}),n[12]=g,n[13]=r,n[14]=f,n[15]=h,n[16]=e,n[17]=t,n[18]=_,n[19]=y,n[20]=b,n[21]=x):x=n[21],x}),Ke=[],qe=[],Je=H.forwardRef((e,t)=>{let n=(0,U.c)(32),{entry:r,registry:i}=e,a=b(),o;n[0]===r?o=n[1]:(o=ee(r.location.directory,void 0,r),n[0]=r,n[1]=o);let s=!!e.onAgentSelect,c;n[2]!==o||n[3]!==s?(c={...o,enabled:s},n[2]=o,n[3]=s,n[4]=c):c=n[4];let l=y(c),u;n[5]!==r||n[6]!==i?(u=Oe(i,r),n[5]=r,n[6]=i,n[7]=u):u=n[7];let d=!!e.onSessionSelect,f;n[8]!==u||n[9]!==d?(f={...u,enabled:d},n[8]=u,n[9]=d,n[10]=f):f=n[10];let p=y(f),m;n[11]===r.key?m=n[12]:(m=e=>e.byRoot[r.key],n[11]=r.key,n[12]=m);let h=Ne(m),g;n[13]!==a||n[14]!==r?(g=(e,t,n,i)=>{let o=n===void 0?60:n;return a.fetchQuery(je(r,t,o,i))},n[13]=a,n[14]=r,n[15]=g):g=n[15];let _=C(g),v=r.location.directory,x;if(n[16]!==r.location.directory){let e;n[18]===Symbol.for(`react.memo_cache_sentinel`)?(e=/\/+$/,n[18]=e):e=n[18],x=r.location.directory.replace(/\\/g,`/`).replace(e,``),n[16]=r.location.directory,n[17]=x}else x=n[17];let S=l.data??qe,w=p.data??Ke,T=l.error??p.error,E;n[19]===r?E=n[20]:(E=()=>{r.sdk()},n[19]=r,n[20]=E);let D;return n[21]!==r.location.directory||n[22]!==h||n[23]!==e||n[24]!==t||n[25]!==_||n[26]!==S||n[27]!==w||n[28]!==T||n[29]!==E||n[30]!==x?(D=(0,X.jsx)(Ye,{...e,ref:t,currentDirectory:v,projectRoot:x,projectTabs:h,agentCatalog:S,sessions:w,searchFiles:_,catalogError:T,assertCurrent:E}),n[21]=r.location.directory,n[22]=h,n[23]=e,n[24]=t,n[25]=_,n[26]=S,n[27]=w,n[28]=T,n[29]=E,n[30]=x,n[31]=D):D=n[31],D}),Ye=H.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:i,onClose:a,style:o,onRowsChange:s,currentDirectory:c,currentSessionId:l,projectRoot:u,projectTabs:d,agentCatalog:p,sessions:h,searchFiles:g,catalogError:_,assertCurrent:v},y)=>{let{t:b}=T(),x=Pe(e,180),S=m(),E=f(),[ee,O]=H.useState([]),[k,j]=H.useState(!1),[M,N]=H.useState(null),[P,re]=H.useState(0),F=H.useRef(0),I=H.useRef({query:e,directory:c,ids:[]}),[L,ie]=H.useState(360),[ae,oe]=H.useState({}),[ce,pe]=H.useState({}),me=H.useRef([]),ge=H.useRef([]),_e=H.useRef([]),Se=H.useRef(null),Ce=H.useRef(null),z=H.useRef(null);z.current||=be();let B=w(e=>e.isMobile),V=(e??``).trim(),we=te({directory:c||null}),U=H.useMemo(()=>r?we.data??[]:[],[r,we.data]),De=H.useMemo(()=>{if(!u||!d)return[];let e=[d.selectedPath,...d.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=[];for(let r of e){if(t.has(r))continue;t.add(r);let e=r.replace(/\\/g,`/`),i=e.split(`/`).filter(Boolean).pop()||e,a=e.startsWith(`${u}/`)?e.slice(u.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return de(n,V,{limit:6})},[V,u,d]),Oe=H.useMemo(()=>n?ne(p).filter(e=>e.mode!==`primary`):[],[p,n]),ke=H.useMemo(()=>i?se({sessions:h,currentSessionId:l??null,searchQuery:V}):[],[h,l,V,i]),Ae=De,je=ee,W=H.useMemo(()=>he({skills:U,agents:Oe,sessions:ke,recentFiles:Ae,pathHits:je,searchQuery:V,untitledSession:b(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:b(`chat.fileMentionAutocomplete.sessionType`),skillBadge:b(`chat.commandAutocomplete.badge.skill`)}),[U,Oe,ke,Ae,je,V,b]);H.useEffect(()=>{let e=e=>{let t=e.target;!t||!Se.current||Se.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),H.useEffect(()=>{if(!c){O([]),j(!1),N(null);return}let e=(x??``).trim(),t=ue(e);if(!t){O([]),j(!1),N(null);return}let n=!1;j(!0),N(null);let r={includeHidden:S,respectGitignore:!E};return Promise.all([g(c,t,80,{...r,type:`file`}),g(c,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(De.map(e=>e.path));O(le({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(e=>{n||N(e instanceof Error?e:Error(String(e)))}).finally(()=>{n||j(!1)}),()=>{n=!0}},[c,x,De,g,S,E]),H.useLayoutEffect(()=>{let t=I.current,n=t.ids[F.current],r=t.query===e&&t.directory===c?Math.max(0,W.findIndex(e=>e.id===n)):0;I.current={query:e,directory:c,ids:W.map(e=>e.id)},F.current=r,re(r)},[W,e,c]),H.useEffect(()=>{oe({}),pe({})},[W]),H.useEffect(()=>{me.current[P]?.scrollIntoView({block:`nearest`})},[P]),H.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};ge.current.forEach((n,r)=>{if(!n)return;let i=_e.current[r]?.offsetWidth??n.scrollWidth,a=Math.max(0,i-n.clientWidth),o=a>8;if(e[r]=o,o){let e=Math.max(.6,a/110);t[r]=e}}),oe(e),pe(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[W]),H.useEffect(()=>{let e=ge.current[P];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&ie(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[P]);let G=C(e=>{t(e)}),K=C(e=>{n?.(e)}),q=C(e=>{i?.(e)}),Me=C(e=>{r?.(e)}),J=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&z.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&z.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(z.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>z.current?.pointerCancel(),onClick:()=>{z.current?.click(t)},onMouseMove:()=>{F.current=e,re(e)}}),Y=e=>{try{v?.()}catch(e){N(e instanceof Error?e:Error(String(e)));return}let t=W.length;if(t===0)return;let n=(e%t+t)%t,r=W[n];if(r.agentName!==void 0){K(r.agentName);return}if(r.id.startsWith(`skill:`)){let e=U.find(e=>r.id===`skill:${e.name}-${e.scope}`);e&&Me(e);return}if(r.id.startsWith(`session:`)){let e=ke.find(e=>r.id===`session:${e.id}`);e&&q(e);return}let i=r.id.startsWith(`recent:`)?Ae.find(e=>r.id===`recent:${e.path}`):je.find(e=>r.id===`file:${e.path}`);i&&G(i)};H.useEffect(()=>{Te(s,Ce,{rows:W,highlightedIndex:P})},[s,P,W]);let Ne=H.useRef(s);return Ne.current=s,H.useEffect(()=>()=>{Ee(Ne.current,Ce)},[]),H.useImperativeHandle(y,()=>({acceptIndex:e=>{Y(e)},handleKeyDown:e=>{if(e===`Escape`){a();return}let t=W.length;if(t!==0){if(e===`ArrowDown`){F.current=(F.current+1)%t,re(F.current);return}if(e===`ArrowUp`){F.current=(F.current-1+t)%t,re(F.current);return}(e===`Enter`||e===`Tab`)&&Y(F.current)}}})),(0,X.jsxs)(ve,{ref:Se,isMobile:B,className:`max-w-[640px] max-h-64`,style:o,children:[(0,X.jsx)(xe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,X.jsxs)(`div`,{className:`py-1`,children:[_||we.error||M?(0,X.jsx)(`div`,{role:`alert`,className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:(_??we.error??M)?.message}):null,W.map((e,t)=>{let n=e.id.startsWith(`file:`)||e.id.startsWith(`recent:`),r=n?D(e.title,{maxLength:60}):e.title,i=P===t,a=ae[t]??!1,o=ce[t]??2.6;return(0,X.jsxs)(`div`,{"data-mention-id":e.id,ref:e=>{me.current[t]=e},className:A(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,B&&`min-h-11`,ye(B,i),!B&&i&&`text-interactive-selection-foreground`),...J(t,()=>Y(t)),children:[(0,X.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center`,children:e.agentName===void 0?(0,X.jsx)(R,{name:e.iconName,className:`size-3.5 text-current`}):(0,X.jsx)(fe,{name:e.agentName,size:20})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,X.jsxs)(`span`,{ref:e=>{ge.current[t]=e},className:A(`relative block min-w-0 overflow-hidden`,n&&a&&i&&`file-mention-marquee-container`),style:i?{"--file-mention-marquee-width":`${L}px`,"--file-mention-marquee-duration":`${o}s`}:void 0,title:e.title,children:[(0,X.jsx)(`span`,{ref:e=>{_e.current[t]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:e.title}),n&&a&&i?(0,X.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Ue(e.title,V)}):(0,X.jsx)(`span`,{className:`block truncate`,children:Ue(r,V)})]}),e.trailingLabel?(0,X.jsx)(`span`,{className:A(`max-w-[40%] shrink-0 truncate text-muted-foreground`,B?`typography-micro`:`typography-meta`),children:e.trailingLabel}):null]}),e.subtitle?(0,X.jsx)(`div`,{className:A(`truncate text-muted-foreground`,B?`typography-micro`:`typography-meta`),children:Ue(e.subtitle,V)}):null]})]},e.id)}),k&&je.length===0?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,X.jsx)(R,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!k&&W.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:b(`chat.fileMentionAutocomplete.empty`)})]})}),!B&&(0,X.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:b(`chat.autocomplete.keyboardHint`)})]})});function Xe(e){return e.currentSessionId}function Ze(e){return e.activeSessions}function Qe(e){return e.activeProjectId}function $e(e){return e.projects}function et(e){return e.agents}function tt(e){return e.searchFiles}var nt=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`btw`]),rt=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&nt.has(n))},it=(e,t)=>!e||t({name:e}),at=` `,ot=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=n;for(;r>0&&!/\s/.test(e[r-1]);)--r;return r>=2&&e[r-1]===at&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},st=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,ct=A(st,`bg-[color-mix(in_srgb,var(--primary-base)_12%,transparent)] text-[color-mix(in_srgb,var(--primary-base)_70%,transparent)] border-[color-mix(in_srgb,var(--primary-base)_24%,transparent)]`),lt=A(st,`bg-[color-mix(in_srgb,var(--status-success)_12%,transparent)] text-[color-mix(in_srgb,var(--status-success)_70%,transparent)] border-[color-mix(in_srgb,var(--status-success)_24%,transparent)]`),ut=A(st,`bg-[color-mix(in_srgb,var(--status-info)_12%,transparent)] text-[color-mix(in_srgb,var(--status-info)_70%,transparent)] border-[color-mix(in_srgb,var(--status-info)_24%,transparent)]`),dt=A(st,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),ft=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),pt=e=>{let t=!!e.sessionID;return{hasSession:t,canStartSessionCommand:t||e.hasNewDraft}},mt=H.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:i,style:a,commandPolicy:o,commandContext:s,onRowsChange:c},l)=>{let{t:u}=T(),d=w(e=>e.isMobile),f=F(e=>e.currentSessionId),p=F(e=>!!e.newSessionDraft?.open),m=F(H.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=re(f??``,m??void 0),g=H.useMemo(()=>s??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[s,f,h.length,p]),{hasSession:_,canStartSessionCommand:v}=H.useMemo(()=>pt(g),[g]),y=g.hasMessages,[b,x]=H.useState([]),[S,C]=H.useState(!1),ee=E({directory:i}),D=H.useMemo(()=>ee.data??[],[ee.data]),O=ee.isFetching,[k,te]=H.useState(0),j=H.useRef(0),M=H.useRef(!1),N=H.useRef([]),ne=H.useRef(null),P=H.useRef(!1),I=H.useRef(null),L=H.useRef(!1),ie=H.useRef(null);H.useEffect(()=>{let e=e=>{let t=e.target;!t||!ne.current||ne.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),H.useEffect(()=>{(async()=>{C(O);try{let t=D.flatMap((e,t)=>e.source===`skill`?[]:[{id:`opencode:${e.scope??`global`}:${e.name}:${e.agent??``}:${e.model??``}:${t}`,name:e.name,source:`opencode`,description:e.description,agent:e.agent??void 0,model:e.model??void 0,isBuiltIn:e.isBuiltIn,scope:e.scope,reference:e.reference}]),n=[{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!y?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:btw`,name:`btw`,source:`yuri`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`yuri:undo`,name:`undo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`yuri:redo`,name:`redo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`yuri:fork`,name:`fork`,source:`yuri`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`yuri:timeline`,name:`timeline`,source:`yuri`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`yuri:model`,name:`model`,source:`yuri`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`yuri:compact`,name:`compact`,source:`yuri`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...r()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...v?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...v?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...v?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...v?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...v?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[],...t],i=!y,a=z(n.filter(e=>(i||e.name!==`init`)&&(o?.(e)??!0)),e);x(e=>ft(e,a)?e:a)}catch{let t=!y,n=z([{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!y?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:btw`,name:`btw`,source:`yuri`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`yuri:undo`,name:`undo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`yuri:redo`,name:`redo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`yuri:fork`,name:`fork`,source:`yuri`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`yuri:timeline`,name:`timeline`,source:`yuri`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`yuri:model`,name:`model`,source:`yuri`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`yuri:compact`,name:`compact`,source:`yuri`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...r()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...v?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...v?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...v?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...v?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...v?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(o?.(e)??!0)),e);x(e=>ft(e,n)?e:n)}finally{C(!1)}})()},[e,y,_,v,D,O,u,o]),H.useEffect(()=>{te(0)},[b]),H.useEffect(()=>{j.current=k},[k]),H.useEffect(()=>{N.current[k]?.scrollIntoView({block:`nearest`})},[k]),H.useEffect(()=>{Te(c,ie,{rows:_e(b,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:k})},[b,c,k,u]);let ae=H.useRef(c);ae.current=c,H.useEffect(()=>()=>{Ee(ae.current,ie)},[]),H.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=b[e];r&&t(r,rt(r,n))},handleKeyDown:e=>{let r=b.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){M.current=!0,te(e=>(e+1)%r);return}if(e===`ArrowUp`){M.current=!0,te(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(j.current%r+r)%r,i=b[n];i&&t(i,rt(i,e===`Enter`))}}}}),[b,n,t]);let oe=e=>{let t=ge(e);switch(e.name){case`new`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,X.jsx)(R,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,X.jsxs)(ve,{ref:ne,isMobile:d,className:`max-w-[450px] max-h-64`,style:a,children:[(0,X.jsx)(xe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:S?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,X.jsx)(R,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,X.jsxs)(`div`,{children:[b.map((n,r)=>{let i=n.isBuiltIn,a=n.isYuri;return(0,X.jsxs)(`div`,{ref:e=>{N.current[r]=e},className:A(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,ye(d,r===k),!d&&r===k&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(I.current={x:e.clientX,y:e.clientY},L.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!I.current)return;let t=e.clientX-I.current.x,n=e.clientY-I.current.y;Math.hypot(t,n)>6&&(L.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=L.current;I.current=null,L.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),P.current=!0,t(n,rt(n,d)))},onPointerCancel:()=>{I.current=null,L.current=!1},onClick:()=>{if(P.current){P.current=!1;return}t(n,rt(n,d))},onMouseMove:()=>{M.current=!1,te(r)},children:[(0,X.jsx)(`div`,{className:A(!d&&`mt-0.5`),children:oe(n)}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,Ue(n.name,e)]}),n.isSkill?(0,X.jsx)(`span`,{className:ct,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,X.jsx)(`span`,{className:ct,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,X.jsx)(`span`,{className:dt,children:`Yuri`}):i?(0,X.jsx)(`span`,{className:dt,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,X.jsx)(`span`,{className:n.scope===`project`?ut:lt,children:n.scope}):null,n.agent&&(0,X.jsx)(`span`,{className:dt,children:n.agent})]}),n.description&&!d&&(0,X.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Ue(n.description,e)})]})]},n.id)}),b.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,X.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});mt.displayName=`CommandAutocomplete`;var ht=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,gt=1e4,_t=6e4,vt=5e3,yt=3e4,bt=6e4,xt=25,St=40,Ct=2,wt=15e3,Tt=500,Et=30,Dt=20971520,Ot=new Map,kt=new Map,At=new Map,jt=new Map,Mt=new Map,Nt=new Map,Pt=new WeakMap,Ft=e=>{let t=Pt.get(e);return t||(t=new Set(e.files.map(e=>e.path)),Pt.set(e,t)),t},It=(e,t)=>`${t}:${e}`,Lt=e=>kt.get(e)??0,Rt=e=>{let t=Lt(e)+1;return kt.set(e,t),t},zt=e=>{let t=(At.get(e)??0)+1;return At.set(e,t),t},Bt=e=>{let t=Ot.get(e);if(t)return t;let n=new Set;return Ot.set(e,n),n},Z=()=>({isGitRepo:null,status:null,branches:null,branchesTransportIdentity:null,log:null,identity:null,diffCache:new Map,indexRevision:0,lastRepoCheckAt:0,lastStatusFetch:0,lastStatusChange:0,lastLogFetch:0,lastBranchesFetch:0,lastIdentityFetch:0,logMaxCount:25,isLoadingStatus:!1,isLoadingLog:!1,isLoadingBranches:!1,isLoadingIdentity:!1}),Vt=(e,t=Et,n=Dt)=>{let r=0;for(let t of e.values())r+=(t.original?.length??0)+(t.modified?.length??0);if(e.size<=t&&r<=n)return e;let i=Array.from(e.entries()).sort((e,t)=>e[1].fetchedAt-t[1].fetchedAt),a=new Map,o=0;for(let e=i.length-1;e>=0;e--){let[r,s]=i[e],c=(s.original?.length??0)+(s.modified?.length??0);if(a.size>=t)break;o+c>n&&a.size>0||(a.set(r,s),o+=c)}return a},Ht=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,Ut=e=>{let t=e?.trim()??``;return t===`?`?``:t},Wt=(e,t)=>{let n=new Set,r=!1,i=!e;e&&(i=e.ahead!==t.ahead||e.behind!==t.behind||e.current!==t.current||e.tracking!==t.tracking||e.isClean!==t.isClean||t.upstreamComparison!==void 0&&Ht(e.upstreamComparison,t.upstreamComparison)||t.diffStats!==void 0&&e.diffStats===void 0);let a=new Map;for(let t of e?.files??[])a.set(t.path,t);for(let e of t.files??[]){let t=a.get(e.path);if(!t){n.add(e.path),Ut(e.index)&&(r=!0);continue}a.delete(e.path),(t.index!==e.index||t.working_dir!==e.working_dir)&&n.add(e.path),!r&&Ut(t.index)!==Ut(e.index)&&(r=!0)}for(let[e,t]of a)n.add(e),Ut(t.index)&&(r=!0);let o=t.diffStats,s=e?.diffStats;if(o!==void 0&&o!==s){let e=s??{};for(let t in o){let r=o[t],i=e[t];(!i||i.insertions!==r.insertions||i.deletions!==r.deletions)&&n.add(t)}for(let t in e)t in o||n.add(t)}return{changed:i||n.size>0,changedPaths:n,indexChanged:r}},Gt=e=>!e||e.trim().length===0,Kt=e=>(e||``).trim()===`U`,qt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Kt(t)||Kt(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},Jt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Kt(t)||Kt(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},Yt=e=>Gt(e.index)&&Gt(e.working_dir),Q=o()(c((e,t)=>({directories:new Map,activeDirectory:null,setActiveDirectory:n=>{let{activeDirectory:r,directories:i}=t();if(r!==n)if(r&&Rt(r),n&&Rt(n),n&&!i.has(n)){let t=new Map(i);t.set(n,Z()),e({activeDirectory:n,directories:t})}else e({activeDirectory:n})},getDirectoryState:e=>t().directories.get(e)??null,fetchStatus:async(n,r,i={})=>{let a=i.mode??`full`,o=It(n,a),s=jt.get(o)??(a===`light`?jt.get(It(n,`full`)):void 0);if(s)return s;let c=(async()=>{let{silent:a=!1}=i,{directories:o}=t(),s=o.get(n);if(s||=Z(),!a){let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingStatus:!0}),e({directories:r})}let c=!1;try{let a=Date.now(),o=s.isGitRepo!==!0||a-(s.lastRepoCheckAt||0)>_t,l=s.isGitRepo===!0;if(o&&(l=await r.checkIsGitRepository(n)),!l){let r=new Map(t().directories),i=r.get(n)??s;return r.set(n,{...i,isGitRepo:!1,status:null,isLoadingStatus:!1,lastRepoCheckAt:a,lastStatusFetch:a}),e({directories:r}),!1}let u=await r.getGitStatus(n,i.mode?{mode:i.mode}:void 0),d=t().directories.get(n)??Z(),f=Nt.get(n),p=f?.received===u&&f.stored===d.status?null:Wt(d.status,u);if(p?.changed){c=!0;let r=new Map(t().directories),i=r.get(n)??Z(),{changedPaths:s,indexChanged:l}=p,d=new Map(i.diffCache);for(let e of s)d.delete(e);let f=s.size>0;f&&Rt(n);let m={...u,diffStats:u.diffStats===void 0&&i.status?.diffStats!==void 0?i.status.diffStats:u.diffStats,upstreamComparison:u.upstreamComparison===void 0?i.status?.upstreamComparison:u.upstreamComparison};r.set(n,{...i,isGitRepo:!0,status:m,diffCache:d,indexRevision:l?i.indexRevision+1:i.indexRevision,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:f?Date.now():i.lastStatusChange}),e({directories:r}),Nt.set(n,{received:u,stored:m})}else{Nt.set(n,{received:u,stored:d.status});let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isGitRepo:!0,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:i.lastStatusChange}),e({directories:r})}}catch(e){console.error(`Failed to fetch git status:`,e)}finally{if(!a){let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingStatus:!1}),e({directories:r})}}return c})();jt.set(o,c);try{return await c}finally{jt.get(o)===c&&jt.delete(o)}},moveStatusPathsOptimistically:(n,r,i)=>{let a=new Set(r.map(e=>e.trim()).filter(Boolean));if(a.size===0)return null;let{directories:o}=t(),s=o.get(n),c=s?.status??null;if(!s||!c)return c;let l=!1,u=[];for(let e of c.files){if(!a.has(e.path)){u.push(e);continue}let t=i===`stage`?qt(e):Jt(e);t!==e&&(l=!0),Yt(t)?l=!0:u.push(t)}if(!l)return c;let d=new Map(o);return d.set(n,{...s,status:{...c,files:u,isClean:u.length===0},indexRevision:s.indexRevision+1,lastStatusChange:Date.now()}),e({directories:d}),c},restoreStatus:(n,r)=>{let{directories:i}=t(),a=i.get(n);if(!a)return;let o=new Map(i);o.set(n,{...a,status:r,indexRevision:a.indexRevision+1,lastStatusChange:Date.now()}),e({directories:o})},bumpIndexRevision:n=>{let{directories:r}=t(),i=r.get(n);if(!i)return;let a=new Map(r);a.set(n,{...i,indexRevision:i.indexRevision+1}),e({directories:a})},fetchBranches:async(r,i,a={})=>{let o=n(),s=zt(r);{let n=new Map(t().directories),i=n.get(r)??Z();n.set(r,{...i,isLoadingBranches:!0}),e({directories:n})}try{let c=a.force?await N(r,i,void 0,o):await O(r,i,void 0,o);if(s!==At.get(r)||o!==n())return;let l=new Map(t().directories),u=l.get(r)??Z();l.set(r,{...u,branches:c,branchesTransportIdentity:o,isLoadingBranches:!1,lastBranchesFetch:Date.now()}),e({directories:l})}catch(i){if(ht(i)||console.error(`Failed to fetch git branches:`,i),s!==At.get(r)||o!==n())return;let a=new Map(t().directories),c=a.get(r)??Z();a.set(r,{...c,isLoadingBranches:!1}),e({directories:a})}},fetchLog:async(n,r,i)=>{let{directories:a}=t(),o=a.get(n),s=i??o?.logMaxCount??25;{let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingLog:!0}),e({directories:r})}try{let i=await r.getGitLog(n,{maxCount:s}),a=new Map(t().directories),o=a.get(n)??Z();a.set(n,{...o,log:i,isLoadingLog:!1,lastLogFetch:Date.now(),logMaxCount:s}),e({directories:a})}catch(r){console.error(`Failed to fetch git log:`,r);let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,isLoadingLog:!1}),e({directories:i})}},fetchIdentity:async(n,r)=>{{let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingIdentity:!0}),e({directories:r})}try{let i=await r.getCurrentGitIdentity(n),a=new Map(t().directories),o=a.get(n)??Z();a.set(n,{...o,identity:i,isLoadingIdentity:!1,lastIdentityFetch:Date.now()}),e({directories:a})}catch(r){console.error(`Failed to fetch git identity:`,r);let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,isLoadingIdentity:!1}),e({directories:i})}},fetchAll:async(n,r,i={})=>{let{directories:a}=t(),o=a.get(n);if(!o){o=Z();let t=new Map(a);t.set(n,o),e({directories:t})}let{force:s=!1,silentIfCached:c=!1}=i,l=Date.now();await t().fetchStatus(n,r,{silent:c&&!!o?.status});let u=t().directories.get(n);if(!u?.isGitRepo)return;await t().fetchBranches(n,r,{force:s});let d=l-(u.lastLogFetch||0);(s||d>gt||!u.log)&&await t().fetchLog(n,r),await t().fetchIdentity(n,r)},getDiff:(e,n)=>t().directories.get(e)?.diffCache.get(n)??null,setDiff:(n,r,i)=>{let a=new Map(t().directories),o=a.get(n)??Z(),s=new Map(o.diffCache);s.set(r,{...i,fetchedAt:Date.now()});let c=Vt(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{Rt(n);let r=new Map(t().directories),i=r.get(n);i&&(r.set(n,{...i,diffCache:new Map}),e({directories:r}))},fetchAllDiffs:async(e,n)=>{let r=t().directories.get(e);if(!r?.status?.files||r.status.files.length===0)return;let i=r.status.files.map(e=>e.path).slice(0,xt);await t().prefetchDiffs(e,n,i,{maxFiles:xt})},prefetchDiffs:async(n,r,i,a={})=>{let o=t().directories.get(n);if(!o?.status?.files||o.status.files.length===0||i.length===0)return;let{maxFiles:s=St}=a,c=Math.min(Math.max(1,s),Et),l=Ft(o.status),u=o.status.diffStats,d=Bt(n),f=[],p=new Set;for(let e of i){if(p.size>=c)break;if(!e||p.has(e)||!l.has(e))continue;let t=u?.[e];t&&t.insertions+t.deletions>Tt||(p.add(e),!o.diffCache.has(e)&&(d.has(e)||f.push(e)))}let m=f;if(m.length===0)return;let h=Lt(n);if(typeof document<`u`&&document.hidden)return;m.forEach(e=>d.add(e));let g=0,_=[],v=()=>{let e=g;return g+=1,e<m.length?m[e]:null},y=async e=>{let t=r.getGitFileDiff(n,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${wt}ms`)),wt)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},b=async()=>{for(;;){if(h!==Lt(n))return;let e=v();if(!e)return;try{_.push(await y(e))}catch{}finally{d.delete(e)}}},x=Math.min(Ct,m.length);if(await Promise.allSettled(Array.from({length:x},()=>b())),m.forEach(e=>d.delete(e)),h!==Lt(n))return;let S=new Map(t().directories),C=S.get(n);if(!C)return;let w=new Map(C.diffCache),T=Date.now();_.forEach(e=>{!e.diff.isBinary&&e.diff.original===``&&e.diff.modified===``||w.set(e.path,{...e.diff,fetchedAt:T})});let E=Vt(w);S.set(n,{...C,diffCache:E}),e({directories:S})},setLogMaxCount:(n,r)=>{let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,logMaxCount:r}),e({directories:i})},ensureStatus:async(e,n)=>{let r=t().directories.get(e),i=Date.now();r?.status&&i-r.lastStatusFetch<vt||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=Mt.get(e);if(r)return r;let i=(async()=>{let r=t().directories.get(e),i=Date.now();(!r?.status||r.status.diffStats===void 0||i-(r?.lastStatusFetch??0)>=vt)&&await t().fetchStatus(e,n,{silent:!!r?.status});let a=t().directories.get(e);if(!a?.isGitRepo)return;let o=[];(!a.branches||i-a.lastBranchesFetch>=yt)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=gt)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=bt)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return Mt.set(e,i),i.finally(()=>{Mt.get(e)===i&&Mt.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),Xt=e=>{let t=(0,U.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status??null:null,t[0]=e,t[1]=n),Q(n)},Zt=e=>{let r=(0,U.c)(3),i=H.useSyncExternalStore(t,n,n),a;return r[0]!==e||r[1]!==i?(a=t=>{if(!e)return null;let n=t.directories.get(e);return n?.branchesTransportIdentity===i?n.branches:null},r[0]=e,r[1]=i,r[2]=a):a=r[2],Q(a)},Qt=e=>{let t=(0,U.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isGitRepo??null:null,t[0]=e,t[1]=n),Q(n)},$t=e=>{let t=(0,U.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status?.current?.trim()??null:null,t[0]=e,t[1]=n),Q(n)},en=e=>{let t=(0,U.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=H.useRef(n),i;return t[1]===e?i=t[2]:(i=t=>{let n=r.current,i=n.size===e.length;if(i)for(let r of e){let e=t.directories.get(r),a=n.get(r);if(!a||(e?.isGitRepo??null)!==a.isGitRepo||(e?.status?.current??null)!==a.branch){i=!1;break}}if(i)return n;let a=new Map;for(let n of e){let e=t.directories.get(n);a.set(n,{isGitRepo:e?.isGitRepo??null,branch:e?.status?.current??null})}return r.current=a,a},t[1]=e,t[2]=i),Q(i)},tn=e=>{let t=(0,U.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingStatus??!1:!1,t[0]=e,t[1]=n),Q(n)},nn=e=>{let t=(0,U.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingBranches??!1:!1,t[0]=e,t[1]=n),Q(n)},rn=e=>{let t=String(e||``).trim().replace(/^remotes\//,``);if(!t)return null;let n=t.indexOf(`/`);return n<=0||n>=t.length-1?null:{remote:t.slice(0,n),branch:t.slice(n+1)}},$=e=>String(e||``).trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/^remotes\//,``),an=e=>e.branchName?$(e.branchName):e.mode===`existing`?$(e.existingBranch||e.preferredName||``):$(e.preferredName||``),on=async e=>{let t=await Se(e);try{let n=rn((await me(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=rn((await pe(e)).tracking);if(t?.remote)return t.remote}catch{}return null},sn=async(e,t)=>{let n=await on(e),r=$(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},cn=async(e,t,n)=>{let r=an(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await sn(e,r):i&&$(r)?{setUpstream:!0,upstreamRemote:i,upstreamBranch:$(r)}:null;return a?{...t,setUpstream:t.setUpstream??a.setUpstream,upstreamRemote:t.upstreamRemote||a.upstreamRemote,upstreamBranch:t.upstreamBranch||a.upstreamBranch}:t},ln=async(e,t,n)=>{let r=await cn(e.path,t,n);return Ce(e,r)},un=`yuri:lastWorktreeSourceBranch`,dn=({mode:e,sourceBranch:t,linkedPr:n,selectedBranch:r})=>e===`existing-branch`?r||null:n?null:t||null,fn=({branches:e,savedSourceBranch:t,rootBranch:n})=>t&&e.includes(t)&&t?{sourceBranch:t,shouldClearSavedSourceBranch:!1}:{sourceBranch:n&&e.includes(n)?n:e.includes(`main`)?`main`:e.includes(`master`)?`master`:e[0]??``,shouldClearSavedSourceBranch:!!t},pn=(e,t,n)=>{if(!e)return e;let r=t.length>0&&!/\s$/.test(t)&&!/^\s/.test(e)&&!/[([{]$/.test(t),i=n.length>0&&!/\s$/.test(e)&&!/^\s/.test(n)&&!/^[\])}.,;:!?]/.test(n);return`${r?` `:``}${e}${i?` `:``}`},mn=(e,t,n)=>{let r=pn(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},hn=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=mn(r,i,a),s=Math.max(0,o.indexOf(r)),c=i.length+s;return{text:`${i}${o}${a}`,caret:i.length+o.length,start:c,end:c+r.length}},gn=(e,t)=>{let n=e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`;return new Set(e.map(n)).has(n(t))||e.some(e=>e.range.start<t.range.end&&t.range.start<e.range.end)?[...e]:[...e,t]},_n=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{Fe as C,Ae as D,ke as E,we as O,We as S,Ne as T,Q as _,un as a,ot as b,ln as c,$t as d,Zt as f,Xt as g,en as h,mn as i,on as l,tn as m,gn as n,fn as o,nn as p,hn as r,dn as s,_n as t,cn as u,Qt as v,Pe as w,it as x,mt as y};