@openchambery/web 2.0.0-beta.7 → 2.0.0-beta.9
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-QJBDn5r6.js → AssistantView-CLFPj5Ki.js} +3 -3
- package/dist/assets/{DiagramView-DdJh8nnv.js → DiagramView-oeXj4YHn.js} +1 -1
- package/dist/assets/{MarkdownRenderer-mDkW7fMx.js → MarkdownRenderer-BK69MEHQ.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-BzFzx1Um.js → MarkdownRendererImpl-CahUctxC.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-DybFWmDa.js → MarkstreamRendererImpl-5JUaTSdl.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-L9ItollZ.js → MobileDetailNavigation-agQ-Yhpd.js} +1 -1
- package/dist/assets/{MobileShareBridge-DyUqMvTH.js → MobileShareBridge-yCN95dYg.js} +1 -1
- package/dist/assets/{MobileSurface-CP23L9re.js → MobileSurface-D0HP_lTS.js} +1 -1
- package/dist/assets/{MultiRunWindow-CdXC_r5j.js → MultiRunWindow-C0HqMFpp.js} +1 -1
- package/dist/assets/{OverlayScrollbar-S-7EePsU.js → OverlayScrollbar-CRfGtcmG.js} +1 -1
- package/dist/assets/{SettingsView-BQ34wp4Z.js → SettingsView-xLYb22wV.js} +1 -1
- package/dist/assets/{SettingsWindow-BUWWhd18.js → SettingsWindow-B_d5Aqq3.js} +1 -1
- package/dist/assets/{TerminalView-Bdmk0H5m.js → TerminalView-DdNQQb8W.js} +1 -1
- package/dist/assets/{ToolOutputDialog-C-_stNqU.js → ToolOutputDialog-4DC5OE1J.js} +1 -1
- package/dist/assets/{appThemeRegistry-DzON5yeB.js → appThemeRegistry-LkVH62uF.js} +1 -1
- package/dist/assets/{fileMentionTouchSelection-C9p8h-Ie.js → fileMentionTouchSelection-CBzDuQxP.js} +1 -1
- package/dist/assets/{gitApi-BMo0uaL3.js → gitApi-da8etTTe.js} +1 -1
- package/dist/assets/{insertionBoundaries-BpukOKbq.js → insertionBoundaries-DQrE5qG2.js} +1 -1
- package/dist/assets/{main-DXVRrh7X.js → main-DYISNvWY.js} +9 -9
- package/dist/assets/{main-w14j2TkM.js → main-KwlAomA8.js} +2 -2
- package/dist/assets/{mcpQueries-Bce7XemU.js → mcpQueries-3GTWeMU-.js} +1 -1
- package/dist/assets/{miniChat-Cl2nrLSA.js → miniChat-DYIqdWi7.js} +2 -2
- package/dist/assets/{mobile-12ThSAzk.js → mobile-CwiCcmWt.js} +2 -2
- package/dist/assets/{multirun-C0A5kRne.js → multirun-C3snjTFs.js} +1 -1
- package/dist/assets/{platform-D_c-T5nO.js → platform-CurqO28D.js} +2 -2
- package/dist/assets/{projectMeta-dAvoTdWm.js → projectMeta-BkhYFMaM.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-CRgsYMpA.js → renderElectronMiniChatApp-7iyh_419.js} +2 -2
- package/dist/assets/{renderMobileApp-Bhh5JnT6.js → renderMobileApp-y0_NeckR.js} +5 -5
- package/dist/assets/{runtimeConfig-DtMsmzDW.js → runtimeConfig-12C5j02f.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-BsqJbOWK.js → runtimeEndpointReset-DTY2ZXXb.js} +1 -1
- package/dist/assets/{sessionChangeSummary-DUrbLwSm.js → sessionChangeSummary-CwPBIb3Z.js} +1 -1
- package/dist/assets/{sessionLookup-CMoWFtbN.js → sessionLookup-0Z4e-J1g.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-BsObV7Pl.js → sortable-tabs-strip-CE7W7lJ9.js} +1 -1
- package/dist/assets/{terminalApi-Dhqqp4xi.js → terminalApi-mDR2jXTo.js} +1 -1
- package/dist/assets/{textarea-BoXpPjTd.js → textarea-XD2oX_Ee.js} +1 -1
- package/dist/assets/{useAppFontEffects-D-k7nO1V.js → useAppFontEffects-y_GTVXhJ.js} +53 -53
- package/dist/assets/{useDesktopWindowControlsLayout-BY2efZLX.js → useDesktopWindowControlsLayout-CR_DcY77.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-B1MaasbE.js → useEffectiveDirectory-BW9jNyuK.js} +1 -1
- package/dist/assets/{useFontPreferences-Xw1vSkmC.js → useFontPreferences-Bjx8zkGM.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-DztaW6eA.js → useMobileNavigationStore-DwupvLSA.js} +13 -13
- package/dist/assets/{useSessionAutoCleanup-2t3bSPWk.js → useSessionAutoCleanup-DkGO_usj.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-B8TVySRJ.js → useWorkerHighlightedLines-BUcSLKlL.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,i as n}from"./runtime-switch-LvWDU-SL.js";import{Cn as r,D as i,d as a,k as o,tn as s,u as c}from"./persistence-D0y7226-.js";import{a as l,i as u,r as d}from"./vendor-zustand-B4dlGEM2.js";import{nt as f,rt as p}from"./vendor-base-ui-CnHfUmDN.js";import{B as m,Ct as h,M as g,Mt as _}from"./platform-D_c-T5nO.js";import{b as v,n as ee,x as y}from"./useUIStore-syVmbuDA.js";import{n as b}from"./vendor-react-DLPElpoQ.js";import{s as x}from"./vendor-tanstack-react-query-D7pys_c9.js";import{n as S}from"./vendor-reactuses-core-Dq5ocTF8.js";import{f as te,r as C,u as ne}from"./button-DIIrsMjW.js";import{Ht as re,Pn as ie,S as w,Ua as ae,_n as T,ao as E,d as D,dt as oe,ft as se,io as ce,lt as O,ma as le,mr as k,mt as A,sn as ue,ut as j,xr as de,y as fe}from"./useMobileNavigationStore-DztaW6eA.js";import{n as M}from"./Icon-B8fSTLdP.js";import{g as N,v as P}from"./gitApi-BMo0uaL3.js";import{f as pe,k as me,o as F}from"./projectMeta-dAvoTdWm.js";import{n as he}from"./textarea-BoXpPjTd.js";import{n as ge,r as _e,t as ve}from"./fileMentionTouchSelection-C9p8h-Ie.js";var I=e=>{switch(e.name){case`new`:return`add`;case`init`:return`file`;case`undo`:return`arrow-go-back`;case`redo`:return`arrow-go-forward`;case`timeline`:return`time`;case`compact`:return`scissors`;case`reload`:return`refresh`;case`goal`:return`target`;case`review`:return`search-eye`;case`test`:case`build`:case`run`:return`terminal-box`;default:return e.isBuiltIn?`flashlight`:`command`}},ye=()=>`book-open`,be=e=>{if(e.isDirectory)return`folder-3-fill`;switch(e.extension?.toLowerCase()){case`ts`:case`tsx`:case`js`:case`jsx`:case`json`:return`code`;case`md`:case`mdx`:return`file`;case`png`:case`jpg`:case`jpeg`:case`gif`:case`svg`:return`file-image`;default:return`file-pdf`}},xe=()=>`ai-agent`,Se=()=>`chat-thread`,Ce=(e,t)=>e.map(e=>{let n=e.isSkill?t.skill:e.isOpenChamber?`OpenChamber`:e.isBuiltIn?t.system:e.scope||e.agent||t.command;return{id:e.id,title:`/${e.name}`,subtitle:e.description,badge:n,iconName:I(e)}}),we=({skills:e=[],agents:t,sessions:n,recentFiles:r,pathHits:i,untitledSession:a,sessionBadge:o,skillBadge:s})=>{let c=[];for(let t of e)c.push({id:`skill:${t.name}-${t.scope}`,title:`@${t.name}`,subtitle:t.description,badge:s??t.scope,iconName:ye()});for(let e of t)c.push({id:`agent:${e.name}`,title:`@${e.name}`,subtitle:e.description,iconName:xe()});for(let e of n)c.push({id:`session:${e.id}`,title:e.title||a,badge:o,iconName:Se()});for(let e of r)c.push({id:`recent:${e.path}`,title:e.relativePath||e.name,iconName:be(e)});for(let e of i)c.push({id:`file:${e.path}`,title:e.relativePath||e.name,iconName:be(e)});return c},Te=(e,t)=>{let n=t.trim();if(!n.length)return[...e].sort((e,t)=>e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name));let r=ie([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.scope===`project`&&t.item.scope!==`project`?-1:e.item.scope!==`project`&&t.item.scope===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score),r.map(e=>e.item)},Ee=(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=ie([...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)},De=(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}),Oe=(e,t)=>e.highlightedIndex===t.highlightedIndex&&De(e.rows,t.rows),ke=(e,t)=>De(e,t)?e:t.slice(),Ae=(e,t,n)=>{e&&(t.current&&Oe(t.current,n)||(t.current=n,e(n)))},je=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},L=e(p(),1),R=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},z=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,B=(e,t)=>{let n=R(t),r=R(e);if(!n||!r)return!1;let i=z(n),a=z(r);return a===i||a.startsWith(`${i}/`)},Me=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=R(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=>R(e)).filter(e=>B(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>R(e)).filter(e=>B(e,t)))):[],s=typeof i.selectedPath==`string`?R(i.selectedPath):null,c=s&&B(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},V=(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},Ne=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},Pe=l()(d(u((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=R((t||``).trim()),a=R((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!B(a,i)||e(e=>{let t=e.byRoot[i],n=Ne(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:V({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=R((t||``).trim()),i=R((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=z(i),a=e=>z(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:V({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=R((t||``).trim()),i=R((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=z(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=z(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:V({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=R((t||``).trim()),i=R((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=z(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=z(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:V({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=R((t||``).trim()),a=n?R(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!B(a,i)||e(e=>{let t=e.byRoot[i],n=Ne(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:V({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=R((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=R((t||``).trim()),i=R((n||``).trim());!r||!i||!B(i,r)||e(e=>{let t=e.byRoot[r],n=Ne(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:V({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=R((t||``).trim()),i=R((n||``).trim());!r||!i||!B(i,r)||e(e=>{let t=e.byRoot[r],n=Ne(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:V({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=R((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>R((e||``).trim())).filter(e=>e&&B(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=Ne(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:V({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:v(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:Me(t)}},partialize:e=>({byRoot:Me(e.byRoot)})}),{name:`files-view-tabs-store`})),H=b(),Fe=(e,t)=>{let n=(0,H.c)(4),r=t===void 0?200:t,[i,a]=L.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]),L.useEffect(o,s),i},Ie=()=>{let e=(0,H.c)(17),t=D(U),n=T(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=w(r),a=D(W),o=D(Le),s=E(G),c=E(Re),l=h(K);if(t){let r;e[2]===i?r=e[3]:(r=fe(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 U(e){return e.currentSessionId}function W(e){return e.worktreeMetadata}function Le(e){return e.newSessionDraft}function G(e){return e.activeProjectId}function Re(e){return e.projects}function K(e){return e.currentDirectory}var q=f(),J=`bg-transparent font-[inherit] text-[var(--primary-base)]`,Y=(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,q.jsx)(`mark`,{className:J,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},X=L.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:a,onClose:s,style:c,onRowsChange:l},u)=>{let{t:d}=te(),f=Ie()??``,p=D(e=>e.currentSessionId),m=de(e=>e.activeSessions),h=re({enabled:!!a}),g=E(e=>e.activeProjectId),v=E(e=>e.projects),y=L.useMemo(()=>v.find(e=>e.id===g)?.path??null,[g,v]),b=L.useMemo(()=>{let e=y||f;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[y,f]),x=Pe(e=>b?e.byRoot[b]:void 0),ie=le(e=>e.getVisibleAgents),w=_(e=>e.searchFiles),T=Fe(e,180),ce=o(),ue=i(),[fe,N]=L.useState([]),[P,pe]=L.useState([]),[me,F]=L.useState(!1),[I,xe]=L.useState(0),Se=L.useRef(0),[Ce,Ee]=L.useState(360),[De,Oe]=L.useState({}),[ke,R]=L.useState({}),z=L.useRef([]),B=L.useRef([]),Me=L.useRef([]),V=L.useRef(null),Ne=L.useRef(null),H=L.useRef(null);H.current||=ve();let U=ee(e=>e.isMobile),W=(e??``).trim(),Le=ae({directory:f||null}),G=L.useMemo(()=>r?Te(Le.data??[],W):[],[W,r,Le.data]),Re=L.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 se(n,W,{limit:6})},[W,b,x]),K=L.useMemo(()=>W.length>0?P:P.slice(0,2),[P,W.length]),J=L.useMemo(()=>a?O({sessions:k(m,h),currentSessionId:p,searchQuery:W}):[],[m,p,h,W,a]),X=Re,Z=fe;L.useEffect(()=>{let e=e=>{let t=e.target;!t||!V.current||V.current.contains(t)||s()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[s]),L.useEffect(()=>{if(!f){N([]);return}let e=(T??``).trim(),t=A(e);if(!t){N([]);return}let n=!1;F(!0);let r={includeHidden:ce,respectGitignore:!ue};return Promise.all([w(f,t,80,{...r,type:`file`}),w(f,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(Re.map(e=>e.path));N(j({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{n||N([])}).finally(()=>{n||F(!1)}),()=>{n=!0}},[f,T,Re,w,ce,ue]),L.useEffect(()=>{let t=ie().filter(e=>e.mode&&e.mode!==`primary`).map(e=>({name:e.name,description:e.description,mode:e.mode}));pe(oe(t,e??``))},[ie,e]),L.useEffect(()=>{xe(0),Oe({}),R({})},[Z,X.length,K.length,J.length,G.length]),L.useEffect(()=>{Se.current=I},[I]),L.useEffect(()=>{z.current[I]?.scrollIntoView({block:`nearest`})},[I]),L.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};B.current.forEach((n,r)=>{if(!n)return;let i=Me.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),R(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[Z,X]),L.useEffect(()=>{let e=B.current[I];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()}},[I]);let ze=S(e=>{t(e)}),Be=S(e=>{n?.(e)}),Ve=S(e=>{a?.(e)}),He=S(e=>{r?.(e)}),Ue=G.length,We=Ue,Ge=We+K.length,Ke=Ge+J.length,qe=Ke+X.length,Je=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&H.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&H.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(H.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>H.current?.pointerCancel(),onClick:()=>{H.current?.click(t)},onMouseMove:()=>xe(e)}),Ye=e=>{let t=Ue+K.length+J.length+X.length+Z.length;if(t===0)return;let n=(e%t+t)%t;if(n<Ue){let e=G[n];e&&He(e);return}if(n<Ge){let e=K[n-We];e&&Be(e.name);return}if(n<Ke){let e=J[n-Ge];e&&Ve(e);return}let r=n-Ke,i=r<X.length?X[r]:Z[r-X.length];i&&ze(i)};L.useEffect(()=>{Ae(l,Ne,{rows:we({skills:G,agents:K,sessions:J,recentFiles:X,pathHits:Z,untitledSession:d(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:d(`chat.fileMentionAutocomplete.sessionType`),skillBadge:d(`chat.commandAutocomplete.badge.skill`)}),highlightedIndex:I})},[l,I,d,K,Z,X,J,G]);let Xe=L.useRef(l);Xe.current=l,L.useEffect(()=>()=>{je(Xe.current,Ne)},[]),L.useImperativeHandle(u,()=>({acceptIndex:e=>{Ye(e)},handleKeyDown:e=>{if(e===`Escape`){s();return}let t=Ue+K.length+J.length+X.length+Z.length;if(t!==0){if(e===`ArrowDown`){xe(e=>(e+1)%t);return}if(e===`ArrowUp`){xe(e=>(e-1+t)%t);return}(e===`Enter`||e===`Tab`)&&Ye(Se.current)}}}),[Ue,Z,X,K,J,G,s,ze,Be,Ve,He]);let Ze=e=>(0,q.jsx)(M,{name:be(e),className:`h-3.5 w-3.5 text-current`});return(0,q.jsxs)(ge,{ref:V,isMobile:U,className:`max-w-[640px] max-h-64`,style:c,children:[(0,q.jsx)(he,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,q.jsxs)(`div`,{className:`pb-2`,children:[G.length>0&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.skills`)}),G.map((e,t)=>{let n=I===t;return(0,q.jsx)(`div`,{ref:e=>{z.current[t]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,_e(U,n),!U&&n&&`text-interactive-selection-foreground`),...Je(t,()=>He(e)),children:(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(M,{name:ye(),className:`h-3.5 w-3.5 translate-y-px flex-shrink-0 text-current`}),(0,q.jsxs)(`span`,{className:`min-w-0 truncate`,children:[`@`,Y(e.name,W)]}),U?null:(0,q.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:e.scope})]}),e.description&&!U?(0,q.jsx)(`div`,{className:`pl-5.5 typography-meta text-muted-foreground truncate`,children:Y(e.description,W)}):null]})},`skill-${e.name}-${e.scope}`)}),K.length>0&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.agents`)}),K.map((e,t)=>{let n=We+t,r=I===n;return(0,q.jsx)(`div`,{ref:e=>{z.current[n]=e},className:C(`flex items-start gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,_e(U,r),!U&&r&&`text-interactive-selection-foreground`),...Je(n,()=>Be(e.name)),children:(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`truncate`,children:[`@`,Y(e.name,W)]}),e.description&&!U?(0,q.jsx)(`div`,{className:`typography-meta text-muted-foreground truncate`,children:Y(e.description,W)}):null]})},`agent-${e.name}`)}),K.length===2&&W.length===0&&P.length>2&&(0,q.jsx)(`div`,{className:`px-3 py-1 typography-meta text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.searchMoreAgents`)}),J.length>0&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.sessions`)}),J.map((e,t)=>{let n=Ge+t,r=I===n;return(0,q.jsxs)(`div`,{ref:e=>{z.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,_e(U,r),!U&&r&&`text-interactive-selection-foreground`),...Je(n,()=>Ve(e)),children:[(0,q.jsx)(M,{name:`chat-thread`,className:`h-4 w-4 flex-shrink-0 text-[var(--primary-base)]`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title||d(`chat.fileMentionAutocomplete.untitledSession`),children:Y(e.title||d(`chat.fileMentionAutocomplete.untitledSession`),W)}),U?null:(0,q.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.sessionType`)})]},`session-${e.id}`)}),X.length>0&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.recentFiles`)}),X.map((e,t)=>{let n=Ke+t,r=e.relativePath||e.name,i=ne(r,{maxLength:60}),a=I===n,o=De[n]??!1,s=ke[n]??2.6;return(0,q.jsxs)(`div`,{ref:e=>{z.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,_e(U,a),!U&&a&&`text-interactive-selection-foreground`),...Je(n,()=>ze(e)),children:[Ze(e),(0,q.jsxs)(`span`,{ref:e=>{B.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${Ce}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,q.jsx)(`span`,{ref:e=>{Me.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,q.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Y(r,W)}):(0,q.jsx)(`span`,{className:`block truncate`,children:Y(i,W)})]})]},`recent-${e.path}`)}),Z.length>0&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.files`)}),Z.map((e,t)=>{let n=qe+t,r=e.relativePath||e.name,i=ne(r,{maxLength:60}),a=I===n,o=De[n]??!1,s=ke[n]??2.6;return(0,q.jsxs)(`div`,{ref:e=>{z.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,_e(U,a),!U&&a&&`text-interactive-selection-foreground`),...Je(n,()=>ze(e)),children:[Ze(e),(0,q.jsxs)(`span`,{ref:e=>{B.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${Ce}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,q.jsx)(`span`,{ref:e=>{Me.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,q.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Y(r,W)}):(0,q.jsx)(`span`,{className:`block truncate`,children:Y(i,W)})]})]},e.path)}),me&&Z.length===0?(0,q.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,q.jsx)(M,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!me&&Z.length===0&&X.length===0&&K.length===0&&J.length===0&&G.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.empty`)})]})}),!U&&(0,q.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:d(`chat.autocomplete.keyboardHint`)})]})}),Z=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`goal`,`btw`]),ze=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&Z.has(n))},Be=(e,t)=>!e||t({name:e}),Ve=` `,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]===Ve&&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)]`),qe=C(Ue,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),Je=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),Ye=(e,t)=>{let n=!!e.sessionID;return{hasSession:n,canStartSessionCommand:n||e.hasNewDraft,canUseReviewHandoffFlow:n&&!t&&!s()}},Xe=L.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:r,style:i,commandPolicy:a,commandContext:o,onRowsChange:c},l)=>{let{t:u}=te(),d=ee(e=>e.isMobile),f=D(e=>e.currentSessionId),p=D(e=>!!e.newSessionDraft?.open),m=D(L.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=ue(f??``,m??void 0),g=L.useMemo(()=>o??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[o,f,h.length,p]),{hasSession:_,canStartSessionCommand:v,canUseReviewHandoffFlow:y}=L.useMemo(()=>Ye(g,d),[g,d]),b=g.hasMessages,[x,S]=L.useState([]),[ne,re]=L.useState(!1),ie=ce({directory:r}),w=L.useMemo(()=>ie.data??[],[ie.data]),ae=ie.isFetching,[T,E]=L.useState(0),oe=L.useRef(0),se=L.useRef(!1),O=L.useRef([]),le=L.useRef(null),k=L.useRef(!1),A=L.useRef(null),j=L.useRef(!1),de=L.useRef(null);L.useEffect(()=>{let e=e=>{let t=e.target;!t||!le.current||le.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),L.useEffect(()=>{(async()=>{re(ae);try{let t=w.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:`openchamber:new`,name:`new`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!b?[{id:`openchamber:init`,name:`init`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:btw`,name:`btw`,source:`openchamber`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`openchamber:undo`,name:`undo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`openchamber:redo`,name:`redo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`openchamber:fork`,name:`fork`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`openchamber:timeline`,name:`timeline`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`openchamber:model`,name:`model`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`openchamber:compact`,name:`compact`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...s()?[{id:`openchamber:reload`,name:`reload`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:summary`,name:`summary`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:workspace-review`,name:`workspace-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isOpenChamber:!0}]:[],...y?[{id:`openchamber:handoff-review`,name:`handoff-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:craft-goal`,name:`craft-goal`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:goal`,name:`goal`,source:`openchamber`,description:u(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],...v?[{id:`openchamber:catch-up`,name:`catch-up`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:debug`,name:`debug`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.debugDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:weigh`,name:`weigh`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.weighDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:explore`,name:`explore`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isOpenChamber:!0}]:[],...t],r=!b,i=Ee(n.filter(e=>(r||e.name!==`init`)&&(a?.(e)??!0)),e);S(e=>Je(e,i)?e:i)}catch{let t=!b,n=Ee([{id:`openchamber:new`,name:`new`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!b?[{id:`openchamber:init`,name:`init`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:btw`,name:`btw`,source:`openchamber`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`openchamber:undo`,name:`undo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`openchamber:redo`,name:`redo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`openchamber:fork`,name:`fork`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`openchamber:timeline`,name:`timeline`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`openchamber:model`,name:`model`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`openchamber:compact`,name:`compact`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...s()?[{id:`openchamber:reload`,name:`reload`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:summary`,name:`summary`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:workspace-review`,name:`workspace-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isOpenChamber:!0}]:[],...y?[{id:`openchamber:handoff-review`,name:`handoff-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:craft-goal`,name:`craft-goal`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:goal`,name:`goal`,source:`openchamber`,description:u(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],...v?[{id:`openchamber:catch-up`,name:`catch-up`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:debug`,name:`debug`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.debugDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:weigh`,name:`weigh`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.weighDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:explore`,name:`explore`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isOpenChamber:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(a?.(e)??!0)),e);S(e=>Je(e,n)?e:n)}finally{re(!1)}})()},[e,b,_,v,y,w,ae,u,a]),L.useEffect(()=>{E(0)},[x]),L.useEffect(()=>{oe.current=T},[T]),L.useEffect(()=>{O.current[T]?.scrollIntoView({block:`nearest`})},[T]),L.useEffect(()=>{Ae(c,de,{rows:Ce(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 fe=L.useRef(c);fe.current=c,L.useEffect(()=>()=>{je(fe.current,de)},[]),L.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=x[e];r&&t(r,ze(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,ze(i,e===`Enter`))}}}}),[x,n,t]);let N=e=>{let t=I(e);switch(e.name){case`new`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,q.jsxs)(ge,{ref:le,isMobile:d,className:`max-w-[450px] max-h-64`,style:i,children:[(0,q.jsx)(he,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:ne?(0,q.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,q.jsx)(M,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,q.jsxs)(`div`,{children:[x.map((n,r)=>{let i=n.isBuiltIn,a=n.isOpenChamber;return(0,q.jsxs)(`div`,{ref:e=>{O.current[r]=e},className:C(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,_e(d,r===T),!d&&r===T&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(A.current={x:e.clientX,y:e.clientY},j.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!A.current)return;let t=e.clientX-A.current.x,n=e.clientY-A.current.y;Math.hypot(t,n)>6&&(j.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=j.current;A.current=null,j.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),k.current=!0,t(n,ze(n,d)))},onPointerCancel:()=>{A.current=null,j.current=!1},onClick:()=>{if(k.current){k.current=!1;return}t(n,ze(n,d))},onMouseMove:()=>{se.current=!1,E(r)},children:[(0,q.jsx)(`div`,{className:C(!d&&`mt-0.5`),children:N(n)}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,Y(n.name,e)]}),n.isSkill?(0,q.jsx)(`span`,{className:We,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,q.jsx)(`span`,{className:We,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,q.jsx)(`span`,{className:qe,children:`OpenChamber`}):i?(0,q.jsx)(`span`,{className:qe,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,q.jsx)(`span`,{className:n.scope===`project`?Ke:Ge,children:n.scope}):null,n.agent&&(0,q.jsx)(`span`,{className:qe,children:n.agent})]}),n.description&&!d&&(0,q.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Y(n.description,e)})]})]},n.id)}),x.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,q.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});Xe.displayName=`CommandAutocomplete`;function Ze(e){return(e.description||e.content).replace(/\s+/g,` `).trim().slice(0,120)}var Qe=L.forwardRef((e,t)=>{let n=(0,H.c)(63),{searchQuery:r,onSnippetSelect:i,onClose:a,style:o}=e,{t:s}=te(),c=L.useRef(null),l=ee($e),[u,d]=L.useState(0),f=L.useRef(0),p;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=[],n[0]=p):p=n[0];let[m,h]=L.useState(p),g;n[1]===Symbol.for(`react.memo_cache_sentinel`)?(g=[],n[1]=g):g=n[1];let _=L.useRef(g),v=me(et),y=me(tt),b=me(nt),x=me(rt),S=ee(it),ne=ee(at),re,w;n[2]===y?(re=n[3],w=n[4]):(re=()=>{y()},w=[y],n[2]=y,n[3]=re,n[4]=w),L.useEffect(re,w);let ae,T;n[5]!==r||n[6]!==v?(ae=()=>{let e=r.trim();if(!e.length){let e=[...v].sort(ot);h(e),d(+!!e.length);return}let t=ie(v,e,st);t.sort(ct);let n=t.map(lt);h(n),d(+!!n.length)},T=[r,v],n[5]=r,n[6]=v,n[7]=ae,n[8]=T):(ae=n[7],T=n[8]),L.useEffect(ae,T);let E,D;n[9]===u?(E=n[10],D=n[11]):(E=()=>{f.current=u,_.current[u]?.scrollIntoView({block:`nearest`})},D=[u],n[9]=u,n[10]=E,n[11]=D),L.useEffect(E,D);let oe,se;n[12]===a?(oe=n[13],se=n[14]):(se=()=>{let e=e=>{let t=e.target;t&&c.current&&!c.current.contains(t)&&a()};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},oe=[a],n[12]=a,n[13]=oe,n[14]=se),L.useEffect(se,oe);let ce;n[15]!==i||n[16]!==r?(ce=e=>{let t=r.trim(),n=e.aliases.includes(t)?t:e.name;i(e,n)},n[15]=i,n[16]=r,n[17]=ce):ce=n[17];let O=ce,le;n[18]!==a||n[19]!==x||n[20]!==S||n[21]!==ne||n[22]!==b||n[23]!==v?(le=()=>{let e=new Set(v.map(ut)),t=`new-snippet`,n=1;for(;e.has(t);)t=`new-snippet-${n++}`;b({name:t,scope:`global`}),x(t),ne(`snippets`),S(!0),a()},n[18]=a,n[19]=x,n[20]=S,n[21]=ne,n[22]=b,n[23]=v,n[24]=le):le=n[24];let k=le,A,ue;n[25]!==O||n[26]!==m||n[27]!==a||n[28]!==k?(A=()=>({handleKeyDown:e=>{if(e===`Escape`){a();return}let t=m.length+1;if(e===`ArrowDown`){d(e=>(e+1)%t);return}if(e===`ArrowUp`){d(e=>(e-1+t)%t);return}if(e===`Enter`||e===`Tab`){if(f.current===0){k();return}let e=m[f.current-1];e&&O(e)}}}),ue=[O,m,a,k],n[25]=O,n[26]=m,n[27]=a,n[28]=k,n[29]=A,n[30]=ue):(A=n[29],ue=n[30]),L.useImperativeHandle(t,A,ue);let j;n[31]===Symbol.for(`react.memo_cache_sentinel`)?(j=e=>{_.current[0]=e},n[31]=j):j=n[31];let de;n[32]!==l||n[33]!==u?(de=C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,_e(l,u===0)),n[32]=l,n[33]=u,n[34]=de):de=n[34];let fe,N;n[35]===Symbol.for(`react.memo_cache_sentinel`)?(fe=()=>d(0),N=(0,q.jsx)(M,{name:`add`,className:`h-3.5 w-3.5 text-muted-foreground`}),n[35]=fe,n[36]=N):(fe=n[35],N=n[36]);let P;n[37]===s?P=n[38]:(P=s(`chat.snippetAutocomplete.action.addNew`),n[37]=s,n[38]=P);let pe;n[39]===P?pe=n[40]:(pe=(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:P}),n[39]=P,n[40]=pe);let F;n[41]!==k||n[42]!==de||n[43]!==pe?(F=(0,q.jsxs)(`div`,{ref:j,className:de,onClick:k,onMouseMove:fe,children:[N,pe]}),n[41]=k,n[42]=de,n[43]=pe,n[44]=F):F=n[44];let ve;n[45]!==O||n[46]!==m||n[47]!==l||n[48]!==r||n[49]!==u||n[50]!==s?(ve=m.length?m.map((e,t)=>(0,q.jsx)(`div`,{ref:e=>{_.current[t+1]=e},className:C(`flex gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,l?`items-center`:`items-start`,_e(l,t+1===u)),onClick:()=>O(e),onMouseMove:()=>d(t+1),children:(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`span`,{className:`truncate`,children:[`#`,Y(e.name,r)]}),(0,q.jsx)(`span`,{className:`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0 bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`,children:s(`snippets.source.${e.source}`)})]}),!l&&(0,q.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Y(Ze(e),r)})]})},`${e.source}:${e.filePath}`)):(0,q.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:s(`chat.snippetAutocomplete.empty`)}),n[45]=O,n[46]=m,n[47]=l,n[48]=r,n[49]=u,n[50]=s,n[51]=ve):ve=n[51];let I;n[52]!==F||n[53]!==ve?(I=(0,q.jsxs)(he,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 pb-2`,children:[F,ve]}),n[52]=F,n[53]=ve,n[54]=I):I=n[54];let ye;n[55]!==l||n[56]!==s?(ye=!l&&(0,q.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:s(`chat.snippetAutocomplete.footer`)}),n[55]=l,n[56]=s,n[57]=ye):ye=n[57];let be;return n[58]!==l||n[59]!==o||n[60]!==I||n[61]!==ye?(be=(0,q.jsxs)(ge,{ref:c,isMobile:l,className:`max-w-[450px] max-h-60`,style:o,children:[I,ye]}),n[58]=l,n[59]=o,n[60]=I,n[61]=ye,n[62]=be):be=n[62],be});Qe.displayName=`SnippetAutocomplete`;function $e(e){return e.isMobile}function et(e){return e.snippets}function tt(e){return e.loadSnippets}function nt(e){return e.setSnippetDraft}function rt(e){return e.setSelectedSnippet}function it(e){return e.setSettingsDialogOpen}function at(e){return e.setSettingsPage}function ot(e,t){return e.source===`project`&&t.source!==`project`?-1:e.source!==`project`&&t.source===`project`?1:e.name.localeCompare(t.name)}function st(e){return[e.name,...e.aliases]}function ct(e,t){return e.score===t.score?e.item.source===`project`&&t.item.source!==`project`?-1:e.item.source!==`project`&&t.item.source===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score}function lt(e){return e.item}function ut(e){return e.name}var dt=2,ft=e=>!!e&&typeof e==`object`&&!Array.isArray(e),pt=e=>{let t=e?.trim().replace(/\\/g,`/`);return t?t.length>1?t.replace(/\/+$/,``):t:null},mt=e=>ft(e)&&Array.isArray(e.all)&&e.all.every(e=>typeof e==`string`)&&typeof e.current==`string`&&ft(e.branches),ht=(e,t)=>JSON.stringify([e,t]),gt=e=>`version`in e&&e.version===dt&&ft(e.entries),_t=e=>{if(!e)return null;try{let t=JSON.parse(e);return ft(t)?t.version===dt&&ft(t.entries)?{version:dt,entries:t.entries}:t:null}catch{return null}},vt=(e,t)=>{try{e.setItem(`oc.gitBranchCache`,JSON.stringify(t))}catch{}},yt=(e,t,n)=>{let r=pt(e);if(!r||!t)return null;let i;try{i=n.getItem(`oc.gitBranchCache`)}catch{return null}let a=_t(i);if(!a)return null;if(gt(a))return mt(a.entries[ht(t,r)])?a.entries[ht(t,r)]:null;let o={};for(let[e,n]of Object.entries(a)){let r=pt(e);r&&mt(n)&&(o[ht(t,r)]=n)}return vt(n,{version:dt,entries:o}),o[ht(t,r)]??null},bt=(e,t,n,r)=>{let i=pt(e);if(!i||!t||!mt(n))return;let a=null;try{a=r.getItem(`oc.gitBranchCache`)}catch{return}let o=_t(a);vt(r,{version:dt,entries:{...o&>(o)?o.entries:{},[ht(t,i)]:n}})},xt=3e4,St=pt,Ct=(e,t=n())=>a.git.branches(St(e),t),wt=(e,t=n())=>a.git.remotes(St(e),t),Tt=async(e,t,n)=>{n.throwIfAborted();let i=r()?.git,a=t?.getGitBranches?await t.getGitBranches(e,{signal:n}):i?await i.getGitBranches(e,{signal:n}):await g(e,{signal:n});return n.throwIfAborted(),a},Et=async(e,t,n)=>{n.throwIfAborted();let i=r()?.git,a=t?.getRemotes?await t.getRemotes(e,{signal:n}):i?await i.getRemotes(e,{signal:n}):await m(e,{signal:n});return n.throwIfAborted(),a},Dt=(e,t,r=n(),i=y())=>{let a=St(e),o=t;return{queryKey:Ct(a,r),queryFn:async({signal:e})=>{if(!a)throw Error(`Git branches require a directory`);let t=await Tt(a,o,e);return bt(a,r,t,i),t},staleTime:xt,gcTime:1/0,initialData:()=>yt(a,r,i)??void 0,initialDataUpdatedAt:0}},Ot=(e,t,r=n())=>{let i=St(e),a=t;return{queryKey:wt(i,r),queryFn:({signal:e})=>{if(!i)throw Error(`Git remotes require a directory`);return Et(i,a,e)},staleTime:xt,gcTime:1/0}},kt=(e,r,i)=>{let a=(0,H.c)(9),o=i===void 0||i,s=L.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=St(e),u=x,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)},At=(e,r,i)=>{let a=(0,H.c)(9),o=i===void 0||i,s=L.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=St(e),u=x,l=Ot(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)},jt=(e,t,r=c,i=n())=>r.fetchQuery(Dt(e,t,i)),Mt=(e,t,r=c,i=n())=>r.fetchQuery({...Dt(e,t,i),staleTime:0}),Nt=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,Pt=1e4,Ft=6e4,It=5e3,Lt=3e4,Rt=6e4,zt=25,Bt=40,Vt=2,Ht=15e3,Ut=500,Wt=30,Gt=20971520,Kt=new Map,qt=new Map,Jt=new Map,Yt=new Map,Xt=new Map,Zt=(e,t)=>`${t}:${e}`,Qt=e=>qt.get(e)??0,$t=e=>{let t=Qt(e)+1;return qt.set(e,t),t},en=e=>{let t=(Jt.get(e)??0)+1;return Jt.set(e,t),t},tn=e=>{let t=Kt.get(e);if(t)return t;let n=new Set;return Kt.set(e,n),n},Q=()=>({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}),nn=(e,t=Wt,n=Gt)=>{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},rn=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=new Set([...Object.keys(e),...Object.keys(t)]);for(let r of n){let n=e[r],i=t[r];if(!(!n&&!i)&&(!n||!i||n.insertions!==i.insertions||n.deletions!==i.deletions))return!0}return!1},an=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,on=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=e.files??[],r=t.files??[];if(n.length!==r.length||e.ahead!==t.ahead||e.behind!==t.behind||e.current!==t.current||e.tracking!==t.tracking||e.isClean!==t.isClean||t.upstreamComparison!==void 0&&an(e.upstreamComparison,t.upstreamComparison))return!0;let i=new Set(n.map(e=>`${e.path}:${e.index}:${e.working_dir}`));for(let e of r)if(!i.has(`${e.path}:${e.index}:${e.working_dir}`))return!0;return!!(t.diffStats!==void 0&&rn(e.diffStats,t.diffStats))},sn=(e,t)=>{let n=new Set;if(!t)return n;let r=e?.files??[],i=t.files??[],a=new Map(r.map(e=>[e.path,e])),o=new Map(i.map(e=>[e.path,e])),s=new Set([...a.keys(),...o.keys()]);for(let e of s){let t=a.get(e),r=o.get(e);if(!t||!r){n.add(e);continue}if(t.index!==r.index||t.working_dir!==r.working_dir){n.add(e);continue}}if(t.diffStats!==void 0){let r=e?.diffStats??{},i=t.diffStats??{},a=new Set([...Object.keys(r),...Object.keys(i)]);for(let e of a){let t=r[e],a=i[e];if(!t||!a){n.add(e);continue}(t.insertions!==a.insertions||t.deletions!==a.deletions)&&n.add(e)}}return n},cn=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=e.files??[],r=t.files??[],i=e=>{let t=e?.trim()??``;return t===`?`?``:t},a=new Map(n.map(e=>[e.path,i(e.index)])),o=new Map(r.map(e=>[e.path,i(e.index)])),s=new Set([...a.keys(),...o.keys()]);for(let e of s)if((a.get(e)??``)!==(o.get(e)??``))return!0;return!1},ln=e=>!e||e.trim().length===0,un=e=>(e||``).trim()===`U`,dn=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(un(t)||un(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},fn=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(un(t)||un(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},pn=e=>ln(e.index)&&ln(e.working_dir),$=l()(d((e,t)=>({directories:new Map,activeDirectory:null,setActiveDirectory:n=>{let{activeDirectory:r,directories:i}=t();if(r!==n)if(r&&$t(r),n&&$t(n),n&&!i.has(n)){let t=new Map(i);t.set(n,Q()),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=Zt(n,a),s=Yt.get(o)??(a===`light`?Yt.get(Zt(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||=Q(),!a){let r=new Map(t().directories),i=r.get(n)??Q();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)>Ft,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);if(on(s.status,u)){c=!0;let r=new Map(t().directories),i=r.get(n)??Q(),s=sn(i.status,u),l=cn(i.status,u),d=new Set((i.status?.files??[]).map(e=>e.path)),f=new Set((u.files??[]).map(e=>e.path)),p=new Map(i.diffCache);for(let e of d)f.has(e)||p.delete(e);for(let e of s)p.delete(e);let m=s.size>0;m&&$t(n);let h={...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:h,diffCache:p,indexRevision:l?i.indexRevision+1:i.indexRevision,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:m?Date.now():i.lastStatusChange}),e({directories:r})}else{let r=new Map(t().directories),i=r.get(n)??Q();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)??Q();r.set(n,{...i,isLoadingStatus:!1}),e({directories:r})}}return c})();Yt.set(o,c);try{return await c}finally{Yt.get(o)===c&&Yt.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`?dn(e):fn(e);t!==e&&(l=!0),pn(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=en(r);{let n=new Map(t().directories),i=n.get(r)??Q();n.set(r,{...i,isLoadingBranches:!0}),e({directories:n})}try{let c=a.force?await Mt(r,i,void 0,o):await jt(r,i,void 0,o);if(s!==Jt.get(r)||o!==n())return;let l=new Map(t().directories),u=l.get(r)??Q();l.set(r,{...u,branches:c,branchesTransportIdentity:o,isLoadingBranches:!1,lastBranchesFetch:Date.now()}),e({directories:l})}catch(i){if(Nt(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)??Q();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)??Q();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)??Q();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)??Q();i.set(n,{...a,isLoadingLog:!1}),e({directories:i})}},fetchIdentity:async(n,r)=>{{let r=new Map(t().directories),i=r.get(n)??Q();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)??Q();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)??Q();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=Q();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>Pt||!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)??Q(),s=new Map(o.diffCache);s.set(r,{...i,fetchedAt:Date.now()});let c=nn(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{$t(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,zt);await t().prefetchDiffs(e,n,i,{maxFiles:zt})},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=Bt}=a,c=new Set(o.status.files.map(e=>e.path)),l=o.status.diffStats,u=tn(n),d=[],f=new Set;for(let e of i){if(!e||f.has(e)||(f.add(e),!c.has(e))||o.diffCache.has(e)||u.has(e))continue;let t=l?.[e];t&&t.insertions+t.deletions>Ut||d.push(e)}let p=d.slice(0,Math.max(1,s));if(p.length===0)return;let m=Qt(n);if(typeof document<`u`&&document.hidden)return;p.forEach(e=>u.add(e));let h=0,g=[],_=()=>{let e=h;return h+=1,e<p.length?p[e]:null},v=async e=>{let t=r.getGitFileDiff(n,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${Ht}ms`)),Ht)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},ee=async()=>{for(;;){if(m!==Qt(n))return;let e=_();if(!e)return;try{g.push(await v(e))}catch{}finally{u.delete(e)}}},y=Math.min(Vt,p.length);if(await Promise.allSettled(Array.from({length:y},()=>ee())),p.forEach(e=>u.delete(e)),m!==Qt(n))return;let b=new Map(t().directories),x=b.get(n);if(!x)return;let S=new Map(x.diffCache),te=Date.now();g.forEach(e=>{!e.diff.isBinary&&e.diff.original===``&&e.diff.modified===``||S.set(e.path,{...e.diff,fetchedAt:te})});let C=nn(S);b.set(n,{...x,diffCache:C}),e({directories:b})},setLogMaxCount:(n,r)=>{let i=new Map(t().directories),a=i.get(n)??Q();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<It||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=Xt.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)>=It)&&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>=Lt)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=Pt)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=Rt)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return Xt.set(e,i),i.finally(()=>{Xt.get(e)===i&&Xt.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),mn=e=>{let t=(0,H.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),$(n)},hn=e=>{let r=(0,H.c)(3),i=L.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],$(a)},gn=e=>{let t=(0,H.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),$(n)},_n=e=>{let t=(0,H.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),$(n)},vn=e=>{let t=(0,H.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),$(n)},yn=e=>{let t=(0,H.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=L.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),$(i)},bn=e=>{let t=(0,H.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),$(n)},xn=e=>{let t=(0,H.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),$(n)},Sn=e=>{let t=(0,H.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),$(n)},Cn=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)}},wn=e=>String(e||``).trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/^remotes\//,``),Tn=e=>e.branchName?wn(e.branchName):e.mode===`existing`?wn(e.existingBranch||e.preferredName||``):wn(e.preferredName||``),En=async e=>{let t=await pe(e);try{let n=Cn((await N(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=Cn((await P(e)).tracking);if(t?.remote)return t.remote}catch{}return null},Dn=async(e,t)=>{let n=await En(e),r=wn(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},On=async(e,t,n)=>{let r=Tn(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await Dn(e,r):i&&wn(r)?{setUpstream:!0,upstreamRemote:i,upstreamBranch:wn(r)}:null;return a?{...t,setUpstream:t.setUpstream??a.setUpstream,upstreamRemote:t.upstreamRemote||a.upstreamRemote,upstreamBranch:t.upstreamBranch||a.upstreamBranch}:t},kn=async(e,t,n)=>{let r=await On(e.path,t,n);return F(e,r)},An=`oc:lastWorktreeSourceBranch`,jn=({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},Nn=(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?` `:``}`},Pn=(e,t,n)=>{let r=Nn(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},Fn=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=Pn(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}},In=(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]},Ln=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{Fe as A,At as C,Be as D,He as E,ke as M,X as O,kt as S,Xe as T,yn as _,An as a,_n as b,kn as c,vn as d,hn as f,gn as g,bn as h,Pn as i,Pe as j,Ie as k,En as l,xn as m,In as n,Mn as o,Sn as p,Fn as r,jn as s,Ln as t,On as u,mn as v,Qe as w,Mt as x,$ as y};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,i as n}from"./runtime-switch-LvWDU-SL.js";import{Cn as r,D as i,d as a,k as o,tn as s,u as c}from"./persistence-D0y7226-.js";import{a as l,i as u,r as d}from"./vendor-zustand-B4dlGEM2.js";import{nt as f,rt as p}from"./vendor-base-ui-CnHfUmDN.js";import{B as m,Ct as h,M as g,Mt as _}from"./platform-CurqO28D.js";import{b as v,n as ee,x as y}from"./useUIStore-syVmbuDA.js";import{n as b}from"./vendor-react-DLPElpoQ.js";import{s as x}from"./vendor-tanstack-react-query-D7pys_c9.js";import{n as S}from"./vendor-reactuses-core-Dq5ocTF8.js";import{f as te,r as C,u as ne}from"./button-DIIrsMjW.js";import{Ht as re,Pn as ie,S as w,Ua as ae,_n as T,ao as E,d as D,dt as oe,ft as se,io as ce,lt as O,ma as le,mr as k,mt as A,sn as ue,ut as j,xr as de,y as fe}from"./useMobileNavigationStore-DwupvLSA.js";import{n as M}from"./Icon-B8fSTLdP.js";import{g as N,v as P}from"./gitApi-da8etTTe.js";import{f as pe,k as me,o as F}from"./projectMeta-BkhYFMaM.js";import{n as he}from"./textarea-XD2oX_Ee.js";import{n as ge,r as _e,t as ve}from"./fileMentionTouchSelection-CBzDuQxP.js";var I=e=>{switch(e.name){case`new`:return`add`;case`init`:return`file`;case`undo`:return`arrow-go-back`;case`redo`:return`arrow-go-forward`;case`timeline`:return`time`;case`compact`:return`scissors`;case`reload`:return`refresh`;case`goal`:return`target`;case`review`:return`search-eye`;case`test`:case`build`:case`run`:return`terminal-box`;default:return e.isBuiltIn?`flashlight`:`command`}},ye=()=>`book-open`,be=e=>{if(e.isDirectory)return`folder-3-fill`;switch(e.extension?.toLowerCase()){case`ts`:case`tsx`:case`js`:case`jsx`:case`json`:return`code`;case`md`:case`mdx`:return`file`;case`png`:case`jpg`:case`jpeg`:case`gif`:case`svg`:return`file-image`;default:return`file-pdf`}},xe=()=>`ai-agent`,Se=()=>`chat-thread`,Ce=(e,t)=>e.map(e=>{let n=e.isSkill?t.skill:e.isOpenChamber?`OpenChamber`:e.isBuiltIn?t.system:e.scope||e.agent||t.command;return{id:e.id,title:`/${e.name}`,subtitle:e.description,badge:n,iconName:I(e)}}),we=({skills:e=[],agents:t,sessions:n,recentFiles:r,pathHits:i,untitledSession:a,sessionBadge:o,skillBadge:s})=>{let c=[];for(let t of e)c.push({id:`skill:${t.name}-${t.scope}`,title:`@${t.name}`,subtitle:t.description,badge:s??t.scope,iconName:ye()});for(let e of t)c.push({id:`agent:${e.name}`,title:`@${e.name}`,subtitle:e.description,iconName:xe()});for(let e of n)c.push({id:`session:${e.id}`,title:e.title||a,badge:o,iconName:Se()});for(let e of r)c.push({id:`recent:${e.path}`,title:e.relativePath||e.name,iconName:be(e)});for(let e of i)c.push({id:`file:${e.path}`,title:e.relativePath||e.name,iconName:be(e)});return c},Te=(e,t)=>{let n=t.trim();if(!n.length)return[...e].sort((e,t)=>e.scope===`project`&&t.scope!==`project`?-1:e.scope!==`project`&&t.scope===`project`?1:e.name.localeCompare(t.name));let r=ie([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.scope===`project`&&t.item.scope!==`project`?-1:e.item.scope!==`project`&&t.item.scope===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score),r.map(e=>e.item)},Ee=(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=ie([...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)},De=(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}),Oe=(e,t)=>e.highlightedIndex===t.highlightedIndex&&De(e.rows,t.rows),ke=(e,t)=>De(e,t)?e:t.slice(),Ae=(e,t,n)=>{e&&(t.current&&Oe(t.current,n)||(t.current=n,e(n)))},je=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},L=e(p(),1),R=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},z=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,B=(e,t)=>{let n=R(t),r=R(e);if(!n||!r)return!1;let i=z(n),a=z(r);return a===i||a.startsWith(`${i}/`)},Me=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=R(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=>R(e)).filter(e=>B(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>R(e)).filter(e=>B(e,t)))):[],s=typeof i.selectedPath==`string`?R(i.selectedPath):null,c=s&&B(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},V=(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},Ne=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},Pe=l()(d(u((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=R((t||``).trim()),a=R((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!B(a,i)||e(e=>{let t=e.byRoot[i],n=Ne(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:V({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=R((t||``).trim()),i=R((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=z(i),a=e=>z(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:V({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=R((t||``).trim()),i=R((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=z(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=z(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:V({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=R((t||``).trim()),i=R((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=z(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=z(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:V({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=R((t||``).trim()),a=n?R(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!B(a,i)||e(e=>{let t=e.byRoot[i],n=Ne(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:V({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=R((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=R((t||``).trim()),i=R((n||``).trim());!r||!i||!B(i,r)||e(e=>{let t=e.byRoot[r],n=Ne(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:V({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=R((t||``).trim()),i=R((n||``).trim());!r||!i||!B(i,r)||e(e=>{let t=e.byRoot[r],n=Ne(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:V({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=R((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>R((e||``).trim())).filter(e=>e&&B(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=Ne(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:V({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:v(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:Me(t)}},partialize:e=>({byRoot:Me(e.byRoot)})}),{name:`files-view-tabs-store`})),H=b(),Fe=(e,t)=>{let n=(0,H.c)(4),r=t===void 0?200:t,[i,a]=L.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]),L.useEffect(o,s),i},Ie=()=>{let e=(0,H.c)(17),t=D(U),n=T(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=w(r),a=D(W),o=D(Le),s=E(G),c=E(Re),l=h(K);if(t){let r;e[2]===i?r=e[3]:(r=fe(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 U(e){return e.currentSessionId}function W(e){return e.worktreeMetadata}function Le(e){return e.newSessionDraft}function G(e){return e.activeProjectId}function Re(e){return e.projects}function K(e){return e.currentDirectory}var q=f(),J=`bg-transparent font-[inherit] text-[var(--primary-base)]`,Y=(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,q.jsx)(`mark`,{className:J,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},X=L.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:a,onClose:s,style:c,onRowsChange:l},u)=>{let{t:d}=te(),f=Ie()??``,p=D(e=>e.currentSessionId),m=de(e=>e.activeSessions),h=re({enabled:!!a}),g=E(e=>e.activeProjectId),v=E(e=>e.projects),y=L.useMemo(()=>v.find(e=>e.id===g)?.path??null,[g,v]),b=L.useMemo(()=>{let e=y||f;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[y,f]),x=Pe(e=>b?e.byRoot[b]:void 0),ie=le(e=>e.getVisibleAgents),w=_(e=>e.searchFiles),T=Fe(e,180),ce=o(),ue=i(),[fe,N]=L.useState([]),[P,pe]=L.useState([]),[me,F]=L.useState(!1),[I,xe]=L.useState(0),Se=L.useRef(0),[Ce,Ee]=L.useState(360),[De,Oe]=L.useState({}),[ke,R]=L.useState({}),z=L.useRef([]),B=L.useRef([]),Me=L.useRef([]),V=L.useRef(null),Ne=L.useRef(null),H=L.useRef(null);H.current||=ve();let U=ee(e=>e.isMobile),W=(e??``).trim(),Le=ae({directory:f||null}),G=L.useMemo(()=>r?Te(Le.data??[],W):[],[W,r,Le.data]),Re=L.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 se(n,W,{limit:6})},[W,b,x]),K=L.useMemo(()=>W.length>0?P:P.slice(0,2),[P,W.length]),J=L.useMemo(()=>a?O({sessions:k(m,h),currentSessionId:p,searchQuery:W}):[],[m,p,h,W,a]),X=Re,Z=fe;L.useEffect(()=>{let e=e=>{let t=e.target;!t||!V.current||V.current.contains(t)||s()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[s]),L.useEffect(()=>{if(!f){N([]);return}let e=(T??``).trim(),t=A(e);if(!t){N([]);return}let n=!1;F(!0);let r={includeHidden:ce,respectGitignore:!ue};return Promise.all([w(f,t,80,{...r,type:`file`}),w(f,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(Re.map(e=>e.path));N(j({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{n||N([])}).finally(()=>{n||F(!1)}),()=>{n=!0}},[f,T,Re,w,ce,ue]),L.useEffect(()=>{let t=ie().filter(e=>e.mode&&e.mode!==`primary`).map(e=>({name:e.name,description:e.description,mode:e.mode}));pe(oe(t,e??``))},[ie,e]),L.useEffect(()=>{xe(0),Oe({}),R({})},[Z,X.length,K.length,J.length,G.length]),L.useEffect(()=>{Se.current=I},[I]),L.useEffect(()=>{z.current[I]?.scrollIntoView({block:`nearest`})},[I]),L.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};B.current.forEach((n,r)=>{if(!n)return;let i=Me.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),R(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[Z,X]),L.useEffect(()=>{let e=B.current[I];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()}},[I]);let ze=S(e=>{t(e)}),Be=S(e=>{n?.(e)}),Ve=S(e=>{a?.(e)}),He=S(e=>{r?.(e)}),Ue=G.length,We=Ue,Ge=We+K.length,Ke=Ge+J.length,qe=Ke+X.length,Je=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&H.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&H.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(H.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>H.current?.pointerCancel(),onClick:()=>{H.current?.click(t)},onMouseMove:()=>xe(e)}),Ye=e=>{let t=Ue+K.length+J.length+X.length+Z.length;if(t===0)return;let n=(e%t+t)%t;if(n<Ue){let e=G[n];e&&He(e);return}if(n<Ge){let e=K[n-We];e&&Be(e.name);return}if(n<Ke){let e=J[n-Ge];e&&Ve(e);return}let r=n-Ke,i=r<X.length?X[r]:Z[r-X.length];i&&ze(i)};L.useEffect(()=>{Ae(l,Ne,{rows:we({skills:G,agents:K,sessions:J,recentFiles:X,pathHits:Z,untitledSession:d(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:d(`chat.fileMentionAutocomplete.sessionType`),skillBadge:d(`chat.commandAutocomplete.badge.skill`)}),highlightedIndex:I})},[l,I,d,K,Z,X,J,G]);let Xe=L.useRef(l);Xe.current=l,L.useEffect(()=>()=>{je(Xe.current,Ne)},[]),L.useImperativeHandle(u,()=>({acceptIndex:e=>{Ye(e)},handleKeyDown:e=>{if(e===`Escape`){s();return}let t=Ue+K.length+J.length+X.length+Z.length;if(t!==0){if(e===`ArrowDown`){xe(e=>(e+1)%t);return}if(e===`ArrowUp`){xe(e=>(e-1+t)%t);return}(e===`Enter`||e===`Tab`)&&Ye(Se.current)}}}),[Ue,Z,X,K,J,G,s,ze,Be,Ve,He]);let Ze=e=>(0,q.jsx)(M,{name:be(e),className:`h-3.5 w-3.5 text-current`});return(0,q.jsxs)(ge,{ref:V,isMobile:U,className:`max-w-[640px] max-h-64`,style:c,children:[(0,q.jsx)(he,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,q.jsxs)(`div`,{className:`pb-2`,children:[G.length>0&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.skills`)}),G.map((e,t)=>{let n=I===t;return(0,q.jsx)(`div`,{ref:e=>{z.current[t]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,_e(U,n),!U&&n&&`text-interactive-selection-foreground`),...Je(t,()=>He(e)),children:(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(M,{name:ye(),className:`h-3.5 w-3.5 translate-y-px flex-shrink-0 text-current`}),(0,q.jsxs)(`span`,{className:`min-w-0 truncate`,children:[`@`,Y(e.name,W)]}),U?null:(0,q.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:e.scope})]}),e.description&&!U?(0,q.jsx)(`div`,{className:`pl-5.5 typography-meta text-muted-foreground truncate`,children:Y(e.description,W)}):null]})},`skill-${e.name}-${e.scope}`)}),K.length>0&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.agents`)}),K.map((e,t)=>{let n=We+t,r=I===n;return(0,q.jsx)(`div`,{ref:e=>{z.current[n]=e},className:C(`flex items-start gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,_e(U,r),!U&&r&&`text-interactive-selection-foreground`),...Je(n,()=>Be(e.name)),children:(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`truncate`,children:[`@`,Y(e.name,W)]}),e.description&&!U?(0,q.jsx)(`div`,{className:`typography-meta text-muted-foreground truncate`,children:Y(e.description,W)}):null]})},`agent-${e.name}`)}),K.length===2&&W.length===0&&P.length>2&&(0,q.jsx)(`div`,{className:`px-3 py-1 typography-meta text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.searchMoreAgents`)}),J.length>0&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.sessions`)}),J.map((e,t)=>{let n=Ge+t,r=I===n;return(0,q.jsxs)(`div`,{ref:e=>{z.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,_e(U,r),!U&&r&&`text-interactive-selection-foreground`),...Je(n,()=>Ve(e)),children:[(0,q.jsx)(M,{name:`chat-thread`,className:`h-4 w-4 flex-shrink-0 text-[var(--primary-base)]`}),(0,q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title||d(`chat.fileMentionAutocomplete.untitledSession`),children:Y(e.title||d(`chat.fileMentionAutocomplete.untitledSession`),W)}),U?null:(0,q.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.sessionType`)})]},`session-${e.id}`)}),X.length>0&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.recentFiles`)}),X.map((e,t)=>{let n=Ke+t,r=e.relativePath||e.name,i=ne(r,{maxLength:60}),a=I===n,o=De[n]??!1,s=ke[n]??2.6;return(0,q.jsxs)(`div`,{ref:e=>{z.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,_e(U,a),!U&&a&&`text-interactive-selection-foreground`),...Je(n,()=>ze(e)),children:[Ze(e),(0,q.jsxs)(`span`,{ref:e=>{B.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${Ce}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,q.jsx)(`span`,{ref:e=>{Me.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,q.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Y(r,W)}):(0,q.jsx)(`span`,{className:`block truncate`,children:Y(i,W)})]})]},`recent-${e.path}`)}),Z.length>0&&(0,q.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.files`)}),Z.map((e,t)=>{let n=qe+t,r=e.relativePath||e.name,i=ne(r,{maxLength:60}),a=I===n,o=De[n]??!1,s=ke[n]??2.6;return(0,q.jsxs)(`div`,{ref:e=>{z.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,U&&`min-h-11`,_e(U,a),!U&&a&&`text-interactive-selection-foreground`),...Je(n,()=>ze(e)),children:[Ze(e),(0,q.jsxs)(`span`,{ref:e=>{B.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${Ce}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,q.jsx)(`span`,{ref:e=>{Me.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,q.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Y(r,W)}):(0,q.jsx)(`span`,{className:`block truncate`,children:Y(i,W)})]})]},e.path)}),me&&Z.length===0?(0,q.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,q.jsx)(M,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!me&&Z.length===0&&X.length===0&&K.length===0&&J.length===0&&G.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.empty`)})]})}),!U&&(0,q.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:d(`chat.autocomplete.keyboardHint`)})]})}),Z=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`goal`,`btw`]),ze=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&Z.has(n))},Be=(e,t)=>!e||t({name:e}),Ve=` `,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]===Ve&&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)]`),qe=C(Ue,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),Je=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),Ye=(e,t)=>{let n=!!e.sessionID;return{hasSession:n,canStartSessionCommand:n||e.hasNewDraft,canUseReviewHandoffFlow:n&&!t&&!s()}},Xe=L.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:r,style:i,commandPolicy:a,commandContext:o,onRowsChange:c},l)=>{let{t:u}=te(),d=ee(e=>e.isMobile),f=D(e=>e.currentSessionId),p=D(e=>!!e.newSessionDraft?.open),m=D(L.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=ue(f??``,m??void 0),g=L.useMemo(()=>o??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[o,f,h.length,p]),{hasSession:_,canStartSessionCommand:v,canUseReviewHandoffFlow:y}=L.useMemo(()=>Ye(g,d),[g,d]),b=g.hasMessages,[x,S]=L.useState([]),[ne,re]=L.useState(!1),ie=ce({directory:r}),w=L.useMemo(()=>ie.data??[],[ie.data]),ae=ie.isFetching,[T,E]=L.useState(0),oe=L.useRef(0),se=L.useRef(!1),O=L.useRef([]),le=L.useRef(null),k=L.useRef(!1),A=L.useRef(null),j=L.useRef(!1),de=L.useRef(null);L.useEffect(()=>{let e=e=>{let t=e.target;!t||!le.current||le.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),L.useEffect(()=>{(async()=>{re(ae);try{let t=w.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:`openchamber:new`,name:`new`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!b?[{id:`openchamber:init`,name:`init`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:btw`,name:`btw`,source:`openchamber`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`openchamber:undo`,name:`undo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`openchamber:redo`,name:`redo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`openchamber:fork`,name:`fork`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`openchamber:timeline`,name:`timeline`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`openchamber:model`,name:`model`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`openchamber:compact`,name:`compact`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...s()?[{id:`openchamber:reload`,name:`reload`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:summary`,name:`summary`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:workspace-review`,name:`workspace-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isOpenChamber:!0}]:[],...y?[{id:`openchamber:handoff-review`,name:`handoff-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:craft-goal`,name:`craft-goal`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:goal`,name:`goal`,source:`openchamber`,description:u(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],...v?[{id:`openchamber:catch-up`,name:`catch-up`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:debug`,name:`debug`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.debugDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:weigh`,name:`weigh`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.weighDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:explore`,name:`explore`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isOpenChamber:!0}]:[],...t],r=!b,i=Ee(n.filter(e=>(r||e.name!==`init`)&&(a?.(e)??!0)),e);S(e=>Je(e,i)?e:i)}catch{let t=!b,n=Ee([{id:`openchamber:new`,name:`new`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!b?[{id:`openchamber:init`,name:`init`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:btw`,name:`btw`,source:`openchamber`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`openchamber:undo`,name:`undo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`openchamber:redo`,name:`redo`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`openchamber:fork`,name:`fork`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`openchamber:timeline`,name:`timeline`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`openchamber:model`,name:`model`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`openchamber:compact`,name:`compact`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...s()?[{id:`openchamber:reload`,name:`reload`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:summary`,name:`summary`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:workspace-review`,name:`workspace-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isOpenChamber:!0}]:[],...y?[{id:`openchamber:handoff-review`,name:`handoff-review`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:craft-goal`,name:`craft-goal`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:goal`,name:`goal`,source:`openchamber`,description:u(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],...v?[{id:`openchamber:catch-up`,name:`catch-up`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:debug`,name:`debug`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.debugDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:weigh`,name:`weigh`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.weighDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:explore`,name:`explore`,source:`openchamber`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isOpenChamber:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(a?.(e)??!0)),e);S(e=>Je(e,n)?e:n)}finally{re(!1)}})()},[e,b,_,v,y,w,ae,u,a]),L.useEffect(()=>{E(0)},[x]),L.useEffect(()=>{oe.current=T},[T]),L.useEffect(()=>{O.current[T]?.scrollIntoView({block:`nearest`})},[T]),L.useEffect(()=>{Ae(c,de,{rows:Ce(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 fe=L.useRef(c);fe.current=c,L.useEffect(()=>()=>{je(fe.current,de)},[]),L.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=x[e];r&&t(r,ze(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,ze(i,e===`Enter`))}}}}),[x,n,t]);let N=e=>{let t=I(e);switch(e.name){case`new`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,q.jsx)(M,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,q.jsxs)(ge,{ref:le,isMobile:d,className:`max-w-[450px] max-h-64`,style:i,children:[(0,q.jsx)(he,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:ne?(0,q.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,q.jsx)(M,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,q.jsxs)(`div`,{children:[x.map((n,r)=>{let i=n.isBuiltIn,a=n.isOpenChamber;return(0,q.jsxs)(`div`,{ref:e=>{O.current[r]=e},className:C(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,_e(d,r===T),!d&&r===T&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(A.current={x:e.clientX,y:e.clientY},j.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!A.current)return;let t=e.clientX-A.current.x,n=e.clientY-A.current.y;Math.hypot(t,n)>6&&(j.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=j.current;A.current=null,j.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),k.current=!0,t(n,ze(n,d)))},onPointerCancel:()=>{A.current=null,j.current=!1},onClick:()=>{if(k.current){k.current=!1;return}t(n,ze(n,d))},onMouseMove:()=>{se.current=!1,E(r)},children:[(0,q.jsx)(`div`,{className:C(!d&&`mt-0.5`),children:N(n)}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,Y(n.name,e)]}),n.isSkill?(0,q.jsx)(`span`,{className:We,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,q.jsx)(`span`,{className:We,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,q.jsx)(`span`,{className:qe,children:`OpenChamber`}):i?(0,q.jsx)(`span`,{className:qe,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,q.jsx)(`span`,{className:n.scope===`project`?Ke:Ge,children:n.scope}):null,n.agent&&(0,q.jsx)(`span`,{className:qe,children:n.agent})]}),n.description&&!d&&(0,q.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Y(n.description,e)})]})]},n.id)}),x.length===0&&(0,q.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,q.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});Xe.displayName=`CommandAutocomplete`;function Ze(e){return(e.description||e.content).replace(/\s+/g,` `).trim().slice(0,120)}var Qe=L.forwardRef((e,t)=>{let n=(0,H.c)(63),{searchQuery:r,onSnippetSelect:i,onClose:a,style:o}=e,{t:s}=te(),c=L.useRef(null),l=ee($e),[u,d]=L.useState(0),f=L.useRef(0),p;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=[],n[0]=p):p=n[0];let[m,h]=L.useState(p),g;n[1]===Symbol.for(`react.memo_cache_sentinel`)?(g=[],n[1]=g):g=n[1];let _=L.useRef(g),v=me(et),y=me(tt),b=me(nt),x=me(rt),S=ee(it),ne=ee(at),re,w;n[2]===y?(re=n[3],w=n[4]):(re=()=>{y()},w=[y],n[2]=y,n[3]=re,n[4]=w),L.useEffect(re,w);let ae,T;n[5]!==r||n[6]!==v?(ae=()=>{let e=r.trim();if(!e.length){let e=[...v].sort(ot);h(e),d(+!!e.length);return}let t=ie(v,e,st);t.sort(ct);let n=t.map(lt);h(n),d(+!!n.length)},T=[r,v],n[5]=r,n[6]=v,n[7]=ae,n[8]=T):(ae=n[7],T=n[8]),L.useEffect(ae,T);let E,D;n[9]===u?(E=n[10],D=n[11]):(E=()=>{f.current=u,_.current[u]?.scrollIntoView({block:`nearest`})},D=[u],n[9]=u,n[10]=E,n[11]=D),L.useEffect(E,D);let oe,se;n[12]===a?(oe=n[13],se=n[14]):(se=()=>{let e=e=>{let t=e.target;t&&c.current&&!c.current.contains(t)&&a()};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},oe=[a],n[12]=a,n[13]=oe,n[14]=se),L.useEffect(se,oe);let ce;n[15]!==i||n[16]!==r?(ce=e=>{let t=r.trim(),n=e.aliases.includes(t)?t:e.name;i(e,n)},n[15]=i,n[16]=r,n[17]=ce):ce=n[17];let O=ce,le;n[18]!==a||n[19]!==x||n[20]!==S||n[21]!==ne||n[22]!==b||n[23]!==v?(le=()=>{let e=new Set(v.map(ut)),t=`new-snippet`,n=1;for(;e.has(t);)t=`new-snippet-${n++}`;b({name:t,scope:`global`}),x(t),ne(`snippets`),S(!0),a()},n[18]=a,n[19]=x,n[20]=S,n[21]=ne,n[22]=b,n[23]=v,n[24]=le):le=n[24];let k=le,A,ue;n[25]!==O||n[26]!==m||n[27]!==a||n[28]!==k?(A=()=>({handleKeyDown:e=>{if(e===`Escape`){a();return}let t=m.length+1;if(e===`ArrowDown`){d(e=>(e+1)%t);return}if(e===`ArrowUp`){d(e=>(e-1+t)%t);return}if(e===`Enter`||e===`Tab`){if(f.current===0){k();return}let e=m[f.current-1];e&&O(e)}}}),ue=[O,m,a,k],n[25]=O,n[26]=m,n[27]=a,n[28]=k,n[29]=A,n[30]=ue):(A=n[29],ue=n[30]),L.useImperativeHandle(t,A,ue);let j;n[31]===Symbol.for(`react.memo_cache_sentinel`)?(j=e=>{_.current[0]=e},n[31]=j):j=n[31];let de;n[32]!==l||n[33]!==u?(de=C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,_e(l,u===0)),n[32]=l,n[33]=u,n[34]=de):de=n[34];let fe,N;n[35]===Symbol.for(`react.memo_cache_sentinel`)?(fe=()=>d(0),N=(0,q.jsx)(M,{name:`add`,className:`h-3.5 w-3.5 text-muted-foreground`}),n[35]=fe,n[36]=N):(fe=n[35],N=n[36]);let P;n[37]===s?P=n[38]:(P=s(`chat.snippetAutocomplete.action.addNew`),n[37]=s,n[38]=P);let pe;n[39]===P?pe=n[40]:(pe=(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:P}),n[39]=P,n[40]=pe);let F;n[41]!==k||n[42]!==de||n[43]!==pe?(F=(0,q.jsxs)(`div`,{ref:j,className:de,onClick:k,onMouseMove:fe,children:[N,pe]}),n[41]=k,n[42]=de,n[43]=pe,n[44]=F):F=n[44];let ve;n[45]!==O||n[46]!==m||n[47]!==l||n[48]!==r||n[49]!==u||n[50]!==s?(ve=m.length?m.map((e,t)=>(0,q.jsx)(`div`,{ref:e=>{_.current[t+1]=e},className:C(`flex gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,l?`items-center`:`items-start`,_e(l,t+1===u)),onClick:()=>O(e),onMouseMove:()=>d(t+1),children:(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`span`,{className:`truncate`,children:[`#`,Y(e.name,r)]}),(0,q.jsx)(`span`,{className:`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0 bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`,children:s(`snippets.source.${e.source}`)})]}),!l&&(0,q.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Y(Ze(e),r)})]})},`${e.source}:${e.filePath}`)):(0,q.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:s(`chat.snippetAutocomplete.empty`)}),n[45]=O,n[46]=m,n[47]=l,n[48]=r,n[49]=u,n[50]=s,n[51]=ve):ve=n[51];let I;n[52]!==F||n[53]!==ve?(I=(0,q.jsxs)(he,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 pb-2`,children:[F,ve]}),n[52]=F,n[53]=ve,n[54]=I):I=n[54];let ye;n[55]!==l||n[56]!==s?(ye=!l&&(0,q.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:s(`chat.snippetAutocomplete.footer`)}),n[55]=l,n[56]=s,n[57]=ye):ye=n[57];let be;return n[58]!==l||n[59]!==o||n[60]!==I||n[61]!==ye?(be=(0,q.jsxs)(ge,{ref:c,isMobile:l,className:`max-w-[450px] max-h-60`,style:o,children:[I,ye]}),n[58]=l,n[59]=o,n[60]=I,n[61]=ye,n[62]=be):be=n[62],be});Qe.displayName=`SnippetAutocomplete`;function $e(e){return e.isMobile}function et(e){return e.snippets}function tt(e){return e.loadSnippets}function nt(e){return e.setSnippetDraft}function rt(e){return e.setSelectedSnippet}function it(e){return e.setSettingsDialogOpen}function at(e){return e.setSettingsPage}function ot(e,t){return e.source===`project`&&t.source!==`project`?-1:e.source!==`project`&&t.source===`project`?1:e.name.localeCompare(t.name)}function st(e){return[e.name,...e.aliases]}function ct(e,t){return e.score===t.score?e.item.source===`project`&&t.item.source!==`project`?-1:e.item.source!==`project`&&t.item.source===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score}function lt(e){return e.item}function ut(e){return e.name}var dt=2,ft=e=>!!e&&typeof e==`object`&&!Array.isArray(e),pt=e=>{let t=e?.trim().replace(/\\/g,`/`);return t?t.length>1?t.replace(/\/+$/,``):t:null},mt=e=>ft(e)&&Array.isArray(e.all)&&e.all.every(e=>typeof e==`string`)&&typeof e.current==`string`&&ft(e.branches),ht=(e,t)=>JSON.stringify([e,t]),gt=e=>`version`in e&&e.version===dt&&ft(e.entries),_t=e=>{if(!e)return null;try{let t=JSON.parse(e);return ft(t)?t.version===dt&&ft(t.entries)?{version:dt,entries:t.entries}:t:null}catch{return null}},vt=(e,t)=>{try{e.setItem(`oc.gitBranchCache`,JSON.stringify(t))}catch{}},yt=(e,t,n)=>{let r=pt(e);if(!r||!t)return null;let i;try{i=n.getItem(`oc.gitBranchCache`)}catch{return null}let a=_t(i);if(!a)return null;if(gt(a))return mt(a.entries[ht(t,r)])?a.entries[ht(t,r)]:null;let o={};for(let[e,n]of Object.entries(a)){let r=pt(e);r&&mt(n)&&(o[ht(t,r)]=n)}return vt(n,{version:dt,entries:o}),o[ht(t,r)]??null},bt=(e,t,n,r)=>{let i=pt(e);if(!i||!t||!mt(n))return;let a=null;try{a=r.getItem(`oc.gitBranchCache`)}catch{return}let o=_t(a);vt(r,{version:dt,entries:{...o&>(o)?o.entries:{},[ht(t,i)]:n}})},xt=3e4,St=pt,Ct=(e,t=n())=>a.git.branches(St(e),t),wt=(e,t=n())=>a.git.remotes(St(e),t),Tt=async(e,t,n)=>{n.throwIfAborted();let i=r()?.git,a=t?.getGitBranches?await t.getGitBranches(e,{signal:n}):i?await i.getGitBranches(e,{signal:n}):await g(e,{signal:n});return n.throwIfAborted(),a},Et=async(e,t,n)=>{n.throwIfAborted();let i=r()?.git,a=t?.getRemotes?await t.getRemotes(e,{signal:n}):i?await i.getRemotes(e,{signal:n}):await m(e,{signal:n});return n.throwIfAborted(),a},Dt=(e,t,r=n(),i=y())=>{let a=St(e),o=t;return{queryKey:Ct(a,r),queryFn:async({signal:e})=>{if(!a)throw Error(`Git branches require a directory`);let t=await Tt(a,o,e);return bt(a,r,t,i),t},staleTime:xt,gcTime:1/0,initialData:()=>yt(a,r,i)??void 0,initialDataUpdatedAt:0}},Ot=(e,t,r=n())=>{let i=St(e),a=t;return{queryKey:wt(i,r),queryFn:({signal:e})=>{if(!i)throw Error(`Git remotes require a directory`);return Et(i,a,e)},staleTime:xt,gcTime:1/0}},kt=(e,r,i)=>{let a=(0,H.c)(9),o=i===void 0||i,s=L.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=St(e),u=x,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)},At=(e,r,i)=>{let a=(0,H.c)(9),o=i===void 0||i,s=L.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=St(e),u=x,l=Ot(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)},jt=(e,t,r=c,i=n())=>r.fetchQuery(Dt(e,t,i)),Mt=(e,t,r=c,i=n())=>r.fetchQuery({...Dt(e,t,i),staleTime:0}),Nt=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,Pt=1e4,Ft=6e4,It=5e3,Lt=3e4,Rt=6e4,zt=25,Bt=40,Vt=2,Ht=15e3,Ut=500,Wt=30,Gt=20971520,Kt=new Map,qt=new Map,Jt=new Map,Yt=new Map,Xt=new Map,Zt=(e,t)=>`${t}:${e}`,Qt=e=>qt.get(e)??0,$t=e=>{let t=Qt(e)+1;return qt.set(e,t),t},en=e=>{let t=(Jt.get(e)??0)+1;return Jt.set(e,t),t},tn=e=>{let t=Kt.get(e);if(t)return t;let n=new Set;return Kt.set(e,n),n},Q=()=>({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}),nn=(e,t=Wt,n=Gt)=>{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},rn=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=new Set([...Object.keys(e),...Object.keys(t)]);for(let r of n){let n=e[r],i=t[r];if(!(!n&&!i)&&(!n||!i||n.insertions!==i.insertions||n.deletions!==i.deletions))return!0}return!1},an=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,on=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=e.files??[],r=t.files??[];if(n.length!==r.length||e.ahead!==t.ahead||e.behind!==t.behind||e.current!==t.current||e.tracking!==t.tracking||e.isClean!==t.isClean||t.upstreamComparison!==void 0&&an(e.upstreamComparison,t.upstreamComparison))return!0;let i=new Set(n.map(e=>`${e.path}:${e.index}:${e.working_dir}`));for(let e of r)if(!i.has(`${e.path}:${e.index}:${e.working_dir}`))return!0;return!!(t.diffStats!==void 0&&rn(e.diffStats,t.diffStats))},sn=(e,t)=>{let n=new Set;if(!t)return n;let r=e?.files??[],i=t.files??[],a=new Map(r.map(e=>[e.path,e])),o=new Map(i.map(e=>[e.path,e])),s=new Set([...a.keys(),...o.keys()]);for(let e of s){let t=a.get(e),r=o.get(e);if(!t||!r){n.add(e);continue}if(t.index!==r.index||t.working_dir!==r.working_dir){n.add(e);continue}}if(t.diffStats!==void 0){let r=e?.diffStats??{},i=t.diffStats??{},a=new Set([...Object.keys(r),...Object.keys(i)]);for(let e of a){let t=r[e],a=i[e];if(!t||!a){n.add(e);continue}(t.insertions!==a.insertions||t.deletions!==a.deletions)&&n.add(e)}}return n},cn=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=e.files??[],r=t.files??[],i=e=>{let t=e?.trim()??``;return t===`?`?``:t},a=new Map(n.map(e=>[e.path,i(e.index)])),o=new Map(r.map(e=>[e.path,i(e.index)])),s=new Set([...a.keys(),...o.keys()]);for(let e of s)if((a.get(e)??``)!==(o.get(e)??``))return!0;return!1},ln=e=>!e||e.trim().length===0,un=e=>(e||``).trim()===`U`,dn=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(un(t)||un(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},fn=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(un(t)||un(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},pn=e=>ln(e.index)&&ln(e.working_dir),$=l()(d((e,t)=>({directories:new Map,activeDirectory:null,setActiveDirectory:n=>{let{activeDirectory:r,directories:i}=t();if(r!==n)if(r&&$t(r),n&&$t(n),n&&!i.has(n)){let t=new Map(i);t.set(n,Q()),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=Zt(n,a),s=Yt.get(o)??(a===`light`?Yt.get(Zt(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||=Q(),!a){let r=new Map(t().directories),i=r.get(n)??Q();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)>Ft,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);if(on(s.status,u)){c=!0;let r=new Map(t().directories),i=r.get(n)??Q(),s=sn(i.status,u),l=cn(i.status,u),d=new Set((i.status?.files??[]).map(e=>e.path)),f=new Set((u.files??[]).map(e=>e.path)),p=new Map(i.diffCache);for(let e of d)f.has(e)||p.delete(e);for(let e of s)p.delete(e);let m=s.size>0;m&&$t(n);let h={...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:h,diffCache:p,indexRevision:l?i.indexRevision+1:i.indexRevision,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:m?Date.now():i.lastStatusChange}),e({directories:r})}else{let r=new Map(t().directories),i=r.get(n)??Q();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)??Q();r.set(n,{...i,isLoadingStatus:!1}),e({directories:r})}}return c})();Yt.set(o,c);try{return await c}finally{Yt.get(o)===c&&Yt.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`?dn(e):fn(e);t!==e&&(l=!0),pn(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=en(r);{let n=new Map(t().directories),i=n.get(r)??Q();n.set(r,{...i,isLoadingBranches:!0}),e({directories:n})}try{let c=a.force?await Mt(r,i,void 0,o):await jt(r,i,void 0,o);if(s!==Jt.get(r)||o!==n())return;let l=new Map(t().directories),u=l.get(r)??Q();l.set(r,{...u,branches:c,branchesTransportIdentity:o,isLoadingBranches:!1,lastBranchesFetch:Date.now()}),e({directories:l})}catch(i){if(Nt(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)??Q();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)??Q();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)??Q();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)??Q();i.set(n,{...a,isLoadingLog:!1}),e({directories:i})}},fetchIdentity:async(n,r)=>{{let r=new Map(t().directories),i=r.get(n)??Q();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)??Q();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)??Q();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=Q();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>Pt||!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)??Q(),s=new Map(o.diffCache);s.set(r,{...i,fetchedAt:Date.now()});let c=nn(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{$t(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,zt);await t().prefetchDiffs(e,n,i,{maxFiles:zt})},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=Bt}=a,c=new Set(o.status.files.map(e=>e.path)),l=o.status.diffStats,u=tn(n),d=[],f=new Set;for(let e of i){if(!e||f.has(e)||(f.add(e),!c.has(e))||o.diffCache.has(e)||u.has(e))continue;let t=l?.[e];t&&t.insertions+t.deletions>Ut||d.push(e)}let p=d.slice(0,Math.max(1,s));if(p.length===0)return;let m=Qt(n);if(typeof document<`u`&&document.hidden)return;p.forEach(e=>u.add(e));let h=0,g=[],_=()=>{let e=h;return h+=1,e<p.length?p[e]:null},v=async e=>{let t=r.getGitFileDiff(n,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${Ht}ms`)),Ht)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},ee=async()=>{for(;;){if(m!==Qt(n))return;let e=_();if(!e)return;try{g.push(await v(e))}catch{}finally{u.delete(e)}}},y=Math.min(Vt,p.length);if(await Promise.allSettled(Array.from({length:y},()=>ee())),p.forEach(e=>u.delete(e)),m!==Qt(n))return;let b=new Map(t().directories),x=b.get(n);if(!x)return;let S=new Map(x.diffCache),te=Date.now();g.forEach(e=>{!e.diff.isBinary&&e.diff.original===``&&e.diff.modified===``||S.set(e.path,{...e.diff,fetchedAt:te})});let C=nn(S);b.set(n,{...x,diffCache:C}),e({directories:b})},setLogMaxCount:(n,r)=>{let i=new Map(t().directories),a=i.get(n)??Q();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<It||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=Xt.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)>=It)&&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>=Lt)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=Pt)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=Rt)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return Xt.set(e,i),i.finally(()=>{Xt.get(e)===i&&Xt.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),mn=e=>{let t=(0,H.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),$(n)},hn=e=>{let r=(0,H.c)(3),i=L.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],$(a)},gn=e=>{let t=(0,H.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),$(n)},_n=e=>{let t=(0,H.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),$(n)},vn=e=>{let t=(0,H.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),$(n)},yn=e=>{let t=(0,H.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=L.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),$(i)},bn=e=>{let t=(0,H.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),$(n)},xn=e=>{let t=(0,H.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),$(n)},Sn=e=>{let t=(0,H.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),$(n)},Cn=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)}},wn=e=>String(e||``).trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/^remotes\//,``),Tn=e=>e.branchName?wn(e.branchName):e.mode===`existing`?wn(e.existingBranch||e.preferredName||``):wn(e.preferredName||``),En=async e=>{let t=await pe(e);try{let n=Cn((await N(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=Cn((await P(e)).tracking);if(t?.remote)return t.remote}catch{}return null},Dn=async(e,t)=>{let n=await En(e),r=wn(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},On=async(e,t,n)=>{let r=Tn(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await Dn(e,r):i&&wn(r)?{setUpstream:!0,upstreamRemote:i,upstreamBranch:wn(r)}:null;return a?{...t,setUpstream:t.setUpstream??a.setUpstream,upstreamRemote:t.upstreamRemote||a.upstreamRemote,upstreamBranch:t.upstreamBranch||a.upstreamBranch}:t},kn=async(e,t,n)=>{let r=await On(e.path,t,n);return F(e,r)},An=`oc:lastWorktreeSourceBranch`,jn=({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},Nn=(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?` `:``}`},Pn=(e,t,n)=>{let r=Nn(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},Fn=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=Pn(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}},In=(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]},Ln=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{Fe as A,At as C,Be as D,He as E,ke as M,X as O,kt as S,Xe as T,yn as _,An as a,_n as b,kn as c,vn as d,hn as f,gn as g,bn as h,Pn as i,Pe as j,Ie as k,En as l,xn as m,In as n,Mn as o,Sn as p,Fn as r,jn as s,Ln as t,On as u,mn as v,Qe as w,Mt as x,$ as y};
|