@openchambery/web 2.0.2-beta.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/assets/{AssistantView-nQrigS4V.js → AssistantView-IobZeLMK.js} +3 -3
  2. package/dist/assets/{DiagramView-DjTaMDNe.js → DiagramView-CaX3wQmk.js} +1 -1
  3. package/dist/assets/MarkdownRenderer-BR3GGkaV.js +2 -0
  4. package/dist/assets/{MarkdownRendererImpl-DyIUIr4N.js → MarkdownRendererImpl-BBi4enXr.js} +1 -1
  5. package/dist/assets/{MarkstreamRendererImpl-DO9IukOP.js → MarkstreamRendererImpl-D29Hxacd.js} +1 -1
  6. package/dist/assets/{MobileDetailNavigation-CsmkM6q9.js → MobileDetailNavigation-DnMMLeWa.js} +1 -1
  7. package/dist/assets/{MobileShareBridge-WU4cZ2YS.js → MobileShareBridge-C2wW1Jn5.js} +1 -1
  8. package/dist/assets/MobileTabPageHeader-Dut8qwOp.js +2 -0
  9. package/dist/assets/{MultiRunWindow-X7nbM3XI.js → MultiRunWindow-DfIQdd6N.js} +1 -1
  10. package/dist/assets/{OverlayScrollbar-CVgW_Z9B.js → OverlayScrollbar-Brzy-kXO.js} +1 -1
  11. package/dist/assets/{SettingsView-Z1JssjqY.js → SettingsView-C5423SQ1.js} +1 -1
  12. package/dist/assets/{SettingsWindow-BhfyWkL2.js → SettingsWindow-CyAp8i7h.js} +1 -1
  13. package/dist/assets/{TerminalView-CqxD82fz.js → TerminalView-C5XWIu3F.js} +1 -1
  14. package/dist/assets/{ToolOutputDialog-WgwI-9al.js → ToolOutputDialog-D4DWCxvI.js} +1 -1
  15. package/dist/assets/{appThemeRegistry-BoxYSKnf.js → appThemeRegistry-CqF7vjgv.js} +1 -1
  16. package/dist/assets/{fileMentionTouchSelection-Du5yXyiw.js → fileMentionTouchSelection-BiHRyKLM.js} +1 -1
  17. package/dist/assets/{gitApi-0zlv_uGd.js → gitApi-BET0Byz4.js} +1 -1
  18. package/dist/assets/{insertionBoundaries-DEmm2KEx.js → insertionBoundaries-BolaZO_L.js} +1 -1
  19. package/dist/assets/{main-D4XFK0Ul.js → main-BYD7ZoLH.js} +4 -4
  20. package/dist/assets/{main-BTIowmls.js → main-C7GCHEEF.js} +2 -2
  21. package/dist/assets/{mcpQueries-Ct1GVJ1_.js → mcpQueries-B4Az0xG3.js} +1 -1
  22. package/dist/assets/{miniChat-B076IsbD.js → miniChat-BCYRFDdi.js} +2 -2
  23. package/dist/assets/{mobile-Ch9Y067K.js → mobile-DQrWwemv.js} +2 -2
  24. package/dist/assets/{multirun-DU_s2vv-.js → multirun-DSHVEjC1.js} +1 -1
  25. package/dist/assets/{platform-Bxaalnc8.js → platform-CAw45mRH.js} +1 -1
  26. package/dist/assets/{projectMeta-Br-6p4Ek.js → projectMeta-Dt7jGs7G.js} +1 -1
  27. package/dist/assets/{renderElectronMiniChatApp-2SCJo2V5.js → renderElectronMiniChatApp-Dg0KAxOh.js} +2 -2
  28. package/dist/assets/{renderMobileApp-So0sDER7.js → renderMobileApp-B7ujjkys.js} +4 -4
  29. package/dist/assets/{runtimeConfig-BNgQOf6h.js → runtimeConfig-Ck3U6U69.js} +1 -1
  30. package/dist/assets/{runtimeEndpointReset-CJh46Mcc.js → runtimeEndpointReset-BLhNx9Ha.js} +1 -1
  31. package/dist/assets/{sessionChangeSummary-DLDfqKFw.js → sessionChangeSummary-CCwFZMko.js} +1 -1
  32. package/dist/assets/{sessionLookup-DSwSyWLE.js → sessionLookup-D1SMVVVx.js} +1 -1
  33. package/dist/assets/{sortable-tabs-strip-CKKp4p3Y.js → sortable-tabs-strip-Df46aoL0.js} +1 -1
  34. package/dist/assets/{terminalApi-DSJOXNRQ.js → terminalApi-D_9-ZZGH.js} +1 -1
  35. package/dist/assets/{textarea-DUjc3iDJ.js → textarea-5RcNvWr-.js} +1 -1
  36. package/dist/assets/{useAppFontEffects-F8byXxse.js → useAppFontEffects-Boj2N0LY.js} +5 -5
  37. package/dist/assets/{useDesktopWindowControlsLayout-CLQU_f5A.js → useDesktopWindowControlsLayout-BHouamSC.js} +1 -1
  38. package/dist/assets/{useEffectiveDirectory-CePbms3i.js → useEffectiveDirectory--BFcBzXy.js} +1 -1
  39. package/dist/assets/{useFontPreferences-DGbTdGy3.js → useFontPreferences-wessJ1bY.js} +1 -1
  40. package/dist/assets/{useMobileNavigationStore-Bjq9HvrR.js → useMobileNavigationStore-CEhyCPzG.js} +20 -20
  41. package/dist/assets/{useSessionAutoCleanup-DdiIB8Vv.js → useSessionAutoCleanup-DtJnFdK_.js} +1 -1
  42. package/dist/assets/{useWorkerHighlightedLines-CKjzXbrt.js → useWorkerHighlightedLines-xOfdvJAv.js} +1 -1
  43. package/dist/index.html +4 -4
  44. package/dist/mini-chat.html +4 -4
  45. package/dist/mobile.html +4 -4
  46. package/package.json +1 -1
  47. package/server/lib/session-index/DOCUMENTATION.md +10 -4
  48. package/server/lib/session-index/service.js +19 -2
  49. package/server/lib/session-index/service.test.js +52 -0
  50. package/server/lib/session-index/sync-runtime.js +3 -17
  51. package/server/lib/session-index/sync-runtime.test.js +29 -0
  52. package/server/lib/session-metadata/DOCUMENTATION.md +6 -4
  53. package/dist/assets/MarkdownRenderer-DejwwmAe.js +0 -2
  54. package/dist/assets/MobileTabPageHeader-8v-HjesS.js +0 -2
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,i as n}from"./runtime-switch-BJM2k_uH.js";import{A as r,M as i,On as a,d as o,f as s,on as c}from"./persistence-CwHY3fDg.js";import{a as l,i as u,r as d}from"./vendor-zustand-DzRqcymP.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-Bxaalnc8.js";import{b as v,n as ee,x as y}from"./useUIStore-DNkuudYO.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-CcOoDLE1.js";import{Dr as re,Ra as ie,S as ae,Vt as oe,_t as w,br as se,cn as ce,d as T,dt as le,eo as ue,ft as de,mt as fe,pa as pe,pt as me,to as E,vn as D,y as he,zn as ge}from"./useMobileNavigationStore-Bjq9HvrR.js";import{n as O}from"./Icon-BE2hkaYc.js";import{g as _e,v as ve}from"./gitApi-0zlv_uGd.js";import{f as ye,o as be}from"./projectMeta-Br-6p4Ek.js";import{n as xe}from"./textarea-DUjc3iDJ.js";import{n as Se,r as Ce,t as we}from"./fileMentionTouchSelection-Du5yXyiw.js";var Te=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`}},Ee=()=>`book-open`,De=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`}},k=()=>`ai-agent`,Oe=()=>`chat-thread`,ke=(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:Te(e)}}),Ae=({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:Ee()});for(let e of t)c.push({id:`agent:${e.name}`,title:`@${e.name}`,subtitle:e.description,iconName:k()});for(let e of n)c.push({id:`session:${e.id}`,title:e.title||a,badge:o,iconName:Oe()});for(let e of r)c.push({id:`recent:${e.path}`,title:e.relativePath||e.name,iconName:De(e)});for(let e of i)c.push({id:`file:${e.path}`,title:e.relativePath||e.name,iconName:De(e)});return c},je=(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=ge([...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)},Me=(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=ge([...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)},Ne=(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}),Pe=(e,t)=>e.highlightedIndex===t.highlightedIndex&&Ne(e.rows,t.rows),Fe=(e,t)=>Ne(e,t)?e:t.slice(),Ie=(e,t,n)=>{e&&(t.current&&Pe(t.current,n)||(t.current=n,e(n)))},Le=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},A=e(p(),1),j=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},M=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,N=(e,t)=>{let n=j(t),r=j(e);if(!n||!r)return!1;let i=M(n),a=M(r);return a===i||a.startsWith(`${i}/`)},Re=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=j(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=>j(e)).filter(e=>N(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>j(e)).filter(e=>N(e,t)))):[],s=typeof i.selectedPath==`string`?j(i.selectedPath):null,c=s&&N(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},P=(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},F=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},ze=l()(d(u((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=j((t||``).trim()),a=j((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!N(a,i)||e(e=>{let t=e.byRoot[i],n=F(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:P({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=j((t||``).trim()),i=j((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=M(i),a=e=>M(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:P({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=j((t||``).trim()),i=j((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=M(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=M(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:P({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=j((t||``).trim()),i=j((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=M(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=M(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:P({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=j((t||``).trim()),a=n?j(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!N(a,i)||e(e=>{let t=e.byRoot[i],n=F(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:P({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=j((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=j((t||``).trim()),i=j((n||``).trim());!r||!i||!N(i,r)||e(e=>{let t=e.byRoot[r],n=F(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:P({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=j((t||``).trim()),i=j((n||``).trim());!r||!i||!N(i,r)||e(e=>{let t=e.byRoot[r],n=F(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:P({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=j((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>j((e||``).trim())).filter(e=>e&&N(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=F(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:P({...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:Re(t)}},partialize:e=>({byRoot:Re(e.byRoot)})}),{name:`files-view-tabs-store`})),I=b(),Be=(e,t)=>{let n=(0,I.c)(4),r=t===void 0?200:t,[i,a]=A.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]),A.useEffect(o,s),i},Ve=()=>{let e=(0,I.c)(17),t=T(L),n=D(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=ae(r),a=T(R),o=T(z),s=E(He),c=E(B),l=h(Ue);if(t){let r;e[2]===i?r=e[3]:(r=he(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 L(e){return e.currentSessionId}function R(e){return e.worktreeMetadata}function z(e){return e.newSessionDraft}function He(e){return e.activeProjectId}function B(e){return e.projects}function Ue(e){return e.currentDirectory}var V=f(),H=`bg-transparent font-[inherit] text-[var(--primary-base)]`,U=(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,V.jsx)(`mark`,{className:H,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},W=A.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:a,onSessionSelect:o,onClose:s,style:c,onRowsChange:l},u)=>{let{t:d}=te(),f=Ve()??``,p=T(e=>e.currentSessionId),m=re(e=>e.activeSessions),h=oe({enabled:!!o}),g=E(e=>e.activeProjectId),v=E(e=>e.projects),y=A.useMemo(()=>v.find(e=>e.id===g)?.path??null,[g,v]),b=A.useMemo(()=>{let e=y||f;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[y,f]),x=ze(e=>b?e.byRoot[b]:void 0),ae=pe(e=>e.getVisibleAgents),ce=_(e=>e.searchFiles),ue=Be(e,180),D=i(),he=r(),[ge,_e]=A.useState([]),[ve,ye]=A.useState([]),[be,Te]=A.useState(!1),[k,Oe]=A.useState(0),ke=A.useRef(0),[Me,Ne]=A.useState(360),[Pe,Fe]=A.useState({}),[j,M]=A.useState({}),N=A.useRef([]),Re=A.useRef([]),P=A.useRef([]),F=A.useRef(null),I=A.useRef(null),L=A.useRef(null);L.current||=we();let R=ee(e=>e.isMobile),z=(e??``).trim(),He=ie({directory:f||null}),B=A.useMemo(()=>a?je(He.data??[],z):[],[z,a,He.data]),Ue=A.useMemo(()=>{if(!b||!x)return[];let e=[x.selectedPath,...x.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=[];for(let r of e){if(t.has(r))continue;t.add(r);let e=r.replace(/\\/g,`/`),i=e.split(`/`).filter(Boolean).pop()||e,a=e.startsWith(`${b}/`)?e.slice(b.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return fe(n,z,{limit:6})},[z,b,x]),H=A.useMemo(()=>z.length>0?ve:ve.slice(0,2),[ve,z.length]),W=A.useMemo(()=>o?le({sessions:se(m,h),currentSessionId:p,searchQuery:z}):[],[m,p,h,z,o]),G=Ue,K=ge;A.useEffect(()=>{let e=e=>{let t=e.target;!t||!F.current||F.current.contains(t)||s()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[s]),A.useEffect(()=>{if(!f){_e([]);return}let e=(ue??``).trim(),t=w(e);if(!t){_e([]);return}let n=!1;Te(!0);let r={includeHidden:D,respectGitignore:!he};return Promise.all([ce(f,t,80,{...r,type:`file`}),ce(f,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(Ue.map(e=>e.path));_e(de({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{n||_e([])}).finally(()=>{n||Te(!1)}),()=>{n=!0}},[f,ue,Ue,ce,D,he]),A.useEffect(()=>{let t=ae().filter(e=>e.mode&&e.mode!==`primary`).map(e=>({name:e.name,description:e.description,mode:e.mode}));ye(me(t,e??``))},[ae,e]),A.useEffect(()=>{Oe(0),Fe({}),M({})},[K,G.length,H.length,W.length,B.length]),A.useEffect(()=>{ke.current=k},[k]),A.useEffect(()=>{N.current[k]?.scrollIntoView({block:`nearest`})},[k]),A.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};Re.current.forEach((n,r)=>{if(!n)return;let i=P.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}}),Fe(e),M(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[K,G]),A.useEffect(()=>{let e=Re.current[k];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&Ne(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[k]);let We=S(e=>{t(e)}),Ge=S(e=>{n?.(e)}),Ke=S(e=>{o?.(e)}),q=S(e=>{a?.(e)}),J=B.length,qe=J,Je=qe+H.length,Y=Je+W.length,Ye=Y+G.length,Xe=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&L.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&L.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(L.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>L.current?.pointerCancel(),onClick:()=>{L.current?.click(t)},onMouseMove:()=>Oe(e)}),Ze=e=>{let t=J+H.length+W.length+G.length+K.length;if(t===0)return;let n=(e%t+t)%t;if(n<J){let e=B[n];e&&q(e);return}if(n<Je){let e=H[n-qe];e&&Ge(e.name);return}if(n<Y){let e=W[n-Je];e&&Ke(e);return}let r=n-Y,i=r<G.length?G[r]:K[r-G.length];i&&We(i)};A.useEffect(()=>{Ie(l,I,{rows:Ae({skills:B,agents:H,sessions:W,recentFiles:G,pathHits:K,untitledSession:d(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:d(`chat.fileMentionAutocomplete.sessionType`),skillBadge:d(`chat.commandAutocomplete.badge.skill`)}),highlightedIndex:k})},[l,k,d,H,K,G,W,B]);let X=A.useRef(l);X.current=l,A.useEffect(()=>()=>{Le(X.current,I)},[]),A.useImperativeHandle(u,()=>({acceptIndex:e=>{Ze(e)},handleKeyDown:e=>{if(e===`Escape`){s();return}let t=J+H.length+W.length+G.length+K.length;if(t!==0){if(e===`ArrowDown`){Oe(e=>(e+1)%t);return}if(e===`ArrowUp`){Oe(e=>(e-1+t)%t);return}(e===`Enter`||e===`Tab`)&&Ze(ke.current)}}}),[J,K,G,H,W,B,s,We,Ge,Ke,q]);let Z=e=>(0,V.jsx)(O,{name:De(e),className:`h-3.5 w-3.5 text-current`});return(0,V.jsxs)(Se,{ref:F,isMobile:R,className:`max-w-[640px] max-h-64`,style:c,children:[(0,V.jsx)(xe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,V.jsxs)(`div`,{className:`pb-2`,children:[B.length>0&&(0,V.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.skills`)}),B.map((e,t)=>{let n=k===t;return(0,V.jsx)(`div`,{ref:e=>{N.current[t]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,R&&`min-h-11`,Ce(R,n),!R&&n&&`text-interactive-selection-foreground`),...Xe(t,()=>q(e)),children:(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(O,{name:Ee(),className:`h-3.5 w-3.5 translate-y-px flex-shrink-0 text-current`}),(0,V.jsxs)(`span`,{className:`min-w-0 truncate`,children:[`@`,U(e.name,z)]}),R?null:(0,V.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:e.scope})]}),e.description?(0,V.jsx)(`div`,{className:C(`pl-5.5 truncate text-muted-foreground`,R?`typography-micro`:`typography-meta`),children:U(e.description,z)}):null]})},`skill-${e.name}-${e.scope}`)}),H.length>0&&(0,V.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.agents`)}),H.map((e,t)=>{let n=qe+t,r=k===n;return(0,V.jsx)(`div`,{ref:e=>{N.current[n]=e},className:C(`flex items-start gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,R&&`min-h-11`,Ce(R,r),!R&&r&&`text-interactive-selection-foreground`),...Xe(n,()=>Ge(e.name)),children:(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`truncate`,children:[`@`,U(e.name,z)]}),e.description&&!R?(0,V.jsx)(`div`,{className:`typography-meta text-muted-foreground truncate`,children:U(e.description,z)}):null]})},`agent-${e.name}`)}),H.length===2&&z.length===0&&ve.length>2&&(0,V.jsx)(`div`,{className:`px-3 py-1 typography-meta text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.searchMoreAgents`)}),W.length>0&&(0,V.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.sessions`)}),W.map((e,t)=>{let n=Je+t,r=k===n;return(0,V.jsxs)(`div`,{ref:e=>{N.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,R&&`min-h-11`,Ce(R,r),!R&&r&&`text-interactive-selection-foreground`),...Xe(n,()=>Ke(e)),children:[(0,V.jsx)(O,{name:`chat-thread`,className:`h-4 w-4 flex-shrink-0 text-[var(--primary-base)]`}),(0,V.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title||d(`chat.fileMentionAutocomplete.untitledSession`),children:U(e.title||d(`chat.fileMentionAutocomplete.untitledSession`),z)}),R?null:(0,V.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.sessionType`)})]},`session-${e.id}`)}),G.length>0&&(0,V.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.recentFiles`)}),G.map((e,t)=>{let n=Y+t,r=e.relativePath||e.name,i=ne(r,{maxLength:60}),a=k===n,o=Pe[n]??!1,s=j[n]??2.6;return(0,V.jsxs)(`div`,{ref:e=>{N.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,R&&`min-h-11`,Ce(R,a),!R&&a&&`text-interactive-selection-foreground`),...Xe(n,()=>We(e)),children:[Z(e),(0,V.jsxs)(`span`,{ref:e=>{Re.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${Me}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,V.jsx)(`span`,{ref:e=>{P.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,V.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:U(r,z)}):(0,V.jsx)(`span`,{className:`block truncate`,children:U(i,z)})]})]},`recent-${e.path}`)}),K.length>0&&(0,V.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.files`)}),K.map((e,t)=>{let n=Ye+t,r=e.relativePath||e.name,i=ne(r,{maxLength:60}),a=k===n,o=Pe[n]??!1,s=j[n]??2.6;return(0,V.jsxs)(`div`,{ref:e=>{N.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,R&&`min-h-11`,Ce(R,a),!R&&a&&`text-interactive-selection-foreground`),...Xe(n,()=>We(e)),children:[Z(e),(0,V.jsxs)(`span`,{ref:e=>{Re.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${Me}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,V.jsx)(`span`,{ref:e=>{P.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,V.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:U(r,z)}):(0,V.jsx)(`span`,{className:`block truncate`,children:U(i,z)})]})]},e.path)}),be&&K.length===0?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,V.jsx)(O,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!be&&K.length===0&&G.length===0&&H.length===0&&W.length===0&&B.length===0&&(0,V.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.empty`)})]})}),!R&&(0,V.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:d(`chat.autocomplete.keyboardHint`)})]})}),G=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`goal`,`btw`]),K=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&G.has(n))},We=(e,t)=>!e||t({name:e}),Ge=` `,Ke=(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]===Ge&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},q=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,J=C(q,`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)]`),qe=C(q,`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)]`),Je=C(q,`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)]`),Y=C(q,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),Ye=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),Xe=(e,t)=>{let n=!!e.sessionID;return{hasSession:n,canStartSessionCommand:n||e.hasNewDraft,canUseReviewHandoffFlow:n&&!t&&!c()}},Ze=A.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:r,style:i,commandPolicy:a,commandContext:o,onRowsChange:s},l)=>{let{t:u}=te(),d=ee(e=>e.isMobile),f=T(e=>e.currentSessionId),p=T(e=>!!e.newSessionDraft?.open),m=T(A.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=ce(f??``,m??void 0),g=A.useMemo(()=>o??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[o,f,h.length,p]),{hasSession:_,canStartSessionCommand:v,canUseReviewHandoffFlow:y}=A.useMemo(()=>Xe(g,d),[g,d]),b=g.hasMessages,[x,S]=A.useState([]),[ne,re]=A.useState(!1),ie=ue({directory:r}),ae=A.useMemo(()=>ie.data??[],[ie.data]),oe=ie.isFetching,[w,se]=A.useState(0),le=A.useRef(0),de=A.useRef(!1),fe=A.useRef([]),pe=A.useRef(null),me=A.useRef(!1),E=A.useRef(null),D=A.useRef(!1),he=A.useRef(null);A.useEffect(()=>{let e=e=>{let t=e.target;!t||!pe.current||pe.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),A.useEffect(()=>{(async()=>{re(oe);try{let t=ae.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},...c()?[{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=Me(n.filter(e=>(r||e.name!==`init`)&&(a?.(e)??!0)),e);S(e=>Ye(e,i)?e:i)}catch{let t=!b,n=Me([{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},...c()?[{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=>Ye(e,n)?e:n)}finally{re(!1)}})()},[e,b,_,v,y,ae,oe,u,a]),A.useEffect(()=>{se(0)},[x]),A.useEffect(()=>{le.current=w},[w]),A.useEffect(()=>{fe.current[w]?.scrollIntoView({block:`nearest`})},[w]),A.useEffect(()=>{Ie(s,he,{rows:ke(x,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:w})},[x,s,w,u]);let ge=A.useRef(s);ge.current=s,A.useEffect(()=>()=>{Le(ge.current,he)},[]),A.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=x[e];r&&t(r,K(r,n))},handleKeyDown:e=>{let r=x.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){de.current=!0,se(e=>(e+1)%r);return}if(e===`ArrowUp`){de.current=!0,se(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(le.current%r+r)%r,i=x[n];i&&t(i,K(i,e===`Enter`))}}}}),[x,n,t]);let _e=e=>{let t=Te(e);switch(e.name){case`new`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,V.jsxs)(Se,{ref:pe,isMobile:d,className:`max-w-[450px] max-h-64`,style:i,children:[(0,V.jsx)(xe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:ne?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,V.jsx)(O,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,V.jsxs)(`div`,{children:[x.map((n,r)=>{let i=n.isBuiltIn,a=n.isOpenChamber;return(0,V.jsxs)(`div`,{ref:e=>{fe.current[r]=e},className:C(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,Ce(d,r===w),!d&&r===w&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(E.current={x:e.clientX,y:e.clientY},D.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!E.current)return;let t=e.clientX-E.current.x,n=e.clientY-E.current.y;Math.hypot(t,n)>6&&(D.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=D.current;E.current=null,D.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),me.current=!0,t(n,K(n,d)))},onPointerCancel:()=>{E.current=null,D.current=!1},onClick:()=>{if(me.current){me.current=!1;return}t(n,K(n,d))},onMouseMove:()=>{de.current=!1,se(r)},children:[(0,V.jsx)(`div`,{className:C(!d&&`mt-0.5`),children:_e(n)}),(0,V.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,U(n.name,e)]}),n.isSkill?(0,V.jsx)(`span`,{className:J,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,V.jsx)(`span`,{className:J,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,V.jsx)(`span`,{className:Y,children:`OpenChamber`}):i?(0,V.jsx)(`span`,{className:Y,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,V.jsx)(`span`,{className:n.scope===`project`?Je:qe,children:n.scope}):null,n.agent&&(0,V.jsx)(`span`,{className:Y,children:n.agent})]}),n.description&&!d&&(0,V.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:U(n.description,e)})]})]},n.id)}),x.length===0&&(0,V.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,V.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});Ze.displayName=`CommandAutocomplete`;var X=2,Z=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Qe=e=>{let t=e?.trim().replace(/\\/g,`/`);return t?t.length>1?t.replace(/\/+$/,``):t:null},$e=e=>Z(e)&&Array.isArray(e.all)&&e.all.every(e=>typeof e==`string`)&&typeof e.current==`string`&&Z(e.branches),et=(e,t)=>JSON.stringify([e,t]),tt=e=>`version`in e&&e.version===X&&Z(e.entries),nt=e=>{if(!e)return null;try{let t=JSON.parse(e);return Z(t)?t.version===X&&Z(t.entries)?{version:X,entries:t.entries}:t:null}catch{return null}},rt=(e,t)=>{try{e.setItem(`oc.gitBranchCache`,JSON.stringify(t))}catch{}},it=(e,t,n)=>{let r=Qe(e);if(!r||!t)return null;let i;try{i=n.getItem(`oc.gitBranchCache`)}catch{return null}let a=nt(i);if(!a)return null;if(tt(a))return $e(a.entries[et(t,r)])?a.entries[et(t,r)]:null;let o={};for(let[e,n]of Object.entries(a)){let r=Qe(e);r&&$e(n)&&(o[et(t,r)]=n)}return rt(n,{version:X,entries:o}),o[et(t,r)]??null},at=(e,t,n,r)=>{let i=Qe(e);if(!i||!t||!$e(n))return;let a=null;try{a=r.getItem(`oc.gitBranchCache`)}catch{return}let o=nt(a);rt(r,{version:X,entries:{...o&&tt(o)?o.entries:{},[et(t,i)]:n}})},ot=3e4,st=Qe,ct=(e,t=n())=>s.git.branches(st(e),t),lt=(e,t=n())=>s.git.remotes(st(e),t),ut=async(e,t,n)=>{n.throwIfAborted();let r=a()?.git,i=t?.getGitBranches?await t.getGitBranches(e,{signal:n}):r?await r.getGitBranches(e,{signal:n}):await g(e,{signal:n});return n.throwIfAborted(),i},dt=async(e,t,n)=>{n.throwIfAborted();let r=a()?.git,i=t?.getRemotes?await t.getRemotes(e,{signal:n}):r?await r.getRemotes(e,{signal:n}):await m(e,{signal:n});return n.throwIfAborted(),i},ft=(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 ut(a,o,e);return at(a,r,t,i),t},staleTime:ot,gcTime:1/0,initialData:()=>it(a,r,i)??void 0,initialDataUpdatedAt:0}},pt=(e,t,r=n())=>{let i=st(e),a=t;return{queryKey:lt(i,r),queryFn:({signal:e})=>{if(!i)throw Error(`Git remotes require a directory`);return dt(i,a,e)},staleTime:ot,gcTime:1/0}},mt=(e,r,i)=>{let a=(0,I.c)(9),o=i===void 0||i,s=A.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=st(e),u=x,l=ft(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)},ht=(e,r,i)=>{let a=(0,I.c)(9),o=i===void 0||i,s=A.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=st(e),u=x,l=pt(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)},gt=(e,t,r=o,i=n())=>r.fetchQuery(ft(e,t,i)),_t=(e,t,r=o,i=n())=>r.fetchQuery({...ft(e,t,i),staleTime:0}),vt=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,yt=1e4,bt=6e4,xt=5e3,St=3e4,Ct=6e4,wt=25,Tt=40,Et=2,Dt=15e3,Ot=500,kt=30,At=20971520,jt=new Map,Mt=new Map,Nt=new Map,Pt=new Map,Ft=new Map,It=(e,t)=>`${t}:${e}`,Lt=e=>Mt.get(e)??0,Rt=e=>{let t=Lt(e)+1;return Mt.set(e,t),t},zt=e=>{let t=(Nt.get(e)??0)+1;return Nt.set(e,t),t},Bt=e=>{let t=jt.get(e);if(t)return t;let n=new Set;return jt.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}),Vt=(e,t=kt,n=At)=>{let r=0;for(let t of e.values())r+=(t.original?.length??0)+(t.modified?.length??0);if(e.size<=t&&r<=n)return e;let i=Array.from(e.entries()).sort((e,t)=>e[1].fetchedAt-t[1].fetchedAt),a=new Map,o=0;for(let e=i.length-1;e>=0;e--){let[r,s]=i[e],c=(s.original?.length??0)+(s.modified?.length??0);if(a.size>=t)break;o+c>n&&a.size>0||(a.set(r,s),o+=c)}return a},Ht=(e,t)=>{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},Ut=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,Wt=(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&&Ut(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&&Ht(e.diffStats,t.diffStats))},Gt=(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},Kt=(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},qt=e=>!e||e.trim().length===0,Jt=e=>(e||``).trim()===`U`,Yt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Jt(t)||Jt(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},Xt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Jt(t)||Jt(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},Zt=e=>qt(e.index)&&qt(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&&Rt(r),n&&Rt(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=It(n,a),s=Pt.get(o)??(a===`light`?Pt.get(It(n,`full`)):void 0);if(s)return s;let c=(async()=>{let{silent:a=!1}=i,{directories:o}=t(),s=o.get(n);if(s||=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)>bt,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(Wt(s.status,u)){c=!0;let r=new Map(t().directories),i=r.get(n)??Q(),s=Gt(i.status,u),l=Kt(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&&Rt(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})();Pt.set(o,c);try{return await c}finally{Pt.get(o)===c&&Pt.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`?Yt(e):Xt(e);t!==e&&(l=!0),Zt(t)?l=!0:u.push(t)}if(!l)return c;let d=new Map(o);return d.set(n,{...s,status:{...c,files:u,isClean:u.length===0},indexRevision:s.indexRevision+1,lastStatusChange:Date.now()}),e({directories:d}),c},restoreStatus:(n,r)=>{let{directories:i}=t(),a=i.get(n);if(!a)return;let o=new Map(i);o.set(n,{...a,status:r,indexRevision:a.indexRevision+1,lastStatusChange:Date.now()}),e({directories:o})},bumpIndexRevision:n=>{let{directories:r}=t(),i=r.get(n);if(!i)return;let a=new Map(r);a.set(n,{...i,indexRevision:i.indexRevision+1}),e({directories:a})},fetchBranches:async(r,i,a={})=>{let o=n(),s=zt(r);{let n=new Map(t().directories),i=n.get(r)??Q();n.set(r,{...i,isLoadingBranches:!0}),e({directories:n})}try{let c=a.force?await _t(r,i,void 0,o):await gt(r,i,void 0,o);if(s!==Nt.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(vt(i)||console.error(`Failed to fetch git branches:`,i),s!==Nt.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>yt||!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=Vt(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{Rt(n);let r=new Map(t().directories),i=r.get(n);i&&(r.set(n,{...i,diffCache:new Map}),e({directories:r}))},fetchAllDiffs:async(e,n)=>{let r=t().directories.get(e);if(!r?.status?.files||r.status.files.length===0)return;let i=r.status.files.map(e=>e.path).slice(0,wt);await t().prefetchDiffs(e,n,i,{maxFiles:wt})},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=Tt}=a,c=new Set(o.status.files.map(e=>e.path)),l=o.status.diffStats,u=Bt(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>Ot||d.push(e)}let p=d.slice(0,Math.max(1,s));if(p.length===0)return;let m=Lt(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 ${Dt}ms`)),Dt)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},ee=async()=>{for(;;){if(m!==Lt(n))return;let e=_();if(!e)return;try{g.push(await v(e))}catch{}finally{u.delete(e)}}},y=Math.min(Et,p.length);if(await Promise.allSettled(Array.from({length:y},()=>ee())),p.forEach(e=>u.delete(e)),m!==Lt(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=Vt(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<xt||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=Ft.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)>=xt)&&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>=St)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=yt)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=Ct)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return Ft.set(e,i),i.finally(()=>{Ft.get(e)===i&&Ft.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),Qt=e=>{let t=(0,I.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)},$t=e=>{let r=(0,I.c)(3),i=A.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)},en=e=>{let t=(0,I.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)},tn=e=>{let t=(0,I.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)},nn=e=>{let t=(0,I.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)},rn=e=>{let t=(0,I.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=A.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)},an=e=>{let t=(0,I.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)},on=e=>{let t=(0,I.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,I.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)}},ln=e=>String(e||``).trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/^remotes\//,``),un=e=>e.branchName?ln(e.branchName):e.mode===`existing`?ln(e.existingBranch||e.preferredName||``):ln(e.preferredName||``),dn=async e=>{let t=await ye(e);try{let n=cn((await _e(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=cn((await ve(e)).tracking);if(t?.remote)return t.remote}catch{}return null},fn=async(e,t)=>{let n=await dn(e),r=ln(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},pn=async(e,t,n)=>{let r=un(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await fn(e,r):i&&ln(r)?{setUpstream:!0,upstreamRemote:i,upstreamBranch:ln(r)}:null;return a?{...t,setUpstream:t.setUpstream??a.setUpstream,upstreamRemote:t.upstreamRemote||a.upstreamRemote,upstreamBranch:t.upstreamBranch||a.upstreamBranch}:t},mn=async(e,t,n)=>{let r=await pn(e.path,t,n);return be(e,r)},hn=`oc:lastWorktreeSourceBranch`,gn=({mode:e,sourceBranch:t,linkedPr:n,selectedBranch:r})=>e===`existing-branch`?r||null:n?null:t||null,_n=({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},vn=(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?` `:``}`},yn=(e,t,n)=>{let r=vn(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},bn=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=yn(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}},xn=(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]},Sn=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{ze as A,ht as C,W as D,We as E,Ve as O,mt as S,Ke as T,rn as _,hn as a,tn as b,mn as c,nn as d,$t as f,en as g,an as h,yn as i,Fe as j,Be as k,dn as l,on as m,xn as n,_n as o,sn as p,bn as r,gn as s,Sn as t,pn as u,Qt as v,Ze as w,_t as x,$ as y};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{c as t,i as n}from"./runtime-switch-BJM2k_uH.js";import{A as r,M as i,On as a,d as o,f as s,on as c}from"./persistence-CwHY3fDg.js";import{a as l,i as u,r as d}from"./vendor-zustand-DzRqcymP.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-CAw45mRH.js";import{b as v,n as ee,x as y}from"./useUIStore-DNkuudYO.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-CcOoDLE1.js";import{Dr as re,Ra as ie,S as ae,Vt as oe,_t as w,br as se,cn as ce,d as T,dt as le,eo as ue,ft as de,mt as fe,pa as pe,pt as me,to as E,vn as D,y as he,zn as ge}from"./useMobileNavigationStore-CEhyCPzG.js";import{n as O}from"./Icon-BE2hkaYc.js";import{g as _e,v as ve}from"./gitApi-BET0Byz4.js";import{f as ye,o as be}from"./projectMeta-Dt7jGs7G.js";import{n as xe}from"./textarea-5RcNvWr-.js";import{n as Se,r as Ce,t as we}from"./fileMentionTouchSelection-BiHRyKLM.js";var Te=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`}},Ee=()=>`book-open`,De=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`}},k=()=>`ai-agent`,Oe=()=>`chat-thread`,ke=(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:Te(e)}}),Ae=({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:Ee()});for(let e of t)c.push({id:`agent:${e.name}`,title:`@${e.name}`,subtitle:e.description,iconName:k()});for(let e of n)c.push({id:`session:${e.id}`,title:e.title||a,badge:o,iconName:Oe()});for(let e of r)c.push({id:`recent:${e.path}`,title:e.relativePath||e.name,iconName:De(e)});for(let e of i)c.push({id:`file:${e.path}`,title:e.relativePath||e.name,iconName:De(e)});return c},je=(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=ge([...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)},Me=(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=ge([...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)},Ne=(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}),Pe=(e,t)=>e.highlightedIndex===t.highlightedIndex&&Ne(e.rows,t.rows),Fe=(e,t)=>Ne(e,t)?e:t.slice(),Ie=(e,t,n)=>{e&&(t.current&&Pe(t.current,n)||(t.current=n,e(n)))},Le=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},A=e(p(),1),j=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},M=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,N=(e,t)=>{let n=j(t),r=j(e);if(!n||!r)return!1;let i=M(n),a=M(r);return a===i||a.startsWith(`${i}/`)},Re=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=j(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=>j(e)).filter(e=>N(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>j(e)).filter(e=>N(e,t)))):[],s=typeof i.selectedPath==`string`?j(i.selectedPath):null,c=s&&N(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},P=(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},F=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},ze=l()(d(u((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=j((t||``).trim()),a=j((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!N(a,i)||e(e=>{let t=e.byRoot[i],n=F(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:P({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=j((t||``).trim()),i=j((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=M(i),a=e=>M(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:P({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=j((t||``).trim()),i=j((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=M(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=M(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:P({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=j((t||``).trim()),i=j((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=M(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=M(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:P({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=j((t||``).trim()),a=n?j(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!N(a,i)||e(e=>{let t=e.byRoot[i],n=F(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:P({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=j((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=j((t||``).trim()),i=j((n||``).trim());!r||!i||!N(i,r)||e(e=>{let t=e.byRoot[r],n=F(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:P({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=j((t||``).trim()),i=j((n||``).trim());!r||!i||!N(i,r)||e(e=>{let t=e.byRoot[r],n=F(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:P({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=j((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>j((e||``).trim())).filter(e=>e&&N(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=F(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:P({...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:Re(t)}},partialize:e=>({byRoot:Re(e.byRoot)})}),{name:`files-view-tabs-store`})),I=b(),Be=(e,t)=>{let n=(0,I.c)(4),r=t===void 0?200:t,[i,a]=A.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]),A.useEffect(o,s),i},Ve=()=>{let e=(0,I.c)(17),t=T(L),n=D(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=ae(r),a=T(R),o=T(z),s=E(He),c=E(B),l=h(Ue);if(t){let r;e[2]===i?r=e[3]:(r=he(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 L(e){return e.currentSessionId}function R(e){return e.worktreeMetadata}function z(e){return e.newSessionDraft}function He(e){return e.activeProjectId}function B(e){return e.projects}function Ue(e){return e.currentDirectory}var V=f(),H=`bg-transparent font-[inherit] text-[var(--primary-base)]`,U=(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,V.jsx)(`mark`,{className:H,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},W=A.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:a,onSessionSelect:o,onClose:s,style:c,onRowsChange:l},u)=>{let{t:d}=te(),f=Ve()??``,p=T(e=>e.currentSessionId),m=re(e=>e.activeSessions),h=oe({enabled:!!o}),g=E(e=>e.activeProjectId),v=E(e=>e.projects),y=A.useMemo(()=>v.find(e=>e.id===g)?.path??null,[g,v]),b=A.useMemo(()=>{let e=y||f;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[y,f]),x=ze(e=>b?e.byRoot[b]:void 0),ae=pe(e=>e.getVisibleAgents),ce=_(e=>e.searchFiles),ue=Be(e,180),D=i(),he=r(),[ge,_e]=A.useState([]),[ve,ye]=A.useState([]),[be,Te]=A.useState(!1),[k,Oe]=A.useState(0),ke=A.useRef(0),[Me,Ne]=A.useState(360),[Pe,Fe]=A.useState({}),[j,M]=A.useState({}),N=A.useRef([]),Re=A.useRef([]),P=A.useRef([]),F=A.useRef(null),I=A.useRef(null),L=A.useRef(null);L.current||=we();let R=ee(e=>e.isMobile),z=(e??``).trim(),He=ie({directory:f||null}),B=A.useMemo(()=>a?je(He.data??[],z):[],[z,a,He.data]),Ue=A.useMemo(()=>{if(!b||!x)return[];let e=[x.selectedPath,...x.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=[];for(let r of e){if(t.has(r))continue;t.add(r);let e=r.replace(/\\/g,`/`),i=e.split(`/`).filter(Boolean).pop()||e,a=e.startsWith(`${b}/`)?e.slice(b.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return fe(n,z,{limit:6})},[z,b,x]),H=A.useMemo(()=>z.length>0?ve:ve.slice(0,2),[ve,z.length]),W=A.useMemo(()=>o?le({sessions:se(m,h),currentSessionId:p,searchQuery:z}):[],[m,p,h,z,o]),G=Ue,K=ge;A.useEffect(()=>{let e=e=>{let t=e.target;!t||!F.current||F.current.contains(t)||s()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[s]),A.useEffect(()=>{if(!f){_e([]);return}let e=(ue??``).trim(),t=w(e);if(!t){_e([]);return}let n=!1;Te(!0);let r={includeHidden:D,respectGitignore:!he};return Promise.all([ce(f,t,80,{...r,type:`file`}),ce(f,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(Ue.map(e=>e.path));_e(de({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{n||_e([])}).finally(()=>{n||Te(!1)}),()=>{n=!0}},[f,ue,Ue,ce,D,he]),A.useEffect(()=>{let t=ae().filter(e=>e.mode&&e.mode!==`primary`).map(e=>({name:e.name,description:e.description,mode:e.mode}));ye(me(t,e??``))},[ae,e]),A.useEffect(()=>{Oe(0),Fe({}),M({})},[K,G.length,H.length,W.length,B.length]),A.useEffect(()=>{ke.current=k},[k]),A.useEffect(()=>{N.current[k]?.scrollIntoView({block:`nearest`})},[k]),A.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};Re.current.forEach((n,r)=>{if(!n)return;let i=P.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}}),Fe(e),M(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[K,G]),A.useEffect(()=>{let e=Re.current[k];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&Ne(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[k]);let We=S(e=>{t(e)}),Ge=S(e=>{n?.(e)}),Ke=S(e=>{o?.(e)}),q=S(e=>{a?.(e)}),J=B.length,qe=J,Je=qe+H.length,Y=Je+W.length,Ye=Y+G.length,Xe=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&L.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&L.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(L.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>L.current?.pointerCancel(),onClick:()=>{L.current?.click(t)},onMouseMove:()=>Oe(e)}),Ze=e=>{let t=J+H.length+W.length+G.length+K.length;if(t===0)return;let n=(e%t+t)%t;if(n<J){let e=B[n];e&&q(e);return}if(n<Je){let e=H[n-qe];e&&Ge(e.name);return}if(n<Y){let e=W[n-Je];e&&Ke(e);return}let r=n-Y,i=r<G.length?G[r]:K[r-G.length];i&&We(i)};A.useEffect(()=>{Ie(l,I,{rows:Ae({skills:B,agents:H,sessions:W,recentFiles:G,pathHits:K,untitledSession:d(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:d(`chat.fileMentionAutocomplete.sessionType`),skillBadge:d(`chat.commandAutocomplete.badge.skill`)}),highlightedIndex:k})},[l,k,d,H,K,G,W,B]);let X=A.useRef(l);X.current=l,A.useEffect(()=>()=>{Le(X.current,I)},[]),A.useImperativeHandle(u,()=>({acceptIndex:e=>{Ze(e)},handleKeyDown:e=>{if(e===`Escape`){s();return}let t=J+H.length+W.length+G.length+K.length;if(t!==0){if(e===`ArrowDown`){Oe(e=>(e+1)%t);return}if(e===`ArrowUp`){Oe(e=>(e-1+t)%t);return}(e===`Enter`||e===`Tab`)&&Ze(ke.current)}}}),[J,K,G,H,W,B,s,We,Ge,Ke,q]);let Z=e=>(0,V.jsx)(O,{name:De(e),className:`h-3.5 w-3.5 text-current`});return(0,V.jsxs)(Se,{ref:F,isMobile:R,className:`max-w-[640px] max-h-64`,style:c,children:[(0,V.jsx)(xe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,V.jsxs)(`div`,{className:`pb-2`,children:[B.length>0&&(0,V.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.skills`)}),B.map((e,t)=>{let n=k===t;return(0,V.jsx)(`div`,{ref:e=>{N.current[t]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,R&&`min-h-11`,Ce(R,n),!R&&n&&`text-interactive-selection-foreground`),...Xe(t,()=>q(e)),children:(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(O,{name:Ee(),className:`h-3.5 w-3.5 translate-y-px flex-shrink-0 text-current`}),(0,V.jsxs)(`span`,{className:`min-w-0 truncate`,children:[`@`,U(e.name,z)]}),R?null:(0,V.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:e.scope})]}),e.description?(0,V.jsx)(`div`,{className:C(`pl-5.5 truncate text-muted-foreground`,R?`typography-micro`:`typography-meta`),children:U(e.description,z)}):null]})},`skill-${e.name}-${e.scope}`)}),H.length>0&&(0,V.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.agents`)}),H.map((e,t)=>{let n=qe+t,r=k===n;return(0,V.jsx)(`div`,{ref:e=>{N.current[n]=e},className:C(`flex items-start gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,R&&`min-h-11`,Ce(R,r),!R&&r&&`text-interactive-selection-foreground`),...Xe(n,()=>Ge(e.name)),children:(0,V.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,V.jsxs)(`div`,{className:`truncate`,children:[`@`,U(e.name,z)]}),e.description&&!R?(0,V.jsx)(`div`,{className:`typography-meta text-muted-foreground truncate`,children:U(e.description,z)}):null]})},`agent-${e.name}`)}),H.length===2&&z.length===0&&ve.length>2&&(0,V.jsx)(`div`,{className:`px-3 py-1 typography-meta text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.searchMoreAgents`)}),W.length>0&&(0,V.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.sessions`)}),W.map((e,t)=>{let n=Je+t,r=k===n;return(0,V.jsxs)(`div`,{ref:e=>{N.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,R&&`min-h-11`,Ce(R,r),!R&&r&&`text-interactive-selection-foreground`),...Xe(n,()=>Ke(e)),children:[(0,V.jsx)(O,{name:`chat-thread`,className:`h-4 w-4 flex-shrink-0 text-[var(--primary-base)]`}),(0,V.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title||d(`chat.fileMentionAutocomplete.untitledSession`),children:U(e.title||d(`chat.fileMentionAutocomplete.untitledSession`),z)}),R?null:(0,V.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.sessionType`)})]},`session-${e.id}`)}),G.length>0&&(0,V.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.recentFiles`)}),G.map((e,t)=>{let n=Y+t,r=e.relativePath||e.name,i=ne(r,{maxLength:60}),a=k===n,o=Pe[n]??!1,s=j[n]??2.6;return(0,V.jsxs)(`div`,{ref:e=>{N.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,R&&`min-h-11`,Ce(R,a),!R&&a&&`text-interactive-selection-foreground`),...Xe(n,()=>We(e)),children:[Z(e),(0,V.jsxs)(`span`,{ref:e=>{Re.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${Me}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,V.jsx)(`span`,{ref:e=>{P.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,V.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:U(r,z)}):(0,V.jsx)(`span`,{className:`block truncate`,children:U(i,z)})]})]},`recent-${e.path}`)}),K.length>0&&(0,V.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.groups.files`)}),K.map((e,t)=>{let n=Ye+t,r=e.relativePath||e.name,i=ne(r,{maxLength:60}),a=k===n,o=Pe[n]??!1,s=j[n]??2.6;return(0,V.jsxs)(`div`,{ref:e=>{N.current[n]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,R&&`min-h-11`,Ce(R,a),!R&&a&&`text-interactive-selection-foreground`),...Xe(n,()=>We(e)),children:[Z(e),(0,V.jsxs)(`span`,{ref:e=>{Re.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${Me}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,V.jsx)(`span`,{ref:e=>{P.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,V.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:U(r,z)}):(0,V.jsx)(`span`,{className:`block truncate`,children:U(i,z)})]})]},e.path)}),be&&K.length===0?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,V.jsx)(O,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!be&&K.length===0&&G.length===0&&H.length===0&&W.length===0&&B.length===0&&(0,V.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.empty`)})]})}),!R&&(0,V.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:d(`chat.autocomplete.keyboardHint`)})]})}),G=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`goal`,`btw`]),K=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&G.has(n))},We=(e,t)=>!e||t({name:e}),Ge=` `,Ke=(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]===Ge&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},q=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,J=C(q,`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)]`),qe=C(q,`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)]`),Je=C(q,`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)]`),Y=C(q,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),Ye=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),Xe=(e,t)=>{let n=!!e.sessionID;return{hasSession:n,canStartSessionCommand:n||e.hasNewDraft,canUseReviewHandoffFlow:n&&!t&&!c()}},Ze=A.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:r,style:i,commandPolicy:a,commandContext:o,onRowsChange:s},l)=>{let{t:u}=te(),d=ee(e=>e.isMobile),f=T(e=>e.currentSessionId),p=T(e=>!!e.newSessionDraft?.open),m=T(A.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=ce(f??``,m??void 0),g=A.useMemo(()=>o??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[o,f,h.length,p]),{hasSession:_,canStartSessionCommand:v,canUseReviewHandoffFlow:y}=A.useMemo(()=>Xe(g,d),[g,d]),b=g.hasMessages,[x,S]=A.useState([]),[ne,re]=A.useState(!1),ie=ue({directory:r}),ae=A.useMemo(()=>ie.data??[],[ie.data]),oe=ie.isFetching,[w,se]=A.useState(0),le=A.useRef(0),de=A.useRef(!1),fe=A.useRef([]),pe=A.useRef(null),me=A.useRef(!1),E=A.useRef(null),D=A.useRef(!1),he=A.useRef(null);A.useEffect(()=>{let e=e=>{let t=e.target;!t||!pe.current||pe.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),A.useEffect(()=>{(async()=>{re(oe);try{let t=ae.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},...c()?[{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=Me(n.filter(e=>(r||e.name!==`init`)&&(a?.(e)??!0)),e);S(e=>Ye(e,i)?e:i)}catch{let t=!b,n=Me([{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},...c()?[{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=>Ye(e,n)?e:n)}finally{re(!1)}})()},[e,b,_,v,y,ae,oe,u,a]),A.useEffect(()=>{se(0)},[x]),A.useEffect(()=>{le.current=w},[w]),A.useEffect(()=>{fe.current[w]?.scrollIntoView({block:`nearest`})},[w]),A.useEffect(()=>{Ie(s,he,{rows:ke(x,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:w})},[x,s,w,u]);let ge=A.useRef(s);ge.current=s,A.useEffect(()=>()=>{Le(ge.current,he)},[]),A.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=x[e];r&&t(r,K(r,n))},handleKeyDown:e=>{let r=x.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){de.current=!0,se(e=>(e+1)%r);return}if(e===`ArrowUp`){de.current=!0,se(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(le.current%r+r)%r,i=x[n];i&&t(i,K(i,e===`Enter`))}}}}),[x,n,t]);let _e=e=>{let t=Te(e);switch(e.name){case`new`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,V.jsx)(O,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,V.jsxs)(Se,{ref:pe,isMobile:d,className:`max-w-[450px] max-h-64`,style:i,children:[(0,V.jsx)(xe,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:ne?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,V.jsx)(O,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,V.jsxs)(`div`,{children:[x.map((n,r)=>{let i=n.isBuiltIn,a=n.isOpenChamber;return(0,V.jsxs)(`div`,{ref:e=>{fe.current[r]=e},className:C(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,Ce(d,r===w),!d&&r===w&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(E.current={x:e.clientX,y:e.clientY},D.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!E.current)return;let t=e.clientX-E.current.x,n=e.clientY-E.current.y;Math.hypot(t,n)>6&&(D.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=D.current;E.current=null,D.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),me.current=!0,t(n,K(n,d)))},onPointerCancel:()=>{E.current=null,D.current=!1},onClick:()=>{if(me.current){me.current=!1;return}t(n,K(n,d))},onMouseMove:()=>{de.current=!1,se(r)},children:[(0,V.jsx)(`div`,{className:C(!d&&`mt-0.5`),children:_e(n)}),(0,V.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,U(n.name,e)]}),n.isSkill?(0,V.jsx)(`span`,{className:J,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,V.jsx)(`span`,{className:J,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,V.jsx)(`span`,{className:Y,children:`OpenChamber`}):i?(0,V.jsx)(`span`,{className:Y,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,V.jsx)(`span`,{className:n.scope===`project`?Je:qe,children:n.scope}):null,n.agent&&(0,V.jsx)(`span`,{className:Y,children:n.agent})]}),n.description&&!d&&(0,V.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:U(n.description,e)})]})]},n.id)}),x.length===0&&(0,V.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,V.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});Ze.displayName=`CommandAutocomplete`;var X=2,Z=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Qe=e=>{let t=e?.trim().replace(/\\/g,`/`);return t?t.length>1?t.replace(/\/+$/,``):t:null},$e=e=>Z(e)&&Array.isArray(e.all)&&e.all.every(e=>typeof e==`string`)&&typeof e.current==`string`&&Z(e.branches),et=(e,t)=>JSON.stringify([e,t]),tt=e=>`version`in e&&e.version===X&&Z(e.entries),nt=e=>{if(!e)return null;try{let t=JSON.parse(e);return Z(t)?t.version===X&&Z(t.entries)?{version:X,entries:t.entries}:t:null}catch{return null}},rt=(e,t)=>{try{e.setItem(`oc.gitBranchCache`,JSON.stringify(t))}catch{}},it=(e,t,n)=>{let r=Qe(e);if(!r||!t)return null;let i;try{i=n.getItem(`oc.gitBranchCache`)}catch{return null}let a=nt(i);if(!a)return null;if(tt(a))return $e(a.entries[et(t,r)])?a.entries[et(t,r)]:null;let o={};for(let[e,n]of Object.entries(a)){let r=Qe(e);r&&$e(n)&&(o[et(t,r)]=n)}return rt(n,{version:X,entries:o}),o[et(t,r)]??null},at=(e,t,n,r)=>{let i=Qe(e);if(!i||!t||!$e(n))return;let a=null;try{a=r.getItem(`oc.gitBranchCache`)}catch{return}let o=nt(a);rt(r,{version:X,entries:{...o&&tt(o)?o.entries:{},[et(t,i)]:n}})},ot=3e4,st=Qe,ct=(e,t=n())=>s.git.branches(st(e),t),lt=(e,t=n())=>s.git.remotes(st(e),t),ut=async(e,t,n)=>{n.throwIfAborted();let r=a()?.git,i=t?.getGitBranches?await t.getGitBranches(e,{signal:n}):r?await r.getGitBranches(e,{signal:n}):await g(e,{signal:n});return n.throwIfAborted(),i},dt=async(e,t,n)=>{n.throwIfAborted();let r=a()?.git,i=t?.getRemotes?await t.getRemotes(e,{signal:n}):r?await r.getRemotes(e,{signal:n}):await m(e,{signal:n});return n.throwIfAborted(),i},ft=(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 ut(a,o,e);return at(a,r,t,i),t},staleTime:ot,gcTime:1/0,initialData:()=>it(a,r,i)??void 0,initialDataUpdatedAt:0}},pt=(e,t,r=n())=>{let i=st(e),a=t;return{queryKey:lt(i,r),queryFn:({signal:e})=>{if(!i)throw Error(`Git remotes require a directory`);return dt(i,a,e)},staleTime:ot,gcTime:1/0}},mt=(e,r,i)=>{let a=(0,I.c)(9),o=i===void 0||i,s=A.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=st(e),u=x,l=ft(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)},ht=(e,r,i)=>{let a=(0,I.c)(9),o=i===void 0||i,s=A.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=st(e),u=x,l=pt(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)},gt=(e,t,r=o,i=n())=>r.fetchQuery(ft(e,t,i)),_t=(e,t,r=o,i=n())=>r.fetchQuery({...ft(e,t,i),staleTime:0}),vt=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,yt=1e4,bt=6e4,xt=5e3,St=3e4,Ct=6e4,wt=25,Tt=40,Et=2,Dt=15e3,Ot=500,kt=30,At=20971520,jt=new Map,Mt=new Map,Nt=new Map,Pt=new Map,Ft=new Map,It=(e,t)=>`${t}:${e}`,Lt=e=>Mt.get(e)??0,Rt=e=>{let t=Lt(e)+1;return Mt.set(e,t),t},zt=e=>{let t=(Nt.get(e)??0)+1;return Nt.set(e,t),t},Bt=e=>{let t=jt.get(e);if(t)return t;let n=new Set;return jt.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}),Vt=(e,t=kt,n=At)=>{let r=0;for(let t of e.values())r+=(t.original?.length??0)+(t.modified?.length??0);if(e.size<=t&&r<=n)return e;let i=Array.from(e.entries()).sort((e,t)=>e[1].fetchedAt-t[1].fetchedAt),a=new Map,o=0;for(let e=i.length-1;e>=0;e--){let[r,s]=i[e],c=(s.original?.length??0)+(s.modified?.length??0);if(a.size>=t)break;o+c>n&&a.size>0||(a.set(r,s),o+=c)}return a},Ht=(e,t)=>{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},Ut=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,Wt=(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&&Ut(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&&Ht(e.diffStats,t.diffStats))},Gt=(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},Kt=(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},qt=e=>!e||e.trim().length===0,Jt=e=>(e||``).trim()===`U`,Yt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Jt(t)||Jt(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},Xt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Jt(t)||Jt(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},Zt=e=>qt(e.index)&&qt(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&&Rt(r),n&&Rt(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=It(n,a),s=Pt.get(o)??(a===`light`?Pt.get(It(n,`full`)):void 0);if(s)return s;let c=(async()=>{let{silent:a=!1}=i,{directories:o}=t(),s=o.get(n);if(s||=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)>bt,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(Wt(s.status,u)){c=!0;let r=new Map(t().directories),i=r.get(n)??Q(),s=Gt(i.status,u),l=Kt(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&&Rt(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})();Pt.set(o,c);try{return await c}finally{Pt.get(o)===c&&Pt.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`?Yt(e):Xt(e);t!==e&&(l=!0),Zt(t)?l=!0:u.push(t)}if(!l)return c;let d=new Map(o);return d.set(n,{...s,status:{...c,files:u,isClean:u.length===0},indexRevision:s.indexRevision+1,lastStatusChange:Date.now()}),e({directories:d}),c},restoreStatus:(n,r)=>{let{directories:i}=t(),a=i.get(n);if(!a)return;let o=new Map(i);o.set(n,{...a,status:r,indexRevision:a.indexRevision+1,lastStatusChange:Date.now()}),e({directories:o})},bumpIndexRevision:n=>{let{directories:r}=t(),i=r.get(n);if(!i)return;let a=new Map(r);a.set(n,{...i,indexRevision:i.indexRevision+1}),e({directories:a})},fetchBranches:async(r,i,a={})=>{let o=n(),s=zt(r);{let n=new Map(t().directories),i=n.get(r)??Q();n.set(r,{...i,isLoadingBranches:!0}),e({directories:n})}try{let c=a.force?await _t(r,i,void 0,o):await gt(r,i,void 0,o);if(s!==Nt.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(vt(i)||console.error(`Failed to fetch git branches:`,i),s!==Nt.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>yt||!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=Vt(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{Rt(n);let r=new Map(t().directories),i=r.get(n);i&&(r.set(n,{...i,diffCache:new Map}),e({directories:r}))},fetchAllDiffs:async(e,n)=>{let r=t().directories.get(e);if(!r?.status?.files||r.status.files.length===0)return;let i=r.status.files.map(e=>e.path).slice(0,wt);await t().prefetchDiffs(e,n,i,{maxFiles:wt})},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=Tt}=a,c=new Set(o.status.files.map(e=>e.path)),l=o.status.diffStats,u=Bt(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>Ot||d.push(e)}let p=d.slice(0,Math.max(1,s));if(p.length===0)return;let m=Lt(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 ${Dt}ms`)),Dt)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},ee=async()=>{for(;;){if(m!==Lt(n))return;let e=_();if(!e)return;try{g.push(await v(e))}catch{}finally{u.delete(e)}}},y=Math.min(Et,p.length);if(await Promise.allSettled(Array.from({length:y},()=>ee())),p.forEach(e=>u.delete(e)),m!==Lt(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=Vt(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<xt||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=Ft.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)>=xt)&&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>=St)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=yt)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=Ct)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return Ft.set(e,i),i.finally(()=>{Ft.get(e)===i&&Ft.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),Qt=e=>{let t=(0,I.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)},$t=e=>{let r=(0,I.c)(3),i=A.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)},en=e=>{let t=(0,I.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)},tn=e=>{let t=(0,I.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)},nn=e=>{let t=(0,I.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)},rn=e=>{let t=(0,I.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=A.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)},an=e=>{let t=(0,I.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)},on=e=>{let t=(0,I.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,I.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)}},ln=e=>String(e||``).trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/^remotes\//,``),un=e=>e.branchName?ln(e.branchName):e.mode===`existing`?ln(e.existingBranch||e.preferredName||``):ln(e.preferredName||``),dn=async e=>{let t=await ye(e);try{let n=cn((await _e(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=cn((await ve(e)).tracking);if(t?.remote)return t.remote}catch{}return null},fn=async(e,t)=>{let n=await dn(e),r=ln(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},pn=async(e,t,n)=>{let r=un(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await fn(e,r):i&&ln(r)?{setUpstream:!0,upstreamRemote:i,upstreamBranch:ln(r)}:null;return a?{...t,setUpstream:t.setUpstream??a.setUpstream,upstreamRemote:t.upstreamRemote||a.upstreamRemote,upstreamBranch:t.upstreamBranch||a.upstreamBranch}:t},mn=async(e,t,n)=>{let r=await pn(e.path,t,n);return be(e,r)},hn=`oc:lastWorktreeSourceBranch`,gn=({mode:e,sourceBranch:t,linkedPr:n,selectedBranch:r})=>e===`existing-branch`?r||null:n?null:t||null,_n=({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},vn=(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?` `:``}`},yn=(e,t,n)=>{let r=vn(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},bn=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=yn(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}},xn=(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]},Sn=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{ze as A,ht as C,W as D,We as E,Ve as O,mt as S,Ke as T,rn as _,hn as a,tn as b,mn as c,nn as d,$t as f,en as g,an as h,yn as i,Fe as j,Be as k,dn as l,on as m,xn as n,_n as o,sn as p,bn as r,gn as s,Sn as t,pn as u,Qt as v,Ze as w,_t as x,$ as y};