@yuriai/web 0.2.12 → 0.2.14
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.
- package/dist/assets/{AssistantView-DU3Q-GKG.js → AssistantView-Ba0QibJU.js} +3 -3
- package/dist/assets/{DiagramView-YnLo2AT2.js → DiagramView-B7Z-RJUd.js} +1 -1
- package/dist/assets/{GuiPluginSurface-d2b15A6E.js → GuiPluginSurface-DCkAA0R4.js} +1 -1
- package/dist/assets/{GuiPluginWindow-X2qtGb-7.js → GuiPluginWindow-pZqqyXGs.js} +1 -1
- package/dist/assets/MarkdownRenderer-CYvVcdhy.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-DzjvFzLO.js → MarkdownRendererImpl-C_h6Vpba.js} +2 -2
- package/dist/assets/{MarkstreamRendererImpl-DzM6YvFv.js → MarkstreamRendererImpl-BE2iZJll.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-BLTmtkxn.js → MobileDetailNavigation-D57BJCZT.js} +1 -1
- package/dist/assets/MobileResizableSheet-BdOIJ61C.js +1 -0
- package/dist/assets/MobileShareBridge-BMbgy_Y9.js +4 -0
- package/dist/assets/MobileTabPageHeader-BW9y2zRG.js +2 -0
- package/dist/assets/{MultiRunWindow-B-z-Hlxt.js → MultiRunWindow-qgKnxGjk.js} +1 -1
- package/dist/assets/{SettingsView-DZaVLtN_.js → SettingsView-RfNOKLm3.js} +8 -8
- package/dist/assets/{SettingsWindow-Dk7zBIhW.js → SettingsWindow-tXzBaLS_.js} +1 -1
- package/dist/assets/{TerminalView-BRZXzdsv.js → TerminalView-aZe7_W0A.js} +1 -1
- package/dist/assets/{ToolOutputDialog-u_nwyfmh.js → ToolOutputDialog-BVplHxKd.js} +3 -3
- package/dist/assets/appThemeRegistry-Br3aTf8c.js +1 -0
- package/dist/assets/{capgoAdapter-oYpF3Iys.js → capgoAdapter-VGW_DUcK.js} +1 -1
- package/dist/assets/device-DzWRCXhq.js +2 -0
- package/dist/assets/dropdown-menu.styles-EKni18O6.js +1 -0
- package/dist/assets/{fileMentionTouchSelection-DLB9NaT8.js → fileMentionTouchSelection-f8n4X8BW.js} +1 -1
- package/dist/assets/gitApi-CjQVuhXI.js +10 -0
- package/dist/assets/gitApiHttp-BtI23x-7.js +7 -0
- package/dist/assets/host-BoCxB_x4.js +1 -0
- package/dist/assets/insertionBoundaries-DQMPnN81.js +1 -0
- package/dist/assets/main-CIqFfTRC.js +2 -0
- package/dist/assets/main-DrimNmCT.js +169 -0
- package/dist/assets/mcpQueries-DJfEAbB6.js +1 -0
- package/dist/assets/miniChat-C6iONZ7A.js +2 -0
- package/dist/assets/mobile-EJ2ArrGZ.js +2 -0
- package/dist/assets/{mobileBackNavigation-PW9PKRp9.js → mobileBackNavigation-DCfPeDp4.js} +1 -1
- package/dist/assets/multirun-Cw4SWn2h.js +3 -0
- package/dist/assets/native-config-D_5OLigY.js +1 -0
- package/dist/assets/platform-syRnKuVU.js +1 -0
- package/dist/assets/{projectMeta-paQJnzSj.js → projectMeta-DbrpqsSQ.js} +1 -1
- package/dist/assets/{readiness-CD8PmDO8.js → readiness-D-k9h36r.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-Bnv9tCyw.js +2 -0
- package/dist/assets/renderMobileApp-C1wyf84w.js +28 -0
- package/dist/assets/runtimeConfig-V7w7piDM.js +2 -0
- package/dist/assets/runtimeEndpointReset-86pXjFoO.js +149 -0
- package/dist/assets/{scheduledTaskNavigation-fnceJcDf.js → scheduledTaskNavigation-DPl7XI48.js} +1 -1
- package/dist/assets/{sessionChangeSummary-BsydkEi-.js → sessionChangeSummary-DdG2p-qM.js} +1 -1
- package/dist/assets/sessionLookup-En7eKd0r.js +1 -0
- package/dist/assets/{sortable-tabs-strip-DR90BVpO.js → sortable-tabs-strip-Bp_bMUwf.js} +1 -1
- package/dist/assets/{speechSettingsQueries-DLQhKWB7.js → speechSettingsQueries-DJpyiHX1.js} +1 -1
- package/dist/assets/terminalApi-Dw1h9m3h.js +1 -0
- package/dist/assets/{types-BC9_N4bU.js → types-CVQBgR8T.js} +1 -1
- package/dist/assets/{useAppFontEffects-BR5PcExE.js → useAppFontEffects-CeYo_5_Z.js} +27 -27
- package/dist/assets/{useDesktopWindowControlsLayout-BXU-GCDJ.js → useDesktopWindowControlsLayout-BhIAC-yK.js} +1 -1
- package/dist/assets/useEffectiveDirectory-DvnOvqoO.js +1 -0
- package/dist/assets/{useFontPreferences-B4l7mbDx.js → useFontPreferences-B4LGrKaG.js} +1 -1
- package/dist/assets/useMobileNavigationStore-mTG_inGR.js +417 -0
- package/dist/assets/{useWorkerHighlightedLines-D5244yEp.js → useWorkerHighlightedLines-Ez7d_RoZ.js} +1 -1
- package/dist/index.html +8 -7
- package/dist/mini-chat.html +8 -7
- package/dist/mobile.html +8 -7
- package/package.json +1 -1
- package/dist/assets/MarkdownRenderer-Fn6_Gozt.js +0 -2
- package/dist/assets/MobileResizableSheet-CVZyFmiP.js +0 -1
- package/dist/assets/MobileShareBridge-DmFvN9Yu.js +0 -4
- package/dist/assets/MobileTabPageHeader-B_IlXMaq.js +0 -2
- package/dist/assets/appThemeRegistry-DQncRaH8.js +0 -1
- package/dist/assets/device-VqNjblDR.js +0 -2
- package/dist/assets/dropdown-menu.styles-BneT70Wd.js +0 -1
- package/dist/assets/gitApi-DmsP48X9.js +0 -10
- package/dist/assets/host-BlpgWo6Q.js +0 -1
- package/dist/assets/insertionBoundaries-CdkyD16g.js +0 -1
- package/dist/assets/main-CizaES-l.js +0 -169
- package/dist/assets/main-DGdMB0a9.js +0 -2
- package/dist/assets/mcpQueries-D-ACeQhU.js +0 -1
- package/dist/assets/miniChat-DFw_Yk31.js +0 -2
- package/dist/assets/mobile-D-9RyRP2.js +0 -2
- package/dist/assets/multirun-CkF_yWhp.js +0 -3
- package/dist/assets/native-config-eNF46MQE.js +0 -1
- package/dist/assets/platform-DUe-qtEp.js +0 -7
- package/dist/assets/renderElectronMiniChatApp-B7G6Pb13.js +0 -2
- package/dist/assets/renderMobileApp-Cfw5ds5r.js +0 -28
- package/dist/assets/runtimeConfig-OWlkIGor.js +0 -2
- package/dist/assets/runtimeEndpointReset-2OM4_xI2.js +0 -149
- package/dist/assets/sessionLookup-C4d1itBe.js +0 -1
- package/dist/assets/terminalApi-BuoB9-0z.js +0 -1
- package/dist/assets/useEffectiveDirectory-BKQn4QdT.js +0 -1
- package/dist/assets/useMobileNavigationStore-DiH8EKl-.js +0 -417
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{A as e,C as t,E as n,F as r,I as i,M as a,P as o,S as s,T as c,_ as l,a as u,b as d,g as f,h as p,i as m,k as h,n as g,o as _,r as v,t as y,v as ee,x as b}from"./vendor-opencode-client-fxfj4IA_.js";import{i as te}from"./vendor-tanstack-query-core-BWz0ose6.js";import{n as ne,r as re}from"./fileQueries-DbUx7NwP.js";import{o as ie}from"./path-utils-jGozTg9d.js";import{n as ae}from"./pathNormalization-ewtPqJWn.js";import{t as x}from"./native-errors-06if6eu-.js";import{i as oe,o as se}from"./fileReferenceParser-1HHDBUum.js";import{n as S,t as ce}from"./vendor-solid-js-Dmt4_-Zk.js";import{a as le,c as ue,d as de,f as C,h as w,i as T,l as E,m as D,n as fe,o as O,p as pe,r as me,s as he,t as ge,u as _e}from"./vendor-opencode-plugin-CQ5ogY33.js";import{Et as k,mt as A,pt as j,y as M}from"./vendor-effect-DV9F8PTZ.js";var N={"@opencode/plugin/gui":O,"@opencode/plugin/gui/main":O,"@opencode/plugin/gui/file":le,"@opencode/plugin/gui/review":T,"@opencode/plugin/gui/browser":me,"@opencode/plugin/rpc":ge,"@opencode/schema/rpc":fe,"@opencode/client":i,"@opencode/client/effect":g,"@opencode/client/solid":y,effect:M,"solid-js":a,"solid-js/web":S,"solid-js/store":u},P=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 F(){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 I(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(N,e))return N[e];if(e===`electron`||e.startsWith(`node:`)||P.has(e))return F();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 x(`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 x(`GUI_PLUGIN_UNSUPPORTED`,`OS-restricted plugins require the native GUI host`);if(!Array.isArray(i.os)||!i.os.includes(t))throw new x(`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)||!k(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(e){let t=e;if(/^file:/i.test(t)){let e=new URL(t);t=`${e.hostname&&e.hostname!==`localhost`?`//${e.hostname}`:``}${decodeURIComponent(e.pathname)}`,/^\/[a-z]:\//i.test(t)&&(t=t.slice(1))}let n=ae(t)??``;return n===`.`?``:n}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,ve=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,r,i){this.files=e,this.query=t,this.transport=r,this.root=i,this.root=L(i),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 r=n();return this.ended||r&&this.endedOwners.has(r)?Promise.resolve():(this.acquireApiLease(e),this.sync(e,t?.force))},unwatch:e=>this.releaseApiLease(n(),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 n=await this.query.fetchQuery({queryKey:[`gui-plugin-files`,r,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 n.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{...re(this.files,this.input(e),this.transport),gcTime:3e4}}track(n,r){let i=this.resolve(n),a=c();if(!a||this.ended)return i;let o=`${r}:${i}`,s=this.subscriptions.get(o);s||(s={revision:t(0),listeners:new Set},this.subscriptions.set(o,s));let l=s;return l.listeners.has(a)||(l.listeners.add(a),e(a,()=>h(()=>{l.listeners.delete(a),!l.listeners.size&&this.subscriptions.get(o)===l&&this.subscriptions.delete(o)}))),l.revision[0](),i}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),p(()=>{this.changed(e,`file`),n?.notFound===!0!=(t.notFound===!0)&&this.changed(e,`missing`)}))}acquireApiLease(e){let t=n();if(this.ended||t&&this.endedOwners.has(t)||!this.files.statFile)return;let r=this.resolve(e),i=this.apiLeases.get(t);if(i?.has(r))return;if(this.leaseCount>=256)throw Error(`GUI file consumer limit exceeded`);let a=this.watch(r);i||(i=new Map,this.apiLeases.set(t,i)),i.set(r,a),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),p(()=>{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=ne(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(_(e)),ye=class{backend;transport;memory=new Map;resets=new Map;constructor(e,t){this.backend=e,this.transport=t}forPlugin(e,n){let r=(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])}`},i=e=>{if(n.aborted)throw Error(`GUI plugin has been disposed`);if(e!==void 0)throw Error(`Unsupported GUI storage migration: from`)},a=new Map;return{store:(e,o)=>{i(o.from);let s=r(e,o.scope),c=a.get(s);if(c)return c;if(a.size>=H)throw Error(`GUI plugin store limit exceeded`);let l=j(o.schema),u=A(o.schema),d=l(u(W(o.initial)));if(JSON.stringify(u(d)).length>U)throw Error(`GUI plugin store exceeds 2 MiB`);let f=d,p=this.backend.getItem(s);if(p!==null&&p.length<=U)try{f=l(JSON.parse(p))}catch{f=d}let[m,h]=t(f),g=e=>{i();let t=JSON.stringify(u(W(e)));if(t.length>U)throw Error(`GUI plugin store exceeds 2 MiB`);let n=l(JSON.parse(t));this.backend.setItem(s,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(s)??new Set;return y.add(v),this.resets.set(s,y),n.addEventListener(`abort`,()=>{y.delete(v),y.size||this.resets.delete(s),a.clear()},{once:!0}),a.set(s,_),_},memory:(e,t)=>{i();let n=r(e),a=this.memory.get(n);if(a)return[a[0],e=>{i(),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]=v(W(t.initial)),c=[o,e=>{i();let t=W(_(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(m(t))}];return this.memory.set(n,[o,e=>{let t=W(_(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(m(t))}]),c},remove:(e,t)=>{i(t?.from);let n=r(e,t?.scope);this.backend.removeItem(n);for(let e of this.resets.get(n)??[])e()}}}dispose(){this.memory.clear(),this.resets.clear()}},be=`yuri.file-icon`,G=`http://www.w3.org/2000/svg`,xe=new Set([`svg`,`g`,`path`,`rect`,`circle`,`ellipse`,`line`,`polyline`,`polygon`,`defs`,`linearGradient`,`radialGradient`,`stop`,`clipPath`,`mask`,`use`,`title`,`desc`]),K=e=>e.trim().replace(/^\./,``).toLowerCase();function q(e,t){if(typeof e!=`string`)throw Error(`GUI file icon requires SVG text`);let n=t.get(e);if(n)return n;if(e.length>16384)throw Error(`GUI file icon SVG exceeds 16 KiB`);let r=new TextEncoder().encode(e).byteLength;if(r>16384)throw Error(`GUI file icon SVG exceeds 16 KiB`);if(!/^\s*<svg[\s>]/.test(e)||/<!|<\?/.test(e))throw Error(`Invalid GUI file icon SVG`);let i=new DOMParser().parseFromString(e,`image/svg+xml`),a=i.documentElement;if(a?.localName!==`svg`||a.namespaceURI!==G||i.querySelector(`parsererror`))throw Error(`Invalid GUI file icon SVG`);for(let e of[a,...a.querySelectorAll(`*`)]){if(e.namespaceURI!==G||!xe.has(e.localName))throw Error(`Unsupported GUI file icon SVG element`);for(let t of e.attributes){let e=t.name.toLowerCase(),n=t.value.trim();if(e.startsWith(`on`)||e===`style`||e===`xml:base`||n.includes(`\\`)||Array.from(n).some(e=>e.charCodeAt(0)<32)||(e===`href`||e.endsWith(`:href`))&&!/^#[\w.-]+$/.test(n)||/url\s*\(/i.test(n)&&!/^url\(\s*#[\w.-]+\s*\)$/.test(n))throw Error(`Unsupported GUI file icon SVG reference or attribute`)}}let o={source:e,bytes:r,uri:`data:image/svg+xml,${encodeURIComponent(e)}`};return t.set(e,o),o}var Se=class{plugins=new Map;index=new Map;listeners=new Set;subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});get(e,t){if(t?.isDirectory)return;let n=e.split(/[\\/]/).at(-1)??``,r=t?.extension??(n.includes(`.`)?n.slice(n.lastIndexOf(`.`)+1):``),i=this.index.get(K(r));return t?.themeVariant===`light`?i?.light.uri:i?.dark.uri}replace(e,t){if(t.length>64)throw Error(`GUI file icon per-plugin limit exceeded`);if(!t.length){this.remove(e);return}let n=new Map;for(let t of this.plugins.get(e)??[])for(let e of[t.dark,t.light])n.set(e.source,e);let r=new Set,i=t.map(e=>{if(!e||typeof e!=`object`||!(`id`in e)||typeof e.id!=`string`||!e.id.trim()||e.id.length>128||r.has(e.id))throw Error(`Invalid or duplicate GUI file icon id`);if(r.add(e.id),!(`extensions`in e)||!Array.isArray(e.extensions)||!e.extensions.length||e.extensions.length>64)throw Error(`GUI file icon requires 1–64 extensions`);let t=e.extensions.map(e=>{if(typeof e!=`string`)throw Error(`Invalid GUI file icon extension`);let t=K(e);if(!/^[a-z0-9][a-z0-9_+-]{0,63}$/.test(t))throw Error(`Invalid GUI file icon extension`);return t}),i=q(`svg`in e?e.svg:void 0,n),a=`lightSvg`in e&&e.lightSvg!==void 0?q(e.lightSvg,n):i;return{id:e.id,extensions:[...new Set(t)],dark:i,light:a}}),a=i.length,o=i.reduce((e,t)=>e+t.dark.bytes+t.light.bytes,0);for(let[t,n]of this.plugins)t!==e&&(a+=n.length,o+=n.reduce((e,t)=>e+t.dark.bytes+t.light.bytes,0));if(a>512||o>8388608)throw Error(`GUI file icon total limit exceeded`);this.plugins.set(e,i),this.publish()}remove(e){this.plugins.delete(e)&&this.publish()}dispose(){this.plugins.clear(),this.publish(),this.listeners.clear()}publish(){let e=new Map;for(let t of this.plugins.values())for(let n of t)for(let t of n.extensions)e.set(t,n);let t=e.size!==this.index.size||[...e].some(([e,t])=>{let n=this.index.get(e);return n?.dark.uri!==t.dark.uri||n?.light.uri!==t.light.uri});if(this.index=e,t)for(let e of this.listeners)e()}},J=e=>e===`yuri.exportPDF`||e===`yuri.exportLongImage`,Ce=class{api;probe;clients=new Map;ended=!1;constructor(e){this.api=e}use(e,n){let r=this.clients.get(n),i=r?.get(e);if(i)return i.live;let[a,o]=t(this.api&&!n.aborted&&!this.ended?{status:`pending`}:{status:`inactive`,reason:`disabled`}),s=()=>{o({status:`inactive`,reason:`disabled`}),n.removeEventListener(`abort`,s),this.clients.delete(n)},c={live:w(a),stop:s};if(this.ended||n.aborted||(r||(r=new Map,this.clients.set(n,r)),r.set(e,c),n.addEventListener(`abort`,s,{once:!0}),!this.api))return c.live;let l=this.api;return this.probe??=Promise.resolve().then(()=>l.capabilities()),this.probe.then(t=>{if(this.ended||n.aborted)return;let r=e===`yuri.exportPDF`?`exportPDF`:`exportLongImage`;if(t.version!==1||!t[r]){o({status:`inactive`,reason:`disabled`});return}let i=async(e,t={})=>{if(this.ended||n.aborted||a().status!==`active`)return{status:`cancelled`};let i=AbortSignal.any([n,...t.signal?[t.signal]:[]]);try{return await l[r](e,{...t,signal:i})}catch(e){throw e&&typeof e==`object`&&`code`in e&&e.code===`EXPORT_UNSUPPORTED`&&o({status:`inactive`,reason:`failed`}),e}},s=Object.freeze(e===`yuri.exportPDF`?{version:1,limits:t.limits,exportPDF:i}:{version:1,limits:t.limits,exportLongImage:i});o({status:`active`,generation:1,value:s})}).catch(()=>{!this.ended&&!n.aborted&&o({status:`inactive`,reason:`failed`})}),c.live}dispose(){this.ended=!0;for(let e of this.clients.values())for(let t of e.values())t.stop();this.clients.clear()}};function we(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 x(`GUI_PLUGIN_UNSUPPORTED`,`GUI toast is unavailable`);if(!i||typeof i!=`object`)throw new x(`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 x(`GUI_PLUGIN_INVALID_INPUT`,`Invalid toast options`);if(u!==void 0||d!==void 0)throw new x(`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 Y=ee();function Te(e){return{version:1,register(t){let n=r(Y);if(!n||n.plugin!==e||n.signal.aborted||e.aborted)throw Error(`Preview actions require the owning mounted panel`);let i=new AbortController,a=AbortSignal.any([e,n.signal,i.signal]),o,s=()=>{a.removeEventListener(`abort`,s),i.abort(),o?.remove()};h(s),a.addEventListener(`abort`,s,{once:!0});try{o=t.render({element:t.element,signal:a,async snapshot(e={}){let r=AbortSignal.any([a,...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 i=await t.capture({...e,signal:r});if(r.throwIfAborted(),!n.content.contains(t.element))throw Error(`Preview capture region was replaced`);return i}}),a.throwIfAborted(),n.target.append(o)}catch(e){throw s(),e}return s}}}var X=e=>{throw new x(`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 Ee(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 De=class{options;fileIcons=new Se;instances=new Map;listeners=new Set;panelMounts=new Set;fileViews=new Map;changes=t(0);views=t(0);session=t();appearance;layouts=new Map;files;storage;ended=!1;contracts=new Map;snapshot=Object.freeze({plugins:Object.freeze([]),commands:Object.freeze([]),panels:Object.freeze([]),settings:Object.freeze([]),menuItems:Object.freeze([]),activePanel:null});screen;viewExports;constructor(e){this.options=e,this.viewExports=new Ce(e.viewExport),this.appearance=t({locale:e.locale,mode:e.mode,narrow:e.narrow}),this.storage=new ye(e.storage,e.transport);let n=()=>(this.session[0](),this.files?.api??X(`screen.file without a session`));this.screen=Z(`screen`,{get file(){return n()}})}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 ve(this.options.files,this.options.queryClient,this.options.transport,e.directory):void 0;let n=Z(`session.server`,{id:this.options.transport,name:this.options.transport,client:this.options.client}),r=e?Object.freeze(Z(`session`,{id:e.id,directory:e.directory,key:`${this.options.transport}\n${e.id}`,tab:e.id,server:n,pending:!1,visit:{},location:{directory:e.directory}})):void 0,i=this.snapshot;this.session[1](r),i===this.snapshot&&this.publish()}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})}install(r,i,a){let c=this.instances.get(r);if(this.ended||c?.status===`active`&&c.revision===i.revision&&c.native?.active!==!1){a?.dispose();return}c&&(this.instances.delete(r),this.release(c));let u={id:r,native:a,revision:i.revision,controller:new AbortController,status:`active`,cleanups:new Set,contributions:new Set,iconChanges:t(0),commands:[],panels:[],settings:[],menus:[]};this.instances.set(r,u);try{if(r===`yuri`||r.startsWith(`yuri.`))throw Error(`The yuri namespace is reserved to the host`);let t=I(i.code,a?.activation.os);s(r=>{u.dispose=r,u.root=n(),f(()=>l(D.Provider,{value:u.context=this.context(u,t,i.options),get children(){u.owner=n();let e=o(()=>t.setup?.(u.context));if(typeof e==`function`)u.cleanups.add(()=>{Promise.resolve(e()).catch(e=>{u.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(u,e)),u.controller.signal.aborted||e(u.owner,()=>b(()=>{if(u.iconChanges[0](),!u.controller.signal.aborted)try{let e=[...u.contributions].filter(e=>e.registry===be).map(e=>e.read()).filter(e=>e!==void 0);this.fileIcons.replace(u.id,e),u.iconError!==void 0&&o(()=>{u.iconError=void 0,this.publish()})}catch(e){o(()=>{this.fileIcons.remove(u.id),u.iconError=e instanceof Error?e.message:String(e),this.publish()})}})),u.controller.signal.aborted||e(u.owner,()=>b(()=>{this.changes[0](),this.session[0](),this.appearance[0]();try{this.derive(u)}catch(e){o(()=>this.fail(u,e))}o(()=>this.publish())}))})}catch(e){this.fail(u,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.panels=[],e.settings=[],e.menus=[],this.fileIcons.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 x&&(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,p(()=>{for(let e of[...this.instances.keys()])this.uninstall(e)}),this.viewExports.dispose(),this.files?.dispose(),this.fileIcons.dispose(),this.storage.dispose(),this.layouts.clear(),this.fileViews.clear(),this.contracts.clear(),this.listeners.clear())}own(e,t){let i=!0,a=()=>{i&&(i=!1,e.cleanups.delete(a),t())};return e.controller.signal.aborted||r(C)?.ended?(a(),a):(e.cleanups.add(a),n()&&h(a),a)}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,i){let a=this.storage.forPlugin(e.id,e.controller.signal),c=Object.fromEntries(Object.entries(t.stores??{}).map(([e,t])=>[e,t.scope===`global`?a.store(e,{...t,scope:`global`}):n=>a.store(e,{...t,scope:{session:n}})])),l=(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))},u=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)=>u.state(e,t)===`visible`?u.close(e,t):u.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(E).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=Te(e.controller.signal),p=w(()=>e.controller.signal.aborted?{status:`inactive`,reason:`disabled`}:{status:`active`,generation:1,value:f});return Z(`ctx`,{id:e.id,options:i,signal:e.controller.signal,client:this.options.client,storage:a,stores:c,toast:we(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:l,plural:(e,t,n)=>{let r=`${e}.${new Intl.PluralRules(this.appearance[0]().locale).select(t)}`;return l(r,{...n,count:t})===r?l(`${e}.other`,{...n,count:t}):l(r,{...n,count:t})},add:(t,i)=>{if(e.controller.signal.aborted||r(C)?.ended)return()=>{};if([`server`,`titlebar-item`,`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 a=()=>{},c,l=s(e=>{a=e,c=n();let r=()=>typeof i==`function`?i():i,o;if(t.id===`yuri.file-icon`){let e=d(()=>{try{return{ok:!0,value:r()}}catch(e){return{ok:!1,error:e}}});o=()=>{let t=e();if(!t.ok)throw t.error;return t.value}}else o=d(r);if(t.id===`style`){let e=document.createElement(`style`);document.head.append(e),h(()=>e.remove()),b(()=>{let t=o();e.textContent=t===void 0?``:String(t)})}return{registry:t.id,read:o}},n()??e.owner);e.contributions.add(l);let u=()=>{t.id===`yuri.file-icon`&&e.iconChanges[1](e=>e+1)};return o(u),o(()=>this.changed()),this.own(e,()=>{$(c,t=>{e.error??=String(t)}),a(),e.contributions.delete(l),o(u),o(()=>this.changed())})},list:e=>this.list(e),provide:(t,n)=>{if(e.controller.signal.aborted||r(C)?.ended)return()=>{};if(J(t.id)||t.id===`yuri.previewActions`)throw Error(`Preview/export 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 i=this.contract(t.id);if(i.provider)throw Error(`Contract already provided: ${t.id}`);return i.provider=e,i.live[1]({status:`active`,value:n,generation:++i.generation}),this.own(e,()=>{i.provider===e&&(i.provider=void 0,i.live[1]({status:`inactive`,reason:e.status===`failed`?`failed`:`disabled`}))})},use:t=>t.id===`yuri.previewActions`?t.kind===`contract`?p:X(`preview actions token must be a Contract`):J(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 x(`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 x(`GUI_PLUGIN_UNSUPPORTED`)}:()=>Promise.reject(new x(`GUI_PLUGIN_UNSUPPORTED`))})},sessions:{current:this.session[0],list:()=>{let e=this.session[0]();return e?[e]:[]}},screen:{current:()=>this.session[0]()?this.screen:void 0},layout:u,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:async e=>{let t=URL.createObjectURL(new Blob([e.content],{type:`text/plain`}));try{let n=document.createElement(`a`);return n.href=t,n.download=e.name,n.click(),!0}finally{setTimeout(()=>URL.revokeObjectURL(t),0)}}},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=>o(()=>{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,n=!1){let r=this.contracts.get(e);if(!r){if(this.contracts.size>=256)throw Error(`GUI contract limit exceeded`);let n=t({status:`inactive`,reason:`disabled`});r={live:[w(n[0]),n[1]],generation:0},this.contracts.set(e,r)}return n&&r.provider&&X(`IPC contract collision`),r}derive(e){if(e.status!==`active`)return;let t=[],n=[],r=[],i=[],a=this.session[0]();for(let o of e.contributions){if(o.registry===`yuri.file-icon`)continue;let s=o.read();if(s!==void 0){if(o.registry===he.id){let n=s;n.enabled!==!1&&t.push({key:`${e.id}.${n.id}`,title:n.title,description:n.description,bind:n.bind,hidden:n.hidden,run:()=>this.invoke(e,()=>n.run())})}else if(o.registry===_e.id&&a){let t=s,r=`${e.id}:`,i=this.layout(a).open.filter(e=>e.startsWith(r)).map(e=>e.slice(r.length));for(let r of t.list({session:a,screen:this.screen,open:i}))n.push({plugin:e,panel:t,tab:r})}else if(o.registry===de.id){let e=s;(e.page||e.section)&&X(`SettingsPage host sections`),e.title,r.push(e)}else if(o.registry===E.id){let e=s;e.menu===`session.panel`?(e.title,i.push(e)):X(`MenuItem.${e.menu}`)}}}for(let e of n)e.tab.title;e.commands=t,e.panels=n,e.settings=r,e.menus=i,o(()=>this.views[1](e=>e+1))}publish(){let e=o(this.session[0]),t=e?this.layouts.get(e.key):void 0,n=[...this.instances.values()],r=n.filter(e=>e.status===`active`),i=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(i),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}`,title:t.title,description:t.description,run:()=>{this.invoke(e,()=>t.run())}})))),activePanel:t?.shown&&i.some(e=>e.key===t.active)?t.active:null,sessionKey:e?.key});for(let e of this.listeners)e()}invoke(t,n){if(!t.controller.signal.aborted)try{let r=e(t.owner??null,n);if(r instanceof Promise)return r.catch(e=>this.fail(t,e))}catch(e){this.fail(t,e)}}command(e){return[...this.instances.values()].flatMap(e=>e.commands).find(t=>t.key===e)}runCommand(e){return this.command(e)?.run()}linkHandler(e){let t=[];for(let e of this.instances.values())for(let n of e.contributions)if(n.registry===ue.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=se(t.href);if(!n||!oe(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=ie(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.screen}: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?d(()=>{let e=r();return{tab:e,fields:Object.getPrototypeOf(e)===Object.prototype?Object.getOwnPropertyDescriptors(e):void 0}},void 0,{equals:Ee}):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.screen}}mountPanel(e,t,n){let r=this.panel(e);if(!r)return()=>{};let i=new AbortController,a=()=>{let a=d(()=>{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});b(()=>{let e=a();e&&(h(e.model.watch(e.file)),e.model.sync(e.file).catch(()=>{}))});let s=()=>o(()=>r.panel.render(this.props(e,!0)));return l(Y.Provider,{value:n?{plugin:r.plugin.controller.signal,signal:i.signal,content:t,target:n}:void 0,get children(){return s()}})},s=this.mount(r.plugin,t,()=>l(pe.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?r.plugin.context.layout.stored(e):[]}},get children(){return a()}})),c=()=>{this.panelMounts.delete(c),i.abort(),s()};return this.panelMounts.add(c),this.own(r.plugin,c)}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()=>{}}mount(e,t,r){if(e.controller.signal.aborted)return()=>{};let i=()=>{},a,s=t=>{queueMicrotask(()=>this.fail(e,t))};try{i=ce(()=>l(D.Provider,{value:e.context,get children(){return a=n(),f(()=>o(r),s)}}),t)}catch(t){this.fail(e,t)}return this.own(e,()=>{$(a,t=>{e.error??=String(t)}),i(),t.replaceChildren()})}};export{De as GuiPluginHost};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n}from"./runtime-switch-CAZiOV2G.js";import{C as r}from"./desktop-dp2Z0toS.js";import{t as i}from"./runtimeAPIRegistry-C2VogTny.js";import{a,i as o,r as s}from"./vendor-zustand-o69pgTEK.js";import{it as c,rt as l}from"./vendor-base-ui-CdzJ6My_.js";import{B as u,Ct as d,M as f,Mt as p}from"./platform-DUe-qtEp.js";import{b as m,n as ee,x as h}from"./useUIStore-NMQx_cnG.js";import{D as g,O as _}from"./persistence-BfjCXjLZ.js";import{n as v}from"./vendor-react-BP2cRVqX.js";import{s as y}from"./vendor-tanstack-react-query-CdqCAt40.js";import{a as b,o as x}from"./queryRuntime-BuRnpVtK.js";import{r as S}from"./vendor-reactuses-core-BJ-jJ4YM.js";import{f as te,r as C,u as ne}from"./button-DFX-UCuQ.js";import{Ea as re,Gn as w,Ht as ie,Ir as ae,S as T,Va as E,Za as oe,_t as se,bn as D,ct as ce,d as O,kr as le,lt as k,mo as A,po as ue,un as de,ut as fe,y as pe}from"./useMobileNavigationStore-DiH8EKl-.js";import{t as me}from"./AgentAvatar-DJCC3Aqe.js";import{n as j}from"./Icon-C1nXIg7J.js";import{g as he,v as ge}from"./gitApi-DmsP48X9.js";import{f as _e,o as M}from"./projectMeta-paQJnzSj.js";import{c as ve,d as ye,l as N,n as be,r as xe,t as Se}from"./fileMentionTouchSelection-DLB9NaT8.js";import{n as Ce}from"./textarea-BuvlUTo2.js";var we=(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=w([...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)},Te=(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}),Ee=(e,t)=>e.highlightedIndex===t.highlightedIndex&&Te(e.rows,t.rows),De=(e,t)=>Te(e,t)?e:t.slice(),Oe=(e,t,n)=>{e&&(t.current&&Ee(t.current,n)||(t.current=n,e(n)))},ke=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},P=e(c(),1),F=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},I=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,L=(e,t)=>{let n=F(t),r=F(e);if(!n||!r)return!1;let i=I(n),a=I(r);return a===i||a.startsWith(`${i}/`)},Ae=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=F(e);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=>F(e)).filter(e=>L(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>F(e)).filter(e=>L(e,t)))):[],s=typeof i.selectedPath==`string`?F(i.selectedPath):null,c=s&&L(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]));n[t]={openPaths:e,selectedPath:u.selectedPath??c??e[0]??null,expandedPaths:r,touchedAt:Math.max(u.touchedAt,l)};continue}n[t]={openPaths:a,selectedPath:c,expandedPaths:o,touchedAt:l}}return n},R=(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},z=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},je=a()(s(o((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=F((t||``).trim()),a=F((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!L(a,i)||e(e=>{let t=e.byRoot[i],n=z(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:R({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=I(i),a=e=>I(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:R({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=I(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=I(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:R({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=I(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=I(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:R({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=F((t||``).trim()),a=n?F(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!L(a,i)||e(e=>{let t=e.byRoot[i],n=z(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:R({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=F((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=F((t||``).trim()),i=F((n||``).trim());!r||!i||!L(i,r)||e(e=>{let t=e.byRoot[r],n=z(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:R({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||!L(i,r)||e(e=>{let t=e.byRoot[r],n=z(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:R({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=F((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>F((e||``).trim())).filter(e=>e&&L(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=z(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:R({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:m(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:Ae(t)}},partialize:e=>({byRoot:Ae(e.byRoot)})}),{name:`files-view-tabs-store`})),B=v(),Me=(e,t)=>{let n=(0,B.c)(4),r=t===void 0?200:t,[i,a]=P.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]),P.useEffect(o,s),i},Ne=()=>{let e=(0,B.c)(17),t=O(Pe),n=D(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=T(r),a=O(V),o=O(H),s=A(U),c=A(Fe),l=d(Ie);if(t){let r;e[2]===i?r=e[3]:(r=pe(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 Pe(e){return e.currentSessionId}function V(e){return e.worktreeMetadata}function H(e){return e.newSessionDraft}function U(e){return e.activeProjectId}function Fe(e){return e.projects}function Ie(e){return e.currentDirectory}var W=l(),Le=`bg-transparent font-[inherit] text-[var(--primary-base)]`,Re=(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,W.jsx)(`mark`,{className:Le,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},ze=P.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:i,onClose:a,style:o,onRowsChange:s},c)=>{let{t:l}=te(),u=Ne()??``,d=O(e=>e.currentSessionId),f=ae(e=>e.activeSessions),m=ie({enabled:!!i}),h=A(e=>e.activeProjectId),v=A(e=>e.projects),y=P.useMemo(()=>v.find(e=>e.id===h)?.path??null,[h,v]),b=P.useMemo(()=>{let e=y||u;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[y,u]),x=je(e=>b?e.byRoot[b]:void 0),w=re(e=>e.agents),T=p(e=>e.searchFiles),D=Me(e,180),ue=_(),de=g(),[pe,he]=P.useState([]),[ge,_e]=P.useState(!1),[M,ye]=P.useState(0),N=P.useRef(0),we=P.useRef({query:e,directory:u,ids:[]}),[Te,Ee]=P.useState(360),[De,F]=P.useState({}),[I,L]=P.useState({}),Ae=P.useRef([]),R=P.useRef([]),z=P.useRef([]),B=P.useRef(null),Pe=P.useRef(null),V=P.useRef(null);V.current||=Se();let H=ee(e=>e.isMobile),U=(e??``).trim(),Fe=oe({directory:u||null}),Ie=P.useMemo(()=>r?Fe.data??[]:[],[r,Fe.data]),Le=P.useMemo(()=>{if(!b||!x)return[];let e=[x.selectedPath,...x.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(`${b}/`)?e.slice(b.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return fe(n,U,{limit:6})},[U,b,x]),ze=P.useMemo(()=>n?E(w).filter(e=>e.mode!==`primary`):[],[w,n]),Be=P.useMemo(()=>i?ce({sessions:le(f,m),currentSessionId:d,searchQuery:U}):[],[f,d,m,U,i]),G=Le,Ve=pe,K=P.useMemo(()=>ve({skills:Ie,agents:ze,sessions:Be,recentFiles:G,pathHits:Ve,searchQuery:U,untitledSession:l(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:l(`chat.fileMentionAutocomplete.sessionType`),skillBadge:l(`chat.commandAutocomplete.badge.skill`)}),[Ie,ze,Be,G,Ve,U,l]);P.useEffect(()=>{let e=e=>{let t=e.target;!t||!B.current||B.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),P.useEffect(()=>{if(!u){he([]);return}let e=(D??``).trim(),t=se(e);if(!t){he([]);return}let n=!1;_e(!0);let r={includeHidden:ue,respectGitignore:!de};return Promise.all([T(u,t,80,{...r,type:`file`}),T(u,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(Le.map(e=>e.path));he(k({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{n||he([])}).finally(()=>{n||_e(!1)}),()=>{n=!0}},[u,D,Le,T,ue,de]),P.useLayoutEffect(()=>{let t=we.current,n=t.ids[N.current],r=t.query===e&&t.directory===u?Math.max(0,K.findIndex(e=>e.id===n)):0;we.current={query:e,directory:u,ids:K.map(e=>e.id)},N.current=r,ye(r)},[K,e,u]),P.useEffect(()=>{F({}),L({})},[K]),P.useEffect(()=>{Ae.current[M]?.scrollIntoView({block:`nearest`})},[M]),P.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};R.current.forEach((n,r)=>{if(!n)return;let i=z.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}}),F(e),L(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[K]),P.useEffect(()=>{let e=R.current[M];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&Ee(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[M]);let He=S(e=>{t(e)}),Ue=S(e=>{n?.(e)}),We=S(e=>{i?.(e)}),Ge=S(e=>{r?.(e)}),Ke=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&V.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&V.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(V.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>V.current?.pointerCancel(),onClick:()=>{V.current?.click(t)},onMouseMove:()=>{N.current=e,ye(e)}}),q=e=>{let t=K.length;if(t===0)return;let n=(e%t+t)%t,r=K[n];if(r.agentName!==void 0){Ue(r.agentName);return}if(r.id.startsWith(`skill:`)){let e=Ie.find(e=>r.id===`skill:${e.name}-${e.scope}`);e&&Ge(e);return}if(r.id.startsWith(`session:`)){let e=Be.find(e=>r.id===`session:${e.id}`);e&&We(e);return}let i=r.id.startsWith(`recent:`)?G.find(e=>r.id===`recent:${e.path}`):Ve.find(e=>r.id===`file:${e.path}`);i&&He(i)};P.useEffect(()=>{Oe(s,Pe,{rows:K,highlightedIndex:M})},[s,M,K]);let qe=P.useRef(s);return qe.current=s,P.useEffect(()=>()=>{ke(qe.current,Pe)},[]),P.useImperativeHandle(c,()=>({acceptIndex:e=>{q(e)},handleKeyDown:e=>{if(e===`Escape`){a();return}let t=K.length;if(t!==0){if(e===`ArrowDown`){N.current=(N.current+1)%t,ye(N.current);return}if(e===`ArrowUp`){N.current=(N.current-1+t)%t,ye(N.current);return}(e===`Enter`||e===`Tab`)&&q(N.current)}}})),(0,W.jsxs)(be,{ref:B,isMobile:H,className:`max-w-[640px] max-h-64`,style:o,children:[(0,W.jsx)(Ce,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,W.jsxs)(`div`,{className:`py-1`,children:[K.map((e,t)=>{let n=e.id.startsWith(`file:`)||e.id.startsWith(`recent:`),r=n?ne(e.title,{maxLength:60}):e.title,i=M===t,a=De[t]??!1,o=I[t]??2.6;return(0,W.jsxs)(`div`,{"data-mention-id":e.id,ref:e=>{Ae.current[t]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,H&&`min-h-11`,xe(H,i),!H&&i&&`text-interactive-selection-foreground`),...Ke(t,()=>q(t)),children:[(0,W.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center`,children:e.agentName===void 0?(0,W.jsx)(j,{name:e.iconName,className:`size-3.5 text-current`}):(0,W.jsx)(me,{name:e.agentName,size:20})}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`span`,{ref:e=>{R.current[t]=e},className:`relative block min-w-0 overflow-hidden file-mention-marquee-container`,style:i?{"--file-mention-marquee-width":`${Te}px`,"--file-mention-marquee-duration":`${o}s`}:void 0,title:e.title,children:[(0,W.jsx)(`span`,{ref:e=>{z.current[t]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:e.title}),n&&a&&i?(0,W.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Re(e.title,U)}):(0,W.jsx)(`span`,{className:`block truncate`,children:Re(r,U)})]}),e.subtitle?(0,W.jsx)(`div`,{className:C(`truncate text-muted-foreground`,H?`typography-micro`:`typography-meta`),children:Re(e.subtitle,U)}):null]})]},e.id)}),ge&&Ve.length===0?(0,W.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,W.jsx)(j,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!ge&&K.length===0&&(0,W.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:l(`chat.fileMentionAutocomplete.empty`)})]})}),!H&&(0,W.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:l(`chat.autocomplete.keyboardHint`)})]})}),Be=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`goal`,`btw`]),G=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&Be.has(n))},Ve=(e,t)=>!e||t({name:e}),K=` `,He=(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]===K&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},Ue=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,We=C(Ue,`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)]`),Ge=C(Ue,`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)]`),Ke=C(Ue,`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)]`),q=C(Ue,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),qe=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),Je=(e,t)=>{let n=!!e.sessionID;return{hasSession:n,canStartSessionCommand:n||e.hasNewDraft,canUseReviewHandoffFlow:n&&!t&&!r()}},Ye=P.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:i,style:a,commandPolicy:o,commandContext:s,onRowsChange:c},l)=>{let{t:u}=te(),d=ee(e=>e.isMobile),f=O(e=>e.currentSessionId),p=O(e=>!!e.newSessionDraft?.open),m=O(P.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=de(f??``,m??void 0),g=P.useMemo(()=>s??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[s,f,h.length,p]),{hasSession:_,canStartSessionCommand:v,canUseReviewHandoffFlow:y}=P.useMemo(()=>Je(g,d),[g,d]),b=g.hasMessages,[x,S]=P.useState([]),[ne,re]=P.useState(!1),w=ue({directory:i}),ie=P.useMemo(()=>w.data??[],[w.data]),ae=w.isFetching,[T,E]=P.useState(0),oe=P.useRef(0),se=P.useRef(!1),D=P.useRef([]),ce=P.useRef(null),le=P.useRef(!1),k=P.useRef(null),A=P.useRef(!1),fe=P.useRef(null);P.useEffect(()=>{let e=e=>{let t=e.target;!t||!ce.current||ce.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),P.useEffect(()=>{(async()=>{re(ae);try{let t=ie.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},..._&&!b?[{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}]:[],...y?[{id:`yuri:handoff-review`,name:`handoff-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isYuri:!0}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...v?[{id:`yuri:goal`,name:`goal`,source:`yuri`,description:u(`chat.goal.button.armAria`),isBuiltIn:!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=!b,a=we(n.filter(e=>(i||e.name!==`init`)&&(o?.(e)??!0)),e);S(e=>qe(e,a)?e:a)}catch{let t=!b,n=we([{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!b?[{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}]:[],...y?[{id:`yuri:handoff-review`,name:`handoff-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isYuri:!0}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...v?[{id:`yuri:goal`,name:`goal`,source:`yuri`,description:u(`chat.goal.button.armAria`),isBuiltIn:!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);S(e=>qe(e,n)?e:n)}finally{re(!1)}})()},[e,b,_,v,y,ie,ae,u,o]),P.useEffect(()=>{E(0)},[x]),P.useEffect(()=>{oe.current=T},[T]),P.useEffect(()=>{D.current[T]?.scrollIntoView({block:`nearest`})},[T]),P.useEffect(()=>{Oe(c,fe,{rows:N(x,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:T})},[x,c,T,u]);let pe=P.useRef(c);pe.current=c,P.useEffect(()=>()=>{ke(pe.current,fe)},[]),P.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=x[e];r&&t(r,G(r,n))},handleKeyDown:e=>{let r=x.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){se.current=!0,E(e=>(e+1)%r);return}if(e===`ArrowUp`){se.current=!0,E(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(oe.current%r+r)%r,i=x[n];i&&t(i,G(i,e===`Enter`))}}}}),[x,n,t]);let me=e=>{let t=ye(e);switch(e.name){case`new`:return(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,W.jsx)(j,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,W.jsxs)(be,{ref:ce,isMobile:d,className:`max-w-[450px] max-h-64`,style:a,children:[(0,W.jsx)(Ce,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:ne?(0,W.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,W.jsx)(j,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,W.jsxs)(`div`,{children:[x.map((n,r)=>{let i=n.isBuiltIn,a=n.isYuri;return(0,W.jsxs)(`div`,{ref:e=>{D.current[r]=e},className:C(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,xe(d,r===T),!d&&r===T&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(k.current={x:e.clientX,y:e.clientY},A.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!k.current)return;let t=e.clientX-k.current.x,n=e.clientY-k.current.y;Math.hypot(t,n)>6&&(A.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=A.current;k.current=null,A.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),le.current=!0,t(n,G(n,d)))},onPointerCancel:()=>{k.current=null,A.current=!1},onClick:()=>{if(le.current){le.current=!1;return}t(n,G(n,d))},onMouseMove:()=>{se.current=!1,E(r)},children:[(0,W.jsx)(`div`,{className:C(!d&&`mt-0.5`),children:me(n)}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,Re(n.name,e)]}),n.isSkill?(0,W.jsx)(`span`,{className:We,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,W.jsx)(`span`,{className:We,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,W.jsx)(`span`,{className:q,children:`Yuri`}):i?(0,W.jsx)(`span`,{className:q,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,W.jsx)(`span`,{className:n.scope===`project`?Ke:Ge,children:n.scope}):null,n.agent&&(0,W.jsx)(`span`,{className:q,children:n.agent})]}),n.description&&!d&&(0,W.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Re(n.description,e)})]})]},n.id)}),x.length===0&&(0,W.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,W.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});Ye.displayName=`CommandAutocomplete`;var Xe=2,Ze=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Qe=e=>{let t=e?.trim().replace(/\\/g,`/`);return t?t.length>1?t.replace(/\/+$/,``):t:null},$e=e=>Ze(e)&&Array.isArray(e.all)&&e.all.every(e=>typeof e==`string`)&&typeof e.current==`string`&&Ze(e.branches),J=(e,t)=>JSON.stringify([e,t]),et=e=>`version`in e&&e.version===Xe&&Ze(e.entries),tt=e=>{if(!e)return null;try{let t=JSON.parse(e);return Ze(t)?t.version===Xe&&Ze(t.entries)?{version:Xe,entries:t.entries}:t:null}catch{return null}},nt=(e,t)=>{try{e.setItem(`yuri.gitBranchCache`,JSON.stringify(t))}catch{}},rt=(e,t,n)=>{let r=Qe(e);if(!r||!t)return null;let i;try{i=n.getItem(`yuri.gitBranchCache`)}catch{return null}let a=tt(i);if(!a)return null;if(et(a))return $e(a.entries[J(t,r)])?a.entries[J(t,r)]:null;let o={};for(let[e,n]of Object.entries(a)){let r=Qe(e);r&&$e(n)&&(o[J(t,r)]=n)}return nt(n,{version:Xe,entries:o}),o[J(t,r)]??null},it=(e,t,n,r)=>{let i=Qe(e);if(!i||!t||!$e(n))return;let a=null;try{a=r.getItem(`yuri.gitBranchCache`)}catch{return}let o=tt(a);nt(r,{version:Xe,entries:{...o&&et(o)?o.entries:{},[J(t,i)]:n}})},at=3e4,Y=Qe,ot=(e,t=n())=>x.git.branches(Y(e),t),st=(e,t=n())=>x.git.remotes(Y(e),t),ct=async(e,t,n)=>{n.throwIfAborted();let r=i()?.git,a=t?.getGitBranches?await t.getGitBranches(e,{signal:n}):r?await r.getGitBranches(e,{signal:n}):await f(e,{signal:n});return n.throwIfAborted(),a},lt=async(e,t,n)=>{n.throwIfAborted();let r=i()?.git,a=t?.getRemotes?await t.getRemotes(e,{signal:n}):r?await r.getRemotes(e,{signal:n}):await u(e,{signal:n});return n.throwIfAborted(),a},ut=(e,t,r=n(),i=h())=>{let a=Y(e),o=t;return{queryKey:ot(a,r),queryFn:async({signal:e})=>{if(!a)throw Error(`Git branches require a directory`);let t=await ct(a,o,e);return it(a,r,t,i),t},staleTime:at,gcTime:1/0,initialData:()=>rt(a,r,i)??void 0,initialDataUpdatedAt:0}},dt=(e,t,r=n())=>{let i=Y(e),a=t;return{queryKey:st(i,r),queryFn:({signal:e})=>{if(!i)throw Error(`Git remotes require a directory`);return lt(i,a,e)},staleTime:at,gcTime:1/0}},ft=(e,r,i)=>{let a=(0,B.c)(9),o=i===void 0||i,s=P.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=Y(e),u=y,l=ut(c,r,s),a[0]=e,a[1]=r,a[2]=s,a[3]=c,a[4]=l,a[5]=u):(c=a[3],l=a[4],u=a[5]);let d=o&&!!c,f;return a[6]!==l||a[7]!==d?(f={...l,enabled:d},a[6]=l,a[7]=d,a[8]=f):f=a[8],u(f)},pt=(e,r,i)=>{let a=(0,B.c)(9),o=i===void 0||i,s=P.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=Y(e),u=y,l=dt(c,r,s),a[0]=e,a[1]=r,a[2]=s,a[3]=c,a[4]=l,a[5]=u):(c=a[3],l=a[4],u=a[5]);let d=o&&!!c,f;return a[6]!==l||a[7]!==d?(f={...l,enabled:d},a[6]=l,a[7]=d,a[8]=f):f=a[8],u(f)},mt=(e,t,r=b,i=n())=>r.fetchQuery(ut(e,t,i)),ht=(e,t,r=b,i=n())=>r.fetchQuery({...ut(e,t,i),staleTime:0}),gt=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,_t=1e4,vt=6e4,yt=5e3,bt=3e4,xt=6e4,St=25,Ct=40,wt=2,Tt=15e3,Et=500,Dt=30,Ot=20971520,kt=new Map,At=new Map,jt=new Map,X=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=>At.get(e)??0,Rt=e=>{let t=Lt(e)+1;return At.set(e,t),t},zt=e=>{let t=(jt.get(e)??0)+1;return jt.set(e,t),t},Bt=e=>{let t=kt.get(e);if(t)return t;let n=new Set;return kt.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=Dt,n=Ot)=>{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=a()(s((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=X.get(o)??(a===`light`?X.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)>vt,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})();X.set(o,c);try{return await c}finally{X.get(o)===c&&X.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 ht(r,i,void 0,o):await mt(r,i,void 0,o);if(s!==jt.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(gt(i)||console.error(`Failed to fetch git branches:`,i),s!==jt.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>_t||!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,St);await t().prefetchDiffs(e,n,i,{maxFiles:St})},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=Ct}=a,c=Math.min(Math.max(1,s),Dt),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>Et||(p.add(e),!o.diffCache.has(e)&&(d.has(e)||f.push(e)))}let m=f;if(m.length===0)return;let ee=Lt(n);if(typeof document<`u`&&document.hidden)return;m.forEach(e=>d.add(e));let h=0,g=[],_=()=>{let e=h;return h+=1,e<m.length?m[e]:null},v=async e=>{let t=r.getGitFileDiff(n,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${Tt}ms`)),Tt)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},y=async()=>{for(;;){if(ee!==Lt(n))return;let e=_();if(!e)return;try{g.push(await v(e))}catch{}finally{d.delete(e)}}},b=Math.min(wt,m.length);if(await Promise.allSettled(Array.from({length:b},()=>y())),m.forEach(e=>d.delete(e)),ee!==Lt(n))return;let x=new Map(t().directories),S=x.get(n);if(!S)return;let te=new Map(S.diffCache),C=Date.now();g.forEach(e=>{!e.diff.isBinary&&e.diff.original===``&&e.diff.modified===``||te.set(e.path,{...e.diff,fetchedAt:C})});let ne=Vt(te);x.set(n,{...S,diffCache:ne}),e({directories:x})},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<yt||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)>=yt)&&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>=bt)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=_t)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=xt)&&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,B.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,B.c)(3),i=P.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,B.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.log??null:null,t[0]=e,t[1]=n),Q(n)},$t=e=>{let t=(0,B.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)},en=e=>{let t=(0,B.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)},tn=e=>{let t=(0,B.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=P.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)},nn=e=>{let t=(0,B.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)},rn=e=>{let t=(0,B.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingLog??!1:!1,t[0]=e,t[1]=n),Q(n)},an=e=>{let t=(0,B.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)},on=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\//,``),sn=e=>e.branchName?$(e.branchName):e.mode===`existing`?$(e.existingBranch||e.preferredName||``):$(e.preferredName||``),cn=async e=>{let t=await _e(e);try{let n=on((await he(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=on((await ge(e)).tracking);if(t?.remote)return t.remote}catch{}return null},ln=async(e,t)=>{let n=await cn(e),r=$(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},un=async(e,t,n)=>{let r=sn(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await ln(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},dn=async(e,t,n)=>{let r=await un(e.path,t,n);return M(e,r)},fn=`yuri:lastWorktreeSourceBranch`,pn=({mode:e,sourceBranch:t,linkedPr:n,selectedBranch:r})=>e===`existing-branch`?r||null:n?null:t||null,mn=({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},hn=(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?` `:``}`},gn=(e,t,n)=>{let r=hn(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},_n=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=gn(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}},vn=(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]},yn=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{je as A,pt as C,ze as D,Ve as E,Ne as O,ft as S,He as T,tn as _,fn as a,$t as b,dn as c,en as d,Zt as f,Qt as g,nn as h,gn as i,De as j,Me as k,cn as l,rn as m,vn as n,mn as o,an as p,_n as r,pn as s,yn as t,un as u,Xt as v,Ye as w,ht as x,Q as y};
|