@openchambery/web 1.18.1 → 1.18.2-beta.2

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 (57) hide show
  1. package/dist/assets/{AssistantView-f5eK9QED.js → AssistantView-DvoyOGkx.js} +1 -1
  2. package/dist/assets/{ChatContainer-BvJoxcjJ.js → ChatContainer-D6yfuigV.js} +35 -35
  3. package/dist/assets/{DiagramView-Vu2JnmC-.js → DiagramView-MGGo9iME.js} +1 -1
  4. package/dist/assets/{MarkdownRendererImpl-CSxVZ_eA.js → MarkdownRendererImpl-jVOkZkyX.js} +1 -1
  5. package/dist/assets/{MobileDetailNavigation-3NIRdxpt.js → MobileDetailNavigation-Q2IzHqGA.js} +1 -1
  6. package/dist/assets/{MobileShareBridge-B7jqfJ-S.js → MobileShareBridge-apXM34Lb.js} +1 -1
  7. package/dist/assets/MobileSurface-htGkf7Ua.js +2 -0
  8. package/dist/assets/{MultiRunWindow-DkYTqcPq.js → MultiRunWindow-B-l_O-bd.js} +1 -1
  9. package/dist/assets/{OnboardingScreen-CCfdEtW6.js → OnboardingScreen-CUsgwt4y.js} +1 -1
  10. package/dist/assets/{OverlayScrollbar-DeL1aO59.js → OverlayScrollbar-D6NySAxi.js} +1 -1
  11. package/dist/assets/{SettingsView-CyrIDyDl.js → SettingsView-DxMpVLlt.js} +1 -1
  12. package/dist/assets/{SettingsWindow--nLXOo-L.js → SettingsWindow-DfVgTQ4I.js} +1 -1
  13. package/dist/assets/{TerminalView-B80SmYHn.js → TerminalView-DNyjfkvT.js} +1 -1
  14. package/dist/assets/{ToolOutputDialog-CtbnU35x.js → ToolOutputDialog-DLG1iThm.js} +1 -1
  15. package/dist/assets/appThemeRegistry-CgfOR_0L.js +2 -0
  16. package/dist/assets/{clipboard-Jdqe05db.js → clipboard-BW7nk_Cx.js} +1 -1
  17. package/dist/assets/{context-menu-D16ocNrk.js → context-menu-BaxmodD8.js} +1 -1
  18. package/dist/assets/{dialog-BzZ3cKxG.js → dialog-DjYfj1Sn.js} +1 -1
  19. package/dist/assets/{es-C25PRSjo.js → es-5Lhudh0n.js} +1 -1
  20. package/dist/assets/{fr-Cv8ZWQdW.js → fr-Q_UhFmKT.js} +1 -1
  21. package/dist/assets/{gitApi-B1CIqazO.js → gitApi-BYxg_qGJ.js} +1 -1
  22. package/dist/assets/{insertionBoundaries-B9cwRNac.js → insertionBoundaries-DzXMTleb.js} +1 -1
  23. package/dist/assets/{ja-Ue9m9eSe.js → ja-CzMPz7bT.js} +1 -1
  24. package/dist/assets/{ko-DWBUCCV6.js → ko-B-EslUsR.js} +1 -1
  25. package/dist/assets/{main-BSVnX01h.js → main-CO6z5yRB.js} +2 -2
  26. package/dist/assets/{main-DzZumJ48.js → main-LDphyc-v.js} +23 -23
  27. package/dist/assets/{miniChat-CrEtOV4u.js → miniChat-BZQwTZpx.js} +2 -2
  28. package/dist/assets/{mobile-DMjO-f5u.js → mobile-BktO3_4R.js} +2 -2
  29. package/dist/assets/{multirun-G-ZwKVUq.js → multirun-ZlwlkIy5.js} +1 -1
  30. package/dist/assets/{pl-DaBaPCyE.js → pl-Dnea6Ppc.js} +1 -1
  31. package/dist/assets/{projectMeta-owiDYjF9.js → projectMeta-v-LP2mzz.js} +1 -1
  32. package/dist/assets/{pt-BR-C2cJZ43o.js → pt-BR-Ca6QTem7.js} +1 -1
  33. package/dist/assets/{radio-BtilB34p.js → radio-CJuhbQ5a.js} +1 -1
  34. package/dist/assets/{renderElectronMiniChatApp-D1HWiWMn.js → renderElectronMiniChatApp-Db8uO-6q.js} +2 -2
  35. package/dist/assets/renderMobileApp-BCV81Ryl.js +23 -0
  36. package/dist/assets/{runtimeEndpointReset-C0oDuy2R.js → runtimeEndpointReset-Dg3DMy9v.js} +2 -2
  37. package/dist/assets/{sortable-tabs-strip-BpvOof2G.js → sortable-tabs-strip-D8JHUI0z.js} +1 -1
  38. package/dist/assets/{store-SqV3zfE8.js → store-wa1ersRf.js} +2 -2
  39. package/dist/assets/{uk-DJz_P8OZ.js → uk-xGc9Pzge.js} +1 -1
  40. package/dist/assets/{useAppFontEffects-BBxqFIta.js → useAppFontEffects-CM0VKsdo.js} +2 -2
  41. package/dist/assets/{useDesktopWindowControlsLayout-D8fjPyqI.js → useDesktopWindowControlsLayout-Cq-r4Hcb.js} +1 -1
  42. package/dist/assets/{useEffectiveDirectory-C5OxWqUH.js → useEffectiveDirectory-aUC3zzl_.js} +1 -1
  43. package/dist/assets/{useMobileNavigationStore-U3b_hG4m.js → useMobileNavigationStore-DnzT4jO2.js} +4 -4
  44. package/dist/assets/{useSessionAutoCleanup-CDYDm76L.js → useSessionAutoCleanup-DxZeceKO.js} +1 -1
  45. package/dist/assets/{useWorkerHighlightedLines-CJozblYF.js → useWorkerHighlightedLines-CiYQjBe6.js} +1 -1
  46. package/dist/assets/{zh-CN-DLAKDOM9.js → zh-CN-sL4ktGB3.js} +1 -1
  47. package/dist/assets/{zh-TW-s3Jjx1_n.js → zh-TW-Cfxps4gq.js} +1 -1
  48. package/dist/index.html +1 -1
  49. package/dist/mini-chat.html +1 -1
  50. package/dist/mobile.html +1 -1
  51. package/package.json +1 -1
  52. package/server/lib/git/DOCUMENTATION.md +2 -1
  53. package/server/lib/git/service.js +24 -5
  54. package/server/lib/git/service.test.js +51 -0
  55. package/dist/assets/MobileSurface-BL3hired.js +0 -2
  56. package/dist/assets/appThemeRegistry-D2ZUcQmr.js +0 -2
  57. package/dist/assets/renderMobileApp-Cqxwb3Ub.js +0 -23
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-C0FnF6B9.js";import{kn as t,xn as n}from"./persistence-DPNMIbF5.js";import{$ as r,A as i,D as a,F as o,G as s,H as c,I as l,J as u,K as d,M as f,P as p,Q as m,S as ee,T as te,W as ne,Y as re,_ as ie,_t as ae,a as oe,at as se,b as ce,c as le,d as ue,dt as de,et as fe,f as pe,ft as me,h as he,ht as ge,k as _e,kt as h,lt as ve,m as ye,mt as be,ot as xe,q as Se,r as Ce,s as we,tt as Te,v as Ee,x as De,y as Oe}from"./gitApiHttp-D8j1qRH4.js";import{Bi as g,Ji as _,Na as ke,l as v,s as Ae}from"./useMobileNavigationStore-U3b_hG4m.js";var je=e({applyGitStash:()=>W,checkIsGitRepository:()=>x,checkoutCommit:()=>Ke,cherryPick:()=>qe,countGitStashFiles:()=>H,createBranch:()=>q,createGitIdentity:()=>X,createGitWorktree:()=>R,deleteGitIdentity:()=>He,deleteGitWorktree:()=>z,deleteRemoteBranch:()=>A,discoverGitCredentials:()=>Q,discoverGitRepositories:()=>S,dropGitStash:()=>K,generateCommitMessage:()=>M,getCommitFileDiff:()=>J,getConflictDetails:()=>$,getGitBranches:()=>k,getGitIdentities:()=>Y,getGitStatus:()=>C,getGitWorktreeBootstrapStatus:()=>I,getGlobalGitIdentity:()=>Ue,git:()=>B,listGitStashes:()=>V,listGitWorktrees:()=>P,merge:()=>Ge,popGitStash:()=>G,previewGitWorktree:()=>L,rebase:()=>We,resetToCommit:()=>Ye,resolveGitPrimaryRoot:()=>w,resolveGitTopLevel:()=>Pe,revertCommit:()=>Je,stageGitFile:()=>T,stageGitFiles:()=>E,stashGitChanges:()=>U,unstageGitFile:()=>D,unstageGitFiles:()=>O,updateGitIdentity:()=>Z,validateGitWorktree:()=>F}),y=()=>n()?.git??null,Me=e=>{typeof window>`u`||window.dispatchEvent(new CustomEvent(`openchamber:chat-force-scroll-bottom`,{detail:{sessionId:e}}))},b=e=>{let t=e.trim(),n=(t.match(/```(?:json)?\s*([\s\S]*?)```/i)?.[1]??t).trim(),r=[n.indexOf(`{`)].filter(e=>e>=0);for(let e of r)for(let t=n.length;t>e;--t)if(n[t-1]===`}`)try{let r=JSON.parse(n.slice(e,t));if(r&&typeof r==`object`&&!Array.isArray(r))return r}catch{}return null},Ne=e=>{let t=e?.data;return(Array.isArray(t?.parts)?t.parts:[]).map(e=>{let t=e;return t.type===`text`?typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:typeof t.value==`string`?t.value:``:``}).filter(e=>e.trim().length>0).join(`
1
+ import{r as e}from"./rolldown-runtime-C0FnF6B9.js";import{kn as t,xn as n}from"./persistence-DPNMIbF5.js";import{$ as r,A as i,D as a,F as o,G as s,H as c,I as l,J as u,K as d,M as f,P as p,Q as m,S as ee,T as te,W as ne,Y as re,_ as ie,_t as ae,a as oe,at as se,b as ce,c as le,d as ue,dt as de,et as fe,f as pe,ft as me,h as he,ht as ge,k as _e,kt as h,lt as ve,m as ye,mt as be,ot as xe,q as Se,r as Ce,s as we,tt as Te,v as Ee,x as De,y as Oe}from"./gitApiHttp-D8j1qRH4.js";import{Bi as g,Ji as _,Na as ke,l as v,s as Ae}from"./useMobileNavigationStore-DnzT4jO2.js";var je=e({applyGitStash:()=>W,checkIsGitRepository:()=>x,checkoutCommit:()=>Ke,cherryPick:()=>qe,countGitStashFiles:()=>H,createBranch:()=>q,createGitIdentity:()=>X,createGitWorktree:()=>R,deleteGitIdentity:()=>He,deleteGitWorktree:()=>z,deleteRemoteBranch:()=>A,discoverGitCredentials:()=>Q,discoverGitRepositories:()=>S,dropGitStash:()=>K,generateCommitMessage:()=>M,getCommitFileDiff:()=>J,getConflictDetails:()=>$,getGitBranches:()=>k,getGitIdentities:()=>Y,getGitStatus:()=>C,getGitWorktreeBootstrapStatus:()=>I,getGlobalGitIdentity:()=>Ue,git:()=>B,listGitStashes:()=>V,listGitWorktrees:()=>P,merge:()=>Ge,popGitStash:()=>G,previewGitWorktree:()=>L,rebase:()=>We,resetToCommit:()=>Ye,resolveGitPrimaryRoot:()=>w,resolveGitTopLevel:()=>Pe,revertCommit:()=>Je,stageGitFile:()=>T,stageGitFiles:()=>E,stashGitChanges:()=>U,unstageGitFile:()=>D,unstageGitFiles:()=>O,updateGitIdentity:()=>Z,validateGitWorktree:()=>F}),y=()=>n()?.git??null,Me=e=>{typeof window>`u`||window.dispatchEvent(new CustomEvent(`openchamber:chat-force-scroll-bottom`,{detail:{sessionId:e}}))},b=e=>{let t=e.trim(),n=(t.match(/```(?:json)?\s*([\s\S]*?)```/i)?.[1]??t).trim(),r=[n.indexOf(`{`)].filter(e=>e>=0);for(let e of r)for(let t=n.length;t>e;--t)if(n[t-1]===`}`)try{let r=JSON.parse(n.slice(e,t));if(r&&typeof r==`object`&&!Array.isArray(r))return r}catch{}return null},Ne=e=>{let t=e?.data;return(Array.isArray(t?.parts)?t.parts:[]).map(e=>{let t=e;return t.type===`text`?typeof t.text==`string`?t.text:typeof t.content==`string`?t.content:typeof t.value==`string`?t.value:``:``}).filter(e=>e.trim().length>0).join(`
2
2
  `).trim()};async function x(e){let t=y();return t?t.checkIsGitRepository(e):oe(e)}async function S(e){return De(e)}async function C(e,t){let n=y();return n?n.getGitStatus(e,t):p(e,t)}async function w(e){return(await r(e)).root}async function Pe(e){return(await fe(e)).root}async function T(e,t){let n=y();return n?.stageGitFile?n.stageGitFile(e,t):se(e,t)}async function E(e,t){let n=y();return n?.stageGitFiles?n.stageGitFiles(e,t):xe(e,t)}async function D(e,t){let n=y();return n?.unstageGitFile?n.unstageGitFile(e,t):de(e,t)}async function O(e,t){let n=y();return n?.unstageGitFiles?n.unstageGitFiles(e,t):me(e,t)}async function k(e,t){let n=y();if(t?.signal?.throwIfAborted(),n){let r=await n.getGitBranches(e,t);return t?.signal?.throwIfAborted(),r}return _e(e,t)}async function A(e,t){let n=y();return n?n.deleteRemoteBranch(e,t):Oe(e,t)}var Fe=30,Ie=12e4,Le=async(e,t)=>{let n=t.slice(0,Fe),r=await Promise.all(n.map(async t=>{try{let[n,r]=await Promise.all([i(e,{path:t,staged:!0}).catch(()=>null),i(e,{path:t,staged:!1}).catch(()=>null)]);return[n?.diff,r?.diff].filter(e=>typeof e==`string`&&e.trim().length>0).join(`
3
3
  `)||`--- ${t} (no textual diff available)`}catch{return`--- ${t} (diff unavailable)`}})),a=``;for(let e of r){if(a.length+e.length>Ie){a+=`
4
4
  [remaining diffs truncated]`;break}a+=(a?`
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,b as n,j as r,t as i,y as a}from"./useUIStore-5agS8bsW.js";import{$t as o,D as s,d as c,k as l,u,xn as d}from"./persistence-DPNMIbF5.js";import{a as f,i as p,r as m}from"./vendor-zustand-B4dlGEM2.js";import{nt as h,rt as g}from"./vendor-base-ui-CnHfUmDN.js";import{L as _,Ot as v,k as y,yt as b}from"./gitApiHttp-D8j1qRH4.js";import{n as x}from"./vendor-react-DLPElpoQ.js";import{s as S}from"./vendor-tanstack-react-query-D7pys_c9.js";import{n as C}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ee}from"./clipboard-Jdqe05db.js";import{Ji as te,Za as ne,_ as re,b as ie,ct as ae,en as oe,l as w,mo as T,ot as E,po as se,st as ce,un as D,wr as O}from"./useMobileNavigationStore-U3b_hG4m.js";import{c as le,t as k}from"./utils-Co19EJEL.js";import{n as A}from"./Icon-AXqa-fYB.js";import{g as j,v as M}from"./gitApi-B1CIqazO.js";import{A as ue,M as N,p as P,s as F}from"./projectMeta-owiDYjF9.js";var I=e(g(),1),L=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},R=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,z=(e,t)=>{let n=L(t),r=L(e);if(!n||!r)return!1;let i=R(n),a=R(r);return a===i||a.startsWith(`${i}/`)},de=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=L(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=>L(e)).filter(e=>z(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>L(e)).filter(e=>z(e,t)))):[],s=typeof i.selectedPath==`string`?L(i.selectedPath):null,c=s&&z(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},B=(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},V=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},fe=f()(m(p((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=L((t||``).trim()),a=L((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!z(a,i)||e(e=>{let t=e.byRoot[i],n=V(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:B({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=L((t||``).trim()),i=L((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=R(i),a=e=>R(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:B({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=L((t||``).trim()),i=L((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=R(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=R(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:B({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=L((t||``).trim()),i=L((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=R(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=R(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:B({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=L((t||``).trim()),a=n?L(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!z(a,i)||e(e=>{let t=e.byRoot[i],n=V(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:B({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=L((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=L((t||``).trim()),i=L((n||``).trim());!r||!i||!z(i,r)||e(e=>{let t=e.byRoot[r],n=V(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:B({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=L((t||``).trim()),i=L((n||``).trim());!r||!i||!z(i,r)||e(e=>{let t=e.byRoot[r],n=V(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:B({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=L((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>L((e||``).trim())).filter(e=>e&&z(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=V(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:B({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:a(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:de(t)}},partialize:e=>({byRoot:de(e.byRoot)})}),{name:`files-view-tabs-store`})),H=x(),pe=(e,t)=>{let n=(0,H.c)(4),r=t===void 0?200:t,[i,a]=I.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]),I.useEffect(o,s),i},me=()=>{let e=(0,H.c)(17),t=w(U),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=ie(r),a=w(W),o=w(G),s=T(K),c=T(he),l=b(ge);if(t){let r;e[2]===i?r=e[3]:(r=re(i),e[2]=i,e[3]=r);let o=r;if(o)return o;let s;e[4]!==t||e[5]!==a?(s=a.get(t),e[4]=t,e[5]=a,e[6]=s):s=e[6];let c=s;if(c?.path)return c.path;let l;if(e[7]!==t||e[8]!==n){let r;e[10]===t?r=e[11]:(r=e=>e.id===t,e[10]=t,e[11]=r),l=n.find(r),e[7]=t,e[8]=n,e[9]=l}else l=e[9];let u=l;if(u?.directory)return u.directory}if(o?.open&&(o.bootstrapPendingDirectory||o.directoryOverride))return(o.bootstrapPendingDirectory||o.directoryOverride)??void 0;if(s){let t;if(e[12]!==s||e[13]!==c){let n;e[15]===s?n=e[16]:(n=e=>e.id===s,e[15]=s,e[16]=n),t=c.find(n),e[12]=s,e[13]=c,e[14]=t}else t=e[14];let n=t;if(n?.path)return n.path}return l??void 0};function U(e){return e.currentSessionId}function W(e){return e.worktreeMetadata}function G(e){return e.newSessionDraft}function K(e){return e.activeProjectId}function he(e){return e.projects}function ge(e){return e.currentDirectory}var _e=.4,q=8,J=e=>{let t=e.gap??q,n=Math.max(0,e.popupBottom-e.boundaryTop-t),r=e.viewportHeight*_e,i=Math.floor(Math.min(n,r));return n>=120?Math.min(n,Math.max(120,i)):i},Y=(e,t=0)=>{let n=e.closest(`main`);if(!n)return null;let r=(e.closest(`.mobile-chat-screen__content`)?.parentElement??n.parentElement?.closest(`main`)??n).querySelector(`:scope > .oc-mobile-detail-navigation`)?.getBoundingClientRect().bottom,i=n.getBoundingClientRect().top;return Math.max(r===void 0?i:Math.max(r,i),t)},ve=(e,t)=>{let n=(0,H.c)(3),[r,i]=I.useState(void 0),a;return n[0]!==e||n[1]!==t?(a=()=>{if(!t)return;let n=()=>{let t=e.current;if(!t)return;let n=window.visualViewport,r=Y(t,n?.offsetTop??0);if(r===null)return;let a=n?.height??window.innerHeight,o=J({popupBottom:t.getBoundingClientRect().bottom,boundaryTop:r,viewportHeight:a});i(e=>e===o?e:o)};return n(),window.addEventListener(`resize`,n),window.addEventListener(`oc:keyboard-settled`,n),window.visualViewport?.addEventListener(`resize`,n),window.visualViewport?.addEventListener(`scroll`,n),()=>{window.removeEventListener(`resize`,n),window.removeEventListener(`oc:keyboard-settled`,n),window.visualViewport?.removeEventListener(`resize`,n),window.visualViewport?.removeEventListener(`scroll`,n)}},n[0]=e,n[1]=t,n[2]=a):a=n[2],I.useLayoutEffect(a),t?r:void 0},ye=()=>{let e=null,t=!1,n=!1;return{pointerDown:(n,r)=>{e={x:n,y:r},t=!1},pointerMove:(n,r)=>{e&&Math.hypot(n-e.x,r-e.y)>6&&(t=!0)},pointerCancel:()=>{e=null,t=!1},pointerUp:r=>{if(!e)return!1;let i=!t;return e=null,t=!1,i?(n=!0,r(),!0):(n=!0,!1)},click:e=>n?(n=!1,!1):(e(),!0)}},X=h(),Z=I.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSessionSelect:r,onClose:a,style:o},c)=>{let{t:u}=ee(),d=me()??``,f=w(e=>e.currentSessionId),p=O(e=>e.activeSessions),m=T(e=>e.activeProjectId),h=T(e=>e.projects),g=I.useMemo(()=>h.find(e=>e.id===m)?.path??null,[m,h]),_=I.useMemo(()=>{let e=g||d;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[g,d]),y=fe(e=>_?e.byRoot[_]:void 0),b=te(e=>e.getVisibleAgents),x=v(e=>e.searchFiles),S=pe(e,180),ne=l(),re=s(),[ie,ae]=I.useState([]),[oe,se]=I.useState([]),[D,j]=I.useState(!1),[M,N]=I.useState(0),P=I.useRef(0),[F,L]=I.useState(360),[R,z]=I.useState({}),[de,B]=I.useState({}),V=I.useRef([]),H=I.useRef([]),U=I.useRef([]),W=I.useRef(null),G=I.useRef(null);G.current||=ye();let K=i(e=>e.isMobile),he=ve(W,K),ge=(e??``).trim(),_e=I.useMemo(()=>{if(!_||!y)return[];let e=[y.selectedPath,...y.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=ge.toLowerCase();return e.filter(e=>{if(t.has(e))return!1;t.add(e);let r=e.startsWith(`${_}/`)?e.slice(_.length+1):e;return!n||r.toLowerCase().includes(n)}).slice(0,6).map(e=>{let t=e.replace(/\\/g,`/`),n=t.split(`/`).filter(Boolean).pop()||t;return{name:n,path:t,relativePath:t.startsWith(`${_}/`)?t.slice(_.length+1):t,extension:n.includes(`.`)?n.split(`.`).pop()?.toLowerCase():void 0}})},[ge,_,y]),q=I.useMemo(()=>ge.length>0?oe:oe.slice(0,2),[oe,ge.length]),J=I.useMemo(()=>r?E({sessions:p,currentSessionId:f,searchQuery:ge}):[],[p,f,ge,r]),Y=_e,Z=ie;I.useEffect(()=>{let e=e=>{let t=e.target;!t||!W.current||W.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),I.useEffect(()=>{if(!d){ae([]);return}let e=(S??``).trim().replace(/^\.\//,``).replace(/^\/+/,``).toLowerCase();if(!e){ae([]);return}let t=!1;j(!0);let n={includeHidden:ne,respectGitignore:!re};return Promise.all([x(d,e,80,{...n,type:`file`}),x(d,e,40,{...n,type:`directory`})]).then(([n,r])=>{if(t)return;let i=new Set(_e.map(e=>e.path));ae(ce({files:n,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{t||ae([])}).finally(()=>{t||j(!1)}),()=>{t=!0}},[d,S,_e,x,ne,re]),I.useEffect(()=>{let t=b(),n=(e??``).trim().toLowerCase(),r=t.filter(e=>e.mode&&e.mode!==`primary`).filter(e=>!n||`${e.name} ${e.description??``}`.toLowerCase().includes(n)).map(e=>({name:e.name,description:e.description,mode:e.mode})).sort((e,t)=>e.name.localeCompare(t.name));se(r)},[b,e]),I.useEffect(()=>{N(0),z({}),B({})},[Z,Y.length,q.length,J.length]),I.useEffect(()=>{P.current=M},[M]),I.useEffect(()=>{V.current[M]?.scrollIntoView({block:`nearest`})},[M]),I.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};H.current.forEach((n,r)=>{if(!n)return;let i=U.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}}),z(e),B(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[Z,Y]),I.useEffect(()=>{let e=H.current[M];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&L(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[M]);let be=C(e=>{t(e)}),xe=C(e=>{n?.(e)}),Se=C(e=>{r?.(e)}),Ce=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&G.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&G.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(G.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>G.current?.pointerCancel(),onClick:()=>{G.current?.click(t)},onMouseMove:()=>N(e)});I.useImperativeHandle(c,()=>({handleKeyDown:e=>{if(e===`Escape`){a();return}let t=q.length+J.length+Y.length+Z.length;if(t!==0){if(e===`ArrowDown`){N(e=>(e+1)%t);return}if(e===`ArrowUp`){N(e=>(e-1+t)%t);return}if(e===`Enter`||e===`Tab`){let e=(P.current%t+t)%t;if(e<q.length){let t=q[e];t&&xe(t.name);return}let n=e-q.length;if(n<J.length){let e=J[n];e&&Se(e);return}let r=n-J.length,i=r<Y.length?Y[r]:Z[r-Y.length];i&&be(i)}}}}),[Z,Y,q,J,a,be,xe,Se]);let we=e=>{if(e.isDirectory)return(0,X.jsx)(A,{name:`folder-3-fill`,className:`h-3.5 w-3.5 text-current`});switch(e.extension?.toLowerCase()){case`ts`:case`tsx`:case`js`:case`jsx`:return(0,X.jsx)(A,{name:`code`,className:`h-3.5 w-3.5 text-current`});case`json`:return(0,X.jsx)(A,{name:`code`,className:`h-3.5 w-3.5 text-current`});case`md`:case`mdx`:return(0,X.jsx)(A,{name:`file`,className:`h-3.5 w-3.5 text-current`});case`png`:case`jpg`:case`jpeg`:case`gif`:case`svg`:return(0,X.jsx)(A,{name:`file-image`,className:`h-3.5 w-3.5 text-current`});default:return(0,X.jsx)(A,{name:`file-pdf`,className:`h-3.5 w-3.5 text-current`})}};return(0,X.jsxs)(`div`,{ref:W,className:`absolute z-[100] min-w-0 w-full max-w-[640px] max-h-64 bg-background border-2 border-border/60 rounded-xl shadow-none bottom-full mb-2 left-0 flex flex-col`,style:he===void 0?o:{...o,maxHeight:he},children:[(0,X.jsx)(ue,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,X.jsxs)(`div`,{className:`pb-2`,children:[q.length>0&&(0,X.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.groups.agents`)}),q.map((e,t)=>(0,X.jsx)(`div`,{ref:e=>{V.current[t]=e},className:k(`flex items-start gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,K&&`min-h-11`,M===t&&`bg-interactive-selection text-interactive-selection-foreground`),...Ce(t,()=>xe(e.name)),children:(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`font-semibold truncate`,children:[`@`,e.name]}),e.description&&!K?(0,X.jsx)(`div`,{className:`typography-meta text-muted-foreground truncate`,children:e.description}):null]})},`agent-${e.name}`)),q.length===2&&ge.length===0&&oe.length>2&&(0,X.jsx)(`div`,{className:`px-3 py-1 typography-meta text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.searchMoreAgents`)}),J.length>0&&(0,X.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.groups.sessions`)}),J.map((e,t)=>{let n=q.length+t;return(0,X.jsxs)(`div`,{ref:e=>{V.current[n]=e},className:k(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,K&&`min-h-11`,M===n&&`bg-interactive-selection text-interactive-selection-foreground`),...Ce(n,()=>Se(e)),children:[(0,X.jsx)(A,{name:`chat-thread`,className:`h-4 w-4 flex-shrink-0 text-[var(--primary-base)]`}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title||u(`chat.fileMentionAutocomplete.untitledSession`),children:e.title||u(`chat.fileMentionAutocomplete.untitledSession`)}),K?null:(0,X.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.sessionType`)})]},`session-${e.id}`)}),Y.length>0&&(0,X.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.groups.recentFiles`)}),Y.map((e,t)=>{let n=q.length+J.length+t,r=e.relativePath||e.name,i=le(r,{maxLength:60}),a=M===n,o=R[n]??!1,s=de[n]??2.6;return(0,X.jsxs)(`div`,{ref:e=>{V.current[n]=e},className:k(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,K&&`min-h-11`,a&&`bg-interactive-selection text-interactive-selection-foreground`),...Ce(n,()=>be(e)),children:[we(e),(0,X.jsxs)(`span`,{ref:e=>{H.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${F}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,X.jsx)(`span`,{ref:e=>{U.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,X.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:r}):(0,X.jsx)(`span`,{className:`block truncate`,children:i})]})]},`recent-${e.path}`)}),Z.length>0&&(0,X.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.groups.files`)}),Z.map((e,t)=>{let n=q.length+J.length+Y.length+t,r=e.relativePath||e.name,i=le(r,{maxLength:60}),a=M===n,o=R[n]??!1,s=de[n]??2.6;return(0,X.jsxs)(`div`,{ref:e=>{V.current[n]=e},className:k(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,K&&`min-h-11`,a&&`bg-interactive-selection text-interactive-selection-foreground`),...Ce(n,()=>be(e)),children:[we(e),(0,X.jsxs)(`span`,{ref:e=>{H.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${F}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,X.jsx)(`span`,{ref:e=>{U.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,X.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:r}):(0,X.jsx)(`span`,{className:`block truncate`,children:i})]})]},e.path)}),D&&Z.length===0?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,X.jsx)(A,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!D&&Z.length===0&&Y.length===0&&q.length===0&&J.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.empty`)})]})}),!K&&(0,X.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})}),be=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`model`,`goal`]),xe=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&be.has(n))},Se=(e,t)=>!e||t({name:e}),Ce=` `,we=(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]===Ce&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},Te=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,Ee=k(Te,`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)]`),De=k(Te,`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)]`),Oe=k(Te,`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)]`),ke=k(Te,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),Ae=(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=ae(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)},je=(e,t)=>{let n=!!e.sessionID;return{hasSession:n,canStartSessionCommand:n||e.hasNewDraft,canUseReviewHandoffFlow:n&&!t&&!o()}},Me=I.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:r,style:a,commandPolicy:o,commandContext:s},c)=>{let{t:l}=ee(),u=i(e=>e.isMobile),d=w(e=>e.currentSessionId),f=w(e=>!!e.newSessionDraft?.open),p=w(I.useCallback(e=>d?e.getDirectoryForSession(d):void 0,[d])),m=oe(d??``,p??void 0),h=I.useMemo(()=>s??{sessionID:d??null,hasMessages:m.length>0,hasNewDraft:f},[s,d,m.length,f]),{hasSession:g,canStartSessionCommand:_,canUseReviewHandoffFlow:v}=I.useMemo(()=>je(h,u),[h,u]),y=h.hasMessages,[b,x]=I.useState([]),[S,C]=I.useState(!1),te=se({directory:r}),re=I.useMemo(()=>te.data??[],[te.data]),ie=te.isFetching,ae=ne({directory:r}),T=I.useMemo(()=>ae.data??[],[ae.data]),[E,ce]=I.useState(0),D=I.useRef(0),O=I.useRef(!1),le=I.useRef([]),j=I.useRef(null),M=ve(j,u),N=I.useRef(!1),P=I.useRef(null),F=I.useRef(!1);I.useEffect(()=>{let e=e=>{let t=e.target;!t||!j.current||j.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),I.useEffect(()=>{(async()=>{C(ie);try{let t=re.map((e,t)=>({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,isSkill:e.source===`skill`,scope:e.scope,reference:e.reference})),n=T.map((e,t)=>({id:`skill:${e.scope}:${e.source??`opencode`}:${e.name}:${t}`,name:e.name,source:`skill`,description:e.description,isSkill:!0,scope:e.scope})),r=[{id:`openchamber:new`,name:`new`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},...g&&!y?[{id:`openchamber:init`,name:`init`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],...g?[{id:`openchamber:undo`,name:`undo`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`openchamber:redo`,name:`redo`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`openchamber:fork`,name:`fork`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`openchamber:timeline`,name:`timeline`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`openchamber:model`,name:`model`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`openchamber:compact`,name:`compact`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...g?[{id:`openchamber:summary`,name:`summary`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.summaryDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:workspace-review`,name:`workspace-review`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.workspaceReviewDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:handoff-review`,name:`handoff-review`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.handoffReviewDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:plan-feature`,name:`plan-feature`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.featurePlanDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:craft-goal`,name:`craft-goal`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.craftGoalDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:goal`,name:`goal`,source:`openchamber`,description:l(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:catch-up`,name:`catch-up`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.catchUpDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:debug`,name:`debug`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.debugDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:weigh`,name:`weigh`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.weighDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:explore`,name:`explore`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.exploreDescription`),isOpenChamber:!0}]:[],...t,...n],i=!y,a=r.filter(e=>(i||e.name!==`init`)&&(o?.(e)??!0));x(Ae(a,e))}catch{let t=!y,n=[{id:`openchamber:new`,name:`new`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},...g&&!y?[{id:`openchamber:init`,name:`init`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],...g?[{id:`openchamber:undo`,name:`undo`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`openchamber:redo`,name:`redo`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`openchamber:fork`,name:`fork`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`openchamber:timeline`,name:`timeline`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`openchamber:model`,name:`model`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`openchamber:compact`,name:`compact`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...g?[{id:`openchamber:summary`,name:`summary`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.summaryDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:workspace-review`,name:`workspace-review`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.workspaceReviewDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:handoff-review`,name:`handoff-review`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.handoffReviewDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:plan-feature`,name:`plan-feature`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.featurePlanDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:craft-goal`,name:`craft-goal`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.craftGoalDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:goal`,name:`goal`,source:`openchamber`,description:l(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:catch-up`,name:`catch-up`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.catchUpDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:debug`,name:`debug`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.debugDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:weigh`,name:`weigh`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.weighDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:explore`,name:`explore`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.exploreDescription`),isOpenChamber:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(o?.(e)??!0));x(Ae(n,e))}finally{C(!1)}})()},[e,y,g,_,v,re,ie,T,l,o]),I.useEffect(()=>{ce(0)},[b]),I.useEffect(()=>{D.current=E},[E]),I.useEffect(()=>{le.current[E]?.scrollIntoView({block:`nearest`})},[E]),I.useImperativeHandle(c,()=>({handleKeyDown:e=>{let r=b.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){O.current=!0,ce(e=>(e+1)%r);return}if(e===`ArrowUp`){O.current=!0,ce(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(D.current%r+r)%r,i=b[n];i&&t(i,xe(i,e===`Enter`))}}}}),[b,n,t]);let L=e=>{switch(e.name){case`new`:return(0,X.jsx)(A,{name:`add`,className:`h-3.5 w-3.5`});case`init`:return(0,X.jsx)(A,{name:`file`,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,X.jsx)(A,{name:`arrow-go-back`,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,X.jsx)(A,{name:`arrow-go-forward`,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:return(0,X.jsx)(A,{name:`time`,className:`h-3.5 w-3.5`});case`compact`:return(0,X.jsx)(A,{name:`scissors`,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,X.jsx)(A,{name:`target`,className:`h-3.5 w-3.5`});case`review`:return(0,X.jsx)(A,{name:`search-eye`,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,X.jsx)(A,{name:`terminal-box`,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,X.jsx)(A,{name:`flashlight`,className:`h-3.5 w-3.5 text-yellow-500`}):(0,X.jsx)(A,{name:`command`,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,X.jsxs)(`div`,{ref:j,className:`absolute z-[100] min-w-0 w-full max-w-[450px] max-h-64 bg-background border-2 border-border/60 rounded-xl shadow-none bottom-full mb-2 left-0 flex flex-col`,style:M===void 0?a:{...a,maxHeight:M},children:[(0,X.jsx)(ue,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 pb-2`,children:S?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,X.jsx)(A,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,X.jsxs)(`div`,{children:[b.map((e,n)=>{let r=e.isBuiltIn,i=e.isOpenChamber;return(0,X.jsxs)(`div`,{ref:e=>{le.current[n]=e},className:k(`flex gap-2 px-3 py-2 cursor-pointer rounded-lg`,u?`items-center`:`items-start`,n===E&&`bg-interactive-selection`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(P.current={x:e.clientX,y:e.clientY},F.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!P.current)return;let t=e.clientX-P.current.x,n=e.clientY-P.current.y;Math.hypot(t,n)>6&&(F.current=!0)},onPointerUp:n=>{if(n.pointerType!==`touch`)return;let r=F.current;P.current=null,F.current=!1,!r&&(n.preventDefault(),n.stopPropagation(),N.current=!0,t(e,xe(e,u)))},onPointerCancel:()=>{P.current=null,F.current=!1},onClick:()=>{if(N.current){N.current=!1;return}t(e,xe(e,u))},onMouseMove:()=>{O.current=!1,ce(n)},children:[(0,X.jsx)(`div`,{className:k(!u&&`mt-0.5`),children:L(e)}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,e.name]}),e.isSkill?(0,X.jsx)(`span`,{className:Ee,children:l(`chat.commandAutocomplete.badge.skill`)}):(0,X.jsx)(`span`,{className:Ee,children:l(`chat.commandAutocomplete.badge.command`)}),i?(0,X.jsx)(`span`,{className:ke,children:`OpenChamber`}):r?(0,X.jsx)(`span`,{className:ke,children:l(`chat.commandAutocomplete.badge.system`)}):e.scope?(0,X.jsx)(`span`,{className:e.scope===`project`?Oe:De,children:e.scope}):null,e.agent&&(0,X.jsx)(`span`,{className:ke,children:e.agent})]}),e.description&&!u&&(0,X.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:e.description})]})]},e.id)}),b.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:l(`chat.commandAutocomplete.empty`)})]})}),!u&&(0,X.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:l(`chat.autocomplete.keyboardHint`)})]})});Me.displayName=`CommandAutocomplete`;function Ne(e){return(e.description||e.content).replace(/\s+/g,` `).trim().slice(0,120)}var Pe=I.forwardRef((e,t)=>{let n=(0,H.c)(63),{searchQuery:r,onSnippetSelect:a,onClose:o,style:s}=e,{t:c}=ee(),l=I.useRef(null),u=i(Fe),d=ve(l,u),[f,p]=I.useState(0),m=I.useRef(0),h;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=[],n[0]=h):h=n[0];let[g,_]=I.useState(h),v;n[1]===Symbol.for(`react.memo_cache_sentinel`)?(v=[],n[1]=v):v=n[1];let y=I.useRef(v),b=N(Ie),x=N(Le),S=N(Re),C=N(ze),te=i(Be),ne=i(Ve),re,ie;n[2]===x?(re=n[3],ie=n[4]):(re=()=>{x()},ie=[x],n[2]=x,n[3]=re,n[4]=ie),I.useEffect(re,ie);let oe,w;n[5]!==r||n[6]!==b?(oe=()=>{let e=r.trim();if(!e.length){let e=[...b].sort(He);_(e),p(+!!e.length);return}let t=ae(b,e,Ue);t.sort(We);let n=t.map(Ge);_(n),p(+!!n.length)},w=[r,b],n[5]=r,n[6]=b,n[7]=oe,n[8]=w):(oe=n[7],w=n[8]),I.useEffect(oe,w);let T,E;n[9]===f?(T=n[10],E=n[11]):(T=()=>{m.current=f,y.current[f]?.scrollIntoView({block:`nearest`})},E=[f],n[9]=f,n[10]=T,n[11]=E),I.useEffect(T,E);let se,ce;n[12]===o?(se=n[13],ce=n[14]):(ce=()=>{let e=e=>{let t=e.target;t&&l.current&&!l.current.contains(t)&&o()};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},se=[o],n[12]=o,n[13]=se,n[14]=ce),I.useEffect(ce,se);let D;n[15]!==a||n[16]!==r?(D=e=>{let t=r.trim(),n=e.aliases.includes(t)?t:e.name;a(e,n)},n[15]=a,n[16]=r,n[17]=D):D=n[17];let O=D,le;n[18]!==o||n[19]!==C||n[20]!==te||n[21]!==ne||n[22]!==S||n[23]!==b?(le=()=>{let e=new Set(b.map(Ke)),t=`new-snippet`,n=1;for(;e.has(t);)t=`new-snippet-${n++}`;S({name:t,scope:`global`}),C(t),ne(`snippets`),te(!0),o()},n[18]=o,n[19]=C,n[20]=te,n[21]=ne,n[22]=S,n[23]=b,n[24]=le):le=n[24];let j=le,M,P;n[25]!==O||n[26]!==g||n[27]!==o||n[28]!==j?(M=()=>({handleKeyDown:e=>{if(e===`Escape`){o();return}let t=g.length+1;if(e===`ArrowDown`){p(e=>(e+1)%t);return}if(e===`ArrowUp`){p(e=>(e-1+t)%t);return}if(e===`Enter`||e===`Tab`){if(m.current===0){j();return}let e=g[m.current-1];e&&O(e)}}}),P=[O,g,o,j],n[25]=O,n[26]=g,n[27]=o,n[28]=j,n[29]=M,n[30]=P):(M=n[29],P=n[30]),I.useImperativeHandle(t,M,P);let F;n[31]!==d||n[32]!==s?(F=d===void 0?s:{...s,maxHeight:d},n[31]=d,n[32]=s,n[33]=F):F=n[33];let L;n[34]===Symbol.for(`react.memo_cache_sentinel`)?(L=e=>{y.current[0]=e},n[34]=L):L=n[34];let R=f===0&&`bg-interactive-selection`,z;n[35]===R?z=n[36]:(z=k(`flex items-center gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,R),n[35]=R,n[36]=z);let de,B;n[37]===Symbol.for(`react.memo_cache_sentinel`)?(de=()=>p(0),B=(0,X.jsx)(A,{name:`add`,className:`h-3.5 w-3.5 text-muted-foreground`}),n[37]=de,n[38]=B):(de=n[37],B=n[38]);let V;n[39]===c?V=n[40]:(V=c(`chat.snippetAutocomplete.action.addNew`),n[39]=c,n[40]=V);let fe;n[41]===V?fe=n[42]:(fe=(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:V}),n[41]=V,n[42]=fe);let pe;n[43]!==j||n[44]!==z||n[45]!==fe?(pe=(0,X.jsxs)(`div`,{ref:L,className:z,onClick:j,onMouseMove:de,children:[B,fe]}),n[43]=j,n[44]=z,n[45]=fe,n[46]=pe):pe=n[46];let me;n[47]!==O||n[48]!==g||n[49]!==u||n[50]!==f||n[51]!==c?(me=g.length?g.map((e,t)=>(0,X.jsx)(`div`,{ref:e=>{y.current[t+1]=e},className:k(`flex gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,u?`items-center`:`items-start`,t+1===f&&`bg-interactive-selection`),onClick:()=>O(e),onMouseMove:()=>p(t+1),children:(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`font-semibold truncate`,children:[`#`,e.name]}),(0,X.jsx)(`span`,{className:`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0 bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`,children:c(`snippets.source.${e.source}`)})]}),!u&&(0,X.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Ne(e)})]})},`${e.source}:${e.filePath}`)):(0,X.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:c(`chat.snippetAutocomplete.empty`)}),n[47]=O,n[48]=g,n[49]=u,n[50]=f,n[51]=c,n[52]=me):me=n[52];let U;n[53]!==pe||n[54]!==me?(U=(0,X.jsxs)(ue,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 pb-2`,children:[pe,me]}),n[53]=pe,n[54]=me,n[55]=U):U=n[55];let W;n[56]!==u||n[57]!==c?(W=!u&&(0,X.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:c(`chat.snippetAutocomplete.footer`)}),n[56]=u,n[57]=c,n[58]=W):W=n[58];let G;return n[59]!==F||n[60]!==U||n[61]!==W?(G=(0,X.jsxs)(`div`,{ref:l,className:`absolute z-[100] min-w-0 w-full max-w-[450px] max-h-60 bg-background border-2 border-border/60 rounded-xl shadow-none bottom-full mb-2 left-0 flex flex-col`,style:F,children:[U,W]}),n[59]=F,n[60]=U,n[61]=W,n[62]=G):G=n[62],G});Pe.displayName=`SnippetAutocomplete`;function Fe(e){return e.isMobile}function Ie(e){return e.snippets}function Le(e){return e.loadSnippets}function Re(e){return e.setSnippetDraft}function ze(e){return e.setSelectedSnippet}function Be(e){return e.setSettingsDialogOpen}function Ve(e){return e.setSettingsPage}function He(e,t){return e.source===`project`&&t.source!==`project`?-1:e.source!==`project`&&t.source===`project`?1:e.name.localeCompare(t.name)}function Ue(e){return[e.name,...e.aliases]}function We(e,t){return e.score===t.score?e.item.source===`project`&&t.item.source!==`project`?-1:e.item.source!==`project`&&t.item.source===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score}function Ge(e){return e.item}function Ke(e){return e.name}var qe=2,Je=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Ye=e=>{let t=e?.trim().replace(/\\/g,`/`);return t?t.length>1?t.replace(/\/+$/,``):t:null},Xe=e=>Je(e)&&Array.isArray(e.all)&&e.all.every(e=>typeof e==`string`)&&typeof e.current==`string`&&Je(e.branches),Ze=(e,t)=>JSON.stringify([e,t]),Qe=e=>`version`in e&&e.version===qe&&Je(e.entries),$e=e=>{if(!e)return null;try{let t=JSON.parse(e);return Je(t)?t.version===qe&&Je(t.entries)?{version:qe,entries:t.entries}:t:null}catch{return null}},et=(e,t)=>{try{e.setItem(`oc.gitBranchCache`,JSON.stringify(t))}catch{}},tt=(e,t,n)=>{let r=Ye(e);if(!r||!t)return null;let i;try{i=n.getItem(`oc.gitBranchCache`)}catch{return null}let a=$e(i);if(!a)return null;if(Qe(a))return Xe(a.entries[Ze(t,r)])?a.entries[Ze(t,r)]:null;let o={};for(let[e,n]of Object.entries(a)){let r=Ye(e);r&&Xe(n)&&(o[Ze(t,r)]=n)}return et(n,{version:qe,entries:o}),o[Ze(t,r)]??null},nt=(e,t,n,r)=>{let i=Ye(e);if(!i||!t||!Xe(n))return;let a=null;try{a=r.getItem(`oc.gitBranchCache`)}catch{return}let o=$e(a);et(r,{version:qe,entries:{...o&&Qe(o)?o.entries:{},[Ze(t,i)]:n}})},rt=3e4,it=Ye,at=(e,n=t())=>c.git.branches(it(e),n),ot=(e,n=t())=>c.git.remotes(it(e),n),st=async(e,t,n)=>{n.throwIfAborted();let r=d()?.git,i=t?.getGitBranches?await t.getGitBranches(e,{signal:n}):r?await r.getGitBranches(e,{signal:n}):await y(e,{signal:n});return n.throwIfAborted(),i},ct=async(e,t,n)=>{n.throwIfAborted();let r=d()?.git,i=t?.getRemotes?await t.getRemotes(e,{signal:n}):r?await r.getRemotes(e,{signal:n}):await _(e,{signal:n});return n.throwIfAborted(),i},lt=(e,r,i=t(),a=n())=>{let o=it(e),s=r;return{queryKey:at(o,i),queryFn:async({signal:e})=>{if(!o)throw Error(`Git branches require a directory`);let t=await st(o,s,e);return nt(o,i,t,a),t},staleTime:rt,gcTime:1/0,initialData:()=>tt(o,i,a)??void 0,initialDataUpdatedAt:0}},ut=(e,n,r=t())=>{let i=it(e),a=n;return{queryKey:ot(i,r),queryFn:({signal:e})=>{if(!i)throw Error(`Git remotes require a directory`);return ct(i,a,e)},staleTime:rt,gcTime:1/0}},dt=(e,n,i)=>{let a=(0,H.c)(9),o=i===void 0||i,s=I.useSyncExternalStore(r,t,t),c,l,u;a[0]!==e||a[1]!==n||a[2]!==s?(c=it(e),u=S,l=lt(c,n,s),a[0]=e,a[1]=n,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)},ft=(e,n,i)=>{let a=(0,H.c)(9),o=i===void 0||i,s=I.useSyncExternalStore(r,t,t),c,l,u;a[0]!==e||a[1]!==n||a[2]!==s?(c=it(e),u=S,l=ut(c,n,s),a[0]=e,a[1]=n,a[2]=s,a[3]=c,a[4]=l,a[5]=u):(c=a[3],l=a[4],u=a[5]);let d=o&&!!c,f;return a[6]!==l||a[7]!==d?(f={...l,enabled:d},a[6]=l,a[7]=d,a[8]=f):f=a[8],u(f)},pt=(e,n,r=u,i=t())=>r.fetchQuery(lt(e,n,i)),mt=(e,n,r=u,i=t())=>r.fetchQuery({...lt(e,n,i),staleTime:0}),ht=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,gt=1e4,_t=6e4,vt=5e3,yt=3e4,bt=6e4,xt=25,St=40,Ct=2,wt=15e3,Tt=500,Et=30,Dt=20971520,Ot=new Map,kt=new Map,At=new Map,jt=new Map,Mt=new Map,Nt=(e,t)=>`${t}:${e}`,Pt=e=>kt.get(e)??0,Ft=e=>{let t=Pt(e)+1;return kt.set(e,t),t},It=e=>{let t=(At.get(e)??0)+1;return At.set(e,t),t},Lt=e=>{let t=Ot.get(e);if(t)return t;let n=new Set;return Ot.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}),Rt=(e,t=Et,n=Dt)=>{let r=0;for(let t of e.values())r+=(t.original?.length??0)+(t.modified?.length??0);if(e.size<=t&&r<=n)return e;let i=Array.from(e.entries()).sort((e,t)=>e[1].fetchedAt-t[1].fetchedAt),a=new Map,o=0;for(let e=i.length-1;e>=0;e--){let[r,s]=i[e],c=(s.original?.length??0)+(s.modified?.length??0);if(a.size>=t)break;o+c>n&&a.size>0||(a.set(r,s),o+=c)}return a},zt=(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},Bt=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,Vt=(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&&Bt(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&&zt(e.diffStats,t.diffStats))},Ht=(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},Ut=(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},Wt=e=>!e||e.trim().length===0,Gt=e=>(e||``).trim()===`U`,Kt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Gt(t)||Gt(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},qt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Gt(t)||Gt(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},Jt=e=>Wt(e.index)&&Wt(e.working_dir),$=f()(m((e,n)=>({directories:new Map,activeDirectory:null,setActiveDirectory:t=>{let{activeDirectory:r,directories:i}=n();if(r!==t)if(r&&Ft(r),t&&Ft(t),t&&!i.has(t)){let n=new Map(i);n.set(t,Q()),e({activeDirectory:t,directories:n})}else e({activeDirectory:t})},getDirectoryState:e=>n().directories.get(e)??null,fetchStatus:async(t,r,i={})=>{let a=i.mode??`full`,o=Nt(t,a),s=jt.get(o)??(a===`light`?jt.get(Nt(t,`full`)):void 0);if(s)return s;let c=(async()=>{let{silent:a=!1}=i,{directories:o}=n(),s=o.get(t);if(s||=Q(),!a){let r=new Map(n().directories),i=r.get(t)??Q();r.set(t,{...i,isLoadingStatus:!0}),e({directories:r})}let c=!1;try{let a=Date.now(),o=s.isGitRepo!==!0||a-(s.lastRepoCheckAt||0)>_t,l=s.isGitRepo===!0;if(o&&(l=await r.checkIsGitRepository(t)),!l){let r=new Map(n().directories),i=r.get(t)??s;return r.set(t,{...i,isGitRepo:!1,status:null,isLoadingStatus:!1,lastRepoCheckAt:a,lastStatusFetch:a}),e({directories:r}),!1}let u=await r.getGitStatus(t,i.mode?{mode:i.mode}:void 0);if(Vt(s.status,u)){c=!0;let r=new Map(n().directories),i=r.get(t)??Q(),s=Ht(i.status,u),l=Ut(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&&Ft(t);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(t,{...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(n().directories),i=r.get(t)??Q();r.set(t,{...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(n().directories),i=r.get(t)??Q();r.set(t,{...i,isLoadingStatus:!1}),e({directories:r})}}return c})();jt.set(o,c);try{return await c}finally{jt.get(o)===c&&jt.delete(o)}},moveStatusPathsOptimistically:(t,r,i)=>{let a=new Set(r.map(e=>e.trim()).filter(Boolean));if(a.size===0)return null;let{directories:o}=n(),s=o.get(t),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`?Kt(e):qt(e);t!==e&&(l=!0),Jt(t)?l=!0:u.push(t)}if(!l)return c;let d=new Map(o);return d.set(t,{...s,status:{...c,files:u,isClean:u.length===0},indexRevision:s.indexRevision+1,lastStatusChange:Date.now()}),e({directories:d}),c},restoreStatus:(t,r)=>{let{directories:i}=n(),a=i.get(t);if(!a)return;let o=new Map(i);o.set(t,{...a,status:r,indexRevision:a.indexRevision+1,lastStatusChange:Date.now()}),e({directories:o})},bumpIndexRevision:t=>{let{directories:r}=n(),i=r.get(t);if(!i)return;let a=new Map(r);a.set(t,{...i,indexRevision:i.indexRevision+1}),e({directories:a})},fetchBranches:async(r,i,a={})=>{let o=t(),s=It(r);{let t=new Map(n().directories),i=t.get(r)??Q();t.set(r,{...i,isLoadingBranches:!0}),e({directories:t})}try{let c=a.force?await mt(r,i,void 0,o):await pt(r,i,void 0,o);if(s!==At.get(r)||o!==t())return;let l=new Map(n().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(ht(i)||console.error(`Failed to fetch git branches:`,i),s!==At.get(r)||o!==t())return;let a=new Map(n().directories),c=a.get(r)??Q();a.set(r,{...c,isLoadingBranches:!1}),e({directories:a})}},fetchLog:async(t,r,i)=>{let{directories:a}=n(),o=a.get(t),s=i??o?.logMaxCount??25;{let r=new Map(n().directories),i=r.get(t)??Q();r.set(t,{...i,isLoadingLog:!0}),e({directories:r})}try{let i=await r.getGitLog(t,{maxCount:s}),a=new Map(n().directories),o=a.get(t)??Q();a.set(t,{...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(n().directories),a=i.get(t)??Q();i.set(t,{...a,isLoadingLog:!1}),e({directories:i})}},fetchIdentity:async(t,r)=>{{let r=new Map(n().directories),i=r.get(t)??Q();r.set(t,{...i,isLoadingIdentity:!0}),e({directories:r})}try{let i=await r.getCurrentGitIdentity(t),a=new Map(n().directories),o=a.get(t)??Q();a.set(t,{...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(n().directories),a=i.get(t)??Q();i.set(t,{...a,isLoadingIdentity:!1}),e({directories:i})}},fetchAll:async(t,r,i={})=>{let{directories:a}=n(),o=a.get(t);if(!o){o=Q();let n=new Map(a);n.set(t,o),e({directories:n})}let{force:s=!1,silentIfCached:c=!1}=i,l=Date.now();await n().fetchStatus(t,r,{silent:c&&!!o?.status});let u=n().directories.get(t);if(!u?.isGitRepo)return;await n().fetchBranches(t,r,{force:s});let d=l-(u.lastLogFetch||0);(s||d>gt||!u.log)&&await n().fetchLog(t,r),await n().fetchIdentity(t,r)},getDiff:(e,t)=>n().directories.get(e)?.diffCache.get(t)??null,setDiff:(t,r,i)=>{let a=new Map(n().directories),o=a.get(t)??Q(),s=new Map(o.diffCache);s.set(r,{...i,fetchedAt:Date.now()});let c=Rt(s);a.set(t,{...o,diffCache:c}),e({directories:a})},clearDiffCache:t=>{Ft(t);let r=new Map(n().directories),i=r.get(t);i&&(r.set(t,{...i,diffCache:new Map}),e({directories:r}))},fetchAllDiffs:async(e,t)=>{let r=n().directories.get(e);if(!r?.status?.files||r.status.files.length===0)return;let i=r.status.files.map(e=>e.path).slice(0,xt);await n().prefetchDiffs(e,t,i,{maxFiles:xt})},prefetchDiffs:async(t,r,i,a={})=>{let o=n().directories.get(t);if(!o?.status?.files||o.status.files.length===0||i.length===0)return;let{maxFiles:s=St}=a,c=new Set(o.status.files.map(e=>e.path)),l=o.status.diffStats,u=Lt(t),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>Tt||d.push(e)}let p=d.slice(0,Math.max(1,s));if(p.length===0)return;let m=Pt(t);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 n=r.getGitFileDiff(t,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${wt}ms`)),wt)}),a=await Promise.race([n,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},y=async()=>{for(;;){if(m!==Pt(t))return;let e=_();if(!e)return;try{g.push(await v(e))}catch{}finally{u.delete(e)}}},b=Math.min(Ct,p.length);if(await Promise.allSettled(Array.from({length:b},()=>y())),p.forEach(e=>u.delete(e)),m!==Pt(t))return;let x=new Map(n().directories),S=x.get(t);if(!S)return;let C=new Map(S.diffCache),ee=Date.now();g.forEach(e=>{C.set(e.path,{...e.diff,fetchedAt:ee})});let te=Rt(C);x.set(t,{...S,diffCache:te}),e({directories:x})},setLogMaxCount:(t,r)=>{let i=new Map(n().directories),a=i.get(t)??Q();i.set(t,{...a,logMaxCount:r}),e({directories:i})},ensureStatus:async(e,t)=>{let r=n().directories.get(e),i=Date.now();r?.status&&i-r.lastStatusFetch<vt||await n().fetchStatus(e,t,{silent:!!r?.status})},ensureAll:(e,t)=>{let r=Mt.get(e);if(r)return r;let i=(async()=>{let r=n().directories.get(e),i=Date.now();(!r?.status||r.status.diffStats===void 0||i-(r?.lastStatusFetch??0)>=vt)&&await n().fetchStatus(e,t,{silent:!!r?.status});let a=n().directories.get(e);if(!a?.isGitRepo)return;let o=[];(!a.branches||i-a.lastBranchesFetch>=yt)&&o.push(n().fetchBranches(e,t)),(!a.log||i-a.lastLogFetch>=gt)&&o.push(n().fetchLog(e,t)),(!a.identity||i-a.lastIdentityFetch>=bt)&&o.push(n().fetchIdentity(e,t)),o.length>0&&await Promise.all(o)})();return Mt.set(e,i),i.finally(()=>{Mt.get(e)===i&&Mt.delete(e)}),i},refresh:async(e,t={})=>{let{activeDirectory:r}=n();r&&await n().fetchAll(r,e,t)}}),{name:`git-store`})),Yt=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status??null:null,t[0]=e,t[1]=n),$(n)},Xt=e=>{let n=(0,H.c)(3),i=I.useSyncExternalStore(r,t,t),a;return n[0]!==e||n[1]!==i?(a=t=>{if(!e)return null;let n=t.directories.get(e);return n?.branchesTransportIdentity===i?n.branches:null},n[0]=e,n[1]=i,n[2]=a):a=n[2],$(a)},Zt=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.log??null:null,t[0]=e,t[1]=n),$(n)},Qt=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isGitRepo??null:null,t[0]=e,t[1]=n),$(n)},$t=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status?.current?.trim()??null:null,t[0]=e,t[1]=n),$(n)},en={current:new Map},tn=()=>$(sn),nn=e=>{let t=(0,H.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=I.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)},rn=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingStatus??!1:!1,t[0]=e,t[1]=n),$(n)},an=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingLog??!1:!1,t[0]=e,t[1]=n),$(n)},on=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingBranches??!1:!1,t[0]=e,t[1]=n),$(n)};function sn(e){let t=en.current,n=t.size===e.directories.size;if(n){for(let[r,i]of e.directories)if(t.get(r)!==(i.status?.current??null)){n=!1;break}}if(n)return t;let r=new Map;for(let[t,n]of e.directories)r.set(t,n.status?.current??null);return en.current=r,r}var 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 P(e);try{let n=cn((await j(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=cn((await M(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 F(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]:[...e,t]},Sn=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{ve as A,dt as C,we as D,Me as E,pe as M,fe as N,Se as O,mt as S,Pe as T,Zt as _,hn as a,$ as b,mn as c,tn as d,$t as f,rn as g,an as h,yn as i,me as j,Z as k,dn as l,on as m,xn as n,_n as o,Xt as p,bn as r,gn as s,Sn as t,pn as u,nn as v,ft as w,Qt as x,Yt as y};
1
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{D as t,b as n,j as r,t as i,y as a}from"./useUIStore-5agS8bsW.js";import{$t as o,D as s,d as c,k as l,u,xn as d}from"./persistence-DPNMIbF5.js";import{a as f,i as p,r as m}from"./vendor-zustand-B4dlGEM2.js";import{nt as h,rt as g}from"./vendor-base-ui-CnHfUmDN.js";import{L as _,Ot as v,k as y,yt as b}from"./gitApiHttp-D8j1qRH4.js";import{n as x}from"./vendor-react-DLPElpoQ.js";import{s as S}from"./vendor-tanstack-react-query-D7pys_c9.js";import{n as C}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as ee}from"./clipboard-BW7nk_Cx.js";import{Ji as te,Za as ne,_ as re,b as ie,ct as ae,en as oe,l as w,mo as T,ot as E,po as se,st as ce,un as D,wr as O}from"./useMobileNavigationStore-DnzT4jO2.js";import{c as le,t as k}from"./utils-Co19EJEL.js";import{n as A}from"./Icon-AXqa-fYB.js";import{g as j,v as M}from"./gitApi-BYxg_qGJ.js";import{A as ue,M as N,p as P,s as F}from"./projectMeta-v-LP2mzz.js";var I=e(g(),1),L=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},R=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,z=(e,t)=>{let n=L(t),r=L(e);if(!n||!r)return!1;let i=R(n),a=R(r);return a===i||a.startsWith(`${i}/`)},de=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=L(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=>L(e)).filter(e=>z(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>L(e)).filter(e=>z(e,t)))):[],s=typeof i.selectedPath==`string`?L(i.selectedPath):null,c=s&&z(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},B=(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},V=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},fe=f()(m(p((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=L((t||``).trim()),a=L((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!z(a,i)||e(e=>{let t=e.byRoot[i],n=V(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:B({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=L((t||``).trim()),i=L((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=R(i),a=e=>R(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:B({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=L((t||``).trim()),i=L((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=R(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=R(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:B({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=L((t||``).trim()),i=L((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=R(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=R(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:B({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=L((t||``).trim()),a=n?L(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!z(a,i)||e(e=>{let t=e.byRoot[i],n=V(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:B({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=L((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=L((t||``).trim()),i=L((n||``).trim());!r||!i||!z(i,r)||e(e=>{let t=e.byRoot[r],n=V(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:B({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=L((t||``).trim()),i=L((n||``).trim());!r||!i||!z(i,r)||e(e=>{let t=e.byRoot[r],n=V(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:B({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=L((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>L((e||``).trim())).filter(e=>e&&z(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=V(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:B({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:a(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:de(t)}},partialize:e=>({byRoot:de(e.byRoot)})}),{name:`files-view-tabs-store`})),H=x(),pe=(e,t)=>{let n=(0,H.c)(4),r=t===void 0?200:t,[i,a]=I.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]),I.useEffect(o,s),i},me=()=>{let e=(0,H.c)(17),t=w(U),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=ie(r),a=w(W),o=w(G),s=T(K),c=T(he),l=b(ge);if(t){let r;e[2]===i?r=e[3]:(r=re(i),e[2]=i,e[3]=r);let o=r;if(o)return o;let s;e[4]!==t||e[5]!==a?(s=a.get(t),e[4]=t,e[5]=a,e[6]=s):s=e[6];let c=s;if(c?.path)return c.path;let l;if(e[7]!==t||e[8]!==n){let r;e[10]===t?r=e[11]:(r=e=>e.id===t,e[10]=t,e[11]=r),l=n.find(r),e[7]=t,e[8]=n,e[9]=l}else l=e[9];let u=l;if(u?.directory)return u.directory}if(o?.open&&(o.bootstrapPendingDirectory||o.directoryOverride))return(o.bootstrapPendingDirectory||o.directoryOverride)??void 0;if(s){let t;if(e[12]!==s||e[13]!==c){let n;e[15]===s?n=e[16]:(n=e=>e.id===s,e[15]=s,e[16]=n),t=c.find(n),e[12]=s,e[13]=c,e[14]=t}else t=e[14];let n=t;if(n?.path)return n.path}return l??void 0};function U(e){return e.currentSessionId}function W(e){return e.worktreeMetadata}function G(e){return e.newSessionDraft}function K(e){return e.activeProjectId}function he(e){return e.projects}function ge(e){return e.currentDirectory}var _e=.4,q=8,J=e=>{let t=e.gap??q,n=Math.max(0,e.popupBottom-e.boundaryTop-t),r=e.viewportHeight*_e,i=Math.floor(Math.min(n,r));return n>=120?Math.min(n,Math.max(120,i)):i},Y=(e,t=0)=>{let n=e.closest(`main`);if(!n)return null;let r=(e.closest(`.mobile-chat-screen__content`)?.parentElement??n.parentElement?.closest(`main`)??n).querySelector(`:scope > .oc-mobile-detail-navigation`)?.getBoundingClientRect().bottom,i=n.getBoundingClientRect().top;return Math.max(r===void 0?i:Math.max(r,i),t)},ve=(e,t)=>{let n=(0,H.c)(3),[r,i]=I.useState(void 0),a;return n[0]!==e||n[1]!==t?(a=()=>{if(!t)return;let n=()=>{let t=e.current;if(!t)return;let n=window.visualViewport,r=Y(t,n?.offsetTop??0);if(r===null)return;let a=n?.height??window.innerHeight,o=J({popupBottom:t.getBoundingClientRect().bottom,boundaryTop:r,viewportHeight:a});i(e=>e===o?e:o)};return n(),window.addEventListener(`resize`,n),window.addEventListener(`oc:keyboard-settled`,n),window.visualViewport?.addEventListener(`resize`,n),window.visualViewport?.addEventListener(`scroll`,n),()=>{window.removeEventListener(`resize`,n),window.removeEventListener(`oc:keyboard-settled`,n),window.visualViewport?.removeEventListener(`resize`,n),window.visualViewport?.removeEventListener(`scroll`,n)}},n[0]=e,n[1]=t,n[2]=a):a=n[2],I.useLayoutEffect(a),t?r:void 0},ye=()=>{let e=null,t=!1,n=!1;return{pointerDown:(n,r)=>{e={x:n,y:r},t=!1},pointerMove:(n,r)=>{e&&Math.hypot(n-e.x,r-e.y)>6&&(t=!0)},pointerCancel:()=>{e=null,t=!1},pointerUp:r=>{if(!e)return!1;let i=!t;return e=null,t=!1,i?(n=!0,r(),!0):(n=!0,!1)},click:e=>n?(n=!1,!1):(e(),!0)}},X=h(),Z=I.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSessionSelect:r,onClose:a,style:o},c)=>{let{t:u}=ee(),d=me()??``,f=w(e=>e.currentSessionId),p=O(e=>e.activeSessions),m=T(e=>e.activeProjectId),h=T(e=>e.projects),g=I.useMemo(()=>h.find(e=>e.id===m)?.path??null,[m,h]),_=I.useMemo(()=>{let e=g||d;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[g,d]),y=fe(e=>_?e.byRoot[_]:void 0),b=te(e=>e.getVisibleAgents),x=v(e=>e.searchFiles),S=pe(e,180),ne=l(),re=s(),[ie,ae]=I.useState([]),[oe,se]=I.useState([]),[D,j]=I.useState(!1),[M,N]=I.useState(0),P=I.useRef(0),[F,L]=I.useState(360),[R,z]=I.useState({}),[de,B]=I.useState({}),V=I.useRef([]),H=I.useRef([]),U=I.useRef([]),W=I.useRef(null),G=I.useRef(null);G.current||=ye();let K=i(e=>e.isMobile),he=ve(W,K),ge=(e??``).trim(),_e=I.useMemo(()=>{if(!_||!y)return[];let e=[y.selectedPath,...y.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=ge.toLowerCase();return e.filter(e=>{if(t.has(e))return!1;t.add(e);let r=e.startsWith(`${_}/`)?e.slice(_.length+1):e;return!n||r.toLowerCase().includes(n)}).slice(0,6).map(e=>{let t=e.replace(/\\/g,`/`),n=t.split(`/`).filter(Boolean).pop()||t;return{name:n,path:t,relativePath:t.startsWith(`${_}/`)?t.slice(_.length+1):t,extension:n.includes(`.`)?n.split(`.`).pop()?.toLowerCase():void 0}})},[ge,_,y]),q=I.useMemo(()=>ge.length>0?oe:oe.slice(0,2),[oe,ge.length]),J=I.useMemo(()=>r?E({sessions:p,currentSessionId:f,searchQuery:ge}):[],[p,f,ge,r]),Y=_e,Z=ie;I.useEffect(()=>{let e=e=>{let t=e.target;!t||!W.current||W.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),I.useEffect(()=>{if(!d){ae([]);return}let e=(S??``).trim().replace(/^\.\//,``).replace(/^\/+/,``).toLowerCase();if(!e){ae([]);return}let t=!1;j(!0);let n={includeHidden:ne,respectGitignore:!re};return Promise.all([x(d,e,80,{...n,type:`file`}),x(d,e,40,{...n,type:`directory`})]).then(([n,r])=>{if(t)return;let i=new Set(_e.map(e=>e.path));ae(ce({files:n,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{t||ae([])}).finally(()=>{t||j(!1)}),()=>{t=!0}},[d,S,_e,x,ne,re]),I.useEffect(()=>{let t=b(),n=(e??``).trim().toLowerCase(),r=t.filter(e=>e.mode&&e.mode!==`primary`).filter(e=>!n||`${e.name} ${e.description??``}`.toLowerCase().includes(n)).map(e=>({name:e.name,description:e.description,mode:e.mode})).sort((e,t)=>e.name.localeCompare(t.name));se(r)},[b,e]),I.useEffect(()=>{N(0),z({}),B({})},[Z,Y.length,q.length,J.length]),I.useEffect(()=>{P.current=M},[M]),I.useEffect(()=>{V.current[M]?.scrollIntoView({block:`nearest`})},[M]),I.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};H.current.forEach((n,r)=>{if(!n)return;let i=U.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}}),z(e),B(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[Z,Y]),I.useEffect(()=>{let e=H.current[M];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&L(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[M]);let be=C(e=>{t(e)}),xe=C(e=>{n?.(e)}),Se=C(e=>{r?.(e)}),Ce=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&G.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&G.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(G.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>G.current?.pointerCancel(),onClick:()=>{G.current?.click(t)},onMouseMove:()=>N(e)});I.useImperativeHandle(c,()=>({handleKeyDown:e=>{if(e===`Escape`){a();return}let t=q.length+J.length+Y.length+Z.length;if(t!==0){if(e===`ArrowDown`){N(e=>(e+1)%t);return}if(e===`ArrowUp`){N(e=>(e-1+t)%t);return}if(e===`Enter`||e===`Tab`){let e=(P.current%t+t)%t;if(e<q.length){let t=q[e];t&&xe(t.name);return}let n=e-q.length;if(n<J.length){let e=J[n];e&&Se(e);return}let r=n-J.length,i=r<Y.length?Y[r]:Z[r-Y.length];i&&be(i)}}}}),[Z,Y,q,J,a,be,xe,Se]);let we=e=>{if(e.isDirectory)return(0,X.jsx)(A,{name:`folder-3-fill`,className:`h-3.5 w-3.5 text-current`});switch(e.extension?.toLowerCase()){case`ts`:case`tsx`:case`js`:case`jsx`:return(0,X.jsx)(A,{name:`code`,className:`h-3.5 w-3.5 text-current`});case`json`:return(0,X.jsx)(A,{name:`code`,className:`h-3.5 w-3.5 text-current`});case`md`:case`mdx`:return(0,X.jsx)(A,{name:`file`,className:`h-3.5 w-3.5 text-current`});case`png`:case`jpg`:case`jpeg`:case`gif`:case`svg`:return(0,X.jsx)(A,{name:`file-image`,className:`h-3.5 w-3.5 text-current`});default:return(0,X.jsx)(A,{name:`file-pdf`,className:`h-3.5 w-3.5 text-current`})}};return(0,X.jsxs)(`div`,{ref:W,className:`absolute z-[100] min-w-0 w-full max-w-[640px] max-h-64 bg-background border-2 border-border/60 rounded-xl shadow-none bottom-full mb-2 left-0 flex flex-col`,style:he===void 0?o:{...o,maxHeight:he},children:[(0,X.jsx)(ue,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,X.jsxs)(`div`,{className:`pb-2`,children:[q.length>0&&(0,X.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.groups.agents`)}),q.map((e,t)=>(0,X.jsx)(`div`,{ref:e=>{V.current[t]=e},className:k(`flex items-start gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,K&&`min-h-11`,M===t&&`bg-interactive-selection text-interactive-selection-foreground`),...Ce(t,()=>xe(e.name)),children:(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`font-semibold truncate`,children:[`@`,e.name]}),e.description&&!K?(0,X.jsx)(`div`,{className:`typography-meta text-muted-foreground truncate`,children:e.description}):null]})},`agent-${e.name}`)),q.length===2&&ge.length===0&&oe.length>2&&(0,X.jsx)(`div`,{className:`px-3 py-1 typography-meta text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.searchMoreAgents`)}),J.length>0&&(0,X.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.groups.sessions`)}),J.map((e,t)=>{let n=q.length+t;return(0,X.jsxs)(`div`,{ref:e=>{V.current[n]=e},className:k(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,K&&`min-h-11`,M===n&&`bg-interactive-selection text-interactive-selection-foreground`),...Ce(n,()=>Se(e)),children:[(0,X.jsx)(A,{name:`chat-thread`,className:`h-4 w-4 flex-shrink-0 text-[var(--primary-base)]`}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.title||u(`chat.fileMentionAutocomplete.untitledSession`),children:e.title||u(`chat.fileMentionAutocomplete.untitledSession`)}),K?null:(0,X.jsx)(`span`,{className:`flex-shrink-0 typography-meta text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.sessionType`)})]},`session-${e.id}`)}),Y.length>0&&(0,X.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.groups.recentFiles`)}),Y.map((e,t)=>{let n=q.length+J.length+t,r=e.relativePath||e.name,i=le(r,{maxLength:60}),a=M===n,o=R[n]??!1,s=de[n]??2.6;return(0,X.jsxs)(`div`,{ref:e=>{V.current[n]=e},className:k(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,K&&`min-h-11`,a&&`bg-interactive-selection text-interactive-selection-foreground`),...Ce(n,()=>be(e)),children:[we(e),(0,X.jsxs)(`span`,{ref:e=>{H.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${F}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,X.jsx)(`span`,{ref:e=>{U.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,X.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:r}):(0,X.jsx)(`span`,{className:`block truncate`,children:i})]})]},`recent-${e.path}`)}),Z.length>0&&(0,X.jsx)(`div`,{className:`px-3 pb-1 pt-2 typography-meta font-medium text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.groups.files`)}),Z.map((e,t)=>{let n=q.length+J.length+Y.length+t,r=e.relativePath||e.name,i=le(r,{maxLength:60}),a=M===n,o=R[n]??!1,s=de[n]??2.6;return(0,X.jsxs)(`div`,{ref:e=>{V.current[n]=e},className:k(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,K&&`min-h-11`,a&&`bg-interactive-selection text-interactive-selection-foreground`),...Ce(n,()=>be(e)),children:[we(e),(0,X.jsxs)(`span`,{ref:e=>{H.current[n]=e},className:`relative flex-1 min-w-0 overflow-hidden file-mention-marquee-container`,style:a?{"--file-mention-marquee-width":`${F}px`,"--file-mention-marquee-duration":`${s}s`}:void 0,"aria-label":r,children:[(0,X.jsx)(`span`,{ref:e=>{U.current[n]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:r}),o&&a?(0,X.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:r}):(0,X.jsx)(`span`,{className:`block truncate`,children:i})]})]},e.path)}),D&&Z.length===0?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,X.jsx)(A,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!D&&Z.length===0&&Y.length===0&&q.length===0&&J.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.fileMentionAutocomplete.empty`)})]})}),!K&&(0,X.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})}),be=new Set([`new`,`fork`,`compact`,`undo`,`redo`,`model`,`goal`]),xe=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&be.has(n))},Se=(e,t)=>!e||t({name:e}),Ce=` `,we=(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]===Ce&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},Te=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,Ee=k(Te,`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)]`),De=k(Te,`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)]`),Oe=k(Te,`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)]`),ke=k(Te,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),Ae=(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=ae(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)},je=(e,t)=>{let n=!!e.sessionID;return{hasSession:n,canStartSessionCommand:n||e.hasNewDraft,canUseReviewHandoffFlow:n&&!t&&!o()}},Me=I.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:r,style:a,commandPolicy:o,commandContext:s},c)=>{let{t:l}=ee(),u=i(e=>e.isMobile),d=w(e=>e.currentSessionId),f=w(e=>!!e.newSessionDraft?.open),p=w(I.useCallback(e=>d?e.getDirectoryForSession(d):void 0,[d])),m=oe(d??``,p??void 0),h=I.useMemo(()=>s??{sessionID:d??null,hasMessages:m.length>0,hasNewDraft:f},[s,d,m.length,f]),{hasSession:g,canStartSessionCommand:_,canUseReviewHandoffFlow:v}=I.useMemo(()=>je(h,u),[h,u]),y=h.hasMessages,[b,x]=I.useState([]),[S,C]=I.useState(!1),te=se({directory:r}),re=I.useMemo(()=>te.data??[],[te.data]),ie=te.isFetching,ae=ne({directory:r}),T=I.useMemo(()=>ae.data??[],[ae.data]),[E,ce]=I.useState(0),D=I.useRef(0),O=I.useRef(!1),le=I.useRef([]),j=I.useRef(null),M=ve(j,u),N=I.useRef(!1),P=I.useRef(null),F=I.useRef(!1);I.useEffect(()=>{let e=e=>{let t=e.target;!t||!j.current||j.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),I.useEffect(()=>{(async()=>{C(ie);try{let t=re.map((e,t)=>({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,isSkill:e.source===`skill`,scope:e.scope,reference:e.reference})),n=T.map((e,t)=>({id:`skill:${e.scope}:${e.source??`opencode`}:${e.name}:${t}`,name:e.name,source:`skill`,description:e.description,isSkill:!0,scope:e.scope})),r=[{id:`openchamber:new`,name:`new`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},...g&&!y?[{id:`openchamber:init`,name:`init`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],...g?[{id:`openchamber:undo`,name:`undo`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`openchamber:redo`,name:`redo`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`openchamber:fork`,name:`fork`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`openchamber:timeline`,name:`timeline`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`openchamber:model`,name:`model`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`openchamber:compact`,name:`compact`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...g?[{id:`openchamber:summary`,name:`summary`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.summaryDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:workspace-review`,name:`workspace-review`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.workspaceReviewDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:handoff-review`,name:`handoff-review`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.handoffReviewDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:plan-feature`,name:`plan-feature`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.featurePlanDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:craft-goal`,name:`craft-goal`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.craftGoalDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:goal`,name:`goal`,source:`openchamber`,description:l(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:catch-up`,name:`catch-up`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.catchUpDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:debug`,name:`debug`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.debugDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:weigh`,name:`weigh`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.weighDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:explore`,name:`explore`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.exploreDescription`),isOpenChamber:!0}]:[],...t,...n],i=!y,a=r.filter(e=>(i||e.name!==`init`)&&(o?.(e)??!0));x(Ae(a,e))}catch{let t=!y,n=[{id:`openchamber:new`,name:`new`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},...g&&!y?[{id:`openchamber:init`,name:`init`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],...g?[{id:`openchamber:undo`,name:`undo`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`openchamber:redo`,name:`redo`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`openchamber:fork`,name:`fork`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`openchamber:timeline`,name:`timeline`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`openchamber:model`,name:`model`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`openchamber:compact`,name:`compact`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...g?[{id:`openchamber:summary`,name:`summary`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.summaryDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:workspace-review`,name:`workspace-review`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.workspaceReviewDescription`),isOpenChamber:!0}]:[],...v?[{id:`openchamber:handoff-review`,name:`handoff-review`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.handoffReviewDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:plan-feature`,name:`plan-feature`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.featurePlanDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:craft-goal`,name:`craft-goal`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.craftGoalDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:goal`,name:`goal`,source:`openchamber`,description:l(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],..._?[{id:`openchamber:catch-up`,name:`catch-up`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.catchUpDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:debug`,name:`debug`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.debugDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:weigh`,name:`weigh`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.weighDescription`),isOpenChamber:!0}]:[],..._?[{id:`openchamber:explore`,name:`explore`,source:`openchamber`,description:l(`chat.commandAutocomplete.command.exploreDescription`),isOpenChamber:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(o?.(e)??!0));x(Ae(n,e))}finally{C(!1)}})()},[e,y,g,_,v,re,ie,T,l,o]),I.useEffect(()=>{ce(0)},[b]),I.useEffect(()=>{D.current=E},[E]),I.useEffect(()=>{le.current[E]?.scrollIntoView({block:`nearest`})},[E]),I.useImperativeHandle(c,()=>({handleKeyDown:e=>{let r=b.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){O.current=!0,ce(e=>(e+1)%r);return}if(e===`ArrowUp`){O.current=!0,ce(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(D.current%r+r)%r,i=b[n];i&&t(i,xe(i,e===`Enter`))}}}}),[b,n,t]);let L=e=>{switch(e.name){case`new`:return(0,X.jsx)(A,{name:`add`,className:`h-3.5 w-3.5`});case`init`:return(0,X.jsx)(A,{name:`file`,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,X.jsx)(A,{name:`arrow-go-back`,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,X.jsx)(A,{name:`arrow-go-forward`,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:return(0,X.jsx)(A,{name:`time`,className:`h-3.5 w-3.5`});case`compact`:return(0,X.jsx)(A,{name:`scissors`,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,X.jsx)(A,{name:`target`,className:`h-3.5 w-3.5`});case`review`:return(0,X.jsx)(A,{name:`search-eye`,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,X.jsx)(A,{name:`terminal-box`,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,X.jsx)(A,{name:`flashlight`,className:`h-3.5 w-3.5 text-yellow-500`}):(0,X.jsx)(A,{name:`command`,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,X.jsxs)(`div`,{ref:j,className:`absolute z-[100] min-w-0 w-full max-w-[450px] max-h-64 bg-background border-2 border-border/60 rounded-xl shadow-none bottom-full mb-2 left-0 flex flex-col`,style:M===void 0?a:{...a,maxHeight:M},children:[(0,X.jsx)(ue,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 pb-2`,children:S?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,X.jsx)(A,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,X.jsxs)(`div`,{children:[b.map((e,n)=>{let r=e.isBuiltIn,i=e.isOpenChamber;return(0,X.jsxs)(`div`,{ref:e=>{le.current[n]=e},className:k(`flex gap-2 px-3 py-2 cursor-pointer rounded-lg`,u?`items-center`:`items-start`,n===E&&`bg-interactive-selection`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(P.current={x:e.clientX,y:e.clientY},F.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!P.current)return;let t=e.clientX-P.current.x,n=e.clientY-P.current.y;Math.hypot(t,n)>6&&(F.current=!0)},onPointerUp:n=>{if(n.pointerType!==`touch`)return;let r=F.current;P.current=null,F.current=!1,!r&&(n.preventDefault(),n.stopPropagation(),N.current=!0,t(e,xe(e,u)))},onPointerCancel:()=>{P.current=null,F.current=!1},onClick:()=>{if(N.current){N.current=!1;return}t(e,xe(e,u))},onMouseMove:()=>{O.current=!1,ce(n)},children:[(0,X.jsx)(`div`,{className:k(!u&&`mt-0.5`),children:L(e)}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,e.name]}),e.isSkill?(0,X.jsx)(`span`,{className:Ee,children:l(`chat.commandAutocomplete.badge.skill`)}):(0,X.jsx)(`span`,{className:Ee,children:l(`chat.commandAutocomplete.badge.command`)}),i?(0,X.jsx)(`span`,{className:ke,children:`OpenChamber`}):r?(0,X.jsx)(`span`,{className:ke,children:l(`chat.commandAutocomplete.badge.system`)}):e.scope?(0,X.jsx)(`span`,{className:e.scope===`project`?Oe:De,children:e.scope}):null,e.agent&&(0,X.jsx)(`span`,{className:ke,children:e.agent})]}),e.description&&!u&&(0,X.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:e.description})]})]},e.id)}),b.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:l(`chat.commandAutocomplete.empty`)})]})}),!u&&(0,X.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:l(`chat.autocomplete.keyboardHint`)})]})});Me.displayName=`CommandAutocomplete`;function Ne(e){return(e.description||e.content).replace(/\s+/g,` `).trim().slice(0,120)}var Pe=I.forwardRef((e,t)=>{let n=(0,H.c)(63),{searchQuery:r,onSnippetSelect:a,onClose:o,style:s}=e,{t:c}=ee(),l=I.useRef(null),u=i(Fe),d=ve(l,u),[f,p]=I.useState(0),m=I.useRef(0),h;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(h=[],n[0]=h):h=n[0];let[g,_]=I.useState(h),v;n[1]===Symbol.for(`react.memo_cache_sentinel`)?(v=[],n[1]=v):v=n[1];let y=I.useRef(v),b=N(Ie),x=N(Le),S=N(Re),C=N(ze),te=i(Be),ne=i(Ve),re,ie;n[2]===x?(re=n[3],ie=n[4]):(re=()=>{x()},ie=[x],n[2]=x,n[3]=re,n[4]=ie),I.useEffect(re,ie);let oe,w;n[5]!==r||n[6]!==b?(oe=()=>{let e=r.trim();if(!e.length){let e=[...b].sort(He);_(e),p(+!!e.length);return}let t=ae(b,e,Ue);t.sort(We);let n=t.map(Ge);_(n),p(+!!n.length)},w=[r,b],n[5]=r,n[6]=b,n[7]=oe,n[8]=w):(oe=n[7],w=n[8]),I.useEffect(oe,w);let T,E;n[9]===f?(T=n[10],E=n[11]):(T=()=>{m.current=f,y.current[f]?.scrollIntoView({block:`nearest`})},E=[f],n[9]=f,n[10]=T,n[11]=E),I.useEffect(T,E);let se,ce;n[12]===o?(se=n[13],ce=n[14]):(ce=()=>{let e=e=>{let t=e.target;t&&l.current&&!l.current.contains(t)&&o()};return document.addEventListener(`pointerdown`,e,!0),()=>document.removeEventListener(`pointerdown`,e,!0)},se=[o],n[12]=o,n[13]=se,n[14]=ce),I.useEffect(ce,se);let D;n[15]!==a||n[16]!==r?(D=e=>{let t=r.trim(),n=e.aliases.includes(t)?t:e.name;a(e,n)},n[15]=a,n[16]=r,n[17]=D):D=n[17];let O=D,le;n[18]!==o||n[19]!==C||n[20]!==te||n[21]!==ne||n[22]!==S||n[23]!==b?(le=()=>{let e=new Set(b.map(Ke)),t=`new-snippet`,n=1;for(;e.has(t);)t=`new-snippet-${n++}`;S({name:t,scope:`global`}),C(t),ne(`snippets`),te(!0),o()},n[18]=o,n[19]=C,n[20]=te,n[21]=ne,n[22]=S,n[23]=b,n[24]=le):le=n[24];let j=le,M,P;n[25]!==O||n[26]!==g||n[27]!==o||n[28]!==j?(M=()=>({handleKeyDown:e=>{if(e===`Escape`){o();return}let t=g.length+1;if(e===`ArrowDown`){p(e=>(e+1)%t);return}if(e===`ArrowUp`){p(e=>(e-1+t)%t);return}if(e===`Enter`||e===`Tab`){if(m.current===0){j();return}let e=g[m.current-1];e&&O(e)}}}),P=[O,g,o,j],n[25]=O,n[26]=g,n[27]=o,n[28]=j,n[29]=M,n[30]=P):(M=n[29],P=n[30]),I.useImperativeHandle(t,M,P);let F;n[31]!==d||n[32]!==s?(F=d===void 0?s:{...s,maxHeight:d},n[31]=d,n[32]=s,n[33]=F):F=n[33];let L;n[34]===Symbol.for(`react.memo_cache_sentinel`)?(L=e=>{y.current[0]=e},n[34]=L):L=n[34];let R=f===0&&`bg-interactive-selection`,z;n[35]===R?z=n[36]:(z=k(`flex items-center gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,R),n[35]=R,n[36]=z);let de,B;n[37]===Symbol.for(`react.memo_cache_sentinel`)?(de=()=>p(0),B=(0,X.jsx)(A,{name:`add`,className:`h-3.5 w-3.5 text-muted-foreground`}),n[37]=de,n[38]=B):(de=n[37],B=n[38]);let V;n[39]===c?V=n[40]:(V=c(`chat.snippetAutocomplete.action.addNew`),n[39]=c,n[40]=V);let fe;n[41]===V?fe=n[42]:(fe=(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:V}),n[41]=V,n[42]=fe);let pe;n[43]!==j||n[44]!==z||n[45]!==fe?(pe=(0,X.jsxs)(`div`,{ref:L,className:z,onClick:j,onMouseMove:de,children:[B,fe]}),n[43]=j,n[44]=z,n[45]=fe,n[46]=pe):pe=n[46];let me;n[47]!==O||n[48]!==g||n[49]!==u||n[50]!==f||n[51]!==c?(me=g.length?g.map((e,t)=>(0,X.jsx)(`div`,{ref:e=>{y.current[t+1]=e},className:k(`flex gap-2 px-3 py-1.5 cursor-pointer rounded-lg typography-ui-label`,u?`items-center`:`items-start`,t+1===f&&`bg-interactive-selection`),onClick:()=>O(e),onMouseMove:()=>p(t+1),children:(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`font-semibold truncate`,children:[`#`,e.name]}),(0,X.jsx)(`span`,{className:`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0 bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`,children:c(`snippets.source.${e.source}`)})]}),!u&&(0,X.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Ne(e)})]})},`${e.source}:${e.filePath}`)):(0,X.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:c(`chat.snippetAutocomplete.empty`)}),n[47]=O,n[48]=g,n[49]=u,n[50]=f,n[51]=c,n[52]=me):me=n[52];let U;n[53]!==pe||n[54]!==me?(U=(0,X.jsxs)(ue,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 pb-2`,children:[pe,me]}),n[53]=pe,n[54]=me,n[55]=U):U=n[55];let W;n[56]!==u||n[57]!==c?(W=!u&&(0,X.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:c(`chat.snippetAutocomplete.footer`)}),n[56]=u,n[57]=c,n[58]=W):W=n[58];let G;return n[59]!==F||n[60]!==U||n[61]!==W?(G=(0,X.jsxs)(`div`,{ref:l,className:`absolute z-[100] min-w-0 w-full max-w-[450px] max-h-60 bg-background border-2 border-border/60 rounded-xl shadow-none bottom-full mb-2 left-0 flex flex-col`,style:F,children:[U,W]}),n[59]=F,n[60]=U,n[61]=W,n[62]=G):G=n[62],G});Pe.displayName=`SnippetAutocomplete`;function Fe(e){return e.isMobile}function Ie(e){return e.snippets}function Le(e){return e.loadSnippets}function Re(e){return e.setSnippetDraft}function ze(e){return e.setSelectedSnippet}function Be(e){return e.setSettingsDialogOpen}function Ve(e){return e.setSettingsPage}function He(e,t){return e.source===`project`&&t.source!==`project`?-1:e.source!==`project`&&t.source===`project`?1:e.name.localeCompare(t.name)}function Ue(e){return[e.name,...e.aliases]}function We(e,t){return e.score===t.score?e.item.source===`project`&&t.item.source!==`project`?-1:e.item.source!==`project`&&t.item.source===`project`?1:e.item.name.localeCompare(t.item.name):e.score-t.score}function Ge(e){return e.item}function Ke(e){return e.name}var qe=2,Je=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Ye=e=>{let t=e?.trim().replace(/\\/g,`/`);return t?t.length>1?t.replace(/\/+$/,``):t:null},Xe=e=>Je(e)&&Array.isArray(e.all)&&e.all.every(e=>typeof e==`string`)&&typeof e.current==`string`&&Je(e.branches),Ze=(e,t)=>JSON.stringify([e,t]),Qe=e=>`version`in e&&e.version===qe&&Je(e.entries),$e=e=>{if(!e)return null;try{let t=JSON.parse(e);return Je(t)?t.version===qe&&Je(t.entries)?{version:qe,entries:t.entries}:t:null}catch{return null}},et=(e,t)=>{try{e.setItem(`oc.gitBranchCache`,JSON.stringify(t))}catch{}},tt=(e,t,n)=>{let r=Ye(e);if(!r||!t)return null;let i;try{i=n.getItem(`oc.gitBranchCache`)}catch{return null}let a=$e(i);if(!a)return null;if(Qe(a))return Xe(a.entries[Ze(t,r)])?a.entries[Ze(t,r)]:null;let o={};for(let[e,n]of Object.entries(a)){let r=Ye(e);r&&Xe(n)&&(o[Ze(t,r)]=n)}return et(n,{version:qe,entries:o}),o[Ze(t,r)]??null},nt=(e,t,n,r)=>{let i=Ye(e);if(!i||!t||!Xe(n))return;let a=null;try{a=r.getItem(`oc.gitBranchCache`)}catch{return}let o=$e(a);et(r,{version:qe,entries:{...o&&Qe(o)?o.entries:{},[Ze(t,i)]:n}})},rt=3e4,it=Ye,at=(e,n=t())=>c.git.branches(it(e),n),ot=(e,n=t())=>c.git.remotes(it(e),n),st=async(e,t,n)=>{n.throwIfAborted();let r=d()?.git,i=t?.getGitBranches?await t.getGitBranches(e,{signal:n}):r?await r.getGitBranches(e,{signal:n}):await y(e,{signal:n});return n.throwIfAborted(),i},ct=async(e,t,n)=>{n.throwIfAborted();let r=d()?.git,i=t?.getRemotes?await t.getRemotes(e,{signal:n}):r?await r.getRemotes(e,{signal:n}):await _(e,{signal:n});return n.throwIfAborted(),i},lt=(e,r,i=t(),a=n())=>{let o=it(e),s=r;return{queryKey:at(o,i),queryFn:async({signal:e})=>{if(!o)throw Error(`Git branches require a directory`);let t=await st(o,s,e);return nt(o,i,t,a),t},staleTime:rt,gcTime:1/0,initialData:()=>tt(o,i,a)??void 0,initialDataUpdatedAt:0}},ut=(e,n,r=t())=>{let i=it(e),a=n;return{queryKey:ot(i,r),queryFn:({signal:e})=>{if(!i)throw Error(`Git remotes require a directory`);return ct(i,a,e)},staleTime:rt,gcTime:1/0}},dt=(e,n,i)=>{let a=(0,H.c)(9),o=i===void 0||i,s=I.useSyncExternalStore(r,t,t),c,l,u;a[0]!==e||a[1]!==n||a[2]!==s?(c=it(e),u=S,l=lt(c,n,s),a[0]=e,a[1]=n,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)},ft=(e,n,i)=>{let a=(0,H.c)(9),o=i===void 0||i,s=I.useSyncExternalStore(r,t,t),c,l,u;a[0]!==e||a[1]!==n||a[2]!==s?(c=it(e),u=S,l=ut(c,n,s),a[0]=e,a[1]=n,a[2]=s,a[3]=c,a[4]=l,a[5]=u):(c=a[3],l=a[4],u=a[5]);let d=o&&!!c,f;return a[6]!==l||a[7]!==d?(f={...l,enabled:d},a[6]=l,a[7]=d,a[8]=f):f=a[8],u(f)},pt=(e,n,r=u,i=t())=>r.fetchQuery(lt(e,n,i)),mt=(e,n,r=u,i=t())=>r.fetchQuery({...lt(e,n,i),staleTime:0}),ht=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,gt=1e4,_t=6e4,vt=5e3,yt=3e4,bt=6e4,xt=25,St=40,Ct=2,wt=15e3,Tt=500,Et=30,Dt=20971520,Ot=new Map,kt=new Map,At=new Map,jt=new Map,Mt=new Map,Nt=(e,t)=>`${t}:${e}`,Pt=e=>kt.get(e)??0,Ft=e=>{let t=Pt(e)+1;return kt.set(e,t),t},It=e=>{let t=(At.get(e)??0)+1;return At.set(e,t),t},Lt=e=>{let t=Ot.get(e);if(t)return t;let n=new Set;return Ot.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}),Rt=(e,t=Et,n=Dt)=>{let r=0;for(let t of e.values())r+=(t.original?.length??0)+(t.modified?.length??0);if(e.size<=t&&r<=n)return e;let i=Array.from(e.entries()).sort((e,t)=>e[1].fetchedAt-t[1].fetchedAt),a=new Map,o=0;for(let e=i.length-1;e>=0;e--){let[r,s]=i[e],c=(s.original?.length??0)+(s.modified?.length??0);if(a.size>=t)break;o+c>n&&a.size>0||(a.set(r,s),o+=c)}return a},zt=(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},Bt=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,Vt=(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&&Bt(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&&zt(e.diffStats,t.diffStats))},Ht=(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},Ut=(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},Wt=e=>!e||e.trim().length===0,Gt=e=>(e||``).trim()===`U`,Kt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Gt(t)||Gt(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},qt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Gt(t)||Gt(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},Jt=e=>Wt(e.index)&&Wt(e.working_dir),$=f()(m((e,n)=>({directories:new Map,activeDirectory:null,setActiveDirectory:t=>{let{activeDirectory:r,directories:i}=n();if(r!==t)if(r&&Ft(r),t&&Ft(t),t&&!i.has(t)){let n=new Map(i);n.set(t,Q()),e({activeDirectory:t,directories:n})}else e({activeDirectory:t})},getDirectoryState:e=>n().directories.get(e)??null,fetchStatus:async(t,r,i={})=>{let a=i.mode??`full`,o=Nt(t,a),s=jt.get(o)??(a===`light`?jt.get(Nt(t,`full`)):void 0);if(s)return s;let c=(async()=>{let{silent:a=!1}=i,{directories:o}=n(),s=o.get(t);if(s||=Q(),!a){let r=new Map(n().directories),i=r.get(t)??Q();r.set(t,{...i,isLoadingStatus:!0}),e({directories:r})}let c=!1;try{let a=Date.now(),o=s.isGitRepo!==!0||a-(s.lastRepoCheckAt||0)>_t,l=s.isGitRepo===!0;if(o&&(l=await r.checkIsGitRepository(t)),!l){let r=new Map(n().directories),i=r.get(t)??s;return r.set(t,{...i,isGitRepo:!1,status:null,isLoadingStatus:!1,lastRepoCheckAt:a,lastStatusFetch:a}),e({directories:r}),!1}let u=await r.getGitStatus(t,i.mode?{mode:i.mode}:void 0);if(Vt(s.status,u)){c=!0;let r=new Map(n().directories),i=r.get(t)??Q(),s=Ht(i.status,u),l=Ut(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&&Ft(t);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(t,{...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(n().directories),i=r.get(t)??Q();r.set(t,{...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(n().directories),i=r.get(t)??Q();r.set(t,{...i,isLoadingStatus:!1}),e({directories:r})}}return c})();jt.set(o,c);try{return await c}finally{jt.get(o)===c&&jt.delete(o)}},moveStatusPathsOptimistically:(t,r,i)=>{let a=new Set(r.map(e=>e.trim()).filter(Boolean));if(a.size===0)return null;let{directories:o}=n(),s=o.get(t),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`?Kt(e):qt(e);t!==e&&(l=!0),Jt(t)?l=!0:u.push(t)}if(!l)return c;let d=new Map(o);return d.set(t,{...s,status:{...c,files:u,isClean:u.length===0},indexRevision:s.indexRevision+1,lastStatusChange:Date.now()}),e({directories:d}),c},restoreStatus:(t,r)=>{let{directories:i}=n(),a=i.get(t);if(!a)return;let o=new Map(i);o.set(t,{...a,status:r,indexRevision:a.indexRevision+1,lastStatusChange:Date.now()}),e({directories:o})},bumpIndexRevision:t=>{let{directories:r}=n(),i=r.get(t);if(!i)return;let a=new Map(r);a.set(t,{...i,indexRevision:i.indexRevision+1}),e({directories:a})},fetchBranches:async(r,i,a={})=>{let o=t(),s=It(r);{let t=new Map(n().directories),i=t.get(r)??Q();t.set(r,{...i,isLoadingBranches:!0}),e({directories:t})}try{let c=a.force?await mt(r,i,void 0,o):await pt(r,i,void 0,o);if(s!==At.get(r)||o!==t())return;let l=new Map(n().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(ht(i)||console.error(`Failed to fetch git branches:`,i),s!==At.get(r)||o!==t())return;let a=new Map(n().directories),c=a.get(r)??Q();a.set(r,{...c,isLoadingBranches:!1}),e({directories:a})}},fetchLog:async(t,r,i)=>{let{directories:a}=n(),o=a.get(t),s=i??o?.logMaxCount??25;{let r=new Map(n().directories),i=r.get(t)??Q();r.set(t,{...i,isLoadingLog:!0}),e({directories:r})}try{let i=await r.getGitLog(t,{maxCount:s}),a=new Map(n().directories),o=a.get(t)??Q();a.set(t,{...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(n().directories),a=i.get(t)??Q();i.set(t,{...a,isLoadingLog:!1}),e({directories:i})}},fetchIdentity:async(t,r)=>{{let r=new Map(n().directories),i=r.get(t)??Q();r.set(t,{...i,isLoadingIdentity:!0}),e({directories:r})}try{let i=await r.getCurrentGitIdentity(t),a=new Map(n().directories),o=a.get(t)??Q();a.set(t,{...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(n().directories),a=i.get(t)??Q();i.set(t,{...a,isLoadingIdentity:!1}),e({directories:i})}},fetchAll:async(t,r,i={})=>{let{directories:a}=n(),o=a.get(t);if(!o){o=Q();let n=new Map(a);n.set(t,o),e({directories:n})}let{force:s=!1,silentIfCached:c=!1}=i,l=Date.now();await n().fetchStatus(t,r,{silent:c&&!!o?.status});let u=n().directories.get(t);if(!u?.isGitRepo)return;await n().fetchBranches(t,r,{force:s});let d=l-(u.lastLogFetch||0);(s||d>gt||!u.log)&&await n().fetchLog(t,r),await n().fetchIdentity(t,r)},getDiff:(e,t)=>n().directories.get(e)?.diffCache.get(t)??null,setDiff:(t,r,i)=>{let a=new Map(n().directories),o=a.get(t)??Q(),s=new Map(o.diffCache);s.set(r,{...i,fetchedAt:Date.now()});let c=Rt(s);a.set(t,{...o,diffCache:c}),e({directories:a})},clearDiffCache:t=>{Ft(t);let r=new Map(n().directories),i=r.get(t);i&&(r.set(t,{...i,diffCache:new Map}),e({directories:r}))},fetchAllDiffs:async(e,t)=>{let r=n().directories.get(e);if(!r?.status?.files||r.status.files.length===0)return;let i=r.status.files.map(e=>e.path).slice(0,xt);await n().prefetchDiffs(e,t,i,{maxFiles:xt})},prefetchDiffs:async(t,r,i,a={})=>{let o=n().directories.get(t);if(!o?.status?.files||o.status.files.length===0||i.length===0)return;let{maxFiles:s=St}=a,c=new Set(o.status.files.map(e=>e.path)),l=o.status.diffStats,u=Lt(t),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>Tt||d.push(e)}let p=d.slice(0,Math.max(1,s));if(p.length===0)return;let m=Pt(t);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 n=r.getGitFileDiff(t,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${wt}ms`)),wt)}),a=await Promise.race([n,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},y=async()=>{for(;;){if(m!==Pt(t))return;let e=_();if(!e)return;try{g.push(await v(e))}catch{}finally{u.delete(e)}}},b=Math.min(Ct,p.length);if(await Promise.allSettled(Array.from({length:b},()=>y())),p.forEach(e=>u.delete(e)),m!==Pt(t))return;let x=new Map(n().directories),S=x.get(t);if(!S)return;let C=new Map(S.diffCache),ee=Date.now();g.forEach(e=>{C.set(e.path,{...e.diff,fetchedAt:ee})});let te=Rt(C);x.set(t,{...S,diffCache:te}),e({directories:x})},setLogMaxCount:(t,r)=>{let i=new Map(n().directories),a=i.get(t)??Q();i.set(t,{...a,logMaxCount:r}),e({directories:i})},ensureStatus:async(e,t)=>{let r=n().directories.get(e),i=Date.now();r?.status&&i-r.lastStatusFetch<vt||await n().fetchStatus(e,t,{silent:!!r?.status})},ensureAll:(e,t)=>{let r=Mt.get(e);if(r)return r;let i=(async()=>{let r=n().directories.get(e),i=Date.now();(!r?.status||r.status.diffStats===void 0||i-(r?.lastStatusFetch??0)>=vt)&&await n().fetchStatus(e,t,{silent:!!r?.status});let a=n().directories.get(e);if(!a?.isGitRepo)return;let o=[];(!a.branches||i-a.lastBranchesFetch>=yt)&&o.push(n().fetchBranches(e,t)),(!a.log||i-a.lastLogFetch>=gt)&&o.push(n().fetchLog(e,t)),(!a.identity||i-a.lastIdentityFetch>=bt)&&o.push(n().fetchIdentity(e,t)),o.length>0&&await Promise.all(o)})();return Mt.set(e,i),i.finally(()=>{Mt.get(e)===i&&Mt.delete(e)}),i},refresh:async(e,t={})=>{let{activeDirectory:r}=n();r&&await n().fetchAll(r,e,t)}}),{name:`git-store`})),Yt=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status??null:null,t[0]=e,t[1]=n),$(n)},Xt=e=>{let n=(0,H.c)(3),i=I.useSyncExternalStore(r,t,t),a;return n[0]!==e||n[1]!==i?(a=t=>{if(!e)return null;let n=t.directories.get(e);return n?.branchesTransportIdentity===i?n.branches:null},n[0]=e,n[1]=i,n[2]=a):a=n[2],$(a)},Zt=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.log??null:null,t[0]=e,t[1]=n),$(n)},Qt=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isGitRepo??null:null,t[0]=e,t[1]=n),$(n)},$t=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status?.current?.trim()??null:null,t[0]=e,t[1]=n),$(n)},en={current:new Map},tn=()=>$(sn),nn=e=>{let t=(0,H.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=I.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)},rn=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingStatus??!1:!1,t[0]=e,t[1]=n),$(n)},an=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingLog??!1:!1,t[0]=e,t[1]=n),$(n)},on=e=>{let t=(0,H.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingBranches??!1:!1,t[0]=e,t[1]=n),$(n)};function sn(e){let t=en.current,n=t.size===e.directories.size;if(n){for(let[r,i]of e.directories)if(t.get(r)!==(i.status?.current??null)){n=!1;break}}if(n)return t;let r=new Map;for(let[t,n]of e.directories)r.set(t,n.status?.current??null);return en.current=r,r}var 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 P(e);try{let n=cn((await j(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=cn((await M(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 F(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]:[...e,t]},Sn=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{ve as A,dt as C,we as D,Me as E,pe as M,fe as N,Se as O,mt as S,Pe as T,Zt as _,hn as a,$ as b,mn as c,tn as d,$t as f,rn as g,an as h,yn as i,me as j,Z as k,dn as l,on as m,xn as n,_n as o,Xt as p,bn as r,gn as s,Sn as t,pn as u,nn as v,ft as w,Qt as x,Yt as y};